From patchwork Wed Feb 1 14:26:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Organov X-Patchwork-Id: 649953 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 B85FAC636D3 for ; Wed, 1 Feb 2023 14:27:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232034AbjBAO1p (ORCPT ); Wed, 1 Feb 2023 09:27:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232024AbjBAO1l (ORCPT ); Wed, 1 Feb 2023 09:27:41 -0500 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E4D8677BB for ; Wed, 1 Feb 2023 06:27:40 -0800 (PST) Received: by mail-ed1-x529.google.com with SMTP id u21so17861174edv.3 for ; Wed, 01 Feb 2023 06:27:40 -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=fGRQXniAfmCVOhEPry8KBc9X4/FRyELFse0MGdO3NRc=; b=SGbmN2t4hYYb3e3VPWT+ES5NcVhUe3+2eOBFVLTN0GQflDQLSehKJBKsv2KfOvPbZY 0/UApKMQKKQqpT4Dt5lw8QwWQpE9rPUufUNuXIWDwyti17Av1wHlOCHKbcQY+dFGtok+ rBrYjErKtcv0Y9uhyZYZyYW+QSwa8woXH2QA2609DWTA1VUzclsqrxsTBhNN0RrhIxes eSdrqteqm/UA0wPwrnF5PlBLO/8neabvp1+Y8016vW/jkaV2VXYWm18z2VW3OG+p2WsI 1Gfll0Gn5YGGrPHqNLbUZAOSFWW7FSPCB8nfQ3EjuYVt268xbV0u1IVb0ur9MBKfigN1 +t5A== 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=fGRQXniAfmCVOhEPry8KBc9X4/FRyELFse0MGdO3NRc=; b=IVPv40FVYXIoasPxacr1kzxz9U0h6NBfJmVfZWgUKFH7fxdNCR1aRIUjBxjiEvx1Ht 266XbuHVFYksMj/jYbke/bv+CHjc5ja6haiOGTaPmvE6Gk1ZmCGPRQ8pBkgqz3Ct8RwM yIa3DnuKPAzXNQODazl81rERiZU7NUDrBX37OnmmuZt3LV0L4OnQ1ctxb5RrRk5zCPn5 WHGbQ/VY0wT/vzx/vLWog1oBHIf6832EswWf/zXcxL3UPxMOhsOm+gsnwSaTwVAtxhsp F0gXZCr7hv/Fcn7Rn8MHFsifckFvoDLznj4ALvKEYsBwnRdD0nysyygWE26+I0Lg+YvX 9/NA== X-Gm-Message-State: AO0yUKUcXgHcP9RVl/MmfhhMaMXO+VaNmC9DtAfSB4SG5EuBkQKxfuLC BJSjouK+o9wKK8ssRu1oeIE= X-Google-Smtp-Source: AK7set9iXSdmW3yFrjlGJjCNUYuL6XEWMG+gPdLAsXKGT93ZsVy4zKEc/s9XpHhl7JmYtae67Hw6Ag== X-Received: by 2002:a05:6402:2c8:b0:4a3:43c1:8435 with SMTP id b8-20020a05640202c800b004a343c18435mr1923504edx.9.1675261658939; Wed, 01 Feb 2023 06:27:38 -0800 (PST) Received: from osv.localdomain ([89.175.180.246]) by smtp.gmail.com with ESMTPSA id cf8-20020a0564020b8800b004a18f2ffb86sm8975564edb.79.2023.02.01.06.27.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 06:27:38 -0800 (PST) From: Sergey Organov To: Greg Kroah-Hartman Cc: linux-serial@vger.kernel.org, Fabio Estevam , Jiri Slaby , Richard Genoud , Sascha Hauer , Shawn Guo , Tim Harvey , =?utf-8?q?Tomasz_Mo=C5=84?= , =?utf-8?q?Uwe_Kle?= =?utf-8?q?ine-K=C3=B6nig?= , Johan Hovold , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Sherry Sun , Stefan Wahren , linux-arm-kernel@lists.infradead.org, NXP Linux Team , Pengutronix Kernel Team , Sergey Organov Subject: [PATCH v1 1/7] serial: imx: factor-out common code to imx_uart_soft_reset() Date: Wed, 1 Feb 2023 17:26:54 +0300 Message-Id: <20230201142700.4346-2-sorganov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230201142700.4346-1-sorganov@gmail.com> References: <87bko4e65y.fsf@osv.gnss.ru> <20230201142700.4346-1-sorganov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org We perform soft reset in 2 places, slightly differently for no sufficient reasons, so move more generic variant to a function, and re-use the code. Out of 2 repeat counters, 10 and 100, select 10, as the code works at interrupts disabled, and in practice the reset happens immediately. Signed-off-by: Sergey Organov --- drivers/tty/serial/imx.c | 73 ++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 36 deletions(-) diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index 757825edb0cd..bf222d8568a9 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -397,6 +397,39 @@ static void start_hrtimer_ms(struct hrtimer *hrt, unsigned long msec) hrtimer_start(hrt, ms_to_ktime(msec), HRTIMER_MODE_REL); } +/* called with port.lock taken and irqs off */ +static void imx_uart_soft_reset(struct imx_port *sport) +{ + int i = 10; + u32 ucr2, ubir, ubmr, uts; + + /* + * According to the Reference Manual description of the UART SRST bit: + * + * "Reset the transmit and receive state machines, + * all FIFOs and register USR1, USR2, UBIR, UBMR, UBRC, URXD, UTXD + * and UTS[6-3]". + * + * We don't need to restore the old values from USR1, USR2, URXD and + * UTXD. UBRC is read only, so only save/restore the other three + * registers. + */ + ubir = imx_uart_readl(sport, UBIR); + ubmr = imx_uart_readl(sport, UBMR); + uts = imx_uart_readl(sport, IMX21_UTS); + + ucr2 = imx_uart_readl(sport, UCR2); + imx_uart_writel(sport, ucr2 & ~UCR2_SRST, UCR2); + + while (!(imx_uart_readl(sport, UCR2) & UCR2_SRST) && (--i > 0)) + udelay(1); + + /* Restore the registers */ + imx_uart_writel(sport, ubir, UBIR); + imx_uart_writel(sport, ubmr, UBMR); + imx_uart_writel(sport, uts, IMX21_UTS); +} + /* called with port.lock taken and irqs off */ static void imx_uart_start_rx(struct uart_port *port) { @@ -1398,7 +1431,7 @@ static void imx_uart_disable_dma(struct imx_port *sport) static int imx_uart_startup(struct uart_port *port) { struct imx_port *sport = (struct imx_port *)port; - int retval, i; + int retval; unsigned long flags; int dma_is_inited = 0; u32 ucr1, ucr2, ucr3, ucr4, uts; @@ -1430,15 +1463,9 @@ static int imx_uart_startup(struct uart_port *port) dma_is_inited = 1; spin_lock_irqsave(&sport->port.lock, flags); + /* Reset fifo's and state machines */ - i = 100; - - ucr2 = imx_uart_readl(sport, UCR2); - ucr2 &= ~UCR2_SRST; - imx_uart_writel(sport, ucr2, UCR2); - - while (!(imx_uart_readl(sport, UCR2) & UCR2_SRST) && (--i > 0)) - udelay(1); + imx_uart_soft_reset(sport); /* * Finally, clear and enable interrupts @@ -1593,8 +1620,6 @@ static void imx_uart_flush_buffer(struct uart_port *port) { struct imx_port *sport = (struct imx_port *)port; struct scatterlist *sgl = &sport->tx_sgl[0]; - u32 ucr2; - int i = 100, ubir, ubmr, uts; if (!sport->dma_chan_tx) return; @@ -1612,32 +1637,8 @@ static void imx_uart_flush_buffer(struct uart_port *port) sport->dma_is_txing = 0; } - /* - * According to the Reference Manual description of the UART SRST bit: - * - * "Reset the transmit and receive state machines, - * all FIFOs and register USR1, USR2, UBIR, UBMR, UBRC, URXD, UTXD - * and UTS[6-3]". - * - * We don't need to restore the old values from USR1, USR2, URXD and - * UTXD. UBRC is read only, so only save/restore the other three - * registers. - */ - ubir = imx_uart_readl(sport, UBIR); - ubmr = imx_uart_readl(sport, UBMR); - uts = imx_uart_readl(sport, IMX21_UTS); + imx_uart_soft_reset(sport); - ucr2 = imx_uart_readl(sport, UCR2); - ucr2 &= ~UCR2_SRST; - imx_uart_writel(sport, ucr2, UCR2); - - while (!(imx_uart_readl(sport, UCR2) & UCR2_SRST) && (--i > 0)) - udelay(1); - - /* Restore the registers */ - imx_uart_writel(sport, ubir, UBIR); - imx_uart_writel(sport, ubmr, UBMR); - imx_uart_writel(sport, uts, IMX21_UTS); } static void From patchwork Wed Feb 1 14:26:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Organov X-Patchwork-Id: 649607 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 57B2AC636D7 for ; Wed, 1 Feb 2023 14:27:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232026AbjBAO1r (ORCPT ); Wed, 1 Feb 2023 09:27:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232124AbjBAO1p (ORCPT ); Wed, 1 Feb 2023 09:27:45 -0500 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 870FD68AC3 for ; Wed, 1 Feb 2023 06:27:42 -0800 (PST) Received: by mail-ed1-x52e.google.com with SMTP id x7so14626797edr.0 for ; Wed, 01 Feb 2023 06:27:42 -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=K1xsYdRkbxOW0gYgS8BKK9rscyZO9LYOWHC1AclbwYuUnU5VVnQNYiP9s8Qzv49dOt VZKhDGe92Pgad9UXE9+mTsO4tFSSB5C97yrnjv3d1BuEjq3dL8UZl4gRcVM/iNvjcmpe MaXYtmd1ceEMrb8Kl04RVgJ091/GwGf7bnMioZQx22Di8b9Zi65t1du7Vg3PpycUkoIb JUl+bHqsDwjTnsrAO7atQWMTon4HOkPOgshVxxRULQ3NaI4tHoVspB1SIjHSCUsfMgnV ou2nC65ChWg/s4wQWu1rqgcg/zp51B9RoQWyi51onq6BkTm0Ac8Znv6WVPX1WKi5uogY cQIw== 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=cU+aqM91KGZaa00x5vPJpPeulWQmp3piqO1U6U/P4uqdANBnyTpNklGhTqzBriulgw aaW12maNtLzHGNfIicFT737fytVv9Q7ONxfXM8OyJMd5g+qelujBVesiatFFrnUzaSj0 IuhkjIprEbae9zlwbryusvZlkBK5P2G1GfuUtur2adGPQKXw3tf0C21pTQhJCEN3OTaH 7hW9l56PrEicJROeBg8V8ITC2vl7UjFG4nVMmhhk+FHeKEpVFBrJCHAFzM6yPbZyRuF2 zRTm9y10vyjD9yVwilKcaJq5UZl2Dw23V8zIkqDQhhmz+P1vjKjS9vVGiTmwkrbtfbSU /W2g== X-Gm-Message-State: AO0yUKWkiCM6WM/pB4o69T95Pv+K09v8CjfDek+u/gTrr3Z1KjKDqKHk D2PTouayDgsiNMIz5uybat0= X-Google-Smtp-Source: AK7set8MRay/4KmKUvccvdPoG83dTuDwt3q3ZbIm1GAwiPqy4nUgcodj++ljfSdIsLXuBfv8zZa4QQ== X-Received: by 2002:a05:6402:1950:b0:4a2:260f:3bbe with SMTP id f16-20020a056402195000b004a2260f3bbemr2606430edz.23.1675261660934; Wed, 01 Feb 2023 06:27:40 -0800 (PST) Received: from osv.localdomain ([89.175.180.246]) by smtp.gmail.com with ESMTPSA id cf8-20020a0564020b8800b004a18f2ffb86sm8975564edb.79.2023.02.01.06.27.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 06:27:40 -0800 (PST) From: Sergey Organov To: Greg Kroah-Hartman Cc: linux-serial@vger.kernel.org, Fabio Estevam , Jiri Slaby , Richard Genoud , Sascha Hauer , Shawn Guo , Tim Harvey , =?utf-8?q?Tomasz_Mo=C5=84?= , =?utf-8?q?Uwe_Kle?= =?utf-8?q?ine-K=C3=B6nig?= , Johan Hovold , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Sherry Sun , Stefan Wahren , linux-arm-kernel@lists.infradead.org, NXP Linux Team , Pengutronix Kernel Team , Sergey Organov Subject: [PATCH v1 2/7] serial: imx: work-around for hardware RX flood Date: Wed, 1 Feb 2023 17:26:55 +0300 Message-Id: <20230201142700.4346-3-sorganov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230201142700.4346-1-sorganov@gmail.com> References: <87bko4e65y.fsf@osv.gnss.ru> <20230201142700.4346-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 Wed Feb 1 14:26:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Organov X-Patchwork-Id: 649952 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 D8136C636CD for ; Wed, 1 Feb 2023 14:27:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232203AbjBAO1y (ORCPT ); Wed, 1 Feb 2023 09:27:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231923AbjBAO1r (ORCPT ); Wed, 1 Feb 2023 09:27:47 -0500 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3018F6813A for ; Wed, 1 Feb 2023 06:27:44 -0800 (PST) Received: by mail-ed1-x52e.google.com with SMTP id eq11so863031edb.6 for ; Wed, 01 Feb 2023 06:27: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=t9PFvNqNRiBtgoK1FQlt2dgZjVa65hIZ+MQtdwTOsMQ=; b=VuJERbKWYOkgt/D8s8FOfDHVNd9glpziOVsTG+1JjLTYT7jGJy1VkNDZTgK1e3AjMi uiTHC7h8eh40cm5Ey0iOSL2dpFDm/v98ZQMIex6y23PczBzbg88bVdaUZNd0WWg/0jOA JzycDx1+F+NmAh/FdYq0uN6t5s2s+R5IAZ0CchzXlf2wZRO593HSjQ8BJOyjxZ9HWs/i uQzPZWRRcgdGxyi/Z+02V/ktq/h+yh9NWIrVbclaJyzIOW5XSGww95ZnYMue7FOCrd9+ TUr+d6HsTGLjHygi10C1POXJ+GgaTvnL56wA9d+DVUKNX4J2/dVnsWp5U/y7xmxOeUQY vjTQ== 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=t9PFvNqNRiBtgoK1FQlt2dgZjVa65hIZ+MQtdwTOsMQ=; b=0y0m4n3SsH/0RYtRmDqFwFT4C8lFjaOP0ahXJ4z4Kc3dTh9xb1e4dr9RPhi7yC/ytR B6C6JdZda4eidGx7SVDHsWqIhyXkqG9tRCIXmJMCbF5mjSN5PtT+78psk2SeRlL2mRCS 0gfF3iZyQatiZKhWYeDU9OMdpGBk1HLvrkOxidAEHf0fwRxeRuN9Vd9qpV+ZuegRkU83 B0bjnboscnxrh5zSi4FQe+HPQNDESTjH3Qi749D96BNi87D0dqJZdd4szFozW2iwgKSs MooytjgfxxLjG9GUmbcbguql49i6hATTdEASOCCHgxDi9meojWbCh6KE8f+F7Zz5thGs Twhw== X-Gm-Message-State: AO0yUKX0qTlaoOZu4wZml1T8m/siNb80ACsz6C/34tPf5eWnvsjZYzQ4 xggi8QN1AG1d/qAFtsLmDNc= X-Google-Smtp-Source: AK7set9hYDxvOQi0xjHhLN/X3aYvdrUsus0F/Am0ploCUlkQQm6XutLDb+3FJsBgq+1sa7AWYzsHnw== X-Received: by 2002:a50:ccd3:0:b0:47a:e008:8662 with SMTP id b19-20020a50ccd3000000b0047ae0088662mr2526553edj.34.1675261662685; Wed, 01 Feb 2023 06:27:42 -0800 (PST) Received: from osv.localdomain ([89.175.180.246]) by smtp.gmail.com with ESMTPSA id cf8-20020a0564020b8800b004a18f2ffb86sm8975564edb.79.2023.02.01.06.27.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 06:27:42 -0800 (PST) From: Sergey Organov To: Greg Kroah-Hartman Cc: linux-serial@vger.kernel.org, Fabio Estevam , Jiri Slaby , Richard Genoud , Sascha Hauer , Shawn Guo , Tim Harvey , =?utf-8?q?Tomasz_Mo=C5=84?= , =?utf-8?q?Uwe_Kle?= =?utf-8?q?ine-K=C3=B6nig?= , Johan Hovold , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Sherry Sun , Stefan Wahren , linux-arm-kernel@lists.infradead.org, NXP Linux Team , Pengutronix Kernel Team , Sergey Organov Subject: [PATCH v1 3/7] serial: imx: do not sysrq broken chars Date: Wed, 1 Feb 2023 17:26:56 +0300 Message-Id: <20230201142700.4346-4-sorganov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230201142700.4346-1-sorganov@gmail.com> References: <87bko4e65y.fsf@osv.gnss.ru> <20230201142700.4346-1-sorganov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org Do not call uart_handle_sysrq_char() if we got any receive error along with the character, as we don't want random junk to be considered a sysrq. 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 e7fce31e460d..e709118fe85c 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -911,9 +911,6 @@ static irqreturn_t __imx_uart_rxint(int irq, void *dev_id) continue; } - if (uart_handle_sysrq_char(&sport->port, (unsigned char)rx)) - continue; - if (unlikely(rx & URXD_ERR)) { if (rx & URXD_BRK) sport->port.icount.brk++; @@ -942,6 +939,8 @@ static irqreturn_t __imx_uart_rxint(int irq, void *dev_id) flg = TTY_OVERRUN; sport->port.sysrq = 0; + } else if (uart_handle_sysrq_char(&sport->port, (unsigned char)rx)) { + continue; } if (sport->port.ignore_status_mask & URXD_DUMMY_READ) From patchwork Wed Feb 1 14:26:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Organov X-Patchwork-Id: 649606 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 BB5ECC05027 for ; Wed, 1 Feb 2023 14:27:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231923AbjBAO1z (ORCPT ); Wed, 1 Feb 2023 09:27:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232094AbjBAO1s (ORCPT ); Wed, 1 Feb 2023 09:27:48 -0500 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E58182CFD9 for ; Wed, 1 Feb 2023 06:27:45 -0800 (PST) Received: by mail-ed1-x534.google.com with SMTP id cw4so12728234edb.13 for ; Wed, 01 Feb 2023 06:27:45 -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=WEm5A99uTG2c238a+JDBkz/mOTpdwi/bBFV9FIiWCUw=; b=hqqEqTK0vARzjhmqa9hC6bsI/43ShQLK8//yNN4LKLiy2WkIGvyXDYZ2m8GwRYhND9 bDzPhj4P3JTMuOHV7ReCUIXnc+k2DCtkuR5WATi1e7simYqn/scDIwWxlbFDqU4KBPXa eZE33vSPuG4gKrpDbQf+ma7fIakaRy+/RXJ2rEjomknemkaxN2HKc5nAxtz5XIpuaRfe puxzpZUI8J04cDtaG4LZIeabkjgsApoH4KDJtMnW1DwWjeFb9Hm/LTHGGmNzxV//ZyrK HMNT3e/PUk/YtM9L+ZlZ5mRx45dDZ0cIiRwiQFQ6YUfQTutjE7IRwN5dxXFb9HS44Xh/ L0pA== 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=WEm5A99uTG2c238a+JDBkz/mOTpdwi/bBFV9FIiWCUw=; b=vSjJ4jvaruGwJGheJtCT2Wogo6XKdWHFYt0nLK9yH4OhHE4V1ZvxEvvPXOzBWOkXac ZhuiIu/Oe3F4eOj6eQSYlBfCmAU6HvcwlVFU5nU+yi3T3X6G5nYAX2tK1xYLaqouAUha kdvKR9JOsc6/qQkZ5REuVMcs3JcPcA8EhUxM1G6MB37dQRJ+dscIqPS191cmpMI3yvaz Pf4CJHdhSFt2zfktdZfaiyWS/leskFalE7hWKf08WK9uTk5Spx0v/Y2+tMPtj0UQwhQm s9MaTl7Njz6PVOk5mkjSEeBL/D60Y9bvVlcR5eahieHLAFys4q0nl1N0kRj7RTCHwPe0 bgWw== X-Gm-Message-State: AO0yUKU7GIT8C2Dk5dqdKRoJlOTETSe0C4NKpTdRtRQ0+996nM6zsAcc g2/lEPuG+iWelZr5DmcfX38= X-Google-Smtp-Source: AK7set8ws7NdcXePeM55LM4BT1j7mYwM+w20CWy2QWuufVGR25bLp8ZxOOgYCX5HpeGK6TKSRutHlA== X-Received: by 2002:aa7:de13:0:b0:499:d0e3:7745 with SMTP id h19-20020aa7de13000000b00499d0e37745mr2245544edv.14.1675261664352; Wed, 01 Feb 2023 06:27:44 -0800 (PST) Received: from osv.localdomain ([89.175.180.246]) by smtp.gmail.com with ESMTPSA id cf8-20020a0564020b8800b004a18f2ffb86sm8975564edb.79.2023.02.01.06.27.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 06:27:43 -0800 (PST) From: Sergey Organov To: Greg Kroah-Hartman Cc: linux-serial@vger.kernel.org, Fabio Estevam , Jiri Slaby , Richard Genoud , Sascha Hauer , Shawn Guo , Tim Harvey , =?utf-8?q?Tomasz_Mo=C5=84?= , =?utf-8?q?Uwe_Kle?= =?utf-8?q?ine-K=C3=B6nig?= , Johan Hovold , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Sherry Sun , Stefan Wahren , linux-arm-kernel@lists.infradead.org, NXP Linux Team , Pengutronix Kernel Team , Sergey Organov Subject: [PATCH v1 4/7] serial: imx: do not break from FIFO reading loop prematurely Date: Wed, 1 Feb 2023 17:26:57 +0300 Message-Id: <20230201142700.4346-5-sorganov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230201142700.4346-1-sorganov@gmail.com> References: <87bko4e65y.fsf@osv.gnss.ru> <20230201142700.4346-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 e709118fe85c..797c441088a9 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); @@ -944,13 +941,12 @@ static irqreturn_t __imx_uart_rxint(int irq, void *dev_id) } 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 Wed Feb 1 14:26:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Organov X-Patchwork-Id: 649951 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 9A2CDC636D7 for ; Wed, 1 Feb 2023 14:27:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232081AbjBAO14 (ORCPT ); Wed, 1 Feb 2023 09:27:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232124AbjBAO1t (ORCPT ); Wed, 1 Feb 2023 09:27:49 -0500 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A89B46811E for ; Wed, 1 Feb 2023 06:27:47 -0800 (PST) Received: by mail-ed1-x534.google.com with SMTP id z11so17876994ede.1 for ; Wed, 01 Feb 2023 06:27:47 -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=vxyxFeq00JGhfZF3lbLUVUOmxZ61KQdQmUjeiwFbgw8=; b=TqxSdo+txye/hH+JqDPj5+BHdWVeRBNc0K8jgGttCeHsb3yXb7k+vU36AzeDltqy3v 9tebe7abB0jDHhCl/7e23/HfrTJI4COPeIxtOr5YPWXChODWdRRPYf0PYmNpipTyH7fL CgQSOYJTfF9CPoRmwvjw9GJqQQXYOcPZA6v+4Z0lsfQmeJV52awQRXWerMbk4kjxrEf2 y2GCmwKDqMkTBpD6ik89DmR0SiIBG1cOdivGzo3YmgAGmExSu1BJsNXONBUgdZQPj1W6 EWiSXk4x18qkxpUHuHC1dZGe2bqT+kvHIPi2SWRSVWh2dS2mkDonCAPpdKGLx0UXaAWY 7New== 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=vxyxFeq00JGhfZF3lbLUVUOmxZ61KQdQmUjeiwFbgw8=; b=ECAHeCgglNzc79lXO9ocaLFMXUiBkBZIU6YZkAJLTZFh+eCmkpgXsUAHU1C1g7M8NK a7oHySA/Di4F+vFRm6/8N9JJiSUhDCsqLy9llHKjCrCJ5s+FMbAHE6KNElJZ6iY2RG59 FUXXge6XC1gN6NHWE4rpHRM29+jqfKyEDfcyeMSHJKSHQwMjjpgsUR3fuDfibsNqaQWg ajvfwuVMWWCRnqrfV7PkTBeRLoNZVBX/kdx78WfCW/AsXqOwjLbgE72x1foakbejXXT1 JaoMWEhez9xEkXosoSHt/Umv7L1z+IA298P7W3EmxrDNdt9jvK4XBIAl5Zw8MbT2j75I 27kw== X-Gm-Message-State: AO0yUKWpcJFOzjsFlfrLfIt9XdhQBAWqYAzkuFlcfTXZmn/yORbvJd4N DfzosjideMfcl4G+iYz0VvA= X-Google-Smtp-Source: AK7set/U/qA9uhgkckwtVXIcYK+eNjL8h6axhavdaN9OZUBKFGGYjKnPrkEhQ7UYDUf9udq8Ns6cYA== X-Received: by 2002:aa7:d0c6:0:b0:49b:4711:f4b4 with SMTP id u6-20020aa7d0c6000000b0049b4711f4b4mr2459599edo.0.1675261666145; Wed, 01 Feb 2023 06:27:46 -0800 (PST) Received: from osv.localdomain ([89.175.180.246]) by smtp.gmail.com with ESMTPSA id cf8-20020a0564020b8800b004a18f2ffb86sm8975564edb.79.2023.02.01.06.27.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 06:27:45 -0800 (PST) From: Sergey Organov To: Greg Kroah-Hartman Cc: linux-serial@vger.kernel.org, Fabio Estevam , Jiri Slaby , Richard Genoud , Sascha Hauer , Shawn Guo , Tim Harvey , =?utf-8?q?Tomasz_Mo=C5=84?= , =?utf-8?q?Uwe_Kle?= =?utf-8?q?ine-K=C3=B6nig?= , Johan Hovold , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Sherry Sun , Stefan Wahren , linux-arm-kernel@lists.infradead.org, NXP Linux Team , Pengutronix Kernel Team , Sergey Organov Subject: [PATCH v1 5/7] serial: imx: remove redundant USR2 read from FIFO reading loop Date: Wed, 1 Feb 2023 17:26:58 +0300 Message-Id: <20230201142700.4346-6-sorganov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230201142700.4346-1-sorganov@gmail.com> References: <87bko4e65y.fsf@osv.gnss.ru> <20230201142700.4346-1-sorganov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org There is no need to read USR2 twice at every loop iteration: get rid of the second read. Signed-off-by: Sergey Organov --- drivers/tty/serial/imx.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index 797c441088a9..af4349fe6970 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -904,7 +904,6 @@ static irqreturn_t __imx_uart_rxint(int irq, void *dev_id) rx = imx_uart_readl(sport, URXD0); - usr2 = imx_uart_readl(sport, USR2); if (usr2 & USR2_BRCD) { imx_uart_writel(sport, USR2_BRCD, USR2); if (uart_handle_break(&sport->port)) From patchwork Wed Feb 1 14:26:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Organov X-Patchwork-Id: 649605 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 F2914C636CD for ; Wed, 1 Feb 2023 14:27:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231463AbjBAO15 (ORCPT ); Wed, 1 Feb 2023 09:27:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232166AbjBAO1u (ORCPT ); Wed, 1 Feb 2023 09:27:50 -0500 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4ABA53FF2E for ; Wed, 1 Feb 2023 06:27:49 -0800 (PST) Received: by mail-ed1-x534.google.com with SMTP id q19so7921498edd.2 for ; Wed, 01 Feb 2023 06:27:49 -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=L5v/xKpmgx3IRd85qrBv3zwjvdUmTrkcJb9ZlFLMDeA=; b=DAPka0L/4I745c/qSKtgYk1wXpzL4moxASBPZFfPfq75oV0qTfjaY5x9Tjq2yLKzof 9fYKAsmN9k0Fu28gVIG26CnvnbN5z54z+r6oz//cPTtDMVEOS3BfzTiVwL01XNHicWV4 DZQxephCKADZIAC1Q9SxrKEAfSPvrBh9B2nakdG9VBvEBmRd57K2b+ZxN52HSbNy7jzT aGEtgbzC5XN2R/aO550nV1rLoUQiVvN9MMtxmFo7bzdT0gCE2CaCZIjNhte5mVq7BRRS sAJQNX1LkG1MKJv8q+g7yO5GvR3oqi09+nRxAFJYBhXLgCA/4LF5I/0WvLIDHIHTAwLH isbQ== 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=L5v/xKpmgx3IRd85qrBv3zwjvdUmTrkcJb9ZlFLMDeA=; b=e2zySTIbgxhIzMNvWM5o0W0ciHQTJhJjf0eNsM2Z4fSJvmcHZKclKpt1phNJVXB0pQ /FgTQ3StKm9DkbI1KrRcmAsh3QICO57/5zzj3MHgBtZQk3cPwcC4fyLOrsXtO78eYXEp ZLqOtNPfWLib6eZI1zsX52uTgK1kXXJhUaCJXu8S+PDoQYULQSgpiuT3hU7UCVg0zHmw fIqbN4dIakqbQHHVz7PNwddzfvVFbNRB4zT9cNtLPFPSMDH+okVBPUKarQsPXjK2m+Gl epUImmgF1eLNE6KcHlbdYZlpiTWjNSZiPuDQneSv6HhnchrWsyoumuAIi2ZKDCKnu42l fMEA== X-Gm-Message-State: AO0yUKXi4LhMucz/13YnxXUI55QGe6zkHwrl9jCQiz7vGcko2CBWXYOb gusiCEdWqJGFqPhIsaO86Z7nWTYPlWs= X-Google-Smtp-Source: AK7set9QcDJuAnQSBUBYWr27mdVAgUyXyUxUF978MjptXVS6Ji9xpOjDJa2P1X5QD2PbSZYITR2dBw== X-Received: by 2002:a05:6402:882:b0:499:b48b:2c3 with SMTP id e2-20020a056402088200b00499b48b02c3mr2062287edy.25.1675261667832; Wed, 01 Feb 2023 06:27:47 -0800 (PST) Received: from osv.localdomain ([89.175.180.246]) by smtp.gmail.com with ESMTPSA id cf8-20020a0564020b8800b004a18f2ffb86sm8975564edb.79.2023.02.01.06.27.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 06:27:47 -0800 (PST) From: Sergey Organov To: Greg Kroah-Hartman Cc: linux-serial@vger.kernel.org, Fabio Estevam , Jiri Slaby , Richard Genoud , Sascha Hauer , Shawn Guo , Tim Harvey , =?utf-8?q?Tomasz_Mo=C5=84?= , =?utf-8?q?Uwe_Kle?= =?utf-8?q?ine-K=C3=B6nig?= , Johan Hovold , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Sherry Sun , Stefan Wahren , linux-arm-kernel@lists.infradead.org, NXP Linux Team , Pengutronix Kernel Team , Sergey Organov Subject: [PATCH v1 6/7] serial: imx: stop using USR2 in FIFO reading loop Date: Wed, 1 Feb 2023 17:26:59 +0300 Message-Id: <20230201142700.4346-7-sorganov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230201142700.4346-1-sorganov@gmail.com> References: <87bko4e65y.fsf@osv.gnss.ru> <20230201142700.4346-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 af4349fe6970..488d8119562e 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 Wed Feb 1 14:27:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Organov X-Patchwork-Id: 649950 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 6F4ADC05027 for ; Wed, 1 Feb 2023 14:27:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232000AbjBAO15 (ORCPT ); Wed, 1 Feb 2023 09:27:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232024AbjBAO1w (ORCPT ); Wed, 1 Feb 2023 09:27:52 -0500 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 160CE68127 for ; Wed, 1 Feb 2023 06:27:51 -0800 (PST) Received: by mail-ed1-x533.google.com with SMTP id m8so8638980edd.10 for ; Wed, 01 Feb 2023 06:27: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=+fbiDWy8ZCeEEPo3XsRTUlzcMe3rsD7fkZwC6S0cFK0=; b=gAuVsJrYc7jh8ErBsEv3KC4ZC2oYJctZttWWSRj1FJ2yUsydorfPIcxfqxhbIpT+NM VJSNjFhzuhLo2iCXIi7JP/kh0sPKfPyNhxp1sLzCMpxDDUwxa1g6RoBiWpOfxmYEMUbk vI1ZbhbaGzTVCg5d2AYbxzQT6Lht/1pTHdceiMUoBc+/tEL6HzyozcGSM/9m37UR9aSn uPZx6Y6ve8uBCqK9loEjuNnqFTWU376VNeTQOrdvDp7xk67ltLLCH9OdKA/N4GUjzlmp RzmXlvs07ezYOghcZkzVgphJEiPqALOXtnVVN8SXtbvZyjnOFA+3dqltAwVIgr/rbMoc eDQw== 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=+fbiDWy8ZCeEEPo3XsRTUlzcMe3rsD7fkZwC6S0cFK0=; b=7tHZGnQZG3AZQ9/YbqXg0f1blmWUnJ3TsyPjRQhm0W+v4FGPjglba8eEOMJTdEfuJO RqY8Xw0Yo/uMToVsuwO6GruY5jgzWGdFJFPcMCyZq93NbAexRxAeNHAJcF9NW+A+qgrx VBI9VejZKQVBoBiybEffW6Byi9QnPQbLAypb+rIUbHvIC2+e9y8LcDNk0T7H+pWUBnI8 wFMqzPhMhD/yLE881HIISstookAMK5qC2wSQJ+Q+wat9++lb7C3nUXS5fEmiWsk288/J 5T2b/jWY7y/5+bcGJF831hdC2wNMnWWE3s0yvsr0FdO5Zud4IzWSaAvJ8ansOAVk5LRE KR1A== X-Gm-Message-State: AO0yUKVVbjf0rCRjSpYkQJzEaTzjazpnl3SLFdxeYON+pIpCnQNye6S4 lv69MBwu8Ow0mYgTc9NTAeG8nLaJdKI= X-Google-Smtp-Source: AK7set+Ldupr8odgypamg0BybQedrh29v5qHb8uwrB94NJrvfSbIEZzbyHzI9wwW8XEVlszcDIL6sg== X-Received: by 2002:a05:6402:1bcd:b0:472:9af1:163f with SMTP id ch13-20020a0564021bcd00b004729af1163fmr1833744edb.37.1675261669554; Wed, 01 Feb 2023 06:27:49 -0800 (PST) Received: from osv.localdomain ([89.175.180.246]) by smtp.gmail.com with ESMTPSA id cf8-20020a0564020b8800b004a18f2ffb86sm8975564edb.79.2023.02.01.06.27.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 06:27:49 -0800 (PST) From: Sergey Organov To: Greg Kroah-Hartman Cc: linux-serial@vger.kernel.org, Fabio Estevam , Jiri Slaby , Richard Genoud , Sascha Hauer , Shawn Guo , Tim Harvey , =?utf-8?q?Tomasz_Mo=C5=84?= , =?utf-8?q?Uwe_Kle?= =?utf-8?q?ine-K=C3=B6nig?= , Johan Hovold , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Sherry Sun , Stefan Wahren , linux-arm-kernel@lists.infradead.org, NXP Linux Team , Pengutronix Kernel Team , Sergey Organov Subject: [PATCH v1 7/7] serial: imx: refine local variables in rxint() Date: Wed, 1 Feb 2023 17:27:00 +0300 Message-Id: <20230201142700.4346-8-sorganov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230201142700.4346-1-sorganov@gmail.com> References: <87bko4e65y.fsf@osv.gnss.ru> <20230201142700.4346-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 488d8119562e..447b9060d9df 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -888,9 +888,8 @@ 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; - u32 usr2; + u32 usr2, rx; /* If we received something, check for 0xff flood */ usr2 = imx_uart_readl(sport, USR2); @@ -898,7 +897,7 @@ static irqreturn_t __imx_uart_rxint(int irq, void *dev_id) imx_uart_check_flood(sport, usr2); while ((rx = imx_uart_readl(sport, URXD0)) & URXD_CHARRDY) { - flg = TTY_NORMAL; + unsigned int flg = TTY_NORMAL; sport->port.icount.rx++; if (unlikely(rx & URXD_ERR)) {