From patchwork Wed Jul 27 12:14:54 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislaw Gruszka X-Patchwork-Id: 1011582 X-Patchwork-Delegate: bhelgaas@google.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p6RCE2fP011515 for ; Wed, 27 Jul 2011 12:14:03 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754186Ab1G0MN6 (ORCPT ); Wed, 27 Jul 2011 08:13:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:3230 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754024Ab1G0MN4 (ORCPT ); Wed, 27 Jul 2011 08:13:56 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p6RCDp8B032436 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 27 Jul 2011 08:13:51 -0400 Received: from localhost (dhcp-27-232.brq.redhat.com [10.34.27.232]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p6RCDnA3028839; Wed, 27 Jul 2011 08:13:50 -0400 From: Stanislaw Gruszka To: linux-wireless Cc: ath9k-devel@venema.h4ckr.net, camilo@mesias.co.uk, Jonathan Nieder , Tony Houghton , Rajkumar Manoharan , ath9k-devel@venema.h4ckr.net, Adrian Chadd , Stanislaw Gruszka , Jesse Barnes , linux-pci@vger.kernel.org Subject: [RFC/RFT v2 07/12] pci: aspm: add function for disabling ASPM Date: Wed, 27 Jul 2011 14:14:54 +0200 Message-Id: <1311768899-4559-8-git-send-email-sgruszka@redhat.com> In-Reply-To: <1311768899-4559-1-git-send-email-sgruszka@redhat.com> References: <1311768899-4559-1-git-send-email-sgruszka@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Wed, 27 Jul 2011 12:14:03 +0000 (UTC) Add support for disabling ASPM if !CONFIG_PCIEASPM. Patch is based on code from e1000e. Cc: Jesse Barnes Cc: linux-pci@vger.kernel.org Signed-off-by: Stanislaw Gruszka --- drivers/pci/pcie/Makefile | 3 +-- drivers/pci/pcie/aspm.c | 41 +++++++++++++++++++++++++++++++++++++++++ include/linux/pci-aspm.h | 2 ++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/drivers/pci/pcie/Makefile b/drivers/pci/pcie/Makefile index 00c62df..6e20c59 100644 --- a/drivers/pci/pcie/Makefile +++ b/drivers/pci/pcie/Makefile @@ -2,8 +2,7 @@ # Makefile for PCI-Express PORT Driver # -# Build PCI Express ASPM if needed -obj-$(CONFIG_PCIEASPM) += aspm.o +obj-y += aspm.o pcieportdrv-y := portdrv_core.o portdrv_pci.o portdrv_bus.o pcieportdrv-$(CONFIG_ACPI) += portdrv_acpi.o diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c index 6892601..2883fc3 100644 --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -21,6 +21,8 @@ #include #include "../pci.h" +#ifdef CONFIG_PCIEASPM + #ifdef MODULE_PARAM_PREFIX #undef MODULE_PARAM_PREFIX #endif @@ -976,3 +978,42 @@ bool pcie_aspm_support_enabled(void) return aspm_support_enabled; } EXPORT_SYMBOL(pcie_aspm_support_enabled); + +void pcie_disable_aspm(struct pci_dev *pdev, u16 state) +{ + pci_disable_link_state_locked(pdev, state); +} +EXPORT_SYMBOL(pcie_disable_aspm); + +#else /* CONFIG_PCIEASPM */ + +void pcie_disable_aspm(struct pci_dev *pdev, u16 state) +{ + int pos; + u16 reg16; + struct pci_dev *parent; + + pos = pci_pcie_cap(pdev); + if (!pos) + return; + /* + * Both device and parent should have the same ASPM setting. + * Disable ASPM in downstream component first and then upstream. + */ + + pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, ®16); + reg16 &= ~state; + pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, reg16); + + parent = pdev->bus->self; + if (WARN_ON(!parent)) + return; + + pos = pci_pcie_cap(parent); + pci_read_config_word(parent, pos + PCI_EXP_LNKCTL, ®16); + reg16 &= ~state; + pci_write_config_word(parent, pos + PCI_EXP_LNKCTL, reg16); +} +EXPORT_SYMBOL(pcie_disable_aspm); + +#endif diff --git a/include/linux/pci-aspm.h b/include/linux/pci-aspm.h index 7cea7b6..f9722e6 100644 --- a/include/linux/pci-aspm.h +++ b/include/linux/pci-aspm.h @@ -55,6 +55,8 @@ static inline void pcie_no_aspm(void) } #endif +extern void pcie_disable_aspm(struct pci_dev *pdev, u16 state); + #ifdef CONFIG_PCIEASPM_DEBUG /* this depends on CONFIG_PCIEASPM */ extern void pcie_aspm_create_sysfs_dev_files(struct pci_dev *pdev); extern void pcie_aspm_remove_sysfs_dev_files(struct pci_dev *pdev);