From patchwork Thu Aug 25 01:56:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AceLan Kao X-Patchwork-Id: 1670025 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=pmzWh6Ki; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MCmKZ6lCDz1yg7 for ; Thu, 25 Aug 2022 11:56:34 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1oR26c-0007IO-6q; Thu, 25 Aug 2022 01:56:26 +0000 Received: from mail-pj1-f43.google.com ([209.85.216.43]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1oR26a-0007Ht-7c for kernel-team@lists.ubuntu.com; Thu, 25 Aug 2022 01:56:24 +0000 Received: by mail-pj1-f43.google.com with SMTP id x63-20020a17090a6c4500b001fabbf8debfso3335915pjj.4 for ; Wed, 24 Aug 2022 18:56:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:sender:from:to:cc; bh=fbxPhZHKJE0zIKePYpNQcn2rrhFZlJ/taGGETKmf1tw=; b=pmzWh6KiE3DSoRzUtsJhjHTnACyvit2jOF+D8OqCedObX5IfL6qMYIic+GUsUMXtQA PBYhZAtdMUqNZQrJtfRrfEc0Yn+EJMNbCqZsBJ0eQY3tb4r1C/4lyh/bEpGUwpaIESUH NtC7Ux4O9oQbRyy6QGJCJrClGShF7qBEniHuiYCLQ2p88vYWhHVGre2mqR0pTZYNfqLU 1m6pS59RwPHUkXyzStrleG/ZH3kKr05tRB0J1Tu8GKK6v7xE4p84W1Qy+TAx+hisQRe3 td3c6eVzkNQwRg75a/yX2uIFWxS93lej9Cp/9eroXHX0shTHR6HTcvUR+4P8QVrotyGV jm4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:sender:x-gm-message-state:from:to :cc; bh=fbxPhZHKJE0zIKePYpNQcn2rrhFZlJ/taGGETKmf1tw=; b=r6qkgqQMTm6XFHZ9pnHvaFcT5lWM7GAIRBCWkd5eu0lCTH3w9ztiWwcJkRT7L3F40n H6UYPrGJ4ADDK2qqHPEIv1dDFafL1QdHGdI3OOzcI4ZA9VjT12o2Aohbh6O9qHVojSIT zjkxBrYxvhUuyViqP0GQlzl/Xox0Km89UhEd8h1UAeOvnmJxueAJ0Gg0zevUDMxlYTYn hMicVRL7FLkx2EZ/k61Wuq3mLyufEIkS8ndyz2f5TBOVmrsqXzqKqWW+FenjckjUVe/O r6I5JNjZ9x5ofSLCpKOjKgEL3OsVaKxUawGV3qm10skjYq0NMGvxyaT9vLKLoAP1PMhp WKBA== X-Gm-Message-State: ACgBeo187FJhPjtpxfS7YgPO/80e/ifDGDXwVmKBviN6+A3RKvBUd3z6 J1ZCtwzGZuK7m50XA3MPv4nHeQAqfYc= X-Google-Smtp-Source: AA6agR6lSwLkmtEFpmtpf6KW9xsujRy52Pz4rVbkuzrFJNvj4+7IVVzUxPTYNrzGMiOqJinS6Zc2wg== X-Received: by 2002:a17:902:ce11:b0:172:6f2c:a910 with SMTP id k17-20020a170902ce1100b001726f2ca910mr1655248plg.156.1661392582209; Wed, 24 Aug 2022 18:56:22 -0700 (PDT) Received: from localhost (220-135-95-34.hinet-ip.hinet.net. [220.135.95.34]) by smtp.gmail.com with ESMTPSA id g15-20020aa79f0f000000b005365c636200sm9494744pfr.102.2022.08.24.18.56.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Aug 2022 18:56:21 -0700 (PDT) From: AceLan Kao To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 1/2][SRU][J][K] UBUNTU: SAUCE: PCI/ASPM: Save/restore L1SS Capability for suspend/resume Date: Thu, 25 Aug 2022 09:56:16 +0800 Message-Id: <20220825015618.39518-2-acelan.kao@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220825015618.39518-1-acelan.kao@canonical.com> References: <20220825015618.39518-1-acelan.kao@canonical.com> MIME-Version: 1.0 Received-SPF: pass client-ip=209.85.216.43; envelope-from=acelan@gmail.com; helo=mail-pj1-f43.google.com X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Vidya Sagar BugLink: https://bugs.launchpad.net/bugs/1980829 Previously ASPM L1 Substates control registers (CTL1 and CTL2) weren't saved and restored during suspend/resume leading to L1 Substates configuration being lost post-resume. Save the L1 Substates control registers so that the configuration is retained post-resume. Signed-off-by: Vidya Sagar Tested-by: Abhishek Sahu (cherry picked from commit https://patchwork.ozlabs.org/project/linux-pci/patch/20220705060014.10050-1-vidyas@nvidia.com/) Signed-off-by: Chia-Lin Kao (AceLan) --- drivers/pci/pci.c | 7 +++++++ drivers/pci/pci.h | 4 ++++ drivers/pci/pcie/aspm.c | 44 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index bc82fb70cad1..5c7ef86db60b 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -1623,6 +1623,7 @@ int pci_save_state(struct pci_dev *dev) return i; pci_save_ltr_state(dev); + pci_save_aspm_l1ss_state(dev); pci_save_dpc_state(dev); pci_save_aer_state(dev); pci_save_ptm_state(dev); @@ -1729,6 +1730,7 @@ void pci_restore_state(struct pci_dev *dev) * LTR itself (in the PCIe capability). */ pci_restore_ltr_state(dev); + pci_restore_aspm_l1ss_state(dev); pci_restore_pcie_state(dev); pci_restore_pasid_state(dev); @@ -3435,6 +3437,11 @@ void pci_allocate_cap_save_buffers(struct pci_dev *dev) if (error) pci_err(dev, "unable to allocate suspend buffer for LTR\n"); + error = pci_add_ext_cap_save_buffer(dev, PCI_EXT_CAP_ID_L1SS, + 2 * sizeof(u32)); + if (error) + pci_err(dev, "unable to allocate suspend buffer for ASPM-L1SS\n"); + pci_allocate_vc_save_buffers(dev); } diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index bc7f3a10ff60..c017776a9ec0 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -601,11 +601,15 @@ void pcie_aspm_init_link_state(struct pci_dev *pdev); void pcie_aspm_exit_link_state(struct pci_dev *pdev); void pcie_aspm_pm_state_change(struct pci_dev *pdev); void pcie_aspm_powersave_config_link(struct pci_dev *pdev); +void pci_save_aspm_l1ss_state(struct pci_dev *dev); +void pci_restore_aspm_l1ss_state(struct pci_dev *dev); #else static inline void pcie_aspm_init_link_state(struct pci_dev *pdev) { } static inline void pcie_aspm_exit_link_state(struct pci_dev *pdev) { } static inline void pcie_aspm_pm_state_change(struct pci_dev *pdev) { } static inline void pcie_aspm_powersave_config_link(struct pci_dev *pdev) { } +static inline void pci_save_aspm_l1ss_state(struct pci_dev *dev) { } +static inline void pci_restore_aspm_l1ss_state(struct pci_dev *dev) { } #endif #ifdef CONFIG_PCIE_ECRC diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c index 9523cd6468ee..09987b8023c9 100644 --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -735,6 +735,50 @@ static void pcie_config_aspm_l1ss(struct pcie_link_state *link, u32 state) PCI_L1SS_CTL1_L1SS_MASK, val); } +void pci_save_aspm_l1ss_state(struct pci_dev *dev) +{ + int aspm_l1ss; + struct pci_cap_saved_state *save_state; + u32 *cap; + + if (!pci_is_pcie(dev)) + return; + + aspm_l1ss = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_L1SS); + if (!aspm_l1ss) + return; + + save_state = pci_find_saved_ext_cap(dev, PCI_EXT_CAP_ID_L1SS); + if (!save_state) + return; + + cap = (u32 *)&save_state->cap.data[0]; + pci_read_config_dword(dev, aspm_l1ss + PCI_L1SS_CTL2, cap++); + pci_read_config_dword(dev, aspm_l1ss + PCI_L1SS_CTL1, cap++); +} + +void pci_restore_aspm_l1ss_state(struct pci_dev *dev) +{ + int aspm_l1ss; + struct pci_cap_saved_state *save_state; + u32 *cap; + + if (!pci_is_pcie(dev)) + return; + + aspm_l1ss = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_L1SS); + if (!aspm_l1ss) + return; + + save_state = pci_find_saved_ext_cap(dev, PCI_EXT_CAP_ID_L1SS); + if (!save_state) + return; + + cap = (u32 *)&save_state->cap.data[0]; + pci_write_config_dword(dev, aspm_l1ss + PCI_L1SS_CTL2, *cap++); + pci_write_config_dword(dev, aspm_l1ss + PCI_L1SS_CTL1, *cap++); +} + static void pcie_config_aspm_dev(struct pci_dev *pdev, u32 val) { pcie_capability_clear_and_set_word(pdev, PCI_EXP_LNKCTL,