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