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

* [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
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

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

* Re: [PATCH] mt76: mt7921: introduce PCIe ASPM support (L0s/L1/L1ss)
  2021-06-12  2:59 ` Deren Wu
  (?)
@ 2021-06-16 11:53 ` kernel test robot
  -1 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2021-06-16 11:53 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 2161 bytes --]

Hi Deren,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on wireless-drivers-next/master]
[also build test WARNING on wireless-drivers/master v5.13-rc6 next-20210615]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Deren-Wu/mt76-mt7921-introduce-PCIe-ASPM-support-L0s-L1-L1ss/20210616-142942
base:   https://git.kernel.org/pub/scm/linux/kernel/git/kvalo/wireless-drivers-next.git master
config: arc-allyesconfig (attached as .config)
compiler: arceb-elf-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/ed4b68aa3d20be1f8b2bfa305e1cba6f0fac0ef7
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Deren-Wu/mt76-mt7921-introduce-PCIe-ASPM-support-L0s-L1-L1ss/20210616-142942
        git checkout ed4b68aa3d20be1f8b2bfa305e1cba6f0fac0ef7
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arc 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> drivers/net/wireless/mediatek/mt76/mt7921/pci.c:151:6: warning: no previous prototype for 'mt7921_pci_enable_aspm' [-Wmissing-prototypes]
     151 | void mt7921_pci_enable_aspm(struct pci_dev *pdev)
         |      ^~~~~~~~~~~~~~~~~~~~~~


vim +/mt7921_pci_enable_aspm +151 drivers/net/wireless/mediatek/mt76/mt7921/pci.c

   150	
 > 151	void mt7921_pci_enable_aspm(struct pci_dev *pdev)
   152	{
   153		mt7921_pci_config_L1ss(pdev, true);
   154		mt7921_pci_config_L1(pdev, true);
   155	}
   156	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 68109 bytes --]

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

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


On 2021-06-12 04:59, Deren Wu wrote:
> 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>
This seems to be duplicating functionality from drivers/pci/pcie/aspm.c
I think the driver shouldn't need to touch this, maybe it is enough to
remove the mt76_pci_disable_aspm call and enable ASPM in the kernel config?

- Felix

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

* Re: [PATCH] mt76: mt7921: introduce PCIe ASPM support (L0s/L1/L1ss)
@ 2021-06-18 16:01   ` Felix Fietkau
  0 siblings, 0 replies; 5+ messages in thread
From: Felix Fietkau @ 2021-06-18 16:01 UTC (permalink / raw)
  To: Deren Wu, Lorenzo Bianconi
  Cc: Sean Wang, Soul Huang, YN Chen, Leon Yen, Eric-SY Chang, KM Lin,
	Robin Chiu, CH Yeh, Posh Sun, Eric Liang, Stella Chang, jemele,
	yenlinlai, linux-wireless, linux-mediatek


On 2021-06-12 04:59, Deren Wu wrote:
> 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>
This seems to be duplicating functionality from drivers/pci/pcie/aspm.c
I think the driver shouldn't need to touch this, maybe it is enough to
remove the mt76_pci_disable_aspm call and enable ASPM in the kernel config?

- Felix

_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

^ permalink raw reply	[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.