Re: [PATCH 02/15] yunsilicon: add the register HAL
From: Andrew Lunn
Date: Mon Oct 12 2026 - 11:25:42 EST
On Mon, Oct 12, 2026 at 07:43:55PM +0800, Xin Tian wrote:
> Add the register access layer and the per-device register map: doorbell
> and interrupt registers, the command queue pointers and the device
> capability queries that the upper layers call. The register map is
> described by xsc_hal.h and implemented for the Andes device.
>
> Signed-off-by: Xin Tian <tianx@xxxxxxxxxxxxxx>
> ---
> .../net/ethernet/yunsilicon/xsc/pci/Makefile | 2 +-
> .../yunsilicon/xsc/pci/hal/andes_impl.c | 708 ++++++++++++++++++
> .../yunsilicon/xsc/pci/hal/andes_reg.h | 43 ++
> .../ethernet/yunsilicon/xsc/pci/hal/xsc_hal.h | 85 +++
> .../net/ethernet/yunsilicon/xsc/pci/main.c | 3 +
> 5 files changed, 840 insertions(+), 1 deletion(-)
> create mode 100644 drivers/net/ethernet/yunsilicon/xsc/pci/hal/andes_impl.c
> create mode 100644 drivers/net/ethernet/yunsilicon/xsc/pci/hal/andes_reg.h
> create mode 100644 drivers/net/ethernet/yunsilicon/xsc/pci/hal/xsc_hal.h
>
> diff --git a/drivers/net/ethernet/yunsilicon/xsc/pci/Makefile b/drivers/net/ethernet/yunsilicon/xsc/pci/Makefile
> index c163aa950..81b65232e 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 hal/andes_impl.o
> diff --git a/drivers/net/ethernet/yunsilicon/xsc/pci/hal/andes_impl.c b/drivers/net/ethernet/yunsilicon/xsc/pci/hal/andes_impl.c
> new file mode 100644
> index 000000000..46fc045f9
> --- /dev/null
> +++ b/drivers/net/ethernet/yunsilicon/xsc/pci/hal/andes_impl.c
> @@ -0,0 +1,708 @@
> +// 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 "andes_reg.h"
> +#include "common/xsc_core.h"
> +#include "common/xsc_cmd.h"
> +#include "common/xsc_hsi.h"
> +#include "common/xsc_reg.h"
> +#include "xsc_hal.h"
> +
> +/* message opcode */
> +enum {
> + XSC_MSG_OPCODE_SEND = 0,
> + XSC_MSG_OPCODE_RDMA_WRITE = 1,
> + XSC_MSG_OPCODE_RDMA_READ = 2,
> + XSC_MSG_OPCODE_MAD = 3,
> + XSC_MSG_OPCODE_RDMA_ACK = 4,
> + XSC_MSG_OPCODE_RDMA_ACK_READ = 5,
> + XSC_MSG_OPCODE_RDMA_CNP = 6,
> + XSC_MSG_OPCODE_RAW = 7,
> + XSC_MSG_OPCODE_VIRTIO_NET = 8,
> + XSC_MSG_OPCODE_VIRTIO_BLK = 9,
> + XSC_MSG_OPCODE_RAW_TPE = 10,
> + XSC_MSG_OPCODE_INIT_QP_REQ = 11,
> + XSC_MSG_OPCODE_INIT_QP_RSP = 12,
> + XSC_MSG_OPCODE_INIT_PATH_REQ = 13,
> + XSC_MSG_OPCODE_INIT_PATH_RSP = 14,
> +
> + XSC_MSG_OPCODE_UNSUPPORT = -1,
> +};
> +
> +#define REG_ADDR(bp, offset) ((bp) + (offset))
> +
> +static void xsc_read32(void __iomem *bar, u32 off, void *data, int len)
> +{
> + u32 val = readl(REG_ADDR(bar, off));
> +
> + memcpy(data, &val, len);
Why memcpy. Probably because the types are messed up.
> +}
> +
> +static void xsc_write32(void __iomem *bar, u32 off, void *data)
> +{
> + writel(*(u32 *)data, REG_ADDR(bar, off));
> +}
Please sort out your types. You should not be passing a void *. Pass
u32 *. Casts are a red flag, they are generally not needed and
normally indicate bad design.
Andrew