wifi: mt76: mt7996: fix MIB TX aggregation counter registers for mt7990
Subsystems (3)
Felix Fietkau
maintainerPATCH 1/15 wifi: mt76: mt7996: fix MIB TX aggregation counter registers for mt7990
The MIB_TSCR0-7 counters read by mt7996_mac_update_stats() are hardcoded at the mt7996/mt7992 offsets 0x6b0-0x6d0, but mt7990 moved them to 0x750-0x770, so TX AMPDU statistics were read from unrelated registers on that chip. Move the offsets into the per-chip register tables.
--- .../net/wireless/mediatek/mt76/mt7996/mmio.c | 24 +++++++++++++++++++ .../net/wireless/mediatek/mt76/mt7996/regs.h | 24 ++++++++++++------- 2 files changed, 40 insertions(+), 8 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7996/mmio.c +24 -0
@@ -54,6 +54,14 @@ static const u32 mt7996_offs[] = { [MIB_BSCR7] = 0x9e8, [MIB_BSCR17] = 0xa10, [MIB_TRDR1] = 0xa28, + [MIB_TSCR0] = 0x6b0, + [MIB_TSCR1] = 0x6b4, + [MIB_TSCR2] = 0x6b8, + [MIB_TSCR3] = 0x6bc, + [MIB_TSCR4] = 0x6c0, + [MIB_TSCR5] = 0x6c4, + [MIB_TSCR6] = 0x6c8, + [MIB_TSCR7] = 0x6d0, [HIF_REMAP_L1] = 0x24, [HIF_REMAP_BASE_L1] = 0x130000, [HIF_REMAP_L2] = 0x1b4,
@@ -91,6 +99,14 @@ static const u32 mt7992_offs[] = { [MIB_BSCR7] = 0xae4, [MIB_BSCR17] = 0xb0c, [MIB_TRDR1] = 0xb24, + [MIB_TSCR0] = 0x6b0, + [MIB_TSCR1] = 0x6b4, + [MIB_TSCR2] = 0x6b8, + [MIB_TSCR3] = 0x6bc, + [MIB_TSCR4] = 0x6c0, + [MIB_TSCR5] = 0x6c4, + [MIB_TSCR6] = 0x6c8, + [MIB_TSCR7] = 0x6d0, [HIF_REMAP_L1] = 0x8, [HIF_REMAP_BASE_L1] = 0x40000, [HIF_REMAP_L2] = 0x1b4,
@@ -128,6 +144,14 @@ static const u32 mt7990_offs[] = { [MIB_BSCR7] = 0xbd4, [MIB_BSCR17] = 0xbfc, [MIB_TRDR1] = 0xc14, + [MIB_TSCR0] = 0x750, + [MIB_TSCR1] = 0x754, + [MIB_TSCR2] = 0x758, + [MIB_TSCR3] = 0x75c, + [MIB_TSCR4] = 0x760, + [MIB_TSCR5] = 0x764, + [MIB_TSCR6] = 0x768, + [MIB_TSCR7] = 0x770, [HIF_REMAP_L1] = 0x8, [HIF_REMAP_BASE_L1] = 0x40000, [HIF_REMAP_L2] = 0x1b8,
drivers/net/wireless/mediatek/mt76/mt7996/regs.h +16 -8
@@ -64,6 +64,14 @@ enum offs_rev {MIB_BSCR7 ,MIB_BSCR17 ,MIB_TRDR1 , +MIB_TSCR0 , +MIB_TSCR1 , +MIB_TSCR2 , +MIB_TSCR3 , +MIB_TSCR4 , +MIB_TSCR5 , +MIB_TSCR6 , +MIB_TSCR7 ,HIF_REMAP_L1 ,HIF_REMAP_BASE_L1 , HIF_REMAP_L2,
@@ -250,9 +258,9 @@ enum offs_rev {#define MT_MIB_BSCR7 (_band) MT_WF_MIB(_band, __OFFS(MIB_BSCR7))#define MT_MIB_BSCR17 (_band) MT_WF_MIB(_band, __OFFS(MIB_BSCR17)) -#define MT_MIB_TSCR5 (_band) MT_WF_MIB(_band, 0x6c4) -#define MT_MIB_TSCR6 (_band) MT_WF_MIB(_band, 0x6c8) -#define MT_MIB_TSCR7 (_band) MT_WF_MIB(_band, 0x6d0) +#define MT_MIB_TSCR5 (_band) MT_WF_MIB(_band, __OFFS(MIB_TSCR5)) +#define MT_MIB_TSCR6 (_band) MT_WF_MIB(_band, __OFFS(MIB_TSCR6)) +#define MT_MIB_TSCR7 (_band) MT_WF_MIB(_band, __OFFS(MIB_TSCR7))#define MT_MIB_RSCR1 (_band) MT_WF_MIB(_band, __OFFS(MIB_RSCR1))/* rx mpdu counter, full 32 bits */
@@ -268,14 +276,14 @@ enum offs_rev {#define MT_MIB_RSCR36 (_band) MT_WF_MIB(_band, __OFFS(MIB_RSCR36))/* tx ampdu cnt, full 32 bits */ -#define MT_MIB_TSCR0 (_band) MT_WF_MIB(_band, 0x6b0) -#define MT_MIB_TSCR2 (_band) MT_WF_MIB(_band, 0x6b8) +#define MT_MIB_TSCR0 (_band) MT_WF_MIB(_band, __OFFS(MIB_TSCR0)) +#define MT_MIB_TSCR2 (_band) MT_WF_MIB(_band, __OFFS(MIB_TSCR2))/* counts all mpdus in ampdu, regardless of success */ -#define MT_MIB_TSCR3 (_band) MT_WF_MIB(_band, 0x6bc) +#define MT_MIB_TSCR3 (_band) MT_WF_MIB(_band, __OFFS(MIB_TSCR3))/* counts all successfully tx'd mpdus in ampdu */ -#define MT_MIB_TSCR4 (_band) MT_WF_MIB(_band, 0x6c0) +#define MT_MIB_TSCR4 (_band) MT_WF_MIB(_band, __OFFS(MIB_TSCR4))/* rx ampdu count, 32-bit */ #define MT_MIB_RSCR27 (_band) MT_WF_MIB(_band, __OFFS(MIB_RSCR27))
@@ -299,7 +307,7 @@ enum offs_rev {#define MT_MIB_RVSR1 (_band) MT_WF_MIB(_band, __OFFS(MIB_RVSR1))/* rx blockack count, 32 bits */ -#define MT_MIB_TSCR1 (_band) MT_WF_MIB(_band, 0x6b4) +#define MT_MIB_TSCR1 (_band) MT_WF_MIB(_band, __OFFS(MIB_TSCR1))#define MT_MIB_BTSCR0 (_band) MT_WF_MIB(_band, 0x5e0)#define MT_MIB_BTSCR5 (_band) MT_WF_MIB(_band, __OFFS(MIB_BTSCR5))
Signature · 1 line
2.53.0
Felix Fietkau
maintainerPATCH 2/15 wifi: mt76: mt7915: fix double hif2 init on the non-WED path
mt7915_pci_init_hif2() was called unconditionally and again inside the WED-inactive branch. The helper increments the global hif_idx, writes the PCIe RECOG_ID register and takes a get_device() reference via mt7915_pci_get_hif2(), while removal only drops one reference. On non-WED dual-hif hardware this double-incremented hif_idx, wrote RECOG_ID twice and leaked a device reference. Only the call inside the WED-inactive branch is correct; drop the unconditional one. hif2 is already initialised to NULL.
--- drivers/net/wireless/mediatek/mt76/mt7915/pci.c | 1 - 1 file changed, 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7915/pci.c +0 -1
@@ -135,7 +135,6 @@ static int mt7915_pci_probe(struct pci_dev *pdev, mdev = &dev->mt76;mt7915_wfsys_reset (dev); - hif2 =mt7915_pci_init_hif2 (pdev); ret =mt7915_mmio_wed_init (dev, pdev, true, &irq);if (ret <0 )
Signature · 1 line
2.53.0
Felix Fietkau
maintainerPATCH 3/15 wifi: mt76: mt7915: fix ext PHY use-after-free on register error path
In reply to Felix FietkauAfter mt7915_register_ext_phy() succeeded, a failure of the main PHY mt7915_init_debugfs() or mt7915_coredump_register() unwound through free_phy2, which called ieee80211_free_hw() on the ext PHY hw while it was still registered with mac80211, since mt76_unregister_device() only unregisters the main hw. Unregister the ext PHY (thermal + phy + hw) first and skip the redundant free.
--- drivers/net/wireless/mediatek/mt76/mt7915/init.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7915/init.c +7 -2
@@ -1302,14 +1302,19 @@ int mt7915_register_device(struct mt7915_dev *dev) ret =mt7915_init_debugfs (&dev->phy);if (ret) - goto unreg_thermal; + goto unreg_ext_phy; ret =mt7915_coredump_register (dev);if (ret) - goto unreg_thermal; + goto unreg_ext_phy;return 0 ; +unreg_ext_phy: +if (phy2) { +mt7915_unregister_ext_phy (dev); + phy2 =NULL ; + } unreg_thermal:mt7915_unregister_thermal (&dev->phy); unreg_dev:
Signature · 1 line
2.53.0
Felix Fietkau
maintainerPATCH 4/15 wifi: mt76: mt7915: release hif2 reference on probe IRQ failure
In reply to Felix FietkauThe hif2 reference obtained by mt7915_pci_init_hif2() is only released on error paths that key off dev->hif2, which is not assigned until after the IRQ setup. If pci_alloc_irq_vectors() or the primary devm_request_irq() fails, the reference leaks. Drop it explicitly on those paths via mt7915_put_hif2().
--- drivers/net/wireless/mediatek/mt76/mt7915/pci.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7915/pci.c +6 -2
@@ -144,16 +144,20 @@ static int mt7915_pci_probe(struct pci_dev *pdev, hif2 =mt7915_pci_init_hif2 (pdev); ret =pci_alloc_irq_vectors (pdev,1 ,1 ,PCI_IRQ_ALL_TYPES ); -if (ret <0 ) +if (ret <0 ) { +mt7915_put_hif2 (hif2); goto free_device; + } irq = pdev->irq; } ret =devm_request_irq (mdev->dev, irq, mt7915_irq_handler,IRQF_SHARED ,KBUILD_MODNAME , dev); -if (ret) +if (ret) { +mt7915_put_hif2 (hif2); goto free_wed_or_irq_vector; + }/* master switch of PCIe tnterrupt enable */ mt76_wr (dev,MT_PCIE_MAC_INT_ENABLE ,0xff );
Signature · 1 line
2.53.0
Felix Fietkau
maintainerPATCH 5/15 wifi: mt76: mt7996: fix reg addr remap when addr is 0
In reply to Felix FietkauFrom: StanleyYP Wang <[email protected]>
When addr is less than the hardcoded threshold in __mt7996_reg_addr, it indicates that remapping is unnecessary.
Currently, the flow remaps address 0x0 to MT_HIF_REMAP_BASE_L2, which is incorrect.
To address this, modify __mt7996_reg_addr to return INVALID_REG_ADDR if the address is not below the hardcoded value or is not present in the mt7996_reg_map array.
Additionally, update the remap condition to check if addr is equal to INVALID_REG_ADDR.
--- drivers/net/wireless/mediatek/mt76/mt7996/mmio.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7996/mmio.c +7 -5
@@ -17,6 +17,8 @@static bool wed_enable;module_param (wed_enable, bool,0644 ); +#define INVALID_REG_ADDR 0xffffffff +static const struct __base mt7996_reg_base[] = { [WF_AGG_BASE ] = { {0x820e2000 ,0x820f2000 ,0x830e2000 } }, [WF_ARB_BASE ] = { {0x820e3000 ,0x820f3000 ,0x830e3000 } },
@@ -358,7 +360,7 @@ static u32 __mt7996_reg_addr(struct mt7996_dev *dev, u32 addr)return dev->reg.map[i].mapped + ofs; } -return 0 ; +return INVALID_REG_ADDR ; }static u32 __mt7996_reg_remap_addr (struct mt7996_dev *dev,u32 addr)
@@ -390,7 +392,7 @@ void mt7996_memcpy_fromio(struct mt7996_dev *dev, void *buf, u32 offset, {u32 addr =__mt7996_reg_addr (dev, offset); -if (addr) { +if (addr !=INVALID_REG_ADDR ) {memcpy_fromio (buf, dev->mt76.mmio.regs + addr, len);return ; }
@@ -406,7 +408,7 @@ static u32 mt7996_rr(struct mt76_dev *mdev, u32 offset) struct mt7996_dev *dev = container_of(mdev, struct mt7996_dev, mt76);u32 addr =__mt7996_reg_addr (dev, offset), val; -if (addr) +if (addr !=INVALID_REG_ADDR )return dev->bus_ops->rr (mdev, addr);spin_lock_bh (&dev->reg_lock);
@@ -421,7 +423,7 @@ static void mt7996_wr(struct mt76_dev *mdev, u32 offset, u32 val) struct mt7996_dev *dev = container_of(mdev, struct mt7996_dev, mt76);u32 addr =__mt7996_reg_addr (dev, offset); -if (addr) { +if (addr !=INVALID_REG_ADDR ) { dev->bus_ops->wr (mdev, addr, val);return ; }
@@ -436,7 +438,7 @@ static u32 mt7996_rmw(struct mt76_dev *mdev, u32 offset, u32 mask, u32 val) struct mt7996_dev *dev = container_of(mdev, struct mt7996_dev, mt76);u32 addr =__mt7996_reg_addr (dev, offset); -if (addr) +if (addr !=INVALID_REG_ADDR )return dev->bus_ops->rmw (mdev, addr, mask, val);spin_lock_bh (&dev->reg_lock);
Signature · 1 line
2.53.0
Felix Fietkau
maintainerPATCH 6/15 wifi: mt76: mt7996: do not attach hif2 WED when the main WED attach failed
In reply to Felix FietkauIf the WED attach for the primary PCIe function fails, the probe path still attached wed_hif2 for the secondary function, leaving the device in an inconsistent half-WED configuration that crashes later. The hif2 call also re-enabled hwrro_mode, which the failed primary attach had just turned off.
Skip the hif2 WED setup when the primary WED device is not active.
--- drivers/net/wireless/mediatek/mt76/mt7996/mmio.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7996/mmio.c +3 -0
@@ -490,6 +490,9 @@ int mt7996_mmio_wed_init(struct mt7996_dev *dev, void *pdev_ptr,if (!wed_enable)return 0 ; +if (hif2 && !mtk_wed_device_active (&dev->mt76.mmio.wed)) +return 0 ; + dev->mt76.hwrro_mode =is_mt7996 (&dev->mt76) ?MT76_HWRRO_V3 :MT76_HWRRO_V3_1 ;
Signature · 1 line
2.53.0
Felix Fietkau
maintainerPATCH 7/15 wifi: mt76: mt7996: do not leave state behind after a failed WED attach
In reply to Felix Fietkaumt7996_mmio_wed_init() set dev->mt76.hwrro_mode and rx_token_size while building the WED configuration, before knowing whether the WED attach can succeed. A failed attach left the enlarged rx_token_size behind and reset hwrro_mode to MT76_HWRRO_OFF, clobbering the values that another RX datapath owner may have configured earlier in probe: on Airoha platforms with the wed_enable module parameter set, this broke the NPU offload configuration set up by mt76_npu_init() (NPU offload requires HW-RRO and a larger rx token space, and the attach always fails there since no SoC has both an Airoha NPU and MTK WED).
Move both assignments after a successful attach, next to the existing success-only dma_dev/irq assignments. This is safe for the regular WED attach case: the first consumer of either field runs after probe continues (mtk_wed_device_attach() only invokes the init_buf callback; rx buffers are allocated via init_rx_buf from mtk_wed_start(), long after mt7996_mmio_wed_init() has returned).
Within the WED configuration the HW-RRO checks were constant: the mode was assigned unconditionally right before them, and the hif2 path is only reachable after a successful main attach has set it. Resolve them to their constant values and drop the dead branches.
--- .../net/wireless/mediatek/mt76/mt7996/mmio.c | 53 +++++++------------ 1 file changed, 20 insertions(+), 33 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7996/mmio.c +20 -33
@@ -493,9 +493,6 @@ int mt7996_mmio_wed_init(struct mt7996_dev *dev, void *pdev_ptr,if (hif2 && !mtk_wed_device_active (&dev->mt76.mmio.wed))return 0 ; - dev->mt76.hwrro_mode =is_mt7996 (&dev->mt76) ?MT76_HWRRO_V3 - :MT76_HWRRO_V3_1 ; - hif1_ofs = dev->hif2 ?MT_WFDMA0_PCIE1 (0 ) -MT_WFDMA0 (0 ) :0 ;if (hif2)
@@ -520,23 +517,16 @@ int mt7996_mmio_wed_init(struct mt7996_dev *dev, void *pdev_ptr, wed->wlan.wpdma_tx = wed->wlan.phy_base + hif1_ofs +MT_TXQ_RING_BASE (0 ) +MT7996_TXQ_BAND2 *MT_RING_SIZE ; -if (mt7996_has_hwrro (dev)) { -if (is_mt7996 (&dev->mt76)) { - wed->wlan.txfree_tbit =ffs (MT_INT_RX_TXFREE_EXT ) -1 ; - wed->wlan.wpdma_txfree = wed->wlan.phy_base + hif1_ofs + -MT_RXQ_RING_BASE (0 ) + -MT7996_RXQ_TXFREE2 *MT_RING_SIZE ; - }else { - wed->wlan.txfree_tbit =ffs (MT_INT_RX_TXFREE_BAND1_EXT ) -1 ; - wed->wlan.wpdma_txfree = wed->wlan.phy_base + hif1_ofs + -MT_RXQ_RING_BASE (0 ) + -MT7996_RXQ_MCU_WA_EXT *MT_RING_SIZE ; - } - }else { +if (is_mt7996 (&dev->mt76)) { + wed->wlan.txfree_tbit =ffs (MT_INT_RX_TXFREE_EXT ) -1 ; wed->wlan.wpdma_txfree = wed->wlan.phy_base + hif1_ofs +MT_RXQ_RING_BASE (0 ) + -MT7996_RXQ_MCU_WA_TRI *MT_RING_SIZE ; - wed->wlan.txfree_tbit =ffs (MT_INT_RX_DONE_WA_TRI ) -1 ; +MT7996_RXQ_TXFREE2 *MT_RING_SIZE ; + }else { + wed->wlan.txfree_tbit =ffs (MT_INT_RX_TXFREE_BAND1_EXT ) -1 ; + wed->wlan.wpdma_txfree = wed->wlan.phy_base + hif1_ofs + +MT_RXQ_RING_BASE (0 ) + +MT7996_RXQ_MCU_WA_EXT *MT_RING_SIZE ; } wed->wlan.wpdma_rx_glo = wed->wlan.phy_base + hif1_ofs +MT_WFDMA0_GLO_CFG ;
@@ -547,7 +537,7 @@ int mt7996_mmio_wed_init(struct mt7996_dev *dev, void *pdev_ptr, wed->wlan.id =MT7996_DEVICE_ID_2 ; wed->wlan.tx_tbit[0 ] =ffs (MT_INT_TX_DONE_BAND2 ) -1 ; }else { - wed->wlan.hw_rro =mt7996_has_hwrro (dev); + wed->wlan.hw_rro = true; wed->wlan.wpdma_int = wed->wlan.phy_base +MT_INT_SOURCE_CSR ; wed->wlan.wpdma_mask = wed->wlan.phy_base +MT_INT_MASK_CSR ; wed->wlan.wpdma_tx = wed->wlan.phy_base + MT_TXQ_RING_BASE(0) +
@@ -600,23 +590,15 @@ int mt7996_mmio_wed_init(struct mt7996_dev *dev, void *pdev_ptr, wed->wlan.tx_tbit[0 ] =ffs (MT_INT_TX_DONE_BAND0 ) -1 ; wed->wlan.tx_tbit[1 ] =ffs (MT_INT_TX_DONE_BAND1 ) -1 ;if (is_mt7996 (&dev->mt76)) { -if (mt7996_has_hwrro (dev)) { - wed->wlan.wpdma_txfree = wed->wlan.phy_base + -MT_RXQ_RING_BASE (0 ) + -MT7996_RXQ_TXFREE0 *MT_RING_SIZE ; - wed->wlan.txfree_tbit =ffs (MT_INT_RX_TXFREE_MAIN ) -1 ; - }else { - wed->wlan.wpdma_txfree = wed->wlan.phy_base + -MT_RXQ_RING_BASE (0 ) + -MT7996_RXQ_MCU_WA_MAIN *MT_RING_SIZE ; - wed->wlan.txfree_tbit =ffs (MT_INT_RX_DONE_WA_MAIN ) -1 ; - } + wed->wlan.wpdma_txfree = wed->wlan.phy_base + +MT_RXQ_RING_BASE (0 ) + +MT7996_RXQ_TXFREE0 *MT_RING_SIZE ; + wed->wlan.txfree_tbit =ffs (MT_INT_RX_TXFREE_MAIN ) -1 ; }else { wed->wlan.txfree_tbit =ffs (MT_INT_RX_DONE_WA_MAIN ) -1 ; wed->wlan.wpdma_txfree = wed->wlan.phy_base +MT_RXQ_RING_BASE (0 ) +MT7996_RXQ_MCU_WA_MAIN *MT_RING_SIZE ; } - dev->mt76.rx_token_size =MT7996_TOKEN_SIZE + wed->wlan.rx_npkt;if (dev->hif2 &&is_mt7992 (&dev->mt76)) wed->wlan.id =0x7992 ;
@@ -639,9 +621,14 @@ int mt7996_mmio_wed_init(struct mt7996_dev *dev, void *pdev_ptr, wed->wlan.reset_complete = mt76_wed_reset_complete; } -if (mtk_wed_device_attach (wed)) { - dev->mt76.hwrro_mode =MT76_HWRRO_OFF ; +if (mtk_wed_device_attach (wed))return 0 ; + +if (!hif2) { + dev->mt76.hwrro_mode =is_mt7996 (&dev->mt76) ?MT76_HWRRO_V3 + :MT76_HWRRO_V3_1 ; + dev->mt76.rx_token_size =MT7996_TOKEN_SIZE + + wed->wlan.rx_npkt; } *irq = wed->irq;
Signature · 1 line
2.53.0
Felix Fietkau
maintainerPATCH 8/15 wifi: mt76: mt7915: fix chainmask handling for non-dbdc phys on band 1
In reply to Felix FietkauOn single-adie mt7986 the only phy is bound to band 1, but its chainmask is stored unshifted, because dev->chainshift is still zero while the eeprom is parsed for the main phy. mt7915_set_antenna() on the other hand shifts by chainshift * band_idx, so the representation of the chainmask changed as soon as the antenna configuration was touched. Until then, mt7915_mcu_set_chan_info() passed rx_path = 0 to the firmware, since shifting the unshifted mask down clears all bits.
Keep the unshifted form for that case and add helpers for the band local chainmask, so that only the band 1 phy of a dbdc device uses the shifted form.
--- .../net/wireless/mediatek/mt76/mt7915/eeprom.c | 2 +- .../net/wireless/mediatek/mt76/mt7915/main.c | 6 +++--- .../net/wireless/mediatek/mt76/mt7915/mcu.c | 2 +- .../net/wireless/mediatek/mt76/mt7915/mt7915.h | 18 ++++++++++++++++++ .../wireless/mediatek/mt76/mt7915/testmode.c | 5 +---- 5 files changed, 24 insertions(+), 9 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c +1 -1
@@ -257,7 +257,7 @@ void mt7915_eeprom_parse_hw_cap(struct mt7915_dev *dev, nss =min_t (u8,min_t (u8, nss_max, nss), path); mphy->chainmask =BIT (path) -1 ; -if (band) +if (band && dev->dbdc_support) mphy->chainmask <<= dev->chainshift; mphy->antenna_mask =BIT (nss) -1 ; dev->chainmask |= mphy->chainmask;
drivers/net/wireless/mediatek/mt76/mt7915/main.c +3 -3
@@ -1138,7 +1138,7 @@ mt7915_set_antenna(struct ieee80211_hw *hw, int radio_idx, u32 tx_ant, u32 rx_anstruct mt7915_dev *dev =mt7915_hw_dev (hw);struct mt7915_phy *phy =mt7915_hw_phy (hw);int max_nss =hweight8 (hw->wiphy->available_antennas_tx); -u8 chainshift = dev->chainshift; +u8 shift =mt7915_band_chainshift (phy);u8 band = phy->mt76->band_idx;if (!tx_ant || tx_ant != rx_ant ||ffs (tx_ant) > max_nss)
@@ -1151,9 +1151,9 @@ mt7915_set_antenna(struct ieee80211_hw *hw, int radio_idx, u32 tx_ant, u32 rx_an/* handle a variant of mt7916/mt7981 which has 3T3R but nss2 on 5 GHz band */ if ((is_mt7916 (&dev->mt76) ||is_mt7981 (&dev->mt76)) && band &&hweight8 (tx_ant) == max_nss) - phy->mt76->chainmask = (dev->chainmask >> chainshift) << chainshift; + phy->mt76->chainmask = (dev->chainmask >> shift) << shift;else - phy->mt76->chainmask = tx_ant << (chainshift * band); + phy->mt76->chainmask = tx_ant << shift;mt76_set_stream_caps (phy->mt76, true);mt7915_set_stream_vht_txbf_caps (phy);
drivers/net/wireless/mediatek/mt76/mt7915/mcu.c +1 -1
@@ -2796,7 +2796,7 @@ int mt7915_mcu_set_chan_info(struct mt7915_phy *phy, int cmd) .center_ch = ieee80211_frequency_to_channel(freq1), .bw = mt76_connac_chan_bw(chandef), .tx_path_num = hweight16(phy->mt76->chainmask), - .rx_path = phy->mt76->chainmask >> (dev->chainshift * band), + .rx_path = mt7915_band_chainmask(phy), .band_idx = band, .channel_band = ch_band[chandef->chan->band], };
drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h +18 -0
@@ -399,6 +399,24 @@ mt7915_ext_phy(struct mt7915_dev *dev)return phy->priv; } +/* without dbdc, the chainmask is stored unshifted, even if the phy is +* bound to band 1 +*/ +static inline u8 mt7915_band_chainshift (struct mt7915_phy *phy) +{ +struct mt7915_dev *dev = phy->dev; + +if (!dev->dbdc_support) +return 0 ; + +return phy->mt76->band_idx * dev->chainshift; +} + +static inline u16 mt7915_band_chainmask (struct mt7915_phy *phy) +{ +return phy->mt76->chainmask >>mt7915_band_chainshift (phy); +} +static inline u32 mt7915_check_adie (struct mt7915_dev *dev,bool sku) {u32 mask = sku ?MT_CONNINFRA_SKU_MASK :MT_ADIE_TYPE_MASK ;
drivers/net/wireless/mediatek/mt76/mt7915/testmode.c +1 -4
@@ -694,9 +694,7 @@ mt7915_tm_set_params(struct mt76_phy *mphy, struct nlattr **tb, {struct mt76_testmode_data *td = &mphy->test;struct mt7915_phy *phy = mphy->priv; -struct mt7915_dev *dev = phy->dev; -u32 chainmask = mphy->chainmask, changed =0 ; -bool ext_phy = phy != &dev->phy; +u32 chainmask =mt7915_band_chainmask (phy), changed =0 ;int i;BUILD_BUG_ON (NUM_TM_CHANGED >=32 );
@@ -705,7 +703,6 @@ mt7915_tm_set_params(struct mt76_phy *mphy, struct nlattr **tb, td->state == MT76_TM_STATE_OFF)return 0 ; - chainmask = ext_phy ? chainmask >> dev->chainshift : chainmask;if (td->tx_antenna_mask > chainmask)return -EINVAL ;
Signature · 1 line
2.53.0
Felix Fietkau
maintainerPATCH 9/15 wifi: mt76: mt7915: report RX chain signal for all RX paths
In reply to Felix Fietkaustatus->chains was set from the antenna mask, which is derived from the number of spatial streams, while the chain_signal array is filled from all RCPI fields. On boards where the number of RX paths exceeds the stream count, e.g. the 3T3R mt7916/mt7981 variant with 2 streams on the 5 GHz band, the RSSI of the extra chains was never reported.
Use the band local RX path chainmask instead.
--- drivers/net/wireless/mediatek/mt76/mt7915/mac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7915/mac.c +1 -1
@@ -437,7 +437,7 @@ mt7915_mac_fill_rx(struct mt7915_dev *dev, struct sk_buff *skb,if (v0 &MT_PRXV_HT_AD_CODE ) status->enc_flags |=RX_ENC_FLAG_LDPC ; - status->chains = mphy->antenna_mask; + status->chains =mt7915_band_chainmask (phy); status->chain_signal[0 ] =to_rssi (MT_PRXV_RCPI0 , v1); status->chain_signal[1 ] =to_rssi (MT_PRXV_RCPI1 , v1); status->chain_signal[2 ] =to_rssi (MT_PRXV_RCPI2 , v1);
Signature · 1 line
2.53.0
Felix Fietkau
maintainerPATCH 10/15 wifi: mt76: mt7996: remove repeater muar config
In reply to Felix FietkauFrom: StanleyYP Wang <[email protected]>
Repeater mode is not supported currently, so remove it. get_omac_idx() only hands out HW_BSSID/EXT_BSSID indices, so the omac_idx >= REPEATER_BSSID_START call sites are unreachable.
--- .../net/wireless/mediatek/mt76/mt7996/mcu.c | 45 ------------------- 1 file changed, 45 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7996/mcu.c +0 -45
@@ -1042,43 +1042,6 @@ mt7996_mcu_bss_sec_tlv(struct sk_buff *skb, struct mt76_vif_link *mlink) sec->cipher = mlink->cipher; } -static int -mt7996_mcu_muar_config (struct mt7996_dev *dev,struct mt76_vif_link *mlink, -const u8 *addr,bool bssid,bool enable) -{ -#define UNI_MUAR_ENTRY 2 -u32 idx = mlink->omac_idx -REPEATER_BSSID_START ; -struct { -struct { -u8 band; -u8 __rsv[3 ]; - } hdr; - -__le16 tag; -__le16 len; - -bool smesh; -u8 bssid; -u8 index; -u8 entry_add; -u8 addr[ETH_ALEN ]; -u8 __rsv[2 ]; - } __packed req = { - .hdr.band = mlink->band_idx, - .tag =cpu_to_le16 (UNI_MUAR_ENTRY ), - .len =cpu_to_le16 (sizeof (req) -sizeof (req.hdr)), - .smesh = false, - .index = idx *2 + bssid, - .entry_add = true, - }; - -if (enable) -memcpy (req.addr, addr,ETH_ALEN ); - -return mt76_mcu_send_msg (&dev->mt76,MCU_WM_UNI_CMD (REPT_MUAR ), &req, -sizeof (req), true); -} -static void mt7996_mcu_bss_ifs_timing_tlv (struct sk_buff *skb,struct mt7996_phy *phy) {
@@ -1208,11 +1171,6 @@ int mt7996_mcu_add_bss_info(struct mt7996_phy *phy, struct ieee80211_vif *vif,struct mt7996_dev *dev = phy->dev;struct sk_buff *skb; -if (mlink->omac_idx >=REPEATER_BSSID_START ) { -mt7996_mcu_muar_config (dev, mlink, link_conf->addr, false, enable); -mt7996_mcu_muar_config (dev, mlink, link_conf->bssid, true, enable); - } - skb =__mt7996_mcu_alloc_bss_req (&dev->mt76, mlink,MT7996_BSS_UPDATE_MAX_SIZE );if (IS_ERR (skb))
@@ -2989,9 +2947,6 @@ int mt7996_mcu_add_dev_info(struct mt7996_phy *phy, struct ieee80211_vif *vif, }, }; -if (mlink->omac_idx >=REPEATER_BSSID_START ) -return mt7996_mcu_muar_config (dev, mlink, link_conf->addr, false, enable); -memcpy (data.tlv.omac_addr, link_conf->addr,ETH_ALEN );return mt76_mcu_send_msg (&dev->mt76,MCU_WMWA_UNI_CMD (DEV_INFO_UPDATE ), &data,sizeof (data), true);
Signature · 1 line
2.53.0
Felix Fietkau
maintainerPATCH 11/15 wifi: mt76: fix queue assignment for disassoc packets
In reply to Felix FietkauFrom: Peter Chiu <[email protected]>
Like deauth, a disassoc frame sent to a client in powersave mode can get stuck in a tx queue along with other buffered frames, filling up hardware queues with frames that are only released after the WTBL slot is reused for another client.
Move disassoc packets to the ALTX queue, matching the existing deauth handling.
--- drivers/net/wireless/mediatek/mt76/tx.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/wireless/mediatek/mt76/tx.c +1 -0
@@ -631,6 +631,7 @@ mt76_txq_schedule_pending_wcid(struct mt76_phy *phy, struct mt76_wcid *wcid, !ieee80211_is_data_present (hdr->frame_control) && (!ieee80211_is_bufferable_mmpdu (skb) ||ieee80211_is_deauth (hdr->frame_control) || +ieee80211_is_disassoc (hdr->frame_control) || head == &wcid->tx_offchannel)) qid = MT_TXQ_PSD;
Signature · 1 line
2.53.0
Felix Fietkau
maintainerPATCH 12/15 wifi: mt76: mt7996: reject iTWT setup requests from MLD stations
In reply to Felix FietkauFrom: Howard Hsu <[email protected]>
The firmware does not support individual TWT agreements with non-AP MLDs, and the driver only tracks TWT flow state on the default link, which may not be the link the agreement was negotiated on. Reject TWT setup requests from MLD stations instead of programming an unsupported configuration.
--- drivers/net/wireless/mediatek/mt76/mt7996/mac.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7996/mac.c +6 -0
@@ -3218,6 +3218,12 @@ void mt7996_mac_add_twt_setup(struct ieee80211_hw *hw,struct mt7996_twt_flow *flow;u8 flowid, table_id, exp; +/* the firmware does not support iTWT agreements with MLD peers, and +* driver TWT state is only tracked on the default link +*/ +if (sta->mlo) + goto out; +if (mt7996_mac_check_twt_req (twt)) goto out;
Signature · 1 line
2.53.0
Felix Fietkau
maintainerPATCH 13/15 wifi: mt76: mt7915: update SKU power limits after changing antennas
In reply to Felix FietkauChanging the antenna configuration updates the stream capabilities but left the per-path SKU power limits and path delta compensation stale until the next channel switch. Reapply the SKU table like mt7996 already does.
--- drivers/net/wireless/mediatek/mt76/mt7915/main.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/wireless/mediatek/mt76/mt7915/main.c +1 -0
@@ -1158,6 +1158,7 @@ mt7915_set_antenna(struct ieee80211_hw *hw, int radio_idx, u32 tx_ant, u32 rx_anmt76_set_stream_caps (phy->mt76, true);mt7915_set_stream_vht_txbf_caps (phy);mt7915_set_stream_he_caps (phy); +mt7915_mcu_set_txpower_sku (phy);mutex_unlock (&dev->mt76.mutex);
Signature · 1 line
2.53.0
Felix Fietkau
maintainerPATCH 14/15 wifi: mt76: mt7996: add scan dwell time hw cap
In reply to Felix FietkauFrom: StanleyYP Wang <[email protected]>
Add NL80211_EXT_FEATURE_SET_SCAN_DWELL support in driver. This allows user to specify channel dwell time during scanning.
--- drivers/net/wireless/mediatek/mt76/mt7996/init.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/wireless/mediatek/mt76/mt7996/init.c +1 -0
@@ -527,6 +527,7 @@ mt7996_init_wiphy(struct ieee80211_hw *hw, struct mtk_wed_device *wed)wiphy_ext_feature_set (wiphy,NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT );wiphy_ext_feature_set (wiphy,NL80211_EXT_FEATURE_CAN_REPLACE_PTK0 );wiphy_ext_feature_set (wiphy,NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER ); +wiphy_ext_feature_set (wiphy,NL80211_EXT_FEATURE_SET_SCAN_DWELL ); if (mt7996_eeprom_has_background_radar(dev) && (!mdev->dev->of_node ||
Signature · 1 line
2.53.0
Felix Fietkau
maintainerPATCH 15/15 wifi: mt76: mt7925: fix infinite loop in UNI event TLV parsing
In reply to Felix FietkauThe event TLV loops accept a zero-length TLV, which advances neither the cursor nor the remaining length, so a malformed event hangs the caller. mt7925_mcu_uni_roc_event() additionally walked past the end of the skb, since it never checked the declared length against the remainder.
Replace the five open-coded loops with a shared iterator that rejects lengths below the TLV header and beyond the remaining buffer, and check the per-tag payload sizes before dereferencing them.
While here, make the RSSI monitor event read from the current TLV rather than from the start of the list.
--- .../net/wireless/mediatek/mt76/mt7925/main.c | 10 ++--- .../net/wireless/mediatek/mt76/mt7925/mcu.c | 38 +++++++++++-------- .../net/wireless/mediatek/mt76/mt7925/mcu.h | 19 ++++++++++ 3 files changed, 46 insertions(+), 21 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/main.c +5 -5
@@ -1562,7 +1562,7 @@ void mt7925_scan_work(struct work_struct *work)while (true) {struct sk_buff *skb;struct tlv *tlv; -int tlv_len; +u32 tlv_len;spin_lock_bh (&phy->dev->mt76.lock); skb =__skb_dequeue (&phy->scan_event_list);
@@ -1575,7 +1575,7 @@ void mt7925_scan_work(struct work_struct *work) tlv = (struct tlv *)skb->data; tlv_len = skb->len; -while (tlv_len >0 &&le16_to_cpu (tlv->len) <= tlv_len) { +mt7925_for_each_tlv (tlv, tlv_len) {struct mt7925_mcu_scan_chinfo_event *evt;switch (le16_to_cpu (tlv->tag)) {
@@ -1588,6 +1588,9 @@ void mt7925_scan_work(struct work_struct *work) }break ;case UNI_EVENT_SCAN_DONE_CHNLINFO : +if (le16_to_cpu (tlv->len) <sizeof (*tlv) +sizeof (*evt)) +break ; + evt = (struct mt7925_mcu_scan_chinfo_event *)tlv->data;mt7925_regd_change (phy, evt->alpha2);
@@ -1599,9 +1602,6 @@ void mt7925_scan_work(struct work_struct *work)default :break ; } - - tlv_len -=le16_to_cpu (tlv->len); - tlv = (struct tlv *)((char *)(tlv) +le16_to_cpu (tlv->len)); }dev_kfree_skb (skb);
drivers/net/wireless/mediatek/mt76/mt7925/mcu.c +22 -16
@@ -409,16 +409,18 @@ mt7925_mcu_uni_hif_ctrl_event(struct mt792x_dev *dev, struct sk_buff *skb) tlv = (struct tlv *)skb->data; tlv_len = skb->len; -while (tlv_len >0 &&le16_to_cpu (tlv->len) <= tlv_len) { +mt7925_for_each_tlv (tlv, tlv_len) {switch (le16_to_cpu (tlv->tag)) {case UNI_EVENT_HIF_CTRL_BASIC : +if (le16_to_cpu (tlv->len) < +sizeof (struct mt7925_mcu_hif_ctrl_basic_tlv )) +break ; +mt7925_mcu_handle_hif_ctrl_basic (dev, tlv);break ;default :break ; } - tlv_len -=le16_to_cpu (tlv->len); - tlv = (struct tlv *)((char *)(tlv) +le16_to_cpu (tlv->len)); } }
@@ -426,22 +428,24 @@ static void mt7925_mcu_uni_roc_event(struct mt792x_dev *dev, struct sk_buff *skb) { struct tlv *tlv; -int i =0 ; +u32 tlv_len;skb_pull (skb,sizeof (struct mt7925_mcu_rxd ) +4 ); + tlv = (struct tlv *)skb->data; + tlv_len = skb->len; -while (i < skb->len) { - tlv = (struct tlv *)(skb->data + i); - +mt7925_for_each_tlv (tlv, tlv_len) {switch (le16_to_cpu (tlv->tag)) {case UNI_EVENT_ROC_GRANT : +if (le16_to_cpu (tlv->len) < +sizeof (struct mt7925_roc_grant_tlv )) +break ; +mt7925_mcu_roc_handle_grant (dev, tlv);break ;case UNI_EVENT_ROC_GRANT_SUB_LINK :break ; } - - i +=le16_to_cpu (tlv->len); } }
@@ -476,7 +480,7 @@ mt7925_mcu_tx_done_event(struct mt792x_dev *dev, struct sk_buff *skb) tlv = (struct tlv *)skb->data; tlv_len = skb->len; -while (tlv_len >0 &&le16_to_cpu (tlv->len) <= tlv_len) { +mt7925_for_each_tlv (tlv, tlv_len) {switch (le16_to_cpu (tlv->tag)) {case UNI_EVENT_TX_DONE_MSG :struct mt7928_uni_txdone_event *evt;
@@ -484,6 +488,9 @@ mt7925_mcu_tx_done_event(struct mt792x_dev *dev, struct sk_buff *skb)if (!is_mt7928 (&dev->mt76))break ; +if (le16_to_cpu (tlv->len) <sizeof (*evt)) +break ; + evt = (struct mt7928_uni_txdone_event *)tlv;if (evt->status) { dev_info(dev->mt76.dev,
@@ -510,8 +517,6 @@ mt7925_mcu_tx_done_event(struct mt792x_dev *dev, struct sk_buff *skb)default :break ; } - tlv_len -=le16_to_cpu (tlv->len); - tlv = (struct tlv *)((char *)(tlv) +le16_to_cpu (tlv->len)); } }
@@ -548,10 +553,13 @@ mt7925_mcu_rssi_monitor_event(struct mt792x_dev *dev, struct sk_buff *skb) tlv = (struct tlv *)skb->data; tlv_len = skb->len; -while (tlv_len >0 &&le16_to_cpu (tlv->len) <= tlv_len) { +mt7925_for_each_tlv (tlv, tlv_len) {switch (le16_to_cpu (tlv->tag)) {case UNI_EVENT_RSSI_MONITOR_INFO : - event = (struct mt7925_uni_rssi_monitor_event *)skb->data; +if (le16_to_cpu (tlv->len) <sizeof (*event)) +break ; + + event = (struct mt7925_uni_rssi_monitor_event *)tlv; ieee80211_iterate_active_interfaces_atomic(dev->mt76.hw, IEEE80211_IFACE_ITER_RESUME_ALL, mt7925_mcu_rssi_monitor_iter,
@@ -560,8 +568,6 @@ mt7925_mcu_rssi_monitor_event(struct mt792x_dev *dev, struct sk_buff *skb)default :break ; } - tlv_len -=le16_to_cpu (tlv->len); - tlv = (struct tlv *)((char *)(tlv) +le16_to_cpu (tlv->len)); } }
drivers/net/wireless/mediatek/mt76/mt7925/mcu.h +19 -0
@@ -699,6 +699,25 @@ mt7925_mcu_get_cipher(int cipher) } } +static inline bool +mt7925_mcu_tlv_valid (struct tlv *tlv,u32 rem) +{ +u16 len; + +if (rem <sizeof (*tlv)) +return false; + + len =le16_to_cpu (tlv->len); + +/* a length below the header size would not advance the cursor */ +return len >=sizeof (*tlv) && len <= rem; +} + +#define mt7925_for_each_tlv (tlv, rem) \ + for (; mt7925_mcu_tlv_valid(tlv, rem); \ + (rem) -= le16_to_cpu((tlv)->len), \ + (tlv) = (struct tlv *)((u8 *)(tlv) + le16_to_cpu((tlv)->len))) +int mt7925_mcu_set_dbdc (struct mt76_phy *phy,bool enable);int mt7925_mcu_hw_scan (struct mt76_phy *phy,struct ieee80211_vif *vif,struct ieee80211_scan_request *scan_req);
Signature · 1 line
2.53.0