This source file includes following definitions.
- rtw_pci_match
- rtw_pci_enable
- rtw_pci_disable
- rtw_pci_attach
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 #include <sys/cdefs.h>
50 #include <sys/param.h>
51 #include <sys/systm.h>
52 #include <sys/mbuf.h>
53 #include <sys/malloc.h>
54 #include <sys/kernel.h>
55 #include <sys/socket.h>
56 #include <sys/ioctl.h>
57 #include <sys/errno.h>
58 #include <sys/device.h>
59
60 #include <machine/endian.h>
61
62 #include <net/if.h>
63 #include <net/if_dl.h>
64 #include <net/if_media.h>
65 #ifdef INET
66 #include <netinet/in.h>
67 #include <netinet/if_ether.h>
68 #endif
69
70 #include <net80211/ieee80211_radiotap.h>
71 #include <net80211/ieee80211_var.h>
72
73 #include <machine/bus.h>
74 #include <machine/intr.h>
75
76 #include <dev/ic/rtwreg.h>
77 #include <dev/ic/sa2400reg.h>
78 #include <dev/ic/rtwvar.h>
79
80 #include <dev/pci/pcivar.h>
81 #include <dev/pci/pcireg.h>
82 #include <dev/pci/pcidevs.h>
83
84 int rtw_pci_enable(struct rtw_softc *);
85 void rtw_pci_disable(struct rtw_softc *);
86
87
88
89
90 #define RTW_PCI_IOBA 0x10
91 #define RTW_PCI_MMBA 0x14
92
93 struct rtw_pci_softc {
94 struct rtw_softc psc_rtw;
95
96 pci_intr_handle_t psc_ih;
97 void *psc_intrcookie;
98
99 pci_chipset_tag_t psc_pc;
100 pcitag_t psc_pcitag;
101 };
102
103 int rtw_pci_match(struct device *, void *, void *);
104 void rtw_pci_attach(struct device *, struct device *, void *);
105
106 struct cfattach rtw_pci_ca = {
107 sizeof (struct rtw_pci_softc), rtw_pci_match, rtw_pci_attach
108 };
109
110 const struct pci_matchid rtw_pci_products[] = {
111 { PCI_VENDOR_REALTEK, PCI_PRODUCT_REALTEK_RT8185 },
112 { PCI_VENDOR_REALTEK, PCI_PRODUCT_REALTEK_RT8180 },
113 { PCI_VENDOR_BELKIN2, PCI_PRODUCT_BELKIN2_F5D6001 },
114 { PCI_VENDOR_DLINK, PCI_PRODUCT_DLINK_DWL610 },
115 };
116
117 int
118 rtw_pci_match(struct device *parent, void *match, void *aux)
119 {
120 return (pci_matchbyid((struct pci_attach_args *)aux, rtw_pci_products,
121 sizeof(rtw_pci_products)/sizeof(rtw_pci_products[0])));
122 }
123
124 int
125 rtw_pci_enable(struct rtw_softc *sc)
126 {
127 struct rtw_pci_softc *psc = (void *)sc;
128
129
130 psc->psc_intrcookie = pci_intr_establish(psc->psc_pc, psc->psc_ih,
131 IPL_NET, rtw_intr, sc, sc->sc_dev.dv_xname);
132 if (psc->psc_intrcookie == NULL) {
133 printf("%s: unable to establish interrupt\n",
134 sc->sc_dev.dv_xname);
135 return (1);
136 }
137
138 return (0);
139 }
140
141 void
142 rtw_pci_disable(struct rtw_softc *sc)
143 {
144 struct rtw_pci_softc *psc = (void *)sc;
145
146
147 pci_intr_disestablish(psc->psc_pc, psc->psc_intrcookie);
148 psc->psc_intrcookie = NULL;
149 }
150
151 void
152 rtw_pci_attach(struct device *parent, struct device *self, void *aux)
153 {
154 struct rtw_pci_softc *psc = (void *) self;
155 struct rtw_softc *sc = &psc->psc_rtw;
156 struct rtw_regs *regs = &sc->sc_regs;
157 struct pci_attach_args *pa = aux;
158 pci_chipset_tag_t pc = pa->pa_pc;
159 const char *intrstr = NULL;
160 bus_space_tag_t iot, memt;
161 bus_space_handle_t ioh, memh;
162 int ioh_valid, memh_valid;
163 pcireg_t reg;
164 int pmreg;
165
166 psc->psc_pc = pa->pa_pc;
167 psc->psc_pcitag = pa->pa_tag;
168
169
170
171
172
173 sc->sc_flags |= RTW_F_ENABLED;
174
175
176
177
178 sc->sc_rev = PCI_REVISION(pa->pa_class);
179
180
181
182
183
184
185
186
187
188
189
190 if (pci_get_capability(pc, pa->pa_tag, PCI_CAP_PWRMGMT, &pmreg, 0)) {
191 reg = pci_conf_read(pc, pa->pa_tag, pmreg + PCI_PMCSR);
192 switch (reg & PCI_PMCSR_STATE_MASK) {
193 case PCI_PMCSR_STATE_D1:
194 case PCI_PMCSR_STATE_D2:
195 printf(": waking up from power state D%d\n",
196 reg & PCI_PMCSR_STATE_MASK);
197 pci_conf_write(pc, pa->pa_tag, pmreg + PCI_PMCSR,
198 (reg & ~PCI_PMCSR_STATE_MASK) |
199 PCI_PMCSR_STATE_D0);
200 break;
201 case PCI_PMCSR_STATE_D3:
202
203
204
205
206 printf(": unable to wake up from power state D3, "
207 "reboot required.\n");
208 pci_conf_write(pc, pa->pa_tag, pmreg + PCI_PMCSR,
209 (reg & ~PCI_PMCSR_STATE_MASK) |
210 PCI_PMCSR_STATE_D0);
211 return;
212 }
213 }
214
215
216
217
218 ioh_valid = (pci_mapreg_map(pa, RTW_PCI_IOBA,
219 PCI_MAPREG_TYPE_IO, 0,
220 &iot, &ioh, NULL, NULL, 0) == 0);
221 memh_valid = (pci_mapreg_map(pa, RTW_PCI_MMBA,
222 PCI_MAPREG_TYPE_MEM|PCI_MAPREG_MEM_TYPE_32BIT, 0,
223 &memt, &memh, NULL, NULL, 0) == 0);
224
225 if (memh_valid) {
226 regs->r_bt = memt;
227 regs->r_bh = memh;
228 } else if (ioh_valid) {
229 regs->r_bt = iot;
230 regs->r_bh = ioh;
231 } else {
232 printf(": unable to map device registers\n");
233 return;
234 }
235
236 sc->sc_dmat = pa->pa_dmat;
237
238
239
240
241 if (pci_intr_map(pa, &psc->psc_ih)) {
242 printf(": unable to map interrupt\n");
243 return;
244 }
245 intrstr = pci_intr_string(pc, psc->psc_ih);
246 psc->psc_intrcookie = pci_intr_establish(pc, psc->psc_ih, IPL_NET,
247 rtw_intr, sc, sc->sc_dev.dv_xname);
248 if (psc->psc_intrcookie == NULL) {
249 printf(": unable to establish interrupt");
250 if (intrstr != NULL)
251 printf(" at %s", intrstr);
252 printf("\n");
253 return;
254 }
255
256 printf(": %s\n", intrstr);
257
258 sc->sc_enable = rtw_pci_enable;
259 sc->sc_disable = rtw_pci_disable;
260
261
262
263
264 rtw_attach(sc);
265 }