blob: 77191a281866e262328b4a5fe5fb4af0fa63dfbb [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <linux/ioport.h>
35#include <linux/in.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#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>
Marcelo Feitoza Parisiff5688a2006-01-09 18:37:15 -080046#include <linux/jiffies.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#include <asm/ecard.h>
49#include <asm/io.h>
David Howells9f97da72012-03-28 18:30:01 +010050#include <asm/system_info.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Al Viro6c3561b2006-10-10 00:19:36 +010052#define EI_SHIFT(x) (ei_local->reg_offset[x])
53
Al Virob9368892006-10-10 00:19:36 +010054#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)
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
Linus Torvalds1da177e2005-04-16 15:20:36 -070059#define DRV_NAME "etherh"
60#define DRV_VERSION "1.11"
61
Olof Johansson335802d2013-12-12 00:39:37 -080062static char version[] =
Al Viro6c3561b2006-10-10 00:19:36 +010063 "EtherH/EtherM Driver (c) 2002-2004 Russell King " DRV_VERSION "\n";
64
Jeff Kirsher644570b2011-04-02 06:20:12 -070065#include "lib8390.c"
Al Viro6c3561b2006-10-10 00:19:36 +010066
Linus Torvalds1da177e2005-04-16 15:20:36 -070067struct etherh_priv {
68 void __iomem *ioc_fast;
69 void __iomem *memc;
70 void __iomem *dma_base;
71 unsigned int id;
72 void __iomem *ctrl_port;
73 unsigned char ctrl;
74 u32 supported;
75};
76
77struct etherh_data {
78 unsigned long ns8390_offset;
79 unsigned long dataport_offset;
80 unsigned long ctrlport_offset;
81 int ctrl_ioc;
82 const char name[16];
83 u32 supported;
84 unsigned char tx_start_page;
85 unsigned char stop_page;
86};
87
88MODULE_AUTHOR("Russell King");
89MODULE_DESCRIPTION("EtherH/EtherM driver");
90MODULE_LICENSE("GPL");
91
Linus Torvalds1da177e2005-04-16 15:20:36 -070092#define ETHERH500_DATAPORT 0x800 /* MEMC */
93#define ETHERH500_NS8390 0x000 /* MEMC */
94#define ETHERH500_CTRLPORT 0x800 /* IOC */
95
96#define ETHERH600_DATAPORT 0x040 /* MEMC */
97#define ETHERH600_NS8390 0x800 /* MEMC */
98#define ETHERH600_CTRLPORT 0x200 /* MEMC */
99
100#define ETHERH_CP_IE 1
101#define ETHERH_CP_IF 2
102#define ETHERH_CP_HEARTBEAT 2
103
104#define ETHERH_TX_START_PAGE 1
105#define ETHERH_STOP_PAGE 127
106
107/*
108 * These came from CK/TEW
109 */
110#define ETHERM_DATAPORT 0x200 /* MEMC */
111#define ETHERM_NS8390 0x800 /* MEMC */
112#define ETHERM_CTRLPORT 0x23c /* MEMC */
113
114#define ETHERM_TX_START_PAGE 64
115#define ETHERM_STOP_PAGE 127
116
117/* ------------------------------------------------------------------------ */
118
119#define etherh_priv(dev) \
120 ((struct etherh_priv *)(((char *)netdev_priv(dev)) + sizeof(struct ei_device)))
121
122static inline void etherh_set_ctrl(struct etherh_priv *eh, unsigned char mask)
123{
124 unsigned char ctrl = eh->ctrl | mask;
125 eh->ctrl = ctrl;
126 writeb(ctrl, eh->ctrl_port);
127}
128
129static inline void etherh_clr_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 unsigned int etherh_get_stat(struct etherh_priv *eh)
137{
138 return readb(eh->ctrl_port);
139}
140
141
142
143
144static void etherh_irq_enable(ecard_t *ec, int irqnr)
145{
146 struct etherh_priv *eh = ec->irq_data;
147
148 etherh_set_ctrl(eh, ETHERH_CP_IE);
149}
150
151static void etherh_irq_disable(ecard_t *ec, int irqnr)
152{
153 struct etherh_priv *eh = ec->irq_data;
154
155 etherh_clr_ctrl(eh, ETHERH_CP_IE);
156}
157
158static expansioncard_ops_t etherh_ops = {
159 .irqenable = etherh_irq_enable,
160 .irqdisable = etherh_irq_disable,
161};
162
163
164
165
166static void
167etherh_setif(struct net_device *dev)
168{
169 struct ei_device *ei_local = netdev_priv(dev);
170 unsigned long flags;
171 void __iomem *addr;
172
173 local_irq_save(flags);
174
175 /* set the interface type */
176 switch (etherh_priv(dev)->id) {
177 case PROD_I3_ETHERLAN600:
178 case PROD_I3_ETHERLAN600A:
Al Virob9368892006-10-10 00:19:36 +0100179 addr = (void __iomem *)dev->base_addr + EN0_RCNTHI;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
181 switch (dev->if_port) {
182 case IF_PORT_10BASE2:
183 writeb((readb(addr) & 0xf8) | 1, addr);
184 break;
185 case IF_PORT_10BASET:
186 writeb((readb(addr) & 0xf8), addr);
187 break;
188 }
189 break;
190
191 case PROD_I3_ETHERLAN500:
192 switch (dev->if_port) {
193 case IF_PORT_10BASE2:
194 etherh_clr_ctrl(etherh_priv(dev), ETHERH_CP_IF);
195 break;
196
197 case IF_PORT_10BASET:
198 etherh_set_ctrl(etherh_priv(dev), ETHERH_CP_IF);
199 break;
200 }
201 break;
202
203 default:
204 break;
205 }
206
207 local_irq_restore(flags);
208}
209
210static int
211etherh_getifstat(struct net_device *dev)
212{
213 struct ei_device *ei_local = netdev_priv(dev);
214 void __iomem *addr;
215 int stat = 0;
216
217 switch (etherh_priv(dev)->id) {
218 case PROD_I3_ETHERLAN600:
219 case PROD_I3_ETHERLAN600A:
Al Virob9368892006-10-10 00:19:36 +0100220 addr = (void __iomem *)dev->base_addr + EN0_RCNTHI;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 switch (dev->if_port) {
222 case IF_PORT_10BASE2:
223 stat = 1;
224 break;
225 case IF_PORT_10BASET:
226 stat = readb(addr) & 4;
227 break;
228 }
229 break;
230
231 case PROD_I3_ETHERLAN500:
232 switch (dev->if_port) {
233 case IF_PORT_10BASE2:
234 stat = 1;
235 break;
236 case IF_PORT_10BASET:
237 stat = etherh_get_stat(etherh_priv(dev)) & ETHERH_CP_HEARTBEAT;
238 break;
239 }
240 break;
241
242 default:
243 stat = 0;
244 break;
245 }
246
247 return stat != 0;
248}
249
250/*
251 * Configure the interface. Note that we ignore the other
252 * parts of ifmap, since its mostly meaningless for this driver.
253 */
254static int etherh_set_config(struct net_device *dev, struct ifmap *map)
255{
256 switch (map->port) {
257 case IF_PORT_10BASE2:
258 case IF_PORT_10BASET:
259 /*
260 * If the user explicitly sets the interface
261 * media type, turn off automedia detection.
262 */
263 dev->flags &= ~IFF_AUTOMEDIA;
264 dev->if_port = map->port;
265 break;
266
267 default:
268 return -EINVAL;
269 }
270
271 etherh_setif(dev);
272
273 return 0;
274}
275
276/*
277 * Reset the 8390 (hard reset). Note that we can't actually do this.
278 */
279static void
280etherh_reset(struct net_device *dev)
281{
282 struct ei_device *ei_local = netdev_priv(dev);
Al Virob9368892006-10-10 00:19:36 +0100283 void __iomem *addr = (void __iomem *)dev->base_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
285 writeb(E8390_NODMA+E8390_PAGE0+E8390_STOP, addr);
286
287 /*
288 * See if we need to change the interface type.
289 * Note that we use 'interface_num' as a flag
290 * to indicate that we need to change the media.
291 */
292 if (dev->flags & IFF_AUTOMEDIA && ei_local->interface_num) {
293 ei_local->interface_num = 0;
294
295 if (dev->if_port == IF_PORT_10BASET)
296 dev->if_port = IF_PORT_10BASE2;
297 else
298 dev->if_port = IF_PORT_10BASET;
299
300 etherh_setif(dev);
301 }
302}
303
304/*
305 * Write a block of data out to the 8390
306 */
307static void
308etherh_block_output (struct net_device *dev, int count, const unsigned char *buf, int start_page)
309{
310 struct ei_device *ei_local = netdev_priv(dev);
311 unsigned long dma_start;
312 void __iomem *dma_base, *addr;
313
314 if (ei_local->dmaing) {
Matthew Whiteheadc45f8122013-12-11 17:00:59 -0500315 netdev_err(dev, "DMAing conflict in etherh_block_input: "
316 " DMAstat %d irqlock %d\n",
317 ei_local->dmaing, ei_local->irqlock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 return;
319 }
320
321 /*
322 * Make sure we have a round number of bytes if we're in word mode.
323 */
324 if (count & 1 && ei_local->word16)
325 count++;
326
327 ei_local->dmaing = 1;
328
Al Virob9368892006-10-10 00:19:36 +0100329 addr = (void __iomem *)dev->base_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 dma_base = etherh_priv(dev)->dma_base;
331
332 count = (count + 1) & ~1;
333 writeb (E8390_NODMA | E8390_PAGE0 | E8390_START, addr + E8390_CMD);
334
335 writeb (0x42, addr + EN0_RCNTLO);
336 writeb (0x00, addr + EN0_RCNTHI);
337 writeb (0x42, addr + EN0_RSARLO);
338 writeb (0x00, addr + EN0_RSARHI);
339 writeb (E8390_RREAD | E8390_START, addr + E8390_CMD);
340
341 udelay (1);
342
343 writeb (ENISR_RDC, addr + EN0_ISR);
344 writeb (count, addr + EN0_RCNTLO);
345 writeb (count >> 8, addr + EN0_RCNTHI);
346 writeb (0, addr + EN0_RSARLO);
347 writeb (start_page, addr + EN0_RSARHI);
348 writeb (E8390_RWRITE | E8390_START, addr + E8390_CMD);
349
350 if (ei_local->word16)
351 writesw (dma_base, buf, count >> 1);
352 else
353 writesb (dma_base, buf, count);
354
355 dma_start = jiffies;
356
357 while ((readb (addr + EN0_ISR) & ENISR_RDC) == 0)
Marcelo Feitoza Parisiff5688a2006-01-09 18:37:15 -0800358 if (time_after(jiffies, dma_start + 2*HZ/100)) { /* 20ms */
Matthew Whiteheadc45f8122013-12-11 17:00:59 -0500359 netdev_warn(dev, "timeout waiting for TX RDC\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 etherh_reset (dev);
Al Viro6c3561b2006-10-10 00:19:36 +0100361 __NS8390_init (dev, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 break;
363 }
364
365 writeb (ENISR_RDC, addr + EN0_ISR);
366 ei_local->dmaing = 0;
367}
368
369/*
370 * Read a block of data from the 8390
371 */
372static void
373etherh_block_input (struct net_device *dev, int count, struct sk_buff *skb, int ring_offset)
374{
375 struct ei_device *ei_local = netdev_priv(dev);
376 unsigned char *buf;
377 void __iomem *dma_base, *addr;
378
379 if (ei_local->dmaing) {
Matthew Whiteheadc45f8122013-12-11 17:00:59 -0500380 netdev_err(dev, "DMAing conflict in etherh_block_input: "
381 " DMAstat %d irqlock %d\n",
382 ei_local->dmaing, ei_local->irqlock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 return;
384 }
385
386 ei_local->dmaing = 1;
387
Al Virob9368892006-10-10 00:19:36 +0100388 addr = (void __iomem *)dev->base_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 dma_base = etherh_priv(dev)->dma_base;
390
391 buf = skb->data;
392 writeb (E8390_NODMA | E8390_PAGE0 | E8390_START, addr + E8390_CMD);
393 writeb (count, addr + EN0_RCNTLO);
394 writeb (count >> 8, addr + EN0_RCNTHI);
395 writeb (ring_offset, addr + EN0_RSARLO);
396 writeb (ring_offset >> 8, addr + EN0_RSARHI);
397 writeb (E8390_RREAD | E8390_START, addr + E8390_CMD);
398
399 if (ei_local->word16) {
400 readsw (dma_base, buf, count >> 1);
401 if (count & 1)
402 buf[count - 1] = readb (dma_base);
403 } else
404 readsb (dma_base, buf, count);
405
406 writeb (ENISR_RDC, addr + EN0_ISR);
407 ei_local->dmaing = 0;
408}
409
410/*
411 * Read a header from the 8390
412 */
413static void
414etherh_get_header (struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
415{
416 struct ei_device *ei_local = netdev_priv(dev);
417 void __iomem *dma_base, *addr;
418
419 if (ei_local->dmaing) {
Matthew Whiteheadc45f8122013-12-11 17:00:59 -0500420 netdev_err(dev, "DMAing conflict in etherh_get_header: "
421 " DMAstat %d irqlock %d\n",
422 ei_local->dmaing, ei_local->irqlock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 return;
424 }
425
426 ei_local->dmaing = 1;
427
Al Virob9368892006-10-10 00:19:36 +0100428 addr = (void __iomem *)dev->base_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 dma_base = etherh_priv(dev)->dma_base;
430
431 writeb (E8390_NODMA | E8390_PAGE0 | E8390_START, addr + E8390_CMD);
432 writeb (sizeof (*hdr), addr + EN0_RCNTLO);
433 writeb (0, addr + EN0_RCNTHI);
434 writeb (0, addr + EN0_RSARLO);
435 writeb (ring_page, addr + EN0_RSARHI);
436 writeb (E8390_RREAD | E8390_START, addr + E8390_CMD);
437
438 if (ei_local->word16)
439 readsw (dma_base, hdr, sizeof (*hdr) >> 1);
440 else
441 readsb (dma_base, hdr, sizeof (*hdr));
442
443 writeb (ENISR_RDC, addr + EN0_ISR);
444 ei_local->dmaing = 0;
445}
446
447/*
448 * Open/initialize the board. This is called (in the current kernel)
449 * sometime after booting when the 'ifconfig' program is run.
450 *
451 * This routine should set everything up anew at each open, even
452 * registers that "should" only need to be set once at boot, so that
453 * there is non-reboot way to recover if something goes wrong.
454 */
455static int
456etherh_open(struct net_device *dev)
457{
458 struct ei_device *ei_local = netdev_priv(dev);
459
Al Viro6c3561b2006-10-10 00:19:36 +0100460 if (request_irq(dev->irq, __ei_interrupt, 0, dev->name, dev))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 return -EAGAIN;
462
463 /*
464 * Make sure that we aren't going to change the
465 * media type on the next reset - we are about to
466 * do automedia manually now.
467 */
468 ei_local->interface_num = 0;
469
470 /*
471 * If we are doing automedia detection, do it now.
472 * This is more reliable than the 8390's detection.
473 */
474 if (dev->flags & IFF_AUTOMEDIA) {
475 dev->if_port = IF_PORT_10BASET;
476 etherh_setif(dev);
477 mdelay(1);
478 if (!etherh_getifstat(dev)) {
479 dev->if_port = IF_PORT_10BASE2;
480 etherh_setif(dev);
481 }
482 } else
483 etherh_setif(dev);
484
485 etherh_reset(dev);
Al Viro6c3561b2006-10-10 00:19:36 +0100486 __ei_open(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
488 return 0;
489}
490
491/*
492 * The inverse routine to etherh_open().
493 */
494static int
495etherh_close(struct net_device *dev)
496{
Al Viro6c3561b2006-10-10 00:19:36 +0100497 __ei_close (dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 free_irq (dev->irq, dev);
499 return 0;
500}
501
502/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 * Read the ethernet address string from the on board rom.
504 * This is an ascii string...
505 */
Bill Pemberton4168ac02012-12-03 09:22:51 -0500506static int etherh_addr(char *addr, struct expansion_card *ec)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507{
508 struct in_chunk_dir cd;
509 char *s;
510
511 if (!ecard_readchunk(&cd, ec, 0xf5, 0)) {
Masanari Iida94435f72015-04-27 23:14:57 +0900512 printk(KERN_ERR "%s: unable to read module description string\n",
Kay Sievers3f978702008-05-30 17:42:11 +0200513 dev_name(&ec->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 goto no_addr;
515 }
516
517 s = strchr(cd.d.string, '(');
518 if (s) {
519 int i;
520
521 for (i = 0; i < 6; i++) {
522 addr[i] = simple_strtoul(s + 1, &s, 0x10);
523 if (*s != (i == 5? ')' : ':'))
524 break;
525 }
526
527 if (i == 6)
528 return 0;
529 }
530
531 printk(KERN_ERR "%s: unable to parse MAC address: %s\n",
Kay Sievers3f978702008-05-30 17:42:11 +0200532 dev_name(&ec->dev), cd.d.string);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533
534 no_addr:
535 return -ENODEV;
536}
537
538/*
539 * Create an ethernet address from the system serial number.
540 */
541static int __init etherm_addr(char *addr)
542{
543 unsigned int serial;
544
545 if (system_serial_low == 0 && system_serial_high == 0)
546 return -ENODEV;
547
548 serial = system_serial_low | system_serial_high;
549
550 addr[0] = 0;
551 addr[1] = 0;
552 addr[2] = 0xa4;
553 addr[3] = 0x10 + (serial >> 24);
554 addr[4] = serial >> 16;
555 addr[5] = serial >> 8;
556 return 0;
557}
558
559static void etherh_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
560{
561 strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
562 strlcpy(info->version, DRV_VERSION, sizeof(info->version));
Kay Sievers3f978702008-05-30 17:42:11 +0200563 strlcpy(info->bus_info, dev_name(dev->dev.parent),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 sizeof(info->bus_info));
565}
566
Michal Kubecek6ce706a2018-08-28 19:56:53 +0200567static int etherh_get_link_ksettings(struct net_device *dev,
568 struct ethtool_link_ksettings *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569{
Michal Kubecek6ce706a2018-08-28 19:56:53 +0200570 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
571 etherh_priv(dev)->supported);
572 cmd->base.speed = SPEED_10;
573 cmd->base.duplex = DUPLEX_HALF;
574 cmd->base.port = dev->if_port == IF_PORT_10BASET ? PORT_TP : PORT_BNC;
575 cmd->base.autoneg = (dev->flags & IFF_AUTOMEDIA ? AUTONEG_ENABLE :
576 AUTONEG_DISABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 return 0;
578}
579
Michal Kubecek6ce706a2018-08-28 19:56:53 +0200580static int etherh_set_link_ksettings(struct net_device *dev,
581 const struct ethtool_link_ksettings *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582{
Michal Kubecek6ce706a2018-08-28 19:56:53 +0200583 switch (cmd->base.autoneg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 case AUTONEG_ENABLE:
585 dev->flags |= IFF_AUTOMEDIA;
586 break;
587
588 case AUTONEG_DISABLE:
Michal Kubecek6ce706a2018-08-28 19:56:53 +0200589 switch (cmd->base.port) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 case PORT_TP:
591 dev->if_port = IF_PORT_10BASET;
592 break;
593
594 case PORT_BNC:
595 dev->if_port = IF_PORT_10BASE2;
596 break;
597
598 default:
599 return -EINVAL;
600 }
601 dev->flags &= ~IFF_AUTOMEDIA;
602 break;
603
604 default:
605 return -EINVAL;
606 }
607
608 etherh_setif(dev);
609
610 return 0;
611}
612
Matthew Whiteheadc45f8122013-12-11 17:00:59 -0500613static u32 etherh_get_msglevel(struct net_device *dev)
614{
615 struct ei_device *ei_local = netdev_priv(dev);
616
617 return ei_local->msg_enable;
618}
619
620static void etherh_set_msglevel(struct net_device *dev, u32 v)
621{
622 struct ei_device *ei_local = netdev_priv(dev);
623
624 ei_local->msg_enable = v;
625}
626
Jeff Garzik7282d492006-09-13 14:30:00 -0400627static const struct ethtool_ops etherh_ethtool_ops = {
Michal Kubecek6ce706a2018-08-28 19:56:53 +0200628 .get_drvinfo = etherh_get_drvinfo,
629 .get_ts_info = ethtool_op_get_ts_info,
630 .get_msglevel = etherh_get_msglevel,
631 .set_msglevel = etherh_set_msglevel,
632 .get_link_ksettings = etherh_get_link_ksettings,
633 .set_link_ksettings = etherh_set_link_ksettings,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634};
635
Stephen Hemmingerb9a9b4b2008-12-02 14:52:25 -0800636static const struct net_device_ops etherh_netdev_ops = {
637 .ndo_open = etherh_open,
638 .ndo_stop = etherh_close,
639 .ndo_set_config = etherh_set_config,
Russell King8cfd9e92009-02-22 12:36:55 +0000640 .ndo_start_xmit = __ei_start_xmit,
641 .ndo_tx_timeout = __ei_tx_timeout,
642 .ndo_get_stats = __ei_get_stats,
Jiri Pirkoafc4b132011-08-16 06:29:01 +0000643 .ndo_set_rx_mode = __ei_set_multicast_list,
Stephen Hemmingerb9a9b4b2008-12-02 14:52:25 -0800644 .ndo_validate_addr = eth_validate_addr,
Russell Kinga71558d2009-01-27 22:32:29 +0000645 .ndo_set_mac_address = eth_mac_addr,
Stephen Hemmingerb9a9b4b2008-12-02 14:52:25 -0800646#ifdef CONFIG_NET_POLL_CONTROLLER
Russell King8cfd9e92009-02-22 12:36:55 +0000647 .ndo_poll_controller = __ei_poll,
Stephen Hemmingerb9a9b4b2008-12-02 14:52:25 -0800648#endif
649};
650
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651static u32 etherh_regoffsets[16];
652static u32 etherm_regoffsets[16];
653
Bill Pemberton4168ac02012-12-03 09:22:51 -0500654static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655etherh_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;
Russell King36149f02008-04-19 15:12:23 +0100661 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 ret = ecard_request_resources(ec);
664 if (ret)
665 goto out;
666
Al Viro6c3561b2006-10-10 00:19:36 +0100667 dev = ____alloc_ei_netdev(sizeof(struct etherh_priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 if (!dev) {
669 ret = -ENOMEM;
670 goto release;
671 }
672
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 SET_NETDEV_DEV(dev, &ec->dev);
674
Stephen Hemmingerb9a9b4b2008-12-02 14:52:25 -0800675 dev->netdev_ops = &etherh_netdev_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 dev->irq = ec->irq;
677 dev->ethtool_ops = &etherh_ethtool_ops;
678
679 if (data->supported & SUPPORTED_Autoneg)
680 dev->flags |= IFF_AUTOMEDIA;
681 if (data->supported & SUPPORTED_TP) {
682 dev->flags |= IFF_PORTSEL;
683 dev->if_port = IF_PORT_10BASET;
684 } else if (data->supported & SUPPORTED_BNC) {
685 dev->flags |= IFF_PORTSEL;
686 dev->if_port = IF_PORT_10BASE2;
687 } else
688 dev->if_port = IF_PORT_UNKNOWN;
689
690 eh = etherh_priv(dev);
691 eh->supported = data->supported;
692 eh->ctrl = 0;
693 eh->id = ec->cid.product;
Russell King10bdaaa2007-05-10 18:40:51 +0100694 eh->memc = ecardm_iomap(ec, ECARD_RES_MEMC, 0, PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 if (!eh->memc) {
696 ret = -ENOMEM;
697 goto free;
698 }
699
700 eh->ctrl_port = eh->memc;
701 if (data->ctrl_ioc) {
Russell King10bdaaa2007-05-10 18:40:51 +0100702 eh->ioc_fast = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 if (!eh->ioc_fast) {
704 ret = -ENOMEM;
705 goto free;
706 }
707 eh->ctrl_port = eh->ioc_fast;
708 }
709
Nicolas Pitrec7e78872005-06-29 18:10:54 +0100710 dev->base_addr = (unsigned long)eh->memc + data->ns8390_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 eh->dma_base = eh->memc + data->dataport_offset;
712 eh->ctrl_port += data->ctrlport_offset;
713
714 /*
715 * IRQ and control port handling - only for non-NIC slot cards.
716 */
717 if (ec->slot_no != 8) {
Russell Kingc7b87f32007-05-10 16:46:13 +0100718 ecard_setirq(ec, &etherh_ops, eh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 } else {
720 /*
721 * If we're in the NIC slot, make sure the IRQ is enabled
722 */
723 etherh_set_ctrl(eh, ETHERH_CP_IE);
724 }
725
726 ei_local = netdev_priv(dev);
727 spin_lock_init(&ei_local->page_lock);
728
729 if (ec->cid.product == PROD_ANT_ETHERM) {
730 etherm_addr(dev->dev_addr);
731 ei_local->reg_offset = etherm_regoffsets;
732 } else {
733 etherh_addr(dev->dev_addr, ec);
734 ei_local->reg_offset = etherh_regoffsets;
735 }
736
737 ei_local->name = dev->name;
738 ei_local->word16 = 1;
739 ei_local->tx_start_page = data->tx_start_page;
740 ei_local->rx_start_page = ei_local->tx_start_page + TX_PAGES;
741 ei_local->stop_page = data->stop_page;
742 ei_local->reset_8390 = etherh_reset;
743 ei_local->block_input = etherh_block_input;
744 ei_local->block_output = etherh_block_output;
745 ei_local->get_8390_hdr = etherh_get_header;
746 ei_local->interface_num = 0;
747
748 etherh_reset(dev);
Al Viro6c3561b2006-10-10 00:19:36 +0100749 __NS8390_init(dev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750
751 ret = register_netdev(dev);
752 if (ret)
753 goto free;
754
Matthew Whiteheadc45f8122013-12-11 17:00:59 -0500755 netdev_info(dev, "%s in slot %d, %pM\n",
756 data->name, ec->slot_no, dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757
758 ecard_set_drvdata(ec, dev);
759
760 return 0;
761
762 free:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 free_netdev(dev);
764 release:
765 ecard_release_resources(ec);
766 out:
767 return ret;
768}
769
Bill Pemberton4168ac02012-12-03 09:22:51 -0500770static void etherh_remove(struct expansion_card *ec)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771{
772 struct net_device *dev = ecard_get_drvdata(ec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773
774 ecard_set_drvdata(ec, NULL);
775
776 unregister_netdev(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 free_netdev(dev);
779
780 ecard_release_resources(ec);
781}
782
783static struct etherh_data etherm_data = {
784 .ns8390_offset = ETHERM_NS8390,
785 .dataport_offset = ETHERM_NS8390 + ETHERM_DATAPORT,
786 .ctrlport_offset = ETHERM_NS8390 + ETHERM_CTRLPORT,
787 .name = "ANT EtherM",
788 .supported = SUPPORTED_10baseT_Half,
789 .tx_start_page = ETHERM_TX_START_PAGE,
790 .stop_page = ETHERM_STOP_PAGE,
791};
792
793static struct etherh_data etherlan500_data = {
794 .ns8390_offset = ETHERH500_NS8390,
795 .dataport_offset = ETHERH500_NS8390 + ETHERH500_DATAPORT,
796 .ctrlport_offset = ETHERH500_CTRLPORT,
797 .ctrl_ioc = 1,
798 .name = "i3 EtherH 500",
799 .supported = SUPPORTED_10baseT_Half,
800 .tx_start_page = ETHERH_TX_START_PAGE,
801 .stop_page = ETHERH_STOP_PAGE,
802};
803
804static struct etherh_data etherlan600_data = {
805 .ns8390_offset = ETHERH600_NS8390,
806 .dataport_offset = ETHERH600_NS8390 + ETHERH600_DATAPORT,
807 .ctrlport_offset = ETHERH600_NS8390 + ETHERH600_CTRLPORT,
808 .name = "i3 EtherH 600",
809 .supported = SUPPORTED_10baseT_Half | SUPPORTED_TP | SUPPORTED_BNC | SUPPORTED_Autoneg,
810 .tx_start_page = ETHERH_TX_START_PAGE,
811 .stop_page = ETHERH_STOP_PAGE,
812};
813
814static struct etherh_data etherlan600a_data = {
815 .ns8390_offset = ETHERH600_NS8390,
816 .dataport_offset = ETHERH600_NS8390 + ETHERH600_DATAPORT,
817 .ctrlport_offset = ETHERH600_NS8390 + ETHERH600_CTRLPORT,
818 .name = "i3 EtherH 600A",
819 .supported = SUPPORTED_10baseT_Half | SUPPORTED_TP | SUPPORTED_BNC | SUPPORTED_Autoneg,
820 .tx_start_page = ETHERH_TX_START_PAGE,
821 .stop_page = ETHERH_STOP_PAGE,
822};
823
824static const struct ecard_id etherh_ids[] = {
825 { MANU_ANT, PROD_ANT_ETHERM, &etherm_data },
826 { MANU_I3, PROD_I3_ETHERLAN500, &etherlan500_data },
827 { MANU_I3, PROD_I3_ETHERLAN600, &etherlan600_data },
828 { MANU_I3, PROD_I3_ETHERLAN600A, &etherlan600a_data },
829 { 0xffff, 0xffff }
830};
831
832static struct ecard_driver etherh_driver = {
833 .probe = etherh_probe,
Bill Pemberton4168ac02012-12-03 09:22:51 -0500834 .remove = etherh_remove,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 .id_table = etherh_ids,
836 .drv = {
837 .name = DRV_NAME,
838 },
839};
840
841static int __init etherh_init(void)
842{
843 int i;
844
845 for (i = 0; i < 16; i++) {
846 etherh_regoffsets[i] = i << 2;
847 etherm_regoffsets[i] = i << 5;
848 }
849
850 return ecard_register_driver(&etherh_driver);
851}
852
853static void __exit etherh_exit(void)
854{
855 ecard_remove_driver(&etherh_driver);
856}
857
858module_init(etherh_init);
859module_exit(etherh_exit);