Home | History | Annotate | Line # | Download | only in pcmcia
if_ne_pcmcia.c revision 1.55
      1 /*	$NetBSD: if_ne_pcmcia.c,v 1.55 2000/02/09 15:40:26 enami 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/param.h>
     33 #include <sys/systm.h>
     34 #include <sys/select.h>
     35 #include <sys/device.h>
     36 #include <sys/socket.h>
     37 
     38 #include <net/if_types.h>
     39 #include <net/if.h>
     40 #include <net/if_media.h>
     41 #include <net/if_ether.h>
     42 
     43 #include <machine/bus.h>
     44 #include <machine/intr.h>
     45 
     46 #include <dev/pcmcia/pcmciareg.h>
     47 #include <dev/pcmcia/pcmciavar.h>
     48 #include <dev/pcmcia/pcmciadevs.h>
     49 
     50 #include <dev/ic/dp8390reg.h>
     51 #include <dev/ic/dp8390var.h>
     52 
     53 #include <dev/ic/ne2000reg.h>
     54 #include <dev/ic/ne2000var.h>
     55 
     56 #include <dev/ic/rtl80x9reg.h>
     57 #include <dev/ic/rtl80x9var.h>
     58 
     59 int	ne_pcmcia_match __P((struct device *, struct cfdata *, void *));
     60 void	ne_pcmcia_attach __P((struct device *, struct device *, void *));
     61 int	ne_pcmcia_detach __P((struct device *, int));
     62 
     63 int	ne_pcmcia_enable __P((struct dp8390_softc *));
     64 void	ne_pcmcia_disable __P((struct dp8390_softc *));
     65 
     66 struct ne_pcmcia_softc {
     67 	struct ne2000_softc sc_ne2000;		/* real "ne2000" softc */
     68 
     69 	/* PCMCIA-specific goo */
     70 	struct pcmcia_io_handle sc_pcioh;	/* PCMCIA i/o information */
     71 	int sc_asic_io_window;			/* i/o window for ASIC */
     72 	int sc_nic_io_window;			/* i/o window for NIC */
     73 	struct pcmcia_function *sc_pf;		/* our PCMCIA function */
     74 	void *sc_ih;				/* interrupt handle */
     75 };
     76 
     77 u_int8_t *
     78 	ne_pcmcia_get_enaddr __P((struct ne_pcmcia_softc *, int,
     79 	    u_int8_t [ETHER_ADDR_LEN]));
     80 u_int8_t *
     81 	ne_pcmcia_dl10019_get_enaddr __P((struct ne_pcmcia_softc *,
     82 	    u_int8_t [ETHER_ADDR_LEN]));
     83 int	ne_pcmcia_ax88190_set_iobase __P((struct ne_pcmcia_softc *));
     84 
     85 struct cfattach ne_pcmcia_ca = {
     86 	sizeof(struct ne_pcmcia_softc), ne_pcmcia_match, ne_pcmcia_attach,
     87 	    ne_pcmcia_detach, dp8390_activate
     88 };
     89 
     90 struct ne2000dev {
     91     char *name;
     92     int32_t manufacturer;
     93     int32_t product;
     94     char *cis_info[4];
     95     int function;
     96     int enet_maddr;
     97     unsigned char enet_vendor[3];
     98     int flags;
     99 #define	NE2000DVF_DL10019	0x0001		/* chip is D-Link DL10019 */
    100 #define	NE2000DVF_AX88190	0x0002		/* chip is ASIX AX88190 */
    101 } ne2000devs[] = {
    102     { PCMCIA_STR_AMBICOM_AMB8002T,
    103       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    104       PCMCIA_CIS_AMBICOM_AMB8002T,
    105       0, -1, { 0x00, 0x10, 0x7a } },
    106 
    107     { PCMCIA_STR_PREMAX_PE200,
    108       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    109       PCMCIA_CIS_PREMAX_PE200,
    110       0, 0x07f0, { 0x00, 0x20, 0xe0 } },
    111 
    112     { PCMCIA_STR_DIGITAL_DEPCMXX,
    113       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    114       PCMCIA_CIS_DIGITAL_DEPCMXX,
    115       0, 0x0ff0, { 0x00, 0x00, 0xe8 } },
    116 
    117     { PCMCIA_STR_PLANET_SMARTCOM2000,
    118       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    119       PCMCIA_CIS_PLANET_SMARTCOM2000,
    120       0, 0xff0, { 0x00, 0x00, 0xe8 } },
    121 
    122     { PCMCIA_STR_DLINK_DE660,
    123       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    124       PCMCIA_CIS_DLINK_DE660,
    125       0, -1, { 0x00, 0x80, 0xc8 } },
    126 
    127     { PCMCIA_STR_RPTI_EP401,
    128       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    129       PCMCIA_CIS_RPTI_EP401,
    130       0, -1, { 0x00, 0x40, 0x95 } },
    131 
    132     { PCMCIA_STR_ACCTON_EN2212,
    133       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    134       PCMCIA_CIS_ACCTON_EN2212,
    135       0, 0x0ff0, { 0x00, 0x00, 0xe8 } },
    136 
    137     { PCMCIA_STR_SVEC_COMBOCARD,
    138       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    139       PCMCIA_CIS_SVEC_COMBOCARD,
    140       0, -1, { 0x00, 0xe0, 0x98 } },
    141 
    142     { PCMCIA_STR_SVEC_LANCARD,
    143       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    144       PCMCIA_CIS_SVEC_LANCARD,
    145       0, 0x7f0, { 0x00, 0xc0, 0x6c } },
    146 
    147     { PCMCIA_STR_EPSON_EEN10B,
    148       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_EPSON_EEN10B,
    149       PCMCIA_CIS_EPSON_EEN10B,
    150       0, 0xff0, { 0x00, 0x00, 0x48 } },
    151 
    152     /*
    153      * You have to add new entries which contains
    154      * PCMCIA_VENDOR_INVALID and/or PCMCIA_PRODUCT_INVALID
    155      * in front of this comment.
    156      *
    157      * There are cards which use a generic vendor and product id but needs
    158      * a different handling depending on the cis_info, so ne2000_match
    159      * needs a table where the exceptions comes first and then the normal
    160      * product and vendor entries.
    161      */
    162 
    163     { PCMCIA_STR_IBM_INFOMOVER,
    164       PCMCIA_VENDOR_IBM, PCMCIA_PRODUCT_IBM_INFOMOVER,
    165       PCMCIA_CIS_IBM_INFOMOVER,
    166       0, 0x0ff0, { 0x08, 0x00, 0x5a } },
    167 
    168     { PCMCIA_STR_LINKSYS_ECARD_1,
    169       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ECARD_1,
    170       PCMCIA_CIS_LINKSYS_ECARD_1,
    171       0, -1, { 0x00, 0x80, 0xc8 } },
    172 
    173     { PCMCIA_STR_PLANEX_FNW3600T,
    174       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_COMBO_ECARD,
    175       PCMCIA_CIS_PLANEX_FNW3600T,
    176       0, -1, { 0x00, 0x90, 0xcc }, NE2000DVF_DL10019 },
    177 
    178     { PCMCIA_STR_PLANEX_FNW3700T,
    179       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_COMBO_ECARD,
    180       PCMCIA_CIS_PLANEX_FNW3700T,
    181       0, -1, { 0x00, 0x90, 0xcc }, NE2000DVF_AX88190 },
    182 
    183     { PCMCIA_STR_SVEC_PN650TX,
    184       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_COMBO_ECARD,
    185       PCMCIA_CIS_SVEC_PN650TX,
    186       0, -1, { 0x00, 0xe0, 0x98 }, NE2000DVF_DL10019 },
    187 
    188     { PCMCIA_STR_LINKSYS_ETHERFAST,
    189       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ETHERFAST,
    190       PCMCIA_CIS_LINKSYS_ETHERFAST,
    191       0, -1, { 0x00, 0x80, 0xc8 }, NE2000DVF_DL10019 },
    192 
    193     { PCMCIA_STR_LINKSYS_COMBO_ECARD,
    194       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_COMBO_ECARD,
    195       PCMCIA_CIS_LINKSYS_COMBO_ECARD,
    196       0, -1, { 0x00, 0x80, 0xc8 } },
    197 
    198     { PCMCIA_STR_LINKSYS_TRUST_COMBO_ECARD,
    199       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_TRUST_COMBO_ECARD,
    200       PCMCIA_CIS_LINKSYS_TRUST_COMBO_ECARD,
    201       0, 0x0120, { 0x20, 0x04, 0x49 } },
    202 
    203     /* Although the comments above say to put VENDOR/PRODUCT INVALID IDs
    204        above this list, we need to keep this one below the ECARD_1, or else
    205        both will match the same more-generic entry rather than the more
    206        specific one above with proper vendor and product IDs. */
    207     { PCMCIA_STR_LINKSYS_ECARD_2,
    208       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    209       PCMCIA_CIS_LINKSYS_ECARD_2,
    210       0, -1, { 0x00, 0x80, 0xc8 } },
    211 
    212     /*
    213      * D-Link DE-650 has many minor versions:
    214      *
    215      *   CIS information          Manufacturer Product  Note
    216      * 1 "D-Link, DE-650"             INVALID  INVALID  white card
    217      * 2 "D-Link, DE-650, Ver 01.00"  INVALID  INVALID  became bare metal
    218      * 3 "D-Link, DE-650, Ver 01.00"   0x149    0x265   minor change in look
    219      * 4 "D-Link, DE-650, Ver 01.00"   0x149    0x265   collision LED added
    220      *
    221      * While the 1st and the 2nd types should use the "D-Link DE-650" entry,
    222      * the 3rd and the 4th types should use the "Linksys EtherCard" entry.
    223      * Therefore, this enty must be below the LINKSYS_ECARD_1.  --itohy
    224      */
    225     { PCMCIA_STR_DLINK_DE650,
    226       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    227       PCMCIA_CIS_DLINK_DE650,
    228       0, 0x0040, { 0x00, 0x80, 0xc8 } },
    229 
    230     /*
    231      * IO-DATA PCLA/TE and later version of PCLA/T has valid
    232      * vendor/product ID and it is possible to read MAC address
    233      * using standard I/O ports.  It also read from CIS offset 0x01c0.
    234      * On the other hand, earlier version of PCLA/T doesn't have valid
    235      * vendor/product ID and MAC address must be read from CIS offset
    236      * 0x0ff0 (i.e., usual ne2000 way to read it doesn't work).
    237      * And CIS information of earlier and later version of PCLA/T are
    238      * same except fourth element.  So, for now, we place the entry for
    239      * PCLA/TE (and later version of PCLA/T) followed by entry
    240      * for the earlier version of PCLA/T (or, modify to match all CIS
    241      * information and have three or more individual entries).
    242      */
    243     { PCMCIA_STR_IODATA_PCLATE,
    244       PCMCIA_VENDOR_IODATA, PCMCIA_PRODUCT_IODATA_PCLATE,
    245       PCMCIA_CIS_IODATA_PCLATE,
    246       0, -1, { 0x00, 0xa0, 0xb0 } },
    247 
    248     /*
    249      * This entry should be placed after above PCLA-TE entry.
    250      * See above comments for detail.
    251      */
    252     { PCMCIA_STR_IODATA_PCLAT,
    253       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    254       PCMCIA_CIS_IODATA_PCLAT,
    255       0, 0x0ff0, { 0x00, 0xa0, 0xb0 } },
    256 
    257     { PCMCIA_STR_DAYNA_COMMUNICARD_E_1,
    258       PCMCIA_VENDOR_DAYNA, PCMCIA_PRODUCT_DAYNA_COMMUNICARD_E_1,
    259       PCMCIA_CIS_DAYNA_COMMUNICARD_E_1,
    260       0, 0x0110, { 0x00, 0x80, 0x19 } },
    261 
    262     { PCMCIA_STR_DAYNA_COMMUNICARD_E_2,
    263       PCMCIA_VENDOR_DAYNA, PCMCIA_PRODUCT_DAYNA_COMMUNICARD_E_2,
    264       PCMCIA_CIS_DAYNA_COMMUNICARD_E_2,
    265       0, -1, { 0x00, 0x80, 0x19 } },
    266 
    267     { PCMCIA_STR_COREGA_ETHER_PCC_T,
    268       PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_ETHER_PCC_T,
    269       PCMCIA_CIS_COREGA_ETHER_PCC_T,
    270       0, -1, { 0x00, 0x00, 0xf4 } },
    271 
    272     { PCMCIA_STR_COREGA_ETHER_II_PCC_T,
    273       PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_ETHER_II_PCC_T,
    274       PCMCIA_CIS_COREGA_ETHER_II_PCC_T,
    275       0, -1, { 0x00, 0x00, 0xf4 } },
    276 
    277     { PCMCIA_STR_COREGA_FAST_ETHER_PCC_TX,
    278       PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_FAST_ETHER_PCC_TX,
    279       PCMCIA_CIS_COREGA_FAST_ETHER_PCC_TX,
    280       0, -1, { 0x00, 0x00, 0xf4 }, NE2000DVF_DL10019 },
    281 
    282     { PCMCIA_STR_COMPEX_LINKPORT_ENET_B,
    283       PCMCIA_VENDOR_COMPEX, PCMCIA_PRODUCT_COMPEX_LINKPORT_ENET_B,
    284       PCMCIA_CIS_COMPEX_LINKPORT_ENET_B,
    285       0, 0x01c0, { 0x00, 0xa0, 0x0c } },
    286 
    287     { PCMCIA_STR_SMC_EZCARD,
    288       PCMCIA_VENDOR_SMC, PCMCIA_PRODUCT_SMC_EZCARD,
    289       PCMCIA_CIS_SMC_EZCARD,
    290       0, 0x01c0, { 0x00, 0xe0, 0x29 } },
    291 
    292     { PCMCIA_STR_SOCEKT_LP_ETHER_CF,
    293       PCMCIA_VENDOR_SOCKET, PCMCIA_PRODUCT_SOCEKT_LP_ETHER_CF,
    294       PCMCIA_CIS_SOCEKT_LP_ETHER_CF,
    295       0, -1, { 0x00, 0xc0, 0x1b} },
    296 
    297     { PCMCIA_STR_XIRCOM_CFE_10,
    298       PCMCIA_VENDOR_XIRCOM, PCMCIA_PRODUCT_XIRCOM_CFE_10,
    299       PCMCIA_CIS_XIRCOM_CFE_10,
    300       0, -1, { 0x00, 0x10, 0xa4 } },
    301 
    302     { PCMCIA_STR_MELCO_LPC3_TX,
    303       PCMCIA_VENDOR_MELCO, PCMCIA_PRODUCT_MELCO_LPC3_TX,
    304       PCMCIA_CIS_MELCO_LPC3_TX,
    305       0, -1, { 0x00, 0x40, 0x26 }, NE2000DVF_AX88190 },
    306 
    307 #if 0
    308     /* the rest of these are stolen from the linux pcnet pcmcia device
    309        driver.  Since I don't know the manfid or cis info strings for
    310        any of them, they're not compiled in until I do. */
    311     { "APEX MultiCard",
    312       0x0000, 0x0000, NULL, NULL, 0,
    313       0x03f4, { 0x00, 0x20, 0xe5 } },
    314     { "ASANTE FriendlyNet",
    315       0x0000, 0x0000, NULL, NULL, 0,
    316       0x4910, { 0x00, 0x00, 0x94 } },
    317     { "Danpex EN-6200P2",
    318       0x0000, 0x0000, NULL, NULL, 0,
    319       0x0110, { 0x00, 0x40, 0xc7 } },
    320     { "DataTrek NetCard",
    321       0x0000, 0x0000, NULL, NULL, 0,
    322       0x0ff0, { 0x00, 0x20, 0xe8 } },
    323     { "Dayna CommuniCard E",
    324       0x0000, 0x0000, NULL, NULL, 0,
    325       0x0110, { 0x00, 0x80, 0x19 } },
    326     { "EP-210 Ethernet",
    327       0x0000, 0x0000, NULL, NULL, 0,
    328       0x0110, { 0x00, 0x40, 0x33 } },
    329     { "ELECOM Laneed LD-CDWA",
    330       0x0000, 0x0000, NULL, NULL, 0,
    331       0x00b8, { 0x08, 0x00, 0x42 } },
    332     { "Grey Cell GCS2220",
    333       0x0000, 0x0000, NULL, NULL, 0,
    334       0x0000, { 0x00, 0x47, 0x43 } },
    335     { "Hypertec Ethernet",
    336       0x0000, 0x0000, NULL, NULL, 0,
    337       0x01c0, { 0x00, 0x40, 0x4c } },
    338     { "IBM CCAE",
    339       0x0000, 0x0000, NULL, NULL, 0,
    340       0x0ff0, { 0x08, 0x00, 0x5a } },
    341     { "IBM CCAE",
    342       0x0000, 0x0000, NULL, NULL, 0,
    343       0x0ff0, { 0x00, 0x04, 0xac } },
    344     { "IBM CCAE",
    345       0x0000, 0x0000, NULL, NULL, 0,
    346       0x0ff0, { 0x00, 0x06, 0x29 } },
    347     { "IBM FME",
    348       0x0000, 0x0000, NULL, NULL, 0,
    349       0x0374, { 0x00, 0x04, 0xac } },
    350     { "IBM FME",
    351       0x0000, 0x0000, NULL, NULL, 0,
    352       0x0374, { 0x08, 0x00, 0x5a } },
    353     { "Katron PE-520",
    354       0x0000, 0x0000, NULL, NULL, 0,
    355       0x0110, { 0x00, 0x40, 0xf6 } },
    356     { "Kingston KNE-PCM/x",
    357       0x0000, 0x0000, NULL, NULL, 0,
    358       0x0ff0, { 0x00, 0xc0, 0xf0 } },
    359     { "Kingston KNE-PCM/x",
    360       0x0000, 0x0000, NULL, NULL, 0,
    361       0x0ff0, { 0xe2, 0x0c, 0x0f } },
    362     { "Kingston KNE-PC2",
    363       0x0000, 0x0000, NULL, NULL, 0,
    364       0x0180, { 0x00, 0xc0, 0xf0 } },
    365     { "Longshine LCS-8534",
    366       0x0000, 0x0000, NULL, NULL, 0,
    367       0x0000, { 0x08, 0x00, 0x00 } },
    368     { "Maxtech PCN2000",
    369       0x0000, 0x0000, NULL, NULL, 0,
    370       0x5000, { 0x00, 0x00, 0xe8 } },
    371     { "NDC Instant-Link",
    372       0x0000, 0x0000, NULL, NULL, 0,
    373       0x003a, { 0x00, 0x80, 0xc6 } },
    374     { "NE2000 Compatible",
    375       0x0000, 0x0000, NULL, NULL, 0,
    376       0x0ff0, { 0x00, 0xa0, 0x0c } },
    377     { "Network General Sniffer",
    378       0x0000, 0x0000, NULL, NULL, 0,
    379       0x0ff0, { 0x00, 0x00, 0x65 } },
    380     { "Panasonic VEL211",
    381       0x0000, 0x0000, NULL, NULL, 0,
    382       0x0ff0, { 0x00, 0x80, 0x45 } },
    383     { "SCM Ethernet",
    384       0x0000, 0x0000, NULL, NULL, 0,
    385       0x0ff0, { 0x00, 0x20, 0xcb } },
    386     { "Socket EA",
    387       0x0000, 0x0000, NULL, NULL, 0,
    388       0x4000, { 0x00, 0xc0, 0x1b } },
    389     { "Volktek NPL-402CT",
    390       0x0000, 0x0000, NULL, NULL, 0,
    391       0x0060, { 0x00, 0x40, 0x05 } },
    392 #endif
    393 
    394     { PCMCIA_STR_ALLIEDTELESIS_LA_PCM,
    395       PCMCIA_VENDOR_ALLIEDTELESIS, PCMCIA_PRODUCT_ALLIEDTELESIS_LA_PCM,
    396       PCMCIA_CIS_ALLIEDTELESIS_LA_PCM,
    397       0, 0x0ff0, { 0x00, 0x00, 0xf4 } },
    398 };
    399 
    400 #define	NE2000_NDEVS	(sizeof(ne2000devs) / sizeof(ne2000devs[0]))
    401 
    402 #define ne2000_match(card, fct, n) \
    403 ((((((card)->manufacturer != PCMCIA_VENDOR_INVALID) && \
    404     ((card)->manufacturer == ne2000devs[(n)].manufacturer) && \
    405     ((card)->product != PCMCIA_PRODUCT_INVALID) && \
    406     ((card)->product == ne2000devs[(n)].product)) || \
    407    ((ne2000devs[(n)].cis_info[0]) && (ne2000devs[(n)].cis_info[1]) && \
    408     (strcmp((card)->cis1_info[0], ne2000devs[(n)].cis_info[0]) == 0) && \
    409     (strcmp((card)->cis1_info[1], ne2000devs[(n)].cis_info[1]) == 0))) && \
    410   ((fct) == ne2000devs[(n)].function))? \
    411  &ne2000devs[(n)]:NULL)
    412 
    413 int
    414 ne_pcmcia_match(parent, match, aux)
    415 	struct device *parent;
    416 	struct cfdata *match;
    417 	void *aux;
    418 {
    419 	struct pcmcia_attach_args *pa = aux;
    420 	int i;
    421 
    422 	for (i = 0; i < NE2000_NDEVS; i++) {
    423 		if (ne2000_match(pa->card, pa->pf->number, i))
    424 			return (1);
    425 	}
    426 
    427 	return (0);
    428 }
    429 
    430 void
    431 ne_pcmcia_attach(parent, self, aux)
    432 	struct device *parent, *self;
    433 	void *aux;
    434 {
    435 	struct ne_pcmcia_softc *psc = (void *) self;
    436 	struct ne2000_softc *nsc = &psc->sc_ne2000;
    437 	struct dp8390_softc *dsc = &nsc->sc_dp8390;
    438 	struct pcmcia_attach_args *pa = aux;
    439 	struct pcmcia_config_entry *cfe;
    440 	struct ne2000dev *ne_dev;
    441 	int i;
    442 	u_int8_t myea[6], *enaddr;
    443 	void (*npp_init_media) __P((struct dp8390_softc *, int **,
    444 	    int *, int *));
    445 	int *media, nmedia, defmedia;
    446 	const char *typestr = "";
    447 
    448 	npp_init_media = NULL;
    449 	media = NULL;
    450 	nmedia = defmedia = 0;
    451 
    452 	psc->sc_pf = pa->pf;
    453 	cfe = pa->pf->cfe_head.sqh_first;
    454 
    455 	/*
    456 	 * XXX need to loop over all config entries?
    457 	 */
    458 #if 0
    459 	/*
    460 	 * Some ne2000 driver's claim to have memory; others don't.
    461 	 * Since I don't care, I don't check.
    462 	 */
    463 
    464 	if (cfe->num_memspace != 1) {
    465 		printf(": unexpected number of memory spaces "
    466 		    " %d should be 1\n", cfe->num_memspace);
    467 		goto fail_1;
    468 	}
    469 #endif
    470 
    471 	if (cfe->num_iospace == 1) {
    472 		if (cfe->iospace[0].length != NE2000_NPORTS) {
    473 			printf(": unexpected I/O space configuration"
    474 			    " (continued)\n%s", dsc->sc_dev.dv_xname);
    475 			/* XXX really safe for all other cards? */
    476 		}
    477 	} else if (cfe->num_iospace == 2) {
    478 		/*
    479 		 * Some cards report a separate space for NIC and ASIC.
    480 		 * This make some sense, but we must allocate a single
    481 		 * NE2000_NPORTS-sized chunk, due to brain damaged
    482 		 * address decoders on some of these cards.
    483 		 */
    484 		if ((cfe->iospace[0].length + cfe->iospace[1].length) !=
    485 		    NE2000_NPORTS) {
    486 			printf(": unexpected I/O space configuration\n");
    487 			goto fail_1;
    488 		}
    489 	} else {
    490 		printf(": unexpected number of i/o spaces %d"
    491 		    " should be 1 or 2\n", cfe->num_iospace);
    492 		goto fail_1;
    493 	}
    494 
    495 	if (pcmcia_io_alloc(pa->pf, cfe->iospace[0].start, NE2000_NPORTS,
    496 	    NE2000_NPORTS, &psc->sc_pcioh)) {
    497 		printf(": can't alloc i/o space\n");
    498 		goto fail_1;
    499 	}
    500 
    501 	dsc->sc_regt = psc->sc_pcioh.iot;
    502 	dsc->sc_regh = psc->sc_pcioh.ioh;
    503 
    504 	nsc->sc_asict = psc->sc_pcioh.iot;
    505 	if (bus_space_subregion(dsc->sc_regt, dsc->sc_regh,
    506 	    NE2000_ASIC_OFFSET, NE2000_ASIC_NPORTS,
    507 	    &nsc->sc_asich)) {
    508 		printf(": can't get subregion for asic\n");
    509 		goto fail_2;
    510 	}
    511 
    512 	/* Set up power management hooks. */
    513 	dsc->sc_enable = ne_pcmcia_enable;
    514 	dsc->sc_disable = ne_pcmcia_disable;
    515 
    516 	/* Enable the card. */
    517 	pcmcia_function_init(pa->pf, cfe);
    518 	if (pcmcia_function_enable(pa->pf)) {
    519 		printf(": function enable failed\n");
    520 		goto fail_2;
    521 	}
    522 
    523 	/* some cards claim to be io16, but they're lying. */
    524 	if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_IO8,
    525 	    NE2000_NIC_OFFSET, NE2000_NIC_NPORTS,
    526 	    &psc->sc_pcioh, &psc->sc_nic_io_window)) {
    527 		printf(": can't map NIC i/o space\n");
    528 		goto fail_3;
    529 	}
    530 
    531 	if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_IO16,
    532 	    NE2000_ASIC_OFFSET, NE2000_ASIC_NPORTS,
    533 	    &psc->sc_pcioh, &psc->sc_asic_io_window)) {
    534 		printf(": can't map ASIC i/o space\n");
    535 		goto fail_4;
    536 	}
    537 
    538 	printf("\n");
    539 
    540 	/*
    541 	 * Read the station address from the board.
    542 	 */
    543 	i = 0;
    544 again:
    545 	enaddr = NULL;			/* Ask ASIC by default */
    546 	for (; i < NE2000_NDEVS; i++) {
    547 		ne_dev = ne2000_match(pa->card, pa->pf->number, i);
    548 		if (ne_dev != NULL) {
    549 			if (ne_dev->enet_maddr >= 0) {
    550 				enaddr = ne_pcmcia_get_enaddr(psc,
    551 				    ne_dev->enet_maddr, myea);
    552 				if (enaddr == NULL)
    553 					continue;
    554 			}
    555 			break;
    556 		}
    557 	}
    558 	if (i == NE2000_NDEVS) {
    559 		printf("%s: can't match ethernet vendor code\n",
    560 		    dsc->sc_dev.dv_xname);
    561 		goto fail_5;
    562 	}
    563 
    564 	if ((ne_dev->flags & NE2000DVF_DL10019) != 0) {
    565 		enaddr = ne_pcmcia_dl10019_get_enaddr(psc, myea);
    566 		if (enaddr == NULL) {
    567 			++i;
    568 			goto again;
    569 		}
    570 		nsc->sc_type = NE2000_TYPE_DL10019;
    571 		typestr = " (DL10019)";
    572 	}
    573 
    574 	if ((ne_dev->flags & NE2000DVF_AX88190) != 0) {
    575 		if (ne_pcmcia_ax88190_set_iobase(psc))
    576 			goto fail_5;
    577 		nsc->sc_type = NE2000_TYPE_AX88190;
    578 		typestr = " (AX88190)";
    579 	}
    580 
    581 	if (enaddr != NULL) {
    582 		/*
    583 		 * Make sure this is what we expect.
    584 		 */
    585 		if (enaddr[0] != ne_dev->enet_vendor[0] ||
    586 		    enaddr[1] != ne_dev->enet_vendor[1] ||
    587 		    enaddr[2] != ne_dev->enet_vendor[2]) {
    588 			++i;
    589 			goto again;
    590 		}
    591 	}
    592 
    593 	/*
    594 	 * Check for a RealTek 8019.
    595 	 */
    596 	bus_space_write_1(dsc->sc_regt, dsc->sc_regh, ED_P0_CR,
    597 	    ED_CR_PAGE_0 | ED_CR_STP);
    598 	if (bus_space_read_1(dsc->sc_regt, dsc->sc_regh, NERTL_RTL0_8019ID0)
    599 		== RTL0_8019ID0 &&
    600 	    bus_space_read_1(dsc->sc_regt, dsc->sc_regh, NERTL_RTL0_8019ID1)
    601 		== RTL0_8019ID1) {
    602 		typestr = " (RTL8019)";
    603 		npp_init_media = rtl80x9_init_media;
    604 		dsc->sc_mediachange = rtl80x9_mediachange;
    605 		dsc->sc_mediastatus = rtl80x9_mediastatus;
    606 		dsc->init_card = rtl80x9_init_card;
    607 	}
    608 
    609 	printf("%s: %s%s Ethernet\n", dsc->sc_dev.dv_xname, ne_dev->name,
    610 	    typestr);
    611 
    612 	/* Initialize media, if we have it. */
    613 	if (npp_init_media != NULL)
    614 		(*npp_init_media)(dsc, &media, &nmedia, &defmedia);
    615 
    616 	if (ne2000_attach(nsc, enaddr, media, nmedia, defmedia))
    617 		goto fail_5;
    618 
    619 	pcmcia_function_disable(pa->pf);
    620 	return;
    621 
    622  fail_5:
    623 	/* Unmap ASIC i/o windows. */
    624 	pcmcia_io_unmap(psc->sc_pf, psc->sc_asic_io_window);
    625 
    626  fail_4:
    627 	/* Unmap NIC i/o windows. */
    628 	pcmcia_io_unmap(psc->sc_pf, psc->sc_nic_io_window);
    629 
    630  fail_3:
    631 	pcmcia_function_disable(pa->pf);
    632 
    633  fail_2:
    634 	/* Free our i/o space. */
    635 	pcmcia_io_free(psc->sc_pf, &psc->sc_pcioh);
    636 
    637  fail_1:
    638 	psc->sc_nic_io_window = -1;
    639 }
    640 
    641 int
    642 ne_pcmcia_detach(self, flags)
    643 	struct device *self;
    644 	int flags;
    645 {
    646 	struct ne_pcmcia_softc *psc = (struct ne_pcmcia_softc *)self;
    647 	int error;
    648 
    649 	if (psc->sc_nic_io_window == -1)
    650 		/* Nothing to detach. */
    651 		return (0);
    652 
    653 	error = ne2000_detach(&psc->sc_ne2000, flags);
    654 	if (error != 0)
    655 		return (error);
    656 
    657 	/* Unmap our i/o windows. */
    658 	pcmcia_io_unmap(psc->sc_pf, psc->sc_asic_io_window);
    659 	pcmcia_io_unmap(psc->sc_pf, psc->sc_nic_io_window);
    660 
    661 	/* Free our i/o space. */
    662 	pcmcia_io_free(psc->sc_pf, &psc->sc_pcioh);
    663 
    664 	return (0);
    665 }
    666 
    667 int
    668 ne_pcmcia_enable(dsc)
    669 	struct dp8390_softc *dsc;
    670 {
    671 	struct ne_pcmcia_softc *psc = (struct ne_pcmcia_softc *)dsc;
    672 	struct ne2000_softc *nsc = &psc->sc_ne2000;
    673 
    674 	/* set up the interrupt */
    675 	psc->sc_ih = pcmcia_intr_establish(psc->sc_pf, IPL_NET, dp8390_intr,
    676 	    dsc);
    677 	if (psc->sc_ih == NULL) {
    678 		printf("%s: couldn't establish interrupt\n",
    679 		    dsc->sc_dev.dv_xname);
    680 		goto fail_1;
    681 	}
    682 
    683 	if (pcmcia_function_enable(psc->sc_pf))
    684 		goto fail_2;
    685 
    686 	if (nsc->sc_type == NE2000_TYPE_AX88190)
    687 		if (ne_pcmcia_ax88190_set_iobase(psc))
    688 			goto fail_3;
    689 
    690 	return (0);
    691 
    692  fail_3:
    693 	pcmcia_function_disable(psc->sc_pf);
    694  fail_2:
    695 	pcmcia_intr_disestablish(psc->sc_pf, psc->sc_ih);
    696  fail_1:
    697 	return (1);
    698 }
    699 
    700 void
    701 ne_pcmcia_disable(dsc)
    702 	struct dp8390_softc *dsc;
    703 {
    704 	struct ne_pcmcia_softc *psc = (struct ne_pcmcia_softc *)dsc;
    705 
    706 	pcmcia_function_disable(psc->sc_pf);
    707 	pcmcia_intr_disestablish(psc->sc_pf, psc->sc_ih);
    708 }
    709 
    710 u_int8_t *
    711 ne_pcmcia_get_enaddr(psc, maddr, myea)
    712 	struct ne_pcmcia_softc *psc;
    713 	int maddr;
    714 	u_int8_t myea[ETHER_ADDR_LEN];
    715 {
    716 	struct ne2000_softc *nsc = &psc->sc_ne2000;
    717 	struct dp8390_softc *dsc = &nsc->sc_dp8390;
    718 	struct pcmcia_mem_handle pcmh;
    719 	bus_addr_t offset;
    720 	u_int8_t *enaddr = NULL;
    721 	int j, mwindow;
    722 
    723 	if (maddr < 0)
    724 		return (NULL);
    725 
    726 	if (pcmcia_mem_alloc(psc->sc_pf, ETHER_ADDR_LEN * 2, &pcmh)) {
    727 		printf("%s: can't alloc mem for enet addr\n",
    728 		    dsc->sc_dev.dv_xname);
    729 		goto fail_1;
    730 	}
    731 	if (pcmcia_mem_map(psc->sc_pf, PCMCIA_MEM_ATTR, maddr,
    732 	    ETHER_ADDR_LEN * 2, &pcmh, &offset, &mwindow)) {
    733 		printf("%s: can't map mem for enet addr\n",
    734 		    dsc->sc_dev.dv_xname);
    735 		goto fail_2;
    736 	}
    737 	for (j = 0; j < ETHER_ADDR_LEN; j++)
    738 		myea[j] = bus_space_read_1(pcmh.memt, pcmh.memh,
    739 		    offset + (j * 2));
    740 	enaddr = myea;
    741 
    742 	pcmcia_mem_unmap(psc->sc_pf, mwindow);
    743  fail_2:
    744 	pcmcia_mem_free(psc->sc_pf, &pcmh);
    745  fail_1:
    746 	return (enaddr);
    747 }
    748 
    749 u_int8_t *
    750 ne_pcmcia_dl10019_get_enaddr(psc, myea)
    751 	struct ne_pcmcia_softc *psc;
    752 	u_int8_t myea[ETHER_ADDR_LEN];
    753 {
    754 	struct ne2000_softc *nsc = &psc->sc_ne2000;
    755 	u_int8_t sum;
    756 	int j;
    757 
    758 #define PAR0	0x04
    759 	for (j = 0, sum = 0; j < 8; j++)
    760 		sum += bus_space_read_1(nsc->sc_asict, nsc->sc_asich,
    761 		    PAR0 + j);
    762 	if (sum != 0xff)
    763 		return (NULL);
    764 	for (j = 0; j < ETHER_ADDR_LEN; j++)
    765 		myea[j] = bus_space_read_1(nsc->sc_asict,
    766 		    nsc->sc_asich, PAR0 + j);
    767 #undef PAR0
    768 	return (myea);
    769 }
    770 
    771 int
    772 ne_pcmcia_ax88190_set_iobase(psc)
    773 	struct ne_pcmcia_softc *psc;
    774 {
    775 	struct ne2000_softc *nsc = &psc->sc_ne2000;
    776 	struct dp8390_softc *dsc = &nsc->sc_dp8390;
    777 	struct pcmcia_mem_handle pcmh;
    778 	bus_addr_t offset;
    779 	int rv = 1, mwindow;
    780 
    781 	if (pcmcia_mem_alloc(psc->sc_pf, NE2000_AX88190_LAN_IOSIZE, &pcmh)) {
    782 		printf("%s: can't alloc mem for LAN iobase\n",
    783 		    dsc->sc_dev.dv_xname);
    784 		goto fail_1;
    785 	}
    786 	if (pcmcia_mem_map(psc->sc_pf, PCMCIA_MEM_ATTR,
    787 	    NE2000_AX88190_LAN_IOBASE, NE2000_AX88190_LAN_IOSIZE,
    788 	    &pcmh, &offset, &mwindow)) {
    789 		printf("%s: can't map mem for LAN iobase\n",
    790 		    dsc->sc_dev.dv_xname);
    791 		goto fail_2;
    792 	}
    793 
    794 #ifdef DIAGNOSTIC
    795 	printf("%s: LAN iobase 0x%x (0x%x) ->", dsc->sc_dev.dv_xname,
    796 	    bus_space_read_1(pcmh.memt, pcmh.memh, offset + 0) |
    797 	    bus_space_read_1(pcmh.memt, pcmh.memh, offset + 2) << 8,
    798 	    (u_int)psc->sc_pcioh.addr);
    799 #endif
    800 	bus_space_write_1(pcmh.memt, pcmh.memh, offset,
    801 	    psc->sc_pcioh.addr & 0xff);
    802 	bus_space_write_1(pcmh.memt, pcmh.memh, offset + 2,
    803 	    psc->sc_pcioh.addr >> 8);
    804 #ifdef DIAGNOSTIC
    805 	printf(" 0x%x\n", bus_space_read_1(pcmh.memt, pcmh.memh, offset + 0) |
    806 	    bus_space_read_1(pcmh.memt, pcmh.memh, offset + 2) << 8);
    807 #endif
    808 	rv = 0;
    809 
    810 	pcmcia_mem_unmap(psc->sc_pf, mwindow);
    811  fail_2:
    812 	pcmcia_mem_free(psc->sc_pf, &pcmh);
    813  fail_1:
    814 	return (rv);
    815 }
    816