Lines Matching +full:led +full:- +full:cur
1 // SPDX-License-Identifier: ISC
81 /* UNII-5 */
106 /* UNII-6 */
113 /* UNII-7 */
131 /* UNII-8 */
197 struct device_node *np = dev->dev->of_node; in mt76_led_init()
198 struct ieee80211_hw *hw = dev->hw; in mt76_led_init()
201 if (!dev->led_cdev.brightness_set && !dev->led_cdev.blink_set) in mt76_led_init()
204 snprintf(dev->led_name, sizeof(dev->led_name), in mt76_led_init()
205 "mt76-%s", wiphy_name(hw->wiphy)); in mt76_led_init()
207 dev->led_cdev.name = dev->led_name; in mt76_led_init()
208 dev->led_cdev.default_trigger = in mt76_led_init()
214 np = of_get_child_by_name(np, "led"); in mt76_led_init()
216 if (!of_property_read_u32(np, "led-sources", &led_pin)) in mt76_led_init()
217 dev->led_pin = led_pin; in mt76_led_init()
218 dev->led_al = of_property_read_bool(np, "led-active-low"); in mt76_led_init()
222 return led_classdev_register(dev->dev, &dev->led_cdev); in mt76_led_init()
227 if (!dev->led_cdev.brightness_set && !dev->led_cdev.blink_set) in mt76_led_cleanup()
230 led_classdev_unregister(&dev->led_cdev); in mt76_led_cleanup()
237 struct ieee80211_sta_ht_cap *ht_cap = &sband->ht_cap; in mt76_init_stream_cap()
238 int i, nstream = hweight8(phy->antenna_mask); in mt76_init_stream_cap()
243 ht_cap->cap |= IEEE80211_HT_CAP_TX_STBC; in mt76_init_stream_cap()
245 ht_cap->cap &= ~IEEE80211_HT_CAP_TX_STBC; in mt76_init_stream_cap()
248 ht_cap->mcs.rx_mask[i] = i < nstream ? 0xff : 0; in mt76_init_stream_cap()
253 vht_cap = &sband->vht_cap; in mt76_init_stream_cap()
255 vht_cap->cap |= IEEE80211_VHT_CAP_TXSTBC; in mt76_init_stream_cap()
257 vht_cap->cap &= ~IEEE80211_VHT_CAP_TXSTBC; in mt76_init_stream_cap()
258 vht_cap->cap |= IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN | in mt76_init_stream_cap()
268 vht_cap->vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map); in mt76_init_stream_cap()
269 vht_cap->vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map); in mt76_init_stream_cap()
270 if (ieee80211_hw_check(phy->hw, SUPPORTS_VHT_EXT_NSS_BW)) in mt76_init_stream_cap()
271 vht_cap->vht_mcs.tx_highest |= in mt76_init_stream_cap()
277 if (phy->cap.has_2ghz) in mt76_set_stream_caps()
278 mt76_init_stream_cap(phy, &phy->sband_2g.sband, false); in mt76_set_stream_caps()
279 if (phy->cap.has_5ghz) in mt76_set_stream_caps()
280 mt76_init_stream_cap(phy, &phy->sband_5g.sband, vht); in mt76_set_stream_caps()
281 if (phy->cap.has_6ghz) in mt76_set_stream_caps()
282 mt76_init_stream_cap(phy, &phy->sband_6g.sband, vht); in mt76_set_stream_caps()
292 struct ieee80211_supported_band *sband = &msband->sband; in mt76_init_sband()
295 struct mt76_dev *dev = phy->dev; in mt76_init_sband()
300 chanlist = devm_kmemdup(dev->dev, chan, size, GFP_KERNEL); in mt76_init_sband()
302 return -ENOMEM; in mt76_init_sband()
304 msband->chan = devm_kcalloc(dev->dev, n_chan, sizeof(*msband->chan), in mt76_init_sband()
306 if (!msband->chan) in mt76_init_sband()
307 return -ENOMEM; in mt76_init_sband()
309 sband->channels = chanlist; in mt76_init_sband()
310 sband->n_channels = n_chan; in mt76_init_sband()
311 sband->bitrates = rates; in mt76_init_sband()
312 sband->n_bitrates = n_rates; in mt76_init_sband()
317 ht_cap = &sband->ht_cap; in mt76_init_sband()
318 ht_cap->ht_supported = true; in mt76_init_sband()
319 ht_cap->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40 | in mt76_init_sband()
325 ht_cap->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED; in mt76_init_sband()
326 ht_cap->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K; in mt76_init_sband()
333 vht_cap = &sband->vht_cap; in mt76_init_sband()
334 vht_cap->vht_supported = true; in mt76_init_sband()
335 vht_cap->cap |= IEEE80211_VHT_CAP_RXLDPC | in mt76_init_sband()
347 phy->hw->wiphy->bands[NL80211_BAND_2GHZ] = &phy->sband_2g.sband; in mt76_init_sband_2g()
349 return mt76_init_sband(phy, &phy->sband_2g, mt76_channels_2ghz, in mt76_init_sband_2g()
358 phy->hw->wiphy->bands[NL80211_BAND_5GHZ] = &phy->sband_5g.sband; in mt76_init_sband_5g()
360 return mt76_init_sband(phy, &phy->sband_5g, mt76_channels_5ghz, in mt76_init_sband_5g()
369 phy->hw->wiphy->bands[NL80211_BAND_6GHZ] = &phy->sband_6g.sband; in mt76_init_sband_6g()
371 return mt76_init_sband(phy, &phy->sband_6g, mt76_channels_6ghz, in mt76_init_sband_6g()
380 struct ieee80211_supported_band *sband = &msband->sband; in mt76_check_sband()
387 for (i = 0; i < sband->n_channels; i++) { in mt76_check_sband()
388 if (sband->channels[i].flags & IEEE80211_CHAN_DISABLED) in mt76_check_sband()
396 phy->chandef.chan = &sband->channels[0]; in mt76_check_sband()
397 phy->chan_state = &msband->chan[0]; in mt76_check_sband()
401 sband->n_channels = 0; in mt76_check_sband()
402 phy->hw->wiphy->bands[band] = NULL; in mt76_check_sband()
408 struct mt76_dev *dev = phy->dev; in mt76_phy_init()
409 struct wiphy *wiphy = hw->wiphy; in mt76_phy_init()
411 SET_IEEE80211_DEV(hw, dev->dev); in mt76_phy_init()
412 SET_IEEE80211_PERM_ADDR(hw, phy->macaddr); in mt76_phy_init()
414 wiphy->features |= NL80211_FEATURE_ACTIVE_MONITOR; in mt76_phy_init()
415 wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH | in mt76_phy_init()
423 wiphy->available_antennas_tx = phy->antenna_mask; in mt76_phy_init()
424 wiphy->available_antennas_rx = phy->antenna_mask; in mt76_phy_init()
426 wiphy->sar_capa = &mt76_sar_capa; in mt76_phy_init()
427 phy->frp = devm_kcalloc(dev->dev, wiphy->sar_capa->num_freq_ranges, in mt76_phy_init()
430 if (!phy->frp) in mt76_phy_init()
431 return -ENOMEM; in mt76_phy_init()
433 hw->txq_data_size = sizeof(struct mt76_txq); in mt76_phy_init()
434 hw->uapsd_max_sp_len = IEEE80211_WMM_IE_STA_QOSINFO_SP_ALL; in mt76_phy_init()
436 if (!hw->max_tx_fragments) in mt76_phy_init()
437 hw->max_tx_fragments = 16; in mt76_phy_init()
468 phy = hw->priv; in mt76_alloc_phy()
469 phy->dev = dev; in mt76_alloc_phy()
470 phy->hw = hw; in mt76_alloc_phy()
471 phy->priv = hw->priv + phy_size; in mt76_alloc_phy()
472 phy->band_idx = band_idx; in mt76_alloc_phy()
474 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN; in mt76_alloc_phy()
475 hw->wiphy->interface_modes = in mt76_alloc_phy()
494 ret = mt76_phy_init(phy, phy->hw); in mt76_register_phy()
498 if (phy->cap.has_2ghz) { in mt76_register_phy()
504 if (phy->cap.has_5ghz) { in mt76_register_phy()
505 ret = mt76_init_sband_5g(phy, rates + 4, n_rates - 4, vht); in mt76_register_phy()
510 if (phy->cap.has_6ghz) { in mt76_register_phy()
511 ret = mt76_init_sband_6g(phy, rates + 4, n_rates - 4); in mt76_register_phy()
516 wiphy_read_of_freq_limits(phy->hw->wiphy); in mt76_register_phy()
517 mt76_check_sband(phy, &phy->sband_2g, NL80211_BAND_2GHZ); in mt76_register_phy()
518 mt76_check_sband(phy, &phy->sband_5g, NL80211_BAND_5GHZ); in mt76_register_phy()
519 mt76_check_sband(phy, &phy->sband_6g, NL80211_BAND_6GHZ); in mt76_register_phy()
521 ret = ieee80211_register_hw(phy->hw); in mt76_register_phy()
525 phy->dev->phys[phy->band_idx] = phy; in mt76_register_phy()
533 struct mt76_dev *dev = phy->dev; in mt76_unregister_phy()
536 ieee80211_unregister_hw(phy->hw); in mt76_unregister_phy()
537 dev->phys[phy->band_idx] = NULL; in mt76_unregister_phy()
555 dev = hw->priv; in mt76_alloc_device()
556 dev->hw = hw; in mt76_alloc_device()
557 dev->dev = pdev; in mt76_alloc_device()
558 dev->drv = drv_ops; in mt76_alloc_device()
559 dev->dma_dev = pdev; in mt76_alloc_device()
561 phy = &dev->phy; in mt76_alloc_device()
562 phy->dev = dev; in mt76_alloc_device()
563 phy->hw = hw; in mt76_alloc_device()
564 phy->band_idx = MT_BAND0; in mt76_alloc_device()
565 dev->phys[phy->band_idx] = phy; in mt76_alloc_device()
567 spin_lock_init(&dev->rx_lock); in mt76_alloc_device()
568 spin_lock_init(&dev->lock); in mt76_alloc_device()
569 spin_lock_init(&dev->cc_lock); in mt76_alloc_device()
570 spin_lock_init(&dev->status_lock); in mt76_alloc_device()
571 mutex_init(&dev->mutex); in mt76_alloc_device()
572 init_waitqueue_head(&dev->tx_wait); in mt76_alloc_device()
574 skb_queue_head_init(&dev->mcu.res_q); in mt76_alloc_device()
575 init_waitqueue_head(&dev->mcu.wait); in mt76_alloc_device()
576 mutex_init(&dev->mcu.mutex); in mt76_alloc_device()
577 dev->tx_worker.fn = mt76_tx_worker; in mt76_alloc_device()
579 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN; in mt76_alloc_device()
580 hw->wiphy->interface_modes = in mt76_alloc_device()
590 spin_lock_init(&dev->token_lock); in mt76_alloc_device()
591 idr_init(&dev->token); in mt76_alloc_device()
593 INIT_LIST_HEAD(&dev->wcid_list); in mt76_alloc_device()
595 INIT_LIST_HEAD(&dev->txwi_cache); in mt76_alloc_device()
596 dev->token_size = dev->drv->token_size; in mt76_alloc_device()
598 for (i = 0; i < ARRAY_SIZE(dev->q_rx); i++) in mt76_alloc_device()
599 skb_queue_head_init(&dev->rx_skb[i]); in mt76_alloc_device()
601 dev->wq = alloc_ordered_workqueue("mt76", 0); in mt76_alloc_device()
602 if (!dev->wq) { in mt76_alloc_device()
614 struct ieee80211_hw *hw = dev->hw; in mt76_register_device()
615 struct mt76_phy *phy = &dev->phy; in mt76_register_device()
618 dev_set_drvdata(dev->dev, dev); in mt76_register_device()
623 if (phy->cap.has_2ghz) { in mt76_register_device()
629 if (phy->cap.has_5ghz) { in mt76_register_device()
630 ret = mt76_init_sband_5g(phy, rates + 4, n_rates - 4, vht); in mt76_register_device()
635 if (phy->cap.has_6ghz) { in mt76_register_device()
636 ret = mt76_init_sband_6g(phy, rates + 4, n_rates - 4); in mt76_register_device()
641 wiphy_read_of_freq_limits(hw->wiphy); in mt76_register_device()
642 mt76_check_sband(&dev->phy, &phy->sband_2g, NL80211_BAND_2GHZ); in mt76_register_device()
643 mt76_check_sband(&dev->phy, &phy->sband_5g, NL80211_BAND_5GHZ); in mt76_register_device()
644 mt76_check_sband(&dev->phy, &phy->sband_6g, NL80211_BAND_6GHZ); in mt76_register_device()
656 WARN_ON(mt76_worker_setup(hw, &dev->tx_worker, NULL, "tx")); in mt76_register_device()
657 sched_set_fifo_low(dev->tx_worker.task); in mt76_register_device()
665 struct ieee80211_hw *hw = dev->hw; in mt76_unregister_device()
676 mt76_worker_teardown(&dev->tx_worker); in mt76_free_device()
677 if (dev->wq) { in mt76_free_device()
678 destroy_workqueue(dev->wq); in mt76_free_device()
679 dev->wq = NULL; in mt76_free_device()
681 ieee80211_free_hw(dev->hw); in mt76_free_device()
687 struct sk_buff *skb = phy->rx_amsdu[q].head; in mt76_rx_release_amsdu()
688 struct mt76_rx_status *status = (struct mt76_rx_status *)skb->cb; in mt76_rx_release_amsdu()
689 struct mt76_dev *dev = phy->dev; in mt76_rx_release_amsdu()
691 phy->rx_amsdu[q].head = NULL; in mt76_rx_release_amsdu()
692 phy->rx_amsdu[q].tail = NULL; in mt76_rx_release_amsdu()
696 * A single MSDU can be parsed as A-MSDU when the unauthenticated A-MSDU in mt76_rx_release_amsdu()
701 if (skb_shinfo(skb)->frag_list) { in mt76_rx_release_amsdu()
704 if (!(status->flag & RX_FLAG_8023)) { in mt76_rx_release_amsdu()
707 if ((status->flag & in mt76_rx_release_amsdu()
713 if (ether_addr_equal(skb->data + offset, rfc1042_header)) { in mt76_rx_release_amsdu()
718 __skb_queue_tail(&dev->rx_skb[q], skb); in mt76_rx_release_amsdu()
724 struct mt76_rx_status *status = (struct mt76_rx_status *)skb->cb; in mt76_rx_release_burst()
726 if (phy->rx_amsdu[q].head && in mt76_rx_release_burst()
727 (!status->amsdu || status->first_amsdu || in mt76_rx_release_burst()
728 status->seqno != phy->rx_amsdu[q].seqno)) in mt76_rx_release_burst()
731 if (!phy->rx_amsdu[q].head) { in mt76_rx_release_burst()
732 phy->rx_amsdu[q].tail = &skb_shinfo(skb)->frag_list; in mt76_rx_release_burst()
733 phy->rx_amsdu[q].seqno = status->seqno; in mt76_rx_release_burst()
734 phy->rx_amsdu[q].head = skb; in mt76_rx_release_burst()
736 *phy->rx_amsdu[q].tail = skb; in mt76_rx_release_burst()
737 phy->rx_amsdu[q].tail = &skb->next; in mt76_rx_release_burst()
740 if (!status->amsdu || status->last_amsdu) in mt76_rx_release_burst()
746 struct mt76_rx_status *status = (struct mt76_rx_status *)skb->cb; in mt76_rx()
747 struct mt76_phy *phy = mt76_dev_phy(dev, status->phy_idx); in mt76_rx()
749 if (!test_bit(MT76_STATE_RUNNING, &phy->state)) { in mt76_rx()
755 if (phy->test.state == MT76_TM_STATE_RX_FRAMES) { in mt76_rx()
756 phy->test.rx_stats.packets[q]++; in mt76_rx()
757 if (status->flag & RX_FLAG_FAILED_FCS_CRC) in mt76_rx()
758 phy->test.rx_stats.fcs_error[q]++; in mt76_rx()
772 q = phy->q_tx[i]; in mt76_has_tx_pending()
773 if (q && q->queued) in mt76_has_tx_pending()
787 if (c->band == NL80211_BAND_2GHZ) in mt76_channel_state()
788 msband = &phy->sband_2g; in mt76_channel_state()
789 else if (c->band == NL80211_BAND_6GHZ) in mt76_channel_state()
790 msband = &phy->sband_6g; in mt76_channel_state()
792 msband = &phy->sband_5g; in mt76_channel_state()
794 idx = c - &msband->sband.channels[0]; in mt76_channel_state()
795 return &msband->chan[idx]; in mt76_channel_state()
800 struct mt76_channel_state *state = phy->chan_state; in mt76_update_survey_active_time()
802 state->cc_active += ktime_to_us(ktime_sub(time, in mt76_update_survey_active_time()
803 phy->survey_time)); in mt76_update_survey_active_time()
804 phy->survey_time = time; in mt76_update_survey_active_time()
810 struct mt76_dev *dev = phy->dev; in mt76_update_survey()
813 if (dev->drv->update_survey) in mt76_update_survey()
814 dev->drv->update_survey(phy); in mt76_update_survey()
819 if (dev->drv->drv_flags & MT_DRV_SW_RX_AIRTIME) { in mt76_update_survey()
820 struct mt76_channel_state *state = phy->chan_state; in mt76_update_survey()
822 spin_lock_bh(&dev->cc_lock); in mt76_update_survey()
823 state->cc_bss_rx += dev->cur_cc_bss_rx; in mt76_update_survey()
824 dev->cur_cc_bss_rx = 0; in mt76_update_survey()
825 spin_unlock_bh(&dev->cc_lock); in mt76_update_survey()
832 struct mt76_dev *dev = phy->dev; in mt76_set_channel()
833 struct ieee80211_hw *hw = phy->hw; in mt76_set_channel()
834 struct cfg80211_chan_def *chandef = &hw->conf.chandef; in mt76_set_channel()
835 bool offchannel = hw->conf.flags & IEEE80211_CONF_OFFCHANNEL; in mt76_set_channel()
838 wait_event_timeout(dev->tx_wait, !mt76_has_tx_pending(phy), timeout); in mt76_set_channel()
841 if (phy->chandef.chan->center_freq != chandef->chan->center_freq || in mt76_set_channel()
842 phy->chandef.width != chandef->width) in mt76_set_channel()
843 phy->dfs_state = MT_DFS_STATE_UNKNOWN; in mt76_set_channel()
845 phy->chandef = *chandef; in mt76_set_channel()
846 phy->chan_state = mt76_channel_state(phy, chandef->chan); in mt76_set_channel()
849 phy->main_chan = chandef->chan; in mt76_set_channel()
851 if (chandef->chan != phy->main_chan) in mt76_set_channel()
852 memset(phy->chan_state, 0, sizeof(*phy->chan_state)); in mt76_set_channel()
859 struct mt76_phy *phy = hw->priv; in mt76_get_survey()
860 struct mt76_dev *dev = phy->dev; in mt76_get_survey()
866 mutex_lock(&dev->mutex); in mt76_get_survey()
867 if (idx == 0 && dev->drv->update_survey) in mt76_get_survey()
870 if (idx >= phy->sband_2g.sband.n_channels + in mt76_get_survey()
871 phy->sband_5g.sband.n_channels) { in mt76_get_survey()
872 idx -= (phy->sband_2g.sband.n_channels + in mt76_get_survey()
873 phy->sband_5g.sband.n_channels); in mt76_get_survey()
874 sband = &phy->sband_6g; in mt76_get_survey()
875 } else if (idx >= phy->sband_2g.sband.n_channels) { in mt76_get_survey()
876 idx -= phy->sband_2g.sband.n_channels; in mt76_get_survey()
877 sband = &phy->sband_5g; in mt76_get_survey()
879 sband = &phy->sband_2g; in mt76_get_survey()
882 if (idx >= sband->sband.n_channels) { in mt76_get_survey()
883 ret = -ENOENT; in mt76_get_survey()
887 chan = &sband->sband.channels[idx]; in mt76_get_survey()
891 survey->channel = chan; in mt76_get_survey()
892 survey->filled = SURVEY_INFO_TIME | SURVEY_INFO_TIME_BUSY; in mt76_get_survey()
893 survey->filled |= dev->drv->survey_flags; in mt76_get_survey()
894 if (state->noise) in mt76_get_survey()
895 survey->filled |= SURVEY_INFO_NOISE_DBM; in mt76_get_survey()
897 if (chan == phy->main_chan) { in mt76_get_survey()
898 survey->filled |= SURVEY_INFO_IN_USE; in mt76_get_survey()
900 if (dev->drv->drv_flags & MT_DRV_SW_RX_AIRTIME) in mt76_get_survey()
901 survey->filled |= SURVEY_INFO_TIME_BSS_RX; in mt76_get_survey()
904 survey->time_busy = div_u64(state->cc_busy, 1000); in mt76_get_survey()
905 survey->time_rx = div_u64(state->cc_rx, 1000); in mt76_get_survey()
906 survey->time = div_u64(state->cc_active, 1000); in mt76_get_survey()
907 survey->noise = state->noise; in mt76_get_survey()
909 spin_lock_bh(&dev->cc_lock); in mt76_get_survey()
910 survey->time_bss_rx = div_u64(state->cc_bss_rx, 1000); in mt76_get_survey()
911 survey->time_tx = div_u64(state->cc_tx, 1000); in mt76_get_survey()
912 spin_unlock_bh(&dev->cc_lock); in mt76_get_survey()
915 mutex_unlock(&dev->mutex); in mt76_get_survey()
927 wcid->rx_check_pn = false; in mt76_wcid_key_setup()
932 if (key->cipher != WLAN_CIPHER_SUITE_CCMP) in mt76_wcid_key_setup()
935 wcid->rx_check_pn = true; in mt76_wcid_key_setup()
940 memcpy(wcid->rx_key_pn[i], seq.ccmp.pn, sizeof(seq.ccmp.pn)); in mt76_wcid_key_setup()
944 ieee80211_get_key_rx_seq(key, -1, &seq); in mt76_wcid_key_setup()
945 memcpy(wcid->rx_key_pn[i], seq.ccmp.pn, sizeof(seq.ccmp.pn)); in mt76_wcid_key_setup()
953 s8 *chain_signal = status->chain_signal; in mt76_rx_signal()
954 int signal = -128; in mt76_rx_signal()
957 for (chains = status->chains; chains; chains >>= 1, chain_signal++) { in mt76_rx_signal()
958 int cur, diff; in mt76_rx_signal() local
960 cur = *chain_signal; in mt76_rx_signal()
962 cur > 0) in mt76_rx_signal()
965 if (cur > signal) in mt76_rx_signal()
966 swap(cur, signal); in mt76_rx_signal()
968 diff = signal - cur; in mt76_rx_signal()
989 mstat = *((struct mt76_rx_status *)skb->cb); in mt76_rx_convert()
992 status->flag = mstat.flag; in mt76_rx_convert()
993 status->freq = mstat.freq; in mt76_rx_convert()
994 status->enc_flags = mstat.enc_flags; in mt76_rx_convert()
995 status->encoding = mstat.encoding; in mt76_rx_convert()
996 status->bw = mstat.bw; in mt76_rx_convert()
997 status->he_ru = mstat.he_ru; in mt76_rx_convert()
998 status->he_gi = mstat.he_gi; in mt76_rx_convert()
999 status->he_dcm = mstat.he_dcm; in mt76_rx_convert()
1000 status->rate_idx = mstat.rate_idx; in mt76_rx_convert()
1001 status->nss = mstat.nss; in mt76_rx_convert()
1002 status->band = mstat.band; in mt76_rx_convert()
1003 status->signal = mstat.signal; in mt76_rx_convert()
1004 status->chains = mstat.chains; in mt76_rx_convert()
1005 status->ampdu_reference = mstat.ampdu_ref; in mt76_rx_convert()
1006 status->device_timestamp = mstat.timestamp; in mt76_rx_convert()
1007 status->mactime = mstat.timestamp; in mt76_rx_convert()
1008 status->signal = mt76_rx_signal(&mstat); in mt76_rx_convert()
1009 if (status->signal <= -128) in mt76_rx_convert()
1010 status->flag |= RX_FLAG_NO_SIGNAL_VAL; in mt76_rx_convert()
1012 if (ieee80211_is_beacon(hdr->frame_control) || in mt76_rx_convert()
1013 ieee80211_is_probe_resp(hdr->frame_control)) in mt76_rx_convert()
1014 status->boottime_ns = ktime_get_boottime_ns(); in mt76_rx_convert()
1016 BUILD_BUG_ON(sizeof(mstat) > sizeof(skb->cb)); in mt76_rx_convert()
1017 BUILD_BUG_ON(sizeof(status->chain_signal) != in mt76_rx_convert()
1019 memcpy(status->chain_signal, mstat.chain_signal, in mt76_rx_convert()
1029 struct mt76_rx_status *status = (struct mt76_rx_status *)skb->cb; in mt76_check_ccmp_pn()
1030 struct mt76_wcid *wcid = status->wcid; in mt76_check_ccmp_pn()
1035 if (!(status->flag & RX_FLAG_DECRYPTED)) in mt76_check_ccmp_pn()
1038 if (status->flag & RX_FLAG_ONLY_MONITOR) in mt76_check_ccmp_pn()
1041 if (!wcid || !wcid->rx_check_pn) in mt76_check_ccmp_pn()
1044 security_idx = status->qos_ctl & IEEE80211_QOS_CTL_TID_MASK; in mt76_check_ccmp_pn()
1045 if (status->flag & RX_FLAG_8023) in mt76_check_ccmp_pn()
1049 if (!(status->flag & RX_FLAG_IV_STRIPPED)) { in mt76_check_ccmp_pn()
1055 !ieee80211_is_first_frag(hdr->frame_control)) in mt76_check_ccmp_pn()
1059 /* IEEE 802.11-2020, 12.5.3.4.4 "PN and replay detection" c): in mt76_check_ccmp_pn()
1065 if (ieee80211_is_mgmt(hdr->frame_control) && in mt76_check_ccmp_pn()
1066 !ieee80211_has_tods(hdr->frame_control)) in mt76_check_ccmp_pn()
1070 BUILD_BUG_ON(sizeof(status->iv) != sizeof(wcid->rx_key_pn[0])); in mt76_check_ccmp_pn()
1071 ret = memcmp(status->iv, wcid->rx_key_pn[security_idx], in mt76_check_ccmp_pn()
1072 sizeof(status->iv)); in mt76_check_ccmp_pn()
1074 status->flag |= RX_FLAG_ONLY_MONITOR; in mt76_check_ccmp_pn()
1078 memcpy(wcid->rx_key_pn[security_idx], status->iv, sizeof(status->iv)); in mt76_check_ccmp_pn()
1080 if (status->flag & RX_FLAG_IV_STRIPPED) in mt76_check_ccmp_pn()
1081 status->flag |= RX_FLAG_PN_VALIDATED; in mt76_check_ccmp_pn()
1088 struct mt76_wcid *wcid = status->wcid; in mt76_airtime_report()
1090 .enc_flags = status->enc_flags, in mt76_airtime_report()
1091 .rate_idx = status->rate_idx, in mt76_airtime_report()
1092 .encoding = status->encoding, in mt76_airtime_report()
1093 .band = status->band, in mt76_airtime_report()
1094 .nss = status->nss, in mt76_airtime_report()
1095 .bw = status->bw, in mt76_airtime_report()
1099 u8 tidno = status->qos_ctl & IEEE80211_QOS_CTL_TID_MASK; in mt76_airtime_report()
1101 airtime = ieee80211_calc_rx_airtime(dev->hw, &info, len); in mt76_airtime_report()
1102 spin_lock(&dev->cc_lock); in mt76_airtime_report()
1103 dev->cur_cc_bss_rx += airtime; in mt76_airtime_report()
1104 spin_unlock(&dev->cc_lock); in mt76_airtime_report()
1106 if (!wcid || !wcid->sta) in mt76_airtime_report()
1119 if (!dev->rx_ampdu_len) in mt76_airtime_flush_ampdu()
1122 wcid_idx = dev->rx_ampdu_status.wcid_idx; in mt76_airtime_flush_ampdu()
1123 if (wcid_idx < ARRAY_SIZE(dev->wcid)) in mt76_airtime_flush_ampdu()
1124 wcid = rcu_dereference(dev->wcid[wcid_idx]); in mt76_airtime_flush_ampdu()
1127 dev->rx_ampdu_status.wcid = wcid; in mt76_airtime_flush_ampdu()
1129 mt76_airtime_report(dev, &dev->rx_ampdu_status, dev->rx_ampdu_len); in mt76_airtime_flush_ampdu()
1131 dev->rx_ampdu_len = 0; in mt76_airtime_flush_ampdu()
1132 dev->rx_ampdu_ref = 0; in mt76_airtime_flush_ampdu()
1138 struct mt76_rx_status *status = (struct mt76_rx_status *)skb->cb; in mt76_airtime_check()
1139 struct mt76_wcid *wcid = status->wcid; in mt76_airtime_check()
1141 if (!(dev->drv->drv_flags & MT_DRV_SW_RX_AIRTIME)) in mt76_airtime_check()
1144 if (!wcid || !wcid->sta) { in mt76_airtime_check()
1147 if (status->flag & RX_FLAG_8023) in mt76_airtime_check()
1150 if (!ether_addr_equal(hdr->addr1, dev->phy.macaddr)) in mt76_airtime_check()
1156 if (!(status->flag & RX_FLAG_AMPDU_DETAILS) || in mt76_airtime_check()
1157 status->ampdu_ref != dev->rx_ampdu_ref) in mt76_airtime_check()
1160 if (status->flag & RX_FLAG_AMPDU_DETAILS) { in mt76_airtime_check()
1161 if (!dev->rx_ampdu_len || in mt76_airtime_check()
1162 status->ampdu_ref != dev->rx_ampdu_ref) { in mt76_airtime_check()
1163 dev->rx_ampdu_status = *status; in mt76_airtime_check()
1164 dev->rx_ampdu_status.wcid_idx = wcid ? wcid->idx : 0xff; in mt76_airtime_check()
1165 dev->rx_ampdu_ref = status->ampdu_ref; in mt76_airtime_check()
1168 dev->rx_ampdu_len += skb->len; in mt76_airtime_check()
1172 mt76_airtime_report(dev, status, skb->len); in mt76_airtime_check()
1178 struct mt76_rx_status *status = (struct mt76_rx_status *)skb->cb; in mt76_check_sta()
1182 struct mt76_wcid *wcid = status->wcid; in mt76_check_sta()
1183 u8 tidno = status->qos_ctl & IEEE80211_QOS_CTL_TID_MASK; in mt76_check_sta()
1186 hw = mt76_phy_hw(dev, status->phy_idx); in mt76_check_sta()
1187 if (ieee80211_is_pspoll(hdr->frame_control) && !wcid && in mt76_check_sta()
1188 !(status->flag & RX_FLAG_8023)) { in mt76_check_sta()
1189 sta = ieee80211_find_sta_by_ifaddr(hw, hdr->addr2, NULL); in mt76_check_sta()
1191 wcid = status->wcid = (struct mt76_wcid *)sta->drv_priv; in mt76_check_sta()
1196 if (!wcid || !wcid->sta) in mt76_check_sta()
1201 if (status->signal <= 0) in mt76_check_sta()
1202 ewma_signal_add(&wcid->rssi, -status->signal); in mt76_check_sta()
1204 wcid->inactive_count = 0; in mt76_check_sta()
1206 if (status->flag & RX_FLAG_8023) in mt76_check_sta()
1209 if (!test_bit(MT_WCID_FLAG_CHECK_PS, &wcid->flags)) in mt76_check_sta()
1212 if (ieee80211_is_pspoll(hdr->frame_control)) { in mt76_check_sta()
1217 if (ieee80211_has_morefrags(hdr->frame_control) || in mt76_check_sta()
1218 !(ieee80211_is_mgmt(hdr->frame_control) || in mt76_check_sta()
1219 ieee80211_is_data(hdr->frame_control))) in mt76_check_sta()
1222 ps = ieee80211_has_pm(hdr->frame_control); in mt76_check_sta()
1224 if (ps && (ieee80211_is_data_qos(hdr->frame_control) || in mt76_check_sta()
1225 ieee80211_is_qos_nullfunc(hdr->frame_control))) in mt76_check_sta()
1228 if (!!test_bit(MT_WCID_FLAG_PS, &wcid->flags) == ps) in mt76_check_sta()
1232 set_bit(MT_WCID_FLAG_PS, &wcid->flags); in mt76_check_sta()
1234 dev->drv->sta_ps(dev, sta, ps); in mt76_check_sta()
1237 clear_bit(MT_WCID_FLAG_PS, &wcid->flags); in mt76_check_sta()
1250 spin_lock(&dev->rx_lock); in mt76_rx_complete()
1252 struct sk_buff *nskb = skb_shinfo(skb)->frag_list; in mt76_rx_complete()
1255 skb_shinfo(skb)->frag_list = NULL; in mt76_rx_complete()
1262 nskb = nskb->next; in mt76_rx_complete()
1263 skb->next = NULL; in mt76_rx_complete()
1269 spin_unlock(&dev->rx_lock); in mt76_rx_complete()
1290 while ((skb = __skb_dequeue(&dev->rx_skb[q])) != NULL) { in mt76_rx_poll_complete()
1303 struct mt76_wcid *wcid = (struct mt76_wcid *)sta->drv_priv; in mt76_sta_add()
1304 struct mt76_dev *dev = phy->dev; in mt76_sta_add()
1308 mutex_lock(&dev->mutex); in mt76_sta_add()
1310 ret = dev->drv->sta_add(dev, vif, sta); in mt76_sta_add()
1314 for (i = 0; i < ARRAY_SIZE(sta->txq); i++) { in mt76_sta_add()
1317 if (!sta->txq[i]) in mt76_sta_add()
1320 mtxq = (struct mt76_txq *)sta->txq[i]->drv_priv; in mt76_sta_add()
1321 mtxq->wcid = wcid->idx; in mt76_sta_add()
1324 ewma_signal_init(&wcid->rssi); in mt76_sta_add()
1325 if (phy->band_idx == MT_BAND1) in mt76_sta_add()
1326 mt76_wcid_mask_set(dev->wcid_phy_mask, wcid->idx); in mt76_sta_add()
1327 wcid->phy_idx = phy->band_idx; in mt76_sta_add()
1328 rcu_assign_pointer(dev->wcid[wcid->idx], wcid); in mt76_sta_add()
1332 mutex_unlock(&dev->mutex); in mt76_sta_add()
1340 struct mt76_wcid *wcid = (struct mt76_wcid *)sta->drv_priv; in __mt76_sta_remove()
1341 int i, idx = wcid->idx; in __mt76_sta_remove()
1343 for (i = 0; i < ARRAY_SIZE(wcid->aggr); i++) in __mt76_sta_remove()
1346 if (dev->drv->sta_remove) in __mt76_sta_remove()
1347 dev->drv->sta_remove(dev, vif, sta); in __mt76_sta_remove()
1351 mt76_wcid_mask_clear(dev->wcid_mask, idx); in __mt76_sta_remove()
1352 mt76_wcid_mask_clear(dev->wcid_phy_mask, idx); in __mt76_sta_remove()
1360 mutex_lock(&dev->mutex); in mt76_sta_remove()
1362 mutex_unlock(&dev->mutex); in mt76_sta_remove()
1370 struct mt76_phy *phy = hw->priv; in mt76_sta_state()
1371 struct mt76_dev *dev = phy->dev; in mt76_sta_state()
1379 dev->drv->sta_assoc) in mt76_sta_state()
1380 dev->drv->sta_assoc(dev, vif, sta); in mt76_sta_state()
1393 struct mt76_phy *phy = hw->priv; in mt76_sta_pre_rcu_remove()
1394 struct mt76_dev *dev = phy->dev; in mt76_sta_pre_rcu_remove()
1395 struct mt76_wcid *wcid = (struct mt76_wcid *)sta->drv_priv; in mt76_sta_pre_rcu_remove()
1397 mutex_lock(&dev->mutex); in mt76_sta_pre_rcu_remove()
1398 spin_lock_bh(&dev->status_lock); in mt76_sta_pre_rcu_remove()
1399 rcu_assign_pointer(dev->wcid[wcid->idx], NULL); in mt76_sta_pre_rcu_remove()
1400 spin_unlock_bh(&dev->status_lock); in mt76_sta_pre_rcu_remove()
1401 mutex_unlock(&dev->mutex); in mt76_sta_pre_rcu_remove()
1408 struct mt76_phy *phy = hw->priv; in mt76_get_txpower()
1409 int n_chains = hweight8(phy->antenna_mask); in mt76_get_txpower()
1412 *dbm = DIV_ROUND_UP(phy->txpower_cur + delta, 2); in mt76_get_txpower()
1421 struct mt76_phy *phy = hw->priv; in mt76_init_sar_power()
1422 const struct cfg80211_sar_capa *capa = hw->wiphy->sar_capa; in mt76_init_sar_power()
1425 if (sar->type != NL80211_SAR_TYPE_POWER || !sar->num_sub_specs) in mt76_init_sar_power()
1426 return -EINVAL; in mt76_init_sar_power()
1428 for (i = 0; i < sar->num_sub_specs; i++) { in mt76_init_sar_power()
1429 u32 index = sar->sub_specs[i].freq_range_index; in mt76_init_sar_power()
1431 s32 power = sar->sub_specs[i].power >> 1; in mt76_init_sar_power()
1433 if (power > 127 || power < -127) in mt76_init_sar_power()
1436 phy->frp[index].range = &capa->freq_ranges[index]; in mt76_init_sar_power()
1437 phy->frp[index].power = power; in mt76_init_sar_power()
1448 const struct cfg80211_sar_capa *capa = phy->hw->wiphy->sar_capa; in mt76_get_sar_power()
1451 if (!capa || !phy->frp) in mt76_get_sar_power()
1454 if (power > 127 || power < -127) in mt76_get_sar_power()
1457 freq = ieee80211_channel_to_frequency(chan->hw_value, chan->band); in mt76_get_sar_power()
1458 for (i = 0 ; i < capa->num_freq_ranges; i++) { in mt76_get_sar_power()
1459 if (phy->frp[i].range && in mt76_get_sar_power()
1460 freq >= phy->frp[i].range->start_freq && in mt76_get_sar_power()
1461 freq < phy->frp[i].range->end_freq) { in mt76_get_sar_power()
1462 power = min_t(int, phy->frp[i].power, power); in mt76_get_sar_power()
1474 if (vif->bss_conf.csa_active && ieee80211_beacon_cntdwn_is_complete(vif)) in __mt76_csa_finish()
1480 if (!dev->csa_complete) in mt76_csa_finish()
1483 ieee80211_iterate_active_interfaces_atomic(dev->hw, in mt76_csa_finish()
1487 dev->csa_complete = 0; in mt76_csa_finish()
1496 if (!vif->bss_conf.csa_active) in __mt76_csa_check()
1499 dev->csa_complete |= ieee80211_beacon_cntdwn_is_complete(vif); in __mt76_csa_check()
1504 ieee80211_iterate_active_interfaces_atomic(dev->hw, in mt76_csa_check()
1519 struct mt76_rx_status *status = (struct mt76_rx_status *)skb->cb; in mt76_insert_ccmp_hdr()
1521 u8 *hdr, *pn = status->iv; in mt76_insert_ccmp_hdr()
1524 memmove(skb->data, skb->data + 8, hdr_len); in mt76_insert_ccmp_hdr()
1525 hdr = skb->data + hdr_len; in mt76_insert_ccmp_hdr()
1536 status->flag &= ~RX_FLAG_IV_STRIPPED; in mt76_insert_ccmp_hdr()
1544 int i, offset = 0, len = sband->n_bitrates; in mt76_get_rate()
1547 if (sband != &dev->phy.sband_2g.sband) in mt76_get_rate()
1551 } else if (sband == &dev->phy.sband_2g.sband) { in mt76_get_rate()
1556 if ((sband->bitrates[i].hw_value & GENMASK(7, 0)) == idx) in mt76_get_rate()
1567 struct mt76_phy *phy = hw->priv; in mt76_sw_scan()
1569 set_bit(MT76_SCANNING, &phy->state); in mt76_sw_scan()
1575 struct mt76_phy *phy = hw->priv; in mt76_sw_scan_complete()
1577 clear_bit(MT76_SCANNING, &phy->state); in mt76_sw_scan_complete()
1583 struct mt76_phy *phy = hw->priv; in mt76_get_antenna()
1584 struct mt76_dev *dev = phy->dev; in mt76_get_antenna()
1586 mutex_lock(&dev->mutex); in mt76_get_antenna()
1587 *tx_ant = phy->antenna_mask; in mt76_get_antenna()
1588 *rx_ant = phy->antenna_mask; in mt76_get_antenna()
1589 mutex_unlock(&dev->mutex); in mt76_get_antenna()
1602 hwq = devm_kzalloc(dev->dev, sizeof(*hwq), GFP_KERNEL); in mt76_init_queue()
1604 return ERR_PTR(-ENOMEM); in mt76_init_queue()
1606 hwq->flags = flags; in mt76_init_queue()
1608 err = dev->queue_ops->alloc(dev, hwq, idx, n_desc, 0, ring_base); in mt76_init_queue()
1620 if (phy->chandef.chan->band != NL80211_BAND_2GHZ) in mt76_calculate_default_rate()
1638 int i, ei = wi->initial_stat_idx; in mt76_ethtool_worker()
1639 u64 *data = wi->data; in mt76_ethtool_worker()
1641 wi->sta_count++; in mt76_ethtool_worker()
1643 data[ei++] += stats->tx_mode[MT_PHY_TYPE_CCK]; in mt76_ethtool_worker()
1644 data[ei++] += stats->tx_mode[MT_PHY_TYPE_OFDM]; in mt76_ethtool_worker()
1645 data[ei++] += stats->tx_mode[MT_PHY_TYPE_HT]; in mt76_ethtool_worker()
1646 data[ei++] += stats->tx_mode[MT_PHY_TYPE_HT_GF]; in mt76_ethtool_worker()
1647 data[ei++] += stats->tx_mode[MT_PHY_TYPE_VHT]; in mt76_ethtool_worker()
1648 data[ei++] += stats->tx_mode[MT_PHY_TYPE_HE_SU]; in mt76_ethtool_worker()
1649 data[ei++] += stats->tx_mode[MT_PHY_TYPE_HE_EXT_SU]; in mt76_ethtool_worker()
1650 data[ei++] += stats->tx_mode[MT_PHY_TYPE_HE_TB]; in mt76_ethtool_worker()
1651 data[ei++] += stats->tx_mode[MT_PHY_TYPE_HE_MU]; in mt76_ethtool_worker()
1653 for (i = 0; i < ARRAY_SIZE(stats->tx_bw); i++) in mt76_ethtool_worker()
1654 data[ei++] += stats->tx_bw[i]; in mt76_ethtool_worker()
1657 data[ei++] += stats->tx_mcs[i]; in mt76_ethtool_worker()
1659 wi->worker_stat_count = ei - wi->initial_stat_idx; in mt76_ethtool_worker()
1665 struct ieee80211_hw *hw = phy->hw; in mt76_phy_dfs_state()
1666 struct mt76_dev *dev = phy->dev; in mt76_phy_dfs_state()
1668 if (dev->region == NL80211_DFS_UNSET || in mt76_phy_dfs_state()
1669 test_bit(MT76_SCANNING, &phy->state)) in mt76_phy_dfs_state()
1672 if (!hw->conf.radar_enabled) { in mt76_phy_dfs_state()
1673 if ((hw->conf.flags & IEEE80211_CONF_MONITOR) && in mt76_phy_dfs_state()
1674 (phy->chandef.chan->flags & IEEE80211_CHAN_RADAR)) in mt76_phy_dfs_state()
1680 if (!cfg80211_reg_can_beacon(hw->wiphy, &phy->chandef, NL80211_IFTYPE_AP)) in mt76_phy_dfs_state()