From patchwork Mon Sep 3 18:02:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Alex G." X-Patchwork-Id: 10586317 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-2.web.codeaurora.org (Postfix) with ESMTP id EF96814BD for ; Mon, 3 Sep 2018 18:04:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E38CA28567 for ; Mon, 3 Sep 2018 18:04:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D7F2828BF1; Mon, 3 Sep 2018 18:04:24 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,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 90D0228567 for ; Mon, 3 Sep 2018 18:04:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727368AbeICWYT (ORCPT ); Mon, 3 Sep 2018 18:24:19 -0400 Received: from mail-oi0-f65.google.com ([209.85.218.65]:40269 "EHLO mail-oi0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727271AbeICWYT (ORCPT ); Mon, 3 Sep 2018 18:24:19 -0400 Received: by mail-oi0-f65.google.com with SMTP id l202-v6so2249320oig.7; Mon, 03 Sep 2018 11:03:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=P8070j0pHB8FWga0Ow2mDVroSkOVwLt7/K7gOaS7NoM=; b=IqwcvWw5xjRsU9a6k/euqg2vuXmsZW+BrOI6gKcrP5U/+5LttCMgeJq/cBoEyiF4iN fdt6l5vBB/ZAeVGY0xFf044Zx1JynUidYKUmJGYAn/EyQViicVy7/7W18r1GjZY8Bwsp 5NeQbegFUjD4z35dnRtu/qnJEyISCkvn4DyS8qRoitTHHiBjlOvMXnYhEC8jkNLCjQ8d e47rcLsT/TrJFgSUWRjoAhMGtSgV7rTUaquNzVDK8EywQepOVpC3XRjtgsMBhqQEbFUI tL0UE5YtSHGSfuafNvis7wAbXJ+lJRqKDar2kWcKdte6Y4c7daC+C3jinTRpIeGZzGb7 VHFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=P8070j0pHB8FWga0Ow2mDVroSkOVwLt7/K7gOaS7NoM=; b=SII0H03n2uqMqFaXnxGEQPXlfPmjBVP/STnOWUqwREHZzBEpvdI41sXhmp12r5WboL uypy2HnZGnrW0rwzFSVQCnRHDryvZDJESUKJZDfvz5k18hHafQ5wIHI8R7//cani5sNu hyiUm6Q7UfPDIfoZUoQsBdnDjl6g7o4vOl2TPt9dp6g7RoQd6kzvzW2AIOu7edK1qXJE fQ7P4ch5RWBCD6oYO15mm7a448H2OgqEsstPcB8TxfDScFJ5NNFDDHZu/Xy2pTOixFCQ J0N9uMWOiIMc9owfCywQAp1ol8nF6u2OWKNvuC3i1iXny531pLm1GmYBgBew0SyK1/SK jXZg== X-Gm-Message-State: APzg51BafY1VmPda4ZvMvhzmVz1Q6D3WwX4M1lwGoA1ZvGL9dsxKN50x UjSjGemnylXZOdbn/8XY+A4YJwJA6oM= X-Google-Smtp-Source: ANB0VdZpO2FfJq10Tc9XyyBRe0tbkdGETay7ed6FYojvwe8I8b/SN8T+5gmPDQRvUl1qKgrHWsjxAg== X-Received: by 2002:aca:bdc4:: with SMTP id n187-v6mr19765754oif.3.1535997781153; Mon, 03 Sep 2018 11:03:01 -0700 (PDT) Received: from nuclearis2-1.lan (c-98-195-139-126.hsd1.tx.comcast.net. [98.195.139.126]) by smtp.gmail.com with ESMTPSA id q124-v6sm15785737oif.8.2018.09.03.11.03.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 03 Sep 2018 11:03:00 -0700 (PDT) From: Alexandru Gagniuc To: linux-pci@vger.kernel.org, bhelgaas@google.com Cc: keith.busch@intel.com, alex_gagniuc@dellteam.com, austin_bolen@dell.com, shyam_iyer@dell.com, Alexandru Gagniuc , Ariel Elior , everest-linux-l2@cavium.com, "David S. Miller" , Michael Chan , Ganesh Goudar , Jeff Kirsher , Tariq Toukan , Saeed Mahameed , Leon Romanovsky , Jakub Kicinski , Dirk van der Merwe , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, intel-wired-lan@lists.osuosl.org, linux-rdma@vger.kernel.org, oss-drivers@netronome.com Subject: [PATCH 1/9] PCI: sysfs: Export available PCIe bandwidth Date: Mon, 3 Sep 2018 13:02:28 -0500 Message-Id: <20180903180242.14504-2-mr.nuke.me@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180903180242.14504-1-mr.nuke.me@gmail.com> References: <20180903180242.14504-1-mr.nuke.me@gmail.com> 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 For certain bandwidth-critical devices (e.g. multi-port network cards) it is useful to know the available bandwidth to the root complex. This information is only available via the system log, which doesn't account for link degradation after probing. With a sysfs attribute, we can computes the bandwidth on-demand, and will detect degraded links. Signed-off-by: Alexandru Gagniuc --- drivers/pci/pci-sysfs.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 9ecfe13157c0..6658e927b1f5 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -218,6 +218,18 @@ static ssize_t current_link_width_show(struct device *dev, } static DEVICE_ATTR_RO(current_link_width); +static ssize_t available_bandwidth_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct pci_dev *pci_dev = to_pci_dev(dev); + u32 bw_avail; + + bw_avail = pcie_bandwidth_available(pci_dev, NULL, NULL, NULL); + + return sprintf(buf, "%u.%03u Gb/s\n", bw_avail / 1000, bw_avail % 1000); +} +static DEVICE_ATTR_RO(available_bandwidth); + static ssize_t secondary_bus_number_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -786,6 +798,7 @@ static struct attribute *pcie_dev_attrs[] = { &dev_attr_current_link_width.attr, &dev_attr_max_link_width.attr, &dev_attr_max_link_speed.attr, + &dev_attr_available_bandwidth.attr, NULL, };