1 /* ewrk3.c: A DIGITAL EtherWORKS 3 ethernet driver for Linux.
2
3 Written 1994 by David C. Davies.
4
5 Copyright 1994 Digital Equipment Corporation.
6
7 This software may be used and distributed according to the terms of
8 the GNU General Public License, incorporated herein by reference.
9
10 This driver is written for the Digital Equipment Corporation series
11 of EtherWORKS ethernet cards:
12
13 DE203 Turbo (BNC)
14 DE204 Turbo (TP)
15 DE205 Turbo (TP BNC)
16
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.
20
21 The author may be reached at davies@maniac.ultranet.com.
22
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.
27
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.
32
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.
38
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:
43
44 FORCE_2K_MODE;
45
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.
49
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) ...
55
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
58 {5,10,11,15}.
59
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).
63
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:
67
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
70 temporary directory.
71 2) edit the source code near line 1898 to reflect the I/O address and
72 IRQ you're using.
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.
77 5) insmod ewrk3.o
78 [Alan Cox: Changed this so you can insmod ewrk3.o irq=x io=y]
79 [Adam Kropelin: now accepts irq=x1,x2 io=y1,y2 for multiple cards]
80 6) run the net startup bits for your new eth?? interface manually
81 (usually /etc/rc.inet[12] at boot time).
82 7) enjoy!
83
84 Note that autoprobing is not allowed in loadable modules - the system is
85 already up and running and you're messing with interrupts.
86
87 To unload a module, turn off the associated interface
88 'ifconfig eth?? down' then 'rmmod ewrk3'.
89
90 Promiscuous mode has been turned off in this driver, but all the
91 multicast address bits have been turned on. This improved the send
92 performance on a busy network by about 13%.
93
94 Ioctl's have now been provided (primarily because I wanted to grab some
95 packet size statistics). They are patterned after 'plipconfig.c' from a
96 suggestion by Alan Cox. Using these ioctls, you can enable promiscuous
97 mode, add/delete multicast addresses, change the hardware address, get
98 packet size distribution statistics and muck around with the control and
99 status register. I'll add others if and when the need arises.
100
101 TO DO:
102 ------
103
104
105 Revision History
106 ----------------
107
108 Version Date Description
109
110 0.1 26-aug-94 Initial writing. ALPHA code release.
111 0.11 31-aug-94 Fixed: 2k mode memory base calc.,
112 LeMAC version calc.,
113 IRQ vector assignments during autoprobe.
114 0.12 31-aug-94 Tested working on LeMAC2 (DE20[345]-AC) card.
115 Fixed up MCA hash table algorithm.
116 0.20 4-sep-94 Added IOCTL functionality.
117 0.21 14-sep-94 Added I/O mode.
118 0.21axp 15-sep-94 Special version for ALPHA AXP Linux V1.0.
119 0.22 16-sep-94 Added more IOCTLs & tidied up.
120 0.23 21-sep-94 Added transmit cut through.
121 0.24 31-oct-94 Added uid checks in some ioctls.
122 0.30 1-nov-94 BETA code release.
123 0.31 5-dec-94 Added check/allocate region code.
124 0.32 16-jan-95 Broadcast packet fix.
125 0.33 10-Feb-95 Fix recognition bug reported by <bkm@star.rl.ac.uk>.
126 0.40 27-Dec-95 Rationalise MODULE and autoprobe code.
127 Rewrite for portability & updated.
128 ALPHA support from <jestabro@amt.tay1.dec.com>
129 Added verify_area() calls in ewrk3_ioctl() from
130 suggestion by <heiko@colossus.escape.de>.
131 Add new multicasting code.
132 0.41 20-Jan-96 Fix IRQ set up problem reported by
133 <kenneth@bbs.sas.ntu.ac.sg>.
134 0.42 22-Apr-96 Fix alloc_device() bug <jari@markkus2.fimr.fi>
135 0.43 16-Aug-96 Update alloc_device() to conform to de4x5.c
136 0.44 08-Nov-01 use library crc32 functions <Matt_Domsch@dell.com>
137 0.45 19-Jul-02 fix unaligned access on alpha <martin@bruli.net>
138 0.46 10-Oct-02 Multiple NIC support when module <akropel1@rochester.rr.com>
139 0.47 18-Oct-02 ethtool support <akropel1@rochester.rr.com>
140 0.48 18-Oct-02 cli/sti removal for 2.5 <vda@port.imtp.ilyichevsk.odessa.ua>
141 ioctl locking, signature search cleanup <akropel1@rochester.rr.com>
142
143 =========================================================================
144 */
145
146 #include <linux/module.h>
147
148 #include <linux/kernel.h>
149 #include <linux/sched.h>
150 #include <linux/string.h>
151 #include <linux/errno.h>
152 #include <linux/ioport.h>
153 #include <linux/slab.h>
154 #include <linux/interrupt.h>
155 #include <linux/delay.h>
156 #include <linux/init.h>
157 #include <linux/crc32.h>
158 #include <asm/bitops.h>
159 #include <asm/io.h>
160 #include <asm/dma.h>
161 #include <asm/uaccess.h>
162
163 #include <linux/netdevice.h>
164 #include <linux/etherdevice.h>
165 #include <linux/skbuff.h>
166 #include <linux/ethtool.h>
167
168 #include <linux/time.h>
169 #include <linux/types.h>
170 #include <linux/unistd.h>
171 #include <linux/ctype.h>
172
173 #include "ewrk3.h"
174
175 #define DRV_NAME "ewrk3"
176 #define DRV_VERSION "0.48"
177
178 static char version[] __initdata =
179 DRV_NAME ":v" DRV_VERSION " 2002/10/18 davies@maniac.ultranet.com\n";
180
181 #ifdef EWRK3_DEBUG
182 static int ewrk3_debug = EWRK3_DEBUG;
183 #else
184 static int ewrk3_debug = 1;
185 #endif
186
187 #define EWRK3_NDA 0xffe0 /* No Device Address */
188
189 #define PROBE_LENGTH 32
190 #define ETH_PROM_SIG 0xAA5500FFUL
191
192 #ifndef EWRK3_SIGNATURE
193 #define EWRK3_SIGNATURE {"DE203","DE204","DE205",""}
194 #define EWRK3_STRLEN 8
195 #endif
196
197 #ifndef EWRK3_RAM_BASE_ADDRESSES
198 #define EWRK3_RAM_BASE_ADDRESSES {0xc0000,0xd0000,0x00000}
199 #endif
200
201 /*
202 ** Sets up the I/O area for the autoprobe.
203 */
204 #define EWRK3_IO_BASE 0x100 /* Start address for probe search */
205 #define EWRK3_IOP_INC 0x20 /* I/O address increment */
206 #define EWRK3_TOTAL_SIZE 0x20 /* required I/O address length */
207
208 /* If you change this, remember to also change MODULE_PARM array limits */
209 #ifndef MAX_NUM_EWRK3S
210 #define MAX_NUM_EWRK3S 21
211 #endif
212
213 #ifndef EWRK3_EISA_IO_PORTS
214 #define EWRK3_EISA_IO_PORTS 0x0c00 /* I/O port base address, slot 0 */
215 #endif
216
217 #ifndef MAX_EISA_SLOTS
218 #define MAX_EISA_SLOTS 16
219 #define EISA_SLOT_INC 0x1000
220 #endif
221
222 #define QUEUE_PKT_TIMEOUT (1*HZ) /* Jiffies */
223
224 /*
225 ** EtherWORKS 3 shared memory window sizes
226 */
227 #define IO_ONLY 0x00
228 #define SHMEM_2K 0x800
229 #define SHMEM_32K 0x8000
230 #define SHMEM_64K 0x10000
231
232 /*
233 ** EtherWORKS 3 IRQ ENABLE/DISABLE
234 */
235 #define ENABLE_IRQs { \
236 icr |= lp->irq_mask;\
237 outb(icr, EWRK3_ICR); /* Enable the IRQs */\
238 }
239
240 #define DISABLE_IRQs { \
241 icr = inb(EWRK3_ICR);\
242 icr &= ~lp->irq_mask;\
243 outb(icr, EWRK3_ICR); /* Disable the IRQs */\
244 }
245
246 /*
247 ** EtherWORKS 3 START/STOP
248 */
249 #define START_EWRK3 { \
250 csr = inb(EWRK3_CSR);\
251 csr &= ~(CSR_TXD|CSR_RXD);\
252 outb(csr, EWRK3_CSR); /* Enable the TX and/or RX */\
253 }
254
255 #define STOP_EWRK3 { \
256 csr = (CSR_TXD|CSR_RXD);\
257 outb(csr, EWRK3_CSR); /* Disable the TX and/or RX */\
258 }
259
260 /*
261 ** The EtherWORKS 3 private structure
262 */
263 #define EWRK3_PKT_STAT_SZ 16
264 #define EWRK3_PKT_BIN_SZ 128 /* Should be >=100 unless you
265 increase EWRK3_PKT_STAT_SZ */
266
267 struct ewrk3_stats {
268 u32 bins[EWRK3_PKT_STAT_SZ];
269 u32 unicast;
270 u32 multicast;
271 u32 broadcast;
272 u32 excessive_collisions;
273 u32 tx_underruns;
274 u32 excessive_underruns;
275 };
276
277 struct ewrk3_private {
278 char adapter_name[80]; /* Name exported to /proc/ioports */
279 u_long shmem_base; /* Shared memory start address */
280 u_long shmem_length; /* Shared memory window length */
281 struct net_device_stats stats; /* Public stats */
282 struct ewrk3_stats pktStats; /* Private stats counters */
283 u_char irq_mask; /* Adapter IRQ mask bits */
284 u_char mPage; /* Maximum 2kB Page number */
285 u_char lemac; /* Chip rev. level */
286 u_char hard_strapped; /* Don't allow a full open */
287 u_char txc; /* Transmit cut through */
288 u_char *mctbl; /* Pointer to the multicast table */
289 u_char led_mask; /* Used to reserve LED access for ethtool */
290 spinlock_t hw_lock;
291 };
292
293 /*
294 ** Force the EtherWORKS 3 card to be in 2kB MODE
295 */
296 #define FORCE_2K_MODE { \
297 shmem_length = SHMEM_2K;\
298 outb(((mem_start - 0x80000) >> 11), EWRK3_MBR);\
299 }
300
301 /*
302 ** Public Functions
303 */
304 static int ewrk3_open(struct net_device *dev);
305 static int ewrk3_queue_pkt(struct sk_buff *skb, struct net_device *dev);
306 static void ewrk3_interrupt(int irq, void *dev_id, struct pt_regs *regs);
307 static int ewrk3_close(struct net_device *dev);
308 static struct net_device_stats *ewrk3_get_stats(struct net_device *dev);
309 static void set_multicast_list(struct net_device *dev);
310 static int ewrk3_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
311
312 /*
313 ** Private functions
314 */
315 static int ewrk3_hw_init(struct net_device *dev, u_long iobase);
316 static void ewrk3_init(struct net_device *dev);
317 static int ewrk3_rx(struct net_device *dev);
318 static int ewrk3_tx(struct net_device *dev);
319 static void ewrk3_timeout(struct net_device *dev);
320
321 static void EthwrkSignature(char *name, char *eeprom_image);
322 static int DevicePresent(u_long iobase);
323 static void SetMulticastFilter(struct net_device *dev);
324 static int EISA_signature(char *name, s32 eisa_id);
325
326 static int Read_EEPROM(u_long iobase, u_char eaddr);
327 static int Write_EEPROM(short data, u_long iobase, u_char eaddr);
328 static u_char get_hw_addr(struct net_device *dev, u_char * eeprom_image, char chipType);
329
330 static void isa_probe(struct net_device *dev, u_long iobase);
331 static void eisa_probe(struct net_device *dev, u_long iobase);
332 static struct net_device *alloc_device(struct net_device *dev, u_long iobase);
333 static int ewrk3_dev_index(char *s);
334 static struct net_device *insert_device(struct net_device *dev, u_long iobase, int (*init) (struct net_device *));
335
336
337 #ifdef MODULE
338 int init_module(void);
339 void cleanup_module(void);
340 static int autoprobed = 1, loading_module = 1;
341
342 #else
343 static u_char irq[] =
344 {5, 0, 10, 3, 11, 9, 15, 12};
345 static int autoprobed, loading_module;
346
347 #endif /* MODULE */
348
349 static char name[EWRK3_STRLEN + 1];
350 static int num_ewrk3s, num_eth;
351
352 /*
353 ** Miscellaneous defines...
354 */
355 #define INIT_EWRK3 {\
356 outb(EEPROM_INIT, EWRK3_IOPR);\
357 mdelay(1);\
358 }
359
ewrk3_probe(struct net_device * dev)360 int __init ewrk3_probe(struct net_device *dev)
361 {
362 int tmp = num_ewrk3s, status = -ENODEV;
363 u_long iobase = dev->base_addr;
364
365 SET_MODULE_OWNER(dev);
366
367 if ((iobase == 0) && loading_module) {
368 printk("Autoprobing is not supported when loading a module based driver.\n");
369 status = -EIO;
370 } else { /* First probe for the Ethernet */
371 /* Address PROM pattern */
372 isa_probe(dev, iobase);
373 eisa_probe(dev, iobase);
374
375 if ((tmp == num_ewrk3s) && (iobase != 0) && loading_module) {
376 printk("%s: ewrk3_probe() cannot find device at 0x%04lx.\n", dev->name,
377 iobase);
378 }
379 /*
380 ** Walk the device list to check that at least one device
381 ** initialised OK
382 */
383 for (; (dev->priv == NULL) && (dev->next != NULL); dev = dev->next);
384
385 if (dev->priv)
386 status = 0;
387 if (iobase == 0)
388 autoprobed = 1;
389 }
390
391 return status;
392 }
393
394 static int __init
ewrk3_hw_init(struct net_device * dev,u_long iobase)395 ewrk3_hw_init(struct net_device *dev, u_long iobase)
396 {
397 struct ewrk3_private *lp;
398 int i, status = 0;
399 u_long mem_start, shmem_length;
400 u_char cr, cmr, icr, nicsr, lemac, hard_strapped = 0;
401 u_char eeprom_image[EEPROM_MAX], chksum, eisa_cr = 0;
402
403 /*
404 ** Stop the EWRK3. Enable the DBR ROM. Disable interrupts and remote boot.
405 ** This also disables the EISA_ENABLE bit in the EISA Control Register.
406 */
407 if (iobase > 0x400)
408 eisa_cr = inb(EISA_CR);
409 INIT_EWRK3;
410
411 nicsr = inb(EWRK3_CSR);
412
413 icr = inb(EWRK3_ICR);
414 icr &= 0x70;
415 outb(icr, EWRK3_ICR); /* Disable all the IRQs */
416
417 if (nicsr == (CSR_TXD | CSR_RXD)) {
418
419 /* Check that the EEPROM is alive and well and not living on Pluto... */
420 for (chksum = 0, i = 0; i < EEPROM_MAX; i += 2) {
421 union {
422 short val;
423 char c[2];
424 } tmp;
425
426 tmp.val = (short) Read_EEPROM(iobase, (i >> 1));
427 eeprom_image[i] = tmp.c[0];
428 eeprom_image[i + 1] = tmp.c[1];
429 chksum += eeprom_image[i] + eeprom_image[i + 1];
430 }
431
432 if (chksum != 0) { /* Bad EEPROM Data! */
433 printk("%s: Device has a bad on-board EEPROM.\n", dev->name);
434 status = -ENXIO;
435 } else {
436 EthwrkSignature(name, eeprom_image);
437 if (*name != '\0') { /* found a EWRK3 device */
438 dev->base_addr = iobase;
439
440 if (iobase > 0x400) {
441 outb(eisa_cr, EISA_CR); /* Rewrite the EISA CR */
442 }
443 lemac = eeprom_image[EEPROM_CHIPVER];
444 cmr = inb(EWRK3_CMR);
445
446 if (((lemac == LeMAC) && ((cmr & CMR_NO_EEPROM) != CMR_NO_EEPROM)) ||
447 ((lemac == LeMAC2) && !(cmr & CMR_HS))) {
448 printk("%s: %s at %#4lx", dev->name, name, iobase);
449 hard_strapped = 1;
450 } else if ((iobase & 0x0fff) == EWRK3_EISA_IO_PORTS) {
451 /* EISA slot address */
452 printk("%s: %s at %#4lx (EISA slot %ld)",
453 dev->name, name, iobase, ((iobase >> 12) & 0x0f));
454 } else { /* ISA port address */
455 printk("%s: %s at %#4lx", dev->name, name, iobase);
456 }
457
458 if (!status) {
459 printk(", h/w address ");
460 if (lemac != LeMAC2)
461 DevicePresent(iobase); /* need after EWRK3_INIT */
462 status = get_hw_addr(dev, eeprom_image, lemac);
463 for (i = 0; i < ETH_ALEN - 1; i++) { /* get the ethernet addr. */
464 printk("%2.2x:", dev->dev_addr[i]);
465 }
466 printk("%2.2x,\n", dev->dev_addr[i]);
467
468 if (status) {
469 printk(" which has an EEPROM CRC error.\n");
470 status = -ENXIO;
471 } else {
472 if (lemac == LeMAC2) { /* Special LeMAC2 CMR things */
473 cmr &= ~(CMR_RA | CMR_WB | CMR_LINK | CMR_POLARITY | CMR_0WS);
474 if (eeprom_image[EEPROM_MISC0] & READ_AHEAD)
475 cmr |= CMR_RA;
476 if (eeprom_image[EEPROM_MISC0] & WRITE_BEHIND)
477 cmr |= CMR_WB;
478 if (eeprom_image[EEPROM_NETMAN0] & NETMAN_POL)
479 cmr |= CMR_POLARITY;
480 if (eeprom_image[EEPROM_NETMAN0] & NETMAN_LINK)
481 cmr |= CMR_LINK;
482 if (eeprom_image[EEPROM_MISC0] & _0WS_ENA)
483 cmr |= CMR_0WS;
484 }
485 if (eeprom_image[EEPROM_SETUP] & SETUP_DRAM)
486 cmr |= CMR_DRAM;
487 outb(cmr, EWRK3_CMR);
488
489 cr = inb(EWRK3_CR); /* Set up the Control Register */
490 cr |= eeprom_image[EEPROM_SETUP] & SETUP_APD;
491 if (cr & SETUP_APD)
492 cr |= eeprom_image[EEPROM_SETUP] & SETUP_PS;
493 cr |= eeprom_image[EEPROM_MISC0] & FAST_BUS;
494 cr |= eeprom_image[EEPROM_MISC0] & ENA_16;
495 outb(cr, EWRK3_CR);
496
497 /*
498 ** Determine the base address and window length for the EWRK3
499 ** RAM from the memory base register.
500 */
501 mem_start = inb(EWRK3_MBR);
502 shmem_length = 0;
503 if (mem_start != 0) {
504 if ((mem_start >= 0x0a) && (mem_start <= 0x0f)) {
505 mem_start *= SHMEM_64K;
506 shmem_length = SHMEM_64K;
507 } else if ((mem_start >= 0x14) && (mem_start <= 0x1f)) {
508 mem_start *= SHMEM_32K;
509 shmem_length = SHMEM_32K;
510 } else if ((mem_start >= 0x40) && (mem_start <= 0xff)) {
511 mem_start = mem_start * SHMEM_2K + 0x80000;
512 shmem_length = SHMEM_2K;
513 } else {
514 status = -ENXIO;
515 }
516 }
517 /*
518 ** See the top of this source code for comments about
519 ** uncommenting this line.
520 */
521 /* FORCE_2K_MODE; */
522
523 if (!status) {
524 if (hard_strapped) {
525 printk(" is hard strapped.\n");
526 } else if (mem_start) {
527 printk(" has a %dk RAM window", (int) (shmem_length >> 10));
528 printk(" at 0x%.5lx", mem_start);
529 } else {
530 printk(" is in I/O only mode");
531 }
532
533 /* private area & initialise */
534 dev->priv = (void *) kmalloc(sizeof(struct ewrk3_private),
535 GFP_KERNEL);
536 if (dev->priv == NULL) {
537 return -ENOMEM;
538 }
539 lp = (struct ewrk3_private *) dev->priv;
540 memset(dev->priv, 0, sizeof(struct ewrk3_private));
541 lp->shmem_base = mem_start;
542 lp->shmem_length = shmem_length;
543 lp->lemac = lemac;
544 lp->hard_strapped = hard_strapped;
545 lp->led_mask = CR_LED;
546 spin_lock_init(&lp->hw_lock);
547
548 lp->mPage = 64;
549 if (cmr & CMR_DRAM)
550 lp->mPage <<= 1; /* 2 DRAMS on module */
551
552 sprintf(lp->adapter_name, "%s (%s)", name, dev->name);
553 request_region(iobase, EWRK3_TOTAL_SIZE, lp->adapter_name);
554
555 lp->irq_mask = ICR_TNEM | ICR_TXDM | ICR_RNEM | ICR_RXDM;
556
557 if (!hard_strapped) {
558 /*
559 ** Enable EWRK3 board interrupts for autoprobing
560 */
561 icr |= ICR_IE; /* Enable interrupts */
562 outb(icr, EWRK3_ICR);
563
564 /* The DMA channel may be passed in on this parameter. */
565 dev->dma = 0;
566
567 /* To auto-IRQ we enable the initialization-done and DMA err,
568 interrupts. For now we will always get a DMA error. */
569 if (dev->irq < 2) {
570 #ifndef MODULE
571 u_char irqnum;
572 unsigned long irq_mask, delay;
573
574
575 irq_mask = probe_irq_on();
576
577 /*
578 ** Trigger a TNE interrupt.
579 */
580 icr |= ICR_TNEM;
581 outb(1, EWRK3_TDQ); /* Write to the TX done queue */
582 outb(icr, EWRK3_ICR); /* Unmask the TXD interrupt */
583
584 irqnum = irq[((icr & IRQ_SEL) >> 4)];
585
586 delay = jiffies + HZ/50;
587 while (time_before(jiffies, delay)) ;
588 dev->irq = probe_irq_off(irq_mask);
589 if ((dev->irq) && (irqnum == dev->irq)) {
590 printk(" and uses IRQ%d.\n", dev->irq);
591 } else {
592 if (!dev->irq) {
593 printk(" and failed to detect IRQ line.\n");
594 } else if ((irqnum == 1) && (lemac == LeMAC2)) {
595 printk(" and an illegal IRQ line detected.\n");
596 } else {
597 printk(", but incorrect IRQ line detected.\n");
598 }
599 status = -ENXIO;
600 }
601
602 DISABLE_IRQs; /* Mask all interrupts */
603
604 #endif /* MODULE */
605 } else {
606 printk(" and requires IRQ%d.\n", dev->irq);
607 }
608 }
609 if (status)
610 release_region(iobase, EWRK3_TOTAL_SIZE);
611 } else {
612 status = -ENXIO;
613 }
614 }
615 }
616 } else {
617 status = -ENXIO;
618 }
619 }
620
621 if (!status) {
622 if (ewrk3_debug > 1) {
623 printk(version);
624 }
625 /* The EWRK3-specific entries in the device structure. */
626 dev->open = ewrk3_open;
627 dev->hard_start_xmit = ewrk3_queue_pkt;
628 dev->stop = ewrk3_close;
629 dev->get_stats = ewrk3_get_stats;
630 dev->set_multicast_list = set_multicast_list;
631 dev->do_ioctl = ewrk3_ioctl;
632 dev->tx_timeout = ewrk3_timeout;
633 dev->watchdog_timeo = QUEUE_PKT_TIMEOUT;
634
635 dev->mem_start = 0;
636
637 /* Fill in the generic field of the device structure. */
638 ether_setup(dev);
639 }
640 } else {
641 status = -ENXIO;
642 }
643 return status;
644 }
645
646
ewrk3_open(struct net_device * dev)647 static int ewrk3_open(struct net_device *dev)
648 {
649 struct ewrk3_private *lp = (struct ewrk3_private *) dev->priv;
650 u_long iobase = dev->base_addr;
651 int i, status = 0;
652 u_char icr, csr;
653
654 /*
655 ** Stop the TX and RX...
656 */
657 STOP_EWRK3;
658
659 if (!lp->hard_strapped) {
660 if (request_irq(dev->irq, (void *) ewrk3_interrupt, 0, "ewrk3", dev)) {
661 printk("ewrk3_open(): Requested IRQ%d is busy\n", dev->irq);
662 status = -EAGAIN;
663 } else {
664
665 /*
666 ** Re-initialize the EWRK3...
667 */
668 ewrk3_init(dev);
669
670 if (ewrk3_debug > 1) {
671 printk("%s: ewrk3 open with irq %d\n", dev->name, dev->irq);
672 printk(" physical address: ");
673 for (i = 0; i < 5; i++) {
674 printk("%2.2x:", (u_char) dev->dev_addr[i]);
675 }
676 printk("%2.2x\n", (u_char) dev->dev_addr[i]);
677 if (lp->shmem_length == 0) {
678 printk(" no shared memory, I/O only mode\n");
679 } else {
680 printk(" start of shared memory: 0x%08lx\n", lp->shmem_base);
681 printk(" window length: 0x%04lx\n", lp->shmem_length);
682 }
683 printk(" # of DRAMS: %d\n", ((inb(EWRK3_CMR) & 0x02) ? 2 : 1));
684 printk(" csr: 0x%02x\n", inb(EWRK3_CSR));
685 printk(" cr: 0x%02x\n", inb(EWRK3_CR));
686 printk(" icr: 0x%02x\n", inb(EWRK3_ICR));
687 printk(" cmr: 0x%02x\n", inb(EWRK3_CMR));
688 printk(" fmqc: 0x%02x\n", inb(EWRK3_FMQC));
689 }
690 netif_start_queue(dev);
691 /*
692 ** Unmask EWRK3 board interrupts
693 */
694 icr = inb(EWRK3_ICR);
695 ENABLE_IRQs;
696
697 }
698 } else {
699 printk(KERN_ERR "%s: ewrk3 available for hard strapped set up only.\n", dev->name);
700 printk(KERN_ERR " Run the 'ewrk3setup' utility or remove the hard straps.\n");
701 return -EINVAL;
702 }
703
704 return status;
705 }
706
707 /*
708 ** Initialize the EtherWORKS 3 operating conditions
709 */
ewrk3_init(struct net_device * dev)710 static void ewrk3_init(struct net_device *dev)
711 {
712 struct ewrk3_private *lp = (struct ewrk3_private *) dev->priv;
713 u_char csr, page;
714 u_long iobase = dev->base_addr;
715 int i;
716
717 /*
718 ** Enable any multicasts
719 */
720 set_multicast_list(dev);
721
722 /*
723 ** Set hardware MAC address. Address is initialized from the EEPROM
724 ** during startup but may have since been changed by the user.
725 */
726 for (i=0; i<ETH_ALEN; i++)
727 outb(dev->dev_addr[i], EWRK3_PAR0 + i);
728
729 /*
730 ** Clean out any remaining entries in all the queues here
731 */
732 while (inb(EWRK3_TQ));
733 while (inb(EWRK3_TDQ));
734 while (inb(EWRK3_RQ));
735 while (inb(EWRK3_FMQ));
736
737 /*
738 ** Write a clean free memory queue
739 */
740 for (page = 1; page < lp->mPage; page++) { /* Write the free page numbers */
741 outb(page, EWRK3_FMQ); /* to the Free Memory Queue */
742 }
743
744 START_EWRK3; /* Enable the TX and/or RX */
745 }
746
747 /*
748 * Transmit timeout
749 */
750
ewrk3_timeout(struct net_device * dev)751 static void ewrk3_timeout(struct net_device *dev)
752 {
753 struct ewrk3_private *lp = (struct ewrk3_private *) dev->priv;
754 u_char icr, csr;
755 u_long iobase = dev->base_addr;
756
757 if (!lp->hard_strapped)
758 {
759 printk(KERN_WARNING"%s: transmit timed/locked out, status %04x, resetting.\n",
760 dev->name, inb(EWRK3_CSR));
761
762 /*
763 ** Mask all board interrupts
764 */
765 DISABLE_IRQs;
766
767 /*
768 ** Stop the TX and RX...
769 */
770 STOP_EWRK3;
771
772 ewrk3_init(dev);
773
774 /*
775 ** Unmask EWRK3 board interrupts
776 */
777 ENABLE_IRQs;
778
779 dev->trans_start = jiffies;
780 netif_wake_queue(dev);
781 }
782 }
783
784 /*
785 ** Writes a socket buffer to the free page queue
786 */
ewrk3_queue_pkt(struct sk_buff * skb,struct net_device * dev)787 static int ewrk3_queue_pkt (struct sk_buff *skb, struct net_device *dev)
788 {
789 struct ewrk3_private *lp = (struct ewrk3_private *) dev->priv;
790 u_long iobase = dev->base_addr;
791 u_long buf = 0;
792 u_char icr;
793 u_char page;
794
795 spin_lock_irq (&lp->hw_lock);
796 DISABLE_IRQs;
797
798 /* if no resources available, exit, request packet be queued */
799 if (inb (EWRK3_FMQC) == 0) {
800 printk (KERN_WARNING "%s: ewrk3_queue_pkt(): No free resources...\n",
801 dev->name);
802 printk (KERN_WARNING "%s: ewrk3_queue_pkt(): CSR: %02x ICR: %02x FMQC: %02x\n",
803 dev->name, inb (EWRK3_CSR), inb (EWRK3_ICR),
804 inb (EWRK3_FMQC));
805 goto err_out;
806 }
807
808 /*
809 ** Get a free page from the FMQ
810 */
811 if ((page = inb (EWRK3_FMQ)) >= lp->mPage) {
812 printk ("ewrk3_queue_pkt(): Invalid free memory page (%d).\n",
813 (u_char) page);
814 goto err_out;
815 }
816
817
818 /*
819 ** Set up shared memory window and pointer into the window
820 */
821 if (lp->shmem_length == IO_ONLY) {
822 outb (page, EWRK3_IOPR);
823 } else if (lp->shmem_length == SHMEM_2K) {
824 buf = lp->shmem_base;
825 outb (page, EWRK3_MPR);
826 } else if (lp->shmem_length == SHMEM_32K) {
827 buf = ((((short) page << 11) & 0x7800) + lp->shmem_base);
828 outb ((page >> 4), EWRK3_MPR);
829 } else if (lp->shmem_length == SHMEM_64K) {
830 buf = ((((short) page << 11) & 0xf800) + lp->shmem_base);
831 outb ((page >> 5), EWRK3_MPR);
832 } else {
833 printk (KERN_ERR "%s: Oops - your private data area is hosed!\n",
834 dev->name);
835 BUG ();
836 }
837
838 /*
839 ** Set up the buffer control structures and copy the data from
840 ** the socket buffer to the shared memory .
841 */
842 if (lp->shmem_length == IO_ONLY) {
843 int i;
844 u_char *p = skb->data;
845 outb ((char) (TCR_QMODE | TCR_PAD | TCR_IFC), EWRK3_DATA);
846 outb ((char) (skb->len & 0xff), EWRK3_DATA);
847 outb ((char) ((skb->len >> 8) & 0xff), EWRK3_DATA);
848 outb ((char) 0x04, EWRK3_DATA);
849 for (i = 0; i < skb->len; i++) {
850 outb (*p++, EWRK3_DATA);
851 }
852 outb (page, EWRK3_TQ); /* Start sending pkt */
853 } else {
854 isa_writeb ((char) (TCR_QMODE | TCR_PAD | TCR_IFC), buf); /* ctrl byte */
855 buf += 1;
856 isa_writeb ((char) (skb->len & 0xff), buf); /* length (16 bit xfer) */
857 buf += 1;
858 if (lp->txc) {
859 isa_writeb ((char)
860 (((skb->len >> 8) & 0xff) | XCT), buf);
861 buf += 1;
862 isa_writeb (0x04, buf); /* index byte */
863 buf += 1;
864 isa_writeb (0x00, (buf + skb->len)); /* Write the XCT flag */
865 isa_memcpy_toio (buf, skb->data, PRELOAD); /* Write PRELOAD bytes */
866 outb (page, EWRK3_TQ); /* Start sending pkt */
867 isa_memcpy_toio (buf + PRELOAD,
868 skb->data + PRELOAD,
869 skb->len - PRELOAD);
870 isa_writeb (0xff, (buf + skb->len)); /* Write the XCT flag */
871 } else {
872 isa_writeb ((char)
873 ((skb->len >> 8) & 0xff), buf);
874 buf += 1;
875 isa_writeb (0x04, buf); /* index byte */
876 buf += 1;
877 isa_memcpy_toio (buf, skb->data, skb->len); /* Write data bytes */
878 outb (page, EWRK3_TQ); /* Start sending pkt */
879 }
880 }
881
882 ENABLE_IRQs;
883 spin_unlock_irq (&lp->hw_lock);
884
885 lp->stats.tx_bytes += skb->len;
886 dev->trans_start = jiffies;
887 dev_kfree_skb (skb);
888
889 /* Check for free resources: stop Tx queue if there are none */
890 if (inb (EWRK3_FMQC) == 0)
891 netif_stop_queue (dev);
892
893 return 0;
894
895 err_out:
896 ENABLE_IRQs;
897 spin_unlock_irq (&lp->hw_lock);
898 return 1;
899 }
900
901 /*
902 ** The EWRK3 interrupt handler.
903 */
ewrk3_interrupt(int irq,void * dev_id,struct pt_regs * regs)904 static void ewrk3_interrupt(int irq, void *dev_id, struct pt_regs *regs)
905 {
906 struct net_device *dev = dev_id;
907 struct ewrk3_private *lp;
908 u_long iobase;
909 u_char icr, cr, csr;
910
911 lp = (struct ewrk3_private *) dev->priv;
912 iobase = dev->base_addr;
913
914 /* get the interrupt information */
915 csr = inb(EWRK3_CSR);
916
917 /*
918 ** Mask the EWRK3 board interrupts and turn on the LED
919 */
920 spin_lock(&lp->hw_lock);
921 DISABLE_IRQs;
922
923 cr = inb(EWRK3_CR);
924 cr |= lp->led_mask;
925 outb(cr, EWRK3_CR);
926
927 if (csr & CSR_RNE) /* Rx interrupt (packet[s] arrived) */
928 ewrk3_rx(dev);
929
930 if (csr & CSR_TNE) /* Tx interrupt (packet sent) */
931 ewrk3_tx(dev);
932
933 /*
934 ** Now deal with the TX/RX disable flags. These are set when there
935 ** are no more resources. If resources free up then enable these
936 ** interrupts, otherwise mask them - failure to do this will result
937 ** in the system hanging in an interrupt loop.
938 */
939 if (inb(EWRK3_FMQC)) { /* any resources available? */
940 lp->irq_mask |= ICR_TXDM | ICR_RXDM; /* enable the interrupt source */
941 csr &= ~(CSR_TXD | CSR_RXD); /* ensure restart of a stalled TX or RX */
942 outb(csr, EWRK3_CSR);
943 netif_wake_queue(dev);
944 } else {
945 lp->irq_mask &= ~(ICR_TXDM | ICR_RXDM); /* disable the interrupt source */
946 }
947
948 /* Unmask the EWRK3 board interrupts and turn off the LED */
949 cr &= ~(lp->led_mask);
950 outb(cr, EWRK3_CR);
951 ENABLE_IRQs;
952 spin_unlock(&lp->hw_lock);
953 }
954
955 /* Called with lp->hw_lock held */
ewrk3_rx(struct net_device * dev)956 static int ewrk3_rx(struct net_device *dev)
957 {
958 struct ewrk3_private *lp = (struct ewrk3_private *) dev->priv;
959 u_long iobase = dev->base_addr;
960 int i, status = 0;
961 u_char page;
962 u_long buf = 0;
963
964 while (inb(EWRK3_RQC) && !status) { /* Whilst there's incoming data */
965 if ((page = inb(EWRK3_RQ)) < lp->mPage) { /* Get next entry's buffer page */
966 /*
967 ** Set up shared memory window and pointer into the window
968 */
969 if (lp->shmem_length == IO_ONLY) {
970 outb(page, EWRK3_IOPR);
971 } else if (lp->shmem_length == SHMEM_2K) {
972 buf = lp->shmem_base;
973 outb(page, EWRK3_MPR);
974 } else if (lp->shmem_length == SHMEM_32K) {
975 buf = ((((short) page << 11) & 0x7800) + lp->shmem_base);
976 outb((page >> 4), EWRK3_MPR);
977 } else if (lp->shmem_length == SHMEM_64K) {
978 buf = ((((short) page << 11) & 0xf800) + lp->shmem_base);
979 outb((page >> 5), EWRK3_MPR);
980 } else {
981 status = -1;
982 printk("%s: Oops - your private data area is hosed!\n", dev->name);
983 }
984
985 if (!status) {
986 char rx_status;
987 int pkt_len;
988
989 if (lp->shmem_length == IO_ONLY) {
990 rx_status = inb(EWRK3_DATA);
991 pkt_len = inb(EWRK3_DATA);
992 pkt_len |= ((u_short) inb(EWRK3_DATA) << 8);
993 } else {
994 rx_status = isa_readb(buf);
995 buf += 1;
996 pkt_len = isa_readw(buf);
997 buf += 3;
998 }
999
1000 if (!(rx_status & R_ROK)) { /* There was an error. */
1001 lp->stats.rx_errors++; /* Update the error stats. */
1002 if (rx_status & R_DBE)
1003 lp->stats.rx_frame_errors++;
1004 if (rx_status & R_CRC)
1005 lp->stats.rx_crc_errors++;
1006 if (rx_status & R_PLL)
1007 lp->stats.rx_fifo_errors++;
1008 } else {
1009 struct sk_buff *skb;
1010
1011 if ((skb = dev_alloc_skb(pkt_len + 2)) != NULL) {
1012 unsigned char *p;
1013 skb->dev = dev;
1014 skb_reserve(skb, 2); /* Align to 16 bytes */
1015 p = skb_put(skb, pkt_len);
1016
1017 if (lp->shmem_length == IO_ONLY) {
1018 *p = inb(EWRK3_DATA); /* dummy read */
1019 for (i = 0; i < pkt_len; i++) {
1020 *p++ = inb(EWRK3_DATA);
1021 }
1022 } else {
1023 isa_memcpy_fromio(p, buf, pkt_len);
1024 }
1025
1026 for (i = 1; i < EWRK3_PKT_STAT_SZ - 1; i++) {
1027 if (pkt_len < i * EWRK3_PKT_BIN_SZ) {
1028 lp->pktStats.bins[i]++;
1029 i = EWRK3_PKT_STAT_SZ;
1030 }
1031 }
1032 p = skb->data; /* Look at the dest addr */
1033 if (p[0] & 0x01) { /* Multicast/Broadcast */
1034 if ((*(s16 *) & p[0] == -1) && (*(s16 *) & p[2] == -1) && (*(s16 *) & p[4] == -1)) {
1035 lp->pktStats.broadcast++;
1036 } else {
1037 lp->pktStats.multicast++;
1038 }
1039 } else if ((*(s16 *) & p[0] == *(s16 *) & dev->dev_addr[0]) &&
1040 (*(s16 *) & p[2] == *(s16 *) & dev->dev_addr[2]) &&
1041 (*(s16 *) & p[4] == *(s16 *) & dev->dev_addr[4])) {
1042 lp->pktStats.unicast++;
1043 }
1044 lp->pktStats.bins[0]++; /* Duplicates stats.rx_packets */
1045 if (lp->pktStats.bins[0] == 0) { /* Reset counters */
1046 memset(&lp->pktStats, 0, sizeof(lp->pktStats));
1047 }
1048 /*
1049 ** Notify the upper protocol layers that there is another
1050 ** packet to handle
1051 */
1052 skb->protocol = eth_type_trans(skb, dev);
1053 netif_rx(skb);
1054
1055 /*
1056 ** Update stats
1057 */
1058 dev->last_rx = jiffies;
1059 lp->stats.rx_packets++;
1060 lp->stats.rx_bytes += pkt_len;
1061 } else {
1062 printk("%s: Insufficient memory; nuking packet.\n", dev->name);
1063 lp->stats.rx_dropped++; /* Really, deferred. */
1064 break;
1065 }
1066 }
1067 }
1068 /*
1069 ** Return the received buffer to the free memory queue
1070 */
1071 outb(page, EWRK3_FMQ);
1072 } else {
1073 printk("ewrk3_rx(): Illegal page number, page %d\n", page);
1074 printk("ewrk3_rx(): CSR: %02x ICR: %02x FMQC: %02x\n", inb(EWRK3_CSR), inb(EWRK3_ICR), inb(EWRK3_FMQC));
1075 }
1076 }
1077 return status;
1078 }
1079
1080 /*
1081 ** Buffer sent - check for TX buffer errors.
1082 ** Called with lp->hw_lock held
1083 */
ewrk3_tx(struct net_device * dev)1084 static int ewrk3_tx(struct net_device *dev)
1085 {
1086 struct ewrk3_private *lp = (struct ewrk3_private *) dev->priv;
1087 u_long iobase = dev->base_addr;
1088 u_char tx_status;
1089
1090 while ((tx_status = inb(EWRK3_TDQ)) > 0) { /* Whilst there's old buffers */
1091 if (tx_status & T_VSTS) { /* The status is valid */
1092 if (tx_status & T_TXE) {
1093 lp->stats.tx_errors++;
1094 if (tx_status & T_NCL)
1095 lp->stats.tx_carrier_errors++;
1096 if (tx_status & T_LCL)
1097 lp->stats.tx_window_errors++;
1098 if (tx_status & T_CTU) {
1099 if ((tx_status & T_COLL) ^ T_XUR) {
1100 lp->pktStats.tx_underruns++;
1101 } else {
1102 lp->pktStats.excessive_underruns++;
1103 }
1104 } else if (tx_status & T_COLL) {
1105 if ((tx_status & T_COLL) ^ T_XCOLL) {
1106 lp->stats.collisions++;
1107 } else {
1108 lp->pktStats.excessive_collisions++;
1109 }
1110 }
1111 } else {
1112 lp->stats.tx_packets++;
1113 }
1114 }
1115 }
1116
1117 return 0;
1118 }
1119
ewrk3_close(struct net_device * dev)1120 static int ewrk3_close(struct net_device *dev)
1121 {
1122 struct ewrk3_private *lp = (struct ewrk3_private *) dev->priv;
1123 u_long iobase = dev->base_addr;
1124 u_char icr, csr;
1125
1126 netif_stop_queue(dev);
1127
1128 if (ewrk3_debug > 1) {
1129 printk("%s: Shutting down ethercard, status was %2.2x.\n",
1130 dev->name, inb(EWRK3_CSR));
1131 }
1132 /*
1133 ** We stop the EWRK3 here... mask interrupts and stop TX & RX
1134 */
1135 DISABLE_IRQs;
1136
1137 STOP_EWRK3;
1138
1139 /*
1140 ** Clean out the TX and RX queues here (note that one entry
1141 ** may get added to either the TXD or RX queues if the TX or RX
1142 ** just starts processing a packet before the STOP_EWRK3 command
1143 ** is received. This will be flushed in the ewrk3_open() call).
1144 */
1145 while (inb(EWRK3_TQ));
1146 while (inb(EWRK3_TDQ));
1147 while (inb(EWRK3_RQ));
1148
1149 if (!lp->hard_strapped) {
1150 free_irq(dev->irq, dev);
1151 }
1152 return 0;
1153 }
1154
ewrk3_get_stats(struct net_device * dev)1155 static struct net_device_stats *ewrk3_get_stats(struct net_device *dev)
1156 {
1157 struct ewrk3_private *lp = (struct ewrk3_private *) dev->priv;
1158
1159 /* Null body since there is no framing error counter */
1160 return &lp->stats;
1161 }
1162
1163 /*
1164 ** Set or clear the multicast filter for this adapter.
1165 */
set_multicast_list(struct net_device * dev)1166 static void set_multicast_list(struct net_device *dev)
1167 {
1168 struct ewrk3_private *lp = (struct ewrk3_private *) dev->priv;
1169 u_long iobase = dev->base_addr;
1170 u_char csr;
1171
1172 csr = inb(EWRK3_CSR);
1173
1174 if (lp->shmem_length == IO_ONLY) {
1175 lp->mctbl = (char *) PAGE0_HTE;
1176 } else {
1177 lp->mctbl = (char *) (lp->shmem_base + PAGE0_HTE);
1178 }
1179
1180 csr &= ~(CSR_PME | CSR_MCE);
1181 if (dev->flags & IFF_PROMISC) { /* set promiscuous mode */
1182 csr |= CSR_PME;
1183 outb(csr, EWRK3_CSR);
1184 } else {
1185 SetMulticastFilter(dev);
1186 csr |= CSR_MCE;
1187 outb(csr, EWRK3_CSR);
1188 }
1189 }
1190
1191 /*
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.
1195 **
1196 ** Note that when clearing the table, the broadcast bit must remain asserted
1197 ** to receive broadcast messages.
1198 */
SetMulticastFilter(struct net_device * dev)1199 static void SetMulticastFilter(struct net_device *dev)
1200 {
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;
1204 int i;
1205 char *addrs, bit, byte;
1206 short *p = (short *) lp->mctbl;
1207 u16 hashcode;
1208 u32 crc;
1209
1210 spin_lock_irq(&lp->hw_lock);
1211
1212 if (lp->shmem_length == IO_ONLY) {
1213 outb(0, EWRK3_IOPR);
1214 outw(EEPROM_OFFSET(lp->mctbl), EWRK3_PIR1);
1215 } else {
1216 outb(0, EWRK3_MPR);
1217 }
1218
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 */
1224 isa_writew(0xffff, (int) p);
1225 p++;
1226 i++;
1227 }
1228 }
1229 } else {
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);
1234 }
1235 outb(0x80, EWRK3_DATA);
1236 i++; /* insert the broadcast bit */
1237 for (; i < (HASH_TABLE_LEN >> 3); i++) {
1238 outb(0x00, EWRK3_DATA);
1239 }
1240 } else {
1241 isa_memset_io((int) lp->mctbl, 0, (HASH_TABLE_LEN >> 3));
1242 isa_writeb(0x80, (int) (lp->mctbl + (HASH_TABLE_LEN >> 4) - 1));
1243 }
1244
1245 /* Update table */
1246 for (i = 0; i < dev->mc_count; i++) { /* for each address in the list */
1247 addrs = dmi->dmi_addr;
1248 dmi = dmi->next;
1249 if ((*addrs & 0x01) == 1) { /* multicast address? */
1250 crc = ether_crc_le(ETH_ALEN, addrs);
1251 hashcode = crc & ((1 << 9) - 1); /* hashcode is 9 LSb of CRC */
1252
1253 byte = hashcode >> 3; /* bit[3-8] -> byte in filter */
1254 bit = 1 << (hashcode & 0x07); /* bit[0-2] -> bit in byte */
1255
1256 if (lp->shmem_length == IO_ONLY) {
1257 u_char tmp;
1258
1259 outw((short) ((long) lp->mctbl) + byte, EWRK3_PIR1);
1260 tmp = inb(EWRK3_DATA);
1261 tmp |= bit;
1262 outw((short) ((long) lp->mctbl) + byte, EWRK3_PIR1);
1263 outb(tmp, EWRK3_DATA);
1264 } else {
1265 isa_writeb(isa_readb((int)(lp->mctbl + byte)) | bit, (int)(lp->mctbl + byte));
1266 }
1267 }
1268 }
1269 }
1270
1271 spin_unlock_irq(&lp->hw_lock);
1272 }
1273
1274 /*
1275 ** ISA bus I/O device probe
1276 */
isa_probe(struct net_device * dev,u_long ioaddr)1277 static void __init isa_probe(struct net_device *dev, u_long ioaddr)
1278 {
1279 int i = num_ewrk3s, maxSlots;
1280 u_long iobase;
1281
1282 if (!ioaddr && autoprobed)
1283 return; /* Been here before ! */
1284 if (ioaddr >= 0x400)
1285 return; /* Not ISA */
1286
1287 if (ioaddr == 0) { /* Autoprobing */
1288 iobase = EWRK3_IO_BASE; /* Get the first slot address */
1289 maxSlots = 24;
1290 } else { /* Probe a specific location */
1291 iobase = ioaddr;
1292 maxSlots = i + 1;
1293 }
1294
1295 for (; (i < maxSlots) && (dev != NULL); iobase += EWRK3_IOP_INC, i++) {
1296 if (!check_region(iobase, EWRK3_TOTAL_SIZE)) {
1297 if (DevicePresent(iobase) == 0) {
1298 if ((dev = alloc_device(dev, iobase)) != NULL) {
1299 if (ewrk3_hw_init(dev, iobase) == 0) {
1300 num_ewrk3s++;
1301 }
1302 num_eth++;
1303 }
1304 }
1305 } else if (autoprobed) {
1306 printk("%s: region already allocated at 0x%04lx.\n", dev->name, iobase);
1307 }
1308 }
1309
1310 return;
1311 }
1312
1313 /*
1314 ** EISA bus I/O device probe. Probe from slot 1 since slot 0 is usually
1315 ** the motherboard.
1316 */
eisa_probe(struct net_device * dev,u_long ioaddr)1317 static void __init eisa_probe(struct net_device *dev, u_long ioaddr)
1318 {
1319 int i, maxSlots;
1320 u_long iobase;
1321 char name[EWRK3_STRLEN];
1322
1323 if (!ioaddr && autoprobed)
1324 return; /* Been here before ! */
1325 if (ioaddr < 0x1000)
1326 return; /* Not EISA */
1327
1328 if (ioaddr == 0) { /* Autoprobing */
1329 iobase = EISA_SLOT_INC; /* Get the first slot address */
1330 i = 1;
1331 maxSlots = MAX_EISA_SLOTS;
1332 } else { /* Probe a specific location */
1333 iobase = ioaddr;
1334 i = (ioaddr >> 12);
1335 maxSlots = i + 1;
1336 }
1337
1338 for (i = 1; (i < maxSlots) && (dev != NULL); i++, iobase += EISA_SLOT_INC) {
1339 if (EISA_signature(name, EISA_ID) == 0) {
1340 if (!check_region(iobase, EWRK3_TOTAL_SIZE)) {
1341 if (DevicePresent(iobase) == 0) {
1342 if ((dev = alloc_device(dev, iobase)) != NULL) {
1343 if (ewrk3_hw_init(dev, iobase) == 0) {
1344 num_ewrk3s++;
1345 }
1346 num_eth++;
1347 }
1348 }
1349 } else if (autoprobed) {
1350 printk("%s: region already allocated at 0x%04lx.\n", dev->name, iobase);
1351 }
1352 }
1353 }
1354
1355 return;
1356 }
1357
1358 /*
1359 ** Search the entire 'eth' device list for a fixed probe. If a match isn't
1360 ** found then check for an autoprobe or unused device location. If they
1361 ** are not available then insert a new device structure at the end of
1362 ** the current list.
1363 */
alloc_device(struct net_device * dev,u_long iobase)1364 static struct net_device * __init alloc_device(struct net_device *dev, u_long iobase)
1365 {
1366 struct net_device *adev = NULL;
1367 int fixed = 0, new_dev = 0;
1368
1369 num_eth = ewrk3_dev_index(dev->name);
1370 if (loading_module)
1371 return dev;
1372
1373 while (1) {
1374 if (((dev->base_addr == EWRK3_NDA) || (dev->base_addr == 0)) && !adev) {
1375 adev = dev;
1376 } else if ((dev->priv == NULL) && (dev->base_addr == iobase)) {
1377 fixed = 1;
1378 } else {
1379 if (dev->next == NULL) {
1380 new_dev = 1;
1381 } else if (strncmp(dev->next->name, "eth", 3) != 0) {
1382 new_dev = 1;
1383 }
1384 }
1385 if ((dev->next == NULL) || new_dev || fixed)
1386 break;
1387 dev = dev->next;
1388 num_eth++;
1389 }
1390 if (adev && !fixed) {
1391 dev = adev;
1392 num_eth = ewrk3_dev_index(dev->name);
1393 new_dev = 0;
1394 }
1395 if (((dev->next == NULL) &&
1396 ((dev->base_addr != EWRK3_NDA) && (dev->base_addr != 0)) && !fixed) ||
1397 new_dev) {
1398 num_eth++; /* New device */
1399 dev = insert_device(dev, iobase, ewrk3_probe);
1400 }
1401 return dev;
1402 }
1403
1404 /*
1405 ** If at end of eth device list and can't use current entry, malloc
1406 ** one up. If memory could not be allocated, print an error message.
1407 */
1408 static struct net_device * __init
insert_device(struct net_device * dev,u_long iobase,int (* init)(struct net_device *))1409 insert_device(struct net_device *dev, u_long iobase, int (*init) (struct net_device *))
1410 {
1411 struct net_device *new;
1412
1413 new = (struct net_device *) kmalloc(sizeof(struct net_device) + 8, GFP_KERNEL);
1414 if (new == NULL) {
1415 printk("eth%d: Device not initialised, insufficient memory\n", num_eth);
1416 return NULL;
1417 } else {
1418 new->next = dev->next;
1419 dev->next = new;
1420 dev = dev->next; /* point to the new device */
1421 if (num_eth > 9999) {
1422 sprintf(dev->name, "eth????"); /* New device name */
1423 } else {
1424 sprintf(dev->name, "eth%d", num_eth); /* New device name */
1425 }
1426 dev->base_addr = iobase; /* assign the io address */
1427 dev->init = init; /* initialisation routine */
1428 }
1429
1430 return dev;
1431 }
1432
1433 static int __init
ewrk3_dev_index(char * s)1434 ewrk3_dev_index(char *s)
1435 {
1436 int i = 0, j = 0;
1437
1438 for (; *s; s++) {
1439 if (isdigit(*s)) {
1440 j = 1;
1441 i = (i * 10) + (*s - '0');
1442 } else if (j)
1443 break;
1444 }
1445
1446 return i;
1447 }
1448
1449 /*
1450 ** Read the EWRK3 EEPROM using this routine
1451 */
Read_EEPROM(u_long iobase,u_char eaddr)1452 static int Read_EEPROM(u_long iobase, u_char eaddr)
1453 {
1454 int i;
1455
1456 outb((eaddr & 0x3f), EWRK3_PIR1); /* set up 6 bits of address info */
1457 outb(EEPROM_RD, EWRK3_IOPR); /* issue read command */
1458 for (i = 0; i < 5000; i++)
1459 inb(EWRK3_CSR); /* wait 1msec */
1460
1461 return inw(EWRK3_EPROM1); /* 16 bits data return */
1462 }
1463
1464 /*
1465 ** Write the EWRK3 EEPROM using this routine
1466 */
Write_EEPROM(short data,u_long iobase,u_char eaddr)1467 static int Write_EEPROM(short data, u_long iobase, u_char eaddr)
1468 {
1469 int i;
1470
1471 outb(EEPROM_WR_EN, EWRK3_IOPR); /* issue write enable command */
1472 for (i = 0; i < 5000; i++)
1473 inb(EWRK3_CSR); /* wait 1msec */
1474 outw(data, EWRK3_EPROM1); /* write data to register */
1475 outb((eaddr & 0x3f), EWRK3_PIR1); /* set up 6 bits of address info */
1476 outb(EEPROM_WR, EWRK3_IOPR); /* issue write command */
1477 for (i = 0; i < 75000; i++)
1478 inb(EWRK3_CSR); /* wait 15msec */
1479 outb(EEPROM_WR_DIS, EWRK3_IOPR); /* issue write disable command */
1480 for (i = 0; i < 5000; i++)
1481 inb(EWRK3_CSR); /* wait 1msec */
1482
1483 return 0;
1484 }
1485
1486 /*
1487 ** Look for a particular board name in the on-board EEPROM.
1488 */
EthwrkSignature(char * name,char * eeprom_image)1489 static void __init EthwrkSignature(char *name, char *eeprom_image)
1490 {
1491 int i;
1492 char *signatures[] = EWRK3_SIGNATURE;
1493
1494 for (i=0; *signatures[i] != '\0'; i++)
1495 if( !strncmp(eeprom_image+EEPROM_PNAME7, signatures[i], strlen(signatures[i])) )
1496 break;
1497
1498 if (*signatures[i] != '\0') {
1499 memcpy(name, eeprom_image+EEPROM_PNAME7, EWRK3_STRLEN);
1500 name[EWRK3_STRLEN] = '\0';
1501 } else
1502 name[0] = '\0';
1503
1504 return;
1505 }
1506
1507 /*
1508 ** Look for a special sequence in the Ethernet station address PROM that
1509 ** is common across all EWRK3 products.
1510 **
1511 ** Search the Ethernet address ROM for the signature. Since the ROM address
1512 ** counter can start at an arbitrary point, the search must include the entire
1513 ** probe sequence length plus the (length_of_the_signature - 1).
1514 ** Stop the search IMMEDIATELY after the signature is found so that the
1515 ** PROM address counter is correctly positioned at the start of the
1516 ** ethernet address for later read out.
1517 */
1518
DevicePresent(u_long iobase)1519 static int __init DevicePresent(u_long iobase)
1520 {
1521 union {
1522 struct {
1523 u32 a;
1524 u32 b;
1525 } llsig;
1526 char Sig[sizeof(u32) << 1];
1527 }
1528 dev;
1529 short sigLength;
1530 char data;
1531 int i, j, status = 0;
1532
1533 dev.llsig.a = ETH_PROM_SIG;
1534 dev.llsig.b = ETH_PROM_SIG;
1535 sigLength = sizeof(u32) << 1;
1536
1537 for (i = 0, j = 0; j < sigLength && i < PROBE_LENGTH + sigLength - 1; i++) {
1538 data = inb(EWRK3_APROM);
1539 if (dev.Sig[j] == data) { /* track signature */
1540 j++;
1541 } else { /* lost signature; begin search again */
1542 if (data == dev.Sig[0]) {
1543 j = 1;
1544 } else {
1545 j = 0;
1546 }
1547 }
1548 }
1549
1550 if (j != sigLength) {
1551 status = -ENODEV; /* search failed */
1552 }
1553 return status;
1554 }
1555
get_hw_addr(struct net_device * dev,u_char * eeprom_image,char chipType)1556 static u_char __init get_hw_addr(struct net_device *dev, u_char * eeprom_image, char chipType)
1557 {
1558 int i, j, k;
1559 u_short chksum;
1560 u_char crc, lfsr, sd, status = 0;
1561 u_long iobase = dev->base_addr;
1562 u16 tmp;
1563
1564 if (chipType == LeMAC2) {
1565 for (crc = 0x6a, j = 0; j < ETH_ALEN; j++) {
1566 sd = dev->dev_addr[j] = eeprom_image[EEPROM_PADDR0 + j];
1567 outb(dev->dev_addr[j], EWRK3_PAR0 + j);
1568 for (k = 0; k < 8; k++, sd >>= 1) {
1569 lfsr = ((((crc & 0x02) >> 1) ^ (crc & 0x01)) ^ (sd & 0x01)) << 7;
1570 crc = (crc >> 1) + lfsr;
1571 }
1572 }
1573 if (crc != eeprom_image[EEPROM_PA_CRC])
1574 status = -1;
1575 } else {
1576 for (i = 0, k = 0; i < ETH_ALEN;) {
1577 k <<= 1;
1578 if (k > 0xffff)
1579 k -= 0xffff;
1580
1581 k += (u_char) (tmp = inb(EWRK3_APROM));
1582 dev->dev_addr[i] = (u_char) tmp;
1583 outb(dev->dev_addr[i], EWRK3_PAR0 + i);
1584 i++;
1585 k += (u_short) ((tmp = inb(EWRK3_APROM)) << 8);
1586 dev->dev_addr[i] = (u_char) tmp;
1587 outb(dev->dev_addr[i], EWRK3_PAR0 + i);
1588 i++;
1589
1590 if (k > 0xffff)
1591 k -= 0xffff;
1592 }
1593 if (k == 0xffff)
1594 k = 0;
1595 chksum = inb(EWRK3_APROM);
1596 chksum |= (inb(EWRK3_APROM) << 8);
1597 if (k != chksum)
1598 status = -1;
1599 }
1600
1601 return status;
1602 }
1603
1604 /*
1605 ** Look for a particular board name in the EISA configuration space
1606 */
EISA_signature(char * name,s32 eisa_id)1607 static int __init EISA_signature(char *name, s32 eisa_id)
1608 {
1609 u_long i;
1610 char *signatures[] = EWRK3_SIGNATURE;
1611 char ManCode[EWRK3_STRLEN];
1612 union {
1613 s32 ID;
1614 char Id[4];
1615 } Eisa;
1616 int status = 0;
1617
1618 *name = '\0';
1619 for (i = 0; i < 4; i++) {
1620 Eisa.Id[i] = inb(eisa_id + i);
1621 }
1622
1623 ManCode[0] = (((Eisa.Id[0] >> 2) & 0x1f) + 0x40);
1624 ManCode[1] = (((Eisa.Id[1] & 0xe0) >> 5) + ((Eisa.Id[0] & 0x03) << 3) + 0x40);
1625 ManCode[2] = (((Eisa.Id[2] >> 4) & 0x0f) + 0x30);
1626 ManCode[3] = ((Eisa.Id[2] & 0x0f) + 0x30);
1627 ManCode[4] = (((Eisa.Id[3] >> 4) & 0x0f) + 0x30);
1628 ManCode[5] = '\0';
1629
1630 for (i = 0; (*signatures[i] != '\0') && (*name == '\0'); i++) {
1631 if (strstr(ManCode, signatures[i]) != NULL) {
1632 strcpy(name, ManCode);
1633 status = 1;
1634 }
1635 }
1636
1637 return status; /* return the device name string */
1638 }
1639
ewrk3_ethtool_ioctl(struct net_device * dev,void * useraddr)1640 static int ewrk3_ethtool_ioctl(struct net_device *dev, void *useraddr)
1641 {
1642 struct ewrk3_private *lp = (struct ewrk3_private *) dev->priv;
1643 u_long iobase = dev->base_addr;
1644 u32 ethcmd;
1645
1646 if (get_user(ethcmd, (u32 *)useraddr))
1647 return -EFAULT;
1648
1649 switch (ethcmd) {
1650
1651 /* Get driver info */
1652 case ETHTOOL_GDRVINFO: {
1653 struct ethtool_drvinfo info = { ETHTOOL_GDRVINFO };
1654 int fwrev = Read_EEPROM(dev->base_addr, EEPROM_REVLVL);
1655
1656 strcpy(info.driver, DRV_NAME);
1657 strcpy(info.version, DRV_VERSION);
1658 sprintf(info.fw_version, "%d", fwrev);
1659 strcpy(info.bus_info, "N/A");
1660 info.eedump_len = EEPROM_MAX;
1661 if (copy_to_user(useraddr, &info, sizeof(info)))
1662 return -EFAULT;
1663 return 0;
1664 }
1665
1666 /* Get settings */
1667 case ETHTOOL_GSET: {
1668 struct ethtool_cmd ecmd = { ETHTOOL_GSET };
1669 u_char cr = inb(EWRK3_CR);
1670
1671 switch (lp->adapter_name[4]) {
1672 case '3': /* DE203 */
1673 ecmd.supported = SUPPORTED_BNC;
1674 ecmd.port = PORT_BNC;
1675 break;
1676
1677 case '4': /* DE204 */
1678 ecmd.supported = SUPPORTED_TP;
1679 ecmd.port = PORT_TP;
1680 break;
1681
1682 case '5': /* DE205 */
1683 ecmd.supported = SUPPORTED_TP | SUPPORTED_BNC | SUPPORTED_AUI;
1684 ecmd.autoneg = !(cr & CR_APD);
1685 /*
1686 ** Port is only valid if autoneg is disabled
1687 ** and even then we don't know if AUI is jumpered.
1688 */
1689 if (!ecmd.autoneg)
1690 ecmd.port = (cr & CR_PSEL) ? PORT_BNC : PORT_TP;
1691 break;
1692 }
1693
1694 ecmd.supported |= SUPPORTED_10baseT_Half;
1695 ecmd.speed = SPEED_10;
1696 ecmd.duplex = DUPLEX_HALF;
1697
1698 if (copy_to_user(useraddr, &ecmd, sizeof(ecmd)))
1699 return -EFAULT;
1700 return 0;
1701 }
1702
1703 /* Set settings */
1704 case ETHTOOL_SSET: {
1705 struct ethtool_cmd ecmd;
1706 u_char cr;
1707 u_long flags;
1708
1709 /* DE205 is the only card with anything to set */
1710 if (lp->adapter_name[4] != '5')
1711 return -EOPNOTSUPP;
1712
1713 if (copy_from_user(&ecmd, useraddr, sizeof(ecmd)))
1714 return -EFAULT;
1715
1716 /* Sanity-check parameters */
1717 if (ecmd.speed != SPEED_10)
1718 return -EINVAL;
1719 if (ecmd.port != PORT_TP && ecmd.port != PORT_BNC)
1720 return -EINVAL; /* AUI is not software-selectable */
1721 if (ecmd.transceiver != XCVR_INTERNAL)
1722 return -EINVAL;
1723 if (ecmd.duplex != DUPLEX_HALF)
1724 return -EINVAL;
1725 if (ecmd.phy_address != 0)
1726 return -EINVAL;
1727
1728 spin_lock_irqsave(&lp->hw_lock, flags);
1729 cr = inb(EWRK3_CR);
1730
1731 /* If Autoneg is set, change to Auto Port mode */
1732 /* Otherwise, disable Auto Port and set port explicitly */
1733 if (ecmd.autoneg) {
1734 cr &= ~CR_APD;
1735 } else {
1736 cr |= CR_APD;
1737 if (ecmd.port == PORT_TP)
1738 cr &= ~CR_PSEL; /* Force TP */
1739 else
1740 cr |= CR_PSEL; /* Force BNC */
1741 }
1742
1743 /* Commit the changes */
1744 outb(cr, EWRK3_CR);
1745
1746 spin_unlock_irqrestore(&lp->hw_lock, flags);
1747 if (copy_to_user(useraddr, &ecmd, sizeof(ecmd)))
1748 return -EFAULT;
1749 return 0;
1750 }
1751
1752 /* Get link status */
1753 case ETHTOOL_GLINK: {
1754 struct ethtool_value edata = { ETHTOOL_GLINK };
1755 u_char cmr = inb(EWRK3_CMR);
1756
1757 /* DE203 has BNC only and link status does not apply */
1758 if (lp->adapter_name[4] == '3')
1759 return -EOPNOTSUPP;
1760
1761 /* On DE204 this is always valid since TP is the only port. */
1762 /* On DE205 this reflects TP status even if BNC or AUI is selected. */
1763 edata.data = !(cmr & CMR_LINK);
1764
1765 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1766 return -EFAULT;
1767 return 0;
1768 }
1769
1770 /* Blink LED for identification */
1771 case ETHTOOL_PHYS_ID: {
1772 struct ethtool_value edata;
1773 u_long flags;
1774 u_char cr;
1775 int count;
1776
1777 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1778 return -EFAULT;
1779
1780 /* Toggle LED 4x per second */
1781 count = edata.data << 2;
1782
1783 spin_lock_irqsave(&lp->hw_lock, flags);
1784
1785 /* Bail if a PHYS_ID is already in progress */
1786 if (lp->led_mask == 0) {
1787 spin_unlock_irqrestore(&lp->hw_lock, flags);
1788 return -EBUSY;
1789 }
1790
1791 /* Prevent ISR from twiddling the LED */
1792 lp->led_mask = 0;
1793
1794 while (count--) {
1795 /* Toggle the LED */
1796 cr = inb(EWRK3_CR);
1797 outb(cr ^ CR_LED, EWRK3_CR);
1798
1799 /* Wait a little while */
1800 spin_unlock_irqrestore(&lp->hw_lock, flags);
1801 set_current_state(TASK_UNINTERRUPTIBLE);
1802 schedule_timeout(HZ>>2);
1803 spin_lock_irqsave(&lp->hw_lock, flags);
1804
1805 /* Exit if we got a signal */
1806 if (signal_pending(current))
1807 break;
1808 }
1809
1810 lp->led_mask = CR_LED;
1811 cr = inb(EWRK3_CR);
1812 outb(cr & ~CR_LED, EWRK3_CR);
1813 spin_unlock_irqrestore(&lp->hw_lock, flags);
1814 return signal_pending(current) ? -ERESTARTSYS : 0;
1815 }
1816
1817 }
1818
1819 return -EOPNOTSUPP;
1820 }
1821
1822 /*
1823 ** Perform IOCTL call functions here. Some are privileged operations and the
1824 ** effective uid is checked in those cases.
1825 */
ewrk3_ioctl(struct net_device * dev,struct ifreq * rq,int cmd)1826 static int ewrk3_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1827 {
1828 struct ewrk3_private *lp = (struct ewrk3_private *) dev->priv;
1829 struct ewrk3_ioctl *ioc = (struct ewrk3_ioctl *) &rq->ifr_data;
1830 u_long iobase = dev->base_addr;
1831 int i, j, status = 0;
1832 u_char csr;
1833 unsigned long flags;
1834 union ewrk3_addr {
1835 u_char addr[HASH_TABLE_LEN * ETH_ALEN];
1836 u_short val[(HASH_TABLE_LEN * ETH_ALEN) >> 1];
1837 };
1838
1839 union ewrk3_addr *tmp;
1840
1841 /* ethtool IOCTLs are handled elsewhere */
1842 if (cmd == SIOCETHTOOL)
1843 return ewrk3_ethtool_ioctl(dev, (void *)rq->ifr_data);
1844
1845 /* Other than ethtool, all we handle are private IOCTLs */
1846 if (cmd != EWRK3IOCTL)
1847 return -EOPNOTSUPP;
1848
1849 tmp = kmalloc(sizeof(union ewrk3_addr), GFP_KERNEL);
1850 if(tmp==NULL)
1851 return -ENOMEM;
1852
1853 switch (ioc->cmd) {
1854 case EWRK3_GET_HWADDR: /* Get the hardware address */
1855 for (i = 0; i < ETH_ALEN; i++) {
1856 tmp->addr[i] = dev->dev_addr[i];
1857 }
1858 ioc->len = ETH_ALEN;
1859 if (copy_to_user(ioc->data, tmp->addr, ioc->len))
1860 status = -EFAULT;
1861 break;
1862
1863 case EWRK3_SET_HWADDR: /* Set the hardware address */
1864 if (capable(CAP_NET_ADMIN)) {
1865 spin_lock_irqsave(&lp->hw_lock, flags);
1866 csr = inb(EWRK3_CSR);
1867 csr |= (CSR_TXD | CSR_RXD);
1868 outb(csr, EWRK3_CSR); /* Disable the TX and RX */
1869 spin_unlock_irqrestore(&lp->hw_lock, flags);
1870
1871 if (copy_from_user(tmp->addr, ioc->data, ETH_ALEN)) {
1872 status = -EFAULT;
1873 break;
1874 }
1875 spin_lock_irqsave(&lp->hw_lock, flags);
1876 for (i = 0; i < ETH_ALEN; i++) {
1877 dev->dev_addr[i] = tmp->addr[i];
1878 outb(tmp->addr[i], EWRK3_PAR0 + i);
1879 }
1880
1881 csr = inb(EWRK3_CSR);
1882 csr &= ~(CSR_TXD | CSR_RXD); /* Enable the TX and RX */
1883 outb(csr, EWRK3_CSR);
1884 spin_unlock_irqrestore(&lp->hw_lock, flags);
1885 } else {
1886 status = -EPERM;
1887 }
1888
1889 break;
1890 case EWRK3_SET_PROM: /* Set Promiscuous Mode */
1891 if (capable(CAP_NET_ADMIN)) {
1892 spin_lock_irqsave(&lp->hw_lock, flags);
1893 csr = inb(EWRK3_CSR);
1894 csr |= CSR_PME;
1895 csr &= ~CSR_MCE;
1896 outb(csr, EWRK3_CSR);
1897 spin_unlock_irqrestore(&lp->hw_lock, flags);
1898 } else {
1899 status = -EPERM;
1900 }
1901
1902 break;
1903 case EWRK3_CLR_PROM: /* Clear Promiscuous Mode */
1904 if (capable(CAP_NET_ADMIN)) {
1905 spin_lock_irqsave(&lp->hw_lock, flags);
1906 csr = inb(EWRK3_CSR);
1907 csr &= ~CSR_PME;
1908 outb(csr, EWRK3_CSR);
1909 spin_unlock_irqrestore(&lp->hw_lock, flags);
1910 } else {
1911 status = -EPERM;
1912 }
1913
1914 break;
1915 case EWRK3_GET_MCA: /* Get the multicast address table */
1916 spin_lock_irqsave(&lp->hw_lock, flags);
1917 if (lp->shmem_length == IO_ONLY) {
1918 outb(0, EWRK3_IOPR);
1919 outw(PAGE0_HTE, EWRK3_PIR1);
1920 for (i = 0; i < (HASH_TABLE_LEN >> 3); i++) {
1921 tmp->addr[i] = inb(EWRK3_DATA);
1922 }
1923 } else {
1924 outb(0, EWRK3_MPR);
1925 isa_memcpy_fromio(tmp->addr, lp->shmem_base + PAGE0_HTE, (HASH_TABLE_LEN >> 3));
1926 }
1927 spin_unlock_irqrestore(&lp->hw_lock, flags);
1928
1929 ioc->len = (HASH_TABLE_LEN >> 3);
1930 if (copy_to_user(ioc->data, tmp->addr, ioc->len))
1931 status = -EFAULT;
1932
1933 break;
1934 case EWRK3_SET_MCA: /* Set a multicast address */
1935 if (capable(CAP_NET_ADMIN)) {
1936 if (ioc->len > 1024)
1937 {
1938 status = -EINVAL;
1939 break;
1940 }
1941 if (copy_from_user(tmp->addr, ioc->data, ETH_ALEN * ioc->len)) {
1942 status = -EFAULT;
1943 break;
1944 }
1945 set_multicast_list(dev);
1946 } else {
1947 status = -EPERM;
1948 }
1949
1950 break;
1951 case EWRK3_CLR_MCA: /* Clear all multicast addresses */
1952 if (capable(CAP_NET_ADMIN)) {
1953 set_multicast_list(dev);
1954 } else {
1955 status = -EPERM;
1956 }
1957
1958 break;
1959 case EWRK3_MCA_EN: /* Enable multicast addressing */
1960 if (capable(CAP_NET_ADMIN)) {
1961 spin_lock_irqsave(&lp->hw_lock, flags);
1962 csr = inb(EWRK3_CSR);
1963 csr |= CSR_MCE;
1964 csr &= ~CSR_PME;
1965 outb(csr, EWRK3_CSR);
1966 spin_unlock_irqrestore(&lp->hw_lock, flags);
1967 } else {
1968 status = -EPERM;
1969 }
1970
1971 break;
1972 case EWRK3_GET_STATS: { /* Get the driver statistics */
1973 struct ewrk3_stats *tmp_stats =
1974 kmalloc(sizeof(lp->pktStats), GFP_KERNEL);
1975 if (!tmp_stats) {
1976 status = -ENOMEM;
1977 break;
1978 }
1979
1980 spin_lock_irqsave(&lp->hw_lock, flags);
1981 memcpy(tmp_stats, &lp->pktStats, sizeof(lp->pktStats));
1982 spin_unlock_irqrestore(&lp->hw_lock, flags);
1983
1984 ioc->len = sizeof(lp->pktStats);
1985 if (copy_to_user(ioc->data, tmp_stats, sizeof(lp->pktStats)))
1986 status = -EFAULT;
1987 kfree(tmp_stats);
1988 break;
1989 }
1990 case EWRK3_CLR_STATS: /* Zero out the driver statistics */
1991 if (capable(CAP_NET_ADMIN)) {
1992 spin_lock_irqsave(&lp->hw_lock, flags);
1993 memset(&lp->pktStats, 0, sizeof(lp->pktStats));
1994 spin_unlock_irqrestore(&lp->hw_lock,flags);
1995 } else {
1996 status = -EPERM;
1997 }
1998
1999 break;
2000 case EWRK3_GET_CSR: /* Get the CSR Register contents */
2001 tmp->addr[0] = inb(EWRK3_CSR);
2002 ioc->len = 1;
2003 if (copy_to_user(ioc->data, tmp->addr, ioc->len))
2004 status = -EFAULT;
2005 break;
2006 case EWRK3_SET_CSR: /* Set the CSR Register contents */
2007 if (capable(CAP_NET_ADMIN)) {
2008 if (copy_from_user(tmp->addr, ioc->data, 1)) {
2009 status = -EFAULT;
2010 break;
2011 }
2012 outb(tmp->addr[0], EWRK3_CSR);
2013 } else {
2014 status = -EPERM;
2015 }
2016
2017 break;
2018 case EWRK3_GET_EEPROM: /* Get the EEPROM contents */
2019 if (capable(CAP_NET_ADMIN)) {
2020 for (i = 0; i < (EEPROM_MAX >> 1); i++) {
2021 tmp->val[i] = (short) Read_EEPROM(iobase, i);
2022 }
2023 i = EEPROM_MAX;
2024 tmp->addr[i++] = inb(EWRK3_CMR); /* Config/Management Reg. */
2025 for (j = 0; j < ETH_ALEN; j++) {
2026 tmp->addr[i++] = inb(EWRK3_PAR0 + j);
2027 }
2028 ioc->len = EEPROM_MAX + 1 + ETH_ALEN;
2029 if (copy_to_user(ioc->data, tmp->addr, ioc->len))
2030 status = -EFAULT;
2031 } else {
2032 status = -EPERM;
2033 }
2034
2035 break;
2036 case EWRK3_SET_EEPROM: /* Set the EEPROM contents */
2037 if (capable(CAP_NET_ADMIN)) {
2038 if (copy_from_user(tmp->addr, ioc->data, EEPROM_MAX)) {
2039 status = -EFAULT;
2040 break;
2041 }
2042 for (i = 0; i < (EEPROM_MAX >> 1); i++) {
2043 Write_EEPROM(tmp->val[i], iobase, i);
2044 }
2045 } else {
2046 status = -EPERM;
2047 }
2048
2049 break;
2050 case EWRK3_GET_CMR: /* Get the CMR Register contents */
2051 tmp->addr[0] = inb(EWRK3_CMR);
2052 ioc->len = 1;
2053 if (copy_to_user(ioc->data, tmp->addr, ioc->len))
2054 status = -EFAULT;
2055 break;
2056 case EWRK3_SET_TX_CUT_THRU: /* Set TX cut through mode */
2057 if (capable(CAP_NET_ADMIN)) {
2058 lp->txc = 1;
2059 } else {
2060 status = -EPERM;
2061 }
2062
2063 break;
2064 case EWRK3_CLR_TX_CUT_THRU: /* Clear TX cut through mode */
2065 if (capable(CAP_NET_ADMIN)) {
2066 lp->txc = 0;
2067 } else {
2068 status = -EPERM;
2069 }
2070
2071 break;
2072 default:
2073 status = -EOPNOTSUPP;
2074 }
2075 kfree(tmp);
2076 return status;
2077 }
2078
2079 #ifdef MODULE
2080 static struct net_device *ewrk3_devs[MAX_NUM_EWRK3S];
2081 static int ndevs;
2082 static int io[MAX_NUM_EWRK3S+1] = { 0x300, 0, }; /* <--- EDIT THESE LINES FOR YOUR CONFIGURATION */
2083 static int irq[MAX_NUM_EWRK3S+1] = { 5, 0, }; /* or use the insmod io= irq= options */
2084
2085 /* '21' below should really be 'MAX_NUM_EWRK3S' */
2086 MODULE_PARM(io, "0-21i");
2087 MODULE_PARM(irq, "0-21i");
2088 MODULE_PARM_DESC(io, "EtherWORKS 3 I/O base address(es)");
2089 MODULE_PARM_DESC(irq, "EtherWORKS 3 IRQ number(s)");
2090
init_module(void)2091 int init_module(void)
2092 {
2093 int i=0;
2094
2095 while( io[i] && irq[i] ) {
2096 ewrk3_devs[ndevs] = kmalloc(sizeof(struct net_device), GFP_KERNEL);
2097 if (!ewrk3_devs[ndevs])
2098 goto error;
2099 memset(ewrk3_devs[ndevs], 0, sizeof(struct net_device));
2100 ewrk3_devs[ndevs]->base_addr = io[i];
2101 ewrk3_devs[ndevs]->irq = irq[i];
2102 ewrk3_devs[ndevs]->init = ewrk3_probe;
2103
2104 if (register_netdev(ewrk3_devs[ndevs]) == 0)
2105 ndevs++;
2106 else
2107 kfree(ewrk3_devs[ndevs]);
2108
2109 i++;
2110 }
2111
2112 return ndevs ? 0 : -EIO;
2113
2114 error:
2115 cleanup_module();
2116 return -ENOMEM;
2117 }
2118
cleanup_module(void)2119 void cleanup_module(void)
2120 {
2121 int i;
2122
2123 for( i=0; i<ndevs; i++ ) {
2124 unregister_netdev(ewrk3_devs[i]);
2125 if (ewrk3_devs[i]->priv) {
2126 kfree(ewrk3_devs[i]->priv);
2127 ewrk3_devs[i]->priv = NULL;
2128 }
2129 ewrk3_devs[i]->irq = 0;
2130
2131 release_region(ewrk3_devs[i]->base_addr, EWRK3_TOTAL_SIZE);
2132 kfree(ewrk3_devs[i]);
2133 ewrk3_devs[i] = NULL;
2134 }
2135 }
2136 #endif /* MODULE */
2137 MODULE_LICENSE("GPL");
2138
2139
2140
2141 /*
2142 * Local variables:
2143 * 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"
2144 *
2145 * 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"
2146 * End:
2147 */
2148