From patchwork Thu Sep 1 14:39:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ilpo_J=C3=A4rvinen?= X-Patchwork-Id: 602146 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 9FA23C64991 for ; Thu, 1 Sep 2022 14:39:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234053AbiIAOjy (ORCPT ); Thu, 1 Sep 2022 10:39:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233889AbiIAOjw (ORCPT ); Thu, 1 Sep 2022 10:39:52 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E145266D; Thu, 1 Sep 2022 07:39:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1662043189; x=1693579189; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WNwFYsnxejnsb3PAJO0FgVsTN5fGGjYc+Bh4CgV230I=; b=XJhOR5DT38D0jb/z6qjrV6WOxbJi8dpuIERH2wLNqS0G4ysjbADNSW+C Qv5GqHBZVWrFltE9hrm8Rkyc1Uqavoun1SphEM0R1EgM17kbSKLKX2jow TGeI66/PCh/Th+TEBTN56HaETGtX1Bs6gSgQcGZsgLN8X7RB5Hzr0FQMy Vxzc1sWedjPviUMop8IZ6BXTB16/MqfC9bH47ohIuGinwejM7qzfuECD+ IRpBF37LZAoaONiUQVWbKRvJYhnVcdDTjfisMi9zW3omLr9KuugNs1keQ Yad1eelG2gknckpN5sjNBDoOP1dkMiCuPkq5UEOfsT9DWs1efQlkWQaKz w==; X-IronPort-AV: E=McAfee;i="6500,9779,10457"; a="321880096" X-IronPort-AV: E=Sophos;i="5.93,281,1654585200"; d="scan'208";a="321880096" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Sep 2022 07:39:49 -0700 X-IronPort-AV: E=Sophos;i="5.93,281,1654585200"; d="scan'208";a="642356651" Received: from rmalliu-mobl.amr.corp.intel.com (HELO ijarvine-MOBL2.ger.corp.intel.com) ([10.249.44.65]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Sep 2022 07:39:46 -0700 From: =?utf-8?q?Ilpo_J=C3=A4rvinen?= To: Greg Kroah-Hartman , Jiri Slaby , linux-serial@vger.kernel.org, Andy Shevchenko , linux-kernel@vger.kernel.org Cc: =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Andy Shevchenko Subject: [PATCH v2 RESEND 1/3] serial: Create uart_xmit_advance() Date: Thu, 1 Sep 2022 17:39:32 +0300 Message-Id: <20220901143934.8850-2-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220901143934.8850-1-ilpo.jarvinen@linux.intel.com> References: <20220901143934.8850-1-ilpo.jarvinen@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org A very common pattern in the drivers is to advance xmit tail index and do bookkeeping of Tx'ed characters. Create uart_xmit_advance() to handle it. Reviewed-by: Andy Shevchenko Signed-off-by: Ilpo Järvinen --- include/linux/serial_core.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h index aef3145f2032..ffc7b8cb7a7f 100644 --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h @@ -616,6 +616,23 @@ struct uart_state { /* number of characters left in xmit buffer before we ask for more */ #define WAKEUP_CHARS 256 +/** + * uart_xmit_advance - Advance xmit buffer and account Tx'ed chars + * @up: uart_port structure describing the port + * @chars: number of characters sent + * + * This function advances the tail of circular xmit buffer by the number of + * @chars transmitted and handles accounting of transmitted bytes (into + * @up's icount.tx). + */ +static inline void uart_xmit_advance(struct uart_port *up, unsigned int chars) +{ + struct circ_buf *xmit = &up->state->xmit; + + xmit->tail = (xmit->tail + chars) & (UART_XMIT_SIZE - 1); + up->icount.tx += chars; +} + struct module; struct tty_driver; From patchwork Thu Sep 1 14:39:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ilpo_J=C3=A4rvinen?= X-Patchwork-Id: 602722 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 5080FECAAD3 for ; Thu, 1 Sep 2022 14:40:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234475AbiIAOkF (ORCPT ); Thu, 1 Sep 2022 10:40:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233808AbiIAOj6 (ORCPT ); Thu, 1 Sep 2022 10:39:58 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF37E5FBA; Thu, 1 Sep 2022 07:39:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1662043197; x=1693579197; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jlOuWqXv3W1+nK5gEHgXZ0S9vII+w0v5W+k4c+5u558=; b=LWhEGaS192pV68s6tvCPsqbsL/IGxA/QTx1mPdDSZG3eqDxvRjzoJycv EGLzvzK+wRwAbffRygl45L+gvsOx5q2rBUdFdIdWYgCV/K7PI1eyBF/Pf 5UThP9xQ619moO/1feja22r7CIwRyKoDxmwH2RyBlTmvulShIxMxrGUuZ J4ukkmY8KHtVQzJmdKmOX8aFkBt7M7G1gaPt6o+j2mfnrRTT60K2xiQjr hqSS7p2MQ/L+gQLPDX0lLG74H/cRqtan4km3ByYFcDib/U9M1dgs7gA8v 4dmUgBxo7kBPWNdtti+MSMY6B3wY9UGsgvB410NTzbMGZt3XL62iErFit g==; X-IronPort-AV: E=McAfee;i="6500,9779,10457"; a="359690403" X-IronPort-AV: E=Sophos;i="5.93,281,1654585200"; d="scan'208";a="359690403" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Sep 2022 07:39:55 -0700 X-IronPort-AV: E=Sophos;i="5.93,281,1654585200"; d="scan'208";a="642356668" Received: from rmalliu-mobl.amr.corp.intel.com (HELO ijarvine-MOBL2.ger.corp.intel.com) ([10.249.44.65]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Sep 2022 07:39:50 -0700 From: =?utf-8?q?Ilpo_J=C3=A4rvinen?= To: Greg Kroah-Hartman , Jiri Slaby , linux-serial@vger.kernel.org, Andy Shevchenko , Laxman Dewangan , Thierry Reding , Jonathan Hunter , Stephen Warren , Alan Cox , linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?utf-8?q?Ilpo_J=C3=A4rvinen?= , stable@vger.kernel.org, Andy Shevchenko Subject: [PATCH v2 RESEND 2/3] serial: tegra: Use uart_xmit_advance(), fixes icount.tx accounting Date: Thu, 1 Sep 2022 17:39:33 +0300 Message-Id: <20220901143934.8850-3-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220901143934.8850-1-ilpo.jarvinen@linux.intel.com> References: <20220901143934.8850-1-ilpo.jarvinen@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org DMA complete & stop paths did not correctly account Tx'ed characters into icount.tx. Using uart_xmit_advance() fixes the problem. Cc: # serial: Create uart_xmit_advance() Fixes: e9ea096dd225 ("serial: tegra: add serial driver") Reviewed-by: Andy Shevchenko Signed-off-by: Ilpo Järvinen --- drivers/tty/serial/serial-tegra.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/tty/serial/serial-tegra.c b/drivers/tty/serial/serial-tegra.c index ad4f3567ff90..a5748e41483b 100644 --- a/drivers/tty/serial/serial-tegra.c +++ b/drivers/tty/serial/serial-tegra.c @@ -525,7 +525,7 @@ static void tegra_uart_tx_dma_complete(void *args) count = tup->tx_bytes_requested - state.residue; async_tx_ack(tup->tx_dma_desc); spin_lock_irqsave(&tup->uport.lock, flags); - xmit->tail = (xmit->tail + count) & (UART_XMIT_SIZE - 1); + uart_xmit_advance(&tup->uport, count); tup->tx_in_progress = 0; if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) uart_write_wakeup(&tup->uport); @@ -613,7 +613,6 @@ static unsigned int tegra_uart_tx_empty(struct uart_port *u) static void tegra_uart_stop_tx(struct uart_port *u) { struct tegra_uart_port *tup = to_tegra_uport(u); - struct circ_buf *xmit = &tup->uport.state->xmit; struct dma_tx_state state; unsigned int count; @@ -624,7 +623,7 @@ static void tegra_uart_stop_tx(struct uart_port *u) dmaengine_tx_status(tup->tx_dma_chan, tup->tx_cookie, &state); count = tup->tx_bytes_requested - state.residue; async_tx_ack(tup->tx_dma_desc); - xmit->tail = (xmit->tail + count) & (UART_XMIT_SIZE - 1); + uart_xmit_advance(&tup->uport, count); tup->tx_in_progress = 0; } From patchwork Thu Sep 1 14:39:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ilpo_J=C3=A4rvinen?= X-Patchwork-Id: 602145 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 6E022ECAAD3 for ; Thu, 1 Sep 2022 14:40:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234949AbiIAOkZ (ORCPT ); Thu, 1 Sep 2022 10:40:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234921AbiIAOkS (ORCPT ); Thu, 1 Sep 2022 10:40:18 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 695742BB33; Thu, 1 Sep 2022 07:40:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1662043206; x=1693579206; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=esWDLWdVUmofxHacNDJ2TfKXCQbNLSqrTFIBVUEvytQ=; b=AWwHUs6XmAs8XyA3YI4lSCzxDlQ+eUJ20cBFBKz4peRxDT32wYS+euKD +p/36cVElFCNGlel0dRDf2bsQ1YvIJVRIy3FnVeDmoTfzzSgdCh7Xio1c JIAXZBeoc1M1kz9z9ucRg3TNQcW3Gg3MA35nvYfdu2z0+wY43KLGKihAM r+mJOEe1LOmXhqx9inIEq1yWZvro3630MUYWWJdDbEneDVEGSl+f4DMLF j/1dWi6ynyZAQlLrmPpncq5agUnOr8GTwxaGeahTQ7Nuzkj5RcVLwRCI9 pFHedv9VTwRGwduKQPxqlkfz8CVylMCBrPop+qb4zzGHDhTiNIuDDRHyb A==; X-IronPort-AV: E=McAfee;i="6500,9779,10457"; a="297014837" X-IronPort-AV: E=Sophos;i="5.93,281,1654585200"; d="scan'208";a="297014837" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Sep 2022 07:40:03 -0700 X-IronPort-AV: E=Sophos;i="5.93,281,1654585200"; d="scan'208";a="642356704" Received: from rmalliu-mobl.amr.corp.intel.com (HELO ijarvine-MOBL2.ger.corp.intel.com) ([10.249.44.65]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Sep 2022 07:39:57 -0700 From: =?utf-8?q?Ilpo_J=C3=A4rvinen?= To: Greg Kroah-Hartman , Jiri Slaby , linux-serial@vger.kernel.org, Andy Shevchenko , Thierry Reding , Jonathan Hunter , linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?utf-8?q?Ilpo_J=C3=A4rvinen?= , stable@vger.kernel.org, Andy Shevchenko Subject: [PATCH v2 RESEND 3/3] serial: tegra-tcu: Use uart_xmit_advance(), fixes icount.tx accounting Date: Thu, 1 Sep 2022 17:39:34 +0300 Message-Id: <20220901143934.8850-4-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220901143934.8850-1-ilpo.jarvinen@linux.intel.com> References: <20220901143934.8850-1-ilpo.jarvinen@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org Tx'ing does not correctly account Tx'ed characters into icount.tx. Using uart_xmit_advance() fixes the problem. Cc: # serial: Create uart_xmit_advance() Fixes: 2d908b38d409 ("serial: Add Tegra Combined UART driver") Reviewed-by: Andy Shevchenko Signed-off-by: Ilpo Järvinen --- drivers/tty/serial/tegra-tcu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/tty/serial/tegra-tcu.c b/drivers/tty/serial/tegra-tcu.c index 4877c54c613d..889b701ba7c6 100644 --- a/drivers/tty/serial/tegra-tcu.c +++ b/drivers/tty/serial/tegra-tcu.c @@ -101,7 +101,7 @@ static void tegra_tcu_uart_start_tx(struct uart_port *port) break; tegra_tcu_write(tcu, &xmit->buf[xmit->tail], count); - xmit->tail = (xmit->tail + count) & (UART_XMIT_SIZE - 1); + uart_xmit_advance(port, count); } uart_write_wakeup(port);