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