xref: /netbsd-src/sys/dev/isapnp/if_an_isapnp.c (revision fe6eef591a5ec7c2c22f819c24ff1a9e107b3759)
1 /*	$NetBSD: if_an_isapnp.c,v 1.24 2022/09/25 17:19:05 thorpej 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.24 2022/09/25 17:19:05 thorpej Exp $");
40 
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/mbuf.h>
44 #include <sys/kernel.h>
45 #include <sys/socket.h>
46 #include <sys/ioctl.h>
47 #include <sys/errno.h>
48 #include <sys/device.h>
49 #include <sys/callout.h>
50 
51 #include <net/if.h>
52 #include <net/if_dl.h>
53 #include <net/if_media.h>
54 #include <net/if_ether.h>
55 
56 #include <net80211/ieee80211_netbsd.h>
57 #include <net80211/ieee80211_var.h>
58 
59 #include <sys/bus.h>
60 #include <sys/intr.h>
61 
62 #include <dev/ic/anreg.h>
63 #include <dev/ic/anvar.h>
64 
65 #include <dev/isa/isavar.h>
66 
67 #include <dev/isapnp/isapnpreg.h>
68 #include <dev/isapnp/isapnpvar.h>
69 #include <dev/isapnp/isapnpdevs.h>
70 
71 int	an_isapnp_match(device_t, cfdata_t, void *);
72 void	an_isapnp_attach(device_t, device_t, void *);
73 
74 struct an_isapnp_softc {
75 	struct an_softc sc_an;			/* real "an" softc */
76 
77 	/* ISA-specific goo. */
78 	void	*sc_ih;				/* interrupt cookie */
79 };
80 
81 CFATTACH_DECL_NEW(an_isapnp, sizeof(struct an_isapnp_softc),
82     an_isapnp_match, an_isapnp_attach, NULL, NULL);
83 
84 int
an_isapnp_match(device_t parent,cfdata_t match,void * aux)85 an_isapnp_match(device_t parent, cfdata_t match, void *aux)
86 {
87 	int pri, variant;
88 
89 	pri = isapnp_devmatch(aux, &isapnp_an_devinfo, &variant);
90 	if (pri && variant > 0)
91 		pri = 0;
92 	return (pri);
93 }
94 
95 void
an_isapnp_attach(device_t parent,device_t self,void * aux)96 an_isapnp_attach(device_t parent, device_t self, void *aux)
97 {
98 	struct an_isapnp_softc *isc = device_private(self);
99 	struct an_softc *sc = &isc->sc_an;
100 	struct isapnp_attach_args *ipa = aux;
101 
102 	printf("\n");
103 
104 	if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
105 		aprint_error_dev(self, "can't configure isapnp resources\n");
106 		return;
107 	}
108 
109 	sc->sc_dev = self;
110 	sc->sc_iot = ipa->ipa_iot;
111 	sc->sc_ioh = ipa->ipa_io[0].h;
112 
113 	printf("%s: %s %s\n", device_xname(self), ipa->ipa_devident,
114 	    ipa->ipa_devclass);
115 
116 	/* This interface is always enabled. */
117 	sc->sc_enabled = 1;
118 
119 	/* Establish the interrupt handler. */
120 	isc->sc_ih = isa_intr_establish(ipa->ipa_ic, ipa->ipa_irq[0].num,
121 	    ipa->ipa_irq[0].type, IPL_NET, an_intr, sc);
122 	if (isc->sc_ih == NULL) {
123 		aprint_error_dev(self,
124 		    "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