Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp4586582rwd; Sun, 11 Jun 2023 10:24:01 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4ncn8jflz0uI+PlX3J3u6aaIH+1YZhcF7n2cGWgXDeGoWdWBPq3rJc5Nrrasqs3gBTP3sR X-Received: by 2002:aa7:d4cf:0:b0:514:a6af:e299 with SMTP id t15-20020aa7d4cf000000b00514a6afe299mr4141732edr.23.1686504241175; Sun, 11 Jun 2023 10:24:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686504241; cv=none; d=google.com; s=arc-20160816; b=l2SVV9/3fTjWrZhkcl/o76fh+E7Wg+2Xz4XlzMHo8c9X+O5jFQqJaQeBiRQJcX1LUW pT+oVj5qliDc2uMY+oSL/4EOVK6T7kQbsmUIJqVioPjzStNrXC5J/r1SYOhb01rZA9N8 HKiWnvu4KY7kWW5Al/5JthKow9jiCDr7+DCzXW4vAxJbRozcQmZaJmzUi1VDn395GeGI YW3E2V3fnyPSfa8tbOc8IhSaaCBOobHBmSDcKFKhHw7thpMURUNHchOfkT9EGhbmyJGF 1+18zefQBI2aJoRLWRRrNgwDlUk34W7LCSD5Maa3NWKr+8jZZrA7u/Omhc81JlbSnNgb 3N2w== 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=QhepCUpNLnlqRgEnGy56jFx9bcSEiD1T348n+Bh6hqw=; b=AIVYRtiamhrzNu5ckH9Fz0GsHeFBXbk9yV2R1VNAocoCYJn7JNh6+TV81omWAMoM76 A2a3WNbJINJLRLN0SjyqrGen8bK3iuOAZhj98sfsk9IuEC/i3927W+RspAs0SlZdNcjK q5NM0fY92lhUIE3JEIT66QWwnY87t7O74MJQDfuN/Epmj9p3Fx3eQPMwh8buaWoIbQA+ zvWCV5ptb1ElywJ72zWJnoOtZVdv4iTh685WfcSd0+meolwMgSPbaL9dEprOtXXzAh5B l6HPfOD0BZ7Bs5EL8Q34XwcWWXfovPTog6Wcq5AQ7vjBJe8pRqIOdhV5awAHE2F8JtFT fFgw== 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 l20-20020a056402125400b00514945a72d3si5325510edw.352.2023.06.11.10.23.36; Sun, 11 Jun 2023 10:24:01 -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 S233894AbjFKRU5 (ORCPT + 99 others); Sun, 11 Jun 2023 13:20:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230233AbjFKRUz (ORCPT ); Sun, 11 Jun 2023 13:20:55 -0400 Received: from angie.orcam.me.uk (angie.orcam.me.uk [IPv6:2001:4190:8020::34]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7BCA110D0; Sun, 11 Jun 2023 10:20:29 -0700 (PDT) Received: by angie.orcam.me.uk (Postfix, from userid 500) id 90AD99200C1; Sun, 11 Jun 2023 19:19:49 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id 8B5119200B3; Sun, 11 Jun 2023 18:19:49 +0100 (BST) Date: Sun, 11 Jun 2023 18:19:49 +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 09/14] PCI: Factor our waiting for link training end 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 Move code polling for the Link Training bit to clear into a function of its own. Signed-off-by: Maciej W. Rozycki --- New change in v9. --- drivers/pci/pci.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) linux-pcie-wait-for-link-status.diff Index: linux-macro/drivers/pci/pci.c =================================================================== --- linux-macro.orig/drivers/pci/pci.c +++ linux-macro/drivers/pci/pci.c @@ -4850,6 +4850,28 @@ static int pci_pm_reset(struct pci_dev * } /** + * pcie_wait_for_link_status - Wait for link training end + * @pdev: Device whose link to wait for. + * + * Return TRUE if successful, or FALSE if training has not completed + * within PCIE_LINK_RETRAIN_TIMEOUT_MS milliseconds. + */ +static bool pcie_wait_for_link_status(struct pci_dev *pdev) +{ + unsigned long end_jiffies; + u16 lnksta; + + end_jiffies = jiffies + msecs_to_jiffies(PCIE_LINK_RETRAIN_TIMEOUT_MS); + do { + pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, &lnksta); + if (!(lnksta & PCI_EXP_LNKSTA_LT)) + break; + msleep(1); + } while (time_before(jiffies, end_jiffies)); + return !(lnksta & PCI_EXP_LNKSTA_LT); +} + +/** * pcie_wait_for_link_delay - Wait until link is active or inactive * @pdev: Bridge device * @active: waiting for active or inactive? @@ -4916,14 +4938,11 @@ bool pcie_wait_for_link(struct pci_dev * * pcie_retrain_link - Request a link retrain and wait for it to complete * @pdev: Device whose link to retrain. * - * Return TRUE if successful, or FALSE if training has not completed - * within PCIE_LINK_RETRAIN_TIMEOUT_MS milliseconds. + * Return TRUE if successful, or FALSE if training has not completed. */ bool pcie_retrain_link(struct pci_dev *pdev) { - unsigned long end_jiffies; u16 lnkctl; - u16 lnksta; pcie_capability_read_word(pdev, PCI_EXP_LNKCTL, &lnkctl); lnkctl |= PCI_EXP_LNKCTL_RL; @@ -4938,15 +4957,7 @@ bool pcie_retrain_link(struct pci_dev *p pcie_capability_write_word(pdev, PCI_EXP_LNKCTL, lnkctl); } - /* Wait for link training end. Break out after waiting for timeout. */ - end_jiffies = jiffies + msecs_to_jiffies(PCIE_LINK_RETRAIN_TIMEOUT_MS); - do { - pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, &lnksta); - if (!(lnksta & PCI_EXP_LNKSTA_LT)) - break; - msleep(1); - } while (time_before(jiffies, end_jiffies)); - return !(lnksta & PCI_EXP_LNKSTA_LT); + return pcie_wait_for_link_status(pdev); } /*