Received: by 10.213.65.68 with SMTP id h4csp53768imn; Fri, 30 Mar 2018 14:06:46 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/GxZGMywfH5ZYMtcsn1BXcEzzmcafjw7WEYJCL+g+VuIH5PKAIt29CuyVZPWRE1uLlWHhj X-Received: by 2002:a17:902:2941:: with SMTP id g59-v6mr563208plb.55.1522444006025; Fri, 30 Mar 2018 14:06:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522444005; cv=none; d=google.com; s=arc-20160816; b=TPbv4gFUgFehh2rr2/etuwmq2oc8uLUH6CCRZuZDcFmzKZIbrx/5yTfZfyfAVNX5D1 y8hmj5RmvgoeHjt2LYU9nrF0s9mFWXcJ/5LfZmwTmTckcHkjASF9bhDF3NeVNeZJqQ+H 9O99kWndmfzpdJw2Kzkm2cOZOWB9kqrgEYJPhibkZrHmrLh7YsQX9MmLKhQZ+rRsLqhk 5Tn+Z4gBiQjSgTHGowAaep0gprJi56ACtCePmTX/VLU8zP8140WECp1Gm46ks5CuYbQi AVBAjx9W5lHBn+TlcuicrZIzB+o0PqukmE1X4smI6AS8SX9ywl9IIsjvczXAkJ1J8r4e PZXA== 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=PHrIh0ZBY7dsOhpXaKg+NaX4iieteB/l65c6JEcJV4k=; b=LrV9mOkEDlGYetPkUPC1gTV6ntKsp3keW+UmEf1Da4ZIT5qQpNoP0PQ19hJ+g2EPoL ePMaYVu7JrJxXSFj+s1cclHi8Xt79nlVU53u8NuiGwlLtIUqAgcDL/QL+unG9gYU6QEK bRBeRpYHJjC96q1qK9dctg4wM9pQe+xZ/9jx9M/7IJcMMVxtdfaAUxjb2+5+ZMnSlnv2 a0zQpNXJAtVRB4jj3hyeHtex4Srba2votNiWdP7MDyVdffXA9POx5YJvMAgI1glilzjn 69jA1c+n+DD/v2kJahwvSoDqmxWEN7KMBwSJFpe6iECZTnTNHNEeiYFKQZiGUdJcxfjy vp9w== 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 e28si6085132pgn.621.2018.03.30.14.06.32; Fri, 30 Mar 2018 14:06:45 -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 S1752932AbeC3VFI (ORCPT + 99 others); Fri, 30 Mar 2018 17:05:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:33538 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752905AbeC3VFG (ORCPT ); Fri, 30 Mar 2018 17:05:06 -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 D617621777; Fri, 30 Mar 2018 21:05:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D617621777 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 03/14] PCI: Add pcie_bandwidth_capable() to compute max supported link bandwidth 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:03 -0500 Message-ID: <152244390359.135666.14890735614456271032.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_bandwidth_capable() to compute the max link bandwidth supported by a device, based on the max link speed and width, adjusted by the encoding overhead. The maximum bandwidth of the link is computed as: max_link_speed * max_link_width * (1 - encoding_overhead) The encoding overhead is about 20% for 2.5 and 5.0 GT/s links using 8b/10b encoding, and about 1.5% for 8 GT/s or higher speed links using 128b/130b encoding. Signed-off-by: Tal Gilboa [bhelgaas: adjust for pcie_get_speed_cap() and pcie_get_width_cap() signatures, don't export outside drivers/pci] Signed-off-by: Bjorn Helgaas Reviewed-by: Tariq Toukan --- drivers/pci/pci.c | 21 +++++++++++++++++++++ drivers/pci/pci.h | 9 +++++++++ 2 files changed, 30 insertions(+) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 43075be79388..9ce89e254197 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -5208,6 +5208,27 @@ enum pcie_link_width pcie_get_width_cap(struct pci_dev *dev) return PCIE_LNK_WIDTH_UNKNOWN; } +/** + * pcie_bandwidth_capable - calculates a PCI device's link bandwidth capability + * @dev: PCI device + * @speed: storage for link speed + * @width: storage for link width + * + * Calculate a PCI device's link bandwidth by querying for its link speed + * and width, multiplying them, and applying encoding overhead. + */ +u32 pcie_bandwidth_capable(struct pci_dev *dev, enum pci_bus_speed *speed, + enum pcie_link_width *width) +{ + *speed = pcie_get_speed_cap(dev); + *width = pcie_get_width_cap(dev); + + if (*speed == PCI_SPEED_UNKNOWN || *width == PCIE_LNK_WIDTH_UNKNOWN) + return 0; + + return *width * PCIE_SPEED2MBS_ENC(*speed); +} + /** * pci_select_bars - Make BAR mask from the type of resource * @dev: the PCI device for which BAR mask is made diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 66738f1050c0..2a50172b9803 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -261,8 +261,17 @@ void pci_disable_bridge_window(struct pci_dev *dev); (speed) == PCIE_SPEED_2_5GT ? "2.5 GT/s" : \ "Unknown speed") +/* PCIe speed to Mb/s with encoding overhead: 20% for gen2, ~1.5% for gen3 */ +#define PCIE_SPEED2MBS_ENC(speed) \ + ((speed) == PCIE_SPEED_8_0GT ? 7877 : \ + (speed) == PCIE_SPEED_5_0GT ? 4000 : \ + (speed) == PCIE_SPEED_2_5GT ? 2000 : \ + 0) + enum pci_bus_speed pcie_get_speed_cap(struct pci_dev *dev); enum pcie_link_width pcie_get_width_cap(struct pci_dev *dev); +u32 pcie_bandwidth_capable(struct pci_dev *dev, enum pci_bus_speed *speed, + enum pcie_link_width *width); /* Single Root I/O Virtualization */ struct pci_sriov {