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 v12 4/6] net: wwan: t9xx: Add control port
Date: Sat, 21 Nov 2026 12:42:29 +0000	[thread overview]
Message-ID: <179526494911.3135.1691599071652469894@kernel.org> (raw)
In-Reply-To: <20261117-t9xx_driver_v1-v12-4-e181b616b820@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] Two comments added in this patch give conflicting meanings for
  -EBUSY, and neither matches mtk_ch_status_check().
- [Low] The struct mtk_port comment (drivers/net/wwan/t9xx/mtk_port.h)
  says tx_seq and rx_seq "are reset while the channel is disabled, so…
- [Low] mtk_port_rx_dispatch() (drivers/net/wwan/t9xx/mtk_port.c) picks
  the target port from the channel field of the received CCCI header,…

--

net: wwan: t9xx: Add control port

This patch adds the port I/O layer and the port manager to the t9xx WWAN
driver. The port table is built from a static config, TRBs are sent to
CLDMA, and received data is dispatched to ports. struct trb gets a kref,
and TX sequence numbers are stamped when a TRB is handed to CLDMA.

> diff --git a/drivers/net/wwan/t9xx/mtk_port.c b/drivers/net/wwan/t9xx/mtk_port.c
> new file mode 100644
> index 0000000000000..eb5ea6741ed7f
> --- /dev/null
> +++ b/drivers/net/wwan/t9xx/mtk_port.c
> @@ -0,0 +1,641 @@

[ ... ]

> +static int mtk_port_rx_dispatch(struct sk_buff *skb, void *priv)
> +{

[ ... ]

> +	channel = FIELD_GET(MTK_HDR_FLD_CHN, le32_to_cpu(ccci_h->status));
> +	/* A CLDMA instance carries the channels of one peer only (sAP or MD),
> +	 * the peer of the port that armed this queue.
> +	 */
> +	if (MTK_PEER_ID(channel) == MTK_PEER_ID(port->info.rx_ch))
> +		port = mtk_port_search_by_id(port_mngr, channel);
> +	else
> +		port = NULL;
> +	if (unlikely(!port)) {
> +		dev_warn_ratelimited(port_mngr->ctrl_blk->mdev->dev,
> +				     "Failed to find port by channel:%d\n", channel);
> +		goto drop_data;
> +	}
> +
> +	mtk_port_check_rx_seq(port, ccci_h);
> +	port->rx_seq = FIELD_GET(MTK_HDR_FLD_SEQ, le32_to_cpu(ccci_h->status));
> +
> +	ret = mtk_port_get_ops(port->info.type)->recv(port, skb);

[Severity: Low]
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?

[ ... ]

> +int mtk_port_ch_enable(struct mtk_port *port)
> +{
> +	struct mtk_port_mngr *port_mngr = port->port_mngr;
> +	struct trb_open_priv *trb_open_priv;
> +	struct sk_buff *skb;
> +	struct trb *trb;
> +	int ret;
> +
> +	/* The modem restarts its sequence numbering with the channel, and
> +	 * the first packet after it is not checked.
> +	 */
> +	port->tx_seq = 0;
> +	port->rx_seq = MTK_INVALID_RX_SEQ;

[Severity: Low]
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.

[ ... ]

> diff --git a/drivers/net/wwan/t9xx/mtk_port_io.c b/drivers/net/wwan/t9xx/mtk_port_io.c
> new file mode 100644
> index 0000000000000..48fdadf96f00f
> --- /dev/null
> +++ b/drivers/net/wwan/t9xx/mtk_port_io.c
> @@ -0,0 +1,236 @@

[ ... ]

> +static void mtk_port_internal_enable(struct mtk_port *port)
> +{
> +	int ret;
> +
> +	if (test_bit(PORT_S_ENABLE, &port->status))
> +		return;
> +
> +	ret = mtk_port_ch_enable(port);
> +	if (ret && ret != -EBUSY) {

[ ... ]

> +	set_bit(PORT_S_WR, &port->status);
> +	set_bit(PORT_S_ENABLE, &port->status);
> +}
> +
> +static void mtk_port_internal_disable(struct mtk_port *port)
> +{

[ ... ]

> +	ret = mtk_port_ch_disable(port);
> +	/* -EBUSY is reported too: every queue has a single port, so a refused
> +	 * DISABLE means its user count was already zero.
> +	 */

[Severity: Low]
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?

> +	if (ret)
> +		dev_warn(port->port_mngr->ctrl_blk->mdev->dev,
> +			 "Failed to disable channel for port(%s): %d\n",
> +			 port->info.name, ret);
> +}

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261117-t9xx_driver_v1-v12-0-e181b616b820%40compal.com

  reply	other threads:[~2026-11-21 12:42 UTC|newest]

Thread overview: 15+ 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-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-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 [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-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=179526494911.3135.1691599071652469894@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®