Home | History | Annotate | Line # | Download | only in pcmcia
if_ep_pcmcia.c revision 1.38
      1  1.38     lukem /*	$NetBSD: if_ep_pcmcia.c,v 1.38 2002/06/01 23:51:01 lukem Exp $	*/
      2  1.14   thorpej 
      3  1.14   thorpej /*-
      4  1.29       cgd  * Copyright (c) 1998, 2000 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.14   thorpej  * NASA Ames Research Center.
     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.38     lukem __KERNEL_RCSID(0, "$NetBSD: if_ep_pcmcia.c,v 1.38 2002/06/01 23:51:01 lukem 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.2   thorpej int	ep_pcmcia_match __P((struct device *, struct cfdata *, void *));
    101   1.2   thorpej void	ep_pcmcia_attach __P((struct device *, struct device *, void *));
    102  1.18   thorpej int	ep_pcmcia_detach __P((struct device *, int));
    103   1.2   thorpej 
    104   1.2   thorpej int	ep_pcmcia_get_enaddr __P((struct pcmcia_tuple *, void *));
    105   1.2   thorpej int	ep_pcmcia_enable __P((struct ep_softc *));
    106   1.2   thorpej void	ep_pcmcia_disable __P((struct ep_softc *));
    107   1.2   thorpej 
    108   1.7   thorpej int	ep_pcmcia_enable1 __P((struct ep_softc *));
    109   1.7   thorpej void	ep_pcmcia_disable1 __P((struct ep_softc *));
    110   1.7   thorpej 
    111   1.2   thorpej struct ep_pcmcia_softc {
    112   1.2   thorpej 	struct ep_softc sc_ep;			/* real "ep" softc */
    113   1.2   thorpej 
    114   1.2   thorpej 	/* PCMCIA-specific goo */
    115   1.2   thorpej 	struct pcmcia_io_handle sc_pcioh;	/* PCMCIA i/o space info */
    116   1.2   thorpej 	int sc_io_window;			/* our i/o window */
    117   1.2   thorpej 	struct pcmcia_function *sc_pf;		/* our PCMCIA function */
    118   1.2   thorpej };
    119   1.2   thorpej 
    120   1.2   thorpej struct cfattach ep_pcmcia_ca = {
    121  1.18   thorpej 	sizeof(struct ep_pcmcia_softc), ep_pcmcia_match, ep_pcmcia_attach,
    122  1.28  augustss 	    ep_pcmcia_detach, ep_activate
    123   1.2   thorpej };
    124   1.2   thorpej 
    125  1.29       cgd const struct ep_pcmcia_product {
    126  1.29       cgd 	struct pcmcia_product epp_product;
    127  1.14   thorpej 	u_short		epp_chipset;	/* 3Com chipset used */
    128  1.14   thorpej 	int		epp_flags;	/* initial softc flags */
    129  1.14   thorpej } ep_pcmcia_products[] = {
    130  1.29       cgd 	{ { PCMCIA_STR_3COM_3C562,		PCMCIA_VENDOR_3COM,
    131  1.29       cgd 	    PCMCIA_PRODUCT_3COM_3C562,		0 },
    132  1.29       cgd 	  ELINK_CHIPSET_3C509, 0 },
    133  1.29       cgd 
    134  1.29       cgd 	{ { PCMCIA_STR_3COM_3C589,		PCMCIA_VENDOR_3COM,
    135  1.29       cgd 	    PCMCIA_PRODUCT_3COM_3C589,		0 },
    136  1.29       cgd 	  ELINK_CHIPSET_3C509, 0 },
    137  1.29       cgd 
    138  1.29       cgd 	{ { PCMCIA_STR_3COM_3CXEM556,		PCMCIA_VENDOR_3COM,
    139  1.29       cgd 	    PCMCIA_PRODUCT_3COM_3CXEM556,	0 },
    140  1.29       cgd 	  ELINK_CHIPSET_3C509, 0 },
    141  1.29       cgd 
    142  1.29       cgd 	{ { PCMCIA_STR_3COM_3CXEM556INT,	PCMCIA_VENDOR_3COM,
    143  1.29       cgd 	    PCMCIA_PRODUCT_3COM_3CXEM556INT,	0 },
    144  1.29       cgd 	  ELINK_CHIPSET_3C509, 0 },
    145  1.29       cgd 
    146  1.29       cgd 	{ { PCMCIA_STR_3COM_3C574,		PCMCIA_VENDOR_3COM,
    147  1.29       cgd 	    PCMCIA_PRODUCT_3COM_3C574,		0 },
    148  1.29       cgd 	  ELINK_CHIPSET_ROADRUNNER, ELINK_FLAGS_MII },
    149  1.29       cgd 
    150  1.29       cgd 	{ { PCMCIA_STR_3COM_3CCFEM556BI,	PCMCIA_VENDOR_3COM,
    151  1.29       cgd 	    PCMCIA_PRODUCT_3COM_3CCFEM556BI,	0 },
    152  1.29       cgd 	  ELINK_CHIPSET_ROADRUNNER, ELINK_FLAGS_MII },
    153  1.31       cgd 
    154  1.32       cgd 	{ { PCMCIA_STR_3COM_3C1,		PCMCIA_VENDOR_3COM,
    155  1.32       cgd 	    PCMCIA_PRODUCT_3COM_3C1,		0 },
    156  1.31       cgd 	  ELINK_CHIPSET_3C509, 0 },
    157  1.29       cgd 
    158  1.29       cgd 	{ { NULL } }
    159  1.14   thorpej };
    160  1.14   thorpej 
    161   1.2   thorpej int
    162   1.2   thorpej ep_pcmcia_match(parent, match, aux)
    163   1.2   thorpej 	struct device *parent;
    164   1.3  drochner 	struct cfdata *match;
    165   1.2   thorpej 	void *aux;
    166   1.2   thorpej {
    167   1.2   thorpej 	struct pcmcia_attach_args *pa = aux;
    168   1.2   thorpej 
    169  1.29       cgd 	if (pcmcia_product_lookup(pa,
    170  1.29       cgd 	    (const struct pcmcia_product *)ep_pcmcia_products,
    171  1.29       cgd 	    sizeof ep_pcmcia_products[0], NULL) != NULL)
    172  1.14   thorpej 		return (1);
    173   1.2   thorpej 
    174   1.2   thorpej 	return (0);
    175   1.2   thorpej }
    176   1.2   thorpej 
    177   1.2   thorpej int
    178   1.2   thorpej ep_pcmcia_enable(sc)
    179   1.2   thorpej 	struct ep_softc *sc;
    180   1.2   thorpej {
    181   1.2   thorpej 	struct ep_pcmcia_softc *psc = (struct ep_pcmcia_softc *) sc;
    182   1.5      marc 	struct pcmcia_function *pf = psc->sc_pf;
    183  1.30     enami 	int error;
    184   1.2   thorpej 
    185  1.36  christos 	if ((error = ep_pcmcia_enable1(sc)) != 0)
    186  1.36  christos 		return error;
    187  1.36  christos 
    188   1.2   thorpej 	/* establish the interrupt. */
    189   1.5      marc 	sc->sc_ih = pcmcia_intr_establish(pf, IPL_NET, epintr, sc);
    190   1.2   thorpej 	if (sc->sc_ih == NULL) {
    191   1.2   thorpej 		printf("%s: couldn't establish interrupt\n",
    192   1.2   thorpej 		    sc->sc_dev.dv_xname);
    193  1.36  christos 		ep_pcmcia_disable1(sc);
    194   1.2   thorpej 		return (1);
    195   1.2   thorpej 	}
    196   1.2   thorpej 
    197  1.36  christos 	return 0;
    198   1.7   thorpej }
    199   1.7   thorpej 
    200   1.7   thorpej int
    201   1.7   thorpej ep_pcmcia_enable1(sc)
    202   1.7   thorpej 	struct ep_softc *sc;
    203   1.7   thorpej {
    204   1.7   thorpej 	struct ep_pcmcia_softc *psc = (struct ep_pcmcia_softc *) sc;
    205   1.7   thorpej 	struct pcmcia_function *pf = psc->sc_pf;
    206   1.7   thorpej 	int ret;
    207   1.7   thorpej 
    208   1.5      marc 	if ((ret = pcmcia_function_enable(pf)))
    209   1.7   thorpej 		return (ret);
    210   1.7   thorpej 
    211  1.21      marc 	if ((psc->sc_pf->sc->card.product == PCMCIA_PRODUCT_3COM_3C562) ||
    212  1.23      tron 	    (psc->sc_pf->sc->card.product == PCMCIA_PRODUCT_3COM_3CXEM556) ||
    213  1.23      tron 	    (psc->sc_pf->sc->card.product == PCMCIA_PRODUCT_3COM_3CXEM556INT)) {
    214   1.5      marc 		int reg;
    215   1.5      marc 
    216   1.5      marc 		/* turn off the serial-disable bit */
    217   1.5      marc 
    218   1.5      marc 		reg = pcmcia_ccr_read(pf, PCMCIA_CCR_OPTION);
    219   1.5      marc 		if (reg & 0x08) {
    220   1.7   thorpej 			reg &= ~0x08;
    221   1.7   thorpej 			pcmcia_ccr_write(pf, PCMCIA_CCR_OPTION, reg);
    222   1.5      marc 		}
    223   1.5      marc 
    224   1.5      marc 	}
    225   1.5      marc 
    226   1.5      marc 	return (ret);
    227   1.2   thorpej }
    228   1.2   thorpej 
    229   1.2   thorpej void
    230   1.2   thorpej ep_pcmcia_disable(sc)
    231   1.2   thorpej 	struct ep_softc *sc;
    232   1.2   thorpej {
    233   1.2   thorpej 	struct ep_pcmcia_softc *psc = (struct ep_pcmcia_softc *) sc;
    234   1.2   thorpej 
    235  1.33  augustss 	/*
    236  1.33  augustss 	 * We must disestablish the interrupt before disabling the function,
    237  1.33  augustss 	 * because on a multifunction card the interrupt disestablishment
    238  1.33  augustss 	 * accesses CCR registers.
    239  1.33  augustss 	 */
    240  1.33  augustss 	pcmcia_intr_disestablish(psc->sc_pf, sc->sc_ih);
    241   1.7   thorpej 	ep_pcmcia_disable1(sc);
    242   1.7   thorpej }
    243   1.7   thorpej 
    244   1.7   thorpej void
    245   1.7   thorpej ep_pcmcia_disable1(sc)
    246   1.7   thorpej 	struct ep_softc *sc;
    247   1.7   thorpej {
    248   1.7   thorpej 	struct ep_pcmcia_softc *psc = (struct ep_pcmcia_softc *) sc;
    249   1.7   thorpej 
    250   1.2   thorpej 	pcmcia_function_disable(psc->sc_pf);
    251   1.2   thorpej }
    252   1.2   thorpej 
    253   1.2   thorpej void
    254   1.2   thorpej ep_pcmcia_attach(parent, self, aux)
    255   1.2   thorpej 	struct device  *parent, *self;
    256   1.2   thorpej 	void           *aux;
    257   1.2   thorpej {
    258   1.2   thorpej 	struct ep_pcmcia_softc *psc = (void *) self;
    259   1.2   thorpej 	struct ep_softc *sc = &psc->sc_ep;
    260   1.2   thorpej 	struct pcmcia_attach_args *pa = aux;
    261   1.2   thorpej 	struct pcmcia_config_entry *cfe;
    262  1.29       cgd 	const struct ep_pcmcia_product *epp;
    263   1.2   thorpej 	u_int8_t myla[ETHER_ADDR_LEN];
    264  1.16   thorpej 	u_int8_t *enaddr = NULL;
    265  1.14   thorpej 	int i;
    266   1.2   thorpej 
    267   1.2   thorpej 	psc->sc_pf = pa->pf;
    268  1.38     lukem 	cfe = SIMPLEQ_FIRST(&pa->pf->cfe_head);
    269   1.2   thorpej 
    270   1.2   thorpej 	/* Enable the card. */
    271   1.2   thorpej 	pcmcia_function_init(pa->pf, cfe);
    272  1.30     enami 	if (ep_pcmcia_enable1(sc)) {
    273   1.2   thorpej 		printf(": function enable failed\n");
    274  1.30     enami 		goto enable_failed;
    275  1.30     enami 	}
    276   1.2   thorpej 	sc->enabled = 1;
    277   1.2   thorpej 
    278  1.30     enami 	if (cfe->num_memspace != 0) {
    279   1.2   thorpej 		printf(": unexpected number of memory spaces %d should be 0\n",
    280   1.2   thorpej 		    cfe->num_memspace);
    281  1.30     enami 		goto ioalloc_failed;
    282  1.30     enami 	}
    283   1.2   thorpej 
    284  1.30     enami 	if (cfe->num_iospace != 1) {
    285   1.2   thorpej 		printf(": unexpected number of I/O spaces %d should be 1\n",
    286   1.2   thorpej 		    cfe->num_iospace);
    287  1.30     enami 		goto ioalloc_failed;
    288  1.30     enami 	}
    289   1.2   thorpej 
    290   1.2   thorpej 	if (pa->product == PCMCIA_PRODUCT_3COM_3C562) {
    291  1.37  christos 		/*
    292  1.37  christos 		 * the 3c562 can only use 0x??00-0x??7f
    293  1.37  christos 		 * according to the Linux driver
    294  1.37  christos 		 */
    295  1.37  christos 
    296  1.37  christos 		/*
    297  1.37  christos 		 * 3c562 i/o may decodes address line not only A0-3
    298  1.37  christos 		 * but also A7.  Anyway, we must sweep at most
    299  1.37  christos 		 * [0x0000, 0x0100).  The address higher is given by a
    300  1.37  christos 		 * pcmcia bridge.  But pcmcia bus-space allocation
    301  1.37  christos 		 * function implies cards will decode 10-bit address
    302  1.37  christos 		 * line.  So we must search [0x0000, 0x0400).
    303  1.37  christos 		 *
    304  1.37  christos 		 * XXX: We must not check the bunch of I/O space range
    305  1.37  christos 		 * [0x400*n, 0x300 + 0x400*n) because they are
    306  1.37  christos 		 * reserved for legacy ISA devices and their alias
    307  1.37  christos 		 * images on PC/AT architecture.
    308  1.37  christos 		 */
    309  1.37  christos 		for (i = 0x0300; i < 0x0380; i += 0x10) {
    310   1.2   thorpej 			if (pcmcia_io_alloc(pa->pf, i, cfe->iospace[0].length,
    311   1.2   thorpej 			    0, &psc->sc_pcioh) == 0)
    312   1.2   thorpej 				break;
    313   1.2   thorpej 		}
    314  1.37  christos 		if (i == 0x0380) {
    315   1.2   thorpej 			printf(": can't allocate i/o space\n");
    316  1.30     enami 			goto ioalloc_failed;
    317   1.2   thorpej 		}
    318   1.2   thorpej 	} else {
    319   1.2   thorpej 		if (pcmcia_io_alloc(pa->pf, 0, cfe->iospace[0].length,
    320  1.30     enami 		    cfe->iospace[0].length, &psc->sc_pcioh)) {
    321   1.2   thorpej 			printf(": can't allocate i/o space\n");
    322  1.30     enami 			goto ioalloc_failed;
    323  1.30     enami 		}
    324   1.2   thorpej 	}
    325   1.2   thorpej 
    326   1.2   thorpej 	sc->sc_iot = psc->sc_pcioh.iot;
    327   1.2   thorpej 	sc->sc_ioh = psc->sc_pcioh.ioh;
    328   1.2   thorpej 
    329   1.2   thorpej 	if (pcmcia_io_map(pa->pf, ((cfe->flags & PCMCIA_CFE_IO16) ?
    330   1.2   thorpej 	    PCMCIA_WIDTH_IO16 : PCMCIA_WIDTH_IO8), 0, cfe->iospace[0].length,
    331   1.2   thorpej 	    &psc->sc_pcioh, &psc->sc_io_window)) {
    332   1.2   thorpej 		printf(": can't map i/o space\n");
    333  1.30     enami 		goto iomap_failed;
    334   1.2   thorpej 	}
    335  1.16   thorpej 
    336  1.16   thorpej 	switch (pa->product) {
    337  1.16   thorpej 	case PCMCIA_PRODUCT_3COM_3C562:
    338   1.6  christos 		/*
    339   1.6  christos 		 * 3c562a-c use this; 3c562d does it in the regular way.
    340   1.6  christos 		 * we might want to check the revision and produce a warning
    341   1.6  christos 		 * in the future.
    342   1.6  christos 		 */
    343  1.16   thorpej 		/* FALLTHROUGH */
    344  1.16   thorpej 	case PCMCIA_PRODUCT_3COM_3C574:
    345  1.24   thorpej 	case PCMCIA_PRODUCT_3COM_3CCFEM556BI:
    346  1.16   thorpej 		/*
    347  1.16   thorpej 		 * Apparently, some 3c574s do it this way, as well.
    348  1.16   thorpej 		 */
    349  1.16   thorpej 		if (pcmcia_scan_cis(parent, ep_pcmcia_get_enaddr, myla))
    350   1.6  christos 			enaddr = myla;
    351  1.16   thorpej 		break;
    352   1.2   thorpej 	}
    353   1.2   thorpej 
    354  1.29       cgd 	epp = (const struct ep_pcmcia_product *)pcmcia_product_lookup(pa,
    355  1.29       cgd             (const struct pcmcia_product *)ep_pcmcia_products,
    356  1.29       cgd             sizeof ep_pcmcia_products[0], NULL);
    357  1.14   thorpej 	if (epp == NULL)
    358  1.14   thorpej 		panic("ep_pcmcia_attach: impossible");
    359   1.2   thorpej 
    360  1.29       cgd 	printf(": %s\n", epp->epp_product.pp_name);
    361  1.22   thorpej 
    362  1.22   thorpej 	sc->bustype = ELINK_BUS_PCMCIA;
    363  1.22   thorpej 	sc->ep_flags = epp->epp_flags;
    364  1.22   thorpej 
    365   1.2   thorpej 	sc->enable = ep_pcmcia_enable;
    366   1.2   thorpej 	sc->disable = ep_pcmcia_disable;
    367   1.2   thorpej 
    368  1.30     enami 	if (epconfig(sc, epp->epp_chipset, enaddr)) {
    369  1.30     enami 		printf("%s: couldn't configure controller\n",
    370  1.30     enami 		    sc->sc_dev.dv_xname);
    371  1.30     enami 		goto config_failed;
    372  1.30     enami 	}
    373   1.2   thorpej 
    374   1.2   thorpej 	sc->enabled = 0;
    375  1.30     enami 	ep_pcmcia_disable1(sc);
    376  1.30     enami 	return;
    377  1.30     enami 
    378  1.30     enami  config_failed:
    379  1.30     enami 	/* Unmap our i/o window. */
    380  1.30     enami 	pcmcia_io_unmap(psc->sc_pf, psc->sc_io_window);
    381  1.30     enami 
    382  1.30     enami  iomap_failed:
    383  1.30     enami 	/* Free our i/o space. */
    384  1.30     enami 	pcmcia_io_free(psc->sc_pf, &psc->sc_pcioh);
    385   1.2   thorpej 
    386  1.30     enami  ioalloc_failed:
    387  1.30     enami 	sc->enabled = 0;
    388   1.7   thorpej 	ep_pcmcia_disable1(sc);
    389  1.30     enami 
    390  1.30     enami  enable_failed:
    391  1.30     enami 	psc->sc_io_window = -1;
    392  1.18   thorpej }
    393  1.18   thorpej 
    394  1.18   thorpej int
    395  1.18   thorpej ep_pcmcia_detach(self, flags)
    396  1.18   thorpej 	struct device *self;
    397  1.18   thorpej 	int flags;
    398  1.18   thorpej {
    399  1.19   thorpej 	struct ep_pcmcia_softc *psc = (struct ep_pcmcia_softc *)self;
    400  1.27  augustss 	int rv;
    401  1.27  augustss 
    402  1.30     enami 	if (psc->sc_io_window == -1)
    403  1.30     enami 		/* Nothing to detach. */
    404  1.30     enami 		return (0);
    405  1.30     enami 
    406  1.27  augustss 	rv = ep_detach(self, flags);
    407  1.30     enami 	if (rv != 0)
    408  1.27  augustss 		return (rv);
    409  1.19   thorpej 
    410  1.19   thorpej 	/* Unmap our i/o window. */
    411  1.19   thorpej 	pcmcia_io_unmap(psc->sc_pf, psc->sc_io_window);
    412  1.19   thorpej 
    413  1.19   thorpej 	/* Free our i/o space. */
    414  1.19   thorpej 	pcmcia_io_free(psc->sc_pf, &psc->sc_pcioh);
    415  1.25  augustss 
    416  1.18   thorpej 	return (0);
    417   1.2   thorpej }
    418   1.2   thorpej 
    419   1.2   thorpej int
    420   1.2   thorpej ep_pcmcia_get_enaddr(tuple, arg)
    421   1.2   thorpej 	struct pcmcia_tuple *tuple;
    422   1.2   thorpej 	void *arg;
    423   1.2   thorpej {
    424   1.2   thorpej 	u_int8_t *myla = arg;
    425   1.2   thorpej 	int i;
    426   1.2   thorpej 
    427   1.6  christos 	/* this is 3c562a-c magic */
    428   1.2   thorpej 	if (tuple->code == 0x88) {
    429   1.2   thorpej 		if (tuple->length < ETHER_ADDR_LEN)
    430   1.2   thorpej 			return (0);
    431   1.2   thorpej 
    432   1.2   thorpej 		for (i = 0; i < ETHER_ADDR_LEN; i += 2) {
    433   1.2   thorpej 			myla[i] = pcmcia_tuple_read_1(tuple, i + 1);
    434   1.2   thorpej 			myla[i + 1] = pcmcia_tuple_read_1(tuple, i);
    435   1.2   thorpej 		}
    436   1.2   thorpej 
    437   1.2   thorpej 		return (1);
    438   1.2   thorpej 	}
    439   1.2   thorpej 	return (0);
    440   1.2   thorpej }
    441