8250 DW UART fixes when under constant Rx pressure
Subsystems (5)
Ilpo Järvinen
maintainerv2 cover 8250 DW UART fixes when under constant Rx pressure
Hi all,
Here are fixes to 8250 DW UART conditions that mostly occur in scenarios under constant Rx pressure which are made complicated by BUSY handling of DW UARTs (used when !uart_16550_compatible).
A few of the changes touch also 8250_port but it's mostly moving existing code around (except for the extra synchronize_irq() in shutdown).
I'll do UART_IIR_RX_TIMEOUT move to switch/case separately from this fix series and a few other cleanups Andy brought up.
v2:
- Added Fixes tags pointing DW & INTC10EE introducing commits
- Added Cc stable to prerequisite patches
- Separate adding serial8250_handle_irq_locked() to own patch
- Put new exports to SERIAL_8250 namespace (eventually all 8250 exports should move there, but out-of-scope for this series)
- Changes to no_int_count
- Change type to u8
- Use modulo in increment, add a define for it
- Perform kick only on 4th NO_INT
- Use serial_port_in/out() throughout the series
- Add FIXME comments to ndelay(frame_time) about very low baud rates
- Add cleanup.h
- Tweak lockdep.h place among misordered includes
- Wording tweaks to changelogs and comments
Ilpo Järvinen (7):
serial: 8250: Protect LCR write in shutdown
serial: 8250_dw: Avoid unnecessary LCR writes
serial: 8250: Add serial8250_handle_irq_locked()
serial: 8250_dw: Rework dw8250_handle_irq() locking and IIR handling
serial: 8250_dw: Rework IIR_NO_INT handling to stop interrupt storm
serial: 8250: Add late synchronize_irq() to shutdown to handle DW UART
BUSY
serial: 8250_dw: Ensure BUSY is deasserted
drivers/tty/serial/8250/8250.h | 25 +++ drivers/tty/serial/8250/8250_dw.c | 309 ++++++++++++++++++++++------ drivers/tty/serial/8250/8250_port.c | 69 ++++--- include/linux/serial_8250.h | 1 + 4 files changed, 313 insertions(+), 91 deletions(-)
base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8
Signature · 1 line
2.39.5
Ilpo Järvinen
maintainerPATCH v2 1/7 serial: 8250: Protect LCR write in shutdown
The 8250_dw driver needs to potentially perform very complex operations during LCR writes because its BUSY handling prevents updates to LCR while UART is BUSY (which is not fully under our control without those complex operations). Thus, LCR writes should occur under port's lock.
Move LCR write under port's lock in serial8250_do_shutdown(). Also split the LCR RMW so that the logic is on a separate line for clarity.
--- drivers/tty/serial/8250/8250_port.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/tty/serial/8250/8250_port.c +6 -5
@@ -2350,6 +2350,7 @@ static int serial8250_startup(struct uart_port *port)void serial8250_do_shutdown (struct uart_port *port) {struct uart_8250_port *up =up_to_u8250p (port); +u32 lcr;serial8250_rpm_get (up);/*
@@ -2376,13 +2377,13 @@ void serial8250_do_shutdown(struct uart_port *port) port->mctrl &= ~TIOCM_OUT2 ;serial8250_set_mctrl (port, port->mctrl); + +/* Disable break condition */ + lcr =serial_port_in (port,UART_LCR ); + lcr &= ~UART_LCR_SBC ; +serial_port_out (port,UART_LCR , lcr); } -/* -* Disable break condition and FIFOs -*/ -serial_port_out (port,UART_LCR , -serial_port_in (port,UART_LCR ) & ~UART_LCR_SBC );serial8250_clear_fifos (up);rsa_disable (up);
Signature · 1 line
2.39.5
Ilpo Järvinen
maintainerPATCH v2 2/7 serial: 8250_dw: Avoid unnecessary LCR writes
In reply to Ilpo JärvinenWhen DW UART is configured with BUSY flag, LCR writes may not always succeed which can make any LCR write complex and very expensive. Performing write directly can trigger IRQ and the driver has to perform complex and distruptive sequence while retrying the write.
Therefore, it's better to avoid doing LCR write that would not change the value of the LCR register. Add LCR write avoidance code into the 8250_dw driver's .serial_out() functions.
--- drivers/tty/serial/8250/8250_dw.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
drivers/tty/serial/8250/8250_dw.c +31 -0
@@ -181,6 +181,22 @@ static void dw8250_check_lcr(struct uart_port *p, unsigned int offset, u32 value*/ } +/* +* With BUSY, LCR writes can be very expensive (IRQ + complex retry logic). +* If the write does not change the value of the LCR register, skip it entirely. +*/ +static bool dw8250_can_skip_reg_write (struct uart_port *p,unsigned int offset,u32 value) +{ +struct dw8250_data *d =to_dw8250_data (p->private_data); +u32 lcr; + +if (offset !=UART_LCR || d->uart_16550_compatible) +return false; + + lcr =serial_port_in (p, offset); +return lcr == value; +} +/* Returns once the transmitter is empty or we run out of retries */ static void dw8250_tx_wait_empty (struct uart_port *p) {
@@ -207,12 +223,18 @@ static void dw8250_tx_wait_empty(struct uart_port *p)static void dw8250_serial_out (struct uart_port *p,unsigned int offset,u32 value) { +if (dw8250_can_skip_reg_write (p, offset, value)) +return ; +writeb (value, p->membase + (offset << p->regshift));dw8250_check_lcr (p, offset, value); }static void dw8250_serial_out38x (struct uart_port *p,unsigned int offset,u32 value) { +if (dw8250_can_skip_reg_write (p, offset, value)) +return ; +/* Allow the TX to drain before we reconfigure */ if (offset ==UART_LCR )dw8250_tx_wait_empty (p);
@@ -237,6 +259,9 @@ static u32 dw8250_serial_inq(struct uart_port *p, unsigned int offset)static void dw8250_serial_outq (struct uart_port *p,unsigned int offset,u32 value) { +if (dw8250_can_skip_reg_write (p, offset, value)) +return ; + value &=0xff ;__raw_writeq (value, p->membase + (offset << p->regshift));/* Read back to ensure register write ordering. */
@@ -248,6 +273,9 @@ static void dw8250_serial_outq(struct uart_port *p, unsigned int offset, u32 valstatic void dw8250_serial_out32 (struct uart_port *p,unsigned int offset,u32 value) { +if (dw8250_can_skip_reg_write (p, offset, value)) +return ; +writel (value, p->membase + (offset << p->regshift));dw8250_check_lcr (p, offset, value); }
@@ -261,6 +289,9 @@ static u32 dw8250_serial_in32(struct uart_port *p, unsigned int offset)static void dw8250_serial_out32be (struct uart_port *p,unsigned int offset,u32 value) { +if (dw8250_can_skip_reg_write (p, offset, value)) +return ; +iowrite32be (value, p->membase + (offset << p->regshift));dw8250_check_lcr (p, offset, value); }
Signature · 1 line
2.39.5
Ilpo Järvinen
maintainerPATCH v2 3/7 serial: 8250: Add serial8250_handle_irq_locked()
In reply to Ilpo Järvinen8250_port exports serial8250_handle_irq() to HW specific 8250 drivers. It takes port's lock within but a HW specific 8250 driver may want to take port's lock itself, do something, and then call the generic handler in 8250_port but to do that, the caller has to release port's lock for no good reason.
Introduce serial8250_handle_irq_locked() which a HW specific driver can call while already holding port's lock.
As this is new export, put it straight into a namespace (where all 8250 exports should eventually be moved).
--- drivers/tty/serial/8250/8250_port.c | 24 ++++++++++++++++-------- include/linux/serial_8250.h | 1 + 2 files changed, 17 insertions(+), 8 deletions(-)
drivers/tty/serial/8250/8250_port.c +16 -8
@@ -18,6 +18,7 @@#include <linux/irq.h> #include <linux/console.h> #include <linux/gpio/consumer.h> +#include <linux/lockdep.h> #include <linux/sysrq.h> #include <linux/delay.h> #include <linux/platform_device.h>
@@ -1782,20 +1783,16 @@ static bool handle_rx_dma(struct uart_8250_port *up, unsigned int iir) }/* -* This handles the interrupt from one port. +* Context: port's lock must be held by the caller. */ -int serial8250_handle_irq (struct uart_port *port,unsigned int iir) +void serial8250_handle_irq_locked (struct uart_port *port,unsigned int iir) {struct uart_8250_port *up =up_to_u8250p (port);struct tty_port *tport = &port->state->port;bool skip_rx = false; -unsigned long flags;u16 status; -if (iir &UART_IIR_NO_INT ) -return 0 ; - -uart_port_lock_irqsave (port, &flags); +lockdep_assert_held_once (&port->lock); status =serial_lsr_in (up);
@@ -1828,8 +1825,19 @@ int serial8250_handle_irq(struct uart_port *port, unsigned int iir)else if (!up->dma->tx_running)__stop_tx (up); } +} +EXPORT_SYMBOL_NS_GPL (serial8250_handle_irq_locked,"SERIAL_8250" ); -uart_unlock_and_check_sysrq_irqrestore (port, flags); +/* +* This handles the interrupt from one port. +*/ +int serial8250_handle_irq (struct uart_port *port,unsigned int iir) +{ +if (iir &UART_IIR_NO_INT ) +return 0 ; + +guard (uart_port_lock_irqsave)(port); +serial8250_handle_irq_locked (port, iir);return 1 ; }
include/linux/serial_8250.h +1 -0
@@ -195,6 +195,7 @@ void serial8250_do_set_mctrl(struct uart_port *port, unsigned int mctrl);void serial8250_do_set_divisor (struct uart_port *port,unsigned int baud,unsigned int quot);int fsl8250_handle_irq (struct uart_port *port); +void serial8250_handle_irq_locked (struct uart_port *port,unsigned int iir);int serial8250_handle_irq (struct uart_port *port,unsigned int iir);u16 serial8250_rx_chars (struct uart_8250_port *up,u16 lsr);void serial8250_read_char (struct uart_8250_port *up,u16 lsr);
Signature · 1 line
2.39.5
Ilpo Järvinen
maintainerPATCH v2 4/7 serial: 8250_dw: Rework dw8250_handle_irq() locking and IIR handling
In reply to Ilpo Järvinendw8250_handle_irq() takes port's lock multiple times with no good reason to release it in between and calls serial8250_handle_irq() that also takes port's lock.
Take port's lock only once in dw8250_handle_irq() and use serial8250_handle_irq_locked() to avoid releasing port's lock in between.
As IIR_NO_INT check in serial8250_handle_irq() was outside of port's lock, it has to be done already in dw8250_handle_irq().
DW UART can, in addition to IIR_NO_INT, report BUSY_DETECT (0x7) which collided with the IIR_NO_INT (0x1) check in serial8250_handle_irq() (because & is used instead of ==) meaning that no other work is done by serial8250_handle_irq() during an BUSY_DETECT interrupt.
This allows reorganizing code in dw8250_handle_irq() to do both IIR_NO_INT and BUSY_DETECT handling right at the start simplifying the logic.
--- drivers/tty/serial/8250/8250_dw.c | 37 ++++++++++++++++++------------- 1 file changed, 21 insertions(+), 16 deletions(-)
drivers/tty/serial/8250/8250_dw.c +21 -16
@@ -9,6 +9,9 @@* LCR is written whilst busy. If it is, then a busy detect interrupt is * raised, the LCR needs to be rewritten and the uart status register read. */ +#include <linux/bitfield.h> +#include <linux/bits.h> +#include <linux/cleanup.h> #include <linux/clk.h> #include <linux/delay.h> #include <linux/device.h>
@@ -40,6 +43,8 @@#define RZN1_UART_RDMACR 0x110/* DMA Control Register Receive Mode */ /* DesignWare specific register fields */ +#define DW_UART_IIR_IID GENMASK(3, 0) +#define DW_UART_MCR_SIRE BIT(6)/* Renesas specific register fields */
@@ -312,7 +317,19 @@ static int dw8250_handle_irq(struct uart_port *p)bool rx_timeout = (iir &0x3f ) ==UART_IIR_RX_TIMEOUT ;unsigned int quirks = d->pdata->quirks;unsigned int status; -unsigned long flags; + +switch (FIELD_GET (DW_UART_IIR_IID , iir)) { +case UART_IIR_NO_INT : +return 0 ; + +case UART_IIR_BUSY : +/* Clear the USR */ +serial_port_in (p, d->pdata->usr_reg); + +return 1 ; + } + +guard (uart_port_lock_irqsave)(p);/* * There are ways to get Designware-based UARTs into a state where
@@ -325,20 +342,15 @@ static int dw8250_handle_irq(struct uart_port *p)* so we limit the workaround only to non-DMA mode. */ if (!up->dma && rx_timeout) { -uart_port_lock_irqsave (p, &flags); status =serial_lsr_in (up);if (!(status & (UART_LSR_DR |UART_LSR_BI )))serial_port_in (p,UART_RX ); - -uart_port_unlock_irqrestore (p, flags); }/* Manually stop the Rx DMA transfer when acting as flow controller */ if (quirks &DW_UART_QUIRK_IS_DMA_FC && up->dma && up->dma->rx_running && rx_timeout) { -uart_port_lock_irqsave (p, &flags); status =serial_lsr_in (up); -uart_port_unlock_irqrestore (p, flags);if (status & (UART_LSR_DR |UART_LSR_BI )) {dw8250_writel_ext (p,RZN1_UART_RDMACR ,0 );
@@ -346,17 +358,9 @@ static int dw8250_handle_irq(struct uart_port *p) } } -if (serial8250_handle_irq (p, iir)) -return 1 ; - -if ((iir &UART_IIR_BUSY ) ==UART_IIR_BUSY ) { -/* Clear the USR */ -serial_port_in (p, d->pdata->usr_reg); +serial8250_handle_irq_locked (p, iir); -return 1 ; - } - -return 0 ; +return 1 ; }static void dw8250_clk_work_cb (struct work_struct *work)
@@ -858,6 +862,7 @@ static struct platform_driver dw8250_platform_driver = {module_platform_driver (dw8250_platform_driver); +MODULE_IMPORT_NS ("SERIAL_8250" );MODULE_AUTHOR ("Jamie Iles" );MODULE_LICENSE ("GPL" );MODULE_DESCRIPTION ("Synopsys DesignWare 8250 serial port driver" );
Signature · 1 line
2.39.5
Ilpo Järvinen
maintainerPATCH v2 5/7 serial: 8250_dw: Rework IIR_NO_INT handling to stop interrupt storm
In reply to Ilpo JärvinenINTC10EE UART can end up into an interrupt storm where it reports IIR_NO_INT (0x1). If the storm happens during active UART operation, it is promptly stopped by IIR value change due to Rx or Tx events. However, when there is no activity, either due to idle serial line or due to specific circumstances such as during shutdown that writes IER=0, there is nothing to stop the storm.
During shutdown the storm is particularly problematic because serial8250_do_shutdown() calls synchronize_irq() that will hang in waiting for the storm to finish which never happens.
This problem can also result in triggering a warning:
irq 45: nobody cared (try booting with the "irqpoll" option) [...snip...]
handlers:
serial8250_interrupt
Disabling IRQ #45
Normal means to reset interrupt status by reading LSR, MSR, USR, or RX register do not result in the UART deasserting the IRQ.
Add a quirk to INTC10EE UARTs to enable Tx interrupts if UART's Tx is currently empty and inactive. Rework IIR_NO_INT to keep track of the number of consecutive IIR_NO_INT, and on fourth one perform the quirk. Enabling Tx interrupts should change IIR value from IIR_NO_INT to IIR_THRI which has been observed to stop the storm.
--- drivers/tty/serial/8250/8250_dw.c | 67 +++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 4 deletions(-)
drivers/tty/serial/8250/8250_dw.c +63 -4
@@ -61,6 +61,13 @@#define DW_UART_QUIRK_IS_DMA_FC BIT(3)#define DW_UART_QUIRK_APMC0D08 BIT(4)#define DW_UART_QUIRK_CPR_VALUE BIT(5) +#define DW_UART_QUIRK_IER_KICK BIT(6) + +/* +* Number of consecutive IIR_NO_INT interrupts required to trigger interrupt +* storm prevention code. +*/ +#define DW_UART_QUIRK_IER_KICK_THRES 4struct dw8250_platform_data {u8 usr_reg;
@@ -82,6 +89,8 @@ struct dw8250_data { unsigned int skip_autocfg:1; unsigned int uart_16550_compatible:1; + +u8 no_int_count; };static inline struct dw8250_data *to_dw8250_data (struct dw8250_port_data *data)
@@ -308,6 +317,29 @@ static u32 dw8250_serial_in32be(struct uart_port *p, unsigned int offset)return dw8250_modify_msr (p, offset, value); } +/* +* INTC10EE UART can IRQ storm while reporting IIR_NO_INT. Inducing IIR value +* change has been observed to break the storm. +* +* If Tx is empty (THRE asserted), we use here IER_THRI to cause IIR_NO_INT -> +* IIR_THRI transition. +*/ +static void dw8250_quirk_ier_kick (struct uart_port *p) +{ +struct uart_8250_port *up =up_to_u8250p (p); +u32 lsr; + +if (up->ier &UART_IER_THRI ) +return ; + + lsr =serial_lsr_in (up); +if (!(lsr &UART_LSR_THRE )) +return ; + +serial_port_out (p,UART_IER , up->ier |UART_IER_THRI ); +serial_port_in (p,UART_LCR );/* safe, no side-effects */ +serial_port_out (p,UART_IER , up->ier); +}static int dw8250_handle_irq (struct uart_port *p) {
@@ -318,18 +350,30 @@ static int dw8250_handle_irq(struct uart_port *p)unsigned int quirks = d->pdata->quirks;unsigned int status; +guard (uart_port_lock_irqsave)(p); +switch (FIELD_GET (DW_UART_IIR_IID , iir)) {case UART_IIR_NO_INT : +if (d->uart_16550_compatible || up->dma) +return 0 ; + +if (quirks &DW_UART_QUIRK_IER_KICK && + d->no_int_count == (DW_UART_QUIRK_IER_KICK_THRES -1 )) +dw8250_quirk_ier_kick (p); + d->no_int_count = (d->no_int_count +1 ) %DW_UART_QUIRK_IER_KICK_THRES ; +return 0 ;case UART_IIR_BUSY :/* Clear the USR */ serial_port_in (p, d->pdata->usr_reg); + d->no_int_count =0 ; +return 1 ; } -guard (uart_port_lock_irqsave)(p); + d->no_int_count =0 ;/* * There are ways to get Designware-based UARTs into a state where
@@ -562,6 +606,14 @@ static void dw8250_reset_control_assert(void *data)reset_control_assert (data); } +static void dw8250_shutdown (struct uart_port *port) +{ +struct dw8250_data *d =to_dw8250_data (port->private_data); + +serial8250_do_shutdown (port); + d->no_int_count =0 ; +} +static int dw8250_probe (struct platform_device *pdev) {struct uart_8250_port uart = {}, *up = &uart;
@@ -685,10 +737,12 @@ static int dw8250_probe(struct platform_device *pdev)dw8250_quirks (p, data);/* If the Busy Functionality is not implemented, don't handle it */ -if (data->uart_16550_compatible) +if (data->uart_16550_compatible) { p->handle_irq =NULL ; -else if (data->pdata) + }else if (data->pdata) { p->handle_irq = dw8250_handle_irq; + p->shutdown = dw8250_shutdown; + }dw8250_setup_dma_filter (p, data);
@@ -815,6 +869,11 @@ static const struct dw8250_platform_data dw8250_skip_set_rate_data = { .quirks = DW_UART_QUIRK_SKIP_SET_RATE, }; +static const struct dw8250_platform_data dw8250_intc10ee = { + .usr_reg =DW_UART_USR , + .quirks =DW_UART_QUIRK_IER_KICK , +}; +static const struct of_device_id dw8250_of_match[] = { { .compatible ="snps,dw-apb-uart" , .data = &dw8250_dw_apb }, { .compatible ="cavium,octeon-3860-uart" , .data = &dw8250_octeon_3860_data },
@@ -844,7 +903,7 @@ static const struct acpi_device_id dw8250_acpi_match[] = { { "INT33C5", (kernel_ulong_t)&dw8250_dw_apb }, { "INT3434", (kernel_ulong_t)&dw8250_dw_apb }, { "INT3435", (kernel_ulong_t)&dw8250_dw_apb }, - { "INTC10EE", (kernel_ulong_t)&dw8250_dw_apb }, + { "INTC10EE", (kernel_ulong_t)&dw8250_intc10ee }, { }, };MODULE_DEVICE_TABLE (acpi, dw8250_acpi_match);
Signature · 1 line
2.39.5
Ilpo Järvinen
maintainerPATCH v2 6/7 serial: 8250: Add late synchronize_irq() to shutdown to handle DW UART BUSY
In reply to Ilpo JärvinenWhen DW UART is !uart_16550_compatible, it can indicate BUSY at any point (when under constant Rx pressure) unless a complex sequence of steps is performed. Any LCR write can run a foul with the condition that prevents writing LCR while the UART is BUSY, which triggers BUSY_DETECT interrupt that seems unmaskable using IER bits.
Normal flow is that dw8250_handle_irq() handles BUSY_DETECT condition by reading USR register. This BUSY feature, however, breaks the assumptions made in serial8250_do_shutdown(), which runs synchronize_irq() after clearing IER and assumes no interrupts can occur after that point but then proceeds to update LCR, which on DW UART can trigger an interrupt.
If serial8250_do_shutdown() releases the interrupt handler before the handler has run and processed the BUSY_DETECT condition by read the USR register, the IRQ is not deasserted resulting in interrupt storm that triggers "irq x: nobody cared" warning leading to disabling the IRQ.
Add late synchronize_irq() into serial8250_do_shutdown() to ensure BUSY_DETECT from DW UART is handled before port's interrupt handler is released. Alternative would be to add DW UART specific shutdown function but it would mostly duplicate the generic code and the extra synchronize_irq() seems pretty harmless in serial8250_do_shutdown().
--- drivers/tty/serial/8250/8250_port.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/tty/serial/8250/8250_port.c +6 -0
@@ -2401,6 +2401,12 @@ void serial8250_do_shutdown(struct uart_port *port)* the IRQ chain. */ serial_port_in (port,UART_RX ); +/* +* LCR writes on DW UART can trigger late (unmaskable) IRQs. +* Handle them before releasing the handler. +*/ +synchronize_irq (port->irq); +serial8250_rpm_put (up); up->ops->release_irq (up);
Signature · 1 line
2.39.5
Ilpo Järvinen
maintainerPATCH v2 7/7 serial: 8250_dw: Ensure BUSY is deasserted
In reply to Ilpo JärvinenDW UART cannot write to LCR, DLL, and DLH while BUSY is asserted. Existance of BUSY depends on uart_16550_compatible, if UART HW is configured with it those registers can always be written.
There currently is dw8250_force_idle() which attempts to achieve non-BUSY state by disabling FIFO, however, the solution is unreliable when Rx keeps getting more and more characters.
Create a sequence of operations that ensures UART cannot keep BUSY asserted indefinitely. The new sequence relies on enabling loopback mode temporarily to prevent incoming Rx characters keeping UART BUSY.
Ensure no Tx in ongoing while the UART is switches into the loopback mode (requires exporting serial8250_fifo_wait_for_lsr_thre() and adding DMA Tx pause/resume functions).
According to tests performed by Adriana Nicolae <[email protected]>, simply disabling FIFO or clearing FIFOs only once does not always ensure BUSY is deasserted but up to two tries may be needed. This could be related to ongoing Rx of a character (a guess, not known for sure). Therefore, retry FIFO clearing a few times (retry limit 4 is arbitrary number but using, e.g., p->fifosize seems overly large). Tests performed by others did not exhibit similar challenge but it does not seem harmful to leave the FIFO clearing loop in place for all DW UARTs with BUSY functionality.
Use the new dw8250_idle_enter/exit() to do divisor writes and LCR writes. In case of plain LCR writes, opportunistically try to update LCR first and only invoke dw8250_idle_enter() if the write did not succeed (it has been observed that in practice most LCR writes do succeed without complications).
This issue was first reported by qianfan Zhao who put lots of debugging effort into understanding the solution space.
--- drivers/tty/serial/8250/8250.h | 25 ++++ drivers/tty/serial/8250/8250_dw.c | 176 ++++++++++++++++++++-------- drivers/tty/serial/8250/8250_port.c | 28 +++-- 3 files changed, 170 insertions(+), 59 deletions(-)
drivers/tty/serial/8250/8250.h +25 -0
@@ -175,7 +175,9 @@ static unsigned int __maybe_unused serial_icr_read(struct uart_8250_port *up,return value; } +void serial8250_clear_fifos (struct uart_8250_port *p);void serial8250_clear_and_reinit_fifos (struct uart_8250_port *p); +void serial8250_fifo_wait_for_lsr_thre (struct uart_8250_port *up,unsigned int count);void serial8250_rpm_get (struct uart_8250_port *p);void serial8250_rpm_put (struct uart_8250_port *p);
@@ -400,6 +402,26 @@ static inline bool serial8250_tx_dma_running(struct uart_8250_port *p) return dma && dma->tx_running; } + +static inline void serial8250_tx_dma_pause (struct uart_8250_port *p) +{ +struct uart_8250_dma *dma = p->dma; + +if (!dma->tx_running) +return ; + +dmaengine_pause (dma->txchan); +} + +static inline void serial8250_tx_dma_resume (struct uart_8250_port *p) +{ +struct uart_8250_dma *dma = p->dma; + +if (!dma->tx_running) +return ; + +dmaengine_resume (dma->txchan); +}#else static inline int serial8250_tx_dma (struct uart_8250_port *p) {
@@ -421,6 +443,9 @@ static inline bool serial8250_tx_dma_running(struct uart_8250_port *p) {return false; } + +static inline void serial8250_tx_dma_pause (struct uart_8250_port *p) { } +static inline void serial8250_tx_dma_resume (struct uart_8250_port *p) { }#endif static inline int ns16550a_goto_highspeed (struct uart_8250_port *up)
drivers/tty/serial/8250/8250_dw.c +130 -46
233 lines not on this page · raw message
drivers/tty/serial/8250/8250_port.c +15 -13
@@ -489,7 +489,7 @@ serial_port_out_sync(struct uart_port *p, int offset, int value)/* * FIFO support. */ -static void serial8250_clear_fifos (struct uart_8250_port *p) +void serial8250_clear_fifos (struct uart_8250_port *p) {if (p->capabilities &UART_CAP_FIFO ) {serial_out (p,UART_FCR ,UART_FCR_ENABLE_FIFO );
@@ -498,6 +498,7 @@ static void serial8250_clear_fifos(struct uart_8250_port *p)serial_out (p,UART_FCR ,0 ); } } +EXPORT_SYMBOL_NS_GPL (serial8250_clear_fifos,"SERIAL_8250" );static enum hrtimer_restart serial8250_em485_handle_start_tx (struct hrtimer *t);static enum hrtimer_restart serial8250_em485_handle_stop_tx (struct hrtimer *t);
@@ -3200,6 +3201,17 @@ void serial8250_set_defaults(struct uart_8250_port *up) }EXPORT_SYMBOL_GPL (serial8250_set_defaults); +void serial8250_fifo_wait_for_lsr_thre (struct uart_8250_port *up,unsigned int count) +{ +unsigned int i; + +for (i =0 ; i < count; i++) { +if (wait_for_lsr (up,UART_LSR_THRE )) +return ; + } +} +EXPORT_SYMBOL_NS_GPL (serial8250_fifo_wait_for_lsr_thre,"SERIAL_8250" ); +#ifdef CONFIG_SERIAL_8250_CONSOLE static void serial8250_console_putchar (struct uart_port *port,unsigned char ch)
@@ -3241,16 +3253,6 @@ static void serial8250_console_restore(struct uart_8250_port *up)serial8250_out_MCR (up, up->mcr |UART_MCR_DTR |UART_MCR_RTS ); } -static void fifo_wait_for_lsr (struct uart_8250_port *up,unsigned int count) -{ -unsigned int i; - -for (i =0 ; i < count; i++) { -if (wait_for_lsr (up,UART_LSR_THRE )) -return ; - } -} -/* * Print a string to the serial port using the device FIFO *
@@ -3269,7 +3271,7 @@ static void serial8250_console_fifo_write(struct uart_8250_port *up,while (s != end) {/* Allow timeout for each byte of a possibly full FIFO */ -fifo_wait_for_lsr (up, fifosize); +serial8250_fifo_wait_for_lsr_thre (up, fifosize);for (i =0 ; i < fifosize && s != end; ++i) {if (*s =='\n' && !cr_sent) {
@@ -3287,7 +3289,7 @@ static void serial8250_console_fifo_write(struct uart_8250_port *up,* Allow timeout for each byte written since the caller will only wait * for UART_LSR_BOTH_EMPTY using the timeout of a single character */ -fifo_wait_for_lsr (up, tx_count); +serial8250_fifo_wait_for_lsr_thre (up, tx_count); }/*
Signature · 1 line
2.39.5
Re: [PATCH v2 1/7] serial: 8250: Protect LCR write in shutdown
In reply to Ilpo JärvinenQuoted 7 lines · Ilpo Järvinen
The 8250_dw driver needs to potentially perform very complex operations during LCR writes because its BUSY handling prevents updates to LCR while UART is BUSY (which is not fully under our control without those complex operations). Thus, LCR writes should occur under port's lock.
Move LCR write under port's lock in
serial8250_do_shutdown(). Also split the LCR RMW so that the logic is on a separate line for clarity.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 3/7] serial: 8250: Add serial8250_handle_irq_locked()
In reply to Ilpo JärvinenQuoted 11 lines · Ilpo Järvinen
8250_port exports
serial8250_handle_irq()to HW specific 8250 drivers. It takes port's lock within but a HW specific 8250 driver may want to take port's lock itself, do something, and then call the generic handler in 8250_port but to do that, the caller has to release port's lock for no good reason.Introduce
serial8250_handle_irq_locked()which a HW specific driver can call while already holding port's lock.As this is new export, put it straight into a namespace (where all 8250 exports should eventually be moved).
...
Quoted 2 lines
+void
serial8250_handle_irq_locked(struct uart_port *port, unsigned int iir);
intserial8250_handle_irq(struct uart_port *port, unsigned int iir);
Looking at these I think at some point we can move to 'u32 iir'.
Quoted 2 lines
u16
serial8250_rx_chars(struct uart_8250_port *up, u16 lsr); voidserial8250_read_char(struct uart_8250_port *up, u16 lsr);
Signature · 2 lines
With Best Regards, Andy Shevchenko
Ilpo Järvinen
maintainerRe: [PATCH v2 3/7] serial: 8250: Add serial8250_handle_irq_locked()
Quoted 13 lines · Andy Shevchenko
Quoted 11 lines · Ilpo Järvinen
8250_port exports
serial8250_handle_irq()to HW specific 8250 drivers. It takes port's lock within but a HW specific 8250 driver may want to take port's lock itself, do something, and then call the generic handler in 8250_port but to do that, the caller has to release port's lock for no good reason.Introduce
serial8250_handle_irq_locked()which a HW specific driver can call while already holding port's lock.As this is new export, put it straight into a namespace (where all 8250 exports should eventually be moved).
Quoted 8 lines
Reviewed-by Andy Shevchenko <[email protected]>...
Quoted 2 lines
+void
serial8250_handle_irq_locked(struct uart_port *port, unsigned int iir);
intserial8250_handle_irq(struct uart_port *port, unsigned int iir);Looking at these I think at some point we can move to 'u32 iir'.
Yes (though for common 8250 code even u8 would probably suffice).
Signature · 1 line
i.
Re: [PATCH v2 2/7] serial: 8250_dw: Avoid unnecessary LCR writes
In reply to Ilpo JärvinenQuoted 8 lines · Ilpo Järvinen
When DW UART is configured with BUSY flag, LCR writes may not always succeed which can make any LCR write complex and very expensive. Performing write directly can trigger IRQ and the driver has to perform complex and distruptive sequence while retrying the write.
Therefore, it's better to avoid doing LCR write that would not change the value of the LCR register. Add LCR write avoidance code into the 8250_dw driver's .serial_out() functions.
...
drivers/tty/serial/8250/8250_dw.c static void dw8250_check_lcr(struct uart_port *p, unsigned int offset, u32 value · line 197
Quoted 10 lines
drivers/tty/serial/8250/8250_dw.c +10
-0+static bool dw8250_can_skip_reg_write (struct uart_port *p,unsigned int offset,u32 value) +{ +struct dw8250_data *d =to_dw8250_data (p->private_data); +u32 lcr; + +if (offset !=UART_LCR || d->uart_16550_compatible) +return false; + + lcr =serial_port_in (p, offset); +return lcr == value;
I don't expect the side-effects, but strictly speaking this compares the 32-bit values, while in some callbacks the only part of that is being used (often lowest 8 bits).
Quoted 1 line
+}
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 4/7] serial: 8250_dw: Rework dw8250_handle_irq() locking and IIR handling
In reply to Ilpo JärvinenQuoted 11 lines · Ilpo Järvinen
dw8250_handle_irq()takes port's lock multiple times with no good reason to release it in between and callsserial8250_handle_irq()that also takes port's lock.Take port's lock only once in
dw8250_handle_irq()and useserial8250_handle_irq_locked()to avoid releasing port's lock in between.As
IIR_NO_INTcheck inserial8250_handle_irq()was outside of port's lock, it has to be done already indw8250_handle_irq().
Quoted 8 lines
DW UART can, in addition to
IIR_NO_INT, reportBUSY_DETECT(0x7) which collided with theIIR_NO_INT(0x1) check inserial8250_handle_irq()(because & is used instead of ==) meaning that no other work is done byserial8250_handle_irq()during anBUSY_DETECTinterrupt.This allows reorganizing code in
dw8250_handle_irq()to do bothIIR_NO_INTandBUSY_DETECThandling right at the start simplifying the logic.
...
drivers/tty/serial/8250/8250_dw.c static int dw8250_handle_irq(struct uart_port *p) · line 356
Quoted 13 lines
drivers/tty/serial/8250/8250_dw.c +0
-0if (!up->dma && rx_timeout) { status =serial_lsr_in (up);if (!(status & (UART_LSR_DR |UART_LSR_BI )))serial_port_in (p,UART_RX ); }/* Manually stop the Rx DMA transfer when acting as flow controller */ if (quirks &DW_UART_QUIRK_IS_DMA_FC && up->dma && up->dma->rx_running && rx_timeout) { status =serial_lsr_in (up);if (status & (UART_LSR_DR |UART_LSR_BI )) {dw8250_writel_ext (p,RZN1_UART_RDMACR ,0 );
...
Review
Quoted 2 lines
(quoted diff) +0
-0} }
Looks like now (perhaps in a separate change) this may be refactored even more.
if (rx_timeout) {
status = serial_lsr_in(up);// Although not sure about moving the above read out from the specific conditions.
if (up->dma && (status & (UART_LSR_DR | UART_LSR_BI))) {
/* Manually stop the Rx DMA transfer when acting as flow controller */
if (quirks & DW_UART_QUIRK_IS_DMA_FC && up->dma->rx_running) {
dw8250_writel_ext(p, RZN1_UART_RDMACR, 0);
dw8250_writel_ext(p, DW_UART_DMASA, 1);
} else if (!up->dma && !(status & (UART_LSR_DR | UART_LSR_BI)))
/* ... */
serial_port_in(p, UART_RX);
}
}Signature · 2 lines
With Best Regards, Andy Shevchenko
Ilpo Järvinen
maintainerRe: [PATCH v2 4/7] serial: 8250_dw: Rework dw8250_handle_irq() locking and IIR handling
Quoted 36 lines · Andy Shevchenko
Quoted 11 lines · Ilpo Järvinen
dw8250_handle_irq()takes port's lock multiple times with no good reason to release it in between and callsserial8250_handle_irq()that also takes port's lock.Take port's lock only once in
dw8250_handle_irq()and useserial8250_handle_irq_locked()to avoid releasing port's lock in between.As
IIR_NO_INTcheck inserial8250_handle_irq()was outside of port's lock, it has to be done already indw8250_handle_irq().Quoted 8 lines
DW UART can, in addition to
IIR_NO_INT, reportBUSY_DETECT(0x7) which collided with theIIR_NO_INT(0x1) check inserial8250_handle_irq()(because & is used instead of ==) meaning that no other work is done byserial8250_handle_irq()during anBUSY_DETECTinterrupt.This allows reorganizing code in
dw8250_handle_irq()to do bothIIR_NO_INTandBUSY_DETECThandling right at the start simplifying the logic.Reviewed-by Andy Shevchenko <[email protected]>...
Quoted 11 lines
drivers/tty/serial/8250/8250_dw.c +0
-0if (!up->dma && rx_timeout) { status =serial_lsr_in (up);if (!(status & (UART_LSR_DR |UART_LSR_BI )))serial_port_in (p,UART_RX ); }/* Manually stop the Rx DMA transfer when acting as flow controller */ if (quirks &DW_UART_QUIRK_IS_DMA_FC && up->dma && up->dma->rx_running && rx_timeout) { status =serial_lsr_in (up);
Quoted 7 lines
drivers/tty/serial/8250/8250_dw.c static int dw8250_handle_irq(struct uart_port *p) · line 356
Quoted 2 lines
drivers/tty/serial/8250/8250_dw.c +0
-0if (status & (UART_LSR_DR |UART_LSR_BI )) {dw8250_writel_ext (p,RZN1_UART_RDMACR ,0 );...Review
Quoted 2 lines
(quoted diff) +0
-0} }Looks like now (perhaps in a separate change) this may be refactored even more.
Definitely, as was noted in the coverletter. ;-)
--
i.
Quoted 18 lines
if (rx_timeout) { status = serial_lsr_in(up);// Although not sure about moving the above read out from the specific conditions.
if (up->dma && (status & (UART_LSR_DR | UART_LSR_BI))) { /* Manually stop the Rx DMA transfer when acting as flow controller */ if (quirks & DW_UART_QUIRK_IS_DMA_FC && up->dma->rx_running) { dw8250_writel_ext(p, RZN1_UART_RDMACR, 0); dw8250_writel_ext(p, DW_UART_DMASA, 1); } else if (!up->dma && !(status & (UART_LSR_DR | UART_LSR_BI))) /* ... */ serial_port_in(p, UART_RX); } }
Re: [PATCH v2 5/7] serial: 8250_dw: Rework IIR_NO_INT handling to stop interrupt storm
In reply to Ilpo JärvinenQuoted 19 lines · Ilpo Järvinen
INTC10EE UART can end up into an interrupt storm where it reports
IIR_NO_INT(0x1). If the storm happens during active UART operation, it is promptly stopped by IIR value change due to Rx or Tx events. However, when there is no activity, either due to idle serial line or due to specific circumstances such as during shutdown that writes IER=0, there is nothing to stop the storm.During shutdown the storm is particularly problematic because
serial8250_do_shutdown()callssynchronize_irq()that will hang in waiting for the storm to finish which never happens.This problem can also result in triggering a warning:
irq 45: nobody cared (try booting with the "irqpoll" option) [...snip...]
handlers:
serial8250_interrupt
Disabling IRQ #45
Quoted 8 lines
Normal means to reset interrupt status by reading LSR, MSR, USR, or RX register do not result in the UART deasserting the IRQ.
Add a quirk to INTC10EE UARTs to enable Tx interrupts if UART's Tx is currently empty and inactive. Rework
IIR_NO_INTto keep track of the number of consecutiveIIR_NO_INT, and on fourth one perform the quirk. Enabling Tx interrupts should change IIR value fromIIR_NO_INTtoIIR_THRIwhich has been observed to stop the storm.
...
drivers/tty/serial/8250/8250_dw.c line 70
Quoted 5 lines
drivers/tty/serial/8250/8250_dw.c +5
-0+/* +* Number of consecutive IIR_NO_INT interrupts required to trigger interrupt +* storm prevention code. +*/ +#define DW_UART_QUIRK_IER_KICK_THRES 4
Actually if we...
drivers/tty/serial/8250/8250_dw.c struct dw8250_data { · line 93
Quoted 8 lines
struct
dw8250_platform_data{drivers/tty/serial/8250/8250_dw.c +2
-0u8 usr_reg; unsigned int skip_autocfg:1; unsigned int uart_16550_compatible:1; + +u8 no_int_count;
...define this as
unsigned int no_int_count:2;
there will be no need to have a modulo at all. But I agree it might look a bit weird.
Quoted 1 line
};
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 6/7] serial: 8250: Add late synchronize_irq() to shutdown to handle DW UART BUSY
In reply to Ilpo JärvinenQuoted 18 lines · Ilpo Järvinen
When DW UART is !uart_16550_compatible, it can indicate BUSY at any point (when under constant Rx pressure) unless a complex sequence of steps is performed. Any LCR write can run a foul with the condition that prevents writing LCR while the UART is BUSY, which triggers
BUSY_DETECTinterrupt that seems unmaskable using IER bits.Normal flow is that
dw8250_handle_irq()handlesBUSY_DETECTcondition by reading USR register. This BUSY feature, however, breaks the assumptions made inserial8250_do_shutdown(), which runssynchronize_irq()after clearing IER and assumes no interrupts can occur after that point but then proceeds to update LCR, which on DW UART can trigger an interrupt.If
serial8250_do_shutdown()releases the interrupt handler before the handler has run and processed theBUSY_DETECTcondition by read the USR register, the IRQ is not deasserted resulting in interrupt storm that triggers "irq x: nobody cared" warning leading to disabling the IRQ.
Quoted 5 lines
Add late
synchronize_irq()intoserial8250_do_shutdown()to ensureBUSY_DETECTfrom DW UART is handled before port's interrupt handler is released. Alternative would be to add DW UART specific shutdown function but it would mostly duplicate the generic code and the extrasynchronize_irq()seems pretty harmless inserial8250_do_shutdown().
Dunno if the triggered interrupt may lead to a new DMA transfers (since this is generic 8520 code...) in some cases. Anyway I've just sent a patch that is Cc'ed to you to prevent that from happening. Not sure if it needs to be incorporated into your series or should have a Fixes tag.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Ilpo Järvinen
maintainerRe: [PATCH v2 6/7] serial: 8250: Add late synchronize_irq() to shutdown to handle DW UART BUSY
Quoted 19 lines · Andy Shevchenko
Quoted 18 lines · Ilpo Järvinen
When DW UART is !uart_16550_compatible, it can indicate BUSY at any point (when under constant Rx pressure) unless a complex sequence of steps is performed. Any LCR write can run a foul with the condition that prevents writing LCR while the UART is BUSY, which triggers
BUSY_DETECTinterrupt that seems unmaskable using IER bits.Normal flow is that
dw8250_handle_irq()handlesBUSY_DETECTcondition by reading USR register. This BUSY feature, however, breaks the assumptions made inserial8250_do_shutdown(), which runssynchronize_irq()after clearing IER and assumes no interrupts can occur after that point but then proceeds to update LCR, which on DW UART can trigger an interrupt.If
serial8250_do_shutdown()releases the interrupt handler before the handler has run and processed theBUSY_DETECTcondition by read the USR register, the IRQ is not deasserted resulting in interrupt storm that triggers "irq x: nobody cared" warning leading to disabling the IRQ.
Quoted 8 lines
Quoted 5 lines
Add late
synchronize_irq()intoserial8250_do_shutdown()to ensureBUSY_DETECTfrom DW UART is handled before port's interrupt handler is released. Alternative would be to add DW UART specific shutdown function but it would mostly duplicate the generic code and the extrasynchronize_irq()seems pretty harmless inserial8250_do_shutdown().Dunno if the triggered interrupt may lead to a new DMA transfers (since this is generic 8520 code...) in some cases.
If BUSY_DETECT interrupt fires (like I'd expect), the handler won't start anything but exits early from dw8250_handle_irq().
Quoted 5 lines
Anyway I've just sent a patch
that is Cc'ed to you to prevent that from happening. Not sure if it needs to be incorporated into your series or should have a Fixes tag.Reviewed-by Andy Shevchenko <[email protected]>
Signature · 1 line
i.
Re: [PATCH v2 7/7] serial: 8250_dw: Ensure BUSY is deasserted
In reply to Ilpo JärvinenQuoted 26 lines · Ilpo Järvinen
DW UART cannot write to LCR, DLL, and DLH while BUSY is asserted. Existance of BUSY depends on
uart_16550_compatible, if UART HW is configured with it those registers can always be written.There currently is
dw8250_force_idle()which attempts to achieve non-BUSY state by disabling FIFO, however, the solution is unreliable when Rx keeps getting more and more characters.Create a sequence of operations that ensures UART cannot keep BUSY asserted indefinitely. The new sequence relies on enabling loopback mode temporarily to prevent incoming Rx characters keeping UART BUSY.
Ensure no Tx in ongoing while the UART is switches into the loopback mode (requires exporting
serial8250_fifo_wait_for_lsr_thre()and adding DMA Tx pause/resume functions).According to tests performed by Adriana Nicolae <[email protected]>, simply disabling FIFO or clearing FIFOs only once does not always ensure BUSY is deasserted but up to two tries may be needed. This could be related to ongoing Rx of a character (a guess, not known for sure). Therefore, retry FIFO clearing a few times (retry limit 4 is arbitrary number but using, e.g.,
p->fifosizeseems overly large). Tests performed by others did not exhibit similar challenge but it does not seem harmful to leave the FIFO clearing loop in place for all DW UARTs with BUSY functionality.
Quoted 8 lines
Use the new dw8250_idle_enter/exit() to do divisor writes and LCR writes. In case of plain LCR writes, opportunistically try to update LCR first and only invoke
dw8250_idle_enter()if the write did not succeed (it has been observed that in practice most LCR writes do succeed without complications).This issue was first reported by qianfan Zhao who put lots of debugging effort into understanding the solution space.
Some nit-picks below, otherwise seems good to go
...
Quoted 4 lines
Shouldn't these Link:s be Closes: tags?
...
drivers/tty/serial/8250/8250_dw.c static inline u32 dw8250_modify_msr(struct uart_port *p, unsigned int offset, u3
Quoted 9 lines
drivers/tty/serial/8250/8250_dw.c +6
-0+struct dw8250_data *d =to_dw8250_data (p->private_data);struct uart_8250_port *up =up_to_u8250p (p); +unsigned int usr_reg =DW_UART_USR ; +int retries; +u32 lsr; +if (d->pdata) + usr_reg = d->pdata->usr_reg;
I would unite this with definition above:
unsigned int usr_reg = d->pdata ? d->pdata->usr_reg : DW_UART_USR;
...
drivers/tty/serial/8250/8250_dw.c static inline u32 dw8250_modify_msr(struct uart_port *p, unsigned int offset, u3 · line 186
Quoted 6 lines
drivers/tty/serial/8250/8250_dw.c +4
-0+ lsr =serial_lsr_in (up); +if (lsr &UART_LSR_DR ) { +serial_port_in (p,UART_RX ); + up->lsr_saved_flags =0 ; }
This seems repeating a top of serial8250_read_char(). Perhaps we can do it in a helper at some point?
...
drivers/tty/serial/8250/8250_dw.c static inline u32 dw8250_modify_msr(struct uart_port *p, unsigned int offset, u3 · line 270
Quoted 6 lines
drivers/tty/serial/8250/8250_dw.c +5
-0+if (d->in_idle) { +/* +* FIXME: this deadlocks if port->lock is already held +* dev_err(p->dev, "Couldn't set LCR to %d\n", value); +*/
Does it make sense to print an error here (assuming it will work with nbcon)? If so, maybe leave it at the end of the function, after dw8250_idle_exit() and goto there?
Quoted 2 lines
(quoted diff) +2
-0+ return; + }
Signature · 2 lines
With Best Regards, Andy Shevchenko
Ilpo Järvinen
maintainerRe: [PATCH v2 7/7] serial: 8250_dw: Ensure BUSY is deasserted
Quoted 39 lines · Andy Shevchenko
Quoted 26 lines · Ilpo Järvinen
DW UART cannot write to LCR, DLL, and DLH while BUSY is asserted. Existance of BUSY depends on
uart_16550_compatible, if UART HW is configured with it those registers can always be written.There currently is
dw8250_force_idle()which attempts to achieve non-BUSY state by disabling FIFO, however, the solution is unreliable when Rx keeps getting more and more characters.Create a sequence of operations that ensures UART cannot keep BUSY asserted indefinitely. The new sequence relies on enabling loopback mode temporarily to prevent incoming Rx characters keeping UART BUSY.
Ensure no Tx in ongoing while the UART is switches into the loopback mode (requires exporting
serial8250_fifo_wait_for_lsr_thre()and adding DMA Tx pause/resume functions).According to tests performed by Adriana Nicolae <[email protected]>, simply disabling FIFO or clearing FIFOs only once does not always ensure BUSY is deasserted but up to two tries may be needed. This could be related to ongoing Rx of a character (a guess, not known for sure). Therefore, retry FIFO clearing a few times (retry limit 4 is arbitrary number but using, e.g.,
p->fifosizeseems overly large). Tests performed by others did not exhibit similar challenge but it does not seem harmful to leave the FIFO clearing loop in place for all DW UARTs with BUSY functionality.Quoted 8 lines
Use the new dw8250_idle_enter/exit() to do divisor writes and LCR writes. In case of plain LCR writes, opportunistically try to update LCR first and only invoke
dw8250_idle_enter()if the write did not succeed (it has been observed that in practice most LCR writes do succeed without complications).This issue was first reported by qianfan Zhao who put lots of debugging effort into understanding the solution space.
Some nit-picks below, otherwise seems good to go
Reviewed-by Andy Shevchenko <[email protected]>
Quoted 8 lines
...
Quoted 4 lines
Shouldn't these Link:s be Closes: tags?
To not possibly give wrong signals, until they confirm their cases are indeed solved by this patch, I'd like to keep these as Link tag only.
Quoted 16 lines
drivers/tty/serial/8250/8250_dw.c static inline u32 dw8250_modify_msr(struct uart_port *p, unsigned int offset, u3
Quoted 9 lines
drivers/tty/serial/8250/8250_dw.c +6
-0+struct dw8250_data *d =to_dw8250_data (p->private_data);struct uart_8250_port *up =up_to_u8250p (p); +unsigned int usr_reg =DW_UART_USR ; +int retries; +u32 lsr; +if (d->pdata) + usr_reg = d->pdata->usr_reg;I would unite this with definition above:
unsigned int usr_reg = d->pdata ? d->pdata->usr_reg : DW_UART_USR;Quoted 1 line
drivers/tty/serial/8250/8250_dw.c +1
-0+ lsr =serial_lsr_in (up);
Quoted 7 lines
drivers/tty/serial/8250/8250_dw.c static inline u32 dw8250_modify_msr(struct uart_port *p, unsigned int offset, u3 · line 186
Quoted 4 lines
drivers/tty/serial/8250/8250_dw.c +3
-0+if (lsr &UART_LSR_DR ) { +serial_port_in (p,UART_RX ); + up->lsr_saved_flags =0 ; }This seems repeating a top of
serial8250_read_char(). Perhaps we can do it in a helper at some point?
I don't see enough similarity as I'd need to deal with lsr_saved_flags somehow still here.
Quoted 10 lines
drivers/tty/serial/8250/8250_dw.c static inline u32 dw8250_modify_msr(struct uart_port *p, unsigned int offset, u3 · line 270
Quoted 6 lines
drivers/tty/serial/8250/8250_dw.c +5
-0+if (d->in_idle) { +/* +* FIXME: this deadlocks if port->lock is already held +* dev_err(p->dev, "Couldn't set LCR to %d\n", value); +*/ Does it make sense to print an error here (assuming it will work with nbcon)? If so, maybe leave it at the end of the function, after
dw8250_idle_exit()and goto there?
I think the print would be useful. I'll leave the FIXME+commented out print into the end of the function in v3.
I also realized that on error, dw8250_idle_enter() should undo what it changed, that is, call dw8250_idle_exit() within which will simplify caller-side error handling slightly.
Signature · 1 line
i.