1/*	$NetBSD: if_an_isapnp.c,v 1.21 2008/07/04 04:53:41 cegger 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.21 2008/07/04 04:53:41 cegger 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
72int	an_isapnp_match(device_t, cfdata_t, void *);
73void	an_isapnp_attach(device_t, device_t, void *);
74
75struct 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
82CFATTACH_DECL_NEW(an_isapnp, sizeof(struct an_isapnp_softc),
83    an_isapnp_match, an_isapnp_attach, NULL, NULL);
84
85int
86an_isapnp_match(device_t parent, cfdata_t match, void *aux)
87{
88	int pri, variant;
89
90	pri = isapnp_devmatch(aux, &isapnp_an_devinfo, &variant);
91	if (pri && variant > 0)
92		pri = 0;
93	return (pri);
94}
95
96void
97an_isapnp_attach(device_t parent, device_t self, void *aux)
98{
99	struct an_isapnp_softc *isc = device_private(self);
100	struct an_softc *sc = &isc->sc_an;
101	struct isapnp_attach_args *ipa = aux;
102
103	printf("\n");
104
105	if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
106		aprint_error_dev(self, "can't configure isapnp resources\n");
107		return;
108	}
109
110	sc->sc_dev = self;
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(self), 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(self, "couldn't establish interrupt handler\n");
125		return;
126	}
127
128	if (an_attach(sc) != 0) {
129		aprint_error_dev(self, "failed to attach controller\n");
130		isa_intr_disestablish(ipa->ipa_ic, isc->sc_ih);
131		isc->sc_ih = NULL;
132	}
133}
134