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