]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/net/pcmcia/3c574_cs.c
[PATCH] pcmcia: rename pcmcia_device.state
[net-next-2.6.git] / drivers / net / pcmcia / 3c574_cs.c
CommitLineData
1da177e4
LT
1/* 3c574.c: A PCMCIA ethernet driver for the 3com 3c574 "RoadRunner".
2
3 Written 1993-1998 by
4 Donald Becker, becker@scyld.com, (driver core) and
5 David Hinds, dahinds@users.sourceforge.net (from his PC card code).
6 Locking fixes (C) Copyright 2003 Red Hat Inc
7
8 This software may be used and distributed according to the terms of
9 the GNU General Public License, incorporated herein by reference.
10
11 This driver derives from Donald Becker's 3c509 core, which has the
12 following copyright:
13 Copyright 1993 United States Government as represented by the
14 Director, National Security Agency.
15
16
17*/
18
19/*
20 Theory of Operation
21
22I. Board Compatibility
23
24This device driver is designed for the 3Com 3c574 PC card Fast Ethernet
25Adapter.
26
27II. Board-specific settings
28
29None -- PC cards are autoconfigured.
30
31III. Driver operation
32
33The 3c574 uses a Boomerang-style interface, without the bus-master capability.
34See the Boomerang driver and documentation for most details.
35
36IV. Notes and chip documentation.
37
38Two added registers are used to enhance PIO performance, RunnerRdCtrl and
39RunnerWrCtrl. These are 11 bit down-counters that are preloaded with the
40count of word (16 bits) reads or writes the driver is about to do to the Rx
41or Tx FIFO. The chip is then able to hide the internal-PCI-bus to PC-card
42translation latency by buffering the I/O operations with an 8 word FIFO.
43Note: No other chip accesses are permitted when this buffer is used.
44
45A second enhancement is that both attribute and common memory space
460x0800-0x0fff can translated to the PIO FIFO. Thus memory operations (faster
47with *some* PCcard bridges) may be used instead of I/O operations.
48This is enabled by setting the 0x10 bit in the PCMCIA LAN COR.
49
50Some slow PC card bridges work better if they never see a WAIT signal.
51This is configured by setting the 0x20 bit in the PCMCIA LAN COR.
52Only do this after testing that it is reliable and improves performance.
53
54The upper five bits of RunnerRdCtrl are used to window into PCcard
55configuration space registers. Window 0 is the regular Boomerang/Odie
56register set, 1-5 are various PC card control registers, and 16-31 are
57the (reversed!) CIS table.
58
59A final note: writing the InternalConfig register in window 3 with an
60invalid ramWidth is Very Bad.
61
62V. References
63
64http://www.scyld.com/expert/NWay.html
65http://www.national.com/pf/DP/DP83840.html
66
67Thanks to Terry Murphy of 3Com for providing development information for
68earlier 3Com products.
69
70*/
71
72#include <linux/module.h>
73#include <linux/kernel.h>
74#include <linux/init.h>
75#include <linux/slab.h>
76#include <linux/string.h>
77#include <linux/timer.h>
78#include <linux/interrupt.h>
79#include <linux/in.h>
80#include <linux/delay.h>
81#include <linux/netdevice.h>
82#include <linux/etherdevice.h>
83#include <linux/skbuff.h>
84#include <linux/if_arp.h>
85#include <linux/ioport.h>
86#include <linux/ethtool.h>
87#include <linux/bitops.h>
88
1da177e4
LT
89#include <pcmcia/cs_types.h>
90#include <pcmcia/cs.h>
91#include <pcmcia/cistpl.h>
92#include <pcmcia/cisreg.h>
93#include <pcmcia/ciscode.h>
94#include <pcmcia/ds.h>
95#include <pcmcia/mem_op.h>
96
97#include <asm/uaccess.h>
98#include <asm/io.h>
99#include <asm/system.h>
100
101/*====================================================================*/
102
103/* Module parameters */
104
105MODULE_AUTHOR("David Hinds <dahinds@users.sourceforge.net>");
106MODULE_DESCRIPTION("3Com 3c574 series PCMCIA ethernet driver");
107MODULE_LICENSE("GPL");
108
109#define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0)
110
111/* Maximum events (Rx packets, etc.) to handle at each interrupt. */
112INT_MODULE_PARM(max_interrupt_work, 32);
113
114/* Force full duplex modes? */
115INT_MODULE_PARM(full_duplex, 0);
116
117/* Autodetect link polarity reversal? */
118INT_MODULE_PARM(auto_polarity, 1);
119
120#ifdef PCMCIA_DEBUG
121INT_MODULE_PARM(pc_debug, PCMCIA_DEBUG);
122#define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
123static char *version =
124"3c574_cs.c 1.65ac1 2003/04/07 Donald Becker/David Hinds, becker@scyld.com.\n";
125#else
126#define DEBUG(n, args...)
127#endif
128
129/*====================================================================*/
130
131/* Time in jiffies before concluding the transmitter is hung. */
132#define TX_TIMEOUT ((800*HZ)/1000)
133
134/* To minimize the size of the driver source and make the driver more
135 readable not all constants are symbolically defined.
136 You'll need the manual if you want to understand driver details anyway. */
137/* Offsets from base I/O address. */
138#define EL3_DATA 0x00
139#define EL3_CMD 0x0e
140#define EL3_STATUS 0x0e
141
142#define EL3WINDOW(win_num) outw(SelectWindow + (win_num), ioaddr + EL3_CMD)
143
144/* The top five bits written to EL3_CMD are a command, the lower
145 11 bits are the parameter, if applicable. */
146enum el3_cmds {
147 TotalReset = 0<<11, SelectWindow = 1<<11, StartCoax = 2<<11,
148 RxDisable = 3<<11, RxEnable = 4<<11, RxReset = 5<<11, RxDiscard = 8<<11,
149 TxEnable = 9<<11, TxDisable = 10<<11, TxReset = 11<<11,
150 FakeIntr = 12<<11, AckIntr = 13<<11, SetIntrEnb = 14<<11,
151 SetStatusEnb = 15<<11, SetRxFilter = 16<<11, SetRxThreshold = 17<<11,
152 SetTxThreshold = 18<<11, SetTxStart = 19<<11, StatsEnable = 21<<11,
153 StatsDisable = 22<<11, StopCoax = 23<<11,
154};
155
156enum elxl_status {
157 IntLatch = 0x0001, AdapterFailure = 0x0002, TxComplete = 0x0004,
158 TxAvailable = 0x0008, RxComplete = 0x0010, RxEarly = 0x0020,
159 IntReq = 0x0040, StatsFull = 0x0080, CmdBusy = 0x1000 };
160
161/* The SetRxFilter command accepts the following classes: */
162enum RxFilter {
163 RxStation = 1, RxMulticast = 2, RxBroadcast = 4, RxProm = 8
164};
165
166enum Window0 {
167 Wn0EepromCmd = 10, Wn0EepromData = 12, /* EEPROM command/address, data. */
168 IntrStatus=0x0E, /* Valid in all windows. */
169};
170/* These assumes the larger EEPROM. */
171enum Win0_EEPROM_cmds {
172 EEPROM_Read = 0x200, EEPROM_WRITE = 0x100, EEPROM_ERASE = 0x300,
173 EEPROM_EWENB = 0x30, /* Enable erasing/writing for 10 msec. */
174 EEPROM_EWDIS = 0x00, /* Disable EWENB before 10 msec timeout. */
175};
176
177/* Register window 1 offsets, the window used in normal operation.
178 On the "Odie" this window is always mapped at offsets 0x10-0x1f.
179 Except for TxFree, which is overlapped by RunnerWrCtrl. */
180enum Window1 {
181 TX_FIFO = 0x10, RX_FIFO = 0x10, RxErrors = 0x14,
182 RxStatus = 0x18, Timer=0x1A, TxStatus = 0x1B,
183 TxFree = 0x0C, /* Remaining free bytes in Tx buffer. */
184 RunnerRdCtrl = 0x16, RunnerWrCtrl = 0x1c,
185};
186
187enum Window3 { /* Window 3: MAC/config bits. */
188 Wn3_Config=0, Wn3_MAC_Ctrl=6, Wn3_Options=8,
189};
190union wn3_config {
191 int i;
192 struct w3_config_fields {
193 unsigned int ram_size:3, ram_width:1, ram_speed:2, rom_size:2;
194 int pad8:8;
195 unsigned int ram_split:2, pad18:2, xcvr:3, pad21:1, autoselect:1;
196 int pad24:7;
197 } u;
198};
199
200enum Window4 { /* Window 4: Xcvr/media bits. */
201 Wn4_FIFODiag = 4, Wn4_NetDiag = 6, Wn4_PhysicalMgmt=8, Wn4_Media = 10,
202};
203
204#define MEDIA_TP 0x00C0 /* Enable link beat and jabber for 10baseT. */
205
206struct el3_private {
207 dev_link_t link;
208 dev_node_t node;
209 struct net_device_stats stats;
210 u16 advertising, partner; /* NWay media advertisement */
211 unsigned char phys; /* MII device address */
212 unsigned int autoselect:1, default_media:3; /* Read from the EEPROM/Wn3_Config. */
213 /* for transceiver monitoring */
214 struct timer_list media;
215 unsigned short media_status;
216 unsigned short fast_poll;
217 unsigned long last_irq;
218 spinlock_t window_lock; /* Guards the Window selection */
219};
220
221/* Set iff a MII transceiver on any interface requires mdio preamble.
222 This only set with the original DP83840 on older 3c905 boards, so the extra
223 code size of a per-interface flag is not worthwhile. */
224static char mii_preamble_required = 0;
225
226/* Index of functions. */
227
228static void tc574_config(dev_link_t *link);
229static void tc574_release(dev_link_t *link);
1da177e4
LT
230
231static void mdio_sync(kio_addr_t ioaddr, int bits);
232static int mdio_read(kio_addr_t ioaddr, int phy_id, int location);
233static void mdio_write(kio_addr_t ioaddr, int phy_id, int location, int value);
234static unsigned short read_eeprom(kio_addr_t ioaddr, int index);
235static void tc574_wait_for_completion(struct net_device *dev, int cmd);
236
237static void tc574_reset(struct net_device *dev);
238static void media_check(unsigned long arg);
239static int el3_open(struct net_device *dev);
240static int el3_start_xmit(struct sk_buff *skb, struct net_device *dev);
241static irqreturn_t el3_interrupt(int irq, void *dev_id, struct pt_regs *regs);
242static void update_stats(struct net_device *dev);
243static struct net_device_stats *el3_get_stats(struct net_device *dev);
244static int el3_rx(struct net_device *dev, int worklimit);
245static int el3_close(struct net_device *dev);
246static void el3_tx_timeout(struct net_device *dev);
247static int el3_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
248static struct ethtool_ops netdev_ethtool_ops;
249static void set_rx_mode(struct net_device *dev);
250
cc3b4866 251static void tc574_detach(struct pcmcia_device *p_dev);
1da177e4 252
1da177e4
LT
253/*
254 tc574_attach() creates an "instance" of the driver, allocating
255 local data structures for one device. The device is registered
256 with Card Services.
257*/
258
f8cfa618 259static int tc574_attach(struct pcmcia_device *p_dev)
1da177e4
LT
260{
261 struct el3_private *lp;
1da177e4
LT
262 dev_link_t *link;
263 struct net_device *dev;
1da177e4
LT
264
265 DEBUG(0, "3c574_attach()\n");
266
267 /* Create the PC card device object. */
268 dev = alloc_etherdev(sizeof(struct el3_private));
269 if (!dev)
f8cfa618 270 return -ENOMEM;
1da177e4
LT
271 lp = netdev_priv(dev);
272 link = &lp->link;
273 link->priv = dev;
274
275 spin_lock_init(&lp->window_lock);
276 link->io.NumPorts1 = 32;
277 link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
278 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
279 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
280 link->irq.Handler = &el3_interrupt;
281 link->irq.Instance = dev;
282 link->conf.Attributes = CONF_ENABLE_IRQ;
1da177e4
LT
283 link->conf.IntType = INT_MEMORY_AND_IO;
284 link->conf.ConfigIndex = 1;
285 link->conf.Present = PRESENT_OPTION;
286
287 /* The EL3-specific entries in the device structure. */
288 dev->hard_start_xmit = &el3_start_xmit;
289 dev->get_stats = &el3_get_stats;
290 dev->do_ioctl = &el3_ioctl;
291 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
292 dev->set_multicast_list = &set_rx_mode;
293 dev->open = &el3_open;
294 dev->stop = &el3_close;
295#ifdef HAVE_TX_TIMEOUT
296 dev->tx_timeout = el3_tx_timeout;
297 dev->watchdog_timeo = TX_TIMEOUT;
298#endif
299
f8cfa618
DB
300 link->handle = p_dev;
301 p_dev->instance = link;
1da177e4 302
f8cfa618
DB
303 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
304 tc574_config(link);
305
306 return 0;
1da177e4
LT
307} /* tc574_attach */
308
309/*
310
311 This deletes a driver "instance". The device is de-registered
312 with Card Services. If it has been released, all local data
313 structures are freed. Otherwise, the structures will be freed
314 when the device is released.
315
316*/
317
cc3b4866 318static void tc574_detach(struct pcmcia_device *p_dev)
1da177e4 319{
cc3b4866 320 dev_link_t *link = dev_to_instance(p_dev);
1da177e4 321 struct net_device *dev = link->priv;
1da177e4
LT
322
323 DEBUG(0, "3c574_detach(0x%p)\n", link);
324
1da177e4
LT
325 if (link->dev)
326 unregister_netdev(dev);
327
328 if (link->state & DEV_CONFIG)
329 tc574_release(link);
330
1da177e4
LT
331 free_netdev(dev);
332} /* tc574_detach */
333
334/*
335 tc574_config() is scheduled to run after a CARD_INSERTION event
336 is received, to configure the PCMCIA socket, and to make the
337 ethernet device available to the system.
338*/
339
340#define CS_CHECK(fn, ret) \
341 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
342
f71e1309 343static const char *ram_split[] = {"5:3", "3:1", "1:1", "3:5"};
1da177e4
LT
344
345static void tc574_config(dev_link_t *link)
346{
347 client_handle_t handle = link->handle;
348 struct net_device *dev = link->priv;
349 struct el3_private *lp = netdev_priv(dev);
350 tuple_t tuple;
351 cisparse_t parse;
352 unsigned short buf[32];
353 int last_fn, last_ret, i, j;
354 kio_addr_t ioaddr;
355 u16 *phys_addr;
356 char *cardname;
357 union wn3_config config;
358
359 phys_addr = (u16 *)dev->dev_addr;
360
361 DEBUG(0, "3c574_config(0x%p)\n", link);
362
363 tuple.Attributes = 0;
364 tuple.DesiredTuple = CISTPL_CONFIG;
365 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));
366 tuple.TupleData = (cisdata_t *)buf;
367 tuple.TupleDataMax = 64;
368 tuple.TupleOffset = 0;
369 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple));
370 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse));
371 link->conf.ConfigBase = parse.config.base;
372 link->conf.Present = parse.config.rmask[0];
373
374 /* Configure card */
375 link->state |= DEV_CONFIG;
376
377 link->io.IOAddrLines = 16;
378 for (i = j = 0; j < 0x400; j += 0x20) {
379 link->io.BasePort1 = j ^ 0x300;
380 i = pcmcia_request_io(link->handle, &link->io);
381 if (i == CS_SUCCESS) break;
382 }
383 if (i != CS_SUCCESS) {
384 cs_error(link->handle, RequestIO, i);
385 goto failed;
386 }
387 CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq));
388 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link->handle, &link->conf));
389
390 dev->irq = link->irq.AssignedIRQ;
391 dev->base_addr = link->io.BasePort1;
392
393 ioaddr = dev->base_addr;
394
395 /* The 3c574 normally uses an EEPROM for configuration info, including
396 the hardware address. The future products may include a modem chip
397 and put the address in the CIS. */
398 tuple.DesiredTuple = 0x88;
399 if (pcmcia_get_first_tuple(handle, &tuple) == CS_SUCCESS) {
400 pcmcia_get_tuple_data(handle, &tuple);
401 for (i = 0; i < 3; i++)
402 phys_addr[i] = htons(buf[i]);
403 } else {
404 EL3WINDOW(0);
405 for (i = 0; i < 3; i++)
406 phys_addr[i] = htons(read_eeprom(ioaddr, i + 10));
407 if (phys_addr[0] == 0x6060) {
408 printk(KERN_NOTICE "3c574_cs: IO port conflict at 0x%03lx"
409 "-0x%03lx\n", dev->base_addr, dev->base_addr+15);
410 goto failed;
411 }
412 }
413 tuple.DesiredTuple = CISTPL_VERS_1;
414 if (pcmcia_get_first_tuple(handle, &tuple) == CS_SUCCESS &&
415 pcmcia_get_tuple_data(handle, &tuple) == CS_SUCCESS &&
416 pcmcia_parse_tuple(handle, &tuple, &parse) == CS_SUCCESS) {
417 cardname = parse.version_1.str + parse.version_1.ofs[1];
418 } else
419 cardname = "3Com 3c574";
420
421 {
422 u_char mcr;
423 outw(2<<11, ioaddr + RunnerRdCtrl);
424 mcr = inb(ioaddr + 2);
425 outw(0<<11, ioaddr + RunnerRdCtrl);
426 printk(KERN_INFO " ASIC rev %d,", mcr>>3);
427 EL3WINDOW(3);
428 config.i = inl(ioaddr + Wn3_Config);
429 lp->default_media = config.u.xcvr;
430 lp->autoselect = config.u.autoselect;
431 }
432
433 init_timer(&lp->media);
434
435 {
436 int phy;
437
438 /* Roadrunner only: Turn on the MII transceiver */
439 outw(0x8040, ioaddr + Wn3_Options);
440 mdelay(1);
441 outw(0xc040, ioaddr + Wn3_Options);
442 tc574_wait_for_completion(dev, TxReset);
443 tc574_wait_for_completion(dev, RxReset);
444 mdelay(1);
445 outw(0x8040, ioaddr + Wn3_Options);
446
447 EL3WINDOW(4);
448 for (phy = 1; phy <= 32; phy++) {
449 int mii_status;
450 mdio_sync(ioaddr, 32);
451 mii_status = mdio_read(ioaddr, phy & 0x1f, 1);
452 if (mii_status != 0xffff) {
453 lp->phys = phy & 0x1f;
454 DEBUG(0, " MII transceiver at index %d, status %x.\n",
455 phy, mii_status);
456 if ((mii_status & 0x0040) == 0)
457 mii_preamble_required = 1;
458 break;
459 }
460 }
461 if (phy > 32) {
462 printk(KERN_NOTICE " No MII transceivers found!\n");
463 goto failed;
464 }
465 i = mdio_read(ioaddr, lp->phys, 16) | 0x40;
466 mdio_write(ioaddr, lp->phys, 16, i);
467 lp->advertising = mdio_read(ioaddr, lp->phys, 4);
468 if (full_duplex) {
469 /* Only advertise the FD media types. */
470 lp->advertising &= ~0x02a0;
471 mdio_write(ioaddr, lp->phys, 4, lp->advertising);
472 }
473 }
474
475 link->state &= ~DEV_CONFIG_PENDING;
476 link->dev = &lp->node;
477 SET_NETDEV_DEV(dev, &handle_to_dev(handle));
478
479 if (register_netdev(dev) != 0) {
480 printk(KERN_NOTICE "3c574_cs: register_netdev() failed\n");
481 link->dev = NULL;
482 goto failed;
483 }
484
485 strcpy(lp->node.dev_name, dev->name);
486
487 printk(KERN_INFO "%s: %s at io %#3lx, irq %d, hw_addr ",
488 dev->name, cardname, dev->base_addr, dev->irq);
489 for (i = 0; i < 6; i++)
490 printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : ".\n"));
491 printk(" %dK FIFO split %s Rx:Tx, %sMII interface.\n",
492 8 << config.u.ram_size, ram_split[config.u.ram_split],
493 config.u.autoselect ? "autoselect " : "");
494
495 return;
496
497cs_failed:
498 cs_error(link->handle, last_fn, last_ret);
499failed:
500 tc574_release(link);
501 return;
502
503} /* tc574_config */
504
505/*
506 After a card is removed, tc574_release() will unregister the net
507 device, and release the PCMCIA configuration. If the device is
508 still open, this will be postponed until it is closed.
509*/
510
511static void tc574_release(dev_link_t *link)
512{
5f2a71fc 513 pcmcia_disable_device(link->handle);
1da177e4
LT
514}
515
98e4c28b
DB
516static int tc574_suspend(struct pcmcia_device *p_dev)
517{
518 dev_link_t *link = dev_to_instance(p_dev);
519 struct net_device *dev = link->priv;
520
8661bb5b
DB
521 if ((link->state & DEV_CONFIG) && (link->open))
522 netif_device_detach(dev);
98e4c28b
DB
523
524 return 0;
525}
526
527static int tc574_resume(struct pcmcia_device *p_dev)
528{
529 dev_link_t *link = dev_to_instance(p_dev);
530 struct net_device *dev = link->priv;
531
8661bb5b
DB
532 if ((link->state & DEV_CONFIG) && (link->open)) {
533 tc574_reset(dev);
534 netif_device_attach(dev);
98e4c28b
DB
535 }
536
537 return 0;
538}
539
1da177e4
LT
540static void dump_status(struct net_device *dev)
541{
542 kio_addr_t ioaddr = dev->base_addr;
543 EL3WINDOW(1);
544 printk(KERN_INFO " irq status %04x, rx status %04x, tx status "
545 "%02x, tx free %04x\n", inw(ioaddr+EL3_STATUS),
546 inw(ioaddr+RxStatus), inb(ioaddr+TxStatus),
547 inw(ioaddr+TxFree));
548 EL3WINDOW(4);
549 printk(KERN_INFO " diagnostics: fifo %04x net %04x ethernet %04x"
550 " media %04x\n", inw(ioaddr+0x04), inw(ioaddr+0x06),
551 inw(ioaddr+0x08), inw(ioaddr+0x0a));
552 EL3WINDOW(1);
553}
554
555/*
556 Use this for commands that may take time to finish
557*/
558static void tc574_wait_for_completion(struct net_device *dev, int cmd)
559{
560 int i = 1500;
561 outw(cmd, dev->base_addr + EL3_CMD);
562 while (--i > 0)
563 if (!(inw(dev->base_addr + EL3_STATUS) & 0x1000)) break;
564 if (i == 0)
565 printk(KERN_NOTICE "%s: command 0x%04x did not complete!\n", dev->name, cmd);
566}
567
568/* Read a word from the EEPROM using the regular EEPROM access register.
569 Assume that we are in register window zero.
570 */
571static unsigned short read_eeprom(kio_addr_t ioaddr, int index)
572{
573 int timer;
574 outw(EEPROM_Read + index, ioaddr + Wn0EepromCmd);
575 /* Pause for at least 162 usec for the read to take place. */
576 for (timer = 1620; timer >= 0; timer--) {
577 if ((inw(ioaddr + Wn0EepromCmd) & 0x8000) == 0)
578 break;
579 }
580 return inw(ioaddr + Wn0EepromData);
581}
582
583/* MII transceiver control section.
584 Read and write the MII registers using software-generated serial
585 MDIO protocol. See the MII specifications or DP83840A data sheet
586 for details.
587 The maxium data clock rate is 2.5 Mhz. The timing is easily met by the
588 slow PC card interface. */
589
590#define MDIO_SHIFT_CLK 0x01
591#define MDIO_DIR_WRITE 0x04
592#define MDIO_DATA_WRITE0 (0x00 | MDIO_DIR_WRITE)
593#define MDIO_DATA_WRITE1 (0x02 | MDIO_DIR_WRITE)
594#define MDIO_DATA_READ 0x02
595#define MDIO_ENB_IN 0x00
596
597/* Generate the preamble required for initial synchronization and
598 a few older transceivers. */
599static void mdio_sync(kio_addr_t ioaddr, int bits)
600{
601 kio_addr_t mdio_addr = ioaddr + Wn4_PhysicalMgmt;
602
603 /* Establish sync by sending at least 32 logic ones. */
604 while (-- bits >= 0) {
605 outw(MDIO_DATA_WRITE1, mdio_addr);
606 outw(MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, mdio_addr);
607 }
608}
609
610static int mdio_read(kio_addr_t ioaddr, int phy_id, int location)
611{
612 int i;
613 int read_cmd = (0xf6 << 10) | (phy_id << 5) | location;
614 unsigned int retval = 0;
615 kio_addr_t mdio_addr = ioaddr + Wn4_PhysicalMgmt;
616
617 if (mii_preamble_required)
618 mdio_sync(ioaddr, 32);
619
620 /* Shift the read command bits out. */
621 for (i = 14; i >= 0; i--) {
622 int dataval = (read_cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
623 outw(dataval, mdio_addr);
624 outw(dataval | MDIO_SHIFT_CLK, mdio_addr);
625 }
626 /* Read the two transition, 16 data, and wire-idle bits. */
627 for (i = 19; i > 0; i--) {
628 outw(MDIO_ENB_IN, mdio_addr);
629 retval = (retval << 1) | ((inw(mdio_addr) & MDIO_DATA_READ) ? 1 : 0);
630 outw(MDIO_ENB_IN | MDIO_SHIFT_CLK, mdio_addr);
631 }
632 return (retval>>1) & 0xffff;
633}
634
635static void mdio_write(kio_addr_t ioaddr, int phy_id, int location, int value)
636{
637 int write_cmd = 0x50020000 | (phy_id << 23) | (location << 18) | value;
638 kio_addr_t mdio_addr = ioaddr + Wn4_PhysicalMgmt;
639 int i;
640
641 if (mii_preamble_required)
642 mdio_sync(ioaddr, 32);
643
644 /* Shift the command bits out. */
645 for (i = 31; i >= 0; i--) {
646 int dataval = (write_cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
647 outw(dataval, mdio_addr);
648 outw(dataval | MDIO_SHIFT_CLK, mdio_addr);
649 }
650 /* Leave the interface idle. */
651 for (i = 1; i >= 0; i--) {
652 outw(MDIO_ENB_IN, mdio_addr);
653 outw(MDIO_ENB_IN | MDIO_SHIFT_CLK, mdio_addr);
654 }
655
656 return;
657}
658
659/* Reset and restore all of the 3c574 registers. */
660static void tc574_reset(struct net_device *dev)
661{
662 struct el3_private *lp = netdev_priv(dev);
663 int i;
664 kio_addr_t ioaddr = dev->base_addr;
665 unsigned long flags;
666
667 tc574_wait_for_completion(dev, TotalReset|0x10);
668
669 spin_lock_irqsave(&lp->window_lock, flags);
670 /* Clear any transactions in progress. */
671 outw(0, ioaddr + RunnerWrCtrl);
672 outw(0, ioaddr + RunnerRdCtrl);
673
674 /* Set the station address and mask. */
675 EL3WINDOW(2);
676 for (i = 0; i < 6; i++)
677 outb(dev->dev_addr[i], ioaddr + i);
678 for (; i < 12; i+=2)
679 outw(0, ioaddr + i);
680
681 /* Reset config options */
682 EL3WINDOW(3);
683 outb((dev->mtu > 1500 ? 0x40 : 0), ioaddr + Wn3_MAC_Ctrl);
684 outl((lp->autoselect ? 0x01000000 : 0) | 0x0062001b,
685 ioaddr + Wn3_Config);
686 /* Roadrunner only: Turn on the MII transceiver. */
687 outw(0x8040, ioaddr + Wn3_Options);
688 mdelay(1);
689 outw(0xc040, ioaddr + Wn3_Options);
690 EL3WINDOW(1);
691 spin_unlock_irqrestore(&lp->window_lock, flags);
692
693 tc574_wait_for_completion(dev, TxReset);
694 tc574_wait_for_completion(dev, RxReset);
695 mdelay(1);
696 spin_lock_irqsave(&lp->window_lock, flags);
697 EL3WINDOW(3);
698 outw(0x8040, ioaddr + Wn3_Options);
699
700 /* Switch to the stats window, and clear all stats by reading. */
701 outw(StatsDisable, ioaddr + EL3_CMD);
702 EL3WINDOW(6);
703 for (i = 0; i < 10; i++)
704 inb(ioaddr + i);
705 inw(ioaddr + 10);
706 inw(ioaddr + 12);
707 EL3WINDOW(4);
708 inb(ioaddr + 12);
709 inb(ioaddr + 13);
710
711 /* .. enable any extra statistics bits.. */
712 outw(0x0040, ioaddr + Wn4_NetDiag);
713
714 EL3WINDOW(1);
715 spin_unlock_irqrestore(&lp->window_lock, flags);
716
717 /* .. re-sync MII and re-fill what NWay is advertising. */
718 mdio_sync(ioaddr, 32);
719 mdio_write(ioaddr, lp->phys, 4, lp->advertising);
720 if (!auto_polarity) {
721 /* works for TDK 78Q2120 series MII's */
722 int i = mdio_read(ioaddr, lp->phys, 16) | 0x20;
723 mdio_write(ioaddr, lp->phys, 16, i);
724 }
725
726 spin_lock_irqsave(&lp->window_lock, flags);
727 /* Switch to register set 1 for normal use, just for TxFree. */
728 set_rx_mode(dev);
729 spin_unlock_irqrestore(&lp->window_lock, flags);
730 outw(StatsEnable, ioaddr + EL3_CMD); /* Turn on statistics. */
731 outw(RxEnable, ioaddr + EL3_CMD); /* Enable the receiver. */
732 outw(TxEnable, ioaddr + EL3_CMD); /* Enable transmitter. */
733 /* Allow status bits to be seen. */
734 outw(SetStatusEnb | 0xff, ioaddr + EL3_CMD);
735 /* Ack all pending events, and set active indicator mask. */
736 outw(AckIntr | IntLatch | TxAvailable | RxEarly | IntReq,
737 ioaddr + EL3_CMD);
738 outw(SetIntrEnb | IntLatch | TxAvailable | RxComplete | StatsFull
739 | AdapterFailure | RxEarly, ioaddr + EL3_CMD);
740}
741
742static int el3_open(struct net_device *dev)
743{
744 struct el3_private *lp = netdev_priv(dev);
745 dev_link_t *link = &lp->link;
746
747 if (!DEV_OK(link))
748 return -ENODEV;
749
750 link->open++;
751 netif_start_queue(dev);
752
753 tc574_reset(dev);
754 lp->media.function = &media_check;
755 lp->media.data = (unsigned long) dev;
756 lp->media.expires = jiffies + HZ;
757 add_timer(&lp->media);
758
759 DEBUG(2, "%s: opened, status %4.4x.\n",
760 dev->name, inw(dev->base_addr + EL3_STATUS));
761
762 return 0;
763}
764
765static void el3_tx_timeout(struct net_device *dev)
766{
767 struct el3_private *lp = netdev_priv(dev);
768 kio_addr_t ioaddr = dev->base_addr;
769
770 printk(KERN_NOTICE "%s: Transmit timed out!\n", dev->name);
771 dump_status(dev);
772 lp->stats.tx_errors++;
773 dev->trans_start = jiffies;
774 /* Issue TX_RESET and TX_START commands. */
775 tc574_wait_for_completion(dev, TxReset);
776 outw(TxEnable, ioaddr + EL3_CMD);
777 netif_wake_queue(dev);
778}
779
780static void pop_tx_status(struct net_device *dev)
781{
782 struct el3_private *lp = netdev_priv(dev);
783 kio_addr_t ioaddr = dev->base_addr;
784 int i;
785
786 /* Clear the Tx status stack. */
787 for (i = 32; i > 0; i--) {
788 u_char tx_status = inb(ioaddr + TxStatus);
789 if (!(tx_status & 0x84))
790 break;
791 /* reset transmitter on jabber error or underrun */
792 if (tx_status & 0x30)
793 tc574_wait_for_completion(dev, TxReset);
794 if (tx_status & 0x38) {
795 DEBUG(1, "%s: transmit error: status 0x%02x\n",
796 dev->name, tx_status);
797 outw(TxEnable, ioaddr + EL3_CMD);
798 lp->stats.tx_aborted_errors++;
799 }
800 outb(0x00, ioaddr + TxStatus); /* Pop the status stack. */
801 }
802}
803
804static int el3_start_xmit(struct sk_buff *skb, struct net_device *dev)
805{
806 kio_addr_t ioaddr = dev->base_addr;
807 struct el3_private *lp = netdev_priv(dev);
808 unsigned long flags;
809
810 DEBUG(3, "%s: el3_start_xmit(length = %ld) called, "
811 "status %4.4x.\n", dev->name, (long)skb->len,
812 inw(ioaddr + EL3_STATUS));
813
814 spin_lock_irqsave(&lp->window_lock, flags);
815 outw(skb->len, ioaddr + TX_FIFO);
816 outw(0, ioaddr + TX_FIFO);
817 outsl(ioaddr + TX_FIFO, skb->data, (skb->len+3)>>2);
818
819 dev->trans_start = jiffies;
820
821 /* TxFree appears only in Window 1, not offset 0x1c. */
822 if (inw(ioaddr + TxFree) <= 1536) {
823 netif_stop_queue(dev);
824 /* Interrupt us when the FIFO has room for max-sized packet.
825 The threshold is in units of dwords. */
826 outw(SetTxThreshold + (1536>>2), ioaddr + EL3_CMD);
827 }
828
829 pop_tx_status(dev);
830 spin_unlock_irqrestore(&lp->window_lock, flags);
831 dev_kfree_skb(skb);
832 return 0;
833}
834
835/* The EL3 interrupt handler. */
836static irqreturn_t el3_interrupt(int irq, void *dev_id, struct pt_regs *regs)
837{
838 struct net_device *dev = (struct net_device *) dev_id;
839 struct el3_private *lp = netdev_priv(dev);
840 kio_addr_t ioaddr;
841 unsigned status;
842 int work_budget = max_interrupt_work;
843 int handled = 0;
844
845 if (!netif_device_present(dev))
846 return IRQ_NONE;
847 ioaddr = dev->base_addr;
848
849 DEBUG(3, "%s: interrupt, status %4.4x.\n",
850 dev->name, inw(ioaddr + EL3_STATUS));
851
852 spin_lock(&lp->window_lock);
853
854 while ((status = inw(ioaddr + EL3_STATUS)) &
855 (IntLatch | RxComplete | RxEarly | StatsFull)) {
856 if (!netif_device_present(dev) ||
857 ((status & 0xe000) != 0x2000)) {
858 DEBUG(1, "%s: Interrupt from dead card\n", dev->name);
859 break;
860 }
861
862 handled = 1;
863
864 if (status & RxComplete)
865 work_budget = el3_rx(dev, work_budget);
866
867 if (status & TxAvailable) {
868 DEBUG(3, " TX room bit was handled.\n");
869 /* There's room in the FIFO for a full-sized packet. */
870 outw(AckIntr | TxAvailable, ioaddr + EL3_CMD);
871 netif_wake_queue(dev);
872 }
873
874 if (status & TxComplete)
875 pop_tx_status(dev);
876
877 if (status & (AdapterFailure | RxEarly | StatsFull)) {
878 /* Handle all uncommon interrupts. */
879 if (status & StatsFull)
880 update_stats(dev);
881 if (status & RxEarly) {
882 work_budget = el3_rx(dev, work_budget);
883 outw(AckIntr | RxEarly, ioaddr + EL3_CMD);
884 }
885 if (status & AdapterFailure) {
886 u16 fifo_diag;
887 EL3WINDOW(4);
888 fifo_diag = inw(ioaddr + Wn4_FIFODiag);
889 EL3WINDOW(1);
890 printk(KERN_NOTICE "%s: adapter failure, FIFO diagnostic"
891 " register %04x.\n", dev->name, fifo_diag);
892 if (fifo_diag & 0x0400) {
893 /* Tx overrun */
894 tc574_wait_for_completion(dev, TxReset);
895 outw(TxEnable, ioaddr + EL3_CMD);
896 }
897 if (fifo_diag & 0x2000) {
898 /* Rx underrun */
899 tc574_wait_for_completion(dev, RxReset);
900 set_rx_mode(dev);
901 outw(RxEnable, ioaddr + EL3_CMD);
902 }
903 outw(AckIntr | AdapterFailure, ioaddr + EL3_CMD);
904 }
905 }
906
907 if (--work_budget < 0) {
908 DEBUG(0, "%s: Too much work in interrupt, "
909 "status %4.4x.\n", dev->name, status);
910 /* Clear all interrupts */
911 outw(AckIntr | 0xFF, ioaddr + EL3_CMD);
912 break;
913 }
914 /* Acknowledge the IRQ. */
915 outw(AckIntr | IntReq | IntLatch, ioaddr + EL3_CMD);
916 }
917
918 DEBUG(3, "%s: exiting interrupt, status %4.4x.\n",
919 dev->name, inw(ioaddr + EL3_STATUS));
920
921 spin_unlock(&lp->window_lock);
922 return IRQ_RETVAL(handled);
923}
924
925/*
926 This timer serves two purposes: to check for missed interrupts
927 (and as a last resort, poll the NIC for events), and to monitor
928 the MII, reporting changes in cable status.
929*/
930static void media_check(unsigned long arg)
931{
932 struct net_device *dev = (struct net_device *) arg;
933 struct el3_private *lp = netdev_priv(dev);
934 kio_addr_t ioaddr = dev->base_addr;
935 unsigned long flags;
936 unsigned short /* cable, */ media, partner;
937
938 if (!netif_device_present(dev))
939 goto reschedule;
940
941 /* Check for pending interrupt with expired latency timer: with
942 this, we can limp along even if the interrupt is blocked */
943 if ((inw(ioaddr + EL3_STATUS) & IntLatch) && (inb(ioaddr + Timer) == 0xff)) {
944 if (!lp->fast_poll)
945 printk(KERN_INFO "%s: interrupt(s) dropped!\n", dev->name);
946 el3_interrupt(dev->irq, lp, NULL);
947 lp->fast_poll = HZ;
948 }
949 if (lp->fast_poll) {
950 lp->fast_poll--;
951 lp->media.expires = jiffies + 2*HZ/100;
952 add_timer(&lp->media);
953 return;
954 }
955
956 spin_lock_irqsave(&lp->window_lock, flags);
957 EL3WINDOW(4);
958 media = mdio_read(ioaddr, lp->phys, 1);
959 partner = mdio_read(ioaddr, lp->phys, 5);
960 EL3WINDOW(1);
961
962 if (media != lp->media_status) {
963 if ((media ^ lp->media_status) & 0x0004)
964 printk(KERN_INFO "%s: %s link beat\n", dev->name,
965 (lp->media_status & 0x0004) ? "lost" : "found");
966 if ((media ^ lp->media_status) & 0x0020) {
967 lp->partner = 0;
968 if (lp->media_status & 0x0020) {
969 printk(KERN_INFO "%s: autonegotiation restarted\n",
970 dev->name);
971 } else if (partner) {
972 partner &= lp->advertising;
973 lp->partner = partner;
974 printk(KERN_INFO "%s: autonegotiation complete: "
975 "%sbaseT-%cD selected\n", dev->name,
976 ((partner & 0x0180) ? "100" : "10"),
977 ((partner & 0x0140) ? 'F' : 'H'));
978 } else {
979 printk(KERN_INFO "%s: link partner did not autonegotiate\n",
980 dev->name);
981 }
982
983 EL3WINDOW(3);
984 outb((partner & 0x0140 ? 0x20 : 0) |
985 (dev->mtu > 1500 ? 0x40 : 0), ioaddr + Wn3_MAC_Ctrl);
986 EL3WINDOW(1);
987
988 }
989 if (media & 0x0010)
990 printk(KERN_INFO "%s: remote fault detected\n",
991 dev->name);
992 if (media & 0x0002)
993 printk(KERN_INFO "%s: jabber detected\n", dev->name);
994 lp->media_status = media;
995 }
996 spin_unlock_irqrestore(&lp->window_lock, flags);
997
998reschedule:
999 lp->media.expires = jiffies + HZ;
1000 add_timer(&lp->media);
1001}
1002
1003static struct net_device_stats *el3_get_stats(struct net_device *dev)
1004{
1005 struct el3_private *lp = netdev_priv(dev);
1006
1007 if (netif_device_present(dev)) {
1008 unsigned long flags;
1009 spin_lock_irqsave(&lp->window_lock, flags);
1010 update_stats(dev);
1011 spin_unlock_irqrestore(&lp->window_lock, flags);
1012 }
1013 return &lp->stats;
1014}
1015
1016/* Update statistics.
1017 Suprisingly this need not be run single-threaded, but it effectively is.
1018 The counters clear when read, so the adds must merely be atomic.
1019 */
1020static void update_stats(struct net_device *dev)
1021{
1022 struct el3_private *lp = netdev_priv(dev);
1023 kio_addr_t ioaddr = dev->base_addr;
1024 u8 rx, tx, up;
1025
1026 DEBUG(2, "%s: updating the statistics.\n", dev->name);
1027
1028 if (inw(ioaddr+EL3_STATUS) == 0xffff) /* No card. */
1029 return;
1030
1031 /* Unlike the 3c509 we need not turn off stats updates while reading. */
1032 /* Switch to the stats window, and read everything. */
1033 EL3WINDOW(6);
1034 lp->stats.tx_carrier_errors += inb(ioaddr + 0);
1035 lp->stats.tx_heartbeat_errors += inb(ioaddr + 1);
1036 /* Multiple collisions. */ inb(ioaddr + 2);
1037 lp->stats.collisions += inb(ioaddr + 3);
1038 lp->stats.tx_window_errors += inb(ioaddr + 4);
1039 lp->stats.rx_fifo_errors += inb(ioaddr + 5);
1040 lp->stats.tx_packets += inb(ioaddr + 6);
1041 up = inb(ioaddr + 9);
1042 lp->stats.tx_packets += (up&0x30) << 4;
1043 /* Rx packets */ inb(ioaddr + 7);
1044 /* Tx deferrals */ inb(ioaddr + 8);
1045 rx = inw(ioaddr + 10);
1046 tx = inw(ioaddr + 12);
1047
1048 EL3WINDOW(4);
1049 /* BadSSD */ inb(ioaddr + 12);
1050 up = inb(ioaddr + 13);
1051
1052 lp->stats.tx_bytes += tx + ((up & 0xf0) << 12);
1053
1054 EL3WINDOW(1);
1055}
1056
1057static int el3_rx(struct net_device *dev, int worklimit)
1058{
1059 struct el3_private *lp = netdev_priv(dev);
1060 kio_addr_t ioaddr = dev->base_addr;
1061 short rx_status;
1062
1063 DEBUG(3, "%s: in rx_packet(), status %4.4x, rx_status %4.4x.\n",
1064 dev->name, inw(ioaddr+EL3_STATUS), inw(ioaddr+RxStatus));
1065 while (!((rx_status = inw(ioaddr + RxStatus)) & 0x8000) &&
1066 (--worklimit >= 0)) {
1067 if (rx_status & 0x4000) { /* Error, update stats. */
1068 short error = rx_status & 0x3800;
1069 lp->stats.rx_errors++;
1070 switch (error) {
1071 case 0x0000: lp->stats.rx_over_errors++; break;
1072 case 0x0800: lp->stats.rx_length_errors++; break;
1073 case 0x1000: lp->stats.rx_frame_errors++; break;
1074 case 0x1800: lp->stats.rx_length_errors++; break;
1075 case 0x2000: lp->stats.rx_frame_errors++; break;
1076 case 0x2800: lp->stats.rx_crc_errors++; break;
1077 }
1078 } else {
1079 short pkt_len = rx_status & 0x7ff;
1080 struct sk_buff *skb;
1081
1082 skb = dev_alloc_skb(pkt_len+5);
1083
1084 DEBUG(3, " Receiving packet size %d status %4.4x.\n",
1085 pkt_len, rx_status);
1086 if (skb != NULL) {
1087 skb->dev = dev;
1088 skb_reserve(skb, 2);
1089 insl(ioaddr+RX_FIFO, skb_put(skb, pkt_len),
1090 ((pkt_len+3)>>2));
1091 skb->protocol = eth_type_trans(skb, dev);
1092 netif_rx(skb);
1093 dev->last_rx = jiffies;
1094 lp->stats.rx_packets++;
1095 lp->stats.rx_bytes += pkt_len;
1096 } else {
1097 DEBUG(1, "%s: couldn't allocate a sk_buff of"
1098 " size %d.\n", dev->name, pkt_len);
1099 lp->stats.rx_dropped++;
1100 }
1101 }
1102 tc574_wait_for_completion(dev, RxDiscard);
1103 }
1104
1105 return worklimit;
1106}
1107
1108static void netdev_get_drvinfo(struct net_device *dev,
1109 struct ethtool_drvinfo *info)
1110{
1111 strcpy(info->driver, "3c574_cs");
1112}
1113
1114static struct ethtool_ops netdev_ethtool_ops = {
1115 .get_drvinfo = netdev_get_drvinfo,
1116};
1117
1118/* Provide ioctl() calls to examine the MII xcvr state. */
1119static int el3_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1120{
1121 struct el3_private *lp = netdev_priv(dev);
1122 kio_addr_t ioaddr = dev->base_addr;
1123 u16 *data = (u16 *)&rq->ifr_ifru;
1124 int phy = lp->phys & 0x1f;
1125
1126 DEBUG(2, "%s: In ioct(%-.6s, %#4.4x) %4.4x %4.4x %4.4x %4.4x.\n",
1127 dev->name, rq->ifr_ifrn.ifrn_name, cmd,
1128 data[0], data[1], data[2], data[3]);
1129
1130 switch(cmd) {
1131 case SIOCGMIIPHY: /* Get the address of the PHY in use. */
1132 data[0] = phy;
1133 case SIOCGMIIREG: /* Read the specified MII register. */
1134 {
1135 int saved_window;
1136 unsigned long flags;
1137
1138 spin_lock_irqsave(&lp->window_lock, flags);
1139 saved_window = inw(ioaddr + EL3_CMD) >> 13;
1140 EL3WINDOW(4);
1141 data[3] = mdio_read(ioaddr, data[0] & 0x1f, data[1] & 0x1f);
1142 EL3WINDOW(saved_window);
1143 spin_unlock_irqrestore(&lp->window_lock, flags);
1144 return 0;
1145 }
1146 case SIOCSMIIREG: /* Write the specified MII register */
1147 {
1148 int saved_window;
1149 unsigned long flags;
1150
1151 if (!capable(CAP_NET_ADMIN))
1152 return -EPERM;
1153 spin_lock_irqsave(&lp->window_lock, flags);
1154 saved_window = inw(ioaddr + EL3_CMD) >> 13;
1155 EL3WINDOW(4);
1156 mdio_write(ioaddr, data[0] & 0x1f, data[1] & 0x1f, data[2]);
1157 EL3WINDOW(saved_window);
1158 spin_unlock_irqrestore(&lp->window_lock, flags);
1159 return 0;
1160 }
1161 default:
1162 return -EOPNOTSUPP;
1163 }
1164}
1165
1166/* The Odie chip has a 64 bin multicast filter, but the bit layout is not
1167 documented. Until it is we revert to receiving all multicast frames when
1168 any multicast reception is desired.
1169 Note: My other drivers emit a log message whenever promiscuous mode is
1170 entered to help detect password sniffers. This is less desirable on
1171 typical PC card machines, so we omit the message.
1172 */
1173
1174static void set_rx_mode(struct net_device *dev)
1175{
1176 kio_addr_t ioaddr = dev->base_addr;
1177
1178 if (dev->flags & IFF_PROMISC)
1179 outw(SetRxFilter | RxStation | RxMulticast | RxBroadcast | RxProm,
1180 ioaddr + EL3_CMD);
1181 else if (dev->mc_count || (dev->flags & IFF_ALLMULTI))
1182 outw(SetRxFilter|RxStation|RxMulticast|RxBroadcast, ioaddr + EL3_CMD);
1183 else
1184 outw(SetRxFilter | RxStation | RxBroadcast, ioaddr + EL3_CMD);
1185}
1186
1187static int el3_close(struct net_device *dev)
1188{
1189 kio_addr_t ioaddr = dev->base_addr;
1190 struct el3_private *lp = netdev_priv(dev);
1191 dev_link_t *link = &lp->link;
1192
1193 DEBUG(2, "%s: shutting down ethercard.\n", dev->name);
1194
1195 if (DEV_OK(link)) {
1196 unsigned long flags;
1197
1198 /* Turn off statistics ASAP. We update lp->stats below. */
1199 outw(StatsDisable, ioaddr + EL3_CMD);
1200
1201 /* Disable the receiver and transmitter. */
1202 outw(RxDisable, ioaddr + EL3_CMD);
1203 outw(TxDisable, ioaddr + EL3_CMD);
1204
1205 /* Note: Switching to window 0 may disable the IRQ. */
1206 EL3WINDOW(0);
1207 spin_lock_irqsave(&lp->window_lock, flags);
1208 update_stats(dev);
1209 spin_unlock_irqrestore(&lp->window_lock, flags);
b9a6eaff
DR
1210
1211 /* force interrupts off */
1212 outw(SetIntrEnb | 0x0000, ioaddr + EL3_CMD);
1da177e4
LT
1213 }
1214
1215 link->open--;
1216 netif_stop_queue(dev);
1217 del_timer_sync(&lp->media);
1218
1219 return 0;
1220}
1221
270b6e94
DB
1222static struct pcmcia_device_id tc574_ids[] = {
1223 PCMCIA_DEVICE_MANF_CARD(0x0101, 0x0574),
1224 PCMCIA_MFC_DEVICE_CIS_MANF_CARD(0, 0x0101, 0x0556, "3CCFEM556.cis"),
1225 PCMCIA_DEVICE_NULL,
1226};
1227MODULE_DEVICE_TABLE(pcmcia, tc574_ids);
1228
1da177e4
LT
1229static struct pcmcia_driver tc574_driver = {
1230 .owner = THIS_MODULE,
1231 .drv = {
1232 .name = "3c574_cs",
1233 },
f8cfa618 1234 .probe = tc574_attach,
cc3b4866 1235 .remove = tc574_detach,
270b6e94 1236 .id_table = tc574_ids,
98e4c28b
DB
1237 .suspend = tc574_suspend,
1238 .resume = tc574_resume,
1da177e4
LT
1239};
1240
1241static int __init init_tc574(void)
1242{
1243 return pcmcia_register_driver(&tc574_driver);
1244}
1245
1246static void __exit exit_tc574(void)
1247{
1248 pcmcia_unregister_driver(&tc574_driver);
1da177e4
LT
1249}
1250
1251module_init(init_tc574);
1252module_exit(exit_tc574);