Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: faliang.wang@airoha.com
Cc: netdev@vger.kernel.org, lorenzo@kernel.org,
	andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
	kuba@kernel.org, pabeni@redhat.com,
	linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org
Subject: Re: [PATCH net 2/2] net: airoha: retry WLAN initialization commands
Date: Tue, 01 Dec 2026 04:37:09 +0000	[thread overview]
Message-ID: <179609982939.3146.14641487017626663057@kernel.org> (raw)
In-Reply-To: <20261130034106.869059-3-faliang.wang@airoha.com>

Thank you for your contribution! Sashiko AI review found 5 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 3 · Low: 2

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] The commit message is an unfilled template.
- [Medium] airoha_npu_wlan_cmd_with_retry() resends a WLAN mailbox
  command after airoha_npu_send_msg() has failed.
- [Medium] airoha_npu_wlan_cmd_with_retry() retries on any non-zero
  return, including errors that are certain to recur.
- [Low] If NPU mailbox commands really can fail transiently, the patch
  handles it only in airoha_npu_wlan_init_memory().
- [Low] The new helper airoha_npu_wlan_cmd_with_retry() uses a bool flag
  to choose between two unrelated operations.

--

net: airoha: retry WLAN initialization commands

This commit adds airoha_npu_wlan_cmd_with_retry(). The helper wraps the
WLAN initialization mailbox commands sent from
airoha_npu_wlan_init_memory(). It makes up to three attempts and sleeps
10 ms between failed attempts.

> net: airoha: retry WLAN initialization commands
>
> DESCRIBE_THE_CONFIRMED_FAILURE_AND_WHY_RETRYING_IS_SAFE.
>
> Allow up to three total attempts for WLAN initialization commands,Sleep for 10 ms between failed attempts before reporting the final error.
>
> Fixes: REAL_LINUX_SHA ("EXACT_ORIGINAL_COMMIT_SUBJECT")

[Severity: Medium]
The commit message looks like an unfilled template. The body is still
the placeholder text. The Fixes: tag does not point at a real commit, so
stable and backport tooling can't use it.

Could the message say which of the WLAN init commands fail? It would
help to know the error returned (-ETIMEDOUT from the mailbox poll, or
-EINVAL from a firmware status), the platform or firmware version, and
why resending an NPU mailbox command is safe.

The message also says the code sleeps "before reporting the final
error". airoha_npu_wlan_cmd_with_retry() doesn't report anything,
though. It just returns err.

There is also a missing space in "commands,Sleep".

> diff --git a/drivers/net/ethernet/airoha/airoha_npu.c b/drivers/net/ethernet/airoha/airoha_npu.c
> index 7f7cdc2553ad4..6fb4eec20c206 100644
> --- a/drivers/net/ethernet/airoha/airoha_npu.c
> +++ b/drivers/net/ethernet/airoha/airoha_npu.c
> @@ -527,44 +527,65 @@ airoha_npu_wlan_set_reserved_memory(struct airoha_npu *npu,
>  	return airoha_npu_wlan_msg_send(npu, ifindex, func_id, &val,
>  					sizeof(val), GFP_KERNEL);
>  }
> +static int airoha_npu_wlan_cmd_with_retry(struct airoha_npu *npu,
> +					  int ifindex,
> +					  enum airoha_npu_wlan_set_cmd cmd,
> +					  const char *name, bool is_msg_send,
> +					  u32 *val)
> +{
> +	int retry, err;
> +
> +	for (retry = 0; retry < 3; retry++) {
> +		if (is_msg_send)
> +			err = airoha_npu_wlan_msg_send(npu, ifindex, cmd, val,
> +						       sizeof(*val),
> +						       GFP_KERNEL);
> +		else
> +			err = airoha_npu_wlan_set_reserved_memory(npu, ifindex,
> +								  name, cmd);
> +		if (!err)
> +			return 0;
> +
> +		if (retry < 2)
> +			msleep(10);
> +	}

[Severity: Medium]
Is it safe to resend the mailbox command without first resetting or
quiescing the NPU MBQ0 mailbox?

When airoha_npu_send_msg() times out, nothing aborts the pending
request. The CTRL(2) doorbell counter has already been advanced, the
buffer is unmapped, and airoha_npu_wlan_msg_send() then frees it:

airoha_npu_send_msg() {
    ...
	regmap_write(npu->regmap, REG_CR_MBQ0_CTRL(3) + offset, val);
	regmap_read(npu->regmap, REG_CR_MBQ0_CTRL(2) + offset, &val);
	regmap_write(npu->regmap, REG_CR_MBQ0_CTRL(2) + offset, val + 1);

	ret = regmap_read_poll_timeout_atomic(npu->regmap,
					      REG_CR_MBQ0_CTRL(3) + offset,
					      val, (val & MBOX_MSG_DONE),
					      100, 100 * MSEC_PER_SEC);
    ...
	dma_unmap_single(npu->dev, dma_addr, size, DMA_BIDIRECTIONAL);
    ...
}

airoha_npu_wlan_msg_send() {
    ...
	err = airoha_npu_send_msg(npu, NPU_FUNC_WIFI, wlan_data, len);
	kfree(wlan_data);
    ...
}

The unmap and free after a single timeout predates this patch. Before
it, though, a timeout ended mt76_npu_init(). Now the retry posts a new
buffer, rewrites CTRL(0/1/3) and advances CTRL(2) again, while the first
request may still be pending in the firmware.

Suppose the NPU was slow rather than dead and completes the stale
request late. Could the retry's poll then treat that DONE/STATUS as the
completion of the new command?

If so, the new buffer would be unmapped and freed while the firmware
still has one more doorbell to process. Because the buffer is mapped
DMA_BIDIRECTIONAL, could the device then touch freed memory, or run the
command twice?

The loop also retries -EINVAL. That error means the firmware already
processed and rejected the command:

	if (!ret && FIELD_GET(MBOX_MSG_STATUS, val) != NPU_MBOX_SUCCESS)
		ret = -EINVAL;

Are the WLAN_FUNC_SET_WAIT_* commands known to be idempotent, so that
resending the same payload is harmless? If they are not, a safe retry
would seem to need a mailbox reset or abort, or a confirmation from the
firmware.

>  
> +	return err;
> +}

[Severity: Low]
If NPU mailbox commands can fail transiently, why is the retry only
applied in airoha_npu_wlan_init_memory()?

Every other user of airoha_npu_send_msg() still fails on the first
error. That includes airoha_npu_wlan_msg_send() and
airoha_npu_wlan_msg_get() when mt76 reaches them through
ops.wlan_send_msg and ops.wlan_get_msg. It also includes the PPE init,
stats and flush commands. For example, mt76_npu_send_txrx_addr() in
drivers/net/wireless/mediatek/mt76/npu.c does:

	err = airoha_npu_wlan_send_msg(npu, ifindex,
				WLAN_FUNC_SET_WAIT_INODE_TXRX_REG_ADDR,
				&info, sizeof(info), GFP_ATOMIC);

A firmware not-ready condition right after boot would explain limiting
the retry to init. The commit message doesn't say whether that is the
cause, though.

That caller runs under rcu_read_lock() with GFP_ATOMIC, and
airoha_npu_send_msg() runs under spin_lock_bh(). An msleep() based retry
couldn't simply be moved into the shared path either.

>  static int airoha_npu_wlan_init_memory(struct airoha_npu *npu)
>  {
>  	enum airoha_npu_wlan_set_cmd cmd = WLAN_FUNC_SET_WAIT_NPU_BAND0_ONCPU;
>  	u32 val = 0;
> -	int err;
> -
> -	err = airoha_npu_wlan_msg_send(npu, 1, cmd, &val, sizeof(val),
> -				       GFP_KERNEL);
> +	int err = 0;
> +	err = airoha_npu_wlan_cmd_with_retry(npu, 1, cmd, "band0_oncpu",1, &val);
>  	if (err)
>  		return err;
>  
>  	cmd = WLAN_FUNC_SET_WAIT_TX_BUF_CHECK_ADDR;
> -	err = airoha_npu_wlan_set_reserved_memory(npu, 0, "tx-bufid", cmd);
> +	err = airoha_npu_wlan_cmd_with_retry(npu, 0, cmd, "tx-bufid", 0, NULL);

[Severity: Medium]
The loop retries any non-zero return. Should it be retrying errors that
are certain to happen again?

When is_msg_send is false, each attempt repeats the DT lookup in
airoha_npu_wlan_set_reserved_memory():

	err = of_reserved_mem_region_to_resource_byname(dev->of_node, name,
							&res);
	if (err)
		return err;

The result of that lookup depends only on static DT content. When
reserved-mem support isn't built, it is -ENOSYS from the stub.

The binding in
Documentation/devicetree/bindings/net/airoha,en7581-npu.yaml sets
minItems: 1 for memory-region-names. That makes "pkt", "tx-pkt" and
"tx-bufid" optional. Only "ba" is checked with of_property_match_string()
before the call; the other three go straight into the retry loop.
Requiring those regions predates this patch, but retrying the lookup is
new.

The loop also retries -ENOMEM, dma_mapping_error() failures and firmware
rejections (-EINVAL), each time with the same payload.

Each of these failures now costs three attempts and two msleep(10)
calls, and the result is the same. Each mailbox attempt can also
busy-wait for up to 100 ms with BH disabled under cores[0].lock.
mt76_npu_init() holds dev->mutex for all of it.

>  	if (err)
>  		return err;
>  
>  	cmd = WLAN_FUNC_SET_WAIT_PKT_BUF_ADDR;
> -	err = airoha_npu_wlan_set_reserved_memory(npu, 0, "pkt", cmd);
> +	err = airoha_npu_wlan_cmd_with_retry(npu, 0, cmd, "pkt", 0, NULL);
>  	if (err)
>  		return err;
>  
>  	cmd = WLAN_FUNC_SET_WAIT_TX_PKT_BUF_ADDR;
> -	err = airoha_npu_wlan_set_reserved_memory(npu, 0, "tx-pkt", cmd);
> +	err = airoha_npu_wlan_cmd_with_retry(npu, 0, cmd, "tx-pkt", 0, NULL);
>  	if (err)
>  		return err;
>  
>  	if (of_property_match_string(npu->dev->of_node, "memory-region-names",
>  				     "ba") >= 0) {
>  		cmd = WLAN_FUNC_SET_WAIT_DRAM_BA_NODE_ADDR;
> -		err = airoha_npu_wlan_set_reserved_memory(npu, 0, "ba", cmd);
> +		err = airoha_npu_wlan_cmd_with_retry(npu, 0, cmd, "ba",false, NULL);
>  		if (err)
>  			return err;
>  	}
>  
>  	cmd = WLAN_FUNC_SET_WAIT_IS_FORCE_TO_CPU;
> -	return airoha_npu_wlan_msg_send(npu, 0, cmd, &val, sizeof(val),
> -					GFP_KERNEL);
> +	return airoha_npu_wlan_cmd_with_retry(npu, 0, cmd, "force_to_cpu", 1,&val);
>  }

[Severity: Low]
This isn't a bug, but there are a few style issues in the new code.

The is_msg_send flag selects between two unrelated operations. name is
ignored when is_msg_send is true, yet the callers pass "band0_oncpu" and
"force_to_cpu", which are not DT region names. val is NULL on the other
branch. The same bool is passed as 1, 0 and false at different call
sites.

The value in "int err = 0;" is overwritten right away, and there is no
blank line after the declarations.

The 3, 2 and 10 in the retry loop are magic numbers.

Two blank lines between functions are missing: one after
airoha_npu_wlan_set_reserved_memory() and one after the new helper,
before airoha_npu_wlan_init_memory().

Spaces are missing after the commas in "band0_oncpu",1 and "ba",false
and 1,&val.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130034106.869059-1-faliang.wang%40airoha.com


  parent reply	other threads:[~2026-12-01  4:37 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30  3:41 [PATCH net 0/2] net: airoha: fix NPU mailbox and WLAN initialization Faliang Wang
2026-11-30  3:41 ` [PATCH net 1/2] net: airoha: fix NPU mailbox notification ordering Faliang Wang
2026-11-30  8:27   ` Lorenzo Bianconi
2026-11-30  8:31     ` Faliang Wang (王法亮)
2026-12-01  4:37   ` netdev-bot+sashiko
2026-11-30  3:41 ` [PATCH net 2/2] net: airoha: retry WLAN initialization commands Faliang Wang
2026-11-30  8:31   ` Lorenzo Bianconi
2026-12-01  4:37   ` netdev-bot+sashiko [this message]
2026-11-30  3:45 ` [PATCH net 0/2] net: airoha: fix NPU mailbox and WLAN initialization netdev-bot+sinfo

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=179609982939.3146.14641487017626663057@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=faliang.wang@airoha.com \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=lorenzo@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.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