aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/pcmcia
diff options
context:
space:
mode:
authorJonathan Herman <hermanjl@cs.unc.edu>2013-01-22 10:38:37 -0500
committerJonathan Herman <hermanjl@cs.unc.edu>2013-01-22 10:38:37 -0500
commitfcc9d2e5a6c89d22b8b773a64fb4ad21ac318446 (patch)
treea57612d1888735a2ec7972891b68c1ac5ec8faea /drivers/net/pcmcia
parent8dea78da5cee153b8af9c07a2745f6c55057fe12 (diff)
Added missing tegra files.HEADmaster
Diffstat (limited to 'drivers/net/pcmcia')
-rw-r--r--drivers/net/pcmcia/3c574_cs.c1181
-rw-r--r--drivers/net/pcmcia/3c589_cs.c943
-rw-r--r--drivers/net/pcmcia/Kconfig123
-rw-r--r--drivers/net/pcmcia/Makefile16
-rw-r--r--drivers/net/pcmcia/axnet_cs.c1725
-rw-r--r--drivers/net/pcmcia/com20020_cs.c349
-rw-r--r--drivers/net/pcmcia/fmvj18x_cs.c1187
-rw-r--r--drivers/net/pcmcia/ibmtr_cs.c371
-rw-r--r--drivers/net/pcmcia/nmclan_cs.c1525
-rw-r--r--drivers/net/pcmcia/pcnet_cs.c1710
-rw-r--r--drivers/net/pcmcia/smc91c92_cs.c2070
-rw-r--r--drivers/net/pcmcia/xirc2ps_cs.c1813
12 files changed, 13013 insertions, 0 deletions
diff --git a/drivers/net/pcmcia/3c574_cs.c b/drivers/net/pcmcia/3c574_cs.c
new file mode 100644
index 00000000000..34c5e1cbf65
--- /dev/null
+++ b/drivers/net/pcmcia/3c574_cs.c
@@ -0,0 +1,1181 @@
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/opf/DP/DP83840A.html
66
67Thanks to Terry Murphy of 3Com for providing development information for
68earlier 3Com products.
69
70*/
71
72#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
73
74#include <linux/module.h>
75#include <linux/kernel.h>
76#include <linux/init.h>
77#include <linux/slab.h>
78#include <linux/string.h>
79#include <linux/timer.h>
80#include <linux/interrupt.h>
81#include <linux/in.h>
82#include <linux/delay.h>
83#include <linux/netdevice.h>
84#include <linux/etherdevice.h>
85#include <linux/skbuff.h>
86#include <linux/if_arp.h>
87#include <linux/ioport.h>
88#include <linux/bitops.h>
89#include <linux/mii.h>
90
91#include <pcmcia/cistpl.h>
92#include <pcmcia/cisreg.h>
93#include <pcmcia/ciscode.h>
94#include <pcmcia/ds.h>
95
96#include <asm/uaccess.h>
97#include <asm/io.h>
98#include <asm/system.h>
99
100/*====================================================================*/
101
102/* Module parameters */
103
104MODULE_AUTHOR("David Hinds <dahinds@users.sourceforge.net>");
105MODULE_DESCRIPTION("3Com 3c574 series PCMCIA ethernet driver");
106MODULE_LICENSE("GPL");
107
108#define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0)
109
110/* Maximum events (Rx packets, etc.) to handle at each interrupt. */
111INT_MODULE_PARM(max_interrupt_work, 32);
112
113/* Force full duplex modes? */
114INT_MODULE_PARM(full_duplex, 0);
115
116/* Autodetect link polarity reversal? */
117INT_MODULE_PARM(auto_polarity, 1);
118
119
120/*====================================================================*/
121
122/* Time in jiffies before concluding the transmitter is hung. */
123#define TX_TIMEOUT ((800*HZ)/1000)
124
125/* To minimize the size of the driver source and make the driver more
126 readable not all constants are symbolically defined.
127 You'll need the manual if you want to understand driver details anyway. */
128/* Offsets from base I/O address. */
129#define EL3_DATA 0x00
130#define EL3_CMD 0x0e
131#define EL3_STATUS 0x0e
132
133#define EL3WINDOW(win_num) outw(SelectWindow + (win_num), ioaddr + EL3_CMD)
134
135/* The top five bits written to EL3_CMD are a command, the lower
136 11 bits are the parameter, if applicable. */
137enum el3_cmds {
138 TotalReset = 0<<11, SelectWindow = 1<<11, StartCoax = 2<<11,
139 RxDisable = 3<<11, RxEnable = 4<<11, RxReset = 5<<11, RxDiscard = 8<<11,
140 TxEnable = 9<<11, TxDisable = 10<<11, TxReset = 11<<11,
141 FakeIntr = 12<<11, AckIntr = 13<<11, SetIntrEnb = 14<<11,
142 SetStatusEnb = 15<<11, SetRxFilter = 16<<11, SetRxThreshold = 17<<11,
143 SetTxThreshold = 18<<11, SetTxStart = 19<<11, StatsEnable = 21<<11,
144 StatsDisable = 22<<11, StopCoax = 23<<11,
145};
146
147enum elxl_status {
148 IntLatch = 0x0001, AdapterFailure = 0x0002, TxComplete = 0x0004,
149 TxAvailable = 0x0008, RxComplete = 0x0010, RxEarly = 0x0020,
150 IntReq = 0x0040, StatsFull = 0x0080, CmdBusy = 0x1000 };
151
152/* The SetRxFilter command accepts the following classes: */
153enum RxFilter {
154 RxStation = 1, RxMulticast = 2, RxBroadcast = 4, RxProm = 8
155};
156
157enum Window0 {
158 Wn0EepromCmd = 10, Wn0EepromData = 12, /* EEPROM command/address, data. */
159 IntrStatus=0x0E, /* Valid in all windows. */
160};
161/* These assumes the larger EEPROM. */
162enum Win0_EEPROM_cmds {
163 EEPROM_Read = 0x200, EEPROM_WRITE = 0x100, EEPROM_ERASE = 0x300,
164 EEPROM_EWENB = 0x30, /* Enable erasing/writing for 10 msec. */
165 EEPROM_EWDIS = 0x00, /* Disable EWENB before 10 msec timeout. */
166};
167
168/* Register window 1 offsets, the window used in normal operation.
169 On the "Odie" this window is always mapped at offsets 0x10-0x1f.
170 Except for TxFree, which is overlapped by RunnerWrCtrl. */
171enum Window1 {
172 TX_FIFO = 0x10, RX_FIFO = 0x10, RxErrors = 0x14,
173 RxStatus = 0x18, Timer=0x1A, TxStatus = 0x1B,
174 TxFree = 0x0C, /* Remaining free bytes in Tx buffer. */
175 RunnerRdCtrl = 0x16, RunnerWrCtrl = 0x1c,
176};
177
178enum Window3 { /* Window 3: MAC/config bits. */
179 Wn3_Config=0, Wn3_MAC_Ctrl=6, Wn3_Options=8,
180};
181enum wn3_config {
182 Ram_size = 7,
183 Ram_width = 8,
184 Ram_speed = 0x30,
185 Rom_size = 0xc0,
186 Ram_split_shift = 16,
187 Ram_split = 3 << Ram_split_shift,
188 Xcvr_shift = 20,
189 Xcvr = 7 << Xcvr_shift,
190 Autoselect = 0x1000000,
191};
192
193enum Window4 { /* Window 4: Xcvr/media bits. */
194 Wn4_FIFODiag = 4, Wn4_NetDiag = 6, Wn4_PhysicalMgmt=8, Wn4_Media = 10,
195};
196
197#define MEDIA_TP 0x00C0 /* Enable link beat and jabber for 10baseT. */
198
199struct el3_private {
200 struct pcmcia_device *p_dev;
201 u16 advertising, partner; /* NWay media advertisement */
202 unsigned char phys; /* MII device address */
203 unsigned int autoselect:1, default_media:3; /* Read from the EEPROM/Wn3_Config. */
204 /* for transceiver monitoring */
205 struct timer_list media;
206 unsigned short media_status;
207 unsigned short fast_poll;
208 unsigned long last_irq;
209 spinlock_t window_lock; /* Guards the Window selection */
210};
211
212/* Set iff a MII transceiver on any interface requires mdio preamble.
213 This only set with the original DP83840 on older 3c905 boards, so the extra
214 code size of a per-interface flag is not worthwhile. */
215static char mii_preamble_required = 0;
216
217/* Index of functions. */
218
219static int tc574_config(struct pcmcia_device *link);
220static void tc574_release(struct pcmcia_device *link);
221
222static void mdio_sync(unsigned int ioaddr, int bits);
223static int mdio_read(unsigned int ioaddr, int phy_id, int location);
224static void mdio_write(unsigned int ioaddr, int phy_id, int location,
225 int value);
226static unsigned short read_eeprom(unsigned int ioaddr, int index);
227static void tc574_wait_for_completion(struct net_device *dev, int cmd);
228
229static void tc574_reset(struct net_device *dev);
230static void media_check(unsigned long arg);
231static int el3_open(struct net_device *dev);
232static netdev_tx_t el3_start_xmit(struct sk_buff *skb,
233 struct net_device *dev);
234static irqreturn_t el3_interrupt(int irq, void *dev_id);
235static void update_stats(struct net_device *dev);
236static struct net_device_stats *el3_get_stats(struct net_device *dev);
237static int el3_rx(struct net_device *dev, int worklimit);
238static int el3_close(struct net_device *dev);
239static void el3_tx_timeout(struct net_device *dev);
240static int el3_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
241static void set_rx_mode(struct net_device *dev);
242static void set_multicast_list(struct net_device *dev);
243
244static void tc574_detach(struct pcmcia_device *p_dev);
245
246/*
247 tc574_attach() creates an "instance" of the driver, allocating
248 local data structures for one device. The device is registered
249 with Card Services.
250*/
251static const struct net_device_ops el3_netdev_ops = {
252 .ndo_open = el3_open,
253 .ndo_stop = el3_close,
254 .ndo_start_xmit = el3_start_xmit,
255 .ndo_tx_timeout = el3_tx_timeout,
256 .ndo_get_stats = el3_get_stats,
257 .ndo_do_ioctl = el3_ioctl,
258 .ndo_set_multicast_list = set_multicast_list,
259 .ndo_change_mtu = eth_change_mtu,
260 .ndo_set_mac_address = eth_mac_addr,
261 .ndo_validate_addr = eth_validate_addr,
262};
263
264static int tc574_probe(struct pcmcia_device *link)
265{
266 struct el3_private *lp;
267 struct net_device *dev;
268
269 dev_dbg(&link->dev, "3c574_attach()\n");
270
271 /* Create the PC card device object. */
272 dev = alloc_etherdev(sizeof(struct el3_private));
273 if (!dev)
274 return -ENOMEM;
275 lp = netdev_priv(dev);
276 link->priv = dev;
277 lp->p_dev = link;
278
279 spin_lock_init(&lp->window_lock);
280 link->resource[0]->end = 32;
281 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_16;
282 link->config_flags |= CONF_ENABLE_IRQ;
283 link->config_index = 1;
284
285 dev->netdev_ops = &el3_netdev_ops;
286 dev->watchdog_timeo = TX_TIMEOUT;
287
288 return tc574_config(link);
289}
290
291static void tc574_detach(struct pcmcia_device *link)
292{
293 struct net_device *dev = link->priv;
294
295 dev_dbg(&link->dev, "3c574_detach()\n");
296
297 unregister_netdev(dev);
298
299 tc574_release(link);
300
301 free_netdev(dev);
302} /* tc574_detach */
303
304static const char *ram_split[] = {"5:3", "3:1", "1:1", "3:5"};
305
306static int tc574_config(struct pcmcia_device *link)
307{
308 struct net_device *dev = link->priv;
309 struct el3_private *lp = netdev_priv(dev);
310 int ret, i, j;
311 unsigned int ioaddr;
312 __be16 *phys_addr;
313 char *cardname;
314 __u32 config;
315 u8 *buf;
316 size_t len;
317
318 phys_addr = (__be16 *)dev->dev_addr;
319
320 dev_dbg(&link->dev, "3c574_config()\n");
321
322 link->io_lines = 16;
323
324 for (i = j = 0; j < 0x400; j += 0x20) {
325 link->resource[0]->start = j ^ 0x300;
326 i = pcmcia_request_io(link);
327 if (i == 0)
328 break;
329 }
330 if (i != 0)
331 goto failed;
332
333 ret = pcmcia_request_irq(link, el3_interrupt);
334 if (ret)
335 goto failed;
336
337 ret = pcmcia_enable_device(link);
338 if (ret)
339 goto failed;
340
341 dev->irq = link->irq;
342 dev->base_addr = link->resource[0]->start;
343
344 ioaddr = dev->base_addr;
345
346 /* The 3c574 normally uses an EEPROM for configuration info, including
347 the hardware address. The future products may include a modem chip
348 and put the address in the CIS. */
349
350 len = pcmcia_get_tuple(link, 0x88, &buf);
351 if (buf && len >= 6) {
352 for (i = 0; i < 3; i++)
353 phys_addr[i] = htons(le16_to_cpu(buf[i * 2]));
354 kfree(buf);
355 } else {
356 kfree(buf); /* 0 < len < 6 */
357 EL3WINDOW(0);
358 for (i = 0; i < 3; i++)
359 phys_addr[i] = htons(read_eeprom(ioaddr, i + 10));
360 if (phys_addr[0] == htons(0x6060)) {
361 pr_notice("IO port conflict at 0x%03lx-0x%03lx\n",
362 dev->base_addr, dev->base_addr+15);
363 goto failed;
364 }
365 }
366 if (link->prod_id[1])
367 cardname = link->prod_id[1];
368 else
369 cardname = "3Com 3c574";
370
371 {
372 u_char mcr;
373 outw(2<<11, ioaddr + RunnerRdCtrl);
374 mcr = inb(ioaddr + 2);
375 outw(0<<11, ioaddr + RunnerRdCtrl);
376 pr_info(" ASIC rev %d,", mcr>>3);
377 EL3WINDOW(3);
378 config = inl(ioaddr + Wn3_Config);
379 lp->default_media = (config & Xcvr) >> Xcvr_shift;
380 lp->autoselect = config & Autoselect ? 1 : 0;
381 }
382
383 init_timer(&lp->media);
384
385 {
386 int phy;
387
388 /* Roadrunner only: Turn on the MII transceiver */
389 outw(0x8040, ioaddr + Wn3_Options);
390 mdelay(1);
391 outw(0xc040, ioaddr + Wn3_Options);
392 tc574_wait_for_completion(dev, TxReset);
393 tc574_wait_for_completion(dev, RxReset);
394 mdelay(1);
395 outw(0x8040, ioaddr + Wn3_Options);
396
397 EL3WINDOW(4);
398 for (phy = 1; phy <= 32; phy++) {
399 int mii_status;
400 mdio_sync(ioaddr, 32);
401 mii_status = mdio_read(ioaddr, phy & 0x1f, 1);
402 if (mii_status != 0xffff) {
403 lp->phys = phy & 0x1f;
404 dev_dbg(&link->dev, " MII transceiver at "
405 "index %d, status %x.\n",
406 phy, mii_status);
407 if ((mii_status & 0x0040) == 0)
408 mii_preamble_required = 1;
409 break;
410 }
411 }
412 if (phy > 32) {
413 pr_notice(" No MII transceivers found!\n");
414 goto failed;
415 }
416 i = mdio_read(ioaddr, lp->phys, 16) | 0x40;
417 mdio_write(ioaddr, lp->phys, 16, i);
418 lp->advertising = mdio_read(ioaddr, lp->phys, 4);
419 if (full_duplex) {
420 /* Only advertise the FD media types. */
421 lp->advertising &= ~0x02a0;
422 mdio_write(ioaddr, lp->phys, 4, lp->advertising);
423 }
424 }
425
426 SET_NETDEV_DEV(dev, &link->dev);
427
428 if (register_netdev(dev) != 0) {
429 pr_notice("register_netdev() failed\n");
430 goto failed;
431 }
432
433 netdev_info(dev, "%s at io %#3lx, irq %d, hw_addr %pM\n",
434 cardname, dev->base_addr, dev->irq, dev->dev_addr);
435 netdev_info(dev, " %dK FIFO split %s Rx:Tx, %sMII interface.\n",
436 8 << config & Ram_size,
437 ram_split[(config & Ram_split) >> Ram_split_shift],
438 config & Autoselect ? "autoselect " : "");
439
440 return 0;
441
442failed:
443 tc574_release(link);
444 return -ENODEV;
445
446} /* tc574_config */
447
448static void tc574_release(struct pcmcia_device *link)
449{
450 pcmcia_disable_device(link);
451}
452
453static int tc574_suspend(struct pcmcia_device *link)
454{
455 struct net_device *dev = link->priv;
456
457 if (link->open)
458 netif_device_detach(dev);
459
460 return 0;
461}
462
463static int tc574_resume(struct pcmcia_device *link)
464{
465 struct net_device *dev = link->priv;
466
467 if (link->open) {
468 tc574_reset(dev);
469 netif_device_attach(dev);
470 }
471
472 return 0;
473}
474
475static void dump_status(struct net_device *dev)
476{
477 unsigned int ioaddr = dev->base_addr;
478 EL3WINDOW(1);
479 netdev_info(dev, " irq status %04x, rx status %04x, tx status %02x, tx free %04x\n",
480 inw(ioaddr+EL3_STATUS),
481 inw(ioaddr+RxStatus), inb(ioaddr+TxStatus),
482 inw(ioaddr+TxFree));
483 EL3WINDOW(4);
484 netdev_info(dev, " diagnostics: fifo %04x net %04x ethernet %04x media %04x\n",
485 inw(ioaddr+0x04), inw(ioaddr+0x06),
486 inw(ioaddr+0x08), inw(ioaddr+0x0a));
487 EL3WINDOW(1);
488}
489
490/*
491 Use this for commands that may take time to finish
492*/
493static void tc574_wait_for_completion(struct net_device *dev, int cmd)
494{
495 int i = 1500;
496 outw(cmd, dev->base_addr + EL3_CMD);
497 while (--i > 0)
498 if (!(inw(dev->base_addr + EL3_STATUS) & 0x1000)) break;
499 if (i == 0)
500 netdev_notice(dev, "command 0x%04x did not complete!\n", cmd);
501}
502
503/* Read a word from the EEPROM using the regular EEPROM access register.
504 Assume that we are in register window zero.
505 */
506static unsigned short read_eeprom(unsigned int ioaddr, int index)
507{
508 int timer;
509 outw(EEPROM_Read + index, ioaddr + Wn0EepromCmd);
510 /* Pause for at least 162 usec for the read to take place. */
511 for (timer = 1620; timer >= 0; timer--) {
512 if ((inw(ioaddr + Wn0EepromCmd) & 0x8000) == 0)
513 break;
514 }
515 return inw(ioaddr + Wn0EepromData);
516}
517
518/* MII transceiver control section.
519 Read and write the MII registers using software-generated serial
520 MDIO protocol. See the MII specifications or DP83840A data sheet
521 for details.
522 The maxium data clock rate is 2.5 Mhz. The timing is easily met by the
523 slow PC card interface. */
524
525#define MDIO_SHIFT_CLK 0x01
526#define MDIO_DIR_WRITE 0x04
527#define MDIO_DATA_WRITE0 (0x00 | MDIO_DIR_WRITE)
528#define MDIO_DATA_WRITE1 (0x02 | MDIO_DIR_WRITE)
529#define MDIO_DATA_READ 0x02
530#define MDIO_ENB_IN 0x00
531
532/* Generate the preamble required for initial synchronization and
533 a few older transceivers. */
534static void mdio_sync(unsigned int ioaddr, int bits)
535{
536 unsigned int mdio_addr = ioaddr + Wn4_PhysicalMgmt;
537
538 /* Establish sync by sending at least 32 logic ones. */
539 while (-- bits >= 0) {
540 outw(MDIO_DATA_WRITE1, mdio_addr);
541 outw(MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, mdio_addr);
542 }
543}
544
545static int mdio_read(unsigned int ioaddr, int phy_id, int location)
546{
547 int i;
548 int read_cmd = (0xf6 << 10) | (phy_id << 5) | location;
549 unsigned int retval = 0;
550 unsigned int mdio_addr = ioaddr + Wn4_PhysicalMgmt;
551
552 if (mii_preamble_required)
553 mdio_sync(ioaddr, 32);
554
555 /* Shift the read command bits out. */
556 for (i = 14; i >= 0; i--) {
557 int dataval = (read_cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
558 outw(dataval, mdio_addr);
559 outw(dataval | MDIO_SHIFT_CLK, mdio_addr);
560 }
561 /* Read the two transition, 16 data, and wire-idle bits. */
562 for (i = 19; i > 0; i--) {
563 outw(MDIO_ENB_IN, mdio_addr);
564 retval = (retval << 1) | ((inw(mdio_addr) & MDIO_DATA_READ) ? 1 : 0);
565 outw(MDIO_ENB_IN | MDIO_SHIFT_CLK, mdio_addr);
566 }
567 return (retval>>1) & 0xffff;
568}
569
570static void mdio_write(unsigned int ioaddr, int phy_id, int location, int value)
571{
572 int write_cmd = 0x50020000 | (phy_id << 23) | (location << 18) | value;
573 unsigned int mdio_addr = ioaddr + Wn4_PhysicalMgmt;
574 int i;
575
576 if (mii_preamble_required)
577 mdio_sync(ioaddr, 32);
578
579 /* Shift the command bits out. */
580 for (i = 31; i >= 0; i--) {
581 int dataval = (write_cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
582 outw(dataval, mdio_addr);
583 outw(dataval | MDIO_SHIFT_CLK, mdio_addr);
584 }
585 /* Leave the interface idle. */
586 for (i = 1; i >= 0; i--) {
587 outw(MDIO_ENB_IN, mdio_addr);
588 outw(MDIO_ENB_IN | MDIO_SHIFT_CLK, mdio_addr);
589 }
590}
591
592/* Reset and restore all of the 3c574 registers. */
593static void tc574_reset(struct net_device *dev)
594{
595 struct el3_private *lp = netdev_priv(dev);
596 int i;
597 unsigned int ioaddr = dev->base_addr;
598 unsigned long flags;
599
600 tc574_wait_for_completion(dev, TotalReset|0x10);
601
602 spin_lock_irqsave(&lp->window_lock, flags);
603 /* Clear any transactions in progress. */
604 outw(0, ioaddr + RunnerWrCtrl);
605 outw(0, ioaddr + RunnerRdCtrl);
606
607 /* Set the station address and mask. */
608 EL3WINDOW(2);
609 for (i = 0; i < 6; i++)
610 outb(dev->dev_addr[i], ioaddr + i);
611 for (; i < 12; i+=2)
612 outw(0, ioaddr + i);
613
614 /* Reset config options */
615 EL3WINDOW(3);
616 outb((dev->mtu > 1500 ? 0x40 : 0), ioaddr + Wn3_MAC_Ctrl);
617 outl((lp->autoselect ? 0x01000000 : 0) | 0x0062001b,
618 ioaddr + Wn3_Config);
619 /* Roadrunner only: Turn on the MII transceiver. */
620 outw(0x8040, ioaddr + Wn3_Options);
621 mdelay(1);
622 outw(0xc040, ioaddr + Wn3_Options);
623 EL3WINDOW(1);
624 spin_unlock_irqrestore(&lp->window_lock, flags);
625
626 tc574_wait_for_completion(dev, TxReset);
627 tc574_wait_for_completion(dev, RxReset);
628 mdelay(1);
629 spin_lock_irqsave(&lp->window_lock, flags);
630 EL3WINDOW(3);
631 outw(0x8040, ioaddr + Wn3_Options);
632
633 /* Switch to the stats window, and clear all stats by reading. */
634 outw(StatsDisable, ioaddr + EL3_CMD);
635 EL3WINDOW(6);
636 for (i = 0; i < 10; i++)
637 inb(ioaddr + i);
638 inw(ioaddr + 10);
639 inw(ioaddr + 12);
640 EL3WINDOW(4);
641 inb(ioaddr + 12);
642 inb(ioaddr + 13);
643
644 /* .. enable any extra statistics bits.. */
645 outw(0x0040, ioaddr + Wn4_NetDiag);
646
647 EL3WINDOW(1);
648 spin_unlock_irqrestore(&lp->window_lock, flags);
649
650 /* .. re-sync MII and re-fill what NWay is advertising. */
651 mdio_sync(ioaddr, 32);
652 mdio_write(ioaddr, lp->phys, 4, lp->advertising);
653 if (!auto_polarity) {
654 /* works for TDK 78Q2120 series MII's */
655 i = mdio_read(ioaddr, lp->phys, 16) | 0x20;
656 mdio_write(ioaddr, lp->phys, 16, i);
657 }
658
659 spin_lock_irqsave(&lp->window_lock, flags);
660 /* Switch to register set 1 for normal use, just for TxFree. */
661 set_rx_mode(dev);
662 spin_unlock_irqrestore(&lp->window_lock, flags);
663 outw(StatsEnable, ioaddr + EL3_CMD); /* Turn on statistics. */
664 outw(RxEnable, ioaddr + EL3_CMD); /* Enable the receiver. */
665 outw(TxEnable, ioaddr + EL3_CMD); /* Enable transmitter. */
666 /* Allow status bits to be seen. */
667 outw(SetStatusEnb | 0xff, ioaddr + EL3_CMD);
668 /* Ack all pending events, and set active indicator mask. */
669 outw(AckIntr | IntLatch | TxAvailable | RxEarly | IntReq,
670 ioaddr + EL3_CMD);
671 outw(SetIntrEnb | IntLatch | TxAvailable | RxComplete | StatsFull
672 | AdapterFailure | RxEarly, ioaddr + EL3_CMD);
673}
674
675static int el3_open(struct net_device *dev)
676{
677 struct el3_private *lp = netdev_priv(dev);
678 struct pcmcia_device *link = lp->p_dev;
679
680 if (!pcmcia_dev_present(link))
681 return -ENODEV;
682
683 link->open++;
684 netif_start_queue(dev);
685
686 tc574_reset(dev);
687 lp->media.function = media_check;
688 lp->media.data = (unsigned long) dev;
689 lp->media.expires = jiffies + HZ;
690 add_timer(&lp->media);
691
692 dev_dbg(&link->dev, "%s: opened, status %4.4x.\n",
693 dev->name, inw(dev->base_addr + EL3_STATUS));
694
695 return 0;
696}
697
698static void el3_tx_timeout(struct net_device *dev)
699{
700 unsigned int ioaddr = dev->base_addr;
701
702 netdev_notice(dev, "Transmit timed out!\n");
703 dump_status(dev);
704 dev->stats.tx_errors++;
705 dev->trans_start = jiffies; /* prevent tx timeout */
706 /* Issue TX_RESET and TX_START commands. */
707 tc574_wait_for_completion(dev, TxReset);
708 outw(TxEnable, ioaddr + EL3_CMD);
709 netif_wake_queue(dev);
710}
711
712static void pop_tx_status(struct net_device *dev)
713{
714 unsigned int ioaddr = dev->base_addr;
715 int i;
716
717 /* Clear the Tx status stack. */
718 for (i = 32; i > 0; i--) {
719 u_char tx_status = inb(ioaddr + TxStatus);
720 if (!(tx_status & 0x84))
721 break;
722 /* reset transmitter on jabber error or underrun */
723 if (tx_status & 0x30)
724 tc574_wait_for_completion(dev, TxReset);
725 if (tx_status & 0x38) {
726 pr_debug("%s: transmit error: status 0x%02x\n",
727 dev->name, tx_status);
728 outw(TxEnable, ioaddr + EL3_CMD);
729 dev->stats.tx_aborted_errors++;
730 }
731 outb(0x00, ioaddr + TxStatus); /* Pop the status stack. */
732 }
733}
734
735static netdev_tx_t el3_start_xmit(struct sk_buff *skb,
736 struct net_device *dev)
737{
738 unsigned int ioaddr = dev->base_addr;
739 struct el3_private *lp = netdev_priv(dev);
740 unsigned long flags;
741
742 pr_debug("%s: el3_start_xmit(length = %ld) called, "
743 "status %4.4x.\n", dev->name, (long)skb->len,
744 inw(ioaddr + EL3_STATUS));
745
746 spin_lock_irqsave(&lp->window_lock, flags);
747
748 dev->stats.tx_bytes += skb->len;
749
750 /* Put out the doubleword header... */
751 outw(skb->len, ioaddr + TX_FIFO);
752 outw(0, ioaddr + TX_FIFO);
753 /* ... and the packet rounded to a doubleword. */
754 outsl(ioaddr + TX_FIFO, skb->data, (skb->len+3)>>2);
755
756 /* TxFree appears only in Window 1, not offset 0x1c. */
757 if (inw(ioaddr + TxFree) <= 1536) {
758 netif_stop_queue(dev);
759 /* Interrupt us when the FIFO has room for max-sized packet.
760 The threshold is in units of dwords. */
761 outw(SetTxThreshold + (1536>>2), ioaddr + EL3_CMD);
762 }
763
764 pop_tx_status(dev);
765 spin_unlock_irqrestore(&lp->window_lock, flags);
766 dev_kfree_skb(skb);
767 return NETDEV_TX_OK;
768}
769
770/* The EL3 interrupt handler. */
771static irqreturn_t el3_interrupt(int irq, void *dev_id)
772{
773 struct net_device *dev = (struct net_device *) dev_id;
774 struct el3_private *lp = netdev_priv(dev);
775 unsigned int ioaddr;
776 unsigned status;
777 int work_budget = max_interrupt_work;
778 int handled = 0;
779
780 if (!netif_device_present(dev))
781 return IRQ_NONE;
782 ioaddr = dev->base_addr;
783
784 pr_debug("%s: interrupt, status %4.4x.\n",
785 dev->name, inw(ioaddr + EL3_STATUS));
786
787 spin_lock(&lp->window_lock);
788
789 while ((status = inw(ioaddr + EL3_STATUS)) &
790 (IntLatch | RxComplete | RxEarly | StatsFull)) {
791 if (!netif_device_present(dev) ||
792 ((status & 0xe000) != 0x2000)) {
793 pr_debug("%s: Interrupt from dead card\n", dev->name);
794 break;
795 }
796
797 handled = 1;
798
799 if (status & RxComplete)
800 work_budget = el3_rx(dev, work_budget);
801
802 if (status & TxAvailable) {
803 pr_debug(" TX room bit was handled.\n");
804 /* There's room in the FIFO for a full-sized packet. */
805 outw(AckIntr | TxAvailable, ioaddr + EL3_CMD);
806 netif_wake_queue(dev);
807 }
808
809 if (status & TxComplete)
810 pop_tx_status(dev);
811
812 if (status & (AdapterFailure | RxEarly | StatsFull)) {
813 /* Handle all uncommon interrupts. */
814 if (status & StatsFull)
815 update_stats(dev);
816 if (status & RxEarly) {
817 work_budget = el3_rx(dev, work_budget);
818 outw(AckIntr | RxEarly, ioaddr + EL3_CMD);
819 }
820 if (status & AdapterFailure) {
821 u16 fifo_diag;
822 EL3WINDOW(4);
823 fifo_diag = inw(ioaddr + Wn4_FIFODiag);
824 EL3WINDOW(1);
825 netdev_notice(dev, "adapter failure, FIFO diagnostic register %04x\n",
826 fifo_diag);
827 if (fifo_diag & 0x0400) {
828 /* Tx overrun */
829 tc574_wait_for_completion(dev, TxReset);
830 outw(TxEnable, ioaddr + EL3_CMD);
831 }
832 if (fifo_diag & 0x2000) {
833 /* Rx underrun */
834 tc574_wait_for_completion(dev, RxReset);
835 set_rx_mode(dev);
836 outw(RxEnable, ioaddr + EL3_CMD);
837 }
838 outw(AckIntr | AdapterFailure, ioaddr + EL3_CMD);
839 }
840 }
841
842 if (--work_budget < 0) {
843 pr_debug("%s: Too much work in interrupt, "
844 "status %4.4x.\n", dev->name, status);
845 /* Clear all interrupts */
846 outw(AckIntr | 0xFF, ioaddr + EL3_CMD);
847 break;
848 }
849 /* Acknowledge the IRQ. */
850 outw(AckIntr | IntReq | IntLatch, ioaddr + EL3_CMD);
851 }
852
853 pr_debug("%s: exiting interrupt, status %4.4x.\n",
854 dev->name, inw(ioaddr + EL3_STATUS));
855
856 spin_unlock(&lp->window_lock);
857 return IRQ_RETVAL(handled);
858}
859
860/*
861 This timer serves two purposes: to check for missed interrupts
862 (and as a last resort, poll the NIC for events), and to monitor
863 the MII, reporting changes in cable status.
864*/
865static void media_check(unsigned long arg)
866{
867 struct net_device *dev = (struct net_device *) arg;
868 struct el3_private *lp = netdev_priv(dev);
869 unsigned int ioaddr = dev->base_addr;
870 unsigned long flags;
871 unsigned short /* cable, */ media, partner;
872
873 if (!netif_device_present(dev))
874 goto reschedule;
875
876 /* Check for pending interrupt with expired latency timer: with
877 this, we can limp along even if the interrupt is blocked */
878 if ((inw(ioaddr + EL3_STATUS) & IntLatch) && (inb(ioaddr + Timer) == 0xff)) {
879 if (!lp->fast_poll)
880 netdev_info(dev, "interrupt(s) dropped!\n");
881
882 local_irq_save(flags);
883 el3_interrupt(dev->irq, dev);
884 local_irq_restore(flags);
885
886 lp->fast_poll = HZ;
887 }
888 if (lp->fast_poll) {
889 lp->fast_poll--;
890 lp->media.expires = jiffies + 2*HZ/100;
891 add_timer(&lp->media);
892 return;
893 }
894
895 spin_lock_irqsave(&lp->window_lock, flags);
896 EL3WINDOW(4);
897 media = mdio_read(ioaddr, lp->phys, 1);
898 partner = mdio_read(ioaddr, lp->phys, 5);
899 EL3WINDOW(1);
900
901 if (media != lp->media_status) {
902 if ((media ^ lp->media_status) & 0x0004)
903 netdev_info(dev, "%s link beat\n",
904 (lp->media_status & 0x0004) ? "lost" : "found");
905 if ((media ^ lp->media_status) & 0x0020) {
906 lp->partner = 0;
907 if (lp->media_status & 0x0020) {
908 netdev_info(dev, "autonegotiation restarted\n");
909 } else if (partner) {
910 partner &= lp->advertising;
911 lp->partner = partner;
912 netdev_info(dev, "autonegotiation complete: "
913 "%dbaseT-%cD selected\n",
914 (partner & 0x0180) ? 100 : 10,
915 (partner & 0x0140) ? 'F' : 'H');
916 } else {
917 netdev_info(dev, "link partner did not autonegotiate\n");
918 }
919
920 EL3WINDOW(3);
921 outb((partner & 0x0140 ? 0x20 : 0) |
922 (dev->mtu > 1500 ? 0x40 : 0), ioaddr + Wn3_MAC_Ctrl);
923 EL3WINDOW(1);
924
925 }
926 if (media & 0x0010)
927 netdev_info(dev, "remote fault detected\n");
928 if (media & 0x0002)
929 netdev_info(dev, "jabber detected\n");
930 lp->media_status = media;
931 }
932 spin_unlock_irqrestore(&lp->window_lock, flags);
933
934reschedule:
935 lp->media.expires = jiffies + HZ;
936 add_timer(&lp->media);
937}
938
939static struct net_device_stats *el3_get_stats(struct net_device *dev)
940{
941 struct el3_private *lp = netdev_priv(dev);
942
943 if (netif_device_present(dev)) {
944 unsigned long flags;
945 spin_lock_irqsave(&lp->window_lock, flags);
946 update_stats(dev);
947 spin_unlock_irqrestore(&lp->window_lock, flags);
948 }
949 return &dev->stats;
950}
951
952/* Update statistics.
953 Surprisingly this need not be run single-threaded, but it effectively is.
954 The counters clear when read, so the adds must merely be atomic.
955 */
956static void update_stats(struct net_device *dev)
957{
958 unsigned int ioaddr = dev->base_addr;
959 u8 rx, tx, up;
960
961 pr_debug("%s: updating the statistics.\n", dev->name);
962
963 if (inw(ioaddr+EL3_STATUS) == 0xffff) /* No card. */
964 return;
965
966 /* Unlike the 3c509 we need not turn off stats updates while reading. */
967 /* Switch to the stats window, and read everything. */
968 EL3WINDOW(6);
969 dev->stats.tx_carrier_errors += inb(ioaddr + 0);
970 dev->stats.tx_heartbeat_errors += inb(ioaddr + 1);
971 /* Multiple collisions. */ inb(ioaddr + 2);
972 dev->stats.collisions += inb(ioaddr + 3);
973 dev->stats.tx_window_errors += inb(ioaddr + 4);
974 dev->stats.rx_fifo_errors += inb(ioaddr + 5);
975 dev->stats.tx_packets += inb(ioaddr + 6);
976 up = inb(ioaddr + 9);
977 dev->stats.tx_packets += (up&0x30) << 4;
978 /* Rx packets */ inb(ioaddr + 7);
979 /* Tx deferrals */ inb(ioaddr + 8);
980 rx = inw(ioaddr + 10);
981 tx = inw(ioaddr + 12);
982
983 EL3WINDOW(4);
984 /* BadSSD */ inb(ioaddr + 12);
985 up = inb(ioaddr + 13);
986
987 EL3WINDOW(1);
988}
989
990static int el3_rx(struct net_device *dev, int worklimit)
991{
992 unsigned int ioaddr = dev->base_addr;
993 short rx_status;
994
995 pr_debug("%s: in rx_packet(), status %4.4x, rx_status %4.4x.\n",
996 dev->name, inw(ioaddr+EL3_STATUS), inw(ioaddr+RxStatus));
997 while (!((rx_status = inw(ioaddr + RxStatus)) & 0x8000) &&
998 worklimit > 0) {
999 worklimit--;
1000 if (rx_status & 0x4000) { /* Error, update stats. */
1001 short error = rx_status & 0x3800;
1002 dev->stats.rx_errors++;
1003 switch (error) {
1004 case 0x0000: dev->stats.rx_over_errors++; break;
1005 case 0x0800: dev->stats.rx_length_errors++; break;
1006 case 0x1000: dev->stats.rx_frame_errors++; break;
1007 case 0x1800: dev->stats.rx_length_errors++; break;
1008 case 0x2000: dev->stats.rx_frame_errors++; break;
1009 case 0x2800: dev->stats.rx_crc_errors++; break;
1010 }
1011 } else {
1012 short pkt_len = rx_status & 0x7ff;
1013 struct sk_buff *skb;
1014
1015 skb = dev_alloc_skb(pkt_len+5);
1016
1017 pr_debug(" Receiving packet size %d status %4.4x.\n",
1018 pkt_len, rx_status);
1019 if (skb != NULL) {
1020 skb_reserve(skb, 2);
1021 insl(ioaddr+RX_FIFO, skb_put(skb, pkt_len),
1022 ((pkt_len+3)>>2));
1023 skb->protocol = eth_type_trans(skb, dev);
1024 netif_rx(skb);
1025 dev->stats.rx_packets++;
1026 dev->stats.rx_bytes += pkt_len;
1027 } else {
1028 pr_debug("%s: couldn't allocate a sk_buff of"
1029 " size %d.\n", dev->name, pkt_len);
1030 dev->stats.rx_dropped++;
1031 }
1032 }
1033 tc574_wait_for_completion(dev, RxDiscard);
1034 }
1035
1036 return worklimit;
1037}
1038
1039/* Provide ioctl() calls to examine the MII xcvr state. */
1040static int el3_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1041{
1042 struct el3_private *lp = netdev_priv(dev);
1043 unsigned int ioaddr = dev->base_addr;
1044 struct mii_ioctl_data *data = if_mii(rq);
1045 int phy = lp->phys & 0x1f;
1046
1047 pr_debug("%s: In ioct(%-.6s, %#4.4x) %4.4x %4.4x %4.4x %4.4x.\n",
1048 dev->name, rq->ifr_ifrn.ifrn_name, cmd,
1049 data->phy_id, data->reg_num, data->val_in, data->val_out);
1050
1051 switch(cmd) {
1052 case SIOCGMIIPHY: /* Get the address of the PHY in use. */
1053 data->phy_id = phy;
1054 case SIOCGMIIREG: /* Read the specified MII register. */
1055 {
1056 int saved_window;
1057 unsigned long flags;
1058
1059 spin_lock_irqsave(&lp->window_lock, flags);
1060 saved_window = inw(ioaddr + EL3_CMD) >> 13;
1061 EL3WINDOW(4);
1062 data->val_out = mdio_read(ioaddr, data->phy_id & 0x1f,
1063 data->reg_num & 0x1f);
1064 EL3WINDOW(saved_window);
1065 spin_unlock_irqrestore(&lp->window_lock, flags);
1066 return 0;
1067 }
1068 case SIOCSMIIREG: /* Write the specified MII register */
1069 {
1070 int saved_window;
1071 unsigned long flags;
1072
1073 spin_lock_irqsave(&lp->window_lock, flags);
1074 saved_window = inw(ioaddr + EL3_CMD) >> 13;
1075 EL3WINDOW(4);
1076 mdio_write(ioaddr, data->phy_id & 0x1f,
1077 data->reg_num & 0x1f, data->val_in);
1078 EL3WINDOW(saved_window);
1079 spin_unlock_irqrestore(&lp->window_lock, flags);
1080 return 0;
1081 }
1082 default:
1083 return -EOPNOTSUPP;
1084 }
1085}
1086
1087/* The Odie chip has a 64 bin multicast filter, but the bit layout is not
1088 documented. Until it is we revert to receiving all multicast frames when
1089 any multicast reception is desired.
1090 Note: My other drivers emit a log message whenever promiscuous mode is
1091 entered to help detect password sniffers. This is less desirable on
1092 typical PC card machines, so we omit the message.
1093 */
1094
1095static void set_rx_mode(struct net_device *dev)
1096{
1097 unsigned int ioaddr = dev->base_addr;
1098
1099 if (dev->flags & IFF_PROMISC)
1100 outw(SetRxFilter | RxStation | RxMulticast | RxBroadcast | RxProm,
1101 ioaddr + EL3_CMD);
1102 else if (!netdev_mc_empty(dev) || (dev->flags & IFF_ALLMULTI))
1103 outw(SetRxFilter|RxStation|RxMulticast|RxBroadcast, ioaddr + EL3_CMD);
1104 else
1105 outw(SetRxFilter | RxStation | RxBroadcast, ioaddr + EL3_CMD);
1106}
1107
1108static void set_multicast_list(struct net_device *dev)
1109{
1110 struct el3_private *lp = netdev_priv(dev);
1111 unsigned long flags;
1112
1113 spin_lock_irqsave(&lp->window_lock, flags);
1114 set_rx_mode(dev);
1115 spin_unlock_irqrestore(&lp->window_lock, flags);
1116}
1117
1118static int el3_close(struct net_device *dev)
1119{
1120 unsigned int ioaddr = dev->base_addr;
1121 struct el3_private *lp = netdev_priv(dev);
1122 struct pcmcia_device *link = lp->p_dev;
1123
1124 dev_dbg(&link->dev, "%s: shutting down ethercard.\n", dev->name);
1125
1126 if (pcmcia_dev_present(link)) {
1127 unsigned long flags;
1128
1129 /* Turn off statistics ASAP. We update lp->stats below. */
1130 outw(StatsDisable, ioaddr + EL3_CMD);
1131
1132 /* Disable the receiver and transmitter. */
1133 outw(RxDisable, ioaddr + EL3_CMD);
1134 outw(TxDisable, ioaddr + EL3_CMD);
1135
1136 /* Note: Switching to window 0 may disable the IRQ. */
1137 EL3WINDOW(0);
1138 spin_lock_irqsave(&lp->window_lock, flags);
1139 update_stats(dev);
1140 spin_unlock_irqrestore(&lp->window_lock, flags);
1141
1142 /* force interrupts off */
1143 outw(SetIntrEnb | 0x0000, ioaddr + EL3_CMD);
1144 }
1145
1146 link->open--;
1147 netif_stop_queue(dev);
1148 del_timer_sync(&lp->media);
1149
1150 return 0;
1151}
1152
1153static const struct pcmcia_device_id tc574_ids[] = {
1154 PCMCIA_DEVICE_MANF_CARD(0x0101, 0x0574),
1155 PCMCIA_MFC_DEVICE_CIS_MANF_CARD(0, 0x0101, 0x0556, "cis/3CCFEM556.cis"),
1156 PCMCIA_DEVICE_NULL,
1157};
1158MODULE_DEVICE_TABLE(pcmcia, tc574_ids);
1159
1160static struct pcmcia_driver tc574_driver = {
1161 .owner = THIS_MODULE,
1162 .name = "3c574_cs",
1163 .probe = tc574_probe,
1164 .remove = tc574_detach,
1165 .id_table = tc574_ids,
1166 .suspend = tc574_suspend,
1167 .resume = tc574_resume,
1168};
1169
1170static int __init init_tc574(void)
1171{
1172 return pcmcia_register_driver(&tc574_driver);
1173}
1174
1175static void __exit exit_tc574(void)
1176{
1177 pcmcia_unregister_driver(&tc574_driver);
1178}
1179
1180module_init(init_tc574);
1181module_exit(exit_tc574);
diff --git a/drivers/net/pcmcia/3c589_cs.c b/drivers/net/pcmcia/3c589_cs.c
new file mode 100644
index 00000000000..4a1a3580980
--- /dev/null
+++ b/drivers/net/pcmcia/3c589_cs.c
@@ -0,0 +1,943 @@
1/*======================================================================
2
3 A PCMCIA ethernet driver for the 3com 3c589 card.
4
5 Copyright (C) 1999 David A. Hinds -- dahinds@users.sourceforge.net
6
7 3c589_cs.c 1.162 2001/10/13 00:08:50
8
9 The network driver code is based on Donald Becker's 3c589 code:
10
11 Written 1994 by Donald Becker.
12 Copyright 1993 United States Government as represented by the
13 Director, National Security Agency. This software may be used and
14 distributed according to the terms of the GNU General Public License,
15 incorporated herein by reference.
16 Donald Becker may be reached at becker@scyld.com
17
18 Updated for 2.5.x by Alan Cox <alan@lxorguk.ukuu.org.uk>
19
20======================================================================*/
21
22#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23
24#define DRV_NAME "3c589_cs"
25#define DRV_VERSION "1.162-ac"
26
27#include <linux/module.h>
28#include <linux/init.h>
29#include <linux/kernel.h>
30#include <linux/ptrace.h>
31#include <linux/slab.h>
32#include <linux/string.h>
33#include <linux/timer.h>
34#include <linux/interrupt.h>
35#include <linux/in.h>
36#include <linux/delay.h>
37#include <linux/ethtool.h>
38#include <linux/netdevice.h>
39#include <linux/etherdevice.h>
40#include <linux/skbuff.h>
41#include <linux/if_arp.h>
42#include <linux/ioport.h>
43#include <linux/bitops.h>
44#include <linux/jiffies.h>
45
46#include <pcmcia/cistpl.h>
47#include <pcmcia/cisreg.h>
48#include <pcmcia/ciscode.h>
49#include <pcmcia/ds.h>
50
51#include <asm/uaccess.h>
52#include <asm/io.h>
53#include <asm/system.h>
54
55/* To minimize the size of the driver source I only define operating
56 constants if they are used several times. You'll need the manual
57 if you want to understand driver details. */
58/* Offsets from base I/O address. */
59#define EL3_DATA 0x00
60#define EL3_TIMER 0x0a
61#define EL3_CMD 0x0e
62#define EL3_STATUS 0x0e
63
64#define EEPROM_READ 0x0080
65#define EEPROM_BUSY 0x8000
66
67#define EL3WINDOW(win_num) outw(SelectWindow + (win_num), ioaddr + EL3_CMD)
68
69/* The top five bits written to EL3_CMD are a command, the lower
70 11 bits are the parameter, if applicable. */
71enum c509cmd {
72 TotalReset = 0<<11,
73 SelectWindow = 1<<11,
74 StartCoax = 2<<11,
75 RxDisable = 3<<11,
76 RxEnable = 4<<11,
77 RxReset = 5<<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
93};
94
95enum c509status {
96 IntLatch = 0x0001,
97 AdapterFailure = 0x0002,
98 TxComplete = 0x0004,
99 TxAvailable = 0x0008,
100 RxComplete = 0x0010,
101 RxEarly = 0x0020,
102 IntReq = 0x0040,
103 StatsFull = 0x0080,
104 CmdBusy = 0x1000
105};
106
107/* The SetRxFilter command accepts the following classes: */
108enum RxFilter {
109 RxStation = 1,
110 RxMulticast = 2,
111 RxBroadcast = 4,
112 RxProm = 8
113};
114
115/* Register window 1 offsets, the window used in normal operation. */
116#define TX_FIFO 0x00
117#define RX_FIFO 0x00
118#define RX_STATUS 0x08
119#define TX_STATUS 0x0B
120#define TX_FREE 0x0C /* Remaining free bytes in Tx buffer. */
121
122#define WN0_IRQ 0x08 /* Window 0: Set IRQ line in bits 12-15. */
123#define WN4_MEDIA 0x0A /* Window 4: Various transcvr/media bits. */
124#define MEDIA_TP 0x00C0 /* Enable link beat and jabber for 10baseT. */
125#define MEDIA_LED 0x0001 /* Enable link light on 3C589E cards. */
126
127/* Time in jiffies before concluding Tx hung */
128#define TX_TIMEOUT ((400*HZ)/1000)
129
130struct el3_private {
131 struct pcmcia_device *p_dev;
132 /* For transceiver monitoring */
133 struct timer_list media;
134 u16 media_status;
135 u16 fast_poll;
136 unsigned long last_irq;
137 spinlock_t lock;
138};
139
140static const char *if_names[] = { "auto", "10baseT", "10base2", "AUI" };
141
142/*====================================================================*/
143
144/* Module parameters */
145
146MODULE_AUTHOR("David Hinds <dahinds@users.sourceforge.net>");
147MODULE_DESCRIPTION("3Com 3c589 series PCMCIA ethernet driver");
148MODULE_LICENSE("GPL");
149
150#define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0)
151
152/* Special hook for setting if_port when module is loaded */
153INT_MODULE_PARM(if_port, 0);
154
155
156/*====================================================================*/
157
158static int tc589_config(struct pcmcia_device *link);
159static void tc589_release(struct pcmcia_device *link);
160
161static u16 read_eeprom(unsigned int ioaddr, int index);
162static void tc589_reset(struct net_device *dev);
163static void media_check(unsigned long arg);
164static int el3_config(struct net_device *dev, struct ifmap *map);
165static int el3_open(struct net_device *dev);
166static netdev_tx_t el3_start_xmit(struct sk_buff *skb,
167 struct net_device *dev);
168static irqreturn_t el3_interrupt(int irq, void *dev_id);
169static void update_stats(struct net_device *dev);
170static struct net_device_stats *el3_get_stats(struct net_device *dev);
171static int el3_rx(struct net_device *dev);
172static int el3_close(struct net_device *dev);
173static void el3_tx_timeout(struct net_device *dev);
174static void set_rx_mode(struct net_device *dev);
175static void set_multicast_list(struct net_device *dev);
176static const struct ethtool_ops netdev_ethtool_ops;
177
178static void tc589_detach(struct pcmcia_device *p_dev);
179
180static const struct net_device_ops el3_netdev_ops = {
181 .ndo_open = el3_open,
182 .ndo_stop = el3_close,
183 .ndo_start_xmit = el3_start_xmit,
184 .ndo_tx_timeout = el3_tx_timeout,
185 .ndo_set_config = el3_config,
186 .ndo_get_stats = el3_get_stats,
187 .ndo_set_multicast_list = set_multicast_list,
188 .ndo_change_mtu = eth_change_mtu,
189 .ndo_set_mac_address = eth_mac_addr,
190 .ndo_validate_addr = eth_validate_addr,
191};
192
193static int tc589_probe(struct pcmcia_device *link)
194{
195 struct el3_private *lp;
196 struct net_device *dev;
197
198 dev_dbg(&link->dev, "3c589_attach()\n");
199
200 /* Create new ethernet device */
201 dev = alloc_etherdev(sizeof(struct el3_private));
202 if (!dev)
203 return -ENOMEM;
204 lp = netdev_priv(dev);
205 link->priv = dev;
206 lp->p_dev = link;
207
208 spin_lock_init(&lp->lock);
209 link->resource[0]->end = 16;
210 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_16;
211
212 link->config_flags |= CONF_ENABLE_IRQ;
213 link->config_index = 1;
214
215 dev->netdev_ops = &el3_netdev_ops;
216 dev->watchdog_timeo = TX_TIMEOUT;
217
218 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
219
220 return tc589_config(link);
221}
222
223static void tc589_detach(struct pcmcia_device *link)
224{
225 struct net_device *dev = link->priv;
226
227 dev_dbg(&link->dev, "3c589_detach\n");
228
229 unregister_netdev(dev);
230
231 tc589_release(link);
232
233 free_netdev(dev);
234} /* tc589_detach */
235
236static int tc589_config(struct pcmcia_device *link)
237{
238 struct net_device *dev = link->priv;
239 __be16 *phys_addr;
240 int ret, i, j, multi = 0, fifo;
241 unsigned int ioaddr;
242 static const char * const ram_split[] = {"5:3", "3:1", "1:1", "3:5"};
243 u8 *buf;
244 size_t len;
245
246 dev_dbg(&link->dev, "3c589_config\n");
247
248 phys_addr = (__be16 *)dev->dev_addr;
249 /* Is this a 3c562? */
250 if (link->manf_id != MANFID_3COM)
251 dev_info(&link->dev, "hmmm, is this really a 3Com card??\n");
252 multi = (link->card_id == PRODID_3COM_3C562);
253
254 link->io_lines = 16;
255
256 /* For the 3c562, the base address must be xx00-xx7f */
257 for (i = j = 0; j < 0x400; j += 0x10) {
258 if (multi && (j & 0x80)) continue;
259 link->resource[0]->start = j ^ 0x300;
260 i = pcmcia_request_io(link);
261 if (i == 0)
262 break;
263 }
264 if (i != 0)
265 goto failed;
266
267 ret = pcmcia_request_irq(link, el3_interrupt);
268 if (ret)
269 goto failed;
270
271 ret = pcmcia_enable_device(link);
272 if (ret)
273 goto failed;
274
275 dev->irq = link->irq;
276 dev->base_addr = link->resource[0]->start;
277 ioaddr = dev->base_addr;
278 EL3WINDOW(0);
279
280 /* The 3c589 has an extra EEPROM for configuration info, including
281 the hardware address. The 3c562 puts the address in the CIS. */
282 len = pcmcia_get_tuple(link, 0x88, &buf);
283 if (buf && len >= 6) {
284 for (i = 0; i < 3; i++)
285 phys_addr[i] = htons(le16_to_cpu(buf[i*2]));
286 kfree(buf);
287 } else {
288 kfree(buf); /* 0 < len < 6 */
289 for (i = 0; i < 3; i++)
290 phys_addr[i] = htons(read_eeprom(ioaddr, i));
291 if (phys_addr[0] == htons(0x6060)) {
292 dev_err(&link->dev, "IO port conflict at 0x%03lx-0x%03lx\n",
293 dev->base_addr, dev->base_addr+15);
294 goto failed;
295 }
296 }
297
298 /* The address and resource configuration register aren't loaded from
299 the EEPROM and *must* be set to 0 and IRQ3 for the PCMCIA version. */
300 outw(0x3f00, ioaddr + 8);
301 fifo = inl(ioaddr);
302
303 /* The if_port symbol can be set when the module is loaded */
304 if ((if_port >= 0) && (if_port <= 3))
305 dev->if_port = if_port;
306 else
307 dev_err(&link->dev, "invalid if_port requested\n");
308
309 SET_NETDEV_DEV(dev, &link->dev);
310
311 if (register_netdev(dev) != 0) {
312 dev_err(&link->dev, "register_netdev() failed\n");
313 goto failed;
314 }
315
316 netdev_info(dev, "3Com 3c%s, io %#3lx, irq %d, hw_addr %pM\n",
317 (multi ? "562" : "589"), dev->base_addr, dev->irq,
318 dev->dev_addr);
319 netdev_info(dev, " %dK FIFO split %s Rx:Tx, %s xcvr\n",
320 (fifo & 7) ? 32 : 8, ram_split[(fifo >> 16) & 3],
321 if_names[dev->if_port]);
322 return 0;
323
324failed:
325 tc589_release(link);
326 return -ENODEV;
327} /* tc589_config */
328
329static void tc589_release(struct pcmcia_device *link)
330{
331 pcmcia_disable_device(link);
332}
333
334static int tc589_suspend(struct pcmcia_device *link)
335{
336 struct net_device *dev = link->priv;
337
338 if (link->open)
339 netif_device_detach(dev);
340
341 return 0;
342}
343
344static int tc589_resume(struct pcmcia_device *link)
345{
346 struct net_device *dev = link->priv;
347
348 if (link->open) {
349 tc589_reset(dev);
350 netif_device_attach(dev);
351 }
352
353 return 0;
354}
355
356/*====================================================================*/
357
358/*
359 Use this for commands that may take time to finish
360*/
361static void tc589_wait_for_completion(struct net_device *dev, int cmd)
362{
363 int i = 100;
364 outw(cmd, dev->base_addr + EL3_CMD);
365 while (--i > 0)
366 if (!(inw(dev->base_addr + EL3_STATUS) & 0x1000)) break;
367 if (i == 0)
368 netdev_warn(dev, "command 0x%04x did not complete!\n", cmd);
369}
370
371/*
372 Read a word from the EEPROM using the regular EEPROM access register.
373 Assume that we are in register window zero.
374*/
375static u16 read_eeprom(unsigned int ioaddr, int index)
376{
377 int i;
378 outw(EEPROM_READ + index, ioaddr + 10);
379 /* Reading the eeprom takes 162 us */
380 for (i = 1620; i >= 0; i--)
381 if ((inw(ioaddr + 10) & EEPROM_BUSY) == 0)
382 break;
383 return inw(ioaddr + 12);
384}
385
386/*
387 Set transceiver type, perhaps to something other than what the user
388 specified in dev->if_port.
389*/
390static void tc589_set_xcvr(struct net_device *dev, int if_port)
391{
392 struct el3_private *lp = netdev_priv(dev);
393 unsigned int ioaddr = dev->base_addr;
394
395 EL3WINDOW(0);
396 switch (if_port) {
397 case 0: case 1: outw(0, ioaddr + 6); break;
398 case 2: outw(3<<14, ioaddr + 6); break;
399 case 3: outw(1<<14, ioaddr + 6); break;
400 }
401 /* On PCMCIA, this just turns on the LED */
402 outw((if_port == 2) ? StartCoax : StopCoax, ioaddr + EL3_CMD);
403 /* 10baseT interface, enable link beat and jabber check. */
404 EL3WINDOW(4);
405 outw(MEDIA_LED | ((if_port < 2) ? MEDIA_TP : 0), ioaddr + WN4_MEDIA);
406 EL3WINDOW(1);
407 if (if_port == 2)
408 lp->media_status = ((dev->if_port == 0) ? 0x8000 : 0x4000);
409 else
410 lp->media_status = ((dev->if_port == 0) ? 0x4010 : 0x8800);
411}
412
413static void dump_status(struct net_device *dev)
414{
415 unsigned int ioaddr = dev->base_addr;
416 EL3WINDOW(1);
417 netdev_info(dev, " irq status %04x, rx status %04x, tx status %02x tx free %04x\n",
418 inw(ioaddr+EL3_STATUS), inw(ioaddr+RX_STATUS),
419 inb(ioaddr+TX_STATUS), inw(ioaddr+TX_FREE));
420 EL3WINDOW(4);
421 netdev_info(dev, " diagnostics: fifo %04x net %04x ethernet %04x media %04x\n",
422 inw(ioaddr+0x04), inw(ioaddr+0x06), inw(ioaddr+0x08),
423 inw(ioaddr+0x0a));
424 EL3WINDOW(1);
425}
426
427/* Reset and restore all of the 3c589 registers. */
428static void tc589_reset(struct net_device *dev)
429{
430 unsigned int ioaddr = dev->base_addr;
431 int i;
432
433 EL3WINDOW(0);
434 outw(0x0001, ioaddr + 4); /* Activate board. */
435 outw(0x3f00, ioaddr + 8); /* Set the IRQ line. */
436
437 /* Set the station address in window 2. */
438 EL3WINDOW(2);
439 for (i = 0; i < 6; i++)
440 outb(dev->dev_addr[i], ioaddr + i);
441
442 tc589_set_xcvr(dev, dev->if_port);
443
444 /* Switch to the stats window, and clear all stats by reading. */
445 outw(StatsDisable, ioaddr + EL3_CMD);
446 EL3WINDOW(6);
447 for (i = 0; i < 9; i++)
448 inb(ioaddr+i);
449 inw(ioaddr + 10);
450 inw(ioaddr + 12);
451
452 /* Switch to register set 1 for normal use. */
453 EL3WINDOW(1);
454
455 set_rx_mode(dev);
456 outw(StatsEnable, ioaddr + EL3_CMD); /* Turn on statistics. */
457 outw(RxEnable, ioaddr + EL3_CMD); /* Enable the receiver. */
458 outw(TxEnable, ioaddr + EL3_CMD); /* Enable transmitter. */
459 /* Allow status bits to be seen. */
460 outw(SetStatusEnb | 0xff, ioaddr + EL3_CMD);
461 /* Ack all pending events, and set active indicator mask. */
462 outw(AckIntr | IntLatch | TxAvailable | RxEarly | IntReq,
463 ioaddr + EL3_CMD);
464 outw(SetIntrEnb | IntLatch | TxAvailable | RxComplete | StatsFull
465 | AdapterFailure, ioaddr + EL3_CMD);
466}
467
468static void netdev_get_drvinfo(struct net_device *dev,
469 struct ethtool_drvinfo *info)
470{
471 strcpy(info->driver, DRV_NAME);
472 strcpy(info->version, DRV_VERSION);
473 sprintf(info->bus_info, "PCMCIA 0x%lx", dev->base_addr);
474}
475
476static const struct ethtool_ops netdev_ethtool_ops = {
477 .get_drvinfo = netdev_get_drvinfo,
478};
479
480static int el3_config(struct net_device *dev, struct ifmap *map)
481{
482 if ((map->port != (u_char)(-1)) && (map->port != dev->if_port)) {
483 if (map->port <= 3) {
484 dev->if_port = map->port;
485 netdev_info(dev, "switched to %s port\n", if_names[dev->if_port]);
486 tc589_set_xcvr(dev, dev->if_port);
487 } else
488 return -EINVAL;
489 }
490 return 0;
491}
492
493static int el3_open(struct net_device *dev)
494{
495 struct el3_private *lp = netdev_priv(dev);
496 struct pcmcia_device *link = lp->p_dev;
497
498 if (!pcmcia_dev_present(link))
499 return -ENODEV;
500
501 link->open++;
502 netif_start_queue(dev);
503
504 tc589_reset(dev);
505 init_timer(&lp->media);
506 lp->media.function = media_check;
507 lp->media.data = (unsigned long) dev;
508 lp->media.expires = jiffies + HZ;
509 add_timer(&lp->media);
510
511 dev_dbg(&link->dev, "%s: opened, status %4.4x.\n",
512 dev->name, inw(dev->base_addr + EL3_STATUS));
513
514 return 0;
515}
516
517static void el3_tx_timeout(struct net_device *dev)
518{
519 unsigned int ioaddr = dev->base_addr;
520
521 netdev_warn(dev, "Transmit timed out!\n");
522 dump_status(dev);
523 dev->stats.tx_errors++;
524 dev->trans_start = jiffies; /* prevent tx timeout */
525 /* Issue TX_RESET and TX_START commands. */
526 tc589_wait_for_completion(dev, TxReset);
527 outw(TxEnable, ioaddr + EL3_CMD);
528 netif_wake_queue(dev);
529}
530
531static void pop_tx_status(struct net_device *dev)
532{
533 unsigned int ioaddr = dev->base_addr;
534 int i;
535
536 /* Clear the Tx status stack. */
537 for (i = 32; i > 0; i--) {
538 u_char tx_status = inb(ioaddr + TX_STATUS);
539 if (!(tx_status & 0x84)) break;
540 /* reset transmitter on jabber error or underrun */
541 if (tx_status & 0x30)
542 tc589_wait_for_completion(dev, TxReset);
543 if (tx_status & 0x38) {
544 netdev_dbg(dev, "transmit error: status 0x%02x\n", tx_status);
545 outw(TxEnable, ioaddr + EL3_CMD);
546 dev->stats.tx_aborted_errors++;
547 }
548 outb(0x00, ioaddr + TX_STATUS); /* Pop the status stack. */
549 }
550}
551
552static netdev_tx_t el3_start_xmit(struct sk_buff *skb,
553 struct net_device *dev)
554{
555 unsigned int ioaddr = dev->base_addr;
556 struct el3_private *priv = netdev_priv(dev);
557 unsigned long flags;
558
559 netdev_dbg(dev, "el3_start_xmit(length = %ld) called, status %4.4x.\n",
560 (long)skb->len, inw(ioaddr + EL3_STATUS));
561
562 spin_lock_irqsave(&priv->lock, flags);
563
564 dev->stats.tx_bytes += skb->len;
565
566 /* Put out the doubleword header... */
567 outw(skb->len, ioaddr + TX_FIFO);
568 outw(0x00, ioaddr + TX_FIFO);
569 /* ... and the packet rounded to a doubleword. */
570 outsl(ioaddr + TX_FIFO, skb->data, (skb->len + 3) >> 2);
571
572 if (inw(ioaddr + TX_FREE) <= 1536) {
573 netif_stop_queue(dev);
574 /* Interrupt us when the FIFO has room for max-sized packet. */
575 outw(SetTxThreshold + 1536, ioaddr + EL3_CMD);
576 }
577
578 pop_tx_status(dev);
579 spin_unlock_irqrestore(&priv->lock, flags);
580 dev_kfree_skb(skb);
581
582 return NETDEV_TX_OK;
583}
584
585/* The EL3 interrupt handler. */
586static irqreturn_t el3_interrupt(int irq, void *dev_id)
587{
588 struct net_device *dev = (struct net_device *) dev_id;
589 struct el3_private *lp = netdev_priv(dev);
590 unsigned int ioaddr;
591 __u16 status;
592 int i = 0, handled = 1;
593
594 if (!netif_device_present(dev))
595 return IRQ_NONE;
596
597 ioaddr = dev->base_addr;
598
599 netdev_dbg(dev, "interrupt, status %4.4x.\n", inw(ioaddr + EL3_STATUS));
600
601 spin_lock(&lp->lock);
602 while ((status = inw(ioaddr + EL3_STATUS)) &
603 (IntLatch | RxComplete | StatsFull)) {
604 if ((status & 0xe000) != 0x2000) {
605 netdev_dbg(dev, "interrupt from dead card\n");
606 handled = 0;
607 break;
608 }
609 if (status & RxComplete)
610 el3_rx(dev);
611 if (status & TxAvailable) {
612 netdev_dbg(dev, " TX room bit was handled.\n");
613 /* There's room in the FIFO for a full-sized packet. */
614 outw(AckIntr | TxAvailable, ioaddr + EL3_CMD);
615 netif_wake_queue(dev);
616 }
617 if (status & TxComplete)
618 pop_tx_status(dev);
619 if (status & (AdapterFailure | RxEarly | StatsFull)) {
620 /* Handle all uncommon interrupts. */
621 if (status & StatsFull) /* Empty statistics. */
622 update_stats(dev);
623 if (status & RxEarly) { /* Rx early is unused. */
624 el3_rx(dev);
625 outw(AckIntr | RxEarly, ioaddr + EL3_CMD);
626 }
627 if (status & AdapterFailure) {
628 u16 fifo_diag;
629 EL3WINDOW(4);
630 fifo_diag = inw(ioaddr + 4);
631 EL3WINDOW(1);
632 netdev_warn(dev, "adapter failure, FIFO diagnostic register %04x.\n",
633 fifo_diag);
634 if (fifo_diag & 0x0400) {
635 /* Tx overrun */
636 tc589_wait_for_completion(dev, TxReset);
637 outw(TxEnable, ioaddr + EL3_CMD);
638 }
639 if (fifo_diag & 0x2000) {
640 /* Rx underrun */
641 tc589_wait_for_completion(dev, RxReset);
642 set_rx_mode(dev);
643 outw(RxEnable, ioaddr + EL3_CMD);
644 }
645 outw(AckIntr | AdapterFailure, ioaddr + EL3_CMD);
646 }
647 }
648 if (++i > 10) {
649 netdev_err(dev, "infinite loop in interrupt, status %4.4x.\n",
650 status);
651 /* Clear all interrupts */
652 outw(AckIntr | 0xFF, ioaddr + EL3_CMD);
653 break;
654 }
655 /* Acknowledge the IRQ. */
656 outw(AckIntr | IntReq | IntLatch, ioaddr + EL3_CMD);
657 }
658 lp->last_irq = jiffies;
659 spin_unlock(&lp->lock);
660 netdev_dbg(dev, "exiting interrupt, status %4.4x.\n",
661 inw(ioaddr + EL3_STATUS));
662 return IRQ_RETVAL(handled);
663}
664
665static void media_check(unsigned long arg)
666{
667 struct net_device *dev = (struct net_device *)(arg);
668 struct el3_private *lp = netdev_priv(dev);
669 unsigned int ioaddr = dev->base_addr;
670 u16 media, errs;
671 unsigned long flags;
672
673 if (!netif_device_present(dev)) goto reschedule;
674
675 /* Check for pending interrupt with expired latency timer: with
676 this, we can limp along even if the interrupt is blocked */
677 if ((inw(ioaddr + EL3_STATUS) & IntLatch) &&
678 (inb(ioaddr + EL3_TIMER) == 0xff)) {
679 if (!lp->fast_poll)
680 netdev_warn(dev, "interrupt(s) dropped!\n");
681
682 local_irq_save(flags);
683 el3_interrupt(dev->irq, dev);
684 local_irq_restore(flags);
685
686 lp->fast_poll = HZ;
687 }
688 if (lp->fast_poll) {
689 lp->fast_poll--;
690 lp->media.expires = jiffies + HZ/100;
691 add_timer(&lp->media);
692 return;
693 }
694
695 /* lp->lock guards the EL3 window. Window should always be 1 except
696 when the lock is held */
697 spin_lock_irqsave(&lp->lock, flags);
698 EL3WINDOW(4);
699 media = inw(ioaddr+WN4_MEDIA) & 0xc810;
700
701 /* Ignore collisions unless we've had no irq's recently */
702 if (time_before(jiffies, lp->last_irq + HZ)) {
703 media &= ~0x0010;
704 } else {
705 /* Try harder to detect carrier errors */
706 EL3WINDOW(6);
707 outw(StatsDisable, ioaddr + EL3_CMD);
708 errs = inb(ioaddr + 0);
709 outw(StatsEnable, ioaddr + EL3_CMD);
710 dev->stats.tx_carrier_errors += errs;
711 if (errs || (lp->media_status & 0x0010)) media |= 0x0010;
712 }
713
714 if (media != lp->media_status) {
715 if ((media & lp->media_status & 0x8000) &&
716 ((lp->media_status ^ media) & 0x0800))
717 netdev_info(dev, "%s link beat\n",
718 (lp->media_status & 0x0800 ? "lost" : "found"));
719 else if ((media & lp->media_status & 0x4000) &&
720 ((lp->media_status ^ media) & 0x0010))
721 netdev_info(dev, "coax cable %s\n",
722 (lp->media_status & 0x0010 ? "ok" : "problem"));
723 if (dev->if_port == 0) {
724 if (media & 0x8000) {
725 if (media & 0x0800)
726 netdev_info(dev, "flipped to 10baseT\n");
727 else
728 tc589_set_xcvr(dev, 2);
729 } else if (media & 0x4000) {
730 if (media & 0x0010)
731 tc589_set_xcvr(dev, 1);
732 else
733 netdev_info(dev, "flipped to 10base2\n");
734 }
735 }
736 lp->media_status = media;
737 }
738
739 EL3WINDOW(1);
740 spin_unlock_irqrestore(&lp->lock, flags);
741
742reschedule:
743 lp->media.expires = jiffies + HZ;
744 add_timer(&lp->media);
745}
746
747static struct net_device_stats *el3_get_stats(struct net_device *dev)
748{
749 struct el3_private *lp = netdev_priv(dev);
750 unsigned long flags;
751 struct pcmcia_device *link = lp->p_dev;
752
753 if (pcmcia_dev_present(link)) {
754 spin_lock_irqsave(&lp->lock, flags);
755 update_stats(dev);
756 spin_unlock_irqrestore(&lp->lock, flags);
757 }
758 return &dev->stats;
759}
760
761/*
762 Update statistics. We change to register window 6, so this should be run
763 single-threaded if the device is active. This is expected to be a rare
764 operation, and it's simpler for the rest of the driver to assume that
765 window 1 is always valid rather than use a special window-state variable.
766
767 Caller must hold the lock for this
768*/
769static void update_stats(struct net_device *dev)
770{
771 unsigned int ioaddr = dev->base_addr;
772
773 netdev_dbg(dev, "updating the statistics.\n");
774 /* Turn off statistics updates while reading. */
775 outw(StatsDisable, ioaddr + EL3_CMD);
776 /* Switch to the stats window, and read everything. */
777 EL3WINDOW(6);
778 dev->stats.tx_carrier_errors += inb(ioaddr + 0);
779 dev->stats.tx_heartbeat_errors += inb(ioaddr + 1);
780 /* Multiple collisions. */ inb(ioaddr + 2);
781 dev->stats.collisions += inb(ioaddr + 3);
782 dev->stats.tx_window_errors += inb(ioaddr + 4);
783 dev->stats.rx_fifo_errors += inb(ioaddr + 5);
784 dev->stats.tx_packets += inb(ioaddr + 6);
785 /* Rx packets */ inb(ioaddr + 7);
786 /* Tx deferrals */ inb(ioaddr + 8);
787 /* Rx octets */ inw(ioaddr + 10);
788 /* Tx octets */ inw(ioaddr + 12);
789
790 /* Back to window 1, and turn statistics back on. */
791 EL3WINDOW(1);
792 outw(StatsEnable, ioaddr + EL3_CMD);
793}
794
795static int el3_rx(struct net_device *dev)
796{
797 unsigned int ioaddr = dev->base_addr;
798 int worklimit = 32;
799 short rx_status;
800
801 netdev_dbg(dev, "in rx_packet(), status %4.4x, rx_status %4.4x.\n",
802 inw(ioaddr+EL3_STATUS), inw(ioaddr+RX_STATUS));
803 while (!((rx_status = inw(ioaddr + RX_STATUS)) & 0x8000) &&
804 worklimit > 0) {
805 worklimit--;
806 if (rx_status & 0x4000) { /* Error, update stats. */
807 short error = rx_status & 0x3800;
808 dev->stats.rx_errors++;
809 switch (error) {
810 case 0x0000: dev->stats.rx_over_errors++; break;
811 case 0x0800: dev->stats.rx_length_errors++; break;
812 case 0x1000: dev->stats.rx_frame_errors++; break;
813 case 0x1800: dev->stats.rx_length_errors++; break;
814 case 0x2000: dev->stats.rx_frame_errors++; break;
815 case 0x2800: dev->stats.rx_crc_errors++; break;
816 }
817 } else {
818 short pkt_len = rx_status & 0x7ff;
819 struct sk_buff *skb;
820
821 skb = dev_alloc_skb(pkt_len+5);
822
823 netdev_dbg(dev, " Receiving packet size %d status %4.4x.\n",
824 pkt_len, rx_status);
825 if (skb != NULL) {
826 skb_reserve(skb, 2);
827 insl(ioaddr+RX_FIFO, skb_put(skb, pkt_len),
828 (pkt_len+3)>>2);
829 skb->protocol = eth_type_trans(skb, dev);
830 netif_rx(skb);
831 dev->stats.rx_packets++;
832 dev->stats.rx_bytes += pkt_len;
833 } else {
834 netdev_dbg(dev, "couldn't allocate a sk_buff of size %d.\n",
835 pkt_len);
836 dev->stats.rx_dropped++;
837 }
838 }
839 /* Pop the top of the Rx FIFO */
840 tc589_wait_for_completion(dev, RxDiscard);
841 }
842 if (worklimit == 0)
843 netdev_warn(dev, "too much work in el3_rx!\n");
844 return 0;
845}
846
847static void set_rx_mode(struct net_device *dev)
848{
849 unsigned int ioaddr = dev->base_addr;
850 u16 opts = SetRxFilter | RxStation | RxBroadcast;
851
852 if (dev->flags & IFF_PROMISC)
853 opts |= RxMulticast | RxProm;
854 else if (!netdev_mc_empty(dev) || (dev->flags & IFF_ALLMULTI))
855 opts |= RxMulticast;
856 outw(opts, ioaddr + EL3_CMD);
857}
858
859static void set_multicast_list(struct net_device *dev)
860{
861 struct el3_private *priv = netdev_priv(dev);
862 unsigned long flags;
863
864 spin_lock_irqsave(&priv->lock, flags);
865 set_rx_mode(dev);
866 spin_unlock_irqrestore(&priv->lock, flags);
867}
868
869static int el3_close(struct net_device *dev)
870{
871 struct el3_private *lp = netdev_priv(dev);
872 struct pcmcia_device *link = lp->p_dev;
873 unsigned int ioaddr = dev->base_addr;
874
875 dev_dbg(&link->dev, "%s: shutting down ethercard.\n", dev->name);
876
877 if (pcmcia_dev_present(link)) {
878 /* Turn off statistics ASAP. We update dev->stats below. */
879 outw(StatsDisable, ioaddr + EL3_CMD);
880
881 /* Disable the receiver and transmitter. */
882 outw(RxDisable, ioaddr + EL3_CMD);
883 outw(TxDisable, ioaddr + EL3_CMD);
884
885 if (dev->if_port == 2)
886 /* Turn off thinnet power. Green! */
887 outw(StopCoax, ioaddr + EL3_CMD);
888 else if (dev->if_port == 1) {
889 /* Disable link beat and jabber */
890 EL3WINDOW(4);
891 outw(0, ioaddr + WN4_MEDIA);
892 }
893
894 /* Switching back to window 0 disables the IRQ. */
895 EL3WINDOW(0);
896 /* But we explicitly zero the IRQ line select anyway. */
897 outw(0x0f00, ioaddr + WN0_IRQ);
898
899 /* Check if the card still exists */
900 if ((inw(ioaddr+EL3_STATUS) & 0xe000) == 0x2000)
901 update_stats(dev);
902 }
903
904 link->open--;
905 netif_stop_queue(dev);
906 del_timer_sync(&lp->media);
907
908 return 0;
909}
910
911static const struct pcmcia_device_id tc589_ids[] = {
912 PCMCIA_MFC_DEVICE_MANF_CARD(0, 0x0101, 0x0562),
913 PCMCIA_MFC_DEVICE_PROD_ID1(0, "Motorola MARQUIS", 0xf03e4e77),
914 PCMCIA_DEVICE_MANF_CARD(0x0101, 0x0589),
915 PCMCIA_DEVICE_PROD_ID12("Farallon", "ENet", 0x58d93fc4, 0x992c2202),
916 PCMCIA_MFC_DEVICE_CIS_MANF_CARD(0, 0x0101, 0x0035, "cis/3CXEM556.cis"),
917 PCMCIA_MFC_DEVICE_CIS_MANF_CARD(0, 0x0101, 0x003d, "cis/3CXEM556.cis"),
918 PCMCIA_DEVICE_NULL,
919};
920MODULE_DEVICE_TABLE(pcmcia, tc589_ids);
921
922static struct pcmcia_driver tc589_driver = {
923 .owner = THIS_MODULE,
924 .name = "3c589_cs",
925 .probe = tc589_probe,
926 .remove = tc589_detach,
927 .id_table = tc589_ids,
928 .suspend = tc589_suspend,
929 .resume = tc589_resume,
930};
931
932static int __init init_tc589(void)
933{
934 return pcmcia_register_driver(&tc589_driver);
935}
936
937static void __exit exit_tc589(void)
938{
939 pcmcia_unregister_driver(&tc589_driver);
940}
941
942module_init(init_tc589);
943module_exit(exit_tc589);
diff --git a/drivers/net/pcmcia/Kconfig b/drivers/net/pcmcia/Kconfig
new file mode 100644
index 00000000000..9b8f793b1cc
--- /dev/null
+++ b/drivers/net/pcmcia/Kconfig
@@ -0,0 +1,123 @@
1#
2# PCMCIA Network device configuration
3#
4
5menuconfig NET_PCMCIA
6 bool "PCMCIA network device support"
7 depends on PCMCIA
8 ---help---
9 Say Y if you would like to include support for any PCMCIA or CardBus
10 network adapters, then say Y to the driver for your particular card
11 below. PCMCIA- or PC-cards are credit-card size devices often used
12 with laptops computers; CardBus is the newer and faster version of
13 PCMCIA.
14
15 To use your PC-cards, you will need supporting software from David
16 Hinds' pcmcia-cs package (see the file <file:Documentation/Changes>
17 for location). You also want to check out the PCMCIA-HOWTO,
18 available from <http://www.tldp.org/docs.html#howto>.
19
20 If unsure, say N.
21
22if NET_PCMCIA && PCMCIA
23
24config PCMCIA_3C589
25 tristate "3Com 3c589 PCMCIA support"
26 help
27 Say Y here if you intend to attach a 3Com 3c589 or compatible PCMCIA
28 (PC-card) Ethernet card to your computer.
29
30 To compile this driver as a module, choose M here: the module will be
31 called 3c589_cs. If unsure, say N.
32
33config PCMCIA_3C574
34 tristate "3Com 3c574 PCMCIA support"
35 help
36 Say Y here if you intend to attach a 3Com 3c574 or compatible PCMCIA
37 (PC-card) Fast Ethernet card to your computer.
38
39 To compile this driver as a module, choose M here: the module will be
40 called 3c574_cs. If unsure, say N.
41
42config PCMCIA_FMVJ18X
43 tristate "Fujitsu FMV-J18x PCMCIA support"
44 select CRC32
45 help
46 Say Y here if you intend to attach a Fujitsu FMV-J18x or compatible
47 PCMCIA (PC-card) Ethernet card to your computer.
48
49 To compile this driver as a module, choose M here: the module will be
50 called fmvj18x_cs. If unsure, say N.
51
52config PCMCIA_PCNET
53 tristate "NE2000 compatible PCMCIA support"
54 select CRC32
55 help
56 Say Y here if you intend to attach an NE2000 compatible PCMCIA
57 (PC-card) Ethernet or Fast Ethernet card to your computer.
58
59 To compile this driver as a module, choose M here: the module will be
60 called pcnet_cs. If unsure, say N.
61
62config PCMCIA_NMCLAN
63 tristate "New Media PCMCIA support"
64 help
65 Say Y here if you intend to attach a New Media Ethernet or LiveWire
66 PCMCIA (PC-card) Ethernet card to your computer.
67
68 To compile this driver as a module, choose M here: the module will be
69 called nmclan_cs. If unsure, say N.
70
71config PCMCIA_SMC91C92
72 tristate "SMC 91Cxx PCMCIA support"
73 select CRC32
74 select MII
75 help
76 Say Y here if you intend to attach an SMC 91Cxx compatible PCMCIA
77 (PC-card) Ethernet or Fast Ethernet card to your computer.
78
79 To compile this driver as a module, choose M here: the module will be
80 called smc91c92_cs. If unsure, say N.
81
82config PCMCIA_XIRC2PS
83 tristate "Xircom 16-bit PCMCIA support"
84 help
85 Say Y here if you intend to attach a Xircom 16-bit PCMCIA (PC-card)
86 Ethernet or Fast Ethernet card to your computer.
87
88 To compile this driver as a module, choose M here: the module will be
89 called xirc2ps_cs. If unsure, say N.
90
91config PCMCIA_AXNET
92 tristate "Asix AX88190 PCMCIA support"
93 ---help---
94 Say Y here if you intend to attach an Asix AX88190-based PCMCIA
95 (PC-card) Fast Ethernet card to your computer. These cards are
96 nearly NE2000 compatible but need a separate driver due to a few
97 misfeatures.
98
99 To compile this driver as a module, choose M here: the module will be
100 called axnet_cs. If unsure, say N.
101
102config ARCNET_COM20020_CS
103 tristate "COM20020 ARCnet PCMCIA support"
104 depends on ARCNET_COM20020
105 help
106 Say Y here if you intend to attach this type of ARCnet PCMCIA card
107 to your computer.
108
109 To compile this driver as a module, choose M here: the module will be
110 called com20020_cs. If unsure, say N.
111
112config PCMCIA_IBMTR
113 tristate "IBM PCMCIA tokenring adapter support"
114 depends on IBMTR!=y && TR
115 help
116 Say Y here if you intend to attach this type of Token Ring PCMCIA
117 card to your computer. You then also need to say Y to "Token Ring
118 driver support".
119
120 To compile this driver as a module, choose M here: the module will be
121 called ibmtr_cs.
122
123endif # NET_PCMCIA
diff --git a/drivers/net/pcmcia/Makefile b/drivers/net/pcmcia/Makefile
new file mode 100644
index 00000000000..87d2d99f4c1
--- /dev/null
+++ b/drivers/net/pcmcia/Makefile
@@ -0,0 +1,16 @@
1#
2# Makefile for the Linux PCMCIA network device drivers.
3#
4
5# 16-bit client drivers
6obj-$(CONFIG_PCMCIA_3C589) += 3c589_cs.o
7obj-$(CONFIG_PCMCIA_3C574) += 3c574_cs.o
8obj-$(CONFIG_PCMCIA_FMVJ18X) += fmvj18x_cs.o
9obj-$(CONFIG_PCMCIA_NMCLAN) += nmclan_cs.o
10obj-$(CONFIG_PCMCIA_PCNET) += pcnet_cs.o
11obj-$(CONFIG_PCMCIA_SMC91C92) += smc91c92_cs.o
12obj-$(CONFIG_PCMCIA_XIRC2PS) += xirc2ps_cs.o
13obj-$(CONFIG_ARCNET_COM20020_CS)+= com20020_cs.o
14obj-$(CONFIG_PCMCIA_AXNET) += axnet_cs.o
15
16obj-$(CONFIG_PCMCIA_IBMTR) += ibmtr_cs.o
diff --git a/drivers/net/pcmcia/axnet_cs.c b/drivers/net/pcmcia/axnet_cs.c
new file mode 100644
index 00000000000..9953db71196
--- /dev/null
+++ b/drivers/net/pcmcia/axnet_cs.c
@@ -0,0 +1,1725 @@
1/*======================================================================
2
3 A PCMCIA ethernet driver for Asix AX88190-based cards
4
5 The Asix AX88190 is a NS8390-derived chipset with a few nasty
6 idiosyncracies that make it very inconvenient to support with a
7 standard 8390 driver. This driver is based on pcnet_cs, with the
8 tweaked 8390 code grafted on the end. Much of what I did was to
9 clean up and update a similar driver supplied by Asix, which was
10 adapted by William Lee, william@asix.com.tw.
11
12 Copyright (C) 2001 David A. Hinds -- dahinds@users.sourceforge.net
13
14 axnet_cs.c 1.28 2002/06/29 06:27:37
15
16 The network driver code is based on Donald Becker's NE2000 code:
17
18 Written 1992,1993 by Donald Becker.
19 Copyright 1993 United States Government as represented by the
20 Director, National Security Agency. This software may be used and
21 distributed according to the terms of the GNU General Public License,
22 incorporated herein by reference.
23 Donald Becker may be reached at becker@scyld.com
24
25======================================================================*/
26
27#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
28
29#include <linux/kernel.h>
30#include <linux/module.h>
31#include <linux/init.h>
32#include <linux/ptrace.h>
33#include <linux/string.h>
34#include <linux/timer.h>
35#include <linux/delay.h>
36#include <linux/spinlock.h>
37#include <linux/netdevice.h>
38#include <linux/etherdevice.h>
39#include <linux/crc32.h>
40#include <linux/mii.h>
41#include "../8390.h"
42
43#include <pcmcia/cistpl.h>
44#include <pcmcia/ciscode.h>
45#include <pcmcia/ds.h>
46#include <pcmcia/cisreg.h>
47
48#include <asm/io.h>
49#include <asm/system.h>
50#include <asm/byteorder.h>
51#include <asm/uaccess.h>
52
53#define AXNET_CMD 0x00
54#define AXNET_DATAPORT 0x10 /* NatSemi-defined port window offset. */
55#define AXNET_RESET 0x1f /* Issue a read to reset, a write to clear. */
56#define AXNET_MII_EEP 0x14 /* Offset of MII access port */
57#define AXNET_TEST 0x15 /* Offset of TEST Register port */
58#define AXNET_GPIO 0x17 /* Offset of General Purpose Register Port */
59
60#define AXNET_START_PG 0x40 /* First page of TX buffer */
61#define AXNET_STOP_PG 0x80 /* Last page +1 of RX ring */
62
63#define AXNET_RDC_TIMEOUT 0x02 /* Max wait in jiffies for Tx RDC */
64
65#define IS_AX88190 0x0001
66#define IS_AX88790 0x0002
67
68/*====================================================================*/
69
70/* Module parameters */
71
72MODULE_AUTHOR("David Hinds <dahinds@users.sourceforge.net>");
73MODULE_DESCRIPTION("Asix AX88190 PCMCIA ethernet driver");
74MODULE_LICENSE("GPL");
75
76
77/*====================================================================*/
78
79static int axnet_config(struct pcmcia_device *link);
80static void axnet_release(struct pcmcia_device *link);
81static int axnet_open(struct net_device *dev);
82static int axnet_close(struct net_device *dev);
83static int axnet_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
84static netdev_tx_t axnet_start_xmit(struct sk_buff *skb,
85 struct net_device *dev);
86static struct net_device_stats *get_stats(struct net_device *dev);
87static void set_multicast_list(struct net_device *dev);
88static void axnet_tx_timeout(struct net_device *dev);
89static irqreturn_t ei_irq_wrapper(int irq, void *dev_id);
90static void ei_watchdog(u_long arg);
91static void axnet_reset_8390(struct net_device *dev);
92
93static int mdio_read(unsigned int addr, int phy_id, int loc);
94static void mdio_write(unsigned int addr, int phy_id, int loc, int value);
95
96static void get_8390_hdr(struct net_device *,
97 struct e8390_pkt_hdr *, int);
98static void block_input(struct net_device *dev, int count,
99 struct sk_buff *skb, int ring_offset);
100static void block_output(struct net_device *dev, int count,
101 const u_char *buf, const int start_page);
102
103static void axnet_detach(struct pcmcia_device *p_dev);
104
105static void AX88190_init(struct net_device *dev, int startp);
106static int ax_open(struct net_device *dev);
107static int ax_close(struct net_device *dev);
108static irqreturn_t ax_interrupt(int irq, void *dev_id);
109
110/*====================================================================*/
111
112typedef struct axnet_dev_t {
113 struct pcmcia_device *p_dev;
114 caddr_t base;
115 struct timer_list watchdog;
116 int stale, fast_poll;
117 u_short link_status;
118 u_char duplex_flag;
119 int phy_id;
120 int flags;
121 int active_low;
122} axnet_dev_t;
123
124static inline axnet_dev_t *PRIV(struct net_device *dev)
125{
126 void *p = (char *)netdev_priv(dev) + sizeof(struct ei_device);
127 return p;
128}
129
130static const struct net_device_ops axnet_netdev_ops = {
131 .ndo_open = axnet_open,
132 .ndo_stop = axnet_close,
133 .ndo_do_ioctl = axnet_ioctl,
134 .ndo_start_xmit = axnet_start_xmit,
135 .ndo_tx_timeout = axnet_tx_timeout,
136 .ndo_get_stats = get_stats,
137 .ndo_set_multicast_list = set_multicast_list,
138 .ndo_change_mtu = eth_change_mtu,
139 .ndo_set_mac_address = eth_mac_addr,
140 .ndo_validate_addr = eth_validate_addr,
141};
142
143static int axnet_probe(struct pcmcia_device *link)
144{
145 axnet_dev_t *info;
146 struct net_device *dev;
147 struct ei_device *ei_local;
148
149 dev_dbg(&link->dev, "axnet_attach()\n");
150
151 dev = alloc_etherdev(sizeof(struct ei_device) + sizeof(axnet_dev_t));
152 if (!dev)
153 return -ENOMEM;
154
155 ei_local = netdev_priv(dev);
156 spin_lock_init(&ei_local->page_lock);
157
158 info = PRIV(dev);
159 info->p_dev = link;
160 link->priv = dev;
161 link->config_flags |= CONF_ENABLE_IRQ;
162
163 dev->netdev_ops = &axnet_netdev_ops;
164
165 dev->watchdog_timeo = TX_TIMEOUT;
166
167 return axnet_config(link);
168} /* axnet_attach */
169
170static void axnet_detach(struct pcmcia_device *link)
171{
172 struct net_device *dev = link->priv;
173
174 dev_dbg(&link->dev, "axnet_detach(0x%p)\n", link);
175
176 unregister_netdev(dev);
177
178 axnet_release(link);
179
180 free_netdev(dev);
181} /* axnet_detach */
182
183/*======================================================================
184
185 This probes for a card's hardware address by reading the PROM.
186
187======================================================================*/
188
189static int get_prom(struct pcmcia_device *link)
190{
191 struct net_device *dev = link->priv;
192 unsigned int ioaddr = dev->base_addr;
193 int i, j;
194
195 /* This is based on drivers/net/ne.c */
196 struct {
197 u_char value, offset;
198 } program_seq[] = {
199 {E8390_NODMA+E8390_PAGE0+E8390_STOP, E8390_CMD}, /* Select page 0*/
200 {0x01, EN0_DCFG}, /* Set word-wide access. */
201 {0x00, EN0_RCNTLO}, /* Clear the count regs. */
202 {0x00, EN0_RCNTHI},
203 {0x00, EN0_IMR}, /* Mask completion irq. */
204 {0xFF, EN0_ISR},
205 {E8390_RXOFF|0x40, EN0_RXCR}, /* 0x60 Set to monitor */
206 {E8390_TXOFF, EN0_TXCR}, /* 0x02 and loopback mode. */
207 {0x10, EN0_RCNTLO},
208 {0x00, EN0_RCNTHI},
209 {0x00, EN0_RSARLO}, /* DMA starting at 0x0400. */
210 {0x04, EN0_RSARHI},
211 {E8390_RREAD+E8390_START, E8390_CMD},
212 };
213
214 /* Not much of a test, but the alternatives are messy */
215 if (link->config_base != 0x03c0)
216 return 0;
217
218 axnet_reset_8390(dev);
219 mdelay(10);
220
221 for (i = 0; i < ARRAY_SIZE(program_seq); i++)
222 outb_p(program_seq[i].value, ioaddr + program_seq[i].offset);
223
224 for (i = 0; i < 6; i += 2) {
225 j = inw(ioaddr + AXNET_DATAPORT);
226 dev->dev_addr[i] = j & 0xff;
227 dev->dev_addr[i+1] = j >> 8;
228 }
229 return 1;
230} /* get_prom */
231
232static int try_io_port(struct pcmcia_device *link)
233{
234 int j, ret;
235 link->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
236 link->resource[1]->flags &= ~IO_DATA_PATH_WIDTH;
237 if (link->resource[0]->end == 32) {
238 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
239 /* for master/slave multifunction cards */
240 if (link->resource[1]->end > 0)
241 link->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
242 } else {
243 /* This should be two 16-port windows */
244 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
245 link->resource[1]->flags |= IO_DATA_PATH_WIDTH_16;
246 }
247 if (link->resource[0]->start == 0) {
248 for (j = 0; j < 0x400; j += 0x20) {
249 link->resource[0]->start = j ^ 0x300;
250 link->resource[1]->start = (j ^ 0x300) + 0x10;
251 link->io_lines = 16;
252 ret = pcmcia_request_io(link);
253 if (ret == 0)
254 return ret;
255 }
256 return ret;
257 } else {
258 return pcmcia_request_io(link);
259 }
260}
261
262static int axnet_configcheck(struct pcmcia_device *p_dev, void *priv_data)
263{
264 if (p_dev->config_index == 0)
265 return -EINVAL;
266
267 p_dev->config_index = 0x05;
268 if (p_dev->resource[0]->end + p_dev->resource[1]->end < 32)
269 return -ENODEV;
270
271 return try_io_port(p_dev);
272}
273
274static int axnet_config(struct pcmcia_device *link)
275{
276 struct net_device *dev = link->priv;
277 axnet_dev_t *info = PRIV(dev);
278 int i, j, j2, ret;
279
280 dev_dbg(&link->dev, "axnet_config(0x%p)\n", link);
281
282 /* don't trust the CIS on this; Linksys got it wrong */
283 link->config_regs = 0x63;
284 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
285 ret = pcmcia_loop_config(link, axnet_configcheck, NULL);
286 if (ret != 0)
287 goto failed;
288
289 if (!link->irq)
290 goto failed;
291
292 if (resource_size(link->resource[1]) == 8)
293 link->config_flags |= CONF_ENABLE_SPKR;
294
295 ret = pcmcia_enable_device(link);
296 if (ret)
297 goto failed;
298
299 dev->irq = link->irq;
300 dev->base_addr = link->resource[0]->start;
301
302 if (!get_prom(link)) {
303 pr_notice("this is not an AX88190 card!\n");
304 pr_notice("use pcnet_cs instead.\n");
305 goto failed;
306 }
307
308 ei_status.name = "AX88190";
309 ei_status.word16 = 1;
310 ei_status.tx_start_page = AXNET_START_PG;
311 ei_status.rx_start_page = AXNET_START_PG + TX_PAGES;
312 ei_status.stop_page = AXNET_STOP_PG;
313 ei_status.reset_8390 = axnet_reset_8390;
314 ei_status.get_8390_hdr = get_8390_hdr;
315 ei_status.block_input = block_input;
316 ei_status.block_output = block_output;
317
318 if (inb(dev->base_addr + AXNET_TEST) != 0)
319 info->flags |= IS_AX88790;
320 else
321 info->flags |= IS_AX88190;
322
323 if (info->flags & IS_AX88790)
324 outb(0x10, dev->base_addr + AXNET_GPIO); /* select Internal PHY */
325
326 info->active_low = 0;
327
328 for (i = 0; i < 32; i++) {
329 j = mdio_read(dev->base_addr + AXNET_MII_EEP, i, 1);
330 j2 = mdio_read(dev->base_addr + AXNET_MII_EEP, i, 2);
331 if (j == j2) continue;
332 if ((j != 0) && (j != 0xffff)) break;
333 }
334
335 if (i == 32) {
336 /* Maybe PHY is in power down mode. (PPD_SET = 1)
337 Bit 2 of CCSR is active low. */
338 pcmcia_write_config_byte(link, CISREG_CCSR, 0x04);
339 for (i = 0; i < 32; i++) {
340 j = mdio_read(dev->base_addr + AXNET_MII_EEP, i, 1);
341 j2 = mdio_read(dev->base_addr + AXNET_MII_EEP, i, 2);
342 if (j == j2) continue;
343 if ((j != 0) && (j != 0xffff)) {
344 info->active_low = 1;
345 break;
346 }
347 }
348 }
349
350 info->phy_id = (i < 32) ? i : -1;
351 SET_NETDEV_DEV(dev, &link->dev);
352
353 if (register_netdev(dev) != 0) {
354 pr_notice("register_netdev() failed\n");
355 goto failed;
356 }
357
358 netdev_info(dev, "Asix AX88%d90: io %#3lx, irq %d, hw_addr %pM\n",
359 ((info->flags & IS_AX88790) ? 7 : 1),
360 dev->base_addr, dev->irq, dev->dev_addr);
361 if (info->phy_id != -1) {
362 netdev_dbg(dev, " MII transceiver at index %d, status %x\n",
363 info->phy_id, j);
364 } else {
365 netdev_notice(dev, " No MII transceivers found!\n");
366 }
367 return 0;
368
369failed:
370 axnet_release(link);
371 return -ENODEV;
372} /* axnet_config */
373
374static void axnet_release(struct pcmcia_device *link)
375{
376 pcmcia_disable_device(link);
377}
378
379static int axnet_suspend(struct pcmcia_device *link)
380{
381 struct net_device *dev = link->priv;
382
383 if (link->open)
384 netif_device_detach(dev);
385
386 return 0;
387}
388
389static int axnet_resume(struct pcmcia_device *link)
390{
391 struct net_device *dev = link->priv;
392 axnet_dev_t *info = PRIV(dev);
393
394 if (link->open) {
395 if (info->active_low == 1)
396 pcmcia_write_config_byte(link, CISREG_CCSR, 0x04);
397
398 axnet_reset_8390(dev);
399 AX88190_init(dev, 1);
400 netif_device_attach(dev);
401 }
402
403 return 0;
404}
405
406
407/*======================================================================
408
409 MII interface support
410
411======================================================================*/
412
413#define MDIO_SHIFT_CLK 0x01
414#define MDIO_DATA_WRITE0 0x00
415#define MDIO_DATA_WRITE1 0x08
416#define MDIO_DATA_READ 0x04
417#define MDIO_MASK 0x0f
418#define MDIO_ENB_IN 0x02
419
420static void mdio_sync(unsigned int addr)
421{
422 int bits;
423 for (bits = 0; bits < 32; bits++) {
424 outb_p(MDIO_DATA_WRITE1, addr);
425 outb_p(MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, addr);
426 }
427}
428
429static int mdio_read(unsigned int addr, int phy_id, int loc)
430{
431 u_int cmd = (0xf6<<10)|(phy_id<<5)|loc;
432 int i, retval = 0;
433
434 mdio_sync(addr);
435 for (i = 14; i >= 0; i--) {
436 int dat = (cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
437 outb_p(dat, addr);
438 outb_p(dat | MDIO_SHIFT_CLK, addr);
439 }
440 for (i = 19; i > 0; i--) {
441 outb_p(MDIO_ENB_IN, addr);
442 retval = (retval << 1) | ((inb_p(addr) & MDIO_DATA_READ) != 0);
443 outb_p(MDIO_ENB_IN | MDIO_SHIFT_CLK, addr);
444 }
445 return (retval>>1) & 0xffff;
446}
447
448static void mdio_write(unsigned int addr, int phy_id, int loc, int value)
449{
450 u_int cmd = (0x05<<28)|(phy_id<<23)|(loc<<18)|(1<<17)|value;
451 int i;
452
453 mdio_sync(addr);
454 for (i = 31; i >= 0; i--) {
455 int dat = (cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
456 outb_p(dat, addr);
457 outb_p(dat | MDIO_SHIFT_CLK, addr);
458 }
459 for (i = 1; i >= 0; i--) {
460 outb_p(MDIO_ENB_IN, addr);
461 outb_p(MDIO_ENB_IN | MDIO_SHIFT_CLK, addr);
462 }
463}
464
465/*====================================================================*/
466
467static int axnet_open(struct net_device *dev)
468{
469 int ret;
470 axnet_dev_t *info = PRIV(dev);
471 struct pcmcia_device *link = info->p_dev;
472 unsigned int nic_base = dev->base_addr;
473
474 dev_dbg(&link->dev, "axnet_open('%s')\n", dev->name);
475
476 if (!pcmcia_dev_present(link))
477 return -ENODEV;
478
479 outb_p(0xFF, nic_base + EN0_ISR); /* Clear bogus intr. */
480 ret = request_irq(dev->irq, ei_irq_wrapper, IRQF_SHARED, "axnet_cs", dev);
481 if (ret)
482 return ret;
483
484 link->open++;
485
486 info->link_status = 0x00;
487 init_timer(&info->watchdog);
488 info->watchdog.function = ei_watchdog;
489 info->watchdog.data = (u_long)dev;
490 info->watchdog.expires = jiffies + HZ;
491 add_timer(&info->watchdog);
492
493 return ax_open(dev);
494} /* axnet_open */
495
496/*====================================================================*/
497
498static int axnet_close(struct net_device *dev)
499{
500 axnet_dev_t *info = PRIV(dev);
501 struct pcmcia_device *link = info->p_dev;
502
503 dev_dbg(&link->dev, "axnet_close('%s')\n", dev->name);
504
505 ax_close(dev);
506 free_irq(dev->irq, dev);
507
508 link->open--;
509 netif_stop_queue(dev);
510 del_timer_sync(&info->watchdog);
511
512 return 0;
513} /* axnet_close */
514
515/*======================================================================
516
517 Hard reset the card. This used to pause for the same period that
518 a 8390 reset command required, but that shouldn't be necessary.
519
520======================================================================*/
521
522static void axnet_reset_8390(struct net_device *dev)
523{
524 unsigned int nic_base = dev->base_addr;
525 int i;
526
527 ei_status.txing = ei_status.dmaing = 0;
528
529 outb_p(E8390_NODMA+E8390_PAGE0+E8390_STOP, nic_base + E8390_CMD);
530
531 outb(inb(nic_base + AXNET_RESET), nic_base + AXNET_RESET);
532
533 for (i = 0; i < 100; i++) {
534 if ((inb_p(nic_base+EN0_ISR) & ENISR_RESET) != 0)
535 break;
536 udelay(100);
537 }
538 outb_p(ENISR_RESET, nic_base + EN0_ISR); /* Ack intr. */
539
540 if (i == 100)
541 netdev_err(dev, "axnet_reset_8390() did not complete\n");
542
543} /* axnet_reset_8390 */
544
545/*====================================================================*/
546
547static irqreturn_t ei_irq_wrapper(int irq, void *dev_id)
548{
549 struct net_device *dev = dev_id;
550 PRIV(dev)->stale = 0;
551 return ax_interrupt(irq, dev_id);
552}
553
554static void ei_watchdog(u_long arg)
555{
556 struct net_device *dev = (struct net_device *)(arg);
557 axnet_dev_t *info = PRIV(dev);
558 unsigned int nic_base = dev->base_addr;
559 unsigned int mii_addr = nic_base + AXNET_MII_EEP;
560 u_short link;
561
562 if (!netif_device_present(dev)) goto reschedule;
563
564 /* Check for pending interrupt with expired latency timer: with
565 this, we can limp along even if the interrupt is blocked */
566 if (info->stale++ && (inb_p(nic_base + EN0_ISR) & ENISR_ALL)) {
567 if (!info->fast_poll)
568 netdev_info(dev, "interrupt(s) dropped!\n");
569 ei_irq_wrapper(dev->irq, dev);
570 info->fast_poll = HZ;
571 }
572 if (info->fast_poll) {
573 info->fast_poll--;
574 info->watchdog.expires = jiffies + 1;
575 add_timer(&info->watchdog);
576 return;
577 }
578
579 if (info->phy_id < 0)
580 goto reschedule;
581 link = mdio_read(mii_addr, info->phy_id, 1);
582 if (!link || (link == 0xffff)) {
583 netdev_info(dev, "MII is missing!\n");
584 info->phy_id = -1;
585 goto reschedule;
586 }
587
588 link &= 0x0004;
589 if (link != info->link_status) {
590 u_short p = mdio_read(mii_addr, info->phy_id, 5);
591 netdev_info(dev, "%s link beat\n", link ? "found" : "lost");
592 if (link) {
593 info->duplex_flag = (p & 0x0140) ? 0x80 : 0x00;
594 if (p)
595 netdev_info(dev, "autonegotiation complete: %dbaseT-%cD selected\n",
596 (p & 0x0180) ? 100 : 10, (p & 0x0140) ? 'F' : 'H');
597 else
598 netdev_info(dev, "link partner did not autonegotiate\n");
599 AX88190_init(dev, 1);
600 }
601 info->link_status = link;
602 }
603
604reschedule:
605 info->watchdog.expires = jiffies + HZ;
606 add_timer(&info->watchdog);
607}
608
609/*====================================================================*/
610
611static int axnet_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
612{
613 axnet_dev_t *info = PRIV(dev);
614 struct mii_ioctl_data *data = if_mii(rq);
615 unsigned int mii_addr = dev->base_addr + AXNET_MII_EEP;
616 switch (cmd) {
617 case SIOCGMIIPHY:
618 data->phy_id = info->phy_id;
619 case SIOCGMIIREG: /* Read MII PHY register. */
620 data->val_out = mdio_read(mii_addr, data->phy_id, data->reg_num & 0x1f);
621 return 0;
622 case SIOCSMIIREG: /* Write MII PHY register. */
623 mdio_write(mii_addr, data->phy_id, data->reg_num & 0x1f, data->val_in);
624 return 0;
625 }
626 return -EOPNOTSUPP;
627}
628
629/*====================================================================*/
630
631static void get_8390_hdr(struct net_device *dev,
632 struct e8390_pkt_hdr *hdr,
633 int ring_page)
634{
635 unsigned int nic_base = dev->base_addr;
636
637 outb_p(0, nic_base + EN0_RSARLO); /* On page boundary */
638 outb_p(ring_page, nic_base + EN0_RSARHI);
639 outb_p(E8390_RREAD+E8390_START, nic_base + AXNET_CMD);
640
641 insw(nic_base + AXNET_DATAPORT, hdr,
642 sizeof(struct e8390_pkt_hdr)>>1);
643 /* Fix for big endian systems */
644 hdr->count = le16_to_cpu(hdr->count);
645
646}
647
648/*====================================================================*/
649
650static void block_input(struct net_device *dev, int count,
651 struct sk_buff *skb, int ring_offset)
652{
653 unsigned int nic_base = dev->base_addr;
654 int xfer_count = count;
655 char *buf = skb->data;
656
657 if ((ei_debug > 4) && (count != 4))
658 pr_debug("%s: [bi=%d]\n", dev->name, count+4);
659 outb_p(ring_offset & 0xff, nic_base + EN0_RSARLO);
660 outb_p(ring_offset >> 8, nic_base + EN0_RSARHI);
661 outb_p(E8390_RREAD+E8390_START, nic_base + AXNET_CMD);
662
663 insw(nic_base + AXNET_DATAPORT,buf,count>>1);
664 if (count & 0x01)
665 buf[count-1] = inb(nic_base + AXNET_DATAPORT), xfer_count++;
666
667}
668
669/*====================================================================*/
670
671static void block_output(struct net_device *dev, int count,
672 const u_char *buf, const int start_page)
673{
674 unsigned int nic_base = dev->base_addr;
675
676 pr_debug("%s: [bo=%d]\n", dev->name, count);
677
678 /* Round the count up for word writes. Do we need to do this?
679 What effect will an odd byte count have on the 8390?
680 I should check someday. */
681 if (count & 0x01)
682 count++;
683
684 outb_p(0x00, nic_base + EN0_RSARLO);
685 outb_p(start_page, nic_base + EN0_RSARHI);
686 outb_p(E8390_RWRITE+E8390_START, nic_base + AXNET_CMD);
687 outsw(nic_base + AXNET_DATAPORT, buf, count>>1);
688}
689
690static const struct pcmcia_device_id axnet_ids[] = {
691 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x016c, 0x0081),
692 PCMCIA_DEVICE_MANF_CARD(0x018a, 0x0301),
693 PCMCIA_DEVICE_MANF_CARD(0x01bf, 0x2328),
694 PCMCIA_DEVICE_MANF_CARD(0x026f, 0x0301),
695 PCMCIA_DEVICE_MANF_CARD(0x026f, 0x0303),
696 PCMCIA_DEVICE_MANF_CARD(0x026f, 0x0309),
697 PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1106),
698 PCMCIA_DEVICE_MANF_CARD(0x8a01, 0xc1ab),
699 PCMCIA_DEVICE_MANF_CARD(0x021b, 0x0202),
700 PCMCIA_DEVICE_MANF_CARD(0xffff, 0x1090),
701 PCMCIA_DEVICE_PROD_ID12("AmbiCom,Inc.", "Fast Ethernet PC Card(AMB8110)", 0x49b020a7, 0x119cc9fc),
702 PCMCIA_DEVICE_PROD_ID124("Fast Ethernet", "16-bit PC Card", "AX88190", 0xb4be14e3, 0x9a12eb6a, 0xab9be5ef),
703 PCMCIA_DEVICE_PROD_ID12("ASIX", "AX88190", 0x0959823b, 0xab9be5ef),
704 PCMCIA_DEVICE_PROD_ID12("Billionton", "LNA-100B", 0x552ab682, 0xbc3b87e1),
705 PCMCIA_DEVICE_PROD_ID12("CHEETAH ETHERCARD", "EN2228", 0x00fa7bc8, 0x00e990cc),
706 PCMCIA_DEVICE_PROD_ID12("CNet", "CNF301", 0xbc477dde, 0x78c5f40b),
707 PCMCIA_DEVICE_PROD_ID12("corega K.K.", "corega FEther PCC-TXD", 0x5261440f, 0x436768c5),
708 PCMCIA_DEVICE_PROD_ID12("corega K.K.", "corega FEtherII PCC-TXD", 0x5261440f, 0x730df72e),
709 PCMCIA_DEVICE_PROD_ID12("corega K.K.", "corega FEther PCC-TXM", 0x5261440f, 0x3abbd061),
710 PCMCIA_DEVICE_PROD_ID12("Dynalink", "L100C16", 0x55632fd5, 0x66bc2a90),
711 PCMCIA_DEVICE_PROD_ID12("IO DATA", "ETXPCM", 0x547e66dc, 0x233adac2),
712 PCMCIA_DEVICE_PROD_ID12("Linksys", "EtherFast 10/100 PC Card (PCMPC100 V3)", 0x0733cc81, 0x232019a8),
713 PCMCIA_DEVICE_PROD_ID12("MELCO", "LPC3-TX", 0x481e0094, 0xf91af609),
714 PCMCIA_DEVICE_PROD_ID12("NETGEAR", "FA411", 0x9aa79dc3, 0x40fad875),
715 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "100BASE", 0x281f1c5d, 0x7c2add04),
716 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "FastEtherCard", 0x281f1c5d, 0x7ef26116),
717 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "FEP501", 0x281f1c5d, 0x2e272058),
718 PCMCIA_DEVICE_PROD_ID14("Network Everywhere", "AX88190", 0x820a67b6, 0xab9be5ef),
719 PCMCIA_DEVICE_NULL,
720};
721MODULE_DEVICE_TABLE(pcmcia, axnet_ids);
722
723static struct pcmcia_driver axnet_cs_driver = {
724 .owner = THIS_MODULE,
725 .name = "axnet_cs",
726 .probe = axnet_probe,
727 .remove = axnet_detach,
728 .id_table = axnet_ids,
729 .suspend = axnet_suspend,
730 .resume = axnet_resume,
731};
732
733static int __init init_axnet_cs(void)
734{
735 return pcmcia_register_driver(&axnet_cs_driver);
736}
737
738static void __exit exit_axnet_cs(void)
739{
740 pcmcia_unregister_driver(&axnet_cs_driver);
741}
742
743module_init(init_axnet_cs);
744module_exit(exit_axnet_cs);
745
746/*====================================================================*/
747
748/* 8390.c: A general NS8390 ethernet driver core for linux. */
749/*
750 Written 1992-94 by Donald Becker.
751
752 Copyright 1993 United States Government as represented by the
753 Director, National Security Agency.
754
755 This software may be used and distributed according to the terms
756 of the GNU General Public License, incorporated herein by reference.
757
758 The author may be reached as becker@scyld.com, or C/O
759 Scyld Computing Corporation
760 410 Severn Ave., Suite 210
761 Annapolis MD 21403
762
763 This is the chip-specific code for many 8390-based ethernet adaptors.
764 This is not a complete driver, it must be combined with board-specific
765 code such as ne.c, wd.c, 3c503.c, etc.
766
767 Seeing how at least eight drivers use this code, (not counting the
768 PCMCIA ones either) it is easy to break some card by what seems like
769 a simple innocent change. Please contact me or Donald if you think
770 you have found something that needs changing. -- PG
771
772 Changelog:
773
774 Paul Gortmaker : remove set_bit lock, other cleanups.
775 Paul Gortmaker : add ei_get_8390_hdr() so we can pass skb's to
776 ei_block_input() for eth_io_copy_and_sum().
777 Paul Gortmaker : exchange static int ei_pingpong for a #define,
778 also add better Tx error handling.
779 Paul Gortmaker : rewrite Rx overrun handling as per NS specs.
780 Alexey Kuznetsov : use the 8390's six bit hash multicast filter.
781 Paul Gortmaker : tweak ANK's above multicast changes a bit.
782 Paul Gortmaker : update packet statistics for v2.1.x
783 Alan Cox : support arbitrary stupid port mappings on the
784 68K Macintosh. Support >16bit I/O spaces
785 Paul Gortmaker : add kmod support for auto-loading of the 8390
786 module by all drivers that require it.
787 Alan Cox : Spinlocking work, added 'BUG_83C690'
788 Paul Gortmaker : Separate out Tx timeout code from Tx path.
789
790 Sources:
791 The National Semiconductor LAN Databook, and the 3Com 3c503 databook.
792
793 */
794
795#include <linux/bitops.h>
796#include <asm/irq.h>
797#include <linux/fcntl.h>
798#include <linux/in.h>
799#include <linux/interrupt.h>
800
801#define BUG_83C690
802
803/* These are the operational function interfaces to board-specific
804 routines.
805 void reset_8390(struct net_device *dev)
806 Resets the board associated with DEV, including a hardware reset of
807 the 8390. This is only called when there is a transmit timeout, and
808 it is always followed by 8390_init().
809 void block_output(struct net_device *dev, int count, const unsigned char *buf,
810 int start_page)
811 Write the COUNT bytes of BUF to the packet buffer at START_PAGE. The
812 "page" value uses the 8390's 256-byte pages.
813 void get_8390_hdr(struct net_device *dev, struct e8390_hdr *hdr, int ring_page)
814 Read the 4 byte, page aligned 8390 header. *If* there is a
815 subsequent read, it will be of the rest of the packet.
816 void block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset)
817 Read COUNT bytes from the packet buffer into the skb data area. Start
818 reading from RING_OFFSET, the address as the 8390 sees it. This will always
819 follow the read of the 8390 header.
820*/
821#define ei_reset_8390 (ei_local->reset_8390)
822#define ei_block_output (ei_local->block_output)
823#define ei_block_input (ei_local->block_input)
824#define ei_get_8390_hdr (ei_local->get_8390_hdr)
825
826/* use 0 for production, 1 for verification, >2 for debug */
827#ifndef ei_debug
828int ei_debug = 1;
829#endif
830
831/* Index to functions. */
832static void ei_tx_intr(struct net_device *dev);
833static void ei_tx_err(struct net_device *dev);
834static void ei_receive(struct net_device *dev);
835static void ei_rx_overrun(struct net_device *dev);
836
837/* Routines generic to NS8390-based boards. */
838static void NS8390_trigger_send(struct net_device *dev, unsigned int length,
839 int start_page);
840static void do_set_multicast_list(struct net_device *dev);
841
842/*
843 * SMP and the 8390 setup.
844 *
845 * The 8390 isn't exactly designed to be multithreaded on RX/TX. There is
846 * a page register that controls bank and packet buffer access. We guard
847 * this with ei_local->page_lock. Nobody should assume or set the page other
848 * than zero when the lock is not held. Lock holders must restore page 0
849 * before unlocking. Even pure readers must take the lock to protect in
850 * page 0.
851 *
852 * To make life difficult the chip can also be very slow. We therefore can't
853 * just use spinlocks. For the longer lockups we disable the irq the device
854 * sits on and hold the lock. We must hold the lock because there is a dual
855 * processor case other than interrupts (get stats/set multicast list in
856 * parallel with each other and transmit).
857 *
858 * Note: in theory we can just disable the irq on the card _but_ there is
859 * a latency on SMP irq delivery. So we can easily go "disable irq" "sync irqs"
860 * enter lock, take the queued irq. So we waddle instead of flying.
861 *
862 * Finally by special arrangement for the purpose of being generally
863 * annoying the transmit function is called bh atomic. That places
864 * restrictions on the user context callers as disable_irq won't save
865 * them.
866 */
867
868/**
869 * ax_open - Open/initialize the board.
870 * @dev: network device to initialize
871 *
872 * This routine goes all-out, setting everything
873 * up anew at each open, even though many of these registers should only
874 * need to be set once at boot.
875 */
876static int ax_open(struct net_device *dev)
877{
878 unsigned long flags;
879 struct ei_device *ei_local = netdev_priv(dev);
880
881 /*
882 * Grab the page lock so we own the register set, then call
883 * the init function.
884 */
885
886 spin_lock_irqsave(&ei_local->page_lock, flags);
887 AX88190_init(dev, 1);
888 /* Set the flag before we drop the lock, That way the IRQ arrives
889 after its set and we get no silly warnings */
890 netif_start_queue(dev);
891 spin_unlock_irqrestore(&ei_local->page_lock, flags);
892 ei_local->irqlock = 0;
893 return 0;
894}
895
896#define dev_lock(dev) (((struct ei_device *)netdev_priv(dev))->page_lock)
897
898/**
899 * ax_close - shut down network device
900 * @dev: network device to close
901 *
902 * Opposite of ax_open(). Only used when "ifconfig <devname> down" is done.
903 */
904static int ax_close(struct net_device *dev)
905{
906 unsigned long flags;
907
908 /*
909 * Hold the page lock during close
910 */
911
912 spin_lock_irqsave(&dev_lock(dev), flags);
913 AX88190_init(dev, 0);
914 spin_unlock_irqrestore(&dev_lock(dev), flags);
915 netif_stop_queue(dev);
916 return 0;
917}
918
919/**
920 * axnet_tx_timeout - handle transmit time out condition
921 * @dev: network device which has apparently fallen asleep
922 *
923 * Called by kernel when device never acknowledges a transmit has
924 * completed (or failed) - i.e. never posted a Tx related interrupt.
925 */
926
927static void axnet_tx_timeout(struct net_device *dev)
928{
929 long e8390_base = dev->base_addr;
930 struct ei_device *ei_local = netdev_priv(dev);
931 int txsr, isr, tickssofar = jiffies - dev_trans_start(dev);
932 unsigned long flags;
933
934 dev->stats.tx_errors++;
935
936 spin_lock_irqsave(&ei_local->page_lock, flags);
937 txsr = inb(e8390_base+EN0_TSR);
938 isr = inb(e8390_base+EN0_ISR);
939 spin_unlock_irqrestore(&ei_local->page_lock, flags);
940
941 netdev_printk(KERN_DEBUG, dev,
942 "Tx timed out, %s TSR=%#2x, ISR=%#2x, t=%d.\n",
943 (txsr & ENTSR_ABT) ? "excess collisions." :
944 (isr) ? "lost interrupt?" : "cable problem?",
945 txsr, isr, tickssofar);
946
947 if (!isr && !dev->stats.tx_packets)
948 {
949 /* The 8390 probably hasn't gotten on the cable yet. */
950 ei_local->interface_num ^= 1; /* Try a different xcvr. */
951 }
952
953 /* Ugly but a reset can be slow, yet must be protected */
954
955 spin_lock_irqsave(&ei_local->page_lock, flags);
956
957 /* Try to restart the card. Perhaps the user has fixed something. */
958 ei_reset_8390(dev);
959 AX88190_init(dev, 1);
960
961 spin_unlock_irqrestore(&ei_local->page_lock, flags);
962 netif_wake_queue(dev);
963}
964
965/**
966 * axnet_start_xmit - begin packet transmission
967 * @skb: packet to be sent
968 * @dev: network device to which packet is sent
969 *
970 * Sends a packet to an 8390 network device.
971 */
972
973static netdev_tx_t axnet_start_xmit(struct sk_buff *skb,
974 struct net_device *dev)
975{
976 long e8390_base = dev->base_addr;
977 struct ei_device *ei_local = netdev_priv(dev);
978 int length, send_length, output_page;
979 unsigned long flags;
980 u8 packet[ETH_ZLEN];
981
982 netif_stop_queue(dev);
983
984 length = skb->len;
985
986 /* Mask interrupts from the ethercard.
987 SMP: We have to grab the lock here otherwise the IRQ handler
988 on another CPU can flip window and race the IRQ mask set. We end
989 up trashing the mcast filter not disabling irqs if we don't lock */
990
991 spin_lock_irqsave(&ei_local->page_lock, flags);
992 outb_p(0x00, e8390_base + EN0_IMR);
993
994 /*
995 * Slow phase with lock held.
996 */
997
998 ei_local->irqlock = 1;
999
1000 send_length = max(length, ETH_ZLEN);
1001
1002 /*
1003 * We have two Tx slots available for use. Find the first free
1004 * slot, and then perform some sanity checks. With two Tx bufs,
1005 * you get very close to transmitting back-to-back packets. With
1006 * only one Tx buf, the transmitter sits idle while you reload the
1007 * card, leaving a substantial gap between each transmitted packet.
1008 */
1009
1010 if (ei_local->tx1 == 0)
1011 {
1012 output_page = ei_local->tx_start_page;
1013 ei_local->tx1 = send_length;
1014 if (ei_debug && ei_local->tx2 > 0)
1015 netdev_printk(KERN_DEBUG, dev,
1016 "idle transmitter tx2=%d, lasttx=%d, txing=%d\n",
1017 ei_local->tx2, ei_local->lasttx,
1018 ei_local->txing);
1019 }
1020 else if (ei_local->tx2 == 0)
1021 {
1022 output_page = ei_local->tx_start_page + TX_PAGES/2;
1023 ei_local->tx2 = send_length;
1024 if (ei_debug && ei_local->tx1 > 0)
1025 netdev_printk(KERN_DEBUG, dev,
1026 "idle transmitter, tx1=%d, lasttx=%d, txing=%d\n",
1027 ei_local->tx1, ei_local->lasttx,
1028 ei_local->txing);
1029 }
1030 else
1031 { /* We should never get here. */
1032 if (ei_debug)
1033 netdev_printk(KERN_DEBUG, dev,
1034 "No Tx buffers free! tx1=%d tx2=%d last=%d\n",
1035 ei_local->tx1, ei_local->tx2,
1036 ei_local->lasttx);
1037 ei_local->irqlock = 0;
1038 netif_stop_queue(dev);
1039 outb_p(ENISR_ALL, e8390_base + EN0_IMR);
1040 spin_unlock_irqrestore(&ei_local->page_lock, flags);
1041 dev->stats.tx_errors++;
1042 return NETDEV_TX_BUSY;
1043 }
1044
1045 /*
1046 * Okay, now upload the packet and trigger a send if the transmitter
1047 * isn't already sending. If it is busy, the interrupt handler will
1048 * trigger the send later, upon receiving a Tx done interrupt.
1049 */
1050
1051 if (length == skb->len)
1052 ei_block_output(dev, length, skb->data, output_page);
1053 else {
1054 memset(packet, 0, ETH_ZLEN);
1055 skb_copy_from_linear_data(skb, packet, skb->len);
1056 ei_block_output(dev, length, packet, output_page);
1057 }
1058
1059 if (! ei_local->txing)
1060 {
1061 ei_local->txing = 1;
1062 NS8390_trigger_send(dev, send_length, output_page);
1063 dev->trans_start = jiffies;
1064 if (output_page == ei_local->tx_start_page)
1065 {
1066 ei_local->tx1 = -1;
1067 ei_local->lasttx = -1;
1068 }
1069 else
1070 {
1071 ei_local->tx2 = -1;
1072 ei_local->lasttx = -2;
1073 }
1074 }
1075 else ei_local->txqueue++;
1076
1077 if (ei_local->tx1 && ei_local->tx2)
1078 netif_stop_queue(dev);
1079 else
1080 netif_start_queue(dev);
1081
1082 /* Turn 8390 interrupts back on. */
1083 ei_local->irqlock = 0;
1084 outb_p(ENISR_ALL, e8390_base + EN0_IMR);
1085
1086 spin_unlock_irqrestore(&ei_local->page_lock, flags);
1087
1088 dev_kfree_skb (skb);
1089 dev->stats.tx_bytes += send_length;
1090
1091 return NETDEV_TX_OK;
1092}
1093
1094/**
1095 * ax_interrupt - handle the interrupts from an 8390
1096 * @irq: interrupt number
1097 * @dev_id: a pointer to the net_device
1098 *
1099 * Handle the ether interface interrupts. We pull packets from
1100 * the 8390 via the card specific functions and fire them at the networking
1101 * stack. We also handle transmit completions and wake the transmit path if
1102 * necessary. We also update the counters and do other housekeeping as
1103 * needed.
1104 */
1105
1106static irqreturn_t ax_interrupt(int irq, void *dev_id)
1107{
1108 struct net_device *dev = dev_id;
1109 long e8390_base;
1110 int interrupts, nr_serviced = 0, i;
1111 struct ei_device *ei_local;
1112 int handled = 0;
1113 unsigned long flags;
1114
1115 e8390_base = dev->base_addr;
1116 ei_local = netdev_priv(dev);
1117
1118 /*
1119 * Protect the irq test too.
1120 */
1121
1122 spin_lock_irqsave(&ei_local->page_lock, flags);
1123
1124 if (ei_local->irqlock) {
1125#if 1 /* This might just be an interrupt for a PCI device sharing this line */
1126 const char *msg;
1127 /* The "irqlock" check is only for testing. */
1128 if (ei_local->irqlock)
1129 msg = "Interrupted while interrupts are masked!";
1130 else
1131 msg = "Reentering the interrupt handler!";
1132 netdev_info(dev, "%s, isr=%#2x imr=%#2x\n",
1133 msg,
1134 inb_p(e8390_base + EN0_ISR),
1135 inb_p(e8390_base + EN0_IMR));
1136#endif
1137 spin_unlock_irqrestore(&ei_local->page_lock, flags);
1138 return IRQ_NONE;
1139 }
1140
1141 if (ei_debug > 3)
1142 netdev_printk(KERN_DEBUG, dev, "interrupt(isr=%#2.2x)\n",
1143 inb_p(e8390_base + EN0_ISR));
1144
1145 outb_p(0x00, e8390_base + EN0_ISR);
1146 ei_local->irqlock = 1;
1147
1148 /* !!Assumption!! -- we stay in page 0. Don't break this. */
1149 while ((interrupts = inb_p(e8390_base + EN0_ISR)) != 0 &&
1150 ++nr_serviced < MAX_SERVICE)
1151 {
1152 if (!netif_running(dev) || (interrupts == 0xff)) {
1153 if (ei_debug > 1)
1154 netdev_warn(dev,
1155 "interrupt from stopped card\n");
1156 outb_p(interrupts, e8390_base + EN0_ISR);
1157 interrupts = 0;
1158 break;
1159 }
1160 handled = 1;
1161
1162 /* AX88190 bug fix. */
1163 outb_p(interrupts, e8390_base + EN0_ISR);
1164 for (i = 0; i < 10; i++) {
1165 if (!(inb(e8390_base + EN0_ISR) & interrupts))
1166 break;
1167 outb_p(0, e8390_base + EN0_ISR);
1168 outb_p(interrupts, e8390_base + EN0_ISR);
1169 }
1170 if (interrupts & ENISR_OVER)
1171 ei_rx_overrun(dev);
1172 else if (interrupts & (ENISR_RX+ENISR_RX_ERR))
1173 {
1174 /* Got a good (?) packet. */
1175 ei_receive(dev);
1176 }
1177 /* Push the next to-transmit packet through. */
1178 if (interrupts & ENISR_TX)
1179 ei_tx_intr(dev);
1180 else if (interrupts & ENISR_TX_ERR)
1181 ei_tx_err(dev);
1182
1183 if (interrupts & ENISR_COUNTERS)
1184 {
1185 dev->stats.rx_frame_errors += inb_p(e8390_base + EN0_COUNTER0);
1186 dev->stats.rx_crc_errors += inb_p(e8390_base + EN0_COUNTER1);
1187 dev->stats.rx_missed_errors+= inb_p(e8390_base + EN0_COUNTER2);
1188 }
1189 }
1190
1191 if (interrupts && ei_debug > 3)
1192 {
1193 handled = 1;
1194 if (nr_serviced >= MAX_SERVICE)
1195 {
1196 /* 0xFF is valid for a card removal */
1197 if(interrupts!=0xFF)
1198 netdev_warn(dev, "Too much work at interrupt, status %#2.2x\n",
1199 interrupts);
1200 outb_p(ENISR_ALL, e8390_base + EN0_ISR); /* Ack. most intrs. */
1201 } else {
1202 netdev_warn(dev, "unknown interrupt %#2x\n",
1203 interrupts);
1204 outb_p(0xff, e8390_base + EN0_ISR); /* Ack. all intrs. */
1205 }
1206 }
1207
1208 /* Turn 8390 interrupts back on. */
1209 ei_local->irqlock = 0;
1210 outb_p(ENISR_ALL, e8390_base + EN0_IMR);
1211
1212 spin_unlock_irqrestore(&ei_local->page_lock, flags);
1213 return IRQ_RETVAL(handled);
1214}
1215
1216/**
1217 * ei_tx_err - handle transmitter error
1218 * @dev: network device which threw the exception
1219 *
1220 * A transmitter error has happened. Most likely excess collisions (which
1221 * is a fairly normal condition). If the error is one where the Tx will
1222 * have been aborted, we try and send another one right away, instead of
1223 * letting the failed packet sit and collect dust in the Tx buffer. This
1224 * is a much better solution as it avoids kernel based Tx timeouts, and
1225 * an unnecessary card reset.
1226 *
1227 * Called with lock held.
1228 */
1229
1230static void ei_tx_err(struct net_device *dev)
1231{
1232 long e8390_base = dev->base_addr;
1233 unsigned char txsr = inb_p(e8390_base+EN0_TSR);
1234 unsigned char tx_was_aborted = txsr & (ENTSR_ABT+ENTSR_FU);
1235
1236#ifdef VERBOSE_ERROR_DUMP
1237 netdev_printk(KERN_DEBUG, dev,
1238 "transmitter error (%#2x):", txsr);
1239 if (txsr & ENTSR_ABT)
1240 pr_cont(" excess-collisions");
1241 if (txsr & ENTSR_ND)
1242 pr_cont(" non-deferral");
1243 if (txsr & ENTSR_CRS)
1244 pr_cont(" lost-carrier");
1245 if (txsr & ENTSR_FU)
1246 pr_cont(" FIFO-underrun");
1247 if (txsr & ENTSR_CDH)
1248 pr_cont(" lost-heartbeat");
1249 pr_cont("\n");
1250#endif
1251
1252 if (tx_was_aborted)
1253 ei_tx_intr(dev);
1254 else
1255 {
1256 dev->stats.tx_errors++;
1257 if (txsr & ENTSR_CRS) dev->stats.tx_carrier_errors++;
1258 if (txsr & ENTSR_CDH) dev->stats.tx_heartbeat_errors++;
1259 if (txsr & ENTSR_OWC) dev->stats.tx_window_errors++;
1260 }
1261}
1262
1263/**
1264 * ei_tx_intr - transmit interrupt handler
1265 * @dev: network device for which tx intr is handled
1266 *
1267 * We have finished a transmit: check for errors and then trigger the next
1268 * packet to be sent. Called with lock held.
1269 */
1270
1271static void ei_tx_intr(struct net_device *dev)
1272{
1273 long e8390_base = dev->base_addr;
1274 struct ei_device *ei_local = netdev_priv(dev);
1275 int status = inb(e8390_base + EN0_TSR);
1276
1277 /*
1278 * There are two Tx buffers, see which one finished, and trigger
1279 * the send of another one if it exists.
1280 */
1281 ei_local->txqueue--;
1282
1283 if (ei_local->tx1 < 0)
1284 {
1285 if (ei_local->lasttx != 1 && ei_local->lasttx != -1)
1286 netdev_err(dev, "%s: bogus last_tx_buffer %d, tx1=%d\n",
1287 ei_local->name, ei_local->lasttx,
1288 ei_local->tx1);
1289 ei_local->tx1 = 0;
1290 if (ei_local->tx2 > 0)
1291 {
1292 ei_local->txing = 1;
1293 NS8390_trigger_send(dev, ei_local->tx2, ei_local->tx_start_page + 6);
1294 dev->trans_start = jiffies;
1295 ei_local->tx2 = -1,
1296 ei_local->lasttx = 2;
1297 }
1298 else ei_local->lasttx = 20, ei_local->txing = 0;
1299 }
1300 else if (ei_local->tx2 < 0)
1301 {
1302 if (ei_local->lasttx != 2 && ei_local->lasttx != -2)
1303 netdev_info(dev, "%s: bogus last_tx_buffer %d, tx2=%d\n",
1304 ei_local->name, ei_local->lasttx,
1305 ei_local->tx2);
1306 ei_local->tx2 = 0;
1307 if (ei_local->tx1 > 0)
1308 {
1309 ei_local->txing = 1;
1310 NS8390_trigger_send(dev, ei_local->tx1, ei_local->tx_start_page);
1311 dev->trans_start = jiffies;
1312 ei_local->tx1 = -1;
1313 ei_local->lasttx = 1;
1314 }
1315 else
1316 ei_local->lasttx = 10, ei_local->txing = 0;
1317 }
1318// else
1319// netdev_warn(dev, "unexpected TX-done interrupt, lasttx=%d\n",
1320// ei_local->lasttx);
1321
1322 /* Minimize Tx latency: update the statistics after we restart TXing. */
1323 if (status & ENTSR_COL)
1324 dev->stats.collisions++;
1325 if (status & ENTSR_PTX)
1326 dev->stats.tx_packets++;
1327 else
1328 {
1329 dev->stats.tx_errors++;
1330 if (status & ENTSR_ABT)
1331 {
1332 dev->stats.tx_aborted_errors++;
1333 dev->stats.collisions += 16;
1334 }
1335 if (status & ENTSR_CRS)
1336 dev->stats.tx_carrier_errors++;
1337 if (status & ENTSR_FU)
1338 dev->stats.tx_fifo_errors++;
1339 if (status & ENTSR_CDH)
1340 dev->stats.tx_heartbeat_errors++;
1341 if (status & ENTSR_OWC)
1342 dev->stats.tx_window_errors++;
1343 }
1344 netif_wake_queue(dev);
1345}
1346
1347/**
1348 * ei_receive - receive some packets
1349 * @dev: network device with which receive will be run
1350 *
1351 * We have a good packet(s), get it/them out of the buffers.
1352 * Called with lock held.
1353 */
1354
1355static void ei_receive(struct net_device *dev)
1356{
1357 long e8390_base = dev->base_addr;
1358 struct ei_device *ei_local = netdev_priv(dev);
1359 unsigned char rxing_page, this_frame, next_frame;
1360 unsigned short current_offset;
1361 int rx_pkt_count = 0;
1362 struct e8390_pkt_hdr rx_frame;
1363
1364 while (++rx_pkt_count < 10)
1365 {
1366 int pkt_len, pkt_stat;
1367
1368 /* Get the rx page (incoming packet pointer). */
1369 rxing_page = inb_p(e8390_base + EN1_CURPAG -1);
1370
1371 /* Remove one frame from the ring. Boundary is always a page behind. */
1372 this_frame = inb_p(e8390_base + EN0_BOUNDARY) + 1;
1373 if (this_frame >= ei_local->stop_page)
1374 this_frame = ei_local->rx_start_page;
1375
1376 /* Someday we'll omit the previous, iff we never get this message.
1377 (There is at least one clone claimed to have a problem.)
1378
1379 Keep quiet if it looks like a card removal. One problem here
1380 is that some clones crash in roughly the same way.
1381 */
1382 if (ei_debug > 0 && this_frame != ei_local->current_page && (this_frame!=0x0 || rxing_page!=0xFF))
1383 netdev_err(dev, "mismatched read page pointers %2x vs %2x\n",
1384 this_frame, ei_local->current_page);
1385
1386 if (this_frame == rxing_page) /* Read all the frames? */
1387 break; /* Done for now */
1388
1389 current_offset = this_frame << 8;
1390 ei_get_8390_hdr(dev, &rx_frame, this_frame);
1391
1392 pkt_len = rx_frame.count - sizeof(struct e8390_pkt_hdr);
1393 pkt_stat = rx_frame.status;
1394
1395 next_frame = this_frame + 1 + ((pkt_len+4)>>8);
1396
1397 if (pkt_len < 60 || pkt_len > 1518)
1398 {
1399 if (ei_debug)
1400 netdev_printk(KERN_DEBUG, dev,
1401 "bogus packet size: %d, status=%#2x nxpg=%#2x\n",
1402 rx_frame.count, rx_frame.status,
1403 rx_frame.next);
1404 dev->stats.rx_errors++;
1405 dev->stats.rx_length_errors++;
1406 }
1407 else if ((pkt_stat & 0x0F) == ENRSR_RXOK)
1408 {
1409 struct sk_buff *skb;
1410
1411 skb = dev_alloc_skb(pkt_len+2);
1412 if (skb == NULL)
1413 {
1414 if (ei_debug > 1)
1415 netdev_printk(KERN_DEBUG, dev,
1416 "Couldn't allocate a sk_buff of size %d\n",
1417 pkt_len);
1418 dev->stats.rx_dropped++;
1419 break;
1420 }
1421 else
1422 {
1423 skb_reserve(skb,2); /* IP headers on 16 byte boundaries */
1424 skb_put(skb, pkt_len); /* Make room */
1425 ei_block_input(dev, pkt_len, skb, current_offset + sizeof(rx_frame));
1426 skb->protocol=eth_type_trans(skb,dev);
1427 netif_rx(skb);
1428 dev->stats.rx_packets++;
1429 dev->stats.rx_bytes += pkt_len;
1430 if (pkt_stat & ENRSR_PHY)
1431 dev->stats.multicast++;
1432 }
1433 }
1434 else
1435 {
1436 if (ei_debug)
1437 netdev_printk(KERN_DEBUG, dev,
1438 "bogus packet: status=%#2x nxpg=%#2x size=%d\n",
1439 rx_frame.status, rx_frame.next,
1440 rx_frame.count);
1441 dev->stats.rx_errors++;
1442 /* NB: The NIC counts CRC, frame and missed errors. */
1443 if (pkt_stat & ENRSR_FO)
1444 dev->stats.rx_fifo_errors++;
1445 }
1446 next_frame = rx_frame.next;
1447
1448 /* This _should_ never happen: it's here for avoiding bad clones. */
1449 if (next_frame >= ei_local->stop_page) {
1450 netdev_info(dev, "next frame inconsistency, %#2x\n",
1451 next_frame);
1452 next_frame = ei_local->rx_start_page;
1453 }
1454 ei_local->current_page = next_frame;
1455 outb_p(next_frame-1, e8390_base+EN0_BOUNDARY);
1456 }
1457}
1458
1459/**
1460 * ei_rx_overrun - handle receiver overrun
1461 * @dev: network device which threw exception
1462 *
1463 * We have a receiver overrun: we have to kick the 8390 to get it started
1464 * again. Problem is that you have to kick it exactly as NS prescribes in
1465 * the updated datasheets, or "the NIC may act in an unpredictable manner."
1466 * This includes causing "the NIC to defer indefinitely when it is stopped
1467 * on a busy network." Ugh.
1468 * Called with lock held. Don't call this with the interrupts off or your
1469 * computer will hate you - it takes 10ms or so.
1470 */
1471
1472static void ei_rx_overrun(struct net_device *dev)
1473{
1474 axnet_dev_t *info = PRIV(dev);
1475 long e8390_base = dev->base_addr;
1476 unsigned char was_txing, must_resend = 0;
1477
1478 /*
1479 * Record whether a Tx was in progress and then issue the
1480 * stop command.
1481 */
1482 was_txing = inb_p(e8390_base+E8390_CMD) & E8390_TRANS;
1483 outb_p(E8390_NODMA+E8390_PAGE0+E8390_STOP, e8390_base+E8390_CMD);
1484
1485 if (ei_debug > 1)
1486 netdev_printk(KERN_DEBUG, dev, "Receiver overrun\n");
1487 dev->stats.rx_over_errors++;
1488
1489 /*
1490 * Wait a full Tx time (1.2ms) + some guard time, NS says 1.6ms total.
1491 * We wait at least 2ms.
1492 */
1493
1494 mdelay(2);
1495
1496 /*
1497 * Reset RBCR[01] back to zero as per magic incantation.
1498 */
1499 outb_p(0x00, e8390_base+EN0_RCNTLO);
1500 outb_p(0x00, e8390_base+EN0_RCNTHI);
1501
1502 /*
1503 * See if any Tx was interrupted or not. According to NS, this
1504 * step is vital, and skipping it will cause no end of havoc.
1505 */
1506
1507 if (was_txing)
1508 {
1509 unsigned char tx_completed = inb_p(e8390_base+EN0_ISR) & (ENISR_TX+ENISR_TX_ERR);
1510 if (!tx_completed)
1511 must_resend = 1;
1512 }
1513
1514 /*
1515 * Have to enter loopback mode and then restart the NIC before
1516 * you are allowed to slurp packets up off the ring.
1517 */
1518 outb_p(E8390_TXOFF, e8390_base + EN0_TXCR);
1519 outb_p(E8390_NODMA + E8390_PAGE0 + E8390_START, e8390_base + E8390_CMD);
1520
1521 /*
1522 * Clear the Rx ring of all the debris, and ack the interrupt.
1523 */
1524 ei_receive(dev);
1525
1526 /*
1527 * Leave loopback mode, and resend any packet that got stopped.
1528 */
1529 outb_p(E8390_TXCONFIG | info->duplex_flag, e8390_base + EN0_TXCR);
1530 if (must_resend)
1531 outb_p(E8390_NODMA + E8390_PAGE0 + E8390_START + E8390_TRANS, e8390_base + E8390_CMD);
1532}
1533
1534/*
1535 * Collect the stats. This is called unlocked and from several contexts.
1536 */
1537
1538static struct net_device_stats *get_stats(struct net_device *dev)
1539{
1540 long ioaddr = dev->base_addr;
1541 struct ei_device *ei_local = netdev_priv(dev);
1542 unsigned long flags;
1543
1544 /* If the card is stopped, just return the present stats. */
1545 if (!netif_running(dev))
1546 return &dev->stats;
1547
1548 spin_lock_irqsave(&ei_local->page_lock,flags);
1549 /* Read the counter registers, assuming we are in page 0. */
1550 dev->stats.rx_frame_errors += inb_p(ioaddr + EN0_COUNTER0);
1551 dev->stats.rx_crc_errors += inb_p(ioaddr + EN0_COUNTER1);
1552 dev->stats.rx_missed_errors+= inb_p(ioaddr + EN0_COUNTER2);
1553 spin_unlock_irqrestore(&ei_local->page_lock, flags);
1554
1555 return &dev->stats;
1556}
1557
1558/*
1559 * Form the 64 bit 8390 multicast table from the linked list of addresses
1560 * associated with this dev structure.
1561 */
1562
1563static inline void make_mc_bits(u8 *bits, struct net_device *dev)
1564{
1565 struct netdev_hw_addr *ha;
1566 u32 crc;
1567
1568 netdev_for_each_mc_addr(ha, dev) {
1569 crc = ether_crc(ETH_ALEN, ha->addr);
1570 /*
1571 * The 8390 uses the 6 most significant bits of the
1572 * CRC to index the multicast table.
1573 */
1574 bits[crc>>29] |= (1<<((crc>>26)&7));
1575 }
1576}
1577
1578/**
1579 * do_set_multicast_list - set/clear multicast filter
1580 * @dev: net device for which multicast filter is adjusted
1581 *
1582 * Set or clear the multicast filter for this adaptor.
1583 * Must be called with lock held.
1584 */
1585
1586static void do_set_multicast_list(struct net_device *dev)
1587{
1588 long e8390_base = dev->base_addr;
1589 int i;
1590 struct ei_device *ei_local = netdev_priv(dev);
1591
1592 if (!(dev->flags&(IFF_PROMISC|IFF_ALLMULTI))) {
1593 memset(ei_local->mcfilter, 0, 8);
1594 if (!netdev_mc_empty(dev))
1595 make_mc_bits(ei_local->mcfilter, dev);
1596 } else {
1597 /* set to accept-all */
1598 memset(ei_local->mcfilter, 0xFF, 8);
1599 }
1600
1601 outb_p(E8390_NODMA + E8390_PAGE1, e8390_base + E8390_CMD);
1602 for(i = 0; i < 8; i++)
1603 {
1604 outb_p(ei_local->mcfilter[i], e8390_base + EN1_MULT_SHIFT(i));
1605 }
1606 outb_p(E8390_NODMA + E8390_PAGE0, e8390_base + E8390_CMD);
1607
1608 if(dev->flags&IFF_PROMISC)
1609 outb_p(E8390_RXCONFIG | 0x58, e8390_base + EN0_RXCR);
1610 else if (dev->flags & IFF_ALLMULTI || !netdev_mc_empty(dev))
1611 outb_p(E8390_RXCONFIG | 0x48, e8390_base + EN0_RXCR);
1612 else
1613 outb_p(E8390_RXCONFIG | 0x40, e8390_base + EN0_RXCR);
1614
1615 outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, e8390_base+E8390_CMD);
1616}
1617
1618/*
1619 * Called without lock held. This is invoked from user context and may
1620 * be parallel to just about everything else. Its also fairly quick and
1621 * not called too often. Must protect against both bh and irq users
1622 */
1623
1624static void set_multicast_list(struct net_device *dev)
1625{
1626 unsigned long flags;
1627
1628 spin_lock_irqsave(&dev_lock(dev), flags);
1629 do_set_multicast_list(dev);
1630 spin_unlock_irqrestore(&dev_lock(dev), flags);
1631}
1632
1633/* This page of functions should be 8390 generic */
1634/* Follow National Semi's recommendations for initializing the "NIC". */
1635
1636/**
1637 * AX88190_init - initialize 8390 hardware
1638 * @dev: network device to initialize
1639 * @startp: boolean. non-zero value to initiate chip processing
1640 *
1641 * Must be called with lock held.
1642 */
1643
1644static void AX88190_init(struct net_device *dev, int startp)
1645{
1646 axnet_dev_t *info = PRIV(dev);
1647 long e8390_base = dev->base_addr;
1648 struct ei_device *ei_local = netdev_priv(dev);
1649 int i;
1650 int endcfg = ei_local->word16 ? (0x48 | ENDCFG_WTS) : 0x48;
1651
1652 if(sizeof(struct e8390_pkt_hdr)!=4)
1653 panic("8390.c: header struct mispacked\n");
1654 /* Follow National Semi's recommendations for initing the DP83902. */
1655 outb_p(E8390_NODMA+E8390_PAGE0+E8390_STOP, e8390_base+E8390_CMD); /* 0x21 */
1656 outb_p(endcfg, e8390_base + EN0_DCFG); /* 0x48 or 0x49 */
1657 /* Clear the remote byte count registers. */
1658 outb_p(0x00, e8390_base + EN0_RCNTLO);
1659 outb_p(0x00, e8390_base + EN0_RCNTHI);
1660 /* Set to monitor and loopback mode -- this is vital!. */
1661 outb_p(E8390_RXOFF|0x40, e8390_base + EN0_RXCR); /* 0x60 */
1662 outb_p(E8390_TXOFF, e8390_base + EN0_TXCR); /* 0x02 */
1663 /* Set the transmit page and receive ring. */
1664 outb_p(ei_local->tx_start_page, e8390_base + EN0_TPSR);
1665 ei_local->tx1 = ei_local->tx2 = 0;
1666 outb_p(ei_local->rx_start_page, e8390_base + EN0_STARTPG);
1667 outb_p(ei_local->stop_page-1, e8390_base + EN0_BOUNDARY); /* 3c503 says 0x3f,NS0x26*/
1668 ei_local->current_page = ei_local->rx_start_page; /* assert boundary+1 */
1669 outb_p(ei_local->stop_page, e8390_base + EN0_STOPPG);
1670 /* Clear the pending interrupts and mask. */
1671 outb_p(0xFF, e8390_base + EN0_ISR);
1672 outb_p(0x00, e8390_base + EN0_IMR);
1673
1674 /* Copy the station address into the DS8390 registers. */
1675
1676 outb_p(E8390_NODMA + E8390_PAGE1 + E8390_STOP, e8390_base+E8390_CMD); /* 0x61 */
1677 for(i = 0; i < 6; i++)
1678 {
1679 outb_p(dev->dev_addr[i], e8390_base + EN1_PHYS_SHIFT(i));
1680 if(inb_p(e8390_base + EN1_PHYS_SHIFT(i))!=dev->dev_addr[i])
1681 netdev_err(dev, "Hw. address read/write mismap %d\n", i);
1682 }
1683
1684 outb_p(ei_local->rx_start_page, e8390_base + EN1_CURPAG);
1685 outb_p(E8390_NODMA+E8390_PAGE0+E8390_STOP, e8390_base+E8390_CMD);
1686
1687 netif_start_queue(dev);
1688 ei_local->tx1 = ei_local->tx2 = 0;
1689 ei_local->txing = 0;
1690
1691 if (info->flags & IS_AX88790) /* select Internal PHY */
1692 outb(0x10, e8390_base + AXNET_GPIO);
1693
1694 if (startp)
1695 {
1696 outb_p(0xff, e8390_base + EN0_ISR);
1697 outb_p(ENISR_ALL, e8390_base + EN0_IMR);
1698 outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, e8390_base+E8390_CMD);
1699 outb_p(E8390_TXCONFIG | info->duplex_flag,
1700 e8390_base + EN0_TXCR); /* xmit on. */
1701 /* 3c503 TechMan says rxconfig only after the NIC is started. */
1702 outb_p(E8390_RXCONFIG | 0x40, e8390_base + EN0_RXCR); /* rx on, */
1703 do_set_multicast_list(dev); /* (re)load the mcast table */
1704 }
1705}
1706
1707/* Trigger a transmit start, assuming the length is valid.
1708 Always called with the page lock held */
1709
1710static void NS8390_trigger_send(struct net_device *dev, unsigned int length,
1711 int start_page)
1712{
1713 long e8390_base = dev->base_addr;
1714 struct ei_device *ei_local __attribute((unused)) = netdev_priv(dev);
1715
1716 if (inb_p(e8390_base) & E8390_TRANS)
1717 {
1718 netdev_warn(dev, "trigger_send() called with the transmitter busy\n");
1719 return;
1720 }
1721 outb_p(length & 0xff, e8390_base + EN0_TCNTLO);
1722 outb_p(length >> 8, e8390_base + EN0_TCNTHI);
1723 outb_p(start_page, e8390_base + EN0_TPSR);
1724 outb_p(E8390_NODMA+E8390_TRANS+E8390_START, e8390_base+E8390_CMD);
1725}
diff --git a/drivers/net/pcmcia/com20020_cs.c b/drivers/net/pcmcia/com20020_cs.c
new file mode 100644
index 00000000000..980e65c1493
--- /dev/null
+++ b/drivers/net/pcmcia/com20020_cs.c
@@ -0,0 +1,349 @@
1/*
2 * Linux ARCnet driver - COM20020 PCMCIA support
3 *
4 * Written 1994-1999 by Avery Pennarun,
5 * based on an ISA version by David Woodhouse.
6 * Derived from ibmtr_cs.c by Steve Kipisz (pcmcia-cs 3.1.4)
7 * which was derived from pcnet_cs.c by David Hinds.
8 * Some additional portions derived from skeleton.c by Donald Becker.
9 *
10 * Special thanks to Contemporary Controls, Inc. (www.ccontrols.com)
11 * for sponsoring the further development of this driver.
12 *
13 * **********************
14 *
15 * The original copyright of skeleton.c was as follows:
16 *
17 * skeleton.c Written 1993 by Donald Becker.
18 * Copyright 1993 United States Government as represented by the
19 * Director, National Security Agency. This software may only be used
20 * and distributed according to the terms of the GNU General Public License as
21 * modified by SRC, incorporated herein by reference.
22 *
23 * **********************
24 * Changes:
25 * Arnaldo Carvalho de Melo <acme@conectiva.com.br> - 08/08/2000
26 * - reorganize kmallocs in com20020_attach, checking all for failure
27 * and releasing the previous allocations if one fails
28 * **********************
29 *
30 * For more details, see drivers/net/arcnet.c
31 *
32 * **********************
33 */
34#include <linux/kernel.h>
35#include <linux/init.h>
36#include <linux/ptrace.h>
37#include <linux/slab.h>
38#include <linux/string.h>
39#include <linux/timer.h>
40#include <linux/delay.h>
41#include <linux/module.h>
42#include <linux/netdevice.h>
43#include <linux/arcdevice.h>
44#include <linux/com20020.h>
45
46#include <pcmcia/cistpl.h>
47#include <pcmcia/ds.h>
48
49#include <asm/io.h>
50#include <asm/system.h>
51
52#define VERSION "arcnet: COM20020 PCMCIA support loaded.\n"
53
54
55static void regdump(struct net_device *dev)
56{
57#ifdef DEBUG
58 int ioaddr = dev->base_addr;
59 int count;
60
61 netdev_dbg(dev, "register dump:\n");
62 for (count = ioaddr; count < ioaddr + 16; count++)
63 {
64 if (!(count % 16))
65 pr_cont("%04X:", count);
66 pr_cont(" %02X", inb(count));
67 }
68 pr_cont("\n");
69
70 netdev_dbg(dev, "buffer0 dump:\n");
71 /* set up the address register */
72 count = 0;
73 outb((count >> 8) | RDDATAflag | AUTOINCflag, _ADDR_HI);
74 outb(count & 0xff, _ADDR_LO);
75
76 for (count = 0; count < 256+32; count++)
77 {
78 if (!(count % 16))
79 pr_cont("%04X:", count);
80
81 /* copy the data */
82 pr_cont(" %02X", inb(_MEMDATA));
83 }
84 pr_cont("\n");
85#endif
86}
87
88
89
90/*====================================================================*/
91
92/* Parameters that can be set with 'insmod' */
93
94static int node;
95static int timeout = 3;
96static int backplane;
97static int clockp;
98static int clockm;
99
100module_param(node, int, 0);
101module_param(timeout, int, 0);
102module_param(backplane, int, 0);
103module_param(clockp, int, 0);
104module_param(clockm, int, 0);
105
106MODULE_LICENSE("GPL");
107
108/*====================================================================*/
109
110static int com20020_config(struct pcmcia_device *link);
111static void com20020_release(struct pcmcia_device *link);
112
113static void com20020_detach(struct pcmcia_device *p_dev);
114
115/*====================================================================*/
116
117typedef struct com20020_dev_t {
118 struct net_device *dev;
119} com20020_dev_t;
120
121static int com20020_probe(struct pcmcia_device *p_dev)
122{
123 com20020_dev_t *info;
124 struct net_device *dev;
125 struct arcnet_local *lp;
126
127 dev_dbg(&p_dev->dev, "com20020_attach()\n");
128
129 /* Create new network device */
130 info = kzalloc(sizeof(struct com20020_dev_t), GFP_KERNEL);
131 if (!info)
132 goto fail_alloc_info;
133
134 dev = alloc_arcdev("");
135 if (!dev)
136 goto fail_alloc_dev;
137
138 lp = netdev_priv(dev);
139 lp->timeout = timeout;
140 lp->backplane = backplane;
141 lp->clockp = clockp;
142 lp->clockm = clockm & 3;
143 lp->hw.owner = THIS_MODULE;
144
145 /* fill in our module parameters as defaults */
146 dev->dev_addr[0] = node;
147
148 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
149 p_dev->resource[0]->end = 16;
150 p_dev->config_flags |= CONF_ENABLE_IRQ;
151
152 info->dev = dev;
153 p_dev->priv = info;
154
155 return com20020_config(p_dev);
156
157fail_alloc_dev:
158 kfree(info);
159fail_alloc_info:
160 return -ENOMEM;
161} /* com20020_attach */
162
163static void com20020_detach(struct pcmcia_device *link)
164{
165 struct com20020_dev_t *info = link->priv;
166 struct net_device *dev = info->dev;
167
168 dev_dbg(&link->dev, "detach...\n");
169
170 dev_dbg(&link->dev, "com20020_detach\n");
171
172 dev_dbg(&link->dev, "unregister...\n");
173
174 unregister_netdev(dev);
175
176 /*
177 * this is necessary because we register our IRQ separately
178 * from card services.
179 */
180 if (dev->irq)
181 free_irq(dev->irq, dev);
182
183 com20020_release(link);
184
185 /* Unlink device structure, free bits */
186 dev_dbg(&link->dev, "unlinking...\n");
187 if (link->priv)
188 {
189 dev = info->dev;
190 if (dev)
191 {
192 dev_dbg(&link->dev, "kfree...\n");
193 free_netdev(dev);
194 }
195 dev_dbg(&link->dev, "kfree2...\n");
196 kfree(info);
197 }
198
199} /* com20020_detach */
200
201static int com20020_config(struct pcmcia_device *link)
202{
203 struct arcnet_local *lp;
204 com20020_dev_t *info;
205 struct net_device *dev;
206 int i, ret;
207 int ioaddr;
208
209 info = link->priv;
210 dev = info->dev;
211
212 dev_dbg(&link->dev, "config...\n");
213
214 dev_dbg(&link->dev, "com20020_config\n");
215
216 dev_dbg(&link->dev, "baseport1 is %Xh\n",
217 (unsigned int) link->resource[0]->start);
218
219 i = -ENODEV;
220 link->io_lines = 16;
221
222 if (!link->resource[0]->start)
223 {
224 for (ioaddr = 0x100; ioaddr < 0x400; ioaddr += 0x10)
225 {
226 link->resource[0]->start = ioaddr;
227 i = pcmcia_request_io(link);
228 if (i == 0)
229 break;
230 }
231 }
232 else
233 i = pcmcia_request_io(link);
234
235 if (i != 0)
236 {
237 dev_dbg(&link->dev, "requestIO failed totally!\n");
238 goto failed;
239 }
240
241 ioaddr = dev->base_addr = link->resource[0]->start;
242 dev_dbg(&link->dev, "got ioaddr %Xh\n", ioaddr);
243
244 dev_dbg(&link->dev, "request IRQ %d\n",
245 link->irq);
246 if (!link->irq)
247 {
248 dev_dbg(&link->dev, "requestIRQ failed totally!\n");
249 goto failed;
250 }
251
252 dev->irq = link->irq;
253
254 ret = pcmcia_enable_device(link);
255 if (ret)
256 goto failed;
257
258 if (com20020_check(dev))
259 {
260 regdump(dev);
261 goto failed;
262 }
263
264 lp = netdev_priv(dev);
265 lp->card_name = "PCMCIA COM20020";
266 lp->card_flags = ARC_CAN_10MBIT; /* pretend all of them can 10Mbit */
267
268 SET_NETDEV_DEV(dev, &link->dev);
269
270 i = com20020_found(dev, 0); /* calls register_netdev */
271
272 if (i != 0) {
273 dev_notice(&link->dev,
274 "com20020_found() failed\n");
275 goto failed;
276 }
277
278 netdev_dbg(dev, "port %#3lx, irq %d\n",
279 dev->base_addr, dev->irq);
280 return 0;
281
282failed:
283 dev_dbg(&link->dev, "com20020_config failed...\n");
284 com20020_release(link);
285 return -ENODEV;
286} /* com20020_config */
287
288static void com20020_release(struct pcmcia_device *link)
289{
290 dev_dbg(&link->dev, "com20020_release\n");
291 pcmcia_disable_device(link);
292}
293
294static int com20020_suspend(struct pcmcia_device *link)
295{
296 com20020_dev_t *info = link->priv;
297 struct net_device *dev = info->dev;
298
299 if (link->open)
300 netif_device_detach(dev);
301
302 return 0;
303}
304
305static int com20020_resume(struct pcmcia_device *link)
306{
307 com20020_dev_t *info = link->priv;
308 struct net_device *dev = info->dev;
309
310 if (link->open) {
311 int ioaddr = dev->base_addr;
312 struct arcnet_local *lp = netdev_priv(dev);
313 ARCRESET;
314 }
315
316 return 0;
317}
318
319static const struct pcmcia_device_id com20020_ids[] = {
320 PCMCIA_DEVICE_PROD_ID12("Contemporary Control Systems, Inc.",
321 "PCM20 Arcnet Adapter", 0x59991666, 0x95dfffaf),
322 PCMCIA_DEVICE_PROD_ID12("SoHard AG",
323 "SH ARC PCMCIA", 0xf8991729, 0x69dff0c7),
324 PCMCIA_DEVICE_NULL
325};
326MODULE_DEVICE_TABLE(pcmcia, com20020_ids);
327
328static struct pcmcia_driver com20020_cs_driver = {
329 .owner = THIS_MODULE,
330 .name = "com20020_cs",
331 .probe = com20020_probe,
332 .remove = com20020_detach,
333 .id_table = com20020_ids,
334 .suspend = com20020_suspend,
335 .resume = com20020_resume,
336};
337
338static int __init init_com20020_cs(void)
339{
340 return pcmcia_register_driver(&com20020_cs_driver);
341}
342
343static void __exit exit_com20020_cs(void)
344{
345 pcmcia_unregister_driver(&com20020_cs_driver);
346}
347
348module_init(init_com20020_cs);
349module_exit(exit_com20020_cs);
diff --git a/drivers/net/pcmcia/fmvj18x_cs.c b/drivers/net/pcmcia/fmvj18x_cs.c
new file mode 100644
index 00000000000..723815e7a99
--- /dev/null
+++ b/drivers/net/pcmcia/fmvj18x_cs.c
@@ -0,0 +1,1187 @@
1/*======================================================================
2 fmvj18x_cs.c 2.8 2002/03/23
3
4 A fmvj18x (and its compatibles) PCMCIA client driver
5
6 Contributed by Shingo Fujimoto, shingo@flab.fujitsu.co.jp
7
8 TDK LAK-CD021 and CONTEC C-NET(PC)C support added by
9 Nobuhiro Katayama, kata-n@po.iijnet.or.jp
10
11 The PCMCIA client code is based on code written by David Hinds.
12 Network code is based on the "FMV-18x driver" by Yutaka TAMIYA
13 but is actually largely Donald Becker's AT1700 driver, which
14 carries the following attribution:
15
16 Written 1993-94 by Donald Becker.
17
18 Copyright 1993 United States Government as represented by the
19 Director, National Security Agency.
20
21 This software may be used and distributed according to the terms
22 of the GNU General Public License, incorporated herein by reference.
23
24 The author may be reached as becker@scyld.com, or C/O
25 Scyld Computing Corporation
26 410 Severn Ave., Suite 210
27 Annapolis MD 21403
28
29======================================================================*/
30
31#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
32
33#define DRV_NAME "fmvj18x_cs"
34#define DRV_VERSION "2.9"
35
36#include <linux/module.h>
37#include <linux/kernel.h>
38#include <linux/init.h>
39#include <linux/ptrace.h>
40#include <linux/slab.h>
41#include <linux/string.h>
42#include <linux/timer.h>
43#include <linux/interrupt.h>
44#include <linux/in.h>
45#include <linux/delay.h>
46#include <linux/ethtool.h>
47#include <linux/netdevice.h>
48#include <linux/etherdevice.h>
49#include <linux/skbuff.h>
50#include <linux/if_arp.h>
51#include <linux/ioport.h>
52#include <linux/crc32.h>
53
54#include <pcmcia/cistpl.h>
55#include <pcmcia/ciscode.h>
56#include <pcmcia/ds.h>
57
58#include <asm/uaccess.h>
59#include <asm/io.h>
60#include <asm/system.h>
61
62/*====================================================================*/
63
64/* Module parameters */
65
66MODULE_DESCRIPTION("fmvj18x and compatible PCMCIA ethernet driver");
67MODULE_LICENSE("GPL");
68
69#define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0)
70
71/* SRAM configuration */
72/* 0:4KB*2 TX buffer else:8KB*2 TX buffer */
73INT_MODULE_PARM(sram_config, 0);
74
75
76/*====================================================================*/
77/*
78 PCMCIA event handlers
79 */
80static int fmvj18x_config(struct pcmcia_device *link);
81static int fmvj18x_get_hwinfo(struct pcmcia_device *link, u_char *node_id);
82static int fmvj18x_setup_mfc(struct pcmcia_device *link);
83static void fmvj18x_release(struct pcmcia_device *link);
84static void fmvj18x_detach(struct pcmcia_device *p_dev);
85
86/*
87 LAN controller(MBH86960A) specific routines
88 */
89static int fjn_config(struct net_device *dev, struct ifmap *map);
90static int fjn_open(struct net_device *dev);
91static int fjn_close(struct net_device *dev);
92static netdev_tx_t fjn_start_xmit(struct sk_buff *skb,
93 struct net_device *dev);
94static irqreturn_t fjn_interrupt(int irq, void *dev_id);
95static void fjn_rx(struct net_device *dev);
96static void fjn_reset(struct net_device *dev);
97static void set_rx_mode(struct net_device *dev);
98static void fjn_tx_timeout(struct net_device *dev);
99static const struct ethtool_ops netdev_ethtool_ops;
100
101/*
102 card type
103 */
104typedef enum { MBH10302, MBH10304, TDK, CONTEC, LA501, UNGERMANN,
105 XXX10304, NEC, KME
106} cardtype_t;
107
108/*
109 driver specific data structure
110*/
111typedef struct local_info_t {
112 struct pcmcia_device *p_dev;
113 long open_time;
114 uint tx_started:1;
115 uint tx_queue;
116 u_short tx_queue_len;
117 cardtype_t cardtype;
118 u_short sent;
119 u_char __iomem *base;
120} local_info_t;
121
122#define MC_FILTERBREAK 64
123
124/*====================================================================*/
125/*
126 ioport offset from the base address
127 */
128#define TX_STATUS 0 /* transmit status register */
129#define RX_STATUS 1 /* receive status register */
130#define TX_INTR 2 /* transmit interrupt mask register */
131#define RX_INTR 3 /* receive interrupt mask register */
132#define TX_MODE 4 /* transmit mode register */
133#define RX_MODE 5 /* receive mode register */
134#define CONFIG_0 6 /* configuration register 0 */
135#define CONFIG_1 7 /* configuration register 1 */
136
137#define NODE_ID 8 /* node ID register (bank 0) */
138#define MAR_ADR 8 /* multicast address registers (bank 1) */
139
140#define DATAPORT 8 /* buffer mem port registers (bank 2) */
141#define TX_START 10 /* transmit start register */
142#define COL_CTRL 11 /* 16 collision control register */
143#define BMPR12 12 /* reserved */
144#define BMPR13 13 /* reserved */
145#define RX_SKIP 14 /* skip received packet register */
146
147#define LAN_CTRL 16 /* LAN card control register */
148
149#define MAC_ID 0x1a /* hardware address */
150#define UNGERMANN_MAC_ID 0x18 /* UNGERMANN-BASS hardware address */
151
152/*
153 control bits
154 */
155#define ENA_TMT_OK 0x80
156#define ENA_TMT_REC 0x20
157#define ENA_COL 0x04
158#define ENA_16_COL 0x02
159#define ENA_TBUS_ERR 0x01
160
161#define ENA_PKT_RDY 0x80
162#define ENA_BUS_ERR 0x40
163#define ENA_LEN_ERR 0x08
164#define ENA_ALG_ERR 0x04
165#define ENA_CRC_ERR 0x02
166#define ENA_OVR_FLO 0x01
167
168/* flags */
169#define F_TMT_RDY 0x80 /* can accept new packet */
170#define F_NET_BSY 0x40 /* carrier is detected */
171#define F_TMT_OK 0x20 /* send packet successfully */
172#define F_SRT_PKT 0x10 /* short packet error */
173#define F_COL_ERR 0x04 /* collision error */
174#define F_16_COL 0x02 /* 16 collision error */
175#define F_TBUS_ERR 0x01 /* bus read error */
176
177#define F_PKT_RDY 0x80 /* packet(s) in buffer */
178#define F_BUS_ERR 0x40 /* bus read error */
179#define F_LEN_ERR 0x08 /* short packet */
180#define F_ALG_ERR 0x04 /* frame error */
181#define F_CRC_ERR 0x02 /* CRC error */
182#define F_OVR_FLO 0x01 /* overflow error */
183
184#define F_BUF_EMP 0x40 /* receive buffer is empty */
185
186#define F_SKP_PKT 0x05 /* drop packet in buffer */
187
188/* default bitmaps */
189#define D_TX_INTR ( ENA_TMT_OK )
190#define D_RX_INTR ( ENA_PKT_RDY | ENA_LEN_ERR \
191 | ENA_ALG_ERR | ENA_CRC_ERR | ENA_OVR_FLO )
192#define TX_STAT_M ( F_TMT_RDY )
193#define RX_STAT_M ( F_PKT_RDY | F_LEN_ERR \
194 | F_ALG_ERR | F_CRC_ERR | F_OVR_FLO )
195
196/* commands */
197#define D_TX_MODE 0x06 /* no tests, detect carrier */
198#define ID_MATCHED 0x02 /* (RX_MODE) */
199#define RECV_ALL 0x03 /* (RX_MODE) */
200#define CONFIG0_DFL 0x5a /* 16bit bus, 4K x 2 Tx queues */
201#define CONFIG0_DFL_1 0x5e /* 16bit bus, 8K x 2 Tx queues */
202#define CONFIG0_RST 0xda /* Data Link Controller off (CONFIG_0) */
203#define CONFIG0_RST_1 0xde /* Data Link Controller off (CONFIG_0) */
204#define BANK_0 0xa0 /* bank 0 (CONFIG_1) */
205#define BANK_1 0xa4 /* bank 1 (CONFIG_1) */
206#define BANK_2 0xa8 /* bank 2 (CONFIG_1) */
207#define CHIP_OFF 0x80 /* contrl chip power off (CONFIG_1) */
208#define DO_TX 0x80 /* do transmit packet */
209#define SEND_PKT 0x81 /* send a packet */
210#define AUTO_MODE 0x07 /* Auto skip packet on 16 col detected */
211#define MANU_MODE 0x03 /* Stop and skip packet on 16 col */
212#define TDK_AUTO_MODE 0x47 /* Auto skip packet on 16 col detected */
213#define TDK_MANU_MODE 0x43 /* Stop and skip packet on 16 col */
214#define INTR_OFF 0x0d /* LAN controller ignores interrupts */
215#define INTR_ON 0x1d /* LAN controller will catch interrupts */
216
217#define TX_TIMEOUT ((400*HZ)/1000)
218
219#define BANK_0U 0x20 /* bank 0 (CONFIG_1) */
220#define BANK_1U 0x24 /* bank 1 (CONFIG_1) */
221#define BANK_2U 0x28 /* bank 2 (CONFIG_1) */
222
223static const struct net_device_ops fjn_netdev_ops = {
224 .ndo_open = fjn_open,
225 .ndo_stop = fjn_close,
226 .ndo_start_xmit = fjn_start_xmit,
227 .ndo_tx_timeout = fjn_tx_timeout,
228 .ndo_set_config = fjn_config,
229 .ndo_set_multicast_list = set_rx_mode,
230 .ndo_change_mtu = eth_change_mtu,
231 .ndo_set_mac_address = eth_mac_addr,
232 .ndo_validate_addr = eth_validate_addr,
233};
234
235static int fmvj18x_probe(struct pcmcia_device *link)
236{
237 local_info_t *lp;
238 struct net_device *dev;
239
240 dev_dbg(&link->dev, "fmvj18x_attach()\n");
241
242 /* Make up a FMVJ18x specific data structure */
243 dev = alloc_etherdev(sizeof(local_info_t));
244 if (!dev)
245 return -ENOMEM;
246 lp = netdev_priv(dev);
247 link->priv = dev;
248 lp->p_dev = link;
249 lp->base = NULL;
250
251 /* The io structure describes IO port mapping */
252 link->resource[0]->end = 32;
253 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
254
255 /* General socket configuration */
256 link->config_flags |= CONF_ENABLE_IRQ;
257
258 dev->netdev_ops = &fjn_netdev_ops;
259 dev->watchdog_timeo = TX_TIMEOUT;
260
261 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
262
263 return fmvj18x_config(link);
264} /* fmvj18x_attach */
265
266/*====================================================================*/
267
268static void fmvj18x_detach(struct pcmcia_device *link)
269{
270 struct net_device *dev = link->priv;
271
272 dev_dbg(&link->dev, "fmvj18x_detach\n");
273
274 unregister_netdev(dev);
275
276 fmvj18x_release(link);
277
278 free_netdev(dev);
279} /* fmvj18x_detach */
280
281/*====================================================================*/
282
283static int mfc_try_io_port(struct pcmcia_device *link)
284{
285 int i, ret;
286 static const unsigned int serial_base[5] =
287 { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
288
289 for (i = 0; i < 5; i++) {
290 link->resource[1]->start = serial_base[i];
291 link->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
292 if (link->resource[1]->start == 0) {
293 link->resource[1]->end = 0;
294 pr_notice("out of resource for serial\n");
295 }
296 ret = pcmcia_request_io(link);
297 if (ret == 0)
298 return ret;
299 }
300 return ret;
301}
302
303static int ungermann_try_io_port(struct pcmcia_device *link)
304{
305 int ret;
306 unsigned int ioaddr;
307 /*
308 Ungermann-Bass Access/CARD accepts 0x300,0x320,0x340,0x360
309 0x380,0x3c0 only for ioport.
310 */
311 for (ioaddr = 0x300; ioaddr < 0x3e0; ioaddr += 0x20) {
312 link->resource[0]->start = ioaddr;
313 ret = pcmcia_request_io(link);
314 if (ret == 0) {
315 /* calculate ConfigIndex value */
316 link->config_index =
317 ((link->resource[0]->start & 0x0f0) >> 3) | 0x22;
318 return ret;
319 }
320 }
321 return ret; /* RequestIO failed */
322}
323
324static int fmvj18x_ioprobe(struct pcmcia_device *p_dev, void *priv_data)
325{
326 return 0; /* strange, but that's what the code did already before... */
327}
328
329static int fmvj18x_config(struct pcmcia_device *link)
330{
331 struct net_device *dev = link->priv;
332 local_info_t *lp = netdev_priv(dev);
333 int i, ret;
334 unsigned int ioaddr;
335 cardtype_t cardtype;
336 char *card_name = "unknown";
337 u8 *buf;
338 size_t len;
339 u_char buggybuf[32];
340
341 dev_dbg(&link->dev, "fmvj18x_config\n");
342
343 link->io_lines = 5;
344
345 len = pcmcia_get_tuple(link, CISTPL_FUNCE, &buf);
346 kfree(buf);
347
348 if (len) {
349 /* Yes, I have CISTPL_FUNCE. Let's check CISTPL_MANFID */
350 ret = pcmcia_loop_config(link, fmvj18x_ioprobe, NULL);
351 if (ret != 0)
352 goto failed;
353
354 switch (link->manf_id) {
355 case MANFID_TDK:
356 cardtype = TDK;
357 if (link->card_id == PRODID_TDK_GN3410 ||
358 link->card_id == PRODID_TDK_NP9610 ||
359 link->card_id == PRODID_TDK_MN3200) {
360 /* MultiFunction Card */
361 link->config_base = 0x800;
362 link->config_index = 0x47;
363 link->resource[1]->end = 8;
364 }
365 break;
366 case MANFID_NEC:
367 cardtype = NEC; /* MultiFunction Card */
368 link->config_base = 0x800;
369 link->config_index = 0x47;
370 link->resource[1]->end = 8;
371 break;
372 case MANFID_KME:
373 cardtype = KME; /* MultiFunction Card */
374 link->config_base = 0x800;
375 link->config_index = 0x47;
376 link->resource[1]->end = 8;
377 break;
378 case MANFID_CONTEC:
379 cardtype = CONTEC;
380 break;
381 case MANFID_FUJITSU:
382 if (link->config_base == 0x0fe0)
383 cardtype = MBH10302;
384 else if (link->card_id == PRODID_FUJITSU_MBH10302)
385 /* RATOC REX-5588/9822/4886's PRODID are 0004(=MBH10302),
386 but these are MBH10304 based card. */
387 cardtype = MBH10304;
388 else if (link->card_id == PRODID_FUJITSU_MBH10304)
389 cardtype = MBH10304;
390 else
391 cardtype = LA501;
392 break;
393 default:
394 cardtype = MBH10304;
395 }
396 } else {
397 /* old type card */
398 switch (link->manf_id) {
399 case MANFID_FUJITSU:
400 if (link->card_id == PRODID_FUJITSU_MBH10304) {
401 cardtype = XXX10304; /* MBH10304 with buggy CIS */
402 link->config_index = 0x20;
403 } else {
404 cardtype = MBH10302; /* NextCom NC5310, etc. */
405 link->config_index = 1;
406 }
407 break;
408 case MANFID_UNGERMANN:
409 cardtype = UNGERMANN;
410 break;
411 default:
412 cardtype = MBH10302;
413 link->config_index = 1;
414 }
415 }
416
417 if (link->resource[1]->end != 0) {
418 ret = mfc_try_io_port(link);
419 if (ret != 0) goto failed;
420 } else if (cardtype == UNGERMANN) {
421 ret = ungermann_try_io_port(link);
422 if (ret != 0) goto failed;
423 } else {
424 ret = pcmcia_request_io(link);
425 if (ret)
426 goto failed;
427 }
428 ret = pcmcia_request_irq(link, fjn_interrupt);
429 if (ret)
430 goto failed;
431 ret = pcmcia_enable_device(link);
432 if (ret)
433 goto failed;
434
435 dev->irq = link->irq;
436 dev->base_addr = link->resource[0]->start;
437
438 if (resource_size(link->resource[1]) != 0) {
439 ret = fmvj18x_setup_mfc(link);
440 if (ret != 0) goto failed;
441 }
442
443 ioaddr = dev->base_addr;
444
445 /* Reset controller */
446 if (sram_config == 0)
447 outb(CONFIG0_RST, ioaddr + CONFIG_0);
448 else
449 outb(CONFIG0_RST_1, ioaddr + CONFIG_0);
450
451 /* Power On chip and select bank 0 */
452 if (cardtype == MBH10302)
453 outb(BANK_0, ioaddr + CONFIG_1);
454 else
455 outb(BANK_0U, ioaddr + CONFIG_1);
456
457 /* Set hardware address */
458 switch (cardtype) {
459 case MBH10304:
460 case TDK:
461 case LA501:
462 case CONTEC:
463 case NEC:
464 case KME:
465 if (cardtype == MBH10304) {
466 card_name = "FMV-J182";
467
468 len = pcmcia_get_tuple(link, CISTPL_FUNCE, &buf);
469 if (len < 11) {
470 kfree(buf);
471 goto failed;
472 }
473 /* Read MACID from CIS */
474 for (i = 5; i < 11; i++)
475 dev->dev_addr[i] = buf[i];
476 kfree(buf);
477 } else {
478 if (pcmcia_get_mac_from_cis(link, dev))
479 goto failed;
480 if( cardtype == TDK ) {
481 card_name = "TDK LAK-CD021";
482 } else if( cardtype == LA501 ) {
483 card_name = "LA501";
484 } else if( cardtype == NEC ) {
485 card_name = "PK-UG-J001";
486 } else if( cardtype == KME ) {
487 card_name = "Panasonic";
488 } else {
489 card_name = "C-NET(PC)C";
490 }
491 }
492 break;
493 case UNGERMANN:
494 /* Read MACID from register */
495 for (i = 0; i < 6; i++)
496 dev->dev_addr[i] = inb(ioaddr + UNGERMANN_MAC_ID + i);
497 card_name = "Access/CARD";
498 break;
499 case XXX10304:
500 /* Read MACID from Buggy CIS */
501 if (fmvj18x_get_hwinfo(link, buggybuf) == -1) {
502 pr_notice("unable to read hardware net address\n");
503 goto failed;
504 }
505 for (i = 0 ; i < 6; i++) {
506 dev->dev_addr[i] = buggybuf[i];
507 }
508 card_name = "FMV-J182";
509 break;
510 case MBH10302:
511 default:
512 /* Read MACID from register */
513 for (i = 0; i < 6; i++)
514 dev->dev_addr[i] = inb(ioaddr + MAC_ID + i);
515 card_name = "FMV-J181";
516 break;
517 }
518
519 lp->cardtype = cardtype;
520 SET_NETDEV_DEV(dev, &link->dev);
521
522 if (register_netdev(dev) != 0) {
523 pr_notice("register_netdev() failed\n");
524 goto failed;
525 }
526
527 /* print current configuration */
528 netdev_info(dev, "%s, sram %s, port %#3lx, irq %d, hw_addr %pM\n",
529 card_name, sram_config == 0 ? "4K TX*2" : "8K TX*2",
530 dev->base_addr, dev->irq, dev->dev_addr);
531
532 return 0;
533
534failed:
535 fmvj18x_release(link);
536 return -ENODEV;
537} /* fmvj18x_config */
538/*====================================================================*/
539
540static int fmvj18x_get_hwinfo(struct pcmcia_device *link, u_char *node_id)
541{
542 u_char __iomem *base;
543 int i, j;
544
545 /* Allocate a small memory window */
546 link->resource[2]->flags |= WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
547 link->resource[2]->start = 0; link->resource[2]->end = 0;
548 i = pcmcia_request_window(link, link->resource[2], 0);
549 if (i != 0)
550 return -1;
551
552 base = ioremap(link->resource[2]->start, resource_size(link->resource[2]));
553 pcmcia_map_mem_page(link, link->resource[2], 0);
554
555 /*
556 * MBH10304 CISTPL_FUNCE_LAN_NODE_ID format
557 * 22 0d xx xx xx 04 06 yy yy yy yy yy yy ff
558 * 'xx' is garbage.
559 * 'yy' is MAC address.
560 */
561 for (i = 0; i < 0x200; i++) {
562 if (readb(base+i*2) == 0x22) {
563 if (readb(base+(i-1)*2) == 0xff &&
564 readb(base+(i+5)*2) == 0x04 &&
565 readb(base+(i+6)*2) == 0x06 &&
566 readb(base+(i+13)*2) == 0xff)
567 break;
568 }
569 }
570
571 if (i != 0x200) {
572 for (j = 0 ; j < 6; j++,i++) {
573 node_id[j] = readb(base+(i+7)*2);
574 }
575 }
576
577 iounmap(base);
578 j = pcmcia_release_window(link, link->resource[2]);
579 return (i != 0x200) ? 0 : -1;
580
581} /* fmvj18x_get_hwinfo */
582/*====================================================================*/
583
584static int fmvj18x_setup_mfc(struct pcmcia_device *link)
585{
586 int i;
587 struct net_device *dev = link->priv;
588 unsigned int ioaddr;
589 local_info_t *lp = netdev_priv(dev);
590
591 /* Allocate a small memory window */
592 link->resource[3]->flags = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
593 link->resource[3]->start = link->resource[3]->end = 0;
594 i = pcmcia_request_window(link, link->resource[3], 0);
595 if (i != 0)
596 return -1;
597
598 lp->base = ioremap(link->resource[3]->start,
599 resource_size(link->resource[3]));
600 if (lp->base == NULL) {
601 netdev_notice(dev, "ioremap failed\n");
602 return -1;
603 }
604
605 i = pcmcia_map_mem_page(link, link->resource[3], 0);
606 if (i != 0) {
607 iounmap(lp->base);
608 lp->base = NULL;
609 return -1;
610 }
611
612 ioaddr = dev->base_addr;
613 writeb(0x47, lp->base+0x800); /* Config Option Register of LAN */
614 writeb(0x0, lp->base+0x802); /* Config and Status Register */
615
616 writeb(ioaddr & 0xff, lp->base+0x80a); /* I/O Base(Low) of LAN */
617 writeb((ioaddr >> 8) & 0xff, lp->base+0x80c); /* I/O Base(High) of LAN */
618
619 writeb(0x45, lp->base+0x820); /* Config Option Register of Modem */
620 writeb(0x8, lp->base+0x822); /* Config and Status Register */
621
622 return 0;
623
624}
625/*====================================================================*/
626
627static void fmvj18x_release(struct pcmcia_device *link)
628{
629
630 struct net_device *dev = link->priv;
631 local_info_t *lp = netdev_priv(dev);
632 u_char __iomem *tmp;
633
634 dev_dbg(&link->dev, "fmvj18x_release\n");
635
636 if (lp->base != NULL) {
637 tmp = lp->base;
638 lp->base = NULL; /* set NULL before iounmap */
639 iounmap(tmp);
640 }
641
642 pcmcia_disable_device(link);
643
644}
645
646static int fmvj18x_suspend(struct pcmcia_device *link)
647{
648 struct net_device *dev = link->priv;
649
650 if (link->open)
651 netif_device_detach(dev);
652
653 return 0;
654}
655
656static int fmvj18x_resume(struct pcmcia_device *link)
657{
658 struct net_device *dev = link->priv;
659
660 if (link->open) {
661 fjn_reset(dev);
662 netif_device_attach(dev);
663 }
664
665 return 0;
666}
667
668/*====================================================================*/
669
670static const struct pcmcia_device_id fmvj18x_ids[] = {
671 PCMCIA_DEVICE_MANF_CARD(0x0004, 0x0004),
672 PCMCIA_DEVICE_PROD_ID12("EAGLE Technology", "NE200 ETHERNET LAN MBH10302 04", 0x528c88c4, 0x74f91e59),
673 PCMCIA_DEVICE_PROD_ID12("Eiger Labs,Inc", "EPX-10BT PC Card Ethernet 10BT", 0x53af556e, 0x877f9922),
674 PCMCIA_DEVICE_PROD_ID12("Eiger labs,Inc.", "EPX-10BT PC Card Ethernet 10BT", 0xf47e6c66, 0x877f9922),
675 PCMCIA_DEVICE_PROD_ID12("FUJITSU", "LAN Card(FMV-J182)", 0x6ee5a3d8, 0x5baf31db),
676 PCMCIA_DEVICE_PROD_ID12("FUJITSU", "MBH10308", 0x6ee5a3d8, 0x3f04875e),
677 PCMCIA_DEVICE_PROD_ID12("FUJITSU TOWA", "LA501", 0xb8451188, 0x12939ba2),
678 PCMCIA_DEVICE_PROD_ID12("HITACHI", "HT-4840-11", 0xf4f43949, 0x773910f4),
679 PCMCIA_DEVICE_PROD_ID12("NextComK.K.", "NC5310B Ver1.0 ", 0x8cef4d3a, 0x075fc7b6),
680 PCMCIA_DEVICE_PROD_ID12("NextComK.K.", "NC5310 Ver1.0 ", 0x8cef4d3a, 0xbccf43e6),
681 PCMCIA_DEVICE_PROD_ID12("RATOC System Inc.", "10BASE_T CARD R280", 0x85c10e17, 0xd9413666),
682 PCMCIA_DEVICE_PROD_ID12("TDK", "LAC-CD02x", 0x1eae9475, 0x8fa0ee70),
683 PCMCIA_DEVICE_PROD_ID12("TDK", "LAC-CF010", 0x1eae9475, 0x7683bc9a),
684 PCMCIA_DEVICE_PROD_ID1("CONTEC Co.,Ltd.", 0x58d8fee2),
685 PCMCIA_DEVICE_PROD_ID1("PCMCIA LAN MBH10304 ES", 0x2599f454),
686 PCMCIA_DEVICE_PROD_ID1("PCMCIA MBH10302", 0x8f4005da),
687 PCMCIA_DEVICE_PROD_ID1("UBKK,V2.0", 0x90888080),
688 PCMCIA_PFC_DEVICE_PROD_ID12(0, "TDK", "GlobalNetworker 3410/3412", 0x1eae9475, 0xd9a93bed),
689 PCMCIA_PFC_DEVICE_PROD_ID12(0, "NEC", "PK-UG-J001" ,0x18df0ba0 ,0x831b1064),
690 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0105, 0x0d0a),
691 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0105, 0x0e0a),
692 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0032, 0x0e01),
693 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0032, 0x0a05),
694 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0032, 0x0b05),
695 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0032, 0x1101),
696 PCMCIA_DEVICE_NULL,
697};
698MODULE_DEVICE_TABLE(pcmcia, fmvj18x_ids);
699
700static struct pcmcia_driver fmvj18x_cs_driver = {
701 .owner = THIS_MODULE,
702 .name = "fmvj18x_cs",
703 .probe = fmvj18x_probe,
704 .remove = fmvj18x_detach,
705 .id_table = fmvj18x_ids,
706 .suspend = fmvj18x_suspend,
707 .resume = fmvj18x_resume,
708};
709
710static int __init init_fmvj18x_cs(void)
711{
712 return pcmcia_register_driver(&fmvj18x_cs_driver);
713}
714
715static void __exit exit_fmvj18x_cs(void)
716{
717 pcmcia_unregister_driver(&fmvj18x_cs_driver);
718}
719
720module_init(init_fmvj18x_cs);
721module_exit(exit_fmvj18x_cs);
722
723/*====================================================================*/
724
725static irqreturn_t fjn_interrupt(int dummy, void *dev_id)
726{
727 struct net_device *dev = dev_id;
728 local_info_t *lp = netdev_priv(dev);
729 unsigned int ioaddr;
730 unsigned short tx_stat, rx_stat;
731
732 ioaddr = dev->base_addr;
733
734 /* avoid multiple interrupts */
735 outw(0x0000, ioaddr + TX_INTR);
736
737 /* wait for a while */
738 udelay(1);
739
740 /* get status */
741 tx_stat = inb(ioaddr + TX_STATUS);
742 rx_stat = inb(ioaddr + RX_STATUS);
743
744 /* clear status */
745 outb(tx_stat, ioaddr + TX_STATUS);
746 outb(rx_stat, ioaddr + RX_STATUS);
747
748 pr_debug("%s: interrupt, rx_status %02x.\n", dev->name, rx_stat);
749 pr_debug(" tx_status %02x.\n", tx_stat);
750
751 if (rx_stat || (inb(ioaddr + RX_MODE) & F_BUF_EMP) == 0) {
752 /* there is packet(s) in rx buffer */
753 fjn_rx(dev);
754 }
755 if (tx_stat & F_TMT_RDY) {
756 dev->stats.tx_packets += lp->sent ;
757 lp->sent = 0 ;
758 if (lp->tx_queue) {
759 outb(DO_TX | lp->tx_queue, ioaddr + TX_START);
760 lp->sent = lp->tx_queue ;
761 lp->tx_queue = 0;
762 lp->tx_queue_len = 0;
763 dev->trans_start = jiffies;
764 } else {
765 lp->tx_started = 0;
766 }
767 netif_wake_queue(dev);
768 }
769 pr_debug("%s: exiting interrupt,\n", dev->name);
770 pr_debug(" tx_status %02x, rx_status %02x.\n", tx_stat, rx_stat);
771
772 outb(D_TX_INTR, ioaddr + TX_INTR);
773 outb(D_RX_INTR, ioaddr + RX_INTR);
774
775 if (lp->base != NULL) {
776 /* Ack interrupt for multifunction card */
777 writeb(0x01, lp->base+0x802);
778 writeb(0x09, lp->base+0x822);
779 }
780
781 return IRQ_HANDLED;
782
783} /* fjn_interrupt */
784
785/*====================================================================*/
786
787static void fjn_tx_timeout(struct net_device *dev)
788{
789 struct local_info_t *lp = netdev_priv(dev);
790 unsigned int ioaddr = dev->base_addr;
791
792 netdev_notice(dev, "transmit timed out with status %04x, %s?\n",
793 htons(inw(ioaddr + TX_STATUS)),
794 inb(ioaddr + TX_STATUS) & F_TMT_RDY
795 ? "IRQ conflict" : "network cable problem");
796 netdev_notice(dev, "timeout registers: %04x %04x %04x "
797 "%04x %04x %04x %04x %04x.\n",
798 htons(inw(ioaddr + 0)), htons(inw(ioaddr + 2)),
799 htons(inw(ioaddr + 4)), htons(inw(ioaddr + 6)),
800 htons(inw(ioaddr + 8)), htons(inw(ioaddr + 10)),
801 htons(inw(ioaddr + 12)), htons(inw(ioaddr + 14)));
802 dev->stats.tx_errors++;
803 /* ToDo: We should try to restart the adaptor... */
804 local_irq_disable();
805 fjn_reset(dev);
806
807 lp->tx_started = 0;
808 lp->tx_queue = 0;
809 lp->tx_queue_len = 0;
810 lp->sent = 0;
811 lp->open_time = jiffies;
812 local_irq_enable();
813 netif_wake_queue(dev);
814}
815
816static netdev_tx_t fjn_start_xmit(struct sk_buff *skb,
817 struct net_device *dev)
818{
819 struct local_info_t *lp = netdev_priv(dev);
820 unsigned int ioaddr = dev->base_addr;
821 short length = skb->len;
822
823 if (length < ETH_ZLEN)
824 {
825 if (skb_padto(skb, ETH_ZLEN))
826 return NETDEV_TX_OK;
827 length = ETH_ZLEN;
828 }
829
830 netif_stop_queue(dev);
831
832 {
833 unsigned char *buf = skb->data;
834
835 if (length > ETH_FRAME_LEN) {
836 netdev_notice(dev, "Attempting to send a large packet (%d bytes)\n",
837 length);
838 return NETDEV_TX_BUSY;
839 }
840
841 netdev_dbg(dev, "Transmitting a packet of length %lu\n",
842 (unsigned long)skb->len);
843 dev->stats.tx_bytes += skb->len;
844
845 /* Disable both interrupts. */
846 outw(0x0000, ioaddr + TX_INTR);
847
848 /* wait for a while */
849 udelay(1);
850
851 outw(length, ioaddr + DATAPORT);
852 outsw(ioaddr + DATAPORT, buf, (length + 1) >> 1);
853
854 lp->tx_queue++;
855 lp->tx_queue_len += ((length+3) & ~1);
856
857 if (lp->tx_started == 0) {
858 /* If the Tx is idle, always trigger a transmit. */
859 outb(DO_TX | lp->tx_queue, ioaddr + TX_START);
860 lp->sent = lp->tx_queue ;
861 lp->tx_queue = 0;
862 lp->tx_queue_len = 0;
863 lp->tx_started = 1;
864 netif_start_queue(dev);
865 } else {
866 if( sram_config == 0 ) {
867 if (lp->tx_queue_len < (4096 - (ETH_FRAME_LEN +2)) )
868 /* Yes, there is room for one more packet. */
869 netif_start_queue(dev);
870 } else {
871 if (lp->tx_queue_len < (8192 - (ETH_FRAME_LEN +2)) &&
872 lp->tx_queue < 127 )
873 /* Yes, there is room for one more packet. */
874 netif_start_queue(dev);
875 }
876 }
877
878 /* Re-enable interrupts */
879 outb(D_TX_INTR, ioaddr + TX_INTR);
880 outb(D_RX_INTR, ioaddr + RX_INTR);
881 }
882 dev_kfree_skb (skb);
883
884 return NETDEV_TX_OK;
885} /* fjn_start_xmit */
886
887/*====================================================================*/
888
889static void fjn_reset(struct net_device *dev)
890{
891 struct local_info_t *lp = netdev_priv(dev);
892 unsigned int ioaddr = dev->base_addr;
893 int i;
894
895 netdev_dbg(dev, "fjn_reset() called\n");
896
897 /* Reset controller */
898 if( sram_config == 0 )
899 outb(CONFIG0_RST, ioaddr + CONFIG_0);
900 else
901 outb(CONFIG0_RST_1, ioaddr + CONFIG_0);
902
903 /* Power On chip and select bank 0 */
904 if (lp->cardtype == MBH10302)
905 outb(BANK_0, ioaddr + CONFIG_1);
906 else
907 outb(BANK_0U, ioaddr + CONFIG_1);
908
909 /* Set Tx modes */
910 outb(D_TX_MODE, ioaddr + TX_MODE);
911 /* set Rx modes */
912 outb(ID_MATCHED, ioaddr + RX_MODE);
913
914 /* Set hardware address */
915 for (i = 0; i < 6; i++)
916 outb(dev->dev_addr[i], ioaddr + NODE_ID + i);
917
918 /* (re)initialize the multicast table */
919 set_rx_mode(dev);
920
921 /* Switch to bank 2 (runtime mode) */
922 if (lp->cardtype == MBH10302)
923 outb(BANK_2, ioaddr + CONFIG_1);
924 else
925 outb(BANK_2U, ioaddr + CONFIG_1);
926
927 /* set 16col ctrl bits */
928 if( lp->cardtype == TDK || lp->cardtype == CONTEC)
929 outb(TDK_AUTO_MODE, ioaddr + COL_CTRL);
930 else
931 outb(AUTO_MODE, ioaddr + COL_CTRL);
932
933 /* clear Reserved Regs */
934 outb(0x00, ioaddr + BMPR12);
935 outb(0x00, ioaddr + BMPR13);
936
937 /* reset Skip packet reg. */
938 outb(0x01, ioaddr + RX_SKIP);
939
940 /* Enable Tx and Rx */
941 if( sram_config == 0 )
942 outb(CONFIG0_DFL, ioaddr + CONFIG_0);
943 else
944 outb(CONFIG0_DFL_1, ioaddr + CONFIG_0);
945
946 /* Init receive pointer ? */
947 inw(ioaddr + DATAPORT);
948 inw(ioaddr + DATAPORT);
949
950 /* Clear all status */
951 outb(0xff, ioaddr + TX_STATUS);
952 outb(0xff, ioaddr + RX_STATUS);
953
954 if (lp->cardtype == MBH10302)
955 outb(INTR_OFF, ioaddr + LAN_CTRL);
956
957 /* Turn on Rx interrupts */
958 outb(D_TX_INTR, ioaddr + TX_INTR);
959 outb(D_RX_INTR, ioaddr + RX_INTR);
960
961 /* Turn on interrupts from LAN card controller */
962 if (lp->cardtype == MBH10302)
963 outb(INTR_ON, ioaddr + LAN_CTRL);
964} /* fjn_reset */
965
966/*====================================================================*/
967
968static void fjn_rx(struct net_device *dev)
969{
970 unsigned int ioaddr = dev->base_addr;
971 int boguscount = 10; /* 5 -> 10: by agy 19940922 */
972
973 pr_debug("%s: in rx_packet(), rx_status %02x.\n",
974 dev->name, inb(ioaddr + RX_STATUS));
975
976 while ((inb(ioaddr + RX_MODE) & F_BUF_EMP) == 0) {
977 u_short status = inw(ioaddr + DATAPORT);
978
979 netdev_dbg(dev, "Rxing packet mode %02x status %04x.\n",
980 inb(ioaddr + RX_MODE), status);
981#ifndef final_version
982 if (status == 0) {
983 outb(F_SKP_PKT, ioaddr + RX_SKIP);
984 break;
985 }
986#endif
987 if ((status & 0xF0) != 0x20) { /* There was an error. */
988 dev->stats.rx_errors++;
989 if (status & F_LEN_ERR) dev->stats.rx_length_errors++;
990 if (status & F_ALG_ERR) dev->stats.rx_frame_errors++;
991 if (status & F_CRC_ERR) dev->stats.rx_crc_errors++;
992 if (status & F_OVR_FLO) dev->stats.rx_over_errors++;
993 } else {
994 u_short pkt_len = inw(ioaddr + DATAPORT);
995 /* Malloc up new buffer. */
996 struct sk_buff *skb;
997
998 if (pkt_len > 1550) {
999 netdev_notice(dev, "The FMV-18x claimed a very large packet, size %d\n",
1000 pkt_len);
1001 outb(F_SKP_PKT, ioaddr + RX_SKIP);
1002 dev->stats.rx_errors++;
1003 break;
1004 }
1005 skb = dev_alloc_skb(pkt_len+2);
1006 if (skb == NULL) {
1007 netdev_notice(dev, "Memory squeeze, dropping packet (len %d)\n",
1008 pkt_len);
1009 outb(F_SKP_PKT, ioaddr + RX_SKIP);
1010 dev->stats.rx_dropped++;
1011 break;
1012 }
1013
1014 skb_reserve(skb, 2);
1015 insw(ioaddr + DATAPORT, skb_put(skb, pkt_len),
1016 (pkt_len + 1) >> 1);
1017 skb->protocol = eth_type_trans(skb, dev);
1018
1019 {
1020 int i;
1021 pr_debug("%s: Rxed packet of length %d: ",
1022 dev->name, pkt_len);
1023 for (i = 0; i < 14; i++)
1024 pr_debug(" %02x", skb->data[i]);
1025 pr_debug(".\n");
1026 }
1027
1028 netif_rx(skb);
1029 dev->stats.rx_packets++;
1030 dev->stats.rx_bytes += pkt_len;
1031 }
1032 if (--boguscount <= 0)
1033 break;
1034 }
1035
1036 /* If any worth-while packets have been received, dev_rint()
1037 has done a netif_wake_queue() for us and will work on them
1038 when we get to the bottom-half routine. */
1039/*
1040 if (lp->cardtype != TDK) {
1041 int i;
1042 for (i = 0; i < 20; i++) {
1043 if ((inb(ioaddr + RX_MODE) & F_BUF_EMP) == F_BUF_EMP)
1044 break;
1045 (void)inw(ioaddr + DATAPORT); /+ dummy status read +/
1046 outb(F_SKP_PKT, ioaddr + RX_SKIP);
1047 }
1048
1049 if (i > 0)
1050 pr_debug("%s: Exint Rx packet with mode %02x after "
1051 "%d ticks.\n", dev->name, inb(ioaddr + RX_MODE), i);
1052 }
1053*/
1054} /* fjn_rx */
1055
1056/*====================================================================*/
1057
1058static void netdev_get_drvinfo(struct net_device *dev,
1059 struct ethtool_drvinfo *info)
1060{
1061 strcpy(info->driver, DRV_NAME);
1062 strcpy(info->version, DRV_VERSION);
1063 sprintf(info->bus_info, "PCMCIA 0x%lx", dev->base_addr);
1064}
1065
1066static const struct ethtool_ops netdev_ethtool_ops = {
1067 .get_drvinfo = netdev_get_drvinfo,
1068};
1069
1070static int fjn_config(struct net_device *dev, struct ifmap *map){
1071 return 0;
1072}
1073
1074static int fjn_open(struct net_device *dev)
1075{
1076 struct local_info_t *lp = netdev_priv(dev);
1077 struct pcmcia_device *link = lp->p_dev;
1078
1079 pr_debug("fjn_open('%s').\n", dev->name);
1080
1081 if (!pcmcia_dev_present(link))
1082 return -ENODEV;
1083
1084 link->open++;
1085
1086 fjn_reset(dev);
1087
1088 lp->tx_started = 0;
1089 lp->tx_queue = 0;
1090 lp->tx_queue_len = 0;
1091 lp->open_time = jiffies;
1092 netif_start_queue(dev);
1093
1094 return 0;
1095} /* fjn_open */
1096
1097/*====================================================================*/
1098
1099static int fjn_close(struct net_device *dev)
1100{
1101 struct local_info_t *lp = netdev_priv(dev);
1102 struct pcmcia_device *link = lp->p_dev;
1103 unsigned int ioaddr = dev->base_addr;
1104
1105 pr_debug("fjn_close('%s').\n", dev->name);
1106
1107 lp->open_time = 0;
1108 netif_stop_queue(dev);
1109
1110 /* Set configuration register 0 to disable Tx and Rx. */
1111 if( sram_config == 0 )
1112 outb(CONFIG0_RST ,ioaddr + CONFIG_0);
1113 else
1114 outb(CONFIG0_RST_1 ,ioaddr + CONFIG_0);
1115
1116 /* Update the statistics -- ToDo. */
1117
1118 /* Power-down the chip. Green, green, green! */
1119 outb(CHIP_OFF ,ioaddr + CONFIG_1);
1120
1121 /* Set the ethernet adaptor disable IRQ */
1122 if (lp->cardtype == MBH10302)
1123 outb(INTR_OFF, ioaddr + LAN_CTRL);
1124
1125 link->open--;
1126
1127 return 0;
1128} /* fjn_close */
1129
1130/*====================================================================*/
1131
1132/*
1133 Set the multicast/promiscuous mode for this adaptor.
1134*/
1135
1136static void set_rx_mode(struct net_device *dev)
1137{
1138 unsigned int ioaddr = dev->base_addr;
1139 u_char mc_filter[8]; /* Multicast hash filter */
1140 u_long flags;
1141 int i;
1142
1143 int saved_bank;
1144 int saved_config_0 = inb(ioaddr + CONFIG_0);
1145
1146 local_irq_save(flags);
1147
1148 /* Disable Tx and Rx */
1149 if (sram_config == 0)
1150 outb(CONFIG0_RST, ioaddr + CONFIG_0);
1151 else
1152 outb(CONFIG0_RST_1, ioaddr + CONFIG_0);
1153
1154 if (dev->flags & IFF_PROMISC) {
1155 memset(mc_filter, 0xff, sizeof(mc_filter));
1156 outb(3, ioaddr + RX_MODE); /* Enable promiscuous mode */
1157 } else if (netdev_mc_count(dev) > MC_FILTERBREAK ||
1158 (dev->flags & IFF_ALLMULTI)) {
1159 /* Too many to filter perfectly -- accept all multicasts. */
1160 memset(mc_filter, 0xff, sizeof(mc_filter));
1161 outb(2, ioaddr + RX_MODE); /* Use normal mode. */
1162 } else if (netdev_mc_empty(dev)) {
1163 memset(mc_filter, 0x00, sizeof(mc_filter));
1164 outb(1, ioaddr + RX_MODE); /* Ignore almost all multicasts. */
1165 } else {
1166 struct netdev_hw_addr *ha;
1167
1168 memset(mc_filter, 0, sizeof(mc_filter));
1169 netdev_for_each_mc_addr(ha, dev) {
1170 unsigned int bit = ether_crc_le(ETH_ALEN, ha->addr) >> 26;
1171 mc_filter[bit >> 3] |= (1 << (bit & 7));
1172 }
1173 outb(2, ioaddr + RX_MODE); /* Use normal mode. */
1174 }
1175
1176 /* Switch to bank 1 and set the multicast table. */
1177 saved_bank = inb(ioaddr + CONFIG_1);
1178 outb(0xe4, ioaddr + CONFIG_1);
1179
1180 for (i = 0; i < 8; i++)
1181 outb(mc_filter[i], ioaddr + MAR_ADR + i);
1182 outb(saved_bank, ioaddr + CONFIG_1);
1183
1184 outb(saved_config_0, ioaddr + CONFIG_0);
1185
1186 local_irq_restore(flags);
1187}
diff --git a/drivers/net/pcmcia/ibmtr_cs.c b/drivers/net/pcmcia/ibmtr_cs.c
new file mode 100644
index 00000000000..6006d5488fb
--- /dev/null
+++ b/drivers/net/pcmcia/ibmtr_cs.c
@@ -0,0 +1,371 @@
1/*======================================================================
2
3 A PCMCIA token-ring driver for IBM-based cards
4
5 This driver supports the IBM PCMCIA Token-Ring Card.
6 Written by Steve Kipisz, kipisz@vnet.ibm.com or
7 bungy@ibm.net
8
9 Written 1995,1996.
10
11 This code is based on pcnet_cs.c from David Hinds.
12
13 V2.2.0 February 1999 - Mike Phillips phillim@amtrak.com
14
15 Linux V2.2.x presented significant changes to the underlying
16 ibmtr.c code. Mainly the code became a lot more organized and
17 modular.
18
19 This caused the old PCMCIA Token Ring driver to give up and go
20 home early. Instead of just patching the old code to make it
21 work, the PCMCIA code has been streamlined, updated and possibly
22 improved.
23
24 This code now only contains code required for the Card Services.
25 All we do here is set the card up enough so that the real ibmtr.c
26 driver can find it and work with it properly.
27
28 i.e. We set up the io port, irq, mmio memory and shared ram
29 memory. This enables ibmtr_probe in ibmtr.c to find the card and
30 configure it as though it was a normal ISA and/or PnP card.
31
32 CHANGES
33
34 v2.2.5 April 1999 Mike Phillips (phillim@amtrak.com)
35 Obscure bug fix, required changed to ibmtr.c not ibmtr_cs.c
36
37 v2.2.7 May 1999 Mike Phillips (phillim@amtrak.com)
38 Updated to version 2.2.7 to match the first version of the kernel
39 that the modification to ibmtr.c were incorporated into.
40
41 v2.2.17 July 2000 Burt Silverman (burts@us.ibm.com)
42 Address translation feature of PCMCIA controller is usable so
43 memory windows can be placed in High memory (meaning above
44 0xFFFFF.)
45
46======================================================================*/
47
48#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
49
50#include <linux/kernel.h>
51#include <linux/init.h>
52#include <linux/ptrace.h>
53#include <linux/slab.h>
54#include <linux/string.h>
55#include <linux/timer.h>
56#include <linux/module.h>
57#include <linux/netdevice.h>
58#include <linux/trdevice.h>
59#include <linux/ibmtr.h>
60
61#include <pcmcia/cistpl.h>
62#include <pcmcia/ds.h>
63
64#include <asm/uaccess.h>
65#include <asm/io.h>
66#include <asm/system.h>
67
68#define PCMCIA
69#include "../tokenring/ibmtr.c"
70
71
72/*====================================================================*/
73
74/* Parameters that can be set with 'insmod' */
75
76/* MMIO base address */
77static u_long mmiobase = 0xce000;
78
79/* SRAM base address */
80static u_long srambase = 0xd0000;
81
82/* SRAM size 8,16,32,64 */
83static u_long sramsize = 64;
84
85/* Ringspeed 4,16 */
86static int ringspeed = 16;
87
88module_param(mmiobase, ulong, 0);
89module_param(srambase, ulong, 0);
90module_param(sramsize, ulong, 0);
91module_param(ringspeed, int, 0);
92MODULE_LICENSE("GPL");
93
94/*====================================================================*/
95
96static int ibmtr_config(struct pcmcia_device *link);
97static void ibmtr_hw_setup(struct net_device *dev, u_int mmiobase);
98static void ibmtr_release(struct pcmcia_device *link);
99static void ibmtr_detach(struct pcmcia_device *p_dev);
100
101/*====================================================================*/
102
103typedef struct ibmtr_dev_t {
104 struct pcmcia_device *p_dev;
105 struct net_device *dev;
106 struct tok_info *ti;
107} ibmtr_dev_t;
108
109static irqreturn_t ibmtr_interrupt(int irq, void *dev_id) {
110 ibmtr_dev_t *info = dev_id;
111 struct net_device *dev = info->dev;
112 return tok_interrupt(irq, dev);
113};
114
115static int __devinit ibmtr_attach(struct pcmcia_device *link)
116{
117 ibmtr_dev_t *info;
118 struct net_device *dev;
119
120 dev_dbg(&link->dev, "ibmtr_attach()\n");
121
122 /* Create new token-ring device */
123 info = kzalloc(sizeof(*info), GFP_KERNEL);
124 if (!info) return -ENOMEM;
125 dev = alloc_trdev(sizeof(struct tok_info));
126 if (!dev) {
127 kfree(info);
128 return -ENOMEM;
129 }
130
131 info->p_dev = link;
132 link->priv = info;
133 info->ti = netdev_priv(dev);
134
135 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
136 link->resource[0]->end = 4;
137 link->config_flags |= CONF_ENABLE_IRQ;
138 link->config_regs = PRESENT_OPTION;
139
140 info->dev = dev;
141
142 return ibmtr_config(link);
143} /* ibmtr_attach */
144
145static void ibmtr_detach(struct pcmcia_device *link)
146{
147 struct ibmtr_dev_t *info = link->priv;
148 struct net_device *dev = info->dev;
149 struct tok_info *ti = netdev_priv(dev);
150
151 dev_dbg(&link->dev, "ibmtr_detach\n");
152
153 /*
154 * When the card removal interrupt hits tok_interrupt(),
155 * bail out early, so we don't crash the machine
156 */
157 ti->sram_phys |= 1;
158
159 unregister_netdev(dev);
160
161 del_timer_sync(&(ti->tr_timer));
162
163 ibmtr_release(link);
164
165 free_netdev(dev);
166 kfree(info);
167} /* ibmtr_detach */
168
169static int __devinit ibmtr_config(struct pcmcia_device *link)
170{
171 ibmtr_dev_t *info = link->priv;
172 struct net_device *dev = info->dev;
173 struct tok_info *ti = netdev_priv(dev);
174 int i, ret;
175
176 dev_dbg(&link->dev, "ibmtr_config\n");
177
178 link->io_lines = 16;
179 link->config_index = 0x61;
180
181 /* Determine if this is PRIMARY or ALTERNATE. */
182
183 /* Try PRIMARY card at 0xA20-0xA23 */
184 link->resource[0]->start = 0xA20;
185 i = pcmcia_request_io(link);
186 if (i != 0) {
187 /* Couldn't get 0xA20-0xA23. Try ALTERNATE at 0xA24-0xA27. */
188 link->resource[0]->start = 0xA24;
189 ret = pcmcia_request_io(link);
190 if (ret)
191 goto failed;
192 }
193 dev->base_addr = link->resource[0]->start;
194
195 ret = pcmcia_request_exclusive_irq(link, ibmtr_interrupt);
196 if (ret)
197 goto failed;
198 dev->irq = link->irq;
199 ti->irq = link->irq;
200 ti->global_int_enable=GLOBAL_INT_ENABLE+((dev->irq==9) ? 2 : dev->irq);
201
202 /* Allocate the MMIO memory window */
203 link->resource[2]->flags |= WIN_DATA_WIDTH_16|WIN_MEMORY_TYPE_CM|WIN_ENABLE;
204 link->resource[2]->flags |= WIN_USE_WAIT;
205 link->resource[2]->start = 0;
206 link->resource[2]->end = 0x2000;
207 ret = pcmcia_request_window(link, link->resource[2], 250);
208 if (ret)
209 goto failed;
210
211 ret = pcmcia_map_mem_page(link, link->resource[2], mmiobase);
212 if (ret)
213 goto failed;
214 ti->mmio = ioremap(link->resource[2]->start,
215 resource_size(link->resource[2]));
216
217 /* Allocate the SRAM memory window */
218 link->resource[3]->flags = WIN_DATA_WIDTH_16|WIN_MEMORY_TYPE_CM|WIN_ENABLE;
219 link->resource[3]->flags |= WIN_USE_WAIT;
220 link->resource[3]->start = 0;
221 link->resource[3]->end = sramsize * 1024;
222 ret = pcmcia_request_window(link, link->resource[3], 250);
223 if (ret)
224 goto failed;
225
226 ret = pcmcia_map_mem_page(link, link->resource[3], srambase);
227 if (ret)
228 goto failed;
229
230 ti->sram_base = srambase >> 12;
231 ti->sram_virt = ioremap(link->resource[3]->start,
232 resource_size(link->resource[3]));
233 ti->sram_phys = link->resource[3]->start;
234
235 ret = pcmcia_enable_device(link);
236 if (ret)
237 goto failed;
238
239 /* Set up the Token-Ring Controller Configuration Register and
240 turn on the card. Check the "Local Area Network Credit Card
241 Adapters Technical Reference" SC30-3585 for this info. */
242 ibmtr_hw_setup(dev, mmiobase);
243
244 SET_NETDEV_DEV(dev, &link->dev);
245
246 i = ibmtr_probe_card(dev);
247 if (i != 0) {
248 pr_notice("register_netdev() failed\n");
249 goto failed;
250 }
251
252 netdev_info(dev, "port %#3lx, irq %d, mmio %#5lx, sram %#5lx, hwaddr=%pM\n",
253 dev->base_addr, dev->irq,
254 (u_long)ti->mmio, (u_long)(ti->sram_base << 12),
255 dev->dev_addr);
256 return 0;
257
258failed:
259 ibmtr_release(link);
260 return -ENODEV;
261} /* ibmtr_config */
262
263static void ibmtr_release(struct pcmcia_device *link)
264{
265 ibmtr_dev_t *info = link->priv;
266 struct net_device *dev = info->dev;
267
268 dev_dbg(&link->dev, "ibmtr_release\n");
269
270 if (link->resource[2]->end) {
271 struct tok_info *ti = netdev_priv(dev);
272 iounmap(ti->mmio);
273 }
274 pcmcia_disable_device(link);
275}
276
277static int ibmtr_suspend(struct pcmcia_device *link)
278{
279 ibmtr_dev_t *info = link->priv;
280 struct net_device *dev = info->dev;
281
282 if (link->open)
283 netif_device_detach(dev);
284
285 return 0;
286}
287
288static int __devinit ibmtr_resume(struct pcmcia_device *link)
289{
290 ibmtr_dev_t *info = link->priv;
291 struct net_device *dev = info->dev;
292
293 if (link->open) {
294 ibmtr_probe(dev); /* really? */
295 netif_device_attach(dev);
296 }
297
298 return 0;
299}
300
301
302/*====================================================================*/
303
304static void ibmtr_hw_setup(struct net_device *dev, u_int mmiobase)
305{
306 int i;
307
308 /* Bizarre IBM behavior, there are 16 bits of information we
309 need to set, but the card only allows us to send 4 bits at a
310 time. For each byte sent to base_addr, bits 7-4 tell the
311 card which part of the 16 bits we are setting, bits 3-0 contain
312 the actual information */
313
314 /* First nibble provides 4 bits of mmio */
315 i = (mmiobase >> 16) & 0x0F;
316 outb(i, dev->base_addr);
317
318 /* Second nibble provides 3 bits of mmio */
319 i = 0x10 | ((mmiobase >> 12) & 0x0E);
320 outb(i, dev->base_addr);
321
322 /* Third nibble, hard-coded values */
323 i = 0x26;
324 outb(i, dev->base_addr);
325
326 /* Fourth nibble sets shared ram page size */
327
328 /* 8 = 00, 16 = 01, 32 = 10, 64 = 11 */
329 i = (sramsize >> 4) & 0x07;
330 i = ((i == 4) ? 3 : i) << 2;
331 i |= 0x30;
332
333 if (ringspeed == 16)
334 i |= 2;
335 if (dev->base_addr == 0xA24)
336 i |= 1;
337 outb(i, dev->base_addr);
338
339 /* 0x40 will release the card for use */
340 outb(0x40, dev->base_addr);
341}
342
343static const struct pcmcia_device_id ibmtr_ids[] = {
344 PCMCIA_DEVICE_PROD_ID12("3Com", "TokenLink Velocity PC Card", 0x41240e5b, 0x82c3734e),
345 PCMCIA_DEVICE_PROD_ID12("IBM", "TOKEN RING", 0xb569a6e5, 0xbf8eed47),
346 PCMCIA_DEVICE_NULL,
347};
348MODULE_DEVICE_TABLE(pcmcia, ibmtr_ids);
349
350static struct pcmcia_driver ibmtr_cs_driver = {
351 .owner = THIS_MODULE,
352 .name = "ibmtr_cs",
353 .probe = ibmtr_attach,
354 .remove = ibmtr_detach,
355 .id_table = ibmtr_ids,
356 .suspend = ibmtr_suspend,
357 .resume = ibmtr_resume,
358};
359
360static int __init init_ibmtr_cs(void)
361{
362 return pcmcia_register_driver(&ibmtr_cs_driver);
363}
364
365static void __exit exit_ibmtr_cs(void)
366{
367 pcmcia_unregister_driver(&ibmtr_cs_driver);
368}
369
370module_init(init_ibmtr_cs);
371module_exit(exit_ibmtr_cs);
diff --git a/drivers/net/pcmcia/nmclan_cs.c b/drivers/net/pcmcia/nmclan_cs.c
new file mode 100644
index 00000000000..9d70b659522
--- /dev/null
+++ b/drivers/net/pcmcia/nmclan_cs.c
@@ -0,0 +1,1525 @@
1/* ----------------------------------------------------------------------------
2Linux PCMCIA ethernet adapter driver for the New Media Ethernet LAN.
3 nmclan_cs.c,v 0.16 1995/07/01 06:42:17 rpao Exp rpao
4
5 The Ethernet LAN uses the Advanced Micro Devices (AMD) Am79C940 Media
6 Access Controller for Ethernet (MACE). It is essentially the Am2150
7 PCMCIA Ethernet card contained in the Am2150 Demo Kit.
8
9Written by Roger C. Pao <rpao@paonet.org>
10 Copyright 1995 Roger C. Pao
11 Linux 2.5 cleanups Copyright Red Hat 2003
12
13 This software may be used and distributed according to the terms of
14 the GNU General Public License.
15
16Ported to Linux 1.3.* network driver environment by
17 Matti Aarnio <mea@utu.fi>
18
19References
20
21 Am2150 Technical Reference Manual, Revision 1.0, August 17, 1993
22 Am79C940 (MACE) Data Sheet, 1994
23 Am79C90 (C-LANCE) Data Sheet, 1994
24 Linux PCMCIA Programmer's Guide v1.17
25 /usr/src/linux/net/inet/dev.c, Linux kernel 1.2.8
26
27 Eric Mears, New Media Corporation
28 Tom Pollard, New Media Corporation
29 Dean Siasoyco, New Media Corporation
30 Ken Lesniak, Silicon Graphics, Inc. <lesniak@boston.sgi.com>
31 Donald Becker <becker@scyld.com>
32 David Hinds <dahinds@users.sourceforge.net>
33
34 The Linux client driver is based on the 3c589_cs.c client driver by
35 David Hinds.
36
37 The Linux network driver outline is based on the 3c589_cs.c driver,
38 the 8390.c driver, and the example skeleton.c kernel code, which are
39 by Donald Becker.
40
41 The Am2150 network driver hardware interface code is based on the
42 OS/9000 driver for the New Media Ethernet LAN by Eric Mears.
43
44 Special thanks for testing and help in debugging this driver goes
45 to Ken Lesniak.
46
47-------------------------------------------------------------------------------
48Driver Notes and Issues
49-------------------------------------------------------------------------------
50
511. Developed on a Dell 320SLi
52 PCMCIA Card Services 2.6.2
53 Linux dell 1.2.10 #1 Thu Jun 29 20:23:41 PDT 1995 i386
54
552. rc.pcmcia may require loading pcmcia_core with io_speed=300:
56 'insmod pcmcia_core.o io_speed=300'.
57 This will avoid problems with fast systems which causes rx_framecnt
58 to return random values.
59
603. If hot extraction does not work for you, use 'ifconfig eth0 down'
61 before extraction.
62
634. There is a bad slow-down problem in this driver.
64
655. Future: Multicast processing. In the meantime, do _not_ compile your
66 kernel with multicast ip enabled.
67
68-------------------------------------------------------------------------------
69History
70-------------------------------------------------------------------------------
71Log: nmclan_cs.c,v
72 * 2.5.75-ac1 2003/07/11 Alan Cox <alan@lxorguk.ukuu.org.uk>
73 * Fixed hang on card eject as we probe it
74 * Cleaned up to use new style locking.
75 *
76 * Revision 0.16 1995/07/01 06:42:17 rpao
77 * Bug fix: nmclan_reset() called CardServices incorrectly.
78 *
79 * Revision 0.15 1995/05/24 08:09:47 rpao
80 * Re-implement MULTI_TX dev->tbusy handling.
81 *
82 * Revision 0.14 1995/05/23 03:19:30 rpao
83 * Added, in nmclan_config(), "tuple.Attributes = 0;".
84 * Modified MACE ID check to ignore chip revision level.
85 * Avoid tx_free_frames race condition between _start_xmit and _interrupt.
86 *
87 * Revision 0.13 1995/05/18 05:56:34 rpao
88 * Statistics changes.
89 * Bug fix: nmclan_reset did not enable TX and RX: call restore_multicast_list.
90 * Bug fix: mace_interrupt checks ~MACE_IMR_DEFAULT. Fixes driver lockup.
91 *
92 * Revision 0.12 1995/05/14 00:12:23 rpao
93 * Statistics overhaul.
94 *
95
9695/05/13 rpao V0.10a
97 Bug fix: MACE statistics counters used wrong I/O ports.
98 Bug fix: mace_interrupt() needed to allow statistics to be
99 processed without RX or TX interrupts pending.
10095/05/11 rpao V0.10
101 Multiple transmit request processing.
102 Modified statistics to use MACE counters where possible.
10395/05/10 rpao V0.09 Bug fix: Must use IO_DATA_PATH_WIDTH_AUTO.
104 *Released
10595/05/10 rpao V0.08
106 Bug fix: Make all non-exported functions private by using
107 static keyword.
108 Bug fix: Test IntrCnt _before_ reading MACE_IR.
10995/05/10 rpao V0.07 Statistics.
11095/05/09 rpao V0.06 Fix rx_framecnt problem by addition of PCIC wait states.
111
112---------------------------------------------------------------------------- */
113
114#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
115
116#define DRV_NAME "nmclan_cs"
117#define DRV_VERSION "0.16"
118
119
120/* ----------------------------------------------------------------------------
121Conditional Compilation Options
122---------------------------------------------------------------------------- */
123
124#define MULTI_TX 0
125#define RESET_ON_TIMEOUT 1
126#define TX_INTERRUPTABLE 1
127#define RESET_XILINX 0
128
129/* ----------------------------------------------------------------------------
130Include Files
131---------------------------------------------------------------------------- */
132
133#include <linux/module.h>
134#include <linux/kernel.h>
135#include <linux/init.h>
136#include <linux/ptrace.h>
137#include <linux/slab.h>
138#include <linux/string.h>
139#include <linux/timer.h>
140#include <linux/interrupt.h>
141#include <linux/in.h>
142#include <linux/delay.h>
143#include <linux/ethtool.h>
144#include <linux/netdevice.h>
145#include <linux/etherdevice.h>
146#include <linux/skbuff.h>
147#include <linux/if_arp.h>
148#include <linux/ioport.h>
149#include <linux/bitops.h>
150
151#include <pcmcia/cisreg.h>
152#include <pcmcia/cistpl.h>
153#include <pcmcia/ds.h>
154
155#include <asm/uaccess.h>
156#include <asm/io.h>
157#include <asm/system.h>
158
159/* ----------------------------------------------------------------------------
160Defines
161---------------------------------------------------------------------------- */
162
163#define ETHER_ADDR_LEN ETH_ALEN
164 /* 6 bytes in an Ethernet Address */
165#define MACE_LADRF_LEN 8
166 /* 8 bytes in Logical Address Filter */
167
168/* Loop Control Defines */
169#define MACE_MAX_IR_ITERATIONS 10
170#define MACE_MAX_RX_ITERATIONS 12
171 /*
172 TBD: Dean brought this up, and I assumed the hardware would
173 handle it:
174
175 If MACE_MAX_RX_ITERATIONS is > 1, rx_framecnt may still be
176 non-zero when the isr exits. We may not get another interrupt
177 to process the remaining packets for some time.
178 */
179
180/*
181The Am2150 has a Xilinx XC3042 field programmable gate array (FPGA)
182which manages the interface between the MACE and the PCMCIA bus. It
183also includes buffer management for the 32K x 8 SRAM to control up to
184four transmit and 12 receive frames at a time.
185*/
186#define AM2150_MAX_TX_FRAMES 4
187#define AM2150_MAX_RX_FRAMES 12
188
189/* Am2150 Ethernet Card I/O Mapping */
190#define AM2150_RCV 0x00
191#define AM2150_XMT 0x04
192#define AM2150_XMT_SKIP 0x09
193#define AM2150_RCV_NEXT 0x0A
194#define AM2150_RCV_FRAME_COUNT 0x0B
195#define AM2150_MACE_BANK 0x0C
196#define AM2150_MACE_BASE 0x10
197
198/* MACE Registers */
199#define MACE_RCVFIFO 0
200#define MACE_XMTFIFO 1
201#define MACE_XMTFC 2
202#define MACE_XMTFS 3
203#define MACE_XMTRC 4
204#define MACE_RCVFC 5
205#define MACE_RCVFS 6
206#define MACE_FIFOFC 7
207#define MACE_IR 8
208#define MACE_IMR 9
209#define MACE_PR 10
210#define MACE_BIUCC 11
211#define MACE_FIFOCC 12
212#define MACE_MACCC 13
213#define MACE_PLSCC 14
214#define MACE_PHYCC 15
215#define MACE_CHIPIDL 16
216#define MACE_CHIPIDH 17
217#define MACE_IAC 18
218/* Reserved */
219#define MACE_LADRF 20
220#define MACE_PADR 21
221/* Reserved */
222/* Reserved */
223#define MACE_MPC 24
224/* Reserved */
225#define MACE_RNTPC 26
226#define MACE_RCVCC 27
227/* Reserved */
228#define MACE_UTR 29
229#define MACE_RTR1 30
230#define MACE_RTR2 31
231
232/* MACE Bit Masks */
233#define MACE_XMTRC_EXDEF 0x80
234#define MACE_XMTRC_XMTRC 0x0F
235
236#define MACE_XMTFS_XMTSV 0x80
237#define MACE_XMTFS_UFLO 0x40
238#define MACE_XMTFS_LCOL 0x20
239#define MACE_XMTFS_MORE 0x10
240#define MACE_XMTFS_ONE 0x08
241#define MACE_XMTFS_DEFER 0x04
242#define MACE_XMTFS_LCAR 0x02
243#define MACE_XMTFS_RTRY 0x01
244
245#define MACE_RCVFS_RCVSTS 0xF000
246#define MACE_RCVFS_OFLO 0x8000
247#define MACE_RCVFS_CLSN 0x4000
248#define MACE_RCVFS_FRAM 0x2000
249#define MACE_RCVFS_FCS 0x1000
250
251#define MACE_FIFOFC_RCVFC 0xF0
252#define MACE_FIFOFC_XMTFC 0x0F
253
254#define MACE_IR_JAB 0x80
255#define MACE_IR_BABL 0x40
256#define MACE_IR_CERR 0x20
257#define MACE_IR_RCVCCO 0x10
258#define MACE_IR_RNTPCO 0x08
259#define MACE_IR_MPCO 0x04
260#define MACE_IR_RCVINT 0x02
261#define MACE_IR_XMTINT 0x01
262
263#define MACE_MACCC_PROM 0x80
264#define MACE_MACCC_DXMT2PD 0x40
265#define MACE_MACCC_EMBA 0x20
266#define MACE_MACCC_RESERVED 0x10
267#define MACE_MACCC_DRCVPA 0x08
268#define MACE_MACCC_DRCVBC 0x04
269#define MACE_MACCC_ENXMT 0x02
270#define MACE_MACCC_ENRCV 0x01
271
272#define MACE_PHYCC_LNKFL 0x80
273#define MACE_PHYCC_DLNKTST 0x40
274#define MACE_PHYCC_REVPOL 0x20
275#define MACE_PHYCC_DAPC 0x10
276#define MACE_PHYCC_LRT 0x08
277#define MACE_PHYCC_ASEL 0x04
278#define MACE_PHYCC_RWAKE 0x02
279#define MACE_PHYCC_AWAKE 0x01
280
281#define MACE_IAC_ADDRCHG 0x80
282#define MACE_IAC_PHYADDR 0x04
283#define MACE_IAC_LOGADDR 0x02
284
285#define MACE_UTR_RTRE 0x80
286#define MACE_UTR_RTRD 0x40
287#define MACE_UTR_RPA 0x20
288#define MACE_UTR_FCOLL 0x10
289#define MACE_UTR_RCVFCSE 0x08
290#define MACE_UTR_LOOP_INCL_MENDEC 0x06
291#define MACE_UTR_LOOP_NO_MENDEC 0x04
292#define MACE_UTR_LOOP_EXTERNAL 0x02
293#define MACE_UTR_LOOP_NONE 0x00
294#define MACE_UTR_RESERVED 0x01
295
296/* Switch MACE register bank (only 0 and 1 are valid) */
297#define MACEBANK(win_num) outb((win_num), ioaddr + AM2150_MACE_BANK)
298
299#define MACE_IMR_DEFAULT \
300 (0xFF - \
301 ( \
302 MACE_IR_CERR | \
303 MACE_IR_RCVCCO | \
304 MACE_IR_RNTPCO | \
305 MACE_IR_MPCO | \
306 MACE_IR_RCVINT | \
307 MACE_IR_XMTINT \
308 ) \
309 )
310#undef MACE_IMR_DEFAULT
311#define MACE_IMR_DEFAULT 0x00 /* New statistics handling: grab everything */
312
313#define TX_TIMEOUT ((400*HZ)/1000)
314
315/* ----------------------------------------------------------------------------
316Type Definitions
317---------------------------------------------------------------------------- */
318
319typedef struct _mace_statistics {
320 /* MACE_XMTFS */
321 int xmtsv;
322 int uflo;
323 int lcol;
324 int more;
325 int one;
326 int defer;
327 int lcar;
328 int rtry;
329
330 /* MACE_XMTRC */
331 int exdef;
332 int xmtrc;
333
334 /* RFS1--Receive Status (RCVSTS) */
335 int oflo;
336 int clsn;
337 int fram;
338 int fcs;
339
340 /* RFS2--Runt Packet Count (RNTPC) */
341 int rfs_rntpc;
342
343 /* RFS3--Receive Collision Count (RCVCC) */
344 int rfs_rcvcc;
345
346 /* MACE_IR */
347 int jab;
348 int babl;
349 int cerr;
350 int rcvcco;
351 int rntpco;
352 int mpco;
353
354 /* MACE_MPC */
355 int mpc;
356
357 /* MACE_RNTPC */
358 int rntpc;
359
360 /* MACE_RCVCC */
361 int rcvcc;
362} mace_statistics;
363
364typedef struct _mace_private {
365 struct pcmcia_device *p_dev;
366 struct net_device_stats linux_stats; /* Linux statistics counters */
367 mace_statistics mace_stats; /* MACE chip statistics counters */
368
369 /* restore_multicast_list() state variables */
370 int multicast_ladrf[MACE_LADRF_LEN]; /* Logical address filter */
371 int multicast_num_addrs;
372
373 char tx_free_frames; /* Number of free transmit frame buffers */
374 char tx_irq_disabled; /* MACE TX interrupt disabled */
375
376 spinlock_t bank_lock; /* Must be held if you step off bank 0 */
377} mace_private;
378
379/* ----------------------------------------------------------------------------
380Private Global Variables
381---------------------------------------------------------------------------- */
382
383static const char *if_names[]={
384 "Auto", "10baseT", "BNC",
385};
386
387/* ----------------------------------------------------------------------------
388Parameters
389 These are the parameters that can be set during loading with
390 'insmod'.
391---------------------------------------------------------------------------- */
392
393MODULE_DESCRIPTION("New Media PCMCIA ethernet driver");
394MODULE_LICENSE("GPL");
395
396#define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0)
397
398/* 0=auto, 1=10baseT, 2 = 10base2, default=auto */
399INT_MODULE_PARM(if_port, 0);
400
401
402/* ----------------------------------------------------------------------------
403Function Prototypes
404---------------------------------------------------------------------------- */
405
406static int nmclan_config(struct pcmcia_device *link);
407static void nmclan_release(struct pcmcia_device *link);
408
409static void nmclan_reset(struct net_device *dev);
410static int mace_config(struct net_device *dev, struct ifmap *map);
411static int mace_open(struct net_device *dev);
412static int mace_close(struct net_device *dev);
413static netdev_tx_t mace_start_xmit(struct sk_buff *skb,
414 struct net_device *dev);
415static void mace_tx_timeout(struct net_device *dev);
416static irqreturn_t mace_interrupt(int irq, void *dev_id);
417static struct net_device_stats *mace_get_stats(struct net_device *dev);
418static int mace_rx(struct net_device *dev, unsigned char RxCnt);
419static void restore_multicast_list(struct net_device *dev);
420static void set_multicast_list(struct net_device *dev);
421static const struct ethtool_ops netdev_ethtool_ops;
422
423
424static void nmclan_detach(struct pcmcia_device *p_dev);
425
426static const struct net_device_ops mace_netdev_ops = {
427 .ndo_open = mace_open,
428 .ndo_stop = mace_close,
429 .ndo_start_xmit = mace_start_xmit,
430 .ndo_tx_timeout = mace_tx_timeout,
431 .ndo_set_config = mace_config,
432 .ndo_get_stats = mace_get_stats,
433 .ndo_set_multicast_list = set_multicast_list,
434 .ndo_change_mtu = eth_change_mtu,
435 .ndo_set_mac_address = eth_mac_addr,
436 .ndo_validate_addr = eth_validate_addr,
437};
438
439static int nmclan_probe(struct pcmcia_device *link)
440{
441 mace_private *lp;
442 struct net_device *dev;
443
444 dev_dbg(&link->dev, "nmclan_attach()\n");
445
446 /* Create new ethernet device */
447 dev = alloc_etherdev(sizeof(mace_private));
448 if (!dev)
449 return -ENOMEM;
450 lp = netdev_priv(dev);
451 lp->p_dev = link;
452 link->priv = dev;
453
454 spin_lock_init(&lp->bank_lock);
455 link->resource[0]->end = 32;
456 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
457 link->config_flags |= CONF_ENABLE_IRQ;
458 link->config_index = 1;
459 link->config_regs = PRESENT_OPTION;
460
461 lp->tx_free_frames=AM2150_MAX_TX_FRAMES;
462
463 dev->netdev_ops = &mace_netdev_ops;
464 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
465 dev->watchdog_timeo = TX_TIMEOUT;
466
467 return nmclan_config(link);
468} /* nmclan_attach */
469
470static void nmclan_detach(struct pcmcia_device *link)
471{
472 struct net_device *dev = link->priv;
473
474 dev_dbg(&link->dev, "nmclan_detach\n");
475
476 unregister_netdev(dev);
477
478 nmclan_release(link);
479
480 free_netdev(dev);
481} /* nmclan_detach */
482
483/* ----------------------------------------------------------------------------
484mace_read
485 Reads a MACE register. This is bank independent; however, the
486 caller must ensure that this call is not interruptable. We are
487 assuming that during normal operation, the MACE is always in
488 bank 0.
489---------------------------------------------------------------------------- */
490static int mace_read(mace_private *lp, unsigned int ioaddr, int reg)
491{
492 int data = 0xFF;
493 unsigned long flags;
494
495 switch (reg >> 4) {
496 case 0: /* register 0-15 */
497 data = inb(ioaddr + AM2150_MACE_BASE + reg);
498 break;
499 case 1: /* register 16-31 */
500 spin_lock_irqsave(&lp->bank_lock, flags);
501 MACEBANK(1);
502 data = inb(ioaddr + AM2150_MACE_BASE + (reg & 0x0F));
503 MACEBANK(0);
504 spin_unlock_irqrestore(&lp->bank_lock, flags);
505 break;
506 }
507 return data & 0xFF;
508} /* mace_read */
509
510/* ----------------------------------------------------------------------------
511mace_write
512 Writes to a MACE register. This is bank independent; however,
513 the caller must ensure that this call is not interruptable. We
514 are assuming that during normal operation, the MACE is always in
515 bank 0.
516---------------------------------------------------------------------------- */
517static void mace_write(mace_private *lp, unsigned int ioaddr, int reg,
518 int data)
519{
520 unsigned long flags;
521
522 switch (reg >> 4) {
523 case 0: /* register 0-15 */
524 outb(data & 0xFF, ioaddr + AM2150_MACE_BASE + reg);
525 break;
526 case 1: /* register 16-31 */
527 spin_lock_irqsave(&lp->bank_lock, flags);
528 MACEBANK(1);
529 outb(data & 0xFF, ioaddr + AM2150_MACE_BASE + (reg & 0x0F));
530 MACEBANK(0);
531 spin_unlock_irqrestore(&lp->bank_lock, flags);
532 break;
533 }
534} /* mace_write */
535
536/* ----------------------------------------------------------------------------
537mace_init
538 Resets the MACE chip.
539---------------------------------------------------------------------------- */
540static int mace_init(mace_private *lp, unsigned int ioaddr, char *enet_addr)
541{
542 int i;
543 int ct = 0;
544
545 /* MACE Software reset */
546 mace_write(lp, ioaddr, MACE_BIUCC, 1);
547 while (mace_read(lp, ioaddr, MACE_BIUCC) & 0x01) {
548 /* Wait for reset bit to be cleared automatically after <= 200ns */;
549 if(++ct > 500)
550 {
551 pr_err("reset failed, card removed?\n");
552 return -1;
553 }
554 udelay(1);
555 }
556 mace_write(lp, ioaddr, MACE_BIUCC, 0);
557
558 /* The Am2150 requires that the MACE FIFOs operate in burst mode. */
559 mace_write(lp, ioaddr, MACE_FIFOCC, 0x0F);
560
561 mace_write(lp,ioaddr, MACE_RCVFC, 0); /* Disable Auto Strip Receive */
562 mace_write(lp, ioaddr, MACE_IMR, 0xFF); /* Disable all interrupts until _open */
563
564 /*
565 * Bit 2-1 PORTSEL[1-0] Port Select.
566 * 00 AUI/10Base-2
567 * 01 10Base-T
568 * 10 DAI Port (reserved in Am2150)
569 * 11 GPSI
570 * For this card, only the first two are valid.
571 * So, PLSCC should be set to
572 * 0x00 for 10Base-2
573 * 0x02 for 10Base-T
574 * Or just set ASEL in PHYCC below!
575 */
576 switch (if_port) {
577 case 1:
578 mace_write(lp, ioaddr, MACE_PLSCC, 0x02);
579 break;
580 case 2:
581 mace_write(lp, ioaddr, MACE_PLSCC, 0x00);
582 break;
583 default:
584 mace_write(lp, ioaddr, MACE_PHYCC, /* ASEL */ 4);
585 /* ASEL Auto Select. When set, the PORTSEL[1-0] bits are overridden,
586 and the MACE device will automatically select the operating media
587 interface port. */
588 break;
589 }
590
591 mace_write(lp, ioaddr, MACE_IAC, MACE_IAC_ADDRCHG | MACE_IAC_PHYADDR);
592 /* Poll ADDRCHG bit */
593 ct = 0;
594 while (mace_read(lp, ioaddr, MACE_IAC) & MACE_IAC_ADDRCHG)
595 {
596 if(++ ct > 500)
597 {
598 pr_err("ADDRCHG timeout, card removed?\n");
599 return -1;
600 }
601 }
602 /* Set PADR register */
603 for (i = 0; i < ETHER_ADDR_LEN; i++)
604 mace_write(lp, ioaddr, MACE_PADR, enet_addr[i]);
605
606 /* MAC Configuration Control Register should be written last */
607 /* Let set_multicast_list set this. */
608 /* mace_write(lp, ioaddr, MACE_MACCC, MACE_MACCC_ENXMT | MACE_MACCC_ENRCV); */
609 mace_write(lp, ioaddr, MACE_MACCC, 0x00);
610 return 0;
611} /* mace_init */
612
613static int nmclan_config(struct pcmcia_device *link)
614{
615 struct net_device *dev = link->priv;
616 mace_private *lp = netdev_priv(dev);
617 u8 *buf;
618 size_t len;
619 int i, ret;
620 unsigned int ioaddr;
621
622 dev_dbg(&link->dev, "nmclan_config\n");
623
624 link->io_lines = 5;
625 ret = pcmcia_request_io(link);
626 if (ret)
627 goto failed;
628 ret = pcmcia_request_exclusive_irq(link, mace_interrupt);
629 if (ret)
630 goto failed;
631 ret = pcmcia_enable_device(link);
632 if (ret)
633 goto failed;
634
635 dev->irq = link->irq;
636 dev->base_addr = link->resource[0]->start;
637
638 ioaddr = dev->base_addr;
639
640 /* Read the ethernet address from the CIS. */
641 len = pcmcia_get_tuple(link, 0x80, &buf);
642 if (!buf || len < ETHER_ADDR_LEN) {
643 kfree(buf);
644 goto failed;
645 }
646 memcpy(dev->dev_addr, buf, ETHER_ADDR_LEN);
647 kfree(buf);
648
649 /* Verify configuration by reading the MACE ID. */
650 {
651 char sig[2];
652
653 sig[0] = mace_read(lp, ioaddr, MACE_CHIPIDL);
654 sig[1] = mace_read(lp, ioaddr, MACE_CHIPIDH);
655 if ((sig[0] == 0x40) && ((sig[1] & 0x0F) == 0x09)) {
656 dev_dbg(&link->dev, "nmclan_cs configured: mace id=%x %x\n",
657 sig[0], sig[1]);
658 } else {
659 pr_notice("mace id not found: %x %x should be 0x40 0x?9\n",
660 sig[0], sig[1]);
661 return -ENODEV;
662 }
663 }
664
665 if(mace_init(lp, ioaddr, dev->dev_addr) == -1)
666 goto failed;
667
668 /* The if_port symbol can be set when the module is loaded */
669 if (if_port <= 2)
670 dev->if_port = if_port;
671 else
672 pr_notice("invalid if_port requested\n");
673
674 SET_NETDEV_DEV(dev, &link->dev);
675
676 i = register_netdev(dev);
677 if (i != 0) {
678 pr_notice("register_netdev() failed\n");
679 goto failed;
680 }
681
682 netdev_info(dev, "nmclan: port %#3lx, irq %d, %s port, hw_addr %pM\n",
683 dev->base_addr, dev->irq, if_names[dev->if_port], dev->dev_addr);
684 return 0;
685
686failed:
687 nmclan_release(link);
688 return -ENODEV;
689} /* nmclan_config */
690
691static void nmclan_release(struct pcmcia_device *link)
692{
693 dev_dbg(&link->dev, "nmclan_release\n");
694 pcmcia_disable_device(link);
695}
696
697static int nmclan_suspend(struct pcmcia_device *link)
698{
699 struct net_device *dev = link->priv;
700
701 if (link->open)
702 netif_device_detach(dev);
703
704 return 0;
705}
706
707static int nmclan_resume(struct pcmcia_device *link)
708{
709 struct net_device *dev = link->priv;
710
711 if (link->open) {
712 nmclan_reset(dev);
713 netif_device_attach(dev);
714 }
715
716 return 0;
717}
718
719
720/* ----------------------------------------------------------------------------
721nmclan_reset
722 Reset and restore all of the Xilinx and MACE registers.
723---------------------------------------------------------------------------- */
724static void nmclan_reset(struct net_device *dev)
725{
726 mace_private *lp = netdev_priv(dev);
727
728#if RESET_XILINX
729 struct pcmcia_device *link = &lp->link;
730 u8 OrigCorValue;
731
732 /* Save original COR value */
733 pcmcia_read_config_byte(link, CISREG_COR, &OrigCorValue);
734
735 /* Reset Xilinx */
736 dev_dbg(&link->dev, "nmclan_reset: OrigCorValue=0x%x, resetting...\n",
737 OrigCorValue);
738 pcmcia_write_config_byte(link, CISREG_COR, COR_SOFT_RESET);
739 /* Need to wait for 20 ms for PCMCIA to finish reset. */
740
741 /* Restore original COR configuration index */
742 pcmcia_write_config_byte(link, CISREG_COR,
743 (COR_LEVEL_REQ | (OrigCorValue & COR_CONFIG_MASK)));
744 /* Xilinx is now completely reset along with the MACE chip. */
745 lp->tx_free_frames=AM2150_MAX_TX_FRAMES;
746
747#endif /* #if RESET_XILINX */
748
749 /* Xilinx is now completely reset along with the MACE chip. */
750 lp->tx_free_frames=AM2150_MAX_TX_FRAMES;
751
752 /* Reinitialize the MACE chip for operation. */
753 mace_init(lp, dev->base_addr, dev->dev_addr);
754 mace_write(lp, dev->base_addr, MACE_IMR, MACE_IMR_DEFAULT);
755
756 /* Restore the multicast list and enable TX and RX. */
757 restore_multicast_list(dev);
758} /* nmclan_reset */
759
760/* ----------------------------------------------------------------------------
761mace_config
762 [Someone tell me what this is supposed to do? Is if_port a defined
763 standard? If so, there should be defines to indicate 1=10Base-T,
764 2=10Base-2, etc. including limited automatic detection.]
765---------------------------------------------------------------------------- */
766static int mace_config(struct net_device *dev, struct ifmap *map)
767{
768 if ((map->port != (u_char)(-1)) && (map->port != dev->if_port)) {
769 if (map->port <= 2) {
770 dev->if_port = map->port;
771 netdev_info(dev, "switched to %s port\n", if_names[dev->if_port]);
772 } else
773 return -EINVAL;
774 }
775 return 0;
776} /* mace_config */
777
778/* ----------------------------------------------------------------------------
779mace_open
780 Open device driver.
781---------------------------------------------------------------------------- */
782static int mace_open(struct net_device *dev)
783{
784 unsigned int ioaddr = dev->base_addr;
785 mace_private *lp = netdev_priv(dev);
786 struct pcmcia_device *link = lp->p_dev;
787
788 if (!pcmcia_dev_present(link))
789 return -ENODEV;
790
791 link->open++;
792
793 MACEBANK(0);
794
795 netif_start_queue(dev);
796 nmclan_reset(dev);
797
798 return 0; /* Always succeed */
799} /* mace_open */
800
801/* ----------------------------------------------------------------------------
802mace_close
803 Closes device driver.
804---------------------------------------------------------------------------- */
805static int mace_close(struct net_device *dev)
806{
807 unsigned int ioaddr = dev->base_addr;
808 mace_private *lp = netdev_priv(dev);
809 struct pcmcia_device *link = lp->p_dev;
810
811 dev_dbg(&link->dev, "%s: shutting down ethercard.\n", dev->name);
812
813 /* Mask off all interrupts from the MACE chip. */
814 outb(0xFF, ioaddr + AM2150_MACE_BASE + MACE_IMR);
815
816 link->open--;
817 netif_stop_queue(dev);
818
819 return 0;
820} /* mace_close */
821
822static void netdev_get_drvinfo(struct net_device *dev,
823 struct ethtool_drvinfo *info)
824{
825 strcpy(info->driver, DRV_NAME);
826 strcpy(info->version, DRV_VERSION);
827 sprintf(info->bus_info, "PCMCIA 0x%lx", dev->base_addr);
828}
829
830static const struct ethtool_ops netdev_ethtool_ops = {
831 .get_drvinfo = netdev_get_drvinfo,
832};
833
834/* ----------------------------------------------------------------------------
835mace_start_xmit
836 This routine begins the packet transmit function. When completed,
837 it will generate a transmit interrupt.
838
839 According to /usr/src/linux/net/inet/dev.c, if _start_xmit
840 returns 0, the "packet is now solely the responsibility of the
841 driver." If _start_xmit returns non-zero, the "transmission
842 failed, put skb back into a list."
843---------------------------------------------------------------------------- */
844
845static void mace_tx_timeout(struct net_device *dev)
846{
847 mace_private *lp = netdev_priv(dev);
848 struct pcmcia_device *link = lp->p_dev;
849
850 netdev_notice(dev, "transmit timed out -- ");
851#if RESET_ON_TIMEOUT
852 pr_cont("resetting card\n");
853 pcmcia_reset_card(link->socket);
854#else /* #if RESET_ON_TIMEOUT */
855 pr_cont("NOT resetting card\n");
856#endif /* #if RESET_ON_TIMEOUT */
857 dev->trans_start = jiffies; /* prevent tx timeout */
858 netif_wake_queue(dev);
859}
860
861static netdev_tx_t mace_start_xmit(struct sk_buff *skb,
862 struct net_device *dev)
863{
864 mace_private *lp = netdev_priv(dev);
865 unsigned int ioaddr = dev->base_addr;
866
867 netif_stop_queue(dev);
868
869 pr_debug("%s: mace_start_xmit(length = %ld) called.\n",
870 dev->name, (long)skb->len);
871
872#if (!TX_INTERRUPTABLE)
873 /* Disable MACE TX interrupts. */
874 outb(MACE_IMR_DEFAULT | MACE_IR_XMTINT,
875 ioaddr + AM2150_MACE_BASE + MACE_IMR);
876 lp->tx_irq_disabled=1;
877#endif /* #if (!TX_INTERRUPTABLE) */
878
879 {
880 /* This block must not be interrupted by another transmit request!
881 mace_tx_timeout will take care of timer-based retransmissions from
882 the upper layers. The interrupt handler is guaranteed never to
883 service a transmit interrupt while we are in here.
884 */
885
886 lp->linux_stats.tx_bytes += skb->len;
887 lp->tx_free_frames--;
888
889 /* WARNING: Write the _exact_ number of bytes written in the header! */
890 /* Put out the word header [must be an outw()] . . . */
891 outw(skb->len, ioaddr + AM2150_XMT);
892 /* . . . and the packet [may be any combination of outw() and outb()] */
893 outsw(ioaddr + AM2150_XMT, skb->data, skb->len >> 1);
894 if (skb->len & 1) {
895 /* Odd byte transfer */
896 outb(skb->data[skb->len-1], ioaddr + AM2150_XMT);
897 }
898
899#if MULTI_TX
900 if (lp->tx_free_frames > 0)
901 netif_start_queue(dev);
902#endif /* #if MULTI_TX */
903 }
904
905#if (!TX_INTERRUPTABLE)
906 /* Re-enable MACE TX interrupts. */
907 lp->tx_irq_disabled=0;
908 outb(MACE_IMR_DEFAULT, ioaddr + AM2150_MACE_BASE + MACE_IMR);
909#endif /* #if (!TX_INTERRUPTABLE) */
910
911 dev_kfree_skb(skb);
912
913 return NETDEV_TX_OK;
914} /* mace_start_xmit */
915
916/* ----------------------------------------------------------------------------
917mace_interrupt
918 The interrupt handler.
919---------------------------------------------------------------------------- */
920static irqreturn_t mace_interrupt(int irq, void *dev_id)
921{
922 struct net_device *dev = (struct net_device *) dev_id;
923 mace_private *lp = netdev_priv(dev);
924 unsigned int ioaddr;
925 int status;
926 int IntrCnt = MACE_MAX_IR_ITERATIONS;
927
928 if (dev == NULL) {
929 pr_debug("mace_interrupt(): irq 0x%X for unknown device.\n",
930 irq);
931 return IRQ_NONE;
932 }
933
934 ioaddr = dev->base_addr;
935
936 if (lp->tx_irq_disabled) {
937 const char *msg;
938 if (lp->tx_irq_disabled)
939 msg = "Interrupt with tx_irq_disabled";
940 else
941 msg = "Re-entering the interrupt handler";
942 netdev_notice(dev, "%s [isr=%02X, imr=%02X]\n",
943 msg,
944 inb(ioaddr + AM2150_MACE_BASE + MACE_IR),
945 inb(ioaddr + AM2150_MACE_BASE + MACE_IMR));
946 /* WARNING: MACE_IR has been read! */
947 return IRQ_NONE;
948 }
949
950 if (!netif_device_present(dev)) {
951 netdev_dbg(dev, "interrupt from dead card\n");
952 return IRQ_NONE;
953 }
954
955 do {
956 /* WARNING: MACE_IR is a READ/CLEAR port! */
957 status = inb(ioaddr + AM2150_MACE_BASE + MACE_IR);
958
959 pr_debug("mace_interrupt: irq 0x%X status 0x%X.\n", irq, status);
960
961 if (status & MACE_IR_RCVINT) {
962 mace_rx(dev, MACE_MAX_RX_ITERATIONS);
963 }
964
965 if (status & MACE_IR_XMTINT) {
966 unsigned char fifofc;
967 unsigned char xmtrc;
968 unsigned char xmtfs;
969
970 fifofc = inb(ioaddr + AM2150_MACE_BASE + MACE_FIFOFC);
971 if ((fifofc & MACE_FIFOFC_XMTFC)==0) {
972 lp->linux_stats.tx_errors++;
973 outb(0xFF, ioaddr + AM2150_XMT_SKIP);
974 }
975
976 /* Transmit Retry Count (XMTRC, reg 4) */
977 xmtrc = inb(ioaddr + AM2150_MACE_BASE + MACE_XMTRC);
978 if (xmtrc & MACE_XMTRC_EXDEF) lp->mace_stats.exdef++;
979 lp->mace_stats.xmtrc += (xmtrc & MACE_XMTRC_XMTRC);
980
981 if (
982 (xmtfs = inb(ioaddr + AM2150_MACE_BASE + MACE_XMTFS)) &
983 MACE_XMTFS_XMTSV /* Transmit Status Valid */
984 ) {
985 lp->mace_stats.xmtsv++;
986
987 if (xmtfs & ~MACE_XMTFS_XMTSV) {
988 if (xmtfs & MACE_XMTFS_UFLO) {
989 /* Underflow. Indicates that the Transmit FIFO emptied before
990 the end of frame was reached. */
991 lp->mace_stats.uflo++;
992 }
993 if (xmtfs & MACE_XMTFS_LCOL) {
994 /* Late Collision */
995 lp->mace_stats.lcol++;
996 }
997 if (xmtfs & MACE_XMTFS_MORE) {
998 /* MORE than one retry was needed */
999 lp->mace_stats.more++;
1000 }
1001 if (xmtfs & MACE_XMTFS_ONE) {
1002 /* Exactly ONE retry occurred */
1003 lp->mace_stats.one++;
1004 }
1005 if (xmtfs & MACE_XMTFS_DEFER) {
1006 /* Transmission was defered */
1007 lp->mace_stats.defer++;
1008 }
1009 if (xmtfs & MACE_XMTFS_LCAR) {
1010 /* Loss of carrier */
1011 lp->mace_stats.lcar++;
1012 }
1013 if (xmtfs & MACE_XMTFS_RTRY) {
1014 /* Retry error: transmit aborted after 16 attempts */
1015 lp->mace_stats.rtry++;
1016 }
1017 } /* if (xmtfs & ~MACE_XMTFS_XMTSV) */
1018
1019 } /* if (xmtfs & MACE_XMTFS_XMTSV) */
1020
1021 lp->linux_stats.tx_packets++;
1022 lp->tx_free_frames++;
1023 netif_wake_queue(dev);
1024 } /* if (status & MACE_IR_XMTINT) */
1025
1026 if (status & ~MACE_IMR_DEFAULT & ~MACE_IR_RCVINT & ~MACE_IR_XMTINT) {
1027 if (status & MACE_IR_JAB) {
1028 /* Jabber Error. Excessive transmit duration (20-150ms). */
1029 lp->mace_stats.jab++;
1030 }
1031 if (status & MACE_IR_BABL) {
1032 /* Babble Error. >1518 bytes transmitted. */
1033 lp->mace_stats.babl++;
1034 }
1035 if (status & MACE_IR_CERR) {
1036 /* Collision Error. CERR indicates the absence of the
1037 Signal Quality Error Test message after a packet
1038 transmission. */
1039 lp->mace_stats.cerr++;
1040 }
1041 if (status & MACE_IR_RCVCCO) {
1042 /* Receive Collision Count Overflow; */
1043 lp->mace_stats.rcvcco++;
1044 }
1045 if (status & MACE_IR_RNTPCO) {
1046 /* Runt Packet Count Overflow */
1047 lp->mace_stats.rntpco++;
1048 }
1049 if (status & MACE_IR_MPCO) {
1050 /* Missed Packet Count Overflow */
1051 lp->mace_stats.mpco++;
1052 }
1053 } /* if (status & ~MACE_IMR_DEFAULT & ~MACE_IR_RCVINT & ~MACE_IR_XMTINT) */
1054
1055 } while ((status & ~MACE_IMR_DEFAULT) && (--IntrCnt));
1056
1057 return IRQ_HANDLED;
1058} /* mace_interrupt */
1059
1060/* ----------------------------------------------------------------------------
1061mace_rx
1062 Receives packets.
1063---------------------------------------------------------------------------- */
1064static int mace_rx(struct net_device *dev, unsigned char RxCnt)
1065{
1066 mace_private *lp = netdev_priv(dev);
1067 unsigned int ioaddr = dev->base_addr;
1068 unsigned char rx_framecnt;
1069 unsigned short rx_status;
1070
1071 while (
1072 ((rx_framecnt = inb(ioaddr + AM2150_RCV_FRAME_COUNT)) > 0) &&
1073 (rx_framecnt <= 12) && /* rx_framecnt==0xFF if card is extracted. */
1074 (RxCnt--)
1075 ) {
1076 rx_status = inw(ioaddr + AM2150_RCV);
1077
1078 pr_debug("%s: in mace_rx(), framecnt 0x%X, rx_status"
1079 " 0x%X.\n", dev->name, rx_framecnt, rx_status);
1080
1081 if (rx_status & MACE_RCVFS_RCVSTS) { /* Error, update stats. */
1082 lp->linux_stats.rx_errors++;
1083 if (rx_status & MACE_RCVFS_OFLO) {
1084 lp->mace_stats.oflo++;
1085 }
1086 if (rx_status & MACE_RCVFS_CLSN) {
1087 lp->mace_stats.clsn++;
1088 }
1089 if (rx_status & MACE_RCVFS_FRAM) {
1090 lp->mace_stats.fram++;
1091 }
1092 if (rx_status & MACE_RCVFS_FCS) {
1093 lp->mace_stats.fcs++;
1094 }
1095 } else {
1096 short pkt_len = (rx_status & ~MACE_RCVFS_RCVSTS) - 4;
1097 /* Auto Strip is off, always subtract 4 */
1098 struct sk_buff *skb;
1099
1100 lp->mace_stats.rfs_rntpc += inb(ioaddr + AM2150_RCV);
1101 /* runt packet count */
1102 lp->mace_stats.rfs_rcvcc += inb(ioaddr + AM2150_RCV);
1103 /* rcv collision count */
1104
1105 pr_debug(" receiving packet size 0x%X rx_status"
1106 " 0x%X.\n", pkt_len, rx_status);
1107
1108 skb = dev_alloc_skb(pkt_len+2);
1109
1110 if (skb != NULL) {
1111 skb_reserve(skb, 2);
1112 insw(ioaddr + AM2150_RCV, skb_put(skb, pkt_len), pkt_len>>1);
1113 if (pkt_len & 1)
1114 *(skb_tail_pointer(skb) - 1) = inb(ioaddr + AM2150_RCV);
1115 skb->protocol = eth_type_trans(skb, dev);
1116
1117 netif_rx(skb); /* Send the packet to the upper (protocol) layers. */
1118
1119 lp->linux_stats.rx_packets++;
1120 lp->linux_stats.rx_bytes += pkt_len;
1121 outb(0xFF, ioaddr + AM2150_RCV_NEXT); /* skip to next frame */
1122 continue;
1123 } else {
1124 pr_debug("%s: couldn't allocate a sk_buff of size"
1125 " %d.\n", dev->name, pkt_len);
1126 lp->linux_stats.rx_dropped++;
1127 }
1128 }
1129 outb(0xFF, ioaddr + AM2150_RCV_NEXT); /* skip to next frame */
1130 } /* while */
1131
1132 return 0;
1133} /* mace_rx */
1134
1135/* ----------------------------------------------------------------------------
1136pr_linux_stats
1137---------------------------------------------------------------------------- */
1138static void pr_linux_stats(struct net_device_stats *pstats)
1139{
1140 pr_debug("pr_linux_stats\n");
1141 pr_debug(" rx_packets=%-7ld tx_packets=%ld\n",
1142 (long)pstats->rx_packets, (long)pstats->tx_packets);
1143 pr_debug(" rx_errors=%-7ld tx_errors=%ld\n",
1144 (long)pstats->rx_errors, (long)pstats->tx_errors);
1145 pr_debug(" rx_dropped=%-7ld tx_dropped=%ld\n",
1146 (long)pstats->rx_dropped, (long)pstats->tx_dropped);
1147 pr_debug(" multicast=%-7ld collisions=%ld\n",
1148 (long)pstats->multicast, (long)pstats->collisions);
1149
1150 pr_debug(" rx_length_errors=%-7ld rx_over_errors=%ld\n",
1151 (long)pstats->rx_length_errors, (long)pstats->rx_over_errors);
1152 pr_debug(" rx_crc_errors=%-7ld rx_frame_errors=%ld\n",
1153 (long)pstats->rx_crc_errors, (long)pstats->rx_frame_errors);
1154 pr_debug(" rx_fifo_errors=%-7ld rx_missed_errors=%ld\n",
1155 (long)pstats->rx_fifo_errors, (long)pstats->rx_missed_errors);
1156
1157 pr_debug(" tx_aborted_errors=%-7ld tx_carrier_errors=%ld\n",
1158 (long)pstats->tx_aborted_errors, (long)pstats->tx_carrier_errors);
1159 pr_debug(" tx_fifo_errors=%-7ld tx_heartbeat_errors=%ld\n",
1160 (long)pstats->tx_fifo_errors, (long)pstats->tx_heartbeat_errors);
1161 pr_debug(" tx_window_errors=%ld\n",
1162 (long)pstats->tx_window_errors);
1163} /* pr_linux_stats */
1164
1165/* ----------------------------------------------------------------------------
1166pr_mace_stats
1167---------------------------------------------------------------------------- */
1168static void pr_mace_stats(mace_statistics *pstats)
1169{
1170 pr_debug("pr_mace_stats\n");
1171
1172 pr_debug(" xmtsv=%-7d uflo=%d\n",
1173 pstats->xmtsv, pstats->uflo);
1174 pr_debug(" lcol=%-7d more=%d\n",
1175 pstats->lcol, pstats->more);
1176 pr_debug(" one=%-7d defer=%d\n",
1177 pstats->one, pstats->defer);
1178 pr_debug(" lcar=%-7d rtry=%d\n",
1179 pstats->lcar, pstats->rtry);
1180
1181 /* MACE_XMTRC */
1182 pr_debug(" exdef=%-7d xmtrc=%d\n",
1183 pstats->exdef, pstats->xmtrc);
1184
1185 /* RFS1--Receive Status (RCVSTS) */
1186 pr_debug(" oflo=%-7d clsn=%d\n",
1187 pstats->oflo, pstats->clsn);
1188 pr_debug(" fram=%-7d fcs=%d\n",
1189 pstats->fram, pstats->fcs);
1190
1191 /* RFS2--Runt Packet Count (RNTPC) */
1192 /* RFS3--Receive Collision Count (RCVCC) */
1193 pr_debug(" rfs_rntpc=%-7d rfs_rcvcc=%d\n",
1194 pstats->rfs_rntpc, pstats->rfs_rcvcc);
1195
1196 /* MACE_IR */
1197 pr_debug(" jab=%-7d babl=%d\n",
1198 pstats->jab, pstats->babl);
1199 pr_debug(" cerr=%-7d rcvcco=%d\n",
1200 pstats->cerr, pstats->rcvcco);
1201 pr_debug(" rntpco=%-7d mpco=%d\n",
1202 pstats->rntpco, pstats->mpco);
1203
1204 /* MACE_MPC */
1205 pr_debug(" mpc=%d\n", pstats->mpc);
1206
1207 /* MACE_RNTPC */
1208 pr_debug(" rntpc=%d\n", pstats->rntpc);
1209
1210 /* MACE_RCVCC */
1211 pr_debug(" rcvcc=%d\n", pstats->rcvcc);
1212
1213} /* pr_mace_stats */
1214
1215/* ----------------------------------------------------------------------------
1216update_stats
1217 Update statistics. We change to register window 1, so this
1218 should be run single-threaded if the device is active. This is
1219 expected to be a rare operation, and it's simpler for the rest
1220 of the driver to assume that window 0 is always valid rather
1221 than use a special window-state variable.
1222
1223 oflo & uflo should _never_ occur since it would mean the Xilinx
1224 was not able to transfer data between the MACE FIFO and the
1225 card's SRAM fast enough. If this happens, something is
1226 seriously wrong with the hardware.
1227---------------------------------------------------------------------------- */
1228static void update_stats(unsigned int ioaddr, struct net_device *dev)
1229{
1230 mace_private *lp = netdev_priv(dev);
1231
1232 lp->mace_stats.rcvcc += mace_read(lp, ioaddr, MACE_RCVCC);
1233 lp->mace_stats.rntpc += mace_read(lp, ioaddr, MACE_RNTPC);
1234 lp->mace_stats.mpc += mace_read(lp, ioaddr, MACE_MPC);
1235 /* At this point, mace_stats is fully updated for this call.
1236 We may now update the linux_stats. */
1237
1238 /* The MACE has no equivalent for linux_stats field which are commented
1239 out. */
1240
1241 /* lp->linux_stats.multicast; */
1242 lp->linux_stats.collisions =
1243 lp->mace_stats.rcvcco * 256 + lp->mace_stats.rcvcc;
1244 /* Collision: The MACE may retry sending a packet 15 times
1245 before giving up. The retry count is in XMTRC.
1246 Does each retry constitute a collision?
1247 If so, why doesn't the RCVCC record these collisions? */
1248
1249 /* detailed rx_errors: */
1250 lp->linux_stats.rx_length_errors =
1251 lp->mace_stats.rntpco * 256 + lp->mace_stats.rntpc;
1252 /* lp->linux_stats.rx_over_errors */
1253 lp->linux_stats.rx_crc_errors = lp->mace_stats.fcs;
1254 lp->linux_stats.rx_frame_errors = lp->mace_stats.fram;
1255 lp->linux_stats.rx_fifo_errors = lp->mace_stats.oflo;
1256 lp->linux_stats.rx_missed_errors =
1257 lp->mace_stats.mpco * 256 + lp->mace_stats.mpc;
1258
1259 /* detailed tx_errors */
1260 lp->linux_stats.tx_aborted_errors = lp->mace_stats.rtry;
1261 lp->linux_stats.tx_carrier_errors = lp->mace_stats.lcar;
1262 /* LCAR usually results from bad cabling. */
1263 lp->linux_stats.tx_fifo_errors = lp->mace_stats.uflo;
1264 lp->linux_stats.tx_heartbeat_errors = lp->mace_stats.cerr;
1265 /* lp->linux_stats.tx_window_errors; */
1266} /* update_stats */
1267
1268/* ----------------------------------------------------------------------------
1269mace_get_stats
1270 Gathers ethernet statistics from the MACE chip.
1271---------------------------------------------------------------------------- */
1272static struct net_device_stats *mace_get_stats(struct net_device *dev)
1273{
1274 mace_private *lp = netdev_priv(dev);
1275
1276 update_stats(dev->base_addr, dev);
1277
1278 pr_debug("%s: updating the statistics.\n", dev->name);
1279 pr_linux_stats(&lp->linux_stats);
1280 pr_mace_stats(&lp->mace_stats);
1281
1282 return &lp->linux_stats;
1283} /* net_device_stats */
1284
1285/* ----------------------------------------------------------------------------
1286updateCRC
1287 Modified from Am79C90 data sheet.
1288---------------------------------------------------------------------------- */
1289
1290#ifdef BROKEN_MULTICAST
1291
1292static void updateCRC(int *CRC, int bit)
1293{
1294 static const int poly[]={
1295 1,1,1,0, 1,1,0,1,
1296 1,0,1,1, 1,0,0,0,
1297 1,0,0,0, 0,0,1,1,
1298 0,0,1,0, 0,0,0,0
1299 }; /* CRC polynomial. poly[n] = coefficient of the x**n term of the
1300 CRC generator polynomial. */
1301
1302 int j;
1303
1304 /* shift CRC and control bit (CRC[32]) */
1305 for (j = 32; j > 0; j--)
1306 CRC[j] = CRC[j-1];
1307 CRC[0] = 0;
1308
1309 /* If bit XOR(control bit) = 1, set CRC = CRC XOR polynomial. */
1310 if (bit ^ CRC[32])
1311 for (j = 0; j < 32; j++)
1312 CRC[j] ^= poly[j];
1313} /* updateCRC */
1314
1315/* ----------------------------------------------------------------------------
1316BuildLAF
1317 Build logical address filter.
1318 Modified from Am79C90 data sheet.
1319
1320Input
1321 ladrf: logical address filter (contents initialized to 0)
1322 adr: ethernet address
1323---------------------------------------------------------------------------- */
1324static void BuildLAF(int *ladrf, int *adr)
1325{
1326 int CRC[33]={1}; /* CRC register, 1 word/bit + extra control bit */
1327
1328 int i, byte; /* temporary array indices */
1329 int hashcode; /* the output object */
1330
1331 CRC[32]=0;
1332
1333 for (byte = 0; byte < 6; byte++)
1334 for (i = 0; i < 8; i++)
1335 updateCRC(CRC, (adr[byte] >> i) & 1);
1336
1337 hashcode = 0;
1338 for (i = 0; i < 6; i++)
1339 hashcode = (hashcode << 1) + CRC[i];
1340
1341 byte = hashcode >> 3;
1342 ladrf[byte] |= (1 << (hashcode & 7));
1343
1344#ifdef PCMCIA_DEBUG
1345 if (0)
1346 printk(KERN_DEBUG " adr =%pM\n", adr);
1347 printk(KERN_DEBUG " hashcode = %d(decimal), ladrf[0:63] =", hashcode);
1348 for (i = 0; i < 8; i++)
1349 pr_cont(" %02X", ladrf[i]);
1350 pr_cont("\n");
1351#endif
1352} /* BuildLAF */
1353
1354/* ----------------------------------------------------------------------------
1355restore_multicast_list
1356 Restores the multicast filter for MACE chip to the last
1357 set_multicast_list() call.
1358
1359Input
1360 multicast_num_addrs
1361 multicast_ladrf[]
1362---------------------------------------------------------------------------- */
1363static void restore_multicast_list(struct net_device *dev)
1364{
1365 mace_private *lp = netdev_priv(dev);
1366 int num_addrs = lp->multicast_num_addrs;
1367 int *ladrf = lp->multicast_ladrf;
1368 unsigned int ioaddr = dev->base_addr;
1369 int i;
1370
1371 pr_debug("%s: restoring Rx mode to %d addresses.\n",
1372 dev->name, num_addrs);
1373
1374 if (num_addrs > 0) {
1375
1376 pr_debug("Attempt to restore multicast list detected.\n");
1377
1378 mace_write(lp, ioaddr, MACE_IAC, MACE_IAC_ADDRCHG | MACE_IAC_LOGADDR);
1379 /* Poll ADDRCHG bit */
1380 while (mace_read(lp, ioaddr, MACE_IAC) & MACE_IAC_ADDRCHG)
1381 ;
1382 /* Set LADRF register */
1383 for (i = 0; i < MACE_LADRF_LEN; i++)
1384 mace_write(lp, ioaddr, MACE_LADRF, ladrf[i]);
1385
1386 mace_write(lp, ioaddr, MACE_UTR, MACE_UTR_RCVFCSE | MACE_UTR_LOOP_EXTERNAL);
1387 mace_write(lp, ioaddr, MACE_MACCC, MACE_MACCC_ENXMT | MACE_MACCC_ENRCV);
1388
1389 } else if (num_addrs < 0) {
1390
1391 /* Promiscuous mode: receive all packets */
1392 mace_write(lp, ioaddr, MACE_UTR, MACE_UTR_LOOP_EXTERNAL);
1393 mace_write(lp, ioaddr, MACE_MACCC,
1394 MACE_MACCC_PROM | MACE_MACCC_ENXMT | MACE_MACCC_ENRCV
1395 );
1396
1397 } else {
1398
1399 /* Normal mode */
1400 mace_write(lp, ioaddr, MACE_UTR, MACE_UTR_LOOP_EXTERNAL);
1401 mace_write(lp, ioaddr, MACE_MACCC, MACE_MACCC_ENXMT | MACE_MACCC_ENRCV);
1402
1403 }
1404} /* restore_multicast_list */
1405
1406/* ----------------------------------------------------------------------------
1407set_multicast_list
1408 Set or clear the multicast filter for this adaptor.
1409
1410Input
1411 num_addrs == -1 Promiscuous mode, receive all packets
1412 num_addrs == 0 Normal mode, clear multicast list
1413 num_addrs > 0 Multicast mode, receive normal and MC packets, and do
1414 best-effort filtering.
1415Output
1416 multicast_num_addrs
1417 multicast_ladrf[]
1418---------------------------------------------------------------------------- */
1419
1420static void set_multicast_list(struct net_device *dev)
1421{
1422 mace_private *lp = netdev_priv(dev);
1423 int adr[ETHER_ADDR_LEN] = {0}; /* Ethernet address */
1424 struct netdev_hw_addr *ha;
1425
1426#ifdef PCMCIA_DEBUG
1427 {
1428 static int old;
1429 if (netdev_mc_count(dev) != old) {
1430 old = netdev_mc_count(dev);
1431 pr_debug("%s: setting Rx mode to %d addresses.\n",
1432 dev->name, old);
1433 }
1434 }
1435#endif
1436
1437 /* Set multicast_num_addrs. */
1438 lp->multicast_num_addrs = netdev_mc_count(dev);
1439
1440 /* Set multicast_ladrf. */
1441 if (num_addrs > 0) {
1442 /* Calculate multicast logical address filter */
1443 memset(lp->multicast_ladrf, 0, MACE_LADRF_LEN);
1444 netdev_for_each_mc_addr(ha, dev) {
1445 memcpy(adr, ha->addr, ETHER_ADDR_LEN);
1446 BuildLAF(lp->multicast_ladrf, adr);
1447 }
1448 }
1449
1450 restore_multicast_list(dev);
1451
1452} /* set_multicast_list */
1453
1454#endif /* BROKEN_MULTICAST */
1455
1456static void restore_multicast_list(struct net_device *dev)
1457{
1458 unsigned int ioaddr = dev->base_addr;
1459 mace_private *lp = netdev_priv(dev);
1460
1461 pr_debug("%s: restoring Rx mode to %d addresses.\n", dev->name,
1462 lp->multicast_num_addrs);
1463
1464 if (dev->flags & IFF_PROMISC) {
1465 /* Promiscuous mode: receive all packets */
1466 mace_write(lp,ioaddr, MACE_UTR, MACE_UTR_LOOP_EXTERNAL);
1467 mace_write(lp, ioaddr, MACE_MACCC,
1468 MACE_MACCC_PROM | MACE_MACCC_ENXMT | MACE_MACCC_ENRCV
1469 );
1470 } else {
1471 /* Normal mode */
1472 mace_write(lp, ioaddr, MACE_UTR, MACE_UTR_LOOP_EXTERNAL);
1473 mace_write(lp, ioaddr, MACE_MACCC, MACE_MACCC_ENXMT | MACE_MACCC_ENRCV);
1474 }
1475} /* restore_multicast_list */
1476
1477static void set_multicast_list(struct net_device *dev)
1478{
1479 mace_private *lp = netdev_priv(dev);
1480
1481#ifdef PCMCIA_DEBUG
1482 {
1483 static int old;
1484 if (netdev_mc_count(dev) != old) {
1485 old = netdev_mc_count(dev);
1486 pr_debug("%s: setting Rx mode to %d addresses.\n",
1487 dev->name, old);
1488 }
1489 }
1490#endif
1491
1492 lp->multicast_num_addrs = netdev_mc_count(dev);
1493 restore_multicast_list(dev);
1494
1495} /* set_multicast_list */
1496
1497static const struct pcmcia_device_id nmclan_ids[] = {
1498 PCMCIA_DEVICE_PROD_ID12("New Media Corporation", "Ethernet", 0x085a850b, 0x00b2e941),
1499 PCMCIA_DEVICE_PROD_ID12("Portable Add-ons", "Ethernet+", 0xebf1d60, 0xad673aaf),
1500 PCMCIA_DEVICE_NULL,
1501};
1502MODULE_DEVICE_TABLE(pcmcia, nmclan_ids);
1503
1504static struct pcmcia_driver nmclan_cs_driver = {
1505 .owner = THIS_MODULE,
1506 .name = "nmclan_cs",
1507 .probe = nmclan_probe,
1508 .remove = nmclan_detach,
1509 .id_table = nmclan_ids,
1510 .suspend = nmclan_suspend,
1511 .resume = nmclan_resume,
1512};
1513
1514static int __init init_nmclan_cs(void)
1515{
1516 return pcmcia_register_driver(&nmclan_cs_driver);
1517}
1518
1519static void __exit exit_nmclan_cs(void)
1520{
1521 pcmcia_unregister_driver(&nmclan_cs_driver);
1522}
1523
1524module_init(init_nmclan_cs);
1525module_exit(exit_nmclan_cs);
diff --git a/drivers/net/pcmcia/pcnet_cs.c b/drivers/net/pcmcia/pcnet_cs.c
new file mode 100644
index 00000000000..b4fd7c3ed07
--- /dev/null
+++ b/drivers/net/pcmcia/pcnet_cs.c
@@ -0,0 +1,1710 @@
1/*======================================================================
2
3 A PCMCIA ethernet driver for NS8390-based cards
4
5 This driver supports the D-Link DE-650 and Linksys EthernetCard
6 cards, the newer D-Link and Linksys combo cards, Accton EN2212
7 cards, the RPTI EP400, and the PreMax PE-200 in non-shared-memory
8 mode, and the IBM Credit Card Adapter, the NE4100, the Thomas
9 Conrad ethernet card, and the Kingston KNE-PCM/x in shared-memory
10 mode. It will also handle the Socket EA card in either mode.
11
12 Copyright (C) 1999 David A. Hinds -- dahinds@users.sourceforge.net
13
14 pcnet_cs.c 1.153 2003/11/09 18:53:09
15
16 The network driver code is based on Donald Becker's NE2000 code:
17
18 Written 1992,1993 by Donald Becker.
19 Copyright 1993 United States Government as represented by the
20 Director, National Security Agency. This software may be used and
21 distributed according to the terms of the GNU General Public License,
22 incorporated herein by reference.
23 Donald Becker may be reached at becker@scyld.com
24
25 Based also on Keith Moore's changes to Don Becker's code, for IBM
26 CCAE support. Drivers merged back together, and shared-memory
27 Socket EA support added, by Ken Raeburn, September 1995.
28
29======================================================================*/
30
31#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
32
33#include <linux/kernel.h>
34#include <linux/module.h>
35#include <linux/init.h>
36#include <linux/ptrace.h>
37#include <linux/string.h>
38#include <linux/timer.h>
39#include <linux/delay.h>
40#include <linux/netdevice.h>
41#include <linux/log2.h>
42#include <linux/etherdevice.h>
43#include <linux/mii.h>
44#include "../8390.h"
45
46#include <pcmcia/cistpl.h>
47#include <pcmcia/ciscode.h>
48#include <pcmcia/ds.h>
49#include <pcmcia/cisreg.h>
50
51#include <asm/io.h>
52#include <asm/system.h>
53#include <asm/byteorder.h>
54#include <asm/uaccess.h>
55
56#define PCNET_CMD 0x00
57#define PCNET_DATAPORT 0x10 /* NatSemi-defined port window offset. */
58#define PCNET_RESET 0x1f /* Issue a read to reset, a write to clear. */
59#define PCNET_MISC 0x18 /* For IBM CCAE and Socket EA cards */
60
61#define PCNET_START_PG 0x40 /* First page of TX buffer */
62#define PCNET_STOP_PG 0x80 /* Last page +1 of RX ring */
63
64/* Socket EA cards have a larger packet buffer */
65#define SOCKET_START_PG 0x01
66#define SOCKET_STOP_PG 0xff
67
68#define PCNET_RDC_TIMEOUT (2*HZ/100) /* Max wait in jiffies for Tx RDC */
69
70static const char *if_names[] = { "auto", "10baseT", "10base2"};
71
72
73/*====================================================================*/
74
75/* Module parameters */
76
77MODULE_AUTHOR("David Hinds <dahinds@users.sourceforge.net>");
78MODULE_DESCRIPTION("NE2000 compatible PCMCIA ethernet driver");
79MODULE_LICENSE("GPL");
80
81#define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0)
82
83INT_MODULE_PARM(if_port, 1); /* Transceiver type */
84INT_MODULE_PARM(use_big_buf, 1); /* use 64K packet buffer? */
85INT_MODULE_PARM(mem_speed, 0); /* shared mem speed, in ns */
86INT_MODULE_PARM(delay_output, 0); /* pause after xmit? */
87INT_MODULE_PARM(delay_time, 4); /* in usec */
88INT_MODULE_PARM(use_shmem, -1); /* use shared memory? */
89INT_MODULE_PARM(full_duplex, 0); /* full duplex? */
90
91/* Ugh! Let the user hardwire the hardware address for queer cards */
92static int hw_addr[6] = { 0, /* ... */ };
93module_param_array(hw_addr, int, NULL, 0);
94
95/*====================================================================*/
96
97static void mii_phy_probe(struct net_device *dev);
98static int pcnet_config(struct pcmcia_device *link);
99static void pcnet_release(struct pcmcia_device *link);
100static int pcnet_open(struct net_device *dev);
101static int pcnet_close(struct net_device *dev);
102static int ei_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
103static irqreturn_t ei_irq_wrapper(int irq, void *dev_id);
104static void ei_watchdog(u_long arg);
105static void pcnet_reset_8390(struct net_device *dev);
106static int set_config(struct net_device *dev, struct ifmap *map);
107static int setup_shmem_window(struct pcmcia_device *link, int start_pg,
108 int stop_pg, int cm_offset);
109static int setup_dma_config(struct pcmcia_device *link, int start_pg,
110 int stop_pg);
111
112static void pcnet_detach(struct pcmcia_device *p_dev);
113
114/*====================================================================*/
115
116typedef struct hw_info_t {
117 u_int offset;
118 u_char a0, a1, a2;
119 u_int flags;
120} hw_info_t;
121
122#define DELAY_OUTPUT 0x01
123#define HAS_MISC_REG 0x02
124#define USE_BIG_BUF 0x04
125#define HAS_IBM_MISC 0x08
126#define IS_DL10019 0x10
127#define IS_DL10022 0x20
128#define HAS_MII 0x40
129#define USE_SHMEM 0x80 /* autodetected */
130
131#define AM79C9XX_HOME_PHY 0x00006B90 /* HomePNA PHY */
132#define AM79C9XX_ETH_PHY 0x00006B70 /* 10baseT PHY */
133#define MII_PHYID_REV_MASK 0xfffffff0
134#define MII_PHYID_REG1 0x02
135#define MII_PHYID_REG2 0x03
136
137static hw_info_t hw_info[] = {
138 { /* Accton EN2212 */ 0x0ff0, 0x00, 0x00, 0xe8, DELAY_OUTPUT },
139 { /* Allied Telesis LA-PCM */ 0x0ff0, 0x00, 0x00, 0xf4, 0 },
140 { /* APEX MultiCard */ 0x03f4, 0x00, 0x20, 0xe5, 0 },
141 { /* ASANTE FriendlyNet */ 0x4910, 0x00, 0x00, 0x94,
142 DELAY_OUTPUT | HAS_IBM_MISC },
143 { /* Danpex EN-6200P2 */ 0x0110, 0x00, 0x40, 0xc7, 0 },
144 { /* DataTrek NetCard */ 0x0ff0, 0x00, 0x20, 0xe8, 0 },
145 { /* Dayna CommuniCard E */ 0x0110, 0x00, 0x80, 0x19, 0 },
146 { /* D-Link DE-650 */ 0x0040, 0x00, 0x80, 0xc8, 0 },
147 { /* EP-210 Ethernet */ 0x0110, 0x00, 0x40, 0x33, 0 },
148 { /* EP4000 Ethernet */ 0x01c0, 0x00, 0x00, 0xb4, 0 },
149 { /* Epson EEN10B */ 0x0ff0, 0x00, 0x00, 0x48,
150 HAS_MISC_REG | HAS_IBM_MISC },
151 { /* ELECOM Laneed LD-CDWA */ 0xb8, 0x08, 0x00, 0x42, 0 },
152 { /* Hypertec Ethernet */ 0x01c0, 0x00, 0x40, 0x4c, 0 },
153 { /* IBM CCAE */ 0x0ff0, 0x08, 0x00, 0x5a,
154 HAS_MISC_REG | HAS_IBM_MISC },
155 { /* IBM CCAE */ 0x0ff0, 0x00, 0x04, 0xac,
156 HAS_MISC_REG | HAS_IBM_MISC },
157 { /* IBM CCAE */ 0x0ff0, 0x00, 0x06, 0x29,
158 HAS_MISC_REG | HAS_IBM_MISC },
159 { /* IBM FME */ 0x0374, 0x08, 0x00, 0x5a,
160 HAS_MISC_REG | HAS_IBM_MISC },
161 { /* IBM FME */ 0x0374, 0x00, 0x04, 0xac,
162 HAS_MISC_REG | HAS_IBM_MISC },
163 { /* Kansai KLA-PCM/T */ 0x0ff0, 0x00, 0x60, 0x87,
164 HAS_MISC_REG | HAS_IBM_MISC },
165 { /* NSC DP83903 */ 0x0374, 0x08, 0x00, 0x17,
166 HAS_MISC_REG | HAS_IBM_MISC },
167 { /* NSC DP83903 */ 0x0374, 0x00, 0xc0, 0xa8,
168 HAS_MISC_REG | HAS_IBM_MISC },
169 { /* NSC DP83903 */ 0x0374, 0x00, 0xa0, 0xb0,
170 HAS_MISC_REG | HAS_IBM_MISC },
171 { /* NSC DP83903 */ 0x0198, 0x00, 0x20, 0xe0,
172 HAS_MISC_REG | HAS_IBM_MISC },
173 { /* I-O DATA PCLA/T */ 0x0ff0, 0x00, 0xa0, 0xb0, 0 },
174 { /* Katron PE-520 */ 0x0110, 0x00, 0x40, 0xf6, 0 },
175 { /* Kingston KNE-PCM/x */ 0x0ff0, 0x00, 0xc0, 0xf0,
176 HAS_MISC_REG | HAS_IBM_MISC },
177 { /* Kingston KNE-PCM/x */ 0x0ff0, 0xe2, 0x0c, 0x0f,
178 HAS_MISC_REG | HAS_IBM_MISC },
179 { /* Kingston KNE-PC2 */ 0x0180, 0x00, 0xc0, 0xf0, 0 },
180 { /* Maxtech PCN2000 */ 0x5000, 0x00, 0x00, 0xe8, 0 },
181 { /* NDC Instant-Link */ 0x003a, 0x00, 0x80, 0xc6, 0 },
182 { /* NE2000 Compatible */ 0x0ff0, 0x00, 0xa0, 0x0c, 0 },
183 { /* Network General Sniffer */ 0x0ff0, 0x00, 0x00, 0x65,
184 HAS_MISC_REG | HAS_IBM_MISC },
185 { /* Panasonic VEL211 */ 0x0ff0, 0x00, 0x80, 0x45,
186 HAS_MISC_REG | HAS_IBM_MISC },
187 { /* PreMax PE-200 */ 0x07f0, 0x00, 0x20, 0xe0, 0 },
188 { /* RPTI EP400 */ 0x0110, 0x00, 0x40, 0x95, 0 },
189 { /* SCM Ethernet */ 0x0ff0, 0x00, 0x20, 0xcb, 0 },
190 { /* Socket EA */ 0x4000, 0x00, 0xc0, 0x1b,
191 DELAY_OUTPUT | HAS_MISC_REG | USE_BIG_BUF },
192 { /* Socket LP-E CF+ */ 0x01c0, 0x00, 0xc0, 0x1b, 0 },
193 { /* SuperSocket RE450T */ 0x0110, 0x00, 0xe0, 0x98, 0 },
194 { /* Volktek NPL-402CT */ 0x0060, 0x00, 0x40, 0x05, 0 },
195 { /* NEC PC-9801N-J12 */ 0x0ff0, 0x00, 0x00, 0x4c, 0 },
196 { /* PCMCIA Technology OEM */ 0x01c8, 0x00, 0xa0, 0x0c, 0 }
197};
198
199#define NR_INFO ARRAY_SIZE(hw_info)
200
201static hw_info_t default_info = { 0, 0, 0, 0, 0 };
202static hw_info_t dl10019_info = { 0, 0, 0, 0, IS_DL10019|HAS_MII };
203static hw_info_t dl10022_info = { 0, 0, 0, 0, IS_DL10022|HAS_MII };
204
205typedef struct pcnet_dev_t {
206 struct pcmcia_device *p_dev;
207 u_int flags;
208 void __iomem *base;
209 struct timer_list watchdog;
210 int stale, fast_poll;
211 u_char phy_id;
212 u_char eth_phy, pna_phy;
213 u_short link_status;
214 u_long mii_reset;
215} pcnet_dev_t;
216
217static inline pcnet_dev_t *PRIV(struct net_device *dev)
218{
219 char *p = netdev_priv(dev);
220 return (pcnet_dev_t *)(p + sizeof(struct ei_device));
221}
222
223static const struct net_device_ops pcnet_netdev_ops = {
224 .ndo_open = pcnet_open,
225 .ndo_stop = pcnet_close,
226 .ndo_set_config = set_config,
227 .ndo_start_xmit = ei_start_xmit,
228 .ndo_get_stats = ei_get_stats,
229 .ndo_do_ioctl = ei_ioctl,
230 .ndo_set_multicast_list = ei_set_multicast_list,
231 .ndo_tx_timeout = ei_tx_timeout,
232 .ndo_change_mtu = eth_change_mtu,
233 .ndo_set_mac_address = eth_mac_addr,
234 .ndo_validate_addr = eth_validate_addr,
235#ifdef CONFIG_NET_POLL_CONTROLLER
236 .ndo_poll_controller = ei_poll,
237#endif
238};
239
240static int pcnet_probe(struct pcmcia_device *link)
241{
242 pcnet_dev_t *info;
243 struct net_device *dev;
244
245 dev_dbg(&link->dev, "pcnet_attach()\n");
246
247 /* Create new ethernet device */
248 dev = __alloc_ei_netdev(sizeof(pcnet_dev_t));
249 if (!dev) return -ENOMEM;
250 info = PRIV(dev);
251 info->p_dev = link;
252 link->priv = dev;
253
254 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
255
256 dev->netdev_ops = &pcnet_netdev_ops;
257
258 return pcnet_config(link);
259} /* pcnet_attach */
260
261static void pcnet_detach(struct pcmcia_device *link)
262{
263 struct net_device *dev = link->priv;
264
265 dev_dbg(&link->dev, "pcnet_detach\n");
266
267 unregister_netdev(dev);
268
269 pcnet_release(link);
270
271 free_netdev(dev);
272} /* pcnet_detach */
273
274/*======================================================================
275
276 This probes for a card's hardware address, for card types that
277 encode this information in their CIS.
278
279======================================================================*/
280
281static hw_info_t *get_hwinfo(struct pcmcia_device *link)
282{
283 struct net_device *dev = link->priv;
284 u_char __iomem *base, *virt;
285 int i, j;
286
287 /* Allocate a small memory window */
288 link->resource[2]->flags |= WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
289 link->resource[2]->start = 0; link->resource[2]->end = 0;
290 i = pcmcia_request_window(link, link->resource[2], 0);
291 if (i != 0)
292 return NULL;
293
294 virt = ioremap(link->resource[2]->start,
295 resource_size(link->resource[2]));
296 for (i = 0; i < NR_INFO; i++) {
297 pcmcia_map_mem_page(link, link->resource[2],
298 hw_info[i].offset & ~(resource_size(link->resource[2])-1));
299 base = &virt[hw_info[i].offset & (resource_size(link->resource[2])-1)];
300 if ((readb(base+0) == hw_info[i].a0) &&
301 (readb(base+2) == hw_info[i].a1) &&
302 (readb(base+4) == hw_info[i].a2)) {
303 for (j = 0; j < 6; j++)
304 dev->dev_addr[j] = readb(base + (j<<1));
305 break;
306 }
307 }
308
309 iounmap(virt);
310 j = pcmcia_release_window(link, link->resource[2]);
311 return (i < NR_INFO) ? hw_info+i : NULL;
312} /* get_hwinfo */
313
314/*======================================================================
315
316 This probes for a card's hardware address by reading the PROM.
317 It checks the address against a list of known types, then falls
318 back to a simple NE2000 clone signature check.
319
320======================================================================*/
321
322static hw_info_t *get_prom(struct pcmcia_device *link)
323{
324 struct net_device *dev = link->priv;
325 unsigned int ioaddr = dev->base_addr;
326 u_char prom[32];
327 int i, j;
328
329 /* This is lifted straight from drivers/net/ne.c */
330 struct {
331 u_char value, offset;
332 } program_seq[] = {
333 {E8390_NODMA+E8390_PAGE0+E8390_STOP, E8390_CMD}, /* Select page 0*/
334 {0x48, EN0_DCFG}, /* Set byte-wide (0x48) access. */
335 {0x00, EN0_RCNTLO}, /* Clear the count regs. */
336 {0x00, EN0_RCNTHI},
337 {0x00, EN0_IMR}, /* Mask completion irq. */
338 {0xFF, EN0_ISR},
339 {E8390_RXOFF, EN0_RXCR}, /* 0x20 Set to monitor */
340 {E8390_TXOFF, EN0_TXCR}, /* 0x02 and loopback mode. */
341 {32, EN0_RCNTLO},
342 {0x00, EN0_RCNTHI},
343 {0x00, EN0_RSARLO}, /* DMA starting at 0x0000. */
344 {0x00, EN0_RSARHI},
345 {E8390_RREAD+E8390_START, E8390_CMD},
346 };
347
348 pcnet_reset_8390(dev);
349 mdelay(10);
350
351 for (i = 0; i < ARRAY_SIZE(program_seq); i++)
352 outb_p(program_seq[i].value, ioaddr + program_seq[i].offset);
353
354 for (i = 0; i < 32; i++)
355 prom[i] = inb(ioaddr + PCNET_DATAPORT);
356 for (i = 0; i < NR_INFO; i++) {
357 if ((prom[0] == hw_info[i].a0) &&
358 (prom[2] == hw_info[i].a1) &&
359 (prom[4] == hw_info[i].a2))
360 break;
361 }
362 if ((i < NR_INFO) || ((prom[28] == 0x57) && (prom[30] == 0x57))) {
363 for (j = 0; j < 6; j++)
364 dev->dev_addr[j] = prom[j<<1];
365 return (i < NR_INFO) ? hw_info+i : &default_info;
366 }
367 return NULL;
368} /* get_prom */
369
370/*======================================================================
371
372 For DL10019 based cards, like the Linksys EtherFast
373
374======================================================================*/
375
376static hw_info_t *get_dl10019(struct pcmcia_device *link)
377{
378 struct net_device *dev = link->priv;
379 int i;
380 u_char sum;
381
382 for (sum = 0, i = 0x14; i < 0x1c; i++)
383 sum += inb_p(dev->base_addr + i);
384 if (sum != 0xff)
385 return NULL;
386 for (i = 0; i < 6; i++)
387 dev->dev_addr[i] = inb_p(dev->base_addr + 0x14 + i);
388 i = inb(dev->base_addr + 0x1f);
389 return ((i == 0x91)||(i == 0x99)) ? &dl10022_info : &dl10019_info;
390}
391
392/*======================================================================
393
394 For Asix AX88190 based cards
395
396======================================================================*/
397
398static hw_info_t *get_ax88190(struct pcmcia_device *link)
399{
400 struct net_device *dev = link->priv;
401 unsigned int ioaddr = dev->base_addr;
402 int i, j;
403
404 /* Not much of a test, but the alternatives are messy */
405 if (link->config_base != 0x03c0)
406 return NULL;
407
408 outb_p(0x01, ioaddr + EN0_DCFG); /* Set word-wide access. */
409 outb_p(0x00, ioaddr + EN0_RSARLO); /* DMA starting at 0x0400. */
410 outb_p(0x04, ioaddr + EN0_RSARHI);
411 outb_p(E8390_RREAD+E8390_START, ioaddr + E8390_CMD);
412
413 for (i = 0; i < 6; i += 2) {
414 j = inw(ioaddr + PCNET_DATAPORT);
415 dev->dev_addr[i] = j & 0xff;
416 dev->dev_addr[i+1] = j >> 8;
417 }
418 return NULL;
419}
420
421/*======================================================================
422
423 This should be totally unnecessary... but when we can't figure
424 out the hardware address any other way, we'll let the user hard
425 wire it when the module is initialized.
426
427======================================================================*/
428
429static hw_info_t *get_hwired(struct pcmcia_device *link)
430{
431 struct net_device *dev = link->priv;
432 int i;
433
434 for (i = 0; i < 6; i++)
435 if (hw_addr[i] != 0) break;
436 if (i == 6)
437 return NULL;
438
439 for (i = 0; i < 6; i++)
440 dev->dev_addr[i] = hw_addr[i];
441
442 return &default_info;
443} /* get_hwired */
444
445static int try_io_port(struct pcmcia_device *link)
446{
447 int j, ret;
448 link->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
449 link->resource[1]->flags &= ~IO_DATA_PATH_WIDTH;
450 if (link->resource[0]->end == 32) {
451 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
452 if (link->resource[1]->end > 0) {
453 /* for master/slave multifunction cards */
454 link->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
455 }
456 } else {
457 /* This should be two 16-port windows */
458 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
459 link->resource[1]->flags |= IO_DATA_PATH_WIDTH_16;
460 }
461 if (link->resource[0]->start == 0) {
462 for (j = 0; j < 0x400; j += 0x20) {
463 link->resource[0]->start = j ^ 0x300;
464 link->resource[1]->start = (j ^ 0x300) + 0x10;
465 link->io_lines = 16;
466 ret = pcmcia_request_io(link);
467 if (ret == 0)
468 return ret;
469 }
470 return ret;
471 } else {
472 return pcmcia_request_io(link);
473 }
474}
475
476static int pcnet_confcheck(struct pcmcia_device *p_dev, void *priv_data)
477{
478 int *priv = priv_data;
479 int try = (*priv & 0x1);
480
481 *priv &= (p_dev->resource[2]->end >= 0x4000) ? 0x10 : ~0x10;
482
483 if (p_dev->config_index == 0)
484 return -EINVAL;
485
486 if (p_dev->resource[0]->end + p_dev->resource[1]->end < 32)
487 return -EINVAL;
488
489 if (try)
490 p_dev->io_lines = 16;
491 return try_io_port(p_dev);
492}
493
494static hw_info_t *pcnet_try_config(struct pcmcia_device *link,
495 int *has_shmem, int try)
496{
497 struct net_device *dev = link->priv;
498 hw_info_t *local_hw_info;
499 pcnet_dev_t *info = PRIV(dev);
500 int priv = try;
501 int ret;
502
503 ret = pcmcia_loop_config(link, pcnet_confcheck, &priv);
504 if (ret) {
505 dev_warn(&link->dev, "no useable port range found\n");
506 return NULL;
507 }
508 *has_shmem = (priv & 0x10);
509
510 if (!link->irq)
511 return NULL;
512
513 if (resource_size(link->resource[1]) == 8)
514 link->config_flags |= CONF_ENABLE_SPKR;
515
516 if ((link->manf_id == MANFID_IBM) &&
517 (link->card_id == PRODID_IBM_HOME_AND_AWAY))
518 link->config_index |= 0x10;
519
520 ret = pcmcia_enable_device(link);
521 if (ret)
522 return NULL;
523
524 dev->irq = link->irq;
525 dev->base_addr = link->resource[0]->start;
526
527 if (info->flags & HAS_MISC_REG) {
528 if ((if_port == 1) || (if_port == 2))
529 dev->if_port = if_port;
530 else
531 dev_notice(&link->dev, "invalid if_port requested\n");
532 } else
533 dev->if_port = 0;
534
535 if ((link->config_base == 0x03c0) &&
536 (link->manf_id == 0x149) && (link->card_id == 0xc1ab)) {
537 dev_info(&link->dev,
538 "this is an AX88190 card - use axnet_cs instead.\n");
539 return NULL;
540 }
541
542 local_hw_info = get_hwinfo(link);
543 if (!local_hw_info)
544 local_hw_info = get_prom(link);
545 if (!local_hw_info)
546 local_hw_info = get_dl10019(link);
547 if (!local_hw_info)
548 local_hw_info = get_ax88190(link);
549 if (!local_hw_info)
550 local_hw_info = get_hwired(link);
551
552 return local_hw_info;
553}
554
555static int pcnet_config(struct pcmcia_device *link)
556{
557 struct net_device *dev = link->priv;
558 pcnet_dev_t *info = PRIV(dev);
559 int start_pg, stop_pg, cm_offset;
560 int has_shmem = 0;
561 hw_info_t *local_hw_info;
562
563 dev_dbg(&link->dev, "pcnet_config\n");
564
565 local_hw_info = pcnet_try_config(link, &has_shmem, 0);
566 if (!local_hw_info) {
567 /* check whether forcing io_lines to 16 helps... */
568 pcmcia_disable_device(link);
569 local_hw_info = pcnet_try_config(link, &has_shmem, 1);
570 if (local_hw_info == NULL) {
571 dev_notice(&link->dev, "unable to read hardware net"
572 " address for io base %#3lx\n", dev->base_addr);
573 goto failed;
574 }
575 }
576
577 info->flags = local_hw_info->flags;
578 /* Check for user overrides */
579 info->flags |= (delay_output) ? DELAY_OUTPUT : 0;
580 if ((link->manf_id == MANFID_SOCKET) &&
581 ((link->card_id == PRODID_SOCKET_LPE) ||
582 (link->card_id == PRODID_SOCKET_LPE_CF) ||
583 (link->card_id == PRODID_SOCKET_EIO)))
584 info->flags &= ~USE_BIG_BUF;
585 if (!use_big_buf)
586 info->flags &= ~USE_BIG_BUF;
587
588 if (info->flags & USE_BIG_BUF) {
589 start_pg = SOCKET_START_PG;
590 stop_pg = SOCKET_STOP_PG;
591 cm_offset = 0x10000;
592 } else {
593 start_pg = PCNET_START_PG;
594 stop_pg = PCNET_STOP_PG;
595 cm_offset = 0;
596 }
597
598 /* has_shmem is ignored if use_shmem != -1 */
599 if ((use_shmem == 0) || (!has_shmem && (use_shmem == -1)) ||
600 (setup_shmem_window(link, start_pg, stop_pg, cm_offset) != 0))
601 setup_dma_config(link, start_pg, stop_pg);
602
603 ei_status.name = "NE2000";
604 ei_status.word16 = 1;
605 ei_status.reset_8390 = pcnet_reset_8390;
606
607 if (info->flags & (IS_DL10019|IS_DL10022))
608 mii_phy_probe(dev);
609
610 SET_NETDEV_DEV(dev, &link->dev);
611
612 if (register_netdev(dev) != 0) {
613 pr_notice("register_netdev() failed\n");
614 goto failed;
615 }
616
617 if (info->flags & (IS_DL10019|IS_DL10022)) {
618 u_char id = inb(dev->base_addr + 0x1a);
619 netdev_info(dev, "NE2000 (DL100%d rev %02x): ",
620 (info->flags & IS_DL10022) ? 22 : 19, id);
621 if (info->pna_phy)
622 pr_cont("PNA, ");
623 } else {
624 netdev_info(dev, "NE2000 Compatible: ");
625 }
626 pr_cont("io %#3lx, irq %d,", dev->base_addr, dev->irq);
627 if (info->flags & USE_SHMEM)
628 pr_cont(" mem %#5lx,", dev->mem_start);
629 if (info->flags & HAS_MISC_REG)
630 pr_cont(" %s xcvr,", if_names[dev->if_port]);
631 pr_cont(" hw_addr %pM\n", dev->dev_addr);
632 return 0;
633
634failed:
635 pcnet_release(link);
636 return -ENODEV;
637} /* pcnet_config */
638
639static void pcnet_release(struct pcmcia_device *link)
640{
641 pcnet_dev_t *info = PRIV(link->priv);
642
643 dev_dbg(&link->dev, "pcnet_release\n");
644
645 if (info->flags & USE_SHMEM)
646 iounmap(info->base);
647
648 pcmcia_disable_device(link);
649}
650
651static int pcnet_suspend(struct pcmcia_device *link)
652{
653 struct net_device *dev = link->priv;
654
655 if (link->open)
656 netif_device_detach(dev);
657
658 return 0;
659}
660
661static int pcnet_resume(struct pcmcia_device *link)
662{
663 struct net_device *dev = link->priv;
664
665 if (link->open) {
666 pcnet_reset_8390(dev);
667 NS8390_init(dev, 1);
668 netif_device_attach(dev);
669 }
670
671 return 0;
672}
673
674
675/*======================================================================
676
677 MII interface support for DL10019 and DL10022 based cards
678
679 On the DL10019, the MII IO direction bit is 0x10; on the DL10022
680 it is 0x20. Setting both bits seems to work on both card types.
681
682======================================================================*/
683
684#define DLINK_GPIO 0x1c
685#define DLINK_DIAG 0x1d
686#define DLINK_EEPROM 0x1e
687
688#define MDIO_SHIFT_CLK 0x80
689#define MDIO_DATA_OUT 0x40
690#define MDIO_DIR_WRITE 0x30
691#define MDIO_DATA_WRITE0 (MDIO_DIR_WRITE)
692#define MDIO_DATA_WRITE1 (MDIO_DIR_WRITE | MDIO_DATA_OUT)
693#define MDIO_DATA_READ 0x10
694#define MDIO_MASK 0x0f
695
696static void mdio_sync(unsigned int addr)
697{
698 int bits, mask = inb(addr) & MDIO_MASK;
699 for (bits = 0; bits < 32; bits++) {
700 outb(mask | MDIO_DATA_WRITE1, addr);
701 outb(mask | MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, addr);
702 }
703}
704
705static int mdio_read(unsigned int addr, int phy_id, int loc)
706{
707 u_int cmd = (0x06<<10)|(phy_id<<5)|loc;
708 int i, retval = 0, mask = inb(addr) & MDIO_MASK;
709
710 mdio_sync(addr);
711 for (i = 13; i >= 0; i--) {
712 int dat = (cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
713 outb(mask | dat, addr);
714 outb(mask | dat | MDIO_SHIFT_CLK, addr);
715 }
716 for (i = 19; i > 0; i--) {
717 outb(mask, addr);
718 retval = (retval << 1) | ((inb(addr) & MDIO_DATA_READ) != 0);
719 outb(mask | MDIO_SHIFT_CLK, addr);
720 }
721 return (retval>>1) & 0xffff;
722}
723
724static void mdio_write(unsigned int addr, int phy_id, int loc, int value)
725{
726 u_int cmd = (0x05<<28)|(phy_id<<23)|(loc<<18)|(1<<17)|value;
727 int i, mask = inb(addr) & MDIO_MASK;
728
729 mdio_sync(addr);
730 for (i = 31; i >= 0; i--) {
731 int dat = (cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
732 outb(mask | dat, addr);
733 outb(mask | dat | MDIO_SHIFT_CLK, addr);
734 }
735 for (i = 1; i >= 0; i--) {
736 outb(mask, addr);
737 outb(mask | MDIO_SHIFT_CLK, addr);
738 }
739}
740
741/*======================================================================
742
743 EEPROM access routines for DL10019 and DL10022 based cards
744
745======================================================================*/
746
747#define EE_EEP 0x40
748#define EE_ASIC 0x10
749#define EE_CS 0x08
750#define EE_CK 0x04
751#define EE_DO 0x02
752#define EE_DI 0x01
753#define EE_ADOT 0x01 /* DataOut for ASIC */
754#define EE_READ_CMD 0x06
755
756#define DL19FDUPLX 0x0400 /* DL10019 Full duplex mode */
757
758static int read_eeprom(unsigned int ioaddr, int location)
759{
760 int i, retval = 0;
761 unsigned int ee_addr = ioaddr + DLINK_EEPROM;
762 int read_cmd = location | (EE_READ_CMD << 8);
763
764 outb(0, ee_addr);
765 outb(EE_EEP|EE_CS, ee_addr);
766
767 /* Shift the read command bits out. */
768 for (i = 10; i >= 0; i--) {
769 short dataval = (read_cmd & (1 << i)) ? EE_DO : 0;
770 outb_p(EE_EEP|EE_CS|dataval, ee_addr);
771 outb_p(EE_EEP|EE_CS|dataval|EE_CK, ee_addr);
772 }
773 outb(EE_EEP|EE_CS, ee_addr);
774
775 for (i = 16; i > 0; i--) {
776 outb_p(EE_EEP|EE_CS | EE_CK, ee_addr);
777 retval = (retval << 1) | ((inb(ee_addr) & EE_DI) ? 1 : 0);
778 outb_p(EE_EEP|EE_CS, ee_addr);
779 }
780
781 /* Terminate the EEPROM access. */
782 outb(0, ee_addr);
783 return retval;
784}
785
786/*
787 The internal ASIC registers can be changed by EEPROM READ access
788 with EE_ASIC bit set.
789 In ASIC mode, EE_ADOT is used to output the data to the ASIC.
790*/
791
792static void write_asic(unsigned int ioaddr, int location, short asic_data)
793{
794 int i;
795 unsigned int ee_addr = ioaddr + DLINK_EEPROM;
796 short dataval;
797 int read_cmd = location | (EE_READ_CMD << 8);
798
799 asic_data |= read_eeprom(ioaddr, location);
800
801 outb(0, ee_addr);
802 outb(EE_ASIC|EE_CS|EE_DI, ee_addr);
803
804 read_cmd = read_cmd >> 1;
805
806 /* Shift the read command bits out. */
807 for (i = 9; i >= 0; i--) {
808 dataval = (read_cmd & (1 << i)) ? EE_DO : 0;
809 outb_p(EE_ASIC|EE_CS|EE_DI|dataval, ee_addr);
810 outb_p(EE_ASIC|EE_CS|EE_DI|dataval|EE_CK, ee_addr);
811 outb_p(EE_ASIC|EE_CS|EE_DI|dataval, ee_addr);
812 }
813 // sync
814 outb(EE_ASIC|EE_CS, ee_addr);
815 outb(EE_ASIC|EE_CS|EE_CK, ee_addr);
816 outb(EE_ASIC|EE_CS, ee_addr);
817
818 for (i = 15; i >= 0; i--) {
819 dataval = (asic_data & (1 << i)) ? EE_ADOT : 0;
820 outb_p(EE_ASIC|EE_CS|dataval, ee_addr);
821 outb_p(EE_ASIC|EE_CS|dataval|EE_CK, ee_addr);
822 outb_p(EE_ASIC|EE_CS|dataval, ee_addr);
823 }
824
825 /* Terminate the ASIC access. */
826 outb(EE_ASIC|EE_DI, ee_addr);
827 outb(EE_ASIC|EE_DI| EE_CK, ee_addr);
828 outb(EE_ASIC|EE_DI, ee_addr);
829
830 outb(0, ee_addr);
831}
832
833/*====================================================================*/
834
835static void set_misc_reg(struct net_device *dev)
836{
837 unsigned int nic_base = dev->base_addr;
838 pcnet_dev_t *info = PRIV(dev);
839 u_char tmp;
840
841 if (info->flags & HAS_MISC_REG) {
842 tmp = inb_p(nic_base + PCNET_MISC) & ~3;
843 if (dev->if_port == 2)
844 tmp |= 1;
845 if (info->flags & USE_BIG_BUF)
846 tmp |= 2;
847 if (info->flags & HAS_IBM_MISC)
848 tmp |= 8;
849 outb_p(tmp, nic_base + PCNET_MISC);
850 }
851 if (info->flags & IS_DL10022) {
852 if (info->flags & HAS_MII) {
853 /* Advertise 100F, 100H, 10F, 10H */
854 mdio_write(nic_base + DLINK_GPIO, info->eth_phy, 4, 0x01e1);
855 /* Restart MII autonegotiation */
856 mdio_write(nic_base + DLINK_GPIO, info->eth_phy, 0, 0x0000);
857 mdio_write(nic_base + DLINK_GPIO, info->eth_phy, 0, 0x1200);
858 info->mii_reset = jiffies;
859 } else {
860 outb(full_duplex ? 4 : 0, nic_base + DLINK_DIAG);
861 }
862 } else if (info->flags & IS_DL10019) {
863 /* Advertise 100F, 100H, 10F, 10H */
864 mdio_write(nic_base + DLINK_GPIO, info->eth_phy, 4, 0x01e1);
865 /* Restart MII autonegotiation */
866 mdio_write(nic_base + DLINK_GPIO, info->eth_phy, 0, 0x0000);
867 mdio_write(nic_base + DLINK_GPIO, info->eth_phy, 0, 0x1200);
868 }
869}
870
871/*====================================================================*/
872
873static void mii_phy_probe(struct net_device *dev)
874{
875 pcnet_dev_t *info = PRIV(dev);
876 unsigned int mii_addr = dev->base_addr + DLINK_GPIO;
877 int i;
878 u_int tmp, phyid;
879
880 for (i = 31; i >= 0; i--) {
881 tmp = mdio_read(mii_addr, i, 1);
882 if ((tmp == 0) || (tmp == 0xffff))
883 continue;
884 tmp = mdio_read(mii_addr, i, MII_PHYID_REG1);
885 phyid = tmp << 16;
886 phyid |= mdio_read(mii_addr, i, MII_PHYID_REG2);
887 phyid &= MII_PHYID_REV_MASK;
888 netdev_dbg(dev, "MII at %d is 0x%08x\n", i, phyid);
889 if (phyid == AM79C9XX_HOME_PHY) {
890 info->pna_phy = i;
891 } else if (phyid != AM79C9XX_ETH_PHY) {
892 info->eth_phy = i;
893 }
894 }
895}
896
897static int pcnet_open(struct net_device *dev)
898{
899 int ret;
900 pcnet_dev_t *info = PRIV(dev);
901 struct pcmcia_device *link = info->p_dev;
902 unsigned int nic_base = dev->base_addr;
903
904 dev_dbg(&link->dev, "pcnet_open('%s')\n", dev->name);
905
906 if (!pcmcia_dev_present(link))
907 return -ENODEV;
908
909 set_misc_reg(dev);
910
911 outb_p(0xFF, nic_base + EN0_ISR); /* Clear bogus intr. */
912 ret = request_irq(dev->irq, ei_irq_wrapper, IRQF_SHARED, dev->name, dev);
913 if (ret)
914 return ret;
915
916 link->open++;
917
918 info->phy_id = info->eth_phy;
919 info->link_status = 0x00;
920 init_timer(&info->watchdog);
921 info->watchdog.function = ei_watchdog;
922 info->watchdog.data = (u_long)dev;
923 info->watchdog.expires = jiffies + HZ;
924 add_timer(&info->watchdog);
925
926 return ei_open(dev);
927} /* pcnet_open */
928
929/*====================================================================*/
930
931static int pcnet_close(struct net_device *dev)
932{
933 pcnet_dev_t *info = PRIV(dev);
934 struct pcmcia_device *link = info->p_dev;
935
936 dev_dbg(&link->dev, "pcnet_close('%s')\n", dev->name);
937
938 ei_close(dev);
939 free_irq(dev->irq, dev);
940
941 link->open--;
942 netif_stop_queue(dev);
943 del_timer_sync(&info->watchdog);
944
945 return 0;
946} /* pcnet_close */
947
948/*======================================================================
949
950 Hard reset the card. This used to pause for the same period that
951 a 8390 reset command required, but that shouldn't be necessary.
952
953======================================================================*/
954
955static void pcnet_reset_8390(struct net_device *dev)
956{
957 unsigned int nic_base = dev->base_addr;
958 int i;
959
960 ei_status.txing = ei_status.dmaing = 0;
961
962 outb_p(E8390_NODMA+E8390_PAGE0+E8390_STOP, nic_base + E8390_CMD);
963
964 outb(inb(nic_base + PCNET_RESET), nic_base + PCNET_RESET);
965
966 for (i = 0; i < 100; i++) {
967 if ((inb_p(nic_base+EN0_ISR) & ENISR_RESET) != 0)
968 break;
969 udelay(100);
970 }
971 outb_p(ENISR_RESET, nic_base + EN0_ISR); /* Ack intr. */
972
973 if (i == 100)
974 netdev_err(dev, "pcnet_reset_8390() did not complete.\n");
975
976 set_misc_reg(dev);
977
978} /* pcnet_reset_8390 */
979
980/*====================================================================*/
981
982static int set_config(struct net_device *dev, struct ifmap *map)
983{
984 pcnet_dev_t *info = PRIV(dev);
985 if ((map->port != (u_char)(-1)) && (map->port != dev->if_port)) {
986 if (!(info->flags & HAS_MISC_REG))
987 return -EOPNOTSUPP;
988 else if ((map->port < 1) || (map->port > 2))
989 return -EINVAL;
990 dev->if_port = map->port;
991 netdev_info(dev, "switched to %s port\n", if_names[dev->if_port]);
992 NS8390_init(dev, 1);
993 }
994 return 0;
995}
996
997/*====================================================================*/
998
999static irqreturn_t ei_irq_wrapper(int irq, void *dev_id)
1000{
1001 struct net_device *dev = dev_id;
1002 pcnet_dev_t *info;
1003 irqreturn_t ret = ei_interrupt(irq, dev_id);
1004
1005 if (ret == IRQ_HANDLED) {
1006 info = PRIV(dev);
1007 info->stale = 0;
1008 }
1009 return ret;
1010}
1011
1012static void ei_watchdog(u_long arg)
1013{
1014 struct net_device *dev = (struct net_device *)arg;
1015 pcnet_dev_t *info = PRIV(dev);
1016 unsigned int nic_base = dev->base_addr;
1017 unsigned int mii_addr = nic_base + DLINK_GPIO;
1018 u_short link;
1019
1020 if (!netif_device_present(dev)) goto reschedule;
1021
1022 /* Check for pending interrupt with expired latency timer: with
1023 this, we can limp along even if the interrupt is blocked */
1024 if (info->stale++ && (inb_p(nic_base + EN0_ISR) & ENISR_ALL)) {
1025 if (!info->fast_poll)
1026 netdev_info(dev, "interrupt(s) dropped!\n");
1027 ei_irq_wrapper(dev->irq, dev);
1028 info->fast_poll = HZ;
1029 }
1030 if (info->fast_poll) {
1031 info->fast_poll--;
1032 info->watchdog.expires = jiffies + 1;
1033 add_timer(&info->watchdog);
1034 return;
1035 }
1036
1037 if (!(info->flags & HAS_MII))
1038 goto reschedule;
1039
1040 mdio_read(mii_addr, info->phy_id, 1);
1041 link = mdio_read(mii_addr, info->phy_id, 1);
1042 if (!link || (link == 0xffff)) {
1043 if (info->eth_phy) {
1044 info->phy_id = info->eth_phy = 0;
1045 } else {
1046 netdev_info(dev, "MII is missing!\n");
1047 info->flags &= ~HAS_MII;
1048 }
1049 goto reschedule;
1050 }
1051
1052 link &= 0x0004;
1053 if (link != info->link_status) {
1054 u_short p = mdio_read(mii_addr, info->phy_id, 5);
1055 netdev_info(dev, "%s link beat\n", link ? "found" : "lost");
1056 if (link && (info->flags & IS_DL10022)) {
1057 /* Disable collision detection on full duplex links */
1058 outb((p & 0x0140) ? 4 : 0, nic_base + DLINK_DIAG);
1059 } else if (link && (info->flags & IS_DL10019)) {
1060 /* Disable collision detection on full duplex links */
1061 write_asic(dev->base_addr, 4, (p & 0x140) ? DL19FDUPLX : 0);
1062 }
1063 if (link) {
1064 if (info->phy_id == info->eth_phy) {
1065 if (p)
1066 netdev_info(dev, "autonegotiation complete: "
1067 "%sbaseT-%cD selected\n",
1068 ((p & 0x0180) ? "100" : "10"),
1069 ((p & 0x0140) ? 'F' : 'H'));
1070 else
1071 netdev_info(dev, "link partner did not autonegotiate\n");
1072 }
1073 NS8390_init(dev, 1);
1074 }
1075 info->link_status = link;
1076 }
1077 if (info->pna_phy && time_after(jiffies, info->mii_reset + 6*HZ)) {
1078 link = mdio_read(mii_addr, info->eth_phy, 1) & 0x0004;
1079 if (((info->phy_id == info->pna_phy) && link) ||
1080 ((info->phy_id != info->pna_phy) && !link)) {
1081 /* isolate this MII and try flipping to the other one */
1082 mdio_write(mii_addr, info->phy_id, 0, 0x0400);
1083 info->phy_id ^= info->pna_phy ^ info->eth_phy;
1084 netdev_info(dev, "switched to %s transceiver\n",
1085 (info->phy_id == info->eth_phy) ? "ethernet" : "PNA");
1086 mdio_write(mii_addr, info->phy_id, 0,
1087 (info->phy_id == info->eth_phy) ? 0x1000 : 0);
1088 info->link_status = 0;
1089 info->mii_reset = jiffies;
1090 }
1091 }
1092
1093reschedule:
1094 info->watchdog.expires = jiffies + HZ;
1095 add_timer(&info->watchdog);
1096}
1097
1098/*====================================================================*/
1099
1100
1101static int ei_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1102{
1103 pcnet_dev_t *info = PRIV(dev);
1104 struct mii_ioctl_data *data = if_mii(rq);
1105 unsigned int mii_addr = dev->base_addr + DLINK_GPIO;
1106
1107 if (!(info->flags & (IS_DL10019|IS_DL10022)))
1108 return -EINVAL;
1109
1110 switch (cmd) {
1111 case SIOCGMIIPHY:
1112 data->phy_id = info->phy_id;
1113 case SIOCGMIIREG: /* Read MII PHY register. */
1114 data->val_out = mdio_read(mii_addr, data->phy_id, data->reg_num & 0x1f);
1115 return 0;
1116 case SIOCSMIIREG: /* Write MII PHY register. */
1117 mdio_write(mii_addr, data->phy_id, data->reg_num & 0x1f, data->val_in);
1118 return 0;
1119 }
1120 return -EOPNOTSUPP;
1121}
1122
1123/*====================================================================*/
1124
1125static void dma_get_8390_hdr(struct net_device *dev,
1126 struct e8390_pkt_hdr *hdr,
1127 int ring_page)
1128{
1129 unsigned int nic_base = dev->base_addr;
1130
1131 if (ei_status.dmaing) {
1132 netdev_notice(dev, "DMAing conflict in dma_block_input."
1133 "[DMAstat:%1x][irqlock:%1x]\n",
1134 ei_status.dmaing, ei_status.irqlock);
1135 return;
1136 }
1137
1138 ei_status.dmaing |= 0x01;
1139 outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base + PCNET_CMD);
1140 outb_p(sizeof(struct e8390_pkt_hdr), nic_base + EN0_RCNTLO);
1141 outb_p(0, nic_base + EN0_RCNTHI);
1142 outb_p(0, nic_base + EN0_RSARLO); /* On page boundary */
1143 outb_p(ring_page, nic_base + EN0_RSARHI);
1144 outb_p(E8390_RREAD+E8390_START, nic_base + PCNET_CMD);
1145
1146 insw(nic_base + PCNET_DATAPORT, hdr,
1147 sizeof(struct e8390_pkt_hdr)>>1);
1148 /* Fix for big endian systems */
1149 hdr->count = le16_to_cpu(hdr->count);
1150
1151 outb_p(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */
1152 ei_status.dmaing &= ~0x01;
1153}
1154
1155/*====================================================================*/
1156
1157static void dma_block_input(struct net_device *dev, int count,
1158 struct sk_buff *skb, int ring_offset)
1159{
1160 unsigned int nic_base = dev->base_addr;
1161 int xfer_count = count;
1162 char *buf = skb->data;
1163
1164 if ((ei_debug > 4) && (count != 4))
1165 netdev_dbg(dev, "[bi=%d]\n", count+4);
1166 if (ei_status.dmaing) {
1167 netdev_notice(dev, "DMAing conflict in dma_block_input."
1168 "[DMAstat:%1x][irqlock:%1x]\n",
1169 ei_status.dmaing, ei_status.irqlock);
1170 return;
1171 }
1172 ei_status.dmaing |= 0x01;
1173 outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base + PCNET_CMD);
1174 outb_p(count & 0xff, nic_base + EN0_RCNTLO);
1175 outb_p(count >> 8, nic_base + EN0_RCNTHI);
1176 outb_p(ring_offset & 0xff, nic_base + EN0_RSARLO);
1177 outb_p(ring_offset >> 8, nic_base + EN0_RSARHI);
1178 outb_p(E8390_RREAD+E8390_START, nic_base + PCNET_CMD);
1179
1180 insw(nic_base + PCNET_DATAPORT,buf,count>>1);
1181 if (count & 0x01)
1182 buf[count-1] = inb(nic_base + PCNET_DATAPORT), xfer_count++;
1183
1184 /* This was for the ALPHA version only, but enough people have been
1185 encountering problems that it is still here. */
1186#ifdef PCMCIA_DEBUG
1187 if (ei_debug > 4) { /* DMA termination address check... */
1188 int addr, tries = 20;
1189 do {
1190 /* DON'T check for 'inb_p(EN0_ISR) & ENISR_RDC' here
1191 -- it's broken for Rx on some cards! */
1192 int high = inb_p(nic_base + EN0_RSARHI);
1193 int low = inb_p(nic_base + EN0_RSARLO);
1194 addr = (high << 8) + low;
1195 if (((ring_offset + xfer_count) & 0xff) == (addr & 0xff))
1196 break;
1197 } while (--tries > 0);
1198 if (tries <= 0)
1199 netdev_notice(dev, "RX transfer address mismatch,"
1200 "%#4.4x (expected) vs. %#4.4x (actual).\n",
1201 ring_offset + xfer_count, addr);
1202 }
1203#endif
1204 outb_p(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */
1205 ei_status.dmaing &= ~0x01;
1206} /* dma_block_input */
1207
1208/*====================================================================*/
1209
1210static void dma_block_output(struct net_device *dev, int count,
1211 const u_char *buf, const int start_page)
1212{
1213 unsigned int nic_base = dev->base_addr;
1214 pcnet_dev_t *info = PRIV(dev);
1215#ifdef PCMCIA_DEBUG
1216 int retries = 0;
1217#endif
1218 u_long dma_start;
1219
1220#ifdef PCMCIA_DEBUG
1221 if (ei_debug > 4)
1222 netdev_dbg(dev, "[bo=%d]\n", count);
1223#endif
1224
1225 /* Round the count up for word writes. Do we need to do this?
1226 What effect will an odd byte count have on the 8390?
1227 I should check someday. */
1228 if (count & 0x01)
1229 count++;
1230 if (ei_status.dmaing) {
1231 netdev_notice(dev, "DMAing conflict in dma_block_output."
1232 "[DMAstat:%1x][irqlock:%1x]\n",
1233 ei_status.dmaing, ei_status.irqlock);
1234 return;
1235 }
1236 ei_status.dmaing |= 0x01;
1237 /* We should already be in page 0, but to be safe... */
1238 outb_p(E8390_PAGE0+E8390_START+E8390_NODMA, nic_base+PCNET_CMD);
1239
1240#ifdef PCMCIA_DEBUG
1241 retry:
1242#endif
1243
1244 outb_p(ENISR_RDC, nic_base + EN0_ISR);
1245
1246 /* Now the normal output. */
1247 outb_p(count & 0xff, nic_base + EN0_RCNTLO);
1248 outb_p(count >> 8, nic_base + EN0_RCNTHI);
1249 outb_p(0x00, nic_base + EN0_RSARLO);
1250 outb_p(start_page, nic_base + EN0_RSARHI);
1251
1252 outb_p(E8390_RWRITE+E8390_START, nic_base + PCNET_CMD);
1253 outsw(nic_base + PCNET_DATAPORT, buf, count>>1);
1254
1255 dma_start = jiffies;
1256
1257#ifdef PCMCIA_DEBUG
1258 /* This was for the ALPHA version only, but enough people have been
1259 encountering problems that it is still here. */
1260 if (ei_debug > 4) { /* DMA termination address check... */
1261 int addr, tries = 20;
1262 do {
1263 int high = inb_p(nic_base + EN0_RSARHI);
1264 int low = inb_p(nic_base + EN0_RSARLO);
1265 addr = (high << 8) + low;
1266 if ((start_page << 8) + count == addr)
1267 break;
1268 } while (--tries > 0);
1269 if (tries <= 0) {
1270 netdev_notice(dev, "Tx packet transfer address mismatch,"
1271 "%#4.4x (expected) vs. %#4.4x (actual).\n",
1272 (start_page << 8) + count, addr);
1273 if (retries++ == 0)
1274 goto retry;
1275 }
1276 }
1277#endif
1278
1279 while ((inb_p(nic_base + EN0_ISR) & ENISR_RDC) == 0)
1280 if (time_after(jiffies, dma_start + PCNET_RDC_TIMEOUT)) {
1281 netdev_notice(dev, "timeout waiting for Tx RDC.\n");
1282 pcnet_reset_8390(dev);
1283 NS8390_init(dev, 1);
1284 break;
1285 }
1286
1287 outb_p(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */
1288 if (info->flags & DELAY_OUTPUT)
1289 udelay((long)delay_time);
1290 ei_status.dmaing &= ~0x01;
1291}
1292
1293/*====================================================================*/
1294
1295static int setup_dma_config(struct pcmcia_device *link, int start_pg,
1296 int stop_pg)
1297{
1298 struct net_device *dev = link->priv;
1299
1300 ei_status.tx_start_page = start_pg;
1301 ei_status.rx_start_page = start_pg + TX_PAGES;
1302 ei_status.stop_page = stop_pg;
1303
1304 /* set up block i/o functions */
1305 ei_status.get_8390_hdr = dma_get_8390_hdr;
1306 ei_status.block_input = dma_block_input;
1307 ei_status.block_output = dma_block_output;
1308
1309 return 0;
1310}
1311
1312/*====================================================================*/
1313
1314static void copyin(void *dest, void __iomem *src, int c)
1315{
1316 u_short *d = dest;
1317 u_short __iomem *s = src;
1318 int odd;
1319
1320 if (c <= 0)
1321 return;
1322 odd = (c & 1); c >>= 1;
1323
1324 if (c) {
1325 do { *d++ = __raw_readw(s++); } while (--c);
1326 }
1327 /* get last byte by fetching a word and masking */
1328 if (odd)
1329 *((u_char *)d) = readw(s) & 0xff;
1330}
1331
1332static void copyout(void __iomem *dest, const void *src, int c)
1333{
1334 u_short __iomem *d = dest;
1335 const u_short *s = src;
1336 int odd;
1337
1338 if (c <= 0)
1339 return;
1340 odd = (c & 1); c >>= 1;
1341
1342 if (c) {
1343 do { __raw_writew(*s++, d++); } while (--c);
1344 }
1345 /* copy last byte doing a read-modify-write */
1346 if (odd)
1347 writew((readw(d) & 0xff00) | *(u_char *)s, d);
1348}
1349
1350/*====================================================================*/
1351
1352static void shmem_get_8390_hdr(struct net_device *dev,
1353 struct e8390_pkt_hdr *hdr,
1354 int ring_page)
1355{
1356 void __iomem *xfer_start = ei_status.mem + (TX_PAGES<<8)
1357 + (ring_page << 8)
1358 - (ei_status.rx_start_page << 8);
1359
1360 copyin(hdr, xfer_start, sizeof(struct e8390_pkt_hdr));
1361 /* Fix for big endian systems */
1362 hdr->count = le16_to_cpu(hdr->count);
1363}
1364
1365/*====================================================================*/
1366
1367static void shmem_block_input(struct net_device *dev, int count,
1368 struct sk_buff *skb, int ring_offset)
1369{
1370 void __iomem *base = ei_status.mem;
1371 unsigned long offset = (TX_PAGES<<8) + ring_offset
1372 - (ei_status.rx_start_page << 8);
1373 char *buf = skb->data;
1374
1375 if (offset + count > ei_status.priv) {
1376 /* We must wrap the input move. */
1377 int semi_count = ei_status.priv - offset;
1378 copyin(buf, base + offset, semi_count);
1379 buf += semi_count;
1380 offset = TX_PAGES<<8;
1381 count -= semi_count;
1382 }
1383 copyin(buf, base + offset, count);
1384}
1385
1386/*====================================================================*/
1387
1388static void shmem_block_output(struct net_device *dev, int count,
1389 const u_char *buf, const int start_page)
1390{
1391 void __iomem *shmem = ei_status.mem + (start_page << 8);
1392 shmem -= ei_status.tx_start_page << 8;
1393 copyout(shmem, buf, count);
1394}
1395
1396/*====================================================================*/
1397
1398static int setup_shmem_window(struct pcmcia_device *link, int start_pg,
1399 int stop_pg, int cm_offset)
1400{
1401 struct net_device *dev = link->priv;
1402 pcnet_dev_t *info = PRIV(dev);
1403 int i, window_size, offset, ret;
1404
1405 window_size = (stop_pg - start_pg) << 8;
1406 if (window_size > 32 * 1024)
1407 window_size = 32 * 1024;
1408
1409 /* Make sure it's a power of two. */
1410 window_size = roundup_pow_of_two(window_size);
1411
1412 /* Allocate a memory window */
1413 link->resource[3]->flags |= WIN_DATA_WIDTH_16|WIN_MEMORY_TYPE_CM|WIN_ENABLE;
1414 link->resource[3]->flags |= WIN_USE_WAIT;
1415 link->resource[3]->start = 0; link->resource[3]->end = window_size;
1416 ret = pcmcia_request_window(link, link->resource[3], mem_speed);
1417 if (ret)
1418 goto failed;
1419
1420 offset = (start_pg << 8) + cm_offset;
1421 offset -= offset % window_size;
1422 ret = pcmcia_map_mem_page(link, link->resource[3], offset);
1423 if (ret)
1424 goto failed;
1425
1426 /* Try scribbling on the buffer */
1427 info->base = ioremap(link->resource[3]->start,
1428 resource_size(link->resource[3]));
1429 for (i = 0; i < (TX_PAGES<<8); i += 2)
1430 __raw_writew((i>>1), info->base+offset+i);
1431 udelay(100);
1432 for (i = 0; i < (TX_PAGES<<8); i += 2)
1433 if (__raw_readw(info->base+offset+i) != (i>>1)) break;
1434 pcnet_reset_8390(dev);
1435 if (i != (TX_PAGES<<8)) {
1436 iounmap(info->base);
1437 pcmcia_release_window(link, link->resource[3]);
1438 info->base = NULL;
1439 goto failed;
1440 }
1441
1442 ei_status.mem = info->base + offset;
1443 ei_status.priv = resource_size(link->resource[3]);
1444 dev->mem_start = (u_long)ei_status.mem;
1445 dev->mem_end = dev->mem_start + resource_size(link->resource[3]);
1446
1447 ei_status.tx_start_page = start_pg;
1448 ei_status.rx_start_page = start_pg + TX_PAGES;
1449 ei_status.stop_page = start_pg + (
1450 (resource_size(link->resource[3]) - offset) >> 8);
1451
1452 /* set up block i/o functions */
1453 ei_status.get_8390_hdr = shmem_get_8390_hdr;
1454 ei_status.block_input = shmem_block_input;
1455 ei_status.block_output = shmem_block_output;
1456
1457 info->flags |= USE_SHMEM;
1458 return 0;
1459
1460failed:
1461 return 1;
1462}
1463
1464/*====================================================================*/
1465
1466static const struct pcmcia_device_id pcnet_ids[] = {
1467 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0057, 0x0021),
1468 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0104, 0x000a),
1469 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0105, 0xea15),
1470 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0143, 0x3341),
1471 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0143, 0xc0ab),
1472 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x021b, 0x0101),
1473 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x08a1, 0xc0ab),
1474 PCMCIA_PFC_DEVICE_PROD_ID12(0, "AnyCom", "Fast Ethernet + 56K COMBO", 0x578ba6e7, 0xb0ac62c4),
1475 PCMCIA_PFC_DEVICE_PROD_ID12(0, "ATKK", "LM33-PCM-T", 0xba9eb7e2, 0x077c174e),
1476 PCMCIA_PFC_DEVICE_PROD_ID12(0, "D-Link", "DME336T", 0x1a424a1c, 0xb23897ff),
1477 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Grey Cell", "GCS3000", 0x2a151fac, 0x48b932ae),
1478 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Linksys", "EtherFast 10&100 + 56K PC Card (PCMLM56)", 0x0733cc81, 0xb3765033),
1479 PCMCIA_PFC_DEVICE_PROD_ID12(0, "LINKSYS", "PCMLM336", 0xf7cb0b07, 0x7a821b58),
1480 PCMCIA_PFC_DEVICE_PROD_ID12(0, "MICRO RESEARCH", "COMBO-L/M-336", 0xb2ced065, 0x3ced0555),
1481 PCMCIA_PFC_DEVICE_PROD_ID12(0, "PCMCIAs", "ComboCard", 0xdcfe12d3, 0xcd8906cc),
1482 PCMCIA_PFC_DEVICE_PROD_ID12(0, "PCMCIAs", "LanModem", 0xdcfe12d3, 0xc67c648f),
1483 PCMCIA_MFC_DEVICE_PROD_ID12(0, "IBM", "Home and Away 28.8 PC Card ", 0xb569a6e5, 0x5bd4ff2c),
1484 PCMCIA_MFC_DEVICE_PROD_ID12(0, "IBM", "Home and Away Credit Card Adapter", 0xb569a6e5, 0x4bdf15c3),
1485 PCMCIA_MFC_DEVICE_PROD_ID12(0, "IBM", "w95 Home and Away Credit Card ", 0xb569a6e5, 0xae911c15),
1486 PCMCIA_MFC_DEVICE_PROD_ID123(0, "APEX DATA", "MULTICARD", "ETHERNET-MODEM", 0x11c2da09, 0x7289dc5d, 0xaad95e1f),
1487 PCMCIA_MFC_DEVICE_PROD_ID2(0, "FAX/Modem/Ethernet Combo Card ", 0x1ed59302),
1488 PCMCIA_DEVICE_MANF_CARD(0x0057, 0x1004),
1489 PCMCIA_DEVICE_MANF_CARD(0x0104, 0x000d),
1490 PCMCIA_DEVICE_MANF_CARD(0x0104, 0x0075),
1491 PCMCIA_DEVICE_MANF_CARD(0x0104, 0x0145),
1492 PCMCIA_DEVICE_MANF_CARD(0x0149, 0x0230),
1493 PCMCIA_DEVICE_MANF_CARD(0x0149, 0x4530),
1494 PCMCIA_DEVICE_MANF_CARD(0x0149, 0xc1ab),
1495 PCMCIA_DEVICE_MANF_CARD(0x0186, 0x0110),
1496 PCMCIA_DEVICE_MANF_CARD(0x01bf, 0x8041),
1497 PCMCIA_DEVICE_MANF_CARD(0x0213, 0x2452),
1498 PCMCIA_DEVICE_MANF_CARD(0x026f, 0x0300),
1499 PCMCIA_DEVICE_MANF_CARD(0x026f, 0x0307),
1500 PCMCIA_DEVICE_MANF_CARD(0x026f, 0x030a),
1501 PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1103),
1502 PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1121),
1503 PCMCIA_DEVICE_PROD_ID12("2408LAN", "Ethernet", 0x352fff7f, 0x00b2e941),
1504 PCMCIA_DEVICE_PROD_ID1234("Socket", "CF 10/100 Ethernet Card", "Revision B", "05/11/06", 0xb38bcc2e, 0x4de88352, 0xeaca6c8d, 0x7e57c22e),
1505 PCMCIA_DEVICE_PROD_ID123("Cardwell", "PCMCIA", "ETHERNET", 0x9533672e, 0x281f1c5d, 0x3ff7175b),
1506 PCMCIA_DEVICE_PROD_ID123("CNet ", "CN30BC", "ETHERNET", 0x9fe55d3d, 0x85601198, 0x3ff7175b),
1507 PCMCIA_DEVICE_PROD_ID123("Digital", "Ethernet", "Adapter", 0x9999ab35, 0x00b2e941, 0x4b0d829e),
1508 PCMCIA_DEVICE_PROD_ID123("Edimax Technology Inc.", "PCMCIA", "Ethernet Card", 0x738a0019, 0x281f1c5d, 0x5e9d92c0),
1509 PCMCIA_DEVICE_PROD_ID123("EFA ", "EFA207", "ETHERNET", 0x3d294be4, 0xeb9aab6c, 0x3ff7175b),
1510 PCMCIA_DEVICE_PROD_ID123("I-O DATA", "PCLA", "ETHERNET", 0x1d55d7ec, 0xe4c64d34, 0x3ff7175b),
1511 PCMCIA_DEVICE_PROD_ID123("IO DATA", "PCLATE", "ETHERNET", 0x547e66dc, 0x6b260753, 0x3ff7175b),
1512 PCMCIA_DEVICE_PROD_ID123("KingMax Technology Inc.", "EN10-T2", "PCMCIA Ethernet Card", 0x932b7189, 0x699e4436, 0x6f6652e0),
1513 PCMCIA_DEVICE_PROD_ID123("PCMCIA", "PCMCIA-ETHERNET-CARD", "UE2216", 0x281f1c5d, 0xd4cd2f20, 0xb87add82),
1514 PCMCIA_DEVICE_PROD_ID123("PCMCIA", "PCMCIA-ETHERNET-CARD", "UE2620", 0x281f1c5d, 0xd4cd2f20, 0x7d3d83a8),
1515 PCMCIA_DEVICE_PROD_ID1("2412LAN", 0x67f236ab),
1516 PCMCIA_DEVICE_PROD_ID12("ACCTON", "EN2212", 0xdfc6b5b2, 0xcb112a11),
1517 PCMCIA_DEVICE_PROD_ID12("ACCTON", "EN2216-PCMCIA-ETHERNET", 0xdfc6b5b2, 0x5542bfff),
1518 PCMCIA_DEVICE_PROD_ID12("Allied Telesis, K.K.", "CentreCOM LA100-PCM-T V2 100/10M LAN PC Card", 0xbb7fbdd7, 0xcd91cc68),
1519 PCMCIA_DEVICE_PROD_ID12("Allied Telesis K.K.", "LA100-PCM V2", 0x36634a66, 0xc6d05997),
1520 PCMCIA_DEVICE_PROD_ID12("Allied Telesis, K.K.", "CentreCOM LA-PCM_V2", 0xbb7fBdd7, 0x28e299f8),
1521 PCMCIA_DEVICE_PROD_ID12("Allied Telesis K.K.", "LA-PCM V3", 0x36634a66, 0x62241d96),
1522 PCMCIA_DEVICE_PROD_ID12("AmbiCom", "AMB8010", 0x5070a7f9, 0x82f96e96),
1523 PCMCIA_DEVICE_PROD_ID12("AmbiCom", "AMB8610", 0x5070a7f9, 0x86741224),
1524 PCMCIA_DEVICE_PROD_ID12("AmbiCom Inc", "AMB8002", 0x93b15570, 0x75ec3efb),
1525 PCMCIA_DEVICE_PROD_ID12("AmbiCom Inc", "AMB8002T", 0x93b15570, 0x461c5247),
1526 PCMCIA_DEVICE_PROD_ID12("AmbiCom Inc", "AMB8010", 0x93b15570, 0x82f96e96),
1527 PCMCIA_DEVICE_PROD_ID12("AnyCom", "ECO Ethernet", 0x578ba6e7, 0x0a9888c1),
1528 PCMCIA_DEVICE_PROD_ID12("AnyCom", "ECO Ethernet 10/100", 0x578ba6e7, 0x939fedbd),
1529 PCMCIA_DEVICE_PROD_ID12("AROWANA", "PCMCIA Ethernet LAN Card", 0x313adbc8, 0x08d9f190),
1530 PCMCIA_DEVICE_PROD_ID12("ASANTE", "FriendlyNet PC Card", 0x3a7ade0f, 0x41c64504),
1531 PCMCIA_DEVICE_PROD_ID12("Billionton", "LNT-10TB", 0x552ab682, 0xeeb1ba6a),
1532 PCMCIA_DEVICE_PROD_ID12("CF", "10Base-Ethernet", 0x44ebf863, 0x93ae4d79),
1533 PCMCIA_DEVICE_PROD_ID12("CNet", "CN40BC Ethernet", 0xbc477dde, 0xfba775a7),
1534 PCMCIA_DEVICE_PROD_ID12("COMPU-SHACK", "BASEline PCMCIA 10 MBit Ethernetadapter", 0xfa2e424d, 0xe9190d8a),
1535 PCMCIA_DEVICE_PROD_ID12("COMPU-SHACK", "FASTline PCMCIA 10/100 Fast-Ethernet", 0xfa2e424d, 0x3953d9b9),
1536 PCMCIA_DEVICE_PROD_ID12("CONTEC", "C-NET(PC)C-10L", 0x21cab552, 0xf6f90722),
1537 PCMCIA_DEVICE_PROD_ID12("corega", "FEther PCC-TXF", 0x0a21501a, 0xa51564a2),
1538 PCMCIA_DEVICE_PROD_ID12("corega", "Ether CF-TD", 0x0a21501a, 0x6589340a),
1539 PCMCIA_DEVICE_PROD_ID12("corega K.K.", "corega Ether CF-TD LAN Card", 0x5261440f, 0x8797663b),
1540 PCMCIA_DEVICE_PROD_ID12("corega K.K.", "corega EtherII PCC-T", 0x5261440f, 0xfa9d85bd),
1541 PCMCIA_DEVICE_PROD_ID12("corega K.K.", "corega EtherII PCC-TD", 0x5261440f, 0xc49bd73d),
1542 PCMCIA_DEVICE_PROD_ID12("Corega K.K.", "corega EtherII PCC-TD", 0xd4fdcbd8, 0xc49bd73d),
1543 PCMCIA_DEVICE_PROD_ID12("corega K.K.", "corega Ether PCC-T", 0x5261440f, 0x6705fcaa),
1544 PCMCIA_DEVICE_PROD_ID12("corega K.K.", "corega Ether PCC-TD", 0x5261440f, 0x47d5ca83),
1545 PCMCIA_DEVICE_PROD_ID12("corega K.K.", "corega FastEther PCC-TX", 0x5261440f, 0x485e85d9),
1546 PCMCIA_DEVICE_PROD_ID12("Corega,K.K.", "Ethernet LAN Card", 0x110d26d9, 0x9fd2f0a2),
1547 PCMCIA_DEVICE_PROD_ID12("corega,K.K.", "Ethernet LAN Card", 0x9791a90e, 0x9fd2f0a2),
1548 PCMCIA_DEVICE_PROD_ID12("corega K.K.", "(CG-LAPCCTXD)", 0x5261440f, 0x73ec0d88),
1549 PCMCIA_DEVICE_PROD_ID12("CouplerlessPCMCIA", "100BASE", 0xee5af0ad, 0x7c2add04),
1550 PCMCIA_DEVICE_PROD_ID12("CyQ've", "ELA-010", 0x77008979, 0x9d8d445d),
1551 PCMCIA_DEVICE_PROD_ID12("CyQ've", "ELA-110E 10/100M LAN Card", 0x77008979, 0xfd184814),
1552 PCMCIA_DEVICE_PROD_ID12("DataTrek.", "NetCard ", 0x5cd66d9d, 0x84697ce0),
1553 PCMCIA_DEVICE_PROD_ID12("Dayna Communications, Inc.", "CommuniCard E", 0x0c629325, 0xb4e7dbaf),
1554 PCMCIA_DEVICE_PROD_ID12("Digicom", "Palladio LAN 10/100", 0x697403d8, 0xe160b995),
1555 PCMCIA_DEVICE_PROD_ID12("Digicom", "Palladio LAN 10/100 Dongless", 0x697403d8, 0xa6d3b233),
1556 PCMCIA_DEVICE_PROD_ID12("DIGITAL", "DEPCM-XX", 0x69616cb3, 0xe600e76e),
1557 PCMCIA_DEVICE_PROD_ID12("D-Link", "DE-650", 0x1a424a1c, 0xf28c8398),
1558 PCMCIA_DEVICE_PROD_ID12("D-Link", "DE-660", 0x1a424a1c, 0xd9a1d05b),
1559 PCMCIA_DEVICE_PROD_ID12("D-Link", "DE-660+", 0x1a424a1c, 0x50dcd0ec),
1560 PCMCIA_DEVICE_PROD_ID12("D-Link", "DFE-650", 0x1a424a1c, 0x0f0073f9),
1561 PCMCIA_DEVICE_PROD_ID12("Dual Speed", "10/100 PC Card", 0x725b842d, 0xf1efee84),
1562 PCMCIA_DEVICE_PROD_ID12("Dual Speed", "10/100 Port Attached PC Card", 0x725b842d, 0x2db1f8e9),
1563 PCMCIA_DEVICE_PROD_ID12("Dynalink", "L10BC", 0x55632fd5, 0xdc65f2b1),
1564 PCMCIA_DEVICE_PROD_ID12("DYNALINK", "L10BC", 0x6a26d1cf, 0xdc65f2b1),
1565 PCMCIA_DEVICE_PROD_ID12("DYNALINK", "L10C", 0x6a26d1cf, 0xc4f84efb),
1566 PCMCIA_DEVICE_PROD_ID12("E-CARD", "E-CARD", 0x6701da11, 0x6701da11),
1567 PCMCIA_DEVICE_PROD_ID12("EIGER Labs Inc.", "Ethernet 10BaseT card", 0x53c864c6, 0xedd059f6),
1568 PCMCIA_DEVICE_PROD_ID12("EIGER Labs Inc.", "Ethernet Combo card", 0x53c864c6, 0x929c486c),
1569 PCMCIA_DEVICE_PROD_ID12("Ethernet", "Adapter", 0x00b2e941, 0x4b0d829e),
1570 PCMCIA_DEVICE_PROD_ID12("Ethernet Adapter", "E2000 PCMCIA Ethernet", 0x96767301, 0x71fbbc61),
1571 PCMCIA_DEVICE_PROD_ID12("Ethernet PCMCIA adapter", "EP-210", 0x8dd86181, 0xf2b52517),
1572 PCMCIA_DEVICE_PROD_ID12("Fast Ethernet", "Adapter", 0xb4be14e3, 0x4b0d829e),
1573 PCMCIA_DEVICE_PROD_ID12("Grey Cell", "GCS2000", 0x2a151fac, 0xf00555cb),
1574 PCMCIA_DEVICE_PROD_ID12("Grey Cell", "GCS2220", 0x2a151fac, 0xc1b7e327),
1575 PCMCIA_DEVICE_PROD_ID12("GVC", "NIC-2000p", 0x76e171bd, 0x6eb1c947),
1576 PCMCIA_DEVICE_PROD_ID12("IBM Corp.", "Ethernet", 0xe3736c88, 0x00b2e941),
1577 PCMCIA_DEVICE_PROD_ID12("IC-CARD", "IC-CARD", 0x60cb09a6, 0x60cb09a6),
1578 PCMCIA_DEVICE_PROD_ID12("IC-CARD+", "IC-CARD+", 0x93693494, 0x93693494),
1579 PCMCIA_DEVICE_PROD_ID12("IO DATA", "PCETTX", 0x547e66dc, 0x6fc5459b),
1580 PCMCIA_DEVICE_PROD_ID12("iPort", "10/100 Ethernet Card", 0x56c538d2, 0x11b0ffc0),
1581 PCMCIA_DEVICE_PROD_ID12("KANSAI ELECTRIC CO.,LTD", "KLA-PCM/T", 0xb18dc3b4, 0xcc51a956),
1582 PCMCIA_DEVICE_PROD_ID12("KENTRONICS", "KEP-230", 0xaf8144c9, 0x868f6616),
1583 PCMCIA_DEVICE_PROD_ID12("KCI", "PE520 PCMCIA Ethernet Adapter", 0xa89b87d3, 0x1eb88e64),
1584 PCMCIA_DEVICE_PROD_ID12("KINGMAX", "EN10T2T", 0x7bcb459a, 0xa5c81fa5),
1585 PCMCIA_DEVICE_PROD_ID12("Kingston", "KNE-PC2", 0x1128e633, 0xce2a89b3),
1586 PCMCIA_DEVICE_PROD_ID12("Kingston Technology Corp.", "EtheRx PC Card Ethernet Adapter", 0x313c7be3, 0x0afb54a2),
1587 PCMCIA_DEVICE_PROD_ID12("Laneed", "LD-10/100CD", 0x1b7827b2, 0xcda71d1c),
1588 PCMCIA_DEVICE_PROD_ID12("Laneed", "LD-CDF", 0x1b7827b2, 0xfec71e40),
1589 PCMCIA_DEVICE_PROD_ID12("Laneed", "LD-CDL/T", 0x1b7827b2, 0x79fba4f7),
1590 PCMCIA_DEVICE_PROD_ID12("Laneed", "LD-CDS", 0x1b7827b2, 0x931afaab),
1591 PCMCIA_DEVICE_PROD_ID12("LEMEL", "LM-N89TX PRO", 0xbbefb52f, 0xd2897a97),
1592 PCMCIA_DEVICE_PROD_ID12("Linksys", "Combo PCMCIA EthernetCard (EC2T)", 0x0733cc81, 0x32ee8c78),
1593 PCMCIA_DEVICE_PROD_ID12("LINKSYS", "E-CARD", 0xf7cb0b07, 0x6701da11),
1594 PCMCIA_DEVICE_PROD_ID12("Linksys", "EtherFast 10/100 Integrated PC Card (PCM100)", 0x0733cc81, 0x453c3f9d),
1595 PCMCIA_DEVICE_PROD_ID12("Linksys", "EtherFast 10/100 PC Card (PCMPC100)", 0x0733cc81, 0x66c5a389),
1596 PCMCIA_DEVICE_PROD_ID12("Linksys", "EtherFast 10/100 PC Card (PCMPC100 V2)", 0x0733cc81, 0x3a3b28e9),
1597 PCMCIA_DEVICE_PROD_ID12("Linksys", "HomeLink Phoneline + 10/100 Network PC Card (PCM100H1)", 0x733cc81, 0x7a3e5c3a),
1598 PCMCIA_DEVICE_PROD_ID12("Logitec", "LPM-LN100TX", 0x88fcdeda, 0x6d772737),
1599 PCMCIA_DEVICE_PROD_ID12("Logitec", "LPM-LN100TE", 0x88fcdeda, 0x0e714bee),
1600 PCMCIA_DEVICE_PROD_ID12("Logitec", "LPM-LN20T", 0x88fcdeda, 0x81090922),
1601 PCMCIA_DEVICE_PROD_ID12("Logitec", "LPM-LN10TE", 0x88fcdeda, 0xc1e2521c),
1602 PCMCIA_DEVICE_PROD_ID12("LONGSHINE", "PCMCIA Ethernet Card", 0xf866b0b0, 0x6f6652e0),
1603 PCMCIA_DEVICE_PROD_ID12("MACNICA", "ME1-JEIDA", 0x20841b68, 0xaf8a3578),
1604 PCMCIA_DEVICE_PROD_ID12("Macsense", "MPC-10", 0xd830297f, 0xd265c307),
1605 PCMCIA_DEVICE_PROD_ID12("Matsushita Electric Industrial Co.,LTD.", "CF-VEL211", 0x44445376, 0x8ded41d4),
1606 PCMCIA_DEVICE_PROD_ID12("MAXTECH", "PCN2000", 0x78d64bc0, 0xca0ca4b8),
1607 PCMCIA_DEVICE_PROD_ID12("MELCO", "LPC2-T", 0x481e0094, 0xa2eb0cf3),
1608 PCMCIA_DEVICE_PROD_ID12("MELCO", "LPC2-TX", 0x481e0094, 0x41a6916c),
1609 PCMCIA_DEVICE_PROD_ID12("Microcom C.E.", "Travel Card LAN 10/100", 0x4b91cec7, 0xe70220d6),
1610 PCMCIA_DEVICE_PROD_ID12("Microdyne", "NE4200", 0x2e6da59b, 0x0478e472),
1611 PCMCIA_DEVICE_PROD_ID12("MIDORI ELEC.", "LT-PCMT", 0x648d55c1, 0xbde526c7),
1612 PCMCIA_DEVICE_PROD_ID12("National Semiconductor", "InfoMover 4100", 0x36e1191f, 0x60c229b9),
1613 PCMCIA_DEVICE_PROD_ID12("National Semiconductor", "InfoMover NE4100", 0x36e1191f, 0xa6617ec8),
1614 PCMCIA_DEVICE_PROD_ID12("NEC", "PC-9801N-J12", 0x18df0ba0, 0xbc912d76),
1615 PCMCIA_DEVICE_PROD_ID12("NETGEAR", "FA410TX", 0x9aa79dc3, 0x60e5bc0e),
1616 PCMCIA_DEVICE_PROD_ID12("Network Everywhere", "Fast Ethernet 10/100 PC Card", 0x820a67b6, 0x31ed1a5f),
1617 PCMCIA_DEVICE_PROD_ID12("NextCom K.K.", "Next Hawk", 0xaedaec74, 0xad050ef1),
1618 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "10/100Mbps Ethernet Card", 0x281f1c5d, 0x6e41773b),
1619 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "Ethernet", 0x281f1c5d, 0x00b2e941),
1620 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "ETHERNET", 0x281f1c5d, 0x3ff7175b),
1621 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "Ethernet 10BaseT Card", 0x281f1c5d, 0x4de2f6c8),
1622 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "Ethernet Card", 0x281f1c5d, 0x5e9d92c0),
1623 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "Ethernet Combo card", 0x281f1c5d, 0x929c486c),
1624 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "ETHERNET V1.0", 0x281f1c5d, 0x4d8817c8),
1625 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "FastEthernet", 0x281f1c5d, 0xfe871eeb),
1626 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "Fast-Ethernet", 0x281f1c5d, 0x45f1f3b4),
1627 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "FAST ETHERNET CARD", 0x281f1c5d, 0xec5dbca7),
1628 PCMCIA_DEVICE_PROD_ID12("PCMCIA LAN", "Ethernet", 0x7500e246, 0x00b2e941),
1629 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "LNT-10TN", 0x281f1c5d, 0xe707f641),
1630 PCMCIA_DEVICE_PROD_ID12("PCMCIAs", "ComboCard", 0xdcfe12d3, 0xcd8906cc),
1631 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "UE2212", 0x281f1c5d, 0xbf17199b),
1632 PCMCIA_DEVICE_PROD_ID12("PCMCIA", " Ethernet NE2000 Compatible", 0x281f1c5d, 0x42d5d7e1),
1633 PCMCIA_DEVICE_PROD_ID12("PRETEC", "Ethernet CompactLAN 10baseT 3.3V", 0xebf91155, 0x30074c80),
1634 PCMCIA_DEVICE_PROD_ID12("PRETEC", "Ethernet CompactLAN 10BaseT 3.3V", 0xebf91155, 0x7f5a4f50),
1635 PCMCIA_DEVICE_PROD_ID12("Psion Dacom", "Gold Card Ethernet", 0xf5f025c2, 0x3a30e110),
1636 PCMCIA_DEVICE_PROD_ID12("=RELIA==", "Ethernet", 0xcdd0644a, 0x00b2e941),
1637 PCMCIA_DEVICE_PROD_ID12("RIOS Systems Co.", "PC CARD3 ETHERNET", 0x7dd33481, 0x10b41826),
1638 PCMCIA_DEVICE_PROD_ID12("RP", "1625B Ethernet NE2000 Compatible", 0xe3e66e22, 0xb96150df),
1639 PCMCIA_DEVICE_PROD_ID12("RPTI", "EP400 Ethernet NE2000 Compatible", 0xdc6f88fd, 0x4a7e2ae0),
1640 PCMCIA_DEVICE_PROD_ID12("RPTI", "EP401 Ethernet NE2000 Compatible", 0xdc6f88fd, 0x4bcbd7fd),
1641 PCMCIA_DEVICE_PROD_ID12("RPTI LTD.", "EP400", 0xc53ac515, 0x81e39388),
1642 PCMCIA_DEVICE_PROD_ID12("SCM", "Ethernet Combo card", 0xbdc3b102, 0x929c486c),
1643 PCMCIA_DEVICE_PROD_ID12("Seiko Epson Corp.", "Ethernet", 0x09928730, 0x00b2e941),
1644 PCMCIA_DEVICE_PROD_ID12("SMC", "EZCard-10-PCMCIA", 0xc4f8b18b, 0xfb21d265),
1645 PCMCIA_DEVICE_PROD_ID12("Socket Communications Inc", "Socket EA PCMCIA LAN Adapter Revision D", 0xc70a4760, 0x2ade483e),
1646 PCMCIA_DEVICE_PROD_ID12("Socket Communications Inc", "Socket EA PCMCIA LAN Adapter Revision E", 0xc70a4760, 0x5dd978a8),
1647 PCMCIA_DEVICE_PROD_ID12("TDK", "LAK-CD031 for PCMCIA", 0x1eae9475, 0x0ed386fa),
1648 PCMCIA_DEVICE_PROD_ID12("Telecom Device K.K.", "SuperSocket RE450T", 0x466b05f0, 0x8b74bc4f),
1649 PCMCIA_DEVICE_PROD_ID12("Telecom Device K.K.", "SuperSocket RE550T", 0x466b05f0, 0x33c8db2a),
1650 PCMCIA_DEVICE_PROD_ID13("Hypertec", "EP401", 0x8787bec7, 0xf6e4a31e),
1651 PCMCIA_DEVICE_PROD_ID13("KingMax Technology Inc.", "Ethernet Card", 0x932b7189, 0x5e9d92c0),
1652 PCMCIA_DEVICE_PROD_ID13("LONGSHINE", "EP401", 0xf866b0b0, 0xf6e4a31e),
1653 PCMCIA_DEVICE_PROD_ID13("Xircom", "CFE-10", 0x2e3ee845, 0x22a49f89),
1654 PCMCIA_DEVICE_PROD_ID1("CyQ've 10 Base-T LAN CARD", 0x94faf360),
1655 PCMCIA_DEVICE_PROD_ID1("EP-210 PCMCIA LAN CARD.", 0x8850b4de),
1656 PCMCIA_DEVICE_PROD_ID1("ETHER-C16", 0x06a8514f),
1657 PCMCIA_DEVICE_PROD_ID1("NE2000 Compatible", 0x75b8ad5a),
1658 PCMCIA_DEVICE_PROD_ID2("EN-6200P2", 0xa996d078),
1659 /* too generic! */
1660 /* PCMCIA_DEVICE_PROD_ID12("PCMCIA", "10/100 Ethernet Card", 0x281f1c5d, 0x11b0ffc0), */
1661 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(0, "PCMCIA", "EN2218-LAN/MODEM", 0x281f1c5d, 0x570f348e, "cis/PCMLM28.cis"),
1662 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(0, "PCMCIA", "UE2218-LAN/MODEM", 0x281f1c5d, 0x6fdcacee, "cis/PCMLM28.cis"),
1663 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(0, "Psion Dacom", "Gold Card V34 Ethernet", 0xf5f025c2, 0x338e8155, "cis/PCMLM28.cis"),
1664 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(0, "Psion Dacom", "Gold Card V34 Ethernet GSM", 0xf5f025c2, 0x4ae85d35, "cis/PCMLM28.cis"),
1665 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(0, "LINKSYS", "PCMLM28", 0xf7cb0b07, 0x66881874, "cis/PCMLM28.cis"),
1666 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(0, "TOSHIBA", "Modem/LAN Card", 0xb4585a1a, 0x53f922f8, "cis/PCMLM28.cis"),
1667 PCMCIA_MFC_DEVICE_CIS_PROD_ID12(0, "DAYNA COMMUNICATIONS", "LAN AND MODEM MULTIFUNCTION", 0x8fdf8f89, 0xdd5ed9e8, "cis/DP83903.cis"),
1668 PCMCIA_MFC_DEVICE_CIS_PROD_ID4(0, "NSC MF LAN/Modem", 0x58fc6056, "cis/DP83903.cis"),
1669 PCMCIA_MFC_DEVICE_CIS_MANF_CARD(0, 0x0175, 0x0000, "cis/DP83903.cis"),
1670 PCMCIA_DEVICE_CIS_PROD_ID12("Allied Telesis,K.K", "Ethernet LAN Card", 0x2ad62f3c, 0x9fd2f0a2, "cis/LA-PCM.cis"),
1671 PCMCIA_DEVICE_CIS_PROD_ID12("KTI", "PE520 PLUS", 0xad180345, 0x9d58d392, "cis/PE520.cis"),
1672 PCMCIA_DEVICE_CIS_PROD_ID12("NDC", "Ethernet", 0x01c43ae1, 0x00b2e941, "cis/NE2K.cis"),
1673 PCMCIA_DEVICE_CIS_PROD_ID12("PMX ", "PE-200", 0x34f3f1c8, 0x10b59f8c, "cis/PE-200.cis"),
1674 PCMCIA_DEVICE_CIS_PROD_ID12("TAMARACK", "Ethernet", 0xcf434fba, 0x00b2e941, "cis/tamarack.cis"),
1675 PCMCIA_DEVICE_PROD_ID12("Ethernet", "CF Size PC Card", 0x00b2e941, 0x43ac239b),
1676 PCMCIA_DEVICE_PROD_ID123("Fast Ethernet", "CF Size PC Card", "1.0",
1677 0xb4be14e3, 0x43ac239b, 0x0877b627),
1678 PCMCIA_DEVICE_NULL
1679};
1680MODULE_DEVICE_TABLE(pcmcia, pcnet_ids);
1681MODULE_FIRMWARE("cis/PCMLM28.cis");
1682MODULE_FIRMWARE("cis/DP83903.cis");
1683MODULE_FIRMWARE("cis/LA-PCM.cis");
1684MODULE_FIRMWARE("cis/PE520.cis");
1685MODULE_FIRMWARE("cis/NE2K.cis");
1686MODULE_FIRMWARE("cis/PE-200.cis");
1687MODULE_FIRMWARE("cis/tamarack.cis");
1688
1689static struct pcmcia_driver pcnet_driver = {
1690 .name = "pcnet_cs",
1691 .probe = pcnet_probe,
1692 .remove = pcnet_detach,
1693 .owner = THIS_MODULE,
1694 .id_table = pcnet_ids,
1695 .suspend = pcnet_suspend,
1696 .resume = pcnet_resume,
1697};
1698
1699static int __init init_pcnet_cs(void)
1700{
1701 return pcmcia_register_driver(&pcnet_driver);
1702}
1703
1704static void __exit exit_pcnet_cs(void)
1705{
1706 pcmcia_unregister_driver(&pcnet_driver);
1707}
1708
1709module_init(init_pcnet_cs);
1710module_exit(exit_pcnet_cs);
diff --git a/drivers/net/pcmcia/smc91c92_cs.c b/drivers/net/pcmcia/smc91c92_cs.c
new file mode 100644
index 00000000000..cffbc0373fa
--- /dev/null
+++ b/drivers/net/pcmcia/smc91c92_cs.c
@@ -0,0 +1,2070 @@
1/*======================================================================
2
3 A PCMCIA ethernet driver for SMC91c92-based cards.
4
5 This driver supports Megahertz PCMCIA ethernet cards; and
6 Megahertz, Motorola, Ositech, and Psion Dacom ethernet/modem
7 multifunction cards.
8
9 Copyright (C) 1999 David A. Hinds -- dahinds@users.sourceforge.net
10
11 smc91c92_cs.c 1.122 2002/10/25 06:26:39
12
13 This driver contains code written by Donald Becker
14 (becker@scyld.com), Rowan Hughes (x-csrdh@jcu.edu.au),
15 David Hinds (dahinds@users.sourceforge.net), and Erik Stahlman
16 (erik@vt.edu). Donald wrote the SMC 91c92 code using parts of
17 Erik's SMC 91c94 driver. Rowan wrote a similar driver, and I've
18 incorporated some parts of his driver here. I (Dave) wrote most
19 of the PCMCIA glue code, and the Ositech support code. Kelly
20 Stephens (kstephen@holli.com) added support for the Motorola
21 Mariner, with help from Allen Brost.
22
23 This software may be used and distributed according to the terms of
24 the GNU General Public License, incorporated herein by reference.
25
26======================================================================*/
27
28#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
29
30#include <linux/module.h>
31#include <linux/kernel.h>
32#include <linux/init.h>
33#include <linux/slab.h>
34#include <linux/string.h>
35#include <linux/timer.h>
36#include <linux/interrupt.h>
37#include <linux/delay.h>
38#include <linux/crc32.h>
39#include <linux/netdevice.h>
40#include <linux/etherdevice.h>
41#include <linux/skbuff.h>
42#include <linux/if_arp.h>
43#include <linux/ioport.h>
44#include <linux/ethtool.h>
45#include <linux/mii.h>
46#include <linux/jiffies.h>
47#include <linux/firmware.h>
48
49#include <pcmcia/cistpl.h>
50#include <pcmcia/cisreg.h>
51#include <pcmcia/ciscode.h>
52#include <pcmcia/ds.h>
53#include <pcmcia/ss.h>
54
55#include <asm/io.h>
56#include <asm/system.h>
57#include <asm/uaccess.h>
58
59/*====================================================================*/
60
61static const char *if_names[] = { "auto", "10baseT", "10base2"};
62
63/* Firmware name */
64#define FIRMWARE_NAME "ositech/Xilinx7OD.bin"
65
66/* Module parameters */
67
68MODULE_DESCRIPTION("SMC 91c92 series PCMCIA ethernet driver");
69MODULE_LICENSE("GPL");
70MODULE_FIRMWARE(FIRMWARE_NAME);
71
72#define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0)
73
74/*
75 Transceiver/media type.
76 0 = auto
77 1 = 10baseT (and autoselect if #define AUTOSELECT),
78 2 = AUI/10base2,
79*/
80INT_MODULE_PARM(if_port, 0);
81
82
83#define DRV_NAME "smc91c92_cs"
84#define DRV_VERSION "1.123"
85
86/*====================================================================*/
87
88/* Operational parameter that usually are not changed. */
89
90/* Time in jiffies before concluding Tx hung */
91#define TX_TIMEOUT ((400*HZ)/1000)
92
93/* Maximum events (Rx packets, etc.) to handle at each interrupt. */
94#define INTR_WORK 4
95
96/* Times to check the check the chip before concluding that it doesn't
97 currently have room for another Tx packet. */
98#define MEMORY_WAIT_TIME 8
99
100struct smc_private {
101 struct pcmcia_device *p_dev;
102 spinlock_t lock;
103 u_short manfid;
104 u_short cardid;
105
106 struct sk_buff *saved_skb;
107 int packets_waiting;
108 void __iomem *base;
109 u_short cfg;
110 struct timer_list media;
111 int watchdog, tx_err;
112 u_short media_status;
113 u_short fast_poll;
114 u_short link_status;
115 struct mii_if_info mii_if;
116 int duplex;
117 int rx_ovrn;
118};
119
120/* Special definitions for Megahertz multifunction cards */
121#define MEGAHERTZ_ISR 0x0380
122
123/* Special function registers for Motorola Mariner */
124#define MOT_LAN 0x0000
125#define MOT_UART 0x0020
126#define MOT_EEPROM 0x20
127
128#define MOT_NORMAL \
129(COR_LEVEL_REQ | COR_FUNC_ENA | COR_ADDR_DECODE | COR_IREQ_ENA)
130
131/* Special function registers for Ositech cards */
132#define OSITECH_AUI_CTL 0x0c
133#define OSITECH_PWRDOWN 0x0d
134#define OSITECH_RESET 0x0e
135#define OSITECH_ISR 0x0f
136#define OSITECH_AUI_PWR 0x0c
137#define OSITECH_RESET_ISR 0x0e
138
139#define OSI_AUI_PWR 0x40
140#define OSI_LAN_PWRDOWN 0x02
141#define OSI_MODEM_PWRDOWN 0x01
142#define OSI_LAN_RESET 0x02
143#define OSI_MODEM_RESET 0x01
144
145/* Symbolic constants for the SMC91c9* series chips, from Erik Stahlman. */
146#define BANK_SELECT 14 /* Window select register. */
147#define SMC_SELECT_BANK(x) { outw(x, ioaddr + BANK_SELECT); }
148
149/* Bank 0 registers. */
150#define TCR 0 /* transmit control register */
151#define TCR_CLEAR 0 /* do NOTHING */
152#define TCR_ENABLE 0x0001 /* if this is 1, we can transmit */
153#define TCR_PAD_EN 0x0080 /* pads short packets to 64 bytes */
154#define TCR_MONCSN 0x0400 /* Monitor Carrier. */
155#define TCR_FDUPLX 0x0800 /* Full duplex mode. */
156#define TCR_NORMAL TCR_ENABLE | TCR_PAD_EN
157
158#define EPH 2 /* Ethernet Protocol Handler report. */
159#define EPH_TX_SUC 0x0001
160#define EPH_SNGLCOL 0x0002
161#define EPH_MULCOL 0x0004
162#define EPH_LTX_MULT 0x0008
163#define EPH_16COL 0x0010
164#define EPH_SQET 0x0020
165#define EPH_LTX_BRD 0x0040
166#define EPH_TX_DEFR 0x0080
167#define EPH_LAT_COL 0x0200
168#define EPH_LOST_CAR 0x0400
169#define EPH_EXC_DEF 0x0800
170#define EPH_CTR_ROL 0x1000
171#define EPH_RX_OVRN 0x2000
172#define EPH_LINK_OK 0x4000
173#define EPH_TX_UNRN 0x8000
174#define MEMINFO 8 /* Memory Information Register */
175#define MEMCFG 10 /* Memory Configuration Register */
176
177/* Bank 1 registers. */
178#define CONFIG 0
179#define CFG_MII_SELECT 0x8000 /* 91C100 only */
180#define CFG_NO_WAIT 0x1000
181#define CFG_FULL_STEP 0x0400
182#define CFG_SET_SQLCH 0x0200
183#define CFG_AUI_SELECT 0x0100
184#define CFG_16BIT 0x0080
185#define CFG_DIS_LINK 0x0040
186#define CFG_STATIC 0x0030
187#define CFG_IRQ_SEL_1 0x0004
188#define CFG_IRQ_SEL_0 0x0002
189#define BASE_ADDR 2
190#define ADDR0 4
191#define GENERAL 10
192#define CONTROL 12
193#define CTL_STORE 0x0001
194#define CTL_RELOAD 0x0002
195#define CTL_EE_SELECT 0x0004
196#define CTL_TE_ENABLE 0x0020
197#define CTL_CR_ENABLE 0x0040
198#define CTL_LE_ENABLE 0x0080
199#define CTL_AUTO_RELEASE 0x0800
200#define CTL_POWERDOWN 0x2000
201
202/* Bank 2 registers. */
203#define MMU_CMD 0
204#define MC_ALLOC 0x20 /* or with number of 256 byte packets */
205#define MC_RESET 0x40
206#define MC_RELEASE 0x80 /* remove and release the current rx packet */
207#define MC_FREEPKT 0xA0 /* Release packet in PNR register */
208#define MC_ENQUEUE 0xC0 /* Enqueue the packet for transmit */
209#define PNR_ARR 2
210#define FIFO_PORTS 4
211#define FP_RXEMPTY 0x8000
212#define POINTER 6
213#define PTR_AUTO_INC 0x0040
214#define PTR_READ 0x2000
215#define PTR_AUTOINC 0x4000
216#define PTR_RCV 0x8000
217#define DATA_1 8
218#define INTERRUPT 12
219#define IM_RCV_INT 0x1
220#define IM_TX_INT 0x2
221#define IM_TX_EMPTY_INT 0x4
222#define IM_ALLOC_INT 0x8
223#define IM_RX_OVRN_INT 0x10
224#define IM_EPH_INT 0x20
225
226#define RCR 4
227enum RxCfg { RxAllMulti = 0x0004, RxPromisc = 0x0002,
228 RxEnable = 0x0100, RxStripCRC = 0x0200};
229#define RCR_SOFTRESET 0x8000 /* resets the chip */
230#define RCR_STRIP_CRC 0x200 /* strips CRC */
231#define RCR_ENABLE 0x100 /* IFF this is set, we can receive packets */
232#define RCR_ALMUL 0x4 /* receive all multicast packets */
233#define RCR_PROMISC 0x2 /* enable promiscuous mode */
234
235/* the normal settings for the RCR register : */
236#define RCR_NORMAL (RCR_STRIP_CRC | RCR_ENABLE)
237#define RCR_CLEAR 0x0 /* set it to a base state */
238#define COUNTER 6
239
240/* BANK 3 -- not the same values as in smc9194! */
241#define MULTICAST0 0
242#define MULTICAST2 2
243#define MULTICAST4 4
244#define MULTICAST6 6
245#define MGMT 8
246#define REVISION 0x0a
247
248/* Transmit status bits. */
249#define TS_SUCCESS 0x0001
250#define TS_16COL 0x0010
251#define TS_LATCOL 0x0200
252#define TS_LOSTCAR 0x0400
253
254/* Receive status bits. */
255#define RS_ALGNERR 0x8000
256#define RS_BADCRC 0x2000
257#define RS_ODDFRAME 0x1000
258#define RS_TOOLONG 0x0800
259#define RS_TOOSHORT 0x0400
260#define RS_MULTICAST 0x0001
261#define RS_ERRORS (RS_ALGNERR | RS_BADCRC | RS_TOOLONG | RS_TOOSHORT)
262
263#define set_bits(v, p) outw(inw(p)|(v), (p))
264#define mask_bits(v, p) outw(inw(p)&(v), (p))
265
266/*====================================================================*/
267
268static void smc91c92_detach(struct pcmcia_device *p_dev);
269static int smc91c92_config(struct pcmcia_device *link);
270static void smc91c92_release(struct pcmcia_device *link);
271
272static int smc_open(struct net_device *dev);
273static int smc_close(struct net_device *dev);
274static int smc_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
275static void smc_tx_timeout(struct net_device *dev);
276static netdev_tx_t smc_start_xmit(struct sk_buff *skb,
277 struct net_device *dev);
278static irqreturn_t smc_interrupt(int irq, void *dev_id);
279static void smc_rx(struct net_device *dev);
280static void set_rx_mode(struct net_device *dev);
281static int s9k_config(struct net_device *dev, struct ifmap *map);
282static void smc_set_xcvr(struct net_device *dev, int if_port);
283static void smc_reset(struct net_device *dev);
284static void media_check(u_long arg);
285static void mdio_sync(unsigned int addr);
286static int mdio_read(struct net_device *dev, int phy_id, int loc);
287static void mdio_write(struct net_device *dev, int phy_id, int loc, int value);
288static int smc_link_ok(struct net_device *dev);
289static const struct ethtool_ops ethtool_ops;
290
291static const struct net_device_ops smc_netdev_ops = {
292 .ndo_open = smc_open,
293 .ndo_stop = smc_close,
294 .ndo_start_xmit = smc_start_xmit,
295 .ndo_tx_timeout = smc_tx_timeout,
296 .ndo_set_config = s9k_config,
297 .ndo_set_multicast_list = set_rx_mode,
298 .ndo_do_ioctl = smc_ioctl,
299 .ndo_change_mtu = eth_change_mtu,
300 .ndo_set_mac_address = eth_mac_addr,
301 .ndo_validate_addr = eth_validate_addr,
302};
303
304static int smc91c92_probe(struct pcmcia_device *link)
305{
306 struct smc_private *smc;
307 struct net_device *dev;
308
309 dev_dbg(&link->dev, "smc91c92_attach()\n");
310
311 /* Create new ethernet device */
312 dev = alloc_etherdev(sizeof(struct smc_private));
313 if (!dev)
314 return -ENOMEM;
315 smc = netdev_priv(dev);
316 smc->p_dev = link;
317 link->priv = dev;
318
319 spin_lock_init(&smc->lock);
320
321 /* The SMC91c92-specific entries in the device structure. */
322 dev->netdev_ops = &smc_netdev_ops;
323 SET_ETHTOOL_OPS(dev, &ethtool_ops);
324 dev->watchdog_timeo = TX_TIMEOUT;
325
326 smc->mii_if.dev = dev;
327 smc->mii_if.mdio_read = mdio_read;
328 smc->mii_if.mdio_write = mdio_write;
329 smc->mii_if.phy_id_mask = 0x1f;
330 smc->mii_if.reg_num_mask = 0x1f;
331
332 return smc91c92_config(link);
333} /* smc91c92_attach */
334
335static void smc91c92_detach(struct pcmcia_device *link)
336{
337 struct net_device *dev = link->priv;
338
339 dev_dbg(&link->dev, "smc91c92_detach\n");
340
341 unregister_netdev(dev);
342
343 smc91c92_release(link);
344
345 free_netdev(dev);
346} /* smc91c92_detach */
347
348/*====================================================================*/
349
350static int cvt_ascii_address(struct net_device *dev, char *s)
351{
352 int i, j, da, c;
353
354 if (strlen(s) != 12)
355 return -1;
356 for (i = 0; i < 6; i++) {
357 da = 0;
358 for (j = 0; j < 2; j++) {
359 c = *s++;
360 da <<= 4;
361 da += ((c >= '0') && (c <= '9')) ?
362 (c - '0') : ((c & 0x0f) + 9);
363 }
364 dev->dev_addr[i] = da;
365 }
366 return 0;
367}
368
369/*====================================================================
370
371 Configuration stuff for Megahertz cards
372
373 mhz_3288_power() is used to power up a 3288's ethernet chip.
374 mhz_mfc_config() handles socket setup for multifunction (1144
375 and 3288) cards. mhz_setup() gets a card's hardware ethernet
376 address.
377
378======================================================================*/
379
380static int mhz_3288_power(struct pcmcia_device *link)
381{
382 struct net_device *dev = link->priv;
383 struct smc_private *smc = netdev_priv(dev);
384 u_char tmp;
385
386 /* Read the ISR twice... */
387 readb(smc->base+MEGAHERTZ_ISR);
388 udelay(5);
389 readb(smc->base+MEGAHERTZ_ISR);
390
391 /* Pause 200ms... */
392 mdelay(200);
393
394 /* Now read and write the COR... */
395 tmp = readb(smc->base + link->config_base + CISREG_COR);
396 udelay(5);
397 writeb(tmp, smc->base + link->config_base + CISREG_COR);
398
399 return 0;
400}
401
402static int mhz_mfc_config_check(struct pcmcia_device *p_dev, void *priv_data)
403{
404 int k;
405 p_dev->io_lines = 16;
406 p_dev->resource[1]->start = p_dev->resource[0]->start;
407 p_dev->resource[1]->end = 8;
408 p_dev->resource[1]->flags &= ~IO_DATA_PATH_WIDTH;
409 p_dev->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
410 p_dev->resource[0]->end = 16;
411 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
412 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
413 for (k = 0; k < 0x400; k += 0x10) {
414 if (k & 0x80)
415 continue;
416 p_dev->resource[0]->start = k ^ 0x300;
417 if (!pcmcia_request_io(p_dev))
418 return 0;
419 }
420 return -ENODEV;
421}
422
423static int mhz_mfc_config(struct pcmcia_device *link)
424{
425 struct net_device *dev = link->priv;
426 struct smc_private *smc = netdev_priv(dev);
427 unsigned int offset;
428 int i;
429
430 link->config_flags |= CONF_ENABLE_SPKR | CONF_ENABLE_IRQ |
431 CONF_AUTO_SET_IO;
432
433 /* The Megahertz combo cards have modem-like CIS entries, so
434 we have to explicitly try a bunch of port combinations. */
435 if (pcmcia_loop_config(link, mhz_mfc_config_check, NULL))
436 return -ENODEV;
437
438 dev->base_addr = link->resource[0]->start;
439
440 /* Allocate a memory window, for accessing the ISR */
441 link->resource[2]->flags = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
442 link->resource[2]->start = link->resource[2]->end = 0;
443 i = pcmcia_request_window(link, link->resource[2], 0);
444 if (i != 0)
445 return -ENODEV;
446
447 smc->base = ioremap(link->resource[2]->start,
448 resource_size(link->resource[2]));
449 offset = (smc->manfid == MANFID_MOTOROLA) ? link->config_base : 0;
450 i = pcmcia_map_mem_page(link, link->resource[2], offset);
451 if ((i == 0) &&
452 (smc->manfid == MANFID_MEGAHERTZ) &&
453 (smc->cardid == PRODID_MEGAHERTZ_EM3288))
454 mhz_3288_power(link);
455
456 return 0;
457}
458
459static int pcmcia_get_versmac(struct pcmcia_device *p_dev,
460 tuple_t *tuple,
461 void *priv)
462{
463 struct net_device *dev = priv;
464 cisparse_t parse;
465 u8 *buf;
466
467 if (pcmcia_parse_tuple(tuple, &parse))
468 return -EINVAL;
469
470 buf = parse.version_1.str + parse.version_1.ofs[3];
471
472 if ((parse.version_1.ns > 3) && (cvt_ascii_address(dev, buf) == 0))
473 return 0;
474
475 return -EINVAL;
476};
477
478static int mhz_setup(struct pcmcia_device *link)
479{
480 struct net_device *dev = link->priv;
481 size_t len;
482 u8 *buf;
483 int rc;
484
485 /* Read the station address from the CIS. It is stored as the last
486 (fourth) string in the Version 1 Version/ID tuple. */
487 if ((link->prod_id[3]) &&
488 (cvt_ascii_address(dev, link->prod_id[3]) == 0))
489 return 0;
490
491 /* Workarounds for broken cards start here. */
492 /* Ugh -- the EM1144 card has two VERS_1 tuples!?! */
493 if (!pcmcia_loop_tuple(link, CISTPL_VERS_1, pcmcia_get_versmac, dev))
494 return 0;
495
496 /* Another possibility: for the EM3288, in a special tuple */
497 rc = -1;
498 len = pcmcia_get_tuple(link, 0x81, &buf);
499 if (buf && len >= 13) {
500 buf[12] = '\0';
501 if (cvt_ascii_address(dev, buf) == 0)
502 rc = 0;
503 }
504 kfree(buf);
505
506 return rc;
507};
508
509/*======================================================================
510
511 Configuration stuff for the Motorola Mariner
512
513 mot_config() writes directly to the Mariner configuration
514 registers because the CIS is just bogus.
515
516======================================================================*/
517
518static void mot_config(struct pcmcia_device *link)
519{
520 struct net_device *dev = link->priv;
521 struct smc_private *smc = netdev_priv(dev);
522 unsigned int ioaddr = dev->base_addr;
523 unsigned int iouart = link->resource[1]->start;
524
525 /* Set UART base address and force map with COR bit 1 */
526 writeb(iouart & 0xff, smc->base + MOT_UART + CISREG_IOBASE_0);
527 writeb((iouart >> 8) & 0xff, smc->base + MOT_UART + CISREG_IOBASE_1);
528 writeb(MOT_NORMAL, smc->base + MOT_UART + CISREG_COR);
529
530 /* Set SMC base address and force map with COR bit 1 */
531 writeb(ioaddr & 0xff, smc->base + MOT_LAN + CISREG_IOBASE_0);
532 writeb((ioaddr >> 8) & 0xff, smc->base + MOT_LAN + CISREG_IOBASE_1);
533 writeb(MOT_NORMAL, smc->base + MOT_LAN + CISREG_COR);
534
535 /* Wait for things to settle down */
536 mdelay(100);
537}
538
539static int mot_setup(struct pcmcia_device *link)
540{
541 struct net_device *dev = link->priv;
542 unsigned int ioaddr = dev->base_addr;
543 int i, wait, loop;
544 u_int addr;
545
546 /* Read Ethernet address from Serial EEPROM */
547
548 for (i = 0; i < 3; i++) {
549 SMC_SELECT_BANK(2);
550 outw(MOT_EEPROM + i, ioaddr + POINTER);
551 SMC_SELECT_BANK(1);
552 outw((CTL_RELOAD | CTL_EE_SELECT), ioaddr + CONTROL);
553
554 for (loop = wait = 0; loop < 200; loop++) {
555 udelay(10);
556 wait = ((CTL_RELOAD | CTL_STORE) & inw(ioaddr + CONTROL));
557 if (wait == 0) break;
558 }
559
560 if (wait)
561 return -1;
562
563 addr = inw(ioaddr + GENERAL);
564 dev->dev_addr[2*i] = addr & 0xff;
565 dev->dev_addr[2*i+1] = (addr >> 8) & 0xff;
566 }
567
568 return 0;
569}
570
571/*====================================================================*/
572
573static int smc_configcheck(struct pcmcia_device *p_dev, void *priv_data)
574{
575 p_dev->resource[0]->end = 16;
576 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
577 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
578
579 return pcmcia_request_io(p_dev);
580}
581
582static int smc_config(struct pcmcia_device *link)
583{
584 struct net_device *dev = link->priv;
585 int i;
586
587 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
588
589 i = pcmcia_loop_config(link, smc_configcheck, NULL);
590 if (!i)
591 dev->base_addr = link->resource[0]->start;
592
593 return i;
594}
595
596
597static int smc_setup(struct pcmcia_device *link)
598{
599 struct net_device *dev = link->priv;
600
601 /* Check for a LAN function extension tuple */
602 if (!pcmcia_get_mac_from_cis(link, dev))
603 return 0;
604
605 /* Try the third string in the Version 1 Version/ID tuple. */
606 if (link->prod_id[2]) {
607 if (cvt_ascii_address(dev, link->prod_id[2]) == 0)
608 return 0;
609 }
610 return -1;
611}
612
613/*====================================================================*/
614
615static int osi_config(struct pcmcia_device *link)
616{
617 struct net_device *dev = link->priv;
618 static const unsigned int com[4] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
619 int i, j;
620
621 link->config_flags |= CONF_ENABLE_SPKR | CONF_ENABLE_IRQ;
622 link->resource[0]->end = 64;
623 link->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
624 link->resource[1]->end = 8;
625
626 /* Enable Hard Decode, LAN, Modem */
627 link->io_lines = 16;
628 link->config_index = 0x23;
629
630 for (i = j = 0; j < 4; j++) {
631 link->resource[1]->start = com[j];
632 i = pcmcia_request_io(link);
633 if (i == 0)
634 break;
635 }
636 if (i != 0) {
637 /* Fallback: turn off hard decode */
638 link->config_index = 0x03;
639 link->resource[1]->end = 0;
640 i = pcmcia_request_io(link);
641 }
642 dev->base_addr = link->resource[0]->start + 0x10;
643 return i;
644}
645
646static int osi_load_firmware(struct pcmcia_device *link)
647{
648 const struct firmware *fw;
649 int i, err;
650
651 err = request_firmware(&fw, FIRMWARE_NAME, &link->dev);
652 if (err) {
653 pr_err("Failed to load firmware \"%s\"\n", FIRMWARE_NAME);
654 return err;
655 }
656
657 /* Download the Seven of Diamonds firmware */
658 for (i = 0; i < fw->size; i++) {
659 outb(fw->data[i], link->resource[0]->start + 2);
660 udelay(50);
661 }
662 release_firmware(fw);
663 return err;
664}
665
666static int pcmcia_osi_mac(struct pcmcia_device *p_dev,
667 tuple_t *tuple,
668 void *priv)
669{
670 struct net_device *dev = priv;
671 int i;
672
673 if (tuple->TupleDataLen < 8)
674 return -EINVAL;
675 if (tuple->TupleData[0] != 0x04)
676 return -EINVAL;
677 for (i = 0; i < 6; i++)
678 dev->dev_addr[i] = tuple->TupleData[i+2];
679 return 0;
680};
681
682
683static int osi_setup(struct pcmcia_device *link, u_short manfid, u_short cardid)
684{
685 struct net_device *dev = link->priv;
686 int rc;
687
688 /* Read the station address from tuple 0x90, subtuple 0x04 */
689 if (pcmcia_loop_tuple(link, 0x90, pcmcia_osi_mac, dev))
690 return -1;
691
692 if (((manfid == MANFID_OSITECH) &&
693 (cardid == PRODID_OSITECH_SEVEN)) ||
694 ((manfid == MANFID_PSION) &&
695 (cardid == PRODID_PSION_NET100))) {
696 rc = osi_load_firmware(link);
697 if (rc)
698 return rc;
699 } else if (manfid == MANFID_OSITECH) {
700 /* Make sure both functions are powered up */
701 set_bits(0x300, link->resource[0]->start + OSITECH_AUI_PWR);
702 /* Now, turn on the interrupt for both card functions */
703 set_bits(0x300, link->resource[0]->start + OSITECH_RESET_ISR);
704 dev_dbg(&link->dev, "AUI/PWR: %4.4x RESET/ISR: %4.4x\n",
705 inw(link->resource[0]->start + OSITECH_AUI_PWR),
706 inw(link->resource[0]->start + OSITECH_RESET_ISR));
707 }
708 return 0;
709}
710
711static int smc91c92_suspend(struct pcmcia_device *link)
712{
713 struct net_device *dev = link->priv;
714
715 if (link->open)
716 netif_device_detach(dev);
717
718 return 0;
719}
720
721static int smc91c92_resume(struct pcmcia_device *link)
722{
723 struct net_device *dev = link->priv;
724 struct smc_private *smc = netdev_priv(dev);
725 int i;
726
727 if ((smc->manfid == MANFID_MEGAHERTZ) &&
728 (smc->cardid == PRODID_MEGAHERTZ_EM3288))
729 mhz_3288_power(link);
730 if (smc->manfid == MANFID_MOTOROLA)
731 mot_config(link);
732 if ((smc->manfid == MANFID_OSITECH) &&
733 (smc->cardid != PRODID_OSITECH_SEVEN)) {
734 /* Power up the card and enable interrupts */
735 set_bits(0x0300, dev->base_addr-0x10+OSITECH_AUI_PWR);
736 set_bits(0x0300, dev->base_addr-0x10+OSITECH_RESET_ISR);
737 }
738 if (((smc->manfid == MANFID_OSITECH) &&
739 (smc->cardid == PRODID_OSITECH_SEVEN)) ||
740 ((smc->manfid == MANFID_PSION) &&
741 (smc->cardid == PRODID_PSION_NET100))) {
742 i = osi_load_firmware(link);
743 if (i) {
744 pr_err("smc91c92_cs: Failed to load firmware\n");
745 return i;
746 }
747 }
748 if (link->open) {
749 smc_reset(dev);
750 netif_device_attach(dev);
751 }
752
753 return 0;
754}
755
756
757/*======================================================================
758
759 This verifies that the chip is some SMC91cXX variant, and returns
760 the revision code if successful. Otherwise, it returns -ENODEV.
761
762======================================================================*/
763
764static int check_sig(struct pcmcia_device *link)
765{
766 struct net_device *dev = link->priv;
767 unsigned int ioaddr = dev->base_addr;
768 int width;
769 u_short s;
770
771 SMC_SELECT_BANK(1);
772 if (inw(ioaddr + BANK_SELECT) >> 8 != 0x33) {
773 /* Try powering up the chip */
774 outw(0, ioaddr + CONTROL);
775 mdelay(55);
776 }
777
778 /* Try setting bus width */
779 width = (link->resource[0]->flags == IO_DATA_PATH_WIDTH_AUTO);
780 s = inb(ioaddr + CONFIG);
781 if (width)
782 s |= CFG_16BIT;
783 else
784 s &= ~CFG_16BIT;
785 outb(s, ioaddr + CONFIG);
786
787 /* Check Base Address Register to make sure bus width is OK */
788 s = inw(ioaddr + BASE_ADDR);
789 if ((inw(ioaddr + BANK_SELECT) >> 8 == 0x33) &&
790 ((s >> 8) != (s & 0xff))) {
791 SMC_SELECT_BANK(3);
792 s = inw(ioaddr + REVISION);
793 return s & 0xff;
794 }
795
796 if (width) {
797 pr_info("using 8-bit IO window\n");
798
799 smc91c92_suspend(link);
800 pcmcia_fixup_iowidth(link);
801 smc91c92_resume(link);
802 return check_sig(link);
803 }
804 return -ENODEV;
805}
806
807static int smc91c92_config(struct pcmcia_device *link)
808{
809 struct net_device *dev = link->priv;
810 struct smc_private *smc = netdev_priv(dev);
811 char *name;
812 int i, rev, j = 0;
813 unsigned int ioaddr;
814 u_long mir;
815
816 dev_dbg(&link->dev, "smc91c92_config\n");
817
818 smc->manfid = link->manf_id;
819 smc->cardid = link->card_id;
820
821 if ((smc->manfid == MANFID_OSITECH) &&
822 (smc->cardid != PRODID_OSITECH_SEVEN)) {
823 i = osi_config(link);
824 } else if ((smc->manfid == MANFID_MOTOROLA) ||
825 ((smc->manfid == MANFID_MEGAHERTZ) &&
826 ((smc->cardid == PRODID_MEGAHERTZ_VARIOUS) ||
827 (smc->cardid == PRODID_MEGAHERTZ_EM3288)))) {
828 i = mhz_mfc_config(link);
829 } else {
830 i = smc_config(link);
831 }
832 if (i)
833 goto config_failed;
834
835 i = pcmcia_request_irq(link, smc_interrupt);
836 if (i)
837 goto config_failed;
838 i = pcmcia_enable_device(link);
839 if (i)
840 goto config_failed;
841
842 if (smc->manfid == MANFID_MOTOROLA)
843 mot_config(link);
844
845 dev->irq = link->irq;
846
847 if ((if_port >= 0) && (if_port <= 2))
848 dev->if_port = if_port;
849 else
850 dev_notice(&link->dev, "invalid if_port requested\n");
851
852 switch (smc->manfid) {
853 case MANFID_OSITECH:
854 case MANFID_PSION:
855 i = osi_setup(link, smc->manfid, smc->cardid); break;
856 case MANFID_SMC:
857 case MANFID_NEW_MEDIA:
858 i = smc_setup(link); break;
859 case 0x128: /* For broken Megahertz cards */
860 case MANFID_MEGAHERTZ:
861 i = mhz_setup(link); break;
862 case MANFID_MOTOROLA:
863 default: /* get the hw address from EEPROM */
864 i = mot_setup(link); break;
865 }
866
867 if (i != 0) {
868 dev_notice(&link->dev, "Unable to find hardware address.\n");
869 goto config_failed;
870 }
871
872 smc->duplex = 0;
873 smc->rx_ovrn = 0;
874
875 rev = check_sig(link);
876 name = "???";
877 if (rev > 0)
878 switch (rev >> 4) {
879 case 3: name = "92"; break;
880 case 4: name = ((rev & 15) >= 6) ? "96" : "94"; break;
881 case 5: name = "95"; break;
882 case 7: name = "100"; break;
883 case 8: name = "100-FD"; break;
884 case 9: name = "110"; break;
885 }
886
887 ioaddr = dev->base_addr;
888 if (rev > 0) {
889 u_long mcr;
890 SMC_SELECT_BANK(0);
891 mir = inw(ioaddr + MEMINFO) & 0xff;
892 if (mir == 0xff) mir++;
893 /* Get scale factor for memory size */
894 mcr = ((rev >> 4) > 3) ? inw(ioaddr + MEMCFG) : 0x0200;
895 mir *= 128 * (1<<((mcr >> 9) & 7));
896 SMC_SELECT_BANK(1);
897 smc->cfg = inw(ioaddr + CONFIG) & ~CFG_AUI_SELECT;
898 smc->cfg |= CFG_NO_WAIT | CFG_16BIT | CFG_STATIC;
899 if (smc->manfid == MANFID_OSITECH)
900 smc->cfg |= CFG_IRQ_SEL_1 | CFG_IRQ_SEL_0;
901 if ((rev >> 4) >= 7)
902 smc->cfg |= CFG_MII_SELECT;
903 } else
904 mir = 0;
905
906 if (smc->cfg & CFG_MII_SELECT) {
907 SMC_SELECT_BANK(3);
908
909 for (i = 0; i < 32; i++) {
910 j = mdio_read(dev, i, 1);
911 if ((j != 0) && (j != 0xffff)) break;
912 }
913 smc->mii_if.phy_id = (i < 32) ? i : -1;
914
915 SMC_SELECT_BANK(0);
916 }
917
918 SET_NETDEV_DEV(dev, &link->dev);
919
920 if (register_netdev(dev) != 0) {
921 dev_err(&link->dev, "register_netdev() failed\n");
922 goto config_undo;
923 }
924
925 netdev_info(dev, "smc91c%s rev %d: io %#3lx, irq %d, hw_addr %pM\n",
926 name, (rev & 0x0f), dev->base_addr, dev->irq, dev->dev_addr);
927
928 if (rev > 0) {
929 if (mir & 0x3ff)
930 netdev_info(dev, " %lu byte", mir);
931 else
932 netdev_info(dev, " %lu kb", mir>>10);
933 pr_cont(" buffer, %s xcvr\n",
934 (smc->cfg & CFG_MII_SELECT) ? "MII" : if_names[dev->if_port]);
935 }
936
937 if (smc->cfg & CFG_MII_SELECT) {
938 if (smc->mii_if.phy_id != -1) {
939 netdev_dbg(dev, " MII transceiver at index %d, status %x\n",
940 smc->mii_if.phy_id, j);
941 } else {
942 netdev_notice(dev, " No MII transceivers found!\n");
943 }
944 }
945 return 0;
946
947config_undo:
948 unregister_netdev(dev);
949config_failed:
950 smc91c92_release(link);
951 free_netdev(dev);
952 return -ENODEV;
953} /* smc91c92_config */
954
955static void smc91c92_release(struct pcmcia_device *link)
956{
957 dev_dbg(&link->dev, "smc91c92_release\n");
958 if (link->resource[2]->end) {
959 struct net_device *dev = link->priv;
960 struct smc_private *smc = netdev_priv(dev);
961 iounmap(smc->base);
962 }
963 pcmcia_disable_device(link);
964}
965
966/*======================================================================
967
968 MII interface support for SMC91cXX based cards
969======================================================================*/
970
971#define MDIO_SHIFT_CLK 0x04
972#define MDIO_DATA_OUT 0x01
973#define MDIO_DIR_WRITE 0x08
974#define MDIO_DATA_WRITE0 (MDIO_DIR_WRITE)
975#define MDIO_DATA_WRITE1 (MDIO_DIR_WRITE | MDIO_DATA_OUT)
976#define MDIO_DATA_READ 0x02
977
978static void mdio_sync(unsigned int addr)
979{
980 int bits;
981 for (bits = 0; bits < 32; bits++) {
982 outb(MDIO_DATA_WRITE1, addr);
983 outb(MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, addr);
984 }
985}
986
987static int mdio_read(struct net_device *dev, int phy_id, int loc)
988{
989 unsigned int addr = dev->base_addr + MGMT;
990 u_int cmd = (0x06<<10)|(phy_id<<5)|loc;
991 int i, retval = 0;
992
993 mdio_sync(addr);
994 for (i = 13; i >= 0; i--) {
995 int dat = (cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
996 outb(dat, addr);
997 outb(dat | MDIO_SHIFT_CLK, addr);
998 }
999 for (i = 19; i > 0; i--) {
1000 outb(0, addr);
1001 retval = (retval << 1) | ((inb(addr) & MDIO_DATA_READ) != 0);
1002 outb(MDIO_SHIFT_CLK, addr);
1003 }
1004 return (retval>>1) & 0xffff;
1005}
1006
1007static void mdio_write(struct net_device *dev, int phy_id, int loc, int value)
1008{
1009 unsigned int addr = dev->base_addr + MGMT;
1010 u_int cmd = (0x05<<28)|(phy_id<<23)|(loc<<18)|(1<<17)|value;
1011 int i;
1012
1013 mdio_sync(addr);
1014 for (i = 31; i >= 0; i--) {
1015 int dat = (cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
1016 outb(dat, addr);
1017 outb(dat | MDIO_SHIFT_CLK, addr);
1018 }
1019 for (i = 1; i >= 0; i--) {
1020 outb(0, addr);
1021 outb(MDIO_SHIFT_CLK, addr);
1022 }
1023}
1024
1025/*======================================================================
1026
1027 The driver core code, most of which should be common with a
1028 non-PCMCIA implementation.
1029
1030======================================================================*/
1031
1032#ifdef PCMCIA_DEBUG
1033static void smc_dump(struct net_device *dev)
1034{
1035 unsigned int ioaddr = dev->base_addr;
1036 u_short i, w, save;
1037 save = inw(ioaddr + BANK_SELECT);
1038 for (w = 0; w < 4; w++) {
1039 SMC_SELECT_BANK(w);
1040 netdev_printk(KERN_DEBUG, dev, "bank %d: ", w);
1041 for (i = 0; i < 14; i += 2)
1042 pr_cont(" %04x", inw(ioaddr + i));
1043 pr_cont("\n");
1044 }
1045 outw(save, ioaddr + BANK_SELECT);
1046}
1047#endif
1048
1049static int smc_open(struct net_device *dev)
1050{
1051 struct smc_private *smc = netdev_priv(dev);
1052 struct pcmcia_device *link = smc->p_dev;
1053
1054 dev_dbg(&link->dev, "%s: smc_open(%p), ID/Window %4.4x.\n",
1055 dev->name, dev, inw(dev->base_addr + BANK_SELECT));
1056#ifdef PCMCIA_DEBUG
1057 smc_dump(dev);
1058#endif
1059
1060 /* Check that the PCMCIA card is still here. */
1061 if (!pcmcia_dev_present(link))
1062 return -ENODEV;
1063 /* Physical device present signature. */
1064 if (check_sig(link) < 0) {
1065 netdev_info(dev, "Yikes! Bad chip signature!\n");
1066 return -ENODEV;
1067 }
1068 link->open++;
1069
1070 netif_start_queue(dev);
1071 smc->saved_skb = NULL;
1072 smc->packets_waiting = 0;
1073
1074 smc_reset(dev);
1075 init_timer(&smc->media);
1076 smc->media.function = media_check;
1077 smc->media.data = (u_long) dev;
1078 smc->media.expires = jiffies + HZ;
1079 add_timer(&smc->media);
1080
1081 return 0;
1082} /* smc_open */
1083
1084/*====================================================================*/
1085
1086static int smc_close(struct net_device *dev)
1087{
1088 struct smc_private *smc = netdev_priv(dev);
1089 struct pcmcia_device *link = smc->p_dev;
1090 unsigned int ioaddr = dev->base_addr;
1091
1092 dev_dbg(&link->dev, "%s: smc_close(), status %4.4x.\n",
1093 dev->name, inw(ioaddr + BANK_SELECT));
1094
1095 netif_stop_queue(dev);
1096
1097 /* Shut off all interrupts, and turn off the Tx and Rx sections.
1098 Don't bother to check for chip present. */
1099 SMC_SELECT_BANK(2); /* Nominally paranoia, but do no assume... */
1100 outw(0, ioaddr + INTERRUPT);
1101 SMC_SELECT_BANK(0);
1102 mask_bits(0xff00, ioaddr + RCR);
1103 mask_bits(0xff00, ioaddr + TCR);
1104
1105 /* Put the chip into power-down mode. */
1106 SMC_SELECT_BANK(1);
1107 outw(CTL_POWERDOWN, ioaddr + CONTROL );
1108
1109 link->open--;
1110 del_timer_sync(&smc->media);
1111
1112 return 0;
1113} /* smc_close */
1114
1115/*======================================================================
1116
1117 Transfer a packet to the hardware and trigger the packet send.
1118 This may be called at either from either the Tx queue code
1119 or the interrupt handler.
1120
1121======================================================================*/
1122
1123static void smc_hardware_send_packet(struct net_device * dev)
1124{
1125 struct smc_private *smc = netdev_priv(dev);
1126 struct sk_buff *skb = smc->saved_skb;
1127 unsigned int ioaddr = dev->base_addr;
1128 u_char packet_no;
1129
1130 if (!skb) {
1131 netdev_err(dev, "In XMIT with no packet to send\n");
1132 return;
1133 }
1134
1135 /* There should be a packet slot waiting. */
1136 packet_no = inw(ioaddr + PNR_ARR) >> 8;
1137 if (packet_no & 0x80) {
1138 /* If not, there is a hardware problem! Likely an ejected card. */
1139 netdev_warn(dev, "hardware Tx buffer allocation failed, status %#2.2x\n",
1140 packet_no);
1141 dev_kfree_skb_irq(skb);
1142 smc->saved_skb = NULL;
1143 netif_start_queue(dev);
1144 return;
1145 }
1146
1147 dev->stats.tx_bytes += skb->len;
1148 /* The card should use the just-allocated buffer. */
1149 outw(packet_no, ioaddr + PNR_ARR);
1150 /* point to the beginning of the packet */
1151 outw(PTR_AUTOINC , ioaddr + POINTER);
1152
1153 /* Send the packet length (+6 for status, length and ctl byte)
1154 and the status word (set to zeros). */
1155 {
1156 u_char *buf = skb->data;
1157 u_int length = skb->len; /* The chip will pad to ethernet min. */
1158
1159 netdev_dbg(dev, "Trying to xmit packet of length %d\n", length);
1160
1161 /* send the packet length: +6 for status word, length, and ctl */
1162 outw(0, ioaddr + DATA_1);
1163 outw(length + 6, ioaddr + DATA_1);
1164 outsw(ioaddr + DATA_1, buf, length >> 1);
1165
1166 /* The odd last byte, if there is one, goes in the control word. */
1167 outw((length & 1) ? 0x2000 | buf[length-1] : 0, ioaddr + DATA_1);
1168 }
1169
1170 /* Enable the Tx interrupts, both Tx (TxErr) and TxEmpty. */
1171 outw(((IM_TX_INT|IM_TX_EMPTY_INT)<<8) |
1172 (inw(ioaddr + INTERRUPT) & 0xff00),
1173 ioaddr + INTERRUPT);
1174
1175 /* The chip does the rest of the work. */
1176 outw(MC_ENQUEUE , ioaddr + MMU_CMD);
1177
1178 smc->saved_skb = NULL;
1179 dev_kfree_skb_irq(skb);
1180 dev->trans_start = jiffies;
1181 netif_start_queue(dev);
1182}
1183
1184/*====================================================================*/
1185
1186static void smc_tx_timeout(struct net_device *dev)
1187{
1188 struct smc_private *smc = netdev_priv(dev);
1189 unsigned int ioaddr = dev->base_addr;
1190
1191 netdev_notice(dev, "transmit timed out, Tx_status %2.2x status %4.4x.\n",
1192 inw(ioaddr)&0xff, inw(ioaddr + 2));
1193 dev->stats.tx_errors++;
1194 smc_reset(dev);
1195 dev->trans_start = jiffies; /* prevent tx timeout */
1196 smc->saved_skb = NULL;
1197 netif_wake_queue(dev);
1198}
1199
1200static netdev_tx_t smc_start_xmit(struct sk_buff *skb,
1201 struct net_device *dev)
1202{
1203 struct smc_private *smc = netdev_priv(dev);
1204 unsigned int ioaddr = dev->base_addr;
1205 u_short num_pages;
1206 short time_out, ir;
1207 unsigned long flags;
1208
1209 netif_stop_queue(dev);
1210
1211 netdev_dbg(dev, "smc_start_xmit(length = %d) called, status %04x\n",
1212 skb->len, inw(ioaddr + 2));
1213
1214 if (smc->saved_skb) {
1215 /* THIS SHOULD NEVER HAPPEN. */
1216 dev->stats.tx_aborted_errors++;
1217 netdev_printk(KERN_DEBUG, dev,
1218 "Internal error -- sent packet while busy\n");
1219 return NETDEV_TX_BUSY;
1220 }
1221 smc->saved_skb = skb;
1222
1223 num_pages = skb->len >> 8;
1224
1225 if (num_pages > 7) {
1226 netdev_err(dev, "Far too big packet error: %d pages\n", num_pages);
1227 dev_kfree_skb (skb);
1228 smc->saved_skb = NULL;
1229 dev->stats.tx_dropped++;
1230 return NETDEV_TX_OK; /* Do not re-queue this packet. */
1231 }
1232 /* A packet is now waiting. */
1233 smc->packets_waiting++;
1234
1235 spin_lock_irqsave(&smc->lock, flags);
1236 SMC_SELECT_BANK(2); /* Paranoia, we should always be in window 2 */
1237
1238 /* need MC_RESET to keep the memory consistent. errata? */
1239 if (smc->rx_ovrn) {
1240 outw(MC_RESET, ioaddr + MMU_CMD);
1241 smc->rx_ovrn = 0;
1242 }
1243
1244 /* Allocate the memory; send the packet now if we win. */
1245 outw(MC_ALLOC | num_pages, ioaddr + MMU_CMD);
1246 for (time_out = MEMORY_WAIT_TIME; time_out >= 0; time_out--) {
1247 ir = inw(ioaddr+INTERRUPT);
1248 if (ir & IM_ALLOC_INT) {
1249 /* Acknowledge the interrupt, send the packet. */
1250 outw((ir&0xff00) | IM_ALLOC_INT, ioaddr + INTERRUPT);
1251 smc_hardware_send_packet(dev); /* Send the packet now.. */
1252 spin_unlock_irqrestore(&smc->lock, flags);
1253 return NETDEV_TX_OK;
1254 }
1255 }
1256
1257 /* Otherwise defer until the Tx-space-allocated interrupt. */
1258 pr_debug("%s: memory allocation deferred.\n", dev->name);
1259 outw((IM_ALLOC_INT << 8) | (ir & 0xff00), ioaddr + INTERRUPT);
1260 spin_unlock_irqrestore(&smc->lock, flags);
1261
1262 return NETDEV_TX_OK;
1263}
1264
1265/*======================================================================
1266
1267 Handle a Tx anomalous event. Entered while in Window 2.
1268
1269======================================================================*/
1270
1271static void smc_tx_err(struct net_device * dev)
1272{
1273 struct smc_private *smc = netdev_priv(dev);
1274 unsigned int ioaddr = dev->base_addr;
1275 int saved_packet = inw(ioaddr + PNR_ARR) & 0xff;
1276 int packet_no = inw(ioaddr + FIFO_PORTS) & 0x7f;
1277 int tx_status;
1278
1279 /* select this as the packet to read from */
1280 outw(packet_no, ioaddr + PNR_ARR);
1281
1282 /* read the first word from this packet */
1283 outw(PTR_AUTOINC | PTR_READ | 0, ioaddr + POINTER);
1284
1285 tx_status = inw(ioaddr + DATA_1);
1286
1287 dev->stats.tx_errors++;
1288 if (tx_status & TS_LOSTCAR) dev->stats.tx_carrier_errors++;
1289 if (tx_status & TS_LATCOL) dev->stats.tx_window_errors++;
1290 if (tx_status & TS_16COL) {
1291 dev->stats.tx_aborted_errors++;
1292 smc->tx_err++;
1293 }
1294
1295 if (tx_status & TS_SUCCESS) {
1296 netdev_notice(dev, "Successful packet caused error interrupt?\n");
1297 }
1298 /* re-enable transmit */
1299 SMC_SELECT_BANK(0);
1300 outw(inw(ioaddr + TCR) | TCR_ENABLE | smc->duplex, ioaddr + TCR);
1301 SMC_SELECT_BANK(2);
1302
1303 outw(MC_FREEPKT, ioaddr + MMU_CMD); /* Free the packet memory. */
1304
1305 /* one less packet waiting for me */
1306 smc->packets_waiting--;
1307
1308 outw(saved_packet, ioaddr + PNR_ARR);
1309}
1310
1311/*====================================================================*/
1312
1313static void smc_eph_irq(struct net_device *dev)
1314{
1315 struct smc_private *smc = netdev_priv(dev);
1316 unsigned int ioaddr = dev->base_addr;
1317 u_short card_stats, ephs;
1318
1319 SMC_SELECT_BANK(0);
1320 ephs = inw(ioaddr + EPH);
1321 pr_debug("%s: Ethernet protocol handler interrupt, status"
1322 " %4.4x.\n", dev->name, ephs);
1323 /* Could be a counter roll-over warning: update stats. */
1324 card_stats = inw(ioaddr + COUNTER);
1325 /* single collisions */
1326 dev->stats.collisions += card_stats & 0xF;
1327 card_stats >>= 4;
1328 /* multiple collisions */
1329 dev->stats.collisions += card_stats & 0xF;
1330#if 0 /* These are for when linux supports these statistics */
1331 card_stats >>= 4; /* deferred */
1332 card_stats >>= 4; /* excess deferred */
1333#endif
1334 /* If we had a transmit error we must re-enable the transmitter. */
1335 outw(inw(ioaddr + TCR) | TCR_ENABLE | smc->duplex, ioaddr + TCR);
1336
1337 /* Clear a link error interrupt. */
1338 SMC_SELECT_BANK(1);
1339 outw(CTL_AUTO_RELEASE | 0x0000, ioaddr + CONTROL);
1340 outw(CTL_AUTO_RELEASE | CTL_TE_ENABLE | CTL_CR_ENABLE,
1341 ioaddr + CONTROL);
1342 SMC_SELECT_BANK(2);
1343}
1344
1345/*====================================================================*/
1346
1347static irqreturn_t smc_interrupt(int irq, void *dev_id)
1348{
1349 struct net_device *dev = dev_id;
1350 struct smc_private *smc = netdev_priv(dev);
1351 unsigned int ioaddr;
1352 u_short saved_bank, saved_pointer, mask, status;
1353 unsigned int handled = 1;
1354 char bogus_cnt = INTR_WORK; /* Work we are willing to do. */
1355
1356 if (!netif_device_present(dev))
1357 return IRQ_NONE;
1358
1359 ioaddr = dev->base_addr;
1360
1361 pr_debug("%s: SMC91c92 interrupt %d at %#x.\n", dev->name,
1362 irq, ioaddr);
1363
1364 spin_lock(&smc->lock);
1365 smc->watchdog = 0;
1366 saved_bank = inw(ioaddr + BANK_SELECT);
1367 if ((saved_bank & 0xff00) != 0x3300) {
1368 /* The device does not exist -- the card could be off-line, or
1369 maybe it has been ejected. */
1370 pr_debug("%s: SMC91c92 interrupt %d for non-existent"
1371 "/ejected device.\n", dev->name, irq);
1372 handled = 0;
1373 goto irq_done;
1374 }
1375
1376 SMC_SELECT_BANK(2);
1377 saved_pointer = inw(ioaddr + POINTER);
1378 mask = inw(ioaddr + INTERRUPT) >> 8;
1379 /* clear all interrupts */
1380 outw(0, ioaddr + INTERRUPT);
1381
1382 do { /* read the status flag, and mask it */
1383 status = inw(ioaddr + INTERRUPT) & 0xff;
1384 pr_debug("%s: Status is %#2.2x (mask %#2.2x).\n", dev->name,
1385 status, mask);
1386 if ((status & mask) == 0) {
1387 if (bogus_cnt == INTR_WORK)
1388 handled = 0;
1389 break;
1390 }
1391 if (status & IM_RCV_INT) {
1392 /* Got a packet(s). */
1393 smc_rx(dev);
1394 }
1395 if (status & IM_TX_INT) {
1396 smc_tx_err(dev);
1397 outw(IM_TX_INT, ioaddr + INTERRUPT);
1398 }
1399 status &= mask;
1400 if (status & IM_TX_EMPTY_INT) {
1401 outw(IM_TX_EMPTY_INT, ioaddr + INTERRUPT);
1402 mask &= ~IM_TX_EMPTY_INT;
1403 dev->stats.tx_packets += smc->packets_waiting;
1404 smc->packets_waiting = 0;
1405 }
1406 if (status & IM_ALLOC_INT) {
1407 /* Clear this interrupt so it doesn't happen again */
1408 mask &= ~IM_ALLOC_INT;
1409
1410 smc_hardware_send_packet(dev);
1411
1412 /* enable xmit interrupts based on this */
1413 mask |= (IM_TX_EMPTY_INT | IM_TX_INT);
1414
1415 /* and let the card send more packets to me */
1416 netif_wake_queue(dev);
1417 }
1418 if (status & IM_RX_OVRN_INT) {
1419 dev->stats.rx_errors++;
1420 dev->stats.rx_fifo_errors++;
1421 if (smc->duplex)
1422 smc->rx_ovrn = 1; /* need MC_RESET outside smc_interrupt */
1423 outw(IM_RX_OVRN_INT, ioaddr + INTERRUPT);
1424 }
1425 if (status & IM_EPH_INT)
1426 smc_eph_irq(dev);
1427 } while (--bogus_cnt);
1428
1429 pr_debug(" Restoring saved registers mask %2.2x bank %4.4x"
1430 " pointer %4.4x.\n", mask, saved_bank, saved_pointer);
1431
1432 /* restore state register */
1433 outw((mask<<8), ioaddr + INTERRUPT);
1434 outw(saved_pointer, ioaddr + POINTER);
1435 SMC_SELECT_BANK(saved_bank);
1436
1437 pr_debug("%s: Exiting interrupt IRQ%d.\n", dev->name, irq);
1438
1439irq_done:
1440
1441 if ((smc->manfid == MANFID_OSITECH) &&
1442 (smc->cardid != PRODID_OSITECH_SEVEN)) {
1443 /* Retrigger interrupt if needed */
1444 mask_bits(0x00ff, ioaddr-0x10+OSITECH_RESET_ISR);
1445 set_bits(0x0300, ioaddr-0x10+OSITECH_RESET_ISR);
1446 }
1447 if (smc->manfid == MANFID_MOTOROLA) {
1448 u_char cor;
1449 cor = readb(smc->base + MOT_UART + CISREG_COR);
1450 writeb(cor & ~COR_IREQ_ENA, smc->base + MOT_UART + CISREG_COR);
1451 writeb(cor, smc->base + MOT_UART + CISREG_COR);
1452 cor = readb(smc->base + MOT_LAN + CISREG_COR);
1453 writeb(cor & ~COR_IREQ_ENA, smc->base + MOT_LAN + CISREG_COR);
1454 writeb(cor, smc->base + MOT_LAN + CISREG_COR);
1455 }
1456
1457 if ((smc->base != NULL) && /* Megahertz MFC's */
1458 (smc->manfid == MANFID_MEGAHERTZ) &&
1459 (smc->cardid == PRODID_MEGAHERTZ_EM3288)) {
1460
1461 u_char tmp;
1462 tmp = readb(smc->base+MEGAHERTZ_ISR);
1463 tmp = readb(smc->base+MEGAHERTZ_ISR);
1464
1465 /* Retrigger interrupt if needed */
1466 writeb(tmp, smc->base + MEGAHERTZ_ISR);
1467 writeb(tmp, smc->base + MEGAHERTZ_ISR);
1468 }
1469
1470 spin_unlock(&smc->lock);
1471 return IRQ_RETVAL(handled);
1472}
1473
1474/*====================================================================*/
1475
1476static void smc_rx(struct net_device *dev)
1477{
1478 unsigned int ioaddr = dev->base_addr;
1479 int rx_status;
1480 int packet_length; /* Caution: not frame length, rather words
1481 to transfer from the chip. */
1482
1483 /* Assertion: we are in Window 2. */
1484
1485 if (inw(ioaddr + FIFO_PORTS) & FP_RXEMPTY) {
1486 netdev_err(dev, "smc_rx() with nothing on Rx FIFO\n");
1487 return;
1488 }
1489
1490 /* Reset the read pointer, and read the status and packet length. */
1491 outw(PTR_READ | PTR_RCV | PTR_AUTOINC, ioaddr + POINTER);
1492 rx_status = inw(ioaddr + DATA_1);
1493 packet_length = inw(ioaddr + DATA_1) & 0x07ff;
1494
1495 pr_debug("%s: Receive status %4.4x length %d.\n",
1496 dev->name, rx_status, packet_length);
1497
1498 if (!(rx_status & RS_ERRORS)) {
1499 /* do stuff to make a new packet */
1500 struct sk_buff *skb;
1501
1502 /* Note: packet_length adds 5 or 6 extra bytes here! */
1503 skb = dev_alloc_skb(packet_length+2);
1504
1505 if (skb == NULL) {
1506 pr_debug("%s: Low memory, packet dropped.\n", dev->name);
1507 dev->stats.rx_dropped++;
1508 outw(MC_RELEASE, ioaddr + MMU_CMD);
1509 return;
1510 }
1511
1512 packet_length -= (rx_status & RS_ODDFRAME ? 5 : 6);
1513 skb_reserve(skb, 2);
1514 insw(ioaddr+DATA_1, skb_put(skb, packet_length),
1515 (packet_length+1)>>1);
1516 skb->protocol = eth_type_trans(skb, dev);
1517
1518 netif_rx(skb);
1519 dev->last_rx = jiffies;
1520 dev->stats.rx_packets++;
1521 dev->stats.rx_bytes += packet_length;
1522 if (rx_status & RS_MULTICAST)
1523 dev->stats.multicast++;
1524 } else {
1525 /* error ... */
1526 dev->stats.rx_errors++;
1527
1528 if (rx_status & RS_ALGNERR) dev->stats.rx_frame_errors++;
1529 if (rx_status & (RS_TOOSHORT | RS_TOOLONG))
1530 dev->stats.rx_length_errors++;
1531 if (rx_status & RS_BADCRC) dev->stats.rx_crc_errors++;
1532 }
1533 /* Let the MMU free the memory of this packet. */
1534 outw(MC_RELEASE, ioaddr + MMU_CMD);
1535}
1536
1537/*======================================================================
1538
1539 Set the receive mode.
1540
1541 This routine is used by both the protocol level to notify us of
1542 promiscuous/multicast mode changes, and by the open/reset code to
1543 initialize the Rx registers. We always set the multicast list and
1544 leave the receiver running.
1545
1546======================================================================*/
1547
1548static void set_rx_mode(struct net_device *dev)
1549{
1550 unsigned int ioaddr = dev->base_addr;
1551 struct smc_private *smc = netdev_priv(dev);
1552 unsigned char multicast_table[8];
1553 unsigned long flags;
1554 u_short rx_cfg_setting;
1555 int i;
1556
1557 memset(multicast_table, 0, sizeof(multicast_table));
1558
1559 if (dev->flags & IFF_PROMISC) {
1560 rx_cfg_setting = RxStripCRC | RxEnable | RxPromisc | RxAllMulti;
1561 } else if (dev->flags & IFF_ALLMULTI)
1562 rx_cfg_setting = RxStripCRC | RxEnable | RxAllMulti;
1563 else {
1564 if (!netdev_mc_empty(dev)) {
1565 struct netdev_hw_addr *ha;
1566
1567 netdev_for_each_mc_addr(ha, dev) {
1568 u_int position = ether_crc(6, ha->addr);
1569 multicast_table[position >> 29] |= 1 << ((position >> 26) & 7);
1570 }
1571 }
1572 rx_cfg_setting = RxStripCRC | RxEnable;
1573 }
1574
1575 /* Load MC table and Rx setting into the chip without interrupts. */
1576 spin_lock_irqsave(&smc->lock, flags);
1577 SMC_SELECT_BANK(3);
1578 for (i = 0; i < 8; i++)
1579 outb(multicast_table[i], ioaddr + MULTICAST0 + i);
1580 SMC_SELECT_BANK(0);
1581 outw(rx_cfg_setting, ioaddr + RCR);
1582 SMC_SELECT_BANK(2);
1583 spin_unlock_irqrestore(&smc->lock, flags);
1584}
1585
1586/*======================================================================
1587
1588 Senses when a card's config changes. Here, it's coax or TP.
1589
1590======================================================================*/
1591
1592static int s9k_config(struct net_device *dev, struct ifmap *map)
1593{
1594 struct smc_private *smc = netdev_priv(dev);
1595 if ((map->port != (u_char)(-1)) && (map->port != dev->if_port)) {
1596 if (smc->cfg & CFG_MII_SELECT)
1597 return -EOPNOTSUPP;
1598 else if (map->port > 2)
1599 return -EINVAL;
1600 dev->if_port = map->port;
1601 netdev_info(dev, "switched to %s port\n", if_names[dev->if_port]);
1602 smc_reset(dev);
1603 }
1604 return 0;
1605}
1606
1607/*======================================================================
1608
1609 Reset the chip, reloading every register that might be corrupted.
1610
1611======================================================================*/
1612
1613/*
1614 Set transceiver type, perhaps to something other than what the user
1615 specified in dev->if_port.
1616*/
1617static void smc_set_xcvr(struct net_device *dev, int if_port)
1618{
1619 struct smc_private *smc = netdev_priv(dev);
1620 unsigned int ioaddr = dev->base_addr;
1621 u_short saved_bank;
1622
1623 saved_bank = inw(ioaddr + BANK_SELECT);
1624 SMC_SELECT_BANK(1);
1625 if (if_port == 2) {
1626 outw(smc->cfg | CFG_AUI_SELECT, ioaddr + CONFIG);
1627 if ((smc->manfid == MANFID_OSITECH) &&
1628 (smc->cardid != PRODID_OSITECH_SEVEN))
1629 set_bits(OSI_AUI_PWR, ioaddr - 0x10 + OSITECH_AUI_PWR);
1630 smc->media_status = ((dev->if_port == 0) ? 0x0001 : 0x0002);
1631 } else {
1632 outw(smc->cfg, ioaddr + CONFIG);
1633 if ((smc->manfid == MANFID_OSITECH) &&
1634 (smc->cardid != PRODID_OSITECH_SEVEN))
1635 mask_bits(~OSI_AUI_PWR, ioaddr - 0x10 + OSITECH_AUI_PWR);
1636 smc->media_status = ((dev->if_port == 0) ? 0x0012 : 0x4001);
1637 }
1638 SMC_SELECT_BANK(saved_bank);
1639}
1640
1641static void smc_reset(struct net_device *dev)
1642{
1643 unsigned int ioaddr = dev->base_addr;
1644 struct smc_private *smc = netdev_priv(dev);
1645 int i;
1646
1647 pr_debug("%s: smc91c92 reset called.\n", dev->name);
1648
1649 /* The first interaction must be a write to bring the chip out
1650 of sleep mode. */
1651 SMC_SELECT_BANK(0);
1652 /* Reset the chip. */
1653 outw(RCR_SOFTRESET, ioaddr + RCR);
1654 udelay(10);
1655
1656 /* Clear the transmit and receive configuration registers. */
1657 outw(RCR_CLEAR, ioaddr + RCR);
1658 outw(TCR_CLEAR, ioaddr + TCR);
1659
1660 /* Set the Window 1 control, configuration and station addr registers.
1661 No point in writing the I/O base register ;-> */
1662 SMC_SELECT_BANK(1);
1663 /* Automatically release successfully transmitted packets,
1664 Accept link errors, counter and Tx error interrupts. */
1665 outw(CTL_AUTO_RELEASE | CTL_TE_ENABLE | CTL_CR_ENABLE,
1666 ioaddr + CONTROL);
1667 smc_set_xcvr(dev, dev->if_port);
1668 if ((smc->manfid == MANFID_OSITECH) &&
1669 (smc->cardid != PRODID_OSITECH_SEVEN))
1670 outw((dev->if_port == 2 ? OSI_AUI_PWR : 0) |
1671 (inw(ioaddr-0x10+OSITECH_AUI_PWR) & 0xff00),
1672 ioaddr - 0x10 + OSITECH_AUI_PWR);
1673
1674 /* Fill in the physical address. The databook is wrong about the order! */
1675 for (i = 0; i < 6; i += 2)
1676 outw((dev->dev_addr[i+1]<<8)+dev->dev_addr[i],
1677 ioaddr + ADDR0 + i);
1678
1679 /* Reset the MMU */
1680 SMC_SELECT_BANK(2);
1681 outw(MC_RESET, ioaddr + MMU_CMD);
1682 outw(0, ioaddr + INTERRUPT);
1683
1684 /* Re-enable the chip. */
1685 SMC_SELECT_BANK(0);
1686 outw(((smc->cfg & CFG_MII_SELECT) ? 0 : TCR_MONCSN) |
1687 TCR_ENABLE | TCR_PAD_EN | smc->duplex, ioaddr + TCR);
1688 set_rx_mode(dev);
1689
1690 if (smc->cfg & CFG_MII_SELECT) {
1691 SMC_SELECT_BANK(3);
1692
1693 /* Reset MII */
1694 mdio_write(dev, smc->mii_if.phy_id, 0, 0x8000);
1695
1696 /* Advertise 100F, 100H, 10F, 10H */
1697 mdio_write(dev, smc->mii_if.phy_id, 4, 0x01e1);
1698
1699 /* Restart MII autonegotiation */
1700 mdio_write(dev, smc->mii_if.phy_id, 0, 0x0000);
1701 mdio_write(dev, smc->mii_if.phy_id, 0, 0x1200);
1702 }
1703
1704 /* Enable interrupts. */
1705 SMC_SELECT_BANK(2);
1706 outw((IM_EPH_INT | IM_RX_OVRN_INT | IM_RCV_INT) << 8,
1707 ioaddr + INTERRUPT);
1708}
1709
1710/*======================================================================
1711
1712 Media selection timer routine
1713
1714======================================================================*/
1715
1716static void media_check(u_long arg)
1717{
1718 struct net_device *dev = (struct net_device *) arg;
1719 struct smc_private *smc = netdev_priv(dev);
1720 unsigned int ioaddr = dev->base_addr;
1721 u_short i, media, saved_bank;
1722 u_short link;
1723 unsigned long flags;
1724
1725 spin_lock_irqsave(&smc->lock, flags);
1726
1727 saved_bank = inw(ioaddr + BANK_SELECT);
1728
1729 if (!netif_device_present(dev))
1730 goto reschedule;
1731
1732 SMC_SELECT_BANK(2);
1733
1734 /* need MC_RESET to keep the memory consistent. errata? */
1735 if (smc->rx_ovrn) {
1736 outw(MC_RESET, ioaddr + MMU_CMD);
1737 smc->rx_ovrn = 0;
1738 }
1739 i = inw(ioaddr + INTERRUPT);
1740 SMC_SELECT_BANK(0);
1741 media = inw(ioaddr + EPH) & EPH_LINK_OK;
1742 SMC_SELECT_BANK(1);
1743 media |= (inw(ioaddr + CONFIG) & CFG_AUI_SELECT) ? 2 : 1;
1744
1745 SMC_SELECT_BANK(saved_bank);
1746 spin_unlock_irqrestore(&smc->lock, flags);
1747
1748 /* Check for pending interrupt with watchdog flag set: with
1749 this, we can limp along even if the interrupt is blocked */
1750 if (smc->watchdog++ && ((i>>8) & i)) {
1751 if (!smc->fast_poll)
1752 netdev_info(dev, "interrupt(s) dropped!\n");
1753 local_irq_save(flags);
1754 smc_interrupt(dev->irq, dev);
1755 local_irq_restore(flags);
1756 smc->fast_poll = HZ;
1757 }
1758 if (smc->fast_poll) {
1759 smc->fast_poll--;
1760 smc->media.expires = jiffies + HZ/100;
1761 add_timer(&smc->media);
1762 return;
1763 }
1764
1765 spin_lock_irqsave(&smc->lock, flags);
1766
1767 saved_bank = inw(ioaddr + BANK_SELECT);
1768
1769 if (smc->cfg & CFG_MII_SELECT) {
1770 if (smc->mii_if.phy_id < 0)
1771 goto reschedule;
1772
1773 SMC_SELECT_BANK(3);
1774 link = mdio_read(dev, smc->mii_if.phy_id, 1);
1775 if (!link || (link == 0xffff)) {
1776 netdev_info(dev, "MII is missing!\n");
1777 smc->mii_if.phy_id = -1;
1778 goto reschedule;
1779 }
1780
1781 link &= 0x0004;
1782 if (link != smc->link_status) {
1783 u_short p = mdio_read(dev, smc->mii_if.phy_id, 5);
1784 netdev_info(dev, "%s link beat\n", link ? "found" : "lost");
1785 smc->duplex = (((p & 0x0100) || ((p & 0x1c0) == 0x40))
1786 ? TCR_FDUPLX : 0);
1787 if (link) {
1788 netdev_info(dev, "autonegotiation complete: "
1789 "%dbaseT-%cD selected\n",
1790 (p & 0x0180) ? 100 : 10, smc->duplex ? 'F' : 'H');
1791 }
1792 SMC_SELECT_BANK(0);
1793 outw(inw(ioaddr + TCR) | smc->duplex, ioaddr + TCR);
1794 smc->link_status = link;
1795 }
1796 goto reschedule;
1797 }
1798
1799 /* Ignore collisions unless we've had no rx's recently */
1800 if (time_after(jiffies, dev->last_rx + HZ)) {
1801 if (smc->tx_err || (smc->media_status & EPH_16COL))
1802 media |= EPH_16COL;
1803 }
1804 smc->tx_err = 0;
1805
1806 if (media != smc->media_status) {
1807 if ((media & smc->media_status & 1) &&
1808 ((smc->media_status ^ media) & EPH_LINK_OK))
1809 netdev_info(dev, "%s link beat\n",
1810 smc->media_status & EPH_LINK_OK ? "lost" : "found");
1811 else if ((media & smc->media_status & 2) &&
1812 ((smc->media_status ^ media) & EPH_16COL))
1813 netdev_info(dev, "coax cable %s\n",
1814 media & EPH_16COL ? "problem" : "ok");
1815 if (dev->if_port == 0) {
1816 if (media & 1) {
1817 if (media & EPH_LINK_OK)
1818 netdev_info(dev, "flipped to 10baseT\n");
1819 else
1820 smc_set_xcvr(dev, 2);
1821 } else {
1822 if (media & EPH_16COL)
1823 smc_set_xcvr(dev, 1);
1824 else
1825 netdev_info(dev, "flipped to 10base2\n");
1826 }
1827 }
1828 smc->media_status = media;
1829 }
1830
1831reschedule:
1832 smc->media.expires = jiffies + HZ;
1833 add_timer(&smc->media);
1834 SMC_SELECT_BANK(saved_bank);
1835 spin_unlock_irqrestore(&smc->lock, flags);
1836}
1837
1838static int smc_link_ok(struct net_device *dev)
1839{
1840 unsigned int ioaddr = dev->base_addr;
1841 struct smc_private *smc = netdev_priv(dev);
1842
1843 if (smc->cfg & CFG_MII_SELECT) {
1844 return mii_link_ok(&smc->mii_if);
1845 } else {
1846 SMC_SELECT_BANK(0);
1847 return inw(ioaddr + EPH) & EPH_LINK_OK;
1848 }
1849}
1850
1851static int smc_netdev_get_ecmd(struct net_device *dev, struct ethtool_cmd *ecmd)
1852{
1853 u16 tmp;
1854 unsigned int ioaddr = dev->base_addr;
1855
1856 ecmd->supported = (SUPPORTED_TP | SUPPORTED_AUI |
1857 SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full);
1858
1859 SMC_SELECT_BANK(1);
1860 tmp = inw(ioaddr + CONFIG);
1861 ecmd->port = (tmp & CFG_AUI_SELECT) ? PORT_AUI : PORT_TP;
1862 ecmd->transceiver = XCVR_INTERNAL;
1863 ethtool_cmd_speed_set(ecmd, SPEED_10);
1864 ecmd->phy_address = ioaddr + MGMT;
1865
1866 SMC_SELECT_BANK(0);
1867 tmp = inw(ioaddr + TCR);
1868 ecmd->duplex = (tmp & TCR_FDUPLX) ? DUPLEX_FULL : DUPLEX_HALF;
1869
1870 return 0;
1871}
1872
1873static int smc_netdev_set_ecmd(struct net_device *dev, struct ethtool_cmd *ecmd)
1874{
1875 u16 tmp;
1876 unsigned int ioaddr = dev->base_addr;
1877
1878 if (ethtool_cmd_speed(ecmd) != SPEED_10)
1879 return -EINVAL;
1880 if (ecmd->duplex != DUPLEX_HALF && ecmd->duplex != DUPLEX_FULL)
1881 return -EINVAL;
1882 if (ecmd->port != PORT_TP && ecmd->port != PORT_AUI)
1883 return -EINVAL;
1884 if (ecmd->transceiver != XCVR_INTERNAL)
1885 return -EINVAL;
1886
1887 if (ecmd->port == PORT_AUI)
1888 smc_set_xcvr(dev, 1);
1889 else
1890 smc_set_xcvr(dev, 0);
1891
1892 SMC_SELECT_BANK(0);
1893 tmp = inw(ioaddr + TCR);
1894 if (ecmd->duplex == DUPLEX_FULL)
1895 tmp |= TCR_FDUPLX;
1896 else
1897 tmp &= ~TCR_FDUPLX;
1898 outw(tmp, ioaddr + TCR);
1899
1900 return 0;
1901}
1902
1903static int check_if_running(struct net_device *dev)
1904{
1905 if (!netif_running(dev))
1906 return -EINVAL;
1907 return 0;
1908}
1909
1910static void smc_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
1911{
1912 strcpy(info->driver, DRV_NAME);
1913 strcpy(info->version, DRV_VERSION);
1914}
1915
1916static int smc_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
1917{
1918 struct smc_private *smc = netdev_priv(dev);
1919 unsigned int ioaddr = dev->base_addr;
1920 u16 saved_bank = inw(ioaddr + BANK_SELECT);
1921 int ret;
1922 unsigned long flags;
1923
1924 spin_lock_irqsave(&smc->lock, flags);
1925 SMC_SELECT_BANK(3);
1926 if (smc->cfg & CFG_MII_SELECT)
1927 ret = mii_ethtool_gset(&smc->mii_if, ecmd);
1928 else
1929 ret = smc_netdev_get_ecmd(dev, ecmd);
1930 SMC_SELECT_BANK(saved_bank);
1931 spin_unlock_irqrestore(&smc->lock, flags);
1932 return ret;
1933}
1934
1935static int smc_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
1936{
1937 struct smc_private *smc = netdev_priv(dev);
1938 unsigned int ioaddr = dev->base_addr;
1939 u16 saved_bank = inw(ioaddr + BANK_SELECT);
1940 int ret;
1941 unsigned long flags;
1942
1943 spin_lock_irqsave(&smc->lock, flags);
1944 SMC_SELECT_BANK(3);
1945 if (smc->cfg & CFG_MII_SELECT)
1946 ret = mii_ethtool_sset(&smc->mii_if, ecmd);
1947 else
1948 ret = smc_netdev_set_ecmd(dev, ecmd);
1949 SMC_SELECT_BANK(saved_bank);
1950 spin_unlock_irqrestore(&smc->lock, flags);
1951 return ret;
1952}
1953
1954static u32 smc_get_link(struct net_device *dev)
1955{
1956 struct smc_private *smc = netdev_priv(dev);
1957 unsigned int ioaddr = dev->base_addr;
1958 u16 saved_bank = inw(ioaddr + BANK_SELECT);
1959 u32 ret;
1960 unsigned long flags;
1961
1962 spin_lock_irqsave(&smc->lock, flags);
1963 SMC_SELECT_BANK(3);
1964 ret = smc_link_ok(dev);
1965 SMC_SELECT_BANK(saved_bank);
1966 spin_unlock_irqrestore(&smc->lock, flags);
1967 return ret;
1968}
1969
1970static int smc_nway_reset(struct net_device *dev)
1971{
1972 struct smc_private *smc = netdev_priv(dev);
1973 if (smc->cfg & CFG_MII_SELECT) {
1974 unsigned int ioaddr = dev->base_addr;
1975 u16 saved_bank = inw(ioaddr + BANK_SELECT);
1976 int res;
1977
1978 SMC_SELECT_BANK(3);
1979 res = mii_nway_restart(&smc->mii_if);
1980 SMC_SELECT_BANK(saved_bank);
1981
1982 return res;
1983 } else
1984 return -EOPNOTSUPP;
1985}
1986
1987static const struct ethtool_ops ethtool_ops = {
1988 .begin = check_if_running,
1989 .get_drvinfo = smc_get_drvinfo,
1990 .get_settings = smc_get_settings,
1991 .set_settings = smc_set_settings,
1992 .get_link = smc_get_link,
1993 .nway_reset = smc_nway_reset,
1994};
1995
1996static int smc_ioctl (struct net_device *dev, struct ifreq *rq, int cmd)
1997{
1998 struct smc_private *smc = netdev_priv(dev);
1999 struct mii_ioctl_data *mii = if_mii(rq);
2000 int rc = 0;
2001 u16 saved_bank;
2002 unsigned int ioaddr = dev->base_addr;
2003 unsigned long flags;
2004
2005 if (!netif_running(dev))
2006 return -EINVAL;
2007
2008 spin_lock_irqsave(&smc->lock, flags);
2009 saved_bank = inw(ioaddr + BANK_SELECT);
2010 SMC_SELECT_BANK(3);
2011 rc = generic_mii_ioctl(&smc->mii_if, mii, cmd, NULL);
2012 SMC_SELECT_BANK(saved_bank);
2013 spin_unlock_irqrestore(&smc->lock, flags);
2014 return rc;
2015}
2016
2017static const struct pcmcia_device_id smc91c92_ids[] = {
2018 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0109, 0x0501),
2019 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0140, 0x000a),
2020 PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "CC/XJEM3288", "DATA/FAX/CELL ETHERNET MODEM", 0xf510db04, 0x04cd2988, 0x46a52d63),
2021 PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "CC/XJEM3336", "DATA/FAX/CELL ETHERNET MODEM", 0xf510db04, 0x0143b773, 0x46a52d63),
2022 PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "EM1144T", "PCMCIA MODEM", 0xf510db04, 0x856d66c8, 0xbd6c43ef),
2023 PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "XJEM1144/CCEM1144", "PCMCIA MODEM", 0xf510db04, 0x52d21e1e, 0xbd6c43ef),
2024 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Gateway 2000", "XJEM3336", 0xdd9989be, 0x662c394c),
2025 PCMCIA_PFC_DEVICE_PROD_ID12(0, "MEGAHERTZ", "XJEM1144/CCEM1144", 0xf510db04, 0x52d21e1e),
2026 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Ositech", "Trumpcard:Jack of Diamonds Modem+Ethernet", 0xc2f80cd, 0x656947b9),
2027 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Ositech", "Trumpcard:Jack of Hearts Modem+Ethernet", 0xc2f80cd, 0xdc9ba5ed),
2028 PCMCIA_MFC_DEVICE_MANF_CARD(0, 0x016c, 0x0020),
2029 PCMCIA_DEVICE_MANF_CARD(0x016c, 0x0023),
2030 PCMCIA_DEVICE_PROD_ID123("BASICS by New Media Corporation", "Ethernet", "SMC91C94", 0x23c78a9d, 0x00b2e941, 0xcef397fb),
2031 PCMCIA_DEVICE_PROD_ID12("ARGOSY", "Fast Ethernet PCCard", 0x78f308dc, 0xdcea68bc),
2032 PCMCIA_DEVICE_PROD_ID12("dit Co., Ltd.", "PC Card-10/100BTX", 0xe59365c8, 0x6a2161d1),
2033 PCMCIA_DEVICE_PROD_ID12("DYNALINK", "L100C", 0x6a26d1cf, 0xc16ce9c5),
2034 PCMCIA_DEVICE_PROD_ID12("Farallon", "Farallon Enet", 0x58d93fc4, 0x244734e9),
2035 PCMCIA_DEVICE_PROD_ID12("Megahertz", "CC10BT/2", 0x33234748, 0x3c95b953),
2036 PCMCIA_DEVICE_PROD_ID12("MELCO/SMC", "LPC-TX", 0xa2cd8e6d, 0x42da662a),
2037 PCMCIA_DEVICE_PROD_ID12("Ositech", "Trumpcard:Four of Diamonds Ethernet", 0xc2f80cd, 0xb3466314),
2038 PCMCIA_DEVICE_PROD_ID12("Ositech", "Trumpcard:Seven of Diamonds Ethernet", 0xc2f80cd, 0x194b650a),
2039 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "Fast Ethernet PCCard", 0x281f1c5d, 0xdcea68bc),
2040 PCMCIA_DEVICE_PROD_ID12("Psion", "10Mb Ethernet", 0x4ef00b21, 0x844be9e9),
2041 PCMCIA_DEVICE_PROD_ID12("SMC", "EtherEZ Ethernet 8020", 0xc4f8b18b, 0x4a0eeb2d),
2042 /* These conflict with other cards! */
2043 /* PCMCIA_DEVICE_MANF_CARD(0x0186, 0x0100), */
2044 /* PCMCIA_DEVICE_MANF_CARD(0x8a01, 0xc1ab), */
2045 PCMCIA_DEVICE_NULL,
2046};
2047MODULE_DEVICE_TABLE(pcmcia, smc91c92_ids);
2048
2049static struct pcmcia_driver smc91c92_cs_driver = {
2050 .owner = THIS_MODULE,
2051 .name = "smc91c92_cs",
2052 .probe = smc91c92_probe,
2053 .remove = smc91c92_detach,
2054 .id_table = smc91c92_ids,
2055 .suspend = smc91c92_suspend,
2056 .resume = smc91c92_resume,
2057};
2058
2059static int __init init_smc91c92_cs(void)
2060{
2061 return pcmcia_register_driver(&smc91c92_cs_driver);
2062}
2063
2064static void __exit exit_smc91c92_cs(void)
2065{
2066 pcmcia_unregister_driver(&smc91c92_cs_driver);
2067}
2068
2069module_init(init_smc91c92_cs);
2070module_exit(exit_smc91c92_cs);
diff --git a/drivers/net/pcmcia/xirc2ps_cs.c b/drivers/net/pcmcia/xirc2ps_cs.c
new file mode 100644
index 00000000000..e33b190d716
--- /dev/null
+++ b/drivers/net/pcmcia/xirc2ps_cs.c
@@ -0,0 +1,1813 @@
1/* [xirc2ps_cs.c wk 03.11.99] (1.40 1999/11/18 00:06:03)
2 * Xircom CreditCard Ethernet Adapter IIps driver
3 * Xircom Realport 10/100 (RE-100) driver
4 *
5 * This driver supports various Xircom CreditCard Ethernet adapters
6 * including the CE2, CE IIps, RE-10, CEM28, CEM33, CE33, CEM56,
7 * CE3-100, CE3B, RE-100, REM10BT, and REM56G-100.
8 *
9 * 2000-09-24 <psheer@icon.co.za> The Xircom CE3B-100 may not
10 * autodetect the media properly. In this case use the
11 * if_port=1 (for 10BaseT) or if_port=4 (for 100BaseT) options
12 * to force the media type.
13 *
14 * Written originally by Werner Koch based on David Hinds' skeleton of the
15 * PCMCIA driver.
16 *
17 * Copyright (c) 1997,1998 Werner Koch (dd9jn)
18 *
19 * This driver is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
23 *
24 * It is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
32 *
33 *
34 * ALTERNATIVELY, this driver may be distributed under the terms of
35 * the following license, in which case the provisions of this license
36 * are required INSTEAD OF the GNU General Public License. (This clause
37 * is necessary due to a potential bad interaction between the GPL and
38 * the restrictions contained in a BSD-style copyright.)
39 *
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
42 * are met:
43 * 1. Redistributions of source code must retain the above copyright
44 * notice, and the entire permission notice in its entirety,
45 * including the disclaimer of warranties.
46 * 2. Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in the
48 * documentation and/or other materials provided with the distribution.
49 * 3. The name of the author may not be used to endorse or promote
50 * products derived from this software without specific prior
51 * written permission.
52 *
53 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
54 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
55 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
56 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
57 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
58 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
59 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
61 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
62 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
63 * OF THE POSSIBILITY OF SUCH DAMAGE.
64 */
65
66#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
67
68#include <linux/module.h>
69#include <linux/kernel.h>
70#include <linux/init.h>
71#include <linux/ptrace.h>
72#include <linux/slab.h>
73#include <linux/string.h>
74#include <linux/timer.h>
75#include <linux/interrupt.h>
76#include <linux/in.h>
77#include <linux/delay.h>
78#include <linux/ethtool.h>
79#include <linux/netdevice.h>
80#include <linux/etherdevice.h>
81#include <linux/skbuff.h>
82#include <linux/if_arp.h>
83#include <linux/ioport.h>
84#include <linux/bitops.h>
85#include <linux/mii.h>
86
87#include <pcmcia/cistpl.h>
88#include <pcmcia/cisreg.h>
89#include <pcmcia/ciscode.h>
90
91#include <asm/io.h>
92#include <asm/system.h>
93#include <asm/uaccess.h>
94
95#ifndef MANFID_COMPAQ
96 #define MANFID_COMPAQ 0x0138
97 #define MANFID_COMPAQ2 0x0183 /* is this correct? */
98#endif
99
100#include <pcmcia/ds.h>
101
102/* Time in jiffies before concluding Tx hung */
103#define TX_TIMEOUT ((400*HZ)/1000)
104
105/****************
106 * Some constants used to access the hardware
107 */
108
109/* Register offsets and value constans */
110#define XIRCREG_CR 0 /* Command register (wr) */
111enum xirc_cr {
112 TransmitPacket = 0x01,
113 SoftReset = 0x02,
114 EnableIntr = 0x04,
115 ForceIntr = 0x08,
116 ClearTxFIFO = 0x10,
117 ClearRxOvrun = 0x20,
118 RestartTx = 0x40
119};
120#define XIRCREG_ESR 0 /* Ethernet status register (rd) */
121enum xirc_esr {
122 FullPktRcvd = 0x01, /* full packet in receive buffer */
123 PktRejected = 0x04, /* a packet has been rejected */
124 TxPktPend = 0x08, /* TX Packet Pending */
125 IncorPolarity = 0x10,
126 MediaSelect = 0x20 /* set if TP, clear if AUI */
127};
128#define XIRCREG_PR 1 /* Page Register select */
129#define XIRCREG_EDP 4 /* Ethernet Data Port Register */
130#define XIRCREG_ISR 6 /* Ethernet Interrupt Status Register */
131enum xirc_isr {
132 TxBufOvr = 0x01, /* TX Buffer Overflow */
133 PktTxed = 0x02, /* Packet Transmitted */
134 MACIntr = 0x04, /* MAC Interrupt occurred */
135 TxResGrant = 0x08, /* Tx Reservation Granted */
136 RxFullPkt = 0x20, /* Rx Full Packet */
137 RxPktRej = 0x40, /* Rx Packet Rejected */
138 ForcedIntr= 0x80 /* Forced Interrupt */
139};
140#define XIRCREG1_IMR0 12 /* Ethernet Interrupt Mask Register (on page 1)*/
141#define XIRCREG1_IMR1 13
142#define XIRCREG0_TSO 8 /* Transmit Space Open Register (on page 0)*/
143#define XIRCREG0_TRS 10 /* Transmit reservation Size Register (page 0)*/
144#define XIRCREG0_DO 12 /* Data Offset Register (page 0) (wr) */
145#define XIRCREG0_RSR 12 /* Receive Status Register (page 0) (rd) */
146enum xirc_rsr {
147 PhyPkt = 0x01, /* set:physical packet, clear: multicast packet */
148 BrdcstPkt = 0x02, /* set if it is a broadcast packet */
149 PktTooLong = 0x04, /* set if packet length > 1518 */
150 AlignErr = 0x10, /* incorrect CRC and last octet not complete */
151 CRCErr = 0x20, /* incorrect CRC and last octet is complete */
152 PktRxOk = 0x80 /* received ok */
153};
154#define XIRCREG0_PTR 13 /* packets transmitted register (rd) */
155#define XIRCREG0_RBC 14 /* receive byte count regsister (rd) */
156#define XIRCREG1_ECR 14 /* ethernet configurationn register */
157enum xirc_ecr {
158 FullDuplex = 0x04, /* enable full duplex mode */
159 LongTPMode = 0x08, /* adjust for longer lengths of TP cable */
160 DisablePolCor = 0x10,/* disable auto polarity correction */
161 DisableLinkPulse = 0x20, /* disable link pulse generation */
162 DisableAutoTx = 0x40, /* disable auto-transmit */
163};
164#define XIRCREG2_RBS 8 /* receive buffer start register */
165#define XIRCREG2_LED 10 /* LED Configuration register */
166/* values for the leds: Bits 2-0 for led 1
167 * 0 disabled Bits 5-3 for led 2
168 * 1 collision
169 * 2 noncollision
170 * 3 link_detected
171 * 4 incor_polarity
172 * 5 jabber
173 * 6 auto_assertion
174 * 7 rx_tx_activity
175 */
176#define XIRCREG2_MSR 12 /* Mohawk specific register */
177
178#define XIRCREG4_GPR0 8 /* General Purpose Register 0 */
179#define XIRCREG4_GPR1 9 /* General Purpose Register 1 */
180#define XIRCREG2_GPR2 13 /* General Purpose Register 2 (page2!)*/
181#define XIRCREG4_BOV 10 /* Bonding Version Register */
182#define XIRCREG4_LMA 12 /* Local Memory Address Register */
183#define XIRCREG4_LMD 14 /* Local Memory Data Port */
184/* MAC register can only by accessed with 8 bit operations */
185#define XIRCREG40_CMD0 8 /* Command Register (wr) */
186enum xirc_cmd { /* Commands */
187 Transmit = 0x01,
188 EnableRecv = 0x04,
189 DisableRecv = 0x08,
190 Abort = 0x10,
191 Online = 0x20,
192 IntrAck = 0x40,
193 Offline = 0x80
194};
195#define XIRCREG5_RHSA0 10 /* Rx Host Start Address */
196#define XIRCREG40_RXST0 9 /* Receive Status Register */
197#define XIRCREG40_TXST0 11 /* Transmit Status Register 0 */
198#define XIRCREG40_TXST1 12 /* Transmit Status Register 10 */
199#define XIRCREG40_RMASK0 13 /* Receive Mask Register */
200#define XIRCREG40_TMASK0 14 /* Transmit Mask Register 0 */
201#define XIRCREG40_TMASK1 15 /* Transmit Mask Register 0 */
202#define XIRCREG42_SWC0 8 /* Software Configuration 0 */
203#define XIRCREG42_SWC1 9 /* Software Configuration 1 */
204#define XIRCREG42_BOC 10 /* Back-Off Configuration */
205#define XIRCREG44_TDR0 8 /* Time Domain Reflectometry 0 */
206#define XIRCREG44_TDR1 9 /* Time Domain Reflectometry 1 */
207#define XIRCREG44_RXBC_LO 10 /* Rx Byte Count 0 (rd) */
208#define XIRCREG44_RXBC_HI 11 /* Rx Byte Count 1 (rd) */
209#define XIRCREG45_REV 15 /* Revision Register (rd) */
210#define XIRCREG50_IA 8 /* Individual Address (8-13) */
211
212static const char *if_names[] = { "Auto", "10BaseT", "10Base2", "AUI", "100BaseT" };
213
214/* card types */
215#define XIR_UNKNOWN 0 /* unknown: not supported */
216#define XIR_CE 1 /* (prodid 1) different hardware: not supported */
217#define XIR_CE2 2 /* (prodid 2) */
218#define XIR_CE3 3 /* (prodid 3) */
219#define XIR_CEM 4 /* (prodid 1) different hardware: not supported */
220#define XIR_CEM2 5 /* (prodid 2) */
221#define XIR_CEM3 6 /* (prodid 3) */
222#define XIR_CEM33 7 /* (prodid 4) */
223#define XIR_CEM56M 8 /* (prodid 5) */
224#define XIR_CEM56 9 /* (prodid 6) */
225#define XIR_CM28 10 /* (prodid 3) modem only: not supported here */
226#define XIR_CM33 11 /* (prodid 4) modem only: not supported here */
227#define XIR_CM56 12 /* (prodid 5) modem only: not supported here */
228#define XIR_CG 13 /* (prodid 1) GSM modem only: not supported */
229#define XIR_CBE 14 /* (prodid 1) cardbus ethernet: not supported */
230/*====================================================================*/
231
232/* Module parameters */
233
234MODULE_DESCRIPTION("Xircom PCMCIA ethernet driver");
235MODULE_LICENSE("Dual MPL/GPL");
236
237#define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0)
238
239INT_MODULE_PARM(if_port, 0);
240INT_MODULE_PARM(full_duplex, 0);
241INT_MODULE_PARM(do_sound, 1);
242INT_MODULE_PARM(lockup_hack, 0); /* anti lockup hack */
243
244/*====================================================================*/
245
246/* We do not process more than these number of bytes during one
247 * interrupt. (Of course we receive complete packets, so this is not
248 * an exact value).
249 * Something between 2000..22000; first value gives best interrupt latency,
250 * the second enables the usage of the complete on-chip buffer. We use the
251 * high value as the initial value.
252 */
253static unsigned maxrx_bytes = 22000;
254
255/* MII management prototypes */
256static void mii_idle(unsigned int ioaddr);
257static void mii_putbit(unsigned int ioaddr, unsigned data);
258static int mii_getbit(unsigned int ioaddr);
259static void mii_wbits(unsigned int ioaddr, unsigned data, int len);
260static unsigned mii_rd(unsigned int ioaddr, u_char phyaddr, u_char phyreg);
261static void mii_wr(unsigned int ioaddr, u_char phyaddr, u_char phyreg,
262 unsigned data, int len);
263
264static int has_ce2_string(struct pcmcia_device * link);
265static int xirc2ps_config(struct pcmcia_device * link);
266static void xirc2ps_release(struct pcmcia_device * link);
267static void xirc2ps_detach(struct pcmcia_device *p_dev);
268
269static irqreturn_t xirc2ps_interrupt(int irq, void *dev_id);
270
271typedef struct local_info_t {
272 struct net_device *dev;
273 struct pcmcia_device *p_dev;
274
275 int card_type;
276 int probe_port;
277 int silicon; /* silicon revision. 0=old CE2, 1=Scipper, 4=Mohawk */
278 int mohawk; /* a CE3 type card */
279 int dingo; /* a CEM56 type card */
280 int new_mii; /* has full 10baseT/100baseT MII */
281 int modem; /* is a multi function card (i.e with a modem) */
282 void __iomem *dingo_ccr; /* only used for CEM56 cards */
283 unsigned last_ptr_value; /* last packets transmitted value */
284 const char *manf_str;
285 struct work_struct tx_timeout_task;
286} local_info_t;
287
288/****************
289 * Some more prototypes
290 */
291static netdev_tx_t do_start_xmit(struct sk_buff *skb,
292 struct net_device *dev);
293static void xirc_tx_timeout(struct net_device *dev);
294static void xirc2ps_tx_timeout_task(struct work_struct *work);
295static void set_addresses(struct net_device *dev);
296static void set_multicast_list(struct net_device *dev);
297static int set_card_type(struct pcmcia_device *link);
298static int do_config(struct net_device *dev, struct ifmap *map);
299static int do_open(struct net_device *dev);
300static int do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
301static const struct ethtool_ops netdev_ethtool_ops;
302static void hardreset(struct net_device *dev);
303static void do_reset(struct net_device *dev, int full);
304static int init_mii(struct net_device *dev);
305static void do_powerdown(struct net_device *dev);
306static int do_stop(struct net_device *dev);
307
308/*=============== Helper functions =========================*/
309#define SelectPage(pgnr) outb((pgnr), ioaddr + XIRCREG_PR)
310#define GetByte(reg) ((unsigned)inb(ioaddr + (reg)))
311#define GetWord(reg) ((unsigned)inw(ioaddr + (reg)))
312#define PutByte(reg,value) outb((value), ioaddr+(reg))
313#define PutWord(reg,value) outw((value), ioaddr+(reg))
314
315/*====== Functions used for debugging =================================*/
316#if 0 /* reading regs may change system status */
317static void
318PrintRegisters(struct net_device *dev)
319{
320 unsigned int ioaddr = dev->base_addr;
321
322 if (pc_debug > 1) {
323 int i, page;
324
325 printk(KERN_DEBUG pr_fmt("Register common: "));
326 for (i = 0; i < 8; i++)
327 pr_cont(" %2.2x", GetByte(i));
328 pr_cont("\n");
329 for (page = 0; page <= 8; page++) {
330 printk(KERN_DEBUG pr_fmt("Register page %2x: "), page);
331 SelectPage(page);
332 for (i = 8; i < 16; i++)
333 pr_cont(" %2.2x", GetByte(i));
334 pr_cont("\n");
335 }
336 for (page=0x40 ; page <= 0x5f; page++) {
337 if (page == 0x43 || (page >= 0x46 && page <= 0x4f) ||
338 (page >= 0x51 && page <=0x5e))
339 continue;
340 printk(KERN_DEBUG pr_fmt("Register page %2x: "), page);
341 SelectPage(page);
342 for (i = 8; i < 16; i++)
343 pr_cont(" %2.2x", GetByte(i));
344 pr_cont("\n");
345 }
346 }
347}
348#endif /* 0 */
349
350/*============== MII Management functions ===============*/
351
352/****************
353 * Turn around for read
354 */
355static void
356mii_idle(unsigned int ioaddr)
357{
358 PutByte(XIRCREG2_GPR2, 0x04|0); /* drive MDCK low */
359 udelay(1);
360 PutByte(XIRCREG2_GPR2, 0x04|1); /* and drive MDCK high */
361 udelay(1);
362}
363
364/****************
365 * Write a bit to MDI/O
366 */
367static void
368mii_putbit(unsigned int ioaddr, unsigned data)
369{
370 #if 1
371 if (data) {
372 PutByte(XIRCREG2_GPR2, 0x0c|2|0); /* set MDIO */
373 udelay(1);
374 PutByte(XIRCREG2_GPR2, 0x0c|2|1); /* and drive MDCK high */
375 udelay(1);
376 } else {
377 PutByte(XIRCREG2_GPR2, 0x0c|0|0); /* clear MDIO */
378 udelay(1);
379 PutByte(XIRCREG2_GPR2, 0x0c|0|1); /* and drive MDCK high */
380 udelay(1);
381 }
382 #else
383 if (data) {
384 PutWord(XIRCREG2_GPR2-1, 0x0e0e);
385 udelay(1);
386 PutWord(XIRCREG2_GPR2-1, 0x0f0f);
387 udelay(1);
388 } else {
389 PutWord(XIRCREG2_GPR2-1, 0x0c0c);
390 udelay(1);
391 PutWord(XIRCREG2_GPR2-1, 0x0d0d);
392 udelay(1);
393 }
394 #endif
395}
396
397/****************
398 * Get a bit from MDI/O
399 */
400static int
401mii_getbit(unsigned int ioaddr)
402{
403 unsigned d;
404
405 PutByte(XIRCREG2_GPR2, 4|0); /* drive MDCK low */
406 udelay(1);
407 d = GetByte(XIRCREG2_GPR2); /* read MDIO */
408 PutByte(XIRCREG2_GPR2, 4|1); /* drive MDCK high again */
409 udelay(1);
410 return d & 0x20; /* read MDIO */
411}
412
413static void
414mii_wbits(unsigned int ioaddr, unsigned data, int len)
415{
416 unsigned m = 1 << (len-1);
417 for (; m; m >>= 1)
418 mii_putbit(ioaddr, data & m);
419}
420
421static unsigned
422mii_rd(unsigned int ioaddr, u_char phyaddr, u_char phyreg)
423{
424 int i;
425 unsigned data=0, m;
426
427 SelectPage(2);
428 for (i=0; i < 32; i++) /* 32 bit preamble */
429 mii_putbit(ioaddr, 1);
430 mii_wbits(ioaddr, 0x06, 4); /* Start and opcode for read */
431 mii_wbits(ioaddr, phyaddr, 5); /* PHY address to be accessed */
432 mii_wbits(ioaddr, phyreg, 5); /* PHY register to read */
433 mii_idle(ioaddr); /* turn around */
434 mii_getbit(ioaddr);
435
436 for (m = 1<<15; m; m >>= 1)
437 if (mii_getbit(ioaddr))
438 data |= m;
439 mii_idle(ioaddr);
440 return data;
441}
442
443static void
444mii_wr(unsigned int ioaddr, u_char phyaddr, u_char phyreg, unsigned data,
445 int len)
446{
447 int i;
448
449 SelectPage(2);
450 for (i=0; i < 32; i++) /* 32 bit preamble */
451 mii_putbit(ioaddr, 1);
452 mii_wbits(ioaddr, 0x05, 4); /* Start and opcode for write */
453 mii_wbits(ioaddr, phyaddr, 5); /* PHY address to be accessed */
454 mii_wbits(ioaddr, phyreg, 5); /* PHY Register to write */
455 mii_putbit(ioaddr, 1); /* turn around */
456 mii_putbit(ioaddr, 0);
457 mii_wbits(ioaddr, data, len); /* And write the data */
458 mii_idle(ioaddr);
459}
460
461/*============= Main bulk of functions =========================*/
462
463static const struct net_device_ops netdev_ops = {
464 .ndo_open = do_open,
465 .ndo_stop = do_stop,
466 .ndo_start_xmit = do_start_xmit,
467 .ndo_tx_timeout = xirc_tx_timeout,
468 .ndo_set_config = do_config,
469 .ndo_do_ioctl = do_ioctl,
470 .ndo_set_multicast_list = set_multicast_list,
471 .ndo_change_mtu = eth_change_mtu,
472 .ndo_set_mac_address = eth_mac_addr,
473 .ndo_validate_addr = eth_validate_addr,
474};
475
476static int
477xirc2ps_probe(struct pcmcia_device *link)
478{
479 struct net_device *dev;
480 local_info_t *local;
481
482 dev_dbg(&link->dev, "attach()\n");
483
484 /* Allocate the device structure */
485 dev = alloc_etherdev(sizeof(local_info_t));
486 if (!dev)
487 return -ENOMEM;
488 local = netdev_priv(dev);
489 local->dev = dev;
490 local->p_dev = link;
491 link->priv = dev;
492
493 /* General socket configuration */
494 link->config_index = 1;
495
496 /* Fill in card specific entries */
497 dev->netdev_ops = &netdev_ops;
498 dev->ethtool_ops = &netdev_ethtool_ops;
499 dev->watchdog_timeo = TX_TIMEOUT;
500 INIT_WORK(&local->tx_timeout_task, xirc2ps_tx_timeout_task);
501
502 return xirc2ps_config(link);
503} /* xirc2ps_attach */
504
505static void
506xirc2ps_detach(struct pcmcia_device *link)
507{
508 struct net_device *dev = link->priv;
509
510 dev_dbg(&link->dev, "detach\n");
511
512 unregister_netdev(dev);
513
514 xirc2ps_release(link);
515
516 free_netdev(dev);
517} /* xirc2ps_detach */
518
519/****************
520 * Detect the type of the card. s is the buffer with the data of tuple 0x20
521 * Returns: 0 := not supported
522 * mediaid=11 and prodid=47
523 * Media-Id bits:
524 * Ethernet 0x01
525 * Tokenring 0x02
526 * Arcnet 0x04
527 * Wireless 0x08
528 * Modem 0x10
529 * GSM only 0x20
530 * Prod-Id bits:
531 * Pocket 0x10
532 * External 0x20
533 * Creditcard 0x40
534 * Cardbus 0x80
535 *
536 */
537static int
538set_card_type(struct pcmcia_device *link)
539{
540 struct net_device *dev = link->priv;
541 local_info_t *local = netdev_priv(dev);
542 u8 *buf;
543 unsigned int cisrev, mediaid, prodid;
544 size_t len;
545
546 len = pcmcia_get_tuple(link, CISTPL_MANFID, &buf);
547 if (len < 5) {
548 dev_err(&link->dev, "invalid CIS -- sorry\n");
549 return 0;
550 }
551
552 cisrev = buf[2];
553 mediaid = buf[3];
554 prodid = buf[4];
555
556 dev_dbg(&link->dev, "cisrev=%02x mediaid=%02x prodid=%02x\n",
557 cisrev, mediaid, prodid);
558
559 local->mohawk = 0;
560 local->dingo = 0;
561 local->modem = 0;
562 local->card_type = XIR_UNKNOWN;
563 if (!(prodid & 0x40)) {
564 pr_notice("Oops: Not a creditcard\n");
565 return 0;
566 }
567 if (!(mediaid & 0x01)) {
568 pr_notice("Not an Ethernet card\n");
569 return 0;
570 }
571 if (mediaid & 0x10) {
572 local->modem = 1;
573 switch(prodid & 15) {
574 case 1: local->card_type = XIR_CEM ; break;
575 case 2: local->card_type = XIR_CEM2 ; break;
576 case 3: local->card_type = XIR_CEM3 ; break;
577 case 4: local->card_type = XIR_CEM33 ; break;
578 case 5: local->card_type = XIR_CEM56M;
579 local->mohawk = 1;
580 break;
581 case 6:
582 case 7: /* 7 is the RealPort 10/56 */
583 local->card_type = XIR_CEM56 ;
584 local->mohawk = 1;
585 local->dingo = 1;
586 break;
587 }
588 } else {
589 switch(prodid & 15) {
590 case 1: local->card_type = has_ce2_string(link)? XIR_CE2 : XIR_CE ;
591 break;
592 case 2: local->card_type = XIR_CE2; break;
593 case 3: local->card_type = XIR_CE3;
594 local->mohawk = 1;
595 break;
596 }
597 }
598 if (local->card_type == XIR_CE || local->card_type == XIR_CEM) {
599 pr_notice("Sorry, this is an old CE card\n");
600 return 0;
601 }
602 if (local->card_type == XIR_UNKNOWN)
603 pr_notice("unknown card (mediaid=%02x prodid=%02x)\n", mediaid, prodid);
604
605 return 1;
606}
607
608/****************
609 * There are some CE2 cards out which claim to be a CE card.
610 * This function looks for a "CE2" in the 3rd version field.
611 * Returns: true if this is a CE2
612 */
613static int
614has_ce2_string(struct pcmcia_device * p_dev)
615{
616 if (p_dev->prod_id[2] && strstr(p_dev->prod_id[2], "CE2"))
617 return 1;
618 return 0;
619}
620
621static int
622xirc2ps_config_modem(struct pcmcia_device *p_dev, void *priv_data)
623{
624 unsigned int ioaddr;
625
626 if ((p_dev->resource[0]->start & 0xf) == 8)
627 return -ENODEV;
628
629 p_dev->resource[0]->end = 16;
630 p_dev->resource[1]->end = 8;
631 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
632 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_16;
633 p_dev->resource[1]->flags &= ~IO_DATA_PATH_WIDTH;
634 p_dev->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
635 p_dev->io_lines = 10;
636
637 p_dev->resource[1]->start = p_dev->resource[0]->start;
638 for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) {
639 p_dev->resource[0]->start = ioaddr;
640 if (!pcmcia_request_io(p_dev))
641 return 0;
642 }
643 return -ENODEV;
644}
645
646static int
647xirc2ps_config_check(struct pcmcia_device *p_dev, void *priv_data)
648{
649 int *pass = priv_data;
650 resource_size_t tmp = p_dev->resource[1]->start;
651
652 tmp += (*pass ? (p_dev->config_index & 0x20 ? -24 : 8)
653 : (p_dev->config_index & 0x20 ? 8 : -24));
654
655 if ((p_dev->resource[0]->start & 0xf) == 8)
656 return -ENODEV;
657
658 p_dev->resource[0]->end = 18;
659 p_dev->resource[1]->end = 8;
660 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
661 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_16;
662 p_dev->resource[1]->flags &= ~IO_DATA_PATH_WIDTH;
663 p_dev->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
664 p_dev->io_lines = 10;
665
666 p_dev->resource[1]->start = p_dev->resource[0]->start;
667 p_dev->resource[0]->start = tmp;
668 return pcmcia_request_io(p_dev);
669}
670
671
672static int pcmcia_get_mac_ce(struct pcmcia_device *p_dev,
673 tuple_t *tuple,
674 void *priv)
675{
676 struct net_device *dev = priv;
677 int i;
678
679 if (tuple->TupleDataLen != 13)
680 return -EINVAL;
681 if ((tuple->TupleData[0] != 2) || (tuple->TupleData[1] != 1) ||
682 (tuple->TupleData[2] != 6))
683 return -EINVAL;
684 /* another try (James Lehmer's CE2 version 4.1)*/
685 for (i = 2; i < 6; i++)
686 dev->dev_addr[i] = tuple->TupleData[i+2];
687 return 0;
688};
689
690
691static int
692xirc2ps_config(struct pcmcia_device * link)
693{
694 struct net_device *dev = link->priv;
695 local_info_t *local = netdev_priv(dev);
696 unsigned int ioaddr;
697 int err;
698 u8 *buf;
699 size_t len;
700
701 local->dingo_ccr = NULL;
702
703 dev_dbg(&link->dev, "config\n");
704
705 /* Is this a valid card */
706 if (link->has_manf_id == 0) {
707 pr_notice("manfid not found in CIS\n");
708 goto failure;
709 }
710
711 switch (link->manf_id) {
712 case MANFID_XIRCOM:
713 local->manf_str = "Xircom";
714 break;
715 case MANFID_ACCTON:
716 local->manf_str = "Accton";
717 break;
718 case MANFID_COMPAQ:
719 case MANFID_COMPAQ2:
720 local->manf_str = "Compaq";
721 break;
722 case MANFID_INTEL:
723 local->manf_str = "Intel";
724 break;
725 case MANFID_TOSHIBA:
726 local->manf_str = "Toshiba";
727 break;
728 default:
729 pr_notice("Unknown Card Manufacturer ID: 0x%04x\n",
730 (unsigned)link->manf_id);
731 goto failure;
732 }
733 dev_dbg(&link->dev, "found %s card\n", local->manf_str);
734
735 if (!set_card_type(link)) {
736 pr_notice("this card is not supported\n");
737 goto failure;
738 }
739
740 /* get the ethernet address from the CIS */
741 err = pcmcia_get_mac_from_cis(link, dev);
742
743 /* not found: try to get the node-id from tuple 0x89 */
744 if (err) {
745 len = pcmcia_get_tuple(link, 0x89, &buf);
746 /* data layout looks like tuple 0x22 */
747 if (buf && len == 8) {
748 if (*buf == CISTPL_FUNCE_LAN_NODE_ID) {
749 int i;
750 for (i = 2; i < 6; i++)
751 dev->dev_addr[i] = buf[i+2];
752 } else
753 err = -1;
754 }
755 kfree(buf);
756 }
757
758 if (err)
759 err = pcmcia_loop_tuple(link, CISTPL_FUNCE, pcmcia_get_mac_ce, dev);
760
761 if (err) {
762 pr_notice("node-id not found in CIS\n");
763 goto failure;
764 }
765
766 if (local->modem) {
767 int pass;
768 link->config_flags |= CONF_AUTO_SET_IO;
769
770 if (local->dingo) {
771 /* Take the Modem IO port from the CIS and scan for a free
772 * Ethernet port */
773 if (!pcmcia_loop_config(link, xirc2ps_config_modem, NULL))
774 goto port_found;
775 } else {
776 /* We do 2 passes here: The first one uses the regular mapping and
777 * the second tries again, thereby considering that the 32 ports are
778 * mirrored every 32 bytes. Actually we use a mirrored port for
779 * the Mako if (on the first pass) the COR bit 5 is set.
780 */
781 for (pass=0; pass < 2; pass++)
782 if (!pcmcia_loop_config(link, xirc2ps_config_check,
783 &pass))
784 goto port_found;
785 /* if special option:
786 * try to configure as Ethernet only.
787 * .... */
788 }
789 pr_notice("no ports available\n");
790 } else {
791 link->io_lines = 10;
792 link->resource[0]->end = 16;
793 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_16;
794 for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) {
795 link->resource[0]->start = ioaddr;
796 if (!(err = pcmcia_request_io(link)))
797 goto port_found;
798 }
799 link->resource[0]->start = 0; /* let CS decide */
800 if ((err = pcmcia_request_io(link)))
801 goto config_error;
802 }
803 port_found:
804 if (err)
805 goto config_error;
806
807 /****************
808 * Now allocate an interrupt line. Note that this does not
809 * actually assign a handler to the interrupt.
810 */
811 if ((err=pcmcia_request_irq(link, xirc2ps_interrupt)))
812 goto config_error;
813
814 link->config_flags |= CONF_ENABLE_IRQ;
815 if (do_sound)
816 link->config_flags |= CONF_ENABLE_SPKR;
817
818 if ((err = pcmcia_enable_device(link)))
819 goto config_error;
820
821 if (local->dingo) {
822 /* Reset the modem's BAR to the correct value
823 * This is necessary because in the RequestConfiguration call,
824 * the base address of the ethernet port (BasePort1) is written
825 * to the BAR registers of the modem.
826 */
827 err = pcmcia_write_config_byte(link, CISREG_IOBASE_0, (u8)
828 link->resource[1]->start & 0xff);
829 if (err)
830 goto config_error;
831
832 err = pcmcia_write_config_byte(link, CISREG_IOBASE_1,
833 (link->resource[1]->start >> 8) & 0xff);
834 if (err)
835 goto config_error;
836
837 /* There is no config entry for the Ethernet part which
838 * is at 0x0800. So we allocate a window into the attribute
839 * memory and write direct to the CIS registers
840 */
841 link->resource[2]->flags = WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_AM |
842 WIN_ENABLE;
843 link->resource[2]->start = link->resource[2]->end = 0;
844 if ((err = pcmcia_request_window(link, link->resource[2], 0)))
845 goto config_error;
846
847 local->dingo_ccr = ioremap(link->resource[2]->start, 0x1000) + 0x0800;
848 if ((err = pcmcia_map_mem_page(link, link->resource[2], 0)))
849 goto config_error;
850
851 /* Setup the CCRs; there are no infos in the CIS about the Ethernet
852 * part.
853 */
854 writeb(0x47, local->dingo_ccr + CISREG_COR);
855 ioaddr = link->resource[0]->start;
856 writeb(ioaddr & 0xff , local->dingo_ccr + CISREG_IOBASE_0);
857 writeb((ioaddr >> 8)&0xff , local->dingo_ccr + CISREG_IOBASE_1);
858
859 #if 0
860 {
861 u_char tmp;
862 pr_info("ECOR:");
863 for (i=0; i < 7; i++) {
864 tmp = readb(local->dingo_ccr + i*2);
865 pr_cont(" %02x", tmp);
866 }
867 pr_cont("\n");
868 pr_info("DCOR:");
869 for (i=0; i < 4; i++) {
870 tmp = readb(local->dingo_ccr + 0x20 + i*2);
871 pr_cont(" %02x", tmp);
872 }
873 pr_cont("\n");
874 pr_info("SCOR:");
875 for (i=0; i < 10; i++) {
876 tmp = readb(local->dingo_ccr + 0x40 + i*2);
877 pr_cont(" %02x", tmp);
878 }
879 pr_cont("\n");
880 }
881 #endif
882
883 writeb(0x01, local->dingo_ccr + 0x20);
884 writeb(0x0c, local->dingo_ccr + 0x22);
885 writeb(0x00, local->dingo_ccr + 0x24);
886 writeb(0x00, local->dingo_ccr + 0x26);
887 writeb(0x00, local->dingo_ccr + 0x28);
888 }
889
890 /* The if_port symbol can be set when the module is loaded */
891 local->probe_port=0;
892 if (!if_port) {
893 local->probe_port = dev->if_port = 1;
894 } else if ((if_port >= 1 && if_port <= 2) ||
895 (local->mohawk && if_port==4))
896 dev->if_port = if_port;
897 else
898 pr_notice("invalid if_port requested\n");
899
900 /* we can now register the device with the net subsystem */
901 dev->irq = link->irq;
902 dev->base_addr = link->resource[0]->start;
903
904 if (local->dingo)
905 do_reset(dev, 1); /* a kludge to make the cem56 work */
906
907 SET_NETDEV_DEV(dev, &link->dev);
908
909 if ((err=register_netdev(dev))) {
910 pr_notice("register_netdev() failed\n");
911 goto config_error;
912 }
913
914 /* give some infos about the hardware */
915 netdev_info(dev, "%s: port %#3lx, irq %d, hwaddr %pM\n",
916 local->manf_str, (u_long)dev->base_addr, (int)dev->irq,
917 dev->dev_addr);
918
919 return 0;
920
921 config_error:
922 xirc2ps_release(link);
923 return -ENODEV;
924
925 failure:
926 return -ENODEV;
927} /* xirc2ps_config */
928
929static void
930xirc2ps_release(struct pcmcia_device *link)
931{
932 dev_dbg(&link->dev, "release\n");
933
934 if (link->resource[2]->end) {
935 struct net_device *dev = link->priv;
936 local_info_t *local = netdev_priv(dev);
937 if (local->dingo)
938 iounmap(local->dingo_ccr - 0x0800);
939 }
940 pcmcia_disable_device(link);
941} /* xirc2ps_release */
942
943/*====================================================================*/
944
945
946static int xirc2ps_suspend(struct pcmcia_device *link)
947{
948 struct net_device *dev = link->priv;
949
950 if (link->open) {
951 netif_device_detach(dev);
952 do_powerdown(dev);
953 }
954
955 return 0;
956}
957
958static int xirc2ps_resume(struct pcmcia_device *link)
959{
960 struct net_device *dev = link->priv;
961
962 if (link->open) {
963 do_reset(dev,1);
964 netif_device_attach(dev);
965 }
966
967 return 0;
968}
969
970
971/*====================================================================*/
972
973/****************
974 * This is the Interrupt service route.
975 */
976static irqreturn_t
977xirc2ps_interrupt(int irq, void *dev_id)
978{
979 struct net_device *dev = (struct net_device *)dev_id;
980 local_info_t *lp = netdev_priv(dev);
981 unsigned int ioaddr;
982 u_char saved_page;
983 unsigned bytes_rcvd;
984 unsigned int_status, eth_status, rx_status, tx_status;
985 unsigned rsr, pktlen;
986 ulong start_ticks = jiffies; /* fixme: jiffies rollover every 497 days
987 * is this something to worry about?
988 * -- on a laptop?
989 */
990
991 if (!netif_device_present(dev))
992 return IRQ_HANDLED;
993
994 ioaddr = dev->base_addr;
995 if (lp->mohawk) { /* must disable the interrupt */
996 PutByte(XIRCREG_CR, 0);
997 }
998
999 pr_debug("%s: interrupt %d at %#x.\n", dev->name, irq, ioaddr);
1000
1001 saved_page = GetByte(XIRCREG_PR);
1002 /* Read the ISR to see whats the cause for the interrupt.
1003 * This also clears the interrupt flags on CE2 cards
1004 */
1005 int_status = GetByte(XIRCREG_ISR);
1006 bytes_rcvd = 0;
1007 loop_entry:
1008 if (int_status == 0xff) { /* card may be ejected */
1009 pr_debug("%s: interrupt %d for dead card\n", dev->name, irq);
1010 goto leave;
1011 }
1012 eth_status = GetByte(XIRCREG_ESR);
1013
1014 SelectPage(0x40);
1015 rx_status = GetByte(XIRCREG40_RXST0);
1016 PutByte(XIRCREG40_RXST0, (~rx_status & 0xff));
1017 tx_status = GetByte(XIRCREG40_TXST0);
1018 tx_status |= GetByte(XIRCREG40_TXST1) << 8;
1019 PutByte(XIRCREG40_TXST0, 0);
1020 PutByte(XIRCREG40_TXST1, 0);
1021
1022 pr_debug("%s: ISR=%#2.2x ESR=%#2.2x RSR=%#2.2x TSR=%#4.4x\n",
1023 dev->name, int_status, eth_status, rx_status, tx_status);
1024
1025 /***** receive section ******/
1026 SelectPage(0);
1027 while (eth_status & FullPktRcvd) {
1028 rsr = GetByte(XIRCREG0_RSR);
1029 if (bytes_rcvd > maxrx_bytes && (rsr & PktRxOk)) {
1030 /* too many bytes received during this int, drop the rest of the
1031 * packets */
1032 dev->stats.rx_dropped++;
1033 pr_debug("%s: RX drop, too much done\n", dev->name);
1034 } else if (rsr & PktRxOk) {
1035 struct sk_buff *skb;
1036
1037 pktlen = GetWord(XIRCREG0_RBC);
1038 bytes_rcvd += pktlen;
1039
1040 pr_debug("rsr=%#02x packet_length=%u\n", rsr, pktlen);
1041
1042 skb = dev_alloc_skb(pktlen+3); /* 1 extra so we can use insw */
1043 if (!skb) {
1044 pr_notice("low memory, packet dropped (size=%u)\n", pktlen);
1045 dev->stats.rx_dropped++;
1046 } else { /* okay get the packet */
1047 skb_reserve(skb, 2);
1048 if (lp->silicon == 0 ) { /* work around a hardware bug */
1049 unsigned rhsa; /* receive start address */
1050
1051 SelectPage(5);
1052 rhsa = GetWord(XIRCREG5_RHSA0);
1053 SelectPage(0);
1054 rhsa += 3; /* skip control infos */
1055 if (rhsa >= 0x8000)
1056 rhsa = 0;
1057 if (rhsa + pktlen > 0x8000) {
1058 unsigned i;
1059 u_char *buf = skb_put(skb, pktlen);
1060 for (i=0; i < pktlen ; i++, rhsa++) {
1061 buf[i] = GetByte(XIRCREG_EDP);
1062 if (rhsa == 0x8000) {
1063 rhsa = 0;
1064 i--;
1065 }
1066 }
1067 } else {
1068 insw(ioaddr+XIRCREG_EDP,
1069 skb_put(skb, pktlen), (pktlen+1)>>1);
1070 }
1071 }
1072 #if 0
1073 else if (lp->mohawk) {
1074 /* To use this 32 bit access we should use
1075 * a manual optimized loop
1076 * Also the words are swapped, we can get more
1077 * performance by using 32 bit access and swapping
1078 * the words in a register. Will need this for cardbus
1079 *
1080 * Note: don't forget to change the ALLOC_SKB to .. +3
1081 */
1082 unsigned i;
1083 u_long *p = skb_put(skb, pktlen);
1084 register u_long a;
1085 unsigned int edpreg = ioaddr+XIRCREG_EDP-2;
1086 for (i=0; i < len ; i += 4, p++) {
1087 a = inl(edpreg);
1088 __asm__("rorl $16,%0\n\t"
1089 :"=q" (a)
1090 : "0" (a));
1091 *p = a;
1092 }
1093 }
1094 #endif
1095 else {
1096 insw(ioaddr+XIRCREG_EDP, skb_put(skb, pktlen),
1097 (pktlen+1)>>1);
1098 }
1099 skb->protocol = eth_type_trans(skb, dev);
1100 netif_rx(skb);
1101 dev->stats.rx_packets++;
1102 dev->stats.rx_bytes += pktlen;
1103 if (!(rsr & PhyPkt))
1104 dev->stats.multicast++;
1105 }
1106 } else { /* bad packet */
1107 pr_debug("rsr=%#02x\n", rsr);
1108 }
1109 if (rsr & PktTooLong) {
1110 dev->stats.rx_frame_errors++;
1111 pr_debug("%s: Packet too long\n", dev->name);
1112 }
1113 if (rsr & CRCErr) {
1114 dev->stats.rx_crc_errors++;
1115 pr_debug("%s: CRC error\n", dev->name);
1116 }
1117 if (rsr & AlignErr) {
1118 dev->stats.rx_fifo_errors++; /* okay ? */
1119 pr_debug("%s: Alignment error\n", dev->name);
1120 }
1121
1122 /* clear the received/dropped/error packet */
1123 PutWord(XIRCREG0_DO, 0x8000); /* issue cmd: skip_rx_packet */
1124
1125 /* get the new ethernet status */
1126 eth_status = GetByte(XIRCREG_ESR);
1127 }
1128 if (rx_status & 0x10) { /* Receive overrun */
1129 dev->stats.rx_over_errors++;
1130 PutByte(XIRCREG_CR, ClearRxOvrun);
1131 pr_debug("receive overrun cleared\n");
1132 }
1133
1134 /***** transmit section ******/
1135 if (int_status & PktTxed) {
1136 unsigned n, nn;
1137
1138 n = lp->last_ptr_value;
1139 nn = GetByte(XIRCREG0_PTR);
1140 lp->last_ptr_value = nn;
1141 if (nn < n) /* rollover */
1142 dev->stats.tx_packets += 256 - n;
1143 else if (n == nn) { /* happens sometimes - don't know why */
1144 pr_debug("PTR not changed?\n");
1145 } else
1146 dev->stats.tx_packets += lp->last_ptr_value - n;
1147 netif_wake_queue(dev);
1148 }
1149 if (tx_status & 0x0002) { /* Execessive collissions */
1150 pr_debug("tx restarted due to execssive collissions\n");
1151 PutByte(XIRCREG_CR, RestartTx); /* restart transmitter process */
1152 }
1153 if (tx_status & 0x0040)
1154 dev->stats.tx_aborted_errors++;
1155
1156 /* recalculate our work chunk so that we limit the duration of this
1157 * ISR to about 1/10 of a second.
1158 * Calculate only if we received a reasonable amount of bytes.
1159 */
1160 if (bytes_rcvd > 1000) {
1161 u_long duration = jiffies - start_ticks;
1162
1163 if (duration >= HZ/10) { /* if more than about 1/10 second */
1164 maxrx_bytes = (bytes_rcvd * (HZ/10)) / duration;
1165 if (maxrx_bytes < 2000)
1166 maxrx_bytes = 2000;
1167 else if (maxrx_bytes > 22000)
1168 maxrx_bytes = 22000;
1169 pr_debug("set maxrx=%u (rcvd=%u ticks=%lu)\n",
1170 maxrx_bytes, bytes_rcvd, duration);
1171 } else if (!duration && maxrx_bytes < 22000) {
1172 /* now much faster */
1173 maxrx_bytes += 2000;
1174 if (maxrx_bytes > 22000)
1175 maxrx_bytes = 22000;
1176 pr_debug("set maxrx=%u\n", maxrx_bytes);
1177 }
1178 }
1179
1180 leave:
1181 if (lockup_hack) {
1182 if (int_status != 0xff && (int_status = GetByte(XIRCREG_ISR)) != 0)
1183 goto loop_entry;
1184 }
1185 SelectPage(saved_page);
1186 PutByte(XIRCREG_CR, EnableIntr); /* re-enable interrupts */
1187 /* Instead of dropping packets during a receive, we could
1188 * force an interrupt with this command:
1189 * PutByte(XIRCREG_CR, EnableIntr|ForceIntr);
1190 */
1191 return IRQ_HANDLED;
1192} /* xirc2ps_interrupt */
1193
1194/*====================================================================*/
1195
1196static void
1197xirc2ps_tx_timeout_task(struct work_struct *work)
1198{
1199 local_info_t *local =
1200 container_of(work, local_info_t, tx_timeout_task);
1201 struct net_device *dev = local->dev;
1202 /* reset the card */
1203 do_reset(dev,1);
1204 dev->trans_start = jiffies; /* prevent tx timeout */
1205 netif_wake_queue(dev);
1206}
1207
1208static void
1209xirc_tx_timeout(struct net_device *dev)
1210{
1211 local_info_t *lp = netdev_priv(dev);
1212 dev->stats.tx_errors++;
1213 netdev_notice(dev, "transmit timed out\n");
1214 schedule_work(&lp->tx_timeout_task);
1215}
1216
1217static netdev_tx_t
1218do_start_xmit(struct sk_buff *skb, struct net_device *dev)
1219{
1220 local_info_t *lp = netdev_priv(dev);
1221 unsigned int ioaddr = dev->base_addr;
1222 int okay;
1223 unsigned freespace;
1224 unsigned pktlen = skb->len;
1225
1226 pr_debug("do_start_xmit(skb=%p, dev=%p) len=%u\n",
1227 skb, dev, pktlen);
1228
1229
1230 /* adjust the packet length to min. required
1231 * and hope that the buffer is large enough
1232 * to provide some random data.
1233 * fixme: For Mohawk we can change this by sending
1234 * a larger packetlen than we actually have; the chip will
1235 * pad this in his buffer with random bytes
1236 */
1237 if (pktlen < ETH_ZLEN)
1238 {
1239 if (skb_padto(skb, ETH_ZLEN))
1240 return NETDEV_TX_OK;
1241 pktlen = ETH_ZLEN;
1242 }
1243
1244 netif_stop_queue(dev);
1245 SelectPage(0);
1246 PutWord(XIRCREG0_TRS, (u_short)pktlen+2);
1247 freespace = GetWord(XIRCREG0_TSO);
1248 okay = freespace & 0x8000;
1249 freespace &= 0x7fff;
1250 /* TRS doesn't work - (indeed it is eliminated with sil-rev 1) */
1251 okay = pktlen +2 < freespace;
1252 pr_debug("%s: avail. tx space=%u%s\n",
1253 dev->name, freespace, okay ? " (okay)":" (not enough)");
1254 if (!okay) { /* not enough space */
1255 return NETDEV_TX_BUSY; /* upper layer may decide to requeue this packet */
1256 }
1257 /* send the packet */
1258 PutWord(XIRCREG_EDP, (u_short)pktlen);
1259 outsw(ioaddr+XIRCREG_EDP, skb->data, pktlen>>1);
1260 if (pktlen & 1)
1261 PutByte(XIRCREG_EDP, skb->data[pktlen-1]);
1262
1263 if (lp->mohawk)
1264 PutByte(XIRCREG_CR, TransmitPacket|EnableIntr);
1265
1266 dev_kfree_skb (skb);
1267 dev->stats.tx_bytes += pktlen;
1268 netif_start_queue(dev);
1269 return NETDEV_TX_OK;
1270}
1271
1272struct set_address_info {
1273 int reg_nr;
1274 int page_nr;
1275 int mohawk;
1276 unsigned int ioaddr;
1277};
1278
1279static void set_address(struct set_address_info *sa_info, char *addr)
1280{
1281 unsigned int ioaddr = sa_info->ioaddr;
1282 int i;
1283
1284 for (i = 0; i < 6; i++) {
1285 if (sa_info->reg_nr > 15) {
1286 sa_info->reg_nr = 8;
1287 sa_info->page_nr++;
1288 SelectPage(sa_info->page_nr);
1289 }
1290 if (sa_info->mohawk)
1291 PutByte(sa_info->reg_nr++, addr[5 - i]);
1292 else
1293 PutByte(sa_info->reg_nr++, addr[i]);
1294 }
1295}
1296
1297/****************
1298 * Set all addresses: This first one is the individual address,
1299 * the next 9 addresses are taken from the multicast list and
1300 * the rest is filled with the individual address.
1301 */
1302static void set_addresses(struct net_device *dev)
1303{
1304 unsigned int ioaddr = dev->base_addr;
1305 local_info_t *lp = netdev_priv(dev);
1306 struct netdev_hw_addr *ha;
1307 struct set_address_info sa_info;
1308 int i;
1309
1310 /*
1311 * Setup the info structure so that by first set_address call it will do
1312 * SelectPage with the right page number. Hence these ones here.
1313 */
1314 sa_info.reg_nr = 15 + 1;
1315 sa_info.page_nr = 0x50 - 1;
1316 sa_info.mohawk = lp->mohawk;
1317 sa_info.ioaddr = ioaddr;
1318
1319 set_address(&sa_info, dev->dev_addr);
1320 i = 0;
1321 netdev_for_each_mc_addr(ha, dev) {
1322 if (i++ == 9)
1323 break;
1324 set_address(&sa_info, ha->addr);
1325 }
1326 while (i++ < 9)
1327 set_address(&sa_info, dev->dev_addr);
1328 SelectPage(0);
1329}
1330
1331/****************
1332 * Set or clear the multicast filter for this adaptor.
1333 * We can filter up to 9 addresses, if more are requested we set
1334 * multicast promiscuous mode.
1335 */
1336
1337static void
1338set_multicast_list(struct net_device *dev)
1339{
1340 unsigned int ioaddr = dev->base_addr;
1341 unsigned value;
1342
1343 SelectPage(0x42);
1344 value = GetByte(XIRCREG42_SWC1) & 0xC0;
1345
1346 if (dev->flags & IFF_PROMISC) { /* snoop */
1347 PutByte(XIRCREG42_SWC1, value | 0x06); /* set MPE and PME */
1348 } else if (netdev_mc_count(dev) > 9 || (dev->flags & IFF_ALLMULTI)) {
1349 PutByte(XIRCREG42_SWC1, value | 0x02); /* set MPE */
1350 } else if (!netdev_mc_empty(dev)) {
1351 /* the chip can filter 9 addresses perfectly */
1352 PutByte(XIRCREG42_SWC1, value | 0x01);
1353 SelectPage(0x40);
1354 PutByte(XIRCREG40_CMD0, Offline);
1355 set_addresses(dev);
1356 SelectPage(0x40);
1357 PutByte(XIRCREG40_CMD0, EnableRecv | Online);
1358 } else { /* standard usage */
1359 PutByte(XIRCREG42_SWC1, value | 0x00);
1360 }
1361 SelectPage(0);
1362}
1363
1364static int
1365do_config(struct net_device *dev, struct ifmap *map)
1366{
1367 local_info_t *local = netdev_priv(dev);
1368
1369 pr_debug("do_config(%p)\n", dev);
1370 if (map->port != 255 && map->port != dev->if_port) {
1371 if (map->port > 4)
1372 return -EINVAL;
1373 if (!map->port) {
1374 local->probe_port = 1;
1375 dev->if_port = 1;
1376 } else {
1377 local->probe_port = 0;
1378 dev->if_port = map->port;
1379 }
1380 netdev_info(dev, "switching to %s port\n", if_names[dev->if_port]);
1381 do_reset(dev,1); /* not the fine way :-) */
1382 }
1383 return 0;
1384}
1385
1386/****************
1387 * Open the driver
1388 */
1389static int
1390do_open(struct net_device *dev)
1391{
1392 local_info_t *lp = netdev_priv(dev);
1393 struct pcmcia_device *link = lp->p_dev;
1394
1395 dev_dbg(&link->dev, "do_open(%p)\n", dev);
1396
1397 /* Check that the PCMCIA card is still here. */
1398 /* Physical device present signature. */
1399 if (!pcmcia_dev_present(link))
1400 return -ENODEV;
1401
1402 /* okay */
1403 link->open++;
1404
1405 netif_start_queue(dev);
1406 do_reset(dev,1);
1407
1408 return 0;
1409}
1410
1411static void netdev_get_drvinfo(struct net_device *dev,
1412 struct ethtool_drvinfo *info)
1413{
1414 strcpy(info->driver, "xirc2ps_cs");
1415 sprintf(info->bus_info, "PCMCIA 0x%lx", dev->base_addr);
1416}
1417
1418static const struct ethtool_ops netdev_ethtool_ops = {
1419 .get_drvinfo = netdev_get_drvinfo,
1420};
1421
1422static int
1423do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1424{
1425 local_info_t *local = netdev_priv(dev);
1426 unsigned int ioaddr = dev->base_addr;
1427 struct mii_ioctl_data *data = if_mii(rq);
1428
1429 pr_debug("%s: ioctl(%-.6s, %#04x) %04x %04x %04x %04x\n",
1430 dev->name, rq->ifr_ifrn.ifrn_name, cmd,
1431 data->phy_id, data->reg_num, data->val_in, data->val_out);
1432
1433 if (!local->mohawk)
1434 return -EOPNOTSUPP;
1435
1436 switch(cmd) {
1437 case SIOCGMIIPHY: /* Get the address of the PHY in use. */
1438 data->phy_id = 0; /* we have only this address */
1439 /* fall through */
1440 case SIOCGMIIREG: /* Read the specified MII register. */
1441 data->val_out = mii_rd(ioaddr, data->phy_id & 0x1f,
1442 data->reg_num & 0x1f);
1443 break;
1444 case SIOCSMIIREG: /* Write the specified MII register */
1445 mii_wr(ioaddr, data->phy_id & 0x1f, data->reg_num & 0x1f, data->val_in,
1446 16);
1447 break;
1448 default:
1449 return -EOPNOTSUPP;
1450 }
1451 return 0;
1452}
1453
1454static void
1455hardreset(struct net_device *dev)
1456{
1457 local_info_t *local = netdev_priv(dev);
1458 unsigned int ioaddr = dev->base_addr;
1459
1460 SelectPage(4);
1461 udelay(1);
1462 PutByte(XIRCREG4_GPR1, 0); /* clear bit 0: power down */
1463 msleep(40); /* wait 40 msec */
1464 if (local->mohawk)
1465 PutByte(XIRCREG4_GPR1, 1); /* set bit 0: power up */
1466 else
1467 PutByte(XIRCREG4_GPR1, 1 | 4); /* set bit 0: power up, bit 2: AIC */
1468 msleep(20); /* wait 20 msec */
1469}
1470
1471static void
1472do_reset(struct net_device *dev, int full)
1473{
1474 local_info_t *local = netdev_priv(dev);
1475 unsigned int ioaddr = dev->base_addr;
1476 unsigned value;
1477
1478 pr_debug("%s: do_reset(%p,%d)\n", dev? dev->name:"eth?", dev, full);
1479
1480 hardreset(dev);
1481 PutByte(XIRCREG_CR, SoftReset); /* set */
1482 msleep(20); /* wait 20 msec */
1483 PutByte(XIRCREG_CR, 0); /* clear */
1484 msleep(40); /* wait 40 msec */
1485 if (local->mohawk) {
1486 SelectPage(4);
1487 /* set pin GP1 and GP2 to output (0x0c)
1488 * set GP1 to low to power up the ML6692 (0x00)
1489 * set GP2 to high to power up the 10Mhz chip (0x02)
1490 */
1491 PutByte(XIRCREG4_GPR0, 0x0e);
1492 }
1493
1494 /* give the circuits some time to power up */
1495 msleep(500); /* about 500ms */
1496
1497 local->last_ptr_value = 0;
1498 local->silicon = local->mohawk ? (GetByte(XIRCREG4_BOV) & 0x70) >> 4
1499 : (GetByte(XIRCREG4_BOV) & 0x30) >> 4;
1500
1501 if (local->probe_port) {
1502 if (!local->mohawk) {
1503 SelectPage(4);
1504 PutByte(XIRCREG4_GPR0, 4);
1505 local->probe_port = 0;
1506 }
1507 } else if (dev->if_port == 2) { /* enable 10Base2 */
1508 SelectPage(0x42);
1509 PutByte(XIRCREG42_SWC1, 0xC0);
1510 } else { /* enable 10BaseT */
1511 SelectPage(0x42);
1512 PutByte(XIRCREG42_SWC1, 0x80);
1513 }
1514 msleep(40); /* wait 40 msec to let it complete */
1515
1516 #if 0
1517 {
1518 SelectPage(0);
1519 value = GetByte(XIRCREG_ESR); /* read the ESR */
1520 pr_debug("%s: ESR is: %#02x\n", dev->name, value);
1521 }
1522 #endif
1523
1524 /* setup the ECR */
1525 SelectPage(1);
1526 PutByte(XIRCREG1_IMR0, 0xff); /* allow all ints */
1527 PutByte(XIRCREG1_IMR1, 1 ); /* and Set TxUnderrunDetect */
1528 value = GetByte(XIRCREG1_ECR);
1529 #if 0
1530 if (local->mohawk)
1531 value |= DisableLinkPulse;
1532 PutByte(XIRCREG1_ECR, value);
1533 #endif
1534 pr_debug("%s: ECR is: %#02x\n", dev->name, value);
1535
1536 SelectPage(0x42);
1537 PutByte(XIRCREG42_SWC0, 0x20); /* disable source insertion */
1538
1539 if (local->silicon != 1) {
1540 /* set the local memory dividing line.
1541 * The comments in the sample code say that this is only
1542 * settable with the scipper version 2 which is revision 0.
1543 * Always for CE3 cards
1544 */
1545 SelectPage(2);
1546 PutWord(XIRCREG2_RBS, 0x2000);
1547 }
1548
1549 if (full)
1550 set_addresses(dev);
1551
1552 /* Hardware workaround:
1553 * The receive byte pointer after reset is off by 1 so we need
1554 * to move the offset pointer back to 0.
1555 */
1556 SelectPage(0);
1557 PutWord(XIRCREG0_DO, 0x2000); /* change offset command, off=0 */
1558
1559 /* setup MAC IMRs and clear status registers */
1560 SelectPage(0x40); /* Bit 7 ... bit 0 */
1561 PutByte(XIRCREG40_RMASK0, 0xff); /* ROK, RAB, rsv, RO, CRC, AE, PTL, MP */
1562 PutByte(XIRCREG40_TMASK0, 0xff); /* TOK, TAB, SQE, LL, TU, JAB, EXC, CRS */
1563 PutByte(XIRCREG40_TMASK1, 0xb0); /* rsv, rsv, PTD, EXT, rsv,rsv,rsv, rsv*/
1564 PutByte(XIRCREG40_RXST0, 0x00); /* ROK, RAB, REN, RO, CRC, AE, PTL, MP */
1565 PutByte(XIRCREG40_TXST0, 0x00); /* TOK, TAB, SQE, LL, TU, JAB, EXC, CRS */
1566 PutByte(XIRCREG40_TXST1, 0x00); /* TEN, rsv, PTD, EXT, retry_counter:4 */
1567
1568 if (full && local->mohawk && init_mii(dev)) {
1569 if (dev->if_port == 4 || local->dingo || local->new_mii) {
1570 netdev_info(dev, "MII selected\n");
1571 SelectPage(2);
1572 PutByte(XIRCREG2_MSR, GetByte(XIRCREG2_MSR) | 0x08);
1573 msleep(20);
1574 } else {
1575 netdev_info(dev, "MII detected; using 10mbs\n");
1576 SelectPage(0x42);
1577 if (dev->if_port == 2) /* enable 10Base2 */
1578 PutByte(XIRCREG42_SWC1, 0xC0);
1579 else /* enable 10BaseT */
1580 PutByte(XIRCREG42_SWC1, 0x80);
1581 msleep(40); /* wait 40 msec to let it complete */
1582 }
1583 if (full_duplex)
1584 PutByte(XIRCREG1_ECR, GetByte(XIRCREG1_ECR | FullDuplex));
1585 } else { /* No MII */
1586 SelectPage(0);
1587 value = GetByte(XIRCREG_ESR); /* read the ESR */
1588 dev->if_port = (value & MediaSelect) ? 1 : 2;
1589 }
1590
1591 /* configure the LEDs */
1592 SelectPage(2);
1593 if (dev->if_port == 1 || dev->if_port == 4) /* TP: Link and Activity */
1594 PutByte(XIRCREG2_LED, 0x3b);
1595 else /* Coax: Not-Collision and Activity */
1596 PutByte(XIRCREG2_LED, 0x3a);
1597
1598 if (local->dingo)
1599 PutByte(0x0b, 0x04); /* 100 Mbit LED */
1600
1601 /* enable receiver and put the mac online */
1602 if (full) {
1603 set_multicast_list(dev);
1604 SelectPage(0x40);
1605 PutByte(XIRCREG40_CMD0, EnableRecv | Online);
1606 }
1607
1608 /* setup Ethernet IMR and enable interrupts */
1609 SelectPage(1);
1610 PutByte(XIRCREG1_IMR0, 0xff);
1611 udelay(1);
1612 SelectPage(0);
1613 PutByte(XIRCREG_CR, EnableIntr);
1614 if (local->modem && !local->dingo) { /* do some magic */
1615 if (!(GetByte(0x10) & 0x01))
1616 PutByte(0x10, 0x11); /* unmask master-int bit */
1617 }
1618
1619 if (full)
1620 netdev_info(dev, "media %s, silicon revision %d\n",
1621 if_names[dev->if_port], local->silicon);
1622 /* We should switch back to page 0 to avoid a bug in revision 0
1623 * where regs with offset below 8 can't be read after an access
1624 * to the MAC registers */
1625 SelectPage(0);
1626}
1627
1628/****************
1629 * Initialize the Media-Independent-Interface
1630 * Returns: True if we have a good MII
1631 */
1632static int
1633init_mii(struct net_device *dev)
1634{
1635 local_info_t *local = netdev_priv(dev);
1636 unsigned int ioaddr = dev->base_addr;
1637 unsigned control, status, linkpartner;
1638 int i;
1639
1640 if (if_port == 4 || if_port == 1) { /* force 100BaseT or 10BaseT */
1641 dev->if_port = if_port;
1642 local->probe_port = 0;
1643 return 1;
1644 }
1645
1646 status = mii_rd(ioaddr, 0, 1);
1647 if ((status & 0xff00) != 0x7800)
1648 return 0; /* No MII */
1649
1650 local->new_mii = (mii_rd(ioaddr, 0, 2) != 0xffff);
1651
1652 if (local->probe_port)
1653 control = 0x1000; /* auto neg */
1654 else if (dev->if_port == 4)
1655 control = 0x2000; /* no auto neg, 100mbs mode */
1656 else
1657 control = 0x0000; /* no auto neg, 10mbs mode */
1658 mii_wr(ioaddr, 0, 0, control, 16);
1659 udelay(100);
1660 control = mii_rd(ioaddr, 0, 0);
1661
1662 if (control & 0x0400) {
1663 netdev_notice(dev, "can't take PHY out of isolation mode\n");
1664 local->probe_port = 0;
1665 return 0;
1666 }
1667
1668 if (local->probe_port) {
1669 /* according to the DP83840A specs the auto negotiation process
1670 * may take up to 3.5 sec, so we use this also for our ML6692
1671 * Fixme: Better to use a timer here!
1672 */
1673 for (i=0; i < 35; i++) {
1674 msleep(100); /* wait 100 msec */
1675 status = mii_rd(ioaddr, 0, 1);
1676 if ((status & 0x0020) && (status & 0x0004))
1677 break;
1678 }
1679
1680 if (!(status & 0x0020)) {
1681 netdev_info(dev, "autonegotiation failed; using 10mbs\n");
1682 if (!local->new_mii) {
1683 control = 0x0000;
1684 mii_wr(ioaddr, 0, 0, control, 16);
1685 udelay(100);
1686 SelectPage(0);
1687 dev->if_port = (GetByte(XIRCREG_ESR) & MediaSelect) ? 1 : 2;
1688 }
1689 } else {
1690 linkpartner = mii_rd(ioaddr, 0, 5);
1691 netdev_info(dev, "MII link partner: %04x\n", linkpartner);
1692 if (linkpartner & 0x0080) {
1693 dev->if_port = 4;
1694 } else
1695 dev->if_port = 1;
1696 }
1697 }
1698
1699 return 1;
1700}
1701
1702static void
1703do_powerdown(struct net_device *dev)
1704{
1705
1706 unsigned int ioaddr = dev->base_addr;
1707
1708 pr_debug("do_powerdown(%p)\n", dev);
1709
1710 SelectPage(4);
1711 PutByte(XIRCREG4_GPR1, 0); /* clear bit 0: power down */
1712 SelectPage(0);
1713}
1714
1715static int
1716do_stop(struct net_device *dev)
1717{
1718 unsigned int ioaddr = dev->base_addr;
1719 local_info_t *lp = netdev_priv(dev);
1720 struct pcmcia_device *link = lp->p_dev;
1721
1722 dev_dbg(&link->dev, "do_stop(%p)\n", dev);
1723
1724 if (!link)
1725 return -ENODEV;
1726
1727 netif_stop_queue(dev);
1728
1729 SelectPage(0);
1730 PutByte(XIRCREG_CR, 0); /* disable interrupts */
1731 SelectPage(0x01);
1732 PutByte(XIRCREG1_IMR0, 0x00); /* forbid all ints */
1733 SelectPage(4);
1734 PutByte(XIRCREG4_GPR1, 0); /* clear bit 0: power down */
1735 SelectPage(0);
1736
1737 link->open--;
1738 return 0;
1739}
1740
1741static const struct pcmcia_device_id xirc2ps_ids[] = {
1742 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0089, 0x110a),
1743 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0138, 0x110a),
1744 PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "CEM28", 0x2e3ee845, 0x0ea978ea),
1745 PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "CEM33", 0x2e3ee845, 0x80609023),
1746 PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "CEM56", 0x2e3ee845, 0xa650c32a),
1747 PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "REM10", 0x2e3ee845, 0x76df1d29),
1748 PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "XEM5600", 0x2e3ee845, 0xf1403719),
1749 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Xircom", "CreditCard Ethernet+Modem II", 0x2e3ee845, 0xeca401bf),
1750 PCMCIA_DEVICE_MANF_CARD(0x01bf, 0x010a),
1751 PCMCIA_DEVICE_PROD_ID13("Toshiba Information Systems", "TPCENET", 0x1b3b94fe, 0xf381c1a2),
1752 PCMCIA_DEVICE_PROD_ID13("Xircom", "CE3-10/100", 0x2e3ee845, 0x0ec0ac37),
1753 PCMCIA_DEVICE_PROD_ID13("Xircom", "PS-CE2-10", 0x2e3ee845, 0x947d9073),
1754 PCMCIA_DEVICE_PROD_ID13("Xircom", "R2E-100BTX", 0x2e3ee845, 0x2464a6e3),
1755 PCMCIA_DEVICE_PROD_ID13("Xircom", "RE-10", 0x2e3ee845, 0x3e08d609),
1756 PCMCIA_DEVICE_PROD_ID13("Xircom", "XE2000", 0x2e3ee845, 0xf7188e46),
1757 PCMCIA_DEVICE_PROD_ID12("Compaq", "Ethernet LAN Card", 0x54f7c49c, 0x9fd2f0a2),
1758 PCMCIA_DEVICE_PROD_ID12("Compaq", "Netelligent 10/100 PC Card", 0x54f7c49c, 0xefe96769),
1759 PCMCIA_DEVICE_PROD_ID12("Intel", "EtherExpress(TM) PRO/100 PC Card Mobile Adapter16", 0x816cc815, 0x174397db),
1760 PCMCIA_DEVICE_PROD_ID12("Toshiba", "10/100 Ethernet PC Card", 0x44a09d9c, 0xb44deecf),
1761 /* also matches CFE-10 cards! */
1762 /* PCMCIA_DEVICE_MANF_CARD(0x0105, 0x010a), */
1763 PCMCIA_DEVICE_NULL,
1764};
1765MODULE_DEVICE_TABLE(pcmcia, xirc2ps_ids);
1766
1767
1768static struct pcmcia_driver xirc2ps_cs_driver = {
1769 .owner = THIS_MODULE,
1770 .name = "xirc2ps_cs",
1771 .probe = xirc2ps_probe,
1772 .remove = xirc2ps_detach,
1773 .id_table = xirc2ps_ids,
1774 .suspend = xirc2ps_suspend,
1775 .resume = xirc2ps_resume,
1776};
1777
1778static int __init
1779init_xirc2ps_cs(void)
1780{
1781 return pcmcia_register_driver(&xirc2ps_cs_driver);
1782}
1783
1784static void __exit
1785exit_xirc2ps_cs(void)
1786{
1787 pcmcia_unregister_driver(&xirc2ps_cs_driver);
1788}
1789
1790module_init(init_xirc2ps_cs);
1791module_exit(exit_xirc2ps_cs);
1792
1793#ifndef MODULE
1794static int __init setup_xirc2ps_cs(char *str)
1795{
1796 /* if_port, full_duplex, do_sound, lockup_hack
1797 */
1798 int ints[10] = { -1 };
1799
1800 str = get_options(str, 9, ints);
1801
1802#define MAYBE_SET(X,Y) if (ints[0] >= Y && ints[Y] != -1) { X = ints[Y]; }
1803 MAYBE_SET(if_port, 3);
1804 MAYBE_SET(full_duplex, 4);
1805 MAYBE_SET(do_sound, 5);
1806 MAYBE_SET(lockup_hack, 6);
1807#undef MAYBE_SET
1808
1809 return 1;
1810}
1811
1812__setup("xirc2ps_cs=", setup_xirc2ps_cs);
1813#endif