From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from angie.orcam.me.uk (angie.orcam.me.uk [78.133.224.34]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8F5F9443F; Sat, 10 Feb 2024 01:43:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=78.133.224.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707529440; cv=none; b=OlSvyn8wjt16tihq5cWVRxti2vz0SYyM2DqUktN4CN5dGH6/mQvMMdpj+RfFRkJm/Xz0O/FPeQCs1loCUWEqmgO7zFF09du8k9BMf6Zo//y7+iMWh88hUpCqXavgg8wX5McqdLL/4j+onCE77F7R5GTPCuTqrrjAaAwXR10hy3s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707529440; c=relaxed/simple; bh=ypgalr47NyKd3kk8vG+pac3NhdZUcsYOC4TTXs6GuPM=; h=Date:From:To:cc:Subject:In-Reply-To:Message-ID:References: MIME-Version:Content-Type; b=tLFlZBap3/HhVOexYwLZzu8czqJuoXA4ljCGztuhSn4A7ty8uE+bbQV5gphYsfhSp/KXvMLjvcKs1wBLN13dG5Xu5m94ypTjh3Y+Tsy6mPrM/djGKluRhKrWZA3yMGDc7KhE4w2IcE97oz3bYB2P8ilHMTq6PtlE8awxQvonEK4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=orcam.me.uk; spf=none smtp.mailfrom=orcam.me.uk; arc=none smtp.client-ip=78.133.224.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=orcam.me.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=orcam.me.uk Received: by angie.orcam.me.uk (Postfix, from userid 500) id 7C32392009D; Sat, 10 Feb 2024 02:43:50 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id 7524092009B; Sat, 10 Feb 2024 01:43:50 +0000 (GMT) Date: Sat, 10 Feb 2024 01:43:50 +0000 (GMT) From: "Maciej W. Rozycki" To: =?UTF-8?Q?Ilpo_J=C3=A4rvinen?= , Bjorn Helgaas cc: Mika Westerberg , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] PCI: Correct error reporting with PCIe failed link retraining In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Only return successful completion status from `pcie_failed_link_retrain' if retraining has actually been done, preventing excessive delays from being triggered at call sites in a hope that communication will finally be established with the downstream device where in fact nothing has been done about the link in question that would justify such a hope. Fixes: a89c82249c37 ("PCI: Work around PCIe link training failures") Reported-by: Ilpo Järvinen Link: https://lore.kernel.org/r/aa2d1c4e-9961-d54a-00c7-ddf8e858a9b0@linux.intel.com/ Signed-off-by: Maciej W. Rozycki Cc: stable@vger.kernel.org # v6.5+ --- drivers/pci/quirks.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) linux-pcie-failed-link-retrain-status-fix.diff Index: linux-macro/drivers/pci/quirks.c =================================================================== --- linux-macro.orig/drivers/pci/quirks.c +++ linux-macro/drivers/pci/quirks.c @@ -74,7 +74,8 @@ * firmware may have already arranged and lift it with ports that already * report their data link being up. * - * Return TRUE if the link has been successfully retrained, otherwise FALSE. + * Return TRUE if the link has been successfully retrained, otherwise FALSE, + * also when retraining was not needed in the first place. */ bool pcie_failed_link_retrain(struct pci_dev *dev) { @@ -83,10 +84,11 @@ bool pcie_failed_link_retrain(struct pci {} }; u16 lnksta, lnkctl2; + bool ret = false; if (!pci_is_pcie(dev) || !pcie_downstream_port(dev) || !pcie_cap_has_lnkctl2(dev) || !dev->link_active_reporting) - return false; + return ret; pcie_capability_read_word(dev, PCI_EXP_LNKCTL2, &lnkctl2); pcie_capability_read_word(dev, PCI_EXP_LNKSTA, &lnksta); @@ -98,9 +100,10 @@ bool pcie_failed_link_retrain(struct pci lnkctl2 |= PCI_EXP_LNKCTL2_TLS_2_5GT; pcie_capability_write_word(dev, PCI_EXP_LNKCTL2, lnkctl2); - if (pcie_retrain_link(dev, false)) { + ret = pcie_retrain_link(dev, false) == 0; + if (!ret) { pci_info(dev, "retraining failed\n"); - return false; + return ret; } pcie_capability_read_word(dev, PCI_EXP_LNKSTA, &lnksta); @@ -117,13 +120,14 @@ bool pcie_failed_link_retrain(struct pci lnkctl2 |= lnkcap & PCI_EXP_LNKCAP_SLS; pcie_capability_write_word(dev, PCI_EXP_LNKCTL2, lnkctl2); - if (pcie_retrain_link(dev, false)) { + ret = pcie_retrain_link(dev, false) == 0; + if (!ret) { pci_info(dev, "retraining failed\n"); - return false; + return ret; } } - return true; + return ret; } static ktime_t fixup_debug_start(struct pci_dev *dev,