Home | History | Annotate | Line # | Download | only in pcmcia
if_ep_pcmcia.c revision 1.41.6.5
      1  1.41.6.5     skrll /*	$NetBSD: if_ep_pcmcia.c,v 1.41.6.5 2005/02/04 11:47:08 skrll Exp $	*/
      2      1.14   thorpej 
      3      1.14   thorpej /*-
      4  1.41.6.2     skrll  * Copyright (c) 1998, 2000, 2004 The NetBSD Foundation, Inc.
      5      1.14   thorpej  * All rights reserved.
      6      1.14   thorpej  *
      7      1.14   thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8      1.14   thorpej  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9  1.41.6.2     skrll  * NASA Ames Research Center, and by Charles M. Hannum.
     10      1.14   thorpej  *
     11      1.14   thorpej  * Redistribution and use in source and binary forms, with or without
     12      1.14   thorpej  * modification, are permitted provided that the following conditions
     13      1.14   thorpej  * are met:
     14      1.14   thorpej  * 1. Redistributions of source code must retain the above copyright
     15      1.14   thorpej  *    notice, this list of conditions and the following disclaimer.
     16      1.14   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     17      1.14   thorpej  *    notice, this list of conditions and the following disclaimer in the
     18      1.14   thorpej  *    documentation and/or other materials provided with the distribution.
     19      1.14   thorpej  * 3. All advertising materials mentioning features or use of this software
     20      1.14   thorpej  *    must display the following acknowledgement:
     21      1.14   thorpej  *	This product includes software developed by the NetBSD
     22      1.14   thorpej  *	Foundation, Inc. and its contributors.
     23      1.14   thorpej  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24      1.14   thorpej  *    contributors may be used to endorse or promote products derived
     25      1.14   thorpej  *    from this software without specific prior written permission.
     26      1.14   thorpej  *
     27      1.14   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28      1.14   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29      1.14   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30      1.14   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31      1.14   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32      1.14   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33      1.14   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34      1.14   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35      1.14   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36      1.14   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37      1.14   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     38      1.14   thorpej  */
     39       1.2   thorpej 
     40       1.2   thorpej /*
     41       1.2   thorpej  * Copyright (c) 1997 Marc Horowitz.  All rights reserved.
     42       1.2   thorpej  *
     43       1.2   thorpej  * Redistribution and use in source and binary forms, with or without
     44       1.2   thorpej  * modification, are permitted provided that the following conditions
     45       1.2   thorpej  * are met:
     46       1.2   thorpej  * 1. Redistributions of source code must retain the above copyright
     47       1.2   thorpej  *    notice, this list of conditions and the following disclaimer.
     48       1.2   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     49       1.2   thorpej  *    notice, this list of conditions and the following disclaimer in the
     50       1.2   thorpej  *    documentation and/or other materials provided with the distribution.
     51       1.2   thorpej  * 3. All advertising materials mentioning features or use of this software
     52       1.2   thorpej  *    must display the following acknowledgement:
     53       1.2   thorpej  *	This product includes software developed by Marc Horowitz.
     54       1.2   thorpej  * 4. The name of the author may not be used to endorse or promote products
     55       1.2   thorpej  *    derived from this software without specific prior written permission.
     56       1.2   thorpej  *
     57       1.2   thorpej  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     58       1.2   thorpej  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     59       1.2   thorpej  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     60       1.2   thorpej  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     61       1.2   thorpej  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     62       1.2   thorpej  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     63       1.2   thorpej  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     64       1.2   thorpej  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     65       1.2   thorpej  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     66       1.2   thorpej  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     67       1.2   thorpej  */
     68      1.35     lukem 
     69      1.35     lukem #include <sys/cdefs.h>
     70  1.41.6.5     skrll __KERNEL_RCSID(0, "$NetBSD: if_ep_pcmcia.c,v 1.41.6.5 2005/02/04 11:47:08 skrll Exp $");
     71       1.2   thorpej 
     72       1.2   thorpej #include <sys/param.h>
     73       1.2   thorpej #include <sys/systm.h>
     74       1.2   thorpej #include <sys/mbuf.h>
     75       1.2   thorpej #include <sys/socket.h>
     76       1.2   thorpej #include <sys/ioctl.h>
     77       1.2   thorpej #include <sys/errno.h>
     78       1.2   thorpej #include <sys/syslog.h>
     79       1.2   thorpej #include <sys/select.h>
     80       1.2   thorpej #include <sys/device.h>
     81       1.2   thorpej 
     82       1.2   thorpej #include <net/if.h>
     83       1.2   thorpej #include <net/if_dl.h>
     84       1.2   thorpej #include <net/if_ether.h>
     85       1.2   thorpej #include <net/if_media.h>
     86       1.2   thorpej 
     87       1.2   thorpej #include <machine/cpu.h>
     88       1.2   thorpej #include <machine/bus.h>
     89       1.2   thorpej #include <machine/intr.h>
     90      1.13   thorpej 
     91      1.13   thorpej #include <dev/mii/miivar.h>
     92       1.2   thorpej 
     93       1.2   thorpej #include <dev/ic/elink3var.h>
     94       1.2   thorpej #include <dev/ic/elink3reg.h>
     95       1.2   thorpej 
     96       1.2   thorpej #include <dev/pcmcia/pcmciareg.h>
     97       1.2   thorpej #include <dev/pcmcia/pcmciavar.h>
     98      1.11  christos #include <dev/pcmcia/pcmciadevs.h>
     99       1.2   thorpej 
    100  1.41.6.5     skrll int	ep_pcmcia_match(struct device *, struct cfdata *, void *);
    101  1.41.6.5     skrll void	ep_pcmcia_attach(struct device *, struct device *, void *);
    102  1.41.6.5     skrll int	ep_pcmcia_detach(struct device *, int);
    103  1.41.6.5     skrll 
    104  1.41.6.5     skrll int	ep_pcmcia_get_enaddr(struct pcmcia_tuple *, void *);
    105  1.41.6.5     skrll int	ep_pcmcia_enable(struct ep_softc *);
    106  1.41.6.5     skrll void	ep_pcmcia_disable(struct ep_softc *);
    107       1.2   thorpej 
    108  1.41.6.5     skrll void	ep_pcmcia_disable1(struct ep_softc *);
    109       1.7   thorpej 
    110       1.2   thorpej struct ep_pcmcia_softc {
    111       1.2   thorpej 	struct ep_softc sc_ep;			/* real "ep" softc */
    112       1.2   thorpej 
    113       1.2   thorpej 	/* PCMCIA-specific goo */
    114       1.2   thorpej 	struct pcmcia_io_handle sc_pcioh;	/* PCMCIA i/o space info */
    115       1.2   thorpej 	int sc_io_window;			/* our i/o window */
    116       1.2   thorpej 	struct pcmcia_function *sc_pf;		/* our PCMCIA function */
    117       1.2   thorpej };
    118       1.2   thorpej 
    119      1.40   thorpej CFATTACH_DECL(ep_pcmcia, sizeof(struct ep_pcmcia_softc),
    120      1.41   thorpej     ep_pcmcia_match, ep_pcmcia_attach, ep_pcmcia_detach, ep_activate);
    121       1.2   thorpej 
    122      1.29       cgd const struct ep_pcmcia_product {
    123      1.29       cgd 	struct pcmcia_product epp_product;
    124      1.14   thorpej 	u_short		epp_chipset;	/* 3Com chipset used */
    125      1.14   thorpej 	int		epp_flags;	/* initial softc flags */
    126      1.14   thorpej } ep_pcmcia_products[] = {
    127  1.41.6.2     skrll 	{ { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3C562,
    128  1.41.6.2     skrll 	    PCMCIA_CIS_INVALID },
    129      1.29       cgd 	  ELINK_CHIPSET_3C509, 0 },
    130      1.29       cgd 
    131  1.41.6.2     skrll 	{ { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3C589,
    132  1.41.6.2     skrll 	    PCMCIA_CIS_INVALID },
    133      1.29       cgd 	  ELINK_CHIPSET_3C509, 0 },
    134      1.29       cgd 
    135  1.41.6.2     skrll 	{ { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556,
    136  1.41.6.2     skrll 	    PCMCIA_CIS_INVALID },
    137      1.29       cgd 	  ELINK_CHIPSET_3C509, 0 },
    138      1.29       cgd 
    139  1.41.6.2     skrll 	{ { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556INT,
    140  1.41.6.2     skrll 	    PCMCIA_CIS_INVALID },
    141      1.29       cgd 	  ELINK_CHIPSET_3C509, 0 },
    142      1.29       cgd 
    143  1.41.6.2     skrll 	{ { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3C574,
    144  1.41.6.2     skrll 	    PCMCIA_CIS_INVALID },
    145      1.29       cgd 	  ELINK_CHIPSET_ROADRUNNER, ELINK_FLAGS_MII },
    146      1.29       cgd 
    147  1.41.6.2     skrll 	{ { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CCFEM556BI,
    148  1.41.6.2     skrll 	    PCMCIA_CIS_INVALID },
    149      1.29       cgd 	  ELINK_CHIPSET_ROADRUNNER, ELINK_FLAGS_MII },
    150      1.31       cgd 
    151  1.41.6.2     skrll 	{ { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3C1,
    152  1.41.6.2     skrll 	    PCMCIA_CIS_INVALID },
    153      1.31       cgd 	  ELINK_CHIPSET_3C509, 0 },
    154      1.14   thorpej };
    155  1.41.6.2     skrll const size_t ep_pcmcia_nproducts =
    156  1.41.6.2     skrll     sizeof(ep_pcmcia_products) / sizeof(ep_pcmcia_products[0]);
    157      1.14   thorpej 
    158       1.2   thorpej int
    159       1.2   thorpej ep_pcmcia_match(parent, match, aux)
    160       1.2   thorpej 	struct device *parent;
    161       1.3  drochner 	struct cfdata *match;
    162       1.2   thorpej 	void *aux;
    163       1.2   thorpej {
    164       1.2   thorpej 	struct pcmcia_attach_args *pa = aux;
    165       1.2   thorpej 
    166  1.41.6.2     skrll 	/* This is to differentiate the serial function of some cards. */
    167  1.41.6.2     skrll 	if (pa->pf->function != PCMCIA_FUNCTION_NETWORK)
    168  1.41.6.2     skrll 		return (0);
    169       1.2   thorpej 
    170  1.41.6.2     skrll 	if (pcmcia_product_lookup(pa, ep_pcmcia_products, ep_pcmcia_nproducts,
    171  1.41.6.2     skrll 	    sizeof(ep_pcmcia_products[0]), NULL))
    172  1.41.6.2     skrll 		return (1);
    173       1.2   thorpej 	return (0);
    174       1.2   thorpej }
    175       1.2   thorpej 
    176       1.2   thorpej int
    177       1.2   thorpej ep_pcmcia_enable(sc)
    178       1.2   thorpej 	struct ep_softc *sc;
    179       1.2   thorpej {
    180       1.2   thorpej 	struct ep_pcmcia_softc *psc = (struct ep_pcmcia_softc *) sc;
    181       1.5      marc 	struct pcmcia_function *pf = psc->sc_pf;
    182      1.30     enami 	int error;
    183       1.2   thorpej 
    184       1.2   thorpej 	/* establish the interrupt. */
    185       1.5      marc 	sc->sc_ih = pcmcia_intr_establish(pf, IPL_NET, epintr, sc);
    186  1.41.6.2     skrll 	if (!sc->sc_ih)
    187  1.41.6.2     skrll 		return (EIO);
    188       1.7   thorpej 
    189  1.41.6.2     skrll 	error = pcmcia_function_enable(pf);
    190  1.41.6.2     skrll 	if (error) {
    191  1.41.6.2     skrll 		pcmcia_intr_disestablish(pf, sc->sc_ih);
    192  1.41.6.2     skrll 		sc->sc_ih = 0;
    193  1.41.6.2     skrll 		return (error);
    194  1.41.6.2     skrll 	}
    195       1.7   thorpej 
    196      1.21      marc 	if ((psc->sc_pf->sc->card.product == PCMCIA_PRODUCT_3COM_3C562) ||
    197      1.23      tron 	    (psc->sc_pf->sc->card.product == PCMCIA_PRODUCT_3COM_3CXEM556) ||
    198      1.23      tron 	    (psc->sc_pf->sc->card.product == PCMCIA_PRODUCT_3COM_3CXEM556INT)) {
    199       1.5      marc 		int reg;
    200       1.5      marc 
    201       1.5      marc 		/* turn off the serial-disable bit */
    202       1.5      marc 
    203       1.5      marc 		reg = pcmcia_ccr_read(pf, PCMCIA_CCR_OPTION);
    204       1.5      marc 		if (reg & 0x08) {
    205       1.7   thorpej 			reg &= ~0x08;
    206       1.7   thorpej 			pcmcia_ccr_write(pf, PCMCIA_CCR_OPTION, reg);
    207       1.5      marc 		}
    208       1.5      marc 
    209       1.5      marc 	}
    210       1.5      marc 
    211  1.41.6.2     skrll 	return (0);
    212       1.2   thorpej }
    213       1.2   thorpej 
    214       1.2   thorpej void
    215       1.2   thorpej ep_pcmcia_disable(sc)
    216       1.2   thorpej 	struct ep_softc *sc;
    217       1.2   thorpej {
    218       1.2   thorpej 	struct ep_pcmcia_softc *psc = (struct ep_pcmcia_softc *) sc;
    219       1.2   thorpej 
    220       1.2   thorpej 	pcmcia_function_disable(psc->sc_pf);
    221  1.41.6.2     skrll 	pcmcia_intr_disestablish(psc->sc_pf, sc->sc_ih);
    222  1.41.6.2     skrll 	sc->sc_ih = 0;
    223       1.2   thorpej }
    224       1.2   thorpej 
    225       1.2   thorpej void
    226       1.2   thorpej ep_pcmcia_attach(parent, self, aux)
    227       1.2   thorpej 	struct device  *parent, *self;
    228       1.2   thorpej 	void           *aux;
    229       1.2   thorpej {
    230       1.2   thorpej 	struct ep_pcmcia_softc *psc = (void *) self;
    231       1.2   thorpej 	struct ep_softc *sc = &psc->sc_ep;
    232       1.2   thorpej 	struct pcmcia_attach_args *pa = aux;
    233       1.2   thorpej 	struct pcmcia_config_entry *cfe;
    234      1.29       cgd 	const struct ep_pcmcia_product *epp;
    235       1.2   thorpej 	u_int8_t myla[ETHER_ADDR_LEN];
    236      1.16   thorpej 	u_int8_t *enaddr = NULL;
    237      1.14   thorpej 	int i;
    238  1.41.6.2     skrll 	int error;
    239  1.41.6.1     skrll 
    240       1.2   thorpej 	psc->sc_pf = pa->pf;
    241       1.2   thorpej 
    242  1.41.6.2     skrll 	SIMPLEQ_FOREACH(cfe, &pa->pf->cfe_head, cfe_list) {
    243  1.41.6.2     skrll 		if (cfe->num_memspace != 0)
    244  1.41.6.2     skrll 			continue;
    245  1.41.6.2     skrll 		if (cfe->num_iospace != 1)
    246  1.41.6.2     skrll 			continue;
    247  1.41.6.2     skrll 
    248  1.41.6.2     skrll 		if (pa->product == PCMCIA_PRODUCT_3COM_3C562) {
    249  1.41.6.2     skrll 			/*
    250  1.41.6.2     skrll 			 * the 3c562 can only use 0x??00-0x??7f
    251  1.41.6.2     skrll 			 * according to the Linux driver
    252  1.41.6.2     skrll 			 */
    253  1.41.6.2     skrll 
    254  1.41.6.2     skrll 			/*
    255  1.41.6.2     skrll 			 * 3c562 i/o may decodes address line not only A0-3
    256  1.41.6.2     skrll 			 * but also A7.  Anyway, we must sweep at most
    257  1.41.6.2     skrll 			 * [0x0000, 0x0100).  The address higher is given by a
    258  1.41.6.2     skrll 			 * pcmcia bridge.  But pcmcia bus-space allocation
    259  1.41.6.2     skrll 			 * function implies cards will decode 10-bit address
    260  1.41.6.2     skrll 			 * line.  So we must search [0x0000, 0x0400).
    261  1.41.6.2     skrll 			 *
    262  1.41.6.2     skrll 			 * XXX: We must not check the bunch of I/O space range
    263  1.41.6.2     skrll 			 * [0x400*n, 0x300 + 0x400*n) because they are
    264  1.41.6.2     skrll 			 * reserved for legacy ISA devices and their alias
    265  1.41.6.2     skrll 			 * images on PC/AT architecture.
    266  1.41.6.2     skrll 			 */
    267  1.41.6.2     skrll 			for (i = 0x0300; i < 0x0380; i += 0x10) {
    268  1.41.6.2     skrll 				if (pcmcia_io_alloc(pa->pf, i,
    269  1.41.6.2     skrll 				    cfe->iospace[0].length,
    270  1.41.6.2     skrll 				    cfe->iospace[0].length,
    271  1.41.6.2     skrll 				    &psc->sc_pcioh) == 0)
    272  1.41.6.2     skrll 					break;
    273  1.41.6.2     skrll 			}
    274  1.41.6.2     skrll 			if (i != 0x0380)
    275  1.41.6.2     skrll 				break;
    276  1.41.6.2     skrll 		} else {
    277  1.41.6.2     skrll 			if (pcmcia_io_alloc(pa->pf, cfe->iospace[0].start,
    278  1.41.6.2     skrll 			    cfe->iospace[0].length, cfe->iospace[0].length,
    279  1.41.6.2     skrll 			    &psc->sc_pcioh) == 0)
    280       1.2   thorpej 				break;
    281      1.30     enami 		}
    282       1.2   thorpej 	}
    283  1.41.6.2     skrll 	if (!cfe) {
    284  1.41.6.2     skrll 		aprint_error("%s: failed to allocate I/O space\n",
    285  1.41.6.2     skrll 		    self->dv_xname);
    286  1.41.6.2     skrll 		goto ioalloc_failed;
    287  1.41.6.2     skrll 	}
    288       1.2   thorpej 
    289       1.2   thorpej 	sc->sc_iot = psc->sc_pcioh.iot;
    290       1.2   thorpej 	sc->sc_ioh = psc->sc_pcioh.ioh;
    291       1.2   thorpej 
    292  1.41.6.2     skrll 	/* Enable the card. */
    293  1.41.6.2     skrll 	pcmcia_function_init(pa->pf, cfe);
    294  1.41.6.2     skrll 
    295       1.2   thorpej 	if (pcmcia_io_map(pa->pf, ((cfe->flags & PCMCIA_CFE_IO16) ?
    296  1.41.6.2     skrll 	    PCMCIA_WIDTH_AUTO : PCMCIA_WIDTH_IO8), &psc->sc_pcioh,
    297  1.41.6.2     skrll 	    &psc->sc_io_window)) {
    298  1.41.6.1     skrll 		aprint_error("%s: can't map i/o space\n", self->dv_xname);
    299      1.30     enami 		goto iomap_failed;
    300       1.2   thorpej 	}
    301      1.16   thorpej 
    302  1.41.6.2     skrll 	error = ep_pcmcia_enable(sc);
    303  1.41.6.2     skrll 	if (error)
    304  1.41.6.2     skrll 		goto enable_failed;
    305  1.41.6.2     skrll 	sc->enabled = 1;
    306  1.41.6.2     skrll 
    307      1.16   thorpej 	switch (pa->product) {
    308      1.16   thorpej 	case PCMCIA_PRODUCT_3COM_3C562:
    309       1.6  christos 		/*
    310       1.6  christos 		 * 3c562a-c use this; 3c562d does it in the regular way.
    311       1.6  christos 		 * we might want to check the revision and produce a warning
    312       1.6  christos 		 * in the future.
    313       1.6  christos 		 */
    314      1.16   thorpej 		/* FALLTHROUGH */
    315      1.16   thorpej 	case PCMCIA_PRODUCT_3COM_3C574:
    316      1.24   thorpej 	case PCMCIA_PRODUCT_3COM_3CCFEM556BI:
    317      1.16   thorpej 		/*
    318      1.16   thorpej 		 * Apparently, some 3c574s do it this way, as well.
    319      1.16   thorpej 		 */
    320      1.16   thorpej 		if (pcmcia_scan_cis(parent, ep_pcmcia_get_enaddr, myla))
    321       1.6  christos 			enaddr = myla;
    322      1.16   thorpej 		break;
    323       1.2   thorpej 	}
    324       1.2   thorpej 
    325  1.41.6.2     skrll 	epp = pcmcia_product_lookup(pa, ep_pcmcia_products, ep_pcmcia_nproducts,
    326  1.41.6.2     skrll 	    sizeof(ep_pcmcia_products[0]), NULL);
    327  1.41.6.2     skrll 	if (!epp)
    328      1.14   thorpej 		panic("ep_pcmcia_attach: impossible");
    329       1.2   thorpej 
    330      1.22   thorpej 	sc->bustype = ELINK_BUS_PCMCIA;
    331      1.22   thorpej 	sc->ep_flags = epp->epp_flags;
    332      1.22   thorpej 
    333       1.2   thorpej 	sc->enable = ep_pcmcia_enable;
    334       1.2   thorpej 	sc->disable = ep_pcmcia_disable;
    335       1.2   thorpej 
    336  1.41.6.2     skrll 	if (epconfig(sc, epp->epp_chipset, enaddr))
    337  1.41.6.1     skrll 		aprint_error("%s: couldn't configure controller\n",
    338  1.41.6.1     skrll 		    self->dv_xname);
    339       1.2   thorpej 
    340       1.2   thorpej 	sc->enabled = 0;
    341  1.41.6.2     skrll 	ep_pcmcia_disable(sc);
    342      1.30     enami 	return;
    343      1.30     enami 
    344  1.41.6.2     skrll enable_failed:
    345      1.30     enami 	pcmcia_io_unmap(psc->sc_pf, psc->sc_io_window);
    346  1.41.6.2     skrll iomap_failed:
    347      1.30     enami 	pcmcia_io_free(psc->sc_pf, &psc->sc_pcioh);
    348  1.41.6.2     skrll ioalloc_failed:
    349      1.30     enami 	psc->sc_io_window = -1;
    350      1.18   thorpej }
    351      1.18   thorpej 
    352      1.18   thorpej int
    353      1.18   thorpej ep_pcmcia_detach(self, flags)
    354      1.18   thorpej 	struct device *self;
    355      1.18   thorpej 	int flags;
    356      1.18   thorpej {
    357      1.19   thorpej 	struct ep_pcmcia_softc *psc = (struct ep_pcmcia_softc *)self;
    358      1.27  augustss 	int rv;
    359      1.27  augustss 
    360      1.30     enami 	if (psc->sc_io_window == -1)
    361      1.30     enami 		/* Nothing to detach. */
    362      1.30     enami 		return (0);
    363      1.30     enami 
    364      1.27  augustss 	rv = ep_detach(self, flags);
    365      1.30     enami 	if (rv != 0)
    366      1.27  augustss 		return (rv);
    367      1.19   thorpej 
    368      1.19   thorpej 	/* Unmap our i/o window. */
    369      1.19   thorpej 	pcmcia_io_unmap(psc->sc_pf, psc->sc_io_window);
    370      1.19   thorpej 
    371      1.19   thorpej 	/* Free our i/o space. */
    372      1.19   thorpej 	pcmcia_io_free(psc->sc_pf, &psc->sc_pcioh);
    373      1.25  augustss 
    374      1.18   thorpej 	return (0);
    375       1.2   thorpej }
    376       1.2   thorpej 
    377       1.2   thorpej int
    378       1.2   thorpej ep_pcmcia_get_enaddr(tuple, arg)
    379       1.2   thorpej 	struct pcmcia_tuple *tuple;
    380       1.2   thorpej 	void *arg;
    381       1.2   thorpej {
    382       1.2   thorpej 	u_int8_t *myla = arg;
    383       1.2   thorpej 	int i;
    384       1.2   thorpej 
    385       1.6  christos 	/* this is 3c562a-c magic */
    386       1.2   thorpej 	if (tuple->code == 0x88) {
    387       1.2   thorpej 		if (tuple->length < ETHER_ADDR_LEN)
    388       1.2   thorpej 			return (0);
    389       1.2   thorpej 
    390       1.2   thorpej 		for (i = 0; i < ETHER_ADDR_LEN; i += 2) {
    391       1.2   thorpej 			myla[i] = pcmcia_tuple_read_1(tuple, i + 1);
    392       1.2   thorpej 			myla[i + 1] = pcmcia_tuple_read_1(tuple, i);
    393       1.2   thorpej 		}
    394       1.2   thorpej 
    395       1.2   thorpej 		return (1);
    396       1.2   thorpej 	}
    397       1.2   thorpej 	return (0);
    398       1.2   thorpej }
    399