From: Frieder Schrempf <frieder.schrempf@kontron.de>
To: Rasmus Villemoes <rasmus.villemoes@prevas.dk>,
Eberhard Stoll <eberhard.stoll@gmx.de>,
sherry.sun@nxp.com
Cc: festevam@gmail.com, gregkh@linuxfoundation.org,
jirislaby@kernel.org, kernel@pengutronix.de,
linux-arm-kernel@lists.infradead.org, linux-imx@nxp.com,
linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org,
s.hauer@pengutronix.de, shawnguo@kernel.org,
eberhard.stoll@kontron.de
Subject: Re: [PATCH] serial: imx: also enable Transmit Complete interrupt in rs232 mode
Date: Wed, 22 Nov 2023 14:01:20 +0100 [thread overview]
Message-ID: <fc843c33-03e4-4603-9cc9-0b30b2c21c66@kontron.de> (raw)
In-Reply-To: <5ad44085-c90b-4a88-bb7b-8ddc2b612793@prevas.dk>
On 22.11.23 09:03, Rasmus Villemoes wrote:
> On 21/11/2023 21.49, Eberhard Stoll wrote:
>>> Currently, if one switches to rs232 mode, writes something to the
>>> device, and then switches to rs485 mode, the imx_port's ->tx_state is
>>> left as SEND. This then prevents a subsequent write in rs485 mode from
>>> properly asserting the rts pin (i.e. enabling the transceiver),
>>> because imx_uart_start_rx() does not enter the "if (sport->tx_state ==
>>> OFF)" branch. Hence nothing is actually transmitted.
>>>
>>> The problem is that in rs232 mode, ->tx_state never gets set to OFF,
>>> due to
>>>
>>> usr2 = imx_uart_readl(sport, USR2);
>>> if (!(usr2 & USR2_TXDC)) {
>>> /* The shifter is still busy, so retry once TC triggers */
>>> return;
>>> }
>>>
>>> in imx_uart_stop_tx(), and TC never triggers because the Transmit
>>> Complete interrupt is not enabled for rs232.
>>>
>>> Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
>>> ---
>>> I'm not sure this is the best fix.
>>>
>>> At first I considered doing something much more targeted, but
>>> definitely also more hacky: In imx_uart_rs485_config(), if switching
>>> on rs485 mode, simply add "sport->tx_state = OFF;".
>>>
>>> If someone has a better suggestion, I'm all ears.
>>
>>
>> Hello Rasmus,
>>
>> i can observe a very similar situation, but with a litte different
>> configuration. This is how i can trigger the situation very quickly:
>>
>> 1) open the port
>> 2) send 1 byte out
>> 3) close the port
>
> Hi Eberhard
>
> Thanks for chiming in. I assume this is all in rs485 mode, no switching
> to rs232 and back involved?
>
>
>> Do it in a loop. As faster, the lockup may occur earlier (but not
>> mandatory, 100ms is sufficient in my setup at 115200 Baud on an
>> i.mx8mm board).
>> With this configuration i get the lockup in around 1 minute.
>>
>> For my setup it's clear what happens:
>>
>> - when the tty is closed imx_uart_shutdown() is called. This calls
>> imx_uart_stop_tx()
>> - for a lockup, the shifter is still busy and imx_uart_stop_tx()
>> returns early (as you explained) without modifying ->tx_state.
>> - imx_uart_shutdown() proceeds and finally closes the port. Due to
>> imx_uart_stop_tx() is not executed completely tx_state is left in
>> state ->tx_state == SEND.
>
> Yes, and imx_uart_shutdown() disables the TCEN which would otherwise
> cause _stop_tx to get called when the transmitter is no longer busy.
>
>> - When the port is opened again, tx_state is SEND and nothing can
>> be transmitted any more. The tx path has locked up!
>>
>> Setting ->tx_state = SEND in imx_uart_shutdown() helps for my issue
>> (and should be ok IMHO).
>
> [I assume you mean tx_state = OFF]. Yes, I suppose doing that would be
> ok, but I'm not sure it's a complete fix. In my simple test cast, I have
> separate programs invoked to do the I/O and do the mode switch, but in a
> real scenario, I'd expect the application itself to just open the device
> once, and then do I/O and mode switching as appropriate for the
> application logic, and I don't think uart_shutdown would then ever get
> called.
>
>> But IMHO there is one next issue with this situation: When the port
>> operates with WAIT_AFTER_RTS and WAIT_AFTER_SEND then some timers
>> for callback functions might be active. I did not discover where they
>> are stopped for the case when the serial port is closed. Maybe stopping
>> is not required ...
>
> Indeed, that's an extra complication. Adding two hrtimer_try_to_cancel()
> in shutdown would probably not hurt, along with setting tx_state OFF.
>
> I wonder if at least mode switching should simply be disallowed (-EBUSY)
> if tx_state is anything but OFF.
Is there a valid use-case for switching the mode while the device is
transmitting? Is this something we need to support for whatever reason?
It sounds rather an obscure thing to do.
If not I would strongly vote for disallowing it in favor of a more
stable and less complex driver.
next prev parent reply other threads:[~2023-11-22 13:01 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-20 13:22 [PATCH] serial: imx: also enable Transmit Complete interrupt in rs232 mode Rasmus Villemoes
2023-11-21 6:37 ` Sherry Sun
2023-11-21 7:26 ` Rasmus Villemoes
2023-11-21 20:49 ` Eberhard Stoll
2023-11-22 8:03 ` Rasmus Villemoes
2023-11-22 9:31 ` Eberhard Stoll
2023-11-22 13:01 ` Frieder Schrempf [this message]
2023-11-22 13:34 ` Rasmus Villemoes
2023-11-21 20:59 ` Eberhard Stoll
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=fc843c33-03e4-4603-9cc9-0b30b2c21c66@kontron.de \
--to=frieder.schrempf@kontron.de \
--cc=eberhard.stoll@gmx.de \
--cc=eberhard.stoll@kontron.de \
--cc=festevam@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=jirislaby@kernel.org \
--cc=kernel@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-imx@nxp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=rasmus.villemoes@prevas.dk \
--cc=s.hauer@pengutronix.de \
--cc=shawnguo@kernel.org \
--cc=sherry.sun@nxp.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox