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

From
Wu. JackBB (GSM) <hidden>
Date
2026-11-23 03:08:51
Also in
linux-doc, linux-mediatek, lkml, netdev
Reply to
netdev-bot+sashiko@kernel.org, 2026-11-21
Thanks for the review.
This isn't a bug, but the subject covers only part of what this patch
does. Besides the FSM core, it adds:

  - the HS1/HS2/HS3 handshake
  - CLDMA dev_init/dev_exit driven by FSM states, including the IRQ
    registration
  - the new mtk_cldma_isr(), mtk_cldma_err_work(), txq->is_stopping and
    mtk_cldma_drv_quiesce() recovery and teardown design

It also changes code from earlier patches in the series:

  - mtk_cldma_rxq_restart() now stops the queue before every restart
  - mtk_pcie_hif_exit() holds submit_lock across the whole teardown and
    returns early on !available
  - mtk_trans_ctrl_exit() now calls mtk_pcie_hif_exit()
  - mtk_cldma_txq_free() and mtk_cldma_rxq_free() reorder their masks
    and flushes

The commit message does describe most of this. Would splitting it make a
regression in one part easier to bisect or revert on its own?
No change.  The CLDMA interrupt, error recovery and teardown are
reachable only once the FSM listener added here registers the interrupt,
so moving them earlier adds unreachable code and moving them later
leaves this patch bringing CLDMA up without interrupt handling.  The
commit message describes each part, as you note.
Should a host MUST_SUPPORT feature fail the handshake here too?

The host marks QUERY_RTFT_ID_MD_PORT_ENUM and QUERY_RTFT_ID_SAP_PORT_ENUM
as RTFT_TYPE_MUST_SUPPORT, version 0. If the device answers
NOT_EXIST/NOT_SUPPORT, the branch above returns -EPROTO.

If the device instead answers OPTIONAL_SUPPORT with a different
FEATURE_VER, this sets NOT_SUPPORT and returns 0. Then
mtk_fsm_parse_hs2_msg() skips the port enumeration:

        if (cur_ft_spt == RTFT_TYPE_MUST_SUPPORT && query_rtft_action[ft_id]) {

HS3 is sent and HS2_DONE is set. The FSM can then reach READY with no
ports enumerated and no error logged.
Will fix in v13: an OPTIONAL_SUPPORT reply whose version does not match
fails the handshake with -EPROTO when the host marked the feature
MUST_SUPPORT, like a NOT_EXIST or NOT_SUPPORT reply does.
Can mtk_cldma_start_xfer() return -EIO for a queue that err_work is
already stopping? The first is_stopping check here is made under
ring_lock, and ring_lock is then dropped while rearm_lock stays held.
mtk_cldma_err_tx_one() sets is_stopping under ring_lock alone, without
rearm_lock, so the write can land just after this check:

  trb service thread                err_work
  mtk_cldma_start_xfer()
    takes rearm_lock
    reads is_stopping == false
                                    mtk_cldma_err_tx_one()
                                      sets is_stopping
                                      mtk_cldma_stop_queue()
    tx start address reads 0
    mtk_cldma_hw_recovery()
      mtk_cldma_rearm_queues()
        skips the start address
        for this txq, is_stopping
      start address still 0
      returns -EIO
    goto out, before the second
    is_stopping check

mtk_cldma_tx() then gets -EIO rather than -EPIPE, so its early return
for a stopping queue is bypassed. It goes on to call
mtk_cldma_stop_queue() and mtk_cldma_txq_flush() on the same queue
while err_work is stopping and flushing it.

The per-slot ring_lock keeps the two flushes from double-unmapping, but
nothing orders the two stops. Suppose err_work's stop succeeds; it then
flushes and clears is_stopping. If the stop in mtk_cldma_tx() times
out after that, mtk_cldma_tx() sets is_stopping again. The queue then
refuses every new request with -EPIPE until the channel is closed.
Also, requests that the error path meant to complete with -EPIPE can
instead be completed with -EIO by the other flush.

The window needs a zero start address read. That is the lost queue
state case mtk_cldma_hw_recovery() exists to handle.

Should mtk_cldma_err_tx_one() set is_stopping under rearm_lock as well,
so it cannot change while start_xfer holds that lock? Or should
start_xfer re-check is_stopping under ring_lock before it turns a
recovery failure into -EIO?
Will fix in v13, as you suggest: mtk_cldma_err_tx_one() sets is_stopping
under rearm_lock as well, so the flag cannot change between the check in
mtk_cldma_start_xfer() and its kick.  The second check there then cannot
trigger any more and is removed.

The race costs an error code and a stuck queue, not a DMA problem: the
two flushes claim each request once under ring_lock, and each side
unmaps only after its own stop succeeded.
Can the FSM reach READY falsely if the modem reboots partway through the
handshake? Nothing ever clears bits in fsm->fsm_flag.

Suppose MD has finished HS2/HS3 and SAP has not, and then the device
reboots:

  fsm->fsm_flag has MD_HS_START | MD_HS2_DONE, state is BOOTUP
  device reboots and goes back through its boot stages
  mtk_fsm_early_bootup_handler() sees a new IDLE dev_state
    mtk_fsm_idle_evt_handler() re-opens both HS channels:

        for (hs_id = 0; hs_id < HS_ID_MAX; hs_id++)
                mtk_fsm_unmask_ext_evt(fsm, fsm->hs_info[hs_id].mhccif_ch);

  new MD HS1 is accepted in BOOTUP, and the host sends HS1 again
  new MD HS2 matches "fsm->fsm_flag & event->fsm_flag" and is dropped
    as a duplicate, so no HS3 is sent
  SAP completes; the stale MD_HS2_DONE bit satisfies hs_done_flag
    and the FSM switches to READY

With later patches in the series, READY enables the MD ports even though
the rebooted MD side never got HS3. The commit message only covers a
reboot after READY.

Should a new HS1 for a side clear that side's done bits?
Will fix in v13, as you suggest: an HS1 from a side clears that side's
HS2-done bit before the handshake is restarted, so the new HS2 is parsed
and answered with HS3 instead of being dropped as a duplicate, and READY
waits for it.  An HS2 repeated without a new HS1 is still dropped.
What brings this RX queue back after the stop fails? The caller in
mtk_cldma_rx_done_work() has already consumed need_restart:

        if (atomic_xchg(&rxq->need_restart, 0)) {
                if (!mtk_cldma_rxq_restart(drv_info, rxq)) {

Returning true means the restart is never retried. On the error path,
the ISR left QUEUE_ERROR masked, and rx_done_work only unmasks
QUEUE_XFER_DONE on exit. RX also has no equivalent of txq->is_stopping
to record the state.

If the stop completes late, the queue ends up stopped. No XFER_DONE
arrives to run the worker again, so the RX channel stays dead while the
port still looks open.

If the hardware ignores the stop, the queue keeps running with its error
interrupt masked.

The comment points to TRB_CMD_DISABLE, but nothing issues one in this
case. The reset-recovery path in mtk_cldma_rearm_queues() also goes
through this function.
No functional change; v13 rewords the comment and adds a sentence to the
commit message.

When the stop times out the engine may still be walking the ring, so it
is given no new start address and its error interrupt is not re-armed.
Nothing restarts that queue by itself: it is recovered when the channel
is closed, where a stop that still times out resets the instance.  The
TX side behaves the same way after a failed stop.  The comment named
TRB_CMD_DISABLE as if something issued it at that point, which it does
not.
This isn't a bug, but LINK_ERROR_VAL is otherwise used only as the
all-ones read-back value for a dead link. See mtk_cldma_check_intr_status(),
mtk_cldma_stop_queue() and mtk_cldma_tx_done_work().

mtk_cldma_drv_init() writes 0 to the same register to enable it. Would a
dedicated "mask all" constant be clearer here?
Will fix in v13: the write uses a dedicated mask-all constant instead of
LINK_ERROR_VAL.
Is it safe to rely on this? The kernel-doc for dma_pool_destroy() 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.

When ring_leaked is set, descriptors from this pool are still allocated
and may still be a live DMA target. They survive only because of the
current pool->nr_active busy branch. That branch prints "busy", skips
dma_free_coherent(), and frees only the bookkeeping.

Every bind cycle where a stop times out also leaks more coherent pages
that nothing tracks.
No change.  Skipping dma_pool_destroy() would leak the same pages plus
the pool object and its sysfs entry.  The descriptors cannot be returned
while the device may still be using them, so the pages are left to the
pool's busy handling on purpose.  This only happens after a queue failed
to stop, and it is reported.
This isn't a bug, but err_work is not the only writer. mtk_cldma_tx()
sets it from the trb service thread when mtk_cldma_start_xfer() fails and
the follow-up stop also fails:

        spin_lock(&txq->ring_lock);
        txq->is_stopping = true;
        spin_unlock(&txq->ring_lock);

mtk_cldma_err_tx_one() then clears it unconditionally after its own stop
and flush succeed, whoever set it. mtk_cldma_rearm_queues() and
mtk_cldma_start_xfer() also read it.

Could the comment describe both writers?
Will fix in v13: the comment will describe both cases in which the flag
is set, while a queue error is being handled and after any stop of the
queue failed, and say that it is protected by ring_lock.
This isn't a bug, but mtk_cldma_drv_quiesce() sets quiesced before any
retirement step runs. It sets the flag under rearm_lock, and only then:

  - writes int_mask
  - masks the vector
  - calls synchronize_irq()
  - unregisters the handler
  - calls drain_workqueue()

mtk_cldma_rx_done_work() and mtk_cldma_rearm_queues() read the flag while
that is still in progress. So the flag really means retirement has
started and no more work should be queued.

Could the comment say that instead of "already been retired"?
Will fix in v13: the comment will say that the flag marks that the
quiesce has started, so that no more work is queued for the instance and
a repeated quiesce returns early.

Thanks,
Jack

pw-bot: cr
Thread (19 messages) 19 messages, 4 authors, last reply 6d 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