From: Joshua Lant <joshualant@gmail.com>
To: linux-cxl@vger.kernel.org
Cc: qemu-devel@nongnu.org, Jonathan.Cameron@huawei.com,
arpit1.kumar@samsung.com, Joshua Lant <joshualant@gmail.com>
Subject: [RFC QEMU PATCH 10/10] cxl-mailbox-utils: Add support for VCS Get Virtual CXL Switch Info command.
Date: Wed, 29 Apr 2026 14:48:44 +0100 [thread overview]
Message-ID: <20260429135717.3048713-11-joshualant@gmail.com> (raw)
In-Reply-To: <20260429135717.3048713-1-joshualant@gmail.com>
Adds support for FMAPI command 0x5200, for more
information see CXL Specification v3.2 (7.6.7.2.1).
Signed-off-by: Joshua Lant <joshualant@gmail.com>
---
hw/cxl/cxl-mailbox-utils.c | 84 ++++++++++++++++++++++++++++++++++++++
1 file changed, 84 insertions(+)
diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
index cf6cb65eb6..825ef35179 100644
--- a/hw/cxl/cxl-mailbox-utils.c
+++ b/hw/cxl/cxl-mailbox-utils.c
@@ -123,6 +123,7 @@ enum {
#define GET_PHYSICAL_PORT_STATE 0x1
#define PHYSICAL_PORT_CONTROL 0x2
VIRTUAL_SWITCH = 0x52,
+ #define GET_VIRTUAL_SWITCH_INFO 0x0
#define BIND_VPPB 0x1
#define UNBIND_VPPB 0x2
TUNNEL = 0x53,
@@ -825,6 +826,87 @@ static CXLRetCode cmd_physical_port_control(const struct cxl_cmd *cmd,
}
}
+/* CXL r3.2 Section 7.6.7.2.1: Get Virtual CXL Switch Info (Opcode 5200h) */
+static CXLRetCode cmd_get_virtual_switch_info(const struct cxl_cmd *cmd,
+ uint8_t *payload_in,
+ size_t len_in,
+ uint8_t *payload_out,
+ size_t *len_out,
+ CXLCCI *cci)
+{
+ struct cxl_fmapi_get_virtual_switch_info_req_pl {
+ uint8_t start_vppb;
+ uint8_t vppb_list_limit;
+ uint8_t number_of_vcs;
+ uint8_t vcs_id_list[];
+ } QEMU_PACKED *in = (void *)payload_in;
+ struct vppb_info {
+ uint8_t binding_status;
+ uint8_t bound_port_id;
+ uint8_t bound_ld_id;
+ uint8_t rsv1;
+ } QEMU_PACKED;
+ struct vcs_info_block {
+ uint8_t vcs_id;
+ uint8_t vcs_state;
+ uint8_t usp_id;
+ uint8_t num_vppbs;
+ struct vppb_info vppbs[];
+ } QEMU_PACKED;
+ struct cxl_fmapi_get_virtual_switch_info_rsp_pl {
+ uint8_t num_vcs;
+ uint8_t rsv1[3];
+ struct vcs_info_block vcs_info_list[];
+ } QEMU_PACKED *out = (void *)payload_out;
+
+ uint8_t num_vcs_ret = cci->vcs->num_usp_ppbs;
+ uint8_t num_vppbs_ret;
+ ssize_t len_out_tmp = *len_out;
+ len_out_tmp = sizeof(struct cxl_fmapi_get_virtual_switch_info_rsp_pl) +
+ (num_vcs_ret * sizeof(*out->vcs_info_list));
+ for(int i = 0; i < num_vcs_ret; i++) {
+ //num_vppbs_ret = get_num_vppbs_in_vcs(cci->d, i);
+ num_vppbs_ret = cci->vcs->usp_ppbs[i]->info->num_vppbs;
+ //vPPB List Entry Count=min(vPPB List Limit, Number of vPPBs).
+ len_out_tmp = (num_vppbs_ret <= VPPB_LIST_LIMIT) ?
+ len_out_tmp + (num_vppbs_ret * sizeof(struct vppb_info)) :
+ len_out_tmp + (VPPB_LIST_LIMIT * sizeof(struct vppb_info));
+ }
+ *len_out = len_out_tmp;
+
+ out->num_vcs = num_vcs_ret;
+ out->rsv1[0] = 0;
+ out->rsv1[1] = 0;
+ out->rsv1[2] = 0;
+
+ uint8_t *ptr = (uint8_t *)out->vcs_info_list;
+
+ for (int i = 0; i < num_vcs_ret; i++) {
+ CXLVCSInfoBlock *info = cci->vcs->usp_ppbs[i]->info;
+ uint8_t num_vppbs = info->num_vppbs;
+ uint8_t vppb_count = MIN(num_vppbs - in->start_vppb,
+ in->vppb_list_limit);
+
+ /* write fixed vcs_info_block header (4 bytes) */
+ *ptr++ = info->vcs_id;
+ *ptr++ = info->vcs_state;
+ *ptr++ = info->usp_id;
+ *ptr++ = num_vppbs;
+
+ /* write vppb entries for current vcs */
+ for (int j = in->start_vppb; j < in->start_vppb + vppb_count; j++) {
+ struct vppb_info *v = (struct vppb_info *)ptr;
+ v->binding_status = info->vppbs[j]->binding_status;
+ v->bound_port_id = info->vppbs[j]->bound_port_id;
+ v->bound_ld_id = info->vppbs[j]->bound_ld_id;
+ v->rsv1 = 0;
+ ptr += sizeof(struct vppb_info);
+ }
+ }
+
+ return CXL_MBOX_SUCCESS;
+}
+
/* CXL r3.2 Section 7.6.7.2.2: Bind vPPB (Opcode 5201h) */
static CXLRetCode cmd_bind_vppb(const struct cxl_cmd *cmd,
uint8_t *payload_in,
@@ -4974,6 +5056,8 @@ static const struct cxl_cmd cxl_cmd_set_vcs_mctp[256][256] = {
cmd_get_physical_port_state, ~0, 0 },
[PHYSICAL_SWITCH][PHYSICAL_PORT_CONTROL] = { "SWITCH_PHYSICAL_PORT_CONTROL",
cmd_physical_port_control, 2, 0 },
+ [VIRTUAL_SWITCH][GET_VIRTUAL_SWITCH_INFO] = { "GET_VIRTUAL_SWITCH_INFO",
+ cmd_get_virtual_switch_info, ~0, 0 },
[VIRTUAL_SWITCH][BIND_VPPB] = { "BIND_VPPB",
cmd_bind_vppb, ~0, 0 },
[VIRTUAL_SWITCH][UNBIND_VPPB] = { "UNBIND_VPPB",
--
2.47.3
prev parent reply other threads:[~2026-04-29 13:58 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-29 13:48 [RFC QEMU PATCH 00/10] Initial Support for VCS Switching Joshua Lant
2026-04-29 13:48 ` [RFC QEMU PATCH 01/10] docs: Add documentation for cxl-vcs-switch Joshua Lant
2026-04-29 13:48 ` [RFC QEMU PATCH 02/10] qdev/qbus: Allow hidden devices to be busless on QEMU startup Joshua Lant
2026-04-29 13:48 ` [RFC QEMU PATCH 03/10] cxl-type3: Properly unmap the memory-backend on device exit Joshua Lant
2026-04-29 13:48 ` [RFC QEMU PATCH 04/10] cxl_downstream: enable power controller present capability Joshua Lant
2026-04-29 13:48 ` [RFC QEMU PATCH 05/10] cxl-vcs-switch: Initial support for CXL VCS Joshua Lant
2026-04-29 13:48 ` [RFC QEMU PATCH 06/10] cxl-upstream-port: Add support for targeting a VCS switch Joshua Lant
2026-04-29 13:48 ` [RFC QEMU PATCH 07/10] cxl-downstream-port: Add support for VCS switching Joshua Lant
2026-04-29 13:48 ` [RFC QEMU PATCH 08/10] cxl-cci-mailbox: Add support for targeting a VCS switch Joshua Lant
2026-04-29 13:48 ` [RFC QEMU PATCH 09/10] cxl-mailbox-utils: Add support for VCS bind/unbind commands Joshua Lant
2026-04-29 13:48 ` Joshua Lant [this message]
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=20260429135717.3048713-11-joshualant@gmail.com \
--to=joshualant@gmail.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=arpit1.kumar@samsung.com \
--cc=linux-cxl@vger.kernel.org \
--cc=qemu-devel@nongnu.org \
/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