Lines Matching +full:ssc +full:- +full:block +full:- +full:bus
3 /*-
23 * o tx a-mpdu
25 * o power-save operation
39 #include <sys/bus.h>
79 device_printf((_sc)->sc_dev, __VA_ARGS__); \
290 /* XXX hard-coded */
351 if (uaa->usb_mode != USB_MODE_HOST ||
352 uaa->info.bIfaceIndex != 0 ||
353 uaa->info.bConfigIndex != 0)
373 * notification from net80211 that it'd like to do A-MPDU on the given TID.
383 struct rsu_softc *sc = ni->ni_ic->ic_softc;
393 req.tid = htole32(tap->txa_tid);
396 if (ieee80211_ampdu_tx_request_ext(ni, tap->txa_tid) != 1)
402 tap->txa_tid);
408 (void) ieee80211_ampdu_tx_request_active_ext(ni, tap->txa_tid, 0);
414 (void) ieee80211_ampdu_tx_request_active_ext(ni, tap->txa_tid, 1);
433 struct ieee80211com *ic = &sc->sc_ic;
440 sc->sc_udev = uaa->device;
441 sc->sc_dev = self;
442 sc->sc_rx_checksum_enable = 1;
444 sc->sc_ht = !! (USB_GET_DRIVER_INFO(uaa) & RSU_HT_SUPPORTED);
447 iface = usbd_get_iface(sc->sc_udev, 0);
448 sc->sc_nendpoints = iface->idesc->bNumEndpoints;
450 /* Endpoints are hard-coded for now, so enforce 4-endpoint only */
451 if (sc->sc_nendpoints != 4) {
452 device_printf(sc->sc_dev,
453 "the driver currently only supports 4-endpoint devices\n");
457 mtx_init(&sc->sc_mtx, device_get_nameunit(self), MTX_NETWORK_LOCK,
460 TIMEOUT_TASK_INIT(taskqueue_thread, &sc->calib_task, 0,
462 TASK_INIT(&sc->del_key_task, 0, rsu_delete_key_pair_cb, sc);
463 TASK_INIT(&sc->tx_task, 0, rsu_tx_task, sc);
464 mbufq_init(&sc->sc_snd, ifqmaxlen);
469 device_printf(sc->sc_dev, "could not allocate Rx buffers\n");
475 device_printf(sc->sc_dev, "could not allocate Tx buffers\n");
481 error = usbd_transfer_setup(uaa->device, &iface_index, sc->sc_xfer,
482 rsu_config, RSU_N_TRANSFER, sc, &sc->sc_mtx);
484 device_printf(sc->sc_dev,
491 sc->cut = MS(rsu_read_4(sc, R92S_PMC_FSM), R92S_PMC_FSM_CUT);
492 if (sc->cut != 3)
493 sc->cut = (sc->cut >> 1) + 1;
502 switch (sc->rom[84]) {
504 sc->sc_rftype = RTL8712_RFCONFIG_1T1R;
505 sc->sc_nrxstream = 1;
506 sc->sc_ntxstream = 1;
510 sc->sc_rftype = RTL8712_RFCONFIG_1T2R;
511 sc->sc_nrxstream = 2;
512 sc->sc_ntxstream = 1;
516 sc->sc_rftype = RTL8712_RFCONFIG_2T2R;
517 sc->sc_nrxstream = 2;
518 sc->sc_ntxstream = 2;
522 sc->sc_rftype = RTL8712_RFCONFIG_1T2R;
523 sc->sc_nrxstream = 2;
524 sc->sc_ntxstream = 1;
528 device_printf(sc->sc_dev,
531 sc->rom[84]);
535 IEEE80211_ADDR_COPY(ic->ic_macaddr, &sc->rom[0x12]);
536 device_printf(self, "MAC/BB RTL8712 cut %d %s\n", sc->cut, rft);
538 ic->ic_softc = sc;
539 ic->ic_name = device_get_nameunit(self);
540 ic->ic_phytype = IEEE80211_T_OFDM; /* Not only, but not used. */
541 ic->ic_opmode = IEEE80211_M_STA; /* Default to BSS mode. */
544 ic->ic_caps =
555 ic->ic_cryptocaps =
561 if (sc->sc_ht) {
562 device_printf(sc->sc_dev, "%s: enabling 11n\n", __func__);
565 ic->ic_htcaps = IEEE80211_HTC_HT |
572 ic->ic_htcaps |= IEEE80211_HTCAP_CHWIDTH40;
575 ic->ic_txstream = sc->sc_ntxstream;
576 ic->ic_rxstream = sc->sc_nrxstream;
578 ic->ic_flags_ext |= IEEE80211_FEXT_SCAN_OFFLOAD;
580 rsu_getradiocaps(ic, IEEE80211_CHAN_MAX, &ic->ic_nchans,
581 ic->ic_channels);
584 ic->ic_raw_xmit = rsu_raw_xmit;
585 ic->ic_scan_start = rsu_scan_start;
586 ic->ic_scan_end = rsu_scan_end;
587 ic->ic_getradiocaps = rsu_getradiocaps;
588 ic->ic_set_channel = rsu_set_channel;
589 ic->ic_scan_curchan = rsu_scan_curchan;
590 ic->ic_scan_mindwell = rsu_scan_mindwell;
591 ic->ic_vap_create = rsu_vap_create;
592 ic->ic_vap_delete = rsu_vap_delete;
593 ic->ic_update_promisc = rsu_update_promisc;
594 ic->ic_update_mcast = rsu_update_mcast;
595 ic->ic_ioctl = rsu_ioctl_net;
596 ic->ic_parent = rsu_parent;
597 ic->ic_transmit = rsu_transmit;
598 ic->ic_send_mgmt = rsu_send_mgmt;
599 ic->ic_update_chw = rsu_update_chw;
600 ic->ic_ampdu_enable = rsu_ampdu_enable;
601 ic->ic_wme.wme_update = rsu_wme_update;
603 ieee80211_radiotap_attach(ic, &sc->sc_txtap.wt_ihdr,
604 sizeof(sc->sc_txtap), RSU_TX_RADIOTAP_PRESENT,
605 &sc->sc_rxtap.wr_ihdr, sizeof(sc->sc_rxtap),
614 usbd_transfer_unsetup(sc->sc_xfer, RSU_N_TRANSFER);
616 mtx_destroy(&sc->sc_mtx);
624 struct ieee80211com *ic = &sc->sc_ic;
628 usbd_transfer_unsetup(sc->sc_xfer, RSU_N_TRANSFER);
643 taskqueue_drain_timeout(taskqueue_thread, &sc->calib_task);
644 taskqueue_drain(taskqueue_thread, &sc->del_key_task);
645 taskqueue_drain(taskqueue_thread, &sc->tx_task);
648 mtx_destroy(&sc->sc_mtx);
662 while (ntries--) {
663 err = usbd_do_request_flags(sc->sc_udev, &sc->sc_mtx,
682 struct rsu_softc *sc = ic->ic_softc;
687 if (!TAILQ_EMPTY(&ic->ic_vaps)) /* only one at a time */
691 vap = &uvp->vap;
700 ifp = vap->iv_ifp;
703 if (sc->sc_rx_checksum_enable)
708 uvp->newstate = vap->iv_newstate;
710 vap->iv_newstate = rsu_monitor_newstate;
712 vap->iv_newstate = rsu_newstate;
713 vap->iv_key_alloc = rsu_key_alloc;
714 vap->iv_key_set = rsu_key_set;
715 vap->iv_key_delete = rsu_key_delete;
718 vap->iv_ampdu_density = IEEE80211_HTCAP_MPDUDENSITY_16;
719 vap->iv_ampdu_rxmax = IEEE80211_HTCAP_MAXRXAMPDU_32K;
724 ic->ic_opmode = opmode;
741 struct rsu_softc *sc = ic->ic_softc;
742 struct ieee80211_scan_state *ss = ic->ic_scan;
743 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
748 sc->sc_active_scan = !!(ss->ss_flags & IEEE80211_SCAN_ACTIVE);
749 /* XXX TODO: force awake if in network-sleep? */
750 error = rsu_site_survey(sc, ss->ss_nssid > 0 ? &ss->ss_ssid[0] : NULL);
753 device_printf(sc->sc_dev,
769 struct rsu_softc *sc = ic->ic_softc;
776 if (sc->sc_ht)
779 bands, (ic->ic_htcaps & IEEE80211_HTCAP_CHWIDTH40) ?
786 struct rsu_softc *sc = ic->ic_softc;
792 if (ic->ic_opmode == IEEE80211_M_MONITOR) {
796 cmd.channel = IEEE80211_CHAN2IEEE(ic->ic_curchan);
802 device_printf(sc->sc_dev,
831 struct rsu_softc *sc = ic->ic_softc;
834 if (sc->sc_running)
852 pos ^= (mask >> (i * 8 + j - 1));
874 struct ieee80211com *ic = &sc->sc_ic;
880 if (ic->ic_allmulti == 0) {
887 TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next)
888 if_foreach_llmaddr(vap->iv_ifp, rsu_hash_maddr, &mfilt);
902 struct rsu_softc *sc = ic->ic_softc;
905 if (sc->sc_running)
918 dp->sc = sc;
919 dp->m = NULL;
920 dp->buf = malloc(maxsz, M_USBDEV, M_NOWAIT);
921 if (dp->buf == NULL) {
922 device_printf(sc->sc_dev,
927 dp->ni = NULL;
941 error = rsu_alloc_list(sc, sc->sc_rx, RSU_RX_LIST_COUNT,
946 STAILQ_INIT(&sc->sc_rx_active);
947 STAILQ_INIT(&sc->sc_rx_inactive);
950 STAILQ_INSERT_HEAD(&sc->sc_rx_inactive, &sc->sc_rx[i], next);
960 error = rsu_alloc_list(sc, sc->sc_tx, RSU_TX_LIST_COUNT,
965 STAILQ_INIT(&sc->sc_tx_inactive);
968 STAILQ_INIT(&sc->sc_tx_active[i]);
969 STAILQ_INIT(&sc->sc_tx_pending[i]);
973 STAILQ_INSERT_HEAD(&sc->sc_tx_inactive, &sc->sc_tx[i], next);
985 STAILQ_INIT(&sc->sc_tx_inactive);
988 STAILQ_INIT(&sc->sc_tx_active[i]);
989 STAILQ_INIT(&sc->sc_tx_pending[i]);
992 rsu_free_list(sc, sc->sc_tx, RSU_TX_LIST_COUNT);
999 STAILQ_INIT(&sc->sc_rx_inactive);
1000 STAILQ_INIT(&sc->sc_rx_active);
1002 rsu_free_list(sc, sc->sc_rx, RSU_RX_LIST_COUNT);
1013 if (dp->buf != NULL) {
1014 free(dp->buf, M_USBDEV);
1015 dp->buf = NULL;
1017 if (dp->ni != NULL) {
1018 ieee80211_free_node(dp->ni);
1019 dp->ni = NULL;
1029 bf = STAILQ_FIRST(&sc->sc_tx_inactive);
1031 STAILQ_REMOVE_HEAD(&sc->sc_tx_inactive, next);
1056 STAILQ_INSERT_TAIL(&sc->sc_tx_inactive, bf, next);
1171 device_printf(sc->sc_dev,
1179 uint8_t *rom = sc->rom;
1197 memset(&sc->rom, 0xff, sizeof(sc->rom));
1220 for (i = 0; i < sizeof(sc->rom); i++)
1245 memset(data->buf, '\0', RSU_TXBUFSZ);
1247 /* Round-up command length to a multiple of 8 bytes. */
1253 memset(data->buf, 0, xferlen);
1256 txd = (struct r92s_tx_desc *)data->buf;
1257 txd->txdw0 = htole32(
1261 txd->txdw1 = htole32(SM(R92S_TXDW1_QSEL, R92S_TXDW1_QSEL_H2C));
1265 cmd->len = htole16(cmdsz);
1266 cmd->code = code;
1267 cmd->seq = sc->cmd_seq;
1268 sc->cmd_seq = (sc->cmd_seq + 1) & 0x7f;
1276 data->buflen = xferlen;
1277 STAILQ_INSERT_TAIL(&sc->sc_tx_pending[which], data, next);
1278 usbd_transfer_start(sc->sc_xfer[which]);
1308 sc->sc_currssi = rsu_read_4(sc, R92S_IOCMD_DATA);
1310 __func__, sc->sc_currssi,
1311 rsu_hwrssi_to_rssi(sc, sc->sc_currssi));
1313 if (sc->sc_calibrating)
1314 taskqueue_enqueue_timeout(taskqueue_thread, &sc->calib_task, hz);
1340 * For now - it's on in all states except RUN, and
1360 if (sc->sc_curpwrstate == state)
1381 device_printf(sc->sc_dev, "%s: unknown ps mode (%d)\n",
1392 sc->sc_curpwrstate = state;
1408 struct ieee80211com *ic = vap->iv_ic;
1409 struct rsu_softc *sc = ic->ic_softc;
1412 if (vap->iv_state != nstate) {
1418 sc->sc_vap_is_running = 0;
1422 sc->sc_vap_is_running = 1;
1435 return (uvp->newstate(vap, nstate, arg));
1442 struct ieee80211com *ic = vap->iv_ic;
1443 struct rsu_softc *sc = ic->ic_softc;
1449 ostate = vap->iv_state;
1450 RSU_DPRINTF(sc, RSU_DEBUG_STATE, "%s: %s -> %s\n",
1459 sc->sc_calibrating = 0;
1463 usb_pause_mtx(&sc->sc_mtx, USB_MS_TO_TICKS(10));
1466 taskqueue_drain_timeout(taskqueue_thread, &sc->calib_task);
1467 taskqueue_drain(taskqueue_thread, &sc->tx_task);
1471 usb_pause_mtx(&sc->sc_mtx, USB_MS_TO_TICKS(10));
1474 sc->sc_vap_is_running = 0;
1478 if (sc->sc_running)
1487 ni = ieee80211_ref_node(vap->iv_bss);
1492 device_printf(sc->sc_dev,
1500 ni = ieee80211_ref_node(vap->iv_bss);
1501 rs = &ni->ni_rates;
1503 ni->ni_txrate = rs->rs_rates[rs->rs_nrates - 1];
1512 sc->sc_calibrating = 1;
1514 taskqueue_enqueue_timeout(taskqueue_thread, &sc->calib_task,
1519 return (uvp->newstate(vap, nstate, arg));
1526 struct rsu_softc *sc = vap->iv_ic->ic_softc;
1533 if (vap->iv_opmode != IEEE80211_M_STA) {
1537 k->wk_flags |= IEEE80211_KEY_SWCRYPT;
1544 if (isset(sc->keys_bmap, *keyix)) {
1545 device_printf(sc->sc_dev,
1551 setbit(sc->keys_bmap, *keyix);
1564 struct rsu_softc *sc = vap->iv_ic->ic_softc;
1567 if (k->wk_flags & IEEE80211_KEY_SWCRYPT) {
1574 KASSERT(k->wk_keyix < nitems(sc->group_keys),
1575 ("keyix %u > %zu\n", k->wk_keyix, nitems(sc->group_keys)));
1578 sc->group_keys[k->wk_keyix] = (set ? k : NULL);
1579 if (!sc->sc_running) {
1588 ret = rsu_delete_key(sc, k->wk_keyix);
1596 taskqueue_drain(taskqueue_thread, &sc->del_key_task);
1603 setbit(sc->free_keys_bmap, k->wk_keyix);
1607 taskqueue_enqueue(taskqueue_thread, &sc->del_key_task);
1637 usb_pause_mtx(&sc->sc_mtx, USB_MS_TO_TICKS(1));
1640 device_printf(sc->sc_dev,
1668 usb_pause_mtx(&sc->sc_mtx, USB_MS_TO_TICKS(1));
1672 device_printf(sc->sc_dev,
1680 device_printf(sc->sc_dev,
1703 device_printf(sc->sc_dev, "unknown cipher %d\n", cipher);
1718 algo = rsu_crypto_mode(sc, k->wk_cipher->ic_cipher, k->wk_keylen);
1724 key.cam_id = k->wk_keyix;
1725 key.grpkey = (k->wk_flags & IEEE80211_KEY_GROUP) != 0;
1726 memcpy(key.key, k->wk_key, MIN(k->wk_keylen, sizeof(key.key)));
1731 k->wk_cipher->ic_cipher, key.algo, k->wk_flags, k->wk_keylen,
1732 ether_sprintf(k->wk_macaddr));
1736 device_printf(sc->sc_dev,
1742 return (rsu_key_check(sc, k->wk_keyix, 1));
1754 if (!sc->sc_running)
1758 algo = rsu_crypto_mode(sc, k->wk_cipher->ic_cipher, k->wk_keylen);
1764 memcpy(key.macaddr, k->wk_macaddr, sizeof(key.macaddr));
1765 memcpy(key.key, k->wk_key, MIN(k->wk_keylen, sizeof(key.key)));
1769 __func__, k->wk_keyix, k->wk_cipher->ic_cipher, key.algo,
1770 k->wk_flags, k->wk_keylen, ether_sprintf(key.macaddr));
1774 device_printf(sc->sc_dev,
1780 return (rsu_key_check(sc, k->wk_keyix, 1));
1788 for (i = 0; i < nitems(sc->group_keys); i++) {
1789 if (sc->group_keys[i] != NULL) {
1790 error = rsu_set_key_group(sc, sc->group_keys[i]);
1792 device_printf(sc->sc_dev,
1812 if (!sc->sc_running)
1820 clrbit(sc->keys_bmap, keyix);
1832 device_printf(sc->sc_dev,
1838 usb_pause_mtx(&sc->sc_mtx, USB_MS_TO_TICKS(5));
1847 clrbit(sc->keys_bmap, keyix);
1860 if (isset(sc->free_keys_bmap, i)) {
1871 clrbit(sc->free_keys_bmap, i);
1874 i = IEEE80211_WEP_NKID - 1;
1890 if (sc->sc_active_scan)
1895 sc->sc_extra_scan = 1;
1896 cmd.ssidlen = htole32(ssid->len);
1897 memcpy(cmd.ssid, ssid->ssid, ssid->len);
1901 device_printf(sc->sc_dev,
1917 struct ieee80211com *ic = &sc->sc_ic;
1918 struct ieee80211vap *vap = ni->ni_vap;
1939 if (vap->iv_flags & IEEE80211_F_WPA) {
1941 auth.dot1x = (ni->ni_authmode == IEEE80211_AUTH_8021X);
1953 IEEE80211_ADDR_COPY(bss->macaddr, ni->ni_bssid);
1954 bss->ssid.ssidlen = htole32(ni->ni_esslen);
1955 memcpy(bss->ssid.ssid, ni->ni_essid, ni->ni_esslen);
1956 if (vap->iv_flags & (IEEE80211_F_PRIVACY | IEEE80211_F_WPA))
1957 bss->privacy = htole32(1);
1958 bss->rssi = htole32(ni->ni_avgrssi);
1959 if (ic->ic_curmode == IEEE80211_MODE_11B)
1960 bss->networktype = htole32(NDIS802_11DS);
1962 bss->networktype = htole32(NDIS802_11OFDM24);
1963 bss->config.len = htole32(sizeof(bss->config));
1964 bss->config.bintval = htole32(ni->ni_intval);
1965 bss->config.dsconfig = htole32(ieee80211_chan2ieee(ic, ni->ni_chan));
1966 bss->inframode = htole32(NDIS802_11INFRASTRUCTURE);
1968 memcpy(bss->supprates, ni->ni_rates.rs_rates,
1969 ni->ni_rates.rs_nrates);
1972 memcpy(&fixed->tstamp, ni->ni_tstamp.data, 8);
1973 fixed->bintval = htole16(ni->ni_intval);
1974 fixed->capabilities = htole16(ni->ni_capinfo);
1980 if ((ic->ic_flags & IEEE80211_F_WME) &&
1981 (ni->ni_ies.wme_ie != NULL))
1982 frm = ieee80211_add_wme_info(frm, &ic->ic_wme, ni);
1983 if (ni->ni_flags & IEEE80211_NODE_HT) {
1987 bss->ieslen = htole32(frm - (uint8_t *)fixed);
1988 bss->len = htole32(((frm - buf) + 3) & ~3);
1992 ether_sprintf(bss->macaddr), le32toh(bss->config.dsconfig));
1999 uint32_t zero = 0; /* :-) */
2030 struct ieee80211com *ic = &sc->sc_ic;
2041 ieslen = le32toh(bss->ieslen);
2043 if (__predict_false(ieslen > (uint32_t)(len - sizeof(*bss))))
2050 ether_sprintf(bss->macaddr), ieslen,
2051 le32toh(bss->config.dsconfig), le32toh(bss->inframode),
2052 le32toh(bss->networktype), le32toh(bss->privacy),
2053 le32toh(bss->rssi));
2057 if (__predict_false(ieslen > (size_t)(MCLBYTES - sizeof(*wh))))
2064 wh->i_fc[0] = IEEE80211_FC0_VERSION_0 | IEEE80211_FC0_TYPE_MGT |
2066 wh->i_fc[1] = IEEE80211_FC1_DIR_NODS;
2067 USETW(wh->i_dur, 0);
2068 IEEE80211_ADDR_COPY(wh->i_addr1, ieee80211broadcastaddr);
2069 IEEE80211_ADDR_COPY(wh->i_addr2, bss->macaddr);
2070 IEEE80211_ADDR_COPY(wh->i_addr3, bss->macaddr);
2071 *(uint16_t *)wh->i_seq = 0;
2075 m->m_pkthdr.len = m->m_len = pktlen;
2082 rxs.c_ieee = le32toh(bss->config.dsconfig);
2086 rxs.c_rssi = le32toh(bss->rssi) / 2;
2087 rxs.c_nf = -96;
2100 struct ieee80211com *ic = &sc->sc_ic;
2101 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
2102 struct ieee80211_node *ni = vap->iv_bss;
2110 res = (int)le32toh(rsp->join_res);
2122 ieee80211_new_state(vap, IEEE80211_S_SCAN, -1);
2127 tmp = le32toh(rsp->associd);
2128 if (tmp >= vap->iv_max_aid) {
2134 __func__, ether_sprintf(rsp->bss.macaddr), tmp);
2136 ni->ni_associd = tmp | 0xc000;
2139 sc->sc_vap_is_running = 1;
2151 struct ieee80211com *ic = &sc->sc_ic;
2152 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
2157 device_printf(sc->sc_dev, "%s: short read (%d)\n", __func__, len);
2166 ether_sprintf(ba->mac_addr),
2167 (int) ba->tid,
2168 (int) le16toh(ba->ssn));
2172 ni = ieee80211_ref_node(vap->iv_bss);
2173 ieee80211_ampdu_rx_start_ext(ni, ba->tid, le16toh(ba->ssn) >> 4, 32);
2180 struct ieee80211com *ic = &sc->sc_ic;
2181 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
2192 __func__, sc->sc_extra_scan ? "direct" : "broadcast",
2194 if (sc->sc_extra_scan == 1) {
2196 sc->sc_extra_scan = 0;
2211 if (vap->iv_state == IEEE80211_S_AUTH)
2218 if (vap->iv_state == IEEE80211_S_RUN &&
2219 IEEE80211_ADDR_EQ(vap->iv_bss->ni_bssid, buf)) {
2221 ieee80211_new_state(vap, IEEE80211_S_SCAN, -1);
2237 device_printf(sc->sc_dev, "%s: unhandled code (%d)\n", __func__, code);
2252 len -= sizeof(struct r92s_rx_stat);
2261 cmdsz = le16toh(cmd->len);
2266 rsu_rx_event(sc, cmd->code, (uint8_t *)&cmd[1], cmdsz);
2268 if (!(cmd->seq & R92S_FW_CMD_MORE))
2271 len -= sizeof(*cmd) + cmdsz;
2278 static const int8_t cckoff[] = { 14, -2, -20, -40 };
2286 rpt = (cck->agc_rpt >> 6) & 0x3;
2287 rssi = cck->agc_rpt & 0x3e;
2288 rssi = cckoff[rpt] - rssi;
2291 rssi = ((le32toh(phy->phydw1) >> 1) & 0x7f) - 106;
2300 struct ieee80211com *ic = &sc->sc_ic;
2305 rxdw0 = le32toh(stat->rxdw0);
2322 device_printf(sc->sc_dev,
2330 m->m_pkthdr.len = m->m_len = totlen;
2334 counter_u64_add(ic->ic_ierrors, 1);
2353 struct ieee80211com *ic = &sc->sc_ic;
2363 rxdw0 = le32toh(stat->rxdw0);
2364 rxdw3 = le32toh(stat->rxdw3);
2375 rssi = rsu_hwrssi_to_rssi(sc, sc->sc_currssi);
2398 m->m_pkthdr.csum_flags = CSUM_IP_CHECKED;
2399 m->m_pkthdr.csum_flags |= CSUM_IP_VALID;
2406 m->m_pkthdr.csum_flags |= CSUM_DATA_VALID;
2407 m->m_pkthdr.csum_flags |= CSUM_PSEUDO_HDR;
2408 m->m_pkthdr.csum_data = 0xffff;
2420 rxs.c_nf = -96;
2430 rxs.c_rate = IEEE80211_RATE_MCS | (rate - 12);
2435 struct rsu_rx_radiotap_header *tap = &sc->sc_rxtap;
2438 tap->wr_flags = 0; /* TODO */
2439 tap->wr_tsft = rsu_get_tsf_high(sc);
2440 if (le32toh(stat->tsf_low) > rsu_get_tsf_low(sc))
2441 tap->wr_tsft--;
2442 tap->wr_tsft = (uint64_t)htole32(tap->wr_tsft) << 32;
2443 tap->wr_tsft += stat->tsf_low;
2445 tap->wr_rate = rxs.c_rate;
2446 tap->wr_dbm_antsignal = rssi;
2454 if ((wh->i_fc[1] & IEEE80211_FC1_PROTECTED) &&
2456 m->m_flags |= M_WEP;
2461 __func__, m->m_len, rate, infosz);
2463 if (m->m_len >= sizeof(*wh))
2481 if (!sc->sc_running)
2486 npkts = MS(le32toh(stat->rxdw2), R92S_RXDW2_PKTCNT);
2491 while (npkts-- > 0) {
2495 rxdw0 = le32toh(stat->rxdw0);
2515 prevm->m_next = m;
2518 /* Next chunk is 128-byte aligned. */
2521 len -= totlen;
2530 struct rsu_softc *sc = data->sc;
2531 struct ieee80211com *ic = &sc->sc_ic;
2539 counter_u64_add(ic->ic_ierrors, 1);
2543 stat = (struct r92s_rx_stat *)data->buf;
2544 if ((le32toh(stat->rxdw1) & 0x1ff) == 0x1ff) {
2545 rsu_rx_multi_event(sc, data->buf, len);
2549 return (rsu_rx_multi_frame(sc, data->buf, len));
2556 struct ieee80211com *ic = &sc->sc_ic;
2565 data = STAILQ_FIRST(&sc->sc_rx_active);
2568 STAILQ_REMOVE_HEAD(&sc->sc_rx_active, next);
2570 STAILQ_INSERT_TAIL(&sc->sc_rx_inactive, data, next);
2574 data = STAILQ_FIRST(&sc->sc_rx_inactive);
2579 STAILQ_REMOVE_HEAD(&sc->sc_rx_inactive, next);
2580 STAILQ_INSERT_TAIL(&sc->sc_rx_active, data, next);
2581 usbd_xfer_set_frame_data(xfer, 0, data->buf,
2590 next = m->m_next;
2591 m->m_next = NULL;
2597 if (ni->ni_flags & IEEE80211_NODE_HT)
2598 m->m_flags |= M_AMPDU;
2610 data = STAILQ_FIRST(&sc->sc_rx_active);
2612 STAILQ_REMOVE_HEAD(&sc->sc_rx_active, next);
2613 STAILQ_INSERT_TAIL(&sc->sc_rx_inactive, data, next);
2617 counter_u64_add(ic->ic_ierrors, 1);
2636 if (data->m) {
2638 ieee80211_tx_complete(data->ni, data->m, 0);
2639 data->m = NULL;
2640 data->ni = NULL;
2649 struct ieee80211com *ic = &sc->sc_ic;
2656 data = STAILQ_FIRST(&sc->sc_tx_active[which]);
2661 STAILQ_REMOVE_HEAD(&sc->sc_tx_active[which], next);
2667 data = STAILQ_FIRST(&sc->sc_tx_pending[which]);
2673 STAILQ_REMOVE_HEAD(&sc->sc_tx_pending[which], next);
2674 STAILQ_INSERT_TAIL(&sc->sc_tx_active[which], data, next);
2675 usbd_xfer_set_frame_data(xfer, 0, data->buf, data->buflen);
2683 data = STAILQ_FIRST(&sc->sc_tx_active[which]);
2685 STAILQ_REMOVE_HEAD(&sc->sc_tx_active[which], next);
2689 counter_u64_add(ic->ic_oerrors, 1);
2747 const struct ieee80211_txparam *tp = ni->ni_txparms;
2748 struct ieee80211vap *vap = ni->ni_vap;
2763 type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK;
2764 ismcast = IEEE80211_IS_MULTICAST(wh->i_addr1);
2772 (m0->m_flags & M_EAPOL) != 0)
2773 rate = tp->mgmtrate;
2775 rate = tp->mcastrate;
2776 else if (tp->ucastrate != IEEE80211_FIXED_RATE_NONE)
2777 rate = tp->ucastrate;
2784 if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) {
2787 device_printf(sc->sc_dev,
2801 qos = ((const struct ieee80211_qosframe *)wh)->i_qos[0];
2803 /* Non-QoS TID */
2804 /* XXX TODO: tid=0 for non-qos TID? */
2832 txd = (struct r92s_tx_desc *)data->buf;
2835 txd->txdw0 |= htole32(
2836 SM(R92S_TXDW0_PKTLEN, m0->m_pkthdr.len) |
2840 txd->txdw1 |= htole32(
2843 txd->txdw1 |= htole32(R92S_TXDW1_NONQOS);
2844 if (k != NULL && !(k->wk_flags & IEEE80211_KEY_SWENCRYPT)) {
2845 switch (k->wk_cipher->ic_cipher) {
2858 txd->txdw1 |= htole32(
2860 SM(R92S_TXDW1_KEYIDX, k->wk_keyix));
2863 txd->txdw2 |= htole32(R92S_TXDW2_BK);
2865 txd->txdw2 |= htole32(R92S_TXDW2_BMCAST);
2869 txd->txdw2 |= htole32(R92S_TXDW2_RTY_LMT_ENA);
2870 txd->txdw2 |= htole32(SM(R92S_TXDW2_RTY_LMT, tp->maxretry));
2876 txd->txdw5 |= htole32(SM(R92S_TXDW5_DATARATE_FB_LMT, 0x1f));
2877 txd->txdw5 |= htole32(SM(R92S_TXDW5_DATARATE, ridx));
2878 txd->txdw4 |= htole32(R92S_TXDW4_DRVRATE);
2885 txd->txdw3 |= htole32(SM(R92S_TXDW3_SEQ, prio));
2888 struct rsu_tx_radiotap_header *tap = &sc->sc_txtap;
2890 tap->wt_flags = 0;
2894 xferlen = sizeof(*txd) + m0->m_pkthdr.len;
2896 m_copydata(m0, 0, m0->m_pkthdr.len, (caddr_t)&txd[1]);
2898 data->buflen = xferlen;
2899 data->ni = ni;
2900 data->m = m0;
2901 STAILQ_INSERT_TAIL(&sc->sc_tx_pending[which], data, next);
2904 usbd_transfer_start(sc->sc_xfer[which]);
2911 struct rsu_softc *sc = ic->ic_softc;
2915 if (!sc->sc_running) {
2924 error = mbufq_enqueue(&sc->sc_snd, m);
2948 while ((m = mbufq_dequeue(&sc->sc_snd)) != NULL) {
2949 ni = (struct ieee80211_node *)m->m_pkthdr.rcvif;
2950 m->m_pkthdr.rcvif = NULL;
2965 while ((m = mbufq_dequeue(&sc->sc_snd)) != NULL) {
2970 mbufq_prepend(&sc->sc_snd, m);
2974 ni = (struct ieee80211_node *)m->m_pkthdr.rcvif;
2975 m->m_pkthdr.rcvif = NULL;
2980 if_inc_counter(ni->ni_vap->iv_ifp,
2994 taskqueue_enqueue(taskqueue_thread, &sc->tx_task);
3000 struct rsu_softc *sc = ic->ic_softc;
3011 rxmask = ifr->ifr_reqcap & (IFCAP_RXCSUM | IFCAP_RXCSUM_IPV6);
3015 if (sc->sc_rx_checksum_enable &&
3018 sc->sc_rx_checksum_enable = 0;
3020 } else if (!sc->sc_rx_checksum_enable && rxmask != 0) {
3022 sc->sc_rx_checksum_enable = 1;
3032 TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
3033 if_t ifp = vap->iv_ifp;
3053 struct rsu_softc *sc = ic->ic_softc;
3055 if (ic->ic_nrunning > 0) {
3059 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
3068 * Power on sequence for A-cut adapters.
3078 /* Enable AFE macro block's bandgap and Mbias. */
3082 /* Enable LDOA15 block. */
3089 /* Enable switch regulator block. */
3107 /* Enable AFE PLL macro block. */
3150 * Power on sequence for B-cut and C-cut adapters.
3201 /* Enable AFE PLL macro block. */
3216 /* Disable CPU clock and 80MHz SSC. */
3292 /* Enable AFE macro block's bandgap and Mbias. */
3298 /* Firmware - tell it to switch things off */
3314 txd = (struct r92s_tx_desc *)data->buf;
3316 if (len <= RSU_TXBUFSZ - sizeof(*txd)) {
3318 txd->txdw0 |= htole32(R92S_TXDW0_LINIP);
3321 mlen = RSU_TXBUFSZ - sizeof(*txd);
3322 txd->txdw0 |= htole32(SM(R92S_TXDW0_PKTLEN, mlen));
3324 data->buflen = sizeof(*txd) + mlen;
3328 STAILQ_INSERT_TAIL(&sc->sc_tx_pending[which], data, next);
3330 len -= mlen;
3332 usbd_transfer_start(sc->sc_xfer[which]);
3343 struct ieee80211com *ic = &sc->sc_ic;
3360 if ((fw = firmware_get("rsu-rtl8712fw")) == NULL) {
3361 device_printf(sc->sc_dev,
3362 "%s: failed load firmware of file rsu-rtl8712fw\n",
3368 size = fw->datasize;
3370 device_printf(sc->sc_dev, "firmware too short\n");
3374 hdr = (const struct r92s_fw_hdr *)fw->data;
3375 if (hdr->signature != htole16(0x8712) &&
3376 hdr->signature != htole16(0x8192)) {
3377 device_printf(sc->sc_dev,
3379 le16toh(hdr->signature));
3383 RSU_DPRINTF(sc, RSU_DEBUG_FW, "FW V%d %02x-%02x %02x:%02x\n",
3384 le16toh(hdr->version), hdr->month, hdr->day, hdr->hour,
3385 hdr->minute);
3388 if (hdr->privsz != htole32(sizeof(dmem))) {
3389 device_printf(sc->sc_dev, "unsupported firmware image\n");
3394 imemsz = le32toh(hdr->imemsz);
3395 ememsz = le32toh(hdr->sramsz);
3397 if (imemsz > (size_t)(size - sizeof(*hdr)) ||
3398 ememsz > (size_t)(size - sizeof(*hdr) - imemsz)) {
3399 device_printf(sc->sc_dev, "firmware too short\n");
3409 device_printf(sc->sc_dev,
3421 device_printf(sc->sc_dev, "timeout waiting for IMEM transfer\n");
3428 device_printf(sc->sc_dev,
3440 device_printf(sc->sc_dev, "timeout waiting for EMEM transfer\n");
3448 device_printf(sc->sc_dev, "could not enable system clock\n");
3455 device_printf(sc->sc_dev,
3467 device_printf(sc->sc_dev,
3476 dmem.nendpoints = sc->sc_nendpoints;
3477 dmem.chip_version = sc->cut;
3478 dmem.rf_config = sc->sc_rftype;
3482 dmem.bw40_en = !! (ic->ic_htcaps & IEEE80211_HTCAP_CHWIDTH40);
3483 dmem.amsdu2ampdu_en = !! (sc->sc_ht);
3484 dmem.ampdu_en = !! (sc->sc_ht);
3485 dmem.agg_offload = !! (sc->sc_ht);
3492 device_printf(sc->sc_dev,
3503 device_printf(sc->sc_dev, "timeout waiting for %s transfer\n",
3515 device_printf(sc->sc_dev,
3529 struct ieee80211com *ic = ni->ni_ic;
3530 struct rsu_softc *sc = ic->ic_softc;
3534 if (!sc->sc_running) {
3570 if (sc->sc_rx_checksum_enable)
3589 struct ieee80211com *ic = &sc->sc_ic;
3597 if (sc->sc_vap_is_running)
3602 if (ic->ic_opmode == IEEE80211_M_MONITOR) {
3604 if (sc->sc_vap_is_running)
3611 if (ic->ic_promisc == 0 && ic->ic_opmode != IEEE80211_M_MONITOR)
3620 struct ieee80211com *ic = &sc->sc_ic;
3621 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
3628 if (sc->sc_running) {
3640 if (sc->cut == 1)
3668 IEEE80211_ADDR_COPY(macaddr, vap ? vap->iv_myaddr : ic->ic_macaddr);
3672 usb_pause_mtx(&sc->sc_mtx, USB_MS_TO_TICKS(2000));
3680 device_printf(sc->sc_dev, "could not set MAC address\n");
3690 device_printf(sc->sc_dev, "could not set PS mode\n");
3699 sc->sc_extra_scan = 0;
3700 usbd_transfer_start(sc->sc_xfer[RSU_BULK_RX]);
3703 sc->sc_running = 1;
3710 usbd_transfer_stop(sc->sc_xfer[i]);
3722 if (!sc->sc_running) {
3727 sc->sc_running = 0;
3728 sc->sc_vap_is_running = 0;
3729 sc->sc_calibrating = 0;
3730 taskqueue_cancel_timeout(taskqueue_thread, &sc->calib_task, NULL);
3731 taskqueue_cancel(taskqueue_thread, &sc->tx_task, NULL);
3740 memset(sc->free_keys_bmap, 0, sizeof(sc->free_keys_bmap));
3741 memset(sc->keys_bmap, 0, sizeof(sc->keys_bmap));
3744 usbd_transfer_stop(sc->sc_xfer[i]);
3759 //usb_pause_mtx(&sc->sc_mtx, hz / 1000);