Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760119AbbKTOJB (ORCPT ); Fri, 20 Nov 2015 09:09:01 -0500 Received: from mail-sn1nam02on0076.outbound.protection.outlook.com ([104.47.36.76]:23669 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S934245AbbKTOI4 (ORCPT ); Fri, 20 Nov 2015 09:08:56 -0500 Authentication-Results: spf=pass (sender IP is 149.199.60.83) smtp.mailfrom=xilinx.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=bestguesspass action=none header.from=xilinx.com; From: Nava kishore Manne To: , , , CC: , , , Nava kishore Manne Subject: [PATCH v2 2/3] serial: xuartps: Rewrite the interrupt handling logic Date: Fri, 20 Nov 2015 19:04:37 +0530 Message-ID: <1448026478-22131-2-git-send-email-navam@xilinx.com> X-Mailer: git-send-email 2.1.2 In-Reply-To: <1448026478-22131-1-git-send-email-navam@xilinx.com> References: <1448026478-22131-1-git-send-email-navam@xilinx.com> X-RCIS-Action: ALLOW X-TM-AS-Product-Ver: IMSS-7.1.0.1224-8.0.0.1202-21952.006 X-TM-AS-User-Approved-Sender: Yes;Yes X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:149.199.60.83;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(2980300002)(438002)(199003)(189002)(50986999)(106466001)(76176999)(103686003)(63266004)(42186005)(87936001)(189998001)(5001920100001)(36386004)(5001770100001)(107886002)(5001960100002)(586003)(6806005)(36756003)(92566002)(575784001)(229853001)(46386002)(48376002)(50226001)(50466002)(45336002)(2201001)(86362001)(19580405001)(19580395003)(52956003)(2950100001)(5003940100001)(90966002)(5008740100001)(33646002)(4001430100002)(11100500001)(4001450100002)(47776003)(5007970100001)(81156007)(107986001);DIR:OUT;SFP:1101;SCL:1;SRVR:SN1NAM02HT246;H:xsj-pvapsmtpgw01;FPR:;SPF:Pass;PTR:unknown-60-83.xilinx.com;A:1;MX:1;LANG:en; MIME-Version: 1.0 Content-Type: text/plain X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(8251501001);SRVR:SN1NAM02HT246; X-Microsoft-Antispam-PRVS: <82bc2cc4831c4c1dbe7bc54e9a5fd661@SN1NAM02HT246.eop-nam02.prod.protection.outlook.com> X-Exchange-Antispam-Report-Test: UriScan:(192813158149592); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(2401047)(8121501046)(5005006)(520078)(10201501046)(3002001);SRVR:SN1NAM02HT246;BCL:0;PCL:0;RULEID:;SRVR:SN1NAM02HT246; X-Forefront-PRVS: 07665BE9D1 X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Nov 2015 13:34:51.2230 (UTC) X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.60.83];Helo=[xsj-pvapsmtpgw01] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1NAM02HT246 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4922 Lines: 138 The existing interrupt handling logic has followins issues. - Upon a parity error with default configuration, the control never comes out of the ISR thereby hanging Linux. - The error handling logic around framing and parity error are buggy. There are chances that the errors will never be captured. This patch fixes all these concerns. Signed-off-by: Nava kishore Manne --- Changes for v2: --Add required changes after spliting the ISR as suggested by Peter Hurley. drivers/tty/serial/xilinx_uartps.c | 64 ++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/drivers/tty/serial/xilinx_uartps.c b/drivers/tty/serial/xilinx_uartps.c index 2e1b0a8..4d71478 100644 --- a/drivers/tty/serial/xilinx_uartps.c +++ b/drivers/tty/serial/xilinx_uartps.c @@ -191,9 +191,10 @@ static irqreturn_t cdns_uart_isr(int irq, void *dev_id) spin_lock_irqsave(&port->lock, flags); /* Read the interrupt status register to determine which - * interrupt(s) is/are active. + * interrupt(s) is/are active and clear them. */ isrstatus = readl(port->membase + CDNS_UART_ISR_OFFSET); + writel(isrstatus, port->membase + CDNS_UART_ISR_OFFSET); if (isrstatus & CDNS_UART_IXR_TXEMPTY) { cdns_uart_handle_tx(dev_id); @@ -202,8 +203,6 @@ static irqreturn_t cdns_uart_isr(int irq, void *dev_id) if (isrstatus & CDNS_UART_IXR_MASK) cdns_uart_handle_rx(dev_id, isrstatus); - writel(isrstatus, port->membase + CDNS_UART_ISR_OFFSET); - /* be sure to release the lock and tty before leaving */ spin_unlock_irqrestore(&port->lock, flags); @@ -354,37 +353,32 @@ static void cdns_uart_handle_rx(void *dev_id, unsigned int isrstatus) { struct uart_port *port = (struct uart_port *)dev_id; unsigned int data; + unsigned int framerrprocessed = 0; char status = TTY_NORMAL; - /* - * There is no hardware break detection, so we interpret framing - * error with all-zeros data as a break sequence. Most of the time, - * there's another non-zero byte at the end of the sequence. - */ - if (isrstatus & CDNS_UART_IXR_FRAMING) { - while (!(readl(port->membase + CDNS_UART_SR_OFFSET) & - CDNS_UART_SR_RXEMPTY)) { - if (!readl(port->membase + CDNS_UART_FIFO_OFFSET)) { + while ((readl(port->membase + CDNS_UART_SR_OFFSET) & + CDNS_UART_SR_RXEMPTY) != CDNS_UART_SR_RXEMPTY) { + data = readl(port->membase + CDNS_UART_FIFO_OFFSET); + port->icount.rx++; + + /* + * There is no hardware break detection, so we interpret framing + * error with all-zeros data as a break sequence. Most of the + * time, there's another non-zero byte at the end of the + * sequence. + */ + if (isrstatus & CDNS_UART_IXR_FRAMING) { + if (!data) { port->read_status_mask |= CDNS_UART_IXR_BRK; - isrstatus &= ~CDNS_UART_IXR_FRAMING; + framerrprocessed = 1; + continue; } } - writel(CDNS_UART_IXR_FRAMING, - port->membase + CDNS_UART_ISR_OFFSET); - } - /* drop byte with parity error if IGNPAR specified */ - if (isrstatus & port->ignore_status_mask & CDNS_UART_IXR_PARITY) - isrstatus &= ~(CDNS_UART_IXR_RXTRIG | CDNS_UART_IXR_TOUT); - - isrstatus &= port->read_status_mask; - isrstatus &= ~port->ignore_status_mask; - if ((isrstatus & CDNS_UART_IXR_TOUT) || - (isrstatus & CDNS_UART_IXR_RXTRIG)) { - /* Receive Timeout Interrupt */ - while ((readl(port->membase + CDNS_UART_SR_OFFSET) & - CDNS_UART_SR_RXEMPTY) != CDNS_UART_SR_RXEMPTY) { - data = readl(port->membase + CDNS_UART_FIFO_OFFSET); + isrstatus &= port->read_status_mask; + isrstatus &= ~port->ignore_status_mask; + if ((isrstatus & CDNS_UART_IXR_TOUT) || + (isrstatus & CDNS_UART_IXR_RXTRIG)) { /* Non-NULL byte after BREAK is garbage (99%) */ if (data && (port->read_status_mask @@ -416,21 +410,25 @@ static void cdns_uart_handle_rx(void *dev_id, unsigned int isrstatus) if (isrstatus & CDNS_UART_IXR_PARITY) { port->icount.parity++; status = TTY_PARITY; - } else if (isrstatus & CDNS_UART_IXR_FRAMING) { + } + if (isrstatus & CDNS_UART_IXR_FRAMING) { port->icount.frame++; status = TTY_FRAME; - } else if (isrstatus & CDNS_UART_IXR_OVERRUN) { + } + if (isrstatus & CDNS_UART_IXR_OVERRUN) { port->icount.overrun++; + tty_insert_flip_char(&port->state->port, 0, + TTY_OVERRUN); } - uart_insert_char(port, isrstatus, CDNS_UART_IXR_OVERRUN, - data, status); + tty_insert_flip_char(&port->state->port, data, status); } + } spin_unlock(&port->lock); tty_flip_buffer_push(&port->state->port); spin_lock(&port->lock); } -} + #ifdef CONFIG_COMMON_CLK /** * cdns_uart_clk_notitifer_cb - Clock notifier callback -- 2.1.2 -- 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/