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/module.h>
52#include <sys/bus.h>
53
54#include <machine/bus.h>
55#include <machine/resource.h>
56#include <sys/rman.h>
57
58#include <dev/ofw/ofw_bus.h>
59#include <dev/ofw/openfirm.h>
60#include <machine/ofw_machdep.h>
61
62#include <net/if.h>
63#include <net/if_arp.h>
64#include <net/ethernet.h>
65#include <net/if_dl.h>
66#include <net/if_media.h>
67#include <net/if_types.h>
68
69#include <net80211/ieee80211_var.h>
70#include <net80211/ieee80211_radiotap.h>
71
72#include <dev/wi/if_wavelan_ieee.h>
73#include <dev/wi/if_wireg.h>
74#include <dev/wi/if_wivar.h>
75
76static int wi_macio_probe(device_t);
77static int wi_macio_attach(device_t);
78
79static device_method_t wi_macio_methods[] = {
80	/* Device interface */
81	DEVMETHOD(device_probe,		wi_macio_probe),
82	DEVMETHOD(device_attach,	wi_macio_attach),
83	DEVMETHOD(device_detach,	wi_detach),
84	DEVMETHOD(device_shutdown,	wi_shutdown),
85
86	{ 0, 0 }
87};
88
89static driver_t wi_macio_driver = {
90	"wi",
91	wi_macio_methods,
92	sizeof(struct wi_softc)
93};
94
95DRIVER_MODULE(wi, macio, wi_macio_driver, wi_devclass, 0, 0);
96MODULE_DEPEND(wi, wlan, 1, 1, 1);
97
98static int
99wi_macio_probe(device_t dev)
100{
101	const char *name, *compat;
102
103	/* Make sure we're a network driver */
104	name = ofw_bus_get_name(dev);
105	if (name == NULL)
106		return (ENXIO);
107
108	if (strcmp(name, "radio") != 0) {
109		return ENXIO;
110	}
111	compat = ofw_bus_get_compat(dev);
112	if (strcmp(compat, "wireless") != 0) {
113		return ENXIO;
114	}
115
116	device_set_desc(dev, "Apple Airport");
117	return 0;
118}
119
120static int
121wi_macio_attach(device_t dev)
122{
123	struct wi_softc	*sc;
124	int error;
125
126	sc = device_get_softc(dev);
127	sc->wi_gone = 0;
128	sc->wi_bus_type = 0;
129
130	error = wi_alloc(dev, 0);
131	if (error == 0) {
132		/* Make sure interrupts are disabled. */
133		CSR_WRITE_2(sc, WI_INT_EN, 0);
134		CSR_WRITE_2(sc, WI_EVENT_ACK, 0xFFFF);
135
136		error = wi_attach(dev);
137		if (error != 0)
138			wi_free(dev);
139	}
140	return error;
141}
142