Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1422670AbcKPURw (ORCPT ); Wed, 16 Nov 2016 15:17:52 -0500 Received: from mail-sn1nam01on0073.outbound.protection.outlook.com ([104.47.32.73]:59664 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S934414AbcKPUQw (ORCPT ); Wed, 16 Nov 2016 15:16:52 -0500 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=nxp.com; nxp.com; dkim=none (message not signed) header.d=none;nxp.com; dmarc=fail action=none header.from=nxp.com;nxp.com; dkim=none (message not signed) header.d=none; X-IncomingTopHeaderMarker: OriginalChecksum:;UpperCasedChecksum:;SizeAsReceived:1062;Count:10 From: Stuart Yoder To: CC: , , , , , , , , Roy Pledge , Haiying Wang , "Stuart Yoder" , Laurentiu Tudor , Ioana Radulescu Subject: [PATCH v2 8/9] bus: fsl-mc: dpio: add the DPAA2 DPIO object driver Date: Wed, 16 Nov 2016 14:09:58 -0600 Message-ID: <1479326999-29340-9-git-send-email-stuart.yoder@nxp.com> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1479326999-29340-1-git-send-email-stuart.yoder@nxp.com> References: <1479326999-29340-1-git-send-email-stuart.yoder@nxp.com> X-IncomingHeaderCount: 10 X-EOPAttributedMessage: 0 X-Matching-Connectors: 131238010098378274;(91ab9b29-cfa4-454e-5278-08d120cd25b8);() X-Forefront-Antispam-Report: CIP:192.88.168.50;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(7916002)(2980300002)(1110001)(1109001)(339900001)(336004)(199003)(189002)(105606002)(36756003)(68736007)(33646002)(189998001)(104016004)(6916009)(76176999)(2950100002)(50986999)(97736004)(106466001)(86362001)(7416002)(8676002)(6666003)(626004)(5660300001)(8666005)(4326007)(7846002)(85426001)(50226002)(356003)(110136003)(8936002)(77096005)(305945005)(81156014)(81166006)(48376002)(92566002)(2906002)(47776003)(87936001)(2351001)(50466002)(5003940100001)(7059030)(2004002);DIR:OUT;SFP:1101;SCL:1;SRVR:BN1PR0301MB0738;H:tx30smr01.am.freescale.net;FPR:;SPF:Fail;PTR:InfoDomainNonexistent;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BL2FFO11FD018;1:nm8yFY9BXjDhoF1FqnCA849dDVOxTwJnfGUeNpQtbN+pZICZlSUMIGHRP1os3d2hUZwtxlRx76ClCqxxujyE1TAi2JBitRHZUx5KUppUbtrPlTfozlggc2C0JtLD9V+MSZmeKMssvFwXrVc/a1I6ApsqpLBRjbOgPCDImZFpbEvpygAsNRqnDU/vt/zHg4Ez1/eRqRvKrciJf7JnUi43tsVSS9WXKyLfp4+W4zBfdLiDZOsZc9wirHaW9qKRGntZUlFF45NCP46SfhnIxHSNqM6TSa16+JikXc9PUXjDYHHRVjrq2lkpuAlUWQydhHhZzFV0LL+JpcKraQVqsJj4FXUJJkpT+k1e/L3ydauhVrMG1DvsxX6kKFmdtiUWeBajKilCi8kfkhaOihzXZ5hHThdqZMXI+m8n/zTEu2mZBrS6tNwkvnU8jdEUDif48QnwSHr4mka1f8iLfYPjBBasyz6Xd2+YR+NDI+5d7HIoNrxcgndJKChV92sGdJV460ekRfKXdp4HotMTO14khieECJmaaDFv640OdzuP+sQdGwkPeM/XazEZ5E7vF5zSaz/FaL12aCQD/QHjUXtd8/lYmxEtb0q6q2nzpxZm1YwbISOuwGUpka+j53RVMuEoqmH8OLbfzJ045v1jG/lnbRevGYBAxtOEumqXNFwwY+L1DVhm35e4QmmOLhMXOB3Q4Qx1yYY+kCZ650ufnxjrAvF1GkntCaOfb1tG9d6o8zLPEyY= MIME-Version: 1.0 Content-Type: text/plain X-Microsoft-Exchange-Diagnostics: 1;BN1PR0301MB0738;2:S4Fq2raWdhFAPitPn8eEQYVmqjk6lw++ATdQUrJRP8NcCXBaTAxX7tM3m2ZJ6kT/1OE5WLElcnBftapHlQzZ/0XnmGkq/YIMYzSKD5L0SnJtSCe1G8K+/Q5moNnlGxuUt4TinmUONKGKCXOL6YDXssHHt7wi0UsCvuRhyOK5C6k=;3:GDyJscUayW3xizUqPMDf71AuVnOfxficFZi2by57oh+0q4F4XCYF8QnrzFG12llSwq+FK29E5P0x1Ndy80ACGLqU9rAkA6c99QNQQeH/FSDEroTPlb2WDtSRXbMX6jGWama+efrZ9vJK31o6tdOzkjLGhWBypZChNCndne3aqo4KXVGAol1rXmKM++qQXwvEiFW/Sv6x+FW+JHlgcuBMbSALEoEbHMu8O/sjrDadt+hobCi+vn56WRHNnBY7i2CGDVbcR2AqCk1nCVpTa7kl4A== X-MS-Office365-Filtering-Correlation-Id: ad02414b-6355-4ad8-6622-08d40e5d7f68 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:BN1PR0301MB0738; X-Microsoft-Exchange-Diagnostics: 1;BN1PR0301MB0738;25:bt9LEVKPOyQ1+BF/zn6paxjg9op7EGnLTliNW/fay1DlzB+FDx7IJma5s/1CClkSMgQa9uCL+RDuh2VIRrS+JC19k7HkZva/PJaT1ce9JpuHffq1uBsQ3gNbEg1mJj4FoHval16MJbARnEi15G0D2tw4wo6Lcc/1tzITUxUf+z30GQazq8tKUBT1GAu+TxMNizLz/l/ANWUMmLCehIw5hI+QAtdqKr8c5PsBZLVATX05r1lVyGtqYseg/Y81QtGuljc9OWn2PJSUJVNpCshyc0dwnFS+KAxR3cakg5eTkUISf78WclUr4g7mn7LmVl3ra5+sYilGbbeMD+wrD7b6T5HCwOq0aTdpYcK0LTXQAJnjsV01S9PSCN8YoSThCe74O1nIcAJnbv3YMtnnSf6ZjritASBhQCWnOAOWZFApnAoTZf+3VqgtC99GAg7boO35YDz/tUuphHNwvYPmuG+yN/IVGi8YAy98Sd1TZ6Uri1iLqrSk5nEU4Ka3QfLm5xbpaYeq6GvaakZYoGR/fAQcjKPLaDczIyIioDIc78HN+d1T1/7UK6EetI6ISR0GvY4CP5KusMR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jFvtEav3VsVqwslwHRDKIZjHG9DNnhW+U13GdqRsMcodXN4Erxe5MdwMhk5UQRJOX9d61REy8yVTBI+HWUgzzE/CpTuwEf9UH1o5fZKQ= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197)(275809806118684); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6095035)(601004)(2401047)(13018025)(13023025)(13024025)(8121501046)(5005006)(13015025)(13017025)(3002001)(10201501046)(6055026)(6096035);SRVR:BN1PR0301MB0738;BCL:0;PCL:0;RULEID:(400006);SRVR:BN1PR0301MB0738; X-Forefront-PRVS: 01283822F8 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BN1PR0301MB0738;23:j7BS/2emaDAJimeG4uIFMHFARtGkJqolUQ3ptnx?= =?us-ascii?Q?T8QWvU0ZQBsJrSEDplSn1+8FbCSRAC51saF+lvDlH7Y7sQBCv4GQOejM/xdl?= =?us-ascii?Q?7LnXc2NCbM4G9vK4KHcBg3MVfWbbJoIG6K/VAogeJIVwb0CvNmwZwQCeCRe9?= =?us-ascii?Q?f/Sr3fXkP0Kl42ChWuASfkZRCmP+7a26MlGV0B+zVh3OE/oj/11QL9ko8BqR?= =?us-ascii?Q?RF8Dx40G3IyWg/A8BFjdU7J/8GaFr3mQHpOFoa4VIs3urTpEWOJ+uG4FDXA6?= =?us-ascii?Q?2t1CoiK/E3R+vhCvVHweAnIgVj8RiFqpGhL22Lk9Qo+KUKJ/EIKKxUWghQ1F?= =?us-ascii?Q?QJHzyXAXTtc1lReWEm0XtZZXzLNrJHF7ccvkeRxDvKSohMGSeJaNwmBQyQfo?= =?us-ascii?Q?b9MOo8gN2HU57Q1HqYoEcEni5v7UxZWZ1Af4kZMXzf+60Dqsx8zVIhFZwykv?= =?us-ascii?Q?PFt5Vk9JQ90PRk8RTcFNB1+Fqfeu9EUEk/9xt1o1WW1fachyHAAetrl/0zUP?= =?us-ascii?Q?Evostc+Kae1Cc2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Oo/kMBrzVASDQcU29I6mELTssjQDtGjG8tHDQUI6xNAWXqgU58gg==;5:NSDbJyQsFLzyFDq/0WBEB5w0Zj2YpDhS1Alb2v4zE+Xl0ND8zNBKlwUc1zZEg7PST7qB9gQpa7cqZHE8D/9XEBiPcbnf7iuDV/Nu06iFNGgHnfHWejOGA2JyaF+jUe7+FjDaZsjp+dSZUg7QOVGcMWqkXqJXkbSVNOj7hItm+yIoD7qLFZ5QoN7GzJ8WM9IX;24:nvEkNRi7jnzsAyknoKoni0Ik1KDuPAd9t4bmP9lXO2EzbvTnVraMlTx63tIBxzmvWY8JrrDLJ8/4DQc74fIbgX4KwkRa+MDsqEpMwWz6aqU= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;BN1PR0301MB0738;7:c9OWmTKG0G5QRZ6rMoRYvSpLjbf1ik/L0eIQKqw+jDWjCyLqdLlCSK+XrB4S3NSDGBsfrInVfaaW7UgXfSiZvZ2gFjmbv9btYHzcxmErTR1tJluAol7qw+Lti+gwRFZ6bpMmiXjP4kP9mMPPdmhY2XOhS/QrQz14sevLh+Yaq91ovZzf8Jw7woojz9K3TfWaL/FJrgnWgOWeD6KOWnZoGVdmgwEMdMcf0qxsY6Biy9p5Bc/7/0LDgiJ6wCRGt4tnpLv3/zPzzRBS4Le2oOKOVCRwhelUWRtwNRR3ziKIsd3Jm9aVvD/XINWP7RlDNQKvGA6j82PCoHfgoqR/nd+gz+ik/gRdSWPTKATfghFaMvA= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Nov 2016 20:16:49.5726 (UTC) X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e;Ip=[192.88.168.50];Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN1PR0301MB0738 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 9724 Lines: 334 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 Cc: Laurentiu Tudor Cc: Ioana Radulescu --- -v2 -handle error case where number of DPIOs > NR_CPUs drivers/bus/fsl-mc/dpio/Makefile | 2 +- drivers/bus/fsl-mc/dpio/dpio-driver.c | 295 ++++++++++++++++++++++++++++++++++ 2 files changed, 296 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..76261d2 --- /dev/null +++ b/drivers/bus/fsl-mc/dpio/dpio-driver.c @@ -0,0 +1,295 @@ +/* + * 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); + + if (!cpu_possible(next_cpu)) { + dev_err(dev, "probe failed. Number of DPIOs exceeds NR_CPUS.\n"); + err = -ERANGE; + goto err_allocate_irqs; + } + desc.cpu = next_cpu; + + /* + * Set the CENA regs to be the cache inhibited area of the portal to + * avoid coherency issues if a user migrates to another core. + */ + desc.regs_cena = ioremap_wc(dpio_dev->regions[1].start, + resource_size(&dpio_dev->regions[1])); + desc.regs_cinh = ioremap(dpio_dev->regions[1].start, + resource_size(&dpio_dev->regions[1])); + + err = fsl_mc_allocate_irqs(dpio_dev); + if (err) { + dev_err(dev, "fsl_mc_allocate_irqs failed. err=%d\n", err); + goto err_allocate_irqs; + } + + err = register_dpio_irq_handlers(dpio_dev, desc.cpu); + if (err) + goto err_register_dpio_irq; + + priv->io = dpaa2_io_create(&desc); + if (!priv->io) { + dev_err(dev, "dpaa2_io_create failed\n"); + goto err_dpaa2_io_create; + } + + dev_info(dev, "probed\n"); + dev_dbg(dev, " receives_notifications = %d\n", + desc.receives_notifications); + dpio_close(dpio_dev->mc_io, 0, dpio_dev->mc_handle); + fsl_mc_portal_free(dpio_dev->mc_io); + + return 0; + +err_dpaa2_io_create: + unregister_dpio_irq_handlers(dpio_dev); +err_register_dpio_irq: + fsl_mc_free_irqs(dpio_dev); +err_allocate_irqs: + dpio_disable(dpio_dev->mc_io, 0, dpio_dev->mc_handle); +err_get_attr: + dpio_close(dpio_dev->mc_io, 0, dpio_dev->mc_handle); +err_open: + fsl_mc_portal_free(dpio_dev->mc_io); +err_mcportal: + dev_set_drvdata(dev, NULL); +err_priv_alloc: + return err; +} + +/* Tear down interrupts for a given DPIO object */ +static void dpio_teardown_irqs(struct fsl_mc_device *dpio_dev) +{ + unregister_dpio_irq_handlers(dpio_dev); + fsl_mc_free_irqs(dpio_dev); +} + +static int dpaa2_dpio_remove(struct fsl_mc_device *dpio_dev) +{ + struct device *dev; + struct dpio_priv *priv; + int err; + + dev = &dpio_dev->dev; + priv = dev_get_drvdata(dev); + + dpaa2_io_down(priv->io); + + dpio_teardown_irqs(dpio_dev); + + err = fsl_mc_portal_allocate(dpio_dev, 0, &dpio_dev->mc_io); + if (err) { + dev_err(dev, "MC portal allocation failed\n"); + 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; + } + + dpio_disable(dpio_dev->mc_io, 0, dpio_dev->mc_handle); + + dpio_close(dpio_dev->mc_io, 0, dpio_dev->mc_handle); + + fsl_mc_portal_free(dpio_dev->mc_io); + + dev_set_drvdata(dev, NULL); + + return 0; + +err_open: + fsl_mc_portal_free(dpio_dev->mc_io); +err_mcportal: + return err; +} + +static const struct fsl_mc_device_id dpaa2_dpio_match_id_table[] = { + { + .vendor = FSL_MC_VENDOR_FREESCALE, + .obj_type = "dpio", + }, + { .vendor = 0x0 } +}; + +static struct fsl_mc_driver dpaa2_dpio_driver = { + .driver = { + .name = KBUILD_MODNAME, + .owner = THIS_MODULE, + }, + .probe = dpaa2_dpio_probe, + .remove = dpaa2_dpio_remove, + .match_id_table = dpaa2_dpio_match_id_table +}; + +static int dpio_driver_init(void) +{ + return fsl_mc_driver_register(&dpaa2_dpio_driver); +} + +static void dpio_driver_exit(void) +{ + fsl_mc_driver_unregister(&dpaa2_dpio_driver); +} +module_init(dpio_driver_init); +module_exit(dpio_driver_exit); -- 1.9.0