From patchwork Fri Jun 1 15:01:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Alex G." X-Patchwork-Id: 10443695 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.web.codeaurora.org (Postfix) with ESMTP id 2EA81602BC for ; Fri, 1 Jun 2018 15:02:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 16F2028DFD for ; Fri, 1 Jun 2018 15:02:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0462528DE7; Fri, 1 Jun 2018 15:02:46 +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=ham 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 C21EF28ED5 for ; Fri, 1 Jun 2018 15:01:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751964AbeFAPBn (ORCPT ); Fri, 1 Jun 2018 11:01:43 -0400 Received: from mail-oi0-f65.google.com ([209.85.218.65]:43618 "EHLO mail-oi0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751780AbeFAPBm (ORCPT ); Fri, 1 Jun 2018 11:01:42 -0400 Received: by mail-oi0-f65.google.com with SMTP id t133-v6so19140370oif.10; Fri, 01 Jun 2018 08:01:42 -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; bh=qdSHSJJYKha67mq4tZMq1pk+W+0pGKDArzhwBkb47kI=; b=FNB4/ZVL/vxfGItkfzSyibZnI9Jme5bYC1BfUzJINjug3XbMe9JGumfIAL2i8N+hKi OSbtiQKjT6kBZUSI2x7cMhQ6B+s1vpldBT9/GWa/Gkc2nm5/o+Splc6qAttyM/fNSafS QwAmcsOOhZYx9WmNPxX/MmxBnCtaI9MpmpSW2LjNHgXeb4ZJ8L91/mxpy5qm2lHc0qKb Vc/Tjpb6HefgWOj5SwE3HQtAGgoK5WFaXU1wRsZfkCIKcA23eaT9vGj5F3Vkg5f/kZgQ hO+X0SJ9vceoJnr8VE5qdk2FMYdUvNcJ2Eb5dQiP++JyvfID/jDyfTZiQ4Ujiryb3EOf B/7w== 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; bh=qdSHSJJYKha67mq4tZMq1pk+W+0pGKDArzhwBkb47kI=; b=cpSAK6fa6abWWwd0F5Im8XzyJoimZU9zA4KpAX66OHxfd1vkRatDo3ydGjQ18TqMed 9QCs1c+3DViOIdtpyIo6KuKoHFxNIjd7laq3LRgkd7b9eX3AGxf7uohh3b8BVlwyaBr0 Yf7rDbeMMukAh7MhIfHbOhaGi0VeYba49+zA0yK9si5AarTOF1PQfULXS1fvdZntzdMc 8wT3PkpCC4uiEDbA06qViKl6A7i1y2vqyjPHh4TMk/7D/FF2QZF8ty/ajFOjn460F7I3 vt4/ysIblE3QZPPKdnXJ6//MkpzAThn1tqY1CfWBp8g71TesBlQ6Oy83S6hBM9MY73s0 Zv+g== X-Gm-Message-State: ALKqPweC7micmh09ZmFjKMW+aH1zwSgsAgPPMpr/DRdNFiO2tvFLbcDx 8fUOxi/heE13Oyuf7clqaoU= X-Google-Smtp-Source: ADUXVKI26PSQUaitHgNiel9kvljudeCTKVZMFJSbhn2oseIOVXNqb/Ik4JdRfcHJzaU5cWJ88A6nRg== X-Received: by 2002:aca:f545:: with SMTP id t66-v6mr3578092oih.316.1527865299065; Fri, 01 Jun 2018 08:01:39 -0700 (PDT) Received: from nuclearis2_1.lan (c-98-201-114-184.hsd1.tx.comcast.net. [98.201.114.184]) by smtp.gmail.com with ESMTPSA id u35-v6sm3983439otc.27.2018.06.01.08.01.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Jun 2018 08:01:38 -0700 (PDT) From: Alexandru Gagniuc To: bhelgaas@google.com Cc: alex_gagniuc@dellteam.com, austin_bolen@dell.com, shyam_iyer@dell.com, keith.busch@intel.com, okaya@codeaurora.org, Alexandru Gagniuc , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] PCI: Check for PCIe downtraining conditions Date: Fri, 1 Jun 2018 10:01:24 -0500 Message-Id: <20180601150129.10486-1-mr.nuke.me@gmail.com> X-Mailer: git-send-email 2.14.3 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 PCIe downtraining happens when both the device and PCIe port are capable of a larger bus width or higher speed than negotiated. Downtraining might be indicative of other problems in the system, and identifying this from userspace is neither intuitive, nor straigh forward. The easiest way to detect this is with pcie_print_link_status(), since the bottleneck is usually the link that is downtrained. It's not a perfect solution, but it works extremely well in most cases. Signed-off-by: Alexandru Gagniuc --- drivers/pci/probe.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index ac91b6fd0bcd..e8e158046cab 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -2146,6 +2146,25 @@ static struct pci_dev *pci_scan_device(struct pci_bus *bus, int devfn) return dev; } +static void pcie_check_upstream_link(struct pci_dev *dev) +{ + + if (!pci_is_pcie(dev)) + return; + + /* Look from the device up to avoid downstream ports with no devices. */ + if ((pci_pcie_type(dev) != PCI_EXP_TYPE_ENDPOINT) && + (pci_pcie_type(dev) != PCI_EXP_TYPE_LEG_END) && + (pci_pcie_type(dev) != PCI_EXP_TYPE_UPSTREAM)) + return; + + /* Multi-function PCIe share the same link/status. */ + if (PCI_FUNC(dev->devfn) != 0) + return; + + pcie_print_link_status(dev); +} + static void pci_init_capabilities(struct pci_dev *dev) { /* Enhanced Allocation */ @@ -2181,6 +2200,9 @@ static void pci_init_capabilities(struct pci_dev *dev) /* Advanced Error Reporting */ pci_aer_init(dev); + /* Check link and detect downtrain errors */ + pcie_check_upstream_link(dev); + if (pci_probe_reset_function(dev) == 0) dev->reset_fn = 1; }