Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4470537ioa; Wed, 27 Apr 2022 04:42:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwe0dLhBvkf8r546E5Y18C3H+Njpq2n55SKladsTFjBQXxRS9Bv2Wqlo5nblSZOviD2sUcB X-Received: by 2002:a17:903:124a:b0:154:c7a4:9374 with SMTP id u10-20020a170903124a00b00154c7a49374mr28383382plh.68.1651059763325; Wed, 27 Apr 2022 04:42:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651059763; cv=none; d=google.com; s=arc-20160816; b=HWXmuWaxFhotu2iaYx6cqmagiesM/eKDht/IJFsXfbekUThsYVwdNtn9TOe2N/Q4Pu j8v7q8UdvcxEWoPCXoj9AlBnNdEBpJHvQBjTcD7UFYMxm2+4osyRPUsEZKKBGNkIxH5l vCWEa5daWe5lZjohL5IRn2wiSMfMOJnVICn6OV0vQFEg3lmhr58FOf56vENAgbygg6xn cCPfJ0P9FhrqGNsiJNe5gtIi3gcYB15oJrhIP8cVgHAV/lGF4m2Wv+UOFVgYNFTVorNR DpypIlFQ3O24d1EsHmPiYIbMF1OGoTpHKiwyaa5GGzHI3LtxwFVtaNFpF7Rss1WwhTAM 3urg== 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=5rTKWkjlHgOXr6kl9UzprHIsMJneYwDS96kK0o+RqvA=; b=mRtRh43nDNBjaz9C/kTl0XXrzDH1bzp/PCVnnI58YAk3V7CjaLC8IiG3eYShBc9WLd WOtS4QwU8UqzNBwJjsfMuAQTjZ+Y8TCNU1hCrORPCc7AmeS0c5Zr4PELiSPgNhvExgVU nsjtZoFrdB3z7LJQ3/+jh6w5nUygwiELlh8sshBntCSdreHNuQx0+c764HMmbuEYb9ZK ZSJC+YrdLETCYhBD72RGUYeKBK/DFz8xwhHMl55GCstp/oZYDZU4PEOtuD159Xoh41Q4 d7VEKzyYqXyt6/LT2t0bLBGswAHFkseik459Parv7hYqwn/fTh122jfNW6dVH6tdXy9s D/Wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dKnZ+95b; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id l12-20020a170902f68c00b00153b2d16541si1490651plg.329.2022.04.27.04.42.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 04:42:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dKnZ+95b; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0EC2548B8A0; Wed, 27 Apr 2022 03:52:24 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230393AbiD0Kz3 (ORCPT + 99 others); Wed, 27 Apr 2022 06:55:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230348AbiD0Kz1 (ORCPT ); Wed, 27 Apr 2022 06:55:27 -0400 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B038B4A18F3 for ; Wed, 27 Apr 2022 03:27:38 -0700 (PDT) Received: by mail-pl1-x632.google.com with SMTP id d15so1152411pll.10 for ; Wed, 27 Apr 2022 03:27:38 -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:in-reply-to; bh=5rTKWkjlHgOXr6kl9UzprHIsMJneYwDS96kK0o+RqvA=; b=dKnZ+95bJGasLjxZvMhXCdPJ8FPh986Z3/p2kElWoyZFQ19AGqrCsyjrBl3Zj+jOFe cpkoqo71cA/CQxE9HAWimnkUxZPVzFD4gMNZXSVrDj/gVvFsaprALNEH0QVjwfQYUCAg nooayKB3XSqsYWD0krgysHqsMQoOTOxff/yX8pMVScF7Reakd3CmoefsrIUYL8qCcQgA 6GxBsVS3/663ePc6R6KdZCv2r7xmTn9NkUB/DmFZCUhaja45n8HKmMySP/GtiH7B+zuE WMgO6mNCOwTpffK3DCq6WtEKFkKj3w4iL1ouqYYlzq7MU62/nxJLtPiZLoIp1j4Xsnb1 1/EA== 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:in-reply-to; bh=5rTKWkjlHgOXr6kl9UzprHIsMJneYwDS96kK0o+RqvA=; b=FtN791pKCNMJRCUPmNQodbwg7keD+LQLe21l1K4s6luGQOf+ZUlxuPpbpdH3Sk3oee 45bKhyiaGQ0ChycYLthkQG3r5oKAwCaiDBpTPlqYgRERB8/1tsWgh5mtn2+LwwV94/H9 eKR8+epWTBoDO4J6gPKVQXegmrV+oh4HMf1eWEZw904+nn3po1C52fsXyyh8+NvNiOpD 80R2lbl0P4S/VbfIfmOTwEmFEq7n2YpummHYPo/ofDqUSEQenMtc+ptN4OL8nkCK2Hvq 474bgW16jNrokDrIRUUgSZxdIWGNxPPk9FZuueidwi+ALJZ5oHRCMKiVlltAa1qdMr9D s1IA== X-Gm-Message-State: AOAM530zIz/GH+VdHWeeK0v3RAu5hyy600RD1LIG0bGeqcQa9zjBxRT1 6DshEJMasdkgZ3F65MNo5r1sacyRTHDN X-Received: by 2002:a17:902:e791:b0:151:dbbd:aeae with SMTP id cp17-20020a170902e79100b00151dbbdaeaemr27675625plb.171.1651054706453; Wed, 27 Apr 2022 03:18:26 -0700 (PDT) Received: from thinkpad ([117.207.26.174]) by smtp.gmail.com with ESMTPSA id mm5-20020a17090b358500b001cd4989ff41sm2354861pjb.8.2022.04.27.03.18.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 03:18:26 -0700 (PDT) Date: Wed, 27 Apr 2022 15:48:20 +0530 From: Manivannan Sadhasivam To: kishon@ti.com, bhelgaas@google.com, robh@kernel.org, lorenzo.pieralisi@arm.com Cc: 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: <20220427101820.GC2536@thinkpad> References: <20220330060515.22328-1-manivannan.sadhasivam@linaro.org> 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=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE 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 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 A gentle ping on this patch! Thanks, Mani > --- > .../pci/controller/dwc/pcie-designware-ep.c | 138 ++++++++++++------ > drivers/pci/controller/dwc/pcie-designware.h | 1 + > 2 files changed, 94 insertions(+), 45 deletions(-) > > 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 >