Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754626AbdCMTD2 (ORCPT ); Mon, 13 Mar 2017 15:03:28 -0400 Received: from mail-by2nam01on0065.outbound.protection.outlook.com ([104.47.34.65]:61066 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754404AbdCMTC0 (ORCPT ); Mon, 13 Mar 2017 15:02:26 -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; From: Roy Pledge To: , , , , , CC: , , , , , , Roy Pledge , Stuart Yoder Subject: [RESEND PATCH v6 7/8] bus: fsl-mc: dpio: add the DPAA2 DPIO object driver Date: Mon, 13 Mar 2017 15:02:03 -0400 Message-ID: <20170313190204.28190-8-roy.pledge@nxp.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170313190204.28190-1-roy.pledge@nxp.com> References: <20170313190204.28190-1-roy.pledge@nxp.com> Reply-To: X-EOPAttributedMessage: 0 X-Matching-Connectors: 131339053433098465;(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)(336005)(39450400003)(39400400002)(39380400002)(39860400002)(39840400002)(39850400002)(39410400002)(2980300002)(1110001)(1109001)(339900001)(189002)(199003)(9170700003)(6666003)(5660300001)(8936002)(50226002)(81166006)(104016004)(2950100002)(8676002)(1076002)(356003)(5003940100001)(54906002)(77096006)(4326008)(36756003)(76176999)(50986999)(43066003)(85426001)(48376002)(47776003)(50466002)(105606002)(38730400002)(39060400002)(189998001)(33646002)(3450700001)(2906002)(86362001)(305945005)(53936002)(106466001)(7416002)(8656002)(2201001)(2004002)(2101003)(217873001);DIR:OUT;SFP:1101;SCL:1;SRVR:BLUPR0301MB1955;H:az84smr01.freescale.net;FPR:;SPF:Fail;MLV:ovrnspm;MX:1;A:1;PTR:InfoDomainNonexistent;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BL2FFO11OLC004;1:jhYj4XGM55pYIce3iv2+f24Ecxqrnp54BJugbz3ZNXPv7CuUBm3dSbvAwNRzek+sxoKnM80J0iPMLzuTYFRU4jjeokRx79rNYvrovb4ya4Uqjn/FbntVA9tHZwlP6hMZdIq3no2vxIr9Cxn0dBA3/F1SQXAL7NuvYELBnmvqFEiKo4kAEzGsTk33qYd8BpzARI73YaurSD77ZTcCSGgInL91j8orqZSpKSjYVJ3eNXi3qeiVNvqqJ+YtL3RkwrsRcSpzX9bSuvz7jyvLWn33qe5JWpsq7dQXvjQNXbwNNCvKP6bV29B1LAXoODxJZmGMqpMLxIT6mqtGfUSPuUeIyp5Ay/TS1y2TCeUqxunUFTrRFzf6gH5ArUdc/Z1PjVxyku2gDyEXrvkcIAlWqgMY1h6UbhOofH+HpQP/VDVhhzjGTzPUx0wUDrsuAngJQ0yMfYSKgXf11pdLq5woA2fJZGan/mReRaP5bYpYws4CmJ9+A39E/2lSRFqdVRtxNKRWeSx3FGKBDf7NGGyTFshozQaMRHim5kgeI4cI1vl5Edml7JTfMqJjMKhZQM9aufxIYZ3gau0gqb0xgTL8fVEaHfQQyYThGvNWQB6yu9gduuHSQE9vAQ07Ekg4xvBhcvaRg0L1XMyWz/PM/uiGd/eo9jF0GXBG7UTkQ7XUg/RPu4WBTCjPK9RUN2BwuAWRftXCJfHu0VoR7FnDocwXX7c12Q== MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: f0167f2c-d617-436c-a49c-08d46a437b65 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:BLUPR0301MB1955; X-Microsoft-Exchange-Diagnostics: 1;BLUPR0301MB1955;3:Km3OSaKC1/71dOxaJdiLeR6UTHlTyoLGXl7YPu3isFEg0x2SZBZS9GULFX9rXt9o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Ub8EgFt7zshB7rIBJuGmtujFP8aDJARtU3yz2ZNpD04EXQUl+QMHLLKzVyHdmQqEU= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197)(275809806118684); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6095060)(601004)(2401047)(13015025)(13017025)(5005006)(8121501046)(13024025)(13023025)(13018025)(3002001)(10201501046)(6055026)(6096035)(20161123565025)(20161123563025)(20161123559025)(20161123561025)(20161123556025);SRVR:BLUPR0301MB1955;BCL:0;PCL:0;RULEID:(400006);SRVR:BLUPR0301MB1955; X-Microsoft-Exchange-Diagnostics: 1;BLUPR0301MB1955;4:pw+Q9+qtVvMvZVDcjo0GMPlSQ6fzkIrZSXagGyPeUKF5V84MZWp3ZBwXjqGVMY1bzeWYpW4Kyhazkbne7jzX/ooF0xASfxeLsmfolJl9FbSlsqdHhpYA3XB8cUK7iyruxg+mEXPRhCAB94ggj5MEPIU7qprrWux2Z7RKTq+MmgKXeKcWYhKj3wE9fomFNUU7FoVIiYfbgPmXW/lbnfUqWRHzndh03ys5j+kHNrDTaRXsPHBTPk8mSCAUdcxPRt++FN3N6T82u2fcwoKj/8HjZ/32+RrsgKXxTWB7mOtrowZ7XbeoDyWdySpL5Xg31+tlLBP3FD3GaRZHsZnfHL7ZoOVs/UmaQVf2dQKjURXCIbeIlYPckI+NIflr+9vyB2Rmj8mT1TQMiN049JQQG9uqXKPxnTTWVmB3oU7Lec4xGlfzlaDMcouMqe45J6KT2QrFx/6s6Mo9mkxFiGmSO9PEKggMU2nmq1V7XNPss+vOuClXcYtpuGXCMswr1lhiZJ6HGj6DFOu3Kt51/KxlBY/wG/rFVtA2ufJwRCj5RbBwTG3TJ8NhGNE0fno8gKRGi6pb3O53DY7KnKwKFD6BDbfsgsJGYhIgJsjskWGY6OGKVgvkWrk3+EZcgEcQKVMypVHeF5RY3Rub8FFyjlJSwnzNQe2oVSzog50VMsa2QUz+czEHdL6CoVUctB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JuybRiqEtjknKp9EW8d/R6goeoAqe+pZmvnXJ2HxmIwAabuynoG6rrJKzPnfYPhwA7zXoHzKumm8f1VHp+NnxEu40NCSGVV+O3DFxS5I+lfI9Z2wxUcp4PMSdPAQp/tbV9JoTVdtAR8=;5:b9N1HZ5gkKLTHUqozDUcME2nv1VYWUb0O9qXo1mTIbUOeNUTZW3gij7WgJYIUqc3IZrsT/FSdT0ZA8R2gDrgg36bGpCQWP06iMclC7E79eammvu63QcmTRQ3hUUC4+hmvAVDmoDD0EAbnzNEBKg7d80pIRCvqok2J/deSV3531it3ubd3YzgzsW4iZJ+r9lD;24:ZW7NFhkiKCVtyJ1fq1oJ9kh4Wz2lht4gjpu3rVsjiBpgTd6dNUmVe+JA2K9dAbr5uzdX6dJCANLW62DehrHYgCMdS7vV2yRXZVM60iZyA0I= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;BLUPR0301MB1955;7:80puPEAw2pb1DilQ9c7B8tpo3pWb7zehuIOuuBohPMlQPszmVXk6Ybqc6DhWVAU08hwhEF8otvqN4+gt5ALXHh/8phuJcyALwhQjrqMAcif8pK7qpciFjqAKvtBuDB5NF3Og5tX4/nXDUYVRH+tseY3CzKT49vKBvUD5zZ966ApPGbAkvr2I4P5b27E5wbkGv4dEJDx0CExE7C3wCnGOFTLznzNTj1k4M/PO00Ge46OvuxPA5/o4fwK6rLX4CJpJAWd8MF4u20JF+9OVt4jO9GamI3vrYuLPOcWfpwL0rfJKf7izlla1RqhFYs1+plfQQPAD4DislvkpUI+XChJP2g== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Mar 2017 19:02:22.9354 (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: BLUPR0301MB1955 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 9880 Lines: 339 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 --- Notes: -v4 -updated copyright -adjust file location to be in drivers/staging -whitespace alignment cleanup -v3 -no changes -v2 -handle error case where number of DPIOs > NR_CPUs drivers/staging/fsl-mc/bus/dpio/Makefile | 2 +- drivers/staging/fsl-mc/bus/dpio/dpio-driver.c | 296 ++++++++++++++++++++++++++ 2 files changed, 297 insertions(+), 1 deletion(-) create mode 100644 drivers/staging/fsl-mc/bus/dpio/dpio-driver.c diff --git a/drivers/staging/fsl-mc/bus/dpio/Makefile b/drivers/staging/fsl-mc/bus/dpio/Makefile index 0778da7..837d330 100644 --- a/drivers/staging/fsl-mc/bus/dpio/Makefile +++ b/drivers/staging/fsl-mc/bus/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/staging/fsl-mc/bus/dpio/dpio-driver.c b/drivers/staging/fsl-mc/bus/dpio/dpio-driver.c new file mode 100644 index 0000000..e36da20 --- /dev/null +++ b/drivers/staging/fsl-mc/bus/dpio/dpio-driver.c @@ -0,0 +1,296 @@ +/* + * Copyright 2014-2016 Freescale Semiconductor Inc. + * Copyright NXP 2016 + * + * 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/mc.h" +#include "../../include/dpaa2-io.h" + +#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); -- 2.9.3