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#include <linux/module.h>
67#include <linux/kernel.h>
68#include <linux/init.h>
69#include <linux/ptrace.h>
70#include <linux/slab.h>
71#include <linux/string.h>
72#include <linux/timer.h>
73#include <linux/interrupt.h>
74#include <linux/in.h>
75#include <linux/delay.h>
76#include <linux/ethtool.h>
77#include <linux/netdevice.h>
78#include <linux/etherdevice.h>
79#include <linux/skbuff.h>
80#include <linux/if_arp.h>
81#include <linux/ioport.h>
82#include <linux/bitops.h>
83
84#include <pcmcia/cs_types.h>
85#include <pcmcia/cs.h>
86#include <pcmcia/cistpl.h>
87#include <pcmcia/cisreg.h>
88#include <pcmcia/ciscode.h>
89
90#include <asm/io.h>
91#include <asm/system.h>
92#include <asm/uaccess.h>
93
94#ifndef MANFID_COMPAQ
95  #define MANFID_COMPAQ 	   0x0138
96  #define MANFID_COMPAQ2	   0x0183  /* is this correct? */
97#endif
98
99#include <pcmcia/ds.h>
100
101/* Time in jiffies before concluding Tx hung */
102#define TX_TIMEOUT	((400*HZ)/1000)
103
104/****************
105 * Some constants used to access the hardware
106 */
107
108/* Register offsets and value constans */
109#define XIRCREG_CR  0	/* Command register (wr) */
110enum xirc_cr {
111    TransmitPacket = 0x01,
112    SoftReset = 0x02,
113    EnableIntr = 0x04,
114    ForceIntr  = 0x08,
115    ClearTxFIFO = 0x10,
116    ClearRxOvrun = 0x20,
117    RestartTx	 = 0x40
118};
119#define XIRCREG_ESR 0	/* Ethernet status register (rd) */
120enum xirc_esr {
121    FullPktRcvd = 0x01, /* full packet in receive buffer */
122    PktRejected = 0x04, /* a packet has been rejected */
123    TxPktPend = 0x08,	/* TX Packet Pending */
124    IncorPolarity = 0x10,
125    MediaSelect = 0x20	/* set if TP, clear if AUI */
126};
127#define XIRCREG_PR  1	/* Page Register select */
128#define XIRCREG_EDP 4	/* Ethernet Data Port Register */
129#define XIRCREG_ISR 6	/* Ethernet Interrupt Status Register */
130enum xirc_isr {
131    TxBufOvr = 0x01,	/* TX Buffer Overflow */
132    PktTxed  = 0x02,	/* Packet Transmitted */
133    MACIntr  = 0x04,	/* MAC Interrupt occurred */
134    TxResGrant = 0x08,	/* Tx Reservation Granted */
135    RxFullPkt = 0x20,	/* Rx Full Packet */
136    RxPktRej  = 0x40,	/* Rx Packet Rejected */
137    ForcedIntr= 0x80	/* Forced Interrupt */
138};
139#define XIRCREG1_IMR0 12 /* Ethernet Interrupt Mask Register (on page 1)*/
140#define XIRCREG1_IMR1 13
141#define XIRCREG0_TSO  8  /* Transmit Space Open Register (on page 0)*/
142#define XIRCREG0_TRS  10 /* Transmit reservation Size Register (page 0)*/
143#define XIRCREG0_DO   12 /* Data Offset Register (page 0) (wr) */
144#define XIRCREG0_RSR  12 /* Receive Status Register (page 0) (rd) */
145enum xirc_rsr {
146    PhyPkt = 0x01,	/* set:physical packet, clear: multicast packet */
147    BrdcstPkt = 0x02,	/* set if it is a broadcast packet */
148    PktTooLong = 0x04,	/* set if packet length > 1518 */
149    AlignErr = 0x10,	/* incorrect CRC and last octet not complete */
150    CRCErr = 0x20,	/* incorrect CRC and last octet is complete */
151    PktRxOk = 0x80	/* received ok */
152};
153#define XIRCREG0_PTR 13 /* packets transmitted register (rd) */
154#define XIRCREG0_RBC 14 /* receive byte count regsister (rd) */
155#define XIRCREG1_ECR 14 /* ethernet configurationn register */
156enum xirc_ecr {
157    FullDuplex = 0x04,	/* enable full duplex mode */
158    LongTPMode = 0x08,	/* adjust for longer lengths of TP cable */
159    DisablePolCor = 0x10,/* disable auto polarity correction */
160    DisableLinkPulse = 0x20, /* disable link pulse generation */
161    DisableAutoTx = 0x40, /* disable auto-transmit */
162};
163#define XIRCREG2_RBS 8	/* receive buffer start register */
164#define XIRCREG2_LED 10 /* LED Configuration register */
165/* values for the leds:    Bits 2-0 for led 1
166 *  0 disabled		   Bits 5-3 for led 2
167 *  1 collision
168 *  2 noncollision
169 *  3 link_detected
170 *  4 incor_polarity
171 *  5 jabber
172 *  6 auto_assertion
173 *  7 rx_tx_activity
174 */
175#define XIRCREG2_MSR 12 /* Mohawk specific register */
176
177#define XIRCREG4_GPR0 8 /* General Purpose Register 0 */
178#define XIRCREG4_GPR1 9 /* General Purpose Register 1 */
179#define XIRCREG2_GPR2 13 /* General Purpose Register 2 (page2!)*/
180#define XIRCREG4_BOV 10 /* Bonding Version Register */
181#define XIRCREG4_LMA 12 /* Local Memory Address Register */
182#define XIRCREG4_LMD 14 /* Local Memory Data Port */
183/* MAC register can only by accessed with 8 bit operations */
184#define XIRCREG40_CMD0 8    /* Command Register (wr) */
185enum xirc_cmd { 	    /* Commands */
186    Transmit = 0x01,
187    EnableRecv = 0x04,
188    DisableRecv = 0x08,
189    Abort = 0x10,
190    Online = 0x20,
191    IntrAck = 0x40,
192    Offline = 0x80
193};
194#define XIRCREG5_RHSA0	10  /* Rx Host Start Address */
195#define XIRCREG40_RXST0 9   /* Receive Status Register */
196#define XIRCREG40_TXST0 11  /* Transmit Status Register 0 */
197#define XIRCREG40_TXST1 12  /* Transmit Status Register 10 */
198#define XIRCREG40_RMASK0 13  /* Receive Mask Register */
199#define XIRCREG40_TMASK0 14  /* Transmit Mask Register 0 */
200#define XIRCREG40_TMASK1 15  /* Transmit Mask Register 0 */
201#define XIRCREG42_SWC0	8   /* Software Configuration 0 */
202#define XIRCREG42_SWC1	9   /* Software Configuration 1 */
203#define XIRCREG42_BOC	10  /* Back-Off Configuration */
204#define XIRCREG44_TDR0	8   /* Time Domain Reflectometry 0 */
205#define XIRCREG44_TDR1	9   /* Time Domain Reflectometry 1 */
206#define XIRCREG44_RXBC_LO 10 /* Rx Byte Count 0 (rd) */
207#define XIRCREG44_RXBC_HI 11 /* Rx Byte Count 1 (rd) */
208#define XIRCREG45_REV	 15 /* Revision Register (rd) */
209#define XIRCREG50_IA	8   /* Individual Address (8-13) */
210
211static const char *if_names[] = { "Auto", "10BaseT", "10Base2", "AUI", "100BaseT" };
212
213/****************
214 * All the PCMCIA modules use PCMCIA_DEBUG to control debugging.  If
215 * you do not define PCMCIA_DEBUG at all, all the debug code will be
216 * left out.  If you compile with PCMCIA_DEBUG=0, the debug code will
217 * be present but disabled -- but it can then be enabled for specific
218 * modules at load time with a 'pc_debug=#' option to insmod.
219 */
220#ifdef PCMCIA_DEBUG
221static int pc_debug = PCMCIA_DEBUG;
222module_param(pc_debug, int, 0);
223#define DEBUG(n, args...) if (pc_debug>(n)) printk(KDBG_XIRC args)
224#else
225#define DEBUG(n, args...)
226#endif
227
228#define KDBG_XIRC KERN_DEBUG   "xirc2ps_cs: "
229#define KERR_XIRC KERN_ERR     "xirc2ps_cs: "
230#define KWRN_XIRC KERN_WARNING "xirc2ps_cs: "
231#define KNOT_XIRC KERN_NOTICE  "xirc2ps_cs: "
232#define KINF_XIRC KERN_INFO    "xirc2ps_cs: "
233
234/* card types */
235#define XIR_UNKNOWN  0	/* unknown: not supported */
236#define XIR_CE	     1	/* (prodid 1) different hardware: not supported */
237#define XIR_CE2      2	/* (prodid 2) */
238#define XIR_CE3      3	/* (prodid 3) */
239#define XIR_CEM      4	/* (prodid 1) different hardware: not supported */
240#define XIR_CEM2     5	/* (prodid 2) */
241#define XIR_CEM3     6	/* (prodid 3) */
242#define XIR_CEM33    7	/* (prodid 4) */
243#define XIR_CEM56M   8	/* (prodid 5) */
244#define XIR_CEM56    9	/* (prodid 6) */
245#define XIR_CM28    10	/* (prodid 3) modem only: not supported here */
246#define XIR_CM33    11	/* (prodid 4) modem only: not supported here */
247#define XIR_CM56    12	/* (prodid 5) modem only: not supported here */
248#define XIR_CG	    13	/* (prodid 1) GSM modem only: not supported */
249#define XIR_CBE     14	/* (prodid 1) cardbus ethernet: not supported */
250/*====================================================================*/
251
252/* Module parameters */
253
254MODULE_DESCRIPTION("Xircom PCMCIA ethernet driver");
255MODULE_LICENSE("Dual MPL/GPL");
256
257#define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0)
258
259INT_MODULE_PARM(if_port,	0);
260INT_MODULE_PARM(full_duplex,	0);
261INT_MODULE_PARM(do_sound, 	1);
262INT_MODULE_PARM(lockup_hack,	0);  /* anti lockup hack */
263
264/*====================================================================*/
265
266/* We do not process more than these number of bytes during one
267 * interrupt. (Of course we receive complete packets, so this is not
268 * an exact value).
269 * Something between 2000..22000; first value gives best interrupt latency,
270 * the second enables the usage of the complete on-chip buffer. We use the
271 * high value as the initial value.
272 */
273static unsigned maxrx_bytes = 22000;
274
275/* MII management prototypes */
276static void mii_idle(kio_addr_t ioaddr);
277static void mii_putbit(kio_addr_t ioaddr, unsigned data);
278static int  mii_getbit(kio_addr_t ioaddr);
279static void mii_wbits(kio_addr_t ioaddr, unsigned data, int len);
280static unsigned mii_rd(kio_addr_t ioaddr, u_char phyaddr, u_char phyreg);
281static void mii_wr(kio_addr_t ioaddr, u_char phyaddr, u_char phyreg,
282		   unsigned data, int len);
283
284/*
285 * The event() function is this driver's Card Services event handler.
286 * It will be called by Card Services when an appropriate card status
287 * event is received.  The config() and release() entry points are
288 * used to configure or release a socket, in response to card insertion
289 * and ejection events.  They are invoked from the event handler.
290 */
291
292static int has_ce2_string(struct pcmcia_device * link);
293static int xirc2ps_config(struct pcmcia_device * link);
294static void xirc2ps_release(struct pcmcia_device * link);
295
296/****************
297 * The attach() and detach() entry points are used to create and destroy
298 * "instances" of the driver, where each instance represents everything
299 * needed to manage one actual PCMCIA card.
300 */
301
302static void xirc2ps_detach(struct pcmcia_device *p_dev);
303
304/****************
305 * You'll also need to prototype all the functions that will actually
306 * be used to talk to your device.  See 'pcmem_cs' for a good example
307 * of a fully self-sufficient driver; the other drivers rely more or
308 * less on other parts of the kernel.
309 */
310
311static irqreturn_t xirc2ps_interrupt(int irq, void *dev_id);
312
313/****************
314 * A linked list of "instances" of the device.  Each actual
315 * PCMCIA card corresponds to one device instance, and is described
316 * by one struct pcmcia_device structure (defined in ds.h).
317 *
318 * You may not want to use a linked list for this -- for example, the
319 * memory card driver uses an array of struct pcmcia_device pointers, where minor
320 * device numbers are used to derive the corresponding array index.
321 */
322
323/****************
324 * A driver needs to provide a dev_node_t structure for each device
325 * on a card.  In some cases, there is only one device per card (for
326 * example, ethernet cards, modems).  In other cases, there may be
327 * many actual or logical devices (SCSI adapters, memory cards with
328 * multiple partitions).  The dev_node_t structures need to be kept
329 * in a linked list starting at the 'dev' field of a struct pcmcia_device
330 * structure.  We allocate them in the card's private data structure,
331 * because they generally can't be allocated dynamically.
332 */
333
334typedef struct local_info_t {
335	struct net_device	*dev;
336	struct pcmcia_device	*p_dev;
337    dev_node_t node;
338    struct net_device_stats stats;
339    int card_type;
340    int probe_port;
341    int silicon; /* silicon revision. 0=old CE2, 1=Scipper, 4=Mohawk */
342    int mohawk;  /* a CE3 type card */
343    int dingo;	 /* a CEM56 type card */
344    int new_mii; /* has full 10baseT/100baseT MII */
345    int modem;	 /* is a multi function card (i.e with a modem) */
346    void __iomem *dingo_ccr; /* only used for CEM56 cards */
347    unsigned last_ptr_value; /* last packets transmitted value */
348    const char *manf_str;
349    struct work_struct tx_timeout_task;
350} local_info_t;
351
352/****************
353 * Some more prototypes
354 */
355static int do_start_xmit(struct sk_buff *skb, struct net_device *dev);
356static void do_tx_timeout(struct net_device *dev);
357static void xirc2ps_tx_timeout_task(struct work_struct *work);
358static struct net_device_stats *do_get_stats(struct net_device *dev);
359static void set_addresses(struct net_device *dev);
360static void set_multicast_list(struct net_device *dev);
361static int set_card_type(struct pcmcia_device *link, const void *s);
362static int do_config(struct net_device *dev, struct ifmap *map);
363static int do_open(struct net_device *dev);
364static int do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
365static const struct ethtool_ops netdev_ethtool_ops;
366static void hardreset(struct net_device *dev);
367static void do_reset(struct net_device *dev, int full);
368static int init_mii(struct net_device *dev);
369static void do_powerdown(struct net_device *dev);
370static int do_stop(struct net_device *dev);
371
372/*=============== Helper functions =========================*/
373static int
374first_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
375{
376	int err;
377
378	if ((err = pcmcia_get_first_tuple(handle, tuple)) == 0 &&
379			(err = pcmcia_get_tuple_data(handle, tuple)) == 0)
380		err = pcmcia_parse_tuple(handle, tuple, parse);
381	return err;
382}
383
384static int
385next_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
386{
387	int err;
388
389	if ((err = pcmcia_get_next_tuple(handle, tuple)) == 0 &&
390			(err = pcmcia_get_tuple_data(handle, tuple)) == 0)
391		err = pcmcia_parse_tuple(handle, tuple, parse);
392	return err;
393}
394
395#define SelectPage(pgnr)   outb((pgnr), ioaddr + XIRCREG_PR)
396#define GetByte(reg)	   ((unsigned)inb(ioaddr + (reg)))
397#define GetWord(reg)	   ((unsigned)inw(ioaddr + (reg)))
398#define PutByte(reg,value) outb((value), ioaddr+(reg))
399#define PutWord(reg,value) outw((value), ioaddr+(reg))
400
401/*====== Functions used for debugging =================================*/
402
403/*============== MII Management functions ===============*/
404
405/****************
406 * Turn around for read
407 */
408static void
409mii_idle(kio_addr_t ioaddr)
410{
411    PutByte(XIRCREG2_GPR2, 0x04|0); /* drive MDCK low */
412    udelay(1);
413    PutByte(XIRCREG2_GPR2, 0x04|1); /* and drive MDCK high */
414    udelay(1);
415}
416
417/****************
418 * Write a bit to MDI/O
419 */
420static void
421mii_putbit(kio_addr_t ioaddr, unsigned data)
422{
423  #if 1
424    if (data) {
425	PutByte(XIRCREG2_GPR2, 0x0c|2|0); /* set MDIO */
426	udelay(1);
427	PutByte(XIRCREG2_GPR2, 0x0c|2|1); /* and drive MDCK high */
428	udelay(1);
429    } else {
430	PutByte(XIRCREG2_GPR2, 0x0c|0|0); /* clear MDIO */
431	udelay(1);
432	PutByte(XIRCREG2_GPR2, 0x0c|0|1); /* and drive MDCK high */
433	udelay(1);
434    }
435  #else
436    if (data) {
437	PutWord(XIRCREG2_GPR2-1, 0x0e0e);
438	udelay(1);
439	PutWord(XIRCREG2_GPR2-1, 0x0f0f);
440	udelay(1);
441    } else {
442	PutWord(XIRCREG2_GPR2-1, 0x0c0c);
443	udelay(1);
444	PutWord(XIRCREG2_GPR2-1, 0x0d0d);
445	udelay(1);
446    }
447  #endif
448}
449
450/****************
451 * Get a bit from MDI/O
452 */
453static int
454mii_getbit(kio_addr_t ioaddr)
455{
456    unsigned d;
457
458    PutByte(XIRCREG2_GPR2, 4|0); /* drive MDCK low */
459    udelay(1);
460    d = GetByte(XIRCREG2_GPR2); /* read MDIO */
461    PutByte(XIRCREG2_GPR2, 4|1); /* drive MDCK high again */
462    udelay(1);
463    return d & 0x20; /* read MDIO */
464}
465
466static void
467mii_wbits(kio_addr_t ioaddr, unsigned data, int len)
468{
469    unsigned m = 1 << (len-1);
470    for (; m; m >>= 1)
471	mii_putbit(ioaddr, data & m);
472}
473
474static unsigned
475mii_rd(kio_addr_t ioaddr,	u_char phyaddr, u_char phyreg)
476{
477    int i;
478    unsigned data=0, m;
479
480    SelectPage(2);
481    for (i=0; i < 32; i++)		/* 32 bit preamble */
482	mii_putbit(ioaddr, 1);
483    mii_wbits(ioaddr, 0x06, 4); 	/* Start and opcode for read */
484    mii_wbits(ioaddr, phyaddr, 5);	/* PHY address to be accessed */
485    mii_wbits(ioaddr, phyreg, 5);	/* PHY register to read */
486    mii_idle(ioaddr);			/* turn around */
487    mii_getbit(ioaddr);
488
489    for (m = 1<<15; m; m >>= 1)
490	if (mii_getbit(ioaddr))
491	    data |= m;
492    mii_idle(ioaddr);
493    return data;
494}
495
496static void
497mii_wr(kio_addr_t ioaddr, u_char phyaddr, u_char phyreg, unsigned data, int len)
498{
499    int i;
500
501    SelectPage(2);
502    for (i=0; i < 32; i++)		/* 32 bit preamble */
503	mii_putbit(ioaddr, 1);
504    mii_wbits(ioaddr, 0x05, 4); 	/* Start and opcode for write */
505    mii_wbits(ioaddr, phyaddr, 5);	/* PHY address to be accessed */
506    mii_wbits(ioaddr, phyreg, 5);	/* PHY Register to write */
507    mii_putbit(ioaddr, 1);		/* turn around */
508    mii_putbit(ioaddr, 0);
509    mii_wbits(ioaddr, data, len);	/* And write the data */
510    mii_idle(ioaddr);
511}
512
513/*============= Main bulk of functions	=========================*/
514
515/****************
516 * xirc2ps_attach() creates an "instance" of the driver, allocating
517 * local data structures for one device.  The device is registered
518 * with Card Services.
519 *
520 * The dev_link structure is initialized, but we don't actually
521 * configure the card at this point -- we wait until we receive a
522 * card insertion event.
523 */
524
525static int
526xirc2ps_probe(struct pcmcia_device *link)
527{
528    struct net_device *dev;
529    local_info_t *local;
530
531    DEBUG(0, "attach()\n");
532
533    /* Allocate the device structure */
534    dev = alloc_etherdev(sizeof(local_info_t));
535    if (!dev)
536	    return -ENOMEM;
537    local = netdev_priv(dev);
538    local->dev = dev;
539    local->p_dev = link;
540    link->priv = dev;
541
542    /* General socket configuration */
543    link->conf.Attributes = CONF_ENABLE_IRQ;
544    link->conf.IntType = INT_MEMORY_AND_IO;
545    link->conf.ConfigIndex = 1;
546    link->irq.Handler = xirc2ps_interrupt;
547    link->irq.Instance = dev;
548
549    /* Fill in card specific entries */
550    SET_MODULE_OWNER(dev);
551    dev->hard_start_xmit = &do_start_xmit;
552    dev->set_config = &do_config;
553    dev->get_stats = &do_get_stats;
554    dev->do_ioctl = &do_ioctl;
555    SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
556    dev->set_multicast_list = &set_multicast_list;
557    dev->open = &do_open;
558    dev->stop = &do_stop;
559#ifdef HAVE_TX_TIMEOUT
560    dev->tx_timeout = do_tx_timeout;
561    dev->watchdog_timeo = TX_TIMEOUT;
562    INIT_WORK(&local->tx_timeout_task, xirc2ps_tx_timeout_task);
563#endif
564
565    return xirc2ps_config(link);
566} /* xirc2ps_attach */
567
568/****************
569 *  This deletes a driver "instance".  The device is de-registered
570 *  with Card Services.  If it has been released, all local data
571 *  structures are freed.  Otherwise, the structures will be freed
572 *  when the device is released.
573 */
574
575static void
576xirc2ps_detach(struct pcmcia_device *link)
577{
578    struct net_device *dev = link->priv;
579
580    DEBUG(0, "detach(0x%p)\n", link);
581
582    if (link->dev_node)
583	unregister_netdev(dev);
584
585    xirc2ps_release(link);
586
587    free_netdev(dev);
588} /* xirc2ps_detach */
589
590/****************
591 * Detect the type of the card. s is the buffer with the data of tuple 0x20
592 * Returns: 0 := not supported
593 *		       mediaid=11 and prodid=47
594 * Media-Id bits:
595 *  Ethernet	    0x01
596 *  Tokenring	    0x02
597 *  Arcnet	    0x04
598 *  Wireless	    0x08
599 *  Modem	    0x10
600 *  GSM only	    0x20
601 * Prod-Id bits:
602 *  Pocket	    0x10
603 *  External	    0x20
604 *  Creditcard	    0x40
605 *  Cardbus	    0x80
606 *
607 */
608static int
609set_card_type(struct pcmcia_device *link, const void *s)
610{
611    struct net_device *dev = link->priv;
612    local_info_t *local = netdev_priv(dev);
613  #ifdef PCMCIA_DEBUG
614    unsigned cisrev = ((const unsigned char *)s)[2];
615  #endif
616    unsigned mediaid= ((const unsigned char *)s)[3];
617    unsigned prodid = ((const unsigned char *)s)[4];
618
619    DEBUG(0, "cisrev=%02x mediaid=%02x prodid=%02x\n",
620	  cisrev, mediaid, prodid);
621
622    local->mohawk = 0;
623    local->dingo = 0;
624    local->modem = 0;
625    local->card_type = XIR_UNKNOWN;
626    if (!(prodid & 0x40)) {
627	printk(KNOT_XIRC "Ooops: Not a creditcard\n");
628	return 0;
629    }
630    if (!(mediaid & 0x01)) {
631	printk(KNOT_XIRC "Not an Ethernet card\n");
632	return 0;
633    }
634    if (mediaid & 0x10) {
635	local->modem = 1;
636	switch(prodid & 15) {
637	  case 1: local->card_type = XIR_CEM   ; break;
638	  case 2: local->card_type = XIR_CEM2  ; break;
639	  case 3: local->card_type = XIR_CEM3  ; break;
640	  case 4: local->card_type = XIR_CEM33 ; break;
641	  case 5: local->card_type = XIR_CEM56M;
642		  local->mohawk = 1;
643		  break;
644	  case 6:
645	  case 7: /* 7 is the RealPort 10/56 */
646		  local->card_type = XIR_CEM56 ;
647		  local->mohawk = 1;
648		  local->dingo = 1;
649		  break;
650	}
651    } else {
652	switch(prodid & 15) {
653	  case 1: local->card_type = has_ce2_string(link)? XIR_CE2 : XIR_CE ;
654		  break;
655	  case 2: local->card_type = XIR_CE2; break;
656	  case 3: local->card_type = XIR_CE3;
657		  local->mohawk = 1;
658		  break;
659	}
660    }
661    if (local->card_type == XIR_CE || local->card_type == XIR_CEM) {
662	printk(KNOT_XIRC "Sorry, this is an old CE card\n");
663	return 0;
664    }
665    if (local->card_type == XIR_UNKNOWN)
666	printk(KNOT_XIRC "unknown card (mediaid=%02x prodid=%02x)\n",
667	       mediaid, prodid);
668
669    return 1;
670}
671
672/****************
673 * There are some CE2 cards out which claim to be a CE card.
674 * This function looks for a "CE2" in the 3rd version field.
675 * Returns: true if this is a CE2
676 */
677static int
678has_ce2_string(struct pcmcia_device * p_dev)
679{
680	if (p_dev->prod_id[2] && strstr(p_dev->prod_id[2], "CE2"))
681		return 1;
682	return 0;
683}
684
685/****************
686 * xirc2ps_config() is scheduled to run after a CARD_INSERTION event
687 * is received, to configure the PCMCIA socket, and to make the
688 * ethernet device available to the system.
689 */
690static int
691xirc2ps_config(struct pcmcia_device * link)
692{
693    struct net_device *dev = link->priv;
694    local_info_t *local = netdev_priv(dev);
695    tuple_t tuple;
696    cisparse_t parse;
697    kio_addr_t ioaddr;
698    int err, i;
699    u_char buf[64];
700    cistpl_lan_node_id_t *node_id = (cistpl_lan_node_id_t*)parse.funce.data;
701    cistpl_cftable_entry_t *cf = &parse.cftable_entry;
702
703    local->dingo_ccr = NULL;
704
705    DEBUG(0, "config(0x%p)\n", link);
706
707    /*
708     * This reads the card's CONFIG tuple to find its configuration
709     * registers.
710     */
711    tuple.Attributes = 0;
712    tuple.TupleData = buf;
713    tuple.TupleDataMax = 64;
714    tuple.TupleOffset = 0;
715
716    /* Is this a valid	card */
717    tuple.DesiredTuple = CISTPL_MANFID;
718    if ((err=first_tuple(link, &tuple, &parse))) {
719	printk(KNOT_XIRC "manfid not found in CIS\n");
720	goto failure;
721    }
722
723    switch(parse.manfid.manf) {
724      case MANFID_XIRCOM:
725	local->manf_str = "Xircom";
726	break;
727      case MANFID_ACCTON:
728	local->manf_str = "Accton";
729	break;
730      case MANFID_COMPAQ:
731      case MANFID_COMPAQ2:
732	local->manf_str = "Compaq";
733	break;
734      case MANFID_INTEL:
735	local->manf_str = "Intel";
736	break;
737      case MANFID_TOSHIBA:
738	local->manf_str = "Toshiba";
739	break;
740      default:
741	printk(KNOT_XIRC "Unknown Card Manufacturer ID: 0x%04x\n",
742	       (unsigned)parse.manfid.manf);
743	goto failure;
744    }
745    DEBUG(0, "found %s card\n", local->manf_str);
746
747    if (!set_card_type(link, buf)) {
748	printk(KNOT_XIRC "this card is not supported\n");
749	goto failure;
750    }
751
752    /* get the ethernet address from the CIS */
753    tuple.DesiredTuple = CISTPL_FUNCE;
754    for (err = first_tuple(link, &tuple, &parse); !err;
755			     err = next_tuple(link, &tuple, &parse)) {
756	/* Once I saw two CISTPL_FUNCE_LAN_NODE_ID entries:
757	 * the first one with a length of zero the second correct -
758	 * so I skip all entries with length 0 */
759	if (parse.funce.type == CISTPL_FUNCE_LAN_NODE_ID
760	    && ((cistpl_lan_node_id_t *)parse.funce.data)->nb)
761	    break;
762    }
763    if (err) { /* not found: try to get the node-id from tuple 0x89 */
764	tuple.DesiredTuple = 0x89;  /* data layout looks like tuple 0x22 */
765	if ((err = pcmcia_get_first_tuple(link, &tuple)) == 0 &&
766		(err = pcmcia_get_tuple_data(link, &tuple)) == 0) {
767	    if (tuple.TupleDataLen == 8 && *buf == CISTPL_FUNCE_LAN_NODE_ID)
768		memcpy(&parse, buf, 8);
769	    else
770		err = -1;
771	}
772    }
773    if (err) { /* another try	(James Lehmer's CE2 version 4.1)*/
774	tuple.DesiredTuple = CISTPL_FUNCE;
775	for (err = first_tuple(link, &tuple, &parse); !err;
776				 err = next_tuple(link, &tuple, &parse)) {
777	    if (parse.funce.type == 0x02 && parse.funce.data[0] == 1
778		&& parse.funce.data[1] == 6 && tuple.TupleDataLen == 13) {
779		buf[1] = 4;
780		memcpy(&parse, buf+1, 8);
781		break;
782	    }
783	}
784    }
785    if (err) {
786	printk(KNOT_XIRC "node-id not found in CIS\n");
787	goto failure;
788    }
789    node_id = (cistpl_lan_node_id_t *)parse.funce.data;
790    if (node_id->nb != 6) {
791	printk(KNOT_XIRC "malformed node-id in CIS\n");
792	goto failure;
793    }
794    for (i=0; i < 6; i++)
795	dev->dev_addr[i] = node_id->id[i];
796
797    link->io.IOAddrLines =10;
798    link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
799    link->irq.Attributes = IRQ_HANDLE_PRESENT;
800    link->irq.IRQInfo1 = IRQ_LEVEL_ID;
801    if (local->modem) {
802	int pass;
803
804	if (do_sound) {
805	    link->conf.Attributes |= CONF_ENABLE_SPKR;
806	    link->conf.Status |= CCSR_AUDIO_ENA;
807	}
808	link->irq.Attributes |= IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED ;
809	link->io.NumPorts2 = 8;
810	link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
811	if (local->dingo) {
812	    /* Take the Modem IO port from the CIS and scan for a free
813	     * Ethernet port */
814	    link->io.NumPorts1 = 16; /* no Mako stuff anymore */
815	    tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
816	    for (err = first_tuple(link, &tuple, &parse); !err;
817				 err = next_tuple(link, &tuple, &parse)) {
818		if (cf->io.nwin > 0  &&  (cf->io.win[0].base & 0xf) == 8) {
819		    for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) {
820			link->conf.ConfigIndex = cf->index ;
821			link->io.BasePort2 = cf->io.win[0].base;
822			link->io.BasePort1 = ioaddr;
823			if (!(err=pcmcia_request_io(link, &link->io)))
824			    goto port_found;
825		    }
826		}
827	    }
828	} else {
829	    link->io.NumPorts1 = 18;
830	    /* We do 2 passes here: The first one uses the regular mapping and
831	     * the second tries again, thereby considering that the 32 ports are
832	     * mirrored every 32 bytes. Actually we use a mirrored port for
833	     * the Mako if (on the first pass) the COR bit 5 is set.
834	     */
835	    for (pass=0; pass < 2; pass++) {
836		tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
837		for (err = first_tuple(link, &tuple, &parse); !err;
838				     err = next_tuple(link, &tuple, &parse)){
839		    if (cf->io.nwin > 0  &&  (cf->io.win[0].base & 0xf) == 8){
840			link->conf.ConfigIndex = cf->index ;
841			link->io.BasePort2 = cf->io.win[0].base;
842			link->io.BasePort1 = link->io.BasePort2
843				    + (pass ? (cf->index & 0x20 ? -24:8)
844					    : (cf->index & 0x20 ?   8:-24));
845			if (!(err=pcmcia_request_io(link, &link->io)))
846			    goto port_found;
847		    }
848		}
849	    }
850	    /* if special option:
851	     * try to configure as Ethernet only.
852	     * .... */
853	}
854	printk(KNOT_XIRC "no ports available\n");
855    } else {
856	link->irq.Attributes |= IRQ_TYPE_EXCLUSIVE;
857	link->io.NumPorts1 = 16;
858	for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) {
859	    link->io.BasePort1 = ioaddr;
860	    if (!(err=pcmcia_request_io(link, &link->io)))
861		goto port_found;
862	}
863	link->io.BasePort1 = 0; /* let CS decide */
864	if ((err=pcmcia_request_io(link, &link->io))) {
865	    cs_error(link, RequestIO, err);
866	    goto config_error;
867	}
868    }
869  port_found:
870    if (err)
871	 goto config_error;
872
873    /****************
874     * Now allocate an interrupt line.	Note that this does not
875     * actually assign a handler to the interrupt.
876     */
877    if ((err=pcmcia_request_irq(link, &link->irq))) {
878	cs_error(link, RequestIRQ, err);
879	goto config_error;
880    }
881
882    /****************
883     * This actually configures the PCMCIA socket -- setting up
884     * the I/O windows and the interrupt mapping.
885     */
886    if ((err=pcmcia_request_configuration(link, &link->conf))) {
887	cs_error(link, RequestConfiguration, err);
888	goto config_error;
889    }
890
891    if (local->dingo) {
892	conf_reg_t reg;
893	win_req_t req;
894	memreq_t mem;
895
896	/* Reset the modem's BAR to the correct value
897	 * This is necessary because in the RequestConfiguration call,
898	 * the base address of the ethernet port (BasePort1) is written
899	 * to the BAR registers of the modem.
900	 */
901	reg.Action = CS_WRITE;
902	reg.Offset = CISREG_IOBASE_0;
903	reg.Value = link->io.BasePort2 & 0xff;
904	if ((err = pcmcia_access_configuration_register(link, &reg))) {
905	    cs_error(link, AccessConfigurationRegister, err);
906	    goto config_error;
907	}
908	reg.Action = CS_WRITE;
909	reg.Offset = CISREG_IOBASE_1;
910	reg.Value = (link->io.BasePort2 >> 8) & 0xff;
911	if ((err = pcmcia_access_configuration_register(link, &reg))) {
912	    cs_error(link, AccessConfigurationRegister, err);
913	    goto config_error;
914	}
915
916	/* There is no config entry for the Ethernet part which
917	 * is at 0x0800. So we allocate a window into the attribute
918	 * memory and write direct to the CIS registers
919	 */
920	req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
921	req.Base = req.Size = 0;
922	req.AccessSpeed = 0;
923	if ((err = pcmcia_request_window(&link, &req, &link->win))) {
924	    cs_error(link, RequestWindow, err);
925	    goto config_error;
926	}
927	local->dingo_ccr = ioremap(req.Base,0x1000) + 0x0800;
928	mem.CardOffset = 0x0;
929	mem.Page = 0;
930	if ((err = pcmcia_map_mem_page(link->win, &mem))) {
931	    cs_error(link, MapMemPage, err);
932	    goto config_error;
933	}
934
935	/* Setup the CCRs; there are no infos in the CIS about the Ethernet
936	 * part.
937	 */
938	writeb(0x47, local->dingo_ccr + CISREG_COR);
939	ioaddr = link->io.BasePort1;
940	writeb(ioaddr & 0xff	  , local->dingo_ccr + CISREG_IOBASE_0);
941	writeb((ioaddr >> 8)&0xff , local->dingo_ccr + CISREG_IOBASE_1);
942
943      #if 0
944	{
945	    u_char tmp;
946	    printk(KERN_INFO "ECOR:");
947	    for (i=0; i < 7; i++) {
948		tmp = readb(local->dingo_ccr + i*2);
949		printk(" %02x", tmp);
950	    }
951	    printk("\n");
952	    printk(KERN_INFO "DCOR:");
953	    for (i=0; i < 4; i++) {
954		tmp = readb(local->dingo_ccr + 0x20 + i*2);
955		printk(" %02x", tmp);
956	    }
957	    printk("\n");
958	    printk(KERN_INFO "SCOR:");
959	    for (i=0; i < 10; i++) {
960		tmp = readb(local->dingo_ccr + 0x40 + i*2);
961		printk(" %02x", tmp);
962	    }
963	    printk("\n");
964	}
965      #endif
966
967	writeb(0x01, local->dingo_ccr + 0x20);
968	writeb(0x0c, local->dingo_ccr + 0x22);
969	writeb(0x00, local->dingo_ccr + 0x24);
970	writeb(0x00, local->dingo_ccr + 0x26);
971	writeb(0x00, local->dingo_ccr + 0x28);
972    }
973
974    /* The if_port symbol can be set when the module is loaded */
975    local->probe_port=0;
976    if (!if_port) {
977	local->probe_port = dev->if_port = 1;
978    } else if ((if_port >= 1 && if_port <= 2) ||
979	       (local->mohawk && if_port==4))
980	dev->if_port = if_port;
981    else
982	printk(KNOT_XIRC "invalid if_port requested\n");
983
984    /* we can now register the device with the net subsystem */
985    dev->irq = link->irq.AssignedIRQ;
986    dev->base_addr = link->io.BasePort1;
987
988    if (local->dingo)
989	do_reset(dev, 1); /* a kludge to make the cem56 work */
990
991    link->dev_node = &local->node;
992    SET_NETDEV_DEV(dev, &handle_to_dev(link));
993
994    if ((err=register_netdev(dev))) {
995	printk(KNOT_XIRC "register_netdev() failed\n");
996	link->dev_node = NULL;
997	goto config_error;
998    }
999
1000    strcpy(local->node.dev_name, dev->name);
1001
1002    /* give some infos about the hardware */
1003    printk(KERN_INFO "%s: %s: port %#3lx, irq %d, hwaddr",
1004	 dev->name, local->manf_str,(u_long)dev->base_addr, (int)dev->irq);
1005    for (i = 0; i < 6; i++)
1006	printk("%c%02X", i?':':' ', dev->dev_addr[i]);
1007    printk("\n");
1008
1009    return 0;
1010
1011  config_error:
1012    xirc2ps_release(link);
1013    return -ENODEV;
1014
1015  failure:
1016    return -ENODEV;
1017} /* xirc2ps_config */
1018
1019/****************
1020 * After a card is removed, xirc2ps_release() will unregister the net
1021 * device, and release the PCMCIA configuration.  If the device is
1022 * still open, this will be postponed until it is closed.
1023 */
1024static void
1025xirc2ps_release(struct pcmcia_device *link)
1026{
1027	DEBUG(0, "release(0x%p)\n", link);
1028
1029	if (link->win) {
1030		struct net_device *dev = link->priv;
1031		local_info_t *local = netdev_priv(dev);
1032		if (local->dingo)
1033			iounmap(local->dingo_ccr - 0x0800);
1034	}
1035	pcmcia_disable_device(link);
1036} /* xirc2ps_release */
1037
1038/*====================================================================*/
1039
1040
1041static int xirc2ps_suspend(struct pcmcia_device *link)
1042{
1043	struct net_device *dev = link->priv;
1044
1045	if (link->open) {
1046		netif_device_detach(dev);
1047		do_powerdown(dev);
1048	}
1049
1050	return 0;
1051}
1052
1053static int xirc2ps_resume(struct pcmcia_device *link)
1054{
1055	struct net_device *dev = link->priv;
1056
1057	if (link->open) {
1058		do_reset(dev,1);
1059		netif_device_attach(dev);
1060	}
1061
1062	return 0;
1063}
1064
1065
1066/*====================================================================*/
1067
1068/****************
1069 * This is the Interrupt service route.
1070 */
1071static irqreturn_t
1072xirc2ps_interrupt(int irq, void *dev_id)
1073{
1074    struct net_device *dev = (struct net_device *)dev_id;
1075    local_info_t *lp = netdev_priv(dev);
1076    kio_addr_t ioaddr;
1077    u_char saved_page;
1078    unsigned bytes_rcvd;
1079    unsigned int_status, eth_status, rx_status, tx_status;
1080    unsigned rsr, pktlen;
1081    ulong start_ticks = jiffies;
1082
1083    if (!netif_device_present(dev))
1084	return IRQ_HANDLED;
1085
1086    ioaddr = dev->base_addr;
1087    if (lp->mohawk) { /* must disable the interrupt */
1088	PutByte(XIRCREG_CR, 0);
1089    }
1090
1091    DEBUG(6, "%s: interrupt %d at %#x.\n", dev->name, irq, ioaddr);
1092
1093    saved_page = GetByte(XIRCREG_PR);
1094    /* Read the ISR to see whats the cause for the interrupt.
1095     * This also clears the interrupt flags on CE2 cards
1096     */
1097    int_status = GetByte(XIRCREG_ISR);
1098    bytes_rcvd = 0;
1099  loop_entry:
1100    if (int_status == 0xff) { /* card may be ejected */
1101	DEBUG(3, "%s: interrupt %d for dead card\n", dev->name, irq);
1102	goto leave;
1103    }
1104    eth_status = GetByte(XIRCREG_ESR);
1105
1106    SelectPage(0x40);
1107    rx_status  = GetByte(XIRCREG40_RXST0);
1108    PutByte(XIRCREG40_RXST0, (~rx_status & 0xff));
1109    tx_status = GetByte(XIRCREG40_TXST0);
1110    tx_status |= GetByte(XIRCREG40_TXST1) << 8;
1111    PutByte(XIRCREG40_TXST0, 0);
1112    PutByte(XIRCREG40_TXST1, 0);
1113
1114    DEBUG(3, "%s: ISR=%#2.2x ESR=%#2.2x RSR=%#2.2x TSR=%#4.4x\n",
1115	  dev->name, int_status, eth_status, rx_status, tx_status);
1116
1117    /***** receive section ******/
1118    SelectPage(0);
1119    while (eth_status & FullPktRcvd) {
1120	rsr = GetByte(XIRCREG0_RSR);
1121	if (bytes_rcvd > maxrx_bytes && (rsr & PktRxOk)) {
1122	    /* too many bytes received during this int, drop the rest of the
1123	     * packets */
1124	    lp->stats.rx_dropped++;
1125	    DEBUG(2, "%s: RX drop, too much done\n", dev->name);
1126	} else if (rsr & PktRxOk) {
1127	    struct sk_buff *skb;
1128
1129	    pktlen = GetWord(XIRCREG0_RBC);
1130	    bytes_rcvd += pktlen;
1131
1132	    DEBUG(5, "rsr=%#02x packet_length=%u\n", rsr, pktlen);
1133
1134	    skb = dev_alloc_skb(pktlen+3); /* 1 extra so we can use insw */
1135	    if (!skb) {
1136		printk(KNOT_XIRC "low memory, packet dropped (size=%u)\n",
1137		       pktlen);
1138		lp->stats.rx_dropped++;
1139	    } else { /* okay get the packet */
1140		skb_reserve(skb, 2);
1141		if (lp->silicon == 0 ) {
1142		    unsigned rhsa; /* receive start address */
1143
1144		    SelectPage(5);
1145		    rhsa = GetWord(XIRCREG5_RHSA0);
1146		    SelectPage(0);
1147		    rhsa += 3; /* skip control infos */
1148		    if (rhsa >= 0x8000)
1149			rhsa = 0;
1150		    if (rhsa + pktlen > 0x8000) {
1151			unsigned i;
1152			u_char *buf = skb_put(skb, pktlen);
1153			for (i=0; i < pktlen ; i++, rhsa++) {
1154			    buf[i] = GetByte(XIRCREG_EDP);
1155			    if (rhsa == 0x8000) {
1156				rhsa = 0;
1157				i--;
1158			    }
1159			}
1160		    } else {
1161			insw(ioaddr+XIRCREG_EDP,
1162				skb_put(skb, pktlen), (pktlen+1)>>1);
1163		    }
1164		}
1165	      #if 0
1166		else if (lp->mohawk) {
1167		    /* To use this 32 bit access we should use
1168		     * a manual optimized loop
1169		     * Also the words are swapped, we can get more
1170		     * performance by using 32 bit access and swapping
1171		     * the words in a register. Will need this for cardbus
1172		     *
1173		     * Note: don't forget to change the ALLOC_SKB to .. +3
1174		     */
1175		    unsigned i;
1176		    u_long *p = skb_put(skb, pktlen);
1177		    register u_long a;
1178		    kio_addr_t edpreg = ioaddr+XIRCREG_EDP-2;
1179		    for (i=0; i < len ; i += 4, p++) {
1180			a = inl(edpreg);
1181			__asm__("rorl $16,%0\n\t"
1182				:"=q" (a)
1183				: "0" (a));
1184			*p = a;
1185		    }
1186		}
1187	      #endif
1188		else {
1189		    insw(ioaddr+XIRCREG_EDP, skb_put(skb, pktlen),
1190			    (pktlen+1)>>1);
1191		}
1192		skb->protocol = eth_type_trans(skb, dev);
1193		netif_rx(skb);
1194		dev->last_rx = jiffies;
1195		lp->stats.rx_packets++;
1196		lp->stats.rx_bytes += pktlen;
1197		if (!(rsr & PhyPkt))
1198		    lp->stats.multicast++;
1199	    }
1200	} else { /* bad packet */
1201	    DEBUG(5, "rsr=%#02x\n", rsr);
1202	}
1203	if (rsr & PktTooLong) {
1204	    lp->stats.rx_frame_errors++;
1205	    DEBUG(3, "%s: Packet too long\n", dev->name);
1206	}
1207	if (rsr & CRCErr) {
1208	    lp->stats.rx_crc_errors++;
1209	    DEBUG(3, "%s: CRC error\n", dev->name);
1210	}
1211	if (rsr & AlignErr) {
1212	    lp->stats.rx_fifo_errors++; /* okay ? */
1213	    DEBUG(3, "%s: Alignment error\n", dev->name);
1214	}
1215
1216	/* clear the received/dropped/error packet */
1217	PutWord(XIRCREG0_DO, 0x8000); /* issue cmd: skip_rx_packet */
1218
1219	/* get the new ethernet status */
1220	eth_status = GetByte(XIRCREG_ESR);
1221    }
1222    if (rx_status & 0x10) { /* Receive overrun */
1223	lp->stats.rx_over_errors++;
1224	PutByte(XIRCREG_CR, ClearRxOvrun);
1225	DEBUG(3, "receive overrun cleared\n");
1226    }
1227
1228    /***** transmit section ******/
1229    if (int_status & PktTxed) {
1230	unsigned n, nn;
1231
1232	n = lp->last_ptr_value;
1233	nn = GetByte(XIRCREG0_PTR);
1234	lp->last_ptr_value = nn;
1235	if (nn < n) /* rollover */
1236	    lp->stats.tx_packets += 256 - n;
1237	else if (n == nn) { /* happens sometimes - don't know why */
1238	    DEBUG(0, "PTR not changed?\n");
1239	} else
1240	    lp->stats.tx_packets += lp->last_ptr_value - n;
1241	netif_wake_queue(dev);
1242    }
1243    if (tx_status & 0x0002) {	/* Execessive collissions */
1244	DEBUG(0, "tx restarted due to execssive collissions\n");
1245	PutByte(XIRCREG_CR, RestartTx);  /* restart transmitter process */
1246    }
1247    if (tx_status & 0x0040)
1248	lp->stats.tx_aborted_errors++;
1249
1250    /* recalculate our work chunk so that we limit the duration of this
1251     * ISR to about 1/10 of a second.
1252     * Calculate only if we received a reasonable amount of bytes.
1253     */
1254    if (bytes_rcvd > 1000) {
1255	u_long duration = jiffies - start_ticks;
1256
1257	if (duration >= HZ/10) { /* if more than about 1/10 second */
1258	    maxrx_bytes = (bytes_rcvd * (HZ/10)) / duration;
1259	    if (maxrx_bytes < 2000)
1260		maxrx_bytes = 2000;
1261	    else if (maxrx_bytes > 22000)
1262		maxrx_bytes = 22000;
1263	    DEBUG(1, "set maxrx=%u (rcvd=%u ticks=%lu)\n",
1264		  maxrx_bytes, bytes_rcvd, duration);
1265	} else if (!duration && maxrx_bytes < 22000) {
1266	    /* now much faster */
1267	    maxrx_bytes += 2000;
1268	    if (maxrx_bytes > 22000)
1269		maxrx_bytes = 22000;
1270	    DEBUG(1, "set maxrx=%u\n", maxrx_bytes);
1271	}
1272    }
1273
1274  leave:
1275    if (lockup_hack) {
1276	if (int_status != 0xff && (int_status = GetByte(XIRCREG_ISR)) != 0)
1277	    goto loop_entry;
1278    }
1279    SelectPage(saved_page);
1280    PutByte(XIRCREG_CR, EnableIntr);  /* re-enable interrupts */
1281    /* Instead of dropping packets during a receive, we could
1282     * force an interrupt with this command:
1283     *	  PutByte(XIRCREG_CR, EnableIntr|ForceIntr);
1284     */
1285    return IRQ_HANDLED;
1286} /* xirc2ps_interrupt */
1287
1288/*====================================================================*/
1289
1290static void
1291xirc2ps_tx_timeout_task(struct work_struct *work)
1292{
1293	local_info_t *local =
1294		container_of(work, local_info_t, tx_timeout_task);
1295	struct net_device *dev = local->dev;
1296    /* reset the card */
1297    do_reset(dev,1);
1298    dev->trans_start = jiffies;
1299    netif_wake_queue(dev);
1300}
1301
1302static void
1303do_tx_timeout(struct net_device *dev)
1304{
1305    local_info_t *lp = netdev_priv(dev);
1306    lp->stats.tx_errors++;
1307    printk(KERN_NOTICE "%s: transmit timed out\n", dev->name);
1308    schedule_work(&lp->tx_timeout_task);
1309}
1310
1311static int
1312do_start_xmit(struct sk_buff *skb, struct net_device *dev)
1313{
1314    local_info_t *lp = netdev_priv(dev);
1315    kio_addr_t ioaddr = dev->base_addr;
1316    int okay;
1317    unsigned freespace;
1318    unsigned pktlen = skb->len;
1319
1320    DEBUG(1, "do_start_xmit(skb=%p, dev=%p) len=%u\n",
1321	  skb, dev, pktlen);
1322
1323
1324    if (pktlen < ETH_ZLEN)
1325    {
1326        if (skb_padto(skb, ETH_ZLEN))
1327        	return 0;
1328	pktlen = ETH_ZLEN;
1329    }
1330
1331    netif_stop_queue(dev);
1332    SelectPage(0);
1333    PutWord(XIRCREG0_TRS, (u_short)pktlen+2);
1334    freespace = GetWord(XIRCREG0_TSO);
1335    okay = freespace & 0x8000;
1336    freespace &= 0x7fff;
1337    /* TRS doesn't work - (indeed it is eliminated with sil-rev 1) */
1338    okay = pktlen +2 < freespace;
1339    DEBUG(2 + (okay ? 2 : 0), "%s: avail. tx space=%u%s\n",
1340	  dev->name, freespace, okay ? " (okay)":" (not enough)");
1341    if (!okay) { /* not enough space */
1342	return 1;  /* upper layer may decide to requeue this packet */
1343    }
1344    /* send the packet */
1345    PutWord(XIRCREG_EDP, (u_short)pktlen);
1346    outsw(ioaddr+XIRCREG_EDP, skb->data, pktlen>>1);
1347    if (pktlen & 1)
1348	PutByte(XIRCREG_EDP, skb->data[pktlen-1]);
1349
1350    if (lp->mohawk)
1351	PutByte(XIRCREG_CR, TransmitPacket|EnableIntr);
1352
1353    dev_kfree_skb (skb);
1354    dev->trans_start = jiffies;
1355    lp->stats.tx_bytes += pktlen;
1356    netif_start_queue(dev);
1357    return 0;
1358}
1359
1360static struct net_device_stats *
1361do_get_stats(struct net_device *dev)
1362{
1363    local_info_t *lp = netdev_priv(dev);
1364
1365    /*	lp->stats.rx_missed_errors = GetByte(?) */
1366    return &lp->stats;
1367}
1368
1369/****************
1370 * Set all addresses: This first one is the individual address,
1371 * the next 9 addresses are taken from the multicast list and
1372 * the rest is filled with the individual address.
1373 */
1374static void
1375set_addresses(struct net_device *dev)
1376{
1377    kio_addr_t ioaddr = dev->base_addr;
1378    local_info_t *lp = netdev_priv(dev);
1379    struct dev_mc_list *dmi = dev->mc_list;
1380    unsigned char *addr;
1381    int i,j,k,n;
1382
1383    SelectPage(k=0x50);
1384    for (i=0,j=8,n=0; ; i++, j++) {
1385	if (i > 5) {
1386	    if (++n > 9)
1387		break;
1388	    i = 0;
1389	    if (n > 1 && n <= dev->mc_count && dmi) {
1390	   	 dmi = dmi->next;
1391	    }
1392	}
1393	if (j > 15) {
1394	    j = 8;
1395	    k++;
1396	    SelectPage(k);
1397	}
1398
1399	if (n && n <= dev->mc_count && dmi)
1400	    addr = dmi->dmi_addr;
1401	else
1402	    addr = dev->dev_addr;
1403
1404	if (lp->mohawk)
1405	    PutByte(j, addr[5-i]);
1406	else
1407	    PutByte(j, addr[i]);
1408    }
1409    SelectPage(0);
1410}
1411
1412/****************
1413 * Set or clear the multicast filter for this adaptor.
1414 * We can filter up to 9 addresses, if more are requested we set
1415 * multicast promiscuous mode.
1416 */
1417
1418static void
1419set_multicast_list(struct net_device *dev)
1420{
1421    kio_addr_t ioaddr = dev->base_addr;
1422
1423    SelectPage(0x42);
1424    if (dev->flags & IFF_PROMISC) { /* snoop */
1425	PutByte(XIRCREG42_SWC1, 0x06); /* set MPE and PME */
1426    } else if (dev->mc_count > 9 || (dev->flags & IFF_ALLMULTI)) {
1427	PutByte(XIRCREG42_SWC1, 0x02); /* set MPE */
1428    } else if (dev->mc_count) {
1429	/* the chip can filter 9 addresses perfectly */
1430	PutByte(XIRCREG42_SWC1, 0x01);
1431	SelectPage(0x40);
1432	PutByte(XIRCREG40_CMD0, Offline);
1433	set_addresses(dev);
1434	SelectPage(0x40);
1435	PutByte(XIRCREG40_CMD0, EnableRecv | Online);
1436    } else { /* standard usage */
1437	PutByte(XIRCREG42_SWC1, 0x00);
1438    }
1439    SelectPage(0);
1440}
1441
1442static int
1443do_config(struct net_device *dev, struct ifmap *map)
1444{
1445    local_info_t *local = netdev_priv(dev);
1446
1447    DEBUG(0, "do_config(%p)\n", dev);
1448    if (map->port != 255 && map->port != dev->if_port) {
1449	if (map->port > 4)
1450	    return -EINVAL;
1451	if (!map->port) {
1452	    local->probe_port = 1;
1453	    dev->if_port = 1;
1454	} else {
1455	    local->probe_port = 0;
1456	    dev->if_port = map->port;
1457	}
1458	printk(KERN_INFO "%s: switching to %s port\n",
1459	       dev->name, if_names[dev->if_port]);
1460	do_reset(dev,1);  /* not the fine way :-) */
1461    }
1462    return 0;
1463}
1464
1465/****************
1466 * Open the driver
1467 */
1468static int
1469do_open(struct net_device *dev)
1470{
1471    local_info_t *lp = netdev_priv(dev);
1472    struct pcmcia_device *link = lp->p_dev;
1473
1474    DEBUG(0, "do_open(%p)\n", dev);
1475
1476    /* Check that the PCMCIA card is still here. */
1477    /* Physical device present signature. */
1478    if (!pcmcia_dev_present(link))
1479	return -ENODEV;
1480
1481    /* okay */
1482    link->open++;
1483
1484    netif_start_queue(dev);
1485    do_reset(dev,1);
1486
1487    return 0;
1488}
1489
1490static void netdev_get_drvinfo(struct net_device *dev,
1491			       struct ethtool_drvinfo *info)
1492{
1493	strcpy(info->driver, "xirc2ps_cs");
1494	sprintf(info->bus_info, "PCMCIA 0x%lx", dev->base_addr);
1495}
1496
1497static const struct ethtool_ops netdev_ethtool_ops = {
1498	.get_drvinfo		= netdev_get_drvinfo,
1499};
1500
1501static int
1502do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1503{
1504    local_info_t *local = netdev_priv(dev);
1505    kio_addr_t ioaddr = dev->base_addr;
1506    u16 *data = (u16 *)&rq->ifr_ifru;
1507
1508    DEBUG(1, "%s: ioctl(%-.6s, %#04x) %04x %04x %04x %04x\n",
1509	  dev->name, rq->ifr_ifrn.ifrn_name, cmd,
1510	  data[0], data[1], data[2], data[3]);
1511
1512    if (!local->mohawk)
1513	return -EOPNOTSUPP;
1514
1515    switch(cmd) {
1516      case SIOCGMIIPHY:		/* Get the address of the PHY in use. */
1517	data[0] = 0;		/* we have only this address */
1518	/* fall through */
1519      case SIOCGMIIREG:		/* Read the specified MII register. */
1520	data[3] = mii_rd(ioaddr, data[0] & 0x1f, data[1] & 0x1f);
1521	break;
1522      case SIOCSMIIREG:		/* Write the specified MII register */
1523	if (!capable(CAP_NET_ADMIN))
1524	    return -EPERM;
1525	mii_wr(ioaddr, data[0] & 0x1f, data[1] & 0x1f, data[2], 16);
1526	break;
1527      default:
1528	return -EOPNOTSUPP;
1529    }
1530    return 0;
1531}
1532
1533static void
1534hardreset(struct net_device *dev)
1535{
1536    local_info_t *local = netdev_priv(dev);
1537    kio_addr_t ioaddr = dev->base_addr;
1538
1539    SelectPage(4);
1540    udelay(1);
1541    PutByte(XIRCREG4_GPR1, 0);	     /* clear bit 0: power down */
1542    msleep(40);				     /* wait 40 msec */
1543    if (local->mohawk)
1544	PutByte(XIRCREG4_GPR1, 1);	 /* set bit 0: power up */
1545    else
1546	PutByte(XIRCREG4_GPR1, 1 | 4);	 /* set bit 0: power up, bit 2: AIC */
1547    msleep(20);			     /* wait 20 msec */
1548}
1549
1550static void
1551do_reset(struct net_device *dev, int full)
1552{
1553    local_info_t *local = netdev_priv(dev);
1554    kio_addr_t ioaddr = dev->base_addr;
1555    unsigned value;
1556
1557    DEBUG(0, "%s: do_reset(%p,%d)\n", dev? dev->name:"eth?", dev, full);
1558
1559    hardreset(dev);
1560    PutByte(XIRCREG_CR, SoftReset); /* set */
1561    msleep(20);			     /* wait 20 msec */
1562    PutByte(XIRCREG_CR, 0);	     /* clear */
1563    msleep(40);			     /* wait 40 msec */
1564    if (local->mohawk) {
1565	SelectPage(4);
1566	/* set pin GP1 and GP2 to output  (0x0c)
1567	 * set GP1 to low to power up the ML6692 (0x00)
1568	 * set GP2 to high to power up the 10Mhz chip  (0x02)
1569	 */
1570	PutByte(XIRCREG4_GPR0, 0x0e);
1571    }
1572
1573    /* give the circuits some time to power up */
1574    msleep(500);			/* about 500ms */
1575
1576    local->last_ptr_value = 0;
1577    local->silicon = local->mohawk ? (GetByte(XIRCREG4_BOV) & 0x70) >> 4
1578				   : (GetByte(XIRCREG4_BOV) & 0x30) >> 4;
1579
1580    if (local->probe_port) {
1581	if (!local->mohawk) {
1582	    SelectPage(4);
1583	    PutByte(XIRCREG4_GPR0, 4);
1584	    local->probe_port = 0;
1585	}
1586    } else if (dev->if_port == 2) { /* enable 10Base2 */
1587	SelectPage(0x42);
1588	PutByte(XIRCREG42_SWC1, 0xC0);
1589    } else { /* enable 10BaseT */
1590	SelectPage(0x42);
1591	PutByte(XIRCREG42_SWC1, 0x80);
1592    }
1593    msleep(40);			     /* wait 40 msec to let it complete */
1594
1595  #ifdef PCMCIA_DEBUG
1596    if (pc_debug) {
1597	SelectPage(0);
1598	value = GetByte(XIRCREG_ESR);	 /* read the ESR */
1599	printk(KERN_DEBUG "%s: ESR is: %#02x\n", dev->name, value);
1600    }
1601  #endif
1602
1603    /* setup the ECR */
1604    SelectPage(1);
1605    PutByte(XIRCREG1_IMR0, 0xff); /* allow all ints */
1606    PutByte(XIRCREG1_IMR1, 1	); /* and Set TxUnderrunDetect */
1607    value = GetByte(XIRCREG1_ECR);
1608  #if 0
1609    if (local->mohawk)
1610	value |= DisableLinkPulse;
1611    PutByte(XIRCREG1_ECR, value);
1612  #endif
1613    DEBUG(0, "%s: ECR is: %#02x\n", dev->name, value);
1614
1615    SelectPage(0x42);
1616    PutByte(XIRCREG42_SWC0, 0x20); /* disable source insertion */
1617
1618    if (local->silicon != 1) {
1619	/* set the local memory dividing line.
1620	 * The comments in the sample code say that this is only
1621	 * settable with the scipper version 2 which is revision 0.
1622	 * Always for CE3 cards
1623	 */
1624	SelectPage(2);
1625	PutWord(XIRCREG2_RBS, 0x2000);
1626    }
1627
1628    if (full)
1629	set_addresses(dev);
1630
1631    SelectPage(0);
1632    PutWord(XIRCREG0_DO, 0x2000); /* change offset command, off=0 */
1633
1634    /* setup MAC IMRs and clear status registers */
1635    SelectPage(0x40);		     /* Bit 7 ... bit 0 */
1636    PutByte(XIRCREG40_RMASK0, 0xff); /* ROK, RAB, rsv, RO, CRC, AE, PTL, MP */
1637    PutByte(XIRCREG40_TMASK0, 0xff); /* TOK, TAB, SQE, LL, TU, JAB, EXC, CRS */
1638    PutByte(XIRCREG40_TMASK1, 0xb0); /* rsv, rsv, PTD, EXT, rsv,rsv,rsv, rsv*/
1639    PutByte(XIRCREG40_RXST0,  0x00); /* ROK, RAB, REN, RO, CRC, AE, PTL, MP */
1640    PutByte(XIRCREG40_TXST0,  0x00); /* TOK, TAB, SQE, LL, TU, JAB, EXC, CRS */
1641    PutByte(XIRCREG40_TXST1,  0x00); /* TEN, rsv, PTD, EXT, retry_counter:4  */
1642
1643    if (full && local->mohawk && init_mii(dev)) {
1644	if (dev->if_port == 4 || local->dingo || local->new_mii) {
1645	    printk(KERN_INFO "%s: MII selected\n", dev->name);
1646	    SelectPage(2);
1647	    PutByte(XIRCREG2_MSR, GetByte(XIRCREG2_MSR) | 0x08);
1648	    msleep(20);
1649	} else {
1650	    printk(KERN_INFO "%s: MII detected; using 10mbs\n",
1651		   dev->name);
1652	    SelectPage(0x42);
1653	    if (dev->if_port == 2) /* enable 10Base2 */
1654		PutByte(XIRCREG42_SWC1, 0xC0);
1655	    else  /* enable 10BaseT */
1656		PutByte(XIRCREG42_SWC1, 0x80);
1657	    msleep(40);			/* wait 40 msec to let it complete */
1658	}
1659	if (full_duplex)
1660	    PutByte(XIRCREG1_ECR, GetByte(XIRCREG1_ECR | FullDuplex));
1661    } else {  /* No MII */
1662	SelectPage(0);
1663	value = GetByte(XIRCREG_ESR);	 /* read the ESR */
1664	dev->if_port = (value & MediaSelect) ? 1 : 2;
1665    }
1666
1667    /* configure the LEDs */
1668    SelectPage(2);
1669    if (dev->if_port == 1 || dev->if_port == 4) /* TP: Link and Activity */
1670	PutByte(XIRCREG2_LED, 0x3b);
1671    else			      /* Coax: Not-Collision and Activity */
1672	PutByte(XIRCREG2_LED, 0x3a);
1673
1674    if (local->dingo)
1675	PutByte(0x0b, 0x04); /* 100 Mbit LED */
1676
1677    /* enable receiver and put the mac online */
1678    if (full) {
1679	SelectPage(0x40);
1680	PutByte(XIRCREG40_CMD0, EnableRecv | Online);
1681    }
1682
1683    /* setup Ethernet IMR and enable interrupts */
1684    SelectPage(1);
1685    PutByte(XIRCREG1_IMR0, 0xff);
1686    udelay(1);
1687    SelectPage(0);
1688    PutByte(XIRCREG_CR, EnableIntr);
1689    if (local->modem && !local->dingo) { /* do some magic */
1690	if (!(GetByte(0x10) & 0x01))
1691	    PutByte(0x10, 0x11); /* unmask master-int bit */
1692    }
1693
1694    if (full)
1695	printk(KERN_INFO "%s: media %s, silicon revision %d\n",
1696	       dev->name, if_names[dev->if_port], local->silicon);
1697    /* We should switch back to page 0 to avoid a bug in revision 0
1698     * where regs with offset below 8 can't be read after an access
1699     * to the MAC registers */
1700    SelectPage(0);
1701}
1702
1703/****************
1704 * Initialize the Media-Independent-Interface
1705 * Returns: True if we have a good MII
1706 */
1707static int
1708init_mii(struct net_device *dev)
1709{
1710    local_info_t *local = netdev_priv(dev);
1711    kio_addr_t ioaddr = dev->base_addr;
1712    unsigned control, status, linkpartner;
1713    int i;
1714
1715    if (if_port == 4 || if_port == 1) { /* force 100BaseT or 10BaseT */
1716	dev->if_port = if_port;
1717	local->probe_port = 0;
1718	return 1;
1719    }
1720
1721    status = mii_rd(ioaddr,  0, 1);
1722    if ((status & 0xff00) != 0x7800)
1723	return 0; /* No MII */
1724
1725    local->new_mii = (mii_rd(ioaddr, 0, 2) != 0xffff);
1726
1727    if (local->probe_port)
1728	control = 0x1000; /* auto neg */
1729    else if (dev->if_port == 4)
1730	control = 0x2000; /* no auto neg, 100mbs mode */
1731    else
1732	control = 0x0000; /* no auto neg, 10mbs mode */
1733    mii_wr(ioaddr,  0, 0, control, 16);
1734    udelay(100);
1735    control = mii_rd(ioaddr, 0, 0);
1736
1737    if (control & 0x0400) {
1738	printk(KERN_NOTICE "%s can't take PHY out of isolation mode\n",
1739	       dev->name);
1740	local->probe_port = 0;
1741	return 0;
1742    }
1743
1744    if (local->probe_port) {
1745	for (i=0; i < 35; i++) {
1746	    msleep(100);	 /* wait 100 msec */
1747	    status = mii_rd(ioaddr,  0, 1);
1748	    if ((status & 0x0020) && (status & 0x0004))
1749		break;
1750	}
1751
1752	if (!(status & 0x0020)) {
1753	    printk(KERN_INFO "%s: autonegotiation failed;"
1754		   " using 10mbs\n", dev->name);
1755	    if (!local->new_mii) {
1756		control = 0x0000;
1757		mii_wr(ioaddr,  0, 0, control, 16);
1758		udelay(100);
1759		SelectPage(0);
1760		dev->if_port = (GetByte(XIRCREG_ESR) & MediaSelect) ? 1 : 2;
1761	    }
1762	} else {
1763	    linkpartner = mii_rd(ioaddr, 0, 5);
1764	    printk(KERN_INFO "%s: MII link partner: %04x\n",
1765		   dev->name, linkpartner);
1766	    if (linkpartner & 0x0080) {
1767		dev->if_port = 4;
1768	    } else
1769		dev->if_port = 1;
1770	}
1771    }
1772
1773    return 1;
1774}
1775
1776static void
1777do_powerdown(struct net_device *dev)
1778{
1779
1780    kio_addr_t ioaddr = dev->base_addr;
1781
1782    DEBUG(0, "do_powerdown(%p)\n", dev);
1783
1784    SelectPage(4);
1785    PutByte(XIRCREG4_GPR1, 0);	     /* clear bit 0: power down */
1786    SelectPage(0);
1787}
1788
1789static int
1790do_stop(struct net_device *dev)
1791{
1792    kio_addr_t ioaddr = dev->base_addr;
1793    local_info_t *lp = netdev_priv(dev);
1794    struct pcmcia_device *link = lp->p_dev;
1795
1796    DEBUG(0, "do_stop(%p)\n", dev);
1797
1798    if (!link)
1799	return -ENODEV;
1800
1801    netif_stop_queue(dev);
1802
1803    SelectPage(0);
1804    PutByte(XIRCREG_CR, 0);  /* disable interrupts */
1805    SelectPage(0x01);
1806    PutByte(XIRCREG1_IMR0, 0x00); /* forbid all ints */
1807    SelectPage(4);
1808    PutByte(XIRCREG4_GPR1, 0);	/* clear bit 0: power down */
1809    SelectPage(0);
1810
1811    link->open--;
1812    return 0;
1813}
1814
1815static struct pcmcia_device_id xirc2ps_ids[] = {
1816	PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0089, 0x110a),
1817	PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0138, 0x110a),
1818	PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "CEM28", 0x2e3ee845, 0x0ea978ea),
1819	PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "CEM33", 0x2e3ee845, 0x80609023),
1820	PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "CEM56", 0x2e3ee845, 0xa650c32a),
1821	PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "REM10", 0x2e3ee845, 0x76df1d29),
1822	PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "XEM5600", 0x2e3ee845, 0xf1403719),
1823	PCMCIA_PFC_DEVICE_PROD_ID12(0, "Xircom", "CreditCard Ethernet+Modem II", 0x2e3ee845, 0xeca401bf),
1824	PCMCIA_DEVICE_MANF_CARD(0x01bf, 0x010a),
1825	PCMCIA_DEVICE_PROD_ID13("Toshiba Information Systems", "TPCENET", 0x1b3b94fe, 0xf381c1a2),
1826	PCMCIA_DEVICE_PROD_ID13("Xircom", "CE3-10/100", 0x2e3ee845, 0x0ec0ac37),
1827	PCMCIA_DEVICE_PROD_ID13("Xircom", "PS-CE2-10", 0x2e3ee845, 0x947d9073),
1828	PCMCIA_DEVICE_PROD_ID13("Xircom", "R2E-100BTX", 0x2e3ee845, 0x2464a6e3),
1829	PCMCIA_DEVICE_PROD_ID13("Xircom", "RE-10", 0x2e3ee845, 0x3e08d609),
1830	PCMCIA_DEVICE_PROD_ID13("Xircom", "XE2000", 0x2e3ee845, 0xf7188e46),
1831	PCMCIA_DEVICE_PROD_ID12("Compaq", "Ethernet LAN Card", 0x54f7c49c, 0x9fd2f0a2),
1832	PCMCIA_DEVICE_PROD_ID12("Compaq", "Netelligent 10/100 PC Card", 0x54f7c49c, 0xefe96769),
1833	PCMCIA_DEVICE_PROD_ID12("Intel", "EtherExpress(TM) PRO/100 PC Card Mobile Adapter16", 0x816cc815, 0x174397db),
1834	PCMCIA_DEVICE_PROD_ID12("Toshiba", "10/100 Ethernet PC Card", 0x44a09d9c, 0xb44deecf),
1835	/* also matches CFE-10 cards! */
1836	/* PCMCIA_DEVICE_MANF_CARD(0x0105, 0x010a), */
1837	PCMCIA_DEVICE_NULL,
1838};
1839MODULE_DEVICE_TABLE(pcmcia, xirc2ps_ids);
1840
1841
1842static struct pcmcia_driver xirc2ps_cs_driver = {
1843	.owner		= THIS_MODULE,
1844	.drv		= {
1845		.name	= "xirc2ps_cs",
1846	},
1847	.probe		= xirc2ps_probe,
1848	.remove		= xirc2ps_detach,
1849	.id_table       = xirc2ps_ids,
1850	.suspend	= xirc2ps_suspend,
1851	.resume		= xirc2ps_resume,
1852};
1853
1854static int __init
1855init_xirc2ps_cs(void)
1856{
1857	return pcmcia_register_driver(&xirc2ps_cs_driver);
1858}
1859
1860static void __exit
1861exit_xirc2ps_cs(void)
1862{
1863	pcmcia_unregister_driver(&xirc2ps_cs_driver);
1864}
1865
1866module_init(init_xirc2ps_cs);
1867module_exit(exit_xirc2ps_cs);
1868
1869#ifndef MODULE
1870static int __init setup_xirc2ps_cs(char *str)
1871{
1872	/* if_port, full_duplex, do_sound, lockup_hack
1873	 */
1874	int ints[10] = { -1 };
1875
1876	str = get_options(str, 9, ints);
1877
1878#define MAYBE_SET(X,Y) if (ints[0] >= Y && ints[Y] != -1) { X = ints[Y]; }
1879	MAYBE_SET(if_port, 3);
1880	MAYBE_SET(full_duplex, 4);
1881	MAYBE_SET(do_sound, 5);
1882	MAYBE_SET(lockup_hack, 6);
1883#undef  MAYBE_SET
1884
1885	return 1;
1886}
1887
1888__setup("xirc2ps_cs=", setup_xirc2ps_cs);
1889#endif
1890