🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #24075

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

#24075
From: netdev-bot+sashiko
Date: Sun, 29 Nov 2026 07:39
244 lines
17100 bytes
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
Technical Details
Message-ID: <179593796811.3146.4950323951333239906@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373401-linux-kernel-netdev=dewy.ru
References: <20261125-t9xx_driver_v1-v13-5-92d9be5fb51e@compal.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373401-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next v13 5/6] net: wwan: t9xx: Add FSM thread
Date: Sun, 29 Nov 2026 07:39:28 +0000
Organization: Usenet Network
Message-ID: <179593796811.3146.4950323951333239906@kernel.org>
References: <20261125-t9xx_driver_v1-v13-5-92d9be5fb51e@compal.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1126679"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:524r4jSyiEWtzZKM5xgYVVoGVhk= sha256:IUFAlRZPa6cAwCyp+H9Dh+66UHsKSYNnGAXoPIDo37E=
	sha1:pupgb5lQqfiPSmoIU5A4tSdHb+Y= sha256:98PtpJIIB6s5fIdy+7eQeU4XPcsOLCr63cbSOWicALE=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id C05A4125F96; Sun, 29 Nov 2026 10:39:57 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 0GNWphbLKhO2;
	Sun, 29 Nov 2026 10:39:54 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-373401-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 9F33A125F93; Sun, 29 Nov 2026 10:39:44 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 480B42736A; Sun, 29 Nov 2026 07:39:33 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795937971;
	b=ymHEqI4wtWNoHB1Y7D9dCVyAHj4xtuvk7piX7Cfu6/AJTr8ckFtGwa2EbbwXe08P/Y9u
	 Xa+dKFeGBNVa+MICL+vxD6sdtT5gyp6Z1Al+q+Ij8x6DCsqSpBqmUGlcqnZ7WQ+eTJ1Wt
	 ciYJxWeabPvJukccC2yAUP35dqzotsv90bi5XsUb/XtE9HFRvxFZRHxtUbgRh8j1r78J8
	 Hfoo8DWeXq6UxNmAOv4uauMf7zTE8GknAUPPxe5jin7harxYf4KKvv+wLMDONdQa31UOV
	 FM/gl1l9tNuaLlWgWPMe97oIbyfk7Hz5T1fEBZPmly6/bLwQ56IDYdkCCfQ1JR2xW2A==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795937971;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=kNTNZBLC1ZG3T6kKzbimLkbsgYWEEV+ZNeyrGc8QOJg=;
	b=HLFY+pqXYYXHqLLv2bbKvO04pzc8eJPNfbLINTz/+bo5GIRkWD5kLD1W6ycs2O+T+pgr
	 qqe2FBanpWTQUAZ3FW/CqWvC1Jnpj0nMa5XDhjgrrybwuWFZX7UUOo5tlNq7qRAxbzMzE
	 IssMx0BgLSSrifHWiMaoGeG86t5Dtt6Q0wfLMHDL4U7kH8iosRVHXOUQbXKpL7U27zB+e
	 IBbt8wd536HFenXxF47vaKmfAEsiX2HY5vkb44j8S7yRJPWfFXwlG91rUYP6gJ8ILqJEc
	 Vicv1Ngr32gze9BlotPRhCFtggzwjBXNCczI3ZzoFQqguPwDo433JCW36pKYhGmTw4w==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=eoUd8Aue;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 1B7BB606A697;
	Sun, 29 Nov 2026 07:39:31 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=eoUd8Aue
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795937970;
	b=hs0RKnYWuEOrb3M2sE4nQa6VtAGqT2970uEU/ssQWYK30GY2cYEdPObxBca5bH2fthPx
	 oK+ENPk7B2Yn6LzBUXtF7DfxWgSWkvx94keiEFW6Z7gFvT5l89QEPI8ECh7oXHDyQqeIs
	 oaBJhV9nldOpwZJbJcVt4OeXJdLUbGQvN1QpBj8BoIXyrwNp51EPKq+QGS7AdcXzg5yu3
	 iIKt3BBh//F2oL+7kpMzYsVuCCiglw+ZFzzsNic0HkClYh6/LPx0kc5sWhfQlsB6jTPHy
	 SP9rglu9y10CRp92ia0HidwhLZmoYg7KArfQ2gtHahlWqVSrpQMOoNNg5GT+frIhEng==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795937970;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=kNTNZBLC1ZG3T6kKzbimLkbsgYWEEV+ZNeyrGc8QOJg=;
	b=c1hSjLE6qm75aLhXB14j8aAn55n/TTsVqimfu3rMWag7CEvIj0IlAZxylMsjqo2SMVxs
	 c466khzAXuQocbO4IAMcXXE24/OgQhbs2pu2qWnfZc/KAQTxytO8XXOIt257nEQIf4QjB
	 kcPgJUkTiyVXRPVMLgFeMPVIr23I+1kLM4B8rPmDEjJIKBHegqzhwh9AO9xJEcPmXjVGg
	 4fnRoJRxGK+fKGLD1314C3ihuYu8TJiHUWUiaWWpZY2jhpRGbUgVGQtk1xModLqk5vzZh
	 /nN8ew/DGjM2tYuZ6GwUBkC+ia19AKuCMgG7Tc8m5VYjePMMcgSDL++T45s121kQJfQ==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=eoUd8Aue;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3B65C606A335;
	Sun, 29 Nov 2026 07:39:29 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8C0E51F00925;
	Sun, 29 Nov 2026 07:39:28 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795937969;
	bh=kNTNZBLC1ZG3T6kKzbimLkbsgYWEEV+ZNeyrGc8QOJg=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=eoUd8AuelP5dqp6LrQ9DeETNcZwg6PCl/bERsF5opdnkQyUGKZnbd+mN/OZFd3Y4n
	 3pzI5tAKvuu2bclZAwXwBI1DCupQsz110XgNJazDxPe7+gzW+JPvJc6LxH/SUncJGp
	 0HmXrA4l8ckC2oofSa7MvNwlv6IXgpkAitvQ8AiIDVL5Z91cwIEy/5O0Ta7CzKgUBB
	 rqbYa1OJmh8fHuFwcU2TpqQ5rVQU6PiRgSJuMWwmWLzGYccbRAhpJ1Wiy/94t5j9Kq
	 jb4yPRtvbqPgkSxoA7S07U1Lhj8yqi9luN4nlewo/mhAW8KYirEfNQdrqH5lETZGcX
	 zaj6gcWbyLPaA==
X-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
X-In-Reply-To: <20261125-t9xx_driver_v1-v13-5-92d9be5fb51e@compal.com>
X-sashiko-severity: Low
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list