The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Xiong Weimin <15927021679@163.com>
To: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	"David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Jesper Dangaard Brouer <hawk@kernel.org>,
	John Fastabend <john.fastabend@gmail.com>,
	Stanislav Fomichev <sdf@fomichev.me>
Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
	xiongweimin <xiongweimin@kylinos.cn>
Subject: [PATCH 02/14] examples/vhost_user_rdma: implement device and port query commands
Date: Wed, 17 Dec 2025 16:43:28 +0800	[thread overview]
Message-ID: <20251217084422.4875-4-15927021679@163.com> (raw)
In-Reply-To: <20251217084422.4875-1-15927021679@163.com>

From: xiongweimin <xiongweimin@kylinos.cn>

Added RDMA control command handlers for:
- VHOST_RDMA_CTRL_ROCE_QUERY_DEVICE
- VHOST_RDMA_CTRL_ROCE_QUERY_PORT

Key features:
1. Device capability reporting:
   - Maximum MR size and page size capabilities
   - Queue Pair (QP) limits (max WR, SGE, CQE)
   - Resource limits (MR, PD, AH counts)
   - RDMA protocol capabilities

2. Port attribute reporting:
   - GID table length and port state
   - MTU settings (active, physical, maximum)
   - Link speed and width capabilities
   - Error counters and security attributes

3. Response validation:
   - CHK_IOVEC macro ensures response buffer safety
   - Fixed attribute values for standard RDMA v2 compliance
   - Structured response formats matching IB specification

Signed-off-by: Xiong Weimin <xiongweimin@kylinos.cn>
Change-Id: I17ac65a0801ebf5e0b0d83a50877004a54840365
---
 examples/vhost_user_rdma/vhost_rdma_ib.c | 27 ++++++++++++
 examples/vhost_user_rdma/vhost_rdma_ib.h | 56 +++++++++++++++++++++++-
 2 files changed, 82 insertions(+), 1 deletion(-)

diff --git a/examples/vhost_user_rdma/vhost_rdma_ib.c b/examples/vhost_user_rdma/vhost_rdma_ib.c
index 5535a8696b..edb6e3fea3 100644
--- a/examples/vhost_user_rdma/vhost_rdma_ib.c
+++ b/examples/vhost_user_rdma/vhost_rdma_ib.c
@@ -537,12 +537,39 @@ vhost_rdma_query_device(struct vhost_rdma_device *dev, CTRL_NO_CMD,
 	return 0;
 }
 
+static int
+vhost_rdma_query_port(__rte_unused struct vhost_rdma_device *dev,
+					CTRL_NO_CMD,
+					struct iovec *out)
+{
+	struct vhost_rdma_ack_query_port *rsp;
+
+	CHK_IOVEC(rsp, out);
+
+	rsp->gid_tbl_len = VHOST_MAX_GID_TBL_LEN;
+	rsp->max_msg_sz = 0x800000;
+	rsp->active_mtu = VHOST_RDMA_IB_MTU_256;
+	rsp->phys_mtu = VHOST_RDMA_IB_MTU_256;
+	rsp->port_cap_flags = 65536UL;
+	rsp->bad_pkey_cntr = 0UL;
+	rsp->phys_state = VHOST_RDMA_IB_PORT_PHYS_STATE_POLLING;
+	rsp->pkey_tbl_len = 1UL;
+	rsp->qkey_viol_cntr = 0UL;
+	rsp->state = VHOST_RDMA_IB_PORT_DOWN;
+	rsp->active_speed = 1UL;
+	rsp->active_width = VHOST_RDMA_IB_WIDTH_1X;
+	rsp->max_mtu = VHOST_RDMA_IB_MTU_4096;
+
+	return 0;
+}
+
 /* Command handler table declaration */
 struct {
 	int (*handler)(struct vhost_rdma_device *dev, struct iovec *in, struct iovec *out);
 	const char *name;  /* Name of the command (for logging) */
 } cmd_tbl[] = {
 	DEFINE_VIRTIO_RDMA_CMD(VHOST_RDMA_CTRL_ROCE_QUERY_DEVICE, vhost_rdma_query_device),
+	DEFINE_VIRTIO_RDMA_CMD(VHOST_RDMA_CTRL_ROCE_QUERY_PORT, vhost_rdma_query_port),
 };
 
 /**
diff --git a/examples/vhost_user_rdma/vhost_rdma_ib.h b/examples/vhost_user_rdma/vhost_rdma_ib.h
index 4ac896d82e..664067b024 100644
--- a/examples/vhost_user_rdma/vhost_rdma_ib.h
+++ b/examples/vhost_user_rdma/vhost_rdma_ib.h
@@ -204,7 +204,44 @@ enum vhost_user_rdma_request {
 	VHOST_USER_SET_CONFIG = 25,
 	VHOST_USER_MAX
 };
-/** @} */
+
+enum vhost_rdma_ib_port_state {
+	VHOST_RDMA_IB_PORT_NOP		= 0,
+	VHOST_RDMA_IB_PORT_DOWN		= 1,
+	VHOST_RDMA_IB_PORT_INIT		= 2,
+	VHOST_RDMA_IB_PORT_ARMED		= 3,
+	VHOST_RDMA_IB_PORT_ACTIVE		= 4,
+	VHOST_RDMA_IB_PORT_ACTIVE_DEFER	= 5
+};
+
+enum vhost_rdma_ib_port_phys_state {
+	VHOST_RDMA_IB_PORT_PHYS_STATE_SLEEP = 1,
+	VHOST_RDMA_IB_PORT_PHYS_STATE_POLLING = 2,
+	VHOST_RDMA_IB_PORT_PHYS_STATE_DISABLED = 3,
+	VHOST_RDMA_IB_PORT_PHYS_STATE_PORT_CONFIGURATION_TRAINING = 4,
+	VHOST_RDMA_IB_PORT_PHYS_STATE_LINK_UP = 5,
+	VHOST_RDMA_IB_PORT_PHYS_STATE_LINK_ERROR_RECOVERY = 6,
+	VHOST_RDMA_IB_PORT_PHYS_STATE_PHY_TEST = 7,
+};
+
+enum ib_port_width {
+	VHOST_RDMA_IB_WIDTH_1X	= 1,
+	VHOST_RDMA_IB_WIDTH_2X	= 16,
+	VHOST_RDMA_IB_WIDTH_4X	= 2,
+	VHOST_RDMA_IB_WIDTH_8X	= 4,
+	VHOST_RDMA_IB_WIDTH_12X	= 8
+};
+
+enum ib_port_speed {
+	VHOST_RDMA_IB_SPEED_SDR	= 1,
+	VHOST_RDMA_IB_SPEED_DDR	= 2,
+	VHOST_RDMA_IB_SPEED_QDR	= 4,
+	VHOST_RDMA_IB_SPEED_FDR10 = 8,
+	VHOST_RDMA_IB_SPEED_FDR	= 16,
+	VHOST_RDMA_IB_SPEED_EDR	= 32,
+	VHOST_RDMA_IB_SPEED_HDR	= 64,
+	VHOST_RDMA_IB_SPEED_NDR	= 128,
+};
 
 /**
  * @brief QP capabilities structure
@@ -622,6 +659,23 @@ struct vhost_rdma_ctrl_hdr {
 	uint8_t cmd;
 };
 
+struct vhost_rdma_ack_query_port {
+	enum vhost_rdma_ib_port_state	state;
+	enum vhost_rdma_ib_mtu		    max_mtu;
+	enum vhost_rdma_ib_mtu		    active_mtu;
+	uint32_t			phys_mtu;
+	int			        gid_tbl_len;
+	uint32_t			port_cap_flags;
+	uint32_t			max_msg_sz;
+	uint32_t			bad_pkey_cntr;
+	uint32_t			qkey_viol_cntr;
+	uint16_t			pkey_tbl_len;
+	uint16_t			active_speed;
+	uint8_t			    active_width;
+	uint8_t			    phys_state;
+	uint32_t			reserved[32];	/* For future extensions */
+}__rte_packed;
+
 /**
  * @brief Convert IB MTU enum to byte size
  * @param mtu The MTU enum value
-- 
2.43.0


  parent reply	other threads:[~2025-12-17  8:45 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-17  8:43 Implement initial driver for virtio-RDMA devices(kernel), virtio-rdma device model(qemu) and vhost-user-RDMA backend device(dpdk) Xiong Weimin
2025-12-17  8:43 ` [PATCH 01/14] examples/vhost_user_rdma: implement core application initialization for supporting vhost_user_rdma device Xiong Weimin
2025-12-17  8:43 ` [PATCH] hw/rdma: Implement vhost-user RDMA device with PCI support Xiong Weimin
2025-12-17  8:43 ` Xiong Weimin [this message]
2025-12-17  8:43 ` [PATCH 03/14] examples/vhost_user_rdma: implement create and destroy completion queue commands Xiong Weimin
2025-12-17  8:43 ` [PATCH 04/14] examples/vhost_user_rdma: implement protection domain create/destroy commands Xiong Weimin
2025-12-17  8:43 ` [PATCH 05/14] examples/vhost_user_rdma: implement comprehensive memory region management Xiong Weimin
2025-12-17  8:43 ` [PATCH 06/14] examples/vhost_user_rdma: implement comprehensive queue pair lifecycle management Xiong Weimin
2025-12-17  8:43 ` [PATCH 07/14] examples/vhost_user_rdma: Implement high-performance requester engine with advanced flow control Xiong Weimin
2025-12-17  8:43 ` [PATCH 08/14] examples/vhost_user_rdma: implement advanced completer engine with reliability features Xiong Weimin
2025-12-17  8:43 ` [PATCH 09/14] examples/vhost_user_rdma: implement P_Key query operation with default partition key Xiong Weimin
  -- strict thread matches above, loose matches on Subject: below --
2025-12-17  8:49 Implement initial driver for virtio-RDMA devices(kernel), virtio-rdma device model(qemu) and vhost-user-RDMA backend device(dpdk) Xiong Weimin
2025-12-17  8:49 ` [PATCH 02/14] examples/vhost_user_rdma: implement device and port query commands Xiong Weimin
2025-12-17  8:05 Implement initial driver for virtio-RDMA devices(kernel), virtio-rdma device model(qemu) and vhost-user-RDMA backend device(dpdk) 15927021679
2025-12-17  8:05 ` [PATCH 02/14] examples/vhost_user_rdma: implement device and port query commands 15927021679
2025-12-17  8:03 Implement initial driver for virtio-RDMA devices(kernel), virtio-rdma device model(qemu) and vhost-user-RDMA backend device(dpdk) 15927021679
2025-12-17  8:03 ` [PATCH 02/14] examples/vhost_user_rdma: implement device and port query commands 15927021679

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251217084422.4875-4-15927021679@163.com \
    --to=15927021679@163.com \
    --cc=ast@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=hawk@kernel.org \
    --cc=john.fastabend@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=sdf@fomichev.me \
    --cc=xiongweimin@kylinos.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox