Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934220AbcJUOYS (ORCPT ); Fri, 21 Oct 2016 10:24:18 -0400 Received: from mail-by2nam03on0050.outbound.protection.outlook.com ([104.47.42.50]:26062 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932934AbcJUOYQ (ORCPT ); Fri, 21 Oct 2016 10:24:16 -0400 Authentication-Results: spf=fail (sender IP is 192.88.158.2) 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; From: Stuart Yoder To: CC: , , , , , , Roy Pledge , Haiying Wang , Stuart Yoder Subject: [PATCH 8/9] bus: fsl-mc: dpio: add the DPAA2 DPIO object driver Date: Fri, 21 Oct 2016 09:01:48 -0500 Message-ID: <1477058509-12547-9-git-send-email-stuart.yoder@nxp.com> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1477058509-12547-1-git-send-email-stuart.yoder@nxp.com> References: <1477058509-12547-1-git-send-email-stuart.yoder@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131215324968465541;(91ab9b29-cfa4-454e-5278-08d120cd25b8);() X-Forefront-Antispam-Report: CIP:192.88.158.2;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(7916002)(2980300002)(1109001)(1110001)(339900001)(189002)(199003)(92566002)(48376002)(106466001)(229853001)(2351001)(33646002)(105606002)(8936002)(2906002)(87936001)(8676002)(305945005)(19580405001)(8666005)(19580395003)(50466002)(77096005)(7846002)(356003)(81166006)(586003)(81156014)(36756003)(47776003)(110136003)(50226002)(86362001)(626004)(68736007)(7416002)(4326007)(85426001)(50986999)(69596002)(5003940100001)(2950100002)(6916009)(104016004)(97736004)(189998001)(6666003)(76176999)(5660300001)(7059030)(2004002);DIR:OUT;SFP:1101;SCL:1;SRVR:BLUPR0301MB1618;H:az84smr01.freescale.net;FPR:;SPF:Fail;PTR:InfoDomainNonexistent;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BN1AFFO11FD053;1:hw/e8CKKA9Kn0WhL6fRTGxT+u1r+RLQtZuzwlanJ3ibX5yE3CormBOtRIyzdIsuQp7z6BwcvwloxffxSLz3sNv6YKc5OcH8SD8PdlSpeO6sL/d+2QddwgY93MQthzcYDBIDkIatxhRlKQmTTSgkeXmxzG1JlDA/RmfTEtQaPWGzVpUU3cPwEEDvK5CGqJwDJa3yELFOot92EFs5xhmXrHQTO9sZeOqYHPZa/+4sAUXYbb/zvEYZsSUMJ+u/I5MDARvhUESQ6E9+91czTOZ5yw1o2VaiHOlGFq3WfgDc0lnmKOVPzQkN/KTjmkGrBuft6ZO7xMg8yL5lqaJv2PXQXLwJLJtZDom0tqrrAE4L5+ybl0432YX5JYG4T1y6f16IPSle/DjIE7eGqWArJZ3rVB0BTiMDZ9oARxCHq2jkF0xTd68a84m0h9Safd6YjI5f8urccEqCc4h5OdYRS1enRt4DG6Y3qUlIiry+50OwgbfW4k0RB8dnWoIdMxS5DRfuXDu9XHjSOWB21QgRVlK9DdJBkfS4phVgBWZOtRCJnRrVb0bI1xjit5zifK10VRHI6ebL7qBLDQxxbE/MH9g7yx9CnpT6zHup/cdqDMdEM3lgFjDKNFNGXInJDUTOfVrxuuo/rmOdbxVTkxDmB7GxnYqaieEy4zqCvCsMzVtEoBkkognq0IQUvk45BoFz9KNsY7fxSEnAbleNVNM7sIwtKjL+g/I69jAd7dNnSv5gZroI= MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 6d1e7469-9765-4321-d328-08d3f9bbb449 X-Microsoft-Exchange-Diagnostics: 1;BLUPR0301MB1618;2:yW6/c6jct6EcMcYFMw8V6e4h2KjcbqjplT0lNpfwL7GkZlIMb5YXgxp4WJ3vPKP2HuxJikKROLt+nu/UIf6ddgaKQt867jmjogS9QblpaIpk0af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jtchDEH2e+APtzdsVN+s90DtdqjuytnPB8gOc+qDSzuvoExczo9trojTzdYP8Mn/OZAwJ8cNcwujFqAMzq5oTSieKePr0pMoe8nwFqCr1m/qMbnwsN3bfyAUr3jA==;4:CZj7S3Q0lxZTqTPNXYCBURXqoIRs3QcIzQCibCM4hOTwmcB7d4EeWbK9sXfuk8LmT4asIMg8mjjocIzV920PWjH6va1wiH7QIeWfWBe+h81PU67GxyEeP8F96QQVJTMZSq/eUf9RgGVSP0yaJSK94OCWI+yOkHH0r5HGDY+oPPYdkyZK3Icof/yAEZ0tWL/YIrM3mfN8G8HIcyb57a6rBxJ5tlM4HAccxFPmZYi2YnV26uzCq9e6h7qLt1bptFIdlkbLIPuctS4lKgDDVRE2EXdqhNhUkh86VZZzCWEpAiVn6v7Irwt5weFwPvaqAiIvQFPQFcZC6sYhwO22tOd62FUCn9APpnGilxCCm12yvZOwVxFxHf10lx+9GZMVGPNMU+3pQyt+Xjp9To1Wjb2BRrkjeYShDVGTocxUR2pu0JqdsSURN7B31PExIzzO8bpECd6tx6u/y0zdi17AnN/XuxJohD1ibym58TfuHUWXdysc3JyOJhn2Jg9DYpNyghuwP16dYfkNPhNtKB4Qhc6OKfRGBCQvYUVpMkTa+oqeQpLTFzUuffivwyuSHIULQqUKVfYFgCoWq9uxnTRiXAZ8jQ== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197)(275809806118684); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040176)(601004)(2401047)(13024025)(5005006)(8121501046)(13017025)(13023025)(13015025)(13018025)(10201501046)(3002001)(6055026);SRVR:BLUPR0301MB1618;BCL:0;PCL:0;RULEID:(400006);SRVR:BLUPR0301MB1618; X-Forefront-PRVS: 01026E1310 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BLUPR0301MB1618;23:wRpypxX0hgbUVUZvLOEr9kTiu2kX96ST2Cl/7TJ?= =?us-ascii?Q?87yfd2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TgV?= =?us-ascii?Q?1Id4LHfjXT1ZIcRMblHeEZX2WgB5kJ0/CDgPXiy7MU/RoqXytBenAR9LLC9I?= =?us-ascii?Q?QZJOrLz5DVVeqmRzcZzXkjAG26/4vJN+mWzhhBkunh2rvDDG4sXSf2yu8qus?= =?us-ascii?Q?4xeKCLGIG4MxcHa8EuuoFT9Kp29uBCiXwGpO3MwVljoWk4evZMCumvKMzG7p?= =?us-ascii?Q?QU1d8i3kpEs/4zinO2FlLcqk6Zwe64qbxdCcdagetiqg8EqRtZhOxonc8yI4?= =?us-ascii?Q?qZeKmCNcLQNf2EmBC2EXFzMICSIb6qht/eex+NTccRmLgGD+lcSXDXjB8TFA?= =?us-ascii?Q?vmYAxQSShPkApTQ+nE7M=3D?= X-Microsoft-Exchange-Diagnostics: 1;BLUPR0301MB1618;6:FMBaFR/F0DBAsJRswhtv81LYqhLkL+clNhM0DAkbBwP7pEtlAf9/5LFiDApMIPPjOuK9iMWtkdJufYGlT4Fz6If/mOHpvDXCaVV1gcsRlZtLgIcnwGEntZd2rVivfNkDvmbj5S1479uw2BZq1owsbgnxCl3bjb8dVhzR0H9/PAwAZOpKjvL74zsmu/VmeYS+jidxBoyY2gALnYyhaBroi76SB+DMxpM2RH+1o3i+g1MJZQFXoxD0CrjFiBA324SnGWL8czZm6RmlJFs294WyIYaxmDYkHSkV3chFX0KdFV9Th7+Mh8TJquWOnMzD8uhz;5:U/mBeo8d/Qk1KyWzAsHgHbAUGpWJpiWbcSjO09iXI0MOXHaZ90jI4ArO2la+jKnlTurdjaNaLXkaz/JYxz17nZCqAp7sMETMrPm8uc/Qg73de/pNhssUR8e6ZfRayZOPOasTiMbmgUiCaEwp0A1mS29melX8iynC3tgbNyQO2+no57Ltgy7SpC0QHrx+k/g3;24:VzozU4yewBPM4VwTOdTkWk9APhNhRpDAycdYjuNtoug4s44B80Grw22qMDAjHM17LmdA/ZniOG+OW14kZF9mSf9zR8nhJ6I7q72cqGEVmZA= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;BLUPR0301MB1618;7:7S/U7SEgK1htHrl4dFRkict8pIXspgOUhiXiBWLa9SgWBsAe9OVd+zrqfjqDTbFFWTG4k9zQLwuVUpat4JzaEiBin5Hp8hjAV2xRtpCyaC0eQ4unga34PT/OjwPmyxoS4DEENCX81oNz4YjJOVer/QcRdTvB7fu9JLCBMv9psmuwGEy0cWwbjRAy+3HIKwKmbffVTECYSaYYutc45NJFpd6KwikSdGPISaf7AIDRdSSFIzZluy2lB8KUx+yg6yUBXe51XFqERK8K3GtrgfQVoWVs8Wql7u/f41zqRbBRoaNVSNLwd/NuQxfd8WEfX2fdgK04bCh+4goIXSFCzX2pYpjgIlgBclE0txzv3s52AYs= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Oct 2016 14:08:16.5969 (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.158.2];Helo=[az84smr01.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR0301MB1618 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 9417 Lines: 323 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; + + /* + * 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