Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp4601735rwd; Sun, 11 Jun 2023 10:46:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6/MdYQY0paHpKPq9NT/MvCSHne+pqgWv/5sJFD0CB0qXEBoXtv7kBr1Y0j+pLS356FI/RX X-Received: by 2002:a17:906:db0a:b0:977:befe:d888 with SMTP id xj10-20020a170906db0a00b00977befed888mr7294612ejb.13.1686505590640; Sun, 11 Jun 2023 10:46:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686505590; cv=none; d=google.com; s=arc-20160816; b=eeKJIj39NgaBvGi0xyp6BYl6bo28knmVFs4JI8aePj8K4xOrnL1AtyojwJbXKovHy1 66TrC0BRNvKJ5ToUZekTEdMQkP9eUWvfAeNLRvSeIwP5d9QWbmhckVDj2g2K86CjHS0x 0ubEC2quNAy8e3lfq3XkQXptqVonJi9kyR+Om8LhhMpmGWvWGKzy4BqgeX+oflTfxRP9 nsNYkAmZJERsBL4IgRAV2cYtDxLLxRJDsJ3yAAzJ0Q+Ls2Vy9QYgUvHT9Ja39Gj/kkjq x+Kwwlbymg8FxSWR5TKwVivZk2ZlEcc9TZb1Ih7E6t1ix7idgk/7gcn3aUOngUWgceaz ww2g== 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=wxFbgfcf6cePRRo7BQ18Bwqcp+ZIA/mUf2+kMM7tUaM=; b=c+8L1+yFSUenAOy8+j6pjxLuOjhn2pA+Tnaz+m5AKSjnUUiIaJK6wKtUSAuXFgIHaM o1kb2ih7Cj8g3HGPiBiq1ftaPPI1qVZjSeUu3x99CigxvnPpNNMAYUUEyojHs6tWIRzw 9AxrtQdxSdjao4MisY10J2eUxchxWinBkMlsCRgSl/E+vcrH9vBX9F0p7tznR43GTIPp s+wuB6mbs6XB4iWq+ztsPIz2DquWoDvKzF2zW1xqC4VUkjVCo5c7tP+432JLP+89eUD/ M2YhPAs2jaJoB9T4Ya7FGWEjepa8R1z1XmSzLO8GnL/BRSh8w8mIfsj+cSJULi/MXDfs 4qCA== 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 qw7-20020a170906fca700b00978970d5573si4124006ejb.156.2023.06.11.10.46.06; Sun, 11 Jun 2023 10:46:30 -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 S234012AbjFKRVR (ORCPT + 99 others); Sun, 11 Jun 2023 13:21:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233888AbjFKRVN (ORCPT ); Sun, 11 Jun 2023 13:21:13 -0400 X-Greylist: delayed 92 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Sun, 11 Jun 2023 10:20:49 PDT Received: from angie.orcam.me.uk (angie.orcam.me.uk [78.133.224.34]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E45F71700; Sun, 11 Jun 2023 10:20:48 -0700 (PDT) Received: by angie.orcam.me.uk (Postfix, from userid 500) id 4E8B29200C6; Sun, 11 Jun 2023 19:19:53 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id 4858E9200B3; Sun, 11 Jun 2023 18:19:53 +0100 (BST) Date: Sun, 11 Jun 2023 18:19:53 +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 10/14] PCI: Add support for polling DLLLA to `pcie_retrain_link' 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 Let the caller of `pcie_retrain_link' specify whether they want to use the LT bit or the DLLLA bit of the Link Status Register to determine if link training has completed. It is up to the caller to verify whether the use of the DLLLA bit, the implementation of which is optional, is valid for the device requested. Signed-off-by: Maciej W. Rozycki --- New change in v9. --- drivers/pci/pci.c | 28 ++++++++++++++++++++-------- drivers/pci/pci.h | 2 +- drivers/pci/pcie/aspm.c | 2 +- 3 files changed, 22 insertions(+), 10 deletions(-) linux-pcie-retrain-link-use-lt.diff Index: linux-macro/drivers/pci/pci.c =================================================================== --- linux-macro.orig/drivers/pci/pci.c +++ linux-macro/drivers/pci/pci.c @@ -4850,25 +4850,32 @@ static int pci_pm_reset(struct pci_dev * } /** - * pcie_wait_for_link_status - Wait for link training end + * pcie_wait_for_link_status - Wait for link status change * @pdev: Device whose link to wait for. + * @use_lt: Use the LT bit if TRUE, or the DLLLA bit if FALSE. + * @active: Waiting for active or inactive? * - * 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 status has not changed within + * PCIE_LINK_RETRAIN_TIMEOUT_MS milliseconds. */ -static bool pcie_wait_for_link_status(struct pci_dev *pdev) +static bool pcie_wait_for_link_status(struct pci_dev *pdev, + bool use_lt, bool active) { + u16 lnksta_mask, lnksta_match; unsigned long end_jiffies; u16 lnksta; + lnksta_mask = use_lt ? PCI_EXP_LNKSTA_LT : PCI_EXP_LNKSTA_DLLLA; + lnksta_match = active ? lnksta_mask : 0; + 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)) + if ((lnksta & lnksta_mask) == lnksta_match) break; msleep(1); } while (time_before(jiffies, end_jiffies)); - return !(lnksta & PCI_EXP_LNKSTA_LT); + return (lnksta & lnksta_mask) == lnksta_match; } /** @@ -4937,10 +4944,15 @@ 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. + * @use_lt: Use the LT bit if TRUE, or the DLLLA bit if FALSE, for status. + * + * Retrain completion status is retrieved from the Link Status Register + * according to @use_lt. It is not verified whether the use of the DLLLA + * bit is valid. * * Return TRUE if successful, or FALSE if training has not completed. */ -bool pcie_retrain_link(struct pci_dev *pdev) +bool pcie_retrain_link(struct pci_dev *pdev, bool use_lt) { u16 lnkctl; @@ -4957,7 +4969,7 @@ bool pcie_retrain_link(struct pci_dev *p pcie_capability_write_word(pdev, PCI_EXP_LNKCTL, lnkctl); } - return pcie_wait_for_link_status(pdev); + return pcie_wait_for_link_status(pdev, use_lt, !use_lt); } /* Index: linux-macro/drivers/pci/pci.h =================================================================== --- linux-macro.orig/drivers/pci/pci.h +++ linux-macro/drivers/pci/pci.h @@ -561,7 +561,7 @@ pci_ers_result_t pcie_do_recovery(struct pci_ers_result_t (*reset_subordinates)(struct pci_dev *pdev)); bool pcie_wait_for_link(struct pci_dev *pdev, bool active); -bool pcie_retrain_link(struct pci_dev *pdev); +bool pcie_retrain_link(struct pci_dev *pdev, bool use_lt); #ifdef CONFIG_PCIEASPM void pcie_aspm_init_link_state(struct pci_dev *pdev); void pcie_aspm_exit_link_state(struct pci_dev *pdev); Index: linux-macro/drivers/pci/pcie/aspm.c =================================================================== --- linux-macro.orig/drivers/pci/pcie/aspm.c +++ linux-macro/drivers/pci/pcie/aspm.c @@ -257,7 +257,7 @@ static void pcie_aspm_configure_common_c reg16 &= ~PCI_EXP_LNKCTL_CCC; pcie_capability_write_word(parent, PCI_EXP_LNKCTL, reg16); - if (pcie_retrain_link(link->pdev)) + if (pcie_retrain_link(link->pdev, true)) return; /* Training failed. Restore common clock configurations */