Lines Matching +full:vco +full:- +full:offset

1 /*-
5 * Copyright (c) 2013-2014 Kevin Lo
20 /*-
114 device_printf((_sc)->sc_dev, __VA_ARGS__); \
530 /* MCS - single stream */
540 /* MCS - 2 streams */
550 /* MCS - 3 streams */
731 if (uaa->dev_state != UAA_DEV_READY) in run_autoinst()
737 id = iface->idesc; in run_autoinst()
738 if (id == NULL || id->bInterfaceClass != UICLASS_MASS) in run_autoinst()
744 uaa->dev_state = UAA_DEV_EJECTING; in run_autoinst()
769 if (uaa->usb_mode != USB_MODE_HOST) in run_match()
771 if (uaa->info.bConfigIndex != 0) in run_match()
773 if (uaa->info.bIfaceIndex != RT2860_IFACE_INDEX) in run_match()
784 struct ieee80211com *ic = &sc->sc_ic; in run_attach()
790 sc->sc_udev = uaa->device; in run_attach()
791 sc->sc_dev = self; in run_attach()
793 sc->sc_flags |= RUN_FLAG_FWLOAD_NEEDED; in run_attach()
795 mtx_init(&sc->sc_mtx, device_get_nameunit(sc->sc_dev), in run_attach()
797 mbufq_init(&sc->sc_snd, ifqmaxlen); in run_attach()
801 error = usbd_transfer_setup(uaa->device, &iface_index, in run_attach()
802 sc->sc_xfer, run_config, RUN_N_XFER, sc, &sc->sc_mtx); in run_attach()
822 device_printf(sc->sc_dev, in run_attach()
827 sc->mac_ver = ver >> 16; in run_attach()
828 sc->mac_rev = ver & 0xffff; in run_attach()
833 device_printf(sc->sc_dev, in run_attach()
835 sc->mac_ver, sc->mac_rev, run_get_rf(sc->rf_rev), in run_attach()
836 sc->ntxchains, sc->nrxchains, ether_sprintf(ic->ic_macaddr)); in run_attach()
840 ic->ic_softc = sc; in run_attach()
841 ic->ic_name = device_get_nameunit(self); in run_attach()
842 ic->ic_phytype = IEEE80211_T_OFDM; /* not only, but not used */ in run_attach()
843 ic->ic_opmode = IEEE80211_M_STA; /* default to BSS mode */ in run_attach()
846 ic->ic_caps = in run_attach()
851 IEEE80211_C_WDS | /* 4-address traffic works */ in run_attach()
855 IEEE80211_C_SWAMSDUTX | /* Do software A-MSDU TX */ in run_attach()
856 IEEE80211_C_FF | /* Atheros fast-frames */ in run_attach()
863 if (sc->rf_rev != RT3070_RF_2020) { in run_attach()
864 device_printf(sc->sc_dev, "[HT] Enabling 802.11n\n"); in run_attach()
865 ic->ic_htcaps = in run_attach()
872 ic->ic_rxstream = sc->nrxchains; in run_attach()
873 ic->ic_txstream = sc->ntxchains; in run_attach()
876 ic->ic_cryptocaps = in run_attach()
882 ic->ic_flags |= IEEE80211_F_DATAPAD; in run_attach()
883 ic->ic_flags_ext |= IEEE80211_FEXT_SWBMISS; in run_attach()
885 run_getradiocaps(ic, IEEE80211_CHAN_MAX, &ic->ic_nchans, in run_attach()
886 ic->ic_channels); in run_attach()
890 ic->ic_scan_start = run_scan_start; in run_attach()
891 ic->ic_scan_end = run_scan_end; in run_attach()
892 ic->ic_set_channel = run_set_channel; in run_attach()
893 ic->ic_getradiocaps = run_getradiocaps; in run_attach()
894 ic->ic_node_alloc = run_node_alloc; in run_attach()
895 ic->ic_newassoc = run_newassoc; in run_attach()
896 ic->ic_updateslot = run_updateslot; in run_attach()
897 ic->ic_update_mcast = run_update_mcast; in run_attach()
898 ic->ic_wme.wme_update = run_wme_update; in run_attach()
899 ic->ic_raw_xmit = run_raw_xmit; in run_attach()
900 ic->ic_update_promisc = run_update_promisc; in run_attach()
901 ic->ic_vap_create = run_vap_create; in run_attach()
902 ic->ic_vap_delete = run_vap_delete; in run_attach()
903 ic->ic_transmit = run_transmit; in run_attach()
904 ic->ic_parent = run_parent; in run_attach()
905 ic->ic_update_chw = run_update_chw; in run_attach()
906 ic->ic_ampdu_enable = run_ampdu_enable; in run_attach()
909 &sc->sc_txtap.wt_ihdr, sizeof(sc->sc_txtap), in run_attach()
911 &sc->sc_rxtap.wr_ihdr, sizeof(sc->sc_rxtap), in run_attach()
914 TASK_INIT(&sc->cmdq_task, 0, run_cmdq_cb, sc); in run_attach()
915 TASK_INIT(&sc->ratectl_task, 0, run_ratectl_cb, sc); in run_attach()
916 usb_callout_init_mtx(&sc->ratectl_ch, &sc->sc_mtx, 0); in run_attach()
935 while ((m = mbufq_dequeue(&sc->sc_snd)) != NULL) { in run_drain_mbufq()
936 ni = (struct ieee80211_node *)m->m_pkthdr.rcvif; in run_drain_mbufq()
937 m->m_pkthdr.rcvif = NULL; in run_drain_mbufq()
947 struct ieee80211com *ic = &sc->sc_ic; in run_detach()
951 sc->sc_detached = 1; in run_detach()
955 usbd_transfer_unsetup(sc->sc_xfer, RUN_N_XFER); in run_detach()
958 sc->ratectl_run = RUN_RATECTL_OFF; in run_detach()
959 sc->cmdq_run = sc->cmdq_key_set = RUN_CMDQ_ABORT; in run_detach()
963 run_unsetup_tx_list(sc, &sc->sc_epq[i]); in run_detach()
969 if (sc->sc_ic.ic_softc == sc) { in run_detach()
971 usb_callout_drain(&sc->ratectl_ch); in run_detach()
972 ieee80211_draintask(ic, &sc->cmdq_task); in run_detach()
973 ieee80211_draintask(ic, &sc->ratectl_task); in run_detach()
977 mtx_destroy(&sc->sc_mtx); in run_detach()
988 struct run_softc *sc = ic->ic_softc; in run_vap_create()
993 if (sc->rvp_cnt >= RUN_VAP_MAX) { in run_vap_create()
994 device_printf(sc->sc_dev, "number of VAPs maxed out\n"); in run_vap_create()
1008 if (!TAILQ_EMPTY(&ic->ic_vaps)) in run_vap_create()
1012 TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next){ in run_vap_create()
1013 if(vap->iv_opmode != IEEE80211_M_HOSTAP) in run_vap_create()
1020 device_printf(sc->sc_dev, in run_vap_create()
1026 device_printf(sc->sc_dev, "unknown opmode %d\n", opmode); in run_vap_create()
1031 vap = &rvp->vap; in run_vap_create()
1040 vap->iv_update_beacon = run_update_beacon; in run_vap_create()
1041 vap->iv_max_aid = RT2870_WCID_MAX; in run_vap_create()
1047 if (ic->ic_rxstream > 1) in run_vap_create()
1048 vap->iv_ampdu_rxmax = IEEE80211_HTCAP_MAXRXAMPDU_64K; in run_vap_create()
1050 vap->iv_ampdu_rxmax = IEEE80211_HTCAP_MAXRXAMPDU_32K; in run_vap_create()
1051 vap->iv_ampdu_density = IEEE80211_HTCAP_MPDUDENSITY_2; /* 2uS */ in run_vap_create()
1059 vap->iv_key_delete = (void *)run_key_delete; in run_vap_create()
1060 vap->iv_key_set = (void *)run_key_set; in run_vap_create()
1063 rvp->newstate = vap->iv_newstate; in run_vap_create()
1064 vap->iv_newstate = run_newstate; in run_vap_create()
1066 rvp->recv_mgmt = vap->iv_recv_mgmt; in run_vap_create()
1067 vap->iv_recv_mgmt = run_recv_mgmt; in run_vap_create()
1079 if((sc->rvp_bmap & 1 << i) == 0){ in run_vap_create()
1080 sc->rvp_bmap |= 1 << i; in run_vap_create()
1081 rvp->rvp_id = i; in run_vap_create()
1085 if (sc->rvp_cnt++ == 0) in run_vap_create()
1086 ic->ic_opmode = opmode; in run_vap_create()
1089 sc->cmdq_run = RUN_CMDQ_GO; in run_vap_create()
1092 rvp->rvp_id, sc->rvp_bmap, sc->rvp_cnt); in run_vap_create()
1108 ic = vap->iv_ic; in run_vap_delete()
1109 sc = ic->ic_softc; in run_vap_delete()
1113 m_freem(rvp->beacon_mbuf); in run_vap_delete()
1114 rvp->beacon_mbuf = NULL; in run_vap_delete()
1116 rvp_id = rvp->rvp_id; in run_vap_delete()
1117 sc->ratectl_run &= ~(1 << rvp_id); in run_vap_delete()
1118 sc->rvp_bmap &= ~(1 << rvp_id); in run_vap_delete()
1121 --sc->rvp_cnt; in run_vap_delete()
1125 vap, rvp_id, sc->rvp_bmap, sc->rvp_cnt); in run_vap_delete()
1137 * here is all-for-one taskqueue callback function. This function
1150 for (i = sc->cmdq_exec; sc->cmdq[i].func && pending; in run_cmdq_cb()
1151 i = sc->cmdq_exec, pending--) { in run_cmdq_cb()
1154 if (sc->cmdq_run == RUN_CMDQ_GO) { in run_cmdq_cb()
1159 if (sc->cmdq[i].arg0) in run_cmdq_cb()
1160 sc->cmdq[i].func(sc->cmdq[i].arg0); in run_cmdq_cb()
1162 sc->cmdq[i].func(&sc->cmdq[i]); in run_cmdq_cb()
1164 sc->cmdq[i].arg0 = NULL; in run_cmdq_cb()
1165 sc->cmdq[i].func = NULL; in run_cmdq_cb()
1166 sc->cmdq_exec++; in run_cmdq_cb()
1167 sc->cmdq_exec &= RUN_CMDQ_MASQ; in run_cmdq_cb()
1179 STAILQ_INIT(&pq->tx_qh); in run_setup_tx_list()
1180 STAILQ_INIT(&pq->tx_fh); in run_setup_tx_list()
1182 for (data = &pq->tx_data[0]; in run_setup_tx_list()
1183 data < &pq->tx_data[RUN_TX_RING_COUNT]; data++) { in run_setup_tx_list()
1184 data->sc = sc; in run_setup_tx_list()
1185 STAILQ_INSERT_TAIL(&pq->tx_fh, data, next); in run_setup_tx_list()
1187 pq->tx_nfree = RUN_TX_RING_COUNT; in run_setup_tx_list()
1196 pq->tx_nfree = 0; in run_unsetup_tx_list()
1197 STAILQ_INIT(&pq->tx_fh); in run_unsetup_tx_list()
1198 STAILQ_INIT(&pq->tx_qh); in run_unsetup_tx_list()
1201 for (data = &pq->tx_data[0]; in run_unsetup_tx_list()
1202 data < &pq->tx_data[RUN_TX_RING_COUNT]; data++) { in run_unsetup_tx_list()
1203 if (data->m != NULL) { in run_unsetup_tx_list()
1204 m_freem(data->m); in run_unsetup_tx_list()
1205 data->m = NULL; in run_unsetup_tx_list()
1207 if (data->ni != NULL) { in run_unsetup_tx_list()
1208 ieee80211_free_node(data->ni); in run_unsetup_tx_list()
1209 data->ni = NULL; in run_unsetup_tx_list()
1229 device_printf(sc->sc_dev, in run_load_microcode()
1234 if (fw->datasize != 8192) { in run_load_microcode()
1235 device_printf(sc->sc_dev, in run_load_microcode()
1243 * run-rt2870 (8KB) contains both, in run_load_microcode()
1247 base = fw->data; in run_load_microcode()
1248 if ((sc->mac_ver) != 0x2860 && in run_load_microcode()
1249 (sc->mac_ver) != 0x2872 && in run_load_microcode()
1250 (sc->mac_ver) != 0x3070) { in run_load_microcode()
1255 temp = fw->data; in run_load_microcode()
1258 device_printf(sc->sc_dev, "firmware checksum failed\n"); in run_load_microcode()
1264 if (sc->sc_flags & RUN_FLAG_FWLOAD_NEEDED) { in run_load_microcode()
1275 if ((error = usbd_do_request(sc->sc_udev, &sc->sc_mtx, &req, NULL)) in run_load_microcode()
1277 device_printf(sc->sc_dev, "firmware reset failed\n"); in run_load_microcode()
1298 device_printf(sc->sc_dev, in run_load_microcode()
1303 device_printf(sc->sc_dev, "firmware %s ver. %u.%u loaded\n", in run_load_microcode()
1304 (base == fw->data) ? "RT2870" : "RT3071", in run_load_microcode()
1322 return (usbd_do_request(sc->sc_udev, &sc->sc_mtx, &req, NULL)); in run_reset()
1334 while (ntries--) { in run_do_request()
1335 err = usbd_do_request_flags(sc->sc_udev, &sc->sc_mtx, in run_do_request()
1420 * firmware. Limit amount of data passed to 64-bytes at a in run_write_region_1()
1438 len -= delta; in run_write_region_1()
1467 /*- in run_efuse_read()
1468 * Read one 16-byte block into registers EFUSE_DATA[0-3]: in run_efuse_read()
1491 /* determine to which 32-bit register our 16-bit word belongs */ in run_efuse_read()
1492 reg = RT3070_EFUSE_DATA3 - (addr & 0xc); in run_efuse_read()
1502 /* Read 16-bit from eFUSE ROM for RT3xxx. */
1523 error = usbd_do_request(sc->sc_udev, &sc->sc_mtx, &req, &tmp); in run_eeprom_read_2()
1535 return sc->sc_srom_read(sc, addr, val); in run_srom_read()
1683 * Add `delta' (signed) to each 4-bit sub-word of a 32-bit word.
1684 * Used to adjust per-rate Tx power registers.
1732 addr = (sc->ntxchains == 3) ? RT3593_EEPROM_PWR2GHZ_BASE1 : in run_rt3593_get_txpower()
1735 sc->txpow1[i + 0] = (int8_t)(val & 0xff); in run_rt3593_get_txpower()
1736 sc->txpow1[i + 1] = (int8_t)(val >> 8); in run_rt3593_get_txpower()
1738 addr = (sc->ntxchains == 3) ? RT3593_EEPROM_PWR2GHZ_BASE2 : in run_rt3593_get_txpower()
1741 sc->txpow2[i + 0] = (int8_t)(val & 0xff); in run_rt3593_get_txpower()
1742 sc->txpow2[i + 1] = (int8_t)(val >> 8); in run_rt3593_get_txpower()
1744 if (sc->ntxchains == 3) { in run_rt3593_get_txpower()
1747 sc->txpow3[i + 0] = (int8_t)(val & 0xff); in run_rt3593_get_txpower()
1748 sc->txpow3[i + 1] = (int8_t)(val >> 8); in run_rt3593_get_txpower()
1753 if (sc->txpow1[i] > 31) in run_rt3593_get_txpower()
1754 sc->txpow1[i] = 5; in run_rt3593_get_txpower()
1755 if (sc->txpow2[i] > 31) in run_rt3593_get_txpower()
1756 sc->txpow2[i] = 5; in run_rt3593_get_txpower()
1757 if (sc->ntxchains == 3) { in run_rt3593_get_txpower()
1758 if (sc->txpow3[i] > 31) in run_rt3593_get_txpower()
1759 sc->txpow3[i] = 5; in run_rt3593_get_txpower()
1765 sc->txpow1[i + 14] = (int8_t)(val & 0xff); in run_rt3593_get_txpower()
1766 sc->txpow1[i + 15] = (int8_t)(val >> 8); in run_rt3593_get_txpower()
1769 sc->txpow2[i + 14] = (int8_t)(val & 0xff); in run_rt3593_get_txpower()
1770 sc->txpow2[i + 15] = (int8_t)(val >> 8); in run_rt3593_get_txpower()
1772 if (sc->ntxchains == 3) { in run_rt3593_get_txpower()
1775 sc->txpow3[i + 14] = (int8_t)(val & 0xff); in run_rt3593_get_txpower()
1776 sc->txpow3[i + 15] = (int8_t)(val >> 8); in run_rt3593_get_txpower()
1790 sc->txpow1[i + 0] = (int8_t)(val & 0xff); in run_get_txpower()
1791 sc->txpow1[i + 1] = (int8_t)(val >> 8); in run_get_txpower()
1793 if (sc->mac_ver != 0x5390) { in run_get_txpower()
1796 sc->txpow2[i + 0] = (int8_t)(val & 0xff); in run_get_txpower()
1797 sc->txpow2[i + 1] = (int8_t)(val >> 8); in run_get_txpower()
1802 if (sc->mac_ver >= 0x5390) { in run_get_txpower()
1803 if (sc->txpow1[i] < 0 || sc->txpow1[i] > 39) in run_get_txpower()
1804 sc->txpow1[i] = 5; in run_get_txpower()
1806 if (sc->txpow1[i] < 0 || sc->txpow1[i] > 31) in run_get_txpower()
1807 sc->txpow1[i] = 5; in run_get_txpower()
1809 if (sc->mac_ver > 0x5390) { in run_get_txpower()
1810 if (sc->txpow2[i] < 0 || sc->txpow2[i] > 39) in run_get_txpower()
1811 sc->txpow2[i] = 5; in run_get_txpower()
1812 } else if (sc->mac_ver < 0x5390) { in run_get_txpower()
1813 if (sc->txpow2[i] < 0 || sc->txpow2[i] > 31) in run_get_txpower()
1814 sc->txpow2[i] = 5; in run_get_txpower()
1818 rt2860_rf2850[i].chan, sc->txpow1[i], sc->txpow2[i]); in run_get_txpower()
1823 sc->txpow1[i + 14] = (int8_t)(val & 0xff); in run_get_txpower()
1824 sc->txpow1[i + 15] = (int8_t)(val >> 8); in run_get_txpower()
1827 sc->txpow2[i + 14] = (int8_t)(val & 0xff); in run_get_txpower()
1828 sc->txpow2[i + 15] = (int8_t)(val >> 8); in run_get_txpower()
1832 if (sc->mac_ver != 0x5592) { in run_get_txpower()
1833 if (sc->txpow1[14 + i] < -7 || sc->txpow1[14 + i] > 15) in run_get_txpower()
1834 sc->txpow1[14 + i] = 5; in run_get_txpower()
1835 if (sc->txpow2[14 + i] < -7 || sc->txpow2[14 + i] > 15) in run_get_txpower()
1836 sc->txpow2[14 + i] = 5; in run_get_txpower()
1840 rt2860_rf2850[14 + i].chan, sc->txpow1[14 + i], in run_get_txpower()
1841 sc->txpow2[14 + i]); in run_get_txpower()
1848 struct ieee80211com *ic = &sc->sc_ic; in run_read_eeprom()
1855 sc->sc_srom_read = run_eeprom_read_2; in run_read_eeprom()
1856 if (sc->mac_ver >= 0x3070) { in run_read_eeprom()
1859 if ((tmp & RT3070_SEL_EFUSE) || sc->mac_ver == 0x3593) in run_read_eeprom()
1860 sc->sc_srom_read = run_efuse_read_2; in run_read_eeprom()
1870 ic->ic_macaddr[0] = val & 0xff; in run_read_eeprom()
1871 ic->ic_macaddr[1] = val >> 8; in run_read_eeprom()
1873 ic->ic_macaddr[2] = val & 0xff; in run_read_eeprom()
1874 ic->ic_macaddr[3] = val >> 8; in run_read_eeprom()
1876 ic->ic_macaddr[4] = val & 0xff; in run_read_eeprom()
1877 ic->ic_macaddr[5] = val >> 8; in run_read_eeprom()
1879 if (sc->mac_ver < 0x3593) { in run_read_eeprom()
1883 sc->bbp[i].val = val & 0xff; in run_read_eeprom()
1884 sc->bbp[i].reg = val >> 8; in run_read_eeprom()
1886 "BBP%d=0x%02x\n", sc->bbp[i].reg, sc->bbp[i].val); in run_read_eeprom()
1888 if (sc->mac_ver >= 0x3071) { in run_read_eeprom()
1893 sc->rf[i].val = val & 0xff; in run_read_eeprom()
1894 sc->rf[i].reg = val >> 8; in run_read_eeprom()
1896 sc->rf[i].reg, sc->rf[i].val); in run_read_eeprom()
1901 /* read RF frequency offset from EEPROM */ in run_read_eeprom()
1902 run_srom_read(sc, (sc->mac_ver != 0x3593) ? RT2860_EEPROM_FREQ_LEDS : in run_read_eeprom()
1904 sc->freq = ((val & 0xff) != 0xff) ? val & 0xff : 0; in run_read_eeprom()
1905 RUN_DPRINTF(sc, RUN_DEBUG_ROM, "EEPROM freq offset %d\n", in run_read_eeprom()
1906 sc->freq & 0xff); in run_read_eeprom()
1908 run_srom_read(sc, (sc->mac_ver != 0x3593) ? RT2860_EEPROM_FREQ_LEDS : in run_read_eeprom()
1912 sc->leds = val >> 8; in run_read_eeprom()
1913 run_srom_read(sc, (sc->mac_ver != 0x3593) ? RT2860_EEPROM_LED1 : in run_read_eeprom()
1914 RT3593_EEPROM_LED1, &sc->led[0]); in run_read_eeprom()
1915 run_srom_read(sc, (sc->mac_ver != 0x3593) ? RT2860_EEPROM_LED2 : in run_read_eeprom()
1916 RT3593_EEPROM_LED2, &sc->led[1]); in run_read_eeprom()
1917 run_srom_read(sc, (sc->mac_ver != 0x3593) ? RT2860_EEPROM_LED3 : in run_read_eeprom()
1918 RT3593_EEPROM_LED3, &sc->led[2]); in run_read_eeprom()
1921 sc->leds = 0x01; in run_read_eeprom()
1922 sc->led[0] = 0x5555; in run_read_eeprom()
1923 sc->led[1] = 0x2221; in run_read_eeprom()
1924 sc->led[2] = 0x5627; /* differs from RT2860 */ in run_read_eeprom()
1928 sc->leds, sc->led[0], sc->led[1], sc->led[2]); in run_read_eeprom()
1931 if (sc->mac_ver == 0x5390 || sc->mac_ver ==0x5392) in run_read_eeprom()
1937 device_printf(sc->sc_dev, in run_read_eeprom()
1939 if (sc->mac_ver == 0x3572) { in run_read_eeprom()
1941 sc->rf_rev = RT3070_RF_3052; in run_read_eeprom()
1942 sc->ntxchains = 2; in run_read_eeprom()
1943 sc->nrxchains = 2; in run_read_eeprom()
1944 } else if (sc->mac_ver >= 0x3070) { in run_read_eeprom()
1946 sc->rf_rev = RT3070_RF_3020; in run_read_eeprom()
1947 sc->ntxchains = 1; in run_read_eeprom()
1948 sc->nrxchains = 1; in run_read_eeprom()
1951 sc->rf_rev = RT2860_RF_2820; in run_read_eeprom()
1952 sc->ntxchains = 1; in run_read_eeprom()
1953 sc->nrxchains = 2; in run_read_eeprom()
1956 if (sc->mac_ver == 0x5390 || sc->mac_ver ==0x5392) { in run_read_eeprom()
1957 sc->rf_rev = val; in run_read_eeprom()
1960 sc->rf_rev = (val >> 8) & 0xf; in run_read_eeprom()
1961 sc->ntxchains = (val >> 4) & 0xf; in run_read_eeprom()
1962 sc->nrxchains = val & 0xf; in run_read_eeprom()
1965 sc->rf_rev, sc->ntxchains, sc->nrxchains); in run_read_eeprom()
1972 sc->patch_dac = (val >> 15) & 1; in run_read_eeprom()
1974 sc->ext_5ghz_lna = (val >> 3) & 1; in run_read_eeprom()
1975 sc->ext_2ghz_lna = (val >> 2) & 1; in run_read_eeprom()
1977 sc->calib_2ghz = sc->calib_5ghz = (val >> 1) & 1; in run_read_eeprom()
1979 sc->rfswitch = val & 1; in run_read_eeprom()
1983 if (sc->mac_ver == 0x3593) in run_read_eeprom()
1994 delta_2ghz = -delta_2ghz; in run_read_eeprom()
2000 delta_5ghz = -delta_5ghz; in run_read_eeprom()
2013 sc->txpow20mhz[ridx] = reg; in run_read_eeprom()
2014 sc->txpow40mhz_2ghz[ridx] = b4inc(reg, delta_2ghz); in run_read_eeprom()
2015 sc->txpow40mhz_5ghz[ridx] = b4inc(reg, delta_5ghz); in run_read_eeprom()
2019 "40MHz/5GHz=0x%08x\n", ridx, sc->txpow20mhz[ridx], in run_read_eeprom()
2020 sc->txpow40mhz_2ghz[ridx], sc->txpow40mhz_5ghz[ridx]); in run_read_eeprom()
2024 run_srom_read(sc, (sc->mac_ver != 0x3593) ? RT2860_EEPROM_RSSI1_2GHZ : in run_read_eeprom()
2026 sc->rssi_2ghz[0] = val & 0xff; /* Ant A */ in run_read_eeprom()
2027 sc->rssi_2ghz[1] = val >> 8; /* Ant B */ in run_read_eeprom()
2028 run_srom_read(sc, (sc->mac_ver != 0x3593) ? RT2860_EEPROM_RSSI2_2GHZ : in run_read_eeprom()
2030 if (sc->mac_ver >= 0x3070) { in run_read_eeprom()
2031 if (sc->mac_ver == 0x3593) { in run_read_eeprom()
2032 sc->txmixgain_2ghz = 0; in run_read_eeprom()
2033 sc->rssi_2ghz[2] = val & 0xff; /* Ant C */ in run_read_eeprom()
2040 sc->txmixgain_2ghz = val & 0x7; in run_read_eeprom()
2043 sc->txmixgain_2ghz); in run_read_eeprom()
2045 sc->rssi_2ghz[2] = val & 0xff; /* Ant C */ in run_read_eeprom()
2046 if (sc->mac_ver == 0x3593) in run_read_eeprom()
2048 sc->lna[2] = val >> 8; /* channel group 2 */ in run_read_eeprom()
2050 run_srom_read(sc, (sc->mac_ver != 0x3593) ? RT2860_EEPROM_RSSI1_5GHZ : in run_read_eeprom()
2052 sc->rssi_5ghz[0] = val & 0xff; /* Ant A */ in run_read_eeprom()
2053 sc->rssi_5ghz[1] = val >> 8; /* Ant B */ in run_read_eeprom()
2054 run_srom_read(sc, (sc->mac_ver != 0x3593) ? RT2860_EEPROM_RSSI2_5GHZ : in run_read_eeprom()
2056 if (sc->mac_ver == 0x3572) { in run_read_eeprom()
2062 sc->txmixgain_5ghz = val & 0x7; in run_read_eeprom()
2064 sc->txmixgain_5ghz); in run_read_eeprom()
2066 sc->rssi_5ghz[2] = val & 0xff; /* Ant C */ in run_read_eeprom()
2067 if (sc->mac_ver == 0x3593) { in run_read_eeprom()
2068 sc->txmixgain_5ghz = 0; in run_read_eeprom()
2071 sc->lna[3] = val >> 8; /* channel group 3 */ in run_read_eeprom()
2073 run_srom_read(sc, (sc->mac_ver != 0x3593) ? RT2860_EEPROM_LNA : in run_read_eeprom()
2075 sc->lna[0] = val & 0xff; /* channel group 0 */ in run_read_eeprom()
2076 sc->lna[1] = val >> 8; /* channel group 1 */ in run_read_eeprom()
2079 if (sc->lna[2] == 0 || sc->lna[2] == 0xff) { in run_read_eeprom()
2082 sc->lna[2] = sc->lna[1]; in run_read_eeprom()
2084 if (sc->lna[3] == 0 || sc->lna[3] == 0xff) { in run_read_eeprom()
2087 sc->lna[3] = sc->lna[1]; in run_read_eeprom()
2090 /* fix broken RSSI offset entries */ in run_read_eeprom()
2092 if (sc->rssi_2ghz[ant] < -10 || sc->rssi_2ghz[ant] > 10) { in run_read_eeprom()
2094 "invalid RSSI%d offset: %d (2GHz)\n", in run_read_eeprom()
2095 ant + 1, sc->rssi_2ghz[ant]); in run_read_eeprom()
2096 sc->rssi_2ghz[ant] = 0; in run_read_eeprom()
2098 if (sc->rssi_5ghz[ant] < -10 || sc->rssi_5ghz[ant] > 10) { in run_read_eeprom()
2100 "invalid RSSI%d offset: %d (5GHz)\n", in run_read_eeprom()
2101 ant + 1, sc->rssi_5ghz[ant]); in run_read_eeprom()
2102 sc->rssi_5ghz[ant] = 0; in run_read_eeprom()
2119 struct ieee80211com *ic = vap->iv_ic; in run_media_change()
2121 struct run_softc *sc = ic->ic_softc; in run_media_change()
2133 tp = &vap->iv_txparms[ieee80211_chan2mode(ic->ic_curchan)]; in run_media_change()
2134 if (tp->ucastrate != IEEE80211_FIXED_RATE_NONE) { in run_media_change()
2139 rate = ic->ic_sup_rates[ic->ic_curmode]. in run_media_change()
2140 rs_rates[tp->ucastrate] & IEEE80211_RATE_VAL; in run_media_change()
2145 ni = ieee80211_ref_node(vap->iv_bss); in run_media_change()
2147 rn->fix_ridx = ridx; in run_media_change()
2149 rate, rn->fix_ridx); in run_media_change()
2169 struct ieee80211com *ic = vap->iv_ic; in run_newstate()
2170 struct run_softc *sc = ic->ic_softc; in run_newstate()
2176 uint8_t bid = 1 << rvp->rvp_id; in run_newstate()
2178 ostate = vap->iv_state; in run_newstate()
2179 RUN_DPRINTF(sc, RUN_DEBUG_STATE, "%s -> %s\n", in run_newstate()
2186 ratectl = sc->ratectl_run; /* remember current state */ in run_newstate()
2187 sc->ratectl_run = RUN_RATECTL_OFF; in run_newstate()
2188 usb_callout_stop(&sc->ratectl_ch); in run_newstate()
2203 sc->runbmap &= ~bid; in run_newstate()
2206 if (--sc->running == 0) in run_newstate()
2211 if (!(sc->runbmap & bid)) { in run_newstate()
2212 if(sc->running++) in run_newstate()
2214 sc->runbmap |= bid; in run_newstate()
2217 m_freem(rvp->beacon_mbuf); in run_newstate()
2218 rvp->beacon_mbuf = NULL; in run_newstate()
2220 switch (vap->iv_opmode) { in run_newstate()
2223 sc->ap_running |= bid; in run_newstate()
2224 ic->ic_opmode = vap->iv_opmode; in run_newstate()
2228 sc->adhoc_running |= bid; in run_newstate()
2229 if (!sc->ap_running) in run_newstate()
2230 ic->ic_opmode = vap->iv_opmode; in run_newstate()
2234 sc->sta_running |= bid; in run_newstate()
2235 if (!sc->ap_running && !sc->adhoc_running) in run_newstate()
2236 ic->ic_opmode = vap->iv_opmode; in run_newstate()
2244 ic->ic_opmode = vap->iv_opmode; in run_newstate()
2248 if (vap->iv_opmode != IEEE80211_M_MONITOR) { in run_newstate()
2251 if (ic->ic_bsschan == IEEE80211_CHAN_ANYC) { in run_newstate()
2254 return (-1); in run_newstate()
2260 ni = ieee80211_ref_node(vap->iv_bss); in run_newstate()
2261 IEEE80211_ADDR_COPY(sc->sc_bssid, ni->ni_bssid); in run_newstate()
2262 run_set_bssid(sc, sc->sc_bssid); in run_newstate()
2267 tp = &vap->iv_txparms[ieee80211_chan2mode(ic->ic_curchan)]; in run_newstate()
2268 if (tp->ucastrate == IEEE80211_FIXED_RATE_NONE) in run_newstate()
2275 (IEEE80211_IS_CHAN_2GHZ(ic->ic_curchan) ? in run_newstate()
2285 if ((sc->ratectl_run = ratectl) && restart_ratectl) in run_newstate()
2286 usb_callout_reset(&sc->ratectl_ch, hz, run_ratectl_to, sc); in run_newstate()
2291 return(rvp->newstate(vap, nstate, arg)); in run_newstate()
2298 struct run_softc *sc = ic->ic_softc; in run_wme_update()
2355 struct ieee80211vap *vap = cmdq->arg1; in run_key_set_cb()
2356 struct ieee80211_key *k = cmdq->k; in run_key_set_cb()
2357 struct ieee80211com *ic = vap->iv_ic; in run_key_set_cb()
2358 struct run_softc *sc = ic->ic_softc; in run_key_set_cb()
2360 u_int cipher = k->wk_cipher->ic_cipher; in run_key_set_cb()
2367 if (vap->iv_opmode == IEEE80211_M_HOSTAP) in run_key_set_cb()
2368 ni = ieee80211_find_vap_node(&ic->ic_sta, vap, cmdq->mac); in run_key_set_cb()
2370 ni = vap->iv_bss; in run_key_set_cb()
2371 associd = (ni != NULL) ? ni->ni_associd : 0; in run_key_set_cb()
2376 if(k->wk_keylen < 8) in run_key_set_cb()
2394 associd, k->wk_keyix, mode, in run_key_set_cb()
2395 (k->wk_flags & IEEE80211_KEY_GROUP) ? "group" : "pairwise", in run_key_set_cb()
2396 (k->wk_flags & IEEE80211_KEY_XMIT) ? "on" : "off", in run_key_set_cb()
2397 (k->wk_flags & IEEE80211_KEY_RECV) ? "on" : "off"); in run_key_set_cb()
2399 if (k->wk_flags & IEEE80211_KEY_GROUP) { in run_key_set_cb()
2401 base = RT2860_SKEY(RUN_VAP(vap)->rvp_id, k->wk_keyix); in run_key_set_cb()
2403 wcid = (vap->iv_opmode == IEEE80211_M_STA) ? in run_key_set_cb()
2409 if(run_write_region_1(sc, base, k->wk_key, 16)) in run_key_set_cb()
2411 if(run_write_region_1(sc, base + 16, &k->wk_key[16], 8)) /* wk_txmic */ in run_key_set_cb()
2413 if(run_write_region_1(sc, base + 24, &k->wk_key[24], 8)) /* wk_rxmic */ in run_key_set_cb()
2416 /* roundup len to 16-bit: XXX fix write_region_1() instead */ in run_key_set_cb()
2417 if(run_write_region_1(sc, base, k->wk_key, (k->wk_keylen + 1) & ~1)) in run_key_set_cb()
2421 if (!(k->wk_flags & IEEE80211_KEY_GROUP) || in run_key_set_cb()
2422 (k->wk_flags & (IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV))) { in run_key_set_cb()
2426 iv[3] = vap->iv_def_txkey << 6; in run_key_set_cb()
2429 iv[0] = k->wk_keytsc >> 8; in run_key_set_cb()
2431 iv[2] = k->wk_keytsc; in run_key_set_cb()
2433 iv[0] = k->wk_keytsc; in run_key_set_cb()
2434 iv[1] = k->wk_keytsc >> 8; in run_key_set_cb()
2437 iv[3] = k->wk_keyix << 6 | IEEE80211_WEP_EXTIV; in run_key_set_cb()
2438 iv[4] = k->wk_keytsc >> 16; in run_key_set_cb()
2439 iv[5] = k->wk_keytsc >> 24; in run_key_set_cb()
2440 iv[6] = k->wk_keytsc >> 32; in run_key_set_cb()
2441 iv[7] = k->wk_keytsc >> 40; in run_key_set_cb()
2447 if (k->wk_flags & IEEE80211_KEY_GROUP) { in run_key_set_cb()
2451 attr &= ~(0xf << (k->wk_keyix * 4)); in run_key_set_cb()
2452 attr |= mode << (k->wk_keyix * 4); in run_key_set_cb()
2464 /* TODO create a pass-thru key entry? */ in run_key_set_cb()
2467 k->wk_pad = wcid; in run_key_set_cb()
2480 struct ieee80211com *ic = vap->iv_ic; in run_key_set()
2481 struct run_softc *sc = ic->ic_softc; in run_key_set()
2484 i = RUN_CMDQ_GET(&sc->cmdq_store); in run_key_set()
2486 sc->cmdq[i].func = run_key_set_cb; in run_key_set()
2487 sc->cmdq[i].arg0 = NULL; in run_key_set()
2488 sc->cmdq[i].arg1 = vap; in run_key_set()
2489 sc->cmdq[i].k = k; in run_key_set()
2490 IEEE80211_ADDR_COPY(sc->cmdq[i].mac, k->wk_macaddr); in run_key_set()
2491 ieee80211_runtask(ic, &sc->cmdq_task); in run_key_set()
2497 if (vap->iv_opmode == IEEE80211_M_HOSTAP) { in run_key_set()
2499 sc->cmdq_key_set = RUN_CMDQ_GO; in run_key_set()
2515 struct run_softc *sc = cmdq->arg1; in run_key_delete_cb()
2516 struct ieee80211_key *k = &cmdq->key; in run_key_delete_cb()
2522 if (k->wk_flags & IEEE80211_KEY_GROUP) { in run_key_delete_cb()
2526 attr &= ~(0xf << (k->wk_keyix * 4)); in run_key_delete_cb()
2531 "removing key for wcid %x\n", k->wk_pad); in run_key_delete_cb()
2533 wcid = k->wk_pad; in run_key_delete_cb()
2540 k->wk_pad = 0; in run_key_delete_cb()
2549 struct ieee80211com *ic = vap->iv_ic; in run_key_delete()
2550 struct run_softc *sc = ic->ic_softc; in run_key_delete()
2560 i = RUN_CMDQ_GET(&sc->cmdq_store); in run_key_delete()
2562 sc->cmdq[i].func = run_key_delete_cb; in run_key_delete()
2563 sc->cmdq[i].arg0 = NULL; in run_key_delete()
2564 sc->cmdq[i].arg1 = sc; in run_key_delete()
2565 k0 = &sc->cmdq[i].key; in run_key_delete()
2566 k0->wk_flags = k->wk_flags; in run_key_delete()
2567 k0->wk_keyix = k->wk_keyix; in run_key_delete()
2569 k0->wk_pad = k->wk_pad; in run_key_delete()
2570 ieee80211_runtask(ic, &sc->cmdq_task); in run_key_delete()
2581 ieee80211_runtask(&sc->sc_ic, &sc->ratectl_task); in run_ratectl_to()
2590 struct ieee80211com *ic = &sc->sc_ic; in run_ratectl_cb()
2591 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); in run_ratectl_cb()
2596 if (sc->rvp_cnt > 1 || vap->iv_opmode != IEEE80211_M_STA) { in run_ratectl_cb()
2611 ieee80211_iterate_nodes(&ic->ic_sta, run_iter_func, sc); in run_ratectl_cb()
2614 if(sc->ratectl_run != RUN_RATECTL_OFF) in run_ratectl_cb()
2615 usb_callout_reset(&sc->ratectl_ch, hz, run_ratectl_to, sc); in run_ratectl_cb()
2645 * Even though each stat is Tx-complete-status like format, in run_drain_fifo()
2654 wstat = &(sc->wcid_stats[wcid]); in run_drain_fifo()
2659 counter_u64_add(sc->sc_ic.ic_oerrors, 1); in run_drain_fifo()
2667 if ((retry = pid -1 - mcs) > 0) { in run_drain_fifo()
2672 RUN_DPRINTF(sc, RUN_DEBUG_XMIT, "count=%d\n", sc->fifo_cnt); in run_drain_fifo()
2674 sc->fifo_cnt = 0; in run_drain_fifo()
2681 struct ieee80211_ratectl_tx_stats *txs = &sc->sc_txs; in run_iter_func()
2682 struct ieee80211vap *vap = ni->ni_vap; in run_iter_func()
2692 if (sc->rvp_cnt <= 1 && vap->iv_opmode == IEEE80211_M_STA && in run_iter_func()
2693 ni != vap->iv_bss) in run_iter_func()
2696 txs->flags = IEEE80211_RATECTL_TX_STATS_NODE | in run_iter_func()
2698 txs->ni = ni; in run_iter_func()
2699 if (sc->rvp_cnt <= 1 && (vap->iv_opmode == IEEE80211_M_IBSS || in run_iter_func()
2700 vap->iv_opmode == IEEE80211_M_STA)) { in run_iter_func()
2708 if_inc_counter(vap->iv_ifp, IFCOUNTER_OERRORS, in run_iter_func()
2711 txs->nretries = le16toh(sta[1].tx.retry); in run_iter_func()
2712 txs->nsuccess = le16toh(sta[1].tx.success); in run_iter_func()
2714 txs->nframes = txs->nretries + txs->nsuccess + in run_iter_func()
2719 txs->nretries, txs->nsuccess, le16toh(sta[0].error.fail)); in run_iter_func()
2721 wstat = &(sc->wcid_stats[RUN_AID2WCID(ni->ni_associd)]); in run_iter_func()
2723 if (wstat == &(sc->wcid_stats[0]) || in run_iter_func()
2724 wstat > &(sc->wcid_stats[RT2870_WCID_MAX])) in run_iter_func()
2727 txs->nretries = (*wstat)[RUN_RETRY]; in run_iter_func()
2728 txs->nsuccess = (*wstat)[RUN_SUCCESS]; in run_iter_func()
2729 txs->nframes = (*wstat)[RUN_TXCNT]; in run_iter_func()
2732 txs->nretries, txs->nframes, txs->nsuccess); in run_iter_func()
2744 rn->amrr_ridx = ridx; in run_iter_func()
2750 ieee80211_node_get_txrate_dot11rate(ni), rn->amrr_ridx); in run_iter_func()
2757 struct ieee80211_node *ni = cmdq->arg1; in run_newassoc_cb()
2758 struct run_softc *sc = ni->ni_vap->iv_ic->ic_softc; in run_newassoc_cb()
2759 uint8_t wcid = cmdq->wcid; in run_newassoc_cb()
2764 ni->ni_macaddr, IEEE80211_ADDR_LEN); in run_newassoc_cb()
2766 memset(&(sc->wcid_stats[wcid]), 0, sizeof(sc->wcid_stats[wcid])); in run_newassoc_cb()
2773 struct ieee80211vap *vap = ni->ni_vap; in run_newassoc()
2774 struct ieee80211com *ic = vap->iv_ic; in run_newassoc()
2775 struct run_softc *sc = ic->ic_softc; in run_newassoc()
2780 wcid = (vap->iv_opmode == IEEE80211_M_STA) ? in run_newassoc()
2781 1 : RUN_AID2WCID(ni->ni_associd); in run_newassoc()
2784 device_printf(sc->sc_dev, "wcid=%d out of range\n", wcid); in run_newassoc()
2789 if (isnew && ni->ni_associd != 0) { in run_newassoc()
2794 uint32_t cnt = RUN_CMDQ_GET(&sc->cmdq_store); in run_newassoc()
2796 sc->cmdq[cnt].func = run_newassoc_cb; in run_newassoc()
2797 sc->cmdq[cnt].arg0 = NULL; in run_newassoc()
2798 sc->cmdq[cnt].arg1 = ni; in run_newassoc()
2799 sc->cmdq[cnt].wcid = wcid; in run_newassoc()
2800 ieee80211_runtask(ic, &sc->cmdq_task); in run_newassoc()
2805 isnew, ni->ni_associd, ether_sprintf(ni->ni_macaddr)); in run_newassoc()
2807 rate = vap->iv_txparms[ieee80211_chan2mode(ic->ic_curchan)].mgmtrate; in run_newassoc()
2812 rn->mgt_ridx = ridx; in run_newassoc()
2814 "rate=%d, mgmt_ridx=%d\n", rate, rn->mgt_ridx); in run_newassoc()
2817 if(sc->ratectl_run != RUN_RATECTL_OFF) in run_newassoc()
2818 usb_callout_reset(&sc->ratectl_ch, hz, run_ratectl_to, sc); in run_newassoc()
2830 if (sc->nrxchains > 1) { in run_maxrssi_chain()
2831 if (rxwi->rssi[1] > rxwi->rssi[rxchain]) in run_maxrssi_chain()
2833 if (sc->nrxchains > 2) in run_maxrssi_chain()
2834 if (rxwi->rssi[2] > rxwi->rssi[rxchain]) in run_maxrssi_chain()
2844 struct ieee80211vap *vap = ni->ni_vap; in run_recv_mgmt()
2845 struct run_softc *sc = vap->iv_ic->ic_softc; in run_recv_mgmt()
2849 rvp->recv_mgmt(ni, m, subtype, rxs, rssi, nf); in run_recv_mgmt()
2851 if (vap->iv_state == IEEE80211_S_RUN && in run_recv_mgmt()
2854 ni_tstamp = le64toh(ni->ni_tstamp.tsf); in run_recv_mgmt()
2872 struct ieee80211com *ic = &sc->sc_ic; in run_rx_frame()
2883 if (sc->mac_ver == 0x5592) in run_rx_frame()
2885 else if (sc->mac_ver == 0x3593) in run_rx_frame()
2897 len = le16toh(rxwi->len) & 0xfff; in run_rx_frame()
2899 if (__predict_false(len > dmalen - rxwisize)) { in run_rx_frame()
2907 flags = le32toh(rxd->flags); in run_rx_frame()
2921 m->m_data += rxwisize; in run_rx_frame()
2922 m->m_pkthdr.len = m->m_len = len; in run_rx_frame()
2926 if ((wh->i_fc[1] & IEEE80211_FC1_PROTECTED) != 0 && in run_rx_frame()
2928 wh->i_fc[1] &= ~IEEE80211_FC1_PROTECTED; in run_rx_frame()
2929 m->m_flags |= M_WEP; in run_rx_frame()
2938 if(ni && ni->ni_flags & IEEE80211_NODE_HT) { in run_rx_frame()
2939 m->m_flags |= M_AMPDU; in run_rx_frame()
2945 ieee80211_notify_michael_failure(ni->ni_vap, wh, in run_rx_frame()
2946 rxwi->keyidx); in run_rx_frame()
2953 rssi = rxwi->rssi[ant]; in run_rx_frame()
2957 struct run_rx_radiotap_header *tap = &sc->sc_rxtap; in run_rx_frame()
2960 tap->wr_flags = 0; in run_rx_frame()
2962 tap->wr_flags |= IEEE80211_RADIOTAP_F_DATAPAD; in run_rx_frame()
2963 tap->wr_antsignal = rssi; in run_rx_frame()
2964 tap->wr_antenna = ant; in run_rx_frame()
2965 tap->wr_dbm_antsignal = run_rssi2dbm(sc, rssi, ant); in run_rx_frame()
2966 tap->wr_rate = 2; /* in case it can't be found below */ in run_rx_frame()
2968 run_get_tsf(sc, &tap->wr_tsf); in run_rx_frame()
2970 phy = le16toh(rxwi->phy); in run_rx_frame()
2974 case 0: tap->wr_rate = 2; break; in run_rx_frame()
2975 case 1: tap->wr_rate = 4; break; in run_rx_frame()
2976 case 2: tap->wr_rate = 11; break; in run_rx_frame()
2977 case 3: tap->wr_rate = 22; break; in run_rx_frame()
2980 tap->wr_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; in run_rx_frame()
2984 case 0: tap->wr_rate = 12; break; in run_rx_frame()
2985 case 1: tap->wr_rate = 18; break; in run_rx_frame()
2986 case 2: tap->wr_rate = 24; break; in run_rx_frame()
2987 case 3: tap->wr_rate = 36; break; in run_rx_frame()
2988 case 4: tap->wr_rate = 48; break; in run_rx_frame()
2989 case 5: tap->wr_rate = 72; break; in run_rx_frame()
2990 case 6: tap->wr_rate = 96; break; in run_rx_frame()
2991 case 7: tap->wr_rate = 108; break; in run_rx_frame()
3008 counter_u64_add(ic->ic_ierrors, 1); in run_rx_frame()
3015 struct ieee80211com *ic = &sc->sc_ic; in run_bulk_rx_callback()
3023 if (sc->mac_ver == 0x5592) in run_bulk_rx_callback()
3025 else if (sc->mac_ver == 0x3593) in run_bulk_rx_callback()
3043 m = sc->rx_m; in run_bulk_rx_callback()
3044 sc->rx_m = NULL; in run_bulk_rx_callback()
3049 if (sc->rx_m == NULL) { in run_bulk_rx_callback()
3050 sc->rx_m = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, in run_bulk_rx_callback()
3053 if (sc->rx_m == NULL) { in run_bulk_rx_callback()
3056 "could not allocate mbuf - idle with stall\n"); in run_bulk_rx_callback()
3057 counter_u64_add(ic->ic_ierrors, 1); in run_bulk_rx_callback()
3067 mtod(sc->rx_m, caddr_t), RUN_MAX_RXSZ); in run_bulk_rx_callback()
3078 device_printf(sc->sc_dev, "device timeout\n"); in run_bulk_rx_callback()
3079 counter_u64_add(ic->ic_ierrors, 1); in run_bulk_rx_callback()
3082 if (sc->rx_m != NULL) { in run_bulk_rx_callback()
3083 m_freem(sc->rx_m); in run_bulk_rx_callback()
3084 sc->rx_m = NULL; in run_bulk_rx_callback()
3096 m->m_pkthdr.len = m->m_len = xferlen; in run_bulk_rx_callback()
3102 if ((dmalen >= (uint32_t)-8) || (dmalen == 0) || in run_bulk_rx_callback()
3116 if ((xferlen -= dmalen + 8) <= 8) { in run_bulk_rx_callback()
3117 /* trim 32-bit DMA-len header */ in run_bulk_rx_callback()
3118 m->m_data += 4; in run_bulk_rx_callback()
3119 m->m_pkthdr.len = m->m_len -= 4; in run_bulk_rx_callback()
3129 counter_u64_add(ic->ic_ierrors, 1); in run_bulk_rx_callback()
3138 counter_u64_add(ic->ic_ierrors, 1); in run_bulk_rx_callback()
3141 m_copydata(m, 4 /* skip 32-bit DMA-len header */, in run_bulk_rx_callback()
3143 m0->m_pkthdr.len = m0->m_len = mbuf_len; in run_bulk_rx_callback()
3147 m->m_data += mbuf_len + 4; in run_bulk_rx_callback()
3148 m->m_pkthdr.len = m->m_len -= mbuf_len + 4; in run_bulk_rx_callback()
3165 ieee80211_tx_complete(data->ni, data->m, txerr); in run_tx_free()
3167 data->m = NULL; in run_tx_free()
3168 data->ni = NULL; in run_tx_free()
3170 STAILQ_INSERT_TAIL(&pq->tx_fh, data, next); in run_tx_free()
3171 pq->tx_nfree++; in run_tx_free()
3178 struct ieee80211com *ic = &sc->sc_ic; in run_bulk_tx_callbackN()
3182 struct run_endpoint_queue *pq = &sc->sc_epq[index]; in run_bulk_tx_callbackN()
3202 data = STAILQ_FIRST(&pq->tx_qh); in run_bulk_tx_callbackN()
3206 STAILQ_REMOVE_HEAD(&pq->tx_qh, next); in run_bulk_tx_callbackN()
3208 m = data->m; in run_bulk_tx_callbackN()
3209 size = (sc->mac_ver == 0x5592) ? in run_bulk_tx_callbackN()
3210 sizeof(data->desc) + sizeof(uint32_t) : sizeof(data->desc); in run_bulk_tx_callbackN()
3211 if ((m->m_pkthdr.len + in run_bulk_tx_callbackN()
3214 "data overflow, %u bytes\n", m->m_pkthdr.len); in run_bulk_tx_callbackN()
3220 usbd_copy_in(pc, 0, &data->desc, size); in run_bulk_tx_callbackN()
3221 usbd_m_copy_in(pc, size, m, 0, m->m_pkthdr.len); in run_bulk_tx_callbackN()
3222 size += m->m_pkthdr.len; in run_bulk_tx_callbackN()
3224 * Align end on a 4-byte boundary, pad 8 bytes (CRC + in run_bulk_tx_callbackN()
3225 * 4-byte padding), and be sure to zero those trailing in run_bulk_tx_callbackN()
3228 usbd_frame_zero(pc, size, ((-size) & 3) + 8); in run_bulk_tx_callbackN()
3229 size += ((-size) & 3) + 8; in run_bulk_tx_callbackN()
3231 vap = data->ni->ni_vap; in run_bulk_tx_callbackN()
3234 struct run_tx_radiotap_header *tap = &sc->sc_txtap; in run_bulk_tx_callbackN()
3236 (struct rt2860_txwi *)(&data->desc + sizeof(struct rt2870_txd)); in run_bulk_tx_callbackN()
3243 tap->wt_flags = 0; in run_bulk_tx_callbackN()
3244 tap->wt_rate = rt2860_rates[data->ridx].rate; in run_bulk_tx_callbackN()
3245 tap->wt_hwqueue = index; in run_bulk_tx_callbackN()
3246 if (le16toh(txwi->phy) & RT2860_PHY_SHPRE) in run_bulk_tx_callbackN()
3247 tap->wt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; in run_bulk_tx_callbackN()
3249 tap->wt_flags |= IEEE80211_RADIOTAP_F_DATAPAD; in run_bulk_tx_callbackN()
3256 m->m_pkthdr.len, size, index); in run_bulk_tx_callbackN()
3272 if(data->ni != NULL) in run_bulk_tx_callbackN()
3273 vap = data->ni->ni_vap; in run_bulk_tx_callbackN()
3279 vap = TAILQ_FIRST(&ic->ic_vaps); in run_bulk_tx_callbackN()
3283 device_printf(sc->sc_dev, "device timeout\n"); in run_bulk_tx_callbackN()
3284 uint32_t i = RUN_CMDQ_GET(&sc->cmdq_store); in run_bulk_tx_callbackN()
3287 sc->cmdq[i].func = run_usb_timeout_cb; in run_bulk_tx_callbackN()
3288 sc->cmdq[i].arg0 = vap; in run_bulk_tx_callbackN()
3289 ieee80211_runtask(ic, &sc->cmdq_task); in run_bulk_tx_callbackN()
3305 if (pq->tx_nfree >= RUN_TX_RING_COUNT) { in run_bulk_tx_callbackN()
3352 struct mbuf *m = data->m; in run_set_tx_desc()
3353 struct ieee80211com *ic = &sc->sc_ic; in run_set_tx_desc()
3354 struct ieee80211vap *vap = data->ni->ni_vap; in run_set_tx_desc()
3360 uint8_t ridx = data->ridx; in run_set_tx_desc()
3366 txwisize = (sc->mac_ver == 0x5592) ? in run_set_tx_desc()
3368 xferlen = txwisize + m->m_pkthdr.len; in run_set_tx_desc()
3370 /* roundup to 32-bit alignment */ in run_set_tx_desc()
3373 txd = (struct rt2870_txd *)&data->desc; in run_set_tx_desc()
3374 txd->len = htole16(xferlen); in run_set_tx_desc()
3380 * are nicely aligned to 32-bit. So, no L2 padding. in run_set_tx_desc()
3389 txwi->len = htole16(m->m_pkthdr.len - pad); in run_set_tx_desc()
3393 (ic->ic_flags & IEEE80211_F_SHPREAMBLE)) in run_set_tx_desc()
3401 txwi->phy = htole16(mcs); in run_set_tx_desc()
3403 /* check if RTS/CTS or CTS-to-self protection is required */ in run_set_tx_desc()
3404 if (!IEEE80211_IS_MULTICAST(wh->i_addr1) && in run_set_tx_desc()
3405 ((m->m_pkthdr.len + IEEE80211_CRC_LEN > vap->iv_rtsthreshold) || in run_set_tx_desc()
3406 ((ic->ic_flags & IEEE80211_F_USEPROT) && in run_set_tx_desc()
3408 ((ic->ic_htprotmode == IEEE80211_PROT_RTSCTS) && in run_set_tx_desc()
3410 txwi->txop |= RT2860_TX_TXOP_HT; in run_set_tx_desc()
3412 txwi->txop |= RT2860_TX_TXOP_BACKOFF; in run_set_tx_desc()
3414 if (vap->iv_opmode != IEEE80211_M_STA && !IEEE80211_QOS_HAS_SEQ(wh)) in run_set_tx_desc()
3415 txwi->xflags |= RT2860_TX_NSEQ; in run_set_tx_desc()
3422 struct ieee80211com *ic = &sc->sc_ic; in run_tx()
3423 struct ieee80211vap *vap = ni->ni_vap; in run_tx()
3425 const struct ieee80211_txparam *tp = ni->ni_txparms; in run_tx()
3445 type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK; in run_tx()
3450 * Update 03-14-2009: some devices like the Planex GW-US300MiniS in run_tx()
3471 if (IEEE80211_IS_MULTICAST(wh->i_addr1) || in run_tx()
3472 type != IEEE80211_FC0_TYPE_DATA || m->m_flags & M_EAPOL) { in run_tx()
3474 ridx = (ic->ic_curmode == IEEE80211_MODE_11A || ic->ic_curmode == IEEE80211_MODE_11NA) ? in run_tx()
3478 if (tp->ucastrate != IEEE80211_FIXED_RATE_NONE) in run_tx()
3479 ridx = rn->fix_ridx; in run_tx()
3481 ridx = rn->amrr_ridx; in run_tx()
3485 if (!IEEE80211_IS_MULTICAST(wh->i_addr1) && in run_tx()
3489 if (ic->ic_flags & IEEE80211_F_SHPREAMBLE) in run_tx()
3493 USETW(wh->i_dur, dur); in run_tx()
3497 if (sc->sc_epq[qid].tx_nfree < 3) { in run_tx()
3499 return (-1); in run_tx()
3502 data = STAILQ_FIRST(&sc->sc_epq[qid].tx_fh); in run_tx()
3503 STAILQ_REMOVE_HEAD(&sc->sc_epq[qid].tx_fh, next); in run_tx()
3504 sc->sc_epq[qid].tx_nfree--; in run_tx()
3506 txd = (struct rt2870_txd *)&data->desc; in run_tx()
3507 txd->flags = qflags; in run_tx()
3509 txwi->xflags = xflags; in run_tx()
3510 if (IEEE80211_IS_MULTICAST(wh->i_addr1)) in run_tx()
3511 txwi->wcid = 0; in run_tx()
3513 txwi->wcid = (vap->iv_opmode == IEEE80211_M_STA) ? in run_tx()
3514 1 : RUN_AID2WCID(ni->ni_associd); in run_tx()
3517 txwi->flags = 0; in run_tx()
3518 txwi->txop = 0; in run_tx()
3520 data->m = m; in run_tx()
3521 data->ni = ni; in run_tx()
3522 data->ridx = ridx; in run_tx()
3529 * * TX_STA_CNT0 for all-TX-in-one stats. in run_tx()
3531 * To use FIFO stats, we need to store MCS into the driver-private in run_tx()
3539 if (sc->rvp_cnt > 1 || vap->iv_opmode == IEEE80211_M_HOSTAP || in run_tx()
3540 vap->iv_opmode == IEEE80211_M_MBSS) { in run_tx()
3542 txwi->len |= htole16(pid << RT2860_TX_PID_SHIFT); in run_tx()
3546 * USB devices, so we simulate FIFO-is-full interrupt here. in run_tx()
3556 if (sc->fifo_cnt++ == 10) { in run_tx()
3559 * with a non-sleepable lock, tcpinp. So, need to defer. in run_tx()
3561 uint32_t i = RUN_CMDQ_GET(&sc->cmdq_store); in run_tx()
3563 sc->cmdq[i].func = run_drain_fifo; in run_tx()
3564 sc->cmdq[i].arg0 = sc; in run_tx()
3565 ieee80211_runtask(ic, &sc->cmdq_task); in run_tx()
3569 STAILQ_INSERT_TAIL(&sc->sc_epq[qid].tx_qh, data, next); in run_tx()
3571 usbd_transfer_start(sc->sc_xfer[qid]); in run_tx()
3575 m->m_pkthdr.len + (int)(sizeof(struct rt2870_txd) + in run_tx()
3584 struct ieee80211com *ic = &sc->sc_ic; in run_tx_mgt()
3591 uint8_t ridx = rn->mgt_ridx; in run_tx_mgt()
3602 else if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) { in run_tx_mgt()
3605 dur = ieee80211_ack_duration(ic->ic_rt, rt2860_rates[ridx].rate, in run_tx_mgt()
3606 ic->ic_flags & IEEE80211_F_SHPREAMBLE); in run_tx_mgt()
3607 USETW(wh->i_dur, dur); in run_tx_mgt()
3610 if (sc->sc_epq[0].tx_nfree == 0) in run_tx_mgt()
3613 data = STAILQ_FIRST(&sc->sc_epq[0].tx_fh); in run_tx_mgt()
3614 STAILQ_REMOVE_HEAD(&sc->sc_epq[0].tx_fh, next); in run_tx_mgt()
3615 sc->sc_epq[0].tx_nfree--; in run_tx_mgt()
3617 txd = (struct rt2870_txd *)&data->desc; in run_tx_mgt()
3618 txd->flags = RT2860_TX_QSEL_EDCA; in run_tx_mgt()
3620 txwi->wcid = 0xff; in run_tx_mgt()
3621 txwi->flags = wflags; in run_tx_mgt()
3622 txwi->xflags = xflags; in run_tx_mgt()
3623 txwi->txop = 0; /* clear leftover garbage bits */ in run_tx_mgt()
3625 data->m = m; in run_tx_mgt()
3626 data->ni = ni; in run_tx_mgt()
3627 data->ridx = ridx; in run_tx_mgt()
3632 m->m_pkthdr.len + (int)(sizeof(struct rt2870_txd) + in run_tx_mgt()
3635 STAILQ_INSERT_TAIL(&sc->sc_epq[0].tx_qh, data, next); in run_tx_mgt()
3637 usbd_transfer_start(sc->sc_xfer[0]); in run_tx_mgt()
3646 struct ieee80211com *ic = ni->ni_ic; in run_sendprot()
3659 if (sc->sc_epq[0].tx_nfree == 0) in run_sendprot()
3665 if_inc_counter(ni->ni_vap->iv_ifp, IFCOUNTER_OERRORS, 1); in run_sendprot()
3670 protrate = ieee80211_ctl_rate(ic->ic_rt, rate); in run_sendprot()
3676 data = STAILQ_FIRST(&sc->sc_epq[0].tx_fh); in run_sendprot()
3677 STAILQ_REMOVE_HEAD(&sc->sc_epq[0].tx_fh, next); in run_sendprot()
3678 sc->sc_epq[0].tx_nfree--; in run_sendprot()
3680 txd = (struct rt2870_txd *)&data->desc; in run_sendprot()
3681 txd->flags = RT2860_TX_QSEL_EDCA; in run_sendprot()
3683 txwi->wcid = 0xff; in run_sendprot()
3684 txwi->flags = wflags; in run_sendprot()
3685 txwi->xflags = xflags; in run_sendprot()
3686 txwi->txop = 0; /* clear leftover garbage bits */ in run_sendprot()
3688 data->m = mprot; in run_sendprot()
3689 data->ni = ieee80211_ref_node(ni); in run_sendprot()
3695 data->ridx = ridx; in run_sendprot()
3700 m->m_pkthdr.len, rate); in run_sendprot()
3702 STAILQ_INSERT_TAIL(&sc->sc_epq[0].tx_qh, data, next); in run_sendprot()
3704 usbd_transfer_start(sc->sc_xfer[0]); in run_sendprot()
3713 struct ieee80211com *ic = ni->ni_ic; in run_tx_param()
3727 rate = params->ibp_rate0; in run_tx_param()
3728 if (!ieee80211_isratevalid(ic->ic_rt, rate)) { in run_tx_param()
3733 if ((params->ibp_flags & IEEE80211_BPF_NOACK) == 0) in run_tx_param()
3735 if (params->ibp_flags & (IEEE80211_BPF_RTS|IEEE80211_BPF_CTS)) { in run_tx_param()
3737 params->ibp_flags & IEEE80211_BPF_RTS ? in run_tx_param()
3747 if (sc->sc_epq[0].tx_nfree == 0) { in run_tx_param()
3753 data = STAILQ_FIRST(&sc->sc_epq[0].tx_fh); in run_tx_param()
3754 STAILQ_REMOVE_HEAD(&sc->sc_epq[0].tx_fh, next); in run_tx_param()
3755 sc->sc_epq[0].tx_nfree--; in run_tx_param()
3757 txd = (struct rt2870_txd *)&data->desc; in run_tx_param()
3758 txd->flags = RT2860_TX_QSEL_EDCA; in run_tx_param()
3760 txwi->wcid = 0xff; in run_tx_param()
3761 txwi->xflags = xflags; in run_tx_param()
3762 txwi->txop = opflags; in run_tx_param()
3763 txwi->flags = 0; /* clear leftover garbage bits */ in run_tx_param()
3765 data->m = m; in run_tx_param()
3766 data->ni = ni; in run_tx_param()
3771 data->ridx = ridx; in run_tx_param()
3776 m->m_pkthdr.len, rate); in run_tx_param()
3778 STAILQ_INSERT_TAIL(&sc->sc_epq[0].tx_qh, data, next); in run_tx_param()
3780 usbd_transfer_start(sc->sc_xfer[0]); in run_tx_param()
3789 struct run_softc *sc = ni->ni_ic->ic_softc; in run_raw_xmit()
3795 if (!(sc->sc_flags & RUN_RUNNING)) { in run_raw_xmit()
3828 struct run_softc *sc = ic->ic_softc; in run_transmit()
3832 if ((sc->sc_flags & RUN_RUNNING) == 0) { in run_transmit()
3836 error = mbufq_enqueue(&sc->sc_snd, m); in run_transmit()
3855 if ((sc->sc_flags & RUN_RUNNING) == 0) in run_start()
3858 while ((m = mbufq_dequeue(&sc->sc_snd)) != NULL) { in run_start()
3859 ni = (struct ieee80211_node *)m->m_pkthdr.rcvif; in run_start()
3861 mbufq_prepend(&sc->sc_snd, m); in run_start()
3870 struct run_softc *sc = ic->ic_softc; in run_parent()
3874 if (sc->sc_detached) { in run_parent()
3879 if (ic->ic_nrunning > 0) { in run_parent()
3880 if (!(sc->sc_flags & RUN_RUNNING)) { in run_parent()
3885 } else if ((sc->sc_flags & RUN_RUNNING) && sc->rvp_cnt <= 1) in run_parent()
3998 if (sc->mac_ver == 0x3572) { in run_set_agc()
4015 run_bbp_write(sc, 62, 0x37 - sc->lna[group]); in run_select_chan_group()
4016 run_bbp_write(sc, 63, 0x37 - sc->lna[group]); in run_select_chan_group()
4017 run_bbp_write(sc, 64, 0x37 - sc->lna[group]); in run_select_chan_group()
4018 if (sc->mac_ver < 0x3572) in run_select_chan_group()
4021 if (sc->mac_ver == 0x3593) { in run_select_chan_group()
4027 if (sc->ext_2ghz_lna) { in run_select_chan_group()
4028 if (sc->mac_ver >= 0x5390) in run_select_chan_group()
4035 if (sc->mac_ver == 0x5592) { in run_select_chan_group()
4053 } else if (sc->mac_ver >= 0x5390) in run_select_chan_group()
4057 (sc->mac_ver == 0x3593) ? 0x62 : 0x84); in run_select_chan_group()
4062 if (sc->mac_ver == 0x5592) { in run_select_chan_group()
4080 } else if (sc->mac_ver == 0x3572) in run_select_chan_group()
4084 (sc->mac_ver == 0x3593) ? 0x82 : 0xf2); in run_select_chan_group()
4085 if (sc->ext_5ghz_lna) in run_select_chan_group()
4098 if (sc->mac_ver == 0x3593) in run_select_chan_group()
4100 if (sc->nrxchains > 1) in run_select_chan_group()
4104 if (sc->ntxchains > 1) in run_select_chan_group()
4106 if (sc->mac_ver == 0x3593) { in run_select_chan_group()
4107 if (sc->ntxchains > 2) in run_select_chan_group()
4112 if (sc->ntxchains > 1) in run_select_chan_group()
4115 if (sc->mac_ver == 0x3572) { in run_select_chan_group()
4122 if (sc->mac_ver == 0x5592) { in run_select_chan_group()
4127 if (sc->mac_ver == 0x3593) { in run_select_chan_group()
4138 if (sc->mac_ver >= 0x3070) in run_select_chan_group()
4139 agc = 0x1c + sc->lna[0] * 2; in run_select_chan_group()
4141 agc = 0x2e + sc->lna[0]; in run_select_chan_group()
4143 if (sc->mac_ver == 0x5592) in run_select_chan_group()
4144 agc = 0x24 + sc->lna[group] * 2; in run_select_chan_group()
4145 else if (sc->mac_ver == 0x3572 || sc->mac_ver == 0x3593) in run_select_chan_group()
4146 agc = 0x22 + (sc->lna[group] * 5) / 3; in run_select_chan_group()
4148 agc = 0x32 + (sc->lna[group] * 5) / 3; in run_select_chan_group()
4165 if (sc->ntxchains == 1) in run_rt2870_set_chan()
4167 if (sc->nrxchains == 1) in run_rt2870_set_chan()
4169 else if (sc->nrxchains == 2) in run_rt2870_set_chan()
4173 txpow1 = sc->txpow1[i]; in run_rt2870_set_chan()
4174 txpow2 = sc->txpow2[i]; in run_rt2870_set_chan()
4178 r4 = (rfprog[i].r4 & ~(0x001f87c0)) | (sc->freq << 15); in run_rt2870_set_chan()
4200 /* Set frequency offset and Tx1 power. */ in run_rt2870_set_chan()
4235 txpow1 = sc->txpow1[i]; in run_rt3070_set_chan()
4236 txpow2 = sc->txpow2[i]; in run_rt3070_set_chan()
4261 if (sc->ntxchains == 1) in run_rt3070_set_chan()
4263 else if (sc->ntxchains == 2) in run_rt3070_set_chan()
4265 if (sc->nrxchains == 1) in run_rt3070_set_chan()
4267 else if (sc->nrxchains == 2) in run_rt3070_set_chan()
4271 /* set RF offset */ in run_rt3070_set_chan()
4273 rf = (rf & ~0x7f) | sc->freq; in run_rt3070_set_chan()
4278 rf = (rf & ~0x3f) | sc->rf24_20mhz; in run_rt3070_set_chan()
4281 rf = (rf & ~0x3f) | sc->rf24_20mhz; in run_rt3070_set_chan()
4301 txpow1 = sc->txpow1[i]; in run_rt3572_set_chan()
4302 txpow2 = sc->txpow2[i]; in run_rt3572_set_chan()
4305 run_bbp_write(sc, 25, sc->bbp25); in run_rt3572_set_chan()
4306 run_bbp_write(sc, 26, sc->bbp26); in run_rt3572_set_chan()
4343 if (sc->ntxchains == 1) in run_rt3572_set_chan()
4345 else if (sc->ntxchains == 2) in run_rt3572_set_chan()
4347 if (sc->nrxchains == 1) in run_rt3572_set_chan()
4349 else if (sc->nrxchains == 2) in run_rt3572_set_chan()
4353 /* set RF offset */ in run_rt3572_set_chan()
4355 rf = (rf & ~0x7f) | sc->freq; in run_rt3572_set_chan()
4359 rf = sc->rf24_20mhz; in run_rt3572_set_chan()
4381 rf = 0x48 | sc->txmixgain_2ghz; in run_rt3572_set_chan()
4383 rf = 0x78 | sc->txmixgain_5ghz; in run_rt3572_set_chan()
4450 txpow1 = sc->txpow1[i]; in run_rt3593_set_chan()
4451 txpow2 = sc->txpow2[i]; in run_rt3593_set_chan()
4452 txpow3 = (sc->ntxchains == 3) ? sc->txpow3[i] : 0; in run_rt3593_set_chan()
4455 run_bbp_write(sc, 25, sc->bbp25); in run_rt3593_set_chan()
4456 run_bbp_write(sc, 26, sc->bbp26); in run_rt3593_set_chan()
4494 if (sc->ntxchains == 3) in run_rt3593_set_chan()
4505 h20mhz = (sc->rf24_20mhz & 0x20) >> 5; in run_rt3593_set_chan()
4522 /* Set vco bias current control. */ in run_rt3593_set_chan()
4570 /* Enable VCO calibration. */ in run_rt3593_set_chan()
4610 txpow1 = sc->txpow1[i]; in run_rt5390_set_chan()
4611 txpow2 = sc->txpow2[i]; in run_rt5390_set_chan()
4626 if (sc->mac_ver == 0x5392) { in run_rt5390_set_chan()
4637 if (sc->mac_ver == 0x5392) in run_rt5390_set_chan()
4641 if (sc->mac_ver != 0x5392) { in run_rt5390_set_chan()
4652 if (sc->mac_ver == 0x5392) { in run_rt5390_set_chan()
4654 if (sc->mac_rev >= 0x0223) { in run_rt5390_set_chan()
4683 if (sc->mac_rev >= 0x0502) { in run_rt5390_set_chan()
4703 /* Enable VCO calibration. */ in run_rt5390_set_chan()
4726 txpow1 = sc->txpow1[i]; in run_rt5592_set_chan()
4727 txpow2 = sc->txpow2[i]; in run_rt5592_set_chan()
4736 run_rt3070_rf_write(sc, 8, freqs->n & 0xff); in run_rt5592_set_chan()
4739 rf |= ((freqs->n & 0x0100) >> 8) << 4; in run_rt5592_set_chan()
4745 rf |= (freqs->k & 0x0f); in run_rt5592_set_chan()
4751 rf |= ((freqs->m - 0x8) & 0x3) << 2; in run_rt5592_set_chan()
4755 rf |= (((freqs->m - 0x8) & 0x4) >> 2) << 7; in run_rt5592_set_chan()
4761 rf |= (freqs->r - 0x1); in run_rt5592_set_chan()
4779 * G-band bit<7:6>=1:0, bit<5:0> range from 0x0 ~ 0x27. in run_rt5592_set_chan()
4799 * A-band bit<7:6>=1:1, bit<5:0> range from 0x0 ~ 0x2b. in run_rt5592_set_chan()
4826 if (sc->ntxchains > 1) in run_rt5592_set_chan()
4828 if (sc->nrxchains > 1) in run_rt5592_set_chan()
4840 /* Enable VCO calibration. */ in run_rt5592_set_chan()
4853 if (sc->rf_rev == RT5390_RF_5370) { in run_set_rx_antenna()
4862 if (sc->rf_rev == RT5390_RF_5370) { in run_set_rx_antenna()
4876 struct ieee80211com *ic = &sc->sc_ic; in run_set_chan()
4883 if (sc->mac_ver == 0x5592) in run_set_chan()
4885 else if (sc->mac_ver >= 0x5390) in run_set_chan()
4887 else if (sc->mac_ver == 0x3593) in run_set_chan()
4889 else if (sc->mac_ver == 0x3572) in run_set_chan()
4891 else if (sc->mac_ver >= 0x3070) in run_set_chan()
4912 if (sc->mac_ver >= 0x5392) in run_set_chan()
4921 struct run_softc *sc = ic->ic_softc; in run_set_channel()
4924 run_set_chan(sc, ic->ic_curchan); in run_set_channel()
4934 struct run_softc *sc = ic->ic_softc; in run_getradiocaps()
4940 if (sc->rf_rev != RT3070_RF_2020) in run_getradiocaps()
4946 if (sc->rf_rev == RT2860_RF_2750 || sc->rf_rev == RT2860_RF_2850 || in run_getradiocaps()
4947 sc->rf_rev == RT3070_RF_3052 || sc->rf_rev == RT3593_RF_3053 || in run_getradiocaps()
4948 sc->rf_rev == RT5592_RF_5592) { in run_getradiocaps()
4950 if (sc->rf_rev != RT3070_RF_2020) in run_getradiocaps()
4961 struct run_softc *sc = ic->ic_softc; in run_scan_start()
4977 struct run_softc *sc = ic->ic_softc; in run_scan_end()
4982 run_set_bssid(sc, sc->sc_bssid); in run_scan_end()
4991 * (non-sleepable thread)
4996 struct ieee80211com *ic = vap->iv_ic; in run_update_beacon()
4997 struct ieee80211_beacon_offsets *bo = &vap->iv_bcn_off; in run_update_beacon()
4998 struct ieee80211_node *ni = vap->iv_bss; in run_update_beacon()
4999 struct run_softc *sc = ic->ic_softc; in run_update_beacon()
5018 setbit(bo->bo_flags, item); in run_update_beacon()
5019 if (rvp->beacon_mbuf == NULL) { in run_update_beacon()
5020 rvp->beacon_mbuf = ieee80211_beacon_alloc(ni); in run_update_beacon()
5021 if (rvp->beacon_mbuf == NULL) in run_update_beacon()
5024 ieee80211_beacon_update(ni, rvp->beacon_mbuf, mcast); in run_update_beacon()
5026 i = RUN_CMDQ_GET(&sc->cmdq_store); in run_update_beacon()
5028 sc->cmdq[i].func = run_update_beacon_cb; in run_update_beacon()
5029 sc->cmdq[i].arg0 = vap; in run_update_beacon()
5030 ieee80211_runtask(ic, &sc->cmdq_task); in run_update_beacon()
5039 struct ieee80211_node *ni = vap->iv_bss; in run_update_beacon_cb()
5041 struct ieee80211com *ic = vap->iv_ic; in run_update_beacon_cb()
5042 struct run_softc *sc = ic->ic_softc; in run_update_beacon_cb()
5048 if (ni->ni_chan == IEEE80211_CHAN_ANYC) in run_update_beacon_cb()
5050 if (ic->ic_bsschan == IEEE80211_CHAN_ANYC) in run_update_beacon_cb()
5057 if (rvp->beacon_mbuf == NULL) { in run_update_beacon_cb()
5058 rvp->beacon_mbuf = ieee80211_beacon_alloc(ni); in run_update_beacon_cb()
5059 if (rvp->beacon_mbuf == NULL) in run_update_beacon_cb()
5062 m = rvp->beacon_mbuf; in run_update_beacon_cb()
5066 txwi.len = htole16(m->m_pkthdr.len); in run_update_beacon_cb()
5069 ridx = (ic->ic_curmode == IEEE80211_MODE_11A) ? in run_update_beacon_cb()
5078 txwisize = (sc->mac_ver == 0x5592) ? in run_update_beacon_cb()
5080 run_write_region_1(sc, RT2860_BCN_BASE(rvp->rvp_id), (uint8_t *)&txwi, in run_update_beacon_cb()
5082 run_write_region_1(sc, RT2860_BCN_BASE(rvp->rvp_id) + txwisize, in run_update_beacon_cb()
5083 mtod(m, uint8_t *), (m->m_pkthdr.len + 1) & ~1); in run_update_beacon_cb()
5089 struct run_softc *sc = ic->ic_softc; in run_updateprot()
5092 i = RUN_CMDQ_GET(&sc->cmdq_store); in run_updateprot()
5094 sc->cmdq[i].func = run_updateprot_cb; in run_updateprot()
5095 sc->cmdq[i].arg0 = ic; in run_updateprot()
5096 ieee80211_runtask(ic, &sc->cmdq_task); in run_updateprot()
5103 struct run_softc *sc = ic->ic_softc; in run_updateprot_cb()
5108 tmp |= (ic->ic_curmode == IEEE80211_MODE_11A) ? in run_updateprot_cb()
5114 if (ic->ic_flags & IEEE80211_F_USEPROT) { in run_updateprot_cb()
5115 if (ic->ic_protmode == IEEE80211_PROT_RTSCTS) in run_updateprot_cb()
5117 else if (ic->ic_protmode == IEEE80211_PROT_CTSONLY) in run_updateprot_cb()
5127 struct run_softc *sc = vap->iv_ic->ic_softc; in run_usb_timeout_cb()
5131 if(vap->iv_state == IEEE80211_S_RUN && in run_usb_timeout_cb()
5132 vap->iv_opmode != IEEE80211_M_STA) in run_usb_timeout_cb()
5134 else if (vap->iv_state == IEEE80211_S_SCAN) { in run_usb_timeout_cb()
5153 * can run into a livelock and start sending CTS-to-self frames like in run_reset_livelock()
5160 "CTS-to-self livelock detected\n"); in run_reset_livelock()
5176 if (sc->sc_ic.ic_promisc > 0) in run_update_promisc_locked()
5182 (sc->sc_ic.ic_promisc > 0) ? "entering" : "leaving"); in run_update_promisc_locked()
5188 struct run_softc *sc = ic->ic_softc; in run_update_promisc()
5190 if ((sc->sc_flags & RUN_RUNNING) == 0) in run_update_promisc()
5201 struct ieee80211com *ic = &sc->sc_ic; in run_enable_tsf_sync()
5202 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); in run_enable_tsf_sync()
5206 RUN_VAP(vap)->rvp_id, ic->ic_opmode); in run_enable_tsf_sync()
5210 tmp |= vap->iv_bss->ni_intval * 16; in run_enable_tsf_sync()
5213 if (ic->ic_opmode == IEEE80211_M_STA) { in run_enable_tsf_sync()
5219 } else if (ic->ic_opmode == IEEE80211_M_IBSS) { in run_enable_tsf_sync()
5226 } else if (ic->ic_opmode == IEEE80211_M_HOSTAP || in run_enable_tsf_sync()
5227 ic->ic_opmode == IEEE80211_M_MBSS) { in run_enable_tsf_sync()
5277 OFDM(6) << 28 | /* 54->48 */ in run_enable_mrr()
5278 OFDM(5) << 24 | /* 48->36 */ in run_enable_mrr()
5279 OFDM(4) << 20 | /* 36->24 */ in run_enable_mrr()
5280 OFDM(3) << 16 | /* 24->18 */ in run_enable_mrr()
5281 OFDM(2) << 12 | /* 18->12 */ in run_enable_mrr()
5282 OFDM(1) << 8 | /* 12-> 9 */ in run_enable_mrr()
5283 OFDM(0) << 4 | /* 9-> 6 */ in run_enable_mrr()
5284 OFDM(0)); /* 6-> 6 */ in run_enable_mrr()
5287 CCK(2) << 12 | /* 11->5.5 */ in run_enable_mrr()
5288 CCK(1) << 8 | /* 5.5-> 2 */ in run_enable_mrr()
5289 CCK(0) << 4 | /* 2-> 1 */ in run_enable_mrr()
5290 CCK(0)); /* 1-> 1 */ in run_enable_mrr()
5298 struct ieee80211com *ic = &sc->sc_ic; in run_set_txpreamble()
5302 if (ic->ic_flags & IEEE80211_F_SHPREAMBLE) in run_set_txpreamble()
5312 struct ieee80211com *ic = &sc->sc_ic; in run_set_basicrates()
5315 if (ic->ic_curmode == IEEE80211_MODE_11B) in run_set_basicrates()
5317 else if (ic->ic_curmode == IEEE80211_MODE_11A) in run_set_basicrates()
5327 which | (sc->leds & 0x7f)); in run_set_leds()
5351 struct run_softc *sc = ic->ic_softc; in run_updateslot()
5354 i = RUN_CMDQ_GET(&sc->cmdq_store); in run_updateslot()
5356 sc->cmdq[i].func = run_updateslot_cb; in run_updateslot()
5357 sc->cmdq[i].arg0 = ic; in run_updateslot()
5358 ieee80211_runtask(ic, &sc->cmdq_task); in run_updateslot()
5368 struct run_softc *sc = ic->ic_softc; in run_updateslot_cb()
5385 struct ieee80211com *ic = &sc->sc_ic; in run_rssi2dbm()
5386 struct ieee80211_channel *c = ic->ic_curchan; in run_rssi2dbm()
5391 delta = sc->rssi_5ghz[rxchain]; in run_rssi2dbm()
5395 delta -= sc->lna[1]; in run_rssi2dbm()
5397 delta -= sc->lna[2]; in run_rssi2dbm()
5399 delta -= sc->lna[3]; in run_rssi2dbm()
5401 delta = sc->rssi_2ghz[rxchain] - sc->lna[0]; in run_rssi2dbm()
5403 return (-12 - delta - rssi); in run_rssi2dbm()
5414 if (sc->nrxchains > 1) in run_rt5390_bbp_init()
5421 if (sc->mac_ver == 0x5592) { in run_rt5390_bbp_init()
5436 if (sc->mac_ver == 0x5392) { in run_rt5390_bbp_init()
5450 if (sc->mac_ver == 0x5592 && sc->mac_rev >= 0x0221) { in run_rt5390_bbp_init()
5456 if (sc->mac_ver == 0x5390) in run_rt5390_bbp_init()
5459 /* Initialize Rx CCK/OFDM frequency offset report. */ in run_rt5390_bbp_init()
5481 if (sc->mac_ver >= 0x5390) in run_bbp_init()
5490 if (sc->mac_ver == 0x3593) { in run_bbp_init()
5499 if (sc->mac_ver == 0x2860 && sc->mac_rev != 0x0101) in run_bbp_init()
5502 if (sc->mac_ver >= 0x3070 && (sc->mac_ver != 0x3593 && in run_bbp_init()
5503 sc->mac_ver != 0x5592)) { in run_bbp_init()
5507 } else if (sc->mac_ver == 0x2860 && sc->mac_rev == 0x0100) { in run_bbp_init()
5528 if (sc->mac_ver == 0x3572) { in run_rt3070_rf_init()
5540 if (sc->mac_ver == 0x3070 && sc->mac_rev < 0x0201) { in run_rt3070_rf_init()
5550 } else if (sc->mac_ver == 0x3071) { in run_rt3070_rf_init()
5557 if (sc->mac_rev < 0x0211) in run_rt3070_rf_init()
5567 } else if (sc->mac_ver == 0x3572) { in run_rt3070_rf_init()
5576 if (sc->mac_rev < 0x0211 || !sc->patch_dac) { in run_rt3070_rf_init()
5589 sc->rf24_20mhz = 0x1f; /* default value */ in run_rt3070_rf_init()
5590 target = (sc->mac_ver < 0x3071) ? 0x16 : 0x13; in run_rt3070_rf_init()
5591 run_rt3070_filter_calib(sc, 0x07, target, &sc->rf24_20mhz); in run_rt3070_rf_init()
5600 sc->rf24_40mhz = 0x2f; /* default value */ in run_rt3070_rf_init()
5601 target = (sc->mac_ver < 0x3071) ? 0x19 : 0x15; in run_rt3070_rf_init()
5602 run_rt3070_filter_calib(sc, 0x27, target, &sc->rf24_40mhz); in run_rt3070_rf_init()
5608 if (sc->mac_ver == 0x3572) { in run_rt3070_rf_init()
5610 run_bbp_read(sc, 25, &sc->bbp25); in run_rt3070_rf_init()
5611 run_bbp_read(sc, 26, &sc->bbp26); in run_rt3070_rf_init()
5612 } else if (sc->mac_rev < 0x0201 || sc->mac_rev < 0x0211) in run_rt3070_rf_init()
5618 if (sc->mac_ver == 0x3070 || sc->mac_ver == 0x3071) { in run_rt3070_rf_init()
5621 if ((sc->mac_ver == 0x3070 || in run_rt3070_rf_init()
5622 (sc->mac_ver == 0x3071 && sc->mac_rev >= 0x0211)) && in run_rt3070_rf_init()
5623 !sc->ext_2ghz_lna) in run_rt3070_rf_init()
5625 mingain = (sc->mac_ver == 0x3070) ? 1 : 2; in run_rt3070_rf_init()
5626 if (sc->txmixgain_2ghz >= mingain) in run_rt3070_rf_init()
5627 rf = (rf & ~0x7) | sc->txmixgain_2ghz; in run_rt3070_rf_init()
5631 if (sc->mac_ver == 0x3071) { in run_rt3070_rf_init()
5647 if (sc->mac_ver == 0x3070 || sc->mac_ver == 0x3071) { in run_rt3070_rf_init()
5651 if (sc->mac_rev < 0x0211) in run_rt3070_rf_init()
5679 /* Initialize RF frequency offset. */ in run_rt3593_rf_init()
5696 sc->rf24_20mhz = 0x1f; in run_rt3593_rf_init()
5697 sc->rf24_40mhz = 0x2f; in run_rt3593_rf_init()
5700 run_bbp_read(sc, 25, &sc->bbp25); in run_rt3593_rf_init()
5701 run_bbp_read(sc, 26, &sc->bbp26); in run_rt3593_rf_init()
5715 if (sc->mac_ver == 0x5390) { in run_rt5390_rf_init()
5726 if (sc->mac_ver == 0x5592) { in run_rt5390_rf_init()
5731 /* Initialize RF frequency offset. */ in run_rt5390_rf_init()
5733 } else if (sc->mac_ver == 0x5392) { in run_rt5390_rf_init()
5738 if (sc->mac_rev >= 0x0223) { in run_rt5390_rf_init()
5751 if (sc->mac_rev >= 0x0502) { in run_rt5390_rf_init()
5761 sc->rf24_20mhz = 0x1f; /* default value */ in run_rt5390_rf_init()
5762 sc->rf24_40mhz = (sc->mac_ver == 0x5592) ? 0 : 0x2f; in run_rt5390_rf_init()
5764 if (sc->mac_rev < 0x0211) in run_rt5390_rf_init()
5811 delta = bbp55_pb - bbp55_sb; in run_rt3070_filter_calib()
5821 rf24--; /* backtrack */ in run_rt3070_filter_calib()
5842 if (sc->mac_ver == 0x3572) { in run_rt3070_rf_setup()
5844 if (sc->mac_rev >= 0x0201) in run_rt3070_rf_setup()
5848 if (sc->ntxchains == 1) in run_rt3070_rf_setup()
5850 if (sc->nrxchains == 1) in run_rt3070_rf_setup()
5854 if (sc->mac_rev >= 0x0211) { in run_rt3070_rf_setup()
5861 rf = (rf & ~0x07) | sc->txmixgain_2ghz; in run_rt3070_rf_setup()
5864 } else if (sc->mac_ver == 0x3071) { in run_rt3070_rf_setup()
5865 if (sc->mac_rev >= 0x0211) { in run_rt3070_rf_setup()
5875 if (sc->ntxchains == 1) in run_rt3070_rf_setup()
5877 if (sc->nrxchains == 1) in run_rt3070_rf_setup()
5882 if (sc->mac_rev < 0x0211) { in run_rt3070_rf_setup()
5884 sc->patch_dac ? 0x2c : 0x0f); in run_rt3070_rf_setup()
5888 } else if (sc->mac_ver == 0x3070) { in run_rt3070_rf_setup()
5889 if (sc->mac_rev >= 0x0201) { in run_rt3070_rf_setup()
5898 if (sc->mac_rev < 0x0201) { in run_rt3070_rf_setup()
5906 if (sc->mac_ver >= 0x3071) { in run_rt3070_rf_setup()
5908 if (sc->rf[i].reg == 0 || sc->rf[i].reg == 0xff) in run_rt3070_rf_setup()
5910 run_rt3070_rf_write(sc, sc->rf[i].reg, sc->rf[i].val); in run_rt3070_rf_setup()
5920 if (sc->mac_rev >= 0x0211) { in run_rt3593_rf_setup()
5925 if (sc->mac_rev < 0x0211) { in run_rt3593_rf_setup()
5927 sc->patch_dac ? 0x2c : 0x0f); in run_rt3593_rf_setup()
5936 ((sc->txmixgain_2ghz & 0x07) << 2); in run_rt3593_rf_setup()
5954 if (sc->nrxchains > 1) in run_rt3593_rf_setup()
5990 if (sc->mac_rev >= 0x0211) { in run_rt5390_rf_setup()
5994 if (sc->mac_ver != 0x5592) { in run_rt5390_rf_setup()
6002 if (sc->ntxchains == 1) in run_rt5390_rf_setup()
6004 if (sc->nrxchains == 1) in run_rt5390_rf_setup()
6022 if (sc->mac_ver != 0x5592) { in run_rt5390_rf_setup()
6024 if (sc->mac_rev < 0x0211) { in run_rt5390_rf_setup()
6026 sc->patch_dac ? 0x2c : 0x0f); in run_rt5390_rf_setup()
6035 struct ieee80211com *ic = &sc->sc_ic; in run_txrx_enable()
6062 if (ic->ic_opmode != IEEE80211_M_MONITOR) { in run_txrx_enable()
6067 if (ic->ic_opmode == IEEE80211_M_STA) in run_txrx_enable()
6085 rf = (rf & ~0x7f) | (sc->freq & 0x7f); in run_adjust_freq_offset()
6095 struct ieee80211com *ic = &sc->sc_ic; in run_init_locked()
6096 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); in run_init_locked()
6103 if (ic->ic_nrunning > 1) in run_init_locked()
6109 device_printf(sc->sc_dev, "could not load 8051 microcode\n"); in run_init_locked()
6124 run_setup_tx_list(sc, &sc->sc_epq[i]); in run_init_locked()
6126 run_set_macaddr(sc, vap ? vap->iv_myaddr : ic->ic_macaddr); in run_init_locked()
6136 device_printf(sc->sc_dev, "timeout waiting for DMA engine\n"); in run_init_locked()
6143 /* turn off PME_OEN to solve high-current issue */ in run_init_locked()
6152 device_printf(sc->sc_dev, "could not reset chipset\n"); in run_init_locked()
6160 if (sc->txpow20mhz[ridx] == 0xffffffff) in run_init_locked()
6162 run_write(sc, RT2860_TX_PWR_CFG(ridx), sc->txpow20mhz[ridx]); in run_init_locked()
6171 if (sc->mac_ver >= 0x5390) { in run_init_locked()
6174 if (sc->mac_ver >= 0x5392) { in run_init_locked()
6176 if (sc->mac_ver == 0x5592) { in run_init_locked()
6184 } else if (sc->mac_ver == 0x3593) { in run_init_locked()
6187 } else if (sc->mac_ver >= 0x3070) { in run_init_locked()
6210 device_printf(sc->sc_dev, "could not initialize BBP\n"); in run_init_locked()
6223 if (sc->cmdq_key_set != RUN_CMDQ_GO) { in run_init_locked()
6234 if (sc->mac_rev != 0x0101) in run_init_locked()
6240 /* write vendor-specific BBP values (from EEPROM) */ in run_init_locked()
6241 if (sc->mac_ver < 0x3593) { in run_init_locked()
6243 if (sc->bbp[i].reg == 0 || sc->bbp[i].reg == 0xff) in run_init_locked()
6245 run_bbp_write(sc, sc->bbp[i].reg, sc->bbp[i].val); in run_init_locked()
6250 if (sc->rf_rev == RT3070_RF_3020 || sc->rf_rev == RT5390_RF_5370) in run_init_locked()
6254 (void)run_mcu_cmd(sc, RT2860_MCU_CMD_LED1, sc->led[0]); in run_init_locked()
6255 (void)run_mcu_cmd(sc, RT2860_MCU_CMD_LED2, sc->led[1]); in run_init_locked()
6256 (void)run_mcu_cmd(sc, RT2860_MCU_CMD_LED3, sc->led[2]); in run_init_locked()
6258 if (sc->mac_ver >= 0x5390) in run_init_locked()
6260 else if (sc->mac_ver == 0x3593) in run_init_locked()
6262 else if (sc->mac_ver >= 0x3070) in run_init_locked()
6265 /* disable non-existing Rx chains */ in run_init_locked()
6268 if (sc->nrxchains == 2) in run_init_locked()
6270 else if (sc->nrxchains == 3) in run_init_locked()
6274 /* disable non-existing Tx chains */ in run_init_locked()
6276 if (sc->ntxchains == 1) in run_init_locked()
6280 if (sc->mac_ver >= 0x5390) in run_init_locked()
6282 else if (sc->mac_ver == 0x3593) in run_init_locked()
6284 else if (sc->mac_ver >= 0x3070) in run_init_locked()
6288 run_set_chan(sc, ic->ic_curchan); in run_init_locked()
6300 sc->sc_flags |= RUN_RUNNING; in run_init_locked()
6301 sc->cmdq_run = RUN_CMDQ_GO; in run_init_locked()
6304 usbd_xfer_set_stall(sc->sc_xfer[i]); in run_init_locked()
6306 usbd_transfer_start(sc->sc_xfer[RUN_BULK_RX]); in run_init_locked()
6327 if (sc->sc_flags & RUN_RUNNING) in run_stop()
6330 sc->sc_flags &= ~RUN_RUNNING; in run_stop()
6332 sc->ratectl_run = RUN_RATECTL_OFF; in run_stop()
6333 sc->cmdq_run = sc->cmdq_key_set; in run_stop()
6338 usbd_transfer_drain(sc->sc_xfer[i]); in run_stop()
6344 if (sc->rx_m != NULL) { in run_stop()
6345 m_free(sc->rx_m); in run_stop()
6346 sc->rx_m = NULL; in run_stop()
6363 device_printf(sc->sc_dev, "timeout waiting for DMA engine\n"); in run_stop()
6396 run_unsetup_tx_list(sc, &sc->sc_epq[i]); in run_stop()
6402 usb_pause_mtx(mtx_owned(&sc->sc_mtx) ? in run_delay()
6403 &sc->sc_mtx : NULL, USB_MS_TO_TICKS(ms)); in run_delay()
6417 /* For now, no A-MPDU TX support in the driver */ in run_ampdu_enable()