All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mt76: mt7921: introduce PCIe ASPM support (L0s/L1/L1ss)
@ 2021-06-12  2:59 ` Deren Wu
  0 siblings, 0 replies; 5+ messages in thread
From: Deren Wu @ 2021-06-12  2:59 UTC (permalink / raw)
  To: Felix Fietkau, Lorenzo Bianconi
  Cc: Sean Wang, Soul Huang, YN Chen, Leon Yen, Eric-SY Chang,
	Deren Wu, KM Lin, Robin Chiu, CH Yeh, Posh Sun, Eric Liang,
	Stella Chang, jemele, yenlinlai, linux-wireless, linux-mediatek,
	Deren Wu

From: Deren Wu <deren.wu@mediatek.com>

for better power consumption, default enable PCIe ASPM

Tested-by: Leon Yen <Leon.Yen@mediatek.com>
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
---
 .../net/wireless/mediatek/mt76/mt7921/pci.c   | 68 ++++++++++++++++++-
 1 file changed, 67 insertions(+), 1 deletion(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/pci.c b/drivers/net/wireless/mediatek/mt76/mt7921/pci.c
index 13263f50dc00..5358836bb00e 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7921/pci.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7921/pci.c
@@ -88,6 +88,72 @@ static void mt7921_irq_tasklet(unsigned long data)
 		napi_schedule(&dev->mt76.napi[MT_RXQ_MAIN]);
 }
 
+static void mt7921_pci_config_L1(struct pci_dev *pdev, u8 enable)
+{
+	u32 reg32;
+	int pos;
+
+	if (!pdev)
+		return;
+
+	/* capability check */
+	pos = pdev->pcie_cap;
+	pci_read_config_dword(pdev, pos + PCI_EXP_LNKCAP, &reg32);
+	if (!(reg32 & PCI_EXP_LNKCAP_ASPMS)) {
+		dev_info(&pdev->dev, "ASPM L1: Invalid cap 0x%X\n", reg32);
+		return;
+	}
+
+	/* set config */
+	pci_read_config_dword(pdev, pos + PCI_EXP_LNKCTL, &reg32);
+	if (enable)
+		reg32 |= (PCI_EXP_LNKCTL_ASPMC);
+	else
+		reg32 &= ~(PCI_EXP_LNKCTL_ASPMC);
+	dev_dbg(&pdev->dev, "%s ASPM L1\n", (enable) ? "enable" : "disable");
+
+	pci_write_config_dword(pdev, pos + PCI_EXP_LNKCTL, reg32);
+}
+
+static void mt7921_pci_config_L1ss(struct pci_dev *pdev, u8 enable)
+{
+#define  PCIE_L1SS_CAP_CHK \
+		(PCI_L1SS_CAP_ASPM_L1_1 | PCI_L1SS_CAP_ASPM_L1_2)
+#define  PCIE_L1SS_CTL_CHK \
+		(PCI_L1SS_CTL1_ASPM_L1_1 | PCI_L1SS_CTL1_ASPM_L1_2)
+
+	int pos;
+	u32 reg32;
+
+	if (!pdev)
+		return;
+
+	/* capability check */
+	pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_L1SS);
+	pci_read_config_dword(pdev, pos + PCI_L1SS_CAP, &reg32);
+	if (!(reg32 & (PCIE_L1SS_CAP_CHK))) {
+		dev_info(&pdev->dev, "ASPM L1SS: Invalid cap 0x%X\n", reg32);
+		return;
+	}
+
+	/* set config */
+	pci_read_config_dword(pdev, pos + PCI_L1SS_CTL1, &reg32);
+	if (enable)
+		reg32 |= (PCIE_L1SS_CTL_CHK);
+	else
+		reg32 &= ~(PCIE_L1SS_CTL_CHK);
+
+	dev_dbg(&pdev->dev, "%s ASPM L1SS\n", (enable) ? "enable" : "disable");
+
+	pci_write_config_dword(pdev, pos + PCI_L1SS_CTL1, reg32);
+}
+
+void mt7921_pci_enable_aspm(struct pci_dev *pdev)
+{
+	mt7921_pci_config_L1ss(pdev, true);
+	mt7921_pci_config_L1(pdev, true);
+}
+
 static int mt7921_pci_probe(struct pci_dev *pdev,
 			    const struct pci_device_id *id)
 {
@@ -131,7 +197,7 @@ static int mt7921_pci_probe(struct pci_dev *pdev,
 	if (ret)
 		goto err_free_pci_vec;
 
-	mt76_pci_disable_aspm(pdev);
+	mt7921_pci_enable_aspm(pdev);
 
 	mdev = mt76_alloc_device(&pdev->dev, sizeof(*dev), &mt7921_ops,
 				 &drv_ops);
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-06-18 16:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-12  2:59 [PATCH] mt76: mt7921: introduce PCIe ASPM support (L0s/L1/L1ss) Deren Wu
2021-06-12  2:59 ` Deren Wu
2021-06-16 11:53 ` kernel test robot
2021-06-18 16:01 ` Felix Fietkau
2021-06-18 16:01   ` Felix Fietkau

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.