Annotation of Gnu-Mach/linux/pcmcia-cs/clients/xirc2ps_cs.c, revision 1.1

1.1     ! root        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 <[email protected]> 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/sched.h>
        !            70: #include <linux/ptrace.h>
        !            71: #include <linux/slab.h>
        !            72: #include <linux/string.h>
        !            73: #include <linux/timer.h>
        !            74: #include <linux/interrupt.h>
        !            75: #include <linux/in.h>
        !            76: #include <linux/delay.h>
        !            77: #include <asm/io.h>
        !            78: #include <asm/system.h>
        !            79: #include <asm/bitops.h>
        !            80: 
        !            81: #include <linux/netdevice.h>
        !            82: #include <linux/etherdevice.h>
        !            83: #include <linux/skbuff.h>
        !            84: #include <linux/if_arp.h>
        !            85: #include <linux/ioport.h>
        !            86: 
        !            87: #include <pcmcia/version.h>
        !            88: #include <pcmcia/cs_types.h>
        !            89: #include <pcmcia/cs.h>
        !            90: #include <pcmcia/cistpl.h>
        !            91: #include <pcmcia/cisreg.h>
        !            92: #include <pcmcia/ciscode.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) */
        !           110: enum 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) */
        !           120: enum 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 */
        !           130: enum 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) */
        !           145: enum 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 */
        !           156: enum 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) */
        !           185: enum 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: 
        !           211: static 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
        !           221: static int pc_debug = PCMCIA_DEBUG;
        !           222: MODULE_PARM(pc_debug, "i");
        !           223: #define DEBUG(n, args...) if (pc_debug>(n)) printk(KDBG_XIRC args)
        !           224: #else
        !           225: #define DEBUG(n, args...)
        !           226: #endif
        !           227: static char *version =
        !           228: "xirc2ps_cs.c 1.31 1998/12/09 19:32:55 (dd9jn+kvh)";
        !           229:            /* !--- CVS revision */
        !           230: #define KDBG_XIRC KERN_DEBUG   "xirc2ps_cs: "
        !           231: #define KERR_XIRC KERN_ERR     "xirc2ps_cs: "
        !           232: #define KWRN_XIRC KERN_WARNING "xirc2ps_cs: "
        !           233: #define KNOT_XIRC KERN_NOTICE  "xirc2ps_cs: "
        !           234: #define KINF_XIRC KERN_INFO    "xirc2ps_cs: "
        !           235: 
        !           236: /* card types */
        !           237: #define XIR_UNKNOWN  0 /* unknown: not supported */
        !           238: #define XIR_CE      1  /* (prodid 1) different hardware: not supported */
        !           239: #define XIR_CE2      2 /* (prodid 2) */
        !           240: #define XIR_CE3      3 /* (prodid 3) */
        !           241: #define XIR_CEM      4 /* (prodid 1) different hardware: not supported */
        !           242: #define XIR_CEM2     5 /* (prodid 2) */
        !           243: #define XIR_CEM3     6 /* (prodid 3) */
        !           244: #define XIR_CEM33    7 /* (prodid 4) */
        !           245: #define XIR_CEM56M   8 /* (prodid 5) */
        !           246: #define XIR_CEM56    9 /* (prodid 6) */
        !           247: #define XIR_CM28    10 /* (prodid 3) modem only: not supported here */
        !           248: #define XIR_CM33    11 /* (prodid 4) modem only: not supported here */
        !           249: #define XIR_CM56    12 /* (prodid 5) modem only: not supported here */
        !           250: #define XIR_CG     13  /* (prodid 1) GSM modem only: not supported */
        !           251: #define XIR_CBE     14 /* (prodid 1) cardbus ethernet: not supported */
        !           252: /*====================================================================*/
        !           253: 
        !           254: /* Module parameters */
        !           255: 
        !           256: MODULE_DESCRIPTION("Xircom PCMCIA ethernet driver");
        !           257: MODULE_LICENSE("Dual MPL/GPL");
        !           258: 
        !           259: #define INT_MODULE_PARM(n, v) static int n = v; MODULE_PARM(n, "i")
        !           260: 
        !           261: static int irq_list[4] = { -1 };
        !           262: MODULE_PARM(irq_list, "1-4i");
        !           263: INT_MODULE_PARM(irq_mask,      0xdeb8);
        !           264: INT_MODULE_PARM(if_port,       0);
        !           265: INT_MODULE_PARM(full_duplex,   0);
        !           266: INT_MODULE_PARM(do_sound,      1);
        !           267: INT_MODULE_PARM(lockup_hack,   0);  /* anti lockup hack */
        !           268: 
        !           269: /*====================================================================*/
        !           270: 
        !           271: /* We do not process more than these number of bytes during one
        !           272:  * interrupt. (Of course we receive complete packets, so this is not
        !           273:  * an exact value).
        !           274:  * Something between 2000..22000; first value gives best interrupt latency,
        !           275:  * the second enables the usage of the complete on-chip buffer. We use the
        !           276:  * high value as the initial value.
        !           277:  */
        !           278: static unsigned maxrx_bytes = 22000;
        !           279: 
        !           280: /* MII management prototypes */
        !           281: static void mii_idle(ioaddr_t ioaddr);
        !           282: static void mii_putbit(ioaddr_t ioaddr, unsigned data);
        !           283: static int  mii_getbit(ioaddr_t ioaddr);
        !           284: static void mii_wbits(ioaddr_t ioaddr, unsigned data, int len);
        !           285: static unsigned mii_rd(ioaddr_t ioaddr,        u_char phyaddr, u_char phyreg);
        !           286: static void mii_wr(ioaddr_t ioaddr, u_char phyaddr, u_char phyreg,
        !           287:                   unsigned data, int len);
        !           288: 
        !           289: /*
        !           290:  * The event() function is this driver's Card Services event handler.
        !           291:  * It will be called by Card Services when an appropriate card status
        !           292:  * event is received.  The config() and release() entry points are
        !           293:  * used to configure or release a socket, in response to card insertion
        !           294:  * and ejection events.  They are invoked from the event handler.
        !           295:  */
        !           296: 
        !           297: static int has_ce2_string(dev_link_t * link);
        !           298: static void xirc2ps_config(dev_link_t * link);
        !           299: static void xirc2ps_release(u_long arg);
        !           300: static int xirc2ps_event(event_t event, int priority,
        !           301:                         event_callback_args_t * args);
        !           302: 
        !           303: /****************
        !           304:  * The attach() and detach() entry points are used to create and destroy
        !           305:  * "instances" of the driver, where each instance represents everything
        !           306:  * needed to manage one actual PCMCIA card.
        !           307:  */
        !           308: 
        !           309: static dev_link_t *xirc2ps_attach(void);
        !           310: static void xirc2ps_detach(dev_link_t *);
        !           311: 
        !           312: /****************
        !           313:  * You'll also need to prototype all the functions that will actually
        !           314:  * be used to talk to your device.  See 'pcmem_cs' for a good example
        !           315:  * of a fully self-sufficient driver; the other drivers rely more or
        !           316:  * less on other parts of the kernel.
        !           317:  */
        !           318: 
        !           319: static void xirc2ps_interrupt(int irq, void *dev_id, struct pt_regs *regs);
        !           320: 
        !           321: /*
        !           322:  * The dev_info variable is the "key" that is used to match up this
        !           323:  * device driver with appropriate cards, through the card configuration
        !           324:  * database.
        !           325:  */
        !           326: 
        !           327: static dev_info_t dev_info = "xirc2ps_cs";
        !           328: 
        !           329: /****************
        !           330:  * A linked list of "instances" of the device.  Each actual
        !           331:  * PCMCIA card corresponds to one device instance, and is described
        !           332:  * by one dev_link_t structure (defined in ds.h).
        !           333:  *
        !           334:  * You may not want to use a linked list for this -- for example, the
        !           335:  * memory card driver uses an array of dev_link_t pointers, where minor
        !           336:  * device numbers are used to derive the corresponding array index.
        !           337:  */
        !           338: 
        !           339: static dev_link_t *dev_list = NULL;
        !           340: 
        !           341: /****************
        !           342:  * A dev_link_t structure has fields for most things that are needed
        !           343:  * to keep track of a socket, but there will usually be some device
        !           344:  * specific information that also needs to be kept track of.  The
        !           345:  * 'priv' pointer in a dev_link_t structure can be used to point to
        !           346:  * a device-specific private data structure, like this.
        !           347:  *
        !           348:  * A driver needs to provide a dev_node_t structure for each device
        !           349:  * on a card.  In some cases, there is only one device per card (for
        !           350:  * example, ethernet cards, modems).  In other cases, there may be
        !           351:  * many actual or logical devices (SCSI adapters, memory cards with
        !           352:  * multiple partitions).  The dev_node_t structures need to be kept
        !           353:  * in a linked list starting at the 'dev' field of a dev_link_t
        !           354:  * structure.  We allocate them in the card's private data structure,
        !           355:  * because they generally can't be allocated dynamically.
        !           356:  */
        !           357: 
        !           358: typedef struct local_info_t {
        !           359:     dev_link_t link;
        !           360:     struct net_device dev;
        !           361:     dev_node_t node;
        !           362:     struct net_device_stats stats;
        !           363:     int card_type;
        !           364:     int probe_port;
        !           365:     int silicon; /* silicon revision. 0=old CE2, 1=Scipper, 4=Mohawk */
        !           366:     int mohawk;  /* a CE3 type card */
        !           367:     int dingo;  /* a CEM56 type card */
        !           368:     int new_mii; /* has full 10baseT/100baseT MII */
        !           369:     int modem;  /* is a multi function card (i.e with a modem) */
        !           370:     caddr_t dingo_ccr; /* only used for CEM56 cards */
        !           371:     unsigned last_ptr_value; /* last packets transmitted value */
        !           372:     const char *manf_str;
        !           373: } local_info_t;
        !           374: 
        !           375: /****************
        !           376:  * Some more prototypes
        !           377:  */
        !           378: static int do_start_xmit(struct sk_buff *skb, struct net_device *dev);
        !           379: static void do_tx_timeout(struct net_device *dev);
        !           380: static struct net_device_stats *do_get_stats(struct net_device *dev);
        !           381: static void set_addresses(struct net_device *dev);
        !           382: static void set_multicast_list(struct net_device *dev);
        !           383: static int set_card_type(dev_link_t *link, const void *s);
        !           384: static int do_config(struct net_device *dev, struct ifmap *map);
        !           385: static int do_open(struct net_device *dev);
        !           386: static int do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
        !           387: static void hardreset(struct net_device *dev);
        !           388: static void do_reset(struct net_device *dev, int full);
        !           389: static int init_mii(struct net_device *dev);
        !           390: static void do_powerdown(struct net_device *dev);
        !           391: static int do_stop(struct net_device *dev);
        !           392: 
        !           393: 
        !           394: /*=============== Helper functions =========================*/
        !           395: static void
        !           396: flush_stale_links(void)
        !           397: {
        !           398:     dev_link_t *link, *next;
        !           399:     for (link = dev_list; link; link = next) {
        !           400:        next = link->next;
        !           401:        if (link->state & DEV_STALE_LINK)
        !           402:            xirc2ps_detach(link);
        !           403:     }
        !           404: }
        !           405: 
        !           406: static void
        !           407: cs_error(client_handle_t handle, int func, int ret)
        !           408: {
        !           409:     error_info_t err = { func, ret };
        !           410:     CardServices(ReportError, handle, &err);
        !           411: }
        !           412: 
        !           413: static int
        !           414: get_tuple_data(int fn, client_handle_t handle, tuple_t *tuple)
        !           415: {
        !           416:     int err;
        !           417: 
        !           418:     if ((err=CardServices(fn, handle, tuple)))
        !           419:        return err;
        !           420:     return CardServices(GetTupleData, handle, tuple);
        !           421: }
        !           422: 
        !           423: static int
        !           424: get_tuple(int fn, client_handle_t handle, tuple_t *tuple, cisparse_t *parse)
        !           425: {
        !           426:     int err;
        !           427: 
        !           428:     if ((err=get_tuple_data(fn, handle, tuple)))
        !           429:        return err;
        !           430:     return CardServices(ParseTuple, handle, tuple, parse);
        !           431: }
        !           432: 
        !           433: #define first_tuple(a, b, c) get_tuple(GetFirstTuple, a, b, c)
        !           434: #define next_tuple(a, b, c)  get_tuple(GetNextTuple, a, b, c)
        !           435: 
        !           436: #define SelectPage(pgnr)   outb((pgnr), ioaddr + XIRCREG_PR)
        !           437: #define GetByte(reg)      ((unsigned)inb(ioaddr + (reg)))
        !           438: #define GetWord(reg)      ((unsigned)inw(ioaddr + (reg)))
        !           439: #define PutByte(reg,value) outb((value), ioaddr+(reg))
        !           440: #define PutWord(reg,value) outw((value), ioaddr+(reg))
        !           441: 
        !           442: static void
        !           443: busy_loop(u_long len)
        !           444: {
        !           445: #ifdef MACH
        !           446:     /* TODO: Is this really what we want?  */
        !           447:     __udelay(1000000 / HZ *  len);
        !           448: #else
        !           449:     if (in_interrupt()) {
        !           450:        u_long timeout = jiffies + len;
        !           451:        u_long flags;
        !           452:        save_flags(flags);
        !           453:        sti();
        !           454:        while (timeout >= jiffies)
        !           455:            ;
        !           456:        restore_flags(flags);
        !           457:     } else {
        !           458:        __set_current_state(TASK_UNINTERRUPTIBLE);
        !           459:        schedule_timeout(len);
        !           460:     }
        !           461: #endif
        !           462: }
        !           463: 
        !           464: 
        !           465: /*====== Functions used for debugging =================================*/
        !           466: #if defined(PCMCIA_DEBUG) && 0 /* reading regs may change system status */
        !           467: static void
        !           468: PrintRegisters(struct net_device *dev)
        !           469: {
        !           470:     ioaddr_t ioaddr = dev->base_addr;
        !           471: 
        !           472:     if (pc_debug > 1) {
        !           473:        int i, page;
        !           474: 
        !           475:        printk(KDBG_XIRC "Register  common: ");
        !           476:        for (i = 0; i < 8; i++)
        !           477:            printk(" %2.2x", GetByte(i));
        !           478:        printk("\n");
        !           479:        for (page = 0; page <= 8; page++) {
        !           480:            printk(KDBG_XIRC "Register page %2x: ", page);
        !           481:            SelectPage(page);
        !           482:            for (i = 8; i < 16; i++)
        !           483:                printk(" %2.2x", GetByte(i));
        !           484:            printk("\n");
        !           485:        }
        !           486:        for (page=0x40 ; page <= 0x5f; page++) {
        !           487:            if (page == 0x43 || (page >= 0x46 && page <= 0x4f)
        !           488:                || (page >= 0x51 && page <=0x5e))
        !           489:                continue;
        !           490:            printk(KDBG_XIRC "Register page %2x: ", page);
        !           491:            SelectPage(page);
        !           492:            for (i = 8; i < 16; i++)
        !           493:                printk(" %2.2x", GetByte(i));
        !           494:            printk("\n");
        !           495:        }
        !           496:     }
        !           497: }
        !           498: #endif /* PCMCIA_DEBUG */
        !           499: 
        !           500: /*============== MII Management functions ===============*/
        !           501: 
        !           502: /****************
        !           503:  * Turn around for read
        !           504:  */
        !           505: static void
        !           506: mii_idle(ioaddr_t ioaddr)
        !           507: {
        !           508:     PutByte(XIRCREG2_GPR2, 0x04|0); /* drive MDCK low */
        !           509:     udelay(1);
        !           510:     PutByte(XIRCREG2_GPR2, 0x04|1); /* and drive MDCK high */
        !           511:     udelay(1);
        !           512: }
        !           513: 
        !           514: /****************
        !           515:  * Write a bit to MDI/O
        !           516:  */
        !           517: static void
        !           518: mii_putbit(ioaddr_t ioaddr, unsigned data)
        !           519: {
        !           520:   #if 1
        !           521:     if (data) {
        !           522:        PutByte(XIRCREG2_GPR2, 0x0c|2|0); /* set MDIO */
        !           523:        udelay(1);
        !           524:        PutByte(XIRCREG2_GPR2, 0x0c|2|1); /* and drive MDCK high */
        !           525:        udelay(1);
        !           526:     } else {
        !           527:        PutByte(XIRCREG2_GPR2, 0x0c|0|0); /* clear MDIO */
        !           528:        udelay(1);
        !           529:        PutByte(XIRCREG2_GPR2, 0x0c|0|1); /* and drive MDCK high */
        !           530:        udelay(1);
        !           531:     }
        !           532:   #else
        !           533:     if (data) {
        !           534:        PutWord(XIRCREG2_GPR2-1, 0x0e0e);
        !           535:        udelay(1);
        !           536:        PutWord(XIRCREG2_GPR2-1, 0x0f0f);
        !           537:        udelay(1);
        !           538:     } else {
        !           539:        PutWord(XIRCREG2_GPR2-1, 0x0c0c);
        !           540:        udelay(1);
        !           541:        PutWord(XIRCREG2_GPR2-1, 0x0d0d);
        !           542:        udelay(1);
        !           543:     }
        !           544:   #endif
        !           545: }
        !           546: 
        !           547: /****************
        !           548:  * Get a bit from MDI/O
        !           549:  */
        !           550: static int
        !           551: mii_getbit(ioaddr_t ioaddr)
        !           552: {
        !           553:     unsigned d;
        !           554: 
        !           555:     PutByte(XIRCREG2_GPR2, 4|0); /* drive MDCK low */
        !           556:     udelay(1);
        !           557:     d = GetByte(XIRCREG2_GPR2); /* read MDIO */
        !           558:     PutByte(XIRCREG2_GPR2, 4|1); /* drive MDCK high again */
        !           559:     udelay(1);
        !           560:     return d & 0x20; /* read MDIO */
        !           561: }
        !           562: 
        !           563: static void
        !           564: mii_wbits(ioaddr_t ioaddr, unsigned data, int len)
        !           565: {
        !           566:     unsigned m = 1 << (len-1);
        !           567:     for (; m; m >>= 1)
        !           568:        mii_putbit(ioaddr, data & m);
        !           569: }
        !           570: 
        !           571: static unsigned
        !           572: mii_rd(ioaddr_t ioaddr,        u_char phyaddr, u_char phyreg)
        !           573: {
        !           574:     int i;
        !           575:     unsigned data=0, m;
        !           576: 
        !           577:     SelectPage(2);
        !           578:     for (i=0; i < 32; i++)             /* 32 bit preamble */
        !           579:        mii_putbit(ioaddr, 1);
        !           580:     mii_wbits(ioaddr, 0x06, 4);        /* Start and opcode for read */
        !           581:     mii_wbits(ioaddr, phyaddr, 5);     /* PHY address to be accessed */
        !           582:     mii_wbits(ioaddr, phyreg, 5);      /* PHY register to read */
        !           583:     mii_idle(ioaddr);                  /* turn around */
        !           584:     mii_getbit(ioaddr);
        !           585: 
        !           586:     for (m = 1<<15; m; m >>= 1)
        !           587:        if (mii_getbit(ioaddr))
        !           588:            data |= m;
        !           589:     mii_idle(ioaddr);
        !           590:     return data;
        !           591: }
        !           592: 
        !           593: static void
        !           594: mii_wr(ioaddr_t ioaddr, u_char phyaddr, u_char phyreg, unsigned data, int len)
        !           595: {
        !           596:     int i;
        !           597: 
        !           598:     SelectPage(2);
        !           599:     for (i=0; i < 32; i++)             /* 32 bit preamble */
        !           600:        mii_putbit(ioaddr, 1);
        !           601:     mii_wbits(ioaddr, 0x05, 4);        /* Start and opcode for write */
        !           602:     mii_wbits(ioaddr, phyaddr, 5);     /* PHY address to be accessed */
        !           603:     mii_wbits(ioaddr, phyreg, 5);      /* PHY Register to write */
        !           604:     mii_putbit(ioaddr, 1);             /* turn around */
        !           605:     mii_putbit(ioaddr, 0);
        !           606:     mii_wbits(ioaddr, data, len);      /* And write the data */
        !           607:     mii_idle(ioaddr);
        !           608: }
        !           609: 
        !           610: /*============= Main bulk of functions =========================*/
        !           611: 
        !           612: /****************
        !           613:  * xirc2ps_attach() creates an "instance" of the driver, allocating
        !           614:  * local data structures for one device.  The device is registered
        !           615:  * with Card Services.
        !           616:  *
        !           617:  * The dev_link structure is initialized, but we don't actually
        !           618:  * configure the card at this point -- we wait until we receive a
        !           619:  * card insertion event.
        !           620:  */
        !           621: 
        !           622: static dev_link_t *
        !           623: xirc2ps_attach(void)
        !           624: {
        !           625:     client_reg_t client_reg;
        !           626:     dev_link_t *link;
        !           627:     struct net_device *dev;
        !           628:     local_info_t *local;
        !           629:     int err;
        !           630: 
        !           631:     DEBUG(0, "attach()\n");
        !           632:     flush_stale_links();
        !           633: 
        !           634:     /* Allocate the device structure */
        !           635:     local = kmalloc(sizeof(*local), GFP_KERNEL);
        !           636:     if (!local) return NULL;
        !           637:     memset(local, 0, sizeof(*local));
        !           638:     link = &local->link; dev = &local->dev;
        !           639:     link->priv = dev->priv = local;
        !           640: 
        !           641:     init_timer(&link->release);
        !           642:     link->release.function = &xirc2ps_release;
        !           643:     link->release.data = (u_long) link;
        !           644: 
        !           645:     /* General socket configuration */
        !           646:     link->conf.Attributes = CONF_ENABLE_IRQ;
        !           647:     link->conf.Vcc = 50;
        !           648:     link->conf.IntType = INT_MEMORY_AND_IO;
        !           649:     link->conf.ConfigIndex = 1;
        !           650:     link->conf.Present = PRESENT_OPTION;
        !           651:     link->irq.Handler = xirc2ps_interrupt;
        !           652:     link->irq.Instance = dev;
        !           653: 
        !           654:     /* Fill in card specific entries */
        !           655:     dev->hard_start_xmit = &do_start_xmit;
        !           656:     dev->set_config = &do_config;
        !           657:     dev->get_stats = &do_get_stats;
        !           658:     dev->do_ioctl = &do_ioctl;
        !           659:     dev->set_multicast_list = &set_multicast_list;
        !           660:     ether_setup(dev);
        !           661:     init_dev_name(dev, local->node);
        !           662:     dev->open = &do_open;
        !           663:     dev->stop = &do_stop;
        !           664: #ifdef HAVE_TX_TIMEOUT
        !           665:     dev->tx_timeout = do_tx_timeout;
        !           666:     dev->watchdog_timeo = TX_TIMEOUT;
        !           667: #endif
        !           668: 
        !           669:     /* Register with Card Services */
        !           670:     link->next = dev_list;
        !           671:     dev_list = link;
        !           672:     client_reg.dev_info = &dev_info;
        !           673:     client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE;
        !           674:     client_reg.EventMask =
        !           675:        CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
        !           676:        CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
        !           677:        CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
        !           678:     client_reg.event_handler = &xirc2ps_event;
        !           679:     client_reg.Version = 0x0210;
        !           680:     client_reg.event_callback_args.client_data = link;
        !           681:     if ((err = CardServices(RegisterClient, &link->handle, &client_reg))) {
        !           682:        cs_error(link->handle, RegisterClient, err);
        !           683:        xirc2ps_detach(link);
        !           684:        return NULL;
        !           685:     }
        !           686: 
        !           687:     return link;
        !           688: } /* xirc2ps_attach */
        !           689: 
        !           690: /****************
        !           691:  *  This deletes a driver "instance".  The device is de-registered
        !           692:  *  with Card Services.  If it has been released, all local data
        !           693:  *  structures are freed.  Otherwise, the structures will be freed
        !           694:  *  when the device is released.
        !           695:  */
        !           696: 
        !           697: static void
        !           698: xirc2ps_detach(dev_link_t * link)
        !           699: {
        !           700:     local_info_t *local = link->priv;
        !           701:     dev_link_t **linkp;
        !           702: 
        !           703:     DEBUG(0, "detach(0x%p)\n", link);
        !           704: 
        !           705:     /* Locate device structure */
        !           706:     for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
        !           707:        if (*linkp == link)
        !           708:            break;
        !           709:     if (!*linkp) {
        !           710:        DEBUG(0, "detach(0x%p): dev_link lost\n", link);
        !           711:        return;
        !           712:     }
        !           713: 
        !           714:     /*
        !           715:      * If the device is currently configured and active, we won't
        !           716:      * actually delete it yet. Instead, it is marked so that when
        !           717:      * the release() function is called, that will trigger a proper
        !           718:      * detach().
        !           719:      */
        !           720:     del_timer(&link->release);
        !           721:     if (link->state & DEV_CONFIG) {
        !           722:        DEBUG(0, "detach postponed, '%s' still locked\n",
        !           723:              link->dev->dev_name);
        !           724:        link->state |= DEV_STALE_LINK;
        !           725:        return;
        !           726:     }
        !           727: 
        !           728:     /* Break the link with Card Services */
        !           729:     if (link->handle)
        !           730:        CardServices(DeregisterClient, link->handle);
        !           731: 
        !           732:     /* Unlink device structure, free it */
        !           733:     *linkp = link->next;
        !           734:     if (link->dev)
        !           735:        unregister_netdev(&local->dev);
        !           736:     kfree(local);
        !           737: 
        !           738: } /* xirc2ps_detach */
        !           739: 
        !           740: /****************
        !           741:  * Detect the type of the card. s is the buffer with the data of tuple 0x20
        !           742:  * Returns: 0 := not supported
        !           743:  *                    mediaid=11 and prodid=47
        !           744:  * Media-Id bits:
        !           745:  *  Ethernet       0x01
        !           746:  *  Tokenring      0x02
        !           747:  *  Arcnet         0x04
        !           748:  *  Wireless       0x08
        !           749:  *  Modem          0x10
        !           750:  *  GSM only       0x20
        !           751:  * Prod-Id bits:
        !           752:  *  Pocket         0x10
        !           753:  *  External       0x20
        !           754:  *  Creditcard     0x40
        !           755:  *  Cardbus        0x80
        !           756:  *
        !           757:  */
        !           758: static int
        !           759: set_card_type(dev_link_t *link, const void *s)
        !           760: {
        !           761:     local_info_t *local = link->priv;
        !           762:   #ifdef PCMCIA_DEBUG
        !           763:     unsigned cisrev = ((const unsigned char *)s)[2];
        !           764:   #endif
        !           765:     unsigned mediaid= ((const unsigned char *)s)[3];
        !           766:     unsigned prodid = ((const unsigned char *)s)[4];
        !           767: 
        !           768:     DEBUG(0, "cisrev=%02x mediaid=%02x prodid=%02x\n",
        !           769:          cisrev, mediaid, prodid);
        !           770: 
        !           771:     local->mohawk = 0;
        !           772:     local->dingo = 0;
        !           773:     local->modem = 0;
        !           774:     local->card_type = XIR_UNKNOWN;
        !           775:     if (!(prodid & 0x40)) {
        !           776:        printk(KNOT_XIRC "Ooops: Not a creditcard\n");
        !           777:        return 0;
        !           778:     }
        !           779:     if (!(mediaid & 0x01)) {
        !           780:        printk(KNOT_XIRC "Not an Ethernet card\n");
        !           781:        return 0;
        !           782:     }
        !           783:     if (mediaid & 0x10) {
        !           784:        local->modem = 1;
        !           785:        switch(prodid & 15) {
        !           786:          case 1: local->card_type = XIR_CEM   ; break;
        !           787:          case 2: local->card_type = XIR_CEM2  ; break;
        !           788:          case 3: local->card_type = XIR_CEM3  ; break;
        !           789:          case 4: local->card_type = XIR_CEM33 ; break;
        !           790:          case 5: local->card_type = XIR_CEM56M;
        !           791:                  local->mohawk = 1;
        !           792:                  break;
        !           793:          case 6:
        !           794:          case 7: /* 7 is the RealPort 10/56 */
        !           795:                  local->card_type = XIR_CEM56 ;
        !           796:                  local->mohawk = 1;
        !           797:                  local->dingo = 1;
        !           798:                  break;
        !           799:        }
        !           800:     } else {
        !           801:        switch(prodid & 15) {
        !           802:          case 1: local->card_type = has_ce2_string(link)? XIR_CE2 : XIR_CE ;
        !           803:                  break;
        !           804:          case 15:
        !           805:          case 2: local->card_type = XIR_CE2; break;
        !           806:          case 3: local->card_type = XIR_CE3;
        !           807:                  local->mohawk = 1;
        !           808:                  break;
        !           809:        }
        !           810:     }
        !           811:     if (local->card_type == XIR_CE || local->card_type == XIR_CEM) {
        !           812:        printk(KNOT_XIRC "Sorry, this is an old CE card\n");
        !           813:        return 0;
        !           814:     }
        !           815:     if (local->card_type == XIR_UNKNOWN)
        !           816:        printk(KNOT_XIRC "unknown card (mediaid=%02x prodid=%02x)\n",
        !           817:               mediaid, prodid);
        !           818: 
        !           819:     return 1;
        !           820: }
        !           821: 
        !           822: /****************
        !           823:  * There are some CE2 cards out which claim to be a CE card.
        !           824:  * This function looks for a "CE2" in the 3rd version field.
        !           825:  * Returns: true if this is a CE2
        !           826:  */
        !           827: static int
        !           828: has_ce2_string(dev_link_t * link)
        !           829: {
        !           830:     client_handle_t handle = link->handle;
        !           831:     tuple_t tuple;
        !           832:     cisparse_t parse;
        !           833:     u_char buf[256];
        !           834: 
        !           835:     tuple.Attributes = 0;
        !           836:     tuple.TupleData = buf;
        !           837:     tuple.TupleDataMax = 254;
        !           838:     tuple.TupleOffset = 0;
        !           839:     tuple.DesiredTuple = CISTPL_VERS_1;
        !           840:     if (!first_tuple(handle, &tuple, &parse) && parse.version_1.ns > 2) {
        !           841:        if (strstr(parse.version_1.str + parse.version_1.ofs[2], "CE2"))
        !           842:            return 1;
        !           843:     }
        !           844:     return 0;
        !           845: }
        !           846: 
        !           847: /****************
        !           848:  * xirc2ps_config() is scheduled to run after a CARD_INSERTION event
        !           849:  * is received, to configure the PCMCIA socket, and to make the
        !           850:  * ethernet device available to the system.
        !           851:  */
        !           852: static void
        !           853: xirc2ps_config(dev_link_t * link)
        !           854: {
        !           855:     client_handle_t handle = link->handle;
        !           856:     local_info_t *local = link->priv;
        !           857:     struct net_device *dev = &local->dev;
        !           858:     tuple_t tuple;
        !           859:     cisparse_t parse;
        !           860:     ioaddr_t ioaddr;
        !           861:     int err, i;
        !           862:     u_char buf[64];
        !           863:     cistpl_lan_node_id_t *node_id = (cistpl_lan_node_id_t*)parse.funce.data;
        !           864:     cistpl_cftable_entry_t *cf = &parse.cftable_entry;
        !           865: 
        !           866:     local->dingo_ccr = 0;
        !           867: 
        !           868:     DEBUG(0, "config(0x%p)\n", link);
        !           869: 
        !           870:     /*
        !           871:      * This reads the card's CONFIG tuple to find its configuration
        !           872:      * registers.
        !           873:      */
        !           874:     tuple.Attributes = 0;
        !           875:     tuple.TupleData = buf;
        !           876:     tuple.TupleDataMax = 64;
        !           877:     tuple.TupleOffset = 0;
        !           878: 
        !           879:     /* Is this a valid card */
        !           880:     tuple.DesiredTuple = CISTPL_MANFID;
        !           881:     if ((err=first_tuple(handle, &tuple, &parse))) {
        !           882:        printk(KNOT_XIRC "manfid not found in CIS\n");
        !           883:        goto failure;
        !           884:     }
        !           885: 
        !           886:     switch(parse.manfid.manf) {
        !           887:       case MANFID_XIRCOM:
        !           888:        local->manf_str = "Xircom";
        !           889:        break;
        !           890:       case MANFID_ACCTON:
        !           891:        local->manf_str = "Accton";
        !           892:        break;
        !           893:       case MANFID_COMPAQ:
        !           894:       case MANFID_COMPAQ2:
        !           895:        local->manf_str = "Compaq";
        !           896:        break;
        !           897:       case MANFID_INTEL:
        !           898:        local->manf_str = "Intel";
        !           899:        break;
        !           900:       case MANFID_TOSHIBA:
        !           901:        local->manf_str = "Toshiba";
        !           902:        break;
        !           903:       default:
        !           904:        printk(KNOT_XIRC "Unknown Card Manufacturer ID: 0x%04x\n",
        !           905:               (unsigned)parse.manfid.manf);
        !           906:        goto failure;
        !           907:     }
        !           908:     DEBUG(0, "found %s card\n", local->manf_str);
        !           909: 
        !           910:     if (!set_card_type(link, buf)) {
        !           911:        printk(KNOT_XIRC "this card is not supported\n");
        !           912:        goto failure;
        !           913:     }
        !           914: 
        !           915:     /* get configuration stuff */
        !           916:     tuple.DesiredTuple = CISTPL_CONFIG;
        !           917:     if ((err=first_tuple(handle, &tuple, &parse)))
        !           918:        goto cis_error;
        !           919:     link->conf.ConfigBase = parse.config.base;
        !           920:     link->conf.Present =    parse.config.rmask[0];
        !           921: 
        !           922:     /* get the ethernet address from the CIS */
        !           923:     tuple.DesiredTuple = CISTPL_FUNCE;
        !           924:     for (err = first_tuple(handle, &tuple, &parse); !err;
        !           925:                             err = next_tuple(handle, &tuple, &parse)) {
        !           926:        /* Once I saw two CISTPL_FUNCE_LAN_NODE_ID entries:
        !           927:         * the first one with a length of zero the second correct -
        !           928:         * so I skip all entries with length 0 */
        !           929:        if (parse.funce.type == CISTPL_FUNCE_LAN_NODE_ID
        !           930:            && ((cistpl_lan_node_id_t *)parse.funce.data)->nb)
        !           931:            break;
        !           932:     }
        !           933:     if (err) { /* not found: try to get the node-id from tuple 0x89 */
        !           934:        tuple.DesiredTuple = 0x89;  /* data layout looks like tuple 0x22 */
        !           935:        if (!(err = get_tuple_data(GetFirstTuple, handle, &tuple))) {
        !           936:            if (tuple.TupleDataLen == 8 && *buf == CISTPL_FUNCE_LAN_NODE_ID)
        !           937:                memcpy(&parse, buf, 8);
        !           938:            else
        !           939:                err = -1;
        !           940:        }
        !           941:     }
        !           942:     if (err) { /* another try  (James Lehmer's CE2 version 4.1)*/
        !           943:        tuple.DesiredTuple = CISTPL_FUNCE;
        !           944:        for (err = first_tuple(handle, &tuple, &parse); !err;
        !           945:                                 err = next_tuple(handle, &tuple, &parse)) {
        !           946:            if (parse.funce.type == 0x02 && parse.funce.data[0] == 1
        !           947:                && parse.funce.data[1] == 6 && tuple.TupleDataLen == 13) {
        !           948:                buf[1] = 4;
        !           949:                memcpy(&parse, buf+1, 8);
        !           950:                break;
        !           951:            }
        !           952:        }
        !           953:     }
        !           954:     if (err) {
        !           955:        printk(KNOT_XIRC "node-id not found in CIS\n");
        !           956:        goto failure;
        !           957:     }
        !           958:     node_id = (cistpl_lan_node_id_t *)parse.funce.data;
        !           959:     if (node_id->nb != 6) {
        !           960:        printk(KNOT_XIRC "malformed node-id in CIS\n");
        !           961:        goto failure;
        !           962:     }
        !           963:     for (i=0; i < 6; i++)
        !           964:        dev->dev_addr[i] = node_id->id[i];
        !           965: 
        !           966:     /* Configure card */
        !           967:     link->state |= DEV_CONFIG;
        !           968: 
        !           969:     link->io.IOAddrLines =10;
        !           970:     link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
        !           971:     link->irq.Attributes = IRQ_HANDLE_PRESENT;
        !           972:     link->irq.IRQInfo1 = IRQ_INFO2_VALID | IRQ_LEVEL_ID;
        !           973:     if (irq_list[0] == -1)
        !           974:        link->irq.IRQInfo2 = irq_mask;
        !           975:     else {
        !           976:        for (i = 0; i < 4; i++)
        !           977:            link->irq.IRQInfo2 |= 1 << irq_list[i];
        !           978:     }
        !           979:     if (local->modem) {
        !           980:        int pass;
        !           981: 
        !           982:        if (do_sound) {
        !           983:            link->conf.Attributes |= CONF_ENABLE_SPKR;
        !           984:            link->conf.Status |= CCSR_AUDIO_ENA;
        !           985:        }
        !           986:        link->irq.Attributes |= IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED ;
        !           987:        link->io.NumPorts2 = 8;
        !           988:        link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
        !           989:        if (local->dingo) {
        !           990:            /* Take the Modem IO port from the CIS and scan for a free
        !           991:             * Ethernet port */
        !           992:            link->io.NumPorts1 = 16; /* no Mako stuff anymore */
        !           993:            tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
        !           994:            for (err = first_tuple(handle, &tuple, &parse); !err;
        !           995:                                 err = next_tuple(handle, &tuple, &parse)) {
        !           996:                if (cf->io.nwin > 0  &&  (cf->io.win[0].base & 0xf) == 8) {
        !           997:                    for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) {
        !           998:                        link->conf.ConfigIndex = cf->index ;
        !           999:                        link->io.BasePort2 = cf->io.win[0].base;
        !          1000:                        link->io.BasePort1 = ioaddr;
        !          1001:                        if (!(err=CardServices(RequestIO, link->handle,
        !          1002:                                                                &link->io)))
        !          1003:                            goto port_found;
        !          1004:                    }
        !          1005:                }
        !          1006:            }
        !          1007:        } else {
        !          1008:            link->io.NumPorts1 = 18;
        !          1009:            /* We do 2 passes here: The first one uses the regular mapping and
        !          1010:             * the second tries again, thereby considering that the 32 ports are
        !          1011:             * mirrored every 32 bytes. Actually we use a mirrored port for
        !          1012:             * the Mako if (on the first pass) the COR bit 5 is set.
        !          1013:             */
        !          1014:            for (pass=0; pass < 2; pass++) {
        !          1015:                tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
        !          1016:                for (err = first_tuple(handle, &tuple, &parse); !err;
        !          1017:                                     err = next_tuple(handle, &tuple, &parse)){
        !          1018:                    if (cf->io.nwin > 0  &&  (cf->io.win[0].base & 0xf) == 8){
        !          1019:                        link->conf.ConfigIndex = cf->index ;
        !          1020:                        link->io.BasePort2 = cf->io.win[0].base;
        !          1021:                        link->io.BasePort1 = link->io.BasePort2
        !          1022:                                    + (pass ? (cf->index & 0x20 ? -24:8)
        !          1023:                                            : (cf->index & 0x20 ?   8:-24));
        !          1024:                        if (!(err=CardServices(RequestIO, link->handle,
        !          1025:                                                                &link->io)))
        !          1026:                            goto port_found;
        !          1027:                    }
        !          1028:                }
        !          1029:            }
        !          1030:            /* if special option:
        !          1031:             * try to configure as Ethernet only.
        !          1032:             * .... */
        !          1033:        }
        !          1034:        printk(KNOT_XIRC "no ports available\n");
        !          1035:     } else {
        !          1036:        link->irq.Attributes |= IRQ_TYPE_EXCLUSIVE;
        !          1037:        link->io.NumPorts1 = 16;
        !          1038:        for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) {
        !          1039:            link->io.BasePort1 = ioaddr;
        !          1040:            if (!(err=CardServices(RequestIO, link->handle, &link->io)))
        !          1041:                goto port_found;
        !          1042:        }
        !          1043:        link->io.BasePort1 = 0; /* let CS decide */
        !          1044:        if ((err=CardServices(RequestIO, link->handle, &link->io))) {
        !          1045:            cs_error(link->handle, RequestIO, err);
        !          1046:            goto config_error;
        !          1047:        }
        !          1048:     }
        !          1049:   port_found:
        !          1050:     if (err)
        !          1051:         goto config_error;
        !          1052: 
        !          1053:     /****************
        !          1054:      * Now allocate an interrupt line. Note that this does not
        !          1055:      * actually assign a handler to the interrupt.
        !          1056:      */
        !          1057:     if ((err=CardServices(RequestIRQ, link->handle, &link->irq))) {
        !          1058:        cs_error(link->handle, RequestIRQ, err);
        !          1059:        goto config_error;
        !          1060:     }
        !          1061: 
        !          1062:     /****************
        !          1063:      * This actually configures the PCMCIA socket -- setting up
        !          1064:      * the I/O windows and the interrupt mapping.
        !          1065:      */
        !          1066:     if ((err=CardServices(RequestConfiguration,
        !          1067:                          link->handle, &link->conf))) {
        !          1068:        cs_error(link->handle, RequestConfiguration, err);
        !          1069:        goto config_error;
        !          1070:     }
        !          1071: 
        !          1072:     if (local->dingo) {
        !          1073:        conf_reg_t reg;
        !          1074:        win_req_t req;
        !          1075:        memreq_t mem;
        !          1076: 
        !          1077:        /* Reset the modem's BAR to the correct value
        !          1078:         * This is necessary because in the RequestConfiguration call,
        !          1079:         * the base address of the ethernet port (BasePort1) is written
        !          1080:         * to the BAR registers of the modem.
        !          1081:         */
        !          1082:        reg.Action = CS_WRITE;
        !          1083:        reg.Offset = CISREG_IOBASE_0;
        !          1084:        reg.Value = link->io.BasePort2 & 0xff;
        !          1085:        if ((err = CardServices(AccessConfigurationRegister, link->handle,
        !          1086:                                &reg))) {
        !          1087:            cs_error(link->handle, AccessConfigurationRegister, err);
        !          1088:            goto config_error;
        !          1089:        }
        !          1090:        reg.Action = CS_WRITE;
        !          1091:        reg.Offset = CISREG_IOBASE_1;
        !          1092:        reg.Value = (link->io.BasePort2 >> 8) & 0xff;
        !          1093:        if ((err = CardServices(AccessConfigurationRegister, link->handle,
        !          1094:                                &reg))) {
        !          1095:            cs_error(link->handle, AccessConfigurationRegister, err);
        !          1096:            goto config_error;
        !          1097:        }
        !          1098: 
        !          1099:        /* There is no config entry for the Ethernet part which
        !          1100:         * is at 0x0800. So we allocate a window into the attribute
        !          1101:         * memory and write direct to the CIS registers
        !          1102:         */
        !          1103:        req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
        !          1104:        req.Base = req.Size = 0;
        !          1105:        req.AccessSpeed = 0;
        !          1106:        link->win = (window_handle_t)link->handle;
        !          1107:        if ((err = CardServices(RequestWindow, &link->win, &req))) {
        !          1108:            cs_error(link->handle, RequestWindow, err);
        !          1109:            goto config_error;
        !          1110:        }
        !          1111:        local->dingo_ccr = ioremap(req.Base,0x1000) + 0x0800;
        !          1112:        mem.CardOffset = 0x0;
        !          1113:        mem.Page = 0;
        !          1114:        if ((err = CardServices(MapMemPage, link->win, &mem))) {
        !          1115:            cs_error(link->handle, MapMemPage, err);
        !          1116:            goto config_error;
        !          1117:        }
        !          1118: 
        !          1119:        /* Setup the CCRs; there are no infos in the CIS about the Ethernet
        !          1120:         * part.
        !          1121:         */
        !          1122:        writeb(0x47, local->dingo_ccr + CISREG_COR);
        !          1123:        ioaddr = link->io.BasePort1;
        !          1124:        writeb(ioaddr & 0xff      , local->dingo_ccr + CISREG_IOBASE_0);
        !          1125:        writeb((ioaddr >> 8)&0xff , local->dingo_ccr + CISREG_IOBASE_1);
        !          1126: 
        !          1127:       #if 0
        !          1128:        {
        !          1129:            u_char tmp;
        !          1130:            printk(KERN_INFO "ECOR:");
        !          1131:            for (i=0; i < 7; i++) {
        !          1132:                tmp = readb(local->dingo_ccr + i*2);
        !          1133:                printk(" %02x", tmp);
        !          1134:            }
        !          1135:            printk("\n");
        !          1136:            printk(KERN_INFO "DCOR:");
        !          1137:            for (i=0; i < 4; i++) {
        !          1138:                tmp = readb(local->dingo_ccr + 0x20 + i*2);
        !          1139:                printk(" %02x", tmp);
        !          1140:            }
        !          1141:            printk("\n");
        !          1142:            printk(KERN_INFO "SCOR:");
        !          1143:            for (i=0; i < 10; i++) {
        !          1144:                tmp = readb(local->dingo_ccr + 0x40 + i*2);
        !          1145:                printk(" %02x", tmp);
        !          1146:            }
        !          1147:            printk("\n");
        !          1148:        }
        !          1149:       #endif
        !          1150: 
        !          1151:        writeb(0x01, local->dingo_ccr + 0x20);
        !          1152:        writeb(0x0c, local->dingo_ccr + 0x22);
        !          1153:        writeb(0x00, local->dingo_ccr + 0x24);
        !          1154:        writeb(0x00, local->dingo_ccr + 0x26);
        !          1155:        writeb(0x00, local->dingo_ccr + 0x28);
        !          1156:     }
        !          1157: 
        !          1158:     /* The if_port symbol can be set when the module is loaded */
        !          1159:     local->probe_port=0;
        !          1160:     if (!if_port) {
        !          1161:        local->probe_port = dev->if_port = 1;
        !          1162:     } else if ((if_port >= 1 && if_port <= 2) ||
        !          1163:               (local->mohawk && if_port==4))
        !          1164:        dev->if_port = if_port;
        !          1165:     else
        !          1166:        printk(KNOT_XIRC "invalid if_port requested\n");
        !          1167: 
        !          1168:     /* we can now register the device with the net subsystem */
        !          1169:     dev->irq = link->irq.AssignedIRQ;
        !          1170:     dev->base_addr = link->io.BasePort1;
        !          1171:     if ((err=register_netdev(dev))) {
        !          1172:        printk(KNOT_XIRC "register_netdev() failed\n");
        !          1173:        goto config_error;
        !          1174:     }
        !          1175: 
        !          1176:     copy_dev_name(local->node, dev);
        !          1177:     link->dev = &local->node;
        !          1178:     link->state &= ~DEV_CONFIG_PENDING;
        !          1179: 
        !          1180:     if (local->dingo)
        !          1181:        do_reset(dev, 1); /* a kludge to make the cem56 work */
        !          1182: 
        !          1183:     /* give some infos about the hardware */
        !          1184:     printk(KERN_INFO "%s: %s: port %#3lx, irq %d, hwaddr",
        !          1185:         dev->name, local->manf_str,(u_long)dev->base_addr, (int)dev->irq);
        !          1186:     for (i = 0; i < 6; i++)
        !          1187:        printk("%c%02X", i?':':' ', dev->dev_addr[i]);
        !          1188:     printk("\n");
        !          1189: 
        !          1190:     return;
        !          1191: 
        !          1192:   config_error:
        !          1193:     link->state &= ~DEV_CONFIG_PENDING;
        !          1194:     xirc2ps_release((u_long)link);
        !          1195:     return;
        !          1196: 
        !          1197:   cis_error:
        !          1198:     printk(KNOT_XIRC "unable to parse CIS\n");
        !          1199:   failure:
        !          1200:     link->state &= ~DEV_CONFIG_PENDING;
        !          1201: } /* xirc2ps_config */
        !          1202: 
        !          1203: /****************
        !          1204:  * After a card is removed, xirc2ps_release() will unregister the net
        !          1205:  * device, and release the PCMCIA configuration.  If the device is
        !          1206:  * still open, this will be postponed until it is closed.
        !          1207:  */
        !          1208: static void
        !          1209: xirc2ps_release(u_long arg)
        !          1210: {
        !          1211:     dev_link_t *link = (dev_link_t *) arg;
        !          1212:     local_info_t *local = link->priv;
        !          1213:     struct net_device *dev = &local->dev;
        !          1214: 
        !          1215:     DEBUG(0, "release(0x%p)\n", link);
        !          1216: 
        !          1217:     /*
        !          1218:      * If the device is currently in use, we won't release until it
        !          1219:      * is actually closed.
        !          1220:      */
        !          1221:     if (link->open) {
        !          1222:        DEBUG(0, "release postponed, '%s' "
        !          1223:              "still open\n", link->dev->dev_name);
        !          1224:        link->state |= DEV_STALE_CONFIG;
        !          1225:        return;
        !          1226:     }
        !          1227: 
        !          1228:     if (link->win) {
        !          1229:        local_info_t *local = dev->priv;
        !          1230:        if (local->dingo)
        !          1231:            iounmap(local->dingo_ccr - 0x0800);
        !          1232:        CardServices(ReleaseWindow, link->win);
        !          1233:     }
        !          1234:     CardServices(ReleaseConfiguration, link->handle);
        !          1235:     CardServices(ReleaseIO, link->handle, &link->io);
        !          1236:     CardServices(ReleaseIRQ, link->handle, &link->irq);
        !          1237:     link->state &= ~DEV_CONFIG;
        !          1238: 
        !          1239: } /* xirc2ps_release */
        !          1240: 
        !          1241: /*====================================================================*/
        !          1242: 
        !          1243: /****************
        !          1244:  * The card status event handler.  Mostly, this schedules other
        !          1245:  * stuff to run after an event is received.  A CARD_REMOVAL event
        !          1246:  * also sets some flags to discourage the net drivers from trying
        !          1247:  * to talk to the card any more.
        !          1248:  *
        !          1249:  * When a CARD_REMOVAL event is received, we immediately set a flag
        !          1250:  * to block future accesses to this device.  All the functions that
        !          1251:  * actually access the device should check this flag to make sure
        !          1252:  * the card is still present.
        !          1253:  */
        !          1254: 
        !          1255: static int
        !          1256: xirc2ps_event(event_t event, int priority,
        !          1257:              event_callback_args_t * args)
        !          1258: {
        !          1259:     dev_link_t *link = args->client_data;
        !          1260:     local_info_t *lp = link->priv;
        !          1261:     struct net_device *dev = &lp->dev;
        !          1262: 
        !          1263:     DEBUG(0, "event(%d)\n", (int)event);
        !          1264: 
        !          1265:     switch (event) {
        !          1266:     case CS_EVENT_REGISTRATION_COMPLETE:
        !          1267:        DEBUG(0, "registration complete\n");
        !          1268:        break;
        !          1269:     case CS_EVENT_CARD_REMOVAL:
        !          1270:        link->state &= ~DEV_PRESENT;
        !          1271:        if (link->state & DEV_CONFIG) {
        !          1272:            netif_device_detach(dev);
        !          1273:            mod_timer(&link->release, jiffies + HZ/20);
        !          1274:        }
        !          1275:        break;
        !          1276:     case CS_EVENT_CARD_INSERTION:
        !          1277:        link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
        !          1278:        xirc2ps_config(link);
        !          1279:        break;
        !          1280:     case CS_EVENT_PM_SUSPEND:
        !          1281:        link->state |= DEV_SUSPEND;
        !          1282:        /* Fall through... */
        !          1283:     case CS_EVENT_RESET_PHYSICAL:
        !          1284:        if (link->state & DEV_CONFIG) {
        !          1285:            if (link->open) {
        !          1286:                netif_device_detach(dev);
        !          1287:                do_powerdown(dev);
        !          1288:            }
        !          1289:            CardServices(ReleaseConfiguration, link->handle);
        !          1290:        }
        !          1291:        break;
        !          1292:     case CS_EVENT_PM_RESUME:
        !          1293:        link->state &= ~DEV_SUSPEND;
        !          1294:        /* Fall through... */
        !          1295:     case CS_EVENT_CARD_RESET:
        !          1296:        if (link->state & DEV_CONFIG) {
        !          1297:            CardServices(RequestConfiguration, link->handle, &link->conf);
        !          1298:            if (link->open) {
        !          1299:                do_reset(dev,1);
        !          1300:                netif_device_attach(dev);
        !          1301:            }
        !          1302:        }
        !          1303:        break;
        !          1304:     }
        !          1305:     return 0;
        !          1306: } /* xirc2ps_event */
        !          1307: 
        !          1308: /*====================================================================*/
        !          1309: 
        !          1310: /****************
        !          1311:  * This is the Interrupt service route.
        !          1312:  */
        !          1313: static void
        !          1314: xirc2ps_interrupt(int irq, void *dev_id, struct pt_regs *regs)
        !          1315: {
        !          1316:     struct net_device *dev = (struct net_device *)dev_id;
        !          1317:     local_info_t *lp = dev->priv;
        !          1318:     ioaddr_t ioaddr;
        !          1319:     u_char saved_page;
        !          1320:     unsigned bytes_rcvd;
        !          1321:     unsigned int_status, eth_status, rx_status, tx_status;
        !          1322:     unsigned rsr, pktlen;
        !          1323:     ulong start_ticks = jiffies; /* fixme: jiffies rollover every 497 days
        !          1324:                                  * is this something to worry about?
        !          1325:                                  * -- on a laptop?
        !          1326:                                  */
        !          1327: 
        !          1328:     if (!netif_device_present(dev))
        !          1329:        return;
        !          1330: 
        !          1331:     ioaddr = dev->base_addr;
        !          1332:     if (lp->mohawk) { /* must disable the interrupt */
        !          1333:        PutByte(XIRCREG_CR, 0);
        !          1334:     }
        !          1335: 
        !          1336:     DEBUG(6, "%s: interrupt %d at %#x.\n", dev->name, irq, ioaddr);
        !          1337: 
        !          1338:     saved_page = GetByte(XIRCREG_PR);
        !          1339:     /* Read the ISR to see whats the cause for the interrupt.
        !          1340:      * This also clears the interrupt flags on CE2 cards
        !          1341:      */
        !          1342:     int_status = GetByte(XIRCREG_ISR);
        !          1343:     bytes_rcvd = 0;
        !          1344:   loop_entry:
        !          1345:     if (int_status == 0xff) { /* card may be ejected */
        !          1346:        DEBUG(3, "%s: interrupt %d for dead card\n", dev->name, irq);
        !          1347:        goto leave;
        !          1348:     }
        !          1349:     eth_status = GetByte(XIRCREG_ESR);
        !          1350: 
        !          1351:     SelectPage(0x40);
        !          1352:     rx_status  = GetByte(XIRCREG40_RXST0);
        !          1353:     PutByte(XIRCREG40_RXST0, (~rx_status & 0xff));
        !          1354:     tx_status = GetByte(XIRCREG40_TXST0);
        !          1355:     tx_status |= GetByte(XIRCREG40_TXST1) << 8;
        !          1356:     PutByte(XIRCREG40_TXST0, 0);
        !          1357:     PutByte(XIRCREG40_TXST1, 0);
        !          1358: 
        !          1359:     DEBUG(3, "%s: ISR=%#2.2x ESR=%#2.2x RSR=%#2.2x TSR=%#4.4x\n",
        !          1360:          dev->name, int_status, eth_status, rx_status, tx_status);
        !          1361: 
        !          1362:     /***** receive section ******/
        !          1363:     SelectPage(0);
        !          1364:     while (eth_status & FullPktRcvd) {
        !          1365:        rsr = GetByte(XIRCREG0_RSR);
        !          1366:        if (bytes_rcvd > maxrx_bytes && (rsr & PktRxOk)) {
        !          1367:            /* too many bytes received during this int, drop the rest of the
        !          1368:             * packets */
        !          1369:            lp->stats.rx_dropped++;
        !          1370:            DEBUG(2, "%s: RX drop, too much done\n", dev->name);
        !          1371:        } else if (rsr & PktRxOk) {
        !          1372:            struct sk_buff *skb;
        !          1373: 
        !          1374:            pktlen = GetWord(XIRCREG0_RBC);
        !          1375:            bytes_rcvd += pktlen;
        !          1376: 
        !          1377:            DEBUG(5, "rsr=%#02x packet_length=%u\n", rsr, pktlen);
        !          1378: 
        !          1379:            skb = dev_alloc_skb(pktlen+3); /* 1 extra so we can use insw */
        !          1380:            if (!skb) {
        !          1381:                printk(KNOT_XIRC "low memory, packet dropped (size=%u)\n",
        !          1382:                       pktlen);
        !          1383:                lp->stats.rx_dropped++;
        !          1384:            } else { /* okay get the packet */
        !          1385:                skb_reserve(skb, 2);
        !          1386:                if (lp->silicon == 0 ) { /* work around a hardware bug */
        !          1387:                    unsigned rhsa; /* receive start address */
        !          1388: 
        !          1389:                    SelectPage(5);
        !          1390:                    rhsa = GetWord(XIRCREG5_RHSA0);
        !          1391:                    SelectPage(0);
        !          1392:                    rhsa += 3; /* skip control infos */
        !          1393:                    if (rhsa >= 0x8000)
        !          1394:                        rhsa = 0;
        !          1395:                    if (rhsa + pktlen > 0x8000) {
        !          1396:                        unsigned i;
        !          1397:                        u_char *buf = skb_put(skb, pktlen);
        !          1398:                        for (i=0; i < pktlen ; i++, rhsa++) {
        !          1399:                            buf[i] = GetByte(XIRCREG_EDP);
        !          1400:                            if (rhsa == 0x8000) {
        !          1401:                                rhsa = 0;
        !          1402:                                i--;
        !          1403:                            }
        !          1404:                        }
        !          1405:                    } else {
        !          1406:                        insw(ioaddr+XIRCREG_EDP,
        !          1407:                             skb_put(skb, pktlen), (pktlen+1)>>1);
        !          1408:                    }
        !          1409:                }
        !          1410:              #if 0
        !          1411:                else if (lp->mohawk) {
        !          1412:                    /* To use this 32 bit access we should use
        !          1413:                     * a manual optimized loop
        !          1414:                     * Also the words are swapped, we can get more
        !          1415:                     * performance by using 32 bit access and swapping
        !          1416:                     * the words in a register. Will need this for cardbus
        !          1417:                     *
        !          1418:                     * Note: don't forget to change the ALLOC_SKB to .. +3
        !          1419:                     */
        !          1420:                    unsigned i;
        !          1421:                    u_long *p = skb_put(skb, pktlen);
        !          1422:                    register u_long a;
        !          1423:                    ioaddr_t edpreg = ioaddr+XIRCREG_EDP-2;
        !          1424:                    for (i=0; i < len ; i += 4, p++) {
        !          1425:                        a = inl(edpreg);
        !          1426:                        __asm__("rorl $16,%0\n\t"
        !          1427:                                :"=q" (a)
        !          1428:                                : "0" (a));
        !          1429:                        *p = a;
        !          1430:                    }
        !          1431:                }
        !          1432:              #endif
        !          1433:                else {
        !          1434:                    insw(ioaddr+XIRCREG_EDP, skb_put(skb, pktlen),
        !          1435:                         (pktlen+1)>>1);
        !          1436:                }
        !          1437:                skb->protocol = eth_type_trans(skb, dev);
        !          1438:                skb->dev = dev;
        !          1439:                netif_rx(skb);
        !          1440:                dev->last_rx = jiffies;
        !          1441:                lp->stats.rx_packets++;
        !          1442:                add_rx_bytes(&lp->stats, pktlen);
        !          1443:                if (!(rsr & PhyPkt))
        !          1444:                    lp->stats.multicast++;
        !          1445:            }
        !          1446:        } else { /* bad packet */
        !          1447:            DEBUG(5, "rsr=%#02x\n", rsr);
        !          1448:        }
        !          1449:        if (rsr & PktTooLong) {
        !          1450:            lp->stats.rx_frame_errors++;
        !          1451:            DEBUG(3, "%s: Packet too long\n", dev->name);
        !          1452:        }
        !          1453:        if (rsr & CRCErr) {
        !          1454:            lp->stats.rx_crc_errors++;
        !          1455:            DEBUG(3, "%s: CRC error\n", dev->name);
        !          1456:        }
        !          1457:        if (rsr & AlignErr) {
        !          1458:            lp->stats.rx_fifo_errors++; /* okay ? */
        !          1459:            DEBUG(3, "%s: Alignment error\n", dev->name);
        !          1460:        }
        !          1461: 
        !          1462:        /* clear the received/dropped/error packet */
        !          1463:        PutWord(XIRCREG0_DO, 0x8000); /* issue cmd: skip_rx_packet */
        !          1464: 
        !          1465:        /* get the new ethernet status */
        !          1466:        eth_status = GetByte(XIRCREG_ESR);
        !          1467:     }
        !          1468:     if (rx_status & 0x10) { /* Receive overrun */
        !          1469:        lp->stats.rx_over_errors++;
        !          1470:        PutByte(XIRCREG_CR, ClearRxOvrun);
        !          1471:        DEBUG(3, "receive overrun cleared\n");
        !          1472:     }
        !          1473: 
        !          1474:     /***** transmit section ******/
        !          1475:     if (int_status & PktTxed) {
        !          1476:        unsigned n, nn;
        !          1477: 
        !          1478:        n = lp->last_ptr_value;
        !          1479:        nn = GetByte(XIRCREG0_PTR);
        !          1480:        lp->last_ptr_value = nn;
        !          1481:        if (nn < n) /* rollover */
        !          1482:            lp->stats.tx_packets += 256 - n;
        !          1483:        else if (n == nn) { /* happens sometimes - don't know why */
        !          1484:            DEBUG(0, "PTR not changed?\n");
        !          1485:        } else
        !          1486:            lp->stats.tx_packets += lp->last_ptr_value - n;
        !          1487:        netif_wake_queue(dev);
        !          1488:     }
        !          1489:     if (tx_status & 0x0002) {  /* Execessive collissions */
        !          1490:        DEBUG(0, "tx restarted due to execssive collissions\n");
        !          1491:        PutByte(XIRCREG_CR, RestartTx);  /* restart transmitter process */
        !          1492:     }
        !          1493:     if (tx_status & 0x0040)
        !          1494:        lp->stats.tx_aborted_errors++;
        !          1495: 
        !          1496:     /* recalculate our work chunk so that we limit the duration of this
        !          1497:      * ISR to about 1/10 of a second.
        !          1498:      * Calculate only if we received a reasonable amount of bytes.
        !          1499:      */
        !          1500:     if (bytes_rcvd > 1000) {
        !          1501:        u_long duration = jiffies - start_ticks;
        !          1502: 
        !          1503:        if (duration >= HZ/10) { /* if more than about 1/10 second */
        !          1504:            maxrx_bytes = (bytes_rcvd * (HZ/10)) / duration;
        !          1505:            if (maxrx_bytes < 2000)
        !          1506:                maxrx_bytes = 2000;
        !          1507:            else if (maxrx_bytes > 22000)
        !          1508:                maxrx_bytes = 22000;
        !          1509:            DEBUG(1, "set maxrx=%u (rcvd=%u ticks=%lu)\n",
        !          1510:                  maxrx_bytes, bytes_rcvd, duration);
        !          1511:        } else if (!duration && maxrx_bytes < 22000) {
        !          1512:            /* now much faster */
        !          1513:            maxrx_bytes += 2000;
        !          1514:            if (maxrx_bytes > 22000)
        !          1515:                maxrx_bytes = 22000;
        !          1516:            DEBUG(1, "set maxrx=%u\n", maxrx_bytes);
        !          1517:        }
        !          1518:     }
        !          1519: 
        !          1520:   leave:
        !          1521:     if (lockup_hack) {
        !          1522:        if (int_status != 0xff && (int_status = GetByte(XIRCREG_ISR)) != 0)
        !          1523:            goto loop_entry;
        !          1524:     }
        !          1525:     SelectPage(saved_page);
        !          1526:     PutByte(XIRCREG_CR, EnableIntr);  /* re-enable interrupts */
        !          1527:     /* Instead of dropping packets during a receive, we could
        !          1528:      * force an interrupt with this command:
        !          1529:      *   PutByte(XIRCREG_CR, EnableIntr|ForceIntr);
        !          1530:      */
        !          1531: } /* xirc2ps_interrupt */
        !          1532: 
        !          1533: /*====================================================================*/
        !          1534: 
        !          1535: static void
        !          1536: do_tx_timeout(struct net_device *dev)
        !          1537: {
        !          1538:     local_info_t *lp = dev->priv;
        !          1539:     printk(KERN_NOTICE "%s: transmit timed out\n", dev->name);
        !          1540:     lp->stats.tx_errors++;
        !          1541:     /* reset the card */
        !          1542:     do_reset(dev,1);
        !          1543:     dev->trans_start = jiffies;
        !          1544:     netif_wake_queue(dev);
        !          1545: }
        !          1546: 
        !          1547: static int
        !          1548: do_start_xmit(struct sk_buff *skb, struct net_device *dev)
        !          1549: {
        !          1550:     local_info_t *lp = dev->priv;
        !          1551:     ioaddr_t ioaddr = dev->base_addr;
        !          1552:     int okay;
        !          1553:     unsigned freespace;
        !          1554:     unsigned pktlen = skb? skb->len : 0;
        !          1555: 
        !          1556:     DEBUG(1, "do_start_xmit(skb=%p, dev=%p) len=%u\n",
        !          1557:          skb, dev, pktlen);
        !          1558: 
        !          1559:     tx_timeout_check(dev, do_tx_timeout);
        !          1560:     skb_tx_check(dev, skb);
        !          1561: 
        !          1562:     /* adjust the packet length to min. required
        !          1563:      * and hope that the buffer is large enough
        !          1564:      * to provide some random data.
        !          1565:      * fixme: For Mohawk we can change this by sending
        !          1566:      * a larger packetlen than we actually have; the chip will
        !          1567:      * pad this in his buffer with random bytes
        !          1568:      */
        !          1569:     if (pktlen < ETH_ZLEN)
        !          1570:        pktlen = ETH_ZLEN;
        !          1571: 
        !          1572:     SelectPage(0);
        !          1573:     PutWord(XIRCREG0_TRS, (u_short)pktlen+2);
        !          1574:     freespace = GetWord(XIRCREG0_TSO);
        !          1575:     okay = freespace & 0x8000;
        !          1576:     freespace &= 0x7fff;
        !          1577:     /* TRS doesn't work - (indeed it is eliminated with sil-rev 1) */
        !          1578:     okay = pktlen +2 < freespace;
        !          1579:     DEBUG(2 + (okay ? 2 : 0), "%s: avail. tx space=%u%s\n",
        !          1580:          dev->name, freespace, okay ? " (okay)":" (not enough)");
        !          1581:     if (!okay) { /* not enough space */
        !          1582:        return 1;  /* upper layer may decide to requeue this packet */
        !          1583:     }
        !          1584:     /* send the packet */
        !          1585:     PutWord(XIRCREG_EDP, (u_short)pktlen);
        !          1586:     outsw(ioaddr+XIRCREG_EDP, skb->data, pktlen>>1);
        !          1587:     if (pktlen & 1)
        !          1588:        PutByte(XIRCREG_EDP, skb->data[pktlen-1]);
        !          1589: 
        !          1590:     if (lp->mohawk)
        !          1591:        PutByte(XIRCREG_CR, TransmitPacket|EnableIntr);
        !          1592: 
        !          1593:     DEV_KFREE_SKB (skb);
        !          1594:     dev->trans_start = jiffies;
        !          1595:     add_tx_bytes(&lp->stats, pktlen);
        !          1596:     netif_start_queue(dev);
        !          1597:     return 0;
        !          1598: }
        !          1599: 
        !          1600: static struct net_device_stats *
        !          1601: do_get_stats(struct net_device *dev)
        !          1602: {
        !          1603:     local_info_t *lp = dev->priv;
        !          1604: 
        !          1605:     /* lp->stats.rx_missed_errors = GetByte(?) */
        !          1606:     return &lp->stats;
        !          1607: }
        !          1608: 
        !          1609: /****************
        !          1610:  * Set all addresses: This first one is the individual address,
        !          1611:  * the next 9 addresses are taken from the multicast list and
        !          1612:  * the rest is filled with the individual address.
        !          1613:  */
        !          1614: static void
        !          1615: set_addresses(struct net_device *dev)
        !          1616: {
        !          1617:     ioaddr_t ioaddr = dev->base_addr;
        !          1618:     local_info_t *lp = dev->priv;
        !          1619:     struct dev_mc_list *dmi = dev->mc_list;
        !          1620:     char *addr;
        !          1621:     int i,j,k,n;
        !          1622: 
        !          1623:     SelectPage(k=0x50);
        !          1624:     for (i=0,j=8,n=0; ; i++, j++) {
        !          1625:        if (i > 5) {
        !          1626:            if (++n > 9)
        !          1627:                break;
        !          1628:            i = 0;
        !          1629:        }
        !          1630:        if (j > 15) {
        !          1631:            j = 8;
        !          1632:            k++;
        !          1633:            SelectPage(k);
        !          1634:        }
        !          1635: 
        !          1636:        if (n && n <= dev->mc_count && dmi) {
        !          1637:            addr = dmi->dmi_addr;
        !          1638:            dmi = dmi->next;
        !          1639:        } else
        !          1640:            addr = dev->dev_addr;
        !          1641: 
        !          1642:        if (lp->mohawk)
        !          1643:            PutByte(j, addr[5-i]);
        !          1644:        else
        !          1645:            PutByte(j, addr[i]);
        !          1646:     }
        !          1647:     SelectPage(0);
        !          1648: }
        !          1649: 
        !          1650: /****************
        !          1651:  * Set or clear the multicast filter for this adaptor.
        !          1652:  * We can filter up to 9 addresses, if more are requested we set
        !          1653:  * multicast promiscuous mode.
        !          1654:  */
        !          1655: 
        !          1656: static void
        !          1657: set_multicast_list(struct net_device *dev)
        !          1658: {
        !          1659:     ioaddr_t ioaddr = dev->base_addr;
        !          1660: 
        !          1661:     SelectPage(0x42);
        !          1662:     if (dev->flags & IFF_PROMISC) { /* snoop */
        !          1663:        PutByte(XIRCREG42_SWC1, 0x06); /* set MPE and PME */
        !          1664:     } else if (dev->mc_count > 9 || (dev->flags & IFF_ALLMULTI)) {
        !          1665:        PutByte(XIRCREG42_SWC1, 0x06); /* set MPE */
        !          1666:     } else if (dev->mc_count) {
        !          1667:        /* the chip can filter 9 addresses perfectly */
        !          1668:        PutByte(XIRCREG42_SWC1, 0x00);
        !          1669:        SelectPage(0x40);
        !          1670:        PutByte(XIRCREG40_CMD0, Offline);
        !          1671:        set_addresses(dev);
        !          1672:        SelectPage(0x40);
        !          1673:        PutByte(XIRCREG40_CMD0, EnableRecv | Online);
        !          1674:     } else { /* standard usage */
        !          1675:        PutByte(XIRCREG42_SWC1, 0x00);
        !          1676:     }
        !          1677:     SelectPage(0);
        !          1678: }
        !          1679: 
        !          1680: static int
        !          1681: do_config(struct net_device *dev, struct ifmap *map)
        !          1682: {
        !          1683:     local_info_t *local = dev->priv;
        !          1684: 
        !          1685:     DEBUG(0, "do_config(%p)\n", dev);
        !          1686:     if (map->port != 255 && map->port != dev->if_port) {
        !          1687:        if (map->port > 4)
        !          1688:            return -EINVAL;
        !          1689:        if (!map->port) {
        !          1690:            local->probe_port = 1;
        !          1691:            dev->if_port = 1;
        !          1692:        } else {
        !          1693:            local->probe_port = 0;
        !          1694:            dev->if_port = map->port;
        !          1695:        }
        !          1696:        printk(KERN_INFO "%s: switching to %s port\n",
        !          1697:               dev->name, if_names[dev->if_port]);
        !          1698:        do_reset(dev,1);  /* not the fine way :-) */
        !          1699:     }
        !          1700:     return 0;
        !          1701: }
        !          1702: 
        !          1703: /****************
        !          1704:  * Open the driver
        !          1705:  */
        !          1706: static int
        !          1707: do_open(struct net_device *dev)
        !          1708: {
        !          1709:     local_info_t *lp = dev->priv;
        !          1710:     dev_link_t *link = &lp->link;
        !          1711: 
        !          1712:     DEBUG(0, "do_open(%p)\n", dev);
        !          1713: 
        !          1714:     /* Check that the PCMCIA card is still here. */
        !          1715:     /* Physical device present signature. */
        !          1716:     if (!DEV_OK(link))
        !          1717:        return -ENODEV;
        !          1718: 
        !          1719:     /* okay */
        !          1720:     link->open++;
        !          1721:     MOD_INC_USE_COUNT;
        !          1722: 
        !          1723:     netif_start_queue(dev);
        !          1724:     netif_mark_up(dev);
        !          1725:     do_reset(dev,1);
        !          1726: 
        !          1727:     return 0;
        !          1728: }
        !          1729: 
        !          1730: static int
        !          1731: do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
        !          1732: {
        !          1733:     local_info_t *local = dev->priv;
        !          1734:     ioaddr_t ioaddr = dev->base_addr;
        !          1735:     u16 *data = (u16 *)&rq->ifr_data;
        !          1736: 
        !          1737:     DEBUG(1, "%s: ioctl(%-.6s, %#04x) %04x %04x %04x %04x\n",
        !          1738:          dev->name, rq->ifr_ifrn.ifrn_name, cmd,
        !          1739:          data[0], data[1], data[2], data[3]);
        !          1740: 
        !          1741:     if (!local->mohawk)
        !          1742:        return -EOPNOTSUPP;
        !          1743: 
        !          1744:     switch(cmd) {
        !          1745:       case SIOCDEVPRIVATE:     /* Get the address of the PHY in use. */
        !          1746:        data[0] = 0;            /* we have only this address */
        !          1747:        /* fall trough */
        !          1748:       case SIOCDEVPRIVATE+1:   /* Read the specified MII register. */
        !          1749:        data[3] = mii_rd(ioaddr, data[0] & 0x1f, data[1] & 0x1f);
        !          1750:        break;
        !          1751:       case SIOCDEVPRIVATE+2:   /* Write the specified MII register */
        !          1752:        if (!capable(CAP_NET_ADMIN))
        !          1753:            return -EPERM;
        !          1754:        mii_wr(ioaddr, data[0] & 0x1f, data[1] & 0x1f, data[2], 16);
        !          1755:        break;
        !          1756:       default:
        !          1757:        return -EOPNOTSUPP;
        !          1758:     }
        !          1759:     return 0;
        !          1760: }
        !          1761: 
        !          1762: static void
        !          1763: hardreset(struct net_device *dev)
        !          1764: {
        !          1765:     local_info_t *local = dev->priv;
        !          1766:     ioaddr_t ioaddr = dev->base_addr;
        !          1767: 
        !          1768:     SelectPage(4);
        !          1769:     udelay(1);
        !          1770:     PutByte(XIRCREG4_GPR1, 0);      /* clear bit 0: power down */
        !          1771:     busy_loop(HZ/25);               /* wait 40 msec */
        !          1772:     if (local->mohawk)
        !          1773:        PutByte(XIRCREG4_GPR1, 1);       /* set bit 0: power up */
        !          1774:     else
        !          1775:        PutByte(XIRCREG4_GPR1, 1 | 4);   /* set bit 0: power up, bit 2: AIC */
        !          1776:     busy_loop(HZ/50);               /* wait 20 msec */
        !          1777: }
        !          1778: 
        !          1779: static void
        !          1780: do_reset(struct net_device *dev, int full)
        !          1781: {
        !          1782:     local_info_t *local = dev->priv;
        !          1783:     ioaddr_t ioaddr = dev->base_addr;
        !          1784:     unsigned value;
        !          1785: 
        !          1786:     DEBUG(0, "%s: do_reset(%p,%d)\n", dev? dev->name:"eth?", dev, full);
        !          1787: 
        !          1788:     hardreset(dev);
        !          1789:     PutByte(XIRCREG_CR, SoftReset); /* set */
        !          1790:     busy_loop(HZ/50);               /* wait 20 msec */
        !          1791:     PutByte(XIRCREG_CR, 0);         /* clear */
        !          1792:     busy_loop(HZ/25);               /* wait 40 msec */
        !          1793:     if (local->mohawk) {
        !          1794:        SelectPage(4);
        !          1795:        /* set pin GP1 and GP2 to output  (0x0c)
        !          1796:         * set GP1 to low to power up the ML6692 (0x00)
        !          1797:         * set GP2 to high to power up the 10Mhz chip  (0x02)
        !          1798:         */
        !          1799:        PutByte(XIRCREG4_GPR0, 0x0e);
        !          1800:     }
        !          1801: 
        !          1802:     /* give the circuits some time to power up */
        !          1803:     busy_loop(HZ/2);           /* about 500ms */
        !          1804: 
        !          1805:     local->last_ptr_value = 0;
        !          1806:     local->silicon = local->mohawk ? (GetByte(XIRCREG4_BOV) & 0x70) >> 4
        !          1807:                                   : (GetByte(XIRCREG4_BOV) & 0x30) >> 4;
        !          1808: 
        !          1809:     if (local->probe_port) {
        !          1810:        if (!local->mohawk) {
        !          1811:            SelectPage(4);
        !          1812:            PutByte(XIRCREG4_GPR0, 4);
        !          1813:            local->probe_port = 0;
        !          1814:        }
        !          1815:     } else if (dev->if_port == 2) { /* enable 10Base2 */
        !          1816:        SelectPage(0x42);
        !          1817:        PutByte(XIRCREG42_SWC1, 0xC0);
        !          1818:     } else { /* enable 10BaseT */
        !          1819:        SelectPage(0x42);
        !          1820:        PutByte(XIRCREG42_SWC1, 0x80);
        !          1821:     }
        !          1822:     busy_loop(HZ/25);               /* wait 40 msec to let it complete */
        !          1823: 
        !          1824:   #ifdef PCMCIA_DEBUG
        !          1825:     if (pc_debug) {
        !          1826:        SelectPage(0);
        !          1827:        value = GetByte(XIRCREG_ESR);    /* read the ESR */
        !          1828:        printk(KERN_DEBUG "%s: ESR is: %#02x\n", dev->name, value);
        !          1829:     }
        !          1830:   #endif
        !          1831: 
        !          1832:     /* setup the ECR */
        !          1833:     SelectPage(1);
        !          1834:     PutByte(XIRCREG1_IMR0, 0xff); /* allow all ints */
        !          1835:     PutByte(XIRCREG1_IMR1, 1   ); /* and Set TxUnderrunDetect */
        !          1836:     value = GetByte(XIRCREG1_ECR);
        !          1837:   #if 0
        !          1838:     if (local->mohawk)
        !          1839:        value |= DisableLinkPulse;
        !          1840:     PutByte(XIRCREG1_ECR, value);
        !          1841:   #endif
        !          1842:     DEBUG(0, "%s: ECR is: %#02x\n", dev->name, value);
        !          1843: 
        !          1844:     SelectPage(0x42);
        !          1845:     PutByte(XIRCREG42_SWC0, 0x20); /* disable source insertion */
        !          1846: 
        !          1847:     if (local->silicon != 1) {
        !          1848:        /* set the local memory dividing line.
        !          1849:         * The comments in the sample code say that this is only
        !          1850:         * settable with the scipper version 2 which is revision 0.
        !          1851:         * Always for CE3 cards
        !          1852:         */
        !          1853:        SelectPage(2);
        !          1854:        PutWord(XIRCREG2_RBS, 0x2000);
        !          1855:     }
        !          1856: 
        !          1857:     if (full)
        !          1858:        set_addresses(dev);
        !          1859: 
        !          1860:     /* Hardware workaround:
        !          1861:      * The receive byte pointer after reset is off by 1 so we need
        !          1862:      * to move the offset pointer back to 0.
        !          1863:      */
        !          1864:     SelectPage(0);
        !          1865:     PutWord(XIRCREG0_DO, 0x2000); /* change offset command, off=0 */
        !          1866: 
        !          1867:     /* setup MAC IMRs and clear status registers */
        !          1868:     SelectPage(0x40);               /* Bit 7 ... bit 0 */
        !          1869:     PutByte(XIRCREG40_RMASK0, 0xff); /* ROK, RAB, rsv, RO, CRC, AE, PTL, MP */
        !          1870:     PutByte(XIRCREG40_TMASK0, 0xff); /* TOK, TAB, SQE, LL, TU, JAB, EXC, CRS */
        !          1871:     PutByte(XIRCREG40_TMASK1, 0xb0); /* rsv, rsv, PTD, EXT, rsv,rsv,rsv, rsv*/
        !          1872:     PutByte(XIRCREG40_RXST0,  0x00); /* ROK, RAB, REN, RO, CRC, AE, PTL, MP */
        !          1873:     PutByte(XIRCREG40_TXST0,  0x00); /* TOK, TAB, SQE, LL, TU, JAB, EXC, CRS */
        !          1874:     PutByte(XIRCREG40_TXST1,  0x00); /* TEN, rsv, PTD, EXT, retry_counter:4  */
        !          1875: 
        !          1876:     if (full && local->mohawk && init_mii(dev)) {
        !          1877:        if (dev->if_port == 4 || local->dingo || local->new_mii) {
        !          1878:            printk(KERN_INFO "%s: MII selected\n", dev->name);
        !          1879:            SelectPage(2);
        !          1880:            PutByte(XIRCREG2_MSR, GetByte(XIRCREG2_MSR) | 0x08);
        !          1881:            busy_loop(HZ/50);
        !          1882:        } else {
        !          1883:            printk(KERN_INFO "%s: MII detected; using 10mbs\n",
        !          1884:                   dev->name);
        !          1885:            SelectPage(0x42);
        !          1886:            if (dev->if_port == 2) /* enable 10Base2 */
        !          1887:                PutByte(XIRCREG42_SWC1, 0xC0);
        !          1888:            else  /* enable 10BaseT */
        !          1889:                PutByte(XIRCREG42_SWC1, 0x80);
        !          1890:            busy_loop(HZ/25);   /* wait 40 msec to let it complete */
        !          1891:        }
        !          1892:        if (full_duplex)
        !          1893:            PutByte(XIRCREG1_ECR, GetByte(XIRCREG1_ECR | FullDuplex));
        !          1894:     } else {  /* No MII */
        !          1895:        SelectPage(0);
        !          1896:        value = GetByte(XIRCREG_ESR);    /* read the ESR */
        !          1897:        dev->if_port = (value & MediaSelect) ? 1 : 2;
        !          1898:     }
        !          1899: 
        !          1900:     /* configure the LEDs */
        !          1901:     SelectPage(2);
        !          1902:     if (dev->if_port == 1 || dev->if_port == 4) /* TP: Link and Activity */
        !          1903:        PutByte(XIRCREG2_LED, 0x3b);
        !          1904:     else                             /* Coax: Not-Collision and Activity */
        !          1905:        PutByte(XIRCREG2_LED, 0x3a);
        !          1906: 
        !          1907:     if (local->dingo)
        !          1908:        PutByte(0x0b, 0x04); /* 100 Mbit LED */
        !          1909: 
        !          1910:     /* enable receiver and put the mac online */
        !          1911:     if (full) {
        !          1912:        SelectPage(0x40);
        !          1913:        PutByte(XIRCREG40_CMD0, EnableRecv | Online);
        !          1914:     }
        !          1915: 
        !          1916:     /* setup Ethernet IMR and enable interrupts */
        !          1917:     SelectPage(1);
        !          1918:     PutByte(XIRCREG1_IMR0, 0xff);
        !          1919:     udelay(1);
        !          1920:     SelectPage(0);
        !          1921:     PutByte(XIRCREG_CR, EnableIntr);
        !          1922:     if (local->modem && !local->dingo) { /* do some magic */
        !          1923:        if (!(GetByte(0x10) & 0x01))
        !          1924:            PutByte(0x10, 0x11); /* unmask master-int bit */
        !          1925:     }
        !          1926: 
        !          1927:     if (full)
        !          1928:        printk(KERN_INFO "%s: media %s, silicon revision %d\n",
        !          1929:               dev->name, if_names[dev->if_port], local->silicon);
        !          1930:     /* We should switch back to page 0 to avoid a bug in revision 0
        !          1931:      * where regs with offset below 8 can't be read after an access
        !          1932:      * to the MAC registers */
        !          1933:     SelectPage(0);
        !          1934: }
        !          1935: 
        !          1936: /****************
        !          1937:  * Initialize the Media-Independent-Interface
        !          1938:  * Returns: True if we have a good MII
        !          1939:  */
        !          1940: static int
        !          1941: init_mii(struct net_device *dev)
        !          1942: {
        !          1943:     local_info_t *local = dev->priv;
        !          1944:     ioaddr_t ioaddr = dev->base_addr;
        !          1945:     unsigned control, status, linkpartner;
        !          1946:     int i;
        !          1947: 
        !          1948:     if (if_port == 4 || if_port == 1) { /* force 100BaseT or 10BaseT */
        !          1949:        dev->if_port = if_port;
        !          1950:        local->probe_port = 0;
        !          1951:        return 1;
        !          1952:     }
        !          1953: 
        !          1954:     status = mii_rd(ioaddr,  0, 1);
        !          1955:     if ((status & 0xff00) != 0x7800)
        !          1956:        return 0; /* No MII */
        !          1957: 
        !          1958:     local->new_mii = (mii_rd(ioaddr, 0, 2) != 0xffff);
        !          1959:     
        !          1960:     if (local->probe_port)
        !          1961:        control = 0x1000; /* auto neg */
        !          1962:     else if (dev->if_port == 4)
        !          1963:        control = 0x2000; /* no auto neg, 100mbs mode */
        !          1964:     else
        !          1965:        control = 0x0000; /* no auto neg, 10mbs mode */
        !          1966:     mii_wr(ioaddr,  0, 0, control, 16);
        !          1967:     udelay(100);
        !          1968:     control = mii_rd(ioaddr, 0, 0);
        !          1969: 
        !          1970:     if (control & 0x0400) {
        !          1971:        printk(KERN_NOTICE "%s can't take PHY out of isolation mode\n",
        !          1972:               dev->name);
        !          1973:        local->probe_port = 0;
        !          1974:        return 0;
        !          1975:     }
        !          1976: 
        !          1977:     if (local->probe_port) {
        !          1978:        /* according to the DP83840A specs the auto negotiation process
        !          1979:         * may take up to 3.5 sec, so we use this also for our ML6692
        !          1980:         * Fixme: Better to use a timer here!
        !          1981:         */
        !          1982:        for (i=0; i < 35; i++) {
        !          1983:            busy_loop(HZ/10);    /* wait 100 msec */
        !          1984:            status = mii_rd(ioaddr,  0, 1);
        !          1985:            if ((status & 0x0020) && (status & 0x0004))
        !          1986:                break;
        !          1987:        }
        !          1988: 
        !          1989:        if (!(status & 0x0020)) {
        !          1990:            printk(KERN_INFO "%s: autonegotiation failed;"
        !          1991:                   " using 10mbs\n", dev->name);
        !          1992:            if (!local->new_mii) {
        !          1993:                control = 0x0000;
        !          1994:                mii_wr(ioaddr,  0, 0, control, 16);
        !          1995:                udelay(100);
        !          1996:                SelectPage(0);
        !          1997:                dev->if_port = (GetByte(XIRCREG_ESR) & MediaSelect) ? 1 : 2;
        !          1998:            }
        !          1999:        } else {
        !          2000:            linkpartner = mii_rd(ioaddr, 0, 5);
        !          2001:            printk(KERN_INFO "%s: MII link partner: %04x\n",
        !          2002:                   dev->name, linkpartner);
        !          2003:            if (linkpartner & 0x0080) {
        !          2004:                dev->if_port = 4;
        !          2005:            } else
        !          2006:                dev->if_port = 1;
        !          2007:        }
        !          2008:     }
        !          2009: 
        !          2010:     return 1;
        !          2011: }
        !          2012: 
        !          2013: static void
        !          2014: do_powerdown(struct net_device *dev)
        !          2015: {
        !          2016: 
        !          2017:     ioaddr_t ioaddr = dev->base_addr;
        !          2018: 
        !          2019:     DEBUG(0, "do_powerdown(%p)\n", dev);
        !          2020: 
        !          2021:     SelectPage(4);
        !          2022:     PutByte(XIRCREG4_GPR1, 0);      /* clear bit 0: power down */
        !          2023:     SelectPage(0);
        !          2024: }
        !          2025: 
        !          2026: static int
        !          2027: do_stop(struct net_device *dev)
        !          2028: {
        !          2029:     ioaddr_t ioaddr = dev->base_addr;
        !          2030:     local_info_t *lp = dev->priv;
        !          2031:     dev_link_t *link = &lp->link;
        !          2032: 
        !          2033:     DEBUG(0, "do_stop(%p)\n", dev);
        !          2034: 
        !          2035:     if (!link)
        !          2036:        return -ENODEV;
        !          2037: 
        !          2038:     netif_stop_queue(dev);
        !          2039:     netif_mark_down(dev);
        !          2040: 
        !          2041:     SelectPage(0);
        !          2042:     PutByte(XIRCREG_CR, 0);  /* disable interrupts */
        !          2043:     SelectPage(0x01);
        !          2044:     PutByte(XIRCREG1_IMR0, 0x00); /* forbid all ints */
        !          2045:     SelectPage(4);
        !          2046:     PutByte(XIRCREG4_GPR1, 0); /* clear bit 0: power down */
        !          2047:     SelectPage(0);
        !          2048: 
        !          2049:     link->open--;
        !          2050:     if (link->state & DEV_STALE_CONFIG)
        !          2051:        mod_timer(&link->release, jiffies + HZ/20);
        !          2052: 
        !          2053:     MOD_DEC_USE_COUNT;
        !          2054: 
        !          2055:     return 0;
        !          2056: }
        !          2057: 
        !          2058: static int __init
        !          2059: init_xirc2ps_cs(void)
        !          2060: {
        !          2061:     servinfo_t serv;
        !          2062: 
        !          2063:     printk(KERN_INFO "%s\n", version);
        !          2064:     if (lockup_hack)
        !          2065:        printk(KINF_XIRC "lockup hack is enabled\n");
        !          2066:     CardServices(GetCardServicesInfo, &serv);
        !          2067:     if (serv.Revision != CS_RELEASE_CODE) {
        !          2068:        printk(KNOT_XIRC "Card Services release does not match!\n");
        !          2069:        return -EINVAL;
        !          2070:     }
        !          2071:     DEBUG(0, "pc_debug=%d\n", pc_debug);
        !          2072:     register_pccard_driver(&dev_info, &xirc2ps_attach, &xirc2ps_detach);
        !          2073:     return 0;
        !          2074: }
        !          2075: 
        !          2076: static void __exit
        !          2077: exit_xirc2ps_cs(void)
        !          2078: {
        !          2079:     DEBUG(0, "unloading\n");
        !          2080:     unregister_pccard_driver(&dev_info);
        !          2081:     while (dev_list) {
        !          2082:        if (dev_list->state & DEV_CONFIG)
        !          2083:            xirc2ps_release((u_long)dev_list);
        !          2084:        if (dev_list)   /* xirc2ps_release() might already have detached... */
        !          2085:            xirc2ps_detach(dev_list);
        !          2086:     }
        !          2087: }
        !          2088: 
        !          2089: module_init(init_xirc2ps_cs);
        !          2090: module_exit(exit_xirc2ps_cs);
        !          2091: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.