Lines Matching +full:4 +full:- +full:ring

1 /*-
2 * Copyright (c) 2007-2010 Damien Bergamini <damien.bergamini@free.fr>
21 /*-
70 #define DPRINTF(x) do { if (sc->sc_debug > 0) printf x; } while (0)
71 #define DPRINTFN(n, x) do { if (sc->sc_debug >= (n)) printf x; } while (0)
238 struct ieee80211com *ic = &sc->sc_ic; in rt2860_attach()
242 sc->sc_dev = dev; in rt2860_attach()
243 sc->sc_debug = 0; in rt2860_attach()
245 mtx_init(&sc->sc_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK, in rt2860_attach()
248 callout_init_mtx(&sc->watchdog_ch, &sc->sc_mtx, 0); in rt2860_attach()
249 mbufq_init(&sc->sc_snd, ifqmaxlen); in rt2860_attach()
259 device_printf(sc->sc_dev, in rt2860_attach()
264 sc->mac_ver = tmp >> 16; in rt2860_attach()
265 sc->mac_rev = tmp & 0xffff; in rt2860_attach()
267 if (sc->mac_ver != 0x2860 && in rt2860_attach()
269 sc->sc_flags |= RT2860_ADVANCED_PS; in rt2860_attach()
272 rt2860_read_eeprom(sc, ic->ic_macaddr); in rt2860_attach()
273 device_printf(sc->sc_dev, "MAC/BBP RT%X (rev 0x%04X), " in rt2860_attach()
275 sc->mac_ver, sc->mac_rev, rt2860_get_rf(sc->rf_rev), in rt2860_attach()
276 sc->ntxchains, sc->nrxchains, ic->ic_macaddr, ":"); in rt2860_attach()
279 * Allocate Tx (4 EDCAs + HCCA + Mgt) and Rx rings. in rt2860_attach()
282 if ((error = rt2860_alloc_tx_ring(sc, &sc->txq[qid])) != 0) { in rt2860_attach()
283 device_printf(sc->sc_dev, in rt2860_attach()
284 "could not allocate Tx ring %d\n", qid); in rt2860_attach()
289 if ((error = rt2860_alloc_rx_ring(sc, &sc->rxq)) != 0) { in rt2860_attach()
290 device_printf(sc->sc_dev, "could not allocate Rx ring\n"); in rt2860_attach()
295 device_printf(sc->sc_dev, "could not allocate Tx pool\n"); in rt2860_attach()
299 /* mgmt ring is broken on RT2860C, use EDCA AC VO ring instead */ in rt2860_attach()
300 sc->mgtqid = (sc->mac_ver == 0x2860 && sc->mac_rev == 0x0100) ? in rt2860_attach()
303 ic->ic_softc = sc; in rt2860_attach()
304 ic->ic_name = device_get_nameunit(dev); in rt2860_attach()
305 ic->ic_opmode = IEEE80211_M_STA; in rt2860_attach()
306 ic->ic_phytype = IEEE80211_T_OFDM; /* not only, but not used */ in rt2860_attach()
309 ic->ic_caps = in rt2860_attach()
315 | IEEE80211_C_WDS /* 4-address traffic works */ in rt2860_attach()
326 rt2860_getradiocaps(ic, IEEE80211_CHAN_MAX, &ic->ic_nchans, in rt2860_attach()
327 ic->ic_channels); in rt2860_attach()
331 ic->ic_wme.wme_update = rt2860_updateedca; in rt2860_attach()
332 ic->ic_scan_start = rt2860_scan_start; in rt2860_attach()
333 ic->ic_scan_end = rt2860_scan_end; in rt2860_attach()
334 ic->ic_getradiocaps = rt2860_getradiocaps; in rt2860_attach()
335 ic->ic_set_channel = rt2860_set_channel; in rt2860_attach()
336 ic->ic_updateslot = rt2860_updateslot; in rt2860_attach()
337 ic->ic_update_promisc = rt2860_update_promisc; in rt2860_attach()
338 ic->ic_raw_xmit = rt2860_raw_xmit; in rt2860_attach()
339 sc->sc_node_free = ic->ic_node_free; in rt2860_attach()
340 ic->ic_node_free = rt2860_node_free; in rt2860_attach()
341 ic->ic_newassoc = rt2860_newassoc; in rt2860_attach()
342 ic->ic_transmit = rt2860_transmit; in rt2860_attach()
343 ic->ic_parent = rt2860_parent; in rt2860_attach()
344 ic->ic_vap_create = rt2860_vap_create; in rt2860_attach()
345 ic->ic_vap_delete = rt2860_vap_delete; in rt2860_attach()
348 &sc->sc_txtap.wt_ihdr, sizeof(sc->sc_txtap), in rt2860_attach()
350 &sc->sc_rxtap.wr_ihdr, sizeof(sc->sc_rxtap), in rt2860_attach()
356 "debug", CTLFLAG_RW, &sc->sc_debug, 0, "debug msgs"); in rt2860_attach()
363 fail3: rt2860_free_rx_ring(sc, &sc->rxq); in rt2860_attach()
364 fail2: while (--qid >= 0) in rt2860_attach()
365 rt2860_free_tx_ring(sc, &sc->txq[qid]); in rt2860_attach()
366 fail1: mtx_destroy(&sc->sc_mtx); in rt2860_attach()
374 struct ieee80211com *ic = &sc->sc_ic; in rt2860_detach()
382 mbufq_drain(&sc->sc_snd); in rt2860_detach()
384 rt2860_free_tx_ring(sc, &sc->txq[qid]); in rt2860_detach()
385 rt2860_free_rx_ring(sc, &sc->rxq); in rt2860_detach()
388 mtx_destroy(&sc->sc_mtx); in rt2860_detach()
414 if (sc->sc_ic.ic_nrunning > 0) in rt2860_resume()
424 struct rt2860_softc *sc = ic->ic_softc; in rt2860_vap_create()
436 if (!TAILQ_EMPTY(&ic->ic_vaps)) { in rt2860_vap_create()
437 device_printf(sc->sc_dev, "only 1 vap supported\n"); in rt2860_vap_create()
444 if (TAILQ_EMPTY(&ic->ic_vaps) || in rt2860_vap_create()
445 ic->ic_opmode != IEEE80211_M_HOSTAP) { in rt2860_vap_create()
446 device_printf(sc->sc_dev, in rt2860_vap_create()
458 device_printf(sc->sc_dev, "unknown opmode %d\n", opmode); in rt2860_vap_create()
462 vap = &rvp->ral_vap; in rt2860_vap_create()
466 rvp->ral_newstate = vap->iv_newstate; in rt2860_vap_create()
467 vap->iv_newstate = rt2860_newstate; in rt2860_vap_create()
469 vap->iv_update_beacon = rt2860_beacon_update; in rt2860_vap_create()
472 /* HW supports up to 255 STAs (0-254) in HostAP and IBSS modes */ in rt2860_vap_create()
473 vap->iv_max_aid = min(IEEE80211_AID_MAX, RT2860_WCID_MAX); in rt2860_vap_create()
479 if (TAILQ_FIRST(&ic->ic_vaps) == vap) in rt2860_vap_create()
480 ic->ic_opmode = opmode; in rt2860_vap_create()
506 rt2860_alloc_tx_ring(struct rt2860_softc *sc, struct rt2860_tx_ring *ring) in rt2860_alloc_tx_ring() argument
512 error = bus_dma_tag_create(bus_get_dma_tag(sc->sc_dev), 16, 0, in rt2860_alloc_tx_ring()
514 size, 1, size, 0, NULL, NULL, &ring->desc_dmat); in rt2860_alloc_tx_ring()
516 device_printf(sc->sc_dev, "could not create desc DMA tag\n"); in rt2860_alloc_tx_ring()
520 error = bus_dmamem_alloc(ring->desc_dmat, (void **)&ring->txd, in rt2860_alloc_tx_ring()
521 BUS_DMA_NOWAIT | BUS_DMA_ZERO, &ring->desc_map); in rt2860_alloc_tx_ring()
523 device_printf(sc->sc_dev, "could not allocate DMA memory\n"); in rt2860_alloc_tx_ring()
527 error = bus_dmamap_load(ring->desc_dmat, ring->desc_map, ring->txd, in rt2860_alloc_tx_ring()
528 size, rt2860_dma_map_addr, &ring->paddr, 0); in rt2860_alloc_tx_ring()
530 device_printf(sc->sc_dev, "could not load desc DMA map\n"); in rt2860_alloc_tx_ring()
534 bus_dmamap_sync(ring->desc_dmat, ring->desc_map, BUS_DMASYNC_PREWRITE); in rt2860_alloc_tx_ring()
538 fail: rt2860_free_tx_ring(sc, ring); in rt2860_alloc_tx_ring()
543 rt2860_reset_tx_ring(struct rt2860_softc *sc, struct rt2860_tx_ring *ring) in rt2860_reset_tx_ring() argument
549 if ((data = ring->data[i]) == NULL) in rt2860_reset_tx_ring()
552 if (data->m != NULL) { in rt2860_reset_tx_ring()
553 bus_dmamap_sync(sc->txwi_dmat, data->map, in rt2860_reset_tx_ring()
555 bus_dmamap_unload(sc->txwi_dmat, data->map); in rt2860_reset_tx_ring()
556 m_freem(data->m); in rt2860_reset_tx_ring()
557 data->m = NULL; in rt2860_reset_tx_ring()
559 if (data->ni != NULL) { in rt2860_reset_tx_ring()
560 ieee80211_free_node(data->ni); in rt2860_reset_tx_ring()
561 data->ni = NULL; in rt2860_reset_tx_ring()
564 SLIST_INSERT_HEAD(&sc->data_pool, data, next); in rt2860_reset_tx_ring()
565 ring->data[i] = NULL; in rt2860_reset_tx_ring()
568 ring->queued = 0; in rt2860_reset_tx_ring()
569 ring->cur = ring->next = 0; in rt2860_reset_tx_ring()
573 rt2860_free_tx_ring(struct rt2860_softc *sc, struct rt2860_tx_ring *ring) in rt2860_free_tx_ring() argument
578 if (ring->txd != NULL) { in rt2860_free_tx_ring()
579 bus_dmamap_sync(ring->desc_dmat, ring->desc_map, in rt2860_free_tx_ring()
581 bus_dmamap_unload(ring->desc_dmat, ring->desc_map); in rt2860_free_tx_ring()
582 bus_dmamem_free(ring->desc_dmat, ring->txd, ring->desc_map); in rt2860_free_tx_ring()
584 if (ring->desc_dmat != NULL) in rt2860_free_tx_ring()
585 bus_dma_tag_destroy(ring->desc_dmat); in rt2860_free_tx_ring()
588 if ((data = ring->data[i]) == NULL) in rt2860_free_tx_ring()
591 if (data->m != NULL) { in rt2860_free_tx_ring()
592 bus_dmamap_sync(sc->txwi_dmat, data->map, in rt2860_free_tx_ring()
594 bus_dmamap_unload(sc->txwi_dmat, data->map); in rt2860_free_tx_ring()
595 m_freem(data->m); in rt2860_free_tx_ring()
597 if (data->ni != NULL) in rt2860_free_tx_ring()
598 ieee80211_free_node(data->ni); in rt2860_free_tx_ring()
600 SLIST_INSERT_HEAD(&sc->data_pool, data, next); in rt2860_free_tx_ring()
617 SLIST_INIT(&sc->data_pool); in rt2860_alloc_tx_pool()
619 error = bus_dma_tag_create(bus_get_dma_tag(sc->sc_dev), 1, 0, in rt2860_alloc_tx_pool()
621 size, 1, size, 0, NULL, NULL, &sc->txwi_dmat); in rt2860_alloc_tx_pool()
623 device_printf(sc->sc_dev, "could not create txwi DMA tag\n"); in rt2860_alloc_tx_pool()
627 error = bus_dmamem_alloc(sc->txwi_dmat, (void **)&sc->txwi_vaddr, in rt2860_alloc_tx_pool()
628 BUS_DMA_NOWAIT | BUS_DMA_ZERO, &sc->txwi_map); in rt2860_alloc_tx_pool()
630 device_printf(sc->sc_dev, "could not allocate DMA memory\n"); in rt2860_alloc_tx_pool()
634 error = bus_dmamap_load(sc->txwi_dmat, sc->txwi_map, in rt2860_alloc_tx_pool()
635 sc->txwi_vaddr, size, rt2860_dma_map_addr, &paddr, 0); in rt2860_alloc_tx_pool()
637 device_printf(sc->sc_dev, "could not load txwi DMA map\n"); in rt2860_alloc_tx_pool()
641 bus_dmamap_sync(sc->txwi_dmat, sc->txwi_map, BUS_DMASYNC_PREWRITE); in rt2860_alloc_tx_pool()
643 vaddr = sc->txwi_vaddr; in rt2860_alloc_tx_pool()
645 struct rt2860_tx_data *data = &sc->data[i]; in rt2860_alloc_tx_pool()
647 error = bus_dmamap_create(sc->txwi_dmat, 0, &data->map); in rt2860_alloc_tx_pool()
649 device_printf(sc->sc_dev, "could not create DMA map\n"); in rt2860_alloc_tx_pool()
652 data->txwi = (struct rt2860_txwi *)vaddr; in rt2860_alloc_tx_pool()
653 data->paddr = paddr; in rt2860_alloc_tx_pool()
657 SLIST_INSERT_HEAD(&sc->data_pool, data, next); in rt2860_alloc_tx_pool()
669 if (sc->txwi_vaddr != NULL) { in rt2860_free_tx_pool()
670 bus_dmamap_sync(sc->txwi_dmat, sc->txwi_map, in rt2860_free_tx_pool()
672 bus_dmamap_unload(sc->txwi_dmat, sc->txwi_map); in rt2860_free_tx_pool()
673 bus_dmamem_free(sc->txwi_dmat, sc->txwi_vaddr, sc->txwi_map); in rt2860_free_tx_pool()
675 if (sc->txwi_dmat != NULL) in rt2860_free_tx_pool()
676 bus_dma_tag_destroy(sc->txwi_dmat); in rt2860_free_tx_pool()
678 while (!SLIST_EMPTY(&sc->data_pool)) { in rt2860_free_tx_pool()
680 data = SLIST_FIRST(&sc->data_pool); in rt2860_free_tx_pool()
681 bus_dmamap_destroy(sc->txwi_dmat, data->map); in rt2860_free_tx_pool()
682 SLIST_REMOVE_HEAD(&sc->data_pool, next); in rt2860_free_tx_pool()
687 rt2860_alloc_rx_ring(struct rt2860_softc *sc, struct rt2860_rx_ring *ring) in rt2860_alloc_rx_ring() argument
694 error = bus_dma_tag_create(bus_get_dma_tag(sc->sc_dev), 16, 0, in rt2860_alloc_rx_ring()
696 size, 1, size, 0, NULL, NULL, &ring->desc_dmat); in rt2860_alloc_rx_ring()
698 device_printf(sc->sc_dev, "could not create desc DMA tag\n"); in rt2860_alloc_rx_ring()
702 error = bus_dmamem_alloc(ring->desc_dmat, (void **)&ring->rxd, in rt2860_alloc_rx_ring()
703 BUS_DMA_NOWAIT | BUS_DMA_ZERO, &ring->desc_map); in rt2860_alloc_rx_ring()
705 device_printf(sc->sc_dev, "could not allocate DMA memory\n"); in rt2860_alloc_rx_ring()
709 error = bus_dmamap_load(ring->desc_dmat, ring->desc_map, ring->rxd, in rt2860_alloc_rx_ring()
710 size, rt2860_dma_map_addr, &ring->paddr, 0); in rt2860_alloc_rx_ring()
712 device_printf(sc->sc_dev, "could not load desc DMA map\n"); in rt2860_alloc_rx_ring()
716 error = bus_dma_tag_create(bus_get_dma_tag(sc->sc_dev), 1, 0, in rt2860_alloc_rx_ring()
718 1, MCLBYTES, 0, NULL, NULL, &ring->data_dmat); in rt2860_alloc_rx_ring()
720 device_printf(sc->sc_dev, "could not create data DMA tag\n"); in rt2860_alloc_rx_ring()
725 struct rt2860_rx_data *data = &ring->data[i]; in rt2860_alloc_rx_ring()
726 struct rt2860_rxd *rxd = &ring->rxd[i]; in rt2860_alloc_rx_ring()
728 error = bus_dmamap_create(ring->data_dmat, 0, &data->map); in rt2860_alloc_rx_ring()
730 device_printf(sc->sc_dev, "could not create DMA map\n"); in rt2860_alloc_rx_ring()
734 data->m = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR); in rt2860_alloc_rx_ring()
735 if (data->m == NULL) { in rt2860_alloc_rx_ring()
736 device_printf(sc->sc_dev, in rt2860_alloc_rx_ring()
742 error = bus_dmamap_load(ring->data_dmat, data->map, in rt2860_alloc_rx_ring()
743 mtod(data->m, void *), MCLBYTES, rt2860_dma_map_addr, in rt2860_alloc_rx_ring()
746 device_printf(sc->sc_dev, in rt2860_alloc_rx_ring()
751 rxd->sdp0 = htole32(physaddr); in rt2860_alloc_rx_ring()
752 rxd->sdl0 = htole16(MCLBYTES); in rt2860_alloc_rx_ring()
755 bus_dmamap_sync(ring->desc_dmat, ring->desc_map, BUS_DMASYNC_PREWRITE); in rt2860_alloc_rx_ring()
759 fail: rt2860_free_rx_ring(sc, ring); in rt2860_alloc_rx_ring()
764 rt2860_reset_rx_ring(struct rt2860_softc *sc, struct rt2860_rx_ring *ring) in rt2860_reset_rx_ring() argument
769 ring->rxd[i].sdl0 &= ~htole16(RT2860_RX_DDONE); in rt2860_reset_rx_ring()
771 bus_dmamap_sync(ring->desc_dmat, ring->desc_map, BUS_DMASYNC_PREWRITE); in rt2860_reset_rx_ring()
773 ring->cur = 0; in rt2860_reset_rx_ring()
777 rt2860_free_rx_ring(struct rt2860_softc *sc, struct rt2860_rx_ring *ring) in rt2860_free_rx_ring() argument
781 if (ring->rxd != NULL) { in rt2860_free_rx_ring()
782 bus_dmamap_sync(ring->desc_dmat, ring->desc_map, in rt2860_free_rx_ring()
784 bus_dmamap_unload(ring->desc_dmat, ring->desc_map); in rt2860_free_rx_ring()
785 bus_dmamem_free(ring->desc_dmat, ring->rxd, ring->desc_map); in rt2860_free_rx_ring()
787 if (ring->desc_dmat != NULL) in rt2860_free_rx_ring()
788 bus_dma_tag_destroy(ring->desc_dmat); in rt2860_free_rx_ring()
791 struct rt2860_rx_data *data = &ring->data[i]; in rt2860_free_rx_ring()
793 if (data->m != NULL) { in rt2860_free_rx_ring()
794 bus_dmamap_sync(ring->data_dmat, data->map, in rt2860_free_rx_ring()
796 bus_dmamap_unload(ring->data_dmat, data->map); in rt2860_free_rx_ring()
797 m_freem(data->m); in rt2860_free_rx_ring()
799 if (data->map != NULL) in rt2860_free_rx_ring()
800 bus_dmamap_destroy(ring->data_dmat, data->map); in rt2860_free_rx_ring()
802 if (ring->data_dmat != NULL) in rt2860_free_rx_ring()
803 bus_dma_tag_destroy(ring->data_dmat); in rt2860_free_rx_ring()
809 struct ieee80211com *ic = &sc->sc_ic; in rt2860_updatestats()
813 * MAC can run into a livelock and start sending CTS-to-self frames in rt2860_updatestats()
817 if (ic->ic_curmode != IEEE80211_M_STA) { in rt2860_updatestats()
822 DPRINTF(("CTS-to-self livelock detected\n")); in rt2860_updatestats()
835 struct ieee80211com *ic = ni->ni_ic; in rt2860_newassoc()
836 struct rt2860_softc *sc = ic->ic_softc; in rt2860_newassoc()
839 wcid = IEEE80211_AID(ni->ni_associd); in rt2860_newassoc()
840 if (isnew && ni->ni_associd != 0) { in rt2860_newassoc()
841 sc->wcid2ni[wcid] = ni; in rt2860_newassoc()
845 ni->ni_macaddr, IEEE80211_ADDR_LEN); in rt2860_newassoc()
848 isnew, ether_sprintf(ni->ni_macaddr), wcid)); in rt2860_newassoc()
854 struct ieee80211com *ic = ni->ni_ic; in rt2860_node_free()
855 struct rt2860_softc *sc = ic->ic_softc; in rt2860_node_free()
858 if (ni->ni_associd != 0) { in rt2860_node_free()
859 wcid = IEEE80211_AID(ni->ni_associd); in rt2860_node_free()
864 sc->sc_node_free(ni); in rt2860_node_free()
872 struct rt2860_softc *sc = ic->ic_softc; in rt2860_ampdu_rx_start()
873 uint8_t wcid = ((struct rt2860_node *)ni)->wcid; in rt2860_ampdu_rx_start()
877 tmp = RAL_READ(sc, RT2860_WCID_ENTRY(wcid) + 4); in rt2860_ampdu_rx_start()
879 RAL_WRITE(sc, RT2860_WCID_ENTRY(wcid) + 4, tmp); in rt2860_ampdu_rx_start()
887 struct rt2860_softc *sc = ic->ic_softc; in rt2860_ampdu_rx_stop()
888 uint8_t wcid = ((struct rt2860_node *)ni)->wcid; in rt2860_ampdu_rx_stop()
892 tmp = RAL_READ(sc, RT2860_WCID_ENTRY(wcid) + 4); in rt2860_ampdu_rx_stop()
894 RAL_WRITE(sc, RT2860_WCID_ENTRY(wcid) + 4, tmp); in rt2860_ampdu_rx_stop()
902 struct ieee80211com *ic = vap->iv_ic; in rt2860_newstate()
903 struct rt2860_softc *sc = ic->ic_softc; in rt2860_newstate()
907 if (vap->iv_state == IEEE80211_S_RUN) { in rt2860_newstate()
912 if (nstate == IEEE80211_S_INIT && vap->iv_state == IEEE80211_S_RUN) { in rt2860_newstate()
922 error = rvp->ral_newstate(vap, nstate, arg); in rt2860_newstate()
927 struct ieee80211_node *ni = vap->iv_bss; in rt2860_newstate()
929 if (ic->ic_opmode != IEEE80211_M_MONITOR) { in rt2860_newstate()
932 rt2860_set_basicrates(sc, &ni->ni_rates); in rt2860_newstate()
933 rt2860_set_bssid(sc, ni->ni_bssid); in rt2860_newstate()
936 if (vap->iv_opmode == IEEE80211_M_HOSTAP || in rt2860_newstate()
937 vap->iv_opmode == IEEE80211_M_IBSS || in rt2860_newstate()
938 vap->iv_opmode == IEEE80211_M_MBSS) { in rt2860_newstate()
944 if (ic->ic_opmode != IEEE80211_M_MONITOR) { in rt2860_newstate()
951 (IEEE80211_IS_CHAN_2GHZ(ni->ni_chan) ? in rt2860_newstate()
957 /* Read 16-bit from eFUSE ROM (>=RT3071 only.) */
966 /*- in rt3090_efuse_read_2()
967 * Read one 16-byte block into registers EFUSE_DATA[0-3]: in rt3090_efuse_read_2()
970 * DATA2: 7 6 5 4 in rt3090_efuse_read_2()
989 /* determine to which 32-bit register our 16-bit word belongs */ in rt3090_efuse_read_2()
990 reg = RT3070_EFUSE_DATA3 - (addr & 0xc); in rt3090_efuse_read_2()
1024 /* write address (A5-A0 or A7-A0) */ in rt2860_eeprom_read_2()
1026 for (; n >= 0; n--) { in rt2860_eeprom_read_2()
1035 /* read data Q15-Q0 */ in rt2860_eeprom_read_2()
1037 for (n = 15; n >= 0; n--) { in rt2860_eeprom_read_2()
1058 return sc->sc_srom_read(sc, addr); in rt2860_srom_read()
1081 struct ieee80211_ratectl_tx_status *txs = &sc->sc_txs; in rt2860_drain_stats_fifo()
1087 txs->flags = IEEE80211_RATECTL_STATUS_LONG_RETRY; in rt2860_drain_stats_fifo()
1089 DPRINTFN(4, ("tx stat 0x%08x\n", stat)); in rt2860_drain_stats_fifo()
1094 ni = sc->wcid2ni[wcid]; in rt2860_drain_stats_fifo()
1100 /* update per-STA AMRR stats */ in rt2860_drain_stats_fifo()
1111 txs->long_retries = 1; in rt2860_drain_stats_fifo()
1113 txs->long_retries = 0; in rt2860_drain_stats_fifo()
1114 txs->status = IEEE80211_RATECTL_TX_SUCCESS; in rt2860_drain_stats_fifo()
1117 txs->status = IEEE80211_RATECTL_TX_FAIL_UNSPECIFIED; in rt2860_drain_stats_fifo()
1118 txs->long_retries = 1; /* XXX */ in rt2860_drain_stats_fifo()
1120 if_inc_counter(ni->ni_vap->iv_ifp, in rt2860_drain_stats_fifo()
1129 struct rt2860_tx_ring *ring = &sc->txq[qid]; in rt2860_tx_intr() local
1135 while (ring->next != hw) { in rt2860_tx_intr()
1136 struct rt2860_tx_data *data = ring->data[ring->next]; in rt2860_tx_intr()
1139 bus_dmamap_sync(sc->txwi_dmat, data->map, in rt2860_tx_intr()
1141 bus_dmamap_unload(sc->txwi_dmat, data->map); in rt2860_tx_intr()
1142 ieee80211_tx_complete(data->ni, data->m, 0); in rt2860_tx_intr()
1143 data->ni = NULL; in rt2860_tx_intr()
1144 data->m = NULL; in rt2860_tx_intr()
1145 SLIST_INSERT_HEAD(&sc->data_pool, data, next); in rt2860_tx_intr()
1146 ring->data[ring->next] = NULL; in rt2860_tx_intr()
1148 ring->queued--; in rt2860_tx_intr()
1149 ring->next = (ring->next + 1) % RT2860_TX_RING_COUNT; in rt2860_tx_intr()
1152 sc->sc_tx_timer = 0; in rt2860_tx_intr()
1153 if (ring->queued < RT2860_TX_RING_COUNT) in rt2860_tx_intr()
1154 sc->qfullmsk &= ~(1 << qid); in rt2860_tx_intr()
1166 if (sc->nrxchains > 1) { in rt2860_maxrssi_chain()
1167 if (rxwi->rssi[1] > rxwi->rssi[rxchain]) in rt2860_maxrssi_chain()
1169 if (sc->nrxchains > 2) in rt2860_maxrssi_chain()
1170 if (rxwi->rssi[2] > rxwi->rssi[rxchain]) in rt2860_maxrssi_chain()
1180 struct ieee80211com *ic = &sc->sc_ic; in rt2860_rx_intr()
1192 while (sc->rxq.cur != hw) { in rt2860_rx_intr()
1193 struct rt2860_rx_data *data = &sc->rxq.data[sc->rxq.cur]; in rt2860_rx_intr()
1194 struct rt2860_rxd *rxd = &sc->rxq.rxd[sc->rxq.cur]; in rt2860_rx_intr()
1197 bus_dmamap_sync(sc->rxq.desc_dmat, sc->rxq.desc_map, in rt2860_rx_intr()
1200 if (__predict_false(!(rxd->sdl0 & htole16(RT2860_RX_DDONE)))) { in rt2860_rx_intr()
1205 if (__predict_false(rxd->flags & in rt2860_rx_intr()
1207 counter_u64_add(ic->ic_ierrors, 1); in rt2860_rx_intr()
1212 if (__predict_false(rxd->flags & htole32(RT2860_RX_MICERR))) { in rt2860_rx_intr()
1214 ic->ic_stats.is_rx_locmicfail++; in rt2860_rx_intr()
1216 counter_u64_add(ic->ic_ierrors, 1); in rt2860_rx_intr()
1223 counter_u64_add(ic->ic_ierrors, 1); in rt2860_rx_intr()
1227 bus_dmamap_sync(sc->rxq.data_dmat, data->map, in rt2860_rx_intr()
1229 bus_dmamap_unload(sc->rxq.data_dmat, data->map); in rt2860_rx_intr()
1231 error = bus_dmamap_load(sc->rxq.data_dmat, data->map, in rt2860_rx_intr()
1238 error = bus_dmamap_load(sc->rxq.data_dmat, data->map, in rt2860_rx_intr()
1239 mtod(data->m, void *), MCLBYTES, in rt2860_rx_intr()
1243 device_get_name(sc->sc_dev)); in rt2860_rx_intr()
1246 rxd->sdp0 = htole32(physaddr); in rt2860_rx_intr()
1247 counter_u64_add(ic->ic_ierrors, 1); in rt2860_rx_intr()
1252 * New mbuf successfully loaded, update Rx ring and continue in rt2860_rx_intr()
1255 m = data->m; in rt2860_rx_intr()
1256 data->m = m1; in rt2860_rx_intr()
1257 rxd->sdp0 = htole32(physaddr); in rt2860_rx_intr()
1262 m->m_data = (caddr_t)(rxwi + 1); in rt2860_rx_intr()
1263 m->m_pkthdr.len = m->m_len = le16toh(rxwi->len) & 0xfff; in rt2860_rx_intr()
1267 if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) { in rt2860_rx_intr()
1269 wh->i_fc[1] &= ~IEEE80211_FC1_PROTECTED; in rt2860_rx_intr()
1274 if (rxd->flags & htole32(RT2860_RX_L2PAD)) { in rt2860_rx_intr()
1277 m->m_data += 2; in rt2860_rx_intr()
1282 rssi = rt2860_rssi2dbm(sc, rxwi->rssi[ant], ant); in rt2860_rx_intr()
1286 tap = &sc->sc_rxtap; in rt2860_rx_intr()
1287 tap->wr_flags = 0; in rt2860_rx_intr()
1288 tap->wr_antenna = ant; in rt2860_rx_intr()
1289 tap->wr_antsignal = nf + rssi; in rt2860_rx_intr()
1290 tap->wr_antnoise = nf; in rt2860_rx_intr()
1292 tap->wr_rate = 2; in rt2860_rx_intr()
1293 phy = le16toh(rxwi->phy); in rt2860_rx_intr()
1297 case 0: tap->wr_rate = 2; break; in rt2860_rx_intr()
1298 case 1: tap->wr_rate = 4; break; in rt2860_rx_intr()
1299 case 2: tap->wr_rate = 11; break; in rt2860_rx_intr()
1300 case 3: tap->wr_rate = 22; break; in rt2860_rx_intr()
1303 tap->wr_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; in rt2860_rx_intr()
1307 case 0: tap->wr_rate = 12; break; in rt2860_rx_intr()
1308 case 1: tap->wr_rate = 18; break; in rt2860_rx_intr()
1309 case 2: tap->wr_rate = 24; break; in rt2860_rx_intr()
1310 case 3: tap->wr_rate = 36; break; in rt2860_rx_intr()
1311 case 4: tap->wr_rate = 48; break; in rt2860_rx_intr()
1312 case 5: tap->wr_rate = 72; break; in rt2860_rx_intr()
1313 case 6: tap->wr_rate = 96; break; in rt2860_rx_intr()
1314 case 7: tap->wr_rate = 108; break; in rt2860_rx_intr()
1327 (void)ieee80211_input(ni, m, rssi - nf, nf); in rt2860_rx_intr()
1330 (void)ieee80211_input_all(ic, m, rssi - nf, nf); in rt2860_rx_intr()
1334 skip: rxd->sdl0 &= ~htole16(RT2860_RX_DDONE); in rt2860_rx_intr()
1336 bus_dmamap_sync(sc->rxq.desc_dmat, sc->rxq.desc_map, in rt2860_rx_intr()
1339 sc->rxq.cur = (sc->rxq.cur + 1) % RT2860_RX_RING_COUNT; in rt2860_rx_intr()
1344 (sc->rxq.cur - 1) % RT2860_RX_RING_COUNT); in rt2860_rx_intr()
1351 struct ieee80211com *ic = &sc->sc_ic; in rt2860_tbtt_intr()
1354 if (ic->ic_opmode == IEEE80211_M_HOSTAP) { in rt2860_tbtt_intr()
1356 if (ic->ic_dtim_count == 0) in rt2860_tbtt_intr()
1357 ic->ic_dtim_count = ic->ic_dtim_period - 1; in rt2860_tbtt_intr()
1359 ic->ic_dtim_count--; in rt2860_tbtt_intr()
1365 if (ic->ic_dtim_count == 0) in rt2860_tbtt_intr()
1370 if ((sc->sc_ic_flags ^ ic->ic_flags) & IEEE80211_F_USEPROT) { in rt2860_tbtt_intr()
1372 sc->sc_ic_flags = ic->ic_flags; in rt2860_tbtt_intr()
1380 struct ieee80211com *ic = &sc->sc_ic; in rt2860_gp_intr()
1381 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); in rt2860_gp_intr()
1383 DPRINTFN(2, ("GP timeout state=%d\n", vap->iv_state)); in rt2860_gp_intr()
1385 if (vap->iv_state == IEEE80211_S_RUN) in rt2860_gp_intr()
1423 rt2860_tx_intr(sc, 4); in rt2860_intr()
1452 struct ieee80211com *ic = &sc->sc_ic; in rt2860_tx()
1453 struct ieee80211vap *vap = ni->ni_vap; in rt2860_tx()
1454 struct rt2860_tx_ring *ring; in rt2860_tx() local
1459 const struct ieee80211_txparam *tp = ni->ni_txparms; in rt2860_tx()
1470 data = SLIST_FIRST(&sc->data_pool); in rt2860_tx()
1474 if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) { in rt2860_tx()
1486 type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK; in rt2860_tx()
1488 if (m->m_flags & M_EAPOL) { in rt2860_tx()
1489 rate = tp->mgmtrate; in rt2860_tx()
1490 } else if (IEEE80211_IS_MULTICAST(wh->i_addr1)) { in rt2860_tx()
1491 rate = tp->mcastrate; in rt2860_tx()
1492 } else if (tp->ucastrate != IEEE80211_FIXED_RATE_NONE) { in rt2860_tx()
1493 rate = tp->ucastrate; in rt2860_tx()
1496 rate = ni->ni_txrate; in rt2860_tx()
1502 qos = ((const struct ieee80211_qosframe *)wh)->i_qos[0]; in rt2860_tx()
1506 ring = &sc->txq[qid]; in rt2860_tx()
1507 ridx = ieee80211_legacy_rate_lookup(ic->ic_rt, rate); in rt2860_tx()
1513 txwi = data->txwi; in rt2860_tx()
1514 txwi->flags = 0; in rt2860_tx()
1515 /* let HW generate seq numbers for non-QoS frames */ in rt2860_tx()
1516 txwi->xflags = qos ? 0 : RT2860_TX_NSEQ; in rt2860_tx()
1518 txwi->wcid = IEEE80211_AID(ni->ni_associd); in rt2860_tx()
1520 txwi->wcid = 0xff; in rt2860_tx()
1521 txwi->len = htole16(m->m_pkthdr.len); in rt2860_tx()
1523 txwi->phy = htole16(RT2860_PHY_CCK); in rt2860_tx()
1525 (ic->ic_flags & IEEE80211_F_SHPREAMBLE)) in rt2860_tx()
1528 txwi->phy = htole16(RT2860_PHY_OFDM); in rt2860_tx()
1529 txwi->phy |= htole16(mcs); in rt2860_tx()
1532 * We store the MCS code into the driver-private PacketID field. in rt2860_tx()
1539 txwi->len |= htole16(pid << RT2860_TX_PID_SHIFT); in rt2860_tx()
1541 /* check if RTS/CTS or CTS-to-self protection is required */ in rt2860_tx()
1542 if (!IEEE80211_IS_MULTICAST(wh->i_addr1) && in rt2860_tx()
1543 (m->m_pkthdr.len + IEEE80211_CRC_LEN > vap->iv_rtsthreshold || in rt2860_tx()
1544 ((ic->ic_flags & IEEE80211_F_USEPROT) && in rt2860_tx()
1546 txwi->txop = RT2860_TX_TXOP_HT; in rt2860_tx()
1548 txwi->txop = RT2860_TX_TXOP_BACKOFF; in rt2860_tx()
1550 if (!IEEE80211_IS_MULTICAST(wh->i_addr1) && in rt2860_tx()
1553 txwi->xflags |= RT2860_TX_ACK; in rt2860_tx()
1555 if (ic->ic_flags & IEEE80211_F_SHPREAMBLE) in rt2860_tx()
1559 *(uint16_t *)wh->i_dur = htole16(dur); in rt2860_tx()
1564 txwi->flags |= RT2860_TX_TS; in rt2860_tx()
1567 struct rt2860_tx_radiotap_header *tap = &sc->sc_txtap; in rt2860_tx()
1569 tap->wt_flags = 0; in rt2860_tx()
1570 tap->wt_rate = rate; in rt2860_tx()
1572 tap->wt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; in rt2860_tx()
1583 error = bus_dmamap_load_mbuf_sg(sc->txwi_dmat, data->map, m, segs, in rt2860_tx()
1586 device_printf(sc->sc_dev, "can't map mbuf (error %d)\n", in rt2860_tx()
1595 if (ring->queued + ntxds >= RT2860_TX_RING_COUNT) { in rt2860_tx()
1597 bus_dmamap_unload(sc->txwi_dmat, data->map); in rt2860_tx()
1604 device_printf(sc->sc_dev, in rt2860_tx()
1611 error = bus_dmamap_load_mbuf_sg(sc->txwi_dmat, data->map, m, in rt2860_tx()
1614 device_printf(sc->sc_dev, "can't map mbuf (error %d)\n", in rt2860_tx()
1623 if (ring->queued + ntxds >= RT2860_TX_RING_COUNT) { in rt2860_tx()
1625 bus_dmamap_unload(sc->txwi_dmat, data->map); in rt2860_tx()
1634 txd = &ring->txd[ring->cur]; in rt2860_tx()
1635 txd->sdp0 = htole32(data->paddr); in rt2860_tx()
1636 txd->sdl0 = htole16(sizeof (struct rt2860_txwi) + pad); in rt2860_tx()
1637 txd->flags = qsel; in rt2860_tx()
1641 for (i = nsegs; i >= 2; i -= 2) { in rt2860_tx()
1642 txd->sdp1 = htole32(seg->ds_addr); in rt2860_tx()
1643 txd->sdl1 = htole16(seg->ds_len); in rt2860_tx()
1645 ring->cur = (ring->cur + 1) % RT2860_TX_RING_COUNT; in rt2860_tx()
1647 txd = &ring->txd[ring->cur]; in rt2860_tx()
1648 txd->sdp0 = htole32(seg->ds_addr); in rt2860_tx()
1649 txd->sdl0 = htole16(seg->ds_len); in rt2860_tx()
1650 txd->flags = qsel; in rt2860_tx()
1655 txd->sdp1 = htole32(seg->ds_addr); in rt2860_tx()
1656 txd->sdl1 = htole16(seg->ds_len | RT2860_TX_LS1); in rt2860_tx()
1658 txd->sdl0 |= htole16(RT2860_TX_LS0); in rt2860_tx()
1659 txd->sdl1 = 0; in rt2860_tx()
1663 SLIST_REMOVE_HEAD(&sc->data_pool, next); in rt2860_tx()
1664 data->m = m; in rt2860_tx()
1665 data->ni = ni; in rt2860_tx()
1666 ring->data[ring->cur] = data; in rt2860_tx()
1668 bus_dmamap_sync(sc->txwi_dmat, sc->txwi_map, BUS_DMASYNC_PREWRITE); in rt2860_tx()
1669 bus_dmamap_sync(sc->txwi_dmat, data->map, BUS_DMASYNC_PREWRITE); in rt2860_tx()
1670 bus_dmamap_sync(ring->desc_dmat, ring->desc_map, BUS_DMASYNC_PREWRITE); in rt2860_tx()
1672 DPRINTFN(4, ("sending frame qid=%d wcid=%d nsegs=%d ridx=%d\n", in rt2860_tx()
1673 qid, txwi->wcid, nsegs, ridx)); in rt2860_tx()
1675 ring->cur = (ring->cur + 1) % RT2860_TX_RING_COUNT; in rt2860_tx()
1676 ring->queued += ntxds; in rt2860_tx()
1677 if (ring->queued >= RT2860_TX_RING_COUNT) in rt2860_tx()
1678 sc->qfullmsk |= 1 << qid; in rt2860_tx()
1681 RAL_WRITE(sc, RT2860_TX_CTX_IDX(qid), ring->cur); in rt2860_tx()
1690 struct ieee80211com *ic = ni->ni_ic; in rt2860_raw_xmit()
1691 struct rt2860_softc *sc = ic->ic_softc; in rt2860_raw_xmit()
1697 if (!(sc->sc_flags & RT2860_RUNNING)) { in rt2860_raw_xmit()
1715 sc->sc_tx_timer = 5; in rt2860_raw_xmit()
1724 struct ieee80211com *ic = &sc->sc_ic; in rt2860_tx_raw()
1725 struct ieee80211vap *vap = ni->ni_vap; in rt2860_tx_raw()
1726 struct rt2860_tx_ring *ring; in rt2860_tx_raw() local
1740 data = SLIST_FIRST(&sc->data_pool); in rt2860_tx_raw()
1746 rate = params->ibp_rate0; in rt2860_tx_raw()
1747 ridx = ieee80211_legacy_rate_lookup(ic->ic_rt, in rt2860_tx_raw()
1749 if (ridx == (uint8_t)-1) { in rt2860_tx_raw()
1755 qid = params->ibp_pri & 3; in rt2860_tx_raw()
1756 ring = &sc->txq[qid]; in rt2860_tx_raw()
1762 txwi = data->txwi; in rt2860_tx_raw()
1763 txwi->flags = 0; in rt2860_tx_raw()
1764 /* let HW generate seq numbers for non-QoS frames */ in rt2860_tx_raw()
1765 txwi->xflags = params->ibp_pri & 3 ? 0 : RT2860_TX_NSEQ; in rt2860_tx_raw()
1766 txwi->wcid = 0xff; in rt2860_tx_raw()
1767 txwi->len = htole16(m->m_pkthdr.len); in rt2860_tx_raw()
1769 txwi->phy = htole16(RT2860_PHY_CCK); in rt2860_tx_raw()
1771 (ic->ic_flags & IEEE80211_F_SHPREAMBLE)) in rt2860_tx_raw()
1774 txwi->phy = htole16(RT2860_PHY_OFDM); in rt2860_tx_raw()
1775 txwi->phy |= htole16(mcs); in rt2860_tx_raw()
1778 * We store the MCS code into the driver-private PacketID field. in rt2860_tx_raw()
1785 txwi->len |= htole16(pid << RT2860_TX_PID_SHIFT); in rt2860_tx_raw()
1787 /* check if RTS/CTS or CTS-to-self protection is required */ in rt2860_tx_raw()
1788 if (params->ibp_flags & IEEE80211_BPF_RTS || in rt2860_tx_raw()
1789 params->ibp_flags & IEEE80211_BPF_CTS) in rt2860_tx_raw()
1790 txwi->txop = RT2860_TX_TXOP_HT; in rt2860_tx_raw()
1792 txwi->txop = RT2860_TX_TXOP_BACKOFF; in rt2860_tx_raw()
1793 if ((params->ibp_flags & IEEE80211_BPF_NOACK) == 0) { in rt2860_tx_raw()
1794 txwi->xflags |= RT2860_TX_ACK; in rt2860_tx_raw()
1796 if (ic->ic_flags & IEEE80211_F_SHPREAMBLE) in rt2860_tx_raw()
1800 *(uint16_t *)wh->i_dur = htole16(dur); in rt2860_tx_raw()
1805 txwi->flags |= RT2860_TX_TS; in rt2860_tx_raw()
1808 struct rt2860_tx_radiotap_header *tap = &sc->sc_txtap; in rt2860_tx_raw()
1810 tap->wt_flags = 0; in rt2860_tx_raw()
1811 tap->wt_rate = rate; in rt2860_tx_raw()
1813 tap->wt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; in rt2860_tx_raw()
1824 error = bus_dmamap_load_mbuf_sg(sc->txwi_dmat, data->map, m, segs, in rt2860_tx_raw()
1827 device_printf(sc->sc_dev, "can't map mbuf (error %d)\n", in rt2860_tx_raw()
1836 if (ring->queued + ntxds >= RT2860_TX_RING_COUNT) { in rt2860_tx_raw()
1838 bus_dmamap_unload(sc->txwi_dmat, data->map); in rt2860_tx_raw()
1845 device_printf(sc->sc_dev, in rt2860_tx_raw()
1852 error = bus_dmamap_load_mbuf_sg(sc->txwi_dmat, data->map, m, in rt2860_tx_raw()
1855 device_printf(sc->sc_dev, "can't map mbuf (error %d)\n", in rt2860_tx_raw()
1864 if (ring->queued + ntxds >= RT2860_TX_RING_COUNT) { in rt2860_tx_raw()
1866 bus_dmamap_unload(sc->txwi_dmat, data->map); in rt2860_tx_raw()
1875 txd = &ring->txd[ring->cur]; in rt2860_tx_raw()
1876 txd->sdp0 = htole32(data->paddr); in rt2860_tx_raw()
1877 txd->sdl0 = htole16(sizeof (struct rt2860_txwi) + pad); in rt2860_tx_raw()
1878 txd->flags = qsel; in rt2860_tx_raw()
1882 for (i = nsegs; i >= 2; i -= 2) { in rt2860_tx_raw()
1883 txd->sdp1 = htole32(seg->ds_addr); in rt2860_tx_raw()
1884 txd->sdl1 = htole16(seg->ds_len); in rt2860_tx_raw()
1886 ring->cur = (ring->cur + 1) % RT2860_TX_RING_COUNT; in rt2860_tx_raw()
1888 txd = &ring->txd[ring->cur]; in rt2860_tx_raw()
1889 txd->sdp0 = htole32(seg->ds_addr); in rt2860_tx_raw()
1890 txd->sdl0 = htole16(seg->ds_len); in rt2860_tx_raw()
1891 txd->flags = qsel; in rt2860_tx_raw()
1896 txd->sdp1 = htole32(seg->ds_addr); in rt2860_tx_raw()
1897 txd->sdl1 = htole16(seg->ds_len | RT2860_TX_LS1); in rt2860_tx_raw()
1899 txd->sdl0 |= htole16(RT2860_TX_LS0); in rt2860_tx_raw()
1900 txd->sdl1 = 0; in rt2860_tx_raw()
1904 SLIST_REMOVE_HEAD(&sc->data_pool, next); in rt2860_tx_raw()
1905 data->m = m; in rt2860_tx_raw()
1906 data->ni = ni; in rt2860_tx_raw()
1907 ring->data[ring->cur] = data; in rt2860_tx_raw()
1909 bus_dmamap_sync(sc->txwi_dmat, sc->txwi_map, BUS_DMASYNC_PREWRITE); in rt2860_tx_raw()
1910 bus_dmamap_sync(sc->txwi_dmat, data->map, BUS_DMASYNC_PREWRITE); in rt2860_tx_raw()
1911 bus_dmamap_sync(ring->desc_dmat, ring->desc_map, BUS_DMASYNC_PREWRITE); in rt2860_tx_raw()
1913 DPRINTFN(4, ("sending frame qid=%d wcid=%d nsegs=%d ridx=%d\n", in rt2860_tx_raw()
1914 qid, txwi->wcid, nsegs, ridx)); in rt2860_tx_raw()
1916 ring->cur = (ring->cur + 1) % RT2860_TX_RING_COUNT; in rt2860_tx_raw()
1917 ring->queued += ntxds; in rt2860_tx_raw()
1918 if (ring->queued >= RT2860_TX_RING_COUNT) in rt2860_tx_raw()
1919 sc->qfullmsk |= 1 << qid; in rt2860_tx_raw()
1922 RAL_WRITE(sc, RT2860_TX_CTX_IDX(qid), ring->cur); in rt2860_tx_raw()
1930 struct rt2860_softc *sc = ic->ic_softc; in rt2860_transmit()
1934 if ((sc->sc_flags & RT2860_RUNNING) == 0) { in rt2860_transmit()
1938 error = mbufq_enqueue(&sc->sc_snd, m); in rt2860_transmit()
1957 if ((sc->sc_flags & RT2860_RUNNING) == 0) in rt2860_start()
1960 while (!SLIST_EMPTY(&sc->data_pool) && sc->qfullmsk == 0 && in rt2860_start()
1961 (m = mbufq_dequeue(&sc->sc_snd)) != NULL) { in rt2860_start()
1962 ni = (struct ieee80211_node *)m->m_pkthdr.rcvif; in rt2860_start()
1964 if_inc_counter(ni->ni_vap->iv_ifp, in rt2860_start()
1969 sc->sc_tx_timer = 5; in rt2860_start()
1980 KASSERT(sc->sc_flags & RT2860_RUNNING, ("not running")); in rt2860_watchdog()
1982 if (sc->sc_invalid) /* card ejected */ in rt2860_watchdog()
1985 if (sc->sc_tx_timer > 0 && --sc->sc_tx_timer == 0) { in rt2860_watchdog()
1986 device_printf(sc->sc_dev, "device timeout\n"); in rt2860_watchdog()
1989 counter_u64_add(sc->sc_ic.ic_oerrors, 1); in rt2860_watchdog()
1992 callout_reset(&sc->watchdog_ch, hz, rt2860_watchdog, sc); in rt2860_watchdog()
1998 struct rt2860_softc *sc = ic->ic_softc; in rt2860_parent()
2002 if (ic->ic_nrunning> 0) { in rt2860_parent()
2003 if (!(sc->sc_flags & RT2860_RUNNING)) { in rt2860_parent()
2008 } else if (sc->sc_flags & RT2860_RUNNING) in rt2860_parent()
2031 device_printf(sc->sc_dev, in rt2860_mcu_bbp_write()
2056 device_printf(sc->sc_dev, in rt2860_mcu_bbp_read()
2074 device_printf(sc->sc_dev, "could not read from BBP through MCU\n"); in rt2860_mcu_bbp_read()
2080 * Write to one of the 4 programmable 24-bit RF registers.
2094 device_printf(sc->sc_dev, "could not write to RF\n"); in rt2860_rf_write()
2098 /* RF registers are 24-bit on the RT2860 */ in rt2860_rf_write()
2116 device_printf(sc->sc_dev, "could not read RF register\n"); in rt3090_rf_read()
2129 device_printf(sc->sc_dev, "could not read RF register\n"); in rt3090_rf_read()
2147 device_printf(sc->sc_dev, "could not write to RF\n"); in rt3090_rf_write()
2184 for (slot = 0; slot < 4; slot++, tmp >>= 8) in rt2860_mcu_cmd()
2187 if (slot < 4) in rt2860_mcu_cmd()
2214 OFDM(6) << 28 | /* 54->48 */ in rt2860_enable_mrr()
2215 OFDM(5) << 24 | /* 48->36 */ in rt2860_enable_mrr()
2216 OFDM(4) << 20 | /* 36->24 */ in rt2860_enable_mrr()
2217 OFDM(3) << 16 | /* 24->18 */ in rt2860_enable_mrr()
2218 OFDM(2) << 12 | /* 18->12 */ in rt2860_enable_mrr()
2219 OFDM(1) << 8 | /* 12-> 9 */ in rt2860_enable_mrr()
2220 OFDM(0) << 4 | /* 9-> 6 */ in rt2860_enable_mrr()
2221 OFDM(0)); /* 6-> 6 */ in rt2860_enable_mrr()
2224 CCK(2) << 12 | /* 11->5.5 */ in rt2860_enable_mrr()
2225 CCK(1) << 8 | /* 5.5-> 2 */ in rt2860_enable_mrr()
2226 CCK(0) << 4 | /* 2-> 1 */ in rt2860_enable_mrr()
2227 CCK(0)); /* 1-> 1 */ in rt2860_enable_mrr()
2235 struct ieee80211com *ic = &sc->sc_ic; in rt2860_set_txpreamble()
2240 if (ic->ic_flags & IEEE80211_F_SHPREAMBLE) in rt2860_set_txpreamble()
2249 struct ieee80211com *ic = &sc->sc_ic; in rt2860_set_basicrates()
2254 for (i = 0; i < rs->rs_nrates; i++) { in rt2860_set_basicrates()
2255 rate = rs->rs_rates[i]; in rt2860_set_basicrates()
2260 mask |= 1 << ieee80211_legacy_rate_lookup(ic->ic_rt, in rt2860_set_basicrates()
2270 struct rt2860_softc *sc = ic->ic_softc; in rt2860_scan_start()
2283 struct rt2860_softc *sc = ic->ic_softc; in rt2860_scan_end()
2284 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); in rt2860_scan_end()
2286 if (vap->iv_state == IEEE80211_S_RUN) { in rt2860_scan_end()
2296 struct rt2860_softc *sc = ic->ic_softc; in rt2860_getradiocaps()
2304 if (sc->rf_rev == RT2860_RF_2750 || sc->rf_rev == RT2860_RF_2850) { in rt2860_getradiocaps()
2314 struct rt2860_softc *sc = ic->ic_softc; in rt2860_set_channel()
2317 rt2860_switch_chan(sc, ic->ic_curchan); in rt2860_set_channel()
2327 rt2860_mcu_bbp_write(sc, 62, 0x37 - sc->lna[group]); in rt2860_select_chan_group()
2328 rt2860_mcu_bbp_write(sc, 63, 0x37 - sc->lna[group]); in rt2860_select_chan_group()
2329 rt2860_mcu_bbp_write(sc, 64, 0x37 - sc->lna[group]); in rt2860_select_chan_group()
2333 if (sc->ext_2ghz_lna) { in rt2860_select_chan_group()
2341 if (sc->ext_5ghz_lna) { in rt2860_select_chan_group()
2357 if (sc->nrxchains > 1) in rt2860_select_chan_group()
2359 if (sc->mac_ver == 0x3593 && sc->nrxchains > 2) in rt2860_select_chan_group()
2363 if (sc->ntxchains > 1) in rt2860_select_chan_group()
2365 if (sc->mac_ver == 0x3593 && sc->ntxchains > 2) in rt2860_select_chan_group()
2369 if (sc->ntxchains > 1) in rt2860_select_chan_group()
2371 if (sc->mac_ver == 0x3593 && sc->ntxchains > 2) in rt2860_select_chan_group()
2376 if (sc->mac_ver == 0x3593) { in rt2860_select_chan_group()
2378 if (sc->sc_flags & RT2860_PCIE) { in rt2860_select_chan_group()
2393 if (sc->mac_ver >= 0x3071) in rt2860_select_chan_group()
2394 agc = 0x1c + sc->lna[0] * 2; in rt2860_select_chan_group()
2396 agc = 0x2e + sc->lna[0]; in rt2860_select_chan_group()
2398 agc = 0x32 + (sc->lna[group] * 5) / 3; in rt2860_select_chan_group()
2417 if (sc->ntxchains == 1) in rt2860_set_chan()
2419 if (sc->nrxchains == 1) in rt2860_set_chan()
2420 r2 |= 1 << 15 | 1 << 4; /* 1R: disable Rx chains 2 & 3 */ in rt2860_set_chan()
2421 else if (sc->nrxchains == 2) in rt2860_set_chan()
2422 r2 |= 1 << 4; /* 2R: disable Rx chain 3 */ in rt2860_set_chan()
2425 txpow1 = sc->txpow1[i]; in rt2860_set_chan()
2426 txpow2 = sc->txpow2[i]; in rt2860_set_chan()
2438 r4 = rfprog[i].r4 | sc->freq << 13 | txpow2 << 4; in rt2860_set_chan()
2474 txpow1 = sc->txpow1[i]; in rt3090_set_chan()
2475 txpow2 = sc->txpow2[i]; in rt3090_set_chan()
2497 if (sc->ntxchains == 1) in rt3090_set_chan()
2499 else if (sc->ntxchains == 2) in rt3090_set_chan()
2501 if (sc->nrxchains == 1) in rt3090_set_chan()
2503 else if (sc->nrxchains == 2) in rt3090_set_chan()
2509 rf = (rf & ~0x7f) | sc->freq; in rt3090_set_chan()
2514 rf = (rf & ~0x3f) | sc->rf24_20mhz; in rt3090_set_chan()
2517 rf = (rf & ~0x3f) | sc->rf24_20mhz; in rt3090_set_chan()
2539 txpow1 = sc->txpow1[i]; in rt5390_set_chan()
2540 txpow2 = sc->txpow2[i]; in rt5390_set_chan()
2554 if (sc->mac_ver == 0x5392) { in rt5390_set_chan()
2565 if (sc->mac_ver == 0x5392) in rt5390_set_chan()
2576 rf = (rf & ~0x7f) | (sc->freq & 0x7f); in rt5390_set_chan()
2581 if (sc->mac_ver == 0x5390) { in rt5390_set_chan()
2582 if (chan <= 4) in rt5390_set_chan()
2598 else if (chan >= 4 && chan <= 6) in rt5390_set_chan()
2610 h20mhz = (sc->rf24_20mhz & 0x20) >> 5; in rt5390_set_chan()
2641 if (sc->patch_dac && sc->mac_rev < 0x0211) in rt3090_rf_init()
2663 if (sc->mac_ver != 0x3593) { in rt3090_rf_init()
2665 sc->rf24_20mhz = 0x1f; /* default value */ in rt3090_rf_init()
2666 rt3090_filter_calib(sc, 0x07, 0x16, &sc->rf24_20mhz); in rt3090_rf_init()
2669 bbp = rt2860_mcu_bbp_read(sc, 4); in rt3090_rf_init()
2670 rt2860_mcu_bbp_write(sc, 4, (bbp & ~0x08) | 0x10); in rt3090_rf_init()
2675 sc->rf24_40mhz = 0x2f; /* default value */ in rt3090_rf_init()
2676 rt3090_filter_calib(sc, 0x27, 0x19, &sc->rf24_40mhz); in rt3090_rf_init()
2679 bbp = rt2860_mcu_bbp_read(sc, 4); in rt3090_rf_init()
2680 rt2860_mcu_bbp_write(sc, 4, bbp & ~0x18); in rt3090_rf_init()
2682 if (sc->mac_rev < 0x0211) in rt3090_rf_init()
2688 if (sc->rf_rev == RT3070_RF_3020) in rt3090_rf_init()
2692 if (sc->mac_ver == 0x3593) { in rt3090_rf_init()
2693 if (sc->ntxchains == 1) in rt3090_rf_init()
2695 else if (sc->ntxchains == 2) in rt3090_rf_init()
2697 if (sc->nrxchains == 1) in rt3090_rf_init()
2699 else if (sc->nrxchains == 2) in rt3090_rf_init()
2702 if (sc->ntxchains == 1) in rt3090_rf_init()
2704 if (sc->nrxchains == 1) in rt3090_rf_init()
2719 if (sc->mac_rev >= 0x0211 && !sc->ext_2ghz_lna) in rt3090_rf_init()
2721 if (sc->txmixgain_2ghz >= 2) in rt3090_rf_init()
2722 rf = (rf & ~0x7) | sc->txmixgain_2ghz; in rt3090_rf_init()
2747 if (sc->mac_ver == 0x5392) { in rt5390_rf_init()
2759 sc->rf24_20mhz = 0x1f; in rt5390_rf_init()
2760 sc->rf24_40mhz = 0x2f; in rt5390_rf_init()
2762 if (sc->mac_rev < 0x0211) in rt5390_rf_init()
2771 if (sc->mac_ver == 0x5390) in rt5390_rf_init()
2780 if (sc->mac_rev >= 0x0211) in rt5390_rf_init()
2784 if (sc->ntxchains == 1) in rt5390_rf_init()
2786 if (sc->nrxchains == 1) in rt5390_rf_init()
2795 rt2860_mcu_bbp_write(sc, 4, in rt5390_rf_init()
2796 rt2860_mcu_bbp_read(sc, 4) | RT5390_MAC_IF_CTRL); in rt5390_rf_init()
2809 if (sc->mac_ver == 0x3593) { in rt3090_rf_wakeup()
2858 if (sc->mac_rev < 0x0211) in rt3090_rf_wakeup()
2862 if (sc->patch_dac && sc->mac_rev < 0x0211) { in rt3090_rf_wakeup()
2878 if (sc->mac_ver == 0x5392) in rt5390_rf_wakeup()
2884 if (sc->mac_ver == 0x5390) in rt5390_rf_wakeup()
2898 if (sc->patch_dac && sc->mac_rev < 0x0211) { in rt5390_rf_wakeup()
2945 delta = bbp55_pb - bbp55_sb; in rt3090_filter_calib()
2955 rf24--; /* backtrack */ in rt3090_filter_calib()
2976 if (sc->mac_rev >= 0x0211) { in rt3090_rf_setup()
2986 if (sc->mac_rev < 0x0211) { in rt3090_rf_setup()
2988 sc->patch_dac ? 0x2c : 0x0f); in rt3090_rf_setup()
2993 if (sc->mac_ver < 0x5390) { in rt3090_rf_setup()
2995 if (sc->rf[i].reg == 0 || sc->rf[i].reg == 0xff) in rt3090_rf_setup()
2997 rt3090_rf_write(sc, sc->rf[i].reg, sc->rf[i].val); in rt3090_rf_setup()
3006 which | (sc->leds & 0x7f), 0); in rt2860_set_leds()
3010 * Hardware has a general-purpose programmable timer interrupt that can
3041 bssid[4] | bssid[5] << 8); in rt2860_set_bssid()
3050 addr[4] | addr[5] << 8 | 0xff << 16); in rt2860_set_macaddr()
3056 struct rt2860_softc *sc = ic->ic_softc; in rt2860_updateslot()
3068 struct ieee80211com *ic = &sc->sc_ic; in rt2860_updateprot()
3073 tmp |= IEEE80211_IS_CHAN_5GHZ(ic->ic_curchan) ? in rt2860_updateprot()
3080 if (ic->ic_flags & IEEE80211_F_USEPROT) { in rt2860_updateprot()
3081 if (ic->ic_protmode == IEEE80211_PROT_RTSCTS) in rt2860_updateprot()
3083 else if (ic->ic_protmode == IEEE80211_PROT_CTSONLY) in rt2860_updateprot()
3092 struct rt2860_softc *sc = ic->ic_softc; in rt2860_update_promisc()
3097 if (ic->ic_promisc == 0) in rt2860_update_promisc()
3105 struct rt2860_softc *sc = ic->ic_softc; in rt2860_updateedca()
3127 wmep[WME_AC_BK].wmep_aifsn << 4 | in rt2860_updateedca()
3132 wmep[WME_AC_BK].wmep_logcwmin << 4 | in rt2860_updateedca()
3137 wmep[WME_AC_BK].wmep_logcwmax << 4 | in rt2860_updateedca()
3154 struct rt2860_softc *sc = ic->ic_softc; in rt2860_set_key()
3160 if ((ic->ic_if.if_flags & (IFF_UP | IFF_RUNNING)) != in rt2860_set_key()
3165 switch (k->k_cipher) { in rt2860_set_key()
3182 if (k->k_flags & IEEE80211_KEY_GROUP) { in rt2860_set_key()
3184 base = RT2860_SKEY(0, k->k_id); in rt2860_set_key()
3186 wcid = ((struct rt2860_node *)ni)->wcid; in rt2860_set_key()
3190 if (k->k_cipher == IEEE80211_CIPHER_TKIP) { in rt2860_set_key()
3191 RAL_WRITE_REGION_1(sc, base, k->k_key, 16); in rt2860_set_key()
3193 if (ic->ic_opmode == IEEE80211_M_HOSTAP) { in rt2860_set_key()
3194 RAL_WRITE_REGION_1(sc, base + 16, &k->k_key[16], 8); in rt2860_set_key()
3195 RAL_WRITE_REGION_1(sc, base + 24, &k->k_key[24], 8); in rt2860_set_key()
3199 RAL_WRITE_REGION_1(sc, base + 16, &k->k_key[24], 8); in rt2860_set_key()
3200 RAL_WRITE_REGION_1(sc, base + 24, &k->k_key[16], 8); in rt2860_set_key()
3203 RAL_WRITE_REGION_1(sc, base, k->k_key, k->k_len); in rt2860_set_key()
3205 if (!(k->k_flags & IEEE80211_KEY_GROUP) || in rt2860_set_key()
3206 (k->k_flags & IEEE80211_KEY_TX)) { in rt2860_set_key()
3208 if (k->k_cipher == IEEE80211_CIPHER_WEP40 || in rt2860_set_key()
3209 k->k_cipher == IEEE80211_CIPHER_WEP104) { in rt2860_set_key()
3217 iv[3] = k->k_id << 6; in rt2860_set_key()
3218 iv[4] = iv[5] = iv[6] = iv[7] = 0; in rt2860_set_key()
3220 if (k->k_cipher == IEEE80211_CIPHER_TKIP) { in rt2860_set_key()
3221 iv[0] = k->k_tsc >> 8; in rt2860_set_key()
3223 iv[2] = k->k_tsc; in rt2860_set_key()
3225 iv[0] = k->k_tsc; in rt2860_set_key()
3226 iv[1] = k->k_tsc >> 8; in rt2860_set_key()
3229 iv[3] = k->k_id << 6 | IEEE80211_WEP_EXTIV; in rt2860_set_key()
3230 iv[4] = k->k_tsc >> 16; in rt2860_set_key()
3231 iv[5] = k->k_tsc >> 24; in rt2860_set_key()
3232 iv[6] = k->k_tsc >> 32; in rt2860_set_key()
3233 iv[7] = k->k_tsc >> 40; in rt2860_set_key()
3238 if (k->k_flags & IEEE80211_KEY_GROUP) { in rt2860_set_key()
3241 attr &= ~(0xf << (k->k_id * 4)); in rt2860_set_key()
3242 attr |= mode << (k->k_id * 4); in rt2860_set_key()
3257 struct rt2860_softc *sc = ic->ic_softc; in rt2860_delete_key()
3261 if (k->k_flags & IEEE80211_KEY_GROUP) { in rt2860_delete_key()
3264 attr &= ~(0xf << (k->k_id * 4)); in rt2860_delete_key()
3269 wcid = ((struct rt2860_node *)ni)->wcid; in rt2860_delete_key()
3280 struct ieee80211com *ic = &sc->sc_ic; in rt2860_rssi2dbm()
3281 struct ieee80211_channel *c = ic->ic_curchan; in rt2860_rssi2dbm()
3286 delta = sc->rssi_5ghz[rxchain]; in rt2860_rssi2dbm()
3290 delta -= sc->lna[1]; in rt2860_rssi2dbm()
3292 delta -= sc->lna[2]; in rt2860_rssi2dbm()
3294 delta -= sc->lna[3]; in rt2860_rssi2dbm()
3296 delta = sc->rssi_2ghz[rxchain] - sc->lna[0]; in rt2860_rssi2dbm()
3298 return -12 - delta - rssi; in rt2860_rssi2dbm()
3302 * Add `delta' (signed) to each 4-bit sub-word of a 32-bit word.
3303 * Used to adjust per-rate Tx power registers.
3317 b32 = b32 >> 4 | (uint32_t)b4 << 28; in b4inc()
3352 sc->sc_srom_read = rt2860_eeprom_read_2; in rt2860_read_eeprom()
3353 if (sc->mac_ver >= 0x3071) { in rt2860_read_eeprom()
3357 sc->sc_srom_read = rt3090_efuse_read_2; in rt2860_read_eeprom()
3374 macaddr[4] = val & 0xff; in rt2860_read_eeprom()
3386 sc->bbp[i].val = val & 0xff; in rt2860_read_eeprom()
3387 sc->bbp[i].reg = val >> 8; in rt2860_read_eeprom()
3388 DPRINTF(("BBP%d=0x%02x\n", sc->bbp[i].reg, sc->bbp[i].val)); in rt2860_read_eeprom()
3390 if (sc->mac_ver >= 0x3071) { in rt2860_read_eeprom()
3394 sc->rf[i].val = val & 0xff; in rt2860_read_eeprom()
3395 sc->rf[i].reg = val >> 8; in rt2860_read_eeprom()
3396 DPRINTF(("RF%d=0x%02x\n", sc->rf[i].reg, in rt2860_read_eeprom()
3397 sc->rf[i].val)); in rt2860_read_eeprom()
3403 sc->freq = ((val & 0xff) != 0xff) ? val & 0xff : 0; in rt2860_read_eeprom()
3404 DPRINTF(("EEPROM freq offset %d\n", sc->freq & 0xff)); in rt2860_read_eeprom()
3407 sc->leds = val >> 8; in rt2860_read_eeprom()
3408 sc->led[0] = rt2860_srom_read(sc, RT2860_EEPROM_LED1); in rt2860_read_eeprom()
3409 sc->led[1] = rt2860_srom_read(sc, RT2860_EEPROM_LED2); in rt2860_read_eeprom()
3410 sc->led[2] = rt2860_srom_read(sc, RT2860_EEPROM_LED3); in rt2860_read_eeprom()
3413 sc->leds = 0x01; in rt2860_read_eeprom()
3414 sc->led[0] = 0x5555; in rt2860_read_eeprom()
3415 sc->led[1] = 0x2221; in rt2860_read_eeprom()
3416 sc->led[2] = 0xa9f8; in rt2860_read_eeprom()
3419 sc->leds, sc->led[0], sc->led[1], sc->led[2])); in rt2860_read_eeprom()
3423 if (sc->mac_ver >= 0x5390) in rt2860_read_eeprom()
3424 sc->rf_rev = rt2860_srom_read(sc, RT2860_EEPROM_CHIPID); in rt2860_read_eeprom()
3426 sc->rf_rev = (val >> 8) & 0xf; in rt2860_read_eeprom()
3427 sc->ntxchains = (val >> 4) & 0xf; in rt2860_read_eeprom()
3428 sc->nrxchains = val & 0xf; in rt2860_read_eeprom()
3430 sc->rf_rev, sc->ntxchains, sc->nrxchains)); in rt2860_read_eeprom()
3437 sc->patch_dac = (val >> 15) & 1; in rt2860_read_eeprom()
3439 sc->ext_5ghz_lna = (val >> 3) & 1; in rt2860_read_eeprom()
3440 sc->ext_2ghz_lna = (val >> 2) & 1; in rt2860_read_eeprom()
3442 sc->calib_2ghz = sc->calib_5ghz = 0; /* XXX (val >> 1) & 1 */ in rt2860_read_eeprom()
3444 sc->rfswitch = val & 1; in rt2860_read_eeprom()
3446 if (sc->sc_flags & RT2860_ADVANCED_PS) { in rt2860_read_eeprom()
3450 sc->pslevel = val & 0x3; in rt2860_read_eeprom()
3453 sc->pslevel = MIN(sc->pslevel, 1); in rt2860_read_eeprom()
3454 DPRINTF(("EEPROM PCIe PS Level=%d\n", sc->pslevel)); in rt2860_read_eeprom()
3462 sc->txpow1[i + 0] = (int8_t)(val & 0xff); in rt2860_read_eeprom()
3463 sc->txpow1[i + 1] = (int8_t)(val >> 8); in rt2860_read_eeprom()
3465 if (sc->mac_ver != 0x5390) { in rt2860_read_eeprom()
3468 sc->txpow2[i + 0] = (int8_t)(val & 0xff); in rt2860_read_eeprom()
3469 sc->txpow2[i + 1] = (int8_t)(val >> 8); in rt2860_read_eeprom()
3474 if (sc->txpow1[i] < 0 || in rt2860_read_eeprom()
3475 sc->txpow1[i] > ((sc->mac_ver >= 0x5390) ? 39 : 31)) in rt2860_read_eeprom()
3476 sc->txpow1[i] = 5; in rt2860_read_eeprom()
3477 if (sc->mac_ver != 0x5390) { in rt2860_read_eeprom()
3478 if (sc->txpow2[i] < 0 || in rt2860_read_eeprom()
3479 sc->txpow2[i] > ((sc->mac_ver == 0x5392) ? 39 : 31)) in rt2860_read_eeprom()
3480 sc->txpow2[i] = 5; in rt2860_read_eeprom()
3483 rt2860_rf2850[i].chan, sc->txpow1[i], sc->txpow2[i])); in rt2860_read_eeprom()
3489 sc->txpow1[i + 14] = (int8_t)(val & 0xff); in rt2860_read_eeprom()
3490 sc->txpow1[i + 15] = (int8_t)(val >> 8); in rt2860_read_eeprom()
3494 sc->txpow2[i + 14] = (int8_t)(val & 0xff); in rt2860_read_eeprom()
3495 sc->txpow2[i + 15] = (int8_t)(val >> 8); in rt2860_read_eeprom()
3499 if (sc->txpow1[14 + i] < -7 || sc->txpow1[14 + i] > 15) in rt2860_read_eeprom()
3500 sc->txpow1[14 + i] = 5; in rt2860_read_eeprom()
3501 if (sc->txpow2[14 + i] < -7 || sc->txpow2[14 + i] > 15) in rt2860_read_eeprom()
3502 sc->txpow2[14 + i] = 5; in rt2860_read_eeprom()
3504 rt2860_rf2850[14 + i].chan, sc->txpow1[14 + i], in rt2860_read_eeprom()
3505 sc->txpow2[14 + i])); in rt2860_read_eeprom()
3514 delta_2ghz = -delta_2ghz; in rt2860_read_eeprom()
3520 delta_5ghz = -delta_5ghz; in rt2860_read_eeprom()
3533 sc->txpow20mhz[ridx] = reg; in rt2860_read_eeprom()
3534 sc->txpow40mhz_2ghz[ridx] = b4inc(reg, delta_2ghz); in rt2860_read_eeprom()
3535 sc->txpow40mhz_5ghz[ridx] = b4inc(reg, delta_5ghz); in rt2860_read_eeprom()
3538 "40MHz/5GHz=0x%08x\n", ridx, sc->txpow20mhz[ridx], in rt2860_read_eeprom()
3539 sc->txpow40mhz_2ghz[ridx], sc->txpow40mhz_5ghz[ridx])); in rt2860_read_eeprom()
3542 /* read factory-calibrated samples for temperature compensation */ in rt2860_read_eeprom()
3544 sc->tssi_2ghz[0] = val & 0xff; /* [-4] */ in rt2860_read_eeprom()
3545 sc->tssi_2ghz[1] = val >> 8; /* [-3] */ in rt2860_read_eeprom()
3547 sc->tssi_2ghz[2] = val & 0xff; /* [-2] */ in rt2860_read_eeprom()
3548 sc->tssi_2ghz[3] = val >> 8; /* [-1] */ in rt2860_read_eeprom()
3550 sc->tssi_2ghz[4] = val & 0xff; /* [+0] */ in rt2860_read_eeprom()
3551 sc->tssi_2ghz[5] = val >> 8; /* [+1] */ in rt2860_read_eeprom()
3553 sc->tssi_2ghz[6] = val & 0xff; /* [+2] */ in rt2860_read_eeprom()
3554 sc->tssi_2ghz[7] = val >> 8; /* [+3] */ in rt2860_read_eeprom()
3556 sc->tssi_2ghz[8] = val & 0xff; /* [+4] */ in rt2860_read_eeprom()
3557 sc->step_2ghz = val >> 8; in rt2860_read_eeprom()
3559 "0x%02x 0x%02x step=%d\n", sc->tssi_2ghz[0], sc->tssi_2ghz[1], in rt2860_read_eeprom()
3560 sc->tssi_2ghz[2], sc->tssi_2ghz[3], sc->tssi_2ghz[4], in rt2860_read_eeprom()
3561 sc->tssi_2ghz[5], sc->tssi_2ghz[6], sc->tssi_2ghz[7], in rt2860_read_eeprom()
3562 sc->tssi_2ghz[8], sc->step_2ghz)); in rt2860_read_eeprom()
3564 if (sc->tssi_2ghz[4] == 0xff) in rt2860_read_eeprom()
3565 sc->calib_2ghz = 0; in rt2860_read_eeprom()
3568 sc->tssi_5ghz[0] = val & 0xff; /* [-4] */ in rt2860_read_eeprom()
3569 sc->tssi_5ghz[1] = val >> 8; /* [-3] */ in rt2860_read_eeprom()
3571 sc->tssi_5ghz[2] = val & 0xff; /* [-2] */ in rt2860_read_eeprom()
3572 sc->tssi_5ghz[3] = val >> 8; /* [-1] */ in rt2860_read_eeprom()
3574 sc->tssi_5ghz[4] = val & 0xff; /* [+0] */ in rt2860_read_eeprom()
3575 sc->tssi_5ghz[5] = val >> 8; /* [+1] */ in rt2860_read_eeprom()
3577 sc->tssi_5ghz[6] = val & 0xff; /* [+2] */ in rt2860_read_eeprom()
3578 sc->tssi_5ghz[7] = val >> 8; /* [+3] */ in rt2860_read_eeprom()
3580 sc->tssi_5ghz[8] = val & 0xff; /* [+4] */ in rt2860_read_eeprom()
3581 sc->step_5ghz = val >> 8; in rt2860_read_eeprom()
3583 "0x%02x 0x%02x step=%d\n", sc->tssi_5ghz[0], sc->tssi_5ghz[1], in rt2860_read_eeprom()
3584 sc->tssi_5ghz[2], sc->tssi_5ghz[3], sc->tssi_5ghz[4], in rt2860_read_eeprom()
3585 sc->tssi_5ghz[5], sc->tssi_5ghz[6], sc->tssi_5ghz[7], in rt2860_read_eeprom()
3586 sc->tssi_5ghz[8], sc->step_5ghz)); in rt2860_read_eeprom()
3588 if (sc->tssi_5ghz[4] == 0xff) in rt2860_read_eeprom()
3589 sc->calib_5ghz = 0; in rt2860_read_eeprom()
3593 sc->rssi_2ghz[0] = val & 0xff; /* Ant A */ in rt2860_read_eeprom()
3594 sc->rssi_2ghz[1] = val >> 8; /* Ant B */ in rt2860_read_eeprom()
3596 if (sc->mac_ver >= 0x3071) { in rt2860_read_eeprom()
3602 sc->txmixgain_2ghz = val & 0x7; in rt2860_read_eeprom()
3603 DPRINTF(("tx mixer gain=%u (2GHz)\n", sc->txmixgain_2ghz)); in rt2860_read_eeprom()
3605 sc->rssi_2ghz[2] = val & 0xff; /* Ant C */ in rt2860_read_eeprom()
3606 sc->lna[2] = val >> 8; /* channel group 2 */ in rt2860_read_eeprom()
3609 sc->rssi_5ghz[0] = val & 0xff; /* Ant A */ in rt2860_read_eeprom()
3610 sc->rssi_5ghz[1] = val >> 8; /* Ant B */ in rt2860_read_eeprom()
3612 sc->rssi_5ghz[2] = val & 0xff; /* Ant C */ in rt2860_read_eeprom()
3613 sc->lna[3] = val >> 8; /* channel group 3 */ in rt2860_read_eeprom()
3616 if (sc->mac_ver >= 0x3071) in rt2860_read_eeprom()
3617 sc->lna[0] = RT3090_DEF_LNA; in rt2860_read_eeprom()
3619 sc->lna[0] = val & 0xff; in rt2860_read_eeprom()
3620 sc->lna[1] = val >> 8; /* channel group 1 */ in rt2860_read_eeprom()
3623 if (sc->lna[2] == 0 || sc->lna[2] == 0xff) { in rt2860_read_eeprom()
3625 sc->lna[2] = sc->lna[1]; in rt2860_read_eeprom()
3627 if (sc->lna[3] == 0 || sc->lna[3] == 0xff) { in rt2860_read_eeprom()
3629 sc->lna[3] = sc->lna[1]; in rt2860_read_eeprom()
3634 if (sc->rssi_2ghz[ant] < -10 || sc->rssi_2ghz[ant] > 10) { in rt2860_read_eeprom()
3636 ant + 1, sc->rssi_2ghz[ant])); in rt2860_read_eeprom()
3637 sc->rssi_2ghz[ant] = 0; in rt2860_read_eeprom()
3639 if (sc->rssi_5ghz[ant] < -10 || sc->rssi_5ghz[ant] > 10) { in rt2860_read_eeprom()
3641 ant + 1, sc->rssi_5ghz[ant])); in rt2860_read_eeprom()
3642 sc->rssi_5ghz[ant] = 0; in rt2860_read_eeprom()
3661 device_printf(sc->sc_dev, in rt2860_bbp_init()
3667 if (sc->mac_ver >= 0x5390) in rt2860_bbp_init()
3677 if (sc->mac_ver == 0x2860 && sc->mac_rev != 0x0101) in rt2860_bbp_init()
3680 if (sc->mac_ver >= 0x3071) { in rt2860_bbp_init()
3684 } else if (sc->mac_ver == 0x2860 && sc->mac_rev == 0x0100) { in rt2860_bbp_init()
3699 if (sc->nrxchains > 1) { in rt5390_bbp_init()
3705 bbp = rt2860_mcu_bbp_read(sc, 4); in rt5390_bbp_init()
3706 rt2860_mcu_bbp_write(sc, 4, bbp | RT5390_MAC_IF_CTRL); in rt5390_bbp_init()
3713 if (sc->mac_ver == 0x5392) { in rt5390_bbp_init()
3726 if (sc->mac_ver == 0x5390) in rt5390_bbp_init()
3733 struct ieee80211com *ic = &sc->sc_ic; in rt2860_txrx_enable()
3747 device_printf(sc->sc_dev, "timeout waiting for DMA engine\n"); in rt2860_txrx_enable()
3759 if (ic->ic_opmode != IEEE80211_M_MONITOR) { in rt2860_txrx_enable()
3764 if (ic->ic_opmode == IEEE80211_M_STA) in rt2860_txrx_enable()
3779 struct ieee80211com *ic = &sc->sc_ic; in rt2860_init()
3785 if (sc->sc_flags & RT2860_RUNNING) in rt2860_init()
3792 struct ieee80211com *ic = &sc->sc_ic; in rt2860_init_locked()
3793 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); in rt2860_init_locked()
3800 if (sc->rfswitch) { in rt2860_init_locked()
3803 device_printf(sc->sc_dev, in rt2860_init_locked()
3831 device_printf(sc->sc_dev, "could not load 8051 microcode\n"); in rt2860_init_locked()
3836 rt2860_set_macaddr(sc, vap ? vap->iv_myaddr : ic->ic_macaddr); in rt2860_init_locked()
3840 if (sc->txpow20mhz[ridx] == 0xffffffff) in rt2860_init_locked()
3842 RAL_WRITE(sc, RT2860_TX_PWR_CFG(ridx), sc->txpow20mhz[ridx]); in rt2860_init_locked()
3852 device_printf(sc->sc_dev, "timeout waiting for DMA engine\n"); in rt2860_init_locked()
3861 /* reset Rx ring and all 6 Tx rings */ in rt2860_init_locked()
3877 if (sc->mac_ver >= 0x5390) in rt2860_init_locked()
3879 else if (sc->mac_ver >= 0x3071) { in rt2860_init_locked()
3882 4 << RT2860_DLY_PAPE_EN_SHIFT); in rt2860_init_locked()
3886 sc->sc_flags |= RT2860_PCIE; in rt2860_init_locked()
3901 device_printf(sc->sc_dev, "timeout waiting for MAC\n"); in rt2860_init_locked()
3929 RAL_SET_REGION_4(sc, RT2860_SKEY_MODE_0_7, 0, 4); in rt2860_init_locked()
3931 /* init Tx rings (4 EDCAs + HCCA + Mgt) */ in rt2860_init_locked()
3933 RAL_WRITE(sc, RT2860_TX_BASE_PTR(qid), sc->txq[qid].paddr); in rt2860_init_locked()
3938 /* init Rx ring */ in rt2860_init_locked()
3939 RAL_WRITE(sc, RT2860_RX_BASE_PTR, sc->rxq.paddr); in rt2860_init_locked()
3941 RAL_WRITE(sc, RT2860_RX_CALC_IDX, RT2860_RX_RING_COUNT - 1); in rt2860_init_locked()
3945 (MCLBYTES - sizeof (struct rt2860_rxwi) - 2)); in rt2860_init_locked()
3954 device_printf(sc->sc_dev, "timeout waiting for DMA engine\n"); in rt2860_init_locked()
3966 /* write vendor-specific BBP values (from EEPROM) */ in rt2860_init_locked()
3968 if (sc->bbp[i].reg == 0 || sc->bbp[i].reg == 0xff) in rt2860_init_locked()
3970 rt2860_mcu_bbp_write(sc, sc->bbp[i].reg, sc->bbp[i].val); in rt2860_init_locked()
3974 if (sc->rf_rev == RT3070_RF_2020 || in rt2860_init_locked()
3975 sc->rf_rev == RT3070_RF_3020 || in rt2860_init_locked()
3976 sc->rf_rev == RT3070_RF_3320 || in rt2860_init_locked()
3977 sc->mac_ver == 0x5390) in rt2860_init_locked()
3981 rt2860_mcu_cmd(sc, RT2860_MCU_CMD_LED1, sc->led[0], 0); in rt2860_init_locked()
3982 rt2860_mcu_cmd(sc, RT2860_MCU_CMD_LED2, sc->led[1], 0); in rt2860_init_locked()
3983 rt2860_mcu_cmd(sc, RT2860_MCU_CMD_LED3, sc->led[2], 0); in rt2860_init_locked()
3985 if (sc->mac_ver >= 0x5390) in rt2860_init_locked()
3987 else if (sc->mac_ver >= 0x3071) { in rt2860_init_locked()
3997 if (sc->mac_ver >= 0x5390) in rt2860_init_locked()
3999 else if (sc->mac_ver >= 0x3071) in rt2860_init_locked()
4002 /* disable non-existing Rx chains */ in rt2860_init_locked()
4004 bbp3 &= ~(1 << 3 | 1 << 4); in rt2860_init_locked()
4005 if (sc->nrxchains == 2) in rt2860_init_locked()
4007 else if (sc->nrxchains == 3) in rt2860_init_locked()
4008 bbp3 |= 1 << 4; in rt2860_init_locked()
4011 /* disable non-existing Tx chains */ in rt2860_init_locked()
4013 if (sc->ntxchains == 1) in rt2860_init_locked()
4014 bbp1 = (bbp1 & ~(1 << 3 | 1 << 4)); in rt2860_init_locked()
4015 else if (sc->mac_ver == 0x3593 && sc->ntxchains == 2) in rt2860_init_locked()
4016 bbp1 = (bbp1 & ~(1 << 4)) | 1 << 3; in rt2860_init_locked()
4017 else if (sc->mac_ver == 0x3593 && sc->ntxchains == 3) in rt2860_init_locked()
4018 bbp1 = (bbp1 & ~(1 << 3)) | 1 << 4; in rt2860_init_locked()
4021 if (sc->mac_ver >= 0x3071) in rt2860_init_locked()
4025 rt2860_switch_chan(sc, ic->ic_curchan); in rt2860_init_locked()
4053 if (sc->sc_flags & RT2860_ADVANCED_PS) in rt2860_init_locked()
4054 rt2860_mcu_cmd(sc, RT2860_MCU_CMD_PSLEVEL, sc->pslevel, 0); in rt2860_init_locked()
4056 sc->sc_flags |= RT2860_RUNNING; in rt2860_init_locked()
4058 callout_reset(&sc->watchdog_ch, hz, rt2860_watchdog, sc); in rt2860_init_locked()
4077 if (sc->sc_flags & RT2860_RUNNING) in rt2860_stop_locked()
4080 callout_stop(&sc->watchdog_ch); in rt2860_stop_locked()
4081 sc->sc_tx_timer = 0; in rt2860_stop_locked()
4082 sc->sc_flags &= ~RT2860_RUNNING; in rt2860_stop_locked()
4101 sc->qfullmsk = 0; in rt2860_stop_locked()
4103 rt2860_reset_tx_ring(sc, &sc->txq[qid]); in rt2860_stop_locked()
4104 rt2860_reset_rx_ring(sc, &sc->rxq); in rt2860_stop_locked()
4119 device_printf(sc->sc_dev, in rt2860_load_microcode()
4127 RAL_WRITE_REGION_1(sc, RT2860_FW_BASE, fp->data, fp->datasize); in rt2860_load_microcode()
4144 device_printf(sc->sc_dev, in rt2860_load_microcode()
4162 struct ieee80211com *ic = &sc->sc_ic; in rt2860_calib()
4170 if (IEEE80211_IS_CHAN_2GHZ(ic->ic_bss->ni_chan)) { in rt2860_calib()
4171 tssi = &sc->tssi_2ghz[4]; in rt2860_calib()
4172 step = sc->step_2ghz; in rt2860_calib()
4174 tssi = &sc->tssi_5ghz[4]; in rt2860_calib()
4175 step = sc->step_5ghz; in rt2860_calib()
4180 for (d = 0; d > -4 && bbp49 <= tssi[d - 1]; d--); in rt2860_calib()
4183 for (d = 0; d < +4 && bbp49 >= tssi[d + 1]; d++); in rt2860_calib()
4194 if (sc->txpow20mhz[ridx] == 0xffffffff) in rt2860_calib()
4197 b4inc(sc->txpow20mhz[ridx], d)); in rt2860_calib()
4208 if (sc->mac_ver == 0x5390) { in rt3090_set_rx_antenna()
4218 if (sc->mac_ver == 0x5390) { in rt3090_set_rx_antenna()
4233 struct ieee80211com *ic = &sc->sc_ic; in rt2860_switch_chan()
4240 if (sc->mac_ver >= 0x5390) in rt2860_switch_chan()
4242 else if (sc->mac_ver >= 0x3071) in rt2860_switch_chan()
4258 if (sc->mac_ver < 0x5390) in rt2860_switch_chan()
4267 struct ieee80211com *ic = vap->iv_ic; in rt2860_setup_beacon()
4272 if ((m = ieee80211_beacon_alloc(vap->iv_bss)) == NULL) in rt2860_setup_beacon()
4277 txwi.len = htole16(m->m_pkthdr.len); in rt2860_setup_beacon()
4279 ridx = IEEE80211_IS_CHAN_5GHZ(ic->ic_bsschan) ? in rt2860_setup_beacon()
4291 mtod(m, uint8_t *), m->m_pkthdr.len); in rt2860_setup_beacon()
4301 struct ieee80211com *ic = &sc->sc_ic; in rt2860_enable_tsf_sync()
4302 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); in rt2860_enable_tsf_sync()
4308 tmp |= vap->iv_bss->ni_intval * 16; in rt2860_enable_tsf_sync()
4310 if (vap->iv_opmode == IEEE80211_M_STA) { in rt2860_enable_tsf_sync()
4317 else if (vap->iv_opmode == IEEE80211_M_IBSS || in rt2860_enable_tsf_sync()
4318 vap->iv_opmode == IEEE80211_M_MBSS) { in rt2860_enable_tsf_sync()
4325 } else if (vap->iv_opmode == IEEE80211_M_HOSTAP) { in rt2860_enable_tsf_sync()