Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S938627AbcLPAUT (ORCPT ); Thu, 15 Dec 2016 19:20:19 -0500 Received: from mail-dm3nam03on0078.outbound.protection.outlook.com ([104.47.41.78]:21223 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S938449AbcLPAT5 (ORCPT ); Thu, 15 Dec 2016 19:19:57 -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:978;Count:10 From: Stuart Yoder To: CC: , , , , , , , , , , Haiying Wang , Stuart Yoder Subject: [PATCH v4 7/8] bus: fsl-mc: dpio: add the DPAA2 DPIO object driver Date: Thu, 15 Dec 2016 17:56:25 -0600 Message-ID: <1481846186-7783-8-git-send-email-stuart.yoder@nxp.com> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1481846186-7783-1-git-send-email-stuart.yoder@nxp.com> References: <1481846186-7783-1-git-send-email-stuart.yoder@nxp.com> X-IncomingHeaderCount: 10 X-EOPAttributedMessage: 0 X-Matching-Connectors: 131263202548304240;(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)(336005)(7916002)(39450400003)(39410400002)(39860400002)(39380400002)(39400400002)(39850400002)(39840400002)(2980300002)(1110001)(1109001)(339900001)(189002)(199003)(50226002)(4326007)(2906002)(106466001)(76176999)(50466002)(86362001)(36756003)(105606002)(5003940100001)(7416002)(92566002)(50986999)(626004)(48376002)(305945005)(85426001)(97736004)(38730400001)(2950100002)(104016004)(6666003)(77096006)(68736007)(2351001)(47776003)(356003)(6916009)(5660300001)(8666005)(33646002)(189998001)(81156014)(8676002)(8936002)(81166006)(110136003)(7059030)(2004002);DIR:OUT;SFP:1101;SCL:1;SRVR:DM5PR03MB2476;H:tx30smr01.am.freescale.net;FPR:;SPF:Fail;PTR:InfoDomainNonexistent;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BY2FFO11OLC002;1:96z6/I2NzV2PJWsLC1f6/HJttTVVgvXTwEKy9Omb43Cl5feTH4FAsDldevgFV1f3Wco6T4peExWBc+Tb2C7hlubTmpWqJVFNl8vspxCoCQvXIf+RC0jylTOIO2VD7w3p6j7sj1iYEa5GjpkSRJvw7LJzsRJMSzR+xO8QtTF1dUZP8R7UI+qSOjxhTNTprblmMb2Wbq+RwIWf+Bl7wdtmp8Uztu3ZrT+Roqfm2qicpJAHK9oiis2GjJZbicDzaP8607nGt3WS4anyTXwnVYWw+AYe1c+q6prFvLvqliBG7eZPT78uFz+g4dI4azrKL3cTaBRxrZu+RsARfe1p5BRfVwL2tNEwW4TR9QLe0z5RisyND9lZMigHvXSabj0eLeLXMnluUp/pp5MCi+6ipSoVLK407LY48aaZ7JmnxQ3f/+yv29irmfq0RZ5FJNxl2ymkiXRth1LvuD3IvWb9AHQ0Iq63ZpBkodH9h2BU6dNKC9VM22wDEQ+UT1bjstdzoxgC8aseFDqyyDm4s8sck04Qc1Q5Wj98V3QnfbWZxRCoB7qrnlm/mAED7Q5wNcrG4AW/Y44AyOxLsYMtkDjySaBPuztQ9WP23JMXrt0wQu2EzLpNDFvVMGnDxIQJfnZ3sE0hztyTDI/EoFyydEyMKuStSEvheGctdBNEaW9L0dFwFcbD1byvglda3oujT0z/QrCukrp+wPQW37Z0zE3Rsp/Yzxbm5BXfIsgBma6++sq/OCQ= MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 0c4ec73a-29a5-4c6f-c970-08d42547126f X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:DM5PR03MB2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t2a6pun++nzxczD1EdKuKUJ6CrgqkBP8JaL8OzjHLFLWx5sA0mohTcBEnkWY1pID+V+l6FyX2GCm0fhFk9LdrMJD0qJLO1LbNaHturLmr5LZiBVLurJhrl7XmEhqXyBTvNGXYHtBrzCLMKVb/Wsvi6hN9Rl9+55CADa+5/K/cUA/ktHzZ8dfPq1udKOkyuT3vs5V2fsSg= X-Microsoft-Exchange-Diagnostics: 1;DM5PR03MB2476;31:UJhL9sx5wONFNzBoS0djUPS3zxFjSpkAvuKYw4SgWAcrdV3cXGngYA7PmnFOuv1R1YCsTLjOdbh9KVxapYAWOMAUmc2F+6A+lOfiSIvUu3s4aGKXVaPKXm9qIm7hjdvTTvf6sl9KUAxZ8eGZh0XaHJSZDyXR72Gx6LSM7gMRx9J7rI2qj0M0GodZbR3WsqCWH4RACv8MHBdG4xaD3+mPTFfUF/6PpwjnKVxg9xXtspjHPRbVyxJnk7wF26CwWlQMkQYDlixI1HjjWjZrRCkpP/bKis+KqSBQIs0C5gMyp/4= 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)(8121501046)(5005006)(13017025)(13018025)(13015025)(13024025)(13023025)(10201501046)(3002001)(6055026)(6096035)(20161123559025)(20161123556025)(20161123561025)(20161123563025)(20161123565025);SRVR:DM5PR03MB2476;BCL:0;PCL:0;RULEID:(400006);SRVR:DM5PR03MB2476; X-Microsoft-Exchange-Diagnostics: 1;DM5PR03MB2476;4:TcJIJtFpGSKdZhlSVYTUShf54TosUA7ro+zdpCluWRJtJq5ESpCCUP0DIUc8WJ4CeCEQiWH3lKKVPaMih3Tubq82dtSvbW/0imcNGtn8NPLJ9aAJZBmsH954REBZsBia/kG1xSe8ahaZJ1S5vhtfTYFQnKlcDeipeeiVC+Sgpd5uB3d5lXOTA16Z5+3etHwAaHyJSeIVdN7JE/JdLl2dWziHx28isVc5m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=?us-ascii?Q?IX4eI1hvfOyL0eoNedrgbyK553ki9RLT+1awPAZewilwNhQZXwVDtDf/zuSF?= =?us-ascii?Q?WinqP3OE4cHsaQvsAThvhc=3D?= X-Microsoft-Exchange-Diagnostics: 1;DM5PR03MB2476;6:fy9TdaO8jiPgrCbnRZoc3XFH211DhQgt+8HoBjUdiAr8cQGA7MQ/PMRPmc1Nl8xCs7I+SzeUjDXwNhsqiZHJnQIAMloeEIV/Xm5JMEKiYUomaE3hQWrLw/yVBs8Ecq9ahpPp0/fv0aSYO+0nMUFvrcfxUT1esZoif0EWzux9wVwkVpRgZnbUKzRKUEHnUc0RbUTQz8i+ocTZ7uhZ2K3rxKve0mMZICGmDpz+xUzm9pWHJ4qRP4NfdsccJhzn9jqlJps8fF/ZonpvQUGvsNqEnDqtFz7ZsvkiXNn3MycfM8QHBD4jynW1RBnyzrc1Y67J1iwhGH/txox01MZEmdPVK57gYOy2Of0z0POnnoYsi7XjZC46dKM2tp+RrF3S1Hb/n4YeD4OBuyXTJxuncrHrlo4svt0PQJD63SPvhusJUxyGylsYbI0ac+rwH+0ipdCn;5:Uzi0xwnDmAFBYGMWhE02TuEy766y8+5Do5dkVrJTJtnwpIQPbeUYIrA8PvNeGvy+G9sV+zGX4BOZXgAzgRrDbUywfe2MkC5x1BLILUPxUNQkIBhJQZXjvOx7Za0xbeALTp3tA2TMbLFL4httXHFfHgQvNHC/xbvPVp3wrBJm6vfbOy7jvc6lP2fLJapNl8/7;24:hipvj6YT0PXIQc7UnjUK9gqftpFWmb5TkRr6VsVlwRh3V+oVcCQu/jxV39Wk5QjDTXUECDdoakKd9nHodGqifF0YAuLIediLFrFZbPhi4cg= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;DM5PR03MB2476;7:eCRDenJ0Y5lXTx7/Zq0lTBL1qfhQvZFKLZY6XirsElA9P5RcX5kLIL9aGKagsydwx3aGmIE2NolvmuUtvA2QIvLTZBikoFJM1msCfFZ8ccZ9RfvAfw+QXXfV+zY71xHm/YhQOcI6QqfEvdqYPVUarj/T2qEsLqOcfGeQsNJ2vQEa8FIUdWizpwp1Y6lej3jobgyAAz/BI1oJf5qEJl5D1XhMo/Cor28aTSpMx7NVYSNCtWNVgj9UxVOHRvgarQp2L5X8LIgFFbKGW8heBPZWQvwatePW1xsRR+RZ+EOtKnL9dKbO4jauOEuhYRUhDOP4oFzEgYduuhBkGXk2zG0BYeQKEJwKSZf7MDlMv0kB8Kvkq19l9/Ou/3rc4b6WdszzNanJE3FA7DMGrq4uZqyRcHKRD4iRW4eGw3NlpYHPqbF5vcbYgRGJPeafeRvwcWLTyp9Y2V2DHqeMz3Q48hp2/Q== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Dec 2016 00:04:14.6432 (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: DM5PR03MB2476 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 9887 Lines: 341 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 --- 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); -- 1.9.0