From patchwork Wed Sep 29 00:43:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Saheed O. Bolarinwa" X-Patchwork-Id: 12524253 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 349D8C433FE for ; Wed, 29 Sep 2021 00:44:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0BE096138F for ; Wed, 29 Sep 2021 00:44:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243474AbhI2Apt (ORCPT ); Tue, 28 Sep 2021 20:45:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243507AbhI2Apr (ORCPT ); Tue, 28 Sep 2021 20:45:47 -0400 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD6A4C061745; Tue, 28 Sep 2021 17:44:06 -0700 (PDT) Received: by mail-ed1-x529.google.com with SMTP id bd28so1894083edb.9; Tue, 28 Sep 2021 17:44:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=l2b36K0VOEbskUSIYtzJAJSfMxT71VREguqbCSTPpWU=; b=KMfsKV9f+1N9bMaDc82Uc+u0pvOBjnmkVVkF6+KIujtFNDEowLMAgIJghV7+twAJxJ gkPokOGez6K09iirfblMhnu9qfdiEpEL2qdWDz0PWPsoA1EKNJGpMePf0MV3UMPaOFvz cBWhJKEBi4CcG4GraxAIN/KA6ZLh9jJTONYCrHLwsHEI7yTAZG1gQZD+I22HQCVd/uVt if2JQvxjPKYnbCxglwgaABxq/tfMeh+J5pGdIwRW0RYFyktw/EolDRrpSFT2w2DGvuoN OxDeUA9KXh362WWzkeKnRvoNYSncU5VT+W9K6FEePDLOyd26dRdMhzRasylrc/0RPasr YYqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=l2b36K0VOEbskUSIYtzJAJSfMxT71VREguqbCSTPpWU=; b=o0dzRkpg9plHb8FjyR/MT2ilQsfGBdHUkqBvd8GmznrEk6PdeBHv6UZccYeIfXmhSD mjsd6wu+i4jWaAM/KsAlhZFkQ9qfq1Y3KVVyv1matptXQJZfPf5QRadlNZDWcmzLaZlO tzKD3F+AIK2ifwpqigUg9I1TlQ2F2tLtWG30c8gGuJRV0ngBx0PZttUPRQV53/UQRy8p 2iqqLMDdxdzgrWUyR8WXHxGntEL7doZq78+/9AMnGMYnel5JYsECo58hpKx40M8EG3SB A8sOKk/NV+h2xhxhU4gwHljbLbNkrpggJb0BN8DYaSybjJf/eZ05qzYtns/7ZK+n5I+E pvNg== X-Gm-Message-State: AOAM531FTwfmn2HZtqD7zWFLhOAN3yn9FXhu8HnAptk4YOtDzGTfRSxQ SvEauTY+155MSGkB7J4ETQoR4Cy5yII= X-Google-Smtp-Source: ABdhPJze8Fy7nKeq1XIX17NpgsoMlr9uJqX8w6Li1nKuDI6BNn4oMqIZz3SCUmH2h3ukYTrZLoF5Lg== X-Received: by 2002:a50:d90b:: with SMTP id t11mr11789788edj.32.1632876245475; Tue, 28 Sep 2021 17:44:05 -0700 (PDT) Received: from localhost.localdomain ([2a02:ab88:10f:c9f0:35c7:3af0:a197:61d0]) by smtp.googlemail.com with ESMTPSA id r19sm383578edt.54.2021.09.28.17.44.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Sep 2021 17:44:05 -0700 (PDT) From: "Saheed O. Bolarinwa" To: helgaas@kernel.org Cc: "Bolarinwa O. Saheed" , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v1 1/4] [PCI/ASPM:] Remove struct pcie_link_state.clkpm_default Date: Wed, 29 Sep 2021 02:43:57 +0200 Message-Id: <20210929004400.25717-2-refactormyself@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210929004400.25717-1-refactormyself@gmail.com> References: <20210929004400.25717-1-refactormyself@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: "Bolarinwa O. Saheed" The clkpm_default member of the struct pcie_link_state stores the value of the default clkpm state as it is in the BIOS. This patch: - Removes clkpm_default from struct pcie_link_state - Creates pcie_get_clkpm_state() which return the clkpm state obtained the BIOS - Replaces references to clkpm_default with call to pcie_get_clkpm_state() Signed-off-by: Bolarinwa O. Saheed --- drivers/pci/pcie/aspm.c | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c index 013a47f587ce..c23da9a4e2fb 100644 --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -63,7 +63,6 @@ struct pcie_link_state { /* Clock PM 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 */ @@ -123,6 +122,30 @@ static int policy_to_aspm_state(struct pcie_link_state *link) return 0; } +static int pcie_get_clkpm_state(struct pci_dev *pdev) +{ + int enabled = 1; + u32 reg32; + u16 reg16; + struct pci_dev *child; + struct pci_bus *linkbus = pdev->subordinate; + + /* All functions should have the same clkpm state, take the worst */ + list_for_each_entry(child, &linkbus->devices, bus_list) { + pcie_capability_read_dword(child, PCI_EXP_LNKCAP, ®32); + if (!(reg32 & PCI_EXP_LNKCAP_CLKPM)) { + enabled = 0; + break; + } + + pcie_capability_read_word(child, PCI_EXP_LNKCTL, ®16); + if (!(reg16 & PCI_EXP_LNKCTL_CLKREQ_EN)) + enabled = 0; + } + + return enabled; +} + static int policy_to_clkpm_state(struct pcie_link_state *link) { switch (aspm_policy) { @@ -134,7 +157,7 @@ static int policy_to_clkpm_state(struct pcie_link_state *link) /* Enable Clock PM */ return 1; case POLICY_DEFAULT: - return link->clkpm_default; + return pcie_get_clkpm_state(link->pdev); } return 0; } @@ -168,9 +191,8 @@ static void pcie_set_clkpm(struct pcie_link_state *link, int enable) static void pcie_clkpm_cap_init(struct pcie_link_state *link, int blacklist) { - int capable = 1, enabled = 1; + int capable = 1; u32 reg32; - u16 reg16; struct pci_dev *child; struct pci_bus *linkbus = link->pdev->subordinate; @@ -179,15 +201,10 @@ static void pcie_clkpm_cap_init(struct pcie_link_state *link, int blacklist) pcie_capability_read_dword(child, PCI_EXP_LNKCAP, ®32); if (!(reg32 & PCI_EXP_LNKCAP_CLKPM)) { capable = 0; - enabled = 0; break; } - pcie_capability_read_word(child, PCI_EXP_LNKCTL, ®16); - if (!(reg16 & PCI_EXP_LNKCTL_CLKREQ_EN)) - enabled = 0; } - link->clkpm_enabled = enabled; - link->clkpm_default = enabled; + link->clkpm_enabled = pcie_get_clkpm_state(link->pdev); link->clkpm_capable = capable; link->clkpm_disable = blacklist ? 1 : 0; } From patchwork Wed Sep 29 00:43:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Saheed O. Bolarinwa" X-Patchwork-Id: 12524255 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A8804C433F5 for ; Wed, 29 Sep 2021 00:44:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8B40C61246 for ; Wed, 29 Sep 2021 00:44:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243479AbhI2Apu (ORCPT ); Tue, 28 Sep 2021 20:45:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243435AbhI2Aps (ORCPT ); Tue, 28 Sep 2021 20:45:48 -0400 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B71BEC061746; Tue, 28 Sep 2021 17:44:07 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id b26so2139322edt.0; Tue, 28 Sep 2021 17:44:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vqYVhHvmXtg26aIqh8dqosLB/DKB+f5Z7Vmc3mQ1XAk=; b=j+zYp2xrNRfjDVqmeFtG+q3Ihp9cyZlzCM16EsaSR+hEiH7r6RjsNxA38dV6daLwS9 phPjWYQDEdvq0FMzv8KMi0nuTArO5xFvEBcQK0dpWp5AaATPVzjcM+FuGS0h8T1/ZVGE 16ihtCs5830RVx3R6cgzMsmordMVBHj6MIalNwwI6nbeOoBE68CGpoImsuTmMDiaDwT0 BvOY2hnSioduFepIy1iOwM2iUpkCsW91XOmxp2JP3k4Ve2B8LGX60TNxO0QD0HBqa9eB fw+rR537pKPDxETpBTxPdaLllPHnvpz1Ft3bzuDpphsQdAOLkwjldZtJMqrKyZgF7+dH Md3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vqYVhHvmXtg26aIqh8dqosLB/DKB+f5Z7Vmc3mQ1XAk=; b=w6Ktn7vZ/dJzr3mU7i/2CNtMevqNmWkxvR+sClQUA4IN0IhCZcOk/aKjcw8CKblkr4 YpNE48VewFS4Jjy3F27RP5YIQ1JEVhzUE1whGhSsXqjtTainVmwwO8/JoZbF0ol3oQrv O1KBsUi3EyG8dKwRRURQ3O4IzJo/n3AHS/Q1mAVPLdiuT/Ed3oo5lkSd0XMitSt9uyEQ rTCdByaVyToXYUr1H+ILeC3oEqppd45+u8Lx9bbAP/UMbX3om3brT9rHxLX2kbS3AqoS +oKEc6Ol99zQs7Xe27pHG/YGsOwHeM/GJ3Pb5AWDHwvNGcukFwLPTiSq6TUxLJ+Xm6SL 2bQA== X-Gm-Message-State: AOAM5312R9bB9EaaG8jvwS3wCPzpJwhgFEeGfuqsOiDP14haHKy0Bv2b exjFwdUM2614RSL9gx+CbZ0= X-Google-Smtp-Source: ABdhPJy1eBXUIOJbBSzr+zaKzRaDJK+jOYrp/5YkObudUYUC0qioXosg+7egQzvubE7QKFPZrQbSWw== X-Received: by 2002:a50:d903:: with SMTP id t3mr11488782edj.70.1632876246379; Tue, 28 Sep 2021 17:44:06 -0700 (PDT) Received: from localhost.localdomain ([2a02:ab88:10f:c9f0:35c7:3af0:a197:61d0]) by smtp.googlemail.com with ESMTPSA id r19sm383578edt.54.2021.09.28.17.44.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Sep 2021 17:44:06 -0700 (PDT) From: "Saheed O. Bolarinwa" To: helgaas@kernel.org Cc: "Bolarinwa O. Saheed" , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v1 2/4] PCI/ASPM: Remove struct pcie_link_state.clkpm_capable Date: Wed, 29 Sep 2021 02:43:58 +0200 Message-Id: <20210929004400.25717-3-refactormyself@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210929004400.25717-1-refactormyself@gmail.com> References: <20210929004400.25717-1-refactormyself@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: "Bolarinwa O. Saheed" The clkpm_capable member of the struct pcie_link_state indicates if the device is Clock PM capable. This can be calculated when it is needed. This patch: - removes clkpm_capable from struct pcie_link_state - moves the calculation of clkpm_capable into pcie_is_clkpm_capable() - replaces references to clkpm_capable with a call to pcie_is_clkpm_capable() Signed-off-by: Bolarinwa O. Saheed --- drivers/pci/pcie/aspm.c | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c index c23da9a4e2fb..9e65da9a22dd 100644 --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -61,7 +61,6 @@ struct pcie_link_state { u32 aspm_disable:7; /* Disabled ASPM state */ /* Clock PM state */ - u32 clkpm_capable:1; /* Clock PM capable? */ u32 clkpm_enabled:1; /* Current Clock PM state */ u32 clkpm_disable:1; /* Clock PM disabled */ @@ -146,6 +145,25 @@ static int pcie_get_clkpm_state(struct pci_dev *pdev) return enabled; } +static int pcie_is_clkpm_capable(struct pci_dev *pdev) +{ + int capable = 1; + u32 reg32; + struct pci_dev *child; + struct pci_bus *linkbus = pdev->subordinate; + + /* All functions should have the same cap state, take the worst */ + list_for_each_entry(child, &linkbus->devices, bus_list) { + pcie_capability_read_dword(child, PCI_EXP_LNKCAP, ®32); + if (!(reg32 & PCI_EXP_LNKCAP_CLKPM)) { + capable = 0; + break; + } + } + + return capable; +} + static int policy_to_clkpm_state(struct pcie_link_state *link) { switch (aspm_policy) { @@ -177,11 +195,12 @@ 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) { + int capable = pcie_is_clkpm_capable(link->pdev); /* * 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) + if (!capable || link->clkpm_disable) enable = 0; /* Need nothing if the specified equals to current state */ if (link->clkpm_enabled == enable) @@ -191,21 +210,7 @@ static void pcie_set_clkpm(struct pcie_link_state *link, int enable) static void pcie_clkpm_cap_init(struct pcie_link_state *link, int blacklist) { - int capable = 1; - u32 reg32; - struct pci_dev *child; - struct pci_bus *linkbus = link->pdev->subordinate; - - /* All functions should have the same cap and state, take the worst */ - list_for_each_entry(child, &linkbus->devices, bus_list) { - pcie_capability_read_dword(child, PCI_EXP_LNKCAP, ®32); - if (!(reg32 & PCI_EXP_LNKCAP_CLKPM)) { - capable = 0; - break; - } - } link->clkpm_enabled = pcie_get_clkpm_state(link->pdev); - link->clkpm_capable = capable; link->clkpm_disable = blacklist ? 1 : 0; } @@ -1346,7 +1351,7 @@ static umode_t aspm_ctrl_attrs_are_visible(struct kobject *kobj, return 0; if (n == 0) - return link->clkpm_capable ? a->mode : 0; + return pcie_is_clkpm_capable(link->pdev) ? a->mode : 0; return link->aspm_capable & aspm_state_map[n - 1] ? a->mode : 0; } From patchwork Wed Sep 29 00:43:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Saheed O. Bolarinwa" X-Patchwork-Id: 12524257 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C5F22C433F5 for ; Wed, 29 Sep 2021 00:44:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ACAA261246 for ; Wed, 29 Sep 2021 00:44:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243554AbhI2Apv (ORCPT ); Tue, 28 Sep 2021 20:45:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243529AbhI2Aps (ORCPT ); Tue, 28 Sep 2021 20:45:48 -0400 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A51C3C061749; Tue, 28 Sep 2021 17:44:08 -0700 (PDT) Received: by mail-ed1-x52f.google.com with SMTP id dj4so1959564edb.5; Tue, 28 Sep 2021 17:44:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RvkhxBWTCQGc5UyPf7Ik8EwSava2UkxqSV31MfuF8nE=; b=QmKx3iZK2fcPq3tcKQWeGQpK56PhAEBPSlHylMW2fvWhv77rsW98W1VMTBQ5HGT79f tFyQ6kdzzKhRWgJ8ZxdvZCnNQz1Gkg3rT8drlqbySlC+HKsY6U4LA5tcwAEYJfpzhI/y JUiN5BT/jYmYVf8q0ffCgTVRscUnL27Je6YziBpJDdZaZZ3bcpuB2ROcirimI9RYIPwB BBOZekQwo6auv8VitAspG+8RjyW9uNpcu+g7MbJnThjujqHNqpISf7UAc9KyXlkRBm0M pNmjd/ZLWZK5TTF2Iip4r+FQQUPbyBUYjHX+T/qQ7BxS38tpBDD2CoOVWw5G8mBbuX67 hpBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RvkhxBWTCQGc5UyPf7Ik8EwSava2UkxqSV31MfuF8nE=; b=edsOd1Wb6gz78D+AobmVtPHMESHRSI5KbWYe0GtwntgA0vV+dC2uoL29EPNMIEm/6u uIM5tepNoK4BWgP8BTEpZauaMpQXRbJiHNH2SCRINXUtRw+ZAE87dqkQO+ho24uP094j HpkFnnmyykyfeZJtfmt5vrEkcxjzehHAgjLk+SUqdEna2gVCKhDWggEieJvCxnt7CBJ0 DOia8kkgOY/XoVoJl3piH79Mldsr2HHavUQM0jBPvr4c9Os/YrRLUDTHuHk0NisuGoNG zh0XLV9Gkx+FD6iY79ulL+fQtKwSvQdd3rBfiR0orlHxzElAE6rRUovPZyVMdKEFtqgF wx9g== X-Gm-Message-State: AOAM5304K2R3oEsgHnQS7h4IV4qvgqYe34y48Zo29jh23LxxRfKFbe0/ O8bBnfDtUM4Yf3wSt1b13wUZQ68YlzY= X-Google-Smtp-Source: ABdhPJyyhVu9B+DglJnyfKL9QAwmjvnPdY04DUdxV0BDhK/hGzfacYFP8Vf+XUuH5d6Pjbx6ecs4rQ== X-Received: by 2002:a05:6402:19a9:: with SMTP id o9mr11227421edz.233.1632876247239; Tue, 28 Sep 2021 17:44:07 -0700 (PDT) Received: from localhost.localdomain ([2a02:ab88:10f:c9f0:35c7:3af0:a197:61d0]) by smtp.googlemail.com with ESMTPSA id r19sm383578edt.54.2021.09.28.17.44.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Sep 2021 17:44:06 -0700 (PDT) From: "Saheed O. Bolarinwa" To: helgaas@kernel.org Cc: "Bolarinwa O. Saheed" , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v1 3/4] PCI/ASPM: Remove struct pcie_link_state.clkpm_enabled Date: Wed, 29 Sep 2021 02:43:59 +0200 Message-Id: <20210929004400.25717-4-refactormyself@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210929004400.25717-1-refactormyself@gmail.com> References: <20210929004400.25717-1-refactormyself@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: "Bolarinwa O. Saheed" The clkpm_enabled member of the struct pcie_link_state stores the current Clock PM state for the device. However, when the state changes it is persisted and can be retrieve by calling pcie_get_clkpm_state() introduced in patch [1/3] in this series. This patch: - removes clkpm_enabled from the struct pcie_link_state - removes all instance where clkpm_enable is set - replaces references to clkpm_enabled with a call to pcie_get_clkpm_state() Signed-off-by: Bolarinwa O. Saheed --- drivers/pci/pcie/aspm.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c index 9e65da9a22dd..368828cd427d 100644 --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -61,7 +61,6 @@ struct pcie_link_state { u32 aspm_disable:7; /* Disabled ASPM state */ /* Clock PM state */ - u32 clkpm_enabled:1; /* Current Clock PM state */ u32 clkpm_disable:1; /* Clock PM disabled */ /* Exit latencies */ @@ -190,7 +189,6 @@ static void pcie_set_clkpm_nocheck(struct pcie_link_state *link, int enable) pcie_capability_clear_and_set_word(child, PCI_EXP_LNKCTL, PCI_EXP_LNKCTL_CLKREQ_EN, val); - link->clkpm_enabled = !!enable; } static void pcie_set_clkpm(struct pcie_link_state *link, int enable) @@ -203,14 +201,13 @@ static void pcie_set_clkpm(struct pcie_link_state *link, int enable) if (!capable || link->clkpm_disable) enable = 0; /* Need nothing if the specified equals to current state */ - if (link->clkpm_enabled == enable) + if (pcie_get_clkpm_state(link->pdev) == enable) return; pcie_set_clkpm_nocheck(link, enable); } static void pcie_clkpm_cap_init(struct pcie_link_state *link, int blacklist) { - link->clkpm_enabled = pcie_get_clkpm_state(link->pdev); link->clkpm_disable = blacklist ? 1 : 0; } @@ -1287,7 +1284,7 @@ static ssize_t clkpm_show(struct device *dev, struct pci_dev *pdev = to_pci_dev(dev); struct pcie_link_state *link = pcie_aspm_get_link(pdev); - return sysfs_emit(buf, "%d\n", link->clkpm_enabled); + return sysfs_emit(buf, "%d\n", pcie_get_clkpm_state(link->pdev)); } static ssize_t clkpm_store(struct device *dev, From patchwork Wed Sep 29 00:44:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Saheed O. Bolarinwa" X-Patchwork-Id: 12524259 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1D556C433EF for ; Wed, 29 Sep 2021 00:44:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0668C61246 for ; Wed, 29 Sep 2021 00:44:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243461AbhI2Ap6 (ORCPT ); Tue, 28 Sep 2021 20:45:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243541AbhI2Apt (ORCPT ); Tue, 28 Sep 2021 20:45:49 -0400 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8249DC06161C; Tue, 28 Sep 2021 17:44:09 -0700 (PDT) Received: by mail-ed1-x532.google.com with SMTP id v18so1861747edc.11; Tue, 28 Sep 2021 17:44:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=X2Mmz28tKhpY4RMXplVTUDjM+WhReCF+5Gp4Be7Q0+M=; b=C38lruJrbEQdQFBuhCDUllgqyqvwtKlnFnUiUraiVteyzHhCyQIchG2wViImyPMFxN /xLwshv5L+XIti+VG7lEFKQWAkwH0oUKXTDtp7Q8paHZ2LK58kc3N/UE8ullgwAK4Y8u 9hWHUyH9I3LCRYv2R8EuexrFjz0wmpTxp9pY4zif5ps1N956BkrvZc+xkhHHW9Ci4FoQ rC+qHP3Jdv1suHJS+QzpBzAwh2yPv1oF34iC5E5k8Jdjuef1ZSF1POVdnjGsVigZPqPy xTNXuYIWCEjkmQ3FSBzSPpCvJw7oWlYe8SyJGEnp4fg6gscsl/XlgEh8WJTLtaWv9cuq KbhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=X2Mmz28tKhpY4RMXplVTUDjM+WhReCF+5Gp4Be7Q0+M=; b=asx6Ps5pgDwcxkOQ3mHhxPXYaiQxUtTgcyk3zsI3lupVeWFG9Qgp+QNzA3vaIYCDBW Ps54NLW9pzWh/N2239LPQCq1fY6gFofttKe/Hopb7xQizuyYw31ozGe6ROYtMwyHoXMR 2BSOb5LEJ5oX3DCZvGc2ju2si9pxiqpFb3sYxy7DUemDXKtCzX4Xm6BAWepY/aP/x6e0 CNYAPwkgpfwJFvl8saoaNYpT59ovlKbfOf/ev3tIU9pawfRe7W9PDOmUDSNx8czoAVmj m8UDhWpQqcM0wWHOu2RZyS4kptL9PVkCEQfq+A6Jeu//NuEUo7d/eCGNU72LSfEUXKX+ mp7Q== X-Gm-Message-State: AOAM531gC8n7PACFk0egU6v4b7pbr9gH5+wvBtBoYPMAUMOilbYNRNsE +ZPReK7yXguqcTkItn3EPMQ= X-Google-Smtp-Source: ABdhPJxmBED0hNvbWqZMqlIqKCeHMg/jW59rSW1kEZC3IA7cmN9FNDperiMTAjH6vW6zzkOWdJnYuQ== X-Received: by 2002:a50:ab18:: with SMTP id s24mr11622300edc.88.1632876248070; Tue, 28 Sep 2021 17:44:08 -0700 (PDT) Received: from localhost.localdomain ([2a02:ab88:10f:c9f0:35c7:3af0:a197:61d0]) by smtp.googlemail.com with ESMTPSA id r19sm383578edt.54.2021.09.28.17.44.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Sep 2021 17:44:07 -0700 (PDT) From: "Saheed O. Bolarinwa" To: helgaas@kernel.org Cc: "Bolarinwa O. Saheed" , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v1 4/4] PCI/ASPM: Remove struct pcie_link_state.clkpm_disable Date: Wed, 29 Sep 2021 02:44:00 +0200 Message-Id: <20210929004400.25717-5-refactormyself@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210929004400.25717-1-refactormyself@gmail.com> References: <20210929004400.25717-1-refactormyself@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: "Bolarinwa O. Saheed" The clkpm_disable member of the struct pcie_link_state indicates if the Clock PM state of the device is disabled. There are two situations which can cause the Clock PM state disabled. 1. If the device fails sanity check as in pcie_aspm_sanity_check() 2. By calling __pci_disable_link_state() It is possible to set the Clock PM state of a device ON or OFF by calling pcie_set_clkpm(). The state can be retieved by calling pcie_get_clkpm_state(). pcie_link_state.clkpm_disable is only accessed in pcie_set_clkpm() to ensure that Clock PM state can be reenabled after being disabled. This patch: - add pm_disable to the struct pcie_link_state, to indicate that the kernel has marked the device's AS and Clock PM states disabled - removes clkpm_disable from the struct pcie_link_state - removes all instance where clkpm_disable is set - ensure that the Clock PM is always disabled if it is part of the states passed into __pci_disable_link_state(), regardless of the global policy Signed-off-by: Bolarinwa O. Saheed --- drivers/pci/pcie/aspm.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c index 368828cd427d..e6ae00daa7ae 100644 --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -60,8 +60,7 @@ struct pcie_link_state { u32 aspm_default:7; /* Default ASPM state by BIOS */ u32 aspm_disable:7; /* Disabled ASPM state */ - /* Clock PM state */ - u32 clkpm_disable:1; /* Clock PM disabled */ + u32 pm_disabled:1; /* Disabled AS and Clock PM ? */ /* Exit latencies */ struct aspm_latency latency_up; /* Upstream direction exit latency */ @@ -198,7 +197,7 @@ 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 * or Clock PM is disabled */ - if (!capable || link->clkpm_disable) + if (enable && (!capable || link->pm_disabled)) enable = 0; /* Need nothing if the specified equals to current state */ if (pcie_get_clkpm_state(link->pdev) == enable) @@ -206,11 +205,6 @@ static void pcie_set_clkpm(struct pcie_link_state *link, int enable) pcie_set_clkpm_nocheck(link, enable); } -static void pcie_clkpm_cap_init(struct pcie_link_state *link, int blacklist) -{ - link->clkpm_disable = blacklist ? 1 : 0; -} - static bool pcie_retrain_link(struct pcie_link_state *link) { struct pci_dev *parent = link->pdev; @@ -952,8 +946,7 @@ void pcie_aspm_init_link_state(struct pci_dev *pdev) */ pcie_aspm_cap_init(link, blacklist); - /* Setup initial Clock PM state */ - pcie_clkpm_cap_init(link, blacklist); + link->pm_disabled = blacklist; /* * At this stage drivers haven't had an opportunity to change the @@ -1129,8 +1122,8 @@ static int __pci_disable_link_state(struct pci_dev *pdev, int state, bool sem) pcie_config_aspm_link(link, policy_to_aspm_state(link)); if (state & PCIE_LINK_STATE_CLKPM) - link->clkpm_disable = 1; - pcie_set_clkpm(link, policy_to_clkpm_state(link)); + pcie_set_clkpm(link, 0); + mutex_unlock(&aspm_lock); if (sem) up_read(&pci_bus_sem); @@ -1301,7 +1294,6 @@ static ssize_t clkpm_store(struct device *dev, 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);