From patchwork Wed Oct 26 18:01:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 9398003 X-Patchwork-Delegate: bhelgaas@google.com 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 F070D60231 for ; Wed, 26 Oct 2016 18:02:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BBCB729C0C for ; Wed, 26 Oct 2016 18:02:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B0D4F29C0E; Wed, 26 Oct 2016 18:02:15 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 65A5E29C0C for ; Wed, 26 Oct 2016 18:02:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753809AbcJZSBe (ORCPT ); Wed, 26 Oct 2016 14:01:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44258 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933999AbcJZSB3 (ORCPT ); Wed, 26 Oct 2016 14:01:29 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4A8A68050A; Wed, 26 Oct 2016 18:01:29 +0000 (UTC) Received: from gimli.home (ovpn-116-188.phx2.redhat.com [10.3.116.188]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9QI1SSH024092; Wed, 26 Oct 2016 14:01:28 -0400 Subject: [PATCH 3/5] PCI: Extract link retraining from pcie_aspm_configure_common_clock() From: Alex Williamson To: linux-pci@vger.kernel.org Cc: bhelgaas@google.com, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Date: Wed, 26 Oct 2016 12:01:28 -0600 Message-ID: <20161026180128.23495.19403.stgit@gimli.home> In-Reply-To: <20161026175156.23495.12980.stgit@gimli.home> References: <20161026175156.23495.12980.stgit@gimli.home> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 26 Oct 2016 18:01:29 +0000 (UTC) Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Alex Williamson --- drivers/pci/pci.c | 29 +++++++++++++++++++++++++++++ drivers/pci/pcie/aspm.c | 17 +---------------- include/linux/pci.h | 1 + 3 files changed, 31 insertions(+), 16 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 diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 6d6cf89..4d327d4 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -4729,6 +4729,35 @@ int pcie_set_mps(struct pci_dev *dev, int mps) } EXPORT_SYMBOL(pcie_set_mps); +int pcie_retrain_link(struct pci_dev *dev) +{ + int ret; + u16 lnksta; + unsigned long timeout; + + /* Can only retrain from downstream ports */ + if (!pci_is_pcie(dev) || + (pci_pcie_type(dev) != PCI_EXP_TYPE_DOWNSTREAM && + pci_pcie_type(dev) != PCI_EXP_TYPE_ROOT_PORT)) + return -EINVAL; + + ret = pcie_capability_set_word(dev, PCI_EXP_LNKCTL, PCI_EXP_LNKCTL_RL); + if (ret) + return ret; + + timeout = jiffies + HZ; /* Retraining timeout */ + for (;;) { + pcie_capability_read_word(dev, PCI_EXP_LNKSTA, &lnksta); + if (!(lnksta & PCI_EXP_LNKSTA_LT) || + time_after(jiffies, timeout)) + break; + msleep(1); + } + + return (lnksta & PCI_EXP_LNKSTA_LT) ? -EBUSY : 0; +} +EXPORT_SYMBOL(pcie_retrain_link); + int pcie_get_link(struct pci_dev *dev, enum pci_bus_speed *speed, enum pcie_link_width *width) { diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c index 0ec649d..482d60c 100644 --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -91,8 +91,6 @@ struct pcie_link_state { [POLICY_POWERSAVE] = "powersave" }; -#define LINK_RETRAIN_TIMEOUT HZ - static int policy_to_aspm_state(struct pcie_link_state *link) { switch (aspm_policy) { @@ -222,20 +220,7 @@ static void pcie_aspm_configure_common_clock(struct pcie_link_state *link) pcie_capability_write_word(parent, PCI_EXP_LNKCTL, reg16); /* Retrain link */ - reg16 |= PCI_EXP_LNKCTL_RL; - pcie_capability_write_word(parent, PCI_EXP_LNKCTL, reg16); - - /* Wait for link training end. Break out after waiting for timeout */ - start_jiffies = jiffies; - for (;;) { - pcie_capability_read_word(parent, PCI_EXP_LNKSTA, ®16); - if (!(reg16 & PCI_EXP_LNKSTA_LT)) - break; - if (time_after(jiffies, start_jiffies + LINK_RETRAIN_TIMEOUT)) - break; - msleep(1); - } - if (!(reg16 & PCI_EXP_LNKSTA_LT)) + if (!pcie_retrain_link(parent)) return; /* Training failed. Restore common clock configurations */ diff --git a/include/linux/pci.h b/include/linux/pci.h index fbfbb40..eb0e9be 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1024,6 +1024,7 @@ static inline int pci_is_managed(struct pci_dev *pdev) int pcie_set_readrq(struct pci_dev *dev, int rq); int pcie_get_mps(struct pci_dev *dev); int pcie_set_mps(struct pci_dev *dev, int mps); +int pcie_retrain_link(struct pci_dev *dev); int pcie_get_minimum_link(struct pci_dev *dev, enum pci_bus_speed *speed, enum pcie_link_width *width); int pcie_get_link(struct pci_dev *dev, enum pci_bus_speed *speed,