if_an_pci.c revision 77217
1169691Skan/* 2169691Skan * Copyright (c) 1997, 1998, 1999 3169691Skan * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved. 4169691Skan * 5169691Skan * Redistribution and use in source and binary forms, with or without 6169691Skan * modification, are permitted provided that the following conditions 7169691Skan * are met: 8169691Skan * 1. Redistributions of source code must retain the above copyright 9169691Skan * notice, this list of conditions and the following disclaimer. 10169691Skan * 2. Redistributions in binary form must reproduce the above copyright 11169691Skan * notice, this list of conditions and the following disclaimer in the 12169691Skan * documentation and/or other materials provided with the distribution. 13169691Skan * 3. All advertising materials mentioning features or use of this software 14169691Skan * must display the following acknowledgement: 15169691Skan * This product includes software developed by Bill Paul. 16169691Skan * 4. Neither the name of the author nor the names of any co-contributors 17169691Skan * may be used to endorse or promote products derived from this software 18169691Skan * without specific prior written permission. 19169691Skan * 20169691Skan * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND 21169691Skan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22169691Skan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23169691Skan * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD 24169691Skan * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25169691Skan * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26169691Skan * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27169691Skan * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28169691Skan * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29169691Skan * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 30169691Skan * THE POSSIBILITY OF SUCH DAMAGE. 31169691Skan * 32169691Skan * $FreeBSD: head/sys/dev/an/if_an_pci.c 77217 2001-05-26 09:27:08Z phk $ 33169691Skan */ 34169691Skan 35169691Skan/* 36169691Skan * This is a PCI shim for the Aironet PC4500/4800 wireless network 37169691Skan * driver. Aironet makes PCMCIA, ISA and PCI versions of these devices, 38169691Skan * which all have basically the same interface. The ISA and PCI cards 39169691Skan * are actually bridge adapters with PCMCIA cards inserted into them, 40169691Skan * however they appear as normal PCI or ISA devices to the host. 41169691Skan * 42169691Skan * All we do here is handle the PCI probe and attach and set up an 43169691Skan * interrupt handler entry point. The PCI version of the card uses 44169691Skan * a PLX 9050 PCI to "dumb bus" bridge chip, which provides us with 45169691Skan * multiple PCI address space mappings. The primary mapping at PCI 46169691Skan * register 0x14 is for the PLX chip itself, *NOT* the Aironet card. 47169691Skan * The I/O address of the Aironet is actually at register 0x18, which 48169691Skan * is the local bus mapping register for bus space 0. There are also 49169691Skan * registers for additional register spaces at registers 0x1C and 50169691Skan * 0x20, but these are unused in the Aironet devices. To find out 51169691Skan * more, you need a datasheet for the 9050 from PLX, but you have 52169691Skan * to go through their sales office to get it. Bleh. 53169691Skan */ 54169691Skan 55169691Skan#include "opt_inet.h" 56169691Skan 57169691Skan#ifdef INET 58169691Skan#define ANCACHE 59169691Skan#endif 60169691Skan 61169691Skan#include <sys/param.h> 62169691Skan#include <sys/systm.h> 63169691Skan#include <sys/sockio.h> 64169691Skan#include <sys/mbuf.h> 65169691Skan#include <sys/kernel.h> 66169691Skan#include <sys/socket.h> 67169691Skan 68169691Skan#include <sys/module.h> 69169691Skan#include <sys/bus.h> 70169691Skan#include <machine/bus.h> 71169691Skan#include <sys/rman.h> 72169691Skan#include <sys/mutex.h> 73169691Skan#include <machine/resource.h> 74169691Skan 75169691Skan#include <net/if.h> 76169691Skan#include <net/if_arp.h> 77169691Skan#include <net/ethernet.h> 78169691Skan#include <net/if_dl.h> 79169691Skan#include <net/if_media.h> 80169691Skan 81169691Skan#include <pci/pcireg.h> 82169691Skan#include <pci/pcivar.h> 83169691Skan 84169691Skan#ifndef lint 85169691Skanstatic const char rcsid[] = 86169691Skan "$FreeBSD: head/sys/dev/an/if_an_pci.c 77217 2001-05-26 09:27:08Z phk $"; 87169691Skan#endif 88169691Skan 89169691Skan#include <dev/an/if_aironet_ieee.h> 90169691Skan#include <dev/an/if_anreg.h> 91169691Skan 92169691Skanstruct an_type { 93169691Skan u_int16_t an_vid; 94169691Skan u_int16_t an_did; 95169691Skan char *an_name; 96169691Skan}; 97169691Skan 98169691Skan#define AIRONET_VENDORID 0x14B9 99169691Skan#define AIRONET_DEVICEID_4500 0x4500 100169691Skan#define AIRONET_DEVICEID_4800 0x4800 101169691Skan#define AIRONET_DEVICEID_4xxx 0x0001 102169691Skan#define AN_PCI_PLX_LOIO 0x14 /* PLX chip iobase */ 103169691Skan#define AN_PCI_LOIO 0x18 /* Aironet iobase */ 104169691Skan 105169691Skanstatic struct an_type an_devs[] = { 106169691Skan { AIRONET_VENDORID, AIRONET_DEVICEID_4500, "Aironet PCI4500" }, 107169691Skan { AIRONET_VENDORID, AIRONET_DEVICEID_4800, "Aironet PCI4800" }, 108169691Skan { AIRONET_VENDORID, AIRONET_DEVICEID_4xxx, "Aironet PCI4500/PCI4800" }, 109169691Skan { 0, 0, NULL } 110169691Skan}; 111169691Skan 112169691Skanstatic int an_probe_pci __P((device_t)); 113169691Skanstatic int an_attach_pci __P((device_t)); 114169691Skanstatic int an_detach_pci __P((device_t)); 115169691Skan 116169691Skanstatic int an_probe_pci(device_t dev) 117169691Skan{ 118169691Skan struct an_type *t; 119169691Skan 120169691Skan t = an_devs; 121169691Skan 122169691Skan while(t->an_name != NULL) { 123169691Skan if (pci_get_vendor(dev) == t->an_vid && 124169691Skan pci_get_device(dev) == t->an_did) { 125169691Skan device_set_desc(dev, t->an_name); 126169691Skan return(0); 127169691Skan } 128169691Skan t++; 129169691Skan } 130169691Skan 131169691Skan return(ENXIO); 132169691Skan} 133169691Skan 134169691Skanstatic int an_attach_pci(dev) 135169691Skan device_t dev; 136169691Skan{ 137169691Skan u_int32_t command; 138169691Skan struct an_softc *sc; 139169691Skan int unit, flags, error = 0; 140169691Skan 141169691Skan sc = device_get_softc(dev); 142169691Skan unit = device_get_unit(dev); 143169691Skan flags = device_get_flags(dev); 144169691Skan bzero(sc, sizeof(struct an_softc)); 145169691Skan 146169691Skan /* 147169691Skan * Map control/status registers. 148169691Skan */ 149169691Skan command = pci_read_config(dev, PCIR_COMMAND, 4); 150169691Skan command |= PCIM_CMD_PORTEN; 151169691Skan pci_write_config(dev, PCIR_COMMAND, command, 4); 152169691Skan command = pci_read_config(dev, PCIR_COMMAND, 4); 153169691Skan 154169691Skan if (!(command & PCIM_CMD_PORTEN)) { 155169691Skan printf("an%d: failed to enable I/O ports!\n", unit); 156169691Skan error = ENXIO; 157169691Skan goto fail; 158169691Skan } 159169691Skan 160169691Skan sc->port_rid = AN_PCI_LOIO; 161169691Skan error = an_alloc_port(dev, sc->port_rid, 1); 162169691Skan 163169691Skan if (error) { 164169691Skan printf("an%d: couldn't map ports\n", unit); 165169691Skan goto fail; 166169691Skan } 167169691Skan 168169691Skan sc->an_btag = rman_get_bustag(sc->port_res); 169169691Skan sc->an_bhandle = rman_get_bushandle(sc->port_res); 170169691Skan 171169691Skan /* Allocate interrupt */ 172169691Skan error = an_alloc_irq(dev, 0, RF_SHAREABLE); 173169691Skan if (error) { 174169691Skan an_release_resources(dev); 175169691Skan goto fail; 176169691Skan } 177169691Skan 178169691Skan error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET, 179169691Skan an_intr, sc, &sc->irq_handle); 180169691Skan if (error) { 181169691Skan an_release_resources(dev); 182169691Skan goto fail; 183169691Skan } 184169691Skan 185169691Skan sc->an_dev = dev; 186169691Skan error = an_attach(sc, device_get_unit(dev), flags); 187169691Skan 188169691Skanfail: 189169691Skan return(error); 190169691Skan} 191169691Skan 192169691Skanstatic int 193169691Skanan_detach_pci(device_t dev) 194169691Skan{ 195169691Skan struct an_softc *sc = device_get_softc(dev); 196169691Skan struct ifnet *ifp = &sc->arpcom.ac_if; 197169691Skan 198169691Skan an_stop(sc); 199169691Skan ifmedia_removeall(&sc->an_ifmedia); 200169691Skan ether_ifdetach(ifp, ETHER_BPF_SUPPORTED); 201169691Skan bus_teardown_intr(dev, sc->irq_res, sc->irq_handle); 202169691Skan an_release_resources(dev); 203169691Skan 204169691Skan return (0); 205169691Skan} 206169691Skan 207169691Skanstatic device_method_t an_pci_methods[] = { 208169691Skan /* Device interface */ 209169691Skan DEVMETHOD(device_probe, an_probe_pci), 210169691Skan DEVMETHOD(device_attach, an_attach_pci), 211169691Skan DEVMETHOD(device_detach, an_detach_pci), 212169691Skan DEVMETHOD(device_shutdown, an_shutdown), 213169691Skan { 0, 0 } 214169691Skan}; 215169691Skan 216169691Skanstatic driver_t an_pci_driver = { 217169691Skan "an", 218169691Skan an_pci_methods, 219169691Skan sizeof(struct an_softc), 220169691Skan}; 221169691Skan 222169691Skanstatic devclass_t an_devclass; 223169691Skan 224169691SkanDRIVER_MODULE(if_an, pci, an_pci_driver, an_devclass, 0, 0); 225169691Skan