1 /* $OpenBSD: if_acx_pci.c,v 1.8 2015/03/14 03:38:48 jsg 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 53 #include <dev/pci/pcireg.h> 54 #include <dev/pci/pcivar.h> 55 #include <dev/pci/pcidevs.h> 56 57 struct acx_pci_softc { 58 struct acx_softc sc_acx; 59 60 /* PCI specific goo */ 61 struct acx_opns *sc_opns; 62 pci_chipset_tag_t sc_pc; 63 void *sc_ih; 64 bus_size_t sc_mapsize1; 65 bus_size_t sc_mapsize2; 66 int sc_intrline; 67 68 /* hack for ACX100A */ 69 bus_space_tag_t sc_io_bt; 70 bus_space_handle_t sc_io_bh; 71 bus_size_t sc_iomapsize; 72 }; 73 74 /* Base Address Register */ 75 #define ACX_PCI_BAR0 0x10 76 #define ACX_PCI_BAR1 0x14 77 #define ACX_PCI_BAR2 0x18 78 79 int acx_pci_match(struct device *, void *, void *); 80 void acx_pci_attach(struct device *, struct device *, void *); 81 int acx_pci_detach(struct device *, int); 82 83 struct cfattach acx_pci_ca = { 84 sizeof (struct acx_pci_softc), acx_pci_match, acx_pci_attach, 85 acx_pci_detach 86 }; 87 88 const struct pci_matchid acx_pci_devices[] = { 89 { PCI_VENDOR_TI, PCI_PRODUCT_TI_ACX100A }, 90 { PCI_VENDOR_TI, PCI_PRODUCT_TI_ACX100B }, 91 { PCI_VENDOR_TI, PCI_PRODUCT_TI_ACX111 } 92 }; 93 94 int 95 acx_pci_match(struct device *parent, void *match, void *aux) 96 { 97 return (pci_matchbyid((struct pci_attach_args *)aux, acx_pci_devices, 98 sizeof (acx_pci_devices) / sizeof (acx_pci_devices[0]))); 99 } 100 101 void 102 acx_pci_attach(struct device *parent, struct device *self, void *aux) 103 { 104 struct acx_pci_softc *psc = (struct acx_pci_softc *)self; 105 struct acx_softc *sc = &psc->sc_acx; 106 struct pci_attach_args *pa = aux; 107 const char *intrstr = NULL; 108 pci_intr_handle_t ih; 109 int error, b1 = ACX_PCI_BAR0, b2 = ACX_PCI_BAR1; 110 111 sc->sc_dmat = pa->pa_dmat; 112 psc->sc_pc = pa->pa_pc; 113 114 /* map control/status registers */ 115 if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_TI_ACX100A) { 116 error = pci_mapreg_map(pa, ACX_PCI_BAR0, 117 PCI_MAPREG_TYPE_IO, 0, &psc->sc_io_bt, 118 &psc->sc_io_bh, NULL, &psc->sc_iomapsize, 0); 119 if (error != 0) { 120 printf(": can't map i/o space\n"); 121 return; 122 } 123 b1 = ACX_PCI_BAR1; 124 b2 = ACX_PCI_BAR2; 125 } 126 127 error = pci_mapreg_map(pa, b1, PCI_MAPREG_TYPE_MEM | 128 PCI_MAPREG_MEM_TYPE_32BIT, 0, &sc->sc_mem1_bt, 129 &sc->sc_mem1_bh, NULL, &psc->sc_mapsize1, 0); 130 if (error != 0) { 131 printf(": can't map mem1 space\n"); 132 return; 133 } 134 135 error = pci_mapreg_map(pa, b2, PCI_MAPREG_TYPE_MEM | 136 PCI_MAPREG_MEM_TYPE_32BIT, 0, &sc->sc_mem2_bt, 137 &sc->sc_mem2_bh, NULL, &psc->sc_mapsize2, 0); 138 if (error != 0) { 139 printf(": can't map mem2 space\n"); 140 return; 141 } 142 143 if (pci_intr_map(pa, &ih) != 0) { 144 printf(": can't map interrupt\n"); 145 return; 146 } 147 148 intrstr = pci_intr_string(psc->sc_pc, ih); 149 psc->sc_ih = pci_intr_establish(psc->sc_pc, ih, IPL_NET, 150 acx_intr, sc, sc->sc_dev.dv_xname); 151 if (psc->sc_ih == NULL) { 152 printf(": can't establish interrupt"); 153 if (intrstr != NULL) 154 printf(" at %s", intrstr); 155 printf("\n"); 156 return; 157 } 158 printf(": %s\n", intrstr); 159 160 if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_TI_ACX111) 161 acx111_set_param(sc); 162 else 163 acx100_set_param(sc); 164 165 acx_attach(sc); 166 } 167 168 int 169 acx_pci_detach(struct device *self, int flags) 170 { 171 struct acx_pci_softc *psc = (struct acx_pci_softc *)self; 172 struct acx_softc *sc = &psc->sc_acx; 173 174 acx_detach(sc); 175 pci_intr_disestablish(psc->sc_pc, psc->sc_ih); 176 177 return 0; 178 } 179