Home | History | Annotate | Line # | Download | only in pcmcia
if_ne_pcmcia.c revision 1.105
      1 /*	$NetBSD: if_ne_pcmcia.c,v 1.105 2003/10/25 18:29:40 christos 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.105 2003/10/25 18:29:40 christos 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_CNET_NE2000,
    184       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    185       PCMCIA_CIS_CNET_NE2000,
    186       0, -1, { 0x00, 0x80, 0xad } },
    187 
    188     { PCMCIA_STR_ZONET_ZEN,
    189       PCMCIA_VENDOR_ZONET, PCMCIA_PRODUCT_ZONET_ZEN,
    190       PCMCIA_CIS_ZONET_ZEN,
    191       0, -1, { 0x00, 0x00, 0x00 } },
    192 
    193     /*
    194      * You have to add new entries which contains
    195      * PCMCIA_VENDOR_INVALID and/or PCMCIA_PRODUCT_INVALID
    196      * in front of this comment.
    197      *
    198      * There are cards which use a generic vendor and product id but needs
    199      * a different handling depending on the cis_info, so ne2000_match
    200      * needs a table where the exceptions comes first and then the normal
    201      * product and vendor entries.
    202      */
    203 
    204     { PCMCIA_STR_IBM_INFOMOVER,
    205       PCMCIA_VENDOR_IBM, PCMCIA_PRODUCT_IBM_INFOMOVER,
    206       PCMCIA_CIS_IBM_INFOMOVER,
    207       0, 0x0ff0, { 0x08, 0x00, 0x5a } },
    208 
    209     { PCMCIA_STR_IBM_INFOMOVER,
    210       PCMCIA_VENDOR_IBM, PCMCIA_PRODUCT_IBM_INFOMOVER,
    211       PCMCIA_CIS_IBM_INFOMOVER,
    212       0, 0x0ff0, { 0x00, 0x04, 0xac } },
    213 
    214     { PCMCIA_STR_IBM_INFOMOVER,
    215       PCMCIA_VENDOR_IBM, PCMCIA_PRODUCT_IBM_INFOMOVER,
    216       PCMCIA_CIS_IBM_INFOMOVER,
    217       0, 0x0ff0, { 0x00, 0x06, 0x29 } },
    218 
    219     /* NEC 9801N_J12 */
    220     { PCMCIA_STR_IBM_INFOMOVER,
    221       PCMCIA_VENDOR_IBM, PCMCIA_PRODUCT_IBM_INFOMOVER,
    222       PCMCIA_CIS_IBM_INFOMOVER,
    223       0, 0x0ff0, { 0x00, 0x00, 0x4c } },
    224 
    225     { PCMCIA_STR_LINKSYS_ECARD_1,
    226       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ECARD_1,
    227       PCMCIA_CIS_LINKSYS_ECARD_1,
    228       0, -1, { 0x00, 0x80, 0xc8 } },
    229 
    230     { PCMCIA_STR_PLANEX_FNW3600T,
    231       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_COMBO_ECARD,
    232       PCMCIA_CIS_PLANEX_FNW3600T,
    233       0, -1, { 0x00, 0x90, 0xcc }, NE2000DVF_DL10019 },
    234 
    235     { PCMCIA_STR_SVEC_PN650TX,
    236       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_COMBO_ECARD,
    237       PCMCIA_CIS_SVEC_PN650TX,
    238       0, -1, { 0x00, 0xe0, 0x98 }, NE2000DVF_DL10019 },
    239 
    240     /*
    241      * This entry should be here so that above two cards doesn't
    242      * match with this.  FNW-3700T won't match above entries due to
    243      * MAC address check.
    244      */
    245     { PCMCIA_STR_LANTECH_FASTNETTX,
    246       PCMCIA_VENDOR_LANTECH, PCMCIA_PRODUCT_LANTECH_FASTNETTX,
    247       PCMCIA_CIS_LANTECH_FASTNETTX,
    248       0, -1, { 0x00, 0x04, 0x1c }, NE2000DVF_AX88190 },
    249 
    250     { PCMCIA_STR_PLANEX_FNW3700T,
    251       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_COMBO_ECARD,
    252       PCMCIA_CIS_PLANEX_FNW3700T,
    253       0, -1, { 0x00, 0x90, 0xcc }, NE2000DVF_AX88190 },
    254 
    255     { PCMCIA_STR_LINKSYS_ETHERFAST,
    256       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ETHERFAST,
    257       PCMCIA_CIS_LINKSYS_ETHERFAST,
    258       0, -1, { 0x00, 0x80, 0xc8 }, NE2000DVF_DL10019 },
    259 
    260     { PCMCIA_STR_LINKSYS_ETHERFAST,
    261       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ETHERFAST,
    262       PCMCIA_CIS_LINKSYS_ETHERFAST,
    263       0, -1, { 0x00, 0x40, 0x05 }, NE2000DVF_DL10019 },
    264 
    265     { PCMCIA_STR_LINKSYS_ETHERFAST,
    266       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ETHERFAST,
    267       PCMCIA_CIS_LINKSYS_ETHERFAST,
    268       0, -1, { 0x00, 0x90, 0xfe }, NE2000DVF_DL10019 },
    269 
    270     { PCMCIA_STR_LINKSYS_ETHERFAST,
    271       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ETHERFAST,
    272       PCMCIA_CIS_LINKSYS_ETHERFAST,
    273       0, -1, { 0x00, 0xa0, 0xb0 }, NE2000DVF_DL10019 },
    274 
    275     { PCMCIA_STR_DLINK_DE650,
    276       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ETHERFAST,
    277       PCMCIA_CIS_LINKSYS_ETHERFAST,
    278       0, -1, { 0x00, 0x50, 0xba }, NE2000DVF_DL10019 },
    279 
    280     { PCMCIA_STR_DLINK_DE650,
    281       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ETHERFAST,
    282       PCMCIA_CIS_DLINK_DE650,
    283       0, -1, { 0x00, 0xe0, 0x98 }, NE2000DVF_DL10019 },
    284 
    285     { PCMCIA_STR_DLINK_DFE670TXD,
    286       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_NETGEAR_FA410TXC,
    287       PCMCIA_CIS_DLINK_DFE670TXD,
    288       0, -1, { 0x00, 0x50, 0xba }, NE2000DVF_DL10019 },
    289 
    290     { PCMCIA_STR_MELCO_LPC2_TX,
    291       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ETHERFAST,
    292       PCMCIA_CIS_MELCO_LPC2_TX,
    293       0, -1, { 0x00, 0x40, 0x26 }, NE2000DVF_DL10019 },
    294 
    295     { PCMCIA_STR_LINKSYS_COMBO_ECARD,
    296       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_COMBO_ECARD,
    297       PCMCIA_CIS_LINKSYS_COMBO_ECARD,
    298       0, -1, { 0x00, 0x80, 0xc8 } },
    299 
    300     { PCMCIA_STR_LINKSYS_TRUST_COMBO_ECARD,
    301       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_TRUST_COMBO_ECARD,
    302       PCMCIA_CIS_LINKSYS_TRUST_COMBO_ECARD,
    303       0, 0x0120, { 0x20, 0x04, 0x49 } },
    304 
    305     /* Although the comments above say to put VENDOR/PRODUCT INVALID IDs
    306        above this list, we need to keep this one below the ECARD_1, or else
    307        both will match the same more-generic entry rather than the more
    308        specific one above with proper vendor and product IDs. */
    309     { PCMCIA_STR_LINKSYS_ECARD_2,
    310       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    311       PCMCIA_CIS_LINKSYS_ECARD_2,
    312       0, -1, { 0x00, 0x80, 0xc8 } },
    313 
    314     /*
    315      * D-Link DE-650 has many minor versions:
    316      *
    317      *   CIS information          Manufacturer Product  Note
    318      * 1 "D-Link, DE-650"             INVALID  INVALID  white card
    319      * 2 "D-Link, DE-650, Ver 01.00"  INVALID  INVALID  became bare metal
    320      * 3 "D-Link, DE-650, Ver 01.00"   0x149    0x265   minor change in look
    321      * 4 "D-Link, DE-650, Ver 01.00"   0x149    0x265   collision LED added
    322      *
    323      * While the 1st and the 2nd types should use the "D-Link DE-650" entry,
    324      * the 3rd and the 4th types should use the "Linksys EtherCard" entry.
    325      * Therefore, this enty must be below the LINKSYS_ECARD_1.  --itohy
    326      */
    327     { PCMCIA_STR_DLINK_DE650,
    328       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    329       PCMCIA_CIS_DLINK_DE650,
    330       0, 0x0040, { 0x00, 0x80, 0xc8 } },
    331 
    332     /*
    333      * IO-DATA PCLA/TE and later version of PCLA/T has valid
    334      * vendor/product ID and it is possible to read MAC address
    335      * using standard I/O ports.  It also read from CIS offset 0x01c0.
    336      * On the other hand, earlier version of PCLA/T doesn't have valid
    337      * vendor/product ID and MAC address must be read from CIS offset
    338      * 0x0ff0 (i.e., usual ne2000 way to read it doesn't work).
    339      * And CIS information of earlier and later version of PCLA/T are
    340      * same except fourth element.  So, for now, we place the entry for
    341      * PCLA/TE (and later version of PCLA/T) followed by entry
    342      * for the earlier version of PCLA/T (or, modify to match all CIS
    343      * information and have three or more individual entries).
    344      */
    345     { PCMCIA_STR_IODATA_PCLATE,
    346       PCMCIA_VENDOR_IODATA, PCMCIA_PRODUCT_IODATA_PCLATE,
    347       PCMCIA_CIS_IODATA_PCLATE,
    348       0, -1, { 0x00, 0xa0, 0xb0 } },
    349 
    350     /*
    351      * This entry should be placed after above PCLA-TE entry.
    352      * See above comments for detail.
    353      */
    354     { PCMCIA_STR_IODATA_PCLAT,
    355       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    356       PCMCIA_CIS_IODATA_PCLAT,
    357       0, 0x0ff0, { 0x00, 0xa0, 0xb0 } },
    358 
    359     { PCMCIA_STR_DAYNA_COMMUNICARD_E_1,
    360       PCMCIA_VENDOR_DAYNA, PCMCIA_PRODUCT_DAYNA_COMMUNICARD_E_1,
    361       PCMCIA_CIS_DAYNA_COMMUNICARD_E_1,
    362       0, 0x0110, { 0x00, 0x80, 0x19 } },
    363 
    364     { PCMCIA_STR_DAYNA_COMMUNICARD_E_2,
    365       PCMCIA_VENDOR_DAYNA, PCMCIA_PRODUCT_DAYNA_COMMUNICARD_E_2,
    366       PCMCIA_CIS_DAYNA_COMMUNICARD_E_2,
    367       0, -1, { 0x00, 0x80, 0x19 } },
    368 
    369     { PCMCIA_STR_COREGA_ETHER_PCC_T,
    370       PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_ETHER_PCC_T,
    371       PCMCIA_CIS_COREGA_ETHER_PCC_T,
    372       0, -1, { 0x00, 0x00, 0xf4 } },
    373 
    374     { PCMCIA_STR_COREGA_ETHER_PCC_TD,
    375       PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_ETHER_PCC_TD,
    376       PCMCIA_CIS_COREGA_ETHER_PCC_TD,
    377       0, -1, { 0x00, 0x00, 0xf4 } },
    378 
    379     { PCMCIA_STR_COREGA_ETHER_II_PCC_T,
    380       PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_ETHER_II_PCC_T,
    381       PCMCIA_CIS_COREGA_ETHER_II_PCC_T,
    382       0, -1, { 0x00, 0x00, 0xf4 } },
    383 
    384     { PCMCIA_STR_COREGA_ETHER_II_PCC_TD,
    385       PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_ETHER_II_PCC_TD,
    386       PCMCIA_CIS_COREGA_ETHER_II_PCC_TD,
    387       0, -1, { 0x00, 0x00, 0xf4 } },
    388 
    389     { PCMCIA_STR_COREGA_FAST_ETHER_PCC_TX,
    390       PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_FAST_ETHER_PCC_TX,
    391       PCMCIA_CIS_COREGA_FAST_ETHER_PCC_TX,
    392       0, -1, { 0x00, 0x00, 0xf4 }, NE2000DVF_DL10019 },
    393 
    394     { PCMCIA_STR_COREGA_FETHER_PCC_TXF,
    395       PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_FETHER_PCC_TXF,
    396       PCMCIA_CIS_COREGA_FETHER_PCC_TXF,
    397       0, -1, { 0x00, 0x90, 0x99 }, NE2000DVF_DL10019 },
    398 
    399     { PCMCIA_STR_COREGA_FETHER_PCC_TXD,
    400       PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_FETHER_PCC_TXD,
    401       PCMCIA_CIS_COREGA_FETHER_PCC_TXD,
    402       0, -1, { 0x00, 0x90, 0x99 } },
    403 
    404     { PCMCIA_STR_COMPEX_LINKPORT_ENET_B,
    405       PCMCIA_VENDOR_COMPEX, PCMCIA_PRODUCT_COMPEX_LINKPORT_ENET_B,
    406       PCMCIA_CIS_COMPEX_LINKPORT_ENET_B,
    407       0, 0x01c0, { 0x00, 0xa0, 0x0c } },
    408 
    409     { PCMCIA_STR_SMC_EZCARD,
    410       PCMCIA_VENDOR_SMC, PCMCIA_PRODUCT_SMC_EZCARD,
    411       PCMCIA_CIS_SMC_EZCARD,
    412       0, 0x01c0, { 0x00, 0xe0, 0x29 } },
    413 
    414     { PCMCIA_STR_SMC_8041,
    415       PCMCIA_VENDOR_SMC, PCMCIA_PRODUCT_SMC_8041,
    416       PCMCIA_CIS_SMC_8041,
    417       0, -1, { 0x00, 0x04, 0xe2 } },
    418 
    419     { PCMCIA_STR_SOCKET_EA_ETHER,
    420       PCMCIA_VENDOR_SOCKET, PCMCIA_PRODUCT_SOCKET_EA_ETHER,
    421       PCMCIA_CIS_SOCKET_EA_ETHER,
    422       0, -1, { 0x00, 0xc0, 0x1b } },
    423 
    424     { PCMCIA_STR_SOCKET_LP_ETHER_CF,
    425       PCMCIA_VENDOR_SOCKET, PCMCIA_PRODUCT_SOCKET_LP_ETHER_CF,
    426       PCMCIA_CIS_SOCKET_LP_ETHER_CF,
    427       0, -1, { 0x00, 0xc0, 0x1b } },
    428 
    429     { PCMCIA_STR_SOCKET_LP_ETH_10_100_CF,
    430       PCMCIA_VENDOR_SOCKET, PCMCIA_PRODUCT_SOCKET_LP_ETH_10_100_CF,
    431       PCMCIA_CIS_SOCKET_LP_ETH_10_100_CF,
    432       0, -1, { 0x00, 0xe0, 0x98 }, NE2000DVF_DL10019 },
    433 
    434     { PCMCIA_STR_SOCKET_LP_ETHER,
    435       PCMCIA_VENDOR_SOCKET, PCMCIA_PRODUCT_SOCKET_LP_ETHER,
    436       PCMCIA_CIS_SOCKET_LP_ETHER,
    437       0, -1, { 0x00, 0xc0, 0x1b } },
    438 
    439     { PCMCIA_STR_KINGSTON_KNE2,
    440       PCMCIA_VENDOR_KINGSTON, PCMCIA_PRODUCT_KINGSTON_KNE2,
    441       PCMCIA_CIS_KINGSTON_KNE2,
    442       0, -1, { 0x00, 0xc0, 0xf0 } },
    443 
    444     { PCMCIA_STR_XIRCOM_CFE_10,
    445       PCMCIA_VENDOR_XIRCOM, PCMCIA_PRODUCT_XIRCOM_CFE_10,
    446       PCMCIA_CIS_XIRCOM_CFE_10,
    447       0, -1, { 0x00, 0x10, 0xa4 } },
    448 
    449     { PCMCIA_STR_MELCO_LPC3_TX,
    450       PCMCIA_VENDOR_MELCO, PCMCIA_PRODUCT_MELCO_LPC3_TX,
    451       PCMCIA_CIS_MELCO_LPC3_TX,
    452       0, -1, { 0x00, 0x40, 0x26 }, NE2000DVF_AX88190 },
    453 
    454     { PCMCIA_STR_BUFFALO_LPC3_CLT,
    455       PCMCIA_VENDOR_BUFFALO, PCMCIA_PRODUCT_BUFFALO_LPC3_CLT,
    456       PCMCIA_CIS_BUFFALO_LPC3_CLT,
    457       0, -1, { 0x00, 0x07, 0x40 } },
    458 
    459     { PCMCIA_STR_BUFFALO_LPC4_CLX,
    460       PCMCIA_VENDOR_BUFFALO, PCMCIA_PRODUCT_BUFFALO_LPC4_CLX,
    461       PCMCIA_CIS_BUFFALO_LPC4_CLX,
    462       0, -1, { 0x00, 0x40, 0xfa }, NE2000DVF_AX88190 | NE2000DVF_AX88790 },
    463 
    464     { PCMCIA_STR_BILLIONTON_LNT10TN,
    465       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    466       PCMCIA_CIS_BILLIONTON_LNT10TN,
    467       0, -1, { 0x00, 0x00, 0x00 } },
    468 
    469     { PCMCIA_STR_BILLIONTON_CFLT10N,
    470       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    471       PCMCIA_CIS_BILLIONTON_CFLT10N,
    472       0, -1, { 0x00, 0x00, 0x00 } },
    473 
    474     { PCMCIA_STR_NDC_ND5100_E,
    475       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    476       PCMCIA_CIS_NDC_ND5100_E,
    477       0, -1, { 0x00, 0x80, 0xc6 } },
    478 
    479     { PCMCIA_STR_TELECOMDEVICE_TCD_HPC100,
    480       PCMCIA_VENDOR_TELECOMDEVICE, PCMCIA_PRODUCT_TELECOMDEVICE_TCD_HPC100,
    481       PCMCIA_CIS_TELECOMDEVICE_TCD_HPC100,
    482       0, -1, { 0x00, 0x40, 0x26 }, NE2000DVF_AX88190 },
    483 
    484     { PCMCIA_STR_MACNICA_ME1_JEIDA,
    485       PCMCIA_VENDOR_MACNICA, PCMCIA_PRODUCT_MACNICA_ME1_JEIDA,
    486       PCMCIA_CIS_MACNICA_ME1_JEIDA,
    487       0, 0x00b8, { 0x08, 0x00, 0x42 } },
    488 
    489     { PCMCIA_STR_NETGEAR_FA411,
    490       PCMCIA_VENDOR_NETGEAR, PCMCIA_PRODUCT_NETGEAR_FA411,
    491       PCMCIA_CIS_NETGEAR_FA411,
    492       0, -1, { 0x00, 0x40, 0xf4 } },
    493 
    494     { PCMCIA_STR_DYNALINK_L10C,
    495       PCMCIA_VENDOR_DYNALINK, PCMCIA_PRODUCT_DYNALINK_L10C,
    496       PCMCIA_CIS_DYNALINK_L10C,
    497       0, -1, { 0x00, 0x00, 0x00 } },
    498 
    499 #if 0
    500     /* the rest of these are stolen from the linux pcnet pcmcia device
    501        driver.  Since I don't know the manfid or cis info strings for
    502        any of them, they're not compiled in until I do. */
    503     { "APEX MultiCard",
    504       0x0000, 0x0000, NULL, NULL, 0,
    505       0x03f4, { 0x00, 0x20, 0xe5 } },
    506     { "ASANTE FriendlyNet",
    507       0x0000, 0x0000, NULL, NULL, 0,
    508       0x4910, { 0x00, 0x00, 0x94 } },
    509     { "Danpex EN-6200P2",
    510       0x0000, 0x0000, NULL, NULL, 0,
    511       0x0110, { 0x00, 0x40, 0xc7 } },
    512     { "DataTrek NetCard",
    513       0x0000, 0x0000, NULL, NULL, 0,
    514       0x0ff0, { 0x00, 0x20, 0xe8 } },
    515     { "Dayna CommuniCard E",
    516       0x0000, 0x0000, NULL, NULL, 0,
    517       0x0110, { 0x00, 0x80, 0x19 } },
    518     { "EP-210 Ethernet",
    519       0x0000, 0x0000, NULL, NULL, 0,
    520       0x0110, { 0x00, 0x40, 0x33 } },
    521     { "ELECOM Laneed LD-CDWA",
    522       0x0000, 0x0000, NULL, NULL, 0,
    523       0x00b8, { 0x08, 0x00, 0x42 } },
    524     { "Grey Cell GCS2220",
    525       0x0000, 0x0000, NULL, NULL, 0,
    526       0x0000, { 0x00, 0x47, 0x43 } },
    527     { "Hypertec Ethernet",
    528       0x0000, 0x0000, NULL, NULL, 0,
    529       0x01c0, { 0x00, 0x40, 0x4c } },
    530     { "IBM CCAE",
    531       0x0000, 0x0000, NULL, NULL, 0,
    532       0x0ff0, { 0x08, 0x00, 0x5a } },
    533     { "IBM CCAE",
    534       0x0000, 0x0000, NULL, NULL, 0,
    535       0x0ff0, { 0x00, 0x04, 0xac } },
    536     { "IBM CCAE",
    537       0x0000, 0x0000, NULL, NULL, 0,
    538       0x0ff0, { 0x00, 0x06, 0x29 } },
    539     { "IBM FME",
    540       0x0000, 0x0000, NULL, NULL, 0,
    541       0x0374, { 0x00, 0x04, 0xac } },
    542     { "IBM FME",
    543       0x0000, 0x0000, NULL, NULL, 0,
    544       0x0374, { 0x08, 0x00, 0x5a } },
    545     { "Katron PE-520",
    546       0x0000, 0x0000, NULL, NULL, 0,
    547       0x0110, { 0x00, 0x40, 0xf6 } },
    548     { "Kingston KNE-PCM/x",
    549       0x0000, 0x0000, NULL, NULL, 0,
    550       0x0ff0, { 0x00, 0xc0, 0xf0 } },
    551     { "Kingston KNE-PCM/x",
    552       0x0000, 0x0000, NULL, NULL, 0,
    553       0x0ff0, { 0xe2, 0x0c, 0x0f } },
    554     { "Longshine LCS-8534",
    555       0x0000, 0x0000, NULL, NULL, 0,
    556       0x0000, { 0x08, 0x00, 0x00 } },
    557     { "Maxtech PCN2000",
    558       0x0000, 0x0000, NULL, NULL, 0,
    559       0x5000, { 0x00, 0x00, 0xe8 } },
    560     { "NDC Instant-Link",
    561       0x0000, 0x0000, NULL, NULL, 0,
    562       0x003a, { 0x00, 0x80, 0xc6 } },
    563     { "NE2000 Compatible",
    564       0x0000, 0x0000, NULL, NULL, 0,
    565       0x0ff0, { 0x00, 0xa0, 0x0c } },
    566     { "Network General Sniffer",
    567       0x0000, 0x0000, NULL, NULL, 0,
    568       0x0ff0, { 0x00, 0x00, 0x65 } },
    569     { "Panasonic VEL211",
    570       0x0000, 0x0000, NULL, NULL, 0,
    571       0x0ff0, { 0x00, 0x80, 0x45 } },
    572     { "SCM Ethernet",
    573       0x0000, 0x0000, NULL, NULL, 0,
    574       0x0ff0, { 0x00, 0x20, 0xcb } },
    575     { "Volktek NPL-402CT",
    576       0x0000, 0x0000, NULL, NULL, 0,
    577       0x0060, { 0x00, 0x40, 0x05 } },
    578 #endif
    579 
    580     { PCMCIA_STR_ALLIEDTELESIS_LA_PCM,
    581       PCMCIA_VENDOR_ALLIEDTELESIS, PCMCIA_PRODUCT_ALLIEDTELESIS_LA_PCM,
    582       PCMCIA_CIS_ALLIEDTELESIS_LA_PCM,
    583       0, 0x0ff0, { 0x00, 0x00, 0xf4 } },
    584 };
    585 
    586 #define	NE2000_NDEVS	(sizeof(ne2000devs) / sizeof(ne2000devs[0]))
    587 
    588 #define ne2000_match(card, fct, n) \
    589 ((((((card)->manufacturer != PCMCIA_VENDOR_INVALID) && \
    590     ((card)->manufacturer == ne2000devs[(n)].manufacturer) && \
    591     ((card)->product != PCMCIA_PRODUCT_INVALID) && \
    592     ((card)->product == ne2000devs[(n)].product)) || \
    593    ((ne2000devs[(n)].cis_info[0]) && (ne2000devs[(n)].cis_info[1]) && \
    594     (strcmp((card)->cis1_info[0], ne2000devs[(n)].cis_info[0]) == 0) && \
    595     (strcmp((card)->cis1_info[1], ne2000devs[(n)].cis_info[1]) == 0))) && \
    596   ((fct) == ne2000devs[(n)].function))? \
    597  &ne2000devs[(n)]:NULL)
    598 
    599 int
    600 ne_pcmcia_match(parent, match, aux)
    601 	struct device *parent;
    602 	struct cfdata *match;
    603 	void *aux;
    604 {
    605 	struct pcmcia_attach_args *pa = aux;
    606 	int i;
    607 
    608 	for (i = 0; i < NE2000_NDEVS; i++) {
    609 		if (ne2000_match(pa->card, pa->pf->number, i))
    610 			return (1);
    611 	}
    612 
    613 	return (0);
    614 }
    615 
    616 void
    617 ne_pcmcia_attach(parent, self, aux)
    618 	struct device *parent, *self;
    619 	void *aux;
    620 {
    621 	struct ne_pcmcia_softc *psc = (void *) self;
    622 	struct ne2000_softc *nsc = &psc->sc_ne2000;
    623 	struct dp8390_softc *dsc = &nsc->sc_dp8390;
    624 	struct pcmcia_attach_args *pa = aux;
    625 	struct pcmcia_config_entry *cfe;
    626 	const struct ne2000dev *ne_dev = NULL;
    627 	int i;
    628 	u_int8_t myea[6], *enaddr;
    629 	const char *typestr = "";
    630 
    631 	psc->sc_pf = pa->pf;
    632 
    633 	SIMPLEQ_FOREACH(cfe, &pa->pf->cfe_head, cfe_list) {
    634 #if 0
    635 		/*
    636 		 * Some ne2000 driver's claim to have memory; others don't.
    637 		 * Since I don't care, I don't check.
    638 		 */
    639 
    640 		if (cfe->num_memspace != 1) {
    641 			printf(": unexpected number of memory spaces "
    642 			    " %d should be 1\n", cfe->num_memspace);
    643 			continue;
    644 		}
    645 #endif
    646 
    647 		if (cfe->num_iospace == 1) {
    648 			if (cfe->iospace[0].length != NE2000_NPORTS) {
    649 				printf(": unexpected I/O space configuration"
    650 				    " (continued)\n%s", dsc->sc_dev.dv_xname);
    651 				/* XXX really safe for all other cards? */
    652 			}
    653 		} else if (cfe->num_iospace == 2) {
    654 			/*
    655 			 * Some cards report a separate space for NIC and ASIC.
    656 			 * This make some sense, but we must allocate a single
    657 			 * NE2000_NPORTS-sized chunk, due to brain damaged
    658 			 * address decoders on some of these cards.
    659 			 */
    660 			if (cfe->iospace[0].length + cfe->iospace[1].length !=
    661 			    NE2000_NPORTS) {
    662 #ifdef DIAGNOSTIC
    663 				printf(": unexpected I/O "
    664 				    "space configuration; ignored\n%s",
    665 				    dsc->sc_dev.dv_xname);
    666 #endif
    667 				continue;
    668 			}
    669 		} else {
    670 #ifdef DIAGNOSTIC
    671 			printf(": unexpected number of i/o spaces %d"
    672 			    " should be 1 or 2; ignored\n%s",
    673 			    cfe->num_iospace, dsc->sc_dev.dv_xname);
    674 #endif
    675 			continue;
    676 		}
    677 
    678 		if (pcmcia_io_alloc(pa->pf, cfe->iospace[0].start,
    679 		    NE2000_NPORTS, NE2000_NPORTS, &psc->sc_pcioh)) {
    680 #ifdef DIAGNOSTIC
    681 			printf(": can't allocate i/o space %lx; ignored\n%s",
    682 			    cfe->iospace[0].start, dsc->sc_dev.dv_xname);
    683 #endif
    684 			continue;
    685 		}
    686 
    687 		/* Ok, found. */
    688 		break;
    689 	}
    690 
    691 	if (cfe == NULL) {
    692 		printf(": no suitable config entry\n");
    693 		goto fail_1;
    694 	}
    695 
    696 	dsc->sc_regt = psc->sc_pcioh.iot;
    697 	dsc->sc_regh = psc->sc_pcioh.ioh;
    698 
    699 	nsc->sc_asict = psc->sc_pcioh.iot;
    700 	if (bus_space_subregion(dsc->sc_regt, dsc->sc_regh,
    701 	    NE2000_ASIC_OFFSET, NE2000_ASIC_NPORTS,
    702 	    &nsc->sc_asich)) {
    703 		printf(": can't get subregion for asic\n");
    704 		goto fail_2;
    705 	}
    706 
    707 	/* Set up power management hooks. */
    708 	dsc->sc_enable = ne_pcmcia_enable;
    709 	dsc->sc_disable = ne_pcmcia_disable;
    710 
    711 	/* Enable the card. */
    712 	pcmcia_function_init(pa->pf, cfe);
    713 	if (pcmcia_function_enable(pa->pf)) {
    714 		printf(": function enable failed\n");
    715 		goto fail_2;
    716 	}
    717 
    718 	/* some cards claim to be io16, but they're lying. */
    719 	if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_IO8,
    720 	    NE2000_NIC_OFFSET, NE2000_NIC_NPORTS,
    721 	    &psc->sc_pcioh, &psc->sc_nic_io_window)) {
    722 		printf(": can't map NIC i/o space\n");
    723 		goto fail_3;
    724 	}
    725 
    726 	if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_IO16,
    727 	    NE2000_ASIC_OFFSET, NE2000_ASIC_NPORTS,
    728 	    &psc->sc_pcioh, &psc->sc_asic_io_window)) {
    729 		printf(": can't map ASIC i/o space\n");
    730 		goto fail_4;
    731 	}
    732 
    733 	printf("\n");
    734 
    735 	/*
    736 	 * Read the station address from the board.
    737 	 */
    738 	i = 0;
    739 again:
    740 	enaddr = NULL;			/* Ask ASIC by default */
    741 	typestr = "";			/* clear previous card-type */
    742 	for (; i < NE2000_NDEVS; i++) {
    743 		ne_dev = ne2000_match(pa->card, pa->pf->number, i);
    744 		if (ne_dev != NULL) {
    745 			if (ne_dev->enet_maddr >= 0) {
    746 				enaddr = ne_pcmcia_get_enaddr(psc,
    747 				    ne_dev->enet_maddr, myea);
    748 				if (enaddr == NULL)
    749 					continue;
    750 			}
    751 			break;
    752 		}
    753 	}
    754 	if (i == NE2000_NDEVS) {
    755 		printf("%s (manf %08x prod %08x) cis %s %s: "
    756 		       "can't match ethernet vendor code\n",
    757 		       dsc->sc_dev.dv_xname,
    758 		       pa->manufacturer, pa->product,
    759 		       pa->card->cis1_info[0], pa->card->cis1_info[1]);
    760 		goto fail_5;
    761 	}
    762 
    763 	if ((ne_dev->flags & NE2000DVF_DL10019) != 0) {
    764 		u_int8_t type;
    765 
    766 		enaddr = ne_pcmcia_dl10019_get_enaddr(psc, myea);
    767 		if (enaddr == NULL) {
    768 			++i;
    769 			goto again;
    770 		}
    771 
    772 		dsc->sc_mediachange = dl10019_mediachange;
    773 		dsc->sc_mediastatus = dl10019_mediastatus;
    774 		dsc->init_card = dl10019_init_card;
    775 		dsc->stop_card = dl10019_stop_card;
    776 		dsc->sc_media_init = dl10019_media_init;
    777 		dsc->sc_media_fini = dl10019_media_fini;
    778 
    779 		/* Determine if this is a DL10019 or a DL10022. */
    780 		type = bus_space_read_1(nsc->sc_asict, nsc->sc_asich, 0x0f);
    781 		if (type == 0x91 || type == 0x99) {
    782 			nsc->sc_type = NE2000_TYPE_DL10022;
    783 			typestr = " (DL10022)";
    784 		} else {
    785 			nsc->sc_type = NE2000_TYPE_DL10019;
    786 			typestr = " (DL10019)";
    787 		}
    788 	}
    789 
    790 	if ((ne_dev->flags & NE2000DVF_AX88190) != 0) {
    791 		if (ne_pcmcia_ax88190_set_iobase(psc)) {
    792 			++i;
    793 			goto again;
    794 		}
    795 
    796 		dsc->sc_mediachange = ax88190_mediachange;
    797 		dsc->sc_mediastatus = ax88190_mediastatus;
    798 		dsc->init_card = ax88190_init_card;
    799 		dsc->stop_card = ax88190_stop_card;
    800 		dsc->sc_media_init = ax88190_media_init;
    801 		dsc->sc_media_fini = ax88190_media_fini;
    802 
    803 		if ((ne_dev->flags & NE2000DVF_AX88790) != 0) {
    804 			nsc->sc_type = NE2000_TYPE_AX88790;
    805 			typestr = " (AX88790)";
    806 		} else {
    807 			nsc->sc_type = NE2000_TYPE_AX88190;
    808 			typestr = " (AX88190)";
    809 		}
    810 	}
    811 
    812 	if (enaddr != NULL) {
    813 		/*
    814 		 * Make sure this is what we expect.
    815 		 */
    816 		if (enaddr[0] != ne_dev->enet_vendor[0] ||
    817 		    enaddr[1] != ne_dev->enet_vendor[1] ||
    818 		    enaddr[2] != ne_dev->enet_vendor[2]) {
    819 			++i;
    820 			goto again;
    821 		}
    822 	}
    823 
    824 	/*
    825 	 * Check for a RealTek 8019.
    826 	 */
    827 	if (nsc->sc_type == 0) {
    828 		bus_space_write_1(dsc->sc_regt, dsc->sc_regh, ED_P0_CR,
    829 		    ED_CR_PAGE_0 | ED_CR_STP);
    830 		if (bus_space_read_1(dsc->sc_regt, dsc->sc_regh,
    831 		    NERTL_RTL0_8019ID0) == RTL0_8019ID0 &&
    832 		    bus_space_read_1(dsc->sc_regt, dsc->sc_regh,
    833 		    NERTL_RTL0_8019ID1) == RTL0_8019ID1) {
    834 			typestr = " (RTL8019)";
    835 			dsc->sc_mediachange = rtl80x9_mediachange;
    836 			dsc->sc_mediastatus = rtl80x9_mediastatus;
    837 			dsc->init_card = rtl80x9_init_card;
    838 			dsc->sc_media_init = rtl80x9_media_init;
    839 		}
    840 	}
    841 
    842 	printf("%s: %s%s Ethernet\n", dsc->sc_dev.dv_xname, ne_dev->name,
    843 	    typestr);
    844 
    845 	if (ne2000_attach(nsc, enaddr))
    846 		goto fail_5;
    847 
    848 	pcmcia_function_disable(pa->pf);
    849 	return;
    850 
    851  fail_5:
    852 	/* Unmap ASIC i/o windows. */
    853 	pcmcia_io_unmap(psc->sc_pf, psc->sc_asic_io_window);
    854 
    855  fail_4:
    856 	/* Unmap NIC i/o windows. */
    857 	pcmcia_io_unmap(psc->sc_pf, psc->sc_nic_io_window);
    858 
    859  fail_3:
    860 	pcmcia_function_disable(pa->pf);
    861 
    862  fail_2:
    863 	/* Free our i/o space. */
    864 	pcmcia_io_free(psc->sc_pf, &psc->sc_pcioh);
    865 
    866  fail_1:
    867 	psc->sc_nic_io_window = -1;
    868 }
    869 
    870 int
    871 ne_pcmcia_detach(self, flags)
    872 	struct device *self;
    873 	int flags;
    874 {
    875 	struct ne_pcmcia_softc *psc = (struct ne_pcmcia_softc *)self;
    876 	int error;
    877 
    878 	if (psc->sc_nic_io_window == -1)
    879 		/* Nothing to detach. */
    880 		return (0);
    881 
    882 	error = ne2000_detach(&psc->sc_ne2000, flags);
    883 	if (error != 0)
    884 		return (error);
    885 
    886 	/* Unmap our i/o windows. */
    887 	pcmcia_io_unmap(psc->sc_pf, psc->sc_asic_io_window);
    888 	pcmcia_io_unmap(psc->sc_pf, psc->sc_nic_io_window);
    889 
    890 	/* Free our i/o space. */
    891 	pcmcia_io_free(psc->sc_pf, &psc->sc_pcioh);
    892 
    893 	return (0);
    894 }
    895 
    896 int
    897 ne_pcmcia_enable(dsc)
    898 	struct dp8390_softc *dsc;
    899 {
    900 	struct ne_pcmcia_softc *psc = (struct ne_pcmcia_softc *)dsc;
    901 	struct ne2000_softc *nsc = &psc->sc_ne2000;
    902 	struct pcmcia_mem_handle pcmh;
    903 
    904 	/* set up the interrupt */
    905 	psc->sc_ih = pcmcia_intr_establish(psc->sc_pf, IPL_NET, dp8390_intr,
    906 	    dsc);
    907 	if (psc->sc_ih == NULL) {
    908 		printf("%s: couldn't establish interrupt\n",
    909 		    dsc->sc_dev.dv_xname);
    910 		goto fail_1;
    911 	}
    912 
    913 	if (pcmcia_function_enable(psc->sc_pf))
    914 		goto fail_2;
    915 
    916 	if (nsc->sc_type == NE2000_TYPE_AX88190 ||
    917 	    nsc->sc_type == NE2000_TYPE_AX88790) {
    918 		if (ne_pcmcia_ax88190_set_iobase(psc))
    919 			goto fail_3;
    920 		if (nsc->sc_type == NE2000_TYPE_AX88790) {
    921 			bus_size_t offset;
    922 			int mwindow;
    923 
    924 			if (pcmcia_mem_alloc(psc->sc_pf,
    925 			    AX88790_CSR_SIZE, &pcmh)) {
    926 				printf("%s: can't alloc mem for CSR\n",
    927 				    dsc->sc_dev.dv_xname);
    928 				goto fail_3;
    929 			}
    930 
    931 			if (pcmcia_mem_map(psc->sc_pf, PCMCIA_MEM_ATTR,
    932 			    AX88790_CSR, AX88790_CSR_SIZE,
    933 			    &pcmh, &offset, &mwindow)) {
    934 				printf("%s: can't map mem for CSR\n",
    935 				    dsc->sc_dev.dv_xname);
    936 				goto fail_4;
    937 			}
    938 
    939 			bus_space_write_1(pcmh.memt, pcmh.memh, offset, 0x4);
    940 			pcmcia_mem_unmap(psc->sc_pf, mwindow);
    941 			pcmcia_mem_free(psc->sc_pf, &pcmh);
    942 		}
    943 	}
    944 
    945 	return (0);
    946 
    947  fail_4:
    948 	pcmcia_mem_free(psc->sc_pf, &pcmh);
    949  fail_3:
    950 	pcmcia_function_disable(psc->sc_pf);
    951  fail_2:
    952 	pcmcia_intr_disestablish(psc->sc_pf, psc->sc_ih);
    953  fail_1:
    954 	return (1);
    955 }
    956 
    957 void
    958 ne_pcmcia_disable(dsc)
    959 	struct dp8390_softc *dsc;
    960 {
    961 	struct ne_pcmcia_softc *psc = (struct ne_pcmcia_softc *)dsc;
    962 
    963 	pcmcia_function_disable(psc->sc_pf);
    964 	pcmcia_intr_disestablish(psc->sc_pf, psc->sc_ih);
    965 }
    966 
    967 u_int8_t *
    968 ne_pcmcia_get_enaddr(psc, maddr, myea)
    969 	struct ne_pcmcia_softc *psc;
    970 	int maddr;
    971 	u_int8_t myea[ETHER_ADDR_LEN];
    972 {
    973 	struct ne2000_softc *nsc = &psc->sc_ne2000;
    974 	struct dp8390_softc *dsc = &nsc->sc_dp8390;
    975 	struct pcmcia_mem_handle pcmh;
    976 	bus_size_t offset;
    977 	u_int8_t *enaddr = NULL;
    978 	int j, mwindow;
    979 
    980 	if (maddr < 0)
    981 		return (NULL);
    982 
    983 	if (pcmcia_mem_alloc(psc->sc_pf, ETHER_ADDR_LEN * 2, &pcmh)) {
    984 		printf("%s: can't alloc mem for enet addr\n",
    985 		    dsc->sc_dev.dv_xname);
    986 		goto fail_1;
    987 	}
    988 	if (pcmcia_mem_map(psc->sc_pf, PCMCIA_MEM_ATTR, maddr,
    989 	    ETHER_ADDR_LEN * 2, &pcmh, &offset, &mwindow)) {
    990 		printf("%s: can't map mem for enet addr\n",
    991 		    dsc->sc_dev.dv_xname);
    992 		goto fail_2;
    993 	}
    994 	for (j = 0; j < ETHER_ADDR_LEN; j++)
    995 		myea[j] = bus_space_read_1(pcmh.memt, pcmh.memh,
    996 		    offset + (j * 2));
    997 	enaddr = myea;
    998 
    999 	pcmcia_mem_unmap(psc->sc_pf, mwindow);
   1000  fail_2:
   1001 	pcmcia_mem_free(psc->sc_pf, &pcmh);
   1002  fail_1:
   1003 	return (enaddr);
   1004 }
   1005 
   1006 u_int8_t *
   1007 ne_pcmcia_dl10019_get_enaddr(psc, myea)
   1008 	struct ne_pcmcia_softc *psc;
   1009 	u_int8_t myea[ETHER_ADDR_LEN];
   1010 {
   1011 	struct ne2000_softc *nsc = &psc->sc_ne2000;
   1012 	u_int8_t sum;
   1013 	int j;
   1014 
   1015 #define PAR0	0x04
   1016 	for (j = 0, sum = 0; j < 8; j++)
   1017 		sum += bus_space_read_1(nsc->sc_asict, nsc->sc_asich,
   1018 		    PAR0 + j);
   1019 	if (sum != 0xff)
   1020 		return (NULL);
   1021 	for (j = 0; j < ETHER_ADDR_LEN; j++)
   1022 		myea[j] = bus_space_read_1(nsc->sc_asict,
   1023 		    nsc->sc_asich, PAR0 + j);
   1024 #undef PAR0
   1025 	return (myea);
   1026 }
   1027 
   1028 int
   1029 ne_pcmcia_ax88190_set_iobase(psc)
   1030 	struct ne_pcmcia_softc *psc;
   1031 {
   1032 	struct ne2000_softc *nsc = &psc->sc_ne2000;
   1033 	struct dp8390_softc *dsc = &nsc->sc_dp8390;
   1034 	struct pcmcia_mem_handle pcmh;
   1035 	bus_size_t offset;
   1036 	int rv = 1, mwindow;
   1037 	u_int last_liobase, new_liobase;
   1038 
   1039 	if (pcmcia_mem_alloc(psc->sc_pf, AX88190_LAN_IOSIZE, &pcmh)) {
   1040 #if 0
   1041 		printf("%s: can't alloc mem for LAN iobase\n",
   1042 		    dsc->sc_dev.dv_xname);
   1043 #endif
   1044 		goto fail_1;
   1045 	}
   1046 	if (pcmcia_mem_map(psc->sc_pf, PCMCIA_MEM_ATTR,
   1047 	    AX88190_LAN_IOBASE, AX88190_LAN_IOSIZE,
   1048 	    &pcmh, &offset, &mwindow)) {
   1049 		printf("%s: can't map mem for LAN iobase\n",
   1050 		    dsc->sc_dev.dv_xname);
   1051 		goto fail_2;
   1052 	}
   1053 
   1054 	last_liobase = bus_space_read_1(pcmh.memt, pcmh.memh, offset + 0) |
   1055 	    (bus_space_read_1(pcmh.memt, pcmh.memh, offset + 2) << 8);
   1056 #ifdef DIAGNOSTIC
   1057 	printf("%s: LAN iobase 0x%x (0x%x) ->", dsc->sc_dev.dv_xname,
   1058 	    last_liobase, (u_int)psc->sc_pcioh.addr);
   1059 #endif
   1060 	bus_space_write_1(pcmh.memt, pcmh.memh, offset,
   1061 	    psc->sc_pcioh.addr & 0xff);
   1062 	bus_space_write_1(pcmh.memt, pcmh.memh, offset + 2,
   1063 	    psc->sc_pcioh.addr >> 8);
   1064 
   1065 	new_liobase = bus_space_read_1(pcmh.memt, pcmh.memh, offset + 0) |
   1066 	    (bus_space_read_1(pcmh.memt, pcmh.memh, offset + 2) << 8);
   1067 #ifdef DIAGNOSTIC
   1068 	printf(" 0x%x\n", new_liobase);
   1069 #endif
   1070 	if ((last_liobase == psc->sc_pcioh.addr)
   1071 	    || (last_liobase != new_liobase))
   1072 		rv = 0;
   1073 
   1074 	pcmcia_mem_unmap(psc->sc_pf, mwindow);
   1075  fail_2:
   1076 	pcmcia_mem_free(psc->sc_pf, &pcmh);
   1077  fail_1:
   1078 	return (rv);
   1079 }
   1080