Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932780AbbKXWt0 (ORCPT ); Tue, 24 Nov 2015 17:49:26 -0500 Received: from mail-bl2on0116.outbound.protection.outlook.com ([65.55.169.116]:60000 "EHLO na01-bl2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932463AbbKXWsI (ORCPT ); Tue, 24 Nov 2015 17:48:08 -0500 Authentication-Results: spf=permerror (sender IP is 192.88.168.50) smtp.mailfrom=freescale.com; freescale.mail.onmicrosoft.com; dkim=none (message not signed) header.d=none;freescale.mail.onmicrosoft.com; dmarc=none action=none header.from=freescale.com; From: "J. German Rivera" To: , , , CC: , , , , , , , , , , , , , , "J. German Rivera" Subject: [PATCH RESEND v3 10/11] staging: fsl-mc: Added DPRC interrupt handler Date: Tue, 24 Nov 2015 16:31:23 -0600 Message-ID: <1448404284-22258-11-git-send-email-German.Rivera@freescale.com> X-Mailer: git-send-email 2.3.3 In-Reply-To: <1448404284-22258-1-git-send-email-German.Rivera@freescale.com> References: <1448404284-22258-1-git-send-email-German.Rivera@freescale.com> X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1;BL2FFO11FD007;1:20kHfIt0Lraj0jL9t8+f8epT/7G+jhMGyVFVbW7394RvxYF0sqU1tDLV+8cWquSQgqHZb2WYhF8kVmwlPUg6XOdCcvs4s4WIEoTB9K9lJx08gGZjQ2mg+dIQ+ObZNXKPZ7iN7drpa1doAsOP9GJ6QvLTLY/PSLcAqha5LGbFcQAUzC2TTO8lEBinUWkezepPfomTq6KyG7yHsqCw1529ZPN6F6lFkbNJc/CWG1nw343ay9qQ+ssG1gJK0R8ghzKWxaYcn0V2L/ddGlXT9LP2TBFv0iKgMJo7exXnUadNn8VqFz9GsAPkS1a4gk4lx2XAw7yvu84fRpGv8byW/3DSal0KNcoS1en9FccmUGAmv8Rp5xuRirUKuFaXOPu8ijaJBNXxhnREbIRPMgcnYOE6lKADpVpcUKrafILy1RbtCq9pvanatxUCMTVYSHlNKe8xyMHyVoyIJCmmR7FUlYf8UQ== X-Forefront-Antispam-Report: CIP:192.88.168.50;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10019020)(6009001)(2980300002)(448002)(3190300001)(189002)(199003)(86362001)(575784001)(2201001)(107886002)(586003)(229853001)(106466001)(5001960100002)(5003940100001)(97736004)(5001920100001)(5001770100001)(87936001)(189998001)(76176999)(48376002)(50226001)(92566002)(50986999)(81156007)(85326001)(47776003)(5007970100001)(50466002)(104016004)(11100500001)(19580405001)(6806005)(36756003)(2950100001)(19580395003)(4001430100002)(5008740100001)(77096005)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:BLUPR0301MB1633;H:tx30smr01.am.freescale.net;FPR:;SPF:PermError;PTR:InfoDomainNonexistent;MX:1;A:1;LANG:en; MIME-Version: 1.0 Content-Type: text/plain X-Microsoft-Exchange-Diagnostics: 1;BLUPR0301MB1633;2:AuBGpgB4qMYzkpm/HStUYP92cWcTK0knOiE96dMz+121MqyATI3TCbTMHYCS02MFtEWmMdMRpv0zD0vyl1rgsSRuBgQhO+b4KIclv3vkqhGBgspvsQXKRmsMkqDe8UClIqN7vmGBGYv9nLRfaecSXA==;3:aAF5xgnOTsXlhR64PnoIHAB+QqvQ54LTLrv+E289uTZGgL6iFrMo1xcvqrny0AdAHgUT85hb+lXP/Y3HNIxfyVTBHVbzbMf8wRemvqkxe1xUqgMGp7nDSNXojqb13Z/FZiY8RGxRgV8UujDdkHTfxwuBKvRdFuvBwAEpdMINheYfAy5Vz+NlyIbr+I6mo5A3tQUGFiCu+0/zaMn0guC3OneMz2a3Z7CyMox9KAkK+nc=;25:OlIhkPZIoBSXYzD4FADWSyw/3RT3AjmbMu/5tXjLpLQdvRf1YLp4Rr6GqwoL0kg0/ktnyT0u1g2xQwhGbHJGD66FaVFH9Yx6IuVYBp04vA1ZSn6MEzyVnQf5+lDwNFgDpKgvEQFxB6Od0XY+i148eT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report-Test: UriScan:(101931422205132); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(2401047)(520078)(5005006)(8121501046)(3002001)(10201501046);SRVR:BLUPR0301MB1633;BCL:0;PCL:0;RULEID:;SRVR:BLUPR0301MB1633; X-Forefront-PRVS: 0770F75EA9 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BLUPR0301MB1633;23:8ZUk9D+lcogUL/j3UuBCuAg1ZBRPg1SbRMthoia?= =?us-ascii?Q?fNB1Xg4VI3hmLb7JImLiB/jaF68LKbwCklgfb3Ja3cng2ZAuvTQ+T8NG2JSO?= =?us-ascii?Q?etilCyaLlTjHm/ugYS+juDtMME6jQbmPKAmkeugERQ1DqYUJ5CITJ4nvaX/s?= =?us-ascii?Q?OhHJ0b/2yx1WEjkDOYEkMztCx5C1NvJTO0S4+7DJc8w/6ToxWet2ILG3azl9?= =?us-ascii?Q?45AvALmel54P5QcPSZfMb+VlmkxNP+ZNql9OoPYlbrfR2Y+kTwQAKNQ8rSRg?= =?us-ascii?Q?YHEPfnGwdoU+LmQmC+IKtvpCu66GCV26VOr83rZ5GAGHBKzphjNHdQMDB1Un?= =?us-ascii?Q?64cFuJth70qoF8WSGIBpQglgCMt3YnoQI+GuE8rzkmfKUeutlpc15RD/QHAD?= =?us-ascii?Q?RspHOADUDUlGGJHkU2BZM3j/bLagcY9Gy4QZmY+auZYlF6M9KHmNgR8g6r+O?= =?us-ascii?Q?QE1VQe73cRYQLhs5MLmhQAIEVGHFH13/qy/2V4TdHwiAwELzq3XtNOfnSf4Q?= =?us-ascii?Q?UFy+WOSWfFwR4ewgbQwvtqq7V2mNy/uCUZAdl9er7NM3UWUwgNpT4sAHrQhx?= =?us-ascii?Q?BaybL8Rj9UYworm/fQRaEcxg6KLGjQyc8DqwYs2hPCPacIxqOIGc9dLKxX0P?= =?us-ascii?Q?xXQ6gHZsd4V4sRdnm0f0LaSXQVxgPZvdwyfZzz5RhHYJLes44xh4RuEZStzm?= =?us-ascii?Q?forSdjz/jBrcdqdeEjZWg2ls4MSA+4AnVFQ2En4NKe2wa674CX7yVfikLp08?= =?us-ascii?Q?pQInPxG4igRZQe2DKOOQuh+ptK/gdGQgdlIGW/LtOv5euVyUdU3YU7+LVUE8?= =?us-ascii?Q?4ZvPEPKBY67OpMK/3gmz7LoxBzQ5a/0S62ODFbtR88Nsn6svW2PmDKsbXjB6?= =?us-ascii?Q?X0fHERKEyC7TsmnNniZiajJmQ5DKNdz/2c8riY2cvXMuUOyjD0zi6VX5OtUw?= =?us-ascii?Q?MEuVH69jywPB9tjUnLnp6eLYC2Rml7pmSAfWeRun0gjNte1lPiGrBg98APVq?= =?us-ascii?Q?QO6n+Qo2BnSTRhLPtU+/EXdMu6DeBflWxgVEhGeKbrPdBvF8gDgZrYZF14Q/?= =?us-ascii?Q?Qts8AMUFrniu8w8EiacCjsRXRA/jYcE6MhlY1f2IT6LDYrpWPMnKvMxpGfTv?= =?us-ascii?Q?cjx2F2gUOQXw=3D?= X-Microsoft-Exchange-Diagnostics: 1;BLUPR0301MB1633;5:/ZHvrccerLUiZk8nRsrNIKpUtC9nq6zQiYOIFMnEgZsUeOCRzBJ/bAH2mTeHKQzQThyWLgEHAxo0o0L+mo1Yb7Jf8WYsg92jJ5jN6KTtC1PhxFdqjkn7QyNQIuzVzkEneMtSmsWIOvGxkyxBx0BqIg==;24:PVGgBvfv3/CD/Po6tkqtFmQEx0vshm7tdifqdZAPXjFmBlkQEfPqJpV4uoRmVG+h9x6LNHRsP7EfwB17Clop8NCOF3mqTrxdA8SRKVa0zmw= X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Nov 2015 22:48:03.6708 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d;Ip=[192.88.168.50];Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR0301MB1633 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 7842 Lines: 311 The interrupt handler for DPRC IRQs is added. DPRC IRQs are generated for hot plug events related to DPAA2 objects in a given DPRC. These events include, creating/destroying DPAA2 objects in the DPRC, changing the "plugged" state of DPAA2 objects and moving objects between DPRCs. Signed-off-by: J. German Rivera --- CHANGE HISTORY Changes in v3: none Changes in v2: none drivers/staging/fsl-mc/bus/dprc-driver.c | 247 +++++++++++++++++++++++++++++++ 1 file changed, 247 insertions(+) diff --git a/drivers/staging/fsl-mc/bus/dprc-driver.c b/drivers/staging/fsl-mc/bus/dprc-driver.c index cfbd779..a9fd1e4 100644 --- a/drivers/staging/fsl-mc/bus/dprc-driver.c +++ b/drivers/staging/fsl-mc/bus/dprc-driver.c @@ -14,6 +14,7 @@ #include #include #include +#include #include "dprc-cmd.h" struct dprc_child_objs { @@ -386,6 +387,230 @@ error: EXPORT_SYMBOL_GPL(dprc_scan_container); /** + * dprc_irq0_handler - Regular ISR for DPRC interrupt 0 + * + * @irq: IRQ number of the interrupt being handled + * @arg: Pointer to device structure + */ +static irqreturn_t dprc_irq0_handler(int irq_num, void *arg) +{ + return IRQ_WAKE_THREAD; +} + +/** + * dprc_irq0_handler_thread - Handler thread function for DPRC interrupt 0 + * + * @irq: IRQ number of the interrupt being handled + * @arg: Pointer to device structure + */ +static irqreturn_t dprc_irq0_handler_thread(int irq_num, void *arg) +{ + int error; + u32 status; + struct device *dev = (struct device *)arg; + struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev); + struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_dev); + struct fsl_mc_io *mc_io = mc_dev->mc_io; + struct msi_desc *msi_desc = mc_dev->irqs[0]->msi_desc; + + dev_dbg(dev, "DPRC IRQ %d triggered on CPU %u\n", + irq_num, smp_processor_id()); + + if (WARN_ON(!(mc_dev->flags & FSL_MC_IS_DPRC))) + return IRQ_HANDLED; + + mutex_lock(&mc_bus->scan_mutex); + if (WARN_ON(!msi_desc || msi_desc->irq != (u32)irq_num)) + goto out; + + error = dprc_get_irq_status(mc_io, 0, mc_dev->mc_handle, 0, + &status); + if (error < 0) { + dev_err(dev, + "dprc_get_irq_status() failed: %d\n", error); + goto out; + } + + error = dprc_clear_irq_status(mc_io, 0, mc_dev->mc_handle, 0, + status); + if (error < 0) { + dev_err(dev, + "dprc_clear_irq_status() failed: %d\n", error); + goto out; + } + + if (status & (DPRC_IRQ_EVENT_OBJ_ADDED | + DPRC_IRQ_EVENT_OBJ_REMOVED | + DPRC_IRQ_EVENT_CONTAINER_DESTROYED | + DPRC_IRQ_EVENT_OBJ_DESTROYED | + DPRC_IRQ_EVENT_OBJ_CREATED)) { + unsigned int irq_count; + + error = dprc_scan_objects(mc_dev, &irq_count); + if (error < 0) { + /* + * If the error is -ENXIO, we ignore it, as it indicates + * that the object scan was aborted, as we detected that + * an object was removed from the DPRC in the MC, while + * we were scanning the DPRC. + */ + if (error != -ENXIO) { + dev_err(dev, "dprc_scan_objects() failed: %d\n", + error); + } + + goto out; + } + + if (irq_count > FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS) { + dev_warn(dev, + "IRQs needed (%u) exceed IRQs preallocated (%u)\n", + irq_count, FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS); + } + } + +out: + mutex_unlock(&mc_bus->scan_mutex); + return IRQ_HANDLED; +} + +/* + * Disable and clear interrupt for a given DPRC object + */ +static int disable_dprc_irq(struct fsl_mc_device *mc_dev) +{ + int error; + struct fsl_mc_io *mc_io = mc_dev->mc_io; + + WARN_ON(mc_dev->obj_desc.irq_count != 1); + + /* + * Disable generation of interrupt, while we configure it: + */ + error = dprc_set_irq_enable(mc_io, 0, mc_dev->mc_handle, 0, 0); + if (error < 0) { + dev_err(&mc_dev->dev, + "Disabling DPRC IRQ failed: dprc_set_irq_enable() failed: %d\n", + error); + return error; + } + + /* + * Disable all interrupt causes for the interrupt: + */ + error = dprc_set_irq_mask(mc_io, 0, mc_dev->mc_handle, 0, 0x0); + if (error < 0) { + dev_err(&mc_dev->dev, + "Disabling DPRC IRQ failed: dprc_set_irq_mask() failed: %d\n", + error); + return error; + } + + /* + * Clear any leftover interrupts: + */ + error = dprc_clear_irq_status(mc_io, 0, mc_dev->mc_handle, 0, ~0x0U); + if (error < 0) { + dev_err(&mc_dev->dev, + "Disabling DPRC IRQ failed: dprc_clear_irq_status() failed: %d\n", + error); + return error; + } + + return 0; +} + +static int register_dprc_irq_handler(struct fsl_mc_device *mc_dev) +{ + int error; + struct fsl_mc_device_irq *irq = mc_dev->irqs[0]; + + WARN_ON(mc_dev->obj_desc.irq_count != 1); + + /* + * NOTE: devm_request_threaded_irq() invokes the device-specific + * function that programs the MSI physically in the device + */ + error = devm_request_threaded_irq(&mc_dev->dev, + irq->msi_desc->irq, + dprc_irq0_handler, + dprc_irq0_handler_thread, + IRQF_NO_SUSPEND | IRQF_ONESHOT, + "FSL MC DPRC irq0", + &mc_dev->dev); + if (error < 0) { + dev_err(&mc_dev->dev, + "devm_request_threaded_irq() failed: %d\n", + error); + return error; + } + + return 0; +} + +static int enable_dprc_irq(struct fsl_mc_device *mc_dev) +{ + int error; + + /* + * Enable all interrupt causes for the interrupt: + */ + error = dprc_set_irq_mask(mc_dev->mc_io, 0, mc_dev->mc_handle, 0, + ~0x0u); + if (error < 0) { + dev_err(&mc_dev->dev, + "Enabling DPRC IRQ failed: dprc_set_irq_mask() failed: %d\n", + error); + + return error; + } + + /* + * Enable generation of the interrupt: + */ + error = dprc_set_irq_enable(mc_dev->mc_io, 0, mc_dev->mc_handle, 0, 1); + if (error < 0) { + dev_err(&mc_dev->dev, + "Enabling DPRC IRQ failed: dprc_set_irq_enable() failed: %d\n", + error); + + return error; + } + + return 0; +} + +/* + * Setup interrupt for a given DPRC device + */ +static int dprc_setup_irq(struct fsl_mc_device *mc_dev) +{ + int error; + + error = fsl_mc_allocate_irqs(mc_dev); + if (error < 0) + return error; + + error = disable_dprc_irq(mc_dev); + if (error < 0) + goto error_free_irqs; + + error = register_dprc_irq_handler(mc_dev); + if (error < 0) + goto error_free_irqs; + + error = enable_dprc_irq(mc_dev); + if (error < 0) + goto error_free_irqs; + + return 0; + +error_free_irqs: + fsl_mc_free_irqs(mc_dev); + return error; +} + +/** * dprc_probe - callback invoked when a DPRC is being bound to this driver * * @mc_dev: Pointer to fsl-mc device representing a DPRC @@ -476,6 +701,13 @@ static int dprc_probe(struct fsl_mc_device *mc_dev) if (error < 0) goto error_cleanup_open; + /* + * Configure interrupt for the DPRC object associated with this MC bus: + */ + error = dprc_setup_irq(mc_dev); + if (error < 0) + goto error_cleanup_open; + dev_info(&mc_dev->dev, "DPRC device bound to driver"); return 0; @@ -494,6 +726,15 @@ error_cleanup_msi_domain: return error; } +/* + * Tear down interrupt for a given DPRC object + */ +static void dprc_teardown_irq(struct fsl_mc_device *mc_dev) +{ + (void)disable_dprc_irq(mc_dev); + fsl_mc_free_irqs(mc_dev); +} + /** * dprc_remove - callback invoked when a DPRC is being unbound from this driver * @@ -514,6 +755,12 @@ static int dprc_remove(struct fsl_mc_device *mc_dev) if (WARN_ON(!mc_dev->mc_io)) return -EINVAL; + if (WARN_ON(!mc_bus->irq_resources)) + return -EINVAL; + + if (dev_get_msi_domain(&mc_dev->dev)) + dprc_teardown_irq(mc_dev); + device_for_each_child(&mc_dev->dev, NULL, __fsl_mc_device_remove); dprc_cleanup_all_resource_pools(mc_dev); error = dprc_close(mc_dev->mc_io, 0, mc_dev->mc_handle); -- 2.3.3 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/