wifi: mt76: mt7915: exclude tx backoff time from airtime
authorChad Monroe <chad@monroe.io>
Tue, 26 Nov 2024 04:52:58 +0000 (04:52 +0000)
committerFelix Fietkau <nbd@nbd.name>
Tue, 14 Jan 2025 12:34:34 +0000 (13:34 +0100)
This helps to make STA airtime counters more accurate.

Signed-off-by: Chad Monroe <chad@monroe.io>
Suggested-by: Ryder Lee <ryder.lee@mediatek.com>
Link: https://patch.msgid.link/026380cec180261956b983cbdb009605867bcd8d.1732596478.git.chad@monroe.io
Signed-off-by: Felix Fietkau <nbd@nbd.name>
drivers/net/wireless/mediatek/mt76/mt7915/init.c
drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
drivers/net/wireless/mediatek/mt76/mt7915/mmio.c
drivers/net/wireless/mediatek/mt76/mt7915/regs.h

index bc983ab10b0c7abf324e95808e324bdef78d1335..4282857d8ce90b5d40ee2bd79ff3ac6e4b9ef087 100644 (file)
@@ -512,6 +512,15 @@ mt7915_mac_init_band(struct mt7915_dev *dev, u8 band)
        mt76_clear(dev, MT_WF_RMAC_MIB_AIRTIME4(band),
                   MT_WF_RMAC_MIB_QOS23_BACKOFF);
 
+       /* clear backoff time for Tx duration */
+       mt76_clear(dev, MT_WTBLOFF_TOP_ACR(band),
+                  MT_WTBLOFF_TOP_ADM_BACKOFFTIME);
+
+       /* exclude estimated backoff time for Tx duration on MT7915 */
+       if (is_mt7915(&dev->mt76))
+               mt76_set(dev, MT_AGG_ATCR0(band),
+                          MT_AGG_ATCR_MAC_BFF_TIME_EN);
+
        /* clear backoff time and set software compensation for OBSS time */
        mask = MT_WF_RMAC_MIB_OBSS_BACKOFF | MT_WF_RMAC_MIB_ED_OFFSET;
        set = FIELD_PREP(MT_WF_RMAC_MIB_OBSS_BACKOFF, 0) |
index 87d0dd040001c5d8986230326786626858e969b3..35af41b5bad667ef257b391492b63ded92fc48ec 100644 (file)
@@ -3150,8 +3150,13 @@ int mt7915_mcu_get_chan_mib_info(struct mt7915_phy *phy, bool chan_switch)
        res = (struct mt7915_mcu_mib *)(skb->data + offs_cc);
 
 #define __res_u64(s) le64_to_cpu(res[s].data)
-       /* subtract Tx backoff time from Tx duration */
-       cc_tx = is_mt7915(&dev->mt76) ? __res_u64(1) - __res_u64(4) : __res_u64(1);
+       /* subtract Tx backoff time from Tx duration for MT7915 */
+       if (is_mt7915(&dev->mt76)) {
+               u64 backoff = (__res_u64(4) & 0xffff) * 79;  /* 16us + 9us * 7 */
+               cc_tx = __res_u64(1) - backoff;
+       } else {
+               cc_tx = __res_u64(1);
+       }
 
        if (chan_switch)
                goto out;
index 44e112b8b5b368e4e3917b4761d4fda72d771384..530182e20ce29d2b24e13277c57cfd5523c51f8f 100644 (file)
@@ -138,6 +138,7 @@ static const u32 mt7915_offs[] = {
        [AGG_ACR0]              = 0x084,
        [AGG_ACR4]              = 0x08c,
        [AGG_MRCR]              = 0x098,
+       [AGG_ATCR0]             = 0x0ec,
        [AGG_ATCR1]             = 0x0f0,
        [AGG_ATCR3]             = 0x0f4,
        [LPON_UTTR0]            = 0x080,
@@ -212,6 +213,7 @@ static const u32 mt7916_offs[] = {
        [AGG_ACR0]              = 0x054,
        [AGG_ACR4]              = 0x05c,
        [AGG_MRCR]              = 0x068,
+       [AGG_ATCR0]             = 0x1a4,
        [AGG_ATCR1]             = 0x1a8,
        [AGG_ATCR3]             = 0x080,
        [LPON_UTTR0]            = 0x360,
index 89ac8e6707b8f6ea8bb3377fb3d94364bad935d0..c5ec63a25a42f9fa28387c34e498281c46e62c96 100644 (file)
@@ -66,6 +66,7 @@ enum offs_rev {
        AGG_ACR0,
        AGG_ACR4,
        AGG_MRCR,
+       AGG_ATCR0,
        AGG_ATCR1,
        AGG_ATCR3,
        LPON_UTTR0,
@@ -254,6 +255,9 @@ enum offs_rev {
 #define MT_WTBLOFF_TOP_RSCR_RCPI_MODE  GENMASK(31, 30)
 #define MT_WTBLOFF_TOP_RSCR_RCPI_PARAM GENMASK(25, 24)
 
+#define MT_WTBLOFF_TOP_ACR(_band)      MT_WTBLOFF_TOP(_band, 0x010)
+#define MT_WTBLOFF_TOP_ADM_BACKOFFTIME BIT(29)
+
 /* ETBF: band 0(0x820ea000), band 1(0x820fa000) */
 #define MT_WF_ETBF_BASE(_band)         ((_band) ? 0x820fa000 : 0x820ea000)
 #define MT_WF_ETBF(_band, ofs)         (MT_WF_ETBF_BASE(_band) + (ofs))
@@ -505,6 +509,9 @@ enum offs_rev {
 #define MT_AGG_MRCR_RTS_FAIL_LIMIT             GENMASK(11, 7)
 #define MT_AGG_MRCR_TXCMD_RTS_FAIL_LIMIT       GENMASK(28, 24)
 
+#define MT_AGG_ATCR0(_band)                    MT_WF_AGG(_band, __OFFS(AGG_ATCR0))
+#define MT_AGG_ATCR_MAC_BFF_TIME_EN    BIT(30)
+
 #define MT_AGG_ATCR1(_band)            MT_WF_AGG(_band, __OFFS(AGG_ATCR1))
 #define MT_AGG_ATCR3(_band)            MT_WF_AGG(_band, __OFFS(AGG_ATCR3))