Skip to contentSkip to conversation

niu: write back TXC_INT_MASK in niu_txc_set_imask()

PATCH New Ian Rogers 2 participants 2 messages Nov 19 – Nov 23

Subsystems (2)
lore
Share & tools
lore

Ian Rogers

author
#0 lore raw

PATCH 1/1 niu: write back TXC_INT_MASK in niu_txc_set_imask()

niu_txc_set_imask() acquires the parent lock, reads TXC_INT_MASK into 'val', updates the port's interrupt mask bits in 'val', and unlocks without writing 'val' back to TXC_INT_MASK, making the function a hardware no-op and leaving per-port TXC error interrupts masked.

Write 'val' back with nw64(TXC_INT_MASK, val) before unlocking, matching niu_txc_enable_port() immediately above it.

Found via an x86_64 LLVM=1 (Clang 21.1.8) allyesconfig audit with -Wunused-but-set-variable enabled; fix and changelog drafted with an AI coding assistant. Build-tested under LLVM=1 W=1 and -Wunused-but-set-variable; not tested on Sun Neptune 10GbE hardware.

Fixes a3138df9f20e ("[NIU]: Add Sun Neptune ethernet driver.")
---
 drivers/net/ethernet/sun/niu.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/ethernet/sun/niu.c +1 -0
index c74a97fe5464..b2da560edd82 100644
@@ -4650,6 +4650,7 @@ static void niu_txc_set_imask(struct niu *np, u64 imask)
 	val = nr64(TXC_INT_MASK);
 	val &= ~TXC_INT_MASK_VAL(np->port);
 	val |= (imask << TXC_INT_MASK_VAL_SHIFT(np->port));
+	nw64(TXC_INT_MASK, val);
 	niu_unlock_parent(np, flags);
 }
 
Signature · 1 line
2.56.1.708.g77570a6a1d-goog
#1 lore raw
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 1

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] The patch makes niu_txc_set_imask() actually write TXC_INT_MASK.
- [Low] niu_init_hw() calls niu_txc_set_imask(np, 0) without first clearing any TXC_INT_STAT bits already latched for that port.

--

niu: write back TXC_INT_MASK in niu_txc_set_imask()

This patch adds the missing nw64(TXC_INT_MASK, val) to niu_txc_set_imask() so the per-port TXC interrupt mask that it computes is actually written to hardware. The only caller, niu_init_hw(), passes imask=0, so after this change all of the port's TXC error sources are unmasked.

drivers/net/ethernet/sun/niu.c static void niu_txc_set_imask(struct niu *np, u64 imask) · line 4653

Quoted 9 lines
drivers/net/ethernet/sun/niu.c +1 -0
index c74a97fe54641..b2da560edd827 100644
@@ -4650,6 +4650,7 @@ static void niu_txc_set_imask(struct niu *np, u64 imask)
 	val = nr64(TXC_INT_MASK);
 	val &= ~TXC_INT_MASK_VAL(np->port);
 	val |= (imask << TXC_INT_MASK_VAL_SHIFT(np->port));
+	nw64(TXC_INT_MASK, val);

[Severity: Medium]
With this write in place, niu_init_hw() now unmasks all six TXC sources for the port:

niu_init_hw()

    niu_txc_set_imask(np, 0);

Those sources are SF_CE, SF_UE, RO_CE, RO_UE, REORDER_ERR and PKTASM_DEAD. niu.h defines TXC_INT_STAT and its per-port bits, but nothing in niu.c reads, decodes or acknowledges that register.

What happens when one of these sources fires? The only route seems to be the SYS_ERR_STAT_TXC summary on LDN_DEVICE_ERROR. niu_ldg_init() assigns that LDN only for port 0. From there:

niu_interrupt()
niu_slowpath_interrupt()

    if (v2 & 0x0210)
        niu_device_error()     <- logs SYS_ERR_STAT, always returns -ENODEV
    if (err)
        niu_enable_interrupts(np, 0);

if (err)
goto out; <- skips niu_ldg_rearm()

Could one TXC event on any of the four ports turn off all of port 0's interrupts (RX/TX DMA, MAC, MIF) with no reset or recovery scheduled? That would also include correctable ECC events (SF_CE/RO_CE) that the hardware has already corrected.

TXC_INT_STAT is never cleared. Could the same bit fire again as soon as port 0 is re-armed on the next open?

Before this patch these sources had no effect. The commit message describes the change as restoring intended behaviour and says it was not tested on Neptune hardware. It also has a Fixes: tag, which makes it a stable candidate.

Would it be better to keep the correctable bits masked, for example:

    niu_txc_set_imask(np, TXC_INT_MASK_SF_CE | TXC_INT_MASK_RO_CE);

or to add a TXC_INT_STAT handler that acknowledges events and treats CE as non-fatal?

[Severity: Low]
Should this port's TXC_INT_STAT be cleared before the mask is opened up? Elsewhere in this driver, status is cleared before the mask is programmed:

niu_init_zcp() {
    ...
	nw64(ZCP_INT_STAT, ZCP_INT_STAT_ALL);
	(void) nr64(ZCP_INT_STAT);
	nw64(ZCP_INT_MASK, ZCP_INT_MASK_ALL);
    ...
}
niu_init_ipp() {
    ...
	(void) nr64_ipp(IPP_INT_STAT);

	nw64_ipp(IPP_MSK, ~IPP_MSK_ALL);
    ...
}

The TXC mask was never written before this patch. Any TXC status latched earlier would still be present, whether from previous operation, an earlier kernel (kexec or module reload), or OBP/firmware use.

Could that stale status assert LDN_DEVICE_ERROR as soon as port 0's LDGs are armed in niu_open(), and so lead into the niu_device_error() path described above?

Also, niu_stop_hw() never re-masks the TXC sources, and niu_txc_enable_port(np, 0) is not called anywhere. IPP and ZCP are not re-masked on stop either. However, after ifdown of ports 1-3, their TXC sources would stay armed in the shared register. The latched status is never acknowledged, and the device error LDN is bound only to port 0. Could a downed port then keep disrupting port 0?

Quoted 2 lines
drivers/net/ethernet/sun/niu.c +0 -0
 	niu_unlock_parent(np, flags);
 }
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119170623.1519909-1-irogers%40google.com