amba-pl011: support hardware flow control
PATCH 1/1 amba-pl011: support hardware flow control
Enable/disable hardware flow control as requested by the termios.
--- drivers/serial/amba-pl011.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
drivers/serial/amba-pl011.c +5 -0
@@ -532,6 +532,11 @@ pl011_set_termios(struct uart_port *port, struct ktermios *termios, old_cr =readw (port->membase +UART011_CR );writew (0 , port->membase +UART011_CR ); +if (termios->c_cflag &CRTSCTS ) + old_cr |=UART011_CR_CTSEN |UART011_CR_RTSEN ; +else + old_cr &= ~(UART011_CR_CTSEN |UART011_CR_RTSEN ); +/* Set baud rate */ writew (quot &0x3f , port->membase +UART011_FBRD );writew (quot >>6 , port->membase +UART011_IBRD );
Signature · 1 line
1.6.5.3
PATCH 1/1 amba-pl011: support hardware flow control
Quoted 1 line · Rabin Vincent
Enable/disable hardware flow control as requested by the termios.
PATCH 1/1 amba-pl011: support hardware flow control
Quoted 6 lines · Russell King - ARM Linux
Quoted 1 line · Rabin Vincent
Enable/disable hardware flow control as requested by the termios.
From what I remember, I didn't implement this because there were corner cases to be dealt with. I don't remember what they were off hand though.
We haven't seen any problems with it thus far. Nothing obvious strikes me on rechecking the pl011 spec; it would be helpful if you could elaborate.
Either way, this patch should be safe to apply since existing users of the driver shouldn't be affected.
Rabin
PATCH 1/1 amba-pl011: support hardware flow control
Quoted 11 lines · Rabin VINCENT
Quoted 6 lines · Russell King - ARM Linux
Quoted 1 line · Rabin Vincent
Enable/disable hardware flow control as requested by the termios.
From what I remember, I didn't implement this because there were corner cases to be dealt with. I don't remember what they were off hand though.
We haven't seen any problems with it thus far. Nothing obvious strikes me on rechecking the pl011 spec; it would be helpful if you could elaborate.
Can't elaborate at the moment without re-reading the specs.
Quoted 2 lines
Either way, this patch should be safe to apply since existing users of the driver shouldn't be affected.
Err, that really doesn't follow. There are existing users, and existing users will have CRTSCTS set by default. Therefore, existing users are going from having hardware flow control on the UART disabled to having it enabled.
That's not "shouldn't be affected", that's a "this patch does change the hardware behaviour for these users".
PATCH 1/1 amba-pl011: support hardware flow control
In reply to Rabin VINCENTQuoted 11 lines · Rabin VINCENT
Quoted 6 lines · Russell King - ARM Linux
Quoted 1 line · Rabin Vincent
Enable/disable hardware flow control as requested by the termios.
From what I remember, I didn't implement this because there were corner cases to be dealt with. I don't remember what they were off hand though.
We haven't seen any problems with it thus far. Nothing obvious strikes me on rechecking the pl011 spec; it would be helpful if you could elaborate.
Right, the problem with RTS flow control is that if you enable it, the hardware takes full control of the RTS signal.
This means that when the kernel's buffers fill up, the kernel calls down to the serial core layer to throttle the input. This then calls into the set_mctrl function to de-assert RTS. However, because the hardware ignores the requested software state, the RTS signal is not de-asserted, and the remote end continues sending data.
So, enabling hardware auto-RTS is bad news - you will lose data if the application stops reading data.
Auto-CTS flow control looks safe.
PATCH 1/1 amba-pl011: support hardware flow control
Quoted 8 lines · Russell King - ARM Linux
This means that when the kernel's buffers fill up, the kernel calls down to the serial core layer to throttle the input. This then calls into the
set_mctrlfunction to de-assert RTS. However, because the hardware ignores the requested software state, the RTS signal is not de-asserted, and the remote end continues sending data.So, enabling hardware auto-RTS is bad news - you will lose data if the application stops reading data.
Surely the driver can just stop reading from the UART when the kernel's buffers are full and hardware-RTS is enabled. Then the hardware will deassert RTS itself.
The problem with relying on the kernel to deassert RTS is that it's too slow when something disables interrupts for a few ms, and you get lost data that way instead.
The ideal combination may be a bit of both:
1. When kernel deasserts RTS, do that and disable hardware-RTS so it really is deasserted.
2. When kernel asserts RTS with mctrl, enable hardware-RTS so what's output depends on the receive FIFO state.
That should solve both types of overrun.
-- Jamie
PATCH 1/1 amba-pl011: support hardware flow control
Quoted 7 lines · Jamie Lokier
Quoted 6 lines · Russell King - ARM Linux
This means that when the kernel's buffers fill up, the kernel calls down to the serial core layer to throttle the input. This then calls into the
set_mctrlfunction to de-assert RTS. However, because the hardware ignores the requested software state, the RTS signal is not de-asserted, and the remote end continues sending data.
Quoted 6 lines
Quoted 2 lines
So, enabling hardware auto-RTS is bad news - you will lose data if the application stops reading data.
Surely the driver can just stop reading from the UART when the kernel's buffers are full and hardware-RTS is enabled. Then the hardware will deassert RTS itself.
I'll let you work out how to implement that.
PATCH 1/1 amba-pl011: support hardware flow control
Quoted 8 lines · Russell King - ARM Linux
Quoted 7 lines · Jamie Lokier
Quoted 6 lines · Russell King - ARM Linux
This means that when the kernel's buffers fill up, the kernel calls down to the serial core layer to throttle the input. This then calls into the
set_mctrlfunction to de-assert RTS. However, because the hardware ignores the requested software state, the RTS signal is not de-asserted, and the remote end continues sending data.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
So, enabling hardware auto-RTS is bad news - you will lose data if the application stops reading data.
Surely the driver can just stop reading from the UART when the kernel's buffers are full and hardware-RTS is enabled. Then the hardware will deassert RTS itself.
I'll let you work out how to implement that.
You have a point.
What do you think of the other suggestion, switching between software-RTS+deasserted and hardware-RTS in response to set_mctrl calls from the generic serial layer - effectively hardware-RTS with ability for kernel to force it deasserted?
-- Jamie
PATCH 1/1 amba-pl011: support hardware flow control
In reply to Jamie LokierQuoted 10 lines · Jamie Lokier
Quoted 8 lines · Russell King - ARM Linux
This means that when the kernel's buffers fill up, the kernel calls down to the serial core layer to throttle the input. This then calls into the
set_mctrlfunction to de-assert RTS. However, because the hardware ignores the requested software state, the RTS signal is not de-asserted, and the remote end continues sending data.So, enabling hardware auto-RTS is bad news - you will lose data if the application stops reading data.
[..]
Quoted 7 lines
The ideal combination may be a bit of both:
1. When kernel deasserts RTS, do that and disable hardware-RTS so it really is deasserted.
2. When kernel asserts RTS with mctrl, enable hardware-RTS so what's output depends on the receive FIFO state.
I've implemented this in the updated patch below.
PATCH 1/1 amba-pl011: support hardware flow control
Quoted 1 line · Rabin VINCENT
I've implemented this in the updated patch below.
I think this is ok. Has it been tested?
PATCH 1/1 amba-pl011: support hardware flow control
Quoted 4 lines · Russell King - ARM Linux
Quoted 1 line · Rabin VINCENT
I've implemented this in the updated patch below.
I think this is ok. Has it been tested?
Yes. I was able to reproduce the described problem, and this version of the patch fixes it.
Rabin
PATCH 1/1 amba-pl011: support hardware flow control
In reply to Russell King - ARM Linux[Russell]
Quoted 4 lines · Rabin VINCENT
Quoted 1 line
I've implemented this in the updated patch below.
I think this is ok. Has it been tested?
I have also regression tested on the U300 (which has a pure, unmodified PL011 from ARM) and no obvious problems. Busybox stty seem to say that -crtscts is on by default so I believe it's in full use now?
I can do further stress tests, just tell me how...
Linus