From patchwork Tue Oct 1 19:16:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 11169501 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0DF1B1920 for ; Tue, 1 Oct 2019 19:19:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E094321855 for ; Tue, 1 Oct 2019 19:19:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Q2dLu8yi" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726458AbfJATTK (ORCPT ); Tue, 1 Oct 2019 15:19:10 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:36418 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726509AbfJATTK (ORCPT ); Tue, 1 Oct 2019 15:19:10 -0400 Received: by mail-wr1-f66.google.com with SMTP id y19so16877979wrd.3 for ; Tue, 01 Oct 2019 12:19:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=wBJD05NJvs43JSkNpE6CAGqMMhHik5oVKM6ZCLNUQNM=; b=Q2dLu8yiAbNzKFXG1hyMOR/u8Gxn5HmfJkRX+xgZtfA2Pn+9qm6ubTeuqztRdOv975 X/4dvds44Xe+tlrMrLdNHU4D8ZQIKToGz5eFyYAUuhYC0kP+I5QODHCgZHsDHdq9bWM7 PKDT+ZMJzjwM7KXMpsscGCp3udRKVF4rEzN6O4H22J53Q/f0wY5Xa+vBTB0mazqBImXQ gZXM8A5x9Vrw27KW86Np2Ec6OCyC59c+x48iXxLWfctImhFWB2VSOUO5YXMA76K/dR2p KbkeR/pL/zdLwFdw7+QeD5jmWdzA/auI+sWGb1OKKJ/9jOtCyZHq4xnX6E8yBFIJIpUJ O7Nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=wBJD05NJvs43JSkNpE6CAGqMMhHik5oVKM6ZCLNUQNM=; b=hwDPRi8KFIWXewyumb4lHXeBox2ixmWNoMqGylqgcqXQ4HcG6pSpIPMi3mfTfFTqqM hFV7gCm7f0/bogUxqlawiboucfNwbz8w3iCT53oNVSU4V3Sb/xn/tHv3j5jUHOxGmOGG 2OKgSBmGaH/PCJ50tsAj9Esi3G+qkOL46pepWRPNzOxNsAzQQuHq4Tt7uRXkjAcz0KjQ vxr4aXRtc8nQfrxHH19TbAAPnG4oXPYJjvkG1z1Ahf/t18zJmLWbRdjS4SDX7kEUPVcm 5nBItDENmHK538VC3pGbTCY8ECafQbPMmkr4hJEk239Hww9ekFfjhpx5hbxxSjn5MdO8 RudA== X-Gm-Message-State: APjAAAU7bnbZEogxKM/o8KL2tph2vR+k0yRpUBjRODJeeQXnhaZwLHLe Uk2NRxxhAfisMWcJIBKRijIg3hMU X-Google-Smtp-Source: APXvYqyUg01jqa1vICxSAXLOraJMSwa5cP+8KGk/qn3ctNhxE4T1nqr+KmBkWQLWv//5/lYah7Us6w== X-Received: by 2002:adf:ce83:: with SMTP id r3mr162617wrn.219.1569957548020; Tue, 01 Oct 2019 12:19:08 -0700 (PDT) Received: from ?IPv6:2003:ea:8f26:6400:ad11:16fb:d8da:de15? (p200300EA8F266400AD1116FBD8DADE15.dip0.t-ipconnect.de. [2003:ea:8f26:6400:ad11:16fb:d8da:de15]) by smtp.googlemail.com with ESMTPSA id o188sm8450183wma.14.2019.10.01.12.19.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Oct 2019 12:19:07 -0700 (PDT) Subject: [PATCH v6 1/4] PCI/ASPM: Add L1 PM Substate support to pci_disable_link_state From: Heiner Kallweit To: Frederick Lawler , Bjorn Helgaas , Greg KH , Rajat Jain Cc: "linux-pci@vger.kernel.org" References: <0577b966-6290-0685-123d-c675baf97caa@gmail.com> Message-ID: Date: Tue, 1 Oct 2019 21:16:50 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <0577b966-6290-0685-123d-c675baf97caa@gmail.com> Content-Language: en-US Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Add support for disabling states L1.1 and L1.2 to pci_disable_link_state(). Allow separate control of ASPM and PCI PM L1 sub-states. Signed-off-by: Heiner Kallweit --- v2: - allow separate control of ASPM and PCI PM L1 sub-states --- 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 652ef23bb..ed463339e 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; + /* sub-states 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 f9088c89a..9dc5bee14 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 Oct 1 19:17:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 11169503 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8849E1599 for ; Tue, 1 Oct 2019 19:19:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 660BF21855 for ; Tue, 1 Oct 2019 19:19:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RJAz6UJt" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726509AbfJATTK (ORCPT ); Tue, 1 Oct 2019 15:19:10 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:36421 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726180AbfJATTK (ORCPT ); Tue, 1 Oct 2019 15:19:10 -0400 Received: by mail-wr1-f67.google.com with SMTP id y19so16878027wrd.3 for ; Tue, 01 Oct 2019 12:19:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=XLEDj7lJ59wa9ec0V3EX//kc9AMcwJTkEP5jkJV1YK4=; b=RJAz6UJtrVJ5cVEpzehQL3R8A9GzE3jsEfxeKwywrI70xkNnKb9pb+ghSZ+WWCb0bD GWyBAUEpspPucE2/H5V9p2F1xctLIW7Yn9g/CcH+QmJhnuZhMfNvQSnREsnxWBbZ7aPe OSZhfuPUit59tO70njdUi6KA5M34002pqycrfFvJEn//aIk5b3tlz+hMQESJ8xiDJvGd SABhXinpkSetEhtuQOosuypHFMN2xWlrbLQ0Jft/EXCFKaekkUQPn/tP5tFhZyrOhPKm iRHZ54CK+dSXSepuRiNaHkI1l0ZP/JhPSSQTHDIDunm+l33EyePD2IYQyjUIVsYlsQv5 Uk1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=XLEDj7lJ59wa9ec0V3EX//kc9AMcwJTkEP5jkJV1YK4=; b=uatS4or3FzP5S0WXRquPD9lkGPrEdE0xHvjENso+3zdeREMXUnIsU0sq8CWyFcv9HX O9uwB5UzWV1LIAjDwmwC/ARzQ1YxCEhK0hoh1iWBQV1/O+lLDM66Lowm1tNQURpS2lpw ylOfFjJXNYeJ+XwbVY+ItdlMER3b8FwzMpIHtkZrZ9iF3JGiUvho8X+ZPT/zCbvMf6tF q2ZYGUbER+RP7J44QpnVcoj75UH+ZBL7bt8UWLmuSZa3b68frbq4YMmpWENDrytvPmtZ zyTXeZ/rEE0Pk3R/PBl+8Ce7219d+2MzUAf9IjdjfFvVQFaPpmpWy1NekUMuJz+Tyb6U g+KA== X-Gm-Message-State: APjAAAUmcDWFEcOzv6Mqm5IKm7XDv7uCPE+hyJyA/X9DAQ2SObUPrrlt 9qpPGye8Rxs+p52VR8IQ7ER6oa7L X-Google-Smtp-Source: APXvYqxQgfVHYBuyH/E+mKYpAU1200WhIaq3prm1svQFXzeasuy/vXHU85jcqPH5DIV1i1aXd/p2zQ== X-Received: by 2002:adf:cd81:: with SMTP id q1mr20117730wrj.185.1569957549151; Tue, 01 Oct 2019 12:19:09 -0700 (PDT) Received: from ?IPv6:2003:ea:8f26:6400:ad11:16fb:d8da:de15? (p200300EA8F266400AD1116FBD8DADE15.dip0.t-ipconnect.de. [2003:ea:8f26:6400:ad11:16fb:d8da:de15]) by smtp.googlemail.com with ESMTPSA id p85sm5661597wme.23.2019.10.01.12.19.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Oct 2019 12:19:08 -0700 (PDT) Subject: [PATCH v6 2/4] PCI/ASPM: Allow to re-enable Clock PM From: Heiner Kallweit To: Frederick Lawler , Bjorn Helgaas , Greg KH , Rajat Jain Cc: "linux-pci@vger.kernel.org" References: <0577b966-6290-0685-123d-c675baf97caa@gmail.com> Message-ID: <2dc07439-034d-0781-0f62-578ca39f81c4@gmail.com> Date: Tue, 1 Oct 2019 21:17:22 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <0577b966-6290-0685-123d-c675baf97caa@gmail.com> Content-Language: en-US Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org So far Clock PM can't be re-enabled once it has been disabled with a call to pci_disable_link_state(). Reason is that clkpm_capable is reset. Change this by adding a clkpm_disable field similar to aspm_disable. Signed-off-by: Heiner Kallweit --- 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 ed463339e..574f822bf 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 Oct 1 19:18:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 11169507 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ABAB014DB for ; Tue, 1 Oct 2019 19:19:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7506121855 for ; Tue, 1 Oct 2019 19:19:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kk7sRPfr" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726492AbfJATTQ (ORCPT ); Tue, 1 Oct 2019 15:19:16 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:39418 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726526AbfJATTP (ORCPT ); Tue, 1 Oct 2019 15:19:15 -0400 Received: by mail-wr1-f68.google.com with SMTP id r3so16884348wrj.6 for ; Tue, 01 Oct 2019 12:19:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=qTEVgOVACCDBR7OeQb4v4rJNPYXOEZWQLWzy0f/scJQ=; b=kk7sRPfrlW+p4+wk815EYqnqQ75jvoYMHU0EOE1l3y7bDFodThrUVYWqhzaK0G7ui+ 7RHuofuX7qo4UnI+W+P7h4/gG8HG06cJtvplOTc0dP6lx90K1uZ1ILXGabLVzq5UXesF wS9XGHArck+4N5rbFNUBi5m+FpTwRQL+bYiOJLlyjDGimz1vix2cCFDrOnWtGDh7w0D9 tUz8LGtT+CX9wyLwcKrpCj0JdceaxOONdzUma7JmDHRtJ2GtEfCT76dTe3MZuyQP8qfk Z5HAR12ZX0MZESRIOkz+0H2W8dRHc00ZFtWTuBRORTCAb+4dos/NGRFD798y6yKWBamt 16tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=qTEVgOVACCDBR7OeQb4v4rJNPYXOEZWQLWzy0f/scJQ=; b=IagHBqDA+5lhl0BiPE7npRK9/ju6x6yLBKKKC9sj3uwDkbkG4XKtTAwO06+sXhSnW6 DB3iNpKJdNQG0ZT0FbaFl0ckCcgTD4bF9ptBbFGuZyl0RDO+G4Oz50br5jq4ceXFTjbI F2cTWsuLMgRt5GBVb2Iqs12rdY9500zx82nLpDEPjE0WcisGdIqWfVWXH10sB4Ni4+rp 14mXy11UfhygUnf5niob8DIFFAFcd7X6ZrNr1fjnu5yvfoRbUB7yrqt58lC/k47nwYgI VvnTwWZcNgorYeP4CmZxKMU3z1nxPjLuWAOWNHrCcClQ/hhgaAYYNQf/tSvlBHGBdWyG uESg== X-Gm-Message-State: APjAAAUHR2TjjoqeEo+x+w6620S0mDS7OcmM4ZQTI5lERXC60rFs5MV+ u0TPlRklrOp4djNCSyRcOX6FWL09 X-Google-Smtp-Source: APXvYqw2IICNt/Hp5SexM9L8A5LmtgkNBVRXRt1JcFtXaXWE/jG/kdVvBpd2rVl5nD86XphAB52+xg== X-Received: by 2002:adf:b1da:: with SMTP id r26mr1772806wra.244.1569957550236; Tue, 01 Oct 2019 12:19:10 -0700 (PDT) Received: from ?IPv6:2003:ea:8f26:6400:ad11:16fb:d8da:de15? (p200300EA8F266400AD1116FBD8DADE15.dip0.t-ipconnect.de. [2003:ea:8f26:6400:ad11:16fb:d8da:de15]) by smtp.googlemail.com with ESMTPSA id 3sm4854200wmo.22.2019.10.01.12.19.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Oct 2019 12:19:09 -0700 (PDT) Subject: [PATCH v6 3/4] PCI/ASPM: Add sysfs attributes for controlling ASPM link states From: Heiner Kallweit To: Frederick Lawler , Bjorn Helgaas , Greg KH , Rajat Jain Cc: "linux-pci@vger.kernel.org" References: <0577b966-6290-0685-123d-c675baf97caa@gmail.com> Message-ID: <09214ca2-422d-45e7-9020-99f66e2ca869@gmail.com> Date: Tue, 1 Oct 2019 21:18:06 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <0577b966-6290-0685-123d-c675baf97caa@gmail.com> Content-Language: en-US Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Background of this extension is a problem with the r8169 network driver. Several combinations of board chipsets and network chip versions have problems if ASPM is enabled, therefore we have to disable ASPM per default. However especially on notebooks ASPM can provide significant power-saving, therefore we want to give users the option to enable ASPM. With the new sysfs attributes users can control which ASPM link-states are enabled/disabled. Signed-off-by: Heiner Kallweit --- v2: - use a dedicated sysfs attribute per link state - allow separate control of ASPM and PCI PM L1 sub-states v3: - statically allocate the attribute group - replace snprintf with printf - base on top of "PCI: Make pcie_downstream_port() available outside of access.c" v4: - add call to sysfs_update_group because is_visible callback returns false always at file creation time - simplify code a little v5: - rebased to latest pci/next v6: - fix style of added documentation and extend it - don't use term "parent" and rename function to pcie_aspm_get_link - rename pcie_check_valid_aspm_endpoint to pcie_is_aspm_dev - enable the sysfs files also selected other port types - avoid usage of !! --- Documentation/ABI/testing/sysfs-bus-pci | 14 ++ drivers/pci/pci-sysfs.c | 7 + drivers/pci/pci.h | 4 + drivers/pci/pcie/aspm.c | 194 ++++++++++++++++++++++++ 4 files changed, 219 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-bus-pci b/Documentation/ABI/testing/sysfs-bus-pci index 8bfee557e..9aabe8bbf 100644 --- a/Documentation/ABI/testing/sysfs-bus-pci +++ b/Documentation/ABI/testing/sysfs-bus-pci @@ -347,3 +347,17 @@ 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/.../aspm/aspm_l0s + /sys/bus/pci/devices/.../aspm/aspm_l1 + /sys/bus/pci/devices/.../aspm/aspm_l1_1 + /sys/bus/pci/devices/.../aspm/aspm_l1_2 + /sys/bus/pci/devices/.../aspm/aspm_l1_1_pcipm + /sys/bus/pci/devices/.../aspm/aspm_l1_2_pcipm + /sys/bus/pci/devices/.../aspm/aspm_clkpm +Date: September 2019 +Contact: Heiner Kallweit +Description: If ASPM is supported for an endpoint, then 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 793412954..26e36b0d0 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -1331,6 +1331,10 @@ static int pci_create_capabilities_sysfs(struct pci_dev *dev) pcie_vpd_create_sysfs_dev_files(dev); pcie_aspm_create_sysfs_dev_files(dev); +#ifdef CONFIG_PCIEASPM + /* update visibility of attributes in this group */ + sysfs_update_group(&dev->dev.kobj, &aspm_ctrl_attr_group); +#endif if (dev->reset_fn) { retval = device_create_file(&dev->dev, &dev_attr_reset); @@ -1587,6 +1591,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 3f6947ee3..b2cd21e8c 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -667,4 +667,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 574f822bf..58c0b069d 100644 --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -1182,6 +1182,18 @@ static int pcie_aspm_get_policy(char *buffer, const struct kernel_param *kp) module_param_call(policy, pcie_aspm_set_policy, pcie_aspm_get_policy, NULL, 0644); +static struct pcie_link_state *pcie_aspm_get_link(struct pci_dev *pdev) +{ + struct pci_dev *upstream; + + if (pcie_downstream_port(pdev)) + upstream = pdev; + else + upstream = pci_upstream_bridge(pdev); + + return upstream ? upstream->link_state : NULL; +} + /** * pcie_aspm_enabled - Check if PCIe ASPM has been enabled for a device. * @pdev: Target device. @@ -1307,6 +1319,188 @@ void pcie_aspm_remove_sysfs_dev_files(struct pci_dev *pdev) } #endif +static bool pcie_is_aspm_dev(struct pci_dev *pdev) +{ + struct pcie_link_state *link; + + if (!pci_is_pcie(pdev)) + return false; + + switch (pci_pcie_type(pdev)) { + case PCI_EXP_TYPE_ENDPOINT: + case PCI_EXP_TYPE_LEG_END: + case PCI_EXP_TYPE_UPSTREAM: + case PCI_EXP_TYPE_PCI_BRIDGE: + case PCI_EXP_TYPE_PCIE_BRIDGE: + link = pcie_aspm_get_link(pdev); + return link && link->aspm_capable; + default: + return false; + } +} + +static ssize_t aspm_attr_show_common(struct device *dev, + struct device_attribute *attr, + char *buf, int state) +{ + struct pci_dev *pdev = to_pci_dev(dev); + struct pcie_link_state *link; + bool enabled; + + link = pcie_aspm_get_link(pdev); + if (!link) + return -EOPNOTSUPP; + + mutex_lock(&aspm_lock); + enabled = link->aspm_enabled & state; + mutex_unlock(&aspm_lock); + + return sprintf(buf, "%d\n", enabled ? 1 : 0); +} + +static ssize_t aspm_attr_store_common(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len, int state) +{ + struct pci_dev *pdev = to_pci_dev(dev); + struct pcie_link_state *link; + bool state_enable; + + if (aspm_disabled) + return -EPERM; + + link = pcie_aspm_get_link(pdev); + if (!link) + return -EOPNOTSUPP; + + if (!(link->aspm_capable & state)) + return -EOPNOTSUPP; + + 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 sub-states */ + 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 aspm_##_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 aspm_##_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, L0S) +ASPM_ATTR(l1, L1) +ASPM_ATTR(l1_1, L1_1) +ASPM_ATTR(l1_2, L1_2) +ASPM_ATTR(l1_1_pcipm, L1_1_PCIPM) +ASPM_ATTR(l1_2_pcipm, L1_2_PCIPM) + +static ssize_t aspm_clkpm_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct pci_dev *pdev = to_pci_dev(dev); + struct pcie_link_state *link; + int val; + + link = pcie_aspm_get_link(pdev); + if (!link) + return -EOPNOTSUPP; + + mutex_lock(&aspm_lock); + val = link->clkpm_enabled; + mutex_unlock(&aspm_lock); + + return sprintf(buf, "%d\n", val); +} + +static ssize_t aspm_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; + bool state_enable; + + if (aspm_disabled) + return -EPERM; + + link = pcie_aspm_get_link(pdev); + if (!link) + return -EOPNOTSUPP; + + if (!link->clkpm_capable) + return -EOPNOTSUPP; + + 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(aspm_l0s); +static DEVICE_ATTR_RW(aspm_l1); +static DEVICE_ATTR_RW(aspm_l1_1); +static DEVICE_ATTR_RW(aspm_l1_2); +static DEVICE_ATTR_RW(aspm_l1_1_pcipm); +static DEVICE_ATTR_RW(aspm_l1_2_pcipm); +static DEVICE_ATTR_RW(aspm_clkpm); + +static struct attribute *aspm_ctrl_attrs[] = { + &dev_attr_aspm_l0s.attr, + &dev_attr_aspm_l1.attr, + &dev_attr_aspm_l1_1.attr, + &dev_attr_aspm_l1_2.attr, + &dev_attr_aspm_l1_1_pcipm.attr, + &dev_attr_aspm_l1_2_pcipm.attr, + &dev_attr_aspm_clkpm.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); + + return pcie_is_aspm_dev(pdev) ? a->mode : 0; +} + +const struct attribute_group aspm_ctrl_attr_group = { + .name = "aspm", + .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 Oct 1 19:18:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 11169505 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5B65914DB for ; Tue, 1 Oct 2019 19:19:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2DEBF2133F for ; Tue, 1 Oct 2019 19:19:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="H3yXaDvr" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726698AbfJATTO (ORCPT ); Tue, 1 Oct 2019 15:19:14 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:34040 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726180AbfJATTO (ORCPT ); Tue, 1 Oct 2019 15:19:14 -0400 Received: by mail-wm1-f67.google.com with SMTP id y135so3241533wmc.1 for ; Tue, 01 Oct 2019 12:19:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=sBpHlPHDs+05No6H7Sh8xOzzLeAhinV3oAGF4G0X5s4=; b=H3yXaDvrv6RYvQnReTs+weWw+NAwamv5dQTi35I7RZ55U82Vi6wESpmS14UBLqeaAT lqaePmlX4WALJULgYjfmzVTitMFTbaua43iJFjs6RDc1ammNPKcPTqddRJNNnBqG2RJc LImK3cpvnWHnR+FWnF4T7OBlDl59nz5Pbt1or062XVef4bz1qV61A4R1jiBZuYRCzDPW OlF1EnaUUKYZkVZwuTrTNheYf9FEZEGeue0XNIIelbgeggr5n+Xqkw0Ecxnl9bBknKMg YqGNgoiQMS0GMGsjZzHieD9P5y5Q8Ddm9BLT4DMrocoGc1nPjDjt0JYgJvfXNZf7gJJ/ QNDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=sBpHlPHDs+05No6H7Sh8xOzzLeAhinV3oAGF4G0X5s4=; b=c+fD6xC9l0yJUlKvAsn6ZCo5JLjiwRVCvRiIjxzC3a3gU6crvHx7hhAecAtnsb04DQ HFJiEK1nMiFZgee8W2a0yym++uSlnjxQV5vCnrPoeTQlVMZiN6PZb/uAcgAzKfiwB1NR AAxt/HMtvb75+VZR+TKmZUR4TeNfYMOgy2YTze+du3T53knIqREc/TZ2Z/WDXZ3lRBhO u66TxMRn+dIFFnhyu60EIwwgiT9DXXtFYYS99GvP1RB6dyENXFCDqpLhDRdNtS0GbIHf ub+0QW/b0hIUt1EySy7DTWR/0HFxcubdKdMHnMSzjCw8F8UdwmLREb/seATjOqiW+QFT M/Sw== X-Gm-Message-State: APjAAAX3mnFnBlxRYvhSi2u3KgJoh7Ev/F9/vvXLorOMVQ5lOWQxLAs+ SZu56VIFTqNCmq8BnbUkLKyHfssB X-Google-Smtp-Source: APXvYqwBu54q1qmbbv+xjJNb4d89DGHiL3V/vBsffpGqXp68sQFAC/gLuUgwzTRaTCbLjcjVN/9idg== X-Received: by 2002:a1c:5fd6:: with SMTP id t205mr4965183wmb.124.1569957551286; Tue, 01 Oct 2019 12:19:11 -0700 (PDT) Received: from ?IPv6:2003:ea:8f26:6400:ad11:16fb:d8da:de15? (p200300EA8F266400AD1116FBD8DADE15.dip0.t-ipconnect.de. [2003:ea:8f26:6400:ad11:16fb:d8da:de15]) by smtp.googlemail.com with ESMTPSA id w125sm7634589wmg.32.2019.10.01.12.19.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Oct 2019 12:19:10 -0700 (PDT) Subject: [PATCH v6 4/4] PCI/ASPM: Remove Kconfig option PCIEASPM_DEBUG and related code From: Heiner Kallweit To: Frederick Lawler , Bjorn Helgaas , Greg KH , Rajat Jain Cc: "linux-pci@vger.kernel.org" References: <0577b966-6290-0685-123d-c675baf97caa@gmail.com> Message-ID: <3a0eded8-9d36-2fa8-d665-96b1df880be2@gmail.com> Date: Tue, 1 Oct 2019 21:18:54 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <0577b966-6290-0685-123d-c675baf97caa@gmail.com> Content-Language: en-US Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Now that we have sysfs attributes for enabling/disabling the individual ASPM link states, this debug code isn't needed any longer. Removing this debug code has been discussed for quite some time, see e.g. [0]. [0] https://lore.kernel.org/lkml/20180727202619.GD173328@bhelgaas-glaptop.roam.corp.google.com/ Signed-off-by: Heiner Kallweit --- v6: - add discussion link to commit message --- 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 26e36b0d0..8657cdf62 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); #ifdef CONFIG_PCIEASPM /* update visibility of attributes in this group */ sysfs_update_group(&dev->dev.kobj, &aspm_ctrl_attr_group); @@ -1344,7 +1343,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; } @@ -1420,7 +1418,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 b2cd21e8c..ae231e3cd 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -541,14 +541,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 362eb8cfa..a2e862d4e 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 58c0b069d..81510eae5 100644 --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -1214,111 +1214,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 bool pcie_is_aspm_dev(struct pci_dev *pdev) { struct pcie_link_state *link;