Lines Matching +full:refresh +full:- +full:rate +full:- +full:hz
2 /*-
3 * Copyright (c) 2005-2007 Damien Bergamini <damien.bergamini@free.fr>
5 * Copyright (c) 2007-2008 Hans Petter Selasky <hselasky@FreeBSD.org>
21 /*-
467 if (uaa->usb_mode != USB_MODE_HOST) in rum_match()
469 if (uaa->info.bConfigIndex != 0) in rum_match()
471 if (uaa->info.bIfaceIndex != RT2573_IFACE_INDEX) in rum_match()
482 struct ieee80211com *ic = &sc->sc_ic; in rum_attach()
488 sc->sc_udev = uaa->device; in rum_attach()
489 sc->sc_dev = self; in rum_attach()
493 mbufq_init(&sc->sc_snd, ifqmaxlen); in rum_attach()
496 error = usbd_transfer_setup(uaa->device, &iface_index, in rum_attach()
497 sc->sc_xfer, rum_config, RUM_N_TRANSFER, sc, &sc->sc_mtx); in rum_attach()
509 if (rum_pause(sc, hz / 100)) in rum_attach()
513 device_printf(sc->sc_dev, "timeout waiting for chip to settle\n"); in rum_attach()
521 device_printf(sc->sc_dev, "MAC/BBP RT2573 (rev 0x%05x), RF %s\n", in rum_attach()
522 tmp, rum_get_rf(sc->rf_rev)); in rum_attach()
527 ic->ic_softc = sc; in rum_attach()
528 ic->ic_name = device_get_nameunit(self); in rum_attach()
529 ic->ic_phytype = IEEE80211_T_OFDM; /* not only, but not used */ in rum_attach()
532 ic->ic_caps = in rum_attach()
544 | IEEE80211_C_PMGT /* Station-side power mgmt */ in rum_attach()
548 ic->ic_cryptocaps = in rum_attach()
554 rum_getradiocaps(ic, IEEE80211_CHAN_MAX, &ic->ic_nchans, in rum_attach()
555 ic->ic_channels); in rum_attach()
558 ic->ic_update_promisc = rum_update_promisc; in rum_attach()
559 ic->ic_raw_xmit = rum_raw_xmit; in rum_attach()
560 ic->ic_scan_start = rum_scan_start; in rum_attach()
561 ic->ic_scan_end = rum_scan_end; in rum_attach()
562 ic->ic_set_channel = rum_set_channel; in rum_attach()
563 ic->ic_getradiocaps = rum_getradiocaps; in rum_attach()
564 ic->ic_transmit = rum_transmit; in rum_attach()
565 ic->ic_parent = rum_parent; in rum_attach()
566 ic->ic_vap_create = rum_vap_create; in rum_attach()
567 ic->ic_vap_delete = rum_vap_delete; in rum_attach()
568 ic->ic_updateslot = rum_update_slot; in rum_attach()
569 ic->ic_wme.wme_update = rum_wme_update; in rum_attach()
570 ic->ic_update_mcast = rum_update_mcast; in rum_attach()
573 &sc->sc_txtap.wt_ihdr, sizeof(sc->sc_txtap), in rum_attach()
575 &sc->sc_rxtap.wr_ihdr, sizeof(sc->sc_rxtap), in rum_attach()
578 TASK_INIT(&sc->cmdq_task, 0, rum_cmdq_cb, sc); in rum_attach()
594 struct ieee80211com *ic = &sc->sc_ic; in rum_detach()
598 sc->sc_detached = 1; in rum_detach()
602 usbd_transfer_unsetup(sc->sc_xfer, RUM_N_TRANSFER); in rum_detach()
609 if (ic->ic_softc == sc) { in rum_detach()
610 ieee80211_draintask(ic, &sc->cmdq_task); in rum_detach()
614 mbufq_drain(&sc->sc_snd); in rum_detach()
628 while (ntries--) { in rum_do_request()
629 err = usbd_do_request_flags(sc->sc_udev, &sc->sc_mtx, in rum_do_request()
636 if (rum_pause(sc, hz / 100)) in rum_do_request()
662 struct rum_softc *sc = ic->ic_softc; in rum_vap_create()
666 if (!TAILQ_EMPTY(&ic->ic_vaps)) /* only one at a time */ in rum_vap_create()
669 vap = &rvp->vap; in rum_vap_create()
680 rvp->newstate = vap->iv_newstate; in rum_vap_create()
681 vap->iv_newstate = rum_newstate; in rum_vap_create()
682 vap->iv_key_alloc = rum_key_alloc; in rum_vap_create()
683 vap->iv_key_set = rum_key_set; in rum_vap_create()
684 vap->iv_key_delete = rum_key_delete; in rum_vap_create()
685 vap->iv_update_beacon = rum_update_beacon; in rum_vap_create()
686 vap->iv_reset = rum_reset; in rum_vap_create()
687 vap->iv_max_aid = RT2573_ADDR_MAX; in rum_vap_create()
696 rvp->recv_mgmt = vap->iv_recv_mgmt; in rum_vap_create()
697 vap->iv_recv_mgmt = rum_sta_recv_mgmt; in rum_vap_create()
700 rvp->bmiss = vap->iv_bmiss; in rum_vap_create()
701 vap->iv_bmiss = rum_beacon_miss; in rum_vap_create()
704 usb_callout_init_mtx(&rvp->ratectl_ch, &sc->sc_mtx, 0); in rum_vap_create()
705 TASK_INIT(&rvp->ratectl_task, 0, rum_ratectl_task, rvp); in rum_vap_create()
711 ic->ic_opmode = opmode; in rum_vap_create()
719 struct ieee80211com *ic = vap->iv_ic; in rum_vap_delete()
720 struct rum_softc *sc = ic->ic_softc; in rum_vap_delete()
724 ieee80211_new_state(vap, IEEE80211_S_INIT, -1); in rum_vap_delete()
726 ieee80211_draintask(ic, &vap->iv_nstate_task[i]); in rum_vap_delete()
733 usb_callout_drain(&rvp->ratectl_ch); in rum_vap_delete()
734 ieee80211_draintask(ic, &rvp->ratectl_task); in rum_vap_delete()
737 m_freem(rvp->bcn_mbuf); in rum_vap_delete()
748 while (sc->cmdq[sc->cmdq_first].func != NULL) { in rum_cmdq_cb()
749 rc = &sc->cmdq[sc->cmdq_first]; in rum_cmdq_cb()
753 rc->func(sc, &rc->data, rc->rvp_id); in rum_cmdq_cb()
758 sc->cmdq_first = (sc->cmdq_first + 1) % RUM_CMDQ_SIZE; in rum_cmdq_cb()
767 struct ieee80211com *ic = &sc->sc_ic; in rum_cmd_sleepable()
772 if (sc->cmdq[sc->cmdq_last].func != NULL) { in rum_cmd_sleepable()
773 device_printf(sc->sc_dev, "%s: cmdq overflow\n", __func__); in rum_cmd_sleepable()
780 memcpy(&sc->cmdq[sc->cmdq_last].data, ptr, len); in rum_cmd_sleepable()
781 sc->cmdq[sc->cmdq_last].rvp_id = rvp_id; in rum_cmd_sleepable()
782 sc->cmdq[sc->cmdq_last].func = func; in rum_cmd_sleepable()
783 sc->cmdq_last = (sc->cmdq_last + 1) % RUM_CMDQ_SIZE; in rum_cmd_sleepable()
786 ieee80211_runtask(ic, &sc->cmdq_task); in rum_cmd_sleepable()
794 struct rum_softc *sc = data->sc; in rum_tx_free()
796 if (data->m != NULL) { in rum_tx_free()
797 ieee80211_tx_complete(data->ni, data->m, txerr); in rum_tx_free()
798 data->m = NULL; in rum_tx_free()
799 data->ni = NULL; in rum_tx_free()
801 STAILQ_INSERT_TAIL(&sc->tx_free, data, next); in rum_tx_free()
802 sc->tx_nfree++; in rum_tx_free()
811 sc->tx_nfree = 0; in rum_setup_tx_list()
812 STAILQ_INIT(&sc->tx_q); in rum_setup_tx_list()
813 STAILQ_INIT(&sc->tx_free); in rum_setup_tx_list()
816 data = &sc->tx_data[i]; in rum_setup_tx_list()
818 data->sc = sc; in rum_setup_tx_list()
819 STAILQ_INSERT_TAIL(&sc->tx_free, data, next); in rum_setup_tx_list()
820 sc->tx_nfree++; in rum_setup_tx_list()
831 STAILQ_FOREACH_SAFE(data, &sc->tx_q, next, tmp) { in rum_reset_tx_list()
832 if (data->ni != NULL && data->ni->ni_vap == vap) { in rum_reset_tx_list()
833 ieee80211_free_node(data->ni); in rum_reset_tx_list()
834 data->ni = NULL; in rum_reset_tx_list()
836 KASSERT(data->m != NULL, ("%s: m is NULL\n", in rum_reset_tx_list()
838 m_freem(data->m); in rum_reset_tx_list()
839 data->m = NULL; in rum_reset_tx_list()
841 STAILQ_REMOVE(&sc->tx_q, data, rum_tx_data, next); in rum_reset_tx_list()
842 STAILQ_INSERT_TAIL(&sc->tx_free, data, next); in rum_reset_tx_list()
843 sc->tx_nfree++; in rum_reset_tx_list()
855 sc->tx_nfree = 0; in rum_unsetup_tx_list()
856 STAILQ_INIT(&sc->tx_q); in rum_unsetup_tx_list()
857 STAILQ_INIT(&sc->tx_free); in rum_unsetup_tx_list()
861 data = &sc->tx_data[i]; in rum_unsetup_tx_list()
863 if (data->m != NULL) { in rum_unsetup_tx_list()
864 m_freem(data->m); in rum_unsetup_tx_list()
865 data->m = NULL; in rum_unsetup_tx_list()
867 if (data->ni != NULL) { in rum_unsetup_tx_list()
868 ieee80211_free_node(data->ni); in rum_unsetup_tx_list()
869 data->ni = NULL; in rum_unsetup_tx_list()
877 struct ieee80211com *ic = vap->iv_ic; in rum_beacon_miss()
878 struct rum_softc *sc = ic->ic_softc; in rum_beacon_miss()
883 if (sc->sc_sleeping && sc->sc_sleep_end < ticks) { in rum_beacon_miss()
887 sc->sc_sleeping = 0; in rum_beacon_miss()
890 sleep = sc->sc_sleeping; in rum_beacon_miss()
894 rvp->bmiss(vap); in rum_beacon_miss()
906 struct ieee80211vap *vap = ni->ni_vap; in rum_sta_recv_mgmt()
907 struct rum_softc *sc = vap->iv_ic->ic_softc; in rum_sta_recv_mgmt()
910 if (vap->iv_state == IEEE80211_S_SLEEP && in rum_sta_recv_mgmt()
914 !!(sc->last_rx_flags & RT2573_RX_MYBSS), in rum_sta_recv_mgmt()
915 sc->last_rx_flags); in rum_sta_recv_mgmt()
917 if ((sc->last_rx_flags & (RT2573_RX_MYBSS | RT2573_RX_BC)) == in rum_sta_recv_mgmt()
922 * SLEEP -> RUN state transition. in rum_sta_recv_mgmt()
929 rvp->recv_mgmt(ni, m, subtype, rxs, rssi, nf); in rum_sta_recv_mgmt()
940 sleep ? "sleep" : "awake", sc->sc_sleep_time); in rum_set_power_state()
945 device_printf(sc->sc_dev, in rum_set_power_state()
951 sc->sc_sleeping = !!sleep; in rum_set_power_state()
952 sc->sc_sleep_end = sleep ? ticks + sc->sc_sleep_time : 0; in rum_set_power_state()
961 struct ieee80211com *ic = vap->iv_ic; in rum_newstate()
962 struct rum_softc *sc = ic->ic_softc; in rum_newstate()
969 ostate = vap->iv_state; in rum_newstate()
970 DPRINTF("%s -> %s\n", in rum_newstate()
976 usb_callout_stop(&rvp->ratectl_ch); in rum_newstate()
978 if (ostate == IEEE80211_S_SLEEP && vap->iv_opmode == IEEE80211_M_STA) { in rum_newstate()
1000 ni = ieee80211_ref_node(vap->iv_bss); in rum_newstate()
1002 if (vap->iv_opmode != IEEE80211_M_MONITOR) { in rum_newstate()
1003 if (ic->ic_bsschan == IEEE80211_CHAN_ANYC || in rum_newstate()
1004 ni->ni_chan == IEEE80211_CHAN_ANYC) { in rum_newstate()
1013 IEEE80211_ADDR_COPY(sc->sc_bssid, ni->ni_bssid); in rum_newstate()
1014 rum_set_bssid(sc, sc->sc_bssid); in rum_newstate()
1017 if (vap->iv_opmode == IEEE80211_M_HOSTAP || in rum_newstate()
1018 vap->iv_opmode == IEEE80211_M_IBSS) { in rum_newstate()
1023 if (vap->iv_opmode != IEEE80211_M_MONITOR && in rum_newstate()
1024 vap->iv_opmode != IEEE80211_M_AHDEMO) { in rum_newstate()
1030 /* enable automatic rate adaptation */ in rum_newstate()
1031 tp = &vap->iv_txparms[ieee80211_chan2mode(ic->ic_curchan)]; in rum_newstate()
1032 if (tp->ucastrate == IEEE80211_FIXED_RATE_NONE) in rum_newstate()
1039 if (vap->iv_opmode != IEEE80211_M_STA) in rum_newstate()
1056 device_printf(sc->sc_dev, in rum_newstate()
1066 return (ret == 0 ? rvp->newstate(vap, nstate, arg) : ret); in rum_newstate()
1094 data = STAILQ_FIRST(&sc->tx_q); in rum_bulk_write_callback()
1096 STAILQ_REMOVE_HEAD(&sc->tx_q, next); in rum_bulk_write_callback()
1097 m = data->m; in rum_bulk_write_callback()
1099 if (m->m_pkthdr.len > (int)(MCLBYTES + RT2573_TX_DESC_SIZE)) { in rum_bulk_write_callback()
1101 m->m_pkthdr.len); in rum_bulk_write_callback()
1102 m->m_pkthdr.len = (MCLBYTES + RT2573_TX_DESC_SIZE); in rum_bulk_write_callback()
1105 usbd_copy_in(pc, 0, &data->desc, RT2573_TX_DESC_SIZE); in rum_bulk_write_callback()
1107 m->m_pkthdr.len); in rum_bulk_write_callback()
1109 vap = data->ni->ni_vap; in rum_bulk_write_callback()
1111 struct rum_tx_radiotap_header *tap = &sc->sc_txtap; in rum_bulk_write_callback()
1113 tap->wt_flags = 0; in rum_bulk_write_callback()
1114 tap->wt_rate = data->rate; in rum_bulk_write_callback()
1115 tap->wt_antenna = sc->tx_ant; in rum_bulk_write_callback()
1120 /* align end on a 4-bytes boundary */ in rum_bulk_write_callback()
1121 len = (RT2573_TX_DESC_SIZE + m->m_pkthdr.len + 3) & ~3; in rum_bulk_write_callback()
1126 m->m_pkthdr.len, len); in rum_bulk_write_callback()
1140 counter_u64_add(sc->sc_ic.ic_oerrors, 1); in rum_bulk_write_callback()
1149 device_printf(sc->sc_dev, "device timeout\n"); in rum_bulk_write_callback()
1167 struct ieee80211com *ic = &sc->sc_ic; in rum_bulk_read_callback()
1185 device_get_nameunit(sc->sc_dev), len); in rum_bulk_read_callback()
1186 counter_u64_add(ic->ic_ierrors, 1); in rum_bulk_read_callback()
1190 len -= RT2573_RX_DESC_SIZE; in rum_bulk_read_callback()
1192 usbd_copy_out(pc, 0, &sc->sc_rx_desc, RT2573_RX_DESC_SIZE); in rum_bulk_read_callback()
1194 rssi = rum_get_rssi(sc, sc->sc_rx_desc.rssi); in rum_bulk_read_callback()
1195 flags = le32toh(sc->sc_rx_desc.flags); in rum_bulk_read_callback()
1196 sc->last_rx_flags = flags; in rum_bulk_read_callback()
1199 "bytes\n", device_get_nameunit(sc->sc_dev), in rum_bulk_read_callback()
1201 counter_u64_add(ic->ic_ierrors, 1); in rum_bulk_read_callback()
1207 device_get_nameunit(sc->sc_dev), len); in rum_bulk_read_callback()
1208 counter_u64_add(ic->ic_ierrors, 1); in rum_bulk_read_callback()
1218 counter_u64_add(ic->ic_ierrors, 1); in rum_bulk_read_callback()
1233 counter_u64_add(ic->ic_ierrors, 1); in rum_bulk_read_callback()
1240 counter_u64_add(ic->ic_ierrors, 1); in rum_bulk_read_callback()
1248 if ((wh->i_fc[1] & IEEE80211_FC1_PROTECTED) && in rum_bulk_read_callback()
1251 wh->i_fc[1] &= ~IEEE80211_FC1_PROTECTED; in rum_bulk_read_callback()
1252 m->m_flags |= M_WEP; in rum_bulk_read_callback()
1256 m->m_pkthdr.len = m->m_len = len; in rum_bulk_read_callback()
1259 struct rum_rx_radiotap_header *tap = &sc->sc_rxtap; in rum_bulk_read_callback()
1261 tap->wr_flags = 0; in rum_bulk_read_callback()
1262 tap->wr_rate = ieee80211_plcp2rate(sc->sc_rx_desc.rate, in rum_bulk_read_callback()
1265 rum_get_tsf(sc, &tap->wr_tsf); in rum_bulk_read_callback()
1266 tap->wr_antsignal = RT2573_NOISE_FLOOR + rssi; in rum_bulk_read_callback()
1267 tap->wr_antnoise = RT2573_NOISE_FLOOR; in rum_bulk_read_callback()
1268 tap->wr_antenna = sc->rx_ant; in rum_bulk_read_callback()
1283 if (m->m_len >= sizeof(struct ieee80211_frame_min)) in rum_bulk_read_callback()
1311 rum_plcp_signal(int rate) in rum_plcp_signal() argument
1313 switch (rate) { in rum_plcp_signal()
1314 /* OFDM rates (cf IEEE Std 802.11a-1999, pp. 14 Table 80) */ in rum_plcp_signal()
1324 /* CCK rates (NB: not IEEE std, device-specific) */ in rum_plcp_signal()
1330 return 0xff; /* XXX unsupported/unknown rate */ in rum_plcp_signal()
1347 device_printf(sc->sc_dev, "unknown cipher %d\n", cipher); in rum_crypto_mode()
1355 int hdrlen, int len, int rate) in rum_setup_tx_desc() argument
1357 struct ieee80211com *ic = &sc->sc_ic; in rum_setup_tx_desc()
1358 struct wmeParams *wmep = &sc->wme_params[qid]; in rum_setup_tx_desc()
1365 if (k != NULL && !(k->wk_flags & IEEE80211_KEY_SWCRYPT)) { in rum_setup_tx_desc()
1366 const struct ieee80211_cipher *cip = k->wk_cipher; in rum_setup_tx_desc()
1368 len += cip->ic_header + cip->ic_trailer + cip->ic_miclen; in rum_setup_tx_desc()
1370 desc->eiv = 0; /* for WEP */ in rum_setup_tx_desc()
1371 cip->ic_setiv(k, (uint8_t *)&desc->iv); in rum_setup_tx_desc()
1375 desc->plcp_signal = rum_plcp_signal(rate); in rum_setup_tx_desc()
1376 desc->plcp_service = 4; in rum_setup_tx_desc()
1379 if (ieee80211_rate2phytype(ic->ic_rt, rate) == IEEE80211_T_OFDM) { in rum_setup_tx_desc()
1383 desc->plcp_length_hi = plcp_length >> 6; in rum_setup_tx_desc()
1384 desc->plcp_length_lo = plcp_length & 0x3f; in rum_setup_tx_desc()
1386 if (rate == 0) in rum_setup_tx_desc()
1387 rate = 2; /* avoid division by zero */ in rum_setup_tx_desc()
1388 plcp_length = howmany(16 * len, rate); in rum_setup_tx_desc()
1389 if (rate == 22) { in rum_setup_tx_desc()
1392 desc->plcp_service |= RT2573_PLCP_LENGEXT; in rum_setup_tx_desc()
1394 desc->plcp_length_hi = plcp_length >> 8; in rum_setup_tx_desc()
1395 desc->plcp_length_lo = plcp_length & 0xff; in rum_setup_tx_desc()
1397 if (rate != 2 && (ic->ic_flags & IEEE80211_F_SHPREAMBLE)) in rum_setup_tx_desc()
1398 desc->plcp_signal |= 0x08; in rum_setup_tx_desc()
1401 desc->flags = htole32(flags); in rum_setup_tx_desc()
1402 desc->hdrlen = hdrlen; in rum_setup_tx_desc()
1403 desc->xflags = xflags; in rum_setup_tx_desc()
1405 desc->wme = htole16(RT2573_QID(qid) | in rum_setup_tx_desc()
1406 RT2573_AIFSN(wmep->wmep_aifsn) | in rum_setup_tx_desc()
1407 RT2573_LOGCWMIN(wmep->wmep_logcwmin) | in rum_setup_tx_desc()
1408 RT2573_LOGCWMAX(wmep->wmep_logcwmax)); in rum_setup_tx_desc()
1413 const struct mbuf *m, struct ieee80211_node *ni, int prot, int rate) in rum_sendprot() argument
1415 struct ieee80211com *ic = ni->ni_ic; in rum_sendprot()
1422 mprot = ieee80211_alloc_prot(ni, m, rate, prot); in rum_sendprot()
1424 if_inc_counter(ni->ni_vap->iv_ifp, IFCOUNTER_OERRORS, 1); in rum_sendprot()
1425 device_printf(sc->sc_dev, in rum_sendprot()
1430 protrate = ieee80211_ctl_rate(ic->ic_rt, rate); in rum_sendprot()
1435 data = STAILQ_FIRST(&sc->tx_free); in rum_sendprot()
1436 STAILQ_REMOVE_HEAD(&sc->tx_free, next); in rum_sendprot()
1437 sc->tx_nfree--; in rum_sendprot()
1439 data->m = mprot; in rum_sendprot()
1440 data->ni = ieee80211_ref_node(ni); in rum_sendprot()
1441 data->rate = protrate; in rum_sendprot()
1442 rum_setup_tx_desc(sc, &data->desc, NULL, flags, 0, 0, 0, in rum_sendprot()
1443 mprot->m_pkthdr.len, protrate); in rum_sendprot()
1445 STAILQ_INSERT_TAIL(&sc->tx_q, data, next); in rum_sendprot()
1446 usbd_transfer_start(sc->sc_xfer[RUM_BULK_WR]); in rum_sendprot()
1455 struct ieee80211vap *vap = ni->ni_vap; in rum_tx_crypto_flags()
1460 if (!(k->wk_flags & IEEE80211_KEY_SWCRYPT)) { in rum_tx_crypto_flags()
1461 cipher = k->wk_cipher->ic_cipher; in rum_tx_crypto_flags()
1462 pos = k->wk_keyix; in rum_tx_crypto_flags()
1463 mode = rum_crypto_mode(sc, cipher, k->wk_keylen); in rum_tx_crypto_flags()
1487 const struct ieee80211_txparam *tp = ni->ni_txparms; in rum_tx_mgt()
1488 struct ieee80211com *ic = &sc->sc_ic; in rum_tx_mgt()
1499 data = STAILQ_FIRST(&sc->tx_free); in rum_tx_mgt()
1500 STAILQ_REMOVE_HEAD(&sc->tx_free, next); in rum_tx_mgt()
1501 sc->tx_nfree--; in rum_tx_mgt()
1504 type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK; in rum_tx_mgt()
1508 if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) { in rum_tx_mgt()
1513 if ((k->wk_flags & IEEE80211_KEY_SWCRYPT) && in rum_tx_mgt()
1514 !k->wk_cipher->ic_encap(k, m0)) in rum_tx_mgt()
1520 if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) { in rum_tx_mgt()
1523 dur = ieee80211_ack_duration(ic->ic_rt, tp->mgmtrate, in rum_tx_mgt()
1524 ic->ic_flags & IEEE80211_F_SHPREAMBLE); in rum_tx_mgt()
1525 USETW(wh->i_dur, dur); in rum_tx_mgt()
1538 data->m = m0; in rum_tx_mgt()
1539 data->ni = ni; in rum_tx_mgt()
1540 data->rate = tp->mgmtrate; in rum_tx_mgt()
1542 rum_setup_tx_desc(sc, &data->desc, k, flags, xflags, ac, hdrlen, in rum_tx_mgt()
1543 m0->m_pkthdr.len, tp->mgmtrate); in rum_tx_mgt()
1545 DPRINTFN(10, "sending mgt frame len=%d rate=%d\n", in rum_tx_mgt()
1546 m0->m_pkthdr.len + (int)RT2573_TX_DESC_SIZE, tp->mgmtrate); in rum_tx_mgt()
1548 STAILQ_INSERT_TAIL(&sc->tx_q, data, next); in rum_tx_mgt()
1549 usbd_transfer_start(sc->sc_xfer[RUM_BULK_WR]); in rum_tx_mgt()
1558 struct ieee80211com *ic = ni->ni_ic; in rum_tx_raw()
1563 int rate, error; in rum_tx_raw() local
1568 type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK; in rum_tx_raw()
1570 ac = params->ibp_pri & 3; in rum_tx_raw()
1572 rate = params->ibp_rate0; in rum_tx_raw()
1573 if (!ieee80211_isratevalid(ic->ic_rt, rate)) in rum_tx_raw()
1577 if ((params->ibp_flags & IEEE80211_BPF_NOACK) == 0) in rum_tx_raw()
1579 if (params->ibp_flags & (IEEE80211_BPF_RTS|IEEE80211_BPF_CTS)) { in rum_tx_raw()
1581 params->ibp_flags & IEEE80211_BPF_RTS ? in rum_tx_raw()
1583 rate); in rum_tx_raw()
1584 if (error || sc->tx_nfree == 0) in rum_tx_raw()
1593 data = STAILQ_FIRST(&sc->tx_free); in rum_tx_raw()
1594 STAILQ_REMOVE_HEAD(&sc->tx_free, next); in rum_tx_raw()
1595 sc->tx_nfree--; in rum_tx_raw()
1597 data->m = m0; in rum_tx_raw()
1598 data->ni = ni; in rum_tx_raw()
1599 data->rate = rate; in rum_tx_raw()
1602 rum_setup_tx_desc(sc, &data->desc, NULL, flags, xflags, ac, 0, in rum_tx_raw()
1603 m0->m_pkthdr.len, rate); in rum_tx_raw()
1605 DPRINTFN(10, "sending raw frame len=%u rate=%u\n", in rum_tx_raw()
1606 m0->m_pkthdr.len, rate); in rum_tx_raw()
1608 STAILQ_INSERT_TAIL(&sc->tx_q, data, next); in rum_tx_raw()
1609 usbd_transfer_start(sc->sc_xfer[RUM_BULK_WR]); in rum_tx_raw()
1617 struct ieee80211vap *vap = ni->ni_vap; in rum_tx_data()
1618 struct ieee80211com *ic = &sc->sc_ic; in rum_tx_data()
1621 const struct ieee80211_txparam *tp = ni->ni_txparms; in rum_tx_data()
1626 int error, hdrlen, rate; in rum_tx_data() local
1631 type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK; in rum_tx_data()
1635 qos = ((const struct ieee80211_qosframe *)wh)->i_qos[0]; in rum_tx_data()
1640 if (m0->m_flags & M_EAPOL) in rum_tx_data()
1641 rate = tp->mgmtrate; in rum_tx_data()
1642 else if (IEEE80211_IS_MULTICAST(wh->i_addr1)) in rum_tx_data()
1643 rate = tp->mcastrate; in rum_tx_data()
1644 else if (tp->ucastrate != IEEE80211_FIXED_RATE_NONE) in rum_tx_data()
1645 rate = tp->ucastrate; in rum_tx_data()
1648 rate = ieee80211_node_get_txrate_dot11rate(ni); in rum_tx_data()
1651 if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) { in rum_tx_data()
1657 if ((k->wk_flags & IEEE80211_KEY_SWCRYPT) && in rum_tx_data()
1658 !k->wk_cipher->ic_encap(k, m0)) { in rum_tx_data()
1670 if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) { in rum_tx_data()
1672 if (m0->m_pkthdr.len + IEEE80211_CRC_LEN > vap->iv_rtsthreshold) in rum_tx_data()
1674 else if ((ic->ic_flags & IEEE80211_F_USEPROT) && in rum_tx_data()
1675 ieee80211_rate2phytype(ic->ic_rt, rate) == IEEE80211_T_OFDM) in rum_tx_data()
1676 prot = ic->ic_protmode; in rum_tx_data()
1678 error = rum_sendprot(sc, m0, ni, prot, rate); in rum_tx_data()
1679 if (error || sc->tx_nfree == 0) { in rum_tx_data()
1690 data = STAILQ_FIRST(&sc->tx_free); in rum_tx_data()
1691 STAILQ_REMOVE_HEAD(&sc->tx_free, next); in rum_tx_data()
1692 sc->tx_nfree--; in rum_tx_data()
1694 data->m = m0; in rum_tx_data()
1695 data->ni = ni; in rum_tx_data()
1696 data->rate = rate; in rum_tx_data()
1698 if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) { in rum_tx_data()
1704 dur = ieee80211_ack_duration(ic->ic_rt, rate, in rum_tx_data()
1705 ic->ic_flags & IEEE80211_F_SHPREAMBLE); in rum_tx_data()
1706 USETW(wh->i_dur, dur); in rum_tx_data()
1709 rum_setup_tx_desc(sc, &data->desc, k, flags, xflags, ac, hdrlen, in rum_tx_data()
1710 m0->m_pkthdr.len, rate); in rum_tx_data()
1712 DPRINTFN(10, "sending frame len=%d rate=%d\n", in rum_tx_data()
1713 m0->m_pkthdr.len + (int)RT2573_TX_DESC_SIZE, rate); in rum_tx_data()
1715 STAILQ_INSERT_TAIL(&sc->tx_q, data, next); in rum_tx_data()
1716 usbd_transfer_start(sc->sc_xfer[RUM_BULK_WR]); in rum_tx_data()
1724 struct rum_softc *sc = ic->ic_softc; in rum_transmit()
1728 if (!sc->sc_running) { in rum_transmit()
1732 error = mbufq_enqueue(&sc->sc_snd, m); in rum_transmit()
1751 if (!sc->sc_running) in rum_start()
1754 while (sc->tx_nfree >= RUM_TX_MINFREE && in rum_start()
1755 (m = mbufq_dequeue(&sc->sc_snd)) != NULL) { in rum_start()
1756 ni = (struct ieee80211_node *) m->m_pkthdr.rcvif; in rum_start()
1758 if_inc_counter(ni->ni_vap->iv_ifp, in rum_start()
1769 struct rum_softc *sc = ic->ic_softc; in rum_parent()
1770 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); in rum_parent()
1773 if (sc->sc_detached) { in rum_parent()
1779 if (ic->ic_nrunning > 0) { in rum_parent()
1802 device_printf(sc->sc_dev, "could not read EEPROM: %s\n", in rum_eeprom_read()
1831 device_printf(sc->sc_dev, in rum_read_multi()
1859 USETW(req.wLength, MIN(len - offset, 64)); in rum_write_multi()
1863 device_printf(sc->sc_dev, in rum_write_multi()
1899 if (rum_pause(sc, hz / 100)) in rum_bbp_busy()
1916 device_printf(sc->sc_dev, "could not write to BBP\n"); in rum_bbp_write()
1933 device_printf(sc->sc_dev, "could not read BBP\n"); in rum_bbp_read()
1944 if (rum_pause(sc, hz / 100)) in rum_bbp_read()
1948 device_printf(sc->sc_dev, "could not read BBP\n"); in rum_bbp_read()
1961 if (rum_pause(sc, hz / 100)) in rum_rf_write()
1965 device_printf(sc->sc_dev, "could not write to RF\n"); in rum_rf_write()
1974 sc->rf_regs[reg] = val; in rum_rf_write()
1976 DPRINTFN(15, "RF R[%u] <- 0x%05x\n", reg & 3, val & 0xfffff); in rum_rf_write()
2001 * Enable multi-rate retries for frames sent at OFDM rates.
2007 struct ieee80211com *ic = &sc->sc_ic; in rum_enable_mrr()
2009 if (!IEEE80211_IS_CHAN_5GHZ(ic->ic_bsschan)) { in rum_enable_mrr()
2021 struct ieee80211com *ic = &sc->sc_ic; in rum_set_txpreamble()
2023 if (ic->ic_flags & IEEE80211_F_SHPREAMBLE) in rum_set_txpreamble()
2032 struct ieee80211com *ic = &sc->sc_ic; in rum_set_basicrates()
2034 /* update basic rate set */ in rum_set_basicrates()
2035 if (ic->ic_curmode == IEEE80211_MODE_11B) { in rum_set_basicrates()
2038 } else if (IEEE80211_IS_CHAN_5GHZ(ic->ic_bsschan)) { in rum_set_basicrates()
2063 if ((IEEE80211_IS_CHAN_2GHZ(c) && sc->ext_2ghz_lna) || in rum_select_band()
2064 (IEEE80211_IS_CHAN_5GHZ(c) && sc->ext_5ghz_lna)) { in rum_select_band()
2068 sc->bbp17 = bbp17; in rum_select_band()
2073 if ((IEEE80211_IS_CHAN_2GHZ(c) && sc->ext_2ghz_lna) || in rum_select_band()
2074 (IEEE80211_IS_CHAN_5GHZ(c) && sc->ext_5ghz_lna)) { in rum_select_band()
2096 struct ieee80211com *ic = &sc->sc_ic; in rum_set_chan()
2107 rfprog = (sc->rf_rev == RT2573_RF_5225 || in rum_set_chan()
2108 sc->rf_rev == RT2573_RF_2527) ? rum_rf5225 : rum_rf5226; in rum_set_chan()
2113 power = sc->txpow[i]; in rum_set_chan()
2118 bbp94 += power - 31; in rum_set_chan()
2124 * vice-versa, BBP registers need to be reprogrammed. in rum_set_chan()
2126 if (c->ic_flags != ic->ic_curchan->ic_flags) { in rum_set_chan()
2130 ic->ic_curchan = c; in rum_set_chan()
2135 rum_rf_write(sc, RT2573_RF4, rfprog[i].r4 | sc->rffreq << 10); in rum_set_chan()
2140 rum_rf_write(sc, RT2573_RF4, rfprog[i].r4 | sc->rffreq << 10); in rum_set_chan()
2145 rum_rf_write(sc, RT2573_RF4, rfprog[i].r4 | sc->rffreq << 10); in rum_set_chan()
2147 rum_pause(sc, hz / 100); in rum_set_chan()
2149 /* enable smart mode for MIMO-capable RFs */ in rum_set_chan()
2153 if (sc->rf_rev == RT2573_RF_5225 || sc->rf_rev == RT2573_RF_2527) in rum_set_chan()
2162 rum_pause(sc, hz / 100); in rum_set_chan()
2168 struct ieee80211_node *ni = vap->iv_bss; in rum_set_maxretry()
2169 const struct ieee80211_txparam *tp = ni->ni_txparms; in rum_set_maxretry()
2172 rvp->maxretry = MIN(tp->maxretry, 0xf); in rum_set_maxretry()
2174 rum_modbits(sc, RT2573_TXRX_CSR4, RT2573_SHORT_RETRY(rvp->maxretry) | in rum_set_maxretry()
2175 RT2573_LONG_RETRY(rvp->maxretry), in rum_set_maxretry()
2186 struct ieee80211com *ic = &sc->sc_ic; in rum_enable_tsf_sync()
2187 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); in rum_enable_tsf_sync()
2191 if (vap->iv_opmode != IEEE80211_M_STA) { in rum_enable_tsf_sync()
2203 bintval = vap->iv_bss->ni_intval; in rum_enable_tsf_sync()
2207 switch (vap->iv_opmode) { in rum_enable_tsf_sync()
2229 device_printf(sc->sc_dev, in rum_enable_tsf_sync()
2231 vap->iv_opmode); in rum_enable_tsf_sync()
2238 /* refresh current sleep time */ in rum_enable_tsf_sync()
2264 struct ieee80211com *ic = &sc->sc_ic; in rum_update_slot_cb()
2277 rum_cmd_sleepable(ic->ic_softc, NULL, 0, 0, rum_update_slot_cb); in rum_update_slot()
2285 struct rum_softc *sc = ic->ic_softc; in rum_wme_update()
2324 memcpy(sc->wme_params, chanp, sizeof(*chanp) * WME_NUM_AC); in rum_wme_update()
2329 device_printf(sc->sc_dev, "%s: WME update failed, error %d\n", in rum_wme_update()
2359 struct ieee80211com *ic = &sc->sc_ic; in rum_setpromisc()
2361 if (ic->ic_promisc == 0) in rum_setpromisc()
2366 DPRINTF("%s promiscuous mode\n", ic->ic_promisc > 0 ? in rum_setpromisc()
2373 struct rum_softc *sc = ic->ic_softc; in rum_update_promisc()
2376 if (sc->sc_running) in rum_update_promisc()
2408 rum_eeprom_read(sc, RT2573_EEPROM_ADDRESS, sc->sc_ic.ic_macaddr, 6); in rum_read_eeprom()
2412 sc->rf_rev = (val >> 11) & 0x1f; in rum_read_eeprom()
2413 sc->hw_radio = (val >> 10) & 0x1; in rum_read_eeprom()
2414 sc->rx_ant = (val >> 4) & 0x3; in rum_read_eeprom()
2415 sc->tx_ant = (val >> 2) & 0x3; in rum_read_eeprom()
2416 sc->nb_ant = val & 0x3; in rum_read_eeprom()
2418 DPRINTF("RF revision=%d\n", sc->rf_rev); in rum_read_eeprom()
2422 sc->ext_5ghz_lna = (val >> 6) & 0x1; in rum_read_eeprom()
2423 sc->ext_2ghz_lna = (val >> 4) & 0x1; in rum_read_eeprom()
2426 sc->ext_2ghz_lna, sc->ext_5ghz_lna); in rum_read_eeprom()
2431 sc->rssi_2ghz_corr = (int8_t)(val & 0xff); /* signed */ in rum_read_eeprom()
2433 /* Only [-10, 10] is valid */ in rum_read_eeprom()
2434 if (sc->rssi_2ghz_corr < -10 || sc->rssi_2ghz_corr > 10) in rum_read_eeprom()
2435 sc->rssi_2ghz_corr = 0; in rum_read_eeprom()
2440 sc->rssi_5ghz_corr = (int8_t)(val & 0xff); /* signed */ in rum_read_eeprom()
2442 /* Only [-10, 10] is valid */ in rum_read_eeprom()
2443 if (sc->rssi_5ghz_corr < -10 || sc->rssi_5ghz_corr > 10) in rum_read_eeprom()
2444 sc->rssi_5ghz_corr = 0; in rum_read_eeprom()
2446 if (sc->ext_2ghz_lna) in rum_read_eeprom()
2447 sc->rssi_2ghz_corr -= 14; in rum_read_eeprom()
2448 if (sc->ext_5ghz_lna) in rum_read_eeprom()
2449 sc->rssi_5ghz_corr -= 14; in rum_read_eeprom()
2452 sc->rssi_2ghz_corr, sc->rssi_5ghz_corr); in rum_read_eeprom()
2457 sc->rffreq = val & 0xff; in rum_read_eeprom()
2459 DPRINTF("RF freq=%d\n", sc->rffreq); in rum_read_eeprom()
2462 rum_eeprom_read(sc, RT2573_EEPROM_TXPOWER, sc->txpow, 14); in rum_read_eeprom()
2464 memset(sc->txpow + 14, 24, sizeof (sc->txpow) - 14); in rum_read_eeprom()
2467 DPRINTF("Channel=%d Tx power=%d\n", i + 1, sc->txpow[i]); in rum_read_eeprom()
2471 rum_eeprom_read(sc, RT2573_EEPROM_BBP_BASE, sc->bbp_prom, 2 * 16); in rum_read_eeprom()
2474 if (sc->bbp_prom[i].reg == 0 || sc->bbp_prom[i].reg == 0xff) in rum_read_eeprom()
2476 DPRINTF("BBP R%d=%02x\n", sc->bbp_prom[i].reg, in rum_read_eeprom()
2477 sc->bbp_prom[i].val); in rum_read_eeprom()
2491 if (rum_pause(sc, hz / 100)) in rum_bbp_wakeup()
2495 device_printf(sc->sc_dev, in rum_bbp_wakeup()
2513 if (rum_pause(sc, hz / 100)) in rum_bbp_init()
2517 device_printf(sc->sc_dev, "timeout waiting for BBP\n"); in rum_bbp_init()
2525 /* write vendor-specific BBP values (from EEPROM) */ in rum_bbp_init()
2527 if (sc->bbp_prom[i].reg == 0 || sc->bbp_prom[i].reg == 0xff) in rum_bbp_init()
2529 rum_bbp_write(sc, sc->bbp_prom[i].reg, sc->bbp_prom[i].val); in rum_bbp_init()
2546 struct ieee80211com *ic = &sc->sc_ic; in rum_init()
2547 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); in rum_init()
2552 if (sc->sc_running) { in rum_init()
2562 sc->wme_params[0].wmep_aifsn = 2; in rum_init()
2563 sc->wme_params[0].wmep_logcwmin = 4; in rum_init()
2564 sc->wme_params[0].wmep_logcwmax = 10; in rum_init()
2578 rum_select_band(sc, ic->ic_curchan); in rum_init()
2580 rum_set_chan(sc, ic->ic_curchan); in rum_init()
2583 rum_read_multi(sc, RT2573_STA_CSR0, sc->sta, sizeof sc->sta); in rum_init()
2586 if (sc->sc_clr_shkeys == 0) { in rum_init()
2588 sc->sc_clr_shkeys = 1; in rum_init()
2591 rum_set_macaddr(sc, vap ? vap->iv_myaddr : ic->ic_macaddr); in rum_init()
2605 if (ic->ic_opmode != IEEE80211_M_MONITOR) { in rum_init()
2608 if (ic->ic_opmode != IEEE80211_M_HOSTAP) in rum_init()
2610 if (ic->ic_promisc == 0) in rum_init()
2615 sc->sc_running = 1; in rum_init()
2616 usbd_xfer_set_stall(sc->sc_xfer[RUM_BULK_WR]); in rum_init()
2617 usbd_transfer_start(sc->sc_xfer[RUM_BULK_RD]); in rum_init()
2632 if (!sc->sc_running) { in rum_stop()
2636 sc->sc_running = 0; in rum_stop()
2642 usbd_transfer_drain(sc->sc_xfer[RUM_BULK_WR]); in rum_stop()
2643 usbd_transfer_drain(sc->sc_xfer[RUM_BULK_RD]); in rum_stop()
2664 for (; size >= 4; reg += 4, ucode += 4, size -= 4) { in rum_load_microcode()
2668 device_printf(sc->sc_dev, "Firmware load " in rum_load_microcode()
2676 device_printf(sc->sc_dev, "could not run firmware: %s\n", in rum_load_microcode()
2681 rum_pause(sc, hz / 8); in rum_load_microcode()
2687 struct ieee80211com *ic = &sc->sc_ic; in rum_set_sleep_time()
2693 exp = ic->ic_lintval / bintval; in rum_set_sleep_time()
2694 delay = ic->ic_lintval % bintval; in rum_set_sleep_time()
2710 sc->sc_sleep_time = IEEE80211_TU_TO_TICKS(exp * bintval + delay); in rum_set_sleep_time()
2718 struct ieee80211com *ic = vap->iv_ic; in rum_reset()
2720 struct rum_softc *sc = ic->ic_softc; in rum_reset()
2730 ni = ieee80211_ref_node(vap->iv_bss); in rum_reset()
2733 error = rum_set_sleep_time(sc, ni->ni_intval); in rum_reset()
2734 if (vap->iv_state == IEEE80211_S_SLEEP) { in rum_reset()
2755 struct ieee80211com *ic = vap->iv_ic; in rum_set_beacon()
2757 struct mbuf *m = rvp->bcn_mbuf; in rum_set_beacon()
2765 if (ic->ic_bsschan == IEEE80211_CHAN_ANYC) in rum_set_beacon()
2768 tp = &vap->iv_txparms[ieee80211_chan2mode(ic->ic_bsschan)]; in rum_set_beacon()
2770 RT2573_TX_HWSEQ, 0, 0, m->m_pkthdr.len, tp->mgmtrate); in rum_set_beacon()
2779 mtod(m, uint8_t *), m->m_pkthdr.len) != 0) in rum_set_beacon()
2789 struct ieee80211_node *ni = vap->iv_bss; in rum_alloc_beacon()
2792 if (ni->ni_chan == IEEE80211_CHAN_ANYC) in rum_alloc_beacon()
2799 if (rvp->bcn_mbuf != NULL) in rum_alloc_beacon()
2800 m_freem(rvp->bcn_mbuf); in rum_alloc_beacon()
2802 rvp->bcn_mbuf = m; in rum_alloc_beacon()
2811 struct ieee80211vap *vap = data->vap; in rum_update_beacon_cb()
2819 struct ieee80211com *ic = vap->iv_ic; in rum_update_beacon()
2820 struct rum_softc *sc = ic->ic_softc; in rum_update_beacon()
2822 struct ieee80211_beacon_offsets *bo = &vap->iv_bcn_off; in rum_update_beacon()
2823 struct ieee80211_node *ni = vap->iv_bss; in rum_update_beacon()
2824 struct mbuf *m = rvp->bcn_mbuf; in rum_update_beacon()
2831 device_printf(sc->sc_dev, in rum_update_beacon()
2836 rvp->bcn_mbuf = m; in rum_update_beacon()
2851 setbit(bo->bo_flags, item); in rum_update_beacon()
2862 if (rum_write_multi(sc, base, k->wk_key, k->wk_keylen)) in rum_common_key_set()
2865 if (k->wk_cipher->ic_cipher == IEEE80211_CIPHER_TKIP) { in rum_common_key_set()
2867 k->wk_txmic, 8)) in rum_common_key_set()
2870 k->wk_rxmic, 8)) in rum_common_key_set()
2881 struct ieee80211_key *k = &data->key; in rum_group_key_set_cb()
2884 if (sc->sc_clr_shkeys == 0) { in rum_group_key_set_cb()
2886 sc->sc_clr_shkeys = 1; in rum_group_key_set_cb()
2889 mode = rum_crypto_mode(sc, k->wk_cipher->ic_cipher, k->wk_keylen); in rum_group_key_set_cb()
2894 "(tx %s, rx %s)\n", k->wk_keyix, rvp_id, mode, in rum_group_key_set_cb()
2895 (k->wk_flags & IEEE80211_KEY_XMIT) ? "on" : "off", in rum_group_key_set_cb()
2896 (k->wk_flags & IEEE80211_KEY_RECV) ? "on" : "off"); in rum_group_key_set_cb()
2899 if (rum_common_key_set(sc, k, RT2573_SKEY(rvp_id, k->wk_keyix)) != 0) in rum_group_key_set_cb()
2904 mode << (rvp_id % 2 + k->wk_keyix) * RT2573_SKEY_MAX, in rum_group_key_set_cb()
2905 RT2573_MODE_MASK << (rvp_id % 2 + k->wk_keyix) * RT2573_SKEY_MAX) in rum_group_key_set_cb()
2911 1 << (rvp_id * RT2573_SKEY_MAX + k->wk_keyix)) != 0) in rum_group_key_set_cb()
2917 device_printf(sc->sc_dev, "%s: cannot set group key %d for vap %d\n", in rum_group_key_set_cb()
2918 __func__, k->wk_keyix, rvp_id); in rum_group_key_set_cb()
2925 struct ieee80211_key *k = &data->key; in rum_group_key_del_cb()
2928 k->wk_keyix, rvp_id); in rum_group_key_del_cb()
2931 RT2573_MODE_MASK << (rvp_id % 2 + k->wk_keyix) * RT2573_SKEY_MAX); in rum_group_key_del_cb()
2933 rvp_id * RT2573_SKEY_MAX + k->wk_keyix); in rum_group_key_del_cb()
2940 struct ieee80211_key *k = &data->key; in rum_pair_key_set_cb()
2944 mode = rum_crypto_mode(sc, k->wk_cipher->ic_cipher, k->wk_keylen); in rum_pair_key_set_cb()
2949 "(tx %s, rx %s)\n", k->wk_keyix, rvp_id, mode, in rum_pair_key_set_cb()
2950 (k->wk_flags & IEEE80211_KEY_XMIT) ? "on" : "off", in rum_pair_key_set_cb()
2951 (k->wk_flags & IEEE80211_KEY_RECV) ? "on" : "off"); in rum_pair_key_set_cb()
2954 if (rum_common_key_set(sc, k, RT2573_PKEY(k->wk_keyix)) != 0) in rum_pair_key_set_cb()
2957 IEEE80211_ADDR_COPY(buf, k->wk_macaddr); in rum_pair_key_set_cb()
2961 if (rum_write_multi(sc, RT2573_ADDR_ENTRY(k->wk_keyix), in rum_pair_key_set_cb()
2966 if (sc->vap_key_count[rvp_id]++ == 0) in rum_pair_key_set_cb()
2972 k->wk_keyix < 32 ? RT2573_SEC_CSR2 : RT2573_SEC_CSR3, in rum_pair_key_set_cb()
2973 1 << (k->wk_keyix % 32)) != 0) in rum_pair_key_set_cb()
2979 device_printf(sc->sc_dev, in rum_pair_key_set_cb()
2980 "%s: cannot set pairwise key %d, vap %d\n", __func__, k->wk_keyix, in rum_pair_key_set_cb()
2988 struct ieee80211_key *k = &data->key; in rum_pair_key_del_cb()
2990 DPRINTF("%s: removing key %d\n", __func__, k->wk_keyix); in rum_pair_key_del_cb()
2991 rum_clrbits(sc, (k->wk_keyix < 32) ? RT2573_SEC_CSR2 : RT2573_SEC_CSR3, in rum_pair_key_del_cb()
2992 1 << (k->wk_keyix % 32)); in rum_pair_key_del_cb()
2993 sc->keys_bmap &= ~(1ULL << k->wk_keyix); in rum_pair_key_del_cb()
2994 if (--sc->vap_key_count[rvp_id] == 0) in rum_pair_key_del_cb()
3002 struct rum_softc *sc = vap->iv_ic->ic_softc; in rum_key_alloc()
3006 if (!(k->wk_flags & IEEE80211_KEY_SWCRYPT)) { in rum_key_alloc()
3009 if ((sc->keys_bmap & (1ULL << i)) == 0) { in rum_key_alloc()
3010 sc->keys_bmap |= (1ULL << i); in rum_key_alloc()
3017 device_printf(sc->sc_dev, in rum_key_alloc()
3034 struct rum_softc *sc = vap->iv_ic->ic_softc; in rum_key_set()
3037 if (k->wk_flags & IEEE80211_KEY_SWCRYPT) { in rum_key_set()
3051 struct rum_softc *sc = vap->iv_ic->ic_softc; in rum_key_delete()
3054 if (k->wk_flags & IEEE80211_KEY_SWCRYPT) { in rum_key_delete()
3069 struct rum_softc *sc = ni->ni_ic->ic_softc; in rum_raw_xmit()
3074 if (!sc->sc_running) { in rum_raw_xmit()
3078 if (sc->tx_nfree < RUM_TX_MINFREE) { in rum_raw_xmit()
3110 struct ieee80211vap *vap = ni->ni_vap; in rum_ratectl_start()
3114 rum_read_multi(sc, RT2573_STA_CSR0, sc->sta, sizeof sc->sta); in rum_ratectl_start()
3116 usb_callout_reset(&rvp->ratectl_ch, hz, rum_ratectl_timeout, rvp); in rum_ratectl_start()
3123 struct ieee80211vap *vap = &rvp->vap; in rum_ratectl_timeout()
3124 struct ieee80211com *ic = vap->iv_ic; in rum_ratectl_timeout()
3126 ieee80211_runtask(ic, &rvp->ratectl_task); in rum_ratectl_timeout()
3133 struct ieee80211vap *vap = &rvp->vap; in rum_ratectl_task()
3134 struct rum_softc *sc = vap->iv_ic->ic_softc; in rum_ratectl_task()
3135 struct ieee80211_ratectl_tx_stats *txs = &sc->sc_txs; in rum_ratectl_task()
3140 rum_read_multi(sc, RT2573_STA_CSR0, sc->sta, sizeof(sc->sta)); in rum_ratectl_task()
3142 ok[0] = (le32toh(sc->sta[4]) & 0xffff); /* TX ok w/o retry */ in rum_ratectl_task()
3143 ok[1] = (le32toh(sc->sta[4]) >> 16); /* TX ok w/ one retry */ in rum_ratectl_task()
3144 ok[2] = (le32toh(sc->sta[5]) & 0xffff); /* TX ok w/ multiple retries */ in rum_ratectl_task()
3145 fail = (le32toh(sc->sta[5]) >> 16); /* TX retry-fail count */ in rum_ratectl_task()
3147 txs->flags = IEEE80211_RATECTL_TX_STATS_RETRIES; in rum_ratectl_task()
3148 txs->nframes = ok[0] + ok[1] + ok[2] + fail; in rum_ratectl_task()
3149 txs->nsuccess = txs->nframes - fail; in rum_ratectl_task()
3151 txs->nretries = ok[1] + ok[2] * 2 + fail * (rvp->maxretry + 1); in rum_ratectl_task()
3153 if (txs->nframes != 0) in rum_ratectl_task()
3156 /* count TX retry-fail as Tx errors */ in rum_ratectl_task()
3157 if_inc_counter(vap->iv_ifp, IFCOUNTER_OERRORS, fail); in rum_ratectl_task()
3159 usb_callout_reset(&rvp->ratectl_ch, hz, rum_ratectl_timeout, rvp); in rum_ratectl_task()
3166 struct rum_softc *sc = ic->ic_softc; in rum_scan_start()
3178 struct rum_softc *sc = ic->ic_softc; in rum_scan_end()
3180 if (ic->ic_flags_ext & IEEE80211_FEXT_BGSCAN) { in rum_scan_end()
3182 if (ic->ic_opmode != IEEE80211_M_AHDEMO) in rum_scan_end()
3186 rum_set_bssid(sc, sc->sc_bssid); in rum_scan_end()
3194 struct rum_softc *sc = ic->ic_softc; in rum_set_channel()
3197 rum_set_chan(sc, ic->ic_curchan); in rum_set_channel()
3205 struct rum_softc *sc = ic->ic_softc; in rum_getradiocaps()
3213 if (sc->rf_rev == RT2573_RF_5225 || sc->rf_rev == RT2573_RF_5226) { in rum_getradiocaps()
3223 struct ieee80211com *ic = &sc->sc_ic; in rum_get_rssi()
3233 * NB: Since RSSI is relative to noise floor, -1 is in rum_get_rssi()
3236 return -1; in rum_get_rssi()
3239 rssi = (2 * agc) - RT2573_NOISE_FLOOR; in rum_get_rssi()
3241 if (IEEE80211_IS_CHAN_2GHZ(ic->ic_curchan)) { in rum_get_rssi()
3242 rssi += sc->rssi_2ghz_corr; in rum_get_rssi()
3245 rssi -= 64; in rum_get_rssi()
3247 rssi -= 74; in rum_get_rssi()
3249 rssi -= 90; in rum_get_rssi()
3251 rssi += sc->rssi_5ghz_corr; in rum_get_rssi()
3253 if (!sc->ext_5ghz_lna && lna != 1) in rum_get_rssi()
3257 rssi -= 64; in rum_get_rssi()
3259 rssi -= 86; in rum_get_rssi()
3261 rssi -= 100; in rum_get_rssi()
3270 usb_pause_mtx(&sc->sc_mtx, timeout); in rum_pause()