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