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

From: Xin Tian

Date: Tue Dec 01 2026 - 04:17:16 EST


On 11/29/2026 1:47 PM, Jason Xing wrote:
> On Thu, Nov 26, 2026 at 10:57 PM Xin Tian <tianx@xxxxxxxxxxxxxx> wrote:
>> Provide doorbell writers and cmdq register accessors operating at
>> fixed offsets in the compressed-BAR register window.
>>
>> Signed-off-by: Xin Tian <tianx@xxxxxxxxxxxxxx>
>> ---
>> .../ethernet/yunsilicon/xsc/common/xsc_core.h | 15 ++
>> .../net/ethernet/yunsilicon/xsc/pci/Makefile | 2 +-
>> .../ethernet/yunsilicon/xsc/pci/doorbell.c | 148 ++++++++++++++++++
>> 3 files changed, 164 insertions(+), 1 deletion(-)
>> create mode 100644 drivers/net/ethernet/yunsilicon/xsc/pci/doorbell.c
>>
>> diff --git a/drivers/net/ethernet/yunsilicon/xsc/common/xsc_core.h b/drivers/net/ethernet/yunsilicon/xsc/common/xsc_core.h
>> index 2d0eda8a2..9580d89a1 100644
>> --- a/drivers/net/ethernet/yunsilicon/xsc/common/xsc_core.h
>> +++ b/drivers/net/ethernet/yunsilicon/xsc/common/xsc_core.h
>> @@ -32,4 +32,19 @@ struct xsc_core_device {
>> int bar_num;
>> };
>>
>> +void xsc_update_tx_db(struct xsc_core_device *xdev, u32 sqn, u32 next_pid);
>> +void xsc_update_rx_db(struct xsc_core_device *xdev, u32 rqn, u32 next_pid);
>> +void xsc_arm_cq(struct xsc_core_device *xdev, u32 cqn, u32 next_cid, u8 solicited);
>> +void xsc_update_cq_ci(struct xsc_core_device *xdev, u32 cqn, u32 next_cid);
>> +void xsc_update_eq_ci(struct xsc_core_device *xdev, u32 eqn, u32 next_cid, u8 arm);
>> +void xsc_update_cmdq_req_pid(struct xsc_core_device *xdev, u32 req_pid);
>> +void xsc_update_cmdq_rsp_cid(struct xsc_core_device *xdev, u32 rsp_cid);
>> +u32 xsc_get_cmdq_req_pid(struct xsc_core_device *xdev);
>> +u32 xsc_get_cmdq_rsp_pid(struct xsc_core_device *xdev);
>> +u32 xsc_get_cmdq_rsp_cid(struct xsc_core_device *xdev);
>> +void xsc_set_cmdq_req_buf_addr(struct xsc_core_device *xdev, u32 haddr, u32 laddr);
>> +void xsc_set_cmdq_rsp_buf_addr(struct xsc_core_device *xdev, u32 haddr, u32 laddr);
>> +u32 xsc_read_cmdq_err_status(struct xsc_core_device *xdev);
>> +void xsc_clear_cmdq_err_status(struct xsc_core_device *xdev, u32 status);
>> +
>> #endif
>> diff --git a/drivers/net/ethernet/yunsilicon/xsc/pci/Makefile b/drivers/net/ethernet/yunsilicon/xsc/pci/Makefile
>> index c163aa950..4a08b92cd 100644
>> --- a/drivers/net/ethernet/yunsilicon/xsc/pci/Makefile
>> +++ b/drivers/net/ethernet/yunsilicon/xsc/pci/Makefile
>> @@ -6,4 +6,4 @@ ccflags-y += -I$(srctree)/drivers/net/ethernet/yunsilicon/xsc
>>
>> obj-$(CONFIG_YUNSILICON_XSC_PCI) += xsc_pci.o
>>
>> -xsc_pci-y := main.o
>> +xsc_pci-y := main.o doorbell.o
>> 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 000000000..5bd64be67
>> --- /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"
>> +
>> +/* doorbell words */
>> +#define XSC_TX_DB_DATA0_NEXT_PID_MASK GENMASK(15, 0)
>> +#define XSC_TX_DB_DATA0_QP_ID_MASK GENMASK(30, 16)
>> +#define XSC_RX_DB_DATA0_NEXT_PID_MASK GENMASK(12, 0)
>> +#define XSC_RX_DB_DATA0_QP_ID_MASK GENMASK(27, 13)
>> +#define XSC_CQ_DB_DATA0_NEXT_CID_MASK GENMASK(15, 0)
>> +#define XSC_CQ_DB_DATA0_CQ_ID_MASK GENMASK(30, 16)
>> +#define XSC_CQ_DB_DATA0_ARM BIT(31)
>> +#define XSC_EQ_DB_DATA0_NEXT_CID_MASK GENMASK(10, 0)
>> +#define XSC_EQ_DB_DATA0_EQ_ID_MASK GENMASK(21, 11)
>> +#define XSC_EQ_DB_DATA0_ARM BIT(22)
>> +
>> +static u32 xsc_read32(void __iomem *bar, u32 off)
>> +{
>> + return readl(bar + off);
>> +}
>> +
>> +static void xsc_write32(void __iomem *bar, u32 off, u32 val)
>> +{
>> + writel(val, bar + off);
>> +}
>> +
>> +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);
> writel() already guarantees that prior memory writes are complete
> before the MMIO store. Please see Documentation/memory-barriers.txt,
> "readX(), writeX()" rule 3:
>
> 3. A writeX() by a CPU thread to the peripheral will first wait for the
> completion of all prior writes to memory either issued by, or
> propagated to, the same thread. This ensures that writes by the CPU
> to an outbound DMA buffer allocated by dma_alloc_coherent() will be
> visible to a DMA engine when the CPU writes to its MMIO control
> register to trigger the transfer.
>
> So I don't see the reason for keeping wmb() when using writel()?
> idpf_rx_buf_hw_update() is a good example.
>
> Thanks,
> Jason

Correct. Will drop all five wmb() calls before writel(), not just tx.


Thanks,

Xin