Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1850736imm; Mon, 3 Sep 2018 11:04:33 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbjPiozuMvF3L3CraK6dRaPlkxgHBUWzMC5fNh8SMbWbh/nmVFkg9Vd+aSIioFov3Qqcej2 X-Received: by 2002:a62:444d:: with SMTP id r74-v6mr30542924pfa.96.1535997873370; Mon, 03 Sep 2018 11:04:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535997873; cv=none; d=google.com; s=arc-20160816; b=Ntmvb2eqLC46NtAmwNn03o0i3W1dUt3m2ydPajAxT17nBDbJQ/tmxUHTN2Qn/kfaTV J0y77VRS7IwY4o+DlfssjqOaiDULdmIoNxuXflglvFWXImqsaqzIqsOwnGBsvm5WMCAi 0QUA8r/bHD3QjzlwVANO9475M80AVJkR/Ezi1LyJm3DlPseSR9vU63UtlpbUivG4BYtX Y1759N88ck9gOkC1oGOsX8l/OUwtKH7vUhjshqFWT3eHMATp53td2imq98krp06CfN/W YQjosNs+wz7VClzAl932voJiLsggcTnv8trqSyXPc3oGPKz7AzS0mqlbpPooZ22At5tX y3Bw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=P8070j0pHB8FWga0Ow2mDVroSkOVwLt7/K7gOaS7NoM=; b=Wp5+NvPY/74dwBj7RtI+viKyTbixMriFmUCjPxJ7FV3NqhfouxEnR3MWJy8hKQBP/z rrTTKk1bmcgrxBcfX3Q5dKRqzJfQrIZ9u11q5YMhuBYGZW6o6PvSvVDtlGbKcSQj/M2J pyAS+MajDc9LN64fqHEjKmNL5HBSq2Ixzm0U+CidmLrM7br1c1HwNP7o2ZeTraozQesk YEVaOY4qAosbaDGZ8yFHV32GuAURvXT3xX7j6WvOkIX0P1AbRucNDZQvmQOwwNtlV0Da RaqZJLL4uWZF4+g5IqP+NqC29LlqxS01+SMwbh9WXXSSk6uK325V6C7X+T4z8IzAWE56 RNmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=IqwcvWw5; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 32-v6si18885109plc.475.2018.09.03.11.04.17; Mon, 03 Sep 2018 11:04:33 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=IqwcvWw5; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727507AbeICWYT (ORCPT + 99 others); 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-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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, }; -- 2.17.1