mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: jackbb_wu@compal.com
Cc: loic.poulain@oss.qualcomm.com, ryazanov.s.a@gmail.com,
	johannes@sipsolutions.net, andrew+netdev@lunn.ch,
	davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com,
	wen-zhi.huang@mediatek.com, shi-wei.yeh@mediatek.com,
	Minano.tseng@mediatek.com, matthias.bgg@gmail.com,
	angelogioacchino.delregno@collabora.com, horms@kernel.org,
	corbet@lwn.net, skhan@linuxfoundation.org, robert_yu@compal.com,
	Jeff_Chang@compal.com, edumazet@kernel.org,
	linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org, linux-doc@vger.kernel.org
Subject: Re: [PATCH net-next v13 5/6] net: wwan: t9xx: Add FSM thread
Date: Sun, 29 Nov 2026 07:39:28 +0000	[thread overview]
Message-ID: <179593796811.3146.4950323951333239906@kernel.org> (raw)
In-Reply-To: <20261125-t9xx_driver_v1-v13-5-92d9be5fb51e@compal.com>

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.

> 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 @@

[ ... ]

> +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");
> +

[ ... ]

> +	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)
> +{

[ ... ]

> +	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)
> +{

[ ... ]

> +	/* 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;
> +	}

[ ... ]

> +	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?

[ ... ]

> 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

[ ... ]

> @@ -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)
> +{

[ ... ]

> +	/* 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

  reply	other threads:[~2026-11-29  7:39 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25  6:27 [PATCH net-next v13 0/6] net: wwan: t9xx: Add MediaTek T9XX WWAN driver Jack Wu via B4 Relay
2026-11-25  6:27 ` [PATCH net-next v13 1/6] net: wwan: t9xx: Add PCIe core Jack Wu via B4 Relay
2026-11-29  7:39   ` netdev-bot+sashiko
2026-11-25  6:27 ` [PATCH net-next v13 2/6] net: wwan: t9xx: Add control plane transaction layer framework Jack Wu via B4 Relay
2026-11-25  6:27 ` [PATCH net-next v13 3/6] net: wwan: t9xx: Add control DMA interface Jack Wu via B4 Relay
2026-11-29  7:39   ` netdev-bot+sashiko
2026-11-25  6:27 ` [PATCH net-next v13 4/6] net: wwan: t9xx: Add control port Jack Wu via B4 Relay
2026-11-29  7:39   ` netdev-bot+sashiko
2026-11-25  6:27 ` [PATCH net-next v13 5/6] net: wwan: t9xx: Add FSM thread Jack Wu via B4 Relay
2026-11-29  7:39   ` netdev-bot+sashiko [this message]
2026-11-25  6:27 ` [PATCH net-next v13 6/6] net: wwan: t9xx: Add AT & MBIM WWAN ports Jack Wu via B4 Relay

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179593796811.3146.4950323951333239906@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=Jeff_Chang@compal.com \
    --cc=Minano.tseng@mediatek.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=jackbb_wu@compal.com \
    --cc=johannes@sipsolutions.net \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=loic.poulain@oss.qualcomm.com \
    --cc=matthias.bgg@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=robert_yu@compal.com \
    --cc=ryazanov.s.a@gmail.com \
    --cc=shi-wei.yeh@mediatek.com \
    --cc=skhan@linuxfoundation.org \
    --cc=wen-zhi.huang@mediatek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®