Linux CXL
 help / color / mirror / Atom feed
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 08/10] cxl-cci-mailbox: Add support for targeting a VCS switch
Date: Wed, 29 Apr 2026 14:48:42 +0100	[thread overview]
Message-ID: <20260429135717.3048713-9-joshualant@gmail.com> (raw)
In-Reply-To: <20260429135717.3048713-1-joshualant@gmail.com>

Allows a cci mailbox and mctp device to target a cxl-vcs-switch. The
target needs to be changed from a PCIDevice to a more generic Object,
since the target can now also be a cxl-vcs-switch, as well as USP or
type3 device. The VCS is an object which is composed of many
PCI devices, but cannot be classed as one itself (since it is busless).

Signed-off-by: Joshua Lant <joshualant@gmail.com>
---
 hw/cxl/cxl-mailbox-utils.c  | 44 +++++++++++++++++++++++--------------
 hw/cxl/switch-mailbox-cci.c | 33 ++++++++++++++++++++++------
 hw/usb/dev-mctp.c           | 23 ++++++++++++++++---
 include/hw/cxl/cxl_device.h | 10 ++++++++-
 4 files changed, 83 insertions(+), 27 deletions(-)

diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
index f12e42a648..779138cdc8 100644
--- a/hw/cxl/cxl-mailbox-utils.c
+++ b/hw/cxl/cxl-mailbox-utils.c
@@ -4600,22 +4600,24 @@ int cxl_process_cci_message(CXLCCI *cci, uint8_t set, uint8_t cmd,
     }
 
     /* forbid any selected commands while the media is disabled */
-    if (object_dynamic_cast(OBJECT(cci->d), TYPE_CXL_TYPE3)) {
-        cxl_dstate = &CXL_TYPE3(cci->d)->cxl_dstate;
-
-        if (cxl_dev_media_disabled(cxl_dstate)) {
-            if (h == cmd_events_get_records ||
-                h == cmd_ccls_get_partition_info ||
-                h == cmd_ccls_set_lsa ||
-                h == cmd_ccls_get_lsa ||
-                h == cmd_logs_get_log ||
-                h == cmd_media_get_poison_list ||
-                h == cmd_media_inject_poison ||
-                h == cmd_media_clear_poison ||
-                h == cmd_sanitize_overwrite ||
-                h == cmd_firmware_update_transfer ||
-                h == cmd_firmware_update_activate) {
-                return CXL_MBOX_MEDIA_DISABLED;
+    if(cci->d) {
+        if (object_dynamic_cast(OBJECT(cci->d), TYPE_CXL_TYPE3)) {
+            cxl_dstate = &CXL_TYPE3(cci->d)->cxl_dstate;
+
+            if (cxl_dev_media_disabled(cxl_dstate)) {
+                if (h == cmd_events_get_records ||
+                    h == cmd_ccls_get_partition_info ||
+                    h == cmd_ccls_set_lsa ||
+                    h == cmd_ccls_get_lsa ||
+                    h == cmd_logs_get_log ||
+                    h == cmd_media_get_poison_list ||
+                    h == cmd_media_inject_poison ||
+                    h == cmd_media_clear_poison ||
+                    h == cmd_sanitize_overwrite ||
+                    h == cmd_firmware_update_transfer ||
+                    h == cmd_firmware_update_activate) {
+                    return CXL_MBOX_MEDIA_DISABLED;
+                }
             }
         }
     }
@@ -4909,3 +4911,13 @@ void cxl_initialize_usp_mctpcci(CXLCCI *cci, DeviceState *d, DeviceState *intf,
     cci->intf = intf;
     cxl_init_cci(cci, payload_max);
 }
+
+void cxl_initialize_vcs_mctpcci(CXLCCI *cci, CXLVCSSwitch *vcs, DeviceState *d,
+        DeviceState *intf, size_t payload_max)
+{
+    cxl_copy_cci_commands(cci, cxl_cmd_set_usp_mctp);
+    cci->vcs = vcs;
+    cci->d = d;
+    cci->intf = intf;
+    cxl_init_cci(cci, payload_max);
+}
diff --git a/hw/cxl/switch-mailbox-cci.c b/hw/cxl/switch-mailbox-cci.c
index 223f220433..73f76484cc 100644
--- a/hw/cxl/switch-mailbox-cci.c
+++ b/hw/cxl/switch-mailbox-cci.c
@@ -16,6 +16,7 @@
 #include "qemu/module.h"
 #include "hw/qdev-properties.h"
 #include "hw/cxl/cxl.h"
+#include "include/hw/cxl/cxl_vcs_switch.h"
 
 #define CXL_SWCCI_MSIX_MBOX 3
 
@@ -32,17 +33,26 @@ static void cswbcci_realize(PCIDevice *pci_dev, Error **errp)
     CXLDeviceState *cxl_dstate = &cswmb->cxl_dstate;
     CXLDVSECRegisterLocator *regloc_dvsec;
     CXLUpstreamPort *usp;
+    CXLVCSSwitch *vcs = 0;
 
     if (!cswmb->target) {
-        error_setg(errp, "Target not set");
+        error_setg(errp, "No target or vcs has been set...");
         return;
     }
-    usp = CXL_USP(cswmb->target);
 
     pcie_endpoint_cap_init(pci_dev, 0x80);
     cxl_cstate->dvsec_offset = 0x100;
     cxl_cstate->pdev = pci_dev;
-    cswmb->cci = &usp->swcci;
+    if (object_dynamic_cast(cswmb->target, TYPE_CXL_VCS_SWITCH)) {
+	vcs = CXL_VCS_SWITCH(cswmb->target);
+	cswmb->cci = &vcs->swcci;
+    } else if (object_dynamic_cast(cswmb->target, TYPE_CXL_USP)) {
+	usp = CXL_USP(cswmb->target);
+	cswmb->cci = &usp->swcci;
+    } else {
+	error_setg(errp, "Target must be a VCS switch or USP");
+	return;
+    }
     cxl_device_register_block_init(OBJECT(pci_dev), cxl_dstate, cswmb->cci);
     pci_register_bar(pci_dev, 0,
                      PCI_BASE_ADDRESS_SPACE_MEMORY |
@@ -57,9 +67,18 @@ static void cswbcci_realize(PCIDevice *pci_dev, Error **errp)
                                REG_LOC_DVSEC_LENGTH, REG_LOC_DVSEC,
                                REG_LOC_DVSEC_REVID, (uint8_t *)regloc_dvsec);
 
-    cxl_initialize_mailbox_swcci(cswmb->cci, DEVICE(pci_dev),
-                                 DEVICE(cswmb->target),
-                                 CXL_MAILBOX_MAX_PAYLOAD_SIZE);
+    if(vcs) {
+	if(vcs->usp_ppbs[0]) {
+	    cxl_initialize_vcs_mctpcci(cswmb->cci,
+		vcs, DEVICE(vcs->usp_ppbs[0]->usp), DEVICE(pci_dev), CXL_MAILBOX_MAX_PAYLOAD_SIZE);
+	} else {
+	    error_setg(errp, "The VCS requires a master USP...");
+	}
+    } else {
+	cxl_initialize_mailbox_swcci(cswmb->cci, DEVICE(pci_dev),
+				     DEVICE(CXL_USP(cswmb->target)),
+				     CXL_MAILBOX_MAX_PAYLOAD_SIZE);
+    }
 }
 
 static void cswmbcci_exit(PCIDevice *pci_dev)
@@ -69,7 +88,7 @@ static void cswmbcci_exit(PCIDevice *pci_dev)
 
 static const Property cxl_switch_cci_props[] = {
     DEFINE_PROP_LINK("target", CSWMBCCIDev,
-                     target, TYPE_CXL_USP, PCIDevice *),
+                     target, TYPE_OBJECT, Object *),
 };
 
 static void cswmbcci_class_init(ObjectClass *oc, const void *data)
diff --git a/hw/usb/dev-mctp.c b/hw/usb/dev-mctp.c
index aafb9e7e96..792a375245 100644
--- a/hw/usb/dev-mctp.c
+++ b/hw/usb/dev-mctp.c
@@ -25,6 +25,7 @@
 #include "hw/usb.h"
 #include "hw/usb/desc.h"
 #include "net/mctp.h"
+#include "include/hw/cxl/cxl_vcs_switch.h"
 
 /* TODO: Move to header */
 
@@ -77,7 +78,7 @@ enum cxl_dev_type {
 
 typedef struct USBCXLMCTPState {
     USBDevice dev;
-    PCIDevice *target;
+    Object *target;
     CXLCCI *cci;
     enum cxl_dev_type type;
     USBPacket *cached_tohost;
@@ -600,12 +601,28 @@ static void usb_cxl_mctp_realize(USBDevice *dev, Error **errp)
         return;
     }
 
+    if (object_dynamic_cast(OBJECT(s->target), TYPE_CXL_VCS_SWITCH)) {
+        CXLVCSSwitch *sw = CXL_VCS_SWITCH(s->target);
+
+        s->type = cxl_switch;
+        s->cci = &sw->mctpcci;
+	s->cci->vcs = sw;
+
+	if(sw->usp_ppbs[0]) {
+	    cxl_initialize_vcs_mctpcci(s->cci, CXL_VCS_SWITCH(s->target),
+		DEVICE(sw->usp_ppbs[0]->usp), DEVICE(dev), MCTP_CXL_MAILBOX_BYTES);
+	} else {
+	    error_setg(errp, "No master USP associated with the VCS");
+	}
+        return;
+    }
+
     error_setg(errp, "Unhandled target type for CXL MCTP EP");
 }
 
 static const Property usb_cxl_mctp_properties[] = {
-    DEFINE_PROP_LINK("target", USBCXLMCTPState, target, TYPE_PCI_DEVICE,
-                     PCIDevice *),
+    DEFINE_PROP_LINK("target", USBCXLMCTPState, target, TYPE_OBJECT,
+                     Object *),
 };
 
 static void usb_cxl_mctp_class_initfn(ObjectClass *klass, const void *data)
diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h
index 6158560e6c..5d9f537a03 100644
--- a/include/hw/cxl/cxl_device.h
+++ b/include/hw/cxl/cxl_device.h
@@ -143,6 +143,7 @@ typedef enum {
 } CXLDSMASFlags;
 
 typedef struct CXLCCI CXLCCI;
+typedef struct CXLVCSSwitch CXLVCSSwitch;
 typedef struct cxl_device_state CXLDeviceState;
 struct cxl_cmd;
 typedef CXLRetCode (*opcode_handler)(const struct cxl_cmd *cmd,
@@ -212,6 +213,8 @@ typedef struct CXLCCI {
     DeviceState *d;
     /* Pointer to the device hosting the protocol conversion */
     DeviceState *intf;
+    /* Pointer to the vcs hosting the CCI (if used) */
+    CXLVCSSwitch *vcs;
     bool initialized;
 } CXLCCI;
 
@@ -349,6 +352,10 @@ void cxl_initialize_t3_ld_cci(CXLCCI *cci, DeviceState *d,
 void cxl_initialize_usp_mctpcci(CXLCCI *cci, DeviceState *d, DeviceState *intf,
                                 size_t payload_max);
 
+void cxl_initialize_vcs_mctpcci(CXLCCI *cci, CXLVCSSwitch *vcs,
+	DeviceState *d, DeviceState *intf, size_t payload_max);
+
+
 #define cxl_device_cap_init(dstate, reg, cap_id, ver)                      \
     do {                                                                   \
         uint32_t *cap_hdrs = dstate->caps_reg_state32;                     \
@@ -820,9 +827,10 @@ struct CXLType3Class {
                           uint8_t *data);
 };
 
+
 struct CSWMBCCIDev {
     PCIDevice parent_obj;
-    PCIDevice *target;
+    Object *target;
     CXLComponentState cxl_cstate;
     CXLDeviceState cxl_dstate;
     CXLCCI *cci;
-- 
2.47.3


  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 ` Joshua Lant [this message]
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 ` [RFC QEMU PATCH 10/10] cxl-mailbox-utils: Add support for VCS Get Virtual CXL Switch Info command Joshua Lant

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-9-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