Home | History | Annotate | Line # | Download | only in pcmcia
if_ne_pcmcia.c revision 1.1.2.2
      1  1.1.2.2  thorpej /*	$NetBSD: if_ne_pcmcia.c,v 1.1.2.2 1997/10/14 01:59:17 thorpej Exp $	*/
      2  1.1.2.1  thorpej 
      3  1.1.2.1  thorpej /*-
      4  1.1.2.1  thorpej  * Copyright (c) 1997 The NetBSD Foundation, Inc.
      5  1.1.2.1  thorpej  * All rights reserved.
      6  1.1.2.1  thorpej  *
      7  1.1.2.1  thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1.2.1  thorpej  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9  1.1.2.1  thorpej  * NASA Ames Research Center.
     10  1.1.2.1  thorpej  *
     11  1.1.2.1  thorpej  * Redistribution and use in source and binary forms, with or without
     12  1.1.2.1  thorpej  * modification, are permitted provided that the following conditions
     13  1.1.2.1  thorpej  * are met:
     14  1.1.2.1  thorpej  * 1. Redistributions of source code must retain the above copyright
     15  1.1.2.1  thorpej  *    notice, this list of conditions and the following disclaimer.
     16  1.1.2.1  thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.1.2.1  thorpej  *    notice, this list of conditions and the following disclaimer in the
     18  1.1.2.1  thorpej  *    documentation and/or other materials provided with the distribution.
     19  1.1.2.1  thorpej  * 3. All advertising materials mentioning features or use of this software
     20  1.1.2.1  thorpej  *    must display the following acknowledgement:
     21  1.1.2.1  thorpej  *	This product includes software developed by the NetBSD
     22  1.1.2.1  thorpej  *	Foundation, Inc. and its contributors.
     23  1.1.2.1  thorpej  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  1.1.2.1  thorpej  *    contributors may be used to endorse or promote products derived
     25  1.1.2.1  thorpej  *    from this software without specific prior written permission.
     26  1.1.2.1  thorpej  *
     27  1.1.2.1  thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  1.1.2.1  thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  1.1.2.1  thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  1.1.2.1  thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  1.1.2.1  thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  1.1.2.1  thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  1.1.2.1  thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  1.1.2.1  thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  1.1.2.1  thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  1.1.2.1  thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  1.1.2.1  thorpej  * POSSIBILITY OF SUCH DAMAGE.
     38  1.1.2.1  thorpej  */
     39  1.1.2.1  thorpej 
     40  1.1.2.1  thorpej #include <sys/param.h>
     41  1.1.2.1  thorpej #include <sys/systm.h>
     42  1.1.2.1  thorpej #include <sys/select.h>
     43  1.1.2.1  thorpej #include <sys/device.h>
     44  1.1.2.1  thorpej #include <sys/socket.h>
     45  1.1.2.1  thorpej 
     46  1.1.2.1  thorpej #include <net/if_types.h>
     47  1.1.2.1  thorpej #include <net/if.h>
     48  1.1.2.1  thorpej #include <net/if_ether.h>
     49  1.1.2.1  thorpej 
     50  1.1.2.1  thorpej #include <machine/bus.h>
     51  1.1.2.1  thorpej #include <machine/intr.h>
     52  1.1.2.1  thorpej 
     53  1.1.2.1  thorpej #include <dev/pcmcia/pcmciareg.h>
     54  1.1.2.1  thorpej #include <dev/pcmcia/pcmciavar.h>
     55  1.1.2.1  thorpej 
     56  1.1.2.1  thorpej #include <dev/ic/dp8390reg.h>
     57  1.1.2.1  thorpej #include <dev/ic/dp8390var.h>
     58  1.1.2.1  thorpej 
     59  1.1.2.1  thorpej #include <dev/ic/ne2000reg.h>
     60  1.1.2.1  thorpej #include <dev/ic/ne2000var.h>
     61  1.1.2.1  thorpej 
     62  1.1.2.1  thorpej #ifdef __BROKEN_INDIRECT_CONFIG
     63  1.1.2.1  thorpej int ne_pcmcia_match __P((struct device *, void *, void *));
     64  1.1.2.1  thorpej #else
     65  1.1.2.1  thorpej int ne_pcmcia_match __P((struct device *, struct cfdata *, void *));
     66  1.1.2.1  thorpej #endif
     67  1.1.2.1  thorpej void ne_pcmcia_attach __P((struct device *, struct device *, void *));
     68  1.1.2.1  thorpej 
     69  1.1.2.2  thorpej int	ne_pcmcia_enable __P((struct dp8390_softc *));
     70  1.1.2.2  thorpej void	ne_pcmcia_disable __P((struct dp8390_softc *));
     71  1.1.2.2  thorpej 
     72  1.1.2.1  thorpej struct ne_pcmcia_softc {
     73  1.1.2.1  thorpej 	struct ne2000_softc sc_ne2000;		/* real "ne2000" softc */
     74  1.1.2.1  thorpej 
     75  1.1.2.1  thorpej 	/* PCMCIA-specific goo */
     76  1.1.2.1  thorpej 	struct pcmcia_io_handle sc_pcioh;	/* PCMCIA i/o information */
     77  1.1.2.1  thorpej 	int sc_asic_io_window;			/* i/o window for ASIC */
     78  1.1.2.1  thorpej 	int sc_nic_io_window;			/* i/o window for NIC */
     79  1.1.2.1  thorpej 	struct pcmcia_function *sc_pf;		/* our PCMCIA function */
     80  1.1.2.1  thorpej 	void *sc_ih;				/* interrupt handle */
     81  1.1.2.1  thorpej };
     82  1.1.2.1  thorpej 
     83  1.1.2.1  thorpej struct cfattach ne_pcmcia_ca = {
     84  1.1.2.1  thorpej 	sizeof(struct ne_pcmcia_softc), ne_pcmcia_match, ne_pcmcia_attach
     85  1.1.2.1  thorpej };
     86  1.1.2.1  thorpej 
     87  1.1.2.1  thorpej struct ne2000dev {
     88  1.1.2.1  thorpej     char *name;
     89  1.1.2.1  thorpej     int manufacturer;
     90  1.1.2.1  thorpej     int product;
     91  1.1.2.1  thorpej     char *cis1_info0;
     92  1.1.2.1  thorpej     char *cis1_info1;
     93  1.1.2.1  thorpej     int function;
     94  1.1.2.1  thorpej     int enet_maddr;
     95  1.1.2.1  thorpej     unsigned char enet_vendor[3];
     96  1.1.2.1  thorpej } ne2000devs[] = {
     97  1.1.2.1  thorpej     { "PreMax PE-200",
     98  1.1.2.1  thorpej       0xffff, 0xffff, "PMX   ", "PE-200", 0,
     99  1.1.2.1  thorpej       0x07f0, { 0x00, 0x20, 0xe0 } },
    100  1.1.2.1  thorpej     { "National Semiconductor InfoMover",
    101  1.1.2.1  thorpej       0x00a4, 0x0002, NULL, NULL, 0,
    102  1.1.2.1  thorpej       0x0ff0, { 0x08, 0x00, 0x5a } },
    103  1.1.2.1  thorpej     { "DEC DEPCM-BA",
    104  1.1.2.1  thorpej       0x0000, 0x0000, "DIGITAL", "DEPCM-XX", 0,
    105  1.1.2.1  thorpej       0x0ff0, { 0x00, 0x00, 0xe8 } },
    106  1.1.2.1  thorpej     /* this card might need pcic_alloc_iobase < 0x400, and/or
    107  1.1.2.1  thorpej        CIRRUS_PD672X on TI TravelMate 5000 needs it: */
    108  1.1.2.1  thorpej     { "Linksys EthernetCard",
    109  1.1.2.1  thorpej       0x0149, 0x0265, "LINKSYS", "E-CARD",
    110  1.1.2.1  thorpej       0, -1, { 0x00, 0x80, 0xc8 } },
    111  1.1.2.1  thorpej     { "Planet SmartCOM 2000",
    112  1.1.2.1  thorpej       0xffffffff, 0xffff,  "PCMCIA", "UE2212", 0,
    113  1.1.2.1  thorpej       0xff0, { 0x00, 0x00, 0xe8 } },
    114  1.1.2.1  thorpej #if 0
    115  1.1.2.1  thorpej     /* the rest of these are stolen from the linux pcnet pcmcia device
    116  1.1.2.1  thorpej        driver.  Since I don't know the manfid or cis info strings for
    117  1.1.2.1  thorpej        any of them, they're not compiled in until I do. */
    118  1.1.2.1  thorpej 
    119  1.1.2.1  thorpej     { "Accton EN2212",
    120  1.1.2.1  thorpej       0x0000, 0x0000, NULL, NULL, 0,
    121  1.1.2.1  thorpej       0x0ff0, { 0x00, 0x00, 0xe8 } },
    122  1.1.2.1  thorpej     { "Allied Telesis LA-PCM",
    123  1.1.2.1  thorpej       0x0000, 0x0000, NULL, NULL, 0,
    124  1.1.2.1  thorpej       0x0ff0, { 0x00, 0x00, 0xf4 } },
    125  1.1.2.1  thorpej     { "APEX MultiCard",
    126  1.1.2.1  thorpej       0x0000, 0x0000, NULL, NULL, 0,
    127  1.1.2.1  thorpej       0x03f4, { 0x00, 0x20, 0xe5 } },
    128  1.1.2.1  thorpej     { "ASANTE FriendlyNet",
    129  1.1.2.1  thorpej       0x0000, 0x0000, NULL, NULL, 0,
    130  1.1.2.1  thorpej       0x4910, { 0x00, 0x00, 0x94 } },
    131  1.1.2.1  thorpej     { "Danpex EN-6200P2",
    132  1.1.2.1  thorpej       0x0000, 0x0000, NULL, NULL, 0,
    133  1.1.2.1  thorpej       0x0110, { 0x00, 0x40, 0xc7 } },
    134  1.1.2.1  thorpej     { "DataTrek NetCard",
    135  1.1.2.1  thorpej       0x0000, 0x0000, NULL, NULL, 0,
    136  1.1.2.1  thorpej       0x0ff0, { 0x00, 0x20, 0xe8 } },
    137  1.1.2.1  thorpej     { "Dayna CommuniCard E",
    138  1.1.2.1  thorpej       0x0000, 0x0000, NULL, NULL, 0,
    139  1.1.2.1  thorpej       0x0110, { 0x00, 0x80, 0x19 } },
    140  1.1.2.1  thorpej     { "D-Link DE-650",
    141  1.1.2.1  thorpej       0x0000, 0x0000, NULL, NULL, 0,
    142  1.1.2.1  thorpej       0x0040, { 0x00, 0x80, 0xc8 } },
    143  1.1.2.1  thorpej     { "EP-210 Ethernet",
    144  1.1.2.1  thorpej       0x0000, 0x0000, NULL, NULL, 0,
    145  1.1.2.1  thorpej       0x0110, { 0x00, 0x40, 0x33 } },
    146  1.1.2.1  thorpej     { "Epson EEN10B",
    147  1.1.2.1  thorpej       0x0000, 0x0000, NULL, NULL, 0,
    148  1.1.2.1  thorpej       0x0ff0, { 0x00, 0x00, 0x48 } },
    149  1.1.2.1  thorpej     { "ELECOM Laneed LD-CDWA",
    150  1.1.2.1  thorpej       0x0000, 0x0000, NULL, NULL, 0,
    151  1.1.2.1  thorpej       0x00b8, { 0x08, 0x00, 0x42 } },
    152  1.1.2.1  thorpej     { "Grey Cell GCS2220",
    153  1.1.2.1  thorpej       0x0000, 0x0000, NULL, NULL, 0,
    154  1.1.2.1  thorpej       0x0000, { 0x00, 0x47, 0x43 } },
    155  1.1.2.1  thorpej     { "Hypertec Ethernet",
    156  1.1.2.1  thorpej       0x0000, 0x0000, NULL, NULL, 0,
    157  1.1.2.1  thorpej       0x01c0, { 0x00, 0x40, 0x4c } },
    158  1.1.2.1  thorpej     { "IBM CCAE",
    159  1.1.2.1  thorpej       0x0000, 0x0000, NULL, NULL, 0,
    160  1.1.2.1  thorpej       0x0ff0, { 0x08, 0x00, 0x5a } },
    161  1.1.2.1  thorpej     { "IBM CCAE",
    162  1.1.2.1  thorpej       0x0000, 0x0000, NULL, NULL, 0,
    163  1.1.2.1  thorpej       0x0ff0, { 0x00, 0x04, 0xac } },
    164  1.1.2.1  thorpej     { "IBM CCAE",
    165  1.1.2.1  thorpej       0x0000, 0x0000, NULL, NULL, 0,
    166  1.1.2.1  thorpej       0x0ff0, { 0x00, 0x06, 0x29 } },
    167  1.1.2.1  thorpej     { "IBM FME",
    168  1.1.2.1  thorpej       0x0000, 0x0000, NULL, NULL, 0,
    169  1.1.2.1  thorpej       0x0374, { 0x00, 0x04, 0xac } },
    170  1.1.2.1  thorpej     { "IBM FME",
    171  1.1.2.1  thorpej       0x0000, 0x0000, NULL, NULL, 0,
    172  1.1.2.1  thorpej       0x0374, { 0x08, 0x00, 0x5a } },
    173  1.1.2.1  thorpej     { "I-O DATA PCLA/T",
    174  1.1.2.1  thorpej       0x0000, 0x0000, NULL, NULL, 0,
    175  1.1.2.1  thorpej       0x0ff0, { 0x00, 0xa0, 0xb0 } },
    176  1.1.2.1  thorpej     { "Katron PE-520",
    177  1.1.2.1  thorpej       0x0000, 0x0000, NULL, NULL, 0,
    178  1.1.2.1  thorpej       0x0110, { 0x00, 0x40, 0xf6 } },
    179  1.1.2.1  thorpej     { "Kingston KNE-PCM/x",
    180  1.1.2.1  thorpej       0x0000, 0x0000, NULL, NULL, 0,
    181  1.1.2.1  thorpej       0x0ff0, { 0x00, 0xc0, 0xf0 } },
    182  1.1.2.1  thorpej     { "Kingston KNE-PCM/x",
    183  1.1.2.1  thorpej       0x0000, 0x0000, NULL, NULL, 0,
    184  1.1.2.1  thorpej       0x0ff0, { 0xe2, 0x0c, 0x0f } },
    185  1.1.2.1  thorpej     { "Kingston KNE-PC2",
    186  1.1.2.1  thorpej       0x0000, 0x0000, NULL, NULL, 0,
    187  1.1.2.1  thorpej       0x0180, { 0x00, 0xc0, 0xf0 } },
    188  1.1.2.1  thorpej     { "Longshine LCS-8534",
    189  1.1.2.1  thorpej       0x0000, 0x0000, NULL, NULL, 0,
    190  1.1.2.1  thorpej       0x0000, { 0x08, 0x00, 0x00 } },
    191  1.1.2.1  thorpej     { "Maxtech PCN2000",
    192  1.1.2.1  thorpej       0x0000, 0x0000, NULL, NULL, 0,
    193  1.1.2.1  thorpej       0x5000, { 0x00, 0x00, 0xe8 } },
    194  1.1.2.1  thorpej     { "NDC Instant-Link",
    195  1.1.2.1  thorpej       0x0000, 0x0000, NULL, NULL, 0,
    196  1.1.2.1  thorpej       0x003a, { 0x00, 0x80, 0xc6 } },
    197  1.1.2.1  thorpej     { "NE2000 Compatible",
    198  1.1.2.1  thorpej       0x0000, 0x0000, NULL, NULL, 0,
    199  1.1.2.1  thorpej       0x0ff0, { 0x00, 0xa0, 0x0c } },
    200  1.1.2.1  thorpej     { "Network General Sniffer",
    201  1.1.2.1  thorpej       0x0000, 0x0000, NULL, NULL, 0,
    202  1.1.2.1  thorpej       0x0ff0, { 0x00, 0x00, 0x65 } },
    203  1.1.2.1  thorpej     { "Panasonic VEL211",
    204  1.1.2.1  thorpej       0x0000, 0x0000, NULL, NULL, 0,
    205  1.1.2.1  thorpej       0x0ff0, { 0x00, 0x80, 0x45 } },
    206  1.1.2.1  thorpej     { "RPTI EP400",
    207  1.1.2.1  thorpej       0x0000, 0x0000, NULL, NULL, 0,
    208  1.1.2.1  thorpej       0x0110, { 0x00, 0x40, 0x95 } },
    209  1.1.2.1  thorpej     { "SCM Ethernet",
    210  1.1.2.1  thorpej       0x0000, 0x0000, NULL, NULL, 0,
    211  1.1.2.1  thorpej       0x0ff0, { 0x00, 0x20, 0xcb } },
    212  1.1.2.1  thorpej     { "Socket EA",
    213  1.1.2.1  thorpej       0x0000, 0x0000, NULL, NULL, 0,
    214  1.1.2.1  thorpej       0x4000, { 0x00, 0xc0, 0x1b } },
    215  1.1.2.1  thorpej     { "Volktek NPL-402CT",
    216  1.1.2.1  thorpej       0x0000, 0x0000, NULL, NULL, 0,
    217  1.1.2.1  thorpej       0x0060, { 0x00, 0x40, 0x05 } },
    218  1.1.2.1  thorpej #endif
    219  1.1.2.1  thorpej };
    220  1.1.2.1  thorpej 
    221  1.1.2.1  thorpej #define	NE2000_NDEVS	(sizeof(ne2000devs) / sizeof(ne2000devs[0]))
    222  1.1.2.1  thorpej 
    223  1.1.2.1  thorpej #define ne2000_match(card, fct, n) \
    224  1.1.2.1  thorpej ((((((card)->manufacturer == ne2000devs[(n)].manufacturer) && \
    225  1.1.2.1  thorpej     ((card)->product == ne2000devs[(n)].product)) || \
    226  1.1.2.1  thorpej    ((ne2000devs[(n)].cis1_info0) && (ne2000devs[(n)].cis1_info1) && \
    227  1.1.2.1  thorpej     (strcmp((card)->cis1_info[0], ne2000devs[(n)].cis1_info0) == 0) && \
    228  1.1.2.1  thorpej     (strcmp((card)->cis1_info[1], ne2000devs[(n)].cis1_info1) == 0))) && \
    229  1.1.2.1  thorpej   (pa->pf->number == ne2000devs[(n)].function))? \
    230  1.1.2.1  thorpej  &ne2000devs[(n)]:NULL)
    231  1.1.2.1  thorpej 
    232  1.1.2.1  thorpej int
    233  1.1.2.1  thorpej ne_pcmcia_match(parent, match, aux)
    234  1.1.2.1  thorpej 	struct device *parent;
    235  1.1.2.1  thorpej #ifdef __BROKEN_INDIRECT_CONFIG
    236  1.1.2.1  thorpej 	void *match;
    237  1.1.2.1  thorpej #else
    238  1.1.2.1  thorpej 	struct cfdata *cf;
    239  1.1.2.1  thorpej #endif
    240  1.1.2.1  thorpej 	void *aux;
    241  1.1.2.1  thorpej {
    242  1.1.2.1  thorpej 	struct pcmcia_attach_args *pa = (struct pcmcia_attach_args *) aux;
    243  1.1.2.1  thorpej 	int i;
    244  1.1.2.1  thorpej 
    245  1.1.2.1  thorpej 	for (i = 0; i < NE2000_NDEVS; i++) {
    246  1.1.2.1  thorpej 		if (ne2000_match(pa->card, pa->pf->number, i))
    247  1.1.2.1  thorpej 			return (1);
    248  1.1.2.1  thorpej 	}
    249  1.1.2.1  thorpej 
    250  1.1.2.1  thorpej 	return (0);
    251  1.1.2.1  thorpej }
    252  1.1.2.1  thorpej 
    253  1.1.2.1  thorpej void
    254  1.1.2.1  thorpej ne_pcmcia_attach(parent, self, aux)
    255  1.1.2.1  thorpej 	struct device *parent, *self;
    256  1.1.2.1  thorpej 	void *aux;
    257  1.1.2.1  thorpej {
    258  1.1.2.1  thorpej 	struct ne_pcmcia_softc *psc = (void *) self;
    259  1.1.2.1  thorpej 	struct ne2000_softc *nsc = &psc->sc_ne2000;
    260  1.1.2.1  thorpej 	struct dp8390_softc *dsc = &nsc->sc_dp8390;
    261  1.1.2.1  thorpej 	struct pcmcia_attach_args *pa = aux;
    262  1.1.2.1  thorpej 	struct pcmcia_config_entry *cfe;
    263  1.1.2.1  thorpej 	struct ne2000dev *ne_dev;
    264  1.1.2.1  thorpej 	struct pcmcia_mem_handle pcmh;
    265  1.1.2.1  thorpej 	bus_addr_t offset;
    266  1.1.2.1  thorpej 	int i, j, mwindow;
    267  1.1.2.1  thorpej 	u_int8_t myea[6], *enaddr = NULL;
    268  1.1.2.1  thorpej 
    269  1.1.2.1  thorpej 	psc->sc_pf = pa->pf;
    270  1.1.2.1  thorpej 	cfe = pa->pf->cfe_head.sqh_first;
    271  1.1.2.1  thorpej 
    272  1.1.2.1  thorpej #if 0
    273  1.1.2.1  thorpej 	/*
    274  1.1.2.1  thorpej 	 * Some ne2000 driver's claim to have memory; others don't.
    275  1.1.2.1  thorpej 	 * Since I don't care, I don't check.
    276  1.1.2.1  thorpej 	 */
    277  1.1.2.1  thorpej 
    278  1.1.2.1  thorpej 	if (cfe->num_memspace != 1) {
    279  1.1.2.1  thorpej 		printf(": unexpected number of memory spaces "
    280  1.1.2.1  thorpej 		    " %d should be 1\n", cfe->num_memspace);
    281  1.1.2.1  thorpej 		return;
    282  1.1.2.1  thorpej 	}
    283  1.1.2.1  thorpej #endif
    284  1.1.2.1  thorpej 
    285  1.1.2.1  thorpej 	if (cfe->num_iospace == 1) {
    286  1.1.2.1  thorpej 		if (cfe->iospace[0].length != NE2000_NPORTS) {
    287  1.1.2.1  thorpej 			printf(": unexpected I/O space configuration\n");
    288  1.1.2.1  thorpej 			return;
    289  1.1.2.1  thorpej 		}
    290  1.1.2.1  thorpej 	} else if (cfe->num_iospace == 2) {
    291  1.1.2.1  thorpej 		/*
    292  1.1.2.1  thorpej 		 * Some cards report a separate space for NIC and ASIC.
    293  1.1.2.1  thorpej 		 * This make some sense, but we must allocate a single
    294  1.1.2.1  thorpej 		 * NE2000_NPORTS-sized chunk, due to brain damaged
    295  1.1.2.1  thorpej 		 * address decoders on some of these cards.
    296  1.1.2.1  thorpej 		 */
    297  1.1.2.1  thorpej 		if ((cfe->iospace[0].length + cfe->iospace[1].length) !=
    298  1.1.2.1  thorpej 		    NE2000_NPORTS) {
    299  1.1.2.1  thorpej 			printf(": unexpected I/O space configuration\n");
    300  1.1.2.1  thorpej 			return;
    301  1.1.2.1  thorpej 		}
    302  1.1.2.1  thorpej 	} else {
    303  1.1.2.1  thorpej 		printf(": unexpected number of i/o spaces %d"
    304  1.1.2.1  thorpej 		    " should be 1 or 2\n", cfe->num_iospace);
    305  1.1.2.1  thorpej 	}
    306  1.1.2.1  thorpej 
    307  1.1.2.1  thorpej 	if (pcmcia_io_alloc(pa->pf, 0, NE2000_NPORTS, NE2000_NPORTS,
    308  1.1.2.1  thorpej 	    &psc->sc_pcioh)) {
    309  1.1.2.1  thorpej 		printf(": can't alloc i/o space\n");
    310  1.1.2.1  thorpej 		return;
    311  1.1.2.1  thorpej 	}
    312  1.1.2.1  thorpej 
    313  1.1.2.1  thorpej 	dsc->sc_regt = psc->sc_pcioh.iot;
    314  1.1.2.1  thorpej 	dsc->sc_regh = psc->sc_pcioh.ioh;
    315  1.1.2.1  thorpej 
    316  1.1.2.1  thorpej 	nsc->sc_asict = psc->sc_pcioh.iot;
    317  1.1.2.1  thorpej 	if (bus_space_subregion(dsc->sc_regt, dsc->sc_regh,
    318  1.1.2.1  thorpej 	    NE2000_ASIC_OFFSET, NE2000_ASIC_NPORTS,
    319  1.1.2.1  thorpej 	    &nsc->sc_asich)) {
    320  1.1.2.1  thorpej 		printf(": can't get subregion for asic\n");
    321  1.1.2.1  thorpej 		return;
    322  1.1.2.1  thorpej 	}
    323  1.1.2.1  thorpej 
    324  1.1.2.2  thorpej 	/* Set up power management hooks. */
    325  1.1.2.2  thorpej 	dsc->sc_enable = ne_pcmcia_enable;
    326  1.1.2.2  thorpej 	dsc->sc_disable = ne_pcmcia_disable;
    327  1.1.2.2  thorpej 
    328  1.1.2.1  thorpej 	/* Enable the card. */
    329  1.1.2.1  thorpej 	pcmcia_function_init(pa->pf, cfe);
    330  1.1.2.1  thorpej 	if (pcmcia_function_enable(pa->pf)) {
    331  1.1.2.1  thorpej 		printf(": function enable failed\n");
    332  1.1.2.1  thorpej 		return;
    333  1.1.2.1  thorpej 	}
    334  1.1.2.1  thorpej 
    335  1.1.2.1  thorpej 	/* some cards claim to be io16, but they're lying. */
    336  1.1.2.1  thorpej 	if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_IO8,
    337  1.1.2.1  thorpej 	    NE2000_NIC_OFFSET, NE2000_NIC_NPORTS,
    338  1.1.2.1  thorpej 	    &psc->sc_pcioh, &psc->sc_nic_io_window)) {
    339  1.1.2.1  thorpej 		printf(": can't map NIC i/o space\n");
    340  1.1.2.1  thorpej 		return;
    341  1.1.2.1  thorpej 	}
    342  1.1.2.1  thorpej 
    343  1.1.2.1  thorpej 	if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_IO16,
    344  1.1.2.1  thorpej 	    NE2000_ASIC_OFFSET, NE2000_ASIC_NPORTS,
    345  1.1.2.1  thorpej 	    &psc->sc_pcioh, &psc->sc_asic_io_window)) {
    346  1.1.2.1  thorpej 		printf(": can't map ASIC i/o space\n");
    347  1.1.2.1  thorpej 		return;
    348  1.1.2.1  thorpej 	}
    349  1.1.2.1  thorpej 
    350  1.1.2.1  thorpej 	printf("\n");
    351  1.1.2.1  thorpej 
    352  1.1.2.1  thorpej 	/*
    353  1.1.2.1  thorpej 	 * Read the station address from the board.
    354  1.1.2.1  thorpej 	 */
    355  1.1.2.1  thorpej 	for (i = 0; i < NE2000_NDEVS; i++) {
    356  1.1.2.1  thorpej 		if ((ne_dev = ne2000_match(pa->card, pa->pf->number, i))
    357  1.1.2.1  thorpej 		    != NULL) {
    358  1.1.2.1  thorpej 			if (ne_dev->enet_maddr >= 0) {
    359  1.1.2.1  thorpej 				if (pcmcia_mem_alloc(pa->pf,
    360  1.1.2.1  thorpej 				    ETHER_ADDR_LEN * 2, &pcmh)) {
    361  1.1.2.1  thorpej 					printf("%s: can't alloc mem for"
    362  1.1.2.1  thorpej 					    " enet addr\n",
    363  1.1.2.1  thorpej 					    dsc->sc_dev.dv_xname);
    364  1.1.2.1  thorpej 					return;
    365  1.1.2.1  thorpej 				}
    366  1.1.2.1  thorpej 				if (pcmcia_mem_map(pa->pf, PCMCIA_MEM_ATTR,
    367  1.1.2.1  thorpej 				    ne_dev->enet_maddr, ETHER_ADDR_LEN * 2,
    368  1.1.2.1  thorpej 				    &pcmh, &offset, &mwindow)) {
    369  1.1.2.1  thorpej 					printf("%s: can't map mem for"
    370  1.1.2.1  thorpej 					    " enet addr\n",
    371  1.1.2.1  thorpej 					    dsc->sc_dev.dv_xname);
    372  1.1.2.1  thorpej 					return;
    373  1.1.2.1  thorpej 				}
    374  1.1.2.1  thorpej 				for (j = 0; j < ETHER_ADDR_LEN; j++)
    375  1.1.2.1  thorpej 					myea[j] = bus_space_read_1(pcmh.memt,
    376  1.1.2.1  thorpej 					    pcmh.memh, offset + (j * 2));
    377  1.1.2.1  thorpej 				pcmcia_mem_unmap(pa->pf, mwindow);
    378  1.1.2.1  thorpej 				pcmcia_mem_free(pa->pf, &pcmh);
    379  1.1.2.1  thorpej 				enaddr = myea;
    380  1.1.2.1  thorpej 			}
    381  1.1.2.1  thorpej 			break;
    382  1.1.2.1  thorpej 		}
    383  1.1.2.1  thorpej 	}
    384  1.1.2.1  thorpej 
    385  1.1.2.1  thorpej 	if (enaddr != NULL) {
    386  1.1.2.1  thorpej 		/*
    387  1.1.2.1  thorpej 		 * Make sure this is what we expect.
    388  1.1.2.1  thorpej 		 */
    389  1.1.2.1  thorpej 		if (enaddr[0] != ne_dev->enet_vendor[0] ||
    390  1.1.2.1  thorpej 		    enaddr[1] != ne_dev->enet_vendor[1] ||
    391  1.1.2.1  thorpej 		    enaddr[2] != ne_dev->enet_vendor[2]) {
    392  1.1.2.1  thorpej 			printf("\n%s: enet addr has incorrect vendor code\n",
    393  1.1.2.1  thorpej 			    dsc->sc_dev.dv_xname);
    394  1.1.2.1  thorpej 			printf("%s: (%02x:%02x:%02x should be "
    395  1.1.2.1  thorpej 			    "%02x:%02x:%02x)\n", dsc->sc_dev.dv_xname,
    396  1.1.2.1  thorpej 			    enaddr[0], enaddr[1], enaddr[2],
    397  1.1.2.1  thorpej 			    ne_dev->enet_vendor[0],
    398  1.1.2.1  thorpej 			    ne_dev->enet_vendor[1],
    399  1.1.2.1  thorpej 			    ne_dev->enet_vendor[2]);
    400  1.1.2.1  thorpej 			return;
    401  1.1.2.1  thorpej 		}
    402  1.1.2.1  thorpej 	}
    403  1.1.2.1  thorpej 
    404  1.1.2.1  thorpej 	printf("%s: %s Ethernet\n", dsc->sc_dev.dv_xname, ne_dev->name);
    405  1.1.2.1  thorpej 
    406  1.1.2.1  thorpej 	ne2000_attach(nsc, enaddr);
    407  1.1.2.1  thorpej 
    408  1.1.2.1  thorpej 	/* set up the interrupt */
    409  1.1.2.1  thorpej 	psc->sc_ih = pcmcia_intr_establish(pa->pf, IPL_NET, dp8390_intr, dsc);
    410  1.1.2.1  thorpej 	if (psc->sc_ih == NULL)
    411  1.1.2.1  thorpej 		printf("%s: couldn't establish interrupt\n",
    412  1.1.2.1  thorpej 		    dsc->sc_dev.dv_xname);
    413  1.1.2.2  thorpej 
    414  1.1.2.2  thorpej 	pcmcia_function_disable(pa->pf);
    415  1.1.2.2  thorpej }
    416  1.1.2.2  thorpej 
    417  1.1.2.2  thorpej int
    418  1.1.2.2  thorpej ne_pcmcia_enable(dsc)
    419  1.1.2.2  thorpej 	struct dp8390_softc *dsc;
    420  1.1.2.2  thorpej {
    421  1.1.2.2  thorpej 	struct ne_pcmcia_softc *psc = (struct ne_pcmcia_softc *)dsc;
    422  1.1.2.2  thorpej 
    423  1.1.2.2  thorpej 	return (pcmcia_function_enable(psc->sc_pf));
    424  1.1.2.2  thorpej }
    425  1.1.2.2  thorpej 
    426  1.1.2.2  thorpej void
    427  1.1.2.2  thorpej ne_pcmcia_disable(dsc)
    428  1.1.2.2  thorpej 	struct dp8390_softc *dsc;
    429  1.1.2.2  thorpej {
    430  1.1.2.2  thorpej 	struct ne_pcmcia_softc *psc = (struct ne_pcmcia_softc *)dsc;
    431  1.1.2.2  thorpej 
    432  1.1.2.2  thorpej 	pcmcia_function_disable(psc->sc_pf);
    433  1.1.2.1  thorpej }
    434