1 // SPDX-License-Identifier: ISC
3 * Copyright (C) 2016 Felix Fietkau <nbd@nbd.name>
5 #include <linux/sched.h>
9 #define CHAN2G(_idx, _freq) { \
10 .band = NL80211_BAND_2GHZ, \
11 .center_freq = (_freq), \
16 #define CHAN5G(_idx, _freq) { \
17 .band = NL80211_BAND_5GHZ, \
18 .center_freq = (_freq), \
23 #define CHAN6G(_idx, _freq) { \
24 .band = NL80211_BAND_6GHZ, \
25 .center_freq = (_freq), \
30 static const struct ieee80211_channel mt76_channels_2ghz[] = {
47 static const struct ieee80211_channel mt76_channels_5ghz[] = {
80 static const struct ieee80211_channel mt76_channels_6ghz[] = {
146 static const struct ieee80211_tpt_blink mt76_tpt_blink[] = {
147 { .throughput = 0 * 1024, .blink_time = 334 },
148 { .throughput = 1 * 1024, .blink_time = 260 },
149 { .throughput = 5 * 1024, .blink_time = 220 },
150 { .throughput = 10 * 1024, .blink_time = 190 },
151 { .throughput = 20 * 1024, .blink_time = 170 },
152 { .throughput = 50 * 1024, .blink_time = 150 },
153 { .throughput = 70 * 1024, .blink_time = 130 },
154 { .throughput = 100 * 1024, .blink_time = 110 },
155 { .throughput = 200 * 1024, .blink_time = 80 },
156 { .throughput = 300 * 1024, .blink_time = 50 },
159 struct ieee80211_rate mt76_rates[] = {
173 EXPORT_SYMBOL_GPL(mt76_rates);
175 static const struct cfg80211_sar_freq_ranges mt76_sar_freq_ranges[] = {
176 { .start_freq = 2402, .end_freq = 2494, },
177 { .start_freq = 5150, .end_freq = 5350, },
178 { .start_freq = 5350, .end_freq = 5470, },
179 { .start_freq = 5470, .end_freq = 5725, },
180 { .start_freq = 5725, .end_freq = 5950, },
183 static const struct cfg80211_sar_capa mt76_sar_capa = {
184 .type = NL80211_SAR_TYPE_POWER,
185 .num_freq_ranges = ARRAY_SIZE(mt76_sar_freq_ranges),
186 .freq_ranges = &mt76_sar_freq_ranges[0],
189 static int mt76_led_init(struct mt76_dev *dev)
191 struct device_node *np = dev->dev->of_node;
192 struct ieee80211_hw *hw = dev->hw;
195 if (!dev->led_cdev.brightness_set && !dev->led_cdev.blink_set)
198 snprintf(dev->led_name, sizeof(dev->led_name),
199 "mt76-%s", wiphy_name(hw->wiphy));
201 dev->led_cdev.name = dev->led_name;
202 dev->led_cdev.default_trigger =
203 ieee80211_create_tpt_led_trigger(hw,
204 IEEE80211_TPT_LEDTRIG_FL_RADIO,
206 ARRAY_SIZE(mt76_tpt_blink));
208 np = of_get_child_by_name(np, "led");
210 if (!of_property_read_u32(np, "led-sources", &led_pin))
211 dev->led_pin = led_pin;
212 dev->led_al = of_property_read_bool(np, "led-active-low");
216 return led_classdev_register(dev->dev, &dev->led_cdev);
219 static void mt76_led_cleanup(struct mt76_dev *dev)
221 if (!dev->led_cdev.brightness_set && !dev->led_cdev.blink_set)
224 led_classdev_unregister(&dev->led_cdev);
227 static void mt76_init_stream_cap(struct mt76_phy *phy,
228 struct ieee80211_supported_band *sband,
231 struct ieee80211_sta_ht_cap *ht_cap = &sband->ht_cap;
232 int i, nstream = hweight8(phy->antenna_mask);
233 struct ieee80211_sta_vht_cap *vht_cap;
237 ht_cap->cap |= IEEE80211_HT_CAP_TX_STBC;
239 ht_cap->cap &= ~IEEE80211_HT_CAP_TX_STBC;
241 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
242 ht_cap->mcs.rx_mask[i] = i < nstream ? 0xff : 0;
247 vht_cap = &sband->vht_cap;
249 vht_cap->cap |= IEEE80211_VHT_CAP_TXSTBC;
251 vht_cap->cap &= ~IEEE80211_VHT_CAP_TXSTBC;
252 vht_cap->cap |= IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN |
253 IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN;
255 for (i = 0; i < 8; i++) {
257 mcs_map |= (IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2));
260 (IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2));
262 vht_cap->vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
263 vht_cap->vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
266 void mt76_set_stream_caps(struct mt76_phy *phy, bool vht)
268 if (phy->cap.has_2ghz)
269 mt76_init_stream_cap(phy, &phy->sband_2g.sband, false);
270 if (phy->cap.has_5ghz)
271 mt76_init_stream_cap(phy, &phy->sband_5g.sband, vht);
272 if (phy->cap.has_6ghz)
273 mt76_init_stream_cap(phy, &phy->sband_6g.sband, vht);
275 EXPORT_SYMBOL_GPL(mt76_set_stream_caps);
278 mt76_init_sband(struct mt76_phy *phy, struct mt76_sband *msband,
279 const struct ieee80211_channel *chan, int n_chan,
280 struct ieee80211_rate *rates, int n_rates,
283 struct ieee80211_supported_band *sband = &msband->sband;
284 struct ieee80211_sta_vht_cap *vht_cap;
285 struct ieee80211_sta_ht_cap *ht_cap;
286 struct mt76_dev *dev = phy->dev;
290 size = n_chan * sizeof(*chan);
291 chanlist = devm_kmemdup(dev->dev, chan, size, GFP_KERNEL);
295 msband->chan = devm_kcalloc(dev->dev, n_chan, sizeof(*msband->chan),
300 sband->channels = chanlist;
301 sband->n_channels = n_chan;
302 sband->bitrates = rates;
303 sband->n_bitrates = n_rates;
308 ht_cap = &sband->ht_cap;
309 ht_cap->ht_supported = true;
310 ht_cap->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
311 IEEE80211_HT_CAP_GRN_FLD |
312 IEEE80211_HT_CAP_SGI_20 |
313 IEEE80211_HT_CAP_SGI_40 |
314 (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT);
316 ht_cap->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
317 ht_cap->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
319 mt76_init_stream_cap(phy, sband, vht);
324 vht_cap = &sband->vht_cap;
325 vht_cap->vht_supported = true;
326 vht_cap->cap |= IEEE80211_VHT_CAP_RXLDPC |
327 IEEE80211_VHT_CAP_RXSTBC_1 |
328 IEEE80211_VHT_CAP_SHORT_GI_80 |
329 (3 << IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
335 mt76_init_sband_2g(struct mt76_phy *phy, struct ieee80211_rate *rates,
338 phy->hw->wiphy->bands[NL80211_BAND_2GHZ] = &phy->sband_2g.sband;
340 return mt76_init_sband(phy, &phy->sband_2g, mt76_channels_2ghz,
341 ARRAY_SIZE(mt76_channels_2ghz), rates,
342 n_rates, true, false);
346 mt76_init_sband_5g(struct mt76_phy *phy, struct ieee80211_rate *rates,
347 int n_rates, bool vht)
349 phy->hw->wiphy->bands[NL80211_BAND_5GHZ] = &phy->sband_5g.sband;
351 return mt76_init_sband(phy, &phy->sband_5g, mt76_channels_5ghz,
352 ARRAY_SIZE(mt76_channels_5ghz), rates,
357 mt76_init_sband_6g(struct mt76_phy *phy, struct ieee80211_rate *rates,
360 phy->hw->wiphy->bands[NL80211_BAND_6GHZ] = &phy->sband_6g.sband;
362 return mt76_init_sband(phy, &phy->sband_6g, mt76_channels_6ghz,
363 ARRAY_SIZE(mt76_channels_6ghz), rates,
364 n_rates, false, false);
368 mt76_check_sband(struct mt76_phy *phy, struct mt76_sband *msband,
369 enum nl80211_band band)
371 struct ieee80211_supported_band *sband = &msband->sband;
378 for (i = 0; i < sband->n_channels; i++) {
379 if (sband->channels[i].flags & IEEE80211_CHAN_DISABLED)
387 phy->chandef.chan = &sband->channels[0];
388 phy->chan_state = &msband->chan[0];
392 sband->n_channels = 0;
393 phy->hw->wiphy->bands[band] = NULL;
397 mt76_phy_init(struct mt76_phy *phy, struct ieee80211_hw *hw)
399 struct mt76_dev *dev = phy->dev;
400 struct wiphy *wiphy = hw->wiphy;
402 SET_IEEE80211_DEV(hw, dev->dev);
403 SET_IEEE80211_PERM_ADDR(hw, phy->macaddr);
405 wiphy->features |= NL80211_FEATURE_ACTIVE_MONITOR;
406 wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH |
407 WIPHY_FLAG_SUPPORTS_TDLS |
410 wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST);
411 wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_AIRTIME_FAIRNESS);
412 wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_AQL);
414 wiphy->available_antennas_tx = phy->antenna_mask;
415 wiphy->available_antennas_rx = phy->antenna_mask;
417 wiphy->sar_capa = &mt76_sar_capa;
418 phy->frp = devm_kcalloc(dev->dev, wiphy->sar_capa->num_freq_ranges,
419 sizeof(struct mt76_freq_range_power),
424 hw->txq_data_size = sizeof(struct mt76_txq);
425 hw->uapsd_max_sp_len = IEEE80211_WMM_IE_STA_QOSINFO_SP_ALL;
427 if (!hw->max_tx_fragments)
428 hw->max_tx_fragments = 16;
430 ieee80211_hw_set(hw, SIGNAL_DBM);
431 ieee80211_hw_set(hw, AMPDU_AGGREGATION);
432 ieee80211_hw_set(hw, SUPPORTS_RC_TABLE);
433 ieee80211_hw_set(hw, SUPPORT_FAST_XMIT);
434 ieee80211_hw_set(hw, SUPPORTS_CLONED_SKBS);
435 ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU);
436 ieee80211_hw_set(hw, SUPPORTS_REORDERING_BUFFER);
437 ieee80211_hw_set(hw, TX_AMSDU);
438 ieee80211_hw_set(hw, TX_FRAG_LIST);
439 ieee80211_hw_set(hw, MFP_CAPABLE);
440 ieee80211_hw_set(hw, AP_LINK_PS);
441 ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
447 mt76_alloc_phy(struct mt76_dev *dev, unsigned int size,
448 const struct ieee80211_ops *ops)
450 struct ieee80211_hw *hw;
451 unsigned int phy_size;
452 struct mt76_phy *phy;
454 phy_size = ALIGN(sizeof(*phy), 8);
455 hw = ieee80211_alloc_hw(size + phy_size, ops);
462 phy->priv = hw->priv + phy_size;
464 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
465 hw->wiphy->interface_modes =
466 BIT(NL80211_IFTYPE_STATION) |
467 BIT(NL80211_IFTYPE_AP) |
468 #ifdef CONFIG_MAC80211_MESH
469 BIT(NL80211_IFTYPE_MESH_POINT) |
471 BIT(NL80211_IFTYPE_P2P_CLIENT) |
472 BIT(NL80211_IFTYPE_P2P_GO) |
473 BIT(NL80211_IFTYPE_ADHOC);
477 EXPORT_SYMBOL_GPL(mt76_alloc_phy);
479 int mt76_register_phy(struct mt76_phy *phy, bool vht,
480 struct ieee80211_rate *rates, int n_rates)
484 ret = mt76_phy_init(phy, phy->hw);
488 if (phy->cap.has_2ghz) {
489 ret = mt76_init_sband_2g(phy, rates, n_rates);
494 if (phy->cap.has_5ghz) {
495 ret = mt76_init_sband_5g(phy, rates + 4, n_rates - 4, vht);
500 if (phy->cap.has_6ghz) {
501 ret = mt76_init_sband_6g(phy, rates + 4, n_rates - 4);
506 wiphy_read_of_freq_limits(phy->hw->wiphy);
507 mt76_check_sband(phy, &phy->sband_2g, NL80211_BAND_2GHZ);
508 mt76_check_sband(phy, &phy->sband_5g, NL80211_BAND_5GHZ);
509 mt76_check_sband(phy, &phy->sband_6g, NL80211_BAND_6GHZ);
511 ret = ieee80211_register_hw(phy->hw);
515 phy->dev->phy2 = phy;
519 EXPORT_SYMBOL_GPL(mt76_register_phy);
521 void mt76_unregister_phy(struct mt76_phy *phy)
523 struct mt76_dev *dev = phy->dev;
525 mt76_tx_status_check(dev, true);
526 ieee80211_unregister_hw(phy->hw);
529 EXPORT_SYMBOL_GPL(mt76_unregister_phy);
532 mt76_alloc_device(struct device *pdev, unsigned int size,
533 const struct ieee80211_ops *ops,
534 const struct mt76_driver_ops *drv_ops)
536 struct ieee80211_hw *hw;
537 struct mt76_phy *phy;
538 struct mt76_dev *dev;
541 hw = ieee80211_alloc_hw(size, ops);
554 spin_lock_init(&dev->rx_lock);
555 spin_lock_init(&dev->lock);
556 spin_lock_init(&dev->cc_lock);
557 spin_lock_init(&dev->status_lock);
558 mutex_init(&dev->mutex);
559 init_waitqueue_head(&dev->tx_wait);
561 skb_queue_head_init(&dev->mcu.res_q);
562 init_waitqueue_head(&dev->mcu.wait);
563 mutex_init(&dev->mcu.mutex);
564 dev->tx_worker.fn = mt76_tx_worker;
566 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
567 hw->wiphy->interface_modes =
568 BIT(NL80211_IFTYPE_STATION) |
569 BIT(NL80211_IFTYPE_AP) |
570 #ifdef CONFIG_MAC80211_MESH
571 BIT(NL80211_IFTYPE_MESH_POINT) |
573 BIT(NL80211_IFTYPE_P2P_CLIENT) |
574 BIT(NL80211_IFTYPE_P2P_GO) |
575 BIT(NL80211_IFTYPE_ADHOC);
577 spin_lock_init(&dev->token_lock);
578 idr_init(&dev->token);
580 INIT_LIST_HEAD(&dev->wcid_list);
582 INIT_LIST_HEAD(&dev->txwi_cache);
584 for (i = 0; i < ARRAY_SIZE(dev->q_rx); i++)
585 skb_queue_head_init(&dev->rx_skb[i]);
587 dev->wq = alloc_ordered_workqueue("mt76", 0);
589 ieee80211_free_hw(hw);
595 EXPORT_SYMBOL_GPL(mt76_alloc_device);
597 int mt76_register_device(struct mt76_dev *dev, bool vht,
598 struct ieee80211_rate *rates, int n_rates)
600 struct ieee80211_hw *hw = dev->hw;
601 struct mt76_phy *phy = &dev->phy;
604 dev_set_drvdata(dev->dev, dev);
605 ret = mt76_phy_init(phy, hw);
609 if (phy->cap.has_2ghz) {
610 ret = mt76_init_sband_2g(phy, rates, n_rates);
615 if (phy->cap.has_5ghz) {
616 ret = mt76_init_sband_5g(phy, rates + 4, n_rates - 4, vht);
621 if (phy->cap.has_6ghz) {
622 ret = mt76_init_sband_6g(phy, rates + 4, n_rates - 4);
627 wiphy_read_of_freq_limits(hw->wiphy);
628 mt76_check_sband(&dev->phy, &phy->sband_2g, NL80211_BAND_2GHZ);
629 mt76_check_sband(&dev->phy, &phy->sband_5g, NL80211_BAND_5GHZ);
630 mt76_check_sband(&dev->phy, &phy->sband_6g, NL80211_BAND_6GHZ);
632 if (IS_ENABLED(CONFIG_MT76_LEDS)) {
633 ret = mt76_led_init(dev);
638 ret = ieee80211_register_hw(hw);
642 WARN_ON(mt76_worker_setup(hw, &dev->tx_worker, NULL, "tx"));
643 sched_set_fifo_low(dev->tx_worker.task);
647 EXPORT_SYMBOL_GPL(mt76_register_device);
649 void mt76_unregister_device(struct mt76_dev *dev)
651 struct ieee80211_hw *hw = dev->hw;
653 if (IS_ENABLED(CONFIG_MT76_LEDS))
654 mt76_led_cleanup(dev);
655 mt76_tx_status_check(dev, true);
656 ieee80211_unregister_hw(hw);
658 EXPORT_SYMBOL_GPL(mt76_unregister_device);
660 void mt76_free_device(struct mt76_dev *dev)
662 mt76_worker_teardown(&dev->tx_worker);
664 destroy_workqueue(dev->wq);
667 ieee80211_free_hw(dev->hw);
669 EXPORT_SYMBOL_GPL(mt76_free_device);
671 static void mt76_rx_release_amsdu(struct mt76_phy *phy, enum mt76_rxq_id q)
673 struct sk_buff *skb = phy->rx_amsdu[q].head;
674 struct mt76_rx_status *status = (struct mt76_rx_status *)skb->cb;
675 struct mt76_dev *dev = phy->dev;
677 phy->rx_amsdu[q].head = NULL;
678 phy->rx_amsdu[q].tail = NULL;
681 * Validate if the amsdu has a proper first subframe.
682 * A single MSDU can be parsed as A-MSDU when the unauthenticated A-MSDU
683 * flag of the QoS header gets flipped. In such cases, the first
684 * subframe has a LLC/SNAP header in the location of the destination
687 if (skb_shinfo(skb)->frag_list) {
690 if (!(status->flag & RX_FLAG_8023)) {
691 offset = ieee80211_get_hdrlen_from_skb(skb);
694 (RX_FLAG_DECRYPTED | RX_FLAG_IV_STRIPPED)) ==
699 if (ether_addr_equal(skb->data + offset, rfc1042_header)) {
704 __skb_queue_tail(&dev->rx_skb[q], skb);
707 static void mt76_rx_release_burst(struct mt76_phy *phy, enum mt76_rxq_id q,
710 struct mt76_rx_status *status = (struct mt76_rx_status *)skb->cb;
712 if (phy->rx_amsdu[q].head &&
713 (!status->amsdu || status->first_amsdu ||
714 status->seqno != phy->rx_amsdu[q].seqno))
715 mt76_rx_release_amsdu(phy, q);
717 if (!phy->rx_amsdu[q].head) {
718 phy->rx_amsdu[q].tail = &skb_shinfo(skb)->frag_list;
719 phy->rx_amsdu[q].seqno = status->seqno;
720 phy->rx_amsdu[q].head = skb;
722 *phy->rx_amsdu[q].tail = skb;
723 phy->rx_amsdu[q].tail = &skb->next;
726 if (!status->amsdu || status->last_amsdu)
727 mt76_rx_release_amsdu(phy, q);
730 void mt76_rx(struct mt76_dev *dev, enum mt76_rxq_id q, struct sk_buff *skb)
732 struct mt76_rx_status *status = (struct mt76_rx_status *)skb->cb;
733 struct mt76_phy *phy = mt76_dev_phy(dev, status->ext_phy);
735 if (!test_bit(MT76_STATE_RUNNING, &phy->state)) {
740 #ifdef CONFIG_NL80211_TESTMODE
741 if (phy->test.state == MT76_TM_STATE_RX_FRAMES) {
742 phy->test.rx_stats.packets[q]++;
743 if (status->flag & RX_FLAG_FAILED_FCS_CRC)
744 phy->test.rx_stats.fcs_error[q]++;
748 mt76_rx_release_burst(phy, q, skb);
750 EXPORT_SYMBOL_GPL(mt76_rx);
752 bool mt76_has_tx_pending(struct mt76_phy *phy)
754 struct mt76_queue *q;
757 for (i = 0; i < __MT_TXQ_MAX; i++) {
765 EXPORT_SYMBOL_GPL(mt76_has_tx_pending);
767 static struct mt76_channel_state *
768 mt76_channel_state(struct mt76_phy *phy, struct ieee80211_channel *c)
770 struct mt76_sband *msband;
773 if (c->band == NL80211_BAND_2GHZ)
774 msband = &phy->sband_2g;
775 else if (c->band == NL80211_BAND_6GHZ)
776 msband = &phy->sband_6g;
778 msband = &phy->sband_5g;
780 idx = c - &msband->sband.channels[0];
781 return &msband->chan[idx];
784 void mt76_update_survey_active_time(struct mt76_phy *phy, ktime_t time)
786 struct mt76_channel_state *state = phy->chan_state;
788 state->cc_active += ktime_to_us(ktime_sub(time,
790 phy->survey_time = time;
792 EXPORT_SYMBOL_GPL(mt76_update_survey_active_time);
794 void mt76_update_survey(struct mt76_phy *phy)
796 struct mt76_dev *dev = phy->dev;
799 if (dev->drv->update_survey)
800 dev->drv->update_survey(phy);
802 cur_time = ktime_get_boottime();
803 mt76_update_survey_active_time(phy, cur_time);
805 if (dev->drv->drv_flags & MT_DRV_SW_RX_AIRTIME) {
806 struct mt76_channel_state *state = phy->chan_state;
808 spin_lock_bh(&dev->cc_lock);
809 state->cc_bss_rx += dev->cur_cc_bss_rx;
810 dev->cur_cc_bss_rx = 0;
811 spin_unlock_bh(&dev->cc_lock);
814 EXPORT_SYMBOL_GPL(mt76_update_survey);
816 void mt76_set_channel(struct mt76_phy *phy)
818 struct mt76_dev *dev = phy->dev;
819 struct ieee80211_hw *hw = phy->hw;
820 struct cfg80211_chan_def *chandef = &hw->conf.chandef;
821 bool offchannel = hw->conf.flags & IEEE80211_CONF_OFFCHANNEL;
822 int timeout = HZ / 5;
824 wait_event_timeout(dev->tx_wait, !mt76_has_tx_pending(phy), timeout);
825 mt76_update_survey(phy);
827 if (phy->chandef.chan->center_freq != chandef->chan->center_freq ||
828 phy->chandef.width != chandef->width)
829 phy->dfs_state = MT_DFS_STATE_UNKNOWN;
831 phy->chandef = *chandef;
832 phy->chan_state = mt76_channel_state(phy, chandef->chan);
835 phy->main_chan = chandef->chan;
837 if (chandef->chan != phy->main_chan)
838 memset(phy->chan_state, 0, sizeof(*phy->chan_state));
840 EXPORT_SYMBOL_GPL(mt76_set_channel);
842 int mt76_get_survey(struct ieee80211_hw *hw, int idx,
843 struct survey_info *survey)
845 struct mt76_phy *phy = hw->priv;
846 struct mt76_dev *dev = phy->dev;
847 struct mt76_sband *sband;
848 struct ieee80211_channel *chan;
849 struct mt76_channel_state *state;
852 mutex_lock(&dev->mutex);
853 if (idx == 0 && dev->drv->update_survey)
854 mt76_update_survey(phy);
856 if (idx >= phy->sband_2g.sband.n_channels +
857 phy->sband_5g.sband.n_channels) {
858 idx -= (phy->sband_2g.sband.n_channels +
859 phy->sband_5g.sband.n_channels);
860 sband = &phy->sband_6g;
861 } else if (idx >= phy->sband_2g.sband.n_channels) {
862 idx -= phy->sband_2g.sband.n_channels;
863 sband = &phy->sband_5g;
865 sband = &phy->sband_2g;
868 if (idx >= sband->sband.n_channels) {
873 chan = &sband->sband.channels[idx];
874 state = mt76_channel_state(phy, chan);
876 memset(survey, 0, sizeof(*survey));
877 survey->channel = chan;
878 survey->filled = SURVEY_INFO_TIME | SURVEY_INFO_TIME_BUSY;
879 survey->filled |= dev->drv->survey_flags;
881 survey->filled |= SURVEY_INFO_NOISE_DBM;
883 if (chan == phy->main_chan) {
884 survey->filled |= SURVEY_INFO_IN_USE;
886 if (dev->drv->drv_flags & MT_DRV_SW_RX_AIRTIME)
887 survey->filled |= SURVEY_INFO_TIME_BSS_RX;
890 survey->time_busy = div_u64(state->cc_busy, 1000);
891 survey->time_rx = div_u64(state->cc_rx, 1000);
892 survey->time = div_u64(state->cc_active, 1000);
893 survey->noise = state->noise;
895 spin_lock_bh(&dev->cc_lock);
896 survey->time_bss_rx = div_u64(state->cc_bss_rx, 1000);
897 survey->time_tx = div_u64(state->cc_tx, 1000);
898 spin_unlock_bh(&dev->cc_lock);
901 mutex_unlock(&dev->mutex);
905 EXPORT_SYMBOL_GPL(mt76_get_survey);
907 void mt76_wcid_key_setup(struct mt76_dev *dev, struct mt76_wcid *wcid,
908 struct ieee80211_key_conf *key)
910 struct ieee80211_key_seq seq;
913 wcid->rx_check_pn = false;
918 if (key->cipher != WLAN_CIPHER_SUITE_CCMP)
921 wcid->rx_check_pn = true;
924 for (i = 0; i < IEEE80211_NUM_TIDS; i++) {
925 ieee80211_get_key_rx_seq(key, i, &seq);
926 memcpy(wcid->rx_key_pn[i], seq.ccmp.pn, sizeof(seq.ccmp.pn));
929 /* robust management frame */
930 ieee80211_get_key_rx_seq(key, -1, &seq);
931 memcpy(wcid->rx_key_pn[i], seq.ccmp.pn, sizeof(seq.ccmp.pn));
934 EXPORT_SYMBOL(mt76_wcid_key_setup);
937 mt76_rx_signal(struct mt76_rx_status *status)
939 s8 *chain_signal = status->chain_signal;
943 for (chains = status->chains; chains; chains >>= 1, chain_signal++) {
947 if (!(chains & BIT(0)) ||
967 mt76_rx_convert(struct mt76_dev *dev, struct sk_buff *skb,
968 struct ieee80211_hw **hw,
969 struct ieee80211_sta **sta)
971 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
972 struct ieee80211_hdr *hdr = mt76_skb_get_hdr(skb);
973 struct mt76_rx_status mstat;
975 mstat = *((struct mt76_rx_status *)skb->cb);
976 memset(status, 0, sizeof(*status));
978 status->flag = mstat.flag;
979 status->freq = mstat.freq;
980 status->enc_flags = mstat.enc_flags;
981 status->encoding = mstat.encoding;
982 status->bw = mstat.bw;
983 status->he_ru = mstat.he_ru;
984 status->he_gi = mstat.he_gi;
985 status->he_dcm = mstat.he_dcm;
986 status->rate_idx = mstat.rate_idx;
987 status->nss = mstat.nss;
988 status->band = mstat.band;
989 status->signal = mstat.signal;
990 status->chains = mstat.chains;
991 status->ampdu_reference = mstat.ampdu_ref;
992 status->device_timestamp = mstat.timestamp;
993 status->mactime = mstat.timestamp;
994 status->signal = mt76_rx_signal(&mstat);
995 if (status->signal <= -128)
996 status->flag |= RX_FLAG_NO_SIGNAL_VAL;
998 if (ieee80211_is_beacon(hdr->frame_control) ||
999 ieee80211_is_probe_resp(hdr->frame_control))
1000 status->boottime_ns = ktime_get_boottime_ns();
1002 BUILD_BUG_ON(sizeof(mstat) > sizeof(skb->cb));
1003 BUILD_BUG_ON(sizeof(status->chain_signal) !=
1004 sizeof(mstat.chain_signal));
1005 memcpy(status->chain_signal, mstat.chain_signal,
1006 sizeof(mstat.chain_signal));
1008 *sta = wcid_to_sta(mstat.wcid);
1009 *hw = mt76_phy_hw(dev, mstat.ext_phy);
1013 mt76_check_ccmp_pn(struct sk_buff *skb)
1015 struct mt76_rx_status *status = (struct mt76_rx_status *)skb->cb;
1016 struct mt76_wcid *wcid = status->wcid;
1017 struct ieee80211_hdr *hdr;
1021 if (!(status->flag & RX_FLAG_DECRYPTED))
1024 if (!wcid || !wcid->rx_check_pn)
1027 security_idx = status->qos_ctl & IEEE80211_QOS_CTL_TID_MASK;
1028 if (status->flag & RX_FLAG_8023)
1029 goto skip_hdr_check;
1031 hdr = mt76_skb_get_hdr(skb);
1032 if (!(status->flag & RX_FLAG_IV_STRIPPED)) {
1034 * Validate the first fragment both here and in mac80211
1035 * All further fragments will be validated by mac80211 only.
1037 if (ieee80211_is_frag(hdr) &&
1038 !ieee80211_is_first_frag(hdr->frame_control))
1042 /* IEEE 802.11-2020, 12.5.3.4.4 "PN and replay detection" c):
1044 * the recipient shall maintain a single replay counter for received
1045 * individually addressed robust Management frames that are received
1046 * with the To DS subfield equal to 0, [...]
1048 if (ieee80211_is_mgmt(hdr->frame_control) &&
1049 !ieee80211_has_tods(hdr->frame_control))
1050 security_idx = IEEE80211_NUM_TIDS;
1053 BUILD_BUG_ON(sizeof(status->iv) != sizeof(wcid->rx_key_pn[0]));
1054 ret = memcmp(status->iv, wcid->rx_key_pn[security_idx],
1055 sizeof(status->iv));
1057 return -EINVAL; /* replay */
1059 memcpy(wcid->rx_key_pn[security_idx], status->iv, sizeof(status->iv));
1061 if (status->flag & RX_FLAG_IV_STRIPPED)
1062 status->flag |= RX_FLAG_PN_VALIDATED;
1068 mt76_airtime_report(struct mt76_dev *dev, struct mt76_rx_status *status,
1071 struct mt76_wcid *wcid = status->wcid;
1072 struct ieee80211_rx_status info = {
1073 .enc_flags = status->enc_flags,
1074 .rate_idx = status->rate_idx,
1075 .encoding = status->encoding,
1076 .band = status->band,
1080 struct ieee80211_sta *sta;
1082 u8 tidno = status->qos_ctl & IEEE80211_QOS_CTL_TID_MASK;
1084 airtime = ieee80211_calc_rx_airtime(dev->hw, &info, len);
1085 spin_lock(&dev->cc_lock);
1086 dev->cur_cc_bss_rx += airtime;
1087 spin_unlock(&dev->cc_lock);
1089 if (!wcid || !wcid->sta)
1092 sta = container_of((void *)wcid, struct ieee80211_sta, drv_priv);
1093 ieee80211_sta_register_airtime(sta, tidno, 0, airtime);
1097 mt76_airtime_flush_ampdu(struct mt76_dev *dev)
1099 struct mt76_wcid *wcid;
1102 if (!dev->rx_ampdu_len)
1105 wcid_idx = dev->rx_ampdu_status.wcid_idx;
1106 if (wcid_idx < ARRAY_SIZE(dev->wcid))
1107 wcid = rcu_dereference(dev->wcid[wcid_idx]);
1110 dev->rx_ampdu_status.wcid = wcid;
1112 mt76_airtime_report(dev, &dev->rx_ampdu_status, dev->rx_ampdu_len);
1114 dev->rx_ampdu_len = 0;
1115 dev->rx_ampdu_ref = 0;
1119 mt76_airtime_check(struct mt76_dev *dev, struct sk_buff *skb)
1121 struct mt76_rx_status *status = (struct mt76_rx_status *)skb->cb;
1122 struct mt76_wcid *wcid = status->wcid;
1124 if (!(dev->drv->drv_flags & MT_DRV_SW_RX_AIRTIME))
1127 if (!wcid || !wcid->sta) {
1128 struct ieee80211_hdr *hdr = mt76_skb_get_hdr(skb);
1130 if (status->flag & RX_FLAG_8023)
1133 if (!ether_addr_equal(hdr->addr1, dev->phy.macaddr))
1139 if (!(status->flag & RX_FLAG_AMPDU_DETAILS) ||
1140 status->ampdu_ref != dev->rx_ampdu_ref)
1141 mt76_airtime_flush_ampdu(dev);
1143 if (status->flag & RX_FLAG_AMPDU_DETAILS) {
1144 if (!dev->rx_ampdu_len ||
1145 status->ampdu_ref != dev->rx_ampdu_ref) {
1146 dev->rx_ampdu_status = *status;
1147 dev->rx_ampdu_status.wcid_idx = wcid ? wcid->idx : 0xff;
1148 dev->rx_ampdu_ref = status->ampdu_ref;
1151 dev->rx_ampdu_len += skb->len;
1155 mt76_airtime_report(dev, status, skb->len);
1159 mt76_check_sta(struct mt76_dev *dev, struct sk_buff *skb)
1161 struct mt76_rx_status *status = (struct mt76_rx_status *)skb->cb;
1162 struct ieee80211_hdr *hdr = mt76_skb_get_hdr(skb);
1163 struct ieee80211_sta *sta;
1164 struct ieee80211_hw *hw;
1165 struct mt76_wcid *wcid = status->wcid;
1166 u8 tidno = status->qos_ctl & IEEE80211_QOS_CTL_TID_MASK;
1169 hw = mt76_phy_hw(dev, status->ext_phy);
1170 if (ieee80211_is_pspoll(hdr->frame_control) && !wcid &&
1171 !(status->flag & RX_FLAG_8023)) {
1172 sta = ieee80211_find_sta_by_ifaddr(hw, hdr->addr2, NULL);
1174 wcid = status->wcid = (struct mt76_wcid *)sta->drv_priv;
1177 mt76_airtime_check(dev, skb);
1179 if (!wcid || !wcid->sta)
1182 sta = container_of((void *)wcid, struct ieee80211_sta, drv_priv);
1184 if (status->signal <= 0)
1185 ewma_signal_add(&wcid->rssi, -status->signal);
1187 wcid->inactive_count = 0;
1189 if (status->flag & RX_FLAG_8023)
1192 if (!test_bit(MT_WCID_FLAG_CHECK_PS, &wcid->flags))
1195 if (ieee80211_is_pspoll(hdr->frame_control)) {
1196 ieee80211_sta_pspoll(sta);
1200 if (ieee80211_has_morefrags(hdr->frame_control) ||
1201 !(ieee80211_is_mgmt(hdr->frame_control) ||
1202 ieee80211_is_data(hdr->frame_control)))
1205 ps = ieee80211_has_pm(hdr->frame_control);
1207 if (ps && (ieee80211_is_data_qos(hdr->frame_control) ||
1208 ieee80211_is_qos_nullfunc(hdr->frame_control)))
1209 ieee80211_sta_uapsd_trigger(sta, tidno);
1211 if (!!test_bit(MT_WCID_FLAG_PS, &wcid->flags) == ps)
1215 set_bit(MT_WCID_FLAG_PS, &wcid->flags);
1217 dev->drv->sta_ps(dev, sta, ps);
1220 clear_bit(MT_WCID_FLAG_PS, &wcid->flags);
1222 ieee80211_sta_ps_transition(sta, ps);
1225 void mt76_rx_complete(struct mt76_dev *dev, struct sk_buff_head *frames,
1226 struct napi_struct *napi)
1228 struct ieee80211_sta *sta;
1229 struct ieee80211_hw *hw;
1230 struct sk_buff *skb, *tmp;
1233 spin_lock(&dev->rx_lock);
1234 while ((skb = __skb_dequeue(frames)) != NULL) {
1235 struct sk_buff *nskb = skb_shinfo(skb)->frag_list;
1237 if (mt76_check_ccmp_pn(skb)) {
1242 skb_shinfo(skb)->frag_list = NULL;
1243 mt76_rx_convert(dev, skb, &hw, &sta);
1244 ieee80211_rx_list(hw, sta, skb, &list);
1246 /* subsequent amsdu frames */
1252 mt76_rx_convert(dev, skb, &hw, &sta);
1253 ieee80211_rx_list(hw, sta, skb, &list);
1256 spin_unlock(&dev->rx_lock);
1259 netif_receive_skb_list(&list);
1263 list_for_each_entry_safe(skb, tmp, &list, list) {
1264 skb_list_del_init(skb);
1265 napi_gro_receive(napi, skb);
1269 void mt76_rx_poll_complete(struct mt76_dev *dev, enum mt76_rxq_id q,
1270 struct napi_struct *napi)
1272 struct sk_buff_head frames;
1273 struct sk_buff *skb;
1275 __skb_queue_head_init(&frames);
1277 while ((skb = __skb_dequeue(&dev->rx_skb[q])) != NULL) {
1278 mt76_check_sta(dev, skb);
1279 mt76_rx_aggr_reorder(skb, &frames);
1282 mt76_rx_complete(dev, &frames, napi);
1284 EXPORT_SYMBOL_GPL(mt76_rx_poll_complete);
1287 mt76_sta_add(struct mt76_dev *dev, struct ieee80211_vif *vif,
1288 struct ieee80211_sta *sta, bool ext_phy)
1290 struct mt76_wcid *wcid = (struct mt76_wcid *)sta->drv_priv;
1294 mutex_lock(&dev->mutex);
1296 ret = dev->drv->sta_add(dev, vif, sta);
1300 for (i = 0; i < ARRAY_SIZE(sta->txq); i++) {
1301 struct mt76_txq *mtxq;
1306 mtxq = (struct mt76_txq *)sta->txq[i]->drv_priv;
1307 mtxq->wcid = wcid->idx;
1310 ewma_signal_init(&wcid->rssi);
1312 mt76_wcid_mask_set(dev->wcid_phy_mask, wcid->idx);
1313 wcid->ext_phy = ext_phy;
1314 rcu_assign_pointer(dev->wcid[wcid->idx], wcid);
1316 mt76_packet_id_init(wcid);
1318 mutex_unlock(&dev->mutex);
1323 void __mt76_sta_remove(struct mt76_dev *dev, struct ieee80211_vif *vif,
1324 struct ieee80211_sta *sta)
1326 struct mt76_wcid *wcid = (struct mt76_wcid *)sta->drv_priv;
1327 int i, idx = wcid->idx;
1329 for (i = 0; i < ARRAY_SIZE(wcid->aggr); i++)
1330 mt76_rx_aggr_stop(dev, wcid, i);
1332 if (dev->drv->sta_remove)
1333 dev->drv->sta_remove(dev, vif, sta);
1335 mt76_packet_id_flush(dev, wcid);
1337 mt76_wcid_mask_clear(dev->wcid_mask, idx);
1338 mt76_wcid_mask_clear(dev->wcid_phy_mask, idx);
1340 EXPORT_SYMBOL_GPL(__mt76_sta_remove);
1343 mt76_sta_remove(struct mt76_dev *dev, struct ieee80211_vif *vif,
1344 struct ieee80211_sta *sta)
1346 mutex_lock(&dev->mutex);
1347 __mt76_sta_remove(dev, vif, sta);
1348 mutex_unlock(&dev->mutex);
1351 int mt76_sta_state(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1352 struct ieee80211_sta *sta,
1353 enum ieee80211_sta_state old_state,
1354 enum ieee80211_sta_state new_state)
1356 struct mt76_phy *phy = hw->priv;
1357 struct mt76_dev *dev = phy->dev;
1358 bool ext_phy = phy != &dev->phy;
1360 if (old_state == IEEE80211_STA_NOTEXIST &&
1361 new_state == IEEE80211_STA_NONE)
1362 return mt76_sta_add(dev, vif, sta, ext_phy);
1364 if (old_state == IEEE80211_STA_AUTH &&
1365 new_state == IEEE80211_STA_ASSOC &&
1366 dev->drv->sta_assoc)
1367 dev->drv->sta_assoc(dev, vif, sta);
1369 if (old_state == IEEE80211_STA_NONE &&
1370 new_state == IEEE80211_STA_NOTEXIST)
1371 mt76_sta_remove(dev, vif, sta);
1375 EXPORT_SYMBOL_GPL(mt76_sta_state);
1377 void mt76_sta_pre_rcu_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1378 struct ieee80211_sta *sta)
1380 struct mt76_phy *phy = hw->priv;
1381 struct mt76_dev *dev = phy->dev;
1382 struct mt76_wcid *wcid = (struct mt76_wcid *)sta->drv_priv;
1384 mutex_lock(&dev->mutex);
1385 spin_lock_bh(&dev->status_lock);
1386 rcu_assign_pointer(dev->wcid[wcid->idx], NULL);
1387 spin_unlock_bh(&dev->status_lock);
1388 mutex_unlock(&dev->mutex);
1390 EXPORT_SYMBOL_GPL(mt76_sta_pre_rcu_remove);
1392 int mt76_get_txpower(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1395 struct mt76_phy *phy = hw->priv;
1396 int n_chains = hweight8(phy->antenna_mask);
1397 int delta = mt76_tx_power_nss_delta(n_chains);
1399 *dbm = DIV_ROUND_UP(phy->txpower_cur + delta, 2);
1403 EXPORT_SYMBOL_GPL(mt76_get_txpower);
1405 int mt76_init_sar_power(struct ieee80211_hw *hw,
1406 const struct cfg80211_sar_specs *sar)
1408 struct mt76_phy *phy = hw->priv;
1409 const struct cfg80211_sar_capa *capa = hw->wiphy->sar_capa;
1412 if (sar->type != NL80211_SAR_TYPE_POWER || !sar->num_sub_specs)
1415 for (i = 0; i < sar->num_sub_specs; i++) {
1416 u32 index = sar->sub_specs[i].freq_range_index;
1417 /* SAR specifies power limitaton in 0.25dbm */
1418 s32 power = sar->sub_specs[i].power >> 1;
1420 if (power > 127 || power < -127)
1423 phy->frp[index].range = &capa->freq_ranges[index];
1424 phy->frp[index].power = power;
1429 EXPORT_SYMBOL_GPL(mt76_init_sar_power);
1431 int mt76_get_sar_power(struct mt76_phy *phy,
1432 struct ieee80211_channel *chan,
1435 const struct cfg80211_sar_capa *capa = phy->hw->wiphy->sar_capa;
1438 if (!capa || !phy->frp)
1441 if (power > 127 || power < -127)
1444 freq = ieee80211_channel_to_frequency(chan->hw_value, chan->band);
1445 for (i = 0 ; i < capa->num_freq_ranges; i++) {
1446 if (phy->frp[i].range &&
1447 freq >= phy->frp[i].range->start_freq &&
1448 freq < phy->frp[i].range->end_freq) {
1449 power = min_t(int, phy->frp[i].power, power);
1456 EXPORT_SYMBOL_GPL(mt76_get_sar_power);
1459 __mt76_csa_finish(void *priv, u8 *mac, struct ieee80211_vif *vif)
1461 if (vif->csa_active && ieee80211_beacon_cntdwn_is_complete(vif))
1462 ieee80211_csa_finish(vif);
1465 void mt76_csa_finish(struct mt76_dev *dev)
1467 if (!dev->csa_complete)
1470 ieee80211_iterate_active_interfaces_atomic(dev->hw,
1471 IEEE80211_IFACE_ITER_RESUME_ALL,
1472 __mt76_csa_finish, dev);
1474 dev->csa_complete = 0;
1476 EXPORT_SYMBOL_GPL(mt76_csa_finish);
1479 __mt76_csa_check(void *priv, u8 *mac, struct ieee80211_vif *vif)
1481 struct mt76_dev *dev = priv;
1483 if (!vif->csa_active)
1486 dev->csa_complete |= ieee80211_beacon_cntdwn_is_complete(vif);
1489 void mt76_csa_check(struct mt76_dev *dev)
1491 ieee80211_iterate_active_interfaces_atomic(dev->hw,
1492 IEEE80211_IFACE_ITER_RESUME_ALL,
1493 __mt76_csa_check, dev);
1495 EXPORT_SYMBOL_GPL(mt76_csa_check);
1498 mt76_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta, bool set)
1502 EXPORT_SYMBOL_GPL(mt76_set_tim);
1504 void mt76_insert_ccmp_hdr(struct sk_buff *skb, u8 key_id)
1506 struct mt76_rx_status *status = (struct mt76_rx_status *)skb->cb;
1507 int hdr_len = ieee80211_get_hdrlen_from_skb(skb);
1508 u8 *hdr, *pn = status->iv;
1511 memmove(skb->data, skb->data + 8, hdr_len);
1512 hdr = skb->data + hdr_len;
1517 hdr[3] = 0x20 | (key_id << 6);
1523 status->flag &= ~RX_FLAG_IV_STRIPPED;
1525 EXPORT_SYMBOL_GPL(mt76_insert_ccmp_hdr);
1527 int mt76_get_rate(struct mt76_dev *dev,
1528 struct ieee80211_supported_band *sband,
1531 int i, offset = 0, len = sband->n_bitrates;
1534 if (sband != &dev->phy.sband_2g.sband)
1537 idx &= ~BIT(2); /* short preamble */
1538 } else if (sband == &dev->phy.sband_2g.sband) {
1542 for (i = offset; i < len; i++) {
1543 if ((sband->bitrates[i].hw_value & GENMASK(7, 0)) == idx)
1549 EXPORT_SYMBOL_GPL(mt76_get_rate);
1551 void mt76_sw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1554 struct mt76_phy *phy = hw->priv;
1556 set_bit(MT76_SCANNING, &phy->state);
1558 EXPORT_SYMBOL_GPL(mt76_sw_scan);
1560 void mt76_sw_scan_complete(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1562 struct mt76_phy *phy = hw->priv;
1564 clear_bit(MT76_SCANNING, &phy->state);
1566 EXPORT_SYMBOL_GPL(mt76_sw_scan_complete);
1568 int mt76_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
1570 struct mt76_phy *phy = hw->priv;
1571 struct mt76_dev *dev = phy->dev;
1573 mutex_lock(&dev->mutex);
1574 *tx_ant = phy->antenna_mask;
1575 *rx_ant = phy->antenna_mask;
1576 mutex_unlock(&dev->mutex);
1580 EXPORT_SYMBOL_GPL(mt76_get_antenna);
1583 mt76_init_queue(struct mt76_dev *dev, int qid, int idx, int n_desc,
1586 struct mt76_queue *hwq;
1589 hwq = devm_kzalloc(dev->dev, sizeof(*hwq), GFP_KERNEL);
1591 return ERR_PTR(-ENOMEM);
1593 err = dev->queue_ops->alloc(dev, hwq, idx, n_desc, 0, ring_base);
1595 return ERR_PTR(err);
1599 EXPORT_SYMBOL_GPL(mt76_init_queue);
1601 u16 mt76_calculate_default_rate(struct mt76_phy *phy, int rateidx)
1605 if (phy->chandef.chan->band != NL80211_BAND_2GHZ)
1608 /* pick the lowest rate for hidden nodes */
1613 if (rateidx >= ARRAY_SIZE(mt76_rates))
1616 return mt76_rates[rateidx].hw_value;
1618 EXPORT_SYMBOL_GPL(mt76_calculate_default_rate);
1620 void mt76_ethtool_worker(struct mt76_ethtool_worker_info *wi,
1621 struct mt76_sta_stats *stats)
1623 int i, ei = wi->initial_stat_idx;
1624 u64 *data = wi->data;
1628 data[ei++] += stats->tx_mode[MT_PHY_TYPE_CCK];
1629 data[ei++] += stats->tx_mode[MT_PHY_TYPE_OFDM];
1630 data[ei++] += stats->tx_mode[MT_PHY_TYPE_HT];
1631 data[ei++] += stats->tx_mode[MT_PHY_TYPE_HT_GF];
1632 data[ei++] += stats->tx_mode[MT_PHY_TYPE_VHT];
1633 data[ei++] += stats->tx_mode[MT_PHY_TYPE_HE_SU];
1634 data[ei++] += stats->tx_mode[MT_PHY_TYPE_HE_EXT_SU];
1635 data[ei++] += stats->tx_mode[MT_PHY_TYPE_HE_TB];
1636 data[ei++] += stats->tx_mode[MT_PHY_TYPE_HE_MU];
1638 for (i = 0; i < ARRAY_SIZE(stats->tx_bw); i++)
1639 data[ei++] += stats->tx_bw[i];
1641 for (i = 0; i < 12; i++)
1642 data[ei++] += stats->tx_mcs[i];
1644 wi->worker_stat_count = ei - wi->initial_stat_idx;
1646 EXPORT_SYMBOL_GPL(mt76_ethtool_worker);
1648 enum mt76_dfs_state mt76_phy_dfs_state(struct mt76_phy *phy)
1650 struct ieee80211_hw *hw = phy->hw;
1651 struct mt76_dev *dev = phy->dev;
1653 if (dev->region == NL80211_DFS_UNSET ||
1654 test_bit(MT76_SCANNING, &phy->state))
1655 return MT_DFS_STATE_DISABLED;
1657 if (!hw->conf.radar_enabled) {
1658 if ((hw->conf.flags & IEEE80211_CONF_MONITOR) &&
1659 (phy->chandef.chan->flags & IEEE80211_CHAN_RADAR))
1660 return MT_DFS_STATE_ACTIVE;
1662 return MT_DFS_STATE_DISABLED;
1665 if (!cfg80211_reg_can_beacon(hw->wiphy, &phy->chandef, NL80211_IFTYPE_AP))
1666 return MT_DFS_STATE_CAC;
1668 return MT_DFS_STATE_ACTIVE;
1670 EXPORT_SYMBOL_GPL(mt76_phy_dfs_state);