Skip to content
/ linux Public

Commit 2d21617

Browse files
ij-intelgregkh
authored andcommitted
serial: 8250_dw: Rework dw8250_handle_irq() locking and IIR handling
commit 883c5a2 upstream. dw8250_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. Tested-by: Bandal, Shankar <shankar.bandal@intel.com> Tested-by: Murthy, Shanth <shanth.murthy@intel.com> Cc: stable <stable@kernel.org> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Link: https://patch.msgid.link/20260203171049.4353-5-ilpo.jarvinen@linux.intel.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 9bb4972 commit 2d21617

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

drivers/tty/serial/8250/8250_dw.c

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
* LCR is written whilst busy. If it is, then a busy detect interrupt is
1010
* raised, the LCR needs to be rewritten and the uart status register read.
1111
*/
12+
#include <linux/bitfield.h>
13+
#include <linux/bits.h>
14+
#include <linux/cleanup.h>
1215
#include <linux/clk.h>
1316
#include <linux/delay.h>
1417
#include <linux/device.h>
@@ -40,6 +43,8 @@
4043
#define RZN1_UART_RDMACR 0x110 /* DMA Control Register Receive Mode */
4144

4245
/* DesignWare specific register fields */
46+
#define DW_UART_IIR_IID GENMASK(3, 0)
47+
4348
#define DW_UART_MCR_SIRE BIT(6)
4449

4550
/* Renesas specific register fields */
@@ -312,7 +317,19 @@ static int dw8250_handle_irq(struct uart_port *p)
312317
bool rx_timeout = (iir & 0x3f) == UART_IIR_RX_TIMEOUT;
313318
unsigned int quirks = d->pdata->quirks;
314319
unsigned int status;
315-
unsigned long flags;
320+
321+
switch (FIELD_GET(DW_UART_IIR_IID, iir)) {
322+
case UART_IIR_NO_INT:
323+
return 0;
324+
325+
case UART_IIR_BUSY:
326+
/* Clear the USR */
327+
serial_port_in(p, d->pdata->usr_reg);
328+
329+
return 1;
330+
}
331+
332+
guard(uart_port_lock_irqsave)(p);
316333

317334
/*
318335
* There are ways to get Designware-based UARTs into a state where
@@ -325,38 +342,25 @@ static int dw8250_handle_irq(struct uart_port *p)
325342
* so we limit the workaround only to non-DMA mode.
326343
*/
327344
if (!up->dma && rx_timeout) {
328-
uart_port_lock_irqsave(p, &flags);
329345
status = serial_lsr_in(up);
330346

331347
if (!(status & (UART_LSR_DR | UART_LSR_BI)))
332348
serial_port_in(p, UART_RX);
333-
334-
uart_port_unlock_irqrestore(p, flags);
335349
}
336350

337351
/* Manually stop the Rx DMA transfer when acting as flow controller */
338352
if (quirks & DW_UART_QUIRK_IS_DMA_FC && up->dma && up->dma->rx_running && rx_timeout) {
339-
uart_port_lock_irqsave(p, &flags);
340353
status = serial_lsr_in(up);
341-
uart_port_unlock_irqrestore(p, flags);
342354

343355
if (status & (UART_LSR_DR | UART_LSR_BI)) {
344356
dw8250_writel_ext(p, RZN1_UART_RDMACR, 0);
345357
dw8250_writel_ext(p, DW_UART_DMASA, 1);
346358
}
347359
}
348360

349-
if (serial8250_handle_irq(p, iir))
350-
return 1;
351-
352-
if ((iir & UART_IIR_BUSY) == UART_IIR_BUSY) {
353-
/* Clear the USR */
354-
serial_port_in(p, d->pdata->usr_reg);
361+
serial8250_handle_irq_locked(p, iir);
355362

356-
return 1;
357-
}
358-
359-
return 0;
363+
return 1;
360364
}
361365

362366
static void dw8250_clk_work_cb(struct work_struct *work)
@@ -865,6 +869,7 @@ static struct platform_driver dw8250_platform_driver = {
865869

866870
module_platform_driver(dw8250_platform_driver);
867871

872+
MODULE_IMPORT_NS("SERIAL_8250");
868873
MODULE_AUTHOR("Jamie Iles");
869874
MODULE_LICENSE("GPL");
870875
MODULE_DESCRIPTION("Synopsys DesignWare 8250 serial port driver");

0 commit comments

Comments
 (0)