Home | History | Annotate | Line # | Download | only in pcmcia
if_mbe_pcmcia.c revision 1.8.4.1
      1  1.8.4.1      fvdl /*	$NetBSD: if_mbe_pcmcia.c,v 1.8.4.1 1999/11/15 00:41:13 fvdl Exp $	*/
      2      1.1     enami 
      3      1.1     enami /*-
      4      1.1     enami  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5      1.1     enami  * All rights reserved.
      6      1.1     enami  *
      7      1.1     enami  * This code is derived from software contributed to The NetBSD Foundation
      8      1.1     enami  * by Enami Tsugutomo.
      9      1.1     enami  *
     10      1.1     enami  * Redistribution and use in source and binary forms, with or without
     11      1.1     enami  * modification, are permitted provided that the following conditions
     12      1.1     enami  * are met:
     13      1.1     enami  * 1. Redistributions of source code must retain the above copyright
     14      1.1     enami  *    notice, this list of conditions and the following disclaimer.
     15      1.1     enami  * 2. Redistributions in binary form must reproduce the above copyright
     16      1.1     enami  *    notice, this list of conditions and the following disclaimer in the
     17      1.1     enami  *    documentation and/or other materials provided with the distribution.
     18      1.1     enami  * 3. All advertising materials mentioning features or use of this software
     19      1.1     enami  *    must display the following acknowledgement:
     20      1.1     enami  *	This product includes software developed by the NetBSD
     21      1.1     enami  *	Foundation, Inc. and its contributors.
     22      1.1     enami  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23      1.1     enami  *    contributors may be used to endorse or promote products derived
     24      1.1     enami  *    from this software without specific prior written permission.
     25      1.1     enami  *
     26      1.1     enami  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27      1.1     enami  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28      1.1     enami  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29      1.1     enami  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30      1.1     enami  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31      1.1     enami  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32      1.1     enami  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33      1.1     enami  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34      1.1     enami  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35      1.1     enami  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36      1.1     enami  * POSSIBILITY OF SUCH DAMAGE.
     37      1.1     enami  */
     38      1.1     enami 
     39      1.1     enami #include <sys/param.h>
     40      1.1     enami #include <sys/systm.h>
     41      1.1     enami #include <sys/device.h>
     42      1.1     enami #include <sys/socket.h>
     43      1.1     enami 
     44      1.1     enami #include <net/if.h>
     45      1.1     enami #include <net/if_ether.h>
     46      1.1     enami #include <net/if_media.h>
     47      1.1     enami 
     48      1.1     enami #include <machine/intr.h>
     49      1.1     enami #include <machine/bus.h>
     50      1.1     enami 
     51      1.1     enami #include <dev/ic/mb86960reg.h>
     52      1.1     enami #include <dev/ic/mb86960var.h>
     53      1.1     enami 
     54      1.1     enami #include <dev/pcmcia/pcmciareg.h>
     55      1.1     enami #include <dev/pcmcia/pcmciavar.h>
     56      1.3  christos #include <dev/pcmcia/pcmciadevs.h>
     57      1.1     enami 
     58      1.1     enami int	mbe_pcmcia_match __P((struct device *, struct cfdata *, void *));
     59      1.1     enami void	mbe_pcmcia_attach __P((struct device *, struct device *, void *));
     60      1.4   thorpej int	mbe_pcmcia_detach __P((struct device *, int));
     61      1.1     enami 
     62      1.1     enami struct mbe_pcmcia_softc {
     63      1.1     enami 	struct	mb86960_softc sc_mb86960;	/* real "mb" softc */
     64      1.1     enami 
     65      1.1     enami 	/* PCMCIA-specific goo. */
     66      1.1     enami 	struct	pcmcia_io_handle sc_pcioh;	/* PCMCIA i/o space info */
     67      1.1     enami 	int	sc_io_window;			/* our i/o window */
     68      1.1     enami 	void	*sc_ih;				/* interrupt cookie */
     69      1.1     enami 	struct	pcmcia_function *sc_pf;		/* our PCMCIA function */
     70      1.1     enami };
     71      1.1     enami 
     72      1.1     enami struct cfattach mbe_pcmcia_ca = {
     73      1.4   thorpej 	sizeof(struct mbe_pcmcia_softc), mbe_pcmcia_match, mbe_pcmcia_attach,
     74      1.6   thorpej 	    mbe_pcmcia_detach, mb86960_activate
     75      1.1     enami };
     76      1.1     enami 
     77      1.1     enami #if NetBSD <= 199712
     78      1.1     enami struct cfdriver mbe_cd = {			/* XXX shouldn't be here */
     79      1.1     enami 	NULL, "mbe", DV_IFNET
     80      1.1     enami };
     81      1.1     enami #endif
     82      1.1     enami 
     83      1.1     enami int	mbe_pcmcia_enable __P((struct mb86960_softc *));
     84      1.1     enami void	mbe_pcmcia_disable __P((struct mb86960_softc *));
     85      1.1     enami 
     86      1.1     enami struct mbe_pcmcia_get_enaddr_args {
     87      1.1     enami 	int got_enaddr;
     88      1.1     enami 	u_int8_t enaddr[ETHER_ADDR_LEN];
     89      1.1     enami };
     90      1.1     enami int	mbe_pcmcia_get_enaddr __P((struct pcmcia_tuple *, void *));
     91      1.1     enami 
     92      1.7   thorpej struct mbe_pcmcia_product {
     93      1.7   thorpej 	u_int32_t	mpp_vendor;	/* vendor ID */
     94      1.7   thorpej 	u_int32_t	mpp_product;	/* product ID */
     95      1.7   thorpej 	int		mpp_expfunc;	/* exptected function */
     96      1.7   thorpej 	u_int32_t	mpp_ioalign;	/* required alignment */
     97      1.7   thorpej 	const char	*mpp_name;	/* product name */
     98      1.7   thorpej } mbe_pcmcia_products[] = {
     99      1.7   thorpej 	{ PCMCIA_VENDOR_TDK,		PCMCIA_PRODUCT_TDK_LAK_CD021BX,
    100      1.7   thorpej 	  0,				0,
    101      1.7   thorpej 	  PCMCIA_STR_TDK_LAK_CD021BX },
    102      1.7   thorpej #if 0 /* XXX 86960-based? */
    103      1.7   thorpej 	{ PCMCIA_VENDOR_TDK,		PCMCIA_PRODUCT_TDK_LAK_DFL9610,
    104      1.7   thorpej 	  1,				0,
    105      1.7   thorpej 	  PCMCIA_STR_TDK_LAK_DFL9610 }
    106      1.7   thorpej #endif
    107      1.8      tron 
    108      1.8      tron 	{ PCMCIA_VENDOR_CONTEC,		PCMCIA_PRODUCT_CONTEC_CNETPC,
    109      1.8      tron 	  0,				0,
    110      1.8      tron 	  PCMCIA_STR_CONTEC_CNETPC },
    111      1.7   thorpej 
    112      1.7   thorpej 	{ PCMCIA_VENDOR_FUJITSU,	PCMCIA_PRODUCT_FUJITSU_LA501,
    113      1.7   thorpej 	  0,				0x20,
    114      1.7   thorpej 	  PCMCIA_STR_FUJITSU_LA501 },
    115  1.8.4.1      fvdl 
    116  1.8.4.1      fvdl 	{ PCMCIA_VENDOR_FUJITSU,	PCMCIA_PRODUCT_FUJITSU_LA10S,
    117  1.8.4.1      fvdl 	  0,				0,
    118  1.8.4.1      fvdl 	  PCMCIA_STR_FUJITSU_LA10S },
    119      1.7   thorpej 
    120      1.7   thorpej 	{ 0,				0,
    121      1.7   thorpej 	  0,				0,
    122      1.7   thorpej 	  NULL },
    123      1.7   thorpej };
    124      1.7   thorpej 
    125      1.7   thorpej const struct mbe_pcmcia_product *mbe_pcmcia_lookup
    126      1.7   thorpej     __P((const struct pcmcia_attach_args *pa));
    127      1.7   thorpej 
    128      1.7   thorpej const struct mbe_pcmcia_product *
    129      1.7   thorpej mbe_pcmcia_lookup(pa)
    130      1.7   thorpej 	const struct pcmcia_attach_args *pa;
    131      1.7   thorpej {
    132      1.7   thorpej 	const struct mbe_pcmcia_product *mpp;
    133      1.7   thorpej 
    134      1.7   thorpej 	for (mpp = mbe_pcmcia_products; mpp->mpp_name != NULL; mpp++) {
    135      1.7   thorpej 		if (pa->manufacturer == mpp->mpp_vendor &&
    136      1.7   thorpej 		    pa->product == mpp->mpp_product &&
    137      1.7   thorpej 		    pa->pf->number == mpp->mpp_expfunc)
    138      1.7   thorpej 			return (mpp);
    139      1.7   thorpej 	}
    140      1.7   thorpej 	return (NULL);
    141      1.7   thorpej }
    142      1.7   thorpej 
    143      1.1     enami int
    144      1.1     enami mbe_pcmcia_match(parent, match, aux)
    145      1.1     enami 	struct device *parent;
    146      1.1     enami 	struct cfdata *match;
    147      1.1     enami 	void *aux;
    148      1.1     enami {
    149      1.1     enami 	struct pcmcia_attach_args *pa = aux;
    150      1.1     enami 
    151      1.7   thorpej 	if (mbe_pcmcia_lookup(pa) != NULL)
    152      1.7   thorpej 		return (1);
    153      1.1     enami 
    154      1.1     enami 	return (0);
    155      1.1     enami }
    156      1.1     enami 
    157      1.1     enami void
    158      1.1     enami mbe_pcmcia_attach(parent, self, aux)
    159      1.1     enami 	struct device *parent, *self;
    160      1.1     enami 	void *aux;
    161      1.1     enami {
    162      1.1     enami 	struct mbe_pcmcia_softc *psc = (struct mbe_pcmcia_softc *)self;
    163      1.1     enami 	struct mb86960_softc *sc = &psc->sc_mb86960;
    164      1.1     enami 	struct pcmcia_attach_args *pa = aux;
    165      1.1     enami 	struct pcmcia_config_entry *cfe;
    166      1.1     enami 	struct mbe_pcmcia_get_enaddr_args pgea;
    167      1.7   thorpej 	const struct mbe_pcmcia_product *mpp;
    168      1.7   thorpej 
    169      1.7   thorpej 	mpp = mbe_pcmcia_lookup(pa);
    170      1.7   thorpej 	if (mpp == NULL) {
    171      1.7   thorpej 		printf("\n");
    172      1.7   thorpej 		panic("mbe_pcmcia_attach: impossible");
    173      1.7   thorpej 	}
    174      1.1     enami 
    175      1.1     enami 	psc->sc_pf = pa->pf;
    176      1.1     enami 	cfe = pa->pf->cfe_head.sqh_first;
    177      1.1     enami 
    178      1.1     enami 	/* Enable the card. */
    179      1.1     enami 	pcmcia_function_init(pa->pf, cfe);
    180      1.1     enami 	if (pcmcia_function_enable(pa->pf)) {
    181      1.1     enami 		printf(": function enable failed\n");
    182      1.1     enami 		return;
    183      1.1     enami 	}
    184      1.1     enami 
    185      1.1     enami 	/* Allocate and map i/o space for the card. */
    186      1.1     enami 	if (pcmcia_io_alloc(pa->pf, cfe->iospace[0].start,
    187      1.7   thorpej 	    cfe->iospace[0].length,
    188      1.7   thorpej 	    mpp->mpp_ioalign ? mpp->mpp_ioalign : cfe->iospace[0].length,
    189      1.7   thorpej 	    &psc->sc_pcioh)) {
    190      1.1     enami 		printf(": can't allocate i/o space\n");
    191      1.1     enami 		return;
    192      1.1     enami 	}
    193      1.1     enami 
    194      1.1     enami 	sc->sc_bst = psc->sc_pcioh.iot;
    195      1.1     enami 	sc->sc_bsh = psc->sc_pcioh.ioh;
    196      1.1     enami 
    197      1.1     enami 	sc->sc_enable = mbe_pcmcia_enable;
    198      1.1     enami 	sc->sc_disable = mbe_pcmcia_disable;
    199      1.1     enami 
    200      1.7   thorpej 	/*
    201      1.7   thorpej 	 * Don't bother checking flags; the back-end sets the chip
    202      1.7   thorpej 	 * into 16-bit mode.
    203      1.7   thorpej 	 */
    204      1.7   thorpej 	if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_IO16, 0, cfe->iospace[0].length,
    205      1.1     enami 	    &psc->sc_pcioh, &psc->sc_io_window)) {
    206      1.1     enami 		printf(": can't map i/o space\n");
    207      1.1     enami 		return;
    208      1.1     enami 	}
    209      1.1     enami 
    210      1.7   thorpej 	printf(": %s\n", mpp->mpp_name);
    211      1.1     enami 
    212      1.1     enami 	/* Read station address. */
    213      1.1     enami 	pgea.got_enaddr = 0;
    214      1.1     enami 	if (pcmcia_scan_cis(parent, mbe_pcmcia_get_enaddr, &pgea) == -1) {
    215      1.1     enami 		printf("%s: Couldn't read CIS to get ethernet address\n",
    216      1.1     enami 		    sc->sc_dev.dv_xname);
    217      1.1     enami 		return;
    218      1.1     enami 	} else if (!pgea.got_enaddr) {
    219      1.1     enami 		printf("%s: Couldn't get ethernet address from CIS\n",
    220      1.1     enami 		    sc->sc_dev.dv_xname);
    221      1.1     enami 		return;
    222      1.1     enami 	} else
    223      1.1     enami #ifdef DIAGNOSTIC
    224      1.1     enami 		printf("%s: Ethernet address from CIS: %s\n",
    225      1.1     enami 		    sc->sc_dev.dv_xname, ether_sprintf(pgea.enaddr))
    226      1.1     enami #endif
    227      1.1     enami 		;
    228      1.1     enami 
    229      1.1     enami 	/* Perform generic initialization. */
    230      1.1     enami 	mb86960_attach(sc, MB86960_TYPE_86965, pgea.enaddr);
    231      1.1     enami 
    232      1.1     enami 	mb86960_config(sc, NULL, 0, 0);
    233      1.1     enami 
    234      1.1     enami 	pcmcia_function_disable(pa->pf);
    235      1.4   thorpej }
    236      1.4   thorpej 
    237      1.4   thorpej int
    238      1.4   thorpej mbe_pcmcia_detach(self, flags)
    239      1.4   thorpej 	struct device *self;
    240      1.4   thorpej 	int flags;
    241      1.4   thorpej {
    242      1.5   thorpej 	struct mbe_pcmcia_softc *psc = (struct mbe_pcmcia_softc *)self;
    243      1.5   thorpej 
    244      1.5   thorpej 	/* Unmap our i/o window. */
    245      1.5   thorpej 	pcmcia_io_unmap(psc->sc_pf, psc->sc_io_window);
    246      1.5   thorpej 
    247      1.5   thorpej 	/* Free our i/o space. */
    248      1.5   thorpej 	pcmcia_io_free(psc->sc_pf, &psc->sc_pcioh);
    249      1.5   thorpej 
    250      1.4   thorpej #ifdef notyet
    251      1.4   thorpej 	/*
    252      1.4   thorpej 	 * Our softc is about to go away, so drop our reference
    253      1.4   thorpej 	 * to the ifnet.
    254      1.4   thorpej 	 */
    255      1.5   thorpej 	if_delref(psc->sc_mb86960.sc_ec.ec_if);
    256      1.4   thorpej 	return (0);
    257      1.4   thorpej #else
    258      1.4   thorpej 	return (EBUSY);
    259      1.4   thorpej #endif
    260      1.1     enami }
    261      1.1     enami 
    262      1.1     enami int
    263      1.1     enami mbe_pcmcia_enable(sc)
    264      1.1     enami 	struct mb86960_softc *sc;
    265      1.1     enami {
    266      1.1     enami 	struct mbe_pcmcia_softc *psc = (struct mbe_pcmcia_softc *)sc;
    267      1.1     enami 
    268      1.1     enami 	/* Establish the interrupt handler. */
    269      1.1     enami 	psc->sc_ih = pcmcia_intr_establish(psc->sc_pf, IPL_NET, mb86960_intr,
    270      1.1     enami 	    sc);
    271      1.1     enami 	if (psc->sc_ih == NULL) {
    272      1.1     enami 		printf("%s: couldn't establish interrupt handler\n",
    273      1.1     enami 		    sc->sc_dev.dv_xname);
    274      1.1     enami 		return (1);
    275      1.1     enami 	}
    276      1.1     enami 
    277      1.1     enami 	return (pcmcia_function_enable(psc->sc_pf));
    278      1.1     enami }
    279      1.1     enami 
    280      1.1     enami void
    281      1.1     enami mbe_pcmcia_disable(sc)
    282      1.1     enami 	struct mb86960_softc *sc;
    283      1.1     enami {
    284      1.1     enami 	struct mbe_pcmcia_softc *psc = (struct mbe_pcmcia_softc *)sc;
    285      1.1     enami 
    286      1.1     enami 	pcmcia_function_disable(psc->sc_pf);
    287      1.1     enami 
    288      1.1     enami 	pcmcia_intr_disestablish(psc->sc_pf, psc->sc_ih);
    289      1.1     enami }
    290      1.1     enami 
    291      1.1     enami int
    292      1.1     enami mbe_pcmcia_get_enaddr(tuple, arg)
    293      1.1     enami 	struct pcmcia_tuple *tuple;
    294      1.1     enami 	void *arg;
    295      1.1     enami {
    296      1.1     enami 	struct mbe_pcmcia_get_enaddr_args *p = arg;
    297      1.1     enami 	int i;
    298      1.1     enami 
    299      1.1     enami 	if (tuple->code == PCMCIA_CISTPL_FUNCE) {
    300      1.1     enami 		if (tuple->length < 2) /* sub code and ether addr length */
    301      1.1     enami 			return (0);
    302      1.1     enami 
    303      1.1     enami 		if ((pcmcia_tuple_read_1(tuple, 0) !=
    304      1.1     enami 			PCMCIA_TPLFE_TYPE_LAN_NID) ||
    305      1.1     enami 		    (pcmcia_tuple_read_1(tuple, 1) != ETHER_ADDR_LEN))
    306      1.1     enami 			return (0);
    307      1.1     enami 
    308      1.1     enami 		for (i = 0; i < ETHER_ADDR_LEN; i++)
    309      1.1     enami 			p->enaddr[i] = pcmcia_tuple_read_1(tuple, i + 2);
    310      1.1     enami 		p->got_enaddr = 1;
    311      1.1     enami 		return (1);
    312      1.1     enami 	}
    313      1.1     enami 	return (0);
    314      1.1     enami }
    315