Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Kai-Heng Feng <kai.heng.feng@canonical.com>
To: hkallweit1@gmail.com, nic_swsd@realtek.com
Cc: Kai-Heng Feng <kai.heng.feng@canonical.com>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	netdev@vger.kernel.org (open list:8169 10/100/1000 GIGABIT
	ETHERNET DRIVER), linux-kernel@vger.kernel.org (open list)
Subject: [PATCH 2/2] r8169: Enable ASPM for selected NICs
Date: Tue,  3 Aug 2021 23:28:23 +0800	[thread overview]
Message-ID: <20210803152823.515849-2-kai.heng.feng@canonical.com> (raw)
In-Reply-To: <20210803152823.515849-1-kai.heng.feng@canonical.com>

The latest vendor driver enables ASPM for more recent r8168 NICs, do the
same here to match the behavior.

In addition, pci_disable_link_state() is only used for RTL8168D/8111D in
vendor driver, also match that.

Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
---
 drivers/net/ethernet/realtek/r8169_main.c | 34 +++++++++++++++++------
 1 file changed, 26 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c
index e257d3cd885e..ec09c13514bd 100644
--- a/drivers/net/ethernet/realtek/r8169_main.c
+++ b/drivers/net/ethernet/realtek/r8169_main.c
@@ -623,7 +623,7 @@ struct rtl8169_private {
 	} wk;
 
 	unsigned supports_gmii:1;
-	unsigned aspm_manageable:1;
+	unsigned aspm_supported:1;
 	unsigned aspm_enabled:1;
 	struct timer_list aspm_timer;
 	u32 aspm_packet_count;
@@ -2666,8 +2666,11 @@ static void rtl_pcie_state_l2l3_disable(struct rtl8169_private *tp)
 
 static void rtl_hw_aspm_clkreq_enable(struct rtl8169_private *tp, bool enable)
 {
+	if (!tp->aspm_supported)
+		return;
+
 	/* Don't enable ASPM in the chip if OS can't control ASPM */
-	if (enable && tp->aspm_manageable) {
+	if (enable) {
 		RTL_W8(tp, Config5, RTL_R8(tp, Config5) | ASPM_en);
 		RTL_W8(tp, Config2, RTL_R8(tp, Config2) | ClkReqEn);
 	} else {
@@ -5279,6 +5282,21 @@ static void rtl_init_mac_address(struct rtl8169_private *tp)
 	rtl_rar_set(tp, mac_addr);
 }
 
+static int rtl_hw_aspm_supported(struct rtl8169_private *tp)
+{
+	switch (tp->mac_version) {
+	case RTL_GIGA_MAC_VER_32 ... RTL_GIGA_MAC_VER_36:
+	case RTL_GIGA_MAC_VER_38:
+	case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_42:
+	case RTL_GIGA_MAC_VER_44 ... RTL_GIGA_MAC_VER_46:
+	case RTL_GIGA_MAC_VER_49 ... RTL_GIGA_MAC_VER_63:
+		return 1;
+
+	default:
+		return 0;
+	}
+}
+
 static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
 	struct rtl8169_private *tp;
@@ -5310,12 +5328,12 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	if (rc)
 		return rc;
 
-	/* Disable ASPM completely as that cause random device stop working
-	 * problems as well as full system hangs for some PCIe devices users.
-	 */
-	rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S |
-					  PCIE_LINK_STATE_L1);
-	tp->aspm_manageable = !rc;
+	if (tp->mac_version == RTL_GIGA_MAC_VER_25)
+		pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S |
+				       PCIE_LINK_STATE_L1 |
+				       PCIE_LINK_STATE_CLKPM);
+
+	tp->aspm_supported = rtl_hw_aspm_supported(tp);
 
 	/* enable device (incl. PCI PM wakeup and hotplug setup) */
 	rc = pcim_enable_device(pdev);
-- 
2.31.1


  reply	other threads:[~2021-08-03 15:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-03 15:28 [PATCH 1/2] r8169: Implement dynamic ASPM mechanism Kai-Heng Feng
2021-08-03 15:28 ` Kai-Heng Feng [this message]
2021-08-03 19:57 ` Heiner Kallweit
2021-08-04  4:05   ` Kai-Heng Feng
2021-08-06 18:47 ` Heiner Kallweit
2021-08-09 11:18   ` Kai-Heng Feng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210803152823.515849-2-kai.heng.feng@canonical.com \
    --to=kai.heng.feng@canonical.com \
    --cc=davem@davemloft.net \
    --cc=hkallweit1@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=nic_swsd@realtek.com \
    --subject='Re: [PATCH 2/2] r8169: Enable ASPM for selected NICs' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).