From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9154E1E47B1; Fri, 8 Nov 2024 10:57:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731063448; cv=none; b=bZhOsh2xzlPb9rMDZxTPs4IVPDzeYJQIdAj5Q8fiNGSFl//y2b0Dc+c8Evn/XOwOPiZuOc7zgOdmmsD09VyIb+ApL18kpBvNYaOTuJDsEmEPGQ8/D9aYYCoKRKbix146suXDJsx1FzSQsgdJ3xs8N80bpdjZoddfBUlaoog9LJU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731063448; c=relaxed/simple; bh=nSKeP6CGVnbkOcjL45x796X6zEZ+6MU3W7LAshyiAl0=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=nW2yUQHwzQdqL39AzwX5NIZBh/HqifY5j24ABpuwWzEGgbIKIDE29ISeINU7tUMO8K9xYqc6+GNQvgyTblmrIk/p/jJhyWLareT/y3xEsdja0WpIjegYpgtY5iKhJwQZDA1a+nlMtrjDcyFz8F5JREKCAp86N2YjmVW2d2jtrIA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=taXXCwSk; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="taXXCwSk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 73495C4CECD; Fri, 8 Nov 2024 10:57:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731063448; bh=nSKeP6CGVnbkOcjL45x796X6zEZ+6MU3W7LAshyiAl0=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=taXXCwSk7If23gLZMvrLibGG0PzweX8z96AMnWqWNkxkmxDkOE5jSwFXL53RjM0qH R7FD4+cof4x+T9IwnHo+TRscHzvBJJMLRIa7D+gnW4J6W9mEEye2PQy5QVDwcn13Vx xwZKlihJJ41um9JI/3Gf5zMplkAXkno3fxFH4TUDjnpAT1LBz2VeahdrAms+lrxvaa XztlC29/Xr/UQbjmIpX30KapZDzd00Nb+jMO4x7jZEBf4PGyTiHpQ2HsoocBMOQJck 5Ns8xKmZQJfoniZJCP8U5+fdorK/2u7mhn09kXmTEJZH9v6Fu++CoLL2obH94UzNne NVXL16SCg8YcQ== Message-ID: <530f4a8e-b71a-4db1-a2cc-df1fcfa132ec@kernel.org> Date: Fri, 8 Nov 2024 11:57:22 +0100 Precedence: bulk X-Mailing-List: linux-clk@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 2/8] serial: sh-sci: Check if TX data was written to device in .tx_empty() To: Claudiu , geert+renesas@glider.be, magnus.damm@gmail.com, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, mturquette@baylibre.com, sboyd@kernel.org, gregkh@linuxfoundation.org, p.zabel@pengutronix.de, g.liakhovetski@gmx.de, lethal@linux-sh.org Cc: linux-renesas-soc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, linux-serial@vger.kernel.org, Claudiu Beznea , stable@vger.kernel.org References: <20241108100513.2814957-1-claudiu.beznea.uj@bp.renesas.com> <20241108100513.2814957-3-claudiu.beznea.uj@bp.renesas.com> Content-Language: en-US From: Jiri Slaby Autocrypt: addr=jirislaby@kernel.org; keydata= xsFNBE6S54YBEACzzjLwDUbU5elY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mzH0HjZZtXjGu2KLJ18G07q0fpz2ZPk2D53Ww39VNI/J9ABEBAAHCwV8EGAECAAkFAk6S 54YCGwwACgkQvSWxBAa0cEk3tRAAgO+DFpbyIa4RlnfpcW17AfnpZi9VR5+zr496n2jH/1ld wRO/S+QNSA8qdABqMb9WI4BNaoANgcg0AS429Mq0taaWKkAjkkGAT7mD1Q5PiLr06Y/+Kzdr 90eUVneqM2TUQQbK+Kh7JwmGVrRGNqQrDk+gRNvKnGwFNeTkTKtJ0P8jYd7P1gZb9Fwj9YLx jhn/sVIhNmEBLBoI7PL+9fbILqJPHgAwW35rpnq4f/EYTykbk1sa13Tav6btJ+4QOgbcezWI wZ5w/JVfEJW9JXp3BFAVzRQ5nVrrLDAJZ8Y5ioWcm99JtSIIxXxt9FJaGc1Bgsi5K/+dyTKL wLMJgiBzbVx8G+fCJJ9YtlNOPWhbKPlrQ8+AY52Aagi9WNhe6XfJdh5g6ptiOILm330mkR4g W6nEgZVyIyTq3ekOuruftWL99qpP5zi+eNrMmLRQx9iecDNgFr342R9bTDlb1TLuRb+/tJ98 f/bIWIr0cqQmqQ33FgRhrG1+Xml6UXyJ2jExmlO8JljuOGeXYh6ZkIEyzqzffzBLXZCujlYQ DFXpyMNVJ2ZwPmX2mWEoYuaBU0JN7wM+/zWgOf2zRwhEuD3A2cO2PxoiIfyUEfB9SSmffaK/ S4xXoB6wvGENZ85Hg37C7WDNdaAt6Xh2uQIly5grkgvWppkNy4ZHxE+jeNsU7tg= In-Reply-To: <20241108100513.2814957-3-claudiu.beznea.uj@bp.renesas.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 08. 11. 24, 11:05, Claudiu wrote: > From: Claudiu Beznea > > On the Renesas RZ/G3S, when doing suspend to RAM, the uart_suspend_port() > is called. The uart_suspend_port() calls 3 times the > struct uart_port::ops::tx_empty() before shutting down the port. > > According to the documentation, the struct uart_port::ops::tx_empty() > API tests whether the transmitter FIFO and shifter for the port is > empty. > > The Renesas RZ/G3S SCIFA IP reports the number of data units stored in the > transmit FIFO through the FDR (FIFO Data Count Register). The data units > in the FIFOs are written in the shift register and transmitted from there. > The TEND bit in the Serial Status Register reports if the data was > transmitted from the shift register. > > In the previous code, in the tx_empty() API implemented by the sh-sci > driver, it is considered that the TX is empty if the hardware reports the > TEND bit set and the number of data units in the FIFO is zero. > > According to the HW manual, the TEND bit has the following meaning: > > 0: Transmission is in the waiting state or in progress. > 1: Transmission is completed. > > It has been noticed that when opening the serial device w/o using it and > then switch to a power saving mode, the tx_empty() call in the > uart_port_suspend() function fails, leading to the "Unable to drain > transmitter" message being printed on the console. This is because the > TEND=0 if nothing has been transmitted and the FIFOs are empty. As the > TEND=0 has double meaning (waiting state, in progress) we can't > determined the scenario described above. > > Add a software workaround for this. This sets a variable if any data has > been sent on the serial console (when using PIO) or if the DMA callback has > been called (meaning something has been transmitted). > > Fixes: 73a19e4c0301 ("serial: sh-sci: Add DMA support.") > Cc: stable@vger.kernel.org > Signed-off-by: Claudiu Beznea > --- > > Changes in v2: > - use bool type instead of atomic_t > > drivers/tty/serial/sh-sci.c | 11 +++++++++++ > 1 file changed, 11 insertions(+) > > diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c > index 136e0c257af1..65514d37bfe2 100644 > --- a/drivers/tty/serial/sh-sci.c > +++ b/drivers/tty/serial/sh-sci.c > @@ -157,6 +157,7 @@ struct sci_port { > > bool has_rtscts; > bool autorts; > + bool first_time_tx; This is a misnomer. It suggests to be set only during the first TX. What about ::did_tx, ::performed_tx, ::transmitted, or alike? > @@ -885,6 +887,7 @@ static void sci_transmit_chars(struct uart_port *port) > } > > sci_serial_out(port, SCxTDR, c); > + s->first_time_tx = true; > > port->icount.tx++; > } while (--count > 0); > @@ -1241,6 +1244,8 @@ static void sci_dma_tx_complete(void *arg) > if (kfifo_len(&tport->xmit_fifo) < WAKEUP_CHARS) > uart_write_wakeup(port); > > + s->first_time_tx = true; This is too late IMO. The first in-flight dma won't be accounted in sci_tx_empty(). From DMA submit up to now. > @@ -2076,6 +2081,10 @@ static unsigned int sci_tx_empty(struct uart_port *port) > { > unsigned short status = sci_serial_in(port, SCxSR); > unsigned short in_tx_fifo = sci_txfill(port); > + struct sci_port *s = to_sci_port(port); > + > + if (!s->first_time_tx) > + return TIOCSER_TEMT; So perhaps check if there is a TX DMA running here too? > > return (status & SCxSR_TEND(port)) && !in_tx_fifo ? TIOCSER_TEMT : 0; > } thanks, -- js suse labs