Lines Matching +full:4 +full:- +full:ring
2 /*-
20 /*-
70 if (sc->sc_debug > 0) \
74 if (sc->sc_debug >= (n)) \
204 struct ieee80211com *ic = &sc->sc_ic; in rt2661_attach()
208 sc->sc_id = id; in rt2661_attach()
209 sc->sc_dev = dev; in rt2661_attach()
211 mtx_init(&sc->sc_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK, in rt2661_attach()
214 callout_init_mtx(&sc->watchdog_ch, &sc->sc_mtx, 0); in rt2661_attach()
215 mbufq_init(&sc->sc_snd, ifqmaxlen); in rt2661_attach()
224 device_printf(sc->sc_dev, in rt2661_attach()
231 rt2661_read_eeprom(sc, ic->ic_macaddr); in rt2661_attach()
234 rt2661_get_rf(sc->rf_rev)); in rt2661_attach()
239 for (ac = 0; ac < 4; ac++) { in rt2661_attach()
240 error = rt2661_alloc_tx_ring(sc, &sc->txq[ac], in rt2661_attach()
243 device_printf(sc->sc_dev, in rt2661_attach()
244 "could not allocate Tx ring %d\n", ac); in rt2661_attach()
249 error = rt2661_alloc_tx_ring(sc, &sc->mgtq, RT2661_MGT_RING_COUNT); in rt2661_attach()
251 device_printf(sc->sc_dev, "could not allocate Mgt ring\n"); in rt2661_attach()
255 error = rt2661_alloc_rx_ring(sc, &sc->rxq, RT2661_RX_RING_COUNT); in rt2661_attach()
257 device_printf(sc->sc_dev, "could not allocate Rx ring\n"); in rt2661_attach()
261 ic->ic_softc = sc; in rt2661_attach()
262 ic->ic_name = device_get_nameunit(dev); in rt2661_attach()
263 ic->ic_opmode = IEEE80211_M_STA; in rt2661_attach()
264 ic->ic_phytype = IEEE80211_T_OFDM; /* not only, but not used */ in rt2661_attach()
267 ic->ic_caps = in rt2661_attach()
273 | IEEE80211_C_WDS /* 4-address traffic works */ in rt2661_attach()
285 rt2661_getradiocaps(ic, IEEE80211_CHAN_MAX, &ic->ic_nchans, in rt2661_attach()
286 ic->ic_channels); in rt2661_attach()
290 ic->ic_wme.wme_update = rt2661_wme_update; in rt2661_attach()
292 ic->ic_scan_start = rt2661_scan_start; in rt2661_attach()
293 ic->ic_scan_end = rt2661_scan_end; in rt2661_attach()
294 ic->ic_getradiocaps = rt2661_getradiocaps; in rt2661_attach()
295 ic->ic_set_channel = rt2661_set_channel; in rt2661_attach()
296 ic->ic_updateslot = rt2661_update_slot; in rt2661_attach()
297 ic->ic_update_promisc = rt2661_update_promisc; in rt2661_attach()
298 ic->ic_raw_xmit = rt2661_raw_xmit; in rt2661_attach()
299 ic->ic_transmit = rt2661_transmit; in rt2661_attach()
300 ic->ic_parent = rt2661_parent; in rt2661_attach()
301 ic->ic_vap_create = rt2661_vap_create; in rt2661_attach()
302 ic->ic_vap_delete = rt2661_vap_delete; in rt2661_attach()
305 &sc->sc_txtap.wt_ihdr, sizeof(sc->sc_txtap), in rt2661_attach()
307 &sc->sc_rxtap.wr_ihdr, sizeof(sc->sc_rxtap), in rt2661_attach()
313 "debug", CTLFLAG_RW, &sc->sc_debug, 0, "debug msgs"); in rt2661_attach()
320 fail3: rt2661_free_tx_ring(sc, &sc->mgtq); in rt2661_attach()
321 fail2: while (--ac >= 0) in rt2661_attach()
322 rt2661_free_tx_ring(sc, &sc->txq[ac]); in rt2661_attach()
323 fail1: mtx_destroy(&sc->sc_mtx); in rt2661_attach()
331 struct ieee80211com *ic = &sc->sc_ic; in rt2661_detach()
338 mbufq_drain(&sc->sc_snd); in rt2661_detach()
340 rt2661_free_tx_ring(sc, &sc->txq[0]); in rt2661_detach()
341 rt2661_free_tx_ring(sc, &sc->txq[1]); in rt2661_detach()
342 rt2661_free_tx_ring(sc, &sc->txq[2]); in rt2661_detach()
343 rt2661_free_tx_ring(sc, &sc->txq[3]); in rt2661_detach()
344 rt2661_free_tx_ring(sc, &sc->mgtq); in rt2661_detach()
345 rt2661_free_rx_ring(sc, &sc->rxq); in rt2661_detach()
347 mtx_destroy(&sc->sc_mtx); in rt2661_detach()
358 struct rt2661_softc *sc = ic->ic_softc; in rt2661_vap_create()
370 if (!TAILQ_EMPTY(&ic->ic_vaps)) { in rt2661_vap_create()
371 device_printf(sc->sc_dev, "only 1 vap supported\n"); in rt2661_vap_create()
378 if (TAILQ_EMPTY(&ic->ic_vaps) || in rt2661_vap_create()
379 ic->ic_opmode != IEEE80211_M_HOSTAP) { in rt2661_vap_create()
380 device_printf(sc->sc_dev, in rt2661_vap_create()
392 device_printf(sc->sc_dev, "unknown opmode %d\n", opmode); in rt2661_vap_create()
396 vap = &rvp->ral_vap; in rt2661_vap_create()
400 rvp->ral_newstate = vap->iv_newstate; in rt2661_vap_create()
401 vap->iv_newstate = rt2661_newstate; in rt2661_vap_create()
403 vap->iv_update_beacon = rt2661_beacon_update; in rt2661_vap_create()
410 if (TAILQ_FIRST(&ic->ic_vaps) == vap) in rt2661_vap_create()
411 ic->ic_opmode = opmode; in rt2661_vap_create()
446 if (sc->sc_ic.ic_nrunning > 0) in rt2661_resume()
462 rt2661_alloc_tx_ring(struct rt2661_softc *sc, struct rt2661_tx_ring *ring, in rt2661_alloc_tx_ring() argument
467 ring->count = count; in rt2661_alloc_tx_ring()
468 ring->queued = 0; in rt2661_alloc_tx_ring()
469 ring->cur = ring->next = ring->stat = 0; in rt2661_alloc_tx_ring()
471 error = bus_dma_tag_create(bus_get_dma_tag(sc->sc_dev), 4, 0, in rt2661_alloc_tx_ring()
474 0, NULL, NULL, &ring->desc_dmat); in rt2661_alloc_tx_ring()
476 device_printf(sc->sc_dev, "could not create desc DMA tag\n"); in rt2661_alloc_tx_ring()
480 error = bus_dmamem_alloc(ring->desc_dmat, (void **)&ring->desc, in rt2661_alloc_tx_ring()
481 BUS_DMA_NOWAIT | BUS_DMA_ZERO, &ring->desc_map); in rt2661_alloc_tx_ring()
483 device_printf(sc->sc_dev, "could not allocate DMA memory\n"); in rt2661_alloc_tx_ring()
487 error = bus_dmamap_load(ring->desc_dmat, ring->desc_map, ring->desc, in rt2661_alloc_tx_ring()
488 count * RT2661_TX_DESC_SIZE, rt2661_dma_map_addr, &ring->physaddr, in rt2661_alloc_tx_ring()
491 device_printf(sc->sc_dev, "could not load desc DMA map\n"); in rt2661_alloc_tx_ring()
495 ring->data = malloc(count * sizeof (struct rt2661_tx_data), M_DEVBUF, in rt2661_alloc_tx_ring()
497 if (ring->data == NULL) { in rt2661_alloc_tx_ring()
498 device_printf(sc->sc_dev, "could not allocate soft data\n"); in rt2661_alloc_tx_ring()
503 error = bus_dma_tag_create(bus_get_dma_tag(sc->sc_dev), 1, 0, in rt2661_alloc_tx_ring()
505 RT2661_MAX_SCATTER, MCLBYTES, 0, NULL, NULL, &ring->data_dmat); in rt2661_alloc_tx_ring()
507 device_printf(sc->sc_dev, "could not create data DMA tag\n"); in rt2661_alloc_tx_ring()
512 error = bus_dmamap_create(ring->data_dmat, 0, in rt2661_alloc_tx_ring()
513 &ring->data[i].map); in rt2661_alloc_tx_ring()
515 device_printf(sc->sc_dev, "could not create DMA map\n"); in rt2661_alloc_tx_ring()
522 fail: rt2661_free_tx_ring(sc, ring); in rt2661_alloc_tx_ring()
527 rt2661_reset_tx_ring(struct rt2661_softc *sc, struct rt2661_tx_ring *ring) in rt2661_reset_tx_ring() argument
533 for (i = 0; i < ring->count; i++) { in rt2661_reset_tx_ring()
534 desc = &ring->desc[i]; in rt2661_reset_tx_ring()
535 data = &ring->data[i]; in rt2661_reset_tx_ring()
537 if (data->m != NULL) { in rt2661_reset_tx_ring()
538 bus_dmamap_sync(ring->data_dmat, data->map, in rt2661_reset_tx_ring()
540 bus_dmamap_unload(ring->data_dmat, data->map); in rt2661_reset_tx_ring()
541 m_freem(data->m); in rt2661_reset_tx_ring()
542 data->m = NULL; in rt2661_reset_tx_ring()
545 if (data->ni != NULL) { in rt2661_reset_tx_ring()
546 ieee80211_free_node(data->ni); in rt2661_reset_tx_ring()
547 data->ni = NULL; in rt2661_reset_tx_ring()
550 desc->flags = 0; in rt2661_reset_tx_ring()
553 bus_dmamap_sync(ring->desc_dmat, ring->desc_map, BUS_DMASYNC_PREWRITE); in rt2661_reset_tx_ring()
555 ring->queued = 0; in rt2661_reset_tx_ring()
556 ring->cur = ring->next = ring->stat = 0; in rt2661_reset_tx_ring()
560 rt2661_free_tx_ring(struct rt2661_softc *sc, struct rt2661_tx_ring *ring) in rt2661_free_tx_ring() argument
565 if (ring->desc != NULL) { in rt2661_free_tx_ring()
566 bus_dmamap_sync(ring->desc_dmat, ring->desc_map, in rt2661_free_tx_ring()
568 bus_dmamap_unload(ring->desc_dmat, ring->desc_map); in rt2661_free_tx_ring()
569 bus_dmamem_free(ring->desc_dmat, ring->desc, ring->desc_map); in rt2661_free_tx_ring()
572 if (ring->desc_dmat != NULL) in rt2661_free_tx_ring()
573 bus_dma_tag_destroy(ring->desc_dmat); in rt2661_free_tx_ring()
575 if (ring->data != NULL) { in rt2661_free_tx_ring()
576 for (i = 0; i < ring->count; i++) { in rt2661_free_tx_ring()
577 data = &ring->data[i]; in rt2661_free_tx_ring()
579 if (data->m != NULL) { in rt2661_free_tx_ring()
580 bus_dmamap_sync(ring->data_dmat, data->map, in rt2661_free_tx_ring()
582 bus_dmamap_unload(ring->data_dmat, data->map); in rt2661_free_tx_ring()
583 m_freem(data->m); in rt2661_free_tx_ring()
586 if (data->ni != NULL) in rt2661_free_tx_ring()
587 ieee80211_free_node(data->ni); in rt2661_free_tx_ring()
589 if (data->map != NULL) in rt2661_free_tx_ring()
590 bus_dmamap_destroy(ring->data_dmat, data->map); in rt2661_free_tx_ring()
593 free(ring->data, M_DEVBUF); in rt2661_free_tx_ring()
596 if (ring->data_dmat != NULL) in rt2661_free_tx_ring()
597 bus_dma_tag_destroy(ring->data_dmat); in rt2661_free_tx_ring()
601 rt2661_alloc_rx_ring(struct rt2661_softc *sc, struct rt2661_rx_ring *ring, in rt2661_alloc_rx_ring() argument
609 ring->count = count; in rt2661_alloc_rx_ring()
610 ring->cur = ring->next = 0; in rt2661_alloc_rx_ring()
612 error = bus_dma_tag_create(bus_get_dma_tag(sc->sc_dev), 4, 0, in rt2661_alloc_rx_ring()
615 0, NULL, NULL, &ring->desc_dmat); in rt2661_alloc_rx_ring()
617 device_printf(sc->sc_dev, "could not create desc DMA tag\n"); in rt2661_alloc_rx_ring()
621 error = bus_dmamem_alloc(ring->desc_dmat, (void **)&ring->desc, in rt2661_alloc_rx_ring()
622 BUS_DMA_NOWAIT | BUS_DMA_ZERO, &ring->desc_map); in rt2661_alloc_rx_ring()
624 device_printf(sc->sc_dev, "could not allocate DMA memory\n"); in rt2661_alloc_rx_ring()
628 error = bus_dmamap_load(ring->desc_dmat, ring->desc_map, ring->desc, in rt2661_alloc_rx_ring()
629 count * RT2661_RX_DESC_SIZE, rt2661_dma_map_addr, &ring->physaddr, in rt2661_alloc_rx_ring()
632 device_printf(sc->sc_dev, "could not load desc DMA map\n"); in rt2661_alloc_rx_ring()
636 ring->data = malloc(count * sizeof (struct rt2661_rx_data), M_DEVBUF, in rt2661_alloc_rx_ring()
638 if (ring->data == NULL) { in rt2661_alloc_rx_ring()
639 device_printf(sc->sc_dev, "could not allocate soft data\n"); in rt2661_alloc_rx_ring()
645 * Pre-allocate Rx buffers and populate Rx ring. in rt2661_alloc_rx_ring()
647 error = bus_dma_tag_create(bus_get_dma_tag(sc->sc_dev), 1, 0, in rt2661_alloc_rx_ring()
649 1, MCLBYTES, 0, NULL, NULL, &ring->data_dmat); in rt2661_alloc_rx_ring()
651 device_printf(sc->sc_dev, "could not create data DMA tag\n"); in rt2661_alloc_rx_ring()
656 desc = &sc->rxq.desc[i]; in rt2661_alloc_rx_ring()
657 data = &sc->rxq.data[i]; in rt2661_alloc_rx_ring()
659 error = bus_dmamap_create(ring->data_dmat, 0, &data->map); in rt2661_alloc_rx_ring()
661 device_printf(sc->sc_dev, "could not create DMA map\n"); in rt2661_alloc_rx_ring()
665 data->m = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR); in rt2661_alloc_rx_ring()
666 if (data->m == NULL) { in rt2661_alloc_rx_ring()
667 device_printf(sc->sc_dev, in rt2661_alloc_rx_ring()
673 error = bus_dmamap_load(ring->data_dmat, data->map, in rt2661_alloc_rx_ring()
674 mtod(data->m, void *), MCLBYTES, rt2661_dma_map_addr, in rt2661_alloc_rx_ring()
677 device_printf(sc->sc_dev, in rt2661_alloc_rx_ring()
682 desc->flags = htole32(RT2661_RX_BUSY); in rt2661_alloc_rx_ring()
683 desc->physaddr = htole32(physaddr); in rt2661_alloc_rx_ring()
686 bus_dmamap_sync(ring->desc_dmat, ring->desc_map, BUS_DMASYNC_PREWRITE); in rt2661_alloc_rx_ring()
690 fail: rt2661_free_rx_ring(sc, ring); in rt2661_alloc_rx_ring()
695 rt2661_reset_rx_ring(struct rt2661_softc *sc, struct rt2661_rx_ring *ring) in rt2661_reset_rx_ring() argument
699 for (i = 0; i < ring->count; i++) in rt2661_reset_rx_ring()
700 ring->desc[i].flags = htole32(RT2661_RX_BUSY); in rt2661_reset_rx_ring()
702 bus_dmamap_sync(ring->desc_dmat, ring->desc_map, BUS_DMASYNC_PREWRITE); in rt2661_reset_rx_ring()
704 ring->cur = ring->next = 0; in rt2661_reset_rx_ring()
708 rt2661_free_rx_ring(struct rt2661_softc *sc, struct rt2661_rx_ring *ring) in rt2661_free_rx_ring() argument
713 if (ring->desc != NULL) { in rt2661_free_rx_ring()
714 bus_dmamap_sync(ring->desc_dmat, ring->desc_map, in rt2661_free_rx_ring()
716 bus_dmamap_unload(ring->desc_dmat, ring->desc_map); in rt2661_free_rx_ring()
717 bus_dmamem_free(ring->desc_dmat, ring->desc, ring->desc_map); in rt2661_free_rx_ring()
720 if (ring->desc_dmat != NULL) in rt2661_free_rx_ring()
721 bus_dma_tag_destroy(ring->desc_dmat); in rt2661_free_rx_ring()
723 if (ring->data != NULL) { in rt2661_free_rx_ring()
724 for (i = 0; i < ring->count; i++) { in rt2661_free_rx_ring()
725 data = &ring->data[i]; in rt2661_free_rx_ring()
727 if (data->m != NULL) { in rt2661_free_rx_ring()
728 bus_dmamap_sync(ring->data_dmat, data->map, in rt2661_free_rx_ring()
730 bus_dmamap_unload(ring->data_dmat, data->map); in rt2661_free_rx_ring()
731 m_freem(data->m); in rt2661_free_rx_ring()
734 if (data->map != NULL) in rt2661_free_rx_ring()
735 bus_dmamap_destroy(ring->data_dmat, data->map); in rt2661_free_rx_ring()
738 free(ring->data, M_DEVBUF); in rt2661_free_rx_ring()
741 if (ring->data_dmat != NULL) in rt2661_free_rx_ring()
742 bus_dma_tag_destroy(ring->data_dmat); in rt2661_free_rx_ring()
749 struct ieee80211com *ic = vap->iv_ic; in rt2661_newstate()
750 struct rt2661_softc *sc = ic->ic_softc; in rt2661_newstate()
753 if (nstate == IEEE80211_S_INIT && vap->iv_state == IEEE80211_S_RUN) { in rt2661_newstate()
761 error = rvp->ral_newstate(vap, nstate, arg); in rt2661_newstate()
764 struct ieee80211_node *ni = vap->iv_bss; in rt2661_newstate()
766 if (vap->iv_opmode != IEEE80211_M_MONITOR) { in rt2661_newstate()
769 rt2661_set_basicrates(sc, &ni->ni_rates); in rt2661_newstate()
770 rt2661_set_bssid(sc, ni->ni_bssid); in rt2661_newstate()
773 if (vap->iv_opmode == IEEE80211_M_HOSTAP || in rt2661_newstate()
774 vap->iv_opmode == IEEE80211_M_IBSS || in rt2661_newstate()
775 vap->iv_opmode == IEEE80211_M_MBSS) { in rt2661_newstate()
780 if (vap->iv_opmode != IEEE80211_M_MONITOR) in rt2661_newstate()
816 /* write address (A5-A0 or A7-A0) */ in rt2661_eeprom_read()
818 for (; n >= 0; n--) { in rt2661_eeprom_read()
827 /* read data Q15-Q0 */ in rt2661_eeprom_read()
829 for (n = 15; n >= 0; n--) { in rt2661_eeprom_read()
849 struct ieee80211_ratectl_tx_status *txs = &sc->sc_txs; in rt2661_tx_intr()
855 txs->flags = IEEE80211_RATECTL_TX_FAIL_LONG; in rt2661_tx_intr()
866 txq = (qid <= 3) ? &sc->txq[qid] : &sc->mgtq; in rt2661_tx_intr()
869 data = &txq->data[txq->stat]; in rt2661_tx_intr()
870 m = data->m; in rt2661_tx_intr()
871 data->m = NULL; in rt2661_tx_intr()
872 ni = data->ni; in rt2661_tx_intr()
873 data->ni = NULL; in rt2661_tx_intr()
881 txs->status = IEEE80211_RATECTL_TX_SUCCESS; in rt2661_tx_intr()
882 txs->long_retries = RT2661_TX_RETRYCNT(val); in rt2661_tx_intr()
885 "%d retries\n", txs->long_retries); in rt2661_tx_intr()
886 if (data->rix != IEEE80211_FIXED_RATE_NONE) in rt2661_tx_intr()
892 txs->status = IEEE80211_RATECTL_TX_FAIL_LONG; in rt2661_tx_intr()
893 txs->long_retries = RT2661_TX_RETRYCNT(val); in rt2661_tx_intr()
897 if (data->rix != IEEE80211_FIXED_RATE_NONE) in rt2661_tx_intr()
904 device_printf(sc->sc_dev, in rt2661_tx_intr()
909 DPRINTFN(sc, 15, "tx done q=%d idx=%u\n", qid, txq->stat); in rt2661_tx_intr()
911 txq->queued--; in rt2661_tx_intr()
912 if (++txq->stat >= txq->count) /* faster than % count */ in rt2661_tx_intr()
913 txq->stat = 0; in rt2661_tx_intr()
918 sc->sc_tx_timer = 0; in rt2661_tx_intr()
929 bus_dmamap_sync(txq->desc_dmat, txq->desc_map, BUS_DMASYNC_POSTREAD); in rt2661_tx_dma_intr()
932 desc = &txq->desc[txq->next]; in rt2661_tx_dma_intr()
933 data = &txq->data[txq->next]; in rt2661_tx_dma_intr()
935 if ((le32toh(desc->flags) & RT2661_TX_BUSY) || in rt2661_tx_dma_intr()
936 !(le32toh(desc->flags) & RT2661_TX_VALID)) in rt2661_tx_dma_intr()
939 bus_dmamap_sync(txq->data_dmat, data->map, in rt2661_tx_dma_intr()
941 bus_dmamap_unload(txq->data_dmat, data->map); in rt2661_tx_dma_intr()
944 desc->flags &= ~htole32(RT2661_TX_VALID); in rt2661_tx_dma_intr()
946 DPRINTFN(sc, 15, "tx dma done q=%p idx=%u\n", txq, txq->next); in rt2661_tx_dma_intr()
948 if (++txq->next >= txq->count) /* faster than % count */ in rt2661_tx_dma_intr()
949 txq->next = 0; in rt2661_tx_dma_intr()
952 bus_dmamap_sync(txq->desc_dmat, txq->desc_map, BUS_DMASYNC_PREWRITE); in rt2661_tx_dma_intr()
958 struct ieee80211com *ic = &sc->sc_ic; in rt2661_rx_intr()
967 bus_dmamap_sync(sc->rxq.desc_dmat, sc->rxq.desc_map, in rt2661_rx_intr()
973 desc = &sc->rxq.desc[sc->rxq.cur]; in rt2661_rx_intr()
974 data = &sc->rxq.data[sc->rxq.cur]; in rt2661_rx_intr()
976 if (le32toh(desc->flags) & RT2661_RX_BUSY) in rt2661_rx_intr()
979 if ((le32toh(desc->flags) & RT2661_RX_PHY_ERROR) || in rt2661_rx_intr()
980 (le32toh(desc->flags) & RT2661_RX_CRC_ERROR)) { in rt2661_rx_intr()
986 le32toh(desc->flags)); in rt2661_rx_intr()
987 counter_u64_add(ic->ic_ierrors, 1); in rt2661_rx_intr()
991 if ((le32toh(desc->flags) & RT2661_RX_CIPHER_MASK) != 0) { in rt2661_rx_intr()
992 counter_u64_add(ic->ic_ierrors, 1); in rt2661_rx_intr()
997 * Try to allocate a new mbuf for this ring element and load it in rt2661_rx_intr()
998 * before processing the current mbuf. If the ring element in rt2661_rx_intr()
1005 counter_u64_add(ic->ic_ierrors, 1); in rt2661_rx_intr()
1009 bus_dmamap_sync(sc->rxq.data_dmat, data->map, in rt2661_rx_intr()
1011 bus_dmamap_unload(sc->rxq.data_dmat, data->map); in rt2661_rx_intr()
1013 error = bus_dmamap_load(sc->rxq.data_dmat, data->map, in rt2661_rx_intr()
1020 error = bus_dmamap_load(sc->rxq.data_dmat, data->map, in rt2661_rx_intr()
1021 mtod(data->m, void *), MCLBYTES, in rt2661_rx_intr()
1026 device_get_name(sc->sc_dev)); in rt2661_rx_intr()
1028 counter_u64_add(ic->ic_ierrors, 1); in rt2661_rx_intr()
1033 * New mbuf successfully loaded, update Rx ring and continue in rt2661_rx_intr()
1036 m = data->m; in rt2661_rx_intr()
1037 data->m = mnew; in rt2661_rx_intr()
1038 desc->physaddr = htole32(physaddr); in rt2661_rx_intr()
1041 m->m_pkthdr.len = m->m_len = in rt2661_rx_intr()
1042 (le32toh(desc->flags) >> 16) & 0xfff; in rt2661_rx_intr()
1044 rssi = rt2661_get_rssi(sc, desc->rssi); in rt2661_rx_intr()
1047 rssi = -30; /* XXX ignored by net80211 */ in rt2661_rx_intr()
1051 struct rt2661_rx_radiotap_header *tap = &sc->sc_rxtap; in rt2661_rx_intr()
1058 tap->wr_tsf = in rt2661_rx_intr()
1060 tap->wr_flags = 0; in rt2661_rx_intr()
1061 tap->wr_rate = ieee80211_plcp2rate(desc->rate, in rt2661_rx_intr()
1062 (desc->flags & htole32(RT2661_RX_OFDM)) ? in rt2661_rx_intr()
1064 tap->wr_antsignal = nf + rssi; in rt2661_rx_intr()
1065 tap->wr_antnoise = nf; in rt2661_rx_intr()
1067 sc->sc_flags |= RAL_INPUT_RUNNING; in rt2661_rx_intr()
1081 sc->sc_flags &= ~RAL_INPUT_RUNNING; in rt2661_rx_intr()
1083 skip: desc->flags |= htole32(RT2661_RX_BUSY); in rt2661_rx_intr()
1085 DPRINTFN(sc, 15, "rx intr idx=%u\n", sc->rxq.cur); in rt2661_rx_intr()
1087 sc->rxq.cur = (sc->rxq.cur + 1) % RT2661_RX_RING_COUNT; in rt2661_rx_intr()
1090 bus_dmamap_sync(sc->rxq.desc_dmat, sc->rxq.desc_map, in rt2661_rx_intr()
1133 /* don't re-enable interrupts if we're shutting down */ in rt2661_intr()
1134 if (!(sc->sc_flags & RAL_RUNNING)) { in rt2661_intr()
1146 rt2661_tx_dma_intr(sc, &sc->mgtq); in rt2661_intr()
1152 rt2661_tx_dma_intr(sc, &sc->txq[0]); in rt2661_intr()
1155 rt2661_tx_dma_intr(sc, &sc->txq[1]); in rt2661_intr()
1158 rt2661_tx_dma_intr(sc, &sc->txq[2]); in rt2661_intr()
1161 rt2661_tx_dma_intr(sc, &sc->txq[3]); in rt2661_intr()
1175 /* re-enable MAC and MCU interrupts */ in rt2661_intr()
1186 /* OFDM rates (cf IEEE Std 802.11a-1999, pp. 14 Table 80) */ in rt2661_plcp_signal()
1196 /* CCK rates (NB: not IEEE std, device-specific) */ in rt2661_plcp_signal()
1198 case 4: return 0x1; in rt2661_plcp_signal()
1210 struct ieee80211com *ic = &sc->sc_ic; in rt2661_setup_tx_desc()
1214 desc->flags = htole32(flags); in rt2661_setup_tx_desc()
1215 desc->flags |= htole32(len << 16); in rt2661_setup_tx_desc()
1216 desc->flags |= htole32(RT2661_TX_BUSY | RT2661_TX_VALID); in rt2661_setup_tx_desc()
1218 desc->xflags = htole16(xflags); in rt2661_setup_tx_desc()
1219 desc->xflags |= htole16(nsegs << 13); in rt2661_setup_tx_desc()
1221 desc->wme = htole16( in rt2661_setup_tx_desc()
1224 RT2661_LOGCWMIN(4) | in rt2661_setup_tx_desc()
1232 desc->qid = ac; in rt2661_setup_tx_desc()
1235 desc->plcp_signal = rt2661_plcp_signal(rate); in rt2661_setup_tx_desc()
1236 desc->plcp_service = 4; in rt2661_setup_tx_desc()
1239 if (ieee80211_rate2phytype(ic->ic_rt, rate) == IEEE80211_T_OFDM) { in rt2661_setup_tx_desc()
1240 desc->flags |= htole32(RT2661_TX_OFDM); in rt2661_setup_tx_desc()
1243 desc->plcp_length_hi = plcp_length >> 6; in rt2661_setup_tx_desc()
1244 desc->plcp_length_lo = plcp_length & 0x3f; in rt2661_setup_tx_desc()
1250 desc->plcp_service |= RT2661_PLCP_LENGEXT; in rt2661_setup_tx_desc()
1252 desc->plcp_length_hi = plcp_length >> 8; in rt2661_setup_tx_desc()
1253 desc->plcp_length_lo = plcp_length & 0xff; in rt2661_setup_tx_desc()
1255 if (rate != 2 && (ic->ic_flags & IEEE80211_F_SHPREAMBLE)) in rt2661_setup_tx_desc()
1256 desc->plcp_signal |= 0x08; in rt2661_setup_tx_desc()
1261 desc->addr[i] = htole32(segs[i].ds_addr); in rt2661_setup_tx_desc()
1262 desc->len [i] = htole16(segs[i].ds_len); in rt2661_setup_tx_desc()
1270 struct ieee80211vap *vap = ni->ni_vap; in rt2661_tx_mgt()
1271 struct ieee80211com *ic = ni->ni_ic; in rt2661_tx_mgt()
1281 desc = &sc->mgtq.desc[sc->mgtq.cur]; in rt2661_tx_mgt()
1282 data = &sc->mgtq.data[sc->mgtq.cur]; in rt2661_tx_mgt()
1284 rate = ni->ni_txparms->mgmtrate; in rt2661_tx_mgt()
1288 if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) { in rt2661_tx_mgt()
1296 error = bus_dmamap_load_mbuf_sg(sc->mgtq.data_dmat, data->map, m0, in rt2661_tx_mgt()
1299 device_printf(sc->sc_dev, "could not map mbuf (error %d)\n", in rt2661_tx_mgt()
1306 struct rt2661_tx_radiotap_header *tap = &sc->sc_txtap; in rt2661_tx_mgt()
1308 tap->wt_flags = 0; in rt2661_tx_mgt()
1309 tap->wt_rate = rate; in rt2661_tx_mgt()
1314 data->m = m0; in rt2661_tx_mgt()
1315 data->ni = ni; in rt2661_tx_mgt()
1317 data->rix = IEEE80211_FIXED_RATE_NONE; in rt2661_tx_mgt()
1321 if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) { in rt2661_tx_mgt()
1324 dur = ieee80211_ack_duration(ic->ic_rt, in rt2661_tx_mgt()
1325 rate, ic->ic_flags & IEEE80211_F_SHPREAMBLE); in rt2661_tx_mgt()
1326 *(uint16_t *)wh->i_dur = htole16(dur); in rt2661_tx_mgt()
1334 m0->m_pkthdr.len, rate, segs, nsegs, RT2661_QID_MGT); in rt2661_tx_mgt()
1336 bus_dmamap_sync(sc->mgtq.data_dmat, data->map, BUS_DMASYNC_PREWRITE); in rt2661_tx_mgt()
1337 bus_dmamap_sync(sc->mgtq.desc_dmat, sc->mgtq.desc_map, in rt2661_tx_mgt()
1341 m0->m_pkthdr.len, sc->mgtq.cur, rate); in rt2661_tx_mgt()
1344 sc->mgtq.queued++; in rt2661_tx_mgt()
1345 sc->mgtq.cur = (sc->mgtq.cur + 1) % RT2661_MGT_RING_COUNT; in rt2661_tx_mgt()
1355 struct ieee80211com *ic = ni->ni_ic; in rt2661_sendprot()
1356 struct rt2661_tx_ring *txq = &sc->txq[ac]; in rt2661_sendprot()
1366 if_inc_counter(ni->ni_vap->iv_ifp, IFCOUNTER_OERRORS, 1); in rt2661_sendprot()
1367 device_printf(sc->sc_dev, in rt2661_sendprot()
1372 data = &txq->data[txq->cur]; in rt2661_sendprot()
1373 desc = &txq->desc[txq->cur]; in rt2661_sendprot()
1375 error = bus_dmamap_load_mbuf_sg(txq->data_dmat, data->map, mprot, segs, in rt2661_sendprot()
1378 device_printf(sc->sc_dev, in rt2661_sendprot()
1384 data->m = mprot; in rt2661_sendprot()
1385 data->ni = ieee80211_ref_node(ni); in rt2661_sendprot()
1387 data->rix = IEEE80211_FIXED_RATE_NONE; in rt2661_sendprot()
1389 protrate = ieee80211_ctl_rate(ic->ic_rt, rate); in rt2661_sendprot()
1394 rt2661_setup_tx_desc(sc, desc, flags, 0, mprot->m_pkthdr.len, in rt2661_sendprot()
1397 bus_dmamap_sync(txq->data_dmat, data->map, BUS_DMASYNC_PREWRITE); in rt2661_sendprot()
1398 bus_dmamap_sync(txq->desc_dmat, txq->desc_map, BUS_DMASYNC_PREWRITE); in rt2661_sendprot()
1400 txq->queued++; in rt2661_sendprot()
1401 txq->cur = (txq->cur + 1) % RT2661_TX_RING_COUNT; in rt2661_sendprot()
1410 struct ieee80211vap *vap = ni->ni_vap; in rt2661_tx_data()
1411 struct ieee80211com *ic = &sc->sc_ic; in rt2661_tx_data()
1412 struct rt2661_tx_ring *txq = &sc->txq[ac]; in rt2661_tx_data()
1416 const struct ieee80211_txparam *tp = ni->ni_txparms; in rt2661_tx_data()
1426 if (m0->m_flags & M_EAPOL) { in rt2661_tx_data()
1427 rate = tp->mgmtrate; in rt2661_tx_data()
1428 } else if (IEEE80211_IS_MULTICAST(wh->i_addr1)) { in rt2661_tx_data()
1429 rate = tp->mcastrate; in rt2661_tx_data()
1430 } else if (tp->ucastrate != IEEE80211_FIXED_RATE_NONE) { in rt2661_tx_data()
1431 rate = tp->ucastrate; in rt2661_tx_data()
1434 rate = ni->ni_txrate; in rt2661_tx_data()
1438 if (wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_QOS_DATA) in rt2661_tx_data()
1441 if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) { in rt2661_tx_data()
1453 if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) { in rt2661_tx_data()
1455 if (m0->m_pkthdr.len + IEEE80211_CRC_LEN > vap->iv_rtsthreshold) in rt2661_tx_data()
1457 else if ((ic->ic_flags & IEEE80211_F_USEPROT) && in rt2661_tx_data()
1458 ieee80211_rate2phytype(ic->ic_rt, rate) == IEEE80211_T_OFDM) in rt2661_tx_data()
1459 prot = ic->ic_protmode; in rt2661_tx_data()
1470 data = &txq->data[txq->cur]; in rt2661_tx_data()
1471 desc = &txq->desc[txq->cur]; in rt2661_tx_data()
1473 error = bus_dmamap_load_mbuf_sg(txq->data_dmat, data->map, m0, segs, in rt2661_tx_data()
1476 device_printf(sc->sc_dev, "could not map mbuf (error %d)\n", in rt2661_tx_data()
1484 device_printf(sc->sc_dev, in rt2661_tx_data()
1491 error = bus_dmamap_load_mbuf_sg(txq->data_dmat, data->map, m0, in rt2661_tx_data()
1494 device_printf(sc->sc_dev, in rt2661_tx_data()
1505 struct rt2661_tx_radiotap_header *tap = &sc->sc_txtap; in rt2661_tx_data()
1507 tap->wt_flags = 0; in rt2661_tx_data()
1508 tap->wt_rate = rate; in rt2661_tx_data()
1513 data->m = m0; in rt2661_tx_data()
1514 data->ni = ni; in rt2661_tx_data()
1517 if (tp->ucastrate == IEEE80211_FIXED_RATE_NONE) { in rt2661_tx_data()
1518 data->rix = ni->ni_txrate; in rt2661_tx_data()
1520 data->rssi = ic->ic_node_getrssi(ni); in rt2661_tx_data()
1522 data->rix = IEEE80211_FIXED_RATE_NONE; in rt2661_tx_data()
1524 if (!noack && !IEEE80211_IS_MULTICAST(wh->i_addr1)) { in rt2661_tx_data()
1527 dur = ieee80211_ack_duration(ic->ic_rt, in rt2661_tx_data()
1528 rate, ic->ic_flags & IEEE80211_F_SHPREAMBLE); in rt2661_tx_data()
1529 *(uint16_t *)wh->i_dur = htole16(dur); in rt2661_tx_data()
1532 rt2661_setup_tx_desc(sc, desc, flags, 0, m0->m_pkthdr.len, rate, segs, in rt2661_tx_data()
1535 bus_dmamap_sync(txq->data_dmat, data->map, BUS_DMASYNC_PREWRITE); in rt2661_tx_data()
1536 bus_dmamap_sync(txq->desc_dmat, txq->desc_map, BUS_DMASYNC_PREWRITE); in rt2661_tx_data()
1539 m0->m_pkthdr.len, txq->cur, rate); in rt2661_tx_data()
1542 txq->queued++; in rt2661_tx_data()
1543 txq->cur = (txq->cur + 1) % RT2661_TX_RING_COUNT; in rt2661_tx_data()
1552 struct rt2661_softc *sc = ic->ic_softc; in rt2661_transmit()
1556 if ((sc->sc_flags & RAL_RUNNING) == 0) { in rt2661_transmit()
1560 error = mbufq_enqueue(&sc->sc_snd, m); in rt2661_transmit()
1581 if (!(sc->sc_flags & RAL_RUNNING) || sc->sc_invalid) in rt2661_start()
1584 while ((m = mbufq_dequeue(&sc->sc_snd)) != NULL) { in rt2661_start()
1586 if (sc->txq[ac].queued >= RT2661_TX_RING_COUNT - 1) { in rt2661_start()
1587 /* there is no place left in this ring */ in rt2661_start()
1588 mbufq_prepend(&sc->sc_snd, m); in rt2661_start()
1591 ni = (struct ieee80211_node *) m->m_pkthdr.rcvif; in rt2661_start()
1593 if_inc_counter(ni->ni_vap->iv_ifp, in rt2661_start()
1598 sc->sc_tx_timer = 5; in rt2661_start()
1606 struct ieee80211com *ic = ni->ni_ic; in rt2661_raw_xmit()
1607 struct rt2661_softc *sc = ic->ic_softc; in rt2661_raw_xmit()
1612 if (!(sc->sc_flags & RAL_RUNNING)) { in rt2661_raw_xmit()
1617 if (sc->mgtq.queued >= RT2661_MGT_RING_COUNT) { in rt2661_raw_xmit()
1630 sc->sc_tx_timer = 5; in rt2661_raw_xmit()
1647 KASSERT(sc->sc_flags & RAL_RUNNING, ("not running")); in rt2661_watchdog()
1649 if (sc->sc_invalid) /* card ejected */ in rt2661_watchdog()
1652 if (sc->sc_tx_timer > 0 && --sc->sc_tx_timer == 0) { in rt2661_watchdog()
1653 device_printf(sc->sc_dev, "device timeout\n"); in rt2661_watchdog()
1655 counter_u64_add(sc->sc_ic.ic_oerrors, 1); in rt2661_watchdog()
1659 callout_reset(&sc->watchdog_ch, hz, rt2661_watchdog, sc); in rt2661_watchdog()
1665 struct rt2661_softc *sc = ic->ic_softc; in rt2661_parent()
1669 if (ic->ic_nrunning > 0) { in rt2661_parent()
1670 if ((sc->sc_flags & RAL_RUNNING) == 0) { in rt2661_parent()
1675 } else if (sc->sc_flags & RAL_RUNNING) in rt2661_parent()
1694 device_printf(sc->sc_dev, "could not write to BBP\n"); in rt2661_bbp_write()
1701 DPRINTFN(sc, 15, "BBP R%u <- 0x%02x\n", reg, val); in rt2661_bbp_write()
1716 device_printf(sc->sc_dev, "could not read from BBP\n"); in rt2661_bbp_read()
1730 device_printf(sc->sc_dev, "could not read from BBP\n"); in rt2661_bbp_read()
1746 device_printf(sc->sc_dev, "could not write to RF\n"); in rt2661_rf_write()
1755 sc->rf_regs[reg] = val; in rt2661_rf_write()
1757 DPRINTFN(sc, 15, "RF R[%u] <- 0x%05x\n", reg & 3, val & 0x1fffff); in rt2661_rf_write()
1780 bbp4 = rt2661_bbp_read(sc, 4); in rt2661_select_antenna()
1789 rt2661_bbp_write(sc, 4, bbp4); in rt2661_select_antenna()
1797 * Enable multi-rate retries for frames sent at OFDM rates.
1803 struct ieee80211com *ic = &sc->sc_ic; in rt2661_enable_mrr()
1809 if (!IEEE80211_IS_CHAN_5GHZ(ic->ic_bsschan)) in rt2661_enable_mrr()
1819 struct ieee80211com *ic = &sc->sc_ic; in rt2661_set_txpreamble()
1825 if (ic->ic_flags & IEEE80211_F_SHPREAMBLE) in rt2661_set_txpreamble()
1835 struct ieee80211com *ic = &sc->sc_ic; in rt2661_set_basicrates()
1840 for (i = 0; i < rs->rs_nrates; i++) { in rt2661_set_basicrates()
1841 rate = rs->rs_rates[i]; in rt2661_set_basicrates()
1846 mask |= 1 << ieee80211_legacy_rate_lookup(ic->ic_rt, in rt2661_set_basicrates()
1872 if ((IEEE80211_IS_CHAN_2GHZ(c) && sc->ext_2ghz_lna) || in rt2661_select_band()
1873 (IEEE80211_IS_CHAN_5GHZ(c) && sc->ext_5ghz_lna)) { in rt2661_select_band()
1881 if ((IEEE80211_IS_CHAN_2GHZ(c) && sc->ext_2ghz_lna) || in rt2661_select_band()
1882 (IEEE80211_IS_CHAN_5GHZ(c) && sc->ext_5ghz_lna)) { in rt2661_select_band()
1904 struct ieee80211com *ic = &sc->sc_ic; in rt2661_set_chan()
1914 rfprog = (sc->rfprog == 0) ? rt2661_rf5225_1 : rt2661_rf5225_2; in rt2661_set_chan()
1919 power = sc->txpow[i]; in rt2661_set_chan()
1924 bbp94 += power - 31; in rt2661_set_chan()
1930 * vice-versa, BBP registers need to be reprogrammed. in rt2661_set_chan()
1932 if (c->ic_flags != sc->sc_curchan->ic_flags) { in rt2661_set_chan()
1936 sc->sc_curchan = c; in rt2661_set_chan()
1941 rt2661_rf_write(sc, RAL_RF4, rfprog[i].r4 | sc->rffreq << 10); in rt2661_set_chan()
1948 rt2661_rf_write(sc, RAL_RF4, rfprog[i].r4 | sc->rffreq << 10); in rt2661_set_chan()
1955 rt2661_rf_write(sc, RAL_RF4, rfprog[i].r4 | sc->rffreq << 10); in rt2661_set_chan()
1957 /* enable smart mode for MIMO-capable RFs */ in rt2661_set_chan()
1961 if (sc->rf_rev == RT2661_RF_5325 || sc->rf_rev == RT2661_RF_2529) in rt2661_set_chan()
1982 tmp = bssid[4] | bssid[5] << 8 | RT2661_ONE_BSSID << 16; in rt2661_set_bssid()
1994 tmp = addr[4] | addr[5] << 8; in rt2661_set_macaddr()
2001 struct rt2661_softc *sc = ic->ic_softc; in rt2661_update_promisc()
2007 if (ic->ic_promisc == 0) in rt2661_update_promisc()
2013 (ic->ic_promisc > 0) ? "entering" : "leaving"); in rt2661_update_promisc()
2017 * Update QoS (802.11e) settings for each h/w Tx ring.
2022 struct rt2661_softc *sc = ic->ic_softc; in rt2661_wme_update()
2045 wmep[WME_AC_VI].wmep_logcwmin << 4 | in rt2661_wme_update()
2052 wmep[WME_AC_VI].wmep_logcwmax << 4 | in rt2661_wme_update()
2059 wmep[WME_AC_VI].wmep_aifsn << 4 | in rt2661_wme_update()
2068 struct rt2661_softc *sc = ic->ic_softc; in rt2661_update_slot()
2107 macaddr[4] = val & 0xff; in rt2661_read_eeprom()
2112 sc->rf_rev = (val >> 11) & 0x1f; in rt2661_read_eeprom()
2113 sc->hw_radio = (val >> 10) & 0x1; in rt2661_read_eeprom()
2114 sc->rx_ant = (val >> 4) & 0x3; in rt2661_read_eeprom()
2115 sc->tx_ant = (val >> 2) & 0x3; in rt2661_read_eeprom()
2116 sc->nb_ant = val & 0x3; in rt2661_read_eeprom()
2118 DPRINTF(sc, "RF revision=%d\n", sc->rf_rev); in rt2661_read_eeprom()
2121 sc->ext_5ghz_lna = (val >> 6) & 0x1; in rt2661_read_eeprom()
2122 sc->ext_2ghz_lna = (val >> 4) & 0x1; in rt2661_read_eeprom()
2125 sc->ext_2ghz_lna, sc->ext_5ghz_lna); in rt2661_read_eeprom()
2129 sc->rssi_2ghz_corr = (int8_t)(val & 0xff); /* signed */ in rt2661_read_eeprom()
2131 /* Only [-10, 10] is valid */ in rt2661_read_eeprom()
2132 if (sc->rssi_2ghz_corr < -10 || sc->rssi_2ghz_corr > 10) in rt2661_read_eeprom()
2133 sc->rssi_2ghz_corr = 0; in rt2661_read_eeprom()
2137 sc->rssi_5ghz_corr = (int8_t)(val & 0xff); /* signed */ in rt2661_read_eeprom()
2139 /* Only [-10, 10] is valid */ in rt2661_read_eeprom()
2140 if (sc->rssi_5ghz_corr < -10 || sc->rssi_5ghz_corr > 10) in rt2661_read_eeprom()
2141 sc->rssi_5ghz_corr = 0; in rt2661_read_eeprom()
2143 /* adjust RSSI correction for external low-noise amplifier */ in rt2661_read_eeprom()
2144 if (sc->ext_2ghz_lna) in rt2661_read_eeprom()
2145 sc->rssi_2ghz_corr -= 14; in rt2661_read_eeprom()
2146 if (sc->ext_5ghz_lna) in rt2661_read_eeprom()
2147 sc->rssi_5ghz_corr -= 14; in rt2661_read_eeprom()
2150 sc->rssi_2ghz_corr, sc->rssi_5ghz_corr); in rt2661_read_eeprom()
2154 sc->rfprog = (val >> 8) & 0x3; in rt2661_read_eeprom()
2156 sc->rffreq = val & 0xff; in rt2661_read_eeprom()
2158 DPRINTF(sc, "RF prog=%d\nRF freq=%d\n", sc->rfprog, sc->rffreq); in rt2661_read_eeprom()
2163 sc->txpow[i * 2] = (int8_t)(val >> 8); /* signed */ in rt2661_read_eeprom()
2165 rt2661_rf5225_1[i * 2].chan, sc->txpow[i * 2]); in rt2661_read_eeprom()
2166 sc->txpow[i * 2 + 1] = (int8_t)(val & 0xff); /* signed */ in rt2661_read_eeprom()
2168 rt2661_rf5225_1[i * 2 + 1].chan, sc->txpow[i * 2 + 1]); in rt2661_read_eeprom()
2171 /* read vendor-specific BBP values */ in rt2661_read_eeprom()
2176 sc->bbp_prom[i].reg = val >> 8; in rt2661_read_eeprom()
2177 sc->bbp_prom[i].val = val & 0xff; in rt2661_read_eeprom()
2178 DPRINTF(sc, "BBP R%d=%02x\n", sc->bbp_prom[i].reg, in rt2661_read_eeprom()
2179 sc->bbp_prom[i].val); in rt2661_read_eeprom()
2197 device_printf(sc->sc_dev, "timeout waiting for BBP\n"); in rt2661_bbp_init()
2207 /* write vendor-specific BBP values (from EEPROM) */ in rt2661_bbp_init()
2209 if (sc->bbp_prom[i].reg == 0) in rt2661_bbp_init()
2211 rt2661_bbp_write(sc, sc->bbp_prom[i].reg, sc->bbp_prom[i].val); in rt2661_bbp_init()
2220 struct ieee80211com *ic = &sc->sc_ic; in rt2661_init_locked()
2221 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); in rt2661_init_locked()
2227 if ((sc->sc_flags & RAL_FW_LOADED) == 0) { in rt2661_init_locked()
2230 device_printf(sc->sc_dev, in rt2661_init_locked()
2235 sc->sc_flags |= RAL_FW_LOADED; in rt2661_init_locked()
2241 RAL_WRITE(sc, RT2661_AC1_BASE_CSR, sc->txq[1].physaddr); in rt2661_init_locked()
2242 RAL_WRITE(sc, RT2661_AC0_BASE_CSR, sc->txq[0].physaddr); in rt2661_init_locked()
2243 RAL_WRITE(sc, RT2661_AC2_BASE_CSR, sc->txq[2].physaddr); in rt2661_init_locked()
2244 RAL_WRITE(sc, RT2661_AC3_BASE_CSR, sc->txq[3].physaddr); in rt2661_init_locked()
2246 /* initialize Mgt ring */ in rt2661_init_locked()
2247 RAL_WRITE(sc, RT2661_MGT_BASE_CSR, sc->mgtq.physaddr); in rt2661_init_locked()
2249 /* initialize Rx ring */ in rt2661_init_locked()
2250 RAL_WRITE(sc, RT2661_RX_BASE_CSR, sc->rxq.physaddr); in rt2661_init_locked()
2261 RT2661_TX_RING_COUNT << 8 | /* XXX: HCCA ring unused */ in rt2661_init_locked()
2273 /* load base addresses of all 5 Tx rings (4 data + 1 mgt) */ in rt2661_init_locked()
2276 /* load base address of Rx ring */ in rt2661_init_locked()
2283 rt2661_set_macaddr(sc, vap ? vap->iv_myaddr : ic->ic_macaddr); in rt2661_init_locked()
2307 sc->sc_curchan = ic->ic_curchan; in rt2661_init_locked()
2308 rt2661_select_band(sc, sc->sc_curchan); in rt2661_init_locked()
2310 rt2661_set_chan(sc, sc->sc_curchan); in rt2661_init_locked()
2316 if (ic->ic_opmode != IEEE80211_M_MONITOR) { in rt2661_init_locked()
2319 if (ic->ic_opmode != IEEE80211_M_HOSTAP && in rt2661_init_locked()
2320 ic->ic_opmode != IEEE80211_M_MBSS) in rt2661_init_locked()
2322 if (ic->ic_promisc == 0) in rt2661_init_locked()
2332 RAL_WRITE(sc, RT2661_MAC_CSR1, 4); in rt2661_init_locked()
2344 sc->sc_flags |= RAL_RUNNING; in rt2661_init_locked()
2346 callout_reset(&sc->watchdog_ch, hz, rt2661_watchdog, sc); in rt2661_init_locked()
2353 struct ieee80211com *ic = &sc->sc_ic; in rt2661_init()
2359 if (sc->sc_flags & RAL_RUNNING) in rt2661_init()
2366 volatile int *flags = &sc->sc_flags; in rt2661_stop_locked()
2370 msleep(sc, &sc->sc_mtx, 0, "ralrunning", hz/10); in rt2661_stop_locked()
2372 callout_stop(&sc->watchdog_ch); in rt2661_stop_locked()
2373 sc->sc_tx_timer = 0; in rt2661_stop_locked()
2375 if (sc->sc_flags & RAL_RUNNING) { in rt2661_stop_locked()
2376 sc->sc_flags &= ~RAL_RUNNING; in rt2661_stop_locked()
2398 rt2661_reset_tx_ring(sc, &sc->txq[0]); in rt2661_stop_locked()
2399 rt2661_reset_tx_ring(sc, &sc->txq[1]); in rt2661_stop_locked()
2400 rt2661_reset_tx_ring(sc, &sc->txq[2]); in rt2661_stop_locked()
2401 rt2661_reset_tx_ring(sc, &sc->txq[3]); in rt2661_stop_locked()
2402 rt2661_reset_tx_ring(sc, &sc->mgtq); in rt2661_stop_locked()
2403 rt2661_reset_rx_ring(sc, &sc->rxq); in rt2661_stop_locked()
2426 switch (sc->sc_id) { in rt2661_load_microcode()
2431 device_printf(sc->sc_dev, "%s: unexpected pci device id 0x%x, " in rt2661_load_microcode()
2433 __func__, sc->sc_id); in rt2661_load_microcode()
2440 device_printf(sc->sc_dev, in rt2661_load_microcode()
2459 RAL_WRITE_REGION_1(sc, RT2661_MCU_CODE_BASE, fp->data, fp->datasize); in rt2661_load_microcode()
2472 device_printf(sc->sc_dev, in rt2661_load_microcode()
2497 * external low-noise amplifier. in rt2661_rx_tune()
2500 if (IEEE80211_IS_CHAN_5GHZ(sc->sc_curchan)) in rt2661_rx_tune()
2502 if ((IEEE80211_IS_CHAN_2GHZ(sc->sc_curchan) && sc->ext_2ghz_lna) || in rt2661_rx_tune()
2503 (IEEE80211_IS_CHAN_5GHZ(sc->sc_curchan) && sc->ext_5ghz_lna)) in rt2661_rx_tune()
2510 if (dbm >= -35) { in rt2661_rx_tune()
2512 } else if (dbm >= -58) { in rt2661_rx_tune()
2514 } else if (dbm >= -66) { in rt2661_rx_tune()
2516 } else if (dbm >= -74) { in rt2661_rx_tune()
2519 /* RSSI < -74dBm, tune using false CCA count */ in rt2661_rx_tune()
2521 bbp17 = sc->bbp17; /* current value */ in rt2661_rx_tune()
2523 hi -= 2 * (-74 - dbm); in rt2661_rx_tune()
2534 if (--bbp17 < lo) in rt2661_rx_tune()
2539 if (bbp17 != sc->bbp17) { in rt2661_rx_tune()
2541 sc->bbp17 = bbp17; in rt2661_rx_tune()
2563 sc->bbp18 = rt2661_bbp_read(sc, 18); in rt2661_radar_start()
2564 sc->bbp21 = rt2661_bbp_read(sc, 21); in rt2661_radar_start()
2565 sc->bbp22 = rt2661_bbp_read(sc, 22); in rt2661_radar_start()
2566 sc->bbp16 = rt2661_bbp_read(sc, 16); in rt2661_radar_start()
2567 sc->bbp17 = rt2661_bbp_read(sc, 17); in rt2661_radar_start()
2568 sc->bbp64 = rt2661_bbp_read(sc, 64); in rt2661_radar_start()
2574 rt2661_bbp_write(sc, 17, sc->ext_5ghz_lna ? 0x44 : 0x34); in rt2661_radar_start()
2590 rt2661_bbp_write(sc, 16, sc->bbp16); in rt2661_radar_stop()
2591 rt2661_bbp_write(sc, 17, sc->bbp17); in rt2661_radar_stop()
2592 rt2661_bbp_write(sc, 18, sc->bbp18); in rt2661_radar_stop()
2593 rt2661_bbp_write(sc, 21, sc->bbp21); in rt2661_radar_stop()
2594 rt2661_bbp_write(sc, 22, sc->bbp22); in rt2661_radar_stop()
2595 rt2661_bbp_write(sc, 64, sc->bbp64); in rt2661_radar_stop()
2604 struct ieee80211com *ic = vap->iv_ic; in rt2661_prepare_beacon()
2609 if ((m0 = ieee80211_beacon_alloc(vap->iv_bss))== NULL) { in rt2661_prepare_beacon()
2610 device_printf(sc->sc_dev, "could not allocate beacon frame\n"); in rt2661_prepare_beacon()
2615 rate = IEEE80211_IS_CHAN_5GHZ(ic->ic_bsschan) ? 12 : 2; in rt2661_prepare_beacon()
2618 m0->m_pkthdr.len, rate, NULL, 0, RT2661_QID_MGT); in rt2661_prepare_beacon()
2625 mtod(m0, uint8_t *), m0->m_pkthdr.len); in rt2661_prepare_beacon()
2639 struct ieee80211com *ic = &sc->sc_ic; in rt2661_enable_tsf_sync()
2640 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); in rt2661_enable_tsf_sync()
2643 if (vap->iv_opmode != IEEE80211_M_STA) { in rt2661_enable_tsf_sync()
2654 tmp |= vap->iv_bss->ni_intval * 16; in rt2661_enable_tsf_sync()
2657 if (vap->iv_opmode == IEEE80211_M_STA) in rt2661_enable_tsf_sync()
2690 * NB: Since RSSI is relative to noise floor, -1 is in rt2661_get_rssi()
2693 return -1; in rt2661_get_rssi()
2696 rssi = (2 * agc) - RT2661_NOISE_FLOOR; in rt2661_get_rssi()
2698 if (IEEE80211_IS_CHAN_2GHZ(sc->sc_curchan)) { in rt2661_get_rssi()
2699 rssi += sc->rssi_2ghz_corr; in rt2661_get_rssi()
2702 rssi -= 64; in rt2661_get_rssi()
2704 rssi -= 74; in rt2661_get_rssi()
2706 rssi -= 90; in rt2661_get_rssi()
2708 rssi += sc->rssi_5ghz_corr; in rt2661_get_rssi()
2711 rssi -= 64; in rt2661_get_rssi()
2713 rssi -= 86; in rt2661_get_rssi()
2715 rssi -= 100; in rt2661_get_rssi()
2723 struct rt2661_softc *sc = ic->ic_softc; in rt2661_scan_start()
2735 struct rt2661_softc *sc = ic->ic_softc; in rt2661_scan_end()
2736 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); in rt2661_scan_end()
2740 rt2661_set_bssid(sc, vap->iv_bss->ni_bssid); in rt2661_scan_end()
2747 struct rt2661_softc *sc = ic->ic_softc; in rt2661_getradiocaps()
2755 if (sc->rf_rev == RT2661_RF_5225 || sc->rf_rev == RT2661_RF_5325) { in rt2661_getradiocaps()
2765 struct rt2661_softc *sc = ic->ic_softc; in rt2661_set_channel()
2768 rt2661_set_chan(sc, ic->ic_curchan); in rt2661_set_channel()