From patchwork Sun Feb 20 19:33:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 12752862 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 76A47C433EF for ; Sun, 20 Feb 2022 19:43:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=jxN+frA/WNDk4HKiN7vR2KNDfvdv6CHzLVBmQ7t6H0Q=; b=Qc2pEa8RsDMDHc +uj56dxkc1gTN94fjy7gaVJFZF5iAy1ZgyHc7++n+dxHKwUyt0Dlx6j060yD7LaiRUW8o324b8Qk+ fsQWQyqZJbBPq9Cuyn0mhVctYgVZ8xnb/Rs5jecexNf5bhe5tpD0UQoWIPyaKndgxPAAiaHX+fKFS EheckPkuEnzHcW/vk4rQJ2mubN/06tT1hYSxF06gjdc9Q7Tm1H6ayuPYGZ+YCkAKg74LvQhDZAR21 B4d/vRZ97wjk4cBydccf3LqG3jU+GSFFMG29TLSU/zt+0IhTqYMui7f7b1jboBiLJLQhoNW58btAj tJMqd/PsZoa7XaiSBdrg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nLs5g-002Eul-SC; Sun, 20 Feb 2022 19:41:53 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nLrya-002BNq-EH for linux-arm-kernel@lists.infradead.org; Sun, 20 Feb 2022 19:34:34 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D61DC60EEC; Sun, 20 Feb 2022 19:34:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C3BF8C340F4; Sun, 20 Feb 2022 19:34:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1645385671; bh=rWN+zuCR+QaLyNXILzPI7B6HtbipzlDCeGNmUfj9SqM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GiUXC22uH9eP/yGCkvyXjld9Mkvn2uBOkLrlbBPgdeo/h+1afA6E4PiQndo7uGrQl 08wBiTDQndfwjn+U10xyiZRuScTrAUzkn9x2SCAWqByDqWwmnX+EndGGRBqkYcZI0U 0e1iUJv/gy9pQHuH1c4i0kl9h2gv2PV0eeBGhOyaiJMnAKvKiLMz48lA0XMJ9rKYBo IxQPvQ36KgByFtUnVxLbURaibRtddxZtHA06UgY4nhoNoG3iDetKaLorrGI0Hn4j+T 66RIh80pZMqf9SLnTpVAwck47wRpPMTssi39nUV1v04VYjKJ2KZ4rsanjM01Jmgy1x jkc5f3RXRvT+A== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: Lorenzo Pieralisi , Bjorn Helgaas Cc: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Marc Zyngier , pali@kernel.org, linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Gregory CLEMENT , =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH 17/18] PCI: aardvark: Run link training in separate worker Date: Sun, 20 Feb 2022 20:33:45 +0100 Message-Id: <20220220193346.23789-18-kabel@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220220193346.23789-1-kabel@kernel.org> References: <20220220193346.23789-1-kabel@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220220_113432_613949_2B6F4256 X-CRM114-Status: GOOD ( 18.62 ) 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 From: Pali Rohár Link training and PCIe card reset routines in Aardvark contain several delays, resulting in rather slow PCIe card probing. The worst case is when there is no card connected: the driver tries link training at all possible speeds and waits until all timers expire. Since probe methods for all system devices are called sequentially, this results in noticeably longer boot time. Move card reset and link training code from driver probe function into a separate worker, so that kernel can do something different while the driver is waiting during reset or training. On ESPRESSObin and Turris MOX this decreases boot time by 0.4s with plugged PCIe card and by 2.2s if no card is connected. Signed-off-by: Pali Rohár Signed-off-by: Marek Behún --- drivers/pci/controller/pci-aardvark.c | 42 ++++++++++++++++++--------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/drivers/pci/controller/pci-aardvark.c b/drivers/pci/controller/pci-aardvark.c index 8c9ac7766ac7..056f49d0e3a4 100644 --- a/drivers/pci/controller/pci-aardvark.c +++ b/drivers/pci/controller/pci-aardvark.c @@ -26,6 +26,7 @@ #include #include #include +#include #include "../pci.h" #include "../pci-bridge-emul.h" @@ -296,6 +297,8 @@ struct advk_pcie { int link_gen; bool link_was_up; struct timer_list link_irq_timer; + struct delayed_work probe_card_work; + bool host_bridge_probed; struct pci_bridge_emul bridge; struct gpio_desc *reset_gpio; struct clk *clk; @@ -497,6 +500,21 @@ static void advk_pcie_train_link(struct advk_pcie *pcie) dev_err(dev, "link never came up\n"); } +static void advk_pcie_probe_card_work(struct work_struct *work) +{ + struct delayed_work *dwork = container_of(work, struct delayed_work, + work); + struct advk_pcie *pcie = container_of(dwork, struct advk_pcie, + probe_card_work); + struct pci_host_bridge *bridge = pci_host_bridge_from_priv(pcie); + int ret; + + advk_pcie_train_link(pcie); + ret = pci_host_probe(bridge); + if (!ret) + pcie->host_bridge_probed = true; +} + /* * Set PCIe address window register which could be used for memory * mapping. @@ -701,8 +719,6 @@ static void advk_pcie_setup_hw(struct advk_pcie *pcie) /* Disable remaining PCIe outbound windows */ for (i = pcie->wins_count; i < OB_WIN_COUNT; i++) advk_pcie_disable_ob_win(pcie, i); - - advk_pcie_train_link(pcie); } static int advk_pcie_check_pio_status(struct advk_pcie *pcie, bool allow_crs, u32 *val) @@ -2112,14 +2128,8 @@ static int advk_pcie_probe(struct platform_device *pdev) bridge->ops = &advk_pcie_ops; bridge->map_irq = advk_pcie_map_irq; - ret = pci_host_probe(bridge); - if (ret < 0) { - irq_set_chained_handler_and_data(pcie->irq, NULL, NULL); - advk_pcie_remove_rp_irq_domain(pcie); - advk_pcie_remove_msi_irq_domain(pcie); - advk_pcie_remove_irq_domain(pcie); - return ret; - } + INIT_DELAYED_WORK(&pcie->probe_card_work, advk_pcie_probe_card_work); + schedule_delayed_work(&pcie->probe_card_work, 1); return 0; } @@ -2131,11 +2141,15 @@ static int advk_pcie_remove(struct platform_device *pdev) u32 val; int i; + cancel_delayed_work_sync(&pcie->probe_card_work); + /* Remove PCI bus with all devices */ - pci_lock_rescan_remove(); - pci_stop_root_bus(bridge->bus); - pci_remove_root_bus(bridge->bus); - pci_unlock_rescan_remove(); + if (pcie->host_bridge_probed) { + pci_lock_rescan_remove(); + pci_stop_root_bus(bridge->bus); + pci_remove_root_bus(bridge->bus); + pci_unlock_rescan_remove(); + } /* Disable Root Bridge I/O space, memory space and bus mastering */ val = advk_readl(pcie, PCIE_CORE_CMD_STATUS_REG);