From patchwork Tue May 3 08:06:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 569251 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 2B7A2C433F5 for ; Tue, 3 May 2022 08:06:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232233AbiECIJs (ORCPT ); Tue, 3 May 2022 04:09:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232619AbiECIJr (ORCPT ); Tue, 3 May 2022 04:09:47 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64A4E20F5A; Tue, 3 May 2022 01:06:15 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 1CFE9210E5; Tue, 3 May 2022 08:06:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1651565174; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ECu5gs4Na4QCx3MdAZscC5hEAd3uD+930KihhgMqo+g=; b=0t0WBLkRPpnbG5Rz/Q0xOIzDEvzKG6LcU1ZOE/l1sdQVgXdq9v/DmJpdnFNkepgTjiEARx 5ACVvNNwo5QYiItuZMVvSKtSLzhxRGEEwQ3bzXD0/KO7Y2C0SoBQuX3VM5wV50Tyqv+XbI 4wcEXjdg28GfPG51QWjlHxJbGT+/A7Q= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1651565174; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ECu5gs4Na4QCx3MdAZscC5hEAd3uD+930KihhgMqo+g=; b=rKX81hd2r72cG0nw9Qh5hiQE9cvWFh2FyS1S/LKNd9V+r0msD1fuOmFfK7hHYRGGABSxz2 B4hWKKeRmGnmcPCg== Received: from localhost.localdomain (unknown [10.100.208.98]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id E67922C143; Tue, 3 May 2022 08:06:13 +0000 (UTC) From: Jiri Slaby To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Jiri Slaby Subject: [PATCH 1/7] serial: pch: move size check from pop_tx one level up Date: Tue, 3 May 2022 10:06:07 +0200 Message-Id: <20220503080613.27601-2-jslaby@suse.cz> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220503080613.27601-1-jslaby@suse.cz> References: <20220503080613.27601-1-jslaby@suse.cz> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org 'count' is zero in the pop_tx()'s comparison against 'size'. So the 'if' tries to find out if 'size' is negative or zero and returns in that case. But it cannot be negative, due to previous (size < 0) check in the caller: handle_tx(). So simply move this check from pop_tx() to handle_tx(). Now it's clear that pop_tx() is called only if fifo_size is non-zero. Signed-off-by: Jiri Slaby --- drivers/tty/serial/pch_uart.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/tty/serial/pch_uart.c b/drivers/tty/serial/pch_uart.c index affe71f8b50c..f872613a5e83 100644 --- a/drivers/tty/serial/pch_uart.c +++ b/drivers/tty/serial/pch_uart.c @@ -791,7 +791,7 @@ static int pop_tx(struct eg20t_port *priv, int size) struct uart_port *port = &priv->port; struct circ_buf *xmit = &port->state->xmit; - if (uart_tx_stopped(port) || uart_circ_empty(xmit) || count >= size) + if (uart_tx_stopped(port) || uart_circ_empty(xmit)) goto pop_tx_end; do { @@ -895,14 +895,16 @@ static unsigned int handle_tx(struct eg20t_port *priv) tx_empty = 0; fifo_size--; } + size = min(xmit->head - xmit->tail, fifo_size); if (size < 0) size = fifo_size; - - tx_size = pop_tx(priv, size); - if (tx_size > 0) { - port->icount.tx += tx_size; - tx_empty = 0; + if (size) { + tx_size = pop_tx(priv, size); + if (tx_size > 0) { + port->icount.tx += tx_size; + tx_empty = 0; + } } priv->tx_empty = tx_empty; From patchwork Tue May 3 08:08:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 569250 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 D47A8C433FE for ; Tue, 3 May 2022 08:08:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232613AbiECILr (ORCPT ); Tue, 3 May 2022 04:11:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231615AbiECILm (ORCPT ); Tue, 3 May 2022 04:11:42 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE86020F5A; Tue, 3 May 2022 01:08:10 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id AA8B71F38D; Tue, 3 May 2022 08:08:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1651565289; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oST/6quGVTIG/7AvfcWNH38FZA1053Lg8E80M28hIlc=; b=H4xE8wA5fckN+Z4Je/Ts5TWK5x0Uz8u2ZtsbUjkdnIsdPTEoS2rb3XyqaaQ3NNMm0seFjs gFvLO+ko5yV89qhlCKe67iXUq0vHg/YEwpBbT1K4XfHawI0K4i3evBT0pAxNz79rwkQbh3 rooj+gisWI4p5shVnL5+zdtT4QEQeog= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1651565289; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oST/6quGVTIG/7AvfcWNH38FZA1053Lg8E80M28hIlc=; b=OUh3Dw3uztirtLxjjR2TiRQy1JFxB/x5riKuW6coGs3afgkOccgukgFNpjPpuafpPW95gC 2g9TmBdAHY777MAQ== Received: from localhost.localdomain (unknown [10.100.208.98]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 79BF72C142; Tue, 3 May 2022 08:08:09 +0000 (UTC) From: Jiri Slaby To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Jiri Slaby , stable@vger.kernel.org Subject: [PATCH 2/7] serial: pch: don't overwrite xmit->buf[0] by x_char Date: Tue, 3 May 2022 10:08:03 +0200 Message-Id: <20220503080808.28332-1-jslaby@suse.cz> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220503080613.27601-1-jslaby@suse.cz> References: <20220503080613.27601-1-jslaby@suse.cz> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org When x_char is to be sent, the TX path overwrites whatever is in the circular buffer at offset 0 with x_char and sends it using pch_uart_hal_write(). I don't understand how this was supposed to work if xmit->buf[0] already contained some character. It must have been lost. Remove this whole pop_tx_x() concept and do the work directly in the callers. (Without printing anything using dev_dbg().) Cc: Fixes: 3c6a483275f4 (Serial: EG20T: add PCH_UART driver) Signed-off-by: Jiri Slaby --- drivers/tty/serial/pch_uart.c | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/drivers/tty/serial/pch_uart.c b/drivers/tty/serial/pch_uart.c index f872613a5e83..6cb631487383 100644 --- a/drivers/tty/serial/pch_uart.c +++ b/drivers/tty/serial/pch_uart.c @@ -624,22 +624,6 @@ static int push_rx(struct eg20t_port *priv, const unsigned char *buf, return 0; } -static int pop_tx_x(struct eg20t_port *priv, unsigned char *buf) -{ - int ret = 0; - struct uart_port *port = &priv->port; - - if (port->x_char) { - dev_dbg(priv->port.dev, "%s:X character send %02x (%lu)\n", - __func__, port->x_char, jiffies); - buf[0] = port->x_char; - port->x_char = 0; - ret = 1; - } - - return ret; -} - static int dma_push_rx(struct eg20t_port *priv, int size) { int room; @@ -889,9 +873,10 @@ static unsigned int handle_tx(struct eg20t_port *priv) fifo_size = max(priv->fifo_size, 1); tx_empty = 1; - if (pop_tx_x(priv, xmit->buf)) { - pch_uart_hal_write(priv, xmit->buf, 1); + if (port->x_char) { + pch_uart_hal_write(priv, &port->x_char, 1); port->icount.tx++; + port->x_char = 0; tx_empty = 0; fifo_size--; } @@ -948,9 +933,11 @@ static unsigned int dma_handle_tx(struct eg20t_port *priv) } fifo_size = max(priv->fifo_size, 1); - if (pop_tx_x(priv, xmit->buf)) { - pch_uart_hal_write(priv, xmit->buf, 1); + + if (port->x_char) { + pch_uart_hal_write(priv, &port->x_char, 1); port->icount.tx++; + port->x_char = 0; fifo_size--; } From patchwork Tue May 3 08:08:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 569249 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 13D6DC433EF for ; Tue, 3 May 2022 08:08:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232621AbiECILw (ORCPT ); Tue, 3 May 2022 04:11:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231915AbiECILm (ORCPT ); Tue, 3 May 2022 04:11:42 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9054020F6D; Tue, 3 May 2022 01:08:11 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 4FA781F74A; Tue, 3 May 2022 08:08:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1651565290; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=15tooGNI+BBIugcRnBOXnwdLyWnVLkW9CS3+fD7edxg=; b=FvKTjqXnjeH0EkWFVpvCZ26JsNjCWPWdv/uCfXBvo30wDiNk1yl3Zg0JEbC19QjD4piKyK IsObjth+vP1w5nKV93UVW71k9Y48kuNgDXLTBbtGirzB2VEs0ILCJTzcsPYVy7TD1EMdm1 WtkOGtlXZuhQj6KQ/m5+jjHki2MsTSM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1651565290; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=15tooGNI+BBIugcRnBOXnwdLyWnVLkW9CS3+fD7edxg=; b=7Or1Z0e76JolPn02tdG223lguF4BEGNkBsRQ5Mv8sPnOCkTT4pIU8lMFzBMqv3hgcJBCNF ldQwshMv1LuFqvAg== Received: from localhost.localdomain (unknown [10.100.208.98]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 1C79C2C142; Tue, 3 May 2022 08:08:10 +0000 (UTC) From: Jiri Slaby To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Jiri Slaby Subject: [PATCH 4/7] serial: pch: remove debug print from pop_tx Date: Tue, 3 May 2022 10:08:05 +0200 Message-Id: <20220503080808.28332-3-jslaby@suse.cz> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220503080808.28332-1-jslaby@suse.cz> References: <20220503080613.27601-1-jslaby@suse.cz> <20220503080808.28332-1-jslaby@suse.cz> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org It makes the code overly complicated for no good reason. Signed-off-by: Jiri Slaby --- drivers/tty/serial/pch_uart.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/drivers/tty/serial/pch_uart.c b/drivers/tty/serial/pch_uart.c index 4fcb6c144b54..a90bdff60908 100644 --- a/drivers/tty/serial/pch_uart.c +++ b/drivers/tty/serial/pch_uart.c @@ -764,7 +764,7 @@ static bool pop_tx(struct eg20t_port *priv, unsigned int size) struct circ_buf *xmit = &port->state->xmit; if (uart_tx_stopped(port)) - goto pop_tx_end; + return false; while (!uart_circ_empty(xmit) && count < size) { iowrite8(xmit->buf[xmit->tail], priv->membase + PCH_UART_THR); @@ -773,10 +773,6 @@ static bool pop_tx(struct eg20t_port *priv, unsigned int size) count++; } -pop_tx_end: - dev_dbg(priv->port.dev, "%d characters. Remained %d characters.(%lu)\n", - count, size - count, jiffies); - return count; } From patchwork Tue May 3 08:08:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 569248 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 DDE77C433EF for ; Tue, 3 May 2022 08:08:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232655AbiECILz (ORCPT ); Tue, 3 May 2022 04:11:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232260AbiECILn (ORCPT ); Tue, 3 May 2022 04:11:43 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31B4A20F7B; Tue, 3 May 2022 01:08:12 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id D78FF1F74D; Tue, 3 May 2022 08:08:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1651565290; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=skhWprJCJ9t6aVTQc28O4ZVcV9NM7tx+rRuIGq1wdK8=; b=KJyGJXf/KNj47pQAJa51hizUKGF/rUo3yyva6EIxtov2pyh/MG8TGF7eKLMrir3oKSNXX9 zpb7mHzVa6Fqfa/FFYnk4QWZRE9vYHAP91sM5JlOPmMGqp7+HJ24AoQg5Z/zjmO/ScT976 2LuIDKq0DuNnNrS7tB8oFHFXBMpYbp0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1651565290; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=skhWprJCJ9t6aVTQc28O4ZVcV9NM7tx+rRuIGq1wdK8=; b=w0BM0TlC7C3V6PVXQtAeRKGEQSr9oesqQWMotY9BIpcO7RSLlctQnlGOmWckm6jlWudcU7 Gq5IbV4MiJQLDrCg== Received: from localhost.localdomain (unknown [10.100.208.98]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id A664A2C145; Tue, 3 May 2022 08:08:10 +0000 (UTC) From: Jiri Slaby To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Jiri Slaby Subject: [PATCH 6/7] serial: pch: simplify pop_tx() even more Date: Tue, 3 May 2022 10:08:07 +0200 Message-Id: <20220503080808.28332-5-jslaby@suse.cz> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220503080808.28332-1-jslaby@suse.cz> References: <20220503080613.27601-1-jslaby@suse.cz> <20220503080808.28332-1-jslaby@suse.cz> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org 1) take uart_tx_stopped into account every loop (the same as other uart drivers) 2) no need for 'count' variable, operate on 'size' directly This allows inlining this into handle_tx() nicely in the next patch. Signed-off-by: Jiri Slaby --- drivers/tty/serial/pch_uart.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/drivers/tty/serial/pch_uart.c b/drivers/tty/serial/pch_uart.c index ae1d6b641253..e1eadf519089 100644 --- a/drivers/tty/serial/pch_uart.c +++ b/drivers/tty/serial/pch_uart.c @@ -759,21 +759,19 @@ static void pch_dma_tx_complete(void *arg) static bool pop_tx(struct eg20t_port *priv, unsigned int size) { - unsigned int count = 0; struct uart_port *port = &priv->port; struct circ_buf *xmit = &port->state->xmit; + bool ret = false; - if (uart_tx_stopped(port)) - return false; - - while (!uart_circ_empty(xmit) && count < size) { + while (!uart_tx_stopped(port) && !uart_circ_empty(xmit) && size) { iowrite8(xmit->buf[xmit->tail], priv->membase + PCH_UART_THR); xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); port->icount.tx++; - count++; + size--; + ret = true; } - return count; + return ret; } static int handle_rx_to(struct eg20t_port *priv)