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.126 2000/10/02 20:38:23
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 Public License,
22 incorporated herein by reference.
23 Donald Becker may be reached at becker@cesdis1.gsfc.nasa.gov
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/sched.h>
35 #include <linux/ptrace.h>
36 #include <linux/malloc.h>
37 #include <linux/string.h>
38 #include <linux/timer.h>
39 #include <linux/delay.h>
41 #include <asm/system.h>
43 #include <linux/netdevice.h>
44 #include <../drivers/net/8390.h>
46 #include <pcmcia/version.h>
47 #include <pcmcia/cs_types.h>
48 #include <pcmcia/cs.h>
49 #include <pcmcia/cistpl.h>
50 #include <pcmcia/ciscode.h>
51 #include <pcmcia/ds.h>
52 #include <pcmcia/cisreg.h>
54 #define PCNET_CMD 0x00
55 #define PCNET_DATAPORT 0x10 /* NatSemi-defined port window offset. */
56 #define PCNET_RESET 0x1f /* Issue a read to reset, a write to clear. */
57 #define PCNET_MISC 0x18 /* For IBM CCAE and Socket EA cards */
59 #define PCNET_START_PG 0x40 /* First page of TX buffer */
60 #define PCNET_STOP_PG 0x80 /* Last page +1 of RX ring */
62 /* Socket EA cards have a larger packet buffer */
63 #define SOCKET_START_PG 0x01
64 #define SOCKET_STOP_PG 0xff
66 #define PCNET_RDC_TIMEOUT 0x02 /* Max wait in jiffies for Tx RDC */
68 static char *if_names
[] = { "auto", "10baseT", "10base2"};
71 static int pc_debug
= PCMCIA_DEBUG
;
72 MODULE_PARM(pc_debug
, "i");
73 #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
74 static char *version
=
75 "pcnet_cs.c 1.126 2000/10/02 20:38:23 (David Hinds)";
77 #define DEBUG(n, args...)
80 /*====================================================================*/
82 /* Parameters that can be set with 'insmod' */
84 #define INT_MODULE_PARM(n, v) static int n = v; MODULE_PARM(n, "i")
86 /* Bit map of interrupts to choose from */
87 INT_MODULE_PARM(irq_mask
, 0xdeb8);
88 static int irq_list
[4] = { -1 };
89 MODULE_PARM(irq_list
, "1-4i");
91 INT_MODULE_PARM(if_port
, 1); /* Transceiver type */
92 INT_MODULE_PARM(use_big_buf
, 1); /* use 64K packet buffer? */
93 INT_MODULE_PARM(mem_speed
, 0); /* shared mem speed, in ns */
94 INT_MODULE_PARM(delay_output
, 0); /* pause after xmit? */
95 INT_MODULE_PARM(delay_time
, 4); /* in usec */
96 INT_MODULE_PARM(use_shmem
, -1); /* use shared memory? */
98 /* Ugh! Let the user hardwire the hardware address for queer cards */
99 static int hw_addr
[6] = { 0, /* ... */ };
100 MODULE_PARM(hw_addr
, "6i");
102 /*====================================================================*/
104 static void pcnet_config(dev_link_t
*link
);
105 static void pcnet_release(u_long arg
);
106 static int pcnet_event(event_t event
, int priority
,
107 event_callback_args_t
*args
);
108 static int pcnet_open(struct net_device
*dev
);
109 static int pcnet_close(struct net_device
*dev
);
110 static int do_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
);
111 static void ei_irq_wrapper(int irq
, void *dev_id
, struct pt_regs
*regs
);
112 static void ei_watchdog(u_long arg
);
113 static void pcnet_reset_8390(struct net_device
*dev
);
114 static int set_config(struct net_device
*dev
, struct ifmap
*map
);
115 static int setup_shmem_window(dev_link_t
*link
, int start_pg
,
116 int stop_pg
, int cm_offset
);
117 static int setup_dma_config(dev_link_t
*link
, int start_pg
,
120 static dev_link_t
*pcnet_attach(void);
121 static void pcnet_detach(dev_link_t
*);
123 static dev_info_t dev_info
= "pcnet_cs";
124 static dev_link_t
*dev_list
;
126 /*====================================================================*/
128 typedef struct hw_info_t
{
134 #define DELAY_OUTPUT 0x01
135 #define HAS_MISC_REG 0x02
136 #define USE_BIG_BUF 0x04
137 #define HAS_IBM_MISC 0x08
138 #define IS_DL10019 0x10
139 #define IS_DL10022 0x20
140 #define IS_AX88190 0x40
141 #define USE_SHMEM 0x80 /* autodetected */
143 static hw_info_t hw_info
[] = {
144 { /* Accton EN2212 */ 0x0ff0, 0x00, 0x00, 0xe8, DELAY_OUTPUT
},
145 { /* Allied Telesis LA-PCM */ 0x0ff0, 0x00, 0x00, 0xf4, 0 },
146 { /* APEX MultiCard */ 0x03f4, 0x00, 0x20, 0xe5, 0 },
147 { /* ASANTE FriendlyNet */ 0x4910, 0x00, 0x00, 0x94,
148 DELAY_OUTPUT
| HAS_IBM_MISC
},
149 { /* Danpex EN-6200P2 */ 0x0110, 0x00, 0x40, 0xc7, 0 },
150 { /* DataTrek NetCard */ 0x0ff0, 0x00, 0x20, 0xe8, 0 },
151 { /* Dayna CommuniCard E */ 0x0110, 0x00, 0x80, 0x19, 0 },
152 { /* D-Link DE-650 */ 0x0040, 0x00, 0x80, 0xc8, 0 },
153 { /* EP-210 Ethernet */ 0x0110, 0x00, 0x40, 0x33, 0 },
154 { /* EP4000 Ethernet */ 0x01c0, 0x00, 0x00, 0xb4, 0 },
155 { /* Epson EEN10B */ 0x0ff0, 0x00, 0x00, 0x48,
156 HAS_MISC_REG
| HAS_IBM_MISC
},
157 { /* ELECOM Laneed LD-CDWA */ 0xb8, 0x08, 0x00, 0x42, 0 },
158 { /* Hypertec Ethernet */ 0x01c0, 0x00, 0x40, 0x4c, 0 },
159 { /* IBM CCAE */ 0x0ff0, 0x08, 0x00, 0x5a,
160 HAS_MISC_REG
| HAS_IBM_MISC
},
161 { /* IBM CCAE */ 0x0ff0, 0x00, 0x04, 0xac,
162 HAS_MISC_REG
| HAS_IBM_MISC
},
163 { /* IBM CCAE */ 0x0ff0, 0x00, 0x06, 0x29,
164 HAS_MISC_REG
| HAS_IBM_MISC
},
165 { /* IBM FME */ 0x0374, 0x08, 0x00, 0x5a,
166 HAS_MISC_REG
| HAS_IBM_MISC
},
167 { /* IBM FME */ 0x0374, 0x00, 0x04, 0xac,
168 HAS_MISC_REG
| HAS_IBM_MISC
},
169 { /* Kansai KLA-PCM/T */ 0x0ff0, 0x00, 0x60, 0x87,
170 HAS_MISC_REG
| HAS_IBM_MISC
},
171 { /* NSC DP83903 */ 0x0374, 0x08, 0x00, 0x17,
172 HAS_MISC_REG
| HAS_IBM_MISC
},
173 { /* NSC DP83903 */ 0x0374, 0x00, 0xc0, 0xa8,
174 HAS_MISC_REG
| HAS_IBM_MISC
},
175 { /* NSC DP83903 */ 0x0374, 0x00, 0xa0, 0xb0,
176 HAS_MISC_REG
| HAS_IBM_MISC
},
177 { /* NSC DP83903 */ 0x0198, 0x00, 0x20, 0xe0,
178 HAS_MISC_REG
| HAS_IBM_MISC
},
179 { /* I-O DATA PCLA/T */ 0x0ff0, 0x00, 0xa0, 0xb0, 0 },
180 { /* Katron PE-520 */ 0x0110, 0x00, 0x40, 0xf6, 0 },
181 { /* Kingston KNE-PCM/x */ 0x0ff0, 0x00, 0xc0, 0xf0,
182 HAS_MISC_REG
| HAS_IBM_MISC
},
183 { /* Kingston KNE-PCM/x */ 0x0ff0, 0xe2, 0x0c, 0x0f,
184 HAS_MISC_REG
| HAS_IBM_MISC
},
185 { /* Kingston KNE-PC2 */ 0x0180, 0x00, 0xc0, 0xf0, 0 },
186 { /* Maxtech PCN2000 */ 0x5000, 0x00, 0x00, 0xe8, 0 },
187 { /* NDC Instant-Link */ 0x003a, 0x00, 0x80, 0xc6, 0 },
188 { /* NE2000 Compatible */ 0x0ff0, 0x00, 0xa0, 0x0c, 0 },
189 { /* Network General Sniffer */ 0x0ff0, 0x00, 0x00, 0x65,
190 HAS_MISC_REG
| HAS_IBM_MISC
},
191 { /* Panasonic VEL211 */ 0x0ff0, 0x00, 0x80, 0x45,
192 HAS_MISC_REG
| HAS_IBM_MISC
},
193 { /* PreMax PE-200 */ 0x07f0, 0x00, 0x20, 0xe0, 0 },
194 { /* RPTI EP400 */ 0x0110, 0x00, 0x40, 0x95, 0 },
195 { /* SCM Ethernet */ 0x0ff0, 0x00, 0x20, 0xcb, 0 },
196 { /* Socket EA */ 0x4000, 0x00, 0xc0, 0x1b,
197 DELAY_OUTPUT
| HAS_MISC_REG
| USE_BIG_BUF
},
198 { /* SuperSocket RE450T */ 0x0110, 0x00, 0xe0, 0x98, 0 },
199 { /* Volktek NPL-402CT */ 0x0060, 0x00, 0x40, 0x05, 0 },
200 { /* NEC PC-9801N-J12 */ 0x0ff0, 0x00, 0x00, 0x4c, 0 },
201 { /* PCMCIA Technology OEM */ 0x01c8, 0x00, 0xa0, 0x0c, 0 }
204 #define NR_INFO (sizeof(hw_info)/sizeof(hw_info_t))
206 static hw_info_t default_info
= { 0, 0, 0, 0, 0 };
207 static hw_info_t dl10019_info
= { 0, 0, 0, 0, IS_DL10019
};
208 static hw_info_t dl10022_info
= { 0, 0, 0, 0, IS_DL10019
|IS_DL10022
};
210 typedef struct pcnet_dev_t
{
211 struct net_device dev
; /* so &dev == &pcnet_dev_t */
216 struct timer_list watchdog
;
217 int stale
, fast_poll
;
221 /*======================================================================
223 This bit of code is used to avoid unregistering network devices
224 at inappropriate times. 2.2 and later kernels are fairly picky
225 about when this can happen.
227 ======================================================================*/
229 static void flush_stale_links(void)
231 dev_link_t
*link
, *next
;
232 for (link
= dev_list
; link
; link
= next
) {
234 if (link
->state
& DEV_STALE_LINK
)
239 /*====================================================================*/
241 static void cs_error(client_handle_t handle
, int func
, int ret
)
243 error_info_t err
= { func
, ret
};
244 CardServices(ReportError
, handle
, &err
);
247 /*======================================================================
249 We never need to do anything when a pcnet device is "initialized"
250 by the net software, because we only register already-found cards.
252 ======================================================================*/
254 static int pcnet_init(struct net_device
*dev
)
259 /*======================================================================
261 pcnet_attach() creates an "instance" of the driver, allocating
262 local data structures for one device. The device is registered
265 ======================================================================*/
267 static dev_link_t
*pcnet_attach(void)
271 struct net_device
*dev
;
272 client_reg_t client_reg
;
275 DEBUG(0, "pcnet_attach()\n");
278 /* Create new ethernet device */
279 info
= kmalloc(sizeof(*info
), GFP_KERNEL
);
280 if (!info
) return NULL
;
281 memset(info
, 0, sizeof(*info
));
282 link
= &info
->link
; dev
= &info
->dev
;
285 link
->release
.function
= &pcnet_release
;
286 link
->release
.data
= (u_long
)link
;
287 link
->irq
.Attributes
= IRQ_TYPE_EXCLUSIVE
;
288 link
->irq
.IRQInfo1
= IRQ_INFO2_VALID
|IRQ_LEVEL_ID
;
289 if (irq_list
[0] == -1)
290 link
->irq
.IRQInfo2
= irq_mask
;
292 for (i
= 0; i
< 4; i
++)
293 link
->irq
.IRQInfo2
|= 1 << irq_list
[i
];
294 link
->conf
.Attributes
= CONF_ENABLE_IRQ
;
295 link
->conf
.IntType
= INT_MEMORY_AND_IO
;
298 dev
->init
= &pcnet_init
;
299 dev
->open
= &pcnet_open
;
300 dev
->stop
= &pcnet_close
;
301 dev
->set_config
= &set_config
;
303 /* Register with Card Services */
304 link
->next
= dev_list
;
306 client_reg
.dev_info
= &dev_info
;
307 client_reg
.Attributes
= INFO_IO_CLIENT
| INFO_CARD_SHARE
;
308 client_reg
.EventMask
=
309 CS_EVENT_CARD_INSERTION
| CS_EVENT_CARD_REMOVAL
|
310 CS_EVENT_RESET_PHYSICAL
| CS_EVENT_CARD_RESET
|
311 CS_EVENT_PM_SUSPEND
| CS_EVENT_PM_RESUME
;
312 client_reg
.event_handler
= &pcnet_event
;
313 client_reg
.Version
= 0x0210;
314 client_reg
.event_callback_args
.client_data
= link
;
315 ret
= CardServices(RegisterClient
, &link
->handle
, &client_reg
);
316 if (ret
!= CS_SUCCESS
) {
317 cs_error(link
->handle
, RegisterClient
, ret
);
325 /*======================================================================
327 This deletes a driver "instance". The device is de-registered
328 with Card Services. If it has been released, all local data
329 structures are freed. Otherwise, the structures will be freed
330 when the device is released.
332 ======================================================================*/
334 static void pcnet_detach(dev_link_t
*link
)
336 pcnet_dev_t
*info
= link
->priv
;
339 DEBUG(0, "pcnet_detach(0x%p)\n", link
);
341 /* Locate device structure */
342 for (linkp
= &dev_list
; *linkp
; linkp
= &(*linkp
)->next
)
343 if (*linkp
== link
) break;
347 del_timer(&link
->release
);
348 if (link
->state
& DEV_CONFIG
) {
349 pcnet_release((u_long
)link
);
350 if (link
->state
& DEV_STALE_CONFIG
) {
351 link
->state
|= DEV_STALE_LINK
;
357 CardServices(DeregisterClient
, link
->handle
);
359 /* Unlink device structure, free bits */
362 unregister_netdev(&info
->dev
);
367 /*======================================================================
369 This probes for a card's hardware address, for card types that
370 encode this information in their CIS.
372 ======================================================================*/
374 static hw_info_t
*get_hwinfo(dev_link_t
*link
)
376 struct net_device
*dev
= link
->priv
;
382 /* Allocate a small memory window */
383 req
.Attributes
= WIN_DATA_WIDTH_8
|WIN_MEMORY_TYPE_AM
|WIN_ENABLE
;
384 req
.Base
= 0; req
.Size
= 0;
386 link
->win
= (window_handle_t
)link
->handle
;
387 i
= CardServices(RequestWindow
, &link
->win
, &req
);
388 if (i
!= CS_SUCCESS
) {
389 cs_error(link
->handle
, RequestWindow
, i
);
393 virt
= ioremap(req
.Base
, req
.Size
);
395 for (i
= 0; i
< NR_INFO
; i
++) {
396 mem
.CardOffset
= hw_info
[i
].offset
& ~(req
.Size
-1);
397 CardServices(MapMemPage
, link
->win
, &mem
);
398 base
= &virt
[hw_info
[i
].offset
& (req
.Size
-1)];
399 if ((readb(base
+0) == hw_info
[i
].a0
) &&
400 (readb(base
+2) == hw_info
[i
].a1
) &&
401 (readb(base
+4) == hw_info
[i
].a2
))
405 for (j
= 0; j
< 6; j
++)
406 dev
->dev_addr
[j
] = readb(base
+ (j
<<1));
410 j
= CardServices(ReleaseWindow
, link
->win
);
412 cs_error(link
->handle
, ReleaseWindow
, j
);
413 return (i
< NR_INFO
) ? hw_info
+i
: NULL
;
416 /*======================================================================
418 This probes for a card's hardware address by reading the PROM.
419 It checks the address against a list of known types, then falls
420 back to a simple NE2000 clone signature check.
422 ======================================================================*/
424 static hw_info_t
*get_prom(dev_link_t
*link
)
426 struct net_device
*dev
= link
->priv
;
427 ioaddr_t ioaddr
= dev
->base_addr
;
431 /* This is lifted straight from drivers/net/ne.c */
433 u_char value
, offset
;
435 {E8390_NODMA
+E8390_PAGE0
+E8390_STOP
, E8390_CMD
}, /* Select page 0*/
436 {0x48, EN0_DCFG
}, /* Set byte-wide (0x48) access. */
437 {0x00, EN0_RCNTLO
}, /* Clear the count regs. */
439 {0x00, EN0_IMR
}, /* Mask completion irq. */
441 {E8390_RXOFF
, EN0_RXCR
}, /* 0x20 Set to monitor */
442 {E8390_TXOFF
, EN0_TXCR
}, /* 0x02 and loopback mode. */
445 {0x00, EN0_RSARLO
}, /* DMA starting at 0x0000. */
447 {E8390_RREAD
+E8390_START
, E8390_CMD
},
450 pcnet_reset_8390(dev
);
453 for (i
= 0; i
< sizeof(program_seq
)/sizeof(program_seq
[0]); i
++)
454 outb_p(program_seq
[i
].value
, ioaddr
+ program_seq
[i
].offset
);
456 for (i
= 0; i
< 32; i
++)
457 prom
[i
] = inb(ioaddr
+ PCNET_DATAPORT
);
458 for (i
= 0; i
< NR_INFO
; i
++) {
459 if ((prom
[0] == hw_info
[i
].a0
) &&
460 (prom
[2] == hw_info
[i
].a1
) &&
461 (prom
[4] == hw_info
[i
].a2
))
464 if ((i
< NR_INFO
) || ((prom
[28] == 0x57) && (prom
[30] == 0x57))) {
465 for (j
= 0; j
< 6; j
++)
466 dev
->dev_addr
[j
] = prom
[j
<<1];
467 return (i
< NR_INFO
) ? hw_info
+i
: &default_info
;
472 /*======================================================================
474 For DL10019 based cards, like the Linksys EtherFast
476 ======================================================================*/
478 static hw_info_t
*get_dl10019(dev_link_t
*link
)
480 struct net_device
*dev
= link
->priv
;
484 for (sum
= 0, i
= 0x14; i
< 0x1c; i
++)
485 sum
+= inb_p(dev
->base_addr
+ i
);
488 for (i
= 0; i
< 6; i
++)
489 dev
->dev_addr
[i
] = inb_p(dev
->base_addr
+ 0x14 + i
);
490 i
= inb(dev
->base_addr
+ 0x1f);
491 return ((i
== 0x91)||(i
== 0x99)) ? &dl10022_info
: &dl10019_info
;
494 /*======================================================================
496 For Asix AX88190 based cards
498 ======================================================================*/
500 static hw_info_t
*get_ax88190(dev_link_t
*link
)
502 struct net_device
*dev
= link
->priv
;
503 ioaddr_t ioaddr
= dev
->base_addr
;
506 /* Not much of a test, but the alternatives are messy */
507 if (link
->conf
.ConfigBase
!= 0x03c0)
510 outb_p(0x01, EN0_DCFG
); /* Set word-wide access. */
511 outb_p(0x00, EN0_RSARLO
); /* DMA starting at 0x0400. */
512 outb_p(0x04, EN0_RSARHI
);
513 outb_p(E8390_RREAD
+E8390_START
, E8390_CMD
);
515 for (i
= 0; i
< 6; i
+= 2) {
516 j
= inw(ioaddr
+ PCNET_DATAPORT
);
517 dev
->dev_addr
[i
] = j
& 0xff;
518 dev
->dev_addr
[i
+1] = j
>> 8;
520 printk(KERN_INFO
"pcnet_cs: sorry, the AX88190 chipset is not "
525 /*======================================================================
527 This should be totally unnecessary... but when we can't figure
528 out the hardware address any other way, we'll let the user hard
529 wire it when the module is initialized.
531 ======================================================================*/
533 static hw_info_t
*get_hwired(dev_link_t
*link
)
535 struct net_device
*dev
= link
->priv
;
538 for (i
= 0; i
< 6; i
++)
539 if (hw_addr
[i
] != 0) break;
543 for (i
= 0; i
< 6; i
++)
544 dev
->dev_addr
[i
] = hw_addr
[i
];
546 return &default_info
;
549 /*======================================================================
551 pcnet_config() is scheduled to run after a CARD_INSERTION event
552 is received, to configure the PCMCIA socket, and to make the
553 ethernet device available to the system.
555 ======================================================================*/
557 #define CS_CHECK(fn, args...) \
558 while ((last_ret=CardServices(last_fn=(fn), args))!=0) goto cs_failed
560 #define CFG_CHECK(fn, args...) \
561 if (CardServices(fn, args) != 0) goto next_entry
563 static int try_io_port(dev_link_t
*link
)
566 if (link
->io
.NumPorts1
== 32) {
567 link
->io
.Attributes1
= IO_DATA_PATH_WIDTH_AUTO
;
568 if (link
->io
.NumPorts2
> 0) {
569 /* for master/slave multifunction cards */
570 link
->io
.Attributes2
= IO_DATA_PATH_WIDTH_8
;
571 link
->irq
.Attributes
=
572 IRQ_TYPE_DYNAMIC_SHARING
|IRQ_FIRST_SHARED
;
575 /* This should be two 16-port windows */
576 link
->io
.Attributes1
= IO_DATA_PATH_WIDTH_8
;
577 link
->io
.Attributes2
= IO_DATA_PATH_WIDTH_16
;
579 if (link
->io
.BasePort1
== 0) {
580 link
->io
.IOAddrLines
= 16;
581 for (j
= 0; j
< 0x400; j
+= 0x20) {
582 link
->io
.BasePort1
= j
^ 0x300;
583 link
->io
.BasePort2
= (j
^ 0x300) + 0x10;
584 ret
= CardServices(RequestIO
, link
->handle
, &link
->io
);
585 if (ret
== CS_SUCCESS
) return ret
;
589 return CardServices(RequestIO
, link
->handle
, &link
->io
);
593 static void pcnet_config(dev_link_t
*link
)
595 client_handle_t handle
= link
->handle
;
596 pcnet_dev_t
*info
= link
->priv
;
597 struct net_device
*dev
= &info
->dev
;
600 int i
, last_ret
, last_fn
, start_pg
, stop_pg
, cm_offset
;
601 int manfid
= 0, prodid
= 0, has_shmem
= 0;
606 DEBUG(0, "pcnet_config(0x%p)\n", link
);
608 tuple
.Attributes
= 0;
609 tuple
.TupleData
= (cisdata_t
*)buf
;
610 tuple
.TupleDataMax
= sizeof(buf
);
611 tuple
.TupleOffset
= 0;
612 tuple
.DesiredTuple
= CISTPL_CONFIG
;
613 CS_CHECK(GetFirstTuple
, handle
, &tuple
);
614 CS_CHECK(GetTupleData
, handle
, &tuple
);
615 CS_CHECK(ParseTuple
, handle
, &tuple
, &parse
);
616 link
->conf
.ConfigBase
= parse
.config
.base
;
617 link
->conf
.Present
= parse
.config
.rmask
[0];
620 link
->state
|= DEV_CONFIG
;
622 /* Look up current Vcc */
623 CS_CHECK(GetConfigurationInfo
, handle
, &conf
);
624 link
->conf
.Vcc
= conf
.Vcc
;
626 tuple
.DesiredTuple
= CISTPL_MANFID
;
627 tuple
.Attributes
= TUPLE_RETURN_COMMON
;
628 if ((CardServices(GetFirstTuple
, handle
, &tuple
) == CS_SUCCESS
) &&
629 (CardServices(GetTupleData
, handle
, &tuple
) == CS_SUCCESS
)) {
630 manfid
= le16_to_cpu(buf
[0]);
631 prodid
= le16_to_cpu(buf
[1]);
634 tuple
.DesiredTuple
= CISTPL_CFTABLE_ENTRY
;
635 tuple
.Attributes
= 0;
636 CS_CHECK(GetFirstTuple
, handle
, &tuple
);
637 while (last_ret
== CS_SUCCESS
) {
638 cistpl_cftable_entry_t
*cfg
= &(parse
.cftable_entry
);
639 cistpl_io_t
*io
= &(parse
.cftable_entry
.io
);
641 CFG_CHECK(GetTupleData
, handle
, &tuple
);
642 CFG_CHECK(ParseTuple
, handle
, &tuple
, &parse
);
643 if ((cfg
->index
== 0) || (cfg
->io
.nwin
== 0))
646 link
->conf
.ConfigIndex
= cfg
->index
;
647 /* For multifunction cards, by convention, we configure the
648 network function with window 0, and serial with window 1 */
650 i
= (io
->win
[1].len
> io
->win
[0].len
);
651 link
->io
.BasePort2
= io
->win
[1-i
].base
;
652 link
->io
.NumPorts2
= io
->win
[1-i
].len
;
654 i
= link
->io
.NumPorts2
= 0;
656 has_shmem
= ((cfg
->mem
.nwin
== 1) &&
657 (cfg
->mem
.win
[0].len
>= 0x4000));
658 link
->io
.BasePort1
= io
->win
[i
].base
;
659 link
->io
.NumPorts1
= io
->win
[i
].len
;
660 link
->io
.IOAddrLines
= io
->flags
& CISTPL_IO_LINES_MASK
;
661 if (link
->io
.NumPorts1
+ link
->io
.NumPorts2
>= 32) {
662 last_ret
= try_io_port(link
);
663 if (last_ret
== CS_SUCCESS
) break;
666 last_ret
= CardServices(GetNextTuple
, handle
, &tuple
);
668 if (last_ret
!= CS_SUCCESS
) {
669 cs_error(handle
, RequestIO
, last_ret
);
673 CS_CHECK(RequestIRQ
, handle
, &link
->irq
);
675 if (link
->io
.NumPorts2
== 8) {
676 link
->conf
.Attributes
|= CONF_ENABLE_SPKR
;
677 link
->conf
.Status
= CCSR_AUDIO_ENA
;
679 if ((manfid
== MANFID_IBM
) &&
680 (prodid
== PRODID_IBM_HOME_AND_AWAY
))
681 link
->conf
.ConfigIndex
|= 0x10;
683 CS_CHECK(RequestConfiguration
, handle
, &link
->conf
);
684 dev
->irq
= link
->irq
.AssignedIRQ
;
685 dev
->base_addr
= link
->io
.BasePort1
;
686 if (info
->flags
& HAS_MISC_REG
) {
687 if ((if_port
== 1) || (if_port
== 2))
688 dev
->if_port
= if_port
;
690 printk(KERN_NOTICE
"pcnet_cs: invalid if_port requested\n");
694 if (register_netdev(dev
) != 0) {
695 printk(KERN_NOTICE
"pcnet_cs: register_netdev() failed\n");
699 hw_info
= get_hwinfo(link
);
701 hw_info
= get_prom(link
);
703 hw_info
= get_dl10019(link
);
705 hw_info
= get_ax88190(link
);
707 hw_info
= get_hwired(link
);
709 if (hw_info
== NULL
) {
710 printk(KERN_NOTICE
"pcnet_cs: unable to read hardware net"
711 " address for io base %#3lx\n", dev
->base_addr
);
712 unregister_netdev(dev
);
716 info
->flags
= hw_info
->flags
;
717 /* Check for user overrides */
718 info
->flags
|= (delay_output
) ? DELAY_OUTPUT
: 0;
719 if ((manfid
== MANFID_SOCKET
) &&
720 ((prodid
== PRODID_SOCKET_LPE
) ||
721 (prodid
== PRODID_SOCKET_EIO
)))
722 info
->flags
&= ~USE_BIG_BUF
;
724 info
->flags
&= ~USE_BIG_BUF
;
726 if (info
->flags
& USE_BIG_BUF
) {
727 start_pg
= SOCKET_START_PG
;
728 stop_pg
= SOCKET_STOP_PG
;
731 start_pg
= PCNET_START_PG
;
732 stop_pg
= PCNET_STOP_PG
;
736 /* has_shmem is ignored if use_shmem != -1 */
737 if ((use_shmem
== 0) || (!has_shmem
&& (use_shmem
== -1)) ||
738 (setup_shmem_window(link
, start_pg
, stop_pg
, cm_offset
) != 0))
739 setup_dma_config(link
, start_pg
, stop_pg
);
741 ei_status
.name
= "NE2000";
742 ei_status
.word16
= 1;
743 ei_status
.reset_8390
= &pcnet_reset_8390
;
745 strcpy(info
->node
.dev_name
, dev
->name
);
746 link
->dev
= &info
->node
;
747 link
->state
&= ~DEV_CONFIG_PENDING
;
749 if (info
->flags
& IS_DL10019
) {
750 dev
->do_ioctl
= &do_ioctl
;
751 printk(KERN_INFO
"%s: NE2000 (DL100%d rev %02x): ",
752 dev
->name
, ((info
->flags
& IS_DL10022
) ? 22 : 19),
753 inb(dev
->base_addr
+ 0x1a));
754 } else if (info
->flags
& IS_AX88190
) {
755 printk(KERN_INFO
"%s: NE2000 (AX88190): ", dev
->name
);
757 printk(KERN_INFO
"%s: NE2000 Compatible: ", dev
->name
);
758 printk("io %#3lx, irq %d,", dev
->base_addr
, dev
->irq
);
759 if (info
->flags
& USE_SHMEM
)
760 printk (" mem %#5lx,", dev
->mem_start
);
761 if (info
->flags
& HAS_MISC_REG
)
762 printk(" %s xcvr,", if_names
[dev
->if_port
]);
764 for (i
= 0; i
< 6; i
++)
765 printk("%02X%s", dev
->dev_addr
[i
], ((i
<5) ? ":" : "\n"));
769 cs_error(link
->handle
, last_fn
, last_ret
);
771 pcnet_release((u_long
)link
);
775 /*======================================================================
777 After a card is removed, pcnet_release() will unregister the net
778 device, and release the PCMCIA configuration. If the device is
779 still open, this will be postponed until it is closed.
781 ======================================================================*/
783 static void pcnet_release(u_long arg
)
785 dev_link_t
*link
= (dev_link_t
*)arg
;
786 pcnet_dev_t
*info
= link
->priv
;
788 DEBUG(0, "pcnet_release(0x%p)\n", link
);
791 DEBUG(1, "pcnet_cs: release postponed, '%s' still open\n",
792 info
->node
.dev_name
);
793 link
->state
|= DEV_STALE_CONFIG
;
797 if (info
->flags
& USE_SHMEM
) {
799 CardServices(ReleaseWindow
, link
->win
);
801 CardServices(ReleaseConfiguration
, link
->handle
);
802 CardServices(ReleaseIO
, link
->handle
, &link
->io
);
803 CardServices(ReleaseIRQ
, link
->handle
, &link
->irq
);
805 link
->state
&= ~DEV_CONFIG
;
807 } /* pcnet_release */
809 /*======================================================================
811 The card status event handler. Mostly, this schedules other
812 stuff to run after an event is received. A CARD_REMOVAL event
813 also sets some flags to discourage the net drivers from trying
814 to talk to the card any more.
816 ======================================================================*/
818 static int pcnet_event(event_t event
, int priority
,
819 event_callback_args_t
*args
)
821 dev_link_t
*link
= args
->client_data
;
822 pcnet_dev_t
*info
= link
->priv
;
824 DEBUG(2, "pcnet_event(0x%06x)\n", event
);
827 case CS_EVENT_CARD_REMOVAL
:
828 link
->state
&= ~DEV_PRESENT
;
829 if (link
->state
& DEV_CONFIG
) {
830 netif_device_detach(&info
->dev
);
831 mod_timer(&link
->release
, jiffies
+ HZ
/20);
834 case CS_EVENT_CARD_INSERTION
:
835 link
->state
|= DEV_PRESENT
;
838 case CS_EVENT_PM_SUSPEND
:
839 link
->state
|= DEV_SUSPEND
;
840 /* Fall through... */
841 case CS_EVENT_RESET_PHYSICAL
:
842 if (link
->state
& DEV_CONFIG
) {
844 netif_device_detach(&info
->dev
);
845 CardServices(ReleaseConfiguration
, link
->handle
);
848 case CS_EVENT_PM_RESUME
:
849 link
->state
&= ~DEV_SUSPEND
;
850 /* Fall through... */
851 case CS_EVENT_CARD_RESET
:
852 if (link
->state
& DEV_CONFIG
) {
853 CardServices(RequestConfiguration
, link
->handle
, &link
->conf
);
855 pcnet_reset_8390(&info
->dev
);
856 NS8390_init(&info
->dev
, 1);
857 netif_device_attach(&info
->dev
);
865 /*======================================================================
867 MII interface support for DL10019 and DL10022 based cards
869 On the DL10019, the MII IO direction bit is 0x10; on the DL10022
870 it is 0x20. Setting both bits seems to work on both card types.
872 ======================================================================*/
874 #define DLINK_GPIO 0x1c
875 #define DLINK_DIAG 0x1d
876 #define MDIO_SHIFT_CLK 0x80
877 #define MDIO_DATA_OUT 0x40
878 #define MDIO_DIR_WRITE 0x30
879 #define MDIO_DATA_WRITE0 (MDIO_DIR_WRITE)
880 #define MDIO_DATA_WRITE1 (MDIO_DIR_WRITE | MDIO_DATA_OUT)
881 #define MDIO_DATA_READ 0x10
882 #define MDIO_MASK 0x0f
884 static void mdio_sync(ioaddr_t addr
)
886 int bits
, mask
= inb(addr
) & MDIO_MASK
;
887 for (bits
= 0; bits
< 32; bits
++) {
888 outb(mask
| MDIO_DATA_WRITE1
, addr
);
889 outb(mask
| MDIO_DATA_WRITE1
| MDIO_SHIFT_CLK
, addr
);
893 static int mdio_read(ioaddr_t addr
, int phy_id
, int loc
)
895 u_int cmd
= (0x06<<10)|(phy_id
<<5)|loc
;
896 int i
, retval
= 0, mask
= inb(addr
) & MDIO_MASK
;
899 for (i
= 13; 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
= 19; i
> 0; i
--) {
906 retval
= (retval
<< 1) | ((inb(addr
) & MDIO_DATA_READ
) != 0);
907 outb(mask
| MDIO_SHIFT_CLK
, addr
);
909 return (retval
>>1) & 0xffff;
912 static void mdio_write(ioaddr_t addr
, int phy_id
, int loc
, int value
)
914 u_int cmd
= (0x05<<28)|(phy_id
<<23)|(loc
<<18)|(1<<17)|value
;
915 int i
, mask
= inb(addr
) & MDIO_MASK
;
918 for (i
= 31; i
>= 0; i
--) {
919 int dat
= (cmd
&(1<<i
)) ? MDIO_DATA_WRITE1
: MDIO_DATA_WRITE0
;
920 outb(mask
| dat
, addr
);
921 outb(mask
| dat
| MDIO_SHIFT_CLK
, addr
);
923 for (i
= 1; i
>= 0; i
--) {
925 outb(mask
| MDIO_SHIFT_CLK
, addr
);
929 static void mdio_reset(ioaddr_t addr
, int phy_id
)
938 /*====================================================================*/
940 static void set_misc_reg(struct net_device
*dev
)
942 ioaddr_t nic_base
= dev
->base_addr
;
943 pcnet_dev_t
*info
= (pcnet_dev_t
*)dev
;
946 if (info
->flags
& HAS_MISC_REG
) {
947 tmp
= inb_p(nic_base
+ PCNET_MISC
) & ~3;
948 if (dev
->if_port
== 2)
950 if (info
->flags
& USE_BIG_BUF
)
952 if (info
->flags
& HAS_IBM_MISC
)
954 outb_p(tmp
, nic_base
+ PCNET_MISC
);
956 if (info
->flags
& IS_DL10022
) {
957 mdio_reset(nic_base
+ DLINK_GPIO
, 0);
958 /* Restart MII autonegotiation */
959 mdio_write(nic_base
+ DLINK_GPIO
, 0, 0, 0x0000);
960 mdio_write(nic_base
+ DLINK_GPIO
, 0, 0, 0x1200);
964 /*====================================================================*/
966 static int pcnet_open(struct net_device
*dev
)
968 pcnet_dev_t
*info
= (pcnet_dev_t
*)dev
;
969 dev_link_t
*link
= &info
->link
;
971 DEBUG(2, "pcnet_open('%s')\n", dev
->name
);
980 request_irq(dev
->irq
, ei_irq_wrapper
, SA_SHIRQ
, dev_info
, dev
);
982 info
->link_status
= 0x00;
983 info
->watchdog
.function
= &ei_watchdog
;
984 info
->watchdog
.data
= (u_long
)info
;
985 info
->watchdog
.expires
= jiffies
+ HZ
;
986 add_timer(&info
->watchdog
);
991 /*====================================================================*/
993 static int pcnet_close(struct net_device
*dev
)
995 pcnet_dev_t
*info
= (pcnet_dev_t
*)dev
;
996 dev_link_t
*link
= &info
->link
;
998 DEBUG(2, "pcnet_close('%s')\n", dev
->name
);
1000 free_irq(dev
->irq
, dev
);
1003 netif_stop_queue(dev
);
1004 del_timer(&info
->watchdog
);
1005 if (link
->state
& DEV_STALE_CONFIG
)
1006 mod_timer(&link
->release
, jiffies
+ HZ
/20);
1013 /*======================================================================
1015 Hard reset the card. This used to pause for the same period that
1016 a 8390 reset command required, but that shouldn't be necessary.
1018 ======================================================================*/
1020 static void pcnet_reset_8390(struct net_device
*dev
)
1022 ioaddr_t nic_base
= dev
->base_addr
;
1025 ei_status
.txing
= ei_status
.dmaing
= 0;
1027 outb(inb(nic_base
+ PCNET_RESET
), nic_base
+ PCNET_RESET
);
1029 for (i
= 0; i
< 100; i
++) {
1030 if ((inb_p(nic_base
+EN0_ISR
) & ENISR_RESET
) != 0)
1034 outb_p(ENISR_RESET
, nic_base
+ EN0_ISR
); /* Ack intr. */
1037 printk(KERN_ERR
"%s: pcnet_reset_8390() did not complete.\n",
1041 } /* pcnet_reset_8390 */
1043 /*====================================================================*/
1045 static int set_config(struct net_device
*dev
, struct ifmap
*map
)
1047 pcnet_dev_t
*info
= (pcnet_dev_t
*)dev
;
1048 if ((map
->port
!= (u_char
)(-1)) && (map
->port
!= dev
->if_port
)) {
1049 if (!(info
->flags
& HAS_MISC_REG
))
1051 else if ((map
->port
< 1) || (map
->port
> 2))
1053 dev
->if_port
= map
->port
;
1054 printk(KERN_INFO
"%s: switched to %s port\n",
1055 dev
->name
, if_names
[dev
->if_port
]);
1056 NS8390_init(dev
, 1);
1061 /*====================================================================*/
1063 static void ei_irq_wrapper(int irq
, void *dev_id
, struct pt_regs
*regs
)
1065 pcnet_dev_t
*info
= dev_id
;
1067 ei_interrupt(irq
, dev_id
, regs
);
1070 static void ei_watchdog(u_long arg
)
1072 pcnet_dev_t
*info
= (pcnet_dev_t
*)(arg
);
1073 struct net_device
*dev
= &info
->dev
;
1074 ioaddr_t nic_base
= dev
->base_addr
;
1077 if (!netif_device_present(dev
)) goto reschedule
;
1079 /* Check for pending interrupt with expired latency timer: with
1080 this, we can limp along even if the interrupt is blocked */
1081 outb_p(E8390_NODMA
+E8390_PAGE0
, nic_base
+ E8390_CMD
);
1082 if (info
->stale
++ && (inb_p(nic_base
+ EN0_ISR
) & ENISR_ALL
)) {
1083 if (!info
->fast_poll
)
1084 printk(KERN_INFO
"%s: interrupt(s) dropped!\n", dev
->name
);
1085 ei_irq_wrapper(dev
->irq
, dev
, NULL
);
1086 info
->fast_poll
= HZ
;
1088 if (info
->fast_poll
) {
1090 info
->watchdog
.expires
= jiffies
+ 1;
1091 add_timer(&info
->watchdog
);
1095 if (!(info
->flags
& IS_DL10019
))
1098 link
= mdio_read(dev
->base_addr
+ DLINK_GPIO
, 0, 1) & 0x0004;
1099 if (link
!= info
->link_status
) {
1100 u_short p
= mdio_read(dev
->base_addr
+ DLINK_GPIO
, 0, 5);
1101 printk(KERN_INFO
"%s: %s link beat\n", dev
->name
,
1102 (link
) ? "found" : "lost");
1103 if (link
&& (info
->flags
& IS_DL10022
)) {
1104 /* Disable collision detection on full duplex links */
1105 outb((p
& 0x0140) ? 4 : 0, dev
->base_addr
+ DLINK_DIAG
);
1109 printk(KERN_INFO
"%s: autonegotiation complete: "
1110 "%sbaseT-%cD selected\n", dev
->name
,
1111 ((p
& 0x0180) ? "100" : "10"),
1112 ((p
& 0x0140) ? 'F' : 'H'));
1114 printk(KERN_INFO
"%s: link partner did not autonegotiate\n",
1116 NS8390_init(dev
, 1);
1118 info
->link_status
= link
;
1122 info
->watchdog
.expires
= jiffies
+ HZ
;
1123 add_timer(&info
->watchdog
);
1126 /*====================================================================*/
1128 static int do_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
1130 u16
*data
= (u16
*)&rq
->ifr_data
;
1131 ioaddr_t addr
= dev
->base_addr
+ DLINK_GPIO
;
1133 case SIOCDEVPRIVATE
:
1135 case SIOCDEVPRIVATE
+1:
1136 data
[3] = mdio_read(addr
, data
[0], data
[1] & 0x1f);
1138 case SIOCDEVPRIVATE
+2:
1139 if (!capable(CAP_NET_ADMIN
))
1141 mdio_write(addr
, data
[0], data
[1] & 0x1f, data
[2]);
1147 /*====================================================================*/
1149 static void dma_get_8390_hdr(struct net_device
*dev
,
1150 struct e8390_pkt_hdr
*hdr
,
1153 ioaddr_t nic_base
= dev
->base_addr
;
1155 if (ei_status
.dmaing
) {
1156 printk(KERN_NOTICE
"%s: DMAing conflict in dma_block_input."
1157 "[DMAstat:%1x][irqlock:%1x]\n",
1158 dev
->name
, ei_status
.dmaing
, ei_status
.irqlock
);
1162 ei_status
.dmaing
|= 0x01;
1163 outb_p(E8390_NODMA
+E8390_PAGE0
+E8390_START
, nic_base
+ PCNET_CMD
);
1164 outb_p(sizeof(struct e8390_pkt_hdr
), nic_base
+ EN0_RCNTLO
);
1165 outb_p(0, nic_base
+ EN0_RCNTHI
);
1166 outb_p(0, nic_base
+ EN0_RSARLO
); /* On page boundary */
1167 outb_p(ring_page
, nic_base
+ EN0_RSARHI
);
1168 outb_p(E8390_RREAD
+E8390_START
, nic_base
+ PCNET_CMD
);
1170 insw(nic_base
+ PCNET_DATAPORT
, hdr
,
1171 sizeof(struct e8390_pkt_hdr
)>>1);
1172 /* Fix for big endian systems */
1173 hdr
->count
= le16_to_cpu(hdr
->count
);
1175 outb_p(ENISR_RDC
, nic_base
+ EN0_ISR
); /* Ack intr. */
1176 ei_status
.dmaing
&= ~0x01;
1179 /*====================================================================*/
1181 static void dma_block_input(struct net_device
*dev
, int count
,
1182 struct sk_buff
*skb
, int ring_offset
)
1184 ioaddr_t nic_base
= dev
->base_addr
;
1185 int xfer_count
= count
;
1186 char *buf
= skb
->data
;
1189 if ((ei_debug
> 4) && (count
!= 4))
1190 printk(KERN_DEBUG
"%s: [bi=%d]\n", dev
->name
, count
+4);
1192 if (ei_status
.dmaing
) {
1193 printk(KERN_NOTICE
"%s: DMAing conflict in dma_block_input."
1194 "[DMAstat:%1x][irqlock:%1x]\n",
1195 dev
->name
, ei_status
.dmaing
, ei_status
.irqlock
);
1198 ei_status
.dmaing
|= 0x01;
1199 outb_p(E8390_NODMA
+E8390_PAGE0
+E8390_START
, nic_base
+ PCNET_CMD
);
1200 outb_p(count
& 0xff, nic_base
+ EN0_RCNTLO
);
1201 outb_p(count
>> 8, nic_base
+ EN0_RCNTHI
);
1202 outb_p(ring_offset
& 0xff, nic_base
+ EN0_RSARLO
);
1203 outb_p(ring_offset
>> 8, nic_base
+ EN0_RSARHI
);
1204 outb_p(E8390_RREAD
+E8390_START
, nic_base
+ PCNET_CMD
);
1206 insw(nic_base
+ PCNET_DATAPORT
,buf
,count
>>1);
1208 buf
[count
-1] = inb(nic_base
+ PCNET_DATAPORT
), xfer_count
++;
1210 /* This was for the ALPHA version only, but enough people have
1211 encountering problems that it is still here. */
1213 if (ei_debug
> 4) { /* DMA termination address check... */
1214 int addr
, tries
= 20;
1216 /* DON'T check for 'inb_p(EN0_ISR) & ENISR_RDC' here
1217 -- it's broken for Rx on some cards! */
1218 int high
= inb_p(nic_base
+ EN0_RSARHI
);
1219 int low
= inb_p(nic_base
+ EN0_RSARLO
);
1220 addr
= (high
<< 8) + low
;
1221 if (((ring_offset
+ xfer_count
) & 0xff) == (addr
& 0xff))
1223 } while (--tries
> 0);
1225 printk(KERN_NOTICE
"%s: RX transfer address mismatch,"
1226 "%#4.4x (expected) vs. %#4.4x (actual).\n",
1227 dev
->name
, ring_offset
+ xfer_count
, addr
);
1230 outb_p(ENISR_RDC
, nic_base
+ EN0_ISR
); /* Ack intr. */
1231 ei_status
.dmaing
&= ~0x01;
1232 } /* dma_block_input */
1234 /*====================================================================*/
1236 static void dma_block_output(struct net_device
*dev
, int count
,
1237 const u_char
*buf
, const int start_page
)
1239 ioaddr_t nic_base
= dev
->base_addr
;
1240 pcnet_dev_t
*info
= (pcnet_dev_t
*)dev
;
1248 printk(KERN_DEBUG
"%s: [bo=%d]\n", dev
->name
, count
);
1251 /* Round the count up for word writes. Do we need to do this?
1252 What effect will an odd byte count have on the 8390?
1253 I should check someday. */
1256 if (ei_status
.dmaing
) {
1257 printk(KERN_NOTICE
"%s: DMAing conflict in dma_block_output."
1258 "[DMAstat:%1x][irqlock:%1x]\n",
1259 dev
->name
, ei_status
.dmaing
, ei_status
.irqlock
);
1262 ei_status
.dmaing
|= 0x01;
1263 /* We should already be in page 0, but to be safe... */
1264 outb_p(E8390_PAGE0
+E8390_START
+E8390_NODMA
, nic_base
+PCNET_CMD
);
1270 outb_p(ENISR_RDC
, nic_base
+ EN0_ISR
);
1272 /* Now the normal output. */
1273 outb_p(count
& 0xff, nic_base
+ EN0_RCNTLO
);
1274 outb_p(count
>> 8, nic_base
+ EN0_RCNTHI
);
1275 outb_p(0x00, nic_base
+ EN0_RSARLO
);
1276 outb_p(start_page
, nic_base
+ EN0_RSARHI
);
1278 outb_p(E8390_RWRITE
+E8390_START
, nic_base
+ PCNET_CMD
);
1279 outsw(nic_base
+ PCNET_DATAPORT
, buf
, count
>>1);
1281 dma_start
= jiffies
;
1284 /* This was for the ALPHA version only, but enough people have
1285 encountering problems that it is still here. */
1286 if (ei_debug
> 4) { /* DMA termination address check... */
1287 int addr
, tries
= 20;
1289 int high
= inb_p(nic_base
+ EN0_RSARHI
);
1290 int low
= inb_p(nic_base
+ EN0_RSARLO
);
1291 addr
= (high
<< 8) + low
;
1292 if ((start_page
<< 8) + count
== addr
)
1294 } while (--tries
> 0);
1296 printk(KERN_NOTICE
"%s: Tx packet transfer address mismatch,"
1297 "%#4.4x (expected) vs. %#4.4x (actual).\n",
1298 dev
->name
, (start_page
<< 8) + count
, addr
);
1305 while ((inb_p(nic_base
+ EN0_ISR
) & ENISR_RDC
) == 0)
1306 if (jiffies
- dma_start
> PCNET_RDC_TIMEOUT
) {
1307 printk(KERN_NOTICE
"%s: timeout waiting for Tx RDC.\n",
1309 pcnet_reset_8390(dev
);
1310 NS8390_init(dev
, 1);
1314 outb_p(ENISR_RDC
, nic_base
+ EN0_ISR
); /* Ack intr. */
1315 if (info
->flags
& DELAY_OUTPUT
)
1316 udelay((long)delay_time
);
1317 ei_status
.dmaing
&= ~0x01;
1320 /*====================================================================*/
1322 static int setup_dma_config(dev_link_t
*link
, int start_pg
,
1325 struct net_device
*dev
= link
->priv
;
1327 ei_status
.tx_start_page
= start_pg
;
1328 ei_status
.rx_start_page
= start_pg
+ TX_PAGES
;
1329 ei_status
.stop_page
= stop_pg
;
1331 /* set up block i/o functions */
1332 ei_status
.get_8390_hdr
= &dma_get_8390_hdr
;
1333 ei_status
.block_input
= &dma_block_input
;
1334 ei_status
.block_output
= &dma_block_output
;
1339 /*====================================================================*/
1341 static void copyin(u_char
*dest
, u_char
*src
, int c
)
1343 u_short
*d
= (u_short
*)dest
, *s
= (u_short
*)src
;
1348 odd
= (c
& 1); c
>>= 1;
1351 do { *d
++ = __raw_readw(s
++); } while (--c
);
1353 /* get last byte by fetching a word and masking */
1355 *((u_char
*)d
) = readw(s
) & 0xff;
1358 static void copyout(u_char
*dest
, const u_char
*src
, int c
)
1360 u_short
*d
= (u_short
*)dest
, *s
= (u_short
*)src
;
1365 odd
= (c
& 1); c
>>= 1;
1368 do { __raw_writew(*s
++, d
++); } while (--c
);
1370 /* copy last byte doing a read-modify-write */
1372 writew((readw(d
) & 0xff00) | *(u_char
*)s
, d
);
1375 /*====================================================================*/
1377 static void shmem_get_8390_hdr(struct net_device
*dev
,
1378 struct e8390_pkt_hdr
*hdr
,
1381 void *xfer_start
= (void *)(dev
->rmem_start
+ (ring_page
<< 8)
1382 - (ei_status
.rx_start_page
<< 8));
1384 copyin((void *)hdr
, xfer_start
, sizeof(struct e8390_pkt_hdr
));
1385 /* Fix for big endian systems */
1386 hdr
->count
= le16_to_cpu(hdr
->count
);
1389 /*====================================================================*/
1391 static void shmem_block_input(struct net_device
*dev
, int count
,
1392 struct sk_buff
*skb
, int ring_offset
)
1394 void *xfer_start
= (void *)(dev
->rmem_start
+ ring_offset
1395 - (ei_status
.rx_start_page
<< 8));
1396 char *buf
= skb
->data
;
1398 if (xfer_start
+ count
> (void *)dev
->rmem_end
) {
1399 /* We must wrap the input move. */
1400 int semi_count
= (void*)dev
->rmem_end
- xfer_start
;
1401 copyin(buf
, xfer_start
, semi_count
);
1403 ring_offset
= ei_status
.rx_start_page
<< 8;
1404 xfer_start
= (void *)dev
->rmem_start
;
1405 count
-= semi_count
;
1407 copyin(buf
, xfer_start
, count
);
1410 /*====================================================================*/
1412 static void shmem_block_output(struct net_device
*dev
, int count
,
1413 const u_char
*buf
, const int start_page
)
1415 void *shmem
= (void *)dev
->mem_start
+ (start_page
<< 8);
1416 shmem
-= ei_status
.tx_start_page
<< 8;
1417 copyout(shmem
, buf
, count
);
1420 /*====================================================================*/
1422 static int setup_shmem_window(dev_link_t
*link
, int start_pg
,
1423 int stop_pg
, int cm_offset
)
1425 struct net_device
*dev
= link
->priv
;
1426 pcnet_dev_t
*info
= link
->priv
;
1429 int i
, window_size
, offset
, last_ret
, last_fn
;
1431 window_size
= (stop_pg
- start_pg
) << 8;
1432 if (window_size
> 32 * 1024)
1433 window_size
= 32 * 1024;
1435 /* Make sure it's a power of two. */
1436 while ((window_size
& (window_size
- 1)) != 0)
1437 window_size
+= window_size
& ~(window_size
- 1);
1439 /* Allocate a memory window */
1440 req
.Attributes
= WIN_DATA_WIDTH_16
|WIN_MEMORY_TYPE_CM
|WIN_ENABLE
;
1441 req
.Attributes
|= WIN_USE_WAIT
;
1442 req
.Base
= 0; req
.Size
= window_size
;
1443 req
.AccessSpeed
= mem_speed
;
1444 link
->win
= (window_handle_t
)link
->handle
;
1445 CS_CHECK(RequestWindow
, &link
->win
, &req
);
1447 mem
.CardOffset
= (start_pg
<< 8) + cm_offset
;
1448 offset
= mem
.CardOffset
% window_size
;
1449 mem
.CardOffset
-= offset
;
1451 CS_CHECK(MapMemPage
, link
->win
, &mem
);
1453 /* Try scribbling on the buffer */
1454 info
->base
= ioremap(req
.Base
, window_size
);
1455 for (i
= 0; i
< (TX_PAGES
<<8); i
+= 2)
1456 __raw_writew((i
>>1), info
->base
+offset
+i
);
1458 for (i
= 0; i
< (TX_PAGES
<<8); i
+= 2)
1459 if (__raw_readw(info
->base
+offset
+i
) != (i
>>1)) break;
1460 pcnet_reset_8390(dev
);
1461 if (i
!= (TX_PAGES
<<8)) {
1462 iounmap(info
->base
);
1463 CardServices(ReleaseWindow
, link
->win
);
1464 info
->base
= NULL
; link
->win
= NULL
;
1468 dev
->mem_start
= (u_long
)info
->base
+ offset
;
1469 dev
->rmem_start
= dev
->mem_start
+ (TX_PAGES
<<8);
1470 dev
->mem_end
= dev
->rmem_end
= (u_long
)info
->base
+ req
.Size
;
1472 ei_status
.tx_start_page
= start_pg
;
1473 ei_status
.rx_start_page
= start_pg
+ TX_PAGES
;
1474 ei_status
.stop_page
= start_pg
+ ((req
.Size
- offset
) >> 8);
1476 /* set up block i/o functions */
1477 ei_status
.get_8390_hdr
= &shmem_get_8390_hdr
;
1478 ei_status
.block_input
= &shmem_block_input
;
1479 ei_status
.block_output
= &shmem_block_output
;
1481 info
->flags
|= USE_SHMEM
;
1485 cs_error(link
->handle
, last_fn
, last_ret
);
1490 /*====================================================================*/
1492 static int __init
init_pcnet_cs(void)
1495 DEBUG(0, "%s\n", version
);
1496 CardServices(GetCardServicesInfo
, &serv
);
1497 if (serv
.Revision
!= CS_RELEASE_CODE
) {
1498 printk(KERN_NOTICE
"pcnet_cs: Card Services release "
1499 "does not match!\n");
1502 register_pccard_driver(&dev_info
, &pcnet_attach
, &pcnet_detach
);
1506 static void __exit
exit_pcnet_cs(void)
1508 DEBUG(0, "pcnet_cs: unloading\n");
1509 unregister_pccard_driver(&dev_info
);
1510 while (dev_list
!= NULL
)
1511 pcnet_detach(dev_list
);
1514 module_init(init_pcnet_cs
);
1515 module_exit(exit_pcnet_cs
);