if_an_pci.c revision 1.1
1/*	$NetBSD: if_an_pci.c,v 1.1 2000/12/14 04:11:25 onoe 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 Atsushi Onoe.
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 * 3. All advertising materials mentioning features or use of this software
19 *    must display the following acknowledgement:
20 *	This product includes software developed by the NetBSD
21 *	Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 *    contributors may be used to endorse or promote products derived
24 *    from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39/*
40 * PCI bus front-end for the Aironet PC4500/PC4800 Wireless LAN Adapter.
41 * Unlike WaveLAN, this adapter attached as PCI device using a PLX 9050
42 * PCI to "dumb bus" bridge chip.
43 */
44
45#include "opt_inet.h"
46#include "opt_ns.h"
47#include "bpfilter.h"
48
49#ifdef INET
50#define	ANCACHE		/* XXX: should be defined elsewhere */
51#endif
52
53#include <sys/param.h>
54#include <sys/systm.h>
55#include <sys/mbuf.h>
56#include <sys/malloc.h>
57#include <sys/kernel.h>
58#include <sys/socket.h>
59#include <sys/ioctl.h>
60#include <sys/errno.h>
61#include <sys/device.h>
62#include <sys/callout.h>
63
64#include <machine/endian.h>
65
66#include <net/if.h>
67#include <net/if_dl.h>
68#include <net/if_media.h>
69#include <net/if_ether.h>
70
71#if NBPFILTER > 0
72#include <net/bpf.h>
73#endif
74
75#ifdef INET
76#include <netinet/in.h>
77#include <netinet/if_inarp.h>
78#endif
79
80#ifdef NS
81#include <netns/ns.h>
82#include <netns/ns_if.h>
83#endif
84
85#include <machine/bus.h>
86#include <machine/intr.h>
87
88#include <dev/ic/anreg.h>
89#include <dev/ic/anvar.h>
90
91#include <dev/pci/pcivar.h>
92#include <dev/pci/pcireg.h>
93#include <dev/pci/pcidevs.h>
94
95#define	AN_PCI_PLX_IOBA		0x14	/* i/o base for PLX chip */
96#define	AN_PCI_IOBA		0x18	/* i/o base */
97
98struct an_pci_softc {
99	struct an_softc sc_an;		/* real "an" softc */
100
101	/* PCI-specific goo. */
102	void	*sc_ih;			/* interrupt handle */
103};
104
105int	an_pci_match __P((struct device *, struct cfdata *, void *));
106void	an_pci_attach __P((struct device *, struct device *, void *));
107
108struct cfattach an_pci_ca = {
109	sizeof(struct an_pci_softc), an_pci_match, an_pci_attach,
110};
111
112const struct an_pci_product {
113	u_int32_t	app_vendor;	/* PCI vendor ID */
114	u_int32_t	app_product;	/* PCI product ID */
115} an_pci_products[] = {
116	{ PCI_VENDOR_AIRONET,		PCI_PRODUCT_AIRONET_PC4xxx },
117	{ PCI_VENDOR_AIRONET,		PCI_PRODUCT_AIRONET_PC4500 },
118	{ PCI_VENDOR_AIRONET,		PCI_PRODUCT_AIRONET_PC4800 },
119	{ 0,				0			   }
120};
121
122int
123an_pci_match(struct device *parent, struct cfdata *match, void *aux)
124{
125	struct pci_attach_args *pa = aux;
126	const struct an_pci_product *app;
127
128	for (app = an_pci_products; app->app_vendor != 0; app++) {
129		if (PCI_VENDOR(pa->pa_id) == app->app_vendor &&
130		    PCI_PRODUCT(pa->pa_id) == app->app_product)
131			return 1;
132	}
133	return 0;
134}
135
136void
137an_pci_attach(struct device *parent, struct device *self, void *aux)
138{
139        struct pci_attach_args *pa = (struct pci_attach_args *)aux;
140	struct an_pci_softc *psc = (struct an_pci_softc *) self;
141	struct an_softc *sc = &psc->sc_an;
142        char devinfo[256];
143	char const *intrstr;
144	pci_intr_handle_t ih;
145	u_int32_t csr;
146
147        pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
148        printf(": %s\n", devinfo);
149
150        /* Map I/O registers */
151        if (pci_mapreg_map(pa, AN_PCI_IOBA, PCI_MAPREG_TYPE_IO, 0,
152	    &sc->an_btag, &sc->an_bhandle, NULL, NULL) != 0) {
153                printf("%s: unable to map registers\n", self->dv_xname);
154                return;
155        }
156
157        /* Enable the device. */
158        csr = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
159        pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
160                       csr | PCI_COMMAND_MASTER_ENABLE);
161
162	/* Map and establish the interrupt. */
163	if (pci_intr_map(pa->pa_pc, pa->pa_intrtag, pa->pa_intrpin,
164	    pa->pa_intrline, &ih)) {
165        	printf("%s: unable to map interrupt\n", self->dv_xname);
166		return;
167	}
168	intrstr = pci_intr_string(pa->pa_pc, ih);
169	psc->sc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_NET, an_intr, sc);
170	if (psc->sc_ih == NULL) {
171		printf("%s: unable to establish interrupt", self->dv_xname);
172		if (intrstr != NULL)
173			printf(" at %s", intrstr);
174		printf("\n");
175		return;
176	}
177	printf("%s: interrupting at %s\n", self->dv_xname, intrstr);
178	sc->sc_enabled = 1;
179
180	if (an_attach(sc) != 0) {
181		printf("%s: failed to attach controller\n", self->dv_xname);
182		pci_intr_disestablish(pa->pa_pc, psc->sc_ih);
183		bus_space_unmap(sc->an_btag, sc->an_bhandle, AN_IOSIZ);
184	}
185}
186