Some hardware platforms use ACPI MTFG table denoting the existence of noise that impacts Wi-Fi performance. This patch reads the ACPI SAR info and notifies FW to detect current status and to adjust PCIe bus to mitigate the noise. Signed-off-by: Anthony Liu --- .../net/wireless/mediatek/mt76/mt7921/init.c | 5 ++++ .../wireless/mediatek/mt76/mt7921/pci_mac.c | 6 ++++ .../net/wireless/mediatek/mt76/mt7925/init.c | 2 ++ .../wireless/mediatek/mt76/mt7925/pci_mac.c | 6 ++++ drivers/net/wireless/mediatek/mt76/mt792x.h | 4 +++ .../net/wireless/mediatek/mt76/mt792x_core.c | 28 +++++++++++++++++++ 6 files changed, 51 insertions(+) diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/init.c b/drivers/net/wireless/mediatek/mt76/mt7921/init.c index a87ebcff547b..8059405f2d5c 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/init.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/init.c @@ -102,6 +102,11 @@ static int __mt7921_init_hardware(struct mt792x_dev *dev) goto out; ret = mt7921_mac_init(dev); + if (ret) + goto out; + + if (is_mt7922(&dev->mt76)) + ret = mt792x_mcu_set_dyn_pcie_gen(dev); out: return ret; } diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/pci_mac.c b/drivers/net/wireless/mediatek/mt76/mt7921/pci_mac.c index d5c33a0d409c..6d8e221eb83f 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/pci_mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/pci_mac.c @@ -118,6 +118,12 @@ int mt7921e_mac_reset(struct mt792x_dev *dev) if (err) goto out; + if (is_mt7922(&dev->mt76)) { + err = mt792x_mcu_set_dyn_pcie_gen(dev); + if (err) + goto out; + } + err = __mt7921_start(&dev->phy); out: diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/init.c b/drivers/net/wireless/mediatek/mt76/mt7925/init.c index ad51f71babd7..b8d629f9bbe5 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/init.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/init.c @@ -126,6 +126,8 @@ static int __mt7925_init_hardware(struct mt792x_dev *dev) } } + if (is_mt7928(&dev->mt76)) + ret = mt792x_mcu_set_dyn_pcie_gen(dev); out: return ret; } diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/pci_mac.c b/drivers/net/wireless/mediatek/mt76/mt7925/pci_mac.c index 6189615d6604..85da7645c8e2 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7925/pci_mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt7925/pci_mac.c @@ -202,6 +202,12 @@ int mt7925e_mac_reset(struct mt792x_dev *dev) goto out; } + if (is_mt7928(&dev->mt76)) { + err = mt792x_mcu_set_dyn_pcie_gen(dev); + if (err) + goto out; + } + err = __mt7925_start(&dev->phy); out: clear_bit(MT76_RESET, &dev->mphy.state); diff --git a/drivers/net/wireless/mediatek/mt76/mt792x.h b/drivers/net/wireless/mediatek/mt76/mt792x.h index 79f57736db35..cdaf07725598 100644 --- a/drivers/net/wireless/mediatek/mt76/mt792x.h +++ b/drivers/net/wireless/mediatek/mt76/mt792x.h @@ -670,6 +670,7 @@ void mt792x_mac_link_bss_remove(struct mt792x_dev *dev, struct mt792x_link_sta *mlink); void mt792x_config_mac_addr_list(struct mt792x_dev *dev); int mt792x_mcu_chip_config(struct mt792x_dev *dev, const char *cmd); +int mt792x_mcu_set_dyn_pcie_gen(struct mt792x_dev *dev); static inline char *mt792x_ram_name(struct mt792x_dev *dev) { @@ -768,6 +769,9 @@ int __mt792xe_mcu_drv_pmctrl(struct mt792x_dev *dev); int mt792xe_mcu_drv_pmctrl(struct mt792x_dev *dev); int mt792xe_mcu_fw_pmctrl(struct mt792x_dev *dev); +#define MT792X_ACPI_FLAG_VALID BIT(0) /* ACPI SAR is valid */ +#define MT792X_ACPI_FLAG_PCIe BIT(3) /* Valid only when valid is set */ + #ifdef CONFIG_ACPI int mt792x_init_acpi_sar(struct mt792x_dev *dev); int mt792x_init_acpi_sar_power(struct mt792x_phy *phy, bool set_default); diff --git a/drivers/net/wireless/mediatek/mt76/mt792x_core.c b/drivers/net/wireless/mediatek/mt76/mt792x_core.c index a59aedd498b2..25408fcc8af3 100644 --- a/drivers/net/wireless/mediatek/mt76/mt792x_core.c +++ b/drivers/net/wireless/mediatek/mt76/mt792x_core.c @@ -1251,6 +1251,34 @@ int mt792x_mcu_chip_config(struct mt792x_dev *dev, const char *cmd) } EXPORT_SYMBOL_GPL(mt792x_mcu_chip_config); +int mt792x_mcu_set_dyn_pcie_gen(struct mt792x_dev *dev) +{ + u8 acpi_conf = mt792x_acpi_get_flags(&dev->phy); + char cmd[64]; + int ret = 0; + + if (!(acpi_conf & MT792X_ACPI_FLAG_VALID) || + !(acpi_conf & MT792X_ACPI_FLAG_PCIe)) + return 0; + + strscpy(cmd, "PcieGenSwitch 1 1200 0 -60"); + ret = mt792x_mcu_chip_config(dev, cmd); + if (ret) + return ret; + + strscpy(cmd, "PcieGenSwitchAGGen2 0"); + ret = mt792x_mcu_chip_config(dev, cmd); + if (ret) + return ret; + + if (!dev->mphy.cap.has_6ghz) + return 0; + + strscpy(cmd, "PcieGenSwitch6G 1"); + return mt792x_mcu_chip_config(dev, cmd); +} +EXPORT_SYMBOL_GPL(mt792x_mcu_set_dyn_pcie_gen); + MODULE_DESCRIPTION("MediaTek MT792x core driver"); MODULE_LICENSE("Dual BSD/GPL"); MODULE_AUTHOR("Lorenzo Bianconi "); -- 2.45.2