Lines Matching +full:tuning +full:- +full:start +full:- +full:tap

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 rt2560_getradiocaps(ic, IEEE80211_CHAN_MAX, &ic->ic_nchans, in rt2560_attach()
285 ic->ic_channels); in rt2560_attach()
288 ic->ic_raw_xmit = rt2560_raw_xmit; in rt2560_attach()
289 ic->ic_updateslot = rt2560_update_slot; in rt2560_attach()
290 ic->ic_update_promisc = rt2560_update_promisc; in rt2560_attach()
291 ic->ic_scan_start = rt2560_scan_start; in rt2560_attach()
292 ic->ic_scan_end = rt2560_scan_end; in rt2560_attach()
293 ic->ic_getradiocaps = rt2560_getradiocaps; in rt2560_attach()
294 ic->ic_set_channel = rt2560_set_channel; in rt2560_attach()
296 ic->ic_vap_create = rt2560_vap_create; in rt2560_attach()
297 ic->ic_vap_delete = rt2560_vap_delete; in rt2560_attach()
298 ic->ic_parent = rt2560_parent; in rt2560_attach()
299 ic->ic_transmit = rt2560_transmit; in rt2560_attach()
302 &sc->sc_txtap.wt_ihdr, sizeof(sc->sc_txtap), in rt2560_attach()
304 &sc->sc_rxtap.wr_ihdr, sizeof(sc->sc_rxtap), in rt2560_attach()
313 "debug", CTLFLAG_RW, &sc->sc_debug, 0, "debug msgs"); in rt2560_attach()
317 "txantenna", CTLFLAG_RW, &sc->tx_ant, 0, "tx antenna (0=auto)"); in rt2560_attach()
321 "rxantenna", CTLFLAG_RW, &sc->rx_ant, 0, "rx antenna (0=auto)"); in rt2560_attach()
328 fail5: rt2560_free_tx_ring(sc, &sc->bcnq); in rt2560_attach()
329 fail4: rt2560_free_tx_ring(sc, &sc->prioq); in rt2560_attach()
330 fail3: rt2560_free_tx_ring(sc, &sc->atimq); in rt2560_attach()
331 fail2: rt2560_free_tx_ring(sc, &sc->txq); in rt2560_attach()
332 fail1: mtx_destroy(&sc->sc_mtx); in rt2560_attach()
341 struct ieee80211com *ic = &sc->sc_ic; in rt2560_detach()
346 mbufq_drain(&sc->sc_snd); in rt2560_detach()
348 rt2560_free_tx_ring(sc, &sc->txq); in rt2560_detach()
349 rt2560_free_tx_ring(sc, &sc->atimq); in rt2560_detach()
350 rt2560_free_tx_ring(sc, &sc->prioq); in rt2560_detach()
351 rt2560_free_tx_ring(sc, &sc->bcnq); in rt2560_detach()
352 rt2560_free_rx_ring(sc, &sc->rxq); in rt2560_detach()
354 mtx_destroy(&sc->sc_mtx); in rt2560_detach()
365 struct rt2560_softc *sc = ic->ic_softc; in rt2560_vap_create()
377 if (!TAILQ_EMPTY(&ic->ic_vaps)) { in rt2560_vap_create()
378 device_printf(sc->sc_dev, "only 1 vap supported\n"); in rt2560_vap_create()
385 if (TAILQ_EMPTY(&ic->ic_vaps) || in rt2560_vap_create()
386 ic->ic_opmode != IEEE80211_M_HOSTAP) { in rt2560_vap_create()
387 device_printf(sc->sc_dev, in rt2560_vap_create()
399 device_printf(sc->sc_dev, "unknown opmode %d\n", opmode); in rt2560_vap_create()
403 vap = &rvp->ral_vap; in rt2560_vap_create()
407 rvp->ral_newstate = vap->iv_newstate; in rt2560_vap_create()
408 vap->iv_newstate = rt2560_newstate; in rt2560_vap_create()
409 vap->iv_update_beacon = rt2560_beacon_update; in rt2560_vap_create()
415 if (TAILQ_FIRST(&ic->ic_vaps) == vap) in rt2560_vap_create()
416 ic->ic_opmode = opmode; in rt2560_vap_create()
435 if (sc->sc_ic.ic_nrunning > 0) in rt2560_resume()
456 ring->count = count; in rt2560_alloc_tx_ring()
457 ring->queued = 0; in rt2560_alloc_tx_ring()
458 ring->cur = ring->next = 0; in rt2560_alloc_tx_ring()
459 ring->cur_encrypt = ring->next_encrypt = 0; in rt2560_alloc_tx_ring()
461 error = bus_dma_tag_create(bus_get_dma_tag(sc->sc_dev), 4, 0, in rt2560_alloc_tx_ring()
464 0, NULL, NULL, &ring->desc_dmat); in rt2560_alloc_tx_ring()
466 device_printf(sc->sc_dev, "could not create desc DMA tag\n"); in rt2560_alloc_tx_ring()
470 error = bus_dmamem_alloc(ring->desc_dmat, (void **)&ring->desc, in rt2560_alloc_tx_ring()
471 BUS_DMA_NOWAIT | BUS_DMA_ZERO, &ring->desc_map); in rt2560_alloc_tx_ring()
473 device_printf(sc->sc_dev, "could not allocate DMA memory\n"); in rt2560_alloc_tx_ring()
477 error = bus_dmamap_load(ring->desc_dmat, ring->desc_map, ring->desc, in rt2560_alloc_tx_ring()
478 count * RT2560_TX_DESC_SIZE, rt2560_dma_map_addr, &ring->physaddr, in rt2560_alloc_tx_ring()
481 device_printf(sc->sc_dev, "could not load desc DMA map\n"); in rt2560_alloc_tx_ring()
485 ring->data = malloc(count * sizeof (struct rt2560_tx_data), M_DEVBUF, in rt2560_alloc_tx_ring()
487 if (ring->data == NULL) { in rt2560_alloc_tx_ring()
488 device_printf(sc->sc_dev, "could not allocate soft data\n"); in rt2560_alloc_tx_ring()
493 error = bus_dma_tag_create(bus_get_dma_tag(sc->sc_dev), 1, 0, in rt2560_alloc_tx_ring()
496 &ring->data_dmat); in rt2560_alloc_tx_ring()
498 device_printf(sc->sc_dev, "could not create data DMA tag\n"); in rt2560_alloc_tx_ring()
503 error = bus_dmamap_create(ring->data_dmat, 0, in rt2560_alloc_tx_ring()
504 &ring->data[i].map); in rt2560_alloc_tx_ring()
506 device_printf(sc->sc_dev, "could not create DMA map\n"); in rt2560_alloc_tx_ring()
524 for (i = 0; i < ring->count; i++) { in rt2560_reset_tx_ring()
525 desc = &ring->desc[i]; in rt2560_reset_tx_ring()
526 data = &ring->data[i]; in rt2560_reset_tx_ring()
528 if (data->m != NULL) { in rt2560_reset_tx_ring()
529 bus_dmamap_sync(ring->data_dmat, data->map, in rt2560_reset_tx_ring()
531 bus_dmamap_unload(ring->data_dmat, data->map); in rt2560_reset_tx_ring()
532 m_freem(data->m); in rt2560_reset_tx_ring()
533 data->m = NULL; in rt2560_reset_tx_ring()
536 if (data->ni != NULL) { in rt2560_reset_tx_ring()
537 ieee80211_free_node(data->ni); in rt2560_reset_tx_ring()
538 data->ni = NULL; in rt2560_reset_tx_ring()
541 desc->flags = 0; in rt2560_reset_tx_ring()
544 bus_dmamap_sync(ring->desc_dmat, ring->desc_map, BUS_DMASYNC_PREWRITE); in rt2560_reset_tx_ring()
546 ring->queued = 0; in rt2560_reset_tx_ring()
547 ring->cur = ring->next = 0; in rt2560_reset_tx_ring()
548 ring->cur_encrypt = ring->next_encrypt = 0; in rt2560_reset_tx_ring()
557 if (ring->desc != NULL) { in rt2560_free_tx_ring()
558 bus_dmamap_sync(ring->desc_dmat, ring->desc_map, in rt2560_free_tx_ring()
560 bus_dmamap_unload(ring->desc_dmat, ring->desc_map); in rt2560_free_tx_ring()
561 bus_dmamem_free(ring->desc_dmat, ring->desc, ring->desc_map); in rt2560_free_tx_ring()
564 if (ring->desc_dmat != NULL) in rt2560_free_tx_ring()
565 bus_dma_tag_destroy(ring->desc_dmat); in rt2560_free_tx_ring()
567 if (ring->data != NULL) { in rt2560_free_tx_ring()
568 for (i = 0; i < ring->count; i++) { in rt2560_free_tx_ring()
569 data = &ring->data[i]; in rt2560_free_tx_ring()
571 if (data->m != NULL) { in rt2560_free_tx_ring()
572 bus_dmamap_sync(ring->data_dmat, data->map, in rt2560_free_tx_ring()
574 bus_dmamap_unload(ring->data_dmat, data->map); in rt2560_free_tx_ring()
575 m_freem(data->m); in rt2560_free_tx_ring()
578 if (data->ni != NULL) in rt2560_free_tx_ring()
579 ieee80211_free_node(data->ni); in rt2560_free_tx_ring()
581 if (data->map != NULL) in rt2560_free_tx_ring()
582 bus_dmamap_destroy(ring->data_dmat, data->map); in rt2560_free_tx_ring()
585 free(ring->data, M_DEVBUF); in rt2560_free_tx_ring()
588 if (ring->data_dmat != NULL) in rt2560_free_tx_ring()
589 bus_dma_tag_destroy(ring->data_dmat); in rt2560_free_tx_ring()
601 ring->count = count; in rt2560_alloc_rx_ring()
602 ring->cur = ring->next = 0; in rt2560_alloc_rx_ring()
603 ring->cur_decrypt = 0; in rt2560_alloc_rx_ring()
605 error = bus_dma_tag_create(bus_get_dma_tag(sc->sc_dev), 4, 0, in rt2560_alloc_rx_ring()
608 0, NULL, NULL, &ring->desc_dmat); in rt2560_alloc_rx_ring()
610 device_printf(sc->sc_dev, "could not create desc DMA tag\n"); in rt2560_alloc_rx_ring()
614 error = bus_dmamem_alloc(ring->desc_dmat, (void **)&ring->desc, in rt2560_alloc_rx_ring()
615 BUS_DMA_NOWAIT | BUS_DMA_ZERO, &ring->desc_map); in rt2560_alloc_rx_ring()
617 device_printf(sc->sc_dev, "could not allocate DMA memory\n"); in rt2560_alloc_rx_ring()
621 error = bus_dmamap_load(ring->desc_dmat, ring->desc_map, ring->desc, in rt2560_alloc_rx_ring()
622 count * RT2560_RX_DESC_SIZE, rt2560_dma_map_addr, &ring->physaddr, in rt2560_alloc_rx_ring()
625 device_printf(sc->sc_dev, "could not load desc DMA map\n"); in rt2560_alloc_rx_ring()
629 ring->data = malloc(count * sizeof (struct rt2560_rx_data), M_DEVBUF, in rt2560_alloc_rx_ring()
631 if (ring->data == NULL) { in rt2560_alloc_rx_ring()
632 device_printf(sc->sc_dev, "could not allocate soft data\n"); in rt2560_alloc_rx_ring()
638 * Pre-allocate Rx buffers and populate Rx ring. in rt2560_alloc_rx_ring()
640 error = bus_dma_tag_create(bus_get_dma_tag(sc->sc_dev), 1, 0, in rt2560_alloc_rx_ring()
642 1, MCLBYTES, 0, NULL, NULL, &ring->data_dmat); in rt2560_alloc_rx_ring()
644 device_printf(sc->sc_dev, "could not create data DMA tag\n"); in rt2560_alloc_rx_ring()
649 desc = &sc->rxq.desc[i]; in rt2560_alloc_rx_ring()
650 data = &sc->rxq.data[i]; in rt2560_alloc_rx_ring()
652 error = bus_dmamap_create(ring->data_dmat, 0, &data->map); in rt2560_alloc_rx_ring()
654 device_printf(sc->sc_dev, "could not create DMA map\n"); in rt2560_alloc_rx_ring()
658 data->m = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR); in rt2560_alloc_rx_ring()
659 if (data->m == NULL) { in rt2560_alloc_rx_ring()
660 device_printf(sc->sc_dev, in rt2560_alloc_rx_ring()
666 error = bus_dmamap_load(ring->data_dmat, data->map, in rt2560_alloc_rx_ring()
667 mtod(data->m, void *), MCLBYTES, rt2560_dma_map_addr, in rt2560_alloc_rx_ring()
670 device_printf(sc->sc_dev, in rt2560_alloc_rx_ring()
675 desc->flags = htole32(RT2560_RX_BUSY); in rt2560_alloc_rx_ring()
676 desc->physaddr = htole32(physaddr); in rt2560_alloc_rx_ring()
679 bus_dmamap_sync(ring->desc_dmat, ring->desc_map, BUS_DMASYNC_PREWRITE); in rt2560_alloc_rx_ring()
692 for (i = 0; i < ring->count; i++) { in rt2560_reset_rx_ring()
693 ring->desc[i].flags = htole32(RT2560_RX_BUSY); in rt2560_reset_rx_ring()
694 ring->data[i].drop = 0; in rt2560_reset_rx_ring()
697 bus_dmamap_sync(ring->desc_dmat, ring->desc_map, BUS_DMASYNC_PREWRITE); in rt2560_reset_rx_ring()
699 ring->cur = ring->next = 0; in rt2560_reset_rx_ring()
700 ring->cur_decrypt = 0; in rt2560_reset_rx_ring()
709 if (ring->desc != NULL) { in rt2560_free_rx_ring()
710 bus_dmamap_sync(ring->desc_dmat, ring->desc_map, in rt2560_free_rx_ring()
712 bus_dmamap_unload(ring->desc_dmat, ring->desc_map); in rt2560_free_rx_ring()
713 bus_dmamem_free(ring->desc_dmat, ring->desc, ring->desc_map); in rt2560_free_rx_ring()
716 if (ring->desc_dmat != NULL) in rt2560_free_rx_ring()
717 bus_dma_tag_destroy(ring->desc_dmat); in rt2560_free_rx_ring()
719 if (ring->data != NULL) { in rt2560_free_rx_ring()
720 for (i = 0; i < ring->count; i++) { in rt2560_free_rx_ring()
721 data = &ring->data[i]; in rt2560_free_rx_ring()
723 if (data->m != NULL) { in rt2560_free_rx_ring()
724 bus_dmamap_sync(ring->data_dmat, data->map, in rt2560_free_rx_ring()
726 bus_dmamap_unload(ring->data_dmat, data->map); in rt2560_free_rx_ring()
727 m_freem(data->m); in rt2560_free_rx_ring()
730 if (data->map != NULL) in rt2560_free_rx_ring()
731 bus_dmamap_destroy(ring->data_dmat, data->map); in rt2560_free_rx_ring()
734 free(ring->data, M_DEVBUF); in rt2560_free_rx_ring()
737 if (ring->data_dmat != NULL) in rt2560_free_rx_ring()
738 bus_dma_tag_destroy(ring->data_dmat); in rt2560_free_rx_ring()
745 struct rt2560_softc *sc = vap->iv_ic->ic_softc; in rt2560_newstate()
748 if (nstate == IEEE80211_S_INIT && vap->iv_state == IEEE80211_S_RUN) { in rt2560_newstate()
756 error = rvp->ral_newstate(vap, nstate, arg); in rt2560_newstate()
759 struct ieee80211_node *ni = vap->iv_bss; in rt2560_newstate()
762 if (vap->iv_opmode != IEEE80211_M_MONITOR) { in rt2560_newstate()
764 rt2560_set_basicrates(sc, &ni->ni_rates); in rt2560_newstate()
765 rt2560_set_bssid(sc, ni->ni_bssid); in rt2560_newstate()
768 if (vap->iv_opmode == IEEE80211_M_HOSTAP || in rt2560_newstate()
769 vap->iv_opmode == IEEE80211_M_IBSS || in rt2560_newstate()
770 vap->iv_opmode == IEEE80211_M_MBSS) { in rt2560_newstate()
773 device_printf(sc->sc_dev, in rt2560_newstate()
786 if (vap->iv_opmode != IEEE80211_M_MONITOR) in rt2560_newstate()
812 /* write start bit (1) */ in rt2560_eeprom_read()
822 /* write address (A5-A0 or A7-A0) */ in rt2560_eeprom_read()
824 for (; n >= 0; n--) { in rt2560_eeprom_read()
833 /* read data Q15-Q0 */ in rt2560_eeprom_read()
835 for (n = 15; n >= 0; n--) { in rt2560_eeprom_read()
863 hw = RAL_READ(sc, RT2560_SECCSR1) - sc->txq.physaddr; in rt2560_encryption_intr()
866 bus_dmamap_sync(sc->txq.desc_dmat, sc->txq.desc_map, in rt2560_encryption_intr()
869 while (sc->txq.next_encrypt != hw) { in rt2560_encryption_intr()
870 if (sc->txq.next_encrypt == sc->txq.cur_encrypt) { in rt2560_encryption_intr()
872 sc->txq.cur_encrypt); in rt2560_encryption_intr()
876 desc = &sc->txq.desc[sc->txq.next_encrypt]; in rt2560_encryption_intr()
878 if ((le32toh(desc->flags) & RT2560_TX_BUSY) || in rt2560_encryption_intr()
879 (le32toh(desc->flags) & RT2560_TX_CIPHER_BUSY)) in rt2560_encryption_intr()
883 if ((le32toh(desc->flags) & RT2560_TX_CIPHER_MASK) == in rt2560_encryption_intr()
885 desc->eiv = bswap32(desc->eiv); in rt2560_encryption_intr()
888 desc->flags |= htole32(RT2560_TX_VALID); in rt2560_encryption_intr()
889 desc->flags |= htole32(RT2560_TX_BUSY); in rt2560_encryption_intr()
892 sc->txq.next_encrypt); in rt2560_encryption_intr()
894 sc->txq.next_encrypt = in rt2560_encryption_intr()
895 (sc->txq.next_encrypt + 1) % RT2560_TX_RING_COUNT; in rt2560_encryption_intr()
898 bus_dmamap_sync(sc->txq.desc_dmat, sc->txq.desc_map, in rt2560_encryption_intr()
908 struct ieee80211_ratectl_tx_status *txs = &sc->sc_txs; in rt2560_tx_intr()
916 bus_dmamap_sync(sc->txq.desc_dmat, sc->txq.desc_map, in rt2560_tx_intr()
919 txs->flags = IEEE80211_RATECTL_STATUS_LONG_RETRY; in rt2560_tx_intr()
921 desc = &sc->txq.desc[sc->txq.next]; in rt2560_tx_intr()
922 data = &sc->txq.data[sc->txq.next]; in rt2560_tx_intr()
924 flags = le32toh(desc->flags); in rt2560_tx_intr()
930 m = data->m; in rt2560_tx_intr()
931 ni = data->ni; in rt2560_tx_intr()
935 txs->status = IEEE80211_RATECTL_TX_SUCCESS; in rt2560_tx_intr()
936 txs->long_retries = 0; in rt2560_tx_intr()
939 if (data->rix != IEEE80211_FIXED_RATE_NONE) in rt2560_tx_intr()
945 txs->status = IEEE80211_RATECTL_TX_SUCCESS; in rt2560_tx_intr()
946 txs->long_retries = RT2560_TX_RETRYCNT(flags); in rt2560_tx_intr()
949 txs->long_retries); in rt2560_tx_intr()
950 if (data->rix != IEEE80211_FIXED_RATE_NONE) in rt2560_tx_intr()
956 txs->status = IEEE80211_RATECTL_TX_FAIL_LONG; in rt2560_tx_intr()
957 txs->long_retries = RT2560_TX_RETRYCNT(flags); in rt2560_tx_intr()
960 txs->long_retries); in rt2560_tx_intr()
961 if (data->rix != IEEE80211_FIXED_RATE_NONE) in rt2560_tx_intr()
969 device_printf(sc->sc_dev, "sending data frame failed " in rt2560_tx_intr()
974 bus_dmamap_sync(sc->txq.data_dmat, data->map, in rt2560_tx_intr()
976 bus_dmamap_unload(sc->txq.data_dmat, data->map); in rt2560_tx_intr()
979 data->ni = NULL; in rt2560_tx_intr()
980 data->m = NULL; in rt2560_tx_intr()
983 desc->flags &= ~htole32(RT2560_TX_VALID); in rt2560_tx_intr()
985 DPRINTFN(sc, 15, "tx done idx=%u\n", sc->txq.next); in rt2560_tx_intr()
987 sc->txq.queued--; in rt2560_tx_intr()
988 sc->txq.next = (sc->txq.next + 1) % RT2560_TX_RING_COUNT; in rt2560_tx_intr()
991 bus_dmamap_sync(sc->txq.desc_dmat, sc->txq.desc_map, in rt2560_tx_intr()
994 if (sc->prioq.queued == 0 && sc->txq.queued == 0) in rt2560_tx_intr()
995 sc->sc_tx_timer = 0; in rt2560_tx_intr()
997 if (sc->txq.queued < RT2560_TX_RING_COUNT - 1) in rt2560_tx_intr()
1010 bus_dmamap_sync(sc->prioq.desc_dmat, sc->prioq.desc_map, in rt2560_prio_intr()
1014 desc = &sc->prioq.desc[sc->prioq.next]; in rt2560_prio_intr()
1015 data = &sc->prioq.data[sc->prioq.next]; in rt2560_prio_intr()
1017 flags = le32toh(desc->flags); in rt2560_prio_intr()
1039 device_printf(sc->sc_dev, "sending mgt frame failed " in rt2560_prio_intr()
1044 bus_dmamap_sync(sc->prioq.data_dmat, data->map, in rt2560_prio_intr()
1046 bus_dmamap_unload(sc->prioq.data_dmat, data->map); in rt2560_prio_intr()
1048 m = data->m; in rt2560_prio_intr()
1049 data->m = NULL; in rt2560_prio_intr()
1050 ni = data->ni; in rt2560_prio_intr()
1051 data->ni = NULL; in rt2560_prio_intr()
1054 desc->flags &= ~htole32(RT2560_TX_VALID); in rt2560_prio_intr()
1056 DPRINTFN(sc, 15, "prio done idx=%u\n", sc->prioq.next); in rt2560_prio_intr()
1058 sc->prioq.queued--; in rt2560_prio_intr()
1059 sc->prioq.next = (sc->prioq.next + 1) % RT2560_PRIO_RING_COUNT; in rt2560_prio_intr()
1061 if (m->m_flags & M_TXCB) in rt2560_prio_intr()
1069 bus_dmamap_sync(sc->prioq.desc_dmat, sc->prioq.desc_map, in rt2560_prio_intr()
1072 if (sc->prioq.queued == 0 && sc->txq.queued == 0) in rt2560_prio_intr()
1073 sc->sc_tx_timer = 0; in rt2560_prio_intr()
1075 if (sc->prioq.queued < RT2560_PRIO_RING_COUNT) in rt2560_prio_intr()
1086 struct ieee80211com *ic = &sc->sc_ic; in rt2560_decryption_intr()
1097 hw = RAL_READ(sc, RT2560_SECCSR0) - sc->rxq.physaddr; in rt2560_decryption_intr()
1100 bus_dmamap_sync(sc->rxq.desc_dmat, sc->rxq.desc_map, in rt2560_decryption_intr()
1103 for (; sc->rxq.cur_decrypt != hw;) { in rt2560_decryption_intr()
1104 desc = &sc->rxq.desc[sc->rxq.cur_decrypt]; in rt2560_decryption_intr()
1105 data = &sc->rxq.data[sc->rxq.cur_decrypt]; in rt2560_decryption_intr()
1107 if ((le32toh(desc->flags) & RT2560_RX_BUSY) || in rt2560_decryption_intr()
1108 (le32toh(desc->flags) & RT2560_RX_CIPHER_BUSY)) in rt2560_decryption_intr()
1111 if (data->drop) { in rt2560_decryption_intr()
1112 counter_u64_add(ic->ic_ierrors, 1); in rt2560_decryption_intr()
1116 if ((le32toh(desc->flags) & RT2560_RX_CIPHER_MASK) != 0 && in rt2560_decryption_intr()
1117 (le32toh(desc->flags) & RT2560_RX_ICV_ERROR)) { in rt2560_decryption_intr()
1118 counter_u64_add(ic->ic_ierrors, 1); in rt2560_decryption_intr()
1131 counter_u64_add(ic->ic_ierrors, 1); in rt2560_decryption_intr()
1135 bus_dmamap_sync(sc->rxq.data_dmat, data->map, in rt2560_decryption_intr()
1137 bus_dmamap_unload(sc->rxq.data_dmat, data->map); in rt2560_decryption_intr()
1139 error = bus_dmamap_load(sc->rxq.data_dmat, data->map, in rt2560_decryption_intr()
1146 error = bus_dmamap_load(sc->rxq.data_dmat, data->map, in rt2560_decryption_intr()
1147 mtod(data->m, void *), MCLBYTES, in rt2560_decryption_intr()
1152 device_get_name(sc->sc_dev)); in rt2560_decryption_intr()
1154 counter_u64_add(ic->ic_ierrors, 1); in rt2560_decryption_intr()
1162 m = data->m; in rt2560_decryption_intr()
1163 data->m = mnew; in rt2560_decryption_intr()
1164 desc->physaddr = htole32(physaddr); in rt2560_decryption_intr()
1167 m->m_pkthdr.len = m->m_len = in rt2560_decryption_intr()
1168 (le32toh(desc->flags) >> 16) & 0xfff; in rt2560_decryption_intr()
1170 rssi = RT2560_RSSI(sc, desc->rssi); in rt2560_decryption_intr()
1173 struct rt2560_rx_radiotap_header *tap = &sc->sc_rxtap; in rt2560_decryption_intr() local
1180 tap->wr_tsf = in rt2560_decryption_intr()
1182 tap->wr_flags = 0; in rt2560_decryption_intr()
1183 tap->wr_rate = ieee80211_plcp2rate(desc->rate, in rt2560_decryption_intr()
1184 (desc->flags & htole32(RT2560_RX_OFDM)) ? in rt2560_decryption_intr()
1186 tap->wr_antenna = sc->rx_ant; in rt2560_decryption_intr()
1187 tap->wr_antsignal = nf + rssi; in rt2560_decryption_intr()
1188 tap->wr_antnoise = nf; in rt2560_decryption_intr()
1191 sc->sc_flags |= RT2560_F_INPUT_RUNNING; in rt2560_decryption_intr()
1203 sc->sc_flags &= ~RT2560_F_INPUT_RUNNING; in rt2560_decryption_intr()
1204 skip: desc->flags = htole32(RT2560_RX_BUSY); in rt2560_decryption_intr()
1206 DPRINTFN(sc, 15, "decryption done idx=%u\n", sc->rxq.cur_decrypt); in rt2560_decryption_intr()
1208 sc->rxq.cur_decrypt = in rt2560_decryption_intr()
1209 (sc->rxq.cur_decrypt + 1) % RT2560_RX_RING_COUNT; in rt2560_decryption_intr()
1212 bus_dmamap_sync(sc->rxq.desc_dmat, sc->rxq.desc_map, in rt2560_decryption_intr()
1226 bus_dmamap_sync(sc->rxq.desc_dmat, sc->rxq.desc_map, in rt2560_rx_intr()
1230 desc = &sc->rxq.desc[sc->rxq.cur]; in rt2560_rx_intr()
1231 data = &sc->rxq.data[sc->rxq.cur]; in rt2560_rx_intr()
1233 if ((le32toh(desc->flags) & RT2560_RX_BUSY) || in rt2560_rx_intr()
1234 (le32toh(desc->flags) & RT2560_RX_CIPHER_BUSY)) in rt2560_rx_intr()
1237 data->drop = 0; in rt2560_rx_intr()
1239 if ((le32toh(desc->flags) & RT2560_RX_PHY_ERROR) || in rt2560_rx_intr()
1240 (le32toh(desc->flags) & RT2560_RX_CRC_ERROR)) { in rt2560_rx_intr()
1246 le32toh(desc->flags)); in rt2560_rx_intr()
1247 data->drop = 1; in rt2560_rx_intr()
1250 if (((le32toh(desc->flags) >> 16) & 0xfff) > MCLBYTES) { in rt2560_rx_intr()
1252 data->drop = 1; in rt2560_rx_intr()
1256 desc->flags |= htole32(RT2560_RX_CIPHER_BUSY); in rt2560_rx_intr()
1258 DPRINTFN(sc, 15, "rx done idx=%u\n", sc->rxq.cur); in rt2560_rx_intr()
1260 sc->rxq.cur = (sc->rxq.cur + 1) % RT2560_RX_RING_COUNT; in rt2560_rx_intr()
1263 bus_dmamap_sync(sc->rxq.desc_dmat, sc->rxq.desc_map, in rt2560_rx_intr()
1273 struct ieee80211_beacon_offsets *bo = &vap->iv_bcn_off; in rt2560_beacon_update()
1275 setbit(bo->bo_flags, item); in rt2560_beacon_update()
1285 struct ieee80211com *ic = &sc->sc_ic; in rt2560_beacon_expire()
1288 if (ic->ic_opmode != IEEE80211_M_IBSS && in rt2560_beacon_expire()
1289 ic->ic_opmode != IEEE80211_M_HOSTAP && in rt2560_beacon_expire()
1290 ic->ic_opmode != IEEE80211_M_MBSS) in rt2560_beacon_expire()
1293 data = &sc->bcnq.data[sc->bcnq.next]; in rt2560_beacon_expire()
1297 if (data->ni == NULL) in rt2560_beacon_expire()
1300 bus_dmamap_sync(sc->bcnq.data_dmat, data->map, BUS_DMASYNC_POSTWRITE); in rt2560_beacon_expire()
1301 bus_dmamap_unload(sc->bcnq.data_dmat, data->map); in rt2560_beacon_expire()
1304 ieee80211_beacon_update(data->ni, data->m, 1); in rt2560_beacon_expire()
1306 rt2560_tx_bcn(sc, data->m, data->ni); in rt2560_beacon_expire()
1310 sc->bcnq.next = (sc->bcnq.next + 1) % RT2560_BEACON_RING_COUNT; in rt2560_beacon_expire()
1331 /* don't re-enable interrupts if we're shutting down */ in rt2560_intr()
1332 if (!(sc->sc_flags & RT2560_F_RUNNING)) { in rt2560_intr()
1363 /* re-enable interrupts */ in rt2560_intr()
1377 /* OFDM rates (cf IEEE Std 802.11a-1999, pp. 14 Table 80) */ in rt2560_plcp_signal()
1387 /* CCK rates (NB: not IEEE std, device-specific) */ in rt2560_plcp_signal()
1400 struct ieee80211com *ic = &sc->sc_ic; in rt2560_setup_tx_desc()
1404 desc->flags = htole32(flags); in rt2560_setup_tx_desc()
1405 desc->flags |= htole32(len << 16); in rt2560_setup_tx_desc()
1407 desc->physaddr = htole32(physaddr); in rt2560_setup_tx_desc()
1408 desc->wme = htole16( in rt2560_setup_tx_desc()
1414 desc->plcp_signal = rt2560_plcp_signal(rate); in rt2560_setup_tx_desc()
1415 desc->plcp_service = 4; in rt2560_setup_tx_desc()
1418 if (ieee80211_rate2phytype(ic->ic_rt, rate) == IEEE80211_T_OFDM) { in rt2560_setup_tx_desc()
1419 desc->flags |= htole32(RT2560_TX_OFDM); in rt2560_setup_tx_desc()
1422 desc->plcp_length_hi = plcp_length >> 6; in rt2560_setup_tx_desc()
1423 desc->plcp_length_lo = plcp_length & 0x3f; in rt2560_setup_tx_desc()
1429 desc->plcp_service |= RT2560_PLCP_LENGEXT; in rt2560_setup_tx_desc()
1431 desc->plcp_length_hi = plcp_length >> 8; in rt2560_setup_tx_desc()
1432 desc->plcp_length_lo = plcp_length & 0xff; in rt2560_setup_tx_desc()
1434 if (rate != 2 && (ic->ic_flags & IEEE80211_F_SHPREAMBLE)) in rt2560_setup_tx_desc()
1435 desc->plcp_signal |= 0x08; in rt2560_setup_tx_desc()
1439 desc->flags |= htole32(RT2560_TX_VALID); in rt2560_setup_tx_desc()
1440 desc->flags |= encrypt ? htole32(RT2560_TX_CIPHER_BUSY) in rt2560_setup_tx_desc()
1448 struct ieee80211vap *vap = ni->ni_vap; in rt2560_tx_bcn()
1454 desc = &sc->bcnq.desc[sc->bcnq.cur]; in rt2560_tx_bcn()
1455 data = &sc->bcnq.data[sc->bcnq.cur]; in rt2560_tx_bcn()
1458 rate = vap->iv_txparms[ieee80211_chan2mode(ni->ni_chan)].mgmtrate; in rt2560_tx_bcn()
1460 error = bus_dmamap_load_mbuf_sg(sc->bcnq.data_dmat, data->map, m0, in rt2560_tx_bcn()
1463 device_printf(sc->sc_dev, "could not map mbuf (error %d)\n", in rt2560_tx_bcn()
1470 struct rt2560_tx_radiotap_header *tap = &sc->sc_txtap; in rt2560_tx_bcn() local
1472 tap->wt_flags = 0; in rt2560_tx_bcn()
1473 tap->wt_rate = rate; in rt2560_tx_bcn()
1474 tap->wt_antenna = sc->tx_ant; in rt2560_tx_bcn()
1479 data->m = m0; in rt2560_tx_bcn()
1480 data->ni = ni; in rt2560_tx_bcn()
1483 RT2560_TX_TIMESTAMP, m0->m_pkthdr.len, rate, 0, segs->ds_addr); in rt2560_tx_bcn()
1486 m0->m_pkthdr.len, sc->bcnq.cur, rate); in rt2560_tx_bcn()
1488 bus_dmamap_sync(sc->bcnq.data_dmat, data->map, BUS_DMASYNC_PREWRITE); in rt2560_tx_bcn()
1489 bus_dmamap_sync(sc->bcnq.desc_dmat, sc->bcnq.desc_map, in rt2560_tx_bcn()
1492 sc->bcnq.cur = (sc->bcnq.cur + 1) % RT2560_BEACON_RING_COUNT; in rt2560_tx_bcn()
1501 struct ieee80211vap *vap = ni->ni_vap; in rt2560_tx_mgt()
1502 struct ieee80211com *ic = ni->ni_ic; in rt2560_tx_mgt()
1512 desc = &sc->prioq.desc[sc->prioq.cur]; in rt2560_tx_mgt()
1513 data = &sc->prioq.data[sc->prioq.cur]; in rt2560_tx_mgt()
1515 rate = ni->ni_txparms->mgmtrate; in rt2560_tx_mgt()
1519 if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) { in rt2560_tx_mgt()
1527 error = bus_dmamap_load_mbuf_sg(sc->prioq.data_dmat, data->map, m0, in rt2560_tx_mgt()
1530 device_printf(sc->sc_dev, "could not map mbuf (error %d)\n", in rt2560_tx_mgt()
1537 struct rt2560_tx_radiotap_header *tap = &sc->sc_txtap; in rt2560_tx_mgt() local
1539 tap->wt_flags = 0; in rt2560_tx_mgt()
1540 tap->wt_rate = rate; in rt2560_tx_mgt()
1541 tap->wt_antenna = sc->tx_ant; in rt2560_tx_mgt()
1546 data->m = m0; in rt2560_tx_mgt()
1547 data->ni = ni; in rt2560_tx_mgt()
1549 data->rix = IEEE80211_FIXED_RATE_NONE; in rt2560_tx_mgt()
1553 if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) { in rt2560_tx_mgt()
1556 dur = ieee80211_ack_duration(ic->ic_rt, in rt2560_tx_mgt()
1557 rate, ic->ic_flags & IEEE80211_F_SHPREAMBLE); in rt2560_tx_mgt()
1558 *(uint16_t *)wh->i_dur = htole16(dur); in rt2560_tx_mgt()
1565 rt2560_setup_tx_desc(sc, desc, flags, m0->m_pkthdr.len, rate, 0, in rt2560_tx_mgt()
1566 segs->ds_addr); in rt2560_tx_mgt()
1568 bus_dmamap_sync(sc->prioq.data_dmat, data->map, BUS_DMASYNC_PREWRITE); in rt2560_tx_mgt()
1569 bus_dmamap_sync(sc->prioq.desc_dmat, sc->prioq.desc_map, in rt2560_tx_mgt()
1573 m0->m_pkthdr.len, sc->prioq.cur, rate); in rt2560_tx_mgt()
1576 sc->prioq.queued++; in rt2560_tx_mgt()
1577 sc->prioq.cur = (sc->prioq.cur + 1) % RT2560_PRIO_RING_COUNT; in rt2560_tx_mgt()
1587 struct ieee80211com *ic = ni->ni_ic; in rt2560_sendprot()
1597 if_inc_counter(ni->ni_vap->iv_ifp, IFCOUNTER_OERRORS, 1); in rt2560_sendprot()
1598 device_printf(sc->sc_dev, in rt2560_sendprot()
1603 desc = &sc->txq.desc[sc->txq.cur_encrypt]; in rt2560_sendprot()
1604 data = &sc->txq.data[sc->txq.cur_encrypt]; in rt2560_sendprot()
1606 error = bus_dmamap_load_mbuf_sg(sc->txq.data_dmat, data->map, in rt2560_sendprot()
1609 device_printf(sc->sc_dev, in rt2560_sendprot()
1615 data->m = mprot; in rt2560_sendprot()
1616 data->ni = ieee80211_ref_node(ni); in rt2560_sendprot()
1618 data->rix = IEEE80211_FIXED_RATE_NONE; in rt2560_sendprot()
1620 protrate = ieee80211_ctl_rate(ic->ic_rt, rate); in rt2560_sendprot()
1625 rt2560_setup_tx_desc(sc, desc, flags, mprot->m_pkthdr.len, protrate, 1, in rt2560_sendprot()
1626 segs->ds_addr); in rt2560_sendprot()
1628 bus_dmamap_sync(sc->txq.data_dmat, data->map, in rt2560_sendprot()
1631 sc->txq.queued++; in rt2560_sendprot()
1632 sc->txq.cur_encrypt = (sc->txq.cur_encrypt + 1) % RT2560_TX_RING_COUNT; in rt2560_sendprot()
1641 struct ieee80211vap *vap = ni->ni_vap; in rt2560_tx_raw()
1642 struct ieee80211com *ic = ni->ni_ic; in rt2560_tx_raw()
1649 desc = &sc->prioq.desc[sc->prioq.cur]; in rt2560_tx_raw()
1650 data = &sc->prioq.data[sc->prioq.cur]; in rt2560_tx_raw()
1652 rate = params->ibp_rate0; in rt2560_tx_raw()
1653 if (!ieee80211_isratevalid(ic->ic_rt, rate)) { in rt2560_tx_raw()
1660 if ((params->ibp_flags & IEEE80211_BPF_NOACK) == 0) in rt2560_tx_raw()
1662 if (params->ibp_flags & (IEEE80211_BPF_RTS|IEEE80211_BPF_CTS)) { in rt2560_tx_raw()
1664 params->ibp_flags & IEEE80211_BPF_RTS ? in rt2560_tx_raw()
1674 error = bus_dmamap_load_mbuf_sg(sc->prioq.data_dmat, data->map, m0, in rt2560_tx_raw()
1677 device_printf(sc->sc_dev, "could not map mbuf (error %d)\n", in rt2560_tx_raw()
1684 struct rt2560_tx_radiotap_header *tap = &sc->sc_txtap; in rt2560_tx_raw() local
1686 tap->wt_flags = 0; in rt2560_tx_raw()
1687 tap->wt_rate = rate; in rt2560_tx_raw()
1688 tap->wt_antenna = sc->tx_ant; in rt2560_tx_raw()
1690 ieee80211_radiotap_tx(ni->ni_vap, m0); in rt2560_tx_raw()
1693 data->m = m0; in rt2560_tx_raw()
1694 data->ni = ni; in rt2560_tx_raw()
1697 rt2560_setup_tx_desc(sc, desc, flags, m0->m_pkthdr.len, in rt2560_tx_raw()
1698 rate, (params->ibp_flags & IEEE80211_BPF_CRYPTO) != 0, in rt2560_tx_raw()
1699 segs->ds_addr); in rt2560_tx_raw()
1701 bus_dmamap_sync(sc->prioq.data_dmat, data->map, BUS_DMASYNC_PREWRITE); in rt2560_tx_raw()
1702 bus_dmamap_sync(sc->prioq.desc_dmat, sc->prioq.desc_map, in rt2560_tx_raw()
1706 m0->m_pkthdr.len, sc->prioq.cur, rate); in rt2560_tx_raw()
1709 sc->prioq.queued++; in rt2560_tx_raw()
1710 sc->prioq.cur = (sc->prioq.cur + 1) % RT2560_PRIO_RING_COUNT; in rt2560_tx_raw()
1720 struct ieee80211vap *vap = ni->ni_vap; in rt2560_tx_data()
1721 struct ieee80211com *ic = ni->ni_ic; in rt2560_tx_data()
1725 const struct ieee80211_txparam *tp = ni->ni_txparms; in rt2560_tx_data()
1735 if (m0->m_flags & M_EAPOL) { in rt2560_tx_data()
1736 rate = tp->mgmtrate; in rt2560_tx_data()
1737 } else if (IEEE80211_IS_MULTICAST(wh->i_addr1)) { in rt2560_tx_data()
1738 rate = tp->mcastrate; in rt2560_tx_data()
1739 } else if (tp->ucastrate != IEEE80211_FIXED_RATE_NONE) { in rt2560_tx_data()
1740 rate = tp->ucastrate; in rt2560_tx_data()
1746 if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) { in rt2560_tx_data()
1758 if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) { in rt2560_tx_data()
1760 if (m0->m_pkthdr.len + IEEE80211_CRC_LEN > vap->iv_rtsthreshold) in rt2560_tx_data()
1762 else if ((ic->ic_flags & IEEE80211_F_USEPROT) && in rt2560_tx_data()
1763 ieee80211_rate2phytype(ic->ic_rt, rate) == IEEE80211_T_OFDM) in rt2560_tx_data()
1764 prot = ic->ic_protmode; in rt2560_tx_data()
1775 data = &sc->txq.data[sc->txq.cur_encrypt]; in rt2560_tx_data()
1776 desc = &sc->txq.desc[sc->txq.cur_encrypt]; in rt2560_tx_data()
1778 error = bus_dmamap_load_mbuf_sg(sc->txq.data_dmat, data->map, m0, in rt2560_tx_data()
1781 device_printf(sc->sc_dev, "could not map mbuf (error %d)\n", in rt2560_tx_data()
1789 device_printf(sc->sc_dev, in rt2560_tx_data()
1796 error = bus_dmamap_load_mbuf_sg(sc->txq.data_dmat, data->map, in rt2560_tx_data()
1799 device_printf(sc->sc_dev, in rt2560_tx_data()
1810 struct rt2560_tx_radiotap_header *tap = &sc->sc_txtap; in rt2560_tx_data() local
1812 tap->wt_flags = 0; in rt2560_tx_data()
1813 tap->wt_rate = rate; in rt2560_tx_data()
1814 tap->wt_antenna = sc->tx_ant; in rt2560_tx_data()
1819 data->m = m0; in rt2560_tx_data()
1820 data->ni = ni; in rt2560_tx_data()
1823 if (tp->ucastrate == IEEE80211_FIXED_RATE_NONE) { in rt2560_tx_data()
1824 data->rix = ieee80211_node_get_txrate_dot11rate(ni); in rt2560_tx_data()
1826 data->rssi = ic->ic_node_getrssi(ni); in rt2560_tx_data()
1828 data->rix = IEEE80211_FIXED_RATE_NONE; in rt2560_tx_data()
1830 if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) { in rt2560_tx_data()
1833 dur = ieee80211_ack_duration(ic->ic_rt, in rt2560_tx_data()
1834 rate, ic->ic_flags & IEEE80211_F_SHPREAMBLE); in rt2560_tx_data()
1835 *(uint16_t *)wh->i_dur = htole16(dur); in rt2560_tx_data()
1838 rt2560_setup_tx_desc(sc, desc, flags, m0->m_pkthdr.len, rate, 1, in rt2560_tx_data()
1839 segs->ds_addr); in rt2560_tx_data()
1841 bus_dmamap_sync(sc->txq.data_dmat, data->map, BUS_DMASYNC_PREWRITE); in rt2560_tx_data()
1842 bus_dmamap_sync(sc->txq.desc_dmat, sc->txq.desc_map, in rt2560_tx_data()
1846 m0->m_pkthdr.len, sc->txq.cur_encrypt, rate); in rt2560_tx_data()
1849 sc->txq.queued++; in rt2560_tx_data()
1850 sc->txq.cur_encrypt = (sc->txq.cur_encrypt + 1) % RT2560_TX_RING_COUNT; in rt2560_tx_data()
1859 struct rt2560_softc *sc = ic->ic_softc; in rt2560_transmit()
1863 if ((sc->sc_flags & RT2560_F_RUNNING) == 0) { in rt2560_transmit()
1867 error = mbufq_enqueue(&sc->sc_snd, m); in rt2560_transmit()
1886 while (sc->txq.queued < RT2560_TX_RING_COUNT - 1 && in rt2560_start()
1887 (m = mbufq_dequeue(&sc->sc_snd)) != NULL) { in rt2560_start()
1888 ni = (struct ieee80211_node *) m->m_pkthdr.rcvif; in rt2560_start()
1890 if_inc_counter(ni->ni_vap->iv_ifp, in rt2560_start()
1895 sc->sc_tx_timer = 5; in rt2560_start()
1906 KASSERT(sc->sc_flags & RT2560_F_RUNNING, ("not running")); in rt2560_watchdog()
1908 if (sc->sc_invalid) /* card ejected */ in rt2560_watchdog()
1914 if (sc->sc_tx_timer > 0 && --sc->sc_tx_timer == 0) { in rt2560_watchdog()
1915 device_printf(sc->sc_dev, "device timeout\n"); in rt2560_watchdog()
1917 counter_u64_add(sc->sc_ic.ic_oerrors, 1); in rt2560_watchdog()
1921 callout_reset(&sc->watchdog_ch, hz, rt2560_watchdog, sc); in rt2560_watchdog()
1927 struct rt2560_softc *sc = ic->ic_softc; in rt2560_parent()
1931 if (ic->ic_nrunning > 0) { in rt2560_parent()
1932 if ((sc->sc_flags & RT2560_F_RUNNING) == 0) { in rt2560_parent()
1937 } else if (sc->sc_flags & RT2560_F_RUNNING) in rt2560_parent()
1956 device_printf(sc->sc_dev, "could not write to BBP\n"); in rt2560_bbp_write()
1963 DPRINTFN(sc, 15, "BBP R%u <- 0x%02x\n", reg, val); in rt2560_bbp_write()
1978 device_printf(sc->sc_dev, "could not read from BBP\n"); in rt2560_bbp_read()
1992 device_printf(sc->sc_dev, "could not read from BBP\n"); in rt2560_bbp_read()
2008 device_printf(sc->sc_dev, "could not write to RF\n"); in rt2560_rf_write()
2017 sc->rf_regs[reg] = val; in rt2560_rf_write()
2019 DPRINTFN(sc, 15, "RF R[%u] <- 0x%05x\n", reg & 0x3, val & 0xfffff); in rt2560_rf_write()
2025 struct ieee80211com *ic = &sc->sc_ic; in rt2560_set_chan()
2033 power = min(sc->txpow[chan - 1], 31); in rt2560_set_chan()
2038 power -= (100 - ic->ic_txpowlimit) / 8; in rt2560_set_chan()
2042 switch (sc->rf_rev) { in rt2560_set_chan()
2045 rt2560_rf_write(sc, RAL_RF2, rt2560_rf2522_r2[chan - 1]); in rt2560_set_chan()
2051 rt2560_rf_write(sc, RAL_RF2, rt2560_rf2523_r2[chan - 1]); in rt2560_set_chan()
2058 rt2560_rf_write(sc, RAL_RF2, rt2560_rf2524_r2[chan - 1]); in rt2560_set_chan()
2065 rt2560_rf_write(sc, RAL_RF2, rt2560_rf2525_hi_r2[chan - 1]); in rt2560_set_chan()
2070 rt2560_rf_write(sc, RAL_RF2, rt2560_rf2525_r2[chan - 1]); in rt2560_set_chan()
2077 rt2560_rf_write(sc, RAL_RF2, rt2560_rf2525e_r2[chan - 1]); in rt2560_set_chan()
2083 rt2560_rf_write(sc, RAL_RF2, rt2560_rf2526_hi_r2[chan - 1]); in rt2560_set_chan()
2087 rt2560_rf_write(sc, RAL_RF2, rt2560_rf2526_r2[chan - 1]); in rt2560_set_chan()
2092 /* dual-band RF */ in rt2560_set_chan()
2102 printf("unknown ral rev=%d\n", sc->rf_rev); in rt2560_set_chan()
2106 if ((ic->ic_flags & IEEE80211_F_SCAN) == 0) { in rt2560_set_chan()
2125 struct rt2560_softc *sc = ic->ic_softc; in rt2560_getradiocaps()
2133 if (sc->rf_rev == RT2560_RF_5222) { in rt2560_getradiocaps()
2143 struct rt2560_softc *sc = ic->ic_softc; in rt2560_set_channel()
2146 rt2560_set_chan(sc, ic->ic_curchan); in rt2560_set_channel()
2153 * Disable RF auto-tuning.
2160 if (sc->rf_rev != RT2560_RF_2523) {
2161 tmp = sc->rf_regs[RAL_RF1] & ~RAL_RF1_AUTOTUNE;
2165 tmp = sc->rf_regs[RAL_RF3] & ~RAL_RF3_AUTOTUNE;
2173 * Refer to IEEE Std 802.11-1999 pp. 123 for more information on TSF
2179 struct ieee80211com *ic = &sc->sc_ic; in rt2560_enable_tsf_sync()
2180 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); in rt2560_enable_tsf_sync()
2187 tmp = 16 * vap->iv_bss->ni_intval; in rt2560_enable_tsf_sync()
2193 preload = (vap->iv_opmode == IEEE80211_M_STA) ? 384 : 1024; in rt2560_enable_tsf_sync()
2199 if (ic->ic_opmode == IEEE80211_M_STA) in rt2560_enable_tsf_sync()
2220 struct ieee80211com *ic = &sc->sc_ic; in rt2560_update_plcp()
2225 if (!(ic->ic_flags & IEEE80211_F_SHPREAMBLE)) { in rt2560_update_plcp()
2238 (ic->ic_flags & IEEE80211_F_SHPREAMBLE) ? "short" : "long"); in rt2560_update_plcp()
2243 * IEEE Std 802.11-1999 pp. 85 to know how these values are computed.
2248 struct rt2560_softc *sc = ic->ic_softc; in rt2560_update_slot()
2269 * (-1Mb~-2Mb lower) and the _whole_ BSS would stop using short in rt2560_update_slot()
2276 tx_sifs = RAL_SIFS - RT2560_TXRX_TURNAROUND; in rt2560_update_slot()
2279 eifs = (ic->ic_curmode == IEEE80211_MODE_11B) ? 364 : 60; in rt2560_update_slot()
2298 struct ieee80211com *ic = &sc->sc_ic; in rt2560_set_basicrates()
2303 for (i = 0; i < rs->rs_nrates; i++) { in rt2560_set_basicrates()
2304 rate = rs->rs_rates[i]; in rt2560_set_basicrates()
2309 mask |= 1 << ieee80211_legacy_rate_lookup(ic->ic_rt, in rt2560_set_basicrates()
2375 struct rt2560_softc *sc = ic->ic_softc; in rt2560_update_promisc()
2381 if (ic->ic_promisc == 0) in rt2560_update_promisc()
2387 (ic->ic_promisc > 0) ? "entering" : "leaving"); in rt2560_update_promisc()
2412 sc->rf_rev = (val >> 11) & 0x7; in rt2560_read_config()
2413 sc->hw_radio = (val >> 10) & 0x1; in rt2560_read_config()
2414 sc->led_mode = (val >> 6) & 0x7; in rt2560_read_config()
2415 sc->rx_ant = (val >> 4) & 0x3; in rt2560_read_config()
2416 sc->tx_ant = (val >> 2) & 0x3; in rt2560_read_config()
2417 sc->nb_ant = val & 0x3; in rt2560_read_config()
2425 sc->bbp_prom[i].reg = val >> 8; in rt2560_read_config()
2426 sc->bbp_prom[i].val = val & 0xff; in rt2560_read_config()
2432 sc->txpow[i * 2] = val & 0xff; in rt2560_read_config()
2433 sc->txpow[i * 2 + 1] = val >> 8; in rt2560_read_config()
2436 if (sc->txpow[i] > 31) in rt2560_read_config()
2437 sc->txpow[i] = 24; in rt2560_read_config()
2442 sc->rssi_corr = RT2560_DEFAULT_RSSI_CORR; in rt2560_read_config()
2444 sc->rssi_corr = val & 0xff; in rt2560_read_config()
2446 sc->rssi_corr, val); in rt2560_read_config()
2452 struct rt2560_softc *sc = ic->ic_softc; in rt2560_scan_start()
2462 struct rt2560_softc *sc = ic->ic_softc; in rt2560_scan_end()
2463 struct ieee80211vap *vap = ic->ic_scan->ss_vap; in rt2560_scan_end()
2467 rt2560_set_bssid(sc, vap->iv_bss->ni_bssid); in rt2560_scan_end()
2482 device_printf(sc->sc_dev, "timeout waiting for BBP\n"); in rt2560_bbp_init()
2494 if (sc->bbp_prom[i].reg == 0 && sc->bbp_prom[i].val == 0) in rt2560_bbp_init()
2496 rt2560_bbp_write(sc, sc->bbp_prom[i].reg, sc->bbp_prom[i].val); in rt2560_bbp_init()
2518 if (sc->rf_rev == RT2560_RF_2525E || sc->rf_rev == RT2560_RF_2526 || in rt2560_set_txantenna()
2519 sc->rf_rev == RT2560_RF_5222) in rt2560_set_txantenna()
2544 if (sc->rf_rev == RT2560_RF_2525E || sc->rf_rev == RT2560_RF_2526) in rt2560_set_rxantenna()
2553 struct ieee80211com *ic = &sc->sc_ic; in rt2560_init_locked()
2554 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); in rt2560_init_locked()
2570 RAL_WRITE(sc, RT2560_TXCSR3, sc->txq.physaddr); in rt2560_init_locked()
2571 RAL_WRITE(sc, RT2560_TXCSR5, sc->prioq.physaddr); in rt2560_init_locked()
2572 RAL_WRITE(sc, RT2560_TXCSR4, sc->atimq.physaddr); in rt2560_init_locked()
2573 RAL_WRITE(sc, RT2560_TXCSR6, sc->bcnq.physaddr); in rt2560_init_locked()
2579 RAL_WRITE(sc, RT2560_RXCSR2, sc->rxq.physaddr); in rt2560_init_locked()
2585 rt2560_set_macaddr(sc, vap ? vap->iv_myaddr : ic->ic_macaddr); in rt2560_init_locked()
2602 rt2560_set_txantenna(sc, sc->tx_ant); in rt2560_init_locked()
2603 rt2560_set_rxantenna(sc, sc->rx_ant); in rt2560_init_locked()
2606 rt2560_set_chan(sc, ic->ic_curchan); in rt2560_init_locked()
2610 if (ic->ic_opmode != IEEE80211_M_MONITOR) { in rt2560_init_locked()
2612 if (ic->ic_opmode != IEEE80211_M_HOSTAP && in rt2560_init_locked()
2613 ic->ic_opmode != IEEE80211_M_MBSS) in rt2560_init_locked()
2615 if (ic->ic_promisc == 0) in rt2560_init_locked()
2630 sc->sc_flags |= RT2560_F_RUNNING; in rt2560_init_locked()
2632 callout_reset(&sc->watchdog_ch, hz, rt2560_watchdog, sc); in rt2560_init_locked()
2639 struct ieee80211com *ic = &sc->sc_ic; in rt2560_init()
2645 if (sc->sc_flags & RT2560_F_RUNNING) in rt2560_init()
2646 ieee80211_start_all(ic); /* start all vap's */ in rt2560_init()
2652 volatile int *flags = &sc->sc_flags; in rt2560_stop_locked()
2657 msleep(sc, &sc->sc_mtx, 0, "ralrunning", hz/10); in rt2560_stop_locked()
2659 callout_stop(&sc->watchdog_ch); in rt2560_stop_locked()
2660 sc->sc_tx_timer = 0; in rt2560_stop_locked()
2662 if (sc->sc_flags & RT2560_F_RUNNING) { in rt2560_stop_locked()
2663 sc->sc_flags &= ~RT2560_F_RUNNING; in rt2560_stop_locked()
2679 rt2560_reset_tx_ring(sc, &sc->txq); in rt2560_stop_locked()
2680 rt2560_reset_tx_ring(sc, &sc->atimq); in rt2560_stop_locked()
2681 rt2560_reset_tx_ring(sc, &sc->prioq); in rt2560_stop_locked()
2682 rt2560_reset_tx_ring(sc, &sc->bcnq); in rt2560_stop_locked()
2683 rt2560_reset_rx_ring(sc, &sc->rxq); in rt2560_stop_locked()
2701 struct ieee80211com *ic = ni->ni_ic; in rt2560_raw_xmit()
2702 struct rt2560_softc *sc = ic->ic_softc; in rt2560_raw_xmit()
2707 if (!(sc->sc_flags & RT2560_F_RUNNING)) { in rt2560_raw_xmit()
2712 if (sc->prioq.queued >= RT2560_PRIO_RING_COUNT) { in rt2560_raw_xmit()
2733 sc->sc_tx_timer = 5; in rt2560_raw_xmit()