Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1158090rwl; Fri, 7 Apr 2023 10:47:34 -0700 (PDT) X-Google-Smtp-Source: AKy350Y0Lyv6Myn8Y3lT7gw8/BnZvQJKK8NjcreXpVPyqcUdiUBZr0/xcjT+2HvOSZItaoIBhh6T X-Received: by 2002:a62:1c15:0:b0:626:e177:fc64 with SMTP id c21-20020a621c15000000b00626e177fc64mr3267965pfc.19.1680889654102; Fri, 07 Apr 2023 10:47:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680889654; cv=none; d=google.com; s=arc-20160816; b=ymw703fMlawFhAyL00bZWEXduzjkAczfQElN7SL5VH3priwb4rRf++IKbM0YhYoDur sIMhOIzbxojg0426CjBKHp9kyQi8ys/tCA4Rj5hq7bl+cogb59/6WuFwsBSjxw/DZnqL 587992uz64YtnoAihEkHh2mPepMXzkGO3KvbR9wLpiGvThyBUBO87kLT+5sPu/XmEJ70 Z6kwIx6kB4hgElvODsdZz/E5SOMXlyiawCtCb0Xbqh7Y8yeO1FzlF/qw4cIbgiDEYhdI +oaMGZFgYDvWdZOuUQ/47HLyrG3hNYH/6EsfjSWP+44H0DQodD61j8mSqsd+2HVEajpd 0o5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=UXdyG/RfpW67IAK948wzPl6enRAxhE2VH4M4A+6dxLY=; b=i2W3v6xZrsCAr05Gz7yTNC/Y1Lftl4vML0L+RLz7HXOP+Kq7Kr4WfBDtARl4SAIyWf K9WgC6oYM3zxkJDy9tH9oCcwXKSSKspWD8pRZSPPUeTrown21izFtneG4c5RjTUKgHuy N6aTRWmzdaBctsP3rpwS4FeU4HCOwPU8KxaOJb3RmbTubOGPXB/snXgDHbP9j+fOP+Zb 5+2tlCbJRmXj6QpVgKn1cZV8TQ+nzVsvECwdijITVVyBexUTeYmj+7Koyn/E7TXfM7Lw gYxJPzJSPGG1Mc5rNBcs6Xx9MW5Fr8qtwzNIAhd5YuwoX6yFCSfYlkSbuz4ms7PtRvkM 7cdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=aJPtgnp0; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d8-20020a63fd08000000b00517a65a29a4si274943pgh.240.2023.04.07.10.47.22; Fri, 07 Apr 2023 10:47:34 -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; dkim=pass header.i=@google.com header.s=20210112 header.b=aJPtgnp0; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229675AbjDGRlM (ORCPT + 99 others); Fri, 7 Apr 2023 13:41:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230158AbjDGRk4 (ORCPT ); Fri, 7 Apr 2023 13:40:56 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5198DC67D for ; Fri, 7 Apr 2023 10:40:27 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1a19cf1b8ddso235675ad.0 for ; Fri, 07 Apr 2023 10:40:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680889206; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=UXdyG/RfpW67IAK948wzPl6enRAxhE2VH4M4A+6dxLY=; b=aJPtgnp01STnN8yZ3rHipVyVyZgjOzxzne2mzs6pTvXzp/G4hooxPtmYVr+/YFfusn xWjS367XvmxI+lSEj9tgNCitl894ECVtxCA0jj93itzczzCRzi6YKbjTzTJQWyp49Uyl 7IKE7boHEaHc0DAW+UElwh/r37V6YtW8IJ0m1erKskA5eAMkMuKaQ3DH7ReeKw/Cwwdx Rqu2Vzs8zlizu2r8nyKXY4gh84Y/f85znniWFhZXIABRz1AWuOhqz++n7YQpc5zCeAet OmzM+HyNgXYpFhlnI1VLHeJm+1prkIJsXtkWUkn6F+rdMuJwTqUWaG6jfEZ8w23iTzZK TGTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680889206; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=UXdyG/RfpW67IAK948wzPl6enRAxhE2VH4M4A+6dxLY=; b=li8RSvHC17ziULfVfmOSvOb85QTP2McLJZ8lhxN1U9M5vVK3L3oxY0vCVrvzdNXxsX CqMPmwsCW+trDiMMCfsk5GKukJeav7iXQ8masLfkLQtusME3DN+97sHDQBYiXxqfYHDg HBCFBdMVgYZw3DLZwr86cwpJDf+GRnLLajCprpuHretNllNhCryC23zwQ8KhUUbSvtH5 0sdgCr5RnXx1Av/40C5bwPgqrAJxc8KVlUOZnjvNOhV1NmJkOflXlvOYOG2YRYzzYFCR vPFCN7Z9oHvg4a5jiMvB0Sp8FejZVmFM/Mj5BlRLvxyuDgF6eE+ntB6yaNOkFpbemVpz euCQ== X-Gm-Message-State: AAQBX9e8TZ0j9fNlCZxWpa0cde/XAQpkM4SroNJn2DnaDLwT8Qsm2GgW Rl2rz6BncYesYmncz9qNy5FMsoRdk0pcI5n0xVdye2hdEfRlONhPXB1z91CpKiDhe65nBsESRuf NM7eX0yK2/StKdS1Ipy4VYVmTUZtstYM= X-Received: by 2002:a17:902:7b8b:b0:198:af4f:de07 with SMTP id w11-20020a1709027b8b00b00198af4fde07mr227612pll.7.1680889205786; Fri, 07 Apr 2023 10:40:05 -0700 (PDT) Received: from google.com (13.65.82.34.bc.googleusercontent.com. [34.82.65.13]) by smtp.gmail.com with ESMTPSA id w20-20020a17090a529400b002367325203fsm1374874pjh.50.2023.04.07.10.40.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Apr 2023 10:40:05 -0700 (PDT) Date: Fri, 7 Apr 2023 10:40:01 -0700 From: William McVicker To: Ajay Agarwal Cc: Bjorn Helgaas , Lorenzo Pieralisi , Sajid Dalvi , Han Jingoo , Bjorn Helgaas , Gustavo Pimentel , Krzysztof =?utf-8?Q?Wilczy=C5=84ski?= , Rob Herring , kernel-team@android.com, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Krzysztof Kozlowski Subject: Re: [PATCH v2] PCI: dwc: Wait for link up only if link is started Message-ID: References: <20230405182753.GA3626483@bhelgaas> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-ccpol: medium X-Spam-Status: No, score=-14.7 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,ENV_AND_HDR_SPF_MATCH, HK_RANDOM_ENVFROM,HK_RANDOM_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=no 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 On 04/06/2023, 'Ajay Agarwal' via kernel-team wrote: > Here is my attempt at a patch which can satisfy all the requirements > (Ideally, I did not want to use `pci->ops` in the host driver but I > could not figure out any other way): > > diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c > b/drivers/pci/controller/dwc/pcie-designware-host.c > index 9952057c8819..39c7219ec7c9 100644 > --- a/drivers/pci/controller/dwc/pcie-designware-host.c > +++ b/drivers/pci/controller/dwc/pcie-designware-host.c > @@ -485,15 +485,18 @@ int dw_pcie_host_init(struct dw_pcie_rp *pp) > if (ret) > goto err_remove_edma; > > - if (!dw_pcie_link_up(pci)) { > - ret = dw_pcie_start_link(pci); > + ret = dw_pcie_start_link(pci); > + if (ret) > + goto err_remove_edma; > + > + if (dw_pcie_link_up(pci)) { > + dw_pcie_print_link_status(pci); > + } else if (pci->ops && pci->ops->start_link) { > + ret = dw_pcie_wait_for_link(pci); > if (ret) > - goto err_remove_edma; > + goto err_stop_link; > } > > - /* Ignore errors, the link may come up later */ > - dw_pcie_wait_for_link(pci); > - > bridge->sysdata = pp; > > ret = pci_host_probe(bridge); > diff --git a/drivers/pci/controller/dwc/pcie-designware.c b/drivers/pci/controller/dwc/pcie-designware.c > index 53a16b8b6ac2..03748a8dffd3 100644 > --- a/drivers/pci/controller/dwc/pcie-designware.c > +++ b/drivers/pci/controller/dwc/pcie-designware.c > @@ -644,9 +644,20 @@ void dw_pcie_disable_atu(struct dw_pcie *pci, u32 dir, int index) > dw_pcie_writel_atu(pci, dir, index, PCIE_ATU_REGION_CTRL2, 0); > } > > -int dw_pcie_wait_for_link(struct dw_pcie *pci) > +void dw_pcie_print_link_status(struct dw_pcie *pci) > { > u32 offset, val; > + > + offset = dw_pcie_find_capability(pci, PCI_CAP_ID_EXP); > + val = dw_pcie_readw_dbi(pci, offset + PCI_EXP_LNKSTA); > + > + dev_info(pci->dev, "PCIe Gen.%u x%u link up\n", > + FIELD_GET(PCI_EXP_LNKSTA_CLS, val), > + FIELD_GET(PCI_EXP_LNKSTA_NLW, val)); > +} > + > +int dw_pcie_wait_for_link(struct dw_pcie *pci) > +{ > int retries; > > /* Check if the link is up or not */ > @@ -662,12 +673,7 @@ int dw_pcie_wait_for_link(struct dw_pcie *pci) > return -ETIMEDOUT; > } > > - offset = dw_pcie_find_capability(pci, PCI_CAP_ID_EXP); > - val = dw_pcie_readw_dbi(pci, offset + PCI_EXP_LNKSTA); > - > - dev_info(pci->dev, "PCIe Gen.%u x%u link up\n", > - FIELD_GET(PCI_EXP_LNKSTA_CLS, val), > - FIELD_GET(PCI_EXP_LNKSTA_NLW, val)); > + dw_pcie_print_link_status(pci); > > return 0; > } > diff --git a/drivers/pci/controller/dwc/pcie-designware.h b/drivers/pci/controller/dwc/pcie-designware.h > index 79713ce075cc..615660640801 100644 > --- a/drivers/pci/controller/dwc/pcie-designware.h > +++ b/drivers/pci/controller/dwc/pcie-designware.h > @@ -429,6 +429,7 @@ void dw_pcie_setup(struct dw_pcie *pci); > void dw_pcie_iatu_detect(struct dw_pcie *pci); > int dw_pcie_edma_detect(struct dw_pcie *pci); > void dw_pcie_edma_remove(struct dw_pcie *pci); > +void dw_pcie_print_link_status(struct dw_pcie *pci); > > static inline void dw_pcie_writel_dbi(struct dw_pcie *pci, u32 reg, u32 val) > { > > -- > To unsubscribe from this group and stop receiving emails from it, send an email to kernel-team+unsubscribe@android.com. > Thanks Ajay for the follow-up patch! I've tested it out on a Pixel 6 and it's working as intended for me. Probing the PCIe RC device now only take 0.02s vs ~1.02s. If others don't object, please send it as a v3 patch. Thanks, Will