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