From patchwork Wed Oct 26 18:01:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 9397989 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 F1B4360231 for ; Wed, 26 Oct 2016 18:01:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BBED229C0C for ; Wed, 26 Oct 2016 18:01:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ADE1C29C0E; Wed, 26 Oct 2016 18:01:49 +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=ham 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 59D9F29C05 for ; Wed, 26 Oct 2016 18:01:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934642AbcJZSBZ (ORCPT ); Wed, 26 Oct 2016 14:01:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46230 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933999AbcJZSBX (ORCPT ); Wed, 26 Oct 2016 14:01:23 -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 712C161BB3; Wed, 26 Oct 2016 18:01:23 +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 u9QI1MIn024014; Wed, 26 Oct 2016 14:01:23 -0400 Subject: [PATCH 2/5] PCI: Extract link speed & width retrieval from pcie_get_minimum_link() 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:22 -0600 Message-ID: <20161026180122.23495.26258.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.39]); Wed, 26 Oct 2016 18:01:23 +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 | 26 ++++++++++++++++++++------ include/linux/pci.h | 2 ++ 2 files changed, 22 insertions(+), 6 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 b901ee7..6d6cf89 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -4729,6 +4729,25 @@ int pcie_set_mps(struct pci_dev *dev, int mps) } EXPORT_SYMBOL(pcie_set_mps); +int pcie_get_link(struct pci_dev *dev, enum pci_bus_speed *speed, + enum pcie_link_width *width) +{ + int ret; + u16 lnksta; + + ret = pcie_capability_read_word(dev, PCI_EXP_LNKSTA, &lnksta); + if (ret) + return ret; + + if (speed) + *speed = pcie_link_speed[lnksta & PCI_EXP_LNKSTA_CLS]; + if (width) + *width = (lnksta & PCI_EXP_LNKSTA_NLW) >> + PCI_EXP_LNKSTA_NLW_SHIFT; + + return 0; +} + /** * pcie_get_minimum_link - determine minimum link settings of a PCI device * @dev: PCI device to query @@ -4747,18 +4766,13 @@ int pcie_get_minimum_link(struct pci_dev *dev, enum pci_bus_speed *speed, *width = PCIE_LNK_WIDTH_UNKNOWN; while (dev) { - u16 lnksta; enum pci_bus_speed next_speed; enum pcie_link_width next_width; - ret = pcie_capability_read_word(dev, PCI_EXP_LNKSTA, &lnksta); + ret = pcie_get_link(dev, &next_speed, &next_width); if (ret) return ret; - next_speed = pcie_link_speed[lnksta & PCI_EXP_LNKSTA_CLS]; - next_width = (lnksta & PCI_EXP_LNKSTA_NLW) >> - PCI_EXP_LNKSTA_NLW_SHIFT; - if (next_speed < *speed) *speed = next_speed; diff --git a/include/linux/pci.h b/include/linux/pci.h index c3248d5..fbfbb40 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1026,6 +1026,8 @@ static inline int pci_is_managed(struct pci_dev *pdev) int pcie_set_mps(struct pci_dev *dev, int mps); 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, + enum pcie_link_width *width); int __pci_reset_function(struct pci_dev *dev); int __pci_reset_function_locked(struct pci_dev *dev); int pci_reset_function(struct pci_dev *dev);