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: Alexandru Gagniuc X-Patchwork-Id: 924049 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="FNB4/ZVL"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40y6x55q1gz9ry1 for ; Sat, 2 Jun 2018 01:01:45 +1000 (AEST) 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 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; }