Lines Matching +full:wdt +full:- +full:interval

1 // SPDX-License-Identifier: ISC
16 #define to_rssi(field, rcpi) ((FIELD_GET(field, rcpi) - 220) / 2)
19 .pulse_th = { 110, -10, -80, 40, 5200, 128, 5200 },
33 .pulse_th = { 110, -10, -80, 40, 5200, 128, 5200 },
44 .pulse_th = { 110, -10, -80, 40, 5200, 128, 5200 },
63 if (idx >= ARRAY_SIZE(dev->mt76.wcid)) in mt7915_rx_get_wcid()
66 wcid = rcu_dereference(dev->mt76.wcid[idx]); in mt7915_rx_get_wcid()
70 if (!wcid->sta) in mt7915_rx_get_wcid()
74 if (!sta->vif) in mt7915_rx_get_wcid()
77 return &sta->vif->sta.wcid; in mt7915_rx_get_wcid()
116 spin_lock_bh(&dev->mt76.sta_poll_lock); in mt7915_mac_sta_poll()
117 list_splice_init(&dev->mt76.sta_poll_list, &sta_poll_list); in mt7915_mac_sta_poll()
118 spin_unlock_bh(&dev->mt76.sta_poll_lock); in mt7915_mac_sta_poll()
129 spin_lock_bh(&dev->mt76.sta_poll_lock); in mt7915_mac_sta_poll()
131 spin_unlock_bh(&dev->mt76.sta_poll_lock); in mt7915_mac_sta_poll()
136 list_del_init(&msta->wcid.poll_list); in mt7915_mac_sta_poll()
137 spin_unlock_bh(&dev->mt76.sta_poll_lock); in mt7915_mac_sta_poll()
139 idx = msta->wcid.idx; in mt7915_mac_sta_poll()
145 u32 tx_last = msta->airtime_ac[i]; in mt7915_mac_sta_poll()
146 u32 rx_last = msta->airtime_ac[i + 4]; in mt7915_mac_sta_poll()
148 msta->airtime_ac[i] = mt76_rr(dev, addr); in mt7915_mac_sta_poll()
149 msta->airtime_ac[i + 4] = mt76_rr(dev, addr + 4); in mt7915_mac_sta_poll()
151 tx_time[i] = msta->airtime_ac[i] - tx_last; in mt7915_mac_sta_poll()
152 rx_time[i] = msta->airtime_ac[i + 4] - rx_last; in mt7915_mac_sta_poll()
163 memset(msta->airtime_ac, 0, sizeof(msta->airtime_ac)); in mt7915_mac_sta_poll()
166 if (!msta->wcid.sta) in mt7915_mac_sta_poll()
188 * from per-sta counters directly. in mt7915_mac_sta_poll()
190 rate = &msta->wcid.rate; in mt7915_mac_sta_poll()
194 switch (rate->bw) { in mt7915_mac_sta_poll()
209 if (rate->flags & RATE_INFO_FLAGS_HE_MCS) { in mt7915_mac_sta_poll()
212 rate->he_gi = (val & (0x3 << offs)) >> offs; in mt7915_mac_sta_poll()
213 } else if (rate->flags & in mt7915_mac_sta_poll()
216 rate->flags |= RATE_INFO_FLAGS_SHORT_GI; in mt7915_mac_sta_poll()
218 rate->flags &= ~RATE_INFO_FLAGS_SHORT_GI; in mt7915_mac_sta_poll()
230 msta->ack_signal = in mt7915_mac_sta_poll()
231 mt76_rx_signal(msta->vif->phy->mt76->antenna_mask, rssi); in mt7915_mac_sta_poll()
233 ewma_avg_signal_add(&msta->avg_ack_signal, -msta->ack_signal); in mt7915_mac_sta_poll()
242 struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv; in mt7915_mac_enable_rtscts()
245 addr = mt7915_mac_wtbl_lmac_addr(dev, mvif->sta.wcid.idx, 5); in mt7915_mac_enable_rtscts()
260 if (!msta || !msta->vif) in mt7915_wed_check_ppe()
269 vif = container_of((void *)msta->vif, struct ieee80211_vif, in mt7915_wed_check_ppe()
272 skb->dev = wdev->netdev; in mt7915_wed_check_ppe()
274 mtk_wed_device_ppe_check(&dev->mt76.mmio.wed, skb, in mt7915_wed_check_ppe()
283 struct mt76_rx_status *status = (struct mt76_rx_status *)skb->cb; in mt7915_mac_fill_rx()
284 struct mt76_phy *mphy = &dev->mt76.phy; in mt7915_mac_fill_rx()
285 struct mt7915_phy *phy = &dev->phy; in mt7915_mac_fill_rx()
287 __le32 *rxd = (__le32 *)skb->data; in mt7915_mac_fill_rx()
299 u32 csum_status = *(u32 *)skb->cb; in mt7915_mac_fill_rx()
308 if ((rxd1 & MT_RXD1_NORMAL_BAND_IDX) && !phy->mt76->band_idx) { in mt7915_mac_fill_rx()
309 mphy = dev->mt76.phys[MT_BAND1]; in mt7915_mac_fill_rx()
311 return -EINVAL; in mt7915_mac_fill_rx()
313 phy = mphy->priv; in mt7915_mac_fill_rx()
314 status->phy_idx = 1; in mt7915_mac_fill_rx()
317 if (!test_bit(MT76_STATE_RUNNING, &mphy->state)) in mt7915_mac_fill_rx()
318 return -EINVAL; in mt7915_mac_fill_rx()
321 return -EINVAL; in mt7915_mac_fill_rx()
325 return -EINVAL; in mt7915_mac_fill_rx()
329 status->flag |= RX_FLAG_ONLY_MONITOR; in mt7915_mac_fill_rx()
333 status->wcid = mt7915_rx_get_wcid(dev, idx, unicast); in mt7915_mac_fill_rx()
335 if (status->wcid) { in mt7915_mac_fill_rx()
336 msta = container_of(status->wcid, struct mt7915_sta, wcid); in mt7915_mac_fill_rx()
337 spin_lock_bh(&dev->mt76.sta_poll_lock); in mt7915_mac_fill_rx()
338 if (list_empty(&msta->wcid.poll_list)) in mt7915_mac_fill_rx()
339 list_add_tail(&msta->wcid.poll_list, in mt7915_mac_fill_rx()
340 &dev->mt76.sta_poll_list); in mt7915_mac_fill_rx()
341 spin_unlock_bh(&dev->mt76.sta_poll_lock); in mt7915_mac_fill_rx()
344 status->freq = mphy->chandef.chan->center_freq; in mt7915_mac_fill_rx()
345 status->band = mphy->chandef.chan->band; in mt7915_mac_fill_rx()
346 if (status->band == NL80211_BAND_5GHZ) in mt7915_mac_fill_rx()
347 sband = &mphy->sband_5g.sband; in mt7915_mac_fill_rx()
348 else if (status->band == NL80211_BAND_6GHZ) in mt7915_mac_fill_rx()
349 sband = &mphy->sband_6g.sband; in mt7915_mac_fill_rx()
351 sband = &mphy->sband_2g.sband; in mt7915_mac_fill_rx()
353 if (!sband->channels) in mt7915_mac_fill_rx()
354 return -EINVAL; in mt7915_mac_fill_rx()
358 skb->ip_summed = CHECKSUM_UNNECESSARY; in mt7915_mac_fill_rx()
361 status->flag |= RX_FLAG_FAILED_FCS_CRC; in mt7915_mac_fill_rx()
364 status->flag |= RX_FLAG_MMIC_ERROR; in mt7915_mac_fill_rx()
368 status->flag |= RX_FLAG_DECRYPTED; in mt7915_mac_fill_rx()
369 status->flag |= RX_FLAG_IV_STRIPPED; in mt7915_mac_fill_rx()
370 status->flag |= RX_FLAG_MMIC_STRIPPED | RX_FLAG_MIC_STRIPPED; in mt7915_mac_fill_rx()
376 return -EINVAL; in mt7915_mac_fill_rx()
388 if ((u8 *)rxd - skb->data >= skb->len) in mt7915_mac_fill_rx()
389 return -EINVAL; in mt7915_mac_fill_rx()
395 if (status->flag & RX_FLAG_DECRYPTED) { in mt7915_mac_fill_rx()
407 status->iv[0] = data[5]; in mt7915_mac_fill_rx()
408 status->iv[1] = data[4]; in mt7915_mac_fill_rx()
409 status->iv[2] = data[3]; in mt7915_mac_fill_rx()
410 status->iv[3] = data[2]; in mt7915_mac_fill_rx()
411 status->iv[4] = data[1]; in mt7915_mac_fill_rx()
412 status->iv[5] = data[0]; in mt7915_mac_fill_rx()
419 if ((u8 *)rxd - skb->data >= skb->len) in mt7915_mac_fill_rx()
420 return -EINVAL; in mt7915_mac_fill_rx()
424 status->timestamp = le32_to_cpu(rxd[0]); in mt7915_mac_fill_rx()
425 status->flag |= RX_FLAG_MACTIME_START; in mt7915_mac_fill_rx()
428 status->flag |= RX_FLAG_AMPDU_DETAILS; in mt7915_mac_fill_rx()
430 /* all subframes of an A-MPDU have the same timestamp */ in mt7915_mac_fill_rx()
431 if (phy->rx_ampdu_ts != status->timestamp) { in mt7915_mac_fill_rx()
432 if (!++phy->ampdu_ref) in mt7915_mac_fill_rx()
433 phy->ampdu_ref++; in mt7915_mac_fill_rx()
435 phy->rx_ampdu_ts = status->timestamp; in mt7915_mac_fill_rx()
437 status->ampdu_ref = phy->ampdu_ref; in mt7915_mac_fill_rx()
441 if ((u8 *)rxd - skb->data >= skb->len) in mt7915_mac_fill_rx()
442 return -EINVAL; in mt7915_mac_fill_rx()
445 /* RXD Group 3 - P-RXV */ in mt7915_mac_fill_rx()
452 if ((u8 *)rxd - skb->data >= skb->len) in mt7915_mac_fill_rx()
453 return -EINVAL; in mt7915_mac_fill_rx()
459 status->enc_flags |= RX_ENC_FLAG_LDPC; in mt7915_mac_fill_rx()
461 status->chains = mphy->antenna_mask; in mt7915_mac_fill_rx()
462 status->chain_signal[0] = to_rssi(MT_PRXV_RCPI0, v1); in mt7915_mac_fill_rx()
463 status->chain_signal[1] = to_rssi(MT_PRXV_RCPI1, v1); in mt7915_mac_fill_rx()
464 status->chain_signal[2] = to_rssi(MT_PRXV_RCPI2, v1); in mt7915_mac_fill_rx()
465 status->chain_signal[3] = to_rssi(MT_PRXV_RCPI3, v1); in mt7915_mac_fill_rx()
467 /* RXD Group 5 - C-RXV */ in mt7915_mac_fill_rx()
470 if ((u8 *)rxd - skb->data >= skb->len) in mt7915_mac_fill_rx()
471 return -EINVAL; in mt7915_mac_fill_rx()
474 if (!is_mt7915(&dev->mt76) || (rxd1 & MT_RXD1_NORMAL_GROUP_5)) { in mt7915_mac_fill_rx()
475 ret = mt76_connac2_mac_fill_rx_rate(&dev->mt76, status, in mt7915_mac_fill_rx()
483 status->amsdu = !!amsdu_info; in mt7915_mac_fill_rx()
484 if (status->amsdu) { in mt7915_mac_fill_rx()
485 status->first_amsdu = amsdu_info == MT_RXD4_FIRST_AMSDU_FRAME; in mt7915_mac_fill_rx()
486 status->last_amsdu = amsdu_info == MT_RXD4_LAST_AMSDU_FRAME; in mt7915_mac_fill_rx()
489 hdr_gap = (u8 *)rxd - skb->data + 2 * remove_pad; in mt7915_mac_fill_rx()
494 if (!msta || !msta->vif) in mt7915_mac_fill_rx()
495 return -EINVAL; in mt7915_mac_fill_rx()
497 vif = container_of((void *)msta->vif, struct ieee80211_vif, in mt7915_mac_fill_rx()
508 if (!hdr_trans && status->amsdu) { in mt7915_mac_fill_rx()
513 * the hardware will insert an extra 2-byte field in mt7915_mac_fill_rx()
515 * type field. This happens either when the LLC-SNAP in mt7915_mac_fill_rx()
520 if (get_unaligned_be16(skb->data + pad_start) == ETH_P_8021Q) in mt7915_mac_fill_rx()
527 memmove(skb->data + 2, skb->data, pad_start); in mt7915_mac_fill_rx()
542 fc = hdr->frame_control; in mt7915_mac_fill_rx()
544 seq_ctrl = le16_to_cpu(hdr->seq_ctrl); in mt7915_mac_fill_rx()
548 status->flag |= RX_FLAG_8023; in mt7915_mac_fill_rx()
549 mt7915_wed_check_ppe(dev, &dev->mt76.q_rx[q], msta, skb, in mt7915_mac_fill_rx()
553 if (rxv && mode >= MT_PHY_TYPE_HE_SU && !(status->flag & RX_FLAG_8023)) in mt7915_mac_fill_rx()
554 mt76_connac2_mac_decode_he_radiotap(&dev->mt76, skb, rxv, mode); in mt7915_mac_fill_rx()
556 if (!status->wcid || !ieee80211_is_data_qos(fc)) in mt7915_mac_fill_rx()
559 status->aggr = unicast && in mt7915_mac_fill_rx()
561 status->qos_ctl = qos_ctl; in mt7915_mac_fill_rx()
562 status->seqno = IEEE80211_SEQ_TO_SN(seq_ctrl); in mt7915_mac_fill_rx()
571 struct mt7915_phy *phy = &dev->phy; in mt7915_mac_fill_rx_vector()
572 __le32 *rxd = (__le32 *)skb->data; in mt7915_mac_fill_rx_vector()
582 if (band_idx && !phy->mt76->band_idx) { in mt7915_mac_fill_rx_vector()
596 phy->test.last_rcpi[i] = rcpi & 0xff; in mt7915_mac_fill_rx_vector()
597 phy->test.last_ib_rssi[i] = ib_rssi & 0xff; in mt7915_mac_fill_rx_vector()
598 phy->test.last_wb_rssi[i] = wb_rssi & 0xff; in mt7915_mac_fill_rx_vector()
607 snr = FIELD_GET(MT_CRXV_SNR, v20) - 16; in mt7915_mac_fill_rx_vector()
609 phy->test.last_freq_offset = foe; in mt7915_mac_fill_rx_vector()
610 phy->test.last_snr = snr; in mt7915_mac_fill_rx_vector()
621 struct mt76_testmode_data *td = &phy->mt76->test; in mt7915_mac_write_txwi_tm()
623 u8 bw, mode, nss = td->tx_rate_nss; in mt7915_mac_write_txwi_tm()
624 u8 rate_idx = td->tx_rate_idx; in mt7915_mac_write_txwi_tm()
630 if (skb != phy->mt76->test.tx_skb) in mt7915_mac_write_txwi_tm()
633 switch (td->tx_rate_mode) { in mt7915_mac_write_txwi_tm()
657 band = phy->mt76->chandef.chan->band; in mt7915_mac_write_txwi_tm()
661 r = &phy->mt76->hw->wiphy->bands[band]->bitrates[rate_idx]; in mt7915_mac_write_txwi_tm()
662 val = cck ? r->hw_value_short : r->hw_value; in mt7915_mac_write_txwi_tm()
672 switch (phy->mt76->chandef.width) { in mt7915_mac_write_txwi_tm()
688 if (td->tx_rate_stbc && nss == 1) { in mt7915_mac_write_txwi_tm()
695 FIELD_PREP(MT_TX_RATE_NSS, nss - 1); in mt7915_mac_write_txwi_tm()
700 if (td->tx_rate_mode < MT76_TM_TX_MODE_HT) in mt7915_mac_write_txwi_tm()
706 FIELD_PREP(MT_TXD6_SGI, td->tx_rate_sgi); in mt7915_mac_write_txwi_tm()
709 * - 1x, 2x, 4x LTF + 0.8us GI in mt7915_mac_write_txwi_tm()
710 * - 2x LTF + 1.6us GI, 4x LTF + 3.2us GI in mt7915_mac_write_txwi_tm()
712 * - 2x, 4x LTF + 0.8us GI in mt7915_mac_write_txwi_tm()
713 * - 2x LTF + 1.6us GI, 4x LTF + 3.2us GI in mt7915_mac_write_txwi_tm()
715 * - 1x, 2x LTF + 1.6us GI in mt7915_mac_write_txwi_tm()
716 * - 4x LTF + 3.2us GI in mt7915_mac_write_txwi_tm()
719 val |= FIELD_PREP(MT_TXD6_HELTF, td->tx_ltf); in mt7915_mac_write_txwi_tm()
721 if (td->tx_rate_ldpc || (bw > 0 && mode >= MT_PHY_TYPE_HE_SU)) in mt7915_mac_write_txwi_tm()
727 phy->test.spe_idx)); in mt7915_mac_write_txwi_tm()
737 u8 phy_idx = (info->hw_queue & MT_TX_HW_QUEUE_PHY) >> 2; in mt7915_mac_write_txwi()
738 struct mt76_phy *mphy = &dev->phy; in mt7915_mac_write_txwi()
740 if (phy_idx && dev->phys[MT_BAND1]) in mt7915_mac_write_txwi()
741 mphy = dev->phys[MT_BAND1]; in mt7915_mac_write_txwi()
746 mt7915_mac_write_txwi_tm(mphy->priv, txwi, skb); in mt7915_mac_write_txwi()
754 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx_info->skb->data; in mt7915_tx_prepare_skb()
756 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx_info->skb); in mt7915_tx_prepare_skb()
757 struct ieee80211_key_conf *key = info->control.hw_key; in mt7915_tx_prepare_skb()
758 struct ieee80211_vif *vif = info->control.vif; in mt7915_tx_prepare_skb()
761 int id, i, nbuf = tx_info->nbuf - 1; in mt7915_tx_prepare_skb()
765 if (unlikely(tx_info->skb->len <= ETH_HLEN)) in mt7915_tx_prepare_skb()
766 return -EINVAL; in mt7915_tx_prepare_skb()
769 wcid = &dev->mt76.global_wcid; in mt7915_tx_prepare_skb()
774 msta = (struct mt7915_sta *)sta->drv_priv; in mt7915_tx_prepare_skb()
776 if (time_after(jiffies, msta->jiffies + HZ / 4)) { in mt7915_tx_prepare_skb()
777 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS; in mt7915_tx_prepare_skb()
778 msta->jiffies = jiffies; in mt7915_tx_prepare_skb()
782 t = (struct mt76_txwi_cache *)(txwi + mdev->drv->txwi_size); in mt7915_tx_prepare_skb()
783 t->skb = tx_info->skb; in mt7915_tx_prepare_skb()
789 pid = mt76_tx_status_skb_add(mdev, wcid, tx_info->skb); in mt7915_tx_prepare_skb()
790 mt7915_mac_write_txwi(mdev, txwi_ptr, tx_info->skb, wcid, pid, key, in mt7915_tx_prepare_skb()
795 txp->buf[i] = cpu_to_le32(tx_info->buf[i + 1].addr); in mt7915_tx_prepare_skb()
796 txp->len[i] = cpu_to_le16(tx_info->buf[i + 1].len); in mt7915_tx_prepare_skb()
798 txp->nbuf = nbuf; in mt7915_tx_prepare_skb()
800 txp->flags = cpu_to_le16(MT_CT_INFO_APPLY_TXD | MT_CT_INFO_FROM_HOST); in mt7915_tx_prepare_skb()
803 txp->flags |= cpu_to_le16(MT_CT_INFO_NONE_CIPHER_FRAME); in mt7915_tx_prepare_skb()
805 if (!(info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP) && in mt7915_tx_prepare_skb()
806 ieee80211_is_mgmt(hdr->frame_control)) in mt7915_tx_prepare_skb()
807 txp->flags |= cpu_to_le16(MT_CT_INFO_MGMT_FRAME); in mt7915_tx_prepare_skb()
810 struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv; in mt7915_tx_prepare_skb()
812 txp->bss_idx = mvif->mt76.idx; in mt7915_tx_prepare_skb()
815 txp->token = cpu_to_le16(id); in mt7915_tx_prepare_skb()
816 if (test_bit(MT_WCID_FLAG_4ADDR, &wcid->flags)) in mt7915_tx_prepare_skb()
817 txp->rept_wds_wcid = cpu_to_le16(wcid->idx); in mt7915_tx_prepare_skb()
819 txp->rept_wds_wcid = cpu_to_le16(0x3ff); in mt7915_tx_prepare_skb()
820 tx_info->skb = DMA_DUMMY_DATA; in mt7915_tx_prepare_skb()
823 tx_info->buf[1].len = MT_CT_PARSE_LEN; in mt7915_tx_prepare_skb()
824 tx_info->buf[1].skip_unmap = true; in mt7915_tx_prepare_skb()
825 tx_info->nbuf = MT_CT_DMA_BUF_NUM; in mt7915_tx_prepare_skb()
850 txp->token = cpu_to_le16(token_id); in mt7915_wed_init_buf()
851 txp->nbuf = 1; in mt7915_wed_init_buf()
852 txp->buf[0] = cpu_to_le32(phys + MT_TXD_SIZE + sizeof(*txp)); in mt7915_wed_init_buf()
860 struct mt76_dev *mdev = &dev->mt76; in mt7915_mac_tx_free_prepare()
861 struct mt76_phy *mphy_ext = mdev->phys[MT_BAND1]; in mt7915_mac_tx_free_prepare()
864 mt76_queue_tx_cleanup(dev, dev->mphy.q_tx[MT_TXQ_PSD], false); in mt7915_mac_tx_free_prepare()
865 mt76_queue_tx_cleanup(dev, dev->mphy.q_tx[MT_TXQ_BE], false); in mt7915_mac_tx_free_prepare()
867 mt76_queue_tx_cleanup(dev, mphy_ext->q_tx[MT_TXQ_PSD], false); in mt7915_mac_tx_free_prepare()
868 mt76_queue_tx_cleanup(dev, mphy_ext->q_tx[MT_TXQ_BE], false); in mt7915_mac_tx_free_prepare()
881 mt76_set_tx_blocked(&dev->mt76, false); in mt7915_mac_tx_free_done()
883 mt76_worker_schedule(&dev->mt76.tx_worker); in mt7915_mac_tx_free_done()
900 struct mt76_dev *mdev = &dev->mt76; in mt7915_mac_tx_free()
913 u32 txd = le32_to_cpu(free->txd); in mt7915_mac_tx_free()
918 total = le16_get_bits(free->ctrl, MT_TX_FREE_MSDU_CNT); in mt7915_mac_tx_free()
938 wcid = rcu_dereference(dev->mt76.wcid[idx]); in mt7915_mac_tx_free()
944 spin_lock_bh(&mdev->sta_poll_lock); in mt7915_mac_tx_free()
945 if (list_empty(&msta->wcid.poll_list)) in mt7915_mac_tx_free()
946 list_add_tail(&msta->wcid.poll_list, in mt7915_mac_tx_free()
947 &mdev->sta_poll_list); in mt7915_mac_tx_free()
948 spin_unlock_bh(&mdev->sta_poll_lock); in mt7915_mac_tx_free()
952 if (!mtk_wed_device_active(&mdev->mmio.wed) && wcid) { in mt7915_mac_tx_free()
957 FIELD_GET(MT_TX_FREE_COUNT_V3, info) - 1; in mt7915_mac_tx_free()
962 FIELD_GET(MT_TX_FREE_COUNT, info) - 1; in mt7915_mac_tx_free()
966 wcid->stats.tx_retries += tx_retries; in mt7915_mac_tx_free()
967 wcid->stats.tx_failed += tx_failed; in mt7915_mac_tx_free()
1002 struct mt76_dev *mdev = &dev->mt76; in mt7915_mac_tx_free_v0()
1015 count = FIELD_GET(MT_TX_FREE_MSDU_CNT_V0, le16_to_cpu(free->ctrl)); in mt7915_mac_tx_free_v0()
1052 wcid = rcu_dereference(dev->mt76.wcid[wcidx]); in mt7915_mac_add_txs()
1059 mt76_connac2_mac_fill_txs(&dev->mt76, wcid, txs_data); in mt7915_mac_add_txs()
1061 mt76_connac2_mac_add_txs_skb(&dev->mt76, wcid, pid, txs_data); in mt7915_mac_add_txs()
1063 if (!wcid->sta) in mt7915_mac_add_txs()
1066 spin_lock_bh(&dev->mt76.sta_poll_lock); in mt7915_mac_add_txs()
1067 if (list_empty(&msta->wcid.poll_list)) in mt7915_mac_add_txs()
1068 list_add_tail(&msta->wcid.poll_list, &dev->mt76.sta_poll_list); in mt7915_mac_add_txs()
1069 spin_unlock_bh(&dev->mt76.sta_poll_lock); in mt7915_mac_add_txs()
1109 __le32 *rxd = (__le32 *)skb->data; in mt7915_queue_rx_skb()
1110 __le32 *end = (__le32 *)&skb->data[skb->len]; in mt7915_queue_rx_skb()
1117 mt7915_mac_tx_free(dev, skb->data, skb->len); in mt7915_queue_rx_skb()
1121 mt7915_mac_tx_free_v0(dev, skb->data, skb->len); in mt7915_queue_rx_skb()
1137 mt7915_debugfs_rx_fw_monitor(dev, skb->data, skb->len); in mt7915_queue_rx_skb()
1143 mt76_rx(&dev->mt76, q, skb); in mt7915_queue_rx_skb()
1155 struct mt7915_dev *dev = phy->dev; in mt7915_mac_cca_stats_reset()
1156 u32 reg = MT_WF_PHY_RX_CTRL1(phy->mt76->band_idx); in mt7915_mac_cca_stats_reset()
1164 struct mt7915_dev *dev = phy->dev; in mt7915_mac_reset_counters()
1168 mt76_rr(dev, MT_TX_AGG_CNT(phy->mt76->band_idx, i)); in mt7915_mac_reset_counters()
1169 mt76_rr(dev, MT_TX_AGG_CNT2(phy->mt76->band_idx, i)); in mt7915_mac_reset_counters()
1172 phy->mt76->survey_time = ktime_get_boottime(); in mt7915_mac_reset_counters()
1173 memset(phy->mt76->aggr_stats, 0, sizeof(phy->mt76->aggr_stats)); in mt7915_mac_reset_counters()
1176 mt76_set(dev, MT_WF_RMAC_MIB_AIRTIME0(phy->mt76->band_idx), in mt7915_mac_reset_counters()
1184 s16 coverage_class = phy->coverage_class; in mt7915_mac_set_timing()
1185 struct mt7915_dev *dev = phy->dev; in mt7915_mac_set_timing()
1192 u8 band = phy->mt76->band_idx; in mt7915_mac_set_timing()
1194 bool a_band = !(phy->mt76->chandef.chan->band == NL80211_BAND_2GHZ); in mt7915_mac_set_timing()
1196 if (!test_bit(MT76_STATE_RUNNING, &phy->mt76->state)) in mt7915_mac_set_timing()
1200 coverage_class = max_t(s16, dev->phy.coverage_class, in mt7915_mac_set_timing()
1201 ext_phy->coverage_class); in mt7915_mac_set_timing()
1211 if (!is_mt7915(&dev->mt76)) { in mt7915_mac_set_timing()
1229 FIELD_PREP(MT_IFS_SLOT, phy->slottime)); in mt7915_mac_set_timing()
1231 if (phy->slottime < 20 || a_band) in mt7915_mac_set_timing()
1245 reg = is_mt7915(&dev->mt76) ? MT_WF_PHY_RXTD12(band) : in mt7915_mac_enable_nf()
1251 reg = is_mt7915(&dev->mt76) ? MT_WF_PHY_RX_CTRL1(band) : in mt7915_mac_enable_nf()
1260 struct mt7915_dev *dev = phy->dev; in mt7915_phy_get_nf()
1264 for (nss = 0; nss < hweight8(phy->mt76->chainmask); nss++) { in mt7915_phy_get_nf()
1265 u32 reg = is_mt7915(&dev->mt76) ? in mt7915_phy_get_nf()
1266 MT_WF_IRPI_NSS(0, nss + (idx << dev->dbdc_support)) : in mt7915_phy_get_nf()
1284 struct mt7915_phy *phy = (struct mt7915_phy *)mphy->priv; in mt7915_update_channel()
1285 struct mt76_channel_state *state = mphy->chan_state; in mt7915_update_channel()
1290 nf = mt7915_phy_get_nf(phy, phy->mt76->band_idx); in mt7915_update_channel()
1291 if (!phy->noise) in mt7915_update_channel()
1292 phy->noise = nf << 4; in mt7915_update_channel()
1294 phy->noise += nf - (phy->noise >> 4); in mt7915_update_channel()
1296 state->noise = -(phy->noise >> 4); in mt7915_update_channel()
1304 ret = wait_event_timeout(dev->reset_wait, in mt7915_wait_reset_state()
1305 (READ_ONCE(dev->recovery.state) & state), in mt7915_wait_reset_state()
1317 switch (vif->type) { in mt7915_update_vif_beacon()
1321 mt7915_mcu_add_beacon(hw, vif, vif->bss_conf.enable_beacon, in mt7915_update_vif_beacon()
1332 struct mt76_phy *mphy_ext = dev->mt76.phys[MT_BAND1]; in mt7915_update_beacons()
1334 ieee80211_iterate_active_interfaces(dev->mt76.hw, in mt7915_update_beacons()
1336 mt7915_update_vif_beacon, dev->mt76.hw); in mt7915_update_beacons()
1341 ieee80211_iterate_active_interfaces(mphy_ext->hw, in mt7915_update_beacons()
1343 mt7915_update_vif_beacon, mphy_ext->hw); in mt7915_update_beacons()
1351 struct mt76_dev *mdev = &dev->mt76; in mt7915_mac_restart()
1354 ext_phy = dev->mt76.phys[MT_BAND1]; in mt7915_mac_restart()
1355 phy2 = ext_phy ? ext_phy->priv : NULL; in mt7915_mac_restart()
1357 if (dev->hif2) { in mt7915_mac_restart()
1362 if (dev_is_pci(mdev->dev)) { in mt7915_mac_restart()
1364 if (dev->hif2) { in mt7915_mac_restart()
1372 set_bit(MT76_RESET, &dev->mphy.state); in mt7915_mac_restart()
1373 set_bit(MT76_MCU_RESET, &dev->mphy.state); in mt7915_mac_restart()
1374 wake_up(&dev->mt76.mcu.wait); in mt7915_mac_restart()
1376 set_bit(MT76_RESET, &ext_phy->state); in mt7915_mac_restart()
1377 set_bit(MT76_MCU_RESET, &ext_phy->state); in mt7915_mac_restart()
1381 mt76_txq_schedule_all(&dev->mphy); in mt7915_mac_restart()
1386 mt76_worker_disable(&dev->mt76.tx_worker); in mt7915_mac_restart()
1388 if (mdev->q_rx[i].ndesc) in mt7915_mac_restart()
1389 napi_disable(&dev->mt76.napi[i]); in mt7915_mac_restart()
1391 napi_disable(&dev->mt76.tx_napi); in mt7915_mac_restart()
1394 mt76_connac2_tx_token_put(&dev->mt76); in mt7915_mac_restart()
1395 idr_init(&dev->mt76.token); in mt7915_mac_restart()
1401 if (mdev->q_rx[i].ndesc) { in mt7915_mac_restart()
1402 napi_enable(&dev->mt76.napi[i]); in mt7915_mac_restart()
1403 napi_schedule(&dev->mt76.napi[i]); in mt7915_mac_restart()
1407 clear_bit(MT76_MCU_RESET, &dev->mphy.state); in mt7915_mac_restart()
1408 clear_bit(MT76_STATE_MCU_RUNNING, &dev->mphy.state); in mt7915_mac_restart()
1410 mt76_wr(dev, MT_INT_MASK_CSR, dev->mt76.mmio.irqmask); in mt7915_mac_restart()
1413 if (dev->hif2) { in mt7915_mac_restart()
1414 mt76_wr(dev, MT_INT1_MASK_CSR, dev->mt76.mmio.irqmask); in mt7915_mac_restart()
1417 if (dev_is_pci(mdev->dev)) { in mt7915_mac_restart()
1419 if (dev->hif2) { in mt7915_mac_restart()
1438 mt7915_init_txpower(dev, &dev->mphy.sband_2g.sband); in mt7915_mac_restart()
1439 mt7915_init_txpower(dev, &dev->mphy.sband_5g.sband); in mt7915_mac_restart()
1442 if (test_bit(MT76_STATE_RUNNING, &dev->mphy.state)) { in mt7915_mac_restart()
1443 ret = mt7915_run(dev->mphy.hw); in mt7915_mac_restart()
1448 if (ext_phy && test_bit(MT76_STATE_RUNNING, &ext_phy->state)) { in mt7915_mac_restart()
1449 ret = mt7915_run(ext_phy->hw); in mt7915_mac_restart()
1456 clear_bit(MT76_RESET, &dev->mphy.state); in mt7915_mac_restart()
1458 clear_bit(MT76_RESET, &phy2->mt76->state); in mt7915_mac_restart()
1461 napi_enable(&dev->mt76.tx_napi); in mt7915_mac_restart()
1462 napi_schedule(&dev->mt76.tx_napi); in mt7915_mac_restart()
1465 mt76_worker_enable(&dev->mt76.tx_worker); in mt7915_mac_restart()
1476 ext_phy = dev->mt76.phys[MT_BAND1]; in mt7915_mac_full_reset()
1478 dev->recovery.hw_full_reset = true; in mt7915_mac_full_reset()
1480 wake_up(&dev->mt76.mcu.wait); in mt7915_mac_full_reset()
1483 ieee80211_stop_queues(ext_phy->hw); in mt7915_mac_full_reset()
1485 cancel_delayed_work_sync(&dev->mphy.mac_work); in mt7915_mac_full_reset()
1487 cancel_delayed_work_sync(&ext_phy->mac_work); in mt7915_mac_full_reset()
1489 mutex_lock(&dev->mt76.mutex); in mt7915_mac_full_reset()
1494 mutex_unlock(&dev->mt76.mutex); in mt7915_mac_full_reset()
1497 dev_err(dev->mt76.dev, "chip full reset failed\n"); in mt7915_mac_full_reset()
1501 ieee80211_restart_hw(ext_phy->hw); in mt7915_mac_full_reset()
1505 ieee80211_wake_queues(ext_phy->hw); in mt7915_mac_full_reset()
1507 dev->recovery.hw_full_reset = false; in mt7915_mac_full_reset()
1508 ieee80211_queue_delayed_work(mt76_hw(dev), &dev->mphy.mac_work, in mt7915_mac_full_reset()
1511 ieee80211_queue_delayed_work(ext_phy->hw, in mt7915_mac_full_reset()
1512 &ext_phy->mac_work, in mt7915_mac_full_reset()
1525 ext_phy = dev->mt76.phys[MT_BAND1]; in mt7915_mac_reset_work()
1526 phy2 = ext_phy ? ext_phy->priv : NULL; in mt7915_mac_reset_work()
1529 if (dev->recovery.restart) { in mt7915_mac_reset_work()
1530 /* disable WA/WM WDT */ in mt7915_mac_reset_work()
1534 if (READ_ONCE(dev->recovery.state) & MT_MCU_CMD_WA_WDT) in mt7915_mac_reset_work()
1535 dev->recovery.wa_reset_count++; in mt7915_mac_reset_work()
1537 dev->recovery.wm_reset_count++; in mt7915_mac_reset_work()
1545 /* enable WA/WM WDT */ in mt7915_mac_reset_work()
1548 dev->recovery.state = MT_MCU_CMD_NORMAL_STATE; in mt7915_mac_reset_work()
1549 dev->recovery.restart = false; in mt7915_mac_reset_work()
1554 if (!(READ_ONCE(dev->recovery.state) & MT_MCU_CMD_STOP_DMA)) in mt7915_mac_reset_work()
1557 if (mtk_wed_device_active(&dev->mt76.mmio.wed)) { in mt7915_mac_reset_work()
1558 mtk_wed_device_stop(&dev->mt76.mmio.wed); in mt7915_mac_reset_work()
1559 if (!is_mt798x(&dev->mt76)) in mt7915_mac_reset_work()
1565 ieee80211_stop_queues(ext_phy->hw); in mt7915_mac_reset_work()
1567 set_bit(MT76_RESET, &dev->mphy.state); in mt7915_mac_reset_work()
1568 set_bit(MT76_MCU_RESET, &dev->mphy.state); in mt7915_mac_reset_work()
1569 wake_up(&dev->mt76.mcu.wait); in mt7915_mac_reset_work()
1570 cancel_delayed_work_sync(&dev->mphy.mac_work); in mt7915_mac_reset_work()
1572 set_bit(MT76_RESET, &phy2->mt76->state); in mt7915_mac_reset_work()
1573 cancel_delayed_work_sync(&phy2->mt76->mac_work); in mt7915_mac_reset_work()
1575 mt76_worker_disable(&dev->mt76.tx_worker); in mt7915_mac_reset_work()
1576 mt76_for_each_q_rx(&dev->mt76, i) in mt7915_mac_reset_work()
1577 napi_disable(&dev->mt76.napi[i]); in mt7915_mac_reset_work()
1578 napi_disable(&dev->mt76.tx_napi); in mt7915_mac_reset_work()
1580 mutex_lock(&dev->mt76.mutex); in mt7915_mac_reset_work()
1587 mt76_connac2_tx_token_put(&dev->mt76); in mt7915_mac_reset_work()
1588 idr_init(&dev->mt76.token); in mt7915_mac_reset_work()
1600 clear_bit(MT76_MCU_RESET, &dev->mphy.state); in mt7915_mac_reset_work()
1601 clear_bit(MT76_RESET, &dev->mphy.state); in mt7915_mac_reset_work()
1603 clear_bit(MT76_RESET, &phy2->mt76->state); in mt7915_mac_reset_work()
1606 mt76_for_each_q_rx(&dev->mt76, i) { in mt7915_mac_reset_work()
1607 napi_enable(&dev->mt76.napi[i]); in mt7915_mac_reset_work()
1608 napi_schedule(&dev->mt76.napi[i]); in mt7915_mac_reset_work()
1612 tasklet_schedule(&dev->mt76.irq_tasklet); in mt7915_mac_reset_work()
1614 mt76_worker_enable(&dev->mt76.tx_worker); in mt7915_mac_reset_work()
1617 napi_enable(&dev->mt76.tx_napi); in mt7915_mac_reset_work()
1618 napi_schedule(&dev->mt76.tx_napi); in mt7915_mac_reset_work()
1623 ieee80211_wake_queues(ext_phy->hw); in mt7915_mac_reset_work()
1625 mutex_unlock(&dev->mt76.mutex); in mt7915_mac_reset_work()
1629 ieee80211_queue_delayed_work(mt76_hw(dev), &dev->mphy.mac_work, in mt7915_mac_reset_work()
1632 ieee80211_queue_delayed_work(ext_phy->hw, in mt7915_mac_reset_work()
1633 &phy2->mt76->mac_work, in mt7915_mac_reset_work()
1651 mutex_lock(&dev->dump_mutex); in mt7915_mac_dump_work()
1655 mutex_unlock(&dev->dump_mutex); in mt7915_mac_dump_work()
1660 if (!mem_region || !crash_data->memdump_buf_len) { in mt7915_mac_dump_work()
1661 mutex_unlock(&dev->dump_mutex); in mt7915_mac_dump_work()
1665 buf = crash_data->memdump_buf; in mt7915_mac_dump_work()
1666 buf_len = crash_data->memdump_buf_len; in mt7915_mac_dump_work()
1671 if (mem_region->len > buf_len) { in mt7915_mac_dump_work()
1672 dev_warn(dev->mt76.dev, "%s len %lu is too large\n", in mt7915_mac_dump_work()
1673 mem_region->name, in mt7915_mac_dump_work()
1674 (unsigned long)mem_region->len); in mt7915_mac_dump_work()
1681 buf_len -= sizeof(*hdr); in mt7915_mac_dump_work()
1683 mt7915_memcpy_fromio(dev, buf, mem_region->start, in mt7915_mac_dump_work()
1684 mem_region->len); in mt7915_mac_dump_work()
1686 hdr->start = mem_region->start; in mt7915_mac_dump_work()
1687 hdr->len = mem_region->len; in mt7915_mac_dump_work()
1689 if (!mem_region->len) in mt7915_mac_dump_work()
1693 buf += mem_region->len; in mt7915_mac_dump_work()
1694 buf_len -= mem_region->len; in mt7915_mac_dump_work()
1699 mutex_unlock(&dev->dump_mutex); in mt7915_mac_dump_work()
1704 queue_work(dev->mt76.wq, &dev->reset_work); in mt7915_mac_dump_work()
1709 if (!dev->recovery.hw_init_done) in mt7915_reset()
1712 if (dev->recovery.hw_full_reset) in mt7915_reset()
1716 if (READ_ONCE(dev->recovery.state) & MT_MCU_CMD_WDT_MASK) { in mt7915_reset()
1717 dev->recovery.restart = true; in mt7915_reset()
1718 dev_info(dev->mt76.dev, in mt7915_reset()
1720 wiphy_name(dev->mt76.hw->wiphy)); in mt7915_reset()
1723 queue_work(dev->mt76.wq, &dev->dump_work); in mt7915_reset()
1727 queue_work(dev->mt76.wq, &dev->reset_work); in mt7915_reset()
1728 wake_up(&dev->reset_wait); in mt7915_reset()
1733 struct mt76_mib_stats *mib = &phy->mib; in mt7915_mac_update_stats()
1734 struct mt7915_dev *dev = phy->dev; in mt7915_mac_update_stats()
1736 u8 band = phy->mt76->band_idx; in mt7915_mac_update_stats()
1740 mib->fcs_err_cnt += is_mt7915(&dev->mt76) ? in mt7915_mac_update_stats()
1745 mib->rx_fifo_full_cnt += FIELD_GET(MT_MIB_SDR4_RX_FIFO_FULL_MASK, cnt); in mt7915_mac_update_stats()
1748 mib->rx_mpdu_cnt += cnt; in mt7915_mac_update_stats()
1751 mib->channel_idle_cnt += FIELD_GET(MT_MIB_SDR6_CHANNEL_IDL_CNT_MASK, cnt); in mt7915_mac_update_stats()
1754 mib->rx_vector_mismatch_cnt += in mt7915_mac_update_stats()
1758 mib->rx_delimiter_fail_cnt += in mt7915_mac_update_stats()
1762 mib->rx_mrdy_cnt += is_mt7915(&dev->mt76) ? in mt7915_mac_update_stats()
1767 mib->rx_len_mismatch_cnt += in mt7915_mac_update_stats()
1771 mib->tx_ampdu_cnt += cnt; in mt7915_mac_update_stats()
1774 mib->tx_stop_q_empty_cnt += in mt7915_mac_update_stats()
1778 mib->tx_mpdu_attempts_cnt += is_mt7915(&dev->mt76) ? in mt7915_mac_update_stats()
1783 mib->tx_mpdu_success_cnt += is_mt7915(&dev->mt76) ? in mt7915_mac_update_stats()
1788 mib->primary_cca_busy_time += in mt7915_mac_update_stats()
1792 mib->secondary_cca_busy_time += in mt7915_mac_update_stats()
1796 mib->primary_energy_detect_time += in mt7915_mac_update_stats()
1800 mib->cck_mdrdy_time += FIELD_GET(MT_MIB_SDR19_CCK_MDRDY_TIME_MASK, cnt); in mt7915_mac_update_stats()
1803 mib->ofdm_mdrdy_time += in mt7915_mac_update_stats()
1807 mib->green_mdrdy_time += in mt7915_mac_update_stats()
1811 mib->rx_ampdu_cnt += cnt; in mt7915_mac_update_stats()
1814 mib->rx_ampdu_bytes_cnt += cnt; in mt7915_mac_update_stats()
1817 mib->rx_ampdu_valid_subframe_cnt += is_mt7915(&dev->mt76) ? in mt7915_mac_update_stats()
1822 mib->rx_ampdu_valid_subframe_bytes_cnt += cnt; in mt7915_mac_update_stats()
1825 mib->tx_rwp_fail_cnt += in mt7915_mac_update_stats()
1829 mib->tx_rwp_need_cnt += in mt7915_mac_update_stats()
1833 mib->rx_pfdrop_cnt += is_mt7915(&dev->mt76) ? in mt7915_mac_update_stats()
1838 mib->rx_vec_queue_overflow_drop_cnt += is_mt7915(&dev->mt76) ? in mt7915_mac_update_stats()
1843 mib->rx_ba_cnt += cnt; in mt7915_mac_update_stats()
1846 mib->tx_bf_cnt += FIELD_GET(MT_MIB_MU_BF_TX_CNT, cnt); in mt7915_mac_update_stats()
1849 mib->tx_mu_mpdu_cnt += cnt; in mt7915_mac_update_stats()
1852 mib->tx_mu_acked_mpdu_cnt += cnt; in mt7915_mac_update_stats()
1855 mib->tx_su_acked_mpdu_cnt += cnt; in mt7915_mac_update_stats()
1858 mib->tx_bf_rx_fb_bw = FIELD_GET(MT_ETBF_PAR_RPT0_FB_BW, cnt); in mt7915_mac_update_stats()
1859 mib->tx_bf_rx_fb_nc_cnt += FIELD_GET(MT_ETBF_PAR_RPT0_FB_NC, cnt); in mt7915_mac_update_stats()
1860 mib->tx_bf_rx_fb_nr_cnt += FIELD_GET(MT_ETBF_PAR_RPT0_FB_NR, cnt); in mt7915_mac_update_stats()
1862 for (i = 0; i < ARRAY_SIZE(mib->tx_amsdu); i++) { in mt7915_mac_update_stats()
1864 mib->tx_amsdu[i] += cnt; in mt7915_mac_update_stats()
1865 mib->tx_amsdu_cnt += cnt; in mt7915_mac_update_stats()
1868 if (is_mt7915(&dev->mt76)) { in mt7915_mac_update_stats()
1871 mib->ba_miss_cnt += in mt7915_mac_update_stats()
1873 mib->ack_fail_cnt += in mt7915_mac_update_stats()
1877 mib->rts_cnt += FIELD_GET(MT_MIB_RTS_COUNT_MASK, val); in mt7915_mac_update_stats()
1878 mib->rts_retries_cnt += in mt7915_mac_update_stats()
1882 phy->mt76->aggr_stats[aggr0++] += val & 0xffff; in mt7915_mac_update_stats()
1883 phy->mt76->aggr_stats[aggr0++] += val >> 16; in mt7915_mac_update_stats()
1886 phy->mt76->aggr_stats[aggr1++] += val & 0xffff; in mt7915_mac_update_stats()
1887 phy->mt76->aggr_stats[aggr1++] += val >> 16; in mt7915_mac_update_stats()
1891 mib->tx_pkt_ebf_cnt += FIELD_GET(MT_MIB_SDR32_TX_PKT_EBF_CNT, cnt); in mt7915_mac_update_stats()
1894 mib->tx_pkt_ibf_cnt += FIELD_GET(MT_MIB_SDR33_TX_PKT_IBF_CNT, cnt); in mt7915_mac_update_stats()
1897 mib->tx_bf_ibf_ppdu_cnt += FIELD_GET(MT_ETBF_TX_IBF_CNT, cnt); in mt7915_mac_update_stats()
1898 mib->tx_bf_ebf_ppdu_cnt += FIELD_GET(MT_ETBF_TX_EBF_CNT, cnt); in mt7915_mac_update_stats()
1901 mib->tx_bf_fb_cpl_cnt += FIELD_GET(MT_ETBF_TX_FB_CPL, cnt); in mt7915_mac_update_stats()
1902 mib->tx_bf_fb_trig_cnt += FIELD_GET(MT_ETBF_TX_FB_TRI, cnt); in mt7915_mac_update_stats()
1905 mib->tx_bf_rx_fb_all_cnt += FIELD_GET(MT_ETBF_RX_FB_ALL, cnt); in mt7915_mac_update_stats()
1906 mib->tx_bf_rx_fb_he_cnt += FIELD_GET(MT_ETBF_RX_FB_HE, cnt); in mt7915_mac_update_stats()
1907 mib->tx_bf_rx_fb_vht_cnt += FIELD_GET(MT_ETBF_RX_FB_VHT, cnt); in mt7915_mac_update_stats()
1908 mib->tx_bf_rx_fb_ht_cnt += FIELD_GET(MT_ETBF_RX_FB_HT, cnt); in mt7915_mac_update_stats()
1913 mib->rts_cnt += FIELD_GET(GENMASK(15, 0), val); in mt7915_mac_update_stats()
1914 mib->rts_cnt += FIELD_GET(GENMASK(31, 16), val); in mt7915_mac_update_stats()
1918 mib->rts_retries_cnt += FIELD_GET(GENMASK(15, 0), val); in mt7915_mac_update_stats()
1919 mib->rts_retries_cnt += FIELD_GET(GENMASK(31, 16), val); in mt7915_mac_update_stats()
1923 mib->ba_miss_cnt += FIELD_GET(GENMASK(15, 0), val); in mt7915_mac_update_stats()
1924 mib->ba_miss_cnt += FIELD_GET(GENMASK(31, 16), val); in mt7915_mac_update_stats()
1928 mib->ack_fail_cnt += FIELD_GET(GENMASK(15, 0), val); in mt7915_mac_update_stats()
1929 mib->ack_fail_cnt += FIELD_GET(GENMASK(31, 16), val); in mt7915_mac_update_stats()
1934 phy->mt76->aggr_stats[aggr0++] += FIELD_GET(GENMASK(15, 0), val); in mt7915_mac_update_stats()
1935 phy->mt76->aggr_stats[aggr0++] += FIELD_GET(GENMASK(31, 16), val); in mt7915_mac_update_stats()
1939 mib->tx_pkt_ibf_cnt += FIELD_GET(MT_MIB_SDR32_TX_PKT_IBF_CNT, cnt); in mt7915_mac_update_stats()
1940 mib->tx_bf_ibf_ppdu_cnt += FIELD_GET(MT_MIB_SDR32_TX_PKT_IBF_CNT, cnt); in mt7915_mac_update_stats()
1941 mib->tx_pkt_ebf_cnt += FIELD_GET(MT_MIB_SDR32_TX_PKT_EBF_CNT, cnt); in mt7915_mac_update_stats()
1942 mib->tx_bf_ebf_ppdu_cnt += FIELD_GET(MT_MIB_SDR32_TX_PKT_EBF_CNT, cnt); in mt7915_mac_update_stats()
1945 mib->tx_bf_fb_cpl_cnt += FIELD_GET(MT_MIB_BFCR7_BFEE_TX_FB_CPL, cnt); in mt7915_mac_update_stats()
1948 mib->tx_bf_fb_trig_cnt += FIELD_GET(MT_MIB_BFCR2_BFEE_TX_FB_TRIG, cnt); in mt7915_mac_update_stats()
1951 mib->tx_bf_rx_fb_vht_cnt += FIELD_GET(MT_MIB_BFCR0_RX_FB_VHT, cnt); in mt7915_mac_update_stats()
1952 mib->tx_bf_rx_fb_all_cnt += FIELD_GET(MT_MIB_BFCR0_RX_FB_VHT, cnt); in mt7915_mac_update_stats()
1953 mib->tx_bf_rx_fb_ht_cnt += FIELD_GET(MT_MIB_BFCR0_RX_FB_HT, cnt); in mt7915_mac_update_stats()
1954 mib->tx_bf_rx_fb_all_cnt += FIELD_GET(MT_MIB_BFCR0_RX_FB_HT, cnt); in mt7915_mac_update_stats()
1957 mib->tx_bf_rx_fb_he_cnt += FIELD_GET(MT_MIB_BFCR1_RX_FB_HE, cnt); in mt7915_mac_update_stats()
1958 mib->tx_bf_rx_fb_all_cnt += FIELD_GET(MT_MIB_BFCR1_RX_FB_HE, cnt); in mt7915_mac_update_stats()
1964 struct mt7915_dev *dev = phy->dev; in mt7915_mac_severe_check()
1967 if (!phy->omac_mask) in mt7915_mac_severe_check()
1974 trb = mt76_rr(dev, MT_TRB_RXPSR0(phy->mt76->band_idx)); in mt7915_mac_severe_check()
1978 (FIELD_GET(MT_TRB_RXPSR0_RX_RMAC_PTR, phy->trb_ts) != in mt7915_mac_severe_check()
1979 FIELD_GET(MT_TRB_RXPSR0_RX_WTBL_PTR, phy->trb_ts)) && in mt7915_mac_severe_check()
1980 trb == phy->trb_ts) in mt7915_mac_severe_check()
1982 phy->mt76->band_idx); in mt7915_mac_severe_check()
1984 phy->trb_ts = trb; in mt7915_mac_severe_check()
2000 spin_lock_bh(&dev->mt76.sta_poll_lock); in mt7915_mac_sta_rc_work()
2001 list_splice_init(&dev->sta_rc_list, &list); in mt7915_mac_sta_rc_work()
2005 list_del_init(&msta->rc_list); in mt7915_mac_sta_rc_work()
2006 changed = msta->changed; in mt7915_mac_sta_rc_work()
2007 msta->changed = 0; in mt7915_mac_sta_rc_work()
2008 spin_unlock_bh(&dev->mt76.sta_poll_lock); in mt7915_mac_sta_rc_work()
2011 vif = container_of((void *)msta->vif, struct ieee80211_vif, drv_priv); in mt7915_mac_sta_rc_work()
2021 spin_lock_bh(&dev->mt76.sta_poll_lock); in mt7915_mac_sta_rc_work()
2024 spin_unlock_bh(&dev->mt76.sta_poll_lock); in mt7915_mac_sta_rc_work()
2034 phy = mphy->priv; in mt7915_mac_work()
2036 mutex_lock(&mphy->dev->mutex); in mt7915_mac_work()
2039 if (++mphy->mac_work_count == 5) { in mt7915_mac_work()
2040 mphy->mac_work_count = 0; in mt7915_mac_work()
2045 if (phy->dev->muru_debug) in mt7915_mac_work()
2049 mutex_unlock(&mphy->dev->mutex); in mt7915_mac_work()
2051 mt76_tx_status_check(mphy->dev, false); in mt7915_mac_work()
2053 ieee80211_queue_delayed_work(mphy->hw, &mphy->mac_work, in mt7915_mac_work()
2059 struct mt7915_dev *dev = phy->dev; in mt7915_dfs_stop_radar_detector()
2061 if (phy->rdd_state & BIT(0)) in mt7915_dfs_stop_radar_detector()
2062 mt76_connac_mcu_rdd_cmd(&dev->mt76, RDD_STOP, 0, in mt7915_dfs_stop_radar_detector()
2064 if (phy->rdd_state & BIT(1)) in mt7915_dfs_stop_radar_detector()
2065 mt76_connac_mcu_rdd_cmd(&dev->mt76, RDD_STOP, 1, in mt7915_dfs_stop_radar_detector()
2073 switch (dev->mt76.region) { in mt7915_dfs_start_rdd()
2086 err = mt76_connac_mcu_rdd_cmd(&dev->mt76, RDD_START, chain, in mt7915_dfs_start_rdd()
2091 if (is_mt7915(&dev->mt76)) { in mt7915_dfs_start_rdd()
2092 err = mt76_connac_mcu_rdd_cmd(&dev->mt76, RDD_SET_WF_ANT, chain, in mt7915_dfs_start_rdd()
2093 0, dev->dbdc_support ? 2 : 0); in mt7915_dfs_start_rdd()
2098 return mt76_connac_mcu_rdd_cmd(&dev->mt76, RDD_DET_MODE, chain, in mt7915_dfs_start_rdd()
2104 struct cfg80211_chan_def *chandef = &phy->mt76->chandef; in mt7915_dfs_start_radar_detector()
2105 struct mt7915_dev *dev = phy->dev; in mt7915_dfs_start_radar_detector()
2109 err = mt76_connac_mcu_rdd_cmd(&dev->mt76, RDD_CAC_START, in mt7915_dfs_start_radar_detector()
2110 phy->mt76->band_idx, MT_RX_SEL0, 0); in mt7915_dfs_start_radar_detector()
2114 err = mt7915_dfs_start_rdd(dev, phy->mt76->band_idx); in mt7915_dfs_start_radar_detector()
2118 phy->rdd_state |= BIT(phy->mt76->band_idx); in mt7915_dfs_start_radar_detector()
2120 if (!is_mt7915(&dev->mt76)) in mt7915_dfs_start_radar_detector()
2123 if (chandef->width == NL80211_CHAN_WIDTH_160 || in mt7915_dfs_start_radar_detector()
2124 chandef->width == NL80211_CHAN_WIDTH_80P80) { in mt7915_dfs_start_radar_detector()
2129 phy->rdd_state |= BIT(1); in mt7915_dfs_start_radar_detector()
2139 struct mt7915_dev *dev = phy->dev; in mt7915_dfs_init_radar_specs()
2142 switch (dev->mt76.region) { in mt7915_dfs_init_radar_specs()
2156 return -EINVAL; in mt7915_dfs_init_radar_specs()
2159 for (i = 0; i < ARRAY_SIZE(radar_specs->radar_pattern); i++) { in mt7915_dfs_init_radar_specs()
2161 &radar_specs->radar_pattern[i]); in mt7915_dfs_init_radar_specs()
2166 return mt7915_mcu_set_pulse_th(dev, &radar_specs->pulse_th); in mt7915_dfs_init_radar_specs()
2171 struct mt7915_dev *dev = phy->dev; in mt7915_dfs_init_radar_detector()
2175 prev_state = phy->mt76->dfs_state; in mt7915_dfs_init_radar_detector()
2176 dfs_state = mt76_phy_dfs_state(phy->mt76); in mt7915_dfs_init_radar_detector()
2196 phy->mt76->dfs_state = MT_DFS_STATE_CAC; in mt7915_dfs_init_radar_detector()
2202 err = mt76_connac_mcu_rdd_cmd(&dev->mt76, RDD_CAC_END, in mt7915_dfs_init_radar_detector()
2203 phy->mt76->band_idx, MT_RX_SEL0, 0); in mt7915_dfs_init_radar_detector()
2205 phy->mt76->dfs_state = MT_DFS_STATE_UNKNOWN; in mt7915_dfs_init_radar_detector()
2209 phy->mt76->dfs_state = MT_DFS_STATE_ACTIVE; in mt7915_dfs_init_radar_detector()
2213 err = mt76_connac_mcu_rdd_cmd(&dev->mt76, RDD_NORMAL_START, in mt7915_dfs_init_radar_detector()
2214 phy->mt76->band_idx, MT_RX_SEL0, 0); in mt7915_dfs_init_radar_detector()
2218 if (is_mt7915(&dev->mt76)) { in mt7915_dfs_init_radar_detector()
2219 err = mt76_connac_mcu_rdd_cmd(&dev->mt76, RDD_SET_WF_ANT, in mt7915_dfs_init_radar_detector()
2220 phy->mt76->band_idx, 0, in mt7915_dfs_init_radar_detector()
2221 dev->dbdc_support ? 2 : 0); in mt7915_dfs_init_radar_detector()
2227 phy->mt76->dfs_state = MT_DFS_STATE_DISABLED; in mt7915_dfs_init_radar_detector()
2243 u32 duration = flow->duration << 8; in mt7915_mac_twt_sched_list_add()
2246 iter = list_first_entry_or_null(&dev->twt_list, in mt7915_mac_twt_sched_list_add()
2248 if (!iter || !iter->sched || iter->start_tsf > duration) { in mt7915_mac_twt_sched_list_add()
2250 list_add(&flow->list, &dev->twt_list); in mt7915_mac_twt_sched_list_add()
2254 list_for_each_entry_safe(iter, iter_next, &dev->twt_list, list) { in mt7915_mac_twt_sched_list_add()
2255 start_tsf = iter->start_tsf + in mt7915_mac_twt_sched_list_add()
2256 mt7915_mac_twt_duration_align(iter->duration); in mt7915_mac_twt_sched_list_add()
2257 if (list_is_last(&iter->list, &dev->twt_list)) in mt7915_mac_twt_sched_list_add()
2260 if (!iter_next->sched || in mt7915_mac_twt_sched_list_add()
2261 iter_next->start_tsf > start_tsf + duration) { in mt7915_mac_twt_sched_list_add()
2262 list_add(&flow->list, &iter->list); in mt7915_mac_twt_sched_list_add()
2268 list_add_tail(&flow->list, &dev->twt_list); in mt7915_mac_twt_sched_list_add()
2276 u64 interval, duration; in mt7915_mac_check_twt_req() local
2281 if (twt->control & IEEE80211_TWT_CONTROL_NEG_TYPE_BROADCAST) in mt7915_mac_check_twt_req()
2282 return -EOPNOTSUPP; in mt7915_mac_check_twt_req()
2285 if (twt->control & IEEE80211_TWT_CONTROL_WAKE_DUR_UNIT) in mt7915_mac_check_twt_req()
2286 return -EOPNOTSUPP; in mt7915_mac_check_twt_req()
2288 twt_agrt = (struct ieee80211_twt_params *)twt->params; in mt7915_mac_check_twt_req()
2291 if (!(twt_agrt->req_type & cpu_to_le16(IEEE80211_TWT_REQTYPE_IMPLICIT))) in mt7915_mac_check_twt_req()
2292 return -EOPNOTSUPP; in mt7915_mac_check_twt_req()
2295 le16_to_cpu(twt_agrt->req_type)); in mt7915_mac_check_twt_req()
2296 mantissa = le16_to_cpu(twt_agrt->mantissa); in mt7915_mac_check_twt_req()
2297 duration = twt_agrt->min_twt_dur << 8; in mt7915_mac_check_twt_req()
2299 interval = (u64)mantissa << exp; in mt7915_mac_check_twt_req()
2300 if (interval < duration) in mt7915_mac_check_twt_req()
2301 return -EOPNOTSUPP; in mt7915_mac_check_twt_req()
2310 u16 type = le16_to_cpu(twt_agrt->req_type); in mt7915_mac_twt_param_equal()
2318 if (!(msta->twt.flowid_mask & BIT(i))) in mt7915_mac_twt_param_equal()
2321 f = &msta->twt.flow[i]; in mt7915_mac_twt_param_equal()
2322 if (f->duration == twt_agrt->min_twt_dur && in mt7915_mac_twt_param_equal()
2323 f->mantissa == twt_agrt->mantissa && in mt7915_mac_twt_param_equal()
2324 f->exp == exp && in mt7915_mac_twt_param_equal()
2325 f->protection == !!(type & IEEE80211_TWT_REQTYPE_PROTECTION) && in mt7915_mac_twt_param_equal()
2326 f->flowtype == !!(type & IEEE80211_TWT_REQTYPE_FLOWTYPE) && in mt7915_mac_twt_param_equal()
2327 f->trigger == !!(type & IEEE80211_TWT_REQTYPE_TRIGGER)) in mt7915_mac_twt_param_equal()
2339 struct mt7915_sta *msta = (struct mt7915_sta *)sta->drv_priv; in mt7915_mac_add_twt_setup()
2340 struct ieee80211_twt_params *twt_agrt = (void *)twt->params; in mt7915_mac_add_twt_setup()
2341 u16 req_type = le16_to_cpu(twt_agrt->req_type); in mt7915_mac_add_twt_setup()
2351 mutex_lock(&dev->mt76.mutex); in mt7915_mac_add_twt_setup()
2353 if (dev->twt.n_agrt == MT7915_MAX_TWT_AGRT) in mt7915_mac_add_twt_setup()
2356 if (hweight8(msta->twt.flowid_mask) == ARRAY_SIZE(msta->twt.flow)) in mt7915_mac_add_twt_setup()
2359 if (twt_agrt->min_twt_dur < MT7915_MIN_TWT_DUR) { in mt7915_mac_add_twt_setup()
2361 twt_agrt->min_twt_dur = MT7915_MIN_TWT_DUR; in mt7915_mac_add_twt_setup()
2365 flowid = ffs(~msta->twt.flowid_mask) - 1; in mt7915_mac_add_twt_setup()
2366 twt_agrt->req_type &= ~cpu_to_le16(IEEE80211_TWT_REQTYPE_FLOWID); in mt7915_mac_add_twt_setup()
2367 twt_agrt->req_type |= le16_encode_bits(flowid, in mt7915_mac_add_twt_setup()
2370 table_id = ffs(~dev->twt.table_mask) - 1; in mt7915_mac_add_twt_setup()
2377 flow = &msta->twt.flow[flowid]; in mt7915_mac_add_twt_setup()
2379 INIT_LIST_HEAD(&flow->list); in mt7915_mac_add_twt_setup()
2380 flow->wcid = msta->wcid.idx; in mt7915_mac_add_twt_setup()
2381 flow->table_id = table_id; in mt7915_mac_add_twt_setup()
2382 flow->id = flowid; in mt7915_mac_add_twt_setup()
2383 flow->duration = twt_agrt->min_twt_dur; in mt7915_mac_add_twt_setup()
2384 flow->mantissa = twt_agrt->mantissa; in mt7915_mac_add_twt_setup()
2385 flow->exp = exp; in mt7915_mac_add_twt_setup()
2386 flow->protection = !!(req_type & IEEE80211_TWT_REQTYPE_PROTECTION); in mt7915_mac_add_twt_setup()
2387 flow->flowtype = !!(req_type & IEEE80211_TWT_REQTYPE_FLOWTYPE); in mt7915_mac_add_twt_setup()
2388 flow->trigger = !!(req_type & IEEE80211_TWT_REQTYPE_TRIGGER); in mt7915_mac_add_twt_setup()
2392 u64 interval = (u64)le16_to_cpu(twt_agrt->mantissa) << exp; in mt7915_mac_add_twt_setup() local
2396 flow->sched = true; in mt7915_mac_add_twt_setup()
2397 flow->start_tsf = mt7915_mac_twt_sched_list_add(dev, flow); in mt7915_mac_add_twt_setup()
2398 curr_tsf = __mt7915_get_tsf(hw, msta->vif); in mt7915_mac_add_twt_setup()
2399 div_u64_rem(curr_tsf - flow->start_tsf, interval, &rem); in mt7915_mac_add_twt_setup()
2400 flow_tsf = curr_tsf + interval - rem; in mt7915_mac_add_twt_setup()
2401 twt_agrt->twt = cpu_to_le64(flow_tsf); in mt7915_mac_add_twt_setup()
2403 list_add_tail(&flow->list, &dev->twt_list); in mt7915_mac_add_twt_setup()
2405 flow->tsf = le64_to_cpu(twt_agrt->twt); in mt7915_mac_add_twt_setup()
2407 if (mt7915_mcu_twt_agrt_update(dev, msta->vif, flow, MCU_TWT_AGRT_ADD)) in mt7915_mac_add_twt_setup()
2411 dev->twt.table_mask |= BIT(table_id); in mt7915_mac_add_twt_setup()
2412 msta->twt.flowid_mask |= BIT(flowid); in mt7915_mac_add_twt_setup()
2413 dev->twt.n_agrt++; in mt7915_mac_add_twt_setup()
2416 mutex_unlock(&dev->mt76.mutex); in mt7915_mac_add_twt_setup()
2418 twt_agrt->req_type &= ~cpu_to_le16(IEEE80211_TWT_REQTYPE_SETUP_CMD); in mt7915_mac_add_twt_setup()
2419 twt_agrt->req_type |= in mt7915_mac_add_twt_setup()
2421 twt->control = (twt->control & IEEE80211_TWT_CONTROL_WAKE_DUR_UNIT) | in mt7915_mac_add_twt_setup()
2422 (twt->control & IEEE80211_TWT_CONTROL_RX_DISABLED); in mt7915_mac_add_twt_setup()
2431 lockdep_assert_held(&dev->mt76.mutex); in mt7915_mac_twt_teardown_flow()
2433 if (flowid >= ARRAY_SIZE(msta->twt.flow)) in mt7915_mac_twt_teardown_flow()
2436 if (!(msta->twt.flowid_mask & BIT(flowid))) in mt7915_mac_twt_teardown_flow()
2439 flow = &msta->twt.flow[flowid]; in mt7915_mac_twt_teardown_flow()
2440 if (mt7915_mcu_twt_agrt_update(dev, msta->vif, flow, in mt7915_mac_twt_teardown_flow()
2444 list_del_init(&flow->list); in mt7915_mac_twt_teardown_flow()
2445 msta->twt.flowid_mask &= ~BIT(flowid); in mt7915_mac_twt_teardown_flow()
2446 dev->twt.table_mask &= ~BIT(flow->table_id); in mt7915_mac_twt_teardown_flow()
2447 dev->twt.n_agrt--; in mt7915_mac_twt_teardown_flow()