aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/pcmcia/3c589_cs.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/pcmcia/3c589_cs.c')
-rw-r--r--drivers/net/pcmcia/3c589_cs.c303
1 files changed, 151 insertions, 152 deletions
diff --git a/drivers/net/pcmcia/3c589_cs.c b/drivers/net/pcmcia/3c589_cs.c
index 091e0b00043e..ce63c3773b4c 100644
--- a/drivers/net/pcmcia/3c589_cs.c
+++ b/drivers/net/pcmcia/3c589_cs.c
@@ -1,20 +1,20 @@
1/*====================================================================== 1/*======================================================================
2 2
3 A PCMCIA ethernet driver for the 3com 3c589 card. 3 A PCMCIA ethernet driver for the 3com 3c589 card.
4 4
5 Copyright (C) 1999 David A. Hinds -- dahinds@users.sourceforge.net 5 Copyright (C) 1999 David A. Hinds -- dahinds@users.sourceforge.net
6 6
7 3c589_cs.c 1.162 2001/10/13 00:08:50 7 3c589_cs.c 1.162 2001/10/13 00:08:50
8 8
9 The network driver code is based on Donald Becker's 3c589 code: 9 The network driver code is based on Donald Becker's 3c589 code:
10 10
11 Written 1994 by Donald Becker. 11 Written 1994 by Donald Becker.
12 Copyright 1993 United States Government as represented by the 12 Copyright 1993 United States Government as represented by the
13 Director, National Security Agency. This software may be used and 13 Director, National Security Agency. This software may be used and
14 distributed according to the terms of the GNU General Public License, 14 distributed according to the terms of the GNU General Public License,
15 incorporated herein by reference. 15 incorporated herein by reference.
16 Donald Becker may be reached at becker@scyld.com 16 Donald Becker may be reached at becker@scyld.com
17 17
18 Updated for 2.5.x by Alan Cox <alan@lxorguk.ukuu.org.uk> 18 Updated for 2.5.x by Alan Cox <alan@lxorguk.ukuu.org.uk>
19 19
20======================================================================*/ 20======================================================================*/
@@ -69,31 +69,54 @@
69/* The top five bits written to EL3_CMD are a command, the lower 69/* The top five bits written to EL3_CMD are a command, the lower
70 11 bits are the parameter, if applicable. */ 70 11 bits are the parameter, if applicable. */
71enum c509cmd { 71enum c509cmd {
72 TotalReset = 0<<11, SelectWindow = 1<<11, StartCoax = 2<<11, 72 TotalReset = 0<<11,
73 RxDisable = 3<<11, RxEnable = 4<<11, RxReset = 5<<11, RxDiscard = 8<<11, 73 SelectWindow = 1<<11,
74 TxEnable = 9<<11, TxDisable = 10<<11, TxReset = 11<<11, 74 StartCoax = 2<<11,
75 FakeIntr = 12<<11, AckIntr = 13<<11, SetIntrEnb = 14<<11, 75 RxDisable = 3<<11,
76 SetStatusEnb = 15<<11, SetRxFilter = 16<<11, SetRxThreshold = 17<<11, 76 RxEnable = 4<<11,
77 SetTxThreshold = 18<<11, SetTxStart = 19<<11, StatsEnable = 21<<11, 77 RxReset = 5<<11,
78 StatsDisable = 22<<11, StopCoax = 23<<11, 78 RxDiscard = 8<<11,
79 TxEnable = 9<<11,
80 TxDisable = 10<<11,
81 TxReset = 11<<11,
82 FakeIntr = 12<<11,
83 AckIntr = 13<<11,
84 SetIntrEnb = 14<<11,
85 SetStatusEnb = 15<<11,
86 SetRxFilter = 16<<11,
87 SetRxThreshold = 17<<11,
88 SetTxThreshold = 18<<11,
89 SetTxStart = 19<<11,
90 StatsEnable = 21<<11,
91 StatsDisable = 22<<11,
92 StopCoax = 23<<11
79}; 93};
80 94
81enum c509status { 95enum c509status {
82 IntLatch = 0x0001, AdapterFailure = 0x0002, TxComplete = 0x0004, 96 IntLatch = 0x0001,
83 TxAvailable = 0x0008, RxComplete = 0x0010, RxEarly = 0x0020, 97 AdapterFailure = 0x0002,
84 IntReq = 0x0040, StatsFull = 0x0080, CmdBusy = 0x1000 98 TxComplete = 0x0004,
99 TxAvailable = 0x0008,
100 RxComplete = 0x0010,
101 RxEarly = 0x0020,
102 IntReq = 0x0040,
103 StatsFull = 0x0080,
104 CmdBusy = 0x1000
85}; 105};
86 106
87/* The SetRxFilter command accepts the following classes: */ 107/* The SetRxFilter command accepts the following classes: */
88enum RxFilter { 108enum RxFilter {
89 RxStation = 1, RxMulticast = 2, RxBroadcast = 4, RxProm = 8 109 RxStation = 1,
110 RxMulticast = 2,
111 RxBroadcast = 4,
112 RxProm = 8
90}; 113};
91 114
92/* Register window 1 offsets, the window used in normal operation. */ 115/* Register window 1 offsets, the window used in normal operation. */
93#define TX_FIFO 0x00 116#define TX_FIFO 0x00
94#define RX_FIFO 0x00 117#define RX_FIFO 0x00
95#define RX_STATUS 0x08 118#define RX_STATUS 0x08
96#define TX_STATUS 0x0B 119#define TX_STATUS 0x0B
97#define TX_FREE 0x0C /* Remaining free bytes in Tx buffer. */ 120#define TX_FREE 0x0C /* Remaining free bytes in Tx buffer. */
98 121
99#define WN0_IRQ 0x08 /* Window 0: Set IRQ line in bits 12-15. */ 122#define WN0_IRQ 0x08 /* Window 0: Set IRQ line in bits 12-15. */
@@ -106,13 +129,12 @@ enum RxFilter {
106 129
107struct el3_private { 130struct el3_private {
108 struct pcmcia_device *p_dev; 131 struct pcmcia_device *p_dev;
109 dev_node_t node; 132 /* For transceiver monitoring */
110 /* For transceiver monitoring */ 133 struct timer_list media;
111 struct timer_list media; 134 u16 media_status;
112 u16 media_status; 135 u16 fast_poll;
113 u16 fast_poll; 136 unsigned long last_irq;
114 unsigned long last_irq; 137 spinlock_t lock;
115 spinlock_t lock;
116}; 138};
117 139
118static const char *if_names[] = { "auto", "10baseT", "10base2", "AUI" }; 140static const char *if_names[] = { "auto", "10baseT", "10base2", "AUI" };
@@ -164,15 +186,15 @@ static void tc589_detach(struct pcmcia_device *p_dev);
164======================================================================*/ 186======================================================================*/
165 187
166static const struct net_device_ops el3_netdev_ops = { 188static const struct net_device_ops el3_netdev_ops = {
167 .ndo_open = el3_open, 189 .ndo_open = el3_open,
168 .ndo_stop = el3_close, 190 .ndo_stop = el3_close,
169 .ndo_start_xmit = el3_start_xmit, 191 .ndo_start_xmit = el3_start_xmit,
170 .ndo_tx_timeout = el3_tx_timeout, 192 .ndo_tx_timeout = el3_tx_timeout,
171 .ndo_set_config = el3_config, 193 .ndo_set_config = el3_config,
172 .ndo_get_stats = el3_get_stats, 194 .ndo_get_stats = el3_get_stats,
173 .ndo_set_multicast_list = set_multicast_list, 195 .ndo_set_multicast_list = set_multicast_list,
174 .ndo_change_mtu = eth_change_mtu, 196 .ndo_change_mtu = eth_change_mtu,
175 .ndo_set_mac_address = eth_mac_addr, 197 .ndo_set_mac_address = eth_mac_addr,
176 .ndo_validate_addr = eth_validate_addr, 198 .ndo_validate_addr = eth_validate_addr,
177}; 199};
178 200
@@ -194,8 +216,7 @@ static int tc589_probe(struct pcmcia_device *link)
194 spin_lock_init(&lp->lock); 216 spin_lock_init(&lp->lock);
195 link->io.NumPorts1 = 16; 217 link->io.NumPorts1 = 16;
196 link->io.Attributes1 = IO_DATA_PATH_WIDTH_16; 218 link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
197 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING; 219
198 link->irq.Handler = &el3_interrupt;
199 link->conf.Attributes = CONF_ENABLE_IRQ; 220 link->conf.Attributes = CONF_ENABLE_IRQ;
200 link->conf.IntType = INT_MEMORY_AND_IO; 221 link->conf.IntType = INT_MEMORY_AND_IO;
201 link->conf.ConfigIndex = 1; 222 link->conf.ConfigIndex = 1;
@@ -223,8 +244,7 @@ static void tc589_detach(struct pcmcia_device *link)
223 244
224 dev_dbg(&link->dev, "3c589_detach\n"); 245 dev_dbg(&link->dev, "3c589_detach\n");
225 246
226 if (link->dev_node) 247 unregister_netdev(dev);
227 unregister_netdev(dev);
228 248
229 tc589_release(link); 249 tc589_release(link);
230 250
@@ -236,20 +256,19 @@ static void tc589_detach(struct pcmcia_device *link)
236 tc589_config() is scheduled to run after a CARD_INSERTION event 256 tc589_config() is scheduled to run after a CARD_INSERTION event
237 is received, to configure the PCMCIA socket, and to make the 257 is received, to configure the PCMCIA socket, and to make the
238 ethernet device available to the system. 258 ethernet device available to the system.
239 259
240======================================================================*/ 260======================================================================*/
241 261
242static int tc589_config(struct pcmcia_device *link) 262static int tc589_config(struct pcmcia_device *link)
243{ 263{
244 struct net_device *dev = link->priv; 264 struct net_device *dev = link->priv;
245 struct el3_private *lp = netdev_priv(dev);
246 __be16 *phys_addr; 265 __be16 *phys_addr;
247 int ret, i, j, multi = 0, fifo; 266 int ret, i, j, multi = 0, fifo;
248 unsigned int ioaddr; 267 unsigned int ioaddr;
249 char *ram_split[] = {"5:3", "3:1", "1:1", "3:5"}; 268 char *ram_split[] = {"5:3", "3:1", "1:1", "3:5"};
250 u8 *buf; 269 u8 *buf;
251 size_t len; 270 size_t len;
252 271
253 dev_dbg(&link->dev, "3c589_config\n"); 272 dev_dbg(&link->dev, "3c589_config\n");
254 273
255 phys_addr = (__be16 *)dev->dev_addr; 274 phys_addr = (__be16 *)dev->dev_addr;
@@ -271,15 +290,15 @@ static int tc589_config(struct pcmcia_device *link)
271 if (i != 0) 290 if (i != 0)
272 goto failed; 291 goto failed;
273 292
274 ret = pcmcia_request_irq(link, &link->irq); 293 ret = pcmcia_request_irq(link, el3_interrupt);
275 if (ret) 294 if (ret)
276 goto failed; 295 goto failed;
277 296
278 ret = pcmcia_request_configuration(link, &link->conf); 297 ret = pcmcia_request_configuration(link, &link->conf);
279 if (ret) 298 if (ret)
280 goto failed; 299 goto failed;
281 300
282 dev->irq = link->irq.AssignedIRQ; 301 dev->irq = link->irq;
283 dev->base_addr = link->io.BasePort1; 302 dev->base_addr = link->io.BasePort1;
284 ioaddr = dev->base_addr; 303 ioaddr = dev->base_addr;
285 EL3WINDOW(0); 304 EL3WINDOW(0);
@@ -312,25 +331,20 @@ static int tc589_config(struct pcmcia_device *link)
312 dev->if_port = if_port; 331 dev->if_port = if_port;
313 else 332 else
314 printk(KERN_ERR "3c589_cs: invalid if_port requested\n"); 333 printk(KERN_ERR "3c589_cs: invalid if_port requested\n");
315 334
316 link->dev_node = &lp->node;
317 SET_NETDEV_DEV(dev, &link->dev); 335 SET_NETDEV_DEV(dev, &link->dev);
318 336
319 if (register_netdev(dev) != 0) { 337 if (register_netdev(dev) != 0) {
320 printk(KERN_ERR "3c589_cs: register_netdev() failed\n"); 338 printk(KERN_ERR "3c589_cs: register_netdev() failed\n");
321 link->dev_node = NULL;
322 goto failed; 339 goto failed;
323 } 340 }
324 341
325 strcpy(lp->node.dev_name, dev->name); 342 netdev_info(dev, "3Com 3c%s, io %#3lx, irq %d, hw_addr %pM\n",
326 343 (multi ? "562" : "589"), dev->base_addr, dev->irq,
327 printk(KERN_INFO "%s: 3Com 3c%s, io %#3lx, irq %d, " 344 dev->dev_addr);
328 "hw_addr %pM\n", 345 netdev_info(dev, " %dK FIFO split %s Rx:Tx, %s xcvr\n",
329 dev->name, (multi ? "562" : "589"), dev->base_addr, dev->irq, 346 (fifo & 7) ? 32 : 8, ram_split[(fifo >> 16) & 3],
330 dev->dev_addr); 347 if_names[dev->if_port]);
331 printk(KERN_INFO " %dK FIFO split %s Rx:Tx, %s xcvr\n",
332 (fifo & 7) ? 32 : 8, ram_split[(fifo >> 16) & 3],
333 if_names[dev->if_port]);
334 return 0; 348 return 0;
335 349
336failed: 350failed:
@@ -343,7 +357,7 @@ failed:
343 After a card is removed, tc589_release() will unregister the net 357 After a card is removed, tc589_release() will unregister the net
344 device, and release the PCMCIA configuration. If the device is 358 device, and release the PCMCIA configuration. If the device is
345 still open, this will be postponed until it is closed. 359 still open, this will be postponed until it is closed.
346 360
347======================================================================*/ 361======================================================================*/
348 362
349static void tc589_release(struct pcmcia_device *link) 363static void tc589_release(struct pcmcia_device *link)
@@ -365,7 +379,7 @@ static int tc589_resume(struct pcmcia_device *link)
365{ 379{
366 struct net_device *dev = link->priv; 380 struct net_device *dev = link->priv;
367 381
368 if (link->open) { 382 if (link->open) {
369 tc589_reset(dev); 383 tc589_reset(dev);
370 netif_device_attach(dev); 384 netif_device_attach(dev);
371 } 385 }
@@ -385,8 +399,7 @@ static void tc589_wait_for_completion(struct net_device *dev, int cmd)
385 while (--i > 0) 399 while (--i > 0)
386 if (!(inw(dev->base_addr + EL3_STATUS) & 0x1000)) break; 400 if (!(inw(dev->base_addr + EL3_STATUS) & 0x1000)) break;
387 if (i == 0) 401 if (i == 0)
388 printk(KERN_WARNING "%s: command 0x%04x did not complete!\n", 402 netdev_warn(dev, "command 0x%04x did not complete!\n", cmd);
389 dev->name, cmd);
390} 403}
391 404
392/* 405/*
@@ -412,7 +425,7 @@ static void tc589_set_xcvr(struct net_device *dev, int if_port)
412{ 425{
413 struct el3_private *lp = netdev_priv(dev); 426 struct el3_private *lp = netdev_priv(dev);
414 unsigned int ioaddr = dev->base_addr; 427 unsigned int ioaddr = dev->base_addr;
415 428
416 EL3WINDOW(0); 429 EL3WINDOW(0);
417 switch (if_port) { 430 switch (if_port) {
418 case 0: case 1: outw(0, ioaddr + 6); break; 431 case 0: case 1: outw(0, ioaddr + 6); break;
@@ -435,14 +448,13 @@ static void dump_status(struct net_device *dev)
435{ 448{
436 unsigned int ioaddr = dev->base_addr; 449 unsigned int ioaddr = dev->base_addr;
437 EL3WINDOW(1); 450 EL3WINDOW(1);
438 printk(KERN_INFO " irq status %04x, rx status %04x, tx status " 451 netdev_info(dev, " irq status %04x, rx status %04x, tx status %02x tx free %04x\n",
439 "%02x tx free %04x\n", inw(ioaddr+EL3_STATUS), 452 inw(ioaddr+EL3_STATUS), inw(ioaddr+RX_STATUS),
440 inw(ioaddr+RX_STATUS), inb(ioaddr+TX_STATUS), 453 inb(ioaddr+TX_STATUS), inw(ioaddr+TX_FREE));
441 inw(ioaddr+TX_FREE));
442 EL3WINDOW(4); 454 EL3WINDOW(4);
443 printk(KERN_INFO " diagnostics: fifo %04x net %04x ethernet %04x" 455 netdev_info(dev, " diagnostics: fifo %04x net %04x ethernet %04x media %04x\n",
444 " media %04x\n", inw(ioaddr+0x04), inw(ioaddr+0x06), 456 inw(ioaddr+0x04), inw(ioaddr+0x06), inw(ioaddr+0x08),
445 inw(ioaddr+0x08), inw(ioaddr+0x0a)); 457 inw(ioaddr+0x0a));
446 EL3WINDOW(1); 458 EL3WINDOW(1);
447} 459}
448 460
@@ -451,18 +463,18 @@ static void tc589_reset(struct net_device *dev)
451{ 463{
452 unsigned int ioaddr = dev->base_addr; 464 unsigned int ioaddr = dev->base_addr;
453 int i; 465 int i;
454 466
455 EL3WINDOW(0); 467 EL3WINDOW(0);
456 outw(0x0001, ioaddr + 4); /* Activate board. */ 468 outw(0x0001, ioaddr + 4); /* Activate board. */
457 outw(0x3f00, ioaddr + 8); /* Set the IRQ line. */ 469 outw(0x3f00, ioaddr + 8); /* Set the IRQ line. */
458 470
459 /* Set the station address in window 2. */ 471 /* Set the station address in window 2. */
460 EL3WINDOW(2); 472 EL3WINDOW(2);
461 for (i = 0; i < 6; i++) 473 for (i = 0; i < 6; i++)
462 outb(dev->dev_addr[i], ioaddr + i); 474 outb(dev->dev_addr[i], ioaddr + i);
463 475
464 tc589_set_xcvr(dev, dev->if_port); 476 tc589_set_xcvr(dev, dev->if_port);
465 477
466 /* Switch to the stats window, and clear all stats by reading. */ 478 /* Switch to the stats window, and clear all stats by reading. */
467 outw(StatsDisable, ioaddr + EL3_CMD); 479 outw(StatsDisable, ioaddr + EL3_CMD);
468 EL3WINDOW(6); 480 EL3WINDOW(6);
@@ -470,7 +482,7 @@ static void tc589_reset(struct net_device *dev)
470 inb(ioaddr+i); 482 inb(ioaddr+i);
471 inw(ioaddr + 10); 483 inw(ioaddr + 10);
472 inw(ioaddr + 12); 484 inw(ioaddr + 12);
473 485
474 /* Switch to register set 1 for normal use. */ 486 /* Switch to register set 1 for normal use. */
475 EL3WINDOW(1); 487 EL3WINDOW(1);
476 488
@@ -504,8 +516,7 @@ static int el3_config(struct net_device *dev, struct ifmap *map)
504 if ((map->port != (u_char)(-1)) && (map->port != dev->if_port)) { 516 if ((map->port != (u_char)(-1)) && (map->port != dev->if_port)) {
505 if (map->port <= 3) { 517 if (map->port <= 3) {
506 dev->if_port = map->port; 518 dev->if_port = map->port;
507 printk(KERN_INFO "%s: switched to %s port\n", 519 netdev_info(dev, "switched to %s port\n", if_names[dev->if_port]);
508 dev->name, if_names[dev->if_port]);
509 tc589_set_xcvr(dev, dev->if_port); 520 tc589_set_xcvr(dev, dev->if_port);
510 } else 521 } else
511 return -EINVAL; 522 return -EINVAL;
@@ -517,13 +528,13 @@ static int el3_open(struct net_device *dev)
517{ 528{
518 struct el3_private *lp = netdev_priv(dev); 529 struct el3_private *lp = netdev_priv(dev);
519 struct pcmcia_device *link = lp->p_dev; 530 struct pcmcia_device *link = lp->p_dev;
520 531
521 if (!pcmcia_dev_present(link)) 532 if (!pcmcia_dev_present(link))
522 return -ENODEV; 533 return -ENODEV;
523 534
524 link->open++; 535 link->open++;
525 netif_start_queue(dev); 536 netif_start_queue(dev);
526 537
527 tc589_reset(dev); 538 tc589_reset(dev);
528 init_timer(&lp->media); 539 init_timer(&lp->media);
529 lp->media.function = &media_check; 540 lp->media.function = &media_check;
@@ -533,18 +544,18 @@ static int el3_open(struct net_device *dev)
533 544
534 dev_dbg(&link->dev, "%s: opened, status %4.4x.\n", 545 dev_dbg(&link->dev, "%s: opened, status %4.4x.\n",
535 dev->name, inw(dev->base_addr + EL3_STATUS)); 546 dev->name, inw(dev->base_addr + EL3_STATUS));
536 547
537 return 0; 548 return 0;
538} 549}
539 550
540static void el3_tx_timeout(struct net_device *dev) 551static void el3_tx_timeout(struct net_device *dev)
541{ 552{
542 unsigned int ioaddr = dev->base_addr; 553 unsigned int ioaddr = dev->base_addr;
543 554
544 printk(KERN_WARNING "%s: Transmit timed out!\n", dev->name); 555 netdev_warn(dev, "Transmit timed out!\n");
545 dump_status(dev); 556 dump_status(dev);
546 dev->stats.tx_errors++; 557 dev->stats.tx_errors++;
547 dev->trans_start = jiffies; 558 dev->trans_start = jiffies; /* prevent tx timeout */
548 /* Issue TX_RESET and TX_START commands. */ 559 /* Issue TX_RESET and TX_START commands. */
549 tc589_wait_for_completion(dev, TxReset); 560 tc589_wait_for_completion(dev, TxReset);
550 outw(TxEnable, ioaddr + EL3_CMD); 561 outw(TxEnable, ioaddr + EL3_CMD);
@@ -555,19 +566,18 @@ static void pop_tx_status(struct net_device *dev)
555{ 566{
556 unsigned int ioaddr = dev->base_addr; 567 unsigned int ioaddr = dev->base_addr;
557 int i; 568 int i;
558 569
559 /* Clear the Tx status stack. */ 570 /* Clear the Tx status stack. */
560 for (i = 32; i > 0; i--) { 571 for (i = 32; i > 0; i--) {
561 u_char tx_status = inb(ioaddr + TX_STATUS); 572 u_char tx_status = inb(ioaddr + TX_STATUS);
562 if (!(tx_status & 0x84)) break; 573 if (!(tx_status & 0x84)) break;
563 /* reset transmitter on jabber error or underrun */ 574 /* reset transmitter on jabber error or underrun */
564 if (tx_status & 0x30) 575 if (tx_status & 0x30)
565 tc589_wait_for_completion(dev, TxReset); 576 tc589_wait_for_completion(dev, TxReset);
566 if (tx_status & 0x38) { 577 if (tx_status & 0x38) {
567 pr_debug("%s: transmit error: status 0x%02x\n", 578 netdev_dbg(dev, "transmit error: status 0x%02x\n", tx_status);
568 dev->name, tx_status); 579 outw(TxEnable, ioaddr + EL3_CMD);
569 outw(TxEnable, ioaddr + EL3_CMD); 580 dev->stats.tx_aborted_errors++;
570 dev->stats.tx_aborted_errors++;
571 } 581 }
572 outb(0x00, ioaddr + TX_STATUS); /* Pop the status stack. */ 582 outb(0x00, ioaddr + TX_STATUS); /* Pop the status stack. */
573 } 583 }
@@ -580,11 +590,10 @@ static netdev_tx_t el3_start_xmit(struct sk_buff *skb,
580 struct el3_private *priv = netdev_priv(dev); 590 struct el3_private *priv = netdev_priv(dev);
581 unsigned long flags; 591 unsigned long flags;
582 592
583 pr_debug("%s: el3_start_xmit(length = %ld) called, " 593 netdev_dbg(dev, "el3_start_xmit(length = %ld) called, status %4.4x.\n",
584 "status %4.4x.\n", dev->name, (long)skb->len, 594 (long)skb->len, inw(ioaddr + EL3_STATUS));
585 inw(ioaddr + EL3_STATUS));
586 595
587 spin_lock_irqsave(&priv->lock, flags); 596 spin_lock_irqsave(&priv->lock, flags);
588 597
589 dev->stats.tx_bytes += skb->len; 598 dev->stats.tx_bytes += skb->len;
590 599
@@ -594,7 +603,6 @@ static netdev_tx_t el3_start_xmit(struct sk_buff *skb,
594 /* ... and the packet rounded to a doubleword. */ 603 /* ... and the packet rounded to a doubleword. */
595 outsl(ioaddr + TX_FIFO, skb->data, (skb->len + 3) >> 2); 604 outsl(ioaddr + TX_FIFO, skb->data, (skb->len + 3) >> 2);
596 605
597 dev->trans_start = jiffies;
598 if (inw(ioaddr + TX_FREE) <= 1536) { 606 if (inw(ioaddr + TX_FREE) <= 1536) {
599 netif_stop_queue(dev); 607 netif_stop_queue(dev);
600 /* Interrupt us when the FIFO has room for max-sized packet. */ 608 /* Interrupt us when the FIFO has room for max-sized packet. */
@@ -602,9 +610,9 @@ static netdev_tx_t el3_start_xmit(struct sk_buff *skb,
602 } 610 }
603 611
604 pop_tx_status(dev); 612 pop_tx_status(dev);
605 spin_unlock_irqrestore(&priv->lock, flags); 613 spin_unlock_irqrestore(&priv->lock, flags);
606 dev_kfree_skb(skb); 614 dev_kfree_skb(skb);
607 615
608 return NETDEV_TX_OK; 616 return NETDEV_TX_OK;
609} 617}
610 618
@@ -616,37 +624,32 @@ static irqreturn_t el3_interrupt(int irq, void *dev_id)
616 unsigned int ioaddr; 624 unsigned int ioaddr;
617 __u16 status; 625 __u16 status;
618 int i = 0, handled = 1; 626 int i = 0, handled = 1;
619 627
620 if (!netif_device_present(dev)) 628 if (!netif_device_present(dev))
621 return IRQ_NONE; 629 return IRQ_NONE;
622 630
623 ioaddr = dev->base_addr; 631 ioaddr = dev->base_addr;
624 632
625 pr_debug("%s: interrupt, status %4.4x.\n", 633 netdev_dbg(dev, "interrupt, status %4.4x.\n", inw(ioaddr + EL3_STATUS));
626 dev->name, inw(ioaddr + EL3_STATUS));
627 634
628 spin_lock(&lp->lock); 635 spin_lock(&lp->lock);
629 while ((status = inw(ioaddr + EL3_STATUS)) & 636 while ((status = inw(ioaddr + EL3_STATUS)) &
630 (IntLatch | RxComplete | StatsFull)) { 637 (IntLatch | RxComplete | StatsFull)) {
631 if ((status & 0xe000) != 0x2000) { 638 if ((status & 0xe000) != 0x2000) {
632 pr_debug("%s: interrupt from dead card\n", dev->name); 639 netdev_dbg(dev, "interrupt from dead card\n");
633 handled = 0; 640 handled = 0;
634 break; 641 break;
635 } 642 }
636
637 if (status & RxComplete) 643 if (status & RxComplete)
638 el3_rx(dev); 644 el3_rx(dev);
639
640 if (status & TxAvailable) { 645 if (status & TxAvailable) {
641 pr_debug(" TX room bit was handled.\n"); 646 netdev_dbg(dev, " TX room bit was handled.\n");
642 /* There's room in the FIFO for a full-sized packet. */ 647 /* There's room in the FIFO for a full-sized packet. */
643 outw(AckIntr | TxAvailable, ioaddr + EL3_CMD); 648 outw(AckIntr | TxAvailable, ioaddr + EL3_CMD);
644 netif_wake_queue(dev); 649 netif_wake_queue(dev);
645 } 650 }
646
647 if (status & TxComplete) 651 if (status & TxComplete)
648 pop_tx_status(dev); 652 pop_tx_status(dev);
649
650 if (status & (AdapterFailure | RxEarly | StatsFull)) { 653 if (status & (AdapterFailure | RxEarly | StatsFull)) {
651 /* Handle all uncommon interrupts. */ 654 /* Handle all uncommon interrupts. */
652 if (status & StatsFull) /* Empty statistics. */ 655 if (status & StatsFull) /* Empty statistics. */
@@ -660,8 +663,8 @@ static irqreturn_t el3_interrupt(int irq, void *dev_id)
660 EL3WINDOW(4); 663 EL3WINDOW(4);
661 fifo_diag = inw(ioaddr + 4); 664 fifo_diag = inw(ioaddr + 4);
662 EL3WINDOW(1); 665 EL3WINDOW(1);
663 printk(KERN_WARNING "%s: adapter failure, FIFO diagnostic" 666 netdev_warn(dev, "adapter failure, FIFO diagnostic register %04x.\n",
664 " register %04x.\n", dev->name, fifo_diag); 667 fifo_diag);
665 if (fifo_diag & 0x0400) { 668 if (fifo_diag & 0x0400) {
666 /* Tx overrun */ 669 /* Tx overrun */
667 tc589_wait_for_completion(dev, TxReset); 670 tc589_wait_for_completion(dev, TxReset);
@@ -676,22 +679,20 @@ static irqreturn_t el3_interrupt(int irq, void *dev_id)
676 outw(AckIntr | AdapterFailure, ioaddr + EL3_CMD); 679 outw(AckIntr | AdapterFailure, ioaddr + EL3_CMD);
677 } 680 }
678 } 681 }
679
680 if (++i > 10) { 682 if (++i > 10) {
681 printk(KERN_ERR "%s: infinite loop in interrupt, " 683 netdev_err(dev, "infinite loop in interrupt, status %4.4x.\n",
682 "status %4.4x.\n", dev->name, status); 684 status);
683 /* Clear all interrupts */ 685 /* Clear all interrupts */
684 outw(AckIntr | 0xFF, ioaddr + EL3_CMD); 686 outw(AckIntr | 0xFF, ioaddr + EL3_CMD);
685 break; 687 break;
686 } 688 }
687 /* Acknowledge the IRQ. */ 689 /* Acknowledge the IRQ. */
688 outw(AckIntr | IntReq | IntLatch, ioaddr + EL3_CMD); 690 outw(AckIntr | IntReq | IntLatch, ioaddr + EL3_CMD);
689 } 691 }
690
691 lp->last_irq = jiffies; 692 lp->last_irq = jiffies;
692 spin_unlock(&lp->lock); 693 spin_unlock(&lp->lock);
693 pr_debug("%s: exiting interrupt, status %4.4x.\n", 694 netdev_dbg(dev, "exiting interrupt, status %4.4x.\n",
694 dev->name, inw(ioaddr + EL3_STATUS)); 695 inw(ioaddr + EL3_STATUS));
695 return IRQ_RETVAL(handled); 696 return IRQ_RETVAL(handled);
696} 697}
697 698
@@ -710,7 +711,7 @@ static void media_check(unsigned long arg)
710 if ((inw(ioaddr + EL3_STATUS) & IntLatch) && 711 if ((inw(ioaddr + EL3_STATUS) & IntLatch) &&
711 (inb(ioaddr + EL3_TIMER) == 0xff)) { 712 (inb(ioaddr + EL3_TIMER) == 0xff)) {
712 if (!lp->fast_poll) 713 if (!lp->fast_poll)
713 printk(KERN_WARNING "%s: interrupt(s) dropped!\n", dev->name); 714 netdev_warn(dev, "interrupt(s) dropped!\n");
714 715
715 local_irq_save(flags); 716 local_irq_save(flags);
716 el3_interrupt(dev->irq, dev); 717 el3_interrupt(dev->irq, dev);
@@ -727,7 +728,7 @@ static void media_check(unsigned long arg)
727 728
728 /* lp->lock guards the EL3 window. Window should always be 1 except 729 /* lp->lock guards the EL3 window. Window should always be 1 except
729 when the lock is held */ 730 when the lock is held */
730 spin_lock_irqsave(&lp->lock, flags); 731 spin_lock_irqsave(&lp->lock, flags);
731 EL3WINDOW(4); 732 EL3WINDOW(4);
732 media = inw(ioaddr+WN4_MEDIA) & 0xc810; 733 media = inw(ioaddr+WN4_MEDIA) & 0xc810;
733 734
@@ -747,32 +748,30 @@ static void media_check(unsigned long arg)
747 if (media != lp->media_status) { 748 if (media != lp->media_status) {
748 if ((media & lp->media_status & 0x8000) && 749 if ((media & lp->media_status & 0x8000) &&
749 ((lp->media_status ^ media) & 0x0800)) 750 ((lp->media_status ^ media) & 0x0800))
750 printk(KERN_INFO "%s: %s link beat\n", dev->name, 751 netdev_info(dev, "%s link beat\n",
751 (lp->media_status & 0x0800 ? "lost" : "found")); 752 (lp->media_status & 0x0800 ? "lost" : "found"));
752 else if ((media & lp->media_status & 0x4000) && 753 else if ((media & lp->media_status & 0x4000) &&
753 ((lp->media_status ^ media) & 0x0010)) 754 ((lp->media_status ^ media) & 0x0010))
754 printk(KERN_INFO "%s: coax cable %s\n", dev->name, 755 netdev_info(dev, "coax cable %s\n",
755 (lp->media_status & 0x0010 ? "ok" : "problem")); 756 (lp->media_status & 0x0010 ? "ok" : "problem"));
756 if (dev->if_port == 0) { 757 if (dev->if_port == 0) {
757 if (media & 0x8000) { 758 if (media & 0x8000) {
758 if (media & 0x0800) 759 if (media & 0x0800)
759 printk(KERN_INFO "%s: flipped to 10baseT\n", 760 netdev_info(dev, "flipped to 10baseT\n");
760 dev->name);
761 else 761 else
762 tc589_set_xcvr(dev, 2); 762 tc589_set_xcvr(dev, 2);
763 } else if (media & 0x4000) { 763 } else if (media & 0x4000) {
764 if (media & 0x0010) 764 if (media & 0x0010)
765 tc589_set_xcvr(dev, 1); 765 tc589_set_xcvr(dev, 1);
766 else 766 else
767 printk(KERN_INFO "%s: flipped to 10base2\n", 767 netdev_info(dev, "flipped to 10base2\n");
768 dev->name);
769 } 768 }
770 } 769 }
771 lp->media_status = media; 770 lp->media_status = media;
772 } 771 }
773 772
774 EL3WINDOW(1); 773 EL3WINDOW(1);
775 spin_unlock_irqrestore(&lp->lock, flags); 774 spin_unlock_irqrestore(&lp->lock, flags);
776 775
777reschedule: 776reschedule:
778 lp->media.expires = jiffies + HZ; 777 lp->media.expires = jiffies + HZ;
@@ -786,7 +785,7 @@ static struct net_device_stats *el3_get_stats(struct net_device *dev)
786 struct pcmcia_device *link = lp->p_dev; 785 struct pcmcia_device *link = lp->p_dev;
787 786
788 if (pcmcia_dev_present(link)) { 787 if (pcmcia_dev_present(link)) {
789 spin_lock_irqsave(&lp->lock, flags); 788 spin_lock_irqsave(&lp->lock, flags);
790 update_stats(dev); 789 update_stats(dev);
791 spin_unlock_irqrestore(&lp->lock, flags); 790 spin_unlock_irqrestore(&lp->lock, flags);
792 } 791 }
@@ -798,21 +797,21 @@ static struct net_device_stats *el3_get_stats(struct net_device *dev)
798 single-threaded if the device is active. This is expected to be a rare 797 single-threaded if the device is active. This is expected to be a rare
799 operation, and it's simpler for the rest of the driver to assume that 798 operation, and it's simpler for the rest of the driver to assume that
800 window 1 is always valid rather than use a special window-state variable. 799 window 1 is always valid rather than use a special window-state variable.
801 800
802 Caller must hold the lock for this 801 Caller must hold the lock for this
803*/ 802*/
804static void update_stats(struct net_device *dev) 803static void update_stats(struct net_device *dev)
805{ 804{
806 unsigned int ioaddr = dev->base_addr; 805 unsigned int ioaddr = dev->base_addr;
807 806
808 pr_debug("%s: updating the statistics.\n", dev->name); 807 netdev_dbg(dev, "updating the statistics.\n");
809 /* Turn off statistics updates while reading. */ 808 /* Turn off statistics updates while reading. */
810 outw(StatsDisable, ioaddr + EL3_CMD); 809 outw(StatsDisable, ioaddr + EL3_CMD);
811 /* Switch to the stats window, and read everything. */ 810 /* Switch to the stats window, and read everything. */
812 EL3WINDOW(6); 811 EL3WINDOW(6);
813 dev->stats.tx_carrier_errors += inb(ioaddr + 0); 812 dev->stats.tx_carrier_errors += inb(ioaddr + 0);
814 dev->stats.tx_heartbeat_errors += inb(ioaddr + 1); 813 dev->stats.tx_heartbeat_errors += inb(ioaddr + 1);
815 /* Multiple collisions. */ inb(ioaddr + 2); 814 /* Multiple collisions. */ inb(ioaddr + 2);
816 dev->stats.collisions += inb(ioaddr + 3); 815 dev->stats.collisions += inb(ioaddr + 3);
817 dev->stats.tx_window_errors += inb(ioaddr + 4); 816 dev->stats.tx_window_errors += inb(ioaddr + 4);
818 dev->stats.rx_fifo_errors += inb(ioaddr + 5); 817 dev->stats.rx_fifo_errors += inb(ioaddr + 5);
@@ -821,7 +820,7 @@ static void update_stats(struct net_device *dev)
821 /* Tx deferrals */ inb(ioaddr + 8); 820 /* Tx deferrals */ inb(ioaddr + 8);
822 /* Rx octets */ inw(ioaddr + 10); 821 /* Rx octets */ inw(ioaddr + 10);
823 /* Tx octets */ inw(ioaddr + 12); 822 /* Tx octets */ inw(ioaddr + 12);
824 823
825 /* Back to window 1, and turn statistics back on. */ 824 /* Back to window 1, and turn statistics back on. */
826 EL3WINDOW(1); 825 EL3WINDOW(1);
827 outw(StatsEnable, ioaddr + EL3_CMD); 826 outw(StatsEnable, ioaddr + EL3_CMD);
@@ -832,9 +831,9 @@ static int el3_rx(struct net_device *dev)
832 unsigned int ioaddr = dev->base_addr; 831 unsigned int ioaddr = dev->base_addr;
833 int worklimit = 32; 832 int worklimit = 32;
834 short rx_status; 833 short rx_status;
835 834
836 pr_debug("%s: in rx_packet(), status %4.4x, rx_status %4.4x.\n", 835 netdev_dbg(dev, "in rx_packet(), status %4.4x, rx_status %4.4x.\n",
837 dev->name, inw(ioaddr+EL3_STATUS), inw(ioaddr+RX_STATUS)); 836 inw(ioaddr+EL3_STATUS), inw(ioaddr+RX_STATUS));
838 while (!((rx_status = inw(ioaddr + RX_STATUS)) & 0x8000) && 837 while (!((rx_status = inw(ioaddr + RX_STATUS)) & 0x8000) &&
839 worklimit > 0) { 838 worklimit > 0) {
840 worklimit--; 839 worklimit--;
@@ -852,11 +851,11 @@ static int el3_rx(struct net_device *dev)
852 } else { 851 } else {
853 short pkt_len = rx_status & 0x7ff; 852 short pkt_len = rx_status & 0x7ff;
854 struct sk_buff *skb; 853 struct sk_buff *skb;
855 854
856 skb = dev_alloc_skb(pkt_len+5); 855 skb = dev_alloc_skb(pkt_len+5);
857 856
858 pr_debug(" Receiving packet size %d status %4.4x.\n", 857 netdev_dbg(dev, " Receiving packet size %d status %4.4x.\n",
859 pkt_len, rx_status); 858 pkt_len, rx_status);
860 if (skb != NULL) { 859 if (skb != NULL) {
861 skb_reserve(skb, 2); 860 skb_reserve(skb, 2);
862 insl(ioaddr+RX_FIFO, skb_put(skb, pkt_len), 861 insl(ioaddr+RX_FIFO, skb_put(skb, pkt_len),
@@ -866,8 +865,8 @@ static int el3_rx(struct net_device *dev)
866 dev->stats.rx_packets++; 865 dev->stats.rx_packets++;
867 dev->stats.rx_bytes += pkt_len; 866 dev->stats.rx_bytes += pkt_len;
868 } else { 867 } else {
869 pr_debug("%s: couldn't allocate a sk_buff of" 868 netdev_dbg(dev, "couldn't allocate a sk_buff of size %d.\n",
870 " size %d.\n", dev->name, pkt_len); 869 pkt_len);
871 dev->stats.rx_dropped++; 870 dev->stats.rx_dropped++;
872 } 871 }
873 } 872 }
@@ -875,7 +874,7 @@ static int el3_rx(struct net_device *dev)
875 tc589_wait_for_completion(dev, RxDiscard); 874 tc589_wait_for_completion(dev, RxDiscard);
876 } 875 }
877 if (worklimit == 0) 876 if (worklimit == 0)
878 printk(KERN_WARNING "%s: too much work in el3_rx!\n", dev->name); 877 netdev_warn(dev, "too much work in el3_rx!\n");
879 return 0; 878 return 0;
880} 879}
881 880
@@ -906,17 +905,17 @@ static int el3_close(struct net_device *dev)
906 struct el3_private *lp = netdev_priv(dev); 905 struct el3_private *lp = netdev_priv(dev);
907 struct pcmcia_device *link = lp->p_dev; 906 struct pcmcia_device *link = lp->p_dev;
908 unsigned int ioaddr = dev->base_addr; 907 unsigned int ioaddr = dev->base_addr;
909 908
910 dev_dbg(&link->dev, "%s: shutting down ethercard.\n", dev->name); 909 dev_dbg(&link->dev, "%s: shutting down ethercard.\n", dev->name);
911 910
912 if (pcmcia_dev_present(link)) { 911 if (pcmcia_dev_present(link)) {
913 /* Turn off statistics ASAP. We update dev->stats below. */ 912 /* Turn off statistics ASAP. We update dev->stats below. */
914 outw(StatsDisable, ioaddr + EL3_CMD); 913 outw(StatsDisable, ioaddr + EL3_CMD);
915 914
916 /* Disable the receiver and transmitter. */ 915 /* Disable the receiver and transmitter. */
917 outw(RxDisable, ioaddr + EL3_CMD); 916 outw(RxDisable, ioaddr + EL3_CMD);
918 outw(TxDisable, ioaddr + EL3_CMD); 917 outw(TxDisable, ioaddr + EL3_CMD);
919 918
920 if (dev->if_port == 2) 919 if (dev->if_port == 2)
921 /* Turn off thinnet power. Green! */ 920 /* Turn off thinnet power. Green! */
922 outw(StopCoax, ioaddr + EL3_CMD); 921 outw(StopCoax, ioaddr + EL3_CMD);
@@ -925,12 +924,12 @@ static int el3_close(struct net_device *dev)
925 EL3WINDOW(4); 924 EL3WINDOW(4);
926 outw(0, ioaddr + WN4_MEDIA); 925 outw(0, ioaddr + WN4_MEDIA);
927 } 926 }
928 927
929 /* Switching back to window 0 disables the IRQ. */ 928 /* Switching back to window 0 disables the IRQ. */
930 EL3WINDOW(0); 929 EL3WINDOW(0);
931 /* But we explicitly zero the IRQ line select anyway. */ 930 /* But we explicitly zero the IRQ line select anyway. */
932 outw(0x0f00, ioaddr + WN0_IRQ); 931 outw(0x0f00, ioaddr + WN0_IRQ);
933 932
934 /* Check if the card still exists */ 933 /* Check if the card still exists */
935 if ((inw(ioaddr+EL3_STATUS) & 0xe000) == 0x2000) 934 if ((inw(ioaddr+EL3_STATUS) & 0xe000) == 0x2000)
936 update_stats(dev); 935 update_stats(dev);
@@ -939,7 +938,7 @@ static int el3_close(struct net_device *dev)
939 link->open--; 938 link->open--;
940 netif_stop_queue(dev); 939 netif_stop_queue(dev);
941 del_timer_sync(&lp->media); 940 del_timer_sync(&lp->media);
942 941
943 return 0; 942 return 0;
944} 943}
945 944
@@ -961,7 +960,7 @@ static struct pcmcia_driver tc589_driver = {
961 }, 960 },
962 .probe = tc589_probe, 961 .probe = tc589_probe,
963 .remove = tc589_detach, 962 .remove = tc589_detach,
964 .id_table = tc589_ids, 963 .id_table = tc589_ids,
965 .suspend = tc589_suspend, 964 .suspend = tc589_suspend,
966 .resume = tc589_resume, 965 .resume = tc589_resume,
967}; 966};