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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 E1C04FD88D3 for ; Wed, 11 Mar 2026 00:55:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:MIME-Version:Date:Message-ID:From:References:To: Subject:Cc:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=sd2Fc6FSnG2d3pMTg14GqePnOxYc9BQqdVSkTf9LTHs=; b=GxExK7LO+6P0xxwRcDs9Upci3U YIAEMnGmu+I5RB/xLpDL+xu+sI5HvnNjqTUKsTK3+B9NbAfy4wTBbqUk8dWCGlYd2jtuko2ANcDIK g/+0cVtpzXs+VJ6GTV5oj9ohEy2/5qLZrTuQrMvz8p/xzTDOAwYfvDwTiQla7YTOfrEBWLkv76LD3 7LRrIsxjx+0wN7XGXUTUpCg5gYJXMCX6vkyyEVJ5qjOUc71+209JH7cGTHGxwhDh+7PU5F2mtwGPE ln8ccxZMHbfHwM7lfY2nj1sSV3+ckswzJPFv+mb5bgLO+M2dJ6r0oGFnMPJ8Quc3tYdDJBEZ1Op7q xmhunvHw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1w07r3-0000000ATGG-2ijk; Wed, 11 Mar 2026 00:55:17 +0000 Received: from mail-m32117.qiye.163.com ([220.197.32.117]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1w07qz-0000000ATFb-2qzu; Wed, 11 Mar 2026 00:55:15 +0000 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 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; X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260310_175514_223860_1A1F4DEA X-CRM114-Status: GOOD ( 32.37 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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); >