From patchwork Wed May 13 03:20:10 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kenji Kaneshige X-Patchwork-Id: 23474 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n4D3KaYW018614 for ; Wed, 13 May 2009 03:20:36 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760360AbZEMDUd (ORCPT ); Tue, 12 May 2009 23:20:33 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1760377AbZEMDUd (ORCPT ); Tue, 12 May 2009 23:20:33 -0400 Received: from fgwmail6.fujitsu.co.jp ([192.51.44.36]:40461 "EHLO fgwmail6.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760322AbZEMDUb (ORCPT ); Tue, 12 May 2009 23:20:31 -0400 Received: from m3.gw.fujitsu.co.jp ([10.0.50.73]) by fgwmail6.fujitsu.co.jp (Fujitsu Gateway) with ESMTP id n4D3KVtk031195 for (envelope-from kaneshige.kenji@jp.fujitsu.com); Wed, 13 May 2009 12:20:31 +0900 Received: from smail (m3 [127.0.0.1]) by outgoing.m3.gw.fujitsu.co.jp (Postfix) with ESMTP id 1A2AD45DD7B for ; Wed, 13 May 2009 12:20:31 +0900 (JST) Received: from s3.gw.fujitsu.co.jp (s3.gw.fujitsu.co.jp [10.0.50.93]) by m3.gw.fujitsu.co.jp (Postfix) with ESMTP id D68F345DD78 for ; Wed, 13 May 2009 12:20:30 +0900 (JST) Received: from s3.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s3.gw.fujitsu.co.jp (Postfix) with ESMTP id B4A69E08003 for ; Wed, 13 May 2009 12:20:30 +0900 (JST) Received: from ml14.s.css.fujitsu.com (ml14.s.css.fujitsu.com [10.249.87.104]) by s3.gw.fujitsu.co.jp (Postfix) with ESMTP id 2B44E1DB8038 for ; Wed, 13 May 2009 12:20:30 +0900 (JST) Received: from ml14.css.fujitsu.com (ml14 [127.0.0.1]) by ml14.s.css.fujitsu.com (Postfix) with ESMTP id F17219F60BC; Wed, 13 May 2009 12:20:29 +0900 (JST) Received: from [127.0.0.1] (unknown [10.124.100.137]) by ml14.s.css.fujitsu.com (Postfix) with ESMTP id C00819F60B4; Wed, 13 May 2009 12:20:28 +0900 (JST) Message-ID: <4A0A3C6A.1060805@jp.fujitsu.com> Date: Wed, 13 May 2009 12:20:10 +0900 From: Kenji Kaneshige User-Agent: Thunderbird 2.0.0.21 (Windows/20090302) MIME-Version: 1.0 To: "linux-pci@vger.kernel.org" , Jesse Barnes CC: "Zhang, Yanmin" , "Li, Shaohua" Subject: [PATCH 9/14] PCI ASPM: cleanup clkpm checks References: <4A0A3A24.5030501@jp.fujitsu.com> In-Reply-To: <4A0A3A24.5030501@jp.fujitsu.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org In the current ASPM implementation, callers of pcie_set_clock_pm() check Clock PM capability of the link or current Clock PM state of the link. This check should be done in pcie_set_clock_pm() itself. This patch moves those checks into pcie_set_clock_pm(). It also introduce pcie_set_clkpm_nocheck() that is equivalent to old pcie_set_clock_pm(), for the caller who wants to change Clocl PM state regardless of the Clock PM capability or current Clock PM state. In addition, this patch changes the function name from pcie_set_clock_pm() to pcie_set_clkpm() for consistency. Signed-off-by: Kenji Kaneshige --- drivers/pci/pcie/aspm.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Index: 20090508/drivers/pci/pcie/aspm.c =================================================================== --- 20090508.orig/drivers/pci/pcie/aspm.c +++ 20090508/drivers/pci/pcie/aspm.c @@ -105,7 +105,7 @@ static int policy_to_clkpm_state(struct return 0; } -static void pcie_set_clock_pm(struct pcie_link_state *link, int enable) +static void pcie_set_clkpm_nocheck(struct pcie_link_state *link, int enable) { int pos; u16 reg16; @@ -126,6 +126,17 @@ static void pcie_set_clock_pm(struct pci 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 */ + if (!link->clkpm_capable && enable) + return; + /* Need nothing if the specified equals to current state */ + if (link->clkpm_enabled == enable) + return; + pcie_set_clkpm_nocheck(link, enable); +} + static void pcie_clkpm_cap_init(struct pcie_link_state *link, int blacklist) { int pos, capable = 1, enabled = 1; @@ -655,7 +666,7 @@ void pcie_aspm_init_link_state(struct pc /* Setup initial Clock PM state */ state = (link->clkpm_capable) ? policy_to_clkpm_state(link) : 0; - pcie_set_clock_pm(link, state); + pcie_set_clkpm(link, state); unlock: mutex_unlock(&aspm_lock); out: @@ -733,12 +744,11 @@ void pci_disable_link_state(struct pci_d mutex_lock(&aspm_lock); link_state = parent->link_state; link_state->aspm_support &= ~state; - if (state & PCIE_LINK_STATE_CLKPM) - link_state->clkpm_capable = 0; - __pcie_aspm_configure_link_state(link_state, link_state->aspm_enabled); - if (!link_state->clkpm_capable && link_state->clkpm_enabled) - pcie_set_clock_pm(link_state, 0); + if (state & PCIE_LINK_STATE_CLKPM) { + link_state->clkpm_capable = 0; + pcie_set_clkpm(link_state, 0); + } mutex_unlock(&aspm_lock); up_read(&pci_bus_sem); } @@ -763,11 +773,7 @@ static int pcie_aspm_set_policy(const ch list_for_each_entry(link_state, &link_list, sibling) { __pcie_aspm_configure_link_state(link_state, policy_to_aspm_state(link_state)); - if (link_state->clkpm_capable && - link_state->clkpm_enabled != policy_to_clkpm_state(link_state)) - pcie_set_clock_pm(link_state, - policy_to_clkpm_state(link_state)); - + pcie_set_clkpm(link_state, policy_to_clkpm_state(link_state)); } mutex_unlock(&aspm_lock); up_read(&pci_bus_sem); @@ -834,7 +840,7 @@ static ssize_t clk_ctl_store(struct devi const char *buf, size_t n) { - struct pci_dev *pci_device = to_pci_dev(dev); + struct pci_dev *pdev = to_pci_dev(dev); int state; if (n < 1) @@ -843,7 +849,7 @@ static ssize_t clk_ctl_store(struct devi down_read(&pci_bus_sem); mutex_lock(&aspm_lock); - pcie_set_clock_pm(pci_device->link_state, !!state); + pcie_set_clkpm_nocheck(pdev->link_state, !!state); mutex_unlock(&aspm_lock); up_read(&pci_bus_sem);