Re: [PATCH v2 02/11] net/xsc: add doorbell and cmdq MMIO accessors

From: Xin Tian

Date: Sat Dec 05 2026 - 22:14:43 EST


On 11/27/2026 11:57 PM, netdev-bot+sashiko@xxxxxxxxxx wrote:
> Thank you for your contribution! Sashiko AI review found 3 potential
> issue(s) to consider.
>
> Critical: 0 · High: 0 · Medium: 1 · 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] xsc_arm_cq(xdev, cqn, next_cid, u8 solicited) in
> drivers/net/ethernet/yunsilicon/xsc/pci/doorbell.c (lines 62-74) puts…
> - [Low] All five doorbell writers in
> drivers/net/ethernet/yunsilicon/xsc/pci/doorbell.c call a full wmb()…
> - [Low] The new file drivers/net/ethernet/yunsilicon/xsc/pci/doorbell.c
> calls EXPORT_SYMBOL_GPL() four times (xsc_update_tx_db,…
>
> --
>
> net/xsc: add doorbell and cmdq MMIO accessors
>
> This commit adds doorbell writers for TX/RX queues, CQs and EQs, along
> with cmdq register accessors. They all operate on fixed offsets in the
> device BAR. The helpers are declared in xsc_core.h, and the TX, RX and
> CQ helpers are exported for use by other modules.
>
>> diff --git a/drivers/net/ethernet/yunsilicon/xsc/pci/doorbell.c b/drivers/net/ethernet/yunsilicon/xsc/pci/doorbell.c
>> new file mode 100644
>> index 0000000000000..5bd64be671646
>> --- /dev/null
>> +++ b/drivers/net/ethernet/yunsilicon/xsc/pci/doorbell.c
>> @@ -0,0 +1,148 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/* Copyright (C) 2024 - 2026, Shanghai Yunsilicon Technology Co., Ltd.
>> + * All rights reserved.
>> + */
>> +
>> +#include <linux/kernel.h>
>> +#include <linux/pci.h>
>> +
>> +#include "common/xsc_core.h"
>> +#include "common/xsc_reg.h"
> [Severity: Low]
> This isn't a bug, but should this file include <linux/export.h> directly?
>
> It uses EXPORT_SYMBOL_GPL() for xsc_update_tx_db(), xsc_update_rx_db(),
> xsc_arm_cq() and xsc_update_cq_ci(). With W=2, the
> check_missing_include_linux_export_h check in scripts/misc-check reports
> this for the file:
>
> EXPORT_SYMBOL() is used, but #include <linux/export.h> is missing
>
> The file builds today only because export.h is pulled in indirectly.
>
> [ ... ]
Added the export.h include here and to the other files in the series that
export symbols.
>> +void xsc_update_tx_db(struct xsc_core_device *xdev, u32 sqn, u32 next_pid)
>> +{
>> + u32 db = FIELD_PREP(XSC_TX_DB_DATA0_NEXT_PID_MASK, next_pid) |
>> + FIELD_PREP(XSC_TX_DB_DATA0_QP_ID_MASK, sqn);
>> +
>> + /* Make sure that descriptors are written before
>> + * updating doorbell record and ringing the doorbell
>> + */
>> + wmb();
>> +
>> + writel(db, xdev->bar + TX_DB_FUNC_MEM_ADDR);
>> +}
> [Severity: Low]
> Is the explicit wmb() needed before writel() here? writel() already
> orders earlier stores to normal and coherent DMA memory before the MMIO
> store:
>
> include/asm-generic/io.h:writel() {
> ...
> __io_bw();
> __raw_writel((u32 __force)__cpu_to_le32(value), addr);
> __io_aw();
> ...
> }
>
> On arm64, __io_bw() is dma_wmb(), so the extra wmb() adds a dsb st to
> every TX doorbell.
>
> xsc_update_rx_db(), xsc_arm_cq(), xsc_update_cq_ci() and
> xsc_update_eq_ci() use the same wmb() plus writel() pattern. Once the
> later "net/xsc: add the transmit path" and "net/xsc: add the receive
> path" patches call these helpers, they are on the hot path.
> xsc_update_cmdq_req_pid() uses a plain writel(), so the barrier usage in
> this file is also inconsistent. The code is unchanged at the end of the
> series.
>
> The comments don't seem to match the code either:
>
> - The TX/RX comments mention "updating doorbell record".
> - xsc_arm_cq() mentions "the doorbell record in host memory".
> - Only a single MMIO word is written, and there is no doorbell record
> in host memory.
> - xsc_update_cq_ci() and xsc_update_eq_ci() say "make sure val write to
> memory done", but there is no val variable.
>
> For the CQ/EQ consumer index updates, the intent may be that the
> CQE/EQE loads finish before the device can reuse the entry. wmb() only
> orders stores, so would a different barrier be needed there?

Dropped all five. writel() already orders prior writes, same as idpf.
The stale doorbell-record / "val" comments go with them, and with no wmb
left in the file.
For the CQ/EQ CI doorbells the wmb() ordered nothing: it can't order the
CQE reads, and there are no stores to order. The read side is handled by
the dma_rmb() after the ownership check in the poll loops.
> [ ... ]
>
>> +void xsc_arm_cq(struct xsc_core_device *xdev, u32 cqn, u32 next_cid,
>> + u8 solicited)
>> +{
>> + u32 db = FIELD_PREP(XSC_CQ_DB_DATA0_NEXT_CID_MASK, next_cid) |
>> + FIELD_PREP(XSC_CQ_DB_DATA0_CQ_ID_MASK, cqn) |
>> + FIELD_PREP(XSC_CQ_DB_DATA0_ARM, !!solicited);
> [Severity: Medium]
> Is the solicited argument meant to set the bit named
> XSC_CQ_DB_DATA0_ARM?
>
> The peer helper xsc_update_eq_ci() sets XSC_EQ_DB_DATA0_ARM from an arm
> argument. Its callers in eq.c pass 1 to arm the EQ at the end of
> xsc_eq_int() and at EQ creation, and 0 for intermediate CI updates.
>
> Later in the series, every caller of xsc_arm_cq() passes 0. The re-arm
> after NAPI completion does this:
>
> xsc_cq_notify_hw_rearm()
> xsc_arm_cq(cq->xdev, cq->xcq.cqn, cq->wq.cc, 0);
>
> So does the initial arm at CQ creation in net/main.c:
>
> xsc_arm_cq(pcq->xdev, pcq->xcq.cqn, pcq->wq.cc, 0);
>
> If BIT(31) is the arm enable bit, as the macro name suggests, do the
> CQs ever get armed? Completion interrupts would then stop after the
> first napi_complete_done(), and the RX/TX datapath would stall.
>
> Another reading is that any write to DB_CQ_FUNC_MEM_ADDR arms the CQ,
> and BIT(31) only selects solicited-only notification. In that case,
> should the macro be renamed so the exported prototype, the
> implementation and the EQ helper agree on what this bit means?
The write always arms the CQ, the bit only picks arm-next vs
arm-solicited, so behavior is fine. Added a comment to make that clear.