From patchwork Fri Jan 13 18:43:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Organov X-Patchwork-Id: 642546 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44826C3DA78 for ; Fri, 13 Jan 2023 18:43:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229648AbjAMSnr (ORCPT ); Fri, 13 Jan 2023 13:43:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229703AbjAMSnp (ORCPT ); Fri, 13 Jan 2023 13:43:45 -0500 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30B141EC46 for ; Fri, 13 Jan 2023 10:43:44 -0800 (PST) Received: by mail-lf1-x12f.google.com with SMTP id j17so34352864lfr.3 for ; Fri, 13 Jan 2023 10:43:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vDEp4eKXdg/3wssI2Ou1QYWdbAeeL+58ez61t5CUM9E=; b=DEbvU45S2p8aPAopC6a9pKkM/u8KbX0uDY8ZXqTQ8UeOAi2PBhwGYPABgd1xwf/APN z25YgjS9VUobk7OFhqVQGKOhcLfKxa0cESbJj92jkP8bp48ZIPYTsVg2GgVkL/Jaof+e ZnDVW2pAABKh2MYe7/VKBvsY03ZHLUcLvw9rY6ARvMKKQCWntiS2frO1usD1jUg3yK8+ FFiyDbgoVvh9oCqf4TCj8C2rSzX1PluXbLFC2jo+OI8dYnfGR1RvnQdd1yPAxnZqLP0p 6sHCpR7awMa7XbsTnSEoZR6dtkOfq4PnDIANA46abeKDC9abul6MOtWAA5jkv7t4EzhQ IfkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vDEp4eKXdg/3wssI2Ou1QYWdbAeeL+58ez61t5CUM9E=; b=noLlCr12LzS+khanIZTPjVa07yFG8UTb+0vw1Hbo/LCUxVTZFUlfGM/Tp09aQR5kkw itNEuSKxmqf03ZcGf6xm+f5+0mIQ3cHWp5ahnFCdL/Y3HzvRV8CbtHoJu+uDzsbuZJ9k WEmNaj+5k+xcmX91QvzMB7uTdDkgwo6VrZ9/U84KTdYgyTN9tPwEjjcz6Z9UgCbBpCYN 7Px06zwKwa9OCQg6/SeDtsuyYDwK7f/VZZQo1xUW4EmYN2pLfS0UMgCfEUDXCJ5txH0S YKSdlAF+AObpiRUwTKxCKuYkpw9fiuntpBTEN13UNmSf82xYcE2/2eLgvc9J1SFyWr9p DoFw== X-Gm-Message-State: AFqh2kquFrSBRdXSzYR9sR5pMlUvL/D+f8LXZISFlqr6+/9UOK6rBocb tUrvGB7lT3CWJ37tSsG3+ZB5huL4tkE= X-Google-Smtp-Source: AMrXdXsa/zrmKcVLowOWxl/7ymTxOgldOiFPfuXlVaUcxJRNIQqfkMfBqpGi1CSUoCmyh6GxryK3Ng== X-Received: by 2002:a19:f614:0:b0:4cc:9de0:c251 with SMTP id x20-20020a19f614000000b004cc9de0c251mr2658400lfe.40.1673635423314; Fri, 13 Jan 2023 10:43:43 -0800 (PST) Received: from osv.localdomain ([89.175.180.246]) by smtp.gmail.com with ESMTPSA id o11-20020ac2434b000000b004cc9ddce3adsm1261439lfl.82.2023.01.13.10.43.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jan 2023 10:43:42 -0800 (PST) From: Sergey Organov To: linux-serial@vger.kernel.org Cc: Fabio Estevam , Greg Kroah-Hartman , Jiri Slaby , Richard Genoud , Sascha Hauer , Shawn Guo , Tim Harvey , =?utf-8?q?Tomasz_Mo=C5=84?= , linux-arm-kernel@lists.infradead.org, NXP Linux Team , Pengutronix Kernel Team , Sergey Organov Subject: [PATCH 2/8] serial: imx: work-around for hardware RX flood Date: Fri, 13 Jan 2023 21:43:28 +0300 Message-Id: <20230113184334.287130-3-sorganov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230113184334.287130-1-sorganov@gmail.com> References: <87bko4e65y.fsf@osv.gnss.ru> <20230113184334.287130-1-sorganov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org Check if hardware Rx flood is in progress, and issue soft reset to UART to stop the flood. A way to reproduce the flood (checked on iMX6SX) is: open iMX UART at 9600 8N1, and from external source send 0xf0 char at 115200 8N1. In about 90% of cases this starts a flood of "receiving" of 0xff characters by the iMX UART that is terminated by any activity on RxD line, or could be stopped by issuing soft reset to the UART (just stop/start of RX does not help). Note that in essence what we did here is sending isolated start bit about 2.4 times shorter than it is to be if issued on the UART configured baud rate. There was earlier attempt to fix similar issue in: 'commit b38cb7d25711 ("serial: imx: Disable new features of autobaud detection")', but apparently it only gets harder to reproduce the issue after that commit. Signed-off-by: Sergey Organov --- drivers/tty/serial/imx.c | 123 ++++++++++++++++++++++++++++++--------- 1 file changed, 95 insertions(+), 28 deletions(-) diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index bf222d8568a9..e7fce31e460d 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -210,6 +210,9 @@ struct imx_port { struct mctrl_gpios *gpios; + /* counter to stop 0xff flood */ + int idle_counter; + /* shadow registers */ unsigned int ucr1; unsigned int ucr2; @@ -428,6 +431,8 @@ static void imx_uart_soft_reset(struct imx_port *sport) imx_uart_writel(sport, ubir, UBIR); imx_uart_writel(sport, ubmr, UBMR); imx_uart_writel(sport, uts, IMX21_UTS); + + sport->idle_counter = 0; } /* called with port.lock taken and irqs off */ @@ -834,15 +839,66 @@ static irqreturn_t imx_uart_txint(int irq, void *dev_id) return IRQ_HANDLED; } +/* Check if hardware Rx flood is in progress, and issue soft reset to stop it. + * This is to be called from Rx ISRs only when some bytes were actually + * received. + * + * A way to reproduce the flood (checked on iMX6SX) is: open iMX UART at 9600 + * 8N1, and from external source send 0xf0 char at 115200 8N1. In about 90% of + * cases this starts a flood of "receiving" of 0xff characters by the iMX6 UART + * that is terminated by any activity on RxD line, or could be stopped by + * issuing soft reset to the UART (just stop/start of RX does not help). Note + * that what we do here is sending isolated start bit about 2.4 times shorter + * than it is to be on UART configured baud rate. + */ +static void imx_uart_check_flood(struct imx_port *sport, u32 usr2) +{ + /* To detect hardware 0xff flood we monitor RxD line between RX + * interrupts to isolate "receiving" of char(s) with no activity + * on RxD line, that'd never happen on actual data transfers. + * + * We use USR2_WAKE bit to check for activity on RxD line, but we have a + * race here if we clear USR2_WAKE when receiving of a char is in + * progress, so we might get RX interrupt later with USR2_WAKE bit + * cleared. Note though that as we don't try to clear USR2_WAKE when we + * detected no activity, this race may hide actual activity only once. + * + * Yet another case where receive interrupt may occur without RxD + * activity is expiration of aging timer, so we consider this as well. + * + * We use 'idle_counter' to ensure that we got at least so many RX + * interrupts without any detected activity on RxD line. 2 cases + * described plus 1 to be on the safe side gives us a margin of 3, + * below. In practice I was not able to produce a false positive to + * induce soft reset at regular data transfers even using 1 as the + * margin, so 3 is actually very strong. + * + * We count interrupts, not chars in 'idle-counter' for simplicity. + */ + + if (usr2 & USR2_WAKE) { + imx_uart_writel(sport, USR2_WAKE, USR2); + sport->idle_counter = 0; + } else if (++sport->idle_counter > 3) { + dev_warn(sport->port.dev, "RX flood detected: soft reset."); + imx_uart_soft_reset(sport); /* also clears 'sport->idle_counter' */ + } +} + static irqreturn_t __imx_uart_rxint(int irq, void *dev_id) { struct imx_port *sport = dev_id; unsigned int rx, flg, ignored = 0; struct tty_port *port = &sport->port.state->port; + u32 usr2; - while (imx_uart_readl(sport, USR2) & USR2_RDR) { - u32 usr2; + usr2 = imx_uart_readl(sport, USR2); + /* If we received something, check for 0xff flood */ + if (usr2 & USR2_RDR) + imx_uart_check_flood(sport, usr2); + + for ( ; usr2 & USR2_RDR; usr2 = imx_uart_readl(sport, USR2)) { flg = TTY_NORMAL; sport->port.icount.rx++; @@ -1180,55 +1236,64 @@ static void imx_uart_dma_rx_callback(void *data) status = dmaengine_tx_status(chan, sport->rx_cookie, &state); if (status == DMA_ERROR) { + spin_lock(&sport->port.lock); imx_uart_clear_rx_errors(sport); + spin_unlock(&sport->port.lock); return; } - if (!(sport->port.ignore_status_mask & URXD_DUMMY_READ)) { + /* + * The state-residue variable represents the empty space + * relative to the entire buffer. Taking this in consideration + * the head is always calculated base on the buffer total + * length - DMA transaction residue. The UART script from the + * SDMA firmware will jump to the next buffer descriptor, + * once a DMA transaction if finalized (IMX53 RM - A.4.1.2.4). + * Taking this in consideration the tail is always at the + * beginning of the buffer descriptor that contains the head. + */ - /* - * The state-residue variable represents the empty space - * relative to the entire buffer. Taking this in consideration - * the head is always calculated base on the buffer total - * length - DMA transaction residue. The UART script from the - * SDMA firmware will jump to the next buffer descriptor, - * once a DMA transaction if finalized (IMX53 RM - A.4.1.2.4). - * Taking this in consideration the tail is always at the - * beginning of the buffer descriptor that contains the head. - */ + /* Calculate the head */ + rx_ring->head = sg_dma_len(sgl) - state.residue; - /* Calculate the head */ - rx_ring->head = sg_dma_len(sgl) - state.residue; + /* Calculate the tail. */ + bd_size = sg_dma_len(sgl) / sport->rx_periods; + rx_ring->tail = ((rx_ring->head-1) / bd_size) * bd_size; - /* Calculate the tail. */ - bd_size = sg_dma_len(sgl) / sport->rx_periods; - rx_ring->tail = ((rx_ring->head-1) / bd_size) * bd_size; + if (rx_ring->head <= sg_dma_len(sgl) && + rx_ring->head > rx_ring->tail) { - if (rx_ring->head <= sg_dma_len(sgl) && - rx_ring->head > rx_ring->tail) { + /* Move data from tail to head */ + r_bytes = rx_ring->head - rx_ring->tail; - /* Move data from tail to head */ - r_bytes = rx_ring->head - rx_ring->tail; + /* If we received something, check for 0xff flood */ + if (r_bytes > 0) { + spin_lock(&sport->port.lock); + imx_uart_check_flood(sport, imx_uart_readl(sport, USR2)); + spin_unlock(&sport->port.lock); + } + + if (!(sport->port.ignore_status_mask & URXD_DUMMY_READ)) { /* CPU claims ownership of RX DMA buffer */ dma_sync_sg_for_cpu(sport->port.dev, sgl, 1, - DMA_FROM_DEVICE); + DMA_FROM_DEVICE); w_bytes = tty_insert_flip_string(port, - sport->rx_buf + rx_ring->tail, r_bytes); + sport->rx_buf + rx_ring->tail, r_bytes); /* UART retrieves ownership of RX DMA buffer */ dma_sync_sg_for_device(sport->port.dev, sgl, 1, - DMA_FROM_DEVICE); + DMA_FROM_DEVICE); if (w_bytes != r_bytes) sport->port.icount.buf_overrun++; sport->port.icount.rx += w_bytes; - } else { - WARN_ON(rx_ring->head > sg_dma_len(sgl)); - WARN_ON(rx_ring->head <= rx_ring->tail); } + } else { + WARN_ON(rx_ring->head > sg_dma_len(sgl)); + WARN_ON(rx_ring->head <= rx_ring->tail); } if (w_bytes) { @@ -1304,6 +1369,8 @@ static void imx_uart_clear_rx_errors(struct imx_port *sport) imx_uart_writel(sport, USR2_ORE, USR2); } + sport->idle_counter = 0; + } #define TXTL_DEFAULT 2 /* reset default */ From patchwork Fri Jan 13 18:43:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Organov X-Patchwork-Id: 642545 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9C924C3DA78 for ; Fri, 13 Jan 2023 18:44:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230123AbjAMSoH (ORCPT ); Fri, 13 Jan 2023 13:44:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230079AbjAMSnt (ORCPT ); Fri, 13 Jan 2023 13:43:49 -0500 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54F4B1EC5D for ; Fri, 13 Jan 2023 10:43:48 -0800 (PST) Received: by mail-lf1-x130.google.com with SMTP id y25so34307599lfa.9 for ; Fri, 13 Jan 2023 10:43:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BEuxX1Ll6053jaM5wYHpbycjGtKOkT1kwUWem6LtYrM=; b=Qv3ZTHYSreLfmMGbsEJVQeKAj0Rsp2AJskikpPzMRGkYLhwu1mXNJoM40qhoqE2Q2N uvKLSM6tPyqNDvP4FVR3V6bs2ptSBvEAVoyXwumN6eTN6gmMZayssMjpShx1E4HGJTqa 842DzUOAgACQtCZe2pgOxXqw55+UfF5XeL9RPfyv798meJ2/U2jWSkOrSTnNXYu7r9cW Jc9TJUmBENDr2gbsacQroSK/NgVhIDxBwCDR/svbH7hn/C6RCxVAR6kETLPsU/aHg1DF Es4c2eRfGJrbmAUPRjeiqpkg3bDP304P1eL60EgJgkQjZTPku1KA2VIQF4nWu9aKlqwH GuXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BEuxX1Ll6053jaM5wYHpbycjGtKOkT1kwUWem6LtYrM=; b=AaYoVvTOKIDcYVwN7mvTIRivoCoIqS4PKQ4kJe76vBkl9STqlf7b9nep7dEOICIxg6 07zPMDMzYHKQ4kD18060kRVLZhxeAPITVLtUOBOny2BuDLVX5o7VaeQ5FP4jUhOIkKW8 0s5u0qruee7RuW3ZMNtB4usCIWh6vLNLtRmH0Uc/ZDxmndiakwF4xaiAWTTPYNkTK80C XjzPbRfoYVZF5VWI7FgIXV5BJYjpHXIVrlgN+4FQcSnX9oJ42tJYFmhYsxYDNx65/7Vg aRFY1Bs5nYTBZZqtXG3pFKEupKm/zbuGBYYn3rWKhZ5sVmbzCjNG1Q6EpydLf7hQL9xy AqEA== X-Gm-Message-State: AFqh2krO8P/+EkrHfhza/9ZSziaNyaS2E1K3d4vgBJo92YhbKlizqTg9 sPMvALYKrHRjtLvFm6J4BPExhlRSkz8= X-Google-Smtp-Source: AMrXdXvFqBm0yaQK2e38U4fE47XqSrNqGwyGOCkcCBfg8zyQzVL6ozWAI3Dhet38lYjyS8B+I/lR5Q== X-Received: by 2002:a05:6512:10d0:b0:4cb:4374:cc78 with SMTP id k16-20020a05651210d000b004cb4374cc78mr16172770lfg.26.1673635426335; Fri, 13 Jan 2023 10:43:46 -0800 (PST) Received: from osv.localdomain ([89.175.180.246]) by smtp.gmail.com with ESMTPSA id o11-20020ac2434b000000b004cc9ddce3adsm1261439lfl.82.2023.01.13.10.43.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jan 2023 10:43:45 -0800 (PST) From: Sergey Organov To: linux-serial@vger.kernel.org Cc: Fabio Estevam , Greg Kroah-Hartman , Jiri Slaby , Richard Genoud , Sascha Hauer , Shawn Guo , Tim Harvey , =?utf-8?q?Tomasz_Mo=C5=84?= , linux-arm-kernel@lists.infradead.org, NXP Linux Team , Pengutronix Kernel Team , Sergey Organov Subject: [PATCH 4/8] serial: imx: do not break from FIFO reading loop prematurely Date: Fri, 13 Jan 2023 21:43:30 +0300 Message-Id: <20230113184334.287130-5-sorganov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230113184334.287130-1-sorganov@gmail.com> References: <87bko4e65y.fsf@osv.gnss.ru> <20230113184334.287130-1-sorganov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org There is no reason to prematurely break out of FIFO reading loop, and it might cause needless reenters into ISR, so keep reading until FIFO is empty. Signed-off-by: Sergey Organov --- drivers/tty/serial/imx.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index 1c950112a598..b96b0edc7854 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -888,7 +888,7 @@ static void imx_uart_check_flood(struct imx_port *sport, u32 usr2) static irqreturn_t __imx_uart_rxint(int irq, void *dev_id) { struct imx_port *sport = dev_id; - unsigned int rx, flg, ignored = 0; + unsigned int rx, flg; struct tty_port *port = &sport->port.state->port; u32 usr2; @@ -921,11 +921,8 @@ static irqreturn_t __imx_uart_rxint(int irq, void *dev_id) if (rx & URXD_OVRRUN) sport->port.icount.overrun++; - if (rx & sport->port.ignore_status_mask) { - if (++ignored > 100) - goto out; + if (rx & sport->port.ignore_status_mask) continue; - } rx &= (sport->port.read_status_mask | 0xFF); @@ -943,13 +940,12 @@ static irqreturn_t __imx_uart_rxint(int irq, void *dev_id) continue; if (sport->port.ignore_status_mask & URXD_DUMMY_READ) - goto out; + continue; if (tty_insert_flip_char(port, rx, flg) == 0) sport->port.icount.buf_overrun++; } -out: tty_flip_buffer_push(port); return IRQ_HANDLED; From patchwork Fri Jan 13 18:43:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Organov X-Patchwork-Id: 642544 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE5CFC3DA78 for ; Fri, 13 Jan 2023 18:44:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230119AbjAMSoK (ORCPT ); Fri, 13 Jan 2023 13:44:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230046AbjAMSny (ORCPT ); Fri, 13 Jan 2023 13:43:54 -0500 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 828853739C for ; Fri, 13 Jan 2023 10:43:51 -0800 (PST) Received: by mail-lf1-x130.google.com with SMTP id d30so29407923lfv.8 for ; Fri, 13 Jan 2023 10:43:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gEk4AFlxAF8T5iRhtAEH/nRNJxTDpq08gbezozP0K5c=; b=EST2u7+EY1BljGeUo+Jl+mIEA0GL3IUBwxEHYsN5Q+frpg+8rXwH/USoGKBXXuaaCq 4DNbVhaE1UxEjroEhkxeNYPTLsYfLK+yC4eH0+a3E2VRZQO287qJ1+vUifcABD7edciy ycSPaQLULmrLkqqGzc46TGE7VatG3iA9bXJE/PPeqthdFEiWQ0L0MDzDEWFRU56urgEK 47qq8OrIHpK00lgOiWmQJLNUc1ebiUV9rWtinefVmz43yYMhwycjYauOCvqVM4Z+8Toj uu7vwLvuTsKARCXTsFXHDttrpfuEgg4m2UyJGCEl9cn9qKPdI6WApM12xgUlj5CHqim9 9qQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gEk4AFlxAF8T5iRhtAEH/nRNJxTDpq08gbezozP0K5c=; b=xI2G+z9waNMdvkV2xgUCvb3WH9/EIYY7tJFky+MFa8AsUnv703o1gjJikYCWyKpUtO Qfe+CsgehOiHzL3ZTrNQ5dKlQWuH/dygfzU7HP3txEXykgYufIjrX/TWbNrZz8RdQqN9 s2GiTULWcdPjW/yKMpWuHmlJ9oyqlrZseWKuO1M4N37BDolMjCsuFUcezIwfAg0GY0iY zYSSwXGIgTxgE4sQBfNIuFRt5Y04Ce611gyEblsgbrj6qGTtmb+MjeBQgecfA0c/Uiyz cq2WLKNWs+9uzGb58uWI5el8Q80J7wiZNsR9hUYIHYuaPLBzuTkTGJf1q3BFFGOFOUWn fRbQ== X-Gm-Message-State: AFqh2krbTPzN1Fq0RBJCqo0HwDXAVIBxT7R7DREkUrKUBzYBUZ9PIMdg q6nYYKlmtRlFSyDW5RJB4Tlcy8PwxWY= X-Google-Smtp-Source: AMrXdXsFRmXLBepa75IdA8upDEUsOGVX6bHbVT7iNgg7WPN7teH0vjcgcywcHXIQ6vaZhr2DUfGdZw== X-Received: by 2002:ac2:5234:0:b0:4a7:64ea:7855 with SMTP id i20-20020ac25234000000b004a764ea7855mr211232lfl.47.1673635429454; Fri, 13 Jan 2023 10:43:49 -0800 (PST) Received: from osv.localdomain ([89.175.180.246]) by smtp.gmail.com with ESMTPSA id o11-20020ac2434b000000b004cc9ddce3adsm1261439lfl.82.2023.01.13.10.43.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jan 2023 10:43:48 -0800 (PST) From: Sergey Organov To: linux-serial@vger.kernel.org Cc: Fabio Estevam , Greg Kroah-Hartman , Jiri Slaby , Richard Genoud , Sascha Hauer , Shawn Guo , Tim Harvey , =?utf-8?q?Tomasz_Mo=C5=84?= , linux-arm-kernel@lists.infradead.org, NXP Linux Team , Pengutronix Kernel Team , Sergey Organov Subject: [PATCH 6/8] serial: imx: stop using USR2 in FIFO reading loop Date: Fri, 13 Jan 2023 21:43:32 +0300 Message-Id: <20230113184334.287130-7-sorganov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230113184334.287130-1-sorganov@gmail.com> References: <87bko4e65y.fsf@osv.gnss.ru> <20230113184334.287130-1-sorganov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org The chip provides all the needed bits in the URXD0 register that we read anyway for data, so get rid of reading USR2 and use only URXD0 bits instead. Signed-off-by: Sergey Organov --- drivers/tty/serial/imx.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index c44a7293c013..be00362b8b67 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -892,27 +892,21 @@ static irqreturn_t __imx_uart_rxint(int irq, void *dev_id) struct tty_port *port = &sport->port.state->port; u32 usr2; - usr2 = imx_uart_readl(sport, USR2); - /* If we received something, check for 0xff flood */ + usr2 = imx_uart_readl(sport, USR2); if (usr2 & USR2_RDR) imx_uart_check_flood(sport, usr2); - for ( ; usr2 & USR2_RDR; usr2 = imx_uart_readl(sport, USR2)) { + while ((rx = imx_uart_readl(sport, URXD0)) & URXD_CHARRDY) { flg = TTY_NORMAL; sport->port.icount.rx++; - rx = imx_uart_readl(sport, URXD0); - - if (usr2 & USR2_BRCD) { - imx_uart_writel(sport, USR2_BRCD, USR2); - if (uart_handle_break(&sport->port)) - continue; - } - if (unlikely(rx & URXD_ERR)) { - if (rx & URXD_BRK) + if (rx & URXD_BRK) { sport->port.icount.brk++; + if (uart_handle_break(&sport->port)) + continue; + } else if (rx & URXD_PRERR) sport->port.icount.parity++; else if (rx & URXD_FRMERR) From patchwork Fri Jan 13 18:43:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Organov X-Patchwork-Id: 642543 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A51C3C3DA78 for ; Fri, 13 Jan 2023 18:44:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230314AbjAMSoV (ORCPT ); Fri, 13 Jan 2023 13:44:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230113AbjAMSoF (ORCPT ); Fri, 13 Jan 2023 13:44:05 -0500 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70DBC32EA1 for ; Fri, 13 Jan 2023 10:43:53 -0800 (PST) Received: by mail-lf1-x130.google.com with SMTP id y25so34307948lfa.9 for ; Fri, 13 Jan 2023 10:43:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Yv7yYu+svGwVLgS8wyxzW693EiE4HtsBGRbigAy1MWs=; b=CP0QKj9lJa+BeUqD8mjzJAzZER4o144dB1FKlqUxhlS8kvXAxLI1Zx0PSlEwZxhtpz A1HItOSE1W9IH0lAmNpXNdj5aXi+Jz3NXTWPeqfhJqrykhBMM8HcMPiSM1INLAp0Dksu N+t/ZsVCAiUJmkuv2QdCm+8qC22E0xZg+HB2GCsdIRSpXNlinC16hWmm9gAJrhAlKQxU ay0wMGuX63vB0rXHiNQv230xrMgyLGz+vNUHCRkdUdbH1iO1v6VRAHsVN4G3RJhlpZGe 3Gs8pau5Tq1YiQ+/mYwyg4MfAS0eQd+TupXow1yPoP790TblXOt0ELIH1HOwtbarFusq IbJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Yv7yYu+svGwVLgS8wyxzW693EiE4HtsBGRbigAy1MWs=; b=m7V58f8TtGzChoD28W4iYVzUDsGCLn0F71GIKv50koSKhJVpSoSxAZ7VnL42c77WA0 k/qlvXmuHs2Xrh+z0XF0bmBn6J4qc6og4cDT/8P52v6Pp2wM74nPZ3akW7gwtV6GfY7L m58uhHoOoTOR5yfFNyG2z7rmoKbiAR310+GZcXgxdTJk8OIXhbCHz2cfaiy9wu8fGRR8 0O7YMPnvlwhZ1kt75+l+aANyzqhRX/3RMf+5083HYgME6mfMgrSlyOTBoHhWIgVG0YYi 7tM90qZjXR5vdAxPWThEXpXWJQ0fEx0ABTnlabTiuR6UTzkss+Af9dQlQoOrJfCQOKwu f1Fg== X-Gm-Message-State: AFqh2krmrB7hj9LVkYqPhK/0ZjP0NvUtcY9zh7PP5+bj15e13I7IiFbG mhBWwoRJ/Cp10DMRwGyn/bWKgpX7FdE= X-Google-Smtp-Source: AMrXdXvt1TMVuja3Y+Zq+MhsrzFa4qgMzz0RT70F2OE4C6YFu2bzKAp9gyGVW7pWlLPpu2ApvjCcEA== X-Received: by 2002:a05:6512:1597:b0:4b6:f4bb:e53f with SMTP id bp23-20020a056512159700b004b6f4bbe53fmr26621541lfb.60.1673635432565; Fri, 13 Jan 2023 10:43:52 -0800 (PST) Received: from osv.localdomain ([89.175.180.246]) by smtp.gmail.com with ESMTPSA id o11-20020ac2434b000000b004cc9ddce3adsm1261439lfl.82.2023.01.13.10.43.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jan 2023 10:43:52 -0800 (PST) From: Sergey Organov To: linux-serial@vger.kernel.org Cc: Fabio Estevam , Greg Kroah-Hartman , Jiri Slaby , Richard Genoud , Sascha Hauer , Shawn Guo , Tim Harvey , =?utf-8?q?Tomasz_Mo=C5=84?= , linux-arm-kernel@lists.infradead.org, NXP Linux Team , Pengutronix Kernel Team , Sergey Organov Subject: [PATCH 8/8] serial: imx: refine local variables in rxint() Date: Fri, 13 Jan 2023 21:43:34 +0300 Message-Id: <20230113184334.287130-9-sorganov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230113184334.287130-1-sorganov@gmail.com> References: <87bko4e65y.fsf@osv.gnss.ru> <20230113184334.287130-1-sorganov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org The 'rx' is chip register, similar to 'usr2', so let it be of 'u32' type as well. Move 'flg' to be FIFO read loop local as it's not used outside. Signed-off-by: Sergey Organov --- drivers/tty/serial/imx.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index f4236e8995fa..45327ff6dd14 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -888,10 +888,9 @@ static void imx_uart_check_flood(struct imx_port *sport, u32 usr2) static irqreturn_t __imx_uart_rxint(int irq, void *dev_id) { struct imx_port *sport = dev_id; - unsigned int rx, flg; struct tty_port *port = &sport->port.state->port; typeof(sport->port.membase) membase = sport->port.membase; - u32 usr2; + u32 usr2, rx; /* If we received something, check for 0xff flood */ usr2 = readl(membase + USR2); @@ -899,7 +898,7 @@ static irqreturn_t __imx_uart_rxint(int irq, void *dev_id) imx_uart_check_flood(sport, usr2); while ((rx = readl(membase + URXD0)) & URXD_CHARRDY) { - flg = TTY_NORMAL; + unsigned int flg = TTY_NORMAL; sport->port.icount.rx++; if (unlikely(rx & URXD_ERR)) {