From patchwork Tue Feb 21 02:38:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kai-Heng Feng X-Patchwork-Id: 13147272 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE275C636D6 for ; Tue, 21 Feb 2023 02:40:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233067AbjBUCkC (ORCPT ); Mon, 20 Feb 2023 21:40:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233070AbjBUCjs (ORCPT ); Mon, 20 Feb 2023 21:39:48 -0500 Received: from smtp-relay-canonical-0.canonical.com (smtp-relay-canonical-0.canonical.com [185.125.188.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45999234F4; Mon, 20 Feb 2023 18:39:47 -0800 (PST) Received: from localhost.localdomain (unknown [10.101.196.174]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-0.canonical.com (Postfix) with ESMTPSA id 1F82B406AF; Tue, 21 Feb 2023 02:39:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1676947185; bh=jXActFRB2e7tUmIdxW8pUWDAQLwCu7muuixpsDg2eGI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=e4Ciw8nS8VyWd/Hlq1uY4k0iXL6mawE03a+E7f+uHpGRMxjqcMUZB4A2TCKWs9Rgv 3mQ5xstI8CQbAyu3J53uPXgjTv1xyWdq+tLJiQxHnUL3ZOvknwFS5yii+ppZSL2UQ7 T/dmABd3kAYjP5h+djhbeWZNeUmezY/sju4eS3/Q8eFsFNAJWQqIzbGa/6GaglRup7 U9AZU+YVjrxUkije1FIJBHSBbjxSvCPzlf3v4O4D82Yd+2r8rCexOGoMKJQM5X1L1W g8ZkXRFEOK8KbqJK0bqlYEAEeg/ntBSkZzvf3zZpa6Rn8Pze0i6m8rxbk26cNb+NIv XlDlvgJknCSXw== From: Kai-Heng Feng To: hkallweit1@gmail.com, nic_swsd@realtek.com, bhelgaas@google.com Cc: koba.ko@canonical.com, acelan.kao@canonical.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, sathyanarayanan.kuppuswamy@linux.intel.com, vidyas@nvidia.com, rafael.j.wysocki@intel.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Kai-Heng Feng Subject: [PATCH v8 RESEND 1/6] r8169: Disable ASPM L1.1 on 8168h Date: Tue, 21 Feb 2023 10:38:44 +0800 Message-Id: <20230221023849.1906728-2-kai.heng.feng@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230221023849.1906728-1-kai.heng.feng@canonical.com> References: <20230221023849.1906728-1-kai.heng.feng@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org ASPM L1/L1.1 gets enabled based on [0], but ASPM L1.1 was actually disabled too [1]. So also disable L1.1 for better compatibility. [0] https://bugs.launchpad.net/bugs/1942830 [1] https://git.launchpad.net/~canonical-kernel/ubuntu/+source/linux-oem/+git/focal/commit/?id=c9b3736de48fd419d6699045d59a0dd1041da014 Signed-off-by: Kai-Heng Feng --- v8: - New patch. drivers/net/ethernet/realtek/r8169_main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c index 45147a1016bec..1c949822661ae 100644 --- a/drivers/net/ethernet/realtek/r8169_main.c +++ b/drivers/net/ethernet/realtek/r8169_main.c @@ -5224,13 +5224,13 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) /* Disable ASPM L1 as that cause random device stop working * problems as well as full system hangs for some PCIe devices users. - * Chips from RTL8168h partially have issues with L1.2, but seem - * to work fine with L1 and L1.1. + * Chips from RTL8168h partially have issues with L1.1 and L1.2, but + * seem to work fine with L1. */ if (rtl_aspm_is_safe(tp)) rc = 0; else if (tp->mac_version >= RTL_GIGA_MAC_VER_46) - rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1_2); + rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1_1 | PCIE_LINK_STATE_L1_2); else rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1); tp->aspm_manageable = !rc; From patchwork Tue Feb 21 02:38:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kai-Heng Feng X-Patchwork-Id: 13147273 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F86BC64EC4 for ; Tue, 21 Feb 2023 02:40:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233075AbjBUCkD (ORCPT ); Mon, 20 Feb 2023 21:40:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233149AbjBUCj7 (ORCPT ); Mon, 20 Feb 2023 21:39:59 -0500 Received: from smtp-relay-canonical-0.canonical.com (smtp-relay-canonical-0.canonical.com [185.125.188.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84B82448B; Mon, 20 Feb 2023 18:39:53 -0800 (PST) Received: from localhost.localdomain (unknown [10.101.196.174]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-0.canonical.com (Postfix) with ESMTPSA id 0CBC13F158; Tue, 21 Feb 2023 02:39:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1676947192; bh=bhjZxuXkm1MHeyPMkpuHBbBuF0eWs3dLUcdK/gbm22M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=sVFwdem5XR4yjnDTanXqgcRjFp2ZadRa79H4Q+MNB5HJuL8btJR+ijuo+BQQu7o78 XWyqtV/FFaNkfXy7Ll3dLUxya5cby2SvtvP3I4XhXL3N2HPTibaRlHB3IjbMjjjhfW 4baW2zpyGyiR0rjJ6E9Fiyntnk1p2g2NAqWZTWDFycwaIXYQlgGhCYvo5jWLOb1o3F Q95vOlWJCiEsivCT2pflGFq9T0m8Bitx7fQ3ND6VDlMEmuGUWDQWP78GHYBoZM3vR/ LjhFV8tiDPbIfYbbvWP+a3VARgT17TdN8jD7NDBS2usVRBMaqQSuNbLBQCf290k99K 3Pfg0plbiPF7g== From: Kai-Heng Feng To: hkallweit1@gmail.com, nic_swsd@realtek.com, bhelgaas@google.com Cc: koba.ko@canonical.com, acelan.kao@canonical.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, sathyanarayanan.kuppuswamy@linux.intel.com, vidyas@nvidia.com, rafael.j.wysocki@intel.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Kai-Heng Feng Subject: [PATCH v8 RESEND 2/6] Revert "PCI/ASPM: Unexport pcie_aspm_support_enabled()" Date: Tue, 21 Feb 2023 10:38:45 +0800 Message-Id: <20230221023849.1906728-3-kai.heng.feng@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230221023849.1906728-1-kai.heng.feng@canonical.com> References: <20230221023849.1906728-1-kai.heng.feng@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org This reverts commit ba13d4575da5e656a3cbc18583e0da5c5d865417. This will be used by module once again. Signed-off-by: Kai-Heng Feng --- v8: - New patch. drivers/pci/pcie/aspm.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c index 4b4184563a927..692d6953f0970 100644 --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -1372,3 +1372,4 @@ bool pcie_aspm_support_enabled(void) { return aspm_support_enabled; } +EXPORT_SYMBOL(pcie_aspm_support_enabled); From patchwork Tue Feb 21 02:38:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kai-Heng Feng X-Patchwork-Id: 13147274 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24F79C61DA3 for ; Tue, 21 Feb 2023 02:40:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233080AbjBUCkT (ORCPT ); Mon, 20 Feb 2023 21:40:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232289AbjBUCkM (ORCPT ); Mon, 20 Feb 2023 21:40:12 -0500 Received: from smtp-relay-canonical-0.canonical.com (smtp-relay-canonical-0.canonical.com [185.125.188.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6517240F4; Mon, 20 Feb 2023 18:40:00 -0800 (PST) Received: from localhost.localdomain (unknown [10.101.196.174]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-0.canonical.com (Postfix) with ESMTPSA id C67E7406AF; Tue, 21 Feb 2023 02:39:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1676947199; bh=VxzDHiK0+rolY+k286CzRqUyRlnpqBJ10GA9uRWnSf0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hJtKPpRUjQjpQL+im8FJ++7VhAxYbIXvhGnHYZfQ+s9G2wcbMnGxDXnNoUy+ysGV+ vYCiaUt0Gzy/IsOlFKOEOX61y3gA/A3JfMg8/imRJ6BUS1hY+jPr68RoueAdzOzd3/ psYEFmoMMp1uTKCn0fgCREn3zMIAQVowh60oAv7OPqvQSC64ocVTuCTLmALWyM6lv9 qaCJ/owyAftRbJhWyzGQ+3qsT7WgVate4fex7uQhsbDZY31xToZRXlctl5uBbAnf03 wsfR/CiMXtNBGesIFNfOAqBJndilIkVZUEip9yuqfmyvH51PtoTA7biyhOzW+a6RDT ACdC2rGw2QdPQ== From: Kai-Heng Feng To: hkallweit1@gmail.com, nic_swsd@realtek.com, bhelgaas@google.com Cc: koba.ko@canonical.com, acelan.kao@canonical.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, sathyanarayanan.kuppuswamy@linux.intel.com, vidyas@nvidia.com, rafael.j.wysocki@intel.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Kai-Heng Feng Subject: [PATCH v8 RESEND 3/6] PCI/ASPM: Add pcie_aspm_capable() helper Date: Tue, 21 Feb 2023 10:38:46 +0800 Message-Id: <20230221023849.1906728-4-kai.heng.feng@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230221023849.1906728-1-kai.heng.feng@canonical.com> References: <20230221023849.1906728-1-kai.heng.feng@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Introduce a new helper, pcie_aspm_capable(), to report ASPM capability. The user will be introduced by next patch. Acked-by: Bjorn Helgaas Suggested-by: Bjorn Helgaas Signed-off-by: Kai-Heng Feng --- v8: - No change. v7: - Change subject. v6: - No change. v5: - No change. v4: - Report aspm_capable instead. v3: - This is a new patch drivers/pci/pcie/aspm.c | 11 +++++++++++ include/linux/pci.h | 2 ++ 2 files changed, 13 insertions(+) diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c index 692d6953f0970..d96bf0a362aa2 100644 --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -1199,6 +1199,17 @@ bool pcie_aspm_enabled(struct pci_dev *pdev) } EXPORT_SYMBOL_GPL(pcie_aspm_enabled); +bool pcie_aspm_capable(struct pci_dev *pdev) +{ + struct pcie_link_state *link = pcie_aspm_get_link(pdev); + + if (!link) + return false; + + return link->aspm_capable; +} +EXPORT_SYMBOL_GPL(pcie_aspm_capable); + static ssize_t aspm_attr_show_common(struct device *dev, struct device_attribute *attr, char *buf, u8 state) diff --git a/include/linux/pci.h b/include/linux/pci.h index adffd65e84b4e..fd56872883e14 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1692,6 +1692,7 @@ int pci_disable_link_state_locked(struct pci_dev *pdev, int state); void pcie_no_aspm(void); bool pcie_aspm_support_enabled(void); bool pcie_aspm_enabled(struct pci_dev *pdev); +bool pcie_aspm_capable(struct pci_dev *pdev); #else static inline int pci_disable_link_state(struct pci_dev *pdev, int state) { return 0; } @@ -1700,6 +1701,7 @@ static inline int pci_disable_link_state_locked(struct pci_dev *pdev, int state) static inline void pcie_no_aspm(void) { } static inline bool pcie_aspm_support_enabled(void) { return false; } static inline bool pcie_aspm_enabled(struct pci_dev *pdev) { return false; } +static inline bool pcie_aspm_capable(struct pci_dev *pdev) { return false; } #endif #ifdef CONFIG_PCIEAER From patchwork Tue Feb 21 02:38:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kai-Heng Feng X-Patchwork-Id: 13147275 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9308FC636D6 for ; Tue, 21 Feb 2023 02:40:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233110AbjBUCkW (ORCPT ); Mon, 20 Feb 2023 21:40:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233132AbjBUCkT (ORCPT ); Mon, 20 Feb 2023 21:40:19 -0500 Received: from smtp-relay-canonical-0.canonical.com (smtp-relay-canonical-0.canonical.com [185.125.188.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45E1E2366F; Mon, 20 Feb 2023 18:40:06 -0800 (PST) Received: from localhost.localdomain (unknown [10.101.196.174]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-0.canonical.com (Postfix) with ESMTPSA id E0B313F158; Tue, 21 Feb 2023 02:39:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1676947204; bh=pNqvuelCqk4rJCSN7tzVgxEDAb98YmVWBtwNCRfo4Z4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MwBE1XbJiP9QiFG4cII20s/diEPXbwaB7gsgsu+UAmZvNnvs91uPrPygCCwNxU0bL ZPix4E3Shilh7Har52hC6wziquvj2bgg7Gg31P5Vxi6O/XputkUIPujcnZZN+pUqGy 4Pi+uNKUdRUf0ACaziyc4RcHBGtefCBh2ifWCFoSnbnVSys1UJUtVudQKYExPBi4nU N3PvQe93TZAVWjPfkJfygfad/vB4SoX0IWG/YWBF96pvfZHGkUMMXnUiMX1NVTRTfQ TP1VGq/1IzBYWQR7uQRbMwS42IyiEEBdFDDv/zK2s7J8V2TGfYQJjbV+NvgvTgAzHy a8Uk9iUKnVPBg== From: Kai-Heng Feng To: hkallweit1@gmail.com, nic_swsd@realtek.com, bhelgaas@google.com Cc: koba.ko@canonical.com, acelan.kao@canonical.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, sathyanarayanan.kuppuswamy@linux.intel.com, vidyas@nvidia.com, rafael.j.wysocki@intel.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Kai-Heng Feng Subject: [PATCH v8 RESEND 4/6] r8169: Consider chip-specific ASPM can be enabled on more cases Date: Tue, 21 Feb 2023 10:38:47 +0800 Message-Id: <20230221023849.1906728-5-kai.heng.feng@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230221023849.1906728-1-kai.heng.feng@canonical.com> References: <20230221023849.1906728-1-kai.heng.feng@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org To really enable ASPM on r8169 NICs, both standard PCIe ASPM and chip-specific ASPM have to be enabled at the same time. Before enabling ASPM at chip side, make sure the following conditions are met: 1) Use pcie_aspm_support_enabled() to check if ASPM is disabled by kernel parameter. 2) Use pcie_aspm_capable() to see if the device is capable to perform PCIe ASPM. 3) Check the return value of pci_disable_link_state(). If it's -EPERM, it means BIOS doesn't grant ASPM control to OS, and device should use the ASPM setting as is Consider ASPM is manageable when those conditions are met. While at it, disable ASPM at chip-side for TX timeout reset, since pci_disable_link_state() doesn't have any effect when OS isn't granted with ASPM control. Signed-off-by: Kai-Heng Feng --- v8: - Enable chip-side ASPM only when PCIe ASPM is already available. - Wording. v7: - No change. v6: - Unconditionally enable chip-specific ASPM. v5: - New patch. drivers/net/ethernet/realtek/r8169_main.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c index 1c949822661ae..e40498dd08d17 100644 --- a/drivers/net/ethernet/realtek/r8169_main.c +++ b/drivers/net/ethernet/realtek/r8169_main.c @@ -2675,8 +2675,11 @@ static void rtl_disable_exit_l1(struct rtl8169_private *tp) static void rtl_hw_aspm_clkreq_enable(struct rtl8169_private *tp, bool enable) { - /* Don't enable ASPM in the chip if OS can't control ASPM */ - if (enable && tp->aspm_manageable) { + /* Skip if PCIe ASPM isn't possible */ + if (!tp->aspm_manageable) + return; + + if (enable) { RTL_W8(tp, Config5, RTL_R8(tp, Config5) | ASPM_en); RTL_W8(tp, Config2, RTL_R8(tp, Config2) | ClkReqEn); @@ -4545,8 +4548,13 @@ static void rtl_task(struct work_struct *work) /* ASPM compatibility issues are a typical reason for tx timeouts */ ret = pci_disable_link_state(tp->pci_dev, PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_L0S); + + /* OS may not be granted to control PCIe ASPM, prevent the driver from using it */ + tp->aspm_manageable = 0; + if (!ret) netdev_warn_once(tp->dev, "ASPM disabled on Tx timeout\n"); + goto reset; } @@ -5227,13 +5235,19 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) * Chips from RTL8168h partially have issues with L1.1 and L1.2, but * seem to work fine with L1. */ - if (rtl_aspm_is_safe(tp)) + if (!pcie_aspm_support_enabled() || !pcie_aspm_capable(pdev)) + rc = -EINVAL; + else if (rtl_aspm_is_safe(tp)) rc = 0; else if (tp->mac_version >= RTL_GIGA_MAC_VER_46) rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1_1 | PCIE_LINK_STATE_L1_2); else rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1); - tp->aspm_manageable = !rc; + + /* -EPERM means BIOS doesn't grant OS ASPM control, ASPM should be use + * as is. Honor it. + */ + tp->aspm_manageable = (rc == -EPERM) ? 1 : !rc; tp->dash_type = rtl_check_dash(tp); From patchwork Tue Feb 21 02:38:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kai-Heng Feng X-Patchwork-Id: 13147276 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6E97DC636D6 for ; Tue, 21 Feb 2023 02:40:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233125AbjBUCkl (ORCPT ); Mon, 20 Feb 2023 21:40:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233134AbjBUCk3 (ORCPT ); Mon, 20 Feb 2023 21:40:29 -0500 Received: from smtp-relay-canonical-0.canonical.com (smtp-relay-canonical-0.canonical.com [185.125.188.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D3A323671; Mon, 20 Feb 2023 18:40:12 -0800 (PST) Received: from localhost.localdomain (unknown [10.101.196.174]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-0.canonical.com (Postfix) with ESMTPSA id 9232F3F2FE; Tue, 21 Feb 2023 02:40:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1676947210; bh=ezbPlxDXhaV/sDJAItoixMIy3dMW2xrI6AAH/J1Y45I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ETctbcQNZLeQqgunhUqAiRSQAKR3iGoZpdxkpmEZjAHKoOakaT7ya1hEzA2o0NASo dYyNakLLya0F3VYLRyHMoJeuijhEdN1oxOlgwP3WZcRYU2lMK7M6pt6sAMoVvh6B+k uGbVNCPJ0LW9DwUtNFSszrq4/x23ZbY6QP+rD9Ri8nVGLrOuYj+dxnc/ubk3Yfi0av ACphm8gvbwhrEt6Xpc7VdLj6u8SLkKrO2a1Wv5s0YejhzmLg5C1WuaueFPtpoHnMk2 SpVszJOfpjtbMDukuMMcUiAloOXTmS2RM3RnqIVuEWnlUPjdCzhtNTb+LIA6imIxwW t5L8kQJCAztVQ== From: Kai-Heng Feng To: hkallweit1@gmail.com, nic_swsd@realtek.com, bhelgaas@google.com Cc: koba.ko@canonical.com, acelan.kao@canonical.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, sathyanarayanan.kuppuswamy@linux.intel.com, vidyas@nvidia.com, rafael.j.wysocki@intel.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Kai-Heng Feng Subject: [PATCH v8 RESEND 5/6] r8169: Use mutex to guard config register locking Date: Tue, 21 Feb 2023 10:38:48 +0800 Message-Id: <20230221023849.1906728-6-kai.heng.feng@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230221023849.1906728-1-kai.heng.feng@canonical.com> References: <20230221023849.1906728-1-kai.heng.feng@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Right now r8169 doesn't have parallel access to its config register, but the next patch makes the driver access config register at anytime. So add a mutex to protect the config register from any potential race. Signed-off-by: Kai-Heng Feng --- v8: - Swap the place when using the mutex. Protect when config register is unlocked. v7: - This is a new patch. drivers/net/ethernet/realtek/r8169_main.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c index e40498dd08d17..897f90b48bba6 100644 --- a/drivers/net/ethernet/realtek/r8169_main.c +++ b/drivers/net/ethernet/realtek/r8169_main.c @@ -613,6 +613,8 @@ struct rtl8169_private { struct work_struct work; } wk; + struct mutex config_lock; + unsigned supports_gmii:1; unsigned aspm_manageable:1; dma_addr_t counters_phys_addr; @@ -662,10 +664,12 @@ static inline struct device *tp_to_dev(struct rtl8169_private *tp) static void rtl_lock_config_regs(struct rtl8169_private *tp) { RTL_W8(tp, Cfg9346, Cfg9346_Lock); + mutex_unlock(&tp->config_lock); } static void rtl_unlock_config_regs(struct rtl8169_private *tp) { + mutex_lock(&tp->config_lock); RTL_W8(tp, Cfg9346, Cfg9346_Unlock); } @@ -5217,6 +5221,8 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) return rc; } + mutex_init(&tp->config_lock); + tp->mmio_addr = pcim_iomap_table(pdev)[region]; xid = (RTL_R32(tp, TxConfig) >> 20) & 0xfcf; From patchwork Tue Feb 21 02:38:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kai-Heng Feng X-Patchwork-Id: 13147277 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6F986C636D6 for ; Tue, 21 Feb 2023 02:40:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232005AbjBUCky (ORCPT ); Mon, 20 Feb 2023 21:40:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233127AbjBUCkr (ORCPT ); Mon, 20 Feb 2023 21:40:47 -0500 Received: from smtp-relay-canonical-0.canonical.com (smtp-relay-canonical-0.canonical.com [185.125.188.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CCEAE23669; Mon, 20 Feb 2023 18:40:17 -0800 (PST) Received: from localhost.localdomain (unknown [10.101.196.174]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-0.canonical.com (Postfix) with ESMTPSA id 3B5F2400DA; Tue, 21 Feb 2023 02:40:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1676947215; bh=Y882fDTAJIgU0c6v4mvBEAwTf+dckq3a6RQpDpIIC1Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=F7csYykfZy3BthhUwy2nS9QY4r8gF3p54jqSejU0psKN7oL0FF86NA4/9YDxPGnXm UzhznvkOoRHjx7zCuNGpzEh14Th+cKXvP0t7ZqsEwHDAvtjBdUtG4vZrLmbW6jwuSf 1UYQkGFLh2s/q3jnzztcGdYl8NHUTl57GjmRmoB9KHg7Q0ZlXRXjNnqxtV0ffJiTPQ i+4Yzw1Y3f4B0E5c0Yntk+80AAEngFYnW12VcGSgvn2ffnwqh/E7vMLp6RleXKUx4s g+EUQ8IkC6DUigxYMRH1ZdTRiX8SZTdg+zwxDObE32P1LTOz6GiRV66TbmzUjuc0fg WA6/e7c7zPGFA== From: Kai-Heng Feng To: hkallweit1@gmail.com, nic_swsd@realtek.com, bhelgaas@google.com Cc: koba.ko@canonical.com, acelan.kao@canonical.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, sathyanarayanan.kuppuswamy@linux.intel.com, vidyas@nvidia.com, rafael.j.wysocki@intel.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Kai-Heng Feng Subject: [PATCH v8 RESEND 6/6] r8169: Disable ASPM while doing NAPI poll Date: Tue, 21 Feb 2023 10:38:49 +0800 Message-Id: <20230221023849.1906728-7-kai.heng.feng@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230221023849.1906728-1-kai.heng.feng@canonical.com> References: <20230221023849.1906728-1-kai.heng.feng@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org NAPI poll of Realtek NICs don't seem to perform well ASPM is enabled. The vendor driver uses a mechanism called "dynamic ASPM" to toggle ASPM based on the packet number in given time period. Instead of implementing "dynamic ASPM", use a more straightforward way by disabling ASPM during NAPI poll, as a similar approach was implemented to solve slow performance on Realtek wireless NIC, see commit 24f5e38a13b5 ("rtw88: Disable PCIe ASPM while doing NAPI poll on 8821CE"). Since NAPI poll should be handled as fast as possible, also remove the delay in rtl_hw_aspm_clkreq_enable() which was added by commit 94235460f9ea ("r8169: Align ASPM/CLKREQ setting function with vendor driver"). Signed-off-by: Kai-Heng Feng --- v8: - New patch. drivers/net/ethernet/realtek/r8169_main.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c index 897f90b48bba6..4d4a802346ae3 100644 --- a/drivers/net/ethernet/realtek/r8169_main.c +++ b/drivers/net/ethernet/realtek/r8169_main.c @@ -2711,8 +2711,6 @@ static void rtl_hw_aspm_clkreq_enable(struct rtl8169_private *tp, bool enable) RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn); RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en); } - - udelay(10); } static void rtl_set_fifo_size(struct rtl8169_private *tp, u16 rx_stat, @@ -4577,6 +4575,12 @@ static int rtl8169_poll(struct napi_struct *napi, int budget) struct net_device *dev = tp->dev; int work_done; + if (tp->aspm_manageable) { + rtl_unlock_config_regs(tp); + rtl_hw_aspm_clkreq_enable(tp, false); + rtl_lock_config_regs(tp); + } + rtl_tx(dev, tp, budget); work_done = rtl_rx(dev, tp, budget); @@ -4584,6 +4588,12 @@ static int rtl8169_poll(struct napi_struct *napi, int budget) if (work_done < budget && napi_complete_done(napi, work_done)) rtl_irq_enable(tp); + if (tp->aspm_manageable) { + rtl_unlock_config_regs(tp); + rtl_hw_aspm_clkreq_enable(tp, true); + rtl_lock_config_regs(tp); + } + return work_done; }