serial: 8250: Fix THRE flag usage for CAP_MINI
PATCH 1/1 serial: 8250: Fix THRE flag usage for CAP_MINI
The BCM2835 MINI UART has non-standard THRE semantics. Conventionally the bit means that the FIFO is empty (although there may still be a byte in the transmit register), but on 2835 it indicates that the FIFO is not full. This causes interrupts after every byte is transmitted, with the FIFO providing some interrupt latency tolerance.
A consequence of this difference is that the usual strategy of writing multiple bytes into the TX FIFO after checking THRE once is unsafe. In the worst case of 7 bytes in the FIFO, writing 8 bytes loses all but the first since by then the FIFO is full.
There is an HFIFO ("Hidden FIFO") capability that causes the transmit loop to terminate when both THRE and TEMT are set, i.e. when the TX block is completely idle. This is unnecessarily cautious, potentially causing gaps in transmission.
Add a new conditional to the transmit loop, predicated on CAP_MINI, that exits when THRE is no longer set (the FIFO is full). This allows the FIFO to fill quickly but subsequent writes are paced by the transmission rate.
--- drivers/tty/serial/8250/8250_port.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/tty/serial/8250/8250_port.c +4 -0
@@ -1764,6 +1764,10 @@ void serial8250_tx_chars(struct uart_8250_port *up)if ((up->capabilities &UART_CAP_HFIFO ) && (serial_in (up,UART_LSR ) &BOTH_EMPTY ) !=BOTH_EMPTY )break ; +/* The BCM2835 MINI UART THRE bit is really a not-full bit. */ +if ((up->capabilities &UART_CAP_MINI ) && + !(serial_in (up,UART_LSR ) &UART_LSR_THRE )) +break ; }while (--count >0 );if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS )
Signature · 1 line
1.9.1
Hi Phil,
Am 26.06.2017 um 15:59 schrieb Phil Elwell:
Quoted 16 lines
The BCM2835 MINI UART has non-standard THRE semantics. Conventionally the bit means that the FIFO is empty (although there may still be a byte in the transmit register), but on 2835 it indicates that the FIFO is not full. This causes interrupts after every byte is transmitted, with the FIFO providing some interrupt latency tolerance.
A consequence of this difference is that the usual strategy of writing multiple bytes into the TX FIFO after checking THRE once is unsafe. In the worst case of 7 bytes in the FIFO, writing 8 bytes loses all but the first since by then the FIFO is full.
There is an HFIFO ("Hidden FIFO") capability that causes the transmit loop to terminate when both THRE and TEMT are set, i.e. when the TX block is completely idle. This is unnecessarily cautious, potentially causing gaps in transmission.
Quoted 4 lines
Add a new conditional to the transmit loop, predicated on
CAP_MINI, that exits when THRE is no longer set (the FIFO is full). This allows the FIFO to fill quickly but subsequent writes are paced by the transmission rate.
thanks for this good explanation.
But this looks like a bug / quirk than a capability?
It would be better to name this define more self-explaining.
Btw can't see the definition of UART_CAP_MINI?
Thanks
Stefan
Quoted 21 lines
Signed-off-by Phil Elwell <[email protected]>--- drivers/tty/serial/8250/8250_port.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/tty/serial/8250/8250_port.c +4
-0@@ -1764,6 +1764,10 @@ void serial8250_tx_chars(struct uart_8250_port *up)if ((up->capabilities &UART_CAP_HFIFO ) && (serial_in (up,UART_LSR ) &BOTH_EMPTY ) !=BOTH_EMPTY )break ; +/* The BCM2835 MINI UART THRE bit is really a not-full bit. */ +if ((up->capabilities &UART_CAP_MINI ) && + !(serial_in (up,UART_LSR ) &UART_LSR_THRE )) +break ; }while (--count >0 );if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS )
Hi Stefan,
Quoted 24 lines · Stefan Wahren
Hi Phil,
Am 26.06.2017 um 15:59 schrieb Phil Elwell:
Quoted 16 lines
The BCM2835 MINI UART has non-standard THRE semantics. Conventionally the bit means that the FIFO is empty (although there may still be a byte in the transmit register), but on 2835 it indicates that the FIFO is not full. This causes interrupts after every byte is transmitted, with the FIFO providing some interrupt latency tolerance.
A consequence of this difference is that the usual strategy of writing multiple bytes into the TX FIFO after checking THRE once is unsafe. In the worst case of 7 bytes in the FIFO, writing 8 bytes loses all but the first since by then the FIFO is full.
There is an HFIFO ("Hidden FIFO") capability that causes the transmit loop to terminate when both THRE and TEMT are set, i.e. when the TX block is completely idle. This is unnecessarily cautious, potentially causing gaps in transmission.
Quoted 4 lines
Add a new conditional to the transmit loop, predicated on
CAP_MINI, that exits when THRE is no longer set (the FIFO is full). This allows the FIFO to fill quickly but subsequent writes are paced by the transmission rate.
Quoted 7 lines
thanks for this good explanation.
But this looks like a bug / quirk than a capability?
It would be better to name this define more self-explaining.
Btw can't see the definition of
UART_CAP_MINI?
The capability was added in d087e7a991f1f61ee2c07db1be7c5cc2aa373f5d, which is in linux-next. Given that the "capability" already exists and the quirk is likely to be unique to BCM2835 MINI UART, I don't think we should create a new quirk.
Besides, the "HFIFO" capability looks a lot like quirk to me.
Thanks,
Phil
Quoted 21 lines
Quoted 21 lines
Signed-off-by Phil Elwell <[email protected]>--- drivers/tty/serial/8250/8250_port.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/tty/serial/8250/8250_port.c +4
-0@@ -1764,6 +1764,10 @@ void serial8250_tx_chars(struct uart_8250_port *up)if ((up->capabilities &UART_CAP_HFIFO ) && (serial_in (up,UART_LSR ) &BOTH_EMPTY ) !=BOTH_EMPTY )break ; +/* The BCM2835 MINI UART THRE bit is really a not-full bit. */ +if ((up->capabilities &UART_CAP_MINI ) && + !(serial_in (up,UART_LSR ) &UART_LSR_THRE )) +break ; }while (--count >0 );if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS )
Quoted 14 lines · Phil Elwell
Quoted 5 lines
But this looks like a bug / quirk than a capability?
It would be better to name this define more self-explaining.
Btw can't see the definition of
UART_CAP_MINI?The capability was added in
d087e7a991f1f61ee2c07db1be7c5cc2aa373f5d, which
is in linux-next. Given that the "capability" already exists and the quirk
is likely to be unique to BCM2835 MINI UART, I don't think we should create
a new quirk.
Quoted 1 line
Besides, the "HFIFO" capability looks a lot like quirk to me.
To me either, which raises a question "Should it be fixed accordingly?"
Signature · 2 lines
Andy Shevchenko <andriy.shevchenko-VuQAYsv1563Yd54FQh9/[email protected]> Intel Finland Oy
Quoted 28 lines · Phil Elwell
The BCM2835 MINI UART has non-standard THRE semantics. Conventionally the bit means that the FIFO is empty (although there may still be a byte in the transmit register), but on 2835 it indicates that the FIFO is not full. This causes interrupts after every byte is transmitted, with the FIFO providing some interrupt latency tolerance.
A consequence of this difference is that the usual strategy of writing multiple bytes into the TX FIFO after checking THRE once is unsafe. In the worst case of 7 bytes in the FIFO, writing 8 bytes loses all but the first since by then the FIFO is full.
There is an HFIFO ("Hidden FIFO") capability that causes the transmit loop to terminate when both THRE and TEMT are set, i.e. when the TX block is completely idle. This is unnecessarily cautious, potentially causing gaps in transmission.
Add a new conditional to the transmit loop, predicated on
CAP_MINI, that exits when THRE is no longer set (the FIFO is full). This allows the FIFO to fill quickly but subsequent writes are paced by the transmission rate.if ((
up->capabilities&UART_CAP_HFIFO) && (serial_in(up, UART_LSR)&BOTH_EMPTY) !=BOTH_EMPTY)
break;(quoted diff) +1
-0+ /* The BCM2835 MINI UART THRE bit is really a not-full bit. */
drivers/tty/serial/8250/8250_port.c void serial8250_tx_chars(struct uart_8250_port *up) · line 1770
Quoted 3 lines
drivers/tty/serial/8250/8250_port.c +3
-0+if ((up->capabilities &UART_CAP_MINI ) && + !(serial_in(up, UART_LSR) & UART_LSR_THRE)) +break ;
Might this end up with two sequential read of LSR?
Signature · 7 lines
Andy Shevchenko <[email protected]> Intel Finland Oy _______________________________________________ linux-rpi-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-rpi-kernel
Quoted 23 lines · Andy Shevchenko
Quoted 21 lines · Phil Elwell
The BCM2835 MINI UART has non-standard THRE semantics. Conventionally the bit means that the FIFO is empty (although there may still be a byte in the transmit register), but on 2835 it indicates that the FIFO is not full. This causes interrupts after every byte is transmitted, with the FIFO providing some interrupt latency tolerance.
A consequence of this difference is that the usual strategy of writing multiple bytes into the TX FIFO after checking THRE once is unsafe. In the worst case of 7 bytes in the FIFO, writing 8 bytes loses all but the first since by then the FIFO is full.
There is an HFIFO ("Hidden FIFO") capability that causes the transmit loop to terminate when both THRE and TEMT are set, i.e. when the TX block is completely idle. This is unnecessarily cautious, potentially causing gaps in transmission.
Add a new conditional to the transmit loop, predicated on
CAP_MINI, that exits when THRE is no longer set (the FIFO is full). This allows the FIFO to fill quickly but subsequent writes are paced by the transmission rate.
Quoted 11 lines
drivers/tty/serial/8250/8250_port.c void serial8250_tx_chars(struct uart_8250_port *up) · line 1770
Quoted 9 lines
(quoted diff) +0
-0if ((up->capabilities & UART_CAP_HFIFO) && (serial_in(up, UART_LSR) & BOTH_EMPTY) !=
BOTH_EMPTY)(quoted diff) +1
-0break; + /* The BCM2835 MINI UART THRE bit is really a not-full bit. */
drivers/tty/serial/8250/8250_port.c +3
-0+if ((up->capabilities &UART_CAP_MINI ) && + !(serial_in (up,UART_LSR ) &UART_LSR_THRE )) +break ;Might this end up with two sequential read of LSR?
The same thought crossed my mind, but CAP_MINI is essentially CAP_BCM2835, and we won't be setting CAP_HFIFO on BCM2835.
Quoted 16 lines · Andy Shevchenko
Quoted 14 lines · Phil Elwell
Quoted 5 lines
But this looks like a bug / quirk than a capability?
It would be better to name this define more self-explaining.
Btw can't see the definition of
UART_CAP_MINI?The capability was added in
d087e7a991f1f61ee2c07db1be7c5cc2aa373f5d, which
is in linux-next. Given that the "capability" already exists and the quirk
is likely to be unique to BCM2835 MINI UART, I don't think we should create
a new quirk.
Quoted 3 lines
Quoted 1 line
Besides, the "HFIFO" capability looks a lot like quirk to me.
To me either, which raises a question "Should it be fixed accordingly?"
If I was going to make these quirks, are we simply talking about renaming the capability or is there another mechanism? I've found the 8250_pci quirks, and they look quite different.
I'm also happy to make this code conditional on CONFIG_SERIAL_8250_BCM2835AUX if that is more acceptable.
Phil (still hoping to lose newb status one day)
Quoted 22 lines · Phil Elwell
Quoted 21 lines · Andy Shevchenko
Quoted 18 lines · Phil Elwell
Quoted 5 lines
But this looks like a bug / quirk than a capability?
It would be better to name this define more self-explaining.
Btw can't see the definition of
UART_CAP_MINI?The capability was added in
d087e7a991f1f61ee2c07db1be7c5cc2aa373f5d,
which
is in linux-next. Given that the "capability" already exists and the
quirk
is likely to be unique to BCM2835 MINI UART, I don't think we should
create
a new quirk.Besides, the "HFIFO" capability looks a lot like quirk to me.
Quoted 8 lines
Quoted 2 lines
To me either, which raises a question "Should it be fixed accordingly?"
If I was going to make these quirks, are we simply talking about renaming the
capability or is there another mechanism? I've found the 8250_pci quirks, and
they look quite different.
Okay, we have several types of flags in the code
1. Capabilities: UART_CAP: looks like it defines features of hardware solely for 8250 compatible devices.
2. Flags as quirks UPF_<something, not all of them> (I have a patch to convert them to quirks, need by the way to update and resend): they are for any serial devices.
3. Flags as capabilities: UPF_<the rest>, similar function as UART_CAP, but for any serial device.
Quoted 4 lines
I'm also happy to make this code conditional on
CONFIG_SERIAL_8250_BCM2835AUX
if that is more acceptable.
No, it is undesired.
Can you describe which one from the above suits the best for your case?
Signature · 2 lines
Andy Shevchenko <andriy.shevchenko-VuQAYsv1563Yd54FQh9/[email protected]> Intel Finland Oy
Quoted 42 lines · Andy Shevchenko
Quoted 22 lines · Phil Elwell
Quoted 21 lines · Andy Shevchenko
Quoted 18 lines · Phil Elwell
Quoted 5 lines
But this looks like a bug / quirk than a capability?
It would be better to name this define more self-explaining.
Btw can't see the definition of
UART_CAP_MINI?The capability was added in
d087e7a991f1f61ee2c07db1be7c5cc2aa373f5d,
which
is in linux-next. Given that the "capability" already exists and the
quirk
is likely to be unique to BCM2835 MINI UART, I don't think we should
create
a new quirk.Besides, the "HFIFO" capability looks a lot like quirk to me.
Quoted 8 lines
Quoted 2 lines
To me either, which raises a question "Should it be fixed accordingly?"
If I was going to make these quirks, are we simply talking about renaming the
capability or is there another mechanism? I've found the 8250_pci quirks, and
they look quite different.Okay, we have several types of flags in the code
1. Capabilities:UART_CAP: looks like it defines features of hardware solely for 8250 compatible devices.
2. Flags as quirks UPF_<something, not all of them> (I have a patch to convert them to quirks, need by the way to update and resend): they are for any serial devices.
3. Flags as capabilities: UPF_<the rest>, similar function asUART_CAP, but for any serial device.Quoted 1 line
Quoted 7 lines
Quoted 3 lines
I'm also happy to make this code conditional on
CONFIG_SERIAL_8250_BCM2835AUX
if that is more acceptable.No, it is undesired.
Can you describe which one from the above suits the best for your case?
This bug I am trying to work around is found in the 8250 implementation of one family of CPUs, so I would say capabilities are the best fit because they are specific to 8250 drivers.
Phil
Eric Anholt
Acked-byQuoted 16 lines · Phil Elwell
The BCM2835 MINI UART has non-standard THRE semantics. Conventionally the bit means that the FIFO is empty (although there may still be a byte in the transmit register), but on 2835 it indicates that the FIFO is not full. This causes interrupts after every byte is transmitted, with the FIFO providing some interrupt latency tolerance.
A consequence of this difference is that the usual strategy of writing multiple bytes into the TX FIFO after checking THRE once is unsafe. In the worst case of 7 bytes in the FIFO, writing 8 bytes loses all but the first since by then the FIFO is full.
There is an HFIFO ("Hidden FIFO") capability that causes the transmit loop to terminate when both THRE and TEMT are set, i.e. when the TX block is completely idle. This is unnecessarily cautious, potentially causing gaps in transmission.
Quoted 6 lines
Add a new conditional to the transmit loop, predicated on
CAP_MINI, that exits when THRE is no longer set (the FIFO is full). This allows the FIFO to fill quickly but subsequent writes are paced by the transmission rate.Signed-off-by Phil Elwell <[email protected]>
Confirmed the hw behavior, so as far as the platform goes,
_______________________________________________
linux-rpi-kernel mailing list linux-rpi-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
http://lists.infradead.org/mailman/listinfo/linux-rpi-kernel
Quoted 36 lines · Phil Elwell
Quoted 35 lines · Andy Shevchenko
Quoted 5 lines · Phil Elwell
Quoted 4 lines · Andy Shevchenko
Quoted 1 line · Phil Elwell
Besides, the "HFIFO" capability looks a lot like quirk to me.
Quoted 8 lines
Quoted 2 lines
To me either, which raises a question "Should it be fixed accordingly?"
If I was going to make these quirks, are we simply talking about renaming the
capability or is there another mechanism? I've found the 8250_pci quirks, and
they look quite different.Okay, we have several types of flags in the code
1. Capabilities:UART_CAP: looks like it defines features of hardware
solely for 8250 compatible devices.
2. Flags as quirks UPF_<something, not all of them> (I have a patch to
convert them to quirks, need by the way to update and resend): they are
for any serial devices.
3. Flags as capabilities: UPF_<the rest>, similar function asUART_CAP,
but for any serial device.Quoted 4 lines
I'm also happy to make this code conditional on
CONFIG_SERIAL_8250_BCM2835AUX
if that is more acceptable.No, it is undesired.
Quoted 8 lines
Quoted 2 lines
Can you describe which one from the above suits the best for your case?
This bug I am trying to work around is found in the 8250 implementation of
one family of CPUs, so I would say capabilities are the best fit because
they are specific to 8250 drivers.
Yeah, looks like UART_CAP suits the best for now.
One more comment that UART_CAP_* gather capabilities and quirks at the same time.
Signature · 2 lines
Andy Shevchenko <andriy.shevchenko-VuQAYsv1563Yd54FQh9/[email protected]> Intel Finland Oy
Quoted 46 lines · Andy Shevchenko
Quoted 36 lines · Phil Elwell
Quoted 35 lines · Andy Shevchenko
Quoted 5 lines · Phil Elwell
Quoted 4 lines · Andy Shevchenko
Quoted 1 line · Phil Elwell
Besides, the "HFIFO" capability looks a lot like quirk to me.
Quoted 8 lines
Quoted 2 lines
To me either, which raises a question "Should it be fixed accordingly?"
If I was going to make these quirks, are we simply talking about renaming the
capability or is there another mechanism? I've found the 8250_pci quirks, and
they look quite different.Okay, we have several types of flags in the code
1. Capabilities:UART_CAP: looks like it defines features of hardware
solely for 8250 compatible devices.
2. Flags as quirks UPF_<something, not all of them> (I have a patch to
convert them to quirks, need by the way to update and resend): they are
for any serial devices.
3. Flags as capabilities: UPF_<the rest>, similar function asUART_CAP,
but for any serial device.Quoted 4 lines
I'm also happy to make this code conditional on
CONFIG_SERIAL_8250_BCM2835AUX
if that is more acceptable.No, it is undesired.
Quoted 8 lines
Quoted 2 lines
Can you describe which one from the above suits the best for your case?
This bug I am trying to work around is found in the 8250 implementation of
one family of CPUs, so I would say capabilities are the best fit because
they are specific to 8250 drivers.
Quoted 4 lines
Yeah, looks like
UART_CAPsuits the best for now.One more comment that UART_CAP_* gather capabilities and quirks at the same time.
Is that a request for an additional comment? Is there anything else needed for an ack?
Thanks,
Phil
Quoted 39 lines · Phil Elwell
Quoted 38 lines · Andy Shevchenko
Quoted 36 lines · Phil Elwell
Quoted 24 lines · Andy Shevchenko
Quoted 1 line · Phil Elwell
On 27/06/2017 10:15, Andy Shevchenko wrote:
Okay, we have several types of flags in the code
1. Capabilities:UART_CAP: looks like it defines features of hardware
solely for 8250 compatible devices.
2. Flags as quirks UPF_<something, not all of them> (I have a patch
to
convert them to quirks, need by the way to update and resend):
they
are
for any serial devices.
3. Flags as capabilities: UPF_<the rest>, similar function asUART_CAP,
but for any serial device.Quoted 4 lines
I'm also happy to make this code conditional on
CONFIG_SERIAL_8250_BCM2835AUX
if that is more acceptable.Quoted 5 lines
No, it is undesired.
Can you describe which one from the above suits the best for your
case?This bug I am trying to work around is found in the 8250 implementation of
one family of CPUs, so I would say capabilities are the best fit because
they are specific to 8250 drivers.
Quoted 7 lines
Quoted 5 lines
Yeah, looks like
UART_CAPsuits the best for now.One more comment that UART_CAP_* gather capabilities and quirks at the
same time.Is that a request for an additional comment?
No.
Quoted 2 lines
Is there anything else needed
for an ack?
No, fine by me. Just resend a new version with tags applied. It would be easier for Greg to pick up it later.
Signature · 2 lines
Andy Shevchenko <andriy.shevchenko-VuQAYsv1563Yd54FQh9/[email protected]> Intel Finland Oy