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