From patchwork Tue Jan 31 19:45:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sinan Kaya X-Patchwork-Id: 9548317 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3462660425 for ; Tue, 31 Jan 2017 19:46:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2644C2831C for ; Tue, 31 Jan 2017 19:46:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1AA7328384; Tue, 31 Jan 2017 19:46:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, T_DKIM_INVALID autolearn=no version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7F3962831C for ; Tue, 31 Jan 2017 19:46:01 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cYeNJ-0004CO-Jy; Tue, 31 Jan 2017 19:45:57 +0000 Received: from smtp.codeaurora.org ([198.145.29.96]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cYeNG-0003HV-4X for linux-arm-kernel@lists.infradead.org; Tue, 31 Jan 2017 19:45:55 +0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 6DA3F60915; Tue, 31 Jan 2017 19:45:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1485891933; bh=PdgKrszCj0nlnEu20TB6PzkSiOSyr2ogGO+fEBK0qRc=; h=From:To:Cc:Subject:Date:From; b=PRpezdcMmHTodcrctVGdEMHs5DHv29jyhItP2hI1xkPhVTtb0HT0C6iPWCbLxtWzZ aloW8ifY2TyZtqSqvyZSs/w/WjKj8cdBKWmS5Ip8gBEp3x/AdSzcF/C7JQPmbT+p6U uxfaNT7ylvfuUkzNp1K6ahnhwnsYTjZ32AhPjePk= Received: from drakthul.qualcomm.com (global_nat1_iad_fw.qualcomm.com [129.46.232.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: okaya@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 17FBB6077B; Tue, 31 Jan 2017 19:45:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1485891932; bh=PdgKrszCj0nlnEu20TB6PzkSiOSyr2ogGO+fEBK0qRc=; h=From:To:Cc:Subject:Date:From; b=O65plwrJ5vYjI4TMdcBC0a6BjUozPqZuf1LGtl4kdQzfuXuIcOJcu/QKM7qRgnS+V tBfjpPXDCRaQXr09WRnO1HbPJIF/e7vF0sR6iHsjJZSi4rp0N6MWRpRo3SKS6DPrdE sDNnfMzI99O/xlwnLZThd8FViBm2OID5QTIHvZMk= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 17FBB6077B Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=okaya@codeaurora.org From: Sinan Kaya To: linux-pci@vger.kernel.org, timur@codeaurora.org, cov@codeaurora.org Subject: [PATCH V2] PCI/ASPM: reconfigure ASPM following hotplug for POLICY_DEFAULT Date: Tue, 31 Jan 2017 14:45:27 -0500 Message-Id: <1485891928-14573-1-git-send-email-okaya@codeaurora.org> X-Mailer: git-send-email 1.9.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170131_114554_227079_E41F5F7E X-CRM114-Status: GOOD ( 16.50 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sinan Kaya , linux-arm-msm@vger.kernel.org, open list , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP When the operating system is booted with the default ASPM policy (POLICY_DEFAULT), the current code is determining the ASPM policy set up by the BIOS by querying the enable/disable states from ASPM registers. In the case of hotplug removal, the ASPM registers get cleared by calling the pcie_aspm_exit_link_state() function. An insertion following hotplug removal reads incorrect policy as ASPM disabled even though ASPM was enabled during boot. Adding a flag to the struct pci_dev and saving the power up policy in the bridge to be reused during hotplug insertion. Bridge's enable counter is used as a switch to determine when to use saved value. Signed-off-by: Sinan Kaya --- drivers/pci/pcie/aspm.c | 21 +++++++++++++++++---- include/linux/pci.h | 1 + 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c index 17ac1dc..5cfcc6d 100644 --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -338,8 +338,9 @@ static void pcie_aspm_check_latency(struct pci_dev *endpoint) } } -static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist) +static void pcie_aspm_cap_init(struct pci_dev *pdev, int blacklist) { + struct pcie_link_state *link = pdev->link_state; struct pci_dev *child, *parent = link->pdev; struct pci_bus *linkbus = parent->subordinate; struct aspm_register_info upreg, dwreg; @@ -397,8 +398,20 @@ static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist) link->latency_up.l1 = calc_l1_latency(upreg.latency_encoding_l1); link->latency_dw.l1 = calc_l1_latency(dwreg.latency_encoding_l1); - /* Save default state */ - link->aspm_default = link->aspm_enabled; + /* + * Save default state from FW when enabling ASPM for the first time + * during boot by looking at the calculated link->aspm_enabled bits + * above and enable_cnt will be zero. + * + * If this path is getting called for the second/third time + * (enable_cnt will be non-zero). Assume that the current state of the + * ASPM registers may not necessarily match what FW asked us to do as + * in the case of hotplug insertion/removal. + */ + if (!atomic_read(&pdev->enable_cnt)) + pdev->aspm_default = link->aspm_default = link->aspm_enabled; + else + link->aspm_default = pdev->aspm_default; /* Setup initial capable state. Will be updated later */ link->aspm_capable = link->aspm_support; @@ -599,7 +612,7 @@ void pcie_aspm_init_link_state(struct pci_dev *pdev) * upstream links also because capable state of them can be * update through pcie_aspm_cap_init(). */ - pcie_aspm_cap_init(link, blacklist); + pcie_aspm_cap_init(pdev, blacklist); /* Setup initial Clock PM state */ pcie_clkpm_cap_init(link, blacklist); diff --git a/include/linux/pci.h b/include/linux/pci.h index e2d1a12..521f88c 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -321,6 +321,7 @@ struct pci_dev { #ifdef CONFIG_PCIEASPM struct pcie_link_state *link_state; /* ASPM link state */ + unsigned int aspm_default; /* ASPM policy set by BIOS */ #endif pci_channel_state_t error_state; /* current connectivity state */