From patchwork Fri Aug 23 06:12: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: 1151977 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="SP9yc7Lr"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 46FB3z571Jz9sNp for ; Fri, 23 Aug 2019 16:16:15 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404340AbfHWGQO (ORCPT ); Fri, 23 Aug 2019 02:16:14 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:37903 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404301AbfHWGQN (ORCPT ); Fri, 23 Aug 2019 02:16:13 -0400 Received: by mail-wr1-f65.google.com with SMTP id g17so7517079wrr.5 for ; Thu, 22 Aug 2019 23:16: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=dk/6LfmE1oX8xh4qZCF6iNA2M7CxlYcaWLLLz9LpGWU=; b=SP9yc7Lrvwg8ldBYtiSTFfd6aUnMY3DobSVDCF5DDtlqVz/RIMISiB3UAn2qqDXLfb jgLuaA13xvqvzPbXIUXJ4rTE2IvgzAEf7y2dWqrql5jBOynNZ4mz/ZZTyfsVfohvyndN Qlr1tzEMB/X/8tWEtVGCL89BM94tY+Ak7QYlXyP9VG2NXF66nrxKY3UhjIdqYbIGMMHZ TvOh7zoMLzcVYFEtQ/bEH612Au9p4FdV2NFAfEL7MEJwA5ML47+oAKBI+u5+TPvMFJrb ivovHahxcgKebh5gP1n5qOkKftcJFMnkoJSKlbhpsWBt6VHzrBRxEz4WJratWMMrN858 RWrA== 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=dk/6LfmE1oX8xh4qZCF6iNA2M7CxlYcaWLLLz9LpGWU=; b=QBIwoCEr33qzfOweA2LaeT7i7AavlDDsgmzKAySqYr95UKHkkFN9LzmLa6wQJ11Tvn mnT28z85QoJJLod0E4+T+OjjahBjnhzvOWqtCpI5SN7KYFlvNd1yTLKXEkf9Tsy+YJm3 D+CfgejxHeavkgPoyB2VYkolrvX//nrYMgr/gCYkrXqsB6kvx3Yxu9s1Uv0qw2CC3L7t ybD6PdlhD8HQ6y0GgLHOIxYORY9bHB9si32lfhf1o9O2dsFA0fRzFQeD71kfXJu8tzi3 rIqKCqR+XmluB7iau3w1Y3Zg3xASX847dsaWOBv96iI1TwcQ+f3WvAScHk1qj+/el51c BA4g== X-Gm-Message-State: APjAAAUI7vb+UFzaUxNm+UDSmVpn7ohqxiAv3FSgey2cwhV8kH1MvlIy 6O3ALPbfO1Hnj+fn/G7HpyiRT2r+ X-Google-Smtp-Source: APXvYqwuRoOaxYwYo0CQYQJKWCyWtXGL4DAUg/aPeACBcnV5CeMY8/HToVtFCcWk532ZuPDG4nHDjA== X-Received: by 2002:a5d:5183:: with SMTP id k3mr3045633wrv.270.1566540971406; Thu, 22 Aug 2019 23:16:11 -0700 (PDT) Received: from ?IPv6:2003:ea:8f04:7c00:34d1:4088:cd1d:73a7? (p200300EA8F047C0034D14088CD1D73A7.dip0.t-ipconnect.de. [2003:ea:8f04:7c00:34d1:4088:cd1d:73a7]) by smtp.googlemail.com with ESMTPSA id e11sm4013125wrc.4.2019.08.22.23.16.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Aug 2019 23:16:10 -0700 (PDT) Subject: [PATCH v3 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: <9e5ef666-1ef9-709a-cd7a-ca43eeb9e4a4@gmail.com> Message-ID: <69c8c402-b34e-8eac-9b79-24c5f13c84dd@gmail.com> Date: Fri, 23 Aug 2019 08:12:06 +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: <9e5ef666-1ef9-709a-cd7a-ca43eeb9e4a4@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-aspm.h | 10 +++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c index 464f8f926..1c1b9b7d6 100644 --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -1095,7 +1095,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-aspm.h b/include/linux/pci-aspm.h index 67064145d..f635cbdff 100644 --- a/include/linux/pci-aspm.h +++ b/include/linux/pci-aspm.h @@ -19,9 +19,13 @@ #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) +#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 Fri Aug 23 06:12:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 1151979 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="QlOAdWJq"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 46FB4248Ytz9sP3 for ; Fri, 23 Aug 2019 16:16:18 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404346AbfHWGQR (ORCPT ); Fri, 23 Aug 2019 02:16:17 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:41624 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404334AbfHWGQO (ORCPT ); Fri, 23 Aug 2019 02:16:14 -0400 Received: by mail-wr1-f66.google.com with SMTP id j16so7496989wrr.8 for ; Thu, 22 Aug 2019 23:16:13 -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=rVtfzdrmRFBQnHI9A6IJKPt4rgOl7HXVD+rwCQXJ+08=; b=QlOAdWJq10m7uwPXm7jBgwmOCPs/Z7GxpNU24vlERml1gVVb5w2SO4sMRoGIDmk/Gx PL4IRf6P54HC1Z9Ns7kDQmSH/INJjWtf4cmnnx92jj1Z2HVAWOlovwdPdY/4Y++jXkkQ mR0N30bTJ+GigDSUUkpkZSDpXdw9FufoDT7uja1A/UKL3IB7ClxWLUSxsLRhjcZW4Och l027ZPnij+XT2sbPttpyaqlyXeXEJArh1MwEQ0aFxGeFZX7W+fph0a255uiPzNMPkCpv fYGUM9p6EzIpFTAdQVTYNOW4Kl2JLlVOOSu6VAyH3FVCtwRhsD1J+IwjLOX9+F8nNOfA F3qg== 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=rVtfzdrmRFBQnHI9A6IJKPt4rgOl7HXVD+rwCQXJ+08=; b=euqZYIcUPO/2CDKqyxICzhAADLtz6L9J17Z8JoQhDP58yqgw8jqu2/6zpXi3XrCYf0 IGh27Wr9q/uLpslMbxqWeL8YQH4FDPDYSCoYJRy9vy37EPRf99Xx06+d3BlNf7yxQFWx mbS53kAPZCvsr6PmtsZZfmC0cfNO63bmuKl76t5zL4z+UShF62sgg8klzlwWNBgeCteD 3I7Q2C82gbpqhy4koFQAxC7joxGR3EjFDTpQmI2m/mOYpQDculeXIYGGY3ors9EE9Ww5 WgbbNTxcTQ2phQ5Y7Yp6V3o8MyI9QzSzKh4Lhz5cn5o1kJzQ/wM9BqJTUMaU/as14nIz YlbA== X-Gm-Message-State: APjAAAUXndt4b4yF48p+HUBNJAGOPxWK4e1NPfzGm2seZIw+oWwd0bpt 6HrIUJGMdCYYcFq1leAz8tku3TgQ X-Google-Smtp-Source: APXvYqz69gflbtaxiLet/quQO2eIqPt+3TrlLXeYRAd+lEAuCEBTtDBO1TAJNaU+UMV5fJTjkFnEFw== X-Received: by 2002:a5d:6a12:: with SMTP id m18mr2212604wru.306.1566540972793; Thu, 22 Aug 2019 23:16:12 -0700 (PDT) Received: from ?IPv6:2003:ea:8f04:7c00:34d1:4088:cd1d:73a7? (p200300EA8F047C0034D14088CD1D73A7.dip0.t-ipconnect.de. [2003:ea:8f04:7c00:34d1:4088:cd1d:73a7]) by smtp.googlemail.com with ESMTPSA id u129sm2058764wmb.12.2019.08.22.23.16.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Aug 2019 23:16:12 -0700 (PDT) Subject: [PATCH v3 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: <9e5ef666-1ef9-709a-cd7a-ca43eeb9e4a4@gmail.com> Message-ID: <80d3f3c6-f08a-dcf9-ed66-70201a90c3ae@gmail.com> Date: Fri, 23 Aug 2019 08:12:52 +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: <9e5ef666-1ef9-709a-cd7a-ca43eeb9e4a4@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 1c1b9b7d6..149b876c9 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) @@ -1107,10 +1112,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 Fri Aug 23 06:15:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 1151978 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="q8gHohWq"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 46FB4163g7z9sNp for ; Fri, 23 Aug 2019 16:16:17 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404334AbfHWGQR (ORCPT ); Fri, 23 Aug 2019 02:16:17 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:52379 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404117AbfHWGQQ (ORCPT ); Fri, 23 Aug 2019 02:16:16 -0400 Received: by mail-wm1-f66.google.com with SMTP id o4so7775632wmh.2 for ; Thu, 22 Aug 2019 23:16: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=De2t+OnH9MfsoPT9GJMrVsUaBz55+3cJW9rOaEd+Kjs=; b=q8gHohWqV2GtAEgYpR0rOaHAvNlud9E0YyOqBFN+R8ZdGQt2nnAy1hxVHPVQkBv0V7 qQ3968pLuAikdjum7G6rRINSrMbggI1swGbf+CAumBK45QE8D86A/RiLJAXwH3T3QtSj KKz9zT+pSH8XvwJ6XSgoS6hY04JVmjMl2fu46T7f2uiHanle5OHz+j8xa81zTvsRXUPF /RScxXqx4N1JdWZK1iU/7dClL7OMOZERC1LCRDnOK3PbTMzsHppP2XhMdqSz8YQhx4e6 JZraDGZXf+jY800Zs2OrSYHFje7mcJ+oV3GI1Hx/S1guGlnLOHocBoh3CtEq/QF6F1oa VSEA== 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=De2t+OnH9MfsoPT9GJMrVsUaBz55+3cJW9rOaEd+Kjs=; b=UtXUQaLADcdr0EQrrH7hHD5oTC1DeRMIbYoYjk0JBIYF38nWB9cx94exi/deSjDbw8 xTg7dB1+QHJLEdXfL14ThccV5lO93vct2dKnxhup2Y/KzdrGmR47XKQIWzjEIvHz1+Qm tYGlyCOsufLc2Zzr+VqLtFllZDAsEagT10Xd8YU4CntJ5VmlP0oR5x4Ef9rQNoobKPN3 ncUcVxGQrYOYF8lOwrRHXECmU5yDTLKHRJusr7/kzR1e9PHVq4xTA80lUX+t5dFlC9Qt UfgXEbd335CgtQFinYVmZfRcfLXyLaaGcFl+rYscURV5Q7X4PDjSVqinpsPACme7LhBw IMdA== X-Gm-Message-State: APjAAAV7541PwQ31OCVNrM2THY+Iz8Tw3jz80f8iSgGByhU4IiakYksQ J86bhh4F1TlcO5C0ic7ziIuLNU8R X-Google-Smtp-Source: APXvYqx+GkFj6s7b0SZ0qrnUghDK0fdzWs8Gu4Ia1y7+xaiuE5qsEPxSkIfC8dw0sPBkPuW1pA2DHw== X-Received: by 2002:a1c:45:: with SMTP id 66mr3006191wma.40.1566540974162; Thu, 22 Aug 2019 23:16:14 -0700 (PDT) Received: from ?IPv6:2003:ea:8f04:7c00:34d1:4088:cd1d:73a7? (p200300EA8F047C0034D14088CD1D73A7.dip0.t-ipconnect.de. [2003:ea:8f04:7c00:34d1:4088:cd1d:73a7]) by smtp.googlemail.com with ESMTPSA id c15sm6869666wrb.80.2019.08.22.23.16.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Aug 2019 23:16:13 -0700 (PDT) Subject: [PATCH v3 3/4] PCI/ASPM: add sysfs attributes for controlling ASPM From: Heiner Kallweit To: Frederick Lawler , Bjorn Helgaas , Greg KH , Rajat Jain Cc: "linux-pci@vger.kernel.org" References: <9e5ef666-1ef9-709a-cd7a-ca43eeb9e4a4@gmail.com> Message-ID: Date: Fri, 23 Aug 2019 08:15:14 +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: <9e5ef666-1ef9-709a-cd7a-ca43eeb9e4a4@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" --- Documentation/ABI/testing/sysfs-bus-pci | 13 ++ drivers/pci/pci-sysfs.c | 3 + drivers/pci/pci.h | 4 + drivers/pci/pcie/aspm.c | 246 ++++++++++++++++++++++++ 4 files changed, 266 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 793412954..0e76c02e0 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 85e9fc14e..3908fb23d 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -649,4 +649,8 @@ static inline void pci_aer_clear_fatal_status(struct pci_dev *dev) { } static inline void pci_aer_clear_device_status(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 149b876c9..0d54cd7c7 100644 --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -1308,6 +1308,252 @@ 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_l0s_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return aspm_attr_show_common(dev, attr, buf, ASPM_STATE_L0S); +} + +static ssize_t aspm_l1_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return aspm_attr_show_common(dev, attr, buf, ASPM_STATE_L1); +} + +static ssize_t aspm_l1_1_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return aspm_attr_show_common(dev, attr, buf, ASPM_STATE_L1_1); +} + +static ssize_t aspm_l1_2_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return aspm_attr_show_common(dev, attr, buf, ASPM_STATE_L1_2); +} + +static ssize_t aspm_l1_1_pcipm_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return aspm_attr_show_common(dev, attr, buf, ASPM_STATE_L1_1_PCIPM); +} + +static ssize_t aspm_l1_2_pcipm_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return aspm_attr_show_common(dev, attr, buf, ASPM_STATE_L1_2_PCIPM); +} + +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; + else + link->aspm_disable |= state; + + if (link->aspm_disable & ASPM_STATE_L1) + link->aspm_disable |= ASPM_STATE_L1SS; + + pcie_config_aspm_link(link, policy_to_aspm_state(link)); + + mutex_unlock(&aspm_lock); + up_read(&pci_bus_sem); + + return len; +} + +static ssize_t aspm_l0s_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_L0S); +} + +static ssize_t aspm_l1_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_L1); +} + +static ssize_t aspm_l1_1_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_L1_1); +} + +static ssize_t aspm_l1_2_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_L1_2); +} + +static ssize_t aspm_l1_1_pcipm_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_L1_1_PCIPM); +} + +static ssize_t aspm_l1_2_pcipm_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_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 Fri Aug 23 06:15: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: 1151980 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="EKnboRJv"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 46FB433q0Nz9sNp for ; Fri, 23 Aug 2019 16:16:19 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404117AbfHWGQS (ORCPT ); Fri, 23 Aug 2019 02:16:18 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:52380 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404341AbfHWGQR (ORCPT ); Fri, 23 Aug 2019 02:16:17 -0400 Received: by mail-wm1-f66.google.com with SMTP id o4so7775725wmh.2 for ; Thu, 22 Aug 2019 23:16: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=+4Bmc0ZpnjfSfSMfniH/rk4kYcHE1WYcpQwbIq12Y6g=; b=EKnboRJv9MdawcXhFG61DfD9ZqGRMGGIugOKe904MDdZxf/03/6VNEPB1KIHQYSdYy pAbTsRFuRfwcXaB1DzUHGGKfN9QP2bgxMpbBgGzY2mXxalSDQGOHIhZOJIz8Fp6S6KQM 5S67IAowAI2dOygmw1+ds2wo2z1JtshGDjgLoxg4eunuPL/r50SUducYowyKyQhJAkP/ DpKZjTYtddfeZWMRzhGRwJlRxYV6EKyCT2qpewMcLUSAGzjT30h+msRl6DipnwxzYm3i mMz+uqdRJVBLJSeS0X5k5PQ0pTiks7AmM4B3OWhmbGIttwaPanhxto68EUPOVLRjOFgF CAxg== 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=+4Bmc0ZpnjfSfSMfniH/rk4kYcHE1WYcpQwbIq12Y6g=; b=btRbT5mGzrDXJ2lHPVYEqXySmnFsVMfvASQJ4xoJPTOJP9HdKoK/bkYA/BxY7D4QPy vl4NGy5k+iGMncVCJ2HxHCScXswAVJGW2jAw9O0iYLrlzohaOiRqpWjIwTwLNX3a4hO8 ng+HscHUN1puDXy+C3aozP7HmSIHtupJC5KCi2o8SCsVvUw81z0d6mX2XUmINUXTfMda 57u6ENBamJ1if76T9tHXprbI0DCrkFma/6WznpPBgunEN+ds/yHVWTWS1bxO74medesZ 0jeQnXPRXGpl1D8AHxGZVYaURsemzNyiUhKNhsHYBIg5UpZtgiDCbMP0ks4JoWwenJJv 78rg== X-Gm-Message-State: APjAAAWn+siqqOhWe4YlQmyEDFkTQzS+R9RWVKc2/C2GQFAV1x7agGY7 tZA0gXJ7mxUWRvzY5PuLMNLy56gk X-Google-Smtp-Source: APXvYqwE8TZFlr9ue5SlaE709iOAKQQ7dyLymCbIp6jL8t9YGXVQ02yOm7huAwb7VNgvJ/g1pXlpsA== X-Received: by 2002:a1c:c1cd:: with SMTP id r196mr3129573wmf.127.1566540975502; Thu, 22 Aug 2019 23:16:15 -0700 (PDT) Received: from ?IPv6:2003:ea:8f04:7c00:34d1:4088:cd1d:73a7? (p200300EA8F047C0034D14088CD1D73A7.dip0.t-ipconnect.de. [2003:ea:8f04:7c00:34d1:4088:cd1d:73a7]) by smtp.googlemail.com with ESMTPSA id f24sm1584058wmc.25.2019.08.22.23.16.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Aug 2019 23:16:15 -0700 (PDT) Subject: [PATCH v3 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: <9e5ef666-1ef9-709a-cd7a-ca43eeb9e4a4@gmail.com> Message-ID: <5f705952-5a4c-579b-d059-98ff36f62261@gmail.com> Date: Fri, 23 Aug 2019 08:15:54 +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: <9e5ef666-1ef9-709a-cd7a-ca43eeb9e4a4@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. Signed-off-by: Heiner Kallweit --- 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 0e76c02e0..92bf1b1ce 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 3908fb23d..9ede6a37a 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -532,14 +532,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 0d54cd7c7..8c13a152f 100644 --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -1203,111 +1203,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 struct pcie_link_state *aspm_get_parent_link(struct pci_dev *pdev) { struct pci_dev *parent = pdev->bus->self;