if_an_pci.c revision 113316
1/* 2 * Copyright (c) 1997, 1998, 1999 3 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. All advertising materials mentioning features or use of this software 14 * must display the following acknowledgement: 15 * This product includes software developed by Bill Paul. 16 * 4. Neither the name of the author nor the names of any co-contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 30 * THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33/* 34 * This is a PCI shim for the Aironet PC4500/4800 wireless network 35 * driver. Aironet makes PCMCIA, ISA and PCI versions of these devices, 36 * which all have basically the same interface. The ISA and PCI cards 37 * are actually bridge adapters with PCMCIA cards inserted into them, 38 * however they appear as normal PCI or ISA devices to the host. 39 * 40 * All we do here is handle the PCI probe and attach and set up an 41 * interrupt handler entry point. The PCI version of the card uses 42 * a PLX 9050 PCI to "dumb bus" bridge chip, which provides us with 43 * multiple PCI address space mappings. The primary mapping at PCI 44 * register 0x14 is for the PLX chip itself, *NOT* the Aironet card. 45 * The I/O address of the Aironet is actually at register 0x18, which 46 * is the local bus mapping register for bus space 0. There are also 47 * registers for additional register spaces at registers 0x1C and 48 * 0x20, but these are unused in the Aironet devices. To find out 49 * more, you need a datasheet for the 9050 from PLX, but you have 50 * to go through their sales office to get it. Bleh. 51 */ 52 53#include <sys/cdefs.h> 54__FBSDID("$FreeBSD: head/sys/dev/an/if_an_pci.c 113316 2003-04-10 05:12:45Z imp $"); 55 56#include "opt_inet.h" 57 58#ifdef INET 59#define ANCACHE 60#endif 61 62#include <sys/param.h> 63#include <sys/systm.h> 64#include <sys/sockio.h> 65#include <sys/mbuf.h> 66#include <sys/kernel.h> 67#include <sys/socket.h> 68 69#include <sys/module.h> 70#include <sys/bus.h> 71#include <machine/bus.h> 72#include <sys/rman.h> 73#include <sys/lock.h> 74#include <sys/mutex.h> 75#include <machine/resource.h> 76 77#include <net/if.h> 78#include <net/if_arp.h> 79#include <net/ethernet.h> 80#include <net/if_dl.h> 81#include <net/if_media.h> 82 83#include <pci/pcireg.h> 84#include <pci/pcivar.h> 85 86#include <dev/an/if_aironet_ieee.h> 87#include <dev/an/if_anreg.h> 88 89struct an_type { 90 u_int16_t an_vid; 91 u_int16_t an_did; 92 char *an_name; 93}; 94 95#define AIRONET_VENDORID 0x14B9 96#define AIRONET_DEVICEID_35x 0x0350 97#define AIRONET_DEVICEID_4500 0x4500 98#define AIRONET_DEVICEID_4800 0x4800 99#define AIRONET_DEVICEID_4xxx 0x0001 100#define AIRONET_DEVICEID_MPI350 0xA504 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_35x, "Cisco Aironet 350 Series" }, 106 { AIRONET_VENDORID, AIRONET_DEVICEID_4500, "Aironet PCI4500" }, 107 { AIRONET_VENDORID, AIRONET_DEVICEID_4800, "Aironet PCI4800" }, 108 { AIRONET_VENDORID, AIRONET_DEVICEID_4xxx, "Aironet PCI4500/PCI4800" }, 109 { 0, 0, NULL } 110}; 111 112static int an_probe_pci (device_t); 113static int an_attach_pci (device_t); 114static int an_detach_pci (device_t); 115static int an_suspend_pci (device_t); 116static int an_resume_pci (device_t); 117 118static int 119an_probe_pci(device_t dev) 120{ 121 struct an_type *t; 122 123 t = an_devs; 124 125 while (t->an_name != NULL) { 126 if (pci_get_vendor(dev) == t->an_vid && 127 pci_get_device(dev) == t->an_did) { 128 device_set_desc(dev, t->an_name); 129 return(0); 130 } 131 t++; 132 } 133 134 if (pci_get_vendor(dev) == AIRONET_VENDORID && 135 pci_get_device(dev) == AIRONET_DEVICEID_MPI350) { 136 device_set_desc(dev, "Cisco Aironet MPI350"); 137 return(0); 138 } 139 140 return(ENXIO); 141} 142 143static int 144an_attach_pci(dev) 145 device_t dev; 146{ 147 u_int32_t command; 148 struct an_softc *sc; 149 int unit, flags, error = 0; 150 151 sc = device_get_softc(dev); 152 unit = device_get_unit(dev); 153 flags = device_get_flags(dev); 154 bzero(sc, sizeof(struct an_softc)); 155 156 if (pci_get_vendor(dev) == AIRONET_VENDORID && 157 pci_get_device(dev) == AIRONET_DEVICEID_MPI350) { 158 sc->mpi350 = 1; 159 sc->port_rid = PCIR_MAPS; 160 } else { 161 /* 162 * Map control/status registers. 163 */ 164 command = pci_read_config(dev, PCIR_COMMAND, 4); 165 command |= PCIM_CMD_PORTEN; 166 pci_write_config(dev, PCIR_COMMAND, command, 4); 167 command = pci_read_config(dev, PCIR_COMMAND, 4); 168 169 if (!(command & PCIM_CMD_PORTEN)) { 170 printf("an%d: failed to enable I/O ports!\n", unit); 171 error = ENXIO; 172 goto fail; 173 } 174 sc->port_rid = AN_PCI_LOIO; 175 } 176 error = an_alloc_port(dev, sc->port_rid, 1); 177 178 if (error) { 179 printf("an%d: couldn't map ports\n", unit); 180 goto fail; 181 } 182 183 sc->an_btag = rman_get_bustag(sc->port_res); 184 sc->an_bhandle = rman_get_bushandle(sc->port_res); 185 186 /* Allocate memory for MPI350 */ 187 if (sc->mpi350) { 188 /* Allocate memory */ 189 sc->mem_rid = PCIR_MAPS + 4; 190 error = an_alloc_memory(dev, sc->mem_rid, 1); 191 if (error) { 192 printf("an%d: couldn't map memory\n", unit); 193 goto fail; 194 } 195 sc->an_mem_btag = rman_get_bustag(sc->mem_res); 196 sc->an_mem_bhandle = rman_get_bushandle(sc->mem_res); 197 198 /* Allocate aux. memory */ 199 sc->mem_aux_rid = PCIR_MAPS + 8; 200 error = an_alloc_aux_memory(dev, sc->mem_aux_rid, 201 AN_AUXMEMSIZE); 202 if (error) { 203 printf("an%d: couldn't map aux memory\n", unit); 204 goto fail; 205 } 206 sc->an_mem_aux_btag = rman_get_bustag(sc->mem_aux_res); 207 sc->an_mem_aux_bhandle = rman_get_bushandle(sc->mem_aux_res); 208 209 /* Allocate DMA region */ 210 error = bus_dma_tag_create(NULL, /* parent */ 211 1, 0, /* alignment, bounds */ 212 BUS_SPACE_MAXADDR_32BIT, /* lowaddr */ 213 BUS_SPACE_MAXADDR, /* highaddr */ 214 NULL, NULL, /* filter, filterarg */ 215 0x3ffff, /* maxsize XXX */ 216 1, /* nsegments */ 217 0xffff, /* maxsegsize XXX */ 218 BUS_DMA_ALLOCNOW, /* flags */ 219 &sc->an_dtag); 220 if (error) { 221 printf("an%d: couldn't get DMA region\n", unit); 222 goto fail; 223 } 224 } 225 226 /* Allocate interrupt */ 227 error = an_alloc_irq(dev, 0, RF_SHAREABLE); 228 if (error) { 229 goto fail; 230 } 231 232 sc->an_dev = dev; 233 error = an_attach(sc, device_get_unit(dev), flags); 234 if (error) { 235 goto fail; 236 } 237 238 /* 239 * Must setup the interrupt after the an_attach to prevent racing. 240 */ 241 error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET, 242 an_intr, sc, &sc->irq_handle); 243 244fail: 245 if (error) 246 an_release_resources(dev); 247 return(error); 248} 249 250static int 251an_detach_pci(device_t dev) 252{ 253 struct an_softc *sc = device_get_softc(dev); 254 struct ifnet *ifp = &sc->arpcom.ac_if; 255 256 an_stop(sc); 257 ifmedia_removeall(&sc->an_ifmedia); 258 ether_ifdetach(ifp); 259 bus_teardown_intr(dev, sc->irq_res, sc->irq_handle); 260 an_release_resources(dev); 261 262 return (0); 263} 264 265static int 266an_suspend_pci(device_t dev) 267{ 268 an_shutdown(dev); 269 270 return (0); 271} 272 273static int 274an_resume_pci(device_t dev) 275{ 276 an_resume(dev); 277 278 return (0); 279} 280 281static device_method_t an_pci_methods[] = { 282 /* Device interface */ 283 DEVMETHOD(device_probe, an_probe_pci), 284 DEVMETHOD(device_attach, an_attach_pci), 285 DEVMETHOD(device_detach, an_detach_pci), 286 DEVMETHOD(device_shutdown, an_shutdown), 287 DEVMETHOD(device_suspend, an_suspend_pci), 288 DEVMETHOD(device_resume, an_resume_pci), 289 { 0, 0 } 290}; 291 292static driver_t an_pci_driver = { 293 "an", 294 an_pci_methods, 295 sizeof(struct an_softc), 296}; 297 298static devclass_t an_devclass; 299 300DRIVER_MODULE(if_an, pci, an_pci_driver, an_devclass, 0, 0); 301MODULE_DEPEND(if_an, wlan, 1, 1, 1); 302