From patchwork Sat Nov 6 17:55:44 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: 1551781 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=d+bfy1B6; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4HmlRH1jVyz9t2p for ; Sun, 7 Nov 2021 04:55:55 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230310AbhKFR6e (ORCPT ); Sat, 6 Nov 2021 13:58:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234077AbhKFR6d (ORCPT ); Sat, 6 Nov 2021 13:58:33 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58931C061570; Sat, 6 Nov 2021 10:55:52 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id w1so45034289edd.10; Sat, 06 Nov 2021 10:55:52 -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=3Q6q3isMgPDupqsbJoM92sZ54D8XuX4Je+/qZDkIAWk=; b=d+bfy1B6PpfYhUEFK0kXh35yU+4gWis+46PpMvWc0VpIZy9dDUb1YDSr+HQZxEIV1e hsi+9NovKp384hXhvBxJSw1F7Bnq6aahySVSWH1FqrZ+vpcuAbvGSL18izlaUeWNxQsC 3ZoZ4Y87DS2UqD4xBNsW8d/489+kWr9BMp830rImLdMrrNK1bJhxuvlym0WcRuj2eX0v j6jEt7KwiQNb1mM8zAanQeVOZTJCTVVxRLfwu1JRgAg4eVQ/H5FZ+87TjTsxrqtGldxM o4aMirVrFpkYUE5SclDmtgkqt6iNHTmAoxBJjYTUz6SwNKT1PRNFkFsHczKZNzlQYbn8 U40A== 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=3Q6q3isMgPDupqsbJoM92sZ54D8XuX4Je+/qZDkIAWk=; b=uDfK1ucPeBCuMYzAoEY7OAl58I3/2NLAoWHi+8G76PgMBagwf3cYTbB/Yoceq0Ca1s 1bWtgm0n/OA7YDYLEtyt6T/X9m3yx740t19MmvMX+pK5POyiE4KzruLNRzoZbE2Ui6HG DxSgQesxyQpRYcK0RM3/6TABFl7a1KlLCtwdtfBFnjfl1w0YWgqD0nzfbslX2ogqj8rF 3BuAmZdrwCFivtbVtk4rBlrUuidR+gPxoIhUs37DTifcTTEch4j2CSI9yGvw1gOU/aoL XsltasVZhVtmwM+9h0kkfQGS84ioUXcU42+AlAYgmTMlmcbuAz9+1NOb1XXB727x977Y qEAA== X-Gm-Message-State: AOAM5332OCMCrv59gVKYDgmLD+s9Xld7Tpn/J0LX5ZgSZWpIVGMlana/ FtuffBFZjBgfI9nLAKT0N1X+Xm5I8rU= X-Google-Smtp-Source: ABdhPJy8f1Xs600hPHGAXRobrm65xm91pySG4J58FkRzEXjyqKsdJ4cHFgZoVqdH6Ya4mytdd+CJlg== X-Received: by 2002:a17:906:a14a:: with SMTP id bu10mr82704284ejb.540.1636221350977; Sat, 06 Nov 2021 10:55:50 -0700 (PDT) Received: from localhost.localdomain ([2a02:ab88:109:9f0:f6a6:7fbe:807a:e1cc]) by smtp.googlemail.com with ESMTPSA id j3sm5742310ejo.2.2021.11.06.10.55.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Nov 2021 10:55:50 -0700 (PDT) From: "Saheed O. Bolarinwa" To: helgaas@kernel.org Cc: "Saheed O. Bolarinwa" , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v2 1/3] PCI/ASPM: Merge pcie_set_clkpm_nocheck() into pcie_set_clkpm() Date: Sat, 6 Nov 2021 18:55:44 +0100 Message-Id: <20211106175546.27785-2-refactormyself@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211106175546.27785-1-refactormyself@gmail.com> References: <20211106175546.27785-1-refactormyself@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org pcie_set_clkpm_nocheck() is only called from pcie_set_clkpm(). Merge the two functions Signed-off-by: Saheed O. Bolarinwa --- drivers/pci/pcie/aspm.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c index 013a47f587ce..e5202cc16ef0 100644 --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -139,21 +139,12 @@ static int policy_to_clkpm_state(struct pcie_link_state *link) return 0; } -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) { + u32 val; struct pci_dev *child; struct pci_bus *linkbus = link->pdev->subordinate; - u32 val = enable ? PCI_EXP_LNKCTL_CLKREQ_EN : 0; - - list_for_each_entry(child, &linkbus->devices, bus_list) - 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) -{ /* * Don't enable Clock PM if the link is not Clock PM capable * or Clock PM is disabled @@ -163,7 +154,14 @@ static void pcie_set_clkpm(struct pcie_link_state *link, int enable) /* Need nothing if the specified equals to current state */ if (link->clkpm_enabled == enable) return; - pcie_set_clkpm_nocheck(link, enable); + + val = enable ? PCI_EXP_LNKCTL_CLKREQ_EN : 0; + list_for_each_entry(child, &linkbus->devices, bus_list) + pcie_capability_clear_and_set_word(child, PCI_EXP_LNKCTL, + PCI_EXP_LNKCTL_CLKREQ_EN, + val); + + link->clkpm_enabled = !!enable; } static void pcie_clkpm_cap_init(struct pcie_link_state *link, int blacklist) From patchwork Sat Nov 6 17:55:45 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: 1551782 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=mCbhhQvC; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4HmlRJ4YGgz9t54 for ; Sun, 7 Nov 2021 04:55:56 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230080AbhKFR6f (ORCPT ); Sat, 6 Nov 2021 13:58:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230007AbhKFR6e (ORCPT ); Sat, 6 Nov 2021 13:58:34 -0400 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13546C061570; Sat, 6 Nov 2021 10:55:53 -0700 (PDT) Received: by mail-ed1-x52a.google.com with SMTP id r4so43906706edi.5; Sat, 06 Nov 2021 10:55:53 -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=2/P8WA+2iDdON1mVpjkOQgEA/jNZnIHNrCcb1i4JNhk=; b=mCbhhQvCpzIbaUdVptVQuuWEcyFQbeb4SxVVpooNFqpe5eKvzkzdDpgz2mSG9lzdoE FsZF+P3ZOdyVK3Bwp2j1sgcI38i/fwkl7og7mVoqmOF8vtXpFb0UnO859n3mAaflP+UJ tYvjwLzFOjKeP/uib5riCgl21lNGMuH14pqqLroUxOUoSLml7M1ex2z3/NSANpz0uCoX rOMzqM1egL45rGQYW0w5tj5K6n5W8+3VUWntSxUeDCdoEAHFQ0Z5aBwCfDNyC9UrOKBi fsTGZla+nZl57Rs5KXMIxbi8KjTErgta21Lz3Kf3kwda3qmEWVrT2bOZcHPbBmiwYkjc DCZQ== 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=2/P8WA+2iDdON1mVpjkOQgEA/jNZnIHNrCcb1i4JNhk=; b=peaAGzrLTOHSBt6g17NFabhLx4vwWunq1p4005uzIlA7asAS3pYHah8ZdliT84Ah44 cf1TUN/qDPlrGXdvwtd4xIXokU7H6ih8z9Wm+j7jKHqDh+0C+jz6zRnyJs61VjZaCrLG JUsyVdcs7zZ05oE+6CKPhpy+xyMw8qyty9QJYj11hMBmyDT8DalX/Mjp7sFyQK5DYyn1 FDA8y/vqIYzLrCK5LULPKhZQgNVFJJJToa8IGe3vjUyV3ogK/6ZJEu4IMxquw72jampI 0Tn4HCozL7hPjodQ1Uhik1WZex4bghepvN69GQkog8ZoQyNAW7hKUrACSVZQ27/L/0pj iISw== X-Gm-Message-State: AOAM533LO1US/rEHOW90xiCyYdd/cKGgnjo54s0uiM3IcY/jP4sjRp96 HpnIK2d80Jm1s9sJNzYiDok= X-Google-Smtp-Source: ABdhPJzf0l6z2FsdOkMX7iPQ9Tt30I2/jqGVaorLESRXNTDWiQ1nwbgHtykobVRJvEtqpbwh1Z3EFw== X-Received: by 2002:a05:6402:40c5:: with SMTP id z5mr17027775edb.185.1636221351717; Sat, 06 Nov 2021 10:55:51 -0700 (PDT) Received: from localhost.localdomain ([2a02:ab88:109:9f0:f6a6:7fbe:807a:e1cc]) by smtp.googlemail.com with ESMTPSA id j3sm5742310ejo.2.2021.11.06.10.55.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Nov 2021 10:55:51 -0700 (PDT) From: "Saheed O. Bolarinwa" To: helgaas@kernel.org Cc: "Saheed O. Bolarinwa" , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v2 2/3] PCI/ASPM: Remove struct pcie_link_state.clkpm_capable Date: Sat, 6 Nov 2021 18:55:45 +0100 Message-Id: <20211106175546.27785-3-refactormyself@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211106175546.27785-1-refactormyself@gmail.com> References: <20211106175546.27785-1-refactormyself@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org 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, because it comes from Link Capabilities, a read-only register. - remove clkpm_capable from struct pcie_link_state - move the calculation of clkpm_capable into pcie_is_clkpm_capable() - replace references to clkpm_capable with a call to pcie_is_clkpm_capable() Signed-off-by: Saheed O. Bolarinwa --- drivers/pci/pcie/aspm.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c index e5202cc16ef0..c1f8f10b7a4c 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_default:1; /* Default Clock PM state by BIOS */ u32 clkpm_disable:1; /* Clock PM disabled */ @@ -105,6 +104,20 @@ static const char *policy_str[] = { #define LINK_RETRAIN_TIMEOUT HZ +static int pcie_clkpm_capable(struct pci_dev *pdev) +{ + u32 cap; + struct pci_dev *child; + struct pci_bus *linkbus = pdev->subordinate; + + list_for_each_entry(child, &linkbus->devices, bus_list) { + pcie_capability_read_dword(child, PCI_EXP_LNKCAP, &cap); + if (!(cap & PCI_EXP_LNKCAP_CLKPM)) + return 0; + } + return 1; +} + static int policy_to_aspm_state(struct pcie_link_state *link) { switch (aspm_policy) { @@ -149,7 +162,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 (!link->clkpm_capable || link->clkpm_disable) + if (!pcie_clkpm_capable(link->pdev) || link->clkpm_disable) enable = 0; /* Need nothing if the specified equals to current state */ if (link->clkpm_enabled == enable) @@ -166,7 +179,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, enabled = 1; + int enabled = 1; u32 reg32; u16 reg16; struct pci_dev *child; @@ -176,7 +189,6 @@ static void pcie_clkpm_cap_init(struct pcie_link_state *link, int blacklist) 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; enabled = 0; break; } @@ -186,7 +198,6 @@ static void pcie_clkpm_cap_init(struct pcie_link_state *link, int blacklist) } link->clkpm_enabled = enabled; link->clkpm_default = enabled; - link->clkpm_capable = capable; link->clkpm_disable = blacklist ? 1 : 0; } @@ -1327,7 +1338,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_clkpm_capable(link->pdev) ? a->mode : 0; return link->aspm_capable & aspm_state_map[n - 1] ? a->mode : 0; } From patchwork Sat Nov 6 17:55:46 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: 1551783 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=ePDCO4SU; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4HmlRL0v80z9sR4 for ; Sun, 7 Nov 2021 04:55:58 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234720AbhKFR6h (ORCPT ); Sat, 6 Nov 2021 13:58:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234150AbhKFR6f (ORCPT ); Sat, 6 Nov 2021 13:58:35 -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 F28D8C061570; Sat, 6 Nov 2021 10:55:53 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id w1so45034460edd.10; Sat, 06 Nov 2021 10:55:53 -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=X3tmpUFdzGmDZ4WUOB/oWLSIyqVvdPUkHVycX9v/1S4=; b=ePDCO4SURPuf12mUqAZnXPG+s5RIrdRkWYYIhMGzf2AKmjPt++Rwf+eONXFTaqE7Ap XPq2ZBvwSHzquYUrwFGV+NGfi9Y3SN3wqPm4IHreVRU6whxAfIuVcHZoPpcJZ+HL6RvU 7Nn19DdicBpjbiBXgEFPaxQiqst/Hc4al3Gxees3duvqViw1+n6sGdEve17YGLNJSYLt r98uu19QQntGvVuaex68lUhdiYF5HDppZhKcz5kjJ+xMFRqqRHQXeB7S3uXyL0mRC7QW VCiCykoSnTTtlactA3Up4CUdyEdyompOUFKOg7sppA53iy0OL5dgRxhdONEOlwaS+1wD 2zeA== 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=X3tmpUFdzGmDZ4WUOB/oWLSIyqVvdPUkHVycX9v/1S4=; b=a/Io8UQiYs+cIoeDedwSG33Wy+HZXl/LDVjYo4cSgcdWXyYP6AKWv1lyzcwCiB7uZS Wc3jdDLhte3wgchdq4VBFY2J1v0b3CmazLrQ99lYNsXNWisqodlhD+mQPwpj1dYZYHl7 SeaZPJ7T61nqINU5thLK4w0rP+Obde+eEhcba/Od06MLwlxLnOYkFqgkL6SaO9q14yAI vzP15iad2zrsUible5YMUgWhIAbA9goev1HvtZKZhJlpePim0uEVU+jA/Ec3yfOW2AEU mMp9PLo3TWnxKrJNhSBkAmgyoM/DfTbGiO6DZ0SASr14t6KcE5xxElZapBnSjqSL+CSf dUlQ== X-Gm-Message-State: AOAM530TJPfvpodie+D6G0Czusd74s5UaubrCDHt7HF1g9Jx2bj+ZiZI lIBz+/QshPc6nnx8c+rcKRY= X-Google-Smtp-Source: ABdhPJyIPH25JvkWo5A1A6qxxj/pUIvTUH/wUWSVevJtRgABfK+CW/BIPFs5alv7FE0jMalnDWFyyA== X-Received: by 2002:a17:907:629b:: with SMTP id nd27mr81379072ejc.24.1636221352613; Sat, 06 Nov 2021 10:55:52 -0700 (PDT) Received: from localhost.localdomain ([2a02:ab88:109:9f0:f6a6:7fbe:807a:e1cc]) by smtp.googlemail.com with ESMTPSA id j3sm5742310ejo.2.2021.11.06.10.55.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Nov 2021 10:55:52 -0700 (PDT) From: "Saheed O. Bolarinwa" To: helgaas@kernel.org Cc: "Saheed O. Bolarinwa" , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v2 3/3] PCI/ASPM: Remove struct pcie_link_state.clkpm_enabled Date: Sat, 6 Nov 2021 18:55:46 +0100 Message-Id: <20211106175546.27785-4-refactormyself@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211106175546.27785-1-refactormyself@gmail.com> References: <20211106175546.27785-1-refactormyself@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org 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 thus can be retieved directly. - move calculations into pcie_clkpm_enabled() - 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: Saheed O. Bolarinwa --- drivers/pci/pcie/aspm.c | 43 +++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c index c1f8f10b7a4c..9425d1e38c51 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_default:1; /* Default Clock PM state by BIOS */ u32 clkpm_disable:1; /* Clock PM disabled */ @@ -104,6 +103,21 @@ static const char *policy_str[] = { #define LINK_RETRAIN_TIMEOUT HZ +static int pcie_clkpm_enabled(struct pci_dev *pdev) +{ + struct pci_dev *child; + struct pci_bus *linkbus = pdev->subordinate; + u16 ctl; + + /* CLKREQ_EN is only applicable for Upstream Ports */ + list_for_each_entry(child, &linkbus->devices, bus_list) { + pcie_capability_read_word(child, PCI_EXP_LNKCTL, &ctl); + if (!(ctl & PCI_EXP_LNKCTL_CLKREQ_EN)) + return 0; + } + return 1; +} + static int pcie_clkpm_capable(struct pci_dev *pdev) { u32 cap; @@ -165,7 +179,7 @@ static void pcie_set_clkpm(struct pcie_link_state *link, int enable) if (!pcie_clkpm_capable(link->pdev) || link->clkpm_disable) enable = 0; /* Need nothing if the specified equals to current state */ - if (link->clkpm_enabled == enable) + if (pcie_clkpm_enabled(link->pdev) == enable) return; val = enable ? PCI_EXP_LNKCTL_CLKREQ_EN : 0; @@ -173,31 +187,11 @@ static void pcie_set_clkpm(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_clkpm_cap_init(struct pcie_link_state *link, int blacklist) { - int enabled = 1; - u32 reg32; - u16 reg16; - 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)) { - 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_default = pcie_clkpm_enabled(link->pdev); link->clkpm_disable = blacklist ? 1 : 0; } @@ -1272,9 +1266,8 @@ static ssize_t clkpm_show(struct device *dev, struct device_attribute *attr, char *buf) { 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_clkpm_enabled(pdev)); } static ssize_t clkpm_store(struct device *dev,