🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
4 messages
4 total messages Started by "Xin Tian" Thu, 26 Nov 2026 14:57
[PATCH v2 02/11] net/xsc: add doorbell and cmdq MMIO accessors
#23122
Author: "Xin Tian"
Date: Thu, 26 Nov 2026 14:57
202 lines
15659 bytes
Provide doorbell writers and cmdq register accessors operating at
fixed offsets in the compressed-BAR register window.

Signed-off-by: Xin Tian <tianx@yunsilicon.com>
---
 .../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);
+}
+EXPORT_SYMBOL_GPL(xsc_update_tx_db);
+
+void xsc_update_rx_db(struct xsc_core_device *xdev, u32 rqn, u32 next_pid)
+{
+	u32 db = FIELD_PREP(XSC_RX_DB_DATA0_NEXT_PID_MASK, next_pid) |
+		 FIELD_PREP(XSC_RX_DB_DATA0_QP_ID_MASK, rqn);
+
+	/* Make sure that descriptors are written before
+	 * updating doorbell record and ringing the doorbell
+	 */
+	wmb();
+
+	writel(db, xdev->bar + RX_DB_FUNC_MEM_ADDR);
+}
+EXPORT_SYMBOL_GPL(xsc_update_rx_db);
+
+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);
+
+	/* Make sure that the doorbell record in host memory is
+	 * written before ringing the doorbell via PCI MMIO.
+	 */
+	wmb();
+	writel(db, xdev->bar + DB_CQ_FUNC_MEM_ADDR);
+}
+EXPORT_SYMBOL_GPL(xsc_arm_cq);
+
+void xsc_update_cq_ci(struct xsc_core_device *xdev, u32 cqn, u32 next_cid)
+{
+	u32 db = FIELD_PREP(XSC_CQ_DB_DATA0_NEXT_CID_MASK, next_cid) |
+		 FIELD_PREP(XSC_CQ_DB_DATA0_CQ_ID_MASK, cqn);
+
+	/* make sure val write to memory done */
+	wmb();
+	writel(db, xdev->bar + DB_CQ_CID_DIRECT_MEM_ADDR);
+}
+EXPORT_SYMBOL_GPL(xsc_update_cq_ci);
+
+void xsc_update_eq_ci(struct xsc_core_device *xdev, u32 eqn, u32 next_cid,
+		      u8 arm)
+{
+	u32 db = FIELD_PREP(XSC_EQ_DB_DATA0_NEXT_CID_MASK, next_cid) |
+		 FIELD_PREP(XSC_EQ_DB_DATA0_EQ_ID_MASK, eqn) |
+		 FIELD_PREP(XSC_EQ_DB_DATA0_ARM, !!arm);
+
+	/* make sure val write to memory done */
+	wmb();
+	writel(db, xdev->bar + DB_EQ_FUNC_MEM_ADDR);
+}
+
+void xsc_update_cmdq_req_pid(struct xsc_core_device *xdev, u32 req_pid)
+{
+	xsc_write32(xdev->bar, CMDQM_HOST_REQ_PID_MEM_ADDR, req_pid);
+}
+
+void xsc_update_cmdq_rsp_cid(struct xsc_core_device *xdev, u32 rsp_cid)
+{
+	xsc_write32(xdev->bar, CMDQM_HOST_RSP_CID_MEM_ADDR, rsp_cid);
+}
+
+u32 xsc_get_cmdq_req_pid(struct xsc_core_device *xdev)
+{
+	return xsc_read32(xdev->bar, CMDQM_HOST_REQ_PID_MEM_ADDR);
+}
+
+u32 xsc_get_cmdq_rsp_pid(struct xsc_core_device *xdev)
+{
+	return xsc_read32(xdev->bar, CMDQM_HOST_RSP_PID_MEM_ADDR);
+}
+
+u32 xsc_get_cmdq_rsp_cid(struct xsc_core_device *xdev)
+{
+	return xsc_read32(xdev->bar, CMDQM_HOST_RSP_CID_MEM_ADDR);
+}
+
+void xsc_set_cmdq_req_buf_addr(struct xsc_core_device *xdev, u32 haddr,
+			       u32 laddr)
+{
+	xsc_write32(xdev->bar, CMDQM_HOST_REQ_BUF_BASE_H_ADDR_MEM_ADDR, haddr);
+	xsc_write32(xdev->bar, CMDQM_HOST_REQ_BUF_BASE_L_ADDR_MEM_ADDR, laddr);
+}
+
+void xsc_set_cmdq_rsp_buf_addr(struct xsc_core_device *xdev, u32 haddr,
+			       u32 laddr)
+{
+	xsc_write32(xdev->bar, CMDQM_HOST_RSP_BUF_BASE_H_ADDR_MEM_ADDR, haddr);
+	xsc_write32(xdev->bar, CMDQM_HOST_RSP_BUF_BASE_L_ADDR_MEM_ADDR, laddr);
+}
+
+u32 xsc_read_cmdq_err_status(struct xsc_core_device *xdev)
+{
+	return xsc_read32(xdev->bar, CMDQM_HOST_VF_ERR_STS_MEM_ADDR);
+}
+
+void xsc_clear_cmdq_err_status(struct xsc_core_device *xdev, u32 status)
+{
+	if (status)
+		xsc_write32(xdev->bar, CMDQM_HOST_VF_ERR_STS_MEM_ADDR, status);
+}
-- 
2.43.0
Re: [PATCH v2 02/11] net/xsc: add doorbell and cmdq MMIO accessors
#23626
Author: netdev-bot+sashiko
Date: Fri, 27 Nov 2026 15:57
147 lines
13284 bytes
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.

[ ... ]

> +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?

[ ... ]

> +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?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126145711.70868-1-tianx%40yunsilicon.com
Re: [PATCH v2 02/11] net/xsc: add doorbell and cmdq MMIO accessors
#24061
Author: Jason Xing
Date: Sun, 29 Nov 2026 05:47
132 lines
17426 bytes
On Thu, Nov 26, 2026 at 10:57 PM Xin Tian <tianx@yunsilicon.com> wrote:
>
> Provide doorbell writers and cmdq register accessors operating at
> fixed offsets in the compressed-BAR register window.
>
> Signed-off-by: Xin Tian <tianx@yunsilicon.com>
> ---
>  .../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
Re: [PATCH v2 02/11] net/xsc: add doorbell and cmdq MMIO accessors
#25115
Author: "Xin Tian"
Date: Tue, 01 Dec 2026 09:16
141 lines
14407 bytes
On 11/29/2026 1:47 PM, Jason Xing wrote:
> On Thu, Nov 26, 2026 at 10:57 PM Xin Tian <tianx@yunsilicon.com> wrote:
>> Provide doorbell writers and cmdq register accessors operating at
>> fixed offsets in the compressed-BAR register window.
>>
>> Signed-off-by: Xin Tian <tianx@yunsilicon.com>
>> ---
>>   .../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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads