Lines Matching +full:phy +full:- +full:reset +full:- +full:duration
1 // SPDX-License-Identifier: ISC
12 #define to_rssi(field, rcpi) ((FIELD_GET(field, rcpi) - 220) / 2)
15 .pulse_th = { 110, -10, -80, 40, 5200, 128, 5200 },
29 .pulse_th = { 110, -10, -80, 40, 5200, 128, 5200 },
40 .pulse_th = { 110, -10, -80, 40, 5200, 128, 5200 },
59 if (idx >= ARRAY_SIZE(dev->mt76.wcid)) in mt7915_rx_get_wcid()
62 wcid = rcu_dereference(dev->mt76.wcid[idx]); in mt7915_rx_get_wcid()
66 if (!wcid->sta) in mt7915_rx_get_wcid()
70 if (!sta->vif) in mt7915_rx_get_wcid()
73 return &sta->vif->sta.wcid; in mt7915_rx_get_wcid()
108 spin_lock_bh(&dev->mt76.sta_poll_lock); in mt7915_mac_sta_poll()
109 list_splice_init(&dev->mt76.sta_poll_list, &sta_poll_list); in mt7915_mac_sta_poll()
110 spin_unlock_bh(&dev->mt76.sta_poll_lock); in mt7915_mac_sta_poll()
121 spin_lock_bh(&dev->mt76.sta_poll_lock); in mt7915_mac_sta_poll()
123 spin_unlock_bh(&dev->mt76.sta_poll_lock); in mt7915_mac_sta_poll()
128 list_del_init(&msta->wcid.poll_list); in mt7915_mac_sta_poll()
129 spin_unlock_bh(&dev->mt76.sta_poll_lock); in mt7915_mac_sta_poll()
131 idx = msta->wcid.idx; in mt7915_mac_sta_poll()
137 u32 tx_last = msta->airtime_ac[i]; in mt7915_mac_sta_poll()
138 u32 rx_last = msta->airtime_ac[i + 4]; in mt7915_mac_sta_poll()
140 msta->airtime_ac[i] = mt76_rr(dev, addr); in mt7915_mac_sta_poll()
141 msta->airtime_ac[i + 4] = mt76_rr(dev, addr + 4); in mt7915_mac_sta_poll()
143 if (msta->airtime_ac[i] <= tx_last) in mt7915_mac_sta_poll()
146 tx_time[i] = msta->airtime_ac[i] - tx_last; in mt7915_mac_sta_poll()
148 if (msta->airtime_ac[i + 4] <= rx_last) in mt7915_mac_sta_poll()
151 rx_time[i] = msta->airtime_ac[i + 4] - rx_last; in mt7915_mac_sta_poll()
162 memset(msta->airtime_ac, 0, sizeof(msta->airtime_ac)); in mt7915_mac_sta_poll()
165 if (!msta->wcid.sta) in mt7915_mac_sta_poll()
187 * from per-sta counters directly. in mt7915_mac_sta_poll()
189 rate = &msta->wcid.rate; in mt7915_mac_sta_poll()
193 switch (rate->bw) { in mt7915_mac_sta_poll()
208 if (rate->flags & RATE_INFO_FLAGS_HE_MCS) { in mt7915_mac_sta_poll()
211 rate->he_gi = (val & (0x3 << offs)) >> offs; in mt7915_mac_sta_poll()
212 } else if (rate->flags & in mt7915_mac_sta_poll()
215 rate->flags |= RATE_INFO_FLAGS_SHORT_GI; in mt7915_mac_sta_poll()
217 rate->flags &= ~RATE_INFO_FLAGS_SHORT_GI; in mt7915_mac_sta_poll()
229 msta->ack_signal = in mt7915_mac_sta_poll()
230 mt76_rx_signal(msta->vif->phy->mt76->antenna_mask, rssi); in mt7915_mac_sta_poll()
232 ewma_avg_signal_add(&msta->avg_ack_signal, -msta->ack_signal); in mt7915_mac_sta_poll()
241 struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv; in mt7915_mac_enable_rtscts()
244 addr = mt7915_mac_wtbl_lmac_addr(dev, mvif->sta.wcid.idx, 5); in mt7915_mac_enable_rtscts()
259 if (!msta || !msta->vif) in mt7915_wed_check_ppe()
268 vif = container_of((void *)msta->vif, struct ieee80211_vif, in mt7915_wed_check_ppe()
271 skb->dev = wdev->netdev; in mt7915_wed_check_ppe()
273 mtk_wed_device_ppe_check(&dev->mt76.mmio.wed, skb, in mt7915_wed_check_ppe()
282 struct mt76_rx_status *status = (struct mt76_rx_status *)skb->cb; in mt7915_mac_fill_rx()
283 struct mt76_phy *mphy = &dev->mt76.phy; in mt7915_mac_fill_rx()
284 struct mt7915_phy *phy = &dev->phy; in mt7915_mac_fill_rx() local
286 __le32 *rxd = (__le32 *)skb->data; in mt7915_mac_fill_rx()
298 u32 csum_status = *(u32 *)skb->cb; in mt7915_mac_fill_rx()
307 if ((rxd1 & MT_RXD1_NORMAL_BAND_IDX) && !phy->mt76->band_idx) { in mt7915_mac_fill_rx()
308 mphy = dev->mt76.phys[MT_BAND1]; in mt7915_mac_fill_rx()
310 return -EINVAL; in mt7915_mac_fill_rx()
312 phy = mphy->priv; in mt7915_mac_fill_rx()
313 status->phy_idx = 1; in mt7915_mac_fill_rx()
316 if (!test_bit(MT76_STATE_RUNNING, &mphy->state)) in mt7915_mac_fill_rx()
317 return -EINVAL; in mt7915_mac_fill_rx()
320 return -EINVAL; in mt7915_mac_fill_rx()
324 return -EINVAL; in mt7915_mac_fill_rx()
328 status->flag |= RX_FLAG_ONLY_MONITOR; in mt7915_mac_fill_rx()
332 status->wcid = mt7915_rx_get_wcid(dev, idx, unicast); in mt7915_mac_fill_rx()
334 if (status->wcid) { in mt7915_mac_fill_rx()
335 msta = container_of(status->wcid, struct mt7915_sta, wcid); in mt7915_mac_fill_rx()
336 mt76_wcid_add_poll(&dev->mt76, &msta->wcid); in mt7915_mac_fill_rx()
339 status->freq = mphy->chandef.chan->center_freq; in mt7915_mac_fill_rx()
340 status->band = mphy->chandef.chan->band; in mt7915_mac_fill_rx()
341 if (status->band == NL80211_BAND_5GHZ) in mt7915_mac_fill_rx()
342 sband = &mphy->sband_5g.sband; in mt7915_mac_fill_rx()
343 else if (status->band == NL80211_BAND_6GHZ) in mt7915_mac_fill_rx()
344 sband = &mphy->sband_6g.sband; in mt7915_mac_fill_rx()
346 sband = &mphy->sband_2g.sband; in mt7915_mac_fill_rx()
348 if (!sband->channels) in mt7915_mac_fill_rx()
349 return -EINVAL; in mt7915_mac_fill_rx()
353 skb->ip_summed = CHECKSUM_UNNECESSARY; in mt7915_mac_fill_rx()
356 status->flag |= RX_FLAG_FAILED_FCS_CRC; in mt7915_mac_fill_rx()
359 status->flag |= RX_FLAG_MMIC_ERROR; in mt7915_mac_fill_rx()
363 status->flag |= RX_FLAG_DECRYPTED; in mt7915_mac_fill_rx()
364 status->flag |= RX_FLAG_IV_STRIPPED; in mt7915_mac_fill_rx()
365 status->flag |= RX_FLAG_MMIC_STRIPPED | RX_FLAG_MIC_STRIPPED; in mt7915_mac_fill_rx()
371 return -EINVAL; in mt7915_mac_fill_rx()
383 if ((u8 *)rxd - skb->data >= skb->len) in mt7915_mac_fill_rx()
384 return -EINVAL; in mt7915_mac_fill_rx()
390 if (status->flag & RX_FLAG_DECRYPTED) { in mt7915_mac_fill_rx()
402 status->iv[0] = data[5]; in mt7915_mac_fill_rx()
403 status->iv[1] = data[4]; in mt7915_mac_fill_rx()
404 status->iv[2] = data[3]; in mt7915_mac_fill_rx()
405 status->iv[3] = data[2]; in mt7915_mac_fill_rx()
406 status->iv[4] = data[1]; in mt7915_mac_fill_rx()
407 status->iv[5] = data[0]; in mt7915_mac_fill_rx()
414 if ((u8 *)rxd - skb->data >= skb->len) in mt7915_mac_fill_rx()
415 return -EINVAL; in mt7915_mac_fill_rx()
419 status->timestamp = le32_to_cpu(rxd[0]); in mt7915_mac_fill_rx()
420 status->flag |= RX_FLAG_MACTIME_START; in mt7915_mac_fill_rx()
423 status->flag |= RX_FLAG_AMPDU_DETAILS; in mt7915_mac_fill_rx()
425 /* all subframes of an A-MPDU have the same timestamp */ in mt7915_mac_fill_rx()
426 if (phy->rx_ampdu_ts != status->timestamp) { in mt7915_mac_fill_rx()
427 if (!++phy->ampdu_ref) in mt7915_mac_fill_rx()
428 phy->ampdu_ref++; in mt7915_mac_fill_rx()
430 phy->rx_ampdu_ts = status->timestamp; in mt7915_mac_fill_rx()
432 status->ampdu_ref = phy->ampdu_ref; in mt7915_mac_fill_rx()
436 if ((u8 *)rxd - skb->data >= skb->len) in mt7915_mac_fill_rx()
437 return -EINVAL; in mt7915_mac_fill_rx()
440 /* RXD Group 3 - P-RXV */ in mt7915_mac_fill_rx()
447 if ((u8 *)rxd - skb->data >= skb->len) in mt7915_mac_fill_rx()
448 return -EINVAL; in mt7915_mac_fill_rx()
454 status->enc_flags |= RX_ENC_FLAG_LDPC; in mt7915_mac_fill_rx()
456 status->chains = mphy->antenna_mask; in mt7915_mac_fill_rx()
457 status->chain_signal[0] = to_rssi(MT_PRXV_RCPI0, v1); in mt7915_mac_fill_rx()
458 status->chain_signal[1] = to_rssi(MT_PRXV_RCPI1, v1); in mt7915_mac_fill_rx()
459 status->chain_signal[2] = to_rssi(MT_PRXV_RCPI2, v1); in mt7915_mac_fill_rx()
460 status->chain_signal[3] = to_rssi(MT_PRXV_RCPI3, v1); in mt7915_mac_fill_rx()
462 /* RXD Group 5 - C-RXV */ in mt7915_mac_fill_rx()
465 if ((u8 *)rxd - skb->data >= skb->len) in mt7915_mac_fill_rx()
466 return -EINVAL; in mt7915_mac_fill_rx()
469 if (!is_mt7915(&dev->mt76) || (rxd1 & MT_RXD1_NORMAL_GROUP_5)) { in mt7915_mac_fill_rx()
470 ret = mt76_connac2_mac_fill_rx_rate(&dev->mt76, status, in mt7915_mac_fill_rx()
478 status->amsdu = !!amsdu_info; in mt7915_mac_fill_rx()
479 if (status->amsdu) { in mt7915_mac_fill_rx()
480 status->first_amsdu = amsdu_info == MT_RXD4_FIRST_AMSDU_FRAME; in mt7915_mac_fill_rx()
481 status->last_amsdu = amsdu_info == MT_RXD4_LAST_AMSDU_FRAME; in mt7915_mac_fill_rx()
484 hdr_gap = (u8 *)rxd - skb->data + 2 * remove_pad; in mt7915_mac_fill_rx()
489 if (!msta || !msta->vif) in mt7915_mac_fill_rx()
490 return -EINVAL; in mt7915_mac_fill_rx()
492 vif = container_of((void *)msta->vif, struct ieee80211_vif, in mt7915_mac_fill_rx()
503 if (!hdr_trans && status->amsdu) { in mt7915_mac_fill_rx()
508 * the hardware will insert an extra 2-byte field in mt7915_mac_fill_rx()
510 * type field. This happens either when the LLC-SNAP in mt7915_mac_fill_rx()
515 if (get_unaligned_be16(skb->data + pad_start) == ETH_P_8021Q) in mt7915_mac_fill_rx()
522 memmove(skb->data + 2, skb->data, pad_start); in mt7915_mac_fill_rx()
537 fc = hdr->frame_control; in mt7915_mac_fill_rx()
539 seq_ctrl = le16_to_cpu(hdr->seq_ctrl); in mt7915_mac_fill_rx()
543 status->flag |= RX_FLAG_8023; in mt7915_mac_fill_rx()
544 mt7915_wed_check_ppe(dev, &dev->mt76.q_rx[q], msta, skb, in mt7915_mac_fill_rx()
548 if (rxv && mode >= MT_PHY_TYPE_HE_SU && !(status->flag & RX_FLAG_8023)) in mt7915_mac_fill_rx()
549 mt76_connac2_mac_decode_he_radiotap(&dev->mt76, skb, rxv, mode); in mt7915_mac_fill_rx()
551 if (!status->wcid || !ieee80211_is_data_qos(fc)) in mt7915_mac_fill_rx()
554 status->aggr = unicast && in mt7915_mac_fill_rx()
556 status->qos_ctl = qos_ctl; in mt7915_mac_fill_rx()
557 status->seqno = IEEE80211_SEQ_TO_SN(seq_ctrl); in mt7915_mac_fill_rx()
566 struct mt7915_phy *phy = &dev->phy; in mt7915_mac_fill_rx_vector() local
567 __le32 *rxd = (__le32 *)skb->data; in mt7915_mac_fill_rx_vector()
577 if (band_idx && !phy->mt76->band_idx) { in mt7915_mac_fill_rx_vector()
578 phy = mt7915_ext_phy(dev); in mt7915_mac_fill_rx_vector()
579 if (!phy) in mt7915_mac_fill_rx_vector()
591 phy->test.last_rcpi[i] = rcpi & 0xff; in mt7915_mac_fill_rx_vector()
592 phy->test.last_ib_rssi[i] = ib_rssi & 0xff; in mt7915_mac_fill_rx_vector()
593 phy->test.last_wb_rssi[i] = wb_rssi & 0xff; in mt7915_mac_fill_rx_vector()
602 snr = FIELD_GET(MT_CRXV_SNR, v20) - 16; in mt7915_mac_fill_rx_vector()
604 phy->test.last_freq_offset = foe; in mt7915_mac_fill_rx_vector()
605 phy->test.last_snr = snr; in mt7915_mac_fill_rx_vector()
612 mt7915_mac_write_txwi_tm(struct mt7915_phy *phy, __le32 *txwi, in mt7915_mac_write_txwi_tm() argument
616 struct mt76_testmode_data *td = &phy->mt76->test; in mt7915_mac_write_txwi_tm()
618 u8 bw, mode, nss = td->tx_rate_nss; in mt7915_mac_write_txwi_tm()
619 u8 rate_idx = td->tx_rate_idx; in mt7915_mac_write_txwi_tm()
625 if (skb != phy->mt76->test.tx_skb) in mt7915_mac_write_txwi_tm()
628 switch (td->tx_rate_mode) { in mt7915_mac_write_txwi_tm()
652 band = phy->mt76->chandef.chan->band; in mt7915_mac_write_txwi_tm()
656 r = &phy->mt76->hw->wiphy->bands[band]->bitrates[rate_idx]; in mt7915_mac_write_txwi_tm()
657 val = cck ? r->hw_value_short : r->hw_value; in mt7915_mac_write_txwi_tm()
667 switch (phy->mt76->chandef.width) { in mt7915_mac_write_txwi_tm()
683 if (td->tx_rate_stbc && nss == 1) { in mt7915_mac_write_txwi_tm()
690 FIELD_PREP(MT_TX_RATE_NSS, nss - 1); in mt7915_mac_write_txwi_tm()
695 if (td->tx_rate_mode < MT76_TM_TX_MODE_HT) in mt7915_mac_write_txwi_tm()
701 FIELD_PREP(MT_TXD6_SGI, td->tx_rate_sgi); in mt7915_mac_write_txwi_tm()
704 * - 1x, 2x, 4x LTF + 0.8us GI in mt7915_mac_write_txwi_tm()
705 * - 2x LTF + 1.6us GI, 4x LTF + 3.2us GI in mt7915_mac_write_txwi_tm()
707 * - 2x, 4x LTF + 0.8us GI in mt7915_mac_write_txwi_tm()
708 * - 2x LTF + 1.6us GI, 4x LTF + 3.2us GI in mt7915_mac_write_txwi_tm()
710 * - 1x, 2x LTF + 1.6us GI in mt7915_mac_write_txwi_tm()
711 * - 4x LTF + 3.2us GI in mt7915_mac_write_txwi_tm()
714 val |= FIELD_PREP(MT_TXD6_HELTF, td->tx_ltf); in mt7915_mac_write_txwi_tm()
716 if (td->tx_rate_ldpc || (bw > 0 && mode >= MT_PHY_TYPE_HE_SU)) in mt7915_mac_write_txwi_tm()
722 phy->test.spe_idx)); in mt7915_mac_write_txwi_tm()
732 u8 phy_idx = (info->hw_queue & MT_TX_HW_QUEUE_PHY) >> 2; in mt7915_mac_write_txwi()
733 struct mt76_phy *mphy = &dev->phy; in mt7915_mac_write_txwi()
735 if (phy_idx && dev->phys[MT_BAND1]) in mt7915_mac_write_txwi()
736 mphy = dev->phys[MT_BAND1]; in mt7915_mac_write_txwi()
741 mt7915_mac_write_txwi_tm(mphy->priv, txwi, skb); in mt7915_mac_write_txwi()
749 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx_info->skb->data; in mt7915_tx_prepare_skb()
751 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx_info->skb); in mt7915_tx_prepare_skb()
752 struct ieee80211_key_conf *key = info->control.hw_key; in mt7915_tx_prepare_skb()
753 struct ieee80211_vif *vif = info->control.vif; in mt7915_tx_prepare_skb()
756 int id, i, nbuf = tx_info->nbuf - 1; in mt7915_tx_prepare_skb()
760 if (unlikely(tx_info->skb->len <= ETH_HLEN)) in mt7915_tx_prepare_skb()
761 return -EINVAL; in mt7915_tx_prepare_skb()
764 wcid = &dev->mt76.global_wcid; in mt7915_tx_prepare_skb()
769 msta = (struct mt7915_sta *)sta->drv_priv; in mt7915_tx_prepare_skb()
771 if (time_after(jiffies, msta->jiffies + HZ / 4)) { in mt7915_tx_prepare_skb()
772 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS; in mt7915_tx_prepare_skb()
773 msta->jiffies = jiffies; in mt7915_tx_prepare_skb()
777 t = (struct mt76_txwi_cache *)(txwi + mdev->drv->txwi_size); in mt7915_tx_prepare_skb()
778 t->skb = tx_info->skb; in mt7915_tx_prepare_skb()
784 pid = mt76_tx_status_skb_add(mdev, wcid, tx_info->skb); in mt7915_tx_prepare_skb()
785 mt7915_mac_write_txwi(mdev, txwi_ptr, tx_info->skb, wcid, pid, key, in mt7915_tx_prepare_skb()
790 txp->buf[i] = cpu_to_le32(tx_info->buf[i + 1].addr); in mt7915_tx_prepare_skb()
791 txp->len[i] = cpu_to_le16(tx_info->buf[i + 1].len); in mt7915_tx_prepare_skb()
793 txp->nbuf = nbuf; in mt7915_tx_prepare_skb()
795 txp->flags = cpu_to_le16(MT_CT_INFO_APPLY_TXD | MT_CT_INFO_FROM_HOST); in mt7915_tx_prepare_skb()
798 txp->flags |= cpu_to_le16(MT_CT_INFO_NONE_CIPHER_FRAME); in mt7915_tx_prepare_skb()
800 if (!(info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP) && in mt7915_tx_prepare_skb()
801 ieee80211_is_mgmt(hdr->frame_control)) in mt7915_tx_prepare_skb()
802 txp->flags |= cpu_to_le16(MT_CT_INFO_MGMT_FRAME); in mt7915_tx_prepare_skb()
805 struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv; in mt7915_tx_prepare_skb()
807 txp->bss_idx = mvif->mt76.idx; in mt7915_tx_prepare_skb()
810 txp->token = cpu_to_le16(id); in mt7915_tx_prepare_skb()
811 if (test_bit(MT_WCID_FLAG_4ADDR, &wcid->flags)) in mt7915_tx_prepare_skb()
812 txp->rept_wds_wcid = cpu_to_le16(wcid->idx); in mt7915_tx_prepare_skb()
814 txp->rept_wds_wcid = cpu_to_le16(0x3ff); in mt7915_tx_prepare_skb()
815 tx_info->skb = NULL; in mt7915_tx_prepare_skb()
818 tx_info->buf[1].len = MT_CT_PARSE_LEN; in mt7915_tx_prepare_skb()
819 tx_info->buf[1].skip_unmap = true; in mt7915_tx_prepare_skb()
820 tx_info->nbuf = MT_CT_DMA_BUF_NUM; in mt7915_tx_prepare_skb()
841 txp->token = cpu_to_le16(token_id); in mt7915_wed_init_buf()
842 txp->nbuf = 1; in mt7915_wed_init_buf()
843 txp->buf[0] = cpu_to_le32(phys + MT_TXD_SIZE + sizeof(*txp)); in mt7915_wed_init_buf()
851 struct mt76_dev *mdev = &dev->mt76; in mt7915_mac_tx_free_prepare()
852 struct mt76_phy *mphy_ext = mdev->phys[MT_BAND1]; in mt7915_mac_tx_free_prepare()
855 mt76_queue_tx_cleanup(dev, dev->mphy.q_tx[MT_TXQ_PSD], false); in mt7915_mac_tx_free_prepare()
856 mt76_queue_tx_cleanup(dev, dev->mphy.q_tx[MT_TXQ_BE], false); in mt7915_mac_tx_free_prepare()
858 mt76_queue_tx_cleanup(dev, mphy_ext->q_tx[MT_TXQ_PSD], false); in mt7915_mac_tx_free_prepare()
859 mt76_queue_tx_cleanup(dev, mphy_ext->q_tx[MT_TXQ_BE], false); in mt7915_mac_tx_free_prepare()
872 mt76_set_tx_blocked(&dev->mt76, false); in mt7915_mac_tx_free_done()
874 mt76_worker_schedule(&dev->mt76.tx_worker); in mt7915_mac_tx_free_done()
887 struct mt76_dev *mdev = &dev->mt76; in mt7915_mac_tx_free()
895 u32 txd = le32_to_cpu(free->txd); in mt7915_mac_tx_free()
900 total = le16_get_bits(free->ctrl, MT_TX_FREE_MSDU_CNT); in mt7915_mac_tx_free()
920 wcid = rcu_dereference(dev->mt76.wcid[idx]); in mt7915_mac_tx_free()
926 mt76_wcid_add_poll(&dev->mt76, &msta->wcid); in mt7915_mac_tx_free()
930 if (!mtk_wed_device_active(&mdev->mmio.wed) && wcid) { in mt7915_mac_tx_free()
935 FIELD_GET(MT_TX_FREE_COUNT_V3, info) - 1; in mt7915_mac_tx_free()
940 FIELD_GET(MT_TX_FREE_COUNT, info) - 1; in mt7915_mac_tx_free()
944 wcid->stats.tx_retries += tx_retries; in mt7915_mac_tx_free()
945 wcid->stats.tx_failed += tx_failed; in mt7915_mac_tx_free()
976 struct mt76_dev *mdev = &dev->mt76; in mt7915_mac_tx_free_v0()
984 count = FIELD_GET(MT_TX_FREE_MSDU_CNT_V0, le16_to_cpu(free->ctrl)); in mt7915_mac_tx_free_v0()
1021 wcid = rcu_dereference(dev->mt76.wcid[wcidx]); in mt7915_mac_add_txs()
1028 mt76_connac2_mac_fill_txs(&dev->mt76, wcid, txs_data); in mt7915_mac_add_txs()
1030 mt76_connac2_mac_add_txs_skb(&dev->mt76, wcid, pid, txs_data); in mt7915_mac_add_txs()
1032 if (!wcid->sta) in mt7915_mac_add_txs()
1035 mt76_wcid_add_poll(&dev->mt76, &msta->wcid); in mt7915_mac_add_txs()
1073 __le32 *rxd = (__le32 *)skb->data; in mt7915_queue_rx_skb()
1074 __le32 *end = (__le32 *)&skb->data[skb->len]; in mt7915_queue_rx_skb()
1081 mt7915_mac_tx_free(dev, skb->data, skb->len); in mt7915_queue_rx_skb()
1085 mt7915_mac_tx_free_v0(dev, skb->data, skb->len); in mt7915_queue_rx_skb()
1100 mt7915_debugfs_rx_fw_monitor(dev, skb->data, skb->len); in mt7915_queue_rx_skb()
1105 mt76_rx(&dev->mt76, q, skb); in mt7915_queue_rx_skb()
1115 void mt7915_mac_cca_stats_reset(struct mt7915_phy *phy) in mt7915_mac_cca_stats_reset() argument
1117 struct mt7915_dev *dev = phy->dev; in mt7915_mac_cca_stats_reset()
1118 u32 reg = MT_WF_PHY_RX_CTRL1(phy->mt76->band_idx); in mt7915_mac_cca_stats_reset()
1124 void mt7915_mac_reset_counters(struct mt7915_phy *phy) in mt7915_mac_reset_counters() argument
1126 struct mt7915_dev *dev = phy->dev; in mt7915_mac_reset_counters()
1130 mt76_rr(dev, MT_TX_AGG_CNT(phy->mt76->band_idx, i)); in mt7915_mac_reset_counters()
1131 mt76_rr(dev, MT_TX_AGG_CNT2(phy->mt76->band_idx, i)); in mt7915_mac_reset_counters()
1134 phy->mt76->survey_time = ktime_get_boottime(); in mt7915_mac_reset_counters()
1135 memset(phy->mt76->aggr_stats, 0, sizeof(phy->mt76->aggr_stats)); in mt7915_mac_reset_counters()
1137 /* reset airtime counters */ in mt7915_mac_reset_counters()
1138 mt76_set(dev, MT_WF_RMAC_MIB_AIRTIME0(phy->mt76->band_idx), in mt7915_mac_reset_counters()
1141 mt7915_mcu_get_chan_mib_info(phy, true); in mt7915_mac_reset_counters()
1144 void mt7915_mac_set_timing(struct mt7915_phy *phy) in mt7915_mac_set_timing() argument
1146 s16 coverage_class = phy->coverage_class; in mt7915_mac_set_timing()
1147 struct mt7915_dev *dev = phy->dev; in mt7915_mac_set_timing()
1154 u8 band = phy->mt76->band_idx; in mt7915_mac_set_timing()
1156 bool a_band = !(phy->mt76->chandef.chan->band == NL80211_BAND_2GHZ); in mt7915_mac_set_timing()
1158 if (!test_bit(MT76_STATE_RUNNING, &phy->mt76->state)) in mt7915_mac_set_timing()
1162 coverage_class = max_t(s16, dev->phy.coverage_class, in mt7915_mac_set_timing()
1163 ext_phy->coverage_class); in mt7915_mac_set_timing()
1173 if (!is_mt7915(&dev->mt76)) { in mt7915_mac_set_timing()
1191 FIELD_PREP(MT_IFS_SLOT, phy->slottime)); in mt7915_mac_set_timing()
1193 if (phy->slottime < 20 || a_band) in mt7915_mac_set_timing()
1207 reg = is_mt7915(&dev->mt76) ? MT_WF_PHY_RXTD12(band) : in mt7915_mac_enable_nf()
1213 reg = is_mt7915(&dev->mt76) ? MT_WF_PHY_RX_CTRL1(band) : in mt7915_mac_enable_nf()
1219 mt7915_phy_get_nf(struct mt7915_phy *phy, int idx) in mt7915_phy_get_nf() argument
1222 struct mt7915_dev *dev = phy->dev; in mt7915_phy_get_nf()
1226 for (nss = 0; nss < hweight8(phy->mt76->chainmask); nss++) { in mt7915_phy_get_nf()
1227 u32 reg = is_mt7915(&dev->mt76) ? in mt7915_phy_get_nf()
1228 MT_WF_IRPI_NSS(0, nss + (idx << dev->dbdc_support)) : in mt7915_phy_get_nf()
1246 struct mt7915_phy *phy = mphy->priv; in mt7915_update_channel() local
1247 struct mt76_channel_state *state = mphy->chan_state; in mt7915_update_channel()
1250 mt7915_mcu_get_chan_mib_info(phy, false); in mt7915_update_channel()
1252 nf = mt7915_phy_get_nf(phy, phy->mt76->band_idx); in mt7915_update_channel()
1253 if (!phy->noise) in mt7915_update_channel()
1254 phy->noise = nf << 4; in mt7915_update_channel()
1256 phy->noise += nf - (phy->noise >> 4); in mt7915_update_channel()
1258 state->noise = -(phy->noise >> 4); in mt7915_update_channel()
1266 ret = wait_event_timeout(dev->reset_wait, in mt7915_wait_reset_state()
1267 (READ_ONCE(dev->recovery.state) & state), in mt7915_wait_reset_state()
1270 WARN(!ret, "Timeout waiting for MCU reset state %x\n", state); in mt7915_wait_reset_state()
1279 switch (vif->type) { in mt7915_update_vif_beacon()
1283 mt7915_mcu_add_beacon(hw, vif, vif->bss_conf.enable_beacon, in mt7915_update_vif_beacon()
1294 struct mt76_phy *mphy_ext = dev->mt76.phys[MT_BAND1]; in mt7915_update_beacons()
1296 ieee80211_iterate_active_interfaces(dev->mt76.hw, in mt7915_update_beacons()
1298 mt7915_update_vif_beacon, dev->mt76.hw); in mt7915_update_beacons()
1303 ieee80211_iterate_active_interfaces(mphy_ext->hw, in mt7915_update_beacons()
1305 mt7915_update_vif_beacon, mphy_ext->hw); in mt7915_update_beacons()
1313 struct mt76_dev *mdev = &dev->mt76; in mt7915_mac_restart()
1316 ext_phy = dev->mt76.phys[MT_BAND1]; in mt7915_mac_restart()
1317 phy2 = ext_phy ? ext_phy->priv : NULL; in mt7915_mac_restart()
1319 if (dev->hif2) { in mt7915_mac_restart()
1324 if (dev_is_pci(mdev->dev)) { in mt7915_mac_restart()
1326 if (dev->hif2) { in mt7915_mac_restart()
1334 set_bit(MT76_RESET, &dev->mphy.state); in mt7915_mac_restart()
1335 set_bit(MT76_MCU_RESET, &dev->mphy.state); in mt7915_mac_restart()
1336 wake_up(&dev->mt76.mcu.wait); in mt7915_mac_restart()
1338 set_bit(MT76_RESET, &ext_phy->state); in mt7915_mac_restart()
1341 mt76_txq_schedule_all(&dev->mphy); in mt7915_mac_restart()
1346 mt76_worker_disable(&dev->mt76.tx_worker); in mt7915_mac_restart()
1348 if (mdev->q_rx[i].ndesc) in mt7915_mac_restart()
1349 napi_disable(&dev->mt76.napi[i]); in mt7915_mac_restart()
1351 napi_disable(&dev->mt76.tx_napi); in mt7915_mac_restart()
1354 mt76_connac2_tx_token_put(&dev->mt76); in mt7915_mac_restart()
1355 idr_init(&dev->mt76.token); in mt7915_mac_restart()
1360 if (mdev->q_rx[i].ndesc) { in mt7915_mac_restart()
1361 napi_enable(&dev->mt76.napi[i]); in mt7915_mac_restart()
1367 if (mdev->q_rx[i].ndesc) { in mt7915_mac_restart()
1368 napi_schedule(&dev->mt76.napi[i]); in mt7915_mac_restart()
1372 clear_bit(MT76_MCU_RESET, &dev->mphy.state); in mt7915_mac_restart()
1373 clear_bit(MT76_STATE_MCU_RUNNING, &dev->mphy.state); in mt7915_mac_restart()
1375 mt76_wr(dev, MT_INT_MASK_CSR, dev->mt76.mmio.irqmask); in mt7915_mac_restart()
1378 if (dev->hif2) { in mt7915_mac_restart()
1379 mt76_wr(dev, MT_INT1_MASK_CSR, dev->mt76.mmio.irqmask); in mt7915_mac_restart()
1382 if (dev_is_pci(mdev->dev)) { in mt7915_mac_restart()
1384 if (dev->hif2) { in mt7915_mac_restart()
1386 dev->hif2->index | MT_PCIE_RECOG_ID_SEM); in mt7915_mac_restart()
1405 mt7915_init_txpower(&dev->phy); in mt7915_mac_restart()
1409 if (test_bit(MT76_STATE_RUNNING, &dev->mphy.state)) { in mt7915_mac_restart()
1410 ret = mt7915_run(dev->mphy.hw); in mt7915_mac_restart()
1415 if (ext_phy && test_bit(MT76_STATE_RUNNING, &ext_phy->state)) { in mt7915_mac_restart()
1416 ret = mt7915_run(ext_phy->hw); in mt7915_mac_restart()
1422 /* reset done */ in mt7915_mac_restart()
1423 clear_bit(MT76_RESET, &dev->mphy.state); in mt7915_mac_restart()
1425 clear_bit(MT76_RESET, &phy2->mt76->state); in mt7915_mac_restart()
1427 napi_enable(&dev->mt76.tx_napi); in mt7915_mac_restart()
1430 napi_schedule(&dev->mt76.tx_napi); in mt7915_mac_restart()
1433 mt76_worker_enable(&dev->mt76.tx_worker); in mt7915_mac_restart()
1445 ext_phy = dev->mt76.phys[MT_BAND1]; in mt7915_mac_full_reset()
1446 phy2 = ext_phy ? ext_phy->priv : NULL; in mt7915_mac_full_reset()
1448 dev->recovery.hw_full_reset = true; in mt7915_mac_full_reset()
1450 set_bit(MT76_MCU_RESET, &dev->mphy.state); in mt7915_mac_full_reset()
1451 wake_up(&dev->mt76.mcu.wait); in mt7915_mac_full_reset()
1454 ieee80211_stop_queues(ext_phy->hw); in mt7915_mac_full_reset()
1456 cancel_delayed_work_sync(&dev->mphy.mac_work); in mt7915_mac_full_reset()
1458 cancel_delayed_work_sync(&ext_phy->mac_work); in mt7915_mac_full_reset()
1460 mutex_lock(&dev->mt76.mutex); in mt7915_mac_full_reset()
1467 dev_err(dev->mt76.dev, "chip full reset failed\n"); in mt7915_mac_full_reset()
1469 spin_lock_bh(&dev->mt76.sta_poll_lock); in mt7915_mac_full_reset()
1470 while (!list_empty(&dev->mt76.sta_poll_list)) in mt7915_mac_full_reset()
1471 list_del_init(dev->mt76.sta_poll_list.next); in mt7915_mac_full_reset()
1472 spin_unlock_bh(&dev->mt76.sta_poll_lock); in mt7915_mac_full_reset()
1474 memset(dev->mt76.wcid_mask, 0, sizeof(dev->mt76.wcid_mask)); in mt7915_mac_full_reset()
1475 dev->mt76.vif_mask = 0; in mt7915_mac_full_reset()
1476 dev->phy.omac_mask = 0; in mt7915_mac_full_reset()
1478 phy2->omac_mask = 0; in mt7915_mac_full_reset()
1480 i = mt76_wcid_alloc(dev->mt76.wcid_mask, MT7915_WTBL_STA); in mt7915_mac_full_reset()
1481 dev->mt76.global_wcid.idx = i; in mt7915_mac_full_reset()
1482 dev->recovery.hw_full_reset = false; in mt7915_mac_full_reset()
1484 mutex_unlock(&dev->mt76.mutex); in mt7915_mac_full_reset()
1488 ieee80211_restart_hw(ext_phy->hw); in mt7915_mac_full_reset()
1500 ext_phy = dev->mt76.phys[MT_BAND1]; in mt7915_mac_reset_work()
1501 phy2 = ext_phy ? ext_phy->priv : NULL; in mt7915_mac_reset_work()
1503 /* chip full reset */ in mt7915_mac_reset_work()
1504 if (dev->recovery.restart) { in mt7915_mac_reset_work()
1509 if (READ_ONCE(dev->recovery.state) & MT_MCU_CMD_WA_WDT) in mt7915_mac_reset_work()
1510 dev->recovery.wa_reset_count++; in mt7915_mac_reset_work()
1512 dev->recovery.wm_reset_count++; in mt7915_mac_reset_work()
1523 dev->recovery.state = MT_MCU_CMD_NORMAL_STATE; in mt7915_mac_reset_work()
1524 dev->recovery.restart = false; in mt7915_mac_reset_work()
1528 /* chip partial reset */ in mt7915_mac_reset_work()
1529 if (!(READ_ONCE(dev->recovery.state) & MT_MCU_CMD_STOP_DMA)) in mt7915_mac_reset_work()
1534 ieee80211_stop_queues(ext_phy->hw); in mt7915_mac_reset_work()
1536 set_bit(MT76_RESET, &dev->mphy.state); in mt7915_mac_reset_work()
1537 set_bit(MT76_MCU_RESET, &dev->mphy.state); in mt7915_mac_reset_work()
1538 wake_up(&dev->mt76.mcu.wait); in mt7915_mac_reset_work()
1539 cancel_delayed_work_sync(&dev->mphy.mac_work); in mt7915_mac_reset_work()
1541 set_bit(MT76_RESET, &phy2->mt76->state); in mt7915_mac_reset_work()
1542 cancel_delayed_work_sync(&phy2->mt76->mac_work); in mt7915_mac_reset_work()
1545 mutex_lock(&dev->mt76.mutex); in mt7915_mac_reset_work()
1547 mt76_worker_disable(&dev->mt76.tx_worker); in mt7915_mac_reset_work()
1548 mt76_for_each_q_rx(&dev->mt76, i) in mt7915_mac_reset_work()
1549 napi_disable(&dev->mt76.napi[i]); in mt7915_mac_reset_work()
1550 napi_disable(&dev->mt76.tx_napi); in mt7915_mac_reset_work()
1553 if (mtk_wed_device_active(&dev->mt76.mmio.wed)) in mt7915_mac_reset_work()
1554 mtk_wed_device_stop(&dev->mt76.mmio.wed); in mt7915_mac_reset_work()
1561 mt76_connac2_tx_token_put(&dev->mt76); in mt7915_mac_reset_work()
1562 idr_init(&dev->mt76.token); in mt7915_mac_reset_work()
1574 clear_bit(MT76_MCU_RESET, &dev->mphy.state); in mt7915_mac_reset_work()
1575 clear_bit(MT76_RESET, &dev->mphy.state); in mt7915_mac_reset_work()
1577 clear_bit(MT76_RESET, &phy2->mt76->state); in mt7915_mac_reset_work()
1579 mt76_for_each_q_rx(&dev->mt76, i) { in mt7915_mac_reset_work()
1580 napi_enable(&dev->mt76.napi[i]); in mt7915_mac_reset_work()
1584 mt76_for_each_q_rx(&dev->mt76, i) { in mt7915_mac_reset_work()
1585 napi_schedule(&dev->mt76.napi[i]); in mt7915_mac_reset_work()
1589 tasklet_schedule(&dev->mt76.irq_tasklet); in mt7915_mac_reset_work()
1591 mt76_worker_enable(&dev->mt76.tx_worker); in mt7915_mac_reset_work()
1593 napi_enable(&dev->mt76.tx_napi); in mt7915_mac_reset_work()
1595 napi_schedule(&dev->mt76.tx_napi); in mt7915_mac_reset_work()
1600 ieee80211_wake_queues(ext_phy->hw); in mt7915_mac_reset_work()
1602 mutex_unlock(&dev->mt76.mutex); in mt7915_mac_reset_work()
1606 ieee80211_queue_delayed_work(mt76_hw(dev), &dev->mphy.mac_work, in mt7915_mac_reset_work()
1609 ieee80211_queue_delayed_work(ext_phy->hw, in mt7915_mac_reset_work()
1610 &phy2->mt76->mac_work, in mt7915_mac_reset_work()
1628 mutex_lock(&dev->dump_mutex); in mt7915_mac_dump_work()
1632 mutex_unlock(&dev->dump_mutex); in mt7915_mac_dump_work()
1637 if (!mem_region || !crash_data->memdump_buf_len) { in mt7915_mac_dump_work()
1638 mutex_unlock(&dev->dump_mutex); in mt7915_mac_dump_work()
1642 buf = crash_data->memdump_buf; in mt7915_mac_dump_work()
1643 buf_len = crash_data->memdump_buf_len; in mt7915_mac_dump_work()
1648 if (mem_region->len > buf_len) { in mt7915_mac_dump_work()
1649 dev_warn(dev->mt76.dev, "%s len %lu is too large\n", in mt7915_mac_dump_work()
1650 mem_region->name, in mt7915_mac_dump_work()
1651 (unsigned long)mem_region->len); in mt7915_mac_dump_work()
1658 buf_len -= sizeof(*hdr); in mt7915_mac_dump_work()
1660 mt7915_memcpy_fromio(dev, buf, mem_region->start, in mt7915_mac_dump_work()
1661 mem_region->len); in mt7915_mac_dump_work()
1663 hdr->start = mem_region->start; in mt7915_mac_dump_work()
1664 hdr->len = mem_region->len; in mt7915_mac_dump_work()
1666 if (!mem_region->len) in mt7915_mac_dump_work()
1670 buf += mem_region->len; in mt7915_mac_dump_work()
1671 buf_len -= mem_region->len; in mt7915_mac_dump_work()
1676 mutex_unlock(&dev->dump_mutex); in mt7915_mac_dump_work()
1681 queue_work(dev->mt76.wq, &dev->reset_work); in mt7915_mac_dump_work()
1686 if (!dev->recovery.hw_init_done) in mt7915_reset()
1689 if (dev->recovery.hw_full_reset) in mt7915_reset()
1693 if (READ_ONCE(dev->recovery.state) & MT_MCU_CMD_WDT_MASK) { in mt7915_reset()
1694 dev->recovery.restart = true; in mt7915_reset()
1695 dev_info(dev->mt76.dev, in mt7915_reset()
1697 wiphy_name(dev->mt76.hw->wiphy)); in mt7915_reset()
1700 queue_work(dev->mt76.wq, &dev->dump_work); in mt7915_reset()
1704 if ((READ_ONCE(dev->recovery.state) & MT_MCU_CMD_STOP_DMA)) { in mt7915_reset()
1705 set_bit(MT76_MCU_RESET, &dev->mphy.state); in mt7915_reset()
1706 wake_up(&dev->mt76.mcu.wait); in mt7915_reset()
1709 queue_work(dev->mt76.wq, &dev->reset_work); in mt7915_reset()
1710 wake_up(&dev->reset_wait); in mt7915_reset()
1713 void mt7915_mac_update_stats(struct mt7915_phy *phy) in mt7915_mac_update_stats() argument
1715 struct mt76_mib_stats *mib = &phy->mib; in mt7915_mac_update_stats()
1716 struct mt7915_dev *dev = phy->dev; in mt7915_mac_update_stats()
1718 u8 band = phy->mt76->band_idx; in mt7915_mac_update_stats()
1722 mib->fcs_err_cnt += is_mt7915(&dev->mt76) ? in mt7915_mac_update_stats()
1727 mib->rx_fifo_full_cnt += FIELD_GET(MT_MIB_SDR4_RX_FIFO_FULL_MASK, cnt); in mt7915_mac_update_stats()
1730 mib->rx_mpdu_cnt += cnt; in mt7915_mac_update_stats()
1733 mib->channel_idle_cnt += FIELD_GET(MT_MIB_SDR6_CHANNEL_IDL_CNT_MASK, cnt); in mt7915_mac_update_stats()
1736 mib->rx_vector_mismatch_cnt += in mt7915_mac_update_stats()
1740 mib->rx_delimiter_fail_cnt += in mt7915_mac_update_stats()
1744 mib->rx_mrdy_cnt += is_mt7915(&dev->mt76) ? in mt7915_mac_update_stats()
1749 mib->rx_len_mismatch_cnt += in mt7915_mac_update_stats()
1753 mib->tx_ampdu_cnt += cnt; in mt7915_mac_update_stats()
1756 mib->tx_stop_q_empty_cnt += in mt7915_mac_update_stats()
1760 mib->tx_mpdu_attempts_cnt += is_mt7915(&dev->mt76) ? in mt7915_mac_update_stats()
1765 mib->tx_mpdu_success_cnt += is_mt7915(&dev->mt76) ? in mt7915_mac_update_stats()
1770 mib->primary_cca_busy_time += in mt7915_mac_update_stats()
1774 mib->secondary_cca_busy_time += in mt7915_mac_update_stats()
1778 mib->primary_energy_detect_time += in mt7915_mac_update_stats()
1782 mib->cck_mdrdy_time += FIELD_GET(MT_MIB_SDR19_CCK_MDRDY_TIME_MASK, cnt); in mt7915_mac_update_stats()
1785 mib->ofdm_mdrdy_time += in mt7915_mac_update_stats()
1789 mib->green_mdrdy_time += in mt7915_mac_update_stats()
1793 mib->rx_ampdu_cnt += cnt; in mt7915_mac_update_stats()
1796 mib->rx_ampdu_bytes_cnt += cnt; in mt7915_mac_update_stats()
1799 mib->rx_ampdu_valid_subframe_cnt += is_mt7915(&dev->mt76) ? in mt7915_mac_update_stats()
1804 mib->rx_ampdu_valid_subframe_bytes_cnt += cnt; in mt7915_mac_update_stats()
1807 mib->tx_rwp_fail_cnt += in mt7915_mac_update_stats()
1811 mib->tx_rwp_need_cnt += in mt7915_mac_update_stats()
1815 mib->rx_pfdrop_cnt += is_mt7915(&dev->mt76) ? in mt7915_mac_update_stats()
1820 mib->rx_vec_queue_overflow_drop_cnt += is_mt7915(&dev->mt76) ? in mt7915_mac_update_stats()
1825 mib->rx_ba_cnt += cnt; in mt7915_mac_update_stats()
1828 mib->tx_bf_cnt += FIELD_GET(MT_MIB_MU_BF_TX_CNT, cnt); in mt7915_mac_update_stats()
1831 mib->tx_mu_mpdu_cnt += cnt; in mt7915_mac_update_stats()
1834 mib->tx_mu_acked_mpdu_cnt += cnt; in mt7915_mac_update_stats()
1837 mib->tx_su_acked_mpdu_cnt += cnt; in mt7915_mac_update_stats()
1840 mib->tx_bf_rx_fb_bw = FIELD_GET(MT_ETBF_PAR_RPT0_FB_BW, cnt); in mt7915_mac_update_stats()
1841 mib->tx_bf_rx_fb_nc_cnt += FIELD_GET(MT_ETBF_PAR_RPT0_FB_NC, cnt); in mt7915_mac_update_stats()
1842 mib->tx_bf_rx_fb_nr_cnt += FIELD_GET(MT_ETBF_PAR_RPT0_FB_NR, cnt); in mt7915_mac_update_stats()
1844 for (i = 0; i < ARRAY_SIZE(mib->tx_amsdu); i++) { in mt7915_mac_update_stats()
1846 mib->tx_amsdu[i] += cnt; in mt7915_mac_update_stats()
1847 mib->tx_amsdu_cnt += cnt; in mt7915_mac_update_stats()
1850 if (is_mt7915(&dev->mt76)) { in mt7915_mac_update_stats()
1853 mib->ba_miss_cnt += in mt7915_mac_update_stats()
1855 mib->ack_fail_cnt += in mt7915_mac_update_stats()
1859 mib->rts_cnt += FIELD_GET(MT_MIB_RTS_COUNT_MASK, val); in mt7915_mac_update_stats()
1860 mib->rts_retries_cnt += in mt7915_mac_update_stats()
1864 phy->mt76->aggr_stats[aggr0++] += val & 0xffff; in mt7915_mac_update_stats()
1865 phy->mt76->aggr_stats[aggr0++] += val >> 16; in mt7915_mac_update_stats()
1868 phy->mt76->aggr_stats[aggr1++] += val & 0xffff; in mt7915_mac_update_stats()
1869 phy->mt76->aggr_stats[aggr1++] += val >> 16; in mt7915_mac_update_stats()
1873 mib->tx_pkt_ebf_cnt += FIELD_GET(MT_MIB_SDR32_TX_PKT_EBF_CNT, cnt); in mt7915_mac_update_stats()
1876 mib->tx_pkt_ibf_cnt += FIELD_GET(MT_MIB_SDR33_TX_PKT_IBF_CNT, cnt); in mt7915_mac_update_stats()
1879 mib->tx_bf_ibf_ppdu_cnt += FIELD_GET(MT_ETBF_TX_IBF_CNT, cnt); in mt7915_mac_update_stats()
1880 mib->tx_bf_ebf_ppdu_cnt += FIELD_GET(MT_ETBF_TX_EBF_CNT, cnt); in mt7915_mac_update_stats()
1883 mib->tx_bf_fb_cpl_cnt += FIELD_GET(MT_ETBF_TX_FB_CPL, cnt); in mt7915_mac_update_stats()
1884 mib->tx_bf_fb_trig_cnt += FIELD_GET(MT_ETBF_TX_FB_TRI, cnt); in mt7915_mac_update_stats()
1887 mib->tx_bf_rx_fb_all_cnt += FIELD_GET(MT_ETBF_RX_FB_ALL, cnt); in mt7915_mac_update_stats()
1888 mib->tx_bf_rx_fb_he_cnt += FIELD_GET(MT_ETBF_RX_FB_HE, cnt); in mt7915_mac_update_stats()
1889 mib->tx_bf_rx_fb_vht_cnt += FIELD_GET(MT_ETBF_RX_FB_VHT, cnt); in mt7915_mac_update_stats()
1890 mib->tx_bf_rx_fb_ht_cnt += FIELD_GET(MT_ETBF_RX_FB_HT, cnt); in mt7915_mac_update_stats()
1895 mib->rts_cnt += FIELD_GET(GENMASK(15, 0), val); in mt7915_mac_update_stats()
1896 mib->rts_cnt += FIELD_GET(GENMASK(31, 16), val); in mt7915_mac_update_stats()
1900 mib->rts_retries_cnt += FIELD_GET(GENMASK(15, 0), val); in mt7915_mac_update_stats()
1901 mib->rts_retries_cnt += FIELD_GET(GENMASK(31, 16), val); in mt7915_mac_update_stats()
1905 mib->ba_miss_cnt += FIELD_GET(GENMASK(15, 0), val); in mt7915_mac_update_stats()
1906 mib->ba_miss_cnt += FIELD_GET(GENMASK(31, 16), val); in mt7915_mac_update_stats()
1910 mib->ack_fail_cnt += FIELD_GET(GENMASK(15, 0), val); in mt7915_mac_update_stats()
1911 mib->ack_fail_cnt += FIELD_GET(GENMASK(31, 16), val); in mt7915_mac_update_stats()
1916 phy->mt76->aggr_stats[aggr0++] += FIELD_GET(GENMASK(15, 0), val); in mt7915_mac_update_stats()
1917 phy->mt76->aggr_stats[aggr0++] += FIELD_GET(GENMASK(31, 16), val); in mt7915_mac_update_stats()
1921 mib->tx_pkt_ibf_cnt += FIELD_GET(MT_MIB_SDR32_TX_PKT_IBF_CNT, cnt); in mt7915_mac_update_stats()
1922 mib->tx_bf_ibf_ppdu_cnt += FIELD_GET(MT_MIB_SDR32_TX_PKT_IBF_CNT, cnt); in mt7915_mac_update_stats()
1923 mib->tx_pkt_ebf_cnt += FIELD_GET(MT_MIB_SDR32_TX_PKT_EBF_CNT, cnt); in mt7915_mac_update_stats()
1924 mib->tx_bf_ebf_ppdu_cnt += FIELD_GET(MT_MIB_SDR32_TX_PKT_EBF_CNT, cnt); in mt7915_mac_update_stats()
1927 mib->tx_bf_fb_cpl_cnt += FIELD_GET(MT_MIB_BFCR7_BFEE_TX_FB_CPL, cnt); in mt7915_mac_update_stats()
1930 mib->tx_bf_fb_trig_cnt += FIELD_GET(MT_MIB_BFCR2_BFEE_TX_FB_TRIG, cnt); in mt7915_mac_update_stats()
1933 mib->tx_bf_rx_fb_vht_cnt += FIELD_GET(MT_MIB_BFCR0_RX_FB_VHT, cnt); in mt7915_mac_update_stats()
1934 mib->tx_bf_rx_fb_all_cnt += FIELD_GET(MT_MIB_BFCR0_RX_FB_VHT, cnt); in mt7915_mac_update_stats()
1935 mib->tx_bf_rx_fb_ht_cnt += FIELD_GET(MT_MIB_BFCR0_RX_FB_HT, cnt); in mt7915_mac_update_stats()
1936 mib->tx_bf_rx_fb_all_cnt += FIELD_GET(MT_MIB_BFCR0_RX_FB_HT, cnt); in mt7915_mac_update_stats()
1939 mib->tx_bf_rx_fb_he_cnt += FIELD_GET(MT_MIB_BFCR1_RX_FB_HE, cnt); in mt7915_mac_update_stats()
1940 mib->tx_bf_rx_fb_all_cnt += FIELD_GET(MT_MIB_BFCR1_RX_FB_HE, cnt); in mt7915_mac_update_stats()
1944 static void mt7915_mac_severe_check(struct mt7915_phy *phy) in mt7915_mac_severe_check() argument
1946 struct mt7915_dev *dev = phy->dev; in mt7915_mac_severe_check()
1949 if (!phy->omac_mask) in mt7915_mac_severe_check()
1956 trb = mt76_rr(dev, MT_TRB_RXPSR0(phy->mt76->band_idx)); in mt7915_mac_severe_check()
1960 (FIELD_GET(MT_TRB_RXPSR0_RX_RMAC_PTR, phy->trb_ts) != in mt7915_mac_severe_check()
1961 FIELD_GET(MT_TRB_RXPSR0_RX_WTBL_PTR, phy->trb_ts)) && in mt7915_mac_severe_check()
1962 trb == phy->trb_ts) in mt7915_mac_severe_check()
1964 phy->mt76->band_idx); in mt7915_mac_severe_check()
1966 phy->trb_ts = trb; in mt7915_mac_severe_check()
1978 spin_lock_bh(&dev->mt76.sta_poll_lock); in mt7915_mac_sta_rc_work()
1979 list_splice_init(&dev->sta_rc_list, &list); in mt7915_mac_sta_rc_work()
1983 list_del_init(&msta->rc_list); in mt7915_mac_sta_rc_work()
1984 changed = msta->changed; in mt7915_mac_sta_rc_work()
1985 msta->changed = 0; in mt7915_mac_sta_rc_work()
1986 spin_unlock_bh(&dev->mt76.sta_poll_lock); in mt7915_mac_sta_rc_work()
1989 vif = container_of((void *)msta->vif, struct ieee80211_vif, drv_priv); in mt7915_mac_sta_rc_work()
1999 spin_lock_bh(&dev->mt76.sta_poll_lock); in mt7915_mac_sta_rc_work()
2002 spin_unlock_bh(&dev->mt76.sta_poll_lock); in mt7915_mac_sta_rc_work()
2007 struct mt7915_phy *phy; in mt7915_mac_work() local
2012 phy = mphy->priv; in mt7915_mac_work()
2014 mutex_lock(&mphy->dev->mutex); in mt7915_mac_work()
2017 if (++mphy->mac_work_count == 5) { in mt7915_mac_work()
2018 mphy->mac_work_count = 0; in mt7915_mac_work()
2020 mt7915_mac_update_stats(phy); in mt7915_mac_work()
2021 mt7915_mac_severe_check(phy); in mt7915_mac_work()
2023 if (phy->dev->muru_debug) in mt7915_mac_work()
2024 mt7915_mcu_muru_debug_get(phy); in mt7915_mac_work()
2027 mutex_unlock(&mphy->dev->mutex); in mt7915_mac_work()
2029 mt76_tx_status_check(mphy->dev, false); in mt7915_mac_work()
2031 ieee80211_queue_delayed_work(mphy->hw, &mphy->mac_work, in mt7915_mac_work()
2035 static void mt7915_dfs_stop_radar_detector(struct mt7915_phy *phy) in mt7915_dfs_stop_radar_detector() argument
2037 struct mt7915_dev *dev = phy->dev; in mt7915_dfs_stop_radar_detector()
2039 if (phy->rdd_state & BIT(0)) in mt7915_dfs_stop_radar_detector()
2040 mt76_connac_mcu_rdd_cmd(&dev->mt76, RDD_STOP, 0, in mt7915_dfs_stop_radar_detector()
2042 if (phy->rdd_state & BIT(1)) in mt7915_dfs_stop_radar_detector()
2043 mt76_connac_mcu_rdd_cmd(&dev->mt76, RDD_STOP, 1, in mt7915_dfs_stop_radar_detector()
2051 switch (dev->mt76.region) { in mt7915_dfs_start_rdd()
2064 err = mt76_connac_mcu_rdd_cmd(&dev->mt76, RDD_START, chain, in mt7915_dfs_start_rdd()
2069 if (is_mt7915(&dev->mt76)) { in mt7915_dfs_start_rdd()
2070 err = mt76_connac_mcu_rdd_cmd(&dev->mt76, RDD_SET_WF_ANT, chain, in mt7915_dfs_start_rdd()
2071 0, dev->dbdc_support ? 2 : 0); in mt7915_dfs_start_rdd()
2076 return mt76_connac_mcu_rdd_cmd(&dev->mt76, RDD_DET_MODE, chain, in mt7915_dfs_start_rdd()
2080 static int mt7915_dfs_start_radar_detector(struct mt7915_phy *phy) in mt7915_dfs_start_radar_detector() argument
2082 struct cfg80211_chan_def *chandef = &phy->mt76->chandef; in mt7915_dfs_start_radar_detector()
2083 struct mt7915_dev *dev = phy->dev; in mt7915_dfs_start_radar_detector()
2087 err = mt76_connac_mcu_rdd_cmd(&dev->mt76, RDD_CAC_START, in mt7915_dfs_start_radar_detector()
2088 phy->mt76->band_idx, MT_RX_SEL0, 0); in mt7915_dfs_start_radar_detector()
2092 err = mt7915_dfs_start_rdd(dev, phy->mt76->band_idx); in mt7915_dfs_start_radar_detector()
2096 phy->rdd_state |= BIT(phy->mt76->band_idx); in mt7915_dfs_start_radar_detector()
2098 if (!is_mt7915(&dev->mt76)) in mt7915_dfs_start_radar_detector()
2101 if (chandef->width == NL80211_CHAN_WIDTH_160 || in mt7915_dfs_start_radar_detector()
2102 chandef->width == NL80211_CHAN_WIDTH_80P80) { in mt7915_dfs_start_radar_detector()
2107 phy->rdd_state |= BIT(1); in mt7915_dfs_start_radar_detector()
2114 mt7915_dfs_init_radar_specs(struct mt7915_phy *phy) in mt7915_dfs_init_radar_specs() argument
2117 struct mt7915_dev *dev = phy->dev; in mt7915_dfs_init_radar_specs()
2120 switch (dev->mt76.region) { in mt7915_dfs_init_radar_specs()
2134 return -EINVAL; in mt7915_dfs_init_radar_specs()
2137 for (i = 0; i < ARRAY_SIZE(radar_specs->radar_pattern); i++) { in mt7915_dfs_init_radar_specs()
2139 &radar_specs->radar_pattern[i]); in mt7915_dfs_init_radar_specs()
2144 return mt7915_mcu_set_pulse_th(dev, &radar_specs->pulse_th); in mt7915_dfs_init_radar_specs()
2147 int mt7915_dfs_init_radar_detector(struct mt7915_phy *phy) in mt7915_dfs_init_radar_detector() argument
2149 struct mt7915_dev *dev = phy->dev; in mt7915_dfs_init_radar_detector()
2153 prev_state = phy->mt76->dfs_state; in mt7915_dfs_init_radar_detector()
2154 dfs_state = mt76_phy_dfs_state(phy->mt76); in mt7915_dfs_init_radar_detector()
2160 mt7915_dfs_stop_radar_detector(phy); in mt7915_dfs_init_radar_detector()
2166 err = mt7915_dfs_init_radar_specs(phy); in mt7915_dfs_init_radar_detector()
2170 err = mt7915_dfs_start_radar_detector(phy); in mt7915_dfs_init_radar_detector()
2174 phy->mt76->dfs_state = MT_DFS_STATE_CAC; in mt7915_dfs_init_radar_detector()
2180 err = mt76_connac_mcu_rdd_cmd(&dev->mt76, RDD_CAC_END, in mt7915_dfs_init_radar_detector()
2181 phy->mt76->band_idx, MT_RX_SEL0, 0); in mt7915_dfs_init_radar_detector()
2183 phy->mt76->dfs_state = MT_DFS_STATE_UNKNOWN; in mt7915_dfs_init_radar_detector()
2187 phy->mt76->dfs_state = MT_DFS_STATE_ACTIVE; in mt7915_dfs_init_radar_detector()
2191 err = mt76_connac_mcu_rdd_cmd(&dev->mt76, RDD_NORMAL_START, in mt7915_dfs_init_radar_detector()
2192 phy->mt76->band_idx, MT_RX_SEL0, 0); in mt7915_dfs_init_radar_detector()
2196 if (is_mt7915(&dev->mt76)) { in mt7915_dfs_init_radar_detector()
2197 err = mt76_connac_mcu_rdd_cmd(&dev->mt76, RDD_SET_WF_ANT, in mt7915_dfs_init_radar_detector()
2198 phy->mt76->band_idx, 0, in mt7915_dfs_init_radar_detector()
2199 dev->dbdc_support ? 2 : 0); in mt7915_dfs_init_radar_detector()
2204 mt7915_dfs_stop_radar_detector(phy); in mt7915_dfs_init_radar_detector()
2205 phy->mt76->dfs_state = MT_DFS_STATE_DISABLED; in mt7915_dfs_init_radar_detector()
2211 mt7915_mac_twt_duration_align(int duration) in mt7915_mac_twt_duration_align() argument
2213 return duration << 8; in mt7915_mac_twt_duration_align()
2221 u32 duration = flow->duration << 8; in mt7915_mac_twt_sched_list_add() local
2224 iter = list_first_entry_or_null(&dev->twt_list, in mt7915_mac_twt_sched_list_add()
2226 if (!iter || !iter->sched || iter->start_tsf > duration) { in mt7915_mac_twt_sched_list_add()
2228 list_add(&flow->list, &dev->twt_list); in mt7915_mac_twt_sched_list_add()
2232 list_for_each_entry_safe(iter, iter_next, &dev->twt_list, list) { in mt7915_mac_twt_sched_list_add()
2233 start_tsf = iter->start_tsf + in mt7915_mac_twt_sched_list_add()
2234 mt7915_mac_twt_duration_align(iter->duration); in mt7915_mac_twt_sched_list_add()
2235 if (list_is_last(&iter->list, &dev->twt_list)) in mt7915_mac_twt_sched_list_add()
2238 if (!iter_next->sched || in mt7915_mac_twt_sched_list_add()
2239 iter_next->start_tsf > start_tsf + duration) { in mt7915_mac_twt_sched_list_add()
2240 list_add(&flow->list, &iter->list); in mt7915_mac_twt_sched_list_add()
2246 list_add_tail(&flow->list, &dev->twt_list); in mt7915_mac_twt_sched_list_add()
2254 u64 interval, duration; in mt7915_mac_check_twt_req() local
2259 if (twt->control & IEEE80211_TWT_CONTROL_NEG_TYPE_BROADCAST) in mt7915_mac_check_twt_req()
2260 return -EOPNOTSUPP; in mt7915_mac_check_twt_req()
2263 if (twt->control & IEEE80211_TWT_CONTROL_WAKE_DUR_UNIT) in mt7915_mac_check_twt_req()
2264 return -EOPNOTSUPP; in mt7915_mac_check_twt_req()
2266 twt_agrt = (struct ieee80211_twt_params *)twt->params; in mt7915_mac_check_twt_req()
2269 if (!(twt_agrt->req_type & cpu_to_le16(IEEE80211_TWT_REQTYPE_IMPLICIT))) in mt7915_mac_check_twt_req()
2270 return -EOPNOTSUPP; in mt7915_mac_check_twt_req()
2273 le16_to_cpu(twt_agrt->req_type)); in mt7915_mac_check_twt_req()
2274 mantissa = le16_to_cpu(twt_agrt->mantissa); in mt7915_mac_check_twt_req()
2275 duration = twt_agrt->min_twt_dur << 8; in mt7915_mac_check_twt_req()
2278 if (interval < duration) in mt7915_mac_check_twt_req()
2279 return -EOPNOTSUPP; in mt7915_mac_check_twt_req()
2288 u16 type = le16_to_cpu(twt_agrt->req_type); in mt7915_mac_twt_param_equal()
2296 if (!(msta->twt.flowid_mask & BIT(i))) in mt7915_mac_twt_param_equal()
2299 f = &msta->twt.flow[i]; in mt7915_mac_twt_param_equal()
2300 if (f->duration == twt_agrt->min_twt_dur && in mt7915_mac_twt_param_equal()
2301 f->mantissa == twt_agrt->mantissa && in mt7915_mac_twt_param_equal()
2302 f->exp == exp && in mt7915_mac_twt_param_equal()
2303 f->protection == !!(type & IEEE80211_TWT_REQTYPE_PROTECTION) && in mt7915_mac_twt_param_equal()
2304 f->flowtype == !!(type & IEEE80211_TWT_REQTYPE_FLOWTYPE) && in mt7915_mac_twt_param_equal()
2305 f->trigger == !!(type & IEEE80211_TWT_REQTYPE_TRIGGER)) in mt7915_mac_twt_param_equal()
2317 struct mt7915_sta *msta = (struct mt7915_sta *)sta->drv_priv; in mt7915_mac_add_twt_setup()
2318 struct ieee80211_twt_params *twt_agrt = (void *)twt->params; in mt7915_mac_add_twt_setup()
2319 u16 req_type = le16_to_cpu(twt_agrt->req_type); in mt7915_mac_add_twt_setup()
2329 mutex_lock(&dev->mt76.mutex); in mt7915_mac_add_twt_setup()
2331 if (dev->twt.n_agrt == MT7915_MAX_TWT_AGRT) in mt7915_mac_add_twt_setup()
2334 if (hweight8(msta->twt.flowid_mask) == ARRAY_SIZE(msta->twt.flow)) in mt7915_mac_add_twt_setup()
2337 if (twt_agrt->min_twt_dur < MT7915_MIN_TWT_DUR) { in mt7915_mac_add_twt_setup()
2339 twt_agrt->min_twt_dur = MT7915_MIN_TWT_DUR; in mt7915_mac_add_twt_setup()
2343 flowid = ffs(~msta->twt.flowid_mask) - 1; in mt7915_mac_add_twt_setup()
2344 twt_agrt->req_type &= ~cpu_to_le16(IEEE80211_TWT_REQTYPE_FLOWID); in mt7915_mac_add_twt_setup()
2345 twt_agrt->req_type |= le16_encode_bits(flowid, in mt7915_mac_add_twt_setup()
2348 table_id = ffs(~dev->twt.table_mask) - 1; in mt7915_mac_add_twt_setup()
2355 flow = &msta->twt.flow[flowid]; in mt7915_mac_add_twt_setup()
2357 INIT_LIST_HEAD(&flow->list); in mt7915_mac_add_twt_setup()
2358 flow->wcid = msta->wcid.idx; in mt7915_mac_add_twt_setup()
2359 flow->table_id = table_id; in mt7915_mac_add_twt_setup()
2360 flow->id = flowid; in mt7915_mac_add_twt_setup()
2361 flow->duration = twt_agrt->min_twt_dur; in mt7915_mac_add_twt_setup()
2362 flow->mantissa = twt_agrt->mantissa; in mt7915_mac_add_twt_setup()
2363 flow->exp = exp; in mt7915_mac_add_twt_setup()
2364 flow->protection = !!(req_type & IEEE80211_TWT_REQTYPE_PROTECTION); in mt7915_mac_add_twt_setup()
2365 flow->flowtype = !!(req_type & IEEE80211_TWT_REQTYPE_FLOWTYPE); in mt7915_mac_add_twt_setup()
2366 flow->trigger = !!(req_type & IEEE80211_TWT_REQTYPE_TRIGGER); in mt7915_mac_add_twt_setup()
2370 u64 interval = (u64)le16_to_cpu(twt_agrt->mantissa) << exp; in mt7915_mac_add_twt_setup()
2374 flow->sched = true; in mt7915_mac_add_twt_setup()
2375 flow->start_tsf = mt7915_mac_twt_sched_list_add(dev, flow); in mt7915_mac_add_twt_setup()
2376 curr_tsf = __mt7915_get_tsf(hw, msta->vif); in mt7915_mac_add_twt_setup()
2377 div_u64_rem(curr_tsf - flow->start_tsf, interval, &rem); in mt7915_mac_add_twt_setup()
2378 flow_tsf = curr_tsf + interval - rem; in mt7915_mac_add_twt_setup()
2379 twt_agrt->twt = cpu_to_le64(flow_tsf); in mt7915_mac_add_twt_setup()
2381 list_add_tail(&flow->list, &dev->twt_list); in mt7915_mac_add_twt_setup()
2383 flow->tsf = le64_to_cpu(twt_agrt->twt); in mt7915_mac_add_twt_setup()
2385 if (mt7915_mcu_twt_agrt_update(dev, msta->vif, flow, MCU_TWT_AGRT_ADD)) in mt7915_mac_add_twt_setup()
2389 dev->twt.table_mask |= BIT(table_id); in mt7915_mac_add_twt_setup()
2390 msta->twt.flowid_mask |= BIT(flowid); in mt7915_mac_add_twt_setup()
2391 dev->twt.n_agrt++; in mt7915_mac_add_twt_setup()
2394 mutex_unlock(&dev->mt76.mutex); in mt7915_mac_add_twt_setup()
2396 twt_agrt->req_type &= ~cpu_to_le16(IEEE80211_TWT_REQTYPE_SETUP_CMD); in mt7915_mac_add_twt_setup()
2397 twt_agrt->req_type |= in mt7915_mac_add_twt_setup()
2399 twt->control = (twt->control & IEEE80211_TWT_CONTROL_WAKE_DUR_UNIT) | in mt7915_mac_add_twt_setup()
2400 (twt->control & IEEE80211_TWT_CONTROL_RX_DISABLED); in mt7915_mac_add_twt_setup()
2409 lockdep_assert_held(&dev->mt76.mutex); in mt7915_mac_twt_teardown_flow()
2411 if (flowid >= ARRAY_SIZE(msta->twt.flow)) in mt7915_mac_twt_teardown_flow()
2414 if (!(msta->twt.flowid_mask & BIT(flowid))) in mt7915_mac_twt_teardown_flow()
2417 flow = &msta->twt.flow[flowid]; in mt7915_mac_twt_teardown_flow()
2418 if (mt7915_mcu_twt_agrt_update(dev, msta->vif, flow, in mt7915_mac_twt_teardown_flow()
2422 list_del_init(&flow->list); in mt7915_mac_twt_teardown_flow()
2423 msta->twt.flowid_mask &= ~BIT(flowid); in mt7915_mac_twt_teardown_flow()
2424 dev->twt.table_mask &= ~BIT(flow->table_id); in mt7915_mac_twt_teardown_flow()
2425 dev->twt.n_agrt--; in mt7915_mac_twt_teardown_flow()