Received: by 10.223.164.202 with SMTP id h10csp1017053wrb; Thu, 9 Nov 2017 19:31:23 -0800 (PST) X-Google-Smtp-Source: ABhQp+QuM+syWkb5pYPHwrsGNylsU5KJdFKtDYrAzKfIonhj/3vYFFewYWDNjaUVGBPuoutv80uG X-Received: by 10.84.235.134 with SMTP id p6mr2741695plk.326.1510284683404; Thu, 09 Nov 2017 19:31:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510284683; cv=none; d=google.com; s=arc-20160816; b=GAg1Jqeatj62PllkQWW25rT7FsX2GpKTvrra9c5F7UoRFsclBR7VbjG9Nj6N0zdROc 8xhn4VThxYdbuuKoSRhPEsLMRAD44tl7m4gyfzF3WbNiXqZJRi6UrkK0P/YojuGt3Aw2 bShpUsW4KCC10XaEM3A4pkS0SBOoJPPFR4ySXh1tP5hlJ4fzbGg+I7VZJ32dAUOSUfr0 yDGXBCLV/5Oxx48ocdpDUjU8D+YrNmtVvpfrfRWvmbgHQRRE2Gm0fhIPTNQNEJLPxAAp OPum/apwua0EoLcth8TwVqFbs74KWIT0l2kcT0MkxKbsYEjQ421sBRC1wz3fpqqAQLxe Nt8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=ULWKtZaSyJLTYhSEUDpf5llRGwKz7jgjy0b7F2/5eak=; b=03Lz7YmITVlkmiMqh9SWRkCAlFKQGO3ytq+dKzyB9G+065D3pd7dBJi3o819YmorF7 194QGsQzWype0yaXuDwF1h4PHw3GoVauKT6gxNO9jc22MEZiHzepha1QqPxUiLYMdQe9 /9Aj9PILTxlMBRv788R5lepFGxUO7Rsm3EClYgTlRSnGhQVTg4ugXpjpZfHWPvkjEetx Y0ERZMxLrNF/vztH/JJy87yeJslqYCpgGvEHGSVjLWPAC8y0fe4fOeDoXLGf4CyU7uDD gmUN8pGEkexwwBo/n2WFfgI043rDfsrIFn4+v3DnZh6NJrNYFMg3dUDzaHQZglnO1X+1 mKrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector1 header.b=mcI4blDp; 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=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e26si8358433pfj.1.2017.11.09.19.31.11; Thu, 09 Nov 2017 19:31:23 -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=@nxp.com header.s=selector1 header.b=mcI4blDp; 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=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755817AbdKJDaf (ORCPT + 83 others); Thu, 9 Nov 2017 22:30:35 -0500 Received: from mail-ve1eur01on0046.outbound.protection.outlook.com ([104.47.1.46]:51264 "EHLO EUR01-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755701AbdKJDac (ORCPT ); Thu, 9 Nov 2017 22:30:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=ULWKtZaSyJLTYhSEUDpf5llRGwKz7jgjy0b7F2/5eak=; b=mcI4blDpqbcxk2t9qzpUlhsrebEHr2JZyxcl/ceFHgDF/UHo/BoJfa6ZTPgJwiSdmEG2i12+YBpiDb0w7G5/+DBMf/PT7Hvs8J67b0wEqyfvAr9VQLg+QtK062nF6e2TbNlMnsZf3iUK6edezv2jDVwke82uLzNRFS08qBKm6ic= Received: from VI1PR04MB1615.eurprd04.prod.outlook.com (10.164.84.149) by VI1PR04MB1455.eurprd04.prod.outlook.com (10.163.166.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.197.13; Fri, 10 Nov 2017 03:30:27 +0000 Received: from VI1PR04MB1615.eurprd04.prod.outlook.com ([fe80::18d5:5f7c:e04f:3bd2]) by VI1PR04MB1615.eurprd04.prod.outlook.com ([fe80::18d5:5f7c:e04f:3bd2%13]) with mapi id 15.20.0197.017; Fri, 10 Nov 2017 03:30:27 +0000 From: "M.h. Lian" To: Xiaowei Bao , "robh+dt@kernel.org" , "mark.rutland@arm.com" , "catalin.marinas@arm.com" , "will.deacon@arm.com" , "bhelgaas@google.com" , "shawnguo@kernel.org" , Madalin-cristian Bucur , Sumit Garg , "Y.b. Lu" , "hongtao.jia@nxp.com" , Andy Tang , Leo Li , "kishon@ti.com" , "jingoohan1@gmail.com" , "pbrobinson@gmail.com" , "songxiaowei@hisilicon.com" , "devicetree@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" , "linux-pci@vger.kernel.org" , "linuxppc-dev@lists.ozlabs.org" , "Z.q. Hou" , "Mingkai Hu" CC: Xiaowei Bao Subject: RE: [PATCHv3 2/3] ARMv8: layerscape: add the pcie ep function support Thread-Topic: [PATCHv3 2/3] ARMv8: layerscape: add the pcie ep function support Thread-Index: AQHTWdElRiC3N6AaI0uQXkOJdHQYIKMM8FsA Date: Fri, 10 Nov 2017 03:30:27 +0000 Message-ID: References: <20171110024926.39700-1-xiaowei.bao@nxp.com> <20171110024926.39700-3-xiaowei.bao@nxp.com> In-Reply-To: <20171110024926.39700-3-xiaowei.bao@nxp.com> Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [192.158.241.86] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;VI1PR04MB1455;6:osi4daH47ERbYvZdpvlWgQeH0jXdA5OOoG7Ecs4/ETFQ85+4bQhBpRRK0prvfYa4d3wrEwMr8/qwa/0o9gZBzqwMTf78fZM82d007aQR4yN7DSouvQaNjhrQFmnWZ3PaGCo7CFUXP5I3G5VtNeTntqknIr9mFtceE0PeBv9BJIfLrOBf8EPw426YRaY/uMb6QAPt+UdqOnXaMlDj7MG2B0AU72u+5h+MuuOPUQQvp5RvPanROIjH5eChNj9wXBZnXfkNdELg3s0vbAZiPvpDnu5KWk3R9hSs4MIKRJvP/ACDPbX4Fyzj95fjDrSVV+Ielv4Qv1kOFw5JEBYVzwuSWVAYyX/wWW14tlHgugS9bn0=;5:mx8mJPN3Lm9KzELI3mR/HE2rir85odoXkvouRgqhKbuOPxO1kRo5ZFpzuCxCkokiRmQ81S3ECdcD7M0YsZ0sm6MLpvEc1cdqFLZGHxAeNGeyo0QTqwAHu75mh7dqe5ufUZI4aM4fhx2vfJ5406GECPBcTmHZXxKeZH+VyTtQv/M=;24:4vxI+li4w9frnS+6Lo1Tq9PE4jY2IpB8jmfwm5iHdBC4Y5HWdoV7xMyUv3eNMczji4JimxEeOanKD0PJyxjMnxGzgCm9mWC/gwQYj1EvrpQ=;7:e9PS3Xwy36IC5IlKvVAwuRsEnrP0bFBU71vUoYLm+1KQXwTrAa7aEGA5LRLQw1LjQ3Z1eAJUNmuuvLbq1jIHRgcdubtp89WNIXnlsVntr9qGtkt2ThHWFQNV6lHF1KuyQIHUF8mncnB/A6152LTSifyeERJytFvWnh2uVvh0+I9MwUwIhf6w7OXemZG6S3DgK68IJaXcOPd366YxPsBg+/i1UFCpH3Jng98mrDQ/crJTFWtyyryNnZrFgCwSUKcV x-ms-office365-filtering-correlation-id: 34e7ba5e-3fdb-413d-ac56-08d527eb631d x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(48565401081)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(2017052603256);SRVR:VI1PR04MB1455; x-ms-traffictypediagnostic: VI1PR04MB1455: x-exchange-antispam-report-test: UriScan:(180628864354917)(31051911155226)(9452136761055)(65623756079841)(185117386973197)(258649278758335)(211936372134217); x-microsoft-antispam-prvs: x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(5005006)(8121501046)(100000703101)(100105400095)(3002001)(93006095)(93001095)(10201501046)(3231021)(920507027)(6055026)(6041248)(20161123555025)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(20161123564025)(20161123562025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:VI1PR04MB1455;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:VI1PR04MB1455; x-forefront-prvs: 0487C0DB7E x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(6009001)(39860400002)(346002)(376002)(13464003)(189002)(199003)(3280700002)(99286004)(68736007)(2950100002)(2900100001)(9686003)(2906002)(33656002)(6506006)(189998001)(6436002)(39060400002)(6246003)(229853002)(76176999)(478600001)(54356999)(25786009)(101416001)(3846002)(6636002)(4326008)(53936002)(316002)(5250100002)(50986999)(110136005)(7736002)(14454004)(53546010)(2501003)(74316002)(7696004)(81156014)(8676002)(86362001)(305945005)(97736004)(34040400001)(7416002)(6116002)(575784001)(102836003)(55016002)(66066001)(5660300001)(3660700001)(106356001)(105586002)(8936002)(81166006)(2201001)(921003)(1121003);DIR:OUT;SFP:1101;SCL:1;SRVR:VI1PR04MB1455;H:VI1PR04MB1615.eurprd04.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; received-spf: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=minghuan.lian@nxp.com; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 34e7ba5e-3fdb-413d-ac56-08d527eb631d X-MS-Exchange-CrossTenant-originalarrivaltime: 10 Nov 2017 03:30:27.4605 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB1455 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > -----Original Message----- > From: Bao Xiaowei [mailto:xiaowei.bao@nxp.com] > Sent: Friday, November 10, 2017 10:49 AM > To: robh+dt@kernel.org; mark.rutland@arm.com; catalin.marinas@arm.com; > will.deacon@arm.com; bhelgaas@google.com; shawnguo@kernel.org; > Madalin-cristian Bucur ; Sumit Garg > ; Y.b. Lu ; hongtao.jia@nxp.com; > Andy Tang ; Leo Li ; > kishon@ti.com; jingoohan1@gmail.com; pbrobinson@gmail.com; > songxiaowei@hisilicon.com; devicetree@vger.kernel.org; linux-arm- > kernel@lists.infradead.org; linux-kernel@vger.kernel.org; linux- > pci@vger.kernel.org; linuxppc-dev@lists.ozlabs.org; Z.q. Hou > ; Mingkai Hu ; M.h. Lian > > Cc: Xiaowei Bao > Subject: [PATCHv3 2/3] ARMv8: layerscape: add the pcie ep function suppor= t >=20 > Add the pcie controller ep function support of layerscape base on pcie ep > framework. >=20 > Signed-off-by: Bao Xiaowei > --- > v2: > - fix the ioremap function used but no ioumap issue > - optimize the code structure > - add code comments > v3: > - fix the msi outband window request failed issue >=20 > drivers/pci/dwc/pci-layerscape.c | 124 > +++++++++++++++++++++++++++++++++++++-- > 1 file changed, 118 insertions(+), 6 deletions(-) >=20 > diff --git a/drivers/pci/dwc/pci-layerscape.c b/drivers/pci/dwc/pci-layer= scape.c > index 87fa486bee2c..d787375528eb 100644 > --- a/drivers/pci/dwc/pci-layerscape.c > +++ b/drivers/pci/dwc/pci-layerscape.c > @@ -34,7 +34,12 @@ > /* PEX Internal Configuration Registers */ > #define PCIE_STRFMR1 0x71c /* Symbol Timer & Filter Mask Register1 > */ >=20 > +#define PCIE_DBI2_BASE 0x1000 /* DBI2 base address*/ > +#define PCIE_MSI_MSG_DATA_OFF 0x5c /* MSI Data register address*/ > +#define PCIE_MSI_OB_SIZE 4096 > +#define PCIE_MSI_ADDR_OFFSET (1024 * 1024) > #define PCIE_IATU_NUM 6 > +#define PCIE_EP_ADDR_SPACE_SIZE 0x100000000 >=20 > struct ls_pcie_drvdata { > u32 lut_offset; > @@ -44,12 +49,20 @@ struct ls_pcie_drvdata { > const struct dw_pcie_ops *dw_pcie_ops; }; >=20 > +struct ls_pcie_ep { > + dma_addr_t msi_phys_addr; > + void __iomem *msi_virt_addr; > + u64 msi_msg_addr; > + u16 msi_msg_data; > +}; > + > struct ls_pcie { > struct dw_pcie *pci; > void __iomem *lut; > struct regmap *scfg; > const struct ls_pcie_drvdata *drvdata; > int index; > + struct ls_pcie_ep *pcie_ep; > }; >=20 > #define to_ls_pcie(x) dev_get_drvdata((x)->dev) > @@ -263,6 +276,100 @@ static const struct of_device_id ls_pcie_of_match[]= =3D > { > { }, > }; >=20 > +static void ls_pcie_raise_msi_irq(struct ls_pcie_ep *pcie_ep) { > + iowrite32(pcie_ep->msi_msg_data, pcie_ep->msi_virt_addr); } > + > +static int ls_pcie_raise_irq(struct dw_pcie_ep *ep, > + enum pci_epc_irq_type type, u8 interrupt_num) { > + struct dw_pcie *pci =3D to_dw_pcie_from_ep(ep); > + struct ls_pcie *pcie =3D to_ls_pcie(pci); > + struct ls_pcie_ep *pcie_ep =3D pcie->pcie_ep; > + u32 free_win; > + > + /* get the msi message address and msi message data */ > + pcie_ep->msi_msg_addr =3D ioread32(pci->dbi_base + > MSI_MESSAGE_ADDR_L32) | > + (((u64)ioread32(pci->dbi_base + MSI_MESSAGE_ADDR_U32)) << > 32); > + pcie_ep->msi_msg_data =3D ioread16(pci->dbi_base + > +PCIE_MSI_MSG_DATA_OFF); > + > + /* request and config the outband window for msi */ > + free_win =3D find_first_zero_bit(&ep->ob_window_map, > + sizeof(ep->ob_window_map)); > + if (free_win >=3D ep->num_ob_windows) { > + dev_err(pci->dev, "no free outbound window\n"); > + return -ENOMEM; > + } > + > + dw_pcie_prog_outbound_atu(pci, free_win, PCIE_ATU_TYPE_MEM, > + pcie_ep->msi_phys_addr, > + pcie_ep->msi_msg_addr, > + PCIE_MSI_OB_SIZE); > + > + set_bit(free_win, &ep->ob_window_map); > + > + /* generate the msi interrupt */ > + ls_pcie_raise_msi_irq(pcie_ep); > + > + /* release the outband window of msi */ > + dw_pcie_disable_atu(pci, free_win, DW_PCIE_REGION_OUTBOUND); > + clear_bit(free_win, &ep->ob_window_map); > + > + return 0; > +} > + > +static struct dw_pcie_ep_ops pcie_ep_ops =3D { > + .raise_irq =3D ls_pcie_raise_irq, > +}; > + > +static int __init ls_add_pcie_ep(struct ls_pcie *pcie, > + struct platform_device *pdev) > +{ > + struct dw_pcie *pci =3D pcie->pci; > + struct device *dev =3D pci->dev; > + struct dw_pcie_ep *ep; > + struct ls_pcie_ep *pcie_ep; > + struct resource *cfg_res; > + int ret; > + > + ep =3D &pci->ep; > + ep->ops =3D &pcie_ep_ops; > + > + pcie_ep =3D devm_kzalloc(dev, sizeof(*pcie_ep), GFP_KERNEL); > + if (!pcie_ep) > + return -ENOMEM; > + > + pcie->pcie_ep =3D pcie_ep; > + > + cfg_res =3D platform_get_resource_byname(pdev, IORESOURCE_MEM, > "config"); > + if (cfg_res) { > + ep->phys_base =3D cfg_res->start; > + ep->addr_size =3D PCIE_EP_ADDR_SPACE_SIZE; > + } else { > + dev_err(dev, "missing *config* space\n"); > + return -ENODEV; > + } > + > + pcie_ep->msi_phys_addr =3D ep->phys_base + PCIE_MSI_ADDR_OFFSET; > + > + pcie_ep->msi_virt_addr =3D ioremap(pcie_ep->msi_phys_addr, > + PCIE_MSI_OB_SIZE); > + if (!pcie_ep->msi_virt_addr) { > + dev_err(dev, "failed to map MSI outbound region\n"); > + return -ENOMEM; > + } > + > + ret =3D dw_pcie_ep_init(ep); > + if (ret) { > + dev_err(dev, "failed to initialize endpoint\n"); > + return ret; > + } > + > + return 0; > + [Minghuan Lian] Remove unnecessary blank line. > +} > + > static int __init ls_add_pcie_port(struct ls_pcie *pcie) { > struct dw_pcie *pci =3D pcie->pci; > @@ -309,16 +416,21 @@ static int __init ls_pcie_probe(struct platform_dev= ice > *pdev) > if (IS_ERR(pci->dbi_base)) > return PTR_ERR(pci->dbi_base); >=20 > - pcie->lut =3D pci->dbi_base + pcie->drvdata->lut_offset; > + pci->dbi_base2 =3D pci->dbi_base + PCIE_DBI2_BASE; >=20 > - if (!ls_pcie_is_bridge(pcie)) > - return -ENODEV; > + pcie->lut =3D pci->dbi_base + pcie->drvdata->lut_offset; >=20 > platform_set_drvdata(pdev, pcie); >=20 > - ret =3D ls_add_pcie_port(pcie); > - if (ret < 0) > - return ret; > + if (!ls_pcie_is_bridge(pcie)) { > + ret =3D ls_add_pcie_ep(pcie, pdev); > + if (ret < 0) > + return ret; > + } else { > + ret =3D ls_add_pcie_port(pcie); > + if (ret < 0) > + return ret; > + } >=20 > return 0; We can clean code like this: if (!ls_pcie_is_bridge(pcie))=20 ret =3D ls_add_pcie_ep(pcie, pdev); else=20 ret =3D ls_add_pcie_port(pcie); return ret; > } > -- > 2.14.1 From 1583646870726718464@xxx Fri Nov 10 03:09:06 +0000 2017 X-GM-THRID: 1583646870726718464 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread