From: Phil Elwell Date: Wed, 21 Jun 2017 16:19:04 +0000 (+0100) Subject: serial: 8250: Fix THRE flag usage for CAP_MINI X-Git-Tag: archive/raspbian/4.9.30-2+deb9u2+rpi1~4^2~353 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=48c48ec59fe06001a09f28e211b8edc4908a86ee;p=linux-4.9.git 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 empty. 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") bit which is almost what is needed, but it only adds more bytes while both THRE and TEMT are set, i.e. when the TX side is completely idle. This is unnecessarily pessimistic. Add a new special case, predicated on CAP_MINI, that loops until THRE is no longer set. With this change, the FIFO fills quickly but subsequent writes are paced by the transmission rate. See: https://github.com/raspberrypi/linux/issues/1855 Signed-off-by: Phil Elwell --- diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c index 2d7a63f69b90..d2ecdb80e5f2 100644 --- a/drivers/tty/serial/8250/8250_port.c +++ b/drivers/tty/serial/8250/8250_port.c @@ -1746,6 +1746,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)