From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 13FDAFD88D8 for ; Wed, 11 Mar 2026 02:10:50 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4fVvNm2lwfz3bTf; Wed, 11 Mar 2026 13:10:48 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip=220.197.31.76 ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1773195048; cv=none; b=fRP4w/Wg7o+en2egJQEEc4pWXR3bLpMuJaJa/Naobu1A4c3EYMUMv0Sz7B0ae68FI/H9PlvluKUcDkId1ASUHhryWAQHIvRolBj1BZkDX2xngiVey3NrFWufVqBUMhzbHyIGdrSwjnVjxHvOrgqyM0ZbnxT+H1VZoCx4uk0d6E6OZFliiEzeZg9odJSLE9AvJhmqFQpH8EGUUr2G11hevtE1/oKXKLfpeu5RBRM4vB92rd6m1ER5i7mAKIeyQg5OrDQvgyG2WBQ5BCu06gI25sqAjNgOkadGcQvB/Rx9miPAzbqObusYjJxGfjqgJl10gDJzxqCBf9ipI577iY1eJw== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1773195048; c=relaxed/relaxed; bh=sd2Fc6FSnG2d3pMTg14GqePnOxYc9BQqdVSkTf9LTHs=; h=Cc:Subject:To:References:From:Message-ID:Date:MIME-Version: In-Reply-To:Content-Type; b=TRp5zFribQ/YK1/I0hWTrDukotXweq6qvIeRYIWbCyQBZt8G2c59fFIwhJKyEjlPPdbbjWIDNemWN9M8NNRR8U28oNl8gkiTFS+nDiJscXDJY56TORKng2N9lv+/sEiSPZxP7R56zCaYCAmWOmTaucVdAoMDaMh1qc3F3hXcQobonwwxTDyEvRK5q/cN4bCol1IIF4V8u/swSTcs1gcMJf1+FHvbcZ1iX7lRcLYm8sImJWmBCekcRePQrWOhn59+f+f1u4DVTfVYPachrPfm84pA6eiBQVXrxNQyrLscNDwA7Pfk70HHM9TcXRzmT4KkncDDj7X/ZA3emn0httoFuA== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=rock-chips.com; dkim=pass (1024-bit key; unprotected) header.d=rock-chips.com header.i=@rock-chips.com header.a=rsa-sha256 header.s=default header.b=kfOdNE3E; dkim-atps=neutral; spf=pass (client-ip=220.197.31.76; helo=mail-m1973176.qiye.163.com; envelope-from=shawn.lin@rock-chips.com; receiver=lists.ozlabs.org) smtp.mailfrom=rock-chips.com Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=rock-chips.com Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=rock-chips.com header.i=@rock-chips.com header.a=rsa-sha256 header.s=default header.b=kfOdNE3E; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=rock-chips.com (client-ip=220.197.31.76; helo=mail-m1973176.qiye.163.com; envelope-from=shawn.lin@rock-chips.com; receiver=lists.ozlabs.org) X-Greylist: delayed 4214 seconds by postgrey-1.37 at boromir; Wed, 11 Mar 2026 13:10:44 AEDT Received: from mail-m1973176.qiye.163.com (mail-m1973176.qiye.163.com [220.197.31.76]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4fVvNh3mlxz30hq for ; Wed, 11 Mar 2026 13:10:40 +1100 (AEDT) Received: from [172.16.12.17] (unknown [58.22.7.114]) by smtp.qiye.163.com (Hmail) with ESMTP id 3678c56ad; Wed, 11 Mar 2026 08:55:03 +0800 (GMT+08:00) Cc: shawn.lin@rock-chips.com, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-rockchip@lists.infradead.org, Niklas Cassel , Wilfred Mallawa , Krishna Chaitanya Chundru , Lukas Wunner , Richard Zhu , Brian Norris , Wilson Ding , Frank Li Subject: Re: [PATCH v7 2/4] PCI: host-common: Add link down handling for Root Ports To: manivannan.sadhasivam@oss.qualcomm.com, Bjorn Helgaas , Mahesh J Salgaonkar , Oliver O'Halloran , Will Deacon , Lorenzo Pieralisi , =?UTF-8?Q?Krzysztof_Wilczy=c5=84ski?= , Manivannan Sadhasivam , Rob Herring , Heiko Stuebner , Philipp Zabel References: <20260310-pci-port-reset-v7-0-9dd00ccc25ab@oss.qualcomm.com> <20260310-pci-port-reset-v7-2-9dd00ccc25ab@oss.qualcomm.com> From: Shawn Lin Message-ID: <2eb738fb-9dfe-1e88-6ea7-afdba9cb3d25@rock-chips.com> Date: Wed, 11 Mar 2026 08:55:01 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Archive: , List-Subscribe: , , List-Unsubscribe: Precedence: list MIME-Version: 1.0 In-Reply-To: <20260310-pci-port-reset-v7-2-9dd00ccc25ab@oss.qualcomm.com> Content-Type: text/plain; charset=gbk; format=flowed Content-Transfer-Encoding: 8bit X-HM-Tid: 0a9cda63dc8f09cckunm38bfaea514eddb X-HM-MType: 1 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFDSUNOT01LS0k3V1ktWUFJV1kPCRoVCBIfWUFZQk4YGFZCS05KHUxLHRpNTUpWFRQJFh oXVRMBExYaEhckFA4PWVdZGBILWUFZTkNVSUlVTFVKSk9ZV1kWGg8SFR0UWUFZT0tIVUpLSU9PT0 hVSktLVUpCS0tZBg++ DKIM-Signature: a=rsa-sha256; b=kfOdNE3EOKnXsygqxi9846fL4/tfGrHHufMHhcZSqW9MTTTIqCuBGUX/zVyg7ioK37rllmhlXiocSZLOPtud5LXKachckvyWn7BGwp1H4lKUNHYY9AmWdtLUnJIF0u/fdulWGnBK2eSSI2LJdbit7/Qw5WUqh7Vhb7SNeSLBpJ4=; c=relaxed/relaxed; s=default; d=rock-chips.com; v=1; bh=sd2Fc6FSnG2d3pMTg14GqePnOxYc9BQqdVSkTf9LTHs=; h=date:mime-version:subject:message-id:from; Hi Mani ÔÚ 2026/03/10 ÐÇÆÚ¶þ 22:02, Manivannan Sadhasivam via B4 Relay дµÀ: > From: Manivannan Sadhasivam > > The PCI link, when down, needs to be recovered to bring it back. But on > some platforms, that cannot be done in a generic way as link recovery > procedure is platform specific. So add a new API > pci_host_handle_link_down() that could be called by the host bridge drivers > for a specific Root Port when the link goes down. > > The API accepts the 'pci_dev' corresponding to the Root Port which observed > the link down event. If CONFIG_PCIEAER is enabled, the API calls > pcie_do_recovery() function with 'pci_channel_io_frozen' as the state. This > will result in the execution of the AER Fatal error handling code. Since > the link down recovery is pretty much the same as AER Fatal error handling, > pcie_do_recovery() helper is reused here. First, the AER error_detected() > callback will be triggered for the bridge and then for the downstream > devices. Finally, pci_host_reset_root_port() will be called for the Root > Port, which will reset the Root Port using 'reset_root_port' callback to > recover the link. Once that's done, resume message will be broadcasted to > the bridge and the downstream devices, indicating successful link recovery. > > But if CONFIG_PCIEAER is not enabled in the kernel, only > pci_host_reset_root_port() API will be called, which will in turn call > pci_bus_error_reset() to just reset the Root Port as there is no way we > could inform the drivers about link recovery. > > Signed-off-by: Manivannan Sadhasivam > Signed-off-by: Manivannan Sadhasivam > Tested-by: Brian Norris > Tested-by: Krishna Chaitanya Chundru > Tested-by: Richard Zhu > Reviewed-by: Frank Li > --- > drivers/pci/controller/pci-host-common.c | 35 ++++++++++++++++++++++++++++++++ > drivers/pci/controller/pci-host-common.h | 1 + > drivers/pci/pci.c | 1 + > drivers/pci/pcie/err.c | 1 + > 4 files changed, 38 insertions(+) > > diff --git a/drivers/pci/controller/pci-host-common.c b/drivers/pci/controller/pci-host-common.c > index d6258c1cffe5..15ebff8a542a 100644 > --- a/drivers/pci/controller/pci-host-common.c > +++ b/drivers/pci/controller/pci-host-common.c > @@ -12,9 +12,11 @@ > #include > #include > #include > +#include > #include > #include > > +#include "../pci.h" > #include "pci-host-common.h" > > static void gen_pci_unmap_cfg(void *ptr) > @@ -106,5 +108,38 @@ void pci_host_common_remove(struct platform_device *pdev) > } > EXPORT_SYMBOL_GPL(pci_host_common_remove); > > +static pci_ers_result_t pci_host_reset_root_port(struct pci_dev *dev) > +{ > + int ret; > + > + pci_lock_rescan_remove(); > + ret = pci_bus_error_reset(dev); > + pci_unlock_rescan_remove(); > + if (ret) { > + pci_err(dev, "Failed to reset Root Port: %d\n", ret); > + return PCI_ERS_RESULT_DISCONNECT; > + } > + > + pci_info(dev, "Root Port has been reset\n"); > + > + return PCI_ERS_RESULT_RECOVERED; > +} > + > +static void pci_host_recover_root_port(struct pci_dev *port) > +{ > +#if IS_ENABLED(CONFIG_PCIEAER) > + pcie_do_recovery(port, pci_channel_io_frozen, pci_host_reset_root_port); > +#else > + pci_host_reset_root_port(port); Since pci_host_reset_root_port() returns pci_ers_result_t, shouldn't we check the result? If the return value is intentionally ignored here, maybe pci_host_reset_root_port actually doesn't need a return value at all? > +#endif > +} > + > +void pci_host_handle_link_down(struct pci_dev *port) > +{ > + pci_info(port, "Recovering Root Port due to Link Down\n"); > + pci_host_recover_root_port(port); > +} > +EXPORT_SYMBOL_GPL(pci_host_handle_link_down); This function shouldn't be called like in interrupt context because of the pci_lock_rescan_remove() and pci_bus_error_reset()::pci_slot_mutex, but it's not so obvious from the API name. It's prone for host drivers to use it like: register_LDn_irq -> irq isr -> pci_host_handle_link_down() So perhaps add a comment about it would be better. > + > MODULE_DESCRIPTION("Common library for PCI host controller drivers"); > MODULE_LICENSE("GPL v2"); > diff --git a/drivers/pci/controller/pci-host-common.h b/drivers/pci/controller/pci-host-common.h > index b5075d4bd7eb..dd12dd1a1b23 100644 > --- a/drivers/pci/controller/pci-host-common.h > +++ b/drivers/pci/controller/pci-host-common.h > @@ -17,6 +17,7 @@ int pci_host_common_init(struct platform_device *pdev, > struct pci_host_bridge *bridge, > const struct pci_ecam_ops *ops); > void pci_host_common_remove(struct platform_device *pdev); > +void pci_host_handle_link_down(struct pci_dev *port); > > struct pci_config_window *pci_host_common_ecam_create(struct device *dev, > struct pci_host_bridge *bridge, const struct pci_ecam_ops *ops); > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c > index 6f09057d83e0..1b37bfe6d079 100644 > --- a/drivers/pci/pci.c > +++ b/drivers/pci/pci.c > @@ -5650,6 +5650,7 @@ int pci_bus_error_reset(struct pci_dev *bridge) > mutex_unlock(&pci_slot_mutex); > return pci_bus_reset(bridge->subordinate, PCI_RESET_DO_RESET); > } > +EXPORT_SYMBOL_GPL(pci_bus_error_reset); > > /** > * pci_probe_reset_bus - probe whether a PCI bus can be reset > diff --git a/drivers/pci/pcie/err.c b/drivers/pci/pcie/err.c > index 13b9d9eb714f..d77403d8855b 100644 > --- a/drivers/pci/pcie/err.c > +++ b/drivers/pci/pcie/err.c > @@ -292,3 +292,4 @@ pci_ers_result_t pcie_do_recovery(struct pci_dev *dev, > > return status; > } > +EXPORT_SYMBOL_GPL(pcie_do_recovery); >