Lines Matching +full:txs +full:- +full:delta
1 /*-
5 * Copyright (c) 2013-2014 Kevin Lo
20 /*-
114 device_printf((_sc)->sc_dev, __VA_ARGS__); \
531 /* MCS - single stream */
541 /* MCS - 2 streams */
551 /* MCS - 3 streams */
732 if (uaa->dev_state != UAA_DEV_READY) in run_autoinst()
738 id = iface->idesc; in run_autoinst()
739 if (id == NULL || id->bInterfaceClass != UICLASS_MASS) in run_autoinst()
745 uaa->dev_state = UAA_DEV_EJECTING; in run_autoinst()
770 if (uaa->usb_mode != USB_MODE_HOST) in run_match()
772 if (uaa->info.bConfigIndex != 0) in run_match()
774 if (uaa->info.bIfaceIndex != RT2860_IFACE_INDEX) in run_match()
785 struct ieee80211com *ic = &sc->sc_ic; in run_attach()
791 sc->sc_udev = uaa->device; in run_attach()
792 sc->sc_dev = self; in run_attach()
794 sc->sc_flags |= RUN_FLAG_FWLOAD_NEEDED; in run_attach()
796 mtx_init(&sc->sc_mtx, device_get_nameunit(sc->sc_dev), in run_attach()
798 mbufq_init(&sc->sc_snd, ifqmaxlen); in run_attach()
802 error = usbd_transfer_setup(uaa->device, &iface_index, in run_attach()
803 sc->sc_xfer, run_config, RUN_N_XFER, sc, &sc->sc_mtx); in run_attach()
823 device_printf(sc->sc_dev, in run_attach()
828 sc->mac_ver = ver >> 16; in run_attach()
829 sc->mac_rev = ver & 0xffff; in run_attach()
834 device_printf(sc->sc_dev, in run_attach()
836 sc->mac_ver, sc->mac_rev, run_get_rf(sc->rf_rev), in run_attach()
837 sc->ntxchains, sc->nrxchains, ether_sprintf(ic->ic_macaddr)); in run_attach()
841 ic->ic_softc = sc; in run_attach()
842 ic->ic_name = device_get_nameunit(self); in run_attach()
843 ic->ic_phytype = IEEE80211_T_OFDM; /* not only, but not used */ in run_attach()
844 ic->ic_opmode = IEEE80211_M_STA; /* default to BSS mode */ in run_attach()
847 ic->ic_caps = in run_attach()
852 IEEE80211_C_WDS | /* 4-address traffic works */ in run_attach()
856 IEEE80211_C_SWAMSDUTX | /* Do software A-MSDU TX */ in run_attach()
857 IEEE80211_C_FF | /* Atheros fast-frames */ in run_attach()
864 if (sc->rf_rev != RT3070_RF_2020) { in run_attach()
865 device_printf(sc->sc_dev, "[HT] Enabling 802.11n\n"); in run_attach()
866 ic->ic_htcaps = in run_attach()
873 ic->ic_rxstream = sc->nrxchains; in run_attach()
874 ic->ic_txstream = sc->ntxchains; in run_attach()
877 ic->ic_cryptocaps = in run_attach()
883 ic->ic_flags |= IEEE80211_F_DATAPAD; in run_attach()
884 ic->ic_flags_ext |= IEEE80211_FEXT_SWBMISS; in run_attach()
886 run_getradiocaps(ic, IEEE80211_CHAN_MAX, &ic->ic_nchans, in run_attach()
887 ic->ic_channels); in run_attach()
891 ic->ic_scan_start = run_scan_start; in run_attach()
892 ic->ic_scan_end = run_scan_end; in run_attach()
893 ic->ic_set_channel = run_set_channel; in run_attach()
894 ic->ic_getradiocaps = run_getradiocaps; in run_attach()
895 ic->ic_node_alloc = run_node_alloc; in run_attach()
896 ic->ic_newassoc = run_newassoc; in run_attach()
897 ic->ic_updateslot = run_updateslot; in run_attach()
898 ic->ic_update_mcast = run_update_mcast; in run_attach()
899 ic->ic_wme.wme_update = run_wme_update; in run_attach()
900 ic->ic_raw_xmit = run_raw_xmit; in run_attach()
901 ic->ic_update_promisc = run_update_promisc; in run_attach()
902 ic->ic_vap_create = run_vap_create; in run_attach()
903 ic->ic_vap_delete = run_vap_delete; in run_attach()
904 ic->ic_transmit = run_transmit; in run_attach()
905 ic->ic_parent = run_parent; in run_attach()
906 ic->ic_update_chw = run_update_chw; in run_attach()
907 ic->ic_ampdu_enable = run_ampdu_enable; in run_attach()
910 &sc->sc_txtap.wt_ihdr, sizeof(sc->sc_txtap), in run_attach()
912 &sc->sc_rxtap.wr_ihdr, sizeof(sc->sc_rxtap), in run_attach()
915 TASK_INIT(&sc->cmdq_task, 0, run_cmdq_cb, sc); in run_attach()
916 TASK_INIT(&sc->ratectl_task, 0, run_ratectl_cb, sc); in run_attach()
917 usb_callout_init_mtx(&sc->ratectl_ch, &sc->sc_mtx, 0); in run_attach()
936 while ((m = mbufq_dequeue(&sc->sc_snd)) != NULL) { in run_drain_mbufq()
937 ni = (struct ieee80211_node *)m->m_pkthdr.rcvif; in run_drain_mbufq()
938 m->m_pkthdr.rcvif = NULL; in run_drain_mbufq()
948 struct ieee80211com *ic = &sc->sc_ic; in run_detach()
952 sc->sc_detached = 1; in run_detach()
956 usbd_transfer_unsetup(sc->sc_xfer, RUN_N_XFER); in run_detach()
959 sc->ratectl_run = RUN_RATECTL_OFF; in run_detach()
960 sc->cmdq_run = sc->cmdq_key_set = RUN_CMDQ_ABORT; in run_detach()
964 run_unsetup_tx_list(sc, &sc->sc_epq[i]); in run_detach()
970 if (sc->sc_ic.ic_softc == sc) { in run_detach()
972 usb_callout_drain(&sc->ratectl_ch); in run_detach()
973 ieee80211_draintask(ic, &sc->cmdq_task); in run_detach()
974 ieee80211_draintask(ic, &sc->ratectl_task); in run_detach()
978 mtx_destroy(&sc->sc_mtx); in run_detach()
989 struct run_softc *sc = ic->ic_softc; in run_vap_create()
994 if (sc->rvp_cnt >= RUN_VAP_MAX) { in run_vap_create()
995 device_printf(sc->sc_dev, "number of VAPs maxed out\n"); in run_vap_create()
1009 if (!TAILQ_EMPTY(&ic->ic_vaps)) in run_vap_create()
1013 TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next){ in run_vap_create()
1014 if(vap->iv_opmode != IEEE80211_M_HOSTAP) in run_vap_create()
1021 device_printf(sc->sc_dev, in run_vap_create()
1027 device_printf(sc->sc_dev, "unknown opmode %d\n", opmode); in run_vap_create()
1032 vap = &rvp->vap; in run_vap_create()
1041 vap->iv_update_beacon = run_update_beacon; in run_vap_create()
1042 vap->iv_max_aid = RT2870_WCID_MAX; in run_vap_create()
1048 if (ic->ic_rxstream > 1) in run_vap_create()
1049 vap->iv_ampdu_rxmax = IEEE80211_HTCAP_MAXRXAMPDU_64K; in run_vap_create()
1051 vap->iv_ampdu_rxmax = IEEE80211_HTCAP_MAXRXAMPDU_32K; in run_vap_create()
1052 vap->iv_ampdu_density = IEEE80211_HTCAP_MPDUDENSITY_2; /* 2uS */ in run_vap_create()
1060 vap->iv_key_delete = (void *)run_key_delete; in run_vap_create()
1061 vap->iv_key_set = (void *)run_key_set; in run_vap_create()
1064 rvp->newstate = vap->iv_newstate; in run_vap_create()
1065 vap->iv_newstate = run_newstate; in run_vap_create()
1067 rvp->recv_mgmt = vap->iv_recv_mgmt; in run_vap_create()
1068 vap->iv_recv_mgmt = run_recv_mgmt; in run_vap_create()
1080 if((sc->rvp_bmap & 1 << i) == 0){ in run_vap_create()
1081 sc->rvp_bmap |= 1 << i; in run_vap_create()
1082 rvp->rvp_id = i; in run_vap_create()
1086 if (sc->rvp_cnt++ == 0) in run_vap_create()
1087 ic->ic_opmode = opmode; in run_vap_create()
1090 sc->cmdq_run = RUN_CMDQ_GO; in run_vap_create()
1093 rvp->rvp_id, sc->rvp_bmap, sc->rvp_cnt); in run_vap_create()
1109 ic = vap->iv_ic; in run_vap_delete()
1110 sc = ic->ic_softc; in run_vap_delete()
1114 m_freem(rvp->beacon_mbuf); in run_vap_delete()
1115 rvp->beacon_mbuf = NULL; in run_vap_delete()
1117 rvp_id = rvp->rvp_id; in run_vap_delete()
1118 sc->ratectl_run &= ~(1 << rvp_id); in run_vap_delete()
1119 sc->rvp_bmap &= ~(1 << rvp_id); in run_vap_delete()
1122 --sc->rvp_cnt; in run_vap_delete()
1126 vap, rvp_id, sc->rvp_bmap, sc->rvp_cnt); in run_vap_delete()
1138 * here is all-for-one taskqueue callback function. This function
1151 for (i = sc->cmdq_exec; sc->cmdq[i].func && pending; in run_cmdq_cb()
1152 i = sc->cmdq_exec, pending--) { in run_cmdq_cb()
1155 if (sc->cmdq_run == RUN_CMDQ_GO) { in run_cmdq_cb()
1160 if (sc->cmdq[i].arg0) in run_cmdq_cb()
1161 sc->cmdq[i].func(sc->cmdq[i].arg0); in run_cmdq_cb()
1163 sc->cmdq[i].func(&sc->cmdq[i]); in run_cmdq_cb()
1165 sc->cmdq[i].arg0 = NULL; in run_cmdq_cb()
1166 sc->cmdq[i].func = NULL; in run_cmdq_cb()
1167 sc->cmdq_exec++; in run_cmdq_cb()
1168 sc->cmdq_exec &= RUN_CMDQ_MASQ; in run_cmdq_cb()
1180 STAILQ_INIT(&pq->tx_qh); in run_setup_tx_list()
1181 STAILQ_INIT(&pq->tx_fh); in run_setup_tx_list()
1183 for (data = &pq->tx_data[0]; in run_setup_tx_list()
1184 data < &pq->tx_data[RUN_TX_RING_COUNT]; data++) { in run_setup_tx_list()
1185 data->sc = sc; in run_setup_tx_list()
1186 STAILQ_INSERT_TAIL(&pq->tx_fh, data, next); in run_setup_tx_list()
1188 pq->tx_nfree = RUN_TX_RING_COUNT; in run_setup_tx_list()
1197 pq->tx_nfree = 0; in run_unsetup_tx_list()
1198 STAILQ_INIT(&pq->tx_fh); in run_unsetup_tx_list()
1199 STAILQ_INIT(&pq->tx_qh); in run_unsetup_tx_list()
1202 for (data = &pq->tx_data[0]; in run_unsetup_tx_list()
1203 data < &pq->tx_data[RUN_TX_RING_COUNT]; data++) { in run_unsetup_tx_list()
1204 if (data->m != NULL) { in run_unsetup_tx_list()
1205 m_freem(data->m); in run_unsetup_tx_list()
1206 data->m = NULL; in run_unsetup_tx_list()
1208 if (data->ni != NULL) { in run_unsetup_tx_list()
1209 ieee80211_free_node(data->ni); in run_unsetup_tx_list()
1210 data->ni = NULL; in run_unsetup_tx_list()
1230 device_printf(sc->sc_dev, in run_load_microcode()
1235 if (fw->datasize != 8192) { in run_load_microcode()
1236 device_printf(sc->sc_dev, in run_load_microcode()
1244 * run-rt2870 (8KB) contains both, in run_load_microcode()
1248 base = fw->data; in run_load_microcode()
1249 if ((sc->mac_ver) != 0x2860 && in run_load_microcode()
1250 (sc->mac_ver) != 0x2872 && in run_load_microcode()
1251 (sc->mac_ver) != 0x3070) { in run_load_microcode()
1256 temp = fw->data; in run_load_microcode()
1259 device_printf(sc->sc_dev, "firmware checksum failed\n"); in run_load_microcode()
1265 if (sc->sc_flags & RUN_FLAG_FWLOAD_NEEDED) { in run_load_microcode()
1276 if ((error = usbd_do_request(sc->sc_udev, &sc->sc_mtx, &req, NULL)) in run_load_microcode()
1278 device_printf(sc->sc_dev, "firmware reset failed\n"); in run_load_microcode()
1299 device_printf(sc->sc_dev, in run_load_microcode()
1304 device_printf(sc->sc_dev, "firmware %s ver. %u.%u loaded\n", in run_load_microcode()
1305 (base == fw->data) ? "RT2870" : "RT3071", in run_load_microcode()
1323 return (usbd_do_request(sc->sc_udev, &sc->sc_mtx, &req, NULL)); in run_reset()
1335 while (ntries--) { in run_do_request()
1336 err = usbd_do_request_flags(sc->sc_udev, &sc->sc_mtx, in run_do_request()
1421 * firmware. Limit amount of data passed to 64-bytes at a in run_write_region_1()
1425 int delta = 64; in run_write_region_1()
1426 if (delta > len) in run_write_region_1()
1427 delta = len; in run_write_region_1()
1433 USETW(req.wLength, delta); in run_write_region_1()
1437 reg += delta; in run_write_region_1()
1438 buf += delta; in run_write_region_1()
1439 len -= delta; in run_write_region_1()
1468 /*- in run_efuse_read()
1469 * Read one 16-byte block into registers EFUSE_DATA[0-3]: in run_efuse_read()
1492 /* determine to which 32-bit register our 16-bit word belongs */ in run_efuse_read()
1493 reg = RT3070_EFUSE_DATA3 - (addr & 0xc); in run_efuse_read()
1503 /* Read 16-bit from eFUSE ROM for RT3xxx. */
1524 error = usbd_do_request(sc->sc_udev, &sc->sc_mtx, &req, &tmp); in run_eeprom_read_2()
1536 return sc->sc_srom_read(sc, addr, val); in run_srom_read()
1684 * Add `delta' (signed) to each 4-bit sub-word of a 32-bit word.
1685 * Used to adjust per-rate Tx power registers.
1688 b4inc(uint32_t b32, int8_t delta) in b4inc() argument
1694 b4 += delta; in b4inc()
1733 addr = (sc->ntxchains == 3) ? RT3593_EEPROM_PWR2GHZ_BASE1 : in run_rt3593_get_txpower()
1736 sc->txpow1[i + 0] = (int8_t)(val & 0xff); in run_rt3593_get_txpower()
1737 sc->txpow1[i + 1] = (int8_t)(val >> 8); in run_rt3593_get_txpower()
1739 addr = (sc->ntxchains == 3) ? RT3593_EEPROM_PWR2GHZ_BASE2 : in run_rt3593_get_txpower()
1742 sc->txpow2[i + 0] = (int8_t)(val & 0xff); in run_rt3593_get_txpower()
1743 sc->txpow2[i + 1] = (int8_t)(val >> 8); in run_rt3593_get_txpower()
1745 if (sc->ntxchains == 3) { in run_rt3593_get_txpower()
1748 sc->txpow3[i + 0] = (int8_t)(val & 0xff); in run_rt3593_get_txpower()
1749 sc->txpow3[i + 1] = (int8_t)(val >> 8); in run_rt3593_get_txpower()
1754 if (sc->txpow1[i] > 31) in run_rt3593_get_txpower()
1755 sc->txpow1[i] = 5; in run_rt3593_get_txpower()
1756 if (sc->txpow2[i] > 31) in run_rt3593_get_txpower()
1757 sc->txpow2[i] = 5; in run_rt3593_get_txpower()
1758 if (sc->ntxchains == 3) { in run_rt3593_get_txpower()
1759 if (sc->txpow3[i] > 31) in run_rt3593_get_txpower()
1760 sc->txpow3[i] = 5; in run_rt3593_get_txpower()
1766 sc->txpow1[i + 14] = (int8_t)(val & 0xff); in run_rt3593_get_txpower()
1767 sc->txpow1[i + 15] = (int8_t)(val >> 8); in run_rt3593_get_txpower()
1770 sc->txpow2[i + 14] = (int8_t)(val & 0xff); in run_rt3593_get_txpower()
1771 sc->txpow2[i + 15] = (int8_t)(val >> 8); in run_rt3593_get_txpower()
1773 if (sc->ntxchains == 3) { in run_rt3593_get_txpower()
1776 sc->txpow3[i + 14] = (int8_t)(val & 0xff); in run_rt3593_get_txpower()
1777 sc->txpow3[i + 15] = (int8_t)(val >> 8); in run_rt3593_get_txpower()
1791 sc->txpow1[i + 0] = (int8_t)(val & 0xff); in run_get_txpower()
1792 sc->txpow1[i + 1] = (int8_t)(val >> 8); in run_get_txpower()
1794 if (sc->mac_ver != 0x5390) { in run_get_txpower()
1797 sc->txpow2[i + 0] = (int8_t)(val & 0xff); in run_get_txpower()
1798 sc->txpow2[i + 1] = (int8_t)(val >> 8); in run_get_txpower()
1803 if (sc->mac_ver >= 0x5390) { in run_get_txpower()
1804 if (sc->txpow1[i] < 0 || sc->txpow1[i] > 39) in run_get_txpower()
1805 sc->txpow1[i] = 5; in run_get_txpower()
1807 if (sc->txpow1[i] < 0 || sc->txpow1[i] > 31) in run_get_txpower()
1808 sc->txpow1[i] = 5; in run_get_txpower()
1810 if (sc->mac_ver > 0x5390) { in run_get_txpower()
1811 if (sc->txpow2[i] < 0 || sc->txpow2[i] > 39) in run_get_txpower()
1812 sc->txpow2[i] = 5; in run_get_txpower()
1813 } else if (sc->mac_ver < 0x5390) { in run_get_txpower()
1814 if (sc->txpow2[i] < 0 || sc->txpow2[i] > 31) in run_get_txpower()
1815 sc->txpow2[i] = 5; in run_get_txpower()
1819 rt2860_rf2850[i].chan, sc->txpow1[i], sc->txpow2[i]); in run_get_txpower()
1824 sc->txpow1[i + 14] = (int8_t)(val & 0xff); in run_get_txpower()
1825 sc->txpow1[i + 15] = (int8_t)(val >> 8); in run_get_txpower()
1828 sc->txpow2[i + 14] = (int8_t)(val & 0xff); in run_get_txpower()
1829 sc->txpow2[i + 15] = (int8_t)(val >> 8); in run_get_txpower()
1833 if (sc->mac_ver != 0x5592) { in run_get_txpower()
1834 if (sc->txpow1[14 + i] < -7 || sc->txpow1[14 + i] > 15) in run_get_txpower()
1835 sc->txpow1[14 + i] = 5; in run_get_txpower()
1836 if (sc->txpow2[14 + i] < -7 || sc->txpow2[14 + i] > 15) in run_get_txpower()
1837 sc->txpow2[14 + i] = 5; in run_get_txpower()
1841 rt2860_rf2850[14 + i].chan, sc->txpow1[14 + i], in run_get_txpower()
1842 sc->txpow2[14 + i]); in run_get_txpower()
1849 struct ieee80211com *ic = &sc->sc_ic; in run_read_eeprom()
1856 sc->sc_srom_read = run_eeprom_read_2; in run_read_eeprom()
1857 if (sc->mac_ver >= 0x3070) { in run_read_eeprom()
1860 if ((tmp & RT3070_SEL_EFUSE) || sc->mac_ver == 0x3593) in run_read_eeprom()
1861 sc->sc_srom_read = run_efuse_read_2; in run_read_eeprom()
1871 ic->ic_macaddr[0] = val & 0xff; in run_read_eeprom()
1872 ic->ic_macaddr[1] = val >> 8; in run_read_eeprom()
1874 ic->ic_macaddr[2] = val & 0xff; in run_read_eeprom()
1875 ic->ic_macaddr[3] = val >> 8; in run_read_eeprom()
1877 ic->ic_macaddr[4] = val & 0xff; in run_read_eeprom()
1878 ic->ic_macaddr[5] = val >> 8; in run_read_eeprom()
1880 if (sc->mac_ver < 0x3593) { in run_read_eeprom()
1884 sc->bbp[i].val = val & 0xff; in run_read_eeprom()
1885 sc->bbp[i].reg = val >> 8; in run_read_eeprom()
1887 "BBP%d=0x%02x\n", sc->bbp[i].reg, sc->bbp[i].val); in run_read_eeprom()
1889 if (sc->mac_ver >= 0x3071) { in run_read_eeprom()
1894 sc->rf[i].val = val & 0xff; in run_read_eeprom()
1895 sc->rf[i].reg = val >> 8; in run_read_eeprom()
1897 sc->rf[i].reg, sc->rf[i].val); in run_read_eeprom()
1903 run_srom_read(sc, (sc->mac_ver != 0x3593) ? RT2860_EEPROM_FREQ_LEDS : in run_read_eeprom()
1905 sc->freq = ((val & 0xff) != 0xff) ? val & 0xff : 0; in run_read_eeprom()
1907 sc->freq & 0xff); in run_read_eeprom()
1909 run_srom_read(sc, (sc->mac_ver != 0x3593) ? RT2860_EEPROM_FREQ_LEDS : in run_read_eeprom()
1913 sc->leds = val >> 8; in run_read_eeprom()
1914 run_srom_read(sc, (sc->mac_ver != 0x3593) ? RT2860_EEPROM_LED1 : in run_read_eeprom()
1915 RT3593_EEPROM_LED1, &sc->led[0]); in run_read_eeprom()
1916 run_srom_read(sc, (sc->mac_ver != 0x3593) ? RT2860_EEPROM_LED2 : in run_read_eeprom()
1917 RT3593_EEPROM_LED2, &sc->led[1]); in run_read_eeprom()
1918 run_srom_read(sc, (sc->mac_ver != 0x3593) ? RT2860_EEPROM_LED3 : in run_read_eeprom()
1919 RT3593_EEPROM_LED3, &sc->led[2]); in run_read_eeprom()
1922 sc->leds = 0x01; in run_read_eeprom()
1923 sc->led[0] = 0x5555; in run_read_eeprom()
1924 sc->led[1] = 0x2221; in run_read_eeprom()
1925 sc->led[2] = 0x5627; /* differs from RT2860 */ in run_read_eeprom()
1929 sc->leds, sc->led[0], sc->led[1], sc->led[2]); in run_read_eeprom()
1932 if (sc->mac_ver == 0x5390 || sc->mac_ver ==0x5392) in run_read_eeprom()
1938 device_printf(sc->sc_dev, in run_read_eeprom()
1940 if (sc->mac_ver == 0x3572) { in run_read_eeprom()
1942 sc->rf_rev = RT3070_RF_3052; in run_read_eeprom()
1943 sc->ntxchains = 2; in run_read_eeprom()
1944 sc->nrxchains = 2; in run_read_eeprom()
1945 } else if (sc->mac_ver >= 0x3070) { in run_read_eeprom()
1947 sc->rf_rev = RT3070_RF_3020; in run_read_eeprom()
1948 sc->ntxchains = 1; in run_read_eeprom()
1949 sc->nrxchains = 1; in run_read_eeprom()
1952 sc->rf_rev = RT2860_RF_2820; in run_read_eeprom()
1953 sc->ntxchains = 1; in run_read_eeprom()
1954 sc->nrxchains = 2; in run_read_eeprom()
1957 if (sc->mac_ver == 0x5390 || sc->mac_ver ==0x5392) { in run_read_eeprom()
1958 sc->rf_rev = val; in run_read_eeprom()
1961 sc->rf_rev = (val >> 8) & 0xf; in run_read_eeprom()
1962 sc->ntxchains = (val >> 4) & 0xf; in run_read_eeprom()
1963 sc->nrxchains = val & 0xf; in run_read_eeprom()
1966 sc->rf_rev, sc->ntxchains, sc->nrxchains); in run_read_eeprom()
1973 sc->patch_dac = (val >> 15) & 1; in run_read_eeprom()
1975 sc->ext_5ghz_lna = (val >> 3) & 1; in run_read_eeprom()
1976 sc->ext_2ghz_lna = (val >> 2) & 1; in run_read_eeprom()
1978 sc->calib_2ghz = sc->calib_5ghz = (val >> 1) & 1; in run_read_eeprom()
1980 sc->rfswitch = val & 1; in run_read_eeprom()
1984 if (sc->mac_ver == 0x3593) in run_read_eeprom()
1995 delta_2ghz = -delta_2ghz; in run_read_eeprom()
2001 delta_5ghz = -delta_5ghz; in run_read_eeprom()
2014 sc->txpow20mhz[ridx] = reg; in run_read_eeprom()
2015 sc->txpow40mhz_2ghz[ridx] = b4inc(reg, delta_2ghz); in run_read_eeprom()
2016 sc->txpow40mhz_5ghz[ridx] = b4inc(reg, delta_5ghz); in run_read_eeprom()
2020 "40MHz/5GHz=0x%08x\n", ridx, sc->txpow20mhz[ridx], in run_read_eeprom()
2021 sc->txpow40mhz_2ghz[ridx], sc->txpow40mhz_5ghz[ridx]); in run_read_eeprom()
2025 run_srom_read(sc, (sc->mac_ver != 0x3593) ? RT2860_EEPROM_RSSI1_2GHZ : in run_read_eeprom()
2027 sc->rssi_2ghz[0] = val & 0xff; /* Ant A */ in run_read_eeprom()
2028 sc->rssi_2ghz[1] = val >> 8; /* Ant B */ in run_read_eeprom()
2029 run_srom_read(sc, (sc->mac_ver != 0x3593) ? RT2860_EEPROM_RSSI2_2GHZ : in run_read_eeprom()
2031 if (sc->mac_ver >= 0x3070) { in run_read_eeprom()
2032 if (sc->mac_ver == 0x3593) { in run_read_eeprom()
2033 sc->txmixgain_2ghz = 0; in run_read_eeprom()
2034 sc->rssi_2ghz[2] = val & 0xff; /* Ant C */ in run_read_eeprom()
2041 sc->txmixgain_2ghz = val & 0x7; in run_read_eeprom()
2044 sc->txmixgain_2ghz); in run_read_eeprom()
2046 sc->rssi_2ghz[2] = val & 0xff; /* Ant C */ in run_read_eeprom()
2047 if (sc->mac_ver == 0x3593) in run_read_eeprom()
2049 sc->lna[2] = val >> 8; /* channel group 2 */ in run_read_eeprom()
2051 run_srom_read(sc, (sc->mac_ver != 0x3593) ? RT2860_EEPROM_RSSI1_5GHZ : in run_read_eeprom()
2053 sc->rssi_5ghz[0] = val & 0xff; /* Ant A */ in run_read_eeprom()
2054 sc->rssi_5ghz[1] = val >> 8; /* Ant B */ in run_read_eeprom()
2055 run_srom_read(sc, (sc->mac_ver != 0x3593) ? RT2860_EEPROM_RSSI2_5GHZ : in run_read_eeprom()
2057 if (sc->mac_ver == 0x3572) { in run_read_eeprom()
2063 sc->txmixgain_5ghz = val & 0x7; in run_read_eeprom()
2065 sc->txmixgain_5ghz); in run_read_eeprom()
2067 sc->rssi_5ghz[2] = val & 0xff; /* Ant C */ in run_read_eeprom()
2068 if (sc->mac_ver == 0x3593) { in run_read_eeprom()
2069 sc->txmixgain_5ghz = 0; in run_read_eeprom()
2072 sc->lna[3] = val >> 8; /* channel group 3 */ in run_read_eeprom()
2074 run_srom_read(sc, (sc->mac_ver != 0x3593) ? RT2860_EEPROM_LNA : in run_read_eeprom()
2076 sc->lna[0] = val & 0xff; /* channel group 0 */ in run_read_eeprom()
2077 sc->lna[1] = val >> 8; /* channel group 1 */ in run_read_eeprom()
2080 if (sc->lna[2] == 0 || sc->lna[2] == 0xff) { in run_read_eeprom()
2083 sc->lna[2] = sc->lna[1]; in run_read_eeprom()
2085 if (sc->lna[3] == 0 || sc->lna[3] == 0xff) { in run_read_eeprom()
2088 sc->lna[3] = sc->lna[1]; in run_read_eeprom()
2093 if (sc->rssi_2ghz[ant] < -10 || sc->rssi_2ghz[ant] > 10) { in run_read_eeprom()
2096 ant + 1, sc->rssi_2ghz[ant]); in run_read_eeprom()
2097 sc->rssi_2ghz[ant] = 0; in run_read_eeprom()
2099 if (sc->rssi_5ghz[ant] < -10 || sc->rssi_5ghz[ant] > 10) { in run_read_eeprom()
2102 ant + 1, sc->rssi_5ghz[ant]); in run_read_eeprom()
2103 sc->rssi_5ghz[ant] = 0; in run_read_eeprom()
2120 struct ieee80211com *ic = vap->iv_ic; in run_media_change()
2122 struct run_softc *sc = ic->ic_softc; in run_media_change()
2134 tp = &vap->iv_txparms[ieee80211_chan2mode(ic->ic_curchan)]; in run_media_change()
2135 if (tp->ucastrate != IEEE80211_FIXED_RATE_NONE) { in run_media_change()
2140 rate = ic->ic_sup_rates[ic->ic_curmode]. in run_media_change()
2141 rs_rates[tp->ucastrate] & IEEE80211_RATE_VAL; in run_media_change()
2146 ni = ieee80211_ref_node(vap->iv_bss); in run_media_change()
2148 rn->fix_ridx = ridx; in run_media_change()
2150 rate, rn->fix_ridx); in run_media_change()
2170 struct ieee80211com *ic = vap->iv_ic; in run_newstate()
2171 struct run_softc *sc = ic->ic_softc; in run_newstate()
2177 uint8_t bid = 1 << rvp->rvp_id; in run_newstate()
2179 ostate = vap->iv_state; in run_newstate()
2180 RUN_DPRINTF(sc, RUN_DEBUG_STATE, "%s -> %s\n", in run_newstate()
2187 ratectl = sc->ratectl_run; /* remember current state */ in run_newstate()
2188 sc->ratectl_run = RUN_RATECTL_OFF; in run_newstate()
2189 usb_callout_stop(&sc->ratectl_ch); in run_newstate()
2204 sc->runbmap &= ~bid; in run_newstate()
2207 if (--sc->running == 0) in run_newstate()
2212 if (!(sc->runbmap & bid)) { in run_newstate()
2213 if(sc->running++) in run_newstate()
2215 sc->runbmap |= bid; in run_newstate()
2218 m_freem(rvp->beacon_mbuf); in run_newstate()
2219 rvp->beacon_mbuf = NULL; in run_newstate()
2221 switch (vap->iv_opmode) { in run_newstate()
2224 sc->ap_running |= bid; in run_newstate()
2225 ic->ic_opmode = vap->iv_opmode; in run_newstate()
2229 sc->adhoc_running |= bid; in run_newstate()
2230 if (!sc->ap_running) in run_newstate()
2231 ic->ic_opmode = vap->iv_opmode; in run_newstate()
2235 sc->sta_running |= bid; in run_newstate()
2236 if (!sc->ap_running && !sc->adhoc_running) in run_newstate()
2237 ic->ic_opmode = vap->iv_opmode; in run_newstate()
2245 ic->ic_opmode = vap->iv_opmode; in run_newstate()
2249 if (vap->iv_opmode != IEEE80211_M_MONITOR) { in run_newstate()
2252 if (ic->ic_bsschan == IEEE80211_CHAN_ANYC) { in run_newstate()
2255 return (-1); in run_newstate()
2261 ni = ieee80211_ref_node(vap->iv_bss); in run_newstate()
2262 IEEE80211_ADDR_COPY(sc->sc_bssid, ni->ni_bssid); in run_newstate()
2263 run_set_bssid(sc, sc->sc_bssid); in run_newstate()
2268 tp = &vap->iv_txparms[ieee80211_chan2mode(ic->ic_curchan)]; in run_newstate()
2269 if (tp->ucastrate == IEEE80211_FIXED_RATE_NONE) in run_newstate()
2276 (IEEE80211_IS_CHAN_2GHZ(ic->ic_curchan) ? in run_newstate()
2286 if ((sc->ratectl_run = ratectl) && restart_ratectl) in run_newstate()
2287 usb_callout_reset(&sc->ratectl_ch, hz, run_ratectl_to, sc); in run_newstate()
2292 return(rvp->newstate(vap, nstate, arg)); in run_newstate()
2299 struct run_softc *sc = ic->ic_softc; in run_wme_update()
2356 struct ieee80211vap *vap = cmdq->arg1; in run_key_set_cb()
2357 struct ieee80211_key *k = cmdq->k; in run_key_set_cb()
2358 struct ieee80211com *ic = vap->iv_ic; in run_key_set_cb()
2359 struct run_softc *sc = ic->ic_softc; in run_key_set_cb()
2361 u_int cipher = k->wk_cipher->ic_cipher; in run_key_set_cb()
2368 if (vap->iv_opmode == IEEE80211_M_HOSTAP) in run_key_set_cb()
2369 ni = ieee80211_find_vap_node(&ic->ic_sta, vap, cmdq->mac); in run_key_set_cb()
2371 ni = vap->iv_bss; in run_key_set_cb()
2372 associd = (ni != NULL) ? ni->ni_associd : 0; in run_key_set_cb()
2377 if(k->wk_keylen < 8) in run_key_set_cb()
2395 associd, k->wk_keyix, mode, in run_key_set_cb()
2396 (k->wk_flags & IEEE80211_KEY_GROUP) ? "group" : "pairwise", in run_key_set_cb()
2397 (k->wk_flags & IEEE80211_KEY_XMIT) ? "on" : "off", in run_key_set_cb()
2398 (k->wk_flags & IEEE80211_KEY_RECV) ? "on" : "off"); in run_key_set_cb()
2400 if (k->wk_flags & IEEE80211_KEY_GROUP) { in run_key_set_cb()
2402 base = RT2860_SKEY(RUN_VAP(vap)->rvp_id, k->wk_keyix); in run_key_set_cb()
2404 wcid = (vap->iv_opmode == IEEE80211_M_STA) ? in run_key_set_cb()
2410 if(run_write_region_1(sc, base, k->wk_key, 16)) in run_key_set_cb()
2412 if(run_write_region_1(sc, base + 16, &k->wk_key[16], 8)) /* wk_txmic */ in run_key_set_cb()
2414 if(run_write_region_1(sc, base + 24, &k->wk_key[24], 8)) /* wk_rxmic */ in run_key_set_cb()
2417 /* roundup len to 16-bit: XXX fix write_region_1() instead */ in run_key_set_cb()
2418 if(run_write_region_1(sc, base, k->wk_key, (k->wk_keylen + 1) & ~1)) in run_key_set_cb()
2422 if (!(k->wk_flags & IEEE80211_KEY_GROUP) || in run_key_set_cb()
2423 (k->wk_flags & (IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV))) { in run_key_set_cb()
2427 iv[3] = vap->iv_def_txkey << 6; in run_key_set_cb()
2430 iv[0] = k->wk_keytsc >> 8; in run_key_set_cb()
2432 iv[2] = k->wk_keytsc; in run_key_set_cb()
2434 iv[0] = k->wk_keytsc; in run_key_set_cb()
2435 iv[1] = k->wk_keytsc >> 8; in run_key_set_cb()
2438 iv[3] = k->wk_keyix << 6 | IEEE80211_WEP_EXTIV; in run_key_set_cb()
2439 iv[4] = k->wk_keytsc >> 16; in run_key_set_cb()
2440 iv[5] = k->wk_keytsc >> 24; in run_key_set_cb()
2441 iv[6] = k->wk_keytsc >> 32; in run_key_set_cb()
2442 iv[7] = k->wk_keytsc >> 40; in run_key_set_cb()
2448 if (k->wk_flags & IEEE80211_KEY_GROUP) { in run_key_set_cb()
2452 attr &= ~(0xf << (k->wk_keyix * 4)); in run_key_set_cb()
2453 attr |= mode << (k->wk_keyix * 4); in run_key_set_cb()
2465 /* TODO create a pass-thru key entry? */ in run_key_set_cb()
2468 k->wk_pad = wcid; in run_key_set_cb()
2481 struct ieee80211com *ic = vap->iv_ic; in run_key_set()
2482 struct run_softc *sc = ic->ic_softc; in run_key_set()
2485 i = RUN_CMDQ_GET(&sc->cmdq_store); in run_key_set()
2487 sc->cmdq[i].func = run_key_set_cb; in run_key_set()
2488 sc->cmdq[i].arg0 = NULL; in run_key_set()
2489 sc->cmdq[i].arg1 = vap; in run_key_set()
2490 sc->cmdq[i].k = k; in run_key_set()
2491 IEEE80211_ADDR_COPY(sc->cmdq[i].mac, k->wk_macaddr); in run_key_set()
2492 ieee80211_runtask(ic, &sc->cmdq_task); in run_key_set()
2498 if (vap->iv_opmode == IEEE80211_M_HOSTAP) { in run_key_set()
2500 sc->cmdq_key_set = RUN_CMDQ_GO; in run_key_set()
2516 struct run_softc *sc = cmdq->arg1; in run_key_delete_cb()
2517 struct ieee80211_key *k = &cmdq->key; in run_key_delete_cb()
2523 if (k->wk_flags & IEEE80211_KEY_GROUP) { in run_key_delete_cb()
2527 attr &= ~(0xf << (k->wk_keyix * 4)); in run_key_delete_cb()
2532 "removing key for wcid %x\n", k->wk_pad); in run_key_delete_cb()
2534 wcid = k->wk_pad; in run_key_delete_cb()
2541 k->wk_pad = 0; in run_key_delete_cb()
2550 struct ieee80211com *ic = vap->iv_ic; in run_key_delete()
2551 struct run_softc *sc = ic->ic_softc; in run_key_delete()
2561 i = RUN_CMDQ_GET(&sc->cmdq_store); in run_key_delete()
2563 sc->cmdq[i].func = run_key_delete_cb; in run_key_delete()
2564 sc->cmdq[i].arg0 = NULL; in run_key_delete()
2565 sc->cmdq[i].arg1 = sc; in run_key_delete()
2566 k0 = &sc->cmdq[i].key; in run_key_delete()
2567 k0->wk_flags = k->wk_flags; in run_key_delete()
2568 k0->wk_keyix = k->wk_keyix; in run_key_delete()
2570 k0->wk_pad = k->wk_pad; in run_key_delete()
2571 ieee80211_runtask(ic, &sc->cmdq_task); in run_key_delete()
2582 ieee80211_runtask(&sc->sc_ic, &sc->ratectl_task); in run_ratectl_to()
2591 struct ieee80211com *ic = &sc->sc_ic; in run_ratectl_cb()
2592 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); in run_ratectl_cb()
2597 if (sc->rvp_cnt > 1 || vap->iv_opmode != IEEE80211_M_STA) { in run_ratectl_cb()
2612 ieee80211_iterate_nodes(&ic->ic_sta, run_iter_func, sc); in run_ratectl_cb()
2615 if(sc->ratectl_run != RUN_RATECTL_OFF) in run_ratectl_cb()
2616 usb_callout_reset(&sc->ratectl_ch, hz, run_ratectl_to, sc); in run_ratectl_cb()
2646 * Even though each stat is Tx-complete-status like format, in run_drain_fifo()
2655 wstat = &(sc->wcid_stats[wcid]); in run_drain_fifo()
2660 counter_u64_add(sc->sc_ic.ic_oerrors, 1); in run_drain_fifo()
2668 if ((retry = pid -1 - mcs) > 0) { in run_drain_fifo()
2673 RUN_DPRINTF(sc, RUN_DEBUG_XMIT, "count=%d\n", sc->fifo_cnt); in run_drain_fifo()
2675 sc->fifo_cnt = 0; in run_drain_fifo()
2682 struct ieee80211_ratectl_tx_stats *txs = &sc->sc_txs; in run_iter_func() local
2683 struct ieee80211vap *vap = ni->ni_vap; in run_iter_func()
2693 if (sc->rvp_cnt <= 1 && vap->iv_opmode == IEEE80211_M_STA && in run_iter_func()
2694 ni != vap->iv_bss) in run_iter_func()
2697 txs->flags = IEEE80211_RATECTL_TX_STATS_NODE | in run_iter_func()
2699 txs->ni = ni; in run_iter_func()
2700 if (sc->rvp_cnt <= 1 && (vap->iv_opmode == IEEE80211_M_IBSS || in run_iter_func()
2701 vap->iv_opmode == IEEE80211_M_STA)) { in run_iter_func()
2709 if_inc_counter(vap->iv_ifp, IFCOUNTER_OERRORS, in run_iter_func()
2712 txs->nretries = le16toh(sta[1].tx.retry); in run_iter_func()
2713 txs->nsuccess = le16toh(sta[1].tx.success); in run_iter_func()
2715 txs->nframes = txs->nretries + txs->nsuccess + in run_iter_func()
2720 txs->nretries, txs->nsuccess, le16toh(sta[0].error.fail)); in run_iter_func()
2722 wstat = &(sc->wcid_stats[RUN_AID2WCID(ni->ni_associd)]); in run_iter_func()
2724 if (wstat == &(sc->wcid_stats[0]) || in run_iter_func()
2725 wstat > &(sc->wcid_stats[RT2870_WCID_MAX])) in run_iter_func()
2728 txs->nretries = (*wstat)[RUN_RETRY]; in run_iter_func()
2729 txs->nsuccess = (*wstat)[RUN_SUCCESS]; in run_iter_func()
2730 txs->nframes = (*wstat)[RUN_TXCNT]; in run_iter_func()
2733 txs->nretries, txs->nframes, txs->nsuccess); in run_iter_func()
2738 ieee80211_ratectl_tx_update(vap, txs); in run_iter_func()
2745 rn->amrr_ridx = ridx; in run_iter_func()
2751 ieee80211_node_get_txrate_dot11rate(ni), rn->amrr_ridx); in run_iter_func()
2758 struct ieee80211_node *ni = cmdq->arg1; in run_newassoc_cb()
2759 struct run_softc *sc = ni->ni_vap->iv_ic->ic_softc; in run_newassoc_cb()
2760 uint8_t wcid = cmdq->wcid; in run_newassoc_cb()
2765 ni->ni_macaddr, IEEE80211_ADDR_LEN); in run_newassoc_cb()
2767 memset(&(sc->wcid_stats[wcid]), 0, sizeof(sc->wcid_stats[wcid])); in run_newassoc_cb()
2774 struct ieee80211vap *vap = ni->ni_vap; in run_newassoc()
2775 struct ieee80211com *ic = vap->iv_ic; in run_newassoc()
2776 struct run_softc *sc = ic->ic_softc; in run_newassoc()
2781 wcid = (vap->iv_opmode == IEEE80211_M_STA) ? in run_newassoc()
2782 1 : RUN_AID2WCID(ni->ni_associd); in run_newassoc()
2785 device_printf(sc->sc_dev, "wcid=%d out of range\n", wcid); in run_newassoc()
2790 if (isnew && ni->ni_associd != 0) { in run_newassoc()
2795 uint32_t cnt = RUN_CMDQ_GET(&sc->cmdq_store); in run_newassoc()
2797 sc->cmdq[cnt].func = run_newassoc_cb; in run_newassoc()
2798 sc->cmdq[cnt].arg0 = NULL; in run_newassoc()
2799 sc->cmdq[cnt].arg1 = ni; in run_newassoc()
2800 sc->cmdq[cnt].wcid = wcid; in run_newassoc()
2801 ieee80211_runtask(ic, &sc->cmdq_task); in run_newassoc()
2806 isnew, ni->ni_associd, ether_sprintf(ni->ni_macaddr)); in run_newassoc()
2808 rate = vap->iv_txparms[ieee80211_chan2mode(ic->ic_curchan)].mgmtrate; in run_newassoc()
2813 rn->mgt_ridx = ridx; in run_newassoc()
2815 "rate=%d, mgmt_ridx=%d\n", rate, rn->mgt_ridx); in run_newassoc()
2818 if(sc->ratectl_run != RUN_RATECTL_OFF) in run_newassoc()
2819 usb_callout_reset(&sc->ratectl_ch, hz, run_ratectl_to, sc); in run_newassoc()
2831 if (sc->nrxchains > 1) { in run_maxrssi_chain()
2832 if (rxwi->rssi[1] > rxwi->rssi[rxchain]) in run_maxrssi_chain()
2834 if (sc->nrxchains > 2) in run_maxrssi_chain()
2835 if (rxwi->rssi[2] > rxwi->rssi[rxchain]) in run_maxrssi_chain()
2845 struct ieee80211vap *vap = ni->ni_vap; in run_recv_mgmt()
2846 struct run_softc *sc = vap->iv_ic->ic_softc; in run_recv_mgmt()
2850 rvp->recv_mgmt(ni, m, subtype, rxs, rssi, nf); in run_recv_mgmt()
2852 if (vap->iv_state == IEEE80211_S_RUN && in run_recv_mgmt()
2855 ni_tstamp = le64toh(ni->ni_tstamp.tsf); in run_recv_mgmt()
2873 struct ieee80211com *ic = &sc->sc_ic; in run_rx_frame()
2884 if (sc->mac_ver == 0x5592) in run_rx_frame()
2886 else if (sc->mac_ver == 0x3593) in run_rx_frame()
2898 len = le16toh(rxwi->len) & 0xfff; in run_rx_frame()
2900 if (__predict_false(len > dmalen - rxwisize)) { in run_rx_frame()
2908 flags = le32toh(rxd->flags); in run_rx_frame()
2922 m->m_data += rxwisize; in run_rx_frame()
2923 m->m_pkthdr.len = m->m_len = len; in run_rx_frame()
2927 if ((wh->i_fc[1] & IEEE80211_FC1_PROTECTED) != 0 && in run_rx_frame()
2929 wh->i_fc[1] &= ~IEEE80211_FC1_PROTECTED; in run_rx_frame()
2930 m->m_flags |= M_WEP; in run_rx_frame()
2939 if(ni && ni->ni_flags & IEEE80211_NODE_HT) { in run_rx_frame()
2940 m->m_flags |= M_AMPDU; in run_rx_frame()
2946 ieee80211_notify_michael_failure(ni->ni_vap, wh, in run_rx_frame()
2947 rxwi->keyidx); in run_rx_frame()
2954 rssi = rxwi->rssi[ant]; in run_rx_frame()
2958 struct run_rx_radiotap_header *tap = &sc->sc_rxtap; in run_rx_frame()
2961 tap->wr_flags = 0; in run_rx_frame()
2963 tap->wr_flags |= IEEE80211_RADIOTAP_F_DATAPAD; in run_rx_frame()
2964 tap->wr_antsignal = rssi; in run_rx_frame()
2965 tap->wr_antenna = ant; in run_rx_frame()
2966 tap->wr_dbm_antsignal = run_rssi2dbm(sc, rssi, ant); in run_rx_frame()
2967 tap->wr_rate = 2; /* in case it can't be found below */ in run_rx_frame()
2969 run_get_tsf(sc, &tap->wr_tsf); in run_rx_frame()
2971 phy = le16toh(rxwi->phy); in run_rx_frame()
2975 case 0: tap->wr_rate = 2; break; in run_rx_frame()
2976 case 1: tap->wr_rate = 4; break; in run_rx_frame()
2977 case 2: tap->wr_rate = 11; break; in run_rx_frame()
2978 case 3: tap->wr_rate = 22; break; in run_rx_frame()
2981 tap->wr_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; in run_rx_frame()
2985 case 0: tap->wr_rate = 12; break; in run_rx_frame()
2986 case 1: tap->wr_rate = 18; break; in run_rx_frame()
2987 case 2: tap->wr_rate = 24; break; in run_rx_frame()
2988 case 3: tap->wr_rate = 36; break; in run_rx_frame()
2989 case 4: tap->wr_rate = 48; break; in run_rx_frame()
2990 case 5: tap->wr_rate = 72; break; in run_rx_frame()
2991 case 6: tap->wr_rate = 96; break; in run_rx_frame()
2992 case 7: tap->wr_rate = 108; break; in run_rx_frame()
3009 counter_u64_add(ic->ic_ierrors, 1); in run_rx_frame()
3016 struct ieee80211com *ic = &sc->sc_ic; in run_bulk_rx_callback()
3024 if (sc->mac_ver == 0x5592) in run_bulk_rx_callback()
3026 else if (sc->mac_ver == 0x3593) in run_bulk_rx_callback()
3044 m = sc->rx_m; in run_bulk_rx_callback()
3045 sc->rx_m = NULL; in run_bulk_rx_callback()
3050 if (sc->rx_m == NULL) { in run_bulk_rx_callback()
3051 sc->rx_m = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, in run_bulk_rx_callback()
3054 if (sc->rx_m == NULL) { in run_bulk_rx_callback()
3057 "could not allocate mbuf - idle with stall\n"); in run_bulk_rx_callback()
3058 counter_u64_add(ic->ic_ierrors, 1); in run_bulk_rx_callback()
3068 mtod(sc->rx_m, caddr_t), RUN_MAX_RXSZ); in run_bulk_rx_callback()
3079 device_printf(sc->sc_dev, "device timeout\n"); in run_bulk_rx_callback()
3080 counter_u64_add(ic->ic_ierrors, 1); in run_bulk_rx_callback()
3083 if (sc->rx_m != NULL) { in run_bulk_rx_callback()
3084 m_freem(sc->rx_m); in run_bulk_rx_callback()
3085 sc->rx_m = NULL; in run_bulk_rx_callback()
3097 m->m_pkthdr.len = m->m_len = xferlen; in run_bulk_rx_callback()
3103 if ((dmalen >= (uint32_t)-8) || (dmalen == 0) || in run_bulk_rx_callback()
3117 if ((xferlen -= dmalen + 8) <= 8) { in run_bulk_rx_callback()
3118 /* trim 32-bit DMA-len header */ in run_bulk_rx_callback()
3119 m->m_data += 4; in run_bulk_rx_callback()
3120 m->m_pkthdr.len = m->m_len -= 4; in run_bulk_rx_callback()
3130 counter_u64_add(ic->ic_ierrors, 1); in run_bulk_rx_callback()
3139 counter_u64_add(ic->ic_ierrors, 1); in run_bulk_rx_callback()
3142 m_copydata(m, 4 /* skip 32-bit DMA-len header */, in run_bulk_rx_callback()
3144 m0->m_pkthdr.len = m0->m_len = mbuf_len; in run_bulk_rx_callback()
3148 m->m_data += mbuf_len + 4; in run_bulk_rx_callback()
3149 m->m_pkthdr.len = m->m_len -= mbuf_len + 4; in run_bulk_rx_callback()
3166 ieee80211_tx_complete(data->ni, data->m, txerr); in run_tx_free()
3168 data->m = NULL; in run_tx_free()
3169 data->ni = NULL; in run_tx_free()
3171 STAILQ_INSERT_TAIL(&pq->tx_fh, data, next); in run_tx_free()
3172 pq->tx_nfree++; in run_tx_free()
3179 struct ieee80211com *ic = &sc->sc_ic; in run_bulk_tx_callbackN()
3183 struct run_endpoint_queue *pq = &sc->sc_epq[index]; in run_bulk_tx_callbackN()
3203 data = STAILQ_FIRST(&pq->tx_qh); in run_bulk_tx_callbackN()
3207 STAILQ_REMOVE_HEAD(&pq->tx_qh, next); in run_bulk_tx_callbackN()
3209 m = data->m; in run_bulk_tx_callbackN()
3210 size = (sc->mac_ver == 0x5592) ? in run_bulk_tx_callbackN()
3211 sizeof(data->desc) + sizeof(uint32_t) : sizeof(data->desc); in run_bulk_tx_callbackN()
3212 if ((m->m_pkthdr.len + in run_bulk_tx_callbackN()
3215 "data overflow, %u bytes\n", m->m_pkthdr.len); in run_bulk_tx_callbackN()
3221 usbd_copy_in(pc, 0, &data->desc, size); in run_bulk_tx_callbackN()
3222 usbd_m_copy_in(pc, size, m, 0, m->m_pkthdr.len); in run_bulk_tx_callbackN()
3223 size += m->m_pkthdr.len; in run_bulk_tx_callbackN()
3225 * Align end on a 4-byte boundary, pad 8 bytes (CRC + in run_bulk_tx_callbackN()
3226 * 4-byte padding), and be sure to zero those trailing in run_bulk_tx_callbackN()
3229 usbd_frame_zero(pc, size, ((-size) & 3) + 8); in run_bulk_tx_callbackN()
3230 size += ((-size) & 3) + 8; in run_bulk_tx_callbackN()
3232 vap = data->ni->ni_vap; in run_bulk_tx_callbackN()
3235 struct run_tx_radiotap_header *tap = &sc->sc_txtap; in run_bulk_tx_callbackN()
3237 (struct rt2860_txwi *)(&data->desc + sizeof(struct rt2870_txd)); in run_bulk_tx_callbackN()
3244 tap->wt_flags = 0; in run_bulk_tx_callbackN()
3245 tap->wt_rate = rt2860_rates[data->ridx].rate; in run_bulk_tx_callbackN()
3246 tap->wt_hwqueue = index; in run_bulk_tx_callbackN()
3247 if (le16toh(txwi->phy) & RT2860_PHY_SHPRE) in run_bulk_tx_callbackN()
3248 tap->wt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; in run_bulk_tx_callbackN()
3250 tap->wt_flags |= IEEE80211_RADIOTAP_F_DATAPAD; in run_bulk_tx_callbackN()
3257 m->m_pkthdr.len, size, index); in run_bulk_tx_callbackN()
3273 if(data->ni != NULL) in run_bulk_tx_callbackN()
3274 vap = data->ni->ni_vap; in run_bulk_tx_callbackN()
3280 vap = TAILQ_FIRST(&ic->ic_vaps); in run_bulk_tx_callbackN()
3284 device_printf(sc->sc_dev, "device timeout\n"); in run_bulk_tx_callbackN()
3285 uint32_t i = RUN_CMDQ_GET(&sc->cmdq_store); in run_bulk_tx_callbackN()
3288 sc->cmdq[i].func = run_usb_timeout_cb; in run_bulk_tx_callbackN()
3289 sc->cmdq[i].arg0 = vap; in run_bulk_tx_callbackN()
3290 ieee80211_runtask(ic, &sc->cmdq_task); in run_bulk_tx_callbackN()
3306 if (pq->tx_nfree >= RUN_TX_RING_COUNT) { in run_bulk_tx_callbackN()
3353 struct mbuf *m = data->m; in run_set_tx_desc()
3354 struct ieee80211com *ic = &sc->sc_ic; in run_set_tx_desc()
3355 struct ieee80211vap *vap = data->ni->ni_vap; in run_set_tx_desc()
3361 uint8_t ridx = data->ridx; in run_set_tx_desc()
3367 txwisize = (sc->mac_ver == 0x5592) ? in run_set_tx_desc()
3369 xferlen = txwisize + m->m_pkthdr.len; in run_set_tx_desc()
3371 /* roundup to 32-bit alignment */ in run_set_tx_desc()
3374 txd = (struct rt2870_txd *)&data->desc; in run_set_tx_desc()
3375 txd->len = htole16(xferlen); in run_set_tx_desc()
3381 * are nicely aligned to 32-bit. So, no L2 padding. in run_set_tx_desc()
3390 txwi->len = htole16(m->m_pkthdr.len - pad); in run_set_tx_desc()
3394 (ic->ic_flags & IEEE80211_F_SHPREAMBLE)) in run_set_tx_desc()
3402 txwi->phy = htole16(mcs); in run_set_tx_desc()
3404 /* check if RTS/CTS or CTS-to-self protection is required */ in run_set_tx_desc()
3405 if (!IEEE80211_IS_MULTICAST(wh->i_addr1) && in run_set_tx_desc()
3406 ((m->m_pkthdr.len + IEEE80211_CRC_LEN > vap->iv_rtsthreshold) || in run_set_tx_desc()
3407 ((ic->ic_flags & IEEE80211_F_USEPROT) && in run_set_tx_desc()
3409 ((ic->ic_htprotmode == IEEE80211_PROT_RTSCTS) && in run_set_tx_desc()
3411 txwi->txop |= RT2860_TX_TXOP_HT; in run_set_tx_desc()
3413 txwi->txop |= RT2860_TX_TXOP_BACKOFF; in run_set_tx_desc()
3415 if (vap->iv_opmode != IEEE80211_M_STA && !IEEE80211_QOS_HAS_SEQ(wh)) in run_set_tx_desc()
3416 txwi->xflags |= RT2860_TX_NSEQ; in run_set_tx_desc()
3423 struct ieee80211com *ic = &sc->sc_ic; in run_tx()
3424 struct ieee80211vap *vap = ni->ni_vap; in run_tx()
3426 const struct ieee80211_txparam *tp = ni->ni_txparms; in run_tx()
3446 type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK; in run_tx()
3451 * Update 03-14-2009: some devices like the Planex GW-US300MiniS in run_tx()
3472 if (IEEE80211_IS_MULTICAST(wh->i_addr1) || in run_tx()
3473 type != IEEE80211_FC0_TYPE_DATA || m->m_flags & M_EAPOL) { in run_tx()
3475 ridx = (ic->ic_curmode == IEEE80211_MODE_11A || ic->ic_curmode == IEEE80211_MODE_11NA) ? in run_tx()
3479 if (tp->ucastrate != IEEE80211_FIXED_RATE_NONE) in run_tx()
3480 ridx = rn->fix_ridx; in run_tx()
3482 ridx = rn->amrr_ridx; in run_tx()
3486 if (!IEEE80211_IS_MULTICAST(wh->i_addr1) && in run_tx()
3490 if (ic->ic_flags & IEEE80211_F_SHPREAMBLE) in run_tx()
3494 USETW(wh->i_dur, dur); in run_tx()
3498 if (sc->sc_epq[qid].tx_nfree < 3) { in run_tx()
3500 return (-1); in run_tx()
3503 data = STAILQ_FIRST(&sc->sc_epq[qid].tx_fh); in run_tx()
3504 STAILQ_REMOVE_HEAD(&sc->sc_epq[qid].tx_fh, next); in run_tx()
3505 sc->sc_epq[qid].tx_nfree--; in run_tx()
3507 txd = (struct rt2870_txd *)&data->desc; in run_tx()
3508 txd->flags = qflags; in run_tx()
3510 txwi->xflags = xflags; in run_tx()
3511 if (IEEE80211_IS_MULTICAST(wh->i_addr1)) in run_tx()
3512 txwi->wcid = 0; in run_tx()
3514 txwi->wcid = (vap->iv_opmode == IEEE80211_M_STA) ? in run_tx()
3515 1 : RUN_AID2WCID(ni->ni_associd); in run_tx()
3518 txwi->flags = 0; in run_tx()
3519 txwi->txop = 0; in run_tx()
3521 data->m = m; in run_tx()
3522 data->ni = ni; in run_tx()
3523 data->ridx = ridx; in run_tx()
3530 * * TX_STA_CNT0 for all-TX-in-one stats. in run_tx()
3532 * To use FIFO stats, we need to store MCS into the driver-private in run_tx()
3540 if (sc->rvp_cnt > 1 || vap->iv_opmode == IEEE80211_M_HOSTAP || in run_tx()
3541 vap->iv_opmode == IEEE80211_M_MBSS) { in run_tx()
3543 txwi->len |= htole16(pid << RT2860_TX_PID_SHIFT); in run_tx()
3547 * USB devices, so we simulate FIFO-is-full interrupt here. in run_tx()
3557 if (sc->fifo_cnt++ == 10) { in run_tx()
3560 * with a non-sleepable lock, tcpinp. So, need to defer. in run_tx()
3562 uint32_t i = RUN_CMDQ_GET(&sc->cmdq_store); in run_tx()
3564 sc->cmdq[i].func = run_drain_fifo; in run_tx()
3565 sc->cmdq[i].arg0 = sc; in run_tx()
3566 ieee80211_runtask(ic, &sc->cmdq_task); in run_tx()
3570 STAILQ_INSERT_TAIL(&sc->sc_epq[qid].tx_qh, data, next); in run_tx()
3572 usbd_transfer_start(sc->sc_xfer[qid]); in run_tx()
3576 m->m_pkthdr.len + (int)(sizeof(struct rt2870_txd) + in run_tx()
3585 struct ieee80211com *ic = &sc->sc_ic; in run_tx_mgt()
3592 uint8_t ridx = rn->mgt_ridx; in run_tx_mgt()
3603 else if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) { in run_tx_mgt()
3606 dur = ieee80211_ack_duration(ic->ic_rt, rt2860_rates[ridx].rate, in run_tx_mgt()
3607 ic->ic_flags & IEEE80211_F_SHPREAMBLE); in run_tx_mgt()
3608 USETW(wh->i_dur, dur); in run_tx_mgt()
3611 if (sc->sc_epq[0].tx_nfree == 0) in run_tx_mgt()
3614 data = STAILQ_FIRST(&sc->sc_epq[0].tx_fh); in run_tx_mgt()
3615 STAILQ_REMOVE_HEAD(&sc->sc_epq[0].tx_fh, next); in run_tx_mgt()
3616 sc->sc_epq[0].tx_nfree--; in run_tx_mgt()
3618 txd = (struct rt2870_txd *)&data->desc; in run_tx_mgt()
3619 txd->flags = RT2860_TX_QSEL_EDCA; in run_tx_mgt()
3621 txwi->wcid = 0xff; in run_tx_mgt()
3622 txwi->flags = wflags; in run_tx_mgt()
3623 txwi->xflags = xflags; in run_tx_mgt()
3624 txwi->txop = 0; /* clear leftover garbage bits */ in run_tx_mgt()
3626 data->m = m; in run_tx_mgt()
3627 data->ni = ni; in run_tx_mgt()
3628 data->ridx = ridx; in run_tx_mgt()
3633 m->m_pkthdr.len + (int)(sizeof(struct rt2870_txd) + in run_tx_mgt()
3636 STAILQ_INSERT_TAIL(&sc->sc_epq[0].tx_qh, data, next); in run_tx_mgt()
3638 usbd_transfer_start(sc->sc_xfer[0]); in run_tx_mgt()
3647 struct ieee80211com *ic = ni->ni_ic; in run_sendprot()
3660 if (sc->sc_epq[0].tx_nfree == 0) in run_sendprot()
3666 if_inc_counter(ni->ni_vap->iv_ifp, IFCOUNTER_OERRORS, 1); in run_sendprot()
3671 protrate = ieee80211_ctl_rate(ic->ic_rt, rate); in run_sendprot()
3677 data = STAILQ_FIRST(&sc->sc_epq[0].tx_fh); in run_sendprot()
3678 STAILQ_REMOVE_HEAD(&sc->sc_epq[0].tx_fh, next); in run_sendprot()
3679 sc->sc_epq[0].tx_nfree--; in run_sendprot()
3681 txd = (struct rt2870_txd *)&data->desc; in run_sendprot()
3682 txd->flags = RT2860_TX_QSEL_EDCA; in run_sendprot()
3684 txwi->wcid = 0xff; in run_sendprot()
3685 txwi->flags = wflags; in run_sendprot()
3686 txwi->xflags = xflags; in run_sendprot()
3687 txwi->txop = 0; /* clear leftover garbage bits */ in run_sendprot()
3689 data->m = mprot; in run_sendprot()
3690 data->ni = ieee80211_ref_node(ni); in run_sendprot()
3696 data->ridx = ridx; in run_sendprot()
3701 m->m_pkthdr.len, rate); in run_sendprot()
3703 STAILQ_INSERT_TAIL(&sc->sc_epq[0].tx_qh, data, next); in run_sendprot()
3705 usbd_transfer_start(sc->sc_xfer[0]); in run_sendprot()
3714 struct ieee80211com *ic = ni->ni_ic; in run_tx_param()
3728 rate = params->ibp_rate0; in run_tx_param()
3729 if (!ieee80211_isratevalid(ic->ic_rt, rate)) { in run_tx_param()
3734 if ((params->ibp_flags & IEEE80211_BPF_NOACK) == 0) in run_tx_param()
3736 if (params->ibp_flags & (IEEE80211_BPF_RTS|IEEE80211_BPF_CTS)) { in run_tx_param()
3738 params->ibp_flags & IEEE80211_BPF_RTS ? in run_tx_param()
3748 if (sc->sc_epq[0].tx_nfree == 0) { in run_tx_param()
3754 data = STAILQ_FIRST(&sc->sc_epq[0].tx_fh); in run_tx_param()
3755 STAILQ_REMOVE_HEAD(&sc->sc_epq[0].tx_fh, next); in run_tx_param()
3756 sc->sc_epq[0].tx_nfree--; in run_tx_param()
3758 txd = (struct rt2870_txd *)&data->desc; in run_tx_param()
3759 txd->flags = RT2860_TX_QSEL_EDCA; in run_tx_param()
3761 txwi->wcid = 0xff; in run_tx_param()
3762 txwi->xflags = xflags; in run_tx_param()
3763 txwi->txop = opflags; in run_tx_param()
3764 txwi->flags = 0; /* clear leftover garbage bits */ in run_tx_param()
3766 data->m = m; in run_tx_param()
3767 data->ni = ni; in run_tx_param()
3772 data->ridx = ridx; in run_tx_param()
3777 m->m_pkthdr.len, rate); in run_tx_param()
3779 STAILQ_INSERT_TAIL(&sc->sc_epq[0].tx_qh, data, next); in run_tx_param()
3781 usbd_transfer_start(sc->sc_xfer[0]); in run_tx_param()
3790 struct run_softc *sc = ni->ni_ic->ic_softc; in run_raw_xmit()
3796 if (!(sc->sc_flags & RUN_RUNNING)) { in run_raw_xmit()
3829 struct run_softc *sc = ic->ic_softc; in run_transmit()
3833 if ((sc->sc_flags & RUN_RUNNING) == 0) { in run_transmit()
3837 error = mbufq_enqueue(&sc->sc_snd, m); in run_transmit()
3856 if ((sc->sc_flags & RUN_RUNNING) == 0) in run_start()
3859 while ((m = mbufq_dequeue(&sc->sc_snd)) != NULL) { in run_start()
3860 ni = (struct ieee80211_node *)m->m_pkthdr.rcvif; in run_start()
3862 mbufq_prepend(&sc->sc_snd, m); in run_start()
3871 struct run_softc *sc = ic->ic_softc; in run_parent()
3875 if (sc->sc_detached) { in run_parent()
3880 if (ic->ic_nrunning > 0) { in run_parent()
3881 if (!(sc->sc_flags & RUN_RUNNING)) { in run_parent()
3886 } else if ((sc->sc_flags & RUN_RUNNING) && sc->rvp_cnt <= 1) in run_parent()
3999 if (sc->mac_ver == 0x3572) { in run_set_agc()
4016 run_bbp_write(sc, 62, 0x37 - sc->lna[group]); in run_select_chan_group()
4017 run_bbp_write(sc, 63, 0x37 - sc->lna[group]); in run_select_chan_group()
4018 run_bbp_write(sc, 64, 0x37 - sc->lna[group]); in run_select_chan_group()
4019 if (sc->mac_ver < 0x3572) in run_select_chan_group()
4022 if (sc->mac_ver == 0x3593) { in run_select_chan_group()
4028 if (sc->ext_2ghz_lna) { in run_select_chan_group()
4029 if (sc->mac_ver >= 0x5390) in run_select_chan_group()
4036 if (sc->mac_ver == 0x5592) { in run_select_chan_group()
4054 } else if (sc->mac_ver >= 0x5390) in run_select_chan_group()
4058 (sc->mac_ver == 0x3593) ? 0x62 : 0x84); in run_select_chan_group()
4063 if (sc->mac_ver == 0x5592) { in run_select_chan_group()
4081 } else if (sc->mac_ver == 0x3572) in run_select_chan_group()
4085 (sc->mac_ver == 0x3593) ? 0x82 : 0xf2); in run_select_chan_group()
4086 if (sc->ext_5ghz_lna) in run_select_chan_group()
4099 if (sc->mac_ver == 0x3593) in run_select_chan_group()
4101 if (sc->nrxchains > 1) in run_select_chan_group()
4105 if (sc->ntxchains > 1) in run_select_chan_group()
4107 if (sc->mac_ver == 0x3593) { in run_select_chan_group()
4108 if (sc->ntxchains > 2) in run_select_chan_group()
4113 if (sc->ntxchains > 1) in run_select_chan_group()
4116 if (sc->mac_ver == 0x3572) { in run_select_chan_group()
4123 if (sc->mac_ver == 0x5592) { in run_select_chan_group()
4128 if (sc->mac_ver == 0x3593) { in run_select_chan_group()
4139 if (sc->mac_ver >= 0x3070) in run_select_chan_group()
4140 agc = 0x1c + sc->lna[0] * 2; in run_select_chan_group()
4142 agc = 0x2e + sc->lna[0]; in run_select_chan_group()
4144 if (sc->mac_ver == 0x5592) in run_select_chan_group()
4145 agc = 0x24 + sc->lna[group] * 2; in run_select_chan_group()
4146 else if (sc->mac_ver == 0x3572 || sc->mac_ver == 0x3593) in run_select_chan_group()
4147 agc = 0x22 + (sc->lna[group] * 5) / 3; in run_select_chan_group()
4149 agc = 0x32 + (sc->lna[group] * 5) / 3; in run_select_chan_group()
4166 if (sc->ntxchains == 1) in run_rt2870_set_chan()
4168 if (sc->nrxchains == 1) in run_rt2870_set_chan()
4170 else if (sc->nrxchains == 2) in run_rt2870_set_chan()
4174 txpow1 = sc->txpow1[i]; in run_rt2870_set_chan()
4175 txpow2 = sc->txpow2[i]; in run_rt2870_set_chan()
4179 r4 = (rfprog[i].r4 & ~(0x001f87c0)) | (sc->freq << 15); in run_rt2870_set_chan()
4236 txpow1 = sc->txpow1[i]; in run_rt3070_set_chan()
4237 txpow2 = sc->txpow2[i]; in run_rt3070_set_chan()
4262 if (sc->ntxchains == 1) in run_rt3070_set_chan()
4264 else if (sc->ntxchains == 2) in run_rt3070_set_chan()
4266 if (sc->nrxchains == 1) in run_rt3070_set_chan()
4268 else if (sc->nrxchains == 2) in run_rt3070_set_chan()
4274 rf = (rf & ~0x7f) | sc->freq; in run_rt3070_set_chan()
4279 rf = (rf & ~0x3f) | sc->rf24_20mhz; in run_rt3070_set_chan()
4282 rf = (rf & ~0x3f) | sc->rf24_20mhz; in run_rt3070_set_chan()
4302 txpow1 = sc->txpow1[i]; in run_rt3572_set_chan()
4303 txpow2 = sc->txpow2[i]; in run_rt3572_set_chan()
4306 run_bbp_write(sc, 25, sc->bbp25); in run_rt3572_set_chan()
4307 run_bbp_write(sc, 26, sc->bbp26); in run_rt3572_set_chan()
4344 if (sc->ntxchains == 1) in run_rt3572_set_chan()
4346 else if (sc->ntxchains == 2) in run_rt3572_set_chan()
4348 if (sc->nrxchains == 1) in run_rt3572_set_chan()
4350 else if (sc->nrxchains == 2) in run_rt3572_set_chan()
4356 rf = (rf & ~0x7f) | sc->freq; in run_rt3572_set_chan()
4360 rf = sc->rf24_20mhz; in run_rt3572_set_chan()
4382 rf = 0x48 | sc->txmixgain_2ghz; in run_rt3572_set_chan()
4384 rf = 0x78 | sc->txmixgain_5ghz; in run_rt3572_set_chan()
4451 txpow1 = sc->txpow1[i]; in run_rt3593_set_chan()
4452 txpow2 = sc->txpow2[i]; in run_rt3593_set_chan()
4453 txpow3 = (sc->ntxchains == 3) ? sc->txpow3[i] : 0; in run_rt3593_set_chan()
4456 run_bbp_write(sc, 25, sc->bbp25); in run_rt3593_set_chan()
4457 run_bbp_write(sc, 26, sc->bbp26); in run_rt3593_set_chan()
4495 if (sc->ntxchains == 3) in run_rt3593_set_chan()
4506 h20mhz = (sc->rf24_20mhz & 0x20) >> 5; in run_rt3593_set_chan()
4611 txpow1 = sc->txpow1[i]; in run_rt5390_set_chan()
4612 txpow2 = sc->txpow2[i]; in run_rt5390_set_chan()
4627 if (sc->mac_ver == 0x5392) { in run_rt5390_set_chan()
4638 if (sc->mac_ver == 0x5392) in run_rt5390_set_chan()
4642 if (sc->mac_ver != 0x5392) { in run_rt5390_set_chan()
4653 if (sc->mac_ver == 0x5392) { in run_rt5390_set_chan()
4655 if (sc->mac_rev >= 0x0223) { in run_rt5390_set_chan()
4684 if (sc->mac_rev >= 0x0502) { in run_rt5390_set_chan()
4727 txpow1 = sc->txpow1[i]; in run_rt5592_set_chan()
4728 txpow2 = sc->txpow2[i]; in run_rt5592_set_chan()
4737 run_rt3070_rf_write(sc, 8, freqs->n & 0xff); in run_rt5592_set_chan()
4740 rf |= ((freqs->n & 0x0100) >> 8) << 4; in run_rt5592_set_chan()
4746 rf |= (freqs->k & 0x0f); in run_rt5592_set_chan()
4752 rf |= ((freqs->m - 0x8) & 0x3) << 2; in run_rt5592_set_chan()
4756 rf |= (((freqs->m - 0x8) & 0x4) >> 2) << 7; in run_rt5592_set_chan()
4762 rf |= (freqs->r - 0x1); in run_rt5592_set_chan()
4780 * G-band bit<7:6>=1:0, bit<5:0> range from 0x0 ~ 0x27. in run_rt5592_set_chan()
4800 * A-band bit<7:6>=1:1, bit<5:0> range from 0x0 ~ 0x2b. in run_rt5592_set_chan()
4827 if (sc->ntxchains > 1) in run_rt5592_set_chan()
4829 if (sc->nrxchains > 1) in run_rt5592_set_chan()
4854 if (sc->rf_rev == RT5390_RF_5370) { in run_set_rx_antenna()
4863 if (sc->rf_rev == RT5390_RF_5370) { in run_set_rx_antenna()
4877 struct ieee80211com *ic = &sc->sc_ic; in run_set_chan()
4884 if (sc->mac_ver == 0x5592) in run_set_chan()
4886 else if (sc->mac_ver >= 0x5390) in run_set_chan()
4888 else if (sc->mac_ver == 0x3593) in run_set_chan()
4890 else if (sc->mac_ver == 0x3572) in run_set_chan()
4892 else if (sc->mac_ver >= 0x3070) in run_set_chan()
4913 if (sc->mac_ver >= 0x5392) in run_set_chan()
4922 struct run_softc *sc = ic->ic_softc; in run_set_channel()
4925 run_set_chan(sc, ic->ic_curchan); in run_set_channel()
4935 struct run_softc *sc = ic->ic_softc; in run_getradiocaps()
4941 if (sc->rf_rev != RT3070_RF_2020) in run_getradiocaps()
4947 if (sc->rf_rev == RT2860_RF_2750 || sc->rf_rev == RT2860_RF_2850 || in run_getradiocaps()
4948 sc->rf_rev == RT3070_RF_3052 || sc->rf_rev == RT3593_RF_3053 || in run_getradiocaps()
4949 sc->rf_rev == RT5592_RF_5592) { in run_getradiocaps()
4951 if (sc->rf_rev != RT3070_RF_2020) in run_getradiocaps()
4962 struct run_softc *sc = ic->ic_softc; in run_scan_start()
4978 struct run_softc *sc = ic->ic_softc; in run_scan_end()
4983 run_set_bssid(sc, sc->sc_bssid); in run_scan_end()
4992 * (non-sleepable thread)
4997 struct ieee80211com *ic = vap->iv_ic; in run_update_beacon()
4998 struct ieee80211_beacon_offsets *bo = &vap->iv_bcn_off; in run_update_beacon()
4999 struct ieee80211_node *ni = vap->iv_bss; in run_update_beacon()
5000 struct run_softc *sc = ic->ic_softc; in run_update_beacon()
5019 setbit(bo->bo_flags, item); in run_update_beacon()
5020 if (rvp->beacon_mbuf == NULL) { in run_update_beacon()
5021 rvp->beacon_mbuf = ieee80211_beacon_alloc(ni); in run_update_beacon()
5022 if (rvp->beacon_mbuf == NULL) in run_update_beacon()
5025 ieee80211_beacon_update(ni, rvp->beacon_mbuf, mcast); in run_update_beacon()
5027 i = RUN_CMDQ_GET(&sc->cmdq_store); in run_update_beacon()
5029 sc->cmdq[i].func = run_update_beacon_cb; in run_update_beacon()
5030 sc->cmdq[i].arg0 = vap; in run_update_beacon()
5031 ieee80211_runtask(ic, &sc->cmdq_task); in run_update_beacon()
5040 struct ieee80211_node *ni = vap->iv_bss; in run_update_beacon_cb()
5042 struct ieee80211com *ic = vap->iv_ic; in run_update_beacon_cb()
5043 struct run_softc *sc = ic->ic_softc; in run_update_beacon_cb()
5049 if (ni->ni_chan == IEEE80211_CHAN_ANYC) in run_update_beacon_cb()
5051 if (ic->ic_bsschan == IEEE80211_CHAN_ANYC) in run_update_beacon_cb()
5058 if (rvp->beacon_mbuf == NULL) { in run_update_beacon_cb()
5059 rvp->beacon_mbuf = ieee80211_beacon_alloc(ni); in run_update_beacon_cb()
5060 if (rvp->beacon_mbuf == NULL) in run_update_beacon_cb()
5063 m = rvp->beacon_mbuf; in run_update_beacon_cb()
5067 txwi.len = htole16(m->m_pkthdr.len); in run_update_beacon_cb()
5070 ridx = (ic->ic_curmode == IEEE80211_MODE_11A) ? in run_update_beacon_cb()
5079 txwisize = (sc->mac_ver == 0x5592) ? in run_update_beacon_cb()
5081 run_write_region_1(sc, RT2860_BCN_BASE(rvp->rvp_id), (uint8_t *)&txwi, in run_update_beacon_cb()
5083 run_write_region_1(sc, RT2860_BCN_BASE(rvp->rvp_id) + txwisize, in run_update_beacon_cb()
5084 mtod(m, uint8_t *), (m->m_pkthdr.len + 1) & ~1); in run_update_beacon_cb()
5090 struct run_softc *sc = ic->ic_softc; in run_updateprot()
5093 i = RUN_CMDQ_GET(&sc->cmdq_store); in run_updateprot()
5095 sc->cmdq[i].func = run_updateprot_cb; in run_updateprot()
5096 sc->cmdq[i].arg0 = ic; in run_updateprot()
5097 ieee80211_runtask(ic, &sc->cmdq_task); in run_updateprot()
5104 struct run_softc *sc = ic->ic_softc; in run_updateprot_cb()
5109 tmp |= (ic->ic_curmode == IEEE80211_MODE_11A) ? in run_updateprot_cb()
5115 if (ic->ic_flags & IEEE80211_F_USEPROT) { in run_updateprot_cb()
5116 if (ic->ic_protmode == IEEE80211_PROT_RTSCTS) in run_updateprot_cb()
5118 else if (ic->ic_protmode == IEEE80211_PROT_CTSONLY) in run_updateprot_cb()
5128 struct run_softc *sc = vap->iv_ic->ic_softc; in run_usb_timeout_cb()
5132 if(vap->iv_state == IEEE80211_S_RUN && in run_usb_timeout_cb()
5133 vap->iv_opmode != IEEE80211_M_STA) in run_usb_timeout_cb()
5135 else if (vap->iv_state == IEEE80211_S_SCAN) { in run_usb_timeout_cb()
5154 * can run into a livelock and start sending CTS-to-self frames like in run_reset_livelock()
5161 "CTS-to-self livelock detected\n"); in run_reset_livelock()
5177 if (sc->sc_ic.ic_promisc > 0) in run_update_promisc_locked()
5183 (sc->sc_ic.ic_promisc > 0) ? "entering" : "leaving"); in run_update_promisc_locked()
5189 struct run_softc *sc = ic->ic_softc; in run_update_promisc()
5191 if ((sc->sc_flags & RUN_RUNNING) == 0) in run_update_promisc()
5202 struct ieee80211com *ic = &sc->sc_ic; in run_enable_tsf_sync()
5203 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); in run_enable_tsf_sync()
5207 RUN_VAP(vap)->rvp_id, ic->ic_opmode); in run_enable_tsf_sync()
5211 tmp |= vap->iv_bss->ni_intval * 16; in run_enable_tsf_sync()
5214 if (ic->ic_opmode == IEEE80211_M_STA) { in run_enable_tsf_sync()
5220 } else if (ic->ic_opmode == IEEE80211_M_IBSS) { in run_enable_tsf_sync()
5227 } else if (ic->ic_opmode == IEEE80211_M_HOSTAP || in run_enable_tsf_sync()
5228 ic->ic_opmode == IEEE80211_M_MBSS) { in run_enable_tsf_sync()
5278 OFDM(6) << 28 | /* 54->48 */ in run_enable_mrr()
5279 OFDM(5) << 24 | /* 48->36 */ in run_enable_mrr()
5280 OFDM(4) << 20 | /* 36->24 */ in run_enable_mrr()
5281 OFDM(3) << 16 | /* 24->18 */ in run_enable_mrr()
5282 OFDM(2) << 12 | /* 18->12 */ in run_enable_mrr()
5283 OFDM(1) << 8 | /* 12-> 9 */ in run_enable_mrr()
5284 OFDM(0) << 4 | /* 9-> 6 */ in run_enable_mrr()
5285 OFDM(0)); /* 6-> 6 */ in run_enable_mrr()
5288 CCK(2) << 12 | /* 11->5.5 */ in run_enable_mrr()
5289 CCK(1) << 8 | /* 5.5-> 2 */ in run_enable_mrr()
5290 CCK(0) << 4 | /* 2-> 1 */ in run_enable_mrr()
5291 CCK(0)); /* 1-> 1 */ in run_enable_mrr()
5299 struct ieee80211com *ic = &sc->sc_ic; in run_set_txpreamble()
5303 if (ic->ic_flags & IEEE80211_F_SHPREAMBLE) in run_set_txpreamble()
5313 struct ieee80211com *ic = &sc->sc_ic; in run_set_basicrates()
5316 if (ic->ic_curmode == IEEE80211_MODE_11B) in run_set_basicrates()
5318 else if (ic->ic_curmode == IEEE80211_MODE_11A) in run_set_basicrates()
5328 which | (sc->leds & 0x7f)); in run_set_leds()
5352 struct run_softc *sc = ic->ic_softc; in run_updateslot()
5355 i = RUN_CMDQ_GET(&sc->cmdq_store); in run_updateslot()
5357 sc->cmdq[i].func = run_updateslot_cb; in run_updateslot()
5358 sc->cmdq[i].arg0 = ic; in run_updateslot()
5359 ieee80211_runtask(ic, &sc->cmdq_task); in run_updateslot()
5369 struct run_softc *sc = ic->ic_softc; in run_updateslot_cb()
5386 struct ieee80211com *ic = &sc->sc_ic; in run_rssi2dbm()
5387 struct ieee80211_channel *c = ic->ic_curchan; in run_rssi2dbm()
5388 int delta; in run_rssi2dbm() local
5392 delta = sc->rssi_5ghz[rxchain]; in run_rssi2dbm()
5396 delta -= sc->lna[1]; in run_rssi2dbm()
5398 delta -= sc->lna[2]; in run_rssi2dbm()
5400 delta -= sc->lna[3]; in run_rssi2dbm()
5402 delta = sc->rssi_2ghz[rxchain] - sc->lna[0]; in run_rssi2dbm()
5404 return (-12 - delta - rssi); in run_rssi2dbm()
5415 if (sc->nrxchains > 1) in run_rt5390_bbp_init()
5422 if (sc->mac_ver == 0x5592) { in run_rt5390_bbp_init()
5437 if (sc->mac_ver == 0x5392) { in run_rt5390_bbp_init()
5451 if (sc->mac_ver == 0x5592 && sc->mac_rev >= 0x0221) { in run_rt5390_bbp_init()
5457 if (sc->mac_ver == 0x5390) in run_rt5390_bbp_init()
5482 if (sc->mac_ver >= 0x5390) in run_bbp_init()
5491 if (sc->mac_ver == 0x3593) { in run_bbp_init()
5500 if (sc->mac_ver == 0x2860 && sc->mac_rev != 0x0101) in run_bbp_init()
5503 if (sc->mac_ver >= 0x3070 && (sc->mac_ver != 0x3593 && in run_bbp_init()
5504 sc->mac_ver != 0x5592)) { in run_bbp_init()
5508 } else if (sc->mac_ver == 0x2860 && sc->mac_rev == 0x0100) { in run_bbp_init()
5529 if (sc->mac_ver == 0x3572) { in run_rt3070_rf_init()
5541 if (sc->mac_ver == 0x3070 && sc->mac_rev < 0x0201) { in run_rt3070_rf_init()
5551 } else if (sc->mac_ver == 0x3071) { in run_rt3070_rf_init()
5558 if (sc->mac_rev < 0x0211) in run_rt3070_rf_init()
5568 } else if (sc->mac_ver == 0x3572) { in run_rt3070_rf_init()
5577 if (sc->mac_rev < 0x0211 || !sc->patch_dac) { in run_rt3070_rf_init()
5590 sc->rf24_20mhz = 0x1f; /* default value */ in run_rt3070_rf_init()
5591 target = (sc->mac_ver < 0x3071) ? 0x16 : 0x13; in run_rt3070_rf_init()
5592 run_rt3070_filter_calib(sc, 0x07, target, &sc->rf24_20mhz); in run_rt3070_rf_init()
5601 sc->rf24_40mhz = 0x2f; /* default value */ in run_rt3070_rf_init()
5602 target = (sc->mac_ver < 0x3071) ? 0x19 : 0x15; in run_rt3070_rf_init()
5603 run_rt3070_filter_calib(sc, 0x27, target, &sc->rf24_40mhz); in run_rt3070_rf_init()
5609 if (sc->mac_ver == 0x3572) { in run_rt3070_rf_init()
5611 run_bbp_read(sc, 25, &sc->bbp25); in run_rt3070_rf_init()
5612 run_bbp_read(sc, 26, &sc->bbp26); in run_rt3070_rf_init()
5613 } else if (sc->mac_rev < 0x0201 || sc->mac_rev < 0x0211) in run_rt3070_rf_init()
5619 if (sc->mac_ver == 0x3070 || sc->mac_ver == 0x3071) { in run_rt3070_rf_init()
5622 if ((sc->mac_ver == 0x3070 || in run_rt3070_rf_init()
5623 (sc->mac_ver == 0x3071 && sc->mac_rev >= 0x0211)) && in run_rt3070_rf_init()
5624 !sc->ext_2ghz_lna) in run_rt3070_rf_init()
5626 mingain = (sc->mac_ver == 0x3070) ? 1 : 2; in run_rt3070_rf_init()
5627 if (sc->txmixgain_2ghz >= mingain) in run_rt3070_rf_init()
5628 rf = (rf & ~0x7) | sc->txmixgain_2ghz; in run_rt3070_rf_init()
5632 if (sc->mac_ver == 0x3071) { in run_rt3070_rf_init()
5648 if (sc->mac_ver == 0x3070 || sc->mac_ver == 0x3071) { in run_rt3070_rf_init()
5652 if (sc->mac_rev < 0x0211) in run_rt3070_rf_init()
5697 sc->rf24_20mhz = 0x1f; in run_rt3593_rf_init()
5698 sc->rf24_40mhz = 0x2f; in run_rt3593_rf_init()
5701 run_bbp_read(sc, 25, &sc->bbp25); in run_rt3593_rf_init()
5702 run_bbp_read(sc, 26, &sc->bbp26); in run_rt3593_rf_init()
5716 if (sc->mac_ver == 0x5390) { in run_rt5390_rf_init()
5727 if (sc->mac_ver == 0x5592) { in run_rt5390_rf_init()
5734 } else if (sc->mac_ver == 0x5392) { in run_rt5390_rf_init()
5739 if (sc->mac_rev >= 0x0223) { in run_rt5390_rf_init()
5752 if (sc->mac_rev >= 0x0502) { in run_rt5390_rf_init()
5762 sc->rf24_20mhz = 0x1f; /* default value */ in run_rt5390_rf_init()
5763 sc->rf24_40mhz = (sc->mac_ver == 0x5592) ? 0 : 0x2f; in run_rt5390_rf_init()
5765 if (sc->mac_rev < 0x0211) in run_rt5390_rf_init()
5777 uint8_t bbp55_pb, bbp55_sb, delta; in run_rt3070_filter_calib() local
5812 delta = bbp55_pb - bbp55_sb; in run_rt3070_filter_calib()
5813 if (delta > target) in run_rt3070_filter_calib()
5822 rf24--; /* backtrack */ in run_rt3070_filter_calib()
5843 if (sc->mac_ver == 0x3572) { in run_rt3070_rf_setup()
5845 if (sc->mac_rev >= 0x0201) in run_rt3070_rf_setup()
5849 if (sc->ntxchains == 1) in run_rt3070_rf_setup()
5851 if (sc->nrxchains == 1) in run_rt3070_rf_setup()
5855 if (sc->mac_rev >= 0x0211) { in run_rt3070_rf_setup()
5862 rf = (rf & ~0x07) | sc->txmixgain_2ghz; in run_rt3070_rf_setup()
5865 } else if (sc->mac_ver == 0x3071) { in run_rt3070_rf_setup()
5866 if (sc->mac_rev >= 0x0211) { in run_rt3070_rf_setup()
5876 if (sc->ntxchains == 1) in run_rt3070_rf_setup()
5878 if (sc->nrxchains == 1) in run_rt3070_rf_setup()
5883 if (sc->mac_rev < 0x0211) { in run_rt3070_rf_setup()
5885 sc->patch_dac ? 0x2c : 0x0f); in run_rt3070_rf_setup()
5889 } else if (sc->mac_ver == 0x3070) { in run_rt3070_rf_setup()
5890 if (sc->mac_rev >= 0x0201) { in run_rt3070_rf_setup()
5899 if (sc->mac_rev < 0x0201) { in run_rt3070_rf_setup()
5907 if (sc->mac_ver >= 0x3071) { in run_rt3070_rf_setup()
5909 if (sc->rf[i].reg == 0 || sc->rf[i].reg == 0xff) in run_rt3070_rf_setup()
5911 run_rt3070_rf_write(sc, sc->rf[i].reg, sc->rf[i].val); in run_rt3070_rf_setup()
5921 if (sc->mac_rev >= 0x0211) { in run_rt3593_rf_setup()
5926 if (sc->mac_rev < 0x0211) { in run_rt3593_rf_setup()
5928 sc->patch_dac ? 0x2c : 0x0f); in run_rt3593_rf_setup()
5937 ((sc->txmixgain_2ghz & 0x07) << 2); in run_rt3593_rf_setup()
5955 if (sc->nrxchains > 1) in run_rt3593_rf_setup()
5991 if (sc->mac_rev >= 0x0211) { in run_rt5390_rf_setup()
5995 if (sc->mac_ver != 0x5592) { in run_rt5390_rf_setup()
6003 if (sc->ntxchains == 1) in run_rt5390_rf_setup()
6005 if (sc->nrxchains == 1) in run_rt5390_rf_setup()
6023 if (sc->mac_ver != 0x5592) { in run_rt5390_rf_setup()
6025 if (sc->mac_rev < 0x0211) { in run_rt5390_rf_setup()
6027 sc->patch_dac ? 0x2c : 0x0f); in run_rt5390_rf_setup()
6036 struct ieee80211com *ic = &sc->sc_ic; in run_txrx_enable()
6063 if (ic->ic_opmode != IEEE80211_M_MONITOR) { in run_txrx_enable()
6068 if (ic->ic_opmode == IEEE80211_M_STA) in run_txrx_enable()
6086 rf = (rf & ~0x7f) | (sc->freq & 0x7f); in run_adjust_freq_offset()
6096 struct ieee80211com *ic = &sc->sc_ic; in run_init_locked()
6097 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); in run_init_locked()
6104 if (ic->ic_nrunning > 1) in run_init_locked()
6110 device_printf(sc->sc_dev, "could not load 8051 microcode\n"); in run_init_locked()
6125 run_setup_tx_list(sc, &sc->sc_epq[i]); in run_init_locked()
6127 run_set_macaddr(sc, vap ? vap->iv_myaddr : ic->ic_macaddr); in run_init_locked()
6137 device_printf(sc->sc_dev, "timeout waiting for DMA engine\n"); in run_init_locked()
6144 /* turn off PME_OEN to solve high-current issue */ in run_init_locked()
6153 device_printf(sc->sc_dev, "could not reset chipset\n"); in run_init_locked()
6161 if (sc->txpow20mhz[ridx] == 0xffffffff) in run_init_locked()
6163 run_write(sc, RT2860_TX_PWR_CFG(ridx), sc->txpow20mhz[ridx]); in run_init_locked()
6172 if (sc->mac_ver >= 0x5390) { in run_init_locked()
6175 if (sc->mac_ver >= 0x5392) { in run_init_locked()
6177 if (sc->mac_ver == 0x5592) { in run_init_locked()
6185 } else if (sc->mac_ver == 0x3593) { in run_init_locked()
6188 } else if (sc->mac_ver >= 0x3070) { in run_init_locked()
6211 device_printf(sc->sc_dev, "could not initialize BBP\n"); in run_init_locked()
6224 if (sc->cmdq_key_set != RUN_CMDQ_GO) { in run_init_locked()
6235 if (sc->mac_rev != 0x0101) in run_init_locked()
6241 /* write vendor-specific BBP values (from EEPROM) */ in run_init_locked()
6242 if (sc->mac_ver < 0x3593) { in run_init_locked()
6244 if (sc->bbp[i].reg == 0 || sc->bbp[i].reg == 0xff) in run_init_locked()
6246 run_bbp_write(sc, sc->bbp[i].reg, sc->bbp[i].val); in run_init_locked()
6251 if (sc->rf_rev == RT3070_RF_3020 || sc->rf_rev == RT5390_RF_5370) in run_init_locked()
6255 (void)run_mcu_cmd(sc, RT2860_MCU_CMD_LED1, sc->led[0]); in run_init_locked()
6256 (void)run_mcu_cmd(sc, RT2860_MCU_CMD_LED2, sc->led[1]); in run_init_locked()
6257 (void)run_mcu_cmd(sc, RT2860_MCU_CMD_LED3, sc->led[2]); in run_init_locked()
6259 if (sc->mac_ver >= 0x5390) in run_init_locked()
6261 else if (sc->mac_ver == 0x3593) in run_init_locked()
6263 else if (sc->mac_ver >= 0x3070) in run_init_locked()
6266 /* disable non-existing Rx chains */ in run_init_locked()
6269 if (sc->nrxchains == 2) in run_init_locked()
6271 else if (sc->nrxchains == 3) in run_init_locked()
6275 /* disable non-existing Tx chains */ in run_init_locked()
6277 if (sc->ntxchains == 1) in run_init_locked()
6281 if (sc->mac_ver >= 0x5390) in run_init_locked()
6283 else if (sc->mac_ver == 0x3593) in run_init_locked()
6285 else if (sc->mac_ver >= 0x3070) in run_init_locked()
6289 run_set_chan(sc, ic->ic_curchan); in run_init_locked()
6301 sc->sc_flags |= RUN_RUNNING; in run_init_locked()
6302 sc->cmdq_run = RUN_CMDQ_GO; in run_init_locked()
6305 usbd_xfer_set_stall(sc->sc_xfer[i]); in run_init_locked()
6307 usbd_transfer_start(sc->sc_xfer[RUN_BULK_RX]); in run_init_locked()
6328 if (sc->sc_flags & RUN_RUNNING) in run_stop()
6331 sc->sc_flags &= ~RUN_RUNNING; in run_stop()
6333 sc->ratectl_run = RUN_RATECTL_OFF; in run_stop()
6334 sc->cmdq_run = sc->cmdq_key_set; in run_stop()
6339 usbd_transfer_drain(sc->sc_xfer[i]); in run_stop()
6345 if (sc->rx_m != NULL) { in run_stop()
6346 m_free(sc->rx_m); in run_stop()
6347 sc->rx_m = NULL; in run_stop()
6364 device_printf(sc->sc_dev, "timeout waiting for DMA engine\n"); in run_stop()
6397 run_unsetup_tx_list(sc, &sc->sc_epq[i]); in run_stop()
6403 usb_pause_mtx(mtx_owned(&sc->sc_mtx) ? in run_delay()
6404 &sc->sc_mtx : NULL, USB_MS_TO_TICKS(ms)); in run_delay()
6418 /* For now, no A-MPDU TX support in the driver */ in run_ampdu_enable()