16c92544dSBjoern A. Zeeb // SPDX-License-Identifier: ISC
26c92544dSBjoern A. Zeeb /* Copyright (C) 2020 MediaTek Inc. */
36c92544dSBjoern A. Zeeb
46c92544dSBjoern A. Zeeb #include "mt76_connac.h"
56c92544dSBjoern A. Zeeb #include "mt76_connac2_mac.h"
66c92544dSBjoern A. Zeeb #include "dma.h"
76c92544dSBjoern A. Zeeb
86c92544dSBjoern A. Zeeb #define HE_BITS(f) cpu_to_le16(IEEE80211_RADIOTAP_HE_##f)
96c92544dSBjoern A. Zeeb #define HE_PREP(f, m, v) le16_encode_bits(le32_get_bits(v, MT_CRXV_HE_##m),\
106c92544dSBjoern A. Zeeb IEEE80211_RADIOTAP_HE_##f)
116c92544dSBjoern A. Zeeb
mt76_connac_gen_ppe_thresh(u8 * he_ppet,int nss)12*cbb3ec25SBjoern A. Zeeb void mt76_connac_gen_ppe_thresh(u8 *he_ppet, int nss)
13*cbb3ec25SBjoern A. Zeeb {
14*cbb3ec25SBjoern A. Zeeb static const u8 ppet16_ppet8_ru3_ru0[] = { 0x1c, 0xc7, 0x71 };
15*cbb3ec25SBjoern A. Zeeb u8 i, ppet_bits, ppet_size, ru_bit_mask = 0x7; /* HE80 */
16*cbb3ec25SBjoern A. Zeeb
17*cbb3ec25SBjoern A. Zeeb he_ppet[0] = FIELD_PREP(IEEE80211_PPE_THRES_NSS_MASK, nss - 1) |
18*cbb3ec25SBjoern A. Zeeb FIELD_PREP(IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK,
19*cbb3ec25SBjoern A. Zeeb ru_bit_mask);
20*cbb3ec25SBjoern A. Zeeb
21*cbb3ec25SBjoern A. Zeeb ppet_bits = IEEE80211_PPE_THRES_INFO_PPET_SIZE *
22*cbb3ec25SBjoern A. Zeeb nss * hweight8(ru_bit_mask) * 2;
23*cbb3ec25SBjoern A. Zeeb ppet_size = DIV_ROUND_UP(ppet_bits, 8);
24*cbb3ec25SBjoern A. Zeeb
25*cbb3ec25SBjoern A. Zeeb for (i = 0; i < ppet_size - 1; i++)
26*cbb3ec25SBjoern A. Zeeb he_ppet[i + 1] = ppet16_ppet8_ru3_ru0[i % 3];
27*cbb3ec25SBjoern A. Zeeb
28*cbb3ec25SBjoern A. Zeeb he_ppet[i + 1] = ppet16_ppet8_ru3_ru0[i % 3] &
29*cbb3ec25SBjoern A. Zeeb (0xff >> (8 - (ppet_bits - 1) % 8));
30*cbb3ec25SBjoern A. Zeeb }
31*cbb3ec25SBjoern A. Zeeb EXPORT_SYMBOL_GPL(mt76_connac_gen_ppe_thresh);
32*cbb3ec25SBjoern A. Zeeb
mt76_connac_pm_wake(struct mt76_phy * phy,struct mt76_connac_pm * pm)336c92544dSBjoern A. Zeeb int mt76_connac_pm_wake(struct mt76_phy *phy, struct mt76_connac_pm *pm)
346c92544dSBjoern A. Zeeb {
356c92544dSBjoern A. Zeeb struct mt76_dev *dev = phy->dev;
366c92544dSBjoern A. Zeeb
376c92544dSBjoern A. Zeeb if (mt76_is_usb(dev))
386c92544dSBjoern A. Zeeb return 0;
396c92544dSBjoern A. Zeeb
406c92544dSBjoern A. Zeeb cancel_delayed_work_sync(&pm->ps_work);
416c92544dSBjoern A. Zeeb if (!test_bit(MT76_STATE_PM, &phy->state))
426c92544dSBjoern A. Zeeb return 0;
436c92544dSBjoern A. Zeeb
446c92544dSBjoern A. Zeeb if (pm->suspended)
456c92544dSBjoern A. Zeeb return 0;
466c92544dSBjoern A. Zeeb
476c92544dSBjoern A. Zeeb queue_work(dev->wq, &pm->wake_work);
486c92544dSBjoern A. Zeeb if (!wait_event_timeout(pm->wait,
496c92544dSBjoern A. Zeeb !test_bit(MT76_STATE_PM, &phy->state),
506c92544dSBjoern A. Zeeb 3 * HZ)) {
516c92544dSBjoern A. Zeeb ieee80211_wake_queues(phy->hw);
526c92544dSBjoern A. Zeeb return -ETIMEDOUT;
536c92544dSBjoern A. Zeeb }
546c92544dSBjoern A. Zeeb
556c92544dSBjoern A. Zeeb return 0;
566c92544dSBjoern A. Zeeb }
576c92544dSBjoern A. Zeeb EXPORT_SYMBOL_GPL(mt76_connac_pm_wake);
586c92544dSBjoern A. Zeeb
mt76_connac_power_save_sched(struct mt76_phy * phy,struct mt76_connac_pm * pm)596c92544dSBjoern A. Zeeb void mt76_connac_power_save_sched(struct mt76_phy *phy,
606c92544dSBjoern A. Zeeb struct mt76_connac_pm *pm)
616c92544dSBjoern A. Zeeb {
626c92544dSBjoern A. Zeeb struct mt76_dev *dev = phy->dev;
636c92544dSBjoern A. Zeeb
646c92544dSBjoern A. Zeeb if (mt76_is_usb(dev))
656c92544dSBjoern A. Zeeb return;
666c92544dSBjoern A. Zeeb
676c92544dSBjoern A. Zeeb if (!pm->enable)
686c92544dSBjoern A. Zeeb return;
696c92544dSBjoern A. Zeeb
706c92544dSBjoern A. Zeeb if (pm->suspended)
716c92544dSBjoern A. Zeeb return;
726c92544dSBjoern A. Zeeb
736c92544dSBjoern A. Zeeb pm->last_activity = jiffies;
746c92544dSBjoern A. Zeeb
756c92544dSBjoern A. Zeeb if (!test_bit(MT76_STATE_PM, &phy->state)) {
766c92544dSBjoern A. Zeeb cancel_delayed_work(&phy->mac_work);
776c92544dSBjoern A. Zeeb queue_delayed_work(dev->wq, &pm->ps_work, pm->idle_timeout);
786c92544dSBjoern A. Zeeb }
796c92544dSBjoern A. Zeeb }
806c92544dSBjoern A. Zeeb EXPORT_SYMBOL_GPL(mt76_connac_power_save_sched);
816c92544dSBjoern A. Zeeb
mt76_connac_free_pending_tx_skbs(struct mt76_connac_pm * pm,struct mt76_wcid * wcid)826c92544dSBjoern A. Zeeb void mt76_connac_free_pending_tx_skbs(struct mt76_connac_pm *pm,
836c92544dSBjoern A. Zeeb struct mt76_wcid *wcid)
846c92544dSBjoern A. Zeeb {
856c92544dSBjoern A. Zeeb int i;
866c92544dSBjoern A. Zeeb
876c92544dSBjoern A. Zeeb spin_lock_bh(&pm->txq_lock);
886c92544dSBjoern A. Zeeb for (i = 0; i < IEEE80211_NUM_ACS; i++) {
896c92544dSBjoern A. Zeeb if (wcid && pm->tx_q[i].wcid != wcid)
906c92544dSBjoern A. Zeeb continue;
916c92544dSBjoern A. Zeeb
926c92544dSBjoern A. Zeeb dev_kfree_skb(pm->tx_q[i].skb);
936c92544dSBjoern A. Zeeb pm->tx_q[i].skb = NULL;
946c92544dSBjoern A. Zeeb }
956c92544dSBjoern A. Zeeb spin_unlock_bh(&pm->txq_lock);
966c92544dSBjoern A. Zeeb }
976c92544dSBjoern A. Zeeb EXPORT_SYMBOL_GPL(mt76_connac_free_pending_tx_skbs);
986c92544dSBjoern A. Zeeb
mt76_connac_pm_queue_skb(struct ieee80211_hw * hw,struct mt76_connac_pm * pm,struct mt76_wcid * wcid,struct sk_buff * skb)996c92544dSBjoern A. Zeeb void mt76_connac_pm_queue_skb(struct ieee80211_hw *hw,
1006c92544dSBjoern A. Zeeb struct mt76_connac_pm *pm,
1016c92544dSBjoern A. Zeeb struct mt76_wcid *wcid,
1026c92544dSBjoern A. Zeeb struct sk_buff *skb)
1036c92544dSBjoern A. Zeeb {
1046c92544dSBjoern A. Zeeb int qid = skb_get_queue_mapping(skb);
1056c92544dSBjoern A. Zeeb struct mt76_phy *phy = hw->priv;
1066c92544dSBjoern A. Zeeb
1076c92544dSBjoern A. Zeeb spin_lock_bh(&pm->txq_lock);
1086c92544dSBjoern A. Zeeb if (!pm->tx_q[qid].skb) {
1096c92544dSBjoern A. Zeeb ieee80211_stop_queues(hw);
1106c92544dSBjoern A. Zeeb pm->tx_q[qid].wcid = wcid;
1116c92544dSBjoern A. Zeeb pm->tx_q[qid].skb = skb;
1126c92544dSBjoern A. Zeeb queue_work(phy->dev->wq, &pm->wake_work);
1136c92544dSBjoern A. Zeeb } else {
1146c92544dSBjoern A. Zeeb dev_kfree_skb(skb);
1156c92544dSBjoern A. Zeeb }
1166c92544dSBjoern A. Zeeb spin_unlock_bh(&pm->txq_lock);
1176c92544dSBjoern A. Zeeb }
1186c92544dSBjoern A. Zeeb EXPORT_SYMBOL_GPL(mt76_connac_pm_queue_skb);
1196c92544dSBjoern A. Zeeb
mt76_connac_pm_dequeue_skbs(struct mt76_phy * phy,struct mt76_connac_pm * pm)1206c92544dSBjoern A. Zeeb void mt76_connac_pm_dequeue_skbs(struct mt76_phy *phy,
1216c92544dSBjoern A. Zeeb struct mt76_connac_pm *pm)
1226c92544dSBjoern A. Zeeb {
1236c92544dSBjoern A. Zeeb int i;
1246c92544dSBjoern A. Zeeb
1256c92544dSBjoern A. Zeeb spin_lock_bh(&pm->txq_lock);
1266c92544dSBjoern A. Zeeb for (i = 0; i < IEEE80211_NUM_ACS; i++) {
1276c92544dSBjoern A. Zeeb struct mt76_wcid *wcid = pm->tx_q[i].wcid;
1286c92544dSBjoern A. Zeeb struct ieee80211_sta *sta = NULL;
1296c92544dSBjoern A. Zeeb
1306c92544dSBjoern A. Zeeb if (!pm->tx_q[i].skb)
1316c92544dSBjoern A. Zeeb continue;
1326c92544dSBjoern A. Zeeb
1336c92544dSBjoern A. Zeeb if (wcid && wcid->sta)
1346c92544dSBjoern A. Zeeb sta = container_of((void *)wcid, struct ieee80211_sta,
1356c92544dSBjoern A. Zeeb drv_priv);
1366c92544dSBjoern A. Zeeb
1376c92544dSBjoern A. Zeeb mt76_tx(phy, sta, wcid, pm->tx_q[i].skb);
1386c92544dSBjoern A. Zeeb pm->tx_q[i].skb = NULL;
1396c92544dSBjoern A. Zeeb }
1406c92544dSBjoern A. Zeeb spin_unlock_bh(&pm->txq_lock);
1416c92544dSBjoern A. Zeeb
1426c92544dSBjoern A. Zeeb mt76_worker_schedule(&phy->dev->tx_worker);
1436c92544dSBjoern A. Zeeb }
1446c92544dSBjoern A. Zeeb EXPORT_SYMBOL_GPL(mt76_connac_pm_dequeue_skbs);
1456c92544dSBjoern A. Zeeb
mt76_connac_tx_complete_skb(struct mt76_dev * mdev,struct mt76_queue_entry * e)1466c92544dSBjoern A. Zeeb void mt76_connac_tx_complete_skb(struct mt76_dev *mdev,
1476c92544dSBjoern A. Zeeb struct mt76_queue_entry *e)
1486c92544dSBjoern A. Zeeb {
1496c92544dSBjoern A. Zeeb if (!e->txwi) {
1506c92544dSBjoern A. Zeeb dev_kfree_skb_any(e->skb);
1516c92544dSBjoern A. Zeeb return;
1526c92544dSBjoern A. Zeeb }
1536c92544dSBjoern A. Zeeb
1546c92544dSBjoern A. Zeeb /* error path */
1556c92544dSBjoern A. Zeeb if (e->skb == DMA_DUMMY_DATA) {
1566c92544dSBjoern A. Zeeb struct mt76_connac_txp_common *txp;
1576c92544dSBjoern A. Zeeb struct mt76_txwi_cache *t;
1586c92544dSBjoern A. Zeeb u16 token;
1596c92544dSBjoern A. Zeeb
1606c92544dSBjoern A. Zeeb txp = mt76_connac_txwi_to_txp(mdev, e->txwi);
1616c92544dSBjoern A. Zeeb if (is_mt76_fw_txp(mdev))
1626c92544dSBjoern A. Zeeb token = le16_to_cpu(txp->fw.token);
1636c92544dSBjoern A. Zeeb else
1646c92544dSBjoern A. Zeeb token = le16_to_cpu(txp->hw.msdu_id[0]) &
1656c92544dSBjoern A. Zeeb ~MT_MSDU_ID_VALID;
1666c92544dSBjoern A. Zeeb
1676c92544dSBjoern A. Zeeb t = mt76_token_put(mdev, token);
1686c92544dSBjoern A. Zeeb e->skb = t ? t->skb : NULL;
1696c92544dSBjoern A. Zeeb }
1706c92544dSBjoern A. Zeeb
1716c92544dSBjoern A. Zeeb if (e->skb)
1726c92544dSBjoern A. Zeeb mt76_tx_complete_skb(mdev, e->wcid, e->skb);
1736c92544dSBjoern A. Zeeb }
1746c92544dSBjoern A. Zeeb EXPORT_SYMBOL_GPL(mt76_connac_tx_complete_skb);
1756c92544dSBjoern A. Zeeb
mt76_connac_write_hw_txp(struct mt76_dev * dev,struct mt76_tx_info * tx_info,void * txp_ptr,u32 id)1766c92544dSBjoern A. Zeeb void mt76_connac_write_hw_txp(struct mt76_dev *dev,
1776c92544dSBjoern A. Zeeb struct mt76_tx_info *tx_info,
1786c92544dSBjoern A. Zeeb void *txp_ptr, u32 id)
1796c92544dSBjoern A. Zeeb {
1806c92544dSBjoern A. Zeeb struct mt76_connac_hw_txp *txp = txp_ptr;
1816c92544dSBjoern A. Zeeb struct mt76_connac_txp_ptr *ptr = &txp->ptr[0];
1826c92544dSBjoern A. Zeeb int i, nbuf = tx_info->nbuf - 1;
1836c92544dSBjoern A. Zeeb u32 last_mask;
1846c92544dSBjoern A. Zeeb
1856c92544dSBjoern A. Zeeb tx_info->buf[0].len = MT_TXD_SIZE + sizeof(*txp);
1866c92544dSBjoern A. Zeeb tx_info->nbuf = 1;
1876c92544dSBjoern A. Zeeb
1886c92544dSBjoern A. Zeeb txp->msdu_id[0] = cpu_to_le16(id | MT_MSDU_ID_VALID);
1896c92544dSBjoern A. Zeeb
1906c92544dSBjoern A. Zeeb if (is_mt7663(dev) || is_mt7921(dev))
1916c92544dSBjoern A. Zeeb last_mask = MT_TXD_LEN_LAST;
1926c92544dSBjoern A. Zeeb else
1936c92544dSBjoern A. Zeeb last_mask = MT_TXD_LEN_AMSDU_LAST |
1946c92544dSBjoern A. Zeeb MT_TXD_LEN_MSDU_LAST;
1956c92544dSBjoern A. Zeeb
1966c92544dSBjoern A. Zeeb for (i = 0; i < nbuf; i++) {
1976c92544dSBjoern A. Zeeb u16 len = tx_info->buf[i + 1].len & MT_TXD_LEN_MASK;
1986c92544dSBjoern A. Zeeb u32 addr = tx_info->buf[i + 1].addr;
1996c92544dSBjoern A. Zeeb
2006c92544dSBjoern A. Zeeb if (i == nbuf - 1)
2016c92544dSBjoern A. Zeeb len |= last_mask;
2026c92544dSBjoern A. Zeeb
2036c92544dSBjoern A. Zeeb if (i & 1) {
2046c92544dSBjoern A. Zeeb ptr->buf1 = cpu_to_le32(addr);
2056c92544dSBjoern A. Zeeb ptr->len1 = cpu_to_le16(len);
2066c92544dSBjoern A. Zeeb ptr++;
2076c92544dSBjoern A. Zeeb } else {
2086c92544dSBjoern A. Zeeb ptr->buf0 = cpu_to_le32(addr);
2096c92544dSBjoern A. Zeeb ptr->len0 = cpu_to_le16(len);
2106c92544dSBjoern A. Zeeb }
2116c92544dSBjoern A. Zeeb }
2126c92544dSBjoern A. Zeeb }
2136c92544dSBjoern A. Zeeb EXPORT_SYMBOL_GPL(mt76_connac_write_hw_txp);
2146c92544dSBjoern A. Zeeb
2156c92544dSBjoern A. Zeeb static void
mt76_connac_txp_skb_unmap_fw(struct mt76_dev * mdev,struct mt76_connac_fw_txp * txp)2166c92544dSBjoern A. Zeeb mt76_connac_txp_skb_unmap_fw(struct mt76_dev *mdev,
2176c92544dSBjoern A. Zeeb struct mt76_connac_fw_txp *txp)
2186c92544dSBjoern A. Zeeb {
2196c92544dSBjoern A. Zeeb struct device *dev = is_connac_v1(mdev) ? mdev->dev : mdev->dma_dev;
2206c92544dSBjoern A. Zeeb int i;
2216c92544dSBjoern A. Zeeb
2226c92544dSBjoern A. Zeeb for (i = 0; i < txp->nbuf; i++)
2236c92544dSBjoern A. Zeeb dma_unmap_single(dev, le32_to_cpu(txp->buf[i]),
2246c92544dSBjoern A. Zeeb le16_to_cpu(txp->len[i]), DMA_TO_DEVICE);
2256c92544dSBjoern A. Zeeb }
2266c92544dSBjoern A. Zeeb
2276c92544dSBjoern A. Zeeb static void
mt76_connac_txp_skb_unmap_hw(struct mt76_dev * dev,struct mt76_connac_hw_txp * txp)2286c92544dSBjoern A. Zeeb mt76_connac_txp_skb_unmap_hw(struct mt76_dev *dev,
2296c92544dSBjoern A. Zeeb struct mt76_connac_hw_txp *txp)
2306c92544dSBjoern A. Zeeb {
2316c92544dSBjoern A. Zeeb u32 last_mask;
2326c92544dSBjoern A. Zeeb int i;
2336c92544dSBjoern A. Zeeb
2346c92544dSBjoern A. Zeeb if (is_mt7663(dev) || is_mt7921(dev))
2356c92544dSBjoern A. Zeeb last_mask = MT_TXD_LEN_LAST;
2366c92544dSBjoern A. Zeeb else
2376c92544dSBjoern A. Zeeb last_mask = MT_TXD_LEN_MSDU_LAST;
2386c92544dSBjoern A. Zeeb
2396c92544dSBjoern A. Zeeb for (i = 0; i < ARRAY_SIZE(txp->ptr); i++) {
2406c92544dSBjoern A. Zeeb struct mt76_connac_txp_ptr *ptr = &txp->ptr[i];
2416c92544dSBjoern A. Zeeb bool last;
2426c92544dSBjoern A. Zeeb u16 len;
2436c92544dSBjoern A. Zeeb
2446c92544dSBjoern A. Zeeb len = le16_to_cpu(ptr->len0);
2456c92544dSBjoern A. Zeeb last = len & last_mask;
2466c92544dSBjoern A. Zeeb len &= MT_TXD_LEN_MASK;
2476c92544dSBjoern A. Zeeb dma_unmap_single(dev->dev, le32_to_cpu(ptr->buf0), len,
2486c92544dSBjoern A. Zeeb DMA_TO_DEVICE);
2496c92544dSBjoern A. Zeeb if (last)
2506c92544dSBjoern A. Zeeb break;
2516c92544dSBjoern A. Zeeb
2526c92544dSBjoern A. Zeeb len = le16_to_cpu(ptr->len1);
2536c92544dSBjoern A. Zeeb last = len & last_mask;
2546c92544dSBjoern A. Zeeb len &= MT_TXD_LEN_MASK;
2556c92544dSBjoern A. Zeeb dma_unmap_single(dev->dev, le32_to_cpu(ptr->buf1), len,
2566c92544dSBjoern A. Zeeb DMA_TO_DEVICE);
2576c92544dSBjoern A. Zeeb if (last)
2586c92544dSBjoern A. Zeeb break;
2596c92544dSBjoern A. Zeeb }
2606c92544dSBjoern A. Zeeb }
2616c92544dSBjoern A. Zeeb
mt76_connac_txp_skb_unmap(struct mt76_dev * dev,struct mt76_txwi_cache * t)2626c92544dSBjoern A. Zeeb void mt76_connac_txp_skb_unmap(struct mt76_dev *dev,
2636c92544dSBjoern A. Zeeb struct mt76_txwi_cache *t)
2646c92544dSBjoern A. Zeeb {
2656c92544dSBjoern A. Zeeb struct mt76_connac_txp_common *txp;
2666c92544dSBjoern A. Zeeb
2676c92544dSBjoern A. Zeeb txp = mt76_connac_txwi_to_txp(dev, t);
2686c92544dSBjoern A. Zeeb if (is_mt76_fw_txp(dev))
2696c92544dSBjoern A. Zeeb mt76_connac_txp_skb_unmap_fw(dev, &txp->fw);
2706c92544dSBjoern A. Zeeb else
2716c92544dSBjoern A. Zeeb mt76_connac_txp_skb_unmap_hw(dev, &txp->hw);
2726c92544dSBjoern A. Zeeb }
2736c92544dSBjoern A. Zeeb EXPORT_SYMBOL_GPL(mt76_connac_txp_skb_unmap);
2746c92544dSBjoern A. Zeeb
mt76_connac_init_tx_queues(struct mt76_phy * phy,int idx,int n_desc,int ring_base,u32 flags)2756c92544dSBjoern A. Zeeb int mt76_connac_init_tx_queues(struct mt76_phy *phy, int idx, int n_desc,
2766c92544dSBjoern A. Zeeb int ring_base, u32 flags)
2776c92544dSBjoern A. Zeeb {
2786c92544dSBjoern A. Zeeb int i, err;
2796c92544dSBjoern A. Zeeb
2806c92544dSBjoern A. Zeeb err = mt76_init_tx_queue(phy, 0, idx, n_desc, ring_base, flags);
2816c92544dSBjoern A. Zeeb if (err < 0)
2826c92544dSBjoern A. Zeeb return err;
2836c92544dSBjoern A. Zeeb
2846c92544dSBjoern A. Zeeb for (i = 1; i <= MT_TXQ_PSD; i++)
2856c92544dSBjoern A. Zeeb phy->q_tx[i] = phy->q_tx[0];
2866c92544dSBjoern A. Zeeb
2876c92544dSBjoern A. Zeeb return 0;
2886c92544dSBjoern A. Zeeb }
2896c92544dSBjoern A. Zeeb EXPORT_SYMBOL_GPL(mt76_connac_init_tx_queues);
2906c92544dSBjoern A. Zeeb
291*cbb3ec25SBjoern A. Zeeb #define __bitrate_mask_check(_mcs, _mode) \
292*cbb3ec25SBjoern A. Zeeb ({ \
293*cbb3ec25SBjoern A. Zeeb u8 i = 0; \
294*cbb3ec25SBjoern A. Zeeb for (nss = 0; i < ARRAY_SIZE(mask->control[band]._mcs); i++) { \
295*cbb3ec25SBjoern A. Zeeb if (!mask->control[band]._mcs[i]) \
296*cbb3ec25SBjoern A. Zeeb continue; \
297*cbb3ec25SBjoern A. Zeeb if (hweight16(mask->control[band]._mcs[i]) == 1) { \
298*cbb3ec25SBjoern A. Zeeb mode = MT_PHY_TYPE_##_mode; \
299*cbb3ec25SBjoern A. Zeeb rateidx = ffs(mask->control[band]._mcs[i]) - 1; \
300*cbb3ec25SBjoern A. Zeeb if (mode == MT_PHY_TYPE_HT) \
301*cbb3ec25SBjoern A. Zeeb rateidx += 8 * i; \
302*cbb3ec25SBjoern A. Zeeb else \
303*cbb3ec25SBjoern A. Zeeb nss = i + 1; \
304*cbb3ec25SBjoern A. Zeeb goto out; \
305*cbb3ec25SBjoern A. Zeeb } \
306*cbb3ec25SBjoern A. Zeeb } \
307*cbb3ec25SBjoern A. Zeeb })
308*cbb3ec25SBjoern A. Zeeb
mt76_connac2_mac_tx_rate_val(struct mt76_phy * mphy,struct ieee80211_vif * vif,bool beacon,bool mcast)309*cbb3ec25SBjoern A. Zeeb u16 mt76_connac2_mac_tx_rate_val(struct mt76_phy *mphy,
310*cbb3ec25SBjoern A. Zeeb struct ieee80211_vif *vif,
3116c92544dSBjoern A. Zeeb bool beacon, bool mcast)
3126c92544dSBjoern A. Zeeb {
313*cbb3ec25SBjoern A. Zeeb u8 nss = 0, mode = 0, band = mphy->chandef.chan->band;
3146c92544dSBjoern A. Zeeb int rateidx = 0, mcast_rate;
3156c92544dSBjoern A. Zeeb
3166c92544dSBjoern A. Zeeb if (!vif)
3176c92544dSBjoern A. Zeeb goto legacy;
3186c92544dSBjoern A. Zeeb
3196c92544dSBjoern A. Zeeb if (is_mt7921(mphy->dev)) {
3206c92544dSBjoern A. Zeeb rateidx = ffs(vif->bss_conf.basic_rates) - 1;
3216c92544dSBjoern A. Zeeb goto legacy;
3226c92544dSBjoern A. Zeeb }
3236c92544dSBjoern A. Zeeb
3246c92544dSBjoern A. Zeeb if (beacon) {
3256c92544dSBjoern A. Zeeb struct cfg80211_bitrate_mask *mask;
3266c92544dSBjoern A. Zeeb
3276c92544dSBjoern A. Zeeb mask = &vif->bss_conf.beacon_tx_rate;
328*cbb3ec25SBjoern A. Zeeb
329*cbb3ec25SBjoern A. Zeeb __bitrate_mask_check(he_mcs, HE_SU);
330*cbb3ec25SBjoern A. Zeeb __bitrate_mask_check(vht_mcs, VHT);
331*cbb3ec25SBjoern A. Zeeb __bitrate_mask_check(ht_mcs, HT);
332*cbb3ec25SBjoern A. Zeeb
333*cbb3ec25SBjoern A. Zeeb if (hweight32(mask->control[band].legacy) == 1) {
3346c92544dSBjoern A. Zeeb rateidx = ffs(mask->control[band].legacy) - 1;
3356c92544dSBjoern A. Zeeb goto legacy;
3366c92544dSBjoern A. Zeeb }
3376c92544dSBjoern A. Zeeb }
3386c92544dSBjoern A. Zeeb
3396c92544dSBjoern A. Zeeb mcast_rate = vif->bss_conf.mcast_rate[band];
3406c92544dSBjoern A. Zeeb if (mcast && mcast_rate > 0)
3416c92544dSBjoern A. Zeeb rateidx = mcast_rate - 1;
3426c92544dSBjoern A. Zeeb else
3436c92544dSBjoern A. Zeeb rateidx = ffs(vif->bss_conf.basic_rates) - 1;
3446c92544dSBjoern A. Zeeb
3456c92544dSBjoern A. Zeeb legacy:
3466c92544dSBjoern A. Zeeb rateidx = mt76_calculate_default_rate(mphy, rateidx);
3476c92544dSBjoern A. Zeeb mode = rateidx >> 8;
3486c92544dSBjoern A. Zeeb rateidx &= GENMASK(7, 0);
3496c92544dSBjoern A. Zeeb out:
350*cbb3ec25SBjoern A. Zeeb return FIELD_PREP(MT_TX_RATE_NSS, nss) |
351*cbb3ec25SBjoern A. Zeeb FIELD_PREP(MT_TX_RATE_IDX, rateidx) |
3526c92544dSBjoern A. Zeeb FIELD_PREP(MT_TX_RATE_MODE, mode);
3536c92544dSBjoern A. Zeeb }
354*cbb3ec25SBjoern A. Zeeb EXPORT_SYMBOL_GPL(mt76_connac2_mac_tx_rate_val);
3556c92544dSBjoern A. Zeeb
3566c92544dSBjoern A. Zeeb static void
mt76_connac2_mac_write_txwi_8023(__le32 * txwi,struct sk_buff * skb,struct mt76_wcid * wcid)3576c92544dSBjoern A. Zeeb mt76_connac2_mac_write_txwi_8023(__le32 *txwi, struct sk_buff *skb,
3586c92544dSBjoern A. Zeeb struct mt76_wcid *wcid)
3596c92544dSBjoern A. Zeeb {
3606c92544dSBjoern A. Zeeb u8 tid = skb->priority & IEEE80211_QOS_CTL_TID_MASK;
3616c92544dSBjoern A. Zeeb u8 fc_type, fc_stype;
3626c92544dSBjoern A. Zeeb u16 ethertype;
3636c92544dSBjoern A. Zeeb bool wmm = false;
3646c92544dSBjoern A. Zeeb u32 val;
3656c92544dSBjoern A. Zeeb
3666c92544dSBjoern A. Zeeb if (wcid->sta) {
3676c92544dSBjoern A. Zeeb struct ieee80211_sta *sta;
3686c92544dSBjoern A. Zeeb
3696c92544dSBjoern A. Zeeb sta = container_of((void *)wcid, struct ieee80211_sta, drv_priv);
3706c92544dSBjoern A. Zeeb wmm = sta->wme;
3716c92544dSBjoern A. Zeeb }
3726c92544dSBjoern A. Zeeb
3736c92544dSBjoern A. Zeeb val = FIELD_PREP(MT_TXD1_HDR_FORMAT, MT_HDR_FORMAT_802_3) |
3746c92544dSBjoern A. Zeeb FIELD_PREP(MT_TXD1_TID, tid);
3756c92544dSBjoern A. Zeeb
3766c92544dSBjoern A. Zeeb ethertype = get_unaligned_be16(&skb->data[12]);
3776c92544dSBjoern A. Zeeb if (ethertype >= ETH_P_802_3_MIN)
3786c92544dSBjoern A. Zeeb val |= MT_TXD1_ETH_802_3;
3796c92544dSBjoern A. Zeeb
3806c92544dSBjoern A. Zeeb txwi[1] |= cpu_to_le32(val);
3816c92544dSBjoern A. Zeeb
3826c92544dSBjoern A. Zeeb fc_type = IEEE80211_FTYPE_DATA >> 2;
3836c92544dSBjoern A. Zeeb fc_stype = wmm ? IEEE80211_STYPE_QOS_DATA >> 4 : 0;
3846c92544dSBjoern A. Zeeb
3856c92544dSBjoern A. Zeeb val = FIELD_PREP(MT_TXD2_FRAME_TYPE, fc_type) |
3866c92544dSBjoern A. Zeeb FIELD_PREP(MT_TXD2_SUB_TYPE, fc_stype);
3876c92544dSBjoern A. Zeeb
3886c92544dSBjoern A. Zeeb txwi[2] |= cpu_to_le32(val);
3896c92544dSBjoern A. Zeeb
3906c92544dSBjoern A. Zeeb val = FIELD_PREP(MT_TXD7_TYPE, fc_type) |
3916c92544dSBjoern A. Zeeb FIELD_PREP(MT_TXD7_SUB_TYPE, fc_stype);
3926c92544dSBjoern A. Zeeb
3936c92544dSBjoern A. Zeeb txwi[7] |= cpu_to_le32(val);
3946c92544dSBjoern A. Zeeb }
3956c92544dSBjoern A. Zeeb
3966c92544dSBjoern A. Zeeb static void
mt76_connac2_mac_write_txwi_80211(struct mt76_dev * dev,__le32 * txwi,struct sk_buff * skb,struct ieee80211_key_conf * key)3976c92544dSBjoern A. Zeeb mt76_connac2_mac_write_txwi_80211(struct mt76_dev *dev, __le32 *txwi,
3986c92544dSBjoern A. Zeeb struct sk_buff *skb,
3996c92544dSBjoern A. Zeeb struct ieee80211_key_conf *key)
4006c92544dSBjoern A. Zeeb {
4016c92544dSBjoern A. Zeeb struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
4026c92544dSBjoern A. Zeeb struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data;
4036c92544dSBjoern A. Zeeb struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
4046c92544dSBjoern A. Zeeb bool multicast = is_multicast_ether_addr(hdr->addr1);
4056c92544dSBjoern A. Zeeb u8 tid = skb->priority & IEEE80211_QOS_CTL_TID_MASK;
4066c92544dSBjoern A. Zeeb __le16 fc = hdr->frame_control;
4076c92544dSBjoern A. Zeeb u8 fc_type, fc_stype;
4086c92544dSBjoern A. Zeeb u32 val;
4096c92544dSBjoern A. Zeeb
4106c92544dSBjoern A. Zeeb if (ieee80211_is_action(fc) &&
4116c92544dSBjoern A. Zeeb mgmt->u.action.category == WLAN_CATEGORY_BACK &&
4126c92544dSBjoern A. Zeeb mgmt->u.action.u.addba_req.action_code == WLAN_ACTION_ADDBA_REQ) {
4136c92544dSBjoern A. Zeeb u16 capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab);
4146c92544dSBjoern A. Zeeb
4156c92544dSBjoern A. Zeeb txwi[5] |= cpu_to_le32(MT_TXD5_ADD_BA);
4166c92544dSBjoern A. Zeeb tid = (capab >> 2) & IEEE80211_QOS_CTL_TID_MASK;
4176c92544dSBjoern A. Zeeb } else if (ieee80211_is_back_req(hdr->frame_control)) {
4186c92544dSBjoern A. Zeeb struct ieee80211_bar *bar = (struct ieee80211_bar *)hdr;
4196c92544dSBjoern A. Zeeb u16 control = le16_to_cpu(bar->control);
4206c92544dSBjoern A. Zeeb
4216c92544dSBjoern A. Zeeb tid = FIELD_GET(IEEE80211_BAR_CTRL_TID_INFO_MASK, control);
4226c92544dSBjoern A. Zeeb }
4236c92544dSBjoern A. Zeeb
4246c92544dSBjoern A. Zeeb val = FIELD_PREP(MT_TXD1_HDR_FORMAT, MT_HDR_FORMAT_802_11) |
4256c92544dSBjoern A. Zeeb FIELD_PREP(MT_TXD1_HDR_INFO,
4266c92544dSBjoern A. Zeeb ieee80211_get_hdrlen_from_skb(skb) / 2) |
4276c92544dSBjoern A. Zeeb FIELD_PREP(MT_TXD1_TID, tid);
4286c92544dSBjoern A. Zeeb
4296c92544dSBjoern A. Zeeb txwi[1] |= cpu_to_le32(val);
4306c92544dSBjoern A. Zeeb
4316c92544dSBjoern A. Zeeb fc_type = (le16_to_cpu(fc) & IEEE80211_FCTL_FTYPE) >> 2;
4326c92544dSBjoern A. Zeeb fc_stype = (le16_to_cpu(fc) & IEEE80211_FCTL_STYPE) >> 4;
4336c92544dSBjoern A. Zeeb
4346c92544dSBjoern A. Zeeb val = FIELD_PREP(MT_TXD2_FRAME_TYPE, fc_type) |
4356c92544dSBjoern A. Zeeb FIELD_PREP(MT_TXD2_SUB_TYPE, fc_stype) |
4366c92544dSBjoern A. Zeeb FIELD_PREP(MT_TXD2_MULTICAST, multicast);
4376c92544dSBjoern A. Zeeb
4386c92544dSBjoern A. Zeeb if (key && multicast && ieee80211_is_robust_mgmt_frame(skb) &&
4396c92544dSBjoern A. Zeeb key->cipher == WLAN_CIPHER_SUITE_AES_CMAC) {
4406c92544dSBjoern A. Zeeb val |= MT_TXD2_BIP;
4416c92544dSBjoern A. Zeeb txwi[3] &= ~cpu_to_le32(MT_TXD3_PROTECT_FRAME);
4426c92544dSBjoern A. Zeeb }
4436c92544dSBjoern A. Zeeb
4446c92544dSBjoern A. Zeeb if (!ieee80211_is_data(fc) || multicast ||
4456c92544dSBjoern A. Zeeb info->flags & IEEE80211_TX_CTL_USE_MINRATE)
4466c92544dSBjoern A. Zeeb val |= MT_TXD2_FIX_RATE;
4476c92544dSBjoern A. Zeeb
4486c92544dSBjoern A. Zeeb txwi[2] |= cpu_to_le32(val);
4496c92544dSBjoern A. Zeeb
4506c92544dSBjoern A. Zeeb if (ieee80211_is_beacon(fc)) {
4516c92544dSBjoern A. Zeeb txwi[3] &= ~cpu_to_le32(MT_TXD3_SW_POWER_MGMT);
4526c92544dSBjoern A. Zeeb txwi[3] |= cpu_to_le32(MT_TXD3_REM_TX_COUNT);
4536c92544dSBjoern A. Zeeb }
4546c92544dSBjoern A. Zeeb
4556c92544dSBjoern A. Zeeb if (info->flags & IEEE80211_TX_CTL_INJECTED) {
4566c92544dSBjoern A. Zeeb u16 seqno = le16_to_cpu(hdr->seq_ctrl);
4576c92544dSBjoern A. Zeeb
4586c92544dSBjoern A. Zeeb if (ieee80211_is_back_req(hdr->frame_control)) {
4596c92544dSBjoern A. Zeeb struct ieee80211_bar *bar;
4606c92544dSBjoern A. Zeeb
4616c92544dSBjoern A. Zeeb bar = (struct ieee80211_bar *)skb->data;
4626c92544dSBjoern A. Zeeb seqno = le16_to_cpu(bar->start_seq_num);
4636c92544dSBjoern A. Zeeb }
4646c92544dSBjoern A. Zeeb
4656c92544dSBjoern A. Zeeb val = MT_TXD3_SN_VALID |
4666c92544dSBjoern A. Zeeb FIELD_PREP(MT_TXD3_SEQ, IEEE80211_SEQ_TO_SN(seqno));
4676c92544dSBjoern A. Zeeb txwi[3] |= cpu_to_le32(val);
4686c92544dSBjoern A. Zeeb txwi[7] &= ~cpu_to_le32(MT_TXD7_HW_AMSDU);
4696c92544dSBjoern A. Zeeb }
4706c92544dSBjoern A. Zeeb
4716c92544dSBjoern A. Zeeb if (mt76_is_mmio(dev)) {
4726c92544dSBjoern A. Zeeb val = FIELD_PREP(MT_TXD7_TYPE, fc_type) |
4736c92544dSBjoern A. Zeeb FIELD_PREP(MT_TXD7_SUB_TYPE, fc_stype);
4746c92544dSBjoern A. Zeeb txwi[7] |= cpu_to_le32(val);
4756c92544dSBjoern A. Zeeb } else {
4766c92544dSBjoern A. Zeeb val = FIELD_PREP(MT_TXD8_L_TYPE, fc_type) |
4776c92544dSBjoern A. Zeeb FIELD_PREP(MT_TXD8_L_SUB_TYPE, fc_stype);
4786c92544dSBjoern A. Zeeb txwi[8] |= cpu_to_le32(val);
4796c92544dSBjoern A. Zeeb }
4806c92544dSBjoern A. Zeeb }
4816c92544dSBjoern A. Zeeb
mt76_connac2_mac_write_txwi(struct mt76_dev * dev,__le32 * txwi,struct sk_buff * skb,struct mt76_wcid * wcid,struct ieee80211_key_conf * key,int pid,enum mt76_txq_id qid,u32 changed)4826c92544dSBjoern A. Zeeb void mt76_connac2_mac_write_txwi(struct mt76_dev *dev, __le32 *txwi,
4836c92544dSBjoern A. Zeeb struct sk_buff *skb, struct mt76_wcid *wcid,
4846c92544dSBjoern A. Zeeb struct ieee80211_key_conf *key, int pid,
4856c92544dSBjoern A. Zeeb enum mt76_txq_id qid, u32 changed)
4866c92544dSBjoern A. Zeeb {
4876c92544dSBjoern A. Zeeb struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
4886c92544dSBjoern A. Zeeb u8 phy_idx = (info->hw_queue & MT_TX_HW_QUEUE_PHY) >> 2;
4896c92544dSBjoern A. Zeeb struct ieee80211_vif *vif = info->control.vif;
4906c92544dSBjoern A. Zeeb struct mt76_phy *mphy = &dev->phy;
4916c92544dSBjoern A. Zeeb u8 p_fmt, q_idx, omac_idx = 0, wmm_idx = 0, band_idx = 0;
4926c92544dSBjoern A. Zeeb u32 val, sz_txd = mt76_is_mmio(dev) ? MT_TXD_SIZE : MT_SDIO_TXD_SIZE;
4936c92544dSBjoern A. Zeeb bool is_8023 = info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP;
4946c92544dSBjoern A. Zeeb bool beacon = !!(changed & (BSS_CHANGED_BEACON |
4956c92544dSBjoern A. Zeeb BSS_CHANGED_BEACON_ENABLED));
4966c92544dSBjoern A. Zeeb bool inband_disc = !!(changed & (BSS_CHANGED_UNSOL_BCAST_PROBE_RESP |
4976c92544dSBjoern A. Zeeb BSS_CHANGED_FILS_DISCOVERY));
498*cbb3ec25SBjoern A. Zeeb bool amsdu_en = wcid->amsdu;
4996c92544dSBjoern A. Zeeb
5006c92544dSBjoern A. Zeeb if (vif) {
5016c92544dSBjoern A. Zeeb struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv;
5026c92544dSBjoern A. Zeeb
5036c92544dSBjoern A. Zeeb omac_idx = mvif->omac_idx;
5046c92544dSBjoern A. Zeeb wmm_idx = mvif->wmm_idx;
5056c92544dSBjoern A. Zeeb band_idx = mvif->band_idx;
5066c92544dSBjoern A. Zeeb }
5076c92544dSBjoern A. Zeeb
5086c92544dSBjoern A. Zeeb if (phy_idx && dev->phys[MT_BAND1])
5096c92544dSBjoern A. Zeeb mphy = dev->phys[MT_BAND1];
5106c92544dSBjoern A. Zeeb
5116c92544dSBjoern A. Zeeb if (inband_disc) {
5126c92544dSBjoern A. Zeeb p_fmt = MT_TX_TYPE_FW;
5136c92544dSBjoern A. Zeeb q_idx = MT_LMAC_ALTX0;
5146c92544dSBjoern A. Zeeb } else if (beacon) {
5156c92544dSBjoern A. Zeeb p_fmt = MT_TX_TYPE_FW;
5166c92544dSBjoern A. Zeeb q_idx = MT_LMAC_BCN0;
5176c92544dSBjoern A. Zeeb } else if (qid >= MT_TXQ_PSD) {
5186c92544dSBjoern A. Zeeb p_fmt = mt76_is_mmio(dev) ? MT_TX_TYPE_CT : MT_TX_TYPE_SF;
5196c92544dSBjoern A. Zeeb q_idx = MT_LMAC_ALTX0;
5206c92544dSBjoern A. Zeeb } else {
5216c92544dSBjoern A. Zeeb p_fmt = mt76_is_mmio(dev) ? MT_TX_TYPE_CT : MT_TX_TYPE_SF;
5226c92544dSBjoern A. Zeeb q_idx = wmm_idx * MT76_CONNAC_MAX_WMM_SETS +
5236c92544dSBjoern A. Zeeb mt76_connac_lmac_mapping(skb_get_queue_mapping(skb));
5246c92544dSBjoern A. Zeeb
525*cbb3ec25SBjoern A. Zeeb /* mt7915 WA only counts WED path */
526*cbb3ec25SBjoern A. Zeeb if (is_mt7915(dev) && mtk_wed_device_active(&dev->mmio.wed))
5276c92544dSBjoern A. Zeeb wcid->stats.tx_packets++;
5286c92544dSBjoern A. Zeeb }
5296c92544dSBjoern A. Zeeb
5306c92544dSBjoern A. Zeeb val = FIELD_PREP(MT_TXD0_TX_BYTES, skb->len + sz_txd) |
5316c92544dSBjoern A. Zeeb FIELD_PREP(MT_TXD0_PKT_FMT, p_fmt) |
5326c92544dSBjoern A. Zeeb FIELD_PREP(MT_TXD0_Q_IDX, q_idx);
5336c92544dSBjoern A. Zeeb txwi[0] = cpu_to_le32(val);
5346c92544dSBjoern A. Zeeb
5356c92544dSBjoern A. Zeeb val = MT_TXD1_LONG_FORMAT |
5366c92544dSBjoern A. Zeeb FIELD_PREP(MT_TXD1_WLAN_IDX, wcid->idx) |
5376c92544dSBjoern A. Zeeb FIELD_PREP(MT_TXD1_OWN_MAC, omac_idx);
5386c92544dSBjoern A. Zeeb if (!is_mt7921(dev))
5396c92544dSBjoern A. Zeeb val |= MT_TXD1_VTA;
5406c92544dSBjoern A. Zeeb if (phy_idx || band_idx)
5416c92544dSBjoern A. Zeeb val |= MT_TXD1_TGID;
5426c92544dSBjoern A. Zeeb
5436c92544dSBjoern A. Zeeb txwi[1] = cpu_to_le32(val);
5446c92544dSBjoern A. Zeeb txwi[2] = 0;
5456c92544dSBjoern A. Zeeb
5466c92544dSBjoern A. Zeeb val = FIELD_PREP(MT_TXD3_REM_TX_COUNT, 15);
5476c92544dSBjoern A. Zeeb if (!is_mt7921(dev))
5486c92544dSBjoern A. Zeeb val |= MT_TXD3_SW_POWER_MGMT;
5496c92544dSBjoern A. Zeeb if (key)
5506c92544dSBjoern A. Zeeb val |= MT_TXD3_PROTECT_FRAME;
5516c92544dSBjoern A. Zeeb if (info->flags & IEEE80211_TX_CTL_NO_ACK)
5526c92544dSBjoern A. Zeeb val |= MT_TXD3_NO_ACK;
5536c92544dSBjoern A. Zeeb
5546c92544dSBjoern A. Zeeb txwi[3] = cpu_to_le32(val);
5556c92544dSBjoern A. Zeeb txwi[4] = 0;
5566c92544dSBjoern A. Zeeb
5576c92544dSBjoern A. Zeeb val = FIELD_PREP(MT_TXD5_PID, pid);
558*cbb3ec25SBjoern A. Zeeb if (pid >= MT_PACKET_ID_FIRST) {
5596c92544dSBjoern A. Zeeb val |= MT_TXD5_TX_STATUS_HOST;
560*cbb3ec25SBjoern A. Zeeb amsdu_en = amsdu_en && !is_mt7921(dev);
561*cbb3ec25SBjoern A. Zeeb }
5626c92544dSBjoern A. Zeeb
5636c92544dSBjoern A. Zeeb txwi[5] = cpu_to_le32(val);
5646c92544dSBjoern A. Zeeb txwi[6] = 0;
565*cbb3ec25SBjoern A. Zeeb txwi[7] = amsdu_en ? cpu_to_le32(MT_TXD7_HW_AMSDU) : 0;
5666c92544dSBjoern A. Zeeb
5676c92544dSBjoern A. Zeeb if (is_8023)
5686c92544dSBjoern A. Zeeb mt76_connac2_mac_write_txwi_8023(txwi, skb, wcid);
5696c92544dSBjoern A. Zeeb else
5706c92544dSBjoern A. Zeeb mt76_connac2_mac_write_txwi_80211(dev, txwi, skb, key);
5716c92544dSBjoern A. Zeeb
5726c92544dSBjoern A. Zeeb if (txwi[2] & cpu_to_le32(MT_TXD2_FIX_RATE)) {
5736c92544dSBjoern A. Zeeb /* Fixed rata is available just for 802.11 txd */
5746c92544dSBjoern A. Zeeb struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
575*cbb3ec25SBjoern A. Zeeb bool multicast = ieee80211_is_data(hdr->frame_control) &&
576*cbb3ec25SBjoern A. Zeeb is_multicast_ether_addr(hdr->addr1);
5776c92544dSBjoern A. Zeeb u16 rate = mt76_connac2_mac_tx_rate_val(mphy, vif, beacon,
5786c92544dSBjoern A. Zeeb multicast);
5796c92544dSBjoern A. Zeeb u32 val = MT_TXD6_FIXED_BW;
5806c92544dSBjoern A. Zeeb
5816c92544dSBjoern A. Zeeb /* hardware won't add HTC for mgmt/ctrl frame */
5826c92544dSBjoern A. Zeeb txwi[2] |= cpu_to_le32(MT_TXD2_HTC_VLD);
5836c92544dSBjoern A. Zeeb
5846c92544dSBjoern A. Zeeb val |= FIELD_PREP(MT_TXD6_TX_RATE, rate);
5856c92544dSBjoern A. Zeeb txwi[6] |= cpu_to_le32(val);
5866c92544dSBjoern A. Zeeb txwi[3] |= cpu_to_le32(MT_TXD3_BA_DISABLE);
587*cbb3ec25SBjoern A. Zeeb
588*cbb3ec25SBjoern A. Zeeb if (!is_mt7921(dev)) {
589*cbb3ec25SBjoern A. Zeeb u8 spe_idx = mt76_connac_spe_idx(mphy->antenna_mask);
590*cbb3ec25SBjoern A. Zeeb
591*cbb3ec25SBjoern A. Zeeb if (!spe_idx)
592*cbb3ec25SBjoern A. Zeeb spe_idx = 24 + phy_idx;
593*cbb3ec25SBjoern A. Zeeb txwi[7] |= cpu_to_le32(FIELD_PREP(MT_TXD7_SPE_IDX, spe_idx));
594*cbb3ec25SBjoern A. Zeeb }
5956c92544dSBjoern A. Zeeb }
5966c92544dSBjoern A. Zeeb }
5976c92544dSBjoern A. Zeeb EXPORT_SYMBOL_GPL(mt76_connac2_mac_write_txwi);
5986c92544dSBjoern A. Zeeb
mt76_connac2_mac_fill_txs(struct mt76_dev * dev,struct mt76_wcid * wcid,__le32 * txs_data)5996c92544dSBjoern A. Zeeb bool mt76_connac2_mac_fill_txs(struct mt76_dev *dev, struct mt76_wcid *wcid,
6006c92544dSBjoern A. Zeeb __le32 *txs_data)
6016c92544dSBjoern A. Zeeb {
6026c92544dSBjoern A. Zeeb struct mt76_sta_stats *stats = &wcid->stats;
6036c92544dSBjoern A. Zeeb struct ieee80211_supported_band *sband;
6046c92544dSBjoern A. Zeeb struct mt76_phy *mphy;
6056c92544dSBjoern A. Zeeb struct rate_info rate = {};
6066c92544dSBjoern A. Zeeb bool cck = false;
607*cbb3ec25SBjoern A. Zeeb u32 txrate, txs, mode, stbc;
6086c92544dSBjoern A. Zeeb
6096c92544dSBjoern A. Zeeb txs = le32_to_cpu(txs_data[0]);
6106c92544dSBjoern A. Zeeb
6116c92544dSBjoern A. Zeeb /* PPDU based reporting */
612*cbb3ec25SBjoern A. Zeeb if (mtk_wed_device_active(&dev->mmio.wed) &&
613*cbb3ec25SBjoern A. Zeeb FIELD_GET(MT_TXS0_TXS_FORMAT, txs) > 1) {
6146c92544dSBjoern A. Zeeb stats->tx_bytes +=
615*cbb3ec25SBjoern A. Zeeb le32_get_bits(txs_data[5], MT_TXS5_MPDU_TX_BYTE) -
616*cbb3ec25SBjoern A. Zeeb le32_get_bits(txs_data[7], MT_TXS7_MPDU_RETRY_BYTE);
6176c92544dSBjoern A. Zeeb stats->tx_failed +=
6186c92544dSBjoern A. Zeeb le32_get_bits(txs_data[6], MT_TXS6_MPDU_FAIL_CNT);
6196c92544dSBjoern A. Zeeb stats->tx_retries +=
6206c92544dSBjoern A. Zeeb le32_get_bits(txs_data[7], MT_TXS7_MPDU_RETRY_CNT);
621*cbb3ec25SBjoern A. Zeeb
622*cbb3ec25SBjoern A. Zeeb if (wcid->sta) {
623*cbb3ec25SBjoern A. Zeeb struct ieee80211_sta *sta;
624*cbb3ec25SBjoern A. Zeeb u8 tid;
625*cbb3ec25SBjoern A. Zeeb
626*cbb3ec25SBjoern A. Zeeb sta = container_of((void *)wcid, struct ieee80211_sta,
627*cbb3ec25SBjoern A. Zeeb drv_priv);
628*cbb3ec25SBjoern A. Zeeb tid = FIELD_GET(MT_TXS0_TID, txs);
629*cbb3ec25SBjoern A. Zeeb
630*cbb3ec25SBjoern A. Zeeb ieee80211_refresh_tx_agg_session_timer(sta, tid);
631*cbb3ec25SBjoern A. Zeeb }
6326c92544dSBjoern A. Zeeb }
6336c92544dSBjoern A. Zeeb
6346c92544dSBjoern A. Zeeb txrate = FIELD_GET(MT_TXS0_TX_RATE, txs);
6356c92544dSBjoern A. Zeeb
6366c92544dSBjoern A. Zeeb rate.mcs = FIELD_GET(MT_TX_RATE_IDX, txrate);
6376c92544dSBjoern A. Zeeb rate.nss = FIELD_GET(MT_TX_RATE_NSS, txrate) + 1;
638*cbb3ec25SBjoern A. Zeeb stbc = FIELD_GET(MT_TX_RATE_STBC, txrate);
639*cbb3ec25SBjoern A. Zeeb
640*cbb3ec25SBjoern A. Zeeb if (stbc && rate.nss > 1)
641*cbb3ec25SBjoern A. Zeeb rate.nss >>= 1;
6426c92544dSBjoern A. Zeeb
6436c92544dSBjoern A. Zeeb if (rate.nss - 1 < ARRAY_SIZE(stats->tx_nss))
6446c92544dSBjoern A. Zeeb stats->tx_nss[rate.nss - 1]++;
6456c92544dSBjoern A. Zeeb if (rate.mcs < ARRAY_SIZE(stats->tx_mcs))
6466c92544dSBjoern A. Zeeb stats->tx_mcs[rate.mcs]++;
6476c92544dSBjoern A. Zeeb
6486c92544dSBjoern A. Zeeb mode = FIELD_GET(MT_TX_RATE_MODE, txrate);
6496c92544dSBjoern A. Zeeb switch (mode) {
6506c92544dSBjoern A. Zeeb case MT_PHY_TYPE_CCK:
6516c92544dSBjoern A. Zeeb cck = true;
6526c92544dSBjoern A. Zeeb fallthrough;
6536c92544dSBjoern A. Zeeb case MT_PHY_TYPE_OFDM:
6546c92544dSBjoern A. Zeeb mphy = &dev->phy;
6556c92544dSBjoern A. Zeeb if (wcid->phy_idx == MT_BAND1 && dev->phys[MT_BAND1])
6566c92544dSBjoern A. Zeeb mphy = dev->phys[MT_BAND1];
6576c92544dSBjoern A. Zeeb
6586c92544dSBjoern A. Zeeb if (mphy->chandef.chan->band == NL80211_BAND_5GHZ)
6596c92544dSBjoern A. Zeeb sband = &mphy->sband_5g.sband;
6606c92544dSBjoern A. Zeeb else if (mphy->chandef.chan->band == NL80211_BAND_6GHZ)
6616c92544dSBjoern A. Zeeb sband = &mphy->sband_6g.sband;
6626c92544dSBjoern A. Zeeb else
6636c92544dSBjoern A. Zeeb sband = &mphy->sband_2g.sband;
6646c92544dSBjoern A. Zeeb
6656c92544dSBjoern A. Zeeb rate.mcs = mt76_get_rate(mphy->dev, sband, rate.mcs, cck);
6666c92544dSBjoern A. Zeeb rate.legacy = sband->bitrates[rate.mcs].bitrate;
6676c92544dSBjoern A. Zeeb break;
6686c92544dSBjoern A. Zeeb case MT_PHY_TYPE_HT:
6696c92544dSBjoern A. Zeeb case MT_PHY_TYPE_HT_GF:
6706c92544dSBjoern A. Zeeb if (rate.mcs > 31)
6716c92544dSBjoern A. Zeeb return false;
6726c92544dSBjoern A. Zeeb
6736c92544dSBjoern A. Zeeb rate.flags = RATE_INFO_FLAGS_MCS;
6746c92544dSBjoern A. Zeeb if (wcid->rate.flags & RATE_INFO_FLAGS_SHORT_GI)
6756c92544dSBjoern A. Zeeb rate.flags |= RATE_INFO_FLAGS_SHORT_GI;
6766c92544dSBjoern A. Zeeb break;
6776c92544dSBjoern A. Zeeb case MT_PHY_TYPE_VHT:
6786c92544dSBjoern A. Zeeb if (rate.mcs > 9)
6796c92544dSBjoern A. Zeeb return false;
6806c92544dSBjoern A. Zeeb
6816c92544dSBjoern A. Zeeb rate.flags = RATE_INFO_FLAGS_VHT_MCS;
6826c92544dSBjoern A. Zeeb break;
6836c92544dSBjoern A. Zeeb case MT_PHY_TYPE_HE_SU:
6846c92544dSBjoern A. Zeeb case MT_PHY_TYPE_HE_EXT_SU:
6856c92544dSBjoern A. Zeeb case MT_PHY_TYPE_HE_TB:
6866c92544dSBjoern A. Zeeb case MT_PHY_TYPE_HE_MU:
6876c92544dSBjoern A. Zeeb if (rate.mcs > 11)
6886c92544dSBjoern A. Zeeb return false;
6896c92544dSBjoern A. Zeeb
6906c92544dSBjoern A. Zeeb rate.he_gi = wcid->rate.he_gi;
6916c92544dSBjoern A. Zeeb rate.he_dcm = FIELD_GET(MT_TX_RATE_DCM, txrate);
6926c92544dSBjoern A. Zeeb rate.flags = RATE_INFO_FLAGS_HE_MCS;
6936c92544dSBjoern A. Zeeb break;
6946c92544dSBjoern A. Zeeb default:
6956c92544dSBjoern A. Zeeb return false;
6966c92544dSBjoern A. Zeeb }
6976c92544dSBjoern A. Zeeb
6986c92544dSBjoern A. Zeeb stats->tx_mode[mode]++;
6996c92544dSBjoern A. Zeeb
7006c92544dSBjoern A. Zeeb switch (FIELD_GET(MT_TXS0_BW, txs)) {
7016c92544dSBjoern A. Zeeb case IEEE80211_STA_RX_BW_160:
7026c92544dSBjoern A. Zeeb rate.bw = RATE_INFO_BW_160;
7036c92544dSBjoern A. Zeeb stats->tx_bw[3]++;
7046c92544dSBjoern A. Zeeb break;
7056c92544dSBjoern A. Zeeb case IEEE80211_STA_RX_BW_80:
7066c92544dSBjoern A. Zeeb rate.bw = RATE_INFO_BW_80;
7076c92544dSBjoern A. Zeeb stats->tx_bw[2]++;
7086c92544dSBjoern A. Zeeb break;
7096c92544dSBjoern A. Zeeb case IEEE80211_STA_RX_BW_40:
7106c92544dSBjoern A. Zeeb rate.bw = RATE_INFO_BW_40;
7116c92544dSBjoern A. Zeeb stats->tx_bw[1]++;
7126c92544dSBjoern A. Zeeb break;
7136c92544dSBjoern A. Zeeb default:
7146c92544dSBjoern A. Zeeb rate.bw = RATE_INFO_BW_20;
7156c92544dSBjoern A. Zeeb stats->tx_bw[0]++;
7166c92544dSBjoern A. Zeeb break;
7176c92544dSBjoern A. Zeeb }
7186c92544dSBjoern A. Zeeb wcid->rate = rate;
7196c92544dSBjoern A. Zeeb
7206c92544dSBjoern A. Zeeb return true;
7216c92544dSBjoern A. Zeeb }
7226c92544dSBjoern A. Zeeb EXPORT_SYMBOL_GPL(mt76_connac2_mac_fill_txs);
7236c92544dSBjoern A. Zeeb
mt76_connac2_mac_add_txs_skb(struct mt76_dev * dev,struct mt76_wcid * wcid,int pid,__le32 * txs_data)7246c92544dSBjoern A. Zeeb bool mt76_connac2_mac_add_txs_skb(struct mt76_dev *dev, struct mt76_wcid *wcid,
7256c92544dSBjoern A. Zeeb int pid, __le32 *txs_data)
7266c92544dSBjoern A. Zeeb {
7276c92544dSBjoern A. Zeeb struct sk_buff_head list;
7286c92544dSBjoern A. Zeeb struct sk_buff *skb;
7296c92544dSBjoern A. Zeeb
7306c92544dSBjoern A. Zeeb mt76_tx_status_lock(dev, &list);
7316c92544dSBjoern A. Zeeb skb = mt76_tx_status_skb_get(dev, wcid, pid, &list);
7326c92544dSBjoern A. Zeeb if (skb) {
7336c92544dSBjoern A. Zeeb struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
7346c92544dSBjoern A. Zeeb
7356c92544dSBjoern A. Zeeb if (!(le32_to_cpu(txs_data[0]) & MT_TXS0_ACK_ERROR_MASK))
7366c92544dSBjoern A. Zeeb info->flags |= IEEE80211_TX_STAT_ACK;
7376c92544dSBjoern A. Zeeb
7386c92544dSBjoern A. Zeeb info->status.ampdu_len = 1;
739*cbb3ec25SBjoern A. Zeeb info->status.ampdu_ack_len =
740*cbb3ec25SBjoern A. Zeeb !!(info->flags & IEEE80211_TX_STAT_ACK);
7416c92544dSBjoern A. Zeeb info->status.rates[0].idx = -1;
7426c92544dSBjoern A. Zeeb
7436c92544dSBjoern A. Zeeb mt76_connac2_mac_fill_txs(dev, wcid, txs_data);
7446c92544dSBjoern A. Zeeb mt76_tx_status_skb_done(dev, skb, &list);
7456c92544dSBjoern A. Zeeb }
7466c92544dSBjoern A. Zeeb mt76_tx_status_unlock(dev, &list);
7476c92544dSBjoern A. Zeeb
7486c92544dSBjoern A. Zeeb return !!skb;
7496c92544dSBjoern A. Zeeb }
7506c92544dSBjoern A. Zeeb EXPORT_SYMBOL_GPL(mt76_connac2_mac_add_txs_skb);
7516c92544dSBjoern A. Zeeb
7526c92544dSBjoern A. Zeeb static void
mt76_connac2_mac_decode_he_radiotap_ru(struct mt76_rx_status * status,struct ieee80211_radiotap_he * he,__le32 * rxv)7536c92544dSBjoern A. Zeeb mt76_connac2_mac_decode_he_radiotap_ru(struct mt76_rx_status *status,
7546c92544dSBjoern A. Zeeb struct ieee80211_radiotap_he *he,
7556c92544dSBjoern A. Zeeb __le32 *rxv)
7566c92544dSBjoern A. Zeeb {
7576c92544dSBjoern A. Zeeb u32 ru_h, ru_l;
7586c92544dSBjoern A. Zeeb u8 ru, offs = 0;
7596c92544dSBjoern A. Zeeb
7606c92544dSBjoern A. Zeeb ru_l = le32_get_bits(rxv[0], MT_PRXV_HE_RU_ALLOC_L);
7616c92544dSBjoern A. Zeeb ru_h = le32_get_bits(rxv[1], MT_PRXV_HE_RU_ALLOC_H);
7626c92544dSBjoern A. Zeeb ru = (u8)(ru_l | ru_h << 4);
7636c92544dSBjoern A. Zeeb
7646c92544dSBjoern A. Zeeb status->bw = RATE_INFO_BW_HE_RU;
7656c92544dSBjoern A. Zeeb
7666c92544dSBjoern A. Zeeb switch (ru) {
7676c92544dSBjoern A. Zeeb case 0 ... 36:
7686c92544dSBjoern A. Zeeb status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_26;
7696c92544dSBjoern A. Zeeb offs = ru;
7706c92544dSBjoern A. Zeeb break;
7716c92544dSBjoern A. Zeeb case 37 ... 52:
7726c92544dSBjoern A. Zeeb status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_52;
7736c92544dSBjoern A. Zeeb offs = ru - 37;
7746c92544dSBjoern A. Zeeb break;
7756c92544dSBjoern A. Zeeb case 53 ... 60:
7766c92544dSBjoern A. Zeeb status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_106;
7776c92544dSBjoern A. Zeeb offs = ru - 53;
7786c92544dSBjoern A. Zeeb break;
7796c92544dSBjoern A. Zeeb case 61 ... 64:
7806c92544dSBjoern A. Zeeb status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_242;
7816c92544dSBjoern A. Zeeb offs = ru - 61;
7826c92544dSBjoern A. Zeeb break;
7836c92544dSBjoern A. Zeeb case 65 ... 66:
7846c92544dSBjoern A. Zeeb status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_484;
7856c92544dSBjoern A. Zeeb offs = ru - 65;
7866c92544dSBjoern A. Zeeb break;
7876c92544dSBjoern A. Zeeb case 67:
7886c92544dSBjoern A. Zeeb status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_996;
7896c92544dSBjoern A. Zeeb break;
7906c92544dSBjoern A. Zeeb case 68:
7916c92544dSBjoern A. Zeeb status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_2x996;
7926c92544dSBjoern A. Zeeb break;
7936c92544dSBjoern A. Zeeb }
7946c92544dSBjoern A. Zeeb
7956c92544dSBjoern A. Zeeb he->data1 |= HE_BITS(DATA1_BW_RU_ALLOC_KNOWN);
7966c92544dSBjoern A. Zeeb he->data2 |= HE_BITS(DATA2_RU_OFFSET_KNOWN) |
7976c92544dSBjoern A. Zeeb le16_encode_bits(offs,
7986c92544dSBjoern A. Zeeb IEEE80211_RADIOTAP_HE_DATA2_RU_OFFSET);
7996c92544dSBjoern A. Zeeb }
8006c92544dSBjoern A. Zeeb
8016c92544dSBjoern A. Zeeb static void
mt76_connac2_mac_decode_he_mu_radiotap(struct mt76_dev * dev,struct sk_buff * skb,__le32 * rxv)8026c92544dSBjoern A. Zeeb mt76_connac2_mac_decode_he_mu_radiotap(struct mt76_dev *dev, struct sk_buff *skb,
8036c92544dSBjoern A. Zeeb __le32 *rxv)
8046c92544dSBjoern A. Zeeb {
8056c92544dSBjoern A. Zeeb struct mt76_rx_status *status = (struct mt76_rx_status *)skb->cb;
8066c92544dSBjoern A. Zeeb static struct ieee80211_radiotap_he_mu mu_known = {
8076c92544dSBjoern A. Zeeb .flags1 = HE_BITS(MU_FLAGS1_SIG_B_MCS_KNOWN) |
8086c92544dSBjoern A. Zeeb HE_BITS(MU_FLAGS1_SIG_B_DCM_KNOWN) |
8096c92544dSBjoern A. Zeeb HE_BITS(MU_FLAGS1_CH1_RU_KNOWN) |
8106c92544dSBjoern A. Zeeb HE_BITS(MU_FLAGS1_SIG_B_SYMS_USERS_KNOWN),
8116c92544dSBjoern A. Zeeb .flags2 = HE_BITS(MU_FLAGS2_BW_FROM_SIG_A_BW_KNOWN),
8126c92544dSBjoern A. Zeeb };
8136c92544dSBjoern A. Zeeb struct ieee80211_radiotap_he_mu *he_mu;
8146c92544dSBjoern A. Zeeb
8156c92544dSBjoern A. Zeeb if (is_mt7921(dev)) {
8166c92544dSBjoern A. Zeeb mu_known.flags1 |= HE_BITS(MU_FLAGS1_SIG_B_COMP_KNOWN);
8176c92544dSBjoern A. Zeeb mu_known.flags2 |= HE_BITS(MU_FLAGS2_PUNC_FROM_SIG_A_BW_KNOWN);
8186c92544dSBjoern A. Zeeb }
8196c92544dSBjoern A. Zeeb
8206c92544dSBjoern A. Zeeb status->flag |= RX_FLAG_RADIOTAP_HE_MU;
8216c92544dSBjoern A. Zeeb
8226c92544dSBjoern A. Zeeb he_mu = skb_push(skb, sizeof(mu_known));
8236c92544dSBjoern A. Zeeb memcpy(he_mu, &mu_known, sizeof(mu_known));
8246c92544dSBjoern A. Zeeb
8256c92544dSBjoern A. Zeeb #define MU_PREP(f, v) le16_encode_bits(v, IEEE80211_RADIOTAP_HE_MU_##f)
8266c92544dSBjoern A. Zeeb
8276c92544dSBjoern A. Zeeb he_mu->flags1 |= MU_PREP(FLAGS1_SIG_B_MCS, status->rate_idx);
8286c92544dSBjoern A. Zeeb if (status->he_dcm)
8296c92544dSBjoern A. Zeeb he_mu->flags1 |= MU_PREP(FLAGS1_SIG_B_DCM, status->he_dcm);
8306c92544dSBjoern A. Zeeb
8316c92544dSBjoern A. Zeeb he_mu->flags2 |= MU_PREP(FLAGS2_BW_FROM_SIG_A_BW, status->bw) |
8326c92544dSBjoern A. Zeeb MU_PREP(FLAGS2_SIG_B_SYMS_USERS,
8336c92544dSBjoern A. Zeeb le32_get_bits(rxv[2], MT_CRXV_HE_NUM_USER));
8346c92544dSBjoern A. Zeeb
8356c92544dSBjoern A. Zeeb he_mu->ru_ch1[0] = le32_get_bits(rxv[3], MT_CRXV_HE_RU0);
8366c92544dSBjoern A. Zeeb
8376c92544dSBjoern A. Zeeb if (status->bw >= RATE_INFO_BW_40) {
8386c92544dSBjoern A. Zeeb he_mu->flags1 |= HE_BITS(MU_FLAGS1_CH2_RU_KNOWN);
8396c92544dSBjoern A. Zeeb he_mu->ru_ch2[0] =
8406c92544dSBjoern A. Zeeb le32_get_bits(rxv[3], MT_CRXV_HE_RU1);
8416c92544dSBjoern A. Zeeb }
8426c92544dSBjoern A. Zeeb
8436c92544dSBjoern A. Zeeb if (status->bw >= RATE_INFO_BW_80) {
8446c92544dSBjoern A. Zeeb he_mu->ru_ch1[1] =
8456c92544dSBjoern A. Zeeb le32_get_bits(rxv[3], MT_CRXV_HE_RU2);
8466c92544dSBjoern A. Zeeb he_mu->ru_ch2[1] =
8476c92544dSBjoern A. Zeeb le32_get_bits(rxv[3], MT_CRXV_HE_RU3);
8486c92544dSBjoern A. Zeeb }
8496c92544dSBjoern A. Zeeb }
8506c92544dSBjoern A. Zeeb
mt76_connac2_mac_decode_he_radiotap(struct mt76_dev * dev,struct sk_buff * skb,__le32 * rxv,u32 mode)8516c92544dSBjoern A. Zeeb void mt76_connac2_mac_decode_he_radiotap(struct mt76_dev *dev,
8526c92544dSBjoern A. Zeeb struct sk_buff *skb,
8536c92544dSBjoern A. Zeeb __le32 *rxv, u32 mode)
8546c92544dSBjoern A. Zeeb {
8556c92544dSBjoern A. Zeeb struct mt76_rx_status *status = (struct mt76_rx_status *)skb->cb;
8566c92544dSBjoern A. Zeeb static const struct ieee80211_radiotap_he known = {
8576c92544dSBjoern A. Zeeb .data1 = HE_BITS(DATA1_DATA_MCS_KNOWN) |
8586c92544dSBjoern A. Zeeb HE_BITS(DATA1_DATA_DCM_KNOWN) |
8596c92544dSBjoern A. Zeeb HE_BITS(DATA1_STBC_KNOWN) |
8606c92544dSBjoern A. Zeeb HE_BITS(DATA1_CODING_KNOWN) |
8616c92544dSBjoern A. Zeeb HE_BITS(DATA1_LDPC_XSYMSEG_KNOWN) |
8626c92544dSBjoern A. Zeeb HE_BITS(DATA1_DOPPLER_KNOWN) |
8636c92544dSBjoern A. Zeeb HE_BITS(DATA1_SPTL_REUSE_KNOWN) |
8646c92544dSBjoern A. Zeeb HE_BITS(DATA1_BSS_COLOR_KNOWN),
8656c92544dSBjoern A. Zeeb .data2 = HE_BITS(DATA2_GI_KNOWN) |
8666c92544dSBjoern A. Zeeb HE_BITS(DATA2_TXBF_KNOWN) |
8676c92544dSBjoern A. Zeeb HE_BITS(DATA2_PE_DISAMBIG_KNOWN) |
8686c92544dSBjoern A. Zeeb HE_BITS(DATA2_TXOP_KNOWN),
8696c92544dSBjoern A. Zeeb };
8706c92544dSBjoern A. Zeeb u32 ltf_size = le32_get_bits(rxv[2], MT_CRXV_HE_LTF_SIZE) + 1;
8716c92544dSBjoern A. Zeeb struct ieee80211_radiotap_he *he;
8726c92544dSBjoern A. Zeeb
8736c92544dSBjoern A. Zeeb status->flag |= RX_FLAG_RADIOTAP_HE;
8746c92544dSBjoern A. Zeeb
8756c92544dSBjoern A. Zeeb he = skb_push(skb, sizeof(known));
8766c92544dSBjoern A. Zeeb memcpy(he, &known, sizeof(known));
8776c92544dSBjoern A. Zeeb
8786c92544dSBjoern A. Zeeb he->data3 = HE_PREP(DATA3_BSS_COLOR, BSS_COLOR, rxv[14]) |
8796c92544dSBjoern A. Zeeb HE_PREP(DATA3_LDPC_XSYMSEG, LDPC_EXT_SYM, rxv[2]);
8806c92544dSBjoern A. Zeeb he->data4 = HE_PREP(DATA4_SU_MU_SPTL_REUSE, SR_MASK, rxv[11]);
8816c92544dSBjoern A. Zeeb he->data5 = HE_PREP(DATA5_PE_DISAMBIG, PE_DISAMBIG, rxv[2]) |
8826c92544dSBjoern A. Zeeb le16_encode_bits(ltf_size,
8836c92544dSBjoern A. Zeeb IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE);
8846c92544dSBjoern A. Zeeb if (le32_to_cpu(rxv[0]) & MT_PRXV_TXBF)
8856c92544dSBjoern A. Zeeb he->data5 |= HE_BITS(DATA5_TXBF);
8866c92544dSBjoern A. Zeeb he->data6 = HE_PREP(DATA6_TXOP, TXOP_DUR, rxv[14]) |
8876c92544dSBjoern A. Zeeb HE_PREP(DATA6_DOPPLER, DOPPLER, rxv[14]);
8886c92544dSBjoern A. Zeeb
8896c92544dSBjoern A. Zeeb switch (mode) {
8906c92544dSBjoern A. Zeeb case MT_PHY_TYPE_HE_SU:
8916c92544dSBjoern A. Zeeb he->data1 |= HE_BITS(DATA1_FORMAT_SU) |
8926c92544dSBjoern A. Zeeb HE_BITS(DATA1_UL_DL_KNOWN) |
8936c92544dSBjoern A. Zeeb HE_BITS(DATA1_BEAM_CHANGE_KNOWN) |
8946c92544dSBjoern A. Zeeb HE_BITS(DATA1_BW_RU_ALLOC_KNOWN);
8956c92544dSBjoern A. Zeeb
8966c92544dSBjoern A. Zeeb he->data3 |= HE_PREP(DATA3_BEAM_CHANGE, BEAM_CHNG, rxv[14]) |
8976c92544dSBjoern A. Zeeb HE_PREP(DATA3_UL_DL, UPLINK, rxv[2]);
8986c92544dSBjoern A. Zeeb break;
8996c92544dSBjoern A. Zeeb case MT_PHY_TYPE_HE_EXT_SU:
9006c92544dSBjoern A. Zeeb he->data1 |= HE_BITS(DATA1_FORMAT_EXT_SU) |
9016c92544dSBjoern A. Zeeb HE_BITS(DATA1_UL_DL_KNOWN) |
9026c92544dSBjoern A. Zeeb HE_BITS(DATA1_BW_RU_ALLOC_KNOWN);
9036c92544dSBjoern A. Zeeb
9046c92544dSBjoern A. Zeeb he->data3 |= HE_PREP(DATA3_UL_DL, UPLINK, rxv[2]);
9056c92544dSBjoern A. Zeeb break;
9066c92544dSBjoern A. Zeeb case MT_PHY_TYPE_HE_MU:
9076c92544dSBjoern A. Zeeb he->data1 |= HE_BITS(DATA1_FORMAT_MU) |
9086c92544dSBjoern A. Zeeb HE_BITS(DATA1_UL_DL_KNOWN);
9096c92544dSBjoern A. Zeeb
9106c92544dSBjoern A. Zeeb he->data3 |= HE_PREP(DATA3_UL_DL, UPLINK, rxv[2]);
9116c92544dSBjoern A. Zeeb he->data4 |= HE_PREP(DATA4_MU_STA_ID, MU_AID, rxv[7]);
9126c92544dSBjoern A. Zeeb
9136c92544dSBjoern A. Zeeb mt76_connac2_mac_decode_he_radiotap_ru(status, he, rxv);
9146c92544dSBjoern A. Zeeb mt76_connac2_mac_decode_he_mu_radiotap(dev, skb, rxv);
9156c92544dSBjoern A. Zeeb break;
9166c92544dSBjoern A. Zeeb case MT_PHY_TYPE_HE_TB:
9176c92544dSBjoern A. Zeeb he->data1 |= HE_BITS(DATA1_FORMAT_TRIG) |
9186c92544dSBjoern A. Zeeb HE_BITS(DATA1_SPTL_REUSE2_KNOWN) |
9196c92544dSBjoern A. Zeeb HE_BITS(DATA1_SPTL_REUSE3_KNOWN) |
9206c92544dSBjoern A. Zeeb HE_BITS(DATA1_SPTL_REUSE4_KNOWN);
9216c92544dSBjoern A. Zeeb
9226c92544dSBjoern A. Zeeb he->data4 |= HE_PREP(DATA4_TB_SPTL_REUSE1, SR_MASK, rxv[11]) |
9236c92544dSBjoern A. Zeeb HE_PREP(DATA4_TB_SPTL_REUSE2, SR1_MASK, rxv[11]) |
9246c92544dSBjoern A. Zeeb HE_PREP(DATA4_TB_SPTL_REUSE3, SR2_MASK, rxv[11]) |
9256c92544dSBjoern A. Zeeb HE_PREP(DATA4_TB_SPTL_REUSE4, SR3_MASK, rxv[11]);
9266c92544dSBjoern A. Zeeb
9276c92544dSBjoern A. Zeeb mt76_connac2_mac_decode_he_radiotap_ru(status, he, rxv);
9286c92544dSBjoern A. Zeeb break;
9296c92544dSBjoern A. Zeeb default:
9306c92544dSBjoern A. Zeeb break;
9316c92544dSBjoern A. Zeeb }
9326c92544dSBjoern A. Zeeb }
9336c92544dSBjoern A. Zeeb EXPORT_SYMBOL_GPL(mt76_connac2_mac_decode_he_radiotap);
9346c92544dSBjoern A. Zeeb
9356c92544dSBjoern A. Zeeb /* The HW does not translate the mac header to 802.3 for mesh point */
mt76_connac2_reverse_frag0_hdr_trans(struct ieee80211_vif * vif,struct sk_buff * skb,u16 hdr_offset)9366c92544dSBjoern A. Zeeb int mt76_connac2_reverse_frag0_hdr_trans(struct ieee80211_vif *vif,
9376c92544dSBjoern A. Zeeb struct sk_buff *skb, u16 hdr_offset)
9386c92544dSBjoern A. Zeeb {
9396c92544dSBjoern A. Zeeb struct mt76_rx_status *status = (struct mt76_rx_status *)skb->cb;
9406c92544dSBjoern A. Zeeb struct ethhdr *eth_hdr = (struct ethhdr *)(skb->data + hdr_offset);
9416c92544dSBjoern A. Zeeb __le32 *rxd = (__le32 *)skb->data;
9426c92544dSBjoern A. Zeeb struct ieee80211_sta *sta;
9436c92544dSBjoern A. Zeeb struct ieee80211_hdr hdr;
9446c92544dSBjoern A. Zeeb u16 frame_control;
9456c92544dSBjoern A. Zeeb
9466c92544dSBjoern A. Zeeb if (le32_get_bits(rxd[3], MT_RXD3_NORMAL_ADDR_TYPE) !=
9476c92544dSBjoern A. Zeeb MT_RXD3_NORMAL_U2M)
9486c92544dSBjoern A. Zeeb return -EINVAL;
9496c92544dSBjoern A. Zeeb
9506c92544dSBjoern A. Zeeb if (!(le32_to_cpu(rxd[1]) & MT_RXD1_NORMAL_GROUP_4))
9516c92544dSBjoern A. Zeeb return -EINVAL;
9526c92544dSBjoern A. Zeeb
9536c92544dSBjoern A. Zeeb sta = container_of((void *)status->wcid, struct ieee80211_sta, drv_priv);
9546c92544dSBjoern A. Zeeb
9556c92544dSBjoern A. Zeeb /* store the info from RXD and ethhdr to avoid being overridden */
9566c92544dSBjoern A. Zeeb frame_control = le32_get_bits(rxd[6], MT_RXD6_FRAME_CONTROL);
9576c92544dSBjoern A. Zeeb hdr.frame_control = cpu_to_le16(frame_control);
9586c92544dSBjoern A. Zeeb hdr.seq_ctrl = cpu_to_le16(le32_get_bits(rxd[8], MT_RXD8_SEQ_CTRL));
9596c92544dSBjoern A. Zeeb hdr.duration_id = 0;
9606c92544dSBjoern A. Zeeb
9616c92544dSBjoern A. Zeeb ether_addr_copy(hdr.addr1, vif->addr);
9626c92544dSBjoern A. Zeeb ether_addr_copy(hdr.addr2, sta->addr);
9636c92544dSBjoern A. Zeeb switch (frame_control & (IEEE80211_FCTL_TODS |
9646c92544dSBjoern A. Zeeb IEEE80211_FCTL_FROMDS)) {
9656c92544dSBjoern A. Zeeb case 0:
9666c92544dSBjoern A. Zeeb ether_addr_copy(hdr.addr3, vif->bss_conf.bssid);
9676c92544dSBjoern A. Zeeb break;
9686c92544dSBjoern A. Zeeb case IEEE80211_FCTL_FROMDS:
9696c92544dSBjoern A. Zeeb ether_addr_copy(hdr.addr3, eth_hdr->h_source);
9706c92544dSBjoern A. Zeeb break;
9716c92544dSBjoern A. Zeeb case IEEE80211_FCTL_TODS:
9726c92544dSBjoern A. Zeeb ether_addr_copy(hdr.addr3, eth_hdr->h_dest);
9736c92544dSBjoern A. Zeeb break;
9746c92544dSBjoern A. Zeeb case IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS:
9756c92544dSBjoern A. Zeeb ether_addr_copy(hdr.addr3, eth_hdr->h_dest);
9766c92544dSBjoern A. Zeeb ether_addr_copy(hdr.addr4, eth_hdr->h_source);
9776c92544dSBjoern A. Zeeb break;
9786c92544dSBjoern A. Zeeb default:
979*cbb3ec25SBjoern A. Zeeb return -EINVAL;
9806c92544dSBjoern A. Zeeb }
9816c92544dSBjoern A. Zeeb
9826c92544dSBjoern A. Zeeb skb_pull(skb, hdr_offset + sizeof(struct ethhdr) - 2);
9836c92544dSBjoern A. Zeeb if (eth_hdr->h_proto == cpu_to_be16(ETH_P_AARP) ||
9846c92544dSBjoern A. Zeeb eth_hdr->h_proto == cpu_to_be16(ETH_P_IPX))
9856c92544dSBjoern A. Zeeb ether_addr_copy(skb_push(skb, ETH_ALEN), bridge_tunnel_header);
9866c92544dSBjoern A. Zeeb else if (be16_to_cpu(eth_hdr->h_proto) >= ETH_P_802_3_MIN)
9876c92544dSBjoern A. Zeeb ether_addr_copy(skb_push(skb, ETH_ALEN), rfc1042_header);
9886c92544dSBjoern A. Zeeb else
9896c92544dSBjoern A. Zeeb skb_pull(skb, 2);
9906c92544dSBjoern A. Zeeb
9916c92544dSBjoern A. Zeeb if (ieee80211_has_order(hdr.frame_control))
9926c92544dSBjoern A. Zeeb memcpy(skb_push(skb, IEEE80211_HT_CTL_LEN), &rxd[9],
9936c92544dSBjoern A. Zeeb IEEE80211_HT_CTL_LEN);
9946c92544dSBjoern A. Zeeb if (ieee80211_is_data_qos(hdr.frame_control)) {
9956c92544dSBjoern A. Zeeb __le16 qos_ctrl;
9966c92544dSBjoern A. Zeeb
9976c92544dSBjoern A. Zeeb qos_ctrl = cpu_to_le16(le32_get_bits(rxd[8], MT_RXD8_QOS_CTL));
9986c92544dSBjoern A. Zeeb memcpy(skb_push(skb, IEEE80211_QOS_CTL_LEN), &qos_ctrl,
9996c92544dSBjoern A. Zeeb IEEE80211_QOS_CTL_LEN);
10006c92544dSBjoern A. Zeeb }
10016c92544dSBjoern A. Zeeb
10026c92544dSBjoern A. Zeeb if (ieee80211_has_a4(hdr.frame_control))
10036c92544dSBjoern A. Zeeb memcpy(skb_push(skb, sizeof(hdr)), &hdr, sizeof(hdr));
10046c92544dSBjoern A. Zeeb else
10056c92544dSBjoern A. Zeeb memcpy(skb_push(skb, sizeof(hdr) - 6), &hdr, sizeof(hdr) - 6);
10066c92544dSBjoern A. Zeeb
10076c92544dSBjoern A. Zeeb return 0;
10086c92544dSBjoern A. Zeeb }
10096c92544dSBjoern A. Zeeb EXPORT_SYMBOL_GPL(mt76_connac2_reverse_frag0_hdr_trans);
10106c92544dSBjoern A. Zeeb
mt76_connac2_mac_fill_rx_rate(struct mt76_dev * dev,struct mt76_rx_status * status,struct ieee80211_supported_band * sband,__le32 * rxv,u8 * mode)10116c92544dSBjoern A. Zeeb int mt76_connac2_mac_fill_rx_rate(struct mt76_dev *dev,
10126c92544dSBjoern A. Zeeb struct mt76_rx_status *status,
10136c92544dSBjoern A. Zeeb struct ieee80211_supported_band *sband,
10146c92544dSBjoern A. Zeeb __le32 *rxv, u8 *mode)
10156c92544dSBjoern A. Zeeb {
10166c92544dSBjoern A. Zeeb u32 v0, v2;
10176c92544dSBjoern A. Zeeb u8 stbc, gi, bw, dcm, nss;
10186c92544dSBjoern A. Zeeb int i, idx;
10196c92544dSBjoern A. Zeeb bool cck = false;
10206c92544dSBjoern A. Zeeb
10216c92544dSBjoern A. Zeeb v0 = le32_to_cpu(rxv[0]);
10226c92544dSBjoern A. Zeeb v2 = le32_to_cpu(rxv[2]);
10236c92544dSBjoern A. Zeeb
10246c92544dSBjoern A. Zeeb idx = i = FIELD_GET(MT_PRXV_TX_RATE, v0);
10256c92544dSBjoern A. Zeeb nss = FIELD_GET(MT_PRXV_NSTS, v0) + 1;
10266c92544dSBjoern A. Zeeb
10276c92544dSBjoern A. Zeeb if (!is_mt7915(dev)) {
10286c92544dSBjoern A. Zeeb stbc = FIELD_GET(MT_PRXV_HT_STBC, v0);
10296c92544dSBjoern A. Zeeb gi = FIELD_GET(MT_PRXV_HT_SGI, v0);
10306c92544dSBjoern A. Zeeb *mode = FIELD_GET(MT_PRXV_TX_MODE, v0);
10316c92544dSBjoern A. Zeeb if (is_mt7921(dev))
10326c92544dSBjoern A. Zeeb dcm = !!(idx & MT_PRXV_TX_DCM);
10336c92544dSBjoern A. Zeeb else
10346c92544dSBjoern A. Zeeb dcm = FIELD_GET(MT_PRXV_DCM, v0);
10356c92544dSBjoern A. Zeeb bw = FIELD_GET(MT_PRXV_FRAME_MODE, v0);
10366c92544dSBjoern A. Zeeb } else {
10376c92544dSBjoern A. Zeeb stbc = FIELD_GET(MT_CRXV_HT_STBC, v2);
10386c92544dSBjoern A. Zeeb gi = FIELD_GET(MT_CRXV_HT_SHORT_GI, v2);
10396c92544dSBjoern A. Zeeb *mode = FIELD_GET(MT_CRXV_TX_MODE, v2);
10406c92544dSBjoern A. Zeeb dcm = !!(idx & GENMASK(3, 0) & MT_PRXV_TX_DCM);
10416c92544dSBjoern A. Zeeb bw = FIELD_GET(MT_CRXV_FRAME_MODE, v2);
10426c92544dSBjoern A. Zeeb }
10436c92544dSBjoern A. Zeeb
10446c92544dSBjoern A. Zeeb switch (*mode) {
10456c92544dSBjoern A. Zeeb case MT_PHY_TYPE_CCK:
10466c92544dSBjoern A. Zeeb cck = true;
10476c92544dSBjoern A. Zeeb fallthrough;
10486c92544dSBjoern A. Zeeb case MT_PHY_TYPE_OFDM:
10496c92544dSBjoern A. Zeeb i = mt76_get_rate(dev, sband, i, cck);
10506c92544dSBjoern A. Zeeb break;
10516c92544dSBjoern A. Zeeb case MT_PHY_TYPE_HT_GF:
10526c92544dSBjoern A. Zeeb case MT_PHY_TYPE_HT:
10536c92544dSBjoern A. Zeeb status->encoding = RX_ENC_HT;
10546c92544dSBjoern A. Zeeb if (gi)
10556c92544dSBjoern A. Zeeb status->enc_flags |= RX_ENC_FLAG_SHORT_GI;
10566c92544dSBjoern A. Zeeb if (i > 31)
10576c92544dSBjoern A. Zeeb return -EINVAL;
10586c92544dSBjoern A. Zeeb break;
10596c92544dSBjoern A. Zeeb case MT_PHY_TYPE_VHT:
10606c92544dSBjoern A. Zeeb status->nss = nss;
10616c92544dSBjoern A. Zeeb status->encoding = RX_ENC_VHT;
10626c92544dSBjoern A. Zeeb if (gi)
10636c92544dSBjoern A. Zeeb status->enc_flags |= RX_ENC_FLAG_SHORT_GI;
10646c92544dSBjoern A. Zeeb if (i > 11)
10656c92544dSBjoern A. Zeeb return -EINVAL;
10666c92544dSBjoern A. Zeeb break;
10676c92544dSBjoern A. Zeeb case MT_PHY_TYPE_HE_MU:
10686c92544dSBjoern A. Zeeb case MT_PHY_TYPE_HE_SU:
10696c92544dSBjoern A. Zeeb case MT_PHY_TYPE_HE_EXT_SU:
10706c92544dSBjoern A. Zeeb case MT_PHY_TYPE_HE_TB:
10716c92544dSBjoern A. Zeeb status->nss = nss;
10726c92544dSBjoern A. Zeeb status->encoding = RX_ENC_HE;
10736c92544dSBjoern A. Zeeb i &= GENMASK(3, 0);
10746c92544dSBjoern A. Zeeb
10756c92544dSBjoern A. Zeeb if (gi <= NL80211_RATE_INFO_HE_GI_3_2)
10766c92544dSBjoern A. Zeeb status->he_gi = gi;
10776c92544dSBjoern A. Zeeb
10786c92544dSBjoern A. Zeeb status->he_dcm = dcm;
10796c92544dSBjoern A. Zeeb break;
10806c92544dSBjoern A. Zeeb default:
10816c92544dSBjoern A. Zeeb return -EINVAL;
10826c92544dSBjoern A. Zeeb }
10836c92544dSBjoern A. Zeeb status->rate_idx = i;
10846c92544dSBjoern A. Zeeb
10856c92544dSBjoern A. Zeeb switch (bw) {
10866c92544dSBjoern A. Zeeb case IEEE80211_STA_RX_BW_20:
10876c92544dSBjoern A. Zeeb break;
10886c92544dSBjoern A. Zeeb case IEEE80211_STA_RX_BW_40:
10896c92544dSBjoern A. Zeeb if (*mode & MT_PHY_TYPE_HE_EXT_SU &&
10906c92544dSBjoern A. Zeeb (idx & MT_PRXV_TX_ER_SU_106T)) {
10916c92544dSBjoern A. Zeeb status->bw = RATE_INFO_BW_HE_RU;
10926c92544dSBjoern A. Zeeb status->he_ru =
10936c92544dSBjoern A. Zeeb NL80211_RATE_INFO_HE_RU_ALLOC_106;
10946c92544dSBjoern A. Zeeb } else {
10956c92544dSBjoern A. Zeeb status->bw = RATE_INFO_BW_40;
10966c92544dSBjoern A. Zeeb }
10976c92544dSBjoern A. Zeeb break;
10986c92544dSBjoern A. Zeeb case IEEE80211_STA_RX_BW_80:
10996c92544dSBjoern A. Zeeb status->bw = RATE_INFO_BW_80;
11006c92544dSBjoern A. Zeeb break;
11016c92544dSBjoern A. Zeeb case IEEE80211_STA_RX_BW_160:
11026c92544dSBjoern A. Zeeb status->bw = RATE_INFO_BW_160;
11036c92544dSBjoern A. Zeeb break;
11046c92544dSBjoern A. Zeeb default:
11056c92544dSBjoern A. Zeeb return -EINVAL;
11066c92544dSBjoern A. Zeeb }
11076c92544dSBjoern A. Zeeb
11086c92544dSBjoern A. Zeeb status->enc_flags |= RX_ENC_FLAG_STBC_MASK * stbc;
11096c92544dSBjoern A. Zeeb if (*mode < MT_PHY_TYPE_HE_SU && gi)
11106c92544dSBjoern A. Zeeb status->enc_flags |= RX_ENC_FLAG_SHORT_GI;
11116c92544dSBjoern A. Zeeb
11126c92544dSBjoern A. Zeeb return 0;
11136c92544dSBjoern A. Zeeb }
11146c92544dSBjoern A. Zeeb EXPORT_SYMBOL_GPL(mt76_connac2_mac_fill_rx_rate);
1115*cbb3ec25SBjoern A. Zeeb
mt76_connac2_tx_check_aggr(struct ieee80211_sta * sta,__le32 * txwi)1116*cbb3ec25SBjoern A. Zeeb void mt76_connac2_tx_check_aggr(struct ieee80211_sta *sta, __le32 *txwi)
1117*cbb3ec25SBjoern A. Zeeb {
1118*cbb3ec25SBjoern A. Zeeb struct mt76_wcid *wcid;
1119*cbb3ec25SBjoern A. Zeeb u16 fc, tid;
1120*cbb3ec25SBjoern A. Zeeb u32 val;
1121*cbb3ec25SBjoern A. Zeeb
1122*cbb3ec25SBjoern A. Zeeb if (!sta ||
1123*cbb3ec25SBjoern A. Zeeb !(sta->deflink.ht_cap.ht_supported || sta->deflink.he_cap.has_he))
1124*cbb3ec25SBjoern A. Zeeb return;
1125*cbb3ec25SBjoern A. Zeeb
1126*cbb3ec25SBjoern A. Zeeb tid = le32_get_bits(txwi[1], MT_TXD1_TID);
1127*cbb3ec25SBjoern A. Zeeb if (tid >= 6) /* skip VO queue */
1128*cbb3ec25SBjoern A. Zeeb return;
1129*cbb3ec25SBjoern A. Zeeb
1130*cbb3ec25SBjoern A. Zeeb val = le32_to_cpu(txwi[2]);
1131*cbb3ec25SBjoern A. Zeeb fc = FIELD_GET(MT_TXD2_FRAME_TYPE, val) << 2 |
1132*cbb3ec25SBjoern A. Zeeb FIELD_GET(MT_TXD2_SUB_TYPE, val) << 4;
1133*cbb3ec25SBjoern A. Zeeb if (unlikely(fc != (IEEE80211_FTYPE_DATA | IEEE80211_STYPE_QOS_DATA)))
1134*cbb3ec25SBjoern A. Zeeb return;
1135*cbb3ec25SBjoern A. Zeeb
1136*cbb3ec25SBjoern A. Zeeb wcid = (struct mt76_wcid *)sta->drv_priv;
1137*cbb3ec25SBjoern A. Zeeb if (!test_and_set_bit(tid, &wcid->ampdu_state))
1138*cbb3ec25SBjoern A. Zeeb ieee80211_start_tx_ba_session(sta, tid, 0);
1139*cbb3ec25SBjoern A. Zeeb }
1140*cbb3ec25SBjoern A. Zeeb EXPORT_SYMBOL_GPL(mt76_connac2_tx_check_aggr);
1141*cbb3ec25SBjoern A. Zeeb
mt76_connac2_txwi_free(struct mt76_dev * dev,struct mt76_txwi_cache * t,struct ieee80211_sta * sta,struct list_head * free_list)1142*cbb3ec25SBjoern A. Zeeb void mt76_connac2_txwi_free(struct mt76_dev *dev, struct mt76_txwi_cache *t,
1143*cbb3ec25SBjoern A. Zeeb struct ieee80211_sta *sta,
1144*cbb3ec25SBjoern A. Zeeb struct list_head *free_list)
1145*cbb3ec25SBjoern A. Zeeb {
1146*cbb3ec25SBjoern A. Zeeb struct mt76_wcid *wcid;
1147*cbb3ec25SBjoern A. Zeeb __le32 *txwi;
1148*cbb3ec25SBjoern A. Zeeb u16 wcid_idx;
1149*cbb3ec25SBjoern A. Zeeb
1150*cbb3ec25SBjoern A. Zeeb mt76_connac_txp_skb_unmap(dev, t);
1151*cbb3ec25SBjoern A. Zeeb if (!t->skb)
1152*cbb3ec25SBjoern A. Zeeb goto out;
1153*cbb3ec25SBjoern A. Zeeb
1154*cbb3ec25SBjoern A. Zeeb txwi = (__le32 *)mt76_get_txwi_ptr(dev, t);
1155*cbb3ec25SBjoern A. Zeeb if (sta) {
1156*cbb3ec25SBjoern A. Zeeb wcid = (struct mt76_wcid *)sta->drv_priv;
1157*cbb3ec25SBjoern A. Zeeb wcid_idx = wcid->idx;
1158*cbb3ec25SBjoern A. Zeeb } else {
1159*cbb3ec25SBjoern A. Zeeb wcid_idx = le32_get_bits(txwi[1], MT_TXD1_WLAN_IDX);
1160*cbb3ec25SBjoern A. Zeeb wcid = rcu_dereference(dev->wcid[wcid_idx]);
1161*cbb3ec25SBjoern A. Zeeb
1162*cbb3ec25SBjoern A. Zeeb if (wcid && wcid->sta) {
1163*cbb3ec25SBjoern A. Zeeb sta = container_of((void *)wcid, struct ieee80211_sta,
1164*cbb3ec25SBjoern A. Zeeb drv_priv);
1165*cbb3ec25SBjoern A. Zeeb spin_lock_bh(&dev->sta_poll_lock);
1166*cbb3ec25SBjoern A. Zeeb if (list_empty(&wcid->poll_list))
1167*cbb3ec25SBjoern A. Zeeb list_add_tail(&wcid->poll_list,
1168*cbb3ec25SBjoern A. Zeeb &dev->sta_poll_list);
1169*cbb3ec25SBjoern A. Zeeb spin_unlock_bh(&dev->sta_poll_lock);
1170*cbb3ec25SBjoern A. Zeeb }
1171*cbb3ec25SBjoern A. Zeeb }
1172*cbb3ec25SBjoern A. Zeeb
1173*cbb3ec25SBjoern A. Zeeb if (sta && likely(t->skb->protocol != cpu_to_be16(ETH_P_PAE)))
1174*cbb3ec25SBjoern A. Zeeb mt76_connac2_tx_check_aggr(sta, txwi);
1175*cbb3ec25SBjoern A. Zeeb
1176*cbb3ec25SBjoern A. Zeeb __mt76_tx_complete_skb(dev, wcid_idx, t->skb, free_list);
1177*cbb3ec25SBjoern A. Zeeb out:
1178*cbb3ec25SBjoern A. Zeeb t->skb = NULL;
1179*cbb3ec25SBjoern A. Zeeb mt76_put_txwi(dev, t);
1180*cbb3ec25SBjoern A. Zeeb }
1181*cbb3ec25SBjoern A. Zeeb EXPORT_SYMBOL_GPL(mt76_connac2_txwi_free);
1182*cbb3ec25SBjoern A. Zeeb
mt76_connac2_tx_token_put(struct mt76_dev * dev)1183*cbb3ec25SBjoern A. Zeeb void mt76_connac2_tx_token_put(struct mt76_dev *dev)
1184*cbb3ec25SBjoern A. Zeeb {
1185*cbb3ec25SBjoern A. Zeeb struct mt76_txwi_cache *txwi;
1186*cbb3ec25SBjoern A. Zeeb int id;
1187*cbb3ec25SBjoern A. Zeeb
1188*cbb3ec25SBjoern A. Zeeb spin_lock_bh(&dev->token_lock);
1189*cbb3ec25SBjoern A. Zeeb idr_for_each_entry(&dev->token, txwi, id) {
1190*cbb3ec25SBjoern A. Zeeb mt76_connac2_txwi_free(dev, txwi, NULL, NULL);
1191*cbb3ec25SBjoern A. Zeeb dev->token_count--;
1192*cbb3ec25SBjoern A. Zeeb }
1193*cbb3ec25SBjoern A. Zeeb spin_unlock_bh(&dev->token_lock);
1194*cbb3ec25SBjoern A. Zeeb idr_destroy(&dev->token);
1195*cbb3ec25SBjoern A. Zeeb }
1196*cbb3ec25SBjoern A. Zeeb EXPORT_SYMBOL_GPL(mt76_connac2_tx_token_put);
1197