1 /* ewrk3.c: A DIGITAL EtherWORKS 3 ethernet driver for Linux.
3 Written 1994 by David C. Davies.
5 Copyright 1994 Digital Equipment Corporation.
7 This software may be used and distributed according to the terms of
8 the GNU Public License, incorporated herein by reference.
10 This driver is written for the Digital Equipment Corporation series
11 of EtherWORKS ethernet cards:
17 The driver has been tested on a relatively busy network using the DE205
18 card and benchmarked with 'ttcp': it transferred 16M of data at 975kB/s
19 (7.8Mb/s) to a DECstation 5000/200.
21 The author may be reached at davies@maniac.ultranet.com.
23 =========================================================================
24 This driver has been written substantially from scratch, although its
25 inheritance of style and stack interface from 'depca.c' and in turn from
26 Donald Becker's 'lance.c' should be obvious.
28 The DE203/4/5 boards all use a new proprietary chip in place of the
29 LANCE chip used in prior cards (DEPCA, DE100, DE200/1/2, DE210, DE422).
30 Use the depca.c driver in the standard distribution for the LANCE based
31 cards from DIGITAL; this driver will not work with them.
33 The DE203/4/5 cards have 2 main modes: shared memory and I/O only. I/O
34 only makes all the card accesses through I/O transactions and no high
35 (shared) memory is used. This mode provides a >48% performance penalty
36 and is deprecated in this driver, although allowed to provide initial
37 setup when hardstrapped.
39 The shared memory mode comes in 3 flavours: 2kB, 32kB and 64kB. There is
40 no point in using any mode other than the 2kB mode - their performances
41 are virtually identical, although the driver has been tested in the 2kB
42 and 32kB modes. I would suggest you uncomment the line:
46 to allow the driver to configure the card as a 2kB card at your current
47 base address, thus leaving more room to clutter your system box with
48 other memory hungry boards.
50 As many ISA and EISA cards can be supported under this driver as you
51 wish, limited primarily by the available IRQ lines, rather than by the
52 available I/O addresses (24 ISA, 16 EISA). I have checked different
53 configurations of multiple depca cards and ewrk3 cards and have not
54 found a problem yet (provided you have at least depca.c v0.38) ...
56 The board IRQ setting must be at an unused IRQ which is auto-probed
57 using Donald Becker's autoprobe routines. All these cards are at
60 No 16MB memory limitation should exist with this driver as DMA is not
61 used and the common memory area is in low memory on the network card (my
62 current system has 20MB and I've not had problems yet).
64 The ability to load this driver as a loadable module has been included
65 and used extensively during the driver development (to save those long
66 reboot sequences). To utilise this ability, you have to do 8 things:
68 0) have a copy of the loadable modules code installed on your system.
69 1) copy ewrk3.c from the /linux/drivers/net directory to your favourite
71 2) edit the source code near line 1898 to reflect the I/O address and
73 3) compile ewrk3.c, but include -DMODULE in the command line to ensure
74 that the correct bits are compiled (see end of source code).
75 4) if you are wanting to add a new card, goto 5. Otherwise, recompile a
76 kernel with the ewrk3 configuration turned off and reboot.
78 [Alan Cox: Changed this so you can insmod ewrk3.o irq=x io=y]
79 6) run the net startup bits for your new eth?? interface manually
80 (usually /etc/rc.inet[12] at boot time).
83 Note that autoprobing is not allowed in loadable modules - the system is
84 already up and running and you're messing with interrupts.
86 To unload a module, turn off the associated interface
87 'ifconfig eth?? down' then 'rmmod ewrk3'.
89 Promiscuous mode has been turned off in this driver, but all the
90 multicast address bits have been turned on. This improved the send
91 performance on a busy network by about 13%.
93 Ioctl's have now been provided (primarily because I wanted to grab some
94 packet size statistics). They are patterned after 'plipconfig.c' from a
95 suggestion by Alan Cox. Using these ioctls, you can enable promiscuous
96 mode, add/delete multicast addresses, change the hardware address, get
97 packet size distribution statistics and muck around with the control and
98 status register. I'll add others if and when the need arises.
107 Version Date Description
109 0.1 26-aug-94 Initial writing. ALPHA code release.
110 0.11 31-aug-94 Fixed: 2k mode memory base calc.,
112 IRQ vector assignments during autoprobe.
113 0.12 31-aug-94 Tested working on LeMAC2 (DE20[345]-AC) card.
114 Fixed up MCA hash table algorithm.
115 0.20 4-sep-94 Added IOCTL functionality.
116 0.21 14-sep-94 Added I/O mode.
117 0.21axp 15-sep-94 Special version for ALPHA AXP Linux V1.0.
118 0.22 16-sep-94 Added more IOCTLs & tidied up.
119 0.23 21-sep-94 Added transmit cut through.
120 0.24 31-oct-94 Added uid checks in some ioctls.
121 0.30 1-nov-94 BETA code release.
122 0.31 5-dec-94 Added check/allocate region code.
123 0.32 16-jan-95 Broadcast packet fix.
124 0.33 10-Feb-95 Fix recognition bug reported by <bkm@star.rl.ac.uk>.
125 0.40 27-Dec-95 Rationalise MODULE and autoprobe code.
126 Rewrite for portability & updated.
127 ALPHA support from <jestabro@amt.tay1.dec.com>
128 Added verify_area() calls in ewrk3_ioctl() from
129 suggestion by <heiko@colossus.escape.de>.
130 Add new multicasting code.
131 0.41 20-Jan-96 Fix IRQ set up problem reported by
132 <kenneth@bbs.sas.ntu.ac.sg>.
133 0.42 22-Apr-96 Fix alloc_device() bug <jari@markkus2.fimr.fi>
134 0.43 16-Aug-96 Update alloc_device() to conform to de4x5.c
136 =========================================================================
139 static const char *version
= "ewrk3.c:v0.43 96/8/16 davies@maniac.ultranet.com\n";
141 #include <linux/module.h>
143 #include <linux/kernel.h>
144 #include <linux/sched.h>
145 #include <linux/string.h>
146 #include <linux/ptrace.h>
147 #include <linux/errno.h>
148 #include <linux/ioport.h>
149 #include <linux/malloc.h>
150 #include <linux/interrupt.h>
151 #include <linux/delay.h>
152 #include <linux/init.h>
153 #include <asm/bitops.h>
156 #include <asm/uaccess.h>
158 #include <linux/netdevice.h>
159 #include <linux/etherdevice.h>
160 #include <linux/skbuff.h>
162 #include <linux/time.h>
163 #include <linux/types.h>
164 #include <linux/unistd.h>
165 #include <linux/ctype.h>
170 static int ewrk3_debug
= EWRK3_DEBUG
;
172 static int ewrk3_debug
= 1;
175 #define EWRK3_NDA 0xffe0 /* No Device Address */
177 #define PROBE_LENGTH 32
178 #define ETH_PROM_SIG 0xAA5500FFUL
180 #ifndef EWRK3_SIGNATURE
181 #define EWRK3_SIGNATURE {"DE203","DE204","DE205",""}
182 #define EWRK3_STRLEN 8
185 #ifndef EWRK3_RAM_BASE_ADDRESSES
186 #define EWRK3_RAM_BASE_ADDRESSES {0xc0000,0xd0000,0x00000}
190 ** Sets up the I/O area for the autoprobe.
192 #define EWRK3_IO_BASE 0x100 /* Start address for probe search */
193 #define EWRK3_IOP_INC 0x20 /* I/O address increment */
194 #define EWRK3_TOTAL_SIZE 0x20 /* required I/O address length */
196 #ifndef MAX_NUM_EWRK3S
197 #define MAX_NUM_EWRK3S 21
200 #ifndef EWRK3_EISA_IO_PORTS
201 #define EWRK3_EISA_IO_PORTS 0x0c00 /* I/O port base address, slot 0 */
204 #ifndef MAX_EISA_SLOTS
205 #define MAX_EISA_SLOTS 16
206 #define EISA_SLOT_INC 0x1000
209 #define CRC_POLYNOMIAL_BE 0x04c11db7UL /* Ethernet CRC, big endian */
210 #define CRC_POLYNOMIAL_LE 0xedb88320UL /* Ethernet CRC, little endian */
212 #define QUEUE_PKT_TIMEOUT (1*HZ) /* Jiffies */
215 ** EtherWORKS 3 shared memory window sizes
218 #define SHMEM_2K 0x800
219 #define SHMEM_32K 0x8000
220 #define SHMEM_64K 0x10000
223 ** EtherWORKS 3 IRQ ENABLE/DISABLE
225 #define ENABLE_IRQs { \
226 icr |= lp->irq_mask;\
227 outb(icr, EWRK3_ICR); /* Enable the IRQs */\
230 #define DISABLE_IRQs { \
231 icr = inb(EWRK3_ICR);\
232 icr &= ~lp->irq_mask;\
233 outb(icr, EWRK3_ICR); /* Disable the IRQs */\
237 ** EtherWORKS 3 START/STOP
239 #define START_EWRK3 { \
240 csr = inb(EWRK3_CSR);\
241 csr &= ~(CSR_TXD|CSR_RXD);\
242 outb(csr, EWRK3_CSR); /* Enable the TX and/or RX */\
245 #define STOP_EWRK3 { \
246 csr = (CSR_TXD|CSR_RXD);\
247 outb(csr, EWRK3_CSR); /* Disable the TX and/or RX */\
251 ** The EtherWORKS 3 private structure
253 #define EWRK3_PKT_STAT_SZ 16
254 #define EWRK3_PKT_BIN_SZ 128 /* Should be >=100 unless you
255 increase EWRK3_PKT_STAT_SZ */
257 struct ewrk3_private
{
258 char adapter_name
[80]; /* Name exported to /proc/ioports */
259 u_long shmem_base
; /* Shared memory start address */
260 u_long shmem_length
; /* Shared memory window length */
261 struct net_device_stats stats
; /* Public stats */
263 u32 bins
[EWRK3_PKT_STAT_SZ
]; /* Private stats counters */
267 u32 excessive_collisions
;
269 u32 excessive_underruns
;
271 u_char irq_mask
; /* Adapter IRQ mask bits */
272 u_char mPage
; /* Maximum 2kB Page number */
273 u_char lemac
; /* Chip rev. level */
274 u_char hard_strapped
; /* Don't allow a full open */
275 u_char lock
; /* Lock the page register */
276 u_char txc
; /* Transmit cut through */
277 u_char
*mctbl
; /* Pointer to the multicast table */
281 ** Force the EtherWORKS 3 card to be in 2kB MODE
283 #define FORCE_2K_MODE { \
284 shmem_length = SHMEM_2K;\
285 outb(((mem_start - 0x80000) >> 11), EWRK3_MBR);\
291 static int ewrk3_open(struct net_device
*dev
);
292 static int ewrk3_queue_pkt(struct sk_buff
*skb
, struct net_device
*dev
);
293 static void ewrk3_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
);
294 static int ewrk3_close(struct net_device
*dev
);
295 static struct net_device_stats
*ewrk3_get_stats(struct net_device
*dev
);
296 static void set_multicast_list(struct net_device
*dev
);
297 static int ewrk3_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
);
302 static int ewrk3_hw_init(struct net_device
*dev
, u_long iobase
);
303 static void ewrk3_init(struct net_device
*dev
);
304 static int ewrk3_rx(struct net_device
*dev
);
305 static int ewrk3_tx(struct net_device
*dev
);
307 static void EthwrkSignature(char *name
, char *eeprom_image
);
308 static int DevicePresent(u_long iobase
);
309 static void SetMulticastFilter(struct net_device
*dev
);
310 static int EISA_signature(char *name
, s32 eisa_id
);
312 static int Read_EEPROM(u_long iobase
, u_char eaddr
);
313 static int Write_EEPROM(short data
, u_long iobase
, u_char eaddr
);
314 static u_char
get_hw_addr(struct net_device
*dev
, u_char
* eeprom_image
, char chipType
);
316 static void isa_probe(struct net_device
*dev
, u_long iobase
);
317 static void eisa_probe(struct net_device
*dev
, u_long iobase
);
318 static struct net_device
*alloc_device(struct net_device
*dev
, u_long iobase
);
319 static int ewrk3_dev_index(char *s
);
320 static struct net_device
*insert_device(struct net_device
*dev
, u_long iobase
, int (*init
) (struct net_device
*));
324 int init_module(void);
325 void cleanup_module(void);
326 static int autoprobed
= 1, loading_module
= 1;
329 static u_char irq
[] =
330 {5, 0, 10, 3, 11, 9, 15, 12};
331 static int autoprobed
= 0, loading_module
= 0;
335 static char name
[EWRK3_STRLEN
+ 1];
336 static int num_ewrk3s
= 0, num_eth
= 0;
339 ** Miscellaneous defines...
341 #define INIT_EWRK3 {\
342 outb(EEPROM_INIT, EWRK3_IOPR);\
346 int __init
ewrk3_probe(struct net_device
*dev
)
348 int tmp
= num_ewrk3s
, status
= -ENODEV
;
349 u_long iobase
= dev
->base_addr
;
351 if ((iobase
== 0) && loading_module
) {
352 printk("Autoprobing is not supported when loading a module based driver.\n");
354 } else { /* First probe for the Ethernet */
355 /* Address PROM pattern */
356 isa_probe(dev
, iobase
);
357 eisa_probe(dev
, iobase
);
359 if ((tmp
== num_ewrk3s
) && (iobase
!= 0) && loading_module
) {
360 printk("%s: ewrk3_probe() cannot find device at 0x%04lx.\n", dev
->name
,
364 ** Walk the device list to check that at least one device
367 for (; (dev
->priv
== NULL
) && (dev
->next
!= NULL
); dev
= dev
->next
);
379 ewrk3_hw_init(struct net_device
*dev
, u_long iobase
)
381 struct ewrk3_private
*lp
;
383 u_long mem_start
, shmem_length
;
384 u_char cr
, cmr
, icr
, nicsr
, lemac
, hard_strapped
= 0;
385 u_char eeprom_image
[EEPROM_MAX
], chksum
, eisa_cr
= 0;
388 ** Stop the EWRK3. Enable the DBR ROM. Disable interrupts and remote boot.
389 ** This also disables the EISA_ENABLE bit in the EISA Control Register.
392 eisa_cr
= inb(EISA_CR
);
395 nicsr
= inb(EWRK3_CSR
);
397 icr
= inb(EWRK3_ICR
);
399 outb(icr
, EWRK3_ICR
); /* Disable all the IRQs */
401 if (nicsr
== (CSR_TXD
| CSR_RXD
)) {
403 /* Check that the EEPROM is alive and well and not living on Pluto... */
404 for (chksum
= 0, i
= 0; i
< EEPROM_MAX
; i
+= 2) {
410 tmp
.val
= (short) Read_EEPROM(iobase
, (i
>> 1));
411 eeprom_image
[i
] = tmp
.c
[0];
412 eeprom_image
[i
+ 1] = tmp
.c
[1];
413 chksum
+= eeprom_image
[i
] + eeprom_image
[i
+ 1];
416 if (chksum
!= 0) { /* Bad EEPROM Data! */
417 printk("%s: Device has a bad on-board EEPROM.\n", dev
->name
);
420 EthwrkSignature(name
, eeprom_image
);
421 if (*name
!= '\0') { /* found a EWRK3 device */
422 dev
->base_addr
= iobase
;
424 if (iobase
> 0x400) {
425 outb(eisa_cr
, EISA_CR
); /* Rewrite the EISA CR */
427 lemac
= eeprom_image
[EEPROM_CHIPVER
];
428 cmr
= inb(EWRK3_CMR
);
430 if (((lemac
== LeMAC
) && ((cmr
& CMR_NO_EEPROM
) != CMR_NO_EEPROM
)) ||
431 ((lemac
== LeMAC2
) && !(cmr
& CMR_HS
))) {
432 printk("%s: %s at %#4lx", dev
->name
, name
, iobase
);
434 } else if ((iobase
& 0x0fff) == EWRK3_EISA_IO_PORTS
) {
435 /* EISA slot address */
436 printk("%s: %s at %#4lx (EISA slot %ld)",
437 dev
->name
, name
, iobase
, ((iobase
>> 12) & 0x0f));
438 } else { /* ISA port address */
439 printk("%s: %s at %#4lx", dev
->name
, name
, iobase
);
443 printk(", h/w address ");
445 DevicePresent(iobase
); /* need after EWRK3_INIT */
446 status
= get_hw_addr(dev
, eeprom_image
, lemac
);
447 for (i
= 0; i
< ETH_ALEN
- 1; i
++) { /* get the ethernet addr. */
448 printk("%2.2x:", dev
->dev_addr
[i
]);
450 printk("%2.2x,\n", dev
->dev_addr
[i
]);
453 printk(" which has an EEPROM CRC error.\n");
456 if (lemac
== LeMAC2
) { /* Special LeMAC2 CMR things */
457 cmr
&= ~(CMR_RA
| CMR_WB
| CMR_LINK
| CMR_POLARITY
| CMR_0WS
);
458 if (eeprom_image
[EEPROM_MISC0
] & READ_AHEAD
)
460 if (eeprom_image
[EEPROM_MISC0
] & WRITE_BEHIND
)
462 if (eeprom_image
[EEPROM_NETMAN0
] & NETMAN_POL
)
464 if (eeprom_image
[EEPROM_NETMAN0
] & NETMAN_LINK
)
466 if (eeprom_image
[EEPROM_MISC0
] & _0WS_ENA
)
469 if (eeprom_image
[EEPROM_SETUP
] & SETUP_DRAM
)
471 outb(cmr
, EWRK3_CMR
);
473 cr
= inb(EWRK3_CR
); /* Set up the Control Register */
474 cr
|= eeprom_image
[EEPROM_SETUP
] & SETUP_APD
;
476 cr
|= eeprom_image
[EEPROM_SETUP
] & SETUP_PS
;
477 cr
|= eeprom_image
[EEPROM_MISC0
] & FAST_BUS
;
478 cr
|= eeprom_image
[EEPROM_MISC0
] & ENA_16
;
482 ** Determine the base address and window length for the EWRK3
483 ** RAM from the memory base register.
485 mem_start
= inb(EWRK3_MBR
);
487 if (mem_start
!= 0) {
488 if ((mem_start
>= 0x0a) && (mem_start
<= 0x0f)) {
489 mem_start
*= SHMEM_64K
;
490 shmem_length
= SHMEM_64K
;
491 } else if ((mem_start
>= 0x14) && (mem_start
<= 0x1f)) {
492 mem_start
*= SHMEM_32K
;
493 shmem_length
= SHMEM_32K
;
494 } else if ((mem_start
>= 0x40) && (mem_start
<= 0xff)) {
495 mem_start
= mem_start
* SHMEM_2K
+ 0x80000;
496 shmem_length
= SHMEM_2K
;
502 ** See the top of this source code for comments about
503 ** uncommenting this line.
509 printk(" is hard strapped.\n");
510 } else if (mem_start
) {
511 printk(" has a %dk RAM window", (int) (shmem_length
>> 10));
512 printk(" at 0x%.5lx", mem_start
);
514 printk(" is in I/O only mode");
517 /* private area & initialise */
518 dev
->priv
= (void *) kmalloc(sizeof(struct ewrk3_private
),
520 if (dev
->priv
== NULL
) {
523 lp
= (struct ewrk3_private
*) dev
->priv
;
524 memset(dev
->priv
, 0, sizeof(struct ewrk3_private
));
525 lp
->shmem_base
= mem_start
;
526 lp
->shmem_length
= shmem_length
;
528 lp
->hard_strapped
= hard_strapped
;
532 lp
->mPage
<<= 1; /* 2 DRAMS on module */
534 sprintf(lp
->adapter_name
, "%s (%s)", name
, dev
->name
);
535 request_region(iobase
, EWRK3_TOTAL_SIZE
, lp
->adapter_name
);
537 lp
->irq_mask
= ICR_TNEM
| ICR_TXDM
| ICR_RNEM
| ICR_RXDM
;
539 if (!hard_strapped
) {
541 ** Enable EWRK3 board interrupts for autoprobing
543 icr
|= ICR_IE
; /* Enable interrupts */
544 outb(icr
, EWRK3_ICR
);
546 /* The DMA channel may be passed in on this parameter. */
549 /* To auto-IRQ we enable the initialization-done and DMA err,
550 interrupts. For now we will always get a DMA error. */
558 ** Trigger a TNE interrupt.
561 outb(1, EWRK3_TDQ
); /* Write to the TX done queue */
562 outb(icr
, EWRK3_ICR
); /* Unmask the TXD interrupt */
564 irqnum
= irq
[((icr
& IRQ_SEL
) >> 4)];
566 dev
->irq
= autoirq_report(1);
567 if ((dev
->irq
) && (irqnum
== dev
->irq
)) {
568 printk(" and uses IRQ%d.\n", dev
->irq
);
571 printk(" and failed to detect IRQ line.\n");
572 } else if ((irqnum
== 1) && (lemac
== LeMAC2
)) {
573 printk(" and an illegal IRQ line detected.\n");
575 printk(", but incorrect IRQ line detected.\n");
580 DISABLE_IRQs
; /* Mask all interrupts */
584 printk(" and requires IRQ%d.\n", dev
->irq
);
588 release_region(iobase
, EWRK3_TOTAL_SIZE
);
600 if (ewrk3_debug
> 1) {
603 /* The EWRK3-specific entries in the device structure. */
604 dev
->open
= &ewrk3_open
;
605 dev
->hard_start_xmit
= &ewrk3_queue_pkt
;
606 dev
->stop
= &ewrk3_close
;
607 dev
->get_stats
= &ewrk3_get_stats
;
608 dev
->set_multicast_list
= &set_multicast_list
;
609 dev
->do_ioctl
= &ewrk3_ioctl
;
613 /* Fill in the generic field of the device structure. */
624 static int ewrk3_open(struct net_device
*dev
)
626 struct ewrk3_private
*lp
= (struct ewrk3_private
*) dev
->priv
;
627 u_long iobase
= dev
->base_addr
;
632 ** Stop the TX and RX...
636 if (!lp
->hard_strapped
) {
637 if (request_irq(dev
->irq
, (void *) ewrk3_interrupt
, 0, "ewrk3", dev
)) {
638 printk("ewrk3_open(): Requested IRQ%d is busy\n", dev
->irq
);
643 ** Re-initialize the EWRK3...
647 if (ewrk3_debug
> 1) {
648 printk("%s: ewrk3 open with irq %d\n", dev
->name
, dev
->irq
);
649 printk(" physical address: ");
650 for (i
= 0; i
< 5; i
++) {
651 printk("%2.2x:", (u_char
) dev
->dev_addr
[i
]);
653 printk("%2.2x\n", (u_char
) dev
->dev_addr
[i
]);
654 if (lp
->shmem_length
== 0) {
655 printk(" no shared memory, I/O only mode\n");
657 printk(" start of shared memory: 0x%08lx\n", lp
->shmem_base
);
658 printk(" window length: 0x%04lx\n", lp
->shmem_length
);
660 printk(" # of DRAMS: %d\n", ((inb(EWRK3_CMR
) & 0x02) ? 2 : 1));
661 printk(" csr: 0x%02x\n", inb(EWRK3_CSR
));
662 printk(" cr: 0x%02x\n", inb(EWRK3_CR
));
663 printk(" icr: 0x%02x\n", inb(EWRK3_ICR
));
664 printk(" cmr: 0x%02x\n", inb(EWRK3_CMR
));
665 printk(" fmqc: 0x%02x\n", inb(EWRK3_FMQC
));
669 dev
->interrupt
= UNMASK_INTERRUPTS
;
672 ** Unmask EWRK3 board interrupts
674 icr
= inb(EWRK3_ICR
);
681 printk("%s: ewrk3 available for hard strapped set up only.\n", dev
->name
);
682 printk(" Run the 'ewrk3setup' utility or remove the hard straps.\n");
691 ** Initialize the EtherWORKS 3 operating conditions
693 static void ewrk3_init(struct net_device
*dev
)
695 struct ewrk3_private
*lp
= (struct ewrk3_private
*) dev
->priv
;
697 u_long iobase
= dev
->base_addr
;
700 ** Enable any multicasts
702 set_multicast_list(dev
);
705 ** Clean out any remaining entries in all the queues here
707 while (inb(EWRK3_TQ
));
708 while (inb(EWRK3_TDQ
));
709 while (inb(EWRK3_RQ
));
710 while (inb(EWRK3_FMQ
));
713 ** Write a clean free memory queue
715 for (page
= 1; page
< lp
->mPage
; page
++) { /* Write the free page numbers */
716 outb(page
, EWRK3_FMQ
); /* to the Free Memory Queue */
719 lp
->lock
= 0; /* Ensure there are no locks */
721 START_EWRK3
; /* Enable the TX and/or RX */
725 ** Writes a socket buffer to the free page queue
727 static int ewrk3_queue_pkt(struct sk_buff
*skb
, struct net_device
*dev
)
729 struct ewrk3_private
*lp
= (struct ewrk3_private
*) dev
->priv
;
730 u_long iobase
= dev
->base_addr
;
734 /* Transmitter timeout, serious problems. */
735 if (dev
->tbusy
|| lp
->lock
) {
736 int tickssofar
= jiffies
- dev
->trans_start
;
737 if (tickssofar
< QUEUE_PKT_TIMEOUT
) {
739 } else if (!lp
->hard_strapped
) {
740 printk("%s: transmit timed/locked out, status %04x, resetting.\n",
741 dev
->name
, inb(EWRK3_CSR
));
744 ** Mask all board interrupts
749 ** Stop the TX and RX...
756 ** Unmask EWRK3 board interrupts
761 dev
->trans_start
= jiffies
;
763 } else if (skb
->len
> 0) {
766 ** Block a timer-based transmit from overlapping. This could better be
767 ** done with atomic_swap(1, dev->tbusy), but set_bit() works as well.
769 if (test_and_set_bit(0, (void *) &dev
->tbusy
) != 0)
770 printk("%s: Transmitter access conflict.\n", dev
->name
);
772 DISABLE_IRQs
; /* So that the page # remains correct */
775 ** Get a free page from the FMQ when resources are available
777 if (inb(EWRK3_FMQC
) > 0) {
781 if ((page
= inb(EWRK3_FMQ
)) < lp
->mPage
) {
783 ** Set up shared memory window and pointer into the window
785 while (test_and_set_bit(0, (void *) &lp
->lock
) != 0); /* Wait for lock to free */
786 if (lp
->shmem_length
== IO_ONLY
) {
787 outb(page
, EWRK3_IOPR
);
788 } else if (lp
->shmem_length
== SHMEM_2K
) {
789 buf
= lp
->shmem_base
;
790 outb(page
, EWRK3_MPR
);
791 } else if (lp
->shmem_length
== SHMEM_32K
) {
792 buf
= ((((short) page
<< 11) & 0x7800) + lp
->shmem_base
);
793 outb((page
>> 4), EWRK3_MPR
);
794 } else if (lp
->shmem_length
== SHMEM_64K
) {
795 buf
= ((((short) page
<< 11) & 0xf800) + lp
->shmem_base
);
796 outb((page
>> 5), EWRK3_MPR
);
799 printk("%s: Oops - your private data area is hosed!\n", dev
->name
);
805 ** Set up the buffer control structures and copy the data from
806 ** the socket buffer to the shared memory .
809 if (lp
->shmem_length
== IO_ONLY
) {
811 u_char
*p
= skb
->data
;
813 outb((char) (TCR_QMODE
| TCR_PAD
| TCR_IFC
), EWRK3_DATA
);
814 outb((char) (skb
->len
& 0xff), EWRK3_DATA
);
815 outb((char) ((skb
->len
>> 8) & 0xff), EWRK3_DATA
);
816 outb((char) 0x04, EWRK3_DATA
);
817 for (i
= 0; i
< skb
->len
; i
++) {
818 outb(*p
++, EWRK3_DATA
);
820 outb(page
, EWRK3_TQ
); /* Start sending pkt */
822 writeb((char) (TCR_QMODE
| TCR_PAD
| TCR_IFC
), (char *) buf
); /* ctrl byte */
824 writeb((char) (skb
->len
& 0xff), (char *) buf
); /* length (16 bit xfer) */
827 writeb((char) (((skb
->len
>> 8) & 0xff) | XCT
), (char *) buf
);
829 writeb(0x04, (char *) buf
); /* index byte */
831 writeb(0x00, (char *) (buf
+ skb
->len
)); /* Write the XCT flag */
832 memcpy_toio(buf
, skb
->data
, PRELOAD
); /* Write PRELOAD bytes */
833 outb(page
, EWRK3_TQ
); /* Start sending pkt */
834 memcpy_toio(buf
+ PRELOAD
, skb
->data
+ PRELOAD
, skb
->len
- PRELOAD
);
835 writeb(0xff, (char *) (buf
+ skb
->len
)); /* Write the XCT flag */
837 writeb((char) ((skb
->len
>> 8) & 0xff), (char *) buf
);
839 writeb(0x04, (char *) buf
); /* index byte */
841 memcpy_toio((char *) buf
, skb
->data
, skb
->len
); /* Write data bytes */
842 outb(page
, EWRK3_TQ
); /* Start sending pkt */
846 dev
->trans_start
= jiffies
;
849 } else { /* return unused page to the free memory queue */
850 outb(page
, EWRK3_FMQ
);
852 lp
->lock
= 0; /* unlock the page register */
854 printk("ewrk3_queue_pkt(): Invalid free memory page (%d).\n",
858 printk("ewrk3_queue_pkt(): No free resources...\n");
859 printk("ewrk3_queue_pkt(): CSR: %02x ICR: %02x FMQC: %02x\n", inb(EWRK3_CSR
), inb(EWRK3_ICR
), inb(EWRK3_FMQC
));
862 /* Check for free resources: clear 'tbusy' if there are some */
863 if (inb(EWRK3_FMQC
) > 0) {
872 ** The EWRK3 interrupt handler.
874 static void ewrk3_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
876 struct net_device
*dev
= dev_id
;
877 struct ewrk3_private
*lp
;
882 printk("ewrk3_interrupt(): irq %d for unknown device.\n", irq
);
884 lp
= (struct ewrk3_private
*) dev
->priv
;
885 iobase
= dev
->base_addr
;
888 printk("%s: Re-entering the interrupt handler.\n", dev
->name
);
890 dev
->interrupt
= MASK_INTERRUPTS
;
892 /* get the interrupt information */
893 csr
= inb(EWRK3_CSR
);
896 ** Mask the EWRK3 board interrupts and turn on the LED
904 if (csr
& CSR_RNE
) /* Rx interrupt (packet[s] arrived) */
907 if (csr
& CSR_TNE
) /* Tx interrupt (packet sent) */
911 ** Now deal with the TX/RX disable flags. These are set when there
912 ** are no more resources. If resources free up then enable these
913 ** interrupts, otherwise mask them - failure to do this will result
914 ** in the system hanging in an interrupt loop.
916 if (inb(EWRK3_FMQC
)) { /* any resources available? */
917 lp
->irq_mask
|= ICR_TXDM
| ICR_RXDM
; /* enable the interrupt source */
918 csr
&= ~(CSR_TXD
| CSR_RXD
); /* ensure restart of a stalled TX or RX */
919 outb(csr
, EWRK3_CSR
);
920 dev
->tbusy
= 0; /* clear TX busy flag */
923 lp
->irq_mask
&= ~(ICR_TXDM
| ICR_RXDM
); /* disable the interrupt source */
926 /* Unmask the EWRK3 board interrupts and turn off the LED */
930 dev
->interrupt
= UNMASK_INTERRUPTS
;
937 static int ewrk3_rx(struct net_device
*dev
)
939 struct ewrk3_private
*lp
= (struct ewrk3_private
*) dev
->priv
;
940 u_long iobase
= dev
->base_addr
;
942 u_char page
, tmpPage
= 0, tmpLock
= 0;
945 while (inb(EWRK3_RQC
) && !status
) { /* Whilst there's incoming data */
946 if ((page
= inb(EWRK3_RQ
)) < lp
->mPage
) { /* Get next entry's buffer page */
948 ** Preempt any process using the current page register. Check for
949 ** an existing lock to reduce time taken in I/O transactions.
951 if ((tmpLock
= test_and_set_bit(0, (void *) &lp
->lock
)) == 1) { /* Assert lock */
952 if (lp
->shmem_length
== IO_ONLY
) { /* Get existing page */
953 tmpPage
= inb(EWRK3_IOPR
);
955 tmpPage
= inb(EWRK3_MPR
);
959 ** Set up shared memory window and pointer into the window
961 if (lp
->shmem_length
== IO_ONLY
) {
962 outb(page
, EWRK3_IOPR
);
963 } else if (lp
->shmem_length
== SHMEM_2K
) {
964 buf
= lp
->shmem_base
;
965 outb(page
, EWRK3_MPR
);
966 } else if (lp
->shmem_length
== SHMEM_32K
) {
967 buf
= ((((short) page
<< 11) & 0x7800) + lp
->shmem_base
);
968 outb((page
>> 4), EWRK3_MPR
);
969 } else if (lp
->shmem_length
== SHMEM_64K
) {
970 buf
= ((((short) page
<< 11) & 0xf800) + lp
->shmem_base
);
971 outb((page
>> 5), EWRK3_MPR
);
974 printk("%s: Oops - your private data area is hosed!\n", dev
->name
);
981 if (lp
->shmem_length
== IO_ONLY
) {
982 rx_status
= inb(EWRK3_DATA
);
983 pkt_len
= inb(EWRK3_DATA
);
984 pkt_len
|= ((u_short
) inb(EWRK3_DATA
) << 8);
986 rx_status
= readb(buf
);
988 pkt_len
= readw(buf
);
992 if (!(rx_status
& R_ROK
)) { /* There was an error. */
993 lp
->stats
.rx_errors
++; /* Update the error stats. */
994 if (rx_status
& R_DBE
)
995 lp
->stats
.rx_frame_errors
++;
996 if (rx_status
& R_CRC
)
997 lp
->stats
.rx_crc_errors
++;
998 if (rx_status
& R_PLL
)
999 lp
->stats
.rx_fifo_errors
++;
1001 struct sk_buff
*skb
;
1003 if ((skb
= dev_alloc_skb(pkt_len
+ 2)) != NULL
) {
1006 skb_reserve(skb
, 2); /* Align to 16 bytes */
1007 p
= skb_put(skb
, pkt_len
);
1009 if (lp
->shmem_length
== IO_ONLY
) {
1010 *p
= inb(EWRK3_DATA
); /* dummy read */
1011 for (i
= 0; i
< pkt_len
; i
++) {
1012 *p
++ = inb(EWRK3_DATA
);
1015 memcpy_fromio(p
, buf
, pkt_len
);
1019 ** Notify the upper protocol layers that there is another
1022 skb
->protocol
= eth_type_trans(skb
, dev
);
1028 lp
->stats
.rx_packets
++;
1029 for (i
= 1; i
< EWRK3_PKT_STAT_SZ
- 1; i
++) {
1030 if (pkt_len
< i
* EWRK3_PKT_BIN_SZ
) {
1031 lp
->pktStats
.bins
[i
]++;
1032 i
= EWRK3_PKT_STAT_SZ
;
1035 p
= skb
->data
; /* Look at the dest addr */
1036 if (p
[0] & 0x01) { /* Multicast/Broadcast */
1037 if ((*(s32
*) & p
[0] == -1) && (*(s16
*) & p
[4] == -1)) {
1038 lp
->pktStats
.broadcast
++;
1040 lp
->pktStats
.multicast
++;
1042 } else if ((*(s32
*) & p
[0] == *(s32
*) & dev
->dev_addr
[0]) &&
1043 (*(s16
*) & p
[4] == *(s16
*) & dev
->dev_addr
[4])) {
1044 lp
->pktStats
.unicast
++;
1046 lp
->pktStats
.bins
[0]++; /* Duplicates stats.rx_packets */
1047 if (lp
->pktStats
.bins
[0] == 0) { /* Reset counters */
1048 memset(&lp
->pktStats
, 0, sizeof(lp
->pktStats
));
1051 printk("%s: Insufficient memory; nuking packet.\n", dev
->name
);
1052 lp
->stats
.rx_dropped
++; /* Really, deferred. */
1058 ** Return the received buffer to the free memory queue
1060 outb(page
, EWRK3_FMQ
);
1062 if (tmpLock
) { /* If a lock was preempted */
1063 if (lp
->shmem_length
== IO_ONLY
) { /* Replace old page */
1064 outb(tmpPage
, EWRK3_IOPR
);
1066 outb(tmpPage
, EWRK3_MPR
);
1069 lp
->lock
= 0; /* Unlock the page register */
1071 printk("ewrk3_rx(): Illegal page number, page %d\n", page
);
1072 printk("ewrk3_rx(): CSR: %02x ICR: %02x FMQC: %02x\n", inb(EWRK3_CSR
), inb(EWRK3_ICR
), inb(EWRK3_FMQC
));
1079 ** Buffer sent - check for TX buffer errors.
1081 static int ewrk3_tx(struct net_device
*dev
)
1083 struct ewrk3_private
*lp
= (struct ewrk3_private
*) dev
->priv
;
1084 u_long iobase
= dev
->base_addr
;
1087 while ((tx_status
= inb(EWRK3_TDQ
)) > 0) { /* Whilst there's old buffers */
1088 if (tx_status
& T_VSTS
) { /* The status is valid */
1089 if (tx_status
& T_TXE
) {
1090 lp
->stats
.tx_errors
++;
1091 if (tx_status
& T_NCL
)
1092 lp
->stats
.tx_carrier_errors
++;
1093 if (tx_status
& T_LCL
)
1094 lp
->stats
.tx_window_errors
++;
1095 if (tx_status
& T_CTU
) {
1096 if ((tx_status
& T_COLL
) ^ T_XUR
) {
1097 lp
->pktStats
.tx_underruns
++;
1099 lp
->pktStats
.excessive_underruns
++;
1101 } else if (tx_status
& T_COLL
) {
1102 if ((tx_status
& T_COLL
) ^ T_XCOLL
) {
1103 lp
->stats
.collisions
++;
1105 lp
->pktStats
.excessive_collisions
++;
1109 lp
->stats
.tx_packets
++;
1117 static int ewrk3_close(struct net_device
*dev
)
1119 struct ewrk3_private
*lp
= (struct ewrk3_private
*) dev
->priv
;
1120 u_long iobase
= dev
->base_addr
;
1126 if (ewrk3_debug
> 1) {
1127 printk("%s: Shutting down ethercard, status was %2.2x.\n",
1128 dev
->name
, inb(EWRK3_CSR
));
1131 ** We stop the EWRK3 here... mask interrupts and stop TX & RX
1138 ** Clean out the TX and RX queues here (note that one entry
1139 ** may get added to either the TXD or RX queues if the TX or RX
1140 ** just starts processing a packet before the STOP_EWRK3 command
1141 ** is received. This will be flushed in the ewrk3_open() call).
1143 while (inb(EWRK3_TQ
));
1144 while (inb(EWRK3_TDQ
));
1145 while (inb(EWRK3_RQ
));
1147 if (!lp
->hard_strapped
) {
1148 free_irq(dev
->irq
, dev
);
1155 static struct net_device_stats
*ewrk3_get_stats(struct net_device
*dev
)
1157 struct ewrk3_private
*lp
= (struct ewrk3_private
*) dev
->priv
;
1159 /* Null body since there is no framing error counter */
1164 ** Set or clear the multicast filter for this adapter.
1166 static void set_multicast_list(struct net_device
*dev
)
1168 struct ewrk3_private
*lp
= (struct ewrk3_private
*) dev
->priv
;
1169 u_long iobase
= dev
->base_addr
;
1172 csr
= inb(EWRK3_CSR
);
1174 if (lp
->shmem_length
== IO_ONLY
) {
1175 lp
->mctbl
= (char *) PAGE0_HTE
;
1177 lp
->mctbl
= (char *) (lp
->shmem_base
+ PAGE0_HTE
);
1180 csr
&= ~(CSR_PME
| CSR_MCE
);
1181 if (dev
->flags
& IFF_PROMISC
) { /* set promiscuous mode */
1183 outb(csr
, EWRK3_CSR
);
1185 SetMulticastFilter(dev
);
1187 outb(csr
, EWRK3_CSR
);
1192 ** Calculate the hash code and update the logical address filter
1193 ** from a list of ethernet multicast addresses.
1194 ** Little endian crc one liner from Matt Thomas, DEC.
1196 ** Note that when clearing the table, the broadcast bit must remain asserted
1197 ** to receive broadcast messages.
1199 static void SetMulticastFilter(struct net_device
*dev
)
1201 struct ewrk3_private
*lp
= (struct ewrk3_private
*) dev
->priv
;
1202 struct dev_mc_list
*dmi
= dev
->mc_list
;
1203 u_long iobase
= dev
->base_addr
;
1205 char *addrs
, j
, bit
, byte
;
1206 short *p
= (short *) lp
->mctbl
;
1208 s32 crc
, poly
= CRC_POLYNOMIAL_LE
;
1210 while (test_and_set_bit(0, (void *) &lp
->lock
) != 0); /* Wait for lock to free */
1212 if (lp
->shmem_length
== IO_ONLY
) {
1213 outb(0, EWRK3_IOPR
);
1214 outw(EEPROM_OFFSET(lp
->mctbl
), EWRK3_PIR1
);
1219 if (dev
->flags
& IFF_ALLMULTI
) {
1220 for (i
= 0; i
< (HASH_TABLE_LEN
>> 3); i
++) {
1221 if (lp
->shmem_length
== IO_ONLY
) {
1222 outb(0xff, EWRK3_DATA
);
1223 } else { /* memset didn't work here */
1230 /* Clear table except for broadcast bit */
1231 if (lp
->shmem_length
== IO_ONLY
) {
1232 for (i
= 0; i
< (HASH_TABLE_LEN
>> 4) - 1; i
++) {
1233 outb(0x00, EWRK3_DATA
);
1235 outb(0x80, EWRK3_DATA
);
1236 i
++; /* insert the broadcast bit */
1237 for (; i
< (HASH_TABLE_LEN
>> 3); i
++) {
1238 outb(0x00, EWRK3_DATA
);
1241 memset_io(lp
->mctbl
, 0, (HASH_TABLE_LEN
>> 3));
1242 writeb(0x80, (char *) (lp
->mctbl
+ (HASH_TABLE_LEN
>> 4) - 1));
1246 for (i
= 0; i
< dev
->mc_count
; i
++) { /* for each address in the list */
1247 addrs
= dmi
->dmi_addr
;
1249 if ((*addrs
& 0x01) == 1) { /* multicast address? */
1250 crc
= 0xffffffff; /* init CRC for each address */
1251 for (byte
= 0; byte
< ETH_ALEN
; byte
++) { /* for each address byte */
1252 /* process each address bit */
1253 for (bit
= *addrs
++, j
= 0; j
< 8; j
++, bit
>>= 1) {
1254 crc
= (crc
>> 1) ^ (((crc
^ bit
) & 0x01) ? poly
: 0);
1257 hashcode
= crc
& ((1 << 9) - 1); /* hashcode is 9 LSb of CRC */
1259 byte
= hashcode
>> 3; /* bit[3-8] -> byte in filter */
1260 bit
= 1 << (hashcode
& 0x07); /* bit[0-2] -> bit in byte */
1262 if (lp
->shmem_length
== IO_ONLY
) {
1265 outw((short) ((long) lp
->mctbl
) + byte
, EWRK3_PIR1
);
1266 tmp
= inb(EWRK3_DATA
);
1268 outw((short) ((long) lp
->mctbl
) + byte
, EWRK3_PIR1
);
1269 outb(tmp
, EWRK3_DATA
);
1271 writeb(readb(lp
->mctbl
+ byte
) | bit
, lp
->mctbl
+ byte
);
1277 lp
->lock
= 0; /* Unlock the page register */
1283 ** ISA bus I/O device probe
1285 static void __init
isa_probe(struct net_device
*dev
, u_long ioaddr
)
1287 int i
= num_ewrk3s
, maxSlots
;
1290 if (!ioaddr
&& autoprobed
)
1291 return; /* Been here before ! */
1292 if (ioaddr
>= 0x400)
1293 return; /* Not ISA */
1295 if (ioaddr
== 0) { /* Autoprobing */
1296 iobase
= EWRK3_IO_BASE
; /* Get the first slot address */
1298 } else { /* Probe a specific location */
1303 for (; (i
< maxSlots
) && (dev
!= NULL
); iobase
+= EWRK3_IOP_INC
, i
++) {
1304 if (!check_region(iobase
, EWRK3_TOTAL_SIZE
)) {
1305 if (DevicePresent(iobase
) == 0) {
1306 if ((dev
= alloc_device(dev
, iobase
)) != NULL
) {
1307 if (ewrk3_hw_init(dev
, iobase
) == 0) {
1313 } else if (autoprobed
) {
1314 printk("%s: region already allocated at 0x%04lx.\n", dev
->name
, iobase
);
1322 ** EISA bus I/O device probe. Probe from slot 1 since slot 0 is usually
1325 static void __init
eisa_probe(struct net_device
*dev
, u_long ioaddr
)
1329 char name
[EWRK3_STRLEN
];
1331 if (!ioaddr
&& autoprobed
)
1332 return; /* Been here before ! */
1333 if (ioaddr
< 0x1000)
1334 return; /* Not EISA */
1336 if (ioaddr
== 0) { /* Autoprobing */
1337 iobase
= EISA_SLOT_INC
; /* Get the first slot address */
1339 maxSlots
= MAX_EISA_SLOTS
;
1340 } else { /* Probe a specific location */
1346 for (i
= 1; (i
< maxSlots
) && (dev
!= NULL
); i
++, iobase
+= EISA_SLOT_INC
) {
1347 if (EISA_signature(name
, EISA_ID
) == 0) {
1348 if (!check_region(iobase
, EWRK3_TOTAL_SIZE
)) {
1349 if (DevicePresent(iobase
) == 0) {
1350 if ((dev
= alloc_device(dev
, iobase
)) != NULL
) {
1351 if (ewrk3_hw_init(dev
, iobase
) == 0) {
1357 } else if (autoprobed
) {
1358 printk("%s: region already allocated at 0x%04lx.\n", dev
->name
, iobase
);
1367 ** Search the entire 'eth' device list for a fixed probe. If a match isn't
1368 ** found then check for an autoprobe or unused device location. If they
1369 ** are not available then insert a new device structure at the end of
1370 ** the current list.
1372 static struct net_device
* __init
1373 alloc_device(struct net_device
*dev
, u_long iobase
)
1375 struct net_device
*adev
= NULL
;
1376 int fixed
= 0, new_dev
= 0;
1378 num_eth
= ewrk3_dev_index(dev
->name
);
1383 if (((dev
->base_addr
== EWRK3_NDA
) || (dev
->base_addr
== 0)) && !adev
) {
1385 } else if ((dev
->priv
== NULL
) && (dev
->base_addr
== iobase
)) {
1388 if (dev
->next
== NULL
) {
1390 } else if (strncmp(dev
->next
->name
, "eth", 3) != 0) {
1394 if ((dev
->next
== NULL
) || new_dev
|| fixed
)
1399 if (adev
&& !fixed
) {
1401 num_eth
= ewrk3_dev_index(dev
->name
);
1404 if (((dev
->next
== NULL
) &&
1405 ((dev
->base_addr
!= EWRK3_NDA
) && (dev
->base_addr
!= 0)) && !fixed
) ||
1407 num_eth
++; /* New device */
1408 dev
= insert_device(dev
, iobase
, ewrk3_probe
);
1414 ** If at end of eth device list and can't use current entry, malloc
1415 ** one up. If memory could not be allocated, print an error message.
1417 static struct net_device
* __init
1418 insert_device(struct net_device
*dev
, u_long iobase
, int (*init
) (struct net_device
*))
1420 struct net_device
*new;
1422 new = (struct net_device
*) kmalloc(sizeof(struct net_device
) + 8, GFP_KERNEL
);
1424 printk("eth%d: Device not initialised, insufficient memory\n", num_eth
);
1427 new->next
= dev
->next
;
1429 dev
= dev
->next
; /* point to the new device */
1430 dev
->name
= (char *) (dev
+ 1);
1431 if (num_eth
> 9999) {
1432 sprintf(dev
->name
, "eth????"); /* New device name */
1434 sprintf(dev
->name
, "eth%d", num_eth
); /* New device name */
1436 dev
->base_addr
= iobase
; /* assign the io address */
1437 dev
->init
= init
; /* initialisation routine */
1444 ewrk3_dev_index(char *s
)
1451 i
= (i
* 10) + (*s
- '0');
1460 ** Read the EWRK3 EEPROM using this routine
1462 static int Read_EEPROM(u_long iobase
, u_char eaddr
)
1466 outb((eaddr
& 0x3f), EWRK3_PIR1
); /* set up 6 bits of address info */
1467 outb(EEPROM_RD
, EWRK3_IOPR
); /* issue read command */
1468 for (i
= 0; i
< 5000; i
++)
1469 inb(EWRK3_CSR
); /* wait 1msec */
1471 return inw(EWRK3_EPROM1
); /* 16 bits data return */
1475 ** Write the EWRK3 EEPROM using this routine
1477 static int Write_EEPROM(short data
, u_long iobase
, u_char eaddr
)
1481 outb(EEPROM_WR_EN
, EWRK3_IOPR
); /* issue write enable command */
1482 for (i
= 0; i
< 5000; i
++)
1483 inb(EWRK3_CSR
); /* wait 1msec */
1484 outw(data
, EWRK3_EPROM1
); /* write data to register */
1485 outb((eaddr
& 0x3f), EWRK3_PIR1
); /* set up 6 bits of address info */
1486 outb(EEPROM_WR
, EWRK3_IOPR
); /* issue write command */
1487 for (i
= 0; i
< 75000; i
++)
1488 inb(EWRK3_CSR
); /* wait 15msec */
1489 outb(EEPROM_WR_DIS
, EWRK3_IOPR
); /* issue write disable command */
1490 for (i
= 0; i
< 5000; i
++)
1491 inb(EWRK3_CSR
); /* wait 1msec */
1497 ** Look for a particular board name in the on-board EEPROM.
1499 static void __init
EthwrkSignature(char *name
, char *eeprom_image
)
1502 char *signatures
[] = EWRK3_SIGNATURE
;
1505 for (i
= 0; *signatures
[i
] != '\0' && *name
== '\0'; i
++) {
1506 for (j
= EEPROM_PNAME7
, k
= 0; j
<= EEPROM_PNAME0
&& k
< strlen(signatures
[i
]); j
++) {
1507 if (signatures
[i
][k
] == eeprom_image
[j
]) { /* track signature */
1509 } else { /* lost signature; begin search again */
1513 if (k
== strlen(signatures
[i
])) {
1514 for (k
= 0; k
< EWRK3_STRLEN
; k
++) {
1515 name
[k
] = eeprom_image
[EEPROM_PNAME7
+ k
];
1516 name
[EWRK3_STRLEN
] = '\0';
1521 return; /* return the device name string */
1525 ** Look for a special sequence in the Ethernet station address PROM that
1526 ** is common across all EWRK3 products.
1528 ** Search the Ethernet address ROM for the signature. Since the ROM address
1529 ** counter can start at an arbitrary point, the search must include the entire
1530 ** probe sequence length plus the (length_of_the_signature - 1).
1531 ** Stop the search IMMEDIATELY after the signature is found so that the
1532 ** PROM address counter is correctly positioned at the start of the
1533 ** ethernet address for later read out.
1536 static int __init
DevicePresent(u_long iobase
)
1543 char Sig
[sizeof(u32
) << 1];
1548 int i
, j
, status
= 0;
1550 dev
.llsig
.a
= ETH_PROM_SIG
;
1551 dev
.llsig
.b
= ETH_PROM_SIG
;
1552 sigLength
= sizeof(u32
) << 1;
1554 for (i
= 0, j
= 0; j
< sigLength
&& i
< PROBE_LENGTH
+ sigLength
- 1; i
++) {
1555 data
= inb(EWRK3_APROM
);
1556 if (dev
.Sig
[j
] == data
) { /* track signature */
1558 } else { /* lost signature; begin search again */
1559 if (data
== dev
.Sig
[0]) {
1567 if (j
!= sigLength
) {
1568 status
= -ENODEV
; /* search failed */
1573 static u_char __init
get_hw_addr(struct net_device
*dev
, u_char
* eeprom_image
, char chipType
)
1577 u_char crc
, lfsr
, sd
, status
= 0;
1578 u_long iobase
= dev
->base_addr
;
1581 if (chipType
== LeMAC2
) {
1582 for (crc
= 0x6a, j
= 0; j
< ETH_ALEN
; j
++) {
1583 sd
= dev
->dev_addr
[j
] = eeprom_image
[EEPROM_PADDR0
+ j
];
1584 outb(dev
->dev_addr
[j
], EWRK3_PAR0
+ j
);
1585 for (k
= 0; k
< 8; k
++, sd
>>= 1) {
1586 lfsr
= ((((crc
& 0x02) >> 1) ^ (crc
& 0x01)) ^ (sd
& 0x01)) << 7;
1587 crc
= (crc
>> 1) + lfsr
;
1590 if (crc
!= eeprom_image
[EEPROM_PA_CRC
])
1593 for (i
= 0, k
= 0; i
< ETH_ALEN
;) {
1598 k
+= (u_char
) (tmp
= inb(EWRK3_APROM
));
1599 dev
->dev_addr
[i
] = (u_char
) tmp
;
1600 outb(dev
->dev_addr
[i
], EWRK3_PAR0
+ i
);
1602 k
+= (u_short
) ((tmp
= inb(EWRK3_APROM
)) << 8);
1603 dev
->dev_addr
[i
] = (u_char
) tmp
;
1604 outb(dev
->dev_addr
[i
], EWRK3_PAR0
+ i
);
1612 chksum
= inb(EWRK3_APROM
);
1613 chksum
|= (inb(EWRK3_APROM
) << 8);
1622 ** Look for a particular board name in the EISA configuration space
1624 static int __init
EISA_signature(char *name
, s32 eisa_id
)
1627 char *signatures
[] = EWRK3_SIGNATURE
;
1628 char ManCode
[EWRK3_STRLEN
];
1636 for (i
= 0; i
< 4; i
++) {
1637 Eisa
.Id
[i
] = inb(eisa_id
+ i
);
1640 ManCode
[0] = (((Eisa
.Id
[0] >> 2) & 0x1f) + 0x40);
1641 ManCode
[1] = (((Eisa
.Id
[1] & 0xe0) >> 5) + ((Eisa
.Id
[0] & 0x03) << 3) + 0x40);
1642 ManCode
[2] = (((Eisa
.Id
[2] >> 4) & 0x0f) + 0x30);
1643 ManCode
[3] = ((Eisa
.Id
[2] & 0x0f) + 0x30);
1644 ManCode
[4] = (((Eisa
.Id
[3] >> 4) & 0x0f) + 0x30);
1647 for (i
= 0; (*signatures
[i
] != '\0') && (*name
== '\0'); i
++) {
1648 if (strstr(ManCode
, signatures
[i
]) != NULL
) {
1649 strcpy(name
, ManCode
);
1654 return status
; /* return the device name string */
1658 ** Perform IOCTL call functions here. Some are privileged operations and the
1659 ** effective uid is checked in those cases.
1661 static int ewrk3_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
1663 struct ewrk3_private
*lp
= (struct ewrk3_private
*) dev
->priv
;
1664 struct ewrk3_ioctl
*ioc
= (struct ewrk3_ioctl
*) &rq
->ifr_data
;
1665 u_long iobase
= dev
->base_addr
;
1666 int i
, j
, status
= 0;
1669 u_char addr
[HASH_TABLE_LEN
* ETH_ALEN
];
1670 u_short val
[(HASH_TABLE_LEN
* ETH_ALEN
) >> 1];
1674 case EWRK3_GET_HWADDR
: /* Get the hardware address */
1675 for (i
= 0; i
< ETH_ALEN
; i
++) {
1676 tmp
.addr
[i
] = dev
->dev_addr
[i
];
1678 ioc
->len
= ETH_ALEN
;
1679 if (copy_to_user(ioc
->data
, tmp
.addr
, ioc
->len
)) {
1683 case EWRK3_SET_HWADDR
: /* Set the hardware address */
1684 if (capable(CAP_NET_ADMIN
)) {
1685 csr
= inb(EWRK3_CSR
);
1686 csr
|= (CSR_TXD
| CSR_RXD
);
1687 outb(csr
, EWRK3_CSR
); /* Disable the TX and RX */
1689 if (copy_from_user(tmp
.addr
, ioc
->data
, ETH_ALEN
)) {
1693 for (i
= 0; i
< ETH_ALEN
; i
++) {
1694 dev
->dev_addr
[i
] = tmp
.addr
[i
];
1695 outb(tmp
.addr
[i
], EWRK3_PAR0
+ i
);
1698 csr
&= ~(CSR_TXD
| CSR_RXD
); /* Enable the TX and RX */
1699 outb(csr
, EWRK3_CSR
);
1705 case EWRK3_SET_PROM
: /* Set Promiscuous Mode */
1706 if (capable(CAP_NET_ADMIN
)) {
1707 csr
= inb(EWRK3_CSR
);
1710 outb(csr
, EWRK3_CSR
);
1716 case EWRK3_CLR_PROM
: /* Clear Promiscuous Mode */
1717 if (capable(CAP_NET_ADMIN
)) {
1718 csr
= inb(EWRK3_CSR
);
1720 outb(csr
, EWRK3_CSR
);
1726 case EWRK3_SAY_BOO
: /* Say "Boo!" to the kernel log file */
1727 printk("%s: Boo!\n", dev
->name
);
1730 case EWRK3_GET_MCA
: /* Get the multicast address table */
1731 while (test_and_set_bit(0, (void *) &lp
->lock
) != 0); /* Wait for lock to free */
1732 if (lp
->shmem_length
== IO_ONLY
) {
1733 outb(0, EWRK3_IOPR
);
1734 outw(PAGE0_HTE
, EWRK3_PIR1
);
1735 for (i
= 0; i
< (HASH_TABLE_LEN
>> 3); i
++) {
1736 tmp
.addr
[i
] = inb(EWRK3_DATA
);
1740 memcpy_fromio(tmp
.addr
, (char *) (lp
->shmem_base
+ PAGE0_HTE
), (HASH_TABLE_LEN
>> 3));
1742 ioc
->len
= (HASH_TABLE_LEN
>> 3);
1743 if (copy_to_user(ioc
->data
, tmp
.addr
, ioc
->len
)) {
1748 lp
->lock
= 0; /* Unlock the page register */
1751 case EWRK3_SET_MCA
: /* Set a multicast address */
1752 if (capable(CAP_NET_ADMIN
)) {
1753 if (copy_from_user(tmp
.addr
, ioc
->data
, ETH_ALEN
* ioc
->len
)) {
1757 set_multicast_list(dev
);
1763 case EWRK3_CLR_MCA
: /* Clear all multicast addresses */
1764 if (capable(CAP_NET_ADMIN
)) {
1765 set_multicast_list(dev
);
1771 case EWRK3_MCA_EN
: /* Enable multicast addressing */
1772 if (capable(CAP_NET_ADMIN
)) {
1773 csr
= inb(EWRK3_CSR
);
1776 outb(csr
, EWRK3_CSR
);
1782 case EWRK3_GET_STATS
: /* Get the driver statistics */
1784 ioc
->len
= sizeof(lp
->pktStats
);
1785 if (copy_to_user(ioc
->data
, &lp
->pktStats
, ioc
->len
))
1790 case EWRK3_CLR_STATS
: /* Zero out the driver statistics */
1791 if (capable(CAP_NET_ADMIN
)) {
1793 memset(&lp
->pktStats
, 0, sizeof(lp
->pktStats
));
1800 case EWRK3_GET_CSR
: /* Get the CSR Register contents */
1801 tmp
.addr
[0] = inb(EWRK3_CSR
);
1803 if (copy_to_user(ioc
->data
, tmp
.addr
, ioc
->len
))
1806 case EWRK3_SET_CSR
: /* Set the CSR Register contents */
1807 if (capable(CAP_NET_ADMIN
)) {
1808 if (copy_from_user(tmp
.addr
, ioc
->data
, 1)) {
1812 outb(tmp
.addr
[0], EWRK3_CSR
);
1818 case EWRK3_GET_EEPROM
: /* Get the EEPROM contents */
1819 if (capable(CAP_NET_ADMIN
)) {
1820 for (i
= 0; i
< (EEPROM_MAX
>> 1); i
++) {
1821 tmp
.val
[i
] = (short) Read_EEPROM(iobase
, i
);
1824 tmp
.addr
[i
++] = inb(EWRK3_CMR
); /* Config/Management Reg. */
1825 for (j
= 0; j
< ETH_ALEN
; j
++) {
1826 tmp
.addr
[i
++] = inb(EWRK3_PAR0
+ j
);
1828 ioc
->len
= EEPROM_MAX
+ 1 + ETH_ALEN
;
1829 if (copy_to_user(ioc
->data
, tmp
.addr
, ioc
->len
))
1836 case EWRK3_SET_EEPROM
: /* Set the EEPROM contents */
1837 if (capable(CAP_NET_ADMIN
)) {
1838 if (copy_from_user(tmp
.addr
, ioc
->data
, EEPROM_MAX
)) {
1842 for (i
= 0; i
< (EEPROM_MAX
>> 1); i
++) {
1843 Write_EEPROM(tmp
.val
[i
], iobase
, i
);
1850 case EWRK3_GET_CMR
: /* Get the CMR Register contents */
1851 tmp
.addr
[0] = inb(EWRK3_CMR
);
1853 if (copy_to_user(ioc
->data
, tmp
.addr
, ioc
->len
))
1856 case EWRK3_SET_TX_CUT_THRU
: /* Set TX cut through mode */
1864 case EWRK3_CLR_TX_CUT_THRU
: /* Clear TX cut through mode */
1873 status
= -EOPNOTSUPP
;
1880 static char devicename
[9] =
1882 static struct net_device thisEthwrk
=
1884 devicename
, /* device name is inserted by /linux/drivers/net/net_init.c */
1886 0x300, 5, /* I/O address, IRQ */
1887 0, 0, 0, NULL
, ewrk3_probe
};
1889 static int io
= 0x300; /* <--- EDIT THESE LINES FOR YOUR CONFIGURATION */
1890 static int irq
= 5; /* or use the insmod io= irq= options */
1892 MODULE_PARM(io
, "i");
1893 MODULE_PARM(irq
, "i");
1895 int init_module(void)
1897 thisEthwrk
.base_addr
= io
;
1898 thisEthwrk
.irq
= irq
;
1899 if (register_netdev(&thisEthwrk
) != 0)
1904 void cleanup_module(void)
1906 unregister_netdev(&thisEthwrk
);
1907 if (thisEthwrk
.priv
) {
1908 kfree(thisEthwrk
.priv
);
1909 thisEthwrk
.priv
= NULL
;
1913 release_region(thisEthwrk
.base_addr
, EWRK3_TOTAL_SIZE
);
1920 * compile-command: "gcc -D__KERNEL__ -I/linux/include -Wall -Wstrict-prototypes -fomit-frame-pointer -fno-strength-reduce -malign-loops=2 -malign-jumps=2 -malign-functions=2 -O2 -m486 -c ewrk3.c"
1922 * compile-command: "gcc -D__KERNEL__ -DMODULE -I/linux/include -Wall -Wstrict-prototypes -fomit-frame-pointer -fno-strength-reduce -malign-loops=2 -malign-jumps=2 -malign-functions=2 -O2 -m486 -c ewrk3.c"