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