blob: 1799660bdc6731163d55cb72dec83bad73ad1768 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070089#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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230
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
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100251static void tc574_detach(struct pcmcia_device *p_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253/*
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
Dominik Brodowskif8cfa612005-11-14 21:25:51 +0100259static int tc574_attach(struct pcmcia_device *p_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260{
261 struct el3_private *lp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 dev_link_t *link;
263 struct net_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
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)
Dominik Brodowskif8cfa612005-11-14 21:25:51 +0100270 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 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;
283 link->conf.Vcc = 50;
284 link->conf.IntType = INT_MEMORY_AND_IO;
285 link->conf.ConfigIndex = 1;
286 link->conf.Present = PRESENT_OPTION;
287
288 /* The EL3-specific entries in the device structure. */
289 dev->hard_start_xmit = &el3_start_xmit;
290 dev->get_stats = &el3_get_stats;
291 dev->do_ioctl = &el3_ioctl;
292 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
293 dev->set_multicast_list = &set_rx_mode;
294 dev->open = &el3_open;
295 dev->stop = &el3_close;
296#ifdef HAVE_TX_TIMEOUT
297 dev->tx_timeout = el3_tx_timeout;
298 dev->watchdog_timeo = TX_TIMEOUT;
299#endif
300
Dominik Brodowskif8cfa612005-11-14 21:25:51 +0100301 link->handle = p_dev;
302 p_dev->instance = link;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
Dominik Brodowskif8cfa612005-11-14 21:25:51 +0100304 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
305 tc574_config(link);
306
307 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308} /* tc574_attach */
309
310/*
311
312 This deletes a driver "instance". The device is de-registered
313 with Card Services. If it has been released, all local data
314 structures are freed. Otherwise, the structures will be freed
315 when the device is released.
316
317*/
318
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100319static void tc574_detach(struct pcmcia_device *p_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320{
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100321 dev_link_t *link = dev_to_instance(p_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 struct net_device *dev = link->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
324 DEBUG(0, "3c574_detach(0x%p)\n", link);
325
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 if (link->dev)
327 unregister_netdev(dev);
328
329 if (link->state & DEV_CONFIG)
330 tc574_release(link);
331
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 free_netdev(dev);
333} /* tc574_detach */
334
335/*
336 tc574_config() is scheduled to run after a CARD_INSERTION event
337 is received, to configure the PCMCIA socket, and to make the
338 ethernet device available to the system.
339*/
340
341#define CS_CHECK(fn, ret) \
342 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
343
Arjan van de Venf71e1302006-03-03 21:33:57 -0500344static const char *ram_split[] = {"5:3", "3:1", "1:1", "3:5"};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
346static void tc574_config(dev_link_t *link)
347{
348 client_handle_t handle = link->handle;
349 struct net_device *dev = link->priv;
350 struct el3_private *lp = netdev_priv(dev);
351 tuple_t tuple;
352 cisparse_t parse;
353 unsigned short buf[32];
354 int last_fn, last_ret, i, j;
355 kio_addr_t ioaddr;
356 u16 *phys_addr;
357 char *cardname;
358 union wn3_config config;
359
360 phys_addr = (u16 *)dev->dev_addr;
361
362 DEBUG(0, "3c574_config(0x%p)\n", link);
363
364 tuple.Attributes = 0;
365 tuple.DesiredTuple = CISTPL_CONFIG;
366 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));
367 tuple.TupleData = (cisdata_t *)buf;
368 tuple.TupleDataMax = 64;
369 tuple.TupleOffset = 0;
370 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple));
371 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse));
372 link->conf.ConfigBase = parse.config.base;
373 link->conf.Present = parse.config.rmask[0];
374
375 /* Configure card */
376 link->state |= DEV_CONFIG;
377
378 link->io.IOAddrLines = 16;
379 for (i = j = 0; j < 0x400; j += 0x20) {
380 link->io.BasePort1 = j ^ 0x300;
381 i = pcmcia_request_io(link->handle, &link->io);
382 if (i == CS_SUCCESS) break;
383 }
384 if (i != CS_SUCCESS) {
385 cs_error(link->handle, RequestIO, i);
386 goto failed;
387 }
388 CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq));
389 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link->handle, &link->conf));
390
391 dev->irq = link->irq.AssignedIRQ;
392 dev->base_addr = link->io.BasePort1;
393
394 ioaddr = dev->base_addr;
395
396 /* The 3c574 normally uses an EEPROM for configuration info, including
397 the hardware address. The future products may include a modem chip
398 and put the address in the CIS. */
399 tuple.DesiredTuple = 0x88;
400 if (pcmcia_get_first_tuple(handle, &tuple) == CS_SUCCESS) {
401 pcmcia_get_tuple_data(handle, &tuple);
402 for (i = 0; i < 3; i++)
403 phys_addr[i] = htons(buf[i]);
404 } else {
405 EL3WINDOW(0);
406 for (i = 0; i < 3; i++)
407 phys_addr[i] = htons(read_eeprom(ioaddr, i + 10));
408 if (phys_addr[0] == 0x6060) {
409 printk(KERN_NOTICE "3c574_cs: IO port conflict at 0x%03lx"
410 "-0x%03lx\n", dev->base_addr, dev->base_addr+15);
411 goto failed;
412 }
413 }
414 tuple.DesiredTuple = CISTPL_VERS_1;
415 if (pcmcia_get_first_tuple(handle, &tuple) == CS_SUCCESS &&
416 pcmcia_get_tuple_data(handle, &tuple) == CS_SUCCESS &&
417 pcmcia_parse_tuple(handle, &tuple, &parse) == CS_SUCCESS) {
418 cardname = parse.version_1.str + parse.version_1.ofs[1];
419 } else
420 cardname = "3Com 3c574";
421
422 {
423 u_char mcr;
424 outw(2<<11, ioaddr + RunnerRdCtrl);
425 mcr = inb(ioaddr + 2);
426 outw(0<<11, ioaddr + RunnerRdCtrl);
427 printk(KERN_INFO " ASIC rev %d,", mcr>>3);
428 EL3WINDOW(3);
429 config.i = inl(ioaddr + Wn3_Config);
430 lp->default_media = config.u.xcvr;
431 lp->autoselect = config.u.autoselect;
432 }
433
434 init_timer(&lp->media);
435
436 {
437 int phy;
438
439 /* Roadrunner only: Turn on the MII transceiver */
440 outw(0x8040, ioaddr + Wn3_Options);
441 mdelay(1);
442 outw(0xc040, ioaddr + Wn3_Options);
443 tc574_wait_for_completion(dev, TxReset);
444 tc574_wait_for_completion(dev, RxReset);
445 mdelay(1);
446 outw(0x8040, ioaddr + Wn3_Options);
447
448 EL3WINDOW(4);
449 for (phy = 1; phy <= 32; phy++) {
450 int mii_status;
451 mdio_sync(ioaddr, 32);
452 mii_status = mdio_read(ioaddr, phy & 0x1f, 1);
453 if (mii_status != 0xffff) {
454 lp->phys = phy & 0x1f;
455 DEBUG(0, " MII transceiver at index %d, status %x.\n",
456 phy, mii_status);
457 if ((mii_status & 0x0040) == 0)
458 mii_preamble_required = 1;
459 break;
460 }
461 }
462 if (phy > 32) {
463 printk(KERN_NOTICE " No MII transceivers found!\n");
464 goto failed;
465 }
466 i = mdio_read(ioaddr, lp->phys, 16) | 0x40;
467 mdio_write(ioaddr, lp->phys, 16, i);
468 lp->advertising = mdio_read(ioaddr, lp->phys, 4);
469 if (full_duplex) {
470 /* Only advertise the FD media types. */
471 lp->advertising &= ~0x02a0;
472 mdio_write(ioaddr, lp->phys, 4, lp->advertising);
473 }
474 }
475
476 link->state &= ~DEV_CONFIG_PENDING;
477 link->dev = &lp->node;
478 SET_NETDEV_DEV(dev, &handle_to_dev(handle));
479
480 if (register_netdev(dev) != 0) {
481 printk(KERN_NOTICE "3c574_cs: register_netdev() failed\n");
482 link->dev = NULL;
483 goto failed;
484 }
485
486 strcpy(lp->node.dev_name, dev->name);
487
488 printk(KERN_INFO "%s: %s at io %#3lx, irq %d, hw_addr ",
489 dev->name, cardname, dev->base_addr, dev->irq);
490 for (i = 0; i < 6; i++)
491 printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : ".\n"));
492 printk(" %dK FIFO split %s Rx:Tx, %sMII interface.\n",
493 8 << config.u.ram_size, ram_split[config.u.ram_split],
494 config.u.autoselect ? "autoselect " : "");
495
496 return;
497
498cs_failed:
499 cs_error(link->handle, last_fn, last_ret);
500failed:
501 tc574_release(link);
502 return;
503
504} /* tc574_config */
505
506/*
507 After a card is removed, tc574_release() will unregister the net
508 device, and release the PCMCIA configuration. If the device is
509 still open, this will be postponed until it is closed.
510*/
511
512static void tc574_release(dev_link_t *link)
513{
Dominik Brodowski5f2a71f2006-01-15 09:32:39 +0100514 pcmcia_disable_device(link->handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515}
516
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100517static int tc574_suspend(struct pcmcia_device *p_dev)
518{
519 dev_link_t *link = dev_to_instance(p_dev);
520 struct net_device *dev = link->priv;
521
522 link->state |= DEV_SUSPEND;
523 if (link->state & DEV_CONFIG) {
524 if (link->open)
525 netif_device_detach(dev);
526 pcmcia_release_configuration(link->handle);
527 }
528
529 return 0;
530}
531
532static int tc574_resume(struct pcmcia_device *p_dev)
533{
534 dev_link_t *link = dev_to_instance(p_dev);
535 struct net_device *dev = link->priv;
536
537 link->state &= ~DEV_SUSPEND;
538 if (link->state & DEV_CONFIG) {
539 pcmcia_request_configuration(link->handle, &link->conf);
540 if (link->open) {
541 tc574_reset(dev);
542 netif_device_attach(dev);
543 }
544 }
545
546 return 0;
547}
548
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549static void dump_status(struct net_device *dev)
550{
551 kio_addr_t ioaddr = dev->base_addr;
552 EL3WINDOW(1);
553 printk(KERN_INFO " irq status %04x, rx status %04x, tx status "
554 "%02x, tx free %04x\n", inw(ioaddr+EL3_STATUS),
555 inw(ioaddr+RxStatus), inb(ioaddr+TxStatus),
556 inw(ioaddr+TxFree));
557 EL3WINDOW(4);
558 printk(KERN_INFO " diagnostics: fifo %04x net %04x ethernet %04x"
559 " media %04x\n", inw(ioaddr+0x04), inw(ioaddr+0x06),
560 inw(ioaddr+0x08), inw(ioaddr+0x0a));
561 EL3WINDOW(1);
562}
563
564/*
565 Use this for commands that may take time to finish
566*/
567static void tc574_wait_for_completion(struct net_device *dev, int cmd)
568{
569 int i = 1500;
570 outw(cmd, dev->base_addr + EL3_CMD);
571 while (--i > 0)
572 if (!(inw(dev->base_addr + EL3_STATUS) & 0x1000)) break;
573 if (i == 0)
574 printk(KERN_NOTICE "%s: command 0x%04x did not complete!\n", dev->name, cmd);
575}
576
577/* Read a word from the EEPROM using the regular EEPROM access register.
578 Assume that we are in register window zero.
579 */
580static unsigned short read_eeprom(kio_addr_t ioaddr, int index)
581{
582 int timer;
583 outw(EEPROM_Read + index, ioaddr + Wn0EepromCmd);
584 /* Pause for at least 162 usec for the read to take place. */
585 for (timer = 1620; timer >= 0; timer--) {
586 if ((inw(ioaddr + Wn0EepromCmd) & 0x8000) == 0)
587 break;
588 }
589 return inw(ioaddr + Wn0EepromData);
590}
591
592/* MII transceiver control section.
593 Read and write the MII registers using software-generated serial
594 MDIO protocol. See the MII specifications or DP83840A data sheet
595 for details.
596 The maxium data clock rate is 2.5 Mhz. The timing is easily met by the
597 slow PC card interface. */
598
599#define MDIO_SHIFT_CLK 0x01
600#define MDIO_DIR_WRITE 0x04
601#define MDIO_DATA_WRITE0 (0x00 | MDIO_DIR_WRITE)
602#define MDIO_DATA_WRITE1 (0x02 | MDIO_DIR_WRITE)
603#define MDIO_DATA_READ 0x02
604#define MDIO_ENB_IN 0x00
605
606/* Generate the preamble required for initial synchronization and
607 a few older transceivers. */
608static void mdio_sync(kio_addr_t ioaddr, int bits)
609{
610 kio_addr_t mdio_addr = ioaddr + Wn4_PhysicalMgmt;
611
612 /* Establish sync by sending at least 32 logic ones. */
613 while (-- bits >= 0) {
614 outw(MDIO_DATA_WRITE1, mdio_addr);
615 outw(MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, mdio_addr);
616 }
617}
618
619static int mdio_read(kio_addr_t ioaddr, int phy_id, int location)
620{
621 int i;
622 int read_cmd = (0xf6 << 10) | (phy_id << 5) | location;
623 unsigned int retval = 0;
624 kio_addr_t mdio_addr = ioaddr + Wn4_PhysicalMgmt;
625
626 if (mii_preamble_required)
627 mdio_sync(ioaddr, 32);
628
629 /* Shift the read command bits out. */
630 for (i = 14; i >= 0; i--) {
631 int dataval = (read_cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
632 outw(dataval, mdio_addr);
633 outw(dataval | MDIO_SHIFT_CLK, mdio_addr);
634 }
635 /* Read the two transition, 16 data, and wire-idle bits. */
636 for (i = 19; i > 0; i--) {
637 outw(MDIO_ENB_IN, mdio_addr);
638 retval = (retval << 1) | ((inw(mdio_addr) & MDIO_DATA_READ) ? 1 : 0);
639 outw(MDIO_ENB_IN | MDIO_SHIFT_CLK, mdio_addr);
640 }
641 return (retval>>1) & 0xffff;
642}
643
644static void mdio_write(kio_addr_t ioaddr, int phy_id, int location, int value)
645{
646 int write_cmd = 0x50020000 | (phy_id << 23) | (location << 18) | value;
647 kio_addr_t mdio_addr = ioaddr + Wn4_PhysicalMgmt;
648 int i;
649
650 if (mii_preamble_required)
651 mdio_sync(ioaddr, 32);
652
653 /* Shift the command bits out. */
654 for (i = 31; i >= 0; i--) {
655 int dataval = (write_cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
656 outw(dataval, mdio_addr);
657 outw(dataval | MDIO_SHIFT_CLK, mdio_addr);
658 }
659 /* Leave the interface idle. */
660 for (i = 1; i >= 0; i--) {
661 outw(MDIO_ENB_IN, mdio_addr);
662 outw(MDIO_ENB_IN | MDIO_SHIFT_CLK, mdio_addr);
663 }
664
665 return;
666}
667
668/* Reset and restore all of the 3c574 registers. */
669static void tc574_reset(struct net_device *dev)
670{
671 struct el3_private *lp = netdev_priv(dev);
672 int i;
673 kio_addr_t ioaddr = dev->base_addr;
674 unsigned long flags;
675
676 tc574_wait_for_completion(dev, TotalReset|0x10);
677
678 spin_lock_irqsave(&lp->window_lock, flags);
679 /* Clear any transactions in progress. */
680 outw(0, ioaddr + RunnerWrCtrl);
681 outw(0, ioaddr + RunnerRdCtrl);
682
683 /* Set the station address and mask. */
684 EL3WINDOW(2);
685 for (i = 0; i < 6; i++)
686 outb(dev->dev_addr[i], ioaddr + i);
687 for (; i < 12; i+=2)
688 outw(0, ioaddr + i);
689
690 /* Reset config options */
691 EL3WINDOW(3);
692 outb((dev->mtu > 1500 ? 0x40 : 0), ioaddr + Wn3_MAC_Ctrl);
693 outl((lp->autoselect ? 0x01000000 : 0) | 0x0062001b,
694 ioaddr + Wn3_Config);
695 /* Roadrunner only: Turn on the MII transceiver. */
696 outw(0x8040, ioaddr + Wn3_Options);
697 mdelay(1);
698 outw(0xc040, ioaddr + Wn3_Options);
699 EL3WINDOW(1);
700 spin_unlock_irqrestore(&lp->window_lock, flags);
701
702 tc574_wait_for_completion(dev, TxReset);
703 tc574_wait_for_completion(dev, RxReset);
704 mdelay(1);
705 spin_lock_irqsave(&lp->window_lock, flags);
706 EL3WINDOW(3);
707 outw(0x8040, ioaddr + Wn3_Options);
708
709 /* Switch to the stats window, and clear all stats by reading. */
710 outw(StatsDisable, ioaddr + EL3_CMD);
711 EL3WINDOW(6);
712 for (i = 0; i < 10; i++)
713 inb(ioaddr + i);
714 inw(ioaddr + 10);
715 inw(ioaddr + 12);
716 EL3WINDOW(4);
717 inb(ioaddr + 12);
718 inb(ioaddr + 13);
719
720 /* .. enable any extra statistics bits.. */
721 outw(0x0040, ioaddr + Wn4_NetDiag);
722
723 EL3WINDOW(1);
724 spin_unlock_irqrestore(&lp->window_lock, flags);
725
726 /* .. re-sync MII and re-fill what NWay is advertising. */
727 mdio_sync(ioaddr, 32);
728 mdio_write(ioaddr, lp->phys, 4, lp->advertising);
729 if (!auto_polarity) {
730 /* works for TDK 78Q2120 series MII's */
731 int i = mdio_read(ioaddr, lp->phys, 16) | 0x20;
732 mdio_write(ioaddr, lp->phys, 16, i);
733 }
734
735 spin_lock_irqsave(&lp->window_lock, flags);
736 /* Switch to register set 1 for normal use, just for TxFree. */
737 set_rx_mode(dev);
738 spin_unlock_irqrestore(&lp->window_lock, flags);
739 outw(StatsEnable, ioaddr + EL3_CMD); /* Turn on statistics. */
740 outw(RxEnable, ioaddr + EL3_CMD); /* Enable the receiver. */
741 outw(TxEnable, ioaddr + EL3_CMD); /* Enable transmitter. */
742 /* Allow status bits to be seen. */
743 outw(SetStatusEnb | 0xff, ioaddr + EL3_CMD);
744 /* Ack all pending events, and set active indicator mask. */
745 outw(AckIntr | IntLatch | TxAvailable | RxEarly | IntReq,
746 ioaddr + EL3_CMD);
747 outw(SetIntrEnb | IntLatch | TxAvailable | RxComplete | StatsFull
748 | AdapterFailure | RxEarly, ioaddr + EL3_CMD);
749}
750
751static int el3_open(struct net_device *dev)
752{
753 struct el3_private *lp = netdev_priv(dev);
754 dev_link_t *link = &lp->link;
755
756 if (!DEV_OK(link))
757 return -ENODEV;
758
759 link->open++;
760 netif_start_queue(dev);
761
762 tc574_reset(dev);
763 lp->media.function = &media_check;
764 lp->media.data = (unsigned long) dev;
765 lp->media.expires = jiffies + HZ;
766 add_timer(&lp->media);
767
768 DEBUG(2, "%s: opened, status %4.4x.\n",
769 dev->name, inw(dev->base_addr + EL3_STATUS));
770
771 return 0;
772}
773
774static void el3_tx_timeout(struct net_device *dev)
775{
776 struct el3_private *lp = netdev_priv(dev);
777 kio_addr_t ioaddr = dev->base_addr;
778
779 printk(KERN_NOTICE "%s: Transmit timed out!\n", dev->name);
780 dump_status(dev);
781 lp->stats.tx_errors++;
782 dev->trans_start = jiffies;
783 /* Issue TX_RESET and TX_START commands. */
784 tc574_wait_for_completion(dev, TxReset);
785 outw(TxEnable, ioaddr + EL3_CMD);
786 netif_wake_queue(dev);
787}
788
789static void pop_tx_status(struct net_device *dev)
790{
791 struct el3_private *lp = netdev_priv(dev);
792 kio_addr_t ioaddr = dev->base_addr;
793 int i;
794
795 /* Clear the Tx status stack. */
796 for (i = 32; i > 0; i--) {
797 u_char tx_status = inb(ioaddr + TxStatus);
798 if (!(tx_status & 0x84))
799 break;
800 /* reset transmitter on jabber error or underrun */
801 if (tx_status & 0x30)
802 tc574_wait_for_completion(dev, TxReset);
803 if (tx_status & 0x38) {
804 DEBUG(1, "%s: transmit error: status 0x%02x\n",
805 dev->name, tx_status);
806 outw(TxEnable, ioaddr + EL3_CMD);
807 lp->stats.tx_aborted_errors++;
808 }
809 outb(0x00, ioaddr + TxStatus); /* Pop the status stack. */
810 }
811}
812
813static int el3_start_xmit(struct sk_buff *skb, struct net_device *dev)
814{
815 kio_addr_t ioaddr = dev->base_addr;
816 struct el3_private *lp = netdev_priv(dev);
817 unsigned long flags;
818
819 DEBUG(3, "%s: el3_start_xmit(length = %ld) called, "
820 "status %4.4x.\n", dev->name, (long)skb->len,
821 inw(ioaddr + EL3_STATUS));
822
823 spin_lock_irqsave(&lp->window_lock, flags);
824 outw(skb->len, ioaddr + TX_FIFO);
825 outw(0, ioaddr + TX_FIFO);
826 outsl(ioaddr + TX_FIFO, skb->data, (skb->len+3)>>2);
827
828 dev->trans_start = jiffies;
829
830 /* TxFree appears only in Window 1, not offset 0x1c. */
831 if (inw(ioaddr + TxFree) <= 1536) {
832 netif_stop_queue(dev);
833 /* Interrupt us when the FIFO has room for max-sized packet.
834 The threshold is in units of dwords. */
835 outw(SetTxThreshold + (1536>>2), ioaddr + EL3_CMD);
836 }
837
838 pop_tx_status(dev);
839 spin_unlock_irqrestore(&lp->window_lock, flags);
840 dev_kfree_skb(skb);
841 return 0;
842}
843
844/* The EL3 interrupt handler. */
845static irqreturn_t el3_interrupt(int irq, void *dev_id, struct pt_regs *regs)
846{
847 struct net_device *dev = (struct net_device *) dev_id;
848 struct el3_private *lp = netdev_priv(dev);
849 kio_addr_t ioaddr;
850 unsigned status;
851 int work_budget = max_interrupt_work;
852 int handled = 0;
853
854 if (!netif_device_present(dev))
855 return IRQ_NONE;
856 ioaddr = dev->base_addr;
857
858 DEBUG(3, "%s: interrupt, status %4.4x.\n",
859 dev->name, inw(ioaddr + EL3_STATUS));
860
861 spin_lock(&lp->window_lock);
862
863 while ((status = inw(ioaddr + EL3_STATUS)) &
864 (IntLatch | RxComplete | RxEarly | StatsFull)) {
865 if (!netif_device_present(dev) ||
866 ((status & 0xe000) != 0x2000)) {
867 DEBUG(1, "%s: Interrupt from dead card\n", dev->name);
868 break;
869 }
870
871 handled = 1;
872
873 if (status & RxComplete)
874 work_budget = el3_rx(dev, work_budget);
875
876 if (status & TxAvailable) {
877 DEBUG(3, " TX room bit was handled.\n");
878 /* There's room in the FIFO for a full-sized packet. */
879 outw(AckIntr | TxAvailable, ioaddr + EL3_CMD);
880 netif_wake_queue(dev);
881 }
882
883 if (status & TxComplete)
884 pop_tx_status(dev);
885
886 if (status & (AdapterFailure | RxEarly | StatsFull)) {
887 /* Handle all uncommon interrupts. */
888 if (status & StatsFull)
889 update_stats(dev);
890 if (status & RxEarly) {
891 work_budget = el3_rx(dev, work_budget);
892 outw(AckIntr | RxEarly, ioaddr + EL3_CMD);
893 }
894 if (status & AdapterFailure) {
895 u16 fifo_diag;
896 EL3WINDOW(4);
897 fifo_diag = inw(ioaddr + Wn4_FIFODiag);
898 EL3WINDOW(1);
899 printk(KERN_NOTICE "%s: adapter failure, FIFO diagnostic"
900 " register %04x.\n", dev->name, fifo_diag);
901 if (fifo_diag & 0x0400) {
902 /* Tx overrun */
903 tc574_wait_for_completion(dev, TxReset);
904 outw(TxEnable, ioaddr + EL3_CMD);
905 }
906 if (fifo_diag & 0x2000) {
907 /* Rx underrun */
908 tc574_wait_for_completion(dev, RxReset);
909 set_rx_mode(dev);
910 outw(RxEnable, ioaddr + EL3_CMD);
911 }
912 outw(AckIntr | AdapterFailure, ioaddr + EL3_CMD);
913 }
914 }
915
916 if (--work_budget < 0) {
917 DEBUG(0, "%s: Too much work in interrupt, "
918 "status %4.4x.\n", dev->name, status);
919 /* Clear all interrupts */
920 outw(AckIntr | 0xFF, ioaddr + EL3_CMD);
921 break;
922 }
923 /* Acknowledge the IRQ. */
924 outw(AckIntr | IntReq | IntLatch, ioaddr + EL3_CMD);
925 }
926
927 DEBUG(3, "%s: exiting interrupt, status %4.4x.\n",
928 dev->name, inw(ioaddr + EL3_STATUS));
929
930 spin_unlock(&lp->window_lock);
931 return IRQ_RETVAL(handled);
932}
933
934/*
935 This timer serves two purposes: to check for missed interrupts
936 (and as a last resort, poll the NIC for events), and to monitor
937 the MII, reporting changes in cable status.
938*/
939static void media_check(unsigned long arg)
940{
941 struct net_device *dev = (struct net_device *) arg;
942 struct el3_private *lp = netdev_priv(dev);
943 kio_addr_t ioaddr = dev->base_addr;
944 unsigned long flags;
945 unsigned short /* cable, */ media, partner;
946
947 if (!netif_device_present(dev))
948 goto reschedule;
949
950 /* Check for pending interrupt with expired latency timer: with
951 this, we can limp along even if the interrupt is blocked */
952 if ((inw(ioaddr + EL3_STATUS) & IntLatch) && (inb(ioaddr + Timer) == 0xff)) {
953 if (!lp->fast_poll)
954 printk(KERN_INFO "%s: interrupt(s) dropped!\n", dev->name);
955 el3_interrupt(dev->irq, lp, NULL);
956 lp->fast_poll = HZ;
957 }
958 if (lp->fast_poll) {
959 lp->fast_poll--;
960 lp->media.expires = jiffies + 2*HZ/100;
961 add_timer(&lp->media);
962 return;
963 }
964
965 spin_lock_irqsave(&lp->window_lock, flags);
966 EL3WINDOW(4);
967 media = mdio_read(ioaddr, lp->phys, 1);
968 partner = mdio_read(ioaddr, lp->phys, 5);
969 EL3WINDOW(1);
970
971 if (media != lp->media_status) {
972 if ((media ^ lp->media_status) & 0x0004)
973 printk(KERN_INFO "%s: %s link beat\n", dev->name,
974 (lp->media_status & 0x0004) ? "lost" : "found");
975 if ((media ^ lp->media_status) & 0x0020) {
976 lp->partner = 0;
977 if (lp->media_status & 0x0020) {
978 printk(KERN_INFO "%s: autonegotiation restarted\n",
979 dev->name);
980 } else if (partner) {
981 partner &= lp->advertising;
982 lp->partner = partner;
983 printk(KERN_INFO "%s: autonegotiation complete: "
984 "%sbaseT-%cD selected\n", dev->name,
985 ((partner & 0x0180) ? "100" : "10"),
986 ((partner & 0x0140) ? 'F' : 'H'));
987 } else {
988 printk(KERN_INFO "%s: link partner did not autonegotiate\n",
989 dev->name);
990 }
991
992 EL3WINDOW(3);
993 outb((partner & 0x0140 ? 0x20 : 0) |
994 (dev->mtu > 1500 ? 0x40 : 0), ioaddr + Wn3_MAC_Ctrl);
995 EL3WINDOW(1);
996
997 }
998 if (media & 0x0010)
999 printk(KERN_INFO "%s: remote fault detected\n",
1000 dev->name);
1001 if (media & 0x0002)
1002 printk(KERN_INFO "%s: jabber detected\n", dev->name);
1003 lp->media_status = media;
1004 }
1005 spin_unlock_irqrestore(&lp->window_lock, flags);
1006
1007reschedule:
1008 lp->media.expires = jiffies + HZ;
1009 add_timer(&lp->media);
1010}
1011
1012static struct net_device_stats *el3_get_stats(struct net_device *dev)
1013{
1014 struct el3_private *lp = netdev_priv(dev);
1015
1016 if (netif_device_present(dev)) {
1017 unsigned long flags;
1018 spin_lock_irqsave(&lp->window_lock, flags);
1019 update_stats(dev);
1020 spin_unlock_irqrestore(&lp->window_lock, flags);
1021 }
1022 return &lp->stats;
1023}
1024
1025/* Update statistics.
1026 Suprisingly this need not be run single-threaded, but it effectively is.
1027 The counters clear when read, so the adds must merely be atomic.
1028 */
1029static void update_stats(struct net_device *dev)
1030{
1031 struct el3_private *lp = netdev_priv(dev);
1032 kio_addr_t ioaddr = dev->base_addr;
1033 u8 rx, tx, up;
1034
1035 DEBUG(2, "%s: updating the statistics.\n", dev->name);
1036
1037 if (inw(ioaddr+EL3_STATUS) == 0xffff) /* No card. */
1038 return;
1039
1040 /* Unlike the 3c509 we need not turn off stats updates while reading. */
1041 /* Switch to the stats window, and read everything. */
1042 EL3WINDOW(6);
1043 lp->stats.tx_carrier_errors += inb(ioaddr + 0);
1044 lp->stats.tx_heartbeat_errors += inb(ioaddr + 1);
1045 /* Multiple collisions. */ inb(ioaddr + 2);
1046 lp->stats.collisions += inb(ioaddr + 3);
1047 lp->stats.tx_window_errors += inb(ioaddr + 4);
1048 lp->stats.rx_fifo_errors += inb(ioaddr + 5);
1049 lp->stats.tx_packets += inb(ioaddr + 6);
1050 up = inb(ioaddr + 9);
1051 lp->stats.tx_packets += (up&0x30) << 4;
1052 /* Rx packets */ inb(ioaddr + 7);
1053 /* Tx deferrals */ inb(ioaddr + 8);
1054 rx = inw(ioaddr + 10);
1055 tx = inw(ioaddr + 12);
1056
1057 EL3WINDOW(4);
1058 /* BadSSD */ inb(ioaddr + 12);
1059 up = inb(ioaddr + 13);
1060
1061 lp->stats.tx_bytes += tx + ((up & 0xf0) << 12);
1062
1063 EL3WINDOW(1);
1064}
1065
1066static int el3_rx(struct net_device *dev, int worklimit)
1067{
1068 struct el3_private *lp = netdev_priv(dev);
1069 kio_addr_t ioaddr = dev->base_addr;
1070 short rx_status;
1071
1072 DEBUG(3, "%s: in rx_packet(), status %4.4x, rx_status %4.4x.\n",
1073 dev->name, inw(ioaddr+EL3_STATUS), inw(ioaddr+RxStatus));
1074 while (!((rx_status = inw(ioaddr + RxStatus)) & 0x8000) &&
1075 (--worklimit >= 0)) {
1076 if (rx_status & 0x4000) { /* Error, update stats. */
1077 short error = rx_status & 0x3800;
1078 lp->stats.rx_errors++;
1079 switch (error) {
1080 case 0x0000: lp->stats.rx_over_errors++; break;
1081 case 0x0800: lp->stats.rx_length_errors++; break;
1082 case 0x1000: lp->stats.rx_frame_errors++; break;
1083 case 0x1800: lp->stats.rx_length_errors++; break;
1084 case 0x2000: lp->stats.rx_frame_errors++; break;
1085 case 0x2800: lp->stats.rx_crc_errors++; break;
1086 }
1087 } else {
1088 short pkt_len = rx_status & 0x7ff;
1089 struct sk_buff *skb;
1090
1091 skb = dev_alloc_skb(pkt_len+5);
1092
1093 DEBUG(3, " Receiving packet size %d status %4.4x.\n",
1094 pkt_len, rx_status);
1095 if (skb != NULL) {
1096 skb->dev = dev;
1097 skb_reserve(skb, 2);
1098 insl(ioaddr+RX_FIFO, skb_put(skb, pkt_len),
1099 ((pkt_len+3)>>2));
1100 skb->protocol = eth_type_trans(skb, dev);
1101 netif_rx(skb);
1102 dev->last_rx = jiffies;
1103 lp->stats.rx_packets++;
1104 lp->stats.rx_bytes += pkt_len;
1105 } else {
1106 DEBUG(1, "%s: couldn't allocate a sk_buff of"
1107 " size %d.\n", dev->name, pkt_len);
1108 lp->stats.rx_dropped++;
1109 }
1110 }
1111 tc574_wait_for_completion(dev, RxDiscard);
1112 }
1113
1114 return worklimit;
1115}
1116
1117static void netdev_get_drvinfo(struct net_device *dev,
1118 struct ethtool_drvinfo *info)
1119{
1120 strcpy(info->driver, "3c574_cs");
1121}
1122
1123static struct ethtool_ops netdev_ethtool_ops = {
1124 .get_drvinfo = netdev_get_drvinfo,
1125};
1126
1127/* Provide ioctl() calls to examine the MII xcvr state. */
1128static int el3_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1129{
1130 struct el3_private *lp = netdev_priv(dev);
1131 kio_addr_t ioaddr = dev->base_addr;
1132 u16 *data = (u16 *)&rq->ifr_ifru;
1133 int phy = lp->phys & 0x1f;
1134
1135 DEBUG(2, "%s: In ioct(%-.6s, %#4.4x) %4.4x %4.4x %4.4x %4.4x.\n",
1136 dev->name, rq->ifr_ifrn.ifrn_name, cmd,
1137 data[0], data[1], data[2], data[3]);
1138
1139 switch(cmd) {
1140 case SIOCGMIIPHY: /* Get the address of the PHY in use. */
1141 data[0] = phy;
1142 case SIOCGMIIREG: /* Read the specified MII register. */
1143 {
1144 int saved_window;
1145 unsigned long flags;
1146
1147 spin_lock_irqsave(&lp->window_lock, flags);
1148 saved_window = inw(ioaddr + EL3_CMD) >> 13;
1149 EL3WINDOW(4);
1150 data[3] = mdio_read(ioaddr, data[0] & 0x1f, data[1] & 0x1f);
1151 EL3WINDOW(saved_window);
1152 spin_unlock_irqrestore(&lp->window_lock, flags);
1153 return 0;
1154 }
1155 case SIOCSMIIREG: /* Write the specified MII register */
1156 {
1157 int saved_window;
1158 unsigned long flags;
1159
1160 if (!capable(CAP_NET_ADMIN))
1161 return -EPERM;
1162 spin_lock_irqsave(&lp->window_lock, flags);
1163 saved_window = inw(ioaddr + EL3_CMD) >> 13;
1164 EL3WINDOW(4);
1165 mdio_write(ioaddr, data[0] & 0x1f, data[1] & 0x1f, data[2]);
1166 EL3WINDOW(saved_window);
1167 spin_unlock_irqrestore(&lp->window_lock, flags);
1168 return 0;
1169 }
1170 default:
1171 return -EOPNOTSUPP;
1172 }
1173}
1174
1175/* The Odie chip has a 64 bin multicast filter, but the bit layout is not
1176 documented. Until it is we revert to receiving all multicast frames when
1177 any multicast reception is desired.
1178 Note: My other drivers emit a log message whenever promiscuous mode is
1179 entered to help detect password sniffers. This is less desirable on
1180 typical PC card machines, so we omit the message.
1181 */
1182
1183static void set_rx_mode(struct net_device *dev)
1184{
1185 kio_addr_t ioaddr = dev->base_addr;
1186
1187 if (dev->flags & IFF_PROMISC)
1188 outw(SetRxFilter | RxStation | RxMulticast | RxBroadcast | RxProm,
1189 ioaddr + EL3_CMD);
1190 else if (dev->mc_count || (dev->flags & IFF_ALLMULTI))
1191 outw(SetRxFilter|RxStation|RxMulticast|RxBroadcast, ioaddr + EL3_CMD);
1192 else
1193 outw(SetRxFilter | RxStation | RxBroadcast, ioaddr + EL3_CMD);
1194}
1195
1196static int el3_close(struct net_device *dev)
1197{
1198 kio_addr_t ioaddr = dev->base_addr;
1199 struct el3_private *lp = netdev_priv(dev);
1200 dev_link_t *link = &lp->link;
1201
1202 DEBUG(2, "%s: shutting down ethercard.\n", dev->name);
1203
1204 if (DEV_OK(link)) {
1205 unsigned long flags;
1206
1207 /* Turn off statistics ASAP. We update lp->stats below. */
1208 outw(StatsDisable, ioaddr + EL3_CMD);
1209
1210 /* Disable the receiver and transmitter. */
1211 outw(RxDisable, ioaddr + EL3_CMD);
1212 outw(TxDisable, ioaddr + EL3_CMD);
1213
1214 /* Note: Switching to window 0 may disable the IRQ. */
1215 EL3WINDOW(0);
1216 spin_lock_irqsave(&lp->window_lock, flags);
1217 update_stats(dev);
1218 spin_unlock_irqrestore(&lp->window_lock, flags);
Daniel Ritzb9a6eaf2005-04-10 20:27:45 +02001219
1220 /* force interrupts off */
1221 outw(SetIntrEnb | 0x0000, ioaddr + EL3_CMD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 }
1223
1224 link->open--;
1225 netif_stop_queue(dev);
1226 del_timer_sync(&lp->media);
1227
1228 return 0;
1229}
1230
Dominik Brodowski270b6e92005-06-27 16:28:18 -07001231static struct pcmcia_device_id tc574_ids[] = {
1232 PCMCIA_DEVICE_MANF_CARD(0x0101, 0x0574),
1233 PCMCIA_MFC_DEVICE_CIS_MANF_CARD(0, 0x0101, 0x0556, "3CCFEM556.cis"),
1234 PCMCIA_DEVICE_NULL,
1235};
1236MODULE_DEVICE_TABLE(pcmcia, tc574_ids);
1237
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238static struct pcmcia_driver tc574_driver = {
1239 .owner = THIS_MODULE,
1240 .drv = {
1241 .name = "3c574_cs",
1242 },
Dominik Brodowskif8cfa612005-11-14 21:25:51 +01001243 .probe = tc574_attach,
Dominik Brodowskicc3b4862005-11-14 21:23:14 +01001244 .remove = tc574_detach,
Dominik Brodowski270b6e92005-06-27 16:28:18 -07001245 .id_table = tc574_ids,
Dominik Brodowski98e4c282005-11-14 21:21:18 +01001246 .suspend = tc574_suspend,
1247 .resume = tc574_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248};
1249
1250static int __init init_tc574(void)
1251{
1252 return pcmcia_register_driver(&tc574_driver);
1253}
1254
1255static void __exit exit_tc574(void)
1256{
1257 pcmcia_unregister_driver(&tc574_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258}
1259
1260module_init(init_tc574);
1261module_exit(exit_tc574);