Received: by 10.213.65.68 with SMTP id h4csp3751014imn; Tue, 10 Apr 2018 04:14:37 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/JGVGH0+L0naB+Z+55Jr+nnAtQENa8eyna4qInWQjOnNKYIZWJJBzRmrywotXy+y5Ejetn X-Received: by 10.98.196.83 with SMTP id y80mr2402260pff.117.1523358877233; Tue, 10 Apr 2018 04:14:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523358877; cv=none; d=google.com; s=arc-20160816; b=wZ/wJQguI+/YABPTvWw93gd1Xjg92/U09Lxuu8zEL/iMkxWHYfgZ6evCIJmJecUJB8 OhRzxx2o5JgPgex4Ih3vyfTJviVX3/Amb6SC7QCzdraxrny5K/JWI0In7P9tYv/RFs9Y TgW60TfTGrUPR4Aoof4yagOxOQezit2F7C0DS3hqN/xlcOi5eLABc7gGW88Fw9Czw4AX Ys17le93AuwFtIc8/RmFUyavLEe+yQlEbylcfrRNmC5rhF4aLezln5RmBMIFypue8r3C Jl0V6pQaaVXfTuCZCeiCLLJxvf1BgKCZBJOBRthTboLlH+PHQAJXaOTkBUf5PLK+q0DO dIdw== 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:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject:dkim-signature:arc-authentication-results; bh=wb9yKvgE3STF94/f4q0I9srDzoG22EvVcb7rfC9tR0Q=; b=lPgJkcx07MQ42ELHmURLQVOxsul8XdSWFM7kgoJR9mPqe6Sw6N1HG+/4CDcjgFelwf NEQJy0iOroBdxEzhSl9ddX6XcICf3ude4IRVr7WnToswfzS/bKdJM1lHAk9wDMi0DtXz dF7GT1cCBzw1m/zmUuf/YSE00een3plvHJs5xpZXbo3G7BIA2imAChB5DQwtnccQaDMZ 43L5h1HH9gblYW/JD5glMocSjhs+rKXfxq0hEu+Muda7jG8YlFRcgsNGEyAl+kJ4Xdgl abg2kJ5a4gdtlRrb/S1pnXHH/Utpf21aPvA1Z18zsm3Ao3RFpHZLKOSVqdlxv4dbTuNc myIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=l53cyoTU; 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 x4si1595806pgt.575.2018.04.10.04.14.00; Tue, 10 Apr 2018 04:14:37 -0700 (PDT) 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=l53cyoTU; 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 S1752831AbeDJLKL (ORCPT + 99 others); Tue, 10 Apr 2018 07:10:11 -0400 Received: from lelnx193.ext.ti.com ([198.47.27.77]:49198 "EHLO lelnx193.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751945AbeDJLKI (ORCPT ); Tue, 10 Apr 2018 07:10:08 -0400 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by lelnx193.ext.ti.com (8.15.1/8.15.1) with ESMTP id w3ABA1ra016486; Tue, 10 Apr 2018 06:10:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ti.com; s=ti-com-17Q1; t=1523358601; bh=N6L7446i/lN//YtwMeKfvC9jW8gqIrBiF18LdzfC++Y=; h=Subject:To:References:CC:From:Date:In-Reply-To; b=l53cyoTUA/UxIThx7uXF6nIgpX6lxBHh0dj16YQ9WVZ2si1ONZt4ONmD1q80A+t+q xOK+x37hNAzn5uivtTKdH5lX2rHI3y5A6zkzlqHrFs/Np4aDmvYK+05l3kK6BxlMr1 FF7J4O6emezOQ3rxnXLpzUdwAK0IVKnERT+UcpzI= Received: from DFLE107.ent.ti.com (dfle107.ent.ti.com [10.64.6.28]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id w3ABA1dq022466; Tue, 10 Apr 2018 06:10:01 -0500 Received: from DFLE112.ent.ti.com (10.64.6.33) by DFLE107.ent.ti.com (10.64.6.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1261.35; Tue, 10 Apr 2018 06:10:01 -0500 Received: from dlep33.itg.ti.com (157.170.170.75) by DFLE112.ent.ti.com (10.64.6.33) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1261.35 via Frontend Transport; Tue, 10 Apr 2018 06:10:01 -0500 Received: from [172.24.190.233] (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep33.itg.ti.com (8.14.3/8.13.8) with ESMTP id w3AB9vFL018955; Tue, 10 Apr 2018 06:09:58 -0500 Subject: Re: [PATCH v2 2/9] PCI: dwc: Add support for endpoint mode To: Gustavo Pimentel , "bhelgaas@google.com" , "lorenzo.pieralisi@arm.com" , "Joao.Pinto@synopsys.com" , "jingoohan1@gmail.com" , "robh+dt@kernel.org" , "mark.rutland@arm.com" References: <9ce10e6844863029992a5f4e74c89818615850e3.1523266508.git.gustavo.pimentel@synopsys.com> <667dde5d-70b9-0001-59f9-f2b7cb8d06b8@synopsys.com> CC: "linux-pci@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "devicetree@vger.kernel.org" From: Kishon Vijay Abraham I Message-ID: <10d70eb7-6966-4ebc-b8ef-5d2a2ff0c5ad@ti.com> Date: Tue, 10 Apr 2018 16:39:57 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <667dde5d-70b9-0001-59f9-f2b7cb8d06b8@synopsys.com> Content-Type: text/plain; charset="windows-1252" 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 Tuesday 10 April 2018 04:06 PM, Gustavo Pimentel wrote: > Hi Kishon, > > On 10/04/2018 06:12, Kishon Vijay Abraham I wrote: >> Hi, >> >> On Monday 09 April 2018 03:11 PM, Gustavo Pimentel wrote: >>> The PCIe controller dual mode is capable of operating in host mode as well >>> as endpoint mode by configuration, therefore this patch aims to add >>> endpoint mode support to the designware driver. >>> >>> Signed-off-by: Gustavo Pimentel >>> --- >>> Change v1->v2: >>> - Removed dw_plat_pcie_stop_link empty function. >>> - Implemented Kishon's suggestions about dw-pcie-rc and dw-pcie strings. >>> compatibility. >>> - Added second entry on pci_epf_test_ids structure. >>> >>> drivers/pci/dwc/Kconfig | 45 ++++++-- >>> drivers/pci/dwc/pcie-designware-ep.c | 4 +- >>> drivers/pci/dwc/pcie-designware-plat.c | 153 ++++++++++++++++++++++++-- >>> drivers/pci/endpoint/functions/pci-epf-test.c | 9 ++ >>> 4 files changed, 190 insertions(+), 21 deletions(-) >>> >>> diff --git a/drivers/pci/dwc/Kconfig b/drivers/pci/dwc/Kconfig >>> index 2f3f5c5..3fd7daf 100644 >>> --- a/drivers/pci/dwc/Kconfig >>> +++ b/drivers/pci/dwc/Kconfig >>> @@ -7,8 +7,7 @@ config PCIE_DW >>> >>> config PCIE_DW_HOST >>> bool >>> - depends on PCI >>> - depends on PCI_MSI_IRQ_DOMAIN >>> + depends on PCI && PCI_MSI_IRQ_DOMAIN >>> select PCIE_DW >>> >>> config PCIE_DW_EP >>> @@ -52,16 +51,42 @@ config PCI_DRA7XX_EP >>> >>> config PCIE_DW_PLAT >>> bool "Platform bus based DesignWare PCIe Controller" >>> - depends on PCI >>> - depends on PCI_MSI_IRQ_DOMAIN >>> - select PCIE_DW_HOST >>> - ---help--- >>> - This selects the DesignWare PCIe controller support. Select this if >>> - you have a PCIe controller on Platform bus. >>> + help >>> + There are two instances of PCIe controller in Designware IP. >>> + This controller can work either as EP or RC. In order to enable >>> + host-specific features PCIE_DW_PLAT_HOST must be selected and in >>> + order to enable device-specific features PCIE_DW_PLAT_EP must be >>> + selected. >>> >>> - If you have a controller with this interface, say Y or M here. >>> +config PCIE_DW_PLAT_HOST >>> + bool "Platform bus based DesignWare PCIe Controller - Host mode" >>> + depends on PCI && PCI_MSI_IRQ_DOMAIN >>> + select PCIE_DW_HOST >>> + select PCIE_DW_PLAT >>> + default y >>> + help >>> + Enables support for the PCIe controller in the Designware IP to >>> + work in host mode. There are two instances of PCIe controller in >>> + Designware IP. >>> + This controller can work either as EP or RC. In order to enable >>> + host-specific features PCIE_DW_PLAT_HOST must be selected and in >>> + order to enable device-specific features PCI_DW_PLAT_EP must be >>> + selected. >>> >>> - If unsure, say N. >>> +config PCIE_DW_PLAT_EP >>> + bool "Platform bus based DesignWare PCIe Controller - Endpoint mode" >>> + depends on PCI && PCI_MSI_IRQ_DOMAIN >>> + depends on PCI_ENDPOINT >>> + select PCIE_DW_EP >>> + select PCIE_DW_PLAT >>> + help >>> + Enables support for the PCIe controller in the Designware IP to >>> + work in endpoint mode. There are two instances of PCIe controller >>> + in Designware IP. >>> + This controller can work either as EP or RC. In order to enable >>> + host-specific features PCIE_DW_PLAT_HOST must be selected and in >>> + order to enable device-specific features PCI_DW_PLAT_EP must be >>> + selected. >>> >>> config PCI_EXYNOS >>> bool "Samsung Exynos PCIe controller" >>> diff --git a/drivers/pci/dwc/pcie-designware-ep.c b/drivers/pci/dwc/pcie-designware-ep.c >>> index f07678b..4ac135a 100644 >>> --- a/drivers/pci/dwc/pcie-designware-ep.c >>> +++ b/drivers/pci/dwc/pcie-designware-ep.c >>> @@ -15,8 +15,10 @@ >>> void dw_pcie_ep_linkup(struct dw_pcie_ep *ep) >>> { >>> struct pci_epc *epc = ep->epc; >>> + struct pci_epf *epf; >>> >>> - pci_epc_linkup(epc); >>> + list_for_each_entry(epf, &epc->pci_epf, list) >>> + pci_epf_linkup(epf); >>> } >> >> This shouldn't be required anymore. > > Ok. I'll revert it. > >>> >>> static void __dw_pcie_ep_reset_bar(struct dw_pcie *pci, enum pci_barno bar, >>> diff --git a/drivers/pci/dwc/pcie-designware-plat.c b/drivers/pci/dwc/pcie-designware-plat.c >>> index 5416aa8..5382a7a 100644 >>> --- a/drivers/pci/dwc/pcie-designware-plat.c >>> +++ b/drivers/pci/dwc/pcie-designware-plat.c >>> @@ -12,19 +12,29 @@ >>> #include >>> #include >>> #include >>> +#include >>> #include >>> #include >>> #include >>> #include >>> #include >>> #include >>> +#include >>> >>> #include "pcie-designware.h" >>> >>> struct dw_plat_pcie { >>> - struct dw_pcie *pci; >>> + struct dw_pcie *pci; >>> + struct regmap *regmap; >>> + enum dw_pcie_device_mode mode; >>> }; >>> >>> +struct dw_plat_pcie_of_data { >>> + enum dw_pcie_device_mode mode; >>> +}; >>> + >>> +static const struct of_device_id dw_plat_pcie_of_match[]; >>> + >>> static int dw_plat_pcie_host_init(struct pcie_port *pp) >>> { >>> struct dw_pcie *pci = to_dw_pcie_from_pp(pp); >>> @@ -42,9 +52,53 @@ static const struct dw_pcie_host_ops dw_plat_pcie_host_ops = { >>> .host_init = dw_plat_pcie_host_init, >>> }; >>> >>> -static int dw_plat_add_pcie_port(struct pcie_port *pp, >>> +static int dw_plat_pcie_establish_link(struct dw_pcie *pci) >>> +{ >>> + return 0; >>> +} >>> + >>> +static const struct dw_pcie_ops dw_pcie_ops = { >>> + .start_link = dw_plat_pcie_establish_link, >>> +}; >>> + >>> +static void dw_plat_pcie_ep_init(struct dw_pcie_ep *ep) >>> +{ >>> + struct dw_pcie *pci = to_dw_pcie_from_ep(ep); >>> + enum pci_barno bar; >>> + >>> + for (bar = BAR_0; bar <= BAR_5; bar++) >>> + dw_pcie_ep_reset_bar(pci, bar); >>> +} >>> + >>> +static int dw_plat_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no, >>> + enum pci_epc_irq_type type, >>> + u8 interrupt_num) >>> +{ >>> + struct dw_pcie *pci = to_dw_pcie_from_ep(ep); >>> + >>> + switch (type) { >>> + case PCI_EPC_IRQ_LEGACY: >>> + dev_err(pci->dev, "EP cannot trigger legacy IRQs\n"); >>> + return -EINVAL; >>> + case PCI_EPC_IRQ_MSI: >>> + return dw_pcie_ep_raise_msi_irq(ep, func_no, interrupt_num); >>> + default: >>> + dev_err(pci->dev, "UNKNOWN IRQ type\n"); >>> + } >>> + >>> + return 0; >>> +} >>> + >>> +static struct dw_pcie_ep_ops pcie_ep_ops = { >>> + .ep_init = dw_plat_pcie_ep_init, >>> + .raise_irq = dw_plat_pcie_ep_raise_irq, >>> +}; >>> + >>> +static int dw_plat_add_pcie_port(struct dw_plat_pcie *dw_plat_pcie, >>> struct platform_device *pdev) >>> { >>> + struct dw_pcie *pci = dw_plat_pcie->pci; >>> + struct pcie_port *pp = &pci->pp; >>> struct device *dev = &pdev->dev; >>> int ret; >>> >>> @@ -63,15 +117,44 @@ static int dw_plat_add_pcie_port(struct pcie_port *pp, >>> >>> ret = dw_pcie_host_init(pp); >>> if (ret) { >>> - dev_err(dev, "failed to initialize host\n"); >>> + dev_err(dev, "Failed to initialize host\n"); >>> return ret; >>> } >>> >>> return 0; >>> } >>> >>> -static const struct dw_pcie_ops dw_pcie_ops = { >>> -}; >>> +static int dw_plat_add_pcie_ep(struct dw_plat_pcie *dw_plat_pcie, >>> + struct platform_device *pdev) >>> +{ >>> + int ret; >>> + struct dw_pcie_ep *ep; >>> + struct resource *res; >>> + struct device *dev = &pdev->dev; >>> + struct dw_pcie *pci = dw_plat_pcie->pci; >>> + >>> + ep = &pci->ep; >>> + ep->ops = &pcie_ep_ops; >>> + >>> + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dbi2"); >>> + pci->dbi_base2 = devm_ioremap(dev, res->start, resource_size(res)); >> >> This can throw up a NULL pointer dereferencing error. Use devm_ioremap_resource >> instead. > > I have looked on [1] and [2] and both implementations uses devm_ioremap > function, they are also wrong? > > [1] -> https://elixir.bootlin.com/linux/latest/source/drivers/pci/dwc/pcie-artpec6.c > [2] -> https://elixir.bootlin.com/linux/latest/source/drivers/pci/dwc/pci-dra7xx.c yes, they are wrong. There was a patch to fix it but somehow dropped https://patchwork.kernel.org/patch/10173831/. I'll resend them. Thanks Kishon