]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/wi/if_wi_macio.c
- Switch releng/11.3 to -RELEASE.
[FreeBSD/FreeBSD.git] / sys / dev / wi / if_wi_macio.c
1 /*-
2  * Copyright (c) 2013   Justin Hibbits
3  * All rights reserved.
4  * Copyright (c) 1997, 1998, 1999
5  *      Bill Paul <wpaul@ctr.columbia.edu>.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *      This product includes software developed by Bill Paul.
18  * 4. Neither the name of the author nor the names of any co-contributors
19  *    may be used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
26  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32  * THE POSSIBILITY OF SUCH DAMAGE.
33  */
34
35 /*
36  * Lucent WaveLAN/IEEE 802.11 MacIO attachment for FreeBSD.
37  *
38  * Based on the PCMCIA driver
39  * Written by Bill Paul <wpaul@ctr.columbia.edu>
40  * Electrical Engineering Department
41  * Columbia University, New York City
42  */
43
44 #include <sys/cdefs.h>
45 __FBSDID("$FreeBSD$");
46
47 #include <sys/param.h>
48 #include <sys/kernel.h>
49 #include <sys/socket.h>
50 #include <sys/systm.h>
51 #include <sys/mbuf.h>
52 #include <sys/module.h>
53 #include <sys/bus.h>
54
55 #include <machine/bus.h>
56 #include <machine/resource.h>
57 #include <sys/rman.h>
58
59 #include <dev/ofw/ofw_bus.h>
60 #include <dev/ofw/openfirm.h>
61 #include <machine/ofw_machdep.h>
62
63 #include <net/if.h>
64 #include <net/if_arp.h>
65 #include <net/ethernet.h>
66 #include <net/if_dl.h>
67 #include <net/if_media.h>
68 #include <net/if_types.h>
69
70 #include <net80211/ieee80211_var.h>
71 #include <net80211/ieee80211_radiotap.h>
72
73 #include <dev/wi/if_wavelan_ieee.h>
74 #include <dev/wi/if_wireg.h>
75 #include <dev/wi/if_wivar.h>
76
77 #include <powerpc/powermac/maciovar.h>
78
79 static int wi_macio_probe(device_t);
80 static int wi_macio_attach(device_t);
81
82 static device_method_t wi_macio_methods[] = {
83         /* Device interface */
84         DEVMETHOD(device_probe,         wi_macio_probe),
85         DEVMETHOD(device_attach,        wi_macio_attach),
86         DEVMETHOD(device_detach,        wi_detach),
87         DEVMETHOD(device_shutdown,      wi_shutdown),
88
89         { 0, 0 }
90 };
91
92 static driver_t wi_macio_driver = {
93         "wi",
94         wi_macio_methods,
95         sizeof(struct wi_softc)
96 };
97
98 DRIVER_MODULE(wi, macio, wi_macio_driver, wi_devclass, 0, 0);
99 MODULE_DEPEND(wi, wlan, 1, 1, 1);
100
101 static int
102 wi_macio_probe(device_t dev)
103 {
104         const char *name, *compat;
105
106         /* Make sure we're a network driver */
107         name = ofw_bus_get_name(dev);
108         if (name == NULL)
109                 return (ENXIO);
110
111         if (strcmp(name, "radio") != 0) {
112                 return ENXIO;
113         }
114         compat = ofw_bus_get_compat(dev);
115         if (strcmp(compat, "wireless") != 0) {
116                 return ENXIO;
117         }
118
119         device_set_desc(dev, "Apple Airport");
120         return 0;
121 }
122
123 static int
124 wi_macio_attach(device_t dev)
125 {
126         struct wi_softc *sc;
127         int error;
128
129         sc = device_get_softc(dev);
130         sc->wi_gone = 0;
131         sc->wi_bus_type = 0;
132
133         error = wi_alloc(dev, 0);
134         if (error == 0) {
135                 macio_enable_wireless(device_get_parent(dev), 1);
136                 /* Make sure interrupts are disabled. */
137                 CSR_WRITE_2(sc, WI_INT_EN, 0);
138                 CSR_WRITE_2(sc, WI_EVENT_ACK, 0xFFFF);
139
140                 error = wi_attach(dev);
141                 if (error != 0)
142                         wi_free(dev);
143         }
144         return error;
145 }