Lines Matching +full:dma +full:- +full:safe +full:- +full:map
1 /*-
27 * main binary firmware image into SRAM on the card via DMA.
29 * communicate by way of circular dma rings via the SRAM to the firmware.
34 * The rx data ring consists of 32 dma buffers. Two registers are used to
54 * from host memory via dma to the card then told to execute. From this point
317 for (ident = wpi_ident_table; ident->name != NULL; ident++) { in wpi_probe()
318 if (pci_get_vendor(dev) == ident->vendor && in wpi_probe()
319 pci_get_device(dev) == ident->device) { in wpi_probe()
320 device_set_desc(dev, ident->name); in wpi_probe()
339 sc->sc_dev = dev; in wpi_attach()
342 error = resource_int_value(device_get_name(sc->sc_dev), in wpi_attach()
343 device_get_unit(sc->sc_dev), "debug", &(sc->sc_debug)); in wpi_attach()
345 sc->sc_debug = 0; in wpi_attach()
347 sc->sc_debug = 0; in wpi_attach()
356 error = pci_find_cap(dev, PCIY_EXPRESS, &sc->sc_cap_off); in wpi_attach()
368 for (ident = wpi_ident_table; ident->name != NULL; ident++) { in wpi_attach()
369 if (ident->subdevice && in wpi_attach()
370 pci_get_subdevice(dev) == ident->subdevice) { in wpi_attach()
377 /* Clear device-specific "PCI retry timeout" register (41h). */ in wpi_attach()
380 /* Enable bus-mastering. */ in wpi_attach()
384 sc->mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, in wpi_attach()
386 if (sc->mem == NULL) { in wpi_attach()
387 device_printf(dev, "can't map mem space\n"); in wpi_attach()
390 sc->sc_st = rman_get_bustag(sc->mem); in wpi_attach()
391 sc->sc_sh = rman_get_bushandle(sc->mem); in wpi_attach()
399 sc->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE | in wpi_attach()
401 if (sc->irq == NULL) { in wpi_attach()
402 device_printf(dev, "can't map interrupt\n"); in wpi_attach()
414 /* Allocate DMA memory for firmware transfers. */ in wpi_attach()
428 /* Allocate TX rings - 4 for QoS purposes, 1 for commands. */ in wpi_attach()
430 if ((error = wpi_alloc_tx_ring(sc, &sc->txq[i], i)) != 0) { in wpi_attach()
448 ic = &sc->sc_ic; in wpi_attach()
449 ic->ic_softc = sc; in wpi_attach()
450 ic->ic_name = device_get_nameunit(dev); in wpi_attach()
451 ic->ic_phytype = IEEE80211_T_OFDM; /* not only, but not used */ in wpi_attach()
452 ic->ic_opmode = IEEE80211_M_STA; /* default to BSS mode */ in wpi_attach()
455 ic->ic_caps = in wpi_attach()
468 | IEEE80211_C_PMGT /* Station-side power mgmt */ in wpi_attach()
471 ic->ic_cryptocaps = in wpi_attach()
478 if ((error = wpi_read_eeprom(sc, ic->ic_macaddr)) != 0) { in wpi_attach()
486 device_printf(sc->sc_dev, "Regulatory Domain: %.4s\n", in wpi_attach()
487 sc->domain); in wpi_attach()
488 device_printf(sc->sc_dev, "Hardware Type: %c\n", in wpi_attach()
489 sc->type > 1 ? 'B': '?'); in wpi_attach()
490 device_printf(sc->sc_dev, "Hardware Revision: %c\n", in wpi_attach()
491 ((sc->rev & 0xf0) == 0xd0) ? 'D': '?'); in wpi_attach()
492 device_printf(sc->sc_dev, "SKU %s support 802.11a\n", in wpi_attach()
496 check what sc->rev really represents - benjsc 20070615 */ in wpi_attach()
501 ic->ic_vap_create = wpi_vap_create; in wpi_attach()
502 ic->ic_vap_delete = wpi_vap_delete; in wpi_attach()
503 ic->ic_parent = wpi_parent; in wpi_attach()
504 ic->ic_raw_xmit = wpi_raw_xmit; in wpi_attach()
505 ic->ic_transmit = wpi_transmit; in wpi_attach()
506 ic->ic_node_alloc = wpi_node_alloc; in wpi_attach()
507 sc->sc_node_free = ic->ic_node_free; in wpi_attach()
508 ic->ic_node_free = wpi_node_free; in wpi_attach()
509 ic->ic_wme.wme_update = wpi_updateedca; in wpi_attach()
510 ic->ic_update_promisc = wpi_update_promisc; in wpi_attach()
511 ic->ic_update_mcast = wpi_update_mcast; in wpi_attach()
512 ic->ic_newassoc = wpi_newassoc; in wpi_attach()
513 ic->ic_scan_start = wpi_scan_start; in wpi_attach()
514 ic->ic_scan_end = wpi_scan_end; in wpi_attach()
515 ic->ic_set_channel = wpi_set_channel; in wpi_attach()
516 ic->ic_scan_curchan = wpi_scan_curchan; in wpi_attach()
517 ic->ic_scan_mindwell = wpi_scan_mindwell; in wpi_attach()
518 ic->ic_getradiocaps = wpi_getradiocaps; in wpi_attach()
519 ic->ic_setregdomain = wpi_setregdomain; in wpi_attach()
521 sc->sc_update_rx_ring = wpi_update_rx_ring; in wpi_attach()
522 sc->sc_update_tx_ring = wpi_update_tx_ring; in wpi_attach()
527 sc->sc_txs.flags = IEEE80211_RATECTL_STATUS_PKTLEN | in wpi_attach()
531 callout_init_mtx(&sc->calib_to, &sc->rxon_mtx, 0); in wpi_attach()
532 callout_init_mtx(&sc->scan_timeout, &sc->rxon_mtx, 0); in wpi_attach()
533 callout_init_mtx(&sc->tx_timeout, &sc->txq_state_mtx, 0); in wpi_attach()
534 callout_init_mtx(&sc->watchdog_rfkill, &sc->sc_mtx, 0); in wpi_attach()
535 TASK_INIT(&sc->sc_radiooff_task, 0, wpi_radio_off, sc); in wpi_attach()
536 TASK_INIT(&sc->sc_radioon_task, 0, wpi_radio_on, sc); in wpi_attach()
543 error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET | INTR_MPSAFE, in wpi_attach()
544 NULL, wpi_intr, sc, &sc->sc_ih); in wpi_attach()
555 if (sc->sc_debug & WPI_DEBUG_HW) in wpi_attach()
573 struct wpi_rx_radiotap_header *rxtap = &sc->sc_rxtap; in wpi_radiotap_attach()
574 struct wpi_tx_radiotap_header *txtap = &sc->sc_txtap; in wpi_radiotap_attach()
577 ieee80211_radiotap_attach(&sc->sc_ic, in wpi_radiotap_attach()
578 &txtap->wt_ihdr, sizeof(*txtap), WPI_TX_RADIOTAP_PRESENT, in wpi_radiotap_attach()
579 &rxtap->wr_ihdr, sizeof(*rxtap), WPI_RX_RADIOTAP_PRESENT); in wpi_radiotap_attach()
587 struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(sc->sc_dev); in wpi_sysctlattach()
588 struct sysctl_oid *tree = device_get_sysctl_tree(sc->sc_dev); in wpi_sysctlattach()
591 "debug", CTLFLAG_RW, &sc->sc_debug, sc->sc_debug, in wpi_sysctlattach()
599 struct wpi_buf *bcn = &wvp->wv_bcbuf; in wpi_init_beacon()
600 struct wpi_cmd_beacon *cmd = (struct wpi_cmd_beacon *)&bcn->data; in wpi_init_beacon()
602 cmd->id = WPI_ID_BROADCAST; in wpi_init_beacon()
603 cmd->ofdm_mask = 0xff; in wpi_init_beacon()
604 cmd->cck_mask = 0x0f; in wpi_init_beacon()
605 cmd->lifetime = htole32(WPI_LIFETIME_INFINITE); in wpi_init_beacon()
608 * XXX WPI_TX_AUTO_SEQ seems to be ignored - workaround this issue in wpi_init_beacon()
611 cmd->flags = htole32(WPI_TX_NEED_ACK | WPI_TX_INSERT_TSTAMP); in wpi_init_beacon()
613 bcn->code = WPI_CMD_SET_BEACON; in wpi_init_beacon()
614 bcn->ac = WPI_CMD_QUEUE_NUM; in wpi_init_beacon()
615 bcn->size = sizeof(struct wpi_cmd_beacon); in wpi_init_beacon()
627 if (!TAILQ_EMPTY(&ic->ic_vaps)) /* only one at a time */ in wpi_vap_create()
631 vap = &wvp->wv_vap; in wpi_vap_create()
640 vap->iv_key_set = wpi_key_set; in wpi_vap_create()
641 vap->iv_key_delete = wpi_key_delete; in wpi_vap_create()
643 wvp->wv_recv_mgmt = vap->iv_recv_mgmt; in wpi_vap_create()
644 vap->iv_recv_mgmt = wpi_ibss_recv_mgmt; in wpi_vap_create()
646 wvp->wv_newstate = vap->iv_newstate; in wpi_vap_create()
647 vap->iv_newstate = wpi_newstate; in wpi_vap_create()
648 vap->iv_update_beacon = wpi_update_beacon; in wpi_vap_create()
649 vap->iv_max_aid = WPI_ID_IBSS_MAX - WPI_ID_IBSS_MIN + 1; in wpi_vap_create()
655 ic->ic_opmode = opmode; in wpi_vap_create()
663 struct wpi_buf *bcn = &wvp->wv_bcbuf; in wpi_vap_delete()
664 enum ieee80211_opmode opmode = vap->iv_opmode; in wpi_vap_delete()
670 if (bcn->m != NULL) in wpi_vap_delete()
671 m_freem(bcn->m); in wpi_vap_delete()
683 struct ieee80211com *ic = &sc->sc_ic; in wpi_detach()
688 if (ic->ic_vap_create == wpi_vap_create) { in wpi_detach()
689 ieee80211_draintask(ic, &sc->sc_radioon_task); in wpi_detach()
690 ieee80211_draintask(ic, &sc->sc_radiooff_task); in wpi_detach()
694 callout_drain(&sc->watchdog_rfkill); in wpi_detach()
695 callout_drain(&sc->tx_timeout); in wpi_detach()
696 callout_drain(&sc->scan_timeout); in wpi_detach()
697 callout_drain(&sc->calib_to); in wpi_detach()
702 if (sc->irq != NULL) { in wpi_detach()
703 bus_teardown_intr(dev, sc->irq, sc->sc_ih); in wpi_detach()
704 bus_release_resource(dev, SYS_RES_IRQ, rman_get_rid(sc->irq), in wpi_detach()
705 sc->irq); in wpi_detach()
709 if (sc->txq[0].data_dmat) { in wpi_detach()
710 /* Free DMA resources. */ in wpi_detach()
712 wpi_free_tx_ring(sc, &sc->txq[qid]); in wpi_detach()
718 if (sc->fw_dma.tag) in wpi_detach()
721 if (sc->mem != NULL) in wpi_detach()
723 rman_get_rid(sc->mem), sc->mem); in wpi_detach()
748 struct ieee80211com *ic = &sc->sc_ic; in wpi_suspend()
758 struct ieee80211com *ic = &sc->sc_ic; in wpi_resume()
760 /* Clear device-specific "PCI retry timeout" register (41h). */ in wpi_resume()
787 device_printf(sc->sc_dev, "could not lock memory\n"); in wpi_nic_lock()
833 for (; count != 0; count--, data++, addr += 4) in wpi_prph_write_region_4()
849 for (; count > 0; count--, addr += 4) in wpi_mem_read_region_4()
865 for (; count > 0; count -= 2, addr++) { in wpi_read_prom_data()
874 device_printf(sc->sc_dev, in wpi_read_prom_data()
895 KASSERT(nsegs == 1, ("too many DMA segments, %d should be 1", nsegs)); in wpi_dma_map_addr()
900 * Allocates a contiguous block of dma memory of the requested size and
904 wpi_dma_contig_alloc(struct wpi_softc *sc, struct wpi_dma_info *dma, in wpi_dma_contig_alloc() argument
909 dma->tag = NULL; in wpi_dma_contig_alloc()
910 dma->size = size; in wpi_dma_contig_alloc()
912 error = bus_dma_tag_create(bus_get_dma_tag(sc->sc_dev), alignment, in wpi_dma_contig_alloc()
914 1, size, 0, NULL, NULL, &dma->tag); in wpi_dma_contig_alloc()
918 error = bus_dmamem_alloc(dma->tag, (void **)&dma->vaddr, in wpi_dma_contig_alloc()
919 BUS_DMA_NOWAIT | BUS_DMA_ZERO | BUS_DMA_COHERENT, &dma->map); in wpi_dma_contig_alloc()
923 error = bus_dmamap_load(dma->tag, dma->map, dma->vaddr, size, in wpi_dma_contig_alloc()
924 wpi_dma_map_addr, &dma->paddr, BUS_DMA_NOWAIT); in wpi_dma_contig_alloc()
928 bus_dmamap_sync(dma->tag, dma->map, BUS_DMASYNC_PREWRITE); in wpi_dma_contig_alloc()
931 *kvap = dma->vaddr; in wpi_dma_contig_alloc()
935 fail: wpi_dma_contig_free(dma); in wpi_dma_contig_alloc()
940 wpi_dma_contig_free(struct wpi_dma_info *dma) in wpi_dma_contig_free() argument
942 if (dma->vaddr != NULL) { in wpi_dma_contig_free()
943 bus_dmamap_sync(dma->tag, dma->map, in wpi_dma_contig_free()
945 bus_dmamap_unload(dma->tag, dma->map); in wpi_dma_contig_free()
946 bus_dmamem_free(dma->tag, dma->vaddr, dma->map); in wpi_dma_contig_free()
947 dma->vaddr = NULL; in wpi_dma_contig_free()
949 if (dma->tag != NULL) { in wpi_dma_contig_free()
950 bus_dma_tag_destroy(dma->tag); in wpi_dma_contig_free()
951 dma->tag = NULL; in wpi_dma_contig_free()
962 return wpi_dma_contig_alloc(sc, &sc->shared_dma, in wpi_alloc_shared()
963 (void **)&sc->shared, sizeof (struct wpi_shared), 4096); in wpi_alloc_shared()
969 wpi_dma_contig_free(&sc->shared_dma); in wpi_free_shared()
973 * Allocate DMA-safe memory for firmware transfer.
978 /* Must be aligned on a 16-byte boundary. */ in wpi_alloc_fwmem()
979 return wpi_dma_contig_alloc(sc, &sc->fw_dma, NULL, in wpi_alloc_fwmem()
986 wpi_dma_contig_free(&sc->fw_dma); in wpi_free_fwmem()
992 struct wpi_rx_ring *ring = &sc->rxq; in wpi_alloc_rx_ring()
996 ring->cur = 0; in wpi_alloc_rx_ring()
997 ring->update = 0; in wpi_alloc_rx_ring()
1003 error = wpi_dma_contig_alloc(sc, &ring->desc_dma, in wpi_alloc_rx_ring()
1004 (void **)&ring->desc, size, WPI_RING_DMA_ALIGN); in wpi_alloc_rx_ring()
1006 device_printf(sc->sc_dev, in wpi_alloc_rx_ring()
1007 "%s: could not allocate RX ring DMA memory, error %d\n", in wpi_alloc_rx_ring()
1012 /* Create RX buffer DMA tag. */ in wpi_alloc_rx_ring()
1013 error = bus_dma_tag_create(bus_get_dma_tag(sc->sc_dev), 1, 0, in wpi_alloc_rx_ring()
1015 MJUMPAGESIZE, 1, MJUMPAGESIZE, 0, NULL, NULL, &ring->data_dmat); in wpi_alloc_rx_ring()
1017 device_printf(sc->sc_dev, in wpi_alloc_rx_ring()
1018 "%s: could not create RX buf DMA tag, error %d\n", in wpi_alloc_rx_ring()
1024 * Allocate and map RX buffers. in wpi_alloc_rx_ring()
1027 struct wpi_rx_data *data = &ring->data[i]; in wpi_alloc_rx_ring()
1030 error = bus_dmamap_create(ring->data_dmat, 0, &data->map); in wpi_alloc_rx_ring()
1032 device_printf(sc->sc_dev, in wpi_alloc_rx_ring()
1033 "%s: could not create RX buf DMA map, error %d\n", in wpi_alloc_rx_ring()
1038 data->m = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, MJUMPAGESIZE); in wpi_alloc_rx_ring()
1039 if (data->m == NULL) { in wpi_alloc_rx_ring()
1040 device_printf(sc->sc_dev, in wpi_alloc_rx_ring()
1046 error = bus_dmamap_load(ring->data_dmat, data->map, in wpi_alloc_rx_ring()
1047 mtod(data->m, void *), MJUMPAGESIZE, wpi_dma_map_addr, in wpi_alloc_rx_ring()
1050 device_printf(sc->sc_dev, in wpi_alloc_rx_ring()
1051 "%s: can't map mbuf (error %d)\n", __func__, in wpi_alloc_rx_ring()
1057 ring->desc[i] = htole32(paddr); in wpi_alloc_rx_ring()
1060 bus_dmamap_sync(ring->desc_dma.tag, ring->desc_dma.map, in wpi_alloc_rx_ring()
1077 WPI_WRITE(sc, WPI_FH_RX_WPTR, sc->rxq.cur & ~7); in wpi_update_rx_ring()
1083 struct wpi_rx_ring *ring = &sc->rxq; in wpi_update_rx_ring_ps()
1085 if (ring->update != 0) { in wpi_update_rx_ring_ps()
1095 ring->update = 1; in wpi_update_rx_ring_ps()
1106 struct wpi_rx_ring *ring = &sc->rxq; in wpi_reset_rx_ring()
1122 ring->cur = 0; in wpi_reset_rx_ring()
1123 ring->update = 0; in wpi_reset_rx_ring()
1129 struct wpi_rx_ring *ring = &sc->rxq; in wpi_free_rx_ring()
1134 wpi_dma_contig_free(&ring->desc_dma); in wpi_free_rx_ring()
1137 struct wpi_rx_data *data = &ring->data[i]; in wpi_free_rx_ring()
1139 if (data->m != NULL) { in wpi_free_rx_ring()
1140 bus_dmamap_sync(ring->data_dmat, data->map, in wpi_free_rx_ring()
1142 bus_dmamap_unload(ring->data_dmat, data->map); in wpi_free_rx_ring()
1143 m_freem(data->m); in wpi_free_rx_ring()
1144 data->m = NULL; in wpi_free_rx_ring()
1146 if (data->map != NULL) in wpi_free_rx_ring()
1147 bus_dmamap_destroy(ring->data_dmat, data->map); in wpi_free_rx_ring()
1149 if (ring->data_dmat != NULL) { in wpi_free_rx_ring()
1150 bus_dma_tag_destroy(ring->data_dmat); in wpi_free_rx_ring()
1151 ring->data_dmat = NULL; in wpi_free_rx_ring()
1162 ring->qid = qid; in wpi_alloc_tx_ring()
1163 ring->queued = 0; in wpi_alloc_tx_ring()
1164 ring->cur = 0; in wpi_alloc_tx_ring()
1165 ring->pending = 0; in wpi_alloc_tx_ring()
1166 ring->update = 0; in wpi_alloc_tx_ring()
1172 error = wpi_dma_contig_alloc(sc, &ring->desc_dma, (void **)&ring->desc, in wpi_alloc_tx_ring()
1175 device_printf(sc->sc_dev, in wpi_alloc_tx_ring()
1176 "%s: could not allocate TX ring DMA memory, error %d\n", in wpi_alloc_tx_ring()
1182 sc->shared->txbase[qid] = htole32(ring->desc_dma.paddr); in wpi_alloc_tx_ring()
1183 bus_dmamap_sync(sc->shared_dma.tag, sc->shared_dma.map, in wpi_alloc_tx_ring()
1187 error = wpi_dma_contig_alloc(sc, &ring->cmd_dma, (void **)&ring->cmd, in wpi_alloc_tx_ring()
1190 device_printf(sc->sc_dev, in wpi_alloc_tx_ring()
1191 "%s: could not allocate TX cmd DMA memory, error %d\n", in wpi_alloc_tx_ring()
1196 error = bus_dma_tag_create(bus_get_dma_tag(sc->sc_dev), 1, 0, in wpi_alloc_tx_ring()
1198 WPI_MAX_SCATTER - 1, MCLBYTES, 0, NULL, NULL, &ring->data_dmat); in wpi_alloc_tx_ring()
1200 device_printf(sc->sc_dev, in wpi_alloc_tx_ring()
1201 "%s: could not create TX buf DMA tag, error %d\n", in wpi_alloc_tx_ring()
1206 paddr = ring->cmd_dma.paddr; in wpi_alloc_tx_ring()
1208 struct wpi_tx_data *data = &ring->data[i]; in wpi_alloc_tx_ring()
1210 data->cmd_paddr = paddr; in wpi_alloc_tx_ring()
1213 error = bus_dmamap_create(ring->data_dmat, 0, &data->map); in wpi_alloc_tx_ring()
1215 device_printf(sc->sc_dev, in wpi_alloc_tx_ring()
1216 "%s: could not create TX buf DMA map, error %d\n", in wpi_alloc_tx_ring()
1234 WPI_WRITE(sc, WPI_HBUS_TARG_WRPTR, ring->qid << 8 | ring->cur); in wpi_update_tx_ring()
1241 if (ring->update != 0) { in wpi_update_tx_ring_ps()
1249 __func__, ring->qid); in wpi_update_tx_ring_ps()
1250 ring->update = 1; in wpi_update_tx_ring_ps()
1265 struct wpi_tx_data *data = &ring->data[i]; in wpi_reset_tx_ring()
1267 if (data->m != NULL) { in wpi_reset_tx_ring()
1268 bus_dmamap_sync(ring->data_dmat, data->map, in wpi_reset_tx_ring()
1270 bus_dmamap_unload(ring->data_dmat, data->map); in wpi_reset_tx_ring()
1271 m_freem(data->m); in wpi_reset_tx_ring()
1272 data->m = NULL; in wpi_reset_tx_ring()
1274 if (data->ni != NULL) { in wpi_reset_tx_ring()
1275 ieee80211_free_node(data->ni); in wpi_reset_tx_ring()
1276 data->ni = NULL; in wpi_reset_tx_ring()
1280 memset(ring->desc, 0, ring->desc_dma.size); in wpi_reset_tx_ring()
1281 bus_dmamap_sync(ring->desc_dma.tag, ring->desc_dma.map, in wpi_reset_tx_ring()
1283 ring->queued = 0; in wpi_reset_tx_ring()
1284 ring->cur = 0; in wpi_reset_tx_ring()
1285 ring->pending = 0; in wpi_reset_tx_ring()
1286 ring->update = 0; in wpi_reset_tx_ring()
1296 wpi_dma_contig_free(&ring->desc_dma); in wpi_free_tx_ring()
1297 wpi_dma_contig_free(&ring->cmd_dma); in wpi_free_tx_ring()
1300 struct wpi_tx_data *data = &ring->data[i]; in wpi_free_tx_ring()
1302 if (data->m != NULL) { in wpi_free_tx_ring()
1303 bus_dmamap_sync(ring->data_dmat, data->map, in wpi_free_tx_ring()
1305 bus_dmamap_unload(ring->data_dmat, data->map); in wpi_free_tx_ring()
1306 m_freem(data->m); in wpi_free_tx_ring()
1308 if (data->map != NULL) in wpi_free_tx_ring()
1309 bus_dmamap_destroy(ring->data_dmat, data->map); in wpi_free_tx_ring()
1311 if (ring->data_dmat != NULL) { in wpi_free_tx_ring()
1312 bus_dma_tag_destroy(ring->data_dmat); in wpi_free_tx_ring()
1313 ring->data_dmat = NULL; in wpi_free_tx_ring()
1334 device_printf(sc->sc_dev, in wpi_read_eeprom()
1341 device_printf(sc->sc_dev, "bad EEPROM signature\n"); in wpi_read_eeprom()
1349 WPI_CHK(wpi_read_prom_data(sc, WPI_EEPROM_SKU_CAP, &sc->cap, in wpi_read_eeprom()
1350 sizeof(sc->cap))); in wpi_read_eeprom()
1351 WPI_CHK(wpi_read_prom_data(sc, WPI_EEPROM_REVISION, &sc->rev, in wpi_read_eeprom()
1352 sizeof(sc->rev))); in wpi_read_eeprom()
1353 WPI_CHK(wpi_read_prom_data(sc, WPI_EEPROM_TYPE, &sc->type, in wpi_read_eeprom()
1354 sizeof(sc->type))); in wpi_read_eeprom()
1356 sc->rev = le16toh(sc->rev); in wpi_read_eeprom()
1357 DPRINTF(sc, WPI_DEBUG_EEPROM, "cap=%x rev=%x type=%x\n", sc->cap, in wpi_read_eeprom()
1358 sc->rev, sc->type); in wpi_read_eeprom()
1361 WPI_CHK(wpi_read_prom_data(sc, WPI_EEPROM_DOMAIN, sc->domain, in wpi_read_eeprom()
1362 sizeof(sc->domain))); in wpi_read_eeprom()
1394 if ((channel->flags & WPI_EEPROM_CHAN_ACTIVE) == 0) in wpi_eeprom_channel_flags()
1396 if ((channel->flags & WPI_EEPROM_CHAN_IBSS) == 0) in wpi_eeprom_channel_flags()
1398 if (channel->flags & WPI_EEPROM_CHAN_RADAR) { in wpi_eeprom_channel_flags()
1415 struct wpi_eeprom_chan *channels = sc->eeprom_channels[n]; in wpi_read_eeprom_band()
1430 for (i = 0; i < band->nchan; i++) { in wpi_read_eeprom_band()
1434 band->chan[i],n); in wpi_read_eeprom_band()
1438 chan = band->chan[i]; in wpi_read_eeprom_band()
1446 sc->maxpwr[chan] = channels[i].maxpwr; in wpi_read_eeprom_band()
1450 chan, channels[i].flags, sc->maxpwr[chan], *nchans); in wpi_read_eeprom_band()
1461 struct ieee80211com *ic = &sc->sc_ic; in wpi_read_eeprom_channels()
1467 error = wpi_read_prom_data(sc, band->addr, &sc->eeprom_channels[n], in wpi_read_eeprom_channels()
1468 band->nchan * sizeof (struct wpi_eeprom_chan)); in wpi_read_eeprom_channels()
1474 wpi_read_eeprom_band(sc, n, IEEE80211_CHAN_MAX, &ic->ic_nchans, in wpi_read_eeprom_channels()
1475 ic->ic_channels); in wpi_read_eeprom_channels()
1477 ieee80211_sort_channels(ic->ic_channels, ic->ic_nchans); in wpi_read_eeprom_channels()
1491 if (wpi_bands[j].chan[i] == c->ic_ieee && in wpi_find_eeprom_channel()
1493 return &sc->eeprom_channels[j][i]; in wpi_find_eeprom_channel()
1502 struct wpi_softc *sc = ic->ic_softc; in wpi_getradiocaps()
1517 struct wpi_softc *sc = ic->ic_softc; in wpi_setregdomain()
1527 __func__, c->ic_ieee, c->ic_freq, c->ic_flags); in wpi_setregdomain()
1530 c->ic_flags |= wpi_eeprom_channel_flags(channel); in wpi_setregdomain()
1539 struct wpi_power_group *group = &sc->groups[n]; in wpi_read_eeprom_group()
1552 group->chan = rgroup.chan; in wpi_read_eeprom_group()
1553 group->maxpwr = rgroup.maxpwr; in wpi_read_eeprom_group()
1555 group->temp = (int16_t)le16toh(rgroup.temp); in wpi_read_eeprom_group()
1558 "power group %d: chan=%d maxpwr=%d temp=%d\n", n, group->chan, in wpi_read_eeprom_group()
1559 group->maxpwr, group->temp); in wpi_read_eeprom_group()
1562 group->samples[i].index = rgroup.samples[i].index; in wpi_read_eeprom_group()
1563 group->samples[i].power = rgroup.samples[i].power; in wpi_read_eeprom_group()
1567 group->samples[i].index, group->samples[i].power); in wpi_read_eeprom_group()
1581 if ((sc->nodesmsk & (1 << newid)) == 0) { in wpi_add_node_entry_adhoc()
1582 sc->nodesmsk |= 1 << newid; in wpi_add_node_entry_adhoc()
1593 sc->nodesmsk |= 1 << WPI_ID_BSS; in wpi_add_node_entry_sta()
1604 return (sc->nodesmsk >> id) & 1; in wpi_check_node_entry()
1610 sc->nodesmsk = 0; in wpi_clear_node_table()
1616 sc->nodesmsk &= ~(1 << id); in wpi_del_node_entry()
1630 wn->id = WPI_ID_UNDEFINED; in wpi_node_alloc()
1632 return &wn->ni; in wpi_node_alloc()
1638 struct wpi_softc *sc = ni->ni_ic->ic_softc; in wpi_node_free()
1641 if (wn->id != WPI_ID_UNDEFINED) { in wpi_node_free()
1643 if (wpi_check_node_entry(sc, wn->id)) { in wpi_node_free()
1644 wpi_del_node_entry(sc, wn->id); in wpi_node_free()
1650 sc->sc_node_free(ni); in wpi_node_free()
1656 return (sc->rxon.filter & htole32(WPI_FILTER_BSS)) != 0; in wpi_check_bss_filter()
1664 struct ieee80211vap *vap = ni->ni_vap; in wpi_ibss_recv_mgmt()
1665 struct wpi_softc *sc = vap->iv_ic->ic_softc; in wpi_ibss_recv_mgmt()
1669 wvp->wv_recv_mgmt(ni, m, subtype, rxs, rssi, nf); in wpi_ibss_recv_mgmt()
1671 if (vap->iv_state == IEEE80211_S_RUN && in wpi_ibss_recv_mgmt()
1674 ni_tstamp = le64toh(ni->ni_tstamp.tsf); in wpi_ibss_recv_mgmt()
1675 rx_tstamp = le64toh(sc->rx_tstamp); in wpi_ibss_recv_mgmt()
1694 if (wn->id != WPI_ID_UNDEFINED) { in wpi_restore_node()
1695 wn->id = WPI_ID_UNDEFINED; in wpi_restore_node()
1697 device_printf(sc->sc_dev, in wpi_restore_node()
1708 struct ieee80211com *ic = &sc->sc_ic; in wpi_restore_node_table()
1712 wvp->wv_gtk = 0; in wpi_restore_node_table()
1715 ieee80211_iterate_nodes(&ic->ic_sta, wpi_restore_node, sc); in wpi_restore_node_table()
1726 struct ieee80211com *ic = vap->iv_ic; in wpi_newstate()
1727 struct wpi_softc *sc = ic->ic_softc; in wpi_newstate()
1733 if (nstate > IEEE80211_S_INIT && sc->sc_running == 0) { in wpi_newstate()
1741 DPRINTF(sc, WPI_DEBUG_STATE, "%s: %s -> %s\n", __func__, in wpi_newstate()
1742 ieee80211_state_name[vap->iv_state], in wpi_newstate()
1745 if (vap->iv_state == IEEE80211_S_RUN && nstate < IEEE80211_S_RUN) { in wpi_newstate()
1747 device_printf(sc->sc_dev, in wpi_newstate()
1760 sc->rxon.filter &= ~htole32(WPI_FILTER_BSS); in wpi_newstate()
1762 device_printf(sc->sc_dev, in wpi_newstate()
1770 if (vap->iv_state != IEEE80211_S_RUN) in wpi_newstate()
1775 * NB: do not optimize AUTH -> AUTH state transmission - in wpi_newstate()
1776 * this will break powersave with non-QoS AP! in wpi_newstate()
1781 * Also the associd must be cleared on RUN -> ASSOC in wpi_newstate()
1785 device_printf(sc->sc_dev, in wpi_newstate()
1793 * RUN -> RUN transition: in wpi_newstate()
1797 if (vap->iv_state == IEEE80211_S_RUN) { in wpi_newstate()
1798 if (vap->iv_opmode != IEEE80211_M_IBSS) { in wpi_newstate()
1809 sc->rxon.filter &= ~htole32(WPI_FILTER_BSS); in wpi_newstate()
1811 device_printf(sc->sc_dev, in wpi_newstate()
1826 * !RUN -> RUN requires setting the association id in wpi_newstate()
1831 device_printf(sc->sc_dev, in wpi_newstate()
1846 return wvp->wv_newstate(vap, nstate, arg); in wpi_newstate()
1859 callout_reset(&sc->calib_to, 60*hz, wpi_calib_timeout, sc); in wpi_calib_timeout()
1909 struct ieee80211com *ic = &sc->sc_ic; in wpi_rx_done()
1910 struct wpi_rx_ring *ring = &sc->rxq; in wpi_rx_done()
1924 if (__predict_false(stat->len > WPI_STAT_MAXLEN)) { in wpi_rx_done()
1925 device_printf(sc->sc_dev, "invalid RX statistic header\n"); in wpi_rx_done()
1929 bus_dmamap_sync(ring->data_dmat, data->map, BUS_DMASYNC_POSTREAD); in wpi_rx_done()
1930 head = (struct wpi_rx_head *)((caddr_t)(stat + 1) + stat->len); in wpi_rx_done()
1931 len = le16toh(head->len); in wpi_rx_done()
1933 flags = le32toh(tail->flags); in wpi_rx_done()
1936 " rate %x chan %d tstamp %ju\n", __func__, ring->cur, in wpi_rx_done()
1937 le32toh(desc->len), len, (int8_t)stat->rssi, in wpi_rx_done()
1938 head->plcp, head->chan, (uintmax_t)le64toh(tail->tstamp)); in wpi_rx_done()
1959 bus_dmamap_unload(ring->data_dmat, data->map); in wpi_rx_done()
1961 error = bus_dmamap_load(ring->data_dmat, data->map, mtod(m1, void *), in wpi_rx_done()
1964 device_printf(sc->sc_dev, in wpi_rx_done()
1969 error = bus_dmamap_load(ring->data_dmat, data->map, in wpi_rx_done()
1970 mtod(data->m, void *), MJUMPAGESIZE, wpi_dma_map_addr, in wpi_rx_done()
1976 ring->desc[ring->cur] = htole32(paddr); in wpi_rx_done()
1977 bus_dmamap_sync(ring->data_dmat, ring->desc_dma.map, in wpi_rx_done()
1982 m = data->m; in wpi_rx_done()
1983 data->m = m1; in wpi_rx_done()
1985 ring->desc[ring->cur] = htole32(paddr); in wpi_rx_done()
1986 bus_dmamap_sync(ring->desc_dma.tag, ring->desc_dma.map, in wpi_rx_done()
1990 m->m_data = (caddr_t)(head + 1); in wpi_rx_done()
1991 m->m_pkthdr.len = m->m_len = len; in wpi_rx_done()
1996 if ((wh->i_fc[1] & IEEE80211_FC1_PROTECTED) && in wpi_rx_done()
2004 m->m_flags |= M_WEP; in wpi_rx_done()
2012 sc->rx_tstamp = tail->tstamp; in wpi_rx_done()
2015 struct wpi_rx_radiotap_header *tap = &sc->sc_rxtap; in wpi_rx_done()
2017 tap->wr_flags = 0; in wpi_rx_done()
2018 if (head->flags & htole16(WPI_STAT_FLAG_SHPREAMBLE)) in wpi_rx_done()
2019 tap->wr_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; in wpi_rx_done()
2020 tap->wr_dbm_antsignal = (int8_t)(stat->rssi + WPI_RSSI_OFFSET); in wpi_rx_done()
2021 tap->wr_dbm_antnoise = WPI_RSSI_OFFSET; in wpi_rx_done()
2022 tap->wr_tsft = tail->tstamp; in wpi_rx_done()
2023 tap->wr_antenna = (le16toh(head->flags) >> 4) & 0xf; in wpi_rx_done()
2024 tap->wr_rate = plcp2rate(head->plcp); in wpi_rx_done()
2031 (void)ieee80211_input(ni, m, stat->rssi, WPI_RSSI_OFFSET); in wpi_rx_done()
2035 (void)ieee80211_input_all(ic, m, stat->rssi, WPI_RSSI_OFFSET); in wpi_rx_done()
2043 fail1: counter_u64_add(ic->ic_ierrors, 1); in wpi_rx_done()
2056 struct ieee80211_ratectl_tx_status *txs = &sc->sc_txs; in wpi_tx_done()
2057 struct wpi_tx_ring *ring = &sc->txq[desc->qid & 0x3]; in wpi_tx_done()
2058 struct wpi_tx_data *data = &ring->data[desc->idx]; in wpi_tx_done()
2062 uint32_t status = le32toh(stat->status); in wpi_tx_done()
2064 KASSERT(data->ni != NULL, ("no node")); in wpi_tx_done()
2065 KASSERT(data->m != NULL, ("no mbuf")); in wpi_tx_done()
2071 "status %x\n", __func__, desc->qid, desc->idx, stat->ackfailcnt, in wpi_tx_done()
2072 stat->btkillcnt, stat->rate, le32toh(stat->duration), status); in wpi_tx_done()
2075 bus_dmamap_sync(ring->data_dmat, data->map, BUS_DMASYNC_POSTWRITE); in wpi_tx_done()
2076 bus_dmamap_unload(ring->data_dmat, data->map); in wpi_tx_done()
2077 m = data->m, data->m = NULL; in wpi_tx_done()
2078 ni = data->ni, data->ni = NULL; in wpi_tx_done()
2081 KASSERT(M_LEADINGSPACE(m) >= data->hdrlen, ("no frame header!")); in wpi_tx_done()
2082 M_PREPEND(m, data->hdrlen, M_NOWAIT); in wpi_tx_done()
2088 txs->pktlen = m->m_pkthdr.len; in wpi_tx_done()
2089 txs->short_retries = stat->rtsfailcnt; in wpi_tx_done()
2090 txs->long_retries = stat->ackfailcnt / WPI_NTRIES_DEFAULT; in wpi_tx_done()
2092 txs->status = IEEE80211_RATECTL_TX_SUCCESS; in wpi_tx_done()
2096 txs->status = IEEE80211_RATECTL_TX_FAIL_SHORT; in wpi_tx_done()
2099 txs->status = IEEE80211_RATECTL_TX_FAIL_LONG; in wpi_tx_done()
2102 txs->status = IEEE80211_RATECTL_TX_FAIL_EXPIRED; in wpi_tx_done()
2105 txs->status = IEEE80211_RATECTL_TX_FAIL_UNSPECIFIED; in wpi_tx_done()
2114 if (--ring->queued > 0) in wpi_tx_done()
2115 callout_reset(&sc->tx_timeout, 5*hz, wpi_tx_timeout, sc); in wpi_tx_done()
2117 callout_stop(&sc->tx_timeout); in wpi_tx_done()
2130 struct wpi_tx_ring *ring = &sc->txq[WPI_CMD_QUEUE_NUM]; in wpi_cmd_done()
2135 "type %s len %d\n", desc->qid, desc->idx, in wpi_cmd_done()
2136 desc->flags, wpi_cmd_str(desc->type), in wpi_cmd_done()
2137 le32toh(desc->len)); in wpi_cmd_done()
2139 if ((desc->qid & WPI_RX_DESC_QID_MSK) != WPI_CMD_QUEUE_NUM) in wpi_cmd_done()
2142 KASSERT(ring->queued == 0, ("ring->queued must be 0")); in wpi_cmd_done()
2144 data = &ring->data[desc->idx]; in wpi_cmd_done()
2145 cmd = &ring->cmd[desc->idx]; in wpi_cmd_done()
2148 if (data->m != NULL) { in wpi_cmd_done()
2149 bus_dmamap_sync(ring->data_dmat, data->map, in wpi_cmd_done()
2151 bus_dmamap_unload(ring->data_dmat, data->map); in wpi_cmd_done()
2152 m_freem(data->m); in wpi_cmd_done()
2153 data->m = NULL; in wpi_cmd_done()
2158 if (desc->type == WPI_CMD_SET_POWER_MODE) { in wpi_cmd_done()
2159 struct wpi_pmgt_cmd *pcmd = (struct wpi_pmgt_cmd *)cmd->data; in wpi_cmd_done()
2161 bus_dmamap_sync(ring->data_dmat, ring->cmd_dma.map, in wpi_cmd_done()
2165 if (le16toh(pcmd->flags) & WPI_PS_ALLOW_SLEEP) { in wpi_cmd_done()
2166 sc->sc_update_rx_ring = wpi_update_rx_ring_ps; in wpi_cmd_done()
2167 sc->sc_update_tx_ring = wpi_update_tx_ring_ps; in wpi_cmd_done()
2169 sc->sc_update_rx_ring = wpi_update_rx_ring; in wpi_cmd_done()
2170 sc->sc_update_tx_ring = wpi_update_tx_ring; in wpi_cmd_done()
2179 struct ieee80211com *ic = &sc->sc_ic; in wpi_notif_intr()
2180 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); in wpi_notif_intr()
2183 bus_dmamap_sync(sc->shared_dma.tag, sc->shared_dma.map, in wpi_notif_intr()
2186 hw = le32toh(sc->shared->next) & 0xfff; in wpi_notif_intr()
2187 hw = (hw == 0) ? WPI_RX_RING_COUNT - 1 : hw - 1; in wpi_notif_intr()
2189 while (sc->rxq.cur != hw) { in wpi_notif_intr()
2190 sc->rxq.cur = (sc->rxq.cur + 1) % WPI_RX_RING_COUNT; in wpi_notif_intr()
2192 struct wpi_rx_data *data = &sc->rxq.data[sc->rxq.cur]; in wpi_notif_intr()
2195 bus_dmamap_sync(sc->rxq.data_dmat, data->map, in wpi_notif_intr()
2197 desc = mtod(data->m, struct wpi_rx_desc *); in wpi_notif_intr()
2201 __func__, sc->rxq.cur, desc->qid, desc->idx, desc->flags, in wpi_notif_intr()
2202 desc->type, wpi_cmd_str(desc->type), le32toh(desc->len)); in wpi_notif_intr()
2204 if (!(desc->qid & WPI_UNSOLICITED_RX_NOTIF)) { in wpi_notif_intr()
2209 switch (desc->type) { in wpi_notif_intr()
2214 if (__predict_false(sc->sc_running == 0)) { in wpi_notif_intr()
2237 bus_dmamap_sync(sc->rxq.data_dmat, data->map, in wpi_notif_intr()
2240 misses = le32toh(miss->consecutive); in wpi_notif_intr()
2241 expected = le32toh(miss->expected); in wpi_notif_intr()
2242 received = le32toh(miss->received); in wpi_notif_intr()
2243 threshold = MAX(2, vap->iv_bmissthreshold); in wpi_notif_intr()
2247 __func__, misses, le32toh(miss->total), received, in wpi_notif_intr()
2253 if (callout_pending(&sc->scan_timeout)) { in wpi_notif_intr()
2258 if (vap->iv_state == IEEE80211_S_RUN && in wpi_notif_intr()
2259 (ic->ic_flags & IEEE80211_F_SCAN) == 0) in wpi_notif_intr()
2273 bus_dmamap_sync(sc->rxq.data_dmat, data->map, in wpi_notif_intr()
2279 stat->rtsfailcnt, stat->ackfailcnt, in wpi_notif_intr()
2280 stat->btkillcnt, stat->rate, le32toh(stat->duration), in wpi_notif_intr()
2281 le32toh(stat->status), le64toh(*tsf), in wpi_notif_intr()
2293 bus_dmamap_sync(sc->rxq.data_dmat, data->map, in wpi_notif_intr()
2297 "subtype=%x alive=%x\n", uc->major, uc->minor, in wpi_notif_intr()
2298 uc->subtype, le32toh(uc->valid)); in wpi_notif_intr()
2300 if (le32toh(uc->valid) != 1) { in wpi_notif_intr()
2301 device_printf(sc->sc_dev, in wpi_notif_intr()
2307 sc->errptr = le32toh(uc->errptr); in wpi_notif_intr()
2312 bus_dmamap_sync(sc->rxq.data_dmat, data->map, in wpi_notif_intr()
2325 &sc->sc_radiooff_task); in wpi_notif_intr()
2333 bus_dmamap_sync(sc->rxq.data_dmat, data->map, in wpi_notif_intr()
2340 __func__, scan->chan, le32toh(scan->status)); in wpi_notif_intr()
2347 bus_dmamap_sync(sc->rxq.data_dmat, data->map, in wpi_notif_intr()
2355 scan->nchan, scan->status, scan->chan); in wpi_notif_intr()
2358 callout_stop(&sc->scan_timeout); in wpi_notif_intr()
2360 if (scan->status == WPI_SCAN_ABORTED) in wpi_notif_intr()
2368 if (sc->rxq.cur % 8 == 0) { in wpi_notif_intr()
2370 sc->sc_update_rx_ring(sc); in wpi_notif_intr()
2377 * from power-down sleep mode.
2385 "%s: ucode wakeup from power-down sleep\n", __func__); in wpi_wakeup_intr()
2388 if (sc->rxq.update) { in wpi_wakeup_intr()
2389 sc->rxq.update = 0; in wpi_wakeup_intr()
2394 struct wpi_tx_ring *ring = &sc->txq[qid]; in wpi_wakeup_intr()
2396 if (ring->update) { in wpi_wakeup_intr()
2397 ring->update = 0; in wpi_wakeup_intr()
2440 DPRINTF(sc, WPI_DEBUG_REGISTER, " %-18s: 0x%08x ", in wpi_debug_registers()
2450 DPRINTF(sc, WPI_DEBUG_REGISTER, " %-18s: 0x%08x ", in wpi_debug_registers()
2478 if (sc->errptr < WPI_FW_DATA_BASE || in wpi_fatal_intr()
2479 sc->errptr + sizeof (dump) > in wpi_fatal_intr()
2482 sc->errptr); in wpi_fatal_intr()
2490 count = wpi_mem_read(sc, sc->errptr); in wpi_fatal_intr()
2498 offset = sc->errptr + sizeof (uint32_t); in wpi_fatal_intr()
2523 struct wpi_tx_ring *ring = &sc->txq[i]; in wpi_fatal_intr()
2524 printf(" tx ring %2d: qid=%-2d cur=%-3d queued=%-3d\n", in wpi_fatal_intr()
2525 i, ring->qid, ring->cur, ring->queued); in wpi_fatal_intr()
2528 printf(" rx ring: cur=%d\n", sc->rxq.cur); in wpi_fatal_intr()
2561 struct ieee80211com *ic = &sc->sc_ic; in wpi_intr()
2563 device_printf(sc->sc_dev, "fatal firmware error\n"); in wpi_intr()
2586 /* Re-enable interrupts. */ in wpi_intr()
2587 if (__predict_true(sc->sc_running)) in wpi_intr()
2601 ring = &sc->txq[ac]; in wpi_free_txfrags()
2603 while (ring->pending != 0) { in wpi_free_txfrags()
2604 ring->pending--; in wpi_free_txfrags()
2605 cur = (ring->cur + ring->pending) % WPI_TX_RING_COUNT; in wpi_free_txfrags()
2606 data = &ring->data[cur]; in wpi_free_txfrags()
2608 bus_dmamap_sync(ring->data_dmat, data->map, in wpi_free_txfrags()
2610 bus_dmamap_unload(ring->data_dmat, data->map); in wpi_free_txfrags()
2611 m_freem(data->m); in wpi_free_txfrags()
2612 data->m = NULL; in wpi_free_txfrags()
2614 ieee80211_node_decref(data->ni); in wpi_free_txfrags()
2615 data->ni = NULL; in wpi_free_txfrags()
2637 KASSERT(buf->size <= sizeof(buf->data), ("buffer overflow")); in wpi_cmd2()
2641 if (__predict_false(sc->sc_running == 0)) { in wpi_cmd2()
2647 wh = mtod(buf->m, struct ieee80211_frame *); in wpi_cmd2()
2649 totlen = buf->m->m_pkthdr.len; in wpi_cmd2()
2650 frag = ((buf->m->m_flags & (M_FRAG | M_LASTFRAG)) == M_FRAG); in wpi_cmd2()
2659 pad = 4 - (hdrlen & 3); in wpi_cmd2()
2663 ring = &sc->txq[buf->ac]; in wpi_cmd2()
2664 cur = (ring->cur + ring->pending) % WPI_TX_RING_COUNT; in wpi_cmd2()
2665 desc = &ring->desc[cur]; in wpi_cmd2()
2666 data = &ring->data[cur]; in wpi_cmd2()
2669 cmd = &ring->cmd[cur]; in wpi_cmd2()
2670 cmd->code = buf->code; in wpi_cmd2()
2671 cmd->flags = 0; in wpi_cmd2()
2672 cmd->qid = ring->qid; in wpi_cmd2()
2673 cmd->idx = cur; in wpi_cmd2()
2675 memcpy(cmd->data, buf->data, buf->size); in wpi_cmd2()
2678 memcpy((uint8_t *)(cmd->data + buf->size), wh, hdrlen); in wpi_cmd2()
2679 m_adj(buf->m, hdrlen); in wpi_cmd2()
2681 error = bus_dmamap_load_mbuf_sg(ring->data_dmat, data->map, buf->m, in wpi_cmd2()
2684 device_printf(sc->sc_dev, in wpi_cmd2()
2685 "%s: can't map mbuf (error %d)\n", __func__, error); in wpi_cmd2()
2689 /* Too many DMA segments, linearize mbuf. */ in wpi_cmd2()
2690 m1 = m_collapse(buf->m, M_NOWAIT, WPI_MAX_SCATTER - 1); in wpi_cmd2()
2692 device_printf(sc->sc_dev, in wpi_cmd2()
2697 buf->m = m1; in wpi_cmd2()
2699 error = bus_dmamap_load_mbuf_sg(ring->data_dmat, data->map, in wpi_cmd2()
2700 buf->m, segs, &nsegs, BUS_DMA_NOWAIT); in wpi_cmd2()
2707 device_printf(sc->sc_dev, in wpi_cmd2()
2708 "%s: can't map mbuf (error %d)\n", __func__, in wpi_cmd2()
2710 if (ring->qid < WPI_CMD_QUEUE_NUM) { in wpi_cmd2()
2711 if_inc_counter(buf->ni->ni_vap->iv_ifp, in wpi_cmd2()
2714 ieee80211_free_node(buf->ni); in wpi_cmd2()
2716 m_freem(buf->m); in wpi_cmd2()
2723 ("too many DMA segments, nsegs (%d) should be less than %d", in wpi_cmd2()
2726 data->m = buf->m; in wpi_cmd2()
2727 data->ni = buf->ni; in wpi_cmd2()
2728 data->hdrlen = hdrlen; in wpi_cmd2()
2731 __func__, ring->qid, cur, totlen, nsegs); in wpi_cmd2()
2734 desc->nsegs = WPI_PAD32(totlen + pad) << 4 | (1 + nsegs); in wpi_cmd2()
2735 /* First DMA segment is used by the TX command. */ in wpi_cmd2()
2736 desc->segs[0].addr = htole32(data->cmd_paddr); in wpi_cmd2()
2737 desc->segs[0].len = htole32(4 + buf->size + hdrlen + pad); in wpi_cmd2()
2738 /* Other DMA segments are for data payload. */ in wpi_cmd2()
2741 desc->segs[i].addr = htole32(seg->ds_addr); in wpi_cmd2()
2742 desc->segs[i].len = htole32(seg->ds_len); in wpi_cmd2()
2746 bus_dmamap_sync(ring->data_dmat, data->map, BUS_DMASYNC_PREWRITE); in wpi_cmd2()
2747 bus_dmamap_sync(ring->data_dmat, ring->cmd_dma.map, in wpi_cmd2()
2749 bus_dmamap_sync(ring->desc_dma.tag, ring->desc_dma.map, in wpi_cmd2()
2752 ring->pending += 1; in wpi_cmd2()
2755 if (ring->qid < WPI_CMD_QUEUE_NUM) { in wpi_cmd2()
2757 ring->queued += ring->pending; in wpi_cmd2()
2758 callout_reset(&sc->tx_timeout, 5*hz, wpi_tx_timeout, in wpi_cmd2()
2764 ring->cur = (ring->cur + ring->pending) % WPI_TX_RING_COUNT; in wpi_cmd2()
2765 ring->pending = 0; in wpi_cmd2()
2766 sc->sc_update_tx_ring(sc, ring); in wpi_cmd2()
2768 (void) ieee80211_ref_node(data->ni); in wpi_cmd2()
2784 const struct ieee80211_txparam *tp = ni->ni_txparms; in wpi_tx_data()
2785 struct ieee80211vap *vap = ni->ni_vap; in wpi_tx_data()
2786 struct ieee80211com *ic = ni->ni_ic; in wpi_tx_data()
2798 type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK; in wpi_tx_data()
2799 ismcast = IEEE80211_IS_MULTICAST(wh->i_addr1); in wpi_tx_data()
2804 qos = ((const struct ieee80211_qosframe *)wh)->i_qos[0]; in wpi_tx_data()
2815 (m->m_flags & M_EAPOL) != 0) in wpi_tx_data()
2816 rate = tp->mgmtrate; in wpi_tx_data()
2818 rate = tp->mcastrate; in wpi_tx_data()
2819 else if (tp->ucastrate != IEEE80211_FIXED_RATE_NONE) in wpi_tx_data()
2820 rate = tp->ucastrate; in wpi_tx_data()
2824 rate = ni->ni_txrate; in wpi_tx_data()
2828 if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) { in wpi_tx_data()
2834 swcrypt = k->wk_flags & IEEE80211_KEY_SWCRYPT; in wpi_tx_data()
2839 totlen = m->m_pkthdr.len; in wpi_tx_data()
2842 struct wpi_tx_radiotap_header *tap = &sc->sc_txtap; in wpi_tx_data()
2844 tap->wt_flags = 0; in wpi_tx_data()
2845 tap->wt_rate = rate; in wpi_tx_data()
2847 tap->wt_flags |= IEEE80211_RADIOTAP_F_WEP; in wpi_tx_data()
2848 if (wh->i_fc[1] & IEEE80211_FC1_MORE_FRAG) in wpi_tx_data()
2849 tap->wt_flags |= IEEE80211_RADIOTAP_F_FRAG; in wpi_tx_data()
2864 if (wh->i_fc[1] & IEEE80211_FC1_MORE_FRAG) in wpi_tx_data()
2867 /* Check if frame must be protected using RTS/CTS or CTS-to-self. */ in wpi_tx_data()
2870 if (totlen + IEEE80211_CRC_LEN > vap->iv_rtsthreshold) { in wpi_tx_data()
2872 } else if ((ic->ic_flags & IEEE80211_F_USEPROT) && in wpi_tx_data()
2874 if (ic->ic_protmode == IEEE80211_PROT_CTSONLY) in wpi_tx_data()
2876 else if (ic->ic_protmode == IEEE80211_PROT_RTSCTS) in wpi_tx_data()
2886 uint8_t subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK; in wpi_tx_data()
2893 tx->timeout = htole16(3); in wpi_tx_data()
2895 tx->timeout = htole16(2); in wpi_tx_data()
2899 tx->id = WPI_ID_BROADCAST; in wpi_tx_data()
2901 if (wn->id == WPI_ID_UNDEFINED) { in wpi_tx_data()
2902 device_printf(sc->sc_dev, in wpi_tx_data()
2907 tx->id = wn->id; in wpi_tx_data()
2911 switch (k->wk_cipher->ic_cipher) { in wpi_tx_data()
2913 tx->security = WPI_CIPHER_CCMP; in wpi_tx_data()
2920 memcpy(tx->key, k->wk_key, k->wk_keylen); in wpi_tx_data()
2923 if (wh->i_fc[1] & IEEE80211_FC1_MORE_FRAG) { in wpi_tx_data()
2924 struct mbuf *next = m->m_nextpkt; in wpi_tx_data()
2926 tx->lnext = htole16(next->m_pkthdr.len); in wpi_tx_data()
2927 tx->fnext = htole32(tx->security | in wpi_tx_data()
2929 WPI_NEXT_STA_ID(tx->id)); in wpi_tx_data()
2932 tx->len = htole16(totlen); in wpi_tx_data()
2933 tx->flags = htole32(flags); in wpi_tx_data()
2934 tx->plcp = rate2plcp(rate); in wpi_tx_data()
2935 tx->tid = tid; in wpi_tx_data()
2936 tx->lifetime = htole32(WPI_LIFETIME_INFINITE); in wpi_tx_data()
2937 tx->ofdm_mask = 0xff; in wpi_tx_data()
2938 tx->cck_mask = 0x0f; in wpi_tx_data()
2939 tx->rts_ntries = 7; in wpi_tx_data()
2940 tx->data_ntries = tp->maxretry; in wpi_tx_data()
2955 struct ieee80211vap *vap = ni->ni_vap; in wpi_tx_data_raw()
2965 type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK; in wpi_tx_data_raw()
2968 ac = params->ibp_pri & 3; in wpi_tx_data_raw()
2971 rate = params->ibp_rate0; in wpi_tx_data_raw()
2976 if ((params->ibp_flags & IEEE80211_BPF_NOACK) == 0) in wpi_tx_data_raw()
2978 if (params->ibp_flags & IEEE80211_BPF_RTS) in wpi_tx_data_raw()
2980 if (params->ibp_flags & IEEE80211_BPF_CTS) in wpi_tx_data_raw()
2986 if (params->ibp_flags & IEEE80211_BPF_CRYPTO) { in wpi_tx_data_raw()
2992 swcrypt = k->wk_flags & IEEE80211_KEY_SWCRYPT; in wpi_tx_data_raw()
2997 totlen = m->m_pkthdr.len; in wpi_tx_data_raw()
3000 struct wpi_tx_radiotap_header *tap = &sc->sc_txtap; in wpi_tx_data_raw()
3002 tap->wt_flags = 0; in wpi_tx_data_raw()
3003 tap->wt_rate = rate; in wpi_tx_data_raw()
3004 if (params->ibp_flags & IEEE80211_BPF_CRYPTO) in wpi_tx_data_raw()
3005 tap->wt_flags |= IEEE80211_RADIOTAP_F_WEP; in wpi_tx_data_raw()
3012 uint8_t subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK; in wpi_tx_data_raw()
3019 tx->timeout = htole16(3); in wpi_tx_data_raw()
3021 tx->timeout = htole16(2); in wpi_tx_data_raw()
3025 switch (k->wk_cipher->ic_cipher) { in wpi_tx_data_raw()
3027 tx->security = WPI_CIPHER_CCMP; in wpi_tx_data_raw()
3034 memcpy(tx->key, k->wk_key, k->wk_keylen); in wpi_tx_data_raw()
3037 tx->len = htole16(totlen); in wpi_tx_data_raw()
3038 tx->flags = htole32(flags); in wpi_tx_data_raw()
3039 tx->plcp = rate2plcp(rate); in wpi_tx_data_raw()
3040 tx->id = WPI_ID_BROADCAST; in wpi_tx_data_raw()
3041 tx->lifetime = htole32(WPI_LIFETIME_INFINITE); in wpi_tx_data_raw()
3042 tx->rts_ntries = params->ibp_try1; in wpi_tx_data_raw()
3043 tx->data_ntries = params->ibp_try0; in wpi_tx_data_raw()
3057 struct wpi_tx_ring *ring = &sc->txq[ac]; in wpi_tx_ring_free_space()
3061 retval = WPI_TX_RING_HIMARK - ring->queued; in wpi_tx_ring_free_space()
3071 struct ieee80211com *ic = ni->ni_ic; in wpi_raw_xmit()
3072 struct wpi_softc *sc = ic->ic_softc; in wpi_raw_xmit()
3083 if (sc->sc_running == 0 || wpi_tx_ring_free_space(sc, ac) < 1) { in wpi_raw_xmit()
3084 error = sc->sc_running ? ENOBUFS : ENETDOWN; in wpi_raw_xmit()
3119 struct wpi_softc *sc = ic->ic_softc; in wpi_transmit()
3129 if (__predict_false(sc->sc_running == 0)) { in wpi_transmit()
3135 for (mnext = m->m_nextpkt; mnext != NULL; mnext = mnext->m_nextpkt) in wpi_transmit()
3146 ni = (struct ieee80211_node *)m->m_pkthdr.rcvif; in wpi_transmit()
3148 mnext = m->m_nextpkt; in wpi_transmit()
3150 if_inc_counter(ni->ni_vap->iv_ifp, IFCOUNTER_OERRORS, in wpi_transmit()
3170 struct ieee80211com *ic = &sc->sc_ic; in wpi_watchdog_rfkill()
3177 callout_reset(&sc->watchdog_rfkill, hz, wpi_watchdog_rfkill, in wpi_watchdog_rfkill()
3180 ieee80211_runtask(ic, &sc->sc_radioon_task); in wpi_watchdog_rfkill()
3187 struct ieee80211com *ic = &sc->sc_ic; in wpi_scan_timeout()
3197 struct ieee80211com *ic = &sc->sc_ic; in wpi_tx_timeout()
3206 struct wpi_softc *sc = ic->ic_softc; in wpi_parent()
3207 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); in wpi_parent()
3209 if (ic->ic_nrunning > 0) { in wpi_parent()
3230 struct wpi_tx_ring *ring = &sc->txq[WPI_CMD_QUEUE_NUM]; in wpi_cmd()
3243 if (__predict_false(sc->sc_running == 0)) { in wpi_cmd()
3259 desc = &ring->desc[ring->cur]; in wpi_cmd()
3260 data = &ring->data[ring->cur]; in wpi_cmd()
3263 if (size > sizeof cmd->data) { in wpi_cmd()
3275 error = bus_dmamap_load(ring->data_dmat, data->map, cmd, in wpi_cmd()
3281 data->m = m; in wpi_cmd()
3283 cmd = &ring->cmd[ring->cur]; in wpi_cmd()
3284 paddr = data->cmd_paddr; in wpi_cmd()
3287 cmd->code = code; in wpi_cmd()
3288 cmd->flags = 0; in wpi_cmd()
3289 cmd->qid = ring->qid; in wpi_cmd()
3290 cmd->idx = ring->cur; in wpi_cmd()
3291 memcpy(cmd->data, buf, size); in wpi_cmd()
3293 desc->nsegs = 1 + (WPI_PAD32(size) << 4); in wpi_cmd()
3294 desc->segs[0].addr = htole32(paddr); in wpi_cmd()
3295 desc->segs[0].len = htole32(totlen); in wpi_cmd()
3297 if (size > sizeof cmd->data) { in wpi_cmd()
3298 bus_dmamap_sync(ring->data_dmat, data->map, in wpi_cmd()
3301 bus_dmamap_sync(ring->data_dmat, ring->cmd_dma.map, in wpi_cmd()
3304 bus_dmamap_sync(ring->desc_dma.tag, ring->desc_dma.map, in wpi_cmd()
3308 ring->cur = (ring->cur + 1) % WPI_TX_RING_COUNT; in wpi_cmd()
3309 sc->sc_update_tx_ring(sc, ring); in wpi_cmd()
3315 return async ? 0 : mtx_sleep(cmd, &sc->sc_mtx, PCATCH, "wpicmd", hz); in wpi_cmd()
3325 * Configure HW multi-rate retries.
3330 struct ieee80211com *ic = &sc->sc_ic; in wpi_mrr_setup()
3341 (i == WPI_RIDX_CCK1) ? WPI_RIDX_CCK1 : i - 1; in wpi_mrr_setup()
3352 ((ic->ic_curmode == IEEE80211_MODE_11A) ? in wpi_mrr_setup()
3354 i - 1; in wpi_mrr_setup()
3362 device_printf(sc->sc_dev, in wpi_mrr_setup()
3370 device_printf(sc->sc_dev, in wpi_mrr_setup()
3380 struct ieee80211com *ic = ni->ni_ic; in wpi_add_node()
3381 struct wpi_vap *wvp = WPI_VAP(ni->ni_vap); in wpi_add_node()
3388 if (wn->id == WPI_ID_UNDEFINED) in wpi_add_node()
3392 IEEE80211_ADDR_COPY(node.macaddr, ni->ni_macaddr); in wpi_add_node()
3393 node.id = wn->id; in wpi_add_node()
3394 node.plcp = (ic->ic_curmode == IEEE80211_MODE_11A) ? in wpi_add_node()
3400 wn->id, ether_sprintf(ni->ni_macaddr)); in wpi_add_node()
3404 device_printf(sc->sc_dev, in wpi_add_node()
3410 if (wvp->wv_gtk != 0) { in wpi_add_node()
3413 device_printf(sc->sc_dev, in wpi_add_node()
3423 * Broadcast node is used to send group-addressed and management frames.
3428 struct ieee80211com *ic = &sc->sc_ic; in wpi_add_broadcast_node()
3436 node.plcp = (ic->ic_curmode == IEEE80211_MODE_11A) ? in wpi_add_broadcast_node()
3454 wn->id = wpi_add_node_entry_sta(sc); in wpi_add_sta_node()
3457 wpi_del_node_entry(sc, wn->id); in wpi_add_sta_node()
3458 wn->id = WPI_ID_UNDEFINED; in wpi_add_sta_node()
3471 KASSERT(wn->id == WPI_ID_UNDEFINED, in wpi_add_ibss_node()
3472 ("the node %d was added before", wn->id)); in wpi_add_ibss_node()
3476 if ((wn->id = wpi_add_node_entry_adhoc(sc)) == WPI_ID_UNDEFINED) { in wpi_add_ibss_node()
3477 device_printf(sc->sc_dev, "%s: h/w table is full\n", __func__); in wpi_add_ibss_node()
3482 wpi_del_node_entry(sc, wn->id); in wpi_add_ibss_node()
3483 wn->id = WPI_ID_UNDEFINED; in wpi_add_ibss_node()
3497 KASSERT(wn->id != WPI_ID_UNDEFINED, ("undefined node id passed")); in wpi_del_node()
3502 IEEE80211_ADDR_COPY(node.macaddr, ni->ni_macaddr); in wpi_del_node()
3506 wn->id, ether_sprintf(ni->ni_macaddr)); in wpi_del_node()
3510 device_printf(sc->sc_dev, in wpi_del_node()
3512 wn->id, error); in wpi_del_node()
3519 #define WPI_EXP2(x) ((1 << (x)) - 1) /* CWmin = 2^ECWmin - 1 */ in wpi_updateedca()
3520 struct wpi_softc *sc = ic->ic_softc; in wpi_updateedca()
3533 cmd.ac[aci].aifsn = ac->wmep_aifsn; in wpi_updateedca()
3534 cmd.ac[aci].cwmin = htole16(WPI_EXP2(ac->wmep_logcwmin)); in wpi_updateedca()
3535 cmd.ac[aci].cwmax = htole16(WPI_EXP2(ac->wmep_logcwmax)); in wpi_updateedca()
3537 htole16(IEEE80211_TXOP_TO_US(ac->wmep_txopLimit)); in wpi_updateedca()
3556 struct ieee80211com *ic = &sc->sc_ic; in wpi_set_promisc()
3557 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); in wpi_set_promisc()
3561 if (vap != NULL && vap->iv_opmode != IEEE80211_M_HOSTAP) in wpi_set_promisc()
3564 if (ic->ic_promisc > 0) in wpi_set_promisc()
3565 sc->rxon.filter |= htole32(promisc_filter); in wpi_set_promisc()
3567 sc->rxon.filter &= ~htole32(promisc_filter); in wpi_set_promisc()
3573 struct wpi_softc *sc = ic->ic_softc; in wpi_update_promisc()
3576 if (sc->sc_running == 0) { in wpi_update_promisc()
3586 device_printf(sc->sc_dev, "%s: could not send RXON\n", in wpi_update_promisc()
3621 memcpy(&cmd.tstamp, ni->ni_tstamp.data, sizeof (uint64_t)); in wpi_set_timing()
3622 cmd.bintval = htole16(ni->ni_intval); in wpi_set_timing()
3626 val = (uint64_t)ni->ni_intval * IEEE80211_DUR_TU; in wpi_set_timing()
3628 cmd.binitval = htole32((uint32_t)(val - mod)); in wpi_set_timing()
3631 ni->ni_intval, le64toh(cmd.tstamp), (uint32_t)(val - mod)); in wpi_set_timing()
3651 /* Sanity-check read value. */ in wpi_power_calibration()
3652 if (temp < -260 || temp > 25) { in wpi_power_calibration()
3655 "out-of-range temperature reported: %d\n", temp); in wpi_power_calibration()
3659 DPRINTF(sc, WPI_DEBUG_TEMP, "temperature %d->%d\n", sc->temp, temp); in wpi_power_calibration()
3662 if (abs(temp - sc->temp) <= 6) in wpi_power_calibration()
3665 sc->temp = temp; in wpi_power_calibration()
3669 device_printf(sc->sc_dev,"could not adjust Tx power\n"); in wpi_power_calibration()
3685 chan = sc->rxon.chan; in wpi_set_txpower()
3686 is_chan_5ghz = (sc->rxon.flags & htole32(WPI_RXON_24GHZ)) == 0; in wpi_set_txpower()
3690 for (group = &sc->groups[1]; group < &sc->groups[4]; group++) in wpi_set_txpower()
3691 if (chan <= group->chan) in wpi_set_txpower()
3694 group = &sc->groups[0]; in wpi_set_txpower()
3730 /* Fixed-point arithmetic division using a n-bit fractional part. */ in wpi_get_power_index()
3736 ((y1) + fdivround(((x) - (x1)) * ((y2) - (y1)), (x2) - (x1), n)) in wpi_get_power_index()
3742 pwr = group->maxpwr / 2; in wpi_get_power_index()
3747 pwr -= is_chan_5ghz ? 5 : 0; in wpi_get_power_index()
3750 pwr -= is_chan_5ghz ? 10 : 7; in wpi_get_power_index()
3753 pwr -= is_chan_5ghz ? 12 : 9; in wpi_get_power_index()
3758 pwr = min(pwr, sc->maxpwr[chan]); in wpi_get_power_index()
3761 for (sample = group->samples; sample < &group->samples[3]; sample++) in wpi_get_power_index()
3764 /* Fixed-point linear interpolation using a 19-bit fractional part. */ in wpi_get_power_index()
3768 /*- in wpi_get_power_index()
3770 * - if cooler than factory-calibrated: decrease output power in wpi_get_power_index()
3771 * - if warmer than factory-calibrated: increase output power in wpi_get_power_index()
3773 idx -= (sc->temp - group->temp) * 11 / 100; in wpi_get_power_index()
3775 /* Decrease TX power for CCK rates (-5dB). */ in wpi_get_power_index()
3817 reg = pci_read_config(sc->sc_dev, sc->sc_cap_off + PCIER_LINK_CTL, 1); in wpi_set_pslevel()
3821 cmd.rxtimeout = htole32(pmgt->rxtimeout * IEEE80211_DUR_TU); in wpi_set_pslevel()
3822 cmd.txtimeout = htole32(pmgt->txtimeout * IEEE80211_DUR_TU); in wpi_set_pslevel()
3828 skip_dtim = pmgt->skip_dtim; in wpi_set_pslevel()
3832 max = pmgt->intval[4]; in wpi_set_pslevel()
3833 if (max == (uint32_t)-1) in wpi_set_pslevel()
3841 cmd.intval[i] = htole32(MIN(max, pmgt->intval[i])); in wpi_set_pslevel()
3871 rxon_assoc.flags = sc->rxon.flags; in wpi_send_rxon()
3872 rxon_assoc.filter = sc->rxon.filter; in wpi_send_rxon()
3873 rxon_assoc.ofdm_mask = sc->rxon.ofdm_mask; in wpi_send_rxon()
3874 rxon_assoc.cck_mask = sc->rxon.cck_mask; in wpi_send_rxon()
3880 device_printf(sc->sc_dev, in wpi_send_rxon()
3887 error = wpi_cmd(sc, WPI_CMD_RXON, &sc->rxon, in wpi_send_rxon()
3893 error = wpi_cmd(sc, WPI_CMD_RXON, &sc->rxon, in wpi_send_rxon()
3900 device_printf(sc->sc_dev, in wpi_send_rxon()
3908 device_printf(sc->sc_dev, in wpi_send_rxon()
3916 device_printf(sc->sc_dev, in wpi_send_rxon()
3931 struct ieee80211com *ic = &sc->sc_ic; in wpi_config()
3932 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); in wpi_config()
3933 struct ieee80211_channel *c = ic->ic_curchan; in wpi_config()
3940 device_printf(sc->sc_dev, in wpi_config()
3947 device_printf(sc->sc_dev, in wpi_config()
3953 memset(&sc->rxon, 0, sizeof (struct wpi_rxon)); in wpi_config()
3954 IEEE80211_ADDR_COPY(sc->rxon.myaddr, vap->iv_myaddr); in wpi_config()
3957 sc->rxon.chan = ieee80211_chan2ieee(ic, c); in wpi_config()
3958 sc->rxon.flags = htole32(WPI_RXON_TSF | WPI_RXON_CTS_TO_SELF); in wpi_config()
3960 sc->rxon.flags |= htole32(WPI_RXON_AUTO | WPI_RXON_24GHZ); in wpi_config()
3962 sc->rxon.filter = WPI_FILTER_MULTICAST; in wpi_config()
3963 switch (ic->ic_opmode) { in wpi_config()
3965 sc->rxon.mode = WPI_MODE_STA; in wpi_config()
3968 sc->rxon.mode = WPI_MODE_IBSS; in wpi_config()
3969 sc->rxon.filter |= WPI_FILTER_BEACON; in wpi_config()
3973 sc->rxon.mode = WPI_MODE_IBSS; in wpi_config()
3974 sc->rxon.filter |= WPI_FILTER_ASSOC | WPI_FILTER_PROMISC; in wpi_config()
3977 sc->rxon.mode = WPI_MODE_HOSTAP; in wpi_config()
3980 sc->rxon.mode = WPI_MODE_MONITOR; in wpi_config()
3983 device_printf(sc->sc_dev, "unknown opmode %d\n", in wpi_config()
3984 ic->ic_opmode); in wpi_config()
3987 sc->rxon.filter = htole32(sc->rxon.filter); in wpi_config()
3989 sc->rxon.cck_mask = 0x0f; /* not yet negotiated */ in wpi_config()
3990 sc->rxon.ofdm_mask = 0xff; /* not yet negotiated */ in wpi_config()
3993 device_printf(sc->sc_dev, "%s: could not send RXON\n", in wpi_config()
4000 device_printf(sc->sc_dev, "could not setup MRR, error %d\n", in wpi_config()
4033 struct ieee80211com *ic = &sc->sc_ic; in wpi_limit_dwell()
4034 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); in wpi_limit_dwell()
4039 bintval = vap->iv_bss->ni_intval; in wpi_limit_dwell()
4042 * If it's non-zero, we should calculate the minimum of in wpi_limit_dwell()
4051 return (MIN(dwell_time, bintval - WPI_CHANNEL_TUNE_TIME * 2)); in wpi_limit_dwell()
4090 struct ieee80211com *ic = &sc->sc_ic; in wpi_scan()
4091 struct ieee80211_scan_state *ss = ic->ic_scan; in wpi_scan()
4092 struct ieee80211vap *vap = ss->ss_vap; in wpi_scan()
4109 if (callout_pending(&sc->scan_timeout)) { in wpi_scan()
4110 device_printf(sc->sc_dev, "%s: called whilst scanning!\n", in wpi_scan()
4117 bintval = vap->iv_bss->ni_intval; in wpi_scan()
4126 device_printf(sc->sc_dev, in wpi_scan()
4138 hdr->quiet_time = htole16(WPI_QUIET_TIME_DEFAULT); in wpi_scan()
4139 hdr->quiet_threshold = htole16(1); in wpi_scan()
4146 hdr->max_svc = htole32(250 * IEEE80211_DUR_TU); in wpi_scan()
4147 hdr->pause_svc = htole32(wpi_get_scan_pause_time(100, in wpi_scan()
4151 hdr->filter = htole32(WPI_FILTER_MULTICAST | WPI_FILTER_BEACON); in wpi_scan()
4154 tx->flags = htole32(WPI_TX_AUTO_SEQ); in wpi_scan()
4155 tx->id = WPI_ID_BROADCAST; in wpi_scan()
4156 tx->lifetime = htole32(WPI_LIFETIME_INFINITE); in wpi_scan()
4160 tx->plcp = wpi_ridx_to_plcp[WPI_RIDX_OFDM6]; in wpi_scan()
4161 rs = &ic->ic_sup_rates[IEEE80211_MODE_11A]; in wpi_scan()
4163 hdr->flags = htole32(WPI_RXON_24GHZ | WPI_RXON_AUTO); in wpi_scan()
4165 tx->plcp = wpi_ridx_to_plcp[WPI_RIDX_CCK1]; in wpi_scan()
4166 rs = &ic->ic_sup_rates[IEEE80211_MODE_11G]; in wpi_scan()
4170 nssid = MIN(ss->ss_nssid, WPI_SCAN_MAX_ESSIDS); in wpi_scan()
4173 essids[i].len = MIN(ss->ss_ssid[i].len, IEEE80211_NWID_LEN); in wpi_scan()
4174 memcpy(essids[i].data, ss->ss_ssid[i].ssid, essids[i].len); in wpi_scan()
4176 if (sc->sc_debug & WPI_DEBUG_SCAN) { in wpi_scan()
4189 wh->i_fc[0] = IEEE80211_FC0_VERSION_0 | IEEE80211_FC0_TYPE_MGT | in wpi_scan()
4191 wh->i_fc[1] = IEEE80211_FC1_DIR_NODS; in wpi_scan()
4192 IEEE80211_ADDR_COPY(wh->i_addr1, ieee80211broadcastaddr); in wpi_scan()
4193 IEEE80211_ADDR_COPY(wh->i_addr2, vap->iv_myaddr); in wpi_scan()
4194 IEEE80211_ADDR_COPY(wh->i_addr3, ieee80211broadcastaddr); in wpi_scan()
4199 if (rs->rs_nrates > IEEE80211_RATE_SIZE) in wpi_scan()
4203 tx->len = htole16(frm - (uint8_t *)wh); in wpi_scan()
4211 chan->chan = ieee80211_chan2ieee(ic, c); in wpi_scan()
4212 chan->flags = 0; in wpi_scan()
4214 hdr->crc_threshold = WPI_SCAN_CRC_TH_DEFAULT; in wpi_scan()
4215 chan->flags |= WPI_CHAN_NPBREQS(nssid); in wpi_scan()
4217 hdr->crc_threshold = WPI_SCAN_CRC_TH_NEVER; in wpi_scan()
4220 chan->flags |= WPI_CHAN_ACTIVE; in wpi_scan()
4232 chan->active = htole16(dwell_active); in wpi_scan()
4233 chan->passive = htole16(dwell_passive); in wpi_scan()
4235 chan->dsp_gain = 0x6e; /* Default level */ in wpi_scan()
4238 chan->rf_gain = 0x3b; in wpi_scan()
4240 chan->rf_gain = 0x28; in wpi_scan()
4243 chan->chan, IEEE80211_IS_CHAN_PASSIVE(c)); in wpi_scan()
4245 hdr->nchan++; in wpi_scan()
4247 if (hdr->nchan == 1 && sc->rxon.chan == chan->chan) { in wpi_scan()
4254 chan->flags = 0; in wpi_scan()
4255 chan->passive = chan->active = hdr->quiet_time; in wpi_scan()
4257 hdr->nchan++; in wpi_scan()
4262 buflen = (uint8_t *)chan - buf; in wpi_scan()
4263 hdr->len = htole16(buflen); in wpi_scan()
4266 hdr->nchan); in wpi_scan()
4273 callout_reset(&sc->scan_timeout, 5*hz, wpi_scan_timeout, sc); in wpi_scan()
4287 struct ieee80211com *ic = vap->iv_ic; in wpi_auth()
4288 struct ieee80211_node *ni = vap->iv_bss; in wpi_auth()
4289 struct ieee80211_channel *c = ni->ni_chan; in wpi_auth()
4297 sc->rxon.associd = 0; in wpi_auth()
4298 sc->rxon.filter &= ~htole32(WPI_FILTER_BSS); in wpi_auth()
4299 IEEE80211_ADDR_COPY(sc->rxon.bssid, ni->ni_bssid); in wpi_auth()
4300 sc->rxon.chan = ieee80211_chan2ieee(ic, c); in wpi_auth()
4301 sc->rxon.flags = htole32(WPI_RXON_TSF | WPI_RXON_CTS_TO_SELF); in wpi_auth()
4303 sc->rxon.flags |= htole32(WPI_RXON_AUTO | WPI_RXON_24GHZ); in wpi_auth()
4304 if (ic->ic_flags & IEEE80211_F_SHSLOT) in wpi_auth()
4305 sc->rxon.flags |= htole32(WPI_RXON_SHSLOT); in wpi_auth()
4306 if (ic->ic_flags & IEEE80211_F_SHPREAMBLE) in wpi_auth()
4307 sc->rxon.flags |= htole32(WPI_RXON_SHPREAMBLE); in wpi_auth()
4309 sc->rxon.cck_mask = 0; in wpi_auth()
4310 sc->rxon.ofdm_mask = 0x15; in wpi_auth()
4312 sc->rxon.cck_mask = 0x03; in wpi_auth()
4313 sc->rxon.ofdm_mask = 0; in wpi_auth()
4316 sc->rxon.cck_mask = 0x0f; in wpi_auth()
4317 sc->rxon.ofdm_mask = 0x15; in wpi_auth()
4321 sc->rxon.chan, sc->rxon.flags, sc->rxon.cck_mask, in wpi_auth()
4322 sc->rxon.ofdm_mask); in wpi_auth()
4325 device_printf(sc->sc_dev, "%s: could not send RXON\n", in wpi_auth()
4339 struct ieee80211vap *vap = &wvp->wv_vap; in wpi_config_beacon()
4340 struct ieee80211com *ic = vap->iv_ic; in wpi_config_beacon()
4341 struct ieee80211_beacon_offsets *bo = &vap->iv_bcn_off; in wpi_config_beacon()
4342 struct wpi_buf *bcn = &wvp->wv_bcbuf; in wpi_config_beacon()
4343 struct wpi_softc *sc = ic->ic_softc; in wpi_config_beacon()
4344 struct wpi_cmd_beacon *cmd = (struct wpi_cmd_beacon *)&bcn->data; in wpi_config_beacon()
4354 cmd->len = htole16(bcn->m->m_pkthdr.len); in wpi_config_beacon()
4355 cmd->plcp = (ic->ic_curmode == IEEE80211_MODE_11A) ? in wpi_config_beacon()
4359 if (*(bo->bo_tim) == IEEE80211_ELEMID_TIM) { in wpi_config_beacon()
4360 tie = (struct ieee80211_tim_ie *) bo->bo_tim; in wpi_config_beacon()
4361 ptr = mtod(bcn->m, uint8_t *); in wpi_config_beacon()
4363 cmd->tim = htole16(bo->bo_tim - ptr); in wpi_config_beacon()
4364 cmd->timsz = tie->tim_len; in wpi_config_beacon()
4368 m = bcn->m; in wpi_config_beacon()
4369 bcn->m = m_dup(m, M_NOWAIT); in wpi_config_beacon()
4370 if (bcn->m == NULL) { in wpi_config_beacon()
4371 device_printf(sc->sc_dev, in wpi_config_beacon()
4378 device_printf(sc->sc_dev, in wpi_config_beacon()
4381 m_freem(bcn->m); in wpi_config_beacon()
4385 end: bcn->m = m; in wpi_config_beacon()
4393 struct ieee80211vap *vap = ni->ni_vap; in wpi_setup_beacon()
4395 struct wpi_buf *bcn = &wvp->wv_bcbuf; in wpi_setup_beacon()
4401 if (ni->ni_chan == IEEE80211_CHAN_ANYC) in wpi_setup_beacon()
4406 device_printf(sc->sc_dev, in wpi_setup_beacon()
4412 if (bcn->m != NULL) in wpi_setup_beacon()
4413 m_freem(bcn->m); in wpi_setup_beacon()
4415 bcn->m = m; in wpi_setup_beacon()
4426 struct wpi_softc *sc = vap->iv_ic->ic_softc; in wpi_update_beacon()
4428 struct wpi_buf *bcn = &wvp->wv_bcbuf; in wpi_update_beacon()
4429 struct ieee80211_beacon_offsets *bo = &vap->iv_bcn_off; in wpi_update_beacon()
4430 struct ieee80211_node *ni = vap->iv_bss; in wpi_update_beacon()
4436 if (bcn->m == NULL) { in wpi_update_beacon()
4437 bcn->m = ieee80211_beacon_alloc(ni); in wpi_update_beacon()
4438 if (bcn->m == NULL) { in wpi_update_beacon()
4439 device_printf(sc->sc_dev, in wpi_update_beacon()
4454 setbit(bo->bo_flags, item); in wpi_update_beacon()
4455 ieee80211_beacon_update(ni, bcn->m, mcast); in wpi_update_beacon()
4467 struct ieee80211vap *vap = ni->ni_vap; in wpi_newassoc()
4468 struct wpi_softc *sc = ni->ni_ic->ic_softc; in wpi_newassoc()
4476 if (vap->iv_opmode != IEEE80211_M_STA && wn->id == WPI_ID_UNDEFINED) { in wpi_newassoc()
4478 device_printf(sc->sc_dev, in wpi_newassoc()
4489 struct ieee80211com *ic = vap->iv_ic; in wpi_run()
4490 struct ieee80211_node *ni = vap->iv_bss; in wpi_run()
4491 struct ieee80211_channel *c = ni->ni_chan; in wpi_run()
4496 if (vap->iv_opmode == IEEE80211_M_MONITOR) { in wpi_run()
4504 device_printf(sc->sc_dev, "%s: incomplete configuration\n", in wpi_run()
4510 device_printf(sc->sc_dev, in wpi_run()
4517 IEEE80211_ADDR_COPY(sc->rxon.bssid, ni->ni_bssid); in wpi_run()
4518 sc->rxon.associd = htole16(IEEE80211_NODE_AID(ni)); in wpi_run()
4519 sc->rxon.chan = ieee80211_chan2ieee(ic, c); in wpi_run()
4520 sc->rxon.flags = htole32(WPI_RXON_TSF | WPI_RXON_CTS_TO_SELF); in wpi_run()
4522 sc->rxon.flags |= htole32(WPI_RXON_AUTO | WPI_RXON_24GHZ); in wpi_run()
4523 if (ic->ic_flags & IEEE80211_F_SHSLOT) in wpi_run()
4524 sc->rxon.flags |= htole32(WPI_RXON_SHSLOT); in wpi_run()
4525 if (ic->ic_flags & IEEE80211_F_SHPREAMBLE) in wpi_run()
4526 sc->rxon.flags |= htole32(WPI_RXON_SHPREAMBLE); in wpi_run()
4528 sc->rxon.cck_mask = 0; in wpi_run()
4529 sc->rxon.ofdm_mask = 0x15; in wpi_run()
4531 sc->rxon.cck_mask = 0x03; in wpi_run()
4532 sc->rxon.ofdm_mask = 0; in wpi_run()
4535 sc->rxon.cck_mask = 0x0f; in wpi_run()
4536 sc->rxon.ofdm_mask = 0x15; in wpi_run()
4538 sc->rxon.filter |= htole32(WPI_FILTER_BSS); in wpi_run()
4541 sc->rxon.chan, sc->rxon.flags); in wpi_run()
4545 device_printf(sc->sc_dev, "%s: could not send RXON\n", in wpi_run()
4551 callout_reset(&sc->calib_to, 60*hz, wpi_calib_timeout, sc); in wpi_run()
4555 if (vap->iv_opmode == IEEE80211_M_IBSS || in wpi_run()
4556 vap->iv_opmode == IEEE80211_M_HOSTAP) { in wpi_run()
4558 device_printf(sc->sc_dev, in wpi_run()
4565 if (vap->iv_opmode == IEEE80211_M_STA) { in wpi_run()
4571 device_printf(sc->sc_dev, in wpi_run()
4581 /* Enable power-saving mode if requested by user. */ in wpi_run()
4582 if ((vap->iv_flags & IEEE80211_F_PMGTON) && in wpi_run()
4583 vap->iv_opmode != IEEE80211_M_IBSS) in wpi_run()
4594 const struct ieee80211_cipher *cip = k->wk_cipher; in wpi_load_key()
4595 struct ieee80211vap *vap = ni->ni_vap; in wpi_load_key()
4596 struct wpi_softc *sc = ni->ni_ic->ic_softc; in wpi_load_key()
4604 if (wpi_check_node_entry(sc, wn->id) == 0) { in wpi_load_key()
4605 device_printf(sc->sc_dev, "%s: node does not exist\n", in wpi_load_key()
4610 switch (cip->ic_cipher) { in wpi_load_key()
4616 device_printf(sc->sc_dev, "%s: unknown cipher %d\n", __func__, in wpi_load_key()
4617 cip->ic_cipher); in wpi_load_key()
4621 kflags |= WPI_KFLAG_KID(k->wk_keyix); in wpi_load_key()
4622 if (k->wk_flags & IEEE80211_KEY_GROUP) in wpi_load_key()
4626 node.id = wn->id; in wpi_load_key()
4630 memcpy(node.key, k->wk_key, k->wk_keylen); in wpi_load_key()
4634 (kflags & WPI_KFLAG_MULTICAST) ? "group" : "ucast", k->wk_keyix, in wpi_load_key()
4635 node.id, ether_sprintf(ni->ni_macaddr)); in wpi_load_key()
4639 device_printf(sc->sc_dev, "can't update node info, error %d\n", in wpi_load_key()
4659 struct ieee80211vap *vap = ni->ni_vap; in wpi_load_key_cb()
4660 struct wpi_softc *sc = ni->ni_ic->ic_softc; in wpi_load_key_cb()
4664 if (vap->iv_bss == ni && wn->id == WPI_ID_UNDEFINED) in wpi_load_key_cb()
4672 device_printf(sc->sc_dev, "%s: error while setting key\n", in wpi_load_key_cb()
4680 struct ieee80211vap *vap = ni->ni_vap; in wpi_set_global_keys()
4681 struct ieee80211_key *wk = &vap->iv_nw_keys[0]; in wpi_set_global_keys()
4684 for (; wk < &vap->iv_nw_keys[IEEE80211_WEP_NKID] && error; wk++) in wpi_set_global_keys()
4685 if (wk->wk_keyix != IEEE80211_KEYIX_NONE) in wpi_set_global_keys()
4694 struct ieee80211vap *vap = ni->ni_vap; in wpi_del_key()
4695 struct wpi_softc *sc = ni->ni_ic->ic_softc; in wpi_del_key()
4703 if (wpi_check_node_entry(sc, wn->id) == 0) { in wpi_del_key()
4708 kflags = WPI_KFLAG_KID(k->wk_keyix); in wpi_del_key()
4709 if (k->wk_flags & IEEE80211_KEY_GROUP) in wpi_del_key()
4713 node.id = wn->id; in wpi_del_key()
4720 k->wk_keyix, node.id, ether_sprintf(ni->ni_macaddr)); in wpi_del_key()
4724 device_printf(sc->sc_dev, "can't update node info, error %d\n", in wpi_del_key()
4744 struct ieee80211vap *vap = ni->ni_vap; in wpi_del_key_cb()
4745 struct wpi_softc *sc = ni->ni_ic->ic_softc; in wpi_del_key_cb()
4749 if (vap->iv_bss == ni && wn->id == WPI_ID_UNDEFINED) in wpi_del_key_cb()
4757 device_printf(sc->sc_dev, "%s: error while deleting key\n", in wpi_del_key_cb()
4766 struct ieee80211com *ic = vap->iv_ic; in wpi_process_key()
4767 struct wpi_softc *sc = ic->ic_softc; in wpi_process_key()
4774 if (k->wk_flags & IEEE80211_KEY_SWCRYPT) { in wpi_process_key()
4779 if (!(k->wk_flags & IEEE80211_KEY_RECV)) { in wpi_process_key()
4788 wvp->wv_gtk |= WPI_VAP_KEY(k->wk_keyix); in wpi_process_key()
4790 wvp->wv_gtk &= ~WPI_VAP_KEY(k->wk_keyix); in wpi_process_key()
4793 if (vap->iv_state == IEEE80211_S_RUN) { in wpi_process_key()
4794 ieee80211_iterate_nodes(&ic->ic_sta, in wpi_process_key()
4802 switch (vap->iv_opmode) { in wpi_process_key()
4804 ni = vap->iv_bss; in wpi_process_key()
4810 ni = ieee80211_find_vap_node(&ic->ic_sta, vap, k->wk_macaddr); in wpi_process_key()
4818 device_printf(sc->sc_dev, "%s: unknown opmode %d\n", __func__, in wpi_process_key()
4819 vap->iv_opmode); in wpi_process_key()
4865 device_printf(sc->sc_dev, in wpi_post_alive()
4868 return EPERM; /* :-) */ in wpi_post_alive()
4874 if ((sc->temp = (int)WPI_READ(sc, WPI_UCODE_GP2)) != 0) in wpi_post_alive()
4880 device_printf(sc->sc_dev, in wpi_post_alive()
4885 DPRINTF(sc, WPI_DEBUG_TEMP, "temperature %d\n", sc->temp); in wpi_post_alive()
4891 * the NIC internal memory (no DMA transfer).
4925 "Status Match! - ntries = %d\n", ntries); in wpi_load_bootcode()
4931 device_printf(sc->sc_dev, "%s: could not load boot firmware\n", in wpi_load_bootcode()
4947 struct wpi_fw_info *fw = &sc->fw; in wpi_load_firmware()
4948 struct wpi_dma_info *dma = &sc->fw_dma; in wpi_load_firmware() local
4953 /* Copy initialization sections into pre-allocated DMA-safe memory. */ in wpi_load_firmware()
4954 memcpy(dma->vaddr, fw->init.data, fw->init.datasz); in wpi_load_firmware()
4955 bus_dmamap_sync(dma->tag, dma->map, BUS_DMASYNC_PREWRITE); in wpi_load_firmware()
4956 memcpy(dma->vaddr + WPI_FW_DATA_MAXSZ, fw->init.text, fw->init.textsz); in wpi_load_firmware()
4957 bus_dmamap_sync(dma->tag, dma->map, BUS_DMASYNC_PREWRITE); in wpi_load_firmware()
4962 wpi_prph_write(sc, WPI_BSM_DRAM_DATA_ADDR, dma->paddr); in wpi_load_firmware()
4963 wpi_prph_write(sc, WPI_BSM_DRAM_DATA_SIZE, fw->init.datasz); in wpi_load_firmware()
4965 dma->paddr + WPI_FW_DATA_MAXSZ); in wpi_load_firmware()
4966 wpi_prph_write(sc, WPI_BSM_DRAM_TEXT_SIZE, fw->init.textsz); in wpi_load_firmware()
4970 error = wpi_load_bootcode(sc, fw->boot.text, fw->boot.textsz); in wpi_load_firmware()
4972 device_printf(sc->sc_dev, "%s: could not load boot firmware\n", in wpi_load_firmware()
4981 if ((error = mtx_sleep(sc, &sc->sc_mtx, PCATCH, "wpiinit", hz)) != 0) { in wpi_load_firmware()
4982 device_printf(sc->sc_dev, in wpi_load_firmware()
4988 /* Copy runtime sections into pre-allocated DMA-safe memory. */ in wpi_load_firmware()
4989 memcpy(dma->vaddr, fw->main.data, fw->main.datasz); in wpi_load_firmware()
4990 bus_dmamap_sync(dma->tag, dma->map, BUS_DMASYNC_PREWRITE); in wpi_load_firmware()
4991 memcpy(dma->vaddr + WPI_FW_DATA_MAXSZ, fw->main.text, fw->main.textsz); in wpi_load_firmware()
4992 bus_dmamap_sync(dma->tag, dma->map, BUS_DMASYNC_PREWRITE); in wpi_load_firmware()
4997 wpi_prph_write(sc, WPI_BSM_DRAM_DATA_ADDR, dma->paddr); in wpi_load_firmware()
4998 wpi_prph_write(sc, WPI_BSM_DRAM_DATA_SIZE, fw->main.datasz); in wpi_load_firmware()
5000 dma->paddr + WPI_FW_DATA_MAXSZ); in wpi_load_firmware()
5002 WPI_FW_UPDATED | fw->main.textsz); in wpi_load_firmware()
5012 struct wpi_fw_info *fw = &sc->fw; in wpi_read_firmware()
5026 device_printf(sc->sc_dev, in wpi_read_firmware()
5031 sc->fw_fp = fp; in wpi_read_firmware()
5033 if (fp->datasize < sizeof (struct wpi_firmware_hdr)) { in wpi_read_firmware()
5034 device_printf(sc->sc_dev, in wpi_read_firmware()
5035 "firmware file too short: %zu bytes\n", fp->datasize); in wpi_read_firmware()
5040 fw->size = fp->datasize; in wpi_read_firmware()
5041 fw->data = (const uint8_t *)fp->data; in wpi_read_firmware()
5044 hdr = (const struct wpi_firmware_hdr *)fw->data; in wpi_read_firmware()
5047 |HDR|<--TEXT-->|<--DATA-->|<--TEXT-->|<--DATA-->|<--TEXT-->| */ in wpi_read_firmware()
5049 fw->main.textsz = le32toh(hdr->rtextsz); in wpi_read_firmware()
5050 fw->main.datasz = le32toh(hdr->rdatasz); in wpi_read_firmware()
5051 fw->init.textsz = le32toh(hdr->itextsz); in wpi_read_firmware()
5052 fw->init.datasz = le32toh(hdr->idatasz); in wpi_read_firmware()
5053 fw->boot.textsz = le32toh(hdr->btextsz); in wpi_read_firmware()
5054 fw->boot.datasz = 0; in wpi_read_firmware()
5056 /* Sanity-check firmware header. */ in wpi_read_firmware()
5057 if (fw->main.textsz > WPI_FW_TEXT_MAXSZ || in wpi_read_firmware()
5058 fw->main.datasz > WPI_FW_DATA_MAXSZ || in wpi_read_firmware()
5059 fw->init.textsz > WPI_FW_TEXT_MAXSZ || in wpi_read_firmware()
5060 fw->init.datasz > WPI_FW_DATA_MAXSZ || in wpi_read_firmware()
5061 fw->boot.textsz > WPI_FW_BOOT_TEXT_MAXSZ || in wpi_read_firmware()
5062 (fw->boot.textsz & 3) != 0) { in wpi_read_firmware()
5063 device_printf(sc->sc_dev, "invalid firmware header\n"); in wpi_read_firmware()
5069 if (fw->size < sizeof (*hdr) + fw->main.textsz + fw->main.datasz + in wpi_read_firmware()
5070 fw->init.textsz + fw->init.datasz + fw->boot.textsz) { in wpi_read_firmware()
5071 device_printf(sc->sc_dev, in wpi_read_firmware()
5072 "firmware file too short: %zu bytes\n", fw->size); in wpi_read_firmware()
5078 fw->main.text = (const uint8_t *)(hdr + 1); in wpi_read_firmware()
5079 fw->main.data = fw->main.text + fw->main.textsz; in wpi_read_firmware()
5080 fw->init.text = fw->main.data + fw->main.datasz; in wpi_read_firmware()
5081 fw->init.data = fw->init.text + fw->init.textsz; in wpi_read_firmware()
5082 fw->boot.text = fw->init.data + fw->init.datasz; in wpi_read_firmware()
5087 "boot (text %u)\n", hdr->major, hdr->minor, le32toh(hdr->driver), in wpi_read_firmware()
5088 fw->main.textsz, fw->main.datasz, in wpi_read_firmware()
5089 fw->init.textsz, fw->init.datasz, fw->boot.textsz); in wpi_read_firmware()
5091 DPRINTF(sc, WPI_DEBUG_FIRMWARE, "fw->main.text %p\n", fw->main.text); in wpi_read_firmware()
5092 DPRINTF(sc, WPI_DEBUG_FIRMWARE, "fw->main.data %p\n", fw->main.data); in wpi_read_firmware()
5093 DPRINTF(sc, WPI_DEBUG_FIRMWARE, "fw->init.text %p\n", fw->init.text); in wpi_read_firmware()
5094 DPRINTF(sc, WPI_DEBUG_FIRMWARE, "fw->init.data %p\n", fw->init.data); in wpi_read_firmware()
5095 DPRINTF(sc, WPI_DEBUG_FIRMWARE, "fw->boot.text %p\n", fw->boot.text); in wpi_read_firmware()
5109 if (sc->fw_fp != NULL) { in wpi_unload_firmware()
5110 firmware_put(sc->fw_fp, FIRMWARE_UNLOAD); in wpi_unload_firmware()
5111 sc->fw_fp = NULL; in wpi_unload_firmware()
5129 device_printf(sc->sc_dev, in wpi_clock_wait()
5152 reg = pci_read_config(sc->sc_dev, sc->sc_cap_off + PCIER_LINK_CTL, 1); in wpi_apm_init()
5153 /* Workaround for HW instability in PCIe L0->L0s->L1 transition. */ in wpi_apm_init()
5171 /* Enable DMA and BSM (Bootstrap State Machine). */ in wpi_apm_init()
5175 /* Disable L1-Active. */ in wpi_apm_init()
5187 /* Stop busmaster DMA activity. */ in wpi_apm_stop_master()
5199 device_printf(sc->sc_dev, "%s: timeout waiting for master\n", in wpi_apm_stop_master()
5223 rev = pci_read_config(sc->sc_dev, PCIR_REVID, 1); in wpi_nic_config()
5229 if (sc->cap == 0x80) in wpi_nic_config()
5232 if ((sc->rev & 0xf0) == 0xd0) in wpi_nic_config()
5237 if (sc->type > 1) in wpi_nic_config()
5253 device_printf(sc->sc_dev, in wpi_hw_init()
5271 device_printf(sc->sc_dev, "timeout selecting power source\n"); in wpi_hw_init()
5282 WPI_WRITE(sc, WPI_FH_RX_BASE, sc->rxq.desc_dma.paddr); in wpi_hw_init()
5284 WPI_WRITE(sc, WPI_FH_RX_RPTR_ADDR, sc->shared_dma.paddr + in wpi_hw_init()
5298 WPI_WRITE(sc, WPI_FH_RX_WPTR, (WPI_RX_RING_COUNT - 1) & ~7); in wpi_hw_init()
5312 WPI_WRITE(sc, WPI_FH_TX_BASE, sc->shared_dma.paddr); in wpi_hw_init()
5315 /* Enable all DMA channels. */ in wpi_hw_init()
5338 device_printf(sc->sc_dev, in wpi_hw_init()
5344 if ((error = mtx_sleep(sc, &sc->sc_mtx, PCATCH, "wpiinit", hz)) != 0) { in wpi_hw_init()
5345 device_printf(sc->sc_dev, in wpi_hw_init()
5353 /* Do post-firmware initialization. */ in wpi_hw_init()
5383 /* Stop all DMA channels. */ in wpi_hw_stop()
5401 wpi_reset_tx_ring(sc, &sc->txq[qid]); in wpi_hw_stop()
5417 struct ieee80211com *ic = &sc->sc_ic; in wpi_radio_on()
5418 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); in wpi_radio_on()
5420 device_printf(sc->sc_dev, "RF switch: radio enabled\n"); in wpi_radio_on()
5423 callout_stop(&sc->watchdog_rfkill); in wpi_radio_on()
5434 struct ieee80211com *ic = &sc->sc_ic; in wpi_radio_off()
5435 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); in wpi_radio_off()
5437 device_printf(sc->sc_dev, "RF switch: radio disabled\n"); in wpi_radio_off()
5445 callout_reset(&sc->watchdog_rfkill, hz, wpi_watchdog_rfkill, sc); in wpi_radio_off()
5458 if (sc->sc_running != 0) in wpi_init()
5463 device_printf(sc->sc_dev, in wpi_init()
5465 callout_reset(&sc->watchdog_rfkill, hz, wpi_watchdog_rfkill, in wpi_init()
5473 device_printf(sc->sc_dev, in wpi_init()
5479 sc->sc_running = 1; in wpi_init()
5485 device_printf(sc->sc_dev, in wpi_init()
5493 device_printf(sc->sc_dev, in wpi_init()
5519 if (sc->sc_running == 0) in wpi_stop_locked()
5524 sc->sc_running = 0; in wpi_stop_locked()
5529 callout_stop(&sc->tx_timeout); in wpi_stop_locked()
5533 callout_stop(&sc->scan_timeout); in wpi_stop_locked()
5534 callout_stop(&sc->calib_to); in wpi_stop_locked()
5555 struct wpi_softc *sc = ic->ic_softc; in wpi_scan_start()
5566 struct wpi_softc *sc = ic->ic_softc; in wpi_scan_end()
5567 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); in wpi_scan_end()
5569 if (vap->iv_state == IEEE80211_S_RUN) in wpi_scan_end()
5580 const struct ieee80211_channel *c = ic->ic_curchan; in wpi_set_channel()
5581 struct wpi_softc *sc = ic->ic_softc; in wpi_set_channel()
5587 sc->sc_rxtap.wr_chan_freq = htole16(c->ic_freq); in wpi_set_channel()
5588 sc->sc_rxtap.wr_chan_flags = htole16(c->ic_flags); in wpi_set_channel()
5591 sc->sc_txtap.wt_chan_freq = htole16(c->ic_freq); in wpi_set_channel()
5592 sc->sc_txtap.wt_chan_flags = htole16(c->ic_flags); in wpi_set_channel()
5599 if (ic->ic_opmode == IEEE80211_M_MONITOR) { in wpi_set_channel()
5601 sc->rxon.chan = ieee80211_chan2ieee(ic, c); in wpi_set_channel()
5603 sc->rxon.flags |= htole32(WPI_RXON_AUTO | in wpi_set_channel()
5606 sc->rxon.flags &= ~htole32(WPI_RXON_AUTO | in wpi_set_channel()
5610 device_printf(sc->sc_dev, in wpi_set_channel()
5625 struct ieee80211vap *vap = ss->ss_vap; in wpi_scan_curchan()
5626 struct ieee80211com *ic = vap->iv_ic; in wpi_scan_curchan()
5627 struct wpi_softc *sc = ic->ic_softc; in wpi_scan_curchan()
5631 error = wpi_scan(sc, ic->ic_curchan); in wpi_scan_curchan()