1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2644570b8SJeff Kirsher /*
3644570b8SJeff Kirsher * linux/drivers/acorn/net/etherh.c
4644570b8SJeff Kirsher *
5644570b8SJeff Kirsher * Copyright (C) 2000-2002 Russell King
6644570b8SJeff Kirsher *
7644570b8SJeff Kirsher * NS8390 I-cubed EtherH and ANT EtherM specific driver
8644570b8SJeff Kirsher * Thanks to I-Cubed for information on their cards.
9644570b8SJeff Kirsher * EtherM conversion (C) 1999 Chris Kemp and Tim Watterton
10644570b8SJeff Kirsher * EtherM integration (C) 2000 Aleph One Ltd (Tak-Shing Chan)
11644570b8SJeff Kirsher * EtherM integration re-engineered by Russell King.
12644570b8SJeff Kirsher *
13644570b8SJeff Kirsher * Changelog:
14644570b8SJeff Kirsher * 08-12-1996 RMK 1.00 Created
15644570b8SJeff Kirsher * RMK 1.03 Added support for EtherLan500 cards
16644570b8SJeff Kirsher * 23-11-1997 RMK 1.04 Added media autodetection
17644570b8SJeff Kirsher * 16-04-1998 RMK 1.05 Improved media autodetection
18644570b8SJeff Kirsher * 10-02-2000 RMK 1.06 Updated for 2.3.43
19644570b8SJeff Kirsher * 13-05-2000 RMK 1.07 Updated for 2.3.99-pre8
20644570b8SJeff Kirsher * 12-10-1999 CK/TEW EtherM driver first release
21644570b8SJeff Kirsher * 21-12-2000 TTC EtherH/EtherM integration
22644570b8SJeff Kirsher * 25-12-2000 RMK 1.08 Clean integration of EtherM into this driver.
23644570b8SJeff Kirsher * 03-01-2002 RMK 1.09 Always enable IRQs if we're in the nic slot.
24644570b8SJeff Kirsher */
25644570b8SJeff Kirsher
26644570b8SJeff Kirsher #include <linux/module.h>
27644570b8SJeff Kirsher #include <linux/kernel.h>
28644570b8SJeff Kirsher #include <linux/types.h>
29644570b8SJeff Kirsher #include <linux/fcntl.h>
30644570b8SJeff Kirsher #include <linux/interrupt.h>
31644570b8SJeff Kirsher #include <linux/ioport.h>
32644570b8SJeff Kirsher #include <linux/in.h>
33644570b8SJeff Kirsher #include <linux/string.h>
34644570b8SJeff Kirsher #include <linux/errno.h>
35644570b8SJeff Kirsher #include <linux/netdevice.h>
36644570b8SJeff Kirsher #include <linux/etherdevice.h>
37644570b8SJeff Kirsher #include <linux/ethtool.h>
38644570b8SJeff Kirsher #include <linux/skbuff.h>
39644570b8SJeff Kirsher #include <linux/delay.h>
40644570b8SJeff Kirsher #include <linux/device.h>
41644570b8SJeff Kirsher #include <linux/init.h>
42644570b8SJeff Kirsher #include <linux/bitops.h>
43644570b8SJeff Kirsher #include <linux/jiffies.h>
44644570b8SJeff Kirsher
45644570b8SJeff Kirsher #include <asm/ecard.h>
46644570b8SJeff Kirsher #include <asm/io.h>
479f97da78SDavid Howells #include <asm/system_info.h>
48644570b8SJeff Kirsher
49644570b8SJeff Kirsher #define EI_SHIFT(x) (ei_local->reg_offset[x])
50644570b8SJeff Kirsher
51644570b8SJeff Kirsher #define ei_inb(_p) readb((void __iomem *)_p)
52644570b8SJeff Kirsher #define ei_outb(_v,_p) writeb(_v,(void __iomem *)_p)
53644570b8SJeff Kirsher #define ei_inb_p(_p) readb((void __iomem *)_p)
54644570b8SJeff Kirsher #define ei_outb_p(_v,_p) writeb(_v,(void __iomem *)_p)
55644570b8SJeff Kirsher
56644570b8SJeff Kirsher #define DRV_NAME "etherh"
57644570b8SJeff Kirsher #define DRV_VERSION "1.11"
58644570b8SJeff Kirsher
59335802d1SOlof Johansson static char version[] =
60644570b8SJeff Kirsher "EtherH/EtherM Driver (c) 2002-2004 Russell King " DRV_VERSION "\n";
61644570b8SJeff Kirsher
62644570b8SJeff Kirsher #include "lib8390.c"
63644570b8SJeff Kirsher
64644570b8SJeff Kirsher struct etherh_priv {
65644570b8SJeff Kirsher void __iomem *ioc_fast;
66644570b8SJeff Kirsher void __iomem *memc;
67644570b8SJeff Kirsher void __iomem *dma_base;
68644570b8SJeff Kirsher unsigned int id;
69644570b8SJeff Kirsher void __iomem *ctrl_port;
70644570b8SJeff Kirsher unsigned char ctrl;
71644570b8SJeff Kirsher u32 supported;
72644570b8SJeff Kirsher };
73644570b8SJeff Kirsher
74644570b8SJeff Kirsher struct etherh_data {
75644570b8SJeff Kirsher unsigned long ns8390_offset;
76644570b8SJeff Kirsher unsigned long dataport_offset;
77644570b8SJeff Kirsher unsigned long ctrlport_offset;
78644570b8SJeff Kirsher int ctrl_ioc;
79644570b8SJeff Kirsher const char name[16];
80644570b8SJeff Kirsher u32 supported;
81644570b8SJeff Kirsher unsigned char tx_start_page;
82644570b8SJeff Kirsher unsigned char stop_page;
83644570b8SJeff Kirsher };
84644570b8SJeff Kirsher
85644570b8SJeff Kirsher MODULE_AUTHOR("Russell King");
86644570b8SJeff Kirsher MODULE_DESCRIPTION("EtherH/EtherM driver");
87644570b8SJeff Kirsher MODULE_LICENSE("GPL");
88644570b8SJeff Kirsher
89644570b8SJeff Kirsher #define ETHERH500_DATAPORT 0x800 /* MEMC */
90644570b8SJeff Kirsher #define ETHERH500_NS8390 0x000 /* MEMC */
91644570b8SJeff Kirsher #define ETHERH500_CTRLPORT 0x800 /* IOC */
92644570b8SJeff Kirsher
93644570b8SJeff Kirsher #define ETHERH600_DATAPORT 0x040 /* MEMC */
94644570b8SJeff Kirsher #define ETHERH600_NS8390 0x800 /* MEMC */
95644570b8SJeff Kirsher #define ETHERH600_CTRLPORT 0x200 /* MEMC */
96644570b8SJeff Kirsher
97644570b8SJeff Kirsher #define ETHERH_CP_IE 1
98644570b8SJeff Kirsher #define ETHERH_CP_IF 2
99644570b8SJeff Kirsher #define ETHERH_CP_HEARTBEAT 2
100644570b8SJeff Kirsher
101644570b8SJeff Kirsher #define ETHERH_TX_START_PAGE 1
102644570b8SJeff Kirsher #define ETHERH_STOP_PAGE 127
103644570b8SJeff Kirsher
104644570b8SJeff Kirsher /*
105644570b8SJeff Kirsher * These came from CK/TEW
106644570b8SJeff Kirsher */
107644570b8SJeff Kirsher #define ETHERM_DATAPORT 0x200 /* MEMC */
108644570b8SJeff Kirsher #define ETHERM_NS8390 0x800 /* MEMC */
109644570b8SJeff Kirsher #define ETHERM_CTRLPORT 0x23c /* MEMC */
110644570b8SJeff Kirsher
111644570b8SJeff Kirsher #define ETHERM_TX_START_PAGE 64
112644570b8SJeff Kirsher #define ETHERM_STOP_PAGE 127
113644570b8SJeff Kirsher
114644570b8SJeff Kirsher /* ------------------------------------------------------------------------ */
115644570b8SJeff Kirsher
116644570b8SJeff Kirsher #define etherh_priv(dev) \
117644570b8SJeff Kirsher ((struct etherh_priv *)(((char *)netdev_priv(dev)) + sizeof(struct ei_device)))
118644570b8SJeff Kirsher
etherh_set_ctrl(struct etherh_priv * eh,unsigned char mask)119644570b8SJeff Kirsher static inline void etherh_set_ctrl(struct etherh_priv *eh, unsigned char mask)
120644570b8SJeff Kirsher {
121644570b8SJeff Kirsher unsigned char ctrl = eh->ctrl | mask;
122644570b8SJeff Kirsher eh->ctrl = ctrl;
123644570b8SJeff Kirsher writeb(ctrl, eh->ctrl_port);
124644570b8SJeff Kirsher }
125644570b8SJeff Kirsher
etherh_clr_ctrl(struct etherh_priv * eh,unsigned char mask)126644570b8SJeff Kirsher static inline void etherh_clr_ctrl(struct etherh_priv *eh, unsigned char mask)
127644570b8SJeff Kirsher {
128644570b8SJeff Kirsher unsigned char ctrl = eh->ctrl & ~mask;
129644570b8SJeff Kirsher eh->ctrl = ctrl;
130644570b8SJeff Kirsher writeb(ctrl, eh->ctrl_port);
131644570b8SJeff Kirsher }
132644570b8SJeff Kirsher
etherh_get_stat(struct etherh_priv * eh)133644570b8SJeff Kirsher static inline unsigned int etherh_get_stat(struct etherh_priv *eh)
134644570b8SJeff Kirsher {
135644570b8SJeff Kirsher return readb(eh->ctrl_port);
136644570b8SJeff Kirsher }
137644570b8SJeff Kirsher
138644570b8SJeff Kirsher
139644570b8SJeff Kirsher
140644570b8SJeff Kirsher
etherh_irq_enable(ecard_t * ec,int irqnr)141644570b8SJeff Kirsher static void etherh_irq_enable(ecard_t *ec, int irqnr)
142644570b8SJeff Kirsher {
143644570b8SJeff Kirsher struct etherh_priv *eh = ec->irq_data;
144644570b8SJeff Kirsher
145644570b8SJeff Kirsher etherh_set_ctrl(eh, ETHERH_CP_IE);
146644570b8SJeff Kirsher }
147644570b8SJeff Kirsher
etherh_irq_disable(ecard_t * ec,int irqnr)148644570b8SJeff Kirsher static void etherh_irq_disable(ecard_t *ec, int irqnr)
149644570b8SJeff Kirsher {
150644570b8SJeff Kirsher struct etherh_priv *eh = ec->irq_data;
151644570b8SJeff Kirsher
152644570b8SJeff Kirsher etherh_clr_ctrl(eh, ETHERH_CP_IE);
153644570b8SJeff Kirsher }
154644570b8SJeff Kirsher
155644570b8SJeff Kirsher static expansioncard_ops_t etherh_ops = {
156644570b8SJeff Kirsher .irqenable = etherh_irq_enable,
157644570b8SJeff Kirsher .irqdisable = etherh_irq_disable,
158644570b8SJeff Kirsher };
159644570b8SJeff Kirsher
160644570b8SJeff Kirsher
161644570b8SJeff Kirsher
162644570b8SJeff Kirsher
163644570b8SJeff Kirsher static void
etherh_setif(struct net_device * dev)164644570b8SJeff Kirsher etherh_setif(struct net_device *dev)
165644570b8SJeff Kirsher {
166644570b8SJeff Kirsher struct ei_device *ei_local = netdev_priv(dev);
167644570b8SJeff Kirsher unsigned long flags;
168644570b8SJeff Kirsher void __iomem *addr;
169644570b8SJeff Kirsher
170644570b8SJeff Kirsher local_irq_save(flags);
171644570b8SJeff Kirsher
172644570b8SJeff Kirsher /* set the interface type */
173644570b8SJeff Kirsher switch (etherh_priv(dev)->id) {
174644570b8SJeff Kirsher case PROD_I3_ETHERLAN600:
175644570b8SJeff Kirsher case PROD_I3_ETHERLAN600A:
176644570b8SJeff Kirsher addr = (void __iomem *)dev->base_addr + EN0_RCNTHI;
177644570b8SJeff Kirsher
178644570b8SJeff Kirsher switch (dev->if_port) {
179644570b8SJeff Kirsher case IF_PORT_10BASE2:
180644570b8SJeff Kirsher writeb((readb(addr) & 0xf8) | 1, addr);
181644570b8SJeff Kirsher break;
182644570b8SJeff Kirsher case IF_PORT_10BASET:
183644570b8SJeff Kirsher writeb((readb(addr) & 0xf8), addr);
184644570b8SJeff Kirsher break;
185644570b8SJeff Kirsher }
186644570b8SJeff Kirsher break;
187644570b8SJeff Kirsher
188644570b8SJeff Kirsher case PROD_I3_ETHERLAN500:
189644570b8SJeff Kirsher switch (dev->if_port) {
190644570b8SJeff Kirsher case IF_PORT_10BASE2:
191644570b8SJeff Kirsher etherh_clr_ctrl(etherh_priv(dev), ETHERH_CP_IF);
192644570b8SJeff Kirsher break;
193644570b8SJeff Kirsher
194644570b8SJeff Kirsher case IF_PORT_10BASET:
195644570b8SJeff Kirsher etherh_set_ctrl(etherh_priv(dev), ETHERH_CP_IF);
196644570b8SJeff Kirsher break;
197644570b8SJeff Kirsher }
198644570b8SJeff Kirsher break;
199644570b8SJeff Kirsher
200644570b8SJeff Kirsher default:
201644570b8SJeff Kirsher break;
202644570b8SJeff Kirsher }
203644570b8SJeff Kirsher
204644570b8SJeff Kirsher local_irq_restore(flags);
205644570b8SJeff Kirsher }
206644570b8SJeff Kirsher
207644570b8SJeff Kirsher static int
etherh_getifstat(struct net_device * dev)208644570b8SJeff Kirsher etherh_getifstat(struct net_device *dev)
209644570b8SJeff Kirsher {
210644570b8SJeff Kirsher struct ei_device *ei_local = netdev_priv(dev);
211644570b8SJeff Kirsher void __iomem *addr;
212644570b8SJeff Kirsher int stat = 0;
213644570b8SJeff Kirsher
214644570b8SJeff Kirsher switch (etherh_priv(dev)->id) {
215644570b8SJeff Kirsher case PROD_I3_ETHERLAN600:
216644570b8SJeff Kirsher case PROD_I3_ETHERLAN600A:
217644570b8SJeff Kirsher addr = (void __iomem *)dev->base_addr + EN0_RCNTHI;
218644570b8SJeff Kirsher switch (dev->if_port) {
219644570b8SJeff Kirsher case IF_PORT_10BASE2:
220644570b8SJeff Kirsher stat = 1;
221644570b8SJeff Kirsher break;
222644570b8SJeff Kirsher case IF_PORT_10BASET:
223644570b8SJeff Kirsher stat = readb(addr) & 4;
224644570b8SJeff Kirsher break;
225644570b8SJeff Kirsher }
226644570b8SJeff Kirsher break;
227644570b8SJeff Kirsher
228644570b8SJeff Kirsher case PROD_I3_ETHERLAN500:
229644570b8SJeff Kirsher switch (dev->if_port) {
230644570b8SJeff Kirsher case IF_PORT_10BASE2:
231644570b8SJeff Kirsher stat = 1;
232644570b8SJeff Kirsher break;
233644570b8SJeff Kirsher case IF_PORT_10BASET:
234644570b8SJeff Kirsher stat = etherh_get_stat(etherh_priv(dev)) & ETHERH_CP_HEARTBEAT;
235644570b8SJeff Kirsher break;
236644570b8SJeff Kirsher }
237644570b8SJeff Kirsher break;
238644570b8SJeff Kirsher
239644570b8SJeff Kirsher default:
240644570b8SJeff Kirsher stat = 0;
241644570b8SJeff Kirsher break;
242644570b8SJeff Kirsher }
243644570b8SJeff Kirsher
244644570b8SJeff Kirsher return stat != 0;
245644570b8SJeff Kirsher }
246644570b8SJeff Kirsher
247644570b8SJeff Kirsher /*
248644570b8SJeff Kirsher * Configure the interface. Note that we ignore the other
249644570b8SJeff Kirsher * parts of ifmap, since its mostly meaningless for this driver.
250644570b8SJeff Kirsher */
etherh_set_config(struct net_device * dev,struct ifmap * map)251644570b8SJeff Kirsher static int etherh_set_config(struct net_device *dev, struct ifmap *map)
252644570b8SJeff Kirsher {
253644570b8SJeff Kirsher switch (map->port) {
254644570b8SJeff Kirsher case IF_PORT_10BASE2:
255644570b8SJeff Kirsher case IF_PORT_10BASET:
256644570b8SJeff Kirsher /*
257644570b8SJeff Kirsher * If the user explicitly sets the interface
258644570b8SJeff Kirsher * media type, turn off automedia detection.
259644570b8SJeff Kirsher */
260644570b8SJeff Kirsher dev->flags &= ~IFF_AUTOMEDIA;
261644570b8SJeff Kirsher dev->if_port = map->port;
262644570b8SJeff Kirsher break;
263644570b8SJeff Kirsher
264644570b8SJeff Kirsher default:
265644570b8SJeff Kirsher return -EINVAL;
266644570b8SJeff Kirsher }
267644570b8SJeff Kirsher
268644570b8SJeff Kirsher etherh_setif(dev);
269644570b8SJeff Kirsher
270644570b8SJeff Kirsher return 0;
271644570b8SJeff Kirsher }
272644570b8SJeff Kirsher
273644570b8SJeff Kirsher /*
274644570b8SJeff Kirsher * Reset the 8390 (hard reset). Note that we can't actually do this.
275644570b8SJeff Kirsher */
276644570b8SJeff Kirsher static void
etherh_reset(struct net_device * dev)277644570b8SJeff Kirsher etherh_reset(struct net_device *dev)
278644570b8SJeff Kirsher {
279644570b8SJeff Kirsher struct ei_device *ei_local = netdev_priv(dev);
280644570b8SJeff Kirsher void __iomem *addr = (void __iomem *)dev->base_addr;
281644570b8SJeff Kirsher
282644570b8SJeff Kirsher writeb(E8390_NODMA+E8390_PAGE0+E8390_STOP, addr);
283644570b8SJeff Kirsher
284644570b8SJeff Kirsher /*
285644570b8SJeff Kirsher * See if we need to change the interface type.
286644570b8SJeff Kirsher * Note that we use 'interface_num' as a flag
287644570b8SJeff Kirsher * to indicate that we need to change the media.
288644570b8SJeff Kirsher */
289644570b8SJeff Kirsher if (dev->flags & IFF_AUTOMEDIA && ei_local->interface_num) {
290644570b8SJeff Kirsher ei_local->interface_num = 0;
291644570b8SJeff Kirsher
292644570b8SJeff Kirsher if (dev->if_port == IF_PORT_10BASET)
293644570b8SJeff Kirsher dev->if_port = IF_PORT_10BASE2;
294644570b8SJeff Kirsher else
295644570b8SJeff Kirsher dev->if_port = IF_PORT_10BASET;
296644570b8SJeff Kirsher
297644570b8SJeff Kirsher etherh_setif(dev);
298644570b8SJeff Kirsher }
299644570b8SJeff Kirsher }
300644570b8SJeff Kirsher
301644570b8SJeff Kirsher /*
302644570b8SJeff Kirsher * Write a block of data out to the 8390
303644570b8SJeff Kirsher */
304644570b8SJeff Kirsher static void
etherh_block_output(struct net_device * dev,int count,const unsigned char * buf,int start_page)305644570b8SJeff Kirsher etherh_block_output (struct net_device *dev, int count, const unsigned char *buf, int start_page)
306644570b8SJeff Kirsher {
307644570b8SJeff Kirsher struct ei_device *ei_local = netdev_priv(dev);
308644570b8SJeff Kirsher unsigned long dma_start;
309644570b8SJeff Kirsher void __iomem *dma_base, *addr;
310644570b8SJeff Kirsher
311644570b8SJeff Kirsher if (ei_local->dmaing) {
312c45f812fSMatthew Whitehead netdev_err(dev, "DMAing conflict in etherh_block_input: "
313c45f812fSMatthew Whitehead " DMAstat %d irqlock %d\n",
314644570b8SJeff Kirsher ei_local->dmaing, ei_local->irqlock);
315644570b8SJeff Kirsher return;
316644570b8SJeff Kirsher }
317644570b8SJeff Kirsher
318644570b8SJeff Kirsher /*
319644570b8SJeff Kirsher * Make sure we have a round number of bytes if we're in word mode.
320644570b8SJeff Kirsher */
321644570b8SJeff Kirsher if (count & 1 && ei_local->word16)
322644570b8SJeff Kirsher count++;
323644570b8SJeff Kirsher
324644570b8SJeff Kirsher ei_local->dmaing = 1;
325644570b8SJeff Kirsher
326644570b8SJeff Kirsher addr = (void __iomem *)dev->base_addr;
327644570b8SJeff Kirsher dma_base = etherh_priv(dev)->dma_base;
328644570b8SJeff Kirsher
329644570b8SJeff Kirsher count = (count + 1) & ~1;
330644570b8SJeff Kirsher writeb (E8390_NODMA | E8390_PAGE0 | E8390_START, addr + E8390_CMD);
331644570b8SJeff Kirsher
332644570b8SJeff Kirsher writeb (0x42, addr + EN0_RCNTLO);
333644570b8SJeff Kirsher writeb (0x00, addr + EN0_RCNTHI);
334644570b8SJeff Kirsher writeb (0x42, addr + EN0_RSARLO);
335644570b8SJeff Kirsher writeb (0x00, addr + EN0_RSARHI);
336644570b8SJeff Kirsher writeb (E8390_RREAD | E8390_START, addr + E8390_CMD);
337644570b8SJeff Kirsher
338644570b8SJeff Kirsher udelay (1);
339644570b8SJeff Kirsher
340644570b8SJeff Kirsher writeb (ENISR_RDC, addr + EN0_ISR);
341644570b8SJeff Kirsher writeb (count, addr + EN0_RCNTLO);
342644570b8SJeff Kirsher writeb (count >> 8, addr + EN0_RCNTHI);
343644570b8SJeff Kirsher writeb (0, addr + EN0_RSARLO);
344644570b8SJeff Kirsher writeb (start_page, addr + EN0_RSARHI);
345644570b8SJeff Kirsher writeb (E8390_RWRITE | E8390_START, addr + E8390_CMD);
346644570b8SJeff Kirsher
347644570b8SJeff Kirsher if (ei_local->word16)
348644570b8SJeff Kirsher writesw (dma_base, buf, count >> 1);
349644570b8SJeff Kirsher else
350644570b8SJeff Kirsher writesb (dma_base, buf, count);
351644570b8SJeff Kirsher
352644570b8SJeff Kirsher dma_start = jiffies;
353644570b8SJeff Kirsher
354644570b8SJeff Kirsher while ((readb (addr + EN0_ISR) & ENISR_RDC) == 0)
355644570b8SJeff Kirsher if (time_after(jiffies, dma_start + 2*HZ/100)) { /* 20ms */
356c45f812fSMatthew Whitehead netdev_warn(dev, "timeout waiting for TX RDC\n");
357644570b8SJeff Kirsher etherh_reset (dev);
358644570b8SJeff Kirsher __NS8390_init (dev, 1);
359644570b8SJeff Kirsher break;
360644570b8SJeff Kirsher }
361644570b8SJeff Kirsher
362644570b8SJeff Kirsher writeb (ENISR_RDC, addr + EN0_ISR);
363644570b8SJeff Kirsher ei_local->dmaing = 0;
364644570b8SJeff Kirsher }
365644570b8SJeff Kirsher
366644570b8SJeff Kirsher /*
367644570b8SJeff Kirsher * Read a block of data from the 8390
368644570b8SJeff Kirsher */
369644570b8SJeff Kirsher static void
etherh_block_input(struct net_device * dev,int count,struct sk_buff * skb,int ring_offset)370644570b8SJeff Kirsher etherh_block_input (struct net_device *dev, int count, struct sk_buff *skb, int ring_offset)
371644570b8SJeff Kirsher {
372644570b8SJeff Kirsher struct ei_device *ei_local = netdev_priv(dev);
373644570b8SJeff Kirsher unsigned char *buf;
374644570b8SJeff Kirsher void __iomem *dma_base, *addr;
375644570b8SJeff Kirsher
376644570b8SJeff Kirsher if (ei_local->dmaing) {
377c45f812fSMatthew Whitehead netdev_err(dev, "DMAing conflict in etherh_block_input: "
378c45f812fSMatthew Whitehead " DMAstat %d irqlock %d\n",
379644570b8SJeff Kirsher ei_local->dmaing, ei_local->irqlock);
380644570b8SJeff Kirsher return;
381644570b8SJeff Kirsher }
382644570b8SJeff Kirsher
383644570b8SJeff Kirsher ei_local->dmaing = 1;
384644570b8SJeff Kirsher
385644570b8SJeff Kirsher addr = (void __iomem *)dev->base_addr;
386644570b8SJeff Kirsher dma_base = etherh_priv(dev)->dma_base;
387644570b8SJeff Kirsher
388644570b8SJeff Kirsher buf = skb->data;
389644570b8SJeff Kirsher writeb (E8390_NODMA | E8390_PAGE0 | E8390_START, addr + E8390_CMD);
390644570b8SJeff Kirsher writeb (count, addr + EN0_RCNTLO);
391644570b8SJeff Kirsher writeb (count >> 8, addr + EN0_RCNTHI);
392644570b8SJeff Kirsher writeb (ring_offset, addr + EN0_RSARLO);
393644570b8SJeff Kirsher writeb (ring_offset >> 8, addr + EN0_RSARHI);
394644570b8SJeff Kirsher writeb (E8390_RREAD | E8390_START, addr + E8390_CMD);
395644570b8SJeff Kirsher
396644570b8SJeff Kirsher if (ei_local->word16) {
397644570b8SJeff Kirsher readsw (dma_base, buf, count >> 1);
398644570b8SJeff Kirsher if (count & 1)
399644570b8SJeff Kirsher buf[count - 1] = readb (dma_base);
400644570b8SJeff Kirsher } else
401644570b8SJeff Kirsher readsb (dma_base, buf, count);
402644570b8SJeff Kirsher
403644570b8SJeff Kirsher writeb (ENISR_RDC, addr + EN0_ISR);
404644570b8SJeff Kirsher ei_local->dmaing = 0;
405644570b8SJeff Kirsher }
406644570b8SJeff Kirsher
407644570b8SJeff Kirsher /*
408644570b8SJeff Kirsher * Read a header from the 8390
409644570b8SJeff Kirsher */
410644570b8SJeff Kirsher static void
etherh_get_header(struct net_device * dev,struct e8390_pkt_hdr * hdr,int ring_page)411644570b8SJeff Kirsher etherh_get_header (struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
412644570b8SJeff Kirsher {
413644570b8SJeff Kirsher struct ei_device *ei_local = netdev_priv(dev);
414644570b8SJeff Kirsher void __iomem *dma_base, *addr;
415644570b8SJeff Kirsher
416644570b8SJeff Kirsher if (ei_local->dmaing) {
417c45f812fSMatthew Whitehead netdev_err(dev, "DMAing conflict in etherh_get_header: "
418c45f812fSMatthew Whitehead " DMAstat %d irqlock %d\n",
419644570b8SJeff Kirsher ei_local->dmaing, ei_local->irqlock);
420644570b8SJeff Kirsher return;
421644570b8SJeff Kirsher }
422644570b8SJeff Kirsher
423644570b8SJeff Kirsher ei_local->dmaing = 1;
424644570b8SJeff Kirsher
425644570b8SJeff Kirsher addr = (void __iomem *)dev->base_addr;
426644570b8SJeff Kirsher dma_base = etherh_priv(dev)->dma_base;
427644570b8SJeff Kirsher
428644570b8SJeff Kirsher writeb (E8390_NODMA | E8390_PAGE0 | E8390_START, addr + E8390_CMD);
429644570b8SJeff Kirsher writeb (sizeof (*hdr), addr + EN0_RCNTLO);
430644570b8SJeff Kirsher writeb (0, addr + EN0_RCNTHI);
431644570b8SJeff Kirsher writeb (0, addr + EN0_RSARLO);
432644570b8SJeff Kirsher writeb (ring_page, addr + EN0_RSARHI);
433644570b8SJeff Kirsher writeb (E8390_RREAD | E8390_START, addr + E8390_CMD);
434644570b8SJeff Kirsher
435644570b8SJeff Kirsher if (ei_local->word16)
436644570b8SJeff Kirsher readsw (dma_base, hdr, sizeof (*hdr) >> 1);
437644570b8SJeff Kirsher else
438644570b8SJeff Kirsher readsb (dma_base, hdr, sizeof (*hdr));
439644570b8SJeff Kirsher
440644570b8SJeff Kirsher writeb (ENISR_RDC, addr + EN0_ISR);
441644570b8SJeff Kirsher ei_local->dmaing = 0;
442644570b8SJeff Kirsher }
443644570b8SJeff Kirsher
444644570b8SJeff Kirsher /*
445644570b8SJeff Kirsher * Open/initialize the board. This is called (in the current kernel)
446644570b8SJeff Kirsher * sometime after booting when the 'ifconfig' program is run.
447644570b8SJeff Kirsher *
448644570b8SJeff Kirsher * This routine should set everything up anew at each open, even
449644570b8SJeff Kirsher * registers that "should" only need to be set once at boot, so that
450644570b8SJeff Kirsher * there is non-reboot way to recover if something goes wrong.
451644570b8SJeff Kirsher */
452644570b8SJeff Kirsher static int
etherh_open(struct net_device * dev)453644570b8SJeff Kirsher etherh_open(struct net_device *dev)
454644570b8SJeff Kirsher {
455644570b8SJeff Kirsher struct ei_device *ei_local = netdev_priv(dev);
456644570b8SJeff Kirsher
457644570b8SJeff Kirsher if (request_irq(dev->irq, __ei_interrupt, 0, dev->name, dev))
458644570b8SJeff Kirsher return -EAGAIN;
459644570b8SJeff Kirsher
460644570b8SJeff Kirsher /*
461644570b8SJeff Kirsher * Make sure that we aren't going to change the
462644570b8SJeff Kirsher * media type on the next reset - we are about to
463644570b8SJeff Kirsher * do automedia manually now.
464644570b8SJeff Kirsher */
465644570b8SJeff Kirsher ei_local->interface_num = 0;
466644570b8SJeff Kirsher
467644570b8SJeff Kirsher /*
468644570b8SJeff Kirsher * If we are doing automedia detection, do it now.
469644570b8SJeff Kirsher * This is more reliable than the 8390's detection.
470644570b8SJeff Kirsher */
471644570b8SJeff Kirsher if (dev->flags & IFF_AUTOMEDIA) {
472644570b8SJeff Kirsher dev->if_port = IF_PORT_10BASET;
473644570b8SJeff Kirsher etherh_setif(dev);
474644570b8SJeff Kirsher mdelay(1);
475644570b8SJeff Kirsher if (!etherh_getifstat(dev)) {
476644570b8SJeff Kirsher dev->if_port = IF_PORT_10BASE2;
477644570b8SJeff Kirsher etherh_setif(dev);
478644570b8SJeff Kirsher }
479644570b8SJeff Kirsher } else
480644570b8SJeff Kirsher etherh_setif(dev);
481644570b8SJeff Kirsher
482644570b8SJeff Kirsher etherh_reset(dev);
483644570b8SJeff Kirsher __ei_open(dev);
484644570b8SJeff Kirsher
485644570b8SJeff Kirsher return 0;
486644570b8SJeff Kirsher }
487644570b8SJeff Kirsher
488644570b8SJeff Kirsher /*
489644570b8SJeff Kirsher * The inverse routine to etherh_open().
490644570b8SJeff Kirsher */
491644570b8SJeff Kirsher static int
etherh_close(struct net_device * dev)492644570b8SJeff Kirsher etherh_close(struct net_device *dev)
493644570b8SJeff Kirsher {
494644570b8SJeff Kirsher __ei_close (dev);
495644570b8SJeff Kirsher free_irq (dev->irq, dev);
496644570b8SJeff Kirsher return 0;
497644570b8SJeff Kirsher }
498644570b8SJeff Kirsher
499644570b8SJeff Kirsher /*
500644570b8SJeff Kirsher * Read the ethernet address string from the on board rom.
501644570b8SJeff Kirsher * This is an ascii string...
502644570b8SJeff Kirsher */
etherh_addr(char * addr,struct expansion_card * ec)5034168ac0eSBill Pemberton static int etherh_addr(char *addr, struct expansion_card *ec)
504644570b8SJeff Kirsher {
505644570b8SJeff Kirsher struct in_chunk_dir cd;
506644570b8SJeff Kirsher char *s;
507644570b8SJeff Kirsher
508644570b8SJeff Kirsher if (!ecard_readchunk(&cd, ec, 0xf5, 0)) {
50994435f76SMasanari Iida printk(KERN_ERR "%s: unable to read module description string\n",
510644570b8SJeff Kirsher dev_name(&ec->dev));
511644570b8SJeff Kirsher goto no_addr;
512644570b8SJeff Kirsher }
513644570b8SJeff Kirsher
514644570b8SJeff Kirsher s = strchr(cd.d.string, '(');
515644570b8SJeff Kirsher if (s) {
516644570b8SJeff Kirsher int i;
517644570b8SJeff Kirsher
518644570b8SJeff Kirsher for (i = 0; i < 6; i++) {
519644570b8SJeff Kirsher addr[i] = simple_strtoul(s + 1, &s, 0x10);
520644570b8SJeff Kirsher if (*s != (i == 5? ')' : ':'))
521644570b8SJeff Kirsher break;
522644570b8SJeff Kirsher }
523644570b8SJeff Kirsher
524644570b8SJeff Kirsher if (i == 6)
525644570b8SJeff Kirsher return 0;
526644570b8SJeff Kirsher }
527644570b8SJeff Kirsher
528644570b8SJeff Kirsher printk(KERN_ERR "%s: unable to parse MAC address: %s\n",
529644570b8SJeff Kirsher dev_name(&ec->dev), cd.d.string);
530644570b8SJeff Kirsher
531644570b8SJeff Kirsher no_addr:
532644570b8SJeff Kirsher return -ENODEV;
533644570b8SJeff Kirsher }
534644570b8SJeff Kirsher
535644570b8SJeff Kirsher /*
536644570b8SJeff Kirsher * Create an ethernet address from the system serial number.
537644570b8SJeff Kirsher */
etherm_addr(char * addr)538644570b8SJeff Kirsher static int __init etherm_addr(char *addr)
539644570b8SJeff Kirsher {
540644570b8SJeff Kirsher unsigned int serial;
541644570b8SJeff Kirsher
542644570b8SJeff Kirsher if (system_serial_low == 0 && system_serial_high == 0)
543644570b8SJeff Kirsher return -ENODEV;
544644570b8SJeff Kirsher
545644570b8SJeff Kirsher serial = system_serial_low | system_serial_high;
546644570b8SJeff Kirsher
547644570b8SJeff Kirsher addr[0] = 0;
548644570b8SJeff Kirsher addr[1] = 0;
549644570b8SJeff Kirsher addr[2] = 0xa4;
550644570b8SJeff Kirsher addr[3] = 0x10 + (serial >> 24);
551644570b8SJeff Kirsher addr[4] = serial >> 16;
552644570b8SJeff Kirsher addr[5] = serial >> 8;
553644570b8SJeff Kirsher return 0;
554644570b8SJeff Kirsher }
555644570b8SJeff Kirsher
etherh_get_drvinfo(struct net_device * dev,struct ethtool_drvinfo * info)556644570b8SJeff Kirsher static void etherh_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
557644570b8SJeff Kirsher {
558*f029c781SWolfram Sang strscpy(info->driver, DRV_NAME, sizeof(info->driver));
559*f029c781SWolfram Sang strscpy(info->version, DRV_VERSION, sizeof(info->version));
560*f029c781SWolfram Sang strscpy(info->bus_info, dev_name(dev->dev.parent),
561644570b8SJeff Kirsher sizeof(info->bus_info));
562644570b8SJeff Kirsher }
563644570b8SJeff Kirsher
etherh_get_link_ksettings(struct net_device * dev,struct ethtool_link_ksettings * cmd)5646ce706a5SMichal Kubecek static int etherh_get_link_ksettings(struct net_device *dev,
5656ce706a5SMichal Kubecek struct ethtool_link_ksettings *cmd)
566644570b8SJeff Kirsher {
5676ce706a5SMichal Kubecek ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
5686ce706a5SMichal Kubecek etherh_priv(dev)->supported);
5696ce706a5SMichal Kubecek cmd->base.speed = SPEED_10;
5706ce706a5SMichal Kubecek cmd->base.duplex = DUPLEX_HALF;
5716ce706a5SMichal Kubecek cmd->base.port = dev->if_port == IF_PORT_10BASET ? PORT_TP : PORT_BNC;
5726ce706a5SMichal Kubecek cmd->base.autoneg = (dev->flags & IFF_AUTOMEDIA ? AUTONEG_ENABLE :
5736ce706a5SMichal Kubecek AUTONEG_DISABLE);
574644570b8SJeff Kirsher return 0;
575644570b8SJeff Kirsher }
576644570b8SJeff Kirsher
etherh_set_link_ksettings(struct net_device * dev,const struct ethtool_link_ksettings * cmd)5776ce706a5SMichal Kubecek static int etherh_set_link_ksettings(struct net_device *dev,
5786ce706a5SMichal Kubecek const struct ethtool_link_ksettings *cmd)
579644570b8SJeff Kirsher {
5806ce706a5SMichal Kubecek switch (cmd->base.autoneg) {
581644570b8SJeff Kirsher case AUTONEG_ENABLE:
582644570b8SJeff Kirsher dev->flags |= IFF_AUTOMEDIA;
583644570b8SJeff Kirsher break;
584644570b8SJeff Kirsher
585644570b8SJeff Kirsher case AUTONEG_DISABLE:
5866ce706a5SMichal Kubecek switch (cmd->base.port) {
587644570b8SJeff Kirsher case PORT_TP:
588644570b8SJeff Kirsher dev->if_port = IF_PORT_10BASET;
589644570b8SJeff Kirsher break;
590644570b8SJeff Kirsher
591644570b8SJeff Kirsher case PORT_BNC:
592644570b8SJeff Kirsher dev->if_port = IF_PORT_10BASE2;
593644570b8SJeff Kirsher break;
594644570b8SJeff Kirsher
595644570b8SJeff Kirsher default:
596644570b8SJeff Kirsher return -EINVAL;
597644570b8SJeff Kirsher }
598644570b8SJeff Kirsher dev->flags &= ~IFF_AUTOMEDIA;
599644570b8SJeff Kirsher break;
600644570b8SJeff Kirsher
601644570b8SJeff Kirsher default:
602644570b8SJeff Kirsher return -EINVAL;
603644570b8SJeff Kirsher }
604644570b8SJeff Kirsher
605644570b8SJeff Kirsher etherh_setif(dev);
606644570b8SJeff Kirsher
607644570b8SJeff Kirsher return 0;
608644570b8SJeff Kirsher }
609644570b8SJeff Kirsher
etherh_get_msglevel(struct net_device * dev)610c45f812fSMatthew Whitehead static u32 etherh_get_msglevel(struct net_device *dev)
611c45f812fSMatthew Whitehead {
612c45f812fSMatthew Whitehead struct ei_device *ei_local = netdev_priv(dev);
613c45f812fSMatthew Whitehead
614c45f812fSMatthew Whitehead return ei_local->msg_enable;
615c45f812fSMatthew Whitehead }
616c45f812fSMatthew Whitehead
etherh_set_msglevel(struct net_device * dev,u32 v)617c45f812fSMatthew Whitehead static void etherh_set_msglevel(struct net_device *dev, u32 v)
618c45f812fSMatthew Whitehead {
619c45f812fSMatthew Whitehead struct ei_device *ei_local = netdev_priv(dev);
620c45f812fSMatthew Whitehead
621c45f812fSMatthew Whitehead ei_local->msg_enable = v;
622c45f812fSMatthew Whitehead }
623c45f812fSMatthew Whitehead
624644570b8SJeff Kirsher static const struct ethtool_ops etherh_ethtool_ops = {
625644570b8SJeff Kirsher .get_drvinfo = etherh_get_drvinfo,
62665198be2SRichard Cochran .get_ts_info = ethtool_op_get_ts_info,
627c45f812fSMatthew Whitehead .get_msglevel = etherh_get_msglevel,
628c45f812fSMatthew Whitehead .set_msglevel = etherh_set_msglevel,
6296ce706a5SMichal Kubecek .get_link_ksettings = etherh_get_link_ksettings,
6306ce706a5SMichal Kubecek .set_link_ksettings = etherh_set_link_ksettings,
631644570b8SJeff Kirsher };
632644570b8SJeff Kirsher
633644570b8SJeff Kirsher static const struct net_device_ops etherh_netdev_ops = {
634644570b8SJeff Kirsher .ndo_open = etherh_open,
635644570b8SJeff Kirsher .ndo_stop = etherh_close,
636644570b8SJeff Kirsher .ndo_set_config = etherh_set_config,
637644570b8SJeff Kirsher .ndo_start_xmit = __ei_start_xmit,
638644570b8SJeff Kirsher .ndo_tx_timeout = __ei_tx_timeout,
639644570b8SJeff Kirsher .ndo_get_stats = __ei_get_stats,
640afc4b13dSJiri Pirko .ndo_set_rx_mode = __ei_set_multicast_list,
641644570b8SJeff Kirsher .ndo_validate_addr = eth_validate_addr,
642644570b8SJeff Kirsher .ndo_set_mac_address = eth_mac_addr,
643644570b8SJeff Kirsher #ifdef CONFIG_NET_POLL_CONTROLLER
644644570b8SJeff Kirsher .ndo_poll_controller = __ei_poll,
645644570b8SJeff Kirsher #endif
646644570b8SJeff Kirsher };
647644570b8SJeff Kirsher
648644570b8SJeff Kirsher static u32 etherh_regoffsets[16];
649644570b8SJeff Kirsher static u32 etherm_regoffsets[16];
650644570b8SJeff Kirsher
6514168ac0eSBill Pemberton static int
etherh_probe(struct expansion_card * ec,const struct ecard_id * id)652644570b8SJeff Kirsher etherh_probe(struct expansion_card *ec, const struct ecard_id *id)
653644570b8SJeff Kirsher {
654644570b8SJeff Kirsher const struct etherh_data *data = id->data;
655644570b8SJeff Kirsher struct ei_device *ei_local;
656644570b8SJeff Kirsher struct net_device *dev;
657644570b8SJeff Kirsher struct etherh_priv *eh;
6585518c524SJakub Kicinski u8 addr[ETH_ALEN];
659644570b8SJeff Kirsher int ret;
660644570b8SJeff Kirsher
661644570b8SJeff Kirsher ret = ecard_request_resources(ec);
662644570b8SJeff Kirsher if (ret)
663644570b8SJeff Kirsher goto out;
664644570b8SJeff Kirsher
665644570b8SJeff Kirsher dev = ____alloc_ei_netdev(sizeof(struct etherh_priv));
666644570b8SJeff Kirsher if (!dev) {
667644570b8SJeff Kirsher ret = -ENOMEM;
668644570b8SJeff Kirsher goto release;
669644570b8SJeff Kirsher }
670644570b8SJeff Kirsher
671644570b8SJeff Kirsher SET_NETDEV_DEV(dev, &ec->dev);
672644570b8SJeff Kirsher
673644570b8SJeff Kirsher dev->netdev_ops = ðerh_netdev_ops;
674644570b8SJeff Kirsher dev->irq = ec->irq;
675644570b8SJeff Kirsher dev->ethtool_ops = ðerh_ethtool_ops;
676644570b8SJeff Kirsher
677644570b8SJeff Kirsher if (data->supported & SUPPORTED_Autoneg)
678644570b8SJeff Kirsher dev->flags |= IFF_AUTOMEDIA;
679644570b8SJeff Kirsher if (data->supported & SUPPORTED_TP) {
680644570b8SJeff Kirsher dev->flags |= IFF_PORTSEL;
681644570b8SJeff Kirsher dev->if_port = IF_PORT_10BASET;
682644570b8SJeff Kirsher } else if (data->supported & SUPPORTED_BNC) {
683644570b8SJeff Kirsher dev->flags |= IFF_PORTSEL;
684644570b8SJeff Kirsher dev->if_port = IF_PORT_10BASE2;
685644570b8SJeff Kirsher } else
686644570b8SJeff Kirsher dev->if_port = IF_PORT_UNKNOWN;
687644570b8SJeff Kirsher
688644570b8SJeff Kirsher eh = etherh_priv(dev);
689644570b8SJeff Kirsher eh->supported = data->supported;
690644570b8SJeff Kirsher eh->ctrl = 0;
691644570b8SJeff Kirsher eh->id = ec->cid.product;
692644570b8SJeff Kirsher eh->memc = ecardm_iomap(ec, ECARD_RES_MEMC, 0, PAGE_SIZE);
693644570b8SJeff Kirsher if (!eh->memc) {
694644570b8SJeff Kirsher ret = -ENOMEM;
695644570b8SJeff Kirsher goto free;
696644570b8SJeff Kirsher }
697644570b8SJeff Kirsher
698644570b8SJeff Kirsher eh->ctrl_port = eh->memc;
699644570b8SJeff Kirsher if (data->ctrl_ioc) {
700644570b8SJeff Kirsher eh->ioc_fast = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, PAGE_SIZE);
701644570b8SJeff Kirsher if (!eh->ioc_fast) {
702644570b8SJeff Kirsher ret = -ENOMEM;
703644570b8SJeff Kirsher goto free;
704644570b8SJeff Kirsher }
705644570b8SJeff Kirsher eh->ctrl_port = eh->ioc_fast;
706644570b8SJeff Kirsher }
707644570b8SJeff Kirsher
708644570b8SJeff Kirsher dev->base_addr = (unsigned long)eh->memc + data->ns8390_offset;
709644570b8SJeff Kirsher eh->dma_base = eh->memc + data->dataport_offset;
710644570b8SJeff Kirsher eh->ctrl_port += data->ctrlport_offset;
711644570b8SJeff Kirsher
712644570b8SJeff Kirsher /*
713644570b8SJeff Kirsher * IRQ and control port handling - only for non-NIC slot cards.
714644570b8SJeff Kirsher */
715644570b8SJeff Kirsher if (ec->slot_no != 8) {
716644570b8SJeff Kirsher ecard_setirq(ec, ðerh_ops, eh);
717644570b8SJeff Kirsher } else {
718644570b8SJeff Kirsher /*
719644570b8SJeff Kirsher * If we're in the NIC slot, make sure the IRQ is enabled
720644570b8SJeff Kirsher */
721644570b8SJeff Kirsher etherh_set_ctrl(eh, ETHERH_CP_IE);
722644570b8SJeff Kirsher }
723644570b8SJeff Kirsher
724644570b8SJeff Kirsher ei_local = netdev_priv(dev);
725644570b8SJeff Kirsher spin_lock_init(&ei_local->page_lock);
726644570b8SJeff Kirsher
727644570b8SJeff Kirsher if (ec->cid.product == PROD_ANT_ETHERM) {
7285518c524SJakub Kicinski etherm_addr(addr);
729644570b8SJeff Kirsher ei_local->reg_offset = etherm_regoffsets;
730644570b8SJeff Kirsher } else {
7315518c524SJakub Kicinski etherh_addr(addr, ec);
732644570b8SJeff Kirsher ei_local->reg_offset = etherh_regoffsets;
733644570b8SJeff Kirsher }
7345518c524SJakub Kicinski eth_hw_addr_set(dev, addr);
735644570b8SJeff Kirsher
736644570b8SJeff Kirsher ei_local->name = dev->name;
737644570b8SJeff Kirsher ei_local->word16 = 1;
738644570b8SJeff Kirsher ei_local->tx_start_page = data->tx_start_page;
739644570b8SJeff Kirsher ei_local->rx_start_page = ei_local->tx_start_page + TX_PAGES;
740644570b8SJeff Kirsher ei_local->stop_page = data->stop_page;
741644570b8SJeff Kirsher ei_local->reset_8390 = etherh_reset;
742644570b8SJeff Kirsher ei_local->block_input = etherh_block_input;
743644570b8SJeff Kirsher ei_local->block_output = etherh_block_output;
744644570b8SJeff Kirsher ei_local->get_8390_hdr = etherh_get_header;
745644570b8SJeff Kirsher ei_local->interface_num = 0;
746644570b8SJeff Kirsher
747644570b8SJeff Kirsher etherh_reset(dev);
748644570b8SJeff Kirsher __NS8390_init(dev, 0);
749644570b8SJeff Kirsher
750644570b8SJeff Kirsher ret = register_netdev(dev);
751644570b8SJeff Kirsher if (ret)
752644570b8SJeff Kirsher goto free;
753644570b8SJeff Kirsher
754c45f812fSMatthew Whitehead netdev_info(dev, "%s in slot %d, %pM\n",
755c45f812fSMatthew Whitehead data->name, ec->slot_no, dev->dev_addr);
756644570b8SJeff Kirsher
757644570b8SJeff Kirsher ecard_set_drvdata(ec, dev);
758644570b8SJeff Kirsher
759644570b8SJeff Kirsher return 0;
760644570b8SJeff Kirsher
761644570b8SJeff Kirsher free:
762644570b8SJeff Kirsher free_netdev(dev);
763644570b8SJeff Kirsher release:
764644570b8SJeff Kirsher ecard_release_resources(ec);
765644570b8SJeff Kirsher out:
766644570b8SJeff Kirsher return ret;
767644570b8SJeff Kirsher }
768644570b8SJeff Kirsher
etherh_remove(struct expansion_card * ec)7694168ac0eSBill Pemberton static void etherh_remove(struct expansion_card *ec)
770644570b8SJeff Kirsher {
771644570b8SJeff Kirsher struct net_device *dev = ecard_get_drvdata(ec);
772644570b8SJeff Kirsher
773644570b8SJeff Kirsher ecard_set_drvdata(ec, NULL);
774644570b8SJeff Kirsher
775644570b8SJeff Kirsher unregister_netdev(dev);
776644570b8SJeff Kirsher
777644570b8SJeff Kirsher free_netdev(dev);
778644570b8SJeff Kirsher
779644570b8SJeff Kirsher ecard_release_resources(ec);
780644570b8SJeff Kirsher }
781644570b8SJeff Kirsher
782644570b8SJeff Kirsher static struct etherh_data etherm_data = {
783644570b8SJeff Kirsher .ns8390_offset = ETHERM_NS8390,
784644570b8SJeff Kirsher .dataport_offset = ETHERM_NS8390 + ETHERM_DATAPORT,
785644570b8SJeff Kirsher .ctrlport_offset = ETHERM_NS8390 + ETHERM_CTRLPORT,
786644570b8SJeff Kirsher .name = "ANT EtherM",
787644570b8SJeff Kirsher .supported = SUPPORTED_10baseT_Half,
788644570b8SJeff Kirsher .tx_start_page = ETHERM_TX_START_PAGE,
789644570b8SJeff Kirsher .stop_page = ETHERM_STOP_PAGE,
790644570b8SJeff Kirsher };
791644570b8SJeff Kirsher
792644570b8SJeff Kirsher static struct etherh_data etherlan500_data = {
793644570b8SJeff Kirsher .ns8390_offset = ETHERH500_NS8390,
794644570b8SJeff Kirsher .dataport_offset = ETHERH500_NS8390 + ETHERH500_DATAPORT,
795644570b8SJeff Kirsher .ctrlport_offset = ETHERH500_CTRLPORT,
796644570b8SJeff Kirsher .ctrl_ioc = 1,
797644570b8SJeff Kirsher .name = "i3 EtherH 500",
798644570b8SJeff Kirsher .supported = SUPPORTED_10baseT_Half,
799644570b8SJeff Kirsher .tx_start_page = ETHERH_TX_START_PAGE,
800644570b8SJeff Kirsher .stop_page = ETHERH_STOP_PAGE,
801644570b8SJeff Kirsher };
802644570b8SJeff Kirsher
803644570b8SJeff Kirsher static struct etherh_data etherlan600_data = {
804644570b8SJeff Kirsher .ns8390_offset = ETHERH600_NS8390,
805644570b8SJeff Kirsher .dataport_offset = ETHERH600_NS8390 + ETHERH600_DATAPORT,
806644570b8SJeff Kirsher .ctrlport_offset = ETHERH600_NS8390 + ETHERH600_CTRLPORT,
807644570b8SJeff Kirsher .name = "i3 EtherH 600",
808644570b8SJeff Kirsher .supported = SUPPORTED_10baseT_Half | SUPPORTED_TP | SUPPORTED_BNC | SUPPORTED_Autoneg,
809644570b8SJeff Kirsher .tx_start_page = ETHERH_TX_START_PAGE,
810644570b8SJeff Kirsher .stop_page = ETHERH_STOP_PAGE,
811644570b8SJeff Kirsher };
812644570b8SJeff Kirsher
813644570b8SJeff Kirsher static struct etherh_data etherlan600a_data = {
814644570b8SJeff Kirsher .ns8390_offset = ETHERH600_NS8390,
815644570b8SJeff Kirsher .dataport_offset = ETHERH600_NS8390 + ETHERH600_DATAPORT,
816644570b8SJeff Kirsher .ctrlport_offset = ETHERH600_NS8390 + ETHERH600_CTRLPORT,
817644570b8SJeff Kirsher .name = "i3 EtherH 600A",
818644570b8SJeff Kirsher .supported = SUPPORTED_10baseT_Half | SUPPORTED_TP | SUPPORTED_BNC | SUPPORTED_Autoneg,
819644570b8SJeff Kirsher .tx_start_page = ETHERH_TX_START_PAGE,
820644570b8SJeff Kirsher .stop_page = ETHERH_STOP_PAGE,
821644570b8SJeff Kirsher };
822644570b8SJeff Kirsher
823644570b8SJeff Kirsher static const struct ecard_id etherh_ids[] = {
824644570b8SJeff Kirsher { MANU_ANT, PROD_ANT_ETHERM, ðerm_data },
825644570b8SJeff Kirsher { MANU_I3, PROD_I3_ETHERLAN500, ðerlan500_data },
826644570b8SJeff Kirsher { MANU_I3, PROD_I3_ETHERLAN600, ðerlan600_data },
827644570b8SJeff Kirsher { MANU_I3, PROD_I3_ETHERLAN600A, ðerlan600a_data },
828644570b8SJeff Kirsher { 0xffff, 0xffff }
829644570b8SJeff Kirsher };
830644570b8SJeff Kirsher
831644570b8SJeff Kirsher static struct ecard_driver etherh_driver = {
832644570b8SJeff Kirsher .probe = etherh_probe,
8334168ac0eSBill Pemberton .remove = etherh_remove,
834644570b8SJeff Kirsher .id_table = etherh_ids,
835644570b8SJeff Kirsher .drv = {
836644570b8SJeff Kirsher .name = DRV_NAME,
837644570b8SJeff Kirsher },
838644570b8SJeff Kirsher };
839644570b8SJeff Kirsher
etherh_init(void)840644570b8SJeff Kirsher static int __init etherh_init(void)
841644570b8SJeff Kirsher {
842644570b8SJeff Kirsher int i;
843644570b8SJeff Kirsher
844644570b8SJeff Kirsher for (i = 0; i < 16; i++) {
845644570b8SJeff Kirsher etherh_regoffsets[i] = i << 2;
846644570b8SJeff Kirsher etherm_regoffsets[i] = i << 5;
847644570b8SJeff Kirsher }
848644570b8SJeff Kirsher
849644570b8SJeff Kirsher return ecard_register_driver(ðerh_driver);
850644570b8SJeff Kirsher }
851644570b8SJeff Kirsher
etherh_exit(void)852644570b8SJeff Kirsher static void __exit etherh_exit(void)
853644570b8SJeff Kirsher {
854644570b8SJeff Kirsher ecard_remove_driver(ðerh_driver);
855644570b8SJeff Kirsher }
856644570b8SJeff Kirsher
857644570b8SJeff Kirsher module_init(etherh_init);
858644570b8SJeff Kirsher module_exit(etherh_exit);
859