Lines Matching +full:phy +full:- +full:reset +full:- +full:duration

1 // SPDX-License-Identifier: ISC
14 #define to_rssi(field, rcpi) ((FIELD_GET(field, rcpi) - 220) / 2)
17 .pulse_th = { 110, -10, -80, 40, 5200, 128, 5200 },
31 .pulse_th = { 110, -10, -80, 40, 5200, 128, 5200 },
42 .pulse_th = { 110, -10, -80, 40, 5200, 128, 5200 },
61 if (idx >= ARRAY_SIZE(dev->mt76.wcid)) in mt7996_rx_get_wcid()
64 wcid = rcu_dereference(dev->mt76.wcid[idx]); in mt7996_rx_get_wcid()
68 if (!wcid->sta) in mt7996_rx_get_wcid()
72 if (!sta->vif) in mt7996_rx_get_wcid()
75 return &sta->vif->sta.wcid; in mt7996_rx_get_wcid()
109 spin_lock_bh(&dev->mt76.sta_poll_lock); in mt7996_mac_sta_poll()
110 list_splice_init(&dev->mt76.sta_poll_list, &sta_poll_list); in mt7996_mac_sta_poll()
111 spin_unlock_bh(&dev->mt76.sta_poll_lock); in mt7996_mac_sta_poll()
121 spin_lock_bh(&dev->mt76.sta_poll_lock); in mt7996_mac_sta_poll()
123 spin_unlock_bh(&dev->mt76.sta_poll_lock); in mt7996_mac_sta_poll()
128 list_del_init(&msta->wcid.poll_list); in mt7996_mac_sta_poll()
129 spin_unlock_bh(&dev->mt76.sta_poll_lock); in mt7996_mac_sta_poll()
131 idx = msta->wcid.idx; in mt7996_mac_sta_poll()
137 u32 tx_last = msta->airtime_ac[i]; in mt7996_mac_sta_poll()
138 u32 rx_last = msta->airtime_ac[i + 4]; in mt7996_mac_sta_poll()
140 msta->airtime_ac[i] = mt76_rr(dev, addr); in mt7996_mac_sta_poll()
141 msta->airtime_ac[i + 4] = mt76_rr(dev, addr + 4); in mt7996_mac_sta_poll()
143 tx_time[i] = msta->airtime_ac[i] - tx_last; in mt7996_mac_sta_poll()
144 rx_time[i] = msta->airtime_ac[i + 4] - rx_last; in mt7996_mac_sta_poll()
155 memset(msta->airtime_ac, 0, sizeof(msta->airtime_ac)); in mt7996_mac_sta_poll()
158 if (!msta->wcid.sta) in mt7996_mac_sta_poll()
184 msta->ack_signal = in mt7996_mac_sta_poll()
185 mt76_rx_signal(msta->vif->phy->mt76->antenna_mask, rssi); in mt7996_mac_sta_poll()
187 ewma_avg_signal_add(&msta->avg_ack_signal, -msta->ack_signal); in mt7996_mac_sta_poll()
196 struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; in mt7996_mac_enable_rtscts()
199 addr = mt7996_mac_wtbl_lmac_addr(dev, mvif->sta.wcid.idx, 5); in mt7996_mac_enable_rtscts()
209 struct mt76_rx_status *status = (struct mt76_rx_status *)skb->cb; in mt7996_reverse_frag0_hdr_trans()
210 struct ethhdr *eth_hdr = (struct ethhdr *)(skb->data + hdr_gap); in mt7996_reverse_frag0_hdr_trans()
211 struct mt7996_sta *msta = (struct mt7996_sta *)status->wcid; in mt7996_reverse_frag0_hdr_trans()
212 __le32 *rxd = (__le32 *)skb->data; in mt7996_reverse_frag0_hdr_trans()
220 return -EINVAL; in mt7996_reverse_frag0_hdr_trans()
223 return -EINVAL; in mt7996_reverse_frag0_hdr_trans()
225 if (!msta || !msta->vif) in mt7996_reverse_frag0_hdr_trans()
226 return -EINVAL; in mt7996_reverse_frag0_hdr_trans()
229 vif = container_of((void *)msta->vif, struct ieee80211_vif, drv_priv); in mt7996_reverse_frag0_hdr_trans()
237 ether_addr_copy(hdr.addr1, vif->addr); in mt7996_reverse_frag0_hdr_trans()
238 ether_addr_copy(hdr.addr2, sta->addr); in mt7996_reverse_frag0_hdr_trans()
242 ether_addr_copy(hdr.addr3, vif->bss_conf.bssid); in mt7996_reverse_frag0_hdr_trans()
245 ether_addr_copy(hdr.addr3, eth_hdr->h_source); in mt7996_reverse_frag0_hdr_trans()
248 ether_addr_copy(hdr.addr3, eth_hdr->h_dest); in mt7996_reverse_frag0_hdr_trans()
251 ether_addr_copy(hdr.addr3, eth_hdr->h_dest); in mt7996_reverse_frag0_hdr_trans()
252 ether_addr_copy(hdr.addr4, eth_hdr->h_source); in mt7996_reverse_frag0_hdr_trans()
255 return -EINVAL; in mt7996_reverse_frag0_hdr_trans()
258 skb_pull(skb, hdr_gap + sizeof(struct ethhdr) - 2); in mt7996_reverse_frag0_hdr_trans()
259 if (eth_hdr->h_proto == cpu_to_be16(ETH_P_AARP) || in mt7996_reverse_frag0_hdr_trans()
260 eth_hdr->h_proto == cpu_to_be16(ETH_P_IPX)) in mt7996_reverse_frag0_hdr_trans()
262 else if (be16_to_cpu(eth_hdr->h_proto) >= ETH_P_802_3_MIN) in mt7996_reverse_frag0_hdr_trans()
281 memcpy(skb_push(skb, sizeof(hdr) - 6), &hdr, sizeof(hdr) - 6); in mt7996_reverse_frag0_hdr_trans()
315 i = mt76_get_rate(&dev->mt76, sband, i, cck); in mt7996_mac_fill_rx_rate()
319 status->encoding = RX_ENC_HT; in mt7996_mac_fill_rx_rate()
321 status->enc_flags |= RX_ENC_FLAG_SHORT_GI; in mt7996_mac_fill_rx_rate()
323 return -EINVAL; in mt7996_mac_fill_rx_rate()
326 status->nss = nss; in mt7996_mac_fill_rx_rate()
327 status->encoding = RX_ENC_VHT; in mt7996_mac_fill_rx_rate()
329 status->enc_flags |= RX_ENC_FLAG_SHORT_GI; in mt7996_mac_fill_rx_rate()
331 return -EINVAL; in mt7996_mac_fill_rx_rate()
337 status->nss = nss; in mt7996_mac_fill_rx_rate()
338 status->encoding = RX_ENC_HE; in mt7996_mac_fill_rx_rate()
342 status->he_gi = gi; in mt7996_mac_fill_rx_rate()
344 status->he_dcm = dcm; in mt7996_mac_fill_rx_rate()
349 status->nss = nss; in mt7996_mac_fill_rx_rate()
350 status->encoding = RX_ENC_EHT; in mt7996_mac_fill_rx_rate()
354 status->eht.gi = gi; in mt7996_mac_fill_rx_rate()
357 return -EINVAL; in mt7996_mac_fill_rx_rate()
359 status->rate_idx = i; in mt7996_mac_fill_rx_rate()
367 status->bw = RATE_INFO_BW_HE_RU; in mt7996_mac_fill_rx_rate()
368 status->he_ru = in mt7996_mac_fill_rx_rate()
371 status->bw = RATE_INFO_BW_40; in mt7996_mac_fill_rx_rate()
375 status->bw = RATE_INFO_BW_80; in mt7996_mac_fill_rx_rate()
378 status->bw = RATE_INFO_BW_160; in mt7996_mac_fill_rx_rate()
380 /* rxv reports bw 320-1 and 320-2 separately */ in mt7996_mac_fill_rx_rate()
383 status->bw = RATE_INFO_BW_320; in mt7996_mac_fill_rx_rate()
386 return -EINVAL; in mt7996_mac_fill_rx_rate()
389 status->enc_flags |= RX_ENC_FLAG_STBC_MASK * stbc; in mt7996_mac_fill_rx_rate()
391 status->enc_flags |= RX_ENC_FLAG_SHORT_GI; in mt7996_mac_fill_rx_rate()
404 if (!msta || !msta->vif) in mt7996_wed_check_ppe()
413 vif = container_of((void *)msta->vif, struct ieee80211_vif, in mt7996_wed_check_ppe()
416 skb->dev = wdev->netdev; in mt7996_wed_check_ppe()
418 mtk_wed_device_ppe_check(&dev->mt76.mmio.wed, skb, in mt7996_wed_check_ppe()
427 struct mt76_rx_status *status = (struct mt76_rx_status *)skb->cb; in mt7996_mac_fill_rx()
428 struct mt76_phy *mphy = &dev->mt76.phy; in mt7996_mac_fill_rx()
429 struct mt7996_phy *phy = &dev->phy; in mt7996_mac_fill_rx() local
431 __le32 *rxd = (__le32 *)skb->data; in mt7996_mac_fill_rx()
439 u32 csum_status = *(u32 *)skb->cb; in mt7996_mac_fill_rx()
453 hw_aggr = status->aggr; in mt7996_mac_fill_rx()
457 mphy = dev->mt76.phys[band_idx]; in mt7996_mac_fill_rx()
458 phy = mphy->priv; in mt7996_mac_fill_rx()
459 status->phy_idx = mphy->band_idx; in mt7996_mac_fill_rx()
461 if (!test_bit(MT76_STATE_RUNNING, &mphy->state)) in mt7996_mac_fill_rx()
462 return -EINVAL; in mt7996_mac_fill_rx()
465 return -EINVAL; in mt7996_mac_fill_rx()
469 return -EINVAL; in mt7996_mac_fill_rx()
473 status->flag |= RX_FLAG_ONLY_MONITOR; in mt7996_mac_fill_rx()
477 status->wcid = mt7996_rx_get_wcid(dev, idx, unicast); in mt7996_mac_fill_rx()
479 if (status->wcid) { in mt7996_mac_fill_rx()
480 msta = container_of(status->wcid, struct mt7996_sta, wcid); in mt7996_mac_fill_rx()
481 spin_lock_bh(&dev->mt76.sta_poll_lock); in mt7996_mac_fill_rx()
482 if (list_empty(&msta->wcid.poll_list)) in mt7996_mac_fill_rx()
483 list_add_tail(&msta->wcid.poll_list, in mt7996_mac_fill_rx()
484 &dev->mt76.sta_poll_list); in mt7996_mac_fill_rx()
485 spin_unlock_bh(&dev->mt76.sta_poll_lock); in mt7996_mac_fill_rx()
488 status->freq = mphy->chandef.chan->center_freq; in mt7996_mac_fill_rx()
489 status->band = mphy->chandef.chan->band; in mt7996_mac_fill_rx()
490 if (status->band == NL80211_BAND_5GHZ) in mt7996_mac_fill_rx()
491 sband = &mphy->sband_5g.sband; in mt7996_mac_fill_rx()
492 else if (status->band == NL80211_BAND_6GHZ) in mt7996_mac_fill_rx()
493 sband = &mphy->sband_6g.sband; in mt7996_mac_fill_rx()
495 sband = &mphy->sband_2g.sband; in mt7996_mac_fill_rx()
497 if (!sband->channels) in mt7996_mac_fill_rx()
498 return -EINVAL; in mt7996_mac_fill_rx()
502 skb->ip_summed = CHECKSUM_UNNECESSARY; in mt7996_mac_fill_rx()
505 status->flag |= RX_FLAG_FAILED_FCS_CRC; in mt7996_mac_fill_rx()
508 status->flag |= RX_FLAG_MMIC_ERROR; in mt7996_mac_fill_rx()
512 status->flag |= RX_FLAG_DECRYPTED; in mt7996_mac_fill_rx()
513 status->flag |= RX_FLAG_IV_STRIPPED; in mt7996_mac_fill_rx()
514 status->flag |= RX_FLAG_MMIC_STRIPPED | RX_FLAG_MIC_STRIPPED; in mt7996_mac_fill_rx()
520 return -EINVAL; in mt7996_mac_fill_rx()
532 if ((u8 *)rxd - skb->data >= skb->len) in mt7996_mac_fill_rx()
533 return -EINVAL; in mt7996_mac_fill_rx()
539 if (status->flag & RX_FLAG_DECRYPTED) { in mt7996_mac_fill_rx()
551 status->iv[0] = data[5]; in mt7996_mac_fill_rx()
552 status->iv[1] = data[4]; in mt7996_mac_fill_rx()
553 status->iv[2] = data[3]; in mt7996_mac_fill_rx()
554 status->iv[3] = data[2]; in mt7996_mac_fill_rx()
555 status->iv[4] = data[1]; in mt7996_mac_fill_rx()
556 status->iv[5] = data[0]; in mt7996_mac_fill_rx()
563 if ((u8 *)rxd - skb->data >= skb->len) in mt7996_mac_fill_rx()
564 return -EINVAL; in mt7996_mac_fill_rx()
568 status->timestamp = le32_to_cpu(rxd[0]); in mt7996_mac_fill_rx()
569 status->flag |= RX_FLAG_MACTIME_START; in mt7996_mac_fill_rx()
572 status->flag |= RX_FLAG_AMPDU_DETAILS; in mt7996_mac_fill_rx()
574 /* all subframes of an A-MPDU have the same timestamp */ in mt7996_mac_fill_rx()
575 if (phy->rx_ampdu_ts != status->timestamp) { in mt7996_mac_fill_rx()
576 if (!++phy->ampdu_ref) in mt7996_mac_fill_rx()
577 phy->ampdu_ref++; in mt7996_mac_fill_rx()
579 phy->rx_ampdu_ts = status->timestamp; in mt7996_mac_fill_rx()
581 status->ampdu_ref = phy->ampdu_ref; in mt7996_mac_fill_rx()
585 if ((u8 *)rxd - skb->data >= skb->len) in mt7996_mac_fill_rx()
586 return -EINVAL; in mt7996_mac_fill_rx()
589 /* RXD Group 3 - P-RXV */ in mt7996_mac_fill_rx()
596 if ((u8 *)rxd - skb->data >= skb->len) in mt7996_mac_fill_rx()
597 return -EINVAL; in mt7996_mac_fill_rx()
601 status->chains = mphy->antenna_mask; in mt7996_mac_fill_rx()
602 status->chain_signal[0] = to_rssi(MT_PRXV_RCPI0, v3); in mt7996_mac_fill_rx()
603 status->chain_signal[1] = to_rssi(MT_PRXV_RCPI1, v3); in mt7996_mac_fill_rx()
604 status->chain_signal[2] = to_rssi(MT_PRXV_RCPI2, v3); in mt7996_mac_fill_rx()
605 status->chain_signal[3] = to_rssi(MT_PRXV_RCPI3, v3); in mt7996_mac_fill_rx()
607 /* RXD Group 5 - C-RXV */ in mt7996_mac_fill_rx()
610 if ((u8 *)rxd - skb->data >= skb->len) in mt7996_mac_fill_rx()
611 return -EINVAL; in mt7996_mac_fill_rx()
620 status->amsdu = !!amsdu_info; in mt7996_mac_fill_rx()
621 if (status->amsdu) { in mt7996_mac_fill_rx()
622 status->first_amsdu = amsdu_info == MT_RXD4_FIRST_AMSDU_FRAME; in mt7996_mac_fill_rx()
623 status->last_amsdu = amsdu_info == MT_RXD4_LAST_AMSDU_FRAME; in mt7996_mac_fill_rx()
626 hdr_gap = (u8 *)rxd - skb->data + 2 * remove_pad; in mt7996_mac_fill_rx()
629 return -EINVAL; in mt7996_mac_fill_rx()
635 if (!hdr_trans && status->amsdu && !(ieee80211_has_a4(fc) && is_mesh)) { in mt7996_mac_fill_rx()
639 * the hardware will insert an extra 2-byte field in mt7996_mac_fill_rx()
641 * type field. This happens either when the LLC-SNAP in mt7996_mac_fill_rx()
646 if (get_unaligned_be16(skb->data + pad_start) == ETH_P_8021Q) in mt7996_mac_fill_rx()
653 memmove(skb->data + 2, skb->data, pad_start); in mt7996_mac_fill_rx()
668 fc = hdr->frame_control; in mt7996_mac_fill_rx()
672 seq_ctrl = le16_to_cpu(hdr->seq_ctrl); in mt7996_mac_fill_rx()
676 * de-amsdu, so here needs to clear amsdu present bit in mt7996_mac_fill_rx()
679 if (ieee80211_has_a4(fc) && is_mesh && status->amsdu) in mt7996_mac_fill_rx()
683 status->flag |= RX_FLAG_8023; in mt7996_mac_fill_rx()
684 mt7996_wed_check_ppe(dev, &dev->mt76.q_rx[q], msta, skb, in mt7996_mac_fill_rx()
688 if (rxv && mode >= MT_PHY_TYPE_HE_SU && !(status->flag & RX_FLAG_8023)) in mt7996_mac_fill_rx()
691 if (!status->wcid || !ieee80211_is_data_qos(fc) || hw_aggr) in mt7996_mac_fill_rx()
694 status->aggr = unicast && in mt7996_mac_fill_rx()
696 status->qos_ctl = qos_ctl; in mt7996_mac_fill_rx()
697 status->seqno = IEEE80211_SEQ_TO_SN(seq_ctrl); in mt7996_mac_fill_rx()
706 u8 tid = skb->priority & IEEE80211_QOS_CTL_TID_MASK; in mt7996_mac_write_txwi_8023()
712 if (wcid->sta) { in mt7996_mac_write_txwi_8023()
716 wmm = sta->wme; in mt7996_mac_write_txwi_8023()
722 ethertype = get_unaligned_be16(&skb->data[12]); in mt7996_mac_write_txwi_8023()
736 if (wcid->amsdu) in mt7996_mac_write_txwi_8023()
744 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; in mt7996_mac_write_txwi_80211()
745 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data; in mt7996_mac_write_txwi_80211()
747 bool multicast = is_multicast_ether_addr(hdr->addr1); in mt7996_mac_write_txwi_80211()
748 u8 tid = skb->priority & IEEE80211_QOS_CTL_TID_MASK; in mt7996_mac_write_txwi_80211()
749 __le16 fc = hdr->frame_control, sc = hdr->seq_ctrl; in mt7996_mac_write_txwi_80211()
754 mgmt->u.action.category == WLAN_CATEGORY_BACK && in mt7996_mac_write_txwi_80211()
755 mgmt->u.action.u.addba_req.action_code == WLAN_ACTION_ADDBA_REQ) in mt7996_mac_write_txwi_80211()
757 else if (ieee80211_is_mgmt(hdr->frame_control)) in mt7996_mac_write_txwi_80211()
766 info->flags & IEEE80211_TX_CTL_USE_MINRATE) in mt7996_mac_write_txwi_80211()
770 key->cipher == WLAN_CIPHER_SUITE_AES_CMAC) { in mt7996_mac_write_txwi_80211()
800 if (info->flags & IEEE80211_TX_CTL_INJECTED) { in mt7996_mac_write_txwi_80211()
803 if (ieee80211_is_back_req(hdr->frame_control)) { in mt7996_mac_write_txwi_80211()
806 bar = (struct ieee80211_bar *)skb->data; in mt7996_mac_write_txwi_80211()
807 seqno = le16_to_cpu(bar->start_seq_num); in mt7996_mac_write_txwi_80211()
823 struct ieee80211_vif *vif = info->control.vif; in mt7996_mac_write_txwi()
824 u8 band_idx = (info->hw_queue & MT_TX_HW_QUEUE_PHY) >> 2; in mt7996_mac_write_txwi()
826 bool is_8023 = info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP; in mt7996_mac_write_txwi()
835 mvif = vif ? (struct mt76_vif *)vif->drv_priv : NULL; in mt7996_mac_write_txwi()
837 omac_idx = mvif->omac_idx; in mt7996_mac_write_txwi()
838 wmm_idx = mvif->wmm_idx; in mt7996_mac_write_txwi()
839 band_idx = mvif->band_idx; in mt7996_mac_write_txwi()
857 val = FIELD_PREP(MT_TXD0_TX_BYTES, skb->len + MT_TXD_SIZE) | in mt7996_mac_write_txwi()
862 val = FIELD_PREP(MT_TXD1_WLAN_IDX, wcid->idx) | in mt7996_mac_write_txwi()
875 if (info->flags & IEEE80211_TX_CTL_NO_ACK) in mt7996_mac_write_txwi()
887 if (is_mt7996(&dev->mt76)) in mt7996_mac_write_txwi()
900 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; in mt7996_mac_write_txwi()
901 bool mcast = ieee80211_is_data(hdr->frame_control) && in mt7996_mac_write_txwi()
902 is_multicast_ether_addr(hdr->addr1); in mt7996_mac_write_txwi()
906 if (mcast && mvif->mcast_rates_idx) in mt7996_mac_write_txwi()
907 idx = mvif->mcast_rates_idx; in mt7996_mac_write_txwi()
908 else if (beacon && mvif->beacon_rates_idx) in mt7996_mac_write_txwi()
909 idx = mvif->beacon_rates_idx; in mt7996_mac_write_txwi()
911 idx = mvif->basic_rates_idx; in mt7996_mac_write_txwi()
925 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx_info->skb->data; in mt7996_tx_prepare_skb()
927 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx_info->skb); in mt7996_tx_prepare_skb()
928 struct ieee80211_key_conf *key = info->control.hw_key; in mt7996_tx_prepare_skb()
929 struct ieee80211_vif *vif = info->control.vif; in mt7996_tx_prepare_skb()
932 int id, i, pid, nbuf = tx_info->nbuf - 1; in mt7996_tx_prepare_skb()
933 bool is_8023 = info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP; in mt7996_tx_prepare_skb()
936 if (unlikely(tx_info->skb->len <= ETH_HLEN)) in mt7996_tx_prepare_skb()
937 return -EINVAL; in mt7996_tx_prepare_skb()
940 wcid = &dev->mt76.global_wcid; in mt7996_tx_prepare_skb()
942 t = (struct mt76_txwi_cache *)(txwi + mdev->drv->txwi_size); in mt7996_tx_prepare_skb()
943 t->skb = tx_info->skb; in mt7996_tx_prepare_skb()
949 pid = mt76_tx_status_skb_add(mdev, wcid, tx_info->skb); in mt7996_tx_prepare_skb()
950 mt7996_mac_write_txwi(dev, txwi_ptr, tx_info->skb, wcid, key, in mt7996_tx_prepare_skb()
957 len = FIELD_PREP(MT_TXP_BUF_LEN, tx_info->buf[i + 1].len); in mt7996_tx_prepare_skb()
960 tx_info->buf[i + 1].addr >> 32); in mt7996_tx_prepare_skb()
963 txp->fw.buf[i] = cpu_to_le32(tx_info->buf[i + 1].addr); in mt7996_tx_prepare_skb()
964 txp->fw.len[i] = cpu_to_le16(len); in mt7996_tx_prepare_skb()
966 txp->fw.nbuf = nbuf; in mt7996_tx_prepare_skb()
968 txp->fw.flags = in mt7996_tx_prepare_skb()
972 txp->fw.flags |= cpu_to_le16(MT_CT_INFO_NONE_CIPHER_FRAME); in mt7996_tx_prepare_skb()
974 if (!is_8023 && ieee80211_is_mgmt(hdr->frame_control)) in mt7996_tx_prepare_skb()
975 txp->fw.flags |= cpu_to_le16(MT_CT_INFO_MGMT_FRAME); in mt7996_tx_prepare_skb()
978 struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv; in mt7996_tx_prepare_skb()
980 txp->fw.bss_idx = mvif->mt76.idx; in mt7996_tx_prepare_skb()
983 txp->fw.token = cpu_to_le16(id); in mt7996_tx_prepare_skb()
984 txp->fw.rept_wds_wcid = cpu_to_le16(sta ? wcid->idx : 0xfff); in mt7996_tx_prepare_skb()
986 tx_info->skb = NULL; in mt7996_tx_prepare_skb()
989 tx_info->buf[1].len = MT_CT_PARSE_LEN; in mt7996_tx_prepare_skb()
990 tx_info->buf[1].skip_unmap = true; in mt7996_tx_prepare_skb()
991 tx_info->nbuf = MT_CT_DMA_BUF_NUM; in mt7996_tx_prepare_skb()
1012 txp->token = cpu_to_le16(token_id); in mt7996_wed_init_buf()
1013 txp->nbuf = 1; in mt7996_wed_init_buf()
1014 txp->buf[0] = cpu_to_le32(phys + MT_TXD_SIZE + sizeof(*txp)); in mt7996_wed_init_buf()
1024 bool is_8023 = info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP; in mt7996_tx_check_aggr()
1027 if (!sta || !(sta->deflink.ht_cap.ht_supported || sta->deflink.he_cap.has_he)) in mt7996_tx_check_aggr()
1030 tid = skb->priority & IEEE80211_QOS_CTL_TID_MASK; in mt7996_tx_check_aggr()
1036 (sta->wme ? IEEE80211_STYPE_QOS_DATA : IEEE80211_STYPE_DATA); in mt7996_tx_check_aggr()
1043 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; in mt7996_tx_check_aggr()
1045 fc = le16_to_cpu(hdr->frame_control) & in mt7996_tx_check_aggr()
1052 msta = (struct mt7996_sta *)sta->drv_priv; in mt7996_tx_check_aggr()
1053 if (!test_and_set_bit(tid, &msta->wcid.ampdu_state)) in mt7996_tx_check_aggr()
1061 struct mt76_dev *mdev = &dev->mt76; in mt7996_txwi_free()
1067 if (!t->skb) in mt7996_txwi_free()
1072 wcid = (struct mt76_wcid *)sta->drv_priv; in mt7996_txwi_free()
1073 wcid_idx = wcid->idx; in mt7996_txwi_free()
1075 if (likely(t->skb->protocol != cpu_to_be16(ETH_P_PAE))) in mt7996_txwi_free()
1076 mt7996_tx_check_aggr(sta, t->skb); in mt7996_txwi_free()
1081 __mt76_tx_complete_skb(mdev, wcid_idx, t->skb, free_list); in mt7996_txwi_free()
1084 t->skb = NULL; in mt7996_txwi_free()
1092 struct mt76_dev *mdev = &dev->mt76; in mt7996_mac_tx_free()
1093 struct mt76_phy *phy2 = mdev->phys[MT_BAND1]; in mt7996_mac_tx_free()
1094 struct mt76_phy *phy3 = mdev->phys[MT_BAND2]; in mt7996_mac_tx_free()
1105 mt76_queue_tx_cleanup(dev, dev->mphy.q_tx[MT_TXQ_PSD], false); in mt7996_mac_tx_free()
1106 mt76_queue_tx_cleanup(dev, dev->mphy.q_tx[MT_TXQ_BE], false); in mt7996_mac_tx_free()
1108 mt76_queue_tx_cleanup(dev, phy2->q_tx[MT_TXQ_PSD], false); in mt7996_mac_tx_free()
1109 mt76_queue_tx_cleanup(dev, phy2->q_tx[MT_TXQ_BE], false); in mt7996_mac_tx_free()
1112 mt76_queue_tx_cleanup(dev, phy3->q_tx[MT_TXQ_PSD], false); in mt7996_mac_tx_free()
1113 mt76_queue_tx_cleanup(dev, phy3->q_tx[MT_TXQ_BE], false); in mt7996_mac_tx_free()
1135 wcid = rcu_dereference(dev->mt76.wcid[idx]); in mt7996_mac_tx_free()
1141 spin_lock_bh(&mdev->sta_poll_lock); in mt7996_mac_tx_free()
1142 if (list_empty(&msta->wcid.poll_list)) in mt7996_mac_tx_free()
1143 list_add_tail(&msta->wcid.poll_list, in mt7996_mac_tx_free()
1144 &mdev->sta_poll_list); in mt7996_mac_tx_free()
1145 spin_unlock_bh(&mdev->sta_poll_lock); in mt7996_mac_tx_free()
1154 FIELD_GET(MT_TXFREE_INFO_COUNT, info) - 1; in mt7996_mac_tx_free()
1158 wcid->stats.tx_retries += tx_retries; in mt7996_mac_tx_free()
1159 wcid->stats.tx_failed += tx_failed; in mt7996_mac_tx_free()
1180 mt76_set_tx_blocked(&dev->mt76, false); in mt7996_mac_tx_free()
1182 mt76_worker_schedule(&dev->mt76.tx_worker); in mt7996_mac_tx_free()
1194 struct mt76_sta_stats *stats = &wcid->stats; in mt7996_mac_add_txs_skb()
1196 struct mt76_dev *mdev = &dev->mt76; in mt7996_mac_add_txs_skb()
1215 info->flags |= IEEE80211_TX_STAT_ACK; in mt7996_mac_add_txs_skb()
1217 info->status.ampdu_len = 1; in mt7996_mac_add_txs_skb()
1218 info->status.ampdu_ack_len = in mt7996_mac_add_txs_skb()
1219 !!(info->flags & IEEE80211_TX_STAT_ACK); in mt7996_mac_add_txs_skb()
1221 info->status.rates[0].idx = -1; in mt7996_mac_add_txs_skb()
1225 if (mtk_wed_device_active(&dev->mt76.mmio.wed) && wcid->sta) { in mt7996_mac_add_txs_skb()
1243 if (rate.nss - 1 < ARRAY_SIZE(stats->tx_nss)) in mt7996_mac_add_txs_skb()
1244 stats->tx_nss[rate.nss - 1]++; in mt7996_mac_add_txs_skb()
1245 if (rate.mcs < ARRAY_SIZE(stats->tx_mcs)) in mt7996_mac_add_txs_skb()
1246 stats->tx_mcs[rate.mcs]++; in mt7996_mac_add_txs_skb()
1254 mphy = mt76_dev_phy(mdev, wcid->phy_idx); in mt7996_mac_add_txs_skb()
1256 if (mphy->chandef.chan->band == NL80211_BAND_5GHZ) in mt7996_mac_add_txs_skb()
1257 sband = &mphy->sband_5g.sband; in mt7996_mac_add_txs_skb()
1258 else if (mphy->chandef.chan->band == NL80211_BAND_6GHZ) in mt7996_mac_add_txs_skb()
1259 sband = &mphy->sband_6g.sband; in mt7996_mac_add_txs_skb()
1261 sband = &mphy->sband_2g.sband; in mt7996_mac_add_txs_skb()
1263 rate.mcs = mt76_get_rate(mphy->dev, sband, rate.mcs, cck); in mt7996_mac_add_txs_skb()
1264 rate.legacy = sband->bitrates[rate.mcs].bitrate; in mt7996_mac_add_txs_skb()
1272 if (wcid->rate.flags & RATE_INFO_FLAGS_SHORT_GI) in mt7996_mac_add_txs_skb()
1280 if (wcid->rate.flags & RATE_INFO_FLAGS_SHORT_GI) in mt7996_mac_add_txs_skb()
1290 rate.he_gi = wcid->rate.he_gi; in mt7996_mac_add_txs_skb()
1300 rate.eht_gi = wcid->rate.eht_gi; in mt7996_mac_add_txs_skb()
1307 stats->tx_mode[mode]++; in mt7996_mac_add_txs_skb()
1312 stats->tx_bw[4]++; in mt7996_mac_add_txs_skb()
1316 stats->tx_bw[3]++; in mt7996_mac_add_txs_skb()
1320 stats->tx_bw[2]++; in mt7996_mac_add_txs_skb()
1324 stats->tx_bw[1]++; in mt7996_mac_add_txs_skb()
1328 stats->tx_bw[0]++; in mt7996_mac_add_txs_skb()
1331 wcid->rate = rate; in mt7996_mac_add_txs_skb()
1360 wcid = rcu_dereference(dev->mt76.wcid[wcidx]); in mt7996_mac_add_txs()
1368 if (!wcid->sta) in mt7996_mac_add_txs()
1371 spin_lock_bh(&dev->mt76.sta_poll_lock); in mt7996_mac_add_txs()
1372 if (list_empty(&msta->wcid.poll_list)) in mt7996_mac_add_txs()
1373 list_add_tail(&msta->wcid.poll_list, &dev->mt76.sta_poll_list); in mt7996_mac_add_txs()
1374 spin_unlock_bh(&dev->mt76.sta_poll_lock); in mt7996_mac_add_txs()
1416 __le32 *rxd = (__le32 *)skb->data; in mt7996_queue_rx_skb()
1417 __le32 *end = (__le32 *)&skb->data[skb->len]; in mt7996_queue_rx_skb()
1431 if (mtk_wed_device_active(&dev->mt76.mmio.wed_hif2) && in mt7996_queue_rx_skb()
1437 mt7996_mac_tx_free(dev, skb->data, skb->len); in mt7996_queue_rx_skb()
1449 mt7996_debugfs_rx_fw_monitor(dev, skb->data, skb->len); in mt7996_queue_rx_skb()
1454 mt76_rx(&dev->mt76, q, skb); in mt7996_queue_rx_skb()
1464 void mt7996_mac_cca_stats_reset(struct mt7996_phy *phy) in mt7996_mac_cca_stats_reset() argument
1466 struct mt7996_dev *dev = phy->dev; in mt7996_mac_cca_stats_reset()
1467 u32 reg = MT_WF_PHYRX_BAND_RX_CTRL1(phy->mt76->band_idx); in mt7996_mac_cca_stats_reset()
1473 void mt7996_mac_reset_counters(struct mt7996_phy *phy) in mt7996_mac_reset_counters() argument
1475 struct mt7996_dev *dev = phy->dev; in mt7996_mac_reset_counters()
1476 u8 band_idx = phy->mt76->band_idx; in mt7996_mac_reset_counters()
1482 phy->mt76->survey_time = ktime_get_boottime(); in mt7996_mac_reset_counters()
1484 memset(phy->mt76->aggr_stats, 0, sizeof(phy->mt76->aggr_stats)); in mt7996_mac_reset_counters()
1486 /* reset airtime counters */ in mt7996_mac_reset_counters()
1490 mt7996_mcu_get_chan_mib_info(phy, true); in mt7996_mac_reset_counters()
1493 void mt7996_mac_set_coverage_class(struct mt7996_phy *phy) in mt7996_mac_set_coverage_class() argument
1495 s16 coverage_class = phy->coverage_class; in mt7996_mac_set_coverage_class()
1496 struct mt7996_dev *dev = phy->dev; in mt7996_mac_set_coverage_class()
1504 u8 band_idx = phy->mt76->band_idx; in mt7996_mac_set_coverage_class()
1507 if (!test_bit(MT76_STATE_RUNNING, &phy->mt76->state)) in mt7996_mac_set_coverage_class()
1511 coverage_class = max_t(s16, dev->phy.coverage_class, in mt7996_mac_set_coverage_class()
1512 phy2->coverage_class); in mt7996_mac_set_coverage_class()
1516 phy3->coverage_class); in mt7996_mac_set_coverage_class()
1537 mt7996_phy_get_nf(struct mt7996_phy *phy, u8 band_idx) in mt7996_phy_get_nf() argument
1540 struct mt7996_dev *dev = phy->dev; in mt7996_phy_get_nf()
1544 for (ant = 0; ant < hweight8(phy->mt76->antenna_mask); ant++) { in mt7996_phy_get_nf()
1559 struct mt7996_phy *phy = mphy->priv; in mt7996_update_channel() local
1560 struct mt76_channel_state *state = mphy->chan_state; in mt7996_update_channel()
1563 mt7996_mcu_get_chan_mib_info(phy, false); in mt7996_update_channel()
1565 nf = mt7996_phy_get_nf(phy, mphy->band_idx); in mt7996_update_channel()
1566 if (!phy->noise) in mt7996_update_channel()
1567 phy->noise = nf << 4; in mt7996_update_channel()
1569 phy->noise += nf - (phy->noise >> 4); in mt7996_update_channel()
1571 state->noise = -(phy->noise >> 4); in mt7996_update_channel()
1579 ret = wait_event_timeout(dev->reset_wait, in mt7996_wait_reset_state()
1580 (READ_ONCE(dev->recovery.state) & state), in mt7996_wait_reset_state()
1583 WARN(!ret, "Timeout waiting for MCU reset state %x\n", state); in mt7996_wait_reset_state()
1592 switch (vif->type) { in mt7996_update_vif_beacon()
1596 mt7996_mcu_add_beacon(hw, vif, vif->bss_conf.enable_beacon); in mt7996_update_vif_beacon()
1608 ieee80211_iterate_active_interfaces(dev->mt76.hw, in mt7996_update_beacons()
1610 mt7996_update_vif_beacon, dev->mt76.hw); in mt7996_update_beacons()
1612 phy2 = dev->mt76.phys[MT_BAND1]; in mt7996_update_beacons()
1616 ieee80211_iterate_active_interfaces(phy2->hw, in mt7996_update_beacons()
1618 mt7996_update_vif_beacon, phy2->hw); in mt7996_update_beacons()
1620 phy3 = dev->mt76.phys[MT_BAND2]; in mt7996_update_beacons()
1624 ieee80211_iterate_active_interfaces(phy3->hw, in mt7996_update_beacons()
1626 mt7996_update_vif_beacon, phy3->hw); in mt7996_update_beacons()
1634 spin_lock_bh(&dev->mt76.token_lock); in mt7996_tx_token_put()
1635 idr_for_each_entry(&dev->mt76.token, txwi, id) { in mt7996_tx_token_put()
1637 dev->mt76.token_count--; in mt7996_tx_token_put()
1639 spin_unlock_bh(&dev->mt76.token_lock); in mt7996_tx_token_put()
1640 idr_destroy(&dev->mt76.token); in mt7996_tx_token_put()
1647 struct mt76_dev *mdev = &dev->mt76; in mt7996_mac_restart()
1653 if (dev->hif2) { in mt7996_mac_restart()
1658 if (dev_is_pci(mdev->dev)) { in mt7996_mac_restart()
1660 if (dev->hif2) in mt7996_mac_restart()
1664 set_bit(MT76_RESET, &dev->mphy.state); in mt7996_mac_restart()
1665 set_bit(MT76_MCU_RESET, &dev->mphy.state); in mt7996_mac_restart()
1666 wake_up(&dev->mt76.mcu.wait); in mt7996_mac_restart()
1668 set_bit(MT76_RESET, &phy2->mt76->state); in mt7996_mac_restart()
1670 set_bit(MT76_RESET, &phy3->mt76->state); in mt7996_mac_restart()
1673 mt76_txq_schedule_all(&dev->mphy); in mt7996_mac_restart()
1675 mt76_txq_schedule_all(phy2->mt76); in mt7996_mac_restart()
1677 mt76_txq_schedule_all(phy3->mt76); in mt7996_mac_restart()
1680 mt76_worker_disable(&dev->mt76.tx_worker); in mt7996_mac_restart()
1682 if (mtk_wed_device_active(&dev->mt76.mmio.wed) && in mt7996_mac_restart()
1683 mt76_queue_is_wed_rro(&mdev->q_rx[i])) in mt7996_mac_restart()
1686 if (mdev->q_rx[i].ndesc) in mt7996_mac_restart()
1687 napi_disable(&dev->mt76.napi[i]); in mt7996_mac_restart()
1689 napi_disable(&dev->mt76.tx_napi); in mt7996_mac_restart()
1693 idr_init(&dev->mt76.token); in mt7996_mac_restart()
1699 if (mtk_wed_device_active(&dev->mt76.mmio.wed) && in mt7996_mac_restart()
1700 mt76_queue_is_wed_rro(&mdev->q_rx[i])) in mt7996_mac_restart()
1703 if (mdev->q_rx[i].ndesc) { in mt7996_mac_restart()
1704 napi_enable(&dev->mt76.napi[i]); in mt7996_mac_restart()
1705 napi_schedule(&dev->mt76.napi[i]); in mt7996_mac_restart()
1709 clear_bit(MT76_MCU_RESET, &dev->mphy.state); in mt7996_mac_restart()
1710 clear_bit(MT76_STATE_MCU_RUNNING, &dev->mphy.state); in mt7996_mac_restart()
1712 mt76_wr(dev, MT_INT_MASK_CSR, dev->mt76.mmio.irqmask); in mt7996_mac_restart()
1714 if (dev->hif2) { in mt7996_mac_restart()
1715 mt76_wr(dev, MT_INT1_MASK_CSR, dev->mt76.mmio.irqmask); in mt7996_mac_restart()
1718 if (dev_is_pci(mdev->dev)) { in mt7996_mac_restart()
1720 if (dev->hif2) in mt7996_mac_restart()
1735 mt7996_init_txpower(&dev->phy); in mt7996_mac_restart()
1740 if (test_bit(MT76_STATE_RUNNING, &dev->mphy.state)) { in mt7996_mac_restart()
1741 ret = mt7996_run(dev->mphy.hw); in mt7996_mac_restart()
1746 if (phy2 && test_bit(MT76_STATE_RUNNING, &phy2->mt76->state)) { in mt7996_mac_restart()
1747 ret = mt7996_run(phy2->mt76->hw); in mt7996_mac_restart()
1752 if (phy3 && test_bit(MT76_STATE_RUNNING, &phy3->mt76->state)) { in mt7996_mac_restart()
1753 ret = mt7996_run(phy3->mt76->hw); in mt7996_mac_restart()
1759 /* reset done */ in mt7996_mac_restart()
1760 clear_bit(MT76_RESET, &dev->mphy.state); in mt7996_mac_restart()
1762 clear_bit(MT76_RESET, &phy2->mt76->state); in mt7996_mac_restart()
1764 clear_bit(MT76_RESET, &phy3->mt76->state); in mt7996_mac_restart()
1767 napi_enable(&dev->mt76.tx_napi); in mt7996_mac_restart()
1768 napi_schedule(&dev->mt76.tx_napi); in mt7996_mac_restart()
1771 mt76_worker_enable(&dev->mt76.tx_worker); in mt7996_mac_restart()
1783 dev->recovery.hw_full_reset = true; in mt7996_mac_full_reset()
1785 wake_up(&dev->mt76.mcu.wait); in mt7996_mac_full_reset()
1788 ieee80211_stop_queues(phy2->mt76->hw); in mt7996_mac_full_reset()
1790 ieee80211_stop_queues(phy3->mt76->hw); in mt7996_mac_full_reset()
1792 cancel_work_sync(&dev->wed_rro.work); in mt7996_mac_full_reset()
1793 cancel_delayed_work_sync(&dev->mphy.mac_work); in mt7996_mac_full_reset()
1795 cancel_delayed_work_sync(&phy2->mt76->mac_work); in mt7996_mac_full_reset()
1797 cancel_delayed_work_sync(&phy3->mt76->mac_work); in mt7996_mac_full_reset()
1799 mutex_lock(&dev->mt76.mutex); in mt7996_mac_full_reset()
1804 mutex_unlock(&dev->mt76.mutex); in mt7996_mac_full_reset()
1807 dev_err(dev->mt76.dev, "chip full reset failed\n"); in mt7996_mac_full_reset()
1811 ieee80211_restart_hw(phy2->mt76->hw); in mt7996_mac_full_reset()
1813 ieee80211_restart_hw(phy3->mt76->hw); in mt7996_mac_full_reset()
1817 ieee80211_wake_queues(phy2->mt76->hw); in mt7996_mac_full_reset()
1819 ieee80211_wake_queues(phy3->mt76->hw); in mt7996_mac_full_reset()
1821 dev->recovery.hw_full_reset = false; in mt7996_mac_full_reset()
1823 &dev->mphy.mac_work, in mt7996_mac_full_reset()
1826 ieee80211_queue_delayed_work(phy2->mt76->hw, in mt7996_mac_full_reset()
1827 &phy2->mt76->mac_work, in mt7996_mac_full_reset()
1830 ieee80211_queue_delayed_work(phy3->mt76->hw, in mt7996_mac_full_reset()
1831 &phy3->mt76->mac_work, in mt7996_mac_full_reset()
1845 /* chip full reset */ in mt7996_mac_reset_work()
1846 if (dev->recovery.restart) { in mt7996_mac_reset_work()
1851 if (READ_ONCE(dev->recovery.state) & MT_MCU_CMD_WA_WDT) in mt7996_mac_reset_work()
1852 dev->recovery.wa_reset_count++; in mt7996_mac_reset_work()
1854 dev->recovery.wm_reset_count++; in mt7996_mac_reset_work()
1865 dev->recovery.state = MT_MCU_CMD_NORMAL_STATE; in mt7996_mac_reset_work()
1866 dev->recovery.restart = false; in mt7996_mac_reset_work()
1870 if (!(READ_ONCE(dev->recovery.state) & MT_MCU_CMD_STOP_DMA)) in mt7996_mac_reset_work()
1873 dev_info(dev->mt76.dev,"\n%s L1 SER recovery start.", in mt7996_mac_reset_work()
1874 wiphy_name(dev->mt76.hw->wiphy)); in mt7996_mac_reset_work()
1876 if (mtk_wed_device_active(&dev->mt76.mmio.wed_hif2)) in mt7996_mac_reset_work()
1877 mtk_wed_device_stop(&dev->mt76.mmio.wed_hif2); in mt7996_mac_reset_work()
1879 if (mtk_wed_device_active(&dev->mt76.mmio.wed)) in mt7996_mac_reset_work()
1880 mtk_wed_device_stop(&dev->mt76.mmio.wed); in mt7996_mac_reset_work()
1884 ieee80211_stop_queues(phy2->mt76->hw); in mt7996_mac_reset_work()
1886 ieee80211_stop_queues(phy3->mt76->hw); in mt7996_mac_reset_work()
1888 set_bit(MT76_RESET, &dev->mphy.state); in mt7996_mac_reset_work()
1889 set_bit(MT76_MCU_RESET, &dev->mphy.state); in mt7996_mac_reset_work()
1890 wake_up(&dev->mt76.mcu.wait); in mt7996_mac_reset_work()
1892 cancel_work_sync(&dev->wed_rro.work); in mt7996_mac_reset_work()
1893 cancel_delayed_work_sync(&dev->mphy.mac_work); in mt7996_mac_reset_work()
1895 set_bit(MT76_RESET, &phy2->mt76->state); in mt7996_mac_reset_work()
1896 cancel_delayed_work_sync(&phy2->mt76->mac_work); in mt7996_mac_reset_work()
1899 set_bit(MT76_RESET, &phy3->mt76->state); in mt7996_mac_reset_work()
1900 cancel_delayed_work_sync(&phy3->mt76->mac_work); in mt7996_mac_reset_work()
1902 mt76_worker_disable(&dev->mt76.tx_worker); in mt7996_mac_reset_work()
1903 mt76_for_each_q_rx(&dev->mt76, i) { in mt7996_mac_reset_work()
1904 if (mtk_wed_device_active(&dev->mt76.mmio.wed) && in mt7996_mac_reset_work()
1905 mt76_queue_is_wed_rro(&dev->mt76.q_rx[i])) in mt7996_mac_reset_work()
1908 napi_disable(&dev->mt76.napi[i]); in mt7996_mac_reset_work()
1910 napi_disable(&dev->mt76.tx_napi); in mt7996_mac_reset_work()
1912 mutex_lock(&dev->mt76.mutex); in mt7996_mac_reset_work()
1920 idr_init(&dev->mt76.token); in mt7996_mac_reset_work()
1932 if (mtk_wed_device_active(&dev->mt76.mmio.wed)) { in mt7996_mac_reset_work()
1934 dev->mt76.mmio.irqmask; in mt7996_mac_reset_work()
1936 if (mtk_wed_get_rx_capa(&dev->mt76.mmio.wed)) in mt7996_mac_reset_work()
1941 mtk_wed_device_start_hw_rro(&dev->mt76.mmio.wed, wed_irq_mask, in mt7996_mac_reset_work()
1947 if (mtk_wed_device_active(&dev->mt76.mmio.wed_hif2)) { in mt7996_mac_reset_work()
1949 mtk_wed_device_start(&dev->mt76.mmio.wed_hif2, in mt7996_mac_reset_work()
1953 clear_bit(MT76_MCU_RESET, &dev->mphy.state); in mt7996_mac_reset_work()
1954 clear_bit(MT76_RESET, &dev->mphy.state); in mt7996_mac_reset_work()
1956 clear_bit(MT76_RESET, &phy2->mt76->state); in mt7996_mac_reset_work()
1958 clear_bit(MT76_RESET, &phy3->mt76->state); in mt7996_mac_reset_work()
1961 mt76_for_each_q_rx(&dev->mt76, i) { in mt7996_mac_reset_work()
1962 if (mtk_wed_device_active(&dev->mt76.mmio.wed) && in mt7996_mac_reset_work()
1963 mt76_queue_is_wed_rro(&dev->mt76.q_rx[i])) in mt7996_mac_reset_work()
1966 napi_enable(&dev->mt76.napi[i]); in mt7996_mac_reset_work()
1967 napi_schedule(&dev->mt76.napi[i]); in mt7996_mac_reset_work()
1971 tasklet_schedule(&dev->mt76.irq_tasklet); in mt7996_mac_reset_work()
1973 mt76_worker_enable(&dev->mt76.tx_worker); in mt7996_mac_reset_work()
1976 napi_enable(&dev->mt76.tx_napi); in mt7996_mac_reset_work()
1977 napi_schedule(&dev->mt76.tx_napi); in mt7996_mac_reset_work()
1982 ieee80211_wake_queues(phy2->mt76->hw); in mt7996_mac_reset_work()
1984 ieee80211_wake_queues(phy3->mt76->hw); in mt7996_mac_reset_work()
1986 mutex_unlock(&dev->mt76.mutex); in mt7996_mac_reset_work()
1990 ieee80211_queue_delayed_work(mt76_hw(dev), &dev->mphy.mac_work, in mt7996_mac_reset_work()
1993 ieee80211_queue_delayed_work(phy2->mt76->hw, in mt7996_mac_reset_work()
1994 &phy2->mt76->mac_work, in mt7996_mac_reset_work()
1997 ieee80211_queue_delayed_work(phy3->mt76->hw, in mt7996_mac_reset_work()
1998 &phy3->mt76->mac_work, in mt7996_mac_reset_work()
2000 dev_info(dev->mt76.dev,"\n%s L1 SER recovery completed.", in mt7996_mac_reset_work()
2001 wiphy_name(dev->mt76.hw->wiphy)); in mt7996_mac_reset_work()
2018 mutex_lock(&dev->dump_mutex); in mt7996_mac_dump_work()
2022 mutex_unlock(&dev->dump_mutex); in mt7996_mac_dump_work()
2027 if (!mem_region || !crash_data->memdump_buf_len) { in mt7996_mac_dump_work()
2028 mutex_unlock(&dev->dump_mutex); in mt7996_mac_dump_work()
2032 buf = crash_data->memdump_buf; in mt7996_mac_dump_work()
2033 buf_len = crash_data->memdump_buf_len; in mt7996_mac_dump_work()
2038 if (mem_region->len > buf_len) { in mt7996_mac_dump_work()
2039 dev_warn(dev->mt76.dev, "%s len %zu is too large\n", in mt7996_mac_dump_work()
2040 mem_region->name, mem_region->len); in mt7996_mac_dump_work()
2047 buf_len -= sizeof(*hdr); in mt7996_mac_dump_work()
2049 mt7996_memcpy_fromio(dev, buf, mem_region->start, in mt7996_mac_dump_work()
2050 mem_region->len); in mt7996_mac_dump_work()
2052 hdr->start = mem_region->start; in mt7996_mac_dump_work()
2053 hdr->len = mem_region->len; in mt7996_mac_dump_work()
2055 if (!mem_region->len) in mt7996_mac_dump_work()
2059 buf += mem_region->len; in mt7996_mac_dump_work()
2060 buf_len -= mem_region->len; in mt7996_mac_dump_work()
2065 mutex_unlock(&dev->dump_mutex); in mt7996_mac_dump_work()
2070 queue_work(dev->mt76.wq, &dev->reset_work); in mt7996_mac_dump_work()
2075 if (!dev->recovery.hw_init_done) in mt7996_reset()
2078 if (dev->recovery.hw_full_reset) in mt7996_reset()
2082 if (READ_ONCE(dev->recovery.state) & MT_MCU_CMD_WDT_MASK) { in mt7996_reset()
2083 dev->recovery.restart = true; in mt7996_reset()
2084 dev_info(dev->mt76.dev, in mt7996_reset()
2086 wiphy_name(dev->mt76.hw->wiphy)); in mt7996_reset()
2089 queue_work(dev->mt76.wq, &dev->dump_work); in mt7996_reset()
2093 queue_work(dev->mt76.wq, &dev->reset_work); in mt7996_reset()
2094 wake_up(&dev->reset_wait); in mt7996_reset()
2097 void mt7996_mac_update_stats(struct mt7996_phy *phy) in mt7996_mac_update_stats() argument
2099 struct mt76_mib_stats *mib = &phy->mib; in mt7996_mac_update_stats()
2100 struct mt7996_dev *dev = phy->dev; in mt7996_mac_update_stats()
2101 u8 band_idx = phy->mt76->band_idx; in mt7996_mac_update_stats()
2106 mib->fcs_err_cnt += cnt; in mt7996_mac_update_stats()
2109 mib->rx_fifo_full_cnt += cnt; in mt7996_mac_update_stats()
2112 mib->rx_mpdu_cnt += cnt; in mt7996_mac_update_stats()
2115 mib->channel_idle_cnt += FIELD_GET(MT_MIB_SDR6_CHANNEL_IDL_CNT_MASK, cnt); in mt7996_mac_update_stats()
2118 mib->rx_vector_mismatch_cnt += cnt; in mt7996_mac_update_stats()
2121 mib->rx_delimiter_fail_cnt += cnt; in mt7996_mac_update_stats()
2124 mib->rx_len_mismatch_cnt += cnt; in mt7996_mac_update_stats()
2127 mib->tx_ampdu_cnt += cnt; in mt7996_mac_update_stats()
2130 mib->tx_stop_q_empty_cnt += cnt; in mt7996_mac_update_stats()
2133 mib->tx_mpdu_attempts_cnt += cnt; in mt7996_mac_update_stats()
2136 mib->tx_mpdu_success_cnt += cnt; in mt7996_mac_update_stats()
2139 mib->rx_ampdu_cnt += cnt; in mt7996_mac_update_stats()
2142 mib->rx_ampdu_bytes_cnt += cnt; in mt7996_mac_update_stats()
2145 mib->rx_ampdu_valid_subframe_cnt += cnt; in mt7996_mac_update_stats()
2148 mib->rx_ampdu_valid_subframe_bytes_cnt += cnt; in mt7996_mac_update_stats()
2151 mib->tx_rwp_fail_cnt += FIELD_GET(MT_MIB_SDR27_TX_RWP_FAIL_CNT, cnt); in mt7996_mac_update_stats()
2154 mib->tx_rwp_need_cnt += FIELD_GET(MT_MIB_SDR28_TX_RWP_NEED_CNT, cnt); in mt7996_mac_update_stats()
2157 mib->rx_pfdrop_cnt += cnt; in mt7996_mac_update_stats()
2160 mib->rx_vec_queue_overflow_drop_cnt += cnt; in mt7996_mac_update_stats()
2163 mib->rx_ba_cnt += cnt; in mt7996_mac_update_stats()
2166 mib->tx_bf_ebf_ppdu_cnt += cnt; in mt7996_mac_update_stats()
2169 mib->tx_bf_ibf_ppdu_cnt += cnt; in mt7996_mac_update_stats()
2172 mib->tx_mu_bf_cnt += cnt; in mt7996_mac_update_stats()
2175 mib->tx_mu_mpdu_cnt += cnt; in mt7996_mac_update_stats()
2178 mib->tx_mu_acked_mpdu_cnt += cnt; in mt7996_mac_update_stats()
2181 mib->tx_su_acked_mpdu_cnt += cnt; in mt7996_mac_update_stats()
2184 mib->tx_bf_rx_fb_ht_cnt += cnt; in mt7996_mac_update_stats()
2185 mib->tx_bf_rx_fb_all_cnt += cnt; in mt7996_mac_update_stats()
2188 mib->tx_bf_rx_fb_vht_cnt += cnt; in mt7996_mac_update_stats()
2189 mib->tx_bf_rx_fb_all_cnt += cnt; in mt7996_mac_update_stats()
2192 mib->tx_bf_rx_fb_he_cnt += cnt; in mt7996_mac_update_stats()
2193 mib->tx_bf_rx_fb_all_cnt += cnt; in mt7996_mac_update_stats()
2196 mib->tx_bf_rx_fb_eht_cnt += cnt; in mt7996_mac_update_stats()
2197 mib->tx_bf_rx_fb_all_cnt += cnt; in mt7996_mac_update_stats()
2200 mib->tx_bf_rx_fb_bw = FIELD_GET(MT_ETBF_RX_FB_BW, cnt); in mt7996_mac_update_stats()
2201 mib->tx_bf_rx_fb_nc_cnt += FIELD_GET(MT_ETBF_RX_FB_NC, cnt); in mt7996_mac_update_stats()
2202 mib->tx_bf_rx_fb_nr_cnt += FIELD_GET(MT_ETBF_RX_FB_NR, cnt); in mt7996_mac_update_stats()
2205 mib->tx_bf_fb_trig_cnt += cnt; in mt7996_mac_update_stats()
2208 mib->tx_bf_fb_cpl_cnt += cnt; in mt7996_mac_update_stats()
2210 for (i = 0; i < ARRAY_SIZE(mib->tx_amsdu); i++) { in mt7996_mac_update_stats()
2212 mib->tx_amsdu[i] += cnt; in mt7996_mac_update_stats()
2213 mib->tx_amsdu_cnt += cnt; in mt7996_mac_update_stats()
2218 mib->rts_cnt += cnt; in mt7996_mac_update_stats()
2222 mib->rts_retries_cnt += cnt; in mt7996_mac_update_stats()
2226 mib->ba_miss_cnt += cnt; in mt7996_mac_update_stats()
2230 mib->ack_fail_cnt += cnt; in mt7996_mac_update_stats()
2234 phy->mt76->aggr_stats[i] += cnt; in mt7996_mac_update_stats()
2247 spin_lock_bh(&dev->mt76.sta_poll_lock); in mt7996_mac_sta_rc_work()
2248 list_splice_init(&dev->sta_rc_list, &list); in mt7996_mac_sta_rc_work()
2252 list_del_init(&msta->rc_list); in mt7996_mac_sta_rc_work()
2253 changed = msta->changed; in mt7996_mac_sta_rc_work()
2254 msta->changed = 0; in mt7996_mac_sta_rc_work()
2255 spin_unlock_bh(&dev->mt76.sta_poll_lock); in mt7996_mac_sta_rc_work()
2258 vif = container_of((void *)msta->vif, struct ieee80211_vif, drv_priv); in mt7996_mac_sta_rc_work()
2269 spin_lock_bh(&dev->mt76.sta_poll_lock); in mt7996_mac_sta_rc_work()
2272 spin_unlock_bh(&dev->mt76.sta_poll_lock); in mt7996_mac_sta_rc_work()
2277 struct mt7996_phy *phy; in mt7996_mac_work() local
2282 phy = mphy->priv; in mt7996_mac_work()
2284 mutex_lock(&mphy->dev->mutex); in mt7996_mac_work()
2287 if (++mphy->mac_work_count == 5) { in mt7996_mac_work()
2288 mphy->mac_work_count = 0; in mt7996_mac_work()
2290 mt7996_mac_update_stats(phy); in mt7996_mac_work()
2292 mt7996_mcu_get_all_sta_info(phy, UNI_ALL_STA_TXRX_RATE); in mt7996_mac_work()
2293 if (mtk_wed_device_active(&phy->dev->mt76.mmio.wed)) { in mt7996_mac_work()
2294 mt7996_mcu_get_all_sta_info(phy, UNI_ALL_STA_TXRX_ADM_STAT); in mt7996_mac_work()
2295 mt7996_mcu_get_all_sta_info(phy, UNI_ALL_STA_TXRX_MSDU_COUNT); in mt7996_mac_work()
2299 mutex_unlock(&mphy->dev->mutex); in mt7996_mac_work()
2301 mt76_tx_status_check(mphy->dev, false); in mt7996_mac_work()
2303 ieee80211_queue_delayed_work(mphy->hw, &mphy->mac_work, in mt7996_mac_work()
2307 static void mt7996_dfs_stop_radar_detector(struct mt7996_phy *phy) in mt7996_dfs_stop_radar_detector() argument
2309 struct mt7996_dev *dev = phy->dev; in mt7996_dfs_stop_radar_detector()
2311 if (phy->rdd_state & BIT(0)) in mt7996_dfs_stop_radar_detector()
2314 if (phy->rdd_state & BIT(1)) in mt7996_dfs_stop_radar_detector()
2323 switch (dev->mt76.region) { in mt7996_dfs_start_rdd()
2345 static int mt7996_dfs_start_radar_detector(struct mt7996_phy *phy) in mt7996_dfs_start_radar_detector() argument
2347 struct cfg80211_chan_def *chandef = &phy->mt76->chandef; in mt7996_dfs_start_radar_detector()
2348 struct mt7996_dev *dev = phy->dev; in mt7996_dfs_start_radar_detector()
2349 u8 band_idx = phy->mt76->band_idx; in mt7996_dfs_start_radar_detector()
2362 phy->rdd_state |= BIT(band_idx); in mt7996_dfs_start_radar_detector()
2364 if (chandef->width == NL80211_CHAN_WIDTH_160 || in mt7996_dfs_start_radar_detector()
2365 chandef->width == NL80211_CHAN_WIDTH_80P80) { in mt7996_dfs_start_radar_detector()
2370 phy->rdd_state |= BIT(1); in mt7996_dfs_start_radar_detector()
2377 mt7996_dfs_init_radar_specs(struct mt7996_phy *phy) in mt7996_dfs_init_radar_specs() argument
2380 struct mt7996_dev *dev = phy->dev; in mt7996_dfs_init_radar_specs()
2383 switch (dev->mt76.region) { in mt7996_dfs_init_radar_specs()
2397 return -EINVAL; in mt7996_dfs_init_radar_specs()
2400 for (i = 0; i < ARRAY_SIZE(radar_specs->radar_pattern); i++) { in mt7996_dfs_init_radar_specs()
2402 &radar_specs->radar_pattern[i]); in mt7996_dfs_init_radar_specs()
2407 return mt7996_mcu_set_pulse_th(dev, &radar_specs->pulse_th); in mt7996_dfs_init_radar_specs()
2410 int mt7996_dfs_init_radar_detector(struct mt7996_phy *phy) in mt7996_dfs_init_radar_detector() argument
2412 struct mt7996_dev *dev = phy->dev; in mt7996_dfs_init_radar_detector()
2416 prev_state = phy->mt76->dfs_state; in mt7996_dfs_init_radar_detector()
2417 dfs_state = mt76_phy_dfs_state(phy->mt76); in mt7996_dfs_init_radar_detector()
2423 mt7996_dfs_stop_radar_detector(phy); in mt7996_dfs_init_radar_detector()
2429 err = mt7996_dfs_init_radar_specs(phy); in mt7996_dfs_init_radar_detector()
2433 err = mt7996_dfs_start_radar_detector(phy); in mt7996_dfs_init_radar_detector()
2437 phy->mt76->dfs_state = MT_DFS_STATE_CAC; in mt7996_dfs_init_radar_detector()
2444 phy->mt76->band_idx, MT_RX_SEL0, 0); in mt7996_dfs_init_radar_detector()
2446 phy->mt76->dfs_state = MT_DFS_STATE_UNKNOWN; in mt7996_dfs_init_radar_detector()
2450 phy->mt76->dfs_state = MT_DFS_STATE_ACTIVE; in mt7996_dfs_init_radar_detector()
2455 phy->mt76->band_idx, MT_RX_SEL0, 0); in mt7996_dfs_init_radar_detector()
2459 mt7996_dfs_stop_radar_detector(phy); in mt7996_dfs_init_radar_detector()
2460 phy->mt76->dfs_state = MT_DFS_STATE_DISABLED; in mt7996_dfs_init_radar_detector()
2466 mt7996_mac_twt_duration_align(int duration) in mt7996_mac_twt_duration_align() argument
2468 return duration << 8; in mt7996_mac_twt_duration_align()
2476 u32 duration = flow->duration << 8; in mt7996_mac_twt_sched_list_add() local
2479 iter = list_first_entry_or_null(&dev->twt_list, in mt7996_mac_twt_sched_list_add()
2481 if (!iter || !iter->sched || iter->start_tsf > duration) { in mt7996_mac_twt_sched_list_add()
2483 list_add(&flow->list, &dev->twt_list); in mt7996_mac_twt_sched_list_add()
2487 list_for_each_entry_safe(iter, iter_next, &dev->twt_list, list) { in mt7996_mac_twt_sched_list_add()
2488 start_tsf = iter->start_tsf + in mt7996_mac_twt_sched_list_add()
2489 mt7996_mac_twt_duration_align(iter->duration); in mt7996_mac_twt_sched_list_add()
2490 if (list_is_last(&iter->list, &dev->twt_list)) in mt7996_mac_twt_sched_list_add()
2493 if (!iter_next->sched || in mt7996_mac_twt_sched_list_add()
2494 iter_next->start_tsf > start_tsf + duration) { in mt7996_mac_twt_sched_list_add()
2495 list_add(&flow->list, &iter->list); in mt7996_mac_twt_sched_list_add()
2501 list_add_tail(&flow->list, &dev->twt_list); in mt7996_mac_twt_sched_list_add()
2509 u64 interval, duration; in mt7996_mac_check_twt_req() local
2514 if (twt->control & IEEE80211_TWT_CONTROL_NEG_TYPE_BROADCAST) in mt7996_mac_check_twt_req()
2515 return -EOPNOTSUPP; in mt7996_mac_check_twt_req()
2518 if (twt->control & IEEE80211_TWT_CONTROL_WAKE_DUR_UNIT) in mt7996_mac_check_twt_req()
2519 return -EOPNOTSUPP; in mt7996_mac_check_twt_req()
2521 twt_agrt = (struct ieee80211_twt_params *)twt->params; in mt7996_mac_check_twt_req()
2524 if (!(twt_agrt->req_type & cpu_to_le16(IEEE80211_TWT_REQTYPE_IMPLICIT))) in mt7996_mac_check_twt_req()
2525 return -EOPNOTSUPP; in mt7996_mac_check_twt_req()
2528 le16_to_cpu(twt_agrt->req_type)); in mt7996_mac_check_twt_req()
2529 mantissa = le16_to_cpu(twt_agrt->mantissa); in mt7996_mac_check_twt_req()
2530 duration = twt_agrt->min_twt_dur << 8; in mt7996_mac_check_twt_req()
2533 if (interval < duration) in mt7996_mac_check_twt_req()
2534 return -EOPNOTSUPP; in mt7996_mac_check_twt_req()
2543 u16 type = le16_to_cpu(twt_agrt->req_type); in mt7996_mac_twt_param_equal()
2551 if (!(msta->twt.flowid_mask & BIT(i))) in mt7996_mac_twt_param_equal()
2554 f = &msta->twt.flow[i]; in mt7996_mac_twt_param_equal()
2555 if (f->duration == twt_agrt->min_twt_dur && in mt7996_mac_twt_param_equal()
2556 f->mantissa == twt_agrt->mantissa && in mt7996_mac_twt_param_equal()
2557 f->exp == exp && in mt7996_mac_twt_param_equal()
2558 f->protection == !!(type & IEEE80211_TWT_REQTYPE_PROTECTION) && in mt7996_mac_twt_param_equal()
2559 f->flowtype == !!(type & IEEE80211_TWT_REQTYPE_FLOWTYPE) && in mt7996_mac_twt_param_equal()
2560 f->trigger == !!(type & IEEE80211_TWT_REQTYPE_TRIGGER)) in mt7996_mac_twt_param_equal()
2572 struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv; in mt7996_mac_add_twt_setup()
2573 struct ieee80211_twt_params *twt_agrt = (void *)twt->params; in mt7996_mac_add_twt_setup()
2574 u16 req_type = le16_to_cpu(twt_agrt->req_type); in mt7996_mac_add_twt_setup()
2583 mutex_lock(&dev->mt76.mutex); in mt7996_mac_add_twt_setup()
2585 if (dev->twt.n_agrt == MT7996_MAX_TWT_AGRT) in mt7996_mac_add_twt_setup()
2588 if (hweight8(msta->twt.flowid_mask) == ARRAY_SIZE(msta->twt.flow)) in mt7996_mac_add_twt_setup()
2591 if (twt_agrt->min_twt_dur < MT7996_MIN_TWT_DUR) { in mt7996_mac_add_twt_setup()
2593 twt_agrt->min_twt_dur = MT7996_MIN_TWT_DUR; in mt7996_mac_add_twt_setup()
2600 flowid = ffs(~msta->twt.flowid_mask) - 1; in mt7996_mac_add_twt_setup()
2601 twt_agrt->req_type &= ~cpu_to_le16(IEEE80211_TWT_REQTYPE_FLOWID); in mt7996_mac_add_twt_setup()
2602 twt_agrt->req_type |= le16_encode_bits(flowid, in mt7996_mac_add_twt_setup()
2605 table_id = ffs(~dev->twt.table_mask) - 1; in mt7996_mac_add_twt_setup()
2609 flow = &msta->twt.flow[flowid]; in mt7996_mac_add_twt_setup()
2611 INIT_LIST_HEAD(&flow->list); in mt7996_mac_add_twt_setup()
2612 flow->wcid = msta->wcid.idx; in mt7996_mac_add_twt_setup()
2613 flow->table_id = table_id; in mt7996_mac_add_twt_setup()
2614 flow->id = flowid; in mt7996_mac_add_twt_setup()
2615 flow->duration = twt_agrt->min_twt_dur; in mt7996_mac_add_twt_setup()
2616 flow->mantissa = twt_agrt->mantissa; in mt7996_mac_add_twt_setup()
2617 flow->exp = exp; in mt7996_mac_add_twt_setup()
2618 flow->protection = !!(req_type & IEEE80211_TWT_REQTYPE_PROTECTION); in mt7996_mac_add_twt_setup()
2619 flow->flowtype = !!(req_type & IEEE80211_TWT_REQTYPE_FLOWTYPE); in mt7996_mac_add_twt_setup()
2620 flow->trigger = !!(req_type & IEEE80211_TWT_REQTYPE_TRIGGER); in mt7996_mac_add_twt_setup()
2624 u64 interval = (u64)le16_to_cpu(twt_agrt->mantissa) << exp; in mt7996_mac_add_twt_setup()
2628 flow->sched = true; in mt7996_mac_add_twt_setup()
2629 flow->start_tsf = mt7996_mac_twt_sched_list_add(dev, flow); in mt7996_mac_add_twt_setup()
2630 curr_tsf = __mt7996_get_tsf(hw, msta->vif); in mt7996_mac_add_twt_setup()
2631 div_u64_rem(curr_tsf - flow->start_tsf, interval, &rem); in mt7996_mac_add_twt_setup()
2632 flow_tsf = curr_tsf + interval - rem; in mt7996_mac_add_twt_setup()
2633 twt_agrt->twt = cpu_to_le64(flow_tsf); in mt7996_mac_add_twt_setup()
2635 list_add_tail(&flow->list, &dev->twt_list); in mt7996_mac_add_twt_setup()
2637 flow->tsf = le64_to_cpu(twt_agrt->twt); in mt7996_mac_add_twt_setup()
2639 if (mt7996_mcu_twt_agrt_update(dev, msta->vif, flow, MCU_TWT_AGRT_ADD)) in mt7996_mac_add_twt_setup()
2643 dev->twt.table_mask |= BIT(table_id); in mt7996_mac_add_twt_setup()
2644 msta->twt.flowid_mask |= BIT(flowid); in mt7996_mac_add_twt_setup()
2645 dev->twt.n_agrt++; in mt7996_mac_add_twt_setup()
2648 mutex_unlock(&dev->mt76.mutex); in mt7996_mac_add_twt_setup()
2650 twt_agrt->req_type &= ~cpu_to_le16(IEEE80211_TWT_REQTYPE_SETUP_CMD); in mt7996_mac_add_twt_setup()
2651 twt_agrt->req_type |= in mt7996_mac_add_twt_setup()
2653 twt->control = twt->control & IEEE80211_TWT_CONTROL_RX_DISABLED; in mt7996_mac_add_twt_setup()
2662 lockdep_assert_held(&dev->mt76.mutex); in mt7996_mac_twt_teardown_flow()
2664 if (flowid >= ARRAY_SIZE(msta->twt.flow)) in mt7996_mac_twt_teardown_flow()
2667 if (!(msta->twt.flowid_mask & BIT(flowid))) in mt7996_mac_twt_teardown_flow()
2670 flow = &msta->twt.flow[flowid]; in mt7996_mac_twt_teardown_flow()
2671 if (mt7996_mcu_twt_agrt_update(dev, msta->vif, flow, in mt7996_mac_twt_teardown_flow()
2675 list_del_init(&flow->list); in mt7996_mac_twt_teardown_flow()
2676 msta->twt.flowid_mask &= ~BIT(flowid); in mt7996_mac_twt_teardown_flow()
2677 dev->twt.table_mask &= ~BIT(flow->table_id); in mt7996_mac_twt_teardown_flow()
2678 dev->twt.n_agrt--; in mt7996_mac_twt_teardown_flow()