Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /*====================================================================== |
2 | ||
3 | A PCMCIA ethernet driver for Asix AX88190-based cards | |
4 | ||
5 | The Asix AX88190 is a NS8390-derived chipset with a few nasty | |
6 | idiosyncracies that make it very inconvenient to support with a | |
7 | standard 8390 driver. This driver is based on pcnet_cs, with the | |
8 | tweaked 8390 code grafted on the end. Much of what I did was to | |
9 | clean up and update a similar driver supplied by Asix, which was | |
10 | adapted by William Lee, william@asix.com.tw. | |
11 | ||
12 | Copyright (C) 2001 David A. Hinds -- dahinds@users.sourceforge.net | |
13 | ||
14 | axnet_cs.c 1.28 2002/06/29 06:27:37 | |
15 | ||
16 | The network driver code is based on Donald Becker's NE2000 code: | |
17 | ||
18 | Written 1992,1993 by Donald Becker. | |
19 | Copyright 1993 United States Government as represented by the | |
20 | Director, National Security Agency. This software may be used and | |
21 | distributed according to the terms of the GNU General Public License, | |
22 | incorporated herein by reference. | |
23 | Donald Becker may be reached at becker@scyld.com | |
24 | ||
25 | ======================================================================*/ | |
26 | ||
27 | #include <linux/kernel.h> | |
28 | #include <linux/module.h> | |
29 | #include <linux/init.h> | |
30 | #include <linux/ptrace.h> | |
31 | #include <linux/slab.h> | |
32 | #include <linux/string.h> | |
33 | #include <linux/timer.h> | |
34 | #include <linux/delay.h> | |
35 | #include <linux/spinlock.h> | |
36 | #include <linux/ethtool.h> | |
37 | #include <linux/netdevice.h> | |
38 | #include "../8390.h" | |
39 | ||
1da177e4 LT |
40 | #include <pcmcia/cs_types.h> |
41 | #include <pcmcia/cs.h> | |
42 | #include <pcmcia/cistpl.h> | |
43 | #include <pcmcia/ciscode.h> | |
44 | #include <pcmcia/ds.h> | |
45 | #include <pcmcia/cisreg.h> | |
46 | ||
47 | #include <asm/io.h> | |
48 | #include <asm/system.h> | |
49 | #include <asm/byteorder.h> | |
50 | #include <asm/uaccess.h> | |
51 | ||
52 | #define AXNET_CMD 0x00 | |
53 | #define AXNET_DATAPORT 0x10 /* NatSemi-defined port window offset. */ | |
54 | #define AXNET_RESET 0x1f /* Issue a read to reset, a write to clear. */ | |
55 | #define AXNET_MII_EEP 0x14 /* Offset of MII access port */ | |
56 | #define AXNET_TEST 0x15 /* Offset of TEST Register port */ | |
57 | #define AXNET_GPIO 0x17 /* Offset of General Purpose Register Port */ | |
58 | ||
59 | #define AXNET_START_PG 0x40 /* First page of TX buffer */ | |
60 | #define AXNET_STOP_PG 0x80 /* Last page +1 of RX ring */ | |
61 | ||
62 | #define AXNET_RDC_TIMEOUT 0x02 /* Max wait in jiffies for Tx RDC */ | |
63 | ||
64 | #define IS_AX88190 0x0001 | |
65 | #define IS_AX88790 0x0002 | |
66 | ||
67 | /*====================================================================*/ | |
68 | ||
69 | /* Module parameters */ | |
70 | ||
71 | MODULE_AUTHOR("David Hinds <dahinds@users.sourceforge.net>"); | |
72 | MODULE_DESCRIPTION("Asix AX88190 PCMCIA ethernet driver"); | |
73 | MODULE_LICENSE("GPL"); | |
74 | ||
75 | #ifdef PCMCIA_DEBUG | |
76 | #define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0) | |
77 | ||
78 | INT_MODULE_PARM(pc_debug, PCMCIA_DEBUG); | |
79 | #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args) | |
80 | static char *version = | |
81 | "axnet_cs.c 1.28 2002/06/29 06:27:37 (David Hinds)"; | |
82 | #else | |
83 | #define DEBUG(n, args...) | |
84 | #endif | |
85 | ||
86 | /*====================================================================*/ | |
87 | ||
88 | static void axnet_config(dev_link_t *link); | |
89 | static void axnet_release(dev_link_t *link); | |
90 | static int axnet_event(event_t event, int priority, | |
91 | event_callback_args_t *args); | |
92 | static int axnet_open(struct net_device *dev); | |
93 | static int axnet_close(struct net_device *dev); | |
94 | static int axnet_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); | |
95 | static struct ethtool_ops netdev_ethtool_ops; | |
96 | static irqreturn_t ei_irq_wrapper(int irq, void *dev_id, struct pt_regs *regs); | |
97 | static void ei_watchdog(u_long arg); | |
98 | static void axnet_reset_8390(struct net_device *dev); | |
99 | ||
100 | static int mdio_read(kio_addr_t addr, int phy_id, int loc); | |
101 | static void mdio_write(kio_addr_t addr, int phy_id, int loc, int value); | |
102 | ||
103 | static void get_8390_hdr(struct net_device *, | |
104 | struct e8390_pkt_hdr *, int); | |
105 | static void block_input(struct net_device *dev, int count, | |
106 | struct sk_buff *skb, int ring_offset); | |
107 | static void block_output(struct net_device *dev, int count, | |
108 | const u_char *buf, const int start_page); | |
109 | ||
110 | static dev_link_t *axnet_attach(void); | |
cc3b4866 | 111 | static void axnet_detach(struct pcmcia_device *p_dev); |
1da177e4 LT |
112 | |
113 | static dev_info_t dev_info = "axnet_cs"; | |
1da177e4 LT |
114 | |
115 | static void axdev_setup(struct net_device *dev); | |
116 | static void AX88190_init(struct net_device *dev, int startp); | |
117 | static int ax_open(struct net_device *dev); | |
118 | static int ax_close(struct net_device *dev); | |
119 | static irqreturn_t ax_interrupt(int irq, void *dev_id, struct pt_regs *regs); | |
120 | ||
121 | /*====================================================================*/ | |
122 | ||
123 | typedef struct axnet_dev_t { | |
124 | dev_link_t link; | |
125 | dev_node_t node; | |
126 | caddr_t base; | |
127 | struct timer_list watchdog; | |
128 | int stale, fast_poll; | |
129 | u_short link_status; | |
130 | u_char duplex_flag; | |
131 | int phy_id; | |
132 | int flags; | |
133 | } axnet_dev_t; | |
134 | ||
135 | static inline axnet_dev_t *PRIV(struct net_device *dev) | |
136 | { | |
137 | void *p = (char *)netdev_priv(dev) + sizeof(struct ei_device); | |
138 | return p; | |
139 | } | |
140 | ||
141 | /*====================================================================== | |
142 | ||
143 | axnet_attach() creates an "instance" of the driver, allocating | |
144 | local data structures for one device. The device is registered | |
145 | with Card Services. | |
146 | ||
147 | ======================================================================*/ | |
148 | ||
149 | static dev_link_t *axnet_attach(void) | |
150 | { | |
151 | axnet_dev_t *info; | |
152 | dev_link_t *link; | |
153 | struct net_device *dev; | |
154 | client_reg_t client_reg; | |
155 | int ret; | |
156 | ||
157 | DEBUG(0, "axnet_attach()\n"); | |
158 | ||
159 | dev = alloc_netdev(sizeof(struct ei_device) + sizeof(axnet_dev_t), | |
160 | "eth%d", axdev_setup); | |
161 | ||
162 | if (!dev) | |
163 | return NULL; | |
164 | ||
165 | info = PRIV(dev); | |
166 | link = &info->link; | |
167 | link->priv = dev; | |
168 | link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; | |
169 | link->irq.IRQInfo1 = IRQ_LEVEL_ID; | |
170 | link->conf.Attributes = CONF_ENABLE_IRQ; | |
171 | link->conf.IntType = INT_MEMORY_AND_IO; | |
172 | ||
173 | dev->open = &axnet_open; | |
174 | dev->stop = &axnet_close; | |
175 | dev->do_ioctl = &axnet_ioctl; | |
176 | SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops); | |
177 | ||
178 | /* Register with Card Services */ | |
b4635811 | 179 | link->next = NULL; |
1da177e4 | 180 | client_reg.dev_info = &dev_info; |
1da177e4 LT |
181 | client_reg.Version = 0x0210; |
182 | client_reg.event_callback_args.client_data = link; | |
183 | ret = pcmcia_register_client(&link->handle, &client_reg); | |
184 | if (ret != CS_SUCCESS) { | |
185 | cs_error(link->handle, RegisterClient, ret); | |
cc3b4866 | 186 | axnet_detach(link->handle); |
1da177e4 LT |
187 | return NULL; |
188 | } | |
189 | ||
190 | return link; | |
191 | } /* axnet_attach */ | |
192 | ||
193 | /*====================================================================== | |
194 | ||
195 | This deletes a driver "instance". The device is de-registered | |
196 | with Card Services. If it has been released, all local data | |
197 | structures are freed. Otherwise, the structures will be freed | |
198 | when the device is released. | |
199 | ||
200 | ======================================================================*/ | |
201 | ||
cc3b4866 | 202 | static void axnet_detach(struct pcmcia_device *p_dev) |
1da177e4 | 203 | { |
cc3b4866 | 204 | dev_link_t *link = dev_to_instance(p_dev); |
1da177e4 | 205 | struct net_device *dev = link->priv; |
1da177e4 LT |
206 | |
207 | DEBUG(0, "axnet_detach(0x%p)\n", link); | |
208 | ||
1da177e4 LT |
209 | if (link->dev) |
210 | unregister_netdev(dev); | |
211 | ||
212 | if (link->state & DEV_CONFIG) | |
213 | axnet_release(link); | |
214 | ||
1da177e4 LT |
215 | free_netdev(dev); |
216 | } /* axnet_detach */ | |
217 | ||
218 | /*====================================================================== | |
219 | ||
220 | This probes for a card's hardware address by reading the PROM. | |
221 | ||
222 | ======================================================================*/ | |
223 | ||
224 | static int get_prom(dev_link_t *link) | |
225 | { | |
226 | struct net_device *dev = link->priv; | |
227 | kio_addr_t ioaddr = dev->base_addr; | |
228 | int i, j; | |
229 | ||
230 | /* This is based on drivers/net/ne.c */ | |
231 | struct { | |
232 | u_char value, offset; | |
233 | } program_seq[] = { | |
234 | {E8390_NODMA+E8390_PAGE0+E8390_STOP, E8390_CMD}, /* Select page 0*/ | |
235 | {0x01, EN0_DCFG}, /* Set word-wide access. */ | |
236 | {0x00, EN0_RCNTLO}, /* Clear the count regs. */ | |
237 | {0x00, EN0_RCNTHI}, | |
238 | {0x00, EN0_IMR}, /* Mask completion irq. */ | |
239 | {0xFF, EN0_ISR}, | |
240 | {E8390_RXOFF|0x40, EN0_RXCR}, /* 0x60 Set to monitor */ | |
241 | {E8390_TXOFF, EN0_TXCR}, /* 0x02 and loopback mode. */ | |
242 | {0x10, EN0_RCNTLO}, | |
243 | {0x00, EN0_RCNTHI}, | |
244 | {0x00, EN0_RSARLO}, /* DMA starting at 0x0400. */ | |
245 | {0x04, EN0_RSARHI}, | |
246 | {E8390_RREAD+E8390_START, E8390_CMD}, | |
247 | }; | |
248 | ||
249 | /* Not much of a test, but the alternatives are messy */ | |
250 | if (link->conf.ConfigBase != 0x03c0) | |
251 | return 0; | |
252 | ||
253 | axnet_reset_8390(dev); | |
254 | mdelay(10); | |
255 | ||
256 | for (i = 0; i < sizeof(program_seq)/sizeof(program_seq[0]); i++) | |
257 | outb_p(program_seq[i].value, ioaddr + program_seq[i].offset); | |
258 | ||
259 | for (i = 0; i < 6; i += 2) { | |
260 | j = inw(ioaddr + AXNET_DATAPORT); | |
261 | dev->dev_addr[i] = j & 0xff; | |
262 | dev->dev_addr[i+1] = j >> 8; | |
263 | } | |
264 | return 1; | |
265 | } /* get_prom */ | |
266 | ||
267 | /*====================================================================== | |
268 | ||
269 | axnet_config() is scheduled to run after a CARD_INSERTION event | |
270 | is received, to configure the PCMCIA socket, and to make the | |
271 | ethernet device available to the system. | |
272 | ||
273 | ======================================================================*/ | |
274 | ||
275 | #define CS_CHECK(fn, ret) \ | |
276 | do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) | |
277 | ||
278 | static int try_io_port(dev_link_t *link) | |
279 | { | |
280 | int j, ret; | |
281 | if (link->io.NumPorts1 == 32) { | |
282 | link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; | |
283 | if (link->io.NumPorts2 > 0) { | |
284 | /* for master/slave multifunction cards */ | |
285 | link->io.Attributes2 = IO_DATA_PATH_WIDTH_8; | |
286 | link->irq.Attributes = | |
287 | IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED; | |
288 | } | |
289 | } else { | |
290 | /* This should be two 16-port windows */ | |
291 | link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; | |
292 | link->io.Attributes2 = IO_DATA_PATH_WIDTH_16; | |
293 | } | |
294 | if (link->io.BasePort1 == 0) { | |
295 | link->io.IOAddrLines = 16; | |
296 | for (j = 0; j < 0x400; j += 0x20) { | |
297 | link->io.BasePort1 = j ^ 0x300; | |
298 | link->io.BasePort2 = (j ^ 0x300) + 0x10; | |
299 | ret = pcmcia_request_io(link->handle, &link->io); | |
300 | if (ret == CS_SUCCESS) return ret; | |
301 | } | |
302 | return ret; | |
303 | } else { | |
304 | return pcmcia_request_io(link->handle, &link->io); | |
305 | } | |
306 | } | |
307 | ||
308 | static void axnet_config(dev_link_t *link) | |
309 | { | |
310 | client_handle_t handle = link->handle; | |
311 | struct net_device *dev = link->priv; | |
312 | axnet_dev_t *info = PRIV(dev); | |
313 | tuple_t tuple; | |
314 | cisparse_t parse; | |
315 | int i, j, last_ret, last_fn; | |
316 | u_short buf[64]; | |
317 | config_info_t conf; | |
318 | ||
319 | DEBUG(0, "axnet_config(0x%p)\n", link); | |
320 | ||
321 | tuple.Attributes = 0; | |
322 | tuple.TupleData = (cisdata_t *)buf; | |
323 | tuple.TupleDataMax = sizeof(buf); | |
324 | tuple.TupleOffset = 0; | |
325 | tuple.DesiredTuple = CISTPL_CONFIG; | |
326 | CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); | |
327 | CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); | |
328 | CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); | |
329 | link->conf.ConfigBase = parse.config.base; | |
330 | /* don't trust the CIS on this; Linksys got it wrong */ | |
331 | link->conf.Present = 0x63; | |
332 | ||
333 | /* Configure card */ | |
334 | link->state |= DEV_CONFIG; | |
335 | ||
336 | /* Look up current Vcc */ | |
337 | CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(handle, &conf)); | |
338 | link->conf.Vcc = conf.Vcc; | |
339 | ||
340 | tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; | |
341 | tuple.Attributes = 0; | |
342 | CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); | |
343 | while (last_ret == CS_SUCCESS) { | |
344 | cistpl_cftable_entry_t *cfg = &(parse.cftable_entry); | |
345 | cistpl_io_t *io = &(parse.cftable_entry.io); | |
346 | ||
347 | if (pcmcia_get_tuple_data(handle, &tuple) != 0 || | |
348 | pcmcia_parse_tuple(handle, &tuple, &parse) != 0 || | |
349 | cfg->index == 0 || cfg->io.nwin == 0) | |
350 | goto next_entry; | |
351 | ||
352 | link->conf.ConfigIndex = 0x05; | |
353 | /* For multifunction cards, by convention, we configure the | |
354 | network function with window 0, and serial with window 1 */ | |
355 | if (io->nwin > 1) { | |
356 | i = (io->win[1].len > io->win[0].len); | |
357 | link->io.BasePort2 = io->win[1-i].base; | |
358 | link->io.NumPorts2 = io->win[1-i].len; | |
359 | } else { | |
360 | i = link->io.NumPorts2 = 0; | |
361 | } | |
362 | link->io.BasePort1 = io->win[i].base; | |
363 | link->io.NumPorts1 = io->win[i].len; | |
364 | link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK; | |
365 | if (link->io.NumPorts1 + link->io.NumPorts2 >= 32) { | |
366 | last_ret = try_io_port(link); | |
367 | if (last_ret == CS_SUCCESS) break; | |
368 | } | |
369 | next_entry: | |
370 | last_ret = pcmcia_get_next_tuple(handle, &tuple); | |
371 | } | |
372 | if (last_ret != CS_SUCCESS) { | |
373 | cs_error(handle, RequestIO, last_ret); | |
374 | goto failed; | |
375 | } | |
376 | ||
377 | CS_CHECK(RequestIRQ, pcmcia_request_irq(handle, &link->irq)); | |
378 | ||
379 | if (link->io.NumPorts2 == 8) { | |
380 | link->conf.Attributes |= CONF_ENABLE_SPKR; | |
381 | link->conf.Status = CCSR_AUDIO_ENA; | |
382 | } | |
383 | ||
384 | CS_CHECK(RequestConfiguration, pcmcia_request_configuration(handle, &link->conf)); | |
385 | dev->irq = link->irq.AssignedIRQ; | |
386 | dev->base_addr = link->io.BasePort1; | |
387 | ||
388 | if (!get_prom(link)) { | |
389 | printk(KERN_NOTICE "axnet_cs: this is not an AX88190 card!\n"); | |
390 | printk(KERN_NOTICE "axnet_cs: use pcnet_cs instead.\n"); | |
391 | goto failed; | |
392 | } | |
393 | ||
394 | ei_status.name = "AX88190"; | |
395 | ei_status.word16 = 1; | |
396 | ei_status.tx_start_page = AXNET_START_PG; | |
397 | ei_status.rx_start_page = AXNET_START_PG + TX_PAGES; | |
398 | ei_status.stop_page = AXNET_STOP_PG; | |
399 | ei_status.reset_8390 = &axnet_reset_8390; | |
400 | ei_status.get_8390_hdr = &get_8390_hdr; | |
401 | ei_status.block_input = &block_input; | |
402 | ei_status.block_output = &block_output; | |
403 | ||
404 | if (inb(dev->base_addr + AXNET_TEST) != 0) | |
405 | info->flags |= IS_AX88790; | |
406 | else | |
407 | info->flags |= IS_AX88190; | |
408 | ||
409 | if (info->flags & IS_AX88790) | |
410 | outb(0x10, dev->base_addr + AXNET_GPIO); /* select Internal PHY */ | |
411 | ||
412 | for (i = 0; i < 32; i++) { | |
413 | j = mdio_read(dev->base_addr + AXNET_MII_EEP, i, 1); | |
414 | if ((j != 0) && (j != 0xffff)) break; | |
415 | } | |
416 | ||
417 | /* Maybe PHY is in power down mode. (PPD_SET = 1) | |
418 | Bit 2 of CCSR is active low. */ | |
419 | if (i == 32) { | |
420 | conf_reg_t reg = { 0, CS_WRITE, CISREG_CCSR, 0x04 }; | |
421 | pcmcia_access_configuration_register(link->handle, ®); | |
422 | for (i = 0; i < 32; i++) { | |
423 | j = mdio_read(dev->base_addr + AXNET_MII_EEP, i, 1); | |
424 | if ((j != 0) && (j != 0xffff)) break; | |
425 | } | |
426 | } | |
427 | ||
428 | info->phy_id = (i < 32) ? i : -1; | |
429 | link->dev = &info->node; | |
430 | link->state &= ~DEV_CONFIG_PENDING; | |
431 | SET_NETDEV_DEV(dev, &handle_to_dev(handle)); | |
432 | ||
433 | if (register_netdev(dev) != 0) { | |
434 | printk(KERN_NOTICE "axnet_cs: register_netdev() failed\n"); | |
435 | link->dev = NULL; | |
436 | goto failed; | |
437 | } | |
438 | ||
439 | strcpy(info->node.dev_name, dev->name); | |
440 | ||
441 | printk(KERN_INFO "%s: Asix AX88%d90: io %#3lx, irq %d, hw_addr ", | |
442 | dev->name, ((info->flags & IS_AX88790) ? 7 : 1), | |
443 | dev->base_addr, dev->irq); | |
444 | for (i = 0; i < 6; i++) | |
445 | printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n")); | |
446 | if (info->phy_id != -1) { | |
447 | DEBUG(0, " MII transceiver at index %d, status %x.\n", info->phy_id, j); | |
448 | } else { | |
449 | printk(KERN_NOTICE " No MII transceivers found!\n"); | |
450 | } | |
451 | return; | |
452 | ||
453 | cs_failed: | |
454 | cs_error(link->handle, last_fn, last_ret); | |
455 | failed: | |
456 | axnet_release(link); | |
457 | link->state &= ~DEV_CONFIG_PENDING; | |
458 | return; | |
459 | } /* axnet_config */ | |
460 | ||
461 | /*====================================================================== | |
462 | ||
463 | After a card is removed, axnet_release() will unregister the net | |
464 | device, and release the PCMCIA configuration. If the device is | |
465 | still open, this will be postponed until it is closed. | |
466 | ||
467 | ======================================================================*/ | |
468 | ||
469 | static void axnet_release(dev_link_t *link) | |
470 | { | |
471 | DEBUG(0, "axnet_release(0x%p)\n", link); | |
472 | ||
473 | pcmcia_release_configuration(link->handle); | |
474 | pcmcia_release_io(link->handle, &link->io); | |
475 | pcmcia_release_irq(link->handle, &link->irq); | |
476 | ||
477 | link->state &= ~DEV_CONFIG; | |
478 | } | |
479 | ||
98e4c28b DB |
480 | static int axnet_suspend(struct pcmcia_device *p_dev) |
481 | { | |
482 | dev_link_t *link = dev_to_instance(p_dev); | |
483 | struct net_device *dev = link->priv; | |
484 | ||
485 | link->state |= DEV_SUSPEND; | |
486 | if (link->state & DEV_CONFIG) { | |
487 | if (link->open) | |
488 | netif_device_detach(dev); | |
489 | pcmcia_release_configuration(link->handle); | |
490 | } | |
491 | ||
492 | return 0; | |
493 | } | |
494 | ||
495 | static int axnet_resume(struct pcmcia_device *p_dev) | |
496 | { | |
497 | dev_link_t *link = dev_to_instance(p_dev); | |
498 | struct net_device *dev = link->priv; | |
499 | ||
500 | link->state &= ~DEV_SUSPEND; | |
501 | if (link->state & DEV_CONFIG) { | |
502 | pcmcia_request_configuration(link->handle, &link->conf); | |
503 | if (link->open) { | |
504 | axnet_reset_8390(dev); | |
505 | AX88190_init(dev, 1); | |
506 | netif_device_attach(dev); | |
507 | } | |
508 | } | |
509 | ||
510 | return 0; | |
511 | } | |
512 | ||
513 | ||
1da177e4 LT |
514 | /*====================================================================== |
515 | ||
516 | The card status event handler. Mostly, this schedules other | |
517 | stuff to run after an event is received. A CARD_REMOVAL event | |
518 | also sets some flags to discourage the net drivers from trying | |
519 | to talk to the card any more. | |
520 | ||
521 | ======================================================================*/ | |
522 | ||
523 | static int axnet_event(event_t event, int priority, | |
524 | event_callback_args_t *args) | |
525 | { | |
526 | dev_link_t *link = args->client_data; | |
1da177e4 LT |
527 | |
528 | DEBUG(2, "axnet_event(0x%06x)\n", event); | |
529 | ||
530 | switch (event) { | |
1da177e4 LT |
531 | case CS_EVENT_CARD_INSERTION: |
532 | link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; | |
533 | axnet_config(link); | |
534 | break; | |
1da177e4 LT |
535 | } |
536 | return 0; | |
537 | } /* axnet_event */ | |
538 | ||
539 | /*====================================================================== | |
540 | ||
541 | MII interface support | |
542 | ||
543 | ======================================================================*/ | |
544 | ||
545 | #define MDIO_SHIFT_CLK 0x01 | |
546 | #define MDIO_DATA_WRITE0 0x00 | |
547 | #define MDIO_DATA_WRITE1 0x08 | |
548 | #define MDIO_DATA_READ 0x04 | |
549 | #define MDIO_MASK 0x0f | |
550 | #define MDIO_ENB_IN 0x02 | |
551 | ||
552 | static void mdio_sync(kio_addr_t addr) | |
553 | { | |
554 | int bits; | |
555 | for (bits = 0; bits < 32; bits++) { | |
556 | outb_p(MDIO_DATA_WRITE1, addr); | |
557 | outb_p(MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, addr); | |
558 | } | |
559 | } | |
560 | ||
561 | static int mdio_read(kio_addr_t addr, int phy_id, int loc) | |
562 | { | |
563 | u_int cmd = (0xf6<<10)|(phy_id<<5)|loc; | |
564 | int i, retval = 0; | |
565 | ||
566 | mdio_sync(addr); | |
567 | for (i = 14; i >= 0; i--) { | |
568 | int dat = (cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0; | |
569 | outb_p(dat, addr); | |
570 | outb_p(dat | MDIO_SHIFT_CLK, addr); | |
571 | } | |
572 | for (i = 19; i > 0; i--) { | |
573 | outb_p(MDIO_ENB_IN, addr); | |
574 | retval = (retval << 1) | ((inb_p(addr) & MDIO_DATA_READ) != 0); | |
575 | outb_p(MDIO_ENB_IN | MDIO_SHIFT_CLK, addr); | |
576 | } | |
577 | return (retval>>1) & 0xffff; | |
578 | } | |
579 | ||
580 | static void mdio_write(kio_addr_t addr, int phy_id, int loc, int value) | |
581 | { | |
582 | u_int cmd = (0x05<<28)|(phy_id<<23)|(loc<<18)|(1<<17)|value; | |
583 | int i; | |
584 | ||
585 | mdio_sync(addr); | |
586 | for (i = 31; i >= 0; i--) { | |
587 | int dat = (cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0; | |
588 | outb_p(dat, addr); | |
589 | outb_p(dat | MDIO_SHIFT_CLK, addr); | |
590 | } | |
591 | for (i = 1; i >= 0; i--) { | |
592 | outb_p(MDIO_ENB_IN, addr); | |
593 | outb_p(MDIO_ENB_IN | MDIO_SHIFT_CLK, addr); | |
594 | } | |
595 | } | |
596 | ||
597 | /*====================================================================*/ | |
598 | ||
599 | static int axnet_open(struct net_device *dev) | |
600 | { | |
601 | axnet_dev_t *info = PRIV(dev); | |
602 | dev_link_t *link = &info->link; | |
603 | ||
604 | DEBUG(2, "axnet_open('%s')\n", dev->name); | |
605 | ||
606 | if (!DEV_OK(link)) | |
607 | return -ENODEV; | |
608 | ||
609 | link->open++; | |
610 | ||
611 | request_irq(dev->irq, ei_irq_wrapper, SA_SHIRQ, dev_info, dev); | |
612 | ||
613 | info->link_status = 0x00; | |
614 | init_timer(&info->watchdog); | |
615 | info->watchdog.function = &ei_watchdog; | |
616 | info->watchdog.data = (u_long)dev; | |
617 | info->watchdog.expires = jiffies + HZ; | |
618 | add_timer(&info->watchdog); | |
619 | ||
620 | return ax_open(dev); | |
621 | } /* axnet_open */ | |
622 | ||
623 | /*====================================================================*/ | |
624 | ||
625 | static int axnet_close(struct net_device *dev) | |
626 | { | |
627 | axnet_dev_t *info = PRIV(dev); | |
628 | dev_link_t *link = &info->link; | |
629 | ||
630 | DEBUG(2, "axnet_close('%s')\n", dev->name); | |
631 | ||
632 | ax_close(dev); | |
633 | free_irq(dev->irq, dev); | |
634 | ||
635 | link->open--; | |
636 | netif_stop_queue(dev); | |
637 | del_timer_sync(&info->watchdog); | |
638 | ||
639 | return 0; | |
640 | } /* axnet_close */ | |
641 | ||
642 | /*====================================================================== | |
643 | ||
644 | Hard reset the card. This used to pause for the same period that | |
645 | a 8390 reset command required, but that shouldn't be necessary. | |
646 | ||
647 | ======================================================================*/ | |
648 | ||
649 | static void axnet_reset_8390(struct net_device *dev) | |
650 | { | |
651 | kio_addr_t nic_base = dev->base_addr; | |
652 | int i; | |
653 | ||
654 | ei_status.txing = ei_status.dmaing = 0; | |
655 | ||
656 | outb_p(E8390_NODMA+E8390_PAGE0+E8390_STOP, nic_base + E8390_CMD); | |
657 | ||
658 | outb(inb(nic_base + AXNET_RESET), nic_base + AXNET_RESET); | |
659 | ||
660 | for (i = 0; i < 100; i++) { | |
661 | if ((inb_p(nic_base+EN0_ISR) & ENISR_RESET) != 0) | |
662 | break; | |
663 | udelay(100); | |
664 | } | |
665 | outb_p(ENISR_RESET, nic_base + EN0_ISR); /* Ack intr. */ | |
666 | ||
667 | if (i == 100) | |
668 | printk(KERN_ERR "%s: axnet_reset_8390() did not complete.\n", | |
669 | dev->name); | |
670 | ||
671 | } /* axnet_reset_8390 */ | |
672 | ||
673 | /*====================================================================*/ | |
674 | ||
675 | static irqreturn_t ei_irq_wrapper(int irq, void *dev_id, struct pt_regs *regs) | |
676 | { | |
677 | struct net_device *dev = dev_id; | |
678 | PRIV(dev)->stale = 0; | |
679 | return ax_interrupt(irq, dev_id, regs); | |
680 | } | |
681 | ||
682 | static void ei_watchdog(u_long arg) | |
683 | { | |
684 | struct net_device *dev = (struct net_device *)(arg); | |
685 | axnet_dev_t *info = PRIV(dev); | |
686 | kio_addr_t nic_base = dev->base_addr; | |
687 | kio_addr_t mii_addr = nic_base + AXNET_MII_EEP; | |
688 | u_short link; | |
689 | ||
690 | if (!netif_device_present(dev)) goto reschedule; | |
691 | ||
692 | /* Check for pending interrupt with expired latency timer: with | |
693 | this, we can limp along even if the interrupt is blocked */ | |
694 | if (info->stale++ && (inb_p(nic_base + EN0_ISR) & ENISR_ALL)) { | |
695 | if (!info->fast_poll) | |
696 | printk(KERN_INFO "%s: interrupt(s) dropped!\n", dev->name); | |
697 | ei_irq_wrapper(dev->irq, dev, NULL); | |
698 | info->fast_poll = HZ; | |
699 | } | |
700 | if (info->fast_poll) { | |
701 | info->fast_poll--; | |
702 | info->watchdog.expires = jiffies + 1; | |
703 | add_timer(&info->watchdog); | |
704 | return; | |
705 | } | |
706 | ||
707 | if (info->phy_id < 0) | |
708 | goto reschedule; | |
709 | link = mdio_read(mii_addr, info->phy_id, 1); | |
710 | if (!link || (link == 0xffff)) { | |
711 | printk(KERN_INFO "%s: MII is missing!\n", dev->name); | |
712 | info->phy_id = -1; | |
713 | goto reschedule; | |
714 | } | |
715 | ||
716 | link &= 0x0004; | |
717 | if (link != info->link_status) { | |
718 | u_short p = mdio_read(mii_addr, info->phy_id, 5); | |
719 | printk(KERN_INFO "%s: %s link beat\n", dev->name, | |
720 | (link) ? "found" : "lost"); | |
721 | if (link) { | |
722 | info->duplex_flag = (p & 0x0140) ? 0x80 : 0x00; | |
723 | if (p) | |
724 | printk(KERN_INFO "%s: autonegotiation complete: " | |
725 | "%sbaseT-%cD selected\n", dev->name, | |
726 | ((p & 0x0180) ? "100" : "10"), | |
727 | ((p & 0x0140) ? 'F' : 'H')); | |
728 | else | |
729 | printk(KERN_INFO "%s: link partner did not autonegotiate\n", | |
730 | dev->name); | |
731 | AX88190_init(dev, 1); | |
732 | } | |
733 | info->link_status = link; | |
734 | } | |
735 | ||
736 | reschedule: | |
737 | info->watchdog.expires = jiffies + HZ; | |
738 | add_timer(&info->watchdog); | |
739 | } | |
740 | ||
741 | static void netdev_get_drvinfo(struct net_device *dev, | |
742 | struct ethtool_drvinfo *info) | |
743 | { | |
744 | strcpy(info->driver, "axnet_cs"); | |
745 | } | |
746 | ||
747 | static struct ethtool_ops netdev_ethtool_ops = { | |
748 | .get_drvinfo = netdev_get_drvinfo, | |
749 | }; | |
750 | ||
751 | /*====================================================================*/ | |
752 | ||
753 | static int axnet_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) | |
754 | { | |
755 | axnet_dev_t *info = PRIV(dev); | |
756 | u16 *data = (u16 *)&rq->ifr_ifru; | |
757 | kio_addr_t mii_addr = dev->base_addr + AXNET_MII_EEP; | |
758 | switch (cmd) { | |
759 | case SIOCGMIIPHY: | |
760 | data[0] = info->phy_id; | |
761 | case SIOCGMIIREG: /* Read MII PHY register. */ | |
762 | data[3] = mdio_read(mii_addr, data[0], data[1] & 0x1f); | |
763 | return 0; | |
764 | case SIOCSMIIREG: /* Write MII PHY register. */ | |
765 | if (!capable(CAP_NET_ADMIN)) | |
766 | return -EPERM; | |
767 | mdio_write(mii_addr, data[0], data[1] & 0x1f, data[2]); | |
768 | return 0; | |
769 | } | |
770 | return -EOPNOTSUPP; | |
771 | } | |
772 | ||
773 | /*====================================================================*/ | |
774 | ||
775 | static void get_8390_hdr(struct net_device *dev, | |
776 | struct e8390_pkt_hdr *hdr, | |
777 | int ring_page) | |
778 | { | |
779 | kio_addr_t nic_base = dev->base_addr; | |
780 | ||
781 | outb_p(0, nic_base + EN0_RSARLO); /* On page boundary */ | |
782 | outb_p(ring_page, nic_base + EN0_RSARHI); | |
783 | outb_p(E8390_RREAD+E8390_START, nic_base + AXNET_CMD); | |
784 | ||
785 | insw(nic_base + AXNET_DATAPORT, hdr, | |
786 | sizeof(struct e8390_pkt_hdr)>>1); | |
787 | /* Fix for big endian systems */ | |
788 | hdr->count = le16_to_cpu(hdr->count); | |
789 | ||
790 | } | |
791 | ||
792 | /*====================================================================*/ | |
793 | ||
794 | static void block_input(struct net_device *dev, int count, | |
795 | struct sk_buff *skb, int ring_offset) | |
796 | { | |
797 | kio_addr_t nic_base = dev->base_addr; | |
798 | int xfer_count = count; | |
799 | char *buf = skb->data; | |
800 | ||
801 | #ifdef PCMCIA_DEBUG | |
802 | if ((ei_debug > 4) && (count != 4)) | |
803 | printk(KERN_DEBUG "%s: [bi=%d]\n", dev->name, count+4); | |
804 | #endif | |
805 | outb_p(ring_offset & 0xff, nic_base + EN0_RSARLO); | |
806 | outb_p(ring_offset >> 8, nic_base + EN0_RSARHI); | |
807 | outb_p(E8390_RREAD+E8390_START, nic_base + AXNET_CMD); | |
808 | ||
809 | insw(nic_base + AXNET_DATAPORT,buf,count>>1); | |
810 | if (count & 0x01) | |
811 | buf[count-1] = inb(nic_base + AXNET_DATAPORT), xfer_count++; | |
812 | ||
813 | } | |
814 | ||
815 | /*====================================================================*/ | |
816 | ||
817 | static void block_output(struct net_device *dev, int count, | |
818 | const u_char *buf, const int start_page) | |
819 | { | |
820 | kio_addr_t nic_base = dev->base_addr; | |
821 | ||
822 | #ifdef PCMCIA_DEBUG | |
823 | if (ei_debug > 4) | |
824 | printk(KERN_DEBUG "%s: [bo=%d]\n", dev->name, count); | |
825 | #endif | |
826 | ||
827 | /* Round the count up for word writes. Do we need to do this? | |
828 | What effect will an odd byte count have on the 8390? | |
829 | I should check someday. */ | |
830 | if (count & 0x01) | |
831 | count++; | |
832 | ||
833 | outb_p(0x00, nic_base + EN0_RSARLO); | |
834 | outb_p(start_page, nic_base + EN0_RSARHI); | |
835 | outb_p(E8390_RWRITE+E8390_START, nic_base + AXNET_CMD); | |
836 | outsw(nic_base + AXNET_DATAPORT, buf, count>>1); | |
837 | } | |
838 | ||
c414f755 DB |
839 | static struct pcmcia_device_id axnet_ids[] = { |
840 | PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x016c, 0x0081), | |
841 | PCMCIA_DEVICE_MANF_CARD(0x018a, 0x0301), | |
842 | PCMCIA_DEVICE_MANF_CARD(0x026f, 0x0301), | |
843 | PCMCIA_DEVICE_MANF_CARD(0x026f, 0x0303), | |
844 | PCMCIA_DEVICE_MANF_CARD(0x026f, 0x0309), | |
845 | PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1106), | |
846 | PCMCIA_DEVICE_MANF_CARD(0x8a01, 0xc1ab), | |
847 | PCMCIA_DEVICE_PROD_ID124("Fast Ethernet", "16-bit PC Card", "AX88190", 0xb4be14e3, 0x9a12eb6a, 0xab9be5ef), | |
848 | PCMCIA_DEVICE_PROD_ID12("ASIX", "AX88190", 0x0959823b, 0xab9be5ef), | |
849 | PCMCIA_DEVICE_PROD_ID12("Billionton", "LNA-100B", 0x552ab682, 0xbc3b87e1), | |
850 | PCMCIA_DEVICE_PROD_ID12("CHEETAH ETHERCARD", "EN2228", 0x00fa7bc8, 0x00e990cc), | |
851 | PCMCIA_DEVICE_PROD_ID12("CNet", "CNF301", 0xbc477dde, 0x78c5f40b), | |
852 | PCMCIA_DEVICE_PROD_ID12("corega K.K.", "corega FEther PCC-TXD", 0x5261440f, 0x436768c5), | |
853 | PCMCIA_DEVICE_PROD_ID12("corega K.K.", "corega FEtherII PCC-TXD", 0x5261440f, 0x730df72e), | |
854 | PCMCIA_DEVICE_PROD_ID12("Dynalink", "L100C16", 0x55632fd5, 0x66bc2a90), | |
855 | PCMCIA_DEVICE_PROD_ID12("Linksys", "EtherFast 10/100 PC Card (PCMPC100 V3)", 0x0733cc81, 0x232019a8), | |
856 | PCMCIA_DEVICE_PROD_ID12("MELCO", "LPC3-TX", 0x481e0094, 0xf91af609), | |
857 | PCMCIA_DEVICE_PROD_ID12("PCMCIA", "100BASE", 0x281f1c5d, 0x7c2add04), | |
858 | PCMCIA_DEVICE_PROD_ID12("PCMCIA", "FastEtherCard", 0x281f1c5d, 0x7ef26116), | |
859 | PCMCIA_DEVICE_PROD_ID12("PCMCIA", "FEP501", 0x281f1c5d, 0x2e272058), | |
860 | PCMCIA_DEVICE_PROD_ID14("Network Everywhere", "AX88190", 0x820a67b6, 0xab9be5ef), | |
861 | /* this is not specific enough */ | |
862 | /* PCMCIA_DEVICE_MANF_CARD(0x021b, 0x0202), */ | |
863 | PCMCIA_DEVICE_NULL, | |
864 | }; | |
865 | MODULE_DEVICE_TABLE(pcmcia, axnet_ids); | |
866 | ||
1da177e4 LT |
867 | static struct pcmcia_driver axnet_cs_driver = { |
868 | .owner = THIS_MODULE, | |
869 | .drv = { | |
870 | .name = "axnet_cs", | |
871 | }, | |
872 | .attach = axnet_attach, | |
1e212f36 | 873 | .event = axnet_event, |
cc3b4866 | 874 | .remove = axnet_detach, |
c414f755 | 875 | .id_table = axnet_ids, |
98e4c28b DB |
876 | .suspend = axnet_suspend, |
877 | .resume = axnet_resume, | |
1da177e4 LT |
878 | }; |
879 | ||
880 | static int __init init_axnet_cs(void) | |
881 | { | |
882 | return pcmcia_register_driver(&axnet_cs_driver); | |
883 | } | |
884 | ||
885 | static void __exit exit_axnet_cs(void) | |
886 | { | |
887 | pcmcia_unregister_driver(&axnet_cs_driver); | |
1da177e4 LT |
888 | } |
889 | ||
890 | module_init(init_axnet_cs); | |
891 | module_exit(exit_axnet_cs); | |
892 | ||
893 | /*====================================================================*/ | |
894 | ||
895 | /* 8390.c: A general NS8390 ethernet driver core for linux. */ | |
896 | /* | |
897 | Written 1992-94 by Donald Becker. | |
898 | ||
899 | Copyright 1993 United States Government as represented by the | |
900 | Director, National Security Agency. | |
901 | ||
902 | This software may be used and distributed according to the terms | |
903 | of the GNU General Public License, incorporated herein by reference. | |
904 | ||
905 | The author may be reached as becker@scyld.com, or C/O | |
906 | Scyld Computing Corporation | |
907 | 410 Severn Ave., Suite 210 | |
908 | Annapolis MD 21403 | |
909 | ||
910 | This is the chip-specific code for many 8390-based ethernet adaptors. | |
911 | This is not a complete driver, it must be combined with board-specific | |
912 | code such as ne.c, wd.c, 3c503.c, etc. | |
913 | ||
914 | Seeing how at least eight drivers use this code, (not counting the | |
915 | PCMCIA ones either) it is easy to break some card by what seems like | |
916 | a simple innocent change. Please contact me or Donald if you think | |
917 | you have found something that needs changing. -- PG | |
918 | ||
919 | Changelog: | |
920 | ||
921 | Paul Gortmaker : remove set_bit lock, other cleanups. | |
922 | Paul Gortmaker : add ei_get_8390_hdr() so we can pass skb's to | |
923 | ei_block_input() for eth_io_copy_and_sum(). | |
924 | Paul Gortmaker : exchange static int ei_pingpong for a #define, | |
925 | also add better Tx error handling. | |
926 | Paul Gortmaker : rewrite Rx overrun handling as per NS specs. | |
927 | Alexey Kuznetsov : use the 8390's six bit hash multicast filter. | |
928 | Paul Gortmaker : tweak ANK's above multicast changes a bit. | |
929 | Paul Gortmaker : update packet statistics for v2.1.x | |
930 | Alan Cox : support arbitary stupid port mappings on the | |
931 | 68K Macintosh. Support >16bit I/O spaces | |
932 | Paul Gortmaker : add kmod support for auto-loading of the 8390 | |
933 | module by all drivers that require it. | |
934 | Alan Cox : Spinlocking work, added 'BUG_83C690' | |
935 | Paul Gortmaker : Separate out Tx timeout code from Tx path. | |
936 | ||
937 | Sources: | |
938 | The National Semiconductor LAN Databook, and the 3Com 3c503 databook. | |
939 | ||
940 | */ | |
941 | ||
942 | static const char *version_8390 = | |
943 | "8390.c:v1.10cvs 9/23/94 Donald Becker (becker@scyld.com)\n"; | |
944 | ||
945 | #include <linux/bitops.h> | |
946 | #include <asm/irq.h> | |
947 | #include <linux/fcntl.h> | |
948 | #include <linux/in.h> | |
949 | #include <linux/interrupt.h> | |
950 | ||
951 | #include <linux/etherdevice.h> | |
952 | ||
953 | #define BUG_83C690 | |
954 | ||
955 | /* These are the operational function interfaces to board-specific | |
956 | routines. | |
957 | void reset_8390(struct net_device *dev) | |
958 | Resets the board associated with DEV, including a hardware reset of | |
959 | the 8390. This is only called when there is a transmit timeout, and | |
960 | it is always followed by 8390_init(). | |
961 | void block_output(struct net_device *dev, int count, const unsigned char *buf, | |
962 | int start_page) | |
963 | Write the COUNT bytes of BUF to the packet buffer at START_PAGE. The | |
964 | "page" value uses the 8390's 256-byte pages. | |
965 | void get_8390_hdr(struct net_device *dev, struct e8390_hdr *hdr, int ring_page) | |
966 | Read the 4 byte, page aligned 8390 header. *If* there is a | |
967 | subsequent read, it will be of the rest of the packet. | |
968 | void block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset) | |
969 | Read COUNT bytes from the packet buffer into the skb data area. Start | |
970 | reading from RING_OFFSET, the address as the 8390 sees it. This will always | |
971 | follow the read of the 8390 header. | |
972 | */ | |
973 | #define ei_reset_8390 (ei_local->reset_8390) | |
974 | #define ei_block_output (ei_local->block_output) | |
975 | #define ei_block_input (ei_local->block_input) | |
976 | #define ei_get_8390_hdr (ei_local->get_8390_hdr) | |
977 | ||
978 | /* use 0 for production, 1 for verification, >2 for debug */ | |
979 | #ifndef ei_debug | |
980 | int ei_debug = 1; | |
981 | #endif | |
982 | ||
983 | /* Index to functions. */ | |
984 | static void ei_tx_intr(struct net_device *dev); | |
985 | static void ei_tx_err(struct net_device *dev); | |
986 | static void ei_tx_timeout(struct net_device *dev); | |
987 | static void ei_receive(struct net_device *dev); | |
988 | static void ei_rx_overrun(struct net_device *dev); | |
989 | ||
990 | /* Routines generic to NS8390-based boards. */ | |
991 | static void NS8390_trigger_send(struct net_device *dev, unsigned int length, | |
992 | int start_page); | |
993 | static void set_multicast_list(struct net_device *dev); | |
994 | static void do_set_multicast_list(struct net_device *dev); | |
995 | ||
996 | /* | |
997 | * SMP and the 8390 setup. | |
998 | * | |
999 | * The 8390 isnt exactly designed to be multithreaded on RX/TX. There is | |
1000 | * a page register that controls bank and packet buffer access. We guard | |
1001 | * this with ei_local->page_lock. Nobody should assume or set the page other | |
1002 | * than zero when the lock is not held. Lock holders must restore page 0 | |
1003 | * before unlocking. Even pure readers must take the lock to protect in | |
1004 | * page 0. | |
1005 | * | |
1006 | * To make life difficult the chip can also be very slow. We therefore can't | |
1007 | * just use spinlocks. For the longer lockups we disable the irq the device | |
1008 | * sits on and hold the lock. We must hold the lock because there is a dual | |
1009 | * processor case other than interrupts (get stats/set multicast list in | |
1010 | * parallel with each other and transmit). | |
1011 | * | |
1012 | * Note: in theory we can just disable the irq on the card _but_ there is | |
1013 | * a latency on SMP irq delivery. So we can easily go "disable irq" "sync irqs" | |
1014 | * enter lock, take the queued irq. So we waddle instead of flying. | |
1015 | * | |
1016 | * Finally by special arrangement for the purpose of being generally | |
1017 | * annoying the transmit function is called bh atomic. That places | |
1018 | * restrictions on the user context callers as disable_irq won't save | |
1019 | * them. | |
1020 | */ | |
1021 | ||
1022 | /** | |
1023 | * ax_open - Open/initialize the board. | |
1024 | * @dev: network device to initialize | |
1025 | * | |
1026 | * This routine goes all-out, setting everything | |
1027 | * up anew at each open, even though many of these registers should only | |
1028 | * need to be set once at boot. | |
1029 | */ | |
1030 | static int ax_open(struct net_device *dev) | |
1031 | { | |
1032 | unsigned long flags; | |
1033 | struct ei_device *ei_local = (struct ei_device *) netdev_priv(dev); | |
1034 | ||
1035 | #ifdef HAVE_TX_TIMEOUT | |
1036 | /* The card I/O part of the driver (e.g. 3c503) can hook a Tx timeout | |
1037 | wrapper that does e.g. media check & then calls ei_tx_timeout. */ | |
1038 | if (dev->tx_timeout == NULL) | |
1039 | dev->tx_timeout = ei_tx_timeout; | |
1040 | if (dev->watchdog_timeo <= 0) | |
1041 | dev->watchdog_timeo = TX_TIMEOUT; | |
1042 | #endif | |
1043 | ||
1044 | /* | |
1045 | * Grab the page lock so we own the register set, then call | |
1046 | * the init function. | |
1047 | */ | |
1048 | ||
1049 | spin_lock_irqsave(&ei_local->page_lock, flags); | |
1050 | AX88190_init(dev, 1); | |
1051 | /* Set the flag before we drop the lock, That way the IRQ arrives | |
1052 | after its set and we get no silly warnings */ | |
1053 | netif_start_queue(dev); | |
1054 | spin_unlock_irqrestore(&ei_local->page_lock, flags); | |
1055 | ei_local->irqlock = 0; | |
1056 | return 0; | |
1057 | } | |
1058 | ||
1059 | #define dev_lock(dev) (((struct ei_device *)netdev_priv(dev))->page_lock) | |
1060 | ||
1061 | /** | |
1062 | * ax_close - shut down network device | |
1063 | * @dev: network device to close | |
1064 | * | |
1065 | * Opposite of ax_open(). Only used when "ifconfig <devname> down" is done. | |
1066 | */ | |
1067 | int ax_close(struct net_device *dev) | |
1068 | { | |
1069 | unsigned long flags; | |
1070 | ||
1071 | /* | |
1072 | * Hold the page lock during close | |
1073 | */ | |
1074 | ||
1075 | spin_lock_irqsave(&dev_lock(dev), flags); | |
1076 | AX88190_init(dev, 0); | |
1077 | spin_unlock_irqrestore(&dev_lock(dev), flags); | |
1078 | netif_stop_queue(dev); | |
1079 | return 0; | |
1080 | } | |
1081 | ||
1082 | /** | |
1083 | * ei_tx_timeout - handle transmit time out condition | |
1084 | * @dev: network device which has apparently fallen asleep | |
1085 | * | |
1086 | * Called by kernel when device never acknowledges a transmit has | |
1087 | * completed (or failed) - i.e. never posted a Tx related interrupt. | |
1088 | */ | |
1089 | ||
1090 | void ei_tx_timeout(struct net_device *dev) | |
1091 | { | |
1092 | long e8390_base = dev->base_addr; | |
1093 | struct ei_device *ei_local = (struct ei_device *) netdev_priv(dev); | |
1094 | int txsr, isr, tickssofar = jiffies - dev->trans_start; | |
1095 | unsigned long flags; | |
1096 | ||
1097 | ei_local->stat.tx_errors++; | |
1098 | ||
1099 | spin_lock_irqsave(&ei_local->page_lock, flags); | |
1100 | txsr = inb(e8390_base+EN0_TSR); | |
1101 | isr = inb(e8390_base+EN0_ISR); | |
1102 | spin_unlock_irqrestore(&ei_local->page_lock, flags); | |
1103 | ||
1104 | printk(KERN_DEBUG "%s: Tx timed out, %s TSR=%#2x, ISR=%#2x, t=%d.\n", | |
1105 | dev->name, (txsr & ENTSR_ABT) ? "excess collisions." : | |
1106 | (isr) ? "lost interrupt?" : "cable problem?", txsr, isr, tickssofar); | |
1107 | ||
1108 | if (!isr && !ei_local->stat.tx_packets) | |
1109 | { | |
1110 | /* The 8390 probably hasn't gotten on the cable yet. */ | |
1111 | ei_local->interface_num ^= 1; /* Try a different xcvr. */ | |
1112 | } | |
1113 | ||
1114 | /* Ugly but a reset can be slow, yet must be protected */ | |
1115 | ||
1116 | disable_irq_nosync(dev->irq); | |
1117 | spin_lock(&ei_local->page_lock); | |
1118 | ||
1119 | /* Try to restart the card. Perhaps the user has fixed something. */ | |
1120 | ei_reset_8390(dev); | |
1121 | AX88190_init(dev, 1); | |
1122 | ||
1123 | spin_unlock(&ei_local->page_lock); | |
1124 | enable_irq(dev->irq); | |
1125 | netif_wake_queue(dev); | |
1126 | } | |
1127 | ||
1128 | /** | |
1129 | * ei_start_xmit - begin packet transmission | |
1130 | * @skb: packet to be sent | |
1131 | * @dev: network device to which packet is sent | |
1132 | * | |
1133 | * Sends a packet to an 8390 network device. | |
1134 | */ | |
1135 | ||
1136 | static int ei_start_xmit(struct sk_buff *skb, struct net_device *dev) | |
1137 | { | |
1138 | long e8390_base = dev->base_addr; | |
1139 | struct ei_device *ei_local = (struct ei_device *) netdev_priv(dev); | |
1140 | int length, send_length, output_page; | |
1141 | unsigned long flags; | |
1142 | u8 packet[ETH_ZLEN]; | |
1143 | ||
1144 | netif_stop_queue(dev); | |
1145 | ||
1146 | length = skb->len; | |
1147 | ||
1148 | /* Mask interrupts from the ethercard. | |
1149 | SMP: We have to grab the lock here otherwise the IRQ handler | |
1150 | on another CPU can flip window and race the IRQ mask set. We end | |
1151 | up trashing the mcast filter not disabling irqs if we don't lock */ | |
1152 | ||
1153 | spin_lock_irqsave(&ei_local->page_lock, flags); | |
1154 | outb_p(0x00, e8390_base + EN0_IMR); | |
1155 | spin_unlock_irqrestore(&ei_local->page_lock, flags); | |
1156 | ||
1157 | /* | |
1158 | * Slow phase with lock held. | |
1159 | */ | |
1160 | ||
1161 | disable_irq_nosync(dev->irq); | |
1162 | ||
1163 | spin_lock(&ei_local->page_lock); | |
1164 | ||
1165 | ei_local->irqlock = 1; | |
1166 | ||
1167 | send_length = ETH_ZLEN < length ? length : ETH_ZLEN; | |
1168 | ||
1169 | /* | |
1170 | * We have two Tx slots available for use. Find the first free | |
1171 | * slot, and then perform some sanity checks. With two Tx bufs, | |
1172 | * you get very close to transmitting back-to-back packets. With | |
1173 | * only one Tx buf, the transmitter sits idle while you reload the | |
1174 | * card, leaving a substantial gap between each transmitted packet. | |
1175 | */ | |
1176 | ||
1177 | if (ei_local->tx1 == 0) | |
1178 | { | |
1179 | output_page = ei_local->tx_start_page; | |
1180 | ei_local->tx1 = send_length; | |
1181 | if (ei_debug && ei_local->tx2 > 0) | |
1182 | printk(KERN_DEBUG "%s: idle transmitter tx2=%d, lasttx=%d, txing=%d.\n", | |
1183 | dev->name, ei_local->tx2, ei_local->lasttx, ei_local->txing); | |
1184 | } | |
1185 | else if (ei_local->tx2 == 0) | |
1186 | { | |
1187 | output_page = ei_local->tx_start_page + TX_PAGES/2; | |
1188 | ei_local->tx2 = send_length; | |
1189 | if (ei_debug && ei_local->tx1 > 0) | |
1190 | printk(KERN_DEBUG "%s: idle transmitter, tx1=%d, lasttx=%d, txing=%d.\n", | |
1191 | dev->name, ei_local->tx1, ei_local->lasttx, ei_local->txing); | |
1192 | } | |
1193 | else | |
1194 | { /* We should never get here. */ | |
1195 | if (ei_debug) | |
1196 | printk(KERN_DEBUG "%s: No Tx buffers free! tx1=%d tx2=%d last=%d\n", | |
1197 | dev->name, ei_local->tx1, ei_local->tx2, ei_local->lasttx); | |
1198 | ei_local->irqlock = 0; | |
1199 | netif_stop_queue(dev); | |
1200 | outb_p(ENISR_ALL, e8390_base + EN0_IMR); | |
1201 | spin_unlock(&ei_local->page_lock); | |
1202 | enable_irq(dev->irq); | |
1203 | ei_local->stat.tx_errors++; | |
1204 | return 1; | |
1205 | } | |
1206 | ||
1207 | /* | |
1208 | * Okay, now upload the packet and trigger a send if the transmitter | |
1209 | * isn't already sending. If it is busy, the interrupt handler will | |
1210 | * trigger the send later, upon receiving a Tx done interrupt. | |
1211 | */ | |
1212 | ||
1213 | if (length == skb->len) | |
1214 | ei_block_output(dev, length, skb->data, output_page); | |
1215 | else { | |
1216 | memset(packet, 0, ETH_ZLEN); | |
1217 | memcpy(packet, skb->data, skb->len); | |
1218 | ei_block_output(dev, length, packet, output_page); | |
1219 | } | |
1220 | ||
1221 | if (! ei_local->txing) | |
1222 | { | |
1223 | ei_local->txing = 1; | |
1224 | NS8390_trigger_send(dev, send_length, output_page); | |
1225 | dev->trans_start = jiffies; | |
1226 | if (output_page == ei_local->tx_start_page) | |
1227 | { | |
1228 | ei_local->tx1 = -1; | |
1229 | ei_local->lasttx = -1; | |
1230 | } | |
1231 | else | |
1232 | { | |
1233 | ei_local->tx2 = -1; | |
1234 | ei_local->lasttx = -2; | |
1235 | } | |
1236 | } | |
1237 | else ei_local->txqueue++; | |
1238 | ||
1239 | if (ei_local->tx1 && ei_local->tx2) | |
1240 | netif_stop_queue(dev); | |
1241 | else | |
1242 | netif_start_queue(dev); | |
1243 | ||
1244 | /* Turn 8390 interrupts back on. */ | |
1245 | ei_local->irqlock = 0; | |
1246 | outb_p(ENISR_ALL, e8390_base + EN0_IMR); | |
1247 | ||
1248 | spin_unlock(&ei_local->page_lock); | |
1249 | enable_irq(dev->irq); | |
1250 | ||
1251 | dev_kfree_skb (skb); | |
1252 | ei_local->stat.tx_bytes += send_length; | |
1253 | ||
1254 | return 0; | |
1255 | } | |
1256 | ||
1257 | /** | |
1258 | * ax_interrupt - handle the interrupts from an 8390 | |
1259 | * @irq: interrupt number | |
1260 | * @dev_id: a pointer to the net_device | |
1261 | * @regs: unused | |
1262 | * | |
1263 | * Handle the ether interface interrupts. We pull packets from | |
1264 | * the 8390 via the card specific functions and fire them at the networking | |
1265 | * stack. We also handle transmit completions and wake the transmit path if | |
1266 | * necessary. We also update the counters and do other housekeeping as | |
1267 | * needed. | |
1268 | */ | |
1269 | ||
1270 | static irqreturn_t ax_interrupt(int irq, void *dev_id, struct pt_regs * regs) | |
1271 | { | |
1272 | struct net_device *dev = dev_id; | |
1273 | long e8390_base; | |
1274 | int interrupts, nr_serviced = 0, i; | |
1275 | struct ei_device *ei_local; | |
1276 | int handled = 0; | |
1277 | ||
1278 | if (dev == NULL) | |
1279 | { | |
1280 | printk ("net_interrupt(): irq %d for unknown device.\n", irq); | |
1281 | return IRQ_NONE; | |
1282 | } | |
1283 | ||
1284 | e8390_base = dev->base_addr; | |
1285 | ei_local = (struct ei_device *) netdev_priv(dev); | |
1286 | ||
1287 | /* | |
1288 | * Protect the irq test too. | |
1289 | */ | |
1290 | ||
1291 | spin_lock(&ei_local->page_lock); | |
1292 | ||
1293 | if (ei_local->irqlock) | |
1294 | { | |
1295 | #if 1 /* This might just be an interrupt for a PCI device sharing this line */ | |
1296 | /* The "irqlock" check is only for testing. */ | |
1297 | printk(ei_local->irqlock | |
1298 | ? "%s: Interrupted while interrupts are masked! isr=%#2x imr=%#2x.\n" | |
1299 | : "%s: Reentering the interrupt handler! isr=%#2x imr=%#2x.\n", | |
1300 | dev->name, inb_p(e8390_base + EN0_ISR), | |
1301 | inb_p(e8390_base + EN0_IMR)); | |
1302 | #endif | |
1303 | spin_unlock(&ei_local->page_lock); | |
1304 | return IRQ_NONE; | |
1305 | } | |
1306 | ||
1307 | if (ei_debug > 3) | |
1308 | printk(KERN_DEBUG "%s: interrupt(isr=%#2.2x).\n", dev->name, | |
1309 | inb_p(e8390_base + EN0_ISR)); | |
1310 | ||
1311 | outb_p(0x00, e8390_base + EN0_ISR); | |
1312 | ei_local->irqlock = 1; | |
1313 | ||
1314 | /* !!Assumption!! -- we stay in page 0. Don't break this. */ | |
1315 | while ((interrupts = inb_p(e8390_base + EN0_ISR)) != 0 | |
1316 | && ++nr_serviced < MAX_SERVICE) | |
1317 | { | |
1318 | if (!netif_running(dev) || (interrupts == 0xff)) { | |
1319 | if (ei_debug > 1) | |
1320 | printk(KERN_WARNING "%s: interrupt from stopped card\n", dev->name); | |
1321 | outb_p(interrupts, e8390_base + EN0_ISR); | |
1322 | interrupts = 0; | |
1323 | break; | |
1324 | } | |
1325 | handled = 1; | |
1326 | ||
1327 | /* AX88190 bug fix. */ | |
1328 | outb_p(interrupts, e8390_base + EN0_ISR); | |
1329 | for (i = 0; i < 10; i++) { | |
1330 | if (!(inb(e8390_base + EN0_ISR) & interrupts)) | |
1331 | break; | |
1332 | outb_p(0, e8390_base + EN0_ISR); | |
1333 | outb_p(interrupts, e8390_base + EN0_ISR); | |
1334 | } | |
1335 | if (interrupts & ENISR_OVER) | |
1336 | ei_rx_overrun(dev); | |
1337 | else if (interrupts & (ENISR_RX+ENISR_RX_ERR)) | |
1338 | { | |
1339 | /* Got a good (?) packet. */ | |
1340 | ei_receive(dev); | |
1341 | } | |
1342 | /* Push the next to-transmit packet through. */ | |
1343 | if (interrupts & ENISR_TX) | |
1344 | ei_tx_intr(dev); | |
1345 | else if (interrupts & ENISR_TX_ERR) | |
1346 | ei_tx_err(dev); | |
1347 | ||
1348 | if (interrupts & ENISR_COUNTERS) | |
1349 | { | |
1350 | ei_local->stat.rx_frame_errors += inb_p(e8390_base + EN0_COUNTER0); | |
1351 | ei_local->stat.rx_crc_errors += inb_p(e8390_base + EN0_COUNTER1); | |
1352 | ei_local->stat.rx_missed_errors+= inb_p(e8390_base + EN0_COUNTER2); | |
1353 | } | |
1354 | } | |
1355 | ||
1356 | if (interrupts && ei_debug) | |
1357 | { | |
1358 | handled = 1; | |
1359 | if (nr_serviced >= MAX_SERVICE) | |
1360 | { | |
1361 | /* 0xFF is valid for a card removal */ | |
1362 | if(interrupts!=0xFF) | |
1363 | printk(KERN_WARNING "%s: Too much work at interrupt, status %#2.2x\n", | |
1364 | dev->name, interrupts); | |
1365 | outb_p(ENISR_ALL, e8390_base + EN0_ISR); /* Ack. most intrs. */ | |
1366 | } else { | |
1367 | printk(KERN_WARNING "%s: unknown interrupt %#2x\n", dev->name, interrupts); | |
1368 | outb_p(0xff, e8390_base + EN0_ISR); /* Ack. all intrs. */ | |
1369 | } | |
1370 | } | |
1371 | ||
1372 | /* Turn 8390 interrupts back on. */ | |
1373 | ei_local->irqlock = 0; | |
1374 | outb_p(ENISR_ALL, e8390_base + EN0_IMR); | |
1375 | ||
1376 | spin_unlock(&ei_local->page_lock); | |
1377 | return IRQ_RETVAL(handled); | |
1378 | } | |
1379 | ||
1380 | /** | |
1381 | * ei_tx_err - handle transmitter error | |
1382 | * @dev: network device which threw the exception | |
1383 | * | |
1384 | * A transmitter error has happened. Most likely excess collisions (which | |
1385 | * is a fairly normal condition). If the error is one where the Tx will | |
1386 | * have been aborted, we try and send another one right away, instead of | |
1387 | * letting the failed packet sit and collect dust in the Tx buffer. This | |
1388 | * is a much better solution as it avoids kernel based Tx timeouts, and | |
1389 | * an unnecessary card reset. | |
1390 | * | |
1391 | * Called with lock held. | |
1392 | */ | |
1393 | ||
1394 | static void ei_tx_err(struct net_device *dev) | |
1395 | { | |
1396 | long e8390_base = dev->base_addr; | |
1397 | struct ei_device *ei_local = (struct ei_device *) netdev_priv(dev); | |
1398 | unsigned char txsr = inb_p(e8390_base+EN0_TSR); | |
1399 | unsigned char tx_was_aborted = txsr & (ENTSR_ABT+ENTSR_FU); | |
1400 | ||
1401 | #ifdef VERBOSE_ERROR_DUMP | |
1402 | printk(KERN_DEBUG "%s: transmitter error (%#2x): ", dev->name, txsr); | |
1403 | if (txsr & ENTSR_ABT) | |
1404 | printk("excess-collisions "); | |
1405 | if (txsr & ENTSR_ND) | |
1406 | printk("non-deferral "); | |
1407 | if (txsr & ENTSR_CRS) | |
1408 | printk("lost-carrier "); | |
1409 | if (txsr & ENTSR_FU) | |
1410 | printk("FIFO-underrun "); | |
1411 | if (txsr & ENTSR_CDH) | |
1412 | printk("lost-heartbeat "); | |
1413 | printk("\n"); | |
1414 | #endif | |
1415 | ||
1416 | if (tx_was_aborted) | |
1417 | ei_tx_intr(dev); | |
1418 | else | |
1419 | { | |
1420 | ei_local->stat.tx_errors++; | |
1421 | if (txsr & ENTSR_CRS) ei_local->stat.tx_carrier_errors++; | |
1422 | if (txsr & ENTSR_CDH) ei_local->stat.tx_heartbeat_errors++; | |
1423 | if (txsr & ENTSR_OWC) ei_local->stat.tx_window_errors++; | |
1424 | } | |
1425 | } | |
1426 | ||
1427 | /** | |
1428 | * ei_tx_intr - transmit interrupt handler | |
1429 | * @dev: network device for which tx intr is handled | |
1430 | * | |
1431 | * We have finished a transmit: check for errors and then trigger the next | |
1432 | * packet to be sent. Called with lock held. | |
1433 | */ | |
1434 | ||
1435 | static void ei_tx_intr(struct net_device *dev) | |
1436 | { | |
1437 | long e8390_base = dev->base_addr; | |
1438 | struct ei_device *ei_local = (struct ei_device *) netdev_priv(dev); | |
1439 | int status = inb(e8390_base + EN0_TSR); | |
1440 | ||
1441 | /* | |
1442 | * There are two Tx buffers, see which one finished, and trigger | |
1443 | * the send of another one if it exists. | |
1444 | */ | |
1445 | ei_local->txqueue--; | |
1446 | ||
1447 | if (ei_local->tx1 < 0) | |
1448 | { | |
1449 | if (ei_local->lasttx != 1 && ei_local->lasttx != -1) | |
1450 | printk(KERN_ERR "%s: bogus last_tx_buffer %d, tx1=%d.\n", | |
1451 | ei_local->name, ei_local->lasttx, ei_local->tx1); | |
1452 | ei_local->tx1 = 0; | |
1453 | if (ei_local->tx2 > 0) | |
1454 | { | |
1455 | ei_local->txing = 1; | |
1456 | NS8390_trigger_send(dev, ei_local->tx2, ei_local->tx_start_page + 6); | |
1457 | dev->trans_start = jiffies; | |
1458 | ei_local->tx2 = -1, | |
1459 | ei_local->lasttx = 2; | |
1460 | } | |
1461 | else ei_local->lasttx = 20, ei_local->txing = 0; | |
1462 | } | |
1463 | else if (ei_local->tx2 < 0) | |
1464 | { | |
1465 | if (ei_local->lasttx != 2 && ei_local->lasttx != -2) | |
1466 | printk("%s: bogus last_tx_buffer %d, tx2=%d.\n", | |
1467 | ei_local->name, ei_local->lasttx, ei_local->tx2); | |
1468 | ei_local->tx2 = 0; | |
1469 | if (ei_local->tx1 > 0) | |
1470 | { | |
1471 | ei_local->txing = 1; | |
1472 | NS8390_trigger_send(dev, ei_local->tx1, ei_local->tx_start_page); | |
1473 | dev->trans_start = jiffies; | |
1474 | ei_local->tx1 = -1; | |
1475 | ei_local->lasttx = 1; | |
1476 | } | |
1477 | else | |
1478 | ei_local->lasttx = 10, ei_local->txing = 0; | |
1479 | } | |
1480 | // else printk(KERN_WARNING "%s: unexpected TX-done interrupt, lasttx=%d.\n", | |
1481 | // dev->name, ei_local->lasttx); | |
1482 | ||
1483 | /* Minimize Tx latency: update the statistics after we restart TXing. */ | |
1484 | if (status & ENTSR_COL) | |
1485 | ei_local->stat.collisions++; | |
1486 | if (status & ENTSR_PTX) | |
1487 | ei_local->stat.tx_packets++; | |
1488 | else | |
1489 | { | |
1490 | ei_local->stat.tx_errors++; | |
1491 | if (status & ENTSR_ABT) | |
1492 | { | |
1493 | ei_local->stat.tx_aborted_errors++; | |
1494 | ei_local->stat.collisions += 16; | |
1495 | } | |
1496 | if (status & ENTSR_CRS) | |
1497 | ei_local->stat.tx_carrier_errors++; | |
1498 | if (status & ENTSR_FU) | |
1499 | ei_local->stat.tx_fifo_errors++; | |
1500 | if (status & ENTSR_CDH) | |
1501 | ei_local->stat.tx_heartbeat_errors++; | |
1502 | if (status & ENTSR_OWC) | |
1503 | ei_local->stat.tx_window_errors++; | |
1504 | } | |
1505 | netif_wake_queue(dev); | |
1506 | } | |
1507 | ||
1508 | /** | |
1509 | * ei_receive - receive some packets | |
1510 | * @dev: network device with which receive will be run | |
1511 | * | |
1512 | * We have a good packet(s), get it/them out of the buffers. | |
1513 | * Called with lock held. | |
1514 | */ | |
1515 | ||
1516 | static void ei_receive(struct net_device *dev) | |
1517 | { | |
1518 | long e8390_base = dev->base_addr; | |
1519 | struct ei_device *ei_local = (struct ei_device *) netdev_priv(dev); | |
1520 | unsigned char rxing_page, this_frame, next_frame; | |
1521 | unsigned short current_offset; | |
1522 | int rx_pkt_count = 0; | |
1523 | struct e8390_pkt_hdr rx_frame; | |
1524 | ||
1525 | while (++rx_pkt_count < 10) | |
1526 | { | |
1527 | int pkt_len, pkt_stat; | |
1528 | ||
1529 | /* Get the rx page (incoming packet pointer). */ | |
1530 | rxing_page = inb_p(e8390_base + EN1_CURPAG -1); | |
1531 | ||
1532 | /* Remove one frame from the ring. Boundary is always a page behind. */ | |
1533 | this_frame = inb_p(e8390_base + EN0_BOUNDARY) + 1; | |
1534 | if (this_frame >= ei_local->stop_page) | |
1535 | this_frame = ei_local->rx_start_page; | |
1536 | ||
1537 | /* Someday we'll omit the previous, iff we never get this message. | |
1538 | (There is at least one clone claimed to have a problem.) | |
1539 | ||
1540 | Keep quiet if it looks like a card removal. One problem here | |
1541 | is that some clones crash in roughly the same way. | |
1542 | */ | |
1543 | if (ei_debug > 0 && this_frame != ei_local->current_page && (this_frame!=0x0 || rxing_page!=0xFF)) | |
1544 | printk(KERN_ERR "%s: mismatched read page pointers %2x vs %2x.\n", | |
1545 | dev->name, this_frame, ei_local->current_page); | |
1546 | ||
1547 | if (this_frame == rxing_page) /* Read all the frames? */ | |
1548 | break; /* Done for now */ | |
1549 | ||
1550 | current_offset = this_frame << 8; | |
1551 | ei_get_8390_hdr(dev, &rx_frame, this_frame); | |
1552 | ||
1553 | pkt_len = rx_frame.count - sizeof(struct e8390_pkt_hdr); | |
1554 | pkt_stat = rx_frame.status; | |
1555 | ||
1556 | next_frame = this_frame + 1 + ((pkt_len+4)>>8); | |
1557 | ||
1558 | if (pkt_len < 60 || pkt_len > 1518) | |
1559 | { | |
1560 | if (ei_debug) | |
1561 | printk(KERN_DEBUG "%s: bogus packet size: %d, status=%#2x nxpg=%#2x.\n", | |
1562 | dev->name, rx_frame.count, rx_frame.status, | |
1563 | rx_frame.next); | |
1564 | ei_local->stat.rx_errors++; | |
1565 | ei_local->stat.rx_length_errors++; | |
1566 | } | |
1567 | else if ((pkt_stat & 0x0F) == ENRSR_RXOK) | |
1568 | { | |
1569 | struct sk_buff *skb; | |
1570 | ||
1571 | skb = dev_alloc_skb(pkt_len+2); | |
1572 | if (skb == NULL) | |
1573 | { | |
1574 | if (ei_debug > 1) | |
1575 | printk(KERN_DEBUG "%s: Couldn't allocate a sk_buff of size %d.\n", | |
1576 | dev->name, pkt_len); | |
1577 | ei_local->stat.rx_dropped++; | |
1578 | break; | |
1579 | } | |
1580 | else | |
1581 | { | |
1582 | skb_reserve(skb,2); /* IP headers on 16 byte boundaries */ | |
1583 | skb->dev = dev; | |
1584 | skb_put(skb, pkt_len); /* Make room */ | |
1585 | ei_block_input(dev, pkt_len, skb, current_offset + sizeof(rx_frame)); | |
1586 | skb->protocol=eth_type_trans(skb,dev); | |
1587 | netif_rx(skb); | |
1588 | dev->last_rx = jiffies; | |
1589 | ei_local->stat.rx_packets++; | |
1590 | ei_local->stat.rx_bytes += pkt_len; | |
1591 | if (pkt_stat & ENRSR_PHY) | |
1592 | ei_local->stat.multicast++; | |
1593 | } | |
1594 | } | |
1595 | else | |
1596 | { | |
1597 | if (ei_debug) | |
1598 | printk(KERN_DEBUG "%s: bogus packet: status=%#2x nxpg=%#2x size=%d\n", | |
1599 | dev->name, rx_frame.status, rx_frame.next, | |
1600 | rx_frame.count); | |
1601 | ei_local->stat.rx_errors++; | |
1602 | /* NB: The NIC counts CRC, frame and missed errors. */ | |
1603 | if (pkt_stat & ENRSR_FO) | |
1604 | ei_local->stat.rx_fifo_errors++; | |
1605 | } | |
1606 | next_frame = rx_frame.next; | |
1607 | ||
1608 | /* This _should_ never happen: it's here for avoiding bad clones. */ | |
1609 | if (next_frame >= ei_local->stop_page) { | |
1610 | printk("%s: next frame inconsistency, %#2x\n", dev->name, | |
1611 | next_frame); | |
1612 | next_frame = ei_local->rx_start_page; | |
1613 | } | |
1614 | ei_local->current_page = next_frame; | |
1615 | outb_p(next_frame-1, e8390_base+EN0_BOUNDARY); | |
1616 | } | |
1617 | ||
1618 | return; | |
1619 | } | |
1620 | ||
1621 | /** | |
1622 | * ei_rx_overrun - handle receiver overrun | |
1623 | * @dev: network device which threw exception | |
1624 | * | |
1625 | * We have a receiver overrun: we have to kick the 8390 to get it started | |
1626 | * again. Problem is that you have to kick it exactly as NS prescribes in | |
1627 | * the updated datasheets, or "the NIC may act in an unpredictable manner." | |
1628 | * This includes causing "the NIC to defer indefinitely when it is stopped | |
1629 | * on a busy network." Ugh. | |
1630 | * Called with lock held. Don't call this with the interrupts off or your | |
1631 | * computer will hate you - it takes 10ms or so. | |
1632 | */ | |
1633 | ||
1634 | static void ei_rx_overrun(struct net_device *dev) | |
1635 | { | |
1636 | axnet_dev_t *info = (axnet_dev_t *)dev; | |
1637 | long e8390_base = dev->base_addr; | |
1638 | unsigned char was_txing, must_resend = 0; | |
1639 | struct ei_device *ei_local = (struct ei_device *) netdev_priv(dev); | |
1640 | ||
1641 | /* | |
1642 | * Record whether a Tx was in progress and then issue the | |
1643 | * stop command. | |
1644 | */ | |
1645 | was_txing = inb_p(e8390_base+E8390_CMD) & E8390_TRANS; | |
1646 | outb_p(E8390_NODMA+E8390_PAGE0+E8390_STOP, e8390_base+E8390_CMD); | |
1647 | ||
1648 | if (ei_debug > 1) | |
1649 | printk(KERN_DEBUG "%s: Receiver overrun.\n", dev->name); | |
1650 | ei_local->stat.rx_over_errors++; | |
1651 | ||
1652 | /* | |
1653 | * Wait a full Tx time (1.2ms) + some guard time, NS says 1.6ms total. | |
1654 | * Early datasheets said to poll the reset bit, but now they say that | |
1655 | * it "is not a reliable indicator and subsequently should be ignored." | |
1656 | * We wait at least 10ms. | |
1657 | */ | |
1658 | ||
1659 | mdelay(10); | |
1660 | ||
1661 | /* | |
1662 | * Reset RBCR[01] back to zero as per magic incantation. | |
1663 | */ | |
1664 | outb_p(0x00, e8390_base+EN0_RCNTLO); | |
1665 | outb_p(0x00, e8390_base+EN0_RCNTHI); | |
1666 | ||
1667 | /* | |
1668 | * See if any Tx was interrupted or not. According to NS, this | |
1669 | * step is vital, and skipping it will cause no end of havoc. | |
1670 | */ | |
1671 | ||
1672 | if (was_txing) | |
1673 | { | |
1674 | unsigned char tx_completed = inb_p(e8390_base+EN0_ISR) & (ENISR_TX+ENISR_TX_ERR); | |
1675 | if (!tx_completed) | |
1676 | must_resend = 1; | |
1677 | } | |
1678 | ||
1679 | /* | |
1680 | * Have to enter loopback mode and then restart the NIC before | |
1681 | * you are allowed to slurp packets up off the ring. | |
1682 | */ | |
1683 | outb_p(E8390_TXOFF, e8390_base + EN0_TXCR); | |
1684 | outb_p(E8390_NODMA + E8390_PAGE0 + E8390_START, e8390_base + E8390_CMD); | |
1685 | ||
1686 | /* | |
1687 | * Clear the Rx ring of all the debris, and ack the interrupt. | |
1688 | */ | |
1689 | ei_receive(dev); | |
1690 | ||
1691 | /* | |
1692 | * Leave loopback mode, and resend any packet that got stopped. | |
1693 | */ | |
1694 | outb_p(E8390_TXCONFIG | info->duplex_flag, e8390_base + EN0_TXCR); | |
1695 | if (must_resend) | |
1696 | outb_p(E8390_NODMA + E8390_PAGE0 + E8390_START + E8390_TRANS, e8390_base + E8390_CMD); | |
1697 | } | |
1698 | ||
1699 | /* | |
1700 | * Collect the stats. This is called unlocked and from several contexts. | |
1701 | */ | |
1702 | ||
1703 | static struct net_device_stats *get_stats(struct net_device *dev) | |
1704 | { | |
1705 | long ioaddr = dev->base_addr; | |
1706 | struct ei_device *ei_local = (struct ei_device *) netdev_priv(dev); | |
1707 | unsigned long flags; | |
1708 | ||
1709 | /* If the card is stopped, just return the present stats. */ | |
1710 | if (!netif_running(dev)) | |
1711 | return &ei_local->stat; | |
1712 | ||
1713 | spin_lock_irqsave(&ei_local->page_lock,flags); | |
1714 | /* Read the counter registers, assuming we are in page 0. */ | |
1715 | ei_local->stat.rx_frame_errors += inb_p(ioaddr + EN0_COUNTER0); | |
1716 | ei_local->stat.rx_crc_errors += inb_p(ioaddr + EN0_COUNTER1); | |
1717 | ei_local->stat.rx_missed_errors+= inb_p(ioaddr + EN0_COUNTER2); | |
1718 | spin_unlock_irqrestore(&ei_local->page_lock, flags); | |
1719 | ||
1720 | return &ei_local->stat; | |
1721 | } | |
1722 | ||
1723 | /** | |
1724 | * do_set_multicast_list - set/clear multicast filter | |
1725 | * @dev: net device for which multicast filter is adjusted | |
1726 | * | |
1727 | * Set or clear the multicast filter for this adaptor. May be called | |
1728 | * from a BH in 2.1.x. Must be called with lock held. | |
1729 | */ | |
1730 | ||
1731 | static void do_set_multicast_list(struct net_device *dev) | |
1732 | { | |
1733 | long e8390_base = dev->base_addr; | |
1734 | ||
1735 | if(dev->flags&IFF_PROMISC) | |
1736 | outb_p(E8390_RXCONFIG | 0x58, e8390_base + EN0_RXCR); | |
1737 | else if(dev->flags&IFF_ALLMULTI || dev->mc_list) | |
1738 | outb_p(E8390_RXCONFIG | 0x48, e8390_base + EN0_RXCR); | |
1739 | else | |
1740 | outb_p(E8390_RXCONFIG | 0x40, e8390_base + EN0_RXCR); | |
1741 | } | |
1742 | ||
1743 | /* | |
1744 | * Called without lock held. This is invoked from user context and may | |
1745 | * be parallel to just about everything else. Its also fairly quick and | |
1746 | * not called too often. Must protect against both bh and irq users | |
1747 | */ | |
1748 | ||
1749 | static void set_multicast_list(struct net_device *dev) | |
1750 | { | |
1751 | unsigned long flags; | |
1752 | ||
1753 | spin_lock_irqsave(&dev_lock(dev), flags); | |
1754 | do_set_multicast_list(dev); | |
1755 | spin_unlock_irqrestore(&dev_lock(dev), flags); | |
1756 | } | |
1757 | ||
1758 | /** | |
1759 | * axdev_setup - init rest of 8390 device struct | |
1760 | * @dev: network device structure to init | |
1761 | * | |
1762 | * Initialize the rest of the 8390 device structure. Do NOT __init | |
1763 | * this, as it is used by 8390 based modular drivers too. | |
1764 | */ | |
1765 | ||
1766 | static void axdev_setup(struct net_device *dev) | |
1767 | { | |
1768 | struct ei_device *ei_local; | |
1769 | if (ei_debug > 1) | |
1770 | printk(version_8390); | |
1771 | ||
1772 | SET_MODULE_OWNER(dev); | |
1773 | ||
1774 | ||
1775 | ei_local = (struct ei_device *)netdev_priv(dev); | |
1776 | spin_lock_init(&ei_local->page_lock); | |
1777 | ||
1778 | dev->hard_start_xmit = &ei_start_xmit; | |
1779 | dev->get_stats = get_stats; | |
1780 | dev->set_multicast_list = &set_multicast_list; | |
1781 | ||
1782 | ether_setup(dev); | |
1783 | } | |
1784 | ||
1785 | /* This page of functions should be 8390 generic */ | |
1786 | /* Follow National Semi's recommendations for initializing the "NIC". */ | |
1787 | ||
1788 | /** | |
1789 | * AX88190_init - initialize 8390 hardware | |
1790 | * @dev: network device to initialize | |
1791 | * @startp: boolean. non-zero value to initiate chip processing | |
1792 | * | |
1793 | * Must be called with lock held. | |
1794 | */ | |
1795 | ||
1796 | static void AX88190_init(struct net_device *dev, int startp) | |
1797 | { | |
1798 | axnet_dev_t *info = PRIV(dev); | |
1799 | long e8390_base = dev->base_addr; | |
1800 | struct ei_device *ei_local = (struct ei_device *) netdev_priv(dev); | |
1801 | int i; | |
1802 | int endcfg = ei_local->word16 ? (0x48 | ENDCFG_WTS) : 0x48; | |
1803 | ||
1804 | if(sizeof(struct e8390_pkt_hdr)!=4) | |
1805 | panic("8390.c: header struct mispacked\n"); | |
1806 | /* Follow National Semi's recommendations for initing the DP83902. */ | |
1807 | outb_p(E8390_NODMA+E8390_PAGE0+E8390_STOP, e8390_base+E8390_CMD); /* 0x21 */ | |
1808 | outb_p(endcfg, e8390_base + EN0_DCFG); /* 0x48 or 0x49 */ | |
1809 | /* Clear the remote byte count registers. */ | |
1810 | outb_p(0x00, e8390_base + EN0_RCNTLO); | |
1811 | outb_p(0x00, e8390_base + EN0_RCNTHI); | |
1812 | /* Set to monitor and loopback mode -- this is vital!. */ | |
1813 | outb_p(E8390_RXOFF|0x40, e8390_base + EN0_RXCR); /* 0x60 */ | |
1814 | outb_p(E8390_TXOFF, e8390_base + EN0_TXCR); /* 0x02 */ | |
1815 | /* Set the transmit page and receive ring. */ | |
1816 | outb_p(ei_local->tx_start_page, e8390_base + EN0_TPSR); | |
1817 | ei_local->tx1 = ei_local->tx2 = 0; | |
1818 | outb_p(ei_local->rx_start_page, e8390_base + EN0_STARTPG); | |
1819 | outb_p(ei_local->stop_page-1, e8390_base + EN0_BOUNDARY); /* 3c503 says 0x3f,NS0x26*/ | |
1820 | ei_local->current_page = ei_local->rx_start_page; /* assert boundary+1 */ | |
1821 | outb_p(ei_local->stop_page, e8390_base + EN0_STOPPG); | |
1822 | /* Clear the pending interrupts and mask. */ | |
1823 | outb_p(0xFF, e8390_base + EN0_ISR); | |
1824 | outb_p(0x00, e8390_base + EN0_IMR); | |
1825 | ||
1826 | /* Copy the station address into the DS8390 registers. */ | |
1827 | ||
1828 | outb_p(E8390_NODMA + E8390_PAGE1 + E8390_STOP, e8390_base+E8390_CMD); /* 0x61 */ | |
1829 | for(i = 0; i < 6; i++) | |
1830 | { | |
1831 | outb_p(dev->dev_addr[i], e8390_base + EN1_PHYS_SHIFT(i)); | |
1832 | if(inb_p(e8390_base + EN1_PHYS_SHIFT(i))!=dev->dev_addr[i]) | |
1833 | printk(KERN_ERR "Hw. address read/write mismap %d\n",i); | |
1834 | } | |
1835 | /* | |
1836 | * Initialize the multicast list to accept-all. If we enable multicast | |
1837 | * the higher levels can do the filtering. | |
1838 | */ | |
1839 | for (i = 0; i < 8; i++) | |
1840 | outb_p(0xff, e8390_base + EN1_MULT + i); | |
1841 | ||
1842 | outb_p(ei_local->rx_start_page, e8390_base + EN1_CURPAG); | |
1843 | outb_p(E8390_NODMA+E8390_PAGE0+E8390_STOP, e8390_base+E8390_CMD); | |
1844 | ||
1845 | netif_start_queue(dev); | |
1846 | ei_local->tx1 = ei_local->tx2 = 0; | |
1847 | ei_local->txing = 0; | |
1848 | ||
1849 | if (startp) | |
1850 | { | |
1851 | outb_p(0xff, e8390_base + EN0_ISR); | |
1852 | outb_p(ENISR_ALL, e8390_base + EN0_IMR); | |
1853 | outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, e8390_base+E8390_CMD); | |
1854 | outb_p(E8390_TXCONFIG | info->duplex_flag, | |
1855 | e8390_base + EN0_TXCR); /* xmit on. */ | |
1856 | /* 3c503 TechMan says rxconfig only after the NIC is started. */ | |
1857 | outb_p(E8390_RXCONFIG | 0x40, e8390_base + EN0_RXCR); /* rx on, */ | |
1858 | do_set_multicast_list(dev); /* (re)load the mcast table */ | |
1859 | } | |
1860 | } | |
1861 | ||
1862 | /* Trigger a transmit start, assuming the length is valid. | |
1863 | Always called with the page lock held */ | |
1864 | ||
1865 | static void NS8390_trigger_send(struct net_device *dev, unsigned int length, | |
1866 | int start_page) | |
1867 | { | |
1868 | long e8390_base = dev->base_addr; | |
1869 | struct ei_device *ei_local __attribute((unused)) = (struct ei_device *) netdev_priv(dev); | |
1870 | ||
1871 | if (inb_p(e8390_base) & E8390_TRANS) | |
1872 | { | |
1873 | printk(KERN_WARNING "%s: trigger_send() called with the transmitter busy.\n", | |
1874 | dev->name); | |
1875 | return; | |
1876 | } | |
1877 | outb_p(length & 0xff, e8390_base + EN0_TCNTLO); | |
1878 | outb_p(length >> 8, e8390_base + EN0_TCNTHI); | |
1879 | outb_p(start_page, e8390_base + EN0_TPSR); | |
1880 | outb_p(E8390_NODMA+E8390_TRANS+E8390_START, e8390_base+E8390_CMD); | |
1881 | } |