1 /*======================================================================
3 A PCMCIA ethernet driver for NS8390-based cards
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.
12 Copyright (C) 1999 David A. Hinds -- dahinds@users.sourceforge.net
14 pcnet_cs.c 1.153 2003/11/09 18:53:09
16 The network driver code is based on Donald Becker's NE2000 code:
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
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.
29 ======================================================================*/
31 #include <linux/kernel.h>
32 #include <linux/module.h>
33 #include <linux/init.h>
34 #include <linux/ptrace.h>
35 #include <linux/slab.h>
36 #include <linux/string.h>
37 #include <linux/timer.h>
38 #include <linux/delay.h>
39 #include <linux/ethtool.h>
40 #include <linux/netdevice.h>
41 #include <../drivers/net/8390.h>
43 #include <pcmcia/version.h>
44 #include <pcmcia/cs_types.h>
45 #include <pcmcia/cs.h>
46 #include <pcmcia/cistpl.h>
47 #include <pcmcia/ciscode.h>
48 #include <pcmcia/ds.h>
49 #include <pcmcia/cisreg.h>
52 #include <asm/system.h>
53 #include <asm/byteorder.h>
54 #include <asm/uaccess.h>
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 */
61 #define PCNET_START_PG 0x40 /* First page of TX buffer */
62 #define PCNET_STOP_PG 0x80 /* Last page +1 of RX ring */
64 /* Socket EA cards have a larger packet buffer */
65 #define SOCKET_START_PG 0x01
66 #define SOCKET_STOP_PG 0xff
68 #define PCNET_RDC_TIMEOUT (2*HZ/100) /* Max wait in jiffies for Tx RDC */
70 static char *if_names[] = { "auto", "10baseT", "10base2"};
73 static int pc_debug = PCMCIA_DEBUG;
74 MODULE_PARM(pc_debug, "i");
75 #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
76 static char *version =
77 "pcnet_cs.c 1.153 2003/11/09 18:53:09 (David Hinds)";
79 #define DEBUG(n, args...)
82 /*====================================================================*/
84 /* Module parameters */
86 MODULE_AUTHOR("David Hinds <dahinds@users.sourceforge.net>");
87 MODULE_DESCRIPTION("NE2000 compatible PCMCIA ethernet driver");
88 MODULE_LICENSE("GPL");
90 #define INT_MODULE_PARM(n, v) static int n = v; MODULE_PARM(n, "i")
92 /* Bit map of interrupts to choose from */
93 INT_MODULE_PARM(irq_mask, 0xdeb8);
94 static int irq_list[4] = { -1 };
95 MODULE_PARM(irq_list, "1-4i");
97 INT_MODULE_PARM(if_port, 1); /* Transceiver type */
98 INT_MODULE_PARM(use_big_buf, 1); /* use 64K packet buffer? */
99 INT_MODULE_PARM(mem_speed, 0); /* shared mem speed, in ns */
100 INT_MODULE_PARM(delay_output, 0); /* pause after xmit? */
101 INT_MODULE_PARM(delay_time, 4); /* in usec */
102 INT_MODULE_PARM(use_shmem, -1); /* use shared memory? */
103 INT_MODULE_PARM(full_duplex, 0); /* full duplex? */
105 /* Ugh! Let the user hardwire the hardware address for queer cards */
106 static int hw_addr[6] = { 0, /* ... */ };
107 MODULE_PARM(hw_addr, "6i");
109 /*====================================================================*/
111 static void mii_phy_probe(struct net_device *dev);
112 static void pcnet_config(dev_link_t *link);
113 static void pcnet_release(dev_link_t *link);
114 static int pcnet_event(event_t event, int priority,
115 event_callback_args_t *args);
116 static int pcnet_open(struct net_device *dev);
117 static int pcnet_close(struct net_device *dev);
118 static int ei_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
119 static struct ethtool_ops netdev_ethtool_ops;
120 static irqreturn_t ei_irq_wrapper(int irq, void *dev_id, struct pt_regs *regs);
121 static void ei_watchdog(u_long arg);
122 static void pcnet_reset_8390(struct net_device *dev);
123 static int set_config(struct net_device *dev, struct ifmap *map);
124 static int setup_shmem_window(dev_link_t *link, int start_pg,
125 int stop_pg, int cm_offset);
126 static int setup_dma_config(dev_link_t *link, int start_pg,
129 static dev_link_t *pcnet_attach(void);
130 static void pcnet_detach(dev_link_t *);
132 static dev_info_t dev_info = "pcnet_cs";
133 static dev_link_t *dev_list;
135 /*====================================================================*/
137 typedef struct hw_info_t {
143 #define DELAY_OUTPUT 0x01
144 #define HAS_MISC_REG 0x02
145 #define USE_BIG_BUF 0x04
146 #define HAS_IBM_MISC 0x08
147 #define IS_DL10019 0x10
148 #define IS_DL10022 0x20
150 #define USE_SHMEM 0x80 /* autodetected */
152 #define AM79C9XX_HOME_PHY 0x00006B90 /* HomePNA PHY */
153 #define AM79C9XX_ETH_PHY 0x00006B70 /* 10baseT PHY */
154 #define MII_PHYID_REV_MASK 0xfffffff0
155 #define MII_PHYID_REG1 0x02
156 #define MII_PHYID_REG2 0x03
158 static hw_info_t hw_info[] = {
159 { /* Accton EN2212 */ 0x0ff0, 0x00, 0x00, 0xe8, DELAY_OUTPUT },
160 { /* Allied Telesis LA-PCM */ 0x0ff0, 0x00, 0x00, 0xf4, 0 },
161 { /* APEX MultiCard */ 0x03f4, 0x00, 0x20, 0xe5, 0 },
162 { /* ASANTE FriendlyNet */ 0x4910, 0x00, 0x00, 0x94,
163 DELAY_OUTPUT | HAS_IBM_MISC },
164 { /* Danpex EN-6200P2 */ 0x0110, 0x00, 0x40, 0xc7, 0 },
165 { /* DataTrek NetCard */ 0x0ff0, 0x00, 0x20, 0xe8, 0 },
166 { /* Dayna CommuniCard E */ 0x0110, 0x00, 0x80, 0x19, 0 },
167 { /* D-Link DE-650 */ 0x0040, 0x00, 0x80, 0xc8, 0 },
168 { /* EP-210 Ethernet */ 0x0110, 0x00, 0x40, 0x33, 0 },
169 { /* EP4000 Ethernet */ 0x01c0, 0x00, 0x00, 0xb4, 0 },
170 { /* Epson EEN10B */ 0x0ff0, 0x00, 0x00, 0x48,
171 HAS_MISC_REG | HAS_IBM_MISC },
172 { /* ELECOM Laneed LD-CDWA */ 0xb8, 0x08, 0x00, 0x42, 0 },
173 { /* Hypertec Ethernet */ 0x01c0, 0x00, 0x40, 0x4c, 0 },
174 { /* IBM CCAE */ 0x0ff0, 0x08, 0x00, 0x5a,
175 HAS_MISC_REG | HAS_IBM_MISC },
176 { /* IBM CCAE */ 0x0ff0, 0x00, 0x04, 0xac,
177 HAS_MISC_REG | HAS_IBM_MISC },
178 { /* IBM CCAE */ 0x0ff0, 0x00, 0x06, 0x29,
179 HAS_MISC_REG | HAS_IBM_MISC },
180 { /* IBM FME */ 0x0374, 0x08, 0x00, 0x5a,
181 HAS_MISC_REG | HAS_IBM_MISC },
182 { /* IBM FME */ 0x0374, 0x00, 0x04, 0xac,
183 HAS_MISC_REG | HAS_IBM_MISC },
184 { /* Kansai KLA-PCM/T */ 0x0ff0, 0x00, 0x60, 0x87,
185 HAS_MISC_REG | HAS_IBM_MISC },
186 { /* NSC DP83903 */ 0x0374, 0x08, 0x00, 0x17,
187 HAS_MISC_REG | HAS_IBM_MISC },
188 { /* NSC DP83903 */ 0x0374, 0x00, 0xc0, 0xa8,
189 HAS_MISC_REG | HAS_IBM_MISC },
190 { /* NSC DP83903 */ 0x0374, 0x00, 0xa0, 0xb0,
191 HAS_MISC_REG | HAS_IBM_MISC },
192 { /* NSC DP83903 */ 0x0198, 0x00, 0x20, 0xe0,
193 HAS_MISC_REG | HAS_IBM_MISC },
194 { /* I-O DATA PCLA/T */ 0x0ff0, 0x00, 0xa0, 0xb0, 0 },
195 { /* Katron PE-520 */ 0x0110, 0x00, 0x40, 0xf6, 0 },
196 { /* Kingston KNE-PCM/x */ 0x0ff0, 0x00, 0xc0, 0xf0,
197 HAS_MISC_REG | HAS_IBM_MISC },
198 { /* Kingston KNE-PCM/x */ 0x0ff0, 0xe2, 0x0c, 0x0f,
199 HAS_MISC_REG | HAS_IBM_MISC },
200 { /* Kingston KNE-PC2 */ 0x0180, 0x00, 0xc0, 0xf0, 0 },
201 { /* Maxtech PCN2000 */ 0x5000, 0x00, 0x00, 0xe8, 0 },
202 { /* NDC Instant-Link */ 0x003a, 0x00, 0x80, 0xc6, 0 },
203 { /* NE2000 Compatible */ 0x0ff0, 0x00, 0xa0, 0x0c, 0 },
204 { /* Network General Sniffer */ 0x0ff0, 0x00, 0x00, 0x65,
205 HAS_MISC_REG | HAS_IBM_MISC },
206 { /* Panasonic VEL211 */ 0x0ff0, 0x00, 0x80, 0x45,
207 HAS_MISC_REG | HAS_IBM_MISC },
208 { /* PreMax PE-200 */ 0x07f0, 0x00, 0x20, 0xe0, 0 },
209 { /* RPTI EP400 */ 0x0110, 0x00, 0x40, 0x95, 0 },
210 { /* SCM Ethernet */ 0x0ff0, 0x00, 0x20, 0xcb, 0 },
211 { /* Socket EA */ 0x4000, 0x00, 0xc0, 0x1b,
212 DELAY_OUTPUT | HAS_MISC_REG | USE_BIG_BUF },
213 { /* Socket LP-E CF+ */ 0x01c0, 0x00, 0xc0, 0x1b, 0 },
214 { /* SuperSocket RE450T */ 0x0110, 0x00, 0xe0, 0x98, 0 },
215 { /* Volktek NPL-402CT */ 0x0060, 0x00, 0x40, 0x05, 0 },
216 { /* NEC PC-9801N-J12 */ 0x0ff0, 0x00, 0x00, 0x4c, 0 },
217 { /* PCMCIA Technology OEM */ 0x01c8, 0x00, 0xa0, 0x0c, 0 }
220 #define NR_INFO (sizeof(hw_info)/sizeof(hw_info_t))
222 static hw_info_t default_info = { 0, 0, 0, 0, 0 };
223 static hw_info_t dl10019_info = { 0, 0, 0, 0, IS_DL10019|HAS_MII };
224 static hw_info_t dl10022_info = { 0, 0, 0, 0, IS_DL10022|HAS_MII };
226 typedef struct pcnet_dev_t {
231 struct timer_list watchdog;
232 int stale, fast_poll;
234 u_char eth_phy, pna_phy;
239 static inline pcnet_dev_t *PRIV(struct net_device *dev)
241 char *p = netdev_priv(dev);
242 return (pcnet_dev_t *)(p + sizeof(struct ei_device));
245 /*======================================================================
247 pcnet_attach() creates an "instance" of the driver, allocating
248 local data structures for one device. The device is registered
251 ======================================================================*/
253 static dev_link_t *pcnet_attach(void)
257 struct net_device *dev;
258 client_reg_t client_reg;
261 DEBUG(0, "pcnet_attach()\n");
263 /* Create new ethernet device */
264 dev = __alloc_ei_netdev(sizeof(pcnet_dev_t));
265 if (!dev) return NULL;
270 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
271 link->irq.IRQInfo1 = IRQ_INFO2_VALID|IRQ_LEVEL_ID;
272 if (irq_list[0] == -1)
273 link->irq.IRQInfo2 = irq_mask;
275 for (i = 0; i < 4; i++)
276 link->irq.IRQInfo2 |= 1 << irq_list[i];
277 link->conf.Attributes = CONF_ENABLE_IRQ;
278 link->conf.IntType = INT_MEMORY_AND_IO;
280 SET_MODULE_OWNER(dev);
281 dev->open = &pcnet_open;
282 dev->stop = &pcnet_close;
283 dev->set_config = &set_config;
285 /* Register with Card Services */
286 link->next = dev_list;
288 client_reg.dev_info = &dev_info;
289 client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE;
290 client_reg.EventMask =
291 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
292 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
293 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
294 client_reg.event_handler = &pcnet_event;
295 client_reg.Version = 0x0210;
296 client_reg.event_callback_args.client_data = link;
297 ret = pcmcia_register_client(&link->handle, &client_reg);
298 if (ret != CS_SUCCESS) {
299 cs_error(link->handle, RegisterClient, ret);
307 /*======================================================================
309 This deletes a driver "instance". The device is de-registered
310 with Card Services. If it has been released, all local data
311 structures are freed. Otherwise, the structures will be freed
312 when the device is released.
314 ======================================================================*/
316 static void pcnet_detach(dev_link_t *link)
318 struct net_device *dev = link->priv;
321 DEBUG(0, "pcnet_detach(0x%p)\n", link);
323 /* Locate device structure */
324 for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
325 if (*linkp == link) break;
330 unregister_netdev(dev);
332 if (link->state & DEV_CONFIG)
336 pcmcia_deregister_client(link->handle);
338 /* Unlink device structure, free bits */
343 /*======================================================================
345 This probes for a card's hardware address, for card types that
346 encode this information in their CIS.
348 ======================================================================*/
350 static hw_info_t *get_hwinfo(dev_link_t *link)
352 struct net_device *dev = link->priv;
358 /* Allocate a small memory window */
359 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
360 req.Base = 0; req.Size = 0;
362 i = pcmcia_request_window(&link->handle, &req, &link->win);
363 if (i != CS_SUCCESS) {
364 cs_error(link->handle, RequestWindow, i);
368 virt = ioremap(req.Base, req.Size);
370 for (i = 0; i < NR_INFO; i++) {
371 mem.CardOffset = hw_info[i].offset & ~(req.Size-1);
372 pcmcia_map_mem_page(link->win, &mem);
373 base = &virt[hw_info[i].offset & (req.Size-1)];
374 if ((readb(base+0) == hw_info[i].a0) &&
375 (readb(base+2) == hw_info[i].a1) &&
376 (readb(base+4) == hw_info[i].a2))
380 for (j = 0; j < 6; j++)
381 dev->dev_addr[j] = readb(base + (j<<1));
385 j = pcmcia_release_window(link->win);
387 cs_error(link->handle, ReleaseWindow, j);
388 return (i < NR_INFO) ? hw_info+i : NULL;
391 /*======================================================================
393 This probes for a card's hardware address by reading the PROM.
394 It checks the address against a list of known types, then falls
395 back to a simple NE2000 clone signature check.
397 ======================================================================*/
399 static hw_info_t *get_prom(dev_link_t *link)
401 struct net_device *dev = link->priv;
402 ioaddr_t ioaddr = dev->base_addr;
406 /* This is lifted straight from drivers/net/ne.c */
408 u_char value, offset;
410 {E8390_NODMA+E8390_PAGE0+E8390_STOP, E8390_CMD}, /* Select page 0*/
411 {0x48, EN0_DCFG}, /* Set byte-wide (0x48) access. */
412 {0x00, EN0_RCNTLO}, /* Clear the count regs. */
414 {0x00, EN0_IMR}, /* Mask completion irq. */
416 {E8390_RXOFF, EN0_RXCR}, /* 0x20 Set to monitor */
417 {E8390_TXOFF, EN0_TXCR}, /* 0x02 and loopback mode. */
420 {0x00, EN0_RSARLO}, /* DMA starting at 0x0000. */
422 {E8390_RREAD+E8390_START, E8390_CMD},
425 pcnet_reset_8390(dev);
428 for (i = 0; i < sizeof(program_seq)/sizeof(program_seq[0]); i++)
429 outb_p(program_seq[i].value, ioaddr + program_seq[i].offset);
431 for (i = 0; i < 32; i++)
432 prom[i] = inb(ioaddr + PCNET_DATAPORT);
433 for (i = 0; i < NR_INFO; i++) {
434 if ((prom[0] == hw_info[i].a0) &&
435 (prom[2] == hw_info[i].a1) &&
436 (prom[4] == hw_info[i].a2))
439 if ((i < NR_INFO) || ((prom[28] == 0x57) && (prom[30] == 0x57))) {
440 for (j = 0; j < 6; j++)
441 dev->dev_addr[j] = prom[j<<1];
442 return (i < NR_INFO) ? hw_info+i : &default_info;
447 /*======================================================================
449 For DL10019 based cards, like the Linksys EtherFast
451 ======================================================================*/
453 static hw_info_t *get_dl10019(dev_link_t *link)
455 struct net_device *dev = link->priv;
459 for (sum = 0, i = 0x14; i < 0x1c; i++)
460 sum += inb_p(dev->base_addr + i);
463 for (i = 0; i < 6; i++)
464 dev->dev_addr[i] = inb_p(dev->base_addr + 0x14 + i);
465 i = inb(dev->base_addr + 0x1f);
466 return ((i == 0x91)||(i == 0x99)) ? &dl10022_info : &dl10019_info;
469 /*======================================================================
471 For Asix AX88190 based cards
473 ======================================================================*/
475 static hw_info_t *get_ax88190(dev_link_t *link)
477 struct net_device *dev = link->priv;
478 ioaddr_t ioaddr = dev->base_addr;
481 /* Not much of a test, but the alternatives are messy */
482 if (link->conf.ConfigBase != 0x03c0)
485 outb_p(0x01, ioaddr + EN0_DCFG); /* Set word-wide access. */
486 outb_p(0x00, ioaddr + EN0_RSARLO); /* DMA starting at 0x0400. */
487 outb_p(0x04, ioaddr + EN0_RSARHI);
488 outb_p(E8390_RREAD+E8390_START, ioaddr + E8390_CMD);
490 for (i = 0; i < 6; i += 2) {
491 j = inw(ioaddr + PCNET_DATAPORT);
492 dev->dev_addr[i] = j & 0xff;
493 dev->dev_addr[i+1] = j >> 8;
495 printk(KERN_NOTICE "pcnet_cs: this is an AX88190 card!\n");
496 printk(KERN_NOTICE "pcnet_cs: use axnet_cs instead.\n");
500 /*======================================================================
502 This should be totally unnecessary... but when we can't figure
503 out the hardware address any other way, we'll let the user hard
504 wire it when the module is initialized.
506 ======================================================================*/
508 static hw_info_t *get_hwired(dev_link_t *link)
510 struct net_device *dev = link->priv;
513 for (i = 0; i < 6; i++)
514 if (hw_addr[i] != 0) break;
518 for (i = 0; i < 6; i++)
519 dev->dev_addr[i] = hw_addr[i];
521 return &default_info;
524 /*======================================================================
526 pcnet_config() is scheduled to run after a CARD_INSERTION event
527 is received, to configure the PCMCIA socket, and to make the
528 ethernet device available to the system.
530 ======================================================================*/
532 #define CS_CHECK(fn, ret) \
533 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
535 static int try_io_port(dev_link_t *link)
538 if (link->io.NumPorts1 == 32) {
539 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
540 if (link->io.NumPorts2 > 0) {
541 /* for master/slave multifunction cards */
542 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
543 link->irq.Attributes =
544 IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED;
547 /* This should be two 16-port windows */
548 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
549 link->io.Attributes2 = IO_DATA_PATH_WIDTH_16;
551 if (link->io.BasePort1 == 0) {
552 link->io.IOAddrLines = 16;
553 for (j = 0; j < 0x400; j += 0x20) {
554 link->io.BasePort1 = j ^ 0x300;
555 link->io.BasePort2 = (j ^ 0x300) + 0x10;
556 ret = pcmcia_request_io(link->handle, &link->io);
557 if (ret == CS_SUCCESS) return ret;
561 return pcmcia_request_io(link->handle, &link->io);
565 static void pcnet_config(dev_link_t *link)
567 client_handle_t handle = link->handle;
568 struct net_device *dev = link->priv;
569 pcnet_dev_t *info = PRIV(dev);
572 int i, last_ret, last_fn, start_pg, stop_pg, cm_offset;
573 int manfid = 0, prodid = 0, has_shmem = 0;
578 DEBUG(0, "pcnet_config(0x%p)\n", link);
580 tuple.Attributes = 0;
581 tuple.TupleData = (cisdata_t *)buf;
582 tuple.TupleDataMax = sizeof(buf);
583 tuple.TupleOffset = 0;
584 tuple.DesiredTuple = CISTPL_CONFIG;
585 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));
586 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple));
587 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse));
588 link->conf.ConfigBase = parse.config.base;
589 link->conf.Present = parse.config.rmask[0];
592 link->state |= DEV_CONFIG;
594 /* Look up current Vcc */
595 CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(handle, &conf));
596 link->conf.Vcc = conf.Vcc;
598 tuple.DesiredTuple = CISTPL_MANFID;
599 tuple.Attributes = TUPLE_RETURN_COMMON;
600 if ((pcmcia_get_first_tuple(handle, &tuple) == CS_SUCCESS) &&
601 (pcmcia_get_tuple_data(handle, &tuple) == CS_SUCCESS)) {
602 manfid = le16_to_cpu(buf[0]);
603 prodid = le16_to_cpu(buf[1]);
606 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
607 tuple.Attributes = 0;
608 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));
609 while (last_ret == CS_SUCCESS) {
610 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
611 cistpl_io_t *io = &(parse.cftable_entry.io);
613 if (pcmcia_get_tuple_data(handle, &tuple) != 0 ||
614 pcmcia_parse_tuple(handle, &tuple, &parse) != 0 ||
615 cfg->index == 0 || cfg->io.nwin == 0)
618 link->conf.ConfigIndex = cfg->index;
619 /* For multifunction cards, by convention, we configure the
620 network function with window 0, and serial with window 1 */
622 i = (io->win[1].len > io->win[0].len);
623 link->io.BasePort2 = io->win[1-i].base;
624 link->io.NumPorts2 = io->win[1-i].len;
626 i = link->io.NumPorts2 = 0;
628 has_shmem = ((cfg->mem.nwin == 1) &&
629 (cfg->mem.win[0].len >= 0x4000));
630 link->io.BasePort1 = io->win[i].base;
631 link->io.NumPorts1 = io->win[i].len;
632 link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
633 if (link->io.NumPorts1 + link->io.NumPorts2 >= 32) {
634 last_ret = try_io_port(link);
635 if (last_ret == CS_SUCCESS) break;
638 last_ret = pcmcia_get_next_tuple(handle, &tuple);
640 if (last_ret != CS_SUCCESS) {
641 cs_error(handle, RequestIO, last_ret);
645 CS_CHECK(RequestIRQ, pcmcia_request_irq(handle, &link->irq));
647 if (link->io.NumPorts2 == 8) {
648 link->conf.Attributes |= CONF_ENABLE_SPKR;
649 link->conf.Status = CCSR_AUDIO_ENA;
651 if ((manfid == MANFID_IBM) &&
652 (prodid == PRODID_IBM_HOME_AND_AWAY))
653 link->conf.ConfigIndex |= 0x10;
655 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(handle, &link->conf));
656 dev->irq = link->irq.AssignedIRQ;
657 dev->base_addr = link->io.BasePort1;
658 if (info->flags & HAS_MISC_REG) {
659 if ((if_port == 1) || (if_port == 2))
660 dev->if_port = if_port;
662 printk(KERN_NOTICE "pcnet_cs: invalid if_port requested\n");
667 hw_info = get_hwinfo(link);
669 hw_info = get_prom(link);
671 hw_info = get_dl10019(link);
673 hw_info = get_ax88190(link);
675 hw_info = get_hwired(link);
677 if (hw_info == NULL) {
678 printk(KERN_NOTICE "pcnet_cs: unable to read hardware net"
679 " address for io base %#3lx\n", dev->base_addr);
683 info->flags = hw_info->flags;
684 /* Check for user overrides */
685 info->flags |= (delay_output) ? DELAY_OUTPUT : 0;
686 if ((manfid == MANFID_SOCKET) &&
687 ((prodid == PRODID_SOCKET_LPE) ||
688 (prodid == PRODID_SOCKET_LPE_CF) ||
689 (prodid == PRODID_SOCKET_EIO)))
690 info->flags &= ~USE_BIG_BUF;
692 info->flags &= ~USE_BIG_BUF;
694 if (info->flags & USE_BIG_BUF) {
695 start_pg = SOCKET_START_PG;
696 stop_pg = SOCKET_STOP_PG;
699 start_pg = PCNET_START_PG;
700 stop_pg = PCNET_STOP_PG;
704 /* has_shmem is ignored if use_shmem != -1 */
705 if ((use_shmem == 0) || (!has_shmem && (use_shmem == -1)) ||
706 (setup_shmem_window(link, start_pg, stop_pg, cm_offset) != 0))
707 setup_dma_config(link, start_pg, stop_pg);
709 ei_status.name = "NE2000";
710 ei_status.word16 = 1;
711 ei_status.reset_8390 = &pcnet_reset_8390;
713 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
715 if (info->flags & (IS_DL10019|IS_DL10022)) {
716 u_char id = inb(dev->base_addr + 0x1a);
717 dev->do_ioctl = &ei_ioctl;
719 if ((id == 0x30) && !info->pna_phy && (info->eth_phy == 4))
723 link->dev = &info->node;
724 link->state &= ~DEV_CONFIG_PENDING;
726 #ifdef CONFIG_NET_POLL_CONTROLLER
727 dev->poll_controller = ei_poll;
730 if (register_netdev(dev) != 0) {
731 printk(KERN_NOTICE "pcnet_cs: register_netdev() failed\n");
736 strcpy(info->node.dev_name, dev->name);
738 if (info->flags & (IS_DL10019|IS_DL10022)) {
739 u_char id = inb(dev->base_addr + 0x1a);
740 printk(KERN_INFO "%s: NE2000 (DL100%d rev %02x): ",
741 dev->name, ((info->flags & IS_DL10022) ? 22 : 19), id);
745 printk(KERN_INFO "%s: NE2000 Compatible: ", dev->name);
747 printk("io %#3lx, irq %d,", dev->base_addr, dev->irq);
748 if (info->flags & USE_SHMEM)
749 printk (" mem %#5lx,", dev->mem_start);
750 if (info->flags & HAS_MISC_REG)
751 printk(" %s xcvr,", if_names[dev->if_port]);
753 for (i = 0; i < 6; i++)
754 printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n"));
758 cs_error(link->handle, last_fn, last_ret);
761 link->state &= ~DEV_CONFIG_PENDING;
765 /*======================================================================
767 After a card is removed, pcnet_release() will unregister the net
768 device, and release the PCMCIA configuration. If the device is
769 still open, this will be postponed until it is closed.
771 ======================================================================*/
773 static void pcnet_release(dev_link_t *link)
775 pcnet_dev_t *info = PRIV(link->priv);
777 DEBUG(0, "pcnet_release(0x%p)\n", link);
779 if (info->flags & USE_SHMEM) {
781 pcmcia_release_window(link->win);
783 pcmcia_release_configuration(link->handle);
784 pcmcia_release_io(link->handle, &link->io);
785 pcmcia_release_irq(link->handle, &link->irq);
787 link->state &= ~DEV_CONFIG;
790 /*======================================================================
792 The card status event handler. Mostly, this schedules other
793 stuff to run after an event is received. A CARD_REMOVAL event
794 also sets some flags to discourage the net drivers from trying
795 to talk to the card any more.
797 ======================================================================*/
799 static int pcnet_event(event_t event, int priority,
800 event_callback_args_t *args)
802 dev_link_t *link = args->client_data;
803 struct net_device *dev = link->priv;
805 DEBUG(2, "pcnet_event(0x%06x)\n", event);
808 case CS_EVENT_CARD_REMOVAL:
809 link->state &= ~DEV_PRESENT;
810 if (link->state & DEV_CONFIG)
811 netif_device_detach(dev);
813 case CS_EVENT_CARD_INSERTION:
814 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
817 case CS_EVENT_PM_SUSPEND:
818 link->state |= DEV_SUSPEND;
819 /* Fall through... */
820 case CS_EVENT_RESET_PHYSICAL:
821 if (link->state & DEV_CONFIG) {
823 netif_device_detach(dev);
824 pcmcia_release_configuration(link->handle);
827 case CS_EVENT_PM_RESUME:
828 link->state &= ~DEV_SUSPEND;
829 /* Fall through... */
830 case CS_EVENT_CARD_RESET:
831 if (link->state & DEV_CONFIG) {
832 pcmcia_request_configuration(link->handle, &link->conf);
834 pcnet_reset_8390(dev);
836 netif_device_attach(dev);
844 /*======================================================================
846 MII interface support for DL10019 and DL10022 based cards
848 On the DL10019, the MII IO direction bit is 0x10; on the DL10022
849 it is 0x20. Setting both bits seems to work on both card types.
851 ======================================================================*/
853 #define DLINK_GPIO 0x1c
854 #define DLINK_DIAG 0x1d
855 #define DLINK_EEPROM 0x1e
857 #define MDIO_SHIFT_CLK 0x80
858 #define MDIO_DATA_OUT 0x40
859 #define MDIO_DIR_WRITE 0x30
860 #define MDIO_DATA_WRITE0 (MDIO_DIR_WRITE)
861 #define MDIO_DATA_WRITE1 (MDIO_DIR_WRITE | MDIO_DATA_OUT)
862 #define MDIO_DATA_READ 0x10
863 #define MDIO_MASK 0x0f
865 static void mdio_sync(ioaddr_t addr)
867 int bits, mask = inb(addr) & MDIO_MASK;
868 for (bits = 0; bits < 32; bits++) {
869 outb(mask | MDIO_DATA_WRITE1, addr);
870 outb(mask | MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, addr);
874 static int mdio_read(ioaddr_t addr, int phy_id, int loc)
876 u_int cmd = (0x06<<10)|(phy_id<<5)|loc;
877 int i, retval = 0, mask = inb(addr) & MDIO_MASK;
880 for (i = 13; i >= 0; i--) {
881 int dat = (cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
882 outb(mask | dat, addr);
883 outb(mask | dat | MDIO_SHIFT_CLK, addr);
885 for (i = 19; i > 0; i--) {
887 retval = (retval << 1) | ((inb(addr) & MDIO_DATA_READ) != 0);
888 outb(mask | MDIO_SHIFT_CLK, addr);
890 return (retval>>1) & 0xffff;
893 static void mdio_write(ioaddr_t addr, int phy_id, int loc, int value)
895 u_int cmd = (0x05<<28)|(phy_id<<23)|(loc<<18)|(1<<17)|value;
896 int i, mask = inb(addr) & MDIO_MASK;
899 for (i = 31; i >= 0; i--) {
900 int dat = (cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
901 outb(mask | dat, addr);
902 outb(mask | dat | MDIO_SHIFT_CLK, addr);
904 for (i = 1; i >= 0; i--) {
906 outb(mask | MDIO_SHIFT_CLK, addr);
910 static void mdio_reset(ioaddr_t addr, int phy_id)
919 /*======================================================================
921 EEPROM access routines for DL10019 and DL10022 based cards
923 ======================================================================*/
931 #define EE_ADOT 0x01 /* DataOut for ASIC */
932 #define EE_READ_CMD 0x06
934 #define DL19FDUPLX 0x0400 /* DL10019 Full duplex mode */
936 static int read_eeprom(ioaddr_t ioaddr, int location)
939 ioaddr_t ee_addr = ioaddr + DLINK_EEPROM;
940 int read_cmd = location | (EE_READ_CMD << 8);
943 outb(EE_EEP|EE_CS, ee_addr);
945 /* Shift the read command bits out. */
946 for (i = 10; i >= 0; i--) {
947 short dataval = (read_cmd & (1 << i)) ? EE_DO : 0;
948 outb_p(EE_EEP|EE_CS|dataval, ee_addr);
949 outb_p(EE_EEP|EE_CS|dataval|EE_CK, ee_addr);
951 outb(EE_EEP|EE_CS, ee_addr);
953 for (i = 16; i > 0; i--) {
954 outb_p(EE_EEP|EE_CS | EE_CK, ee_addr);
955 retval = (retval << 1) | ((inb(ee_addr) & EE_DI) ? 1 : 0);
956 outb_p(EE_EEP|EE_CS, ee_addr);
959 /* Terminate the EEPROM access. */
965 The internal ASIC registers can be changed by EEPROM READ access
966 with EE_ASIC bit set.
967 In ASIC mode, EE_ADOT is used to output the data to the ASIC.
970 static void write_asic(ioaddr_t ioaddr, int location, short asic_data)
973 ioaddr_t ee_addr = ioaddr + DLINK_EEPROM;
975 int read_cmd = location | (EE_READ_CMD << 8);
977 asic_data |= read_eeprom(ioaddr, location);
980 outb(EE_ASIC|EE_CS|EE_DI, ee_addr);
982 read_cmd = read_cmd >> 1;
984 /* Shift the read command bits out. */
985 for (i = 9; i >= 0; i--) {
986 dataval = (read_cmd & (1 << i)) ? EE_DO : 0;
987 outb_p(EE_ASIC|EE_CS|EE_DI|dataval, ee_addr);
988 outb_p(EE_ASIC|EE_CS|EE_DI|dataval|EE_CK, ee_addr);
989 outb_p(EE_ASIC|EE_CS|EE_DI|dataval, ee_addr);
992 outb(EE_ASIC|EE_CS, ee_addr);
993 outb(EE_ASIC|EE_CS|EE_CK, ee_addr);
994 outb(EE_ASIC|EE_CS, ee_addr);
996 for (i = 15; i >= 0; i--) {
997 dataval = (asic_data & (1 << i)) ? EE_ADOT : 0;
998 outb_p(EE_ASIC|EE_CS|dataval, ee_addr);
999 outb_p(EE_ASIC|EE_CS|dataval|EE_CK, ee_addr);
1000 outb_p(EE_ASIC|EE_CS|dataval, ee_addr);
1003 /* Terminate the ASIC access. */
1004 outb(EE_ASIC|EE_DI, ee_addr);
1005 outb(EE_ASIC|EE_DI| EE_CK, ee_addr);
1006 outb(EE_ASIC|EE_DI, ee_addr);
1011 /*====================================================================*/
1013 static void set_misc_reg(struct net_device *dev)
1015 ioaddr_t nic_base = dev->base_addr;
1016 pcnet_dev_t *info = PRIV(dev);
1019 if (info->flags & HAS_MISC_REG) {
1020 tmp = inb_p(nic_base + PCNET_MISC) & ~3;
1021 if (dev->if_port == 2)
1023 if (info->flags & USE_BIG_BUF)
1025 if (info->flags & HAS_IBM_MISC)
1027 outb_p(tmp, nic_base + PCNET_MISC);
1029 if (info->flags & IS_DL10022) {
1030 if (info->flags & HAS_MII) {
1031 mdio_reset(nic_base + DLINK_GPIO, info->eth_phy);
1032 /* Restart MII autonegotiation */
1033 mdio_write(nic_base + DLINK_GPIO, info->eth_phy, 0, 0x0000);
1034 mdio_write(nic_base + DLINK_GPIO, info->eth_phy, 0, 0x1200);
1035 info->mii_reset = jiffies;
1037 outb(full_duplex ? 4 : 0, nic_base + DLINK_DIAG);
1042 /*====================================================================*/
1044 static void mii_phy_probe(struct net_device *dev)
1046 pcnet_dev_t *info = PRIV(dev);
1047 ioaddr_t mii_addr = dev->base_addr + DLINK_GPIO;
1051 for (i = 31; i >= 0; i--) {
1052 tmp = mdio_read(mii_addr, i, 1);
1053 if ((tmp == 0) || (tmp == 0xffff))
1055 tmp = mdio_read(mii_addr, i, MII_PHYID_REG1);
1057 phyid |= mdio_read(mii_addr, i, MII_PHYID_REG2);
1058 phyid &= MII_PHYID_REV_MASK;
1059 DEBUG(0, "%s: MII at %d is 0x%08x\n", dev->name, i, phyid);
1060 if (phyid == AM79C9XX_HOME_PHY) {
1062 } else if (phyid != AM79C9XX_ETH_PHY) {
1068 static int pcnet_open(struct net_device *dev)
1070 pcnet_dev_t *info = PRIV(dev);
1071 dev_link_t *link = &info->link;
1073 DEBUG(2, "pcnet_open('%s')\n", dev->name);
1081 request_irq(dev->irq, ei_irq_wrapper, SA_SHIRQ, dev_info, dev);
1083 info->phy_id = info->eth_phy;
1084 info->link_status = 0x00;
1085 init_timer(&info->watchdog);
1086 info->watchdog.function = &ei_watchdog;
1087 info->watchdog.data = (u_long)dev;
1088 info->watchdog.expires = jiffies + HZ;
1089 add_timer(&info->watchdog);
1091 return ei_open(dev);
1094 /*====================================================================*/
1096 static int pcnet_close(struct net_device *dev)
1098 pcnet_dev_t *info = PRIV(dev);
1099 dev_link_t *link = &info->link;
1101 DEBUG(2, "pcnet_close('%s')\n", dev->name);
1104 free_irq(dev->irq, dev);
1107 netif_stop_queue(dev);
1108 del_timer_sync(&info->watchdog);
1113 /*======================================================================
1115 Hard reset the card. This used to pause for the same period that
1116 a 8390 reset command required, but that shouldn't be necessary.
1118 ======================================================================*/
1120 static void pcnet_reset_8390(struct net_device *dev)
1122 ioaddr_t nic_base = dev->base_addr;
1125 ei_status.txing = ei_status.dmaing = 0;
1127 outb_p(E8390_NODMA+E8390_PAGE0+E8390_STOP, nic_base + E8390_CMD);
1129 outb(inb(nic_base + PCNET_RESET), nic_base + PCNET_RESET);
1131 for (i = 0; i < 100; i++) {
1132 if ((inb_p(nic_base+EN0_ISR) & ENISR_RESET) != 0)
1136 outb_p(ENISR_RESET, nic_base + EN0_ISR); /* Ack intr. */
1139 printk(KERN_ERR "%s: pcnet_reset_8390() did not complete.\n",
1143 } /* pcnet_reset_8390 */
1145 /*====================================================================*/
1147 static int set_config(struct net_device *dev, struct ifmap *map)
1149 pcnet_dev_t *info = PRIV(dev);
1150 if ((map->port != (u_char)(-1)) && (map->port != dev->if_port)) {
1151 if (!(info->flags & HAS_MISC_REG))
1153 else if ((map->port < 1) || (map->port > 2))
1155 dev->if_port = map->port;
1156 printk(KERN_INFO "%s: switched to %s port\n",
1157 dev->name, if_names[dev->if_port]);
1158 NS8390_init(dev, 1);
1163 /*====================================================================*/
1165 static irqreturn_t ei_irq_wrapper(int irq, void *dev_id, struct pt_regs *regs)
1167 struct net_device *dev = dev_id;
1168 pcnet_dev_t *info = PRIV(dev);
1169 irqreturn_t ret = ei_interrupt(irq, dev_id, regs);
1171 if (ret == IRQ_HANDLED)
1176 static void ei_watchdog(u_long arg)
1178 struct net_device *dev = (struct net_device *)arg;
1179 pcnet_dev_t *info = PRIV(dev);
1180 ioaddr_t nic_base = dev->base_addr;
1181 ioaddr_t mii_addr = nic_base + DLINK_GPIO;
1184 if (!netif_device_present(dev)) goto reschedule;
1186 /* Check for pending interrupt with expired latency timer: with
1187 this, we can limp along even if the interrupt is blocked */
1188 outb_p(E8390_NODMA+E8390_PAGE0, nic_base + E8390_CMD);
1189 if (info->stale++ && (inb_p(nic_base + EN0_ISR) & ENISR_ALL)) {
1190 if (!info->fast_poll)
1191 printk(KERN_INFO "%s: interrupt(s) dropped!\n", dev->name);
1192 ei_irq_wrapper(dev->irq, dev, NULL);
1193 info->fast_poll = HZ;
1195 if (info->fast_poll) {
1197 info->watchdog.expires = jiffies + 1;
1198 add_timer(&info->watchdog);
1202 if (!(info->flags & HAS_MII))
1205 mdio_read(mii_addr, info->phy_id, 1);
1206 link = mdio_read(mii_addr, info->phy_id, 1);
1207 if (!link || (link == 0xffff)) {
1208 if (info->eth_phy) {
1209 info->phy_id = info->eth_phy = 0;
1211 printk(KERN_INFO "%s: MII is missing!\n", dev->name);
1212 info->flags &= ~HAS_MII;
1218 if (link != info->link_status) {
1219 u_short p = mdio_read(mii_addr, info->phy_id, 5);
1220 printk(KERN_INFO "%s: %s link beat\n", dev->name,
1221 (link) ? "found" : "lost");
1222 if (link && (info->flags & IS_DL10022)) {
1223 /* Disable collision detection on full duplex links */
1224 outb((p & 0x0140) ? 4 : 0, nic_base + DLINK_DIAG);
1225 } else if (link && (info->flags & IS_DL10019)) {
1226 /* Disable collision detection on full duplex links */
1227 write_asic(dev->base_addr, 4, (p & 0x140) ? DL19FDUPLX : 0);
1230 if (info->phy_id == info->eth_phy) {
1232 printk(KERN_INFO "%s: autonegotiation complete: "
1233 "%sbaseT-%cD selected\n", dev->name,
1234 ((p & 0x0180) ? "100" : "10"),
1235 ((p & 0x0140) ? 'F' : 'H'));
1237 printk(KERN_INFO "%s: link partner did not "
1238 "autonegotiate\n", dev->name);
1240 NS8390_init(dev, 1);
1242 info->link_status = link;
1244 if (info->pna_phy && time_after(jiffies, info->mii_reset + 6*HZ)) {
1245 link = mdio_read(mii_addr, info->eth_phy, 1) & 0x0004;
1246 if (((info->phy_id == info->pna_phy) && link) ||
1247 ((info->phy_id != info->pna_phy) && !link)) {
1248 /* isolate this MII and try flipping to the other one */
1249 mdio_write(mii_addr, info->phy_id, 0, 0x0400);
1250 info->phy_id ^= info->pna_phy ^ info->eth_phy;
1251 printk(KERN_INFO "%s: switched to %s transceiver\n", dev->name,
1252 (info->phy_id == info->eth_phy) ? "ethernet" : "PNA");
1253 mdio_write(mii_addr, info->phy_id, 0,
1254 (info->phy_id == info->eth_phy) ? 0x1000 : 0);
1255 info->link_status = 0;
1256 info->mii_reset = jiffies;
1261 info->watchdog.expires = jiffies + HZ;
1262 add_timer(&info->watchdog);
1265 /*====================================================================*/
1267 static void netdev_get_drvinfo(struct net_device *dev,
1268 struct ethtool_drvinfo *info)
1270 strcpy(info->driver, "pcnet_cs");
1273 static struct ethtool_ops netdev_ethtool_ops = {
1274 .get_drvinfo = netdev_get_drvinfo,
1277 /*====================================================================*/
1280 static int ei_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1282 pcnet_dev_t *info = PRIV(dev);
1283 u16 *data = (u16 *)&rq->ifr_ifru;
1284 ioaddr_t mii_addr = dev->base_addr + DLINK_GPIO;
1287 data[0] = info->phy_id;
1288 case SIOCGMIIREG: /* Read MII PHY register. */
1289 data[3] = mdio_read(mii_addr, data[0], data[1] & 0x1f);
1291 case SIOCSMIIREG: /* Write MII PHY register. */
1292 if (!capable(CAP_NET_ADMIN))
1294 mdio_write(mii_addr, data[0], data[1] & 0x1f, data[2]);
1300 /*====================================================================*/
1302 static void dma_get_8390_hdr(struct net_device *dev,
1303 struct e8390_pkt_hdr *hdr,
1306 ioaddr_t nic_base = dev->base_addr;
1308 if (ei_status.dmaing) {
1309 printk(KERN_NOTICE "%s: DMAing conflict in dma_block_input."
1310 "[DMAstat:%1x][irqlock:%1x]\n",
1311 dev->name, ei_status.dmaing, ei_status.irqlock);
1315 ei_status.dmaing |= 0x01;
1316 outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base + PCNET_CMD);
1317 outb_p(sizeof(struct e8390_pkt_hdr), nic_base + EN0_RCNTLO);
1318 outb_p(0, nic_base + EN0_RCNTHI);
1319 outb_p(0, nic_base + EN0_RSARLO); /* On page boundary */
1320 outb_p(ring_page, nic_base + EN0_RSARHI);
1321 outb_p(E8390_RREAD+E8390_START, nic_base + PCNET_CMD);
1323 insw(nic_base + PCNET_DATAPORT, hdr,
1324 sizeof(struct e8390_pkt_hdr)>>1);
1325 /* Fix for big endian systems */
1326 hdr->count = le16_to_cpu(hdr->count);
1328 outb_p(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */
1329 ei_status.dmaing &= ~0x01;
1332 /*====================================================================*/
1334 static void dma_block_input(struct net_device *dev, int count,
1335 struct sk_buff *skb, int ring_offset)
1337 ioaddr_t nic_base = dev->base_addr;
1338 int xfer_count = count;
1339 char *buf = skb->data;
1342 if ((ei_debug > 4) && (count != 4))
1343 printk(KERN_DEBUG "%s: [bi=%d]\n", dev->name, count+4);
1345 if (ei_status.dmaing) {
1346 printk(KERN_NOTICE "%s: DMAing conflict in dma_block_input."
1347 "[DMAstat:%1x][irqlock:%1x]\n",
1348 dev->name, ei_status.dmaing, ei_status.irqlock);
1351 ei_status.dmaing |= 0x01;
1352 outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base + PCNET_CMD);
1353 outb_p(count & 0xff, nic_base + EN0_RCNTLO);
1354 outb_p(count >> 8, nic_base + EN0_RCNTHI);
1355 outb_p(ring_offset & 0xff, nic_base + EN0_RSARLO);
1356 outb_p(ring_offset >> 8, nic_base + EN0_RSARHI);
1357 outb_p(E8390_RREAD+E8390_START, nic_base + PCNET_CMD);
1359 insw(nic_base + PCNET_DATAPORT,buf,count>>1);
1361 buf[count-1] = inb(nic_base + PCNET_DATAPORT), xfer_count++;
1363 /* This was for the ALPHA version only, but enough people have
1364 encountering problems that it is still here. */
1366 if (ei_debug > 4) { /* DMA termination address check... */
1367 int addr, tries = 20;
1369 /* DON'T check for 'inb_p(EN0_ISR) & ENISR_RDC' here
1370 -- it's broken for Rx on some cards! */
1371 int high = inb_p(nic_base + EN0_RSARHI);
1372 int low = inb_p(nic_base + EN0_RSARLO);
1373 addr = (high << 8) + low;
1374 if (((ring_offset + xfer_count) & 0xff) == (addr & 0xff))
1376 } while (--tries > 0);
1378 printk(KERN_NOTICE "%s: RX transfer address mismatch,"
1379 "%#4.4x (expected) vs. %#4.4x (actual).\n",
1380 dev->name, ring_offset + xfer_count, addr);
1383 outb_p(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */
1384 ei_status.dmaing &= ~0x01;
1385 } /* dma_block_input */
1387 /*====================================================================*/
1389 static void dma_block_output(struct net_device *dev, int count,
1390 const u_char *buf, const int start_page)
1392 ioaddr_t nic_base = dev->base_addr;
1393 pcnet_dev_t *info = PRIV(dev);
1401 printk(KERN_DEBUG "%s: [bo=%d]\n", dev->name, count);
1404 /* Round the count up for word writes. Do we need to do this?
1405 What effect will an odd byte count have on the 8390?
1406 I should check someday. */
1409 if (ei_status.dmaing) {
1410 printk(KERN_NOTICE "%s: DMAing conflict in dma_block_output."
1411 "[DMAstat:%1x][irqlock:%1x]\n",
1412 dev->name, ei_status.dmaing, ei_status.irqlock);
1415 ei_status.dmaing |= 0x01;
1416 /* We should already be in page 0, but to be safe... */
1417 outb_p(E8390_PAGE0+E8390_START+E8390_NODMA, nic_base+PCNET_CMD);
1423 outb_p(ENISR_RDC, nic_base + EN0_ISR);
1425 /* Now the normal output. */
1426 outb_p(count & 0xff, nic_base + EN0_RCNTLO);
1427 outb_p(count >> 8, nic_base + EN0_RCNTHI);
1428 outb_p(0x00, nic_base + EN0_RSARLO);
1429 outb_p(start_page, nic_base + EN0_RSARHI);
1431 outb_p(E8390_RWRITE+E8390_START, nic_base + PCNET_CMD);
1432 outsw(nic_base + PCNET_DATAPORT, buf, count>>1);
1434 dma_start = jiffies;
1437 /* This was for the ALPHA version only, but enough people have
1438 encountering problems that it is still here. */
1439 if (ei_debug > 4) { /* DMA termination address check... */
1440 int addr, tries = 20;
1442 int high = inb_p(nic_base + EN0_RSARHI);
1443 int low = inb_p(nic_base + EN0_RSARLO);
1444 addr = (high << 8) + low;
1445 if ((start_page << 8) + count == addr)
1447 } while (--tries > 0);
1449 printk(KERN_NOTICE "%s: Tx packet transfer address mismatch,"
1450 "%#4.4x (expected) vs. %#4.4x (actual).\n",
1451 dev->name, (start_page << 8) + count, addr);
1458 while ((inb_p(nic_base + EN0_ISR) & ENISR_RDC) == 0)
1459 if (time_after(jiffies, dma_start + PCNET_RDC_TIMEOUT)) {
1460 printk(KERN_NOTICE "%s: timeout waiting for Tx RDC.\n",
1462 pcnet_reset_8390(dev);
1463 NS8390_init(dev, 1);
1467 outb_p(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */
1468 if (info->flags & DELAY_OUTPUT)
1469 udelay((long)delay_time);
1470 ei_status.dmaing &= ~0x01;
1473 /*====================================================================*/
1475 static int setup_dma_config(dev_link_t *link, int start_pg,
1478 struct net_device *dev = link->priv;
1480 ei_status.tx_start_page = start_pg;
1481 ei_status.rx_start_page = start_pg + TX_PAGES;
1482 ei_status.stop_page = stop_pg;
1484 /* set up block i/o functions */
1485 ei_status.get_8390_hdr = &dma_get_8390_hdr;
1486 ei_status.block_input = &dma_block_input;
1487 ei_status.block_output = &dma_block_output;
1492 /*====================================================================*/
1494 static void copyin(u_char *dest, u_char *src, int c)
1496 u_short *d = (u_short *)dest, *s = (u_short *)src;
1501 odd = (c & 1); c >>= 1;
1504 do { *d++ = __raw_readw(s++); } while (--c);
1506 /* get last byte by fetching a word and masking */
1508 *((u_char *)d) = readw(s) & 0xff;
1511 static void copyout(u_char *dest, const u_char *src, int c)
1513 u_short *d = (u_short *)dest, *s = (u_short *)src;
1518 odd = (c & 1); c >>= 1;
1521 do { __raw_writew(*s++, d++); } while (--c);
1523 /* copy last byte doing a read-modify-write */
1525 writew((readw(d) & 0xff00) | *(u_char *)s, d);
1528 /*====================================================================*/
1530 static void shmem_get_8390_hdr(struct net_device *dev,
1531 struct e8390_pkt_hdr *hdr,
1534 void *xfer_start = (void *)(ei_status.rmem_start + (ring_page << 8)
1535 - (ei_status.rx_start_page << 8));
1537 copyin((void *)hdr, xfer_start, sizeof(struct e8390_pkt_hdr));
1538 /* Fix for big endian systems */
1539 hdr->count = le16_to_cpu(hdr->count);
1542 /*====================================================================*/
1544 static void shmem_block_input(struct net_device *dev, int count,
1545 struct sk_buff *skb, int ring_offset)
1547 void *xfer_start = (void *)(ei_status.rmem_start + ring_offset
1548 - (ei_status.rx_start_page << 8));
1549 char *buf = skb->data;
1551 if (xfer_start + count > (void *)ei_status.rmem_end) {
1552 /* We must wrap the input move. */
1553 int semi_count = (void*)ei_status.rmem_end - xfer_start;
1554 copyin(buf, xfer_start, semi_count);
1556 ring_offset = ei_status.rx_start_page << 8;
1557 xfer_start = (void *)ei_status.rmem_start;
1558 count -= semi_count;
1560 copyin(buf, xfer_start, count);
1563 /*====================================================================*/
1565 static void shmem_block_output(struct net_device *dev, int count,
1566 const u_char *buf, const int start_page)
1568 void *shmem = (void *)dev->mem_start + (start_page << 8);
1569 shmem -= ei_status.tx_start_page << 8;
1570 copyout(shmem, buf, count);
1573 /*====================================================================*/
1575 static int setup_shmem_window(dev_link_t *link, int start_pg,
1576 int stop_pg, int cm_offset)
1578 struct net_device *dev = link->priv;
1579 pcnet_dev_t *info = PRIV(dev);
1582 int i, window_size, offset, last_ret, last_fn;
1584 window_size = (stop_pg - start_pg) << 8;
1585 if (window_size > 32 * 1024)
1586 window_size = 32 * 1024;
1588 /* Make sure it's a power of two. */
1589 while ((window_size & (window_size - 1)) != 0)
1590 window_size += window_size & ~(window_size - 1);
1592 /* Allocate a memory window */
1593 req.Attributes = WIN_DATA_WIDTH_16|WIN_MEMORY_TYPE_CM|WIN_ENABLE;
1594 req.Attributes |= WIN_USE_WAIT;
1595 req.Base = 0; req.Size = window_size;
1596 req.AccessSpeed = mem_speed;
1597 CS_CHECK(RequestWindow, pcmcia_request_window(&link->handle, &req, &link->win));
1599 mem.CardOffset = (start_pg << 8) + cm_offset;
1600 offset = mem.CardOffset % window_size;
1601 mem.CardOffset -= offset;
1603 CS_CHECK(MapMemPage, pcmcia_map_mem_page(link->win, &mem));
1605 /* Try scribbling on the buffer */
1606 info->base = ioremap(req.Base, window_size);
1607 for (i = 0; i < (TX_PAGES<<8); i += 2)
1608 __raw_writew((i>>1), info->base+offset+i);
1610 for (i = 0; i < (TX_PAGES<<8); i += 2)
1611 if (__raw_readw(info->base+offset+i) != (i>>1)) break;
1612 pcnet_reset_8390(dev);
1613 if (i != (TX_PAGES<<8)) {
1614 iounmap(info->base);
1615 pcmcia_release_window(link->win);
1616 info->base = NULL; link->win = NULL;
1620 dev->mem_start = (u_long)info->base + offset;
1621 ei_status.rmem_start = dev->mem_start + (TX_PAGES<<8);
1622 dev->mem_end = ei_status.rmem_end = (u_long)info->base + req.Size;
1624 ei_status.tx_start_page = start_pg;
1625 ei_status.rx_start_page = start_pg + TX_PAGES;
1626 ei_status.stop_page = start_pg + ((req.Size - offset) >> 8);
1628 /* set up block i/o functions */
1629 ei_status.get_8390_hdr = &shmem_get_8390_hdr;
1630 ei_status.block_input = &shmem_block_input;
1631 ei_status.block_output = &shmem_block_output;
1633 info->flags |= USE_SHMEM;
1637 cs_error(link->handle, last_fn, last_ret);
1642 /*====================================================================*/
1644 static struct pcmcia_driver pcnet_driver = {
1648 .attach = pcnet_attach,
1649 .detach = pcnet_detach,
1650 .owner = THIS_MODULE,
1653 static int __init init_pcnet_cs(void)
1655 return pcmcia_register_driver(&pcnet_driver);
1658 static void __exit exit_pcnet_cs(void)
1660 DEBUG(0, "pcnet_cs: unloading\n");
1661 pcmcia_unregister_driver(&pcnet_driver);
1662 while (dev_list != NULL)
1663 pcnet_detach(dev_list);
1666 module_init(init_pcnet_cs);
1667 module_exit(exit_pcnet_cs);