From patchwork Tue Mar 10 01:48:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AceLan Kao X-Patchwork-Id: 1251917 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) 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: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Authentication-Results: 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=20161025 header.b=lx8ZfFZY; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48bygB31hzz9sRf; Tue, 10 Mar 2020 12:48:49 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1jBU0j-0001Ok-74; Tue, 10 Mar 2020 01:48:45 +0000 Received: from mail-pf1-f196.google.com ([209.85.210.196]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jBU0h-0001OP-Aq for kernel-team@lists.ubuntu.com; Tue, 10 Mar 2020 01:48:43 +0000 Received: by mail-pf1-f196.google.com with SMTP id f5so5694892pfk.9 for ; Mon, 09 Mar 2020 18:48:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=SssvR6G6NI1fThHKm8GLh/pR9nkTzTcge6H1CDywoew=; b=lx8ZfFZYKivlbDTCpU056mnnU8NKTbOrtpEJOg0HynpyeTvtGJLxcfzAk/k90Sx222 ONrbp6VHbkUx4poiqoFJJRqiNDCNaQ0E1wrq5lna4vAXZOFWQwtLSZQDzB9MLLwGxWIW rjHQZy7u1meEdPc7BlnXrSR90TJ7isX75qh+NKE5JsSEQDkFokgcEV5zwEoAmEuAj18T hd9VkffVnJ5ZKIkCiz+e5jTExBK43J7B503ceHxoUq/gCwVxUczCI/GUr2SsE4+tvAZA nGNf3wm2Um52hVtVDUMFAqwsE/KiMrgQ/I/Xi/TQT9ZjWOj9hDy03wXOCl5ILVnue6IK PkQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=SssvR6G6NI1fThHKm8GLh/pR9nkTzTcge6H1CDywoew=; b=BHzSayLk/HNSeNujMrm9cbfxHdqtRuoI5K/s5Io9ZQDo28aJkCfZEa1XV8HX/uK5a0 i2a+ZcUimqDch1+nfH8KPFa1yOxG0l7DDe1AGu6rpcyv/ivBciVtPjpc954PmUGiWk8l 0qmlkGTQTu10NwzD8hkOKiDAKHGYYmpVOjBNiE2UbfaTOkhiDugcApLb2ew9dqIXScoQ JmSRweV0DqSZQenH9uz4K2Gd6pTPDXYJMMkBlJRDrQnm4PkvaPkkk9S01CG9VvappMwD Rq5h23kFX4qh/O2J16ILkSznS+vtOvkqmkkOK2yIYoGmTktSAUc3L3L4zb1KM+8d2GB/ c0hg== X-Gm-Message-State: ANhLgQ3XUoCU8Q+x5LQtbYBiWThRufQ5rkkvNlMSsUzSj+ZHOr1kMMRh oPRwPCq6Jt5MPE24KSrxxk0a2uZB X-Google-Smtp-Source: ADFU+vu2gVOQlYK5hJtJZ96PByOplDqJrXhwMbZM4PFcZ8sre5aNeLffLOb4VKaSHkPSpYvo9RoC1w== X-Received: by 2002:a63:348b:: with SMTP id b133mr19059930pga.372.1583804921499; Mon, 09 Mar 2020 18:48:41 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id 144sm48667349pfc.45.2020.03.09.18.48.40 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 09 Mar 2020 18:48:40 -0700 (PDT) From: AceLan Kao To: kernel-team@lists.ubuntu.com Subject: [PATCH 1/7][SRU][Focal] PCI/ASPM: Add L1 PM substate support to pci_disable_link_state() Date: Tue, 10 Mar 2020 09:48:30 +0800 Message-Id: <20200310014836.23656-2-acelan.kao@canonical.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200310014836.23656-1-acelan.kao@canonical.com> References: <20200310014836.23656-1-acelan.kao@canonical.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: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Heiner Kallweit BugLink: https://bugs.launchpad.net/bugs/1836030 Add support for disabling states L1.1 and L1.2 to pci_disable_link_state(). Allow separate control of ASPM and PCI PM L1 substates. Link: https://lore.kernel.org/r/d81f8036-c236-6463-48e7-ebcdcda85bba@gmail.com Signed-off-by: Heiner Kallweit Signed-off-by: Bjorn Helgaas (cherry picked from commit aff5d0552da4055da3faa27ee4252e48bb1f5821) Signed-off-by: AceLan Kao --- drivers/pci/pcie/aspm.c | 11 ++++++++++- include/linux/pci.h | 10 +++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c index 652ef23bba35..e8df0b51b74a 100644 --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -1094,7 +1094,16 @@ static int __pci_disable_link_state(struct pci_dev *pdev, int state, bool sem) if (state & PCIE_LINK_STATE_L0S) link->aspm_disable |= ASPM_STATE_L0S; if (state & PCIE_LINK_STATE_L1) - link->aspm_disable |= ASPM_STATE_L1; + /* L1 PM substates require L1 */ + link->aspm_disable |= ASPM_STATE_L1 | ASPM_STATE_L1SS; + if (state & PCIE_LINK_STATE_L1_1) + link->aspm_disable |= ASPM_STATE_L1_1; + if (state & PCIE_LINK_STATE_L1_2) + link->aspm_disable |= ASPM_STATE_L1_2; + if (state & PCIE_LINK_STATE_L1_1_PCIPM) + link->aspm_disable |= ASPM_STATE_L1_1_PCIPM; + if (state & PCIE_LINK_STATE_L1_2_PCIPM) + link->aspm_disable |= ASPM_STATE_L1_2_PCIPM; pcie_config_aspm_link(link, policy_to_aspm_state(link)); if (state & PCIE_LINK_STATE_CLKPM) { diff --git a/include/linux/pci.h b/include/linux/pci.h index f39f22f9ee47..9c39a9ef2829 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1544,9 +1544,13 @@ extern bool pcie_ports_native; #define pcie_ports_native false #endif -#define PCIE_LINK_STATE_L0S 1 -#define PCIE_LINK_STATE_L1 2 -#define PCIE_LINK_STATE_CLKPM 4 +#define PCIE_LINK_STATE_L0S BIT(0) +#define PCIE_LINK_STATE_L1 BIT(1) +#define PCIE_LINK_STATE_CLKPM BIT(2) +#define PCIE_LINK_STATE_L1_1 BIT(3) +#define PCIE_LINK_STATE_L1_2 BIT(4) +#define PCIE_LINK_STATE_L1_1_PCIPM BIT(5) +#define PCIE_LINK_STATE_L1_2_PCIPM BIT(6) #ifdef CONFIG_PCIEASPM int pci_disable_link_state(struct pci_dev *pdev, int state); From patchwork Tue Mar 10 01:48:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AceLan Kao X-Patchwork-Id: 1251916 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) 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: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Authentication-Results: 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=20161025 header.b=mLwzA5a2; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48byg75W9wz9sSJ; Tue, 10 Mar 2020 12:48:51 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1jBU0m-0001QS-Cl; Tue, 10 Mar 2020 01:48:48 +0000 Received: from mail-pf1-f193.google.com ([209.85.210.193]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jBU0k-0001Oj-1f for kernel-team@lists.ubuntu.com; Tue, 10 Mar 2020 01:48:46 +0000 Received: by mail-pf1-f193.google.com with SMTP id l184so5695651pfl.7 for ; Mon, 09 Mar 2020 18:48:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=kkb7Yil0QGcFQNQoU9gazCdPLv9JgsPdJSmH8sw6M7w=; b=mLwzA5a2sJhwhPxPLnT05Nfwo6aw6jSGsiO25fQpzYD22AtlpGMjQ1n4wbdhsJ/FtZ Rv5vLit3BtsBsg65ZEMSs6DZloHAEC5tQRgBrahzvQxa0j2LJTm0v+GPwIOzMR6MY6YJ qpXToSBXAzrEIHzfPU+JkdeT5gxzmSSXDniwYl9iLSoQ1/KtJqSdHKCsOXDzJ61K9B0n cuAL3JAa4scPIBoS236qYAmcCchQG9BfavZI2/E5/QQTrG8/dQEt4TYb7ckQHYT+aWDR mezbtnhQItAw6jpRQKmCLKqJJpQrHAm6Iz7ePs4iONU5gM7nNe3C3Ep9zCZjp3Yjw44Q VlsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=kkb7Yil0QGcFQNQoU9gazCdPLv9JgsPdJSmH8sw6M7w=; b=UvX7TZeDAWZrcA5eeiDIhr4OsPZzW49MsVtzx8pb81m441uM3JUpGIEbMLpWTpF3bq Hlh7IfzRxoWdhsfO+pOW9Z81rRdrJeW3VhWgXnw1pbNkg7hn58YjPK9bNYFHhSye2Sle lqvVjr8olW3+dJW/JcDJU5U8KtaEQCuRCpRxngwR680r1b2IBl/5tle+Cwr4G/FI2YzQ KMmh9PRq3HnwuMqX2u+m2Qc6x75pSa6M2hctCckUyhY9orgAcB2hlTgPmsvxcD5GMGFR 9LhuudAZPfX6JQ6aDOzBed2tmDJB1c/rYB+99h15n6uJQyxvYUuNH73632UkWn6ZQ/AC ptqg== X-Gm-Message-State: ANhLgQ2zwK/TAc7N7BIuLHCNwWD4F2dDh4O2h62SvLpE5j7KCRh9q1Ym ASZ6+6Xzxh0oodRiHthv480LAn55 X-Google-Smtp-Source: ADFU+vszWLIWdyQeLgFuHQMbVG05K3rDUCx0bIDM5OtFAA5z9gsImWq76Cr3OPMsxC7XOnuv/DJXsg== X-Received: by 2002:aa7:8149:: with SMTP id d9mr18842955pfn.170.1583804924298; Mon, 09 Mar 2020 18:48:44 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id z6sm726832pjd.34.2020.03.09.18.48.43 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 09 Mar 2020 18:48:43 -0700 (PDT) From: AceLan Kao To: kernel-team@lists.ubuntu.com Subject: [PATCH 2/7][SRU][Focal] PCI/ASPM: Allow re-enabling Clock PM Date: Tue, 10 Mar 2020 09:48:31 +0800 Message-Id: <20200310014836.23656-3-acelan.kao@canonical.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200310014836.23656-1-acelan.kao@canonical.com> References: <20200310014836.23656-1-acelan.kao@canonical.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: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Heiner Kallweit BugLink: https://bugs.launchpad.net/bugs/1836030 Previously Clock PM could not be re-enabled after being disabled by pci_disable_link_state() because clkpm_capable was reset. Change this by adding a clkpm_disable field similar to aspm_disable. Link: https://lore.kernel.org/r/4e8a66db-7d53-4a66-c26c-f0037ffaa705@gmail.com Signed-off-by: Heiner Kallweit Signed-off-by: Bjorn Helgaas (cherry picked from commit 35efea32b26f9aacc99bf07e0d2cdfba2028b099) Signed-off-by: AceLan Kao --- drivers/pci/pcie/aspm.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c index e8df0b51b74a..a602c51c932f 100644 --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -64,6 +64,7 @@ struct pcie_link_state { u32 clkpm_capable:1; /* Clock PM capable? */ u32 clkpm_enabled:1; /* Current Clock PM state */ u32 clkpm_default:1; /* Default Clock PM state by BIOS */ + u32 clkpm_disable:1; /* Clock PM disabled */ /* Exit latencies */ struct aspm_latency latency_up; /* Upstream direction exit latency */ @@ -161,8 +162,11 @@ static void pcie_set_clkpm_nocheck(struct pcie_link_state *link, int enable) static void pcie_set_clkpm(struct pcie_link_state *link, int enable) { - /* Don't enable Clock PM if the link is not Clock PM capable */ - if (!link->clkpm_capable) + /* + * Don't enable Clock PM if the link is not Clock PM capable + * or Clock PM is disabled + */ + if (!link->clkpm_capable || link->clkpm_disable) enable = 0; /* Need nothing if the specified equals to current state */ if (link->clkpm_enabled == enable) @@ -192,7 +196,8 @@ static void pcie_clkpm_cap_init(struct pcie_link_state *link, int blacklist) } link->clkpm_enabled = enabled; link->clkpm_default = enabled; - link->clkpm_capable = (blacklist) ? 0 : capable; + link->clkpm_capable = capable; + link->clkpm_disable = blacklist ? 1 : 0; } static bool pcie_retrain_link(struct pcie_link_state *link) @@ -1106,10 +1111,9 @@ static int __pci_disable_link_state(struct pci_dev *pdev, int state, bool sem) link->aspm_disable |= ASPM_STATE_L1_2_PCIPM; pcie_config_aspm_link(link, policy_to_aspm_state(link)); - if (state & PCIE_LINK_STATE_CLKPM) { - link->clkpm_capable = 0; - pcie_set_clkpm(link, 0); - } + if (state & PCIE_LINK_STATE_CLKPM) + link->clkpm_disable = 1; + pcie_set_clkpm(link, policy_to_clkpm_state(link)); mutex_unlock(&aspm_lock); if (sem) up_read(&pci_bus_sem); From patchwork Tue Mar 10 01:48:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AceLan Kao X-Patchwork-Id: 1251919 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) 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: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Authentication-Results: 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=20161025 header.b=RZlGPCJ1; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48bygM648vz9sRR; Tue, 10 Mar 2020 12:49:03 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1jBU0y-0001Wp-Fy; Tue, 10 Mar 2020 01:49:00 +0000 Received: from mail-pg1-f194.google.com ([209.85.215.194]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jBU0m-0001Q2-IK for kernel-team@lists.ubuntu.com; Tue, 10 Mar 2020 01:48:48 +0000 Received: by mail-pg1-f194.google.com with SMTP id 37so1396201pgm.11 for ; Mon, 09 Mar 2020 18:48:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=8vWl209Gx2Gk2gdgROE21E2bSZ9Z8+AKQkkvYb12aZw=; b=RZlGPCJ1YyNyMfGsMFnMBil0HVj7Eo0ZE8vDPuWdyXXAhEv8v65fVEG2llqbqYhJaT dmn1oSZRpGV9M7365JUC6RCX7qkCmo9w9xsgXmBRL+0qY/ezYoJ+cYxmPj6oJkK8+3Mc gkZmY9ih/JfEfDLEFvT7jCJCvwJqB1K36kMDHx4eoQff6VnRAXR51PXYixgH9lNc4YZt zld1SRSig1fcjC5vYz8hSxyaBQ4AUWFmYhZoxt07wno8wlGEBNgXXTTXfm8foJi4cckX HulyoJXewm90xBp+my9ClRGTJmdmNJ1HfUWl0VJ6Hnhvhb6m4Onv4vMVrc+C74o4gfeQ IbUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=8vWl209Gx2Gk2gdgROE21E2bSZ9Z8+AKQkkvYb12aZw=; b=EqBOnpB5VmXRXgNwS/L+PGO1Zljy54xCyuAmxTMY+9f31Zq48XNw0Joe6cxi32Hv+6 SPGs/2Uc/8MPtZwHBLU9QsIaYggQtupSqlXU+9sW5ZmflSO+xWeKscgxZoQ6X9yGpTtG Xe+XCYSU0iLmsRd6E+FDf5BT9gaQe7lvVXiglJUQEiNV76iWRhLSUCJ2ThVDfPHvobK3 70kX5mfncpIQDPbs+tbccjuGixaNBXvixaxuC0pOetHwwgevieIqWyxxYxxKYZt/6FA8 QcznR/QJdJRow6hcmtQlQaiJO+rIK6tQxTa3ETWkIumbeaoFxg2h+RKBEEY5AJY4TvDu KaBA== X-Gm-Message-State: ANhLgQ2LXWbF9YBuuYrHq8zIG1dKnjEEcwOZHGbqRgReQ4PP7kF1Q/xQ hr2WPWCpDjxAhzrohWA+TIVffd5Q X-Google-Smtp-Source: ADFU+vuCJ4NV+eops4HJT5zVofzyjqoLkZYDEVuedwSPrafaKhkQT6py79VpoXYUu9cR1sgNpbDzaw== X-Received: by 2002:aa7:96a6:: with SMTP id g6mr9726789pfk.88.1583804926458; Mon, 09 Mar 2020 18:48:46 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id n14sm746571pjt.36.2020.03.09.18.48.45 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 09 Mar 2020 18:48:45 -0700 (PDT) From: AceLan Kao To: kernel-team@lists.ubuntu.com Subject: [PATCH 3/7][SRU][Focal] PCI/ASPM: Remove pcie_aspm_enabled() unnecessary locking Date: Tue, 10 Mar 2020 09:48:32 +0800 Message-Id: <20200310014836.23656-4-acelan.kao@canonical.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200310014836.23656-1-acelan.kao@canonical.com> References: <20200310014836.23656-1-acelan.kao@canonical.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: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Bjorn Helgaas BugLink: https://bugs.launchpad.net/bugs/1836030 The lifetime of the link_state structure (bridge->link_state) is not the same as the lifetime of "bridge" itself. The link_state is allocated by pcie_aspm_init_link_state() after children of the bridge have been enumerated, and it is deallocated by pcie_aspm_exit_link_state() after all children of the bridge (but not the bridge itself) have been removed. Previously pcie_aspm_enabled() acquired aspm_lock to ensure that link_state was not deallocated while we're looking at it. But the fact that the caller of pcie_aspm_enabled() holds a reference to @pdev means there's always at least one child of the bridge, which means link_state can't be deallocated. Remove the unnecessary locking in pcie_aspm_enabled(). Signed-off-by: Bjorn Helgaas Acked-by: Rafael J. Wysocki (cherry picked from commit 5e0c21c75e8c08375a69710527e4a921b897cb7e) Signed-off-by: AceLan Kao --- drivers/pci/pcie/aspm.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c index a602c51c932f..23e1d6b88655 100644 --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -1185,20 +1185,20 @@ module_param_call(policy, pcie_aspm_set_policy, pcie_aspm_get_policy, /** * pcie_aspm_enabled - Check if PCIe ASPM has been enabled for a device. * @pdev: Target device. + * + * Relies on the upstream bridge's link_state being valid. The link_state + * is deallocated only when the last child of the bridge (i.e., @pdev or a + * sibling) is removed, and the caller should be holding a reference to + * @pdev, so this should be safe. */ bool pcie_aspm_enabled(struct pci_dev *pdev) { struct pci_dev *bridge = pci_upstream_bridge(pdev); - bool ret; if (!bridge) return false; - mutex_lock(&aspm_lock); - ret = bridge->link_state ? !!bridge->link_state->aspm_enabled : false; - mutex_unlock(&aspm_lock); - - return ret; + return bridge->link_state ? !!bridge->link_state->aspm_enabled : false; } EXPORT_SYMBOL_GPL(pcie_aspm_enabled); From patchwork Tue Mar 10 01:48:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AceLan Kao X-Patchwork-Id: 1251921 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) 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: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Authentication-Results: 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=20161025 header.b=ojtLF+PD; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48bygQ2m22z9sSJ; Tue, 10 Mar 2020 12:49:06 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1jBU10-0001Yw-Vi; Tue, 10 Mar 2020 01:49:02 +0000 Received: from mail-pl1-f195.google.com ([209.85.214.195]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jBU0p-0001RZ-T8 for kernel-team@lists.ubuntu.com; Tue, 10 Mar 2020 01:48:52 +0000 Received: by mail-pl1-f195.google.com with SMTP id w12so4753213pll.13 for ; Mon, 09 Mar 2020 18:48:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=kEKGvWE3KQ7k9FQz1kpVGsHGqITc+TEAXnINDm/b0J0=; b=ojtLF+PDbyh9w8jzpb3szAs9fXE36ljBsa6tDX7SvJsm6B2vng74NM+rI5nIgHxhcz 7FLUv02LyR6GnabFgw0cujfcdIHn1Un10w3MH1/n/AdZm14OAziTey4ydubz6QBz3Ui+ snn2ZgTja8c00h1wQqzoq/48fj8Y3L/SFzJYgrdFMfW6LD5Ehcm10htz2+6EhB6kbmXE zLPR+TyRFmO2ERbyq/raMg57wqJmS1TzVFPqc0IyyACunaeEhnkBNptIQ7n9s0ZU6Dc0 OB50uWz7Ajbl3RjjFqH0Pcu0ovErxmm/rFan9FbfJICIUxqf/CC4ATJXW0AYJa5nANlP CM/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=kEKGvWE3KQ7k9FQz1kpVGsHGqITc+TEAXnINDm/b0J0=; b=GrlqlvmksCMQYbSH/n6IOXqO+On5iELmqtkPfAIuDIJQLayh4ToNMAWKfu1vGVC+kn nxh8FbqXgBZmCDO/ijgfJqtTWwRu2lqlE/41yLaI+L3JWGKdr3Tto8lKx06O4poP/iEx McwiAmso4YLXGTNv0od7xl/b2Z2sHPc/24VQJpL7EtYMHivlryTyv2Wk0nYB/660cB+d CYardW/YH+Rq2k1HKv9TgNAWuRTRaLei5nTR/bYpMKAKmilfYPd+TywkT1gq2uJjpdXS DcKw+54dtzF7eXpuxznLtLHqtzn42ZSP5fm/roGA/LBInha+Ls8qfchqjgaCvmdrkiZc e8rw== X-Gm-Message-State: ANhLgQ0P1xO5T0I2W5V34xiWPWhYK9DGnquvW5iI0RPwF6J2NaBoV++Q GBHbY1L7F/IbPhG8w13YCRs/+dsw X-Google-Smtp-Source: ADFU+vtXUxiAGhg5/cOL9WjfH4elojyZhJJcCfE8TNedDpViSZJ9bbmNmXclQRWlfLsk47n5QhdaDQ== X-Received: by 2002:a17:902:8d92:: with SMTP id v18mr18833859plo.18.1583804929610; Mon, 09 Mar 2020 18:48:49 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id 72sm35284362pgd.86.2020.03.09.18.48.48 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 09 Mar 2020 18:48:49 -0700 (PDT) From: AceLan Kao To: kernel-team@lists.ubuntu.com Subject: [PATCH 4/7][SRU][Focal] PCI/ASPM: Add pcie_aspm_get_link() Date: Tue, 10 Mar 2020 09:48:33 +0800 Message-Id: <20200310014836.23656-5-acelan.kao@canonical.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200310014836.23656-1-acelan.kao@canonical.com> References: <20200310014836.23656-1-acelan.kao@canonical.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: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Heiner Kallweit BugLink: https://bugs.launchpad.net/bugs/1836030 Factor out getting the link associated with a pci_dev and use this helper where appropriate. In addition this helper will be used in a subsequent patch of this series. Link: https://lore.kernel.org/r/19d33770-29de-a9af-4d85-f2b30269d383@gmail.com Signed-off-by: Heiner Kallweit Signed-off-by: Bjorn Helgaas (cherry picked from commit 687aaf386aeb551130f31705ce40d1341047a936) Signed-off-by: AceLan Kao --- drivers/pci/pcie/aspm.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c index 23e1d6b88655..2d5ecede8fa3 100644 --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -1066,19 +1066,26 @@ void pcie_aspm_powersave_config_link(struct pci_dev *pdev) up_read(&pci_bus_sem); } -static int __pci_disable_link_state(struct pci_dev *pdev, int state, bool sem) +static struct pcie_link_state *pcie_aspm_get_link(struct pci_dev *pdev) { - struct pci_dev *parent = pdev->bus->self; - struct pcie_link_state *link; + struct pci_dev *bridge; if (!pci_is_pcie(pdev)) - return 0; + return NULL; - if (pcie_downstream_port(pdev)) - parent = pdev; - if (!parent || !parent->link_state) - return -EINVAL; + bridge = pci_upstream_bridge(pdev); + if (!bridge || !pci_is_pcie(bridge)) + return NULL; + return bridge->link_state; +} + +static int __pci_disable_link_state(struct pci_dev *pdev, int state, bool sem) +{ + struct pcie_link_state *link = pcie_aspm_get_link(pdev); + + if (!link) + return -EINVAL; /* * A driver requested that ASPM be disabled on this device, but * if we don't have permission to manage ASPM (e.g., on ACPI @@ -1095,7 +1102,6 @@ static int __pci_disable_link_state(struct pci_dev *pdev, int state, bool sem) if (sem) down_read(&pci_bus_sem); mutex_lock(&aspm_lock); - link = parent->link_state; if (state & PCIE_LINK_STATE_L0S) link->aspm_disable |= ASPM_STATE_L0S; if (state & PCIE_LINK_STATE_L1) @@ -1193,12 +1199,12 @@ module_param_call(policy, pcie_aspm_set_policy, pcie_aspm_get_policy, */ bool pcie_aspm_enabled(struct pci_dev *pdev) { - struct pci_dev *bridge = pci_upstream_bridge(pdev); + struct pcie_link_state *link = pcie_aspm_get_link(pdev); - if (!bridge) + if (!link) return false; - return bridge->link_state ? !!bridge->link_state->aspm_enabled : false; + return link->aspm_enabled; } EXPORT_SYMBOL_GPL(pcie_aspm_enabled); From patchwork Tue Mar 10 01:48:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AceLan Kao X-Patchwork-Id: 1251918 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) 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: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Authentication-Results: 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=20161025 header.b=ckXlW2lL; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48bygJ5ZRPz9sRf; Tue, 10 Mar 2020 12:49:00 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1jBU0v-0001UY-A2; Tue, 10 Mar 2020 01:48:57 +0000 Received: from mail-pl1-f196.google.com ([209.85.214.196]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jBU0r-0001Sx-UX for kernel-team@lists.ubuntu.com; Tue, 10 Mar 2020 01:48:54 +0000 Received: by mail-pl1-f196.google.com with SMTP id h11so1574657plk.7 for ; Mon, 09 Mar 2020 18:48:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=songgneK7ehQXZ+EY+FgAdwWNGIf7sYqhSIy52AjAdU=; b=ckXlW2lLMtUJU8tnJj1mwPykbxu+SaFNhtuw129MYIzsfXRl7Ii01uhm+cavhaNxjC pA7V1MVVtKwPHZ85erTHYOrJP7hchndJ14vSpjLnoRcpneBeocesFKWzOKBq2Yw7erdv e4jON0rqQ7YzI4PtDrOy8TIEpc4cV4LGVNpRFWeA+1PM5tS1GezdZ7JXHc9b+lXdD2wb KL6B0KKwWZ4oxdX7YV804MjKbtBwz/rhBKmAoQmpUaH0wMGWsB+QWznj2rPDVphImVqN UVuoE9qKyvQbwaf3Jaf8ow/xxadVAeNhlenWYPaGseHbOKgyaQMFihFsOjE4W51DNUC1 qqCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=songgneK7ehQXZ+EY+FgAdwWNGIf7sYqhSIy52AjAdU=; b=FdaaX5VhL41tFEVp8QbkUC/0jrbZLeWnaoDBZb0XaMmXM6dpxuk2euGd3vfqrn90yp 6wnWobE/ZmV/wYAbsdQMArVpHW/3mQmR22cmHwfM/GsA/1RyhKbpRBzgSsOQ5evzh7K1 1Ww/oDdfNFXAF1ALTT41/wQDQ26RPAqlo0slT3vaWo8N2JMYV8NuH+mgw3OMdHeTP9hI naCNwjxWLo2sADhWmKcE9tzdY1lwcO8sY3a5zgs+WYyZ4/yAovVOtqHckcgllDtFnNqx n0hHaSMF9kENFMfoM/mv8yaNchO6i0GBbNuNwbqCHdegRQoHdlfL2o++lZ4JbVayR7QP dnbQ== X-Gm-Message-State: ANhLgQ0oiS+fkGm+AUQZRLJOD8gRgr1wdCOtTDL4Kpki36b1IB9fhK3Q kJwNgXqb1retWoucMmVdOveBwjer X-Google-Smtp-Source: ADFU+vtgAfUhrGdmrD9A50gAIj2YGaIQD6ULTTLEM8R4+2ipiWzbQ8pwsi8/DilIWOQN9Fuu9i+E8w== X-Received: by 2002:a17:902:8c91:: with SMTP id t17mr16981209plo.98.1583804932052; Mon, 09 Mar 2020 18:48:52 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id k21sm9313127pfi.115.2020.03.09.18.48.51 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 09 Mar 2020 18:48:51 -0700 (PDT) From: AceLan Kao To: kernel-team@lists.ubuntu.com Subject: [PATCH 5/7][SRU][Focal] PCI/ASPM: Add sysfs attributes for controlling ASPM link states Date: Tue, 10 Mar 2020 09:48:34 +0800 Message-Id: <20200310014836.23656-6-acelan.kao@canonical.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200310014836.23656-1-acelan.kao@canonical.com> References: <20200310014836.23656-1-acelan.kao@canonical.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: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Heiner Kallweit BugLink: https://bugs.launchpad.net/ubuntu/bugs/1836030 Add sysfs attributes to Endpoints and other Upstream Ports to control ASPM, Clock PM, and L1 PM Substates. The new attributes are: /sys/devices/pci*/.../link/clkpm /sys/devices/pci*/.../link/l0s_aspm /sys/devices/pci*/.../link/l1_aspm /sys/devices/pci*/.../link/l1_1_aspm /sys/devices/pci*/.../link/l1_2_aspm /sys/devices/pci*/.../link/l1_1_pcipm /sys/devices/pci*/.../link/l1_2_pcipm An attribute is only visible if both ends of the Link leading to the device support the state. Writing y/1/on to the file enables the state; n/0/off disables it. These attributes can be used to tune the power/performance tradeoff for individual devices. [bhelgaas: commit log, rename directory to "link"] Link: https://lore.kernel.org/r/b1c83f8a-9bf6-eac5-82d0-cf5b90128fbf@gmail.com Signed-off-by: Heiner Kallweit Signed-off-by: Bjorn Helgaas (cherry picked from commit 72ea91afbfb08619696ccde610ee4d0d29cf4a1d) Signed-off-by: AceLan Kao --- Documentation/ABI/testing/sysfs-bus-pci | 13 +++ drivers/pci/pci-sysfs.c | 3 + drivers/pci/pci.h | 4 + drivers/pci/pcie/aspm.c | 149 ++++++++++++++++++++++++ 4 files changed, 169 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-bus-pci b/Documentation/ABI/testing/sysfs-bus-pci index 8bfee557e50e..450296cc7948 100644 --- a/Documentation/ABI/testing/sysfs-bus-pci +++ b/Documentation/ABI/testing/sysfs-bus-pci @@ -347,3 +347,16 @@ Description: If the device has any Peer-to-Peer memory registered, this file contains a '1' if the memory has been published for use outside the driver that owns the device. + +What: /sys/bus/pci/devices/.../link/clkpm + /sys/bus/pci/devices/.../link/l0s_aspm + /sys/bus/pci/devices/.../link/l1_aspm + /sys/bus/pci/devices/.../link/l1_1_aspm + /sys/bus/pci/devices/.../link/l1_2_aspm + /sys/bus/pci/devices/.../link/l1_1_pcipm + /sys/bus/pci/devices/.../link/l1_2_pcipm +Date: October 2019 +Contact: Heiner Kallweit +Description: If ASPM is supported for an endpoint, these files can be + used to disable or enable the individual power management + states. Write y/1/on to enable, n/0/off to disable. diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 793412954529..0e76c02e0b7d 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -1587,6 +1587,9 @@ static const struct attribute_group *pci_dev_attr_groups[] = { &pcie_dev_attr_group, #ifdef CONFIG_PCIEAER &aer_stats_attr_group, +#endif +#ifdef CONFIG_PCIEASPM + &aspm_ctrl_attr_group, #endif NULL, }; diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index a5adc2e2c351..317a796a723e 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -671,4 +671,8 @@ static inline int pci_acpi_program_hp_params(struct pci_dev *dev) } #endif +#ifdef CONFIG_PCIEASPM +extern const struct attribute_group aspm_ctrl_attr_group; +#endif + #endif /* DRIVERS_PCI_H */ diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c index 2d5ecede8fa3..9cd251827a67 100644 --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -899,6 +899,14 @@ static struct pcie_link_state *alloc_pcie_link_state(struct pci_dev *pdev) return link; } +static void pcie_aspm_update_sysfs_visibility(struct pci_dev *pdev) +{ + struct pci_dev *child; + + list_for_each_entry(child, &pdev->subordinate->devices, bus_list) + sysfs_update_group(&child->dev.kobj, &aspm_ctrl_attr_group); +} + /* * pcie_aspm_init_link_state: Initiate PCI express link state. * It is called after the pcie and its children devices are scanned. @@ -960,6 +968,8 @@ void pcie_aspm_init_link_state(struct pci_dev *pdev) pcie_set_clkpm(link, policy_to_clkpm_state(link)); } + pcie_aspm_update_sysfs_visibility(pdev); + unlock: mutex_unlock(&aspm_lock); out: @@ -1313,6 +1323,145 @@ void pcie_aspm_remove_sysfs_dev_files(struct pci_dev *pdev) } #endif +static ssize_t aspm_attr_show_common(struct device *dev, + struct device_attribute *attr, + char *buf, u8 state) +{ + struct pci_dev *pdev = to_pci_dev(dev); + struct pcie_link_state *link = pcie_aspm_get_link(pdev); + + return sprintf(buf, "%d\n", (link->aspm_enabled & state) ? 1 : 0); +} + +static ssize_t aspm_attr_store_common(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len, u8 state) +{ + struct pci_dev *pdev = to_pci_dev(dev); + struct pcie_link_state *link = pcie_aspm_get_link(pdev); + bool state_enable; + + if (strtobool(buf, &state_enable) < 0) + return -EINVAL; + + down_read(&pci_bus_sem); + mutex_lock(&aspm_lock); + + if (state_enable) { + link->aspm_disable &= ~state; + /* need to enable L1 for substates */ + if (state & ASPM_STATE_L1SS) + link->aspm_disable &= ~ASPM_STATE_L1; + } else { + link->aspm_disable |= state; + } + + pcie_config_aspm_link(link, policy_to_aspm_state(link)); + + mutex_unlock(&aspm_lock); + up_read(&pci_bus_sem); + + return len; +} + +#define ASPM_ATTR(_f, _s) \ +static ssize_t _f##_show(struct device *dev, \ + struct device_attribute *attr, char *buf) \ +{ return aspm_attr_show_common(dev, attr, buf, ASPM_STATE_##_s); } \ + \ +static ssize_t _f##_store(struct device *dev, \ + struct device_attribute *attr, \ + const char *buf, size_t len) \ +{ return aspm_attr_store_common(dev, attr, buf, len, ASPM_STATE_##_s); } + +ASPM_ATTR(l0s_aspm, L0S) +ASPM_ATTR(l1_aspm, L1) +ASPM_ATTR(l1_1_aspm, L1_1) +ASPM_ATTR(l1_2_aspm, L1_2) +ASPM_ATTR(l1_1_pcipm, L1_1_PCIPM) +ASPM_ATTR(l1_2_pcipm, L1_2_PCIPM) + +static ssize_t clkpm_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct pci_dev *pdev = to_pci_dev(dev); + struct pcie_link_state *link = pcie_aspm_get_link(pdev); + + return sprintf(buf, "%d\n", link->clkpm_enabled); +} + +static ssize_t clkpm_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len) +{ + struct pci_dev *pdev = to_pci_dev(dev); + struct pcie_link_state *link = pcie_aspm_get_link(pdev); + bool state_enable; + + if (strtobool(buf, &state_enable) < 0) + return -EINVAL; + + down_read(&pci_bus_sem); + mutex_lock(&aspm_lock); + + link->clkpm_disable = !state_enable; + pcie_set_clkpm(link, policy_to_clkpm_state(link)); + + mutex_unlock(&aspm_lock); + up_read(&pci_bus_sem); + + return len; +} + +static DEVICE_ATTR_RW(clkpm); +static DEVICE_ATTR_RW(l0s_aspm); +static DEVICE_ATTR_RW(l1_aspm); +static DEVICE_ATTR_RW(l1_1_aspm); +static DEVICE_ATTR_RW(l1_2_aspm); +static DEVICE_ATTR_RW(l1_1_pcipm); +static DEVICE_ATTR_RW(l1_2_pcipm); + +static struct attribute *aspm_ctrl_attrs[] = { + &dev_attr_clkpm.attr, + &dev_attr_l0s_aspm.attr, + &dev_attr_l1_aspm.attr, + &dev_attr_l1_1_aspm.attr, + &dev_attr_l1_2_aspm.attr, + &dev_attr_l1_1_pcipm.attr, + &dev_attr_l1_2_pcipm.attr, + NULL +}; + +static umode_t aspm_ctrl_attrs_are_visible(struct kobject *kobj, + struct attribute *a, int n) +{ + struct device *dev = kobj_to_dev(kobj); + struct pci_dev *pdev = to_pci_dev(dev); + struct pcie_link_state *link = pcie_aspm_get_link(pdev); + static const u8 aspm_state_map[] = { + ASPM_STATE_L0S, + ASPM_STATE_L1, + ASPM_STATE_L1_1, + ASPM_STATE_L1_2, + ASPM_STATE_L1_1_PCIPM, + ASPM_STATE_L1_2_PCIPM, + }; + + if (aspm_disabled || !link) + return 0; + + if (n == 0) + return link->clkpm_capable ? a->mode : 0; + + return link->aspm_capable & aspm_state_map[n - 1] ? a->mode : 0; +} + +const struct attribute_group aspm_ctrl_attr_group = { + .name = "link", + .attrs = aspm_ctrl_attrs, + .is_visible = aspm_ctrl_attrs_are_visible, +}; + static int __init pcie_aspm_disable(char *str) { if (!strcmp(str, "off")) { From patchwork Tue Mar 10 01:48:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AceLan Kao X-Patchwork-Id: 1251920 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) 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: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Authentication-Results: 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=20161025 header.b=fGhZQKyO; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48bygQ15wNz9sRR; Tue, 10 Mar 2020 12:49:06 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1jBU0z-0001YF-QL; Tue, 10 Mar 2020 01:49:01 +0000 Received: from mail-pj1-f66.google.com ([209.85.216.66]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jBU0v-0001UM-3F for kernel-team@lists.ubuntu.com; Tue, 10 Mar 2020 01:48:57 +0000 Received: by mail-pj1-f66.google.com with SMTP id u10so704557pjy.0 for ; Mon, 09 Mar 2020 18:48:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=LmjgnmIBksq43qjnH/SiHVJpRGSZlabXB28oHE+plZQ=; b=fGhZQKyOr9U+9dFjOzxv6OJtzdspAZ7w5qU6TfYa+OHFWz85IuZR9HtA2mxTpMdTiA PmFZxtbo9VXnQbsPEaci/T0MzyajPCYt7NoidzBTwOnBrIdxioD4Q47ocvqN5O8n2U6F XctaAuA9xGEVLla5c6g6s+Ek9C68kalZ4e/g6fDUBGLaNwY2OIgbVrHZGXeUikcOvGwv Zj3hbVvYlRnhCvSk/2ORtNWrOAisDvIqoMailX7jJeOTVib9lD2YabfoPhKbSEIQtHFe ICEGH4KmWNBDXqMV5S8NDlhkvFbaoQ4sQGX0tH3yLfCdFONNUPEajBlxp7T0+fpp0KNo 7C/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=LmjgnmIBksq43qjnH/SiHVJpRGSZlabXB28oHE+plZQ=; b=TILYZnklNh41qgpaNXgXlllWYTPjC8VXMbUuM1SQHIdSrg3Ny61Oh2mGAeDAP01vRg yjfrJXpCgEc1yWbDh/1jFoqjgAanJOyyCOSUBDGuKQyn+cj5IvAFC8Fd5bJ/ZBvNhs7z /eyA886B75HnRT4CQguZaviLI+Bag4GR8s2/SmXG7qtA3O9UbKN2I6OM7vX3YbEqEFkM QaaHlb+dIT/lre+ZOKl2qQBWRNRdkcR77B7P6PiNDYKDUKRdcHHRewRPn9dRY1SIcWI8 8+6ZIOuVIn69y93vZZap+Bqk9Qc3ItdLW7j+ljjf1sR3BErLbXPimWTnz7qACJ7nfWGA NtPQ== X-Gm-Message-State: ANhLgQ3xbZmaIb/Cr3GuT8Y4jhcCSuvEYWwBRb169r5mmYRXXrM/Sxwm RhW/dstz2da08+Qw2YnrNx6nhNtH X-Google-Smtp-Source: ADFU+vsn8O5C8TqznMqm8mfnfOSNqiUNE+6Vy4pnQIP1LkRib4NfCLbLaSLplR1eMx0WZEustKpaVg== X-Received: by 2002:a17:902:a409:: with SMTP id p9mr18746122plq.211.1583804935062; Mon, 09 Mar 2020 18:48:55 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id cm2sm750939pjb.23.2020.03.09.18.48.54 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 09 Mar 2020 18:48:54 -0700 (PDT) From: AceLan Kao To: kernel-team@lists.ubuntu.com Subject: [PATCH 6/7][SRU][Focal] PCI/ASPM: Remove PCIEASPM_DEBUG Kconfig option and related code Date: Tue, 10 Mar 2020 09:48:35 +0800 Message-Id: <20200310014836.23656-7-acelan.kao@canonical.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200310014836.23656-1-acelan.kao@canonical.com> References: <20200310014836.23656-1-acelan.kao@canonical.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: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Heiner Kallweit BguLink: https://bugs.launchpad.net/bugs/1836030 Previously, CONFIG_PCIEASPM_DEBUG enabled "link_state" and "clk_ctl" sysfs files that controlled ASPM. We believe these files were rarely if ever used. We recently added sysfs ASPM controls that are always present, so the debug code is no longer needed. Removing this debug code has been discussed for quite some time, see e.g. [0]. Remove PCIEASPM_DEBUG and the related code. [0] https://lore.kernel.org/lkml/20180727202619.GD173328@bhelgaas-glaptop.roam.corp.google.com/ Link: https://lore.kernel.org/r/ec935d8e-c084-3938-f1d1-748617596b25@gmail.com Signed-off-by: Heiner Kallweit Signed-off-by: Bjorn Helgaas (cherry picked from commit 87e90283c94c76ee11d379ab5a0973382bbd0baf) Signed-off-by: AceLan Kao --- drivers/pci/pci-sysfs.c | 3 -- drivers/pci/pci.h | 8 --- drivers/pci/pcie/Kconfig | 7 --- drivers/pci/pcie/aspm.c | 105 --------------------------------------- 4 files changed, 123 deletions(-) diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 0e76c02e0b7d..92bf1b1ce280 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -1330,7 +1330,6 @@ static int pci_create_capabilities_sysfs(struct pci_dev *dev) int retval; pcie_vpd_create_sysfs_dev_files(dev); - pcie_aspm_create_sysfs_dev_files(dev); if (dev->reset_fn) { retval = device_create_file(&dev->dev, &dev_attr_reset); @@ -1340,7 +1339,6 @@ static int pci_create_capabilities_sysfs(struct pci_dev *dev) return 0; error: - pcie_aspm_remove_sysfs_dev_files(dev); pcie_vpd_remove_sysfs_dev_files(dev); return retval; } @@ -1416,7 +1414,6 @@ int __must_check pci_create_sysfs_dev_files(struct pci_dev *pdev) static void pci_remove_capabilities_sysfs(struct pci_dev *dev) { pcie_vpd_remove_sysfs_dev_files(dev); - pcie_aspm_remove_sysfs_dev_files(dev); if (dev->reset_fn) { device_remove_file(&dev->dev, &dev_attr_reset); dev->reset_fn = 0; diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 317a796a723e..09d54503f366 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -545,14 +545,6 @@ static inline void pcie_aspm_pm_state_change(struct pci_dev *pdev) { } static inline void pcie_aspm_powersave_config_link(struct pci_dev *pdev) { } #endif -#ifdef CONFIG_PCIEASPM_DEBUG -void pcie_aspm_create_sysfs_dev_files(struct pci_dev *pdev); -void pcie_aspm_remove_sysfs_dev_files(struct pci_dev *pdev); -#else -static inline void pcie_aspm_create_sysfs_dev_files(struct pci_dev *pdev) { } -static inline void pcie_aspm_remove_sysfs_dev_files(struct pci_dev *pdev) { } -#endif - #ifdef CONFIG_PCIE_ECRC void pcie_set_ecrc_checking(struct pci_dev *dev); void pcie_ecrc_get_policy(char *str); diff --git a/drivers/pci/pcie/Kconfig b/drivers/pci/pcie/Kconfig index 362eb8cfa53b..a2e862d4ec21 100644 --- a/drivers/pci/pcie/Kconfig +++ b/drivers/pci/pcie/Kconfig @@ -79,13 +79,6 @@ config PCIEASPM When in doubt, say Y. -config PCIEASPM_DEBUG - bool "Debug PCI Express ASPM" - depends on PCIEASPM - help - This enables PCI Express ASPM debug support. It will add per-device - interface to control ASPM. - choice prompt "Default ASPM policy" default PCIEASPM_DEFAULT diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c index 9cd251827a67..0dcd44308228 100644 --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -1218,111 +1218,6 @@ bool pcie_aspm_enabled(struct pci_dev *pdev) } EXPORT_SYMBOL_GPL(pcie_aspm_enabled); -#ifdef CONFIG_PCIEASPM_DEBUG -static ssize_t link_state_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct pci_dev *pci_device = to_pci_dev(dev); - struct pcie_link_state *link_state = pci_device->link_state; - - return sprintf(buf, "%d\n", link_state->aspm_enabled); -} - -static ssize_t link_state_store(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t n) -{ - struct pci_dev *pdev = to_pci_dev(dev); - struct pcie_link_state *link, *root = pdev->link_state->root; - u32 state; - - if (aspm_disabled) - return -EPERM; - - if (kstrtouint(buf, 10, &state)) - return -EINVAL; - if ((state & ~ASPM_STATE_ALL) != 0) - return -EINVAL; - - down_read(&pci_bus_sem); - mutex_lock(&aspm_lock); - list_for_each_entry(link, &link_list, sibling) { - if (link->root != root) - continue; - pcie_config_aspm_link(link, state); - } - mutex_unlock(&aspm_lock); - up_read(&pci_bus_sem); - return n; -} - -static ssize_t clk_ctl_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct pci_dev *pci_device = to_pci_dev(dev); - struct pcie_link_state *link_state = pci_device->link_state; - - return sprintf(buf, "%d\n", link_state->clkpm_enabled); -} - -static ssize_t clk_ctl_store(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t n) -{ - struct pci_dev *pdev = to_pci_dev(dev); - bool state; - - if (strtobool(buf, &state)) - return -EINVAL; - - down_read(&pci_bus_sem); - mutex_lock(&aspm_lock); - pcie_set_clkpm_nocheck(pdev->link_state, state); - mutex_unlock(&aspm_lock); - up_read(&pci_bus_sem); - - return n; -} - -static DEVICE_ATTR_RW(link_state); -static DEVICE_ATTR_RW(clk_ctl); - -static char power_group[] = "power"; -void pcie_aspm_create_sysfs_dev_files(struct pci_dev *pdev) -{ - struct pcie_link_state *link_state = pdev->link_state; - - if (!link_state) - return; - - if (link_state->aspm_support) - sysfs_add_file_to_group(&pdev->dev.kobj, - &dev_attr_link_state.attr, power_group); - if (link_state->clkpm_capable) - sysfs_add_file_to_group(&pdev->dev.kobj, - &dev_attr_clk_ctl.attr, power_group); -} - -void pcie_aspm_remove_sysfs_dev_files(struct pci_dev *pdev) -{ - struct pcie_link_state *link_state = pdev->link_state; - - if (!link_state) - return; - - if (link_state->aspm_support) - sysfs_remove_file_from_group(&pdev->dev.kobj, - &dev_attr_link_state.attr, power_group); - if (link_state->clkpm_capable) - sysfs_remove_file_from_group(&pdev->dev.kobj, - &dev_attr_clk_ctl.attr, power_group); -} -#endif - static ssize_t aspm_attr_show_common(struct device *dev, struct device_attribute *attr, char *buf, u8 state) From patchwork Tue Mar 10 01:48:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AceLan Kao X-Patchwork-Id: 1251922 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) 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: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Authentication-Results: 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=20161025 header.b=mE+pseRf; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48bygR5JSZz9sPF; Tue, 10 Mar 2020 12:49:07 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1jBU11-0001Zn-GQ; Tue, 10 Mar 2020 01:49:03 +0000 Received: from mail-pj1-f67.google.com ([209.85.216.67]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jBU0x-0001VP-C1 for kernel-team@lists.ubuntu.com; Tue, 10 Mar 2020 01:48:59 +0000 Received: by mail-pj1-f67.google.com with SMTP id np16so693906pjb.4 for ; Mon, 09 Mar 2020 18:48:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=nBzn/86Bi6qqV4b3wqXYQapd0NCnrYurTxyljzDwjnY=; b=mE+pseRfGCiurH6tJFPPfwCf2A8hCdJTwy9mKV8WNm43f2p2SCmWjHFkT1nHa2YQpO KWK5Zu4pFYmGg9848Bilk+KVJTmQK6+lrdp/lb5mmajS8wSnby7FJ4r1YrudWBvi4nwA /IBw45xc2n9bSWXEAJjc+1OnaGvpVUjESYe3dYO7sevqlQzRU5Z2FhsUlm9EQPvZZTrW beucQ7ouVnrUnLXoeOAVA/nYvoWr4lXMf2ybJMMJoGfO36a/Z3UIiJAPqZR+6JQbmtdW +OQTvRJFTInHasDjiEmze4I+RbRRUyigpFchFcrZRUEcmqlt7iMqaUR/n6eb5hzjtoDe SywQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=nBzn/86Bi6qqV4b3wqXYQapd0NCnrYurTxyljzDwjnY=; b=GTwhIbaTLUqde23NMLVHXFn4dDZ7H4FUIIMfxjUontZtBFZtdNQSqSrJQLl7hnftkN g352DdUroEuu+Mm43Xi43INiE3ApAsnIWmM05Y4HS1NoJhWXL65ZuQiQJxTFe3X9sg5u m8WFZ+3rFF68J6r1NiZhKEg/EBl6UA08Rj4SPEyxXMJMKRwq/D07eh/4GGlydy0wEOVo k/OqZd24Awlwe/VYxNGxwnJ/iUb0SxQYH4N6HR1hjd7e9PXaIgnZ0QNCe/UUMRggbB/K tWZkMfG+DIqbpTBFcwx68eQTkJBXo+g4lwhuK3rW7e5BR6DdaG2fZOadCmGryNdbm8NP nh6w== X-Gm-Message-State: ANhLgQ2ZzLso4ocQGtVV5uryBx6BfEc2rpWCe/lL0doas8l8kGQFL1gT FvbCIMTtffOThYymxpKScjxKhd7L X-Google-Smtp-Source: ADFU+vv8GaTbn2qlZ/ukK2huXDDVaUq8pHLucyiV0amniTfqXnHrdH/kYmEHUMs8xGmIDtn61nbGiQ== X-Received: by 2002:a17:90a:d14d:: with SMTP id t13mr2110008pjw.83.1583804937650; Mon, 09 Mar 2020 18:48:57 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id d6sm723486pjv.38.2020.03.09.18.48.56 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 09 Mar 2020 18:48:57 -0700 (PDT) From: AceLan Kao To: kernel-team@lists.ubuntu.com Subject: [PATCH 7/7][SRU][Focal][Unstable] UBUNTU: SAUCE: r8169: disable ASPM L1.1 Date: Tue, 10 Mar 2020 09:48:36 +0800 Message-Id: <20200310014836.23656-8-acelan.kao@canonical.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200310014836.23656-1-acelan.kao@canonical.com> References: <20200310014836.23656-1-acelan.kao@canonical.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: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" BguLink: https://bugs.launchpad.net/bugs/1836030 r8169 doesn't suport ASPM L1.1, so we don't have to disable ASPM completely. Disable ASPM L1.1 doesn't affect the power consumption and the network function keeps working after S3 test 30 times. Signed-off-by: AceLan Kao --- drivers/net/ethernet/realtek/r8169_main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c index a2cef6a004e7..7613022c344c 100644 --- a/drivers/net/ethernet/realtek/r8169_main.c +++ b/drivers/net/ethernet/realtek/r8169_main.c @@ -7094,8 +7094,7 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) /* 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); + rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L1_1); tp->aspm_manageable = !rc; /* enable device (incl. PCI PM wakeup and hotplug setup) */