wifi: mt76: add mt76_connac_gen_ppe_thresh utility routine
authorLorenzo Bianconi <lorenzo@kernel.org>
Mon, 3 Apr 2023 10:33:58 +0000 (12:33 +0200)
committerFelix Fietkau <nbd@nbd.name>
Mon, 17 Apr 2023 15:30:01 +0000 (17:30 +0200)
gen_ppe_thresh routine is shared between mt7615, mt7915, mt7921 and
mt7996 so move it in mt76_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/init.c
drivers/net/wireless/mediatek/mt76/mt7921/main.c
drivers/net/wireless/mediatek/mt76/mt7996/init.c

index 84974dfe1953ad0fe00e5fcfcfd3ee25a66ecc0c..fc8e999a431a0e22809e6e15566d2ceaff91c1ad 100644 (file)
@@ -359,6 +359,7 @@ mt76_connac_mutex_release(struct mt76_dev *dev, struct mt76_connac_pm *pm)
        mutex_unlock(&dev->mutex);
 }
 
+void mt76_connac_gen_ppe_thresh(u8 *he_ppet, int nss);
 int mt76_connac_init_tx_queues(struct mt76_phy *phy, int idx, int n_desc,
                               int ring_base, u32 flags);
 void mt76_connac_write_hw_txp(struct mt76_dev *dev,
index 8d316d3aab8ff63dac550a15daa43ab3bda9e937..bd4ce2c7742da1bf49eb1f00a0388d417e4365d3 100644 (file)
@@ -9,6 +9,27 @@
 #define HE_PREP(f, m, v)       le16_encode_bits(le32_get_bits(v, MT_CRXV_HE_##m),\
                                                 IEEE80211_RADIOTAP_HE_##f)
 
+void mt76_connac_gen_ppe_thresh(u8 *he_ppet, int nss)
+{
+       static const u8 ppet16_ppet8_ru3_ru0[] = { 0x1c, 0xc7, 0x71 };
+       u8 i, ppet_bits, ppet_size, ru_bit_mask = 0x7; /* HE80 */
+
+       he_ppet[0] = FIELD_PREP(IEEE80211_PPE_THRES_NSS_MASK, nss - 1) |
+                    FIELD_PREP(IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK,
+                               ru_bit_mask);
+
+       ppet_bits = IEEE80211_PPE_THRES_INFO_PPET_SIZE *
+                   nss * hweight8(ru_bit_mask) * 2;
+       ppet_size = DIV_ROUND_UP(ppet_bits, 8);
+
+       for (i = 0; i < ppet_size - 1; i++)
+               he_ppet[i + 1] = ppet16_ppet8_ru3_ru0[i % 3];
+
+       he_ppet[i + 1] = ppet16_ppet8_ru3_ru0[i % 3] &
+                        (0xff >> (8 - (ppet_bits - 1) % 8));
+}
+EXPORT_SYMBOL_GPL(mt76_connac_gen_ppe_thresh);
+
 int mt76_connac_pm_wake(struct mt76_phy *phy, struct mt76_connac_pm *pm)
 {
        struct mt76_dev *dev = phy->dev;
index 0d52c30ff8fd7c0d35b8f764c45d80dc3de50c9f..538ec0f8e630e328402448a3c9c8c80ea23bd876 100644 (file)
@@ -931,27 +931,6 @@ mt7915_set_stream_he_txbf_caps(struct mt7915_phy *phy,
        }
 }
 
-static void
-mt7915_gen_ppe_thresh(u8 *he_ppet, int nss)
-{
-       u8 i, ppet_bits, ppet_size, ru_bit_mask = 0x7; /* HE80 */
-       static const u8 ppet16_ppet8_ru3_ru0[] = {0x1c, 0xc7, 0x71};
-
-       he_ppet[0] = FIELD_PREP(IEEE80211_PPE_THRES_NSS_MASK, nss - 1) |
-                    FIELD_PREP(IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK,
-                               ru_bit_mask);
-
-       ppet_bits = IEEE80211_PPE_THRES_INFO_PPET_SIZE *
-                   nss * hweight8(ru_bit_mask) * 2;
-       ppet_size = DIV_ROUND_UP(ppet_bits, 8);
-
-       for (i = 0; i < ppet_size - 1; i++)
-               he_ppet[i + 1] = ppet16_ppet8_ru3_ru0[i % 3];
-
-       he_ppet[i + 1] = ppet16_ppet8_ru3_ru0[i % 3] &
-                        (0xff >> (8 - (ppet_bits - 1) % 8));
-}
-
 static int
 mt7915_init_he_caps(struct mt7915_phy *phy, enum nl80211_band band,
                    struct ieee80211_sband_iftype_data *data)
@@ -1101,7 +1080,7 @@ mt7915_init_he_caps(struct mt7915_phy *phy, enum nl80211_band band,
                memset(he_cap->ppe_thres, 0, sizeof(he_cap->ppe_thres));
                if (he_cap_elem->phy_cap_info[6] &
                    IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) {
-                       mt7915_gen_ppe_thresh(he_cap->ppe_thres, nss);
+                       mt76_connac_gen_ppe_thresh(he_cap->ppe_thres, nss);
                } else {
                        he_cap_elem->phy_cap_info[9] |=
                                u8_encode_bits(IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_16US,
index f1d537a7705aee066add932a272a9cdd9560d7e9..0c9a472bc81a762323c2a19852843c5df1ddc342 100644 (file)
@@ -9,27 +9,6 @@
 #include "mt7921.h"
 #include "mcu.h"
 
-static void
-mt7921_gen_ppe_thresh(u8 *he_ppet, int nss)
-{
-       u8 i, ppet_bits, ppet_size, ru_bit_mask = 0x7; /* HE80 */
-       static const u8 ppet16_ppet8_ru3_ru0[] = {0x1c, 0xc7, 0x71};
-
-       he_ppet[0] = FIELD_PREP(IEEE80211_PPE_THRES_NSS_MASK, nss - 1) |
-                    FIELD_PREP(IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK,
-                               ru_bit_mask);
-
-       ppet_bits = IEEE80211_PPE_THRES_INFO_PPET_SIZE *
-                   nss * hweight8(ru_bit_mask) * 2;
-       ppet_size = DIV_ROUND_UP(ppet_bits, 8);
-
-       for (i = 0; i < ppet_size - 1; i++)
-               he_ppet[i + 1] = ppet16_ppet8_ru3_ru0[i % 3];
-
-       he_ppet[i + 1] = ppet16_ppet8_ru3_ru0[i % 3] &
-                        (0xff >> (8 - (ppet_bits - 1) % 8));
-}
-
 static int
 mt7921_init_he_caps(struct mt7921_phy *phy, enum nl80211_band band,
                    struct ieee80211_sband_iftype_data *data)
@@ -168,7 +147,7 @@ mt7921_init_he_caps(struct mt7921_phy *phy, enum nl80211_band band,
                memset(he_cap->ppe_thres, 0, sizeof(he_cap->ppe_thres));
                if (he_cap_elem->phy_cap_info[6] &
                    IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) {
-                       mt7921_gen_ppe_thresh(he_cap->ppe_thres, nss);
+                       mt76_connac_gen_ppe_thresh(he_cap->ppe_thres, nss);
                } else {
                        he_cap_elem->phy_cap_info[9] |=
                                u8_encode_bits(IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_16US,
index 539e5cc4aa2bf0f29ad821e4f3e8a40bbbdedba4..ddea5f48816dd08570c8c6960cc2ae5f359a6fcf 100644 (file)
@@ -557,27 +557,6 @@ mt7996_set_stream_he_txbf_caps(struct mt7996_phy *phy,
        elem->phy_cap_info[7] |= c;
 }
 
-static void
-mt7996_gen_ppe_thresh(u8 *he_ppet, int nss)
-{
-       u8 i, ppet_bits, ppet_size, ru_bit_mask = 0x7; /* HE80 */
-       static const u8 ppet16_ppet8_ru3_ru0[] = {0x1c, 0xc7, 0x71};
-
-       he_ppet[0] = FIELD_PREP(IEEE80211_PPE_THRES_NSS_MASK, nss - 1) |
-                    FIELD_PREP(IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK,
-                               ru_bit_mask);
-
-       ppet_bits = IEEE80211_PPE_THRES_INFO_PPET_SIZE *
-                   nss * hweight8(ru_bit_mask) * 2;
-       ppet_size = DIV_ROUND_UP(ppet_bits, 8);
-
-       for (i = 0; i < ppet_size - 1; i++)
-               he_ppet[i + 1] = ppet16_ppet8_ru3_ru0[i % 3];
-
-       he_ppet[i + 1] = ppet16_ppet8_ru3_ru0[i % 3] &
-                        (0xff >> (8 - (ppet_bits - 1) % 8));
-}
-
 static void
 mt7996_init_he_caps(struct mt7996_phy *phy, enum nl80211_band band,
                    struct ieee80211_sband_iftype_data *data,
@@ -683,7 +662,7 @@ mt7996_init_he_caps(struct mt7996_phy *phy, enum nl80211_band band,
        memset(he_cap->ppe_thres, 0, sizeof(he_cap->ppe_thres));
        if (he_cap_elem->phy_cap_info[6] &
            IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) {
-               mt7996_gen_ppe_thresh(he_cap->ppe_thres, nss);
+               mt76_connac_gen_ppe_thresh(he_cap->ppe_thres, nss);
        } else {
                he_cap_elem->phy_cap_info[9] |=
                        u8_encode_bits(IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_16US,