Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp4588754rwd; Sun, 11 Jun 2023 10:27:11 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5Aqe0Mkzi03tDnNWUUDMXvMnJ5fRHpB07Jhr7JlQ/1ezLy8WdT9kvlhtj4qjVhLzvQ2hz2 X-Received: by 2002:a17:907:3ea7:b0:978:9235:d450 with SMTP id hs39-20020a1709073ea700b009789235d450mr6383051ejc.9.1686504430882; Sun, 11 Jun 2023 10:27:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686504430; cv=none; d=google.com; s=arc-20160816; b=Z8/8rSwmCp3PRimndJNrEIpCybBgbe2EFD4WPYHCwV5FNGELfKGRRWXqxs4yngHfZk +N6Z8Y6Ivh1sHRDNg/ndCoJqjgN4YcJnD4ABLAj8V2r3agKe3ON/+ZarDrASkKvOxytf ht+d2FLWIJeVGUQgW/y0cYRegiytsD/k4mFuwn0DoqkQ325BwP5cljAII+lsYJoWcsVj pG5FJpZEkyKg7uRd+rNXnoC6t4alJPzPfyhp7IsK9S48hpLHqQWTRAMCnyjjdNYtkY4L 9CyQo8g4dm5wV2hXKFWYajwWu+KKD4391+fl9k24luFwaOhbMptXpDTalt2SN1DkxAy0 l5Rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:from:date; bh=4moH3bZ6fQEGY92Cg/cgHpWL81RAv3+VKZWLn1XfRq4=; b=cTlYOoE6L2+bPyM5c0OT74eOH0C7SrmrnY1f2uDweUydQb0Z+aIIasrFndMk9lXM7v zhB61IaIOMQw6Jq00NZahv1xqoeh3i1G3DC3WVED6XKbWsVxgAeq3PRiVefdyyyY4W4c 8GBnUotELtAanA4iZU1Yyic+1wkEhTZRcBG5IBLqGM1qSbJVMuCitc65FJn7qrEL3bSE aDGKqb3EsvR01hQwoaflmoMgHgnAe8rWZDyN2SVdkZwyBiLHoe4M977U4yFyY3QUWSEs yNFSj8H6ETRYFVgOyCJsO/TuFOIXMeeKSyUYJ7clOXvsT/tNRetpAWcJNWHEhdDfjguN ApUw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id by1-20020a0564021b0100b0051632dc69b3si4798811edb.263.2023.06.11.10.26.34; Sun, 11 Jun 2023 10:27:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234025AbjFKRVW (ORCPT + 99 others); Sun, 11 Jun 2023 13:21:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233992AbjFKRVT (ORCPT ); Sun, 11 Jun 2023 13:21:19 -0400 Received: from angie.orcam.me.uk (angie.orcam.me.uk [78.133.224.34]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CCE1719AA; Sun, 11 Jun 2023 10:20:54 -0700 (PDT) Received: by angie.orcam.me.uk (Postfix, from userid 500) id 6DEA69200CB; Sun, 11 Jun 2023 19:20:06 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id 66A4F9200CA; Sun, 11 Jun 2023 18:20:06 +0100 (BST) Date: Sun, 11 Jun 2023 18:20:06 +0100 (BST) From: "Maciej W. Rozycki" To: Bjorn Helgaas , Mahesh J Salgaonkar , Oliver O'Halloran , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Saeed Mahameed , Leon Romanovsky , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni cc: Alex Williamson , Lukas Wunner , Mika Westerberg , Stefan Roese , Jim Wilson , David Abdurachmanov , =?UTF-8?Q?Pali_Roh=C3=A1r?= , linux-pci@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-rdma@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v9 13/14] PCI: Add failed link recovery for device reset events In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Request failed link recovery with any upstream bridge where a device has not come back after reset within PCI_RESET_WAIT time. Reset the polling interval if recovery succeeded, otherwise continue as usual. Signed-off-by: Maciej W. Rozycki --- New change in v9, factored out from 7/7: - Remove duplicate succesful completion report previously added (not sure where it came from, possibly an unnoticed leftover from experiments). - Make the type of `retrain' variable `bool' rather than `int' and invert the logic used. - Rename `pcie_downstream_link_retrain' to `pcie_failed_link_retrain'. - Rename `pcie_upstream_link_retrain' to `pcie_parent_link_retrain'. Add documentation. --- drivers/pci/pci.c | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) linux-pcie-dev-wait-link-retrain.diff Index: linux-macro/drivers/pci/pci.c =================================================================== --- linux-macro.orig/drivers/pci/pci.c +++ linux-macro/drivers/pci/pci.c @@ -1146,10 +1146,27 @@ void pci_resume_bus(struct pci_bus *bus) pci_walk_bus(bus, pci_resume_one, NULL); } +/** + * pcie_parent_link_retrain - Check and retrain link we are downstream from + * @dev: PCI device to handle. + * + * Return TRUE if the link was retrained, FALSE otherwise. + */ +static bool pcie_parent_link_retrain(struct pci_dev *dev) +{ + struct pci_dev *bridge; + + bridge = pci_upstream_bridge(dev); + if (bridge) + return pcie_failed_link_retrain(bridge); + else + return false; +} + static int pci_dev_wait(struct pci_dev *dev, char *reset_type, int timeout) { + bool retrain = true; int delay = 1; - u32 id; /* * After reset, the device should not silently discard config @@ -1163,21 +1180,33 @@ static int pci_dev_wait(struct pci_dev * * Command register instead of Vendor ID so we don't have to * contend with the CRS SV value. */ - pci_read_config_dword(dev, PCI_COMMAND, &id); - while (PCI_POSSIBLE_ERROR(id)) { + for (;;) { + u32 id; + + pci_read_config_dword(dev, PCI_COMMAND, &id); + if (!PCI_POSSIBLE_ERROR(id)) + break; + if (delay > timeout) { pci_warn(dev, "not ready %dms after %s; giving up\n", delay - 1, reset_type); return -ENOTTY; } - if (delay > PCI_RESET_WAIT) + if (delay > PCI_RESET_WAIT) { + if (retrain) { + retrain = false; + if (pcie_parent_link_retrain(dev)) { + delay = 1; + continue; + } + } pci_info(dev, "not ready %dms after %s; waiting\n", delay - 1, reset_type); + } msleep(delay); delay *= 2; - pci_read_config_dword(dev, PCI_COMMAND, &id); } if (delay > PCI_RESET_WAIT)