Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5226883rwb; Mon, 14 Nov 2022 00:58:29 -0800 (PST) X-Google-Smtp-Source: AA0mqf5vlWqF7CMdHsGfMQx0CGyxtVEhgQX94O7AaeOdfLIa15ldzpitG3V9RiYzb8f5CSeV8q5y X-Received: by 2002:a17:902:d544:b0:186:e114:bea6 with SMTP id z4-20020a170902d54400b00186e114bea6mr12986560plf.88.1668416309292; Mon, 14 Nov 2022 00:58:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668416309; cv=none; d=google.com; s=arc-20160816; b=zhogbfysyqYLYQG7j1Jw+UkhUcwJ30jh+u2bqA1X/nUjL3lXXtkWhW1JVkAwRIAK1O GIg7eVWGpXG9q1lkqZN2As/vMroCYX98l9skPa4TMPcrJ25h/EtUeOob9U5ZGJDOY7/6 nV40eifPtWHs8ErGOvkR6E5aqL4Ty/hLBx4+KmbfbR6PAMRiLQfOXAcFC7jjG+ttZeDQ Xbojh/Qu47karYcKVzX4ivp0j77yNuXUzzWecuiWvJKQCX35C9V21ZGahPcVaVdOle1I QDsW8XtgLY58SDjhcUDyaFtkrmk4oPlzwG+LiBuTkDjRp7uW6gS1hdweGIuB3pUM7c1u XsrA== 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=oFFN2XjDVoZ+b/EgZP/LKCVKMInAJA6uKY9rXNlna+E=; b=hRrIMq+FKg2V7MWwkxbh0RKdsPqEoSjNa9pMxsQ9pz9VzLvBeq+QAVi655ckco/FxM sSdmad4LI6Gte2wj5dh4AzAY5ovxj32cbjoIR2DOGmAYTL4jqR1RQG68+F5s9ozCDGSX AXGgeNriurw5vwes7abkP6KwXQWAXOJzrZ8Y7NUmOe56KUA7thhQqLjSgk4KPld8pdRL zrs/53mE5MvS6vtS2YN5cZ+H5I30yVVT2i0C1fTI4E18vPaOOlPbtKgIXmVj/GYkPGzC zSIQZUW6SYhg3Zg1YVd6UARyqDbS7NJwdBqJP88xAUfnl8Rc8d1jXPKiJO4QJNwhm5IF kuBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=IFj4n3fq; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j4-20020a170902758400b00188b9b4139asi4522169pll.210.2022.11.14.00.58.17; Mon, 14 Nov 2022 00:58:29 -0800 (PST) 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=@gmail.com header.s=20210112 header.b=IFj4n3fq; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235991AbiKNIjO (ORCPT + 88 others); Mon, 14 Nov 2022 03:39:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236099AbiKNIjJ (ORCPT ); Mon, 14 Nov 2022 03:39:09 -0500 Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [IPv6:2a00:1450:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72D52DF1D; Mon, 14 Nov 2022 00:39:08 -0800 (PST) Received: by mail-lj1-x233.google.com with SMTP id b9so12215646ljr.5; Mon, 14 Nov 2022 00:39:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=oFFN2XjDVoZ+b/EgZP/LKCVKMInAJA6uKY9rXNlna+E=; b=IFj4n3fqvGdFsbNV7ZAbFbBwJuS1yaYQ0jDbvB/952aQ9bqBozf/17UkrFDSqQ0S+e zR4k0KjgRdMSmrSsQIcuzuae5GBPmnAAyA7dPzeQQ+SjQcVuicS1eOOUROUE8K1Z0bDo UtCkPczWaLFuRLbflhuV5ljKoKBrqlzQchaiqLRKqJKm2ynqXzGEHleqM9JMkffAAvzX h5dv+og8jNjC2pNDIjKRh9hbNDuN822ikTTtAH2HZKiW6RtizbDjKoeuj6006oeg1s25 NGetWqSjK5P740n3FakKwjvJGSE5VRSOaSBm3Rvl9bVlP+zF9rZz5nYMciuHXab4OPJY aWKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-transfer-encoding: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=oFFN2XjDVoZ+b/EgZP/LKCVKMInAJA6uKY9rXNlna+E=; b=OCJS0yJGrk7Unwi4TdnNiYklSNNuQybU0jGqnoYqwHj4JTHilb5f2AxfrIu6RICEs3 NdgTq8uZDRdiXjMo8i9pyzgixxxHpDwVrlgScT/FqpjTRVd9J/2nDLWlO4vkEq+pIbQM EuWQxq3PptNhUbSNiLTTrGf9ejxcgsHl4acK6a7DHEmQg6nGKQ9p1GFTVUfxGz/SaHxJ /qcvy1pESiOyq/FWL22nKIFZJcYuKIrxGodTUYeycYn/QvXfwNpXRuGWPEbpqpvvGnHE qoSMl3Ekj4Ji1YdzLD+Ndke57kmUhclJ6KpahBMqfl7Bzp2yp4MnNoLeQN2glpu5+/QD URpg== X-Gm-Message-State: ANoB5pk/EH6xh7ocuowpYQ06eqJMLawSmf1F/LgucSDA8zzusk4SIpJD 9RnJtqOujkboief16bshU4o= X-Received: by 2002:a05:651c:1247:b0:26d:e656:d853 with SMTP id h7-20020a05651c124700b0026de656d853mr3562654ljh.177.1668415146568; Mon, 14 Nov 2022 00:39:06 -0800 (PST) Received: from mobilestation ([95.79.133.202]) by smtp.gmail.com with ESMTPSA id l16-20020ac24310000000b004947f8b6266sm1734935lfh.203.2022.11.14.00.39.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 00:39:06 -0800 (PST) Date: Mon, 14 Nov 2022 11:39:03 +0300 From: Serge Semin To: Manivannan Sadhasivam Cc: Serge Semin , Rob Herring , Rob Herring , Krzysztof Kozlowski , Bjorn Helgaas , Lorenzo Pieralisi , Cai Huoqing , Robin Murphy , Jingoo Han , Gustavo Pimentel , Lorenzo Pieralisi , Krzysztof =?utf-8?Q?Wilczy=C5=84ski?= , Alexey Malahov , Pavel Parkhomenko , Frank Li , Manivannan Sadhasivam , caihuoqing , Vinod Koul , linux-pci@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v7 17/20] PCI: dwc: Introduce generic resources getter Message-ID: <20221114083903.r2vyuyotwkf52jk7@mobilestation> References: <20221113191301.5526-1-Sergey.Semin@baikalelectronics.ru> <20221113191301.5526-18-Sergey.Semin@baikalelectronics.ru> <20221114064654.GE3869@thinkpad> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20221114064654.GE3869@thinkpad> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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 Mon, Nov 14, 2022 at 12:16:54PM +0530, Manivannan Sadhasivam wrote: > On Sun, Nov 13, 2022 at 10:12:58PM +0300, Serge Semin wrote: > > Currently the DW PCIe Root Port and Endpoint CSR spaces are retrieved in > > the separate parts of the DW PCIe core driver. It doesn't really make > > sense since the both controller types have identical set of the core CSR > > regions: DBI, DBI CS2 and iATU/eDMA. Thus we can simplify the DW PCIe Host > > and EP initialization methods by moving the platform-specific registers > > space getting and mapping into a common method. It gets to be even more > > justified seeing the CSRs base address pointers are preserved in the > > common DW PCIe descriptor. Note all the OF-based common DW PCIe settings > > initialization will be moved to the new method too in order to have a > > single function for all the generic platform properties handling in single > > place. > > > > A nice side-effect of this change is that the pcie-designware-host.c and > > pcie-designware-ep.c drivers are cleaned up from all the direct dw_pcie > > storage modification, which makes the DW PCIe core, Root Port and Endpoint > > modules more coherent. > > > > You have clubbed both generic resource API and introducing CDM_CHECK flag. > Please split them into separate patches. This modification is a part of the new method dw_pcie_get_resources(). Without that method there is no point in adding the new flag. So no. It's better to have all of it in a single patch as a part of creating a coherent resources getter method. -Sergey > > Thanks, > Mani > > > Signed-off-by: Serge Semin > > Reviewed-by: Rob Herring > > > > --- > > > > Changelog v3: > > - This is a new patch created on v3 lap of the series. > > > > Changelog v4: > > - Convert the method name from dw_pcie_get_res() to > > dw_pcie_get_resources(). (@Bjorn) > > > > Changelog v7: > > - Get back device.of_node pointer to the dw_pcie_ep_init() method. > > (@Yoshihiro) > > --- > > .../pci/controller/dwc/pcie-designware-ep.c | 25 +------ > > .../pci/controller/dwc/pcie-designware-host.c | 15 +--- > > drivers/pci/controller/dwc/pcie-designware.c | 75 ++++++++++++++----- > > drivers/pci/controller/dwc/pcie-designware.h | 3 + > > 4 files changed, 65 insertions(+), 53 deletions(-) > > > > diff --git a/drivers/pci/controller/dwc/pcie-designware-ep.c b/drivers/pci/controller/dwc/pcie-designware-ep.c > > index 237bb01d7852..f68d1ab83bb3 100644 > > --- a/drivers/pci/controller/dwc/pcie-designware-ep.c > > +++ b/drivers/pci/controller/dwc/pcie-designware-ep.c > > @@ -13,8 +13,6 @@ > > #include > > #include > > > > -#include "../../pci.h" > > - > > void dw_pcie_ep_linkup(struct dw_pcie_ep *ep) > > { > > struct pci_epc *epc = ep->epc; > > @@ -694,23 +692,9 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep) > > > > INIT_LIST_HEAD(&ep->func_list); > > > > - if (!pci->dbi_base) { > > - res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dbi"); > > - pci->dbi_base = devm_pci_remap_cfg_resource(dev, res); > > - if (IS_ERR(pci->dbi_base)) > > - return PTR_ERR(pci->dbi_base); > > - } > > - > > - if (!pci->dbi_base2) { > > - res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dbi2"); > > - if (!res) { > > - pci->dbi_base2 = pci->dbi_base + SZ_4K; > > - } else { > > - pci->dbi_base2 = devm_pci_remap_cfg_resource(dev, res); > > - if (IS_ERR(pci->dbi_base2)) > > - return PTR_ERR(pci->dbi_base2); > > - } > > - } > > + ret = dw_pcie_get_resources(pci); > > + if (ret) > > + return ret; > > > > res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "addr_space"); > > if (!res) > > @@ -739,9 +723,6 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep) > > return -ENOMEM; > > ep->outbound_addr = addr; > > > > - if (pci->link_gen < 1) > > - pci->link_gen = of_pci_get_max_link_speed(np); > > - > > epc = devm_pci_epc_create(dev, &epc_ops); > > if (IS_ERR(epc)) { > > dev_err(dev, "Failed to create epc device\n"); > > diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c > > index ea923c25e12d..3ab6ae3712c4 100644 > > --- a/drivers/pci/controller/dwc/pcie-designware-host.c > > +++ b/drivers/pci/controller/dwc/pcie-designware-host.c > > @@ -16,7 +16,6 @@ > > #include > > #include > > > > -#include "../../pci.h" > > #include "pcie-designware.h" > > > > static struct pci_ops dw_pcie_ops; > > @@ -395,6 +394,10 @@ int dw_pcie_host_init(struct dw_pcie_rp *pp) > > > > raw_spin_lock_init(&pp->lock); > > > > + ret = dw_pcie_get_resources(pci); > > + if (ret) > > + return ret; > > + > > res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "config"); > > if (res) { > > pp->cfg0_size = resource_size(res); > > @@ -408,13 +411,6 @@ int dw_pcie_host_init(struct dw_pcie_rp *pp) > > return -ENODEV; > > } > > > > - if (!pci->dbi_base) { > > - res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dbi"); > > - pci->dbi_base = devm_pci_remap_cfg_resource(dev, res); > > - if (IS_ERR(pci->dbi_base)) > > - return PTR_ERR(pci->dbi_base); > > - } > > - > > bridge = devm_pci_alloc_host_bridge(dev, 0); > > if (!bridge) > > return -ENOMEM; > > @@ -429,9 +425,6 @@ int dw_pcie_host_init(struct dw_pcie_rp *pp) > > pp->io_base = pci_pio_to_address(win->res->start); > > } > > > > - if (pci->link_gen < 1) > > - pci->link_gen = of_pci_get_max_link_speed(np); > > - > > /* Set default bus ops */ > > bridge->ops = &dw_pcie_ops; > > bridge->child_ops = &dw_child_pcie_ops; > > diff --git a/drivers/pci/controller/dwc/pcie-designware.c b/drivers/pci/controller/dwc/pcie-designware.c > > index 9d78e7ca61e1..a8436027434d 100644 > > --- a/drivers/pci/controller/dwc/pcie-designware.c > > +++ b/drivers/pci/controller/dwc/pcie-designware.c > > @@ -11,6 +11,7 @@ > > #include > > #include > > #include > > +#include > > #include > > #include > > #include > > @@ -19,6 +20,59 @@ > > #include "../../pci.h" > > #include "pcie-designware.h" > > > > +int dw_pcie_get_resources(struct dw_pcie *pci) > > +{ > > + struct platform_device *pdev = to_platform_device(pci->dev); > > + struct device_node *np = dev_of_node(pci->dev); > > + struct resource *res; > > + > > + if (!pci->dbi_base) { > > + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dbi"); > > + pci->dbi_base = devm_pci_remap_cfg_resource(pci->dev, res); > > + if (IS_ERR(pci->dbi_base)) > > + return PTR_ERR(pci->dbi_base); > > + } > > + > > + /* DBI2 is mainly useful for the endpoint controller */ > > + if (!pci->dbi_base2) { > > + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dbi2"); > > + if (res) { > > + pci->dbi_base2 = devm_pci_remap_cfg_resource(pci->dev, res); > > + if (IS_ERR(pci->dbi_base2)) > > + return PTR_ERR(pci->dbi_base2); > > + } else { > > + pci->dbi_base2 = pci->dbi_base + SZ_4K; > > + } > > + } > > + > > + /* For non-unrolled iATU/eDMA platforms this range will be ignored */ > > + if (!pci->atu_base) { > > + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "atu"); > > + if (res) { > > + pci->atu_size = resource_size(res); > > + pci->atu_base = devm_ioremap_resource(pci->dev, res); > > + if (IS_ERR(pci->atu_base)) > > + return PTR_ERR(pci->atu_base); > > + } else { > > + pci->atu_base = pci->dbi_base + DEFAULT_DBI_ATU_OFFSET; > > + } > > + } > > + > > + /* Set a default value suitable for at most 8 in and 8 out windows */ > > + if (!pci->atu_size) > > + pci->atu_size = SZ_4K; > > + > > + if (pci->link_gen < 1) > > + pci->link_gen = of_pci_get_max_link_speed(np); > > + > > + of_property_read_u32(np, "num-lanes", &pci->num_lanes); > > + > > + if (of_property_read_bool(np, "snps,enable-cdm-check")) > > + dw_pcie_cap_set(pci, CDM_CHECK); > > + > > + return 0; > > +} > > + > > void dw_pcie_version_detect(struct dw_pcie *pci) > > { > > u32 ver; > > @@ -639,25 +693,8 @@ static void dw_pcie_iatu_detect_regions(struct dw_pcie *pci) > > > > void dw_pcie_iatu_detect(struct dw_pcie *pci) > > { > > - struct platform_device *pdev = to_platform_device(pci->dev); > > - > > if (dw_pcie_iatu_unroll_enabled(pci)) { > > dw_pcie_cap_set(pci, IATU_UNROLL); > > - > > - if (!pci->atu_base) { > > - struct resource *res = > > - platform_get_resource_byname(pdev, IORESOURCE_MEM, "atu"); > > - if (res) { > > - pci->atu_size = resource_size(res); > > - pci->atu_base = devm_ioremap_resource(pci->dev, res); > > - } > > - if (!pci->atu_base || IS_ERR(pci->atu_base)) > > - pci->atu_base = pci->dbi_base + DEFAULT_DBI_ATU_OFFSET; > > - } > > - > > - if (!pci->atu_size) > > - /* Pick a minimal default, enough for 8 in and 8 out windows */ > > - pci->atu_size = SZ_4K; > > } else { > > pci->atu_base = pci->dbi_base + PCIE_ATU_VIEWPORT_BASE; > > pci->atu_size = PCIE_ATU_VIEWPORT_SIZE; > > @@ -675,7 +712,6 @@ void dw_pcie_iatu_detect(struct dw_pcie *pci) > > > > void dw_pcie_setup(struct dw_pcie *pci) > > { > > - struct device_node *np = pci->dev->of_node; > > u32 val; > > > > if (pci->link_gen > 0) > > @@ -703,14 +739,13 @@ void dw_pcie_setup(struct dw_pcie *pci) > > val |= PORT_LINK_DLL_LINK_EN; > > dw_pcie_writel_dbi(pci, PCIE_PORT_LINK_CONTROL, val); > > > > - if (of_property_read_bool(np, "snps,enable-cdm-check")) { > > + if (dw_pcie_cap_is(pci, CDM_CHECK)) { > > val = dw_pcie_readl_dbi(pci, PCIE_PL_CHK_REG_CONTROL_STATUS); > > val |= PCIE_PL_CHK_REG_CHK_REG_CONTINUOUS | > > PCIE_PL_CHK_REG_CHK_REG_START; > > dw_pcie_writel_dbi(pci, PCIE_PL_CHK_REG_CONTROL_STATUS, val); > > } > > > > - of_property_read_u32(np, "num-lanes", &pci->num_lanes); > > if (!pci->num_lanes) { > > dev_dbg(pci->dev, "Using h/w default number of lanes\n"); > > return; > > diff --git a/drivers/pci/controller/dwc/pcie-designware.h b/drivers/pci/controller/dwc/pcie-designware.h > > index c6dddacee3b1..081f169e6021 100644 > > --- a/drivers/pci/controller/dwc/pcie-designware.h > > +++ b/drivers/pci/controller/dwc/pcie-designware.h > > @@ -46,6 +46,7 @@ > > > > /* DWC PCIe controller capabilities */ > > #define DW_PCIE_CAP_IATU_UNROLL 1 > > +#define DW_PCIE_CAP_CDM_CHECK 2 > > > > #define dw_pcie_cap_is(_pci, _cap) \ > > test_bit(DW_PCIE_CAP_ ## _cap, &(_pci)->caps) > > @@ -338,6 +339,8 @@ struct dw_pcie { > > #define to_dw_pcie_from_ep(endpoint) \ > > container_of((endpoint), struct dw_pcie, ep) > > > > +int dw_pcie_get_resources(struct dw_pcie *pci); > > + > > void dw_pcie_version_detect(struct dw_pcie *pci); > > > > u8 dw_pcie_find_capability(struct dw_pcie *pci, u8 cap); > > -- > > 2.38.1 > > > > > > -- > மணிவண்ணன் சதாசிவம்