From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.0 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,T_DKIMWL_WL_HIGH,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 868C8C282CE for ; Sat, 25 May 2019 11:38:57 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 594012175B for ; Sat, 25 May 2019 11:38:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="GApLFzXo"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=xilinx.onmicrosoft.com header.i=@xilinx.onmicrosoft.com header.b="STpW8Msz" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 594012175B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xilinx.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=kZQjPPSb1TCh/vIZqFDntRg+zLkh45eSVRvp2dkaHVo=; b=GApLFzXoYaH9vw qxy1XX2vEx4PoJCaQ5TU0x9G86GkS03hLzMM5en7zqtkVpc0URF5YEiRFsPxoqUL6kq7Z+djkIbjs SsF8B4HZjczwGEMfbNbsKpHe5TUJJNuMc3punZkTi3iyyTXQ8Iv8vmt8KHtfYpPiOq2sddS3t0AtS aXgiFUvmT+ztO4IXDVMGXySz1jHhaY2RXsdwTTgpAdFD9wFGdGpYMKs3BQzxE/rFs8nNS2g+FsEy2 kGqVRC5A/sN/1eluTC4X3WG5V1yr1l+6vdqbtH5J8QW46MwH8XmzUfAhvfQTmYlVGaX6r0OURyMyn EqMrAEmeTUe/qycZ7Fpg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hUV0j-0002kt-TU; Sat, 25 May 2019 11:38:49 +0000 Received: from mail-eopbgr770089.outbound.protection.outlook.com ([40.107.77.89] helo=NAM02-SN1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hUUzg-0001TY-J3 for linux-arm-kernel@lists.infradead.org; Sat, 25 May 2019 11:37:47 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector1-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=J2CIgSmoR1CVPz5PQbVsVEzA12CsVNylhOAIMEoKc0g=; b=STpW8MszxiE5lFFkX5jb8rBBVBBs4EpLNJ7IbJsz4vXzS6Os0lTG9WyLg6931akeZP7a9FX5r2APHI4QK73BV46eHRYWaIyj8q5XIBZUJ0tzD7nUSw70wLU946dxMCERlcsHoBOzsI9kLiYMOyM9V4oh8SGDUkcmBREvhw83FN4= Received: from BL0PR02CA0046.namprd02.prod.outlook.com (2603:10b6:207:3d::23) by BN6PR02MB2676.namprd02.prod.outlook.com (2603:10b6:404:fa::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1922.16; Sat, 25 May 2019 11:37:42 +0000 Received: from SN1NAM02FT064.eop-nam02.prod.protection.outlook.com (2a01:111:f400:7e44::207) by BL0PR02CA0046.outlook.office365.com (2603:10b6:207:3d::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1922.15 via Frontend Transport; Sat, 25 May 2019 11:37:42 +0000 Authentication-Results: spf=pass (sender IP is 149.199.80.198) smtp.mailfrom=xilinx.com; arndb.de; dkim=none (message not signed) header.d=none;arndb.de; dmarc=bestguesspass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.80.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.80.198; helo=xir-pvapexch02.xlnx.xilinx.com; Received: from xir-pvapexch02.xlnx.xilinx.com (149.199.80.198) by SN1NAM02FT064.mail.protection.outlook.com (10.152.72.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.1922.16 via Frontend Transport; Sat, 25 May 2019 11:37:41 +0000 Received: from xir-pvapexch01.xlnx.xilinx.com (172.21.17.15) by xir-pvapexch02.xlnx.xilinx.com (172.21.17.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1531.3; Sat, 25 May 2019 12:37:34 +0100 Received: from smtp.xilinx.com (172.21.105.198) by xir-pvapexch01.xlnx.xilinx.com (172.21.17.15) with Microsoft SMTP Server id 15.1.1531.3 via Frontend Transport; Sat, 25 May 2019 12:37:34 +0100 Received: from [149.199.110.15] (port=57194 helo=xirdraganc40.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1hUUzW-00058U-PO; Sat, 25 May 2019 12:37:34 +0100 From: Dragan Cvetic To: , , , , , , Subject: [PATCH V4 09/12] misc: xilinx_sdfec: Support poll file operation Date: Sat, 25 May 2019 12:37:22 +0100 Message-ID: <1558784245-108751-10-git-send-email-dragan.cvetic@xilinx.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1558784245-108751-1-git-send-email-dragan.cvetic@xilinx.com> References: <1558784245-108751-1-git-send-email-dragan.cvetic@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:149.199.80.198; IPV:CAL; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(39860400002)(396003)(346002)(136003)(376002)(2980300002)(199004)(189003)(5660300002)(4326008)(76176011)(9786002)(356004)(6666004)(8936002)(246002)(50226002)(8676002)(107886003)(36756003)(48376002)(305945005)(2906002)(50466002)(51416003)(486006)(2616005)(336012)(44832011)(446003)(426003)(76130400001)(476003)(71366001)(956004)(126002)(16586007)(106002)(7696005)(36906005)(11346002)(30864003)(26005)(7636002)(54906003)(110136005)(186003)(60926002)(47776003)(28376004)(70586007)(2201001)(26826003)(14444005)(316002)(70206006)(478600001)(102446001); DIR:OUT; SFP:1101; SCL:1; SRVR:BN6PR02MB2676; H:xir-pvapexch02.xlnx.xilinx.com; FPR:; SPF:Pass; LANG:en; PTR:unknown-80-198.xilinx.com; A:1; MX:1; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 77e98fcf-29d2-4401-0f30-08d6e10565f0 X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(5600148)(711020)(4605104)(4709054)(1401327)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328); SRVR:BN6PR02MB2676; X-MS-TrafficTypeDiagnostic: BN6PR02MB2676: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5516; X-Forefront-PRVS: 0048BCF4DA X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: XjPxTnoJVh4T7UU7rONwzlCh5z3d+Ovhw5XCYRD+ohVrEF1KChWLX9gfwZzbStMvqLjhXIq+YAOUMfMF/OlqHOPUZL2dfB0g62PbCczvdM3sxUCk0l0VV23wkiFLGd95NqYPW23dJCWF7hgqeAj7NV7kdnE4DQegLRq1+tHVcw4H6fOeAMcv2bxJ42vMDWcwqgnVRrCkXv+oAsSsLbh1Z/bpPuA3rETNs+lTXtKknR8OdYAjUgiBCSHBNomR8khccFBU+HUwO6LBRYM4o01/caQcm3wAZ/V7nqGTK8vCjRcNmad/Luw59va3oiCngbZvH61lWOkGNVv5xxvpQMXFHVrgNZv6hSn5l8BvY/lpHHpfT+668INYLUzedM4iJtI0FZUHQMx1cnQoLAV47iTQjyFN38h+s6gUTzrhBAnTIWQ= X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 May 2019 11:37:41.7078 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 77e98fcf-29d2-4401-0f30-08d6e10565f0 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c; Ip=[149.199.80.198]; Helo=[xir-pvapexch02.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR02MB2676 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190525_043744_671053_8E85E6A2 X-CRM114-Status: GOOD ( 14.23 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Dragan Cvetic , Derek Kiernan , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org Support monitoring and detecting the SD-FEC error events through IRQ and poll file operation. The SD-FEC device can detect one-error or multi-error events. An error triggers an interrupt which creates and run the ONE_SHOT IRQ thread. The ONE_SHOT IRQ thread detects type of error and pass that information to the poll function. The file_operation callback poll(), collects the events and updates the statistics accordingly. The function poll blocks() on waiting queue which can be unblocked by ONE_SHOT IRQ handling thread. Support SD-FEC interrupt set ioctl callback. The SD-FEC can detect two type of errors: coding errors (ECC) and a data interface errors (TLAST). The errors are events which can trigger an IRQ if enabled. The driver can monitor and detect these errors through IRQ. Also the driver updates the statistical data. Tested-by: Dragan Cvetic Signed-off-by: Derek Kiernan Signed-off-by: Dragan Cvetic --- drivers/misc/xilinx_sdfec.c | 286 +++++++++++++++++++++++++++++++++++++++ include/uapi/misc/xilinx_sdfec.h | 13 ++ 2 files changed, 299 insertions(+) diff --git a/drivers/misc/xilinx_sdfec.c b/drivers/misc/xilinx_sdfec.c index f1c96c7..544e746 100644 --- a/drivers/misc/xilinx_sdfec.c +++ b/drivers/misc/xilinx_sdfec.c @@ -189,7 +189,14 @@ struct xsdfec_clks { * @dev: pointer to device struct * @state: State of the SDFEC device * @config: Configuration of the SDFEC device + * @state_updated: indicates State updated by interrupt handler + * @stats_updated: indicates Stats updated by interrupt handler + * @isr_err_count: Count of ISR errors + * @cecc_count: Count of Correctable ECC errors (SBE) + * @uecc_count: Count of Uncorrectable ECC errors (MBE) + * @irq: IRQ number * @miscdev: Misc device handle + * @waitq: Driver wait queue * @irq_lock: Driver spinlock * @clks: Clocks managed by the SDFEC driver * @@ -200,9 +207,17 @@ struct xsdfec_dev { struct device *dev; enum xsdfec_state state; struct xsdfec_config config; + bool state_updated; + bool stats_updated; + atomic_t isr_err_count; + atomic_t cecc_count; + atomic_t uecc_count; + int irq; struct miscdevice miscdev; + wait_queue_head_t waitq; /* Spinlock to protect state_updated and stats_updated */ spinlock_t irq_lock; + unsigned long flags; struct xsdfec_clks clks; }; @@ -286,6 +301,90 @@ static int xsdfec_get_config(struct xsdfec_dev *xsdfec, void __user *arg) return err; } +static int xsdfec_isr_enable(struct xsdfec_dev *xsdfec, bool enable) +{ + u32 mask_read; + + if (enable) { + /* Enable */ + xsdfec_regwrite(xsdfec, XSDFEC_IER_ADDR, XSDFEC_ISR_MASK); + mask_read = xsdfec_regread(xsdfec, XSDFEC_IMR_ADDR); + if (mask_read & XSDFEC_ISR_MASK) { + dev_dbg(xsdfec->dev, + "SDFEC enabling irq with IER failed"); + return -EIO; + } + } else { + /* Disable */ + xsdfec_regwrite(xsdfec, XSDFEC_IDR_ADDR, XSDFEC_ISR_MASK); + mask_read = xsdfec_regread(xsdfec, XSDFEC_IMR_ADDR); + if ((mask_read & XSDFEC_ISR_MASK) != XSDFEC_ISR_MASK) { + dev_dbg(xsdfec->dev, + "SDFEC disabling irq with IDR failed"); + return -EIO; + } + } + return 0; +} + +static int xsdfec_ecc_isr_enable(struct xsdfec_dev *xsdfec, bool enable) +{ + u32 mask_read; + + if (enable) { + /* Enable */ + xsdfec_regwrite(xsdfec, XSDFEC_ECC_IER_ADDR, + XSDFEC_ALL_ECC_ISR_MASK); + mask_read = xsdfec_regread(xsdfec, XSDFEC_ECC_IMR_ADDR); + if (mask_read & XSDFEC_ALL_ECC_ISR_MASK) { + dev_dbg(xsdfec->dev, + "SDFEC enabling ECC irq with ECC IER failed"); + return -EIO; + } + } else { + /* Disable */ + xsdfec_regwrite(xsdfec, XSDFEC_ECC_IDR_ADDR, + XSDFEC_ALL_ECC_ISR_MASK); + mask_read = xsdfec_regread(xsdfec, XSDFEC_ECC_IMR_ADDR); + if (!(((mask_read & XSDFEC_ALL_ECC_ISR_MASK) == + XSDFEC_ECC_ISR_MASK) || + ((mask_read & XSDFEC_ALL_ECC_ISR_MASK) == + XSDFEC_PL_INIT_ECC_ISR_MASK))) { + dev_dbg(xsdfec->dev, + "SDFEC disable ECC irq with ECC IDR failed"); + return -EIO; + } + } + return 0; +} + +static int xsdfec_set_irq(struct xsdfec_dev *xsdfec, void __user *arg) +{ + struct xsdfec_irq irq; + int err; + int isr_err; + int ecc_err; + + err = copy_from_user(&irq, arg, sizeof(irq)); + if (err) + return -EFAULT; + + /* Setup tlast related IRQ */ + isr_err = xsdfec_isr_enable(xsdfec, irq.enable_isr); + if (!isr_err) + xsdfec->config.irq.enable_isr = irq.enable_isr; + + /* Setup ECC related IRQ */ + ecc_err = xsdfec_ecc_isr_enable(xsdfec, irq.enable_ecc_isr); + if (!ecc_err) + xsdfec->config.irq.enable_ecc_isr = irq.enable_ecc_isr; + + if (isr_err < 0 || ecc_err < 0) + err = -EIO; + + return err; +} + static int xsdfec_set_turbo(struct xsdfec_dev *xsdfec, void __user *arg) { struct xsdfec_turbo turbo; @@ -776,6 +875,9 @@ static long xsdfec_dev_ioctl(struct file *fptr, unsigned int cmd, case XSDFEC_GET_CONFIG: rval = xsdfec_get_config(xsdfec, arg); break; + case XSDFEC_SET_IRQ: + rval = xsdfec_set_irq(xsdfec, arg); + break; case XSDFEC_SET_TURBO: rval = xsdfec_set_turbo(xsdfec, arg); break; @@ -810,11 +912,36 @@ static long xsdfec_dev_compat_ioctl(struct file *file, unsigned int cmd, } #endif +static unsigned int xsdfec_poll(struct file *file, poll_table *wait) +{ + unsigned int mask = 0; + struct xsdfec_dev *xsdfec; + + xsdfec = container_of(file->private_data, struct xsdfec_dev, miscdev); + + if (!xsdfec) + return POLLNVAL | POLLHUP; + + poll_wait(file, &xsdfec->waitq, wait); + + /* XSDFEC ISR detected an error */ + spin_lock_irqsave(&xsdfec->irq_lock, xsdfec->flags); + if (xsdfec->state_updated) + mask |= POLLIN | POLLPRI; + + if (xsdfec->stats_updated) + mask |= POLLIN | POLLRDNORM; + spin_unlock_irqrestore(&xsdfec->irq_lock, xsdfec->flags); + + return mask; +} + static const struct file_operations xsdfec_fops = { .owner = THIS_MODULE, .open = xsdfec_dev_open, .release = xsdfec_dev_release, .unlocked_ioctl = xsdfec_dev_ioctl, + .poll = xsdfec_poll, #ifdef CONFIG_COMPAT .compat_ioctl = xsdfec_dev_compat_ioctl, #endif @@ -908,6 +1035,146 @@ static int xsdfec_parse_of(struct xsdfec_dev *xsdfec) return 0; } +static void xsdfec_count_and_clear_ecc_multi_errors(struct xsdfec_dev *xsdfec, + u32 uecc) +{ + u32 uecc_event; + + /* Update ECC ISR error counts */ + atomic_add(hweight32(uecc), &xsdfec->uecc_count); + xsdfec->stats_updated = true; + + /* Clear ECC errors */ + xsdfec_regwrite(xsdfec, XSDFEC_ECC_ISR_ADDR, + XSDFEC_ALL_ECC_ISR_MBE_MASK); + /* Clear ECC events */ + if (uecc & XSDFEC_ECC_ISR_MBE_MASK) { + uecc_event = uecc >> XSDFEC_ECC_ISR_MBE_TO_EVENT_SHIFT; + xsdfec_regwrite(xsdfec, XSDFEC_ECC_ISR_ADDR, uecc_event); + } else if (uecc & XSDFEC_PL_INIT_ECC_ISR_MBE_MASK) { + uecc_event = uecc >> XSDFEC_PL_INIT_ECC_ISR_MBE_TO_EVENT_SHIFT; + xsdfec_regwrite(xsdfec, XSDFEC_ECC_ISR_ADDR, uecc_event); + } +} + +static void xsdfec_count_and_clear_ecc_single_errors(struct xsdfec_dev *xsdfec, + u32 cecc, u32 sbe_mask) +{ + /* Update ECC ISR error counts */ + atomic_add(hweight32(cecc), &xsdfec->cecc_count); + xsdfec->stats_updated = true; + + /* Clear ECC errors */ + xsdfec_regwrite(xsdfec, XSDFEC_ECC_ISR_ADDR, sbe_mask); +} + +static void xsdfec_count_and_clear_isr_errors(struct xsdfec_dev *xsdfec, + u32 isr_err) +{ + /* Update ISR error counts */ + atomic_add(hweight32(isr_err), &xsdfec->isr_err_count); + xsdfec->stats_updated = true; + + /* Clear ISR error status */ + xsdfec_regwrite(xsdfec, XSDFEC_ISR_ADDR, XSDFEC_ISR_MASK); +} + +static void xsdfec_update_state_for_isr_err(struct xsdfec_dev *xsdfec) +{ + xsdfec->state = XSDFEC_NEEDS_RESET; + xsdfec->state_updated = true; +} + +static void xsdfec_update_state_for_ecc_err(struct xsdfec_dev *xsdfec, + u32 ecc_err) +{ + if (ecc_err & XSDFEC_ECC_ISR_MBE_MASK) + xsdfec->state = XSDFEC_NEEDS_RESET; + else if (ecc_err & XSDFEC_PL_INIT_ECC_ISR_MBE_MASK) + xsdfec->state = XSDFEC_PL_RECONFIGURE; + + xsdfec->state_updated = true; +} + +static int xsdfec_get_sbe_mask(u32 ecc_err) +{ + u32 sbe_mask = XSDFEC_ALL_ECC_ISR_SBE_MASK; + + if (ecc_err & XSDFEC_ECC_ISR_MBE_MASK) { + sbe_mask = (XSDFEC_ECC_ISR_MBE_MASK - ecc_err) >> + XSDFEC_ECC_ISR_MBE_TO_EVENT_SHIFT; + } else if (ecc_err & XSDFEC_PL_INIT_ECC_ISR_MBE_MASK) + sbe_mask = (XSDFEC_PL_INIT_ECC_ISR_MBE_MASK - ecc_err) >> + XSDFEC_PL_INIT_ECC_ISR_MBE_TO_EVENT_SHIFT; + + return sbe_mask; +} + +static irqreturn_t xsdfec_irq_thread(int irq, void *dev_id) +{ + struct xsdfec_dev *xsdfec = dev_id; + irqreturn_t ret = IRQ_HANDLED; + u32 ecc_err; + u32 isr_err; + u32 err_value; + u32 sbe_mask; + + WARN_ON(xsdfec->irq != irq); + + /* Mask Interrupts */ + xsdfec_isr_enable(xsdfec, false); + xsdfec_ecc_isr_enable(xsdfec, false); + + /* Read Interrupt Status Registers */ + ecc_err = xsdfec_regread(xsdfec, XSDFEC_ECC_ISR_ADDR); + isr_err = xsdfec_regread(xsdfec, XSDFEC_ISR_ADDR); + + spin_lock_irqsave(&xsdfec->irq_lock, xsdfec->flags); + + err_value = ecc_err & XSDFEC_ALL_ECC_ISR_MBE_MASK; + if (err_value) { + dev_dbg(xsdfec->dev, "Multi-bit error on xsdfec%d", + xsdfec->config.fec_id); + /* Count and clear multi-bit errors and associated events */ + xsdfec_count_and_clear_ecc_multi_errors(xsdfec, err_value); + xsdfec_update_state_for_ecc_err(xsdfec, ecc_err); + } + + /* + * Update SBE mask to remove events associated with MBE if present. + * If no MBEs are present will return mask for all SBE bits + */ + sbe_mask = xsdfec_get_sbe_mask(err_value); + err_value = ecc_err & sbe_mask; + if (err_value) { + dev_dbg(xsdfec->dev, "Correctable error on xsdfec%d", + xsdfec->config.fec_id); + xsdfec_count_and_clear_ecc_single_errors(xsdfec, err_value, + sbe_mask); + } + + err_value = isr_err & XSDFEC_ISR_MASK; + if (err_value) { + dev_dbg(xsdfec->dev, + "Tlast,or DIN_WORDS or DOUT_WORDS not correct"); + xsdfec_count_and_clear_isr_errors(xsdfec, err_value); + xsdfec_update_state_for_isr_err(xsdfec); + } + + if (xsdfec->state_updated || xsdfec->stats_updated) + wake_up_interruptible(&xsdfec->waitq); + else + ret = IRQ_NONE; + + /* Unmask Interrupts */ + xsdfec_isr_enable(xsdfec, true); + xsdfec_ecc_isr_enable(xsdfec, true); + + spin_unlock_irqrestore(&xsdfec->irq_lock, xsdfec->flags); + + return ret; +} + static int xsdfec_clk_init(struct platform_device *pdev, struct xsdfec_clks *clks) { @@ -1069,6 +1336,7 @@ static int xsdfec_probe(struct platform_device *pdev) struct resource *res; int err; char buf[NAMEBUF_SIZE]; + bool irq_enabled = true; xsdfec = devm_kzalloc(&pdev->dev, sizeof(*xsdfec), GFP_KERNEL); if (!xsdfec) @@ -1091,6 +1359,12 @@ static int xsdfec_probe(struct platform_device *pdev) goto err_xsdfec_dev; } + xsdfec->irq = platform_get_irq(pdev, 0); + if (xsdfec->irq < 0) { + dev_dbg(dev, "platform_get_irq failed"); + irq_enabled = false; + } + err = xsdfec_parse_of(xsdfec); if (err < 0) goto err_xsdfec_dev; @@ -1100,6 +1374,18 @@ static int xsdfec_probe(struct platform_device *pdev) /* Save driver private data */ platform_set_drvdata(pdev, xsdfec); + if (irq_enabled) { + init_waitqueue_head(&xsdfec->waitq); + /* Register IRQ thread */ + err = devm_request_threaded_irq(dev, xsdfec->irq, NULL, + xsdfec_irq_thread, IRQF_ONESHOT, + "xilinx-sdfec16", xsdfec); + if (err < 0) { + dev_err(dev, "unable to request IRQ%d", xsdfec->irq); + goto err_xsdfec_dev; + } + } + snprintf(buf, NAMEBUF_SIZE, "xsdfec%d", xsdfec->config.fec_id); xsdfec->miscdev.minor = MISC_DYNAMIC_MINOR; xsdfec->miscdev.name = buf; diff --git a/include/uapi/misc/xilinx_sdfec.h b/include/uapi/misc/xilinx_sdfec.h index 82e58b3..890930d 100644 --- a/include/uapi/misc/xilinx_sdfec.h +++ b/include/uapi/misc/xilinx_sdfec.h @@ -260,6 +260,19 @@ struct xsdfec_ldpc_param_table_sizes { */ #define XSDFEC_MAGIC 'f' /** + * DOC: XSDFEC_SET_IRQ + * @Parameters + * + * @struct xsdfec_irq * + * Pointer to the &struct xsdfec_irq that contains the interrupt settings + * for the SD-FEC core + * + * @Description + * + * ioctl to enable or disable irq + */ +#define XSDFEC_SET_IRQ _IOW(XSDFEC_MAGIC, 3, struct xsdfec_irq) +/** * DOC: XSDFEC_SET_TURBO * @Parameters * -- 2.7.4 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel