if_an_pci.c revision 67096
150276Speter/*
276726Speter * Copyright (c) 1997, 1998, 1999
350276Speter *	Bill Paul <wpaul@ctr.columbia.edu>.  All rights reserved.
450276Speter *
550276Speter * Redistribution and use in source and binary forms, with or without
650276Speter * modification, are permitted provided that the following conditions
750276Speter * are met:
850276Speter * 1. Redistributions of source code must retain the above copyright
950276Speter *    notice, this list of conditions and the following disclaimer.
1050276Speter * 2. Redistributions in binary form must reproduce the above copyright
1150276Speter *    notice, this list of conditions and the following disclaimer in the
1250276Speter *    documentation and/or other materials provided with the distribution.
1350276Speter * 3. All advertising materials mentioning features or use of this software
1450276Speter *    must display the following acknowledgement:
1550276Speter *	This product includes software developed by Bill Paul.
1650276Speter * 4. Neither the name of the author nor the names of any co-contributors
1750276Speter *    may be used to endorse or promote products derived from this software
1850276Speter *    without specific prior written permission.
1950276Speter *
2050276Speter * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
2150276Speter * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2250276Speter * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2350276Speter * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
2450276Speter * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2550276Speter * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2650276Speter * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2750276Speter * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2850276Speter * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2950276Speter * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
3050276Speter * THE POSSIBILITY OF SUCH DAMAGE.
3150276Speter *
3250276Speter * $FreeBSD: head/sys/dev/an/if_an_pci.c 67096 2000-10-13 22:04:20Z wpaul $
3350276Speter */
3450276Speter
3550276Speter/*
3650276Speter * This is a PCI shim for the Aironet PC4500/4800 wireless network
3750276Speter * driver. Aironet makes PCMCIA, ISA and PCI versions of these devices,
3850276Speter * which all have basically the same interface. The ISA and PCI cards
3950276Speter * are actually bridge adapters with PCMCIA cards inserted into them,
4076726Speter * however they appear as normal PCI or ISA devices to the host.
4150276Speter *
4250276Speter * All we do here is handle the PCI probe and attach and set up an
4350276Speter * interrupt handler entry point. The PCI version of the card uses
4450276Speter * a PLX 9050 PCI to "dumb bus" bridge chip, which provides us with
4550276Speter * multiple PCI address space mappings. The primary mapping at PCI
4650276Speter * register 0x14 is for the PLX chip itself, *NOT* the Aironet card.
4750276Speter * The I/O address of the Aironet is actually at register 0x18, which
4850276Speter * is the local bus mapping register for bus space 0. There are also
4950276Speter * registers for additional register spaces at registers 0x1C and
5050276Speter * 0x20, but these are unused in the Aironet devices. To find out
5150276Speter * more, you need a datasheet for the 9050 from PLX, but you have
5276726Speter * to go through their sales office to get it. Bleh.
5376726Speter */
5450276Speter
5550276Speter#include "opt_inet.h"
5650276Speter
5750276Speter#ifdef INET
5850276Speter#define ANCACHE
5950276Speter#endif
6050276Speter
6150276Speter#include <sys/param.h>
6250276Speter#include <sys/systm.h>
6350276Speter#include <sys/sockio.h>
6450276Speter#include <sys/mbuf.h>
6550276Speter#include <sys/kernel.h>
6650276Speter#include <sys/socket.h>
6750276Speter
68#include <sys/module.h>
69#include <sys/bus.h>
70#include <machine/bus.h>
71#include <sys/rman.h>
72#include <machine/mutex.h>
73#include <machine/resource.h>
74
75#include <net/if.h>
76#include <net/if_arp.h>
77#include <net/ethernet.h>
78#include <net/if_dl.h>
79
80#include <pci/pcireg.h>
81#include <pci/pcivar.h>
82
83#ifndef lint
84static const char rcsid[] =
85 "$FreeBSD: head/sys/dev/an/if_an_pci.c 67096 2000-10-13 22:04:20Z wpaul $";
86#endif
87
88#include <dev/an/if_aironet_ieee.h>
89#include <dev/an/if_anreg.h>
90
91struct an_type {
92	u_int16_t		an_vid;
93	u_int16_t		an_did;
94	char			*an_name;
95};
96
97#define AIRONET_VENDORID	0x14B9
98#define AIRONET_DEVICEID_4500	0x4500
99#define AIRONET_DEVICEID_4800	0x4800
100#define AIRONET_DEVICEID_4xxx	0x0001
101#define AN_PCI_PLX_LOIO		0x14	/* PLX chip iobase */
102#define AN_PCI_LOIO		0x18	/* Aironet iobase */
103
104static struct an_type an_devs[] = {
105	{ AIRONET_VENDORID, AIRONET_DEVICEID_4500, "Aironet PCI4500" },
106	{ AIRONET_VENDORID, AIRONET_DEVICEID_4800, "Aironet PCI4800" },
107	{ AIRONET_VENDORID, AIRONET_DEVICEID_4xxx, "Aironet PCI4500/PCI4800" },
108	{ 0, 0, NULL }
109};
110
111static int an_probe_pci		__P((device_t));
112static int an_attach_pci	__P((device_t));
113static int an_detach_pci	__P((device_t));
114
115static int an_probe_pci(device_t dev)
116{
117	struct an_type		*t;
118
119	t = an_devs;
120
121	while(t->an_name != NULL) {
122		if (pci_get_vendor(dev) == t->an_vid &&
123		    pci_get_device(dev) == t->an_did) {
124			device_set_desc(dev, t->an_name);
125			return(0);
126		}
127		t++;
128	}
129
130	return(ENXIO);
131}
132
133static int an_attach_pci(dev)
134	device_t		dev;
135{
136	u_int32_t		command;
137	struct an_softc		*sc;
138	int 			unit, flags, error = 0;
139
140	sc = device_get_softc(dev);
141	unit = device_get_unit(dev);
142	flags = device_get_flags(dev);
143	bzero(sc, sizeof(struct an_softc));
144
145	/*
146	 * Map control/status registers.
147 	 */
148	command = pci_read_config(dev, PCIR_COMMAND, 4);
149	command |= PCIM_CMD_PORTEN;
150	pci_write_config(dev, PCIR_COMMAND, command, 4);
151	command = pci_read_config(dev, PCIR_COMMAND, 4);
152
153	if (!(command & PCIM_CMD_PORTEN)) {
154		printf("an%d: failed to enable I/O ports!\n", unit);
155		error = ENXIO;
156		goto fail;
157	}
158
159	sc->port_rid = AN_PCI_LOIO;
160	error = an_alloc_port(dev, sc->port_rid, 1);
161
162	if (error) {
163		printf("an%d: couldn't map ports\n", unit);
164		goto fail;
165	}
166
167	sc->an_btag = rman_get_bustag(sc->port_res);
168	sc->an_bhandle = rman_get_bushandle(sc->port_res);
169
170	/* Allocate interrupt */
171	error = an_alloc_irq(dev, 0, RF_SHAREABLE);
172	if (error) {
173		an_release_resources(dev);
174		goto fail;
175        }
176
177	error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET,
178	    an_intr, sc, &sc->irq_handle);
179	if (error) {
180		an_release_resources(dev);
181		goto fail;
182	}
183
184	sc->an_dev = dev;
185	error = an_attach(sc, device_get_unit(dev), flags);
186
187fail:
188	return(error);
189}
190
191static int
192an_detach_pci(device_t dev)
193{
194	struct an_softc		*sc = device_get_softc(dev);
195	struct ifnet		*ifp = &sc->arpcom.ac_if;
196
197	an_stop(sc);
198	ether_ifdetach(ifp, ETHER_BPF_SUPPORTED);
199	bus_teardown_intr(dev, sc->irq_res, sc->irq_handle);
200	an_release_resources(dev);
201
202	return (0);
203}
204
205static device_method_t an_pci_methods[] = {
206        /* Device interface */
207        DEVMETHOD(device_probe,         an_probe_pci),
208        DEVMETHOD(device_attach,        an_attach_pci),
209	DEVMETHOD(device_detach,	an_detach_pci),
210	DEVMETHOD(device_shutdown,	an_shutdown),
211        { 0, 0 }
212};
213
214static driver_t an_pci_driver = {
215        "an",
216        an_pci_methods,
217        sizeof(struct an_softc),
218};
219
220static devclass_t an_devclass;
221
222DRIVER_MODULE(if_an, pci, an_pci_driver, an_devclass, 0, 0);
223