Re: [PATCH net-next v13 5/6] net: wwan: t9xx: Add FSM thread

From
netdev-bot+sashiko@kernel.org
Date
2026-11-29 07:39:29
Also in
linux-arm-kernel, linux-doc, linux-mediatek, lkml
Reply to
Jack Wu via B4 Relay, 2026-11-25
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The commit message contradicts what mtk_fsm_startup_act()
  (drivers/net/wwan/t9xx/mtk_fsm.c) does before READY.
- [Low] mtk_cldma_dev_exit() (drivers/net/wwan/t9xx/pcie/mtk_cldma.c)
  deliberately calls dma_pool_destroy(drv_info->gpd_dma_pool) while the…
- [Low] mtk_fsm_early_bootup_handler() (drivers/net/wwan/t9xx/mtk_fsm.c)
  only skips a notification when the whole 32-bit device-state word is…

--

net: wwan: t9xx: Add FSM thread

This adds an FSM kthread to the t9xx WWAN driver. The thread sequences
device and OS events, runs the HS1/HS2/HS3 runtime feature handshake for
MD and SAP, and notifies the port manager and transport layer of each
state change. CLDMA bring-up and teardown now follow FSM transitions, and
the patch also adds a queue error recovery worker and a quiesce step on
teardown.
quoted hunk ↗ jump to hunk
diff --git a/drivers/net/wwan/t9xx/mtk_fsm.c b/drivers/net/wwan/t9xx/mtk_fsm.c
new file mode 100644
index 0000000000000..bdb4ac75cc039
--- /dev/null
+++ b/drivers/net/wwan/t9xx/mtk_fsm.c
@@ -0,0 +1,1011 @@
[ ... ]
quoted hunk ↗ jump to hunk
+static void mtk_fsm_idle_evt_handler(struct mtk_md_dev *mdev,
+				     u32 dev_state, struct mtk_md_fsm *fsm)
+{
+	u32 dev_cfg = dev_state >> DEVICE_CFG_SHIFT & DEVICE_CFG_REGION_MASK;
+	int hs_id;
+
+	if (dev_cfg == DEV_CFG_MD_ONLY)
+		WRITE_ONCE(fsm->hs_done_flag, FSM_F_MD_HS_START | FSM_F_MD_HS2_DONE);
+	else
+		WRITE_ONCE(fsm->hs_done_flag, FSM_HS_START_MASK | FSM_HS2_DONE_MASK);
+
+	if (mtk_fsm_evt_submit(mdev, FSM_EVT_STARTUP, FSM_F_DFLT,
+			       NULL, 0))
+		dev_err(mdev->dev, "Failed to submit STARTUP evt\n");
+
[ ... ]
quoted hunk ↗ jump to hunk
+	for (hs_id = 0; hs_id < HS_ID_MAX; hs_id++)
+		mtk_fsm_unmask_ext_evt(fsm, fsm->hs_info[hs_id].mhccif_ch);
+}
+
+static void mtk_fsm_early_bootup_handler(u32 status, void *__fsm)
+{
[ ... ]
quoted hunk ↗ jump to hunk
+	if (dev_state == fsm->last_dev_state)
+		goto exit;
+
+	if (dev_stage == DEV_STAGE_IDLE)
+		mtk_fsm_idle_evt_handler(mdev, dev_state, fsm);
+
+	fsm->last_dev_state = dev_state;
[Severity: Low]
Can the IDLE work run more than once per boot? The duplicate check
compares the whole 32-bit state word. The call to
mtk_fsm_idle_evt_handler() depends only on the stage nibble.

Suppose firmware changes some other bit of REG_PCIE_DEBUG_DUMMY_7 (for
example the dev_cfg field at bits 24-25) while the stage stays
DEV_STAGE_IDLE, and raises BOOT_FLOW_SYNC again. Then
mtk_fsm_idle_evt_handler() runs a second time and:

- rewrites fsm->hs_done_flag in the middle of a handshake.
  mtk_fsm_startup_act() re-reads that flag to decide READY, so a switch
  from MD-only to full would leave READY waiting for a SAP handshake that
  never comes.
- queues another bare STARTUP, which is refused with -EPROTO once the FSM
  is READY.
- unmasks both HS notify channels that mtk_fsm_hs1_handler() masked
  "until the device boots again".

mtk_mhccif_isr_work() only acks unmasked status bits:

    stat &= ~mask;
    if (stat)
        mtk_pci_ack_ext_evt_hw(mdev, stat);

Could a notify that latched while the channel was masked then be
delivered after the unmask? In BOOTUP that would restart that side's
handshake and clear its HS2_DONE bit.

This depends on firmware behaviour I can't check from the tree, and the
comment says the device notifies once per boot stage. Would it make sense
to record that the IDLE work has already run for this boot?

[ ... ]
+static int mtk_fsm_startup_act(struct mtk_md_fsm *fsm, struct mtk_fsm_evt *event)
+{
[ ... ]
quoted hunk ↗ jump to hunk
+	/* The device signals its own reboot with a separate reset interrupt;
+	 * a handshake event outside ON/BOOTUP is not a restart request and is
+	 * refused.
+	 */
+	if (fsm->state != FSM_STATE_ON && fsm->state != FSM_STATE_BOOTUP) {
+		ret = -EPROTO;
+		goto free_skb;
+	}
[ ... ]
quoted hunk ↗ jump to hunk
+	if (event->fsm_flag & FSM_HS_START_MASK) {
+		/* An HS1 that raced ahead of the bare STARTUP must both
+		 * switch ON to BOOTUP and run the handshake below; returning
+		 * after the switch would consume the only trigger.
+		 * A side that sends HS1 again before READY has booted again:
+		 * its earlier HS2 no longer counts.
+		 */
+		fsm->fsm_flag &= ~hs_info->fsm_flag_hs2;
+		mtk_fsm_switch_state(fsm, to_state, event);
+
+		ret = mtk_fsm_ctrl_ch_start(fsm, hs_info, O_NONBLOCK);
+		if (!ret)
+			ret = mtk_fsm_send_hs1_msg(hs_info);
+		if (ret)
+			goto hs_err;
[Severity: Low]
Does this match the commit message? It says:

    The device sends HS1 once per boot and does not retry a failed
    handshake; it starts again only after a modem reset, which removal
    performs. A modem that reboots on its own announces it with a
    separate reset interrupt, and recovery is driven from that interrupt,
    not from the new handshake.

Here, a second HS1 that arrives while the FSM is in BOOTUP is treated as
a device reboot. That side's HS2_DONE bit is cleared, the FSM re-enters
BOOTUP, and the whole handshake runs again. That looks like recovery
driven from the new handshake.

The path would be mtk_fsm_early_bootup_handler()->
mtk_fsm_idle_evt_handler(), which unmasks the HS channels on the new
IDLE. mtk_fsm_hs1_handler() then submits STARTUP with the HS_START flag.

The re-run also seems to reuse host-side state from the previous boot.
mtk_fsm_ctrl_ch_start() skips the open because hs_info->ctrl_port is
still set:

    if (!hs_info->ctrl_port) {
        hs_info->ctrl_port = mtk_port_internal_open(...);

mtk_cldma_dev_init() also returns early for the existing instance:

    if (cd->cldma_drv_info[hif_id])
        return 0;

The control port's enable resets tx_seq/rx_seq, but mtk_cldma_open()
returns -EBUSY because the queues still exist. Recovery would then rely
on mtk_cldma_start_xfer() reading a zero TX start address and calling
mtk_cldma_hw_recovery().

Is this pre-READY restart path intended? If so, could the commit message
describe it, and how the CLDMA queues are expected to recover?

[ ... ]
quoted hunk ↗ jump to hunk
diff --git a/drivers/net/wwan/t9xx/pcie/mtk_cldma.c b/drivers/net/wwan/t9xx/pcie/mtk_cldma.c
index d1472b6759746..aa72d7b46d031 100644
--- a/drivers/net/wwan/t9xx/pcie/mtk_cldma.c
+++ b/drivers/net/wwan/t9xx/pcie/mtk_cldma.c
[ ... ]
quoted hunk ↗ jump to hunk
@@ -788,9 +1025,110 @@ static int mtk_cldma_hw_recovery(struct cldma_drv_info *drv_info, u32 qno)
[ ... ]
+static int mtk_cldma_dev_exit(struct cldma_dev *cd, int hif_id)
+{
[ ... ]
quoted hunk ↗ jump to hunk
+	/* Best-effort: reset the IP so it drops its queue state before the
+	 * descriptor memory goes away.  Not guaranteed to stop the engine,
+	 * hence ring_leaked.
+	 */
+	mtk_cldma_drv_reset(drv_info);
+	/* A handler retired by the quiesce may have unmasked the vector on
+	 * its way out, and nothing handles it any more: leave it masked.
+	 */
+	mtk_pci_mask_irq(mdev, drv_info->pci_ext_irq_id);
+
+	if (drv_info->ring_leaked)
+		dev_err(mdev->dev, "CLDMA%d rings leaked\n", drv_info->hw_id);
+	/* The leaked rings keep the pool busy: it keeps its pages and only its
+	 * bookkeeping is freed.  Not destroying it would leak the same pages
+	 * and the pool.
+	 */
+	dma_pool_destroy(drv_info->gpd_dma_pool);
[Severity: Low]
Is it safe to call dma_pool_destroy() here while the pool still has
blocks handed out? When mtk_cldma_txq_free() or mtk_cldma_rxq_free() hits
a stop timeout, it sets ring_leaked and returns without calling
dma_pool_free() on the ring's GPDs. The device may still be walking those
descriptors.

The documented contract in mm/dmapool.c says:

    * Caller guarantees that no more memory from the pool is in use,
    * and that nothing will try to use the pool after this call.

The comment here, and the commit message ("dma_pool_destroy() does not
free the pages of a pool that still has blocks outstanding"), rely on the
current implementation skipping dma_free_coherent() when pool->nr_active
is non-zero. That looks like defensive handling of caller bugs rather
than an API guarantee.

This path also:

- prints the "dma_pool_destroy ... busy" error on every such teardown.
- leaks every page of the pool, not only the leaked rings.
- with CONFIG_DMA_API_DEBUG, reports pending allocations at unbind.

If dmapool ever frees pages on a busy destroy, the device could DMA into
freed coherent memory.

Would it be better to skip dma_pool_destroy() and leave the pool allocated
together with the rings when ring_leaked is set?

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125-t9xx_driver_v1-v13-0-92d9be5fb51e%40compal.com
Thread (11 messages) 11 messages, 2 authors, last reply 6h ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help