Home | History | Annotate | Line # | Download | only in isapnp
if_an_isapnp.c revision 1.17.2.1
      1 /*	$NetBSD: if_an_isapnp.c,v 1.17.2.1 2008/05/18 12:34:09 yamt Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2000 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jason R. Thorpe.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 /*
     33  * ISAPnP bus front-end for the Aironet ISA4500/ISA4800 Wireless LAN Adapter.
     34  * Unlike WaveLAN, this adapter is attached as an ISA device using an address
     35  * decoder hack.
     36  */
     37 
     38 #include <sys/cdefs.h>
     39 __KERNEL_RCSID(0, "$NetBSD: if_an_isapnp.c,v 1.17.2.1 2008/05/18 12:34:09 yamt Exp $");
     40 
     41 #include <sys/param.h>
     42 #include <sys/systm.h>
     43 #include <sys/mbuf.h>
     44 #include <sys/malloc.h>
     45 #include <sys/kernel.h>
     46 #include <sys/socket.h>
     47 #include <sys/ioctl.h>
     48 #include <sys/errno.h>
     49 #include <sys/device.h>
     50 #include <sys/callout.h>
     51 
     52 #include <net/if.h>
     53 #include <net/if_dl.h>
     54 #include <net/if_media.h>
     55 #include <net/if_ether.h>
     56 
     57 #include <net80211/ieee80211_netbsd.h>
     58 #include <net80211/ieee80211_var.h>
     59 
     60 #include <sys/bus.h>
     61 #include <sys/intr.h>
     62 
     63 #include <dev/ic/anreg.h>
     64 #include <dev/ic/anvar.h>
     65 
     66 #include <dev/isa/isavar.h>
     67 
     68 #include <dev/isapnp/isapnpreg.h>
     69 #include <dev/isapnp/isapnpvar.h>
     70 #include <dev/isapnp/isapnpdevs.h>
     71 
     72 int	an_isapnp_match(struct device *, struct cfdata *, void *);
     73 void	an_isapnp_attach(struct device *, struct device *, void *);
     74 
     75 struct an_isapnp_softc {
     76 	struct an_softc sc_an;			/* real "an" softc */
     77 
     78 	/* ISA-specific goo. */
     79 	void	*sc_ih;				/* interrupt cookie */
     80 };
     81 
     82 CFATTACH_DECL(an_isapnp, sizeof(struct an_isapnp_softc),
     83     an_isapnp_match, an_isapnp_attach, NULL, NULL);
     84 
     85 int
     86 an_isapnp_match(struct device *parent, struct cfdata *match,
     87     void *aux)
     88 {
     89 	int pri, variant;
     90 
     91 	pri = isapnp_devmatch(aux, &isapnp_an_devinfo, &variant);
     92 	if (pri && variant > 0)
     93 		pri = 0;
     94 	return (pri);
     95 }
     96 
     97 void
     98 an_isapnp_attach(struct device *parent, struct device *self, void *aux)
     99 {
    100 	struct an_isapnp_softc *isc = device_private(self);
    101 	struct an_softc *sc = &isc->sc_an;
    102 	struct isapnp_attach_args *ipa = aux;
    103 
    104 	printf("\n");
    105 
    106 	if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
    107 		aprint_error_dev(&sc->sc_dev, "can't configure isapnp resources\n");
    108 		return;
    109 	}
    110 
    111 	sc->sc_iot = ipa->ipa_iot;
    112 	sc->sc_ioh = ipa->ipa_io[0].h;
    113 
    114 	printf("%s: %s %s\n", device_xname(&sc->sc_dev), ipa->ipa_devident,
    115 	    ipa->ipa_devclass);
    116 
    117 	/* This interface is always enabled. */
    118 	sc->sc_enabled = 1;
    119 
    120 	/* Establish the interrupt handler. */
    121 	isc->sc_ih = isa_intr_establish(ipa->ipa_ic, ipa->ipa_irq[0].num,
    122 	    ipa->ipa_irq[0].type, IPL_NET, an_intr, sc);
    123 	if (isc->sc_ih == NULL) {
    124 		aprint_error_dev(&sc->sc_dev, "couldn't establish interrupt handler\n");
    125 		return;
    126 	}
    127 
    128 	if (an_attach(sc) != 0) {
    129 		aprint_error_dev(&sc->sc_dev, "failed to attach controller\n");
    130 		isa_intr_disestablish(ipa->ipa_ic, isc->sc_ih);
    131 		isc->sc_ih = NULL;
    132 	}
    133 }
    134