max310x_startup() resets the FIFOs, writes the RS-485 and flow control registers, then reads the interrupt status register to clear it and enables the interrupts. The receiver runs from the moment the FIFO reset is released, so a character that arrives before the status read sets the receive status bit, and the read clears it again. That bit is an edge: with RxEmtyInv set the chip raises it when the receive FIFO goes from empty to not empty. The character stays in the FIFO, so the edge does not repeat, and since the rework this is the only receive interrupt the driver enables. No interrupt arrives and the port receives nothing until it is closed and opened again. Opening a port on a line that carries a continuous stream left it deaf in 14 of 48 attempts at 9600 baud and in nearly every attempt from 38400 baud up. Wake the interrupt thread once after the interrupts are enabled. The port handler reads the receive FIFO level besides the status register, so it picks up the character without its interrupt. On a chip with more than one port the thread only visits ports that the global interrupt register names, so mark the port in a mask that the thread takes in addition. The wake relies on the driver's own interrupt thread. Behind an interrupt controller that uses nested threading there is none, the wake does nothing and the port can still come up deaf as before. Reading the status register before the FIFO reset is released would keep the event without a wake, but after the release the register reads CTSInt, RFifoEmptyInt and TFifoEmptyInt on every open. The read after the configuration is what discards them; without it every open raises an interrupt and reports a CTS change that did not happen. Fixes: 10d8b34a4217 ("serial: max310x: Driver rework") Cc: stable@vger.kernel.org Signed-off-by: Tapio Reijonen --- A port of a MAX310x chip that is opened while characters arrive on its line can come up deaf: it receives nothing until it is closed and opened again. The commit message has the mechanism. Tested on a MAX14830 (four ports, SPI) on v7.4-rc3. A second device sends a continuous stream to the port while it is opened in four ways (plain open, open with a flush, with a termios change, with an RS-485 configuration). Without the patch, 14 of 48 opens at 9600 baud came up deaf, and almost every open from 38400 baud up. With the patch: - one port receiving, 48 opens each at 9600, 38400 and 115200 baud, run twice: 0 of 288 deaf; - the same stream on all four ports of the chip, all four opened at the same time and one opened while the other three receive, at 9600, 19200 and 38400 baud: 0 of 315 deaf; - 24 opens on an idle line: no interrupt and no CTS change counted. An alternative was tried first: reading the status register while the FIFO reset is still asserted, so that nothing can be lost afterwards. It cured the deafness as well, but the chip then reports CTSInt, RFifoEmptyInt and TFifoEmptyInt on the first status read after the interrupts are enabled, so every open raised an interrupt and reported a CTS change that did not happen. Waking the thread leaves the status handling as it is. irq_wake_thread() with a mask that the thread reads in addition to the hardware status is what pciehp_request() does with pending_events, and oa_tc6_init() wakes its thread the same way for an event that predates the handler. The patch is independent of the other MAX310x fixes on the list. The patch was written and reviewed with help from an LLM assistant (Claude), used for code reading, review of the drafts and the test scripts; the analysis, the change and the testing on hardware are mine. --- drivers/tty/serial/max310x.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c index de8a1f05cf30ed121e5d62140f2e8dccb851a4ed..cdd1655c9f35c51e0559d8c24b3bfd7c1fb79ff8 100644 --- a/drivers/tty/serial/max310x.c +++ b/drivers/tty/serial/max310x.c @@ -331,6 +331,7 @@ struct max310x_port { const struct max310x_if_cfg *if_cfg; struct regmap *regmap; struct clk *clk; + unsigned long poll_ports; /* ports to service once without an IRQ */ #ifdef CONFIG_GPIOLIB struct gpio_chip gpio; #endif @@ -1076,7 +1077,7 @@ static irqreturn_t max310x_ist(int irq, void *dev_id) WARN_ON_ONCE(regmap_read(s->regmap, MAX310X_GLOBALIRQ_REG, &val)); - irq = val; + irq = val & ~xchg(&s->poll_ports, 0); for_each_clear_bit(port, &irq, s->devtype->nr) { done = false; @@ -1539,6 +1540,7 @@ static int max310x_rs485_config(struct uart_port *port, struct ktermios *termios static int max310x_startup(struct uart_port *port) { + struct max310x_port *s = dev_get_drvdata(port->dev); struct max310x_one *one = to_max310x_port(port); unsigned int val; @@ -1595,11 +1597,19 @@ static int max310x_startup(struct uart_port *port) val = MAX310X_IRQ_RXEMPTY_BIT | MAX310X_IRQ_TXEMPTY_BIT; max310x_port_write(port, MAX310X_IRQEN_REG, val | MAX310X_IRQ_CTS_BIT); + /* + * A character received since the FIFO reset has lost its interrupt + * to the status read above: have the handler look at this port once. + */ + set_bit(one - s->p, &s->poll_ports); + irq_wake_thread(port->irq, s); + return 0; } static void max310x_shutdown(struct uart_port *port) { + struct max310x_port *s = dev_get_drvdata(port->dev); struct max310x_one *one = to_max310x_port(port); /* @@ -1612,6 +1622,7 @@ static void max310x_shutdown(struct uart_port *port) scoped_guard(spinlock_irqsave, &port->lock) one->tx_teardown = true; max310x_port_write(port, MAX310X_IRQEN_REG, 0); + clear_bit(one - s->p, &s->poll_ports); /* * Stop the transmitter: the character in flight completes, data --- base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3 change-id: 20261118-max310x-startup-irq-status-0639806a1275 Best regards, -- Tapio Reijonen