Lines Matching +full:txpower +full:- +full:5 +full:g
2 /*-
20 /*-
67 ((rssi) > (RT2560_NOISE_FLOOR + (sc)->rssi_corr) ? \
68 ((rssi) - RT2560_NOISE_FLOOR - (sc)->rssi_corr) : 0)
73 if (sc->sc_debug > 0) \
77 if (sc->sc_debug >= (n)) \
205 struct ieee80211com *ic = &sc->sc_ic; in rt2560_attach()
208 sc->sc_dev = dev; in rt2560_attach()
210 mtx_init(&sc->sc_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK, in rt2560_attach()
213 callout_init_mtx(&sc->watchdog_ch, &sc->sc_mtx, 0); in rt2560_attach()
214 mbufq_init(&sc->sc_snd, ifqmaxlen); in rt2560_attach()
217 sc->asic_rev = RAL_READ(sc, RT2560_CSR0); in rt2560_attach()
223 sc->asic_rev, rt2560_get_rf(sc->rf_rev)); in rt2560_attach()
228 error = rt2560_alloc_tx_ring(sc, &sc->txq, RT2560_TX_RING_COUNT); in rt2560_attach()
230 device_printf(sc->sc_dev, "could not allocate Tx ring\n"); in rt2560_attach()
234 error = rt2560_alloc_tx_ring(sc, &sc->atimq, RT2560_ATIM_RING_COUNT); in rt2560_attach()
236 device_printf(sc->sc_dev, "could not allocate ATIM ring\n"); in rt2560_attach()
240 error = rt2560_alloc_tx_ring(sc, &sc->prioq, RT2560_PRIO_RING_COUNT); in rt2560_attach()
242 device_printf(sc->sc_dev, "could not allocate Prio ring\n"); in rt2560_attach()
246 error = rt2560_alloc_tx_ring(sc, &sc->bcnq, RT2560_BEACON_RING_COUNT); in rt2560_attach()
248 device_printf(sc->sc_dev, "could not allocate Beacon ring\n"); in rt2560_attach()
252 error = rt2560_alloc_rx_ring(sc, &sc->rxq, RT2560_RX_RING_COUNT); in rt2560_attach()
254 device_printf(sc->sc_dev, "could not allocate Rx ring\n"); in rt2560_attach()
259 rt2560_get_macaddr(sc, ic->ic_macaddr); in rt2560_attach()
261 ic->ic_softc = sc; in rt2560_attach()
262 ic->ic_name = device_get_nameunit(dev); in rt2560_attach()
263 ic->ic_opmode = IEEE80211_M_STA; in rt2560_attach()
264 ic->ic_phytype = IEEE80211_T_OFDM; /* not only, but not used */ in rt2560_attach()
267 ic->ic_caps = in rt2560_attach()
273 | IEEE80211_C_WDS /* 4-address traffic works */ in rt2560_attach()
284 ic->ic_flags_ext |= IEEE80211_FEXT_SEQNO_OFFLOAD; in rt2560_attach()
286 rt2560_getradiocaps(ic, IEEE80211_CHAN_MAX, &ic->ic_nchans, in rt2560_attach()
287 ic->ic_channels); in rt2560_attach()
290 ic->ic_raw_xmit = rt2560_raw_xmit; in rt2560_attach()
291 ic->ic_updateslot = rt2560_update_slot; in rt2560_attach()
292 ic->ic_update_promisc = rt2560_update_promisc; in rt2560_attach()
293 ic->ic_scan_start = rt2560_scan_start; in rt2560_attach()
294 ic->ic_scan_end = rt2560_scan_end; in rt2560_attach()
295 ic->ic_getradiocaps = rt2560_getradiocaps; in rt2560_attach()
296 ic->ic_set_channel = rt2560_set_channel; in rt2560_attach()
298 ic->ic_vap_create = rt2560_vap_create; in rt2560_attach()
299 ic->ic_vap_delete = rt2560_vap_delete; in rt2560_attach()
300 ic->ic_parent = rt2560_parent; in rt2560_attach()
301 ic->ic_transmit = rt2560_transmit; in rt2560_attach()
304 &sc->sc_txtap.wt_ihdr, sizeof(sc->sc_txtap), in rt2560_attach()
306 &sc->sc_rxtap.wr_ihdr, sizeof(sc->sc_rxtap), in rt2560_attach()
315 "debug", CTLFLAG_RW, &sc->sc_debug, 0, "debug msgs"); in rt2560_attach()
319 "txantenna", CTLFLAG_RW, &sc->tx_ant, 0, "tx antenna (0=auto)"); in rt2560_attach()
323 "rxantenna", CTLFLAG_RW, &sc->rx_ant, 0, "rx antenna (0=auto)"); in rt2560_attach()
330 fail5: rt2560_free_tx_ring(sc, &sc->bcnq); in rt2560_attach()
331 fail4: rt2560_free_tx_ring(sc, &sc->prioq); in rt2560_attach()
332 fail3: rt2560_free_tx_ring(sc, &sc->atimq); in rt2560_attach()
333 fail2: rt2560_free_tx_ring(sc, &sc->txq); in rt2560_attach()
334 fail1: mtx_destroy(&sc->sc_mtx); in rt2560_attach()
343 struct ieee80211com *ic = &sc->sc_ic; in rt2560_detach()
348 mbufq_drain(&sc->sc_snd); in rt2560_detach()
350 rt2560_free_tx_ring(sc, &sc->txq); in rt2560_detach()
351 rt2560_free_tx_ring(sc, &sc->atimq); in rt2560_detach()
352 rt2560_free_tx_ring(sc, &sc->prioq); in rt2560_detach()
353 rt2560_free_tx_ring(sc, &sc->bcnq); in rt2560_detach()
354 rt2560_free_rx_ring(sc, &sc->rxq); in rt2560_detach()
356 mtx_destroy(&sc->sc_mtx); in rt2560_detach()
367 struct rt2560_softc *sc = ic->ic_softc; in rt2560_vap_create()
379 if (!TAILQ_EMPTY(&ic->ic_vaps)) { in rt2560_vap_create()
380 device_printf(sc->sc_dev, "only 1 vap supported\n"); in rt2560_vap_create()
387 if (TAILQ_EMPTY(&ic->ic_vaps) || in rt2560_vap_create()
388 ic->ic_opmode != IEEE80211_M_HOSTAP) { in rt2560_vap_create()
389 device_printf(sc->sc_dev, in rt2560_vap_create()
401 device_printf(sc->sc_dev, "unknown opmode %d\n", opmode); in rt2560_vap_create()
405 vap = &rvp->ral_vap; in rt2560_vap_create()
409 rvp->ral_newstate = vap->iv_newstate; in rt2560_vap_create()
410 vap->iv_newstate = rt2560_newstate; in rt2560_vap_create()
411 vap->iv_update_beacon = rt2560_beacon_update; in rt2560_vap_create()
417 if (TAILQ_FIRST(&ic->ic_vaps) == vap) in rt2560_vap_create()
418 ic->ic_opmode = opmode; in rt2560_vap_create()
437 if (sc->sc_ic.ic_nrunning > 0) in rt2560_resume()
458 ring->count = count; in rt2560_alloc_tx_ring()
459 ring->queued = 0; in rt2560_alloc_tx_ring()
460 ring->cur = ring->next = 0; in rt2560_alloc_tx_ring()
461 ring->cur_encrypt = ring->next_encrypt = 0; in rt2560_alloc_tx_ring()
463 error = bus_dma_tag_create(bus_get_dma_tag(sc->sc_dev), 4, 0, in rt2560_alloc_tx_ring()
466 0, NULL, NULL, &ring->desc_dmat); in rt2560_alloc_tx_ring()
468 device_printf(sc->sc_dev, "could not create desc DMA tag\n"); in rt2560_alloc_tx_ring()
472 error = bus_dmamem_alloc(ring->desc_dmat, (void **)&ring->desc, in rt2560_alloc_tx_ring()
473 BUS_DMA_NOWAIT | BUS_DMA_ZERO, &ring->desc_map); in rt2560_alloc_tx_ring()
475 device_printf(sc->sc_dev, "could not allocate DMA memory\n"); in rt2560_alloc_tx_ring()
479 error = bus_dmamap_load(ring->desc_dmat, ring->desc_map, ring->desc, in rt2560_alloc_tx_ring()
480 count * RT2560_TX_DESC_SIZE, rt2560_dma_map_addr, &ring->physaddr, in rt2560_alloc_tx_ring()
483 device_printf(sc->sc_dev, "could not load desc DMA map\n"); in rt2560_alloc_tx_ring()
487 ring->data = malloc(count * sizeof (struct rt2560_tx_data), M_DEVBUF, in rt2560_alloc_tx_ring()
489 if (ring->data == NULL) { in rt2560_alloc_tx_ring()
490 device_printf(sc->sc_dev, "could not allocate soft data\n"); in rt2560_alloc_tx_ring()
495 error = bus_dma_tag_create(bus_get_dma_tag(sc->sc_dev), 1, 0, in rt2560_alloc_tx_ring()
498 &ring->data_dmat); in rt2560_alloc_tx_ring()
500 device_printf(sc->sc_dev, "could not create data DMA tag\n"); in rt2560_alloc_tx_ring()
505 error = bus_dmamap_create(ring->data_dmat, 0, in rt2560_alloc_tx_ring()
506 &ring->data[i].map); in rt2560_alloc_tx_ring()
508 device_printf(sc->sc_dev, "could not create DMA map\n"); in rt2560_alloc_tx_ring()
526 for (i = 0; i < ring->count; i++) { in rt2560_reset_tx_ring()
527 desc = &ring->desc[i]; in rt2560_reset_tx_ring()
528 data = &ring->data[i]; in rt2560_reset_tx_ring()
530 if (data->m != NULL) { in rt2560_reset_tx_ring()
531 bus_dmamap_sync(ring->data_dmat, data->map, in rt2560_reset_tx_ring()
533 bus_dmamap_unload(ring->data_dmat, data->map); in rt2560_reset_tx_ring()
534 m_freem(data->m); in rt2560_reset_tx_ring()
535 data->m = NULL; in rt2560_reset_tx_ring()
538 if (data->ni != NULL) { in rt2560_reset_tx_ring()
539 ieee80211_free_node(data->ni); in rt2560_reset_tx_ring()
540 data->ni = NULL; in rt2560_reset_tx_ring()
543 desc->flags = 0; in rt2560_reset_tx_ring()
546 bus_dmamap_sync(ring->desc_dmat, ring->desc_map, BUS_DMASYNC_PREWRITE); in rt2560_reset_tx_ring()
548 ring->queued = 0; in rt2560_reset_tx_ring()
549 ring->cur = ring->next = 0; in rt2560_reset_tx_ring()
550 ring->cur_encrypt = ring->next_encrypt = 0; in rt2560_reset_tx_ring()
559 if (ring->desc != NULL) { in rt2560_free_tx_ring()
560 bus_dmamap_sync(ring->desc_dmat, ring->desc_map, in rt2560_free_tx_ring()
562 bus_dmamap_unload(ring->desc_dmat, ring->desc_map); in rt2560_free_tx_ring()
563 bus_dmamem_free(ring->desc_dmat, ring->desc, ring->desc_map); in rt2560_free_tx_ring()
566 if (ring->desc_dmat != NULL) in rt2560_free_tx_ring()
567 bus_dma_tag_destroy(ring->desc_dmat); in rt2560_free_tx_ring()
569 if (ring->data != NULL) { in rt2560_free_tx_ring()
570 for (i = 0; i < ring->count; i++) { in rt2560_free_tx_ring()
571 data = &ring->data[i]; in rt2560_free_tx_ring()
573 if (data->m != NULL) { in rt2560_free_tx_ring()
574 bus_dmamap_sync(ring->data_dmat, data->map, in rt2560_free_tx_ring()
576 bus_dmamap_unload(ring->data_dmat, data->map); in rt2560_free_tx_ring()
577 m_freem(data->m); in rt2560_free_tx_ring()
580 if (data->ni != NULL) in rt2560_free_tx_ring()
581 ieee80211_free_node(data->ni); in rt2560_free_tx_ring()
583 if (data->map != NULL) in rt2560_free_tx_ring()
584 bus_dmamap_destroy(ring->data_dmat, data->map); in rt2560_free_tx_ring()
587 free(ring->data, M_DEVBUF); in rt2560_free_tx_ring()
590 if (ring->data_dmat != NULL) in rt2560_free_tx_ring()
591 bus_dma_tag_destroy(ring->data_dmat); in rt2560_free_tx_ring()
603 ring->count = count; in rt2560_alloc_rx_ring()
604 ring->cur = ring->next = 0; in rt2560_alloc_rx_ring()
605 ring->cur_decrypt = 0; in rt2560_alloc_rx_ring()
607 error = bus_dma_tag_create(bus_get_dma_tag(sc->sc_dev), 4, 0, in rt2560_alloc_rx_ring()
610 0, NULL, NULL, &ring->desc_dmat); in rt2560_alloc_rx_ring()
612 device_printf(sc->sc_dev, "could not create desc DMA tag\n"); in rt2560_alloc_rx_ring()
616 error = bus_dmamem_alloc(ring->desc_dmat, (void **)&ring->desc, in rt2560_alloc_rx_ring()
617 BUS_DMA_NOWAIT | BUS_DMA_ZERO, &ring->desc_map); in rt2560_alloc_rx_ring()
619 device_printf(sc->sc_dev, "could not allocate DMA memory\n"); in rt2560_alloc_rx_ring()
623 error = bus_dmamap_load(ring->desc_dmat, ring->desc_map, ring->desc, in rt2560_alloc_rx_ring()
624 count * RT2560_RX_DESC_SIZE, rt2560_dma_map_addr, &ring->physaddr, in rt2560_alloc_rx_ring()
627 device_printf(sc->sc_dev, "could not load desc DMA map\n"); in rt2560_alloc_rx_ring()
631 ring->data = malloc(count * sizeof (struct rt2560_rx_data), M_DEVBUF, in rt2560_alloc_rx_ring()
633 if (ring->data == NULL) { in rt2560_alloc_rx_ring()
634 device_printf(sc->sc_dev, "could not allocate soft data\n"); in rt2560_alloc_rx_ring()
640 * Pre-allocate Rx buffers and populate Rx ring. in rt2560_alloc_rx_ring()
642 error = bus_dma_tag_create(bus_get_dma_tag(sc->sc_dev), 1, 0, in rt2560_alloc_rx_ring()
644 1, MCLBYTES, 0, NULL, NULL, &ring->data_dmat); in rt2560_alloc_rx_ring()
646 device_printf(sc->sc_dev, "could not create data DMA tag\n"); in rt2560_alloc_rx_ring()
651 desc = &sc->rxq.desc[i]; in rt2560_alloc_rx_ring()
652 data = &sc->rxq.data[i]; in rt2560_alloc_rx_ring()
654 error = bus_dmamap_create(ring->data_dmat, 0, &data->map); in rt2560_alloc_rx_ring()
656 device_printf(sc->sc_dev, "could not create DMA map\n"); in rt2560_alloc_rx_ring()
660 data->m = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR); in rt2560_alloc_rx_ring()
661 if (data->m == NULL) { in rt2560_alloc_rx_ring()
662 device_printf(sc->sc_dev, in rt2560_alloc_rx_ring()
668 error = bus_dmamap_load(ring->data_dmat, data->map, in rt2560_alloc_rx_ring()
669 mtod(data->m, void *), MCLBYTES, rt2560_dma_map_addr, in rt2560_alloc_rx_ring()
672 device_printf(sc->sc_dev, in rt2560_alloc_rx_ring()
677 desc->flags = htole32(RT2560_RX_BUSY); in rt2560_alloc_rx_ring()
678 desc->physaddr = htole32(physaddr); in rt2560_alloc_rx_ring()
681 bus_dmamap_sync(ring->desc_dmat, ring->desc_map, BUS_DMASYNC_PREWRITE); in rt2560_alloc_rx_ring()
694 for (i = 0; i < ring->count; i++) { in rt2560_reset_rx_ring()
695 ring->desc[i].flags = htole32(RT2560_RX_BUSY); in rt2560_reset_rx_ring()
696 ring->data[i].drop = 0; in rt2560_reset_rx_ring()
699 bus_dmamap_sync(ring->desc_dmat, ring->desc_map, BUS_DMASYNC_PREWRITE); in rt2560_reset_rx_ring()
701 ring->cur = ring->next = 0; in rt2560_reset_rx_ring()
702 ring->cur_decrypt = 0; in rt2560_reset_rx_ring()
711 if (ring->desc != NULL) { in rt2560_free_rx_ring()
712 bus_dmamap_sync(ring->desc_dmat, ring->desc_map, in rt2560_free_rx_ring()
714 bus_dmamap_unload(ring->desc_dmat, ring->desc_map); in rt2560_free_rx_ring()
715 bus_dmamem_free(ring->desc_dmat, ring->desc, ring->desc_map); in rt2560_free_rx_ring()
718 if (ring->desc_dmat != NULL) in rt2560_free_rx_ring()
719 bus_dma_tag_destroy(ring->desc_dmat); in rt2560_free_rx_ring()
721 if (ring->data != NULL) { in rt2560_free_rx_ring()
722 for (i = 0; i < ring->count; i++) { in rt2560_free_rx_ring()
723 data = &ring->data[i]; in rt2560_free_rx_ring()
725 if (data->m != NULL) { in rt2560_free_rx_ring()
726 bus_dmamap_sync(ring->data_dmat, data->map, in rt2560_free_rx_ring()
728 bus_dmamap_unload(ring->data_dmat, data->map); in rt2560_free_rx_ring()
729 m_freem(data->m); in rt2560_free_rx_ring()
732 if (data->map != NULL) in rt2560_free_rx_ring()
733 bus_dmamap_destroy(ring->data_dmat, data->map); in rt2560_free_rx_ring()
736 free(ring->data, M_DEVBUF); in rt2560_free_rx_ring()
739 if (ring->data_dmat != NULL) in rt2560_free_rx_ring()
740 bus_dma_tag_destroy(ring->data_dmat); in rt2560_free_rx_ring()
747 struct rt2560_softc *sc = vap->iv_ic->ic_softc; in rt2560_newstate()
750 if (nstate == IEEE80211_S_INIT && vap->iv_state == IEEE80211_S_RUN) { in rt2560_newstate()
758 error = rvp->ral_newstate(vap, nstate, arg); in rt2560_newstate()
761 struct ieee80211_node *ni = vap->iv_bss; in rt2560_newstate()
764 if (vap->iv_opmode != IEEE80211_M_MONITOR) { in rt2560_newstate()
766 rt2560_set_basicrates(sc, &ni->ni_rates); in rt2560_newstate()
767 rt2560_set_bssid(sc, ni->ni_bssid); in rt2560_newstate()
770 if (vap->iv_opmode == IEEE80211_M_HOSTAP || in rt2560_newstate()
771 vap->iv_opmode == IEEE80211_M_IBSS || in rt2560_newstate()
772 vap->iv_opmode == IEEE80211_M_MBSS) { in rt2560_newstate()
775 device_printf(sc->sc_dev, in rt2560_newstate()
788 if (vap->iv_opmode != IEEE80211_M_MONITOR) in rt2560_newstate()
824 /* write address (A5-A0 or A7-A0) */ in rt2560_eeprom_read()
825 n = (RAL_READ(sc, RT2560_CSR21) & RT2560_93C46) ? 5 : 7; in rt2560_eeprom_read()
826 for (; n >= 0; n--) { in rt2560_eeprom_read()
835 /* read data Q15-Q0 */ in rt2560_eeprom_read()
837 for (n = 15; n >= 0; n--) { in rt2560_eeprom_read()
865 hw = RAL_READ(sc, RT2560_SECCSR1) - sc->txq.physaddr; in rt2560_encryption_intr()
868 bus_dmamap_sync(sc->txq.desc_dmat, sc->txq.desc_map, in rt2560_encryption_intr()
871 while (sc->txq.next_encrypt != hw) { in rt2560_encryption_intr()
872 if (sc->txq.next_encrypt == sc->txq.cur_encrypt) { in rt2560_encryption_intr()
874 sc->txq.cur_encrypt); in rt2560_encryption_intr()
878 desc = &sc->txq.desc[sc->txq.next_encrypt]; in rt2560_encryption_intr()
880 if ((le32toh(desc->flags) & RT2560_TX_BUSY) || in rt2560_encryption_intr()
881 (le32toh(desc->flags) & RT2560_TX_CIPHER_BUSY)) in rt2560_encryption_intr()
885 if ((le32toh(desc->flags) & RT2560_TX_CIPHER_MASK) == in rt2560_encryption_intr()
887 desc->eiv = bswap32(desc->eiv); in rt2560_encryption_intr()
890 desc->flags |= htole32(RT2560_TX_VALID); in rt2560_encryption_intr()
891 desc->flags |= htole32(RT2560_TX_BUSY); in rt2560_encryption_intr()
894 sc->txq.next_encrypt); in rt2560_encryption_intr()
896 sc->txq.next_encrypt = in rt2560_encryption_intr()
897 (sc->txq.next_encrypt + 1) % RT2560_TX_RING_COUNT; in rt2560_encryption_intr()
900 bus_dmamap_sync(sc->txq.desc_dmat, sc->txq.desc_map, in rt2560_encryption_intr()
910 struct ieee80211_ratectl_tx_status *txs = &sc->sc_txs; in rt2560_tx_intr()
918 bus_dmamap_sync(sc->txq.desc_dmat, sc->txq.desc_map, in rt2560_tx_intr()
921 txs->flags = IEEE80211_RATECTL_STATUS_LONG_RETRY; in rt2560_tx_intr()
923 desc = &sc->txq.desc[sc->txq.next]; in rt2560_tx_intr()
924 data = &sc->txq.data[sc->txq.next]; in rt2560_tx_intr()
926 flags = le32toh(desc->flags); in rt2560_tx_intr()
932 m = data->m; in rt2560_tx_intr()
933 ni = data->ni; in rt2560_tx_intr()
937 txs->status = IEEE80211_RATECTL_TX_SUCCESS; in rt2560_tx_intr()
938 txs->long_retries = 0; in rt2560_tx_intr()
941 if (data->rix != IEEE80211_FIXED_RATE_NONE) in rt2560_tx_intr()
947 txs->status = IEEE80211_RATECTL_TX_SUCCESS; in rt2560_tx_intr()
948 txs->long_retries = RT2560_TX_RETRYCNT(flags); in rt2560_tx_intr()
951 txs->long_retries); in rt2560_tx_intr()
952 if (data->rix != IEEE80211_FIXED_RATE_NONE) in rt2560_tx_intr()
958 txs->status = IEEE80211_RATECTL_TX_FAIL_LONG; in rt2560_tx_intr()
959 txs->long_retries = RT2560_TX_RETRYCNT(flags); in rt2560_tx_intr()
962 txs->long_retries); in rt2560_tx_intr()
963 if (data->rix != IEEE80211_FIXED_RATE_NONE) in rt2560_tx_intr()
971 device_printf(sc->sc_dev, "sending data frame failed " in rt2560_tx_intr()
976 bus_dmamap_sync(sc->txq.data_dmat, data->map, in rt2560_tx_intr()
978 bus_dmamap_unload(sc->txq.data_dmat, data->map); in rt2560_tx_intr()
981 data->ni = NULL; in rt2560_tx_intr()
982 data->m = NULL; in rt2560_tx_intr()
985 desc->flags &= ~htole32(RT2560_TX_VALID); in rt2560_tx_intr()
987 DPRINTFN(sc, 15, "tx done idx=%u\n", sc->txq.next); in rt2560_tx_intr()
989 sc->txq.queued--; in rt2560_tx_intr()
990 sc->txq.next = (sc->txq.next + 1) % RT2560_TX_RING_COUNT; in rt2560_tx_intr()
993 bus_dmamap_sync(sc->txq.desc_dmat, sc->txq.desc_map, in rt2560_tx_intr()
996 if (sc->prioq.queued == 0 && sc->txq.queued == 0) in rt2560_tx_intr()
997 sc->sc_tx_timer = 0; in rt2560_tx_intr()
999 if (sc->txq.queued < RT2560_TX_RING_COUNT - 1) in rt2560_tx_intr()
1012 bus_dmamap_sync(sc->prioq.desc_dmat, sc->prioq.desc_map, in rt2560_prio_intr()
1016 desc = &sc->prioq.desc[sc->prioq.next]; in rt2560_prio_intr()
1017 data = &sc->prioq.data[sc->prioq.next]; in rt2560_prio_intr()
1019 flags = le32toh(desc->flags); in rt2560_prio_intr()
1030 (flags >> 5) & 0x7); in rt2560_prio_intr()
1041 device_printf(sc->sc_dev, "sending mgt frame failed " in rt2560_prio_intr()
1046 bus_dmamap_sync(sc->prioq.data_dmat, data->map, in rt2560_prio_intr()
1048 bus_dmamap_unload(sc->prioq.data_dmat, data->map); in rt2560_prio_intr()
1050 m = data->m; in rt2560_prio_intr()
1051 data->m = NULL; in rt2560_prio_intr()
1052 ni = data->ni; in rt2560_prio_intr()
1053 data->ni = NULL; in rt2560_prio_intr()
1056 desc->flags &= ~htole32(RT2560_TX_VALID); in rt2560_prio_intr()
1058 DPRINTFN(sc, 15, "prio done idx=%u\n", sc->prioq.next); in rt2560_prio_intr()
1060 sc->prioq.queued--; in rt2560_prio_intr()
1061 sc->prioq.next = (sc->prioq.next + 1) % RT2560_PRIO_RING_COUNT; in rt2560_prio_intr()
1063 if (m->m_flags & M_TXCB) in rt2560_prio_intr()
1071 bus_dmamap_sync(sc->prioq.desc_dmat, sc->prioq.desc_map, in rt2560_prio_intr()
1074 if (sc->prioq.queued == 0 && sc->txq.queued == 0) in rt2560_prio_intr()
1075 sc->sc_tx_timer = 0; in rt2560_prio_intr()
1077 if (sc->prioq.queued < RT2560_PRIO_RING_COUNT) in rt2560_prio_intr()
1088 struct ieee80211com *ic = &sc->sc_ic; in rt2560_decryption_intr()
1099 hw = RAL_READ(sc, RT2560_SECCSR0) - sc->rxq.physaddr; in rt2560_decryption_intr()
1102 bus_dmamap_sync(sc->rxq.desc_dmat, sc->rxq.desc_map, in rt2560_decryption_intr()
1105 for (; sc->rxq.cur_decrypt != hw;) { in rt2560_decryption_intr()
1106 desc = &sc->rxq.desc[sc->rxq.cur_decrypt]; in rt2560_decryption_intr()
1107 data = &sc->rxq.data[sc->rxq.cur_decrypt]; in rt2560_decryption_intr()
1109 if ((le32toh(desc->flags) & RT2560_RX_BUSY) || in rt2560_decryption_intr()
1110 (le32toh(desc->flags) & RT2560_RX_CIPHER_BUSY)) in rt2560_decryption_intr()
1113 if (data->drop) { in rt2560_decryption_intr()
1114 counter_u64_add(ic->ic_ierrors, 1); in rt2560_decryption_intr()
1118 if ((le32toh(desc->flags) & RT2560_RX_CIPHER_MASK) != 0 && in rt2560_decryption_intr()
1119 (le32toh(desc->flags) & RT2560_RX_ICV_ERROR)) { in rt2560_decryption_intr()
1120 counter_u64_add(ic->ic_ierrors, 1); in rt2560_decryption_intr()
1133 counter_u64_add(ic->ic_ierrors, 1); in rt2560_decryption_intr()
1137 bus_dmamap_sync(sc->rxq.data_dmat, data->map, in rt2560_decryption_intr()
1139 bus_dmamap_unload(sc->rxq.data_dmat, data->map); in rt2560_decryption_intr()
1141 error = bus_dmamap_load(sc->rxq.data_dmat, data->map, in rt2560_decryption_intr()
1148 error = bus_dmamap_load(sc->rxq.data_dmat, data->map, in rt2560_decryption_intr()
1149 mtod(data->m, void *), MCLBYTES, in rt2560_decryption_intr()
1154 device_get_name(sc->sc_dev)); in rt2560_decryption_intr()
1156 counter_u64_add(ic->ic_ierrors, 1); in rt2560_decryption_intr()
1164 m = data->m; in rt2560_decryption_intr()
1165 data->m = mnew; in rt2560_decryption_intr()
1166 desc->physaddr = htole32(physaddr); in rt2560_decryption_intr()
1169 m->m_pkthdr.len = m->m_len = in rt2560_decryption_intr()
1170 (le32toh(desc->flags) >> 16) & 0xfff; in rt2560_decryption_intr()
1172 rssi = RT2560_RSSI(sc, desc->rssi); in rt2560_decryption_intr()
1175 struct rt2560_rx_radiotap_header *tap = &sc->sc_rxtap; in rt2560_decryption_intr()
1182 tap->wr_tsf = in rt2560_decryption_intr()
1184 tap->wr_flags = 0; in rt2560_decryption_intr()
1185 tap->wr_rate = ieee80211_plcp2rate(desc->rate, in rt2560_decryption_intr()
1186 (desc->flags & htole32(RT2560_RX_OFDM)) ? in rt2560_decryption_intr()
1188 tap->wr_antenna = sc->rx_ant; in rt2560_decryption_intr()
1189 tap->wr_antsignal = nf + rssi; in rt2560_decryption_intr()
1190 tap->wr_antnoise = nf; in rt2560_decryption_intr()
1193 sc->sc_flags |= RT2560_F_INPUT_RUNNING; in rt2560_decryption_intr()
1205 sc->sc_flags &= ~RT2560_F_INPUT_RUNNING; in rt2560_decryption_intr()
1206 skip: desc->flags = htole32(RT2560_RX_BUSY); in rt2560_decryption_intr()
1208 DPRINTFN(sc, 15, "decryption done idx=%u\n", sc->rxq.cur_decrypt); in rt2560_decryption_intr()
1210 sc->rxq.cur_decrypt = in rt2560_decryption_intr()
1211 (sc->rxq.cur_decrypt + 1) % RT2560_RX_RING_COUNT; in rt2560_decryption_intr()
1214 bus_dmamap_sync(sc->rxq.desc_dmat, sc->rxq.desc_map, in rt2560_decryption_intr()
1228 bus_dmamap_sync(sc->rxq.desc_dmat, sc->rxq.desc_map, in rt2560_rx_intr()
1232 desc = &sc->rxq.desc[sc->rxq.cur]; in rt2560_rx_intr()
1233 data = &sc->rxq.data[sc->rxq.cur]; in rt2560_rx_intr()
1235 if ((le32toh(desc->flags) & RT2560_RX_BUSY) || in rt2560_rx_intr()
1236 (le32toh(desc->flags) & RT2560_RX_CIPHER_BUSY)) in rt2560_rx_intr()
1239 data->drop = 0; in rt2560_rx_intr()
1241 if ((le32toh(desc->flags) & RT2560_RX_PHY_ERROR) || in rt2560_rx_intr()
1242 (le32toh(desc->flags) & RT2560_RX_CRC_ERROR)) { in rt2560_rx_intr()
1247 DPRINTFN(sc, 5, "PHY or CRC error flags 0x%08x\n", in rt2560_rx_intr()
1248 le32toh(desc->flags)); in rt2560_rx_intr()
1249 data->drop = 1; in rt2560_rx_intr()
1252 if (((le32toh(desc->flags) >> 16) & 0xfff) > MCLBYTES) { in rt2560_rx_intr()
1253 DPRINTFN(sc, 5, "%s\n", "bad length"); in rt2560_rx_intr()
1254 data->drop = 1; in rt2560_rx_intr()
1258 desc->flags |= htole32(RT2560_RX_CIPHER_BUSY); in rt2560_rx_intr()
1260 DPRINTFN(sc, 15, "rx done idx=%u\n", sc->rxq.cur); in rt2560_rx_intr()
1262 sc->rxq.cur = (sc->rxq.cur + 1) % RT2560_RX_RING_COUNT; in rt2560_rx_intr()
1265 bus_dmamap_sync(sc->rxq.desc_dmat, sc->rxq.desc_map, in rt2560_rx_intr()
1275 struct ieee80211_beacon_offsets *bo = &vap->iv_bcn_off; in rt2560_beacon_update()
1277 setbit(bo->bo_flags, item); in rt2560_beacon_update()
1287 struct ieee80211com *ic = &sc->sc_ic; in rt2560_beacon_expire()
1290 if (ic->ic_opmode != IEEE80211_M_IBSS && in rt2560_beacon_expire()
1291 ic->ic_opmode != IEEE80211_M_HOSTAP && in rt2560_beacon_expire()
1292 ic->ic_opmode != IEEE80211_M_MBSS) in rt2560_beacon_expire()
1295 data = &sc->bcnq.data[sc->bcnq.next]; in rt2560_beacon_expire()
1299 if (data->ni == NULL) in rt2560_beacon_expire()
1302 bus_dmamap_sync(sc->bcnq.data_dmat, data->map, BUS_DMASYNC_POSTWRITE); in rt2560_beacon_expire()
1303 bus_dmamap_unload(sc->bcnq.data_dmat, data->map); in rt2560_beacon_expire()
1306 ieee80211_beacon_update(data->ni, data->m, 1); in rt2560_beacon_expire()
1308 rt2560_tx_bcn(sc, data->m, data->ni); in rt2560_beacon_expire()
1312 sc->bcnq.next = (sc->bcnq.next + 1) % RT2560_BEACON_RING_COUNT; in rt2560_beacon_expire()
1333 /* don't re-enable interrupts if we're shutting down */ in rt2560_intr()
1334 if (!(sc->sc_flags & RT2560_F_RUNNING)) { in rt2560_intr()
1365 /* re-enable interrupts */ in rt2560_intr()
1379 /* OFDM rates (cf IEEE Std 802.11a-1999, pp. 14 Table 80) */ in rt2560_plcp_signal()
1389 /* CCK rates (NB: not IEEE std, device-specific) */ in rt2560_plcp_signal()
1402 struct ieee80211com *ic = &sc->sc_ic; in rt2560_setup_tx_desc()
1406 desc->flags = htole32(flags); in rt2560_setup_tx_desc()
1407 desc->flags |= htole32(len << 16); in rt2560_setup_tx_desc()
1409 desc->physaddr = htole32(physaddr); in rt2560_setup_tx_desc()
1410 desc->wme = htole16( in rt2560_setup_tx_desc()
1416 desc->plcp_signal = rt2560_plcp_signal(rate); in rt2560_setup_tx_desc()
1417 desc->plcp_service = 4; in rt2560_setup_tx_desc()
1420 if (ieee80211_rate2phytype(ic->ic_rt, rate) == IEEE80211_T_OFDM) { in rt2560_setup_tx_desc()
1421 desc->flags |= htole32(RT2560_TX_OFDM); in rt2560_setup_tx_desc()
1424 desc->plcp_length_hi = plcp_length >> 6; in rt2560_setup_tx_desc()
1425 desc->plcp_length_lo = plcp_length & 0x3f; in rt2560_setup_tx_desc()
1431 desc->plcp_service |= RT2560_PLCP_LENGEXT; in rt2560_setup_tx_desc()
1433 desc->plcp_length_hi = plcp_length >> 8; in rt2560_setup_tx_desc()
1434 desc->plcp_length_lo = plcp_length & 0xff; in rt2560_setup_tx_desc()
1436 if (rate != 2 && (ic->ic_flags & IEEE80211_F_SHPREAMBLE)) in rt2560_setup_tx_desc()
1437 desc->plcp_signal |= 0x08; in rt2560_setup_tx_desc()
1441 desc->flags |= htole32(RT2560_TX_VALID); in rt2560_setup_tx_desc()
1442 desc->flags |= encrypt ? htole32(RT2560_TX_CIPHER_BUSY) in rt2560_setup_tx_desc()
1450 struct ieee80211vap *vap = ni->ni_vap; in rt2560_tx_bcn()
1456 desc = &sc->bcnq.desc[sc->bcnq.cur]; in rt2560_tx_bcn()
1457 data = &sc->bcnq.data[sc->bcnq.cur]; in rt2560_tx_bcn()
1460 rate = vap->iv_txparms[ieee80211_chan2mode(ni->ni_chan)].mgmtrate; in rt2560_tx_bcn()
1462 error = bus_dmamap_load_mbuf_sg(sc->bcnq.data_dmat, data->map, m0, in rt2560_tx_bcn()
1465 device_printf(sc->sc_dev, "could not map mbuf (error %d)\n", in rt2560_tx_bcn()
1472 struct rt2560_tx_radiotap_header *tap = &sc->sc_txtap; in rt2560_tx_bcn()
1474 tap->wt_flags = 0; in rt2560_tx_bcn()
1475 tap->wt_rate = rate; in rt2560_tx_bcn()
1476 tap->wt_antenna = sc->tx_ant; in rt2560_tx_bcn()
1481 data->m = m0; in rt2560_tx_bcn()
1482 data->ni = ni; in rt2560_tx_bcn()
1485 RT2560_TX_TIMESTAMP, m0->m_pkthdr.len, rate, 0, segs->ds_addr); in rt2560_tx_bcn()
1488 m0->m_pkthdr.len, sc->bcnq.cur, rate); in rt2560_tx_bcn()
1490 bus_dmamap_sync(sc->bcnq.data_dmat, data->map, BUS_DMASYNC_PREWRITE); in rt2560_tx_bcn()
1491 bus_dmamap_sync(sc->bcnq.desc_dmat, sc->bcnq.desc_map, in rt2560_tx_bcn()
1494 sc->bcnq.cur = (sc->bcnq.cur + 1) % RT2560_BEACON_RING_COUNT; in rt2560_tx_bcn()
1503 struct ieee80211vap *vap = ni->ni_vap; in rt2560_tx_mgt()
1504 struct ieee80211com *ic = ni->ni_ic; in rt2560_tx_mgt()
1514 desc = &sc->prioq.desc[sc->prioq.cur]; in rt2560_tx_mgt()
1515 data = &sc->prioq.data[sc->prioq.cur]; in rt2560_tx_mgt()
1517 rate = ni->ni_txparms->mgmtrate; in rt2560_tx_mgt()
1521 ieee80211_output_seqno_assign(ni, -1, m0); in rt2560_tx_mgt()
1523 if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) { in rt2560_tx_mgt()
1531 error = bus_dmamap_load_mbuf_sg(sc->prioq.data_dmat, data->map, m0, in rt2560_tx_mgt()
1534 device_printf(sc->sc_dev, "could not map mbuf (error %d)\n", in rt2560_tx_mgt()
1541 struct rt2560_tx_radiotap_header *tap = &sc->sc_txtap; in rt2560_tx_mgt()
1543 tap->wt_flags = 0; in rt2560_tx_mgt()
1544 tap->wt_rate = rate; in rt2560_tx_mgt()
1545 tap->wt_antenna = sc->tx_ant; in rt2560_tx_mgt()
1550 data->m = m0; in rt2560_tx_mgt()
1551 data->ni = ni; in rt2560_tx_mgt()
1553 data->rix = IEEE80211_FIXED_RATE_NONE; in rt2560_tx_mgt()
1557 if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) { in rt2560_tx_mgt()
1560 dur = ieee80211_ack_duration(ic->ic_rt, in rt2560_tx_mgt()
1561 rate, ic->ic_flags & IEEE80211_F_SHPREAMBLE); in rt2560_tx_mgt()
1562 *(uint16_t *)wh->i_dur = htole16(dur); in rt2560_tx_mgt()
1569 rt2560_setup_tx_desc(sc, desc, flags, m0->m_pkthdr.len, rate, 0, in rt2560_tx_mgt()
1570 segs->ds_addr); in rt2560_tx_mgt()
1572 bus_dmamap_sync(sc->prioq.data_dmat, data->map, BUS_DMASYNC_PREWRITE); in rt2560_tx_mgt()
1573 bus_dmamap_sync(sc->prioq.desc_dmat, sc->prioq.desc_map, in rt2560_tx_mgt()
1577 m0->m_pkthdr.len, sc->prioq.cur, rate); in rt2560_tx_mgt()
1580 sc->prioq.queued++; in rt2560_tx_mgt()
1581 sc->prioq.cur = (sc->prioq.cur + 1) % RT2560_PRIO_RING_COUNT; in rt2560_tx_mgt()
1591 struct ieee80211com *ic = ni->ni_ic; in rt2560_sendprot()
1601 if_inc_counter(ni->ni_vap->iv_ifp, IFCOUNTER_OERRORS, 1); in rt2560_sendprot()
1602 device_printf(sc->sc_dev, in rt2560_sendprot()
1607 desc = &sc->txq.desc[sc->txq.cur_encrypt]; in rt2560_sendprot()
1608 data = &sc->txq.data[sc->txq.cur_encrypt]; in rt2560_sendprot()
1610 error = bus_dmamap_load_mbuf_sg(sc->txq.data_dmat, data->map, in rt2560_sendprot()
1613 device_printf(sc->sc_dev, in rt2560_sendprot()
1619 data->m = mprot; in rt2560_sendprot()
1620 data->ni = ieee80211_ref_node(ni); in rt2560_sendprot()
1622 data->rix = IEEE80211_FIXED_RATE_NONE; in rt2560_sendprot()
1624 protrate = ieee80211_ctl_rate(ic->ic_rt, rate); in rt2560_sendprot()
1629 rt2560_setup_tx_desc(sc, desc, flags, mprot->m_pkthdr.len, protrate, 1, in rt2560_sendprot()
1630 segs->ds_addr); in rt2560_sendprot()
1632 bus_dmamap_sync(sc->txq.data_dmat, data->map, in rt2560_sendprot()
1635 sc->txq.queued++; in rt2560_sendprot()
1636 sc->txq.cur_encrypt = (sc->txq.cur_encrypt + 1) % RT2560_TX_RING_COUNT; in rt2560_sendprot()
1645 struct ieee80211vap *vap = ni->ni_vap; in rt2560_tx_raw()
1646 struct ieee80211com *ic = ni->ni_ic; in rt2560_tx_raw()
1653 desc = &sc->prioq.desc[sc->prioq.cur]; in rt2560_tx_raw()
1654 data = &sc->prioq.data[sc->prioq.cur]; in rt2560_tx_raw()
1656 rate = params->ibp_rate0; in rt2560_tx_raw()
1657 if (!ieee80211_isratevalid(ic->ic_rt, rate)) { in rt2560_tx_raw()
1664 if ((params->ibp_flags & IEEE80211_BPF_NOACK) == 0) in rt2560_tx_raw()
1666 if (params->ibp_flags & (IEEE80211_BPF_RTS|IEEE80211_BPF_CTS)) { in rt2560_tx_raw()
1668 params->ibp_flags & IEEE80211_BPF_RTS ? in rt2560_tx_raw()
1678 error = bus_dmamap_load_mbuf_sg(sc->prioq.data_dmat, data->map, m0, in rt2560_tx_raw()
1681 device_printf(sc->sc_dev, "could not map mbuf (error %d)\n", in rt2560_tx_raw()
1688 struct rt2560_tx_radiotap_header *tap = &sc->sc_txtap; in rt2560_tx_raw()
1690 tap->wt_flags = 0; in rt2560_tx_raw()
1691 tap->wt_rate = rate; in rt2560_tx_raw()
1692 tap->wt_antenna = sc->tx_ant; in rt2560_tx_raw()
1694 ieee80211_radiotap_tx(ni->ni_vap, m0); in rt2560_tx_raw()
1697 data->m = m0; in rt2560_tx_raw()
1698 data->ni = ni; in rt2560_tx_raw()
1701 rt2560_setup_tx_desc(sc, desc, flags, m0->m_pkthdr.len, in rt2560_tx_raw()
1702 rate, (params->ibp_flags & IEEE80211_BPF_CRYPTO) != 0, in rt2560_tx_raw()
1703 segs->ds_addr); in rt2560_tx_raw()
1705 bus_dmamap_sync(sc->prioq.data_dmat, data->map, BUS_DMASYNC_PREWRITE); in rt2560_tx_raw()
1706 bus_dmamap_sync(sc->prioq.desc_dmat, sc->prioq.desc_map, in rt2560_tx_raw()
1710 m0->m_pkthdr.len, sc->prioq.cur, rate); in rt2560_tx_raw()
1713 sc->prioq.queued++; in rt2560_tx_raw()
1714 sc->prioq.cur = (sc->prioq.cur + 1) % RT2560_PRIO_RING_COUNT; in rt2560_tx_raw()
1724 struct ieee80211vap *vap = ni->ni_vap; in rt2560_tx_data()
1725 struct ieee80211com *ic = ni->ni_ic; in rt2560_tx_data()
1729 const struct ieee80211_txparam *tp = ni->ni_txparms; in rt2560_tx_data()
1739 if (m0->m_flags & M_EAPOL) { in rt2560_tx_data()
1740 rate = tp->mgmtrate; in rt2560_tx_data()
1741 } else if (IEEE80211_IS_MULTICAST(wh->i_addr1)) { in rt2560_tx_data()
1742 rate = tp->mcastrate; in rt2560_tx_data()
1743 } else if (tp->ucastrate != IEEE80211_FIXED_RATE_NONE) { in rt2560_tx_data()
1744 rate = tp->ucastrate; in rt2560_tx_data()
1750 if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) { in rt2560_tx_data()
1762 if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) { in rt2560_tx_data()
1764 if (m0->m_pkthdr.len + IEEE80211_CRC_LEN > vap->iv_rtsthreshold) in rt2560_tx_data()
1766 else if ((ic->ic_flags & IEEE80211_F_USEPROT) && in rt2560_tx_data()
1767 ieee80211_rate2phytype(ic->ic_rt, rate) == IEEE80211_T_OFDM) in rt2560_tx_data()
1768 prot = ic->ic_protmode; in rt2560_tx_data()
1779 data = &sc->txq.data[sc->txq.cur_encrypt]; in rt2560_tx_data()
1780 desc = &sc->txq.desc[sc->txq.cur_encrypt]; in rt2560_tx_data()
1782 error = bus_dmamap_load_mbuf_sg(sc->txq.data_dmat, data->map, m0, in rt2560_tx_data()
1785 device_printf(sc->sc_dev, "could not map mbuf (error %d)\n", in rt2560_tx_data()
1793 device_printf(sc->sc_dev, in rt2560_tx_data()
1800 error = bus_dmamap_load_mbuf_sg(sc->txq.data_dmat, data->map, in rt2560_tx_data()
1803 device_printf(sc->sc_dev, in rt2560_tx_data()
1814 struct rt2560_tx_radiotap_header *tap = &sc->sc_txtap; in rt2560_tx_data()
1816 tap->wt_flags = 0; in rt2560_tx_data()
1817 tap->wt_rate = rate; in rt2560_tx_data()
1818 tap->wt_antenna = sc->tx_ant; in rt2560_tx_data()
1823 data->m = m0; in rt2560_tx_data()
1824 data->ni = ni; in rt2560_tx_data()
1827 if (tp->ucastrate == IEEE80211_FIXED_RATE_NONE) { in rt2560_tx_data()
1828 data->rix = ieee80211_node_get_txrate_dot11rate(ni); in rt2560_tx_data()
1830 data->rssi = ic->ic_node_getrssi(ni); in rt2560_tx_data()
1832 data->rix = IEEE80211_FIXED_RATE_NONE; in rt2560_tx_data()
1834 if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) { in rt2560_tx_data()
1837 dur = ieee80211_ack_duration(ic->ic_rt, in rt2560_tx_data()
1838 rate, ic->ic_flags & IEEE80211_F_SHPREAMBLE); in rt2560_tx_data()
1839 *(uint16_t *)wh->i_dur = htole16(dur); in rt2560_tx_data()
1842 rt2560_setup_tx_desc(sc, desc, flags, m0->m_pkthdr.len, rate, 1, in rt2560_tx_data()
1843 segs->ds_addr); in rt2560_tx_data()
1845 bus_dmamap_sync(sc->txq.data_dmat, data->map, BUS_DMASYNC_PREWRITE); in rt2560_tx_data()
1846 bus_dmamap_sync(sc->txq.desc_dmat, sc->txq.desc_map, in rt2560_tx_data()
1850 m0->m_pkthdr.len, sc->txq.cur_encrypt, rate); in rt2560_tx_data()
1853 sc->txq.queued++; in rt2560_tx_data()
1854 sc->txq.cur_encrypt = (sc->txq.cur_encrypt + 1) % RT2560_TX_RING_COUNT; in rt2560_tx_data()
1863 struct rt2560_softc *sc = ic->ic_softc; in rt2560_transmit()
1867 if ((sc->sc_flags & RT2560_F_RUNNING) == 0) { in rt2560_transmit()
1871 error = mbufq_enqueue(&sc->sc_snd, m); in rt2560_transmit()
1890 while (sc->txq.queued < RT2560_TX_RING_COUNT - 1 && in rt2560_start()
1891 (m = mbufq_dequeue(&sc->sc_snd)) != NULL) { in rt2560_start()
1892 ni = (struct ieee80211_node *) m->m_pkthdr.rcvif; in rt2560_start()
1894 if_inc_counter(ni->ni_vap->iv_ifp, in rt2560_start()
1899 sc->sc_tx_timer = 5; in rt2560_start()
1910 KASSERT(sc->sc_flags & RT2560_F_RUNNING, ("not running")); in rt2560_watchdog()
1912 if (sc->sc_invalid) /* card ejected */ in rt2560_watchdog()
1918 if (sc->sc_tx_timer > 0 && --sc->sc_tx_timer == 0) { in rt2560_watchdog()
1919 device_printf(sc->sc_dev, "device timeout\n"); in rt2560_watchdog()
1921 counter_u64_add(sc->sc_ic.ic_oerrors, 1); in rt2560_watchdog()
1925 callout_reset(&sc->watchdog_ch, hz, rt2560_watchdog, sc); in rt2560_watchdog()
1931 struct rt2560_softc *sc = ic->ic_softc; in rt2560_parent()
1935 if (ic->ic_nrunning > 0) { in rt2560_parent()
1936 if ((sc->sc_flags & RT2560_F_RUNNING) == 0) { in rt2560_parent()
1941 } else if (sc->sc_flags & RT2560_F_RUNNING) in rt2560_parent()
1960 device_printf(sc->sc_dev, "could not write to BBP\n"); in rt2560_bbp_write()
1967 DPRINTFN(sc, 15, "BBP R%u <- 0x%02x\n", reg, val); in rt2560_bbp_write()
1982 device_printf(sc->sc_dev, "could not read from BBP\n"); in rt2560_bbp_read()
1996 device_printf(sc->sc_dev, "could not read from BBP\n"); in rt2560_bbp_read()
2012 device_printf(sc->sc_dev, "could not write to RF\n"); in rt2560_rf_write()
2021 sc->rf_regs[reg] = val; in rt2560_rf_write()
2023 DPRINTFN(sc, 15, "RF R[%u] <- 0x%05x\n", reg & 0x3, val & 0xfffff); in rt2560_rf_write()
2029 struct ieee80211com *ic = &sc->sc_ic; in rt2560_set_chan()
2037 power = min(sc->txpow[chan - 1], 31); in rt2560_set_chan()
2041 /* adjust txpower using ifconfig settings */ in rt2560_set_chan()
2042 power -= (100 - ic->ic_txpowlimit) / 8; in rt2560_set_chan()
2044 DPRINTFN(sc, 2, "setting channel to %u, txpower to %u\n", chan, power); in rt2560_set_chan()
2046 switch (sc->rf_rev) { in rt2560_set_chan()
2049 rt2560_rf_write(sc, RAL_RF2, rt2560_rf2522_r2[chan - 1]); in rt2560_set_chan()
2055 rt2560_rf_write(sc, RAL_RF2, rt2560_rf2523_r2[chan - 1]); in rt2560_set_chan()
2062 rt2560_rf_write(sc, RAL_RF2, rt2560_rf2524_r2[chan - 1]); in rt2560_set_chan()
2069 rt2560_rf_write(sc, RAL_RF2, rt2560_rf2525_hi_r2[chan - 1]); in rt2560_set_chan()
2074 rt2560_rf_write(sc, RAL_RF2, rt2560_rf2525_r2[chan - 1]); in rt2560_set_chan()
2081 rt2560_rf_write(sc, RAL_RF2, rt2560_rf2525e_r2[chan - 1]); in rt2560_set_chan()
2087 rt2560_rf_write(sc, RAL_RF2, rt2560_rf2526_hi_r2[chan - 1]); in rt2560_set_chan()
2091 rt2560_rf_write(sc, RAL_RF2, rt2560_rf2526_r2[chan - 1]); in rt2560_set_chan()
2096 /* dual-band RF */ in rt2560_set_chan()
2106 printf("unknown ral rev=%d\n", sc->rf_rev); in rt2560_set_chan()
2110 if ((ic->ic_flags & IEEE80211_F_SCAN) == 0) { in rt2560_set_chan()
2129 struct rt2560_softc *sc = ic->ic_softc; in rt2560_getradiocaps()
2137 if (sc->rf_rev == RT2560_RF_5222) { in rt2560_getradiocaps()
2147 struct rt2560_softc *sc = ic->ic_softc; in rt2560_set_channel()
2150 rt2560_set_chan(sc, ic->ic_curchan); in rt2560_set_channel()
2157 * Disable RF auto-tuning.
2164 if (sc->rf_rev != RT2560_RF_2523) {
2165 tmp = sc->rf_regs[RAL_RF1] & ~RAL_RF1_AUTOTUNE;
2169 tmp = sc->rf_regs[RAL_RF3] & ~RAL_RF3_AUTOTUNE;
2177 * Refer to IEEE Std 802.11-1999 pp. 123 for more information on TSF
2183 struct ieee80211com *ic = &sc->sc_ic; in rt2560_enable_tsf_sync()
2184 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); in rt2560_enable_tsf_sync()
2191 tmp = 16 * vap->iv_bss->ni_intval; in rt2560_enable_tsf_sync()
2196 logcwmin = 5; in rt2560_enable_tsf_sync()
2197 preload = (vap->iv_opmode == IEEE80211_M_STA) ? 384 : 1024; in rt2560_enable_tsf_sync()
2203 if (ic->ic_opmode == IEEE80211_M_STA) in rt2560_enable_tsf_sync()
2224 struct ieee80211com *ic = &sc->sc_ic; in rt2560_update_plcp()
2229 if (!(ic->ic_flags & IEEE80211_F_SHPREAMBLE)) { in rt2560_update_plcp()
2242 (ic->ic_flags & IEEE80211_F_SHPREAMBLE) ? "short" : "long"); in rt2560_update_plcp()
2247 * IEEE Std 802.11-1999 pp. 85 to know how these values are computed.
2252 struct rt2560_softc *sc = ic->ic_softc; in rt2560_update_slot()
2273 * (-1Mb~-2Mb lower) and the _whole_ BSS would stop using short in rt2560_update_slot()
2280 tx_sifs = RAL_SIFS - RT2560_TXRX_TURNAROUND; in rt2560_update_slot()
2283 eifs = (ic->ic_curmode == IEEE80211_MODE_11B) ? 364 : 60; in rt2560_update_slot()
2302 struct ieee80211com *ic = &sc->sc_ic; in rt2560_set_basicrates()
2307 for (i = 0; i < rs->rs_nrates; i++) { in rt2560_set_basicrates()
2308 rate = rs->rs_rates[i]; in rt2560_set_basicrates()
2313 mask |= 1 << ieee80211_legacy_rate_lookup(ic->ic_rt, in rt2560_set_basicrates()
2340 tmp = bssid[4] | bssid[5] << 8; in rt2560_set_bssid()
2354 tmp = addr[4] | addr[5] << 8; in rt2560_set_macaddr()
2373 addr[5] = (tmp >> 8) & 0xff; in rt2560_get_macaddr()
2379 struct rt2560_softc *sc = ic->ic_softc; in rt2560_update_promisc()
2385 if (ic->ic_promisc == 0) in rt2560_update_promisc()
2391 (ic->ic_promisc > 0) ? "entering" : "leaving"); in rt2560_update_promisc()
2416 sc->rf_rev = (val >> 11) & 0x7; in rt2560_read_config()
2417 sc->hw_radio = (val >> 10) & 0x1; in rt2560_read_config()
2418 sc->led_mode = (val >> 6) & 0x7; in rt2560_read_config()
2419 sc->rx_ant = (val >> 4) & 0x3; in rt2560_read_config()
2420 sc->tx_ant = (val >> 2) & 0x3; in rt2560_read_config()
2421 sc->nb_ant = val & 0x3; in rt2560_read_config()
2429 sc->bbp_prom[i].reg = val >> 8; in rt2560_read_config()
2430 sc->bbp_prom[i].val = val & 0xff; in rt2560_read_config()
2433 /* read Tx power for all b/g channels */ in rt2560_read_config()
2436 sc->txpow[i * 2] = val & 0xff; in rt2560_read_config()
2437 sc->txpow[i * 2 + 1] = val >> 8; in rt2560_read_config()
2440 if (sc->txpow[i] > 31) in rt2560_read_config()
2441 sc->txpow[i] = 24; in rt2560_read_config()
2446 sc->rssi_corr = RT2560_DEFAULT_RSSI_CORR; in rt2560_read_config()
2448 sc->rssi_corr = val & 0xff; in rt2560_read_config()
2450 sc->rssi_corr, val); in rt2560_read_config()
2456 struct rt2560_softc *sc = ic->ic_softc; in rt2560_scan_start()
2466 struct rt2560_softc *sc = ic->ic_softc; in rt2560_scan_end()
2467 struct ieee80211vap *vap = ic->ic_scan->ss_vap; in rt2560_scan_end()
2471 rt2560_set_bssid(sc, vap->iv_bss->ni_bssid); in rt2560_scan_end()
2486 device_printf(sc->sc_dev, "timeout waiting for BBP\n"); in rt2560_bbp_init()
2498 if (sc->bbp_prom[i].reg == 0 && sc->bbp_prom[i].val == 0) in rt2560_bbp_init()
2500 rt2560_bbp_write(sc, sc->bbp_prom[i].reg, sc->bbp_prom[i].val); in rt2560_bbp_init()
2522 if (sc->rf_rev == RT2560_RF_2525E || sc->rf_rev == RT2560_RF_2526 || in rt2560_set_txantenna()
2523 sc->rf_rev == RT2560_RF_5222) in rt2560_set_txantenna()
2548 if (sc->rf_rev == RT2560_RF_2525E || sc->rf_rev == RT2560_RF_2526) in rt2560_set_rxantenna()
2557 struct ieee80211com *ic = &sc->sc_ic; in rt2560_init_locked()
2558 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); in rt2560_init_locked()
2574 RAL_WRITE(sc, RT2560_TXCSR3, sc->txq.physaddr); in rt2560_init_locked()
2575 RAL_WRITE(sc, RT2560_TXCSR5, sc->prioq.physaddr); in rt2560_init_locked()
2576 RAL_WRITE(sc, RT2560_TXCSR4, sc->atimq.physaddr); in rt2560_init_locked()
2577 RAL_WRITE(sc, RT2560_TXCSR6, sc->bcnq.physaddr); in rt2560_init_locked()
2583 RAL_WRITE(sc, RT2560_RXCSR2, sc->rxq.physaddr); in rt2560_init_locked()
2589 rt2560_set_macaddr(sc, vap ? vap->iv_myaddr : ic->ic_macaddr); in rt2560_init_locked()
2606 rt2560_set_txantenna(sc, sc->tx_ant); in rt2560_init_locked()
2607 rt2560_set_rxantenna(sc, sc->rx_ant); in rt2560_init_locked()
2610 rt2560_set_chan(sc, ic->ic_curchan); in rt2560_init_locked()
2614 if (ic->ic_opmode != IEEE80211_M_MONITOR) { in rt2560_init_locked()
2616 if (ic->ic_opmode != IEEE80211_M_HOSTAP && in rt2560_init_locked()
2617 ic->ic_opmode != IEEE80211_M_MBSS) in rt2560_init_locked()
2619 if (ic->ic_promisc == 0) in rt2560_init_locked()
2634 sc->sc_flags |= RT2560_F_RUNNING; in rt2560_init_locked()
2636 callout_reset(&sc->watchdog_ch, hz, rt2560_watchdog, sc); in rt2560_init_locked()
2643 struct ieee80211com *ic = &sc->sc_ic; in rt2560_init()
2649 if (sc->sc_flags & RT2560_F_RUNNING) in rt2560_init()
2656 volatile int *flags = &sc->sc_flags; in rt2560_stop_locked()
2661 msleep(sc, &sc->sc_mtx, 0, "ralrunning", hz/10); in rt2560_stop_locked()
2663 callout_stop(&sc->watchdog_ch); in rt2560_stop_locked()
2664 sc->sc_tx_timer = 0; in rt2560_stop_locked()
2666 if (sc->sc_flags & RT2560_F_RUNNING) { in rt2560_stop_locked()
2667 sc->sc_flags &= ~RT2560_F_RUNNING; in rt2560_stop_locked()
2683 rt2560_reset_tx_ring(sc, &sc->txq); in rt2560_stop_locked()
2684 rt2560_reset_tx_ring(sc, &sc->atimq); in rt2560_stop_locked()
2685 rt2560_reset_tx_ring(sc, &sc->prioq); in rt2560_stop_locked()
2686 rt2560_reset_tx_ring(sc, &sc->bcnq); in rt2560_stop_locked()
2687 rt2560_reset_rx_ring(sc, &sc->rxq); in rt2560_stop_locked()
2705 struct ieee80211com *ic = ni->ni_ic; in rt2560_raw_xmit()
2706 struct rt2560_softc *sc = ic->ic_softc; in rt2560_raw_xmit()
2711 if (!(sc->sc_flags & RT2560_F_RUNNING)) { in rt2560_raw_xmit()
2716 if (sc->prioq.queued >= RT2560_PRIO_RING_COUNT) { in rt2560_raw_xmit()
2737 sc->sc_tx_timer = 5; in rt2560_raw_xmit()