Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp7450756ybl; Wed, 15 Jan 2020 23:17:48 -0800 (PST) X-Google-Smtp-Source: APXvYqy5c4ilejKn1VnJ2UnVAY+m+GmLrtu3DCmGiNHnibHB7uzkD2hZPLXHQ51OXLpfaw4SAerG X-Received: by 2002:a05:6808:208:: with SMTP id l8mr2996345oie.112.1579159068157; Wed, 15 Jan 2020 23:17:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579159068; cv=none; d=google.com; s=arc-20160816; b=T8y1L0MA4Ymmvv2X03gfu1teh9sjCOavr6KEcBwj5dil4mDMRqCuZZ1aPnZdYclbWe DCoqSfwtYmLgFxsbvpd9Q5Bch/uoVA6sG4ptpKahy47gt34U6iNpSfOF79fObIQ5nKtp FW/9zOUndTwMVO77ATDZP1BnseTulMXGbBdpHJfQv+e+3BeH0awikkmmIhVrUJG1A4YL Saldn2cZG1PEK2z72sbwiQggfZ6zyiT6oxpTZu8M4Jrk4kWzPRYIdrSp+d8YfayZOw9d Xl04t9iqPxfD3d/f/hzH+XjmZTdH8fUyooxRMj/sXSH7nE6pVpAvUBBcf2t4s6hQNGGI TvXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=sOYcxg4iNklbKYvqwCFV5iSNCYi87ZaFpe1ow9AnDTU=; b=dc2AXsdUlst/xHg30lnoQEvyF2LvgMo311NvDNTksIwr1NVdRkOc22zvduKefKrVuh eUBS2368un6eHZ8UvimQpu+f9sZNQeOMbpx8WBbvF+cQOUWdrSZVspIsyJ/C07nZj0gf war6xt1uffxG/y2cHVZaBWBFNUqdEfSVDg/IaBl3loeLgjHLuoPSgzcvx0j2c20pz+Lx DfNBmB2wbpba68rmIKUYD3CxUA1jQLZdPWBLdEzu3OUykRuVqghf+XJSAoaeAcAgchdL RVcrMxPnK6xZ5iKig77Td4zjOox/ukVxoaRWzEM8SS/d1NMq6KFS6rSaV1Net00lW88I aN+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b="YbFoQy/N"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m85si11192218oig.158.2020.01.15.23.17.23; Wed, 15 Jan 2020 23:17:48 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b="YbFoQy/N"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726928AbgAPFxs (ORCPT + 99 others); Thu, 16 Jan 2020 00:53:48 -0500 Received: from fllv0016.ext.ti.com ([198.47.19.142]:55204 "EHLO fllv0016.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726082AbgAPFxs (ORCPT ); Thu, 16 Jan 2020 00:53:48 -0500 Received: from lelv0265.itg.ti.com ([10.180.67.224]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 00G5rAQA064244; Wed, 15 Jan 2020 23:53:10 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1579153990; bh=sOYcxg4iNklbKYvqwCFV5iSNCYi87ZaFpe1ow9AnDTU=; h=Subject:To:CC:References:From:Date:In-Reply-To; b=YbFoQy/NnB0Fi70gEYTGrbWZ9o5nFdZJ7Z3UtPUiMe+IjeJ3qgs7+qECWuxJwjjBt cDPuq/5yx6ImrbqYJ7mdLwHBmTS1FN9cNyYH4NqselWP4aCmMz14pqNkUoFkPFx4ZR kgveTfWlqEChZCam07S1dGkJjO1jYmXG6qhzMtiw= Received: from DLEE105.ent.ti.com (dlee105.ent.ti.com [157.170.170.35]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 00G5rAxA039773 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 15 Jan 2020 23:53:10 -0600 Received: from DLEE106.ent.ti.com (157.170.170.36) by DLEE105.ent.ti.com (157.170.170.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3; Wed, 15 Jan 2020 23:53:10 -0600 Received: from fllv0039.itg.ti.com (10.64.41.19) by DLEE106.ent.ti.com (157.170.170.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3 via Frontend Transport; Wed, 15 Jan 2020 23:53:10 -0600 Received: from [10.24.69.159] (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0039.itg.ti.com (8.15.2/8.15.2) with ESMTP id 00G5r064074235; Wed, 15 Jan 2020 23:53:02 -0600 Subject: Re: [v3 5/6] PCI: rcar: Add support for rcar PCIe controller in endpoint mode To: Lad Prabhakar , Bjorn Helgaas , Rob Herring , Mark Rutland , Geert Uytterhoeven , Magnus Damm , Marek Vasut , Yoshihiro Shimoda , CC: Catalin Marinas , Will Deacon , Lorenzo Pieralisi , Arnd Bergmann , Greg Kroah-Hartman , Andrew Murray , , , , , Chris Paterson , Frank Rowand , Gustavo Pimentel , Jingoo Han , Simon Horman , Shawn Lin , Tom Joseph , Heiko Stuebner , , Lad Prabhakar References: <20200108162211.22358-1-prabhakar.mahadev-lad.rj@bp.renesas.com> <20200108162211.22358-6-prabhakar.mahadev-lad.rj@bp.renesas.com> From: Kishon Vijay Abraham I Message-ID: <5cf7fbe3-c7e4-8e8e-9815-a5e52a62615b@ti.com> Date: Thu, 16 Jan 2020 11:25:12 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: <20200108162211.22358-6-prabhakar.mahadev-lad.rj@bp.renesas.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 08/01/20 9:52 PM, Lad Prabhakar wrote: > This patch adds support for rcar PCIe controller to work in endpoint mode. > > Signed-off-by: Lad Prabhakar > --- > drivers/pci/controller/Kconfig | 7 + > drivers/pci/controller/Makefile | 1 + > drivers/pci/controller/pcie-rcar-ep.c | 497 ++++++++++++++++++++++++++ > drivers/pci/controller/pcie-rcar.h | 6 + > 4 files changed, 511 insertions(+) > create mode 100644 drivers/pci/controller/pcie-rcar-ep.c > > diff --git a/drivers/pci/controller/Kconfig b/drivers/pci/controller/Kconfig > index b022ac5678f7..69b1c778dad4 100644 > --- a/drivers/pci/controller/Kconfig > +++ b/drivers/pci/controller/Kconfig > @@ -61,6 +61,13 @@ config PCIE_RCAR_HOST > help > Say Y here if you want PCIe controller support on R-Car SoCs in host mode. > > +config PCIE_RCAR_EP > + bool "Renesas R-Car PCIe endpoint controller" > + depends on ARCH_RENESAS || COMPILE_TEST > + depends on PCI_ENDPOINT > + help > + Say Y here if you want PCIe controller support on R-Car SoCs in endpoint mode. > + > config PCI_HOST_COMMON > bool > select PCI_ECAM > diff --git a/drivers/pci/controller/Makefile b/drivers/pci/controller/Makefile > index 69ba1dbf837b..61505b1fc66a 100644 > --- a/drivers/pci/controller/Makefile > +++ b/drivers/pci/controller/Makefile > @@ -8,6 +8,7 @@ obj-$(CONFIG_PCI_AARDVARK) += pci-aardvark.o > obj-$(CONFIG_PCI_TEGRA) += pci-tegra.o > obj-$(CONFIG_PCI_RCAR_GEN2) += pci-rcar-gen2.o > obj-$(CONFIG_PCIE_RCAR_HOST) += pcie-rcar.o pcie-rcar-host.o > +obj-$(CONFIG_PCIE_RCAR_EP) += pcie-rcar.o pcie-rcar-ep.o > obj-$(CONFIG_PCI_HOST_COMMON) += pci-host-common.o > obj-$(CONFIG_PCI_HOST_GENERIC) += pci-host-generic.o > obj-$(CONFIG_PCIE_XILINX) += pcie-xilinx.o > diff --git a/drivers/pci/controller/pcie-rcar-ep.c b/drivers/pci/controller/pcie-rcar-ep.c > new file mode 100644 > index 000000000000..40cd2aad8c3c > --- /dev/null > +++ b/drivers/pci/controller/pcie-rcar-ep.c > @@ -0,0 +1,497 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * PCIe endpoint driver for Renesas R-Car SoCs > + * Copyright (c) 2020 Renesas Electronics Europe GmbH > + * > + * Author: Lad Prabhakar > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include "pcie-rcar.h" > + > +#define MAX_NR_INBOUND_MAPS 6 > +#define MAX_NR_OUTBOUND_MAPS 4 > + > +/* Structure representing the PCIe interface */ > +struct rcar_pcie { > + phys_addr_t *ob_addr; > + struct pci_epc_mem_window *ob_window; > + struct pci_epc *epc; > + struct device *dev; > + void __iomem *base; > + u8 max_functions; > + unsigned int bar_to_atu[MAX_NR_INBOUND_MAPS]; > + unsigned long *ib_window_map; > + u32 num_ib_windows; > + u32 num_ob_windows; > +}; > + > +static void rcar_pcie_ep_hw_init(struct rcar_pcie *pcie) > +{ > + u32 val; > + > + rcar_pci_write_reg(pcie->base, 0, PCIETCTLR); > + > + /* Set endpoint mode */ > + rcar_pci_write_reg(pcie->base, 0, PCIEMSR); > + > + /* Initialize default capabilities. */ > + rcar_rmw32(pcie->base, REXPCAP(0), 0xff, PCI_CAP_ID_EXP); > + rcar_rmw32(pcie->base, REXPCAP(PCI_EXP_FLAGS), > + PCI_EXP_FLAGS_TYPE, PCI_EXP_TYPE_ENDPOINT << 4); > + rcar_rmw32(pcie->base, RCONF(PCI_HEADER_TYPE), 0x7f, > + PCI_HEADER_TYPE_NORMAL); > + > + /* Write out the physical slot number = 0 */ > + rcar_rmw32(pcie->base, REXPCAP(PCI_EXP_SLTCAP), PCI_EXP_SLTCAP_PSN, 0); > + > + val = rcar_pci_read_reg(pcie->base, EXPCAP(1)); > + /* device supports fixed 128 bytes MPSS */ > + val &= ~GENMASK(2, 0); > + /* L1 to L0 transition latency no time limit */ > + val |= GENMASK(11, 9); > + /* L0s to L0 transistion no time limit */ > + val |= GENMASK(8, 6); > + rcar_pci_write_reg(pcie->base, val, EXPCAP(1)); > + > + val = rcar_pci_read_reg(pcie->base, EXPCAP(2)); > + /* read requests size 128 bytes */ > + val &= ~GENMASK(14, 12); > + /* payload size 128 bytes */ > + val &= ~GENMASK(7, 5); > + /* disable relaxed ordering transaction */ > + val &= ~BIT(4); > + rcar_pci_write_reg(pcie->base, val, EXPCAP(2)); > + > + val = rcar_pci_read_reg(pcie->base, EXPCAP(4)); > + /* disable ASPM control */ > + val &= ~GENMASK(1, 0); > + rcar_pci_write_reg(pcie->base, val, EXPCAP(4)); > + > + /* Set target link speed to 5.0 GT/s */ > + rcar_rmw32(pcie->base, EXPCAP(12), PCI_EXP_LNKSTA_CLS, > + PCI_EXP_LNKSTA_CLS_5_0GB); > + > + /* Set the completion timer timeout to the maximum 50ms. */ > + rcar_rmw32(pcie->base, TLCTLR + 1, 0x3f, 50); > + > + /* Terminate list of capabilities (Next Capability Offset=0) */ > + rcar_rmw32(pcie->base, RVCCAP(0), 0xfff00000, 0); > + > + /* flush modifications */ > + wmb(); > +} > + > +static int rcar_pcie_parse_outbound_ranges(struct rcar_pcie *pcie, > + struct platform_device *pdev) > +{ > + char outbound_name[10]; > + struct resource *res; > + unsigned int i = 0; > + > + pcie->num_ob_windows = 0; > + for (i = 0; i < MAX_NR_OUTBOUND_MAPS; i++) { > + sprintf(outbound_name, "memory%u", i); > + res = platform_get_resource_byname(pdev, > + IORESOURCE_MEM, > + outbound_name); > + if (!res) { > + dev_err(pcie->dev, "missing outbound window %u\n", i); > + return -EINVAL; > + } > + if (!devm_request_mem_region(&pdev->dev, res->start, > + resource_size(res), > + outbound_name)) { > + dev_err(pcie->dev, "Cannot request memory region %s.\n", > + outbound_name); > + return -EIO; > + } > + > + pcie->ob_window[i].phys_base = res->start; > + pcie->ob_window[i].size = resource_size(res); > + /* controller doesn't support multiple allocation > + * from same window, so set page_size to window size > + */ > + pcie->ob_window[i].page_size = resource_size(res); I would prefer the page_size comes from device tree. I'm also thinking if we should add a standard binding for specifying the outbound memory regions. Rob, what do you think? Thanks Kishon