Skip to contentSkip to conversation

serial: pmac_zilog: two receive fixes

PATCH New Tim Douglas 2 participants 5 messages Oct 13

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover serial: pmac_zilog: two receive fixes

These two patches fix receive problems in pmac_zilog that I ran into while bringing up the serial ports on a Performa 6200CD, a NuBus Power Macintosh. The first stops data received on one port from being left in its flip buffer while the other port is open. The second makes received breaks visible; until now they arrived as plain NUL characters.

I tested both on the 6200, running 7.2.8 with an out-of-tree platform port and a loopback plug on the printer port. Without the series, only 3 of 8 bytes written to ttyPZ1 came back while ttyPZ0 was open, and a break sent with tcsendbreak() arrived as a NUL with no break counted. With the series, all 8 bytes came back, the break was counted, and with PARMRK set it read as FF 00 00.

The series also builds on v7.3-rc7 with pmac32_defconfig and W=1 without warnings. I have not tested 68k Macs or macio Power Macs.

I found these bugs and wrote the patches with the help of Claude Opus 5.5. I have reviewed both patches and run the tests on the 6200 myself.

Tim Douglas (2):
serial: pmac_zilog: push received data to the port that received it
serial: pmac_zilog: report received breaks

 drivers/tty/serial/pmac_zilog.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

base-commit: 24a19b953e2a3d0ea5a8c4951a0ab8f32720c907

Signature · 1 line
2.54.0 (Apple Git-157)
#1 lore raw

PATCH 1/2 serial: pmac_zilog: push received data to the port that received it

pmz_interrupt() drains both channels but, since commit 2e124b4a390c ("TTY: switch tty_flip_buffer_push"), pushes the flip buffer of the port whose handler is running rather than the port that was drained. With both ports open, data received on the other port can be left in its flip buffer until something else pushes it, so its reader may not see it.

Fixes 2e124b4a390c ("TTY: switch tty_flip_buffer_push")
Assisted-by LLM
---
 drivers/tty/serial/pmac_zilog.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/tty/serial/pmac_zilog.c +2 -2
index e3a9193..f49d605 100644
@@ -444,7 +444,7 @@ static irqreturn_t pmz_interrupt(int irq, void *dev_id)
  skip_a:
 	uart_port_unlock(&uap_a->port);
 	if (push)
-		tty_flip_buffer_push(&uap->port.state->port);
+		tty_flip_buffer_push(&uap_a->port.state->port);
 
 	if (!uap_b)
 		goto out;
@@ -469,7 +469,7 @@ static irqreturn_t pmz_interrupt(int irq, void *dev_id)
  skip_b:
 	uart_port_unlock(&uap_b->port);
 	if (push)
-		tty_flip_buffer_push(&uap->port.state->port);
+		tty_flip_buffer_push(&uap_b->port.state->port);
 
  out:
 	return rc;
Signature · 1 line
2.54.0 (Apple Git-157)
#2 lore raw

Re: [PATCH 1/2] serial: pmac_zilog: push received data to the port that received it

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 11 lines

pmz_interrupt() drains both channels but, since commit 2e124b4a390c ("TTY: switch tty_flip_buffer_push"), pushes the flip buffer of the port whose handler is running rather than the port that was drained. With both ports open, data received on the other port can be left in its flip buffer until something else pushes it, so its reader may not see it.

Fixes 2e124b4a390c ("TTY: switch tty_flip_buffer_push")
Assisted-by LLM

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw

PATCH 2/2 serial: pmac_zilog: report received breaks

In reply to Tim Douglas

pmz_status_handle() sets PMACZILOG_FLAG_BREAK from RR0, and pmz_receive_chars() clears it on the null character that ends the break without marking that character, then tests BRK_ABRT in RR1, where the SCC does not set it in asynchronous mode. Breaks therefore arrive as plain NULs: brk is never counted and BRKINT, PARMRK and SysRq never see them.

Set BRK_ABRT in r1 for that character, as sunzilog does.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
Assisted-by LLM
---
 drivers/tty/serial/pmac_zilog.c | 1 +
 1 file changed, 1 insertion(+)
drivers/tty/serial/pmac_zilog.c +1 -0
index f49d605..a612f1d 100644
@@ -233,6 +233,7 @@ static bool pmz_receive_chars(struct uart_pmac_port *uap)
 		ch &= uap->parity_mask;
 		if (ch == 0 && uap->flags & PMACZILOG_FLAG_BREAK) {
 			uap->flags &= ~PMACZILOG_FLAG_BREAK;
+			r1 |= BRK_ABRT;
 		}
 
 #if defined(CONFIG_MAGIC_SYSRQ) && defined(CONFIG_SERIAL_CORE_CONSOLE)
Signature · 1 line
2.54.0 (Apple Git-157)
#4 lore raw

Re: [PATCH 2/2] serial: pmac_zilog: report received breaks

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] tty: serial: false break injection on NUL after Rx overrun --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] tty: serial: false break injection on NUL after Rx overrun
--

commit 009d6cf5b2db60250bcc44251e6de09814cc2746
Author: Tim Douglas <[email protected]>

serial: pmac_zilog: report received breaks

This commit modifies pmz_receive_chars() to set the BRK_ABRT flag in r1 when processing the null character that ends a break. This allows breaks to be properly counted and passed to BRKINT, PARMRK, and SysRq handlers, matching the behavior of sunzilog.

drivers/tty/serial/pmac_zilog.c static bool pmz_receive_chars(struct uart_pmac_port *uap) · line 237

Quoted 10 lines
drivers/tty/serial/pmac_zilog.c +1 -0
index f49d6052d11be..a612f1db9f189 100644
@@ -233,6 +233,7 @@ static bool pmz_receive_chars(struct uart_pmac_port *uap)
 		ch &= uap->parity_mask;
 		if (ch == 0 && uap->flags & PMACZILOG_FLAG_BREAK) {
 			uap->flags &= ~PMACZILOG_FLAG_BREAK;
+			r1 |= BRK_ABRT;
 		}

[Severity: Medium]
Does this code risk injecting a false Break event if an Rx FIFO overrun occurs?

pmz_status_handle() sets PMACZILOG_FLAG_BREAK when it receives an EXT status interrupt for a Break. Then pmz_receive_chars() waits for the associated NUL character to clear the flag.

If an Rx FIFO overrun occurs and the hardware drops the expected NUL character, the PMACZILOG_FLAG_BREAK flag will remain set indefinitely.

Since BRK_ABRT is now artificially injected into r1 when this flag is finally cleared, could a subsequent, perfectly valid NUL character (such as Ctrl-@) arriving much later falsely trigger a Break?

This might cause dropped data or trigger an unintended SysRq. Before this patch, the stuck flag was harmless because it was cleared without altering r1.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2