Loading...
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 DRV_NAME "etherh"
60#define DRV_VERSION "1.11"
61
62static char version[] =
63 "EtherH/EtherM Driver (c) 2002-2004 Russell King " DRV_VERSION "\n";
64
65#include "lib8390.c"
66
67static u32 etherh_msg_enable;
68
69struct etherh_priv {
70 void __iomem *ioc_fast;
71 void __iomem *memc;
72 void __iomem *dma_base;
73 unsigned int id;
74 void __iomem *ctrl_port;
75 unsigned char ctrl;
76 u32 supported;
77};
78
79struct etherh_data {
80 unsigned long ns8390_offset;
81 unsigned long dataport_offset;
82 unsigned long ctrlport_offset;
83 int ctrl_ioc;
84 const char name[16];
85 u32 supported;
86 unsigned char tx_start_page;
87 unsigned char stop_page;
88};
89
90MODULE_AUTHOR("Russell King");
91MODULE_DESCRIPTION("EtherH/EtherM driver");
92MODULE_LICENSE("GPL");
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
124static 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
131static 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
138static inline unsigned int etherh_get_stat(struct etherh_priv *eh)
139{
140 return readb(eh->ctrl_port);
141}
142
143
144
145
146static 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
153static 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
160static expansioncard_ops_t etherh_ops = {
161 .irqenable = etherh_irq_enable,
162 .irqdisable = etherh_irq_disable,
163};
164
165
166
167
168static void
169etherh_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 = (void __iomem *)dev->base_addr + 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
212static int
213etherh_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 = (void __iomem *)dev->base_addr + 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 */
256static 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 */
281static void
282etherh_reset(struct net_device *dev)
283{
284 struct ei_device *ei_local = netdev_priv(dev);
285 void __iomem *addr = (void __iomem *)dev->base_addr;
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 */
309static void
310etherh_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 netdev_err(dev, "DMAing conflict in etherh_block_input: "
318 " DMAstat %d irqlock %d\n",
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 = (void __iomem *)dev->base_addr;
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 (time_after(jiffies, dma_start + 2*HZ/100)) { /* 20ms */
361 netdev_warn(dev, "timeout waiting for TX RDC\n");
362 etherh_reset (dev);
363 __NS8390_init (dev, 1);
364 break;
365 }
366
367 writeb (ENISR_RDC, addr + EN0_ISR);
368 ei_local->dmaing = 0;
369}
370
371/*
372 * Read a block of data from the 8390
373 */
374static void
375etherh_block_input (struct net_device *dev, int count, struct sk_buff *skb, int ring_offset)
376{
377 struct ei_device *ei_local = netdev_priv(dev);
378 unsigned char *buf;
379 void __iomem *dma_base, *addr;
380
381 if (ei_local->dmaing) {
382 netdev_err(dev, "DMAing conflict in etherh_block_input: "
383 " DMAstat %d irqlock %d\n",
384 ei_local->dmaing, ei_local->irqlock);
385 return;
386 }
387
388 ei_local->dmaing = 1;
389
390 addr = (void __iomem *)dev->base_addr;
391 dma_base = etherh_priv(dev)->dma_base;
392
393 buf = skb->data;
394 writeb (E8390_NODMA | E8390_PAGE0 | E8390_START, addr + E8390_CMD);
395 writeb (count, addr + EN0_RCNTLO);
396 writeb (count >> 8, addr + EN0_RCNTHI);
397 writeb (ring_offset, addr + EN0_RSARLO);
398 writeb (ring_offset >> 8, addr + EN0_RSARHI);
399 writeb (E8390_RREAD | E8390_START, addr + E8390_CMD);
400
401 if (ei_local->word16) {
402 readsw (dma_base, buf, count >> 1);
403 if (count & 1)
404 buf[count - 1] = readb (dma_base);
405 } else
406 readsb (dma_base, buf, count);
407
408 writeb (ENISR_RDC, addr + EN0_ISR);
409 ei_local->dmaing = 0;
410}
411
412/*
413 * Read a header from the 8390
414 */
415static void
416etherh_get_header (struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
417{
418 struct ei_device *ei_local = netdev_priv(dev);
419 void __iomem *dma_base, *addr;
420
421 if (ei_local->dmaing) {
422 netdev_err(dev, "DMAing conflict in etherh_get_header: "
423 " DMAstat %d irqlock %d\n",
424 ei_local->dmaing, ei_local->irqlock);
425 return;
426 }
427
428 ei_local->dmaing = 1;
429
430 addr = (void __iomem *)dev->base_addr;
431 dma_base = etherh_priv(dev)->dma_base;
432
433 writeb (E8390_NODMA | E8390_PAGE0 | E8390_START, addr + E8390_CMD);
434 writeb (sizeof (*hdr), addr + EN0_RCNTLO);
435 writeb (0, addr + EN0_RCNTHI);
436 writeb (0, addr + EN0_RSARLO);
437 writeb (ring_page, addr + EN0_RSARHI);
438 writeb (E8390_RREAD | E8390_START, addr + E8390_CMD);
439
440 if (ei_local->word16)
441 readsw (dma_base, hdr, sizeof (*hdr) >> 1);
442 else
443 readsb (dma_base, hdr, sizeof (*hdr));
444
445 writeb (ENISR_RDC, addr + EN0_ISR);
446 ei_local->dmaing = 0;
447}
448
449/*
450 * Open/initialize the board. This is called (in the current kernel)
451 * sometime after booting when the 'ifconfig' program is run.
452 *
453 * This routine should set everything up anew at each open, even
454 * registers that "should" only need to be set once at boot, so that
455 * there is non-reboot way to recover if something goes wrong.
456 */
457static int
458etherh_open(struct net_device *dev)
459{
460 struct ei_device *ei_local = netdev_priv(dev);
461
462 if (request_irq(dev->irq, __ei_interrupt, 0, dev->name, dev))
463 return -EAGAIN;
464
465 /*
466 * Make sure that we aren't going to change the
467 * media type on the next reset - we are about to
468 * do automedia manually now.
469 */
470 ei_local->interface_num = 0;
471
472 /*
473 * If we are doing automedia detection, do it now.
474 * This is more reliable than the 8390's detection.
475 */
476 if (dev->flags & IFF_AUTOMEDIA) {
477 dev->if_port = IF_PORT_10BASET;
478 etherh_setif(dev);
479 mdelay(1);
480 if (!etherh_getifstat(dev)) {
481 dev->if_port = IF_PORT_10BASE2;
482 etherh_setif(dev);
483 }
484 } else
485 etherh_setif(dev);
486
487 etherh_reset(dev);
488 __ei_open(dev);
489
490 return 0;
491}
492
493/*
494 * The inverse routine to etherh_open().
495 */
496static int
497etherh_close(struct net_device *dev)
498{
499 __ei_close (dev);
500 free_irq (dev->irq, dev);
501 return 0;
502}
503
504/*
505 * Initialisation
506 */
507
508static void __init etherh_banner(void)
509{
510 static int version_printed;
511
512 if ((etherh_msg_enable & NETIF_MSG_DRV) && (version_printed++ == 0))
513 pr_info("%s", version);
514}
515
516/*
517 * Read the ethernet address string from the on board rom.
518 * This is an ascii string...
519 */
520static int etherh_addr(char *addr, struct expansion_card *ec)
521{
522 struct in_chunk_dir cd;
523 char *s;
524
525 if (!ecard_readchunk(&cd, ec, 0xf5, 0)) {
526 printk(KERN_ERR "%s: unable to read podule description string\n",
527 dev_name(&ec->dev));
528 goto no_addr;
529 }
530
531 s = strchr(cd.d.string, '(');
532 if (s) {
533 int i;
534
535 for (i = 0; i < 6; i++) {
536 addr[i] = simple_strtoul(s + 1, &s, 0x10);
537 if (*s != (i == 5? ')' : ':'))
538 break;
539 }
540
541 if (i == 6)
542 return 0;
543 }
544
545 printk(KERN_ERR "%s: unable to parse MAC address: %s\n",
546 dev_name(&ec->dev), cd.d.string);
547
548 no_addr:
549 return -ENODEV;
550}
551
552/*
553 * Create an ethernet address from the system serial number.
554 */
555static int __init etherm_addr(char *addr)
556{
557 unsigned int serial;
558
559 if (system_serial_low == 0 && system_serial_high == 0)
560 return -ENODEV;
561
562 serial = system_serial_low | system_serial_high;
563
564 addr[0] = 0;
565 addr[1] = 0;
566 addr[2] = 0xa4;
567 addr[3] = 0x10 + (serial >> 24);
568 addr[4] = serial >> 16;
569 addr[5] = serial >> 8;
570 return 0;
571}
572
573static void etherh_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
574{
575 strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
576 strlcpy(info->version, DRV_VERSION, sizeof(info->version));
577 strlcpy(info->bus_info, dev_name(dev->dev.parent),
578 sizeof(info->bus_info));
579}
580
581static int etherh_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
582{
583 cmd->supported = etherh_priv(dev)->supported;
584 ethtool_cmd_speed_set(cmd, SPEED_10);
585 cmd->duplex = DUPLEX_HALF;
586 cmd->port = dev->if_port == IF_PORT_10BASET ? PORT_TP : PORT_BNC;
587 cmd->autoneg = (dev->flags & IFF_AUTOMEDIA ?
588 AUTONEG_ENABLE : AUTONEG_DISABLE);
589 return 0;
590}
591
592static int etherh_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
593{
594 switch (cmd->autoneg) {
595 case AUTONEG_ENABLE:
596 dev->flags |= IFF_AUTOMEDIA;
597 break;
598
599 case AUTONEG_DISABLE:
600 switch (cmd->port) {
601 case PORT_TP:
602 dev->if_port = IF_PORT_10BASET;
603 break;
604
605 case PORT_BNC:
606 dev->if_port = IF_PORT_10BASE2;
607 break;
608
609 default:
610 return -EINVAL;
611 }
612 dev->flags &= ~IFF_AUTOMEDIA;
613 break;
614
615 default:
616 return -EINVAL;
617 }
618
619 etherh_setif(dev);
620
621 return 0;
622}
623
624static u32 etherh_get_msglevel(struct net_device *dev)
625{
626 struct ei_device *ei_local = netdev_priv(dev);
627
628 return ei_local->msg_enable;
629}
630
631static void etherh_set_msglevel(struct net_device *dev, u32 v)
632{
633 struct ei_device *ei_local = netdev_priv(dev);
634
635 ei_local->msg_enable = v;
636}
637
638static const struct ethtool_ops etherh_ethtool_ops = {
639 .get_settings = etherh_get_settings,
640 .set_settings = etherh_set_settings,
641 .get_drvinfo = etherh_get_drvinfo,
642 .get_ts_info = ethtool_op_get_ts_info,
643 .get_msglevel = etherh_get_msglevel,
644 .set_msglevel = etherh_set_msglevel,
645};
646
647static const struct net_device_ops etherh_netdev_ops = {
648 .ndo_open = etherh_open,
649 .ndo_stop = etherh_close,
650 .ndo_set_config = etherh_set_config,
651 .ndo_start_xmit = __ei_start_xmit,
652 .ndo_tx_timeout = __ei_tx_timeout,
653 .ndo_get_stats = __ei_get_stats,
654 .ndo_set_rx_mode = __ei_set_multicast_list,
655 .ndo_validate_addr = eth_validate_addr,
656 .ndo_set_mac_address = eth_mac_addr,
657 .ndo_change_mtu = eth_change_mtu,
658#ifdef CONFIG_NET_POLL_CONTROLLER
659 .ndo_poll_controller = __ei_poll,
660#endif
661};
662
663static u32 etherh_regoffsets[16];
664static u32 etherm_regoffsets[16];
665
666static int
667etherh_probe(struct expansion_card *ec, const struct ecard_id *id)
668{
669 const struct etherh_data *data = id->data;
670 struct ei_device *ei_local;
671 struct net_device *dev;
672 struct etherh_priv *eh;
673 int ret;
674
675 etherh_banner();
676
677 ret = ecard_request_resources(ec);
678 if (ret)
679 goto out;
680
681 dev = ____alloc_ei_netdev(sizeof(struct etherh_priv));
682 if (!dev) {
683 ret = -ENOMEM;
684 goto release;
685 }
686
687 SET_NETDEV_DEV(dev, &ec->dev);
688
689 dev->netdev_ops = ðerh_netdev_ops;
690 dev->irq = ec->irq;
691 dev->ethtool_ops = ðerh_ethtool_ops;
692
693 if (data->supported & SUPPORTED_Autoneg)
694 dev->flags |= IFF_AUTOMEDIA;
695 if (data->supported & SUPPORTED_TP) {
696 dev->flags |= IFF_PORTSEL;
697 dev->if_port = IF_PORT_10BASET;
698 } else if (data->supported & SUPPORTED_BNC) {
699 dev->flags |= IFF_PORTSEL;
700 dev->if_port = IF_PORT_10BASE2;
701 } else
702 dev->if_port = IF_PORT_UNKNOWN;
703
704 eh = etherh_priv(dev);
705 eh->supported = data->supported;
706 eh->ctrl = 0;
707 eh->id = ec->cid.product;
708 eh->memc = ecardm_iomap(ec, ECARD_RES_MEMC, 0, PAGE_SIZE);
709 if (!eh->memc) {
710 ret = -ENOMEM;
711 goto free;
712 }
713
714 eh->ctrl_port = eh->memc;
715 if (data->ctrl_ioc) {
716 eh->ioc_fast = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, PAGE_SIZE);
717 if (!eh->ioc_fast) {
718 ret = -ENOMEM;
719 goto free;
720 }
721 eh->ctrl_port = eh->ioc_fast;
722 }
723
724 dev->base_addr = (unsigned long)eh->memc + data->ns8390_offset;
725 eh->dma_base = eh->memc + data->dataport_offset;
726 eh->ctrl_port += data->ctrlport_offset;
727
728 /*
729 * IRQ and control port handling - only for non-NIC slot cards.
730 */
731 if (ec->slot_no != 8) {
732 ecard_setirq(ec, ðerh_ops, eh);
733 } else {
734 /*
735 * If we're in the NIC slot, make sure the IRQ is enabled
736 */
737 etherh_set_ctrl(eh, ETHERH_CP_IE);
738 }
739
740 ei_local = netdev_priv(dev);
741 spin_lock_init(&ei_local->page_lock);
742
743 if (ec->cid.product == PROD_ANT_ETHERM) {
744 etherm_addr(dev->dev_addr);
745 ei_local->reg_offset = etherm_regoffsets;
746 } else {
747 etherh_addr(dev->dev_addr, ec);
748 ei_local->reg_offset = etherh_regoffsets;
749 }
750
751 ei_local->name = dev->name;
752 ei_local->word16 = 1;
753 ei_local->tx_start_page = data->tx_start_page;
754 ei_local->rx_start_page = ei_local->tx_start_page + TX_PAGES;
755 ei_local->stop_page = data->stop_page;
756 ei_local->reset_8390 = etherh_reset;
757 ei_local->block_input = etherh_block_input;
758 ei_local->block_output = etherh_block_output;
759 ei_local->get_8390_hdr = etherh_get_header;
760 ei_local->interface_num = 0;
761 ei_local->msg_enable = etherh_msg_enable;
762
763 etherh_reset(dev);
764 __NS8390_init(dev, 0);
765
766 ret = register_netdev(dev);
767 if (ret)
768 goto free;
769
770 netdev_info(dev, "%s in slot %d, %pM\n",
771 data->name, ec->slot_no, dev->dev_addr);
772
773 ecard_set_drvdata(ec, dev);
774
775 return 0;
776
777 free:
778 free_netdev(dev);
779 release:
780 ecard_release_resources(ec);
781 out:
782 return ret;
783}
784
785static void etherh_remove(struct expansion_card *ec)
786{
787 struct net_device *dev = ecard_get_drvdata(ec);
788
789 ecard_set_drvdata(ec, NULL);
790
791 unregister_netdev(dev);
792
793 free_netdev(dev);
794
795 ecard_release_resources(ec);
796}
797
798static struct etherh_data etherm_data = {
799 .ns8390_offset = ETHERM_NS8390,
800 .dataport_offset = ETHERM_NS8390 + ETHERM_DATAPORT,
801 .ctrlport_offset = ETHERM_NS8390 + ETHERM_CTRLPORT,
802 .name = "ANT EtherM",
803 .supported = SUPPORTED_10baseT_Half,
804 .tx_start_page = ETHERM_TX_START_PAGE,
805 .stop_page = ETHERM_STOP_PAGE,
806};
807
808static struct etherh_data etherlan500_data = {
809 .ns8390_offset = ETHERH500_NS8390,
810 .dataport_offset = ETHERH500_NS8390 + ETHERH500_DATAPORT,
811 .ctrlport_offset = ETHERH500_CTRLPORT,
812 .ctrl_ioc = 1,
813 .name = "i3 EtherH 500",
814 .supported = SUPPORTED_10baseT_Half,
815 .tx_start_page = ETHERH_TX_START_PAGE,
816 .stop_page = ETHERH_STOP_PAGE,
817};
818
819static struct etherh_data etherlan600_data = {
820 .ns8390_offset = ETHERH600_NS8390,
821 .dataport_offset = ETHERH600_NS8390 + ETHERH600_DATAPORT,
822 .ctrlport_offset = ETHERH600_NS8390 + ETHERH600_CTRLPORT,
823 .name = "i3 EtherH 600",
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
829static struct etherh_data etherlan600a_data = {
830 .ns8390_offset = ETHERH600_NS8390,
831 .dataport_offset = ETHERH600_NS8390 + ETHERH600_DATAPORT,
832 .ctrlport_offset = ETHERH600_NS8390 + ETHERH600_CTRLPORT,
833 .name = "i3 EtherH 600A",
834 .supported = SUPPORTED_10baseT_Half | SUPPORTED_TP | SUPPORTED_BNC | SUPPORTED_Autoneg,
835 .tx_start_page = ETHERH_TX_START_PAGE,
836 .stop_page = ETHERH_STOP_PAGE,
837};
838
839static const struct ecard_id etherh_ids[] = {
840 { MANU_ANT, PROD_ANT_ETHERM, ðerm_data },
841 { MANU_I3, PROD_I3_ETHERLAN500, ðerlan500_data },
842 { MANU_I3, PROD_I3_ETHERLAN600, ðerlan600_data },
843 { MANU_I3, PROD_I3_ETHERLAN600A, ðerlan600a_data },
844 { 0xffff, 0xffff }
845};
846
847static struct ecard_driver etherh_driver = {
848 .probe = etherh_probe,
849 .remove = etherh_remove,
850 .id_table = etherh_ids,
851 .drv = {
852 .name = DRV_NAME,
853 },
854};
855
856static int __init etherh_init(void)
857{
858 int i;
859
860 for (i = 0; i < 16; i++) {
861 etherh_regoffsets[i] = i << 2;
862 etherm_regoffsets[i] = i << 5;
863 }
864
865 return ecard_register_driver(ðerh_driver);
866}
867
868static void __exit etherh_exit(void)
869{
870 ecard_remove_driver(ðerh_driver);
871}
872
873module_init(etherh_init);
874module_exit(etherh_exit);
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
65static char version[] __initdata =
66 "EtherH/EtherM Driver (c) 2002-2004 Russell King " DRV_VERSION "\n";
67
68#include "lib8390.c"
69
70static unsigned int net_debug = NET_DEBUG;
71
72struct 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
82struct 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
93MODULE_AUTHOR("Russell King");
94MODULE_DESCRIPTION("EtherH/EtherM driver");
95MODULE_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
127static 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
134static 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
141static inline unsigned int etherh_get_stat(struct etherh_priv *eh)
142{
143 return readb(eh->ctrl_port);
144}
145
146
147
148
149static 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
156static 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
163static expansioncard_ops_t etherh_ops = {
164 .irqenable = etherh_irq_enable,
165 .irqdisable = etherh_irq_disable,
166};
167
168
169
170
171static void
172etherh_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
215static int
216etherh_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 */
259static 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 */
284static void
285etherh_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 */
312static void
313etherh_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 */
378static void
379etherh_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 */
419static void
420etherh_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 */
461static int
462etherh_open(struct net_device *dev)
463{
464 struct ei_device *ei_local = netdev_priv(dev);
465
466 if (!is_valid_ether_addr(dev->dev_addr)) {
467 printk(KERN_WARNING "%s: invalid ethernet MAC address\n",
468 dev->name);
469 return -EINVAL;
470 }
471
472 if (request_irq(dev->irq, __ei_interrupt, 0, dev->name, dev))
473 return -EAGAIN;
474
475 /*
476 * Make sure that we aren't going to change the
477 * media type on the next reset - we are about to
478 * do automedia manually now.
479 */
480 ei_local->interface_num = 0;
481
482 /*
483 * If we are doing automedia detection, do it now.
484 * This is more reliable than the 8390's detection.
485 */
486 if (dev->flags & IFF_AUTOMEDIA) {
487 dev->if_port = IF_PORT_10BASET;
488 etherh_setif(dev);
489 mdelay(1);
490 if (!etherh_getifstat(dev)) {
491 dev->if_port = IF_PORT_10BASE2;
492 etherh_setif(dev);
493 }
494 } else
495 etherh_setif(dev);
496
497 etherh_reset(dev);
498 __ei_open(dev);
499
500 return 0;
501}
502
503/*
504 * The inverse routine to etherh_open().
505 */
506static int
507etherh_close(struct net_device *dev)
508{
509 __ei_close (dev);
510 free_irq (dev->irq, dev);
511 return 0;
512}
513
514/*
515 * Initialisation
516 */
517
518static void __init etherh_banner(void)
519{
520 static int version_printed;
521
522 if (net_debug && version_printed++ == 0)
523 printk(KERN_INFO "%s", version);
524}
525
526/*
527 * Read the ethernet address string from the on board rom.
528 * This is an ascii string...
529 */
530static int __devinit etherh_addr(char *addr, struct expansion_card *ec)
531{
532 struct in_chunk_dir cd;
533 char *s;
534
535 if (!ecard_readchunk(&cd, ec, 0xf5, 0)) {
536 printk(KERN_ERR "%s: unable to read podule description string\n",
537 dev_name(&ec->dev));
538 goto no_addr;
539 }
540
541 s = strchr(cd.d.string, '(');
542 if (s) {
543 int i;
544
545 for (i = 0; i < 6; i++) {
546 addr[i] = simple_strtoul(s + 1, &s, 0x10);
547 if (*s != (i == 5? ')' : ':'))
548 break;
549 }
550
551 if (i == 6)
552 return 0;
553 }
554
555 printk(KERN_ERR "%s: unable to parse MAC address: %s\n",
556 dev_name(&ec->dev), cd.d.string);
557
558 no_addr:
559 return -ENODEV;
560}
561
562/*
563 * Create an ethernet address from the system serial number.
564 */
565static int __init etherm_addr(char *addr)
566{
567 unsigned int serial;
568
569 if (system_serial_low == 0 && system_serial_high == 0)
570 return -ENODEV;
571
572 serial = system_serial_low | system_serial_high;
573
574 addr[0] = 0;
575 addr[1] = 0;
576 addr[2] = 0xa4;
577 addr[3] = 0x10 + (serial >> 24);
578 addr[4] = serial >> 16;
579 addr[5] = serial >> 8;
580 return 0;
581}
582
583static void etherh_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
584{
585 strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
586 strlcpy(info->version, DRV_VERSION, sizeof(info->version));
587 strlcpy(info->bus_info, dev_name(dev->dev.parent),
588 sizeof(info->bus_info));
589}
590
591static int etherh_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
592{
593 cmd->supported = etherh_priv(dev)->supported;
594 ethtool_cmd_speed_set(cmd, SPEED_10);
595 cmd->duplex = DUPLEX_HALF;
596 cmd->port = dev->if_port == IF_PORT_10BASET ? PORT_TP : PORT_BNC;
597 cmd->autoneg = (dev->flags & IFF_AUTOMEDIA ?
598 AUTONEG_ENABLE : AUTONEG_DISABLE);
599 return 0;
600}
601
602static int etherh_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
603{
604 switch (cmd->autoneg) {
605 case AUTONEG_ENABLE:
606 dev->flags |= IFF_AUTOMEDIA;
607 break;
608
609 case AUTONEG_DISABLE:
610 switch (cmd->port) {
611 case PORT_TP:
612 dev->if_port = IF_PORT_10BASET;
613 break;
614
615 case PORT_BNC:
616 dev->if_port = IF_PORT_10BASE2;
617 break;
618
619 default:
620 return -EINVAL;
621 }
622 dev->flags &= ~IFF_AUTOMEDIA;
623 break;
624
625 default:
626 return -EINVAL;
627 }
628
629 etherh_setif(dev);
630
631 return 0;
632}
633
634static const struct ethtool_ops etherh_ethtool_ops = {
635 .get_settings = etherh_get_settings,
636 .set_settings = etherh_set_settings,
637 .get_drvinfo = etherh_get_drvinfo,
638 .get_ts_info = ethtool_op_get_ts_info,
639};
640
641static const struct net_device_ops etherh_netdev_ops = {
642 .ndo_open = etherh_open,
643 .ndo_stop = etherh_close,
644 .ndo_set_config = etherh_set_config,
645 .ndo_start_xmit = __ei_start_xmit,
646 .ndo_tx_timeout = __ei_tx_timeout,
647 .ndo_get_stats = __ei_get_stats,
648 .ndo_set_rx_mode = __ei_set_multicast_list,
649 .ndo_validate_addr = eth_validate_addr,
650 .ndo_set_mac_address = eth_mac_addr,
651 .ndo_change_mtu = eth_change_mtu,
652#ifdef CONFIG_NET_POLL_CONTROLLER
653 .ndo_poll_controller = __ei_poll,
654#endif
655};
656
657static u32 etherh_regoffsets[16];
658static u32 etherm_regoffsets[16];
659
660static int __devinit
661etherh_probe(struct expansion_card *ec, const struct ecard_id *id)
662{
663 const struct etherh_data *data = id->data;
664 struct ei_device *ei_local;
665 struct net_device *dev;
666 struct etherh_priv *eh;
667 int ret;
668
669 etherh_banner();
670
671 ret = ecard_request_resources(ec);
672 if (ret)
673 goto out;
674
675 dev = ____alloc_ei_netdev(sizeof(struct etherh_priv));
676 if (!dev) {
677 ret = -ENOMEM;
678 goto release;
679 }
680
681 SET_NETDEV_DEV(dev, &ec->dev);
682
683 dev->netdev_ops = ðerh_netdev_ops;
684 dev->irq = ec->irq;
685 dev->ethtool_ops = ðerh_ethtool_ops;
686
687 if (data->supported & SUPPORTED_Autoneg)
688 dev->flags |= IFF_AUTOMEDIA;
689 if (data->supported & SUPPORTED_TP) {
690 dev->flags |= IFF_PORTSEL;
691 dev->if_port = IF_PORT_10BASET;
692 } else if (data->supported & SUPPORTED_BNC) {
693 dev->flags |= IFF_PORTSEL;
694 dev->if_port = IF_PORT_10BASE2;
695 } else
696 dev->if_port = IF_PORT_UNKNOWN;
697
698 eh = etherh_priv(dev);
699 eh->supported = data->supported;
700 eh->ctrl = 0;
701 eh->id = ec->cid.product;
702 eh->memc = ecardm_iomap(ec, ECARD_RES_MEMC, 0, PAGE_SIZE);
703 if (!eh->memc) {
704 ret = -ENOMEM;
705 goto free;
706 }
707
708 eh->ctrl_port = eh->memc;
709 if (data->ctrl_ioc) {
710 eh->ioc_fast = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, PAGE_SIZE);
711 if (!eh->ioc_fast) {
712 ret = -ENOMEM;
713 goto free;
714 }
715 eh->ctrl_port = eh->ioc_fast;
716 }
717
718 dev->base_addr = (unsigned long)eh->memc + data->ns8390_offset;
719 eh->dma_base = eh->memc + data->dataport_offset;
720 eh->ctrl_port += data->ctrlport_offset;
721
722 /*
723 * IRQ and control port handling - only for non-NIC slot cards.
724 */
725 if (ec->slot_no != 8) {
726 ecard_setirq(ec, ðerh_ops, eh);
727 } else {
728 /*
729 * If we're in the NIC slot, make sure the IRQ is enabled
730 */
731 etherh_set_ctrl(eh, ETHERH_CP_IE);
732 }
733
734 ei_local = netdev_priv(dev);
735 spin_lock_init(&ei_local->page_lock);
736
737 if (ec->cid.product == PROD_ANT_ETHERM) {
738 etherm_addr(dev->dev_addr);
739 ei_local->reg_offset = etherm_regoffsets;
740 } else {
741 etherh_addr(dev->dev_addr, ec);
742 ei_local->reg_offset = etherh_regoffsets;
743 }
744
745 ei_local->name = dev->name;
746 ei_local->word16 = 1;
747 ei_local->tx_start_page = data->tx_start_page;
748 ei_local->rx_start_page = ei_local->tx_start_page + TX_PAGES;
749 ei_local->stop_page = data->stop_page;
750 ei_local->reset_8390 = etherh_reset;
751 ei_local->block_input = etherh_block_input;
752 ei_local->block_output = etherh_block_output;
753 ei_local->get_8390_hdr = etherh_get_header;
754 ei_local->interface_num = 0;
755
756 etherh_reset(dev);
757 __NS8390_init(dev, 0);
758
759 ret = register_netdev(dev);
760 if (ret)
761 goto free;
762
763 printk(KERN_INFO "%s: %s in slot %d, %pM\n",
764 dev->name, data->name, ec->slot_no, dev->dev_addr);
765
766 ecard_set_drvdata(ec, dev);
767
768 return 0;
769
770 free:
771 free_netdev(dev);
772 release:
773 ecard_release_resources(ec);
774 out:
775 return ret;
776}
777
778static void __devexit etherh_remove(struct expansion_card *ec)
779{
780 struct net_device *dev = ecard_get_drvdata(ec);
781
782 ecard_set_drvdata(ec, NULL);
783
784 unregister_netdev(dev);
785
786 free_netdev(dev);
787
788 ecard_release_resources(ec);
789}
790
791static struct etherh_data etherm_data = {
792 .ns8390_offset = ETHERM_NS8390,
793 .dataport_offset = ETHERM_NS8390 + ETHERM_DATAPORT,
794 .ctrlport_offset = ETHERM_NS8390 + ETHERM_CTRLPORT,
795 .name = "ANT EtherM",
796 .supported = SUPPORTED_10baseT_Half,
797 .tx_start_page = ETHERM_TX_START_PAGE,
798 .stop_page = ETHERM_STOP_PAGE,
799};
800
801static struct etherh_data etherlan500_data = {
802 .ns8390_offset = ETHERH500_NS8390,
803 .dataport_offset = ETHERH500_NS8390 + ETHERH500_DATAPORT,
804 .ctrlport_offset = ETHERH500_CTRLPORT,
805 .ctrl_ioc = 1,
806 .name = "i3 EtherH 500",
807 .supported = SUPPORTED_10baseT_Half,
808 .tx_start_page = ETHERH_TX_START_PAGE,
809 .stop_page = ETHERH_STOP_PAGE,
810};
811
812static struct etherh_data etherlan600_data = {
813 .ns8390_offset = ETHERH600_NS8390,
814 .dataport_offset = ETHERH600_NS8390 + ETHERH600_DATAPORT,
815 .ctrlport_offset = ETHERH600_NS8390 + ETHERH600_CTRLPORT,
816 .name = "i3 EtherH 600",
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 struct etherh_data etherlan600a_data = {
823 .ns8390_offset = ETHERH600_NS8390,
824 .dataport_offset = ETHERH600_NS8390 + ETHERH600_DATAPORT,
825 .ctrlport_offset = ETHERH600_NS8390 + ETHERH600_CTRLPORT,
826 .name = "i3 EtherH 600A",
827 .supported = SUPPORTED_10baseT_Half | SUPPORTED_TP | SUPPORTED_BNC | SUPPORTED_Autoneg,
828 .tx_start_page = ETHERH_TX_START_PAGE,
829 .stop_page = ETHERH_STOP_PAGE,
830};
831
832static const struct ecard_id etherh_ids[] = {
833 { MANU_ANT, PROD_ANT_ETHERM, ðerm_data },
834 { MANU_I3, PROD_I3_ETHERLAN500, ðerlan500_data },
835 { MANU_I3, PROD_I3_ETHERLAN600, ðerlan600_data },
836 { MANU_I3, PROD_I3_ETHERLAN600A, ðerlan600a_data },
837 { 0xffff, 0xffff }
838};
839
840static struct ecard_driver etherh_driver = {
841 .probe = etherh_probe,
842 .remove = __devexit_p(etherh_remove),
843 .id_table = etherh_ids,
844 .drv = {
845 .name = DRV_NAME,
846 },
847};
848
849static int __init etherh_init(void)
850{
851 int i;
852
853 for (i = 0; i < 16; i++) {
854 etherh_regoffsets[i] = i << 2;
855 etherm_regoffsets[i] = i << 5;
856 }
857
858 return ecard_register_driver(ðerh_driver);
859}
860
861static void __exit etherh_exit(void)
862{
863 ecard_remove_driver(ðerh_driver);
864}
865
866module_init(etherh_init);
867module_exit(etherh_exit);