root/dev/pci/if_acx_pci.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. acx_pci_match
  2. acx_pci_attach
  3. acx_pci_detach

    1 /*      $OpenBSD: if_acx_pci.c,v 1.6 2006/11/18 20:44:40 grange Exp $  */
    2 
    3 /*-
    4  * Copyright (c) 2006 Theo de Raadt <deraadt@openbsd.org>
    5  * Copyright (c) 2005, 2006
    6  *      Damien Bergamini <damien.bergamini@free.fr>
    7  *
    8  * Permission to use, copy, modify, and distribute this software for any
    9  * purpose with or without fee is hereby granted, provided that the above
   10  * copyright notice and this permission notice appear in all copies.
   11  *
   12  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
   13  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
   14  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
   15  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
   16  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
   17  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
   18  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
   19  */
   20 
   21 /*
   22  * PCI front-end for the ACX100/111
   23  */
   24 
   25 #include "bpfilter.h"
   26 
   27 #include <sys/param.h>
   28 #include <sys/sockio.h>
   29 #include <sys/mbuf.h>
   30 #include <sys/kernel.h>
   31 #include <sys/socket.h>
   32 #include <sys/systm.h>
   33 #include <sys/malloc.h>
   34 #include <sys/timeout.h>
   35 #include <sys/device.h>
   36 
   37 #include <machine/bus.h>
   38 #include <machine/intr.h>
   39 
   40 #include <net/if.h>
   41 #include <net/if_dl.h>
   42 #include <net/if_media.h>
   43 
   44 #include <netinet/in.h>
   45 #include <netinet/if_ether.h>
   46 
   47 #include <net80211/ieee80211_var.h>
   48 #include <net80211/ieee80211_amrr.h>
   49 #include <net80211/ieee80211_radiotap.h>
   50 
   51 #include <dev/ic/acxvar.h>
   52 #include <dev/ic/acxreg.h>
   53 
   54 #include <dev/pci/pcireg.h>
   55 #include <dev/pci/pcivar.h>
   56 #include <dev/pci/pcidevs.h>
   57 
   58 struct acx_pci_softc {
   59         struct acx_softc        sc_acx;
   60 
   61         /* PCI specific goo */
   62         struct acx_opns         *sc_opns;
   63         pci_chipset_tag_t       sc_pc;
   64         void                    *sc_ih;
   65         bus_size_t              sc_mapsize1;
   66         bus_size_t              sc_mapsize2;
   67         int                     sc_intrline;
   68 
   69         /* hack for ACX100A */
   70         bus_space_tag_t         sc_io_bt;
   71         bus_space_handle_t      sc_io_bh;
   72         bus_size_t              sc_iomapsize;
   73 };
   74 
   75 /* Base Address Register */
   76 #define ACX_PCI_BAR0    0x10
   77 #define ACX_PCI_BAR1    0x14
   78 #define ACX_PCI_BAR2    0x18
   79 
   80 int     acx_pci_match(struct device *, void *, void *);
   81 void    acx_pci_attach(struct device *, struct device *, void *);
   82 int     acx_pci_detach(struct device *, int);
   83 
   84 struct cfattach acx_pci_ca = {
   85         sizeof (struct acx_pci_softc), acx_pci_match, acx_pci_attach,
   86         acx_pci_detach
   87 };
   88 
   89 const struct pci_matchid acx_pci_devices[] = {
   90         { PCI_VENDOR_TI, PCI_PRODUCT_TI_ACX100A },
   91         { PCI_VENDOR_TI, PCI_PRODUCT_TI_ACX100B },
   92         { PCI_VENDOR_TI, PCI_PRODUCT_TI_ACX111  }
   93 };
   94 
   95 int
   96 acx_pci_match(struct device *parent, void *match, void *aux)
   97 {
   98         return (pci_matchbyid((struct pci_attach_args *)aux, acx_pci_devices,
   99             sizeof (acx_pci_devices) / sizeof (acx_pci_devices[0])));
  100 }
  101 
  102 void
  103 acx_pci_attach(struct device *parent, struct device *self, void *aux)
  104 {
  105         struct acx_pci_softc *psc = (struct acx_pci_softc *)self;
  106         struct acx_softc *sc = &psc->sc_acx;
  107         struct pci_attach_args *pa = aux;
  108         const char *intrstr = NULL;
  109         pci_intr_handle_t ih;
  110         int error, b1 = ACX_PCI_BAR0, b2 = ACX_PCI_BAR1;
  111 
  112         sc->sc_dmat = pa->pa_dmat;
  113         psc->sc_pc = pa->pa_pc;
  114 
  115         /* map control/status registers */
  116         if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_TI_ACX100A) {
  117                 error = pci_mapreg_map(pa, ACX_PCI_BAR0,
  118                     PCI_MAPREG_TYPE_IO, 0, &psc->sc_io_bt,
  119                     &psc->sc_io_bh, NULL, &psc->sc_iomapsize, 0);
  120                 if (error != 0) {
  121                         printf(": could not map i/o space\n");
  122                         return;
  123                 }
  124                 b1 = ACX_PCI_BAR1;
  125                 b2 = ACX_PCI_BAR2;
  126         }
  127 
  128         error = pci_mapreg_map(pa, b1, PCI_MAPREG_TYPE_MEM |
  129             PCI_MAPREG_MEM_TYPE_32BIT, 0, &sc->sc_mem1_bt,
  130             &sc->sc_mem1_bh, NULL, &psc->sc_mapsize1, 0);
  131         if (error != 0) {
  132                 printf(": could not map memory1 space\n");
  133                 return;
  134         }
  135 
  136         error = pci_mapreg_map(pa, b2, PCI_MAPREG_TYPE_MEM |
  137             PCI_MAPREG_MEM_TYPE_32BIT, 0, &sc->sc_mem2_bt,
  138             &sc->sc_mem2_bh, NULL, &psc->sc_mapsize2, 0);
  139         if (error != 0) {
  140                 printf(": could not map memory2 space\n");
  141                 return;
  142         }
  143 
  144         if (pci_intr_map(pa, &ih) != 0) {
  145                 printf(": could not map interrupt\n");
  146                 return;
  147         }
  148 
  149         intrstr = pci_intr_string(psc->sc_pc, ih);
  150         psc->sc_ih = pci_intr_establish(psc->sc_pc, ih, IPL_NET,
  151             acx_intr, sc, sc->sc_dev.dv_xname);
  152         if (psc->sc_ih == NULL) {
  153                 printf(": could not establish interrupt");
  154                 if (intrstr != NULL)
  155                         printf(" at %s", intrstr);
  156                 printf("\n");
  157                 return;
  158         }
  159         printf(": %s\n", intrstr);
  160 
  161         if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_TI_ACX111)
  162                 acx111_set_param(sc);
  163         else
  164                 acx100_set_param(sc);
  165 
  166         acx_attach(sc);
  167 }
  168 
  169 int
  170 acx_pci_detach(struct device *self, int flags)
  171 {
  172         struct acx_pci_softc *psc = (struct acx_pci_softc *)self;
  173         struct acx_softc *sc = &psc->sc_acx;
  174 
  175         acx_detach(sc);
  176         pci_intr_disestablish(psc->sc_pc, psc->sc_ih);
  177 
  178         return 0;
  179 }

/* [<][>][^][v][top][bottom][index][help] */