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