OSDN Git Service

mt76: connac: move connac2_mac_write_txwi in mt76_connac module
authorLorenzo Bianconi <lorenzo@kernel.org>
Tue, 7 Jun 2022 09:28:40 +0000 (11:28 +0200)
committerFelix Fietkau <nbd@nbd.name>
Mon, 11 Jul 2022 11:40:01 +0000 (13:40 +0200)
mac_write_txwi code is shared between connac2 devices (mt7915 and
mt7921). Move it in connac module.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
drivers/net/wireless/mediatek/mt76/mt76_connac.h
drivers/net/wireless/mediatek/mt76/mt76_connac_mac.c
drivers/net/wireless/mediatek/mt76/mt7915/mac.c
drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h
drivers/net/wireless/mediatek/mt76/mt7921/mac.c
drivers/net/wireless/mediatek/mt76/mt7921/main.c
drivers/net/wireless/mediatek/mt76/mt7921/mcu.c
drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h
drivers/net/wireless/mediatek/mt76/mt7921/pci_mac.c

index 400ba51..a9d7a26 100644 (file)
@@ -12,6 +12,8 @@
 #define MT76_CONNAC_MAX_SCHED_SCAN_SSID                10
 #define MT76_CONNAC_MAX_SCAN_MATCH             16
 
+#define MT76_CONNAC_MAX_WMM_SETS               4
+
 #define MT76_CONNAC_COREDUMP_TIMEOUT           (HZ / 20)
 #define MT76_CONNAC_COREDUMP_SZ                        (1300 * 1024)
 
@@ -244,5 +246,9 @@ void mt76_connac_pm_queue_skb(struct ieee80211_hw *hw,
                              struct sk_buff *skb);
 void mt76_connac_pm_dequeue_skbs(struct mt76_phy *phy,
                                 struct mt76_connac_pm *pm);
+void 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,
+                                u32 changed);
 
 #endif /* __MT76_CONNAC_H */
index 306e9ea..0ea7955 100644 (file)
@@ -2,6 +2,7 @@
 /* Copyright (C) 2020 MediaTek Inc. */
 
 #include "mt76_connac.h"
+#include "mt76_connac2_mac.h"
 
 int mt76_connac_pm_wake(struct mt76_phy *phy, struct mt76_connac_pm *pm)
 {
@@ -115,3 +116,286 @@ void mt76_connac_pm_dequeue_skbs(struct mt76_phy *phy,
        mt76_worker_schedule(&phy->dev->tx_worker);
 }
 EXPORT_SYMBOL_GPL(mt76_connac_pm_dequeue_skbs);
+
+static u16
+mt76_connac2_mac_tx_rate_val(struct mt76_phy *mphy, struct ieee80211_vif *vif,
+                            bool beacon, bool mcast)
+{
+       u8 mode = 0, band = mphy->chandef.chan->band;
+       int rateidx = 0, mcast_rate;
+
+       if (!vif)
+               goto legacy;
+
+       if (is_mt7921(mphy->dev)) {
+               rateidx = ffs(vif->bss_conf.basic_rates) - 1;
+               goto legacy;
+       }
+
+       if (beacon) {
+               struct cfg80211_bitrate_mask *mask;
+
+               mask = &vif->bss_conf.beacon_tx_rate;
+               if (hweight16(mask->control[band].he_mcs[0]) == 1) {
+                       rateidx = ffs(mask->control[band].he_mcs[0]) - 1;
+                       mode = MT_PHY_TYPE_HE_SU;
+                       goto out;
+               } else if (hweight16(mask->control[band].vht_mcs[0]) == 1) {
+                       rateidx = ffs(mask->control[band].vht_mcs[0]) - 1;
+                       mode = MT_PHY_TYPE_VHT;
+                       goto out;
+               } else if (hweight8(mask->control[band].ht_mcs[0]) == 1) {
+                       rateidx = ffs(mask->control[band].ht_mcs[0]) - 1;
+                       mode = MT_PHY_TYPE_HT;
+                       goto out;
+               } else if (hweight32(mask->control[band].legacy) == 1) {
+                       rateidx = ffs(mask->control[band].legacy) - 1;
+                       goto legacy;
+               }
+       }
+
+       mcast_rate = vif->bss_conf.mcast_rate[band];
+       if (mcast && mcast_rate > 0)
+               rateidx = mcast_rate - 1;
+       else
+               rateidx = ffs(vif->bss_conf.basic_rates) - 1;
+
+legacy:
+       rateidx = mt76_calculate_default_rate(mphy, rateidx);
+       mode = rateidx >> 8;
+       rateidx &= GENMASK(7, 0);
+
+out:
+       return FIELD_PREP(MT_TX_RATE_IDX, rateidx) |
+              FIELD_PREP(MT_TX_RATE_MODE, mode);
+}
+
+static void
+mt76_connac2_mac_write_txwi_8023(__le32 *txwi, struct sk_buff *skb,
+                                struct mt76_wcid *wcid)
+{
+       u8 tid = skb->priority & IEEE80211_QOS_CTL_TID_MASK;
+       u8 fc_type, fc_stype;
+       u16 ethertype;
+       bool wmm = false;
+       u32 val;
+
+       if (wcid->sta) {
+               struct ieee80211_sta *sta;
+
+               sta = container_of((void *)wcid, struct ieee80211_sta, drv_priv);
+               wmm = sta->wme;
+       }
+
+       val = FIELD_PREP(MT_TXD1_HDR_FORMAT, MT_HDR_FORMAT_802_3) |
+             FIELD_PREP(MT_TXD1_TID, tid);
+
+       ethertype = get_unaligned_be16(&skb->data[12]);
+       if (ethertype >= ETH_P_802_3_MIN)
+               val |= MT_TXD1_ETH_802_3;
+
+       txwi[1] |= cpu_to_le32(val);
+
+       fc_type = IEEE80211_FTYPE_DATA >> 2;
+       fc_stype = wmm ? IEEE80211_STYPE_QOS_DATA >> 4 : 0;
+
+       val = FIELD_PREP(MT_TXD2_FRAME_TYPE, fc_type) |
+             FIELD_PREP(MT_TXD2_SUB_TYPE, fc_stype);
+
+       txwi[2] |= cpu_to_le32(val);
+
+       val = FIELD_PREP(MT_TXD7_TYPE, fc_type) |
+             FIELD_PREP(MT_TXD7_SUB_TYPE, fc_stype);
+
+       txwi[7] |= cpu_to_le32(val);
+}
+
+static void
+mt76_connac2_mac_write_txwi_80211(struct mt76_dev *dev, __le32 *txwi,
+                                 struct sk_buff *skb,
+                                 struct ieee80211_key_conf *key)
+{
+       struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
+       struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data;
+       struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
+       bool multicast = is_multicast_ether_addr(hdr->addr1);
+       u8 tid = skb->priority & IEEE80211_QOS_CTL_TID_MASK;
+       __le16 fc = hdr->frame_control;
+       u8 fc_type, fc_stype;
+       u32 val;
+
+       if (ieee80211_is_action(fc) &&
+           mgmt->u.action.category == WLAN_CATEGORY_BACK &&
+           mgmt->u.action.u.addba_req.action_code == WLAN_ACTION_ADDBA_REQ) {
+               u16 capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab);
+
+               txwi[5] |= cpu_to_le32(MT_TXD5_ADD_BA);
+               tid = (capab >> 2) & IEEE80211_QOS_CTL_TID_MASK;
+       } else if (ieee80211_is_back_req(hdr->frame_control)) {
+               struct ieee80211_bar *bar = (struct ieee80211_bar *)hdr;
+               u16 control = le16_to_cpu(bar->control);
+
+               tid = FIELD_GET(IEEE80211_BAR_CTRL_TID_INFO_MASK, control);
+       }
+
+       val = FIELD_PREP(MT_TXD1_HDR_FORMAT, MT_HDR_FORMAT_802_11) |
+             FIELD_PREP(MT_TXD1_HDR_INFO,
+                        ieee80211_get_hdrlen_from_skb(skb) / 2) |
+             FIELD_PREP(MT_TXD1_TID, tid);
+
+       txwi[1] |= cpu_to_le32(val);
+
+       fc_type = (le16_to_cpu(fc) & IEEE80211_FCTL_FTYPE) >> 2;
+       fc_stype = (le16_to_cpu(fc) & IEEE80211_FCTL_STYPE) >> 4;
+
+       val = FIELD_PREP(MT_TXD2_FRAME_TYPE, fc_type) |
+             FIELD_PREP(MT_TXD2_SUB_TYPE, fc_stype) |
+             FIELD_PREP(MT_TXD2_MULTICAST, multicast);
+
+       if (key && multicast && ieee80211_is_robust_mgmt_frame(skb) &&
+           key->cipher == WLAN_CIPHER_SUITE_AES_CMAC) {
+               val |= MT_TXD2_BIP;
+               txwi[3] &= ~cpu_to_le32(MT_TXD3_PROTECT_FRAME);
+       }
+
+       if (!ieee80211_is_data(fc) || multicast ||
+           info->flags & IEEE80211_TX_CTL_USE_MINRATE)
+               val |= MT_TXD2_FIX_RATE;
+
+       txwi[2] |= cpu_to_le32(val);
+
+       if (ieee80211_is_beacon(fc)) {
+               txwi[3] &= ~cpu_to_le32(MT_TXD3_SW_POWER_MGMT);
+               txwi[3] |= cpu_to_le32(MT_TXD3_REM_TX_COUNT);
+               if (!is_mt7921(dev))
+                       txwi[7] |= cpu_to_le32(FIELD_PREP(MT_TXD7_SPE_IDX,
+                                                         0x18));
+       }
+
+       if (info->flags & IEEE80211_TX_CTL_INJECTED) {
+               u16 seqno = le16_to_cpu(hdr->seq_ctrl);
+
+               if (ieee80211_is_back_req(hdr->frame_control)) {
+                       struct ieee80211_bar *bar;
+
+                       bar = (struct ieee80211_bar *)skb->data;
+                       seqno = le16_to_cpu(bar->start_seq_num);
+               }
+
+               val = MT_TXD3_SN_VALID |
+                     FIELD_PREP(MT_TXD3_SEQ, IEEE80211_SEQ_TO_SN(seqno));
+               txwi[3] |= cpu_to_le32(val);
+               txwi[7] &= ~cpu_to_le32(MT_TXD7_HW_AMSDU);
+       }
+
+       if (mt76_is_mmio(dev)) {
+               val = FIELD_PREP(MT_TXD7_TYPE, fc_type) |
+                     FIELD_PREP(MT_TXD7_SUB_TYPE, fc_stype);
+               txwi[7] |= cpu_to_le32(val);
+       } else {
+               val = FIELD_PREP(MT_TXD8_L_TYPE, fc_type) |
+                     FIELD_PREP(MT_TXD8_L_SUB_TYPE, fc_stype);
+               txwi[8] |= cpu_to_le32(val);
+       }
+}
+
+void 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,
+                                u32 changed)
+{
+       struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
+       bool ext_phy = info->hw_queue & MT_TX_HW_QUEUE_EXT_PHY;
+       struct ieee80211_vif *vif = info->control.vif;
+       struct mt76_phy *mphy = &dev->phy;
+       u8 p_fmt, q_idx, omac_idx = 0, wmm_idx = 0, band_idx = 0;
+       u32 val, sz_txd = mt76_is_mmio(dev) ? MT_TXD_SIZE : MT_SDIO_TXD_SIZE;
+       bool is_8023 = info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP;
+       bool beacon = !!(changed & (BSS_CHANGED_BEACON |
+                                   BSS_CHANGED_BEACON_ENABLED));
+       bool inband_disc = !!(changed & (BSS_CHANGED_UNSOL_BCAST_PROBE_RESP |
+                                        BSS_CHANGED_FILS_DISCOVERY));
+
+       if (vif) {
+               struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv;
+
+               omac_idx = mvif->omac_idx;
+               wmm_idx = mvif->wmm_idx;
+               band_idx = mvif->band_idx;
+       }
+
+       if (ext_phy && dev->phy2)
+               mphy = dev->phy2;
+
+       if (inband_disc) {
+               p_fmt = MT_TX_TYPE_FW;
+               q_idx = MT_LMAC_ALTX0;
+       } else if (beacon) {
+               p_fmt = MT_TX_TYPE_FW;
+               q_idx = MT_LMAC_BCN0;
+       } else if (skb_get_queue_mapping(skb) >= MT_TXQ_PSD) {
+               p_fmt = mt76_is_mmio(dev) ? MT_TX_TYPE_CT : MT_TX_TYPE_SF;
+               q_idx = MT_LMAC_ALTX0;
+       } else {
+               p_fmt = mt76_is_mmio(dev) ? MT_TX_TYPE_CT : MT_TX_TYPE_SF;
+               q_idx = wmm_idx * MT76_CONNAC_MAX_WMM_SETS +
+                       mt76_connac_lmac_mapping(skb_get_queue_mapping(skb));
+       }
+
+       val = FIELD_PREP(MT_TXD0_TX_BYTES, skb->len + sz_txd) |
+             FIELD_PREP(MT_TXD0_PKT_FMT, p_fmt) |
+             FIELD_PREP(MT_TXD0_Q_IDX, q_idx);
+       txwi[0] = cpu_to_le32(val);
+
+       val = MT_TXD1_LONG_FORMAT |
+             FIELD_PREP(MT_TXD1_WLAN_IDX, wcid->idx) |
+             FIELD_PREP(MT_TXD1_OWN_MAC, omac_idx);
+       if (!is_mt7921(dev))
+               val |= MT_TXD1_VTA;
+       if (ext_phy || band_idx)
+               val |= MT_TXD1_TGID;
+
+       txwi[1] = cpu_to_le32(val);
+       txwi[2] = 0;
+
+       val = FIELD_PREP(MT_TXD3_REM_TX_COUNT, 15);
+       if (!is_mt7921(dev))
+               val |= MT_TXD3_SW_POWER_MGMT;
+       if (key)
+               val |= MT_TXD3_PROTECT_FRAME;
+       if (info->flags & IEEE80211_TX_CTL_NO_ACK)
+               val |= MT_TXD3_NO_ACK;
+
+       txwi[3] = cpu_to_le32(val);
+       txwi[4] = 0;
+
+       val = FIELD_PREP(MT_TXD5_PID, pid);
+       if (pid >= MT_PACKET_ID_FIRST)
+               val |= MT_TXD5_TX_STATUS_HOST;
+
+       txwi[5] = cpu_to_le32(val);
+       txwi[6] = 0;
+       txwi[7] = wcid->amsdu ? cpu_to_le32(MT_TXD7_HW_AMSDU) : 0;
+
+       if (is_8023)
+               mt76_connac2_mac_write_txwi_8023(txwi, skb, wcid);
+       else
+               mt76_connac2_mac_write_txwi_80211(dev, txwi, skb, key);
+
+       if (txwi[2] & cpu_to_le32(MT_TXD2_FIX_RATE)) {
+               /* Fixed rata is available just for 802.11 txd */
+               struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
+               bool multicast = is_multicast_ether_addr(hdr->addr1);
+               u16 rate = mt76_connac2_mac_tx_rate_val(mphy, vif, beacon,
+                                                       multicast);
+               u32 val = MT_TXD6_FIXED_BW;
+
+               /* hardware won't add HTC for mgmt/ctrl frame */
+               txwi[2] |= cpu_to_le32(MT_TXD2_HTC_VLD);
+
+               val |= FIELD_PREP(MT_TXD6_TX_RATE, rate);
+               txwi[6] |= cpu_to_le32(val);
+               txwi[3] |= cpu_to_le32(MT_TXD3_BA_DISABLE);
+       }
+}
+EXPORT_SYMBOL_GPL(mt76_connac2_mac_write_txwi);
index caed0db..932dfe0 100644 (file)
@@ -1009,265 +1009,18 @@ mt7915_mac_write_txwi_tm(struct mt7915_phy *phy, __le32 *txwi,
 #endif
 }
 
-static void
-mt7915_mac_write_txwi_8023(__le32 *txwi, struct sk_buff *skb,
-                          struct mt76_wcid *wcid)
-{
-
-       u8 tid = skb->priority & IEEE80211_QOS_CTL_TID_MASK;
-       u8 fc_type, fc_stype;
-       u16 ethertype;
-       bool wmm = false;
-       u32 val;
-
-       if (wcid->sta) {
-               struct ieee80211_sta *sta;
-
-               sta = container_of((void *)wcid, struct ieee80211_sta, drv_priv);
-               wmm = sta->wme;
-       }
-
-       val = FIELD_PREP(MT_TXD1_HDR_FORMAT, MT_HDR_FORMAT_802_3) |
-             FIELD_PREP(MT_TXD1_TID, tid);
-
-       ethertype = get_unaligned_be16(&skb->data[12]);
-       if (ethertype >= ETH_P_802_3_MIN)
-               val |= MT_TXD1_ETH_802_3;
-
-       txwi[1] |= cpu_to_le32(val);
-
-       fc_type = IEEE80211_FTYPE_DATA >> 2;
-       fc_stype = wmm ? IEEE80211_STYPE_QOS_DATA >> 4 : 0;
-
-       val = FIELD_PREP(MT_TXD2_FRAME_TYPE, fc_type) |
-             FIELD_PREP(MT_TXD2_SUB_TYPE, fc_stype);
-
-       txwi[2] |= cpu_to_le32(val);
-
-       val = FIELD_PREP(MT_TXD7_TYPE, fc_type) |
-             FIELD_PREP(MT_TXD7_SUB_TYPE, fc_stype);
-       txwi[7] |= cpu_to_le32(val);
-}
-
-static void
-mt7915_mac_write_txwi_80211(__le32 *txwi, struct sk_buff *skb,
-                           struct ieee80211_key_conf *key, bool *mcast)
-{
-       struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
-       struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data;
-       struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
-       u8 tid = skb->priority & IEEE80211_QOS_CTL_TID_MASK;
-       __le16 fc = hdr->frame_control;
-       u8 fc_type, fc_stype;
-       u32 val;
-
-       *mcast = is_multicast_ether_addr(hdr->addr1);
-
-       if (ieee80211_is_action(fc) &&
-           mgmt->u.action.category == WLAN_CATEGORY_BACK &&
-           mgmt->u.action.u.addba_req.action_code == WLAN_ACTION_ADDBA_REQ) {
-               u16 capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab);
-
-               txwi[5] |= cpu_to_le32(MT_TXD5_ADD_BA);
-               tid = (capab >> 2) & IEEE80211_QOS_CTL_TID_MASK;
-       } else if (ieee80211_is_back_req(hdr->frame_control)) {
-               struct ieee80211_bar *bar = (struct ieee80211_bar *)hdr;
-               u16 control = le16_to_cpu(bar->control);
-
-               tid = FIELD_GET(IEEE80211_BAR_CTRL_TID_INFO_MASK, control);
-       }
-
-       val = FIELD_PREP(MT_TXD1_HDR_FORMAT, MT_HDR_FORMAT_802_11) |
-             FIELD_PREP(MT_TXD1_HDR_INFO,
-                        ieee80211_get_hdrlen_from_skb(skb) / 2) |
-             FIELD_PREP(MT_TXD1_TID, tid);
-       txwi[1] |= cpu_to_le32(val);
-
-       fc_type = (le16_to_cpu(fc) & IEEE80211_FCTL_FTYPE) >> 2;
-       fc_stype = (le16_to_cpu(fc) & IEEE80211_FCTL_STYPE) >> 4;
-
-       val = FIELD_PREP(MT_TXD2_FRAME_TYPE, fc_type) |
-             FIELD_PREP(MT_TXD2_SUB_TYPE, fc_stype) |
-             FIELD_PREP(MT_TXD2_MULTICAST, *mcast);
-
-       if (key && *mcast && ieee80211_is_robust_mgmt_frame(skb) &&
-           key->cipher == WLAN_CIPHER_SUITE_AES_CMAC) {
-               val |= MT_TXD2_BIP;
-               txwi[3] &= ~cpu_to_le32(MT_TXD3_PROTECT_FRAME);
-       }
-
-       if (!ieee80211_is_data(fc) || *mcast ||
-           info->flags & IEEE80211_TX_CTL_USE_MINRATE)
-               val |= MT_TXD2_FIX_RATE;
-
-       txwi[2] |= cpu_to_le32(val);
-
-       if (ieee80211_is_beacon(fc)) {
-               txwi[3] &= ~cpu_to_le32(MT_TXD3_SW_POWER_MGMT);
-               txwi[3] |= cpu_to_le32(MT_TXD3_REM_TX_COUNT);
-               txwi[7] |= cpu_to_le32(FIELD_PREP(MT_TXD7_SPE_IDX, 0x18));
-       }
-
-       if (info->flags & IEEE80211_TX_CTL_INJECTED) {
-               u16 seqno = le16_to_cpu(hdr->seq_ctrl);
-
-               if (ieee80211_is_back_req(hdr->frame_control)) {
-                       struct ieee80211_bar *bar;
-
-                       bar = (struct ieee80211_bar *)skb->data;
-                       seqno = le16_to_cpu(bar->start_seq_num);
-               }
-
-               val = MT_TXD3_SN_VALID |
-                     FIELD_PREP(MT_TXD3_SEQ, IEEE80211_SEQ_TO_SN(seqno));
-               txwi[3] |= cpu_to_le32(val);
-               txwi[7] &= ~cpu_to_le32(MT_TXD7_HW_AMSDU);
-       }
-
-       val = FIELD_PREP(MT_TXD7_TYPE, fc_type) |
-             FIELD_PREP(MT_TXD7_SUB_TYPE, fc_stype);
-       txwi[7] |= cpu_to_le32(val);
-}
-
-static u16
-mt7915_mac_tx_rate_val(struct mt76_phy *mphy, struct ieee80211_vif *vif,
-                      bool beacon, bool mcast)
-{
-       u8 mode = 0, band = mphy->chandef.chan->band;
-       int rateidx = 0, mcast_rate;
-
-       if (beacon) {
-               struct cfg80211_bitrate_mask *mask;
-
-               mask = &vif->bss_conf.beacon_tx_rate;
-               if (hweight16(mask->control[band].he_mcs[0]) == 1) {
-                       rateidx = ffs(mask->control[band].he_mcs[0]) - 1;
-                       mode = MT_PHY_TYPE_HE_SU;
-                       goto out;
-               } else if (hweight16(mask->control[band].vht_mcs[0]) == 1) {
-                       rateidx = ffs(mask->control[band].vht_mcs[0]) - 1;
-                       mode = MT_PHY_TYPE_VHT;
-                       goto out;
-               } else if (hweight8(mask->control[band].ht_mcs[0]) == 1) {
-                       rateidx = ffs(mask->control[band].ht_mcs[0]) - 1;
-                       mode = MT_PHY_TYPE_HT;
-                       goto out;
-               } else if (hweight32(mask->control[band].legacy) == 1) {
-                       rateidx = ffs(mask->control[band].legacy) - 1;
-                       goto legacy;
-               }
-       }
-
-       mcast_rate = vif->bss_conf.mcast_rate[band];
-       if (mcast && mcast_rate > 0)
-               rateidx = mcast_rate - 1;
-       else
-               rateidx = ffs(vif->bss_conf.basic_rates) - 1;
-
-legacy:
-       rateidx = mt76_calculate_default_rate(mphy, rateidx);
-       mode = rateidx >> 8;
-       rateidx &= GENMASK(7, 0);
-
-out:
-       return FIELD_PREP(MT_TX_RATE_IDX, rateidx) |
-              FIELD_PREP(MT_TX_RATE_MODE, mode);
-}
-
 void mt7915_mac_write_txwi(struct mt76_dev *dev, __le32 *txwi,
                           struct sk_buff *skb, struct mt76_wcid *wcid, int pid,
                           struct ieee80211_key_conf *key, u32 changed)
 {
        struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
-       struct ieee80211_vif *vif = info->control.vif;
        struct mt76_phy *mphy = &dev->phy;
-       bool ext_phy = info->hw_queue & MT_TX_HW_QUEUE_EXT_PHY;
-       u8 p_fmt, q_idx, omac_idx = 0, wmm_idx = 0, band_idx = 0;
-       bool is_8023 = info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP;
-       bool mcast = false;
-       u16 tx_count = 15;
-       u32 val;
-       bool beacon = !!(changed & (BSS_CHANGED_BEACON |
-                                   BSS_CHANGED_BEACON_ENABLED));
-       bool inband_disc = !!(changed & (BSS_CHANGED_UNSOL_BCAST_PROBE_RESP |
-                                        BSS_CHANGED_FILS_DISCOVERY));
-
-       if (vif) {
-               struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv;
 
-               omac_idx = mvif->mt76.omac_idx;
-               wmm_idx = mvif->mt76.wmm_idx;
-               band_idx = mvif->mt76.band_idx;
-       }
-
-       if (ext_phy && dev->phy2)
+       if ((info->hw_queue & MT_TX_HW_QUEUE_EXT_PHY) && dev->phy2)
                mphy = dev->phy2;
 
-       if (inband_disc) {
-               p_fmt = MT_TX_TYPE_FW;
-               q_idx = MT_LMAC_ALTX0;
-       } else if (beacon) {
-               p_fmt = MT_TX_TYPE_FW;
-               q_idx = MT_LMAC_BCN0;
-       } else if (skb_get_queue_mapping(skb) >= MT_TXQ_PSD) {
-               p_fmt = MT_TX_TYPE_CT;
-               q_idx = MT_LMAC_ALTX0;
-       } else {
-               p_fmt = MT_TX_TYPE_CT;
-               q_idx = wmm_idx * MT7915_MAX_WMM_SETS +
-                       mt76_connac_lmac_mapping(skb_get_queue_mapping(skb));
-       }
-
-       val = FIELD_PREP(MT_TXD0_TX_BYTES, skb->len + MT_TXD_SIZE) |
-             FIELD_PREP(MT_TXD0_PKT_FMT, p_fmt) |
-             FIELD_PREP(MT_TXD0_Q_IDX, q_idx);
-       txwi[0] = cpu_to_le32(val);
-
-       val = MT_TXD1_LONG_FORMAT | MT_TXD1_VTA |
-             FIELD_PREP(MT_TXD1_WLAN_IDX, wcid->idx) |
-             FIELD_PREP(MT_TXD1_OWN_MAC, omac_idx);
-
-       if (ext_phy || band_idx)
-               val |= MT_TXD1_TGID;
-
-       txwi[1] = cpu_to_le32(val);
-
-       txwi[2] = 0;
+       mt76_connac2_mac_write_txwi(dev, txwi, skb, wcid, key, pid, changed);
 
-       val = MT_TXD3_SW_POWER_MGMT |
-             FIELD_PREP(MT_TXD3_REM_TX_COUNT, tx_count);
-       if (key)
-               val |= MT_TXD3_PROTECT_FRAME;
-       if (info->flags & IEEE80211_TX_CTL_NO_ACK)
-               val |= MT_TXD3_NO_ACK;
-
-       txwi[3] = cpu_to_le32(val);
-       txwi[4] = 0;
-
-       val = FIELD_PREP(MT_TXD5_PID, pid);
-       if (pid >= MT_PACKET_ID_FIRST)
-               val |= MT_TXD5_TX_STATUS_HOST;
-       txwi[5] = cpu_to_le32(val);
-
-       txwi[6] = 0;
-       txwi[7] = wcid->amsdu ? cpu_to_le32(MT_TXD7_HW_AMSDU) : 0;
-
-       if (is_8023)
-               mt7915_mac_write_txwi_8023(txwi, skb, wcid);
-       else
-               mt7915_mac_write_txwi_80211(txwi, skb, key, &mcast);
-
-       if (txwi[2] & cpu_to_le32(MT_TXD2_FIX_RATE)) {
-               u16 rate = mt7915_mac_tx_rate_val(mphy, vif, beacon, mcast);
-
-               /* hardware won't add HTC for mgmt/ctrl frame */
-               txwi[2] |= cpu_to_le32(MT_TXD2_HTC_VLD);
-
-               val = MT_TXD6_FIXED_BW |
-                     FIELD_PREP(MT_TXD6_TX_RATE, rate);
-               txwi[6] |= cpu_to_le32(val);
-               txwi[3] |= cpu_to_le32(MT_TXD3_BA_DISABLE);
-       }
 
        if (mt76_testmode_enabled(mphy))
                mt7915_mac_write_txwi_tm(mphy->priv, txwi, skb);
index 76ff647..3a70518 100644 (file)
@@ -2432,7 +2432,7 @@ int mt7915_mcu_set_tx(struct mt7915_dev *dev, struct ieee80211_vif *vif)
                struct edca *e = &req.edca[ac];
 
                e->set = WMM_PARAM_SET;
-               e->queue = ac + mvif->mt76.wmm_idx * MT7915_MAX_WMM_SETS;
+               e->queue = ac + mvif->mt76.wmm_idx * MT76_CONNAC_MAX_WMM_SETS;
                e->aifs = q->aifs;
                e->txop = cpu_to_le16(q->txop);
 
index fbd5f12..3db0758 100644 (file)
@@ -10,7 +10,6 @@
 #include "regs.h"
 
 #define MT7915_MAX_INTERFACES          19
-#define MT7915_MAX_WMM_SETS            4
 #define MT7915_WTBL_SIZE               288
 #define MT7916_WTBL_SIZE               544
 #define MT7915_WTBL_RESERVED           (mt7915_wtbl_size(dev) - 1)
index 78c8a76..ae1dafc 100644 (file)
@@ -808,216 +808,6 @@ mt7921_mac_fill_rx(struct mt7921_dev *dev, struct sk_buff *skb)
        return 0;
 }
 
-static void
-mt7921_mac_write_txwi_8023(__le32 *txwi, struct sk_buff *skb,
-                          struct mt76_wcid *wcid)
-{
-       u8 tid = skb->priority & IEEE80211_QOS_CTL_TID_MASK;
-       u8 fc_type, fc_stype;
-       u16 ethertype;
-       bool wmm = false;
-       u32 val;
-
-       if (wcid->sta) {
-               struct ieee80211_sta *sta;
-
-               sta = container_of((void *)wcid, struct ieee80211_sta, drv_priv);
-               wmm = sta->wme;
-       }
-
-       val = FIELD_PREP(MT_TXD1_HDR_FORMAT, MT_HDR_FORMAT_802_3) |
-             FIELD_PREP(MT_TXD1_TID, tid);
-
-       ethertype = get_unaligned_be16(&skb->data[12]);
-       if (ethertype >= ETH_P_802_3_MIN)
-               val |= MT_TXD1_ETH_802_3;
-
-       txwi[1] |= cpu_to_le32(val);
-
-       fc_type = IEEE80211_FTYPE_DATA >> 2;
-       fc_stype = wmm ? IEEE80211_STYPE_QOS_DATA >> 4 : 0;
-
-       val = FIELD_PREP(MT_TXD2_FRAME_TYPE, fc_type) |
-             FIELD_PREP(MT_TXD2_SUB_TYPE, fc_stype);
-
-       txwi[2] |= cpu_to_le32(val);
-
-       val = FIELD_PREP(MT_TXD7_TYPE, fc_type) |
-             FIELD_PREP(MT_TXD7_SUB_TYPE, fc_stype);
-       txwi[7] |= cpu_to_le32(val);
-}
-
-static void
-mt7921_mac_write_txwi_80211(struct mt76_dev *dev, __le32 *txwi,
-                           struct sk_buff *skb, struct ieee80211_key_conf *key)
-{
-       struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
-       struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data;
-       struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
-       bool multicast = is_multicast_ether_addr(hdr->addr1);
-       u8 tid = skb->priority & IEEE80211_QOS_CTL_TID_MASK;
-       __le16 fc = hdr->frame_control;
-       u8 fc_type, fc_stype;
-       u32 val;
-
-       if (ieee80211_is_action(fc) &&
-           mgmt->u.action.category == WLAN_CATEGORY_BACK &&
-           mgmt->u.action.u.addba_req.action_code == WLAN_ACTION_ADDBA_REQ) {
-               u16 capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab);
-
-               txwi[5] |= cpu_to_le32(MT_TXD5_ADD_BA);
-               tid = (capab >> 2) & IEEE80211_QOS_CTL_TID_MASK;
-       } else if (ieee80211_is_back_req(hdr->frame_control)) {
-               struct ieee80211_bar *bar = (struct ieee80211_bar *)hdr;
-               u16 control = le16_to_cpu(bar->control);
-
-               tid = FIELD_GET(IEEE80211_BAR_CTRL_TID_INFO_MASK, control);
-       }
-
-       val = FIELD_PREP(MT_TXD1_HDR_FORMAT, MT_HDR_FORMAT_802_11) |
-             FIELD_PREP(MT_TXD1_HDR_INFO,
-                        ieee80211_get_hdrlen_from_skb(skb) / 2) |
-             FIELD_PREP(MT_TXD1_TID, tid);
-       txwi[1] |= cpu_to_le32(val);
-
-       fc_type = (le16_to_cpu(fc) & IEEE80211_FCTL_FTYPE) >> 2;
-       fc_stype = (le16_to_cpu(fc) & IEEE80211_FCTL_STYPE) >> 4;
-
-       val = FIELD_PREP(MT_TXD2_FRAME_TYPE, fc_type) |
-             FIELD_PREP(MT_TXD2_SUB_TYPE, fc_stype) |
-             FIELD_PREP(MT_TXD2_MULTICAST, multicast);
-
-       if (key && multicast && ieee80211_is_robust_mgmt_frame(skb) &&
-           key->cipher == WLAN_CIPHER_SUITE_AES_CMAC) {
-               val |= MT_TXD2_BIP;
-               txwi[3] &= ~cpu_to_le32(MT_TXD3_PROTECT_FRAME);
-       }
-
-       if (!ieee80211_is_data(fc) || multicast ||
-           info->flags & IEEE80211_TX_CTL_USE_MINRATE)
-               val |= MT_TXD2_FIX_RATE;
-
-       txwi[2] |= cpu_to_le32(val);
-
-       if (ieee80211_is_beacon(fc)) {
-               txwi[3] &= ~cpu_to_le32(MT_TXD3_SW_POWER_MGMT);
-               txwi[3] |= cpu_to_le32(MT_TXD3_REM_TX_COUNT);
-       }
-
-       if (info->flags & IEEE80211_TX_CTL_INJECTED) {
-               u16 seqno = le16_to_cpu(hdr->seq_ctrl);
-
-               if (ieee80211_is_back_req(hdr->frame_control)) {
-                       struct ieee80211_bar *bar;
-
-                       bar = (struct ieee80211_bar *)skb->data;
-                       seqno = le16_to_cpu(bar->start_seq_num);
-               }
-
-               val = MT_TXD3_SN_VALID |
-                     FIELD_PREP(MT_TXD3_SEQ, IEEE80211_SEQ_TO_SN(seqno));
-               txwi[3] |= cpu_to_le32(val);
-               txwi[7] &= ~cpu_to_le32(MT_TXD7_HW_AMSDU);
-       }
-
-       if (mt76_is_mmio(dev)) {
-               val = FIELD_PREP(MT_TXD7_TYPE, fc_type) |
-                     FIELD_PREP(MT_TXD7_SUB_TYPE, fc_stype);
-               txwi[7] |= cpu_to_le32(val);
-       } else {
-               val = FIELD_PREP(MT_TXD8_L_TYPE, fc_type) |
-                     FIELD_PREP(MT_TXD8_L_SUB_TYPE, fc_stype);
-               txwi[8] |= cpu_to_le32(val);
-       }
-}
-
-void mt7921_mac_write_txwi(struct mt76_dev *dev, __le32 *txwi,
-                          struct sk_buff *skb, struct mt76_wcid *wcid,
-                          struct ieee80211_key_conf *key, int pid,
-                          bool beacon)
-{
-       struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
-       struct ieee80211_vif *vif = info->control.vif;
-       struct mt76_phy *mphy = &dev->phy;
-       u8 p_fmt, q_idx, omac_idx = 0, wmm_idx = 0;
-       u32 sz_txd = mt76_is_mmio(dev) ? MT_TXD_SIZE : MT_SDIO_TXD_SIZE;
-       bool is_8023 = info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP;
-       u16 tx_count = 15;
-       u32 val;
-
-       if (vif) {
-               struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv;
-
-               omac_idx = mvif->omac_idx;
-               wmm_idx = mvif->wmm_idx;
-       }
-
-       if (beacon) {
-               p_fmt = MT_TX_TYPE_FW;
-               q_idx = MT_LMAC_BCN0;
-       } else if (skb_get_queue_mapping(skb) >= MT_TXQ_PSD) {
-               p_fmt = mt76_is_mmio(dev) ? MT_TX_TYPE_CT : MT_TX_TYPE_SF;
-               q_idx = MT_LMAC_ALTX0;
-       } else {
-               p_fmt = mt76_is_mmio(dev) ? MT_TX_TYPE_CT : MT_TX_TYPE_SF;
-               q_idx = wmm_idx * MT7921_MAX_WMM_SETS +
-                       mt76_connac_lmac_mapping(skb_get_queue_mapping(skb));
-       }
-
-       val = FIELD_PREP(MT_TXD0_TX_BYTES, skb->len + sz_txd) |
-             FIELD_PREP(MT_TXD0_PKT_FMT, p_fmt) |
-             FIELD_PREP(MT_TXD0_Q_IDX, q_idx);
-       txwi[0] = cpu_to_le32(val);
-
-       val = MT_TXD1_LONG_FORMAT |
-             FIELD_PREP(MT_TXD1_WLAN_IDX, wcid->idx) |
-             FIELD_PREP(MT_TXD1_OWN_MAC, omac_idx);
-
-       txwi[1] = cpu_to_le32(val);
-       txwi[2] = 0;
-
-       val = FIELD_PREP(MT_TXD3_REM_TX_COUNT, tx_count);
-       if (key)
-               val |= MT_TXD3_PROTECT_FRAME;
-       if (info->flags & IEEE80211_TX_CTL_NO_ACK)
-               val |= MT_TXD3_NO_ACK;
-
-       txwi[3] = cpu_to_le32(val);
-       txwi[4] = 0;
-
-       val = FIELD_PREP(MT_TXD5_PID, pid);
-       if (pid >= MT_PACKET_ID_FIRST)
-               val |= MT_TXD5_TX_STATUS_HOST;
-       txwi[5] = cpu_to_le32(val);
-
-       txwi[6] = 0;
-       txwi[7] = wcid->amsdu ? cpu_to_le32(MT_TXD7_HW_AMSDU) : 0;
-
-       if (is_8023)
-               mt7921_mac_write_txwi_8023(txwi, skb, wcid);
-       else
-               mt7921_mac_write_txwi_80211(dev, txwi, skb, key);
-
-       if (txwi[2] & cpu_to_le32(MT_TXD2_FIX_RATE)) {
-               int rateidx = vif ? ffs(vif->bss_conf.basic_rates) - 1 : 0;
-               u16 rate, mode;
-
-               /* hardware won't add HTC for mgmt/ctrl frame */
-               txwi[2] |= cpu_to_le32(MT_TXD2_HTC_VLD);
-
-               rate = mt76_calculate_default_rate(mphy, rateidx);
-               mode = rate >> 8;
-               rate &= GENMASK(7, 0);
-               rate |= FIELD_PREP(MT_TX_RATE_MODE, mode);
-
-               val = MT_TXD6_FIXED_BW |
-                     FIELD_PREP(MT_TXD6_TX_RATE, rate);
-               txwi[6] |= cpu_to_le32(val);
-               txwi[3] |= cpu_to_le32(MT_TXD3_BA_DISABLE);
-       }
-}
-EXPORT_SYMBOL_GPL(mt7921_mac_write_txwi);
-
 void mt7921_tx_check_aggr(struct ieee80211_sta *sta, __le32 *txwi)
 {
        struct mt7921_sta *msta;
@@ -1647,7 +1437,7 @@ mt7921_usb_sdio_write_txwi(struct mt7921_dev *dev, struct mt76_wcid *wcid,
        __le32 *txwi = (__le32 *)(skb->data - MT_SDIO_TXD_SIZE);
 
        memset(txwi, 0, MT_SDIO_TXD_SIZE);
-       mt7921_mac_write_txwi(&dev->mt76, txwi, skb, wcid, key, pid, false);
+       mt76_connac2_mac_write_txwi(&dev->mt76, txwi, skb, wcid, key, pid, 0);
        skb_push(skb, MT_SDIO_TXD_SIZE);
 }
 
index 6b3e88f..5163704 100644 (file)
@@ -322,7 +322,7 @@ static int mt7921_add_interface(struct ieee80211_hw *hw,
        mvif->mt76.omac_idx = mvif->mt76.idx;
        mvif->phy = phy;
        mvif->mt76.band_idx = 0;
-       mvif->mt76.wmm_idx = mvif->mt76.idx % MT7921_MAX_WMM_SETS;
+       mvif->mt76.wmm_idx = mvif->mt76.idx % MT76_CONNAC_MAX_WMM_SETS;
 
        ret = mt76_connac_mcu_uni_add_dev(&dev->mphy, vif, &mvif->sta.wcid,
                                          true);
index af43fbc..ef29c30 100644 (file)
@@ -994,8 +994,8 @@ mt7921_mcu_uni_add_beacon_offload(struct mt7921_dev *dev,
                return -EINVAL;
        }
 
-       mt7921_mac_write_txwi(&dev->mt76, (__le32 *)(req.beacon_tlv.pkt), skb,
-                             wcid, NULL, 0, true);
+       mt76_connac2_mac_write_txwi(&dev->mt76, (__le32 *)(req.beacon_tlv.pkt),
+                                   skb, wcid, NULL, 0, BSS_CHANGED_BEACON);
        memcpy(req.beacon_tlv.pkt + MT_TXD_SIZE, skb->data, skb->len);
        req.beacon_tlv.pkt_len = cpu_to_le16(MT_TXD_SIZE + skb->len);
        req.beacon_tlv.tim_ie_pos = cpu_to_le16(MT_TXD_SIZE + offs.tim_offset);
index 8015764..7da29fa 100644 (file)
@@ -11,7 +11,6 @@
 #include "acpi_sar.h"
 
 #define MT7921_MAX_INTERFACES          4
-#define MT7921_MAX_WMM_SETS            4
 #define MT7921_WTBL_SIZE               20
 #define MT7921_WTBL_RESERVED           (MT7921_WTBL_SIZE - 1)
 #define MT7921_WTBL_STA                        (MT7921_WTBL_RESERVED - \
@@ -417,10 +416,6 @@ int mt7921_testmode_cmd(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
                        void *data, int len);
 int mt7921_testmode_dump(struct ieee80211_hw *hw, struct sk_buff *msg,
                         struct netlink_callback *cb, void *data, int len);
-void mt7921_mac_write_txwi(struct mt76_dev *dev, __le32 *txwi,
-                          struct sk_buff *skb, struct mt76_wcid *wcid,
-                          struct ieee80211_key_conf *key, int pid,
-                          bool beacon);
 void mt7921_tx_check_aggr(struct ieee80211_sta *sta, __le32 *txwi);
 void mt7921_mac_sta_poll(struct mt7921_dev *dev);
 int mt7921_mcu_fill_message(struct mt76_dev *mdev, struct sk_buff *skb,
index f261cbf..b0f58bc 100644 (file)
@@ -72,8 +72,8 @@ int mt7921e_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
        }
 
        pid = mt76_tx_status_skb_add(mdev, wcid, tx_info->skb);
-       mt7921_mac_write_txwi(mdev, txwi_ptr, tx_info->skb, wcid, key,
-                             pid, false);
+       mt76_connac2_mac_write_txwi(mdev, txwi_ptr, tx_info->skb, wcid, key,
+                                   pid, 0);
 
        txp = (struct mt7921_txp_common *)(txwi + MT_TXD_SIZE);
        memset(txp, 0, sizeof(struct mt7921_txp_common));