Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp909579imw; Fri, 15 Jul 2022 15:32:29 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vzoyUgZOghdrIB8Zs6GBgJLRpkNrbVIQgKKiRm6xlR73Zx1Ejlnl7ig8x1+8vX1bA+pLnD X-Received: by 2002:a63:195d:0:b0:412:50b8:c410 with SMTP id 29-20020a63195d000000b0041250b8c410mr13548720pgz.520.1657924349434; Fri, 15 Jul 2022 15:32:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657924349; cv=none; d=google.com; s=arc-20160816; b=PMdgoA1fupNLMT5LH19ojREtdyQqHvxjIvN9gZjpcNfNHH0+eAB13tgoxYrRscya71 4a/TzMO+bpNwuI9D64WmpP2Q47MIkt5wbT4k3cg2c2chAoQX4XXImIbmtTlXMRb2lNLF tjXHkr0grMZLJ3G6dlTSM+KSm2HN9pDzjxGRBi1GVmYsbP59EVCzjYiSToyPAAjsHqOT GtWqiJldeirqHaWemTVM4k8N/ujhgktraLf5IcxduC2bgsU8AhGZ7myMEtQ2h39O3OOg GVwITXoijH9Es9kLmMVaivRAAvkA1zVJ6EhmSiuO1nm4tW8MtrXVu3J03z6c9Pho8zwh 7yGQ== 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 :message-id:subject:cc:to:from:date:dkim-signature; bh=qTAUd6xfUA4XlneG5VOMk2MgvJNQtRJUNRQNRnZlLL4=; b=KfKlSErTS6OjBzaEgiD7gzbsfpVBO+OU3j++sSvJP9/zN/r4X2cLrwxR3YGKGVHOYJ kmO5S4d3d1+ISIF4qj6oJkQqh7r0Tz7bJ1AZa7tCo1Fv6/cl5RsT9zWhfA+rFMg5T3jc 49uJesBrN6KYkAn9Nl44D2+0Xa+W8vZQjcYtgB86Kw8JWvzVqnm/E8HK7D1ECm0DtbgE duH/T1JOwMaUmsVrVjeDpIGqUv7Pxf1Mz0kEIwCHvyFq8gN+O4gOqI20jXDlAN7thz6D u3dxqWNasn9q7r6YjusKStnpZYtTHG1kk7gGOrMWILP8sO+rtlDdOPuq9YmmeNC2Y+bO y/9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Z2gJ6D3i; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l14-20020a63570e000000b00409fc0f5d8esi6245451pgb.245.2022.07.15.15.32.14; Fri, 15 Jul 2022 15:32:29 -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=@kernel.org header.s=k20201202 header.b=Z2gJ6D3i; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231750AbiGOVkK (ORCPT + 99 others); Fri, 15 Jul 2022 17:40:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231761AbiGOVkE (ORCPT ); Fri, 15 Jul 2022 17:40:04 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DA2688CE3; Fri, 15 Jul 2022 14:40:02 -0700 (PDT) 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 116C960A0F; Fri, 15 Jul 2022 21:40:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 339CDC34115; Fri, 15 Jul 2022 21:40:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1657921201; bh=28348M0wJlqt7bCON1sYtP7vaFlfk8S+8wRDjWS1Cxk=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=Z2gJ6D3ihL8pqoPCUFlUHPoLyrpRDCndaPGgbv59vBtvDf7zymnGI5G9qUWh0Bdff RJ1zrTyPCeOLQxVxN9vAKlTCH+YnFlVz6qfbiCwK2Yf/uTMamleU5N3fUuEIHjxt3x BxD2gibsgt1ugIBLswHa+9+bK1x/DfuKSxPXcwiCUYUfOVti2MmrMfg+invHtXztKe lIuir2PcIbCcSGO39DRwDEsxaZylSnmbVbGlTI4xl5DFnwQNAHVw08ti5oy2mPzd4S cfmT1p7PDDkdINiCwNJd40heuPoMms83thl5FLMiD+u+FSqUWR0dsWsxJRJeqTzbrK rknbd2vI565+Q== Date: Fri, 15 Jul 2022 16:39:58 -0500 From: Bjorn Helgaas To: Manivannan Sadhasivam Cc: kishon@ti.com, bhelgaas@google.com, robh@kernel.org, lorenzo.pieralisi@arm.com, kw@linux.com, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Kunihiko Hayashi , Om Prakash Singh , Vidya Sagar Subject: Re: [PATCH] PCI: designware-ep: Move DBI access to init_complete if notifier is used Message-ID: <20220715213958.GA1192967@bhelgaas> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220330060515.22328-1-manivannan.sadhasivam@linaro.org> X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 On Wed, Mar 30, 2022 at 11:35:15AM +0530, Manivannan Sadhasivam wrote: > For controllers supporting the CORE_INIT notifier, the resources are > supposed to be enabled in the init_complete function. Currently, > these controllers are enabling the resources during probe time due to > the DBI access happens in dw_pcie_ep_init(). > > This creates the dependency with the host PCIe controller since the > resource enablement like PHY depends on host PCIe to be up. For the > standalone endpoint usecase, this would never work. So let's move all DBI > access to init_complete function if CORE_INIT notifier is used. For the > controllers those doesn't support this notifier, this change is a NO-OP. > > Cc: Kunihiko Hayashi > Cc: Om Prakash Singh > Cc: Vidya Sagar > Signed-off-by: Manivannan Sadhasivam > --- > .../pci/controller/dwc/pcie-designware-ep.c | 138 ++++++++++++------ > drivers/pci/controller/dwc/pcie-designware.h | 1 + > 2 files changed, 94 insertions(+), 45 deletions(-) Sorry this got missed. Seems like there are two patches to solve the same problem: 1) This patch, and 2) Vidya's patch (https://lore.kernel.org/linux-pci/20220622040133.31058-1-vidyas@nvidia.com/) I don't know much about dwc or this issue, but if these patches are functionally equivalent, I think Vidya's is a little more attractive because: - It's smaller (49 insertions(+), 39 deletions(-)). - "core_init_notifier" looks like sort of a corner-case feature and Vidya's patch doesn't depend on it so it seems more maintainable. - It's more straightforward to read -- it basically just moves things from dw_pcie_ep_init() to dw_pcie_ep_init_complete(), which is exactly the sort of thing I expect if we're doing something out of order. > diff --git a/drivers/pci/controller/dwc/pcie-designware-ep.c b/drivers/pci/controller/dwc/pcie-designware-ep.c > index 0eda8236c125..fb2bf4bf5ba0 100644 > --- a/drivers/pci/controller/dwc/pcie-designware-ep.c > +++ b/drivers/pci/controller/dwc/pcie-designware-ep.c > @@ -636,6 +636,63 @@ static unsigned int dw_pcie_ep_find_ext_capability(struct dw_pcie *pci, int cap) > return 0; > } > > +static int dw_pcie_iatu_config(struct dw_pcie_ep *ep) > +{ > + struct dw_pcie *pci = to_dw_pcie_from_ep(ep); > + struct device *dev = pci->dev; > + void *addr; > + > + 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; > + > + return 0; > +} > + > +static int dw_pcie_ep_func_init(struct dw_pcie_ep *ep) > +{ > + struct dw_pcie *pci = to_dw_pcie_from_ep(ep); > + struct dw_pcie_ep_func *ep_func; > + struct pci_epc *epc = ep->epc; > + struct device *dev = pci->dev; > + u8 func_no; > + > + 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); > + } > + > + return 0; > +} > + > int dw_pcie_ep_init_complete(struct dw_pcie_ep *ep) > { > struct dw_pcie *pci = to_dw_pcie_from_ep(ep); > @@ -643,7 +700,22 @@ int dw_pcie_ep_init_complete(struct dw_pcie_ep *ep) > unsigned int nbars; > u8 hdr_type; > u32 reg; > - int i; > + int ret, i; > + > + if (ep->core_init_notifier) { > + ret = dw_pcie_iatu_config(ep); > + if (ret) > + return ret; > + } > + > + if (ep->core_init_notifier) { > + ret = dw_pcie_ep_func_init(ep); > + if (ret) > + return ret; > + > + if (ep->ops->ep_init) > + ep->ops->ep_init(ep); > + } > > hdr_type = dw_pcie_readb_dbi(pci, PCI_HEADER_TYPE) & > PCI_HEADER_TYPE_MASK; > @@ -677,8 +749,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 +756,12 @@ 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; > + > + if (ep->ops->get_features) { > + epc_features = ep->ops->get_features(ep); > + if (epc_features->core_init_notifier) > + ep->core_init_notifier = true; > + } > > INIT_LIST_HEAD(&ep->func_list); > > @@ -708,7 +783,11 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep) > } > } > > - dw_pcie_iatu_detect(pci); > + if (!ep->core_init_notifier) { > + ret = dw_pcie_iatu_config(ep); > + if (ret) > + return ret; > + } > > res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "addr_space"); > if (!res) > @@ -717,26 +796,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,23 +812,15 @@ 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); > + if (!ep->core_init_notifier) { > + ret = dw_pcie_ep_func_init(ep); > + if (ret) > + return ret; > > - list_add_tail(&ep_func->list, &ep->func_list); > + if (ep->ops->ep_init) > + ep->ops->ep_init(ep); > } > > - if (ep->ops->ep_init) > - ep->ops->ep_init(ep); > - > ret = pci_epc_mem_init(epc, ep->phys_base, ep->addr_size, > ep->page_size); > if (ret < 0) { > @@ -784,12 +835,9 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep) > return -ENOMEM; > } > > - if (ep->ops->get_features) { > - epc_features = ep->ops->get_features(ep); > - if (epc_features->core_init_notifier) > - return 0; > - } > + if (!ep->core_init_notifier) > + return dw_pcie_ep_init_complete(ep); > > - return dw_pcie_ep_init_complete(ep); > + return 0; > } > EXPORT_SYMBOL_GPL(dw_pcie_ep_init); > diff --git a/drivers/pci/controller/dwc/pcie-designware.h b/drivers/pci/controller/dwc/pcie-designware.h > index 7d6e9b7576be..aadb14159df7 100644 > --- a/drivers/pci/controller/dwc/pcie-designware.h > +++ b/drivers/pci/controller/dwc/pcie-designware.h > @@ -242,6 +242,7 @@ struct dw_pcie_ep { > void __iomem *msi_mem; > phys_addr_t msi_mem_phys; > struct pci_epf_bar *epf_bar[PCI_STD_NUM_BARS]; > + bool core_init_notifier; > }; > > struct dw_pcie_ops { > -- > 2.25.1 >