From patchwork Mon Jun 4 15:55:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Alex G." X-Patchwork-Id: 925133 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="abVk2I3L"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40zzzp43Wwz9rvt for ; Tue, 5 Jun 2018 01:55:34 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751387AbeFDPzc (ORCPT ); Mon, 4 Jun 2018 11:55:32 -0400 Received: from mail-oi0-f66.google.com ([209.85.218.66]:39899 "EHLO mail-oi0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751362AbeFDPzb (ORCPT ); Mon, 4 Jun 2018 11:55:31 -0400 Received: by mail-oi0-f66.google.com with SMTP id t22-v6so25436746oih.6; Mon, 04 Jun 2018 08:55:31 -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=g9HeAxMVD2uQc2pxHBTrHkPYrMDEGdejU+hvT5c5IVA=; b=abVk2I3L30wS5HtOfNNj2ooloxbzlrAvJJPiZAdc978bFazAN93KDFBoQG7IhnFDuc yLAGChMJwBlzk8RaCfe5X47ll/wkrbk1MVzvt+fiI2b1X65gwDdHBpy7xkWWIFSgI/hY 2nnXa4je7I2HJAaRj6AIZ8aFCsshwi12PGQzlsaYPpCJoltF+32KQ4+VZDdiTI5Gtjuw 2rK6Ief4ze/WWnrSahVU25acdkXs8TFpMbid5vemlk6svyIZrdDbg/m+wRS9VAUiNPTa 4J8GGsZGr+RYLvWJov8EMz/7MLL5evCgbfxiOimWuuf46fNa3vNbKZo/YDbCI/CEFMlO EVxw== 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=g9HeAxMVD2uQc2pxHBTrHkPYrMDEGdejU+hvT5c5IVA=; b=Urxyyhw9rQpXpXFxegPISWaSp1c77G8U1RUvutnWU7VW6967wVMTKumyaRDUPmxIzq 91ex7c2EQKEGFGgaiEY5Vm8HjY4lPE9Mxc/7UDRZDW1/gXiUWBuqXK/UX/O3NqLBRS0d n3cTcV03Ck5PH2liz2kTQOEGrq9NPhJXCpIddjJ/J4AX2jDDWIY9LDUdYr6obDn2Px1M wxby/GbWdoEyX+674CgvKW5RDjT/zEsFCEOVFE1lrSw+T61IX0ipq4fTugWbv+WV6Z/R rmI3sF0YP5z7BkSCIc8a57SVBum36TE4Z5KS1z6HEPdgo+z6aJzeqE9fResdUOY8H8oi NPFQ== X-Gm-Message-State: APt69E1Wd83Rz15CnEsfrE7exiMUZuQtImYgfjMiuC80rmIQu8F8Rbz4 fMHWRPTpnotGu+QPPldI8OpiRFQYhK1NdA== X-Google-Smtp-Source: ADUXVKLvKfCZDsWEfwCJBB0dh3okyiJHvvWxNL+0NvEGa1sC723hb0rrT6j8nG7ym9Z1ZAQxxnsTrg== X-Received: by 2002:aca:e70c:: with SMTP id e12-v6mr12985093oih.312.1528127730690; Mon, 04 Jun 2018 08:55:30 -0700 (PDT) Received: from austins740xd.raid.adc.delllabs.net ([143.166.81.254]) by smtp.gmail.com with ESMTPSA id s144-v6sm5620946oie.17.2018.06.04.08.55.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 04 Jun 2018 08:55:30 -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, Alexandru Gagniuc , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3] PCI: Check for PCIe downtraining conditions Date: Mon, 4 Jun 2018 10:55:21 -0500 Message-Id: <20180604155523.14906-1-mr.nuke.me@gmail.com> X-Mailer: git-send-email 2.14.4 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 --- Changes since v2: - Check dev->is_virtfn flag Changes since v1: - Use pcie_print_link_status() instead of reimplementing logic drivers/pci/probe.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index ac91b6fd0bcd..a88ec8c25dd5 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) || dev->is_virtfn) + 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; }