From patchwork Thu May 23 20:03:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 10958721 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8D33D924 for ; Thu, 23 May 2019 20:05:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 79E821FF81 for ; Thu, 23 May 2019 20:05:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6BC282855C; Thu, 23 May 2019 20:05:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 113601FF81 for ; Thu, 23 May 2019 20:05:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387497AbfEWUFt (ORCPT ); Thu, 23 May 2019 16:05:49 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:43731 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387455AbfEWUFt (ORCPT ); Thu, 23 May 2019 16:05:49 -0400 Received: by mail-wr1-f65.google.com with SMTP id t7so7289355wrr.10 for ; Thu, 23 May 2019 13:05:48 -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=Kzu+IErrOKTjkX/at7kkRf5eNsPGEAisB7hOvORvAyU=; b=RCdh0RYqWGQrJZJD11U9Nh8vZBbPCgulFCh7jH5dTQgMOO9taP3l6GrXpbJye2nMHr m3ybaKaBSSC7tIJehcnpCTR3IExfO2pTOosYPmnCu/RruluAKQmCheHtyqkZwhWy0MuC 5O3QIddRXmS1ssOfaSNWmpPIKQPr2092cBN2o1LyBKtjiYnn87POvWnaHh8SUpPB1Azy Yy/ji4Hlf2P2zvTcpknp3wiV96Fv4IJzWuwEFNqoEIxebHJ4zQ5eTHf7ac3sfg8HTRay WWjlgaHtPNBJ6Pzfjs3jH5roGWTjrfM9MWu4UtN9Q1iDE0PaAJGcNU3gTJcujS9UOEjM fdZQ== 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=Kzu+IErrOKTjkX/at7kkRf5eNsPGEAisB7hOvORvAyU=; b=DGJEfSZMt8F/nJDg4LU3ZJ3Jfd5LoMAxk2D0viZijRCBxvtjK6NiJ1Y2Voo0hQ7W8g 0ecm2zTCyPIPx1RpgcCOGP7Ly3khJgjUO9CnqHYFlBJBJq+Wei3vyr4qxOAg2wlEdx7O HfvhLuAnw186mvtWwZvsVjlaAaZ/XeBDGUgnceIgWn8NiKrRMcG/wMFQWO50vvQDK4SJ yIZZx4nxO4GHJRY9DPPM7SnQvX3UuxY6s6FWWMxgLPcqCIiOju32GcfLabrkzP/gM7/E l/n3QPmhKI/d0Ro+FMO98lwgfSuER4CJFx0A/JCFvK5zxOo2mbMOglL9fbBIWkAo27ap ONLQ== X-Gm-Message-State: APjAAAUWXCIOjaspKR/4S/nSymrv/jEtNTwcTN+pZ0TUpDXCPRRpgleq Go6AcpLv8lOtSssuaRYZSbeO2L6P X-Google-Smtp-Source: APXvYqxUzbW/XlK7vVoAUgPNbwBILV0YjHUwPUrEACS+5QfMLFVjsej8W+lME//BTW7XND1lLgkoig== X-Received: by 2002:adf:edce:: with SMTP id v14mr55926977wro.94.1558641947165; Thu, 23 May 2019 13:05:47 -0700 (PDT) Received: from ?IPv6:2003:ea:8be9:7a00:3cd1:e8fe:d810:b3f0? (p200300EA8BE97A003CD1E8FED810B3F0.dip0.t-ipconnect.de. [2003:ea:8be9:7a00:3cd1:e8fe:d810:b3f0]) by smtp.googlemail.com with ESMTPSA id f24sm276599wmb.16.2019.05.23.13.05.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 May 2019 13:05:46 -0700 (PDT) Subject: [PATCH 1/3] PCI/ASPM: add L1 sub-state support to pci_disable_link_state From: Heiner Kallweit To: Frederick Lawler , Bjorn Helgaas Cc: "linux-pci@vger.kernel.org" References: <7a6d2f14-f2a6-99ad-3a93-fdaa0726ce86@gmail.com> Message-ID: <6b01bb7d-8ed7-89f0-46e1-5f8a34d68f79@gmail.com> Date: Thu, 23 May 2019 22:03:57 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <7a6d2f14-f2a6-99ad-3a93-fdaa0726ce86@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 X-Virus-Scanned: ClamAV using ClamSMTP Add support for disabling states L1.1 and L1.2 to pci_disable_link_state. Signed-off-by: Heiner Kallweit --- drivers/pci/pcie/aspm.c | 13 ++++++++++--- include/linux/pci-aspm.h | 8 +++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c index fd4cb7508..511f3e018 100644 --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -35,9 +35,9 @@ #define ASPM_STATE_L1_1_PCIPM (0x20) /* PCI PM L1.1 state */ #define ASPM_STATE_L1_2_PCIPM (0x40) /* PCI PM L1.2 state */ #define ASPM_STATE_L1_SS_PCIPM (ASPM_STATE_L1_1_PCIPM | ASPM_STATE_L1_2_PCIPM) +#define ASPM_STATE_L1_1_MASK (ASPM_STATE_L1_1 | ASPM_STATE_L1_1_PCIPM) #define ASPM_STATE_L1_2_MASK (ASPM_STATE_L1_2 | ASPM_STATE_L1_2_PCIPM) -#define ASPM_STATE_L1SS (ASPM_STATE_L1_1 | ASPM_STATE_L1_1_PCIPM |\ - ASPM_STATE_L1_2_MASK) +#define ASPM_STATE_L1SS (ASPM_STATE_L1_1_MASK | ASPM_STATE_L1_2_MASK) #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW) #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1 | \ ASPM_STATE_L1SS) @@ -1094,8 +1094,15 @@ static void __pci_disable_link_state(struct pci_dev *pdev, int state, bool sem) link = parent->link_state; if (state & PCIE_LINK_STATE_L0S) link->aspm_disable |= ASPM_STATE_L0S; - if (state & PCIE_LINK_STATE_L1) + if (state & PCIE_LINK_STATE_L1) { link->aspm_disable |= ASPM_STATE_L1; + /* sub-states require L1 */ + link->aspm_disable |= ASPM_STATE_L1SS; + } + if (state & PCIE_LINK_STATE_L1_1) + link->aspm_disable |= ASPM_STATE_L1_1_MASK; + if (state & PCIE_LINK_STATE_L1_2) + link->aspm_disable |= ASPM_STATE_L1_2_MASK; pcie_config_aspm_link(link, policy_to_aspm_state(link)); if (state & PCIE_LINK_STATE_CLKPM) { diff --git a/include/linux/pci-aspm.h b/include/linux/pci-aspm.h index df28af5ce..e66c3e3d8 100644 --- a/include/linux/pci-aspm.h +++ b/include/linux/pci-aspm.h @@ -19,9 +19,11 @@ #include -#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) #ifdef CONFIG_PCIEASPM void pci_disable_link_state(struct pci_dev *pdev, int state); From patchwork Thu May 23 20:04:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 10958723 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 494CA14B6 for ; Thu, 23 May 2019 20:05:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 36BFC1FF81 for ; Thu, 23 May 2019 20:05:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2A9D52855C; Thu, 23 May 2019 20:05:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C435D1FF81 for ; Thu, 23 May 2019 20:05:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387566AbfEWUFv (ORCPT ); Thu, 23 May 2019 16:05:51 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:53220 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387455AbfEWUFv (ORCPT ); Thu, 23 May 2019 16:05:51 -0400 Received: by mail-wm1-f65.google.com with SMTP id y3so7111134wmm.2 for ; Thu, 23 May 2019 13:05:49 -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=kgoy6MzCDFZksLCgPm3ckOOZ7Ci44vWIX+S6sDXfwtE=; b=uR41fvb8SB92vY5ZwRC/nkNyHDaXEw3e4ZmReN7zM0b4+dfKmztnK/h334o6nVFZbE qzEeBqLbgtH/Sd8bA3VLxKtRxx2Qw6YO6WQbCRV3biCGD+zaeIX0EkgDTiNNwBiKOcAD ahWeunmyVJb//qQmOvgTPNgqf/mX9J4QeUnpuFA8CvQu4kIstE9H+IuFqypKqtrkJbbP OXr8p3weS6+rYwaFHDUuuwT2CtRG7yr4eenP6hw4FkqcVDAEBsBW4lYIX4wq4QG2Hngz AMOtwz10P3BCvhrJsMw1uvJVPapAkiKjdcvCzA6e7UMjSRiDZ/eS7r1Vi0dDANUuME4D UQCg== 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=kgoy6MzCDFZksLCgPm3ckOOZ7Ci44vWIX+S6sDXfwtE=; b=tNKjbd4RU2Sl/UD5WA/XNqT3JwdASDJ5+sUhwu5SCQfSP5+SmyrRXp60fBGowr49OH 0xnrxOcsQSV7vNNCYyRvM+mvdOUqXNIZ2M40q8Y/oRoJtdyPpOjjysHIiLj80Y+1uvPK Yyo/xN3fNzJ7S1KSysNwdAfZvpU37odq63oSmz90zofdvAPA5fIIvQrFJIPamo5LnqNl L9bZce7oW8ego0P8wptrp7gUZ2TQv+2Sw1TU24v7Y8n4U4SrCeKzsMMrssanKXk4w/U0 t3kC9l7iVdOr08AfJhi0N/yO1vxxNzb9ee7nkorFkbRVQzrR67qXl0BCMDemH6Ab/AFV GyIg== X-Gm-Message-State: APjAAAX6k0J8fy6E01eD9pOmW8TjwBtLtqm43tAuyTB/ffFWORa7WVMK CALxbn4rMjuwWCDMxYqquqKkPDm6 X-Google-Smtp-Source: APXvYqz2dDFnXcsGWqpLO9/g9IKzlwyJ3PbEG0awyZY7Su09zrv3zWgvecW+5aB8bAHg5aAS0B9NNA== X-Received: by 2002:a7b:c084:: with SMTP id r4mr12496986wmh.14.1558641948524; Thu, 23 May 2019 13:05:48 -0700 (PDT) Received: from ?IPv6:2003:ea:8be9:7a00:3cd1:e8fe:d810:b3f0? (p200300EA8BE97A003CD1E8FED810B3F0.dip0.t-ipconnect.de. [2003:ea:8be9:7a00:3cd1:e8fe:d810:b3f0]) by smtp.googlemail.com with ESMTPSA id q9sm912738wmq.9.2019.05.23.13.05.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 May 2019 13:05:47 -0700 (PDT) Subject: [PATCH 2/3] PCI/ASPM: allow to re-enable Clock PM From: Heiner Kallweit To: Frederick Lawler , Bjorn Helgaas Cc: "linux-pci@vger.kernel.org" References: <7a6d2f14-f2a6-99ad-3a93-fdaa0726ce86@gmail.com> Message-ID: <02603196-4ca1-789d-f59c-6f172fc69fae@gmail.com> Date: Thu, 23 May 2019 22:04:27 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <7a6d2f14-f2a6-99ad-3a93-fdaa0726ce86@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 X-Virus-Scanned: ClamAV using ClamSMTP 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 511f3e018..7847be38e 100644 --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -65,6 +65,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 */ @@ -162,8 +163,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) @@ -193,7 +197,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) @@ -1105,10 +1110,9 @@ static void __pci_disable_link_state(struct pci_dev *pdev, int state, bool sem) link->aspm_disable |= ASPM_STATE_L1_2_MASK; 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 Thu May 23 20:05:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 10958725 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6C7B7924 for ; Thu, 23 May 2019 20:05:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5A2781FF81 for ; Thu, 23 May 2019 20:05:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4E0412855C; Thu, 23 May 2019 20:05:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9C95C26E3A for ; Thu, 23 May 2019 20:05:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387455AbfEWUFy (ORCPT ); Thu, 23 May 2019 16:05:54 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:38992 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387557AbfEWUFx (ORCPT ); Thu, 23 May 2019 16:05:53 -0400 Received: by mail-wm1-f66.google.com with SMTP id z23so2942505wma.4 for ; Thu, 23 May 2019 13:05:51 -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=zdDlqnYJIlV7gpzNe3dnj/pPwwf1pv/uvt4HC3KkAtc=; b=uxTq0YMQDt/CuQgiOUMiGI2Z+FegRZRmJdnK+sCfpSCkM/BvEoimGnvAUij+GCldqI 4eXZuY7phIaNVb1W+XxDsyJY2jZi3kQyrdzukGX3oDl1z6UWaHQ5OngKoMljX1t7DgZj DCsMbel3GZLQE9onGHJkUUaa3Z7cUaC28Dm3nT6v3TAeZRvjf4ruFWQ7BT128CcREUAU JAdVNGSM1f3RvUJ4TPv+azsS1bDFbV8Bn9hkWPlhm2OclkRHsKJ6mAqABMw7eeYjJuN3 MH/zm9dMEyda4rs0YwXKksa566j5lcKyVhbluVkY5EfB1ZuTE6Ajn+SE5uGgRjuf/kj2 Ivdg== 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=zdDlqnYJIlV7gpzNe3dnj/pPwwf1pv/uvt4HC3KkAtc=; b=rlJFvPhzA6FzjOvsiqvV7hz8pBoJRL4iqwCXg0qaAyQk8lptBddGEmFjWqyt0j61rC u3vup4ynCiHVDhKBTW2R79bCTXem1W2suh7Dh4HpybyJ2ObQeWnkSoRuxl0Cc7RqalZa TcQujdHCIcVLJmioCQrK+8glJ8EXl70DNBUoYnzjAWoPDzwEdQpQs9T8NbFE8XMb5ctA w+V0PqEf5mQJLMMHh/Gfr7Sa4tU036+QxtMO6Z8gafLmCouwgz7h71/ngby6aogmIQS7 yPXwGlYmGCc9faf9ffJirdxiBd5rT7WlEts0B/8Dy8TOYeGHZgqHDRlOH/aguYSheYY+ b9xg== X-Gm-Message-State: APjAAAWIih6XHANwJOxhb8AHDYLxHsL1Bt6twBLeLy0WRs7pNr5n4MDv I268zhAbfAd5hsYTPbPhbkiXJL5P X-Google-Smtp-Source: APXvYqzn7Psa8ux4+buHtEelV3qhWGzoCllXIKKkXYyPdQebfm+EvoM2LBixa9hZaYeU6/pD62W5CA== X-Received: by 2002:a1c:7503:: with SMTP id o3mr13831589wmc.28.1558641950088; Thu, 23 May 2019 13:05:50 -0700 (PDT) Received: from ?IPv6:2003:ea:8be9:7a00:3cd1:e8fe:d810:b3f0? (p200300EA8BE97A003CD1E8FED810B3F0.dip0.t-ipconnect.de. [2003:ea:8be9:7a00:3cd1:e8fe:d810:b3f0]) by smtp.googlemail.com with ESMTPSA id p8sm406699wro.0.2019.05.23.13.05.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 May 2019 13:05:49 -0700 (PDT) Subject: [PATCH 3/3] PCI/ASPM: add sysfs attribute for controlling ASPM From: Heiner Kallweit To: Frederick Lawler , Bjorn Helgaas Cc: "linux-pci@vger.kernel.org" References: <7a6d2f14-f2a6-99ad-3a93-fdaa0726ce86@gmail.com> Message-ID: Date: Thu, 23 May 2019 22:05:35 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <7a6d2f14-f2a6-99ad-3a93-fdaa0726ce86@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 X-Virus-Scanned: ClamAV using ClamSMTP 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 attribute users can control which ASPM link-states are enabled/disabled. Signed-off-by: Heiner Kallweit --- Documentation/ABI/testing/sysfs-bus-pci | 13 ++ drivers/pci/pci.h | 8 +- drivers/pci/pcie/aspm.c | 180 +++++++++++++++++++++++- 3 files changed, 193 insertions(+), 8 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-bus-pci b/Documentation/ABI/testing/sysfs-bus-pci index 8bfee557e..38fe358de 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/.../power/aspm_link_states +Date: May 2019 +Contact: Heiner Kallweit +Description: + If ASPM is supported for an endpoint, then this file can be + used to enable / disable link states. A link state + displayed in brackets is enabled, otherwise it's disabled. + To control link states (case insensitive): + +state : enables a supported state + -state : disables a state + none : disables all link states + all : enables all supported link states diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 9cb99380c..06642b7de 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -499,17 +499,13 @@ 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 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_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) { } -#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 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c index 7847be38e..f3822accb 100644 --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -42,6 +42,8 @@ #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1 | \ ASPM_STATE_L1SS) +static const char power_group[] = "power"; + struct aspm_latency { u32 l0s; /* L0s latency (nsec) */ u32 l1; /* L1 latency (nsec) */ @@ -1251,38 +1253,212 @@ static ssize_t clk_ctl_store(struct device *dev, static DEVICE_ATTR_RW(link_state); static DEVICE_ATTR_RW(clk_ctl); +#endif + +struct aspm_sysfs_state { + const char *name; + int mask; +}; + +static const struct aspm_sysfs_state aspm_sysfs_states[] = { + { "L0S", ASPM_STATE_L0S }, + { "L1", ASPM_STATE_L1 }, + { "L1.1", ASPM_STATE_L1_1_MASK }, + { "L1.2", ASPM_STATE_L1_2_MASK }, +}; + +static struct pcie_link_state *aspm_get_parent_link(struct pci_dev *pdev) +{ + struct pci_dev *parent = pdev->bus->self; + + if (pdev->has_secondary_link) + parent = pdev; + + return parent ? parent->link_state : NULL; +} + +static bool pcie_check_aspm_endpoint(struct pci_dev *pdev) +{ + struct pcie_link_state *link; + + if (pci_pcie_type(pdev) != PCI_EXP_TYPE_ENDPOINT) + return false; + + link = aspm_get_parent_link(pdev); + + return link && link->aspm_support; +} + +static ssize_t aspm_link_states_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct pci_dev *pdev = to_pci_dev(dev); + struct pcie_link_state *link; + int len = 0, i; + + link = aspm_get_parent_link(pdev); + if (!link) + return -EOPNOTSUPP; + + mutex_lock(&aspm_lock); + + for (i = 0; i < ARRAY_SIZE(aspm_sysfs_states); i++) { + const struct aspm_sysfs_state *st = aspm_sysfs_states + i; + + if (link->aspm_enabled & st->mask) + len += scnprintf(buf + len, PAGE_SIZE - len, "[%s] ", + st->name); + else + len += scnprintf(buf + len, PAGE_SIZE - len, "%s ", + st->name); + } + + if (link->clkpm_enabled) + len += scnprintf(buf + len, PAGE_SIZE - len, "[CLKPM] "); + else + len += scnprintf(buf + len, PAGE_SIZE - len, "CLKPM "); + + mutex_unlock(&aspm_lock); + + len += scnprintf(buf + len, PAGE_SIZE - len, "\n"); + + return len; +} + +static ssize_t aspm_link_states_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; + char *buftmp = (char *)buf, *tok; + unsigned int disable_aspm, disable_clkpm; + bool first = true, add; + int err = 0, i; + + if (aspm_disabled) + return -EPERM; + + link = aspm_get_parent_link(pdev); + if (!link) + return -EOPNOTSUPP; + + down_read(&pci_bus_sem); + mutex_lock(&aspm_lock); + + disable_aspm = link->aspm_disable; + disable_clkpm = link->clkpm_disable; + + while ((tok = strsep(&buftmp, " \n")) != NULL) { + bool found = false; + + if (!*tok) + continue; + + if (first) { + if (!strcasecmp(tok, "none")) { + disable_aspm = ASPM_STATE_ALL; + disable_clkpm = 1; + break; + } + if (!strcasecmp(tok, "all")) { + disable_aspm = 0; + disable_clkpm = 0; + break; + } + first = false; + } + + if (*tok != '+' && *tok != '-') { + err = -EINVAL; + goto out; + } + + add = *tok++ == '+'; + + for (i = 0; i < ARRAY_SIZE(aspm_sysfs_states); i++) { + const struct aspm_sysfs_state *st = + aspm_sysfs_states + i; + + if (!strcasecmp(tok, st->name)) { + if (add) + disable_aspm &= ~st->mask; + else + disable_aspm |= st->mask; + found = true; + break; + } + } + + if (!found && !strcasecmp(tok, "clkpm")) { + disable_clkpm = add ? 0 : 1; + found = true; + } + + if (!found) { + err = -EINVAL; + goto out; + } + } + + if (disable_aspm & ASPM_STATE_L1) + disable_aspm |= ASPM_STATE_L1SS; + + link->aspm_disable = disable_aspm; + link->clkpm_disable = disable_clkpm; + + pcie_config_aspm_link(link, policy_to_aspm_state(link)); + pcie_set_clkpm(link, policy_to_clkpm_state(link)); +out: + mutex_unlock(&aspm_lock); + up_read(&pci_bus_sem); + + return err ?: len; +} + +static DEVICE_ATTR_RW(aspm_link_states); -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 (pcie_check_aspm_endpoint(pdev)) + sysfs_add_file_to_group(&pdev->dev.kobj, + &dev_attr_aspm_link_states.attr, power_group); + if (!link_state) return; +#ifdef CONFIG_PCIEASPM_DEBUG 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); +#endif } void pcie_aspm_remove_sysfs_dev_files(struct pci_dev *pdev) { struct pcie_link_state *link_state = pdev->link_state; + if (pcie_check_aspm_endpoint(pdev)) + sysfs_remove_file_from_group(&pdev->dev.kobj, + &dev_attr_aspm_link_states.attr, power_group); + if (!link_state) return; +#ifdef CONFIG_PCIEASPM_DEBUG 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 int __init pcie_aspm_disable(char *str) {