Received: by 10.213.65.68 with SMTP id h4csp1866567imn; Sun, 1 Apr 2018 17:42:52 -0700 (PDT) X-Google-Smtp-Source: AIpwx49OKy07c4bm341qM2YOQG28Dp4VsGO1k+Fta7CxB4nAdas/3B1sVpYi0mkuOjHmD1LXt5gI X-Received: by 2002:a17:902:20cb:: with SMTP id v11-v6mr8058578plg.82.1522629772532; Sun, 01 Apr 2018 17:42:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522629772; cv=none; d=google.com; s=arc-20160816; b=j6ocApC/gGFEpeAdcNfTNjKUtnAf6AgsAGkZnADVnofhj/OndYo0Ca5Pj2arws3tam sbLhbx1dn4+f6clFoQwNFmGiri6HHMQRE3ryxwYBfwFmTmbc7aKOkoaWLM0VRfp4Foif oLKMNH82EX+Zqoq5TbTccizE/5tooF4GALR7k3KnTpXYIlbe4HaKefOeSX2sY2IzV73e QuJoFME0kWy5tS4tYq1bh7ZShtaSM7PRMHinGya+a75wCdhHsbU4Yut482UzjLEVHDKn 63IFKBXe5eqw1sd/DR3sd1rD9IPbSO9JuQgrUKvgiGuKMNN3uY/yteK1XV2yLjv4Y+Q3 AQlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dmarc-filter:arc-authentication-results; bh=FggZoTex1bzLFh5WazcJnO1s4Me+MEmD00JDfdkvqAQ=; b=y5hhKHXq+uwTteB0NPLzVzygY3+ROrgB+zQTeXpTVuvcv01dwbVEB1loJ3kmbHKyZN 52CpMwq5kT07+kw0oebI8b9n6APIfudgovZ51PJKGlYH3InaySuGKch/2H26l/QeQzmG 4D6ied3YByl2/+WfDTsUzarK3VBiVKJdah25JV3lrmCIX8COZmx5VcpAmVsDM7VJzgni c2GmU5PEBQyRY/n7a+Brq4kxskSt+3Qe4YqQYtEIEo6cFmG+YshL4Gz392UFD0KexumH pO4BBCYPJBPcBto4l/GWPMcyNSKybu1C8fTz7kwvJdzlTSYrW+8dEFjqKUR2fi1DK7Y7 NONQ== 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 b1-v6si13760688plc.95.2018.04.01.17.42.39; Sun, 01 Apr 2018 17:42:52 -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 S1754114AbeDBAlL (ORCPT + 99 others); Sun, 1 Apr 2018 20:41:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:50042 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753988AbeDBAlK (ORCPT ); Sun, 1 Apr 2018 20:41:10 -0400 Received: from localhost (13.sub-174-234-133.myvzw.com [174.234.133.13]) (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 555AF21723; Mon, 2 Apr 2018 00:41:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 555AF21723 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 Date: Sun, 1 Apr 2018 19:41:08 -0500 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 Subject: Re: [PATCH v5 04/14] PCI: Add pcie_bandwidth_available() to compute bandwidth available to device Message-ID: <20180402004107.GB131023@bhelgaas-glaptop.roam.corp.google.com> References: <152244269202.135666.3064353823697623332.stgit@bhelgaas-glaptop.roam.corp.google.com> <152244391143.135666.12548496808512444463.stgit@bhelgaas-glaptop.roam.corp.google.com> <7b82d160-002f-9687-ad80-5aaff639d7ab@mellanox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7b82d160-002f-9687-ad80-5aaff639d7ab@mellanox.com> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Apr 01, 2018 at 11:41:42PM +0300, Tal Gilboa wrote: > On 3/31/2018 12:05 AM, Bjorn Helgaas wrote: > > From: Tal Gilboa > > > > Add pcie_bandwidth_available() to compute the bandwidth available to a > > device. This may be limited by the device itself or by a slower upstream > > link leading to the device. > > > > The available bandwidth at each link along the path is computed as: > > > > link_speed * 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. > > > > Also return the device with the slowest link and the speed and width of > > that link. > > > > Signed-off-by: Tal Gilboa > > [bhelgaas: changelog, leave pcie_get_minimum_link() alone for now, return > > bw directly, use pci_upstream_bridge(), check "next_bw <= bw" to find > > uppermost limiting device, return speed/width of the limiting device] > > Signed-off-by: Bjorn Helgaas > > --- > > drivers/pci/pci.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ > > include/linux/pci.h | 3 +++ > > 2 files changed, 57 insertions(+) > > > > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c > > index 9ce89e254197..e00d56b12747 100644 > > --- a/drivers/pci/pci.c > > +++ b/drivers/pci/pci.c > > @@ -5146,6 +5146,60 @@ int pcie_get_minimum_link(struct pci_dev *dev, enum pci_bus_speed *speed, > > } > > EXPORT_SYMBOL(pcie_get_minimum_link); > > +/** > > + * pcie_bandwidth_available - determine minimum link settings of a PCIe > > + * device and its bandwidth limitation > > + * @dev: PCI device to query > > + * @limiting_dev: storage for device causing the bandwidth limitation > > + * @speed: storage for speed of limiting device > > + * @width: storage for width of limiting device > > + * > > + * Walk up the PCI device chain and find the point where the minimum > > + * bandwidth is available. Return the bandwidth available there and (if > > + * limiting_dev, speed, and width pointers are supplied) information about > > + * that point. > > + */ > > +u32 pcie_bandwidth_available(struct pci_dev *dev, struct pci_dev **limiting_dev, > > + enum pci_bus_speed *speed, > > + enum pcie_link_width *width) > > +{ > > + u16 lnksta; > > + enum pci_bus_speed next_speed; > > + enum pcie_link_width next_width; > > + u32 bw, next_bw; > > + > > + *speed = PCI_SPEED_UNKNOWN; > > + *width = PCIE_LNK_WIDTH_UNKNOWN; > > This is not safe anymore, now that we allow speed/width=NULL. Good catch, thanks!