Lines Matching +full:programmable +full:- +full:security

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()
282 if ((error = rt2860_alloc_tx_ring(sc, &sc->txq[qid])) != 0) { in rt2860_attach()
283 device_printf(sc->sc_dev, 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()
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 ic->ic_flags_ext |= IEEE80211_FEXT_SEQNO_OFFLOAD; in rt2860_attach()
328 rt2860_getradiocaps(ic, IEEE80211_CHAN_MAX, &ic->ic_nchans, in rt2860_attach()
329 ic->ic_channels); in rt2860_attach()
333 ic->ic_wme.wme_update = rt2860_updateedca; in rt2860_attach()
334 ic->ic_scan_start = rt2860_scan_start; in rt2860_attach()
335 ic->ic_scan_end = rt2860_scan_end; in rt2860_attach()
336 ic->ic_getradiocaps = rt2860_getradiocaps; in rt2860_attach()
337 ic->ic_set_channel = rt2860_set_channel; in rt2860_attach()
338 ic->ic_updateslot = rt2860_updateslot; in rt2860_attach()
339 ic->ic_update_promisc = rt2860_update_promisc; in rt2860_attach()
340 ic->ic_raw_xmit = rt2860_raw_xmit; in rt2860_attach()
341 sc->sc_node_free = ic->ic_node_free; in rt2860_attach()
342 ic->ic_node_free = rt2860_node_free; in rt2860_attach()
343 ic->ic_newassoc = rt2860_newassoc; in rt2860_attach()
344 ic->ic_transmit = rt2860_transmit; in rt2860_attach()
345 ic->ic_parent = rt2860_parent; in rt2860_attach()
346 ic->ic_vap_create = rt2860_vap_create; in rt2860_attach()
347 ic->ic_vap_delete = rt2860_vap_delete; in rt2860_attach()
350 &sc->sc_txtap.wt_ihdr, sizeof(sc->sc_txtap), in rt2860_attach()
352 &sc->sc_rxtap.wr_ihdr, sizeof(sc->sc_rxtap), in rt2860_attach()
358 "debug", CTLFLAG_RW, &sc->sc_debug, 0, "debug msgs"); in rt2860_attach()
365 fail3: rt2860_free_rx_ring(sc, &sc->rxq); in rt2860_attach()
366 fail2: while (--qid >= 0) in rt2860_attach()
367 rt2860_free_tx_ring(sc, &sc->txq[qid]); in rt2860_attach()
368 fail1: mtx_destroy(&sc->sc_mtx); in rt2860_attach()
376 struct ieee80211com *ic = &sc->sc_ic; in rt2860_detach()
384 mbufq_drain(&sc->sc_snd); in rt2860_detach()
386 rt2860_free_tx_ring(sc, &sc->txq[qid]); in rt2860_detach()
387 rt2860_free_rx_ring(sc, &sc->rxq); in rt2860_detach()
390 mtx_destroy(&sc->sc_mtx); in rt2860_detach()
416 if (sc->sc_ic.ic_nrunning > 0) in rt2860_resume()
426 struct rt2860_softc *sc = ic->ic_softc; in rt2860_vap_create()
438 if (!TAILQ_EMPTY(&ic->ic_vaps)) { in rt2860_vap_create()
439 device_printf(sc->sc_dev, "only 1 vap supported\n"); in rt2860_vap_create()
446 if (TAILQ_EMPTY(&ic->ic_vaps) || in rt2860_vap_create()
447 ic->ic_opmode != IEEE80211_M_HOSTAP) { in rt2860_vap_create()
448 device_printf(sc->sc_dev, in rt2860_vap_create()
460 device_printf(sc->sc_dev, "unknown opmode %d\n", opmode); in rt2860_vap_create()
464 vap = &rvp->ral_vap; in rt2860_vap_create()
468 rvp->ral_newstate = vap->iv_newstate; in rt2860_vap_create()
469 vap->iv_newstate = rt2860_newstate; in rt2860_vap_create()
471 vap->iv_update_beacon = rt2860_beacon_update; in rt2860_vap_create()
474 /* HW supports up to 255 STAs (0-254) in HostAP and IBSS modes */ in rt2860_vap_create()
475 vap->iv_max_aid = min(IEEE80211_AID_MAX, RT2860_WCID_MAX); in rt2860_vap_create()
481 if (TAILQ_FIRST(&ic->ic_vaps) == vap) in rt2860_vap_create()
482 ic->ic_opmode = opmode; in rt2860_vap_create()
514 error = bus_dma_tag_create(bus_get_dma_tag(sc->sc_dev), 16, 0, in rt2860_alloc_tx_ring()
516 size, 1, size, 0, NULL, NULL, &ring->desc_dmat); in rt2860_alloc_tx_ring()
518 device_printf(sc->sc_dev, "could not create desc DMA tag\n"); in rt2860_alloc_tx_ring()
522 error = bus_dmamem_alloc(ring->desc_dmat, (void **)&ring->txd, in rt2860_alloc_tx_ring()
523 BUS_DMA_NOWAIT | BUS_DMA_ZERO, &ring->desc_map); in rt2860_alloc_tx_ring()
525 device_printf(sc->sc_dev, "could not allocate DMA memory\n"); in rt2860_alloc_tx_ring()
529 error = bus_dmamap_load(ring->desc_dmat, ring->desc_map, ring->txd, in rt2860_alloc_tx_ring()
530 size, rt2860_dma_map_addr, &ring->paddr, 0); in rt2860_alloc_tx_ring()
532 device_printf(sc->sc_dev, "could not load desc DMA map\n"); in rt2860_alloc_tx_ring()
536 bus_dmamap_sync(ring->desc_dmat, ring->desc_map, BUS_DMASYNC_PREWRITE); in rt2860_alloc_tx_ring()
551 if ((data = ring->data[i]) == NULL) in rt2860_reset_tx_ring()
554 if (data->m != NULL) { in rt2860_reset_tx_ring()
555 bus_dmamap_sync(sc->txwi_dmat, data->map, in rt2860_reset_tx_ring()
557 bus_dmamap_unload(sc->txwi_dmat, data->map); in rt2860_reset_tx_ring()
558 m_freem(data->m); in rt2860_reset_tx_ring()
559 data->m = NULL; in rt2860_reset_tx_ring()
561 if (data->ni != NULL) { in rt2860_reset_tx_ring()
562 ieee80211_free_node(data->ni); in rt2860_reset_tx_ring()
563 data->ni = NULL; in rt2860_reset_tx_ring()
566 SLIST_INSERT_HEAD(&sc->data_pool, data, next); in rt2860_reset_tx_ring()
567 ring->data[i] = NULL; in rt2860_reset_tx_ring()
570 ring->queued = 0; in rt2860_reset_tx_ring()
571 ring->cur = ring->next = 0; in rt2860_reset_tx_ring()
580 if (ring->txd != NULL) { in rt2860_free_tx_ring()
581 bus_dmamap_sync(ring->desc_dmat, ring->desc_map, in rt2860_free_tx_ring()
583 bus_dmamap_unload(ring->desc_dmat, ring->desc_map); in rt2860_free_tx_ring()
584 bus_dmamem_free(ring->desc_dmat, ring->txd, ring->desc_map); in rt2860_free_tx_ring()
586 if (ring->desc_dmat != NULL) in rt2860_free_tx_ring()
587 bus_dma_tag_destroy(ring->desc_dmat); in rt2860_free_tx_ring()
590 if ((data = ring->data[i]) == NULL) in rt2860_free_tx_ring()
593 if (data->m != NULL) { in rt2860_free_tx_ring()
594 bus_dmamap_sync(sc->txwi_dmat, data->map, in rt2860_free_tx_ring()
596 bus_dmamap_unload(sc->txwi_dmat, data->map); in rt2860_free_tx_ring()
597 m_freem(data->m); in rt2860_free_tx_ring()
599 if (data->ni != NULL) in rt2860_free_tx_ring()
600 ieee80211_free_node(data->ni); in rt2860_free_tx_ring()
602 SLIST_INSERT_HEAD(&sc->data_pool, data, next); in rt2860_free_tx_ring()
619 SLIST_INIT(&sc->data_pool); in rt2860_alloc_tx_pool()
621 error = bus_dma_tag_create(bus_get_dma_tag(sc->sc_dev), 1, 0, in rt2860_alloc_tx_pool()
623 size, 1, size, 0, NULL, NULL, &sc->txwi_dmat); in rt2860_alloc_tx_pool()
625 device_printf(sc->sc_dev, "could not create txwi DMA tag\n"); in rt2860_alloc_tx_pool()
629 error = bus_dmamem_alloc(sc->txwi_dmat, (void **)&sc->txwi_vaddr, in rt2860_alloc_tx_pool()
630 BUS_DMA_NOWAIT | BUS_DMA_ZERO, &sc->txwi_map); in rt2860_alloc_tx_pool()
632 device_printf(sc->sc_dev, "could not allocate DMA memory\n"); in rt2860_alloc_tx_pool()
636 error = bus_dmamap_load(sc->txwi_dmat, sc->txwi_map, in rt2860_alloc_tx_pool()
637 sc->txwi_vaddr, size, rt2860_dma_map_addr, &paddr, 0); in rt2860_alloc_tx_pool()
639 device_printf(sc->sc_dev, "could not load txwi DMA map\n"); in rt2860_alloc_tx_pool()
643 bus_dmamap_sync(sc->txwi_dmat, sc->txwi_map, BUS_DMASYNC_PREWRITE); in rt2860_alloc_tx_pool()
645 vaddr = sc->txwi_vaddr; in rt2860_alloc_tx_pool()
647 struct rt2860_tx_data *data = &sc->data[i]; in rt2860_alloc_tx_pool()
649 error = bus_dmamap_create(sc->txwi_dmat, 0, &data->map); in rt2860_alloc_tx_pool()
651 device_printf(sc->sc_dev, "could not create DMA map\n"); in rt2860_alloc_tx_pool()
654 data->txwi = (struct rt2860_txwi *)vaddr; in rt2860_alloc_tx_pool()
655 data->paddr = paddr; in rt2860_alloc_tx_pool()
659 SLIST_INSERT_HEAD(&sc->data_pool, data, next); in rt2860_alloc_tx_pool()
671 if (sc->txwi_vaddr != NULL) { in rt2860_free_tx_pool()
672 bus_dmamap_sync(sc->txwi_dmat, sc->txwi_map, in rt2860_free_tx_pool()
674 bus_dmamap_unload(sc->txwi_dmat, sc->txwi_map); in rt2860_free_tx_pool()
675 bus_dmamem_free(sc->txwi_dmat, sc->txwi_vaddr, sc->txwi_map); in rt2860_free_tx_pool()
677 if (sc->txwi_dmat != NULL) in rt2860_free_tx_pool()
678 bus_dma_tag_destroy(sc->txwi_dmat); in rt2860_free_tx_pool()
680 while (!SLIST_EMPTY(&sc->data_pool)) { in rt2860_free_tx_pool()
682 data = SLIST_FIRST(&sc->data_pool); in rt2860_free_tx_pool()
683 bus_dmamap_destroy(sc->txwi_dmat, data->map); in rt2860_free_tx_pool()
684 SLIST_REMOVE_HEAD(&sc->data_pool, next); in rt2860_free_tx_pool()
696 error = bus_dma_tag_create(bus_get_dma_tag(sc->sc_dev), 16, 0, in rt2860_alloc_rx_ring()
698 size, 1, size, 0, NULL, NULL, &ring->desc_dmat); in rt2860_alloc_rx_ring()
700 device_printf(sc->sc_dev, "could not create desc DMA tag\n"); in rt2860_alloc_rx_ring()
704 error = bus_dmamem_alloc(ring->desc_dmat, (void **)&ring->rxd, in rt2860_alloc_rx_ring()
705 BUS_DMA_NOWAIT | BUS_DMA_ZERO, &ring->desc_map); in rt2860_alloc_rx_ring()
707 device_printf(sc->sc_dev, "could not allocate DMA memory\n"); in rt2860_alloc_rx_ring()
711 error = bus_dmamap_load(ring->desc_dmat, ring->desc_map, ring->rxd, in rt2860_alloc_rx_ring()
712 size, rt2860_dma_map_addr, &ring->paddr, 0); in rt2860_alloc_rx_ring()
714 device_printf(sc->sc_dev, "could not load desc DMA map\n"); in rt2860_alloc_rx_ring()
718 error = bus_dma_tag_create(bus_get_dma_tag(sc->sc_dev), 1, 0, in rt2860_alloc_rx_ring()
720 1, MCLBYTES, 0, NULL, NULL, &ring->data_dmat); in rt2860_alloc_rx_ring()
722 device_printf(sc->sc_dev, "could not create data DMA tag\n"); in rt2860_alloc_rx_ring()
727 struct rt2860_rx_data *data = &ring->data[i]; in rt2860_alloc_rx_ring()
728 struct rt2860_rxd *rxd = &ring->rxd[i]; in rt2860_alloc_rx_ring()
730 error = bus_dmamap_create(ring->data_dmat, 0, &data->map); in rt2860_alloc_rx_ring()
732 device_printf(sc->sc_dev, "could not create DMA map\n"); in rt2860_alloc_rx_ring()
736 data->m = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR); in rt2860_alloc_rx_ring()
737 if (data->m == NULL) { in rt2860_alloc_rx_ring()
738 device_printf(sc->sc_dev, in rt2860_alloc_rx_ring()
744 error = bus_dmamap_load(ring->data_dmat, data->map, in rt2860_alloc_rx_ring()
745 mtod(data->m, void *), MCLBYTES, rt2860_dma_map_addr, in rt2860_alloc_rx_ring()
748 device_printf(sc->sc_dev, in rt2860_alloc_rx_ring()
753 rxd->sdp0 = htole32(physaddr); in rt2860_alloc_rx_ring()
754 rxd->sdl0 = htole16(MCLBYTES); in rt2860_alloc_rx_ring()
757 bus_dmamap_sync(ring->desc_dmat, ring->desc_map, BUS_DMASYNC_PREWRITE); in rt2860_alloc_rx_ring()
771 ring->rxd[i].sdl0 &= ~htole16(RT2860_RX_DDONE); in rt2860_reset_rx_ring()
773 bus_dmamap_sync(ring->desc_dmat, ring->desc_map, BUS_DMASYNC_PREWRITE); in rt2860_reset_rx_ring()
775 ring->cur = 0; in rt2860_reset_rx_ring()
783 if (ring->rxd != NULL) { in rt2860_free_rx_ring()
784 bus_dmamap_sync(ring->desc_dmat, ring->desc_map, in rt2860_free_rx_ring()
786 bus_dmamap_unload(ring->desc_dmat, ring->desc_map); in rt2860_free_rx_ring()
787 bus_dmamem_free(ring->desc_dmat, ring->rxd, ring->desc_map); in rt2860_free_rx_ring()
789 if (ring->desc_dmat != NULL) in rt2860_free_rx_ring()
790 bus_dma_tag_destroy(ring->desc_dmat); in rt2860_free_rx_ring()
793 struct rt2860_rx_data *data = &ring->data[i]; in rt2860_free_rx_ring()
795 if (data->m != NULL) { in rt2860_free_rx_ring()
796 bus_dmamap_sync(ring->data_dmat, data->map, in rt2860_free_rx_ring()
798 bus_dmamap_unload(ring->data_dmat, data->map); in rt2860_free_rx_ring()
799 m_freem(data->m); in rt2860_free_rx_ring()
801 if (data->map != NULL) in rt2860_free_rx_ring()
802 bus_dmamap_destroy(ring->data_dmat, data->map); in rt2860_free_rx_ring()
804 if (ring->data_dmat != NULL) in rt2860_free_rx_ring()
805 bus_dma_tag_destroy(ring->data_dmat); in rt2860_free_rx_ring()
811 struct ieee80211com *ic = &sc->sc_ic; in rt2860_updatestats()
815 * MAC can run into a livelock and start sending CTS-to-self frames in rt2860_updatestats()
819 if (ic->ic_curmode != IEEE80211_M_STA) { in rt2860_updatestats()
824 DPRINTF(("CTS-to-self livelock detected\n")); in rt2860_updatestats()
837 struct ieee80211com *ic = ni->ni_ic; in rt2860_newassoc()
838 struct rt2860_softc *sc = ic->ic_softc; in rt2860_newassoc()
841 wcid = IEEE80211_AID(ni->ni_associd); in rt2860_newassoc()
842 if (isnew && ni->ni_associd != 0) { in rt2860_newassoc()
843 sc->wcid2ni[wcid] = ni; in rt2860_newassoc()
847 ni->ni_macaddr, IEEE80211_ADDR_LEN); in rt2860_newassoc()
850 isnew, ether_sprintf(ni->ni_macaddr), wcid)); in rt2860_newassoc()
856 struct ieee80211com *ic = ni->ni_ic; in rt2860_node_free()
857 struct rt2860_softc *sc = ic->ic_softc; in rt2860_node_free()
860 if (ni->ni_associd != 0) { in rt2860_node_free()
861 wcid = IEEE80211_AID(ni->ni_associd); in rt2860_node_free()
866 sc->sc_node_free(ni); in rt2860_node_free()
874 struct rt2860_softc *sc = ic->ic_softc; in rt2860_ampdu_rx_start()
875 uint8_t wcid = ((struct rt2860_node *)ni)->wcid; in rt2860_ampdu_rx_start()
889 struct rt2860_softc *sc = ic->ic_softc; in rt2860_ampdu_rx_stop()
890 uint8_t wcid = ((struct rt2860_node *)ni)->wcid; in rt2860_ampdu_rx_stop()
904 struct ieee80211com *ic = vap->iv_ic; in rt2860_newstate()
905 struct rt2860_softc *sc = ic->ic_softc; in rt2860_newstate()
909 if (vap->iv_state == IEEE80211_S_RUN) { in rt2860_newstate()
914 if (nstate == IEEE80211_S_INIT && vap->iv_state == IEEE80211_S_RUN) { in rt2860_newstate()
924 error = rvp->ral_newstate(vap, nstate, arg); in rt2860_newstate()
929 struct ieee80211_node *ni = vap->iv_bss; in rt2860_newstate()
931 if (ic->ic_opmode != IEEE80211_M_MONITOR) { in rt2860_newstate()
934 rt2860_set_basicrates(sc, &ni->ni_rates); in rt2860_newstate()
935 rt2860_set_bssid(sc, ni->ni_bssid); in rt2860_newstate()
938 if (vap->iv_opmode == IEEE80211_M_HOSTAP || in rt2860_newstate()
939 vap->iv_opmode == IEEE80211_M_IBSS || in rt2860_newstate()
940 vap->iv_opmode == IEEE80211_M_MBSS) { in rt2860_newstate()
946 if (ic->ic_opmode != IEEE80211_M_MONITOR) { in rt2860_newstate()
953 (IEEE80211_IS_CHAN_2GHZ(ni->ni_chan) ? in rt2860_newstate()
959 /* Read 16-bit from eFUSE ROM (>=RT3071 only.) */
968 /*- in rt3090_efuse_read_2()
969 * Read one 16-byte block into registers EFUSE_DATA[0-3]: in rt3090_efuse_read_2()
991 /* determine to which 32-bit register our 16-bit word belongs */ in rt3090_efuse_read_2()
992 reg = RT3070_EFUSE_DATA3 - (addr & 0xc); in rt3090_efuse_read_2()
1026 /* write address (A5-A0 or A7-A0) */ in rt2860_eeprom_read_2()
1028 for (; n >= 0; n--) { in rt2860_eeprom_read_2()
1037 /* read data Q15-Q0 */ in rt2860_eeprom_read_2()
1039 for (n = 15; n >= 0; n--) { in rt2860_eeprom_read_2()
1060 return sc->sc_srom_read(sc, addr); in rt2860_srom_read()
1083 struct ieee80211_ratectl_tx_status *txs = &sc->sc_txs; in rt2860_drain_stats_fifo()
1089 txs->flags = IEEE80211_RATECTL_STATUS_LONG_RETRY; in rt2860_drain_stats_fifo()
1096 ni = sc->wcid2ni[wcid]; in rt2860_drain_stats_fifo()
1102 /* update per-STA AMRR stats */ in rt2860_drain_stats_fifo()
1113 txs->long_retries = 1; in rt2860_drain_stats_fifo()
1115 txs->long_retries = 0; in rt2860_drain_stats_fifo()
1116 txs->status = IEEE80211_RATECTL_TX_SUCCESS; in rt2860_drain_stats_fifo()
1119 txs->status = IEEE80211_RATECTL_TX_FAIL_UNSPECIFIED; in rt2860_drain_stats_fifo()
1120 txs->long_retries = 1; /* XXX */ in rt2860_drain_stats_fifo()
1122 if_inc_counter(ni->ni_vap->iv_ifp, in rt2860_drain_stats_fifo()
1131 struct rt2860_tx_ring *ring = &sc->txq[qid]; in rt2860_tx_intr()
1137 while (ring->next != hw) { in rt2860_tx_intr()
1138 struct rt2860_tx_data *data = ring->data[ring->next]; in rt2860_tx_intr()
1141 bus_dmamap_sync(sc->txwi_dmat, data->map, in rt2860_tx_intr()
1143 bus_dmamap_unload(sc->txwi_dmat, data->map); in rt2860_tx_intr()
1144 ieee80211_tx_complete(data->ni, data->m, 0); in rt2860_tx_intr()
1145 data->ni = NULL; in rt2860_tx_intr()
1146 data->m = NULL; in rt2860_tx_intr()
1147 SLIST_INSERT_HEAD(&sc->data_pool, data, next); in rt2860_tx_intr()
1148 ring->data[ring->next] = NULL; in rt2860_tx_intr()
1150 ring->queued--; in rt2860_tx_intr()
1151 ring->next = (ring->next + 1) % RT2860_TX_RING_COUNT; in rt2860_tx_intr()
1154 sc->sc_tx_timer = 0; in rt2860_tx_intr()
1155 if (ring->queued < RT2860_TX_RING_COUNT) in rt2860_tx_intr()
1156 sc->qfullmsk &= ~(1 << qid); in rt2860_tx_intr()
1168 if (sc->nrxchains > 1) { in rt2860_maxrssi_chain()
1169 if (rxwi->rssi[1] > rxwi->rssi[rxchain]) in rt2860_maxrssi_chain()
1171 if (sc->nrxchains > 2) in rt2860_maxrssi_chain()
1172 if (rxwi->rssi[2] > rxwi->rssi[rxchain]) in rt2860_maxrssi_chain()
1182 struct ieee80211com *ic = &sc->sc_ic; in rt2860_rx_intr()
1194 while (sc->rxq.cur != hw) { in rt2860_rx_intr()
1195 struct rt2860_rx_data *data = &sc->rxq.data[sc->rxq.cur]; in rt2860_rx_intr()
1196 struct rt2860_rxd *rxd = &sc->rxq.rxd[sc->rxq.cur]; in rt2860_rx_intr()
1199 bus_dmamap_sync(sc->rxq.desc_dmat, sc->rxq.desc_map, in rt2860_rx_intr()
1202 if (__predict_false(!(rxd->sdl0 & htole16(RT2860_RX_DDONE)))) { in rt2860_rx_intr()
1207 if (__predict_false(rxd->flags & in rt2860_rx_intr()
1209 counter_u64_add(ic->ic_ierrors, 1); in rt2860_rx_intr()
1214 if (__predict_false(rxd->flags & htole32(RT2860_RX_MICERR))) { in rt2860_rx_intr()
1216 ic->ic_stats.is_rx_locmicfail++; in rt2860_rx_intr()
1218 counter_u64_add(ic->ic_ierrors, 1); in rt2860_rx_intr()
1225 counter_u64_add(ic->ic_ierrors, 1); in rt2860_rx_intr()
1229 bus_dmamap_sync(sc->rxq.data_dmat, data->map, in rt2860_rx_intr()
1231 bus_dmamap_unload(sc->rxq.data_dmat, data->map); in rt2860_rx_intr()
1233 error = bus_dmamap_load(sc->rxq.data_dmat, data->map, in rt2860_rx_intr()
1240 error = bus_dmamap_load(sc->rxq.data_dmat, data->map, in rt2860_rx_intr()
1241 mtod(data->m, void *), MCLBYTES, in rt2860_rx_intr()
1245 device_get_name(sc->sc_dev)); in rt2860_rx_intr()
1248 rxd->sdp0 = htole32(physaddr); in rt2860_rx_intr()
1249 counter_u64_add(ic->ic_ierrors, 1); in rt2860_rx_intr()
1257 m = data->m; in rt2860_rx_intr()
1258 data->m = m1; in rt2860_rx_intr()
1259 rxd->sdp0 = htole32(physaddr); in rt2860_rx_intr()
1264 m->m_data = (caddr_t)(rxwi + 1); in rt2860_rx_intr()
1265 m->m_pkthdr.len = m->m_len = le16toh(rxwi->len) & 0xfff; in rt2860_rx_intr()
1269 if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) { in rt2860_rx_intr()
1271 wh->i_fc[1] &= ~IEEE80211_FC1_PROTECTED; in rt2860_rx_intr()
1276 if (rxd->flags & htole32(RT2860_RX_L2PAD)) { in rt2860_rx_intr()
1279 m->m_data += 2; in rt2860_rx_intr()
1284 rssi = rt2860_rssi2dbm(sc, rxwi->rssi[ant], ant); in rt2860_rx_intr()
1288 tap = &sc->sc_rxtap; in rt2860_rx_intr()
1289 tap->wr_flags = 0; in rt2860_rx_intr()
1290 tap->wr_antenna = ant; in rt2860_rx_intr()
1291 tap->wr_antsignal = nf + rssi; in rt2860_rx_intr()
1292 tap->wr_antnoise = nf; in rt2860_rx_intr()
1294 tap->wr_rate = 2; in rt2860_rx_intr()
1295 phy = le16toh(rxwi->phy); in rt2860_rx_intr()
1299 case 0: tap->wr_rate = 2; break; in rt2860_rx_intr()
1300 case 1: tap->wr_rate = 4; break; in rt2860_rx_intr()
1301 case 2: tap->wr_rate = 11; break; in rt2860_rx_intr()
1302 case 3: tap->wr_rate = 22; break; in rt2860_rx_intr()
1305 tap->wr_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; in rt2860_rx_intr()
1309 case 0: tap->wr_rate = 12; break; in rt2860_rx_intr()
1310 case 1: tap->wr_rate = 18; break; in rt2860_rx_intr()
1311 case 2: tap->wr_rate = 24; break; in rt2860_rx_intr()
1312 case 3: tap->wr_rate = 36; break; in rt2860_rx_intr()
1313 case 4: tap->wr_rate = 48; break; in rt2860_rx_intr()
1314 case 5: tap->wr_rate = 72; break; in rt2860_rx_intr()
1315 case 6: tap->wr_rate = 96; break; in rt2860_rx_intr()
1316 case 7: tap->wr_rate = 108; break; in rt2860_rx_intr()
1329 (void)ieee80211_input(ni, m, rssi - nf, nf); in rt2860_rx_intr()
1332 (void)ieee80211_input_all(ic, m, rssi - nf, nf); in rt2860_rx_intr()
1336 skip: rxd->sdl0 &= ~htole16(RT2860_RX_DDONE); in rt2860_rx_intr()
1338 bus_dmamap_sync(sc->rxq.desc_dmat, sc->rxq.desc_map, in rt2860_rx_intr()
1341 sc->rxq.cur = (sc->rxq.cur + 1) % RT2860_RX_RING_COUNT; in rt2860_rx_intr()
1346 (sc->rxq.cur - 1) % RT2860_RX_RING_COUNT); in rt2860_rx_intr()
1353 struct ieee80211com *ic = &sc->sc_ic; in rt2860_tbtt_intr()
1356 if (ic->ic_opmode == IEEE80211_M_HOSTAP) { in rt2860_tbtt_intr()
1358 if (ic->ic_dtim_count == 0) in rt2860_tbtt_intr()
1359 ic->ic_dtim_count = ic->ic_dtim_period - 1; in rt2860_tbtt_intr()
1361 ic->ic_dtim_count--; in rt2860_tbtt_intr()
1367 if (ic->ic_dtim_count == 0) in rt2860_tbtt_intr()
1372 if ((sc->sc_ic_flags ^ ic->ic_flags) & IEEE80211_F_USEPROT) { in rt2860_tbtt_intr()
1374 sc->sc_ic_flags = ic->ic_flags; in rt2860_tbtt_intr()
1382 struct ieee80211com *ic = &sc->sc_ic; in rt2860_gp_intr()
1383 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); in rt2860_gp_intr()
1385 DPRINTFN(2, ("GP timeout state=%d\n", vap->iv_state)); in rt2860_gp_intr()
1387 if (vap->iv_state == IEEE80211_S_RUN) in rt2860_gp_intr()
1454 struct ieee80211com *ic = &sc->sc_ic; in rt2860_tx()
1455 struct ieee80211vap *vap = ni->ni_vap; in rt2860_tx()
1461 const struct ieee80211_txparam *tp = ni->ni_txparms; in rt2860_tx()
1472 data = SLIST_FIRST(&sc->data_pool); in rt2860_tx()
1476 ieee80211_output_seqno_assign(ni, -1, m); in rt2860_tx()
1477 if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) { in rt2860_tx()
1489 type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK; in rt2860_tx()
1491 if (m->m_flags & M_EAPOL) { in rt2860_tx()
1492 rate = tp->mgmtrate; in rt2860_tx()
1493 } else if (IEEE80211_IS_MULTICAST(wh->i_addr1)) { in rt2860_tx()
1494 rate = tp->mcastrate; in rt2860_tx()
1495 } else if (tp->ucastrate != IEEE80211_FIXED_RATE_NONE) { in rt2860_tx()
1496 rate = tp->ucastrate; in rt2860_tx()
1505 qos = ((const struct ieee80211_qosframe *)wh)->i_qos[0]; in rt2860_tx()
1509 ring = &sc->txq[qid]; in rt2860_tx()
1510 ridx = ieee80211_legacy_rate_lookup(ic->ic_rt, rate); in rt2860_tx()
1516 txwi = data->txwi; in rt2860_tx()
1517 txwi->flags = 0; in rt2860_tx()
1518 /* let HW generate seq numbers for non-QoS frames */ in rt2860_tx()
1519 txwi->xflags = qos ? 0 : RT2860_TX_NSEQ; in rt2860_tx()
1521 txwi->wcid = IEEE80211_AID(ni->ni_associd); in rt2860_tx()
1523 txwi->wcid = 0xff; in rt2860_tx()
1524 txwi->len = htole16(m->m_pkthdr.len); in rt2860_tx()
1526 txwi->phy = htole16(RT2860_PHY_CCK); in rt2860_tx()
1528 (ic->ic_flags & IEEE80211_F_SHPREAMBLE)) in rt2860_tx()
1531 txwi->phy = htole16(RT2860_PHY_OFDM); in rt2860_tx()
1532 txwi->phy |= htole16(mcs); in rt2860_tx()
1535 * We store the MCS code into the driver-private PacketID field. in rt2860_tx()
1542 txwi->len |= htole16(pid << RT2860_TX_PID_SHIFT); in rt2860_tx()
1544 /* check if RTS/CTS or CTS-to-self protection is required */ in rt2860_tx()
1545 if (!IEEE80211_IS_MULTICAST(wh->i_addr1) && in rt2860_tx()
1546 (m->m_pkthdr.len + IEEE80211_CRC_LEN > vap->iv_rtsthreshold || in rt2860_tx()
1547 ((ic->ic_flags & IEEE80211_F_USEPROT) && in rt2860_tx()
1549 txwi->txop = RT2860_TX_TXOP_HT; in rt2860_tx()
1551 txwi->txop = RT2860_TX_TXOP_BACKOFF; in rt2860_tx()
1553 if (!IEEE80211_IS_MULTICAST(wh->i_addr1) && in rt2860_tx()
1556 txwi->xflags |= RT2860_TX_ACK; in rt2860_tx()
1558 if (ic->ic_flags & IEEE80211_F_SHPREAMBLE) in rt2860_tx()
1562 *(uint16_t *)wh->i_dur = htole16(dur); in rt2860_tx()
1567 txwi->flags |= RT2860_TX_TS; in rt2860_tx()
1570 struct rt2860_tx_radiotap_header *tap = &sc->sc_txtap; in rt2860_tx()
1572 tap->wt_flags = 0; in rt2860_tx()
1573 tap->wt_rate = rate; in rt2860_tx()
1575 tap->wt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; in rt2860_tx()
1586 error = bus_dmamap_load_mbuf_sg(sc->txwi_dmat, data->map, m, segs, in rt2860_tx()
1589 device_printf(sc->sc_dev, "can't map mbuf (error %d)\n", in rt2860_tx()
1598 if (ring->queued + ntxds >= RT2860_TX_RING_COUNT) { in rt2860_tx()
1600 bus_dmamap_unload(sc->txwi_dmat, data->map); in rt2860_tx()
1607 device_printf(sc->sc_dev, in rt2860_tx()
1614 error = bus_dmamap_load_mbuf_sg(sc->txwi_dmat, data->map, m, in rt2860_tx()
1617 device_printf(sc->sc_dev, "can't map mbuf (error %d)\n", in rt2860_tx()
1626 if (ring->queued + ntxds >= RT2860_TX_RING_COUNT) { in rt2860_tx()
1628 bus_dmamap_unload(sc->txwi_dmat, data->map); in rt2860_tx()
1637 txd = &ring->txd[ring->cur]; in rt2860_tx()
1638 txd->sdp0 = htole32(data->paddr); in rt2860_tx()
1639 txd->sdl0 = htole16(sizeof (struct rt2860_txwi) + pad); in rt2860_tx()
1640 txd->flags = qsel; in rt2860_tx()
1644 for (i = nsegs; i >= 2; i -= 2) { in rt2860_tx()
1645 txd->sdp1 = htole32(seg->ds_addr); in rt2860_tx()
1646 txd->sdl1 = htole16(seg->ds_len); in rt2860_tx()
1648 ring->cur = (ring->cur + 1) % RT2860_TX_RING_COUNT; in rt2860_tx()
1650 txd = &ring->txd[ring->cur]; in rt2860_tx()
1651 txd->sdp0 = htole32(seg->ds_addr); in rt2860_tx()
1652 txd->sdl0 = htole16(seg->ds_len); in rt2860_tx()
1653 txd->flags = qsel; in rt2860_tx()
1658 txd->sdp1 = htole32(seg->ds_addr); in rt2860_tx()
1659 txd->sdl1 = htole16(seg->ds_len | RT2860_TX_LS1); in rt2860_tx()
1661 txd->sdl0 |= htole16(RT2860_TX_LS0); in rt2860_tx()
1662 txd->sdl1 = 0; in rt2860_tx()
1666 SLIST_REMOVE_HEAD(&sc->data_pool, next); in rt2860_tx()
1667 data->m = m; in rt2860_tx()
1668 data->ni = ni; in rt2860_tx()
1669 ring->data[ring->cur] = data; in rt2860_tx()
1671 bus_dmamap_sync(sc->txwi_dmat, sc->txwi_map, BUS_DMASYNC_PREWRITE); in rt2860_tx()
1672 bus_dmamap_sync(sc->txwi_dmat, data->map, BUS_DMASYNC_PREWRITE); in rt2860_tx()
1673 bus_dmamap_sync(ring->desc_dmat, ring->desc_map, BUS_DMASYNC_PREWRITE); in rt2860_tx()
1676 qid, txwi->wcid, nsegs, ridx)); in rt2860_tx()
1678 ring->cur = (ring->cur + 1) % RT2860_TX_RING_COUNT; in rt2860_tx()
1679 ring->queued += ntxds; in rt2860_tx()
1680 if (ring->queued >= RT2860_TX_RING_COUNT) in rt2860_tx()
1681 sc->qfullmsk |= 1 << qid; in rt2860_tx()
1684 RAL_WRITE(sc, RT2860_TX_CTX_IDX(qid), ring->cur); in rt2860_tx()
1693 struct ieee80211com *ic = ni->ni_ic; in rt2860_raw_xmit()
1694 struct rt2860_softc *sc = ic->ic_softc; in rt2860_raw_xmit()
1700 if (!(sc->sc_flags & RT2860_RUNNING)) { in rt2860_raw_xmit()
1718 sc->sc_tx_timer = 5; in rt2860_raw_xmit()
1727 struct ieee80211com *ic = &sc->sc_ic; in rt2860_tx_raw()
1728 struct ieee80211vap *vap = ni->ni_vap; in rt2860_tx_raw()
1743 data = SLIST_FIRST(&sc->data_pool); in rt2860_tx_raw()
1749 rate = params->ibp_rate0; in rt2860_tx_raw()
1750 ridx = ieee80211_legacy_rate_lookup(ic->ic_rt, in rt2860_tx_raw()
1752 if (ridx == (uint8_t)-1) { in rt2860_tx_raw()
1758 qid = params->ibp_pri & 3; in rt2860_tx_raw()
1759 ring = &sc->txq[qid]; in rt2860_tx_raw()
1765 txwi = data->txwi; in rt2860_tx_raw()
1766 txwi->flags = 0; in rt2860_tx_raw()
1767 /* let HW generate seq numbers for non-QoS frames */ in rt2860_tx_raw()
1768 txwi->xflags = params->ibp_pri & 3 ? 0 : RT2860_TX_NSEQ; in rt2860_tx_raw()
1769 txwi->wcid = 0xff; in rt2860_tx_raw()
1770 txwi->len = htole16(m->m_pkthdr.len); in rt2860_tx_raw()
1772 txwi->phy = htole16(RT2860_PHY_CCK); in rt2860_tx_raw()
1774 (ic->ic_flags & IEEE80211_F_SHPREAMBLE)) in rt2860_tx_raw()
1777 txwi->phy = htole16(RT2860_PHY_OFDM); in rt2860_tx_raw()
1778 txwi->phy |= htole16(mcs); in rt2860_tx_raw()
1781 * We store the MCS code into the driver-private PacketID field. in rt2860_tx_raw()
1788 txwi->len |= htole16(pid << RT2860_TX_PID_SHIFT); in rt2860_tx_raw()
1790 /* check if RTS/CTS or CTS-to-self protection is required */ in rt2860_tx_raw()
1791 if (params->ibp_flags & IEEE80211_BPF_RTS || in rt2860_tx_raw()
1792 params->ibp_flags & IEEE80211_BPF_CTS) in rt2860_tx_raw()
1793 txwi->txop = RT2860_TX_TXOP_HT; in rt2860_tx_raw()
1795 txwi->txop = RT2860_TX_TXOP_BACKOFF; in rt2860_tx_raw()
1796 if ((params->ibp_flags & IEEE80211_BPF_NOACK) == 0) { in rt2860_tx_raw()
1797 txwi->xflags |= RT2860_TX_ACK; in rt2860_tx_raw()
1799 if (ic->ic_flags & IEEE80211_F_SHPREAMBLE) in rt2860_tx_raw()
1803 *(uint16_t *)wh->i_dur = htole16(dur); in rt2860_tx_raw()
1808 txwi->flags |= RT2860_TX_TS; in rt2860_tx_raw()
1811 struct rt2860_tx_radiotap_header *tap = &sc->sc_txtap; in rt2860_tx_raw()
1813 tap->wt_flags = 0; in rt2860_tx_raw()
1814 tap->wt_rate = rate; in rt2860_tx_raw()
1816 tap->wt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; in rt2860_tx_raw()
1827 error = bus_dmamap_load_mbuf_sg(sc->txwi_dmat, data->map, m, segs, in rt2860_tx_raw()
1830 device_printf(sc->sc_dev, "can't map mbuf (error %d)\n", in rt2860_tx_raw()
1839 if (ring->queued + ntxds >= RT2860_TX_RING_COUNT) { in rt2860_tx_raw()
1841 bus_dmamap_unload(sc->txwi_dmat, data->map); in rt2860_tx_raw()
1848 device_printf(sc->sc_dev, in rt2860_tx_raw()
1855 error = bus_dmamap_load_mbuf_sg(sc->txwi_dmat, data->map, m, in rt2860_tx_raw()
1858 device_printf(sc->sc_dev, "can't map mbuf (error %d)\n", in rt2860_tx_raw()
1867 if (ring->queued + ntxds >= RT2860_TX_RING_COUNT) { in rt2860_tx_raw()
1869 bus_dmamap_unload(sc->txwi_dmat, data->map); in rt2860_tx_raw()
1878 txd = &ring->txd[ring->cur]; in rt2860_tx_raw()
1879 txd->sdp0 = htole32(data->paddr); in rt2860_tx_raw()
1880 txd->sdl0 = htole16(sizeof (struct rt2860_txwi) + pad); in rt2860_tx_raw()
1881 txd->flags = qsel; in rt2860_tx_raw()
1885 for (i = nsegs; i >= 2; i -= 2) { in rt2860_tx_raw()
1886 txd->sdp1 = htole32(seg->ds_addr); in rt2860_tx_raw()
1887 txd->sdl1 = htole16(seg->ds_len); in rt2860_tx_raw()
1889 ring->cur = (ring->cur + 1) % RT2860_TX_RING_COUNT; in rt2860_tx_raw()
1891 txd = &ring->txd[ring->cur]; in rt2860_tx_raw()
1892 txd->sdp0 = htole32(seg->ds_addr); in rt2860_tx_raw()
1893 txd->sdl0 = htole16(seg->ds_len); in rt2860_tx_raw()
1894 txd->flags = qsel; in rt2860_tx_raw()
1899 txd->sdp1 = htole32(seg->ds_addr); in rt2860_tx_raw()
1900 txd->sdl1 = htole16(seg->ds_len | RT2860_TX_LS1); in rt2860_tx_raw()
1902 txd->sdl0 |= htole16(RT2860_TX_LS0); in rt2860_tx_raw()
1903 txd->sdl1 = 0; in rt2860_tx_raw()
1907 SLIST_REMOVE_HEAD(&sc->data_pool, next); in rt2860_tx_raw()
1908 data->m = m; in rt2860_tx_raw()
1909 data->ni = ni; in rt2860_tx_raw()
1910 ring->data[ring->cur] = data; in rt2860_tx_raw()
1912 bus_dmamap_sync(sc->txwi_dmat, sc->txwi_map, BUS_DMASYNC_PREWRITE); in rt2860_tx_raw()
1913 bus_dmamap_sync(sc->txwi_dmat, data->map, BUS_DMASYNC_PREWRITE); in rt2860_tx_raw()
1914 bus_dmamap_sync(ring->desc_dmat, ring->desc_map, BUS_DMASYNC_PREWRITE); in rt2860_tx_raw()
1917 qid, txwi->wcid, nsegs, ridx)); in rt2860_tx_raw()
1919 ring->cur = (ring->cur + 1) % RT2860_TX_RING_COUNT; in rt2860_tx_raw()
1920 ring->queued += ntxds; in rt2860_tx_raw()
1921 if (ring->queued >= RT2860_TX_RING_COUNT) in rt2860_tx_raw()
1922 sc->qfullmsk |= 1 << qid; in rt2860_tx_raw()
1925 RAL_WRITE(sc, RT2860_TX_CTX_IDX(qid), ring->cur); in rt2860_tx_raw()
1933 struct rt2860_softc *sc = ic->ic_softc; in rt2860_transmit()
1937 if ((sc->sc_flags & RT2860_RUNNING) == 0) { in rt2860_transmit()
1941 error = mbufq_enqueue(&sc->sc_snd, m); in rt2860_transmit()
1960 if ((sc->sc_flags & RT2860_RUNNING) == 0) in rt2860_start()
1963 while (!SLIST_EMPTY(&sc->data_pool) && sc->qfullmsk == 0 && in rt2860_start()
1964 (m = mbufq_dequeue(&sc->sc_snd)) != NULL) { in rt2860_start()
1965 ni = (struct ieee80211_node *)m->m_pkthdr.rcvif; in rt2860_start()
1967 if_inc_counter(ni->ni_vap->iv_ifp, in rt2860_start()
1972 sc->sc_tx_timer = 5; in rt2860_start()
1983 KASSERT(sc->sc_flags & RT2860_RUNNING, ("not running")); in rt2860_watchdog()
1985 if (sc->sc_invalid) /* card ejected */ in rt2860_watchdog()
1988 if (sc->sc_tx_timer > 0 && --sc->sc_tx_timer == 0) { in rt2860_watchdog()
1989 device_printf(sc->sc_dev, "device timeout\n"); in rt2860_watchdog()
1992 counter_u64_add(sc->sc_ic.ic_oerrors, 1); in rt2860_watchdog()
1995 callout_reset(&sc->watchdog_ch, hz, rt2860_watchdog, sc); in rt2860_watchdog()
2001 struct rt2860_softc *sc = ic->ic_softc; in rt2860_parent()
2005 if (ic->ic_nrunning> 0) { in rt2860_parent()
2006 if (!(sc->sc_flags & RT2860_RUNNING)) { in rt2860_parent()
2011 } else if (sc->sc_flags & RT2860_RUNNING) in rt2860_parent()
2034 device_printf(sc->sc_dev, in rt2860_mcu_bbp_write()
2059 device_printf(sc->sc_dev, in rt2860_mcu_bbp_read()
2077 device_printf(sc->sc_dev, "could not read from BBP through MCU\n"); in rt2860_mcu_bbp_read()
2083 * Write to one of the 4 programmable 24-bit RF registers.
2097 device_printf(sc->sc_dev, "could not write to RF\n"); in rt2860_rf_write()
2101 /* RF registers are 24-bit on the RT2860 */ in rt2860_rf_write()
2119 device_printf(sc->sc_dev, "could not read RF register\n"); in rt3090_rf_read()
2132 device_printf(sc->sc_dev, "could not read RF register\n"); in rt3090_rf_read()
2150 device_printf(sc->sc_dev, "could not write to RF\n"); in rt3090_rf_write()
2217 OFDM(6) << 28 | /* 54->48 */ in rt2860_enable_mrr()
2218 OFDM(5) << 24 | /* 48->36 */ in rt2860_enable_mrr()
2219 OFDM(4) << 20 | /* 36->24 */ in rt2860_enable_mrr()
2220 OFDM(3) << 16 | /* 24->18 */ in rt2860_enable_mrr()
2221 OFDM(2) << 12 | /* 18->12 */ in rt2860_enable_mrr()
2222 OFDM(1) << 8 | /* 12-> 9 */ in rt2860_enable_mrr()
2223 OFDM(0) << 4 | /* 9-> 6 */ in rt2860_enable_mrr()
2224 OFDM(0)); /* 6-> 6 */ in rt2860_enable_mrr()
2227 CCK(2) << 12 | /* 11->5.5 */ in rt2860_enable_mrr()
2228 CCK(1) << 8 | /* 5.5-> 2 */ in rt2860_enable_mrr()
2229 CCK(0) << 4 | /* 2-> 1 */ in rt2860_enable_mrr()
2230 CCK(0)); /* 1-> 1 */ in rt2860_enable_mrr()
2238 struct ieee80211com *ic = &sc->sc_ic; in rt2860_set_txpreamble()
2243 if (ic->ic_flags & IEEE80211_F_SHPREAMBLE) in rt2860_set_txpreamble()
2252 struct ieee80211com *ic = &sc->sc_ic; in rt2860_set_basicrates()
2257 for (i = 0; i < rs->rs_nrates; i++) { in rt2860_set_basicrates()
2258 rate = rs->rs_rates[i]; in rt2860_set_basicrates()
2263 mask |= 1 << ieee80211_legacy_rate_lookup(ic->ic_rt, in rt2860_set_basicrates()
2273 struct rt2860_softc *sc = ic->ic_softc; in rt2860_scan_start()
2286 struct rt2860_softc *sc = ic->ic_softc; in rt2860_scan_end()
2287 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); in rt2860_scan_end()
2289 if (vap->iv_state == IEEE80211_S_RUN) { in rt2860_scan_end()
2299 struct rt2860_softc *sc = ic->ic_softc; in rt2860_getradiocaps()
2307 if (sc->rf_rev == RT2860_RF_2750 || sc->rf_rev == RT2860_RF_2850) { in rt2860_getradiocaps()
2317 struct rt2860_softc *sc = ic->ic_softc; in rt2860_set_channel()
2320 rt2860_switch_chan(sc, ic->ic_curchan); in rt2860_set_channel()
2330 rt2860_mcu_bbp_write(sc, 62, 0x37 - sc->lna[group]); in rt2860_select_chan_group()
2331 rt2860_mcu_bbp_write(sc, 63, 0x37 - sc->lna[group]); in rt2860_select_chan_group()
2332 rt2860_mcu_bbp_write(sc, 64, 0x37 - sc->lna[group]); in rt2860_select_chan_group()
2336 if (sc->ext_2ghz_lna) { in rt2860_select_chan_group()
2344 if (sc->ext_5ghz_lna) { in rt2860_select_chan_group()
2360 if (sc->nrxchains > 1) in rt2860_select_chan_group()
2362 if (sc->mac_ver == 0x3593 && sc->nrxchains > 2) in rt2860_select_chan_group()
2366 if (sc->ntxchains > 1) in rt2860_select_chan_group()
2368 if (sc->mac_ver == 0x3593 && sc->ntxchains > 2) in rt2860_select_chan_group()
2372 if (sc->ntxchains > 1) in rt2860_select_chan_group()
2374 if (sc->mac_ver == 0x3593 && sc->ntxchains > 2) in rt2860_select_chan_group()
2379 if (sc->mac_ver == 0x3593) { in rt2860_select_chan_group()
2381 if (sc->sc_flags & RT2860_PCIE) { in rt2860_select_chan_group()
2396 if (sc->mac_ver >= 0x3071) in rt2860_select_chan_group()
2397 agc = 0x1c + sc->lna[0] * 2; in rt2860_select_chan_group()
2399 agc = 0x2e + sc->lna[0]; in rt2860_select_chan_group()
2401 agc = 0x32 + (sc->lna[group] * 5) / 3; in rt2860_select_chan_group()
2420 if (sc->ntxchains == 1) in rt2860_set_chan()
2422 if (sc->nrxchains == 1) in rt2860_set_chan()
2424 else if (sc->nrxchains == 2) in rt2860_set_chan()
2428 txpow1 = sc->txpow1[i]; in rt2860_set_chan()
2429 txpow2 = sc->txpow2[i]; in rt2860_set_chan()
2441 r4 = rfprog[i].r4 | sc->freq << 13 | txpow2 << 4; in rt2860_set_chan()
2477 txpow1 = sc->txpow1[i]; in rt3090_set_chan()
2478 txpow2 = sc->txpow2[i]; in rt3090_set_chan()
2500 if (sc->ntxchains == 1) in rt3090_set_chan()
2502 else if (sc->ntxchains == 2) in rt3090_set_chan()
2504 if (sc->nrxchains == 1) in rt3090_set_chan()
2506 else if (sc->nrxchains == 2) in rt3090_set_chan()
2512 rf = (rf & ~0x7f) | sc->freq; in rt3090_set_chan()
2517 rf = (rf & ~0x3f) | sc->rf24_20mhz; in rt3090_set_chan()
2520 rf = (rf & ~0x3f) | sc->rf24_20mhz; in rt3090_set_chan()
2542 txpow1 = sc->txpow1[i]; in rt5390_set_chan()
2543 txpow2 = sc->txpow2[i]; in rt5390_set_chan()
2557 if (sc->mac_ver == 0x5392) { in rt5390_set_chan()
2568 if (sc->mac_ver == 0x5392) in rt5390_set_chan()
2579 rf = (rf & ~0x7f) | (sc->freq & 0x7f); in rt5390_set_chan()
2584 if (sc->mac_ver == 0x5390) { in rt5390_set_chan()
2613 h20mhz = (sc->rf24_20mhz & 0x20) >> 5; in rt5390_set_chan()
2644 if (sc->patch_dac && sc->mac_rev < 0x0211) in rt3090_rf_init()
2666 if (sc->mac_ver != 0x3593) { in rt3090_rf_init()
2668 sc->rf24_20mhz = 0x1f; /* default value */ in rt3090_rf_init()
2669 rt3090_filter_calib(sc, 0x07, 0x16, &sc->rf24_20mhz); in rt3090_rf_init()
2678 sc->rf24_40mhz = 0x2f; /* default value */ in rt3090_rf_init()
2679 rt3090_filter_calib(sc, 0x27, 0x19, &sc->rf24_40mhz); in rt3090_rf_init()
2685 if (sc->mac_rev < 0x0211) in rt3090_rf_init()
2691 if (sc->rf_rev == RT3070_RF_3020) in rt3090_rf_init()
2695 if (sc->mac_ver == 0x3593) { in rt3090_rf_init()
2696 if (sc->ntxchains == 1) in rt3090_rf_init()
2698 else if (sc->ntxchains == 2) in rt3090_rf_init()
2700 if (sc->nrxchains == 1) in rt3090_rf_init()
2702 else if (sc->nrxchains == 2) in rt3090_rf_init()
2705 if (sc->ntxchains == 1) in rt3090_rf_init()
2707 if (sc->nrxchains == 1) in rt3090_rf_init()
2722 if (sc->mac_rev >= 0x0211 && !sc->ext_2ghz_lna) in rt3090_rf_init()
2724 if (sc->txmixgain_2ghz >= 2) in rt3090_rf_init()
2725 rf = (rf & ~0x7) | sc->txmixgain_2ghz; in rt3090_rf_init()
2750 if (sc->mac_ver == 0x5392) { in rt5390_rf_init()
2762 sc->rf24_20mhz = 0x1f; in rt5390_rf_init()
2763 sc->rf24_40mhz = 0x2f; in rt5390_rf_init()
2765 if (sc->mac_rev < 0x0211) in rt5390_rf_init()
2774 if (sc->mac_ver == 0x5390) in rt5390_rf_init()
2783 if (sc->mac_rev >= 0x0211) in rt5390_rf_init()
2787 if (sc->ntxchains == 1) in rt5390_rf_init()
2789 if (sc->nrxchains == 1) in rt5390_rf_init()
2812 if (sc->mac_ver == 0x3593) { in rt3090_rf_wakeup()
2861 if (sc->mac_rev < 0x0211) in rt3090_rf_wakeup()
2865 if (sc->patch_dac && sc->mac_rev < 0x0211) { in rt3090_rf_wakeup()
2881 if (sc->mac_ver == 0x5392) in rt5390_rf_wakeup()
2887 if (sc->mac_ver == 0x5390) in rt5390_rf_wakeup()
2901 if (sc->patch_dac && sc->mac_rev < 0x0211) { in rt5390_rf_wakeup()
2948 delta = bbp55_pb - bbp55_sb; in rt3090_filter_calib()
2958 rf24--; /* backtrack */ in rt3090_filter_calib()
2979 if (sc->mac_rev >= 0x0211) { in rt3090_rf_setup()
2989 if (sc->mac_rev < 0x0211) { in rt3090_rf_setup()
2991 sc->patch_dac ? 0x2c : 0x0f); in rt3090_rf_setup()
2996 if (sc->mac_ver < 0x5390) { in rt3090_rf_setup()
2998 if (sc->rf[i].reg == 0 || sc->rf[i].reg == 0xff) in rt3090_rf_setup()
3000 rt3090_rf_write(sc, sc->rf[i].reg, sc->rf[i].val); in rt3090_rf_setup()
3009 which | (sc->leds & 0x7f), 0); in rt2860_set_leds()
3013 * Hardware has a general-purpose programmable timer interrupt that can
3059 struct rt2860_softc *sc = ic->ic_softc; in rt2860_updateslot()
3071 struct ieee80211com *ic = &sc->sc_ic; in rt2860_updateprot()
3076 tmp |= IEEE80211_IS_CHAN_5GHZ(ic->ic_curchan) ? in rt2860_updateprot()
3083 if (ic->ic_flags & IEEE80211_F_USEPROT) { in rt2860_updateprot()
3084 if (ic->ic_protmode == IEEE80211_PROT_RTSCTS) in rt2860_updateprot()
3086 else if (ic->ic_protmode == IEEE80211_PROT_CTSONLY) in rt2860_updateprot()
3095 struct rt2860_softc *sc = ic->ic_softc; in rt2860_update_promisc()
3100 if (ic->ic_promisc == 0) in rt2860_update_promisc()
3108 struct rt2860_softc *sc = ic->ic_softc; in rt2860_updateedca()
3157 struct rt2860_softc *sc = ic->ic_softc; in rt2860_set_key()
3163 if ((ic->ic_if.if_flags & (IFF_UP | IFF_RUNNING)) != in rt2860_set_key()
3167 /* map net80211 cipher to RT2860 security mode */ in rt2860_set_key()
3168 switch (k->k_cipher) { in rt2860_set_key()
3185 if (k->k_flags & IEEE80211_KEY_GROUP) { in rt2860_set_key()
3187 base = RT2860_SKEY(0, k->k_id); in rt2860_set_key()
3189 wcid = ((struct rt2860_node *)ni)->wcid; in rt2860_set_key()
3193 if (k->k_cipher == IEEE80211_CIPHER_TKIP) { in rt2860_set_key()
3194 RAL_WRITE_REGION_1(sc, base, k->k_key, 16); in rt2860_set_key()
3196 if (ic->ic_opmode == IEEE80211_M_HOSTAP) { in rt2860_set_key()
3197 RAL_WRITE_REGION_1(sc, base + 16, &k->k_key[16], 8); in rt2860_set_key()
3198 RAL_WRITE_REGION_1(sc, base + 24, &k->k_key[24], 8); in rt2860_set_key()
3202 RAL_WRITE_REGION_1(sc, base + 16, &k->k_key[24], 8); in rt2860_set_key()
3203 RAL_WRITE_REGION_1(sc, base + 24, &k->k_key[16], 8); in rt2860_set_key()
3206 RAL_WRITE_REGION_1(sc, base, k->k_key, k->k_len); in rt2860_set_key()
3208 if (!(k->k_flags & IEEE80211_KEY_GROUP) || in rt2860_set_key()
3209 (k->k_flags & IEEE80211_KEY_TX)) { in rt2860_set_key()
3211 if (k->k_cipher == IEEE80211_CIPHER_WEP40 || in rt2860_set_key()
3212 k->k_cipher == IEEE80211_CIPHER_WEP104) { in rt2860_set_key()
3220 iv[3] = k->k_id << 6; in rt2860_set_key()
3223 if (k->k_cipher == IEEE80211_CIPHER_TKIP) { in rt2860_set_key()
3224 iv[0] = k->k_tsc >> 8; in rt2860_set_key()
3226 iv[2] = k->k_tsc; in rt2860_set_key()
3228 iv[0] = k->k_tsc; in rt2860_set_key()
3229 iv[1] = k->k_tsc >> 8; in rt2860_set_key()
3232 iv[3] = k->k_id << 6 | IEEE80211_WEP_EXTIV; in rt2860_set_key()
3233 iv[4] = k->k_tsc >> 16; in rt2860_set_key()
3234 iv[5] = k->k_tsc >> 24; in rt2860_set_key()
3235 iv[6] = k->k_tsc >> 32; in rt2860_set_key()
3236 iv[7] = k->k_tsc >> 40; in rt2860_set_key()
3241 if (k->k_flags & IEEE80211_KEY_GROUP) { in rt2860_set_key()
3244 attr &= ~(0xf << (k->k_id * 4)); in rt2860_set_key()
3245 attr |= mode << (k->k_id * 4); in rt2860_set_key()
3260 struct rt2860_softc *sc = ic->ic_softc; in rt2860_delete_key()
3264 if (k->k_flags & IEEE80211_KEY_GROUP) { in rt2860_delete_key()
3267 attr &= ~(0xf << (k->k_id * 4)); in rt2860_delete_key()
3272 wcid = ((struct rt2860_node *)ni)->wcid; in rt2860_delete_key()
3283 struct ieee80211com *ic = &sc->sc_ic; in rt2860_rssi2dbm()
3284 struct ieee80211_channel *c = ic->ic_curchan; in rt2860_rssi2dbm()
3289 delta = sc->rssi_5ghz[rxchain]; in rt2860_rssi2dbm()
3293 delta -= sc->lna[1]; in rt2860_rssi2dbm()
3295 delta -= sc->lna[2]; in rt2860_rssi2dbm()
3297 delta -= sc->lna[3]; in rt2860_rssi2dbm()
3299 delta = sc->rssi_2ghz[rxchain] - sc->lna[0]; in rt2860_rssi2dbm()
3301 return -12 - delta - rssi; in rt2860_rssi2dbm()
3305 * Add `delta' (signed) to each 4-bit sub-word of a 32-bit word.
3306 * Used to adjust per-rate Tx power registers.
3355 sc->sc_srom_read = rt2860_eeprom_read_2; in rt2860_read_eeprom()
3356 if (sc->mac_ver >= 0x3071) { in rt2860_read_eeprom()
3360 sc->sc_srom_read = rt3090_efuse_read_2; in rt2860_read_eeprom()
3389 sc->bbp[i].val = val & 0xff; in rt2860_read_eeprom()
3390 sc->bbp[i].reg = val >> 8; in rt2860_read_eeprom()
3391 DPRINTF(("BBP%d=0x%02x\n", sc->bbp[i].reg, sc->bbp[i].val)); in rt2860_read_eeprom()
3393 if (sc->mac_ver >= 0x3071) { in rt2860_read_eeprom()
3397 sc->rf[i].val = val & 0xff; in rt2860_read_eeprom()
3398 sc->rf[i].reg = val >> 8; in rt2860_read_eeprom()
3399 DPRINTF(("RF%d=0x%02x\n", sc->rf[i].reg, in rt2860_read_eeprom()
3400 sc->rf[i].val)); in rt2860_read_eeprom()
3406 sc->freq = ((val & 0xff) != 0xff) ? val & 0xff : 0; in rt2860_read_eeprom()
3407 DPRINTF(("EEPROM freq offset %d\n", sc->freq & 0xff)); in rt2860_read_eeprom()
3410 sc->leds = val >> 8; in rt2860_read_eeprom()
3411 sc->led[0] = rt2860_srom_read(sc, RT2860_EEPROM_LED1); in rt2860_read_eeprom()
3412 sc->led[1] = rt2860_srom_read(sc, RT2860_EEPROM_LED2); in rt2860_read_eeprom()
3413 sc->led[2] = rt2860_srom_read(sc, RT2860_EEPROM_LED3); in rt2860_read_eeprom()
3416 sc->leds = 0x01; in rt2860_read_eeprom()
3417 sc->led[0] = 0x5555; in rt2860_read_eeprom()
3418 sc->led[1] = 0x2221; in rt2860_read_eeprom()
3419 sc->led[2] = 0xa9f8; in rt2860_read_eeprom()
3422 sc->leds, sc->led[0], sc->led[1], sc->led[2])); in rt2860_read_eeprom()
3426 if (sc->mac_ver >= 0x5390) in rt2860_read_eeprom()
3427 sc->rf_rev = rt2860_srom_read(sc, RT2860_EEPROM_CHIPID); in rt2860_read_eeprom()
3429 sc->rf_rev = (val >> 8) & 0xf; in rt2860_read_eeprom()
3430 sc->ntxchains = (val >> 4) & 0xf; in rt2860_read_eeprom()
3431 sc->nrxchains = val & 0xf; in rt2860_read_eeprom()
3433 sc->rf_rev, sc->ntxchains, sc->nrxchains)); in rt2860_read_eeprom()
3440 sc->patch_dac = (val >> 15) & 1; in rt2860_read_eeprom()
3442 sc->ext_5ghz_lna = (val >> 3) & 1; in rt2860_read_eeprom()
3443 sc->ext_2ghz_lna = (val >> 2) & 1; in rt2860_read_eeprom()
3445 sc->calib_2ghz = sc->calib_5ghz = 0; /* XXX (val >> 1) & 1 */ in rt2860_read_eeprom()
3447 sc->rfswitch = val & 1; in rt2860_read_eeprom()
3449 if (sc->sc_flags & RT2860_ADVANCED_PS) { in rt2860_read_eeprom()
3453 sc->pslevel = val & 0x3; in rt2860_read_eeprom()
3456 sc->pslevel = MIN(sc->pslevel, 1); in rt2860_read_eeprom()
3457 DPRINTF(("EEPROM PCIe PS Level=%d\n", sc->pslevel)); in rt2860_read_eeprom()
3465 sc->txpow1[i + 0] = (int8_t)(val & 0xff); in rt2860_read_eeprom()
3466 sc->txpow1[i + 1] = (int8_t)(val >> 8); in rt2860_read_eeprom()
3468 if (sc->mac_ver != 0x5390) { in rt2860_read_eeprom()
3471 sc->txpow2[i + 0] = (int8_t)(val & 0xff); in rt2860_read_eeprom()
3472 sc->txpow2[i + 1] = (int8_t)(val >> 8); in rt2860_read_eeprom()
3477 if (sc->txpow1[i] < 0 || in rt2860_read_eeprom()
3478 sc->txpow1[i] > ((sc->mac_ver >= 0x5390) ? 39 : 31)) in rt2860_read_eeprom()
3479 sc->txpow1[i] = 5; in rt2860_read_eeprom()
3480 if (sc->mac_ver != 0x5390) { in rt2860_read_eeprom()
3481 if (sc->txpow2[i] < 0 || in rt2860_read_eeprom()
3482 sc->txpow2[i] > ((sc->mac_ver == 0x5392) ? 39 : 31)) in rt2860_read_eeprom()
3483 sc->txpow2[i] = 5; in rt2860_read_eeprom()
3486 rt2860_rf2850[i].chan, sc->txpow1[i], sc->txpow2[i])); in rt2860_read_eeprom()
3492 sc->txpow1[i + 14] = (int8_t)(val & 0xff); in rt2860_read_eeprom()
3493 sc->txpow1[i + 15] = (int8_t)(val >> 8); in rt2860_read_eeprom()
3497 sc->txpow2[i + 14] = (int8_t)(val & 0xff); in rt2860_read_eeprom()
3498 sc->txpow2[i + 15] = (int8_t)(val >> 8); in rt2860_read_eeprom()
3502 if (sc->txpow1[14 + i] < -7 || sc->txpow1[14 + i] > 15) in rt2860_read_eeprom()
3503 sc->txpow1[14 + i] = 5; in rt2860_read_eeprom()
3504 if (sc->txpow2[14 + i] < -7 || sc->txpow2[14 + i] > 15) in rt2860_read_eeprom()
3505 sc->txpow2[14 + i] = 5; in rt2860_read_eeprom()
3507 rt2860_rf2850[14 + i].chan, sc->txpow1[14 + i], in rt2860_read_eeprom()
3508 sc->txpow2[14 + i])); in rt2860_read_eeprom()
3517 delta_2ghz = -delta_2ghz; in rt2860_read_eeprom()
3523 delta_5ghz = -delta_5ghz; in rt2860_read_eeprom()
3536 sc->txpow20mhz[ridx] = reg; in rt2860_read_eeprom()
3537 sc->txpow40mhz_2ghz[ridx] = b4inc(reg, delta_2ghz); in rt2860_read_eeprom()
3538 sc->txpow40mhz_5ghz[ridx] = b4inc(reg, delta_5ghz); in rt2860_read_eeprom()
3541 "40MHz/5GHz=0x%08x\n", ridx, sc->txpow20mhz[ridx], in rt2860_read_eeprom()
3542 sc->txpow40mhz_2ghz[ridx], sc->txpow40mhz_5ghz[ridx])); in rt2860_read_eeprom()
3545 /* read factory-calibrated samples for temperature compensation */ in rt2860_read_eeprom()
3547 sc->tssi_2ghz[0] = val & 0xff; /* [-4] */ in rt2860_read_eeprom()
3548 sc->tssi_2ghz[1] = val >> 8; /* [-3] */ in rt2860_read_eeprom()
3550 sc->tssi_2ghz[2] = val & 0xff; /* [-2] */ in rt2860_read_eeprom()
3551 sc->tssi_2ghz[3] = val >> 8; /* [-1] */ in rt2860_read_eeprom()
3553 sc->tssi_2ghz[4] = val & 0xff; /* [+0] */ in rt2860_read_eeprom()
3554 sc->tssi_2ghz[5] = val >> 8; /* [+1] */ in rt2860_read_eeprom()
3556 sc->tssi_2ghz[6] = val & 0xff; /* [+2] */ in rt2860_read_eeprom()
3557 sc->tssi_2ghz[7] = val >> 8; /* [+3] */ in rt2860_read_eeprom()
3559 sc->tssi_2ghz[8] = val & 0xff; /* [+4] */ in rt2860_read_eeprom()
3560 sc->step_2ghz = val >> 8; in rt2860_read_eeprom()
3562 "0x%02x 0x%02x step=%d\n", sc->tssi_2ghz[0], sc->tssi_2ghz[1], in rt2860_read_eeprom()
3563 sc->tssi_2ghz[2], sc->tssi_2ghz[3], sc->tssi_2ghz[4], in rt2860_read_eeprom()
3564 sc->tssi_2ghz[5], sc->tssi_2ghz[6], sc->tssi_2ghz[7], in rt2860_read_eeprom()
3565 sc->tssi_2ghz[8], sc->step_2ghz)); in rt2860_read_eeprom()
3567 if (sc->tssi_2ghz[4] == 0xff) in rt2860_read_eeprom()
3568 sc->calib_2ghz = 0; in rt2860_read_eeprom()
3571 sc->tssi_5ghz[0] = val & 0xff; /* [-4] */ in rt2860_read_eeprom()
3572 sc->tssi_5ghz[1] = val >> 8; /* [-3] */ in rt2860_read_eeprom()
3574 sc->tssi_5ghz[2] = val & 0xff; /* [-2] */ in rt2860_read_eeprom()
3575 sc->tssi_5ghz[3] = val >> 8; /* [-1] */ in rt2860_read_eeprom()
3577 sc->tssi_5ghz[4] = val & 0xff; /* [+0] */ in rt2860_read_eeprom()
3578 sc->tssi_5ghz[5] = val >> 8; /* [+1] */ in rt2860_read_eeprom()
3580 sc->tssi_5ghz[6] = val & 0xff; /* [+2] */ in rt2860_read_eeprom()
3581 sc->tssi_5ghz[7] = val >> 8; /* [+3] */ in rt2860_read_eeprom()
3583 sc->tssi_5ghz[8] = val & 0xff; /* [+4] */ in rt2860_read_eeprom()
3584 sc->step_5ghz = val >> 8; in rt2860_read_eeprom()
3586 "0x%02x 0x%02x step=%d\n", sc->tssi_5ghz[0], sc->tssi_5ghz[1], in rt2860_read_eeprom()
3587 sc->tssi_5ghz[2], sc->tssi_5ghz[3], sc->tssi_5ghz[4], in rt2860_read_eeprom()
3588 sc->tssi_5ghz[5], sc->tssi_5ghz[6], sc->tssi_5ghz[7], in rt2860_read_eeprom()
3589 sc->tssi_5ghz[8], sc->step_5ghz)); in rt2860_read_eeprom()
3591 if (sc->tssi_5ghz[4] == 0xff) in rt2860_read_eeprom()
3592 sc->calib_5ghz = 0; in rt2860_read_eeprom()
3596 sc->rssi_2ghz[0] = val & 0xff; /* Ant A */ in rt2860_read_eeprom()
3597 sc->rssi_2ghz[1] = val >> 8; /* Ant B */ in rt2860_read_eeprom()
3599 if (sc->mac_ver >= 0x3071) { in rt2860_read_eeprom()
3605 sc->txmixgain_2ghz = val & 0x7; in rt2860_read_eeprom()
3606 DPRINTF(("tx mixer gain=%u (2GHz)\n", sc->txmixgain_2ghz)); in rt2860_read_eeprom()
3608 sc->rssi_2ghz[2] = val & 0xff; /* Ant C */ in rt2860_read_eeprom()
3609 sc->lna[2] = val >> 8; /* channel group 2 */ in rt2860_read_eeprom()
3612 sc->rssi_5ghz[0] = val & 0xff; /* Ant A */ in rt2860_read_eeprom()
3613 sc->rssi_5ghz[1] = val >> 8; /* Ant B */ in rt2860_read_eeprom()
3615 sc->rssi_5ghz[2] = val & 0xff; /* Ant C */ in rt2860_read_eeprom()
3616 sc->lna[3] = val >> 8; /* channel group 3 */ in rt2860_read_eeprom()
3619 if (sc->mac_ver >= 0x3071) in rt2860_read_eeprom()
3620 sc->lna[0] = RT3090_DEF_LNA; in rt2860_read_eeprom()
3622 sc->lna[0] = val & 0xff; in rt2860_read_eeprom()
3623 sc->lna[1] = val >> 8; /* channel group 1 */ in rt2860_read_eeprom()
3626 if (sc->lna[2] == 0 || sc->lna[2] == 0xff) { in rt2860_read_eeprom()
3628 sc->lna[2] = sc->lna[1]; in rt2860_read_eeprom()
3630 if (sc->lna[3] == 0 || sc->lna[3] == 0xff) { in rt2860_read_eeprom()
3632 sc->lna[3] = sc->lna[1]; in rt2860_read_eeprom()
3637 if (sc->rssi_2ghz[ant] < -10 || sc->rssi_2ghz[ant] > 10) { in rt2860_read_eeprom()
3639 ant + 1, sc->rssi_2ghz[ant])); in rt2860_read_eeprom()
3640 sc->rssi_2ghz[ant] = 0; in rt2860_read_eeprom()
3642 if (sc->rssi_5ghz[ant] < -10 || sc->rssi_5ghz[ant] > 10) { in rt2860_read_eeprom()
3644 ant + 1, sc->rssi_5ghz[ant])); in rt2860_read_eeprom()
3645 sc->rssi_5ghz[ant] = 0; in rt2860_read_eeprom()
3664 device_printf(sc->sc_dev, in rt2860_bbp_init()
3670 if (sc->mac_ver >= 0x5390) in rt2860_bbp_init()
3680 if (sc->mac_ver == 0x2860 && sc->mac_rev != 0x0101) in rt2860_bbp_init()
3683 if (sc->mac_ver >= 0x3071) { in rt2860_bbp_init()
3687 } else if (sc->mac_ver == 0x2860 && sc->mac_rev == 0x0100) { in rt2860_bbp_init()
3702 if (sc->nrxchains > 1) { in rt5390_bbp_init()
3716 if (sc->mac_ver == 0x5392) { in rt5390_bbp_init()
3729 if (sc->mac_ver == 0x5390) in rt5390_bbp_init()
3736 struct ieee80211com *ic = &sc->sc_ic; in rt2860_txrx_enable()
3750 device_printf(sc->sc_dev, "timeout waiting for DMA engine\n"); in rt2860_txrx_enable()
3762 if (ic->ic_opmode != IEEE80211_M_MONITOR) { in rt2860_txrx_enable()
3767 if (ic->ic_opmode == IEEE80211_M_STA) in rt2860_txrx_enable()
3782 struct ieee80211com *ic = &sc->sc_ic; in rt2860_init()
3788 if (sc->sc_flags & RT2860_RUNNING) in rt2860_init()
3795 struct ieee80211com *ic = &sc->sc_ic; in rt2860_init_locked()
3796 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); in rt2860_init_locked()
3803 if (sc->rfswitch) { in rt2860_init_locked()
3806 device_printf(sc->sc_dev, in rt2860_init_locked()
3834 device_printf(sc->sc_dev, "could not load 8051 microcode\n"); in rt2860_init_locked()
3839 rt2860_set_macaddr(sc, vap ? vap->iv_myaddr : ic->ic_macaddr); in rt2860_init_locked()
3843 if (sc->txpow20mhz[ridx] == 0xffffffff) in rt2860_init_locked()
3845 RAL_WRITE(sc, RT2860_TX_PWR_CFG(ridx), sc->txpow20mhz[ridx]); in rt2860_init_locked()
3855 device_printf(sc->sc_dev, "timeout waiting for DMA engine\n"); in rt2860_init_locked()
3880 if (sc->mac_ver >= 0x5390) in rt2860_init_locked()
3882 else if (sc->mac_ver >= 0x3071) { in rt2860_init_locked()
3889 sc->sc_flags |= RT2860_PCIE; in rt2860_init_locked()
3904 device_printf(sc->sc_dev, "timeout waiting for MAC\n"); in rt2860_init_locked()
3936 RAL_WRITE(sc, RT2860_TX_BASE_PTR(qid), sc->txq[qid].paddr); in rt2860_init_locked()
3942 RAL_WRITE(sc, RT2860_RX_BASE_PTR, sc->rxq.paddr); in rt2860_init_locked()
3944 RAL_WRITE(sc, RT2860_RX_CALC_IDX, RT2860_RX_RING_COUNT - 1); in rt2860_init_locked()
3948 (MCLBYTES - sizeof (struct rt2860_rxwi) - 2)); in rt2860_init_locked()
3957 device_printf(sc->sc_dev, "timeout waiting for DMA engine\n"); in rt2860_init_locked()
3969 /* write vendor-specific BBP values (from EEPROM) */ in rt2860_init_locked()
3971 if (sc->bbp[i].reg == 0 || sc->bbp[i].reg == 0xff) in rt2860_init_locked()
3973 rt2860_mcu_bbp_write(sc, sc->bbp[i].reg, sc->bbp[i].val); in rt2860_init_locked()
3977 if (sc->rf_rev == RT3070_RF_2020 || in rt2860_init_locked()
3978 sc->rf_rev == RT3070_RF_3020 || in rt2860_init_locked()
3979 sc->rf_rev == RT3070_RF_3320 || in rt2860_init_locked()
3980 sc->mac_ver == 0x5390) in rt2860_init_locked()
3984 rt2860_mcu_cmd(sc, RT2860_MCU_CMD_LED1, sc->led[0], 0); in rt2860_init_locked()
3985 rt2860_mcu_cmd(sc, RT2860_MCU_CMD_LED2, sc->led[1], 0); in rt2860_init_locked()
3986 rt2860_mcu_cmd(sc, RT2860_MCU_CMD_LED3, sc->led[2], 0); in rt2860_init_locked()
3988 if (sc->mac_ver >= 0x5390) in rt2860_init_locked()
3990 else if (sc->mac_ver >= 0x3071) { in rt2860_init_locked()
4000 if (sc->mac_ver >= 0x5390) in rt2860_init_locked()
4002 else if (sc->mac_ver >= 0x3071) in rt2860_init_locked()
4005 /* disable non-existing Rx chains */ in rt2860_init_locked()
4008 if (sc->nrxchains == 2) in rt2860_init_locked()
4010 else if (sc->nrxchains == 3) in rt2860_init_locked()
4014 /* disable non-existing Tx chains */ in rt2860_init_locked()
4016 if (sc->ntxchains == 1) in rt2860_init_locked()
4018 else if (sc->mac_ver == 0x3593 && sc->ntxchains == 2) in rt2860_init_locked()
4020 else if (sc->mac_ver == 0x3593 && sc->ntxchains == 3) in rt2860_init_locked()
4024 if (sc->mac_ver >= 0x3071) in rt2860_init_locked()
4028 rt2860_switch_chan(sc, ic->ic_curchan); in rt2860_init_locked()
4056 if (sc->sc_flags & RT2860_ADVANCED_PS) in rt2860_init_locked()
4057 rt2860_mcu_cmd(sc, RT2860_MCU_CMD_PSLEVEL, sc->pslevel, 0); in rt2860_init_locked()
4059 sc->sc_flags |= RT2860_RUNNING; in rt2860_init_locked()
4061 callout_reset(&sc->watchdog_ch, hz, rt2860_watchdog, sc); in rt2860_init_locked()
4080 if (sc->sc_flags & RT2860_RUNNING) in rt2860_stop_locked()
4083 callout_stop(&sc->watchdog_ch); in rt2860_stop_locked()
4084 sc->sc_tx_timer = 0; in rt2860_stop_locked()
4085 sc->sc_flags &= ~RT2860_RUNNING; in rt2860_stop_locked()
4104 sc->qfullmsk = 0; in rt2860_stop_locked()
4106 rt2860_reset_tx_ring(sc, &sc->txq[qid]); in rt2860_stop_locked()
4107 rt2860_reset_rx_ring(sc, &sc->rxq); in rt2860_stop_locked()
4122 device_printf(sc->sc_dev, in rt2860_load_microcode()
4130 RAL_WRITE_REGION_1(sc, RT2860_FW_BASE, fp->data, fp->datasize); in rt2860_load_microcode()
4147 device_printf(sc->sc_dev, in rt2860_load_microcode()
4165 struct ieee80211com *ic = &sc->sc_ic; in rt2860_calib()
4173 if (IEEE80211_IS_CHAN_2GHZ(ic->ic_bss->ni_chan)) { in rt2860_calib()
4174 tssi = &sc->tssi_2ghz[4]; in rt2860_calib()
4175 step = sc->step_2ghz; in rt2860_calib()
4177 tssi = &sc->tssi_5ghz[4]; in rt2860_calib()
4178 step = sc->step_5ghz; in rt2860_calib()
4183 for (d = 0; d > -4 && bbp49 <= tssi[d - 1]; d--); in rt2860_calib()
4197 if (sc->txpow20mhz[ridx] == 0xffffffff) in rt2860_calib()
4200 b4inc(sc->txpow20mhz[ridx], d)); in rt2860_calib()
4211 if (sc->mac_ver == 0x5390) { in rt3090_set_rx_antenna()
4221 if (sc->mac_ver == 0x5390) { in rt3090_set_rx_antenna()
4236 struct ieee80211com *ic = &sc->sc_ic; in rt2860_switch_chan()
4243 if (sc->mac_ver >= 0x5390) in rt2860_switch_chan()
4245 else if (sc->mac_ver >= 0x3071) in rt2860_switch_chan()
4261 if (sc->mac_ver < 0x5390) in rt2860_switch_chan()
4270 struct ieee80211com *ic = vap->iv_ic; in rt2860_setup_beacon()
4275 if ((m = ieee80211_beacon_alloc(vap->iv_bss)) == NULL) in rt2860_setup_beacon()
4280 txwi.len = htole16(m->m_pkthdr.len); in rt2860_setup_beacon()
4282 ridx = IEEE80211_IS_CHAN_5GHZ(ic->ic_bsschan) ? in rt2860_setup_beacon()
4294 mtod(m, uint8_t *), m->m_pkthdr.len); in rt2860_setup_beacon()
4304 struct ieee80211com *ic = &sc->sc_ic; in rt2860_enable_tsf_sync()
4305 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); in rt2860_enable_tsf_sync()
4311 tmp |= vap->iv_bss->ni_intval * 16; in rt2860_enable_tsf_sync()
4313 if (vap->iv_opmode == IEEE80211_M_STA) { in rt2860_enable_tsf_sync()
4320 else if (vap->iv_opmode == IEEE80211_M_IBSS || in rt2860_enable_tsf_sync()
4321 vap->iv_opmode == IEEE80211_M_MBSS) { in rt2860_enable_tsf_sync()
4328 } else if (vap->iv_opmode == IEEE80211_M_HOSTAP) { in rt2860_enable_tsf_sync()