Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753456AbcKJAgK (ORCPT ); Wed, 9 Nov 2016 19:36:10 -0500 Received: from mail-db5eur01on0068.outbound.protection.outlook.com ([104.47.2.68]:16848 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751934AbcKJAgI (ORCPT ); Wed, 9 Nov 2016 19:36:08 -0500 From: Stuart Yoder To: Ruxandra Ioana Radulescu , "gregkh@linuxfoundation.org" CC: "devel@driverdev.osuosl.org" , "linux-kernel@vger.kernel.org" , "agraf@suse.de" , "arnd@arndb.de" , Leo Li , Roy Pledge , Haiying Wang Subject: RE: [PATCH 8/9] bus: fsl-mc: dpio: add the DPAA2 DPIO object driver Thread-Topic: [PATCH 8/9] bus: fsl-mc: dpio: add the DPAA2 DPIO object driver Thread-Index: AQHSK6SUAF2ytlfJTECvWCh2Z1kO06DHaH8ggAGa7YCACHU7AA== Date: Thu, 10 Nov 2016 00:20:09 +0000 Message-ID: References: <1477058509-12547-1-git-send-email-stuart.yoder@nxp.com> <1477058509-12547-9-git-send-email-stuart.yoder@nxp.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=stuart.yoder@nxp.com; x-originating-ip: [192.88.168.1] x-ms-office365-filtering-correlation-id: 3bc1809a-ba45-40f1-4e5b-08d408ff5483 x-microsoft-exchange-diagnostics: 1;VI1PR0401MB2637;7:HldQCIlb47jV062sDBoEHx34mhCX97mZPgcy1SzpA11ScVKr7nr1qnDDZzpWj1nbejpScntvOcVIn+ILupvte60v3ywN3lZBiK5WSSQl51roNMcvVS53BcjRpGBJ9GCsZ2WJeuO7WN+NYSdGUIQ63Tm02+uPLxqpyiIYSxIZrbvytRSh8G46Yr1v/K2wxULhrrJo6umC+x4CWcbS/LvHp7NYstDW3lXtKvsw20KQTwxrexCp4qTFXz7F3OlmKK/vrRwIQ3Fn5//1jLiyu3SkzluK8AqMkLqPVHcSOzkgJVRe4ixNlS5nyz3JxsUu2PQOMdYNBnSFfxr3XS5uMzwe21PIRqEU6XLNfA3TbMIJLbs= x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:VI1PR0401MB2637; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(9452136761055)(185117386973197)(275809806118684); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(6045074)(6060229)(6040176)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6055026)(6046074)(6072074);SRVR:VI1PR0401MB2637;BCL:0;PCL:0;RULEID:;SRVR:VI1PR0401MB2637; x-forefront-prvs: 01221E3973 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(6009001)(7916002)(377454003)(13464003)(199003)(189002)(105586002)(106116001)(106356001)(76576001)(54356999)(8936002)(66066001)(101416001)(50986999)(2950100002)(5660300001)(6116002)(76176999)(102836003)(3846002)(7696004)(77096005)(68736007)(2900100001)(92566002)(586003)(2906002)(9686002)(33656002)(3280700002)(93886004)(4326007)(3900700001)(3660700001)(87936001)(189998001)(5001770100001)(86362001)(122556002)(2501003)(97736004)(8676002)(81156014)(74316002)(305945005)(81166006)(7846002)(7736002)(229853002)(2004002);DIR:OUT;SFP:1101;SCL:1;SRVR:VI1PR0401MB2637;H:VI1PR0401MB2638.eurprd04.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-originalarrivaltime: 10 Nov 2016 00:20:09.0724 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0401MB2637 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by mail.home.local id uAA0aKT1020079 Content-Length: 8668 Lines: 247 > -----Original Message----- > From: Ruxandra Ioana Radulescu > Sent: Friday, November 04, 2016 10:11 AM > To: Stuart Yoder ; gregkh@linuxfoundation.org > Cc: German Rivera ; devel@driverdev.osuosl.org; linux-kernel@vger.kernel.org; > agraf@suse.de; arnd@arndb.de; Leo Li ; Roy Pledge ; Haiying Wang > ; Stuart Yoder > Subject: RE: [PATCH 8/9] bus: fsl-mc: dpio: add the DPAA2 DPIO object driver > > > -----Original Message----- > > From: Stuart Yoder > > Sent: Thursday, November 03, 2016 4:38 PM > > To: Ruxandra Ioana Radulescu > > Subject: FW: [PATCH 8/9] bus: fsl-mc: dpio: add the DPAA2 DPIO object > > driver > > > > > > > > -----Original Message----- > > From: Stuart Yoder [mailto:stuart.yoder@nxp.com] > > Sent: Friday, October 21, 2016 9:02 AM > > To: gregkh@linuxfoundation.org > > Cc: German Rivera ; devel@driverdev.osuosl.org; > > linux-kernel@vger.kernel.org; agraf@suse.de; arnd@arndb.de; Leo Li > > ; Roy Pledge ; Haiying Wang > > ; Stuart Yoder > > Subject: [PATCH 8/9] bus: fsl-mc: dpio: add the DPAA2 DPIO object driver > > > > From: Roy Pledge > > > > The DPIO driver registers with the fsl-mc bus to handle bus-related > > events for DPIO objects. Key responsibility is mapping I/O > > regions, setting up interrupt handlers, and calling the DPIO > > service initialization during probe. > > > > Signed-off-by: Roy Pledge > > Signed-off-by: Haiying Wang > > Signed-off-by: Stuart Yoder > > --- > > drivers/bus/fsl-mc/dpio/Makefile | 2 +- > > drivers/bus/fsl-mc/dpio/dpio-driver.c | 289 > > ++++++++++++++++++++++++++++++++++ > > 2 files changed, 290 insertions(+), 1 deletion(-) > > create mode 100644 drivers/bus/fsl-mc/dpio/dpio-driver.c > > > > diff --git a/drivers/bus/fsl-mc/dpio/Makefile b/drivers/bus/fsl- > > mc/dpio/Makefile > > index 0778da7..837d330 100644 > > --- a/drivers/bus/fsl-mc/dpio/Makefile > > +++ b/drivers/bus/fsl-mc/dpio/Makefile > > @@ -6,4 +6,4 @@ subdir-ccflags-y := -Werror > > > > obj-$(CONFIG_FSL_MC_DPIO) += fsl-mc-dpio.o > > > > -fsl-mc-dpio-objs := dpio.o qbman-portal.o dpio-service.o > > +fsl-mc-dpio-objs := dpio.o qbman-portal.o dpio-service.o dpio-driver.o > > diff --git a/drivers/bus/fsl-mc/dpio/dpio-driver.c b/drivers/bus/fsl- > > mc/dpio/dpio-driver.c > > new file mode 100644 > > index 0000000..ad04a2c > > --- /dev/null > > +++ b/drivers/bus/fsl-mc/dpio/dpio-driver.c > > @@ -0,0 +1,289 @@ > > +/* > > + * Copyright 2014-2016 Freescale Semiconductor Inc. > > + * > > + * Redistribution and use in source and binary forms, with or without > > + * modification, are permitted provided that the following conditions are > > met: > > + * * Redistributions of source code must retain the above copyright > > + * notice, this list of conditions and the following disclaimer. > > + * * Redistributions in binary form must reproduce the above copyright > > + * notice, this list of conditions and the following disclaimer in the > > + * documentation and/or other materials provided with the > > distribution. > > + * * Neither the name of Freescale Semiconductor nor the > > + * names of its contributors may be used to endorse or promote > > products > > + * derived from this software without specific prior written permission. > > + * > > + * ALTERNATIVELY, this software may be distributed under the terms of the > > + * GNU General Public License ("GPL") as published by the Free Software > > + * Foundation, either version 2 of that License or (at your option) any > > + * later version. > > + * > > + * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND > > ANY > > + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, > > THE IMPLIED > > + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR > > PURPOSE ARE > > + * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR > > ANY > > + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR > > CONSEQUENTIAL DAMAGES > > + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE > > GOODS OR SERVICES; > > + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) > > HOWEVER CAUSED AND > > + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, > > OR TORT > > + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF > > THE USE OF THIS > > + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > > + */ > > + > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > + > > +#include > > +#include > > + > > +#include "qbman-portal.h" > > +#include "dpio.h" > > +#include "dpio-cmd.h" > > + > > +MODULE_LICENSE("Dual BSD/GPL"); > > +MODULE_AUTHOR("Freescale Semiconductor, Inc"); > > +MODULE_DESCRIPTION("DPIO Driver"); > > + > > +struct dpio_priv { > > + struct dpaa2_io *io; > > +}; > > + > > +static irqreturn_t dpio_irq_handler(int irq_num, void *arg) > > +{ > > + struct device *dev = (struct device *)arg; > > + struct dpio_priv *priv = dev_get_drvdata(dev); > > + > > + return dpaa2_io_irq(priv->io); > > +} > > + > > +static void unregister_dpio_irq_handlers(struct fsl_mc_device *dpio_dev) > > +{ > > + struct fsl_mc_device_irq *irq; > > + > > + irq = dpio_dev->irqs[0]; > > + > > + /* clear the affinity hint */ > > + irq_set_affinity_hint(irq->msi_desc->irq, NULL); > > +} > > + > > +static int register_dpio_irq_handlers(struct fsl_mc_device *dpio_dev, int > > cpu) > > +{ > > + struct dpio_priv *priv; > > + int error; > > + struct fsl_mc_device_irq *irq; > > + cpumask_t mask; > > + > > + priv = dev_get_drvdata(&dpio_dev->dev); > > + > > + irq = dpio_dev->irqs[0]; > > + error = devm_request_irq(&dpio_dev->dev, > > + irq->msi_desc->irq, > > + dpio_irq_handler, > > + 0, > > + dev_name(&dpio_dev->dev), > > + &dpio_dev->dev); > > + if (error < 0) { > > + dev_err(&dpio_dev->dev, > > + "devm_request_irq() failed: %d\n", > > + error); > > + return error; > > + } > > + > > + /* set the affinity hint */ > > + cpumask_clear(&mask); > > + cpumask_set_cpu(cpu, &mask); > > + if (irq_set_affinity_hint(irq->msi_desc->irq, &mask)) > > + dev_err(&dpio_dev->dev, > > + "irq_set_affinity failed irq %d cpu %d\n", > > + irq->msi_desc->irq, cpu); > > + > > + return 0; > > +} > > + > > +static int dpaa2_dpio_probe(struct fsl_mc_device *dpio_dev) > > +{ > > + struct dpio_attr dpio_attrs; > > + struct dpaa2_io_desc desc; > > + struct dpio_priv *priv; > > + int err = -ENOMEM; > > + struct device *dev = &dpio_dev->dev; > > + static int next_cpu = -1; > > + > > + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); > > + if (!priv) > > + goto err_priv_alloc; > > + > > + dev_set_drvdata(dev, priv); > > + > > + err = fsl_mc_portal_allocate(dpio_dev, 0, &dpio_dev->mc_io); > > + if (err) { > > + dev_dbg(dev, "MC portal allocation failed\n"); > > + err = -EPROBE_DEFER; > > + goto err_mcportal; > > + } > > + > > + err = dpio_open(dpio_dev->mc_io, 0, dpio_dev->obj_desc.id, > > + &dpio_dev->mc_handle); > > + if (err) { > > + dev_err(dev, "dpio_open() failed\n"); > > + goto err_open; > > + } > > + > > + err = dpio_get_attributes(dpio_dev->mc_io, 0, dpio_dev- > > >mc_handle, > > + &dpio_attrs); > > + if (err) { > > + dev_err(dev, "dpio_get_attributes() failed %d\n", err); > > + goto err_get_attr; > > + } > > + desc.qman_version = dpio_attrs.qbman_version; > > + > > + err = dpio_enable(dpio_dev->mc_io, 0, dpio_dev->mc_handle); > > + if (err) { > > + dev_err(dev, "dpio_enable() failed %d\n", err); > > + goto err_get_attr; > > + } > > + > > + /* initialize DPIO descriptor */ > > + desc.receives_notifications = dpio_attrs.num_priorities ? 1 : 0; > > + desc.has_8prio = dpio_attrs.num_priorities == 8 ? 1 : 0; > > + desc.dpio_id = dpio_dev->obj_desc.id; > > + > > + /* get the cpu to use for the affinity hint */ > > + if (next_cpu == -1) > > + next_cpu = cpumask_first(cpu_online_mask); > > + else > > + next_cpu = cpumask_next(next_cpu, cpu_online_mask); > > + desc.cpu = next_cpu; > > What happens if there's more DPIOs than cores and cpumask_next > returns nr_cpu_ids? We need to error out in that case. DPIO can't handle >= NR_CPUS. Stuart