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