[PATCH v1 06/31] serial: 8250_mxupci: add custom handle_irq()

Crescent Hsieh posted 31 patches 1 day, 11 hours ago
[PATCH v1 06/31] serial: 8250_mxupci: add custom handle_irq()
Posted by Crescent Hsieh 1 day, 11 hours ago
Add a custom handle_irq() for 8250_mxupci based on serial8250_handle_irq(),
removing PM wakeup and DMA handling that are not needed.

This prepares for future adjustments to RX and TX behavior specific to
Moxa MU860 UART.

Signed-off-by: Crescent Hsieh <crescentcy.hsieh@moxa.com>
---
 drivers/tty/serial/8250/8250_mxupci.c | 36 +++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/drivers/tty/serial/8250/8250_mxupci.c b/drivers/tty/serial/8250/8250_mxupci.c
index 99bd3e504549..376c6d6135a3 100644
--- a/drivers/tty/serial/8250/8250_mxupci.c
+++ b/drivers/tty/serial/8250/8250_mxupci.c
@@ -212,6 +212,41 @@ static void mxupci8250_unthrottle(struct uart_port *port)
 	uart_port_unlock_irqrestore(port, flags);
 }
 
+static int mxupci8250_handle_irq(struct uart_port *port)
+{
+	struct uart_8250_port *up = up_to_u8250p(port);
+	bool skip_rx = false;
+	unsigned long flags;
+	u16 lsr;
+	u8 iir;
+
+	iir = serial_in(up, UART_IIR);
+
+	if (iir & UART_IIR_NO_INT)
+		return 0;
+
+	uart_port_lock_irqsave(port, &flags);
+
+	lsr = serial_lsr_in(up);
+
+	if (!(lsr & (UART_LSR_FIFOE | UART_LSR_BRK_ERROR_BITS)) &&
+	    (port->status & (UPSTAT_AUTOCTS | UPSTAT_AUTORTS)) &&
+	    !(port->read_status_mask & UART_LSR_DR))
+		skip_rx = true;
+
+	if (lsr & (UART_LSR_DR | UART_LSR_BI) && !skip_rx)
+		lsr = serial8250_rx_chars(up, lsr);
+
+	serial8250_modem_status(up);
+
+	if ((lsr & UART_LSR_THRE) && (up->ier & UART_IER_THRI))
+		serial8250_tx_chars(up);
+
+	uart_unlock_and_check_sysrq_irqrestore(port, flags);
+
+	return 1;
+}
+
 static int mxupci8250_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 {
 	struct uart_8250_port up;
@@ -248,6 +283,7 @@ static int mxupci8250_probe(struct pci_dev *pdev, const struct pci_device_id *id
 	up.port.shutdown = mxupci8250_shutdown;
 	up.port.throttle = mxupci8250_throttle;
 	up.port.unthrottle = mxupci8250_unthrottle;
+	up.port.handle_irq = mxupci8250_handle_irq;
 
 	for (i = 0; i < num_ports; i++) {
 		if (serial8250_pci_setup_port(pdev, &up, FL_GET_BASE(FL_BASE2), i * MOXA_UART_OFFSET, 0))
-- 
2.45.2
Re: [PATCH v1 06/31] serial: 8250_mxupci: add custom handle_irq()
Posted by Andy Shevchenko 1 day, 4 hours ago
On Sun, Nov 30, 2025 at 12:43 PM Crescent Hsieh
<crescentcy.hsieh@moxa.com> wrote:
>
> Add a custom handle_irq() for 8250_mxupci based on serial8250_handle_irq(),
> removing PM wakeup and DMA handling that are not needed.
>
> This prepares for future adjustments to RX and TX behavior specific to
> Moxa MU860 UART.

...

> +static int mxupci8250_handle_irq(struct uart_port *port)
> +{
> +       struct uart_8250_port *up = up_to_u8250p(port);
> +       bool skip_rx = false;
> +       unsigned long flags;
> +       u16 lsr;
> +       u8 iir;
> +
> +       iir = serial_in(up, UART_IIR);

> +

Stray blank line addition.

> +       if (iir & UART_IIR_NO_INT)
> +               return 0;
> +
> +       uart_port_lock_irqsave(port, &flags);
> +
> +       lsr = serial_lsr_in(up);

> +

Ditto.

> +       if (!(lsr & (UART_LSR_FIFOE | UART_LSR_BRK_ERROR_BITS)) &&
> +           (port->status & (UPSTAT_AUTOCTS | UPSTAT_AUTORTS)) &&
> +           !(port->read_status_mask & UART_LSR_DR))
> +               skip_rx = true;
> +
> +       if (lsr & (UART_LSR_DR | UART_LSR_BI) && !skip_rx)
> +               lsr = serial8250_rx_chars(up, lsr);
> +
> +       serial8250_modem_status(up);
> +
> +       if ((lsr & UART_LSR_THRE) && (up->ier & UART_IER_THRI))
> +               serial8250_tx_chars(up);
> +
> +       uart_unlock_and_check_sysrq_irqrestore(port, flags);
> +
> +       return 1;
> +}

-- 
With Best Regards,
Andy Shevchenko