2 * Copyright (c) 2006,2007
3 * Damien Bergamini <damien.bergamini@free.fr>
4 * Benjamin Close <Benjamin.Close@clearchain.com>
5 * Copyright (c) 2015 Andriy Voskoboinyk <avos@FreeBSD.org>
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include <sys/cdefs.h>
21 __FBSDID("$FreeBSD$");
24 * Driver for Intel PRO/Wireless 3945ABG 802.11 network adapters.
26 * The 3945ABG network adapter doesn't use traditional hardware as
27 * many other adaptors do. Instead at run time the eeprom is set into a known
28 * state and told to load boot firmware. The boot firmware loads an init and a
29 * main binary firmware image into SRAM on the card via DMA.
30 * Once the firmware is loaded, the driver/hw then
31 * communicate by way of circular dma rings via the SRAM to the firmware.
33 * There is 6 memory rings. 1 command ring, 1 rx data ring & 4 tx data rings.
34 * The 4 tx data rings allow for prioritization QoS.
36 * The rx data ring consists of 32 dma buffers. Two registers are used to
37 * indicate where in the ring the driver and the firmware are up to. The
38 * driver sets the initial read index (reg1) and the initial write index (reg2),
39 * the firmware updates the read index (reg1) on rx of a packet and fires an
40 * interrupt. The driver then processes the buffers starting at reg1 indicating
41 * to the firmware which buffers have been accessed by updating reg2. At the
42 * same time allocating new memory for the processed buffer.
44 * A similar thing happens with the tx rings. The difference is the firmware
45 * stop processing buffers once the queue is full and until confirmation
46 * of a successful transmition (tx_done) has occurred.
48 * The command ring operates in the same manner as the tx queues.
50 * All communication direct to the card (ie eeprom) is classed as Stage1
53 * All communication via the firmware to the card is classed as State2.
54 * The firmware consists of 2 parts. A bootstrap firmware and a runtime
55 * firmware. The bootstrap firmware and runtime firmware are loaded
56 * from host memory via dma to the card then told to execute. From this point
57 * on the majority of communications between the driver and the card goes
64 #include <sys/param.h>
65 #include <sys/sysctl.h>
66 #include <sys/sockio.h>
68 #include <sys/kernel.h>
69 #include <sys/socket.h>
70 #include <sys/systm.h>
71 #include <sys/malloc.h>
72 #include <sys/queue.h>
73 #include <sys/taskqueue.h>
74 #include <sys/module.h>
76 #include <sys/endian.h>
77 #include <sys/linker.h>
78 #include <sys/firmware.h>
80 #include <machine/bus.h>
81 #include <machine/resource.h>
84 #include <dev/pci/pcireg.h>
85 #include <dev/pci/pcivar.h>
89 #include <net/if_var.h>
90 #include <net/if_arp.h>
91 #include <net/ethernet.h>
92 #include <net/if_dl.h>
93 #include <net/if_media.h>
94 #include <net/if_types.h>
96 #include <netinet/in.h>
97 #include <netinet/in_systm.h>
98 #include <netinet/in_var.h>
99 #include <netinet/if_ether.h>
100 #include <netinet/ip.h>
102 #include <net80211/ieee80211_var.h>
103 #include <net80211/ieee80211_radiotap.h>
104 #include <net80211/ieee80211_regdomain.h>
105 #include <net80211/ieee80211_ratectl.h>
107 #include <dev/wpi/if_wpireg.h>
108 #include <dev/wpi/if_wpivar.h>
109 #include <dev/wpi/if_wpi_debug.h>
118 static const struct wpi_ident wpi_ident_table[] = {
119 /* The below entries support ABG regardless of the subid */
120 { 0x8086, 0x4222, 0x0, "Intel(R) PRO/Wireless 3945ABG" },
121 { 0x8086, 0x4227, 0x0, "Intel(R) PRO/Wireless 3945ABG" },
122 /* The below entries only support BG */
123 { 0x8086, 0x4222, 0x1005, "Intel(R) PRO/Wireless 3945BG" },
124 { 0x8086, 0x4222, 0x1034, "Intel(R) PRO/Wireless 3945BG" },
125 { 0x8086, 0x4227, 0x1014, "Intel(R) PRO/Wireless 3945BG" },
126 { 0x8086, 0x4222, 0x1044, "Intel(R) PRO/Wireless 3945BG" },
130 static int wpi_probe(device_t);
131 static int wpi_attach(device_t);
132 static void wpi_radiotap_attach(struct wpi_softc *);
133 static void wpi_sysctlattach(struct wpi_softc *);
134 static void wpi_init_beacon(struct wpi_vap *);
135 static struct ieee80211vap *wpi_vap_create(struct ieee80211com *,
136 const char [IFNAMSIZ], int, enum ieee80211_opmode, int,
137 const uint8_t [IEEE80211_ADDR_LEN],
138 const uint8_t [IEEE80211_ADDR_LEN]);
139 static void wpi_vap_delete(struct ieee80211vap *);
140 static int wpi_detach(device_t);
141 static int wpi_shutdown(device_t);
142 static int wpi_suspend(device_t);
143 static int wpi_resume(device_t);
144 static int wpi_nic_lock(struct wpi_softc *);
145 static int wpi_read_prom_data(struct wpi_softc *, uint32_t, void *, int);
146 static void wpi_dma_map_addr(void *, bus_dma_segment_t *, int, int);
147 static int wpi_dma_contig_alloc(struct wpi_softc *, struct wpi_dma_info *,
148 void **, bus_size_t, bus_size_t);
149 static void wpi_dma_contig_free(struct wpi_dma_info *);
150 static int wpi_alloc_shared(struct wpi_softc *);
151 static void wpi_free_shared(struct wpi_softc *);
152 static int wpi_alloc_fwmem(struct wpi_softc *);
153 static void wpi_free_fwmem(struct wpi_softc *);
154 static int wpi_alloc_rx_ring(struct wpi_softc *);
155 static void wpi_update_rx_ring(struct wpi_softc *);
156 static void wpi_update_rx_ring_ps(struct wpi_softc *);
157 static void wpi_reset_rx_ring(struct wpi_softc *);
158 static void wpi_free_rx_ring(struct wpi_softc *);
159 static int wpi_alloc_tx_ring(struct wpi_softc *, struct wpi_tx_ring *,
161 static void wpi_update_tx_ring(struct wpi_softc *, struct wpi_tx_ring *);
162 static void wpi_update_tx_ring_ps(struct wpi_softc *,
163 struct wpi_tx_ring *);
164 static void wpi_reset_tx_ring(struct wpi_softc *, struct wpi_tx_ring *);
165 static void wpi_free_tx_ring(struct wpi_softc *, struct wpi_tx_ring *);
166 static int wpi_read_eeprom(struct wpi_softc *,
167 uint8_t macaddr[IEEE80211_ADDR_LEN]);
168 static uint32_t wpi_eeprom_channel_flags(struct wpi_eeprom_chan *);
169 static void wpi_read_eeprom_band(struct wpi_softc *, uint8_t, int, int *,
170 struct ieee80211_channel[]);
171 static int wpi_read_eeprom_channels(struct wpi_softc *, uint8_t);
172 static struct wpi_eeprom_chan *wpi_find_eeprom_channel(struct wpi_softc *,
173 struct ieee80211_channel *);
174 static void wpi_getradiocaps(struct ieee80211com *, int, int *,
175 struct ieee80211_channel[]);
176 static int wpi_setregdomain(struct ieee80211com *,
177 struct ieee80211_regdomain *, int,
178 struct ieee80211_channel[]);
179 static int wpi_read_eeprom_group(struct wpi_softc *, uint8_t);
180 static struct ieee80211_node *wpi_node_alloc(struct ieee80211vap *,
181 const uint8_t mac[IEEE80211_ADDR_LEN]);
182 static void wpi_node_free(struct ieee80211_node *);
183 static void wpi_ibss_recv_mgmt(struct ieee80211_node *, struct mbuf *, int,
184 const struct ieee80211_rx_stats *,
186 static void wpi_restore_node(void *, struct ieee80211_node *);
187 static void wpi_restore_node_table(struct wpi_softc *, struct wpi_vap *);
188 static int wpi_newstate(struct ieee80211vap *, enum ieee80211_state, int);
189 static void wpi_calib_timeout(void *);
190 static void wpi_rx_done(struct wpi_softc *, struct wpi_rx_desc *,
191 struct wpi_rx_data *);
192 static void wpi_rx_statistics(struct wpi_softc *, struct wpi_rx_desc *,
193 struct wpi_rx_data *);
194 static void wpi_tx_done(struct wpi_softc *, struct wpi_rx_desc *);
195 static void wpi_cmd_done(struct wpi_softc *, struct wpi_rx_desc *);
196 static void wpi_notif_intr(struct wpi_softc *);
197 static void wpi_wakeup_intr(struct wpi_softc *);
199 static void wpi_debug_registers(struct wpi_softc *);
201 static void wpi_fatal_intr(struct wpi_softc *);
202 static void wpi_intr(void *);
203 static void wpi_free_txfrags(struct wpi_softc *, uint16_t);
204 static int wpi_cmd2(struct wpi_softc *, struct wpi_buf *);
205 static int wpi_tx_data(struct wpi_softc *, struct mbuf *,
206 struct ieee80211_node *);
207 static int wpi_tx_data_raw(struct wpi_softc *, struct mbuf *,
208 struct ieee80211_node *,
209 const struct ieee80211_bpf_params *);
210 static int wpi_raw_xmit(struct ieee80211_node *, struct mbuf *,
211 const struct ieee80211_bpf_params *);
212 static int wpi_transmit(struct ieee80211com *, struct mbuf *);
213 static void wpi_watchdog_rfkill(void *);
214 static void wpi_scan_timeout(void *);
215 static void wpi_tx_timeout(void *);
216 static void wpi_parent(struct ieee80211com *);
217 static int wpi_cmd(struct wpi_softc *, uint8_t, const void *, uint16_t,
219 static int wpi_mrr_setup(struct wpi_softc *);
220 static int wpi_add_node(struct wpi_softc *, struct ieee80211_node *);
221 static int wpi_add_broadcast_node(struct wpi_softc *, int);
222 static int wpi_add_ibss_node(struct wpi_softc *, struct ieee80211_node *);
223 static void wpi_del_node(struct wpi_softc *, struct ieee80211_node *);
224 static int wpi_updateedca(struct ieee80211com *);
225 static void wpi_set_promisc(struct wpi_softc *);
226 static void wpi_update_promisc(struct ieee80211com *);
227 static void wpi_update_mcast(struct ieee80211com *);
228 static void wpi_set_led(struct wpi_softc *, uint8_t, uint8_t, uint8_t);
229 static int wpi_set_timing(struct wpi_softc *, struct ieee80211_node *);
230 static void wpi_power_calibration(struct wpi_softc *);
231 static int wpi_set_txpower(struct wpi_softc *, int);
232 static int wpi_get_power_index(struct wpi_softc *,
233 struct wpi_power_group *, uint8_t, int, int);
234 static int wpi_set_pslevel(struct wpi_softc *, uint8_t, int, int);
235 static int wpi_send_btcoex(struct wpi_softc *);
236 static int wpi_send_rxon(struct wpi_softc *, int, int);
237 static int wpi_config(struct wpi_softc *);
238 static uint16_t wpi_get_active_dwell_time(struct wpi_softc *,
239 struct ieee80211_channel *, uint8_t);
240 static uint16_t wpi_limit_dwell(struct wpi_softc *, uint16_t);
241 static uint16_t wpi_get_passive_dwell_time(struct wpi_softc *,
242 struct ieee80211_channel *);
243 static uint32_t wpi_get_scan_pause_time(uint32_t, uint16_t);
244 static int wpi_scan(struct wpi_softc *, struct ieee80211_channel *);
245 static int wpi_auth(struct wpi_softc *, struct ieee80211vap *);
246 static int wpi_config_beacon(struct wpi_vap *);
247 static int wpi_setup_beacon(struct wpi_softc *, struct ieee80211_node *);
248 static void wpi_update_beacon(struct ieee80211vap *, int);
249 static void wpi_newassoc(struct ieee80211_node *, int);
250 static int wpi_run(struct wpi_softc *, struct ieee80211vap *);
251 static int wpi_load_key(struct ieee80211_node *,
252 const struct ieee80211_key *);
253 static void wpi_load_key_cb(void *, struct ieee80211_node *);
254 static int wpi_set_global_keys(struct ieee80211_node *);
255 static int wpi_del_key(struct ieee80211_node *,
256 const struct ieee80211_key *);
257 static void wpi_del_key_cb(void *, struct ieee80211_node *);
258 static int wpi_process_key(struct ieee80211vap *,
259 const struct ieee80211_key *, int);
260 static int wpi_key_set(struct ieee80211vap *,
261 const struct ieee80211_key *);
262 static int wpi_key_delete(struct ieee80211vap *,
263 const struct ieee80211_key *);
264 static int wpi_post_alive(struct wpi_softc *);
265 static int wpi_load_bootcode(struct wpi_softc *, const uint8_t *,
267 static int wpi_load_firmware(struct wpi_softc *);
268 static int wpi_read_firmware(struct wpi_softc *);
269 static void wpi_unload_firmware(struct wpi_softc *);
270 static int wpi_clock_wait(struct wpi_softc *);
271 static int wpi_apm_init(struct wpi_softc *);
272 static void wpi_apm_stop_master(struct wpi_softc *);
273 static void wpi_apm_stop(struct wpi_softc *);
274 static void wpi_nic_config(struct wpi_softc *);
275 static int wpi_hw_init(struct wpi_softc *);
276 static void wpi_hw_stop(struct wpi_softc *);
277 static void wpi_radio_on(void *, int);
278 static void wpi_radio_off(void *, int);
279 static int wpi_init(struct wpi_softc *);
280 static void wpi_stop_locked(struct wpi_softc *);
281 static void wpi_stop(struct wpi_softc *);
282 static void wpi_scan_start(struct ieee80211com *);
283 static void wpi_scan_end(struct ieee80211com *);
284 static void wpi_set_channel(struct ieee80211com *);
285 static void wpi_scan_curchan(struct ieee80211_scan_state *, unsigned long);
286 static void wpi_scan_mindwell(struct ieee80211_scan_state *);
288 static device_method_t wpi_methods[] = {
289 /* Device interface */
290 DEVMETHOD(device_probe, wpi_probe),
291 DEVMETHOD(device_attach, wpi_attach),
292 DEVMETHOD(device_detach, wpi_detach),
293 DEVMETHOD(device_shutdown, wpi_shutdown),
294 DEVMETHOD(device_suspend, wpi_suspend),
295 DEVMETHOD(device_resume, wpi_resume),
300 static driver_t wpi_driver = {
303 sizeof (struct wpi_softc)
305 static devclass_t wpi_devclass;
307 DRIVER_MODULE(wpi, pci, wpi_driver, wpi_devclass, NULL, NULL);
309 MODULE_VERSION(wpi, 1);
311 MODULE_DEPEND(wpi, pci, 1, 1, 1);
312 MODULE_DEPEND(wpi, wlan, 1, 1, 1);
313 MODULE_DEPEND(wpi, firmware, 1, 1, 1);
316 wpi_probe(device_t dev)
318 const struct wpi_ident *ident;
320 for (ident = wpi_ident_table; ident->name != NULL; ident++) {
321 if (pci_get_vendor(dev) == ident->vendor &&
322 pci_get_device(dev) == ident->device) {
323 device_set_desc(dev, ident->name);
324 return (BUS_PROBE_DEFAULT);
331 wpi_attach(device_t dev)
333 struct wpi_softc *sc = (struct wpi_softc *)device_get_softc(dev);
334 struct ieee80211com *ic;
339 const struct wpi_ident *ident;
345 error = resource_int_value(device_get_name(sc->sc_dev),
346 device_get_unit(sc->sc_dev), "debug", &(sc->sc_debug));
353 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__);
356 * Get the offset of the PCI Express Capability Structure in PCI
357 * Configuration Space.
359 error = pci_find_cap(dev, PCIY_EXPRESS, &sc->sc_cap_off);
361 device_printf(dev, "PCIe capability structure not found!\n");
366 * Some card's only support 802.11b/g not a, check to see if
367 * this is one such card. A 0x0 in the subdevice table indicates
368 * the entire subdevice range is to be ignored.
371 for (ident = wpi_ident_table; ident->name != NULL; ident++) {
372 if (ident->subdevice &&
373 pci_get_subdevice(dev) == ident->subdevice) {
380 /* Clear device-specific "PCI retry timeout" register (41h). */
381 pci_write_config(dev, 0x41, 0, 1);
383 /* Enable bus-mastering. */
384 pci_enable_busmaster(dev);
387 sc->mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
389 if (sc->mem == NULL) {
390 device_printf(dev, "can't map mem space\n");
393 sc->sc_st = rman_get_bustag(sc->mem);
394 sc->sc_sh = rman_get_bushandle(sc->mem);
397 if (pci_alloc_msi(dev, &rid) == 0)
401 /* Install interrupt handler. */
402 sc->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE |
403 (rid != 0 ? 0 : RF_SHAREABLE));
404 if (sc->irq == NULL) {
405 device_printf(dev, "can't map interrupt\n");
411 WPI_TX_LOCK_INIT(sc);
412 WPI_RXON_LOCK_INIT(sc);
413 WPI_NT_LOCK_INIT(sc);
414 WPI_TXQ_LOCK_INIT(sc);
415 WPI_TXQ_STATE_LOCK_INIT(sc);
417 /* Allocate DMA memory for firmware transfers. */
418 if ((error = wpi_alloc_fwmem(sc)) != 0) {
420 "could not allocate memory for firmware, error %d\n",
425 /* Allocate shared page. */
426 if ((error = wpi_alloc_shared(sc)) != 0) {
427 device_printf(dev, "could not allocate shared page\n");
431 /* Allocate TX rings - 4 for QoS purposes, 1 for commands. */
432 for (i = 0; i < WPI_DRV_NTXQUEUES; i++) {
433 if ((error = wpi_alloc_tx_ring(sc, &sc->txq[i], i)) != 0) {
435 "could not allocate TX ring %d, error %d\n", i,
441 /* Allocate RX ring. */
442 if ((error = wpi_alloc_rx_ring(sc)) != 0) {
443 device_printf(dev, "could not allocate RX ring, error %d\n",
448 /* Clear pending interrupts. */
449 WPI_WRITE(sc, WPI_INT, 0xffffffff);
453 ic->ic_name = device_get_nameunit(dev);
454 ic->ic_phytype = IEEE80211_T_OFDM; /* not only, but not used */
455 ic->ic_opmode = IEEE80211_M_STA; /* default to BSS mode */
457 /* Set device capabilities. */
459 IEEE80211_C_STA /* station mode supported */
460 | IEEE80211_C_IBSS /* IBSS mode supported */
461 | IEEE80211_C_HOSTAP /* Host access point mode */
462 | IEEE80211_C_MONITOR /* monitor mode supported */
463 | IEEE80211_C_AHDEMO /* adhoc demo mode */
464 | IEEE80211_C_BGSCAN /* capable of bg scanning */
465 | IEEE80211_C_TXFRAG /* handle tx frags */
466 | IEEE80211_C_TXPMGT /* tx power management */
467 | IEEE80211_C_SHSLOT /* short slot time supported */
468 | IEEE80211_C_WPA /* 802.11i */
469 | IEEE80211_C_SHPREAMBLE /* short preamble supported */
470 | IEEE80211_C_WME /* 802.11e */
471 | IEEE80211_C_PMGT /* Station-side power mgmt */
475 IEEE80211_CRYPTO_AES_CCM;
478 * Read in the eeprom and also setup the channels for
479 * net80211. We don't set the rates as net80211 does this for us
481 if ((error = wpi_read_eeprom(sc, ic->ic_macaddr)) != 0) {
482 device_printf(dev, "could not read EEPROM, error %d\n",
489 device_printf(sc->sc_dev, "Regulatory Domain: %.4s\n",
491 device_printf(sc->sc_dev, "Hardware Type: %c\n",
492 sc->type > 1 ? 'B': '?');
493 device_printf(sc->sc_dev, "Hardware Revision: %c\n",
494 ((sc->rev & 0xf0) == 0xd0) ? 'D': '?');
495 device_printf(sc->sc_dev, "SKU %s support 802.11a\n",
496 supportsa ? "does" : "does not");
498 /* XXX hw_config uses the PCIDEV for the Hardware rev. Must
499 check what sc->rev really represents - benjsc 20070615 */
503 ieee80211_ifattach(ic);
504 ic->ic_vap_create = wpi_vap_create;
505 ic->ic_vap_delete = wpi_vap_delete;
506 ic->ic_parent = wpi_parent;
507 ic->ic_raw_xmit = wpi_raw_xmit;
508 ic->ic_transmit = wpi_transmit;
509 ic->ic_node_alloc = wpi_node_alloc;
510 sc->sc_node_free = ic->ic_node_free;
511 ic->ic_node_free = wpi_node_free;
512 ic->ic_wme.wme_update = wpi_updateedca;
513 ic->ic_update_promisc = wpi_update_promisc;
514 ic->ic_update_mcast = wpi_update_mcast;
515 ic->ic_newassoc = wpi_newassoc;
516 ic->ic_scan_start = wpi_scan_start;
517 ic->ic_scan_end = wpi_scan_end;
518 ic->ic_set_channel = wpi_set_channel;
519 ic->ic_scan_curchan = wpi_scan_curchan;
520 ic->ic_scan_mindwell = wpi_scan_mindwell;
521 ic->ic_getradiocaps = wpi_getradiocaps;
522 ic->ic_setregdomain = wpi_setregdomain;
524 sc->sc_update_rx_ring = wpi_update_rx_ring;
525 sc->sc_update_tx_ring = wpi_update_tx_ring;
527 wpi_radiotap_attach(sc);
529 callout_init_mtx(&sc->calib_to, &sc->rxon_mtx, 0);
530 callout_init_mtx(&sc->scan_timeout, &sc->rxon_mtx, 0);
531 callout_init_mtx(&sc->tx_timeout, &sc->txq_state_mtx, 0);
532 callout_init_mtx(&sc->watchdog_rfkill, &sc->sc_mtx, 0);
533 TASK_INIT(&sc->sc_radiooff_task, 0, wpi_radio_off, sc);
534 TASK_INIT(&sc->sc_radioon_task, 0, wpi_radio_on, sc);
536 wpi_sysctlattach(sc);
539 * Hook our interrupt after all initialization is complete.
541 error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET | INTR_MPSAFE,
542 NULL, wpi_intr, sc, &sc->sc_ih);
544 device_printf(dev, "can't establish interrupt, error %d\n",
550 ieee80211_announce(ic);
553 if (sc->sc_debug & WPI_DEBUG_HW)
554 ieee80211_announce_channels(ic);
557 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
560 fail: wpi_detach(dev);
561 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END_ERR, __func__);
566 * Attach the interface to 802.11 radiotap.
569 wpi_radiotap_attach(struct wpi_softc *sc)
571 struct wpi_rx_radiotap_header *rxtap = &sc->sc_rxtap;
572 struct wpi_tx_radiotap_header *txtap = &sc->sc_txtap;
574 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__);
575 ieee80211_radiotap_attach(&sc->sc_ic,
576 &txtap->wt_ihdr, sizeof(*txtap), WPI_TX_RADIOTAP_PRESENT,
577 &rxtap->wr_ihdr, sizeof(*rxtap), WPI_RX_RADIOTAP_PRESENT);
578 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
582 wpi_sysctlattach(struct wpi_softc *sc)
585 struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(sc->sc_dev);
586 struct sysctl_oid *tree = device_get_sysctl_tree(sc->sc_dev);
588 SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
589 "debug", CTLFLAG_RW, &sc->sc_debug, sc->sc_debug,
590 "control debugging printfs");
595 wpi_init_beacon(struct wpi_vap *wvp)
597 struct wpi_buf *bcn = &wvp->wv_bcbuf;
598 struct wpi_cmd_beacon *cmd = (struct wpi_cmd_beacon *)&bcn->data;
600 cmd->id = WPI_ID_BROADCAST;
601 cmd->ofdm_mask = 0xff;
602 cmd->cck_mask = 0x0f;
603 cmd->lifetime = htole32(WPI_LIFETIME_INFINITE);
606 * XXX WPI_TX_AUTO_SEQ seems to be ignored - workaround this issue
607 * XXX by using WPI_TX_NEED_ACK instead (with some side effects).
609 cmd->flags = htole32(WPI_TX_NEED_ACK | WPI_TX_INSERT_TSTAMP);
611 bcn->code = WPI_CMD_SET_BEACON;
612 bcn->ac = WPI_CMD_QUEUE_NUM;
613 bcn->size = sizeof(struct wpi_cmd_beacon);
616 static struct ieee80211vap *
617 wpi_vap_create(struct ieee80211com *ic, const char name[IFNAMSIZ], int unit,
618 enum ieee80211_opmode opmode, int flags,
619 const uint8_t bssid[IEEE80211_ADDR_LEN],
620 const uint8_t mac[IEEE80211_ADDR_LEN])
623 struct ieee80211vap *vap;
625 if (!TAILQ_EMPTY(&ic->ic_vaps)) /* only one at a time */
628 wvp = malloc(sizeof(struct wpi_vap), M_80211_VAP, M_WAITOK | M_ZERO);
630 ieee80211_vap_setup(ic, vap, name, unit, opmode, flags, bssid);
632 if (opmode == IEEE80211_M_IBSS || opmode == IEEE80211_M_HOSTAP) {
633 WPI_VAP_LOCK_INIT(wvp);
634 wpi_init_beacon(wvp);
637 /* Override with driver methods. */
638 vap->iv_key_set = wpi_key_set;
639 vap->iv_key_delete = wpi_key_delete;
640 if (opmode == IEEE80211_M_IBSS) {
641 wvp->wv_recv_mgmt = vap->iv_recv_mgmt;
642 vap->iv_recv_mgmt = wpi_ibss_recv_mgmt;
644 wvp->wv_newstate = vap->iv_newstate;
645 vap->iv_newstate = wpi_newstate;
646 vap->iv_update_beacon = wpi_update_beacon;
647 vap->iv_max_aid = WPI_ID_IBSS_MAX - WPI_ID_IBSS_MIN + 1;
649 ieee80211_ratectl_init(vap);
650 /* Complete setup. */
651 ieee80211_vap_attach(vap, ieee80211_media_change,
652 ieee80211_media_status, mac);
653 ic->ic_opmode = opmode;
658 wpi_vap_delete(struct ieee80211vap *vap)
660 struct wpi_vap *wvp = WPI_VAP(vap);
661 struct wpi_buf *bcn = &wvp->wv_bcbuf;
662 enum ieee80211_opmode opmode = vap->iv_opmode;
664 ieee80211_ratectl_deinit(vap);
665 ieee80211_vap_detach(vap);
667 if (opmode == IEEE80211_M_IBSS || opmode == IEEE80211_M_HOSTAP) {
671 WPI_VAP_LOCK_DESTROY(wvp);
674 free(wvp, M_80211_VAP);
678 wpi_detach(device_t dev)
680 struct wpi_softc *sc = device_get_softc(dev);
681 struct ieee80211com *ic = &sc->sc_ic;
684 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__);
686 if (ic->ic_vap_create == wpi_vap_create) {
687 ieee80211_draintask(ic, &sc->sc_radioon_task);
688 ieee80211_draintask(ic, &sc->sc_radiooff_task);
692 callout_drain(&sc->watchdog_rfkill);
693 callout_drain(&sc->tx_timeout);
694 callout_drain(&sc->scan_timeout);
695 callout_drain(&sc->calib_to);
696 ieee80211_ifdetach(ic);
699 /* Uninstall interrupt handler. */
700 if (sc->irq != NULL) {
701 bus_teardown_intr(dev, sc->irq, sc->sc_ih);
702 bus_release_resource(dev, SYS_RES_IRQ, rman_get_rid(sc->irq),
704 pci_release_msi(dev);
707 if (sc->txq[0].data_dmat) {
708 /* Free DMA resources. */
709 for (qid = 0; qid < WPI_DRV_NTXQUEUES; qid++)
710 wpi_free_tx_ring(sc, &sc->txq[qid]);
712 wpi_free_rx_ring(sc);
720 bus_release_resource(dev, SYS_RES_MEMORY,
721 rman_get_rid(sc->mem), sc->mem);
723 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
724 WPI_TXQ_STATE_LOCK_DESTROY(sc);
725 WPI_TXQ_LOCK_DESTROY(sc);
726 WPI_NT_LOCK_DESTROY(sc);
727 WPI_RXON_LOCK_DESTROY(sc);
728 WPI_TX_LOCK_DESTROY(sc);
729 WPI_LOCK_DESTROY(sc);
734 wpi_shutdown(device_t dev)
736 struct wpi_softc *sc = device_get_softc(dev);
743 wpi_suspend(device_t dev)
745 struct wpi_softc *sc = device_get_softc(dev);
746 struct ieee80211com *ic = &sc->sc_ic;
748 ieee80211_suspend_all(ic);
753 wpi_resume(device_t dev)
755 struct wpi_softc *sc = device_get_softc(dev);
756 struct ieee80211com *ic = &sc->sc_ic;
758 /* Clear device-specific "PCI retry timeout" register (41h). */
759 pci_write_config(dev, 0x41, 0, 1);
761 ieee80211_resume_all(ic);
766 * Grab exclusive access to NIC memory.
769 wpi_nic_lock(struct wpi_softc *sc)
773 /* Request exclusive access to NIC. */
774 WPI_SETBITS(sc, WPI_GP_CNTRL, WPI_GP_CNTRL_MAC_ACCESS_REQ);
776 /* Spin until we actually get the lock. */
777 for (ntries = 0; ntries < 1000; ntries++) {
778 if ((WPI_READ(sc, WPI_GP_CNTRL) &
779 (WPI_GP_CNTRL_MAC_ACCESS_ENA | WPI_GP_CNTRL_SLEEP)) ==
780 WPI_GP_CNTRL_MAC_ACCESS_ENA)
785 device_printf(sc->sc_dev, "could not lock memory\n");
791 * Release lock on NIC memory.
794 wpi_nic_unlock(struct wpi_softc *sc)
796 WPI_CLRBITS(sc, WPI_GP_CNTRL, WPI_GP_CNTRL_MAC_ACCESS_REQ);
799 static __inline uint32_t
800 wpi_prph_read(struct wpi_softc *sc, uint32_t addr)
802 WPI_WRITE(sc, WPI_PRPH_RADDR, WPI_PRPH_DWORD | addr);
803 WPI_BARRIER_READ_WRITE(sc);
804 return WPI_READ(sc, WPI_PRPH_RDATA);
808 wpi_prph_write(struct wpi_softc *sc, uint32_t addr, uint32_t data)
810 WPI_WRITE(sc, WPI_PRPH_WADDR, WPI_PRPH_DWORD | addr);
811 WPI_BARRIER_WRITE(sc);
812 WPI_WRITE(sc, WPI_PRPH_WDATA, data);
816 wpi_prph_setbits(struct wpi_softc *sc, uint32_t addr, uint32_t mask)
818 wpi_prph_write(sc, addr, wpi_prph_read(sc, addr) | mask);
822 wpi_prph_clrbits(struct wpi_softc *sc, uint32_t addr, uint32_t mask)
824 wpi_prph_write(sc, addr, wpi_prph_read(sc, addr) & ~mask);
828 wpi_prph_write_region_4(struct wpi_softc *sc, uint32_t addr,
829 const uint32_t *data, uint32_t count)
831 for (; count != 0; count--, data++, addr += 4)
832 wpi_prph_write(sc, addr, *data);
835 static __inline uint32_t
836 wpi_mem_read(struct wpi_softc *sc, uint32_t addr)
838 WPI_WRITE(sc, WPI_MEM_RADDR, addr);
839 WPI_BARRIER_READ_WRITE(sc);
840 return WPI_READ(sc, WPI_MEM_RDATA);
844 wpi_mem_read_region_4(struct wpi_softc *sc, uint32_t addr, uint32_t *data,
847 for (; count > 0; count--, addr += 4)
848 *data++ = wpi_mem_read(sc, addr);
852 wpi_read_prom_data(struct wpi_softc *sc, uint32_t addr, void *data, int count)
858 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__);
860 if ((error = wpi_nic_lock(sc)) != 0)
863 for (; count > 0; count -= 2, addr++) {
864 WPI_WRITE(sc, WPI_EEPROM, addr << 2);
865 for (ntries = 0; ntries < 10; ntries++) {
866 val = WPI_READ(sc, WPI_EEPROM);
867 if (val & WPI_EEPROM_READ_VALID)
872 device_printf(sc->sc_dev,
873 "timeout reading ROM at 0x%x\n", addr);
883 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
889 wpi_dma_map_addr(void *arg, bus_dma_segment_t *segs, int nsegs, int error)
893 KASSERT(nsegs == 1, ("too many DMA segments, %d should be 1", nsegs));
894 *(bus_addr_t *)arg = segs[0].ds_addr;
898 * Allocates a contiguous block of dma memory of the requested size and
902 wpi_dma_contig_alloc(struct wpi_softc *sc, struct wpi_dma_info *dma,
903 void **kvap, bus_size_t size, bus_size_t alignment)
910 error = bus_dma_tag_create(bus_get_dma_tag(sc->sc_dev), alignment,
911 0, BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL, size,
912 1, size, 0, NULL, NULL, &dma->tag);
916 error = bus_dmamem_alloc(dma->tag, (void **)&dma->vaddr,
917 BUS_DMA_NOWAIT | BUS_DMA_ZERO | BUS_DMA_COHERENT, &dma->map);
921 error = bus_dmamap_load(dma->tag, dma->map, dma->vaddr, size,
922 wpi_dma_map_addr, &dma->paddr, BUS_DMA_NOWAIT);
926 bus_dmamap_sync(dma->tag, dma->map, BUS_DMASYNC_PREWRITE);
933 fail: wpi_dma_contig_free(dma);
938 wpi_dma_contig_free(struct wpi_dma_info *dma)
940 if (dma->vaddr != NULL) {
941 bus_dmamap_sync(dma->tag, dma->map,
942 BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
943 bus_dmamap_unload(dma->tag, dma->map);
944 bus_dmamem_free(dma->tag, dma->vaddr, dma->map);
947 if (dma->tag != NULL) {
948 bus_dma_tag_destroy(dma->tag);
954 * Allocate a shared page between host and NIC.
957 wpi_alloc_shared(struct wpi_softc *sc)
959 /* Shared buffer must be aligned on a 4KB boundary. */
960 return wpi_dma_contig_alloc(sc, &sc->shared_dma,
961 (void **)&sc->shared, sizeof (struct wpi_shared), 4096);
965 wpi_free_shared(struct wpi_softc *sc)
967 wpi_dma_contig_free(&sc->shared_dma);
971 * Allocate DMA-safe memory for firmware transfer.
974 wpi_alloc_fwmem(struct wpi_softc *sc)
976 /* Must be aligned on a 16-byte boundary. */
977 return wpi_dma_contig_alloc(sc, &sc->fw_dma, NULL,
978 WPI_FW_TEXT_MAXSZ + WPI_FW_DATA_MAXSZ, 16);
982 wpi_free_fwmem(struct wpi_softc *sc)
984 wpi_dma_contig_free(&sc->fw_dma);
988 wpi_alloc_rx_ring(struct wpi_softc *sc)
990 struct wpi_rx_ring *ring = &sc->rxq;
997 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__);
999 /* Allocate RX descriptors (16KB aligned.) */
1000 size = WPI_RX_RING_COUNT * sizeof (uint32_t);
1001 error = wpi_dma_contig_alloc(sc, &ring->desc_dma,
1002 (void **)&ring->desc, size, WPI_RING_DMA_ALIGN);
1004 device_printf(sc->sc_dev,
1005 "%s: could not allocate RX ring DMA memory, error %d\n",
1010 /* Create RX buffer DMA tag. */
1011 error = bus_dma_tag_create(bus_get_dma_tag(sc->sc_dev), 1, 0,
1012 BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL,
1013 MJUMPAGESIZE, 1, MJUMPAGESIZE, 0, NULL, NULL, &ring->data_dmat);
1015 device_printf(sc->sc_dev,
1016 "%s: could not create RX buf DMA tag, error %d\n",
1022 * Allocate and map RX buffers.
1024 for (i = 0; i < WPI_RX_RING_COUNT; i++) {
1025 struct wpi_rx_data *data = &ring->data[i];
1028 error = bus_dmamap_create(ring->data_dmat, 0, &data->map);
1030 device_printf(sc->sc_dev,
1031 "%s: could not create RX buf DMA map, error %d\n",
1036 data->m = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, MJUMPAGESIZE);
1037 if (data->m == NULL) {
1038 device_printf(sc->sc_dev,
1039 "%s: could not allocate RX mbuf\n", __func__);
1044 error = bus_dmamap_load(ring->data_dmat, data->map,
1045 mtod(data->m, void *), MJUMPAGESIZE, wpi_dma_map_addr,
1046 &paddr, BUS_DMA_NOWAIT);
1047 if (error != 0 && error != EFBIG) {
1048 device_printf(sc->sc_dev,
1049 "%s: can't map mbuf (error %d)\n", __func__,
1054 /* Set physical address of RX buffer. */
1055 ring->desc[i] = htole32(paddr);
1058 bus_dmamap_sync(ring->desc_dma.tag, ring->desc_dma.map,
1059 BUS_DMASYNC_PREWRITE);
1061 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
1065 fail: wpi_free_rx_ring(sc);
1067 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END_ERR, __func__);
1073 wpi_update_rx_ring(struct wpi_softc *sc)
1075 WPI_WRITE(sc, WPI_FH_RX_WPTR, sc->rxq.cur & ~7);
1079 wpi_update_rx_ring_ps(struct wpi_softc *sc)
1081 struct wpi_rx_ring *ring = &sc->rxq;
1083 if (ring->update != 0) {
1084 /* Wait for INT_WAKEUP event. */
1089 WPI_SETBITS(sc, WPI_GP_CNTRL, WPI_GP_CNTRL_MAC_ACCESS_REQ);
1090 if (WPI_READ(sc, WPI_GP_CNTRL) & WPI_GP_CNTRL_SLEEP) {
1091 DPRINTF(sc, WPI_DEBUG_PWRSAVE, "%s: wakeup request\n",
1095 wpi_update_rx_ring(sc);
1096 WPI_CLRBITS(sc, WPI_GP_CNTRL, WPI_GP_CNTRL_MAC_ACCESS_REQ);
1102 wpi_reset_rx_ring(struct wpi_softc *sc)
1104 struct wpi_rx_ring *ring = &sc->rxq;
1107 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
1109 if (wpi_nic_lock(sc) == 0) {
1110 WPI_WRITE(sc, WPI_FH_RX_CONFIG, 0);
1111 for (ntries = 0; ntries < 1000; ntries++) {
1112 if (WPI_READ(sc, WPI_FH_RX_STATUS) &
1113 WPI_FH_RX_STATUS_IDLE)
1125 wpi_free_rx_ring(struct wpi_softc *sc)
1127 struct wpi_rx_ring *ring = &sc->rxq;
1130 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
1132 wpi_dma_contig_free(&ring->desc_dma);
1134 for (i = 0; i < WPI_RX_RING_COUNT; i++) {
1135 struct wpi_rx_data *data = &ring->data[i];
1137 if (data->m != NULL) {
1138 bus_dmamap_sync(ring->data_dmat, data->map,
1139 BUS_DMASYNC_POSTREAD);
1140 bus_dmamap_unload(ring->data_dmat, data->map);
1144 if (data->map != NULL)
1145 bus_dmamap_destroy(ring->data_dmat, data->map);
1147 if (ring->data_dmat != NULL) {
1148 bus_dma_tag_destroy(ring->data_dmat);
1149 ring->data_dmat = NULL;
1154 wpi_alloc_tx_ring(struct wpi_softc *sc, struct wpi_tx_ring *ring, uint8_t qid)
1166 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__);
1168 /* Allocate TX descriptors (16KB aligned.) */
1169 size = WPI_TX_RING_COUNT * sizeof (struct wpi_tx_desc);
1170 error = wpi_dma_contig_alloc(sc, &ring->desc_dma, (void **)&ring->desc,
1171 size, WPI_RING_DMA_ALIGN);
1173 device_printf(sc->sc_dev,
1174 "%s: could not allocate TX ring DMA memory, error %d\n",
1179 /* Update shared area with ring physical address. */
1180 sc->shared->txbase[qid] = htole32(ring->desc_dma.paddr);
1181 bus_dmamap_sync(sc->shared_dma.tag, sc->shared_dma.map,
1182 BUS_DMASYNC_PREWRITE);
1184 size = WPI_TX_RING_COUNT * sizeof (struct wpi_tx_cmd);
1185 error = wpi_dma_contig_alloc(sc, &ring->cmd_dma, (void **)&ring->cmd,
1188 device_printf(sc->sc_dev,
1189 "%s: could not allocate TX cmd DMA memory, error %d\n",
1194 error = bus_dma_tag_create(bus_get_dma_tag(sc->sc_dev), 1, 0,
1195 BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL, MCLBYTES,
1196 WPI_MAX_SCATTER - 1, MCLBYTES, 0, NULL, NULL, &ring->data_dmat);
1198 device_printf(sc->sc_dev,
1199 "%s: could not create TX buf DMA tag, error %d\n",
1204 paddr = ring->cmd_dma.paddr;
1205 for (i = 0; i < WPI_TX_RING_COUNT; i++) {
1206 struct wpi_tx_data *data = &ring->data[i];
1208 data->cmd_paddr = paddr;
1209 paddr += sizeof (struct wpi_tx_cmd);
1211 error = bus_dmamap_create(ring->data_dmat, 0, &data->map);
1213 device_printf(sc->sc_dev,
1214 "%s: could not create TX buf DMA map, error %d\n",
1220 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
1224 fail: wpi_free_tx_ring(sc, ring);
1225 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END_ERR, __func__);
1230 wpi_update_tx_ring(struct wpi_softc *sc, struct wpi_tx_ring *ring)
1232 WPI_WRITE(sc, WPI_HBUS_TARG_WRPTR, ring->qid << 8 | ring->cur);
1236 wpi_update_tx_ring_ps(struct wpi_softc *sc, struct wpi_tx_ring *ring)
1239 if (ring->update != 0) {
1240 /* Wait for INT_WAKEUP event. */
1244 WPI_SETBITS(sc, WPI_GP_CNTRL, WPI_GP_CNTRL_MAC_ACCESS_REQ);
1245 if (WPI_READ(sc, WPI_GP_CNTRL) & WPI_GP_CNTRL_SLEEP) {
1246 DPRINTF(sc, WPI_DEBUG_PWRSAVE, "%s (%d): requesting wakeup\n",
1247 __func__, ring->qid);
1250 wpi_update_tx_ring(sc, ring);
1251 WPI_CLRBITS(sc, WPI_GP_CNTRL, WPI_GP_CNTRL_MAC_ACCESS_REQ);
1256 wpi_reset_tx_ring(struct wpi_softc *sc, struct wpi_tx_ring *ring)
1260 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
1262 for (i = 0; i < WPI_TX_RING_COUNT; i++) {
1263 struct wpi_tx_data *data = &ring->data[i];
1265 if (data->m != NULL) {
1266 bus_dmamap_sync(ring->data_dmat, data->map,
1267 BUS_DMASYNC_POSTWRITE);
1268 bus_dmamap_unload(ring->data_dmat, data->map);
1272 if (data->ni != NULL) {
1273 ieee80211_free_node(data->ni);
1277 /* Clear TX descriptors. */
1278 memset(ring->desc, 0, ring->desc_dma.size);
1279 bus_dmamap_sync(ring->desc_dma.tag, ring->desc_dma.map,
1280 BUS_DMASYNC_PREWRITE);
1288 wpi_free_tx_ring(struct wpi_softc *sc, struct wpi_tx_ring *ring)
1292 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
1294 wpi_dma_contig_free(&ring->desc_dma);
1295 wpi_dma_contig_free(&ring->cmd_dma);
1297 for (i = 0; i < WPI_TX_RING_COUNT; i++) {
1298 struct wpi_tx_data *data = &ring->data[i];
1300 if (data->m != NULL) {
1301 bus_dmamap_sync(ring->data_dmat, data->map,
1302 BUS_DMASYNC_POSTWRITE);
1303 bus_dmamap_unload(ring->data_dmat, data->map);
1306 if (data->map != NULL)
1307 bus_dmamap_destroy(ring->data_dmat, data->map);
1309 if (ring->data_dmat != NULL) {
1310 bus_dma_tag_destroy(ring->data_dmat);
1311 ring->data_dmat = NULL;
1316 * Extract various information from EEPROM.
1319 wpi_read_eeprom(struct wpi_softc *sc, uint8_t macaddr[IEEE80211_ADDR_LEN])
1321 #define WPI_CHK(res) do { \
1322 if ((error = res) != 0) \
1328 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__);
1330 /* Adapter has to be powered on for EEPROM access to work. */
1331 if ((error = wpi_apm_init(sc)) != 0) {
1332 device_printf(sc->sc_dev,
1333 "%s: could not power ON adapter, error %d\n", __func__,
1338 if ((WPI_READ(sc, WPI_EEPROM_GP) & 0x6) == 0) {
1339 device_printf(sc->sc_dev, "bad EEPROM signature\n");
1343 /* Clear HW ownership of EEPROM. */
1344 WPI_CLRBITS(sc, WPI_EEPROM_GP, WPI_EEPROM_GP_IF_OWNER);
1346 /* Read the hardware capabilities, revision and SKU type. */
1347 WPI_CHK(wpi_read_prom_data(sc, WPI_EEPROM_SKU_CAP, &sc->cap,
1349 WPI_CHK(wpi_read_prom_data(sc, WPI_EEPROM_REVISION, &sc->rev,
1351 WPI_CHK(wpi_read_prom_data(sc, WPI_EEPROM_TYPE, &sc->type,
1354 sc->rev = le16toh(sc->rev);
1355 DPRINTF(sc, WPI_DEBUG_EEPROM, "cap=%x rev=%x type=%x\n", sc->cap,
1358 /* Read the regulatory domain (4 ASCII characters.) */
1359 WPI_CHK(wpi_read_prom_data(sc, WPI_EEPROM_DOMAIN, sc->domain,
1360 sizeof(sc->domain)));
1362 /* Read MAC address. */
1363 WPI_CHK(wpi_read_prom_data(sc, WPI_EEPROM_MAC, macaddr,
1364 IEEE80211_ADDR_LEN));
1366 /* Read the list of authorized channels. */
1367 for (i = 0; i < WPI_CHAN_BANDS_COUNT; i++)
1368 WPI_CHK(wpi_read_eeprom_channels(sc, i));
1370 /* Read the list of TX power groups. */
1371 for (i = 0; i < WPI_POWER_GROUPS_COUNT; i++)
1372 WPI_CHK(wpi_read_eeprom_group(sc, i));
1374 fail: wpi_apm_stop(sc); /* Power OFF adapter. */
1376 DPRINTF(sc, WPI_DEBUG_TRACE, error ? TRACE_STR_END_ERR : TRACE_STR_END,
1384 * Translate EEPROM flags to net80211.
1387 wpi_eeprom_channel_flags(struct wpi_eeprom_chan *channel)
1392 if ((channel->flags & WPI_EEPROM_CHAN_ACTIVE) == 0)
1393 nflags |= IEEE80211_CHAN_PASSIVE;
1394 if ((channel->flags & WPI_EEPROM_CHAN_IBSS) == 0)
1395 nflags |= IEEE80211_CHAN_NOADHOC;
1396 if (channel->flags & WPI_EEPROM_CHAN_RADAR) {
1397 nflags |= IEEE80211_CHAN_DFS;
1398 /* XXX apparently IBSS may still be marked */
1399 nflags |= IEEE80211_CHAN_NOADHOC;
1402 /* XXX HOSTAP uses WPI_MODE_IBSS */
1403 if (nflags & IEEE80211_CHAN_NOADHOC)
1404 nflags |= IEEE80211_CHAN_NOHOSTAP;
1410 wpi_read_eeprom_band(struct wpi_softc *sc, uint8_t n, int maxchans,
1411 int *nchans, struct ieee80211_channel chans[])
1413 struct wpi_eeprom_chan *channels = sc->eeprom_channels[n];
1414 const struct wpi_chan_band *band = &wpi_bands[n];
1415 struct ieee80211_channel *c;
1419 for (i = 0; i < band->nchan; i++) {
1420 if (!(channels[i].flags & WPI_EEPROM_CHAN_VALID)) {
1421 DPRINTF(sc, WPI_DEBUG_EEPROM,
1422 "Channel Not Valid: %d, band %d\n",
1427 if (*nchans >= maxchans)
1430 chan = band->chan[i];
1431 nflags = wpi_eeprom_channel_flags(&channels[i]);
1433 c = &chans[(*nchans)++];
1435 c->ic_maxregpower = channels[i].maxpwr;
1436 c->ic_maxpower = 2*c->ic_maxregpower;
1438 if (n == 0) { /* 2GHz band */
1439 c->ic_freq = ieee80211_ieee2mhz(chan,
1442 /* G =>'s B is supported */
1443 c->ic_flags = IEEE80211_CHAN_B | nflags;
1445 if (*nchans >= maxchans)
1448 c = &chans[(*nchans)++];
1450 c->ic_flags = IEEE80211_CHAN_G | nflags;
1451 } else { /* 5GHz band */
1452 c->ic_freq = ieee80211_ieee2mhz(chan,
1455 c->ic_flags = IEEE80211_CHAN_A | nflags;
1458 /* Save maximum allowed TX power for this channel. */
1459 sc->maxpwr[chan] = channels[i].maxpwr;
1461 DPRINTF(sc, WPI_DEBUG_EEPROM,
1462 "adding chan %d (%dMHz) flags=0x%x maxpwr=%d passive=%d,"
1463 " offset %d\n", chan, c->ic_freq,
1464 channels[i].flags, sc->maxpwr[chan],
1465 IEEE80211_IS_CHAN_PASSIVE(c), *nchans);
1470 * Read the eeprom to find out what channels are valid for the given
1471 * band and update net80211 with what we find.
1474 wpi_read_eeprom_channels(struct wpi_softc *sc, uint8_t n)
1476 struct ieee80211com *ic = &sc->sc_ic;
1477 const struct wpi_chan_band *band = &wpi_bands[n];
1480 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__);
1482 error = wpi_read_prom_data(sc, band->addr, &sc->eeprom_channels[n],
1483 band->nchan * sizeof (struct wpi_eeprom_chan));
1485 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END_ERR, __func__);
1489 wpi_read_eeprom_band(sc, n, IEEE80211_CHAN_MAX, &ic->ic_nchans,
1492 ieee80211_sort_channels(ic->ic_channels, ic->ic_nchans);
1494 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
1499 static struct wpi_eeprom_chan *
1500 wpi_find_eeprom_channel(struct wpi_softc *sc, struct ieee80211_channel *c)
1504 for (j = 0; j < WPI_CHAN_BANDS_COUNT; j++)
1505 for (i = 0; i < wpi_bands[j].nchan; i++)
1506 if (wpi_bands[j].chan[i] == c->ic_ieee &&
1507 ((j == 0) ^ IEEE80211_IS_CHAN_A(c)) == 1)
1508 return &sc->eeprom_channels[j][i];
1514 wpi_getradiocaps(struct ieee80211com *ic,
1515 int maxchans, int *nchans, struct ieee80211_channel chans[])
1517 struct wpi_softc *sc = ic->ic_softc;
1520 /* Parse the list of authorized channels. */
1521 for (i = 0; i < WPI_CHAN_BANDS_COUNT && *nchans < maxchans; i++)
1522 wpi_read_eeprom_band(sc, i, maxchans, nchans, chans);
1526 * Enforce flags read from EEPROM.
1529 wpi_setregdomain(struct ieee80211com *ic, struct ieee80211_regdomain *rd,
1530 int nchan, struct ieee80211_channel chans[])
1532 struct wpi_softc *sc = ic->ic_softc;
1535 for (i = 0; i < nchan; i++) {
1536 struct ieee80211_channel *c = &chans[i];
1537 struct wpi_eeprom_chan *channel;
1539 channel = wpi_find_eeprom_channel(sc, c);
1540 if (channel == NULL) {
1541 ic_printf(ic, "%s: invalid channel %u freq %u/0x%x\n",
1542 __func__, c->ic_ieee, c->ic_freq, c->ic_flags);
1545 c->ic_flags |= wpi_eeprom_channel_flags(channel);
1552 wpi_read_eeprom_group(struct wpi_softc *sc, uint8_t n)
1554 struct wpi_power_group *group = &sc->groups[n];
1555 struct wpi_eeprom_group rgroup;
1558 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__);
1560 if ((error = wpi_read_prom_data(sc, WPI_EEPROM_POWER_GRP + n * 32,
1561 &rgroup, sizeof rgroup)) != 0) {
1562 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END_ERR, __func__);
1566 /* Save TX power group information. */
1567 group->chan = rgroup.chan;
1568 group->maxpwr = rgroup.maxpwr;
1569 /* Retrieve temperature at which the samples were taken. */
1570 group->temp = (int16_t)le16toh(rgroup.temp);
1572 DPRINTF(sc, WPI_DEBUG_EEPROM,
1573 "power group %d: chan=%d maxpwr=%d temp=%d\n", n, group->chan,
1574 group->maxpwr, group->temp);
1576 for (i = 0; i < WPI_SAMPLES_COUNT; i++) {
1577 group->samples[i].index = rgroup.samples[i].index;
1578 group->samples[i].power = rgroup.samples[i].power;
1580 DPRINTF(sc, WPI_DEBUG_EEPROM,
1581 "\tsample %d: index=%d power=%d\n", i,
1582 group->samples[i].index, group->samples[i].power);
1585 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
1590 static __inline uint8_t
1591 wpi_add_node_entry_adhoc(struct wpi_softc *sc)
1593 uint8_t newid = WPI_ID_IBSS_MIN;
1595 for (; newid <= WPI_ID_IBSS_MAX; newid++) {
1596 if ((sc->nodesmsk & (1 << newid)) == 0) {
1597 sc->nodesmsk |= 1 << newid;
1602 return WPI_ID_UNDEFINED;
1605 static __inline uint8_t
1606 wpi_add_node_entry_sta(struct wpi_softc *sc)
1608 sc->nodesmsk |= 1 << WPI_ID_BSS;
1614 wpi_check_node_entry(struct wpi_softc *sc, uint8_t id)
1616 if (id == WPI_ID_UNDEFINED)
1619 return (sc->nodesmsk >> id) & 1;
1622 static __inline void
1623 wpi_clear_node_table(struct wpi_softc *sc)
1628 static __inline void
1629 wpi_del_node_entry(struct wpi_softc *sc, uint8_t id)
1631 sc->nodesmsk &= ~(1 << id);
1634 static struct ieee80211_node *
1635 wpi_node_alloc(struct ieee80211vap *vap, const uint8_t mac[IEEE80211_ADDR_LEN])
1637 struct wpi_node *wn;
1639 wn = malloc(sizeof (struct wpi_node), M_80211_NODE,
1645 wn->id = WPI_ID_UNDEFINED;
1651 wpi_node_free(struct ieee80211_node *ni)
1653 struct wpi_softc *sc = ni->ni_ic->ic_softc;
1654 struct wpi_node *wn = WPI_NODE(ni);
1656 if (wn->id != WPI_ID_UNDEFINED) {
1658 if (wpi_check_node_entry(sc, wn->id)) {
1659 wpi_del_node_entry(sc, wn->id);
1660 wpi_del_node(sc, ni);
1665 sc->sc_node_free(ni);
1669 wpi_check_bss_filter(struct wpi_softc *sc)
1671 return (sc->rxon.filter & htole32(WPI_FILTER_BSS)) != 0;
1675 wpi_ibss_recv_mgmt(struct ieee80211_node *ni, struct mbuf *m, int subtype,
1676 const struct ieee80211_rx_stats *rxs,
1679 struct ieee80211vap *vap = ni->ni_vap;
1680 struct wpi_softc *sc = vap->iv_ic->ic_softc;
1681 struct wpi_vap *wvp = WPI_VAP(vap);
1682 uint64_t ni_tstamp, rx_tstamp;
1684 wvp->wv_recv_mgmt(ni, m, subtype, rxs, rssi, nf);
1686 if (vap->iv_state == IEEE80211_S_RUN &&
1687 (subtype == IEEE80211_FC0_SUBTYPE_BEACON ||
1688 subtype == IEEE80211_FC0_SUBTYPE_PROBE_RESP)) {
1689 ni_tstamp = le64toh(ni->ni_tstamp.tsf);
1690 rx_tstamp = le64toh(sc->rx_tstamp);
1692 if (ni_tstamp >= rx_tstamp) {
1693 DPRINTF(sc, WPI_DEBUG_STATE,
1694 "ibss merge, tsf %ju tstamp %ju\n",
1695 (uintmax_t)rx_tstamp, (uintmax_t)ni_tstamp);
1696 (void) ieee80211_ibss_merge(ni);
1702 wpi_restore_node(void *arg, struct ieee80211_node *ni)
1704 struct wpi_softc *sc = arg;
1705 struct wpi_node *wn = WPI_NODE(ni);
1709 if (wn->id != WPI_ID_UNDEFINED) {
1710 wn->id = WPI_ID_UNDEFINED;
1711 if ((error = wpi_add_ibss_node(sc, ni)) != 0) {
1712 device_printf(sc->sc_dev,
1713 "%s: could not add IBSS node, error %d\n",
1721 wpi_restore_node_table(struct wpi_softc *sc, struct wpi_vap *wvp)
1723 struct ieee80211com *ic = &sc->sc_ic;
1725 /* Set group keys once. */
1730 ieee80211_iterate_nodes(&ic->ic_sta, wpi_restore_node, sc);
1731 ieee80211_crypto_reload_keys(ic);
1735 * Called by net80211 when ever there is a change to 80211 state machine
1738 wpi_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
1740 struct wpi_vap *wvp = WPI_VAP(vap);
1741 struct ieee80211com *ic = vap->iv_ic;
1742 struct wpi_softc *sc = ic->ic_softc;
1745 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__);
1748 if (nstate > IEEE80211_S_INIT && sc->sc_running == 0) {
1749 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END_ERR, __func__);
1756 DPRINTF(sc, WPI_DEBUG_STATE, "%s: %s -> %s\n", __func__,
1757 ieee80211_state_name[vap->iv_state],
1758 ieee80211_state_name[nstate]);
1760 if (vap->iv_state == IEEE80211_S_RUN && nstate < IEEE80211_S_RUN) {
1761 if ((error = wpi_set_pslevel(sc, 0, 0, 1)) != 0) {
1762 device_printf(sc->sc_dev,
1763 "%s: could not set power saving level\n",
1768 wpi_set_led(sc, WPI_LED_LINK, 1, 0);
1772 case IEEE80211_S_SCAN:
1774 if (wpi_check_bss_filter(sc) != 0) {
1775 sc->rxon.filter &= ~htole32(WPI_FILTER_BSS);
1776 if ((error = wpi_send_rxon(sc, 0, 1)) != 0) {
1777 device_printf(sc->sc_dev,
1778 "%s: could not send RXON\n", __func__);
1781 WPI_RXON_UNLOCK(sc);
1784 case IEEE80211_S_ASSOC:
1785 if (vap->iv_state != IEEE80211_S_RUN)
1788 case IEEE80211_S_AUTH:
1790 * NB: do not optimize AUTH -> AUTH state transmission -
1791 * this will break powersave with non-QoS AP!
1795 * The node must be registered in the firmware before auth.
1796 * Also the associd must be cleared on RUN -> ASSOC
1799 if ((error = wpi_auth(sc, vap)) != 0) {
1800 device_printf(sc->sc_dev,
1801 "%s: could not move to AUTH state, error %d\n",
1806 case IEEE80211_S_RUN:
1808 * RUN -> RUN transition:
1809 * STA mode: Just restart the timers.
1810 * IBSS mode: Process IBSS merge.
1812 if (vap->iv_state == IEEE80211_S_RUN) {
1813 if (vap->iv_opmode != IEEE80211_M_IBSS) {
1815 wpi_calib_timeout(sc);
1816 WPI_RXON_UNLOCK(sc);
1820 * Drop the BSS_FILTER bit
1821 * (there is no another way to change bssid).
1824 sc->rxon.filter &= ~htole32(WPI_FILTER_BSS);
1825 if ((error = wpi_send_rxon(sc, 0, 1)) != 0) {
1826 device_printf(sc->sc_dev,
1827 "%s: could not send RXON\n",
1830 WPI_RXON_UNLOCK(sc);
1832 /* Restore all what was lost. */
1833 wpi_restore_node_table(sc, wvp);
1835 /* XXX set conditionally? */
1841 * !RUN -> RUN requires setting the association id
1842 * which is done with a firmware cmd. We also defer
1843 * starting the timers until that work is done.
1845 if ((error = wpi_run(sc, vap)) != 0) {
1846 device_printf(sc->sc_dev,
1847 "%s: could not move to RUN state\n", __func__);
1855 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END_ERR, __func__);
1859 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
1861 return wvp->wv_newstate(vap, nstate, arg);
1865 wpi_calib_timeout(void *arg)
1867 struct wpi_softc *sc = arg;
1869 if (wpi_check_bss_filter(sc) == 0)
1872 wpi_power_calibration(sc);
1874 callout_reset(&sc->calib_to, 60*hz, wpi_calib_timeout, sc);
1877 static __inline uint8_t
1878 rate2plcp(const uint8_t rate)
1881 case 12: return 0xd;
1882 case 18: return 0xf;
1883 case 24: return 0x5;
1884 case 36: return 0x7;
1885 case 48: return 0x9;
1886 case 72: return 0xb;
1887 case 96: return 0x1;
1888 case 108: return 0x3;
1892 case 22: return 110;
1897 static __inline uint8_t
1898 plcp2rate(const uint8_t plcp)
1901 case 0xd: return 12;
1902 case 0xf: return 18;
1903 case 0x5: return 24;
1904 case 0x7: return 36;
1905 case 0x9: return 48;
1906 case 0xb: return 72;
1907 case 0x1: return 96;
1908 case 0x3: return 108;
1912 case 110: return 22;
1917 /* Quickly determine if a given rate is CCK or OFDM. */
1918 #define WPI_RATE_IS_OFDM(rate) ((rate) >= 12 && (rate) != 22)
1921 wpi_rx_done(struct wpi_softc *sc, struct wpi_rx_desc *desc,
1922 struct wpi_rx_data *data)
1924 struct ieee80211com *ic = &sc->sc_ic;
1925 struct wpi_rx_ring *ring = &sc->rxq;
1926 struct wpi_rx_stat *stat;
1927 struct wpi_rx_head *head;
1928 struct wpi_rx_tail *tail;
1929 struct ieee80211_frame *wh;
1930 struct ieee80211_node *ni;
1931 struct mbuf *m, *m1;
1937 stat = (struct wpi_rx_stat *)(desc + 1);
1939 if (__predict_false(stat->len > WPI_STAT_MAXLEN)) {
1940 device_printf(sc->sc_dev, "invalid RX statistic header\n");
1944 bus_dmamap_sync(ring->data_dmat, data->map, BUS_DMASYNC_POSTREAD);
1945 head = (struct wpi_rx_head *)((caddr_t)(stat + 1) + stat->len);
1946 len = le16toh(head->len);
1947 tail = (struct wpi_rx_tail *)((caddr_t)(head + 1) + len);
1948 flags = le32toh(tail->flags);
1950 DPRINTF(sc, WPI_DEBUG_RECV, "%s: idx %d len %d stat len %u rssi %d"
1951 " rate %x chan %d tstamp %ju\n", __func__, ring->cur,
1952 le32toh(desc->len), len, (int8_t)stat->rssi,
1953 head->plcp, head->chan, (uintmax_t)le64toh(tail->tstamp));
1955 /* Discard frames with a bad FCS early. */
1956 if ((flags & WPI_RX_NOERROR) != WPI_RX_NOERROR) {
1957 DPRINTF(sc, WPI_DEBUG_RECV, "%s: RX flags error %x\n",
1961 /* Discard frames that are too short. */
1962 if (len < sizeof (struct ieee80211_frame_ack)) {
1963 DPRINTF(sc, WPI_DEBUG_RECV, "%s: frame too short: %d\n",
1968 m1 = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, MJUMPAGESIZE);
1969 if (__predict_false(m1 == NULL)) {
1970 DPRINTF(sc, WPI_DEBUG_ANY, "%s: no mbuf to restock ring\n",
1974 bus_dmamap_unload(ring->data_dmat, data->map);
1976 error = bus_dmamap_load(ring->data_dmat, data->map, mtod(m1, void *),
1977 MJUMPAGESIZE, wpi_dma_map_addr, &paddr, BUS_DMA_NOWAIT);
1978 if (__predict_false(error != 0 && error != EFBIG)) {
1979 device_printf(sc->sc_dev,
1980 "%s: bus_dmamap_load failed, error %d\n", __func__, error);
1983 /* Try to reload the old mbuf. */
1984 error = bus_dmamap_load(ring->data_dmat, data->map,
1985 mtod(data->m, void *), MJUMPAGESIZE, wpi_dma_map_addr,
1986 &paddr, BUS_DMA_NOWAIT);
1987 if (error != 0 && error != EFBIG) {
1988 panic("%s: could not load old RX mbuf", __func__);
1990 /* Physical address may have changed. */
1991 ring->desc[ring->cur] = htole32(paddr);
1992 bus_dmamap_sync(ring->data_dmat, ring->desc_dma.map,
1993 BUS_DMASYNC_PREWRITE);
1999 /* Update RX descriptor. */
2000 ring->desc[ring->cur] = htole32(paddr);
2001 bus_dmamap_sync(ring->desc_dma.tag, ring->desc_dma.map,
2002 BUS_DMASYNC_PREWRITE);
2004 /* Finalize mbuf. */
2005 m->m_data = (caddr_t)(head + 1);
2006 m->m_pkthdr.len = m->m_len = len;
2008 /* Grab a reference to the source node. */
2009 wh = mtod(m, struct ieee80211_frame *);
2011 if ((wh->i_fc[1] & IEEE80211_FC1_PROTECTED) &&
2012 (flags & WPI_RX_CIPHER_MASK) == WPI_RX_CIPHER_CCMP) {
2013 /* Check whether decryption was successful or not. */
2014 if ((flags & WPI_RX_DECRYPT_MASK) != WPI_RX_DECRYPT_OK) {
2015 DPRINTF(sc, WPI_DEBUG_RECV,
2016 "CCMP decryption failed 0x%x\n", flags);
2019 m->m_flags |= M_WEP;
2022 if (len >= sizeof(struct ieee80211_frame_min))
2023 ni = ieee80211_find_rxnode(ic, (struct ieee80211_frame_min *)wh);
2027 sc->rx_tstamp = tail->tstamp;
2029 if (ieee80211_radiotap_active(ic)) {
2030 struct wpi_rx_radiotap_header *tap = &sc->sc_rxtap;
2033 if (head->flags & htole16(WPI_STAT_FLAG_SHPREAMBLE))
2034 tap->wr_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
2035 tap->wr_dbm_antsignal = (int8_t)(stat->rssi + WPI_RSSI_OFFSET);
2036 tap->wr_dbm_antnoise = WPI_RSSI_OFFSET;
2037 tap->wr_tsft = tail->tstamp;
2038 tap->wr_antenna = (le16toh(head->flags) >> 4) & 0xf;
2039 tap->wr_rate = plcp2rate(head->plcp);
2044 /* Send the frame to the 802.11 layer. */
2046 (void)ieee80211_input(ni, m, stat->rssi, WPI_RSSI_OFFSET);
2047 /* Node is no longer needed. */
2048 ieee80211_free_node(ni);
2050 (void)ieee80211_input_all(ic, m, stat->rssi, WPI_RSSI_OFFSET);
2058 fail1: counter_u64_add(ic->ic_ierrors, 1);
2062 wpi_rx_statistics(struct wpi_softc *sc, struct wpi_rx_desc *desc,
2063 struct wpi_rx_data *data)
2069 wpi_tx_done(struct wpi_softc *sc, struct wpi_rx_desc *desc)
2071 struct wpi_tx_ring *ring = &sc->txq[desc->qid & 0x3];
2072 struct wpi_tx_data *data = &ring->data[desc->idx];
2073 struct wpi_tx_stat *stat = (struct wpi_tx_stat *)(desc + 1);
2075 struct ieee80211_node *ni;
2076 struct ieee80211vap *vap;
2077 struct ieee80211com *ic;
2078 uint32_t status = le32toh(stat->status);
2079 int ackfailcnt = stat->ackfailcnt / WPI_NTRIES_DEFAULT;
2081 KASSERT(data->ni != NULL, ("no node"));
2082 KASSERT(data->m != NULL, ("no mbuf"));
2084 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__);
2086 DPRINTF(sc, WPI_DEBUG_XMIT, "%s: "
2087 "qid %d idx %d retries %d btkillcnt %d rate %x duration %d "
2088 "status %x\n", __func__, desc->qid, desc->idx, stat->ackfailcnt,
2089 stat->btkillcnt, stat->rate, le32toh(stat->duration), status);
2091 /* Unmap and free mbuf. */
2092 bus_dmamap_sync(ring->data_dmat, data->map, BUS_DMASYNC_POSTWRITE);
2093 bus_dmamap_unload(ring->data_dmat, data->map);
2094 m = data->m, data->m = NULL;
2095 ni = data->ni, data->ni = NULL;
2100 * Update rate control statistics for the node.
2102 if (status & WPI_TX_STATUS_FAIL) {
2103 ieee80211_ratectl_tx_complete(vap, ni,
2104 IEEE80211_RATECTL_TX_FAILURE, &ackfailcnt, NULL);
2106 ieee80211_ratectl_tx_complete(vap, ni,
2107 IEEE80211_RATECTL_TX_SUCCESS, &ackfailcnt, NULL);
2109 ieee80211_tx_complete(ni, m, (status & WPI_TX_STATUS_FAIL) != 0);
2111 WPI_TXQ_STATE_LOCK(sc);
2112 if (--ring->queued > 0)
2113 callout_reset(&sc->tx_timeout, 5*hz, wpi_tx_timeout, sc);
2115 callout_stop(&sc->tx_timeout);
2116 WPI_TXQ_STATE_UNLOCK(sc);
2118 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
2122 * Process a "command done" firmware notification. This is where we wakeup
2123 * processes waiting for a synchronous command completion.
2126 wpi_cmd_done(struct wpi_softc *sc, struct wpi_rx_desc *desc)
2128 struct wpi_tx_ring *ring = &sc->txq[WPI_CMD_QUEUE_NUM];
2129 struct wpi_tx_data *data;
2130 struct wpi_tx_cmd *cmd;
2132 DPRINTF(sc, WPI_DEBUG_CMD, "cmd notification qid %x idx %d flags %x "
2133 "type %s len %d\n", desc->qid, desc->idx,
2134 desc->flags, wpi_cmd_str(desc->type),
2135 le32toh(desc->len));
2137 if ((desc->qid & WPI_RX_DESC_QID_MSK) != WPI_CMD_QUEUE_NUM)
2138 return; /* Not a command ack. */
2140 KASSERT(ring->queued == 0, ("ring->queued must be 0"));
2142 data = &ring->data[desc->idx];
2143 cmd = &ring->cmd[desc->idx];
2145 /* If the command was mapped in an mbuf, free it. */
2146 if (data->m != NULL) {
2147 bus_dmamap_sync(ring->data_dmat, data->map,
2148 BUS_DMASYNC_POSTWRITE);
2149 bus_dmamap_unload(ring->data_dmat, data->map);
2156 if (desc->type == WPI_CMD_SET_POWER_MODE) {
2157 struct wpi_pmgt_cmd *pcmd = (struct wpi_pmgt_cmd *)cmd->data;
2159 bus_dmamap_sync(ring->data_dmat, ring->cmd_dma.map,
2160 BUS_DMASYNC_POSTREAD);
2163 if (le16toh(pcmd->flags) & WPI_PS_ALLOW_SLEEP) {
2164 sc->sc_update_rx_ring = wpi_update_rx_ring_ps;
2165 sc->sc_update_tx_ring = wpi_update_tx_ring_ps;
2167 sc->sc_update_rx_ring = wpi_update_rx_ring;
2168 sc->sc_update_tx_ring = wpi_update_tx_ring;
2175 wpi_notif_intr(struct wpi_softc *sc)
2177 struct ieee80211com *ic = &sc->sc_ic;
2178 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
2181 bus_dmamap_sync(sc->shared_dma.tag, sc->shared_dma.map,
2182 BUS_DMASYNC_POSTREAD);
2184 hw = le32toh(sc->shared->next) & 0xfff;
2185 hw = (hw == 0) ? WPI_RX_RING_COUNT - 1 : hw - 1;
2187 while (sc->rxq.cur != hw) {
2188 sc->rxq.cur = (sc->rxq.cur + 1) % WPI_RX_RING_COUNT;
2190 struct wpi_rx_data *data = &sc->rxq.data[sc->rxq.cur];
2191 struct wpi_rx_desc *desc;
2193 bus_dmamap_sync(sc->rxq.data_dmat, data->map,
2194 BUS_DMASYNC_POSTREAD);
2195 desc = mtod(data->m, struct wpi_rx_desc *);
2197 DPRINTF(sc, WPI_DEBUG_NOTIFY,
2198 "%s: cur=%d; qid %x idx %d flags %x type %d(%s) len %d\n",
2199 __func__, sc->rxq.cur, desc->qid, desc->idx, desc->flags,
2200 desc->type, wpi_cmd_str(desc->type), le32toh(desc->len));
2202 if (!(desc->qid & WPI_UNSOLICITED_RX_NOTIF)) {
2203 /* Reply to a command. */
2204 wpi_cmd_done(sc, desc);
2207 switch (desc->type) {
2209 /* An 802.11 frame has been received. */
2210 wpi_rx_done(sc, desc, data);
2212 if (__predict_false(sc->sc_running == 0)) {
2213 /* wpi_stop() was called. */
2220 /* An 802.11 frame has been transmitted. */
2221 wpi_tx_done(sc, desc);
2224 case WPI_RX_STATISTICS:
2225 case WPI_BEACON_STATISTICS:
2226 wpi_rx_statistics(sc, desc, data);
2229 case WPI_BEACON_MISSED:
2231 struct wpi_beacon_missed *miss =
2232 (struct wpi_beacon_missed *)(desc + 1);
2233 uint32_t expected, misses, received, threshold;
2235 bus_dmamap_sync(sc->rxq.data_dmat, data->map,
2236 BUS_DMASYNC_POSTREAD);
2238 misses = le32toh(miss->consecutive);
2239 expected = le32toh(miss->expected);
2240 received = le32toh(miss->received);
2241 threshold = MAX(2, vap->iv_bmissthreshold);
2243 DPRINTF(sc, WPI_DEBUG_BMISS,
2244 "%s: beacons missed %u(%u) (received %u/%u)\n",
2245 __func__, misses, le32toh(miss->total), received,
2248 if (misses >= threshold ||
2249 (received == 0 && expected >= threshold)) {
2251 if (callout_pending(&sc->scan_timeout)) {
2252 wpi_cmd(sc, WPI_CMD_SCAN_ABORT, NULL,
2255 WPI_RXON_UNLOCK(sc);
2256 if (vap->iv_state == IEEE80211_S_RUN &&
2257 (ic->ic_flags & IEEE80211_F_SCAN) == 0)
2258 ieee80211_beacon_miss(ic);
2264 case WPI_BEACON_SENT:
2266 struct wpi_tx_stat *stat =
2267 (struct wpi_tx_stat *)(desc + 1);
2268 uint64_t *tsf = (uint64_t *)(stat + 1);
2269 uint32_t *mode = (uint32_t *)(tsf + 1);
2271 bus_dmamap_sync(sc->rxq.data_dmat, data->map,
2272 BUS_DMASYNC_POSTREAD);
2274 DPRINTF(sc, WPI_DEBUG_BEACON,
2275 "beacon sent: rts %u, ack %u, btkill %u, rate %u, "
2276 "duration %u, status %x, tsf %ju, mode %x\n",
2277 stat->rtsfailcnt, stat->ackfailcnt,
2278 stat->btkillcnt, stat->rate, le32toh(stat->duration),
2279 le32toh(stat->status), le64toh(*tsf),
2287 struct wpi_ucode_info *uc =
2288 (struct wpi_ucode_info *)(desc + 1);
2290 /* The microcontroller is ready. */
2291 bus_dmamap_sync(sc->rxq.data_dmat, data->map,
2292 BUS_DMASYNC_POSTREAD);
2293 DPRINTF(sc, WPI_DEBUG_RESET,
2294 "microcode alive notification version=%d.%d "
2295 "subtype=%x alive=%x\n", uc->major, uc->minor,
2296 uc->subtype, le32toh(uc->valid));
2298 if (le32toh(uc->valid) != 1) {
2299 device_printf(sc->sc_dev,
2300 "microcontroller initialization failed\n");
2301 wpi_stop_locked(sc);
2304 /* Save the address of the error log in SRAM. */
2305 sc->errptr = le32toh(uc->errptr);
2308 case WPI_STATE_CHANGED:
2310 bus_dmamap_sync(sc->rxq.data_dmat, data->map,
2311 BUS_DMASYNC_POSTREAD);
2313 uint32_t *status = (uint32_t *)(desc + 1);
2315 DPRINTF(sc, WPI_DEBUG_STATE, "state changed to %x\n",
2318 if (le32toh(*status) & 1) {
2320 wpi_clear_node_table(sc);
2322 ieee80211_runtask(ic,
2323 &sc->sc_radiooff_task);
2329 case WPI_START_SCAN:
2331 bus_dmamap_sync(sc->rxq.data_dmat, data->map,
2332 BUS_DMASYNC_POSTREAD);
2334 struct wpi_start_scan *scan =
2335 (struct wpi_start_scan *)(desc + 1);
2336 DPRINTF(sc, WPI_DEBUG_SCAN,
2337 "%s: scanning channel %d status %x\n",
2338 __func__, scan->chan, le32toh(scan->status));
2345 bus_dmamap_sync(sc->rxq.data_dmat, data->map,
2346 BUS_DMASYNC_POSTREAD);
2348 struct wpi_stop_scan *scan =
2349 (struct wpi_stop_scan *)(desc + 1);
2351 DPRINTF(sc, WPI_DEBUG_SCAN,
2352 "scan finished nchan=%d status=%d chan=%d\n",
2353 scan->nchan, scan->status, scan->chan);
2356 callout_stop(&sc->scan_timeout);
2357 WPI_RXON_UNLOCK(sc);
2358 if (scan->status == WPI_SCAN_ABORTED)
2359 ieee80211_cancel_scan(vap);
2361 ieee80211_scan_next(vap);
2366 if (sc->rxq.cur % 8 == 0) {
2367 /* Tell the firmware what we have processed. */
2368 sc->sc_update_rx_ring(sc);
2374 * Process an INT_WAKEUP interrupt raised when the microcontroller wakes up
2375 * from power-down sleep mode.
2378 wpi_wakeup_intr(struct wpi_softc *sc)
2382 DPRINTF(sc, WPI_DEBUG_PWRSAVE,
2383 "%s: ucode wakeup from power-down sleep\n", __func__);
2385 /* Wakeup RX and TX rings. */
2386 if (sc->rxq.update) {
2388 wpi_update_rx_ring(sc);
2391 for (qid = 0; qid < WPI_DRV_NTXQUEUES; qid++) {
2392 struct wpi_tx_ring *ring = &sc->txq[qid];
2396 wpi_update_tx_ring(sc, ring);
2399 WPI_CLRBITS(sc, WPI_GP_CNTRL, WPI_GP_CNTRL_MAC_ACCESS_REQ);
2404 * This function prints firmware registers
2408 wpi_debug_registers(struct wpi_softc *sc)
2411 static const uint32_t csr_tbl[] = {
2428 static const uint32_t prph_tbl[] = {
2435 DPRINTF(sc, WPI_DEBUG_REGISTER,"%s","\n");
2437 for (i = 0; i < nitems(csr_tbl); i++) {
2438 DPRINTF(sc, WPI_DEBUG_REGISTER, " %-18s: 0x%08x ",
2439 wpi_get_csr_string(csr_tbl[i]), WPI_READ(sc, csr_tbl[i]));
2441 if ((i + 1) % 2 == 0)
2442 DPRINTF(sc, WPI_DEBUG_REGISTER, "\n");
2444 DPRINTF(sc, WPI_DEBUG_REGISTER, "\n\n");
2446 if (wpi_nic_lock(sc) == 0) {
2447 for (i = 0; i < nitems(prph_tbl); i++) {
2448 DPRINTF(sc, WPI_DEBUG_REGISTER, " %-18s: 0x%08x ",
2449 wpi_get_prph_string(prph_tbl[i]),
2450 wpi_prph_read(sc, prph_tbl[i]));
2452 if ((i + 1) % 2 == 0)
2453 DPRINTF(sc, WPI_DEBUG_REGISTER, "\n");
2455 DPRINTF(sc, WPI_DEBUG_REGISTER, "\n");
2458 DPRINTF(sc, WPI_DEBUG_REGISTER,
2459 "Cannot access internal registers.\n");
2465 * Dump the error log of the firmware when a firmware panic occurs. Although
2466 * we can't debug the firmware because it is neither open source nor free, it
2467 * can help us to identify certain classes of problems.
2470 wpi_fatal_intr(struct wpi_softc *sc)
2472 struct wpi_fw_dump dump;
2473 uint32_t i, offset, count;
2475 /* Check that the error log address is valid. */
2476 if (sc->errptr < WPI_FW_DATA_BASE ||
2477 sc->errptr + sizeof (dump) >
2478 WPI_FW_DATA_BASE + WPI_FW_DATA_MAXSZ) {
2479 printf("%s: bad firmware error log address 0x%08x\n", __func__,
2483 if (wpi_nic_lock(sc) != 0) {
2484 printf("%s: could not read firmware error log\n", __func__);
2487 /* Read number of entries in the log. */
2488 count = wpi_mem_read(sc, sc->errptr);
2489 if (count == 0 || count * sizeof (dump) > WPI_FW_DATA_MAXSZ) {
2490 printf("%s: invalid count field (count = %u)\n", __func__,
2495 /* Skip "count" field. */
2496 offset = sc->errptr + sizeof (uint32_t);
2497 printf("firmware error log (count = %u):\n", count);
2498 for (i = 0; i < count; i++) {
2499 wpi_mem_read_region_4(sc, offset, (uint32_t *)&dump,
2500 sizeof (dump) / sizeof (uint32_t));
2502 printf(" error type = \"%s\" (0x%08X)\n",
2503 (dump.desc < nitems(wpi_fw_errmsg)) ?
2504 wpi_fw_errmsg[dump.desc] : "UNKNOWN",
2506 printf(" error data = 0x%08X\n",
2508 printf(" branch link = 0x%08X%08X\n",
2509 dump.blink[0], dump.blink[1]);
2510 printf(" interrupt link = 0x%08X%08X\n",
2511 dump.ilink[0], dump.ilink[1]);
2512 printf(" time = %u\n", dump.time);
2514 offset += sizeof (dump);
2517 /* Dump driver status (TX and RX rings) while we're here. */
2518 printf("driver status:\n");
2520 for (i = 0; i < WPI_DRV_NTXQUEUES; i++) {
2521 struct wpi_tx_ring *ring = &sc->txq[i];
2522 printf(" tx ring %2d: qid=%-2d cur=%-3d queued=%-3d\n",
2523 i, ring->qid, ring->cur, ring->queued);
2526 printf(" rx ring: cur=%d\n", sc->rxq.cur);
2532 struct wpi_softc *sc = arg;
2537 /* Disable interrupts. */
2538 WPI_WRITE(sc, WPI_INT_MASK, 0);
2540 r1 = WPI_READ(sc, WPI_INT);
2542 if (__predict_false(r1 == 0xffffffff ||
2543 (r1 & 0xfffffff0) == 0xa5a5a5a0))
2544 goto end; /* Hardware gone! */
2546 r2 = WPI_READ(sc, WPI_FH_INT);
2548 DPRINTF(sc, WPI_DEBUG_INTR, "%s: reg1=0x%08x reg2=0x%08x\n", __func__,
2551 if (r1 == 0 && r2 == 0)
2552 goto done; /* Interrupt not for us. */
2554 /* Acknowledge interrupts. */
2555 WPI_WRITE(sc, WPI_INT, r1);
2556 WPI_WRITE(sc, WPI_FH_INT, r2);
2558 if (__predict_false(r1 & (WPI_INT_SW_ERR | WPI_INT_HW_ERR))) {
2559 struct ieee80211com *ic = &sc->sc_ic;
2561 device_printf(sc->sc_dev, "fatal firmware error\n");
2563 wpi_debug_registers(sc);
2566 DPRINTF(sc, WPI_DEBUG_HW,
2567 "(%s)\n", (r1 & WPI_INT_SW_ERR) ? "(Software Error)" :
2568 "(Hardware Error)");
2569 ieee80211_restart_all(ic);
2573 if ((r1 & (WPI_INT_FH_RX | WPI_INT_SW_RX)) ||
2574 (r2 & WPI_FH_INT_RX))
2577 if (r1 & WPI_INT_ALIVE)
2578 wakeup(sc); /* Firmware is alive. */
2580 if (r1 & WPI_INT_WAKEUP)
2581 wpi_wakeup_intr(sc);
2584 /* Re-enable interrupts. */
2585 if (__predict_true(sc->sc_running))
2586 WPI_WRITE(sc, WPI_INT_MASK, WPI_INT_MASK_DEF);
2588 end: WPI_UNLOCK(sc);
2592 wpi_free_txfrags(struct wpi_softc *sc, uint16_t ac)
2594 struct wpi_tx_ring *ring;
2595 struct wpi_tx_data *data;
2599 ring = &sc->txq[ac];
2601 while (ring->pending != 0) {
2603 cur = (ring->cur + ring->pending) % WPI_TX_RING_COUNT;
2604 data = &ring->data[cur];
2606 bus_dmamap_sync(ring->data_dmat, data->map,
2607 BUS_DMASYNC_POSTWRITE);
2608 bus_dmamap_unload(ring->data_dmat, data->map);
2612 ieee80211_node_decref(data->ni);
2620 wpi_cmd2(struct wpi_softc *sc, struct wpi_buf *buf)
2622 struct ieee80211_frame *wh;
2623 struct wpi_tx_cmd *cmd;
2624 struct wpi_tx_data *data;
2625 struct wpi_tx_desc *desc;
2626 struct wpi_tx_ring *ring;
2628 bus_dma_segment_t *seg, segs[WPI_MAX_SCATTER];
2631 int error, i, nsegs, totlen, frag;
2635 KASSERT(buf->size <= sizeof(buf->data), ("buffer overflow"));
2637 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__);
2639 if (__predict_false(sc->sc_running == 0)) {
2640 /* wpi_stop() was called */
2645 wh = mtod(buf->m, struct ieee80211_frame *);
2646 hdrlen = ieee80211_anyhdrsize(wh);
2647 totlen = buf->m->m_pkthdr.len;
2648 frag = ((buf->m->m_flags & (M_FRAG | M_LASTFRAG)) == M_FRAG);
2650 if (__predict_false(totlen < sizeof(struct ieee80211_frame_min))) {
2656 /* First segment length must be a multiple of 4. */
2657 pad = 4 - (hdrlen & 3);
2661 ring = &sc->txq[buf->ac];
2662 cur = (ring->cur + ring->pending) % WPI_TX_RING_COUNT;
2663 desc = &ring->desc[cur];
2664 data = &ring->data[cur];
2666 /* Prepare TX firmware command. */
2667 cmd = &ring->cmd[cur];
2668 cmd->code = buf->code;
2670 cmd->qid = ring->qid;
2673 memcpy(cmd->data, buf->data, buf->size);
2675 /* Save and trim IEEE802.11 header. */
2676 memcpy((uint8_t *)(cmd->data + buf->size), wh, hdrlen);
2677 m_adj(buf->m, hdrlen);
2679 error = bus_dmamap_load_mbuf_sg(ring->data_dmat, data->map, buf->m,
2680 segs, &nsegs, BUS_DMA_NOWAIT);
2681 if (error != 0 && error != EFBIG) {
2682 device_printf(sc->sc_dev,
2683 "%s: can't map mbuf (error %d)\n", __func__, error);
2687 /* Too many DMA segments, linearize mbuf. */
2688 m1 = m_collapse(buf->m, M_NOWAIT, WPI_MAX_SCATTER - 1);
2690 device_printf(sc->sc_dev,
2691 "%s: could not defrag mbuf\n", __func__);
2697 error = bus_dmamap_load_mbuf_sg(ring->data_dmat, data->map,
2698 buf->m, segs, &nsegs, BUS_DMA_NOWAIT);
2699 if (__predict_false(error != 0)) {
2700 /* XXX fix this (applicable to the iwn(4) too) */
2702 * NB: Do not return error;
2703 * original mbuf does not exist anymore.
2705 device_printf(sc->sc_dev,
2706 "%s: can't map mbuf (error %d)\n", __func__,
2708 if (ring->qid < WPI_CMD_QUEUE_NUM) {
2709 if_inc_counter(buf->ni->ni_vap->iv_ifp,
2710 IFCOUNTER_OERRORS, 1);
2712 ieee80211_free_node(buf->ni);
2720 KASSERT(nsegs < WPI_MAX_SCATTER,
2721 ("too many DMA segments, nsegs (%d) should be less than %d",
2722 nsegs, WPI_MAX_SCATTER));
2727 DPRINTF(sc, WPI_DEBUG_XMIT, "%s: qid %d idx %d len %d nsegs %d\n",
2728 __func__, ring->qid, cur, totlen, nsegs);
2730 /* Fill TX descriptor. */
2731 desc->nsegs = WPI_PAD32(totlen + pad) << 4 | (1 + nsegs);
2732 /* First DMA segment is used by the TX command. */
2733 desc->segs[0].addr = htole32(data->cmd_paddr);
2734 desc->segs[0].len = htole32(4 + buf->size + hdrlen + pad);
2735 /* Other DMA segments are for data payload. */
2737 for (i = 1; i <= nsegs; i++) {
2738 desc->segs[i].addr = htole32(seg->ds_addr);
2739 desc->segs[i].len = htole32(seg->ds_len);
2743 bus_dmamap_sync(ring->data_dmat, data->map, BUS_DMASYNC_PREWRITE);
2744 bus_dmamap_sync(ring->data_dmat, ring->cmd_dma.map,
2745 BUS_DMASYNC_PREWRITE);
2746 bus_dmamap_sync(ring->desc_dma.tag, ring->desc_dma.map,
2747 BUS_DMASYNC_PREWRITE);
2752 if (ring->qid < WPI_CMD_QUEUE_NUM) {
2753 WPI_TXQ_STATE_LOCK(sc);
2754 ring->queued += ring->pending;
2755 callout_reset(&sc->tx_timeout, 5*hz, wpi_tx_timeout,
2757 WPI_TXQ_STATE_UNLOCK(sc);
2761 ring->cur = (ring->cur + ring->pending) % WPI_TX_RING_COUNT;
2763 sc->sc_update_tx_ring(sc, ring);
2765 ieee80211_node_incref(data->ni);
2767 end: DPRINTF(sc, WPI_DEBUG_TRACE, error ? TRACE_STR_END_ERR : TRACE_STR_END,
2776 * Construct the data packet for a transmit buffer.
2779 wpi_tx_data(struct wpi_softc *sc, struct mbuf *m, struct ieee80211_node *ni)
2781 const struct ieee80211_txparam *tp;
2782 struct ieee80211vap *vap = ni->ni_vap;
2783 struct ieee80211com *ic = ni->ni_ic;
2784 struct wpi_node *wn = WPI_NODE(ni);
2785 struct ieee80211_channel *chan;
2786 struct ieee80211_frame *wh;
2787 struct ieee80211_key *k = NULL;
2788 struct wpi_buf tx_data;
2789 struct wpi_cmd_data *tx = (struct wpi_cmd_data *)&tx_data.data;
2792 uint8_t tid, type, rate;
2793 int swcrypt, ismcast, totlen;
2795 wh = mtod(m, struct ieee80211_frame *);
2796 type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK;
2797 ismcast = IEEE80211_IS_MULTICAST(wh->i_addr1);
2800 /* Select EDCA Access Category and TX ring for this frame. */
2801 if (IEEE80211_QOS_HAS_SEQ(wh)) {
2802 qos = ((const struct ieee80211_qosframe *)wh)->i_qos[0];
2803 tid = qos & IEEE80211_QOS_TID;
2808 ac = M_WME_GETAC(m);
2810 chan = (ni->ni_chan != IEEE80211_CHAN_ANYC) ?
2811 ni->ni_chan : ic->ic_curchan;
2812 tp = &vap->iv_txparms[ieee80211_chan2mode(chan)];
2814 /* Choose a TX rate index. */
2815 if (type == IEEE80211_FC0_TYPE_MGT)
2816 rate = tp->mgmtrate;
2818 rate = tp->mcastrate;
2819 else if (tp->ucastrate != IEEE80211_FIXED_RATE_NONE)
2820 rate = tp->ucastrate;
2821 else if (m->m_flags & M_EAPOL)
2822 rate = tp->mgmtrate;
2824 /* XXX pass pktlen */
2825 (void) ieee80211_ratectl_rate(ni, NULL, 0);
2826 rate = ni->ni_txrate;
2829 /* Encrypt the frame if need be. */
2830 if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) {
2831 /* Retrieve key for TX. */
2832 k = ieee80211_crypto_encap(ni, m);
2836 swcrypt = k->wk_flags & IEEE80211_KEY_SWCRYPT;
2838 /* 802.11 header may have moved. */
2839 wh = mtod(m, struct ieee80211_frame *);
2841 totlen = m->m_pkthdr.len;
2843 if (ieee80211_radiotap_active_vap(vap)) {
2844 struct wpi_tx_radiotap_header *tap = &sc->sc_txtap;
2847 tap->wt_rate = rate;
2849 tap->wt_flags |= IEEE80211_RADIOTAP_F_WEP;
2850 if (wh->i_fc[1] & IEEE80211_FC1_MORE_FRAG)
2851 tap->wt_flags |= IEEE80211_RADIOTAP_F_FRAG;
2853 ieee80211_radiotap_tx(vap, m);
2858 /* Unicast frame, check if an ACK is expected. */
2859 if (!qos || (qos & IEEE80211_QOS_ACKPOLICY) !=
2860 IEEE80211_QOS_ACKPOLICY_NOACK)
2861 flags |= WPI_TX_NEED_ACK;
2864 if (!IEEE80211_QOS_HAS_SEQ(wh))
2865 flags |= WPI_TX_AUTO_SEQ;
2866 if (wh->i_fc[1] & IEEE80211_FC1_MORE_FRAG)
2867 flags |= WPI_TX_MORE_FRAG;
2869 /* Check if frame must be protected using RTS/CTS or CTS-to-self. */
2871 /* NB: Group frames are sent using CCK in 802.11b/g. */
2872 if (totlen + IEEE80211_CRC_LEN > vap->iv_rtsthreshold) {
2873 flags |= WPI_TX_NEED_RTS;
2874 } else if ((ic->ic_flags & IEEE80211_F_USEPROT) &&
2875 WPI_RATE_IS_OFDM(rate)) {
2876 if (ic->ic_protmode == IEEE80211_PROT_CTSONLY)
2877 flags |= WPI_TX_NEED_CTS;
2878 else if (ic->ic_protmode == IEEE80211_PROT_RTSCTS)
2879 flags |= WPI_TX_NEED_RTS;
2882 if (flags & (WPI_TX_NEED_RTS | WPI_TX_NEED_CTS))
2883 flags |= WPI_TX_FULL_TXOP;
2886 memset(tx, 0, sizeof (struct wpi_cmd_data));
2887 if (type == IEEE80211_FC0_TYPE_MGT) {
2888 uint8_t subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK;
2890 /* Tell HW to set timestamp in probe responses. */
2891 if (subtype == IEEE80211_FC0_SUBTYPE_PROBE_RESP)
2892 flags |= WPI_TX_INSERT_TSTAMP;
2893 if (subtype == IEEE80211_FC0_SUBTYPE_ASSOC_REQ ||
2894 subtype == IEEE80211_FC0_SUBTYPE_REASSOC_REQ)
2895 tx->timeout = htole16(3);
2897 tx->timeout = htole16(2);
2900 if (ismcast || type != IEEE80211_FC0_TYPE_DATA)
2901 tx->id = WPI_ID_BROADCAST;
2903 if (wn->id == WPI_ID_UNDEFINED) {
2904 device_printf(sc->sc_dev,
2905 "%s: undefined node id\n", __func__);
2913 switch (k->wk_cipher->ic_cipher) {
2914 case IEEE80211_CIPHER_AES_CCM:
2915 tx->security = WPI_CIPHER_CCMP;
2922 memcpy(tx->key, k->wk_key, k->wk_keylen);
2925 if (wh->i_fc[1] & IEEE80211_FC1_MORE_FRAG) {
2926 struct mbuf *next = m->m_nextpkt;
2928 tx->lnext = htole16(next->m_pkthdr.len);
2929 tx->fnext = htole32(tx->security |
2930 (flags & WPI_TX_NEED_ACK) |
2931 WPI_NEXT_STA_ID(tx->id));
2934 tx->len = htole16(totlen);
2935 tx->flags = htole32(flags);
2936 tx->plcp = rate2plcp(rate);
2938 tx->lifetime = htole32(WPI_LIFETIME_INFINITE);
2939 tx->ofdm_mask = 0xff;
2940 tx->cck_mask = 0x0f;
2942 tx->data_ntries = tp->maxretry;
2946 tx_data.size = sizeof(struct wpi_cmd_data);
2947 tx_data.code = WPI_CMD_TX_DATA;
2950 return wpi_cmd2(sc, &tx_data);
2954 wpi_tx_data_raw(struct wpi_softc *sc, struct mbuf *m,
2955 struct ieee80211_node *ni, const struct ieee80211_bpf_params *params)
2957 struct ieee80211vap *vap = ni->ni_vap;
2958 struct ieee80211_key *k = NULL;
2959 struct ieee80211_frame *wh;
2960 struct wpi_buf tx_data;
2961 struct wpi_cmd_data *tx = (struct wpi_cmd_data *)&tx_data.data;
2963 uint8_t ac, type, rate;
2964 int swcrypt, totlen;
2966 wh = mtod(m, struct ieee80211_frame *);
2967 type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK;
2970 ac = params->ibp_pri & 3;
2972 /* Choose a TX rate index. */
2973 rate = params->ibp_rate0;
2976 if (!IEEE80211_QOS_HAS_SEQ(wh))
2977 flags |= WPI_TX_AUTO_SEQ;
2978 if ((params->ibp_flags & IEEE80211_BPF_NOACK) == 0)
2979 flags |= WPI_TX_NEED_ACK;
2980 if (params->ibp_flags & IEEE80211_BPF_RTS)
2981 flags |= WPI_TX_NEED_RTS;
2982 if (params->ibp_flags & IEEE80211_BPF_CTS)
2983 flags |= WPI_TX_NEED_CTS;
2984 if (flags & (WPI_TX_NEED_RTS | WPI_TX_NEED_CTS))
2985 flags |= WPI_TX_FULL_TXOP;
2987 /* Encrypt the frame if need be. */
2988 if (params->ibp_flags & IEEE80211_BPF_CRYPTO) {
2989 /* Retrieve key for TX. */
2990 k = ieee80211_crypto_encap(ni, m);
2994 swcrypt = k->wk_flags & IEEE80211_KEY_SWCRYPT;
2996 /* 802.11 header may have moved. */
2997 wh = mtod(m, struct ieee80211_frame *);
2999 totlen = m->m_pkthdr.len;
3001 if (ieee80211_radiotap_active_vap(vap)) {
3002 struct wpi_tx_radiotap_header *tap = &sc->sc_txtap;
3005 tap->wt_rate = rate;
3006 if (params->ibp_flags & IEEE80211_BPF_CRYPTO)
3007 tap->wt_flags |= IEEE80211_RADIOTAP_F_WEP;
3009 ieee80211_radiotap_tx(vap, m);
3012 memset(tx, 0, sizeof (struct wpi_cmd_data));
3013 if (type == IEEE80211_FC0_TYPE_MGT) {
3014 uint8_t subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK;
3016 /* Tell HW to set timestamp in probe responses. */
3017 if (subtype == IEEE80211_FC0_SUBTYPE_PROBE_RESP)
3018 flags |= WPI_TX_INSERT_TSTAMP;
3019 if (subtype == IEEE80211_FC0_SUBTYPE_ASSOC_REQ ||
3020 subtype == IEEE80211_FC0_SUBTYPE_REASSOC_REQ)
3021 tx->timeout = htole16(3);
3023 tx->timeout = htole16(2);
3027 switch (k->wk_cipher->ic_cipher) {
3028 case IEEE80211_CIPHER_AES_CCM:
3029 tx->security = WPI_CIPHER_CCMP;
3036 memcpy(tx->key, k->wk_key, k->wk_keylen);
3039 tx->len = htole16(totlen);
3040 tx->flags = htole32(flags);
3041 tx->plcp = rate2plcp(rate);
3042 tx->id = WPI_ID_BROADCAST;
3043 tx->lifetime = htole32(WPI_LIFETIME_INFINITE);
3044 tx->rts_ntries = params->ibp_try1;
3045 tx->data_ntries = params->ibp_try0;
3049 tx_data.size = sizeof(struct wpi_cmd_data);
3050 tx_data.code = WPI_CMD_TX_DATA;
3053 return wpi_cmd2(sc, &tx_data);
3057 wpi_tx_ring_free_space(struct wpi_softc *sc, uint16_t ac)
3059 struct wpi_tx_ring *ring = &sc->txq[ac];
3062 WPI_TXQ_STATE_LOCK(sc);
3063 retval = WPI_TX_RING_HIMARK - ring->queued;
3064 WPI_TXQ_STATE_UNLOCK(sc);
3070 wpi_raw_xmit(struct ieee80211_node *ni, struct mbuf *m,
3071 const struct ieee80211_bpf_params *params)
3073 struct ieee80211com *ic = ni->ni_ic;
3074 struct wpi_softc *sc = ic->ic_softc;
3078 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__);
3080 ac = M_WME_GETAC(m);
3084 /* NB: no fragments here */
3085 if (sc->sc_running == 0 || wpi_tx_ring_free_space(sc, ac) < 1) {
3086 error = sc->sc_running ? ENOBUFS : ENETDOWN;
3090 if (params == NULL) {
3092 * Legacy path; interpret frame contents to decide
3093 * precisely how to send the frame.
3095 error = wpi_tx_data(sc, m, ni);
3098 * Caller supplied explicit parameters to use in
3099 * sending the frame.
3101 error = wpi_tx_data_raw(sc, m, ni, params);
3104 unlock: WPI_TX_UNLOCK(sc);
3108 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END_ERR, __func__);
3113 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
3119 wpi_transmit(struct ieee80211com *ic, struct mbuf *m)
3121 struct wpi_softc *sc = ic->ic_softc;
3122 struct ieee80211_node *ni;
3128 DPRINTF(sc, WPI_DEBUG_XMIT, "%s: called\n", __func__);
3130 /* Check if interface is up & running. */
3131 if (__predict_false(sc->sc_running == 0)) {
3137 for (mnext = m->m_nextpkt; mnext != NULL; mnext = mnext->m_nextpkt)
3140 /* Check for available space. */
3141 ac = M_WME_GETAC(m);
3142 if (wpi_tx_ring_free_space(sc, ac) < nmbufs) {
3148 ni = (struct ieee80211_node *)m->m_pkthdr.rcvif;
3150 mnext = m->m_nextpkt;
3151 if (wpi_tx_data(sc, m, ni) != 0) {
3152 if_inc_counter(ni->ni_vap->iv_ifp, IFCOUNTER_OERRORS,
3154 wpi_free_txfrags(sc, ac);
3155 ieee80211_free_mbuf(m);
3156 ieee80211_free_node(ni);
3159 } while((m = mnext) != NULL);
3161 DPRINTF(sc, WPI_DEBUG_XMIT, "%s: done\n", __func__);
3163 unlock: WPI_TX_UNLOCK(sc);
3169 wpi_watchdog_rfkill(void *arg)
3171 struct wpi_softc *sc = arg;
3172 struct ieee80211com *ic = &sc->sc_ic;
3174 DPRINTF(sc, WPI_DEBUG_WATCHDOG, "RFkill Watchdog: tick\n");
3176 /* No need to lock firmware memory. */
3177 if ((wpi_prph_read(sc, WPI_APMG_RFKILL) & 0x1) == 0) {
3178 /* Radio kill switch is still off. */
3179 callout_reset(&sc->watchdog_rfkill, hz, wpi_watchdog_rfkill,
3182 ieee80211_runtask(ic, &sc->sc_radioon_task);
3186 wpi_scan_timeout(void *arg)
3188 struct wpi_softc *sc = arg;
3189 struct ieee80211com *ic = &sc->sc_ic;
3191 ic_printf(ic, "scan timeout\n");
3192 ieee80211_restart_all(ic);
3196 wpi_tx_timeout(void *arg)
3198 struct wpi_softc *sc = arg;
3199 struct ieee80211com *ic = &sc->sc_ic;
3201 ic_printf(ic, "device timeout\n");
3202 ieee80211_restart_all(ic);
3206 wpi_parent(struct ieee80211com *ic)
3208 struct wpi_softc *sc = ic->ic_softc;
3209 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
3211 if (ic->ic_nrunning > 0) {
3212 if (wpi_init(sc) == 0) {
3213 ieee80211_notify_radio(ic, 1);
3214 ieee80211_start_all(ic);
3216 ieee80211_notify_radio(ic, 0);
3217 ieee80211_stop(vap);
3220 ieee80211_notify_radio(ic, 0);
3226 * Send a command to the firmware.
3229 wpi_cmd(struct wpi_softc *sc, uint8_t code, const void *buf, uint16_t size,
3232 struct wpi_tx_ring *ring = &sc->txq[WPI_CMD_QUEUE_NUM];
3233 struct wpi_tx_desc *desc;
3234 struct wpi_tx_data *data;
3235 struct wpi_tx_cmd *cmd;
3243 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__);
3245 if (__predict_false(sc->sc_running == 0)) {
3246 /* wpi_stop() was called */
3247 if (code == WPI_CMD_SCAN)
3256 WPI_LOCK_ASSERT(sc);
3258 DPRINTF(sc, WPI_DEBUG_CMD, "%s: cmd %s size %u async %d\n",
3259 __func__, wpi_cmd_str(code), size, async);
3261 desc = &ring->desc[ring->cur];
3262 data = &ring->data[ring->cur];
3265 if (size > sizeof cmd->data) {
3266 /* Command is too large to fit in a descriptor. */
3267 if (totlen > MCLBYTES) {
3271 m = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, MJUMPAGESIZE);
3276 cmd = mtod(m, struct wpi_tx_cmd *);
3277 error = bus_dmamap_load(ring->data_dmat, data->map, cmd,
3278 totlen, wpi_dma_map_addr, &paddr, BUS_DMA_NOWAIT);
3285 cmd = &ring->cmd[ring->cur];
3286 paddr = data->cmd_paddr;
3291 cmd->qid = ring->qid;
3292 cmd->idx = ring->cur;
3293 memcpy(cmd->data, buf, size);
3295 desc->nsegs = 1 + (WPI_PAD32(size) << 4);
3296 desc->segs[0].addr = htole32(paddr);
3297 desc->segs[0].len = htole32(totlen);
3299 if (size > sizeof cmd->data) {
3300 bus_dmamap_sync(ring->data_dmat, data->map,
3301 BUS_DMASYNC_PREWRITE);
3303 bus_dmamap_sync(ring->data_dmat, ring->cmd_dma.map,
3304 BUS_DMASYNC_PREWRITE);
3306 bus_dmamap_sync(ring->desc_dma.tag, ring->desc_dma.map,
3307 BUS_DMASYNC_PREWRITE);
3309 /* Kick command ring. */
3310 ring->cur = (ring->cur + 1) % WPI_TX_RING_COUNT;
3311 sc->sc_update_tx_ring(sc, ring);
3313 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
3317 return async ? 0 : mtx_sleep(cmd, &sc->sc_mtx, PCATCH, "wpicmd", hz);
3319 fail: DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END_ERR, __func__);
3327 * Configure HW multi-rate retries.
3330 wpi_mrr_setup(struct wpi_softc *sc)
3332 struct ieee80211com *ic = &sc->sc_ic;
3333 struct wpi_mrr_setup mrr;
3337 /* CCK rates (not used with 802.11a). */
3338 for (i = WPI_RIDX_CCK1; i <= WPI_RIDX_CCK11; i++) {
3339 mrr.rates[i].flags = 0;
3340 mrr.rates[i].plcp = wpi_ridx_to_plcp[i];
3341 /* Fallback to the immediate lower CCK rate (if any.) */
3343 (i == WPI_RIDX_CCK1) ? WPI_RIDX_CCK1 : i - 1;
3344 /* Try twice at this rate before falling back to "next". */
3345 mrr.rates[i].ntries = WPI_NTRIES_DEFAULT;
3347 /* OFDM rates (not used with 802.11b). */
3348 for (i = WPI_RIDX_OFDM6; i <= WPI_RIDX_OFDM54; i++) {
3349 mrr.rates[i].flags = 0;
3350 mrr.rates[i].plcp = wpi_ridx_to_plcp[i];
3351 /* Fallback to the immediate lower rate (if any.) */
3352 /* We allow fallback from OFDM/6 to CCK/2 in 11b/g mode. */
3353 mrr.rates[i].next = (i == WPI_RIDX_OFDM6) ?
3354 ((ic->ic_curmode == IEEE80211_MODE_11A) ?
3355 WPI_RIDX_OFDM6 : WPI_RIDX_CCK2) :
3357 /* Try twice at this rate before falling back to "next". */
3358 mrr.rates[i].ntries = WPI_NTRIES_DEFAULT;
3360 /* Setup MRR for control frames. */
3361 mrr.which = htole32(WPI_MRR_CTL);
3362 error = wpi_cmd(sc, WPI_CMD_MRR_SETUP, &mrr, sizeof mrr, 0);
3364 device_printf(sc->sc_dev,
3365 "could not setup MRR for control frames\n");
3368 /* Setup MRR for data frames. */
3369 mrr.which = htole32(WPI_MRR_DATA);
3370 error = wpi_cmd(sc, WPI_CMD_MRR_SETUP, &mrr, sizeof mrr, 0);
3372 device_printf(sc->sc_dev,
3373 "could not setup MRR for data frames\n");
3380 wpi_add_node(struct wpi_softc *sc, struct ieee80211_node *ni)
3382 struct ieee80211com *ic = ni->ni_ic;
3383 struct wpi_vap *wvp = WPI_VAP(ni->ni_vap);
3384 struct wpi_node *wn = WPI_NODE(ni);
3385 struct wpi_node_info node;
3388 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
3390 if (wn->id == WPI_ID_UNDEFINED)
3393 memset(&node, 0, sizeof node);
3394 IEEE80211_ADDR_COPY(node.macaddr, ni->ni_macaddr);
3396 node.plcp = (ic->ic_curmode == IEEE80211_MODE_11A) ?
3397 wpi_ridx_to_plcp[WPI_RIDX_OFDM6] : wpi_ridx_to_plcp[WPI_RIDX_CCK1];
3398 node.action = htole32(WPI_ACTION_SET_RATE);
3399 node.antenna = WPI_ANTENNA_BOTH;
3401 DPRINTF(sc, WPI_DEBUG_NODE, "%s: adding node %d (%s)\n", __func__,
3402 wn->id, ether_sprintf(ni->ni_macaddr));
3404 error = wpi_cmd(sc, WPI_CMD_ADD_NODE, &node, sizeof node, 1);
3406 device_printf(sc->sc_dev,
3407 "%s: wpi_cmd() call failed with error code %d\n", __func__,
3412 if (wvp->wv_gtk != 0) {
3413 error = wpi_set_global_keys(ni);
3415 device_printf(sc->sc_dev,
3416 "%s: error while setting global keys\n", __func__);
3425 * Broadcast node is used to send group-addressed and management frames.
3428 wpi_add_broadcast_node(struct wpi_softc *sc, int async)
3430 struct ieee80211com *ic = &sc->sc_ic;
3431 struct wpi_node_info node;
3433 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
3435 memset(&node, 0, sizeof node);
3436 IEEE80211_ADDR_COPY(node.macaddr, ieee80211broadcastaddr);
3437 node.id = WPI_ID_BROADCAST;
3438 node.plcp = (ic->ic_curmode == IEEE80211_MODE_11A) ?
3439 wpi_ridx_to_plcp[WPI_RIDX_OFDM6] : wpi_ridx_to_plcp[WPI_RIDX_CCK1];
3440 node.action = htole32(WPI_ACTION_SET_RATE);
3441 node.antenna = WPI_ANTENNA_BOTH;
3443 DPRINTF(sc, WPI_DEBUG_NODE, "%s: adding broadcast node\n", __func__);
3445 return wpi_cmd(sc, WPI_CMD_ADD_NODE, &node, sizeof node, async);
3449 wpi_add_sta_node(struct wpi_softc *sc, struct ieee80211_node *ni)
3451 struct wpi_node *wn = WPI_NODE(ni);
3454 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
3456 wn->id = wpi_add_node_entry_sta(sc);
3458 if ((error = wpi_add_node(sc, ni)) != 0) {
3459 wpi_del_node_entry(sc, wn->id);
3460 wn->id = WPI_ID_UNDEFINED;
3468 wpi_add_ibss_node(struct wpi_softc *sc, struct ieee80211_node *ni)
3470 struct wpi_node *wn = WPI_NODE(ni);
3473 KASSERT(wn->id == WPI_ID_UNDEFINED,
3474 ("the node %d was added before", wn->id));
3476 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
3478 if ((wn->id = wpi_add_node_entry_adhoc(sc)) == WPI_ID_UNDEFINED) {
3479 device_printf(sc->sc_dev, "%s: h/w table is full\n", __func__);
3483 if ((error = wpi_add_node(sc, ni)) != 0) {
3484 wpi_del_node_entry(sc, wn->id);
3485 wn->id = WPI_ID_UNDEFINED;
3493 wpi_del_node(struct wpi_softc *sc, struct ieee80211_node *ni)
3495 struct wpi_node *wn = WPI_NODE(ni);
3496 struct wpi_cmd_del_node node;
3499 KASSERT(wn->id != WPI_ID_UNDEFINED, ("undefined node id passed"));
3501 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
3503 memset(&node, 0, sizeof node);
3504 IEEE80211_ADDR_COPY(node.macaddr, ni->ni_macaddr);
3507 DPRINTF(sc, WPI_DEBUG_NODE, "%s: deleting node %d (%s)\n", __func__,
3508 wn->id, ether_sprintf(ni->ni_macaddr));
3510 error = wpi_cmd(sc, WPI_CMD_DEL_NODE, &node, sizeof node, 1);
3512 device_printf(sc->sc_dev,
3513 "%s: could not delete node %u, error %d\n", __func__,
3519 wpi_updateedca(struct ieee80211com *ic)
3521 #define WPI_EXP2(x) ((1 << (x)) - 1) /* CWmin = 2^ECWmin - 1 */
3522 struct wpi_softc *sc = ic->ic_softc;
3523 struct wpi_edca_params cmd;
3526 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__);
3528 memset(&cmd, 0, sizeof cmd);
3529 cmd.flags = htole32(WPI_EDCA_UPDATE);
3530 for (aci = 0; aci < WME_NUM_AC; aci++) {
3531 const struct wmeParams *ac =
3532 &ic->ic_wme.wme_chanParams.cap_wmeParams[aci];
3533 cmd.ac[aci].aifsn = ac->wmep_aifsn;
3534 cmd.ac[aci].cwmin = htole16(WPI_EXP2(ac->wmep_logcwmin));
3535 cmd.ac[aci].cwmax = htole16(WPI_EXP2(ac->wmep_logcwmax));
3536 cmd.ac[aci].txoplimit =
3537 htole16(IEEE80211_TXOP_TO_US(ac->wmep_txopLimit));
3539 DPRINTF(sc, WPI_DEBUG_EDCA,
3540 "setting WME for queue %d aifsn=%d cwmin=%d cwmax=%d "
3541 "txoplimit=%d\n", aci, cmd.ac[aci].aifsn,
3542 cmd.ac[aci].cwmin, cmd.ac[aci].cwmax,
3543 cmd.ac[aci].txoplimit);
3545 error = wpi_cmd(sc, WPI_CMD_EDCA_PARAMS, &cmd, sizeof cmd, 1);
3547 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
3554 wpi_set_promisc(struct wpi_softc *sc)
3556 struct ieee80211com *ic = &sc->sc_ic;
3557 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
3558 uint32_t promisc_filter;
3560 promisc_filter = WPI_FILTER_CTL;
3561 if (vap != NULL && vap->iv_opmode != IEEE80211_M_HOSTAP)
3562 promisc_filter |= WPI_FILTER_PROMISC;
3564 if (ic->ic_promisc > 0)
3565 sc->rxon.filter |= htole32(promisc_filter);
3567 sc->rxon.filter &= ~htole32(promisc_filter);
3571 wpi_update_promisc(struct ieee80211com *ic)
3573 struct wpi_softc *sc = ic->ic_softc;
3576 if (sc->sc_running == 0) {
3583 wpi_set_promisc(sc);
3585 if (wpi_send_rxon(sc, 1, 1) != 0) {
3586 device_printf(sc->sc_dev, "%s: could not send RXON\n",
3589 WPI_RXON_UNLOCK(sc);
3593 wpi_update_mcast(struct ieee80211com *ic)
3599 wpi_set_led(struct wpi_softc *sc, uint8_t which, uint8_t off, uint8_t on)
3601 struct wpi_cmd_led led;
3603 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
3606 led.unit = htole32(100000); /* on/off in unit of 100ms */
3609 (void)wpi_cmd(sc, WPI_CMD_SET_LED, &led, sizeof led, 1);
3613 wpi_set_timing(struct wpi_softc *sc, struct ieee80211_node *ni)
3615 struct wpi_cmd_timing cmd;
3618 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
3620 memset(&cmd, 0, sizeof cmd);
3621 memcpy(&cmd.tstamp, ni->ni_tstamp.data, sizeof (uint64_t));
3622 cmd.bintval = htole16(ni->ni_intval);
3623 cmd.lintval = htole16(10);
3625 /* Compute remaining time until next beacon. */
3626 val = (uint64_t)ni->ni_intval * IEEE80211_DUR_TU;
3627 mod = le64toh(cmd.tstamp) % val;
3628 cmd.binitval = htole32((uint32_t)(val - mod));
3630 DPRINTF(sc, WPI_DEBUG_RESET, "timing bintval=%u tstamp=%ju, init=%u\n",
3631 ni->ni_intval, le64toh(cmd.tstamp), (uint32_t)(val - mod));
3633 return wpi_cmd(sc, WPI_CMD_TIMING, &cmd, sizeof cmd, 1);
3637 * This function is called periodically (every 60 seconds) to adjust output
3638 * power to temperature changes.
3641 wpi_power_calibration(struct wpi_softc *sc)
3645 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
3647 /* Update sensor data. */
3648 temp = (int)WPI_READ(sc, WPI_UCODE_GP2);
3649 DPRINTF(sc, WPI_DEBUG_TEMP, "Temp in calibration is: %d\n", temp);
3651 /* Sanity-check read value. */
3652 if (temp < -260 || temp > 25) {
3653 /* This can't be correct, ignore. */
3654 DPRINTF(sc, WPI_DEBUG_TEMP,
3655 "out-of-range temperature reported: %d\n", temp);
3659 DPRINTF(sc, WPI_DEBUG_TEMP, "temperature %d->%d\n", sc->temp, temp);
3661 /* Adjust Tx power if need be. */
3662 if (abs(temp - sc->temp) <= 6)
3667 if (wpi_set_txpower(sc, 1) != 0) {
3668 /* just warn, too bad for the automatic calibration... */
3669 device_printf(sc->sc_dev,"could not adjust Tx power\n");
3674 * Set TX power for current channel.
3677 wpi_set_txpower(struct wpi_softc *sc, int async)
3679 struct wpi_power_group *group;
3680 struct wpi_cmd_txpower cmd;
3682 int idx, is_chan_5ghz, i;
3684 /* Retrieve current channel from last RXON. */
3685 chan = sc->rxon.chan;
3686 is_chan_5ghz = (sc->rxon.flags & htole32(WPI_RXON_24GHZ)) == 0;
3688 /* Find the TX power group to which this channel belongs. */
3690 for (group = &sc->groups[1]; group < &sc->groups[4]; group++)
3691 if (chan <= group->chan)
3694 group = &sc->groups[0];
3696 memset(&cmd, 0, sizeof cmd);
3697 cmd.band = is_chan_5ghz ? WPI_BAND_5GHZ : WPI_BAND_2GHZ;
3698 cmd.chan = htole16(chan);
3700 /* Set TX power for all OFDM and CCK rates. */
3701 for (i = 0; i <= WPI_RIDX_MAX ; i++) {
3702 /* Retrieve TX power for this channel/rate. */
3703 idx = wpi_get_power_index(sc, group, chan, is_chan_5ghz, i);
3705 cmd.rates[i].plcp = wpi_ridx_to_plcp[i];
3708 cmd.rates[i].rf_gain = wpi_rf_gain_5ghz[idx];
3709 cmd.rates[i].dsp_gain = wpi_dsp_gain_5ghz[idx];
3711 cmd.rates[i].rf_gain = wpi_rf_gain_2ghz[idx];
3712 cmd.rates[i].dsp_gain = wpi_dsp_gain_2ghz[idx];
3714 DPRINTF(sc, WPI_DEBUG_TEMP,
3715 "chan %d/ridx %d: power index %d\n", chan, i, idx);
3718 return wpi_cmd(sc, WPI_CMD_TXPOWER, &cmd, sizeof cmd, async);
3722 * Determine Tx power index for a given channel/rate combination.
3723 * This takes into account the regulatory information from EEPROM and the
3724 * current temperature.
3727 wpi_get_power_index(struct wpi_softc *sc, struct wpi_power_group *group,
3728 uint8_t chan, int is_chan_5ghz, int ridx)
3730 /* Fixed-point arithmetic division using a n-bit fractional part. */
3731 #define fdivround(a, b, n) \
3732 ((((1 << n) * (a)) / (b) + (1 << n) / 2) / (1 << n))
3734 /* Linear interpolation. */
3735 #define interpolate(x, x1, y1, x2, y2, n) \
3736 ((y1) + fdivround(((x) - (x1)) * ((y2) - (y1)), (x2) - (x1), n))
3738 struct wpi_power_sample *sample;
3741 /* Default TX power is group maximum TX power minus 3dB. */
3742 pwr = group->maxpwr / 2;
3744 /* Decrease TX power for highest OFDM rates to reduce distortion. */
3746 case WPI_RIDX_OFDM36:
3747 pwr -= is_chan_5ghz ? 5 : 0;
3749 case WPI_RIDX_OFDM48:
3750 pwr -= is_chan_5ghz ? 10 : 7;
3752 case WPI_RIDX_OFDM54:
3753 pwr -= is_chan_5ghz ? 12 : 9;
3757 /* Never exceed the channel maximum allowed TX power. */
3758 pwr = min(pwr, sc->maxpwr[chan]);
3760 /* Retrieve TX power index into gain tables from samples. */
3761 for (sample = group->samples; sample < &group->samples[3]; sample++)
3762 if (pwr > sample[1].power)
3764 /* Fixed-point linear interpolation using a 19-bit fractional part. */
3765 idx = interpolate(pwr, sample[0].power, sample[0].index,
3766 sample[1].power, sample[1].index, 19);
3769 * Adjust power index based on current temperature:
3770 * - if cooler than factory-calibrated: decrease output power
3771 * - if warmer than factory-calibrated: increase output power
3773 idx -= (sc->temp - group->temp) * 11 / 100;
3775 /* Decrease TX power for CCK rates (-5dB). */
3776 if (ridx >= WPI_RIDX_CCK1)
3779 /* Make sure idx stays in a valid range. */
3782 if (idx > WPI_MAX_PWR_INDEX)
3783 return WPI_MAX_PWR_INDEX;
3791 * Set STA mode power saving level (between 0 and 5).
3792 * Level 0 is CAM (Continuously Aware Mode), 5 is for maximum power saving.
3795 wpi_set_pslevel(struct wpi_softc *sc, uint8_t dtim, int level, int async)
3797 struct wpi_pmgt_cmd cmd;
3798 const struct wpi_pmgt *pmgt;
3803 DPRINTF(sc, WPI_DEBUG_PWRSAVE,
3804 "%s: dtim=%d, level=%d, async=%d\n",
3805 __func__, dtim, level, async);
3807 /* Select which PS parameters to use. */
3809 pmgt = &wpi_pmgt[0][level];
3811 pmgt = &wpi_pmgt[1][level];
3813 memset(&cmd, 0, sizeof cmd);
3814 if (level != 0) /* not CAM */
3815 cmd.flags |= htole16(WPI_PS_ALLOW_SLEEP);
3816 /* Retrieve PCIe Active State Power Management (ASPM). */
3817 reg = pci_read_config(sc->sc_dev, sc->sc_cap_off + PCIER_LINK_CTL, 1);
3818 if (!(reg & PCIEM_LINK_CTL_ASPMC_L0S)) /* L0s Entry disabled. */
3819 cmd.flags |= htole16(WPI_PS_PCI_PMGT);
3821 cmd.rxtimeout = htole32(pmgt->rxtimeout * IEEE80211_DUR_TU);
3822 cmd.txtimeout = htole32(pmgt->txtimeout * IEEE80211_DUR_TU);
3828 skip_dtim = pmgt->skip_dtim;
3830 if (skip_dtim != 0) {
3831 cmd.flags |= htole16(WPI_PS_SLEEP_OVER_DTIM);
3832 max = pmgt->intval[4];
3833 if (max == (uint32_t)-1)
3834 max = dtim * (skip_dtim + 1);
3835 else if (max > dtim)
3836 max = (max / dtim) * dtim;
3840 for (i = 0; i < 5; i++)
3841 cmd.intval[i] = htole32(MIN(max, pmgt->intval[i]));
3843 return wpi_cmd(sc, WPI_CMD_SET_POWER_MODE, &cmd, sizeof cmd, async);
3847 wpi_send_btcoex(struct wpi_softc *sc)
3849 struct wpi_bluetooth cmd;
3851 memset(&cmd, 0, sizeof cmd);
3852 cmd.flags = WPI_BT_COEX_MODE_4WIRE;
3853 cmd.lead_time = WPI_BT_LEAD_TIME_DEF;
3854 cmd.max_kill = WPI_BT_MAX_KILL_DEF;
3855 DPRINTF(sc, WPI_DEBUG_RESET, "%s: configuring bluetooth coexistence\n",
3857 return wpi_cmd(sc, WPI_CMD_BT_COEX, &cmd, sizeof(cmd), 0);
3861 wpi_send_rxon(struct wpi_softc *sc, int assoc, int async)
3866 WPI_RXON_LOCK_ASSERT(sc);
3868 if (assoc && wpi_check_bss_filter(sc) != 0) {
3869 struct wpi_assoc rxon_assoc;
3871 rxon_assoc.flags = sc->rxon.flags;
3872 rxon_assoc.filter = sc->rxon.filter;
3873 rxon_assoc.ofdm_mask = sc->rxon.ofdm_mask;
3874 rxon_assoc.cck_mask = sc->rxon.cck_mask;
3875 rxon_assoc.reserved = 0;
3877 error = wpi_cmd(sc, WPI_CMD_RXON_ASSOC, &rxon_assoc,
3878 sizeof (struct wpi_assoc), async);
3880 device_printf(sc->sc_dev,
3881 "RXON_ASSOC command failed, error %d\n", error);
3887 error = wpi_cmd(sc, WPI_CMD_RXON, &sc->rxon,
3888 sizeof (struct wpi_rxon), async);
3890 wpi_clear_node_table(sc);
3893 error = wpi_cmd(sc, WPI_CMD_RXON, &sc->rxon,
3894 sizeof (struct wpi_rxon), async);
3896 wpi_clear_node_table(sc);
3900 device_printf(sc->sc_dev,
3901 "RXON command failed, error %d\n", error);
3905 /* Add broadcast node. */
3906 error = wpi_add_broadcast_node(sc, async);
3908 device_printf(sc->sc_dev,
3909 "could not add broadcast node, error %d\n", error);
3914 /* Configuration has changed, set Tx power accordingly. */
3915 if ((error = wpi_set_txpower(sc, async)) != 0) {
3916 device_printf(sc->sc_dev,
3917 "%s: could not set TX power, error %d\n", __func__, error);
3925 * Configure the card to listen to a particular channel, this transisions the
3926 * card in to being able to receive frames from remote devices.
3929 wpi_config(struct wpi_softc *sc)
3931 struct ieee80211com *ic = &sc->sc_ic;
3932 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
3933 struct ieee80211_channel *c = ic->ic_curchan;
3936 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__);
3938 /* Set power saving level to CAM during initialization. */
3939 if ((error = wpi_set_pslevel(sc, 0, 0, 0)) != 0) {
3940 device_printf(sc->sc_dev,
3941 "%s: could not set power saving level\n", __func__);
3945 /* Configure bluetooth coexistence. */
3946 if ((error = wpi_send_btcoex(sc)) != 0) {
3947 device_printf(sc->sc_dev,
3948 "could not configure bluetooth coexistence\n");
3952 /* Configure adapter. */
3953 memset(&sc->rxon, 0, sizeof (struct wpi_rxon));
3954 IEEE80211_ADDR_COPY(sc->rxon.myaddr, vap->iv_myaddr);
3956 /* Set default channel. */
3957 sc->rxon.chan = ieee80211_chan2ieee(ic, c);
3958 sc->rxon.flags = htole32(WPI_RXON_TSF | WPI_RXON_CTS_TO_SELF);
3959 if (IEEE80211_IS_CHAN_2GHZ(c))
3960 sc->rxon.flags |= htole32(WPI_RXON_AUTO | WPI_RXON_24GHZ);
3962 sc->rxon.filter = WPI_FILTER_MULTICAST;
3963 switch (ic->ic_opmode) {
3964 case IEEE80211_M_STA:
3965 sc->rxon.mode = WPI_MODE_STA;
3967 case IEEE80211_M_IBSS:
3968 sc->rxon.mode = WPI_MODE_IBSS;
3969 sc->rxon.filter |= WPI_FILTER_BEACON;
3971 case IEEE80211_M_HOSTAP:
3972 /* XXX workaround for beaconing */
3973 sc->rxon.mode = WPI_MODE_IBSS;
3974 sc->rxon.filter |= WPI_FILTER_ASSOC | WPI_FILTER_PROMISC;
3976 case IEEE80211_M_AHDEMO:
3977 sc->rxon.mode = WPI_MODE_HOSTAP;
3979 case IEEE80211_M_MONITOR:
3980 sc->rxon.mode = WPI_MODE_MONITOR;
3983 device_printf(sc->sc_dev, "unknown opmode %d\n",
3987 sc->rxon.filter = htole32(sc->rxon.filter);
3988 wpi_set_promisc(sc);
3989 sc->rxon.cck_mask = 0x0f; /* not yet negotiated */
3990 sc->rxon.ofdm_mask = 0xff; /* not yet negotiated */
3992 if ((error = wpi_send_rxon(sc, 0, 0)) != 0) {
3993 device_printf(sc->sc_dev, "%s: could not send RXON\n",
3998 /* Setup rate scalling. */
3999 if ((error = wpi_mrr_setup(sc)) != 0) {
4000 device_printf(sc->sc_dev, "could not setup MRR, error %d\n",
4005 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
4011 wpi_get_active_dwell_time(struct wpi_softc *sc,
4012 struct ieee80211_channel *c, uint8_t n_probes)
4014 /* No channel? Default to 2GHz settings. */
4015 if (c == NULL || IEEE80211_IS_CHAN_2GHZ(c)) {
4016 return (WPI_ACTIVE_DWELL_TIME_2GHZ +
4017 WPI_ACTIVE_DWELL_FACTOR_2GHZ * (n_probes + 1));
4020 /* 5GHz dwell time. */
4021 return (WPI_ACTIVE_DWELL_TIME_5GHZ +
4022 WPI_ACTIVE_DWELL_FACTOR_5GHZ * (n_probes + 1));
4026 * Limit the total dwell time.
4028 * Returns the dwell time in milliseconds.
4031 wpi_limit_dwell(struct wpi_softc *sc, uint16_t dwell_time)
4033 struct ieee80211com *ic = &sc->sc_ic;
4034 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
4035 uint16_t bintval = 0;
4037 /* bintval is in TU (1.024mS) */
4039 bintval = vap->iv_bss->ni_intval;
4042 * If it's non-zero, we should calculate the minimum of
4043 * it and the DWELL_BASE.
4045 * XXX Yes, the math should take into account that bintval
4046 * is 1.024mS, not 1mS..
4049 DPRINTF(sc, WPI_DEBUG_SCAN, "%s: bintval=%d\n", __func__,
4051 return (MIN(dwell_time, bintval - WPI_CHANNEL_TUNE_TIME * 2));
4054 /* No association context? Default. */
4059 wpi_get_passive_dwell_time(struct wpi_softc *sc, struct ieee80211_channel *c)
4063 if (c == NULL || IEEE80211_IS_CHAN_2GHZ(c))
4064 passive = WPI_PASSIVE_DWELL_BASE + WPI_PASSIVE_DWELL_TIME_2GHZ;
4066 passive = WPI_PASSIVE_DWELL_BASE + WPI_PASSIVE_DWELL_TIME_5GHZ;
4068 /* Clamp to the beacon interval if we're associated. */
4069 return (wpi_limit_dwell(sc, passive));
4073 wpi_get_scan_pause_time(uint32_t time, uint16_t bintval)
4075 uint32_t mod = (time % bintval) * IEEE80211_DUR_TU;
4076 uint32_t nbeacons = time / bintval;
4078 if (mod > WPI_PAUSE_MAX_TIME)
4079 mod = WPI_PAUSE_MAX_TIME;
4081 return WPI_PAUSE_SCAN(nbeacons, mod);
4085 * Send a scan request to the firmware.
4088 wpi_scan(struct wpi_softc *sc, struct ieee80211_channel *c)
4090 struct ieee80211com *ic = &sc->sc_ic;
4091 struct ieee80211_scan_state *ss = ic->ic_scan;
4092 struct ieee80211vap *vap = ss->ss_vap;
4093 struct wpi_scan_hdr *hdr;
4094 struct wpi_cmd_data *tx;
4095 struct wpi_scan_essid *essids;
4096 struct wpi_scan_chan *chan;
4097 struct ieee80211_frame *wh;
4098 struct ieee80211_rateset *rs;
4099 uint16_t bintval, buflen, dwell_active, dwell_passive;
4100 uint8_t *buf, *frm, i, nssid;
4103 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__);
4106 * We are absolutely not allowed to send a scan command when another
4107 * scan command is pending.
4109 if (callout_pending(&sc->scan_timeout)) {
4110 device_printf(sc->sc_dev, "%s: called whilst scanning!\n",
4116 bgscan = wpi_check_bss_filter(sc);
4117 bintval = vap->iv_bss->ni_intval;
4119 bintval < WPI_QUIET_TIME_DEFAULT + WPI_CHANNEL_TUNE_TIME * 2) {
4124 buf = malloc(WPI_SCAN_MAXSZ, M_DEVBUF, M_NOWAIT | M_ZERO);
4126 device_printf(sc->sc_dev,
4127 "%s: could not allocate buffer for scan command\n",
4132 hdr = (struct wpi_scan_hdr *)buf;
4135 * Move to the next channel if no packets are received within 10 msecs
4136 * after sending the probe request.
4138 hdr->quiet_time = htole16(WPI_QUIET_TIME_DEFAULT);
4139 hdr->quiet_threshold = htole16(1);
4143 * Max needs to be greater than active and passive and quiet!
4144 * It's also in microseconds!
4146 hdr->max_svc = htole32(250 * IEEE80211_DUR_TU);
4147 hdr->pause_svc = htole32(wpi_get_scan_pause_time(100,
4151 hdr->filter = htole32(WPI_FILTER_MULTICAST | WPI_FILTER_BEACON);
4153 tx = (struct wpi_cmd_data *)(hdr + 1);
4154 tx->flags = htole32(WPI_TX_AUTO_SEQ);
4155 tx->id = WPI_ID_BROADCAST;
4156 tx->lifetime = htole32(WPI_LIFETIME_INFINITE);
4158 if (IEEE80211_IS_CHAN_5GHZ(c)) {
4159 /* Send probe requests at 6Mbps. */
4160 tx->plcp = wpi_ridx_to_plcp[WPI_RIDX_OFDM6];
4161 rs = &ic->ic_sup_rates[IEEE80211_MODE_11A];
4163 hdr->flags = htole32(WPI_RXON_24GHZ | WPI_RXON_AUTO);
4164 /* Send probe requests at 1Mbps. */
4165 tx->plcp = wpi_ridx_to_plcp[WPI_RIDX_CCK1];
4166 rs = &ic->ic_sup_rates[IEEE80211_MODE_11G];
4169 essids = (struct wpi_scan_essid *)(tx + 1);
4170 nssid = MIN(ss->ss_nssid, WPI_SCAN_MAX_ESSIDS);
4171 for (i = 0; i < nssid; i++) {
4172 essids[i].id = IEEE80211_ELEMID_SSID;
4173 essids[i].len = MIN(ss->ss_ssid[i].len, IEEE80211_NWID_LEN);
4174 memcpy(essids[i].data, ss->ss_ssid[i].ssid, essids[i].len);
4176 if (sc->sc_debug & WPI_DEBUG_SCAN) {
4177 printf("Scanning Essid: ");
4178 ieee80211_print_essid(essids[i].data, essids[i].len);
4185 * Build a probe request frame. Most of the following code is a
4186 * copy & paste of what is done in net80211.
4188 wh = (struct ieee80211_frame *)(essids + WPI_SCAN_MAX_ESSIDS);
4189 wh->i_fc[0] = IEEE80211_FC0_VERSION_0 | IEEE80211_FC0_TYPE_MGT |
4190 IEEE80211_FC0_SUBTYPE_PROBE_REQ;
4191 wh->i_fc[1] = IEEE80211_FC1_DIR_NODS;
4192 IEEE80211_ADDR_COPY(wh->i_addr1, ieee80211broadcastaddr);
4193 IEEE80211_ADDR_COPY(wh->i_addr2, vap->iv_myaddr);
4194 IEEE80211_ADDR_COPY(wh->i_addr3, ieee80211broadcastaddr);
4196 frm = (uint8_t *)(wh + 1);
4197 frm = ieee80211_add_ssid(frm, NULL, 0);
4198 frm = ieee80211_add_rates(frm, rs);
4199 if (rs->rs_nrates > IEEE80211_RATE_SIZE)
4200 frm = ieee80211_add_xrates(frm, rs);
4202 /* Set length of probe request. */
4203 tx->len = htole16(frm - (uint8_t *)wh);
4206 * Construct information about the channel that we
4207 * want to scan. The firmware expects this to be directly
4208 * after the scan probe request
4210 chan = (struct wpi_scan_chan *)frm;
4211 chan->chan = ieee80211_chan2ieee(ic, c);
4214 hdr->crc_threshold = WPI_SCAN_CRC_TH_DEFAULT;
4215 chan->flags |= WPI_CHAN_NPBREQS(nssid);
4217 hdr->crc_threshold = WPI_SCAN_CRC_TH_NEVER;
4219 if (!IEEE80211_IS_CHAN_PASSIVE(c))
4220 chan->flags |= WPI_CHAN_ACTIVE;
4223 * Calculate the active/passive dwell times.
4225 dwell_active = wpi_get_active_dwell_time(sc, c, nssid);
4226 dwell_passive = wpi_get_passive_dwell_time(sc, c);
4228 /* Make sure they're valid. */
4229 if (dwell_active > dwell_passive)
4230 dwell_active = dwell_passive;
4232 chan->active = htole16(dwell_active);
4233 chan->passive = htole16(dwell_passive);
4235 chan->dsp_gain = 0x6e; /* Default level */
4237 if (IEEE80211_IS_CHAN_5GHZ(c))
4238 chan->rf_gain = 0x3b;
4240 chan->rf_gain = 0x28;
4242 DPRINTF(sc, WPI_DEBUG_SCAN, "Scanning %u Passive: %d\n",
4243 chan->chan, IEEE80211_IS_CHAN_PASSIVE(c));
4247 if (hdr->nchan == 1 && sc->rxon.chan == chan->chan) {
4248 /* XXX Force probe request transmission. */
4249 memcpy(chan + 1, chan, sizeof (struct wpi_scan_chan));
4253 /* Reduce unnecessary delay. */
4255 chan->passive = chan->active = hdr->quiet_time;
4262 buflen = (uint8_t *)chan - buf;
4263 hdr->len = htole16(buflen);
4265 DPRINTF(sc, WPI_DEBUG_CMD, "sending scan command nchan=%d\n",
4267 error = wpi_cmd(sc, WPI_CMD_SCAN, buf, buflen, 1);
4268 free(buf, M_DEVBUF);
4273 callout_reset(&sc->scan_timeout, 5*hz, wpi_scan_timeout, sc);
4275 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
4279 fail: DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END_ERR, __func__);
4285 wpi_auth(struct wpi_softc *sc, struct ieee80211vap *vap)
4287 struct ieee80211com *ic = vap->iv_ic;
4288 struct ieee80211_node *ni = vap->iv_bss;
4289 struct ieee80211_channel *c = ni->ni_chan;
4294 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__);
4296 /* Update adapter configuration. */
4297 sc->rxon.associd = 0;
4298 sc->rxon.filter &= ~htole32(WPI_FILTER_BSS);
4299 IEEE80211_ADDR_COPY(sc->rxon.bssid, ni->ni_bssid);
4300 sc->rxon.chan = ieee80211_chan2ieee(ic, c);
4301 sc->rxon.flags = htole32(WPI_RXON_TSF | WPI_RXON_CTS_TO_SELF);
4302 if (IEEE80211_IS_CHAN_2GHZ(c))
4303 sc->rxon.flags |= htole32(WPI_RXON_AUTO | WPI_RXON_24GHZ);
4304 if (ic->ic_flags & IEEE80211_F_SHSLOT)
4305 sc->rxon.flags |= htole32(WPI_RXON_SHSLOT);
4306 if (ic->ic_flags & IEEE80211_F_SHPREAMBLE)
4307 sc->rxon.flags |= htole32(WPI_RXON_SHPREAMBLE);
4308 if (IEEE80211_IS_CHAN_A(c)) {
4309 sc->rxon.cck_mask = 0;
4310 sc->rxon.ofdm_mask = 0x15;
4311 } else if (IEEE80211_IS_CHAN_B(c)) {
4312 sc->rxon.cck_mask = 0x03;
4313 sc->rxon.ofdm_mask = 0;
4315 /* Assume 802.11b/g. */
4316 sc->rxon.cck_mask = 0x0f;
4317 sc->rxon.ofdm_mask = 0x15;
4320 DPRINTF(sc, WPI_DEBUG_STATE, "rxon chan %d flags %x cck %x ofdm %x\n",
4321 sc->rxon.chan, sc->rxon.flags, sc->rxon.cck_mask,
4322 sc->rxon.ofdm_mask);
4324 if ((error = wpi_send_rxon(sc, 0, 1)) != 0) {
4325 device_printf(sc->sc_dev, "%s: could not send RXON\n",
4329 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
4331 WPI_RXON_UNLOCK(sc);
4337 wpi_config_beacon(struct wpi_vap *wvp)
4339 struct ieee80211vap *vap = &wvp->wv_vap;
4340 struct ieee80211com *ic = vap->iv_ic;
4341 struct ieee80211_beacon_offsets *bo = &vap->iv_bcn_off;
4342 struct wpi_buf *bcn = &wvp->wv_bcbuf;
4343 struct wpi_softc *sc = ic->ic_softc;
4344 struct wpi_cmd_beacon *cmd = (struct wpi_cmd_beacon *)&bcn->data;
4345 struct ieee80211_tim_ie *tie;
4350 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
4352 WPI_VAP_LOCK_ASSERT(wvp);
4354 cmd->len = htole16(bcn->m->m_pkthdr.len);
4355 cmd->plcp = (ic->ic_curmode == IEEE80211_MODE_11A) ?
4356 wpi_ridx_to_plcp[WPI_RIDX_OFDM6] : wpi_ridx_to_plcp[WPI_RIDX_CCK1];
4358 /* XXX seems to be unused */
4359 if (*(bo->bo_tim) == IEEE80211_ELEMID_TIM) {
4360 tie = (struct ieee80211_tim_ie *) bo->bo_tim;
4361 ptr = mtod(bcn->m, uint8_t *);
4363 cmd->tim = htole16(bo->bo_tim - ptr);
4364 cmd->timsz = tie->tim_len;
4367 /* Necessary for recursion in ieee80211_beacon_update(). */
4369 bcn->m = m_dup(m, M_NOWAIT);
4370 if (bcn->m == NULL) {
4371 device_printf(sc->sc_dev,
4372 "%s: could not copy beacon frame\n", __func__);
4377 if ((error = wpi_cmd2(sc, bcn)) != 0) {
4378 device_printf(sc->sc_dev,
4379 "%s: could not update beacon frame, error %d", __func__,
4391 wpi_setup_beacon(struct wpi_softc *sc, struct ieee80211_node *ni)
4393 struct ieee80211vap *vap = ni->ni_vap;
4394 struct wpi_vap *wvp = WPI_VAP(vap);
4395 struct wpi_buf *bcn = &wvp->wv_bcbuf;
4399 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
4401 if (ni->ni_chan == IEEE80211_CHAN_ANYC)
4404 m = ieee80211_beacon_alloc(ni);
4406 device_printf(sc->sc_dev,
4407 "%s: could not allocate beacon frame\n", __func__);
4417 error = wpi_config_beacon(wvp);
4418 WPI_VAP_UNLOCK(wvp);
4424 wpi_update_beacon(struct ieee80211vap *vap, int item)
4426 struct wpi_softc *sc = vap->iv_ic->ic_softc;
4427 struct wpi_vap *wvp = WPI_VAP(vap);
4428 struct wpi_buf *bcn = &wvp->wv_bcbuf;
4429 struct ieee80211_beacon_offsets *bo = &vap->iv_bcn_off;
4430 struct ieee80211_node *ni = vap->iv_bss;
4433 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__);
4436 if (bcn->m == NULL) {
4437 bcn->m = ieee80211_beacon_alloc(ni);
4438 if (bcn->m == NULL) {
4439 device_printf(sc->sc_dev,
4440 "%s: could not allocate beacon frame\n", __func__);
4442 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END_ERR,
4445 WPI_VAP_UNLOCK(wvp);
4449 WPI_VAP_UNLOCK(wvp);
4451 if (item == IEEE80211_BEACON_TIM)
4452 mcast = 1; /* TODO */
4454 setbit(bo->bo_flags, item);
4455 ieee80211_beacon_update(ni, bcn->m, mcast);
4458 wpi_config_beacon(wvp);
4459 WPI_VAP_UNLOCK(wvp);
4461 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
4465 wpi_newassoc(struct ieee80211_node *ni, int isnew)
4467 struct ieee80211vap *vap = ni->ni_vap;
4468 struct wpi_softc *sc = ni->ni_ic->ic_softc;
4469 struct wpi_node *wn = WPI_NODE(ni);
4474 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
4476 if (vap->iv_opmode != IEEE80211_M_STA && wn->id == WPI_ID_UNDEFINED) {
4477 if ((error = wpi_add_ibss_node(sc, ni)) != 0) {
4478 device_printf(sc->sc_dev,
4479 "%s: could not add IBSS node, error %d\n",
4487 wpi_run(struct wpi_softc *sc, struct ieee80211vap *vap)
4489 struct ieee80211com *ic = vap->iv_ic;
4490 struct ieee80211_node *ni = vap->iv_bss;
4491 struct ieee80211_channel *c = ni->ni_chan;
4494 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__);
4496 if (vap->iv_opmode == IEEE80211_M_MONITOR) {
4497 /* Link LED blinks while monitoring. */
4498 wpi_set_led(sc, WPI_LED_LINK, 5, 5);
4502 /* XXX kernel panic workaround */
4503 if (c == IEEE80211_CHAN_ANYC) {
4504 device_printf(sc->sc_dev, "%s: incomplete configuration\n",
4509 if ((error = wpi_set_timing(sc, ni)) != 0) {
4510 device_printf(sc->sc_dev,
4511 "%s: could not set timing, error %d\n", __func__, error);
4515 /* Update adapter configuration. */
4517 IEEE80211_ADDR_COPY(sc->rxon.bssid, ni->ni_bssid);
4518 sc->rxon.associd = htole16(IEEE80211_NODE_AID(ni));
4519 sc->rxon.chan = ieee80211_chan2ieee(ic, c);
4520 sc->rxon.flags = htole32(WPI_RXON_TSF | WPI_RXON_CTS_TO_SELF);
4521 if (IEEE80211_IS_CHAN_2GHZ(c))
4522 sc->rxon.flags |= htole32(WPI_RXON_AUTO | WPI_RXON_24GHZ);
4523 if (ic->ic_flags & IEEE80211_F_SHSLOT)
4524 sc->rxon.flags |= htole32(WPI_RXON_SHSLOT);
4525 if (ic->ic_flags & IEEE80211_F_SHPREAMBLE)
4526 sc->rxon.flags |= htole32(WPI_RXON_SHPREAMBLE);
4527 if (IEEE80211_IS_CHAN_A(c)) {
4528 sc->rxon.cck_mask = 0;
4529 sc->rxon.ofdm_mask = 0x15;
4530 } else if (IEEE80211_IS_CHAN_B(c)) {
4531 sc->rxon.cck_mask = 0x03;
4532 sc->rxon.ofdm_mask = 0;
4534 /* Assume 802.11b/g. */
4535 sc->rxon.cck_mask = 0x0f;
4536 sc->rxon.ofdm_mask = 0x15;
4538 sc->rxon.filter |= htole32(WPI_FILTER_BSS);
4540 DPRINTF(sc, WPI_DEBUG_STATE, "rxon chan %d flags %x\n",
4541 sc->rxon.chan, sc->rxon.flags);
4543 if ((error = wpi_send_rxon(sc, 0, 1)) != 0) {
4544 device_printf(sc->sc_dev, "%s: could not send RXON\n",
4549 /* Start periodic calibration timer. */
4550 callout_reset(&sc->calib_to, 60*hz, wpi_calib_timeout, sc);
4552 WPI_RXON_UNLOCK(sc);
4554 if (vap->iv_opmode == IEEE80211_M_IBSS ||
4555 vap->iv_opmode == IEEE80211_M_HOSTAP) {
4556 if ((error = wpi_setup_beacon(sc, ni)) != 0) {
4557 device_printf(sc->sc_dev,
4558 "%s: could not setup beacon, error %d\n", __func__,
4564 if (vap->iv_opmode == IEEE80211_M_STA) {
4567 error = wpi_add_sta_node(sc, ni);
4570 device_printf(sc->sc_dev,
4571 "%s: could not add BSS node, error %d\n", __func__,
4577 /* Link LED always on while associated. */
4578 wpi_set_led(sc, WPI_LED_LINK, 0, 1);
4580 /* Enable power-saving mode if requested by user. */
4581 if ((vap->iv_flags & IEEE80211_F_PMGTON) &&
4582 vap->iv_opmode != IEEE80211_M_IBSS)
4583 (void)wpi_set_pslevel(sc, 0, 3, 1);
4585 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
4591 wpi_load_key(struct ieee80211_node *ni, const struct ieee80211_key *k)
4593 const struct ieee80211_cipher *cip = k->wk_cipher;
4594 struct ieee80211vap *vap = ni->ni_vap;
4595 struct wpi_softc *sc = ni->ni_ic->ic_softc;
4596 struct wpi_node *wn = WPI_NODE(ni);
4597 struct wpi_node_info node;
4601 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
4603 if (wpi_check_node_entry(sc, wn->id) == 0) {
4604 device_printf(sc->sc_dev, "%s: node does not exist\n",
4609 switch (cip->ic_cipher) {
4610 case IEEE80211_CIPHER_AES_CCM:
4611 kflags = WPI_KFLAG_CCMP;
4615 device_printf(sc->sc_dev, "%s: unknown cipher %d\n", __func__,
4620 kflags |= WPI_KFLAG_KID(k->wk_keyix);
4621 if (k->wk_flags & IEEE80211_KEY_GROUP)
4622 kflags |= WPI_KFLAG_MULTICAST;
4624 memset(&node, 0, sizeof node);
4626 node.control = WPI_NODE_UPDATE;
4627 node.flags = WPI_FLAG_KEY_SET;
4628 node.kflags = htole16(kflags);
4629 memcpy(node.key, k->wk_key, k->wk_keylen);
4631 DPRINTF(sc, WPI_DEBUG_KEY,
4632 "%s: setting %s key id %d for node %d (%s)\n", __func__,
4633 (kflags & WPI_KFLAG_MULTICAST) ? "group" : "ucast", k->wk_keyix,
4634 node.id, ether_sprintf(ni->ni_macaddr));
4636 error = wpi_cmd(sc, WPI_CMD_ADD_NODE, &node, sizeof node, 1);
4638 device_printf(sc->sc_dev, "can't update node info, error %d\n",
4643 if (!(kflags & WPI_KFLAG_MULTICAST) && &vap->iv_nw_keys[0] <= k &&
4644 k < &vap->iv_nw_keys[IEEE80211_WEP_NKID]) {
4645 kflags |= WPI_KFLAG_MULTICAST;
4646 node.kflags = htole16(kflags);
4655 wpi_load_key_cb(void *arg, struct ieee80211_node *ni)
4657 const struct ieee80211_key *k = arg;
4658 struct ieee80211vap *vap = ni->ni_vap;
4659 struct wpi_softc *sc = ni->ni_ic->ic_softc;
4660 struct wpi_node *wn = WPI_NODE(ni);
4663 if (vap->iv_bss == ni && wn->id == WPI_ID_UNDEFINED)
4667 error = wpi_load_key(ni, k);
4671 device_printf(sc->sc_dev, "%s: error while setting key\n",
4677 wpi_set_global_keys(struct ieee80211_node *ni)
4679 struct ieee80211vap *vap = ni->ni_vap;
4680 struct ieee80211_key *wk = &vap->iv_nw_keys[0];
4683 for (; wk < &vap->iv_nw_keys[IEEE80211_WEP_NKID] && error; wk++)
4684 if (wk->wk_keyix != IEEE80211_KEYIX_NONE)
4685 error = wpi_load_key(ni, wk);
4691 wpi_del_key(struct ieee80211_node *ni, const struct ieee80211_key *k)
4693 struct ieee80211vap *vap = ni->ni_vap;
4694 struct wpi_softc *sc = ni->ni_ic->ic_softc;
4695 struct wpi_node *wn = WPI_NODE(ni);
4696 struct wpi_node_info node;
4700 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
4702 if (wpi_check_node_entry(sc, wn->id) == 0) {
4703 DPRINTF(sc, WPI_DEBUG_KEY, "%s: node was removed\n", __func__);
4704 return 1; /* Nothing to do. */
4707 kflags = WPI_KFLAG_KID(k->wk_keyix);
4708 if (k->wk_flags & IEEE80211_KEY_GROUP)
4709 kflags |= WPI_KFLAG_MULTICAST;
4711 memset(&node, 0, sizeof node);
4713 node.control = WPI_NODE_UPDATE;
4714 node.flags = WPI_FLAG_KEY_SET;
4715 node.kflags = htole16(kflags);
4717 DPRINTF(sc, WPI_DEBUG_KEY, "%s: deleting %s key %d for node %d (%s)\n",
4718 __func__, (kflags & WPI_KFLAG_MULTICAST) ? "group" : "ucast",
4719 k->wk_keyix, node.id, ether_sprintf(ni->ni_macaddr));
4721 error = wpi_cmd(sc, WPI_CMD_ADD_NODE, &node, sizeof node, 1);
4723 device_printf(sc->sc_dev, "can't update node info, error %d\n",
4728 if (!(kflags & WPI_KFLAG_MULTICAST) && &vap->iv_nw_keys[0] <= k &&
4729 k < &vap->iv_nw_keys[IEEE80211_WEP_NKID]) {
4730 kflags |= WPI_KFLAG_MULTICAST;
4731 node.kflags = htole16(kflags);
4740 wpi_del_key_cb(void *arg, struct ieee80211_node *ni)
4742 const struct ieee80211_key *k = arg;
4743 struct ieee80211vap *vap = ni->ni_vap;
4744 struct wpi_softc *sc = ni->ni_ic->ic_softc;
4745 struct wpi_node *wn = WPI_NODE(ni);
4748 if (vap->iv_bss == ni && wn->id == WPI_ID_UNDEFINED)
4752 error = wpi_del_key(ni, k);
4756 device_printf(sc->sc_dev, "%s: error while deleting key\n",
4762 wpi_process_key(struct ieee80211vap *vap, const struct ieee80211_key *k,
4765 struct ieee80211com *ic = vap->iv_ic;
4766 struct wpi_softc *sc = ic->ic_softc;
4767 struct wpi_vap *wvp = WPI_VAP(vap);
4768 struct ieee80211_node *ni;
4769 int error, ni_ref = 0;
4771 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
4773 if (k->wk_flags & IEEE80211_KEY_SWCRYPT) {
4778 if (!(k->wk_flags & IEEE80211_KEY_RECV)) {
4779 /* XMIT keys are handled in wpi_tx_data(). */
4783 /* Handle group keys. */
4784 if (&vap->iv_nw_keys[0] <= k &&
4785 k < &vap->iv_nw_keys[IEEE80211_WEP_NKID]) {
4788 wvp->wv_gtk |= WPI_VAP_KEY(k->wk_keyix);
4790 wvp->wv_gtk &= ~WPI_VAP_KEY(k->wk_keyix);
4793 if (vap->iv_state == IEEE80211_S_RUN) {
4794 ieee80211_iterate_nodes(&ic->ic_sta,
4795 set ? wpi_load_key_cb : wpi_del_key_cb,
4796 __DECONST(void *, k));
4802 switch (vap->iv_opmode) {
4803 case IEEE80211_M_STA:
4807 case IEEE80211_M_IBSS:
4808 case IEEE80211_M_AHDEMO:
4809 case IEEE80211_M_HOSTAP:
4810 ni = ieee80211_find_vap_node(&ic->ic_sta, vap, k->wk_macaddr);
4812 return 0; /* should not happen */
4818 device_printf(sc->sc_dev, "%s: unknown opmode %d\n", __func__,
4825 error = wpi_load_key(ni, k);
4827 error = wpi_del_key(ni, k);
4831 ieee80211_node_decref(ni);
4837 wpi_key_set(struct ieee80211vap *vap, const struct ieee80211_key *k)
4839 return wpi_process_key(vap, k, 1);
4843 wpi_key_delete(struct ieee80211vap *vap, const struct ieee80211_key *k)
4845 return wpi_process_key(vap, k, 0);
4849 * This function is called after the runtime firmware notifies us of its
4850 * readiness (called in a process context).
4853 wpi_post_alive(struct wpi_softc *sc)
4857 /* Check (again) that the radio is not disabled. */
4858 if ((error = wpi_nic_lock(sc)) != 0)
4861 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
4863 /* NB: Runtime firmware must be up and running. */
4864 if (!(wpi_prph_read(sc, WPI_APMG_RFKILL) & 1)) {
4865 device_printf(sc->sc_dev,
4866 "RF switch: radio disabled (%s)\n", __func__);
4868 return EPERM; /* :-) */
4872 /* Wait for thermal sensor to calibrate. */
4873 for (ntries = 0; ntries < 1000; ntries++) {
4874 if ((sc->temp = (int)WPI_READ(sc, WPI_UCODE_GP2)) != 0)
4879 if (ntries == 1000) {
4880 device_printf(sc->sc_dev,
4881 "timeout waiting for thermal sensor calibration\n");
4885 DPRINTF(sc, WPI_DEBUG_TEMP, "temperature %d\n", sc->temp);
4890 * The firmware boot code is small and is intended to be copied directly into
4891 * the NIC internal memory (no DMA transfer).
4894 wpi_load_bootcode(struct wpi_softc *sc, const uint8_t *ucode, uint32_t size)
4898 DPRINTF(sc, WPI_DEBUG_HW, "Loading microcode size 0x%x\n", size);
4900 size /= sizeof (uint32_t);
4902 if ((error = wpi_nic_lock(sc)) != 0)
4905 /* Copy microcode image into NIC memory. */
4906 wpi_prph_write_region_4(sc, WPI_BSM_SRAM_BASE,
4907 (const uint32_t *)ucode, size);
4909 wpi_prph_write(sc, WPI_BSM_WR_MEM_SRC, 0);
4910 wpi_prph_write(sc, WPI_BSM_WR_MEM_DST, WPI_FW_TEXT_BASE);
4911 wpi_prph_write(sc, WPI_BSM_WR_DWCOUNT, size);
4913 /* Start boot load now. */
4914 wpi_prph_write(sc, WPI_BSM_WR_CTRL, WPI_BSM_WR_CTRL_START);
4916 /* Wait for transfer to complete. */
4917 for (ntries = 0; ntries < 1000; ntries++) {
4918 uint32_t status = WPI_READ(sc, WPI_FH_TX_STATUS);
4919 DPRINTF(sc, WPI_DEBUG_HW,
4920 "firmware status=0x%x, val=0x%x, result=0x%x\n", status,
4921 WPI_FH_TX_STATUS_IDLE(6),
4922 status & WPI_FH_TX_STATUS_IDLE(6));
4923 if (status & WPI_FH_TX_STATUS_IDLE(6)) {
4924 DPRINTF(sc, WPI_DEBUG_HW,
4925 "Status Match! - ntries = %d\n", ntries);
4930 if (ntries == 1000) {
4931 device_printf(sc->sc_dev, "%s: could not load boot firmware\n",
4937 /* Enable boot after power up. */
4938 wpi_prph_write(sc, WPI_BSM_WR_CTRL, WPI_BSM_WR_CTRL_START_EN);
4945 wpi_load_firmware(struct wpi_softc *sc)
4947 struct wpi_fw_info *fw = &sc->fw;
4948 struct wpi_dma_info *dma = &sc->fw_dma;
4951 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
4953 /* Copy initialization sections into pre-allocated DMA-safe memory. */
4954 memcpy(dma->vaddr, fw->init.data, fw->init.datasz);
4955 bus_dmamap_sync(dma->tag, dma->map, BUS_DMASYNC_PREWRITE);
4956 memcpy(dma->vaddr + WPI_FW_DATA_MAXSZ, fw->init.text, fw->init.textsz);
4957 bus_dmamap_sync(dma->tag, dma->map, BUS_DMASYNC_PREWRITE);
4959 /* Tell adapter where to find initialization sections. */
4960 if ((error = wpi_nic_lock(sc)) != 0)
4962 wpi_prph_write(sc, WPI_BSM_DRAM_DATA_ADDR, dma->paddr);
4963 wpi_prph_write(sc, WPI_BSM_DRAM_DATA_SIZE, fw->init.datasz);
4964 wpi_prph_write(sc, WPI_BSM_DRAM_TEXT_ADDR,
4965 dma->paddr + WPI_FW_DATA_MAXSZ);
4966 wpi_prph_write(sc, WPI_BSM_DRAM_TEXT_SIZE, fw->init.textsz);
4969 /* Load firmware boot code. */
4970 error = wpi_load_bootcode(sc, fw->boot.text, fw->boot.textsz);
4972 device_printf(sc->sc_dev, "%s: could not load boot firmware\n",
4977 /* Now press "execute". */
4978 WPI_WRITE(sc, WPI_RESET, 0);
4980 /* Wait at most one second for first alive notification. */
4981 if ((error = mtx_sleep(sc, &sc->sc_mtx, PCATCH, "wpiinit", hz)) != 0) {
4982 device_printf(sc->sc_dev,
4983 "%s: timeout waiting for adapter to initialize, error %d\n",
4988 /* Copy runtime sections into pre-allocated DMA-safe memory. */
4989 memcpy(dma->vaddr, fw->main.data, fw->main.datasz);
4990 bus_dmamap_sync(dma->tag, dma->map, BUS_DMASYNC_PREWRITE);
4991 memcpy(dma->vaddr + WPI_FW_DATA_MAXSZ, fw->main.text, fw->main.textsz);
4992 bus_dmamap_sync(dma->tag, dma->map, BUS_DMASYNC_PREWRITE);
4994 /* Tell adapter where to find runtime sections. */
4995 if ((error = wpi_nic_lock(sc)) != 0)
4997 wpi_prph_write(sc, WPI_BSM_DRAM_DATA_ADDR, dma->paddr);
4998 wpi_prph_write(sc, WPI_BSM_DRAM_DATA_SIZE, fw->main.datasz);
4999 wpi_prph_write(sc, WPI_BSM_DRAM_TEXT_ADDR,
5000 dma->paddr + WPI_FW_DATA_MAXSZ);
5001 wpi_prph_write(sc, WPI_BSM_DRAM_TEXT_SIZE,
5002 WPI_FW_UPDATED | fw->main.textsz);
5009 wpi_read_firmware(struct wpi_softc *sc)
5011 const struct firmware *fp;
5012 struct wpi_fw_info *fw = &sc->fw;
5013 const struct wpi_firmware_hdr *hdr;
5016 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
5018 DPRINTF(sc, WPI_DEBUG_FIRMWARE,
5019 "Attempting Loading Firmware from %s module\n", WPI_FW_NAME);
5022 fp = firmware_get(WPI_FW_NAME);
5026 device_printf(sc->sc_dev,
5027 "could not load firmware image '%s'\n", WPI_FW_NAME);
5033 if (fp->datasize < sizeof (struct wpi_firmware_hdr)) {
5034 device_printf(sc->sc_dev,
5035 "firmware file too short: %zu bytes\n", fp->datasize);
5040 fw->size = fp->datasize;
5041 fw->data = (const uint8_t *)fp->data;
5043 /* Extract firmware header information. */
5044 hdr = (const struct wpi_firmware_hdr *)fw->data;
5046 /* | RUNTIME FIRMWARE | INIT FIRMWARE | BOOT FW |
5047 |HDR|<--TEXT-->|<--DATA-->|<--TEXT-->|<--DATA-->|<--TEXT-->| */
5049 fw->main.textsz = le32toh(hdr->rtextsz);
5050 fw->main.datasz = le32toh(hdr->rdatasz);
5051 fw->init.textsz = le32toh(hdr->itextsz);
5052 fw->init.datasz = le32toh(hdr->idatasz);
5053 fw->boot.textsz = le32toh(hdr->btextsz);
5054 fw->boot.datasz = 0;
5056 /* Sanity-check firmware header. */
5057 if (fw->main.textsz > WPI_FW_TEXT_MAXSZ ||
5058 fw->main.datasz > WPI_FW_DATA_MAXSZ ||
5059 fw->init.textsz > WPI_FW_TEXT_MAXSZ ||
5060 fw->init.datasz > WPI_FW_DATA_MAXSZ ||
5061 fw->boot.textsz > WPI_FW_BOOT_TEXT_MAXSZ ||
5062 (fw->boot.textsz & 3) != 0) {
5063 device_printf(sc->sc_dev, "invalid firmware header\n");
5068 /* Check that all firmware sections fit. */
5069 if (fw->size < sizeof (*hdr) + fw->main.textsz + fw->main.datasz +
5070 fw->init.textsz + fw->init.datasz + fw->boot.textsz) {
5071 device_printf(sc->sc_dev,
5072 "firmware file too short: %zu bytes\n", fw->size);
5077 /* Get pointers to firmware sections. */
5078 fw->main.text = (const uint8_t *)(hdr + 1);
5079 fw->main.data = fw->main.text + fw->main.textsz;
5080 fw->init.text = fw->main.data + fw->main.datasz;
5081 fw->init.data = fw->init.text + fw->init.textsz;
5082 fw->boot.text = fw->init.data + fw->init.datasz;
5084 DPRINTF(sc, WPI_DEBUG_FIRMWARE,
5085 "Firmware Version: Major %d, Minor %d, Driver %d, \n"
5086 "runtime (text: %u, data: %u) init (text: %u, data %u) "
5087 "boot (text %u)\n", hdr->major, hdr->minor, le32toh(hdr->driver),
5088 fw->main.textsz, fw->main.datasz,
5089 fw->init.textsz, fw->init.datasz, fw->boot.textsz);
5091 DPRINTF(sc, WPI_DEBUG_FIRMWARE, "fw->main.text %p\n", fw->main.text);
5092 DPRINTF(sc, WPI_DEBUG_FIRMWARE, "fw->main.data %p\n", fw->main.data);
5093 DPRINTF(sc, WPI_DEBUG_FIRMWARE, "fw->init.text %p\n", fw->init.text);
5094 DPRINTF(sc, WPI_DEBUG_FIRMWARE, "fw->init.data %p\n", fw->init.data);
5095 DPRINTF(sc, WPI_DEBUG_FIRMWARE, "fw->boot.text %p\n", fw->boot.text);
5099 fail: wpi_unload_firmware(sc);
5104 * Free the referenced firmware image
5107 wpi_unload_firmware(struct wpi_softc *sc)
5109 if (sc->fw_fp != NULL) {
5110 firmware_put(sc->fw_fp, FIRMWARE_UNLOAD);
5116 wpi_clock_wait(struct wpi_softc *sc)
5120 /* Set "initialization complete" bit. */
5121 WPI_SETBITS(sc, WPI_GP_CNTRL, WPI_GP_CNTRL_INIT_DONE);
5123 /* Wait for clock stabilization. */
5124 for (ntries = 0; ntries < 2500; ntries++) {
5125 if (WPI_READ(sc, WPI_GP_CNTRL) & WPI_GP_CNTRL_MAC_CLOCK_READY)
5129 device_printf(sc->sc_dev,
5130 "%s: timeout waiting for clock stabilization\n", __func__);
5136 wpi_apm_init(struct wpi_softc *sc)
5141 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
5143 /* Disable L0s exit timer (NMI bug workaround). */
5144 WPI_SETBITS(sc, WPI_GIO_CHICKEN, WPI_GIO_CHICKEN_DIS_L0S_TIMER);
5145 /* Don't wait for ICH L0s (ICH bug workaround). */
5146 WPI_SETBITS(sc, WPI_GIO_CHICKEN, WPI_GIO_CHICKEN_L1A_NO_L0S_RX);
5148 /* Set FH wait threshold to max (HW bug under stress workaround). */
5149 WPI_SETBITS(sc, WPI_DBG_HPET_MEM, 0xffff0000);
5151 /* Retrieve PCIe Active State Power Management (ASPM). */
5152 reg = pci_read_config(sc->sc_dev, sc->sc_cap_off + PCIER_LINK_CTL, 1);
5153 /* Workaround for HW instability in PCIe L0->L0s->L1 transition. */
5154 if (reg & PCIEM_LINK_CTL_ASPMC_L1) /* L1 Entry enabled. */
5155 WPI_SETBITS(sc, WPI_GIO, WPI_GIO_L0S_ENA);
5157 WPI_CLRBITS(sc, WPI_GIO, WPI_GIO_L0S_ENA);
5159 WPI_SETBITS(sc, WPI_ANA_PLL, WPI_ANA_PLL_INIT);
5161 /* Wait for clock stabilization before accessing prph. */
5162 if ((error = wpi_clock_wait(sc)) != 0)
5165 if ((error = wpi_nic_lock(sc)) != 0)
5168 wpi_prph_write(sc, WPI_APMG_CLK_DIS, 0x00000400);
5169 wpi_prph_clrbits(sc, WPI_APMG_PS, 0x00000200);
5171 /* Enable DMA and BSM (Bootstrap State Machine). */
5172 wpi_prph_write(sc, WPI_APMG_CLK_EN,
5173 WPI_APMG_CLK_CTRL_DMA_CLK_RQT | WPI_APMG_CLK_CTRL_BSM_CLK_RQT);
5175 /* Disable L1-Active. */
5176 wpi_prph_setbits(sc, WPI_APMG_PCI_STT, WPI_APMG_PCI_STT_L1A_DIS);
5183 wpi_apm_stop_master(struct wpi_softc *sc)
5187 /* Stop busmaster DMA activity. */
5188 WPI_SETBITS(sc, WPI_RESET, WPI_RESET_STOP_MASTER);
5190 if ((WPI_READ(sc, WPI_GP_CNTRL) & WPI_GP_CNTRL_PS_MASK) ==
5191 WPI_GP_CNTRL_MAC_PS)
5192 return; /* Already asleep. */
5194 for (ntries = 0; ntries < 100; ntries++) {
5195 if (WPI_READ(sc, WPI_RESET) & WPI_RESET_MASTER_DISABLED)
5199 device_printf(sc->sc_dev, "%s: timeout waiting for master\n",
5204 wpi_apm_stop(struct wpi_softc *sc)
5206 wpi_apm_stop_master(sc);
5208 /* Reset the entire device. */
5209 WPI_SETBITS(sc, WPI_RESET, WPI_RESET_SW);
5211 /* Clear "initialization complete" bit. */
5212 WPI_CLRBITS(sc, WPI_GP_CNTRL, WPI_GP_CNTRL_INIT_DONE);
5216 wpi_nic_config(struct wpi_softc *sc)
5220 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
5222 /* voodoo from the Linux "driver".. */
5223 rev = pci_read_config(sc->sc_dev, PCIR_REVID, 1);
5224 if ((rev & 0xc0) == 0x40)
5225 WPI_SETBITS(sc, WPI_HW_IF_CONFIG, WPI_HW_IF_CONFIG_ALM_MB);
5226 else if (!(rev & 0x80))
5227 WPI_SETBITS(sc, WPI_HW_IF_CONFIG, WPI_HW_IF_CONFIG_ALM_MM);
5229 if (sc->cap == 0x80)
5230 WPI_SETBITS(sc, WPI_HW_IF_CONFIG, WPI_HW_IF_CONFIG_SKU_MRC);
5232 if ((sc->rev & 0xf0) == 0xd0)
5233 WPI_SETBITS(sc, WPI_HW_IF_CONFIG, WPI_HW_IF_CONFIG_REV_D);
5235 WPI_CLRBITS(sc, WPI_HW_IF_CONFIG, WPI_HW_IF_CONFIG_REV_D);
5238 WPI_SETBITS(sc, WPI_HW_IF_CONFIG, WPI_HW_IF_CONFIG_TYPE_B);
5242 wpi_hw_init(struct wpi_softc *sc)
5247 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__);
5249 /* Clear pending interrupts. */
5250 WPI_WRITE(sc, WPI_INT, 0xffffffff);
5252 if ((error = wpi_apm_init(sc)) != 0) {
5253 device_printf(sc->sc_dev,
5254 "%s: could not power ON adapter, error %d\n", __func__,
5259 /* Select VMAIN power source. */
5260 if ((error = wpi_nic_lock(sc)) != 0)
5262 wpi_prph_clrbits(sc, WPI_APMG_PS, WPI_APMG_PS_PWR_SRC_MASK);
5264 /* Spin until VMAIN gets selected. */
5265 for (ntries = 0; ntries < 5000; ntries++) {
5266 if (WPI_READ(sc, WPI_GPIO_IN) & WPI_GPIO_IN_VMAIN)
5270 if (ntries == 5000) {
5271 device_printf(sc->sc_dev, "timeout selecting power source\n");
5275 /* Perform adapter initialization. */
5278 /* Initialize RX ring. */
5279 if ((error = wpi_nic_lock(sc)) != 0)
5281 /* Set physical address of RX ring. */
5282 WPI_WRITE(sc, WPI_FH_RX_BASE, sc->rxq.desc_dma.paddr);
5283 /* Set physical address of RX read pointer. */
5284 WPI_WRITE(sc, WPI_FH_RX_RPTR_ADDR, sc->shared_dma.paddr +
5285 offsetof(struct wpi_shared, next));
5286 WPI_WRITE(sc, WPI_FH_RX_WPTR, 0);
5288 WPI_WRITE(sc, WPI_FH_RX_CONFIG,
5289 WPI_FH_RX_CONFIG_DMA_ENA |
5290 WPI_FH_RX_CONFIG_RDRBD_ENA |
5291 WPI_FH_RX_CONFIG_WRSTATUS_ENA |
5292 WPI_FH_RX_CONFIG_MAXFRAG |
5293 WPI_FH_RX_CONFIG_NRBD(WPI_RX_RING_COUNT_LOG) |
5294 WPI_FH_RX_CONFIG_IRQ_DST_HOST |
5295 WPI_FH_RX_CONFIG_IRQ_TIMEOUT(1));
5296 (void)WPI_READ(sc, WPI_FH_RSSR_TBL); /* barrier */
5298 WPI_WRITE(sc, WPI_FH_RX_WPTR, (WPI_RX_RING_COUNT - 1) & ~7);
5300 /* Initialize TX rings. */
5301 if ((error = wpi_nic_lock(sc)) != 0)
5303 wpi_prph_write(sc, WPI_ALM_SCHED_MODE, 2); /* bypass mode */
5304 wpi_prph_write(sc, WPI_ALM_SCHED_ARASTAT, 1); /* enable RA0 */
5305 /* Enable all 6 TX rings. */
5306 wpi_prph_write(sc, WPI_ALM_SCHED_TXFACT, 0x3f);
5307 wpi_prph_write(sc, WPI_ALM_SCHED_SBYPASS_MODE1, 0x10000);
5308 wpi_prph_write(sc, WPI_ALM_SCHED_SBYPASS_MODE2, 0x30002);
5309 wpi_prph_write(sc, WPI_ALM_SCHED_TXF4MF, 4);
5310 wpi_prph_write(sc, WPI_ALM_SCHED_TXF5MF, 5);
5311 /* Set physical address of TX rings. */
5312 WPI_WRITE(sc, WPI_FH_TX_BASE, sc->shared_dma.paddr);
5313 WPI_WRITE(sc, WPI_FH_MSG_CONFIG, 0xffff05a5);
5315 /* Enable all DMA channels. */
5316 for (chnl = 0; chnl < WPI_NDMACHNLS; chnl++) {
5317 WPI_WRITE(sc, WPI_FH_CBBC_CTRL(chnl), 0);
5318 WPI_WRITE(sc, WPI_FH_CBBC_BASE(chnl), 0);
5319 WPI_WRITE(sc, WPI_FH_TX_CONFIG(chnl), 0x80200008);
5322 (void)WPI_READ(sc, WPI_FH_TX_BASE); /* barrier */
5324 /* Clear "radio off" and "commands blocked" bits. */
5325 WPI_WRITE(sc, WPI_UCODE_GP1_CLR, WPI_UCODE_GP1_RFKILL);
5326 WPI_WRITE(sc, WPI_UCODE_GP1_CLR, WPI_UCODE_GP1_CMD_BLOCKED);
5328 /* Clear pending interrupts. */
5329 WPI_WRITE(sc, WPI_INT, 0xffffffff);
5330 /* Enable interrupts. */
5331 WPI_WRITE(sc, WPI_INT_MASK, WPI_INT_MASK_DEF);
5333 /* _Really_ make sure "radio off" bit is cleared! */
5334 WPI_WRITE(sc, WPI_UCODE_GP1_CLR, WPI_UCODE_GP1_RFKILL);
5335 WPI_WRITE(sc, WPI_UCODE_GP1_CLR, WPI_UCODE_GP1_RFKILL);
5337 if ((error = wpi_load_firmware(sc)) != 0) {
5338 device_printf(sc->sc_dev,
5339 "%s: could not load firmware, error %d\n", __func__,
5343 /* Wait at most one second for firmware alive notification. */
5344 if ((error = mtx_sleep(sc, &sc->sc_mtx, PCATCH, "wpiinit", hz)) != 0) {
5345 device_printf(sc->sc_dev,
5346 "%s: timeout waiting for adapter to initialize, error %d\n",
5351 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
5353 /* Do post-firmware initialization. */
5354 return wpi_post_alive(sc);
5358 wpi_hw_stop(struct wpi_softc *sc)
5363 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
5365 if (WPI_READ(sc, WPI_UCODE_GP1) & WPI_UCODE_GP1_MAC_SLEEP)
5368 WPI_WRITE(sc, WPI_RESET, WPI_RESET_NEVO);
5370 /* Disable interrupts. */
5371 WPI_WRITE(sc, WPI_INT_MASK, 0);
5372 WPI_WRITE(sc, WPI_INT, 0xffffffff);
5373 WPI_WRITE(sc, WPI_FH_INT, 0xffffffff);
5375 /* Make sure we no longer hold the NIC lock. */
5378 if (wpi_nic_lock(sc) == 0) {
5379 /* Stop TX scheduler. */
5380 wpi_prph_write(sc, WPI_ALM_SCHED_MODE, 0);
5381 wpi_prph_write(sc, WPI_ALM_SCHED_TXFACT, 0);
5383 /* Stop all DMA channels. */
5384 for (chnl = 0; chnl < WPI_NDMACHNLS; chnl++) {
5385 WPI_WRITE(sc, WPI_FH_TX_CONFIG(chnl), 0);
5386 for (ntries = 0; ntries < 200; ntries++) {
5387 if (WPI_READ(sc, WPI_FH_TX_STATUS) &
5388 WPI_FH_TX_STATUS_IDLE(chnl))
5397 wpi_reset_rx_ring(sc);
5399 /* Reset all TX rings. */
5400 for (qid = 0; qid < WPI_DRV_NTXQUEUES; qid++)
5401 wpi_reset_tx_ring(sc, &sc->txq[qid]);
5403 if (wpi_nic_lock(sc) == 0) {
5404 wpi_prph_write(sc, WPI_APMG_CLK_DIS,
5405 WPI_APMG_CLK_CTRL_DMA_CLK_RQT);
5409 /* Power OFF adapter. */
5414 wpi_radio_on(void *arg0, int pending)
5416 struct wpi_softc *sc = arg0;
5417 struct ieee80211com *ic = &sc->sc_ic;
5418 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
5420 device_printf(sc->sc_dev, "RF switch: radio enabled\n");
5423 callout_stop(&sc->watchdog_rfkill);
5427 ieee80211_init(vap);
5431 wpi_radio_off(void *arg0, int pending)
5433 struct wpi_softc *sc = arg0;
5434 struct ieee80211com *ic = &sc->sc_ic;
5435 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
5437 device_printf(sc->sc_dev, "RF switch: radio disabled\n");
5439 ieee80211_notify_radio(ic, 0);
5442 ieee80211_stop(vap);
5445 callout_reset(&sc->watchdog_rfkill, hz, wpi_watchdog_rfkill, sc);
5450 wpi_init(struct wpi_softc *sc)
5456 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_BEGIN, __func__);
5458 if (sc->sc_running != 0)
5461 /* Check that the radio is not disabled by hardware switch. */
5462 if (!(WPI_READ(sc, WPI_GP_CNTRL) & WPI_GP_CNTRL_RFKILL)) {
5463 device_printf(sc->sc_dev,
5464 "RF switch: radio disabled (%s)\n", __func__);
5465 callout_reset(&sc->watchdog_rfkill, hz, wpi_watchdog_rfkill,
5467 error = EINPROGRESS;
5471 /* Read firmware images from the filesystem. */
5472 if ((error = wpi_read_firmware(sc)) != 0) {
5473 device_printf(sc->sc_dev,
5474 "%s: could not read firmware, error %d\n", __func__,
5481 /* Initialize hardware and upload firmware. */
5482 error = wpi_hw_init(sc);
5483 wpi_unload_firmware(sc);
5485 device_printf(sc->sc_dev,
5486 "%s: could not initialize hardware, error %d\n", __func__,
5491 /* Configure adapter now that it is ready. */
5492 if ((error = wpi_config(sc)) != 0) {
5493 device_printf(sc->sc_dev,
5494 "%s: could not configure device, error %d\n", __func__,
5499 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END, __func__);
5505 fail: wpi_stop_locked(sc);
5507 end: DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_END_ERR, __func__);
5514 wpi_stop_locked(struct wpi_softc *sc)
5517 WPI_LOCK_ASSERT(sc);
5519 if (sc->sc_running == 0)
5528 WPI_TXQ_STATE_LOCK(sc);
5529 callout_stop(&sc->tx_timeout);
5530 WPI_TXQ_STATE_UNLOCK(sc);
5533 callout_stop(&sc->scan_timeout);
5534 callout_stop(&sc->calib_to);
5535 WPI_RXON_UNLOCK(sc);
5537 /* Power OFF hardware. */
5542 wpi_stop(struct wpi_softc *sc)
5545 wpi_stop_locked(sc);
5550 * Callback from net80211 to start a scan.
5553 wpi_scan_start(struct ieee80211com *ic)
5555 struct wpi_softc *sc = ic->ic_softc;
5557 wpi_set_led(sc, WPI_LED_LINK, 20, 2);
5561 * Callback from net80211 to terminate a scan.
5564 wpi_scan_end(struct ieee80211com *ic)
5566 struct wpi_softc *sc = ic->ic_softc;
5567 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
5569 if (vap->iv_state == IEEE80211_S_RUN)
5570 wpi_set_led(sc, WPI_LED_LINK, 0, 1);
5574 * Called by the net80211 framework to indicate to the driver
5575 * that the channel should be changed
5578 wpi_set_channel(struct ieee80211com *ic)
5580 const struct ieee80211_channel *c = ic->ic_curchan;
5581 struct wpi_softc *sc = ic->ic_softc;
5584 DPRINTF(sc, WPI_DEBUG_TRACE, TRACE_STR_DOING, __func__);
5587 sc->sc_rxtap.wr_chan_freq = htole16(c->ic_freq);
5588 sc->sc_rxtap.wr_chan_flags = htole16(c->ic_flags);
5591 sc->sc_txtap.wt_chan_freq = htole16(c->ic_freq);
5592 sc->sc_txtap.wt_chan_flags = htole16(c->ic_flags);
5596 * Only need to set the channel in Monitor mode. AP scanning and auth
5597 * are already taken care of by their respective firmware commands.
5599 if (ic->ic_opmode == IEEE80211_M_MONITOR) {
5601 sc->rxon.chan = ieee80211_chan2ieee(ic, c);
5602 if (IEEE80211_IS_CHAN_2GHZ(c)) {
5603 sc->rxon.flags |= htole32(WPI_RXON_AUTO |
5606 sc->rxon.flags &= ~htole32(WPI_RXON_AUTO |
5609 if ((error = wpi_send_rxon(sc, 0, 1)) != 0)
5610 device_printf(sc->sc_dev,
5611 "%s: error %d setting channel\n", __func__,
5613 WPI_RXON_UNLOCK(sc);
5618 * Called by net80211 to indicate that we need to scan the current
5619 * channel. The channel is previously be set via the wpi_set_channel
5623 wpi_scan_curchan(struct ieee80211_scan_state *ss, unsigned long maxdwell)
5625 struct ieee80211vap *vap = ss->ss_vap;
5626 struct ieee80211com *ic = vap->iv_ic;
5627 struct wpi_softc *sc = ic->ic_softc;
5631 error = wpi_scan(sc, ic->ic_curchan);
5632 WPI_RXON_UNLOCK(sc);
5634 ieee80211_cancel_scan(vap);
5638 * Called by the net80211 framework to indicate
5639 * the minimum dwell time has been met, terminate the scan.
5640 * We don't actually terminate the scan as the firmware will notify
5641 * us when it's finished and we have no way to interrupt it.
5644 wpi_scan_mindwell(struct ieee80211_scan_state *ss)
5646 /* NB: don't try to abort scan; wait for firmware to finish */