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