From patchwork Sat Aug 31 20:15:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 11125009 X-Patchwork-Delegate: bhelgaas@google.com 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 2BDA614DE for ; Sat, 31 Aug 2019 20:21:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F279623407 for ; Sat, 31 Aug 2019 20:21:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Os/QglKs" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728517AbfHaUVO (ORCPT ); Sat, 31 Aug 2019 16:21:14 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:40831 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726328AbfHaUVO (ORCPT ); Sat, 31 Aug 2019 16:21:14 -0400 Received: by mail-wm1-f66.google.com with SMTP id t9so10816542wmi.5 for ; Sat, 31 Aug 2019 13:21: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=BiNwWT0M1OAy06tKN+bdr+MkdmbD4pT3atZheplZ5JA=; b=Os/QglKstOeNdN/bWZ/naaa43JTlGch3XxTV8AhcWHGMx4WFJOM92xmome6OFKEG7K a7H1rkVBksZGR/SGMrdpV/7CyQkBqgOdk6ZMgJgN497jtvjp2S353Gcee79kkEIbkUQ6 olWzz1Y/+/Xx9vstW1B0ujJ0dM+ce5SeluDOUjz0fy8V8p3vF2z7Ba4mgZ3IjuiMUY29 XsTNONDMF3f41XUOYSBAHSsRMZ5OBiY+2wW7lF6LlcQEoWLA61ooQi53+W2xsFYk81px AjxQ2N4CyQfPVqkQXnXdnQ8sRq60s/tdc2LDS3OSQv2c2oHAyDLbKLGc/7uzkZPxUs4z cb8A== 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=BiNwWT0M1OAy06tKN+bdr+MkdmbD4pT3atZheplZ5JA=; b=ilZY75mY4wQUwVosZK3Uxiw/YibsyNDB7d3N1nXW/ACl/+iFfbv35zyltEhHD+UvW4 jXHMCEIjXHAiViFHsayKcGieZIH1U4ZEzXczSlnwopwaMQ0wsKX+dkGtmD9nemgxE4xk gDxRbbj8QQHDzV8QcUZB5w1CqFoiXO0X1L12MVEgvCKu6F9cCwv9BMDAu3hwXCNZVHOw RL1SCLudDJXT94OQBCb4HXojuFsWK1+a4AuodBi38hM9xzNnn2xPjknC9HnvEjcc7Gfe 68DbyczqzONbnOgBmF4G/2yfB2zIqweMRRVdSt2Bqoa65BHlf38pHkqQqvRjqqcLQmDS nKEg== X-Gm-Message-State: APjAAAVrVq+D2ejCnY1yYDqYhM1WTNSbP3CS/Lg7u+lNNwAvSrd1283d 8gXdeSjlU5YT8E7HbpDVpxbB8H+X X-Google-Smtp-Source: APXvYqyqhJCvKm8EH9IU82cCNKjWJjxEhsY2oLyJWFgLjT2ET3Dp9S8YJYvYTneFg8T31bGiXbLPIA== X-Received: by 2002:a1c:5451:: with SMTP id p17mr21366607wmi.103.1567282871883; Sat, 31 Aug 2019 13:21:11 -0700 (PDT) Received: from ?IPv6:2003:ea:8f04:7c00:9586:e556:3a4d:c04? (p200300EA8F047C009586E5563A4D0C04.dip0.t-ipconnect.de. [2003:ea:8f04:7c00:9586:e556:3a4d:c04]) by smtp.googlemail.com with ESMTPSA id d1sm10543625wrs.71.2019.08.31.13.21.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 31 Aug 2019 13:21:11 -0700 (PDT) Subject: [PATCH v5 1/4] PCI/ASPM: add L1 sub-state 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: Message-ID: <18f323f1-89a9-f624-1cef-a226e257b69a@gmail.com> Date: Sat, 31 Aug 2019 22:15:23 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: 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 v5: - rebased to latest pci/next --- 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 ad6259ec5..6de7a597a 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 67303262f..054345eed 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1553,9 +1553,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 Sat Aug 31 20:16:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 11125011 X-Patchwork-Delegate: bhelgaas@google.com 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 4CBCC14DE for ; Sat, 31 Aug 2019 20:21:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 27D6F23407 for ; Sat, 31 Aug 2019 20:21:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mLlQqVbF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728534AbfHaUVP (ORCPT ); Sat, 31 Aug 2019 16:21:15 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:38253 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728512AbfHaUVP (ORCPT ); Sat, 31 Aug 2019 16:21:15 -0400 Received: by mail-wm1-f68.google.com with SMTP id o184so10825010wme.3 for ; Sat, 31 Aug 2019 13:21:14 -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=QwI7vXDYlvIApsTBwHQIWtgOUS8kocR7BXXXZ5uchHI=; b=mLlQqVbFxMiusHHQ9jn9pTJRf0ovE40puaOy1oRPxIH8ZG8wPqoIeAPuH7UJr1HTdE uht2tP4Ib5OV8MaZHA6lyDDQq4LTiuCvAQfGqodglTqo/TtdRbThU9fhs+nPZJ0tm8pg Xr2D7MLZ5j6SwoTuDN1HeczIVMzqOb5OVZ67x7UDSVwuADbmZTZgD/BQOmnlBOREmwZ3 ADy2q78kHhY1gLGUEa95ekxGrRG/aMCUHgMHCu+XUlG82igEWiLEs9j09gk8m0nb0D1O imYCbpWmP4uGn8xWi2uRWG0vy2qqHWw6NQikzwZMzhhxo0kBZas+QawN34B46V7esw2f TJkQ== 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=QwI7vXDYlvIApsTBwHQIWtgOUS8kocR7BXXXZ5uchHI=; b=hje7uFiba2pJPnalignVgj41O9Qm0gCF/s9xyEgaAznz8R7CenN5K5KUwF6pzF22Z1 lZLquBkQPxRNici34sWqFMA5GRd+f8oSUdKwsDTmbNT7jTx3rRFX01C9DR9nK6Idku1r osIE6Ri28mW6Nk+z1TSqn1irtV9QSVr4tIiGNeI2VqmNMAK17tIMtDpkFs2HBHmpxrhu ljKwM57O/0zPL0/ktAfdp951IRe+k0BF0xCcBTnhA4CVxzncZemoT0Xu3oLctVBG0FzA ZsfIDpoBRJes9+gUml7HCWjwn8IJGeUU+jHOoY14ihw88cYplY6OkbC2UMfbuGf7lxtj ALPw== X-Gm-Message-State: APjAAAXBV8T92wf5vrnVRAmtru8R99S7H4PedMItneowdKCgkqhBnFvo A0zqdrMARNCnYOF0QILWmGrAV8ZG X-Google-Smtp-Source: APXvYqy4yyWUNvmCu+3PnQd2r0/xOkybZnUWNRSpeaAXH8YkDbuO8CJoNsPIYhYAqQPBEp3A6762NA== X-Received: by 2002:a05:600c:24a:: with SMTP id 10mr9836668wmj.7.1567282873211; Sat, 31 Aug 2019 13:21:13 -0700 (PDT) Received: from ?IPv6:2003:ea:8f04:7c00:9586:e556:3a4d:c04? (p200300EA8F047C009586E5563A4D0C04.dip0.t-ipconnect.de. [2003:ea:8f04:7c00:9586:e556:3a4d:c04]) by smtp.googlemail.com with ESMTPSA id r23sm11538013wmc.38.2019.08.31.13.21.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 31 Aug 2019 13:21:12 -0700 (PDT) Subject: [PATCH v5 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: Message-ID: <6a050164-8a63-f271-566f-2553ef579b5e@gmail.com> Date: Sat, 31 Aug 2019 22:16:00 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: 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 6de7a597a..f044ae4d1 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 Sat Aug 31 20:20:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 11125015 X-Patchwork-Delegate: bhelgaas@google.com 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 D3967174A for ; Sat, 31 Aug 2019 20:21:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9ED4022CE9 for ; Sat, 31 Aug 2019 20:21:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="G9LasMD4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726328AbfHaUVT (ORCPT ); Sat, 31 Aug 2019 16:21:19 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:51339 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728512AbfHaUVT (ORCPT ); Sat, 31 Aug 2019 16:21:19 -0400 Received: by mail-wm1-f66.google.com with SMTP id k1so10715119wmi.1 for ; Sat, 31 Aug 2019 13:21:16 -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=F+t8Cr+q/0B86BI83/P5P4BD0j9yQLctzzA5ry5iyh0=; b=G9LasMD4OSya4A6ezPEyB1XX1DPAjIL509nPWWVPeYLwqH+HBVRGLtVyb/XHAB1WYV W+RE3g3YQv+pR07XVfoP8ClNtDW9EPIAPDjrUPqF10JpMhCxF/qvvhBydmgADB1/hHDT DIy1rDyjG72vZkMWPfuUJb8p20ZxpcuWlCNsh2j6Wh5wZ1+6IqL6HBcaYt+L5Yi20G/c b5vw2tHWi/dgCs3fvfsF9XfH4xDsMbgTjZ2+iWOua0LFlnQ30y+QzduT44mFkNrnXiCU XC3lbVkNGlo5NgcVCtwekkZp4yfPzwDa4i0MHIZoBMBU+PcdCj0i2waYeE4kESL+H7fy yRTw== 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=F+t8Cr+q/0B86BI83/P5P4BD0j9yQLctzzA5ry5iyh0=; b=pW1dluWMMBZbZZI23JWo9Dxq2udk/vufs/7aXqOZhGtb8A3TtneC7+QwoD2REbVa1k po1mYg82b7nvyreKzIX7B8VUjTKoDJ6fG61T7suzJweW/eCKt2rNPUrSa/sdEXLVOWyV Y7WXVj6k1HLWkoi41oErj8AZlM8Omrlq43ctmsQMaLTycMBA6r7RVGWps21+bXAVw+du oO7FnwKb9PA+KPqhsuDu6yOuvw1mKKrxQkVqhMpr6MpTCJ3iURgQqfBhZJyvaGydVWU4 PVEEhrtLBhNnwcO9qzO2kw5fShLjve3tnh/qj2bTiib7WG/G8ZKDdTr9eHM3UFxVylCk rVjA== X-Gm-Message-State: APjAAAXIkffkP9vWaEEo7wQXMcw6bDIIj42rrq6Hbye15B1xDPjh4Ph1 TbHoOsJm/XDOu6IvstNcSU6aVA0+ X-Google-Smtp-Source: APXvYqyJYenCe+G514HYd/i42APadbjBPDffiHh14q0LyA5lv7PvKwW6IMFRSRsbMvASD/SIXlveBw== X-Received: by 2002:a7b:cbcf:: with SMTP id n15mr26842615wmi.48.1567282875685; Sat, 31 Aug 2019 13:21:15 -0700 (PDT) Received: from ?IPv6:2003:ea:8f04:7c00:9586:e556:3a4d:c04? (p200300EA8F047C009586E5563A4D0C04.dip0.t-ipconnect.de. [2003:ea:8f04:7c00:9586:e556:3a4d:c04]) by smtp.googlemail.com with ESMTPSA id k6sm32958223wrg.0.2019.08.31.13.21.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 31 Aug 2019 13:21:15 -0700 (PDT) Subject: [PATCH v5 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: Message-ID: <8783b887-2e30-43f0-d462-96f8fbb18ae2@gmail.com> Date: Sat, 31 Aug 2019 22:20:47 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: 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 Reviewed-by: Greg Kroah-Hartman --- 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 --- Documentation/ABI/testing/sysfs-bus-pci | 13 ++ drivers/pci/pci-sysfs.c | 7 + drivers/pci/pci.h | 4 + drivers/pci/pcie/aspm.c | 184 ++++++++++++++++++++++++ 4 files changed, 208 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-bus-pci b/Documentation/ABI/testing/sysfs-bus-pci index 8bfee557e..49249a165 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/.../aspm/aspm_l0s +What /sys/bus/pci/devices/.../aspm/aspm_l1 +What /sys/bus/pci/devices/.../aspm/aspm_l1_1 +What /sys/bus/pci/devices/.../aspm/aspm_l1_2 +What /sys/bus/pci/devices/.../aspm/aspm_l1_1_pcipm +What /sys/bus/pci/devices/.../aspm/aspm_l1_2_pcipm +What /sys/bus/pci/devices/.../aspm/aspm_clkpm +date: August 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. diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 868e35109..687240f55 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -1315,6 +1315,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); @@ -1571,6 +1575,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 44b80186d..9dc3e3673 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -659,4 +659,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 f044ae4d1..ce3425125 100644 --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -1287,6 +1287,190 @@ void pcie_aspm_remove_sysfs_dev_files(struct pci_dev *pdev) } #endif +static struct pcie_link_state *aspm_get_parent_link(struct pci_dev *pdev) +{ + struct pci_dev *parent = pdev->bus->self; + + if (pcie_downstream_port(pdev)) + parent = pdev; + + return parent ? parent->link_state : NULL; +} + +static bool pcie_check_valid_aspm_endpoint(struct pci_dev *pdev) +{ + struct pcie_link_state *link; + + if (!pci_is_pcie(pdev) || pci_pcie_type(pdev) != PCI_EXP_TYPE_ENDPOINT) + return false; + + link = aspm_get_parent_link(pdev); + + return link && link->aspm_capable; +} + +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; + int val; + + link = aspm_get_parent_link(pdev); + if (!link) + return -EOPNOTSUPP; + + mutex_lock(&aspm_lock); + val = !!(link->aspm_enabled & state); + mutex_unlock(&aspm_lock); + + return sprintf(buf, "%d\n", val); +} + +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 = aspm_get_parent_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 = aspm_get_parent_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 = aspm_get_parent_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_check_valid_aspm_endpoint(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 Sat Aug 31 20:18:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 11125013 X-Patchwork-Delegate: bhelgaas@google.com 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 63B6814DE for ; Sat, 31 Aug 2019 20:21:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3617823405 for ; Sat, 31 Aug 2019 20:21:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SEwkT8bG" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728535AbfHaUVR (ORCPT ); Sat, 31 Aug 2019 16:21:17 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:39628 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726328AbfHaUVR (ORCPT ); Sat, 31 Aug 2019 16:21:17 -0400 Received: by mail-wr1-f66.google.com with SMTP id t16so10171100wra.6 for ; Sat, 31 Aug 2019 13:21:15 -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=IJgntNFMeDEKUhV8HXAMOPKHkJCV2oBkuZRizPy8vqE=; b=SEwkT8bGqEmZ9l2EGDINOqeLjsCQAeHTiJAE/TLVWEugbD4PfvgXWmbQSNp9Uqon1t xroe28oMPcijcNfuq64S5bsj7tPjQ3/rdh572PPUIfqxlXUbopow+zs6NJ5xjhWwqqm2 sXjv3hqF05uF8/YYlzsLDpWqsf6E6PEjb/VgsoV2/FVP25aFPtrKwRG3RZdOQZFKXuSD YfBDoc5czuDmQDXA0j7F04Xof8NngVUZJPmR7VY+13FFCH4bKs1hoGP1ui2JgwRmGKAX QTWO2mXRiHVSnmQRaKbEyZEvRnPeHp0+YYUqeVAvIV/ZjkJB3tClnIvzWmPGD8VIFN9Z G9iA== 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=IJgntNFMeDEKUhV8HXAMOPKHkJCV2oBkuZRizPy8vqE=; b=Obxj/LLsbtlTANo0HxfrppgFllE7qAF5GVRqhbBRW+jQvnxjukXMOBzTkKkg2DMERL tb7GqM9yRuwtl49s+6xjmOxz0awwwhNXu0eqMOqMq8w4YKtTn5juV2oCNtNygvrDaMyE BMOk0olSZykCjwKRbszCkQSW2Vz6TDoH7cBArvw9pdyPOHJPtXTxwjOCqLeX7iv/c9cj 4BXq/uT4hOm79pNZ1pmtSo61ZUnuhdo+GRgugHtBLe1e2xCKiuupf3epC+uIdL/lbtWT guDrz1zgAhDk+YKkrJJFUidGVLeuOfeH8jCW7Bq9YDxHQivwxTyhqVpv3k6LCBJ/kcc6 c6Ag== X-Gm-Message-State: APjAAAVK5bNIVUSBnnc77PQYIsZASB96gDJGlhFWAIGsQ73F329oiKOT 8mgqcIz3NFpqxL/j/mD1IAghRhXc X-Google-Smtp-Source: APXvYqzSEkm6Jk4/nD2YVD2Bqqw0IWayyqyGDdIlqpHojD7YvxyeYH0O7w781xkP1SVyOA6HWHGdOA== X-Received: by 2002:adf:9050:: with SMTP id h74mr26189051wrh.191.1567282874500; Sat, 31 Aug 2019 13:21:14 -0700 (PDT) Received: from ?IPv6:2003:ea:8f04:7c00:9586:e556:3a4d:c04? (p200300EA8F047C009586E5563A4D0C04.dip0.t-ipconnect.de. [2003:ea:8f04:7c00:9586:e556:3a4d:c04]) by smtp.googlemail.com with ESMTPSA id j20sm18462361wre.65.2019.08.31.13.21.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 31 Aug 2019 13:21:13 -0700 (PDT) Subject: [PATCH v5 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: Message-ID: <4096ba95-b132-fc0d-8516-85352e87d82a@gmail.com> Date: Sat, 31 Aug 2019 22:18:28 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: 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. Signed-off-by: Heiner Kallweit --- v5: - rebased to latest pci/next --- 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 687240f55..acba3aff0 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -1314,7 +1314,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); @@ -1328,7 +1327,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; } @@ -1404,7 +1402,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 9dc3e3673..b3d3da257 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -533,14 +533,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 ce3425125..67a142251 100644 --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -1182,111 +1182,6 @@ 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); -#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 struct pcie_link_state *aspm_get_parent_link(struct pci_dev *pdev) { struct pci_dev *parent = pdev->bus->self;