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