From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D595E606A31A for ; Tue, 1 Dec 2026 04:37:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=QEdPQJkS; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ixtiHcAF DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version: Content-Transfer-Encoding:Content-Type:References:In-Reply-To:Message-ID:Date :Cc:To:From:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=bQ525OLciFFE9LkeJD8/5sSXUNy5sYut8yKVBNK+Pns=; b=QEdPQJkS+uqfHGSOmuJNz6ioAL 2X+dLyhtYHUic1HvA1XpTV0CGOscTEDZu4+CVd6ahodpaE6rGLrXA7IhQZJpT4P9maOAPy5diAP8G fYt/nWDoxE2THSPaMBUKb0FbQxYJJge7Sn5RR5CHGzsNtVvdv8Y+Bz4ur7Xa9YnY8Hbnkg4czXB4R BhO9CCMwyTbjAsFEVvx8d1ojeH+AD2glceQbATjzAy7FI1knOl09ksniFHqIaTFj88S3NXhBD4Ell S0aYcxQ5WJ5i9seLjLOoijWatcvL/f+Zz6qZem2vEdRMRUfd1BeHt1RsldlimWC6Besy4oOrE1rj0 T5Hy3XYQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYFcI-00000006cZx-0nzu; Tue, 01 Dec 2026 04:37:22 +0000 Received: from tor.source.kernel.org ([172.105.4.254]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYFc7-00000006cX0-2IGl; Tue, 01 Dec 2026 04:37:11 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id AB51161EDC; Tue, 1 Dec 2026 04:37:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CE09A1F00893; Tue, 1 Dec 2026 04:37:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796099830; bh=bQ525OLciFFE9LkeJD8/5sSXUNy5sYut8yKVBNK+Pns=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=ixtiHcAFM5Xpd4fon+b9YbGfoYJ25pVIL2U01fuKzsps9lcr90e13dCY8rwBs1xm2 TZyYTPiKj8MZBdSwpcUeGaDfVQ9FBold8SIlla0l5hTin3mJVxA+IbYQ0LrzVg3Ibd sW+bdbwpfffwoqkpRbtw43Qb+DGX3rmkmtT+7r+7Sv9mE9LvHY75HY5lwMwnn0Sudw cJgKgNdhRi/OPYCVk66mIu0nhvNWioT+HWwTSs4tzSyll8c6gO3+N3yx2nW2nnJtZ5 4znApE0XHQ/FZhsvmeY7jRpvIs8XYNHsTD5oJinHhQ43aA9nQJ7ZiNwnvBFMyFNGb5 6H1TjF/6B3FQg== Subject: Re: [PATCH net 2/2] net: airoha: retry WLAN initialization commands 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 Date: Tue, 01 Dec 2026 04:37:09 +0000 Message-ID: <179609982939.3146.14641487017626663057@kernel.org> In-Reply-To: <20261130034106.869059-3-faliang.wang@airoha.com> References: <20261130034106.869059-3-faliang.wang@airoha.com> X-sashiko-severity: Medium Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Archived-By: MIME-Version: 1.0 X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-10.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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