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