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