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