if_an_pci.c revision 1.1
11.1Sonoe/* $NetBSD: if_an_pci.c,v 1.1 2000/12/14 04:11:25 onoe Exp $ */ 21.1Sonoe 31.1Sonoe/* 41.1Sonoe * Copyright (c) 2000 The NetBSD Foundation, Inc. 51.1Sonoe * All rights reserved. 61.1Sonoe * 71.1Sonoe * This code is derived from software contributed to The NetBSD Foundation 81.1Sonoe * by Atsushi Onoe. 91.1Sonoe * 101.1Sonoe * Redistribution and use in source and binary forms, with or without 111.1Sonoe * modification, are permitted provided that the following conditions 121.1Sonoe * are met: 131.1Sonoe * 1. Redistributions of source code must retain the above copyright 141.1Sonoe * notice, this list of conditions and the following disclaimer. 151.1Sonoe * 2. Redistributions in binary form must reproduce the above copyright 161.1Sonoe * notice, this list of conditions and the following disclaimer in the 171.1Sonoe * documentation and/or other materials provided with the distribution. 181.1Sonoe * 3. All advertising materials mentioning features or use of this software 191.1Sonoe * must display the following acknowledgement: 201.1Sonoe * This product includes software developed by the NetBSD 211.1Sonoe * Foundation, Inc. and its contributors. 221.1Sonoe * 4. Neither the name of The NetBSD Foundation nor the names of its 231.1Sonoe * contributors may be used to endorse or promote products derived 241.1Sonoe * from this software without specific prior written permission. 251.1Sonoe * 261.1Sonoe * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 271.1Sonoe * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 281.1Sonoe * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 291.1Sonoe * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 301.1Sonoe * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 311.1Sonoe * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 321.1Sonoe * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 331.1Sonoe * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 341.1Sonoe * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 351.1Sonoe * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 361.1Sonoe * POSSIBILITY OF SUCH DAMAGE. 371.1Sonoe */ 381.1Sonoe 391.1Sonoe/* 401.1Sonoe * PCI bus front-end for the Aironet PC4500/PC4800 Wireless LAN Adapter. 411.1Sonoe * Unlike WaveLAN, this adapter attached as PCI device using a PLX 9050 421.1Sonoe * PCI to "dumb bus" bridge chip. 431.1Sonoe */ 441.1Sonoe 451.1Sonoe#include "opt_inet.h" 461.1Sonoe#include "opt_ns.h" 471.1Sonoe#include "bpfilter.h" 481.1Sonoe 491.1Sonoe#ifdef INET 501.1Sonoe#define ANCACHE /* XXX: should be defined elsewhere */ 511.1Sonoe#endif 521.1Sonoe 531.1Sonoe#include <sys/param.h> 541.1Sonoe#include <sys/systm.h> 551.1Sonoe#include <sys/mbuf.h> 561.1Sonoe#include <sys/malloc.h> 571.1Sonoe#include <sys/kernel.h> 581.1Sonoe#include <sys/socket.h> 591.1Sonoe#include <sys/ioctl.h> 601.1Sonoe#include <sys/errno.h> 611.1Sonoe#include <sys/device.h> 621.1Sonoe#include <sys/callout.h> 631.1Sonoe 641.1Sonoe#include <machine/endian.h> 651.1Sonoe 661.1Sonoe#include <net/if.h> 671.1Sonoe#include <net/if_dl.h> 681.1Sonoe#include <net/if_media.h> 691.1Sonoe#include <net/if_ether.h> 701.1Sonoe 711.1Sonoe#if NBPFILTER > 0 721.1Sonoe#include <net/bpf.h> 731.1Sonoe#endif 741.1Sonoe 751.1Sonoe#ifdef INET 761.1Sonoe#include <netinet/in.h> 771.1Sonoe#include <netinet/if_inarp.h> 781.1Sonoe#endif 791.1Sonoe 801.1Sonoe#ifdef NS 811.1Sonoe#include <netns/ns.h> 821.1Sonoe#include <netns/ns_if.h> 831.1Sonoe#endif 841.1Sonoe 851.1Sonoe#include <machine/bus.h> 861.1Sonoe#include <machine/intr.h> 871.1Sonoe 881.1Sonoe#include <dev/ic/anreg.h> 891.1Sonoe#include <dev/ic/anvar.h> 901.1Sonoe 911.1Sonoe#include <dev/pci/pcivar.h> 921.1Sonoe#include <dev/pci/pcireg.h> 931.1Sonoe#include <dev/pci/pcidevs.h> 941.1Sonoe 951.1Sonoe#define AN_PCI_PLX_IOBA 0x14 /* i/o base for PLX chip */ 961.1Sonoe#define AN_PCI_IOBA 0x18 /* i/o base */ 971.1Sonoe 981.1Sonoestruct an_pci_softc { 991.1Sonoe struct an_softc sc_an; /* real "an" softc */ 1001.1Sonoe 1011.1Sonoe /* PCI-specific goo. */ 1021.1Sonoe void *sc_ih; /* interrupt handle */ 1031.1Sonoe}; 1041.1Sonoe 1051.1Sonoeint an_pci_match __P((struct device *, struct cfdata *, void *)); 1061.1Sonoevoid an_pci_attach __P((struct device *, struct device *, void *)); 1071.1Sonoe 1081.1Sonoestruct cfattach an_pci_ca = { 1091.1Sonoe sizeof(struct an_pci_softc), an_pci_match, an_pci_attach, 1101.1Sonoe}; 1111.1Sonoe 1121.1Sonoeconst struct an_pci_product { 1131.1Sonoe u_int32_t app_vendor; /* PCI vendor ID */ 1141.1Sonoe u_int32_t app_product; /* PCI product ID */ 1151.1Sonoe} an_pci_products[] = { 1161.1Sonoe { PCI_VENDOR_AIRONET, PCI_PRODUCT_AIRONET_PC4xxx }, 1171.1Sonoe { PCI_VENDOR_AIRONET, PCI_PRODUCT_AIRONET_PC4500 }, 1181.1Sonoe { PCI_VENDOR_AIRONET, PCI_PRODUCT_AIRONET_PC4800 }, 1191.1Sonoe { 0, 0 } 1201.1Sonoe}; 1211.1Sonoe 1221.1Sonoeint 1231.1Sonoean_pci_match(struct device *parent, struct cfdata *match, void *aux) 1241.1Sonoe{ 1251.1Sonoe struct pci_attach_args *pa = aux; 1261.1Sonoe const struct an_pci_product *app; 1271.1Sonoe 1281.1Sonoe for (app = an_pci_products; app->app_vendor != 0; app++) { 1291.1Sonoe if (PCI_VENDOR(pa->pa_id) == app->app_vendor && 1301.1Sonoe PCI_PRODUCT(pa->pa_id) == app->app_product) 1311.1Sonoe return 1; 1321.1Sonoe } 1331.1Sonoe return 0; 1341.1Sonoe} 1351.1Sonoe 1361.1Sonoevoid 1371.1Sonoean_pci_attach(struct device *parent, struct device *self, void *aux) 1381.1Sonoe{ 1391.1Sonoe struct pci_attach_args *pa = (struct pci_attach_args *)aux; 1401.1Sonoe struct an_pci_softc *psc = (struct an_pci_softc *) self; 1411.1Sonoe struct an_softc *sc = &psc->sc_an; 1421.1Sonoe char devinfo[256]; 1431.1Sonoe char const *intrstr; 1441.1Sonoe pci_intr_handle_t ih; 1451.1Sonoe u_int32_t csr; 1461.1Sonoe 1471.1Sonoe pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo); 1481.1Sonoe printf(": %s\n", devinfo); 1491.1Sonoe 1501.1Sonoe /* Map I/O registers */ 1511.1Sonoe if (pci_mapreg_map(pa, AN_PCI_IOBA, PCI_MAPREG_TYPE_IO, 0, 1521.1Sonoe &sc->an_btag, &sc->an_bhandle, NULL, NULL) != 0) { 1531.1Sonoe printf("%s: unable to map registers\n", self->dv_xname); 1541.1Sonoe return; 1551.1Sonoe } 1561.1Sonoe 1571.1Sonoe /* Enable the device. */ 1581.1Sonoe csr = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG); 1591.1Sonoe pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, 1601.1Sonoe csr | PCI_COMMAND_MASTER_ENABLE); 1611.1Sonoe 1621.1Sonoe /* Map and establish the interrupt. */ 1631.1Sonoe if (pci_intr_map(pa->pa_pc, pa->pa_intrtag, pa->pa_intrpin, 1641.1Sonoe pa->pa_intrline, &ih)) { 1651.1Sonoe printf("%s: unable to map interrupt\n", self->dv_xname); 1661.1Sonoe return; 1671.1Sonoe } 1681.1Sonoe intrstr = pci_intr_string(pa->pa_pc, ih); 1691.1Sonoe psc->sc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_NET, an_intr, sc); 1701.1Sonoe if (psc->sc_ih == NULL) { 1711.1Sonoe printf("%s: unable to establish interrupt", self->dv_xname); 1721.1Sonoe if (intrstr != NULL) 1731.1Sonoe printf(" at %s", intrstr); 1741.1Sonoe printf("\n"); 1751.1Sonoe return; 1761.1Sonoe } 1771.1Sonoe printf("%s: interrupting at %s\n", self->dv_xname, intrstr); 1781.1Sonoe sc->sc_enabled = 1; 1791.1Sonoe 1801.1Sonoe if (an_attach(sc) != 0) { 1811.1Sonoe printf("%s: failed to attach controller\n", self->dv_xname); 1821.1Sonoe pci_intr_disestablish(pa->pa_pc, psc->sc_ih); 1831.1Sonoe bus_space_unmap(sc->an_btag, sc->an_bhandle, AN_IOSIZ); 1841.1Sonoe } 1851.1Sonoe} 186