Home | History | Annotate | Line # | Download | only in pcmcia
if_ne_pcmcia.c revision 1.110
      1 /*	$NetBSD: if_ne_pcmcia.c,v 1.110 2004/03/13 15:09:16 cube Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1997 Marc Horowitz.  All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. All advertising materials mentioning features or use of this software
     15  *    must display the following acknowledgement:
     16  *	This product includes software developed by Marc Horowitz.
     17  * 4. The name of the author may not be used to endorse or promote products
     18  *    derived from this software without specific prior written permission.
     19  *
     20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include <sys/cdefs.h>
     33 __KERNEL_RCSID(0, "$NetBSD: if_ne_pcmcia.c,v 1.110 2004/03/13 15:09:16 cube Exp $");
     34 
     35 #include <sys/param.h>
     36 #include <sys/systm.h>
     37 #include <sys/select.h>
     38 #include <sys/device.h>
     39 #include <sys/socket.h>
     40 
     41 #include <net/if_types.h>
     42 #include <net/if.h>
     43 #include <net/if_media.h>
     44 #include <net/if_ether.h>
     45 
     46 #include <machine/bus.h>
     47 #include <machine/intr.h>
     48 
     49 #include <dev/pcmcia/pcmciareg.h>
     50 #include <dev/pcmcia/pcmciavar.h>
     51 #include <dev/pcmcia/pcmciadevs.h>
     52 
     53 #include <dev/ic/dp8390reg.h>
     54 #include <dev/ic/dp8390var.h>
     55 
     56 #include <dev/ic/ne2000reg.h>
     57 #include <dev/ic/ne2000var.h>
     58 
     59 #include <dev/ic/rtl80x9reg.h>
     60 #include <dev/ic/rtl80x9var.h>
     61 
     62 #include <dev/ic/dl10019var.h>
     63 
     64 #include <dev/ic/ax88190reg.h>
     65 #include <dev/ic/ax88190var.h>
     66 
     67 int	ne_pcmcia_match __P((struct device *, struct cfdata *, void *));
     68 void	ne_pcmcia_attach __P((struct device *, struct device *, void *));
     69 int	ne_pcmcia_detach __P((struct device *, int));
     70 
     71 int	ne_pcmcia_enable __P((struct dp8390_softc *));
     72 void	ne_pcmcia_disable __P((struct dp8390_softc *));
     73 
     74 struct ne_pcmcia_softc {
     75 	struct ne2000_softc sc_ne2000;		/* real "ne2000" softc */
     76 
     77 	/* PCMCIA-specific goo */
     78 	struct pcmcia_io_handle sc_pcioh;	/* PCMCIA i/o information */
     79 	int sc_asic_io_window;			/* i/o window for ASIC */
     80 	int sc_nic_io_window;			/* i/o window for NIC */
     81 	struct pcmcia_function *sc_pf;		/* our PCMCIA function */
     82 	void *sc_ih;				/* interrupt handle */
     83 };
     84 
     85 u_int8_t *
     86 	ne_pcmcia_get_enaddr __P((struct ne_pcmcia_softc *, int,
     87 	    u_int8_t [ETHER_ADDR_LEN]));
     88 u_int8_t *
     89 	ne_pcmcia_dl10019_get_enaddr __P((struct ne_pcmcia_softc *,
     90 	    u_int8_t [ETHER_ADDR_LEN]));
     91 int	ne_pcmcia_ax88190_set_iobase __P((struct ne_pcmcia_softc *));
     92 
     93 CFATTACH_DECL(ne_pcmcia, sizeof(struct ne_pcmcia_softc),
     94     ne_pcmcia_match, ne_pcmcia_attach, ne_pcmcia_detach, dp8390_activate);
     95 
     96 static const struct ne2000dev {
     97     char *name;
     98     int32_t manufacturer;
     99     int32_t product;
    100     char *cis_info[4];
    101     int function;
    102     int enet_maddr;
    103     unsigned char enet_vendor[3];
    104     int flags;
    105 #define	NE2000DVF_DL10019	0x0001		/* chip is D-Link DL10019 */
    106 #define	NE2000DVF_AX88190	0x0002		/* chip is ASIX AX88190 */
    107 #define	NE2000DVF_AX88790	0x0004		/* chip is ASIX AX88790 */
    108 } ne2000devs[] = {
    109     { PCMCIA_STR_EDIMAX_EP4000A,
    110       PCMCIA_VENDOR_EDIMAX, PCMCIA_PRODUCT_EDIMAX_EP4000A,
    111       PCMCIA_CIS_EDIMAX_EP4000A,
    112       0, -1, { 0x00, 0xa0, 0x0c } },
    113 
    114     { PCMCIA_STR_SYNERGY21_S21810,
    115       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    116       PCMCIA_CIS_SYNERGY21_S21810,
    117       0, -1, { 0x00, 0x48, 0x54 } },
    118 
    119     { PCMCIA_STR_AMBICOM_AMB8002T,
    120       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    121       PCMCIA_CIS_AMBICOM_AMB8002T,
    122       0, -1, { 0x00, 0x10, 0x7a } },
    123 
    124     { PCMCIA_STR_PREMAX_PE200,
    125       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    126       PCMCIA_CIS_PREMAX_PE200,
    127       0, 0x07f0, { 0x00, 0x20, 0xe0 } },
    128 
    129     { PCMCIA_STR_DIGITAL_DEPCMXX,
    130       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    131       PCMCIA_CIS_DIGITAL_DEPCMXX,
    132       0, 0x0ff0, { 0x00, 0x00, 0xe8 } },
    133 
    134     { PCMCIA_STR_PLANET_SMARTCOM2000,
    135       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    136       PCMCIA_CIS_PLANET_SMARTCOM2000,
    137       0, 0xff0, { 0x00, 0x00, 0xe8 } },
    138 
    139     { PCMCIA_STR_DLINK_DE660,
    140       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    141       PCMCIA_CIS_DLINK_DE660,
    142       0, -1, { 0x00, 0x80, 0xc8 } },
    143 
    144     { PCMCIA_STR_DLINK_DE660PLUS,
    145       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    146       PCMCIA_CIS_DLINK_DE660PLUS,
    147       0, -1, { 0x00, 0x80, 0xc8 } },
    148 
    149     { PCMCIA_STR_RPTI_EP400,
    150       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    151       PCMCIA_CIS_RPTI_EP400,
    152       0, -1, { 0x00, 0x40, 0x95 } },
    153 
    154     { PCMCIA_STR_RPTI_EP401,
    155       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    156       PCMCIA_CIS_RPTI_EP401,
    157       0, -1, { 0x00, 0x40, 0x95 } },
    158 
    159     { PCMCIA_STR_ACCTON_EN2212,
    160       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    161       PCMCIA_CIS_ACCTON_EN2212,
    162       0, 0x0ff0, { 0x00, 0x00, 0xe8 } },
    163     { PCMCIA_STR_ACCTON_EN2216,
    164       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    165       PCMCIA_CIS_ACCTON_EN2216,
    166       0, -1, { 0x00, 0x00, 0xe8 } },
    167 
    168     { PCMCIA_STR_SVEC_COMBOCARD,
    169       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    170       PCMCIA_CIS_SVEC_COMBOCARD,
    171       0, -1, { 0x00, 0xe0, 0x98 } },
    172 
    173     { PCMCIA_STR_SVEC_LANCARD,
    174       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    175       PCMCIA_CIS_SVEC_LANCARD,
    176       0, 0x7f0, { 0x00, 0xc0, 0x6c } },
    177 
    178     { PCMCIA_STR_EPSON_EEN10B,
    179       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_EPSON_EEN10B,
    180       PCMCIA_CIS_EPSON_EEN10B,
    181       0, 0xff0, { 0x00, 0x00, 0x48 } },
    182 
    183     { PCMCIA_STR_TAMARACK_ETHERNET,
    184       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    185       PCMCIA_CIS_TAMARACK_ETHERNET,
    186       0, -1, { 0x00, 0x00, 0x00 } },
    187 
    188 
    189     { PCMCIA_STR_CNET_NE2000,
    190       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    191       PCMCIA_CIS_CNET_NE2000,
    192       0, -1, { 0x00, 0x80, 0xad } },
    193 
    194     { PCMCIA_STR_ZONET_ZEN,
    195       PCMCIA_VENDOR_ZONET, PCMCIA_PRODUCT_ZONET_ZEN,
    196       PCMCIA_CIS_ZONET_ZEN,
    197       0, -1, { 0x00, 0x00, 0x00 } },
    198 
    199     /*
    200      * You have to add new entries which contains
    201      * PCMCIA_VENDOR_INVALID and/or PCMCIA_PRODUCT_INVALID
    202      * in front of this comment.
    203      *
    204      * There are cards which use a generic vendor and product id but needs
    205      * a different handling depending on the cis_info, so ne2000_match
    206      * needs a table where the exceptions comes first and then the normal
    207      * product and vendor entries.
    208      */
    209 
    210     { PCMCIA_STR_IBM_INFOMOVER,
    211       PCMCIA_VENDOR_IBM, PCMCIA_PRODUCT_IBM_INFOMOVER,
    212       PCMCIA_CIS_IBM_INFOMOVER,
    213       0, 0x0ff0, { 0x08, 0x00, 0x5a } },
    214 
    215     { PCMCIA_STR_IBM_INFOMOVER,
    216       PCMCIA_VENDOR_IBM, PCMCIA_PRODUCT_IBM_INFOMOVER,
    217       PCMCIA_CIS_IBM_INFOMOVER,
    218       0, 0x0ff0, { 0x00, 0x04, 0xac } },
    219 
    220     { PCMCIA_STR_IBM_INFOMOVER,
    221       PCMCIA_VENDOR_IBM, PCMCIA_PRODUCT_IBM_INFOMOVER,
    222       PCMCIA_CIS_IBM_INFOMOVER,
    223       0, 0x0ff0, { 0x00, 0x06, 0x29 } },
    224 
    225     /* NEC 9801N_J12 */
    226     { PCMCIA_STR_IBM_INFOMOVER,
    227       PCMCIA_VENDOR_IBM, PCMCIA_PRODUCT_IBM_INFOMOVER,
    228       PCMCIA_CIS_IBM_INFOMOVER,
    229       0, 0x0ff0, { 0x00, 0x00, 0x4c } },
    230 
    231     { PCMCIA_STR_LINKSYS_ECARD_1,
    232       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ECARD_1,
    233       PCMCIA_CIS_LINKSYS_ECARD_1,
    234       0, -1, { 0x00, 0x80, 0xc8 } },
    235 
    236     { PCMCIA_STR_PLANEX_FNW3600T,
    237       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_COMBO_ECARD,
    238       PCMCIA_CIS_PLANEX_FNW3600T,
    239       0, -1, { 0x00, 0x90, 0xcc }, NE2000DVF_DL10019 },
    240 
    241     { PCMCIA_STR_SVEC_PN650TX,
    242       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_COMBO_ECARD,
    243       PCMCIA_CIS_SVEC_PN650TX,
    244       0, -1, { 0x00, 0xe0, 0x98 }, NE2000DVF_DL10019 },
    245 
    246     /*
    247      * This entry should be here so that above two cards doesn't
    248      * match with this.  FNW-3700T won't match above entries due to
    249      * MAC address check.
    250      */
    251     { PCMCIA_STR_LANTECH_FASTNETTX,
    252       PCMCIA_VENDOR_LANTECH, PCMCIA_PRODUCT_LANTECH_FASTNETTX,
    253       PCMCIA_CIS_LANTECH_FASTNETTX,
    254       0, -1, { 0x00, 0x04, 0x1c }, NE2000DVF_AX88190 },
    255 
    256     { PCMCIA_STR_PLANEX_FNW3700T,
    257       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_COMBO_ECARD,
    258       PCMCIA_CIS_PLANEX_FNW3700T,
    259       0, -1, { 0x00, 0x90, 0xcc }, NE2000DVF_AX88190 },
    260 
    261     { PCMCIA_STR_LINKSYS_ETHERFAST,
    262       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ETHERFAST,
    263       PCMCIA_CIS_LINKSYS_ETHERFAST,
    264       0, -1, { 0x00, 0x80, 0xc8 }, NE2000DVF_DL10019 },
    265 
    266     { PCMCIA_STR_LINKSYS_ETHERFAST,
    267       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ETHERFAST,
    268       PCMCIA_CIS_LINKSYS_ETHERFAST,
    269       0, -1, { 0x00, 0x40, 0x05 }, NE2000DVF_DL10019 },
    270 
    271     { PCMCIA_STR_LINKSYS_ETHERFAST,
    272       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ETHERFAST,
    273       PCMCIA_CIS_LINKSYS_ETHERFAST,
    274       0, -1, { 0x00, 0x90, 0xfe }, NE2000DVF_DL10019 },
    275 
    276     { PCMCIA_STR_LINKSYS_ETHERFAST,
    277       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ETHERFAST,
    278       PCMCIA_CIS_LINKSYS_ETHERFAST,
    279       0, -1, { 0x00, 0xa0, 0xb0 }, NE2000DVF_DL10019 },
    280 
    281     { PCMCIA_STR_DLINK_DE650,
    282       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ETHERFAST,
    283       PCMCIA_CIS_LINKSYS_ETHERFAST,
    284       0, -1, { 0x00, 0x50, 0xba }, NE2000DVF_DL10019 },
    285 
    286     { PCMCIA_STR_DLINK_DE650,
    287       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ETHERFAST,
    288       PCMCIA_CIS_DLINK_DE650,
    289       0, -1, { 0x00, 0xe0, 0x98 }, NE2000DVF_DL10019 },
    290 
    291     /*
    292      * There are two entries for the DFE-670TXD because there are
    293      * several possible Vendor IDs for the MAC address.  Both are
    294      * from D-Link, though.
    295      */
    296     { PCMCIA_STR_DLINK_DFE670TXD,
    297       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_NETGEAR_FA410TXC,
    298       PCMCIA_CIS_DLINK_DFE670TXD,
    299       0, -1, { 0x00, 0x50, 0xba }, NE2000DVF_DL10019 },
    300 
    301     { PCMCIA_STR_DLINK_DFE670TXD,
    302       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_NETGEAR_FA410TXC,
    303       PCMCIA_CIS_DLINK_DFE670TXD,
    304       0, -1, { 0x00, 0x0d, 0x88 }, NE2000DVF_DL10019 },
    305 
    306     { PCMCIA_STR_MELCO_LPC2_TX,
    307       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ETHERFAST,
    308       PCMCIA_CIS_MELCO_LPC2_TX,
    309       0, -1, { 0x00, 0x40, 0x26 }, NE2000DVF_DL10019 },
    310 
    311     { PCMCIA_STR_LINKSYS_COMBO_ECARD,
    312       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_COMBO_ECARD,
    313       PCMCIA_CIS_LINKSYS_COMBO_ECARD,
    314       0, -1, { 0x00, 0x80, 0xc8 } },
    315 
    316     { PCMCIA_STR_LINKSYS_TRUST_COMBO_ECARD,
    317       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_TRUST_COMBO_ECARD,
    318       PCMCIA_CIS_LINKSYS_TRUST_COMBO_ECARD,
    319       0, 0x0120, { 0x20, 0x04, 0x49 } },
    320 
    321     /* Although the comments above say to put VENDOR/PRODUCT INVALID IDs
    322        above this list, we need to keep this one below the ECARD_1, or else
    323        both will match the same more-generic entry rather than the more
    324        specific one above with proper vendor and product IDs. */
    325     { PCMCIA_STR_LINKSYS_ECARD_2,
    326       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    327       PCMCIA_CIS_LINKSYS_ECARD_2,
    328       0, -1, { 0x00, 0x80, 0xc8 } },
    329 
    330     /*
    331      * D-Link DE-650 has many minor versions:
    332      *
    333      *   CIS information          Manufacturer Product  Note
    334      * 1 "D-Link, DE-650"             INVALID  INVALID  white card
    335      * 2 "D-Link, DE-650, Ver 01.00"  INVALID  INVALID  became bare metal
    336      * 3 "D-Link, DE-650, Ver 01.00"   0x149    0x265   minor change in look
    337      * 4 "D-Link, DE-650, Ver 01.00"   0x149    0x265   collision LED added
    338      *
    339      * While the 1st and the 2nd types should use the "D-Link DE-650" entry,
    340      * the 3rd and the 4th types should use the "Linksys EtherCard" entry.
    341      * Therefore, this enty must be below the LINKSYS_ECARD_1.  --itohy
    342      */
    343     { PCMCIA_STR_DLINK_DE650,
    344       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    345       PCMCIA_CIS_DLINK_DE650,
    346       0, 0x0040, { 0x00, 0x80, 0xc8 } },
    347 
    348     /*
    349      * IO-DATA PCLA/TE and later version of PCLA/T has valid
    350      * vendor/product ID and it is possible to read MAC address
    351      * using standard I/O ports.  It also read from CIS offset 0x01c0.
    352      * On the other hand, earlier version of PCLA/T doesn't have valid
    353      * vendor/product ID and MAC address must be read from CIS offset
    354      * 0x0ff0 (i.e., usual ne2000 way to read it doesn't work).
    355      * And CIS information of earlier and later version of PCLA/T are
    356      * same except fourth element.  So, for now, we place the entry for
    357      * PCLA/TE (and later version of PCLA/T) followed by entry
    358      * for the earlier version of PCLA/T (or, modify to match all CIS
    359      * information and have three or more individual entries).
    360      */
    361     { PCMCIA_STR_IODATA_PCLATE,
    362       PCMCIA_VENDOR_IODATA, PCMCIA_PRODUCT_IODATA_PCLATE,
    363       PCMCIA_CIS_IODATA_PCLATE,
    364       0, -1, { 0x00, 0xa0, 0xb0 } },
    365 
    366     /*
    367      * This entry should be placed after above PCLA-TE entry.
    368      * See above comments for detail.
    369      */
    370     { PCMCIA_STR_IODATA_PCLAT,
    371       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    372       PCMCIA_CIS_IODATA_PCLAT,
    373       0, 0x0ff0, { 0x00, 0xa0, 0xb0 } },
    374 
    375     { PCMCIA_STR_DAYNA_COMMUNICARD_E_1,
    376       PCMCIA_VENDOR_DAYNA, PCMCIA_PRODUCT_DAYNA_COMMUNICARD_E_1,
    377       PCMCIA_CIS_DAYNA_COMMUNICARD_E_1,
    378       0, 0x0110, { 0x00, 0x80, 0x19 } },
    379 
    380     { PCMCIA_STR_DAYNA_COMMUNICARD_E_2,
    381       PCMCIA_VENDOR_DAYNA, PCMCIA_PRODUCT_DAYNA_COMMUNICARD_E_2,
    382       PCMCIA_CIS_DAYNA_COMMUNICARD_E_2,
    383       0, -1, { 0x00, 0x80, 0x19 } },
    384 
    385     { PCMCIA_STR_COREGA_ETHER_PCC_T,
    386       PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_ETHER_PCC_T,
    387       PCMCIA_CIS_COREGA_ETHER_PCC_T,
    388       0, -1, { 0x00, 0x00, 0xf4 } },
    389 
    390     { PCMCIA_STR_COREGA_ETHER_PCC_TD,
    391       PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_ETHER_PCC_TD,
    392       PCMCIA_CIS_COREGA_ETHER_PCC_TD,
    393       0, -1, { 0x00, 0x00, 0xf4 } },
    394 
    395     { PCMCIA_STR_COREGA_ETHER_PCC_TL,
    396       PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_ETHER_PCC_TL,
    397       PCMCIA_CIS_COREGA_ETHER_PCC_TL,
    398       0, -1, { 0x00, 0x00, 0xf4 } },
    399 
    400     { PCMCIA_STR_COREGA_ETHER_II_PCC_T,
    401       PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_ETHER_II_PCC_T,
    402       PCMCIA_CIS_COREGA_ETHER_II_PCC_T,
    403       0, -1, { 0x00, 0x00, 0xf4 } },
    404 
    405     { PCMCIA_STR_COREGA_ETHER_II_PCC_TD,
    406       PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_ETHER_II_PCC_TD,
    407       PCMCIA_CIS_COREGA_ETHER_II_PCC_TD,
    408       0, -1, { 0x00, 0x00, 0xf4 } },
    409 
    410     { PCMCIA_STR_COREGA_FAST_ETHER_PCC_TX,
    411       PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_FAST_ETHER_PCC_TX,
    412       PCMCIA_CIS_COREGA_FAST_ETHER_PCC_TX,
    413       0, -1, { 0x00, 0x00, 0xf4 }, NE2000DVF_DL10019 },
    414 
    415     { PCMCIA_STR_COREGA_FETHER_PCC_TXF,
    416       PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_FETHER_PCC_TXF,
    417       PCMCIA_CIS_COREGA_FETHER_PCC_TXF,
    418       0, -1, { 0x00, 0x90, 0x99 }, NE2000DVF_DL10019 },
    419 
    420     { PCMCIA_STR_COREGA_FETHER_PCC_TXD,
    421       PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_FETHER_PCC_TXD,
    422       PCMCIA_CIS_COREGA_FETHER_PCC_TXD,
    423       0, -1, { 0x00, 0x90, 0x99 } },
    424 
    425     { PCMCIA_STR_COMPEX_LINKPORT_ENET_B,
    426       PCMCIA_VENDOR_COMPEX, PCMCIA_PRODUCT_COMPEX_LINKPORT_ENET_B,
    427       PCMCIA_CIS_COMPEX_LINKPORT_ENET_B,
    428       0, 0x01c0, { 0x00, 0xa0, 0x0c } },
    429 
    430     { PCMCIA_STR_SMC_EZCARD,
    431       PCMCIA_VENDOR_SMC, PCMCIA_PRODUCT_SMC_EZCARD,
    432       PCMCIA_CIS_SMC_EZCARD,
    433       0, 0x01c0, { 0x00, 0xe0, 0x29 } },
    434 
    435     { PCMCIA_STR_SMC_8041,
    436       PCMCIA_VENDOR_SMC, PCMCIA_PRODUCT_SMC_8041,
    437       PCMCIA_CIS_SMC_8041,
    438       0, -1, { 0x00, 0x04, 0xe2 } },
    439 
    440     { PCMCIA_STR_SOCKET_EA_ETHER,
    441       PCMCIA_VENDOR_SOCKET, PCMCIA_PRODUCT_SOCKET_EA_ETHER,
    442       PCMCIA_CIS_SOCKET_EA_ETHER,
    443       0, -1, { 0x00, 0xc0, 0x1b } },
    444 
    445     { PCMCIA_STR_SOCKET_LP_ETHER_CF,
    446       PCMCIA_VENDOR_SOCKET, PCMCIA_PRODUCT_SOCKET_LP_ETHER_CF,
    447       PCMCIA_CIS_SOCKET_LP_ETHER_CF,
    448       0, -1, { 0x00, 0xc0, 0x1b } },
    449 
    450     { PCMCIA_STR_SOCKET_LP_ETH_10_100_CF,
    451       PCMCIA_VENDOR_SOCKET, PCMCIA_PRODUCT_SOCKET_LP_ETH_10_100_CF,
    452       PCMCIA_CIS_SOCKET_LP_ETH_10_100_CF,
    453       0, -1, { 0x00, 0xe0, 0x98 }, NE2000DVF_DL10019 },
    454 
    455     { PCMCIA_STR_SOCKET_LP_ETHER,
    456       PCMCIA_VENDOR_SOCKET, PCMCIA_PRODUCT_SOCKET_LP_ETHER,
    457       PCMCIA_CIS_SOCKET_LP_ETHER,
    458       0, -1, { 0x00, 0xc0, 0x1b } },
    459 
    460     { PCMCIA_STR_KINGSTON_KNE2,
    461       PCMCIA_VENDOR_KINGSTON, PCMCIA_PRODUCT_KINGSTON_KNE2,
    462       PCMCIA_CIS_KINGSTON_KNE2,
    463       0, -1, { 0x00, 0xc0, 0xf0 } },
    464 
    465     { PCMCIA_STR_XIRCOM_CFE_10,
    466       PCMCIA_VENDOR_XIRCOM, PCMCIA_PRODUCT_XIRCOM_CFE_10,
    467       PCMCIA_CIS_XIRCOM_CFE_10,
    468       0, -1, { 0x00, 0x10, 0xa4 } },
    469 
    470     { PCMCIA_STR_MELCO_LPC3_TX,
    471       PCMCIA_VENDOR_MELCO, PCMCIA_PRODUCT_MELCO_LPC3_TX,
    472       PCMCIA_CIS_MELCO_LPC3_TX,
    473       0, -1, { 0x00, 0x40, 0x26 }, NE2000DVF_AX88190 },
    474 
    475     { PCMCIA_STR_BUFFALO_LPC3_CLT,
    476       PCMCIA_VENDOR_BUFFALO, PCMCIA_PRODUCT_BUFFALO_LPC3_CLT,
    477       PCMCIA_CIS_BUFFALO_LPC3_CLT,
    478       0, -1, { 0x00, 0x07, 0x40 } },
    479 
    480     { PCMCIA_STR_BUFFALO_LPC4_CLX,
    481       PCMCIA_VENDOR_BUFFALO, PCMCIA_PRODUCT_BUFFALO_LPC4_CLX,
    482       PCMCIA_CIS_BUFFALO_LPC4_CLX,
    483       0, -1, { 0x00, 0x40, 0xfa }, NE2000DVF_AX88190 | NE2000DVF_AX88790 },
    484 
    485     { PCMCIA_STR_BILLIONTON_LNT10TN,
    486       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    487       PCMCIA_CIS_BILLIONTON_LNT10TN,
    488       0, -1, { 0x00, 0x00, 0x00 } },
    489 
    490     { PCMCIA_STR_BILLIONTON_CFLT10N,
    491       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    492       PCMCIA_CIS_BILLIONTON_CFLT10N,
    493       0, -1, { 0x00, 0x00, 0x00 } },
    494 
    495     { PCMCIA_STR_NDC_ND5100_E,
    496       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    497       PCMCIA_CIS_NDC_ND5100_E,
    498       0, -1, { 0x00, 0x80, 0xc6 } },
    499 
    500     { PCMCIA_STR_TELECOMDEVICE_TCD_HPC100,
    501       PCMCIA_VENDOR_TELECOMDEVICE, PCMCIA_PRODUCT_TELECOMDEVICE_TCD_HPC100,
    502       PCMCIA_CIS_TELECOMDEVICE_TCD_HPC100,
    503       0, -1, { 0x00, 0x40, 0x26 }, NE2000DVF_AX88190 },
    504 
    505     { PCMCIA_STR_MACNICA_ME1_JEIDA,
    506       PCMCIA_VENDOR_MACNICA, PCMCIA_PRODUCT_MACNICA_ME1_JEIDA,
    507       PCMCIA_CIS_MACNICA_ME1_JEIDA,
    508       0, 0x00b8, { 0x08, 0x00, 0x42 } },
    509 
    510     { PCMCIA_STR_NETGEAR_FA411,
    511       PCMCIA_VENDOR_NETGEAR, PCMCIA_PRODUCT_NETGEAR_FA411,
    512       PCMCIA_CIS_NETGEAR_FA411,
    513       0, -1, { 0x00, 0x40, 0xf4 } },
    514 
    515     { PCMCIA_STR_DYNALINK_L10C,
    516       PCMCIA_VENDOR_DYNALINK, PCMCIA_PRODUCT_DYNALINK_L10C,
    517       PCMCIA_CIS_DYNALINK_L10C,
    518       0, -1, { 0x00, 0x00, 0x00 } },
    519 
    520 #if 0
    521     /* the rest of these are stolen from the linux pcnet pcmcia device
    522        driver.  Since I don't know the manfid or cis info strings for
    523        any of them, they're not compiled in until I do. */
    524     { "APEX MultiCard",
    525       0x0000, 0x0000, NULL, NULL, 0,
    526       0x03f4, { 0x00, 0x20, 0xe5 } },
    527     { "ASANTE FriendlyNet",
    528       0x0000, 0x0000, NULL, NULL, 0,
    529       0x4910, { 0x00, 0x00, 0x94 } },
    530     { "Danpex EN-6200P2",
    531       0x0000, 0x0000, NULL, NULL, 0,
    532       0x0110, { 0x00, 0x40, 0xc7 } },
    533     { "DataTrek NetCard",
    534       0x0000, 0x0000, NULL, NULL, 0,
    535       0x0ff0, { 0x00, 0x20, 0xe8 } },
    536     { "Dayna CommuniCard E",
    537       0x0000, 0x0000, NULL, NULL, 0,
    538       0x0110, { 0x00, 0x80, 0x19 } },
    539     { "EP-210 Ethernet",
    540       0x0000, 0x0000, NULL, NULL, 0,
    541       0x0110, { 0x00, 0x40, 0x33 } },
    542     { "ELECOM Laneed LD-CDWA",
    543       0x0000, 0x0000, NULL, NULL, 0,
    544       0x00b8, { 0x08, 0x00, 0x42 } },
    545     { "Grey Cell GCS2220",
    546       0x0000, 0x0000, NULL, NULL, 0,
    547       0x0000, { 0x00, 0x47, 0x43 } },
    548     { "Hypertec Ethernet",
    549       0x0000, 0x0000, NULL, NULL, 0,
    550       0x01c0, { 0x00, 0x40, 0x4c } },
    551     { "IBM CCAE",
    552       0x0000, 0x0000, NULL, NULL, 0,
    553       0x0ff0, { 0x08, 0x00, 0x5a } },
    554     { "IBM CCAE",
    555       0x0000, 0x0000, NULL, NULL, 0,
    556       0x0ff0, { 0x00, 0x04, 0xac } },
    557     { "IBM CCAE",
    558       0x0000, 0x0000, NULL, NULL, 0,
    559       0x0ff0, { 0x00, 0x06, 0x29 } },
    560     { "IBM FME",
    561       0x0000, 0x0000, NULL, NULL, 0,
    562       0x0374, { 0x00, 0x04, 0xac } },
    563     { "IBM FME",
    564       0x0000, 0x0000, NULL, NULL, 0,
    565       0x0374, { 0x08, 0x00, 0x5a } },
    566     { "Katron PE-520",
    567       0x0000, 0x0000, NULL, NULL, 0,
    568       0x0110, { 0x00, 0x40, 0xf6 } },
    569     { "Kingston KNE-PCM/x",
    570       0x0000, 0x0000, NULL, NULL, 0,
    571       0x0ff0, { 0x00, 0xc0, 0xf0 } },
    572     { "Kingston KNE-PCM/x",
    573       0x0000, 0x0000, NULL, NULL, 0,
    574       0x0ff0, { 0xe2, 0x0c, 0x0f } },
    575     { "Longshine LCS-8534",
    576       0x0000, 0x0000, NULL, NULL, 0,
    577       0x0000, { 0x08, 0x00, 0x00 } },
    578     { "Maxtech PCN2000",
    579       0x0000, 0x0000, NULL, NULL, 0,
    580       0x5000, { 0x00, 0x00, 0xe8 } },
    581     { "NDC Instant-Link",
    582       0x0000, 0x0000, NULL, NULL, 0,
    583       0x003a, { 0x00, 0x80, 0xc6 } },
    584     { "NE2000 Compatible",
    585       0x0000, 0x0000, NULL, NULL, 0,
    586       0x0ff0, { 0x00, 0xa0, 0x0c } },
    587     { "Network General Sniffer",
    588       0x0000, 0x0000, NULL, NULL, 0,
    589       0x0ff0, { 0x00, 0x00, 0x65 } },
    590     { "Panasonic VEL211",
    591       0x0000, 0x0000, NULL, NULL, 0,
    592       0x0ff0, { 0x00, 0x80, 0x45 } },
    593     { "SCM Ethernet",
    594       0x0000, 0x0000, NULL, NULL, 0,
    595       0x0ff0, { 0x00, 0x20, 0xcb } },
    596     { "Volktek NPL-402CT",
    597       0x0000, 0x0000, NULL, NULL, 0,
    598       0x0060, { 0x00, 0x40, 0x05 } },
    599 #endif
    600 
    601     { PCMCIA_STR_ALLIEDTELESIS_LA_PCM,
    602       PCMCIA_VENDOR_ALLIEDTELESIS, PCMCIA_PRODUCT_ALLIEDTELESIS_LA_PCM,
    603       PCMCIA_CIS_ALLIEDTELESIS_LA_PCM,
    604       0, 0x0ff0, { 0x00, 0x00, 0xf4 } },
    605 };
    606 
    607 #define	NE2000_NDEVS	(sizeof(ne2000devs) / sizeof(ne2000devs[0]))
    608 
    609 #define ne2000_match(card, fct, n) \
    610 ((((((card)->manufacturer != PCMCIA_VENDOR_INVALID) && \
    611     ((card)->manufacturer == ne2000devs[(n)].manufacturer) && \
    612     ((card)->product != PCMCIA_PRODUCT_INVALID) && \
    613     ((card)->product == ne2000devs[(n)].product)) || \
    614    ((ne2000devs[(n)].cis_info[0]) && (ne2000devs[(n)].cis_info[1]) && \
    615     (strcmp((card)->cis1_info[0], ne2000devs[(n)].cis_info[0]) == 0) && \
    616     (strcmp((card)->cis1_info[1], ne2000devs[(n)].cis_info[1]) == 0))) && \
    617   ((fct) == ne2000devs[(n)].function))? \
    618  &ne2000devs[(n)]:NULL)
    619 
    620 int
    621 ne_pcmcia_match(parent, match, aux)
    622 	struct device *parent;
    623 	struct cfdata *match;
    624 	void *aux;
    625 {
    626 	struct pcmcia_attach_args *pa = aux;
    627 	int i;
    628 
    629 	for (i = 0; i < NE2000_NDEVS; i++) {
    630 		if (ne2000_match(pa->card, pa->pf->number, i))
    631 			return (1);
    632 	}
    633 
    634 	return (0);
    635 }
    636 
    637 void
    638 ne_pcmcia_attach(parent, self, aux)
    639 	struct device *parent, *self;
    640 	void *aux;
    641 {
    642 	struct ne_pcmcia_softc *psc = (void *) self;
    643 	struct ne2000_softc *nsc = &psc->sc_ne2000;
    644 	struct dp8390_softc *dsc = &nsc->sc_dp8390;
    645 	struct pcmcia_attach_args *pa = aux;
    646 	struct pcmcia_config_entry *cfe;
    647 	const struct ne2000dev *ne_dev;
    648 	int i;
    649 	u_int8_t myea[6], *enaddr;
    650 	const char *typestr = "";
    651 
    652 	psc->sc_pf = pa->pf;
    653 
    654 	SIMPLEQ_FOREACH(cfe, &pa->pf->cfe_head, cfe_list) {
    655 #if 0
    656 		/*
    657 		 * Some ne2000 driver's claim to have memory; others don't.
    658 		 * Since I don't care, I don't check.
    659 		 */
    660 
    661 		if (cfe->num_memspace != 1) {
    662 			printf(": unexpected number of memory spaces "
    663 			    " %d should be 1\n", cfe->num_memspace);
    664 			continue;
    665 		}
    666 #endif
    667 
    668 		if (cfe->num_iospace == 1) {
    669 			if (cfe->iospace[0].length != NE2000_NPORTS) {
    670 				printf(": unexpected I/O space configuration"
    671 				    " (continued)\n%s", dsc->sc_dev.dv_xname);
    672 				/* XXX really safe for all other cards? */
    673 			}
    674 		} else if (cfe->num_iospace == 2) {
    675 			/*
    676 			 * Some cards report a separate space for NIC and ASIC.
    677 			 * This make some sense, but we must allocate a single
    678 			 * NE2000_NPORTS-sized chunk, due to brain damaged
    679 			 * address decoders on some of these cards.
    680 			 */
    681 			if (cfe->iospace[0].length + cfe->iospace[1].length !=
    682 			    NE2000_NPORTS) {
    683 #ifdef DIAGNOSTIC
    684 				printf(": unexpected I/O "
    685 				    "space configuration; ignored\n%s",
    686 				    dsc->sc_dev.dv_xname);
    687 #endif
    688 				continue;
    689 			}
    690 		} else {
    691 #ifdef DIAGNOSTIC
    692 			printf(": unexpected number of i/o spaces %d"
    693 			    " should be 1 or 2; ignored\n%s",
    694 			    cfe->num_iospace, dsc->sc_dev.dv_xname);
    695 #endif
    696 			continue;
    697 		}
    698 
    699 		if (pcmcia_io_alloc(pa->pf, cfe->iospace[0].start,
    700 		    NE2000_NPORTS, NE2000_NPORTS, &psc->sc_pcioh)) {
    701 #ifdef DIAGNOSTIC
    702 			printf(": can't allocate i/o space %lx; ignored\n%s",
    703 			    cfe->iospace[0].start, dsc->sc_dev.dv_xname);
    704 #endif
    705 			continue;
    706 		}
    707 
    708 		/* Ok, found. */
    709 		break;
    710 	}
    711 
    712 	if (cfe == NULL) {
    713 		printf(": no suitable config entry\n");
    714 		goto fail_1;
    715 	}
    716 
    717 	dsc->sc_regt = psc->sc_pcioh.iot;
    718 	dsc->sc_regh = psc->sc_pcioh.ioh;
    719 
    720 	nsc->sc_asict = psc->sc_pcioh.iot;
    721 	if (bus_space_subregion(dsc->sc_regt, dsc->sc_regh,
    722 	    NE2000_ASIC_OFFSET, NE2000_ASIC_NPORTS,
    723 	    &nsc->sc_asich)) {
    724 		printf(": can't get subregion for asic\n");
    725 		goto fail_2;
    726 	}
    727 
    728 	/* Set up power management hooks. */
    729 	dsc->sc_enable = ne_pcmcia_enable;
    730 	dsc->sc_disable = ne_pcmcia_disable;
    731 
    732 	/* Enable the card. */
    733 	pcmcia_function_init(pa->pf, cfe);
    734 	if (pcmcia_function_enable(pa->pf)) {
    735 		printf(": function enable failed\n");
    736 		goto fail_2;
    737 	}
    738 
    739 	/* some cards claim to be io16, but they're lying. */
    740 	if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_IO8,
    741 	    NE2000_NIC_OFFSET, NE2000_NIC_NPORTS,
    742 	    &psc->sc_pcioh, &psc->sc_nic_io_window)) {
    743 		printf(": can't map NIC i/o space\n");
    744 		goto fail_3;
    745 	}
    746 
    747 	if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_IO16,
    748 	    NE2000_ASIC_OFFSET, NE2000_ASIC_NPORTS,
    749 	    &psc->sc_pcioh, &psc->sc_asic_io_window)) {
    750 		printf(": can't map ASIC i/o space\n");
    751 		goto fail_4;
    752 	}
    753 
    754 	printf("\n");
    755 
    756 	/*
    757 	 * Read the station address from the board.
    758 	 */
    759 	i = 0;
    760 again:
    761 	enaddr = NULL;			/* Ask ASIC by default */
    762 	typestr = "";			/* clear previous card-type */
    763 	for (; i < NE2000_NDEVS; i++) {
    764 		ne_dev = ne2000_match(pa->card, pa->pf->number, i);
    765 		if (ne_dev != NULL) {
    766 			if (ne_dev->enet_maddr >= 0) {
    767 				enaddr = ne_pcmcia_get_enaddr(psc,
    768 				    ne_dev->enet_maddr, myea);
    769 				if (enaddr == NULL)
    770 					continue;
    771 			}
    772 			goto found;
    773 		}
    774 	}
    775 	printf("%s (manf %08x prod %08x) cis %s %s: "
    776 	       "can't match ethernet vendor code\n",
    777 	       dsc->sc_dev.dv_xname,
    778 	       pa->manufacturer, pa->product,
    779 	       pa->card->cis1_info[0], pa->card->cis1_info[1]);
    780 	goto fail_5;
    781 
    782 found:
    783 	if ((ne_dev->flags & NE2000DVF_DL10019) != 0) {
    784 		u_int8_t type;
    785 
    786 		enaddr = ne_pcmcia_dl10019_get_enaddr(psc, myea);
    787 		if (enaddr == NULL) {
    788 			++i;
    789 			goto again;
    790 		}
    791 
    792 		dsc->sc_mediachange = dl10019_mediachange;
    793 		dsc->sc_mediastatus = dl10019_mediastatus;
    794 		dsc->init_card = dl10019_init_card;
    795 		dsc->stop_card = dl10019_stop_card;
    796 		dsc->sc_media_init = dl10019_media_init;
    797 		dsc->sc_media_fini = dl10019_media_fini;
    798 
    799 		/* Determine if this is a DL10019 or a DL10022. */
    800 		type = bus_space_read_1(nsc->sc_asict, nsc->sc_asich, 0x0f);
    801 		if (type == 0x91 || type == 0x99) {
    802 			nsc->sc_type = NE2000_TYPE_DL10022;
    803 			typestr = " (DL10022)";
    804 		} else {
    805 			nsc->sc_type = NE2000_TYPE_DL10019;
    806 			typestr = " (DL10019)";
    807 		}
    808 	}
    809 
    810 	if ((ne_dev->flags & NE2000DVF_AX88190) != 0) {
    811 		if (ne_pcmcia_ax88190_set_iobase(psc)) {
    812 			++i;
    813 			goto again;
    814 		}
    815 
    816 		dsc->sc_mediachange = ax88190_mediachange;
    817 		dsc->sc_mediastatus = ax88190_mediastatus;
    818 		dsc->init_card = ax88190_init_card;
    819 		dsc->stop_card = ax88190_stop_card;
    820 		dsc->sc_media_init = ax88190_media_init;
    821 		dsc->sc_media_fini = ax88190_media_fini;
    822 
    823 		if ((ne_dev->flags & NE2000DVF_AX88790) != 0) {
    824 			nsc->sc_type = NE2000_TYPE_AX88790;
    825 			typestr = " (AX88790)";
    826 		} else {
    827 			nsc->sc_type = NE2000_TYPE_AX88190;
    828 			typestr = " (AX88190)";
    829 		}
    830 	}
    831 
    832 	if (enaddr != NULL) {
    833 		/*
    834 		 * Make sure this is what we expect.
    835 		 */
    836 		if (enaddr[0] != ne_dev->enet_vendor[0] ||
    837 		    enaddr[1] != ne_dev->enet_vendor[1] ||
    838 		    enaddr[2] != ne_dev->enet_vendor[2]) {
    839 			++i;
    840 			goto again;
    841 		}
    842 	}
    843 
    844 	/*
    845 	 * Check for a Realtek 8019.
    846 	 */
    847 	if (nsc->sc_type == 0) {
    848 		bus_space_write_1(dsc->sc_regt, dsc->sc_regh, ED_P0_CR,
    849 		    ED_CR_PAGE_0 | ED_CR_STP);
    850 		if (bus_space_read_1(dsc->sc_regt, dsc->sc_regh,
    851 		    NERTL_RTL0_8019ID0) == RTL0_8019ID0 &&
    852 		    bus_space_read_1(dsc->sc_regt, dsc->sc_regh,
    853 		    NERTL_RTL0_8019ID1) == RTL0_8019ID1) {
    854 			typestr = " (RTL8019)";
    855 			dsc->sc_mediachange = rtl80x9_mediachange;
    856 			dsc->sc_mediastatus = rtl80x9_mediastatus;
    857 			dsc->init_card = rtl80x9_init_card;
    858 			dsc->sc_media_init = rtl80x9_media_init;
    859 		}
    860 	}
    861 
    862 	printf("%s: %s%s Ethernet\n", dsc->sc_dev.dv_xname, ne_dev->name,
    863 	    typestr);
    864 
    865 	if (ne2000_attach(nsc, enaddr))
    866 		goto fail_5;
    867 
    868 	pcmcia_function_disable(pa->pf);
    869 	return;
    870 
    871  fail_5:
    872 	/* Unmap ASIC i/o windows. */
    873 	pcmcia_io_unmap(psc->sc_pf, psc->sc_asic_io_window);
    874 
    875  fail_4:
    876 	/* Unmap NIC i/o windows. */
    877 	pcmcia_io_unmap(psc->sc_pf, psc->sc_nic_io_window);
    878 
    879  fail_3:
    880 	pcmcia_function_disable(pa->pf);
    881 
    882  fail_2:
    883 	/* Free our i/o space. */
    884 	pcmcia_io_free(psc->sc_pf, &psc->sc_pcioh);
    885 
    886  fail_1:
    887 	psc->sc_nic_io_window = -1;
    888 }
    889 
    890 int
    891 ne_pcmcia_detach(self, flags)
    892 	struct device *self;
    893 	int flags;
    894 {
    895 	struct ne_pcmcia_softc *psc = (struct ne_pcmcia_softc *)self;
    896 	int error;
    897 
    898 	if (psc->sc_nic_io_window == -1)
    899 		/* Nothing to detach. */
    900 		return (0);
    901 
    902 	error = ne2000_detach(&psc->sc_ne2000, flags);
    903 	if (error != 0)
    904 		return (error);
    905 
    906 	/* Unmap our i/o windows. */
    907 	pcmcia_io_unmap(psc->sc_pf, psc->sc_asic_io_window);
    908 	pcmcia_io_unmap(psc->sc_pf, psc->sc_nic_io_window);
    909 
    910 	/* Free our i/o space. */
    911 	pcmcia_io_free(psc->sc_pf, &psc->sc_pcioh);
    912 
    913 	return (0);
    914 }
    915 
    916 int
    917 ne_pcmcia_enable(dsc)
    918 	struct dp8390_softc *dsc;
    919 {
    920 	struct ne_pcmcia_softc *psc = (struct ne_pcmcia_softc *)dsc;
    921 	struct ne2000_softc *nsc = &psc->sc_ne2000;
    922 	struct pcmcia_mem_handle pcmh;
    923 
    924 	/* set up the interrupt */
    925 	psc->sc_ih = pcmcia_intr_establish(psc->sc_pf, IPL_NET, dp8390_intr,
    926 	    dsc);
    927 	if (psc->sc_ih == NULL) {
    928 		printf("%s: couldn't establish interrupt\n",
    929 		    dsc->sc_dev.dv_xname);
    930 		goto fail_1;
    931 	}
    932 
    933 	if (pcmcia_function_enable(psc->sc_pf))
    934 		goto fail_2;
    935 
    936 	if (nsc->sc_type == NE2000_TYPE_AX88190 ||
    937 	    nsc->sc_type == NE2000_TYPE_AX88790) {
    938 		if (ne_pcmcia_ax88190_set_iobase(psc))
    939 			goto fail_3;
    940 		if (nsc->sc_type == NE2000_TYPE_AX88790) {
    941 			bus_size_t offset;
    942 			int mwindow;
    943 
    944 			if (pcmcia_mem_alloc(psc->sc_pf,
    945 			    AX88790_CSR_SIZE, &pcmh)) {
    946 				printf("%s: can't alloc mem for CSR\n",
    947 				    dsc->sc_dev.dv_xname);
    948 				goto fail_3;
    949 			}
    950 
    951 			if (pcmcia_mem_map(psc->sc_pf, PCMCIA_MEM_ATTR,
    952 			    AX88790_CSR, AX88790_CSR_SIZE,
    953 			    &pcmh, &offset, &mwindow)) {
    954 				printf("%s: can't map mem for CSR\n",
    955 				    dsc->sc_dev.dv_xname);
    956 				goto fail_4;
    957 			}
    958 
    959 			bus_space_write_1(pcmh.memt, pcmh.memh, offset, 0x4);
    960 			pcmcia_mem_unmap(psc->sc_pf, mwindow);
    961 			pcmcia_mem_free(psc->sc_pf, &pcmh);
    962 		}
    963 	}
    964 
    965 	return (0);
    966 
    967  fail_4:
    968 	pcmcia_mem_free(psc->sc_pf, &pcmh);
    969  fail_3:
    970 	pcmcia_function_disable(psc->sc_pf);
    971  fail_2:
    972 	pcmcia_intr_disestablish(psc->sc_pf, psc->sc_ih);
    973  fail_1:
    974 	return (1);
    975 }
    976 
    977 void
    978 ne_pcmcia_disable(dsc)
    979 	struct dp8390_softc *dsc;
    980 {
    981 	struct ne_pcmcia_softc *psc = (struct ne_pcmcia_softc *)dsc;
    982 
    983 	pcmcia_function_disable(psc->sc_pf);
    984 	pcmcia_intr_disestablish(psc->sc_pf, psc->sc_ih);
    985 }
    986 
    987 u_int8_t *
    988 ne_pcmcia_get_enaddr(psc, maddr, myea)
    989 	struct ne_pcmcia_softc *psc;
    990 	int maddr;
    991 	u_int8_t myea[ETHER_ADDR_LEN];
    992 {
    993 	struct ne2000_softc *nsc = &psc->sc_ne2000;
    994 	struct dp8390_softc *dsc = &nsc->sc_dp8390;
    995 	struct pcmcia_mem_handle pcmh;
    996 	bus_size_t offset;
    997 	u_int8_t *enaddr = NULL;
    998 	int j, mwindow;
    999 
   1000 	if (maddr < 0)
   1001 		return (NULL);
   1002 
   1003 	if (pcmcia_mem_alloc(psc->sc_pf, ETHER_ADDR_LEN * 2, &pcmh)) {
   1004 		printf("%s: can't alloc mem for enet addr\n",
   1005 		    dsc->sc_dev.dv_xname);
   1006 		goto fail_1;
   1007 	}
   1008 	if (pcmcia_mem_map(psc->sc_pf, PCMCIA_MEM_ATTR, maddr,
   1009 	    ETHER_ADDR_LEN * 2, &pcmh, &offset, &mwindow)) {
   1010 		printf("%s: can't map mem for enet addr\n",
   1011 		    dsc->sc_dev.dv_xname);
   1012 		goto fail_2;
   1013 	}
   1014 	for (j = 0; j < ETHER_ADDR_LEN; j++)
   1015 		myea[j] = bus_space_read_1(pcmh.memt, pcmh.memh,
   1016 		    offset + (j * 2));
   1017 	enaddr = myea;
   1018 
   1019 	pcmcia_mem_unmap(psc->sc_pf, mwindow);
   1020  fail_2:
   1021 	pcmcia_mem_free(psc->sc_pf, &pcmh);
   1022  fail_1:
   1023 	return (enaddr);
   1024 }
   1025 
   1026 u_int8_t *
   1027 ne_pcmcia_dl10019_get_enaddr(psc, myea)
   1028 	struct ne_pcmcia_softc *psc;
   1029 	u_int8_t myea[ETHER_ADDR_LEN];
   1030 {
   1031 	struct ne2000_softc *nsc = &psc->sc_ne2000;
   1032 	u_int8_t sum;
   1033 	int j;
   1034 
   1035 #define PAR0	0x04
   1036 	for (j = 0, sum = 0; j < 8; j++)
   1037 		sum += bus_space_read_1(nsc->sc_asict, nsc->sc_asich,
   1038 		    PAR0 + j);
   1039 	if (sum != 0xff)
   1040 		return (NULL);
   1041 	for (j = 0; j < ETHER_ADDR_LEN; j++)
   1042 		myea[j] = bus_space_read_1(nsc->sc_asict,
   1043 		    nsc->sc_asich, PAR0 + j);
   1044 #undef PAR0
   1045 	return (myea);
   1046 }
   1047 
   1048 int
   1049 ne_pcmcia_ax88190_set_iobase(psc)
   1050 	struct ne_pcmcia_softc *psc;
   1051 {
   1052 	struct ne2000_softc *nsc = &psc->sc_ne2000;
   1053 	struct dp8390_softc *dsc = &nsc->sc_dp8390;
   1054 	struct pcmcia_mem_handle pcmh;
   1055 	bus_size_t offset;
   1056 	int rv = 1, mwindow;
   1057 	u_int last_liobase, new_liobase;
   1058 
   1059 	if (pcmcia_mem_alloc(psc->sc_pf, AX88190_LAN_IOSIZE, &pcmh)) {
   1060 #if 0
   1061 		printf("%s: can't alloc mem for LAN iobase\n",
   1062 		    dsc->sc_dev.dv_xname);
   1063 #endif
   1064 		goto fail_1;
   1065 	}
   1066 	if (pcmcia_mem_map(psc->sc_pf, PCMCIA_MEM_ATTR,
   1067 	    AX88190_LAN_IOBASE, AX88190_LAN_IOSIZE,
   1068 	    &pcmh, &offset, &mwindow)) {
   1069 		printf("%s: can't map mem for LAN iobase\n",
   1070 		    dsc->sc_dev.dv_xname);
   1071 		goto fail_2;
   1072 	}
   1073 
   1074 	last_liobase = bus_space_read_1(pcmh.memt, pcmh.memh, offset + 0) |
   1075 	    (bus_space_read_1(pcmh.memt, pcmh.memh, offset + 2) << 8);
   1076 #ifdef DIAGNOSTIC
   1077 	printf("%s: LAN iobase 0x%x (0x%x) ->", dsc->sc_dev.dv_xname,
   1078 	    last_liobase, (u_int)psc->sc_pcioh.addr);
   1079 #endif
   1080 	bus_space_write_1(pcmh.memt, pcmh.memh, offset,
   1081 	    psc->sc_pcioh.addr & 0xff);
   1082 	bus_space_write_1(pcmh.memt, pcmh.memh, offset + 2,
   1083 	    psc->sc_pcioh.addr >> 8);
   1084 
   1085 	new_liobase = bus_space_read_1(pcmh.memt, pcmh.memh, offset + 0) |
   1086 	    (bus_space_read_1(pcmh.memt, pcmh.memh, offset + 2) << 8);
   1087 #ifdef DIAGNOSTIC
   1088 	printf(" 0x%x\n", new_liobase);
   1089 #endif
   1090 	if ((last_liobase == psc->sc_pcioh.addr)
   1091 	    || (last_liobase != new_liobase))
   1092 		rv = 0;
   1093 
   1094 	pcmcia_mem_unmap(psc->sc_pf, mwindow);
   1095  fail_2:
   1096 	pcmcia_mem_free(psc->sc_pf, &pcmh);
   1097  fail_1:
   1098 	return (rv);
   1099 }
   1100