From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796291203; b=cpol9UhLAQHii4kxEuhkMWnPMqXgTdWX2Etb0wyT7idye191+Gdbptr54ZBgx5PryBSO jLCcOjD471A2cGkkhJdBtrJ9u3nczQnyRGx3S2OGStcucnAN3UORoHYe+/2IHKqLcZii3 Vc6fG2egmB2aF0SG+Hz11kS/y/kMMHKX9SfsmzRkc7IhCoKW/uZgfNEc6PDuZtHrFHmDb wQVHEmaYgnDmPd8uZUnfbA5YU0/Gh5WIgHNP1m9zcz/iuPzVdc85y+dpG2Ssigwq30gMk uKa1PREEp5WDEkZJmJj6kzfXemetryQz1KYlQ23P1eOBYP3Lu2Rqu9HGKn412jVYEIg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796291203; 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=MMKIBUJij69HTF98A89K3bMFiRdCWdxS0A142OxZSGY=; b=s/g73qfXsqDiADZBsVscVM8b7FKYOybE1n7pXMZwlqqUNEbCIdHpWT+i3g31VI/WJQCO m9aGkqDQhwAjRozI+Fio2A5mU9iR/OyUmrY9IciGMIoeXk78ijvwM/E8zsAjOe9VwNbrK hvuMAsCi/B2652Hp5022PS2gPfhx1hTAaoEZ3sg27IseZj+gbtdH3DCIBAsCECLyMyiE/ 16+acmrBiO+7cx4pU2lsPr8g2il4O6sGlarkmKxGl8yFtNxTrYYWcaMKopU5gEYhj5Fh6 Jfo73N6um+GQy1Ln86/BQ5Bwcj54wjA3gvVT362QT0/Lq9qEyOZCPpDxX/EkuV+fXNA== 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="S/E+Z+Is"; arc=none smtp.remote-ip=100.103.45.18 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 82E91606A69C; Thu, 3 Dec 2026 09:46:43 +0000 (UTC) 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=S/E+Z+Is Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28FB01F00898; Thu, 3 Dec 2026 09:46:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796291203; bh=MMKIBUJij69HTF98A89K3bMFiRdCWdxS0A142OxZSGY=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=S/E+Z+Is7MTzUXXzbAlTggEobwh5CWo9Rck24BS49SMekAnWlOm1lzUGV1L763gMK jGAKT6755VGw9HD9AFT42P8zBngDb866BwCoG4nzmt0Y4cOY+skdE6+ZWtr7NFKPmV qIxdzByxmysuRXAF1uWLILbiv2pnjDNjVX2NYE08pW+4hZQT39HIfzsYvOyajm6Q3q 4fUYOcIBnfcVuZwjy2pAt/NWOjLRIGbg51c1l8Kfd4ut2RPvLxp/ZEK3OWdFeX8qK4 e9VWnbS/7zzd8pgA4jppAPjjqdtSmGW3JNhXtrjn0nlu9QKOooqRZELAWjDNg7IEKf k7UkI+aT+bgZA== Subject: Re: [PATCH net-next v14 5/6] net: wwan: t9xx: Add FSM thread 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 Date: Thu, 03 Dec 2026 09:46:41 +0000 Message-ID: <179629120173.3146.3576973350427912504@kernel.org> In-Reply-To: <20261202-t9xx_driver_v1-v14-5-08ebc870ea94@compal.com> References: <20261202-t9xx_driver_v1-v14-5-08ebc870ea94@compal.com> X-sashiko-severity: Medium Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider. Critical: 0 · High: 0 · Medium: 4 · 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] If the bare STARTUP from the IDLE report cannot be queued, the earlier boot's HS2_DONE bits stay set. - [Medium] The stale-HS2 check in mtk_fsm_startup_act() is a check-then- act race. - [Medium] The free paths mask a queue's L2 QUEUE_ERROR/XFER_DONE sources but never clear status latched while they were masked, and the alloc… - [Medium] net: wwan: t9xx: TX queue stop timeout stalls TRB thread when ring is full - [Low] Some comments describe a TX queue whose stop failed as down for good, but the code can bring it back. -- net: wwan: t9xx: Add FSM thread This adds an FSM kthread that serializes device and OS events. It drives the HS1/HS2/HS3 runtime feature handshake for the MD and SAP sides, and it moves port manager and CLDMA bring-up/teardown onto FSM state transitions. It also registers the CLDMA IRQ, adds err_work for queue error recovery, and reorders HIF teardown around a new mtk_cldma_quiesce(). > diff --git a/drivers/net/wwan/t9xx/mtk_fsm.c b/drivers/net/wwan/t9xx/mtk_fsm.c > new file mode 100644 > index 0000000000000..06921251cbfb4 > --- /dev/null > +++ b/drivers/net/wwan/t9xx/mtk_fsm.c > @@ -0,0 +1,1029 @@ [ ... ] > +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); > + > + /* Only an IDLE reached from an earlier stage starts a new boot's > + * handshake round; another report within IDLE queues nothing. > + */ > + if ((fsm->last_dev_state & REGION_BITMASK) != DEV_STAGE_IDLE) { > + WRITE_ONCE(fsm->boot_seq, fsm->boot_seq + 1); > + if (mtk_fsm_evt_submit(mdev, FSM_EVT_STARTUP, FSM_F_DFLT, NULL, 0)) > + dev_err(mdev->dev, "Failed to submit STARTUP evt\n"); > + } > + > + /* The notification carrying this state is one-shot, so there is no > + * retry to wait for: open the handshake channels whether or not the > + * STARTUP above was queued. A bare HS1 drives ON->BOOTUP as well. > + */ > + for (hs_id = 0; hs_id < HS_ID_MAX; hs_id++) > + mtk_fsm_unmask_ext_evt(fsm, fsm->hs_info[hs_id].mhccif_ch); > +} [Severity: Medium] If mtk_fsm_evt_submit() fails here, for example because kzalloc_obj() returns NULL, what clears the HS2_DONE bits recorded for the earlier boot? For a new boot, the only code that drops them is the bare STARTUP branch of mtk_fsm_startup_act(): if (fsm->state != FSM_STATE_BOOTUP) mtk_fsm_switch_state(fsm, to_state, event); else fsm->fsm_flag &= ~FSM_HS2_DONE_MASK; A new HS1 clears only its own side's bit: fsm->fsm_flag &= ~hs_info->fsm_flag_hs2; Take an MD+SAP device in BOOTUP. SAP has finished HS1/HS2 and MD has sent HS1. The modem reboots and reports IDLE, and the STARTUP allocation fails. boot_seq is still bumped and both channels are still unmasked. The new MD HS1 and HS2 then complete and set MD_HS2_DONE. The READY test passes because SAP_HS2_DONE is still set from the earlier boot: hs_done_flag = READ_ONCE(fsm->hs_done_flag); if (((fsm->fsm_flag | event->fsm_flag) & hs_done_flag) == hs_done_flag) { When the new boot's SAP HS1 arrives, the FSM is in READY and the HS1 is refused with -EPROTO. Would the SAP control path then stay down while the FSM reports READY? This also seems to contradict the commit message: Before READY, the IDLE report of the new boot drops the HS2 results recorded so far Could the HS2_DONE bits be dropped in a way that does not depend on the event allocation succeeding? [ ... ] > +static int mtk_fsm_startup_act(struct mtk_md_fsm *fsm, struct mtk_fsm_evt *event) > +{ [ ... ] > + } else if (event->fsm_flag & FSM_HS2_DONE_MASK) { > + /* This side's HS1 was handled before the device last reported > + * a new boot, so the HS2 answers the earlier boot's handshake. > + */ > + if (hs_info->boot_seq != READ_ONCE(fsm->boot_seq)) { > + dev_warn(mdev->dev, "HS2 of an earlier boot (hs%d), dropping\n", > + hs_info->id); > + dev_kfree_skb(skb); > + return 0; > + } > + if (fsm->fsm_flag & event->fsm_flag) { > + dev_warn(mdev->dev, "Duplicate HS2 (hs%d), dropping\n", hs_info->id); > + dev_kfree_skb(skb); > + return 0; > + } > + ret = mtk_fsm_parse_hs2_msg(fsm, hs_info, skb); > + if (!ret) > + ret = mtk_fsm_send_hs3_msg(hs_info, skb); > + dev_kfree_skb(skb); > + if (ret) > + goto hs_err; > + fsm->fsm_flag |= event->fsm_flag; > + } > + > + hs_done_flag = READ_ONCE(fsm->hs_done_flag); > + if (((fsm->fsm_flag | event->fsm_flag) & hs_done_flag) == hs_done_flag) { > + to_state = FSM_STATE_READY; > + mtk_fsm_switch_state(fsm, to_state, NULL); > + } [Severity: Medium] What keeps fsm->boot_seq stable between the boot_seq check and the READY switch below? mtk_fsm_idle_evt_handler() bumps boot_seq from the MHCCIF work and shares no lock with the FSM thread. The new boot's IDLE report can land after the check but before mtk_fsm_switch_state(..., READY). In that case the earlier boot's HS2 is still parsed, HS3 goes to the rebooted device, and READY is reached. The bare STARTUP and new HS1 events queued for the new boot then hit: if (fsm->state != FSM_STATE_ON && fsm->state != FSM_STATE_BOOTUP) { ret = -EPROTO; goto free_skb; } so the modem stays down until the device is rebound. The only exception the commit message lists is an HS2 of the earlier boot "that completes READY before the new boot reports IDLE". Is the window where the report arrives during HS2 handling meant to be covered by that too? [ ... ] > diff --git a/drivers/net/wwan/t9xx/pcie/mtk_cldma.c b/drivers/net/wwan/t9xx/pcie/mtk_cldma.c > index f5ede24fcd14e..0f070072f5d00 100644 > --- a/drivers/net/wwan/t9xx/pcie/mtk_cldma.c > +++ b/drivers/net/wwan/t9xx/pcie/mtk_cldma.c [ ... ] > @@ -461,20 +649,28 @@ static void mtk_cldma_rearm_queues(struct cldma_drv_info *drv_info) > if (txq) { > spin_lock(&txq->ring_lock); > req = txq->req_pool + mtk_cldma_tx_start_idx(txq); > - mtk_cldma_setup_start_addr(drv_info, DIR_TX, i, > - req->gpd_dma_addr); > - if (READ_ONCE(txq->tx_started)) { > - /* An XFER_DONE may have been lost in the reset; > - * without this free_idx never advances. > + if (txq->is_stopping) { > + /* Its stop failed: its requests are kept and > + * the queue stays down until it is freed. > */ [ ... ] > mtk_cldma_unmask_intr(drv_info, DIR_TX, i, QUEUE_ERROR); > mtk_cldma_unmask_intr(drv_info, DIR_TX, i, QUEUE_XFER_DONE); > - if (READ_ONCE(txq->tx_started)) > + if (READ_ONCE(txq->tx_started) && !txq->is_stopping) > mtk_cldma_start_queue(drv_info, DIR_TX, i); > spin_unlock(&txq->ring_lock); [Severity: Low] This isn't a bug, but the comment says the queue stays down until it is freed. A few lines below, QUEUE_ERROR and QUEUE_XFER_DONE are unmasked for this txq as well. After a re-arm, a new QUEUE_ERROR goes mtk_cldma_isr()->mtk_cldma_err_work()->mtk_cldma_err_tx_one(), which stops the queue again. If that stop succeeds, it flushes the kept requests with -EPIPE and runs: txq->is_stopping = false; >>From then on mtk_cldma_submit_tx() and mtk_cldma_start_xfer() accept requests again. Two other comments also describe this state as permanent: the struct txq comment in mtk_cldma.h ("from then on if a stop of this queue failed") and the one in mtk_cldma_tx() ("the stop is not retried"). Should these comments say that a re-arm followed by a new error can bring the queue back? Or is the unmask here not meant for a queue with is_stopping set? [ ... ] > @@ -528,12 +724,32 @@ static void mtk_cldma_txq_free(struct cldma_drv_info *drv_info, u32 txqno) > } > txq->tx_started = false; > > + /* Mask before waiting on anything: a QUEUE_ERROR latched after the > + * flushes below would outlive this queue and be acted on for the > + * next occupant of the same queue number. > + */ > + mtk_cldma_mask_intr(drv_info, DIR_TX, txqno, QUEUE_XFER_DONE); > + mtk_cldma_mask_intr(drv_info, DIR_TX, txqno, QUEUE_ERROR); > irq_id = mtk_pci_get_virq_id(mdev, drv_info->pci_ext_irq_id); > synchronize_irq(irq_id); [ ... ] > + synchronize_irq(irq_id); > + atomic_andnot(BIT(txqno), &drv_info->tx_err_qs); > + flush_work(&drv_info->err_work); [Severity: Medium] Does masking QUEUE_ERROR here keep a late error away from the next occupant, or does it only postpone the error to the next unmask? mtk_cldma_get_intr_status() computes the pending bits as status & ~mask: *tx_sta = (*tx_sta) & (~tx_mask); That suggests the L2 status register keeps latching bits for masked sources. The only code that clears QUEUE_ERROR status is mtk_cldma_isr(), and only for unmasked bits it has just seen. The atomic_andnot() and flush_work() here clear only the software copy. On reopen, mtk_cldma_txq_alloc() unmasks without first clearing the queue's status: mtk_cldma_unmask_intr(drv_info, DIR_TX, txq->txqno, QUEUE_ERROR); mtk_cldma_dev_init() only clears the PCIe L1 bit. mtk_cldma_rxq_free() and mtk_cldma_rxq_alloc() follow the same pattern on RX. Here is one sequence. mtk_cldma_err_tx_one() fails to stop the queue, so QUEUE_ERROR stays masked, and the queue raises the error again. A later close then stops the queue without a reset, which would leave that bit latched. When the channel is reopened, the stale error would fire at unmask. mtk_cldma_err_tx_one() would then stop the new queue and complete its HWO descriptors with -EPIPE. If that happens after the first HS1 kick, which the device does not retry, would the handshake fail? On RX, the stale error would set need_restart and stop/restart the newly armed ring. Should the free or alloc paths clear the queue's QUEUE_ERROR (and XFER_DONE) status before unmasking? [ ... ] > @@ -960,15 +1308,100 @@ static void mtk_cldma_txq_flush(struct cldma_drv_info *drv_info, > trb->status = status; > trb->trb_complete(skb); > > - /* The service may already have been torn down; completing the > - * TRB is still correct, there is just nobody left to wake. > + /* The service may never have been started; completing the TRB > + * is still correct, there is just nobody left to wake. > */ > - srv = trans->trb_srv[0]; > if (was_starved && srv) > wake_up(&srv->trb_waitq); > } > } > > +static void mtk_cldma_err_tx_one(struct cldma_drv_info *drv_info, u32 qno) > +{ > + struct txq *txq; > + int ret; > + > + /* pairs with smp_store_release() in txq_alloc */ > + txq = smp_load_acquire(&drv_info->txq[qno]); > + if (!txq) > + return; > + > + /* is_stopping keeps submit_tx from publishing into the ring between > + * the stop and the flush. rearm_lock: not while start_xfer is > + * between its check and the kick, and held to the end so that two > + * stops of this queue run one after the other and the flag is left > + * as the later one found the queue. > + */ > + mutex_lock(&drv_info->rearm_lock); > + spin_lock(&txq->ring_lock); > + txq->is_stopping = true; > + spin_unlock(&txq->ring_lock); > + > + ret = mtk_cldma_stop_queue(drv_info, DIR_TX, qno); > + /* -ENODEV: the link is dead, nothing is walking the ring */ > + if (ret && ret != -ENODEV) { > + /* the device may still be walking the ring: unmapping its > + * buffers here would leave it reading unmapped memory. > + * is_stopping stays set so nothing submits to it again; > + * QUEUE_ERROR stays masked until an instance re-arm. > + */ > + dev_err(drv_info->mdev->dev, > + "TX queue %u stop failed (%d), keeping its requests\n", > + qno, ret); > + mutex_unlock(&drv_info->rearm_lock); > + return; > + } > + > + spin_lock(&txq->ring_lock); > + WRITE_ONCE(txq->tx_started, false); > + spin_unlock(&txq->ring_lock); > + mtk_cldma_txq_flush(drv_info, txq, -EPIPE); > + > + spin_lock(&txq->ring_lock); > + txq->is_stopping = false; > + spin_unlock(&txq->ring_lock); > + mutex_unlock(&drv_info->rearm_lock); > + /* handled: re-arm what the ISR left masked */ > + mtk_cldma_unmask_intr(drv_info, DIR_TX, qno, QUEUE_ERROR); > +} > + > +/* Handed to the worker because it owns free_idx and is the only context > + * allowed to program an RX queue; a stopped queue raises no further > + * interrupt, so nothing else would re-arm it. > + */ > +static void mtk_cldma_err_rx_one(struct cldma_drv_info *drv_info, u32 qno) > +{ > + struct rxq *rxq; > + > + /* pairs with smp_store_release() in rxq_alloc */ > + rxq = smp_load_acquire(&drv_info->rxq[qno]); > + if (!rxq) > + return; > + > + atomic_set(&rxq->need_restart, 1); > + queue_work(drv_info->wq, &rxq->rx_done_work); > +} > + > +/* The latched bits are consumed up front, so an early exit on one direction > + * must not swallow the other's error. > + */ > +static void mtk_cldma_err_work(struct work_struct *work) > +{ > + struct cldma_drv_info *drv_info = container_of(work, struct cldma_drv_info, err_work); > + u32 tx_err, rx_err; > + int i; > + > + tx_err = atomic_xchg(&drv_info->tx_err_qs, 0); > + rx_err = atomic_xchg(&drv_info->rx_err_qs, 0); > + > + for (i = 0; i < HW_QUE_NUM; i++) { > + if (tx_err & BIT(i)) > + mtk_cldma_err_tx_one(drv_info, i); > + if (rx_err & BIT(i)) > + mtk_cldma_err_rx_one(drv_info, i); > + } > +} > + > static int mtk_cldma_tx(struct cldma_dev *cd, struct sk_buff *skb) > { > struct trb *trb = (struct trb *)skb->cb; [Severity: Medium] If mtk_cldma_stop_queue() fails here while the ring is full, can the TX requests for this queue ever be completed? is_stopping stays set and the flush is skipped. Unless the device still completes descriptors, txq->req_budget stays at 0. The new is_stopping check in mtk_cldma_submit_tx() sits ahead of the req_budget check, so that the trb thread gets -EPIPE rather than -EAGAIN. However, mtk_cldma_get_tx_budget() still returns req_budget without looking at is_stopping. mtk_ctrl_chs_is_busy_or_empty() only dispatches a TRB_CMD_TX at the head of skb_list when mtk_cldma_get_tx_budget() is non-zero. With a zero budget it keeps reporting the queue as busy, so mtk_ctrl_trb_thread() never calls mtk_ctrl_trb_handler() for it. That means mtk_cldma_submit_tx() is never reached. The queued TX skbs and any new ones are never completed with -EPIPE. Nothing on this stop-failure path wakes srv->trb_waitq either. A blocking writer in mtk_port_send_data() would then sleep in wait_event_interruptible() until it is signalled or the device is removed. The commit message instead promises that "a queue whose stop times out keeps its requests and refuses new ones". Should mtk_cldma_get_tx_budget() report a queue with is_stopping set as dispatchable? It already reads under ring_lock, which the locking comment on struct txq allows for this flag. And should the stop-failure path wake the trb thread, so that requests already queued are failed instead of left waiting? -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202-t9xx_driver_v1-v14-0-08ebc870ea94%40compal.com