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