blob: 6a93b666eb7231c272fe8aa84424a1aa9be2e799 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/drivers/acorn/net/etherh.c
3 *
4 * Copyright (C) 2000-2002 Russell King
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * NS8390 I-cubed EtherH and ANT EtherM specific driver
11 * Thanks to I-Cubed for information on their cards.
12 * EtherM conversion (C) 1999 Chris Kemp and Tim Watterton
13 * EtherM integration (C) 2000 Aleph One Ltd (Tak-Shing Chan)
14 * EtherM integration re-engineered by Russell King.
15 *
16 * Changelog:
17 * 08-12-1996 RMK 1.00 Created
18 * RMK 1.03 Added support for EtherLan500 cards
19 * 23-11-1997 RMK 1.04 Added media autodetection
20 * 16-04-1998 RMK 1.05 Improved media autodetection
21 * 10-02-2000 RMK 1.06 Updated for 2.3.43
22 * 13-05-2000 RMK 1.07 Updated for 2.3.99-pre8
23 * 12-10-1999 CK/TEW EtherM driver first release
24 * 21-12-2000 TTC EtherH/EtherM integration
25 * 25-12-2000 RMK 1.08 Clean integration of EtherM into this driver.
26 * 03-01-2002 RMK 1.09 Always enable IRQs if we're in the nic slot.
27 */
28
29#include <linux/module.h>
30#include <linux/kernel.h>
31#include <linux/sched.h>
32#include <linux/types.h>
33#include <linux/fcntl.h>
34#include <linux/interrupt.h>
35#include <linux/ptrace.h>
36#include <linux/ioport.h>
37#include <linux/in.h>
38#include <linux/slab.h>
39#include <linux/string.h>
40#include <linux/errno.h>
41#include <linux/netdevice.h>
42#include <linux/etherdevice.h>
43#include <linux/ethtool.h>
44#include <linux/skbuff.h>
45#include <linux/delay.h>
46#include <linux/device.h>
47#include <linux/init.h>
48#include <linux/bitops.h>
49
50#include <asm/system.h>
51#include <asm/ecard.h>
52#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54#include "../8390.h"
55
56#define NET_DEBUG 0
57#define DEBUG_INIT 2
58
59#define DRV_NAME "etherh"
60#define DRV_VERSION "1.11"
61
62static unsigned int net_debug = NET_DEBUG;
63
64struct etherh_priv {
65 void __iomem *ioc_fast;
66 void __iomem *memc;
67 void __iomem *dma_base;
68 unsigned int id;
69 void __iomem *ctrl_port;
70 unsigned char ctrl;
71 u32 supported;
72};
73
74struct etherh_data {
75 unsigned long ns8390_offset;
76 unsigned long dataport_offset;
77 unsigned long ctrlport_offset;
78 int ctrl_ioc;
79 const char name[16];
80 u32 supported;
81 unsigned char tx_start_page;
82 unsigned char stop_page;
83};
84
85MODULE_AUTHOR("Russell King");
86MODULE_DESCRIPTION("EtherH/EtherM driver");
87MODULE_LICENSE("GPL");
88
89static char version[] __initdata =
90 "EtherH/EtherM Driver (c) 2002-2004 Russell King " DRV_VERSION "\n";
91
92#define ETHERH500_DATAPORT 0x800 /* MEMC */
93#define ETHERH500_NS8390 0x000 /* MEMC */
94#define ETHERH500_CTRLPORT 0x800 /* IOC */
95
96#define ETHERH600_DATAPORT 0x040 /* MEMC */
97#define ETHERH600_NS8390 0x800 /* MEMC */
98#define ETHERH600_CTRLPORT 0x200 /* MEMC */
99
100#define ETHERH_CP_IE 1
101#define ETHERH_CP_IF 2
102#define ETHERH_CP_HEARTBEAT 2
103
104#define ETHERH_TX_START_PAGE 1
105#define ETHERH_STOP_PAGE 127
106
107/*
108 * These came from CK/TEW
109 */
110#define ETHERM_DATAPORT 0x200 /* MEMC */
111#define ETHERM_NS8390 0x800 /* MEMC */
112#define ETHERM_CTRLPORT 0x23c /* MEMC */
113
114#define ETHERM_TX_START_PAGE 64
115#define ETHERM_STOP_PAGE 127
116
117/* ------------------------------------------------------------------------ */
118
119#define etherh_priv(dev) \
120 ((struct etherh_priv *)(((char *)netdev_priv(dev)) + sizeof(struct ei_device)))
121
122static inline void etherh_set_ctrl(struct etherh_priv *eh, unsigned char mask)
123{
124 unsigned char ctrl = eh->ctrl | mask;
125 eh->ctrl = ctrl;
126 writeb(ctrl, eh->ctrl_port);
127}
128
129static inline void etherh_clr_ctrl(struct etherh_priv *eh, unsigned char mask)
130{
131 unsigned char ctrl = eh->ctrl & ~mask;
132 eh->ctrl = ctrl;
133 writeb(ctrl, eh->ctrl_port);
134}
135
136static inline unsigned int etherh_get_stat(struct etherh_priv *eh)
137{
138 return readb(eh->ctrl_port);
139}
140
141
142
143
144static void etherh_irq_enable(ecard_t *ec, int irqnr)
145{
146 struct etherh_priv *eh = ec->irq_data;
147
148 etherh_set_ctrl(eh, ETHERH_CP_IE);
149}
150
151static void etherh_irq_disable(ecard_t *ec, int irqnr)
152{
153 struct etherh_priv *eh = ec->irq_data;
154
155 etherh_clr_ctrl(eh, ETHERH_CP_IE);
156}
157
158static expansioncard_ops_t etherh_ops = {
159 .irqenable = etherh_irq_enable,
160 .irqdisable = etherh_irq_disable,
161};
162
163
164
165
166static void
167etherh_setif(struct net_device *dev)
168{
169 struct ei_device *ei_local = netdev_priv(dev);
170 unsigned long flags;
171 void __iomem *addr;
172
173 local_irq_save(flags);
174
175 /* set the interface type */
176 switch (etherh_priv(dev)->id) {
177 case PROD_I3_ETHERLAN600:
178 case PROD_I3_ETHERLAN600A:
Nicolas Pitrec7e78872005-06-29 18:10:54 +0100179 addr = (void *)dev->base_addr + EN0_RCNTHI;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
181 switch (dev->if_port) {
182 case IF_PORT_10BASE2:
183 writeb((readb(addr) & 0xf8) | 1, addr);
184 break;
185 case IF_PORT_10BASET:
186 writeb((readb(addr) & 0xf8), addr);
187 break;
188 }
189 break;
190
191 case PROD_I3_ETHERLAN500:
192 switch (dev->if_port) {
193 case IF_PORT_10BASE2:
194 etherh_clr_ctrl(etherh_priv(dev), ETHERH_CP_IF);
195 break;
196
197 case IF_PORT_10BASET:
198 etherh_set_ctrl(etherh_priv(dev), ETHERH_CP_IF);
199 break;
200 }
201 break;
202
203 default:
204 break;
205 }
206
207 local_irq_restore(flags);
208}
209
210static int
211etherh_getifstat(struct net_device *dev)
212{
213 struct ei_device *ei_local = netdev_priv(dev);
214 void __iomem *addr;
215 int stat = 0;
216
217 switch (etherh_priv(dev)->id) {
218 case PROD_I3_ETHERLAN600:
219 case PROD_I3_ETHERLAN600A:
Nicolas Pitrec7e78872005-06-29 18:10:54 +0100220 addr = (void *)dev->base_addr + EN0_RCNTHI;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 switch (dev->if_port) {
222 case IF_PORT_10BASE2:
223 stat = 1;
224 break;
225 case IF_PORT_10BASET:
226 stat = readb(addr) & 4;
227 break;
228 }
229 break;
230
231 case PROD_I3_ETHERLAN500:
232 switch (dev->if_port) {
233 case IF_PORT_10BASE2:
234 stat = 1;
235 break;
236 case IF_PORT_10BASET:
237 stat = etherh_get_stat(etherh_priv(dev)) & ETHERH_CP_HEARTBEAT;
238 break;
239 }
240 break;
241
242 default:
243 stat = 0;
244 break;
245 }
246
247 return stat != 0;
248}
249
250/*
251 * Configure the interface. Note that we ignore the other
252 * parts of ifmap, since its mostly meaningless for this driver.
253 */
254static int etherh_set_config(struct net_device *dev, struct ifmap *map)
255{
256 switch (map->port) {
257 case IF_PORT_10BASE2:
258 case IF_PORT_10BASET:
259 /*
260 * If the user explicitly sets the interface
261 * media type, turn off automedia detection.
262 */
263 dev->flags &= ~IFF_AUTOMEDIA;
264 dev->if_port = map->port;
265 break;
266
267 default:
268 return -EINVAL;
269 }
270
271 etherh_setif(dev);
272
273 return 0;
274}
275
276/*
277 * Reset the 8390 (hard reset). Note that we can't actually do this.
278 */
279static void
280etherh_reset(struct net_device *dev)
281{
282 struct ei_device *ei_local = netdev_priv(dev);
Nicolas Pitrec7e78872005-06-29 18:10:54 +0100283 void __iomem *addr = (void *)dev->base_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
285 writeb(E8390_NODMA+E8390_PAGE0+E8390_STOP, addr);
286
287 /*
288 * See if we need to change the interface type.
289 * Note that we use 'interface_num' as a flag
290 * to indicate that we need to change the media.
291 */
292 if (dev->flags & IFF_AUTOMEDIA && ei_local->interface_num) {
293 ei_local->interface_num = 0;
294
295 if (dev->if_port == IF_PORT_10BASET)
296 dev->if_port = IF_PORT_10BASE2;
297 else
298 dev->if_port = IF_PORT_10BASET;
299
300 etherh_setif(dev);
301 }
302}
303
304/*
305 * Write a block of data out to the 8390
306 */
307static void
308etherh_block_output (struct net_device *dev, int count, const unsigned char *buf, int start_page)
309{
310 struct ei_device *ei_local = netdev_priv(dev);
311 unsigned long dma_start;
312 void __iomem *dma_base, *addr;
313
314 if (ei_local->dmaing) {
315 printk(KERN_ERR "%s: DMAing conflict in etherh_block_input: "
316 " DMAstat %d irqlock %d\n", dev->name,
317 ei_local->dmaing, ei_local->irqlock);
318 return;
319 }
320
321 /*
322 * Make sure we have a round number of bytes if we're in word mode.
323 */
324 if (count & 1 && ei_local->word16)
325 count++;
326
327 ei_local->dmaing = 1;
328
Nicolas Pitrec7e78872005-06-29 18:10:54 +0100329 addr = (void *)dev->base_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 dma_base = etherh_priv(dev)->dma_base;
331
332 count = (count + 1) & ~1;
333 writeb (E8390_NODMA | E8390_PAGE0 | E8390_START, addr + E8390_CMD);
334
335 writeb (0x42, addr + EN0_RCNTLO);
336 writeb (0x00, addr + EN0_RCNTHI);
337 writeb (0x42, addr + EN0_RSARLO);
338 writeb (0x00, addr + EN0_RSARHI);
339 writeb (E8390_RREAD | E8390_START, addr + E8390_CMD);
340
341 udelay (1);
342
343 writeb (ENISR_RDC, addr + EN0_ISR);
344 writeb (count, addr + EN0_RCNTLO);
345 writeb (count >> 8, addr + EN0_RCNTHI);
346 writeb (0, addr + EN0_RSARLO);
347 writeb (start_page, addr + EN0_RSARHI);
348 writeb (E8390_RWRITE | E8390_START, addr + E8390_CMD);
349
350 if (ei_local->word16)
351 writesw (dma_base, buf, count >> 1);
352 else
353 writesb (dma_base, buf, count);
354
355 dma_start = jiffies;
356
357 while ((readb (addr + EN0_ISR) & ENISR_RDC) == 0)
358 if (jiffies - dma_start > 2*HZ/100) { /* 20ms */
359 printk(KERN_ERR "%s: timeout waiting for TX RDC\n",
360 dev->name);
361 etherh_reset (dev);
362 NS8390_init (dev, 1);
363 break;
364 }
365
366 writeb (ENISR_RDC, addr + EN0_ISR);
367 ei_local->dmaing = 0;
368}
369
370/*
371 * Read a block of data from the 8390
372 */
373static void
374etherh_block_input (struct net_device *dev, int count, struct sk_buff *skb, int ring_offset)
375{
376 struct ei_device *ei_local = netdev_priv(dev);
377 unsigned char *buf;
378 void __iomem *dma_base, *addr;
379
380 if (ei_local->dmaing) {
381 printk(KERN_ERR "%s: DMAing conflict in etherh_block_input: "
382 " DMAstat %d irqlock %d\n", dev->name,
383 ei_local->dmaing, ei_local->irqlock);
384 return;
385 }
386
387 ei_local->dmaing = 1;
388
Nicolas Pitrec7e78872005-06-29 18:10:54 +0100389 addr = (void *)dev->base_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 dma_base = etherh_priv(dev)->dma_base;
391
392 buf = skb->data;
393 writeb (E8390_NODMA | E8390_PAGE0 | E8390_START, addr + E8390_CMD);
394 writeb (count, addr + EN0_RCNTLO);
395 writeb (count >> 8, addr + EN0_RCNTHI);
396 writeb (ring_offset, addr + EN0_RSARLO);
397 writeb (ring_offset >> 8, addr + EN0_RSARHI);
398 writeb (E8390_RREAD | E8390_START, addr + E8390_CMD);
399
400 if (ei_local->word16) {
401 readsw (dma_base, buf, count >> 1);
402 if (count & 1)
403 buf[count - 1] = readb (dma_base);
404 } else
405 readsb (dma_base, buf, count);
406
407 writeb (ENISR_RDC, addr + EN0_ISR);
408 ei_local->dmaing = 0;
409}
410
411/*
412 * Read a header from the 8390
413 */
414static void
415etherh_get_header (struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
416{
417 struct ei_device *ei_local = netdev_priv(dev);
418 void __iomem *dma_base, *addr;
419
420 if (ei_local->dmaing) {
421 printk(KERN_ERR "%s: DMAing conflict in etherh_get_header: "
422 " DMAstat %d irqlock %d\n", dev->name,
423 ei_local->dmaing, ei_local->irqlock);
424 return;
425 }
426
427 ei_local->dmaing = 1;
428
Nicolas Pitrec7e78872005-06-29 18:10:54 +0100429 addr = (void *)dev->base_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 dma_base = etherh_priv(dev)->dma_base;
431
432 writeb (E8390_NODMA | E8390_PAGE0 | E8390_START, addr + E8390_CMD);
433 writeb (sizeof (*hdr), addr + EN0_RCNTLO);
434 writeb (0, addr + EN0_RCNTHI);
435 writeb (0, addr + EN0_RSARLO);
436 writeb (ring_page, addr + EN0_RSARHI);
437 writeb (E8390_RREAD | E8390_START, addr + E8390_CMD);
438
439 if (ei_local->word16)
440 readsw (dma_base, hdr, sizeof (*hdr) >> 1);
441 else
442 readsb (dma_base, hdr, sizeof (*hdr));
443
444 writeb (ENISR_RDC, addr + EN0_ISR);
445 ei_local->dmaing = 0;
446}
447
448/*
449 * Open/initialize the board. This is called (in the current kernel)
450 * sometime after booting when the 'ifconfig' program is run.
451 *
452 * This routine should set everything up anew at each open, even
453 * registers that "should" only need to be set once at boot, so that
454 * there is non-reboot way to recover if something goes wrong.
455 */
456static int
457etherh_open(struct net_device *dev)
458{
459 struct ei_device *ei_local = netdev_priv(dev);
460
461 if (!is_valid_ether_addr(dev->dev_addr)) {
462 printk(KERN_WARNING "%s: invalid ethernet MAC address\n",
463 dev->name);
464 return -EINVAL;
465 }
466
467 if (request_irq(dev->irq, ei_interrupt, 0, dev->name, dev))
468 return -EAGAIN;
469
470 /*
471 * Make sure that we aren't going to change the
472 * media type on the next reset - we are about to
473 * do automedia manually now.
474 */
475 ei_local->interface_num = 0;
476
477 /*
478 * If we are doing automedia detection, do it now.
479 * This is more reliable than the 8390's detection.
480 */
481 if (dev->flags & IFF_AUTOMEDIA) {
482 dev->if_port = IF_PORT_10BASET;
483 etherh_setif(dev);
484 mdelay(1);
485 if (!etherh_getifstat(dev)) {
486 dev->if_port = IF_PORT_10BASE2;
487 etherh_setif(dev);
488 }
489 } else
490 etherh_setif(dev);
491
492 etherh_reset(dev);
493 ei_open(dev);
494
495 return 0;
496}
497
498/*
499 * The inverse routine to etherh_open().
500 */
501static int
502etherh_close(struct net_device *dev)
503{
504 ei_close (dev);
505 free_irq (dev->irq, dev);
506 return 0;
507}
508
509/*
510 * Initialisation
511 */
512
513static void __init etherh_banner(void)
514{
515 static int version_printed;
516
517 if (net_debug && version_printed++ == 0)
518 printk(KERN_INFO "%s", version);
519}
520
521/*
522 * Read the ethernet address string from the on board rom.
523 * This is an ascii string...
524 */
525static int __init etherh_addr(char *addr, struct expansion_card *ec)
526{
527 struct in_chunk_dir cd;
528 char *s;
529
530 if (!ecard_readchunk(&cd, ec, 0xf5, 0)) {
531 printk(KERN_ERR "%s: unable to read podule description string\n",
532 ec->dev.bus_id);
533 goto no_addr;
534 }
535
536 s = strchr(cd.d.string, '(');
537 if (s) {
538 int i;
539
540 for (i = 0; i < 6; i++) {
541 addr[i] = simple_strtoul(s + 1, &s, 0x10);
542 if (*s != (i == 5? ')' : ':'))
543 break;
544 }
545
546 if (i == 6)
547 return 0;
548 }
549
550 printk(KERN_ERR "%s: unable to parse MAC address: %s\n",
551 ec->dev.bus_id, cd.d.string);
552
553 no_addr:
554 return -ENODEV;
555}
556
557/*
558 * Create an ethernet address from the system serial number.
559 */
560static int __init etherm_addr(char *addr)
561{
562 unsigned int serial;
563
564 if (system_serial_low == 0 && system_serial_high == 0)
565 return -ENODEV;
566
567 serial = system_serial_low | system_serial_high;
568
569 addr[0] = 0;
570 addr[1] = 0;
571 addr[2] = 0xa4;
572 addr[3] = 0x10 + (serial >> 24);
573 addr[4] = serial >> 16;
574 addr[5] = serial >> 8;
575 return 0;
576}
577
578static void etherh_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
579{
580 strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
581 strlcpy(info->version, DRV_VERSION, sizeof(info->version));
582 strlcpy(info->bus_info, dev->class_dev.dev->bus_id,
583 sizeof(info->bus_info));
584}
585
586static int etherh_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
587{
588 cmd->supported = etherh_priv(dev)->supported;
589 cmd->speed = SPEED_10;
590 cmd->duplex = DUPLEX_HALF;
591 cmd->port = dev->if_port == IF_PORT_10BASET ? PORT_TP : PORT_BNC;
592 cmd->autoneg = dev->flags & IFF_AUTOMEDIA ? AUTONEG_ENABLE : AUTONEG_DISABLE;
593 return 0;
594}
595
596static int etherh_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
597{
598 switch (cmd->autoneg) {
599 case AUTONEG_ENABLE:
600 dev->flags |= IFF_AUTOMEDIA;
601 break;
602
603 case AUTONEG_DISABLE:
604 switch (cmd->port) {
605 case PORT_TP:
606 dev->if_port = IF_PORT_10BASET;
607 break;
608
609 case PORT_BNC:
610 dev->if_port = IF_PORT_10BASE2;
611 break;
612
613 default:
614 return -EINVAL;
615 }
616 dev->flags &= ~IFF_AUTOMEDIA;
617 break;
618
619 default:
620 return -EINVAL;
621 }
622
623 etherh_setif(dev);
624
625 return 0;
626}
627
628static struct ethtool_ops etherh_ethtool_ops = {
629 .get_settings = etherh_get_settings,
630 .set_settings = etherh_set_settings,
631 .get_drvinfo = etherh_get_drvinfo,
632};
633
634static u32 etherh_regoffsets[16];
635static u32 etherm_regoffsets[16];
636
637static int __init
638etherh_probe(struct expansion_card *ec, const struct ecard_id *id)
639{
640 const struct etherh_data *data = id->data;
641 struct ei_device *ei_local;
642 struct net_device *dev;
643 struct etherh_priv *eh;
644 int i, ret;
645
646 etherh_banner();
647
648 ret = ecard_request_resources(ec);
649 if (ret)
650 goto out;
651
652 dev = __alloc_ei_netdev(sizeof(struct etherh_priv));
653 if (!dev) {
654 ret = -ENOMEM;
655 goto release;
656 }
657
658 SET_MODULE_OWNER(dev);
659 SET_NETDEV_DEV(dev, &ec->dev);
660
661 dev->open = etherh_open;
662 dev->stop = etherh_close;
663 dev->set_config = etherh_set_config;
664 dev->irq = ec->irq;
665 dev->ethtool_ops = &etherh_ethtool_ops;
666
667 if (data->supported & SUPPORTED_Autoneg)
668 dev->flags |= IFF_AUTOMEDIA;
669 if (data->supported & SUPPORTED_TP) {
670 dev->flags |= IFF_PORTSEL;
671 dev->if_port = IF_PORT_10BASET;
672 } else if (data->supported & SUPPORTED_BNC) {
673 dev->flags |= IFF_PORTSEL;
674 dev->if_port = IF_PORT_10BASE2;
675 } else
676 dev->if_port = IF_PORT_UNKNOWN;
677
678 eh = etherh_priv(dev);
679 eh->supported = data->supported;
680 eh->ctrl = 0;
681 eh->id = ec->cid.product;
682 eh->memc = ioremap(ecard_resource_start(ec, ECARD_RES_MEMC), PAGE_SIZE);
683 if (!eh->memc) {
684 ret = -ENOMEM;
685 goto free;
686 }
687
688 eh->ctrl_port = eh->memc;
689 if (data->ctrl_ioc) {
690 eh->ioc_fast = ioremap(ecard_resource_start(ec, ECARD_RES_IOCFAST), PAGE_SIZE);
691 if (!eh->ioc_fast) {
692 ret = -ENOMEM;
693 goto free;
694 }
695 eh->ctrl_port = eh->ioc_fast;
696 }
697
Nicolas Pitrec7e78872005-06-29 18:10:54 +0100698 dev->base_addr = (unsigned long)eh->memc + data->ns8390_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 eh->dma_base = eh->memc + data->dataport_offset;
700 eh->ctrl_port += data->ctrlport_offset;
701
702 /*
703 * IRQ and control port handling - only for non-NIC slot cards.
704 */
705 if (ec->slot_no != 8) {
706 ec->ops = &etherh_ops;
707 ec->irq_data = eh;
708 } else {
709 /*
710 * If we're in the NIC slot, make sure the IRQ is enabled
711 */
712 etherh_set_ctrl(eh, ETHERH_CP_IE);
713 }
714
715 ei_local = netdev_priv(dev);
716 spin_lock_init(&ei_local->page_lock);
717
718 if (ec->cid.product == PROD_ANT_ETHERM) {
719 etherm_addr(dev->dev_addr);
720 ei_local->reg_offset = etherm_regoffsets;
721 } else {
722 etherh_addr(dev->dev_addr, ec);
723 ei_local->reg_offset = etherh_regoffsets;
724 }
725
726 ei_local->name = dev->name;
727 ei_local->word16 = 1;
728 ei_local->tx_start_page = data->tx_start_page;
729 ei_local->rx_start_page = ei_local->tx_start_page + TX_PAGES;
730 ei_local->stop_page = data->stop_page;
731 ei_local->reset_8390 = etherh_reset;
732 ei_local->block_input = etherh_block_input;
733 ei_local->block_output = etherh_block_output;
734 ei_local->get_8390_hdr = etherh_get_header;
735 ei_local->interface_num = 0;
736
737 etherh_reset(dev);
738 NS8390_init(dev, 0);
739
740 ret = register_netdev(dev);
741 if (ret)
742 goto free;
743
744 printk(KERN_INFO "%s: %s in slot %d, ",
745 dev->name, data->name, ec->slot_no);
746
747 for (i = 0; i < 6; i++)
748 printk("%2.2x%c", dev->dev_addr[i], i == 5 ? '\n' : ':');
749
750 ecard_set_drvdata(ec, dev);
751
752 return 0;
753
754 free:
755 if (eh->ioc_fast)
756 iounmap(eh->ioc_fast);
757 if (eh->memc)
758 iounmap(eh->memc);
759 free_netdev(dev);
760 release:
761 ecard_release_resources(ec);
762 out:
763 return ret;
764}
765
766static void __devexit etherh_remove(struct expansion_card *ec)
767{
768 struct net_device *dev = ecard_get_drvdata(ec);
769 struct etherh_priv *eh = etherh_priv(dev);
770
771 ecard_set_drvdata(ec, NULL);
772
773 unregister_netdev(dev);
774 ec->ops = NULL;
775
776 if (eh->ioc_fast)
777 iounmap(eh->ioc_fast);
778 iounmap(eh->memc);
779
780 free_netdev(dev);
781
782 ecard_release_resources(ec);
783}
784
785static struct etherh_data etherm_data = {
786 .ns8390_offset = ETHERM_NS8390,
787 .dataport_offset = ETHERM_NS8390 + ETHERM_DATAPORT,
788 .ctrlport_offset = ETHERM_NS8390 + ETHERM_CTRLPORT,
789 .name = "ANT EtherM",
790 .supported = SUPPORTED_10baseT_Half,
791 .tx_start_page = ETHERM_TX_START_PAGE,
792 .stop_page = ETHERM_STOP_PAGE,
793};
794
795static struct etherh_data etherlan500_data = {
796 .ns8390_offset = ETHERH500_NS8390,
797 .dataport_offset = ETHERH500_NS8390 + ETHERH500_DATAPORT,
798 .ctrlport_offset = ETHERH500_CTRLPORT,
799 .ctrl_ioc = 1,
800 .name = "i3 EtherH 500",
801 .supported = SUPPORTED_10baseT_Half,
802 .tx_start_page = ETHERH_TX_START_PAGE,
803 .stop_page = ETHERH_STOP_PAGE,
804};
805
806static struct etherh_data etherlan600_data = {
807 .ns8390_offset = ETHERH600_NS8390,
808 .dataport_offset = ETHERH600_NS8390 + ETHERH600_DATAPORT,
809 .ctrlport_offset = ETHERH600_NS8390 + ETHERH600_CTRLPORT,
810 .name = "i3 EtherH 600",
811 .supported = SUPPORTED_10baseT_Half | SUPPORTED_TP | SUPPORTED_BNC | SUPPORTED_Autoneg,
812 .tx_start_page = ETHERH_TX_START_PAGE,
813 .stop_page = ETHERH_STOP_PAGE,
814};
815
816static struct etherh_data etherlan600a_data = {
817 .ns8390_offset = ETHERH600_NS8390,
818 .dataport_offset = ETHERH600_NS8390 + ETHERH600_DATAPORT,
819 .ctrlport_offset = ETHERH600_NS8390 + ETHERH600_CTRLPORT,
820 .name = "i3 EtherH 600A",
821 .supported = SUPPORTED_10baseT_Half | SUPPORTED_TP | SUPPORTED_BNC | SUPPORTED_Autoneg,
822 .tx_start_page = ETHERH_TX_START_PAGE,
823 .stop_page = ETHERH_STOP_PAGE,
824};
825
826static const struct ecard_id etherh_ids[] = {
827 { MANU_ANT, PROD_ANT_ETHERM, &etherm_data },
828 { MANU_I3, PROD_I3_ETHERLAN500, &etherlan500_data },
829 { MANU_I3, PROD_I3_ETHERLAN600, &etherlan600_data },
830 { MANU_I3, PROD_I3_ETHERLAN600A, &etherlan600a_data },
831 { 0xffff, 0xffff }
832};
833
834static struct ecard_driver etherh_driver = {
835 .probe = etherh_probe,
836 .remove = __devexit_p(etherh_remove),
837 .id_table = etherh_ids,
838 .drv = {
839 .name = DRV_NAME,
840 },
841};
842
843static int __init etherh_init(void)
844{
845 int i;
846
847 for (i = 0; i < 16; i++) {
848 etherh_regoffsets[i] = i << 2;
849 etherm_regoffsets[i] = i << 5;
850 }
851
852 return ecard_register_driver(&etherh_driver);
853}
854
855static void __exit etherh_exit(void)
856{
857 ecard_remove_driver(&etherh_driver);
858}
859
860module_init(etherh_init);
861module_exit(etherh_exit);