if_an_pci.c revision 106937
155992Swpaul/* 255992Swpaul * Copyright (c) 1997, 1998, 1999 355992Swpaul * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved. 455992Swpaul * 555992Swpaul * Redistribution and use in source and binary forms, with or without 655992Swpaul * modification, are permitted provided that the following conditions 755992Swpaul * are met: 855992Swpaul * 1. Redistributions of source code must retain the above copyright 955992Swpaul * notice, this list of conditions and the following disclaimer. 1055992Swpaul * 2. Redistributions in binary form must reproduce the above copyright 1155992Swpaul * notice, this list of conditions and the following disclaimer in the 1255992Swpaul * documentation and/or other materials provided with the distribution. 1355992Swpaul * 3. All advertising materials mentioning features or use of this software 1455992Swpaul * must display the following acknowledgement: 1555992Swpaul * This product includes software developed by Bill Paul. 1655992Swpaul * 4. Neither the name of the author nor the names of any co-contributors 1755992Swpaul * may be used to endorse or promote products derived from this software 1855992Swpaul * without specific prior written permission. 1955992Swpaul * 2055992Swpaul * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND 2155992Swpaul * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2255992Swpaul * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2355992Swpaul * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD 2455992Swpaul * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2555992Swpaul * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2655992Swpaul * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2755992Swpaul * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2855992Swpaul * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2955992Swpaul * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 3055992Swpaul * THE POSSIBILITY OF SUCH DAMAGE. 3155992Swpaul * 3255992Swpaul * $FreeBSD: head/sys/dev/an/if_an_pci.c 106937 2002-11-14 23:54:55Z sam $ 3355992Swpaul */ 3455992Swpaul 3555992Swpaul/* 3655992Swpaul * This is a PCI shim for the Aironet PC4500/4800 wireless network 3755992Swpaul * driver. Aironet makes PCMCIA, ISA and PCI versions of these devices, 3855992Swpaul * which all have basically the same interface. The ISA and PCI cards 3955992Swpaul * are actually bridge adapters with PCMCIA cards inserted into them, 4055992Swpaul * however they appear as normal PCI or ISA devices to the host. 4155992Swpaul * 4255992Swpaul * All we do here is handle the PCI probe and attach and set up an 4355992Swpaul * interrupt handler entry point. The PCI version of the card uses 4455992Swpaul * a PLX 9050 PCI to "dumb bus" bridge chip, which provides us with 4555992Swpaul * multiple PCI address space mappings. The primary mapping at PCI 4655992Swpaul * register 0x14 is for the PLX chip itself, *NOT* the Aironet card. 4755992Swpaul * The I/O address of the Aironet is actually at register 0x18, which 4855992Swpaul * is the local bus mapping register for bus space 0. There are also 4955992Swpaul * registers for additional register spaces at registers 0x1C and 5055992Swpaul * 0x20, but these are unused in the Aironet devices. To find out 5155992Swpaul * more, you need a datasheet for the 9050 from PLX, but you have 5255992Swpaul * to go through their sales office to get it. Bleh. 5355992Swpaul */ 5455992Swpaul 5555992Swpaul#include "opt_inet.h" 5655992Swpaul 5755992Swpaul#ifdef INET 5855992Swpaul#define ANCACHE 5955992Swpaul#endif 6055992Swpaul 6155992Swpaul#include <sys/param.h> 6255992Swpaul#include <sys/systm.h> 6355992Swpaul#include <sys/sockio.h> 6455992Swpaul#include <sys/mbuf.h> 6555992Swpaul#include <sys/kernel.h> 6655992Swpaul#include <sys/socket.h> 6755992Swpaul 6855992Swpaul#include <sys/module.h> 6955992Swpaul#include <sys/bus.h> 7055992Swpaul#include <machine/bus.h> 7155992Swpaul#include <sys/rman.h> 7284811Sjhb#include <sys/lock.h> 7367365Sjhb#include <sys/mutex.h> 7455992Swpaul#include <machine/resource.h> 7555992Swpaul 7655992Swpaul#include <net/if.h> 7755992Swpaul#include <net/if_arp.h> 7855992Swpaul#include <net/ethernet.h> 7955992Swpaul#include <net/if_dl.h> 8077217Sphk#include <net/if_media.h> 8155992Swpaul 8255992Swpaul#include <pci/pcireg.h> 8355992Swpaul#include <pci/pcivar.h> 8455992Swpaul 8555992Swpaul#ifndef lint 8655992Swpaulstatic const char rcsid[] = 8755992Swpaul "$FreeBSD: head/sys/dev/an/if_an_pci.c 106937 2002-11-14 23:54:55Z sam $"; 8855992Swpaul#endif 8955992Swpaul 9055992Swpaul#include <dev/an/if_aironet_ieee.h> 9155992Swpaul#include <dev/an/if_anreg.h> 9255992Swpaul 9355992Swpaulstruct an_type { 9455992Swpaul u_int16_t an_vid; 9555992Swpaul u_int16_t an_did; 9655992Swpaul char *an_name; 9755992Swpaul}; 9855992Swpaul 9955992Swpaul#define AIRONET_VENDORID 0x14B9 10081221Sbrooks#define AIRONET_DEVICEID_35x 0x0350 10155992Swpaul#define AIRONET_DEVICEID_4500 0x4500 10255992Swpaul#define AIRONET_DEVICEID_4800 0x4800 10355992Swpaul#define AIRONET_DEVICEID_4xxx 0x0001 10455992Swpaul#define AN_PCI_PLX_LOIO 0x14 /* PLX chip iobase */ 10555992Swpaul#define AN_PCI_LOIO 0x18 /* Aironet iobase */ 10655992Swpaul 10755992Swpaulstatic struct an_type an_devs[] = { 10881221Sbrooks { AIRONET_VENDORID, AIRONET_DEVICEID_35x, "Cisco Aironet 350 Series" }, 10955992Swpaul { AIRONET_VENDORID, AIRONET_DEVICEID_4500, "Aironet PCI4500" }, 11055992Swpaul { AIRONET_VENDORID, AIRONET_DEVICEID_4800, "Aironet PCI4800" }, 11155992Swpaul { AIRONET_VENDORID, AIRONET_DEVICEID_4xxx, "Aironet PCI4500/PCI4800" }, 11255992Swpaul { 0, 0, NULL } 11355992Swpaul}; 11455992Swpaul 11592739Salfredstatic int an_probe_pci (device_t); 11692739Salfredstatic int an_attach_pci (device_t); 11792739Salfredstatic int an_detach_pci (device_t); 11855992Swpaul 11983270Sbrooksstatic int 12083270Sbrooksan_probe_pci(device_t dev) 12155992Swpaul{ 12255992Swpaul struct an_type *t; 12355992Swpaul 12455992Swpaul t = an_devs; 12555992Swpaul 12683270Sbrooks while (t->an_name != NULL) { 12755992Swpaul if (pci_get_vendor(dev) == t->an_vid && 12856051Swpaul pci_get_device(dev) == t->an_did) { 12955992Swpaul device_set_desc(dev, t->an_name); 13055992Swpaul return(0); 13155992Swpaul } 13255992Swpaul t++; 13355992Swpaul } 13455992Swpaul 13555992Swpaul return(ENXIO); 13655992Swpaul} 13755992Swpaul 13883270Sbrooksstatic int 13983270Sbrooksan_attach_pci(dev) 14055992Swpaul device_t dev; 14155992Swpaul{ 14255992Swpaul u_int32_t command; 14355992Swpaul struct an_softc *sc; 14455992Swpaul int unit, flags, error = 0; 14555992Swpaul 14655992Swpaul sc = device_get_softc(dev); 14755992Swpaul unit = device_get_unit(dev); 14855992Swpaul flags = device_get_flags(dev); 14955992Swpaul bzero(sc, sizeof(struct an_softc)); 15083270Sbrooks 15155992Swpaul /* 15255992Swpaul * Map control/status registers. 15355992Swpaul */ 15461048Speter command = pci_read_config(dev, PCIR_COMMAND, 4); 15555992Swpaul command |= PCIM_CMD_PORTEN; 15661048Speter pci_write_config(dev, PCIR_COMMAND, command, 4); 15761048Speter command = pci_read_config(dev, PCIR_COMMAND, 4); 15855992Swpaul 15955992Swpaul if (!(command & PCIM_CMD_PORTEN)) { 16055992Swpaul printf("an%d: failed to enable I/O ports!\n", unit); 16155992Swpaul error = ENXIO; 16255992Swpaul goto fail; 16355992Swpaul } 16455992Swpaul 16555992Swpaul sc->port_rid = AN_PCI_LOIO; 16655992Swpaul error = an_alloc_port(dev, sc->port_rid, 1); 16755992Swpaul 16855992Swpaul if (error) { 16955992Swpaul printf("an%d: couldn't map ports\n", unit); 17055992Swpaul goto fail; 17155992Swpaul } 17255992Swpaul 17355992Swpaul sc->an_btag = rman_get_bustag(sc->port_res); 17455992Swpaul sc->an_bhandle = rman_get_bushandle(sc->port_res); 17555992Swpaul 17655992Swpaul /* Allocate interrupt */ 17755992Swpaul error = an_alloc_irq(dev, 0, RF_SHAREABLE); 17855992Swpaul if (error) { 17955992Swpaul an_release_resources(dev); 18055992Swpaul goto fail; 18155992Swpaul } 18283270Sbrooks 18355992Swpaul error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET, 18455992Swpaul an_intr, sc, &sc->irq_handle); 18555992Swpaul if (error) { 18655992Swpaul an_release_resources(dev); 18755992Swpaul goto fail; 18855992Swpaul } 18955992Swpaul 19067096Swpaul sc->an_dev = dev; 19155992Swpaul error = an_attach(sc, device_get_unit(dev), flags); 19255992Swpaul 19355992Swpaulfail: 19455992Swpaul return(error); 19555992Swpaul} 19655992Swpaul 19783270Sbrooksstatic int 19855992Swpaulan_detach_pci(device_t dev) 19955992Swpaul{ 20055992Swpaul struct an_softc *sc = device_get_softc(dev); 20155992Swpaul struct ifnet *ifp = &sc->arpcom.ac_if; 20255992Swpaul 20355992Swpaul an_stop(sc); 20477217Sphk ifmedia_removeall(&sc->an_ifmedia); 205106937Ssam ether_ifdetach(ifp); 20655992Swpaul bus_teardown_intr(dev, sc->irq_res, sc->irq_handle); 20755992Swpaul an_release_resources(dev); 20855992Swpaul 20955992Swpaul return (0); 21055992Swpaul} 21155992Swpaul 21255992Swpaulstatic device_method_t an_pci_methods[] = { 21355992Swpaul /* Device interface */ 21455992Swpaul DEVMETHOD(device_probe, an_probe_pci), 21555992Swpaul DEVMETHOD(device_attach, an_attach_pci), 21655992Swpaul DEVMETHOD(device_detach, an_detach_pci), 21755992Swpaul DEVMETHOD(device_shutdown, an_shutdown), 21855992Swpaul { 0, 0 } 21955992Swpaul}; 22055992Swpaul 22155992Swpaulstatic driver_t an_pci_driver = { 22255992Swpaul "an", 22355992Swpaul an_pci_methods, 22455992Swpaul sizeof(struct an_softc), 22555992Swpaul}; 22655992Swpaul 22755992Swpaulstatic devclass_t an_devclass; 22855992Swpaul 22955992SwpaulDRIVER_MODULE(if_an, pci, an_pci_driver, an_devclass, 0, 0); 230