Lines 16-23
Link Here
|
16 |
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
16 |
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
17 |
*/ |
17 |
*/ |
18 |
|
18 |
|
19 |
#define VERSION "20071127" |
|
|
20 |
|
21 |
#include <sys/cdefs.h> |
19 |
#include <sys/cdefs.h> |
22 |
__FBSDID("$FreeBSD$"); |
20 |
__FBSDID("$FreeBSD$"); |
23 |
|
21 |
|
Lines 60-65
Link Here
|
60 |
*/ |
58 |
*/ |
61 |
|
59 |
|
62 |
#include "opt_wlan.h" |
60 |
#include "opt_wlan.h" |
|
|
61 |
#include "opt_wpi.h" |
63 |
|
62 |
|
64 |
#include <sys/param.h> |
63 |
#include <sys/param.h> |
65 |
#include <sys/sysctl.h> |
64 |
#include <sys/sysctl.h> |
Lines 93-144
Link Here
|
93 |
#include <net/if_media.h> |
92 |
#include <net/if_media.h> |
94 |
#include <net/if_types.h> |
93 |
#include <net/if_types.h> |
95 |
|
94 |
|
|
|
95 |
#include <netinet/in.h> |
96 |
#include <netinet/in_systm.h> |
97 |
#include <netinet/in_var.h> |
98 |
#include <netinet/if_ether.h> |
99 |
#include <netinet/ip.h> |
100 |
|
96 |
#include <net80211/ieee80211_var.h> |
101 |
#include <net80211/ieee80211_var.h> |
97 |
#include <net80211/ieee80211_radiotap.h> |
102 |
#include <net80211/ieee80211_radiotap.h> |
98 |
#include <net80211/ieee80211_regdomain.h> |
103 |
#include <net80211/ieee80211_regdomain.h> |
99 |
#include <net80211/ieee80211_ratectl.h> |
104 |
#include <net80211/ieee80211_ratectl.h> |
100 |
|
105 |
|
101 |
#include <netinet/in.h> |
|
|
102 |
#include <netinet/in_systm.h> |
103 |
#include <netinet/in_var.h> |
104 |
#include <netinet/ip.h> |
105 |
#include <netinet/if_ether.h> |
106 |
|
107 |
#include <dev/wpi/if_wpireg.h> |
106 |
#include <dev/wpi/if_wpireg.h> |
108 |
#include <dev/wpi/if_wpivar.h> |
107 |
#include <dev/wpi/if_wpivar.h> |
|
|
108 |
#include <dev/wpi/if_wpi_debug.h> |
109 |
|
109 |
|
110 |
#define WPI_DEBUG |
|
|
111 |
|
112 |
#ifdef WPI_DEBUG |
113 |
#define DPRINTF(x) do { if (wpi_debug != 0) printf x; } while (0) |
114 |
#define DPRINTFN(n, x) do { if (wpi_debug & n) printf x; } while (0) |
115 |
#define WPI_DEBUG_SET (wpi_debug != 0) |
116 |
|
117 |
enum { |
118 |
WPI_DEBUG_UNUSED = 0x00000001, /* Unused */ |
119 |
WPI_DEBUG_HW = 0x00000002, /* Stage 1 (eeprom) debugging */ |
120 |
WPI_DEBUG_TX = 0x00000004, /* Stage 2 TX intrp debugging*/ |
121 |
WPI_DEBUG_RX = 0x00000008, /* Stage 2 RX intrp debugging */ |
122 |
WPI_DEBUG_CMD = 0x00000010, /* Stage 2 CMD intrp debugging*/ |
123 |
WPI_DEBUG_FIRMWARE = 0x00000020, /* firmware(9) loading debug */ |
124 |
WPI_DEBUG_DMA = 0x00000040, /* DMA (de)allocations/syncs */ |
125 |
WPI_DEBUG_SCANNING = 0x00000080, /* Stage 2 Scanning debugging */ |
126 |
WPI_DEBUG_NOTIFY = 0x00000100, /* State 2 Noftif intr debug */ |
127 |
WPI_DEBUG_TEMP = 0x00000200, /* TXPower/Temp Calibration */ |
128 |
WPI_DEBUG_OPS = 0x00000400, /* wpi_ops taskq debug */ |
129 |
WPI_DEBUG_WATCHDOG = 0x00000800, /* Watch dog debug */ |
130 |
WPI_DEBUG_ANY = 0xffffffff |
131 |
}; |
132 |
|
133 |
static int wpi_debug; |
134 |
SYSCTL_INT(_debug, OID_AUTO, wpi, CTLFLAG_RWTUN, &wpi_debug, 0, "wpi debug level"); |
135 |
|
136 |
#else |
137 |
#define DPRINTF(x) |
138 |
#define DPRINTFN(n, x) |
139 |
#define WPI_DEBUG_SET 0 |
140 |
#endif |
141 |
|
142 |
struct wpi_ident { |
110 |
struct wpi_ident { |
143 |
uint16_t vendor; |
111 |
uint16_t vendor; |
144 |
uint16_t device; |
112 |
uint16_t device; |
Lines 158-257
Link Here
|
158 |
{ 0, 0, 0, NULL } |
126 |
{ 0, 0, 0, NULL } |
159 |
}; |
127 |
}; |
160 |
|
128 |
|
|
|
129 |
static int wpi_probe(device_t); |
130 |
static int wpi_attach(device_t); |
131 |
static void wpi_radiotap_attach(struct wpi_softc *); |
132 |
static void wpi_sysctlattach(struct wpi_softc *); |
161 |
static struct ieee80211vap *wpi_vap_create(struct ieee80211com *, |
133 |
static struct ieee80211vap *wpi_vap_create(struct ieee80211com *, |
162 |
const char [IFNAMSIZ], int, enum ieee80211_opmode, int, |
134 |
const char [IFNAMSIZ], int, enum ieee80211_opmode, int, |
163 |
const uint8_t [IEEE80211_ADDR_LEN], |
135 |
const uint8_t [IEEE80211_ADDR_LEN], |
164 |
const uint8_t [IEEE80211_ADDR_LEN]); |
136 |
const uint8_t [IEEE80211_ADDR_LEN]); |
165 |
static void wpi_vap_delete(struct ieee80211vap *); |
137 |
static void wpi_vap_delete(struct ieee80211vap *); |
|
|
138 |
static int wpi_detach(device_t); |
139 |
static int wpi_shutdown(device_t); |
140 |
static int wpi_suspend(device_t); |
141 |
static int wpi_resume(device_t); |
142 |
static int wpi_nic_lock(struct wpi_softc *); |
143 |
static int wpi_read_prom_data(struct wpi_softc *, uint32_t, void *, int); |
144 |
static void wpi_dma_map_addr(void *, bus_dma_segment_t *, int, int); |
166 |
static int wpi_dma_contig_alloc(struct wpi_softc *, struct wpi_dma_info *, |
145 |
static int wpi_dma_contig_alloc(struct wpi_softc *, struct wpi_dma_info *, |
167 |
void **, bus_size_t, bus_size_t, int); |
146 |
void **, bus_size_t, bus_size_t); |
168 |
static void wpi_dma_contig_free(struct wpi_dma_info *); |
147 |
static void wpi_dma_contig_free(struct wpi_dma_info *); |
169 |
static void wpi_dma_map_addr(void *, bus_dma_segment_t *, int, int); |
|
|
170 |
static int wpi_alloc_shared(struct wpi_softc *); |
148 |
static int wpi_alloc_shared(struct wpi_softc *); |
171 |
static void wpi_free_shared(struct wpi_softc *); |
149 |
static void wpi_free_shared(struct wpi_softc *); |
172 |
static int wpi_alloc_rx_ring(struct wpi_softc *, struct wpi_rx_ring *); |
150 |
static int wpi_alloc_fwmem(struct wpi_softc *); |
173 |
static void wpi_reset_rx_ring(struct wpi_softc *, struct wpi_rx_ring *); |
151 |
static void wpi_free_fwmem(struct wpi_softc *); |
174 |
static void wpi_free_rx_ring(struct wpi_softc *, struct wpi_rx_ring *); |
152 |
static int wpi_alloc_rx_ring(struct wpi_softc *); |
|
|
153 |
static void wpi_update_rx_ring(struct wpi_softc *); |
154 |
static void wpi_reset_rx_ring(struct wpi_softc *); |
155 |
static void wpi_free_rx_ring(struct wpi_softc *); |
175 |
static int wpi_alloc_tx_ring(struct wpi_softc *, struct wpi_tx_ring *, |
156 |
static int wpi_alloc_tx_ring(struct wpi_softc *, struct wpi_tx_ring *, |
176 |
int, int); |
157 |
int); |
|
|
158 |
static void wpi_update_tx_ring(struct wpi_softc *, struct wpi_tx_ring *); |
177 |
static void wpi_reset_tx_ring(struct wpi_softc *, struct wpi_tx_ring *); |
159 |
static void wpi_reset_tx_ring(struct wpi_softc *, struct wpi_tx_ring *); |
178 |
static void wpi_free_tx_ring(struct wpi_softc *, struct wpi_tx_ring *); |
160 |
static void wpi_free_tx_ring(struct wpi_softc *, struct wpi_tx_ring *); |
|
|
161 |
static int wpi_read_eeprom(struct wpi_softc *, |
162 |
uint8_t macaddr[IEEE80211_ADDR_LEN]); |
163 |
static int wpi_read_eeprom_channels(struct wpi_softc *, int); |
164 |
static int wpi_read_eeprom_group(struct wpi_softc *, int); |
165 |
static struct ieee80211_node *wpi_node_alloc(struct ieee80211vap *, |
166 |
const uint8_t mac[IEEE80211_ADDR_LEN]); |
179 |
static int wpi_newstate(struct ieee80211vap *, enum ieee80211_state, int); |
167 |
static int wpi_newstate(struct ieee80211vap *, enum ieee80211_state, int); |
180 |
static void wpi_mem_lock(struct wpi_softc *); |
168 |
static void wpi_calib_timeout(void *); |
181 |
static void wpi_mem_unlock(struct wpi_softc *); |
169 |
static void wpi_rx_done(struct wpi_softc *, struct wpi_rx_desc *, |
182 |
static uint32_t wpi_mem_read(struct wpi_softc *, uint16_t); |
|
|
183 |
static void wpi_mem_write(struct wpi_softc *, uint16_t, uint32_t); |
184 |
static void wpi_mem_write_region_4(struct wpi_softc *, uint16_t, |
185 |
const uint32_t *, int); |
186 |
static uint16_t wpi_read_prom_data(struct wpi_softc *, uint32_t, void *, int); |
187 |
static int wpi_alloc_fwmem(struct wpi_softc *); |
188 |
static void wpi_free_fwmem(struct wpi_softc *); |
189 |
static int wpi_load_firmware(struct wpi_softc *); |
190 |
static void wpi_unload_firmware(struct wpi_softc *); |
191 |
static int wpi_load_microcode(struct wpi_softc *, const uint8_t *, int); |
192 |
static void wpi_rx_intr(struct wpi_softc *, struct wpi_rx_desc *, |
193 |
struct wpi_rx_data *); |
170 |
struct wpi_rx_data *); |
194 |
static void wpi_tx_intr(struct wpi_softc *, struct wpi_rx_desc *); |
171 |
static void wpi_rx_statistics(struct wpi_softc *, struct wpi_rx_desc *, |
195 |
static void wpi_cmd_intr(struct wpi_softc *, struct wpi_rx_desc *); |
172 |
struct wpi_rx_data *); |
|
|
173 |
static void wpi_tx_done(struct wpi_softc *, struct wpi_rx_desc *); |
174 |
static void wpi_cmd_done(struct wpi_softc *, struct wpi_rx_desc *); |
196 |
static void wpi_notif_intr(struct wpi_softc *); |
175 |
static void wpi_notif_intr(struct wpi_softc *); |
|
|
176 |
static void wpi_wakeup_intr(struct wpi_softc *); |
177 |
static void wpi_fatal_intr(struct wpi_softc *); |
197 |
static void wpi_intr(void *); |
178 |
static void wpi_intr(void *); |
198 |
static uint8_t wpi_plcp_signal(int); |
179 |
static int wpi_cmd2(struct wpi_softc *, struct wpi_buf *); |
199 |
static void wpi_watchdog(void *); |
|
|
200 |
static int wpi_tx_data(struct wpi_softc *, struct mbuf *, |
180 |
static int wpi_tx_data(struct wpi_softc *, struct mbuf *, |
201 |
struct ieee80211_node *, int); |
181 |
struct ieee80211_node *); |
|
|
182 |
static int wpi_tx_data_raw(struct wpi_softc *, struct mbuf *, |
183 |
struct ieee80211_node *, |
184 |
const struct ieee80211_bpf_params *); |
185 |
static int wpi_raw_xmit(struct ieee80211_node *, struct mbuf *, |
186 |
const struct ieee80211_bpf_params *); |
202 |
static void wpi_start(struct ifnet *); |
187 |
static void wpi_start(struct ifnet *); |
203 |
static void wpi_start_locked(struct ifnet *); |
188 |
static void wpi_start_locked(struct ifnet *); |
204 |
static int wpi_raw_xmit(struct ieee80211_node *, struct mbuf *, |
189 |
static void wpi_watchdog_rfkill(void *); |
205 |
const struct ieee80211_bpf_params *); |
190 |
static void wpi_watchdog(void *); |
206 |
static void wpi_scan_start(struct ieee80211com *); |
|
|
207 |
static void wpi_scan_end(struct ieee80211com *); |
208 |
static void wpi_set_channel(struct ieee80211com *); |
209 |
static void wpi_scan_curchan(struct ieee80211_scan_state *, unsigned long); |
210 |
static void wpi_scan_mindwell(struct ieee80211_scan_state *); |
211 |
static int wpi_ioctl(struct ifnet *, u_long, caddr_t); |
191 |
static int wpi_ioctl(struct ifnet *, u_long, caddr_t); |
212 |
static void wpi_read_eeprom(struct wpi_softc *, |
192 |
static int wpi_cmd(struct wpi_softc *, int, const void *, size_t, int); |
213 |
uint8_t macaddr[IEEE80211_ADDR_LEN]); |
|
|
214 |
static void wpi_read_eeprom_channels(struct wpi_softc *, int); |
215 |
static void wpi_read_eeprom_group(struct wpi_softc *, int); |
216 |
static int wpi_cmd(struct wpi_softc *, int, const void *, int, int); |
217 |
static int wpi_wme_update(struct ieee80211com *); |
218 |
static int wpi_mrr_setup(struct wpi_softc *); |
193 |
static int wpi_mrr_setup(struct wpi_softc *); |
|
|
194 |
static int wpi_add_node(struct wpi_softc *, struct ieee80211_node *); |
195 |
static int wpi_add_broadcast_node(struct wpi_softc *, int); |
196 |
static int wpi_updateedca(struct ieee80211com *); |
197 |
static void wpi_update_promisc(struct ifnet *); |
198 |
static void wpi_update_mcast(struct ifnet *); |
219 |
static void wpi_set_led(struct wpi_softc *, uint8_t, uint8_t, uint8_t); |
199 |
static void wpi_set_led(struct wpi_softc *, uint8_t, uint8_t, uint8_t); |
220 |
static void wpi_enable_tsf(struct wpi_softc *, struct ieee80211_node *); |
200 |
static int wpi_set_timing(struct wpi_softc *, struct ieee80211_node *); |
|
|
201 |
static void wpi_power_calibration(struct wpi_softc *); |
202 |
static int wpi_set_txpower(struct wpi_softc *, int); |
203 |
static int wpi_get_power_index(struct wpi_softc *, |
204 |
struct wpi_power_group *, struct ieee80211_channel *, int); |
205 |
static int wpi_set_pslevel(struct wpi_softc *, uint8_t, int, int); |
206 |
static int wpi_send_btcoex(struct wpi_softc *); |
207 |
static int wpi_send_rxon(struct wpi_softc *, int); |
208 |
static int wpi_config(struct wpi_softc *); |
209 |
static uint16_t wpi_get_active_dwell_time(struct wpi_softc *, |
210 |
struct ieee80211_channel *, uint8_t); |
211 |
static uint16_t wpi_limit_dwell(struct wpi_softc *, uint16_t); |
212 |
static uint16_t wpi_get_passive_dwell_time(struct wpi_softc *, |
213 |
struct ieee80211_channel *); |
214 |
static int wpi_scan(struct wpi_softc *, struct ieee80211_channel *); |
215 |
static int wpi_auth(struct wpi_softc *, struct ieee80211vap *); |
216 |
static int wpi_run(struct wpi_softc *, struct ieee80211vap *); |
221 |
#if 0 |
217 |
#if 0 |
222 |
static int wpi_setup_beacon(struct wpi_softc *, struct ieee80211_node *); |
218 |
static int wpi_key_set(struct ieee80211vap *, |
|
|
219 |
const struct ieee80211_key *, |
220 |
const uint8_t mac[IEEE80211_ADDR_LEN]); |
221 |
static int wpi_key_delete(struct ieee80211vap *, |
222 |
const struct ieee80211_key *); |
223 |
#endif |
223 |
#endif |
224 |
static int wpi_auth(struct wpi_softc *, struct ieee80211vap *); |
224 |
static int wpi_post_alive(struct wpi_softc *); |
225 |
static int wpi_run(struct wpi_softc *, struct ieee80211vap *); |
225 |
static int wpi_load_bootcode(struct wpi_softc *, const uint8_t *, int); |
226 |
static int wpi_scan(struct wpi_softc *); |
226 |
static int wpi_load_firmware(struct wpi_softc *); |
227 |
static int wpi_config(struct wpi_softc *); |
227 |
static int wpi_read_firmware(struct wpi_softc *); |
228 |
static void wpi_stop_master(struct wpi_softc *); |
228 |
static void wpi_unload_firmware(struct wpi_softc *); |
229 |
static int wpi_power_up(struct wpi_softc *); |
229 |
static int wpi_clock_wait(struct wpi_softc *); |
230 |
static int wpi_reset(struct wpi_softc *); |
230 |
static int wpi_apm_init(struct wpi_softc *); |
231 |
static void wpi_hwreset(void *, int); |
231 |
static void wpi_apm_stop_master(struct wpi_softc *); |
232 |
static void wpi_rfreset(void *, int); |
232 |
static void wpi_apm_stop(struct wpi_softc *); |
233 |
static void wpi_hw_config(struct wpi_softc *); |
233 |
static void wpi_nic_config(struct wpi_softc *); |
|
|
234 |
static int wpi_hw_init(struct wpi_softc *); |
235 |
static void wpi_hw_stop(struct wpi_softc *); |
236 |
static void wpi_radio_on(void *, int); |
237 |
static void wpi_radio_off(void *, int); |
238 |
static void wpi_init_locked(struct wpi_softc *); |
234 |
static void wpi_init(void *); |
239 |
static void wpi_init(void *); |
235 |
static void wpi_init_locked(struct wpi_softc *, int); |
240 |
static void wpi_stop_locked(struct wpi_softc *); |
236 |
static void wpi_stop(struct wpi_softc *); |
241 |
static void wpi_stop(struct wpi_softc *); |
237 |
static void wpi_stop_locked(struct wpi_softc *); |
242 |
static void wpi_scan_start(struct ieee80211com *); |
|
|
243 |
static void wpi_scan_end(struct ieee80211com *); |
244 |
static void wpi_set_channel(struct ieee80211com *); |
245 |
static void wpi_scan_curchan(struct ieee80211_scan_state *, unsigned long); |
246 |
static void wpi_scan_mindwell(struct ieee80211_scan_state *); |
247 |
static void wpi_hw_reset(void *, int); |
238 |
|
248 |
|
239 |
static int wpi_set_txpower(struct wpi_softc *, struct ieee80211_channel *, |
|
|
240 |
int); |
241 |
static void wpi_calib_timeout(void *); |
242 |
static void wpi_power_calibration(struct wpi_softc *, int); |
243 |
static int wpi_get_power_index(struct wpi_softc *, |
244 |
struct wpi_power_group *, struct ieee80211_channel *, int); |
245 |
#ifdef WPI_DEBUG |
246 |
static const char *wpi_cmd_str(int); |
247 |
#endif |
248 |
static int wpi_probe(device_t); |
249 |
static int wpi_attach(device_t); |
250 |
static int wpi_detach(device_t); |
251 |
static int wpi_shutdown(device_t); |
252 |
static int wpi_suspend(device_t); |
253 |
static int wpi_resume(device_t); |
254 |
|
255 |
static device_method_t wpi_methods[] = { |
249 |
static device_method_t wpi_methods[] = { |
256 |
/* Device interface */ |
250 |
/* Device interface */ |
257 |
DEVMETHOD(device_probe, wpi_probe), |
251 |
DEVMETHOD(device_probe, wpi_probe), |
Lines 269-275
Link Here
|
269 |
wpi_methods, |
263 |
wpi_methods, |
270 |
sizeof (struct wpi_softc) |
264 |
sizeof (struct wpi_softc) |
271 |
}; |
265 |
}; |
272 |
|
|
|
273 |
static devclass_t wpi_devclass; |
266 |
static devclass_t wpi_devclass; |
274 |
|
267 |
|
275 |
DRIVER_MODULE(wpi, pci, wpi_driver, wpi_devclass, NULL, NULL); |
268 |
DRIVER_MODULE(wpi, pci, wpi_driver, wpi_devclass, NULL, NULL); |
Lines 276-294
Link Here
|
276 |
|
269 |
|
277 |
MODULE_VERSION(wpi, 1); |
270 |
MODULE_VERSION(wpi, 1); |
278 |
|
271 |
|
279 |
static const uint8_t wpi_ridx_to_plcp[] = { |
272 |
MODULE_DEPEND(wpi, pci, 1, 1, 1); |
280 |
/* OFDM: IEEE Std 802.11a-1999, pp. 14 Table 80 */ |
273 |
MODULE_DEPEND(wpi, wlan, 1, 1, 1); |
281 |
/* R1-R4 (ral/ural is R4-R1) */ |
274 |
MODULE_DEPEND(wpi, firmware, 1, 1, 1); |
282 |
0xd, 0xf, 0x5, 0x7, 0x9, 0xb, 0x1, 0x3, |
|
|
283 |
/* CCK: device-dependent */ |
284 |
10, 20, 55, 110 |
285 |
}; |
286 |
|
275 |
|
287 |
static const uint8_t wpi_ridx_to_rate[] = { |
|
|
288 |
12, 18, 24, 36, 48, 72, 96, 108, /* OFDM */ |
289 |
2, 4, 11, 22 /*CCK */ |
290 |
}; |
291 |
|
292 |
static int |
276 |
static int |
293 |
wpi_probe(device_t dev) |
277 |
wpi_probe(device_t dev) |
294 |
{ |
278 |
{ |
Lines 304-507
Link Here
|
304 |
return ENXIO; |
288 |
return ENXIO; |
305 |
} |
289 |
} |
306 |
|
290 |
|
307 |
/** |
|
|
308 |
* Load the firmare image from disk to the allocated dma buffer. |
309 |
* we also maintain the reference to the firmware pointer as there |
310 |
* is times where we may need to reload the firmware but we are not |
311 |
* in a context that can access the filesystem (ie taskq cause by restart) |
312 |
* |
313 |
* @return 0 on success, an errno on failure |
314 |
*/ |
315 |
static int |
291 |
static int |
316 |
wpi_load_firmware(struct wpi_softc *sc) |
|
|
317 |
{ |
318 |
const struct firmware *fp; |
319 |
struct wpi_dma_info *dma = &sc->fw_dma; |
320 |
const struct wpi_firmware_hdr *hdr; |
321 |
const uint8_t *itext, *idata, *rtext, *rdata, *btext; |
322 |
uint32_t itextsz, idatasz, rtextsz, rdatasz, btextsz; |
323 |
int error; |
324 |
|
325 |
DPRINTFN(WPI_DEBUG_FIRMWARE, |
326 |
("Attempting Loading Firmware from wpi_fw module\n")); |
327 |
|
328 |
WPI_UNLOCK(sc); |
329 |
|
330 |
if (sc->fw_fp == NULL && (sc->fw_fp = firmware_get("wpifw")) == NULL) { |
331 |
device_printf(sc->sc_dev, |
332 |
"could not load firmware image 'wpifw'\n"); |
333 |
error = ENOENT; |
334 |
WPI_LOCK(sc); |
335 |
goto fail; |
336 |
} |
337 |
|
338 |
fp = sc->fw_fp; |
339 |
|
340 |
WPI_LOCK(sc); |
341 |
|
342 |
/* Validate the firmware is minimum a particular version */ |
343 |
if (fp->version < WPI_FW_MINVERSION) { |
344 |
device_printf(sc->sc_dev, |
345 |
"firmware version is too old. Need %d, got %d\n", |
346 |
WPI_FW_MINVERSION, |
347 |
fp->version); |
348 |
error = ENXIO; |
349 |
goto fail; |
350 |
} |
351 |
|
352 |
if (fp->datasize < sizeof (struct wpi_firmware_hdr)) { |
353 |
device_printf(sc->sc_dev, |
354 |
"firmware file too short: %zu bytes\n", fp->datasize); |
355 |
error = ENXIO; |
356 |
goto fail; |
357 |
} |
358 |
|
359 |
hdr = (const struct wpi_firmware_hdr *)fp->data; |
360 |
|
361 |
/* | RUNTIME FIRMWARE | INIT FIRMWARE | BOOT FW | |
362 |
|HDR|<--TEXT-->|<--DATA-->|<--TEXT-->|<--DATA-->|<--TEXT-->| */ |
363 |
|
364 |
rtextsz = le32toh(hdr->rtextsz); |
365 |
rdatasz = le32toh(hdr->rdatasz); |
366 |
itextsz = le32toh(hdr->itextsz); |
367 |
idatasz = le32toh(hdr->idatasz); |
368 |
btextsz = le32toh(hdr->btextsz); |
369 |
|
370 |
/* check that all firmware segments are present */ |
371 |
if (fp->datasize < sizeof (struct wpi_firmware_hdr) + |
372 |
rtextsz + rdatasz + itextsz + idatasz + btextsz) { |
373 |
device_printf(sc->sc_dev, |
374 |
"firmware file too short: %zu bytes\n", fp->datasize); |
375 |
error = ENXIO; /* XXX appropriate error code? */ |
376 |
goto fail; |
377 |
} |
378 |
|
379 |
/* get pointers to firmware segments */ |
380 |
rtext = (const uint8_t *)(hdr + 1); |
381 |
rdata = rtext + rtextsz; |
382 |
itext = rdata + rdatasz; |
383 |
idata = itext + itextsz; |
384 |
btext = idata + idatasz; |
385 |
|
386 |
DPRINTFN(WPI_DEBUG_FIRMWARE, |
387 |
("Firmware Version: Major %d, Minor %d, Driver %d, \n" |
388 |
"runtime (text: %u, data: %u) init (text: %u, data %u) boot (text %u)\n", |
389 |
(le32toh(hdr->version) & 0xff000000) >> 24, |
390 |
(le32toh(hdr->version) & 0x00ff0000) >> 16, |
391 |
(le32toh(hdr->version) & 0x0000ffff), |
392 |
rtextsz, rdatasz, |
393 |
itextsz, idatasz, btextsz)); |
394 |
|
395 |
DPRINTFN(WPI_DEBUG_FIRMWARE,("rtext 0x%x\n", *(const uint32_t *)rtext)); |
396 |
DPRINTFN(WPI_DEBUG_FIRMWARE,("rdata 0x%x\n", *(const uint32_t *)rdata)); |
397 |
DPRINTFN(WPI_DEBUG_FIRMWARE,("itext 0x%x\n", *(const uint32_t *)itext)); |
398 |
DPRINTFN(WPI_DEBUG_FIRMWARE,("idata 0x%x\n", *(const uint32_t *)idata)); |
399 |
DPRINTFN(WPI_DEBUG_FIRMWARE,("btext 0x%x\n", *(const uint32_t *)btext)); |
400 |
|
401 |
/* sanity checks */ |
402 |
if (rtextsz > WPI_FW_MAIN_TEXT_MAXSZ || |
403 |
rdatasz > WPI_FW_MAIN_DATA_MAXSZ || |
404 |
itextsz > WPI_FW_INIT_TEXT_MAXSZ || |
405 |
idatasz > WPI_FW_INIT_DATA_MAXSZ || |
406 |
btextsz > WPI_FW_BOOT_TEXT_MAXSZ || |
407 |
(btextsz & 3) != 0) { |
408 |
device_printf(sc->sc_dev, "firmware invalid\n"); |
409 |
error = EINVAL; |
410 |
goto fail; |
411 |
} |
412 |
|
413 |
/* copy initialization images into pre-allocated DMA-safe memory */ |
414 |
memcpy(dma->vaddr, idata, idatasz); |
415 |
memcpy(dma->vaddr + WPI_FW_INIT_DATA_MAXSZ, itext, itextsz); |
416 |
|
417 |
bus_dmamap_sync(dma->tag, dma->map, BUS_DMASYNC_PREWRITE); |
418 |
|
419 |
/* tell adapter where to find initialization images */ |
420 |
wpi_mem_lock(sc); |
421 |
wpi_mem_write(sc, WPI_MEM_DATA_BASE, dma->paddr); |
422 |
wpi_mem_write(sc, WPI_MEM_DATA_SIZE, idatasz); |
423 |
wpi_mem_write(sc, WPI_MEM_TEXT_BASE, |
424 |
dma->paddr + WPI_FW_INIT_DATA_MAXSZ); |
425 |
wpi_mem_write(sc, WPI_MEM_TEXT_SIZE, itextsz); |
426 |
wpi_mem_unlock(sc); |
427 |
|
428 |
/* load firmware boot code */ |
429 |
if ((error = wpi_load_microcode(sc, btext, btextsz)) != 0) { |
430 |
device_printf(sc->sc_dev, "Failed to load microcode\n"); |
431 |
goto fail; |
432 |
} |
433 |
|
434 |
/* now press "execute" */ |
435 |
WPI_WRITE(sc, WPI_RESET, 0); |
436 |
|
437 |
/* wait at most one second for the first alive notification */ |
438 |
if ((error = msleep(sc, &sc->sc_mtx, PCATCH, "wpiinit", hz)) != 0) { |
439 |
device_printf(sc->sc_dev, |
440 |
"timeout waiting for adapter to initialize\n"); |
441 |
goto fail; |
442 |
} |
443 |
|
444 |
/* copy runtime images into pre-allocated DMA-sage memory */ |
445 |
memcpy(dma->vaddr, rdata, rdatasz); |
446 |
memcpy(dma->vaddr + WPI_FW_MAIN_DATA_MAXSZ, rtext, rtextsz); |
447 |
bus_dmamap_sync(dma->tag, dma->map, BUS_DMASYNC_PREWRITE); |
448 |
|
449 |
/* tell adapter where to find runtime images */ |
450 |
wpi_mem_lock(sc); |
451 |
wpi_mem_write(sc, WPI_MEM_DATA_BASE, dma->paddr); |
452 |
wpi_mem_write(sc, WPI_MEM_DATA_SIZE, rdatasz); |
453 |
wpi_mem_write(sc, WPI_MEM_TEXT_BASE, |
454 |
dma->paddr + WPI_FW_MAIN_DATA_MAXSZ); |
455 |
wpi_mem_write(sc, WPI_MEM_TEXT_SIZE, WPI_FW_UPDATED | rtextsz); |
456 |
wpi_mem_unlock(sc); |
457 |
|
458 |
/* wait at most one second for the first alive notification */ |
459 |
if ((error = msleep(sc, &sc->sc_mtx, PCATCH, "wpiinit", hz)) != 0) { |
460 |
device_printf(sc->sc_dev, |
461 |
"timeout waiting for adapter to initialize2\n"); |
462 |
goto fail; |
463 |
} |
464 |
|
465 |
DPRINTFN(WPI_DEBUG_FIRMWARE, |
466 |
("Firmware loaded to driver successfully\n")); |
467 |
return error; |
468 |
fail: |
469 |
wpi_unload_firmware(sc); |
470 |
return error; |
471 |
} |
472 |
|
473 |
/** |
474 |
* Free the referenced firmware image |
475 |
*/ |
476 |
static void |
477 |
wpi_unload_firmware(struct wpi_softc *sc) |
478 |
{ |
479 |
|
480 |
if (sc->fw_fp) { |
481 |
WPI_UNLOCK(sc); |
482 |
firmware_put(sc->fw_fp, FIRMWARE_UNLOAD); |
483 |
WPI_LOCK(sc); |
484 |
sc->fw_fp = NULL; |
485 |
} |
486 |
} |
487 |
|
488 |
static int |
489 |
wpi_attach(device_t dev) |
292 |
wpi_attach(device_t dev) |
490 |
{ |
293 |
{ |
491 |
struct wpi_softc *sc = device_get_softc(dev); |
294 |
struct wpi_softc *sc = (struct wpi_softc *)device_get_softc(dev); |
|
|
295 |
struct ieee80211com *ic; |
492 |
struct ifnet *ifp; |
296 |
struct ifnet *ifp; |
493 |
struct ieee80211com *ic; |
297 |
int i, error, rid, supportsa = 1; |
494 |
int ac, error, rid, supportsa = 1; |
|
|
495 |
uint32_t tmp; |
496 |
const struct wpi_ident *ident; |
298 |
const struct wpi_ident *ident; |
497 |
uint8_t macaddr[IEEE80211_ADDR_LEN]; |
299 |
uint8_t macaddr[IEEE80211_ADDR_LEN]; |
498 |
|
300 |
|
499 |
sc->sc_dev = dev; |
301 |
sc->sc_dev = dev; |
500 |
|
302 |
|
501 |
if (bootverbose || WPI_DEBUG_SET) |
303 |
#ifdef WPI_DEBUG |
502 |
device_printf(sc->sc_dev,"Driver Revision %s\n", VERSION); |
304 |
error = resource_int_value(device_get_name(sc->sc_dev), |
|
|
305 |
device_get_unit(sc->sc_dev), "debug", &(sc->sc_debug)); |
306 |
if (error != 0) |
307 |
sc->sc_debug = 0; |
308 |
#else |
309 |
sc->sc_debug = 0; |
310 |
#endif |
503 |
|
311 |
|
|
|
312 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__); |
313 |
|
504 |
/* |
314 |
/* |
|
|
315 |
* Get the offset of the PCI Express Capability Structure in PCI |
316 |
* Configuration Space. |
317 |
*/ |
318 |
error = pci_find_cap(dev, PCIY_EXPRESS, &sc->sc_cap_off); |
319 |
if (error != 0) { |
320 |
device_printf(dev, "PCIe capability structure not found!\n"); |
321 |
return error; |
322 |
} |
323 |
|
324 |
/* |
505 |
* Some card's only support 802.11b/g not a, check to see if |
325 |
* Some card's only support 802.11b/g not a, check to see if |
506 |
* this is one such card. A 0x0 in the subdevice table indicates |
326 |
* this is one such card. A 0x0 in the subdevice table indicates |
507 |
* the entire subdevice range is to be ignored. |
327 |
* the entire subdevice range is to be ignored. |
Lines 514-532
Link Here
|
514 |
} |
334 |
} |
515 |
} |
335 |
} |
516 |
|
336 |
|
517 |
/* Create the tasks that can be queued */ |
337 |
/* Clear device-specific "PCI retry timeout" register (41h). */ |
518 |
TASK_INIT(&sc->sc_restarttask, 0, wpi_hwreset, sc); |
|
|
519 |
TASK_INIT(&sc->sc_radiotask, 0, wpi_rfreset, sc); |
520 |
|
521 |
WPI_LOCK_INIT(sc); |
522 |
|
523 |
callout_init_mtx(&sc->calib_to, &sc->sc_mtx, 0); |
524 |
callout_init_mtx(&sc->watchdog_to, &sc->sc_mtx, 0); |
525 |
|
526 |
/* disable the retry timeout register */ |
527 |
pci_write_config(dev, 0x41, 0, 1); |
338 |
pci_write_config(dev, 0x41, 0, 1); |
528 |
|
339 |
|
529 |
/* enable bus-mastering */ |
340 |
/* Enable bus-mastering. */ |
530 |
pci_enable_busmaster(dev); |
341 |
pci_enable_busmaster(dev); |
531 |
|
342 |
|
532 |
rid = PCIR_BAR(0); |
343 |
rid = PCIR_BAR(0); |
Lines 533-644
Link Here
|
533 |
sc->mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, |
344 |
sc->mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, |
534 |
RF_ACTIVE); |
345 |
RF_ACTIVE); |
535 |
if (sc->mem == NULL) { |
346 |
if (sc->mem == NULL) { |
536 |
device_printf(dev, "could not allocate memory resource\n"); |
347 |
device_printf(dev, "can't map mem space\n"); |
537 |
error = ENOMEM; |
348 |
error = ENOMEM; |
538 |
goto fail; |
349 |
return error; |
539 |
} |
350 |
} |
540 |
|
|
|
541 |
sc->sc_st = rman_get_bustag(sc->mem); |
351 |
sc->sc_st = rman_get_bustag(sc->mem); |
542 |
sc->sc_sh = rman_get_bushandle(sc->mem); |
352 |
sc->sc_sh = rman_get_bushandle(sc->mem); |
543 |
|
353 |
|
|
|
354 |
i = 1; |
544 |
rid = 0; |
355 |
rid = 0; |
545 |
sc->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, |
356 |
if (pci_alloc_msi(dev, &i) == 0) |
546 |
RF_ACTIVE | RF_SHAREABLE); |
357 |
rid = 1; |
|
|
358 |
/* Install interrupt handler. */ |
359 |
sc->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE | |
360 |
(rid != 0 ? 0 : RF_SHAREABLE)); |
547 |
if (sc->irq == NULL) { |
361 |
if (sc->irq == NULL) { |
548 |
device_printf(dev, "could not allocate interrupt resource\n"); |
362 |
device_printf(dev, "can't map interrupt\n"); |
549 |
error = ENOMEM; |
363 |
error = ENOMEM; |
550 |
goto fail; |
364 |
goto fail; |
551 |
} |
365 |
} |
552 |
|
366 |
|
553 |
/* |
367 |
WPI_LOCK_INIT(sc); |
554 |
* Allocate DMA memory for firmware transfers. |
368 |
|
555 |
*/ |
369 |
/* Allocate DMA memory for firmware transfers. */ |
556 |
if ((error = wpi_alloc_fwmem(sc)) != 0) { |
370 |
if ((error = wpi_alloc_fwmem(sc)) != 0) { |
557 |
printf(": could not allocate firmware memory\n"); |
371 |
device_printf(dev, |
558 |
error = ENOMEM; |
372 |
"could not allocate memory for firmware, error %d\n", |
|
|
373 |
error); |
559 |
goto fail; |
374 |
goto fail; |
560 |
} |
375 |
} |
561 |
|
376 |
|
562 |
/* |
377 |
/* Allocate shared page. */ |
563 |
* Put adapter into a known state. |
|
|
564 |
*/ |
565 |
if ((error = wpi_reset(sc)) != 0) { |
566 |
device_printf(dev, "could not reset adapter\n"); |
567 |
goto fail; |
568 |
} |
569 |
|
570 |
wpi_mem_lock(sc); |
571 |
tmp = wpi_mem_read(sc, WPI_MEM_PCIDEV); |
572 |
if (bootverbose || WPI_DEBUG_SET) |
573 |
device_printf(sc->sc_dev, "Hardware Revision (0x%X)\n", tmp); |
574 |
|
575 |
wpi_mem_unlock(sc); |
576 |
|
577 |
/* Allocate shared page */ |
578 |
if ((error = wpi_alloc_shared(sc)) != 0) { |
378 |
if ((error = wpi_alloc_shared(sc)) != 0) { |
579 |
device_printf(dev, "could not allocate shared page\n"); |
379 |
device_printf(dev, "could not allocate shared page\n"); |
580 |
goto fail; |
380 |
goto fail; |
581 |
} |
381 |
} |
582 |
|
382 |
|
583 |
/* tx data queues - 4 for QoS purposes */ |
383 |
/* Allocate TX rings - 4 for QoS purposes, 1 for commands. */ |
584 |
for (ac = 0; ac < WME_NUM_AC; ac++) { |
384 |
for (i = 0; i < WPI_NTXQUEUES; i++) { |
585 |
error = wpi_alloc_tx_ring(sc, &sc->txq[ac], WPI_TX_RING_COUNT, ac); |
385 |
if ((error = wpi_alloc_tx_ring(sc, &sc->txq[i], i)) != 0) { |
586 |
if (error != 0) { |
386 |
device_printf(dev, |
587 |
device_printf(dev, "could not allocate Tx ring %d\n",ac); |
387 |
"could not allocate TX ring %d, error %d\n", i, |
588 |
goto fail; |
388 |
error); |
|
|
389 |
goto fail; |
589 |
} |
390 |
} |
590 |
} |
391 |
} |
591 |
|
392 |
|
592 |
/* command queue to talk to the card's firmware */ |
393 |
/* Allocate RX ring. */ |
593 |
error = wpi_alloc_tx_ring(sc, &sc->cmdq, WPI_CMD_RING_COUNT, 4); |
394 |
if ((error = wpi_alloc_rx_ring(sc)) != 0) { |
594 |
if (error != 0) { |
395 |
device_printf(dev, "could not allocate RX ring, error %d\n", |
595 |
device_printf(dev, "could not allocate command ring\n"); |
396 |
error); |
596 |
goto fail; |
397 |
goto fail; |
597 |
} |
398 |
} |
598 |
|
399 |
|
599 |
/* receive data queue */ |
400 |
/* Clear pending interrupts. */ |
600 |
error = wpi_alloc_rx_ring(sc, &sc->rxq); |
401 |
WPI_WRITE(sc, WPI_INT, 0xffffffff); |
601 |
if (error != 0) { |
|
|
602 |
device_printf(dev, "could not allocate Rx ring\n"); |
603 |
goto fail; |
604 |
} |
605 |
|
402 |
|
606 |
ifp = sc->sc_ifp = if_alloc(IFT_IEEE80211); |
403 |
ifp = sc->sc_ifp = if_alloc(IFT_IEEE80211); |
607 |
if (ifp == NULL) { |
404 |
if (ifp == NULL) { |
608 |
device_printf(dev, "can not if_alloc()\n"); |
405 |
device_printf(dev, "can not allocate ifnet structure\n"); |
609 |
error = ENOMEM; |
|
|
610 |
goto fail; |
406 |
goto fail; |
611 |
} |
407 |
} |
|
|
408 |
|
612 |
ic = ifp->if_l2com; |
409 |
ic = ifp->if_l2com; |
613 |
|
|
|
614 |
ic->ic_ifp = ifp; |
410 |
ic->ic_ifp = ifp; |
615 |
ic->ic_phytype = IEEE80211_T_OFDM; /* not only, but not used */ |
411 |
ic->ic_phytype = IEEE80211_T_OFDM; /* not only, but not used */ |
616 |
ic->ic_opmode = IEEE80211_M_STA; /* default to BSS mode */ |
412 |
ic->ic_opmode = IEEE80211_M_STA; /* default to BSS mode */ |
617 |
|
413 |
|
618 |
/* set device capabilities */ |
414 |
/* Set device capabilities. */ |
619 |
ic->ic_caps = |
415 |
ic->ic_caps = |
620 |
IEEE80211_C_STA /* station mode supported */ |
416 |
IEEE80211_C_STA /* station mode supported */ |
621 |
| IEEE80211_C_MONITOR /* monitor mode supported */ |
417 |
| IEEE80211_C_MONITOR /* monitor mode supported */ |
|
|
418 |
| IEEE80211_C_BGSCAN /* capable of bg scanning */ |
622 |
| IEEE80211_C_TXPMGT /* tx power management */ |
419 |
| IEEE80211_C_TXPMGT /* tx power management */ |
623 |
| IEEE80211_C_SHSLOT /* short slot time supported */ |
420 |
| IEEE80211_C_SHSLOT /* short slot time supported */ |
|
|
421 |
| IEEE80211_C_WPA /* 802.11i */ |
624 |
| IEEE80211_C_SHPREAMBLE /* short preamble supported */ |
422 |
| IEEE80211_C_SHPREAMBLE /* short preamble supported */ |
625 |
| IEEE80211_C_WPA /* 802.11i */ |
|
|
626 |
/* XXX looks like WME is partly supported? */ |
627 |
#if 0 |
423 |
#if 0 |
628 |
| IEEE80211_C_IBSS /* IBSS mode support */ |
424 |
| IEEE80211_C_IBSS /* IBSS mode support */ |
629 |
| IEEE80211_C_BGSCAN /* capable of bg scanning */ |
|
|
630 |
| IEEE80211_C_WME /* 802.11e */ |
631 |
| IEEE80211_C_HOSTAP /* Host access point mode */ |
425 |
| IEEE80211_C_HOSTAP /* Host access point mode */ |
632 |
#endif |
426 |
#endif |
|
|
427 |
| IEEE80211_C_WME /* 802.11e */ |
428 |
| IEEE80211_C_PMGT /* Station-side power mgmt */ |
633 |
; |
429 |
; |
634 |
|
430 |
#if 0 |
|
|
431 |
ic->ic_cryptocaps = |
432 |
IEEE80211_CRYPTO_AES_CCM; |
433 |
#endif |
635 |
/* |
434 |
/* |
636 |
* Read in the eeprom and also setup the channels for |
435 |
* Read in the eeprom and also setup the channels for |
637 |
* net80211. We don't set the rates as net80211 does this for us |
436 |
* net80211. We don't set the rates as net80211 does this for us |
638 |
*/ |
437 |
*/ |
639 |
wpi_read_eeprom(sc, macaddr); |
438 |
if ((error = wpi_read_eeprom(sc, macaddr)) != 0) { |
|
|
439 |
device_printf(dev, "could not read EEPROM, error %d\n", |
440 |
error); |
441 |
goto fail; |
442 |
} |
640 |
|
443 |
|
641 |
if (bootverbose || WPI_DEBUG_SET) { |
444 |
#ifdef WPI_DEBUG |
|
|
445 |
if (bootverbose) { |
642 |
device_printf(sc->sc_dev, "Regulatory Domain: %.4s\n", sc->domain); |
446 |
device_printf(sc->sc_dev, "Regulatory Domain: %.4s\n", sc->domain); |
643 |
device_printf(sc->sc_dev, "Hardware Type: %c\n", |
447 |
device_printf(sc->sc_dev, "Hardware Type: %c\n", |
644 |
sc->type > 1 ? 'B': '?'); |
448 |
sc->type > 1 ? 'B': '?'); |
Lines 650-655
Link Here
|
650 |
/* XXX hw_config uses the PCIDEV for the Hardware rev. Must check |
454 |
/* XXX hw_config uses the PCIDEV for the Hardware rev. Must check |
651 |
what sc->rev really represents - benjsc 20070615 */ |
455 |
what sc->rev really represents - benjsc 20070615 */ |
652 |
} |
456 |
} |
|
|
457 |
#endif |
653 |
|
458 |
|
654 |
if_initname(ifp, device_get_name(dev), device_get_unit(dev)); |
459 |
if_initname(ifp, device_get_name(dev), device_get_unit(dev)); |
655 |
ifp->if_softc = sc; |
460 |
ifp->if_softc = sc; |
Lines 662-706
Link Here
|
662 |
IFQ_SET_READY(&ifp->if_snd); |
467 |
IFQ_SET_READY(&ifp->if_snd); |
663 |
|
468 |
|
664 |
ieee80211_ifattach(ic, macaddr); |
469 |
ieee80211_ifattach(ic, macaddr); |
665 |
/* override default methods */ |
470 |
ic->ic_vap_create = wpi_vap_create; |
|
|
471 |
ic->ic_vap_delete = wpi_vap_delete; |
666 |
ic->ic_raw_xmit = wpi_raw_xmit; |
472 |
ic->ic_raw_xmit = wpi_raw_xmit; |
667 |
ic->ic_wme.wme_update = wpi_wme_update; |
473 |
ic->ic_node_alloc = wpi_node_alloc; |
|
|
474 |
ic->ic_wme.wme_update = wpi_updateedca; |
475 |
ic->ic_update_promisc = wpi_update_promisc; |
476 |
ic->ic_update_mcast = wpi_update_mcast; |
668 |
ic->ic_scan_start = wpi_scan_start; |
477 |
ic->ic_scan_start = wpi_scan_start; |
669 |
ic->ic_scan_end = wpi_scan_end; |
478 |
ic->ic_scan_end = wpi_scan_end; |
670 |
ic->ic_set_channel = wpi_set_channel; |
479 |
ic->ic_set_channel = wpi_set_channel; |
|
|
480 |
sc->sc_scan_curchan = ic->ic_scan_curchan; |
671 |
ic->ic_scan_curchan = wpi_scan_curchan; |
481 |
ic->ic_scan_curchan = wpi_scan_curchan; |
672 |
ic->ic_scan_mindwell = wpi_scan_mindwell; |
482 |
ic->ic_scan_mindwell = wpi_scan_mindwell; |
673 |
|
483 |
|
674 |
ic->ic_vap_create = wpi_vap_create; |
484 |
wpi_radiotap_attach(sc); |
675 |
ic->ic_vap_delete = wpi_vap_delete; |
|
|
676 |
|
485 |
|
677 |
ieee80211_radiotap_attach(ic, |
486 |
callout_init_mtx(&sc->calib_to, &sc->sc_mtx, 0); |
678 |
&sc->sc_txtap.wt_ihdr, sizeof(sc->sc_txtap), |
487 |
callout_init_mtx(&sc->watchdog_to, &sc->sc_mtx, 0); |
679 |
WPI_TX_RADIOTAP_PRESENT, |
488 |
callout_init_mtx(&sc->watchdog_rfkill, &sc->sc_mtx, 0); |
680 |
&sc->sc_rxtap.wr_ihdr, sizeof(sc->sc_rxtap), |
489 |
TASK_INIT(&sc->sc_reinittask, 0, wpi_hw_reset, sc); |
681 |
WPI_RX_RADIOTAP_PRESENT); |
490 |
TASK_INIT(&sc->sc_radiooff_task, 0, wpi_radio_off, sc); |
|
|
491 |
TASK_INIT(&sc->sc_radioon_task, 0, wpi_radio_on, sc); |
682 |
|
492 |
|
|
|
493 |
wpi_sysctlattach(sc); |
494 |
|
683 |
/* |
495 |
/* |
684 |
* Hook our interrupt after all initialization is complete. |
496 |
* Hook our interrupt after all initialization is complete. |
685 |
*/ |
497 |
*/ |
686 |
error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET |INTR_MPSAFE, |
498 |
error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET | INTR_MPSAFE, |
687 |
NULL, wpi_intr, sc, &sc->sc_ih); |
499 |
NULL, wpi_intr, sc, &sc->sc_ih); |
688 |
if (error != 0) { |
500 |
if (error != 0) { |
689 |
device_printf(dev, "could not set up interrupt\n"); |
501 |
device_printf(dev, "can't establish interrupt, error %d\n", |
|
|
502 |
error); |
690 |
goto fail; |
503 |
goto fail; |
691 |
} |
504 |
} |
692 |
|
505 |
|
693 |
if (bootverbose) |
506 |
if (bootverbose) |
694 |
ieee80211_announce(ic); |
507 |
ieee80211_announce(ic); |
695 |
#ifdef XXX_DEBUG |
508 |
|
696 |
ieee80211_announce_channels(ic); |
509 |
#ifdef WPI_DEBUG |
|
|
510 |
if (sc->sc_debug & WPI_DEBUG_HW) |
511 |
ieee80211_announce_channels(ic); |
697 |
#endif |
512 |
#endif |
|
|
513 |
|
514 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__); |
698 |
return 0; |
515 |
return 0; |
699 |
|
516 |
|
700 |
fail: wpi_detach(dev); |
517 |
fail: wpi_detach(dev); |
701 |
return ENXIO; |
518 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END_ERR, __func__); |
|
|
519 |
return error; |
702 |
} |
520 |
} |
703 |
|
521 |
|
|
|
522 |
/* |
523 |
* Attach the interface to 802.11 radiotap. |
524 |
*/ |
525 |
static void |
526 |
wpi_radiotap_attach(struct wpi_softc *sc) |
527 |
{ |
528 |
struct ifnet *ifp = sc->sc_ifp; |
529 |
struct ieee80211com *ic = ifp->if_l2com; |
530 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__); |
531 |
ieee80211_radiotap_attach(ic, |
532 |
&sc->sc_txtap.wt_ihdr, sizeof(sc->sc_txtap), |
533 |
WPI_TX_RADIOTAP_PRESENT, |
534 |
&sc->sc_rxtap.wr_ihdr, sizeof(sc->sc_rxtap), |
535 |
WPI_RX_RADIOTAP_PRESENT); |
536 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__); |
537 |
} |
538 |
|
539 |
static void |
540 |
wpi_sysctlattach(struct wpi_softc *sc) |
541 |
{ |
542 |
#ifdef WPI_DEBUG |
543 |
struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(sc->sc_dev); |
544 |
struct sysctl_oid *tree = device_get_sysctl_tree(sc->sc_dev); |
545 |
|
546 |
SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, |
547 |
"debug", CTLFLAG_RW, &sc->sc_debug, sc->sc_debug, |
548 |
"control debugging printfs"); |
549 |
#endif |
550 |
} |
551 |
|
552 |
static struct ieee80211vap * |
553 |
wpi_vap_create(struct ieee80211com *ic, const char name[IFNAMSIZ], int unit, |
554 |
enum ieee80211_opmode opmode, int flags, |
555 |
const uint8_t bssid[IEEE80211_ADDR_LEN], |
556 |
const uint8_t mac[IEEE80211_ADDR_LEN]) |
557 |
{ |
558 |
struct wpi_vap *wvp; |
559 |
struct ieee80211vap *vap; |
560 |
|
561 |
if (!TAILQ_EMPTY(&ic->ic_vaps)) /* only one at a time */ |
562 |
return NULL; |
563 |
|
564 |
wvp = (struct wpi_vap *) malloc(sizeof(struct wpi_vap), |
565 |
M_80211_VAP, M_NOWAIT | M_ZERO); |
566 |
if (wvp == NULL) |
567 |
return NULL; |
568 |
vap = &wvp->vap; |
569 |
ieee80211_vap_setup(ic, vap, name, unit, opmode, flags, bssid, mac); |
570 |
|
571 |
/* Override with driver methods. */ |
572 |
wvp->newstate = vap->iv_newstate; |
573 |
#if 0 |
574 |
vap->iv_key_delete = wpi_key_delete; |
575 |
vap->iv_key_set = wpi_key_set; |
576 |
#endif |
577 |
vap->iv_newstate = wpi_newstate; |
578 |
|
579 |
ieee80211_ratectl_init(vap); |
580 |
/* Complete setup. */ |
581 |
ieee80211_vap_attach(vap, ieee80211_media_change, ieee80211_media_status); |
582 |
ic->ic_opmode = opmode; |
583 |
return vap; |
584 |
} |
585 |
|
586 |
static void |
587 |
wpi_vap_delete(struct ieee80211vap *vap) |
588 |
{ |
589 |
struct wpi_vap *wvp = WPI_VAP(vap); |
590 |
|
591 |
ieee80211_ratectl_deinit(vap); |
592 |
ieee80211_vap_detach(vap); |
593 |
free(wvp, M_80211_VAP); |
594 |
} |
595 |
|
704 |
static int |
596 |
static int |
705 |
wpi_detach(device_t dev) |
597 |
wpi_detach(device_t dev) |
706 |
{ |
598 |
{ |
Lines 707-749
Link Here
|
707 |
struct wpi_softc *sc = device_get_softc(dev); |
599 |
struct wpi_softc *sc = device_get_softc(dev); |
708 |
struct ifnet *ifp = sc->sc_ifp; |
600 |
struct ifnet *ifp = sc->sc_ifp; |
709 |
struct ieee80211com *ic; |
601 |
struct ieee80211com *ic; |
710 |
int ac; |
602 |
int qid; |
711 |
|
603 |
|
712 |
if (sc->irq != NULL) |
604 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__); |
713 |
bus_teardown_intr(dev, sc->irq, sc->sc_ih); |
|
|
714 |
|
605 |
|
715 |
if (ifp != NULL) { |
606 |
if (ifp != NULL) { |
716 |
ic = ifp->if_l2com; |
607 |
ic = ifp->if_l2com; |
717 |
|
608 |
|
718 |
ieee80211_draintask(ic, &sc->sc_restarttask); |
609 |
ieee80211_draintask(ic, &sc->sc_reinittask); |
719 |
ieee80211_draintask(ic, &sc->sc_radiotask); |
610 |
ieee80211_draintask(ic, &sc->sc_radiooff_task); |
|
|
611 |
|
720 |
wpi_stop(sc); |
612 |
wpi_stop(sc); |
|
|
613 |
|
721 |
callout_drain(&sc->watchdog_to); |
614 |
callout_drain(&sc->watchdog_to); |
|
|
615 |
callout_drain(&sc->watchdog_rfkill); |
722 |
callout_drain(&sc->calib_to); |
616 |
callout_drain(&sc->calib_to); |
723 |
ieee80211_ifdetach(ic); |
617 |
ieee80211_ifdetach(ic); |
724 |
} |
618 |
} |
725 |
|
619 |
|
|
|
620 |
/* Uninstall interrupt handler. */ |
621 |
if (sc->irq != NULL) { |
622 |
bus_teardown_intr(dev, sc->irq, sc->sc_ih); |
623 |
bus_release_resource(dev, SYS_RES_IRQ, rman_get_rid(sc->irq), |
624 |
sc->irq); |
625 |
pci_release_msi(dev); |
626 |
} |
627 |
|
726 |
WPI_LOCK(sc); |
628 |
WPI_LOCK(sc); |
727 |
if (sc->txq[0].data_dmat) { |
629 |
if (sc->txq[0].data_dmat) { |
728 |
for (ac = 0; ac < WME_NUM_AC; ac++) |
630 |
/* Free DMA resources. */ |
729 |
wpi_free_tx_ring(sc, &sc->txq[ac]); |
631 |
for (qid = 0; qid < WPI_NTXQUEUES; qid++) |
|
|
632 |
wpi_free_tx_ring(sc, &sc->txq[qid]); |
730 |
|
633 |
|
731 |
wpi_free_tx_ring(sc, &sc->cmdq); |
634 |
wpi_free_rx_ring(sc); |
732 |
wpi_free_rx_ring(sc, &sc->rxq); |
|
|
733 |
wpi_free_shared(sc); |
635 |
wpi_free_shared(sc); |
734 |
} |
636 |
} |
735 |
|
637 |
|
736 |
if (sc->fw_fp != NULL) { |
|
|
737 |
wpi_unload_firmware(sc); |
738 |
} |
739 |
|
740 |
if (sc->fw_dma.tag) |
638 |
if (sc->fw_dma.tag) |
741 |
wpi_free_fwmem(sc); |
639 |
wpi_free_fwmem(sc); |
742 |
WPI_UNLOCK(sc); |
640 |
WPI_UNLOCK(sc); |
743 |
|
641 |
|
744 |
if (sc->irq != NULL) |
|
|
745 |
bus_release_resource(dev, SYS_RES_IRQ, rman_get_rid(sc->irq), |
746 |
sc->irq); |
747 |
if (sc->mem != NULL) |
642 |
if (sc->mem != NULL) |
748 |
bus_release_resource(dev, SYS_RES_MEMORY, |
643 |
bus_release_resource(dev, SYS_RES_MEMORY, |
749 |
rman_get_rid(sc->mem), sc->mem); |
644 |
rman_get_rid(sc->mem), sc->mem); |
Lines 751-898
Link Here
|
751 |
if (ifp != NULL) |
646 |
if (ifp != NULL) |
752 |
if_free(ifp); |
647 |
if_free(ifp); |
753 |
|
648 |
|
|
|
649 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__); |
754 |
WPI_LOCK_DESTROY(sc); |
650 |
WPI_LOCK_DESTROY(sc); |
|
|
651 |
return 0; |
652 |
} |
755 |
|
653 |
|
|
|
654 |
static int |
655 |
wpi_shutdown(device_t dev) |
656 |
{ |
657 |
struct wpi_softc *sc = device_get_softc(dev); |
658 |
|
659 |
wpi_stop(sc); |
756 |
return 0; |
660 |
return 0; |
757 |
} |
661 |
} |
758 |
|
662 |
|
759 |
static struct ieee80211vap * |
663 |
static int |
760 |
wpi_vap_create(struct ieee80211com *ic, const char name[IFNAMSIZ], int unit, |
664 |
wpi_suspend(device_t dev) |
761 |
enum ieee80211_opmode opmode, int flags, |
|
|
762 |
const uint8_t bssid[IEEE80211_ADDR_LEN], |
763 |
const uint8_t mac[IEEE80211_ADDR_LEN]) |
764 |
{ |
665 |
{ |
765 |
struct wpi_vap *wvp; |
666 |
struct wpi_softc *sc = device_get_softc(dev); |
766 |
struct ieee80211vap *vap; |
667 |
struct ieee80211com *ic = sc->sc_ifp->if_l2com; |
767 |
|
668 |
|
768 |
if (!TAILQ_EMPTY(&ic->ic_vaps)) /* only one at a time */ |
669 |
ieee80211_suspend_all(ic); |
769 |
return NULL; |
670 |
return 0; |
770 |
wvp = (struct wpi_vap *) malloc(sizeof(struct wpi_vap), |
671 |
} |
771 |
M_80211_VAP, M_NOWAIT | M_ZERO); |
|
|
772 |
if (wvp == NULL) |
773 |
return NULL; |
774 |
vap = &wvp->vap; |
775 |
ieee80211_vap_setup(ic, vap, name, unit, opmode, flags, bssid, mac); |
776 |
/* override with driver methods */ |
777 |
wvp->newstate = vap->iv_newstate; |
778 |
vap->iv_newstate = wpi_newstate; |
779 |
|
672 |
|
780 |
ieee80211_ratectl_init(vap); |
673 |
static int |
781 |
/* complete setup */ |
674 |
wpi_resume(device_t dev) |
782 |
ieee80211_vap_attach(vap, ieee80211_media_change, ieee80211_media_status); |
675 |
{ |
783 |
ic->ic_opmode = opmode; |
676 |
struct wpi_softc *sc = device_get_softc(dev); |
784 |
return vap; |
677 |
struct ieee80211com *ic = sc->sc_ifp->if_l2com; |
|
|
678 |
|
679 |
/* Clear device-specific "PCI retry timeout" register (41h). */ |
680 |
pci_write_config(dev, 0x41, 0, 1); |
681 |
|
682 |
ieee80211_resume_all(ic); |
683 |
return 0; |
785 |
} |
684 |
} |
786 |
|
685 |
|
787 |
static void |
686 |
/* |
788 |
wpi_vap_delete(struct ieee80211vap *vap) |
687 |
* Grab exclusive access to NIC memory. |
|
|
688 |
*/ |
689 |
static int |
690 |
wpi_nic_lock(struct wpi_softc *sc) |
789 |
{ |
691 |
{ |
790 |
struct wpi_vap *wvp = WPI_VAP(vap); |
692 |
int ntries; |
791 |
|
693 |
|
792 |
ieee80211_ratectl_deinit(vap); |
694 |
/* Request exclusive access to NIC. */ |
793 |
ieee80211_vap_detach(vap); |
695 |
WPI_SETBITS(sc, WPI_GP_CNTRL, WPI_GP_CNTRL_MAC_ACCESS_REQ); |
794 |
free(wvp, M_80211_VAP); |
696 |
|
|
|
697 |
/* Spin until we actually get the lock. */ |
698 |
for (ntries = 0; ntries < 1000; ntries++) { |
699 |
if ((WPI_READ(sc, WPI_GP_CNTRL) & |
700 |
(WPI_GP_CNTRL_MAC_ACCESS_ENA | WPI_GP_CNTRL_SLEEP)) == |
701 |
WPI_GP_CNTRL_MAC_ACCESS_ENA) |
702 |
return 0; |
703 |
DELAY(10); |
704 |
} |
705 |
|
706 |
device_printf(sc->sc_dev, "could not lock memory\n"); |
707 |
|
708 |
return ETIMEDOUT; |
795 |
} |
709 |
} |
796 |
|
710 |
|
|
|
711 |
/* |
712 |
* Release lock on NIC memory. |
713 |
*/ |
714 |
static __inline void |
715 |
wpi_nic_unlock(struct wpi_softc *sc) |
716 |
{ |
717 |
WPI_CLRBITS(sc, WPI_GP_CNTRL, WPI_GP_CNTRL_MAC_ACCESS_REQ); |
718 |
} |
719 |
|
720 |
static __inline uint32_t |
721 |
wpi_prph_read(struct wpi_softc *sc, uint32_t addr) |
722 |
{ |
723 |
WPI_WRITE(sc, WPI_PRPH_RADDR, WPI_PRPH_DWORD | addr); |
724 |
WPI_BARRIER_READ_WRITE(sc); |
725 |
return WPI_READ(sc, WPI_PRPH_RDATA); |
726 |
} |
727 |
|
728 |
static __inline void |
729 |
wpi_prph_write(struct wpi_softc *sc, uint32_t addr, uint32_t data) |
730 |
{ |
731 |
WPI_WRITE(sc, WPI_PRPH_WADDR, WPI_PRPH_DWORD | addr); |
732 |
WPI_BARRIER_WRITE(sc); |
733 |
WPI_WRITE(sc, WPI_PRPH_WDATA, data); |
734 |
} |
735 |
|
736 |
static __inline void |
737 |
wpi_prph_setbits(struct wpi_softc *sc, uint32_t addr, uint32_t mask) |
738 |
{ |
739 |
wpi_prph_write(sc, addr, wpi_prph_read(sc, addr) | mask); |
740 |
} |
741 |
|
742 |
static __inline void |
743 |
wpi_prph_clrbits(struct wpi_softc *sc, uint32_t addr, uint32_t mask) |
744 |
{ |
745 |
wpi_prph_write(sc, addr, wpi_prph_read(sc, addr) & ~mask); |
746 |
} |
747 |
|
748 |
static __inline void |
749 |
wpi_prph_write_region_4(struct wpi_softc *sc, uint32_t addr, |
750 |
const uint32_t *data, int count) |
751 |
{ |
752 |
for (; count > 0; count--, data++, addr += 4) |
753 |
wpi_prph_write(sc, addr, *data); |
754 |
} |
755 |
|
756 |
static __inline uint32_t |
757 |
wpi_mem_read(struct wpi_softc *sc, uint32_t addr) |
758 |
{ |
759 |
WPI_WRITE(sc, WPI_MEM_RADDR, addr); |
760 |
WPI_BARRIER_READ_WRITE(sc); |
761 |
return WPI_READ(sc, WPI_MEM_RDATA); |
762 |
} |
763 |
|
764 |
static __inline void |
765 |
wpi_mem_read_region_4(struct wpi_softc *sc, uint32_t addr, uint32_t *data, |
766 |
int count) |
767 |
{ |
768 |
for (; count > 0; count--, addr += 4) |
769 |
*data++ = wpi_mem_read(sc, addr); |
770 |
} |
771 |
|
772 |
static int |
773 |
wpi_read_prom_data(struct wpi_softc *sc, uint32_t addr, void *data, int count) |
774 |
{ |
775 |
uint8_t *out = data; |
776 |
uint32_t val; |
777 |
int error, ntries; |
778 |
|
779 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__); |
780 |
|
781 |
if ((error = wpi_nic_lock(sc)) != 0) |
782 |
return error; |
783 |
|
784 |
for (; count > 0; count -= 2, addr++) { |
785 |
WPI_WRITE(sc, WPI_EEPROM, addr << 2); |
786 |
for (ntries = 0; ntries < 10; ntries++) { |
787 |
val = WPI_READ(sc, WPI_EEPROM); |
788 |
if (val & WPI_EEPROM_READ_VALID) |
789 |
break; |
790 |
DELAY(5); |
791 |
} |
792 |
if (ntries == 10) { |
793 |
device_printf(sc->sc_dev, |
794 |
"timeout reading ROM at 0x%x\n", addr); |
795 |
return ETIMEDOUT; |
796 |
} |
797 |
*out++= val >> 16; |
798 |
if (count > 1) |
799 |
*out ++= val >> 24; |
800 |
} |
801 |
|
802 |
wpi_nic_unlock(sc); |
803 |
|
804 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__); |
805 |
|
806 |
return 0; |
807 |
} |
808 |
|
797 |
static void |
809 |
static void |
798 |
wpi_dma_map_addr(void *arg, bus_dma_segment_t *segs, int nsegs, int error) |
810 |
wpi_dma_map_addr(void *arg, bus_dma_segment_t *segs, int nsegs, int error) |
799 |
{ |
811 |
{ |
800 |
if (error != 0) |
812 |
if (error != 0) |
801 |
return; |
813 |
return; |
802 |
|
|
|
803 |
KASSERT(nsegs == 1, ("too many DMA segments, %d should be 1", nsegs)); |
814 |
KASSERT(nsegs == 1, ("too many DMA segments, %d should be 1", nsegs)); |
804 |
|
|
|
805 |
*(bus_addr_t *)arg = segs[0].ds_addr; |
815 |
*(bus_addr_t *)arg = segs[0].ds_addr; |
806 |
} |
816 |
} |
807 |
|
817 |
|
808 |
/* |
818 |
/* |
809 |
* Allocates a contiguous block of dma memory of the requested size and |
819 |
* Allocates a contiguous block of dma memory of the requested size and |
810 |
* alignment. Due to limitations of the FreeBSD dma subsystem as of 20071217, |
820 |
* alignment. |
811 |
* allocations greater than 4096 may fail. Hence if the requested alignment is |
|
|
812 |
* greater we allocate 'alignment' size extra memory and shift the vaddr and |
813 |
* paddr after the dma load. This bypasses the problem at the cost of a little |
814 |
* more memory. |
815 |
*/ |
821 |
*/ |
816 |
static int |
822 |
static int |
817 |
wpi_dma_contig_alloc(struct wpi_softc *sc, struct wpi_dma_info *dma, |
823 |
wpi_dma_contig_alloc(struct wpi_softc *sc, struct wpi_dma_info *dma, |
818 |
void **kvap, bus_size_t size, bus_size_t alignment, int flags) |
824 |
void **kvap, bus_size_t size, bus_size_t alignment) |
819 |
{ |
825 |
{ |
820 |
int error; |
826 |
int error; |
821 |
bus_size_t align; |
|
|
822 |
bus_size_t reqsize; |
823 |
|
827 |
|
824 |
DPRINTFN(WPI_DEBUG_DMA, |
828 |
dma->tag = NULL; |
825 |
("Size: %zd - alignment %zd\n", size, alignment)); |
|
|
826 |
|
827 |
dma->size = size; |
829 |
dma->size = size; |
828 |
dma->tag = NULL; |
|
|
829 |
|
830 |
|
830 |
if (alignment > 4096) { |
831 |
error = bus_dma_tag_create(bus_get_dma_tag(sc->sc_dev), alignment, |
831 |
align = PAGE_SIZE; |
832 |
0, BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL, size, |
832 |
reqsize = size + alignment; |
833 |
1, size, BUS_DMA_NOWAIT, NULL, NULL, &dma->tag); |
833 |
} else { |
834 |
if (error != 0) |
834 |
align = alignment; |
|
|
835 |
reqsize = size; |
836 |
} |
837 |
error = bus_dma_tag_create(bus_get_dma_tag(sc->sc_dev), align, |
838 |
0, BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, |
839 |
NULL, NULL, reqsize, |
840 |
1, reqsize, flags, |
841 |
NULL, NULL, &dma->tag); |
842 |
if (error != 0) { |
843 |
device_printf(sc->sc_dev, |
844 |
"could not create shared page DMA tag\n"); |
845 |
goto fail; |
835 |
goto fail; |
846 |
} |
836 |
|
847 |
error = bus_dmamem_alloc(dma->tag, (void **)&dma->vaddr_start, |
837 |
error = bus_dmamem_alloc(dma->tag, (void **)&dma->vaddr, |
848 |
flags | BUS_DMA_ZERO, &dma->map); |
838 |
BUS_DMA_NOWAIT | BUS_DMA_ZERO | BUS_DMA_COHERENT, &dma->map); |
849 |
if (error != 0) { |
839 |
if (error != 0) |
850 |
device_printf(sc->sc_dev, |
|
|
851 |
"could not allocate shared page DMA memory\n"); |
852 |
goto fail; |
840 |
goto fail; |
853 |
} |
|
|
854 |
|
841 |
|
855 |
error = bus_dmamap_load(dma->tag, dma->map, dma->vaddr_start, |
842 |
error = bus_dmamap_load(dma->tag, dma->map, dma->vaddr, size, |
856 |
reqsize, wpi_dma_map_addr, &dma->paddr_start, flags); |
843 |
wpi_dma_map_addr, &dma->paddr, BUS_DMA_NOWAIT); |
|
|
844 |
if (error != 0) |
845 |
goto fail; |
857 |
|
846 |
|
858 |
/* Save the original pointers so we can free all the memory */ |
847 |
bus_dmamap_sync(dma->tag, dma->map, BUS_DMASYNC_PREWRITE); |
859 |
dma->paddr = dma->paddr_start; |
|
|
860 |
dma->vaddr = dma->vaddr_start; |
861 |
|
848 |
|
862 |
/* |
|
|
863 |
* Check the alignment and increment by 4096 until we get the |
864 |
* requested alignment. Fail if can't obtain the alignment |
865 |
* we requested. |
866 |
*/ |
867 |
if ((dma->paddr & (alignment -1 )) != 0) { |
868 |
int i; |
869 |
|
870 |
for (i = 0; i < alignment / 4096; i++) { |
871 |
if ((dma->paddr & (alignment - 1 )) == 0) |
872 |
break; |
873 |
dma->paddr += 4096; |
874 |
dma->vaddr += 4096; |
875 |
} |
876 |
if (i == alignment / 4096) { |
877 |
device_printf(sc->sc_dev, |
878 |
"alignment requirement was not satisfied\n"); |
879 |
goto fail; |
880 |
} |
881 |
} |
882 |
|
883 |
if (error != 0) { |
884 |
device_printf(sc->sc_dev, |
885 |
"could not load shared page DMA map\n"); |
886 |
goto fail; |
887 |
} |
888 |
|
889 |
if (kvap != NULL) |
849 |
if (kvap != NULL) |
890 |
*kvap = dma->vaddr; |
850 |
*kvap = dma->vaddr; |
891 |
|
851 |
|
892 |
return 0; |
852 |
return 0; |
893 |
|
853 |
|
894 |
fail: |
854 |
fail: wpi_dma_contig_free(dma); |
895 |
wpi_dma_contig_free(dma); |
|
|
896 |
return error; |
855 |
return error; |
897 |
} |
856 |
} |
898 |
|
857 |
|
Lines 899-914
Link Here
|
899 |
static void |
858 |
static void |
900 |
wpi_dma_contig_free(struct wpi_dma_info *dma) |
859 |
wpi_dma_contig_free(struct wpi_dma_info *dma) |
901 |
{ |
860 |
{ |
902 |
if (dma->tag) { |
861 |
if (dma->vaddr != NULL) { |
903 |
if (dma->vaddr_start != NULL) { |
862 |
bus_dmamap_sync(dma->tag, dma->map, |
904 |
if (dma->paddr_start != 0) { |
863 |
BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE); |
905 |
bus_dmamap_sync(dma->tag, dma->map, |
864 |
bus_dmamap_unload(dma->tag, dma->map); |
906 |
BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE); |
865 |
bus_dmamem_free(dma->tag, dma->vaddr, dma->map); |
907 |
bus_dmamap_unload(dma->tag, dma->map); |
866 |
dma->vaddr = NULL; |
908 |
} |
867 |
} |
909 |
bus_dmamem_free(dma->tag, dma->vaddr_start, dma->map); |
868 |
if (dma->tag != NULL) { |
910 |
} |
|
|
911 |
bus_dma_tag_destroy(dma->tag); |
869 |
bus_dma_tag_destroy(dma->tag); |
|
|
870 |
dma->tag = NULL; |
912 |
} |
871 |
} |
913 |
} |
872 |
} |
914 |
|
873 |
|
Lines 918-936
Link Here
|
918 |
static int |
877 |
static int |
919 |
wpi_alloc_shared(struct wpi_softc *sc) |
878 |
wpi_alloc_shared(struct wpi_softc *sc) |
920 |
{ |
879 |
{ |
921 |
int error; |
880 |
/* Shared buffer must be aligned on a 4KB boundary. */ |
922 |
|
881 |
return wpi_dma_contig_alloc(sc, &sc->shared_dma, |
923 |
error = wpi_dma_contig_alloc(sc, &sc->shared_dma, |
882 |
(void **)&sc->shared, sizeof (struct wpi_shared), 4096); |
924 |
(void **)&sc->shared, sizeof (struct wpi_shared), |
|
|
925 |
PAGE_SIZE, |
926 |
BUS_DMA_NOWAIT); |
927 |
|
928 |
if (error != 0) { |
929 |
device_printf(sc->sc_dev, |
930 |
"could not allocate shared area DMA memory\n"); |
931 |
} |
932 |
|
933 |
return error; |
934 |
} |
883 |
} |
935 |
|
884 |
|
936 |
static void |
885 |
static void |
Lines 939-1052
Link Here
|
939 |
wpi_dma_contig_free(&sc->shared_dma); |
888 |
wpi_dma_contig_free(&sc->shared_dma); |
940 |
} |
889 |
} |
941 |
|
890 |
|
|
|
891 |
/* |
892 |
* Allocate DMA-safe memory for firmware transfer. |
893 |
*/ |
942 |
static int |
894 |
static int |
943 |
wpi_alloc_rx_ring(struct wpi_softc *sc, struct wpi_rx_ring *ring) |
895 |
wpi_alloc_fwmem(struct wpi_softc *sc) |
944 |
{ |
896 |
{ |
|
|
897 |
/* Must be aligned on a 16-byte boundary. */ |
898 |
return wpi_dma_contig_alloc(sc, &sc->fw_dma, NULL, |
899 |
WPI_FW_TEXT_MAXSZ + WPI_FW_DATA_MAXSZ, 16); |
900 |
} |
945 |
|
901 |
|
|
|
902 |
static void |
903 |
wpi_free_fwmem(struct wpi_softc *sc) |
904 |
{ |
905 |
wpi_dma_contig_free(&sc->fw_dma); |
906 |
} |
907 |
|
908 |
static int |
909 |
wpi_alloc_rx_ring(struct wpi_softc *sc) |
910 |
{ |
911 |
struct wpi_rx_ring *ring = &sc->rxq; |
912 |
bus_size_t size; |
946 |
int i, error; |
913 |
int i, error; |
947 |
|
914 |
|
948 |
ring->cur = 0; |
915 |
ring->cur = 0; |
|
|
916 |
ring->update = 0; |
949 |
|
917 |
|
|
|
918 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__); |
919 |
|
920 |
/* Allocate RX descriptors (16KB aligned.) */ |
921 |
size = WPI_RX_RING_COUNT * sizeof (uint32_t); |
950 |
error = wpi_dma_contig_alloc(sc, &ring->desc_dma, |
922 |
error = wpi_dma_contig_alloc(sc, &ring->desc_dma, |
951 |
(void **)&ring->desc, WPI_RX_RING_COUNT * sizeof (uint32_t), |
923 |
(void **)&ring->desc, size, WPI_RING_DMA_ALIGN); |
952 |
WPI_RING_DMA_ALIGN, BUS_DMA_NOWAIT); |
|
|
953 |
|
954 |
if (error != 0) { |
924 |
if (error != 0) { |
955 |
device_printf(sc->sc_dev, |
925 |
device_printf(sc->sc_dev, |
956 |
"%s: could not allocate rx ring DMA memory, error %d\n", |
926 |
"%s: could not allocate RX ring DMA memory, error %d\n", |
957 |
__func__, error); |
927 |
__func__, error); |
958 |
goto fail; |
928 |
goto fail; |
959 |
} |
929 |
} |
960 |
|
930 |
|
|
|
931 |
/* Create RX buffer DMA tag. */ |
961 |
error = bus_dma_tag_create(bus_get_dma_tag(sc->sc_dev), 1, 0, |
932 |
error = bus_dma_tag_create(bus_get_dma_tag(sc->sc_dev), 1, 0, |
962 |
BUS_SPACE_MAXADDR_32BIT, |
933 |
BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL, |
963 |
BUS_SPACE_MAXADDR, NULL, NULL, MJUMPAGESIZE, 1, |
934 |
MJUMPAGESIZE, 1, MJUMPAGESIZE, BUS_DMA_NOWAIT, NULL, NULL, |
964 |
MJUMPAGESIZE, BUS_DMA_NOWAIT, NULL, NULL, &ring->data_dmat); |
935 |
&ring->data_dmat); |
965 |
if (error != 0) { |
936 |
if (error != 0) { |
966 |
device_printf(sc->sc_dev, |
937 |
device_printf(sc->sc_dev, |
967 |
"%s: bus_dma_tag_create_failed, error %d\n", |
938 |
"%s: could not create RX buf DMA tag, error %d\n", |
968 |
__func__, error); |
939 |
__func__, error); |
969 |
goto fail; |
940 |
goto fail; |
970 |
} |
941 |
} |
971 |
|
942 |
|
972 |
/* |
943 |
/* |
973 |
* Setup Rx buffers. |
944 |
* Allocate and map RX buffers. |
974 |
*/ |
945 |
*/ |
975 |
for (i = 0; i < WPI_RX_RING_COUNT; i++) { |
946 |
for (i = 0; i < WPI_RX_RING_COUNT; i++) { |
976 |
struct wpi_rx_data *data = &ring->data[i]; |
947 |
struct wpi_rx_data *data = &ring->data[i]; |
977 |
struct mbuf *m; |
|
|
978 |
bus_addr_t paddr; |
948 |
bus_addr_t paddr; |
979 |
|
949 |
|
980 |
error = bus_dmamap_create(ring->data_dmat, 0, &data->map); |
950 |
error = bus_dmamap_create(ring->data_dmat, 0, &data->map); |
981 |
if (error != 0) { |
951 |
if (error != 0) { |
982 |
device_printf(sc->sc_dev, |
952 |
device_printf(sc->sc_dev, |
983 |
"%s: bus_dmamap_create failed, error %d\n", |
953 |
"%s: could not create RX buf DMA map, error %d\n", |
984 |
__func__, error); |
954 |
__func__, error); |
985 |
goto fail; |
955 |
goto fail; |
986 |
} |
956 |
} |
987 |
m = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, MJUMPAGESIZE); |
957 |
|
988 |
if (m == NULL) { |
958 |
data->m = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, MJUMPAGESIZE); |
|
|
959 |
if (data->m == NULL) { |
989 |
device_printf(sc->sc_dev, |
960 |
device_printf(sc->sc_dev, |
990 |
"%s: could not allocate rx mbuf\n", __func__); |
961 |
"%s: could not allocate RX mbuf\n", __func__); |
991 |
error = ENOMEM; |
962 |
error = ENOBUFS; |
992 |
goto fail; |
963 |
goto fail; |
993 |
} |
964 |
} |
994 |
/* map page */ |
965 |
|
995 |
error = bus_dmamap_load(ring->data_dmat, data->map, |
966 |
error = bus_dmamap_load(ring->data_dmat, data->map, |
996 |
mtod(m, caddr_t), MJUMPAGESIZE, |
967 |
mtod(data->m, void *), MJUMPAGESIZE, wpi_dma_map_addr, |
997 |
wpi_dma_map_addr, &paddr, BUS_DMA_NOWAIT); |
968 |
&paddr, BUS_DMA_NOWAIT); |
998 |
if (error != 0 && error != EFBIG) { |
969 |
if (error != 0 && error != EFBIG) { |
999 |
device_printf(sc->sc_dev, |
970 |
device_printf(sc->sc_dev, |
1000 |
"%s: bus_dmamap_load failed, error %d\n", |
971 |
"%s: can't map mbuf (error %d)\n", __func__, |
1001 |
__func__, error); |
972 |
error); |
1002 |
m_freem(m); |
|
|
1003 |
error = ENOMEM; /* XXX unique code */ |
1004 |
goto fail; |
973 |
goto fail; |
1005 |
} |
974 |
} |
1006 |
bus_dmamap_sync(ring->data_dmat, data->map, |
|
|
1007 |
BUS_DMASYNC_PREWRITE); |
1008 |
|
975 |
|
1009 |
data->m = m; |
976 |
/* Set physical address of RX buffer. */ |
1010 |
ring->desc[i] = htole32(paddr); |
977 |
ring->desc[i] = htole32(paddr); |
1011 |
} |
978 |
} |
|
|
979 |
|
1012 |
bus_dmamap_sync(ring->desc_dma.tag, ring->desc_dma.map, |
980 |
bus_dmamap_sync(ring->desc_dma.tag, ring->desc_dma.map, |
1013 |
BUS_DMASYNC_PREWRITE); |
981 |
BUS_DMASYNC_PREWRITE); |
|
|
982 |
|
983 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__); |
984 |
|
1014 |
return 0; |
985 |
return 0; |
1015 |
fail: |
986 |
|
1016 |
wpi_free_rx_ring(sc, ring); |
987 |
fail: wpi_free_rx_ring(sc); |
|
|
988 |
|
989 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END_ERR, __func__); |
990 |
|
1017 |
return error; |
991 |
return error; |
1018 |
} |
992 |
} |
1019 |
|
993 |
|
1020 |
static void |
994 |
static void |
1021 |
wpi_reset_rx_ring(struct wpi_softc *sc, struct wpi_rx_ring *ring) |
995 |
wpi_update_rx_ring(struct wpi_softc *sc) |
1022 |
{ |
996 |
{ |
1023 |
int ntries; |
997 |
struct wpi_rx_ring *ring = &sc->rxq; |
1024 |
|
998 |
|
1025 |
wpi_mem_lock(sc); |
999 |
if (WPI_READ(sc, WPI_UCODE_GP1) & WPI_UCODE_GP1_MAC_SLEEP) { |
|
|
1000 |
DPRINTF(sc, WPI_DEBUG_PWRSAVE, "%s: wakeup request\n", |
1001 |
__func__); |
1026 |
|
1002 |
|
1027 |
WPI_WRITE(sc, WPI_RX_CONFIG, 0); |
1003 |
WPI_SETBITS(sc, WPI_GP_CNTRL, WPI_GP_CNTRL_MAC_ACCESS_REQ); |
|
|
1004 |
ring->update = 1; |
1005 |
} else |
1006 |
WPI_WRITE(sc, WPI_FH_RX_WPTR, ring->cur & ~7); |
1007 |
} |
1028 |
|
1008 |
|
1029 |
for (ntries = 0; ntries < 100; ntries++) { |
1009 |
static void |
1030 |
if (WPI_READ(sc, WPI_RX_STATUS) & WPI_RX_IDLE) |
1010 |
wpi_reset_rx_ring(struct wpi_softc *sc) |
1031 |
break; |
1011 |
{ |
1032 |
DELAY(10); |
1012 |
struct wpi_rx_ring *ring = &sc->rxq; |
1033 |
} |
1013 |
int ntries; |
1034 |
|
1014 |
|
1035 |
wpi_mem_unlock(sc); |
1015 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__); |
1036 |
|
1016 |
|
|
|
1017 |
if (wpi_nic_lock(sc) == 0) { |
1018 |
WPI_WRITE(sc, WPI_FH_RX_CONFIG, 0); |
1019 |
for (ntries = 0; ntries < 1000; ntries++) { |
1020 |
if (WPI_READ(sc, WPI_FH_RX_STATUS) & |
1021 |
WPI_FH_RX_STATUS_IDLE) |
1022 |
break; |
1023 |
DELAY(10); |
1024 |
} |
1037 |
#ifdef WPI_DEBUG |
1025 |
#ifdef WPI_DEBUG |
1038 |
if (ntries == 100 && wpi_debug > 0) |
1026 |
if (ntries == 1000) { |
1039 |
device_printf(sc->sc_dev, "timeout resetting Rx ring\n"); |
1027 |
device_printf(sc->sc_dev, |
|
|
1028 |
"timeout resetting Rx ring\n"); |
1029 |
} |
1040 |
#endif |
1030 |
#endif |
|
|
1031 |
wpi_nic_unlock(sc); |
1032 |
} |
1041 |
|
1033 |
|
1042 |
ring->cur = 0; |
1034 |
ring->cur = 0; |
|
|
1035 |
ring->update = 0; |
1043 |
} |
1036 |
} |
1044 |
|
1037 |
|
1045 |
static void |
1038 |
static void |
1046 |
wpi_free_rx_ring(struct wpi_softc *sc, struct wpi_rx_ring *ring) |
1039 |
wpi_free_rx_ring(struct wpi_softc *sc) |
1047 |
{ |
1040 |
{ |
|
|
1041 |
struct wpi_rx_ring *ring = &sc->rxq; |
1048 |
int i; |
1042 |
int i; |
1049 |
|
1043 |
|
|
|
1044 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__); |
1045 |
|
1050 |
wpi_dma_contig_free(&ring->desc_dma); |
1046 |
wpi_dma_contig_free(&ring->desc_dma); |
1051 |
|
1047 |
|
1052 |
for (i = 0; i < WPI_RX_RING_COUNT; i++) { |
1048 |
for (i = 0; i < WPI_RX_RING_COUNT; i++) { |
Lines 1057-1238
Link Here
|
1057 |
BUS_DMASYNC_POSTREAD); |
1053 |
BUS_DMASYNC_POSTREAD); |
1058 |
bus_dmamap_unload(ring->data_dmat, data->map); |
1054 |
bus_dmamap_unload(ring->data_dmat, data->map); |
1059 |
m_freem(data->m); |
1055 |
m_freem(data->m); |
|
|
1056 |
data->m = NULL; |
1060 |
} |
1057 |
} |
1061 |
if (data->map != NULL) |
1058 |
if (data->map != NULL) |
1062 |
bus_dmamap_destroy(ring->data_dmat, data->map); |
1059 |
bus_dmamap_destroy(ring->data_dmat, data->map); |
1063 |
} |
1060 |
} |
|
|
1061 |
if (ring->data_dmat != NULL) { |
1062 |
bus_dma_tag_destroy(ring->data_dmat); |
1063 |
ring->data_dmat = NULL; |
1064 |
} |
1064 |
} |
1065 |
} |
1065 |
|
1066 |
|
1066 |
static int |
1067 |
static int |
1067 |
wpi_alloc_tx_ring(struct wpi_softc *sc, struct wpi_tx_ring *ring, int count, |
1068 |
wpi_alloc_tx_ring(struct wpi_softc *sc, struct wpi_tx_ring *ring, int qid) |
1068 |
int qid) |
|
|
1069 |
{ |
1069 |
{ |
1070 |
struct wpi_tx_data *data; |
1070 |
bus_addr_t paddr; |
|
|
1071 |
bus_size_t size; |
1071 |
int i, error; |
1072 |
int i, error; |
1072 |
|
1073 |
|
1073 |
ring->qid = qid; |
1074 |
ring->qid = qid; |
1074 |
ring->count = count; |
|
|
1075 |
ring->queued = 0; |
1075 |
ring->queued = 0; |
1076 |
ring->cur = 0; |
1076 |
ring->cur = 0; |
1077 |
ring->data = NULL; |
1077 |
ring->update = 0; |
1078 |
|
1078 |
|
1079 |
error = wpi_dma_contig_alloc(sc, &ring->desc_dma, |
1079 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__); |
1080 |
(void **)&ring->desc, count * sizeof (struct wpi_tx_desc), |
|
|
1081 |
WPI_RING_DMA_ALIGN, BUS_DMA_NOWAIT); |
1082 |
|
1080 |
|
|
|
1081 |
/* Allocate TX descriptors (16KB aligned.) */ |
1082 |
size = WPI_TX_RING_COUNT * sizeof (struct wpi_tx_desc); |
1083 |
error = wpi_dma_contig_alloc(sc, &ring->desc_dma, (void **)&ring->desc, |
1084 |
size, WPI_RING_DMA_ALIGN); |
1083 |
if (error != 0) { |
1085 |
if (error != 0) { |
1084 |
device_printf(sc->sc_dev, "could not allocate tx dma memory\n"); |
1086 |
device_printf(sc->sc_dev, |
1085 |
goto fail; |
1087 |
"%s: could not allocate TX ring DMA memory, error %d\n", |
|
|
1088 |
__func__, error); |
1089 |
goto fail; |
1086 |
} |
1090 |
} |
1087 |
|
1091 |
|
1088 |
/* update shared page with ring's base address */ |
1092 |
/* Update shared area with ring physical address. */ |
1089 |
sc->shared->txbase[qid] = htole32(ring->desc_dma.paddr); |
1093 |
sc->shared->txbase[qid] = htole32(ring->desc_dma.paddr); |
|
|
1094 |
bus_dmamap_sync(sc->shared_dma.tag, sc->shared_dma.map, |
1095 |
BUS_DMASYNC_PREWRITE); |
1090 |
|
1096 |
|
|
|
1097 |
/* |
1098 |
* We only use rings 0 through 4 (4 EDCA + cmd) so there is no need |
1099 |
* to allocate commands space for other rings. |
1100 |
* XXX Do we really need to allocate descriptors for other rings? |
1101 |
*/ |
1102 |
if (qid > 4) |
1103 |
return 0; |
1104 |
|
1105 |
size = WPI_TX_RING_COUNT * sizeof (struct wpi_tx_cmd); |
1091 |
error = wpi_dma_contig_alloc(sc, &ring->cmd_dma, (void **)&ring->cmd, |
1106 |
error = wpi_dma_contig_alloc(sc, &ring->cmd_dma, (void **)&ring->cmd, |
1092 |
count * sizeof (struct wpi_tx_cmd), WPI_RING_DMA_ALIGN, |
1107 |
size, 4); |
1093 |
BUS_DMA_NOWAIT); |
|
|
1094 |
|
1095 |
if (error != 0) { |
1108 |
if (error != 0) { |
1096 |
device_printf(sc->sc_dev, |
1109 |
device_printf(sc->sc_dev, |
1097 |
"could not allocate tx command DMA memory\n"); |
1110 |
"%s: could not allocate TX cmd DMA memory, error %d\n", |
|
|
1111 |
__func__, error); |
1098 |
goto fail; |
1112 |
goto fail; |
1099 |
} |
1113 |
} |
1100 |
|
1114 |
|
1101 |
ring->data = malloc(count * sizeof (struct wpi_tx_data), M_DEVBUF, |
|
|
1102 |
M_NOWAIT | M_ZERO); |
1103 |
if (ring->data == NULL) { |
1104 |
device_printf(sc->sc_dev, |
1105 |
"could not allocate tx data slots\n"); |
1106 |
goto fail; |
1107 |
} |
1108 |
|
1109 |
error = bus_dma_tag_create(bus_get_dma_tag(sc->sc_dev), 1, 0, |
1115 |
error = bus_dma_tag_create(bus_get_dma_tag(sc->sc_dev), 1, 0, |
1110 |
BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL, MCLBYTES, |
1116 |
BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL, MCLBYTES, |
1111 |
WPI_MAX_SCATTER - 1, MCLBYTES, BUS_DMA_NOWAIT, NULL, NULL, |
1117 |
WPI_MAX_SCATTER - 1, MCLBYTES, BUS_DMA_NOWAIT, NULL, NULL, |
1112 |
&ring->data_dmat); |
1118 |
&ring->data_dmat); |
1113 |
if (error != 0) { |
1119 |
if (error != 0) { |
1114 |
device_printf(sc->sc_dev, "could not create data DMA tag\n"); |
1120 |
device_printf(sc->sc_dev, |
|
|
1121 |
"%s: could not create TX buf DMA tag, error %d\n", |
1122 |
__func__, error); |
1115 |
goto fail; |
1123 |
goto fail; |
1116 |
} |
1124 |
} |
1117 |
|
1125 |
|
1118 |
for (i = 0; i < count; i++) { |
1126 |
paddr = ring->cmd_dma.paddr; |
1119 |
data = &ring->data[i]; |
1127 |
for (i = 0; i < WPI_TX_RING_COUNT; i++) { |
|
|
1128 |
struct wpi_tx_data *data = &ring->data[i]; |
1120 |
|
1129 |
|
|
|
1130 |
data->cmd_paddr = paddr; |
1131 |
paddr += sizeof (struct wpi_tx_cmd); |
1132 |
|
1121 |
error = bus_dmamap_create(ring->data_dmat, 0, &data->map); |
1133 |
error = bus_dmamap_create(ring->data_dmat, 0, &data->map); |
1122 |
if (error != 0) { |
1134 |
if (error != 0) { |
1123 |
device_printf(sc->sc_dev, |
1135 |
device_printf(sc->sc_dev, |
1124 |
"could not create tx buf DMA map\n"); |
1136 |
"%s: could not create TX buf DMA map, error %d\n", |
|
|
1137 |
__func__, error); |
1125 |
goto fail; |
1138 |
goto fail; |
1126 |
} |
1139 |
} |
1127 |
bus_dmamap_sync(ring->data_dmat, data->map, |
|
|
1128 |
BUS_DMASYNC_PREWRITE); |
1129 |
} |
1140 |
} |
1130 |
|
1141 |
|
|
|
1142 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__); |
1143 |
|
1131 |
return 0; |
1144 |
return 0; |
1132 |
|
1145 |
|
1133 |
fail: |
1146 |
fail: wpi_free_tx_ring(sc, ring); |
1134 |
wpi_free_tx_ring(sc, ring); |
1147 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END_ERR, __func__); |
1135 |
return error; |
1148 |
return error; |
1136 |
} |
1149 |
} |
1137 |
|
1150 |
|
1138 |
static void |
1151 |
static void |
|
|
1152 |
wpi_update_tx_ring(struct wpi_softc *sc, struct wpi_tx_ring *ring) |
1153 |
{ |
1154 |
if (WPI_READ(sc, WPI_UCODE_GP1) & WPI_UCODE_GP1_MAC_SLEEP) { |
1155 |
DPRINTF(sc, WPI_DEBUG_PWRSAVE, "%s (%d): requesting wakeup\n", |
1156 |
__func__, ring->qid); |
1157 |
|
1158 |
WPI_SETBITS(sc, WPI_GP_CNTRL, WPI_GP_CNTRL_MAC_ACCESS_REQ); |
1159 |
ring->update = 1; |
1160 |
} else |
1161 |
WPI_WRITE(sc, WPI_HBUS_TARG_WRPTR, ring->qid << 8 | ring->cur); |
1162 |
} |
1163 |
|
1164 |
static void |
1139 |
wpi_reset_tx_ring(struct wpi_softc *sc, struct wpi_tx_ring *ring) |
1165 |
wpi_reset_tx_ring(struct wpi_softc *sc, struct wpi_tx_ring *ring) |
1140 |
{ |
1166 |
{ |
1141 |
struct wpi_tx_data *data; |
1167 |
int i; |
1142 |
int i, ntries; |
|
|
1143 |
|
1168 |
|
1144 |
wpi_mem_lock(sc); |
1169 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__); |
1145 |
|
1170 |
|
1146 |
WPI_WRITE(sc, WPI_TX_CONFIG(ring->qid), 0); |
1171 |
for (i = 0; i < WPI_TX_RING_COUNT; i++) { |
1147 |
for (ntries = 0; ntries < 100; ntries++) { |
1172 |
struct wpi_tx_data *data = &ring->data[i]; |
1148 |
if (WPI_READ(sc, WPI_TX_STATUS) & WPI_TX_IDLE(ring->qid)) |
|
|
1149 |
break; |
1150 |
DELAY(10); |
1151 |
} |
1152 |
#ifdef WPI_DEBUG |
1153 |
if (ntries == 100 && wpi_debug > 0) |
1154 |
device_printf(sc->sc_dev, "timeout resetting Tx ring %d\n", |
1155 |
ring->qid); |
1156 |
#endif |
1157 |
wpi_mem_unlock(sc); |
1158 |
|
1173 |
|
1159 |
for (i = 0; i < ring->count; i++) { |
|
|
1160 |
data = &ring->data[i]; |
1161 |
|
1162 |
if (data->m != NULL) { |
1174 |
if (data->m != NULL) { |
|
|
1175 |
bus_dmamap_sync(ring->data_dmat, data->map, |
1176 |
BUS_DMASYNC_POSTWRITE); |
1163 |
bus_dmamap_unload(ring->data_dmat, data->map); |
1177 |
bus_dmamap_unload(ring->data_dmat, data->map); |
1164 |
m_freem(data->m); |
1178 |
m_freem(data->m); |
1165 |
data->m = NULL; |
1179 |
data->m = NULL; |
1166 |
} |
1180 |
} |
1167 |
} |
1181 |
} |
1168 |
|
1182 |
/* Clear TX descriptors. */ |
|
|
1183 |
memset(ring->desc, 0, ring->desc_dma.size); |
1184 |
bus_dmamap_sync(ring->desc_dma.tag, ring->desc_dma.map, |
1185 |
BUS_DMASYNC_PREWRITE); |
1186 |
sc->qfullmsk &= ~(1 << ring->qid); |
1169 |
ring->queued = 0; |
1187 |
ring->queued = 0; |
1170 |
ring->cur = 0; |
1188 |
ring->cur = 0; |
|
|
1189 |
ring->update = 0; |
1171 |
} |
1190 |
} |
1172 |
|
1191 |
|
1173 |
static void |
1192 |
static void |
1174 |
wpi_free_tx_ring(struct wpi_softc *sc, struct wpi_tx_ring *ring) |
1193 |
wpi_free_tx_ring(struct wpi_softc *sc, struct wpi_tx_ring *ring) |
1175 |
{ |
1194 |
{ |
1176 |
struct wpi_tx_data *data; |
|
|
1177 |
int i; |
1195 |
int i; |
1178 |
|
1196 |
|
|
|
1197 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__); |
1198 |
|
1179 |
wpi_dma_contig_free(&ring->desc_dma); |
1199 |
wpi_dma_contig_free(&ring->desc_dma); |
1180 |
wpi_dma_contig_free(&ring->cmd_dma); |
1200 |
wpi_dma_contig_free(&ring->cmd_dma); |
1181 |
|
1201 |
|
1182 |
if (ring->data != NULL) { |
1202 |
for (i = 0; i < WPI_TX_RING_COUNT; i++) { |
1183 |
for (i = 0; i < ring->count; i++) { |
1203 |
struct wpi_tx_data *data = &ring->data[i]; |
1184 |
data = &ring->data[i]; |
|
|
1185 |
|
1204 |
|
1186 |
if (data->m != NULL) { |
1205 |
if (data->m != NULL) { |
1187 |
bus_dmamap_sync(ring->data_dmat, data->map, |
1206 |
bus_dmamap_sync(ring->data_dmat, data->map, |
1188 |
BUS_DMASYNC_POSTWRITE); |
1207 |
BUS_DMASYNC_POSTWRITE); |
1189 |
bus_dmamap_unload(ring->data_dmat, data->map); |
1208 |
bus_dmamap_unload(ring->data_dmat, data->map); |
1190 |
m_freem(data->m); |
1209 |
m_freem(data->m); |
1191 |
data->m = NULL; |
|
|
1192 |
} |
1193 |
} |
1210 |
} |
1194 |
free(ring->data, M_DEVBUF); |
1211 |
if (data->map != NULL) |
|
|
1212 |
bus_dmamap_destroy(ring->data_dmat, data->map); |
1195 |
} |
1213 |
} |
1196 |
|
1214 |
if (ring->data_dmat != NULL) { |
1197 |
if (ring->data_dmat != NULL) |
|
|
1198 |
bus_dma_tag_destroy(ring->data_dmat); |
1215 |
bus_dma_tag_destroy(ring->data_dmat); |
|
|
1216 |
ring->data_dmat = NULL; |
1217 |
} |
1199 |
} |
1218 |
} |
1200 |
|
1219 |
|
|
|
1220 |
/* |
1221 |
* Extract various information from EEPROM. |
1222 |
*/ |
1201 |
static int |
1223 |
static int |
1202 |
wpi_shutdown(device_t dev) |
1224 |
wpi_read_eeprom(struct wpi_softc *sc, uint8_t macaddr[IEEE80211_ADDR_LEN]) |
1203 |
{ |
1225 |
{ |
1204 |
struct wpi_softc *sc = device_get_softc(dev); |
1226 |
#define WPI_CHK(res) do { \ |
|
|
1227 |
if ((error = res) != 0) \ |
1228 |
goto fail; \ |
1229 |
} while (0) |
1230 |
int error, i; |
1205 |
|
1231 |
|
1206 |
WPI_LOCK(sc); |
1232 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__); |
1207 |
wpi_stop_locked(sc); |
|
|
1208 |
wpi_unload_firmware(sc); |
1209 |
WPI_UNLOCK(sc); |
1210 |
|
1233 |
|
1211 |
return 0; |
1234 |
/* Adapter has to be powered on for EEPROM access to work. */ |
|
|
1235 |
if ((error = wpi_apm_init(sc)) != 0) { |
1236 |
device_printf(sc->sc_dev, |
1237 |
"%s: could not power ON adapter, error %d\n", __func__, |
1238 |
error); |
1239 |
return error; |
1240 |
} |
1241 |
|
1242 |
if ((WPI_READ(sc, WPI_EEPROM_GP) & 0x6) == 0) { |
1243 |
device_printf(sc->sc_dev, "bad EEPROM signature\n"); |
1244 |
error = EIO; |
1245 |
goto fail; |
1246 |
} |
1247 |
/* Clear HW ownership of EEPROM. */ |
1248 |
WPI_CLRBITS(sc, WPI_EEPROM_GP, WPI_EEPROM_GP_IF_OWNER); |
1249 |
|
1250 |
/* Read the hardware capabilities, revision and SKU type. */ |
1251 |
WPI_CHK(wpi_read_prom_data(sc, WPI_EEPROM_SKU_CAP, &sc->cap, |
1252 |
sizeof(sc->cap))); |
1253 |
WPI_CHK(wpi_read_prom_data(sc, WPI_EEPROM_REVISION, &sc->rev, |
1254 |
sizeof(sc->rev))); |
1255 |
WPI_CHK(wpi_read_prom_data(sc, WPI_EEPROM_TYPE, &sc->type, |
1256 |
sizeof(sc->type))); |
1257 |
|
1258 |
DPRINTF(sc, WPI_DEBUG_EEPROM, "cap=%x rev=%x type=%x\n", sc->cap, le16toh(sc->rev), |
1259 |
sc->type); |
1260 |
|
1261 |
/* Read the regulatory domain (4 ASCII characters.) */ |
1262 |
WPI_CHK(wpi_read_prom_data(sc, WPI_EEPROM_DOMAIN, sc->domain, |
1263 |
sizeof(sc->domain))); |
1264 |
|
1265 |
/* Read MAC address. */ |
1266 |
WPI_CHK(wpi_read_prom_data(sc, WPI_EEPROM_MAC, macaddr, |
1267 |
IEEE80211_ADDR_LEN)); |
1268 |
|
1269 |
/* Read the list of authorized channels. */ |
1270 |
for (i = 0; i < WPI_CHAN_BANDS_COUNT; i++) |
1271 |
WPI_CHK(wpi_read_eeprom_channels(sc, i)); |
1272 |
|
1273 |
/* Read the list of TX power groups. */ |
1274 |
for (i = 0; i < WPI_POWER_GROUPS_COUNT; i++) |
1275 |
WPI_CHK(wpi_read_eeprom_group(sc, i)); |
1276 |
|
1277 |
fail: wpi_apm_stop(sc); /* Power OFF adapter. */ |
1278 |
|
1279 |
DPRINTF(sc, WPI_DEBUG_TRACE, error ? TRACE_STR_END_ERR : TRACE_STR_END, |
1280 |
__func__); |
1281 |
|
1282 |
return error; |
1283 |
#undef WPI_CHK |
1212 |
} |
1284 |
} |
1213 |
|
1285 |
|
|
|
1286 |
/** |
1287 |
* Read the eeprom to find out what channels are valid for the given |
1288 |
* band and update net80211 with what we find. |
1289 |
*/ |
1214 |
static int |
1290 |
static int |
1215 |
wpi_suspend(device_t dev) |
1291 |
wpi_read_eeprom_channels(struct wpi_softc *sc, int n) |
1216 |
{ |
1292 |
{ |
1217 |
struct wpi_softc *sc = device_get_softc(dev); |
1293 |
struct ifnet *ifp = sc->sc_ifp; |
1218 |
struct ieee80211com *ic = sc->sc_ifp->if_l2com; |
1294 |
struct ieee80211com *ic = ifp->if_l2com; |
|
|
1295 |
const struct wpi_chan_band *band = &wpi_bands[n]; |
1296 |
struct wpi_eeprom_chan channels[WPI_MAX_CHAN_PER_BAND]; |
1297 |
struct ieee80211_channel *c; |
1298 |
int chan, i, error, passive; |
1219 |
|
1299 |
|
1220 |
ieee80211_suspend_all(ic); |
1300 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__); |
|
|
1301 |
|
1302 |
if ((error = wpi_read_prom_data(sc, band->addr, channels, |
1303 |
band->nchan * sizeof (struct wpi_eeprom_chan))) != 0) { |
1304 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END_ERR, __func__); |
1305 |
return error; |
1306 |
} |
1307 |
|
1308 |
for (i = 0; i < band->nchan; i++) { |
1309 |
if (!(channels[i].flags & WPI_EEPROM_CHAN_VALID)) { |
1310 |
DPRINTF(sc, WPI_DEBUG_HW, |
1311 |
"Channel Not Valid: %d, band %d\n", |
1312 |
band->chan[i],n); |
1313 |
continue; |
1314 |
} |
1315 |
|
1316 |
passive = 0; |
1317 |
chan = band->chan[i]; |
1318 |
c = &ic->ic_channels[ic->ic_nchans++]; |
1319 |
|
1320 |
/* is active scan allowed on this channel? */ |
1321 |
if (!(channels[i].flags & WPI_EEPROM_CHAN_ACTIVE)) { |
1322 |
passive = IEEE80211_CHAN_PASSIVE; |
1323 |
} |
1324 |
|
1325 |
if (n == 0) { /* 2GHz band */ |
1326 |
c->ic_ieee = chan; |
1327 |
c->ic_freq = ieee80211_ieee2mhz(chan, |
1328 |
IEEE80211_CHAN_2GHZ); |
1329 |
c->ic_flags = IEEE80211_CHAN_B | passive; |
1330 |
|
1331 |
c = &ic->ic_channels[ic->ic_nchans++]; |
1332 |
c->ic_ieee = chan; |
1333 |
c->ic_freq = ieee80211_ieee2mhz(chan, |
1334 |
IEEE80211_CHAN_2GHZ); |
1335 |
c->ic_flags = IEEE80211_CHAN_G | passive; |
1336 |
|
1337 |
} else { /* 5GHz band */ |
1338 |
/* |
1339 |
* Some 3945ABG adapters support channels 7, 8, 11 |
1340 |
* and 12 in the 2GHz *and* 5GHz bands. |
1341 |
* Because of limitations in our net80211(9) stack, |
1342 |
* we can't support these channels in 5GHz band. |
1343 |
* XXX not true; just need to map to proper frequency |
1344 |
*/ |
1345 |
if (chan <= 14) |
1346 |
continue; |
1347 |
|
1348 |
c->ic_ieee = chan; |
1349 |
c->ic_freq = ieee80211_ieee2mhz(chan, |
1350 |
IEEE80211_CHAN_5GHZ); |
1351 |
c->ic_flags = IEEE80211_CHAN_A | passive; |
1352 |
} |
1353 |
|
1354 |
/* Save maximum allowed power for this channel. */ |
1355 |
sc->maxpwr[chan] = channels[i].maxpwr; |
1356 |
|
1357 |
#if 0 |
1358 |
// XXX We can probably use this an get rid of maxpwr - ben 20070617 |
1359 |
ic->ic_channels[chan].ic_maxpower = channels[i].maxpwr; |
1360 |
//ic->ic_channels[chan].ic_minpower... |
1361 |
//ic->ic_channels[chan].ic_maxregtxpower... |
1362 |
#endif |
1363 |
|
1364 |
DPRINTF(sc, WPI_DEBUG_EEPROM, |
1365 |
"adding chan %d (%dMHz) flags=0x%x maxpwr=%d passive=%d," |
1366 |
" offset %d\n", chan, c->ic_freq, |
1367 |
channels[i].flags, sc->maxpwr[chan], |
1368 |
(c->ic_flags & IEEE80211_CHAN_PASSIVE) != 0, |
1369 |
ic->ic_nchans); |
1370 |
} |
1371 |
|
1372 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__); |
1373 |
|
1221 |
return 0; |
1374 |
return 0; |
1222 |
} |
1375 |
} |
1223 |
|
1376 |
|
1224 |
static int |
1377 |
static int |
1225 |
wpi_resume(device_t dev) |
1378 |
wpi_read_eeprom_group(struct wpi_softc *sc, int n) |
1226 |
{ |
1379 |
{ |
1227 |
struct wpi_softc *sc = device_get_softc(dev); |
1380 |
struct wpi_power_group *group = &sc->groups[n]; |
1228 |
struct ieee80211com *ic = sc->sc_ifp->if_l2com; |
1381 |
struct wpi_eeprom_group rgroup; |
|
|
1382 |
int i, error; |
1229 |
|
1383 |
|
1230 |
pci_write_config(dev, 0x41, 0, 1); |
1384 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__); |
1231 |
|
1385 |
|
1232 |
ieee80211_resume_all(ic); |
1386 |
if ((error = wpi_read_prom_data(sc, WPI_EEPROM_POWER_GRP + n * 32, |
|
|
1387 |
&rgroup, sizeof rgroup)) != 0) { |
1388 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END_ERR, __func__); |
1389 |
return error; |
1390 |
} |
1391 |
|
1392 |
/* Save TX power group information. */ |
1393 |
group->chan = rgroup.chan; |
1394 |
group->maxpwr = rgroup.maxpwr; |
1395 |
/* Retrieve temperature at which the samples were taken. */ |
1396 |
group->temp = (int16_t)le16toh(rgroup.temp); |
1397 |
|
1398 |
DPRINTF(sc, WPI_DEBUG_EEPROM, |
1399 |
"power group %d: chan=%d maxpwr=%d temp=%d\n", n, group->chan, |
1400 |
group->maxpwr, group->temp); |
1401 |
|
1402 |
for (i = 0; i < WPI_SAMPLES_COUNT; i++) { |
1403 |
group->samples[i].index = rgroup.samples[i].index; |
1404 |
group->samples[i].power = rgroup.samples[i].power; |
1405 |
|
1406 |
DPRINTF(sc, WPI_DEBUG_EEPROM, |
1407 |
"\tsample %d: index=%d power=%d\n", i, |
1408 |
group->samples[i].index, group->samples[i].power); |
1409 |
} |
1410 |
|
1411 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__); |
1412 |
|
1233 |
return 0; |
1413 |
return 0; |
1234 |
} |
1414 |
} |
1235 |
|
1415 |
|
|
|
1416 |
static struct ieee80211_node * |
1417 |
wpi_node_alloc(struct ieee80211vap *vap, const uint8_t mac[IEEE80211_ADDR_LEN]) |
1418 |
{ |
1419 |
struct wpi_node *wn; |
1420 |
|
1421 |
wn = malloc(sizeof (struct wpi_node), M_80211_NODE, |
1422 |
M_NOWAIT | M_ZERO); |
1423 |
|
1424 |
if (wn == NULL) |
1425 |
return NULL; |
1426 |
|
1427 |
wn->id = -1; |
1428 |
|
1429 |
return &wn->ni; |
1430 |
} |
1431 |
|
1236 |
/** |
1432 |
/** |
1237 |
* Called by net80211 when ever there is a change to 80211 state machine |
1433 |
* Called by net80211 when ever there is a change to 80211 state machine |
1238 |
*/ |
1434 |
*/ |
Lines 1243-1449
Link Here
|
1243 |
struct ieee80211com *ic = vap->iv_ic; |
1439 |
struct ieee80211com *ic = vap->iv_ic; |
1244 |
struct ifnet *ifp = ic->ic_ifp; |
1440 |
struct ifnet *ifp = ic->ic_ifp; |
1245 |
struct wpi_softc *sc = ifp->if_softc; |
1441 |
struct wpi_softc *sc = ifp->if_softc; |
1246 |
int error; |
1442 |
int error = 0; |
1247 |
|
1443 |
|
1248 |
DPRINTF(("%s: %s -> %s flags 0x%x\n", __func__, |
1444 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__); |
|
|
1445 |
|
1446 |
DPRINTF(sc, WPI_DEBUG_STATE, "%s: %s -> %s\n", __func__, |
1249 |
ieee80211_state_name[vap->iv_state], |
1447 |
ieee80211_state_name[vap->iv_state], |
1250 |
ieee80211_state_name[nstate], sc->flags)); |
1448 |
ieee80211_state_name[nstate]); |
1251 |
|
1449 |
|
1252 |
IEEE80211_UNLOCK(ic); |
1450 |
IEEE80211_UNLOCK(ic); |
1253 |
WPI_LOCK(sc); |
1451 |
WPI_LOCK(sc); |
1254 |
if (nstate == IEEE80211_S_SCAN && vap->iv_state != IEEE80211_S_INIT) { |
1452 |
switch (nstate) { |
|
|
1453 |
case IEEE80211_S_ASSOC: |
1454 |
if (vap->iv_state != IEEE80211_S_RUN) |
1455 |
break; |
1456 |
/* FALLTHROUGH */ |
1457 |
case IEEE80211_S_AUTH: |
1255 |
/* |
1458 |
/* |
1256 |
* On !INIT -> SCAN transitions, we need to clear any possible |
|
|
1257 |
* knowledge about associations. |
1258 |
*/ |
1259 |
error = wpi_config(sc); |
1260 |
if (error != 0) { |
1261 |
device_printf(sc->sc_dev, |
1262 |
"%s: device config failed, error %d\n", |
1263 |
__func__, error); |
1264 |
} |
1265 |
} |
1266 |
if (nstate == IEEE80211_S_AUTH || |
1267 |
(nstate == IEEE80211_S_ASSOC && vap->iv_state == IEEE80211_S_RUN)) { |
1268 |
/* |
1269 |
* The node must be registered in the firmware before auth. |
1459 |
* The node must be registered in the firmware before auth. |
1270 |
* Also the associd must be cleared on RUN -> ASSOC |
1460 |
* Also the associd must be cleared on RUN -> ASSOC |
1271 |
* transitions. |
1461 |
* transitions. |
1272 |
*/ |
1462 |
*/ |
1273 |
error = wpi_auth(sc, vap); |
1463 |
if ((error = wpi_auth(sc, vap)) != 0) { |
1274 |
if (error != 0) { |
|
|
1275 |
device_printf(sc->sc_dev, |
1464 |
device_printf(sc->sc_dev, |
1276 |
"%s: could not move to auth state, error %d\n", |
1465 |
"%s: could not move to auth state, error %d\n", |
1277 |
__func__, error); |
1466 |
__func__, error); |
1278 |
} |
1467 |
} |
1279 |
} |
1468 |
break; |
1280 |
if (nstate == IEEE80211_S_RUN && vap->iv_state != IEEE80211_S_RUN) { |
1469 |
|
1281 |
error = wpi_run(sc, vap); |
1470 |
case IEEE80211_S_RUN: |
1282 |
if (error != 0) { |
1471 |
/* |
|
|
1472 |
* RUN -> RUN transition; Just restart the timers. |
1473 |
*/ |
1474 |
if (vap->iv_state == IEEE80211_S_RUN) { |
1475 |
wpi_calib_timeout(sc); |
1476 |
break; |
1477 |
} |
1478 |
|
1479 |
/* |
1480 |
* !RUN -> RUN requires setting the association id |
1481 |
* which is done with a firmware cmd. We also defer |
1482 |
* starting the timers until that work is done. |
1483 |
*/ |
1484 |
if ((error = wpi_run(sc, vap)) != 0) { |
1283 |
device_printf(sc->sc_dev, |
1485 |
device_printf(sc->sc_dev, |
1284 |
"%s: could not move to run state, error %d\n", |
1486 |
"%s: could not move to run state\n", __func__); |
1285 |
__func__, error); |
|
|
1286 |
} |
1487 |
} |
|
|
1488 |
break; |
1489 |
|
1490 |
default: |
1491 |
break; |
1287 |
} |
1492 |
} |
1288 |
if (nstate == IEEE80211_S_RUN) { |
|
|
1289 |
/* RUN -> RUN transition; just restart the timers */ |
1290 |
wpi_calib_timeout(sc); |
1291 |
/* XXX split out rate control timer */ |
1292 |
} |
1293 |
WPI_UNLOCK(sc); |
1493 |
WPI_UNLOCK(sc); |
1294 |
IEEE80211_LOCK(ic); |
1494 |
IEEE80211_LOCK(ic); |
1295 |
return wvp->newstate(vap, nstate, arg); |
1495 |
if (error != 0) { |
1296 |
} |
1496 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END_ERR, __func__); |
|
|
1497 |
return error; |
1498 |
} |
1297 |
|
1499 |
|
1298 |
/* |
1500 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__); |
1299 |
* Grab exclusive access to NIC memory. |
|
|
1300 |
*/ |
1301 |
static void |
1302 |
wpi_mem_lock(struct wpi_softc *sc) |
1303 |
{ |
1304 |
int ntries; |
1305 |
uint32_t tmp; |
1306 |
|
1501 |
|
1307 |
tmp = WPI_READ(sc, WPI_GPIO_CTL); |
1502 |
return wvp->newstate(vap, nstate, arg); |
1308 |
WPI_WRITE(sc, WPI_GPIO_CTL, tmp | WPI_GPIO_MAC); |
|
|
1309 |
|
1310 |
/* spin until we actually get the lock */ |
1311 |
for (ntries = 0; ntries < 100; ntries++) { |
1312 |
if ((WPI_READ(sc, WPI_GPIO_CTL) & |
1313 |
(WPI_GPIO_CLOCK | WPI_GPIO_SLEEP)) == WPI_GPIO_CLOCK) |
1314 |
break; |
1315 |
DELAY(10); |
1316 |
} |
1317 |
if (ntries == 100) |
1318 |
device_printf(sc->sc_dev, "could not lock memory\n"); |
1319 |
} |
1503 |
} |
1320 |
|
1504 |
|
1321 |
/* |
|
|
1322 |
* Release lock on NIC memory. |
1323 |
*/ |
1324 |
static void |
1505 |
static void |
1325 |
wpi_mem_unlock(struct wpi_softc *sc) |
1506 |
wpi_calib_timeout(void *arg) |
1326 |
{ |
1507 |
{ |
1327 |
uint32_t tmp = WPI_READ(sc, WPI_GPIO_CTL); |
1508 |
struct wpi_softc *sc = arg; |
1328 |
WPI_WRITE(sc, WPI_GPIO_CTL, tmp & ~WPI_GPIO_MAC); |
1509 |
struct ifnet *ifp = sc->sc_ifp; |
1329 |
} |
1510 |
struct ieee80211com *ic = ifp->if_l2com; |
|
|
1511 |
struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); |
1330 |
|
1512 |
|
1331 |
static uint32_t |
1513 |
if (vap->iv_state != IEEE80211_S_RUN) |
1332 |
wpi_mem_read(struct wpi_softc *sc, uint16_t addr) |
1514 |
return; |
1333 |
{ |
|
|
1334 |
WPI_WRITE(sc, WPI_READ_MEM_ADDR, WPI_MEM_4 | addr); |
1335 |
return WPI_READ(sc, WPI_READ_MEM_DATA); |
1336 |
} |
1337 |
|
1515 |
|
1338 |
static void |
1516 |
wpi_power_calibration(sc); |
1339 |
wpi_mem_write(struct wpi_softc *sc, uint16_t addr, uint32_t data) |
|
|
1340 |
{ |
1341 |
WPI_WRITE(sc, WPI_WRITE_MEM_ADDR, WPI_MEM_4 | addr); |
1342 |
WPI_WRITE(sc, WPI_WRITE_MEM_DATA, data); |
1343 |
} |
1344 |
|
1517 |
|
1345 |
static void |
1518 |
callout_reset(&sc->calib_to, 60*hz, wpi_calib_timeout, sc); |
1346 |
wpi_mem_write_region_4(struct wpi_softc *sc, uint16_t addr, |
|
|
1347 |
const uint32_t *data, int wlen) |
1348 |
{ |
1349 |
for (; wlen > 0; wlen--, data++, addr+=4) |
1350 |
wpi_mem_write(sc, addr, *data); |
1351 |
} |
1519 |
} |
1352 |
|
1520 |
|
1353 |
/* |
1521 |
static __inline uint8_t |
1354 |
* Read data from the EEPROM. We access EEPROM through the MAC instead of |
1522 |
rate2plcp(const uint8_t rate) |
1355 |
* using the traditional bit-bang method. Data is read up until len bytes have |
|
|
1356 |
* been obtained. |
1357 |
*/ |
1358 |
static uint16_t |
1359 |
wpi_read_prom_data(struct wpi_softc *sc, uint32_t addr, void *data, int len) |
1360 |
{ |
1523 |
{ |
1361 |
int ntries; |
1524 |
switch (rate) { |
1362 |
uint32_t val; |
1525 |
case 12: return 0xd; |
1363 |
uint8_t *out = data; |
1526 |
case 18: return 0xf; |
1364 |
|
1527 |
case 24: return 0x5; |
1365 |
wpi_mem_lock(sc); |
1528 |
case 36: return 0x7; |
1366 |
|
1529 |
case 48: return 0x9; |
1367 |
for (; len > 0; len -= 2, addr++) { |
1530 |
case 72: return 0xb; |
1368 |
WPI_WRITE(sc, WPI_EEPROM_CTL, addr << 2); |
1531 |
case 96: return 0x1; |
1369 |
|
1532 |
case 108: return 0x3; |
1370 |
for (ntries = 0; ntries < 10; ntries++) { |
1533 |
case 2: return 10; |
1371 |
if ((val = WPI_READ(sc, WPI_EEPROM_CTL)) & WPI_EEPROM_READY) |
1534 |
case 4: return 20; |
1372 |
break; |
1535 |
case 11: return 55; |
1373 |
DELAY(5); |
1536 |
case 22: return 110; |
1374 |
} |
1537 |
default: return 0; |
1375 |
|
|
|
1376 |
if (ntries == 10) { |
1377 |
device_printf(sc->sc_dev, "could not read EEPROM\n"); |
1378 |
return ETIMEDOUT; |
1379 |
} |
1380 |
|
1381 |
*out++= val >> 16; |
1382 |
if (len > 1) |
1383 |
*out ++= val >> 24; |
1384 |
} |
1538 |
} |
1385 |
|
|
|
1386 |
wpi_mem_unlock(sc); |
1387 |
|
1388 |
return 0; |
1389 |
} |
1539 |
} |
1390 |
|
1540 |
|
1391 |
/* |
1541 |
static __inline uint8_t |
1392 |
* The firmware text and data segments are transferred to the NIC using DMA. |
1542 |
plcp2rate(const uint8_t plcp) |
1393 |
* The driver just copies the firmware into DMA-safe memory and tells the NIC |
|
|
1394 |
* where to find it. Once the NIC has copied the firmware into its internal |
1395 |
* memory, we can free our local copy in the driver. |
1396 |
*/ |
1397 |
static int |
1398 |
wpi_load_microcode(struct wpi_softc *sc, const uint8_t *fw, int size) |
1399 |
{ |
1543 |
{ |
1400 |
int error, ntries; |
1544 |
switch (plcp) { |
1401 |
|
1545 |
case 0xd: return 12; |
1402 |
DPRINTFN(WPI_DEBUG_HW,("Loading microcode size 0x%x\n", size)); |
1546 |
case 0xf: return 18; |
1403 |
|
1547 |
case 0x5: return 24; |
1404 |
size /= sizeof(uint32_t); |
1548 |
case 0x7: return 36; |
1405 |
|
1549 |
case 0x9: return 48; |
1406 |
wpi_mem_lock(sc); |
1550 |
case 0xb: return 72; |
1407 |
|
1551 |
case 0x1: return 96; |
1408 |
wpi_mem_write_region_4(sc, WPI_MEM_UCODE_BASE, |
1552 |
case 0x3: return 108; |
1409 |
(const uint32_t *)fw, size); |
1553 |
case 10: return 2; |
1410 |
|
1554 |
case 20: return 4; |
1411 |
wpi_mem_write(sc, WPI_MEM_UCODE_SRC, 0); |
1555 |
case 55: return 11; |
1412 |
wpi_mem_write(sc, WPI_MEM_UCODE_DST, WPI_FW_TEXT); |
1556 |
case 110: return 22; |
1413 |
wpi_mem_write(sc, WPI_MEM_UCODE_SIZE, size); |
1557 |
default: return 0; |
1414 |
|
|
|
1415 |
/* run microcode */ |
1416 |
wpi_mem_write(sc, WPI_MEM_UCODE_CTL, WPI_UC_RUN); |
1417 |
|
1418 |
/* wait while the adapter is busy copying the firmware */ |
1419 |
for (error = 0, ntries = 0; ntries < 1000; ntries++) { |
1420 |
uint32_t status = WPI_READ(sc, WPI_TX_STATUS); |
1421 |
DPRINTFN(WPI_DEBUG_HW, |
1422 |
("firmware status=0x%x, val=0x%x, result=0x%x\n", status, |
1423 |
WPI_TX_IDLE(6), status & WPI_TX_IDLE(6))); |
1424 |
if (status & WPI_TX_IDLE(6)) { |
1425 |
DPRINTFN(WPI_DEBUG_HW, |
1426 |
("Status Match! - ntries = %d\n", ntries)); |
1427 |
break; |
1428 |
} |
1429 |
DELAY(10); |
1430 |
} |
1558 |
} |
1431 |
if (ntries == 1000) { |
1559 |
} |
1432 |
device_printf(sc->sc_dev, "timeout transferring firmware\n"); |
|
|
1433 |
error = ETIMEDOUT; |
1434 |
} |
1435 |
|
1560 |
|
1436 |
/* start the microcode executing */ |
1561 |
/* Quickly determine if a given rate is CCK or OFDM. */ |
1437 |
wpi_mem_write(sc, WPI_MEM_UCODE_CTL, WPI_UC_ENABLE); |
1562 |
#define WPI_RATE_IS_OFDM(rate) ((rate) >= 12 && (rate) != 22) |
1438 |
|
1563 |
|
1439 |
wpi_mem_unlock(sc); |
|
|
1440 |
|
1441 |
return (error); |
1442 |
} |
1443 |
|
1444 |
static void |
1564 |
static void |
1445 |
wpi_rx_intr(struct wpi_softc *sc, struct wpi_rx_desc *desc, |
1565 |
wpi_rx_done(struct wpi_softc *sc, struct wpi_rx_desc *desc, |
1446 |
struct wpi_rx_data *data) |
1566 |
struct wpi_rx_data *data) |
1447 |
{ |
1567 |
{ |
1448 |
struct ifnet *ifp = sc->sc_ifp; |
1568 |
struct ifnet *ifp = sc->sc_ifp; |
1449 |
struct ieee80211com *ic = ifp->if_l2com; |
1569 |
struct ieee80211com *ic = ifp->if_l2com; |
Lines 1451-1465
Link Here
|
1451 |
struct wpi_rx_stat *stat; |
1571 |
struct wpi_rx_stat *stat; |
1452 |
struct wpi_rx_head *head; |
1572 |
struct wpi_rx_head *head; |
1453 |
struct wpi_rx_tail *tail; |
1573 |
struct wpi_rx_tail *tail; |
|
|
1574 |
struct ieee80211_frame *wh; |
1454 |
struct ieee80211_node *ni; |
1575 |
struct ieee80211_node *ni; |
1455 |
struct mbuf *m, *mnew; |
1576 |
struct mbuf *m, *m1; |
1456 |
bus_addr_t paddr; |
1577 |
bus_addr_t paddr; |
|
|
1578 |
uint32_t flags; |
1579 |
uint16_t len; |
1457 |
int error; |
1580 |
int error; |
1458 |
|
1581 |
|
1459 |
stat = (struct wpi_rx_stat *)(desc + 1); |
1582 |
stat = (struct wpi_rx_stat *)(desc + 1); |
1460 |
|
1583 |
|
1461 |
if (stat->len > WPI_STAT_MAXLEN) { |
1584 |
if (stat->len > WPI_STAT_MAXLEN) { |
1462 |
device_printf(sc->sc_dev, "invalid rx statistic header\n"); |
1585 |
device_printf(sc->sc_dev, "invalid RX statistic header\n"); |
1463 |
if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); |
1586 |
if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); |
1464 |
return; |
1587 |
return; |
1465 |
} |
1588 |
} |
Lines 1466-1638
Link Here
|
1466 |
|
1589 |
|
1467 |
bus_dmamap_sync(ring->data_dmat, data->map, BUS_DMASYNC_POSTREAD); |
1590 |
bus_dmamap_sync(ring->data_dmat, data->map, BUS_DMASYNC_POSTREAD); |
1468 |
head = (struct wpi_rx_head *)((caddr_t)(stat + 1) + stat->len); |
1591 |
head = (struct wpi_rx_head *)((caddr_t)(stat + 1) + stat->len); |
1469 |
tail = (struct wpi_rx_tail *)((caddr_t)(head + 1) + le16toh(head->len)); |
1592 |
len = le16toh(head->len); |
|
|
1593 |
tail = (struct wpi_rx_tail *)((caddr_t)(head + 1) + len); |
1594 |
flags = le32toh(tail->flags); |
1470 |
|
1595 |
|
1471 |
DPRINTFN(WPI_DEBUG_RX, ("rx intr: idx=%d len=%d stat len=%d rssi=%d " |
1596 |
DPRINTF(sc, WPI_DEBUG_RECV, "%s: idx %d len %d stat len %u rssi %d" |
1472 |
"rate=%x chan=%d tstamp=%ju\n", ring->cur, le32toh(desc->len), |
1597 |
" rate %x chan %d tstamp %ju\n", __func__, ring->cur, |
1473 |
le16toh(head->len), (int8_t)stat->rssi, head->rate, head->chan, |
1598 |
le32toh(desc->len), len, (int8_t)stat->rssi, |
1474 |
(uintmax_t)le64toh(tail->tstamp))); |
1599 |
head->plcp, head->chan, (uintmax_t)le64toh(tail->tstamp)); |
1475 |
|
1600 |
|
1476 |
/* discard Rx frames with bad CRC early */ |
1601 |
/* Discard frames with a bad FCS early. */ |
1477 |
if ((le32toh(tail->flags) & WPI_RX_NOERROR) != WPI_RX_NOERROR) { |
1602 |
if ((flags & WPI_RX_NOERROR) != WPI_RX_NOERROR) { |
1478 |
DPRINTFN(WPI_DEBUG_RX, ("%s: rx flags error %x\n", __func__, |
1603 |
DPRINTF(sc, WPI_DEBUG_RECV, "%s: RX flags error %x\n", |
1479 |
le32toh(tail->flags))); |
1604 |
__func__, flags); |
1480 |
if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); |
1605 |
if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); |
1481 |
return; |
1606 |
return; |
1482 |
} |
1607 |
} |
1483 |
if (le16toh(head->len) < sizeof (struct ieee80211_frame)) { |
1608 |
/* Discard frames that are too short. */ |
1484 |
DPRINTFN(WPI_DEBUG_RX, ("%s: frame too short: %d\n", __func__, |
1609 |
if (len < sizeof (*wh)) { |
1485 |
le16toh(head->len))); |
1610 |
DPRINTF(sc, WPI_DEBUG_RECV, "%s: frame too short: %d\n", |
|
|
1611 |
__func__, len); |
1486 |
if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); |
1612 |
if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); |
1487 |
return; |
1613 |
return; |
1488 |
} |
1614 |
} |
1489 |
|
1615 |
|
1490 |
/* XXX don't need mbuf, just dma buffer */ |
1616 |
m1 = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, MJUMPAGESIZE); |
1491 |
mnew = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, MJUMPAGESIZE); |
1617 |
if (m1 == NULL) { |
1492 |
if (mnew == NULL) { |
1618 |
DPRINTF(sc, WPI_DEBUG_ANY, "%s: no mbuf to restock ring\n", |
1493 |
DPRINTFN(WPI_DEBUG_RX, ("%s: no mbuf to restock ring\n", |
1619 |
__func__); |
1494 |
__func__)); |
|
|
1495 |
if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); |
1620 |
if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); |
1496 |
return; |
1621 |
return; |
1497 |
} |
1622 |
} |
1498 |
bus_dmamap_unload(ring->data_dmat, data->map); |
1623 |
bus_dmamap_unload(ring->data_dmat, data->map); |
1499 |
|
1624 |
|
1500 |
error = bus_dmamap_load(ring->data_dmat, data->map, |
1625 |
error = bus_dmamap_load(ring->data_dmat, data->map, mtod(m1, void *), |
1501 |
mtod(mnew, caddr_t), MJUMPAGESIZE, |
1626 |
MJUMPAGESIZE, wpi_dma_map_addr, &paddr, BUS_DMA_NOWAIT); |
1502 |
wpi_dma_map_addr, &paddr, BUS_DMA_NOWAIT); |
|
|
1503 |
if (error != 0 && error != EFBIG) { |
1627 |
if (error != 0 && error != EFBIG) { |
1504 |
device_printf(sc->sc_dev, |
1628 |
device_printf(sc->sc_dev, |
1505 |
"%s: bus_dmamap_load failed, error %d\n", __func__, error); |
1629 |
"%s: bus_dmamap_load failed, error %d\n", __func__, error); |
1506 |
m_freem(mnew); |
1630 |
m_freem(m1); |
|
|
1631 |
|
1632 |
/* Try to reload the old mbuf. */ |
1633 |
error = bus_dmamap_load(ring->data_dmat, data->map, |
1634 |
mtod(data->m, void *), MJUMPAGESIZE, wpi_dma_map_addr, |
1635 |
&paddr, BUS_DMA_NOWAIT); |
1636 |
if (error != 0 && error != EFBIG) { |
1637 |
panic("%s: could not load old RX mbuf", __func__); |
1638 |
} |
1639 |
/* Physical address may have changed. */ |
1640 |
ring->desc[ring->cur] = htole32(paddr); |
1641 |
bus_dmamap_sync(ring->data_dmat, ring->desc_dma.map, |
1642 |
BUS_DMASYNC_PREWRITE); |
1507 |
if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); |
1643 |
if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); |
1508 |
return; |
1644 |
return; |
1509 |
} |
1645 |
} |
1510 |
bus_dmamap_sync(ring->data_dmat, data->map, BUS_DMASYNC_PREWRITE); |
|
|
1511 |
|
1646 |
|
1512 |
/* finalize mbuf and swap in new one */ |
|
|
1513 |
m = data->m; |
1647 |
m = data->m; |
|
|
1648 |
data->m = m1; |
1649 |
/* Update RX descriptor. */ |
1650 |
ring->desc[ring->cur] = htole32(paddr); |
1651 |
bus_dmamap_sync(ring->desc_dma.tag, ring->desc_dma.map, |
1652 |
BUS_DMASYNC_PREWRITE); |
1653 |
|
1654 |
/* Finalize mbuf. */ |
1514 |
m->m_pkthdr.rcvif = ifp; |
1655 |
m->m_pkthdr.rcvif = ifp; |
1515 |
m->m_data = (caddr_t)(head + 1); |
1656 |
m->m_data = (caddr_t)(head + 1); |
1516 |
m->m_pkthdr.len = m->m_len = le16toh(head->len); |
1657 |
m->m_pkthdr.len = m->m_len = len; |
1517 |
|
1658 |
|
1518 |
data->m = mnew; |
1659 |
/* Grab a reference to the source node. */ |
1519 |
/* update Rx descriptor */ |
1660 |
wh = mtod(m, struct ieee80211_frame *); |
1520 |
ring->desc[ring->cur] = htole32(paddr); |
1661 |
ni = ieee80211_find_rxnode(ic, (struct ieee80211_frame_min *)wh); |
1521 |
|
1662 |
|
1522 |
if (ieee80211_radiotap_active(ic)) { |
1663 |
if (ieee80211_radiotap_active(ic)) { |
1523 |
struct wpi_rx_radiotap_header *tap = &sc->sc_rxtap; |
1664 |
struct wpi_rx_radiotap_header *tap = &sc->sc_rxtap; |
1524 |
|
1665 |
|
1525 |
tap->wr_flags = 0; |
1666 |
tap->wr_flags = 0; |
1526 |
tap->wr_chan_freq = |
1667 |
if (head->flags & htole16(WPI_STAT_FLAG_SHPREAMBLE)) |
1527 |
htole16(ic->ic_channels[head->chan].ic_freq); |
1668 |
tap->wr_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; |
1528 |
tap->wr_chan_flags = |
|
|
1529 |
htole16(ic->ic_channels[head->chan].ic_flags); |
1530 |
tap->wr_dbm_antsignal = (int8_t)(stat->rssi - WPI_RSSI_OFFSET); |
1669 |
tap->wr_dbm_antsignal = (int8_t)(stat->rssi - WPI_RSSI_OFFSET); |
1531 |
tap->wr_dbm_antnoise = (int8_t)le16toh(stat->noise); |
1670 |
tap->wr_dbm_antnoise = (int8_t)le16toh(stat->noise); |
1532 |
tap->wr_tsft = tail->tstamp; |
1671 |
tap->wr_tsft = tail->tstamp; |
1533 |
tap->wr_antenna = (le16toh(head->flags) >> 4) & 0xf; |
1672 |
tap->wr_antenna = (le16toh(head->flags) >> 4) & 0xf; |
1534 |
switch (head->rate) { |
1673 |
tap->wr_rate = plcp2rate(head->plcp); |
1535 |
/* CCK rates */ |
|
|
1536 |
case 10: tap->wr_rate = 2; break; |
1537 |
case 20: tap->wr_rate = 4; break; |
1538 |
case 55: tap->wr_rate = 11; break; |
1539 |
case 110: tap->wr_rate = 22; break; |
1540 |
/* OFDM rates */ |
1541 |
case 0xd: tap->wr_rate = 12; break; |
1542 |
case 0xf: tap->wr_rate = 18; break; |
1543 |
case 0x5: tap->wr_rate = 24; break; |
1544 |
case 0x7: tap->wr_rate = 36; break; |
1545 |
case 0x9: tap->wr_rate = 48; break; |
1546 |
case 0xb: tap->wr_rate = 72; break; |
1547 |
case 0x1: tap->wr_rate = 96; break; |
1548 |
case 0x3: tap->wr_rate = 108; break; |
1549 |
/* unknown rate: should not happen */ |
1550 |
default: tap->wr_rate = 0; |
1551 |
} |
1552 |
if (le16toh(head->flags) & 0x4) |
1553 |
tap->wr_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; |
1554 |
} |
1674 |
} |
1555 |
|
1675 |
|
1556 |
WPI_UNLOCK(sc); |
1676 |
WPI_UNLOCK(sc); |
1557 |
|
1677 |
|
1558 |
ni = ieee80211_find_rxnode(ic, mtod(m, struct ieee80211_frame_min *)); |
1678 |
/* Send the frame to the 802.11 layer. */ |
1559 |
if (ni != NULL) { |
1679 |
if (ni != NULL) { |
1560 |
(void) ieee80211_input(ni, m, stat->rssi, 0); |
1680 |
(void)ieee80211_input(ni, m, stat->rssi, 0); |
|
|
1681 |
/* Node is no longer needed. */ |
1561 |
ieee80211_free_node(ni); |
1682 |
ieee80211_free_node(ni); |
1562 |
} else |
1683 |
} else |
1563 |
(void) ieee80211_input_all(ic, m, stat->rssi, 0); |
1684 |
(void)ieee80211_input_all(ic, m, stat->rssi, 0); |
1564 |
|
1685 |
|
1565 |
WPI_LOCK(sc); |
1686 |
WPI_LOCK(sc); |
1566 |
} |
1687 |
} |
1567 |
|
1688 |
|
1568 |
static void |
1689 |
static void |
1569 |
wpi_tx_intr(struct wpi_softc *sc, struct wpi_rx_desc *desc) |
1690 |
wpi_rx_statistics(struct wpi_softc *sc, struct wpi_rx_desc *desc, |
|
|
1691 |
struct wpi_rx_data *data) |
1570 |
{ |
1692 |
{ |
|
|
1693 |
/* Ignore */ |
1694 |
} |
1695 |
|
1696 |
static void |
1697 |
wpi_tx_done(struct wpi_softc *sc, struct wpi_rx_desc *desc) |
1698 |
{ |
1571 |
struct ifnet *ifp = sc->sc_ifp; |
1699 |
struct ifnet *ifp = sc->sc_ifp; |
1572 |
struct wpi_tx_ring *ring = &sc->txq[desc->qid & 0x3]; |
1700 |
struct wpi_tx_ring *ring = &sc->txq[desc->qid & 0x3]; |
1573 |
struct wpi_tx_data *txdata = &ring->data[desc->idx]; |
1701 |
struct wpi_tx_data *data = &ring->data[desc->idx]; |
1574 |
struct wpi_tx_stat *stat = (struct wpi_tx_stat *)(desc + 1); |
1702 |
struct wpi_tx_stat *stat = (struct wpi_tx_stat *)(desc + 1); |
1575 |
struct ieee80211_node *ni = txdata->ni; |
1703 |
struct mbuf *m; |
1576 |
struct ieee80211vap *vap = ni->ni_vap; |
1704 |
struct ieee80211_node *ni; |
1577 |
int retrycnt = 0; |
1705 |
struct ieee80211vap *vap; |
|
|
1706 |
int status = le32toh(stat->status); |
1578 |
|
1707 |
|
1579 |
DPRINTFN(WPI_DEBUG_TX, ("tx done: qid=%d idx=%d retries=%d nkill=%d " |
1708 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__); |
1580 |
"rate=%x duration=%d status=%x\n", desc->qid, desc->idx, |
|
|
1581 |
stat->ntries, stat->nkill, stat->rate, le32toh(stat->duration), |
1582 |
le32toh(stat->status))); |
1583 |
|
1709 |
|
|
|
1710 |
DPRINTF(sc, WPI_DEBUG_XMIT, "%s: " |
1711 |
"qid %d idx %d retries %d nkill %d rate %x duration %d status %x\n", |
1712 |
__func__, desc->qid, desc->idx, stat->retrycnt, |
1713 |
stat->nkill, stat->rate, le32toh(stat->duration), |
1714 |
status); |
1715 |
|
1716 |
/* Unmap and free mbuf. */ |
1717 |
bus_dmamap_sync(ring->data_dmat, data->map, BUS_DMASYNC_POSTWRITE); |
1718 |
bus_dmamap_unload(ring->data_dmat, data->map); |
1719 |
m = data->m, data->m = NULL; |
1720 |
ni = data->ni, data->ni = NULL; |
1721 |
vap = ni->ni_vap; |
1722 |
|
1584 |
/* |
1723 |
/* |
1585 |
* Update rate control statistics for the node. |
1724 |
* Update rate control statistics for the node. |
1586 |
* XXX we should not count mgmt frames since they're always sent at |
|
|
1587 |
* the lowest available bit-rate. |
1588 |
* XXX frames w/o ACK shouldn't be used either |
1589 |
*/ |
1725 |
*/ |
1590 |
if (stat->ntries > 0) { |
1726 |
if ((status & 0xff) != 1) { |
1591 |
DPRINTFN(WPI_DEBUG_TX, ("%d retries\n", stat->ntries)); |
|
|
1592 |
retrycnt = 1; |
1593 |
} |
1594 |
ieee80211_ratectl_tx_complete(vap, ni, IEEE80211_RATECTL_TX_SUCCESS, |
1595 |
&retrycnt, NULL); |
1596 |
|
1597 |
/* XXX oerrors should only count errors !maxtries */ |
1598 |
if ((le32toh(stat->status) & 0xff) != 1) |
1599 |
if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); |
1727 |
if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); |
1600 |
else |
1728 |
ieee80211_ratectl_tx_complete(vap, ni, |
|
|
1729 |
IEEE80211_RATECTL_TX_FAILURE, &stat->retrycnt, NULL); |
1730 |
} else { |
1601 |
if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1); |
1731 |
if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1); |
|
|
1732 |
ieee80211_ratectl_tx_complete(vap, ni, |
1733 |
IEEE80211_RATECTL_TX_SUCCESS, &stat->retrycnt, NULL); |
1734 |
} |
1602 |
|
1735 |
|
1603 |
bus_dmamap_sync(ring->data_dmat, txdata->map, BUS_DMASYNC_POSTWRITE); |
1736 |
ieee80211_tx_complete(ni, m, (status & 0xff) != 1); |
1604 |
bus_dmamap_unload(ring->data_dmat, txdata->map); |
|
|
1605 |
/* XXX handle M_TXCB? */ |
1606 |
m_freem(txdata->m); |
1607 |
txdata->m = NULL; |
1608 |
ieee80211_free_node(txdata->ni); |
1609 |
txdata->ni = NULL; |
1610 |
|
1737 |
|
1611 |
ring->queued--; |
1738 |
sc->sc_tx_timer = 0; |
|
|
1739 |
if (--ring->queued < WPI_TX_RING_LOMARK) { |
1740 |
sc->qfullmsk &= ~(1 << ring->qid); |
1741 |
if (sc->qfullmsk == 0 && |
1742 |
(ifp->if_drv_flags & IFF_DRV_OACTIVE)) { |
1743 |
ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; |
1744 |
wpi_start_locked(ifp); |
1745 |
} |
1746 |
} |
1612 |
|
1747 |
|
1613 |
sc->sc_tx_timer = 0; |
1748 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__); |
1614 |
ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; |
|
|
1615 |
wpi_start_locked(ifp); |
1616 |
} |
1749 |
} |
1617 |
|
1750 |
|
|
|
1751 |
/* |
1752 |
* Process a "command done" firmware notification. This is where we wakeup |
1753 |
* processes waiting for a synchronous command completion. |
1754 |
*/ |
1618 |
static void |
1755 |
static void |
1619 |
wpi_cmd_intr(struct wpi_softc *sc, struct wpi_rx_desc *desc) |
1756 |
wpi_cmd_done(struct wpi_softc *sc, struct wpi_rx_desc *desc) |
1620 |
{ |
1757 |
{ |
1621 |
struct wpi_tx_ring *ring = &sc->cmdq; |
1758 |
struct wpi_tx_ring *ring = &sc->txq[4]; |
1622 |
struct wpi_tx_data *data; |
1759 |
struct wpi_tx_data *data; |
1623 |
|
1760 |
|
1624 |
DPRINTFN(WPI_DEBUG_CMD, ("cmd notification qid=%x idx=%d flags=%x " |
1761 |
DPRINTF(sc, WPI_DEBUG_CMD, "cmd notification qid=%x idx=%d flags=%x " |
1625 |
"type=%s len=%d\n", desc->qid, desc->idx, |
1762 |
"type=%s len=%d\n", desc->qid, desc->idx, |
1626 |
desc->flags, wpi_cmd_str(desc->type), |
1763 |
desc->flags, wpi_cmd_str(desc->type), |
1627 |
le32toh(desc->len))); |
1764 |
le32toh(desc->len)); |
1628 |
|
1765 |
|
1629 |
if ((desc->qid & 7) != 4) |
1766 |
if ((desc->qid & 7) != 4) |
1630 |
return; /* not a command ack */ |
1767 |
return; /* Not a command ack. */ |
1631 |
|
1768 |
|
1632 |
data = &ring->data[desc->idx]; |
1769 |
data = &ring->data[desc->idx]; |
1633 |
|
1770 |
|
1634 |
/* if the command was mapped in a mbuf, free it */ |
1771 |
/* If the command was mapped in an mbuf, free it. */ |
1635 |
if (data->m != NULL) { |
1772 |
if (data->m != NULL) { |
|
|
1773 |
bus_dmamap_sync(ring->data_dmat, data->map, |
1774 |
BUS_DMASYNC_POSTWRITE); |
1636 |
bus_dmamap_unload(ring->data_dmat, data->map); |
1775 |
bus_dmamap_unload(ring->data_dmat, data->map); |
1637 |
m_freem(data->m); |
1776 |
m_freem(data->m); |
1638 |
data->m = NULL; |
1777 |
data->m = NULL; |
Lines 1647-1698
Link Here
|
1647 |
{ |
1786 |
{ |
1648 |
struct ifnet *ifp = sc->sc_ifp; |
1787 |
struct ifnet *ifp = sc->sc_ifp; |
1649 |
struct ieee80211com *ic = ifp->if_l2com; |
1788 |
struct ieee80211com *ic = ifp->if_l2com; |
1650 |
struct wpi_rx_desc *desc; |
1789 |
struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); |
1651 |
struct wpi_rx_data *data; |
1790 |
int hw; |
1652 |
uint32_t hw; |
|
|
1653 |
|
1791 |
|
1654 |
bus_dmamap_sync(sc->shared_dma.tag, sc->shared_dma.map, |
1792 |
bus_dmamap_sync(sc->shared_dma.tag, sc->shared_dma.map, |
1655 |
BUS_DMASYNC_POSTREAD); |
1793 |
BUS_DMASYNC_POSTREAD); |
1656 |
|
1794 |
|
1657 |
hw = le32toh(sc->shared->next); |
1795 |
hw = le32toh(sc->shared->next); |
1658 |
while (sc->rxq.cur != hw) { |
1796 |
hw = (hw == 0) ? WPI_RX_RING_COUNT - 1 : hw - 1; |
1659 |
data = &sc->rxq.data[sc->rxq.cur]; |
|
|
1660 |
|
1797 |
|
|
|
1798 |
if (sc->rxq.cur == hw) |
1799 |
return; |
1800 |
|
1801 |
do { |
1802 |
sc->rxq.cur = (sc->rxq.cur + 1) % WPI_RX_RING_COUNT; |
1803 |
|
1804 |
struct wpi_rx_data *data = &sc->rxq.data[sc->rxq.cur]; |
1805 |
struct wpi_rx_desc *desc; |
1806 |
|
1661 |
bus_dmamap_sync(sc->rxq.data_dmat, data->map, |
1807 |
bus_dmamap_sync(sc->rxq.data_dmat, data->map, |
1662 |
BUS_DMASYNC_POSTREAD); |
1808 |
BUS_DMASYNC_POSTREAD); |
1663 |
desc = (void *)data->m->m_ext.ext_buf; |
1809 |
desc = mtod(data->m, struct wpi_rx_desc *); |
1664 |
|
1810 |
|
1665 |
DPRINTFN(WPI_DEBUG_NOTIFY, |
1811 |
DPRINTF(sc, WPI_DEBUG_NOTIFY, |
1666 |
("notify qid=%x idx=%d flags=%x type=%d len=%d\n", |
1812 |
"%s: cur=%d; qid %x idx %d flags %x type %d(%s) len %d\n", |
1667 |
desc->qid, |
1813 |
__func__, sc->rxq.cur, desc->qid, desc->idx, desc->flags, |
1668 |
desc->idx, |
1814 |
desc->type, wpi_cmd_str(desc->type), le32toh(desc->len)); |
1669 |
desc->flags, |
|
|
1670 |
desc->type, |
1671 |
le32toh(desc->len))); |
1672 |
|
1815 |
|
1673 |
if (!(desc->qid & 0x80)) /* reply to a command */ |
1816 |
if (!(desc->qid & 0x80)) /* Reply to a command. */ |
1674 |
wpi_cmd_intr(sc, desc); |
1817 |
wpi_cmd_done(sc, desc); |
1675 |
|
1818 |
|
1676 |
switch (desc->type) { |
1819 |
switch (desc->type) { |
1677 |
case WPI_RX_DONE: |
1820 |
case WPI_RX_DONE: |
1678 |
/* a 802.11 frame was received */ |
1821 |
/* An 802.11 frame has been received. */ |
1679 |
wpi_rx_intr(sc, desc, data); |
1822 |
wpi_rx_done(sc, desc, data); |
1680 |
break; |
1823 |
break; |
1681 |
|
1824 |
|
1682 |
case WPI_TX_DONE: |
1825 |
case WPI_TX_DONE: |
1683 |
/* a 802.11 frame has been transmitted */ |
1826 |
/* An 802.11 frame has been transmitted. */ |
1684 |
wpi_tx_intr(sc, desc); |
1827 |
wpi_tx_done(sc, desc); |
1685 |
break; |
1828 |
break; |
1686 |
|
1829 |
|
|
|
1830 |
case WPI_RX_STATISTICS: |
1831 |
case WPI_BEACON_STATISTICS: |
1832 |
wpi_rx_statistics(sc, desc, data); |
1833 |
break; |
1834 |
|
1835 |
case WPI_BEACON_MISSED: |
1836 |
{ |
1837 |
struct wpi_beacon_missed *miss = |
1838 |
(struct wpi_beacon_missed *)(desc + 1); |
1839 |
int misses; |
1840 |
|
1841 |
bus_dmamap_sync(sc->rxq.data_dmat, data->map, |
1842 |
BUS_DMASYNC_POSTREAD); |
1843 |
misses = le32toh(miss->consecutive); |
1844 |
|
1845 |
DPRINTF(sc, WPI_DEBUG_STATE, |
1846 |
"%s: beacons missed %d/%d\n", __func__, misses, |
1847 |
le32toh(miss->total)); |
1848 |
|
1849 |
if (vap->iv_state == IEEE80211_S_RUN && |
1850 |
(ic->ic_flags & IEEE80211_S_SCAN) == 0) { |
1851 |
if (misses >= vap->iv_bmissthreshold) { |
1852 |
WPI_UNLOCK(sc); |
1853 |
ieee80211_beacon_miss(ic); |
1854 |
WPI_LOCK(sc); |
1855 |
} |
1856 |
} |
1857 |
break; |
1858 |
} |
1687 |
case WPI_UC_READY: |
1859 |
case WPI_UC_READY: |
1688 |
{ |
1860 |
{ |
1689 |
struct wpi_ucode_info *uc = |
1861 |
struct wpi_ucode_info *uc = |
1690 |
(struct wpi_ucode_info *)(desc + 1); |
1862 |
(struct wpi_ucode_info *)(desc + 1); |
1691 |
|
1863 |
|
1692 |
/* the microcontroller is ready */ |
1864 |
/* The microcontroller is ready. */ |
1693 |
DPRINTF(("microcode alive notification version %x " |
1865 |
bus_dmamap_sync(sc->rxq.data_dmat, data->map, |
1694 |
"alive %x\n", le32toh(uc->version), |
1866 |
BUS_DMASYNC_POSTREAD); |
1695 |
le32toh(uc->valid))); |
1867 |
DPRINTF(sc, WPI_DEBUG_RESET, |
|
|
1868 |
"microcode alive notification version=%d.%d " |
1869 |
"subtype=%x alive=%x\n", uc->major, uc->minor, |
1870 |
uc->subtype, le32toh(uc->valid)); |
1696 |
|
1871 |
|
1697 |
if (le32toh(uc->valid) != 1) { |
1872 |
if (le32toh(uc->valid) != 1) { |
1698 |
device_printf(sc->sc_dev, |
1873 |
device_printf(sc->sc_dev, |
Lines 1699-1774
Link Here
|
1699 |
"microcontroller initialization failed\n"); |
1874 |
"microcontroller initialization failed\n"); |
1700 |
wpi_stop_locked(sc); |
1875 |
wpi_stop_locked(sc); |
1701 |
} |
1876 |
} |
|
|
1877 |
/* Save the address of the error log in SRAM. */ |
1878 |
sc->errptr = le32toh(uc->errptr); |
1702 |
break; |
1879 |
break; |
1703 |
} |
1880 |
} |
1704 |
case WPI_STATE_CHANGED: |
1881 |
case WPI_STATE_CHANGED: |
1705 |
{ |
1882 |
{ |
|
|
1883 |
bus_dmamap_sync(sc->rxq.data_dmat, data->map, |
1884 |
BUS_DMASYNC_POSTREAD); |
1885 |
|
1706 |
uint32_t *status = (uint32_t *)(desc + 1); |
1886 |
uint32_t *status = (uint32_t *)(desc + 1); |
1707 |
|
1887 |
#ifdef WPI_DEBUG |
1708 |
/* enabled/disabled notification */ |
1888 |
DPRINTF(sc, WPI_DEBUG_STATE, "state changed to %x\n", |
1709 |
DPRINTF(("state changed to %x\n", le32toh(*status))); |
1889 |
le32toh(*status)); |
1710 |
|
1890 |
#endif |
1711 |
if (le32toh(*status) & 1) { |
1891 |
if (le32toh(*status) & 1) { |
1712 |
device_printf(sc->sc_dev, |
1892 |
ieee80211_runtask(ic, &sc->sc_radiooff_task); |
1713 |
"Radio transmitter is switched off\n"); |
1893 |
return; |
1714 |
sc->flags |= WPI_FLAG_HW_RADIO_OFF; |
|
|
1715 |
ifp->if_drv_flags &= ~IFF_DRV_RUNNING; |
1716 |
/* Disable firmware commands */ |
1717 |
WPI_WRITE(sc, WPI_UCODE_SET, WPI_DISABLE_CMD); |
1718 |
} |
1894 |
} |
1719 |
break; |
1895 |
break; |
1720 |
} |
1896 |
} |
1721 |
case WPI_START_SCAN: |
1897 |
case WPI_START_SCAN: |
1722 |
{ |
1898 |
{ |
|
|
1899 |
bus_dmamap_sync(sc->rxq.data_dmat, data->map, |
1900 |
BUS_DMASYNC_POSTREAD); |
1723 |
#ifdef WPI_DEBUG |
1901 |
#ifdef WPI_DEBUG |
1724 |
struct wpi_start_scan *scan = |
1902 |
struct wpi_start_scan *scan = |
1725 |
(struct wpi_start_scan *)(desc + 1); |
1903 |
(struct wpi_start_scan *)(desc + 1); |
|
|
1904 |
DPRINTF(sc, WPI_DEBUG_SCAN, |
1905 |
"%s: scanning channel %d status %x\n", |
1906 |
__func__, scan->chan, le32toh(scan->status)); |
1726 |
#endif |
1907 |
#endif |
1727 |
|
|
|
1728 |
DPRINTFN(WPI_DEBUG_SCANNING, |
1729 |
("scanning channel %d status %x\n", |
1730 |
scan->chan, le32toh(scan->status))); |
1731 |
break; |
1908 |
break; |
1732 |
} |
1909 |
} |
1733 |
case WPI_STOP_SCAN: |
1910 |
case WPI_STOP_SCAN: |
1734 |
{ |
1911 |
{ |
|
|
1912 |
bus_dmamap_sync(sc->rxq.data_dmat, data->map, |
1913 |
BUS_DMASYNC_POSTREAD); |
1735 |
#ifdef WPI_DEBUG |
1914 |
#ifdef WPI_DEBUG |
1736 |
struct wpi_stop_scan *scan = |
1915 |
struct wpi_stop_scan *scan = |
1737 |
(struct wpi_stop_scan *)(desc + 1); |
1916 |
(struct wpi_stop_scan *)(desc + 1); |
|
|
1917 |
DPRINTF(sc, WPI_DEBUG_SCAN, |
1918 |
"scan finished nchan=%d status=%d chan=%d\n", |
1919 |
scan->nchan, scan->status, scan->chan); |
1738 |
#endif |
1920 |
#endif |
1739 |
struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); |
|
|
1740 |
|
1741 |
DPRINTFN(WPI_DEBUG_SCANNING, |
1742 |
("scan finished nchan=%d status=%d chan=%d\n", |
1743 |
scan->nchan, scan->status, scan->chan)); |
1744 |
|
1745 |
sc->sc_scan_timer = 0; |
1921 |
sc->sc_scan_timer = 0; |
|
|
1922 |
WPI_UNLOCK(sc); |
1746 |
ieee80211_scan_next(vap); |
1923 |
ieee80211_scan_next(vap); |
|
|
1924 |
WPI_LOCK(sc); |
1747 |
break; |
1925 |
break; |
1748 |
} |
1926 |
} |
1749 |
case WPI_MISSED_BEACON: |
1927 |
} |
1750 |
{ |
1928 |
} while (sc->rxq.cur != hw); |
1751 |
struct wpi_missed_beacon *beacon = |
|
|
1752 |
(struct wpi_missed_beacon *)(desc + 1); |
1753 |
struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); |
1754 |
|
1929 |
|
1755 |
if (le32toh(beacon->consecutive) >= |
1930 |
/* Tell the firmware what we have processed. */ |
1756 |
vap->iv_bmissthreshold) { |
1931 |
wpi_update_rx_ring(sc); |
1757 |
DPRINTF(("Beacon miss: %u >= %u\n", |
1932 |
} |
1758 |
le32toh(beacon->consecutive), |
1933 |
|
1759 |
vap->iv_bmissthreshold)); |
1934 |
/* |
1760 |
ieee80211_beacon_miss(ic); |
1935 |
* Process an INT_WAKEUP interrupt raised when the microcontroller wakes up |
1761 |
} |
1936 |
* from power-down sleep mode. |
1762 |
break; |
1937 |
*/ |
|
|
1938 |
static void |
1939 |
wpi_wakeup_intr(struct wpi_softc *sc) |
1940 |
{ |
1941 |
int qid; |
1942 |
|
1943 |
DPRINTF(sc, WPI_DEBUG_RESET, |
1944 |
"%s: ucode wakeup from power-down sleep\n", __func__); |
1945 |
|
1946 |
/* Wakeup RX and TX rings. */ |
1947 |
if (sc->rxq.update) { |
1948 |
wpi_update_rx_ring(sc); |
1949 |
sc->rxq.update = 0; |
1950 |
} |
1951 |
for (qid = 0; qid < WPI_NTXQUEUES; qid++) { |
1952 |
struct wpi_tx_ring *ring = &sc->txq[qid]; |
1953 |
|
1954 |
if (ring->update) { |
1955 |
wpi_update_tx_ring(sc, ring); |
1956 |
ring->update = 0; |
1763 |
} |
1957 |
} |
1764 |
} |
1958 |
} |
1765 |
|
1959 |
|
1766 |
sc->rxq.cur = (sc->rxq.cur + 1) % WPI_RX_RING_COUNT; |
1960 |
WPI_CLRBITS(sc, WPI_GP_CNTRL, WPI_GP_CNTRL_MAC_ACCESS_REQ); |
|
|
1961 |
} |
1962 |
|
1963 |
/* |
1964 |
* Dump the error log of the firmware when a firmware panic occurs. Although |
1965 |
* we can't debug the firmware because it is neither open source nor free, it |
1966 |
* can help us to identify certain classes of problems. |
1967 |
*/ |
1968 |
static void |
1969 |
wpi_fatal_intr(struct wpi_softc *sc) |
1970 |
{ |
1971 |
struct wpi_fw_dump dump; |
1972 |
uint32_t i, offset, count; |
1973 |
const uint32_t size_errmsg = |
1974 |
(sizeof (wpi_fw_errmsg) / sizeof ((wpi_fw_errmsg)[0])); |
1975 |
|
1976 |
/* Check that the error log address is valid. */ |
1977 |
if (sc->errptr < WPI_FW_DATA_BASE || |
1978 |
sc->errptr + sizeof (dump) > |
1979 |
WPI_FW_DATA_BASE + WPI_FW_DATA_MAXSZ) { |
1980 |
printf("%s: bad firmware error log address 0x%08x\n", __func__, |
1981 |
sc->errptr); |
1982 |
return; |
1983 |
} |
1984 |
if (wpi_nic_lock(sc) != 0) { |
1985 |
printf("%s: could not read firmware error log\n", __func__); |
1986 |
return; |
1987 |
} |
1988 |
/* Read number of entries in the log. */ |
1989 |
count = wpi_mem_read(sc, sc->errptr); |
1990 |
if (count == 0 || count * sizeof (dump) > WPI_FW_DATA_MAXSZ) { |
1991 |
printf("%s: invalid count field (count = %u)\n", __func__, |
1992 |
count); |
1993 |
wpi_nic_unlock(sc); |
1994 |
return; |
1767 |
} |
1995 |
} |
|
|
1996 |
/* Skip "count" field. */ |
1997 |
offset = sc->errptr + sizeof (uint32_t); |
1998 |
printf("firmware error log (count = %u):\n", count); |
1999 |
for (i = 0; i < count; i++) { |
2000 |
wpi_mem_read_region_4(sc, offset, (uint32_t *)&dump, |
2001 |
sizeof (dump) / sizeof (uint32_t)); |
1768 |
|
2002 |
|
1769 |
/* tell the firmware what we have processed */ |
2003 |
printf(" error type = \"%s\" (0x%08X)\n", |
1770 |
hw = (hw == 0) ? WPI_RX_RING_COUNT - 1 : hw - 1; |
2004 |
(dump.desc < size_errmsg) ? |
1771 |
WPI_WRITE(sc, WPI_RX_WIDX, hw & ~7); |
2005 |
wpi_fw_errmsg[dump.desc] : "UNKNOWN", |
|
|
2006 |
dump.desc); |
2007 |
printf(" error data = 0x%08X\n", |
2008 |
dump.data); |
2009 |
printf(" branch link = 0x%08X%08X\n", |
2010 |
dump.blink[0], dump.blink[1]); |
2011 |
printf(" interrupt link = 0x%08X%08X\n", |
2012 |
dump.ilink[0], dump.ilink[1]); |
2013 |
printf(" time = %u\n", dump.time); |
2014 |
|
2015 |
offset += sizeof (dump); |
2016 |
} |
2017 |
wpi_nic_unlock(sc); |
2018 |
/* Dump driver status (TX and RX rings) while we're here. */ |
2019 |
printf("driver status:\n"); |
2020 |
for (i = 0; i < WPI_NTXQUEUES; i++) { |
2021 |
struct wpi_tx_ring *ring = &sc->txq[i]; |
2022 |
printf(" tx ring %2d: qid=%-2d cur=%-3d queued=%-3d\n", |
2023 |
i, ring->qid, ring->cur, ring->queued); |
2024 |
} |
2025 |
printf(" rx ring: cur=%d\n", sc->rxq.cur); |
1772 |
} |
2026 |
} |
1773 |
|
2027 |
|
1774 |
static void |
2028 |
static void |
Lines 1775-2022
Link Here
|
1775 |
wpi_intr(void *arg) |
2029 |
wpi_intr(void *arg) |
1776 |
{ |
2030 |
{ |
1777 |
struct wpi_softc *sc = arg; |
2031 |
struct wpi_softc *sc = arg; |
1778 |
uint32_t r; |
2032 |
struct ifnet *ifp = sc->sc_ifp; |
|
|
2033 |
uint32_t r1, r2; |
1779 |
|
2034 |
|
1780 |
WPI_LOCK(sc); |
2035 |
WPI_LOCK(sc); |
1781 |
|
2036 |
|
1782 |
r = WPI_READ(sc, WPI_INTR); |
2037 |
/* Disable interrupts. */ |
1783 |
if (r == 0 || r == 0xffffffff) { |
2038 |
WPI_WRITE(sc, WPI_INT_MASK, 0); |
|
|
2039 |
|
2040 |
r1 = WPI_READ(sc, WPI_INT); |
2041 |
|
2042 |
if (r1 == 0xffffffff || (r1 & 0xfffffff0) == 0xa5a5a5a0) { |
1784 |
WPI_UNLOCK(sc); |
2043 |
WPI_UNLOCK(sc); |
1785 |
return; |
2044 |
return; /* Hardware gone! */ |
1786 |
} |
2045 |
} |
1787 |
|
2046 |
|
1788 |
/* disable interrupts */ |
2047 |
r2 = WPI_READ(sc, WPI_FH_INT); |
1789 |
WPI_WRITE(sc, WPI_MASK, 0); |
|
|
1790 |
/* ack interrupts */ |
1791 |
WPI_WRITE(sc, WPI_INTR, r); |
1792 |
|
2048 |
|
1793 |
if (r & (WPI_SW_ERROR | WPI_HW_ERROR)) { |
2049 |
DPRINTF(sc, WPI_DEBUG_INTR, "%s: reg1=0x%08x reg2=0x%08x\n", __func__, |
1794 |
struct ifnet *ifp = sc->sc_ifp; |
2050 |
r1, r2); |
|
|
2051 |
|
2052 |
if (r1 == 0 && r2 == 0) |
2053 |
goto done; /* Interrupt not for us. */ |
2054 |
|
2055 |
/* Acknowledge interrupts. */ |
2056 |
WPI_WRITE(sc, WPI_INT, r1); |
2057 |
WPI_WRITE(sc, WPI_FH_INT, r2); |
2058 |
|
2059 |
if (r1 & (WPI_INT_SW_ERR | WPI_INT_HW_ERR)) { |
1795 |
struct ieee80211com *ic = ifp->if_l2com; |
2060 |
struct ieee80211com *ic = ifp->if_l2com; |
1796 |
struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); |
|
|
1797 |
|
2061 |
|
1798 |
device_printf(sc->sc_dev, "fatal firmware error\n"); |
2062 |
device_printf(sc->sc_dev, "fatal firmware error\n"); |
1799 |
DPRINTFN(6,("(%s)\n", (r & WPI_SW_ERROR) ? "(Software Error)" : |
2063 |
wpi_fatal_intr(sc); |
1800 |
"(Hardware Error)")); |
2064 |
DPRINTF(sc, WPI_DEBUG_HW, |
1801 |
if (vap != NULL) |
2065 |
"(%s)\n", (r1 & WPI_INT_SW_ERR) ? "(Software Error)" : |
1802 |
ieee80211_cancel_scan(vap); |
2066 |
"(Hardware Error)"); |
1803 |
ieee80211_runtask(ic, &sc->sc_restarttask); |
2067 |
ieee80211_runtask(ic, &sc->sc_reinittask); |
1804 |
sc->flags &= ~WPI_FLAG_BUSY; |
|
|
1805 |
WPI_UNLOCK(sc); |
2068 |
WPI_UNLOCK(sc); |
1806 |
return; |
2069 |
return; |
1807 |
} |
2070 |
} |
1808 |
|
2071 |
|
1809 |
if (r & WPI_RX_INTR) |
2072 |
if ((r1 & (WPI_INT_FH_RX | WPI_INT_SW_RX)) || |
|
|
2073 |
(r2 & WPI_FH_INT_RX)) |
1810 |
wpi_notif_intr(sc); |
2074 |
wpi_notif_intr(sc); |
1811 |
|
2075 |
|
1812 |
if (r & WPI_ALIVE_INTR) /* firmware initialized */ |
2076 |
if (r1 & WPI_INT_ALIVE) |
1813 |
wakeup(sc); |
2077 |
wakeup(sc); /* Firmware is alive. */ |
1814 |
|
2078 |
|
1815 |
/* re-enable interrupts */ |
2079 |
if (r1 & WPI_INT_WAKEUP) |
1816 |
if (sc->sc_ifp->if_flags & IFF_UP) |
2080 |
wpi_wakeup_intr(sc); |
1817 |
WPI_WRITE(sc, WPI_MASK, WPI_INTR_MASK); |
|
|
1818 |
|
2081 |
|
|
|
2082 |
done: |
2083 |
/* Re-enable interrupts. */ |
2084 |
if (ifp->if_flags & IFF_UP) |
2085 |
WPI_WRITE(sc, WPI_INT_MASK, WPI_INT_MASK_DEF); |
2086 |
|
1819 |
WPI_UNLOCK(sc); |
2087 |
WPI_UNLOCK(sc); |
1820 |
} |
2088 |
} |
1821 |
|
2089 |
|
1822 |
static uint8_t |
2090 |
static int |
1823 |
wpi_plcp_signal(int rate) |
2091 |
wpi_cmd2(struct wpi_softc *sc, struct wpi_buf *buf) |
1824 |
{ |
2092 |
{ |
1825 |
switch (rate) { |
2093 |
struct ieee80211_frame *wh; |
1826 |
/* CCK rates (returned values are device-dependent) */ |
2094 |
struct wpi_tx_cmd *cmd; |
1827 |
case 2: return 10; |
2095 |
struct wpi_tx_data *data; |
1828 |
case 4: return 20; |
2096 |
struct wpi_tx_desc *desc; |
1829 |
case 11: return 55; |
2097 |
struct wpi_tx_ring *ring; |
1830 |
case 22: return 110; |
2098 |
struct mbuf *m1; |
|
|
2099 |
bus_dma_segment_t *seg, segs[WPI_MAX_SCATTER]; |
2100 |
u_int hdrlen; |
2101 |
int error, i, nsegs, pad, totlen; |
1831 |
|
2102 |
|
1832 |
/* OFDM rates (cf IEEE Std 802.11a-1999, pp. 14 Table 80) */ |
2103 |
WPI_LOCK_ASSERT(sc); |
1833 |
/* R1-R4 (ral/ural is R4-R1) */ |
|
|
1834 |
case 12: return 0xd; |
1835 |
case 18: return 0xf; |
1836 |
case 24: return 0x5; |
1837 |
case 36: return 0x7; |
1838 |
case 48: return 0x9; |
1839 |
case 72: return 0xb; |
1840 |
case 96: return 0x1; |
1841 |
case 108: return 0x3; |
1842 |
|
2104 |
|
1843 |
/* unsupported rates (should not get there) */ |
2105 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__); |
1844 |
default: return 0; |
2106 |
|
|
|
2107 |
wh = mtod(buf->m, struct ieee80211_frame *); |
2108 |
hdrlen = ieee80211_anyhdrsize(wh); |
2109 |
totlen = buf->m->m_pkthdr.len; |
2110 |
|
2111 |
if (hdrlen & 3) { |
2112 |
/* First segment length must be a multiple of 4. */ |
2113 |
pad = 4 - (hdrlen & 3); |
2114 |
} else |
2115 |
pad = 0; |
2116 |
|
2117 |
ring = &sc->txq[buf->ac]; |
2118 |
desc = &ring->desc[ring->cur]; |
2119 |
data = &ring->data[ring->cur]; |
2120 |
|
2121 |
/* Prepare TX firmware command. */ |
2122 |
cmd = &ring->cmd[ring->cur]; |
2123 |
cmd->code = buf->code; |
2124 |
cmd->flags = 0; |
2125 |
cmd->qid = ring->qid; |
2126 |
cmd->idx = ring->cur; |
2127 |
|
2128 |
memcpy(cmd->data, buf->data, buf->size); |
2129 |
|
2130 |
/* Save and trim IEEE802.11 header. */ |
2131 |
memcpy((uint8_t *)(cmd->data + buf->size), wh, hdrlen); |
2132 |
m_adj(buf->m, hdrlen); |
2133 |
|
2134 |
error = bus_dmamap_load_mbuf_sg(ring->data_dmat, data->map, buf->m, |
2135 |
segs, &nsegs, BUS_DMA_NOWAIT); |
2136 |
if (error != 0 && error != EFBIG) { |
2137 |
device_printf(sc->sc_dev, |
2138 |
"%s: can't map mbuf (error %d)\n", __func__, error); |
2139 |
m_freem(buf->m); |
2140 |
return error; |
1845 |
} |
2141 |
} |
|
|
2142 |
if (error != 0) { |
2143 |
/* Too many DMA segments, linearize mbuf. */ |
2144 |
m1 = m_collapse(buf->m, M_NOWAIT, WPI_MAX_SCATTER); |
2145 |
if (m1 == NULL) { |
2146 |
device_printf(sc->sc_dev, |
2147 |
"%s: could not defrag mbuf\n", __func__); |
2148 |
m_freem(buf->m); |
2149 |
return ENOBUFS; |
2150 |
} |
2151 |
buf->m = m1; |
2152 |
|
2153 |
error = bus_dmamap_load_mbuf_sg(ring->data_dmat, data->map, |
2154 |
buf->m, segs, &nsegs, BUS_DMA_NOWAIT); |
2155 |
if (error != 0) { |
2156 |
device_printf(sc->sc_dev, |
2157 |
"%s: can't map mbuf (error %d)\n", __func__, error); |
2158 |
m_freem(buf->m); |
2159 |
return error; |
2160 |
} |
2161 |
} |
2162 |
|
2163 |
data->m = buf->m; |
2164 |
data->ni = buf->ni; |
2165 |
|
2166 |
DPRINTF(sc, WPI_DEBUG_XMIT, "%s: qid %d idx %d len %d nsegs %d\n", |
2167 |
__func__, ring->qid, ring->cur, totlen, nsegs); |
2168 |
|
2169 |
/* Fill TX descriptor. */ |
2170 |
desc->nsegs = WPI_PAD32(totlen) << 4 | (1 + nsegs); |
2171 |
/* First DMA segment is used by the TX command. */ |
2172 |
desc->segs[0].addr = htole32(data->cmd_paddr); |
2173 |
desc->segs[0].len = htole32(4 + buf->size + hdrlen + pad); |
2174 |
/* Other DMA segments are for data payload. */ |
2175 |
seg = &segs[0]; |
2176 |
for (i = 1; i <= nsegs; i++) { |
2177 |
desc->segs[i].addr = htole32(seg->ds_addr); |
2178 |
desc->segs[i].len = htole32(seg->ds_len); |
2179 |
seg++; |
2180 |
} |
2181 |
|
2182 |
bus_dmamap_sync(ring->data_dmat, data->map, BUS_DMASYNC_PREWRITE); |
2183 |
bus_dmamap_sync(ring->data_dmat, ring->cmd_dma.map, |
2184 |
BUS_DMASYNC_PREWRITE); |
2185 |
bus_dmamap_sync(ring->desc_dma.tag, ring->desc_dma.map, |
2186 |
BUS_DMASYNC_PREWRITE); |
2187 |
|
2188 |
/* Kick TX ring. */ |
2189 |
ring->cur = (ring->cur + 1) % WPI_TX_RING_COUNT; |
2190 |
wpi_update_tx_ring(sc, ring); |
2191 |
|
2192 |
/* Mark TX ring as full if we reach a certain threshold. */ |
2193 |
if (++ring->queued > WPI_TX_RING_HIMARK) |
2194 |
sc->qfullmsk |= 1 << ring->qid; |
2195 |
|
2196 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__); |
2197 |
|
2198 |
return 0; |
1846 |
} |
2199 |
} |
1847 |
|
2200 |
|
1848 |
/* quickly determine if a given rate is CCK or OFDM */ |
|
|
1849 |
#define WPI_RATE_IS_OFDM(rate) ((rate) >= 12 && (rate) != 22) |
1850 |
|
1851 |
/* |
2201 |
/* |
1852 |
* Construct the data packet for a transmit buffer and acutally put |
2202 |
* Construct the data packet for a transmit buffer. |
1853 |
* the buffer onto the transmit ring, kicking the card to process the |
|
|
1854 |
* the buffer. |
1855 |
*/ |
2203 |
*/ |
1856 |
static int |
2204 |
static int |
1857 |
wpi_tx_data(struct wpi_softc *sc, struct mbuf *m0, struct ieee80211_node *ni, |
2205 |
wpi_tx_data(struct wpi_softc *sc, struct mbuf *m, struct ieee80211_node *ni) |
1858 |
int ac) |
|
|
1859 |
{ |
2206 |
{ |
|
|
2207 |
const struct ieee80211_txparam *tp; |
1860 |
struct ieee80211vap *vap = ni->ni_vap; |
2208 |
struct ieee80211vap *vap = ni->ni_vap; |
1861 |
struct ifnet *ifp = sc->sc_ifp; |
2209 |
struct ieee80211com *ic = ni->ni_ic; |
1862 |
struct ieee80211com *ic = ifp->if_l2com; |
2210 |
struct wpi_node *wn = (void *)ni; |
1863 |
const struct chanAccParams *cap = &ic->ic_wme.wme_chanParams; |
2211 |
struct ieee80211_channel *chan; |
1864 |
struct wpi_tx_ring *ring = &sc->txq[ac]; |
|
|
1865 |
struct wpi_tx_desc *desc; |
1866 |
struct wpi_tx_data *data; |
1867 |
struct wpi_tx_cmd *cmd; |
1868 |
struct wpi_cmd_data *tx; |
1869 |
struct ieee80211_frame *wh; |
2212 |
struct ieee80211_frame *wh; |
1870 |
const struct ieee80211_txparam *tp; |
2213 |
struct ieee80211_key *k = NULL; |
1871 |
struct ieee80211_key *k; |
2214 |
struct wpi_cmd_data tx; |
1872 |
struct mbuf *mnew; |
2215 |
struct wpi_buf tx_data; |
1873 |
int i, error, nsegs, rate, hdrlen, ismcast; |
2216 |
uint32_t flags; |
1874 |
bus_dma_segment_t segs[WPI_MAX_SCATTER]; |
2217 |
uint16_t qos; |
|
|
2218 |
uint8_t tid, type; |
2219 |
int ac, rate, ismcast, totlen; |
1875 |
|
2220 |
|
1876 |
desc = &ring->desc[ring->cur]; |
2221 |
wh = mtod(m, struct ieee80211_frame *); |
1877 |
data = &ring->data[ring->cur]; |
2222 |
type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK; |
|
|
2223 |
ismcast = IEEE80211_IS_MULTICAST(wh->i_addr1); |
1878 |
|
2224 |
|
1879 |
wh = mtod(m0, struct ieee80211_frame *); |
2225 |
/* Select EDCA Access Category and TX ring for this frame. */ |
|
|
2226 |
if (IEEE80211_QOS_HAS_SEQ(wh)) { |
2227 |
qos = ((const struct ieee80211_qosframe *)wh)->i_qos[0]; |
2228 |
tid = qos & IEEE80211_QOS_TID; |
2229 |
} else { |
2230 |
qos = 0; |
2231 |
tid = 0; |
2232 |
} |
2233 |
ac = M_WME_GETAC(m); |
1880 |
|
2234 |
|
1881 |
hdrlen = ieee80211_hdrsize(wh); |
2235 |
chan = (ni->ni_chan != IEEE80211_CHAN_ANYC) ? |
1882 |
ismcast = IEEE80211_IS_MULTICAST(wh->i_addr1); |
2236 |
ni->ni_chan : ic->ic_curchan; |
|
|
2237 |
tp = &vap->iv_txparms[ieee80211_chan2mode(chan)]; |
1883 |
|
2238 |
|
|
|
2239 |
/* Choose a TX rate index. */ |
2240 |
if (type == IEEE80211_FC0_TYPE_MGT) |
2241 |
rate = tp->mgmtrate; |
2242 |
else if (ismcast) |
2243 |
rate = tp->mcastrate; |
2244 |
else if (tp->ucastrate != IEEE80211_FIXED_RATE_NONE) |
2245 |
rate = tp->ucastrate; |
2246 |
else if (m->m_flags & M_EAPOL) |
2247 |
rate = tp->mgmtrate; |
2248 |
else { |
2249 |
/* XXX pass pktlen */ |
2250 |
(void) ieee80211_ratectl_rate(ni, NULL, 0); |
2251 |
rate = ni->ni_txrate; |
2252 |
} |
2253 |
|
2254 |
/* Encrypt the frame if need be. */ |
1884 |
if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) { |
2255 |
if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) { |
1885 |
k = ieee80211_crypto_encap(ni, m0); |
2256 |
/* Retrieve key for TX. */ |
|
|
2257 |
k = ieee80211_crypto_encap(ni, m); |
1886 |
if (k == NULL) { |
2258 |
if (k == NULL) { |
1887 |
m_freem(m0); |
2259 |
m_freem(m); |
1888 |
return ENOBUFS; |
2260 |
return ENOBUFS; |
1889 |
} |
2261 |
} |
1890 |
/* packet header may have moved, reset our local pointer */ |
2262 |
/* 802.11 header may have moved. */ |
1891 |
wh = mtod(m0, struct ieee80211_frame *); |
2263 |
wh = mtod(m, struct ieee80211_frame *); |
1892 |
} |
2264 |
} |
|
|
2265 |
totlen = m->m_pkthdr.len; |
1893 |
|
2266 |
|
1894 |
cmd = &ring->cmd[ring->cur]; |
2267 |
if (ieee80211_radiotap_active_vap(vap)) { |
1895 |
cmd->code = WPI_CMD_TX_DATA; |
2268 |
struct wpi_tx_radiotap_header *tap = &sc->sc_txtap; |
1896 |
cmd->flags = 0; |
|
|
1897 |
cmd->qid = ring->qid; |
1898 |
cmd->idx = ring->cur; |
1899 |
|
2269 |
|
1900 |
tx = (struct wpi_cmd_data *)cmd->data; |
2270 |
tap->wt_flags = 0; |
1901 |
tx->flags = htole32(WPI_TX_AUTO_SEQ); |
2271 |
tap->wt_rate = rate; |
1902 |
tx->timeout = htole16(0); |
2272 |
if (k != NULL) |
1903 |
tx->ofdm_mask = 0xff; |
2273 |
tap->wt_flags |= IEEE80211_RADIOTAP_F_WEP; |
1904 |
tx->cck_mask = 0x0f; |
|
|
1905 |
tx->lifetime = htole32(WPI_LIFETIME_INFINITE); |
1906 |
tx->id = ismcast ? WPI_ID_BROADCAST : WPI_ID_BSS; |
1907 |
tx->len = htole16(m0->m_pkthdr.len); |
1908 |
|
2274 |
|
|
|
2275 |
ieee80211_radiotap_tx(vap, m); |
2276 |
} |
2277 |
|
2278 |
flags = 0; |
1909 |
if (!ismcast) { |
2279 |
if (!ismcast) { |
1910 |
if ((ni->ni_flags & IEEE80211_NODE_QOS) == 0 || |
2280 |
/* Unicast frame, check if an ACK is expected. */ |
1911 |
!cap->cap_wmeParams[ac].wmep_noackPolicy) |
2281 |
if (!qos || (qos & IEEE80211_QOS_ACKPOLICY) != |
1912 |
tx->flags |= htole32(WPI_TX_NEED_ACK); |
2282 |
IEEE80211_QOS_ACKPOLICY_NOACK) |
1913 |
if (m0->m_pkthdr.len + IEEE80211_CRC_LEN > vap->iv_rtsthreshold) { |
2283 |
flags |= WPI_TX_NEED_ACK; |
1914 |
tx->flags |= htole32(WPI_TX_NEED_RTS|WPI_TX_FULL_TXOP); |
2284 |
} |
1915 |
tx->rts_ntries = 7; |
2285 |
|
|
|
2286 |
/* Check if frame must be protected using RTS/CTS or CTS-to-self. */ |
2287 |
if (!ismcast) { |
2288 |
/* NB: Group frames are sent using CCK in 802.11b/g. */ |
2289 |
if (totlen + IEEE80211_CRC_LEN > vap->iv_rtsthreshold) { |
2290 |
flags |= WPI_TX_NEED_RTS; |
2291 |
} else if ((ic->ic_flags & IEEE80211_F_USEPROT) && |
2292 |
WPI_RATE_IS_OFDM(rate)) { |
2293 |
if (ic->ic_protmode == IEEE80211_PROT_CTSONLY) |
2294 |
flags |= WPI_TX_NEED_CTS; |
2295 |
else if (ic->ic_protmode == IEEE80211_PROT_RTSCTS) |
2296 |
flags |= WPI_TX_NEED_RTS; |
1916 |
} |
2297 |
} |
|
|
2298 |
|
2299 |
if (flags & (WPI_TX_NEED_RTS | WPI_TX_NEED_CTS)) |
2300 |
flags |= WPI_TX_FULL_TXOP; |
1917 |
} |
2301 |
} |
1918 |
/* pick a rate */ |
2302 |
|
1919 |
tp = &vap->iv_txparms[ieee80211_chan2mode(ni->ni_chan)]; |
2303 |
if (type == IEEE80211_FC0_TYPE_MGT) { |
1920 |
if ((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) == IEEE80211_FC0_TYPE_MGT) { |
|
|
1921 |
uint8_t subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK; |
2304 |
uint8_t subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK; |
1922 |
/* tell h/w to set timestamp in probe responses */ |
2305 |
|
|
|
2306 |
/* Tell HW to set timestamp in probe responses. */ |
1923 |
if (subtype == IEEE80211_FC0_SUBTYPE_PROBE_RESP) |
2307 |
if (subtype == IEEE80211_FC0_SUBTYPE_PROBE_RESP) |
1924 |
tx->flags |= htole32(WPI_TX_INSERT_TSTAMP); |
2308 |
flags |= WPI_TX_INSERT_TSTAMP; |
1925 |
if (subtype == IEEE80211_FC0_SUBTYPE_ASSOC_REQ || |
2309 |
if (subtype == IEEE80211_FC0_SUBTYPE_ASSOC_REQ || |
1926 |
subtype == IEEE80211_FC0_SUBTYPE_REASSOC_REQ) |
2310 |
subtype == IEEE80211_FC0_SUBTYPE_REASSOC_REQ) |
1927 |
tx->timeout = htole16(3); |
2311 |
tx.timeout = htole16(3); |
1928 |
else |
2312 |
else |
1929 |
tx->timeout = htole16(2); |
2313 |
tx.timeout = htole16(2); |
1930 |
rate = tp->mgmtrate; |
2314 |
} else |
1931 |
} else if (ismcast) { |
2315 |
tx.timeout = htole16(0); |
1932 |
rate = tp->mcastrate; |
|
|
1933 |
} else if (tp->ucastrate != IEEE80211_FIXED_RATE_NONE) { |
1934 |
rate = tp->ucastrate; |
1935 |
} else { |
1936 |
(void) ieee80211_ratectl_rate(ni, NULL, 0); |
1937 |
rate = ni->ni_txrate; |
1938 |
} |
1939 |
tx->rate = wpi_plcp_signal(rate); |
1940 |
|
2316 |
|
1941 |
/* be very persistant at sending frames out */ |
2317 |
if (ismcast || type != IEEE80211_FC0_TYPE_DATA) |
|
|
2318 |
tx.id = WPI_ID_BROADCAST; |
2319 |
else |
2320 |
tx.id = wn->id; |
2321 |
|
2322 |
tx.len = htole16(totlen); |
2323 |
tx.flags = htole32(flags); |
2324 |
tx.plcp = rate2plcp(rate); |
2325 |
tx.tid = tid; |
2326 |
tx.lifetime = htole32(WPI_LIFETIME_INFINITE); |
2327 |
tx.ofdm_mask = 0xff; |
2328 |
tx.cck_mask = 0x0f; |
2329 |
tx.rts_ntries = 7; |
2330 |
tx.data_ntries = 15; |
2331 |
|
1942 |
#if 0 |
2332 |
#if 0 |
1943 |
tx->data_ntries = tp->maxretry; |
2333 |
memset(tx.key, 0, IEEE80211_KEYBUF_SIZE); |
1944 |
#else |
2334 |
if (k != NULL && k->wk_cipher->ic_cipher == IEEE80211_CIPHER_AES_CCM) { |
1945 |
tx->data_ntries = 15; /* XXX way too high */ |
2335 |
tx.security = WPI_CIPHER_CCMP; |
|
|
2336 |
memcpy(tx.key, k->wk_key, k->wk_keylen); |
2337 |
} else |
1946 |
#endif |
2338 |
#endif |
|
|
2339 |
tx.security = 0; |
1947 |
|
2340 |
|
|
|
2341 |
tx_data.data = &tx; |
2342 |
tx_data.ni = ni; |
2343 |
tx_data.m = m; |
2344 |
tx_data.size = sizeof(tx); |
2345 |
tx_data.code = WPI_CMD_TX_DATA; |
2346 |
tx_data.ac = ac; |
2347 |
|
2348 |
return wpi_cmd2(sc, &tx_data); |
2349 |
} |
2350 |
|
2351 |
static int |
2352 |
wpi_tx_data_raw(struct wpi_softc *sc, struct mbuf *m, struct ieee80211_node *ni, |
2353 |
const struct ieee80211_bpf_params *params) |
2354 |
{ |
2355 |
struct ieee80211vap *vap = ni->ni_vap; |
2356 |
struct ieee80211_frame *wh; |
2357 |
struct ieee80211_key *k = NULL; |
2358 |
struct wpi_cmd_data tx; |
2359 |
struct wpi_buf tx_data; |
2360 |
uint32_t flags; |
2361 |
uint8_t type; |
2362 |
int ac, rate, totlen; |
2363 |
|
2364 |
wh = mtod(m, struct ieee80211_frame *); |
2365 |
type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK; |
2366 |
|
2367 |
ac = params->ibp_pri & 3; |
2368 |
|
2369 |
/* Choose a TX rate index. */ |
2370 |
rate = params->ibp_rate0; |
2371 |
|
2372 |
flags = 0; |
2373 |
if ((params->ibp_flags & IEEE80211_BPF_NOACK) == 0) |
2374 |
flags |= WPI_TX_NEED_ACK; |
2375 |
if (params->ibp_flags & IEEE80211_BPF_RTS) |
2376 |
flags |= WPI_TX_NEED_RTS; |
2377 |
if (params->ibp_flags & IEEE80211_BPF_CTS) |
2378 |
flags |= WPI_TX_NEED_CTS; |
2379 |
if (flags & (WPI_TX_NEED_RTS | WPI_TX_NEED_CTS)) |
2380 |
flags |= WPI_TX_FULL_TXOP; |
2381 |
|
2382 |
if (params->ibp_flags & IEEE80211_BPF_CRYPTO) { |
2383 |
/* Retrieve key for TX. */ |
2384 |
k = ieee80211_crypto_encap(ni, m); |
2385 |
if (k == NULL) { |
2386 |
m_freem(m); |
2387 |
return ENOBUFS; |
2388 |
} |
2389 |
/* 802.11 header may have moved. */ |
2390 |
wh = mtod(m, struct ieee80211_frame *); |
2391 |
} |
2392 |
totlen = m->m_pkthdr.len; |
2393 |
|
1948 |
if (ieee80211_radiotap_active_vap(vap)) { |
2394 |
if (ieee80211_radiotap_active_vap(vap)) { |
1949 |
struct wpi_tx_radiotap_header *tap = &sc->sc_txtap; |
2395 |
struct wpi_tx_radiotap_header *tap = &sc->sc_txtap; |
|
|
2396 |
|
1950 |
tap->wt_flags = 0; |
2397 |
tap->wt_flags = 0; |
1951 |
tap->wt_rate = rate; |
2398 |
tap->wt_rate = rate; |
1952 |
tap->wt_hwqueue = ac; |
|
|
1953 |
if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) |
1954 |
tap->wt_flags |= IEEE80211_RADIOTAP_F_WEP; |
1955 |
|
2399 |
|
1956 |
ieee80211_radiotap_tx(vap, m0); |
2400 |
ieee80211_radiotap_tx(vap, m); |
1957 |
} |
2401 |
} |
1958 |
|
2402 |
|
1959 |
/* save and trim IEEE802.11 header */ |
2403 |
if (type == IEEE80211_FC0_TYPE_MGT) { |
1960 |
m_copydata(m0, 0, hdrlen, (caddr_t)&tx->wh); |
2404 |
uint8_t subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK; |
1961 |
m_adj(m0, hdrlen); |
|
|
1962 |
|
2405 |
|
1963 |
error = bus_dmamap_load_mbuf_sg(ring->data_dmat, data->map, m0, segs, |
2406 |
/* Tell HW to set timestamp in probe responses. */ |
1964 |
&nsegs, BUS_DMA_NOWAIT); |
2407 |
if (subtype == IEEE80211_FC0_SUBTYPE_PROBE_RESP) |
1965 |
if (error != 0 && error != EFBIG) { |
2408 |
flags |= WPI_TX_INSERT_TSTAMP; |
1966 |
device_printf(sc->sc_dev, "could not map mbuf (error %d)\n", |
|
|
1967 |
error); |
1968 |
m_freem(m0); |
1969 |
return error; |
1970 |
} |
1971 |
if (error != 0) { |
1972 |
/* XXX use m_collapse */ |
1973 |
mnew = m_defrag(m0, M_NOWAIT); |
1974 |
if (mnew == NULL) { |
1975 |
device_printf(sc->sc_dev, |
1976 |
"could not defragment mbuf\n"); |
1977 |
m_freem(m0); |
1978 |
return ENOBUFS; |
1979 |
} |
1980 |
m0 = mnew; |
1981 |
|
2409 |
|
1982 |
error = bus_dmamap_load_mbuf_sg(ring->data_dmat, data->map, |
2410 |
if (subtype == IEEE80211_FC0_SUBTYPE_ASSOC_REQ || |
1983 |
m0, segs, &nsegs, BUS_DMA_NOWAIT); |
2411 |
subtype == IEEE80211_FC0_SUBTYPE_REASSOC_REQ) |
1984 |
if (error != 0) { |
2412 |
tx.timeout = htole16(3); |
1985 |
device_printf(sc->sc_dev, |
2413 |
else |
1986 |
"could not map mbuf (error %d)\n", error); |
2414 |
tx.timeout = htole16(2); |
1987 |
m_freem(m0); |
2415 |
} else |
1988 |
return error; |
2416 |
tx.timeout = htole16(0); |
1989 |
} |
|
|
1990 |
} |
1991 |
|
2417 |
|
1992 |
data->m = m0; |
2418 |
tx.len = htole16(totlen); |
1993 |
data->ni = ni; |
2419 |
tx.flags = htole32(flags); |
|
|
2420 |
tx.plcp = rate2plcp(rate); |
2421 |
tx.id = WPI_ID_BROADCAST; |
2422 |
tx.tid = 0; |
2423 |
tx.lifetime = htole32(WPI_LIFETIME_INFINITE); |
2424 |
tx.rts_ntries = params->ibp_try1; |
2425 |
tx.data_ntries = params->ibp_try0; |
1994 |
|
2426 |
|
1995 |
DPRINTFN(WPI_DEBUG_TX, ("sending data: qid=%d idx=%d len=%d nsegs=%d\n", |
2427 |
#if 0 |
1996 |
ring->qid, ring->cur, m0->m_pkthdr.len, nsegs)); |
2428 |
memset(tx.key, 0, IEEE80211_KEYBUF_SIZE); |
|
|
2429 |
if (k != NULL && k->wk_cipher->ic_cipher == IEEE80211_CIPHER_AES_CCM) { |
2430 |
tx.security = WPI_CIPHER_CCMP; |
2431 |
memcpy(tx.key, k->wk_key, k->wk_keylen); |
2432 |
} else |
2433 |
#endif |
2434 |
tx.security = 0; |
1997 |
|
2435 |
|
1998 |
/* first scatter/gather segment is used by the tx data command */ |
2436 |
tx_data.data = &tx; |
1999 |
desc->flags = htole32(WPI_PAD32(m0->m_pkthdr.len) << 28 | |
2437 |
tx_data.ni = ni; |
2000 |
(1 + nsegs) << 24); |
2438 |
tx_data.m = m; |
2001 |
desc->segs[0].addr = htole32(ring->cmd_dma.paddr + |
2439 |
tx_data.size = sizeof(tx); |
2002 |
ring->cur * sizeof (struct wpi_tx_cmd)); |
2440 |
tx_data.code = WPI_CMD_TX_DATA; |
2003 |
desc->segs[0].len = htole32(4 + sizeof (struct wpi_cmd_data)); |
2441 |
tx_data.ac = ac; |
2004 |
for (i = 1; i <= nsegs; i++) { |
2442 |
|
2005 |
desc->segs[i].addr = htole32(segs[i - 1].ds_addr); |
2443 |
return wpi_cmd2(sc, &tx_data); |
2006 |
desc->segs[i].len = htole32(segs[i - 1].ds_len); |
2444 |
} |
|
|
2445 |
|
2446 |
static int |
2447 |
wpi_raw_xmit(struct ieee80211_node *ni, struct mbuf *m, |
2448 |
const struct ieee80211_bpf_params *params) |
2449 |
{ |
2450 |
struct ieee80211com *ic = ni->ni_ic; |
2451 |
struct ifnet *ifp = ic->ic_ifp; |
2452 |
struct wpi_softc *sc = ifp->if_softc; |
2453 |
int error = 0; |
2454 |
|
2455 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__); |
2456 |
|
2457 |
if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) { |
2458 |
ieee80211_free_node(ni); |
2459 |
m_freem(m); |
2460 |
return ENETDOWN; |
2007 |
} |
2461 |
} |
2008 |
|
2462 |
|
2009 |
bus_dmamap_sync(ring->data_dmat, data->map, BUS_DMASYNC_PREWRITE); |
2463 |
WPI_LOCK(sc); |
2010 |
bus_dmamap_sync(ring->desc_dma.tag, ring->desc_dma.map, |
2464 |
if (params == NULL) { |
2011 |
BUS_DMASYNC_PREWRITE); |
2465 |
/* |
|
|
2466 |
* Legacy path; interpret frame contents to decide |
2467 |
* precisely how to send the frame. |
2468 |
*/ |
2469 |
error = wpi_tx_data(sc, m, ni); |
2470 |
} else { |
2471 |
/* |
2472 |
* Caller supplied explicit parameters to use in |
2473 |
* sending the frame. |
2474 |
*/ |
2475 |
error = wpi_tx_data_raw(sc, m, ni, params); |
2476 |
} |
2477 |
if (error != 0) { |
2478 |
/* NB: m is reclaimed on tx failure */ |
2479 |
ieee80211_free_node(ni); |
2480 |
if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); |
2481 |
} else |
2482 |
sc->sc_tx_timer = 5; |
2012 |
|
2483 |
|
2013 |
ring->queued++; |
2484 |
WPI_UNLOCK(sc); |
2014 |
|
2485 |
|
2015 |
/* kick ring */ |
2486 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__); |
2016 |
ring->cur = (ring->cur + 1) % WPI_TX_RING_COUNT; |
|
|
2017 |
WPI_WRITE(sc, WPI_TX_WIDX, ring->qid << 8 | ring->cur); |
2018 |
|
2487 |
|
2019 |
return 0; |
2488 |
return error; |
2020 |
} |
2489 |
} |
2021 |
|
2490 |
|
2022 |
/** |
2491 |
/** |
Lines 2038-2109
Link Here
|
2038 |
struct wpi_softc *sc = ifp->if_softc; |
2507 |
struct wpi_softc *sc = ifp->if_softc; |
2039 |
struct ieee80211_node *ni; |
2508 |
struct ieee80211_node *ni; |
2040 |
struct mbuf *m; |
2509 |
struct mbuf *m; |
2041 |
int ac; |
|
|
2042 |
|
2510 |
|
2043 |
WPI_LOCK_ASSERT(sc); |
2511 |
WPI_LOCK_ASSERT(sc); |
2044 |
|
2512 |
|
2045 |
if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) |
2513 |
DPRINTF(sc, WPI_DEBUG_XMIT, "%s: called\n", __func__); |
|
|
2514 |
|
2515 |
if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0 || |
2516 |
(ifp->if_drv_flags & IFF_DRV_OACTIVE)) |
2046 |
return; |
2517 |
return; |
2047 |
|
2518 |
|
2048 |
for (;;) { |
2519 |
for (;;) { |
|
|
2520 |
if (sc->qfullmsk != 0) { |
2521 |
ifp->if_drv_flags |= IFF_DRV_OACTIVE; |
2522 |
break; |
2523 |
} |
2049 |
IFQ_DRV_DEQUEUE(&ifp->if_snd, m); |
2524 |
IFQ_DRV_DEQUEUE(&ifp->if_snd, m); |
2050 |
if (m == NULL) |
2525 |
if (m == NULL) |
2051 |
break; |
2526 |
break; |
2052 |
ac = M_WME_GETAC(m); |
2527 |
ni = (struct ieee80211_node *)m->m_pkthdr.rcvif; |
2053 |
if (sc->txq[ac].queued > sc->txq[ac].count - 8) { |
2528 |
if (wpi_tx_data(sc, m, ni) != 0) { |
2054 |
/* there is no place left in this ring */ |
|
|
2055 |
IFQ_DRV_PREPEND(&ifp->if_snd, m); |
2056 |
ifp->if_drv_flags |= IFF_DRV_OACTIVE; |
2057 |
break; |
2058 |
} |
2059 |
ni = (struct ieee80211_node *) m->m_pkthdr.rcvif; |
2060 |
if (wpi_tx_data(sc, m, ni, ac) != 0) { |
2061 |
ieee80211_free_node(ni); |
2529 |
ieee80211_free_node(ni); |
2062 |
if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); |
2530 |
if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); |
2063 |
break; |
2531 |
continue; |
2064 |
} |
2532 |
} |
2065 |
sc->sc_tx_timer = 5; |
2533 |
sc->sc_tx_timer = 5; |
2066 |
} |
2534 |
} |
|
|
2535 |
|
2536 |
DPRINTF(sc, WPI_DEBUG_XMIT, "%s: done\n", __func__); |
2067 |
} |
2537 |
} |
2068 |
|
2538 |
|
2069 |
static int |
2539 |
static void |
2070 |
wpi_raw_xmit(struct ieee80211_node *ni, struct mbuf *m, |
2540 |
wpi_watchdog_rfkill(void *arg) |
2071 |
const struct ieee80211_bpf_params *params) |
|
|
2072 |
{ |
2541 |
{ |
2073 |
struct ieee80211com *ic = ni->ni_ic; |
2542 |
struct wpi_softc *sc = arg; |
2074 |
struct ifnet *ifp = ic->ic_ifp; |
2543 |
struct ifnet *ifp = sc->sc_ifp; |
2075 |
struct wpi_softc *sc = ifp->if_softc; |
2544 |
struct ieee80211com *ic = ifp->if_l2com; |
2076 |
|
2545 |
|
2077 |
/* prevent management frames from being sent if we're not ready */ |
2546 |
DPRINTF(sc, WPI_DEBUG_WATCHDOG, "RFkill Watchdog: tick\n"); |
2078 |
if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) { |
2547 |
|
2079 |
m_freem(m); |
2548 |
/* No need to lock firmware memory. */ |
2080 |
ieee80211_free_node(ni); |
2549 |
if ((wpi_prph_read(sc, WPI_APMG_RFKILL) & 0x1) == 0) { |
2081 |
return ENETDOWN; |
2550 |
/* Radio kill switch is still off. */ |
|
|
2551 |
callout_reset(&sc->watchdog_rfkill, hz, wpi_watchdog_rfkill, |
2552 |
sc); |
2553 |
} else |
2554 |
ieee80211_runtask(ic, &sc->sc_radioon_task); |
2555 |
} |
2556 |
|
2557 |
/** |
2558 |
* Called every second, wpi_watchdog used by the watch dog timer |
2559 |
* to check that the card is still alive |
2560 |
*/ |
2561 |
static void |
2562 |
wpi_watchdog(void *arg) |
2563 |
{ |
2564 |
struct wpi_softc *sc = arg; |
2565 |
struct ifnet *ifp = sc->sc_ifp; |
2566 |
struct ieee80211com *ic = ifp->if_l2com; |
2567 |
|
2568 |
DPRINTF(sc, WPI_DEBUG_WATCHDOG, "Watchdog: tick\n"); |
2569 |
|
2570 |
if (sc->sc_tx_timer > 0) { |
2571 |
if (--sc->sc_tx_timer == 0) { |
2572 |
if_printf(ifp, "device timeout\n"); |
2573 |
if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); |
2574 |
ieee80211_runtask(ic, &sc->sc_reinittask); |
2575 |
} |
2082 |
} |
2576 |
} |
2083 |
WPI_LOCK(sc); |
|
|
2084 |
|
2577 |
|
2085 |
/* management frames go into ring 0 */ |
2578 |
if (sc->sc_scan_timer > 0) { |
2086 |
if (sc->txq[0].queued > sc->txq[0].count - 8) { |
2579 |
struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); |
2087 |
ifp->if_drv_flags |= IFF_DRV_OACTIVE; |
2580 |
if (--sc->sc_scan_timer == 0 && vap != NULL) { |
2088 |
m_freem(m); |
2581 |
if_printf(ifp, "scan timeout\n"); |
2089 |
WPI_UNLOCK(sc); |
2582 |
ieee80211_cancel_scan(vap); |
2090 |
ieee80211_free_node(ni); |
2583 |
ieee80211_runtask(ic, &sc->sc_reinittask); |
2091 |
return ENOBUFS; /* XXX */ |
2584 |
} |
2092 |
} |
2585 |
} |
2093 |
|
2586 |
|
2094 |
if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1); |
2587 |
if (ifp->if_drv_flags & IFF_DRV_RUNNING) |
2095 |
if (wpi_tx_data(sc, m, ni, 0) != 0) |
2588 |
callout_reset(&sc->watchdog_to, hz, wpi_watchdog, sc); |
2096 |
goto bad; |
|
|
2097 |
sc->sc_tx_timer = 5; |
2098 |
callout_reset(&sc->watchdog_to, hz, wpi_watchdog, sc); |
2099 |
|
2100 |
WPI_UNLOCK(sc); |
2101 |
return 0; |
2102 |
bad: |
2103 |
if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); |
2104 |
WPI_UNLOCK(sc); |
2105 |
ieee80211_free_node(ni); |
2106 |
return EIO; /* XXX */ |
2107 |
} |
2589 |
} |
2108 |
|
2590 |
|
2109 |
static int |
2591 |
static int |
Lines 2111-2140
Link Here
|
2111 |
{ |
2593 |
{ |
2112 |
struct wpi_softc *sc = ifp->if_softc; |
2594 |
struct wpi_softc *sc = ifp->if_softc; |
2113 |
struct ieee80211com *ic = ifp->if_l2com; |
2595 |
struct ieee80211com *ic = ifp->if_l2com; |
|
|
2596 |
struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); |
2114 |
struct ifreq *ifr = (struct ifreq *) data; |
2597 |
struct ifreq *ifr = (struct ifreq *) data; |
2115 |
int error = 0, startall = 0; |
2598 |
int error = 0, startall = 0, stop = 0; |
2116 |
|
2599 |
|
2117 |
switch (cmd) { |
2600 |
switch (cmd) { |
|
|
2601 |
case SIOCGIFADDR: |
2602 |
error = ether_ioctl(ifp, cmd, data); |
2603 |
break; |
2118 |
case SIOCSIFFLAGS: |
2604 |
case SIOCSIFFLAGS: |
2119 |
WPI_LOCK(sc); |
2605 |
WPI_LOCK(sc); |
2120 |
if ((ifp->if_flags & IFF_UP)) { |
2606 |
if (ifp->if_flags & IFF_UP) { |
2121 |
if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) { |
2607 |
if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) { |
2122 |
wpi_init_locked(sc, 0); |
2608 |
wpi_init_locked(sc); |
2123 |
startall = 1; |
2609 |
if (WPI_READ(sc, WPI_GP_CNTRL) & |
|
|
2610 |
WPI_GP_CNTRL_RFKILL) |
2611 |
startall = 1; |
2612 |
else |
2613 |
stop = 1; |
2124 |
} |
2614 |
} |
2125 |
} else if ((ifp->if_drv_flags & IFF_DRV_RUNNING) || |
2615 |
} else if (ifp->if_drv_flags & IFF_DRV_RUNNING) |
2126 |
(sc->flags & WPI_FLAG_HW_RADIO_OFF)) |
|
|
2127 |
wpi_stop_locked(sc); |
2616 |
wpi_stop_locked(sc); |
2128 |
WPI_UNLOCK(sc); |
2617 |
WPI_UNLOCK(sc); |
2129 |
if (startall) |
2618 |
if (startall) |
2130 |
ieee80211_start_all(ic); |
2619 |
ieee80211_start_all(ic); |
|
|
2620 |
else if (vap != NULL && stop) |
2621 |
ieee80211_stop(vap); |
2131 |
break; |
2622 |
break; |
2132 |
case SIOCGIFMEDIA: |
2623 |
case SIOCGIFMEDIA: |
2133 |
error = ifmedia_ioctl(ifp, ifr, &ic->ic_media, cmd); |
2624 |
error = ifmedia_ioctl(ifp, ifr, &ic->ic_media, cmd); |
2134 |
break; |
2625 |
break; |
2135 |
case SIOCGIFADDR: |
|
|
2136 |
error = ether_ioctl(ifp, cmd, data); |
2137 |
break; |
2138 |
default: |
2626 |
default: |
2139 |
error = EINVAL; |
2627 |
error = EINVAL; |
2140 |
break; |
2628 |
break; |
Lines 2143-2193
Link Here
|
2143 |
} |
2631 |
} |
2144 |
|
2632 |
|
2145 |
/* |
2633 |
/* |
2146 |
* Extract various information from EEPROM. |
|
|
2147 |
*/ |
2148 |
static void |
2149 |
wpi_read_eeprom(struct wpi_softc *sc, uint8_t macaddr[IEEE80211_ADDR_LEN]) |
2150 |
{ |
2151 |
int i; |
2152 |
|
2153 |
/* read the hardware capabilities, revision and SKU type */ |
2154 |
wpi_read_prom_data(sc, WPI_EEPROM_CAPABILITIES, &sc->cap,1); |
2155 |
wpi_read_prom_data(sc, WPI_EEPROM_REVISION, &sc->rev,2); |
2156 |
wpi_read_prom_data(sc, WPI_EEPROM_TYPE, &sc->type, 1); |
2157 |
|
2158 |
/* read the regulatory domain */ |
2159 |
wpi_read_prom_data(sc, WPI_EEPROM_DOMAIN, sc->domain, 4); |
2160 |
|
2161 |
/* read in the hw MAC address */ |
2162 |
wpi_read_prom_data(sc, WPI_EEPROM_MAC, macaddr, 6); |
2163 |
|
2164 |
/* read the list of authorized channels */ |
2165 |
for (i = 0; i < WPI_CHAN_BANDS_COUNT; i++) |
2166 |
wpi_read_eeprom_channels(sc,i); |
2167 |
|
2168 |
/* read the power level calibration info for each group */ |
2169 |
for (i = 0; i < WPI_POWER_GROUPS_COUNT; i++) |
2170 |
wpi_read_eeprom_group(sc,i); |
2171 |
} |
2172 |
|
2173 |
/* |
2174 |
* Send a command to the firmware. |
2634 |
* Send a command to the firmware. |
2175 |
*/ |
2635 |
*/ |
2176 |
static int |
2636 |
static int |
2177 |
wpi_cmd(struct wpi_softc *sc, int code, const void *buf, int size, int async) |
2637 |
wpi_cmd(struct wpi_softc *sc, int code, const void *buf, size_t size, |
|
|
2638 |
int async) |
2178 |
{ |
2639 |
{ |
2179 |
struct wpi_tx_ring *ring = &sc->cmdq; |
2640 |
struct wpi_tx_ring *ring = &sc->txq[4]; |
2180 |
struct wpi_tx_desc *desc; |
2641 |
struct wpi_tx_desc *desc; |
|
|
2642 |
struct wpi_tx_data *data; |
2181 |
struct wpi_tx_cmd *cmd; |
2643 |
struct wpi_tx_cmd *cmd; |
|
|
2644 |
struct mbuf *m; |
2645 |
bus_addr_t paddr; |
2646 |
int totlen, error; |
2182 |
|
2647 |
|
2183 |
#ifdef WPI_DEBUG |
2648 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__); |
2184 |
if (!async) { |
2649 |
|
|
|
2650 |
if (async == 0) |
2185 |
WPI_LOCK_ASSERT(sc); |
2651 |
WPI_LOCK_ASSERT(sc); |
2186 |
} |
|
|
2187 |
#endif |
2188 |
|
2652 |
|
2189 |
DPRINTFN(WPI_DEBUG_CMD,("wpi_cmd %d size %d async %d\n", code, size, |
2653 |
DPRINTF(sc, WPI_DEBUG_CMD, "wpi_cmd %s size %zu async %d\n", |
2190 |
async)); |
2654 |
wpi_cmd_str(code), size, async); |
2191 |
|
2655 |
|
2192 |
if (sc->flags & WPI_FLAG_BUSY) { |
2656 |
if (sc->flags & WPI_FLAG_BUSY) { |
2193 |
device_printf(sc->sc_dev, "%s: cmd %d not sent, busy\n", |
2657 |
device_printf(sc->sc_dev, "%s: cmd %d not sent, busy\n", |
Lines 2194-2207
Link Here
|
2194 |
__func__, code); |
2658 |
__func__, code); |
2195 |
return EAGAIN; |
2659 |
return EAGAIN; |
2196 |
} |
2660 |
} |
2197 |
sc->flags|= WPI_FLAG_BUSY; |
2661 |
sc->flags |= WPI_FLAG_BUSY; |
2198 |
|
2662 |
|
2199 |
KASSERT(size <= sizeof cmd->data, ("command %d too large: %d bytes", |
|
|
2200 |
code, size)); |
2201 |
|
2202 |
desc = &ring->desc[ring->cur]; |
2663 |
desc = &ring->desc[ring->cur]; |
2203 |
cmd = &ring->cmd[ring->cur]; |
2664 |
data = &ring->data[ring->cur]; |
|
|
2665 |
totlen = 4 + size; |
2204 |
|
2666 |
|
|
|
2667 |
if (size > sizeof cmd->data) { |
2668 |
/* Command is too large to fit in a descriptor. */ |
2669 |
if (totlen > MCLBYTES) |
2670 |
return EINVAL; |
2671 |
m = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, MJUMPAGESIZE); |
2672 |
if (m == NULL) |
2673 |
return ENOMEM; |
2674 |
cmd = mtod(m, struct wpi_tx_cmd *); |
2675 |
error = bus_dmamap_load(ring->data_dmat, data->map, cmd, |
2676 |
totlen, wpi_dma_map_addr, &paddr, BUS_DMA_NOWAIT); |
2677 |
if (error != 0) { |
2678 |
m_freem(m); |
2679 |
return error; |
2680 |
} |
2681 |
data->m = m; |
2682 |
} else { |
2683 |
cmd = &ring->cmd[ring->cur]; |
2684 |
paddr = data->cmd_paddr; |
2685 |
} |
2686 |
|
2205 |
cmd->code = code; |
2687 |
cmd->code = code; |
2206 |
cmd->flags = 0; |
2688 |
cmd->flags = 0; |
2207 |
cmd->qid = ring->qid; |
2689 |
cmd->qid = ring->qid; |
Lines 2208-2224
Link Here
|
2208 |
cmd->idx = ring->cur; |
2690 |
cmd->idx = ring->cur; |
2209 |
memcpy(cmd->data, buf, size); |
2691 |
memcpy(cmd->data, buf, size); |
2210 |
|
2692 |
|
2211 |
desc->flags = htole32(WPI_PAD32(size) << 28 | 1 << 24); |
2693 |
desc->nsegs = 1 + (WPI_PAD32(size) << 4); |
2212 |
desc->segs[0].addr = htole32(ring->cmd_dma.paddr + |
2694 |
desc->segs[0].addr = htole32(paddr); |
2213 |
ring->cur * sizeof (struct wpi_tx_cmd)); |
2695 |
desc->segs[0].len = htole32(totlen); |
2214 |
desc->segs[0].len = htole32(4 + size); |
|
|
2215 |
|
2696 |
|
2216 |
/* kick cmd ring */ |
2697 |
if (size > sizeof cmd->data) { |
2217 |
ring->cur = (ring->cur + 1) % WPI_CMD_RING_COUNT; |
2698 |
bus_dmamap_sync(ring->data_dmat, data->map, |
2218 |
WPI_WRITE(sc, WPI_TX_WIDX, ring->qid << 8 | ring->cur); |
2699 |
BUS_DMASYNC_PREWRITE); |
|
|
2700 |
} else { |
2701 |
bus_dmamap_sync(ring->data_dmat, ring->cmd_dma.map, |
2702 |
BUS_DMASYNC_PREWRITE); |
2703 |
} |
2704 |
bus_dmamap_sync(ring->desc_dma.tag, ring->desc_dma.map, |
2705 |
BUS_DMASYNC_PREWRITE); |
2219 |
|
2706 |
|
|
|
2707 |
/* Kick command ring. */ |
2708 |
ring->cur = (ring->cur + 1) % WPI_TX_RING_COUNT; |
2709 |
wpi_update_tx_ring(sc, ring); |
2710 |
|
2711 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__); |
2712 |
|
2220 |
if (async) { |
2713 |
if (async) { |
2221 |
sc->flags &= ~ WPI_FLAG_BUSY; |
2714 |
sc->flags &= ~WPI_FLAG_BUSY; |
2222 |
return 0; |
2715 |
return 0; |
2223 |
} |
2716 |
} |
2224 |
|
2717 |
|
Lines 2225-2263
Link Here
|
2225 |
return msleep(cmd, &sc->sc_mtx, PCATCH, "wpicmd", hz); |
2718 |
return msleep(cmd, &sc->sc_mtx, PCATCH, "wpicmd", hz); |
2226 |
} |
2719 |
} |
2227 |
|
2720 |
|
2228 |
static int |
|
|
2229 |
wpi_wme_update(struct ieee80211com *ic) |
2230 |
{ |
2231 |
#define WPI_EXP2(v) htole16((1 << (v)) - 1) |
2232 |
#define WPI_USEC(v) htole16(IEEE80211_TXOP_TO_US(v)) |
2233 |
struct wpi_softc *sc = ic->ic_ifp->if_softc; |
2234 |
const struct wmeParams *wmep; |
2235 |
struct wpi_wme_setup wme; |
2236 |
int ac; |
2237 |
|
2238 |
/* don't override default WME values if WME is not actually enabled */ |
2239 |
if (!(ic->ic_flags & IEEE80211_F_WME)) |
2240 |
return 0; |
2241 |
|
2242 |
wme.flags = 0; |
2243 |
for (ac = 0; ac < WME_NUM_AC; ac++) { |
2244 |
wmep = &ic->ic_wme.wme_chanParams.cap_wmeParams[ac]; |
2245 |
wme.ac[ac].aifsn = wmep->wmep_aifsn; |
2246 |
wme.ac[ac].cwmin = WPI_EXP2(wmep->wmep_logcwmin); |
2247 |
wme.ac[ac].cwmax = WPI_EXP2(wmep->wmep_logcwmax); |
2248 |
wme.ac[ac].txop = WPI_USEC(wmep->wmep_txopLimit); |
2249 |
|
2250 |
DPRINTF(("setting WME for queue %d aifsn=%d cwmin=%d cwmax=%d " |
2251 |
"txop=%d\n", ac, wme.ac[ac].aifsn, wme.ac[ac].cwmin, |
2252 |
wme.ac[ac].cwmax, wme.ac[ac].txop)); |
2253 |
} |
2254 |
return wpi_cmd(sc, WPI_CMD_SET_WME, &wme, sizeof wme, 1); |
2255 |
#undef WPI_USEC |
2256 |
#undef WPI_EXP2 |
2257 |
} |
2258 |
|
2259 |
/* |
2721 |
/* |
2260 |
* Configure h/w multi-rate retries. |
2722 |
* Configure HW multi-rate retries. |
2261 |
*/ |
2723 |
*/ |
2262 |
static int |
2724 |
static int |
2263 |
wpi_mrr_setup(struct wpi_softc *sc) |
2725 |
wpi_mrr_setup(struct wpi_softc *sc) |
Lines 2267-2300
Link Here
|
2267 |
struct wpi_mrr_setup mrr; |
2729 |
struct wpi_mrr_setup mrr; |
2268 |
int i, error; |
2730 |
int i, error; |
2269 |
|
2731 |
|
2270 |
memset(&mrr, 0, sizeof (struct wpi_mrr_setup)); |
2732 |
/* CCK rates (not used with 802.11a). */ |
2271 |
|
2733 |
for (i = WPI_RIDX_CCK1; i <= WPI_RIDX_CCK11; i++) { |
2272 |
/* CCK rates (not used with 802.11a) */ |
|
|
2273 |
for (i = WPI_CCK1; i <= WPI_CCK11; i++) { |
2274 |
mrr.rates[i].flags = 0; |
2734 |
mrr.rates[i].flags = 0; |
2275 |
mrr.rates[i].signal = wpi_ridx_to_plcp[i]; |
2735 |
mrr.rates[i].plcp = wpi_ridx_to_plcp[i]; |
2276 |
/* fallback to the immediate lower CCK rate (if any) */ |
2736 |
/* Fallback to the immediate lower CCK rate (if any.) */ |
2277 |
mrr.rates[i].next = (i == WPI_CCK1) ? WPI_CCK1 : i - 1; |
2737 |
mrr.rates[i].next = |
2278 |
/* try one time at this rate before falling back to "next" */ |
2738 |
(i == WPI_RIDX_CCK1) ? WPI_RIDX_CCK1 : i - 1; |
|
|
2739 |
/* Try one time at this rate before falling back to "next". */ |
2279 |
mrr.rates[i].ntries = 1; |
2740 |
mrr.rates[i].ntries = 1; |
2280 |
} |
2741 |
} |
2281 |
|
2742 |
/* OFDM rates (not used with 802.11b). */ |
2282 |
/* OFDM rates (not used with 802.11b) */ |
2743 |
for (i = WPI_RIDX_OFDM6; i <= WPI_RIDX_OFDM54; i++) { |
2283 |
for (i = WPI_OFDM6; i <= WPI_OFDM54; i++) { |
|
|
2284 |
mrr.rates[i].flags = 0; |
2744 |
mrr.rates[i].flags = 0; |
2285 |
mrr.rates[i].signal = wpi_ridx_to_plcp[i]; |
2745 |
mrr.rates[i].plcp = wpi_ridx_to_plcp[i]; |
2286 |
/* fallback to the immediate lower OFDM rate (if any) */ |
2746 |
/* Fallback to the immediate lower rate (if any.) */ |
2287 |
/* we allow fallback from OFDM/6 to CCK/2 in 11b/g mode */ |
2747 |
/* We allow fallback from OFDM/6 to CCK/2 in 11b/g mode. */ |
2288 |
mrr.rates[i].next = (i == WPI_OFDM6) ? |
2748 |
mrr.rates[i].next = (i == WPI_RIDX_OFDM6) ? |
2289 |
((ic->ic_curmode == IEEE80211_MODE_11A) ? |
2749 |
((ic->ic_curmode == IEEE80211_MODE_11A) ? |
2290 |
WPI_OFDM6 : WPI_CCK2) : |
2750 |
WPI_RIDX_OFDM6 : WPI_RIDX_CCK2) : |
2291 |
i - 1; |
2751 |
i - 1; |
2292 |
/* try one time at this rate before falling back to "next" */ |
2752 |
/* Try one time at this rate before falling back to "next". */ |
2293 |
mrr.rates[i].ntries = 1; |
2753 |
mrr.rates[i].ntries = 1; |
2294 |
} |
2754 |
} |
2295 |
|
2755 |
/* Setup MRR for control frames. */ |
2296 |
/* setup MRR for control frames */ |
2756 |
mrr.which = htole32(WPI_MRR_CTL); |
2297 |
mrr.which = WPI_MRR_CTL; |
|
|
2298 |
error = wpi_cmd(sc, WPI_CMD_MRR_SETUP, &mrr, sizeof mrr, 0); |
2757 |
error = wpi_cmd(sc, WPI_CMD_MRR_SETUP, &mrr, sizeof mrr, 0); |
2299 |
if (error != 0) { |
2758 |
if (error != 0) { |
2300 |
device_printf(sc->sc_dev, |
2759 |
device_printf(sc->sc_dev, |
Lines 2301-2309
Link Here
|
2301 |
"could not setup MRR for control frames\n"); |
2760 |
"could not setup MRR for control frames\n"); |
2302 |
return error; |
2761 |
return error; |
2303 |
} |
2762 |
} |
2304 |
|
2763 |
/* Setup MRR for data frames. */ |
2305 |
/* setup MRR for data frames */ |
2764 |
mrr.which = htole32(WPI_MRR_DATA); |
2306 |
mrr.which = WPI_MRR_DATA; |
|
|
2307 |
error = wpi_cmd(sc, WPI_CMD_MRR_SETUP, &mrr, sizeof mrr, 0); |
2765 |
error = wpi_cmd(sc, WPI_CMD_MRR_SETUP, &mrr, sizeof mrr, 0); |
2308 |
if (error != 0) { |
2766 |
if (error != 0) { |
2309 |
device_printf(sc->sc_dev, |
2767 |
device_printf(sc->sc_dev, |
Lines 2310-2626
Link Here
|
2310 |
"could not setup MRR for data frames\n"); |
2768 |
"could not setup MRR for data frames\n"); |
2311 |
return error; |
2769 |
return error; |
2312 |
} |
2770 |
} |
2313 |
|
|
|
2314 |
return 0; |
2771 |
return 0; |
2315 |
} |
2772 |
} |
2316 |
|
2773 |
|
|
|
2774 |
static int |
2775 |
wpi_add_node(struct wpi_softc *sc, struct ieee80211_node *ni) |
2776 |
{ |
2777 |
struct ieee80211com *ic = ni->ni_ic; |
2778 |
struct wpi_node *wn = (void *)ni; |
2779 |
struct wpi_node_info node; |
2780 |
|
2781 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__); |
2782 |
|
2783 |
memset(&node, 0, sizeof node); |
2784 |
IEEE80211_ADDR_COPY(node.macaddr, ni->ni_bssid); |
2785 |
node.id = wn->id; |
2786 |
node.plcp = (ic->ic_curmode == IEEE80211_MODE_11A) ? |
2787 |
wpi_ridx_to_plcp[WPI_RIDX_OFDM6] : wpi_ridx_to_plcp[WPI_RIDX_CCK1]; |
2788 |
node.action = htole32(WPI_ACTION_SET_RATE); |
2789 |
node.antenna = WPI_ANTENNA_BOTH; |
2790 |
|
2791 |
return wpi_cmd(sc, WPI_CMD_ADD_NODE, &node, sizeof node, 1); |
2792 |
} |
2793 |
|
2794 |
/* |
2795 |
* Broadcast node is used to send group-addressed and management frames. |
2796 |
*/ |
2797 |
static int |
2798 |
wpi_add_broadcast_node(struct wpi_softc *sc, int async) |
2799 |
{ |
2800 |
struct ifnet *ifp = sc->sc_ifp; |
2801 |
struct ieee80211com *ic = ifp->if_l2com; |
2802 |
struct wpi_node_info node; |
2803 |
|
2804 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__); |
2805 |
|
2806 |
memset(&node, 0, sizeof node); |
2807 |
IEEE80211_ADDR_COPY(node.macaddr, ifp->if_broadcastaddr); |
2808 |
node.id = WPI_ID_BROADCAST; |
2809 |
node.plcp = (ic->ic_curmode == IEEE80211_MODE_11A) ? |
2810 |
wpi_ridx_to_plcp[WPI_RIDX_OFDM6] : wpi_ridx_to_plcp[WPI_RIDX_CCK1]; |
2811 |
node.action = htole32(WPI_ACTION_SET_RATE); |
2812 |
node.antenna = WPI_ANTENNA_BOTH; |
2813 |
|
2814 |
return wpi_cmd(sc, WPI_CMD_ADD_NODE, &node, sizeof node, async); |
2815 |
} |
2816 |
|
2817 |
static int |
2818 |
wpi_updateedca(struct ieee80211com *ic) |
2819 |
{ |
2820 |
#define WPI_EXP2(x) ((1 << (x)) - 1) /* CWmin = 2^ECWmin - 1 */ |
2821 |
struct wpi_softc *sc = ic->ic_ifp->if_softc; |
2822 |
struct wpi_edca_params cmd; |
2823 |
int aci, error; |
2824 |
|
2825 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__); |
2826 |
|
2827 |
memset(&cmd, 0, sizeof cmd); |
2828 |
cmd.flags = htole32(WPI_EDCA_UPDATE); |
2829 |
for (aci = 0; aci < WME_NUM_AC; aci++) { |
2830 |
const struct wmeParams *ac = |
2831 |
&ic->ic_wme.wme_chanParams.cap_wmeParams[aci]; |
2832 |
cmd.ac[aci].aifsn = ac->wmep_aifsn; |
2833 |
cmd.ac[aci].cwmin = htole16(WPI_EXP2(ac->wmep_logcwmin)); |
2834 |
cmd.ac[aci].cwmax = htole16(WPI_EXP2(ac->wmep_logcwmax)); |
2835 |
cmd.ac[aci].txoplimit = |
2836 |
htole16(IEEE80211_TXOP_TO_US(ac->wmep_txopLimit)); |
2837 |
|
2838 |
DPRINTF(sc, WPI_DEBUG_EDCA, |
2839 |
"setting WME for queue %d aifsn=%d cwmin=%d cwmax=%d " |
2840 |
"txoplimit=%d\n", aci, cmd.ac[aci].aifsn, |
2841 |
cmd.ac[aci].cwmin, cmd.ac[aci].cwmax, |
2842 |
cmd.ac[aci].txoplimit); |
2843 |
} |
2844 |
IEEE80211_UNLOCK(ic); |
2845 |
WPI_LOCK(sc); |
2846 |
error = wpi_cmd(sc, WPI_CMD_EDCA_PARAMS, &cmd, sizeof cmd, 1); |
2847 |
WPI_UNLOCK(sc); |
2848 |
IEEE80211_LOCK(ic); |
2849 |
|
2850 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__); |
2851 |
|
2852 |
return error; |
2853 |
#undef WPI_EXP2 |
2854 |
} |
2855 |
|
2317 |
static void |
2856 |
static void |
|
|
2857 |
wpi_update_promisc(struct ifnet *ifp) |
2858 |
{ |
2859 |
struct wpi_softc *sc = ifp->if_softc; |
2860 |
|
2861 |
WPI_LOCK(sc); |
2862 |
if (ifp->if_flags & IFF_PROMISC) |
2863 |
sc->rxon.filter |= htole32(WPI_FILTER_PROMISC); |
2864 |
else |
2865 |
sc->rxon.filter &= ~htole32(WPI_FILTER_PROMISC); |
2866 |
|
2867 |
(void)wpi_send_rxon(sc, 1); |
2868 |
WPI_UNLOCK(sc); |
2869 |
} |
2870 |
|
2871 |
static void |
2872 |
wpi_update_mcast(struct ifnet *ifp) |
2873 |
{ |
2874 |
/* Ignore */ |
2875 |
} |
2876 |
|
2877 |
static void |
2318 |
wpi_set_led(struct wpi_softc *sc, uint8_t which, uint8_t off, uint8_t on) |
2878 |
wpi_set_led(struct wpi_softc *sc, uint8_t which, uint8_t off, uint8_t on) |
2319 |
{ |
2879 |
{ |
2320 |
struct wpi_cmd_led led; |
2880 |
struct wpi_cmd_led led; |
2321 |
|
2881 |
|
|
|
2882 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__); |
2883 |
|
2322 |
led.which = which; |
2884 |
led.which = which; |
2323 |
led.unit = htole32(100000); /* on/off in unit of 100ms */ |
2885 |
led.unit = htole32(100000); /* on/off in unit of 100ms */ |
2324 |
led.off = off; |
2886 |
led.off = off; |
2325 |
led.on = on; |
2887 |
led.on = on; |
2326 |
|
|
|
2327 |
(void)wpi_cmd(sc, WPI_CMD_SET_LED, &led, sizeof led, 1); |
2888 |
(void)wpi_cmd(sc, WPI_CMD_SET_LED, &led, sizeof led, 1); |
2328 |
} |
2889 |
} |
2329 |
|
2890 |
|
2330 |
static void |
2891 |
static int |
2331 |
wpi_enable_tsf(struct wpi_softc *sc, struct ieee80211_node *ni) |
2892 |
wpi_set_timing(struct wpi_softc *sc, struct ieee80211_node *ni) |
2332 |
{ |
2893 |
{ |
2333 |
struct wpi_cmd_tsf tsf; |
2894 |
struct wpi_cmd_timing cmd; |
2334 |
uint64_t val, mod; |
2895 |
uint64_t val, mod; |
2335 |
|
2896 |
|
2336 |
memset(&tsf, 0, sizeof tsf); |
2897 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__); |
2337 |
memcpy(&tsf.tstamp, ni->ni_tstamp.data, 8); |
|
|
2338 |
tsf.bintval = htole16(ni->ni_intval); |
2339 |
tsf.lintval = htole16(10); |
2340 |
|
2898 |
|
2341 |
/* compute remaining time until next beacon */ |
2899 |
memset(&cmd, 0, sizeof cmd); |
2342 |
val = (uint64_t)ni->ni_intval * 1024; /* msec -> usec */ |
2900 |
memcpy(&cmd.tstamp, ni->ni_tstamp.data, sizeof (uint64_t)); |
2343 |
mod = le64toh(tsf.tstamp) % val; |
2901 |
cmd.bintval = htole16(ni->ni_intval); |
2344 |
tsf.binitval = htole32((uint32_t)(val - mod)); |
2902 |
cmd.lintval = htole16(10); |
2345 |
|
2903 |
|
2346 |
if (wpi_cmd(sc, WPI_CMD_TSF, &tsf, sizeof tsf, 1) != 0) |
2904 |
/* Compute remaining time until next beacon. */ |
2347 |
device_printf(sc->sc_dev, "could not enable TSF\n"); |
2905 |
val = (uint64_t)ni->ni_intval * IEEE80211_DUR_TU; |
|
|
2906 |
mod = le64toh(cmd.tstamp) % val; |
2907 |
cmd.binitval = htole32((uint32_t)(val - mod)); |
2908 |
|
2909 |
DPRINTF(sc, WPI_DEBUG_RESET, "timing bintval=%u tstamp=%ju, init=%u\n", |
2910 |
ni->ni_intval, le64toh(cmd.tstamp), (uint32_t)(val - mod)); |
2911 |
|
2912 |
return wpi_cmd(sc, WPI_CMD_TIMING, &cmd, sizeof cmd, 1); |
2348 |
} |
2913 |
} |
2349 |
|
2914 |
|
2350 |
#if 0 |
|
|
2351 |
/* |
2915 |
/* |
2352 |
* Build a beacon frame that the firmware will broadcast periodically in |
2916 |
* This function is called periodically (every 60 seconds) to adjust output |
2353 |
* IBSS or HostAP modes. |
2917 |
* power to temperature changes. |
2354 |
*/ |
2918 |
*/ |
|
|
2919 |
static void |
2920 |
wpi_power_calibration(struct wpi_softc *sc) |
2921 |
{ |
2922 |
int temp; |
2923 |
|
2924 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__); |
2925 |
|
2926 |
/* Update sensor data. */ |
2927 |
temp = (int)WPI_READ(sc, WPI_UCODE_GP2); |
2928 |
DPRINTF(sc, WPI_DEBUG_TEMP, "Temp in calibration is: %d\n", temp); |
2929 |
|
2930 |
/* Sanity-check read value. */ |
2931 |
if (temp < -260 || temp > 25) { |
2932 |
/* This can't be correct, ignore. */ |
2933 |
DPRINTF(sc, WPI_DEBUG_TEMP, |
2934 |
"out-of-range temperature reported: %d\n", temp); |
2935 |
return; |
2936 |
} |
2937 |
|
2938 |
DPRINTF(sc, WPI_DEBUG_TEMP, "temperature %d->%d\n", sc->temp, temp); |
2939 |
|
2940 |
/* Adjust Tx power if need be. */ |
2941 |
if (abs(temp - sc->temp) <= 6) |
2942 |
return; |
2943 |
|
2944 |
sc->temp = temp; |
2945 |
|
2946 |
if (wpi_set_txpower(sc, 1) != 0) { |
2947 |
/* just warn, too bad for the automatic calibration... */ |
2948 |
device_printf(sc->sc_dev,"could not adjust Tx power\n"); |
2949 |
} |
2950 |
} |
2951 |
|
2952 |
/* |
2953 |
* Set TX power for current channel. |
2954 |
*/ |
2355 |
static int |
2955 |
static int |
2356 |
wpi_setup_beacon(struct wpi_softc *sc, struct ieee80211_node *ni) |
2956 |
wpi_set_txpower(struct wpi_softc *sc, int async) |
2357 |
{ |
2957 |
{ |
2358 |
struct ifnet *ifp = sc->sc_ifp; |
2958 |
struct ifnet *ifp = sc->sc_ifp; |
2359 |
struct ieee80211com *ic = ifp->if_l2com; |
2959 |
struct ieee80211com *ic = ifp->if_l2com; |
2360 |
struct wpi_tx_ring *ring = &sc->cmdq; |
2960 |
struct ieee80211_channel *ch; |
2361 |
struct wpi_tx_desc *desc; |
2961 |
struct wpi_power_group *group; |
2362 |
struct wpi_tx_data *data; |
2962 |
struct wpi_cmd_txpower cmd; |
2363 |
struct wpi_tx_cmd *cmd; |
2963 |
uint8_t chan; |
2364 |
struct wpi_cmd_beacon *bcn; |
2964 |
int idx, i; |
2365 |
struct ieee80211_beacon_offsets bo; |
|
|
2366 |
struct mbuf *m0; |
2367 |
bus_addr_t physaddr; |
2368 |
int error; |
2369 |
|
2965 |
|
2370 |
desc = &ring->desc[ring->cur]; |
2966 |
/* Retrieve current channel from last RXON. */ |
2371 |
data = &ring->data[ring->cur]; |
2967 |
chan = sc->rxon.chan; |
|
|
2968 |
ch = &ic->ic_channels[chan]; |
2372 |
|
2969 |
|
2373 |
m0 = ieee80211_beacon_alloc(ic, ni, &bo); |
2970 |
/* Find the TX power group to which this channel belongs. */ |
2374 |
if (m0 == NULL) { |
2971 |
if (IEEE80211_IS_CHAN_5GHZ(ch)) { |
2375 |
device_printf(sc->sc_dev, "could not allocate beacon frame\n"); |
2972 |
for (group = &sc->groups[1]; group < &sc->groups[4]; group++) |
2376 |
return ENOMEM; |
2973 |
if (chan <= group->chan) |
|
|
2974 |
break; |
2975 |
} else |
2976 |
group = &sc->groups[0]; |
2977 |
|
2978 |
memset(&cmd, 0, sizeof cmd); |
2979 |
cmd.band = IEEE80211_IS_CHAN_5GHZ(ch) ? 0 : 1; |
2980 |
cmd.chan = htole16(chan); |
2981 |
|
2982 |
/* Set TX power for all OFDM and CCK rates. */ |
2983 |
for (i = 0; i <= WPI_RIDX_MAX ; i++) { |
2984 |
/* Retrieve TX power for this channel/rate. */ |
2985 |
idx = wpi_get_power_index(sc, group, ch, i); |
2986 |
|
2987 |
cmd.rates[i].plcp = wpi_ridx_to_plcp[i]; |
2988 |
|
2989 |
if (IEEE80211_IS_CHAN_5GHZ(ch)) { |
2990 |
cmd.rates[i].rf_gain = wpi_rf_gain_5ghz[idx]; |
2991 |
cmd.rates[i].dsp_gain = wpi_dsp_gain_5ghz[idx]; |
2992 |
} else { |
2993 |
cmd.rates[i].rf_gain = wpi_rf_gain_2ghz[idx]; |
2994 |
cmd.rates[i].dsp_gain = wpi_dsp_gain_2ghz[idx]; |
2995 |
} |
2996 |
DPRINTF(sc, WPI_DEBUG_TEMP, |
2997 |
"chan %d/ridx %d: power index %d\n", chan, i, idx); |
2377 |
} |
2998 |
} |
2378 |
|
2999 |
|
2379 |
cmd = &ring->cmd[ring->cur]; |
3000 |
return wpi_cmd(sc, WPI_CMD_TXPOWER, &cmd, sizeof cmd, async); |
2380 |
cmd->code = WPI_CMD_SET_BEACON; |
3001 |
} |
2381 |
cmd->flags = 0; |
|
|
2382 |
cmd->qid = ring->qid; |
2383 |
cmd->idx = ring->cur; |
2384 |
|
3002 |
|
2385 |
bcn = (struct wpi_cmd_beacon *)cmd->data; |
3003 |
/* |
2386 |
memset(bcn, 0, sizeof (struct wpi_cmd_beacon)); |
3004 |
* Determine Tx power index for a given channel/rate combination. |
2387 |
bcn->id = WPI_ID_BROADCAST; |
3005 |
* This takes into account the regulatory information from EEPROM and the |
2388 |
bcn->ofdm_mask = 0xff; |
3006 |
* current temperature. |
2389 |
bcn->cck_mask = 0x0f; |
3007 |
*/ |
2390 |
bcn->lifetime = htole32(WPI_LIFETIME_INFINITE); |
3008 |
static int |
2391 |
bcn->len = htole16(m0->m_pkthdr.len); |
3009 |
wpi_get_power_index(struct wpi_softc *sc, struct wpi_power_group *group, |
2392 |
bcn->rate = (ic->ic_curmode == IEEE80211_MODE_11A) ? |
3010 |
struct ieee80211_channel *c, int ridx) |
2393 |
wpi_plcp_signal(12) : wpi_plcp_signal(2); |
3011 |
{ |
2394 |
bcn->flags = htole32(WPI_TX_AUTO_SEQ | WPI_TX_INSERT_TSTAMP); |
3012 |
/* Fixed-point arithmetic division using a n-bit fractional part. */ |
|
|
3013 |
#define fdivround(a, b, n) \ |
3014 |
((((1 << n) * (a)) / (b) + (1 << n) / 2) / (1 << n)) |
2395 |
|
3015 |
|
2396 |
/* save and trim IEEE802.11 header */ |
3016 |
/* Linear interpolation. */ |
2397 |
m_copydata(m0, 0, sizeof (struct ieee80211_frame), (caddr_t)&bcn->wh); |
3017 |
#define interpolate(x, x1, y1, x2, y2, n) \ |
2398 |
m_adj(m0, sizeof (struct ieee80211_frame)); |
3018 |
((y1) + fdivround(((x) - (x1)) * ((y2) - (y1)), (x2) - (x1), n)) |
2399 |
|
3019 |
|
2400 |
/* assume beacon frame is contiguous */ |
3020 |
struct ifnet *ifp = sc->sc_ifp; |
2401 |
error = bus_dmamap_load(ring->data_dmat, data->map, mtod(m0, void *), |
3021 |
struct ieee80211com *ic = ifp->if_l2com; |
2402 |
m0->m_pkthdr.len, wpi_dma_map_addr, &physaddr, 0); |
3022 |
struct wpi_power_sample *sample; |
2403 |
if (error != 0) { |
3023 |
int pwr, idx; |
2404 |
device_printf(sc->sc_dev, "could not map beacon\n"); |
3024 |
u_int chan; |
2405 |
m_freem(m0); |
3025 |
|
2406 |
return error; |
3026 |
/* Get channel number. */ |
|
|
3027 |
chan = ieee80211_chan2ieee(ic, c); |
3028 |
|
3029 |
/* Default TX power is group maximum TX power minus 3dB. */ |
3030 |
pwr = group->maxpwr / 2; |
3031 |
|
3032 |
/* Decrease TX power for highest OFDM rates to reduce distortion. */ |
3033 |
switch (ridx) { |
3034 |
case WPI_RIDX_OFDM36: |
3035 |
pwr -= IEEE80211_IS_CHAN_2GHZ(c) ? 0 : 5; |
3036 |
break; |
3037 |
case WPI_RIDX_OFDM48: |
3038 |
pwr -= IEEE80211_IS_CHAN_2GHZ(c) ? 7 : 10; |
3039 |
break; |
3040 |
case WPI_RIDX_OFDM54: |
3041 |
pwr -= IEEE80211_IS_CHAN_2GHZ(c) ? 9 : 12; |
3042 |
break; |
2407 |
} |
3043 |
} |
2408 |
|
3044 |
|
2409 |
data->m = m0; |
3045 |
/* Never exceed the channel maximum allowed TX power. */ |
|
|
3046 |
pwr = min(pwr, sc->maxpwr[chan]); |
2410 |
|
3047 |
|
2411 |
/* first scatter/gather segment is used by the beacon command */ |
3048 |
/* Retrieve TX power index into gain tables from samples. */ |
2412 |
desc->flags = htole32(WPI_PAD32(m0->m_pkthdr.len) << 28 | 2 << 24); |
3049 |
for (sample = group->samples; sample < &group->samples[3]; sample++) |
2413 |
desc->segs[0].addr = htole32(ring->cmd_dma.paddr + |
3050 |
if (pwr > sample[1].power) |
2414 |
ring->cur * sizeof (struct wpi_tx_cmd)); |
3051 |
break; |
2415 |
desc->segs[0].len = htole32(4 + sizeof (struct wpi_cmd_beacon)); |
3052 |
/* Fixed-point linear interpolation using a 19-bit fractional part. */ |
2416 |
desc->segs[1].addr = htole32(physaddr); |
3053 |
idx = interpolate(pwr, sample[0].power, sample[0].index, |
2417 |
desc->segs[1].len = htole32(m0->m_pkthdr.len); |
3054 |
sample[1].power, sample[1].index, 19); |
2418 |
|
3055 |
|
2419 |
/* kick cmd ring */ |
3056 |
/*- |
2420 |
ring->cur = (ring->cur + 1) % WPI_CMD_RING_COUNT; |
3057 |
* Adjust power index based on current temperature: |
2421 |
WPI_WRITE(sc, WPI_TX_WIDX, ring->qid << 8 | ring->cur); |
3058 |
* - if cooler than factory-calibrated: decrease output power |
|
|
3059 |
* - if warmer than factory-calibrated: increase output power |
3060 |
*/ |
3061 |
idx -= (sc->temp - group->temp) * 11 / 100; |
2422 |
|
3062 |
|
2423 |
return 0; |
3063 |
/* Decrease TX power for CCK rates (-5dB). */ |
|
|
3064 |
if (ridx >= WPI_RIDX_CCK1) |
3065 |
idx += 10; |
3066 |
|
3067 |
/* Make sure idx stays in a valid range. */ |
3068 |
if (idx < 0) |
3069 |
return 0; |
3070 |
if (idx > WPI_MAX_PWR_INDEX) |
3071 |
return WPI_MAX_PWR_INDEX; |
3072 |
return idx; |
3073 |
|
3074 |
#undef interpolate |
3075 |
#undef fdivround |
2424 |
} |
3076 |
} |
2425 |
#endif |
|
|
2426 |
|
3077 |
|
|
|
3078 |
/* |
3079 |
* Set STA mode power saving level (between 0 and 5). |
3080 |
* Level 0 is CAM (Continuously Aware Mode), 5 is for maximum power saving. |
3081 |
*/ |
2427 |
static int |
3082 |
static int |
2428 |
wpi_auth(struct wpi_softc *sc, struct ieee80211vap *vap) |
3083 |
wpi_set_pslevel(struct wpi_softc *sc, uint8_t dtim, int level, int async) |
2429 |
{ |
3084 |
{ |
2430 |
struct ieee80211com *ic = vap->iv_ic; |
3085 |
struct wpi_pmgt_cmd cmd; |
2431 |
struct ieee80211_node *ni = vap->iv_bss; |
3086 |
const struct wpi_pmgt *pmgt; |
2432 |
struct wpi_node_info node; |
3087 |
uint32_t max, skip_dtim; |
2433 |
int error; |
3088 |
uint32_t reg; |
|
|
3089 |
int i; |
2434 |
|
3090 |
|
|
|
3091 |
DPRINTF(sc, WPI_DEBUG_PWRSAVE, |
3092 |
"%s: dtim=%d, level=%d, async=%d\n", |
3093 |
__func__, dtim, level, async); |
2435 |
|
3094 |
|
2436 |
/* update adapter's configuration */ |
3095 |
/* Select which PS parameters to use. */ |
2437 |
sc->config.associd = 0; |
3096 |
if (dtim <= 10) |
2438 |
sc->config.filter &= ~htole32(WPI_FILTER_BSS); |
3097 |
pmgt = &wpi_pmgt[0][level]; |
2439 |
IEEE80211_ADDR_COPY(sc->config.bssid, ni->ni_bssid); |
3098 |
else |
2440 |
sc->config.chan = ieee80211_chan2ieee(ic, ni->ni_chan); |
3099 |
pmgt = &wpi_pmgt[1][level]; |
2441 |
if (IEEE80211_IS_CHAN_2GHZ(ni->ni_chan)) { |
|
|
2442 |
sc->config.flags |= htole32(WPI_CONFIG_AUTO | |
2443 |
WPI_CONFIG_24GHZ); |
2444 |
} else { |
2445 |
sc->config.flags &= ~htole32(WPI_CONFIG_AUTO | |
2446 |
WPI_CONFIG_24GHZ); |
2447 |
} |
2448 |
if (IEEE80211_IS_CHAN_A(ni->ni_chan)) { |
2449 |
sc->config.cck_mask = 0; |
2450 |
sc->config.ofdm_mask = 0x15; |
2451 |
} else if (IEEE80211_IS_CHAN_B(ni->ni_chan)) { |
2452 |
sc->config.cck_mask = 0x03; |
2453 |
sc->config.ofdm_mask = 0; |
2454 |
} else { |
2455 |
/* XXX assume 802.11b/g */ |
2456 |
sc->config.cck_mask = 0x0f; |
2457 |
sc->config.ofdm_mask = 0x15; |
2458 |
} |
2459 |
|
3100 |
|
2460 |
DPRINTF(("config chan %d flags %x cck %x ofdm %x\n", sc->config.chan, |
3101 |
memset(&cmd, 0, sizeof cmd); |
2461 |
sc->config.flags, sc->config.cck_mask, sc->config.ofdm_mask)); |
3102 |
if (level != 0) /* not CAM */ |
2462 |
error = wpi_cmd(sc, WPI_CMD_CONFIGURE, &sc->config, |
3103 |
cmd.flags |= htole16(WPI_PS_ALLOW_SLEEP); |
2463 |
sizeof (struct wpi_config), 1); |
3104 |
/* Retrieve PCIe Active State Power Management (ASPM). */ |
|
|
3105 |
reg = pci_read_config(sc->sc_dev, sc->sc_cap_off + 0x10, 1); |
3106 |
if (!(reg & 0x1)) /* L0s Entry disabled. */ |
3107 |
cmd.flags |= htole16(WPI_PS_PCI_PMGT); |
3108 |
|
3109 |
cmd.rxtimeout = htole32(pmgt->rxtimeout * IEEE80211_DUR_TU); |
3110 |
cmd.txtimeout = htole32(pmgt->txtimeout * IEEE80211_DUR_TU); |
3111 |
|
3112 |
if (dtim == 0) { |
3113 |
dtim = 1; |
3114 |
skip_dtim = 0; |
3115 |
} else |
3116 |
skip_dtim = pmgt->skip_dtim; |
3117 |
|
3118 |
if (skip_dtim != 0) { |
3119 |
cmd.flags |= htole16(WPI_PS_SLEEP_OVER_DTIM); |
3120 |
max = pmgt->intval[4]; |
3121 |
if (max == (uint32_t)-1) |
3122 |
max = dtim * (skip_dtim + 1); |
3123 |
else if (max > dtim) |
3124 |
max = (max / dtim) * dtim; |
3125 |
} else |
3126 |
max = dtim; |
3127 |
|
3128 |
for (i = 0; i < 5; i++) |
3129 |
cmd.intval[i] = htole32(MIN(max, pmgt->intval[i])); |
3130 |
|
3131 |
return wpi_cmd(sc, WPI_CMD_SET_POWER_MODE, &cmd, sizeof cmd, async); |
3132 |
} |
3133 |
|
3134 |
static int |
3135 |
wpi_send_btcoex(struct wpi_softc *sc) |
3136 |
{ |
3137 |
struct wpi_bluetooth cmd; |
3138 |
|
3139 |
memset(&cmd, 0, sizeof cmd); |
3140 |
cmd.flags = WPI_BT_COEX_MODE_4WIRE; |
3141 |
cmd.lead_time = WPI_BT_LEAD_TIME_DEF; |
3142 |
cmd.max_kill = WPI_BT_MAX_KILL_DEF; |
3143 |
DPRINTF(sc, WPI_DEBUG_RESET, "%s: configuring bluetooth coexistence\n", |
3144 |
__func__); |
3145 |
return wpi_cmd(sc, WPI_CMD_BT_COEX, &cmd, sizeof(cmd), 0); |
3146 |
} |
3147 |
|
3148 |
static int |
3149 |
wpi_send_rxon(struct wpi_softc *sc, int async) |
3150 |
{ |
3151 |
int error; |
3152 |
|
3153 |
error = wpi_cmd(sc, WPI_CMD_RXON, &sc->rxon, sizeof (struct wpi_rxon), |
3154 |
async); |
2464 |
if (error != 0) { |
3155 |
if (error != 0) { |
2465 |
device_printf(sc->sc_dev, "could not configure\n"); |
3156 |
device_printf(sc->sc_dev, "RXON command failed, error %d\n", |
|
|
3157 |
error); |
2466 |
return error; |
3158 |
return error; |
2467 |
} |
3159 |
} |
2468 |
|
3160 |
|
2469 |
/* configuration has changed, set Tx power accordingly */ |
3161 |
/* Configuration has changed, set Tx power accordingly. */ |
2470 |
if ((error = wpi_set_txpower(sc, ni->ni_chan, 1)) != 0) { |
3162 |
if ((error = wpi_set_txpower(sc, async)) != 0) { |
2471 |
device_printf(sc->sc_dev, "could not set Tx power\n"); |
3163 |
device_printf(sc->sc_dev, |
|
|
3164 |
"%s: could not set TX power, error %d\n", __func__, error); |
2472 |
return error; |
3165 |
return error; |
2473 |
} |
3166 |
} |
2474 |
|
3167 |
|
2475 |
/* add default node */ |
3168 |
if (!(sc->rxon.filter & WPI_FILTER_BSS)) { |
2476 |
memset(&node, 0, sizeof node); |
3169 |
/* Add broadcast node. */ |
2477 |
IEEE80211_ADDR_COPY(node.bssid, ni->ni_bssid); |
3170 |
error = wpi_add_broadcast_node(sc, async); |
2478 |
node.id = WPI_ID_BSS; |
3171 |
if (error != 0) { |
2479 |
node.rate = (ic->ic_curmode == IEEE80211_MODE_11A) ? |
3172 |
device_printf(sc->sc_dev, |
2480 |
wpi_plcp_signal(12) : wpi_plcp_signal(2); |
3173 |
"could not add broadcast node, error %d\n", error); |
2481 |
node.action = htole32(WPI_ACTION_SET_RATE); |
3174 |
return error; |
2482 |
node.antenna = WPI_ANTENNA_BOTH; |
3175 |
} |
2483 |
error = wpi_cmd(sc, WPI_CMD_ADD_NODE, &node, sizeof node, 1); |
3176 |
} |
2484 |
if (error != 0) |
|
|
2485 |
device_printf(sc->sc_dev, "could not add BSS node\n"); |
2486 |
|
3177 |
|
2487 |
return (error); |
3178 |
return 0; |
2488 |
} |
3179 |
} |
2489 |
|
3180 |
|
|
|
3181 |
/** |
3182 |
* Configure the card to listen to a particular channel, this transisions the |
3183 |
* card in to being able to receive frames from remote devices. |
3184 |
*/ |
2490 |
static int |
3185 |
static int |
2491 |
wpi_run(struct wpi_softc *sc, struct ieee80211vap *vap) |
3186 |
wpi_config(struct wpi_softc *sc) |
2492 |
{ |
3187 |
{ |
2493 |
struct ieee80211com *ic = vap->iv_ic; |
3188 |
struct ifnet *ifp = sc->sc_ifp; |
2494 |
struct ieee80211_node *ni = vap->iv_bss; |
3189 |
struct ieee80211com *ic = ifp->if_l2com; |
|
|
3190 |
uint32_t flags; |
2495 |
int error; |
3191 |
int error; |
2496 |
|
3192 |
|
2497 |
if (vap->iv_opmode == IEEE80211_M_MONITOR) { |
3193 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__); |
2498 |
/* link LED blinks while monitoring */ |
3194 |
|
2499 |
wpi_set_led(sc, WPI_LED_LINK, 5, 5); |
3195 |
/* Set power saving level to CAM during initialization. */ |
2500 |
return 0; |
3196 |
if ((error = wpi_set_pslevel(sc, 0, 0, 0)) != 0) { |
|
|
3197 |
device_printf(sc->sc_dev, |
3198 |
"%s: could not set power saving level\n", __func__); |
3199 |
return error; |
2501 |
} |
3200 |
} |
2502 |
|
3201 |
|
2503 |
wpi_enable_tsf(sc, ni); |
3202 |
/* Configure bluetooth coexistence. */ |
|
|
3203 |
if ((error = wpi_send_btcoex(sc)) != 0) { |
3204 |
device_printf(sc->sc_dev, |
3205 |
"could not configure bluetooth coexistence\n"); |
3206 |
return error; |
3207 |
} |
2504 |
|
3208 |
|
2505 |
/* update adapter's configuration */ |
3209 |
/* Configure adapter. */ |
2506 |
sc->config.associd = htole16(ni->ni_associd & ~0xc000); |
3210 |
memset(&sc->rxon, 0, sizeof (struct wpi_rxon)); |
2507 |
/* short preamble/slot time are negotiated when associating */ |
3211 |
IEEE80211_ADDR_COPY(sc->rxon.myaddr, IF_LLADDR(ifp)); |
2508 |
sc->config.flags &= ~htole32(WPI_CONFIG_SHPREAMBLE | |
|
|
2509 |
WPI_CONFIG_SHSLOT); |
2510 |
if (ic->ic_flags & IEEE80211_F_SHSLOT) |
2511 |
sc->config.flags |= htole32(WPI_CONFIG_SHSLOT); |
2512 |
if (ic->ic_flags & IEEE80211_F_SHPREAMBLE) |
2513 |
sc->config.flags |= htole32(WPI_CONFIG_SHPREAMBLE); |
2514 |
sc->config.filter |= htole32(WPI_FILTER_BSS); |
2515 |
|
3212 |
|
2516 |
/* XXX put somewhere HC_QOS_SUPPORT_ASSOC + HC_IBSS_START */ |
3213 |
/* Set default channel. */ |
|
|
3214 |
sc->rxon.chan = ieee80211_chan2ieee(ic, ic->ic_curchan); |
3215 |
sc->rxon.flags = htole32(WPI_RXON_TSF | WPI_RXON_CTS_TO_SELF); |
3216 |
if (IEEE80211_IS_CHAN_2GHZ(ic->ic_curchan)) |
3217 |
sc->rxon.flags |= htole32(WPI_RXON_AUTO | WPI_RXON_24GHZ); |
2517 |
|
3218 |
|
2518 |
DPRINTF(("config chan %d flags %x\n", sc->config.chan, |
3219 |
switch (ic->ic_opmode) { |
2519 |
sc->config.flags)); |
3220 |
case IEEE80211_M_STA: |
2520 |
error = wpi_cmd(sc, WPI_CMD_CONFIGURE, &sc->config, sizeof (struct |
3221 |
case IEEE80211_M_WDS: /* No know setup, use STA for now */ |
2521 |
wpi_config), 1); |
3222 |
sc->rxon.mode = WPI_MODE_STA; |
2522 |
if (error != 0) { |
3223 |
sc->rxon.filter |= htole32(WPI_FILTER_MULTICAST); |
2523 |
device_printf(sc->sc_dev, "could not update configuration\n"); |
3224 |
break; |
|
|
3225 |
case IEEE80211_M_IBSS: |
3226 |
case IEEE80211_M_AHDEMO: |
3227 |
sc->rxon.mode = WPI_MODE_IBSS; |
3228 |
sc->rxon.filter |= htole32(WPI_FILTER_BEACON | |
3229 |
WPI_FILTER_MULTICAST); |
3230 |
break; |
3231 |
case IEEE80211_M_HOSTAP: |
3232 |
sc->rxon.mode = WPI_MODE_HOSTAP; |
3233 |
break; |
3234 |
case IEEE80211_M_MONITOR: |
3235 |
sc->rxon.mode = WPI_MODE_MONITOR; |
3236 |
sc->rxon.filter |= htole32(WPI_FILTER_MULTICAST | |
3237 |
WPI_FILTER_CTL); |
3238 |
|
3239 |
if (ifp->if_flags & IFF_PROMISC) |
3240 |
sc->rxon.filter |= WPI_FILTER_PROMISC; |
3241 |
break; |
3242 |
default: |
3243 |
device_printf(sc->sc_dev, "unknown opmode %d\n", ic->ic_opmode); |
3244 |
return EINVAL; |
3245 |
} |
3246 |
sc->rxon.cck_mask = 0x0f; /* not yet negotiated */ |
3247 |
sc->rxon.ofdm_mask = 0xff; /* not yet negotiated */ |
3248 |
|
3249 |
if ((error = wpi_send_rxon(sc, 0)) != 0) { |
3250 |
device_printf(sc->sc_dev, |
3251 |
"%s: wpi_send_rxon failed\n", __func__); |
2524 |
return error; |
3252 |
return error; |
2525 |
} |
3253 |
} |
2526 |
|
3254 |
|
2527 |
error = wpi_set_txpower(sc, ni->ni_chan, 1); |
3255 |
/* Setup rate scalling. */ |
|
|
3256 |
if ((error = wpi_mrr_setup(sc)) != 0) { |
3257 |
device_printf(sc->sc_dev, "could not setup MRR, error %d\n", |
3258 |
error); |
3259 |
return error; |
3260 |
} |
3261 |
|
3262 |
/* Disable beacon notifications (unused). */ |
3263 |
flags = WPI_STATISTICS_BEACON_DISABLE; |
3264 |
error = wpi_cmd(sc, WPI_CMD_GET_STATISTICS, &flags, sizeof flags, 1); |
2528 |
if (error != 0) { |
3265 |
if (error != 0) { |
2529 |
device_printf(sc->sc_dev, "could set txpower\n"); |
3266 |
device_printf(sc->sc_dev, |
|
|
3267 |
"could not disable beacon statistics, error %d\n", error); |
2530 |
return error; |
3268 |
return error; |
2531 |
} |
3269 |
} |
2532 |
|
3270 |
|
2533 |
/* link LED always on while associated */ |
3271 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__); |
2534 |
wpi_set_led(sc, WPI_LED_LINK, 0, 1); |
|
|
2535 |
|
3272 |
|
2536 |
/* start automatic rate control timer */ |
3273 |
return 0; |
2537 |
callout_reset(&sc->calib_to, 60*hz, wpi_calib_timeout, sc); |
3274 |
} |
2538 |
|
3275 |
|
2539 |
return (error); |
3276 |
static uint16_t |
|
|
3277 |
wpi_get_active_dwell_time(struct wpi_softc *sc, |
3278 |
struct ieee80211_channel *c, uint8_t n_probes) |
3279 |
{ |
3280 |
/* No channel? Default to 2GHz settings. */ |
3281 |
if (c == NULL || IEEE80211_IS_CHAN_2GHZ(c)) { |
3282 |
return (WPI_ACTIVE_DWELL_TIME_2GHZ + |
3283 |
WPI_ACTIVE_DWELL_FACTOR_2GHZ * (n_probes + 1)); |
3284 |
} |
3285 |
|
3286 |
/* 5GHz dwell time. */ |
3287 |
return (WPI_ACTIVE_DWELL_TIME_5GHZ + |
3288 |
WPI_ACTIVE_DWELL_FACTOR_5GHZ * (n_probes + 1)); |
2540 |
} |
3289 |
} |
2541 |
|
3290 |
|
2542 |
/* |
3291 |
/* |
2543 |
* Send a scan request to the firmware. Since this command is huge, we map it |
3292 |
* Limit the total dwell time to 85% of the beacon interval. |
2544 |
* into a mbufcluster instead of using the pre-allocated set of commands. Note, |
3293 |
* |
2545 |
* much of this code is similar to that in wpi_cmd but because we must manually |
3294 |
* Returns the dwell time in milliseconds. |
2546 |
* construct the probe & channels, we duplicate what's needed here. XXX In the |
|
|
2547 |
* future, this function should be modified to use wpi_cmd to help cleanup the |
2548 |
* code base. |
2549 |
*/ |
3295 |
*/ |
|
|
3296 |
static uint16_t |
3297 |
wpi_limit_dwell(struct wpi_softc *sc, uint16_t dwell_time) |
3298 |
{ |
3299 |
struct ieee80211com *ic = sc->sc_ifp->if_l2com; |
3300 |
struct ieee80211vap *vap = NULL; |
3301 |
int bintval = 0; |
3302 |
|
3303 |
/* bintval is in TU (1.024mS) */ |
3304 |
if (! TAILQ_EMPTY(&ic->ic_vaps)) { |
3305 |
vap = TAILQ_FIRST(&ic->ic_vaps); |
3306 |
bintval = vap->iv_bss->ni_intval; |
3307 |
} |
3308 |
|
3309 |
/* |
3310 |
* If it's non-zero, we should calculate the minimum of |
3311 |
* it and the DWELL_BASE. |
3312 |
* |
3313 |
* XXX Yes, the math should take into account that bintval |
3314 |
* is 1.024mS, not 1mS.. |
3315 |
*/ |
3316 |
if (bintval > 0) { |
3317 |
DPRINTF(sc, WPI_DEBUG_SCAN, "%s: bintval=%d\n", __func__, |
3318 |
bintval); |
3319 |
return (MIN(WPI_PASSIVE_DWELL_BASE, ((bintval * 85) / 100))); |
3320 |
} |
3321 |
|
3322 |
/* No association context? Default. */ |
3323 |
return (WPI_PASSIVE_DWELL_BASE); |
3324 |
} |
3325 |
|
3326 |
static uint16_t |
3327 |
wpi_get_passive_dwell_time(struct wpi_softc *sc, struct ieee80211_channel *c) |
3328 |
{ |
3329 |
uint16_t passive; |
3330 |
|
3331 |
if (c == NULL || IEEE80211_IS_CHAN_2GHZ(c)) { |
3332 |
passive = WPI_PASSIVE_DWELL_BASE + WPI_PASSIVE_DWELL_TIME_2GHZ; |
3333 |
} else { |
3334 |
passive = WPI_PASSIVE_DWELL_BASE + WPI_PASSIVE_DWELL_TIME_5GHZ; |
3335 |
} |
3336 |
|
3337 |
/* Clamp to the beacon interval if we're associated. */ |
3338 |
return (wpi_limit_dwell(sc, passive)); |
3339 |
} |
3340 |
|
3341 |
/* |
3342 |
* Send a scan request to the firmware. |
3343 |
*/ |
2550 |
static int |
3344 |
static int |
2551 |
wpi_scan(struct wpi_softc *sc) |
3345 |
wpi_scan(struct wpi_softc *sc, struct ieee80211_channel *c) |
2552 |
{ |
3346 |
{ |
2553 |
struct ifnet *ifp = sc->sc_ifp; |
3347 |
struct ifnet *ifp = sc->sc_ifp; |
2554 |
struct ieee80211com *ic = ifp->if_l2com; |
3348 |
struct ieee80211com *ic = ifp->if_l2com; |
2555 |
struct ieee80211_scan_state *ss = ic->ic_scan; |
3349 |
struct ieee80211_scan_state *ss = ic->ic_scan; |
2556 |
struct wpi_tx_ring *ring = &sc->cmdq; |
|
|
2557 |
struct wpi_tx_desc *desc; |
2558 |
struct wpi_tx_data *data; |
2559 |
struct wpi_tx_cmd *cmd; |
2560 |
struct wpi_scan_hdr *hdr; |
3350 |
struct wpi_scan_hdr *hdr; |
|
|
3351 |
struct wpi_cmd_data *tx; |
3352 |
struct wpi_scan_essid *essids; |
2561 |
struct wpi_scan_chan *chan; |
3353 |
struct wpi_scan_chan *chan; |
2562 |
struct ieee80211_frame *wh; |
3354 |
struct ieee80211_frame *wh; |
2563 |
struct ieee80211_rateset *rs; |
3355 |
struct ieee80211_rateset *rs; |
2564 |
struct ieee80211_channel *c; |
3356 |
uint16_t dwell_active, dwell_passive; |
2565 |
enum ieee80211_phymode mode; |
3357 |
uint8_t *buf, *frm; |
2566 |
uint8_t *frm; |
3358 |
int buflen, error, i, nssid; |
2567 |
int pktlen, error, i, nssid; |
|
|
2568 |
bus_addr_t physaddr; |
2569 |
|
3359 |
|
2570 |
desc = &ring->desc[ring->cur]; |
3360 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__); |
2571 |
data = &ring->data[ring->cur]; |
|
|
2572 |
|
3361 |
|
2573 |
data->m = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR); |
3362 |
/* |
2574 |
if (data->m == NULL) { |
3363 |
* We are absolutely not allowed to send a scan command when another |
|
|
3364 |
* scan command is pending. |
3365 |
*/ |
3366 |
if (sc->sc_scan_timer) { |
3367 |
device_printf(sc->sc_dev, "%s: called whilst scanning!\n", |
3368 |
__func__); |
3369 |
return (EAGAIN); |
3370 |
} |
3371 |
|
3372 |
buf = malloc(WPI_SCAN_MAXSZ, M_DEVBUF, M_NOWAIT | M_ZERO); |
3373 |
if (buf == NULL) { |
2575 |
device_printf(sc->sc_dev, |
3374 |
device_printf(sc->sc_dev, |
2576 |
"could not allocate mbuf for scan command\n"); |
3375 |
"%s: could not allocate buffer for scan command\n", |
|
|
3376 |
__func__); |
2577 |
return ENOMEM; |
3377 |
return ENOMEM; |
2578 |
} |
3378 |
} |
|
|
3379 |
hdr = (struct wpi_scan_hdr *)buf; |
2579 |
|
3380 |
|
2580 |
cmd = mtod(data->m, struct wpi_tx_cmd *); |
|
|
2581 |
cmd->code = WPI_CMD_SCAN; |
2582 |
cmd->flags = 0; |
2583 |
cmd->qid = ring->qid; |
2584 |
cmd->idx = ring->cur; |
2585 |
|
2586 |
hdr = (struct wpi_scan_hdr *)cmd->data; |
2587 |
memset(hdr, 0, sizeof(struct wpi_scan_hdr)); |
2588 |
|
2589 |
/* |
3381 |
/* |
2590 |
* Move to the next channel if no packets are received within 5 msecs |
3382 |
* Move to the next channel if no packets are received within 10 msecs |
2591 |
* after sending the probe request (this helps to reduce the duration |
3383 |
* after sending the probe request. |
2592 |
* of active scans). |
|
|
2593 |
*/ |
3384 |
*/ |
2594 |
hdr->quiet = htole16(5); |
3385 |
hdr->quiet_time = htole16(10); /* timeout in milliseconds */ |
2595 |
hdr->threshold = htole16(1); |
3386 |
hdr->quiet_threshold = htole16(1); /* min # of packets */ |
|
|
3387 |
/* |
3388 |
* Max needs to be greater than active and passive and quiet! |
3389 |
* It's also in microseconds! |
3390 |
*/ |
3391 |
hdr->max_svc = htole32(250 * IEEE80211_DUR_TU); |
3392 |
hdr->pause_svc = htole32((4 << 24) | |
3393 |
(100 * IEEE80211_DUR_TU)); /* Hardcode for now */ |
3394 |
hdr->filter = htole32(WPI_FILTER_MULTICAST | WPI_FILTER_BEACON); |
2596 |
|
3395 |
|
2597 |
if (IEEE80211_IS_CHAN_A(ic->ic_curchan)) { |
3396 |
tx = (struct wpi_cmd_data *)(hdr + 1); |
2598 |
/* send probe requests at 6Mbps */ |
3397 |
tx->flags = htole32(WPI_TX_AUTO_SEQ); |
2599 |
hdr->tx.rate = wpi_ridx_to_plcp[WPI_OFDM6]; |
3398 |
tx->id = WPI_ID_BROADCAST; |
|
|
3399 |
tx->lifetime = htole32(WPI_LIFETIME_INFINITE); |
2600 |
|
3400 |
|
2601 |
/* Enable crc checking */ |
3401 |
if (IEEE80211_IS_CHAN_5GHZ(c)) { |
2602 |
hdr->promotion = htole16(1); |
3402 |
/* Send probe requests at 6Mbps. */ |
|
|
3403 |
tx->plcp = wpi_ridx_to_plcp[WPI_RIDX_OFDM6]; |
3404 |
rs = &ic->ic_sup_rates[IEEE80211_MODE_11A]; |
2603 |
} else { |
3405 |
} else { |
2604 |
hdr->flags = htole32(WPI_CONFIG_24GHZ | WPI_CONFIG_AUTO); |
3406 |
hdr->flags = htole32(WPI_RXON_24GHZ | WPI_RXON_AUTO); |
2605 |
/* send probe requests at 1Mbps */ |
3407 |
/* Send probe requests at 1Mbps. */ |
2606 |
hdr->tx.rate = wpi_ridx_to_plcp[WPI_CCK1]; |
3408 |
tx->plcp = wpi_ridx_to_plcp[WPI_RIDX_CCK1]; |
|
|
3409 |
rs = &ic->ic_sup_rates[IEEE80211_MODE_11G]; |
2607 |
} |
3410 |
} |
2608 |
hdr->tx.id = WPI_ID_BROADCAST; |
|
|
2609 |
hdr->tx.lifetime = htole32(WPI_LIFETIME_INFINITE); |
2610 |
hdr->tx.flags = htole32(WPI_TX_AUTO_SEQ); |
2611 |
|
3411 |
|
2612 |
memset(hdr->scan_essids, 0, sizeof(hdr->scan_essids)); |
3412 |
essids = (struct wpi_scan_essid *)(tx + 1); |
2613 |
nssid = MIN(ss->ss_nssid, WPI_SCAN_MAX_ESSIDS); |
3413 |
nssid = MIN(ss->ss_nssid, WPI_SCAN_MAX_ESSIDS); |
2614 |
for (i = 0; i < nssid; i++) { |
3414 |
for (i = 0; i < nssid; i++) { |
2615 |
hdr->scan_essids[i].id = IEEE80211_ELEMID_SSID; |
3415 |
essids[i].id = IEEE80211_ELEMID_SSID; |
2616 |
hdr->scan_essids[i].esslen = MIN(ss->ss_ssid[i].len, IEEE80211_NWID_LEN); |
3416 |
essids[i].len = MIN(ss->ss_ssid[i].len, IEEE80211_NWID_LEN); |
2617 |
memcpy(hdr->scan_essids[i].essid, ss->ss_ssid[i].ssid, |
3417 |
memcpy(essids[i].data, ss->ss_ssid[i].ssid, essids[i].len); |
2618 |
hdr->scan_essids[i].esslen); |
|
|
2619 |
#ifdef WPI_DEBUG |
3418 |
#ifdef WPI_DEBUG |
2620 |
if (wpi_debug & WPI_DEBUG_SCANNING) { |
3419 |
if (sc->sc_debug & WPI_DEBUG_SCAN) { |
2621 |
printf("Scanning Essid: "); |
3420 |
printf("Scanning Essid: "); |
2622 |
ieee80211_print_essid(hdr->scan_essids[i].essid, |
3421 |
ieee80211_print_essid(essids[i].data, essids[i].len); |
2623 |
hdr->scan_essids[i].esslen); |
|
|
2624 |
printf("\n"); |
3422 |
printf("\n"); |
2625 |
} |
3423 |
} |
2626 |
#endif |
3424 |
#endif |
Lines 2630-2636
Link Here
|
2630 |
* Build a probe request frame. Most of the following code is a |
3428 |
* Build a probe request frame. Most of the following code is a |
2631 |
* copy & paste of what is done in net80211. |
3429 |
* copy & paste of what is done in net80211. |
2632 |
*/ |
3430 |
*/ |
2633 |
wh = (struct ieee80211_frame *)&hdr->scan_essids[WPI_SCAN_MAX_ESSIDS]; |
3431 |
wh = (struct ieee80211_frame *)(essids + WPI_SCAN_MAX_ESSIDS); |
2634 |
wh->i_fc[0] = IEEE80211_FC0_VERSION_0 | IEEE80211_FC0_TYPE_MGT | |
3432 |
wh->i_fc[0] = IEEE80211_FC0_VERSION_0 | IEEE80211_FC0_TYPE_MGT | |
2635 |
IEEE80211_FC0_SUBTYPE_PROBE_REQ; |
3433 |
IEEE80211_FC0_SUBTYPE_PROBE_REQ; |
2636 |
wh->i_fc[1] = IEEE80211_FC1_DIR_NODS; |
3434 |
wh->i_fc[1] = IEEE80211_FC1_DIR_NODS; |
Lines 2637-2656
Link Here
|
2637 |
IEEE80211_ADDR_COPY(wh->i_addr1, ifp->if_broadcastaddr); |
3435 |
IEEE80211_ADDR_COPY(wh->i_addr1, ifp->if_broadcastaddr); |
2638 |
IEEE80211_ADDR_COPY(wh->i_addr2, IF_LLADDR(ifp)); |
3436 |
IEEE80211_ADDR_COPY(wh->i_addr2, IF_LLADDR(ifp)); |
2639 |
IEEE80211_ADDR_COPY(wh->i_addr3, ifp->if_broadcastaddr); |
3437 |
IEEE80211_ADDR_COPY(wh->i_addr3, ifp->if_broadcastaddr); |
2640 |
*(u_int16_t *)&wh->i_dur[0] = 0; /* filled by h/w */ |
3438 |
*(uint16_t *)&wh->i_dur[0] = 0; /* filled by h/w */ |
2641 |
*(u_int16_t *)&wh->i_seq[0] = 0; /* filled by h/w */ |
3439 |
*(uint16_t *)&wh->i_seq[0] = 0; /* filled by h/w */ |
2642 |
|
3440 |
|
2643 |
frm = (uint8_t *)(wh + 1); |
3441 |
frm = (uint8_t *)(wh + 1); |
2644 |
|
|
|
2645 |
mode = ieee80211_chan2mode(ic->ic_curchan); |
2646 |
rs = &ic->ic_sup_rates[mode]; |
2647 |
|
2648 |
frm = ieee80211_add_ssid(frm, NULL, 0); |
3442 |
frm = ieee80211_add_ssid(frm, NULL, 0); |
2649 |
frm = ieee80211_add_rates(frm, rs); |
3443 |
frm = ieee80211_add_rates(frm, rs); |
2650 |
frm = ieee80211_add_xrates(frm, rs); |
3444 |
if (rs->rs_nrates > IEEE80211_RATE_SIZE) |
|
|
3445 |
frm = ieee80211_add_xrates(frm, rs); |
2651 |
|
3446 |
|
2652 |
/* setup length of probe request */ |
3447 |
/* Set length of probe request. */ |
2653 |
hdr->tx.len = htole16(frm - (uint8_t *)wh); |
3448 |
tx->len = htole16(frm - (uint8_t *)wh); |
2654 |
|
3449 |
|
2655 |
/* |
3450 |
/* |
2656 |
* Construct information about the channel that we |
3451 |
* Construct information about the channel that we |
Lines 2657-3506
Link Here
|
2657 |
* want to scan. The firmware expects this to be directly |
3452 |
* want to scan. The firmware expects this to be directly |
2658 |
* after the scan probe request |
3453 |
* after the scan probe request |
2659 |
*/ |
3454 |
*/ |
2660 |
c = ic->ic_curchan; |
|
|
2661 |
chan = (struct wpi_scan_chan *)frm; |
3455 |
chan = (struct wpi_scan_chan *)frm; |
2662 |
chan->chan = ieee80211_chan2ieee(ic, c); |
3456 |
chan->chan = htole16(ieee80211_chan2ieee(ic, c)); |
2663 |
chan->flags = 0; |
3457 |
chan->flags = 0; |
2664 |
if (!(c->ic_flags & IEEE80211_CHAN_PASSIVE)) { |
3458 |
if (nssid) { |
|
|
3459 |
hdr->crc_threshold = WPI_SCAN_CRC_TH_DEFAULT; |
3460 |
chan->flags |= WPI_CHAN_NPBREQS(nssid); |
3461 |
} else |
3462 |
hdr->crc_threshold = WPI_SCAN_CRC_TH_NEVER; |
3463 |
|
3464 |
if (!(c->ic_flags & IEEE80211_CHAN_PASSIVE)) |
2665 |
chan->flags |= WPI_CHAN_ACTIVE; |
3465 |
chan->flags |= WPI_CHAN_ACTIVE; |
2666 |
if (nssid != 0) |
|
|
2667 |
chan->flags |= WPI_CHAN_DIRECT; |
2668 |
} |
2669 |
chan->gain_dsp = 0x6e; /* Default level */ |
2670 |
if (IEEE80211_IS_CHAN_5GHZ(c)) { |
2671 |
chan->active = htole16(10); |
2672 |
chan->passive = htole16(ss->ss_maxdwell); |
2673 |
chan->gain_radio = 0x3b; |
2674 |
} else { |
2675 |
chan->active = htole16(20); |
2676 |
chan->passive = htole16(ss->ss_maxdwell); |
2677 |
chan->gain_radio = 0x28; |
2678 |
} |
2679 |
|
3466 |
|
2680 |
DPRINTFN(WPI_DEBUG_SCANNING, |
3467 |
/* |
2681 |
("Scanning %u Passive: %d\n", |
3468 |
* Calculate the active/passive dwell times. |
2682 |
chan->chan, |
3469 |
*/ |
2683 |
c->ic_flags & IEEE80211_CHAN_PASSIVE)); |
|
|
2684 |
|
3470 |
|
|
|
3471 |
dwell_active = wpi_get_active_dwell_time(sc, c, nssid); |
3472 |
dwell_passive = wpi_get_passive_dwell_time(sc, c); |
3473 |
|
3474 |
/* Make sure they're valid. */ |
3475 |
if (dwell_passive <= dwell_active) |
3476 |
dwell_passive = dwell_active + 1; |
3477 |
|
3478 |
chan->active = htole16(dwell_active); |
3479 |
chan->passive = htole16(dwell_passive); |
3480 |
|
3481 |
chan->dsp_gain = 0x6e; /* Default level */ |
3482 |
|
3483 |
if (IEEE80211_IS_CHAN_5GHZ(c)) |
3484 |
chan->rf_gain = 0x3b; |
3485 |
else |
3486 |
chan->rf_gain = 0x28; |
3487 |
|
3488 |
DPRINTF(sc, WPI_DEBUG_SCAN, "Scanning %u Passive: %d\n", |
3489 |
chan->chan, (c->ic_flags & IEEE80211_CHAN_PASSIVE) ? 1 : 0); |
3490 |
|
2685 |
hdr->nchan++; |
3491 |
hdr->nchan++; |
2686 |
chan++; |
3492 |
chan++; |
2687 |
|
3493 |
|
2688 |
frm += sizeof (struct wpi_scan_chan); |
3494 |
buflen = (uint8_t *)chan - buf; |
2689 |
#if 0 |
3495 |
hdr->len = htole16(buflen); |
2690 |
// XXX All Channels.... |
|
|
2691 |
for (c = &ic->ic_channels[1]; |
2692 |
c <= &ic->ic_channels[IEEE80211_CHAN_MAX]; c++) { |
2693 |
if ((c->ic_flags & ic->ic_curchan->ic_flags) != ic->ic_curchan->ic_flags) |
2694 |
continue; |
2695 |
|
3496 |
|
2696 |
chan->chan = ieee80211_chan2ieee(ic, c); |
3497 |
DPRINTF(sc, WPI_DEBUG_CMD, "sending scan command nchan=%d\n", |
2697 |
chan->flags = 0; |
3498 |
hdr->nchan); |
2698 |
if (!(c->ic_flags & IEEE80211_CHAN_PASSIVE)) { |
3499 |
error = wpi_cmd(sc, WPI_CMD_SCAN, buf, buflen, 1); |
2699 |
chan->flags |= WPI_CHAN_ACTIVE; |
3500 |
free(buf, M_DEVBUF); |
2700 |
if (ic->ic_des_ssid[0].len != 0) |
|
|
2701 |
chan->flags |= WPI_CHAN_DIRECT; |
2702 |
} |
2703 |
chan->gain_dsp = 0x6e; /* Default level */ |
2704 |
if (IEEE80211_IS_CHAN_5GHZ(c)) { |
2705 |
chan->active = htole16(10); |
2706 |
chan->passive = htole16(110); |
2707 |
chan->gain_radio = 0x3b; |
2708 |
} else { |
2709 |
chan->active = htole16(20); |
2710 |
chan->passive = htole16(120); |
2711 |
chan->gain_radio = 0x28; |
2712 |
} |
2713 |
|
3501 |
|
2714 |
DPRINTFN(WPI_DEBUG_SCANNING, |
3502 |
sc->sc_scan_timer = 5; |
2715 |
("Scanning %u Passive: %d\n", |
|
|
2716 |
chan->chan, |
2717 |
c->ic_flags & IEEE80211_CHAN_PASSIVE)); |
2718 |
|
3503 |
|
2719 |
hdr->nchan++; |
3504 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__); |
2720 |
chan++; |
|
|
2721 |
|
3505 |
|
2722 |
frm += sizeof (struct wpi_scan_chan); |
3506 |
return error; |
2723 |
} |
3507 |
} |
2724 |
#endif |
|
|
2725 |
|
3508 |
|
2726 |
hdr->len = htole16(frm - (uint8_t *)hdr); |
3509 |
static int |
2727 |
pktlen = frm - (uint8_t *)cmd; |
3510 |
wpi_auth(struct wpi_softc *sc, struct ieee80211vap *vap) |
|
|
3511 |
{ |
3512 |
struct ieee80211com *ic = vap->iv_ic; |
3513 |
struct ieee80211_node *ni = vap->iv_bss; |
3514 |
int error; |
2728 |
|
3515 |
|
2729 |
error = bus_dmamap_load(ring->data_dmat, data->map, cmd, pktlen, |
3516 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__); |
2730 |
wpi_dma_map_addr, &physaddr, BUS_DMA_NOWAIT); |
3517 |
|
2731 |
if (error != 0) { |
3518 |
/* Update adapter configuration. */ |
2732 |
device_printf(sc->sc_dev, "could not map scan command\n"); |
3519 |
sc->rxon.associd = 0; |
2733 |
m_freem(data->m); |
3520 |
sc->rxon.filter &= ~htole32(WPI_FILTER_BSS); |
2734 |
data->m = NULL; |
3521 |
IEEE80211_ADDR_COPY(sc->rxon.bssid, ni->ni_bssid); |
2735 |
return error; |
3522 |
sc->rxon.chan = ieee80211_chan2ieee(ic, ni->ni_chan); |
|
|
3523 |
sc->rxon.flags = htole32(WPI_RXON_TSF | WPI_RXON_CTS_TO_SELF); |
3524 |
if (IEEE80211_IS_CHAN_2GHZ(ni->ni_chan)) |
3525 |
sc->rxon.flags |= htole32(WPI_RXON_AUTO | WPI_RXON_24GHZ); |
3526 |
if (ic->ic_flags & IEEE80211_F_SHSLOT) |
3527 |
sc->rxon.flags |= htole32(WPI_RXON_SHSLOT); |
3528 |
if (ic->ic_flags & IEEE80211_F_SHPREAMBLE) |
3529 |
sc->rxon.flags |= htole32(WPI_RXON_SHPREAMBLE); |
3530 |
if (IEEE80211_IS_CHAN_A(ni->ni_chan)) { |
3531 |
sc->rxon.cck_mask = 0; |
3532 |
sc->rxon.ofdm_mask = 0x15; |
3533 |
} else if (IEEE80211_IS_CHAN_B(ni->ni_chan)) { |
3534 |
sc->rxon.cck_mask = 0x03; |
3535 |
sc->rxon.ofdm_mask = 0; |
3536 |
} else { |
3537 |
/* Assume 802.11b/g. */ |
3538 |
sc->rxon.cck_mask = 0x0f; |
3539 |
sc->rxon.ofdm_mask = 0x15; |
2736 |
} |
3540 |
} |
2737 |
|
3541 |
|
2738 |
desc->flags = htole32(WPI_PAD32(pktlen) << 28 | 1 << 24); |
3542 |
DPRINTF(sc, WPI_DEBUG_STATE, "rxon chan %d flags %x cck %x ofdm %x\n", |
2739 |
desc->segs[0].addr = htole32(physaddr); |
3543 |
sc->rxon.chan, sc->rxon.flags, sc->rxon.cck_mask, |
2740 |
desc->segs[0].len = htole32(pktlen); |
3544 |
sc->rxon.ofdm_mask); |
2741 |
|
3545 |
|
2742 |
bus_dmamap_sync(ring->desc_dma.tag, ring->desc_dma.map, |
3546 |
if ((error = wpi_send_rxon(sc, 1)) != 0) { |
2743 |
BUS_DMASYNC_PREWRITE); |
3547 |
device_printf(sc->sc_dev, |
2744 |
bus_dmamap_sync(ring->data_dmat, data->map, BUS_DMASYNC_PREWRITE); |
3548 |
"%s: wpi_send_rxon failed\n", __func__); |
|
|
3549 |
} |
2745 |
|
3550 |
|
2746 |
/* kick cmd ring */ |
3551 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__); |
2747 |
ring->cur = (ring->cur + 1) % WPI_CMD_RING_COUNT; |
|
|
2748 |
WPI_WRITE(sc, WPI_TX_WIDX, ring->qid << 8 | ring->cur); |
2749 |
|
3552 |
|
2750 |
sc->sc_scan_timer = 5; |
3553 |
return error; |
2751 |
return 0; /* will be notified async. of failure/success */ |
|
|
2752 |
} |
3554 |
} |
2753 |
|
3555 |
|
2754 |
/** |
|
|
2755 |
* Configure the card to listen to a particular channel, this transisions the |
2756 |
* card in to being able to receive frames from remote devices. |
2757 |
*/ |
2758 |
static int |
3556 |
static int |
2759 |
wpi_config(struct wpi_softc *sc) |
3557 |
wpi_run(struct wpi_softc *sc, struct ieee80211vap *vap) |
2760 |
{ |
3558 |
{ |
2761 |
struct ifnet *ifp = sc->sc_ifp; |
3559 |
struct ieee80211com *ic = vap->iv_ic; |
2762 |
struct ieee80211com *ic = ifp->if_l2com; |
3560 |
struct ieee80211_node *ni = vap->iv_bss; |
2763 |
struct wpi_power power; |
|
|
2764 |
struct wpi_bluetooth bluetooth; |
2765 |
struct wpi_node_info node; |
2766 |
int error; |
3561 |
int error; |
2767 |
|
3562 |
|
2768 |
/* set power mode */ |
3563 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__); |
2769 |
memset(&power, 0, sizeof power); |
3564 |
|
2770 |
power.flags = htole32(WPI_POWER_CAM|0x8); |
3565 |
if (vap->iv_opmode == IEEE80211_M_MONITOR) { |
2771 |
error = wpi_cmd(sc, WPI_CMD_SET_POWER_MODE, &power, sizeof power, 0); |
3566 |
/* Link LED blinks while monitoring. */ |
2772 |
if (error != 0) { |
3567 |
wpi_set_led(sc, WPI_LED_LINK, 5, 5); |
2773 |
device_printf(sc->sc_dev, "could not set power mode\n"); |
3568 |
return 0; |
2774 |
return error; |
|
|
2775 |
} |
3569 |
} |
2776 |
|
3570 |
|
2777 |
/* configure bluetooth coexistence */ |
3571 |
if ((error = wpi_set_timing(sc, ni)) != 0) { |
2778 |
memset(&bluetooth, 0, sizeof bluetooth); |
|
|
2779 |
bluetooth.flags = 3; |
2780 |
bluetooth.lead = 0xaa; |
2781 |
bluetooth.kill = 1; |
2782 |
error = wpi_cmd(sc, WPI_CMD_BLUETOOTH, &bluetooth, sizeof bluetooth, |
2783 |
0); |
2784 |
if (error != 0) { |
2785 |
device_printf(sc->sc_dev, |
3572 |
device_printf(sc->sc_dev, |
2786 |
"could not configure bluetooth coexistence\n"); |
3573 |
"%s: could not set timing, error %d\n", __func__, error); |
2787 |
return error; |
3574 |
return error; |
2788 |
} |
3575 |
} |
2789 |
|
3576 |
|
2790 |
/* configure adapter */ |
3577 |
/* Update adapter configuration. */ |
2791 |
memset(&sc->config, 0, sizeof (struct wpi_config)); |
3578 |
IEEE80211_ADDR_COPY(sc->rxon.bssid, ni->ni_bssid); |
2792 |
IEEE80211_ADDR_COPY(sc->config.myaddr, IF_LLADDR(ifp)); |
3579 |
sc->rxon.associd = htole16(IEEE80211_NODE_AID(ni)); |
2793 |
/*set default channel*/ |
3580 |
sc->rxon.chan = ieee80211_chan2ieee(ic, ni->ni_chan); |
2794 |
sc->config.chan = htole16(ieee80211_chan2ieee(ic, ic->ic_curchan)); |
3581 |
sc->rxon.flags = htole32(WPI_RXON_TSF | WPI_RXON_CTS_TO_SELF); |
2795 |
sc->config.flags = htole32(WPI_CONFIG_TSF); |
3582 |
if (IEEE80211_IS_CHAN_2GHZ(ni->ni_chan)) |
2796 |
if (IEEE80211_IS_CHAN_2GHZ(ic->ic_curchan)) { |
3583 |
sc->rxon.flags |= htole32(WPI_RXON_AUTO | WPI_RXON_24GHZ); |
2797 |
sc->config.flags |= htole32(WPI_CONFIG_AUTO | |
3584 |
/* Short preamble and slot time are negotiated when associating. */ |
2798 |
WPI_CONFIG_24GHZ); |
3585 |
sc->rxon.flags &= ~htole32(WPI_RXON_SHPREAMBLE | WPI_RXON_SHSLOT); |
|
|
3586 |
if (ic->ic_flags & IEEE80211_F_SHSLOT) |
3587 |
sc->rxon.flags |= htole32(WPI_RXON_SHSLOT); |
3588 |
if (ic->ic_flags & IEEE80211_F_SHPREAMBLE) |
3589 |
sc->rxon.flags |= htole32(WPI_RXON_SHPREAMBLE); |
3590 |
if (IEEE80211_IS_CHAN_A(ni->ni_chan)) { |
3591 |
sc->rxon.cck_mask = 0; |
3592 |
sc->rxon.ofdm_mask = 0x15; |
3593 |
} else if (IEEE80211_IS_CHAN_B(ni->ni_chan)) { |
3594 |
sc->rxon.cck_mask = 0x03; |
3595 |
sc->rxon.ofdm_mask = 0; |
3596 |
} else { |
3597 |
/* Assume 802.11b/g. */ |
3598 |
sc->rxon.cck_mask = 0x0f; |
3599 |
sc->rxon.ofdm_mask = 0x15; |
2799 |
} |
3600 |
} |
2800 |
sc->config.filter = 0; |
3601 |
sc->rxon.filter |= htole32(WPI_FILTER_BSS); |
2801 |
switch (ic->ic_opmode) { |
3602 |
|
2802 |
case IEEE80211_M_STA: |
3603 |
/* XXX put somewhere HC_QOS_SUPPORT_ASSOC + HC_IBSS_START */ |
2803 |
case IEEE80211_M_WDS: /* No know setup, use STA for now */ |
3604 |
|
2804 |
sc->config.mode = WPI_MODE_STA; |
3605 |
DPRINTF(sc, WPI_DEBUG_STATE, "rxon chan %d flags %x\n", |
2805 |
sc->config.filter |= htole32(WPI_FILTER_MULTICAST); |
3606 |
sc->rxon.chan, sc->rxon.flags); |
2806 |
break; |
3607 |
|
2807 |
case IEEE80211_M_IBSS: |
3608 |
if ((error = wpi_send_rxon(sc, 1)) != 0) { |
2808 |
case IEEE80211_M_AHDEMO: |
3609 |
device_printf(sc->sc_dev, |
2809 |
sc->config.mode = WPI_MODE_IBSS; |
3610 |
"%s: wpi_send_rxon failed\n", __func__); |
2810 |
sc->config.filter |= htole32(WPI_FILTER_BEACON | |
3611 |
return error; |
2811 |
WPI_FILTER_MULTICAST); |
|
|
2812 |
break; |
2813 |
case IEEE80211_M_HOSTAP: |
2814 |
sc->config.mode = WPI_MODE_HOSTAP; |
2815 |
break; |
2816 |
case IEEE80211_M_MONITOR: |
2817 |
sc->config.mode = WPI_MODE_MONITOR; |
2818 |
sc->config.filter |= htole32(WPI_FILTER_MULTICAST | |
2819 |
WPI_FILTER_CTL | WPI_FILTER_PROMISC); |
2820 |
break; |
2821 |
default: |
2822 |
device_printf(sc->sc_dev, "unknown opmode %d\n", ic->ic_opmode); |
2823 |
return EINVAL; |
2824 |
} |
3612 |
} |
2825 |
sc->config.cck_mask = 0x0f; /* not yet negotiated */ |
3613 |
|
2826 |
sc->config.ofdm_mask = 0xff; /* not yet negotiated */ |
3614 |
/* Add BSS node. */ |
2827 |
error = wpi_cmd(sc, WPI_CMD_CONFIGURE, &sc->config, |
3615 |
((struct wpi_node *)ni)->id = WPI_ID_BSS; |
2828 |
sizeof (struct wpi_config), 0); |
3616 |
if ((error = wpi_add_node(sc, ni)) != 0) { |
2829 |
if (error != 0) { |
3617 |
device_printf(sc->sc_dev, "could not add BSS node, error %d\n", |
2830 |
device_printf(sc->sc_dev, "configure command failed\n"); |
3618 |
error); |
2831 |
return error; |
3619 |
return error; |
2832 |
} |
3620 |
} |
2833 |
|
3621 |
|
2834 |
/* configuration has changed, set Tx power accordingly */ |
3622 |
/* Link LED always on while associated. */ |
2835 |
if ((error = wpi_set_txpower(sc, ic->ic_curchan, 0)) != 0) { |
3623 |
wpi_set_led(sc, WPI_LED_LINK, 0, 1); |
2836 |
device_printf(sc->sc_dev, "could not set Tx power\n"); |
3624 |
|
2837 |
return error; |
3625 |
/* Start periodic calibration timer. */ |
|
|
3626 |
callout_reset(&sc->calib_to, 60*hz, wpi_calib_timeout, sc); |
3627 |
|
3628 |
/* Enable power-saving mode if requested by user. */ |
3629 |
if (vap->iv_flags & IEEE80211_F_PMGTON) |
3630 |
(void)wpi_set_pslevel(sc, 0, 3, 1); |
3631 |
|
3632 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__); |
3633 |
|
3634 |
return 0; |
3635 |
} |
3636 |
|
3637 |
#if 0 |
3638 |
static int |
3639 |
wpi_key_set(struct ieee80211vap *vap, const struct ieee80211_key *k, |
3640 |
const uint8_t mac[IEEE80211_ADDR_LEN]) |
3641 |
{ |
3642 |
const struct ieee80211_cipher *cip = k->wk_cipher; |
3643 |
struct ieee80211com *ic = vap->iv_ic; |
3644 |
struct ieee80211_node *ni = vap->iv_bss; |
3645 |
struct wpi_softc *sc = ic->ic_ifp->if_softc; |
3646 |
struct wpi_node *wn = (void *)ni; |
3647 |
struct wpi_node_info node; |
3648 |
uint16_t kflags; |
3649 |
int error; |
3650 |
|
3651 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__); |
3652 |
|
3653 |
switch (cip->ic_cipher) { |
3654 |
case IEEE80211_CIPHER_AES_CCM: |
3655 |
kflags = WPI_KFLAG_CCMP; |
3656 |
break; |
3657 |
default: |
3658 |
return 0; |
2838 |
} |
3659 |
} |
2839 |
|
3660 |
|
2840 |
/* add broadcast node */ |
|
|
2841 |
memset(&node, 0, sizeof node); |
3661 |
memset(&node, 0, sizeof node); |
2842 |
IEEE80211_ADDR_COPY(node.bssid, ifp->if_broadcastaddr); |
|
|
2843 |
node.id = WPI_ID_BROADCAST; |
2844 |
node.rate = wpi_plcp_signal(2); |
2845 |
error = wpi_cmd(sc, WPI_CMD_ADD_NODE, &node, sizeof node, 0); |
2846 |
if (error != 0) { |
2847 |
device_printf(sc->sc_dev, "could not add broadcast node\n"); |
2848 |
return error; |
2849 |
} |
2850 |
|
3662 |
|
2851 |
/* Setup rate scalling */ |
3663 |
kflags |= WPI_KFLAG_KID(k->wk_keyix); |
2852 |
error = wpi_mrr_setup(sc); |
3664 |
|
|
|
3665 |
if (k->wk_flags & IEEE80211_KEY_GROUP) |
3666 |
kflags |= WPI_KFLAG_MULTICAST; |
3667 |
|
3668 |
node.id = wn->id; |
3669 |
node.control = WPI_NODE_UPDATE; |
3670 |
node.flags = WPI_FLAG_KEY_SET; |
3671 |
node.kflags = htole16(kflags); |
3672 |
memcpy(node.key, k->wk_key, k->wk_keylen); |
3673 |
|
3674 |
DPRINTF(sc, WPI_DEBUG_KEY, "set key id=%d for node %d\n", k->wk_keyix, |
3675 |
node.id); |
3676 |
|
3677 |
error = wpi_cmd(sc, WPI_CMD_ADD_NODE, &node, sizeof node, 1); |
2853 |
if (error != 0) { |
3678 |
if (error != 0) { |
2854 |
device_printf(sc->sc_dev, "could not setup MRR\n"); |
3679 |
device_printf(sc->sc_dev, "can't update node info, error %d\n", |
2855 |
return error; |
3680 |
error); |
|
|
3681 |
return 0; |
2856 |
} |
3682 |
} |
2857 |
|
3683 |
|
2858 |
return 0; |
3684 |
return 1; |
2859 |
} |
3685 |
} |
2860 |
|
3686 |
|
2861 |
static void |
3687 |
static int |
2862 |
wpi_stop_master(struct wpi_softc *sc) |
3688 |
wpi_key_delete(struct ieee80211vap *vap, const struct ieee80211_key *k) |
2863 |
{ |
3689 |
{ |
2864 |
uint32_t tmp; |
3690 |
const struct ieee80211_cipher *cip = k->wk_cipher; |
2865 |
int ntries; |
3691 |
struct ieee80211com *ic = vap->iv_ic; |
|
|
3692 |
struct ieee80211_node *ni = vap->iv_bss; |
3693 |
struct wpi_softc *sc = ic->ic_ifp->if_softc; |
3694 |
struct wpi_node *wn = (void *)ni; |
3695 |
struct wpi_node_info node; |
2866 |
|
3696 |
|
2867 |
DPRINTFN(WPI_DEBUG_HW,("Disabling Firmware execution\n")); |
3697 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__); |
2868 |
|
3698 |
|
2869 |
tmp = WPI_READ(sc, WPI_RESET); |
3699 |
switch (cip->ic_cipher) { |
2870 |
WPI_WRITE(sc, WPI_RESET, tmp | WPI_STOP_MASTER | WPI_NEVO_RESET); |
3700 |
case IEEE80211_CIPHER_AES_CCM: |
|
|
3701 |
break; |
3702 |
default: |
3703 |
return 0; |
3704 |
} |
2871 |
|
3705 |
|
2872 |
tmp = WPI_READ(sc, WPI_GPIO_CTL); |
3706 |
if (vap->iv_state != IEEE80211_S_RUN) |
2873 |
if ((tmp & WPI_GPIO_PWR_STATUS) == WPI_GPIO_PWR_SLEEP) |
3707 |
return 1; /* Nothing to do. */ |
2874 |
return; /* already asleep */ |
|
|
2875 |
|
3708 |
|
2876 |
for (ntries = 0; ntries < 100; ntries++) { |
3709 |
memset(&node, 0, sizeof node); |
2877 |
if (WPI_READ(sc, WPI_RESET) & WPI_MASTER_DISABLED) |
3710 |
node.id = wn->id; |
2878 |
break; |
3711 |
node.control = WPI_NODE_UPDATE; |
2879 |
DELAY(10); |
3712 |
node.flags = WPI_FLAG_KEY_SET; |
2880 |
} |
3713 |
|
2881 |
if (ntries == 100) { |
3714 |
DPRINTF(sc, WPI_DEBUG_KEY, "delete keys for node %d\n", node.id); |
2882 |
device_printf(sc->sc_dev, "timeout waiting for master\n"); |
3715 |
(void)wpi_cmd(sc, WPI_CMD_ADD_NODE, &node, sizeof node, 1); |
2883 |
} |
3716 |
|
|
|
3717 |
return 1; |
2884 |
} |
3718 |
} |
|
|
3719 |
#endif |
2885 |
|
3720 |
|
|
|
3721 |
/* |
3722 |
* This function is called after the runtime firmware notifies us of its |
3723 |
* readiness (called in a process context). |
3724 |
*/ |
2886 |
static int |
3725 |
static int |
2887 |
wpi_power_up(struct wpi_softc *sc) |
3726 |
wpi_post_alive(struct wpi_softc *sc) |
2888 |
{ |
3727 |
{ |
2889 |
uint32_t tmp; |
3728 |
int ntries, error; |
2890 |
int ntries; |
|
|
2891 |
|
3729 |
|
2892 |
wpi_mem_lock(sc); |
3730 |
/* Check (again) that the radio is not disabled. */ |
2893 |
tmp = wpi_mem_read(sc, WPI_MEM_POWER); |
3731 |
if ((error = wpi_nic_lock(sc)) != 0) |
2894 |
wpi_mem_write(sc, WPI_MEM_POWER, tmp & ~0x03000000); |
3732 |
return error; |
2895 |
wpi_mem_unlock(sc); |
|
|
2896 |
|
3733 |
|
2897 |
for (ntries = 0; ntries < 5000; ntries++) { |
3734 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__); |
2898 |
if (WPI_READ(sc, WPI_GPIO_STATUS) & WPI_POWERED) |
3735 |
|
|
|
3736 |
/* NB: Runtime firmware must be up and running. */ |
3737 |
if (!(wpi_prph_read(sc, WPI_APMG_RFKILL) & 1)) { |
3738 |
device_printf(sc->sc_dev, |
3739 |
"RF switch: radio disabled (%s)\n", __func__); |
3740 |
wpi_nic_unlock(sc); |
3741 |
return EPERM; /* :-) */ |
3742 |
} |
3743 |
wpi_nic_unlock(sc); |
3744 |
|
3745 |
/* Wait for thermal sensor to calibrate. */ |
3746 |
for (ntries = 0; ntries < 1000; ntries++) { |
3747 |
if ((sc->temp = (int)WPI_READ(sc, WPI_UCODE_GP2)) != 0) |
2899 |
break; |
3748 |
break; |
2900 |
DELAY(10); |
3749 |
DELAY(10); |
2901 |
} |
3750 |
} |
2902 |
if (ntries == 5000) { |
3751 |
|
|
|
3752 |
if (ntries == 1000) { |
2903 |
device_printf(sc->sc_dev, |
3753 |
device_printf(sc->sc_dev, |
2904 |
"timeout waiting for NIC to power up\n"); |
3754 |
"timeout waiting for thermal sensor calibration\n"); |
2905 |
return ETIMEDOUT; |
3755 |
return ETIMEDOUT; |
2906 |
} |
3756 |
} |
2907 |
return 0; |
3757 |
|
|
|
3758 |
DPRINTF(sc, WPI_DEBUG_TEMP, "temperature %d\n", sc->temp); |
3759 |
return 0; |
2908 |
} |
3760 |
} |
2909 |
|
3761 |
|
|
|
3762 |
/* |
3763 |
* The firmware boot code is small and is intended to be copied directly into |
3764 |
* the NIC internal memory (no DMA transfer). |
3765 |
*/ |
2910 |
static int |
3766 |
static int |
2911 |
wpi_reset(struct wpi_softc *sc) |
3767 |
wpi_load_bootcode(struct wpi_softc *sc, const uint8_t *ucode, int size) |
2912 |
{ |
3768 |
{ |
2913 |
uint32_t tmp; |
3769 |
int error, ntries; |
2914 |
int ntries; |
|
|
2915 |
|
3770 |
|
2916 |
DPRINTFN(WPI_DEBUG_HW, |
3771 |
DPRINTF(sc, WPI_DEBUG_HW, "Loading microcode size 0x%x\n", size); |
2917 |
("Resetting the card - clearing any uploaded firmware\n")); |
|
|
2918 |
|
3772 |
|
2919 |
/* clear any pending interrupts */ |
3773 |
size /= sizeof (uint32_t); |
2920 |
WPI_WRITE(sc, WPI_INTR, 0xffffffff); |
|
|
2921 |
|
3774 |
|
2922 |
tmp = WPI_READ(sc, WPI_PLL_CTL); |
3775 |
if ((error = wpi_nic_lock(sc)) != 0) |
2923 |
WPI_WRITE(sc, WPI_PLL_CTL, tmp | WPI_PLL_INIT); |
3776 |
return error; |
2924 |
|
3777 |
|
2925 |
tmp = WPI_READ(sc, WPI_CHICKEN); |
3778 |
/* Copy microcode image into NIC memory. */ |
2926 |
WPI_WRITE(sc, WPI_CHICKEN, tmp | WPI_CHICKEN_RXNOLOS); |
3779 |
wpi_prph_write_region_4(sc, WPI_BSM_SRAM_BASE, |
|
|
3780 |
(const uint32_t *)ucode, size); |
2927 |
|
3781 |
|
2928 |
tmp = WPI_READ(sc, WPI_GPIO_CTL); |
3782 |
wpi_prph_write(sc, WPI_BSM_WR_MEM_SRC, 0); |
2929 |
WPI_WRITE(sc, WPI_GPIO_CTL, tmp | WPI_GPIO_INIT); |
3783 |
wpi_prph_write(sc, WPI_BSM_WR_MEM_DST, WPI_FW_TEXT_BASE); |
|
|
3784 |
wpi_prph_write(sc, WPI_BSM_WR_DWCOUNT, size); |
2930 |
|
3785 |
|
2931 |
/* wait for clock stabilization */ |
3786 |
/* Start boot load now. */ |
2932 |
for (ntries = 0; ntries < 25000; ntries++) { |
3787 |
wpi_prph_write(sc, WPI_BSM_WR_CTRL, WPI_BSM_WR_CTRL_START); |
2933 |
if (WPI_READ(sc, WPI_GPIO_CTL) & WPI_GPIO_CLOCK) |
3788 |
|
|
|
3789 |
/* Wait for transfer to complete. */ |
3790 |
for (ntries = 0; ntries < 1000; ntries++) { |
3791 |
uint32_t status = WPI_READ(sc, WPI_FH_TX_STATUS); |
3792 |
DPRINTF(sc, WPI_DEBUG_HW, |
3793 |
"firmware status=0x%x, val=0x%x, result=0x%x\n", status, |
3794 |
WPI_FH_TX_STATUS_IDLE(6), |
3795 |
status & WPI_FH_TX_STATUS_IDLE(6)); |
3796 |
if (status & WPI_FH_TX_STATUS_IDLE(6)) { |
3797 |
DPRINTF(sc, WPI_DEBUG_HW, |
3798 |
"Status Match! - ntries = %d\n", ntries); |
2934 |
break; |
3799 |
break; |
|
|
3800 |
} |
2935 |
DELAY(10); |
3801 |
DELAY(10); |
2936 |
} |
3802 |
} |
2937 |
if (ntries == 25000) { |
3803 |
if (ntries == 1000) { |
2938 |
device_printf(sc->sc_dev, |
3804 |
device_printf(sc->sc_dev, "%s: could not load boot firmware\n", |
2939 |
"timeout waiting for clock stabilization\n"); |
3805 |
__func__); |
|
|
3806 |
wpi_nic_unlock(sc); |
2940 |
return ETIMEDOUT; |
3807 |
return ETIMEDOUT; |
2941 |
} |
3808 |
} |
2942 |
|
3809 |
|
2943 |
/* initialize EEPROM */ |
3810 |
/* Enable boot after power up. */ |
2944 |
tmp = WPI_READ(sc, WPI_EEPROM_STATUS); |
3811 |
wpi_prph_write(sc, WPI_BSM_WR_CTRL, WPI_BSM_WR_CTRL_START_EN); |
2945 |
|
3812 |
|
2946 |
if ((tmp & WPI_EEPROM_VERSION) == 0) { |
3813 |
wpi_nic_unlock(sc); |
2947 |
device_printf(sc->sc_dev, "EEPROM not found\n"); |
|
|
2948 |
return EIO; |
2949 |
} |
2950 |
WPI_WRITE(sc, WPI_EEPROM_STATUS, tmp & ~WPI_EEPROM_LOCKED); |
2951 |
|
2952 |
return 0; |
3814 |
return 0; |
2953 |
} |
3815 |
} |
2954 |
|
3816 |
|
2955 |
static void |
3817 |
static int |
2956 |
wpi_hw_config(struct wpi_softc *sc) |
3818 |
wpi_load_firmware(struct wpi_softc *sc) |
2957 |
{ |
3819 |
{ |
2958 |
uint32_t rev, hw; |
3820 |
struct wpi_fw_info *fw = &sc->fw; |
|
|
3821 |
struct wpi_dma_info *dma = &sc->fw_dma; |
3822 |
int error; |
2959 |
|
3823 |
|
2960 |
/* voodoo from the Linux "driver".. */ |
3824 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__); |
2961 |
hw = WPI_READ(sc, WPI_HWCONFIG); |
|
|
2962 |
|
3825 |
|
2963 |
rev = pci_read_config(sc->sc_dev, PCIR_REVID, 1); |
3826 |
/* Copy initialization sections into pre-allocated DMA-safe memory. */ |
2964 |
if ((rev & 0xc0) == 0x40) |
3827 |
memcpy(dma->vaddr, fw->init.data, fw->init.datasz); |
2965 |
hw |= WPI_HW_ALM_MB; |
3828 |
bus_dmamap_sync(dma->tag, dma->map, BUS_DMASYNC_PREWRITE); |
2966 |
else if (!(rev & 0x80)) |
3829 |
memcpy(dma->vaddr + WPI_FW_DATA_MAXSZ, fw->init.text, fw->init.textsz); |
2967 |
hw |= WPI_HW_ALM_MM; |
3830 |
bus_dmamap_sync(dma->tag, dma->map, BUS_DMASYNC_PREWRITE); |
2968 |
|
3831 |
|
2969 |
if (sc->cap == 0x80) |
3832 |
/* Tell adapter where to find initialization sections. */ |
2970 |
hw |= WPI_HW_SKU_MRC; |
3833 |
if ((error = wpi_nic_lock(sc)) != 0) |
|
|
3834 |
return error; |
3835 |
wpi_prph_write(sc, WPI_BSM_DRAM_DATA_ADDR, dma->paddr); |
3836 |
wpi_prph_write(sc, WPI_BSM_DRAM_DATA_SIZE, fw->init.datasz); |
3837 |
wpi_prph_write(sc, WPI_BSM_DRAM_TEXT_ADDR, |
3838 |
dma->paddr + WPI_FW_DATA_MAXSZ); |
3839 |
wpi_prph_write(sc, WPI_BSM_DRAM_TEXT_SIZE, fw->init.textsz); |
3840 |
wpi_nic_unlock(sc); |
2971 |
|
3841 |
|
2972 |
hw &= ~WPI_HW_REV_D; |
3842 |
/* Load firmware boot code. */ |
2973 |
if ((le16toh(sc->rev) & 0xf0) == 0xd0) |
3843 |
error = wpi_load_bootcode(sc, fw->boot.text, fw->boot.textsz); |
2974 |
hw |= WPI_HW_REV_D; |
3844 |
if (error != 0) { |
|
|
3845 |
device_printf(sc->sc_dev, "%s: could not load boot firmware\n", |
3846 |
__func__); |
3847 |
return error; |
3848 |
} |
2975 |
|
3849 |
|
2976 |
if (sc->type > 1) |
3850 |
/* Now press "execute". */ |
2977 |
hw |= WPI_HW_TYPE_B; |
3851 |
WPI_WRITE(sc, WPI_RESET, 0); |
2978 |
|
3852 |
|
2979 |
WPI_WRITE(sc, WPI_HWCONFIG, hw); |
3853 |
/* Wait at most one second for first alive notification. */ |
2980 |
} |
3854 |
if ((error = msleep(sc, &sc->sc_mtx, PCATCH, "wpiinit", hz)) != 0) { |
2981 |
|
|
|
2982 |
static void |
2983 |
wpi_rfkill_resume(struct wpi_softc *sc) |
2984 |
{ |
2985 |
struct ifnet *ifp = sc->sc_ifp; |
2986 |
struct ieee80211com *ic = ifp->if_l2com; |
2987 |
struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); |
2988 |
int ntries; |
2989 |
|
2990 |
/* enable firmware again */ |
2991 |
WPI_WRITE(sc, WPI_UCODE_CLR, WPI_RADIO_OFF); |
2992 |
WPI_WRITE(sc, WPI_UCODE_CLR, WPI_DISABLE_CMD); |
2993 |
|
2994 |
/* wait for thermal sensors to calibrate */ |
2995 |
for (ntries = 0; ntries < 1000; ntries++) { |
2996 |
if ((sc->temp = (int)WPI_READ(sc, WPI_TEMPERATURE)) != 0) |
2997 |
break; |
2998 |
DELAY(10); |
2999 |
} |
3000 |
|
3001 |
if (ntries == 1000) { |
3002 |
device_printf(sc->sc_dev, |
3855 |
device_printf(sc->sc_dev, |
3003 |
"timeout waiting for thermal calibration\n"); |
3856 |
"%s: timeout waiting for adapter to initialize, error %d\n", |
3004 |
return; |
3857 |
__func__, error); |
|
|
3858 |
return error; |
3005 |
} |
3859 |
} |
3006 |
DPRINTFN(WPI_DEBUG_TEMP,("temperature %d\n", sc->temp)); |
|
|
3007 |
|
3860 |
|
3008 |
if (wpi_config(sc) != 0) { |
3861 |
/* Copy runtime sections into pre-allocated DMA-safe memory. */ |
3009 |
device_printf(sc->sc_dev, "device config failed\n"); |
3862 |
memcpy(dma->vaddr, fw->main.data, fw->main.datasz); |
3010 |
return; |
3863 |
bus_dmamap_sync(dma->tag, dma->map, BUS_DMASYNC_PREWRITE); |
3011 |
} |
3864 |
memcpy(dma->vaddr + WPI_FW_DATA_MAXSZ, fw->main.text, fw->main.textsz); |
|
|
3865 |
bus_dmamap_sync(dma->tag, dma->map, BUS_DMASYNC_PREWRITE); |
3012 |
|
3866 |
|
3013 |
ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; |
3867 |
/* Tell adapter where to find runtime sections. */ |
3014 |
ifp->if_drv_flags |= IFF_DRV_RUNNING; |
3868 |
if ((error = wpi_nic_lock(sc)) != 0) |
3015 |
sc->flags &= ~WPI_FLAG_HW_RADIO_OFF; |
3869 |
return error; |
|
|
3870 |
wpi_prph_write(sc, WPI_BSM_DRAM_DATA_ADDR, dma->paddr); |
3871 |
wpi_prph_write(sc, WPI_BSM_DRAM_DATA_SIZE, fw->main.datasz); |
3872 |
wpi_prph_write(sc, WPI_BSM_DRAM_TEXT_ADDR, |
3873 |
dma->paddr + WPI_FW_DATA_MAXSZ); |
3874 |
wpi_prph_write(sc, WPI_BSM_DRAM_TEXT_SIZE, |
3875 |
WPI_FW_UPDATED | fw->main.textsz); |
3876 |
wpi_nic_unlock(sc); |
3016 |
|
3877 |
|
3017 |
if (vap != NULL) { |
3878 |
return 0; |
3018 |
if ((ic->ic_flags & IEEE80211_F_SCAN) == 0) { |
|
|
3019 |
if (vap->iv_opmode != IEEE80211_M_MONITOR) { |
3020 |
ieee80211_beacon_miss(ic); |
3021 |
wpi_set_led(sc, WPI_LED_LINK, 0, 1); |
3022 |
} else |
3023 |
wpi_set_led(sc, WPI_LED_LINK, 5, 5); |
3024 |
} else { |
3025 |
ieee80211_scan_next(vap); |
3026 |
wpi_set_led(sc, WPI_LED_LINK, 20, 2); |
3027 |
} |
3028 |
} |
3029 |
|
3030 |
callout_reset(&sc->watchdog_to, hz, wpi_watchdog, sc); |
3031 |
} |
3879 |
} |
3032 |
|
3880 |
|
3033 |
static void |
3881 |
static int |
3034 |
wpi_init_locked(struct wpi_softc *sc, int force) |
3882 |
wpi_read_firmware(struct wpi_softc *sc) |
3035 |
{ |
3883 |
{ |
3036 |
struct ifnet *ifp = sc->sc_ifp; |
3884 |
const struct firmware *fp; |
3037 |
uint32_t tmp; |
3885 |
struct wpi_fw_info *fw = &sc->fw; |
3038 |
int ntries, qid; |
3886 |
const struct wpi_firmware_hdr *hdr; |
|
|
3887 |
int error; |
3039 |
|
3888 |
|
3040 |
wpi_stop_locked(sc); |
3889 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__); |
3041 |
(void)wpi_reset(sc); |
|
|
3042 |
|
3890 |
|
3043 |
wpi_mem_lock(sc); |
3891 |
DPRINTF(sc, WPI_DEBUG_FIRMWARE, |
3044 |
wpi_mem_write(sc, WPI_MEM_CLOCK1, 0xa00); |
3892 |
"Attempting Loading Firmware from %s module\n", WPI_FW_NAME); |
3045 |
DELAY(20); |
|
|
3046 |
tmp = wpi_mem_read(sc, WPI_MEM_PCIDEV); |
3047 |
wpi_mem_write(sc, WPI_MEM_PCIDEV, tmp | 0x800); |
3048 |
wpi_mem_unlock(sc); |
3049 |
|
3893 |
|
3050 |
(void)wpi_power_up(sc); |
3894 |
WPI_UNLOCK(sc); |
3051 |
wpi_hw_config(sc); |
3895 |
fp = firmware_get(WPI_FW_NAME); |
|
|
3896 |
WPI_LOCK(sc); |
3052 |
|
3897 |
|
3053 |
/* init Rx ring */ |
3898 |
if (fp == NULL) { |
3054 |
wpi_mem_lock(sc); |
3899 |
device_printf(sc->sc_dev, |
3055 |
WPI_WRITE(sc, WPI_RX_BASE, sc->rxq.desc_dma.paddr); |
3900 |
"could not load firmware image '%s'\n", WPI_FW_NAME); |
3056 |
WPI_WRITE(sc, WPI_RX_RIDX_PTR, sc->shared_dma.paddr + |
3901 |
return EINVAL; |
3057 |
offsetof(struct wpi_shared, next)); |
3902 |
} |
3058 |
WPI_WRITE(sc, WPI_RX_WIDX, (WPI_RX_RING_COUNT - 1) & ~7); |
|
|
3059 |
WPI_WRITE(sc, WPI_RX_CONFIG, 0xa9601010); |
3060 |
wpi_mem_unlock(sc); |
3061 |
|
3903 |
|
3062 |
/* init Tx rings */ |
3904 |
sc->fw_fp = fp; |
3063 |
wpi_mem_lock(sc); |
|
|
3064 |
wpi_mem_write(sc, WPI_MEM_MODE, 2); /* bypass mode */ |
3065 |
wpi_mem_write(sc, WPI_MEM_RA, 1); /* enable RA0 */ |
3066 |
wpi_mem_write(sc, WPI_MEM_TXCFG, 0x3f); /* enable all 6 Tx rings */ |
3067 |
wpi_mem_write(sc, WPI_MEM_BYPASS1, 0x10000); |
3068 |
wpi_mem_write(sc, WPI_MEM_BYPASS2, 0x30002); |
3069 |
wpi_mem_write(sc, WPI_MEM_MAGIC4, 4); |
3070 |
wpi_mem_write(sc, WPI_MEM_MAGIC5, 5); |
3071 |
|
3905 |
|
3072 |
WPI_WRITE(sc, WPI_TX_BASE_PTR, sc->shared_dma.paddr); |
3906 |
if (fp->datasize < sizeof (struct wpi_firmware_hdr)) { |
3073 |
WPI_WRITE(sc, WPI_MSG_CONFIG, 0xffff05a5); |
3907 |
device_printf(sc->sc_dev, |
3074 |
|
3908 |
"firmware file too short: %zu bytes\n", fp->datasize); |
3075 |
for (qid = 0; qid < 6; qid++) { |
3909 |
error = EINVAL; |
3076 |
WPI_WRITE(sc, WPI_TX_CTL(qid), 0); |
3910 |
goto fail; |
3077 |
WPI_WRITE(sc, WPI_TX_BASE(qid), 0); |
|
|
3078 |
WPI_WRITE(sc, WPI_TX_CONFIG(qid), 0x80200008); |
3079 |
} |
3911 |
} |
3080 |
wpi_mem_unlock(sc); |
|
|
3081 |
|
3912 |
|
3082 |
/* clear "radio off" and "disable command" bits (reversed logic) */ |
3913 |
fw->size = fp->datasize; |
3083 |
WPI_WRITE(sc, WPI_UCODE_CLR, WPI_RADIO_OFF); |
3914 |
fw->data = (const uint8_t *)fp->data; |
3084 |
WPI_WRITE(sc, WPI_UCODE_CLR, WPI_DISABLE_CMD); |
|
|
3085 |
sc->flags &= ~WPI_FLAG_HW_RADIO_OFF; |
3086 |
|
3915 |
|
3087 |
/* clear any pending interrupts */ |
3916 |
/* Extract firmware header information. */ |
3088 |
WPI_WRITE(sc, WPI_INTR, 0xffffffff); |
3917 |
hdr = (const struct wpi_firmware_hdr *)fw->data; |
3089 |
|
3918 |
|
3090 |
/* enable interrupts */ |
3919 |
/* | RUNTIME FIRMWARE | INIT FIRMWARE | BOOT FW | |
3091 |
WPI_WRITE(sc, WPI_MASK, WPI_INTR_MASK); |
3920 |
|HDR|<--TEXT-->|<--DATA-->|<--TEXT-->|<--DATA-->|<--TEXT-->| */ |
3092 |
|
3921 |
|
3093 |
WPI_WRITE(sc, WPI_UCODE_CLR, WPI_RADIO_OFF); |
3922 |
fw->main.textsz = le32toh(hdr->rtextsz); |
3094 |
WPI_WRITE(sc, WPI_UCODE_CLR, WPI_RADIO_OFF); |
3923 |
fw->main.datasz = le32toh(hdr->rdatasz); |
|
|
3924 |
fw->init.textsz = le32toh(hdr->itextsz); |
3925 |
fw->init.datasz = le32toh(hdr->idatasz); |
3926 |
fw->boot.textsz = le32toh(hdr->btextsz); |
3927 |
fw->boot.datasz = 0; |
3095 |
|
3928 |
|
3096 |
if ((wpi_load_firmware(sc)) != 0) { |
3929 |
/* Sanity-check firmware header. */ |
3097 |
device_printf(sc->sc_dev, |
3930 |
if (fw->main.textsz > WPI_FW_TEXT_MAXSZ || |
3098 |
"A problem occurred loading the firmware to the driver\n"); |
3931 |
fw->main.datasz > WPI_FW_DATA_MAXSZ || |
3099 |
return; |
3932 |
fw->init.textsz > WPI_FW_TEXT_MAXSZ || |
|
|
3933 |
fw->init.datasz > WPI_FW_DATA_MAXSZ || |
3934 |
fw->boot.textsz > WPI_FW_BOOT_TEXT_MAXSZ || |
3935 |
(fw->boot.textsz & 3) != 0) { |
3936 |
device_printf(sc->sc_dev, "invalid firmware header\n"); |
3937 |
error = EINVAL; |
3938 |
goto fail; |
3100 |
} |
3939 |
} |
3101 |
|
3940 |
|
3102 |
/* At this point the firmware is up and running. If the hardware |
3941 |
/* Check that all firmware sections fit. */ |
3103 |
* RF switch is turned off thermal calibration will fail, though |
3942 |
if (fw->size < sizeof (*hdr) + fw->main.textsz + fw->main.datasz + |
3104 |
* the card is still happy to continue to accept commands, catch |
3943 |
fw->init.textsz + fw->init.datasz + fw->boot.textsz) { |
3105 |
* this case and schedule a task to watch for it to be turned on. |
3944 |
device_printf(sc->sc_dev, |
3106 |
*/ |
3945 |
"firmware file too short: %zu bytes\n", fw->size); |
3107 |
wpi_mem_lock(sc); |
3946 |
error = EINVAL; |
3108 |
tmp = wpi_mem_read(sc, WPI_MEM_HW_RADIO_OFF); |
3947 |
goto fail; |
3109 |
wpi_mem_unlock(sc); |
|
|
3110 |
|
3111 |
if (!(tmp & 0x1)) { |
3112 |
sc->flags |= WPI_FLAG_HW_RADIO_OFF; |
3113 |
device_printf(sc->sc_dev,"Radio Transmitter is switched off\n"); |
3114 |
goto out; |
3115 |
} |
3948 |
} |
3116 |
|
3949 |
|
3117 |
/* wait for thermal sensors to calibrate */ |
3950 |
/* Get pointers to firmware sections. */ |
3118 |
for (ntries = 0; ntries < 1000; ntries++) { |
3951 |
fw->main.text = (const uint8_t *)(hdr + 1); |
3119 |
if ((sc->temp = (int)WPI_READ(sc, WPI_TEMPERATURE)) != 0) |
3952 |
fw->main.data = fw->main.text + fw->main.textsz; |
3120 |
break; |
3953 |
fw->init.text = fw->main.data + fw->main.datasz; |
3121 |
DELAY(10); |
3954 |
fw->init.data = fw->init.text + fw->init.textsz; |
3122 |
} |
3955 |
fw->boot.text = fw->init.data + fw->init.datasz; |
3123 |
|
3956 |
|
3124 |
if (ntries == 1000) { |
3957 |
DPRINTF(sc, WPI_DEBUG_FIRMWARE, |
3125 |
device_printf(sc->sc_dev, |
3958 |
"Firmware Version: Major %d, Minor %d, Driver %d, \n" |
3126 |
"timeout waiting for thermal sensors calibration\n"); |
3959 |
"runtime (text: %u, data: %u) init (text: %u, data %u) boot (text %u)\n", |
3127 |
return; |
3960 |
hdr->major, hdr->minor, le32toh(hdr->driver), |
3128 |
} |
3961 |
fw->main.textsz, fw->main.datasz, |
3129 |
DPRINTFN(WPI_DEBUG_TEMP,("temperature %d\n", sc->temp)); |
3962 |
fw->init.textsz, fw->init.datasz, fw->boot.textsz); |
3130 |
|
3963 |
|
3131 |
if (wpi_config(sc) != 0) { |
3964 |
DPRINTF(sc, WPI_DEBUG_FIRMWARE, "fw->main.text %p\n", fw->main.text); |
3132 |
device_printf(sc->sc_dev, "device config failed\n"); |
3965 |
DPRINTF(sc, WPI_DEBUG_FIRMWARE, "fw->main.data %p\n", fw->main.data); |
3133 |
return; |
3966 |
DPRINTF(sc, WPI_DEBUG_FIRMWARE, "fw->init.text %p\n", fw->init.text); |
3134 |
} |
3967 |
DPRINTF(sc, WPI_DEBUG_FIRMWARE, "fw->init.data %p\n", fw->init.data); |
|
|
3968 |
DPRINTF(sc, WPI_DEBUG_FIRMWARE, "fw->boot.text %p\n", fw->boot.text); |
3135 |
|
3969 |
|
3136 |
ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; |
3970 |
return 0; |
3137 |
ifp->if_drv_flags |= IFF_DRV_RUNNING; |
3971 |
|
3138 |
out: |
3972 |
fail: wpi_unload_firmware(sc); |
3139 |
callout_reset(&sc->watchdog_to, hz, wpi_watchdog, sc); |
3973 |
return error; |
3140 |
} |
3974 |
} |
3141 |
|
3975 |
|
|
|
3976 |
/** |
3977 |
* Free the referenced firmware image |
3978 |
*/ |
3142 |
static void |
3979 |
static void |
3143 |
wpi_init(void *arg) |
3980 |
wpi_unload_firmware(struct wpi_softc *sc) |
3144 |
{ |
3981 |
{ |
3145 |
struct wpi_softc *sc = arg; |
3982 |
if (sc->fw_fp != NULL) { |
3146 |
struct ifnet *ifp = sc->sc_ifp; |
3983 |
firmware_put(sc->fw_fp, FIRMWARE_UNLOAD); |
3147 |
struct ieee80211com *ic = ifp->if_l2com; |
3984 |
sc->fw_fp = NULL; |
|
|
3985 |
} |
3986 |
} |
3148 |
|
3987 |
|
3149 |
WPI_LOCK(sc); |
3988 |
static int |
3150 |
wpi_init_locked(sc, 0); |
3989 |
wpi_clock_wait(struct wpi_softc *sc) |
3151 |
WPI_UNLOCK(sc); |
3990 |
{ |
|
|
3991 |
int ntries; |
3152 |
|
3992 |
|
3153 |
if (ifp->if_drv_flags & IFF_DRV_RUNNING) |
3993 |
/* Set "initialization complete" bit. */ |
3154 |
ieee80211_start_all(ic); /* start all vaps */ |
3994 |
WPI_SETBITS(sc, WPI_GP_CNTRL, WPI_GP_CNTRL_INIT_DONE); |
|
|
3995 |
|
3996 |
/* Wait for clock stabilization. */ |
3997 |
for (ntries = 0; ntries < 2500; ntries++) { |
3998 |
if (WPI_READ(sc, WPI_GP_CNTRL) & WPI_GP_CNTRL_MAC_CLOCK_READY) |
3999 |
return 0; |
4000 |
DELAY(100); |
4001 |
} |
4002 |
device_printf(sc->sc_dev, |
4003 |
"%s: timeout waiting for clock stabilization\n", __func__); |
4004 |
|
4005 |
return ETIMEDOUT; |
3155 |
} |
4006 |
} |
3156 |
|
4007 |
|
3157 |
static void |
4008 |
static int |
3158 |
wpi_stop_locked(struct wpi_softc *sc) |
4009 |
wpi_apm_init(struct wpi_softc *sc) |
3159 |
{ |
4010 |
{ |
3160 |
struct ifnet *ifp = sc->sc_ifp; |
4011 |
uint32_t reg; |
3161 |
uint32_t tmp; |
4012 |
int error; |
3162 |
int ac; |
|
|
3163 |
|
4013 |
|
3164 |
sc->sc_tx_timer = 0; |
4014 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__); |
3165 |
sc->sc_scan_timer = 0; |
|
|
3166 |
ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE); |
3167 |
sc->flags &= ~WPI_FLAG_HW_RADIO_OFF; |
3168 |
callout_stop(&sc->watchdog_to); |
3169 |
callout_stop(&sc->calib_to); |
3170 |
|
4015 |
|
3171 |
/* disable interrupts */ |
4016 |
/* Disable L0s exit timer (NMI bug workaround). */ |
3172 |
WPI_WRITE(sc, WPI_MASK, 0); |
4017 |
WPI_SETBITS(sc, WPI_GIO_CHICKEN, WPI_GIO_CHICKEN_DIS_L0S_TIMER); |
3173 |
WPI_WRITE(sc, WPI_INTR, WPI_INTR_MASK); |
4018 |
/* Don't wait for ICH L0s (ICH bug workaround). */ |
3174 |
WPI_WRITE(sc, WPI_INTR_STATUS, 0xff); |
4019 |
WPI_SETBITS(sc, WPI_GIO_CHICKEN, WPI_GIO_CHICKEN_L1A_NO_L0S_RX); |
3175 |
WPI_WRITE(sc, WPI_INTR_STATUS, 0x00070000); |
|
|
3176 |
|
4020 |
|
3177 |
wpi_mem_lock(sc); |
4021 |
/* Set FH wait threshold to max (HW bug under stress workaround). */ |
3178 |
wpi_mem_write(sc, WPI_MEM_MODE, 0); |
4022 |
WPI_SETBITS(sc, WPI_DBG_HPET_MEM, 0xffff0000); |
3179 |
wpi_mem_unlock(sc); |
|
|
3180 |
|
4023 |
|
3181 |
/* reset all Tx rings */ |
4024 |
/* Retrieve PCIe Active State Power Management (ASPM). */ |
3182 |
for (ac = 0; ac < 4; ac++) |
4025 |
reg = pci_read_config(sc->sc_dev, sc->sc_cap_off + 0x10, 1); |
3183 |
wpi_reset_tx_ring(sc, &sc->txq[ac]); |
4026 |
/* Workaround for HW instability in PCIe L0->L0s->L1 transition. */ |
3184 |
wpi_reset_tx_ring(sc, &sc->cmdq); |
4027 |
if (reg & 0x02) /* L1 Entry enabled. */ |
|
|
4028 |
WPI_SETBITS(sc, WPI_GIO, WPI_GIO_L0S_ENA); |
4029 |
else |
4030 |
WPI_CLRBITS(sc, WPI_GIO, WPI_GIO_L0S_ENA); |
3185 |
|
4031 |
|
3186 |
/* reset Rx ring */ |
4032 |
WPI_SETBITS(sc, WPI_ANA_PLL, WPI_ANA_PLL_INIT); |
3187 |
wpi_reset_rx_ring(sc, &sc->rxq); |
|
|
3188 |
|
4033 |
|
3189 |
wpi_mem_lock(sc); |
4034 |
/* Wait for clock stabilization before accessing prph. */ |
3190 |
wpi_mem_write(sc, WPI_MEM_CLOCK2, 0x200); |
4035 |
if ((error = wpi_clock_wait(sc)) != 0) |
3191 |
wpi_mem_unlock(sc); |
4036 |
return error; |
3192 |
|
4037 |
|
3193 |
DELAY(5); |
4038 |
if ((error = wpi_nic_lock(sc)) != 0) |
|
|
4039 |
return error; |
4040 |
/* Enable DMA and BSM (Bootstrap State Machine). */ |
4041 |
wpi_prph_write(sc, WPI_APMG_CLK_EN, |
4042 |
WPI_APMG_CLK_CTRL_DMA_CLK_RQT | WPI_APMG_CLK_CTRL_BSM_CLK_RQT); |
4043 |
DELAY(20); |
4044 |
/* Disable L1-Active. */ |
4045 |
wpi_prph_setbits(sc, WPI_APMG_PCI_STT, WPI_APMG_PCI_STT_L1A_DIS); |
4046 |
wpi_nic_unlock(sc); |
3194 |
|
4047 |
|
3195 |
wpi_stop_master(sc); |
4048 |
return 0; |
|
|
4049 |
} |
3196 |
|
4050 |
|
3197 |
tmp = WPI_READ(sc, WPI_RESET); |
4051 |
static void |
3198 |
WPI_WRITE(sc, WPI_RESET, tmp | WPI_SW_RESET); |
4052 |
wpi_apm_stop_master(struct wpi_softc *sc) |
3199 |
sc->flags &= ~WPI_FLAG_BUSY; |
4053 |
{ |
|
|
4054 |
int ntries; |
4055 |
|
4056 |
/* Stop busmaster DMA activity. */ |
4057 |
WPI_SETBITS(sc, WPI_RESET, WPI_RESET_STOP_MASTER); |
4058 |
|
4059 |
if ((WPI_READ(sc, WPI_GP_CNTRL) & WPI_GP_CNTRL_PS_MASK) == |
4060 |
WPI_GP_CNTRL_MAC_PS) |
4061 |
return; /* Already asleep. */ |
4062 |
|
4063 |
for (ntries = 0; ntries < 100; ntries++) { |
4064 |
if (WPI_READ(sc, WPI_RESET) & WPI_RESET_MASTER_DISABLED) |
4065 |
return; |
4066 |
DELAY(10); |
4067 |
} |
4068 |
device_printf(sc->sc_dev, "%s: timeout waiting for master\n", __func__); |
3200 |
} |
4069 |
} |
3201 |
|
4070 |
|
3202 |
static void |
4071 |
static void |
3203 |
wpi_stop(struct wpi_softc *sc) |
4072 |
wpi_apm_stop(struct wpi_softc *sc) |
3204 |
{ |
4073 |
{ |
3205 |
WPI_LOCK(sc); |
4074 |
wpi_apm_stop_master(sc); |
3206 |
wpi_stop_locked(sc); |
4075 |
|
3207 |
WPI_UNLOCK(sc); |
4076 |
/* Reset the entire device. */ |
|
|
4077 |
WPI_SETBITS(sc, WPI_RESET, WPI_RESET_SW); |
4078 |
DELAY(10); |
4079 |
/* Clear "initialization complete" bit. */ |
4080 |
WPI_CLRBITS(sc, WPI_GP_CNTRL, WPI_GP_CNTRL_INIT_DONE); |
3208 |
} |
4081 |
} |
3209 |
|
4082 |
|
3210 |
static void |
4083 |
static void |
3211 |
wpi_calib_timeout(void *arg) |
4084 |
wpi_nic_config(struct wpi_softc *sc) |
3212 |
{ |
4085 |
{ |
3213 |
struct wpi_softc *sc = arg; |
4086 |
uint32_t rev; |
3214 |
struct ifnet *ifp = sc->sc_ifp; |
|
|
3215 |
struct ieee80211com *ic = ifp->if_l2com; |
3216 |
struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); |
3217 |
int temp; |
3218 |
|
4087 |
|
3219 |
if (vap->iv_state != IEEE80211_S_RUN) |
4088 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__); |
3220 |
return; |
|
|
3221 |
|
4089 |
|
3222 |
/* update sensor data */ |
4090 |
/* voodoo from the Linux "driver".. */ |
3223 |
temp = (int)WPI_READ(sc, WPI_TEMPERATURE); |
4091 |
rev = pci_read_config(sc->sc_dev, PCIR_REVID, 1); |
3224 |
DPRINTFN(WPI_DEBUG_TEMP,("Temp in calibration is: %d\n", temp)); |
4092 |
if ((rev & 0xc0) == 0x40) |
|
|
4093 |
WPI_SETBITS(sc, WPI_HW_IF_CONFIG, WPI_HW_IF_CONFIG_ALM_MB); |
4094 |
else if (!(rev & 0x80)) |
4095 |
WPI_SETBITS(sc, WPI_HW_IF_CONFIG, WPI_HW_IF_CONFIG_ALM_MM); |
3225 |
|
4096 |
|
3226 |
wpi_power_calibration(sc, temp); |
4097 |
if (sc->cap == 0x80) |
|
|
4098 |
WPI_SETBITS(sc, WPI_HW_IF_CONFIG, WPI_HW_IF_CONFIG_SKU_MRC); |
3227 |
|
4099 |
|
3228 |
callout_reset(&sc->calib_to, 60*hz, wpi_calib_timeout, sc); |
4100 |
if ((le16toh(sc->rev) & 0xf0) == 0xd0) |
|
|
4101 |
WPI_SETBITS(sc, WPI_HW_IF_CONFIG, WPI_HW_IF_CONFIG_REV_D); |
4102 |
else |
4103 |
WPI_CLRBITS(sc, WPI_HW_IF_CONFIG, WPI_HW_IF_CONFIG_REV_D); |
4104 |
|
4105 |
if (sc->type > 1) |
4106 |
WPI_SETBITS(sc, WPI_HW_IF_CONFIG, WPI_HW_IF_CONFIG_TYPE_B); |
3229 |
} |
4107 |
} |
3230 |
|
4108 |
|
3231 |
/* |
4109 |
static int |
3232 |
* This function is called periodically (every 60 seconds) to adjust output |
4110 |
wpi_hw_init(struct wpi_softc *sc) |
3233 |
* power to temperature changes. |
|
|
3234 |
*/ |
3235 |
static void |
3236 |
wpi_power_calibration(struct wpi_softc *sc, int temp) |
3237 |
{ |
4111 |
{ |
3238 |
struct ifnet *ifp = sc->sc_ifp; |
4112 |
int chnl, ntries, error; |
3239 |
struct ieee80211com *ic = ifp->if_l2com; |
|
|
3240 |
struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); |
3241 |
|
4113 |
|
3242 |
/* sanity-check read value */ |
4114 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__); |
3243 |
if (temp < -260 || temp > 25) { |
4115 |
|
3244 |
/* this can't be correct, ignore */ |
4116 |
/* Clear pending interrupts. */ |
3245 |
DPRINTFN(WPI_DEBUG_TEMP, |
4117 |
WPI_WRITE(sc, WPI_INT, 0xffffffff); |
3246 |
("out-of-range temperature reported: %d\n", temp)); |
4118 |
|
3247 |
return; |
4119 |
if ((error = wpi_apm_init(sc)) != 0) { |
|
|
4120 |
device_printf(sc->sc_dev, |
4121 |
"%s: could not power ON adapter, error %d\n", __func__, |
4122 |
error); |
4123 |
return error; |
3248 |
} |
4124 |
} |
3249 |
|
4125 |
|
3250 |
DPRINTFN(WPI_DEBUG_TEMP,("temperature %d->%d\n", sc->temp, temp)); |
4126 |
/* Select VMAIN power source. */ |
|
|
4127 |
if ((error = wpi_nic_lock(sc)) != 0) |
4128 |
return error; |
4129 |
wpi_prph_clrbits(sc, WPI_APMG_PS, WPI_APMG_PS_PWR_SRC_MASK); |
4130 |
wpi_nic_unlock(sc); |
4131 |
/* Spin until VMAIN gets selected. */ |
4132 |
for (ntries = 0; ntries < 5000; ntries++) { |
4133 |
if (WPI_READ(sc, WPI_GPIO_IN) & WPI_GPIO_IN_VMAIN) |
4134 |
break; |
4135 |
DELAY(10); |
4136 |
} |
4137 |
if (ntries == 5000) { |
4138 |
device_printf(sc->sc_dev, "timeout selecting power source\n"); |
4139 |
return ETIMEDOUT; |
4140 |
} |
3251 |
|
4141 |
|
3252 |
/* adjust Tx power if need be */ |
4142 |
/* Perform adapter initialization. */ |
3253 |
if (abs(temp - sc->temp) <= 6) |
4143 |
wpi_nic_config(sc); |
3254 |
return; |
|
|
3255 |
|
4144 |
|
3256 |
sc->temp = temp; |
4145 |
/* Initialize RX ring. */ |
|
|
4146 |
if ((error = wpi_nic_lock(sc)) != 0) |
4147 |
return error; |
4148 |
/* Set physical address of RX ring. */ |
4149 |
WPI_WRITE(sc, WPI_FH_RX_BASE, sc->rxq.desc_dma.paddr); |
4150 |
/* Set physical address of RX read pointer. */ |
4151 |
WPI_WRITE(sc, WPI_FH_RX_RPTR_ADDR, sc->shared_dma.paddr + |
4152 |
offsetof(struct wpi_shared, next)); |
4153 |
WPI_WRITE(sc, WPI_FH_RX_WPTR, 0); |
4154 |
/* Enable RX. */ |
4155 |
WPI_WRITE(sc, WPI_FH_RX_CONFIG, |
4156 |
WPI_FH_RX_CONFIG_DMA_ENA | |
4157 |
WPI_FH_RX_CONFIG_RDRBD_ENA | |
4158 |
WPI_FH_RX_CONFIG_WRSTATUS_ENA | |
4159 |
WPI_FH_RX_CONFIG_MAXFRAG | |
4160 |
WPI_FH_RX_CONFIG_NRBD(WPI_RX_RING_COUNT_LOG) | |
4161 |
WPI_FH_RX_CONFIG_IRQ_DST_HOST | |
4162 |
WPI_FH_RX_CONFIG_IRQ_TIMEOUT(1)); |
4163 |
(void)WPI_READ(sc, WPI_FH_RSSR_TBL); /* barrier */ |
4164 |
wpi_nic_unlock(sc); |
4165 |
WPI_WRITE(sc, WPI_FH_RX_WPTR, (WPI_RX_RING_COUNT - 1) & ~7); |
3257 |
|
4166 |
|
3258 |
if (wpi_set_txpower(sc, vap->iv_bss->ni_chan, 1) != 0) { |
4167 |
/* Initialize TX rings. */ |
3259 |
/* just warn, too bad for the automatic calibration... */ |
4168 |
if ((error = wpi_nic_lock(sc)) != 0) |
3260 |
device_printf(sc->sc_dev,"could not adjust Tx power\n"); |
4169 |
return error; |
|
|
4170 |
wpi_prph_write(sc, WPI_ALM_SCHED_MODE, 2); /* bypass mode */ |
4171 |
wpi_prph_write(sc, WPI_ALM_SCHED_ARASTAT, 1); /* enable RA0 */ |
4172 |
/* Enable all 6 TX rings. */ |
4173 |
wpi_prph_write(sc, WPI_ALM_SCHED_TXFACT, 0x3f); |
4174 |
wpi_prph_write(sc, WPI_ALM_SCHED_SBYPASS_MODE1, 0x10000); |
4175 |
wpi_prph_write(sc, WPI_ALM_SCHED_SBYPASS_MODE2, 0x30002); |
4176 |
wpi_prph_write(sc, WPI_ALM_SCHED_TXF4MF, 4); |
4177 |
wpi_prph_write(sc, WPI_ALM_SCHED_TXF5MF, 5); |
4178 |
/* Set physical address of TX rings. */ |
4179 |
WPI_WRITE(sc, WPI_FH_TX_BASE, sc->shared_dma.paddr); |
4180 |
WPI_WRITE(sc, WPI_FH_MSG_CONFIG, 0xffff05a5); |
4181 |
|
4182 |
/* Enable all DMA channels. */ |
4183 |
for (chnl = 0; chnl < WPI_NDMACHNLS; chnl++) { |
4184 |
WPI_WRITE(sc, WPI_FH_CBBC_CTRL(chnl), 0); |
4185 |
WPI_WRITE(sc, WPI_FH_CBBC_BASE(chnl), 0); |
4186 |
WPI_WRITE(sc, WPI_FH_TX_CONFIG(chnl), 0x80200008); |
3261 |
} |
4187 |
} |
|
|
4188 |
wpi_nic_unlock(sc); |
4189 |
(void)WPI_READ(sc, WPI_FH_TX_BASE); /* barrier */ |
4190 |
|
4191 |
/* Clear "radio off" and "commands blocked" bits. */ |
4192 |
WPI_WRITE(sc, WPI_UCODE_GP1_CLR, WPI_UCODE_GP1_RFKILL); |
4193 |
WPI_WRITE(sc, WPI_UCODE_GP1_CLR, WPI_UCODE_GP1_CMD_BLOCKED); |
4194 |
|
4195 |
/* Clear pending interrupts. */ |
4196 |
WPI_WRITE(sc, WPI_INT, 0xffffffff); |
4197 |
/* Enable interrupts. */ |
4198 |
WPI_WRITE(sc, WPI_INT_MASK, WPI_INT_MASK_DEF); |
4199 |
|
4200 |
/* _Really_ make sure "radio off" bit is cleared! */ |
4201 |
WPI_WRITE(sc, WPI_UCODE_GP1_CLR, WPI_UCODE_GP1_RFKILL); |
4202 |
WPI_WRITE(sc, WPI_UCODE_GP1_CLR, WPI_UCODE_GP1_RFKILL); |
4203 |
|
4204 |
if ((error = wpi_load_firmware(sc)) != 0) { |
4205 |
device_printf(sc->sc_dev, |
4206 |
"%s: could not load firmware, error %d\n", __func__, |
4207 |
error); |
4208 |
return error; |
4209 |
} |
4210 |
/* Wait at most one second for firmware alive notification. */ |
4211 |
if ((error = msleep(sc, &sc->sc_mtx, PCATCH, "wpiinit", hz)) != 0) { |
4212 |
device_printf(sc->sc_dev, |
4213 |
"%s: timeout waiting for adapter to initialize, error %d\n", |
4214 |
__func__, error); |
4215 |
return error; |
4216 |
} |
4217 |
|
4218 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__); |
4219 |
|
4220 |
/* Do post-firmware initialization. */ |
4221 |
return wpi_post_alive(sc); |
3262 |
} |
4222 |
} |
3263 |
|
4223 |
|
3264 |
/** |
|
|
3265 |
* Read the eeprom to find out what channels are valid for the given |
3266 |
* band and update net80211 with what we find. |
3267 |
*/ |
3268 |
static void |
4224 |
static void |
3269 |
wpi_read_eeprom_channels(struct wpi_softc *sc, int n) |
4225 |
wpi_hw_stop(struct wpi_softc *sc) |
3270 |
{ |
4226 |
{ |
3271 |
struct ifnet *ifp = sc->sc_ifp; |
4227 |
int chnl, qid, ntries; |
3272 |
struct ieee80211com *ic = ifp->if_l2com; |
|
|
3273 |
const struct wpi_chan_band *band = &wpi_bands[n]; |
3274 |
struct wpi_eeprom_chan channels[WPI_MAX_CHAN_PER_BAND]; |
3275 |
struct ieee80211_channel *c; |
3276 |
int chan, i, passive; |
3277 |
|
4228 |
|
3278 |
wpi_read_prom_data(sc, band->addr, channels, |
4229 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__); |
3279 |
band->nchan * sizeof (struct wpi_eeprom_chan)); |
|
|
3280 |
|
4230 |
|
3281 |
for (i = 0; i < band->nchan; i++) { |
4231 |
if (WPI_READ(sc, WPI_UCODE_GP1) & WPI_UCODE_GP1_MAC_SLEEP) |
3282 |
if (!(channels[i].flags & WPI_EEPROM_CHAN_VALID)) { |
4232 |
wpi_nic_lock(sc); |
3283 |
DPRINTFN(WPI_DEBUG_HW, |
|
|
3284 |
("Channel Not Valid: %d, band %d\n", |
3285 |
band->chan[i],n)); |
3286 |
continue; |
3287 |
} |
3288 |
|
4233 |
|
3289 |
passive = 0; |
4234 |
WPI_WRITE(sc, WPI_RESET, WPI_RESET_NEVO); |
3290 |
chan = band->chan[i]; |
|
|
3291 |
c = &ic->ic_channels[ic->ic_nchans++]; |
3292 |
|
4235 |
|
3293 |
/* is active scan allowed on this channel? */ |
4236 |
/* Disable interrupts. */ |
3294 |
if (!(channels[i].flags & WPI_EEPROM_CHAN_ACTIVE)) { |
4237 |
WPI_WRITE(sc, WPI_INT_MASK, 0); |
3295 |
passive = IEEE80211_CHAN_PASSIVE; |
4238 |
WPI_WRITE(sc, WPI_INT, 0xffffffff); |
3296 |
} |
4239 |
WPI_WRITE(sc, WPI_FH_INT, 0xffffffff); |
3297 |
|
4240 |
|
3298 |
if (n == 0) { /* 2GHz band */ |
4241 |
/* Make sure we no longer hold the NIC lock. */ |
3299 |
c->ic_ieee = chan; |
4242 |
wpi_nic_unlock(sc); |
3300 |
c->ic_freq = ieee80211_ieee2mhz(chan, |
|
|
3301 |
IEEE80211_CHAN_2GHZ); |
3302 |
c->ic_flags = IEEE80211_CHAN_B | passive; |
3303 |
|
4243 |
|
3304 |
c = &ic->ic_channels[ic->ic_nchans++]; |
4244 |
if (wpi_nic_lock(sc) == 0) { |
3305 |
c->ic_ieee = chan; |
4245 |
/* Stop TX scheduler. */ |
3306 |
c->ic_freq = ieee80211_ieee2mhz(chan, |
4246 |
wpi_prph_write(sc, WPI_ALM_SCHED_MODE, 0); |
3307 |
IEEE80211_CHAN_2GHZ); |
4247 |
wpi_prph_write(sc, WPI_ALM_SCHED_TXFACT, 0); |
3308 |
c->ic_flags = IEEE80211_CHAN_G | passive; |
|
|
3309 |
|
4248 |
|
3310 |
} else { /* 5GHz band */ |
4249 |
/* Stop all DMA channels. */ |
3311 |
/* |
4250 |
for (chnl = 0; chnl < WPI_NDMACHNLS; chnl++) { |
3312 |
* Some 3945ABG adapters support channels 7, 8, 11 |
4251 |
WPI_WRITE(sc, WPI_FH_TX_CONFIG(chnl), 0); |
3313 |
* and 12 in the 2GHz *and* 5GHz bands. |
4252 |
for (ntries = 0; ntries < 200; ntries++) { |
3314 |
* Because of limitations in our net80211(9) stack, |
4253 |
if (WPI_READ(sc, WPI_FH_TX_STATUS) & |
3315 |
* we can't support these channels in 5GHz band. |
4254 |
WPI_FH_TX_STATUS_IDLE(chnl)) |
3316 |
* XXX not true; just need to map to proper frequency |
4255 |
break; |
3317 |
*/ |
4256 |
DELAY(10); |
3318 |
if (chan <= 14) |
4257 |
} |
3319 |
continue; |
|
|
3320 |
|
3321 |
c->ic_ieee = chan; |
3322 |
c->ic_freq = ieee80211_ieee2mhz(chan, |
3323 |
IEEE80211_CHAN_5GHZ); |
3324 |
c->ic_flags = IEEE80211_CHAN_A | passive; |
3325 |
} |
4258 |
} |
|
|
4259 |
wpi_nic_unlock(sc); |
4260 |
} |
3326 |
|
4261 |
|
3327 |
/* save maximum allowed power for this channel */ |
4262 |
/* Stop RX ring. */ |
3328 |
sc->maxpwr[chan] = channels[i].maxpwr; |
4263 |
wpi_reset_rx_ring(sc); |
3329 |
|
4264 |
|
3330 |
#if 0 |
4265 |
/* Reset all TX rings. */ |
3331 |
// XXX We can probably use this an get rid of maxpwr - ben 20070617 |
4266 |
for (qid = 0; qid < WPI_NTXQUEUES; qid++) |
3332 |
ic->ic_channels[chan].ic_maxpower = channels[i].maxpwr; |
4267 |
wpi_reset_tx_ring(sc, &sc->txq[qid]); |
3333 |
//ic->ic_channels[chan].ic_minpower... |
|
|
3334 |
//ic->ic_channels[chan].ic_maxregtxpower... |
3335 |
#endif |
3336 |
|
4268 |
|
3337 |
DPRINTF(("adding chan %d (%dMHz) flags=0x%x maxpwr=%d" |
4269 |
if (wpi_nic_lock(sc) == 0) { |
3338 |
" passive=%d, offset %d\n", chan, c->ic_freq, |
4270 |
wpi_prph_write(sc, WPI_APMG_CLK_DIS, |
3339 |
channels[i].flags, sc->maxpwr[chan], |
4271 |
WPI_APMG_CLK_CTRL_DMA_CLK_RQT); |
3340 |
(c->ic_flags & IEEE80211_CHAN_PASSIVE) != 0, |
4272 |
wpi_nic_unlock(sc); |
3341 |
ic->ic_nchans)); |
|
|
3342 |
} |
4273 |
} |
|
|
4274 |
DELAY(5); |
4275 |
/* Power OFF adapter. */ |
4276 |
wpi_apm_stop(sc); |
3343 |
} |
4277 |
} |
3344 |
|
4278 |
|
3345 |
static void |
4279 |
static void |
3346 |
wpi_read_eeprom_group(struct wpi_softc *sc, int n) |
4280 |
wpi_radio_on(void *arg0, int pending) |
3347 |
{ |
4281 |
{ |
3348 |
struct wpi_power_group *group = &sc->groups[n]; |
4282 |
struct wpi_softc *sc = arg0; |
3349 |
struct wpi_eeprom_group rgroup; |
4283 |
struct ifnet *ifp = sc->sc_ifp; |
3350 |
int i; |
4284 |
struct ieee80211com *ic = ifp->if_l2com; |
|
|
4285 |
struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); |
3351 |
|
4286 |
|
3352 |
wpi_read_prom_data(sc, WPI_EEPROM_POWER_GRP + n * 32, &rgroup, |
4287 |
device_printf(sc->sc_dev, "RF switch: radio enabled\n"); |
3353 |
sizeof rgroup); |
|
|
3354 |
|
4288 |
|
3355 |
/* save power group information */ |
4289 |
if (vap != NULL) { |
3356 |
group->chan = rgroup.chan; |
4290 |
wpi_init(sc); |
3357 |
group->maxpwr = rgroup.maxpwr; |
4291 |
ieee80211_init(vap); |
3358 |
/* temperature at which the samples were taken */ |
4292 |
} |
3359 |
group->temp = (int16_t)le16toh(rgroup.temp); |
|
|
3360 |
|
4293 |
|
3361 |
DPRINTF(("power group %d: chan=%d maxpwr=%d temp=%d\n", n, |
4294 |
if (WPI_READ(sc, WPI_GP_CNTRL) & WPI_GP_CNTRL_RFKILL) { |
3362 |
group->chan, group->maxpwr, group->temp)); |
4295 |
WPI_LOCK(sc); |
3363 |
|
4296 |
callout_stop(&sc->watchdog_rfkill); |
3364 |
for (i = 0; i < WPI_SAMPLES_COUNT; i++) { |
4297 |
WPI_UNLOCK(sc); |
3365 |
group->samples[i].index = rgroup.samples[i].index; |
|
|
3366 |
group->samples[i].power = rgroup.samples[i].power; |
3367 |
|
3368 |
DPRINTF(("\tsample %d: index=%d power=%d\n", i, |
3369 |
group->samples[i].index, group->samples[i].power)); |
3370 |
} |
4298 |
} |
3371 |
} |
4299 |
} |
3372 |
|
4300 |
|
3373 |
/* |
4301 |
static void |
3374 |
* Update Tx power to match what is defined for channel `c'. |
4302 |
wpi_radio_off(void *arg0, int pending) |
3375 |
*/ |
|
|
3376 |
static int |
3377 |
wpi_set_txpower(struct wpi_softc *sc, struct ieee80211_channel *c, int async) |
3378 |
{ |
4303 |
{ |
|
|
4304 |
struct wpi_softc *sc = arg0; |
3379 |
struct ifnet *ifp = sc->sc_ifp; |
4305 |
struct ifnet *ifp = sc->sc_ifp; |
3380 |
struct ieee80211com *ic = ifp->if_l2com; |
4306 |
struct ieee80211com *ic = ifp->if_l2com; |
3381 |
struct wpi_power_group *group; |
4307 |
struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); |
3382 |
struct wpi_cmd_txpower txpower; |
|
|
3383 |
u_int chan; |
3384 |
int i; |
3385 |
|
4308 |
|
3386 |
/* get channel number */ |
4309 |
device_printf(sc->sc_dev, "RF switch: radio disabled\n"); |
3387 |
chan = ieee80211_chan2ieee(ic, c); |
|
|
3388 |
|
4310 |
|
3389 |
/* find the power group to which this channel belongs */ |
4311 |
wpi_stop(sc); |
3390 |
if (IEEE80211_IS_CHAN_5GHZ(c)) { |
4312 |
if (vap != NULL) |
3391 |
for (group = &sc->groups[1]; group < &sc->groups[4]; group++) |
4313 |
ieee80211_stop(vap); |
3392 |
if (chan <= group->chan) |
|
|
3393 |
break; |
3394 |
} else |
3395 |
group = &sc->groups[0]; |
3396 |
|
4314 |
|
3397 |
memset(&txpower, 0, sizeof txpower); |
4315 |
callout_reset(&sc->watchdog_rfkill, hz, wpi_watchdog_rfkill, sc); |
3398 |
txpower.band = IEEE80211_IS_CHAN_5GHZ(c) ? 0 : 1; |
4316 |
} |
3399 |
txpower.channel = htole16(chan); |
|
|
3400 |
|
4317 |
|
3401 |
/* set Tx power for all OFDM and CCK rates */ |
4318 |
static void |
3402 |
for (i = 0; i <= 11 ; i++) { |
4319 |
wpi_init_locked(struct wpi_softc *sc) |
3403 |
/* retrieve Tx power for this channel/rate combination */ |
4320 |
{ |
3404 |
int idx = wpi_get_power_index(sc, group, c, |
4321 |
struct ifnet *ifp = sc->sc_ifp; |
3405 |
wpi_ridx_to_rate[i]); |
4322 |
int error; |
3406 |
|
4323 |
|
3407 |
txpower.rates[i].rate = wpi_ridx_to_plcp[i]; |
4324 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__); |
3408 |
|
4325 |
|
3409 |
if (IEEE80211_IS_CHAN_5GHZ(c)) { |
4326 |
WPI_LOCK_ASSERT(sc); |
3410 |
txpower.rates[i].gain_radio = wpi_rf_gain_5ghz[idx]; |
4327 |
|
3411 |
txpower.rates[i].gain_dsp = wpi_dsp_gain_5ghz[idx]; |
4328 |
/* Check that the radio is not disabled by hardware switch. */ |
3412 |
} else { |
4329 |
if (!(WPI_READ(sc, WPI_GP_CNTRL) & WPI_GP_CNTRL_RFKILL)) { |
3413 |
txpower.rates[i].gain_radio = wpi_rf_gain_2ghz[idx]; |
4330 |
device_printf(sc->sc_dev, |
3414 |
txpower.rates[i].gain_dsp = wpi_dsp_gain_2ghz[idx]; |
4331 |
"RF switch: radio disabled (%s)\n", __func__); |
3415 |
} |
4332 |
callout_reset(&sc->watchdog_rfkill, hz, wpi_watchdog_rfkill, |
3416 |
DPRINTFN(WPI_DEBUG_TEMP,("chan %d/rate %d: power index %d\n", |
4333 |
sc); |
3417 |
chan, wpi_ridx_to_rate[i], idx)); |
4334 |
return; |
3418 |
} |
4335 |
} |
3419 |
|
4336 |
|
3420 |
return wpi_cmd(sc, WPI_CMD_TXPOWER, &txpower, sizeof txpower, async); |
4337 |
/* Read firmware images from the filesystem. */ |
3421 |
} |
4338 |
if ((error = wpi_read_firmware(sc)) != 0) { |
|
|
4339 |
device_printf(sc->sc_dev, |
4340 |
"%s: could not read firmware, error %d\n", __func__, |
4341 |
error); |
4342 |
goto fail; |
4343 |
} |
3422 |
|
4344 |
|
3423 |
/* |
4345 |
/* Initialize hardware and upload firmware. */ |
3424 |
* Determine Tx power index for a given channel/rate combination. |
4346 |
error = wpi_hw_init(sc); |
3425 |
* This takes into account the regulatory information from EEPROM and the |
4347 |
wpi_unload_firmware(sc); |
3426 |
* current temperature. |
4348 |
if (error != 0) { |
3427 |
*/ |
4349 |
device_printf(sc->sc_dev, |
3428 |
static int |
4350 |
"%s: could not initialize hardware, error %d\n", __func__, |
3429 |
wpi_get_power_index(struct wpi_softc *sc, struct wpi_power_group *group, |
4351 |
error); |
3430 |
struct ieee80211_channel *c, int rate) |
4352 |
goto fail; |
3431 |
{ |
4353 |
} |
3432 |
/* fixed-point arithmetic division using a n-bit fractional part */ |
|
|
3433 |
#define fdivround(a, b, n) \ |
3434 |
((((1 << n) * (a)) / (b) + (1 << n) / 2) / (1 << n)) |
3435 |
|
4354 |
|
3436 |
/* linear interpolation */ |
4355 |
/* Configure adapter now that it is ready. */ |
3437 |
#define interpolate(x, x1, y1, x2, y2, n) \ |
4356 |
if ((error = wpi_config(sc)) != 0) { |
3438 |
((y1) + fdivround(((x) - (x1)) * ((y2) - (y1)), (x2) - (x1), n)) |
4357 |
device_printf(sc->sc_dev, |
|
|
4358 |
"%s: could not configure device, error %d\n", __func__, |
4359 |
error); |
4360 |
goto fail; |
4361 |
} |
3439 |
|
4362 |
|
3440 |
struct ifnet *ifp = sc->sc_ifp; |
4363 |
ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; |
3441 |
struct ieee80211com *ic = ifp->if_l2com; |
4364 |
ifp->if_drv_flags |= IFF_DRV_RUNNING; |
3442 |
struct wpi_power_sample *sample; |
|
|
3443 |
int pwr, idx; |
3444 |
u_int chan; |
3445 |
|
4365 |
|
3446 |
/* get channel number */ |
4366 |
callout_reset(&sc->watchdog_to, hz, wpi_watchdog, sc); |
3447 |
chan = ieee80211_chan2ieee(ic, c); |
|
|
3448 |
|
4367 |
|
3449 |
/* default power is group's maximum power - 3dB */ |
4368 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__); |
3450 |
pwr = group->maxpwr / 2; |
|
|
3451 |
|
4369 |
|
3452 |
/* decrease power for highest OFDM rates to reduce distortion */ |
4370 |
return; |
3453 |
switch (rate) { |
|
|
3454 |
case 72: /* 36Mb/s */ |
3455 |
pwr -= IEEE80211_IS_CHAN_2GHZ(c) ? 0 : 5; |
3456 |
break; |
3457 |
case 96: /* 48Mb/s */ |
3458 |
pwr -= IEEE80211_IS_CHAN_2GHZ(c) ? 7 : 10; |
3459 |
break; |
3460 |
case 108: /* 54Mb/s */ |
3461 |
pwr -= IEEE80211_IS_CHAN_2GHZ(c) ? 9 : 12; |
3462 |
break; |
3463 |
} |
3464 |
|
4371 |
|
3465 |
/* never exceed channel's maximum allowed Tx power */ |
4372 |
fail: wpi_stop_locked(sc); |
3466 |
pwr = min(pwr, sc->maxpwr[chan]); |
4373 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END_ERR, __func__); |
|
|
4374 |
} |
3467 |
|
4375 |
|
3468 |
/* retrieve power index into gain tables from samples */ |
4376 |
static void |
3469 |
for (sample = group->samples; sample < &group->samples[3]; sample++) |
4377 |
wpi_init(void *arg) |
3470 |
if (pwr > sample[1].power) |
4378 |
{ |
3471 |
break; |
4379 |
struct wpi_softc *sc = arg; |
3472 |
/* fixed-point linear interpolation using a 19-bit fractional part */ |
4380 |
struct ifnet *ifp = sc->sc_ifp; |
3473 |
idx = interpolate(pwr, sample[0].power, sample[0].index, |
4381 |
struct ieee80211com *ic = ifp->if_l2com; |
3474 |
sample[1].power, sample[1].index, 19); |
|
|
3475 |
|
4382 |
|
3476 |
/* |
4383 |
WPI_LOCK(sc); |
3477 |
* Adjust power index based on current temperature |
4384 |
wpi_init_locked(sc); |
3478 |
* - if colder than factory-calibrated: decreate output power |
4385 |
WPI_UNLOCK(sc); |
3479 |
* - if warmer than factory-calibrated: increase output power |
|
|
3480 |
*/ |
3481 |
idx -= (sc->temp - group->temp) * 11 / 100; |
3482 |
|
4386 |
|
3483 |
/* decrease power for CCK rates (-5dB) */ |
4387 |
if (ifp->if_drv_flags & IFF_DRV_RUNNING) |
3484 |
if (!WPI_RATE_IS_OFDM(rate)) |
4388 |
ieee80211_start_all(ic); |
3485 |
idx += 10; |
4389 |
} |
3486 |
|
4390 |
|
3487 |
/* keep power index in a valid range */ |
4391 |
static void |
3488 |
if (idx < 0) |
4392 |
wpi_stop_locked(struct wpi_softc *sc) |
3489 |
return 0; |
4393 |
{ |
3490 |
if (idx > WPI_MAX_PWR_INDEX) |
4394 |
struct ifnet *ifp = sc->sc_ifp; |
3491 |
return WPI_MAX_PWR_INDEX; |
|
|
3492 |
return idx; |
3493 |
|
4395 |
|
3494 |
#undef interpolate |
4396 |
WPI_LOCK_ASSERT(sc); |
3495 |
#undef fdivround |
4397 |
|
|
|
4398 |
sc->sc_scan_timer = 0; |
4399 |
sc->sc_tx_timer = 0; |
4400 |
callout_stop(&sc->watchdog_to); |
4401 |
callout_stop(&sc->calib_to); |
4402 |
ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE); |
4403 |
|
4404 |
/* Power OFF hardware. */ |
4405 |
wpi_hw_stop(sc); |
3496 |
} |
4406 |
} |
3497 |
|
4407 |
|
3498 |
/** |
4408 |
static void |
3499 |
* Called by net80211 framework to indicate that a scan |
4409 |
wpi_stop(struct wpi_softc *sc) |
3500 |
* is starting. This function doesn't actually do the scan, |
4410 |
{ |
3501 |
* wpi_scan_curchan starts things off. This function is more |
4411 |
WPI_LOCK(sc); |
3502 |
* of an early warning from the framework we should get ready |
4412 |
wpi_stop_locked(sc); |
3503 |
* for the scan. |
4413 |
WPI_UNLOCK(sc); |
|
|
4414 |
} |
4415 |
|
4416 |
/* |
4417 |
* Callback from net80211 to start a scan. |
3504 |
*/ |
4418 |
*/ |
3505 |
static void |
4419 |
static void |
3506 |
wpi_scan_start(struct ieee80211com *ic) |
4420 |
wpi_scan_start(struct ieee80211com *ic) |
Lines 3513-3527
Link Here
|
3513 |
WPI_UNLOCK(sc); |
4427 |
WPI_UNLOCK(sc); |
3514 |
} |
4428 |
} |
3515 |
|
4429 |
|
3516 |
/** |
4430 |
/* |
3517 |
* Called by the net80211 framework, indicates that the |
4431 |
* Callback from net80211 to terminate a scan. |
3518 |
* scan has ended. If there is a scan in progress on the card |
|
|
3519 |
* then it should be aborted. |
3520 |
*/ |
4432 |
*/ |
3521 |
static void |
4433 |
static void |
3522 |
wpi_scan_end(struct ieee80211com *ic) |
4434 |
wpi_scan_end(struct ieee80211com *ic) |
3523 |
{ |
4435 |
{ |
3524 |
/* XXX ignore */ |
4436 |
struct ifnet *ifp = ic->ic_ifp; |
|
|
4437 |
struct wpi_softc *sc = ifp->if_softc; |
4438 |
struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); |
4439 |
|
4440 |
if (vap->iv_state == IEEE80211_S_RUN) { |
4441 |
WPI_LOCK(sc); |
4442 |
wpi_set_led(sc, WPI_LED_LINK, 0, 1); |
4443 |
WPI_UNLOCK(sc); |
4444 |
} |
3525 |
} |
4445 |
} |
3526 |
|
4446 |
|
3527 |
/** |
4447 |
/** |
Lines 3531-3552
Link Here
|
3531 |
static void |
4451 |
static void |
3532 |
wpi_set_channel(struct ieee80211com *ic) |
4452 |
wpi_set_channel(struct ieee80211com *ic) |
3533 |
{ |
4453 |
{ |
|
|
4454 |
const struct ieee80211_channel *c = ic->ic_curchan; |
3534 |
struct ifnet *ifp = ic->ic_ifp; |
4455 |
struct ifnet *ifp = ic->ic_ifp; |
3535 |
struct wpi_softc *sc = ifp->if_softc; |
4456 |
struct wpi_softc *sc = ifp->if_softc; |
3536 |
int error; |
4457 |
int error; |
3537 |
|
4458 |
|
|
|
4459 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__); |
4460 |
|
4461 |
WPI_LOCK(sc); |
4462 |
sc->sc_rxtap.wr_chan_freq = htole16(c->ic_freq); |
4463 |
sc->sc_rxtap.wr_chan_flags = htole16(c->ic_flags); |
4464 |
sc->sc_txtap.wt_chan_freq = htole16(c->ic_freq); |
4465 |
sc->sc_txtap.wt_chan_flags = htole16(c->ic_flags); |
4466 |
|
3538 |
/* |
4467 |
/* |
3539 |
* Only need to set the channel in Monitor mode. AP scanning and auth |
4468 |
* Only need to set the channel in Monitor mode. AP scanning and auth |
3540 |
* are already taken care of by their respective firmware commands. |
4469 |
* are already taken care of by their respective firmware commands. |
3541 |
*/ |
4470 |
*/ |
3542 |
if (ic->ic_opmode == IEEE80211_M_MONITOR) { |
4471 |
if (ic->ic_opmode == IEEE80211_M_MONITOR) { |
3543 |
WPI_LOCK(sc); |
4472 |
sc->rxon.filter &= ~htole32(WPI_FILTER_BSS); |
3544 |
error = wpi_config(sc); |
4473 |
sc->rxon.chan = ieee80211_chan2ieee(ic, c); |
3545 |
WPI_UNLOCK(sc); |
4474 |
if (IEEE80211_IS_CHAN_2GHZ(c)) { |
3546 |
if (error != 0) |
4475 |
sc->rxon.flags |= htole32(WPI_RXON_AUTO | |
|
|
4476 |
WPI_RXON_24GHZ); |
4477 |
} else { |
4478 |
sc->rxon.flags &= ~htole32(WPI_RXON_AUTO | |
4479 |
WPI_RXON_24GHZ); |
4480 |
} |
4481 |
if ((error = wpi_send_rxon(sc, 0)) != 0) |
3547 |
device_printf(sc->sc_dev, |
4482 |
device_printf(sc->sc_dev, |
3548 |
"error %d settting channel\n", error); |
4483 |
"%s: error %d settting channel\n", __func__, |
|
|
4484 |
error); |
3549 |
} |
4485 |
} |
|
|
4486 |
WPI_UNLOCK(sc); |
3550 |
} |
4487 |
} |
3551 |
|
4488 |
|
3552 |
/** |
4489 |
/** |
Lines 3558-3570
Link Here
|
3558 |
wpi_scan_curchan(struct ieee80211_scan_state *ss, unsigned long maxdwell) |
4495 |
wpi_scan_curchan(struct ieee80211_scan_state *ss, unsigned long maxdwell) |
3559 |
{ |
4496 |
{ |
3560 |
struct ieee80211vap *vap = ss->ss_vap; |
4497 |
struct ieee80211vap *vap = ss->ss_vap; |
3561 |
struct ifnet *ifp = vap->iv_ic->ic_ifp; |
4498 |
struct ieee80211com *ic = vap->iv_ic; |
|
|
4499 |
struct ifnet *ifp = ic->ic_ifp; |
3562 |
struct wpi_softc *sc = ifp->if_softc; |
4500 |
struct wpi_softc *sc = ifp->if_softc; |
|
|
4501 |
int error; |
3563 |
|
4502 |
|
3564 |
WPI_LOCK(sc); |
4503 |
if (sc->rxon.chan != ieee80211_chan2ieee(ic, ic->ic_curchan)) { |
3565 |
if (wpi_scan(sc)) |
4504 |
WPI_LOCK(sc); |
3566 |
ieee80211_cancel_scan(vap); |
4505 |
error = wpi_scan(sc, ic->ic_curchan); |
3567 |
WPI_UNLOCK(sc); |
4506 |
WPI_UNLOCK(sc); |
|
|
4507 |
if (error != 0) |
4508 |
ieee80211_cancel_scan(vap); |
4509 |
} else { |
4510 |
/* Send probe request when associated. */ |
4511 |
sc->sc_scan_curchan(ss, maxdwell); |
4512 |
} |
3568 |
} |
4513 |
} |
3569 |
|
4514 |
|
3570 |
/** |
4515 |
/** |
Lines 3580-3697
Link Here
|
3580 |
} |
4525 |
} |
3581 |
|
4526 |
|
3582 |
static void |
4527 |
static void |
3583 |
wpi_hwreset(void *arg, int pending) |
4528 |
wpi_hw_reset(void *arg, int pending) |
3584 |
{ |
4529 |
{ |
3585 |
struct wpi_softc *sc = arg; |
4530 |
struct wpi_softc *sc = arg; |
3586 |
|
|
|
3587 |
WPI_LOCK(sc); |
3588 |
wpi_init_locked(sc, 0); |
3589 |
WPI_UNLOCK(sc); |
3590 |
} |
3591 |
|
3592 |
static void |
3593 |
wpi_rfreset(void *arg, int pending) |
3594 |
{ |
3595 |
struct wpi_softc *sc = arg; |
3596 |
|
3597 |
WPI_LOCK(sc); |
3598 |
wpi_rfkill_resume(sc); |
3599 |
WPI_UNLOCK(sc); |
3600 |
} |
3601 |
|
3602 |
/* |
3603 |
* Allocate DMA-safe memory for firmware transfer. |
3604 |
*/ |
3605 |
static int |
3606 |
wpi_alloc_fwmem(struct wpi_softc *sc) |
3607 |
{ |
3608 |
/* allocate enough contiguous space to store text and data */ |
3609 |
return wpi_dma_contig_alloc(sc, &sc->fw_dma, NULL, |
3610 |
WPI_FW_MAIN_TEXT_MAXSZ + WPI_FW_MAIN_DATA_MAXSZ, 1, |
3611 |
BUS_DMA_NOWAIT); |
3612 |
} |
3613 |
|
3614 |
static void |
3615 |
wpi_free_fwmem(struct wpi_softc *sc) |
3616 |
{ |
3617 |
wpi_dma_contig_free(&sc->fw_dma); |
3618 |
} |
3619 |
|
3620 |
/** |
3621 |
* Called every second, wpi_watchdog used by the watch dog timer |
3622 |
* to check that the card is still alive |
3623 |
*/ |
3624 |
static void |
3625 |
wpi_watchdog(void *arg) |
3626 |
{ |
3627 |
struct wpi_softc *sc = arg; |
3628 |
struct ifnet *ifp = sc->sc_ifp; |
4531 |
struct ifnet *ifp = sc->sc_ifp; |
3629 |
struct ieee80211com *ic = ifp->if_l2com; |
4532 |
struct ieee80211com *ic = ifp->if_l2com; |
3630 |
uint32_t tmp; |
4533 |
struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); |
3631 |
|
4534 |
|
3632 |
DPRINTFN(WPI_DEBUG_WATCHDOG,("Watchdog: tick\n")); |
4535 |
DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__); |
3633 |
|
4536 |
|
3634 |
if (sc->flags & WPI_FLAG_HW_RADIO_OFF) { |
4537 |
wpi_stop(sc); |
3635 |
/* No need to lock firmware memory */ |
4538 |
if (vap != NULL) |
3636 |
tmp = wpi_mem_read(sc, WPI_MEM_HW_RADIO_OFF); |
4539 |
ieee80211_stop(vap); |
3637 |
|
4540 |
wpi_init(sc); |
3638 |
if ((tmp & 0x1) == 0) { |
4541 |
if (vap != NULL) |
3639 |
/* Radio kill switch is still off */ |
4542 |
ieee80211_init(vap); |
3640 |
callout_reset(&sc->watchdog_to, hz, wpi_watchdog, sc); |
|
|
3641 |
return; |
3642 |
} |
3643 |
|
3644 |
device_printf(sc->sc_dev, "Hardware Switch Enabled\n"); |
3645 |
ieee80211_runtask(ic, &sc->sc_radiotask); |
3646 |
return; |
3647 |
} |
3648 |
|
3649 |
if (sc->sc_tx_timer > 0) { |
3650 |
if (--sc->sc_tx_timer == 0) { |
3651 |
device_printf(sc->sc_dev,"device timeout\n"); |
3652 |
if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); |
3653 |
ieee80211_runtask(ic, &sc->sc_restarttask); |
3654 |
} |
3655 |
} |
3656 |
if (sc->sc_scan_timer > 0) { |
3657 |
struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); |
3658 |
if (--sc->sc_scan_timer == 0 && vap != NULL) { |
3659 |
device_printf(sc->sc_dev,"scan timeout\n"); |
3660 |
ieee80211_cancel_scan(vap); |
3661 |
ieee80211_runtask(ic, &sc->sc_restarttask); |
3662 |
} |
3663 |
} |
3664 |
|
3665 |
if (ifp->if_drv_flags & IFF_DRV_RUNNING) |
3666 |
callout_reset(&sc->watchdog_to, hz, wpi_watchdog, sc); |
3667 |
} |
4543 |
} |
3668 |
|
|
|
3669 |
#ifdef WPI_DEBUG |
3670 |
static const char *wpi_cmd_str(int cmd) |
3671 |
{ |
3672 |
switch (cmd) { |
3673 |
case WPI_DISABLE_CMD: return "WPI_DISABLE_CMD"; |
3674 |
case WPI_CMD_CONFIGURE: return "WPI_CMD_CONFIGURE"; |
3675 |
case WPI_CMD_ASSOCIATE: return "WPI_CMD_ASSOCIATE"; |
3676 |
case WPI_CMD_SET_WME: return "WPI_CMD_SET_WME"; |
3677 |
case WPI_CMD_TSF: return "WPI_CMD_TSF"; |
3678 |
case WPI_CMD_ADD_NODE: return "WPI_CMD_ADD_NODE"; |
3679 |
case WPI_CMD_TX_DATA: return "WPI_CMD_TX_DATA"; |
3680 |
case WPI_CMD_MRR_SETUP: return "WPI_CMD_MRR_SETUP"; |
3681 |
case WPI_CMD_SET_LED: return "WPI_CMD_SET_LED"; |
3682 |
case WPI_CMD_SET_POWER_MODE: return "WPI_CMD_SET_POWER_MODE"; |
3683 |
case WPI_CMD_SCAN: return "WPI_CMD_SCAN"; |
3684 |
case WPI_CMD_SET_BEACON:return "WPI_CMD_SET_BEACON"; |
3685 |
case WPI_CMD_TXPOWER: return "WPI_CMD_TXPOWER"; |
3686 |
case WPI_CMD_BLUETOOTH: return "WPI_CMD_BLUETOOTH"; |
3687 |
|
3688 |
default: |
3689 |
KASSERT(1, ("Unknown Command: %d\n", cmd)); |
3690 |
return "UNKNOWN CMD"; /* Make the compiler happy */ |
3691 |
} |
3692 |
} |
3693 |
#endif |
3694 |
|
3695 |
MODULE_DEPEND(wpi, pci, 1, 1, 1); |
3696 |
MODULE_DEPEND(wpi, wlan, 1, 1, 1); |
3697 |
MODULE_DEPEND(wpi, firmware, 1, 1, 1); |