From: "Wu. JackBB (GSM)" <JackBB_Wu@compal.com>
To: "netdev-bot+sashiko@kernel.org" <netdev-bot+sashiko@kernel.org>
Cc: "loic.poulain@oss.qualcomm.com" <loic.poulain@oss.qualcomm.com>,
"ryazanov.s.a@gmail.com" <ryazanov.s.a@gmail.com>,
"johannes@sipsolutions.net" <johannes@sipsolutions.net>,
"andrew+netdev@lunn.ch" <andrew+netdev@lunn.ch>,
"davem@davemloft.net" <davem@davemloft.net>,
"kuba@kernel.org" <kuba@kernel.org>,
"pabeni@redhat.com" <pabeni@redhat.com>,
"wen-zhi.huang@mediatek.com" <wen-zhi.huang@mediatek.com>,
"shi-wei.yeh@mediatek.com" <shi-wei.yeh@mediatek.com>,
"Minano.tseng@mediatek.com" <Minano.tseng@mediatek.com>,
"matthias.bgg@gmail.com" <matthias.bgg@gmail.com>,
"angelogioacchino.delregno@collabora.com"
<angelogioacchino.delregno@collabora.com>,
"horms@kernel.org" <horms@kernel.org>,
"corbet@lwn.net" <corbet@lwn.net>,
"skhan@linuxfoundation.org" <skhan@linuxfoundation.org>,
"Yu. Robert (GSM)" <robert_yu@compal.com>,
"Chang. Jeff (GSM)" <Jeff_Chang@compal.com>,
"edumazet@kernel.org" <edumazet@kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>,
"linux-mediatek@lists.infradead.org"
<linux-mediatek@lists.infradead.org>,
"linux-doc@vger.kernel.org" <linux-doc@vger.kernel.org>
Subject: Re: [PATCH net-next v12 4/6] net: wwan: t9xx: Add control port
Date: Mon, 23 Nov 2026 03:07:11 +0000 [thread overview]
Message-ID: <5ad4346ac47844bca9de6c6344394175@compal.com> (raw)
In-Reply-To: <179526494911.3135.1691599071652469894@kernel.org>
Thanks for the review.
> Can two RX workers update the same port->rx_seq at the same time here?
>
> The target port comes from the channel in the CCCI header. The only
> filter is the peer ID. The queue that delivered the packet (the port
> passed in as priv, i.e. rxq->arg) is not used for the lookup.
>
> Each RX queue has its own rx_done_work. mtk_cldma_dev_init() creates
> drv_info->wq like this:
>
> flag = WQ_UNBOUND | WQ_MEM_RECLAIM | WQ_HIGHPRI;
> drv_info->wq = alloc_workqueue("cldma%d_workq_%s", flag, 0, hw_id,
> mdev->dev_str);
>
> So work items for different RX queues of the same CLDMA are not ordered.
> Later in the series CLDMA1 serves RXQ(0) for MDCTRL, RXQ(2) for MBIM and
> RXQ(5) for AT.
>
> Suppose the device puts a packet whose header names channel B on queue A's
> ring. Queue A's worker then runs mtk_port_check_rx_seq(), does the plain
> store to port B's rx_seq, and calls port B's ->recv(). Queue B's worker
> may be doing the same thing at that moment.
>
> That seems to conflict with the comment in struct mtk_port:
>
> rx_seq only from the rx_done
> callback of the one queue serving this channel.
>
> Should dispatch reject packets whose channel does not belong to the
> delivering queue? Or should rx_seq be protected some other way?
No code change: t7xx matches path and channel in the same way, both
->recv() paths tolerate concurrent calls, and rx_seq only feeds a
rate-limited warning. A check against the delivering queue would drop
frames on queues that several channels share. The struct mtk_port
comment you quote will be reworded so that it no longer reads as a rule
about which queue may write rx_seq.
> Is the struct mtk_port comment right about when these counters are reset?
>
> Both are reset
> while the channel is disabled, so neither needs a lock.
>
> The reset happens at the start of mtk_port_ch_enable(), before the ENABLE
> trb is submitted. The channel is not always disabled at that point.
>
> The ENABLE can complete with -EBUSY in two places:
>
> - mtk_ch_status_check(), when usr_cnt is already >= 1
> - mtk_cldma_open(), when the queues already exist
>
> In either case the RX queue is already armed with rxq->arg == port.
> mtk_port_rx_dispatch() may be running this store at the same time:
>
> port->rx_seq = FIELD_GET(MTK_HDR_FLD_SEQ, le32_to_cpu(ccci_h->status));
>
> There is also a second case. An earlier ENABLE that timed out may still be
> queued, along with its compensating DISABLE. That pair can arm the queue
> for a short time while a new ->enable() resets the counters.
>
> These are plain unsigned short accesses with no READ_ONCE() or
> WRITE_ONCE(). A late store from RX dispatch could undo the reset. The
> first packet of the new session would then be checked against a stale
> rx_seq and log a spurious "seq num out-of-order" warning.
>
> Likewise, a TX left in flight from an earlier session could be stamped
> with a tx_seq while the reset is happening.
Will fix the comment in v13: it will say who writes each counter and
that rx_seq only feeds the out-of-order warning, and will no longer
state when they are reset. The code stays as it is: the reset only runs
with PORT_S_ENABLE clear, which is either after every queue was closed
or after an enable that never got as far as opening the port.
> Does this comment match what mtk_ch_status_check() does? The DISABLE path
> there is:
>
> case TRB_CMD_DISABLE:
> if (trans->usr_cnt[que->hif_id][que->txqno] > 0) {
> trans->usr_cnt[que->hif_id][que->txqno]--;
> if (!trans->usr_cnt[que->hif_id][que->txqno])
> break;
> }
> trb->status = -EBUSY;
>
> So -EBUSY comes back in two cases: when the count was zero, and when the
> count was decremented but is still above zero.
>
> mtk_port_ch_enable() has its own comment about -EBUSY:
>
> /* -EBUSY means another user already owns the queue, and the
> * geometry it reports is that queue's - also valid here.
> */
>
> This assumes a queue can have more than one owner, which conflicts with
> the "single port" claim above. Following that comment,
> mtk_port_internal_enable() treats an ENABLE that returns -EBUSY (usr_cnt
> 1->2) as success and sets PORT_S_WR and PORT_S_ENABLE.
>
> The later DISABLE then takes usr_cnt from 2 to 1 and gets -EBUSY.
> mtk_cldma_close() never runs, and the RX queue stays armed with rxq->arg
> pointing at the port.
>
> Even with one port per queue, a leftover count can come from either of
> two failures:
>
> - An ENABLE times out and the compensating mtk_port_ch_disable() fails in
> __dev_alloc_skb(). The ENABLE is still queued and later raises usr_cnt
> to 1.
> - mtk_port_internal_disable() clears PORT_S_ENABLE, but the DISABLE skb
> cannot be allocated, so usr_cnt stays at 1.
>
> If one owner per queue is meant to be an invariant, should an ENABLE that
> returns -EBUSY be treated as success? If not, should this comment and the
> one in mtk_port_ch_enable() be reconciled?
Will fix in v13: you are right that the comment in
mtk_port_internal_disable() claims more than the code guarantees. It
will only say that a DISABLE refused with -EBUSY did not close the
queue, which holds for both cases in mtk_ch_status_check(). The one in
mtk_port_ch_enable() will say that -EBUSY means the queue is already
open, without naming another user.
-EBUSY stays a successful ENABLE. With one port per queue the open queue
can only have been armed by this port's own earlier ENABLE, with the
same rx callback and argument.
No change for the two leftover-count cases. A count left by a failed
DISABLE does not outlive the HIF: ->disable() runs only on the way to
OFF or at unbind, and mtk_pcie_hif_exit() there frees every queue while
the ports are still alive; the next HIF init starts the counts at zero.
Thanks,
Jack
pw-bot: cr
next prev parent reply other threads:[~2026-11-23 3:07 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 10:50 [PATCH net-next v12 0/6] net: wwan: t9xx: Add MediaTek T9XX WWAN driver Jack Wu via B4 Relay
2026-11-17 10:50 ` [PATCH net-next v12 1/6] net: wwan: t9xx: Add PCIe core Jack Wu via B4 Relay
2026-11-17 15:28 ` Loic Poulain
2026-11-18 2:41 ` [External Mail] " Wu. JackBB (GSM)
2026-11-21 12:42 ` netdev-bot+sashiko
2026-11-23 3:05 ` Wu. JackBB (GSM)
2026-11-17 10:50 ` [PATCH net-next v12 2/6] net: wwan: t9xx: Add control plane transaction layer framework Jack Wu via B4 Relay
2026-11-17 15:31 ` Loic Poulain
2026-11-18 2:44 ` Wu. JackBB (GSM)
2026-11-17 10:50 ` [PATCH net-next v12 3/6] net: wwan: t9xx: Add control DMA interface Jack Wu via B4 Relay
2026-11-21 12:42 ` netdev-bot+sashiko
2026-11-23 3:06 ` Wu. JackBB (GSM)
2026-11-17 10:50 ` [PATCH net-next v12 4/6] net: wwan: t9xx: Add control port Jack Wu via B4 Relay
2026-11-21 12:42 ` netdev-bot+sashiko
2026-11-23 3:07 ` Wu. JackBB (GSM) [this message]
2026-11-17 10:50 ` [PATCH net-next v12 5/6] net: wwan: t9xx: Add FSM thread Jack Wu via B4 Relay
2026-11-21 12:42 ` netdev-bot+sashiko
2026-11-23 3:08 ` Wu. JackBB (GSM)
2026-11-17 10:50 ` [PATCH net-next v12 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=5ad4346ac47844bca9de6c6344394175@compal.com \
--to=jackbb_wu@compal.com \
--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=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-bot+sashiko@kernel.org \
--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;
as well as URLs for NNTP newsgroup(s).