Received: by 10.213.65.68 with SMTP id h4csp54089imn; Fri, 30 Mar 2018 14:07:09 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+F8gBQ5nj/MW4ehShLhoE+4vgaVQjUg1Rs323WhMLDDoN/4mMHMCCUK5W70HOtF5k8Bd51 X-Received: by 2002:a17:902:6b01:: with SMTP id o1-v6mr563242plk.350.1522444029175; Fri, 30 Mar 2018 14:07:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522444029; cv=none; d=google.com; s=arc-20160816; b=ifz2TI6rYZDcIRnwJgzggSxzE0wYW046sVIkv2a9rPacxM1Mdwp1FHqeHuU6gXQO1s 7ZTJdhXOA3lkOzfEmdmZQZOapuh4LWFb1w7CTP4Ro7VVOi7GdhXwqHSfZXWEc9lrta9s gENKj1x1rcAQZ9PUC6mw+1hmYqO9aw4hNHNJwCkoHJdSWsnE8jql6Q1DiwAmb3nCNg1t of/r22pWUZOn15yuiU5hpIiVbNkxsP4/HZJPkQPyUy56FSUT1LGi11hCUquZvQWeCRuZ PSpqE4PnOYgtsbN45zqi3rmR62jfac9zrHU0Qi9Tiw1iqdwMWHoKRI69ouSZuf8bgCL6 DL0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:dmarc-filter:arc-authentication-results; bh=wjbymjKXhLqaRADMchGo3BYArnK2sdFBbNqRaAzv5t0=; b=NMOxycxVP1tr72jxm2H2aWpiaDWvHZLlL9ASByX/TaIX2w/XCGBZQDeAt11pqoUeTs rtf2cRwE8qifyuTpWxXEpzPqAFKffKeXWWkTWXZ7Sz4EP7gQP2YiaZLVdClTMTYQGVUT LZekjVGeNdF4JOiIcGIOXu752F6p32zRugwPYH8U9rUYgAzskzuf7uDLrlNvYJnXo8km 4q6H+6T0TB26d8F0FCBS7X9ppR8rePeU4J+hDzHWODBA1l2vSXqFu7FFuHG0NBFiYIwo rs+wsK+/K5AlZpoZ+q3PDwKO5oq9/gfA4gSlTHWlNFTX/5OXqux7AU7o5+v8hBW2vH2L 7Y1A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n86si7027123pfj.86.2018.03.30.14.06.55; Fri, 30 Mar 2018 14:07:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753007AbeC3VFX (ORCPT + 99 others); Fri, 30 Mar 2018 17:05:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:33624 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752978AbeC3VFV (ORCPT ); Fri, 30 Mar 2018 17:05:21 -0400 Received: from localhost (unknown [69.71.5.252]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 03DCA21777; Fri, 30 Mar 2018 21:05:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 03DCA21777 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=helgaas@kernel.org Subject: [PATCH v5 05/14] PCI: Add pcie_print_link_status() to log link speed and whether it's limited From: Bjorn Helgaas To: Tal Gilboa Cc: Tariq Toukan , Jacob Keller , Ariel Elior , Ganesh Goudar , Jeff Kirsher , everest-linux-l2@cavium.com, intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org Date: Fri, 30 Mar 2018 16:05:18 -0500 Message-ID: <152244391852.135666.14903825998610307052.stgit@bhelgaas-glaptop.roam.corp.google.com> In-Reply-To: <152244269202.135666.3064353823697623332.stgit@bhelgaas-glaptop.roam.corp.google.com> References: <152244269202.135666.3064353823697623332.stgit@bhelgaas-glaptop.roam.corp.google.com> User-Agent: StGit/0.18 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tal Gilboa Add pcie_print_link_status(). This logs the current settings of the link (speed, width, and total available bandwidth). If the device is capable of more bandwidth but is limited by a slower upstream link, we include information about the link that limits the device's performance. The user may be able to move the device to a different slot for better performance. This provides a unified method for all PCI devices to report status and issues, instead of each device reporting in a different way, using different code. Signed-off-by: Tal Gilboa [bhelgaas: changelog, reword log messages, print device capabilities when not limited] Signed-off-by: Bjorn Helgaas --- drivers/pci/pci.c | 29 +++++++++++++++++++++++++++++ include/linux/pci.h | 1 + 2 files changed, 30 insertions(+) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index e00d56b12747..cec7aed09f6b 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -5283,6 +5283,35 @@ u32 pcie_bandwidth_capable(struct pci_dev *dev, enum pci_bus_speed *speed, return *width * PCIE_SPEED2MBS_ENC(*speed); } +/** + * pcie_print_link_status - Report the PCI device's link speed and width + * @dev: PCI device to query + * + * Report the available bandwidth at the device. If this is less than the + * device is capable of, report the device's maximum possible bandwidth and + * the upstream link that limits its performance to less than that. + */ +void pcie_print_link_status(struct pci_dev *dev) +{ + enum pcie_link_width width, width_cap; + enum pci_bus_speed speed, speed_cap; + struct pci_dev *limiting_dev = NULL; + u32 bw_avail, bw_cap; + + bw_cap = pcie_bandwidth_capable(dev, &speed_cap, &width_cap); + bw_avail = pcie_bandwidth_available(dev, &limiting_dev, &speed, &width); + + if (bw_avail >= bw_cap) + pci_info(dev, "%d Mb/s available bandwidth (%s x%d link)\n", + bw_cap, PCIE_SPEED2STR(speed_cap), width_cap); + else + pci_info(dev, "%d Mb/s available bandwidth, limited by %s x%d link at %s (capable of %d Mb/s with %s x%d link)\n", + bw_avail, PCIE_SPEED2STR(speed), width, + limiting_dev ? pci_name(limiting_dev) : "", + bw_cap, PCIE_SPEED2STR(speed_cap), width_cap); +} +EXPORT_SYMBOL(pcie_print_link_status); + /** * pci_select_bars - Make BAR mask from the type of resource * @dev: the PCI device for which BAR mask is made diff --git a/include/linux/pci.h b/include/linux/pci.h index f2bf2b7a66c7..38f7957121ef 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1086,6 +1086,7 @@ int pcie_get_minimum_link(struct pci_dev *dev, enum pci_bus_speed *speed, u32 pcie_bandwidth_available(struct pci_dev *dev, struct pci_dev **limiting_dev, enum pci_bus_speed *speed, enum pcie_link_width *width); +void pcie_print_link_status(struct pci_dev *dev); void pcie_flr(struct pci_dev *dev); int __pci_reset_function_locked(struct pci_dev *dev); int pci_reset_function(struct pci_dev *dev);