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