Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3942262imw; Thu, 7 Jul 2022 10:00:17 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tostMiwhS4IPMJa1ZxYWTm7vCi0JoozQIx4CCq6h01LWmKUEgodFuXJv5FK885Bl/zcBaz X-Received: by 2002:a65:6bcc:0:b0:3f6:1815:f541 with SMTP id e12-20020a656bcc000000b003f61815f541mr39102689pgw.183.1657213217683; Thu, 07 Jul 2022 10:00:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657213217; cv=none; d=google.com; s=arc-20160816; b=XN7DV0B8EJHKgqySxC//y5lrIVzlWK4bsGdUiuIRmb+ZuUiPi3L625cmG+iWZl0Q1b i0YQfs/zVAnoRyJR4Rt2kc0JSUG0CrdpzfukR/ghwfIABGOPZen2beo78lD8UjcQiuvo OP6muCc0o6Pf6D4HFxtXILd0nX/quDJkuOv2Tc6whgIkVuty7sKrVTyCqV9QVWhL0ZQX vh8516pHWF2dRIUnX/vv4P3yL2FJFdaQ5xNZfNpt2/4FyiJT58zEV1WE8baEyKNRwQ+5 gNDzJvAlbA+2FZrvIvl7xWYBrgpwvgecdKHbEeskLS6OCdJGBEOk/GzxflCckOTL/pz8 q6YQ== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=1BT1AT3k3iZmUZypE3uU5mjcufGCXhMCCf//Wo7EMV0=; b=Xq+vlwXE8Ht5F8NLrvGhEnQEgrLgbiRnCpLnnZlSYNFmlZHCdprkKcpoiZSXG3PMhr 3kAK4broEOWx4JROMzFaoDdIz3cufHDKC3V90rqmuT9Y8Vda80hcAgOWpafruWFk5H+S M6ZKisQRMvhi8IfL8O/IOL4HgPme4PRWCGf7PO0DewbGxb7IBH/C5Xfb/AqYbKWDsFDN FCbQao55nMzEiP3aRiMxcP8zEXDx8ewMtNeMrQmJ0dv9Te1Q5FKVGE3jCUZbVQSDDnlu 4kXBsxYhAscYYSmvSj/JXdefllk6UFm4SOloqQ+9iVkQCaQo6x126Ww/uKM9AGnEN181 ovKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=C6bwjOBD; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d10-20020a634f0a000000b003f6229e2eabsi25389784pgb.843.2022.07.07.10.00.04; Thu, 07 Jul 2022 10:00:17 -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=@linaro.org header.s=google header.b=C6bwjOBD; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235799AbiGGQ4H (ORCPT + 99 others); Thu, 7 Jul 2022 12:56:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235638AbiGGQ4F (ORCPT ); Thu, 7 Jul 2022 12:56:05 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 021691D335 for ; Thu, 7 Jul 2022 09:56:04 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id l124so10191274pfl.8 for ; Thu, 07 Jul 2022 09:56:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=1BT1AT3k3iZmUZypE3uU5mjcufGCXhMCCf//Wo7EMV0=; b=C6bwjOBD52gxx6jkELTtK27C7o3ITQe946fB8fjzS8ygN3RVGrh0hDzKQd/5woWYsE qTvSUaTh9ZDRbZ8bNYVIoU4dSWpJ/04NsVHJL5wpZ0rxdLRmhPJPgNjwhxl9txmyAGYn hlLvBlzMhojacIdcbt4Ta5XayLq48MWFeC2/5yJRj7iI2h0PVujwu3jSqJ6kSD4dC9dR PrO/ST/nzyMl4a8jz5CLtFH2nhCk8yfdKFY/r3deEVhmp2ZoiSObgF9jQk4FYx/i5yoh +KWj4h2jQ1BYsYJ1j8jVx7Lp5/r+BfI3pSPvbPp4OSntUuYFCHqoHoEIDsL8JJYOyaKM Qyuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=1BT1AT3k3iZmUZypE3uU5mjcufGCXhMCCf//Wo7EMV0=; b=T1bHupCQAWa1hT5CPxNwVvEz7F+3vmfN2k0R1E+p+xoqaUkLWG1h4ZBy/MPDbgtGY/ /Ui6qW/e/FrlnFyOy5I3NN1Sev0UHFh7kegj16BFin/IbkotE+kKx9VfTgWfG+gpNfyN 1dKBBxbyTgi4PGJqnVLi7+BcOK17sobT+WmAYjIjckOtdFAPu6oVXyE1EGHjl5QAKQrX 1wHHCAbZ3ehn8QesqCHiF7i3rw+7C/2+mRaO8Wx9QtMgbIqXNipw3RGEP6jkUpXERmbL 4Kefjph5TAPlRrdVl6iYqU2M0lAF090TiV7VTDl/B/ppLrWaFlRPqLlFKAczp3MQ6YlN QSFQ== X-Gm-Message-State: AJIora9Br9ut2GzSVmqT7bAD8irPov762wjLV75Ep2IkqkAiPUo0gWbH 40cvtMVcaZCLnbJ3ngsVyW94 X-Received: by 2002:a63:d54c:0:b0:412:562e:6964 with SMTP id v12-20020a63d54c000000b00412562e6964mr16815009pgi.528.1657212963414; Thu, 07 Jul 2022 09:56:03 -0700 (PDT) Received: from thinkpad ([117.207.26.37]) by smtp.gmail.com with ESMTPSA id b123-20020a621b81000000b00528c22fbb45sm2927241pfb.141.2022.07.07.09.55.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jul 2022 09:56:03 -0700 (PDT) Date: Thu, 7 Jul 2022 22:25:56 +0530 From: Manivannan Sadhasivam To: Vidya Sagar Cc: jingoohan1@gmail.com, gustavo.pimentel@synopsys.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, kthota@nvidia.com, mmaddireddy@nvidia.com, sagar.tv@gmail.com Subject: Re: [PATCH V1] PCI: designware-ep: Fix DBI access before core init Message-ID: <20220707165556.GA5458@thinkpad> References: <20220622040133.31058-1-vidyas@nvidia.com> <5c36260c-6bb6-7eb5-be82-c60cd927c02d@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <5c36260c-6bb6-7eb5-be82-c60cd927c02d@nvidia.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,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 Hi, On Thu, Jul 07, 2022 at 02:39:08PM +0530, Vidya Sagar wrote: > Hi, > Anyone has review comments for this change? > Without this change, Tegra194's endpoint mode is effectively broken. > I submitted a patch that fixes this issue in March and I did CC you on that. https://lore.kernel.org/lkml/20220330060515.22328-1-manivannan.sadhasivam@linaro.org/ That patch incorporated comments from Kishon on the previous patch from Kunihiko Hayashi. But there was no response afterwards. Thanks, Mani > Thanks & Regards, > Vidya Sagar > > On 6/22/2022 9:31 AM, Vidya Sagar wrote: > > Platforms that cannot support their core initialization without the > > reference clock from the host, implement the feature 'core_init_notifier' > > to indicate the DesignWare sub-system about when their core is getting > > initialized. Any accesses to the core (Ex:- DBI) would result in system > > hang in such systems (Ex:- tegra194). This patch moves any access to the > > core to dw_pcie_ep_init_complete() API which is effectively called only > > after the core initialization. > > > > Signed-off-by: Vidya Sagar > > --- > > .../pci/controller/dwc/pcie-designware-ep.c | 88 +++++++++++-------- > > 1 file changed, 49 insertions(+), 39 deletions(-) > > > > diff --git a/drivers/pci/controller/dwc/pcie-designware-ep.c b/drivers/pci/controller/dwc/pcie-designware-ep.c > > index 0eda8236c125..9feec720175f 100644 > > --- a/drivers/pci/controller/dwc/pcie-designware-ep.c > > +++ b/drivers/pci/controller/dwc/pcie-designware-ep.c > > @@ -639,9 +639,14 @@ static unsigned int dw_pcie_ep_find_ext_capability(struct dw_pcie *pci, int cap) > > int dw_pcie_ep_init_complete(struct dw_pcie_ep *ep) > > { > > struct dw_pcie *pci = to_dw_pcie_from_ep(ep); > > + struct dw_pcie_ep_func *ep_func; > > + struct device *dev = pci->dev; > > + struct pci_epc *epc = ep->epc; > > unsigned int offset; > > unsigned int nbars; > > u8 hdr_type; > > + u8 func_no; > > + void *addr; > > u32 reg; > > int i; > > @@ -654,6 +659,42 @@ int dw_pcie_ep_init_complete(struct dw_pcie_ep *ep) > > return -EIO; > > } > > + dw_pcie_iatu_detect(pci); > > + > > + ep->ib_window_map = devm_kcalloc(dev, > > + BITS_TO_LONGS(pci->num_ib_windows), > > + sizeof(long), > > + GFP_KERNEL); > > + if (!ep->ib_window_map) > > + return -ENOMEM; > > + > > + ep->ob_window_map = devm_kcalloc(dev, > > + BITS_TO_LONGS(pci->num_ob_windows), > > + sizeof(long), > > + GFP_KERNEL); > > + if (!ep->ob_window_map) > > + return -ENOMEM; > > + > > + addr = devm_kcalloc(dev, pci->num_ob_windows, sizeof(phys_addr_t), > > + GFP_KERNEL); > > + if (!addr) > > + return -ENOMEM; > > + ep->outbound_addr = addr; > > + > > + for (func_no = 0; func_no < epc->max_functions; func_no++) { > > + ep_func = devm_kzalloc(dev, sizeof(*ep_func), GFP_KERNEL); > > + if (!ep_func) > > + return -ENOMEM; > > + > > + ep_func->func_no = func_no; > > + ep_func->msi_cap = dw_pcie_ep_find_capability(ep, func_no, > > + PCI_CAP_ID_MSI); > > + ep_func->msix_cap = dw_pcie_ep_find_capability(ep, func_no, > > + PCI_CAP_ID_MSIX); > > + > > + list_add_tail(&ep_func->list, &ep->func_list); > > + } > > + > > offset = dw_pcie_ep_find_ext_capability(pci, PCI_EXT_CAP_ID_REBAR); > > dw_pcie_dbi_ro_wr_en(pci); > > @@ -677,8 +718,6 @@ EXPORT_SYMBOL_GPL(dw_pcie_ep_init_complete); > > int dw_pcie_ep_init(struct dw_pcie_ep *ep) > > { > > int ret; > > - void *addr; > > - u8 func_no; > > struct resource *res; > > struct pci_epc *epc; > > struct dw_pcie *pci = to_dw_pcie_from_ep(ep); > > @@ -686,7 +725,6 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep) > > struct platform_device *pdev = to_platform_device(dev); > > struct device_node *np = dev->of_node; > > const struct pci_epc_features *epc_features; > > - struct dw_pcie_ep_func *ep_func; > > INIT_LIST_HEAD(&ep->func_list); > > @@ -708,8 +746,6 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep) > > } > > } > > - dw_pcie_iatu_detect(pci); > > - > > res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "addr_space"); > > if (!res) > > return -EINVAL; > > @@ -717,26 +753,6 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep) > > ep->phys_base = res->start; > > ep->addr_size = resource_size(res); > > - ep->ib_window_map = devm_kcalloc(dev, > > - BITS_TO_LONGS(pci->num_ib_windows), > > - sizeof(long), > > - GFP_KERNEL); > > - if (!ep->ib_window_map) > > - return -ENOMEM; > > - > > - ep->ob_window_map = devm_kcalloc(dev, > > - BITS_TO_LONGS(pci->num_ob_windows), > > - sizeof(long), > > - GFP_KERNEL); > > - if (!ep->ob_window_map) > > - return -ENOMEM; > > - > > - addr = devm_kcalloc(dev, pci->num_ob_windows, sizeof(phys_addr_t), > > - GFP_KERNEL); > > - if (!addr) > > - return -ENOMEM; > > - ep->outbound_addr = addr; > > - > > if (pci->link_gen < 1) > > pci->link_gen = of_pci_get_max_link_speed(np); > > @@ -753,20 +769,6 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep) > > if (ret < 0) > > epc->max_functions = 1; > > - for (func_no = 0; func_no < epc->max_functions; func_no++) { > > - ep_func = devm_kzalloc(dev, sizeof(*ep_func), GFP_KERNEL); > > - if (!ep_func) > > - return -ENOMEM; > > - > > - ep_func->func_no = func_no; > > - ep_func->msi_cap = dw_pcie_ep_find_capability(ep, func_no, > > - PCI_CAP_ID_MSI); > > - ep_func->msix_cap = dw_pcie_ep_find_capability(ep, func_no, > > - PCI_CAP_ID_MSIX); > > - > > - list_add_tail(&ep_func->list, &ep->func_list); > > - } > > - > > if (ep->ops->ep_init) > > ep->ops->ep_init(ep); > > @@ -790,6 +792,14 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep) > > return 0; > > } > > + /* > > + * NOTE:- Avoid accessing the hardware (Ex:- DBI space) before this > > + * step as platforms that implement 'core_init_notifier' feature may > > + * not have the hardware ready (i.e. core initialized) for access > > + * (Ex: tegra194). Any hardware access on such platforms result > > + * in system hard hang. > > + */ > > + > > return dw_pcie_ep_init_complete(ep); > > } > > EXPORT_SYMBOL_GPL(dw_pcie_ep_init); > > -- மணிவண்ணன் சதாசிவம்