QEMU: CXL mailbox rework and features
cover QEMU: CXL mailbox rework and features
Based on: [PATCH] hw/cxl: Fix local variable shadowing of cap_hdrs
Based on: [PATCH v2 0/3] hw/cxl: Add dummy ACPI QTG DSM
Based on: [PATCH V2] hw/pci-bridge/cxl-upstream: Add serial number extended capability support Based on: [PATCH v3 0/4] hw/cxl: Line length reduction and related
Based on: [PATCH v6 0/3] hw/{i2c,nvme}: mctp endpoint, nvme management interface model
I'm assuming this last dependency will go via a different tree though there is an outstanding request for tests. That equally applies to the CXL setup, but there are lot of moving parts. I'll experiment with basic testing of the MCTP I2C device whilst this is being reviewed.
Based on: Message ID: [email protected] Based on: Message ID: [email protected] Based on: Message ID: [email protected] Based on: Message ID: [email protected] Based on: Message ID: [email protected]
I've been carrying most of this series on our CXL staging tree
https://gitlab.com/jic23/qemu for some time and a lot of more recent work around Multi Head Devices and Dynamic Capacity that we need for Linux kernel enabling are backed up behind it. Hence I reorganized my queue to try and land this before other less 'central' features such as CXL PMUs and arm/virt support.
This series is focused on enabling the Fabric Management (FM) aspects of CXL to enable orchestration and tooling development and also to enable testing of related kernel features. That requires some substantial reworking of existing mailbox handling (improving a few things along the way).
Features:
1. Rework the Component Command Interface (CCI) implementation to extract generic parts from the existing CXL Primary Mailbox (in PCI BAR space).
2. Add CXL Switch Mailbox CCI function support. This CXL r3.0 feature enables an in band PCI path to control switch configuration. It is basically a CXL primary mailbox in a separate PCI function. On many systems this would be wired to a BMC, but as it is a normal PCI function we can make it an option for an emulated host providing us with a useful interface for testing some Fabric Mnagement features of CXL. In particular this will be useful for tunneling Fabric Management commands to Type 3 memory devices (via MCTP over PCI VDM)
3. Via MCTP over I2C and the two CXL MCTP bindings (FM-API and Memory Device) provide an alternative control interface. For now this can only be used with an aspeed-i2c controller. (There are hacks to enable this controller on CXL host systems but they are not suitable for upstreaming - so in upstream it's either MCTP access, or inband access depending on machine used). This is primarily implemented to enable work on the very different Linux kernel interface for MCTP (network socket based) to the IOCTL interface for the Switch Mailbox CCI.
4. A set of example commands to explore how to get access to various information. Additional commands will be added in future series. This one is big enough already! One or two bits are made up for now. Fidelity may therefore improve in future patch sets.
5. Davidlohr's work on background operations (only for the CXL type 3 primary mailbox for now. This wasn't directly related to the above series but was based on the early rework and is a simple feature. Background support for MCTP interfaces and the Switch Mailbox CCI is left for future series.
Note that we are currently only implement a simple fixed configuration single VH switch. If anyone is interested in working on expanding that to deal with the high degree of configurability of topology that vPPBs bring then let me know.
A few areas that might be of interest to reviewers:
1) The target=XXX approach to linking the 'interfaces' up with the underlying CXL devices.
2) The walking of various PCIe structures and similar to fill in the data needed for some commands. I'm still using some fake data for now, but ultimately all this stuff is probably discoverable.
3) Tunneling fun in the final patch. That gives an idea of one of the more complex corners of the Fabric Management part of the CXL spec and perhaps best illustrates the reason we have so many CCI instances inside one device a they all require separate state and can present different available commands.
A typical QEMU command line snippet for testing the Switch Mailbox CCI.
-object memory-backend-file,id=cxl-mem1,share=on,mem-path=/tmp/t3_cxl1.raw,size=256M,align=256M \
-object memory-backend-file,id=cxl-lsa1,share=on,mem-path=/tmp/t3_lsa1.raw,size=1M \
-object memory-backend-file,id=cxl-mem2,share=on,mem-path=/tmp/t3_cxl2.raw,size=256M,align=256M \
-object memory-backend-file,id=cxl-lsa2,share=on,mem-path=/tmp/t3_lsa2.raw,size=1M \
-device pxb-cxl,bus_nr=12,bus=pcie.0,id=cxl.1,hdm_for_passthrough=true \
-device cxl-rp,port=0,bus=cxl.1,id=cxl_rp_port0,chassis=0,slot=2 \
-device cxl-upstream,port=2,sn=1234,bus=cxl_rp_port0,id=us0,addr=0.0,multifunction=on, \
-device cxl-switch-mailbox-cci,bus=cxl_rp_port0,addr=0.1,target=us0 \
-device cxl-downstream,port=0,bus=us0,id=swport0,chassis=0,slot=4 \
-device cxl-downstream,port=1,bus=us0,id=swport1,chassis=0,slot=5 \
-device cxl-type3,bus=swport0,memdev=cxl-mem1,id=cxl-pmem1,lsa=cxl-lsa1,sn=3 \
-device cxl-type3,bus=swport1,memdev=cxl-mem2,id=cxl-pmem2,lsa=cxl-lsa2,sn=4 \
-machine cxl-fmw.0.targets.0=cxl.1,cxl-fmw.0.size=4G,cxl-fmw.0.interleave-granularity=1k \
-device i2c_mctp_cxl,bus=aspeed.i2c.bus.0,address=4,target=us0 \
-device i2c_mctp_cxl,bus=aspeed.i2c.bus.0,address=5,target=cxl-pmem1 \
-device i2c_mctp_cxl,bus=aspeed.i2c.bus.0,address=6,target=cxl-pmem2
A snippet for testing the i2c_mctp_cxl (on a suitable aspeed machine, or with the hacks on gitlab.com/jic23/qemu to add an aspeed controller to i386/pc).
-object memory-backend-file,id=cxl-mem1,share=on,mem-path=/tmp/t3_cxl1.raw,size=256M,align=256M \
-object memory-backend-file,id=cxl-lsa1,share=on,mem-path=/tmp/t3_lsa1.raw,size=1M \
-object memory-backend-file,id=cxl-mem2,share=on,mem-path=/tmp/t3_cxl2.raw,size=256M,align=256M \
-object memory-backend-file,id=cxl-lsa2,share=on,mem-path=/tmp/t3_lsa2.raw,size=1M \
-device pxb-cxl,bus_nr=12,bus=pcie.0,id=cxl.1,hdm_for_passthrough=true \
-device cxl-rp,port=0,bus=cxl.1,id=cxl_rp_port0,chassis=0,slot=2 \
-device cxl-upstream,port=2,sn=1234,bus=cxl_rp_port0,id=us0,addr=0.0,multifunction=on, \
-device cxl-downstream,port=0,bus=us0,id=swport0,chassis=0,slot=4 \
-device cxl-downstream,port=1,bus=us0,id=swport1,chassis=0,slot=5 \
-device cxl-type3,bus=swport0,memdev=cxl-mem1,id=cxl-pmem1,lsa=cxl-lsa1,sn=3 \
-device cxl-type3,bus=swport1,memdev=cxl-mem2,id=cxl-pmem2,lsa=cxl-lsa2,sn=4 \
-device i2c_mctp_cxl,bus=aspeed.i2c.bus.0,address=4,target=us0 \
-device i2c_mctp_cxl,bus=aspeed.i2c.bus.0,address=5,target=cxl-pmem1 \
-device i2c_mctp_cxl,bus=aspeed.i2c.bus.0,address=6,target=cxl-pmem2
Rather than ending up with a very long cover letter, I'll post where to find test userspace code to talk to the switch-cci and the i2c_mctp_cxl device + tunnel to the devices below them separately along with pointers to the kernel series needed (for the switch mailbox CCI).
I'll shortly push out a fresh tree including dependencies for this set and everything we currently have on top of it at
gitlab.com/jic23/qemu cxl-2023-09-26
Davidlohr Bueso (3):
hw/cxl/mbox: Add support for background operations hw/cxl/mbox: Wire up interrupts for background completion hw/cxl: Add support for device sanitation
Gregory Price (1):
hw/cxl/type3: Cleanup multiple CXL_TYPE3() calls in read/write
functions
Jonathan Cameron (15):
hw/cxl/mbox: Pull the payload out of struct cxl_cmd and make instances
constant
hw/cxl/mbox: Split mailbox command payload into separate input and
output
hw/cxl/mbox: Pull the CCI definition out of the CXLDeviceState hw/cxl/mbox: Generalize the CCI command processing hw/pci-bridge/cxl_upstream: Move defintion of device to header. hw/cxl/i2c_mctp_cxl: Initial device emulation
hw/cxl/mbox: Add Information and Status / Identify command
docs: cxl: Add example commandline for MCTP CXL CCIs hw/cxl/mbox: Add Physical Switch Identify command.
hw/cxl: Add a switch mailbox CCI function hw/pci-bridge/cxl_downstream: Set default link width and link speed hw/cxl: Implement Physical Ports status retrieval hw/cxl/mbox: Add Get Background Operation Status Command hw/cxl: Add dummy security state get
hw/cxl: Add tunneled command support to mailbox for switch cci/mctp.
docs/system/devices/cxl.rst | 27 + include/hw/cxl/cxl.h | 6 + include/hw/cxl/cxl_component.h | 3 +- include/hw/cxl/cxl_device.h | 110 ++- include/hw/pci-bridge/cxl_upstream_port.h | 20 + hw/cxl/cxl-device-utils.c | 120 ++- hw/cxl/cxl-events.c | 2 +- hw/cxl/cxl-mailbox-utils.c | 1038 ++++++++++++++++++--- hw/cxl/i2c_mctp_cxl.c | 290 ++++++ hw/cxl/switch-mailbox-cci.c | 111 +++ hw/mem/cxl_type3.c | 32 +- hw/pci-bridge/cxl_downstream.c | 18 +- hw/pci-bridge/cxl_upstream.c | 11 +- hw/cxl/Kconfig | 4 + hw/cxl/meson.build | 2 + 15 files changed, 1609 insertions(+), 185 deletions(-) create mode 100644 include/hw/pci-bridge/cxl_upstream_port.h create mode 100644 hw/cxl/i2c_mctp_cxl.c create mode 100644 hw/cxl/switch-mailbox-cci.c
Signature · 1 line
2.39.2
PATCH 1/19 hw/cxl/mbox: Pull the payload out of struct cxl_cmd and make instances constant
Putting the pointer in the structure for command handling puts a single variable element inside an otherwise constant structure. Move it out as a directly passed variable and take the cxl_cmd structures constant.
--- include/hw/cxl/cxl_device.h | 13 ++++ hw/cxl/cxl-mailbox-utils.c | 121 +++++++++++++++++++----------------- 2 files changed, 78 insertions(+), 56 deletions(-)
include/hw/cxl/cxl_device.h +13 -0
@@ -111,6 +111,18 @@ typedef enum { CXL_MBOX_MAX = 0x17 } CXLRetCode; +typedef struct cxl_device_state CXLDeviceState ; +struct cxl_cmd ; +typedef CXLRetCode (*opcode_handler )(const struct cxl_cmd *cmd, +uint8_t *payload, +CXLDeviceState *cxl_dstate,uint16_t *len); +struct cxl_cmd { +const char *name; +opcode_handler handler; +ssize_t in; +uint16_t effect;/* Reported in CEL */ +}; + typedef struct CXLEvent { CXLEventRecordRaw data; QSIMPLEQ_ENTRY(CXLEvent) node;
@@ -178,6 +190,7 @@ typedef struct cxl_device_state {uint64_t pmem_size;uint64_t vmem_size; +const struct cxl_cmd (*cxl_cmd_set)[256 ];CXLEventLog event_logs[CXL_EVENT_TYPE_MAX ]; } CXLDeviceState;
hw/cxl/cxl-mailbox-utils.c +65 -56
344 lines not on this page · raw message
Signature · 1 line
2.39.2
Re: [PATCH 01/19] hw/cxl/mbox: Pull the payload out of struct cxl_cmd and make instances constant
Quoted 6 lines · Jonathan Cameron
Putting the pointer in the structure for command handling puts a single variable element inside an otherwise constant structure. Move it out as a directly passed variable and take the
cxl_cmdstructures constant.Signed-off-by Jonathan Cameron <[email protected]>---
Quoted 415 lines
include/hw/cxl/cxl_device.h | 13 ++++ hw/cxl/cxl-mailbox-utils.c | 121 +++++++++++++++++++----------------- 2 files changed, 78 insertions(+), 56 deletions(-)include/hw/cxl/cxl_device.h +13
-0@@ -111,6 +111,18 @@ typedef enum { CXL_MBOX_MAX = 0x17 } CXLRetCode; +typedef struct cxl_device_state CXLDeviceState ; +struct cxl_cmd ; +typedef CXLRetCode (*opcode_handler )(const struct cxl_cmd *cmd, +uint8_t *payload, +CXLDeviceState *cxl_dstate,uint16_t *len); +struct cxl_cmd { +const char *name; +opcode_handler handler; +ssize_t in; +uint16_t effect;/* Reported in CEL */ +}; + typedef struct CXLEvent { CXLEventRecordRaw data; QSIMPLEQ_ENTRY(CXLEvent) node;@@ -178,6 +190,7 @@ typedef struct cxl_device_state {uint64_t pmem_size;uint64_t vmem_size; +const struct cxl_cmd (*cxl_cmd_set)[256 ];CXLEventLog event_logs[CXL_EVENT_TYPE_MAX ]; } CXLDeviceState;hw/cxl/cxl-mailbox-utils.c +65
-56@@ -69,18 +69,9 @@ enum {#define CLEAR_POISON 0x2 }; -struct cxl_cmd ; -typedef CXLRetCode (*opcode_handler )(struct cxl_cmd *cmd, -CXLDeviceState *cxl_dstate,uint16_t *len); -struct cxl_cmd { -const char *name; -opcode_handler handler; -ssize_t in; -uint16_t effect;/* Reported in CEL */ -uint8_t *payload; -}; -static CXLRetCode cmd_events_get_records (struct cxl_cmd *cmd, +static CXLRetCode cmd_events_get_records (const struct cxl_cmd *cmd, +uint8_t *payload,CXLDeviceState *cxlds,uint16_t *len) {@@ -92,9 +83,9 @@ static CXLRetCode cmd_events_get_records(struct cxl_cmd *cmd,return CXL_MBOX_INVALID_INPUT ; } - log_type = *((uint8_t *)cmd->payload); + log_type = payload[0 ]; - pl = (CXLGetEventPayload *)cmd->payload; + pl = (CXLGetEventPayload *)payload;memset (pl,0 ,sizeof (*pl)); max_recs = (cxlds->payload_size - CXL_EVENT_PAYLOAD_HDR_SIZE) /@@ -106,25 +97,27 @@ static CXLRetCode cmd_events_get_records(struct cxl_cmd *cmd,return cxl_event_get_records (cxlds, pl, log_type, max_recs, len); } -static CXLRetCode cmd_events_clear_records (struct cxl_cmd *cmd, +static CXLRetCode cmd_events_clear_records (const struct cxl_cmd *cmd, +uint8_t *payload,CXLDeviceState *cxlds,uint16_t *len) {CXLClearEventPayload *pl; - pl = (CXLClearEventPayload *)cmd->payload; + pl = (CXLClearEventPayload *)payload; *len =0 ;return cxl_event_clear_records (cxlds, pl); } -static CXLRetCode cmd_events_get_interrupt_policy (struct cxl_cmd *cmd, +static CXLRetCode cmd_events_get_interrupt_policy (const struct cxl_cmd *cmd, +uint8_t *payload,CXLDeviceState *cxlds,uint16_t *len) {CXLEventInterruptPolicy *policy;CXLEventLog *log; - policy = (CXLEventInterruptPolicy *)cmd->payload; + policy = (CXLEventInterruptPolicy *)payload;memset (policy,0 ,sizeof (*policy)); log = &cxlds->event_logs[CXL_EVENT_TYPE_INFO ];@@ -157,7 +150,8 @@ static CXLRetCode cmd_events_get_interrupt_policy(struct cxl_cmd *cmd,return CXL_MBOX_SUCCESS ; } -static CXLRetCode cmd_events_set_interrupt_policy (struct cxl_cmd *cmd, +static CXLRetCode cmd_events_set_interrupt_policy (const struct cxl_cmd *cmd, +uint8_t *payload,CXLDeviceState *cxlds,uint16_t *len) {@@ -168,7 +162,7 @@ static CXLRetCode cmd_events_set_interrupt_policy(struct cxl_cmd *cmd,return CXL_MBOX_INVALID_PAYLOAD_LENGTH ; } - policy = (CXLEventInterruptPolicy *)cmd->payload; + policy = (CXLEventInterruptPolicy *)payload; log = &cxlds->event_logs[CXL_EVENT_TYPE_INFO ]; log->irq_enabled = (policy->info_settings & CXL_EVENT_INT_MODE_MASK) ==@@ -200,7 +194,8 @@ static CXLRetCode cmd_events_set_interrupt_policy(struct cxl_cmd *cmd, }/* 8.2.9.2.1 */ -static CXLRetCode cmd_firmware_update_get_info (struct cxl_cmd *cmd, +static CXLRetCode cmd_firmware_update_get_info (const struct cxl_cmd *cmd, +uint8_t *payload,CXLDeviceState *cxl_dstate,uint16_t *len) {@@ -221,7 +216,7 @@ static CXLRetCode cmd_firmware_update_get_info(struct cxl_cmd *cmd,return CXL_MBOX_INTERNAL_ERROR ; } - fw_info = (void *)cmd->payload; + fw_info = (void *)payload;memset (fw_info,0 ,sizeof (*fw_info)); fw_info->slots_supported =2 ;@@ -234,27 +229,29 @@ static CXLRetCode cmd_firmware_update_get_info(struct cxl_cmd *cmd, }/* 8.2.9.3.1 */ -static CXLRetCode cmd_timestamp_get (struct cxl_cmd *cmd, +static CXLRetCode cmd_timestamp_get (const struct cxl_cmd *cmd, +uint8_t *payload,CXLDeviceState *cxl_dstate,uint16_t *len) {uint64_t final_time =cxl_device_get_timestamp (cxl_dstate); -stq_le_p (cmd->payload, final_time); +stq_le_p (payload, final_time); *len =8 ;return CXL_MBOX_SUCCESS ; }/* 8.2.9.3.2 */ -static CXLRetCode cmd_timestamp_set (struct cxl_cmd *cmd, -CXLDeviceState *cxl_dstate, -uint16_t *len) +static CXLRetCode cmd_timestamp_set (const struct cxl_cmd *cmd, +uint8_t *payload, +CXLDeviceState *cxl_dstate, +uint16_t *len) { cxl_dstate->timestamp.set = true; cxl_dstate->timestamp.last_set =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); - cxl_dstate->timestamp.host_set =le64_to_cpu (*(uint64_t *)cmd->payload); + cxl_dstate->timestamp.host_set =le64_to_cpu (*(uint64_t *)payload); *len =0 ;return CXL_MBOX_SUCCESS ;@@ -267,7 +264,8 @@ static const QemuUUID cel_uuid = { };/* 8.2.9.4.1 */ -static CXLRetCode cmd_logs_get_supported (struct cxl_cmd *cmd, +static CXLRetCode cmd_logs_get_supported (const struct cxl_cmd *cmd, +uint8_t *payload,CXLDeviceState *cxl_dstate,uint16_t *len) {@@ -278,7 +276,7 @@ static CXLRetCode cmd_logs_get_supported(struct cxl_cmd *cmd,QemuUUID uuid;uint32_t size; } log_entries[1 ]; - }QEMU_PACKED *supported_logs = (void *)cmd->payload; + }QEMU_PACKED *supported_logs = (void *)payload;QEMU_BUILD_BUG_ON (sizeof (*supported_logs) !=0x1c ); supported_logs->entries =1 ;@@ -290,7 +288,8 @@ static CXLRetCode cmd_logs_get_supported(struct cxl_cmd *cmd, }/* 8.2.9.4.2 */ -static CXLRetCode cmd_logs_get_log (struct cxl_cmd *cmd, +static CXLRetCode cmd_logs_get_log (const struct cxl_cmd *cmd, +uint8_t *payload,CXLDeviceState *cxl_dstate,uint16_t *len) {@@ -298,7 +297,9 @@ static CXLRetCode cmd_logs_get_log(struct cxl_cmd *cmd,QemuUUID uuid;uint32_t offset;uint32_t length; - } QEMU_PACKED QEMU_ALIGNED(16) *get_log = (void *)cmd->payload; + } QEMU_PACKED QEMU_ALIGNED(16) *get_log; + + get_log = (void *)payload;/* * 8.2.9.4.2 @@ -324,14 +325,15 @@ static CXLRetCode cmd_logs_get_log(struct cxl_cmd *cmd,/* Store off everything to local variables so we can wipe out the payload */ *len = get_log->length; -memmove (cmd->payload, cxl_dstate->cel_log + get_log->offset, +memmove (payload, cxl_dstate->cel_log + get_log->offset, get_log->length);return CXL_MBOX_SUCCESS ; }/* 8.2.9.5.1.1 */ -static CXLRetCode cmd_identify_memory_device (struct cxl_cmd *cmd, +static CXLRetCode cmd_identify_memory_device (const struct cxl_cmd *cmd, +uint8_t *payload,CXLDeviceState *cxl_dstate,uint16_t *len) {@@ -361,7 +363,7 @@ static CXLRetCode cmd_identify_memory_device(struct cxl_cmd *cmd,return CXL_MBOX_INTERNAL_ERROR ; } - id = (void *)cmd->payload; + id = (void *)payload;memset (id,0 ,sizeof (*id));snprintf (id->fw_revision,0x10 ,"BWFW VERSION %02d" ,0 );@@ -382,7 +384,8 @@ static CXLRetCode cmd_identify_memory_device(struct cxl_cmd *cmd,return CXL_MBOX_SUCCESS ; } -static CXLRetCode cmd_ccls_get_partition_info (struct cxl_cmd *cmd, +static CXLRetCode cmd_ccls_get_partition_info (const struct cxl_cmd *cmd, +uint8_t *payload,CXLDeviceState *cxl_dstate,uint16_t *len) {@@ -391,7 +394,7 @@ static CXLRetCode cmd_ccls_get_partition_info(struct cxl_cmd *cmd,uint64_t active_pmem;uint64_t next_vmem;uint64_t next_pmem; - }QEMU_PACKED *part_info = (void *)cmd->payload; + }QEMU_PACKED *part_info = (void *)payload;QEMU_BUILD_BUG_ON (sizeof (*part_info) !=0x20 ); if ((!QEMU_IS_ALIGNED(cxl_dstate->vmem_size, CXL_CAPACITY_MULTIPLIER)) ||@@ -414,7 +417,8 @@ static CXLRetCode cmd_ccls_get_partition_info(struct cxl_cmd *cmd,return CXL_MBOX_SUCCESS ; } -static CXLRetCode cmd_ccls_get_lsa (struct cxl_cmd *cmd, +static CXLRetCode cmd_ccls_get_lsa (const struct cxl_cmd *cmd, +uint8_t *payload,CXLDeviceState *cxl_dstate,uint16_t *len) {@@ -426,7 +430,7 @@ static CXLRetCode cmd_ccls_get_lsa(struct cxl_cmd *cmd,CXLType3Class *cvc =CXL_TYPE3_GET_CLASS (ct3d);uint32_t offset, length; - get_lsa = (void *)cmd->payload; + get_lsa = (void *)payload; offset = get_lsa->offset; length = get_lsa->length;@@ -439,7 +443,8 @@ static CXLRetCode cmd_ccls_get_lsa(struct cxl_cmd *cmd,return CXL_MBOX_SUCCESS ; } -static CXLRetCode cmd_ccls_set_lsa (struct cxl_cmd *cmd, +static CXLRetCode cmd_ccls_set_lsa (const struct cxl_cmd *cmd, +uint8_t *payload,CXLDeviceState *cxl_dstate,uint16_t *len) {@@ -448,7 +453,7 @@ static CXLRetCode cmd_ccls_set_lsa(struct cxl_cmd *cmd,uint32_t rsvd;uint8_t data[]; }QEMU_PACKED ; -struct set_lsa_pl *set_lsa_payload = (void *)cmd->payload; +struct set_lsa_pl *set_lsa_payload = (void *)payload;CXLType3Dev *ct3d =container_of (cxl_dstate, CXLType3Dev, cxl_dstate);CXLType3Class *cvc =CXL_TYPE3_GET_CLASS (ct3d);const size_t hdr_len = offsetof(struct set_lsa_pl , data);@@ -474,7 +479,8 @@ static CXLRetCode cmd_ccls_set_lsa(struct cxl_cmd *cmd,* make this stateful. We may want to allow longer poison lists to aid * testing that kernel functionality. */ -static CXLRetCode cmd_media_get_poison_list (struct cxl_cmd *cmd, +static CXLRetCode cmd_media_get_poison_list (const struct cxl_cmd *cmd, +uint8_t *payload,CXLDeviceState *cxl_dstate,uint16_t *len) {@@ -496,8 +502,8 @@ static CXLRetCode cmd_media_get_poison_list(struct cxl_cmd *cmd, }QEMU_PACKED records[]; }QEMU_PACKED ; -struct get_poison_list_pl *in = (void *)cmd->payload; -struct get_poison_list_out_pl *out = (void *)cmd->payload; +struct get_poison_list_pl *in = (void *)payload; +struct get_poison_list_out_pl *out = (void *)payload;CXLType3Dev *ct3d =container_of (cxl_dstate, CXLType3Dev, cxl_dstate);uint16_t record_count =0 , i =0 ;uint64_t query_start, query_length;@@ -550,7 +556,8 @@ static CXLRetCode cmd_media_get_poison_list(struct cxl_cmd *cmd,return CXL_MBOX_SUCCESS ; } -static CXLRetCode cmd_media_inject_poison (struct cxl_cmd *cmd, +static CXLRetCode cmd_media_inject_poison (const struct cxl_cmd *cmd, +uint8_t *payload,CXLDeviceState *cxl_dstate,uint16_t *len_unused) {@@ -560,7 +567,7 @@ static CXLRetCode cmd_media_inject_poison(struct cxl_cmd *cmd,struct inject_poison_pl {uint64_t dpa; }; -struct inject_poison_pl *in = (void *)cmd->payload; +struct inject_poison_pl *in = (void *)payload;uint64_t dpa =ldq_le_p (&in->dpa);CXLPoison *p;@@ -589,7 +596,8 @@ static CXLRetCode cmd_media_inject_poison(struct cxl_cmd *cmd,return CXL_MBOX_SUCCESS ; } -static CXLRetCode cmd_media_clear_poison (struct cxl_cmd *cmd, +static CXLRetCode cmd_media_clear_poison (const struct cxl_cmd *cmd, +uint8_t *payload,CXLDeviceState *cxl_dstate,uint16_t *len_unused) {@@ -603,7 +611,7 @@ static CXLRetCode cmd_media_clear_poison(struct cxl_cmd *cmd,CXLPoison *ent;uint64_t dpa; -struct clear_poison_pl *in = (void *)cmd->payload; +struct clear_poison_pl *in = (void *)payload; dpa =ldq_le_p (&in->dpa);if (dpa +CXL_CACHE_LINE_SIZE > cxl_dstate->mem_size) {@@ -673,7 +681,7 @@ static CXLRetCode cmd_media_clear_poison(struct cxl_cmd *cmd,#define IMMEDIATE_POLICY_CHANGE (1 << 3)#define IMMEDIATE_LOG_CHANGE (1 << 4) -static struct cxl_cmd cxl_cmd_set[256 ][256 ] = { +static const struct cxl_cmd cxl_cmd_set[256 ][256 ] = { [EVENTS ][GET_RECORDS ] = {"EVENTS_GET_RECORDS" , cmd_events_get_records,1 ,0 }, [EVENTS ][CLEAR_RECORDS ] = {"EVENTS_CLEAR_RECORDS" ,@@ -709,21 +717,21 @@ static struct cxl_cmd cxl_cmd_set[256][256] = {void cxl_process_mailbox (CXLDeviceState *cxl_dstate) {uint16_t ret =CXL_MBOX_SUCCESS ; -struct cxl_cmd *cxl_cmd; -uint64_t status_reg; +const struct cxl_cmd *cxl_cmd; +uint64_t status_reg =0 ;opcode_handler h;uint64_t command_reg = cxl_dstate->mbox_reg_state64[R_CXL_DEV_MAILBOX_CMD ];uint8_t set =FIELD_EX64 (command_reg,CXL_DEV_MAILBOX_CMD ,COMMAND_SET );uint8_t cmd =FIELD_EX64 (command_reg,CXL_DEV_MAILBOX_CMD ,COMMAND );uint16_t len =FIELD_EX64 (command_reg,CXL_DEV_MAILBOX_CMD ,LENGTH ); - cxl_cmd = &cxl_cmd_set[set][cmd]; +uint8_t *pl = cxl_dstate->mbox_reg_state +A_CXL_DEV_CMD_PAYLOAD ; + + cxl_cmd = &cxl_dstate->cxl_cmd_set[set][cmd]; h = cxl_cmd->handler;if (h) {if (len == cxl_cmd->in || cxl_cmd->in == ~0 ) { - cxl_cmd->payload = cxl_dstate->mbox_reg_state + -A_CXL_DEV_CMD_PAYLOAD ; - ret = (*h)(cxl_cmd, cxl_dstate, &len); + ret = (*h)(cxl_cmd, pl, cxl_dstate, &len);assert (len <= cxl_dstate->payload_size); }else { ret =CXL_MBOX_INVALID_PAYLOAD_LENGTH ;@@ -752,10 +760,11 @@ void cxl_process_mailbox(CXLDeviceState *cxl_dstate)void cxl_initialize_mailbox (CXLDeviceState *cxl_dstate) { + cxl_dstate->cxl_cmd_set = cxl_cmd_set;for (int set =0 ; set <256 ; set++) {for (int cmd =0 ; cmd <256 ; cmd++) { -if (cxl_cmd_set[set][cmd].handler) { -struct cxl_cmd *c = &cxl_cmd_set[set][cmd]; +if (cxl_dstate->cxl_cmd_set[set][cmd].handler) { +const struct cxl_cmd *c = &cxl_dstate->cxl_cmd_set[set][cmd];struct cel_log *log = &cxl_dstate->cel_log[cxl_dstate->cel_size];Signature · 1 line
2.39.2
PATCH 2/19 hw/cxl/mbox: Split mailbox command payload into separate input and output
In reply to Jonathan CameronNew CCI types that will be supported shortly do not have a single buffer used in both directions. As such, split it up. For CXL mailboxes the two pointers will be aliases of the same memory so all callbacks must allow for that.
--- include/hw/cxl/cxl_device.h | 7 +- hw/cxl/cxl-events.c | 2 +- hw/cxl/cxl-mailbox-utils.c | 222 +++++++++++++++++++++--------------- 3 files changed, 132 insertions(+), 99 deletions(-)
include/hw/cxl/cxl_device.h +4 -3
@@ -114,8 +114,9 @@ typedef enum {typedef struct cxl_device_state CXLDeviceState ;struct cxl_cmd ;typedef CXLRetCode (*opcode_handler )(const struct cxl_cmd *cmd, -uint8_t *payload, -CXLDeviceState *cxl_dstate,uint16_t *len); +uint8_t *payload_in,size_t len_in, +uint8_t *payload_out,size_t *len_out, +CXLDeviceState *cxl_dstate);struct cxl_cmd {const char *name;opcode_handler handler;
@@ -390,7 +391,7 @@ bool cxl_event_insert(CXLDeviceState *cxlds, CXLEventLogType log_type, CXLEventRecordRaw *event);CXLRetCode cxl_event_get_records (CXLDeviceState *cxlds,CXLGetEventPayload *pl,uint8_t log_type,int max_recs, -uint16_t *len); +size_t *len);CXLRetCode cxl_event_clear_records (CXLDeviceState *cxlds,CXLClearEventPayload *pl);
hw/cxl/cxl-events.c +1 -1
@@ -143,7 +143,7 @@ bool cxl_event_insert(CXLDeviceState *cxlds, CXLEventLogType log_type,CXLRetCode cxl_event_get_records (CXLDeviceState *cxlds,CXLGetEventPayload *pl,uint8_t log_type,int max_recs, -uint16_t *len) +size_t *len) {CXLEventLog *log;CXLEvent *entry;
hw/cxl/cxl-mailbox-utils.c +127 -95
495 lines not on this page · raw message
Signature · 1 line
2.39.2
Re: [PATCH 02/19] hw/cxl/mbox: Split mailbox command payload into separate input and output
Quoted 7 lines · Jonathan Cameron
New CCI types that will be supported shortly do not have a single buffer used in both directions. As such, split it up. For CXL mailboxes the two pointers will be aliases of the same memory so all callbacks must allow for that.
Signed-off-by Jonathan Cameron <[email protected]>---
Quoted 570 lines
include/hw/cxl/cxl_device.h | 7 +- hw/cxl/cxl-events.c | 2 +- hw/cxl/cxl-mailbox-utils.c | 222 +++++++++++++++++++++--------------- 3 files changed, 132 insertions(+), 99 deletions(-)include/hw/cxl/cxl_device.h +4
-3@@ -114,8 +114,9 @@ typedef enum {typedef struct cxl_device_state CXLDeviceState ;struct cxl_cmd ;typedef CXLRetCode (*opcode_handler )(const struct cxl_cmd *cmd, -uint8_t *payload, -CXLDeviceState *cxl_dstate,uint16_t *len); +uint8_t *payload_in,size_t len_in, +uint8_t *payload_out,size_t *len_out, +CXLDeviceState *cxl_dstate);struct cxl_cmd {const char *name;opcode_handler handler;@@ -390,7 +391,7 @@ bool cxl_event_insert(CXLDeviceState *cxlds, CXLEventLogType log_type, CXLEventRecordRaw *event);CXLRetCode cxl_event_get_records (CXLDeviceState *cxlds,CXLGetEventPayload *pl,uint8_t log_type,int max_recs, -uint16_t *len); +size_t *len);CXLRetCode cxl_event_clear_records (CXLDeviceState *cxlds,CXLClearEventPayload *pl);hw/cxl/cxl-events.c +1
-1@@ -143,7 +143,7 @@ bool cxl_event_insert(CXLDeviceState *cxlds, CXLEventLogType log_type,CXLRetCode cxl_event_get_records (CXLDeviceState *cxlds,CXLGetEventPayload *pl,uint8_t log_type,int max_recs, -uint16_t *len) +size_t *len) {CXLEventLog *log;CXLEvent *entry;hw/cxl/cxl-mailbox-utils.c +127
-95@@ -71,9 +71,9 @@ enum {static CXLRetCode cmd_events_get_records (const struct cxl_cmd *cmd, -uint8_t *payload, -CXLDeviceState *cxlds, -uint16_t *len) +uint8_t *payload_in,size_t len_in, +uint8_t *payload_out,size_t *len_out, +CXLDeviceState *cxlds) {CXLGetEventPayload *pl;uint8_t log_type;@@ -83,9 +83,9 @@ static CXLRetCode cmd_events_get_records(const struct cxl_cmd *cmd,return CXL_MBOX_INVALID_INPUT ; } - log_type = payload[0 ]; + log_type = payload_in[0 ]; - pl = (CXLGetEventPayload *)payload; + pl = (CXLGetEventPayload *)payload_out;memset (pl,0 ,sizeof (*pl)); max_recs = (cxlds->payload_size - CXL_EVENT_PAYLOAD_HDR_SIZE) /@@ -94,30 +94,34 @@ static CXLRetCode cmd_events_get_records(const struct cxl_cmd *cmd, max_recs =0xFFFF ; } -return cxl_event_get_records (cxlds, pl, log_type, max_recs, len); +return cxl_event_get_records (cxlds, pl, log_type, max_recs, len_out); }static CXLRetCode cmd_events_clear_records (const struct cxl_cmd *cmd, -uint8_t *payload, -CXLDeviceState *cxlds, -uint16_t *len) +uint8_t *payload_in, +size_t len_in, +uint8_t *payload_out, +size_t *len_out, +CXLDeviceState *cxlds) {CXLClearEventPayload *pl; - pl = (CXLClearEventPayload *)payload; - *len =0 ; + pl = (CXLClearEventPayload *)payload_in; + *len_out =0 ;return cxl_event_clear_records (cxlds, pl); }static CXLRetCode cmd_events_get_interrupt_policy (const struct cxl_cmd *cmd, -uint8_t *payload, -CXLDeviceState *cxlds, -uint16_t *len) +uint8_t *payload_in, +size_t len_in, +uint8_t *payload_out, +size_t *len_out, +CXLDeviceState *cxlds) {CXLEventInterruptPolicy *policy;CXLEventLog *log; - policy = (CXLEventInterruptPolicy *)payload; + policy = (CXLEventInterruptPolicy *)payload_out;memset (policy,0 ,sizeof (*policy)); log = &cxlds->event_logs[CXL_EVENT_TYPE_INFO ];@@ -146,23 +150,25 @@ static CXLRetCode cmd_events_get_interrupt_policy(const struct cxl_cmd *cmd, policy->dyn_cap_settings =CXL_INT_MSI_MSIX ; } - *len =sizeof (*policy); + *len_out =sizeof (*policy);return CXL_MBOX_SUCCESS ; }static CXLRetCode cmd_events_set_interrupt_policy (const struct cxl_cmd *cmd, -uint8_t *payload, -CXLDeviceState *cxlds, -uint16_t *len) +uint8_t *payload_in, +size_t len_in, +uint8_t *payload_out, +size_t *len_out, +CXLDeviceState *cxlds) {CXLEventInterruptPolicy *policy;CXLEventLog *log; -if (*len <CXL_EVENT_INT_SETTING_MIN_LEN ) { +if (len_in <CXL_EVENT_INT_SETTING_MIN_LEN ) {return CXL_MBOX_INVALID_PAYLOAD_LENGTH ; } - policy = (CXLEventInterruptPolicy *)payload; + policy = (CXLEventInterruptPolicy *)payload_in; log = &cxlds->event_logs[CXL_EVENT_TYPE_INFO ]; log->irq_enabled = (policy->info_settings & CXL_EVENT_INT_MODE_MASK) ==@@ -181,7 +187,7 @@ static CXLRetCode cmd_events_set_interrupt_policy(const struct cxl_cmd *cmd,CXL_INT_MSI_MSIX ;/* DCD is optional */ -if (*len <sizeof (*policy)) { +if (len_in <sizeof (*policy)) {return CXL_MBOX_SUCCESS ; }@@ -189,15 +195,17 @@ static CXLRetCode cmd_events_set_interrupt_policy(const struct cxl_cmd *cmd, log->irq_enabled = (policy->dyn_cap_settings &CXL_EVENT_INT_MODE_MASK ) ==CXL_INT_MSI_MSIX ; - *len =sizeof (*policy); + *len_out =0 ;return CXL_MBOX_SUCCESS ; }/* 8.2.9.2.1 */ static CXLRetCode cmd_firmware_update_get_info (const struct cxl_cmd *cmd, -uint8_t *payload, -CXLDeviceState *cxl_dstate, -uint16_t *len) +uint8_t *payload_in, +size_t len, +uint8_t *payload_out, +size_t *len_out, +CXLDeviceState *cxl_dstate) {struct {uint8_t slots_supported;@@ -216,7 +224,7 @@ static CXLRetCode cmd_firmware_update_get_info(const struct cxl_cmd *cmd,return CXL_MBOX_INTERNAL_ERROR ; } - fw_info = (void *)payload; + fw_info = (void *)payload_out;memset (fw_info,0 ,sizeof (*fw_info)); fw_info->slots_supported =2 ;@@ -224,36 +232,40 @@ static CXLRetCode cmd_firmware_update_get_info(const struct cxl_cmd *cmd, fw_info->caps =0 ;pstrcpy (fw_info->fw_rev1,sizeof (fw_info->fw_rev1),"BWFW VERSION 0" ); - *len =sizeof (*fw_info); + *len_out =sizeof (*fw_info);return CXL_MBOX_SUCCESS ; }/* 8.2.9.3.1 */ static CXLRetCode cmd_timestamp_get (const struct cxl_cmd *cmd, -uint8_t *payload, -CXLDeviceState *cxl_dstate, -uint16_t *len) +uint8_t *payload_in, +size_t len_in, +uint8_t *payload_out, +size_t *len_out, +CXLDeviceState *cxl_dstate) {uint64_t final_time =cxl_device_get_timestamp (cxl_dstate); -stq_le_p (payload, final_time); - *len =8 ; +stq_le_p (payload_out, final_time); + *len_out =8 ;return CXL_MBOX_SUCCESS ; }/* 8.2.9.3.2 */ static CXLRetCode cmd_timestamp_set (const struct cxl_cmd *cmd, -uint8_t *payload, -CXLDeviceState *cxl_dstate, -uint16_t *len) +uint8_t *payload_in, +size_t len_in, +uint8_t *payload_out, +size_t *len_out, +CXLDeviceState *cxl_dstate) { cxl_dstate->timestamp.set = true; cxl_dstate->timestamp.last_set =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); - cxl_dstate->timestamp.host_set =le64_to_cpu (*(uint64_t *)payload); + cxl_dstate->timestamp.host_set =le64_to_cpu (*(uint64_t *)payload_in); - *len =0 ; + *len_out =0 ;return CXL_MBOX_SUCCESS ; }@@ -265,9 +277,11 @@ static const QemuUUID cel_uuid = {/* 8.2.9.4.1 */ static CXLRetCode cmd_logs_get_supported (const struct cxl_cmd *cmd, -uint8_t *payload, -CXLDeviceState *cxl_dstate, -uint16_t *len) +uint8_t *payload_in, +size_t len_in, +uint8_t *payload_out, +size_t *len_out, +CXLDeviceState *cxl_dstate) {struct {uint16_t entries;@@ -276,22 +290,24 @@ static CXLRetCode cmd_logs_get_supported(const struct cxl_cmd *cmd,QemuUUID uuid;uint32_t size; } log_entries[1 ]; - }QEMU_PACKED *supported_logs = (void *)payload; + }QEMU_PACKED *supported_logs = (void *)payload_out;QEMU_BUILD_BUG_ON (sizeof (*supported_logs) !=0x1c ); supported_logs->entries =1 ; supported_logs->log_entries[0 ].uuid = cel_uuid; supported_logs->log_entries[0 ].size =4 * cxl_dstate->cel_size; - *len =sizeof (*supported_logs); + *len_out =sizeof (*supported_logs);return CXL_MBOX_SUCCESS ; }/* 8.2.9.4.2 */ static CXLRetCode cmd_logs_get_log (const struct cxl_cmd *cmd, -uint8_t *payload, -CXLDeviceState *cxl_dstate, -uint16_t *len) +uint8_t *payload_in, +size_t len_in, +uint8_t *payload_out, +size_t *len_out, +CXLDeviceState *cxl_dstate) {struct {QemuUUID uuid;@@ -299,7 +315,7 @@ static CXLRetCode cmd_logs_get_log(const struct cxl_cmd *cmd,uint32_t length; } QEMU_PACKED QEMU_ALIGNED(16) *get_log; - get_log = (void *)payload; + get_log = (void *)payload_in;/* * 8.2.9.4.2 @@ -323,19 +339,21 @@ static CXLRetCode cmd_logs_get_log(const struct cxl_cmd *cmd, }/* Store off everything to local variables so we can wipe out the payload */ - *len = get_log->length; + *len_out = get_log->length; -memmove (payload, cxl_dstate->cel_log + get_log->offset, - get_log->length); +memmove (payload_out, cxl_dstate->cel_log + get_log->offset, + get_log->length);return CXL_MBOX_SUCCESS ; }/* 8.2.9.5.1.1 */ static CXLRetCode cmd_identify_memory_device (const struct cxl_cmd *cmd, -uint8_t *payload, -CXLDeviceState *cxl_dstate, -uint16_t *len) +uint8_t *payload_in, +size_t len_in, +uint8_t *payload_out, +size_t *len_out, +CXLDeviceState *cxl_dstate) {struct {char fw_revision[0x10 ];@@ -363,7 +381,7 @@ static CXLRetCode cmd_identify_memory_device(const struct cxl_cmd *cmd,return CXL_MBOX_INTERNAL_ERROR ; } - id = (void *)payload; + id = (void *)payload_out;memset (id,0 ,sizeof (*id));snprintf (id->fw_revision,0x10 ,"BWFW VERSION %02d" ,0 );@@ -380,21 +398,23 @@ static CXLRetCode cmd_identify_memory_device(const struct cxl_cmd *cmd,/* No limit - so limited by main poison record limit */ stw_le_p (&id->inject_poison_limit,0 ); - *len =sizeof (*id); + *len_out =sizeof (*id);return CXL_MBOX_SUCCESS ; }static CXLRetCode cmd_ccls_get_partition_info (const struct cxl_cmd *cmd, -uint8_t *payload, -CXLDeviceState *cxl_dstate, -uint16_t *len) +uint8_t *payload_in, +size_t len_in, +uint8_t *payload_out, +size_t *len_out, +CXLDeviceState *cxl_dstate) {struct {uint64_t active_vmem;uint64_t active_pmem;uint64_t next_vmem;uint64_t next_pmem; - } QEMU_PACKED *part_info = (void *)payload; + } QEMU_PACKED *part_info = (void *)payload_out;QEMU_BUILD_BUG_ON (sizeof (*part_info) !=0x20 ); if ((!QEMU_IS_ALIGNED(cxl_dstate->vmem_size, CXL_CAPACITY_MULTIPLIER)) ||@@ -413,14 +433,16 @@ static CXLRetCode cmd_ccls_get_partition_info(const struct cxl_cmd *cmd, cxl_dstate->pmem_size / CXL_CAPACITY_MULTIPLIER);stq_le_p (&part_info->next_pmem,0 ); - *len =sizeof (*part_info); + *len_out =sizeof (*part_info);return CXL_MBOX_SUCCESS ; }static CXLRetCode cmd_ccls_get_lsa (const struct cxl_cmd *cmd, -uint8_t *payload, -CXLDeviceState *cxl_dstate, -uint16_t *len) +uint8_t *payload_in, +size_t len_in, +uint8_t *payload_out, +size_t *len_out, +CXLDeviceState *cxl_dstate) {struct {uint32_t offset;@@ -430,46 +452,47 @@ static CXLRetCode cmd_ccls_get_lsa(const struct cxl_cmd *cmd,CXLType3Class *cvc =CXL_TYPE3_GET_CLASS (ct3d);uint32_t offset, length; - get_lsa = (void *)payload; + get_lsa = (void *)payload_in; offset = get_lsa->offset; length = get_lsa->length;if (offset + length > cvc->get_lsa_size (ct3d)) { - *len =0 ; + *len_out =0 ;return CXL_MBOX_INVALID_INPUT ; } - *len = cvc->get_lsa (ct3d, get_lsa, length, offset); + *len_out = cvc->get_lsa (ct3d, payload_out, length, offset);return CXL_MBOX_SUCCESS ; }static CXLRetCode cmd_ccls_set_lsa (const struct cxl_cmd *cmd, -uint8_t *payload, -CXLDeviceState *cxl_dstate, -uint16_t *len) +uint8_t *payload_in, +size_t len_in, +uint8_t *payload_out, +size_t *len_out, +CXLDeviceState *cxl_dstate) {struct set_lsa_pl {uint32_t offset;uint32_t rsvd;uint8_t data[]; }QEMU_PACKED ; -struct set_lsa_pl *set_lsa_payload = (void *)payload; +struct set_lsa_pl *set_lsa_payload = (void *)payload_in;CXLType3Dev *ct3d =container_of (cxl_dstate, CXLType3Dev, cxl_dstate);CXLType3Class *cvc =CXL_TYPE3_GET_CLASS (ct3d);const size_t hdr_len = offsetof(struct set_lsa_pl , data); -uint16_t plen = *len; - *len =0 ; -if (!plen) { + *len_out =0 ; +if (!len_in) {return CXL_MBOX_SUCCESS ; } -if (set_lsa_payload->offset + plen > cvc->get_lsa_size (ct3d) + hdr_len) { +if (set_lsa_payload->offset + len_in > cvc->get_lsa_size (ct3d) + hdr_len) {return CXL_MBOX_INVALID_INPUT ; } - plen -= hdr_len; + len_in -= hdr_len; - cvc->set_lsa (ct3d, set_lsa_payload->data, plen, set_lsa_payload->offset); + cvc->set_lsa (ct3d, set_lsa_payload->data, len_in, set_lsa_payload->offset);return CXL_MBOX_SUCCESS ; }@@ -480,9 +503,11 @@ static CXLRetCode cmd_ccls_set_lsa(const struct cxl_cmd *cmd,* testing that kernel functionality. */ static CXLRetCode cmd_media_get_poison_list (const struct cxl_cmd *cmd, -uint8_t *payload, -CXLDeviceState *cxl_dstate, -uint16_t *len) +uint8_t *payload_in, +size_t len_in, +uint8_t *payload_out, +size_t *len_out, +CXLDeviceState *cxl_dstate) {struct get_poison_list_pl {uint64_t pa;@@ -502,8 +527,8 @@ static CXLRetCode cmd_media_get_poison_list(const struct cxl_cmd *cmd, }QEMU_PACKED records[]; }QEMU_PACKED ; -struct get_poison_list_pl *in = (void *)payload; -struct get_poison_list_out_pl *out = (void *)payload; +struct get_poison_list_pl *in = (void *)payload_in; +struct get_poison_list_out_pl *out = (void *)payload_out;CXLType3Dev *ct3d =container_of (cxl_dstate, CXLType3Dev, cxl_dstate);uint16_t record_count =0 , i =0 ;uint64_t query_start, query_length;@@ -552,14 +577,16 @@ static CXLRetCode cmd_media_get_poison_list(const struct cxl_cmd *cmd,stq_le_p (&out->overflow_timestamp, ct3d->poison_list_overflow_ts); }stw_le_p (&out->count, record_count); - *len = out_pl_len; + *len_out = out_pl_len;return CXL_MBOX_SUCCESS ; }static CXLRetCode cmd_media_inject_poison (const struct cxl_cmd *cmd, -uint8_t *payload, -CXLDeviceState *cxl_dstate, -uint16_t *len_unused) +uint8_t *payload_in, +size_t len_in, +uint8_t *payload_out, +size_t *len_out, +CXLDeviceState *cxl_dstate) {CXLType3Dev *ct3d =container_of (cxl_dstate, CXLType3Dev, cxl_dstate);CXLPoisonList *poison_list = &ct3d->poison_list;@@ -567,7 +594,7 @@ static CXLRetCode cmd_media_inject_poison(const struct cxl_cmd *cmd,struct inject_poison_pl {uint64_t dpa; }; -struct inject_poison_pl *in = (void *)payload; +struct inject_poison_pl *in = (void *)payload_in;uint64_t dpa =ldq_le_p (&in->dpa);CXLPoison *p;@@ -592,14 +619,17 @@ static CXLRetCode cmd_media_inject_poison(const struct cxl_cmd *cmd,*/ QLIST_INSERT_HEAD (poison_list, p, node); ct3d->poison_list_cnt++; + *len_out =0 ;return CXL_MBOX_SUCCESS ; }static CXLRetCode cmd_media_clear_poison (const struct cxl_cmd *cmd, -uint8_t *payload, -CXLDeviceState *cxl_dstate, -uint16_t *len_unused) +uint8_t *payload_in, +size_t len_in, +uint8_t *payload_out, +size_t *len_out, +CXLDeviceState *cxl_dstate) {CXLType3Dev *ct3d =container_of (cxl_dstate, CXLType3Dev, cxl_dstate);CXLPoisonList *poison_list = &ct3d->poison_list;@@ -611,7 +641,7 @@ static CXLRetCode cmd_media_clear_poison(const struct cxl_cmd *cmd,CXLPoison *ent;uint64_t dpa; -struct clear_poison_pl *in = (void *)payload; +struct clear_poison_pl *in = (void *)payload_in; dpa =ldq_le_p (&in->dpa);if (dpa +CXL_CACHE_LINE_SIZE > cxl_dstate->mem_size) {@@ -672,6 +702,7 @@ static CXLRetCode cmd_media_clear_poison(const struct cxl_cmd *cmd, }/* Any fragments have been added, free original entry */ g_free (ent); + *len_out =0 ;return CXL_MBOX_SUCCESS ; }@@ -724,15 +755,16 @@ void cxl_process_mailbox(CXLDeviceState *cxl_dstate)uint8_t set =FIELD_EX64 (command_reg,CXL_DEV_MAILBOX_CMD ,COMMAND_SET );uint8_t cmd =FIELD_EX64 (command_reg,CXL_DEV_MAILBOX_CMD ,COMMAND ); -uint16_t len =FIELD_EX64 (command_reg,CXL_DEV_MAILBOX_CMD ,LENGTH ); +uint16_t len_in =FIELD_EX64 (command_reg,CXL_DEV_MAILBOX_CMD ,LENGTH );uint8_t *pl = cxl_dstate->mbox_reg_state +A_CXL_DEV_CMD_PAYLOAD ; +size_t len_out =0 ; cxl_cmd = &cxl_dstate->cxl_cmd_set[set][cmd]; h = cxl_cmd->handler;if (h) { -if (len == cxl_cmd->in || cxl_cmd->in == ~0 ) { - ret = (*h)(cxl_cmd, pl, cxl_dstate, &len); -assert (len <= cxl_dstate->payload_size); +if (len_in == cxl_cmd->in || cxl_cmd->in == ~0 ) { + ret = (*h)(cxl_cmd, pl, len_in, pl, &len_out, cxl_dstate); +assert (len_out <= cxl_dstate->payload_size); }else { ret =CXL_MBOX_INVALID_PAYLOAD_LENGTH ; }@@ -748,7 +780,7 @@ void cxl_process_mailbox(CXLDeviceState *cxl_dstate)/* Set the return length */ command_reg =FIELD_DP64 (command_reg,CXL_DEV_MAILBOX_CMD ,COMMAND_SET ,0 ); command_reg =FIELD_DP64 (command_reg,CXL_DEV_MAILBOX_CMD ,COMMAND ,0 ); - command_reg =FIELD_DP64 (command_reg,CXL_DEV_MAILBOX_CMD ,LENGTH , len); + command_reg =FIELD_DP64 (command_reg,CXL_DEV_MAILBOX_CMD ,LENGTH , len_out); cxl_dstate->mbox_reg_state64[R_CXL_DEV_MAILBOX_CMD ] = command_reg; cxl_dstate->mbox_reg_state64[R_CXL_DEV_MAILBOX_STS ] = status_reg;Signature · 1 line
2.39.2
PATCH 3/19 hw/cxl/mbox: Pull the CCI definition out of the CXLDeviceState
In reply to Jonathan CameronEnables having multiple CCIs per devices. Each CCI (mailbox) has it's own state and command list, so they can't share a single structure.
--- include/hw/cxl/cxl_device.h | 45 ++++++++++++++---- hw/cxl/cxl-device-utils.c | 31 +++++++++--- hw/cxl/cxl-mailbox-utils.c | 94 ++++++++++++++++++++++--------------- hw/mem/cxl_type3.c | 5 +- 4 files changed, 119 insertions(+), 56 deletions(-)
include/hw/cxl/cxl_device.h +35 -10
@@ -111,12 +111,13 @@ typedef enum { CXL_MBOX_MAX = 0x17 } CXLRetCode; +typedef struct CXLCCI CXLCCI ;typedef struct cxl_device_state CXLDeviceState ;struct cxl_cmd ;typedef CXLRetCode (*opcode_handler )(const struct cxl_cmd *cmd,uint8_t *payload_in,size_t len_in,uint8_t *payload_out,size_t *len_out, -CXLDeviceState *cxl_dstate); +CXLCCI *cci);struct cxl_cmd {const char *name;opcode_handler handler;
@@ -140,6 +141,31 @@ typedef struct CXLEventLog { QSIMPLEQ_HEAD(, CXLEvent) events; } CXLEventLog; +typedef struct CXLCCI { +const struct cxl_cmd (*cxl_cmd_set)[256 ]; +struct cel_log { +uint16_t opcode; +uint16_t effect; + } cel_log[1 <<16 ]; +size_t cel_size; + +/* background command handling (times in ms) */ +struct { +uint16_t opcode; +uint16_t complete_pct; +uint16_t ret_code;/* Current value of retcode */ +uint64_t starttime; +/* set by each bg cmd, cleared by the bg_timer when complete */ +uint64_t runtime; +QEMUTimer *timer; + } bg; +size_t payload_max; +/* Pointer to device hosting the CCI */ +DeviceState *d; +/* Pointer to the device hosting the protocol conversion */ +DeviceState *intf; +}CXLCCI ; + typedef struct cxl_device_state { MemoryRegion device_registers;
@@ -173,11 +199,6 @@ typedef struct cxl_device_state {uint32_t mbox_reg_state32[CXL_MAILBOX_REGISTERS_LENGTH /4 ];uint64_t mbox_reg_state64[CXL_MAILBOX_REGISTERS_LENGTH /8 ]; }; -struct cel_log { -uint16_t opcode; -uint16_t effect; - } cel_log[1 <<16 ]; -size_t cel_size; };struct {
@@ -196,10 +217,12 @@ typedef struct cxl_device_state { } CXLDeviceState;/* Initialize the register block for a device */ -void cxl_device_register_block_init (Object *obj,CXLDeviceState *dev); +void cxl_device_register_block_init (Object *obj,CXLDeviceState *dev, +CXLCCI *cci); +typedef struct CXLType3Dev CXLType3Dev ;/* Set up default values for the register block */ -void cxl_device_register_init_common (CXLDeviceState *dev); +void cxl_device_register_init_t3 (CXLType3Dev *ct3d);/* * CXL 2.0 - 8.2.8.1 including errata F4
@@ -245,8 +268,9 @@ CXL_DEVICE_CAPABILITY_HEADER_REGISTER(MEMORY_DEVICE, CXL_DEVICE_CAP_HDR1_OFFSET + CXL_DEVICE_CAP_REG_SIZE * 2) -void cxl_initialize_mailbox (CXLDeviceState *cxl_dstate); -void cxl_process_mailbox (CXLDeviceState *cxl_dstate); +void cxl_initialize_mailbox_t3 (CXLCCI *cci,DeviceState *d,size_t payload_max); +void cxl_init_cci (CXLCCI *cci,size_t payload_max); +void cxl_process_mailbox (CXLCCI *cci);#define cxl_device_cap_init (dstate, reg, cap_id, ver) \ do { \
@@ -347,6 +371,7 @@ struct CXLType3Dev {AddressSpace hostpmem_as;CXLComponentState cxl_cstate;CXLDeviceState cxl_dstate; +CXLCCI cci;/* Primary PCI mailbox CCI */ /* DOE */ DOECap doe_cdat;
hw/cxl/cxl-device-utils.c +24 -7
@@ -62,7 +62,14 @@ static uint64_t dev_reg_read(void *opaque, hwaddr offset, unsigned size)static uint64_t mailbox_reg_read (void *opaque,hwaddr offset,unsigned size) { -CXLDeviceState *cxl_dstate = opaque; +CXLDeviceState *cxl_dstate; +CXLCCI *cci = opaque; + +if (object_dynamic_cast (OBJECT (cci->intf),TYPE_CXL_TYPE3 )) { + cxl_dstate = &CXL_TYPE3 (cci->intf)->cxl_dstate; + }else { +return 0 ; + }switch (size) {case 1 :
@@ -123,7 +130,14 @@ static void mailbox_mem_writeq(uint64_t *reg_state, hwaddr offset,static void mailbox_reg_write (void *opaque,hwaddr offset,uint64_t value,unsigned size) { -CXLDeviceState *cxl_dstate = opaque; +CXLDeviceState *cxl_dstate; +CXLCCI *cci = opaque; + +if (object_dynamic_cast (OBJECT (cci->intf),TYPE_CXL_TYPE3 )) { + cxl_dstate = &CXL_TYPE3 (cci->intf)->cxl_dstate; + }else { +return ; + }if (offset >=A_CXL_DEV_CMD_PAYLOAD ) {memcpy (cxl_dstate->mbox_reg_state + offset, &value, size);
@@ -143,7 +157,7 @@ static void mailbox_reg_write(void *opaque, hwaddr offset, uint64_t value,if (ARRAY_FIELD_EX32 (cxl_dstate->mbox_reg_state32,CXL_DEV_MAILBOX_CTRL ,DOORBELL )) { -cxl_process_mailbox (cxl_dstate); +cxl_process_mailbox (cci); } }
@@ -223,7 +237,8 @@ static const MemoryRegionOps caps_ops = { }, }; -void cxl_device_register_block_init (Object *obj,CXLDeviceState *cxl_dstate) +void cxl_device_register_block_init (Object *obj,CXLDeviceState *cxl_dstate, +CXLCCI *cci) {/* This will be a BAR, so needs to be rounded up to pow2 for PCI spec */ memory_region_init(&cxl_dstate->device_registers, obj, "device-registers",
@@ -233,7 +248,7 @@ void cxl_device_register_block_init(Object *obj, CXLDeviceState *cxl_dstate) "cap-array", CXL_CAPS_SIZE);memory_region_init_io (&cxl_dstate->device, obj, &dev_ops, cxl_dstate,"device-status" ,CXL_DEVICE_STATUS_REGISTERS_LENGTH ); -memory_region_init_io (&cxl_dstate->mailbox, obj, &mailbox_ops, cxl_dstate, +memory_region_init_io (&cxl_dstate->mailbox, obj, &mailbox_ops, cci,"mailbox" ,CXL_MAILBOX_REGISTERS_LENGTH ); memory_region_init_io(&cxl_dstate->memory_device, obj, &mdev_ops, cxl_dstate, "memory device caps",
@@ -284,8 +299,9 @@ static void mailbox_reg_init_common(CXLDeviceState *cxl_dstate)static void memdev_reg_init_common (CXLDeviceState *cxl_dstate) { } -void cxl_device_register_init_common (CXLDeviceState *cxl_dstate) +void cxl_device_register_init_t3 (CXLType3Dev *ct3d) { +CXLDeviceState *cxl_dstate = &ct3d->cxl_dstate;uint64_t *cap_h = cxl_dstate->caps_reg_state64;const int cap_count =3 ;
@@ -303,7 +319,8 @@ void cxl_device_register_init_common(CXLDeviceState *cxl_dstate)cxl_device_cap_init (cxl_dstate,MEMORY_DEVICE ,0x4000 ,1 );memdev_reg_init_common (cxl_dstate); -cxl_initialize_mailbox (cxl_dstate); +cxl_initialize_mailbox_t3 (&ct3d->cci,DEVICE (ct3d), +CXL_MAILBOX_MAX_PAYLOAD_SIZE ); }uint64_t cxl_device_get_timestamp (CXLDeviceState *cxl_dstate)
hw/cxl/cxl-mailbox-utils.c +57 -37
276 lines not on this page · raw message
hw/mem/cxl_type3.c +3 -2
@@ -716,7 +716,8 @@ static void ct3_realize(PCIDevice *pci_dev, Error **errp) pci_dev,CXL_COMPONENT_REG_BAR_IDX , PCI_BASE_ADDRESS_SPACE_MEMORY | PCI_BASE_ADDRESS_MEM_TYPE_64, mr); -cxl_device_register_block_init (OBJECT (pci_dev), &ct3d->cxl_dstate); +cxl_device_register_block_init (OBJECT (pci_dev), &ct3d->cxl_dstate, + &ct3d->cci); pci_register_bar(pci_dev, CXL_DEVICE_REG_BAR_IDX, PCI_BASE_ADDRESS_SPACE_MEMORY | PCI_BASE_ADDRESS_MEM_TYPE_64,
@@ -922,7 +923,7 @@ static void ct3d_reset(DeviceState *dev)uint32_t *write_msk = ct3d->cxl_cstate.crb.cache_mem_regs_write_mask;cxl_component_register_init_common (reg_state, write_msk,CXL2_TYPE3_DEVICE ); -cxl_device_register_init_common (&ct3d->cxl_dstate); +cxl_device_register_init_t3 (ct3d); }static Property ct3_props[] = {
Signature · 1 line
2.39.2
Re: [PATCH 03/19] hw/cxl/mbox: Pull the CCI definition out of the CXLDeviceState
Quoted 5 lines · Jonathan Cameron
Enables having multiple CCIs per devices. Each CCI (mailbox) has it's own state and command list, so they can't share a single structure.
Signed-off-by Jonathan Cameron <[email protected]>---
Quoted 520 lines
include/hw/cxl/cxl_device.h | 45 ++++++++++++++---- hw/cxl/cxl-device-utils.c | 31 +++++++++--- hw/cxl/cxl-mailbox-utils.c | 94 ++++++++++++++++++++++--------------- hw/mem/cxl_type3.c | 5 +- 4 files changed, 119 insertions(+), 56 deletions(-)include/hw/cxl/cxl_device.h +35
-10@@ -111,12 +111,13 @@ typedef enum { CXL_MBOX_MAX = 0x17 } CXLRetCode; +typedef struct CXLCCI CXLCCI ;typedef struct cxl_device_state CXLDeviceState ;struct cxl_cmd ;typedef CXLRetCode (*opcode_handler )(const struct cxl_cmd *cmd,uint8_t *payload_in,size_t len_in,uint8_t *payload_out,size_t *len_out, -CXLDeviceState *cxl_dstate); +CXLCCI *cci);struct cxl_cmd {const char *name;opcode_handler handler;@@ -140,6 +141,31 @@ typedef struct CXLEventLog { QSIMPLEQ_HEAD(, CXLEvent) events; } CXLEventLog; +typedef struct CXLCCI { +const struct cxl_cmd (*cxl_cmd_set)[256 ]; +struct cel_log { +uint16_t opcode; +uint16_t effect; + } cel_log[1 <<16 ]; +size_t cel_size; + +/* background command handling (times in ms) */ +struct { +uint16_t opcode; +uint16_t complete_pct; +uint16_t ret_code;/* Current value of retcode */ +uint64_t starttime; +/* set by each bg cmd, cleared by the bg_timer when complete */ +uint64_t runtime; +QEMUTimer *timer; + } bg; +size_t payload_max; +/* Pointer to device hosting the CCI */ +DeviceState *d; +/* Pointer to the device hosting the protocol conversion */ +DeviceState *intf; +}CXLCCI ; + typedef struct cxl_device_state { MemoryRegion device_registers;@@ -173,11 +199,6 @@ typedef struct cxl_device_state {uint32_t mbox_reg_state32[CXL_MAILBOX_REGISTERS_LENGTH /4 ];uint64_t mbox_reg_state64[CXL_MAILBOX_REGISTERS_LENGTH /8 ]; }; -struct cel_log { -uint16_t opcode; -uint16_t effect; - } cel_log[1 <<16 ]; -size_t cel_size; };struct {@@ -196,10 +217,12 @@ typedef struct cxl_device_state { } CXLDeviceState;/* Initialize the register block for a device */ -void cxl_device_register_block_init (Object *obj,CXLDeviceState *dev); +void cxl_device_register_block_init (Object *obj,CXLDeviceState *dev, +CXLCCI *cci); +typedef struct CXLType3Dev CXLType3Dev ;/* Set up default values for the register block */ -void cxl_device_register_init_common (CXLDeviceState *dev); +void cxl_device_register_init_t3 (CXLType3Dev *ct3d);/* * CXL 2.0 - 8.2.8.1 including errata F4 @@ -245,8 +268,9 @@ CXL_DEVICE_CAPABILITY_HEADER_REGISTER(MEMORY_DEVICE, CXL_DEVICE_CAP_HDR1_OFFSET + CXL_DEVICE_CAP_REG_SIZE * 2) -void cxl_initialize_mailbox (CXLDeviceState *cxl_dstate); -void cxl_process_mailbox (CXLDeviceState *cxl_dstate); +void cxl_initialize_mailbox_t3 (CXLCCI *cci,DeviceState *d,size_t payload_max); +void cxl_init_cci (CXLCCI *cci,size_t payload_max); +void cxl_process_mailbox (CXLCCI *cci);#define cxl_device_cap_init (dstate, reg, cap_id, ver) \ do { \@@ -347,6 +371,7 @@ struct CXLType3Dev {AddressSpace hostpmem_as;CXLComponentState cxl_cstate;CXLDeviceState cxl_dstate; +CXLCCI cci;/* Primary PCI mailbox CCI */ /* DOE */ DOECap doe_cdat;hw/cxl/cxl-device-utils.c +24
-7@@ -62,7 +62,14 @@ static uint64_t dev_reg_read(void *opaque, hwaddr offset, unsigned size)static uint64_t mailbox_reg_read (void *opaque,hwaddr offset,unsigned size) { -CXLDeviceState *cxl_dstate = opaque; +CXLDeviceState *cxl_dstate; +CXLCCI *cci = opaque; + +if (object_dynamic_cast (OBJECT (cci->intf),TYPE_CXL_TYPE3 )) { + cxl_dstate = &CXL_TYPE3 (cci->intf)->cxl_dstate; + }else { +return 0 ; + }switch (size) {case 1 :@@ -123,7 +130,14 @@ static void mailbox_mem_writeq(uint64_t *reg_state, hwaddr offset,static void mailbox_reg_write (void *opaque,hwaddr offset,uint64_t value,unsigned size) { -CXLDeviceState *cxl_dstate = opaque; +CXLDeviceState *cxl_dstate; +CXLCCI *cci = opaque; + +if (object_dynamic_cast (OBJECT (cci->intf),TYPE_CXL_TYPE3 )) { + cxl_dstate = &CXL_TYPE3 (cci->intf)->cxl_dstate; + }else { +return ; + }if (offset >=A_CXL_DEV_CMD_PAYLOAD ) {memcpy (cxl_dstate->mbox_reg_state + offset, &value, size);@@ -143,7 +157,7 @@ static void mailbox_reg_write(void *opaque, hwaddr offset, uint64_t value,if (ARRAY_FIELD_EX32 (cxl_dstate->mbox_reg_state32,CXL_DEV_MAILBOX_CTRL ,DOORBELL )) { -cxl_process_mailbox (cxl_dstate); +cxl_process_mailbox (cci); } }@@ -223,7 +237,8 @@ static const MemoryRegionOps caps_ops = { }, }; -void cxl_device_register_block_init (Object *obj,CXLDeviceState *cxl_dstate) +void cxl_device_register_block_init (Object *obj,CXLDeviceState *cxl_dstate, +CXLCCI *cci) {/* This will be a BAR, so needs to be rounded up to pow2 for PCI spec */ memory_region_init(&cxl_dstate->device_registers, obj, "device-registers",@@ -233,7 +248,7 @@ void cxl_device_register_block_init(Object *obj, CXLDeviceState *cxl_dstate) "cap-array", CXL_CAPS_SIZE);memory_region_init_io (&cxl_dstate->device, obj, &dev_ops, cxl_dstate,"device-status" ,CXL_DEVICE_STATUS_REGISTERS_LENGTH ); -memory_region_init_io (&cxl_dstate->mailbox, obj, &mailbox_ops, cxl_dstate, +memory_region_init_io (&cxl_dstate->mailbox, obj, &mailbox_ops, cci,"mailbox" ,CXL_MAILBOX_REGISTERS_LENGTH ); memory_region_init_io(&cxl_dstate->memory_device, obj, &mdev_ops, cxl_dstate, "memory device caps",@@ -284,8 +299,9 @@ static void mailbox_reg_init_common(CXLDeviceState *cxl_dstate)static void memdev_reg_init_common (CXLDeviceState *cxl_dstate) { } -void cxl_device_register_init_common (CXLDeviceState *cxl_dstate) +void cxl_device_register_init_t3 (CXLType3Dev *ct3d) { +CXLDeviceState *cxl_dstate = &ct3d->cxl_dstate;uint64_t *cap_h = cxl_dstate->caps_reg_state64;const int cap_count =3 ;@@ -303,7 +319,8 @@ void cxl_device_register_init_common(CXLDeviceState *cxl_dstate)cxl_device_cap_init (cxl_dstate,MEMORY_DEVICE ,0x4000 ,1 );memdev_reg_init_common (cxl_dstate); -cxl_initialize_mailbox (cxl_dstate); +cxl_initialize_mailbox_t3 (&ct3d->cci,DEVICE (ct3d), +CXL_MAILBOX_MAX_PAYLOAD_SIZE ); }uint64_t cxl_device_get_timestamp (CXLDeviceState *cxl_dstate)hw/cxl/cxl-mailbox-utils.c +57
-37@@ -73,8 +73,9 @@ enum {static CXLRetCode cmd_events_get_records (const struct cxl_cmd *cmd,uint8_t *payload_in,size_t len_in,uint8_t *payload_out,size_t *len_out, -CXLDeviceState *cxlds) +CXLCCI *cci) { +CXLDeviceState *cxlds = &CXL_TYPE3 (cci->d)->cxl_dstate;CXLGetEventPayload *pl;uint8_t log_type;int max_recs;@@ -102,8 +103,9 @@ static CXLRetCode cmd_events_clear_records(const struct cxl_cmd *cmd,size_t len_in, uint8_t *payload_out, size_t *len_out, - CXLDeviceState *cxlds) + CXLCCI *cci) { + CXLDeviceState *cxlds = &CXL_TYPE3(cci->d)->cxl_dstate;CXLClearEventPayload *pl; pl = (CXLClearEventPayload *)payload_in;@@ -116,8 +118,9 @@ static CXLRetCode cmd_events_get_interrupt_policy(const struct cxl_cmd *cmd,size_t len_in, uint8_t *payload_out, size_t *len_out, - CXLDeviceState *cxlds) + CXLCCI *cci) { + CXLDeviceState *cxlds = &CXL_TYPE3(cci->d)->cxl_dstate;CXLEventInterruptPolicy *policy;CXLEventLog *log;@@ -159,8 +162,9 @@ static CXLRetCode cmd_events_set_interrupt_policy(const struct cxl_cmd *cmd,size_t len_in, uint8_t *payload_out, size_t *len_out, - CXLDeviceState *cxlds) + CXLCCI *cci) { + CXLDeviceState *cxlds = &CXL_TYPE3(cci->d)->cxl_dstate;CXLEventInterruptPolicy *policy;CXLEventLog *log;@@ -205,8 +209,9 @@ static CXLRetCode cmd_firmware_update_get_info(const struct cxl_cmd *cmd,size_t len, uint8_t *payload_out, size_t *len_out, - CXLDeviceState *cxl_dstate) + CXLCCI *cci) { + CXLDeviceState *cxl_dstate = &CXL_TYPE3(cci->d)->cxl_dstate; struct { uint8_t slots_supported; uint8_t slot_info;@@ -242,8 +247,9 @@ static CXLRetCode cmd_timestamp_get(const struct cxl_cmd *cmd,size_t len_in, uint8_t *payload_out, size_t *len_out, - CXLDeviceState *cxl_dstate) + CXLCCI *cci) { + CXLDeviceState *cxl_dstate = &CXL_TYPE3(cci->d)->cxl_dstate;uint64_t final_time =cxl_device_get_timestamp (cxl_dstate);stq_le_p (payload_out, final_time);@@ -258,8 +264,10 @@ static CXLRetCode cmd_timestamp_set(const struct cxl_cmd *cmd,size_t len_in, uint8_t *payload_out, size_t *len_out, - CXLDeviceState *cxl_dstate) + CXLCCI *cci) { + CXLDeviceState *cxl_dstate = &CXL_TYPE3(cci->d)->cxl_dstate; + cxl_dstate->timestamp.set = true; cxl_dstate->timestamp.last_set =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );@@ -281,7 +289,7 @@ static CXLRetCode cmd_logs_get_supported(const struct cxl_cmd *cmd,size_t len_in, uint8_t *payload_out, size_t *len_out, - CXLDeviceState *cxl_dstate) + CXLCCI *cci) { struct { uint16_t entries;@@ -295,7 +303,7 @@ static CXLRetCode cmd_logs_get_supported(const struct cxl_cmd *cmd, supported_logs->entries =1 ; supported_logs->log_entries[0 ].uuid = cel_uuid; - supported_logs->log_entries[0 ].size =4 * cxl_dstate->cel_size; + supported_logs->log_entries[0 ].size =4 * cci->cel_size; *len_out =sizeof (*supported_logs);return CXL_MBOX_SUCCESS ;@@ -307,7 +315,7 @@ static CXLRetCode cmd_logs_get_log(const struct cxl_cmd *cmd,size_t len_in, uint8_t *payload_out, size_t *len_out, - CXLDeviceState *cxl_dstate) + CXLCCI *cci) { struct { QemuUUID uuid;@@ -330,7 +338,7 @@ static CXLRetCode cmd_logs_get_log(const struct cxl_cmd *cmd,* the only possible failure would be if the mailbox itself isn't big * enough. */ -if (get_log->offset + get_log->length > cxl_dstate->payload_size) { +if (get_log->offset + get_log->length > cci->payload_max) {return CXL_MBOX_INVALID_INPUT ; }@@ -341,8 +349,7 @@ static CXLRetCode cmd_logs_get_log(const struct cxl_cmd *cmd,/* Store off everything to local variables so we can wipe out the payload */ *len_out = get_log->length; -memmove (payload_out, cxl_dstate->cel_log + get_log->offset, - get_log->length); +memmove (payload_out, cci->cel_log + get_log->offset, get_log->length);return CXL_MBOX_SUCCESS ; }@@ -353,7 +360,7 @@ static CXLRetCode cmd_identify_memory_device(const struct cxl_cmd *cmd,size_t len_in, uint8_t *payload_out, size_t *len_out, - CXLDeviceState *cxl_dstate) + CXLCCI *cci) { struct { char fw_revision[0x10];@@ -372,9 +379,9 @@ static CXLRetCode cmd_identify_memory_device(const struct cxl_cmd *cmd,uint8_t qos_telemetry_caps; }QEMU_PACKED *id;QEMU_BUILD_BUG_ON (sizeof (*id) !=0x43 ); - -CXLType3Dev *ct3d =container_of (cxl_dstate, CXLType3Dev, cxl_dstate); +CXLType3Dev *ct3d =CXL_TYPE3 (cci->d);CXLType3Class *cvc =CXL_TYPE3_GET_CLASS (ct3d); +CXLDeviceState *cxl_dstate = &ct3d->cxl_dstate;if ((!QEMU_IS_ALIGNED (cxl_dstate->vmem_size,CXL_CAPACITY_MULTIPLIER )) || (!QEMU_IS_ALIGNED (cxl_dstate->pmem_size,CXL_CAPACITY_MULTIPLIER ))) {@@ -407,8 +414,9 @@ static CXLRetCode cmd_ccls_get_partition_info(const struct cxl_cmd *cmd,size_t len_in, uint8_t *payload_out, size_t *len_out, - CXLDeviceState *cxl_dstate) + CXLCCI *cci) { + CXLDeviceState *cxl_dstate = &CXL_TYPE3(cci->d)->cxl_dstate; struct { uint64_t active_vmem; uint64_t active_pmem;@@ -442,13 +450,13 @@ static CXLRetCode cmd_ccls_get_lsa(const struct cxl_cmd *cmd,size_t len_in, uint8_t *payload_out, size_t *len_out, - CXLDeviceState *cxl_dstate) + CXLCCI *cci) { struct { uint32_t offset;uint32_t length; }QEMU_PACKED *get_lsa; -CXLType3Dev *ct3d =container_of (cxl_dstate, CXLType3Dev, cxl_dstate); +CXLType3Dev *ct3d =CXL_TYPE3 (cci->d);CXLType3Class *cvc =CXL_TYPE3_GET_CLASS (ct3d);uint32_t offset, length;@@ -470,7 +478,7 @@ static CXLRetCode cmd_ccls_set_lsa(const struct cxl_cmd *cmd,size_t len_in, uint8_t *payload_out, size_t *len_out, - CXLDeviceState *cxl_dstate) + CXLCCI *cci) { struct set_lsa_pl { uint32_t offset;@@ -478,7 +486,7 @@ static CXLRetCode cmd_ccls_set_lsa(const struct cxl_cmd *cmd,uint8_t data[]; }QEMU_PACKED ;struct set_lsa_pl *set_lsa_payload = (void *)payload_in; -CXLType3Dev *ct3d =container_of (cxl_dstate, CXLType3Dev, cxl_dstate); +CXLType3Dev *ct3d =CXL_TYPE3 (cci->d);CXLType3Class *cvc =CXL_TYPE3_GET_CLASS (ct3d);const size_t hdr_len = offsetof(struct set_lsa_pl , data);@@ -507,7 +515,7 @@ static CXLRetCode cmd_media_get_poison_list(const struct cxl_cmd *cmd,size_t len_in, uint8_t *payload_out, size_t *len_out, - CXLDeviceState *cxl_dstate) + CXLCCI *cci) { struct get_poison_list_pl { uint64_t pa;@@ -529,7 +537,7 @@ static CXLRetCode cmd_media_get_poison_list(const struct cxl_cmd *cmd,struct get_poison_list_pl *in = (void *)payload_in;struct get_poison_list_out_pl *out = (void *)payload_out; -CXLType3Dev *ct3d =container_of (cxl_dstate, CXLType3Dev, cxl_dstate); +CXLType3Dev *ct3d =CXL_TYPE3 (cci->d);uint16_t record_count =0 , i =0 ;uint64_t query_start, query_length;CXLPoisonList *poison_list = &ct3d->poison_list;@@ -586,9 +594,9 @@ static CXLRetCode cmd_media_inject_poison(const struct cxl_cmd *cmd,size_t len_in, uint8_t *payload_out, size_t *len_out, - CXLDeviceState *cxl_dstate) + CXLCCI *cci) { - CXLType3Dev *ct3d = container_of(cxl_dstate, CXLType3Dev, cxl_dstate); + CXLType3Dev *ct3d = CXL_TYPE3(cci->d);CXLPoisonList *poison_list = &ct3d->poison_list;CXLPoison *ent; struct inject_poison_pl {@@ -629,9 +637,10 @@ static CXLRetCode cmd_media_clear_poison(const struct cxl_cmd *cmd,size_t len_in, uint8_t *payload_out, size_t *len_out, - CXLDeviceState *cxl_dstate) + CXLCCI *cci) { - CXLType3Dev *ct3d = container_of(cxl_dstate, CXLType3Dev, cxl_dstate); + CXLType3Dev *ct3d = CXL_TYPE3(cci->d); +CXLDeviceState *cxl_dstate = &ct3d->cxl_dstate;CXLPoisonList *poison_list = &ct3d->poison_list;CXLType3Class *cvc =CXL_TYPE3_GET_CLASS (ct3d); struct clear_poison_pl {@@ -745,12 +754,13 @@ static const struct cxl_cmd cxl_cmd_set[256][256] = { cmd_media_clear_poison, 72, 0 }, }; -void cxl_process_mailbox (CXLDeviceState *cxl_dstate) +void cxl_process_mailbox (CXLCCI *cci) {uint16_t ret =CXL_MBOX_SUCCESS ;const struct cxl_cmd *cxl_cmd;uint64_t status_reg =0 ;opcode_handler h; +CXLDeviceState *cxl_dstate = &CXL_TYPE3 (cci->d)->cxl_dstate;uint64_t command_reg = cxl_dstate->mbox_reg_state64[R_CXL_DEV_MAILBOX_CMD ];uint8_t set =FIELD_EX64 (command_reg,CXL_DEV_MAILBOX_CMD ,COMMAND_SET );@@ -759,12 +769,12 @@ void cxl_process_mailbox(CXLDeviceState *cxl_dstate)uint8_t *pl = cxl_dstate->mbox_reg_state +A_CXL_DEV_CMD_PAYLOAD ;size_t len_out =0 ; - cxl_cmd = &cxl_dstate->cxl_cmd_set[set][cmd]; + cxl_cmd = &cci->cxl_cmd_set[set][cmd]; h = cxl_cmd->handler;if (h) {if (len_in == cxl_cmd->in || cxl_cmd->in == ~0 ) { - ret = (*h)(cxl_cmd, pl, len_in, pl, &len_out, cxl_dstate); -assert (len_out <= cxl_dstate->payload_size); + ret = (*h)(cxl_cmd, pl, len_in, pl, &len_out, cci); +assert (len_out <= cci->payload_max); }else { ret =CXL_MBOX_INVALID_PAYLOAD_LENGTH ; }@@ -790,20 +800,30 @@ void cxl_process_mailbox(CXLDeviceState *cxl_dstate) DOORBELL, 0); } -void cxl_initialize_mailbox (CXLDeviceState *cxl_dstate) +void cxl_init_cci (CXLCCI *cci,size_t payload_max) { - cxl_dstate->cxl_cmd_set = cxl_cmd_set; + cci->payload_max = payload_max;for (int set =0 ; set <256 ; set++) {for (int cmd =0 ; cmd <256 ; cmd++) { -if (cxl_dstate->cxl_cmd_set[set][cmd].handler) { -const struct cxl_cmd *c = &cxl_dstate->cxl_cmd_set[set][cmd]; +if (cci->cxl_cmd_set[set][cmd].handler) { +const struct cxl_cmd *c = &cci->cxl_cmd_set[set][cmd];struct cel_log *log = - &cxl_dstate->cel_log[cxl_dstate->cel_size]; + &cci->cel_log[cci->cel_size]; log->opcode = (set <<8 ) | cmd; log->effect = c->effect; - cxl_dstate->cel_size++; + cci->cel_size++; } } } } + +void cxl_initialize_mailbox_t3 (CXLCCI *cci,DeviceState *d,size_t payload_max) +{ + cci->cxl_cmd_set = cxl_cmd_set; + cci->d = d; + +/* No separation for PCI MB as protocol handled in PCI device */ + cci->intf = d; +cxl_init_cci (cci, payload_max); +}hw/mem/cxl_type3.c +3
-3@@ -716,7 +716,8 @@ static void ct3_realize(PCIDevice *pci_dev, Error **errp) pci_dev,CXL_COMPONENT_REG_BAR_IDX , PCI_BASE_ADDRESS_SPACE_MEMORY | PCI_BASE_ADDRESS_MEM_TYPE_64, mr); -cxl_device_register_block_init (OBJECT (pci_dev), &ct3d->cxl_dstate); +cxl_device_register_block_init (OBJECT (pci_dev), &ct3d->cxl_dstate, + &ct3d->cci); pci_register_bar(pci_dev, CXL_DEVICE_REG_BAR_IDX, PCI_BASE_ADDRESS_SPACE_MEMORY | PCI_BASE_ADDRESS_MEM_TYPE_64,@@ -922,7 +923,7 @@ static void ct3d_reset(DeviceState *dev)uint32_t *write_msk = ct3d->cxl_cstate.crb.cache_mem_regs_write_mask;cxl_component_register_init_common (reg_state, write_msk,CXL2_TYPE3_DEVICE ); -cxl_device_register_init_common (&ct3d->cxl_dstate); +cxl_device_register_init_t3 (ct3d); }static Property ct3_props[] = { --2.39.2
Re: [PATCH 03/19] hw/cxl/mbox: Pull the CCI definition out of the CXLDeviceState
In reply to Jonathan CameronQuoted 5 lines · On Mon, 25 Sep 2023 17:11:08 +0100 Jonathan Cameron…
Enables having multiple CCIs per devices. Each CCI (mailbox) has it's own state and command list, so they can't share a single structure.
Signed-off-by Jonathan Cameron <[email protected]>---
I made a mess of reordering patches, so some of Davidlohr's BG ops patch ended up in this one and the next patch. I'll put that back where it should be in v2.
Quoted 9 lines
include/hw/cxl/cxl_device.h +8
-0+typedef struct CXLCCI { + const struct cxl_cmd (*cxl_cmd_set)[256]; + struct cel_log { + uint16_t opcode; + uint16_t effect; + } cel_log[1 << 16]; + size_t cel_size; +
include/hw/cxl/cxl_device.h typedef struct CXLEventLog { · line 161
Quoted 10 lines
include/hw/cxl/cxl_device.h +10
-0+/* background command handling (times in ms) */ +struct { +uint16_t opcode; +uint16_t complete_pct; +uint16_t ret_code;/* Current value of retcode */ +uint64_t starttime; +/* set by each bg cmd, cleared by the bg_timer when complete */ +uint64_t runtime; +QEMUTimer *timer; + } bg;
We don't have bg ops yet!
Quoted 7 lines
include/hw/cxl/cxl_device.h +7
-0+size_t payload_max; +/* Pointer to device hosting the CCI */ +DeviceState *d; +/* Pointer to the device hosting the protocol conversion */ +DeviceState *intf; +}CXLCCI ; +
PATCH 4/19 hw/cxl/mbox: Generalize the CCI command processing
In reply to Jonathan CameronBy moving the parts of the mailbox command handling that are CCI type specific out to the caller, make the main handling code generic. Rename it to cxl_process_cci_message() to reflect this new generality.
--- include/hw/cxl/cxl_device.h | 5 +++- hw/cxl/cxl-device-utils.c | 51 ++++++++++++++++++++++++++++++++++++- hw/cxl/cxl-mailbox-utils.c | 43 ++++++++----------------------- 3 files changed, 64 insertions(+), 35 deletions(-)
include/hw/cxl/cxl_device.h +4 -1
@@ -270,7 +270,10 @@ CXL_DEVICE_CAPABILITY_HEADER_REGISTER(MEMORY_DEVICE,void cxl_initialize_mailbox_t3 (CXLCCI *cci,DeviceState *d,size_t payload_max);void cxl_init_cci (CXLCCI *cci,size_t payload_max); -void cxl_process_mailbox (CXLCCI *cci); +int cxl_process_cci_message (CXLCCI *cci,uint8_t set,uint8_t cmd, +size_t len_in,uint8_t *pl_in, +size_t *len_out,uint8_t *pl_out, +bool *bg_started);#define cxl_device_cap_init (dstate, reg, cap_id, ver) \ do { \
hw/cxl/cxl-device-utils.c +50 -1
63 lines not on this page · raw message
hw/cxl/cxl-mailbox-utils.c +10 -33
60 lines not on this page · raw message
Signature · 1 line
2.39.2
Re: [PATCH 04/19] hw/cxl/mbox: Generalize the CCI command processing
Quoted 6 lines · Jonathan Cameron
By moving the parts of the mailbox command handling that are CCI type specific out to the caller, make the main handling code generic. Rename it to
cxl_process_cci_message()to reflect this new generality.Signed-off-by Jonathan Cameron <[email protected]>---
Quoted 158 lines
include/hw/cxl/cxl_device.h | 5 +++- hw/cxl/cxl-device-utils.c | 51 ++++++++++++++++++++++++++++++++++++- hw/cxl/cxl-mailbox-utils.c | 43 ++++++++----------------------- 3 files changed, 64 insertions(+), 35 deletions(-)include/hw/cxl/cxl_device.h +4
-1@@ -270,7 +270,10 @@ CXL_DEVICE_CAPABILITY_HEADER_REGISTER(MEMORY_DEVICE,void cxl_initialize_mailbox_t3 (CXLCCI *cci,DeviceState *d,size_t payload_max);void cxl_init_cci (CXLCCI *cci,size_t payload_max); -void cxl_process_mailbox (CXLCCI *cci); +int cxl_process_cci_message (CXLCCI *cci,uint8_t set,uint8_t cmd, +size_t len_in,uint8_t *pl_in, +size_t *len_out,uint8_t *pl_out, +bool *bg_started);#define cxl_device_cap_init (dstate, reg, cap_id, ver) \ do { \hw/cxl/cxl-device-utils.c +50
-1@@ -79,6 +79,25 @@ static uint64_t mailbox_reg_read(void *opaque, hwaddr offset, unsigned size)case 4 :return cxl_dstate->mbox_reg_state32[offset / size];case 8 : +if (offset ==A_CXL_DEV_BG_CMD_STS ) { +uint64_t bg_status_reg; + bg_status_reg =FIELD_DP64 (0 ,CXL_DEV_BG_CMD_STS ,OP , + cci->bg.opcode); + bg_status_reg =FIELD_DP64 (bg_status_reg,CXL_DEV_BG_CMD_STS , +PERCENTAGE_COMP , cci->bg.complete_pct); + bg_status_reg =FIELD_DP64 (bg_status_reg,CXL_DEV_BG_CMD_STS , +RET_CODE , cci->bg.ret_code); +/* endian? */ + cxl_dstate->mbox_reg_state64[offset / size] = bg_status_reg; + } +if (offset ==A_CXL_DEV_MAILBOX_STS ) { +uint64_t status_reg = cxl_dstate->mbox_reg_state64[offset / size]; +if (cci->bg.complete_pct) { + status_reg =FIELD_DP64 (status_reg,CXL_DEV_MAILBOX_STS ,BG_OP , +0 ); + cxl_dstate->mbox_reg_state64[offset / size] = status_reg; + } + }return cxl_dstate->mbox_reg_state64[offset / size];default :g_assert_not_reached ();@@ -157,7 +176,37 @@ static void mailbox_reg_write(void *opaque, hwaddr offset, uint64_t value,if (ARRAY_FIELD_EX32 (cxl_dstate->mbox_reg_state32,CXL_DEV_MAILBOX_CTRL ,DOORBELL )) { -cxl_process_mailbox (cci); +uint64_t command_reg = + cxl_dstate->mbox_reg_state64[R_CXL_DEV_MAILBOX_CMD ]; +uint8_t cmd_set =FIELD_EX64 (command_reg,CXL_DEV_MAILBOX_CMD , +COMMAND_SET ); +uint8_t cmd =FIELD_EX64 (command_reg,CXL_DEV_MAILBOX_CMD ,COMMAND ); +size_t len_in =FIELD_EX64 (command_reg,CXL_DEV_MAILBOX_CMD ,LENGTH ); +uint8_t *pl = cxl_dstate->mbox_reg_state +A_CXL_DEV_CMD_PAYLOAD ; +size_t len_out; +uint64_t status_reg; +bool bg_started; +int rc; + + rc =cxl_process_cci_message (cci, cmd_set, cmd, len_in, pl, + &len_out, pl, &bg_started); + +/* Set bg and the return code */ + status_reg =FIELD_DP64 (0 ,CXL_DEV_MAILBOX_STS ,BG_OP , + bg_started ?1 :0 ); + status_reg =FIELD_DP64 (status_reg,CXL_DEV_MAILBOX_STS ,ERRNO , rc); +/* Set the return length */ + command_reg =FIELD_DP64 (0 ,CXL_DEV_MAILBOX_CMD ,COMMAND_SET , cmd_set); + command_reg =FIELD_DP64 (command_reg,CXL_DEV_MAILBOX_CMD , +COMMAND , cmd); + command_reg =FIELD_DP64 (command_reg,CXL_DEV_MAILBOX_CMD , +LENGTH , len_out); + + cxl_dstate->mbox_reg_state64[R_CXL_DEV_MAILBOX_CMD ] = command_reg; + cxl_dstate->mbox_reg_state64[R_CXL_DEV_MAILBOX_STS ] = status_reg; +/* Tell the host we're done */ +ARRAY_FIELD_DP32 (cxl_dstate->mbox_reg_state32,CXL_DEV_MAILBOX_CTRL , +DOORBELL ,0 ); } }hw/cxl/cxl-mailbox-utils.c +10
-34@@ -754,50 +754,27 @@ static const struct cxl_cmd cxl_cmd_set[256][256] = { cmd_media_clear_poison, 72, 0 }, }; -void cxl_process_mailbox (CXLCCI *cci) +int cxl_process_cci_message (CXLCCI *cci,uint8_t set,uint8_t cmd, +size_t len_in,uint8_t *pl_in,size_t *len_out, +uint8_t *pl_out,bool *bg_started) { -uint16_t ret =CXL_MBOX_SUCCESS ;const struct cxl_cmd *cxl_cmd; -uint64_t status_reg =0 ;opcode_handler h; -CXLDeviceState *cxl_dstate = &CXL_TYPE3 (cci->d)->cxl_dstate; -uint64_t command_reg = cxl_dstate->mbox_reg_state64[R_CXL_DEV_MAILBOX_CMD ]; - -uint8_t set =FIELD_EX64 (command_reg,CXL_DEV_MAILBOX_CMD ,COMMAND_SET ); -uint8_t cmd =FIELD_EX64 (command_reg,CXL_DEV_MAILBOX_CMD ,COMMAND ); -uint16_t len_in =FIELD_EX64 (command_reg,CXL_DEV_MAILBOX_CMD ,LENGTH ); -uint8_t *pl = cxl_dstate->mbox_reg_state +A_CXL_DEV_CMD_PAYLOAD ; -size_t len_out =0 ; + *len_out =0 ; cxl_cmd = &cci->cxl_cmd_set[set][cmd]; h = cxl_cmd->handler; -if (h) { -if (len_in == cxl_cmd->in || cxl_cmd->in == ~0 ) { - ret = (*h)(cxl_cmd, pl, len_in, pl, &len_out, cci); -assert (len_out <= cci->payload_max); - }else { - ret =CXL_MBOX_INVALID_PAYLOAD_LENGTH ; - } - }else { +if (!h) {qemu_log_mask (LOG_UNIMP ,"Command %04xh not implemented\n" , set <<8 | cmd); - ret =CXL_MBOX_UNSUPPORTED ; +return CXL_MBOX_UNSUPPORTED ; } -/* Set the return code */ - status_reg =FIELD_DP64 (0 ,CXL_DEV_MAILBOX_STS ,ERRNO , ret); - -/* Set the return length */ - command_reg =FIELD_DP64 (command_reg,CXL_DEV_MAILBOX_CMD ,COMMAND_SET ,0 ); - command_reg =FIELD_DP64 (command_reg,CXL_DEV_MAILBOX_CMD ,COMMAND ,0 ); - command_reg =FIELD_DP64 (command_reg,CXL_DEV_MAILBOX_CMD ,LENGTH , len_out); - - cxl_dstate->mbox_reg_state64[R_CXL_DEV_MAILBOX_CMD ] = command_reg; - cxl_dstate->mbox_reg_state64[R_CXL_DEV_MAILBOX_STS ] = status_reg; +if (len_in != cxl_cmd->in && cxl_cmd->in != ~0 ) { +return CXL_MBOX_INVALID_PAYLOAD_LENGTH ; + } -/* Tell the host we're done */ -ARRAY_FIELD_DP32 (cxl_dstate->mbox_reg_state32,CXL_DEV_MAILBOX_CTRL , -DOORBELL ,0 ); +return (*h)(cxl_cmd, pl_in, len_in, pl_out, len_out, cci); }void cxl_init_cci (CXLCCI *cci,size_t payload_max) --2.39.2
Re: [PATCH 04/19] hw/cxl/mbox: Generalize the CCI command processing
Quoted 9 lines · On Thu, 28 Sep 2023 11:21:31 -0700 Fan Ni <[email protected]> wrote:
Quoted 6 lines · Jonathan Cameron
By moving the parts of the mailbox command handling that are CCI type specific out to the caller, make the main handling code generic. Rename it to
cxl_process_cci_message()to reflect this new generality.Signed-off-by Jonathan Cameron <[email protected]>---
Reviewed-by Fan Ni <[email protected]>
Thanks!
Unfortunately I've changed how this works for v2.
The aliasing of the mailbox buffer into both the input and output payload lead to an annoying bug when I was implementing Get Physical Port State via a tunnel from the Switch CCI. Having wasted too much time (as I'd forgotten this aliased) I've changed this code to take a snapshot of the input data instead. Cleanup is simplified using a g_autofree().
I should be ready to post a new version early next week with this in place.
Generally I've expanded my testing and the supported commands etc so hit a bunch of cases where the many many length values in nested tunneling (there are 5+ IIRC) either didn't correspond to each other or weren't being read.
I'm not sure a uf real implementation is obliged to check the stuff that is redundant information, but we probably want QEMU to do so.
Jonathan
Quoted 159 lines
Quoted 159 lines
include/hw/cxl/cxl_device.h | 5 +++- hw/cxl/cxl-device-utils.c | 51 ++++++++++++++++++++++++++++++++++++- hw/cxl/cxl-mailbox-utils.c | 43 ++++++++----------------------- 3 files changed, 64 insertions(+), 35 deletions(-)include/hw/cxl/cxl_device.h +4
-1@@ -270,7 +270,10 @@ CXL_DEVICE_CAPABILITY_HEADER_REGISTER(MEMORY_DEVICE,void cxl_initialize_mailbox_t3 (CXLCCI *cci,DeviceState *d,size_t payload_max);void cxl_init_cci (CXLCCI *cci,size_t payload_max); -void cxl_process_mailbox (CXLCCI *cci); +int cxl_process_cci_message (CXLCCI *cci,uint8_t set,uint8_t cmd, +size_t len_in,uint8_t *pl_in, +size_t *len_out,uint8_t *pl_out, +bool *bg_started);#define cxl_device_cap_init (dstate, reg, cap_id, ver) \ do { \hw/cxl/cxl-device-utils.c +50
-1@@ -79,6 +79,25 @@ static uint64_t mailbox_reg_read(void *opaque, hwaddr offset, unsigned size)case 4 :return cxl_dstate->mbox_reg_state32[offset / size];case 8 : +if (offset ==A_CXL_DEV_BG_CMD_STS ) { +uint64_t bg_status_reg; + bg_status_reg =FIELD_DP64 (0 ,CXL_DEV_BG_CMD_STS ,OP , + cci->bg.opcode); + bg_status_reg =FIELD_DP64 (bg_status_reg,CXL_DEV_BG_CMD_STS , +PERCENTAGE_COMP , cci->bg.complete_pct); + bg_status_reg =FIELD_DP64 (bg_status_reg,CXL_DEV_BG_CMD_STS , +RET_CODE , cci->bg.ret_code); +/* endian? */ + cxl_dstate->mbox_reg_state64[offset / size] = bg_status_reg; + } +if (offset ==A_CXL_DEV_MAILBOX_STS ) { +uint64_t status_reg = cxl_dstate->mbox_reg_state64[offset / size]; +if (cci->bg.complete_pct) { + status_reg =FIELD_DP64 (status_reg,CXL_DEV_MAILBOX_STS ,BG_OP , +0 ); + cxl_dstate->mbox_reg_state64[offset / size] = status_reg; + } + }return cxl_dstate->mbox_reg_state64[offset / size];default :g_assert_not_reached ();@@ -157,7 +176,37 @@ static void mailbox_reg_write(void *opaque, hwaddr offset, uint64_t value,if (ARRAY_FIELD_EX32 (cxl_dstate->mbox_reg_state32,CXL_DEV_MAILBOX_CTRL ,DOORBELL )) { -cxl_process_mailbox (cci); +uint64_t command_reg = + cxl_dstate->mbox_reg_state64[R_CXL_DEV_MAILBOX_CMD ]; +uint8_t cmd_set =FIELD_EX64 (command_reg,CXL_DEV_MAILBOX_CMD , +COMMAND_SET ); +uint8_t cmd =FIELD_EX64 (command_reg,CXL_DEV_MAILBOX_CMD ,COMMAND ); +size_t len_in =FIELD_EX64 (command_reg,CXL_DEV_MAILBOX_CMD ,LENGTH ); +uint8_t *pl = cxl_dstate->mbox_reg_state +A_CXL_DEV_CMD_PAYLOAD ; +size_t len_out; +uint64_t status_reg; +bool bg_started; +int rc; + + rc =cxl_process_cci_message (cci, cmd_set, cmd, len_in, pl, + &len_out, pl, &bg_started); + +/* Set bg and the return code */ + status_reg =FIELD_DP64 (0 ,CXL_DEV_MAILBOX_STS ,BG_OP , + bg_started ?1 :0 ); + status_reg =FIELD_DP64 (status_reg,CXL_DEV_MAILBOX_STS ,ERRNO , rc); +/* Set the return length */ + command_reg =FIELD_DP64 (0 ,CXL_DEV_MAILBOX_CMD ,COMMAND_SET , cmd_set); + command_reg =FIELD_DP64 (command_reg,CXL_DEV_MAILBOX_CMD , +COMMAND , cmd); + command_reg =FIELD_DP64 (command_reg,CXL_DEV_MAILBOX_CMD , +LENGTH , len_out); + + cxl_dstate->mbox_reg_state64[R_CXL_DEV_MAILBOX_CMD ] = command_reg; + cxl_dstate->mbox_reg_state64[R_CXL_DEV_MAILBOX_STS ] = status_reg; +/* Tell the host we're done */ +ARRAY_FIELD_DP32 (cxl_dstate->mbox_reg_state32,CXL_DEV_MAILBOX_CTRL , +DOORBELL ,0 ); } }hw/cxl/cxl-mailbox-utils.c +10
-34@@ -754,50 +754,27 @@ static const struct cxl_cmd cxl_cmd_set[256][256] = { cmd_media_clear_poison, 72, 0 }, }; -void cxl_process_mailbox (CXLCCI *cci) +int cxl_process_cci_message (CXLCCI *cci,uint8_t set,uint8_t cmd, +size_t len_in,uint8_t *pl_in,size_t *len_out, +uint8_t *pl_out,bool *bg_started) { -uint16_t ret =CXL_MBOX_SUCCESS ;const struct cxl_cmd *cxl_cmd; -uint64_t status_reg =0 ;opcode_handler h; -CXLDeviceState *cxl_dstate = &CXL_TYPE3 (cci->d)->cxl_dstate; -uint64_t command_reg = cxl_dstate->mbox_reg_state64[R_CXL_DEV_MAILBOX_CMD ]; - -uint8_t set =FIELD_EX64 (command_reg,CXL_DEV_MAILBOX_CMD ,COMMAND_SET ); -uint8_t cmd =FIELD_EX64 (command_reg,CXL_DEV_MAILBOX_CMD ,COMMAND ); -uint16_t len_in =FIELD_EX64 (command_reg,CXL_DEV_MAILBOX_CMD ,LENGTH ); -uint8_t *pl = cxl_dstate->mbox_reg_state +A_CXL_DEV_CMD_PAYLOAD ; -size_t len_out =0 ; + *len_out =0 ; cxl_cmd = &cci->cxl_cmd_set[set][cmd]; h = cxl_cmd->handler; -if (h) { -if (len_in == cxl_cmd->in || cxl_cmd->in == ~0 ) { - ret = (*h)(cxl_cmd, pl, len_in, pl, &len_out, cci); -assert (len_out <= cci->payload_max); - }else { - ret =CXL_MBOX_INVALID_PAYLOAD_LENGTH ; - } - }else { +if (!h) {qemu_log_mask (LOG_UNIMP ,"Command %04xh not implemented\n" , set <<8 | cmd); - ret =CXL_MBOX_UNSUPPORTED ; +return CXL_MBOX_UNSUPPORTED ; } -/* Set the return code */ - status_reg =FIELD_DP64 (0 ,CXL_DEV_MAILBOX_STS ,ERRNO , ret); - -/* Set the return length */ - command_reg =FIELD_DP64 (command_reg,CXL_DEV_MAILBOX_CMD ,COMMAND_SET ,0 ); - command_reg =FIELD_DP64 (command_reg,CXL_DEV_MAILBOX_CMD ,COMMAND ,0 ); - command_reg =FIELD_DP64 (command_reg,CXL_DEV_MAILBOX_CMD ,LENGTH , len_out); - - cxl_dstate->mbox_reg_state64[R_CXL_DEV_MAILBOX_CMD ] = command_reg; - cxl_dstate->mbox_reg_state64[R_CXL_DEV_MAILBOX_STS ] = status_reg; +if (len_in != cxl_cmd->in && cxl_cmd->in != ~0 ) { +return CXL_MBOX_INVALID_PAYLOAD_LENGTH ; + } -/* Tell the host we're done */ -ARRAY_FIELD_DP32 (cxl_dstate->mbox_reg_state32,CXL_DEV_MAILBOX_CTRL , -DOORBELL ,0 ); +return (*h)(cxl_cmd, pl_in, len_in, pl_out, len_out, cci); }void cxl_init_cci (CXLCCI *cci,size_t payload_max) --2.39.2
PATCH 5/19 hw/pci-bridge/cxl_upstream: Move defintion of device to header.
In reply to Jonathan CameronTo avoid repetition of switch upstream port specific data in the CXLDeviceState structure it will be necessary to access the switch USP specific data from mailbox callbacks. Hence move it to cxl_device.h so it is no longer an opaque structure.
--- include/hw/pci-bridge/cxl_upstream_port.h | 18 ++++++++++++++++++ hw/pci-bridge/cxl_upstream.c | 11 +---------- 2 files changed, 19 insertions(+), 10 deletions(-)
include/hw/pci-bridge/cxl_upstream_port.h new file +18 -0
@@ -0,0 +1,18 @@ + +#ifndef CXL_USP_H +#define CXL_USP_H +#include "hw/pci/pcie.h" +#include "hw/pci/pcie_port.h" +#include "hw/cxl/cxl.h" + +typedef struct CXLUpstreamPort { +/*< private >*/ +PCIEPort parent_obj; + +/*< public >*/ +CXLComponentState cxl_cstate; +DOECap doe_cdat; +uint64_t sn; +}CXLUpstreamPort ; + +#endif /* CXL_SUP_H */
hw/pci-bridge/cxl_upstream.c +1 -10
@@ -14,6 +14,7 @@#include "hw/pci/msi.h" #include "hw/pci/pcie.h" #include "hw/pci/pcie_port.h" +#include "hw/pci-bridge/cxl_upstream_port.h" /* * Null value of all Fs suggested by IEEE RA guidelines for use of * EU, OUI and CID
@@ -30,16 +31,6 @@#define CXL_UPSTREAM_PORT_DVSEC_OFFSET \ (CXL_UPSTREAM_PORT_SN_OFFSET + PCI_EXT_CAP_DSN_SIZEOF) -typedef struct CXLUpstreamPort { -/*< private >*/ -PCIEPort parent_obj; - -/*< public >*/ -CXLComponentState cxl_cstate; -DOECap doe_cdat; -uint64_t sn; -}CXLUpstreamPort ; -CXLComponentState *cxl_usp_to_cstate (CXLUpstreamPort *usp) {return &usp->cxl_cstate;
Signature · 1 line
2.39.2
Re: [PATCH 05/19] hw/pci-bridge/cxl_upstream: Move defintion of device to header.
Quoted 7 lines · Jonathan Cameron
To avoid repetition of switch upstream port specific data in the CXLDeviceState structure it will be necessary to access the switch USP specific data from mailbox callbacks. Hence move it to
cxl_device.hso it is no longer an opaque structure.Signed-off-by Jonathan Cameron <[email protected]>---
Quoted 60 lines
include/hw/pci-bridge/cxl_upstream_port.h | 18 ++++++++++++++++++ hw/pci-bridge/cxl_upstream.c | 11 +---------- 2 files changed, 19 insertions(+), 10 deletions(-)include/hw/pci-bridge/cxl_upstream_port.h new file +18
-0@@ -0,0 +1,18 @@ + +#ifndef CXL_USP_H +#define CXL_USP_H +#include "hw/pci/pcie.h" +#include "hw/pci/pcie_port.h" +#include "hw/cxl/cxl.h" + +typedef struct CXLUpstreamPort { +/*< private >*/ +PCIEPort parent_obj; + +/*< public >*/ +CXLComponentState cxl_cstate; +DOECap doe_cdat; +uint64_t sn; +}CXLUpstreamPort ; + +#endif /* CXL_SUP_H */ hw/pci-bridge/cxl_upstream.c +1
-11@@ -14,6 +14,7 @@#include "hw/pci/msi.h" #include "hw/pci/pcie.h" #include "hw/pci/pcie_port.h" +#include "hw/pci-bridge/cxl_upstream_port.h" /* * Null value of all Fs suggested by IEEE RA guidelines for use of * EU, OUI and CID @@ -30,16 +31,6 @@#define CXL_UPSTREAM_PORT_DVSEC_OFFSET \ (CXL_UPSTREAM_PORT_SN_OFFSET + PCI_EXT_CAP_DSN_SIZEOF) -typedef struct CXLUpstreamPort { -/*< private >*/ -PCIEPort parent_obj; - -/*< public >*/ -CXLComponentState cxl_cstate; -DOECap doe_cdat; -uint64_t sn; -}CXLUpstreamPort ; -CXLComponentState *cxl_usp_to_cstate (CXLUpstreamPort *usp) {return &usp->cxl_cstate; --2.39.2
PATCH 6/19 hw/cxl/i2c_mctp_cxl: Initial device emulation
In reply to Jonathan CameronThe CCI and Fabric Manager APIs are used to configure CXL switches and devices. DMTF has defined an MCTP binding specification to carry these messages. The end goal of this work is to hook this up to emulated CXL switches and devices to allow control of the configuration.
Since this relies on i2c target mode, this can currently only be used with an SoC that includes the Aspeed I2C controller.
Note, no commands supported at this point.
---
Updated to use the v6 MCTP patch set.
Can be tested in similar fashion to NVME-mi (or using the out of tree patches to add the aspeed-i2c controller to other i386/pc and arm/virt.
--- include/hw/cxl/cxl_device.h | 5 + include/hw/pci-bridge/cxl_upstream_port.h | 1 + hw/cxl/cxl-mailbox-utils.c | 24 ++ hw/cxl/i2c_mctp_cxl.c | 290 ++++++++++++++++++++++ hw/cxl/Kconfig | 4 + hw/cxl/meson.build | 1 + 6 files changed, 325 insertions(+)
include/hw/cxl/cxl_device.h +5 -0
@@ -274,6 +274,10 @@ int cxl_process_cci_message(CXLCCI *cci, uint8_t set, uint8_t cmd, size_t len_in, uint8_t *pl_in, size_t *len_out, uint8_t *pl_out, bool *bg_started); +void cxl_initialize_t3_mctpcci (CXLCCI *cci,DeviceState *d,DeviceState *intf, +size_t payload_max); +void cxl_initialize_usp_mctpcci (CXLCCI *cci,DeviceState *d,DeviceState *intf, +size_t payload_max);#define cxl_device_cap_init (dstate, reg, cap_id, ver) \ do { \
@@ -375,6 +379,7 @@ struct CXLType3Dev {CXLComponentState cxl_cstate;CXLDeviceState cxl_dstate;CXLCCI cci;/* Primary PCI mailbox CCI */ +CXLCCI oob_mctp_cci;/* Initialized only if targetted */ /* DOE */ DOECap doe_cdat;
include/hw/pci-bridge/cxl_upstream_port.h +1 -0
@@ -11,6 +11,7 @@ typedef struct CXLUpstreamPort {/*< public >*/ CXLComponentState cxl_cstate; +CXLCCI mctpcci;DOECap doe_cdat;uint64_t sn; } CXLUpstreamPort;
hw/cxl/cxl-mailbox-utils.c +24 -0
@@ -804,3 +804,27 @@ void cxl_initialize_mailbox_t3(CXLCCI *cci, DeviceState *d, size_t payload_max) cci->intf = d;cxl_init_cci (cci, payload_max); } + +static const struct cxl_cmd cxl_cmd_set_t3_mctp[256 ][256 ] = { +}; + +void cxl_initialize_t3_mctpcci (CXLCCI *cci,DeviceState *d,DeviceState *intf, +size_t payload_max) +{ + cci->cxl_cmd_set = cxl_cmd_set_t3_mctp; + cci->d = d; + cci->intf = intf; +cxl_init_cci (cci, payload_max); +} + +static const struct cxl_cmd cxl_cmd_set_usp_mctp[256 ][256 ] = { +}; + +void cxl_initialize_usp_mctpcci (CXLCCI *cci,DeviceState *d,DeviceState *intf, +size_t payload_max) +{ + cci->cxl_cmd_set = cxl_cmd_set_usp_mctp; + cci->d = d; + cci->intf = intf; +cxl_init_cci (cci, payload_max); +}
hw/cxl/i2c_mctp_cxl.c new file +290 -0
290 lines not on this page · raw message
hw/cxl/Kconfig +4 -0
@@ -1,3 +1,7 @@ config CXL bool default y if PCI_EXPRESS + +config I2C_MCTP_CXL + bool + default y if CXL && I2C_MCTP
hw/cxl/meson.build +1 -0
@@ -10,5 +10,6 @@ system_ss.add(when: 'CONFIG_CXL', if_false: files( 'cxl-host-stubs.c', )) +system_ss.add(when: 'CONFIG_I2C_MCTP_CXL', if_true: files('i2c_mctp_cxl.c')) system_ss.add(when: 'CONFIG_ALL', if_true: files('cxl-host-stubs.c'))
Signature · 1 line
2.39.2
PATCH 7/19 hw/cxl/mbox: Add Information and Status / Identify command
In reply to Jonathan CameronAdd this command that is only available via out of band CCIs. It replicates information that can be discovered inband via PCI config space.
--- hw/cxl/cxl-mailbox-utils.c | 48 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+)
hw/cxl/cxl-mailbox-utils.c +48 -0
@@ -11,6 +11,7 @@#include "hw/cxl/cxl.h" #include "hw/cxl/cxl_events.h" #include "hw/pci/pci.h" +#include "hw/pci-bridge/cxl_upstream_port.h" #include "qemu/cutils.h" #include "qemu/log.h" #include "qemu/units.h"
@@ -44,6 +45,8 @@*/ enum { +INFOSTAT =0x00 , +#define IS_IDENTIFY 0x1 EVENTS = 0x01,#define GET_RECORDS 0x0 #define CLEAR_RECORDS 0x1
@@ -203,6 +206,49 @@ static CXLRetCode cmd_events_set_interrupt_policy(const struct cxl_cmd *cmd,return CXL_MBOX_SUCCESS ; } +/* CXL r3.0 section 8.2.9.1.1: Identify (Opcode 0001h) */ +static CXLRetCode cmd_infostat_identify (const struct cxl_cmd *cmd, +uint8_t *payload_in, +size_t len_in, +uint8_t *payload_out, +size_t *len_out, +CXLCCI *cci) +{ +PCIDeviceClass *class =PCI_DEVICE_GET_CLASS (cci->d); +struct { +uint16_t pcie_vid; +uint16_t pcie_did; +uint16_t pcie_subsys_vid; +uint16_t pcie_subsys_id; +uint64_t sn; +uint8_t max_message_size; +uint8_t component_type; + } QEMU_PACKED *is_identify; +QEMU_BUILD_BUG_ON (sizeof (*is_identify) !=18 ); + + is_identify = (void *)payload_out; +memset (is_identify,0 ,sizeof (*is_identify)); + is_identify->pcie_vid = class->vendor_id; + is_identify->pcie_did = class->device_id; +if (object_dynamic_cast (OBJECT (cci->d),TYPE_CXL_USP )) { + is_identify->sn =CXL_USP (cci->d)->sn; +/* Subsystem info not defined for a USP */ + is_identify->pcie_subsys_vid =0 ; + is_identify->pcie_subsys_id =0 ; + is_identify->component_type =0x0 ;/* Switch */ + }else if (object_dynamic_cast (OBJECT (cci->d),TYPE_CXL_TYPE3 )) { + is_identify->sn =CXL_TYPE3 (cci->d)->sn; + is_identify->pcie_subsys_vid = class->subsystem_vendor_id; + is_identify->pcie_subsys_id = class->subsystem_id; + is_identify->component_type =0x3 ;/* Type 3 */ + } + +/* TODO: Allow this to vary across different CCIs */ + is_identify->max_message_size =9 ;/* 512 bytes - MCTP_CXL_MAILBOX_BYTES */ + *len_out =sizeof (*is_identify); +return CXL_MBOX_SUCCESS ; +} +/* 8.2.9.2.1 */ static CXLRetCode cmd_firmware_update_get_info(const struct cxl_cmd *cmd, uint8_t *payload_in,
@@ -806,6 +852,7 @@ void cxl_initialize_mailbox_t3(CXLCCI *cci, DeviceState *d, size_t payload_max) }static const struct cxl_cmd cxl_cmd_set_t3_mctp[256 ][256 ] = { + [INFOSTAT ][IS_IDENTIFY ] = {"IDENTIFY" , cmd_infostat_identify,0 ,18 }, }; void cxl_initialize_t3_mctpcci(CXLCCI *cci, DeviceState *d, DeviceState *intf,
@@ -818,6 +865,7 @@ void cxl_initialize_t3_mctpcci(CXLCCI *cci, DeviceState *d, DeviceState *intf, }static const struct cxl_cmd cxl_cmd_set_usp_mctp[256 ][256 ] = { + [INFOSTAT ][IS_IDENTIFY ] = {"IDENTIFY" , cmd_infostat_identify,0 ,18 }, }; void cxl_initialize_usp_mctpcci(CXLCCI *cci, DeviceState *d, DeviceState *intf,
Signature · 1 line
2.39.2
PATCH 8/19 docs: cxl: Add example commandline for MCTP CXL CCIs
In reply to Jonathan CameronAdd initial documentation for the MCTP over I2C management device. At current time this can only be used with the Aspeed I2C controller which is only available in aspeed SoCs, though can be added to other emulated boards.
--- docs/system/devices/cxl.rst | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
docs/system/devices/cxl.rst +27 -0
@@ -406,6 +406,33 @@ OS management of CXL memory devices as described here. * CONFIG_CXL_PORT * CONFIG_CXL_REGION + +CCI access via MCTP over I2C +---------------------------- + +In order to make use of this device, an I2C controller that supports MCTP +is required. The aspeed-i2c controller is an example of such a controller. + +Both CXL switches and CXL Type 3 devices support configuration via +MCTP access to Component Command Interfaces (CCIs) on the devices. + +Example configuration: + + -device cxl-upstream,port=33,bus=root_port0,id=us0,multifunction=on,addr=0.0,sn=12345678 \ + -device cxl-downstream,port=0,bus=us0,id=swport0,chassis=0,slot=4 \ + -device cxl-downstream,port=1,bus=us0,id=swport1,chassis=0,slot=5 \ + -device cxl-downstream,port=2,bus=us0,id=swport2,chassis=0,slot=6 \ + -device cxl-type3,bus=swport0,persistent-memdev=cxl-mem1,id=cxl-pmem0,lsa=cxl-lsa1,sn=3 \ + -device cxl-type3,bus=swport1,persistent-memdev=cxl-mem2,id=cxl-pmem1,lsa=cxl-lsa2,sn=4 \ + -device cxl-type3,bus=swport2,persistent-memdev=cxl-mem3,id=cxl-pmem2,lsa=cxl-lsa3,sn=5 \ + -device i2c_mctp_cxl,bus=aspeed.i2c.bus.0,address=4,target=us0 \ + -device i2c_mctp_cxl,bus=aspeed.i2c.bus.0,address=5,target=cxl-pmem0 \ + -device i2c_mctp_cxl,bus=aspeed.i2c.bus.0,address=6,target=cxl-pmem1 \ + -device i2c_mctp_cxl,bus=aspeed.i2c.bus.0,address=7,target=cxl-pmem2 + +Guest OS communication with the MCTP CCI can then be established using standard +MCTP configuration tools. + References ----------
Signature · 1 line
2.39.2
PATCH 9/19 hw/cxl/mbox: Add Physical Switch Identify command.
In reply to Jonathan CameronEnable it for MCTP CCI for the switch. Will shortly be enabled for switch CCI as well.
--- include/hw/cxl/cxl.h | 6 ++++ hw/cxl/cxl-mailbox-utils.c | 65 ++++++++++++++++++++++++++++++++++ hw/pci-bridge/cxl_downstream.c | 4 +-- 3 files changed, 72 insertions(+), 3 deletions(-)
include/hw/cxl/cxl.h +6 -0
@@ -61,4 +61,10 @@ OBJECT_DECLARE_SIMPLE_TYPE(CXLHost, PXB_CXL_HOST)typedef struct CXLUpstreamPort CXLUpstreamPort ; DECLARE_INSTANCE_CHECKER(CXLUpstreamPort, CXL_USP, TYPE_CXL_USP)CXLComponentState *cxl_usp_to_cstate (CXLUpstreamPort *usp); + +#define TYPE_CXL_DSP "cxl-downstream" + +typedef struct CXLDownstreamPort CXLDownstreamPort ; +DECLARE_INSTANCE_CHECKER(CXLDownstreamPort, CXL_DSP, TYPE_CXL_DSP) +#endif
hw/cxl/cxl-mailbox-utils.c +65 -0
83 lines not on this page · raw message
hw/pci-bridge/cxl_downstream.c +1 -3
@@ -13,6 +13,7 @@#include "hw/pci/msi.h" #include "hw/pci/pcie.h" #include "hw/pci/pcie_port.h" +#include "hw/cxl/cxl.h" #include "qapi/error.h" typedef struct CXLDownstreamPort {
@@ -23,9 +24,6 @@ typedef struct CXLDownstreamPort {CXLComponentState cxl_cstate; } CXLDownstreamPort; -#define TYPE_CXL_DSP "cxl-downstream" -DECLARE_INSTANCE_CHECKER(CXLDownstreamPort, CXL_DSP, TYPE_CXL_DSP) -#define CXL_DOWNSTREAM_PORT_MSI_OFFSET 0x70#define CXL_DOWNSTREAM_PORT_MSI_NR_VECTOR 1#define CXL_DOWNSTREAM_PORT_EXP_OFFSET 0x90
Signature · 1 line
2.39.2
PATCH 10/19 hw/cxl: Add a switch mailbox CCI function
In reply to Jonathan CameronCXL switch CCIs were added in CXL r3.0. They are a PCI function, identified by class code that provides a CXL mailbox (identical to that previously defined for CXL type 3 memory devices) over which various FM-API commands may be used. Whilst the intent of this feature is enable switch control from a BMC attached to a switch upstream port, it is also useful to allow emulation of this feature on the upstream port connected to a host using the CXL devices as this greatly simplifies testing.
---
- Use assigned Huawei VID and Device ID pair for this emulated device.
--- include/hw/cxl/cxl_component.h | 3 +- include/hw/cxl/cxl_device.h | 15 +++ include/hw/pci-bridge/cxl_upstream_port.h | 1 + hw/cxl/cxl-device-utils.c | 27 ++++++ hw/cxl/cxl-mailbox-utils.c | 21 ++++ hw/cxl/switch-mailbox-cci.c | 111 ++++++++++++++++++++++ hw/cxl/meson.build | 1 + 7 files changed, 178 insertions(+), 1 deletion(-)
include/hw/cxl/cxl_component.h +2 -1
@@ -26,7 +26,8 @@ enum reg_type {CXL2_LOGICAL_DEVICE ,CXL2_ROOT_PORT ,CXL2_UPSTREAM_PORT , - CXL2_DOWNSTREAM_PORT +CXL2_DOWNSTREAM_PORT , + CXL3_SWITCH_MAILBOX_CCI, };/*
include/hw/cxl/cxl_device.h +15 -0
@@ -221,8 +221,10 @@ void cxl_device_register_block_init(Object *obj, CXLDeviceState *dev, CXLCCI *cci);typedef struct CXLType3Dev CXLType3Dev ; +typedef struct CSWMBCCIDev CSWMBCCIDev ;/* Set up default values for the register block */ void cxl_device_register_init_t3 (CXLType3Dev *ct3d); +void cxl_device_register_init_swcci (CSWMBCCIDev *sw);/* * CXL 2.0 - 8.2.8.1 including errata F4
@@ -269,6 +271,8 @@ CXL_DEVICE_CAPABILITY_HEADER_REGISTER(MEMORY_DEVICE, CXL_DEVICE_CAP_REG_SIZE * 2)void cxl_initialize_mailbox_t3 (CXLCCI *cci,DeviceState *d,size_t payload_max); +void cxl_initialize_mailbox_swcci (CXLCCI *cci,DeviceState *intf, +DeviceState *d,size_t payload_max);void cxl_init_cci (CXLCCI *cci,size_t payload_max); int cxl_process_cci_message(CXLCCI *cci, uint8_t set, uint8_t cmd, size_t len_in, uint8_t *pl_in,
@@ -412,6 +416,17 @@ struct CXLType3Class { uint8_t *data); }; +struct CSWMBCCIDev { +PCIDevice parent_obj; +PCIDevice *target; +CXLComponentState cxl_cstate; +CXLDeviceState cxl_dstate; +CXLCCI *cci; +}; + +#define TYPE_CXL_SWITCH_MAILBOX_CCI "cxl-switch-mailbox-cci" +OBJECT_DECLARE_TYPE(CSWMBCCIDev, CSWMBCCIClass, CXL_SWITCH_MAILBOX_CCI) +MemTxResult cxl_type3_read (PCIDevice *d,hwaddr host_addr,uint64_t *data,unsigned size,MemTxAttrs attrs); MemTxResult cxl_type3_write(PCIDevice *d, hwaddr host_addr, uint64_t data,
include/hw/pci-bridge/cxl_upstream_port.h +1 -0
@@ -12,6 +12,7 @@ typedef struct CXLUpstreamPort {/*< public >*/ CXLComponentState cxl_cstate;CXLCCI mctpcci; +CXLCCI swcci;DOECap doe_cdat;uint64_t sn; } CXLUpstreamPort;
hw/cxl/cxl-device-utils.c +27 -0
@@ -67,6 +67,9 @@ static uint64_t mailbox_reg_read(void *opaque, hwaddr offset, unsigned size)if (object_dynamic_cast (OBJECT (cci->intf),TYPE_CXL_TYPE3 )) { cxl_dstate = &CXL_TYPE3 (cci->intf)->cxl_dstate; + }else if (object_dynamic_cast (OBJECT (cci->intf), +TYPE_CXL_SWITCH_MAILBOX_CCI )) { + cxl_dstate = &CXL_SWITCH_MAILBOX_CCI (cci->intf)->cxl_dstate; }else {return 0 ; }
@@ -154,6 +157,9 @@ static void mailbox_reg_write(void *opaque, hwaddr offset, uint64_t value,if (object_dynamic_cast (OBJECT (cci->intf),TYPE_CXL_TYPE3 )) { cxl_dstate = &CXL_TYPE3 (cci->intf)->cxl_dstate; + }else if (object_dynamic_cast (OBJECT (cci->intf), +TYPE_CXL_SWITCH_MAILBOX_CCI )) { + cxl_dstate = &CXL_SWITCH_MAILBOX_CCI (cci->intf)->cxl_dstate; }else {return ; }
@@ -372,6 +378,27 @@ void cxl_device_register_init_t3(CXLType3Dev *ct3d) CXL_MAILBOX_MAX_PAYLOAD_SIZE); } +void cxl_device_register_init_swcci (CSWMBCCIDev *sw) +{ +CXLDeviceState *cxl_dstate = &sw->cxl_dstate; +uint64_t *cap_h = cxl_dstate->caps_reg_state64; +const int cap_count =3 ; + +/* CXL Device Capabilities Array Register */ +ARRAY_FIELD_DP64 (cap_h,CXL_DEV_CAP_ARRAY ,CAP_ID ,0 ); +ARRAY_FIELD_DP64 (cap_h,CXL_DEV_CAP_ARRAY ,CAP_VERSION ,1 ); +ARRAY_FIELD_DP64 (cap_h,CXL_DEV_CAP_ARRAY ,CAP_COUNT , cap_count); + +cxl_device_cap_init (cxl_dstate,DEVICE_STATUS ,1 ,2 ); +device_reg_init_common (cxl_dstate); + +cxl_device_cap_init (cxl_dstate,MAILBOX ,2 ,1 ); +mailbox_reg_init_common (cxl_dstate); + +cxl_device_cap_init (cxl_dstate,MEMORY_DEVICE ,0x4000 ,1 ); +memdev_reg_init_common (cxl_dstate); +} +uint64_t cxl_device_get_timestamp (CXLDeviceState *cxl_dstate) {uint64_t time, delta;
hw/cxl/cxl-mailbox-utils.c +21 -0
@@ -863,6 +863,18 @@ static const struct cxl_cmd cxl_cmd_set[256][256] = { cmd_media_clear_poison, 72, 0 }, }; +static const struct cxl_cmd cxl_cmd_set_sw[256 ][256 ] = { + [INFOSTAT ][IS_IDENTIFY ] = {"IDENTIFY" , cmd_infostat_identify,0 ,18 }, + [TIMESTAMP ][GET ] = {"TIMESTAMP_GET" , cmd_timestamp_get,0 ,0 }, + [TIMESTAMP ][SET ] = {"TIMESTAMP_SET" , cmd_timestamp_set,8 , +IMMEDIATE_POLICY_CHANGE }, + [LOGS ][GET_SUPPORTED ] = {"LOGS_GET_SUPPORTED" , cmd_logs_get_supported,0 , +0 }, + [LOGS ][GET_LOG ] = {"LOGS_GET_LOG" , cmd_logs_get_log,0x18 ,0 }, + [PHYSICAL_SWITCH ][IDENTIFY_SWITCH_DEVICE ] = {"IDENTIFY_SWITCH_DEVICE" , + cmd_identify_switch_device,0 ,0x49 }, +}; +int cxl_process_cci_message (CXLCCI *cci,uint8_t set,uint8_t cmd,size_t len_in,uint8_t *pl_in,size_t *len_out,uint8_t *pl_out,bool *bg_started)
@@ -904,6 +916,15 @@ void cxl_init_cci(CXLCCI *cci, size_t payload_max) } } +void cxl_initialize_mailbox_swcci (CXLCCI *cci,DeviceState *intf, +DeviceState *d,size_t payload_max) +{ + cci->cxl_cmd_set = cxl_cmd_set_sw; + cci->d = d; + cci->intf = intf; +cxl_init_cci (cci, payload_max); +} +void cxl_initialize_mailbox_t3 (CXLCCI *cci,DeviceState *d,size_t payload_max) { cci->cxl_cmd_set = cxl_cmd_set;
hw/cxl/switch-mailbox-cci.c new file +111 -0
111 lines not on this page · raw message
hw/cxl/meson.build +1 -0
@@ -6,6 +6,7 @@ system_ss.add(when: 'CONFIG_CXL', 'cxl-host.c', 'cxl-cdat.c', 'cxl-events.c', + 'switch-mailbox-cci.c', ), if_false: files( 'cxl-host-stubs.c',
Signature · 1 line
2.39.2
PATCH 11/19 hw/pci-bridge/cxl_downstream: Set default link width and link speed
In reply to Jonathan CameronWithout these being set the PCIE Link Capabilities register has invalid values in these two fields.
--- hw/pci-bridge/cxl_downstream.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
hw/pci-bridge/cxl_downstream.c +14 -0
@@ -210,6 +210,19 @@ static void cxl_dsp_exitfn(PCIDevice *d)pci_bridge_exitfn (d); } +static void cxl_dsp_instance_post_init (Object *obj) +{ +PCIESlot *s =PCIE_SLOT (obj); + +if (!s->speed) { + s->speed =QEMU_PCI_EXP_LNK_2_5GT ; + } + +if (!s->width) { + s->width =QEMU_PCI_EXP_LNK_X1 ; + } +} +static void cxl_dsp_class_init (ObjectClass *oc,void *data) {DeviceClass *dc =DEVICE_CLASS (oc);
@@ -230,6 +243,7 @@ static const TypeInfo cxl_dsp_info = { .name = TYPE_CXL_DSP, .instance_size = sizeof(CXLDownstreamPort), .parent = TYPE_PCIE_SLOT, + .instance_post_init = cxl_dsp_instance_post_init, .class_init = cxl_dsp_class_init, .interfaces = (InterfaceInfo []) { {INTERFACE_PCIE_DEVICE },
Signature · 1 line
2.39.2
PATCH 12/19 hw/cxl: Implement Physical Ports status retrieval
In reply to Jonathan CameronAdd this command for both the Switch CCI and the MCTP CCI found in switch upstream ports.
--- hw/cxl/cxl-mailbox-utils.c | 121 +++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+)
hw/cxl/cxl-mailbox-utils.c +121 -0
@@ -72,6 +72,7 @@ enum {#define CLEAR_POISON 0x2 PHYSICAL_SWITCH = 0x51,#define IDENTIFY_SWITCH_DEVICE 0x0 +#define GET_PHYSICAL_PORT_STATE 0x1 };
@@ -312,6 +313,122 @@ static CXLRetCode cmd_identify_switch_device(const struct cxl_cmd *cmd,return CXL_MBOX_SUCCESS ; } + +/* CXL r3.0 Section 7.6.7.1.2: Get Physical Port State (Opcode 5101h) */ +static CXLRetCode cmd_get_physical_port_state (const struct cxl_cmd *cmd, +uint8_t *payload_in, +size_t len_in, +uint8_t *payload_out, +size_t *len_out, +CXLCCI *cci) +{ +/* CXL r3.0 Table 7-18: Get Physical Port State Request Payload */ +struct cxl_fmapi_get_phys_port_state_req_pl { +uint8_t num_ports; +uint8_t ports[]; + } QEMU_PACKED *in; + +/* +* CXL r3.0 Table 7-20: Get Physical Port State Port Information Block +* Format +*/ +struct cxl_fmapi_port_state_info_block { +uint8_t port_id; +uint8_t config_state; +uint8_t connected_device_cxl_version; +uint8_t rsv1; +uint8_t connected_device_type; +uint8_t port_cxl_version_bitmask; +uint8_t max_link_width; +uint8_t negotiated_link_width; +uint8_t supported_link_speeds_vector; +uint8_t max_link_speed; +uint8_t current_link_speed; +uint8_t ltssm_state; +uint8_t first_lane_num; +uint16_t link_state; +uint8_t supported_ld_count; + }QEMU_PACKED ; + +/* CXL r3.0 Table 7-19: Get Physical Port State Response Payload */ +struct cxl_fmapi_get_phys_port_state_resp_pl { +uint8_t num_ports; +uint8_t rsv1[3 ]; +struct cxl_fmapi_port_state_info_block ports[]; + } QEMU_PACKED *out; +PCIBus *bus = &PCI_BRIDGE (cci->d)->sec_bus; +PCIEPort *usp =PCIE_PORT (cci->d); +size_t pl_size; +int i; + + in = (struct cxl_fmapi_get_phys_port_state_req_pl *)payload_in; + out = (struct cxl_fmapi_get_phys_port_state_resp_pl *)payload_out; + +/* Check if what was requested can fit */ +if (sizeof (*out) +sizeof (*out->ports) * in->num_ports > cci->payload_max) { +return CXL_MBOX_INVALID_INPUT ; + } + +/* For success there should be a match for each requested */ + out->num_ports = in->num_ports; + +for (i =0 ; i < in->num_ports; i++) { +struct cxl_fmapi_port_state_info_block *port; +/* First try to match on downstream port */ +PCIDevice *port_dev; +uint16_t lnkcap, lnkcap2, lnksta; + + port = &out->ports[i]; + + port_dev =pcie_find_port_by_pn (bus, in->ports[i]); +if (port_dev) {/* DSP */ + port->config_state =3 ; + port->connected_device_type =4 ;/* TODO: Check. CXL type 3 */ + port->supported_ld_count =3 ; + }else if (usp->port == in->ports[i]) {/* USP */ + port_dev =PCI_DEVICE (usp); + port->config_state =4 ; + port->connected_device_type =0 ; + }else { +return CXL_MBOX_INVALID_INPUT ; + } + + port->port_id = in->ports[i]; +/* Information on status of this port in lnksta, lnkcap */ +if (!port_dev->exp.exp_cap) { +return CXL_MBOX_INTERNAL_ERROR ; + } + lnksta = port_dev->config_read (port_dev, + port_dev->exp.exp_cap +PCI_EXP_LNKSTA , +sizeof (lnksta)); + lnkcap = port_dev->config_read (port_dev, + port_dev->exp.exp_cap +PCI_EXP_LNKCAP , +sizeof (lnkcap)); + lnkcap2 = port_dev->config_read (port_dev, + port_dev->exp.exp_cap +PCI_EXP_LNKCAP2 , +sizeof (lnkcap2)); + + port->max_link_width = (lnkcap &PCI_EXP_LNKCAP_MLW ) >>4 ; + port->negotiated_link_width = (lnksta &PCI_EXP_LNKSTA_NLW ) >>4 ; +/* No definition for SLS field in linux/pci_regs.h */ + port->supported_link_speeds_vector = (lnkcap2 &0xFE ) >>1 ; + port->max_link_speed = lnkcap &PCI_EXP_LNKCAP_SLS ; + port->current_link_speed = lnksta &PCI_EXP_LNKSTA_CLS ; +/* TODO: Track down if we can get the rest of the info */ + port->ltssm_state =0x7 ; + port->first_lane_num =0 ; + port->link_state =0 ; + port->port_cxl_version_bitmask =0x2 ; + port->connected_device_cxl_version =0x2 ; + } + + pl_size =sizeof (out) +sizeof (*out->ports) * in->num_ports; + + *len_out = pl_size; + +return CXL_MBOX_SUCCESS ; +} +/* 8.2.9.2.1 */ static CXLRetCode cmd_firmware_update_get_info(const struct cxl_cmd *cmd, uint8_t *payload_in,
@@ -873,6 +990,8 @@ static const struct cxl_cmd cxl_cmd_set_sw[256][256] = { [LOGS][GET_LOG] = { "LOGS_GET_LOG", cmd_logs_get_log, 0x18, 0 }, [PHYSICAL_SWITCH ][IDENTIFY_SWITCH_DEVICE ] = {"IDENTIFY_SWITCH_DEVICE" , cmd_identify_switch_device, 0, 0x49 }, + [PHYSICAL_SWITCH ][GET_PHYSICAL_PORT_STATE ] = {"SWITCH_PHYSICAL_PORT_STATS" , + cmd_get_physical_port_state, ~0, ~0 }, }; int cxl_process_cci_message(CXLCCI *cci, uint8_t set, uint8_t cmd,
@@ -952,6 +1071,8 @@ static const struct cxl_cmd cxl_cmd_set_usp_mctp[256][256] = { [INFOSTAT][IS_IDENTIFY] = { "IDENTIFY", cmd_infostat_identify, 0, 18 }, [PHYSICAL_SWITCH ][IDENTIFY_SWITCH_DEVICE ] = {"IDENTIFY_SWITCH_DEVICE" , cmd_identify_switch_device, 0, 0x49 }, + [PHYSICAL_SWITCH ][GET_PHYSICAL_PORT_STATE ] = {"SWITCH_PHYSICAL_PORT_STATS" , + cmd_get_physical_port_state, ~0, ~0 }, }; void cxl_initialize_usp_mctpcci(CXLCCI *cci, DeviceState *d, DeviceState *intf,
Signature · 1 line
2.39.2
Re: [PATCH 12/19] hw/cxl: Implement Physical Ports status retrieval
...
Quoted 42 lines
hw/cxl/cxl-mailbox-utils.c +42
-0+/* CXL r3.0 Section 7.6.7.1.2: Get Physical Port State (Opcode 5101h) */ +static CXLRetCode cmd_get_physical_port_state (const struct cxl_cmd *cmd, +uint8_t *payload_in, +size_t len_in, +uint8_t *payload_out, +size_t *len_out, +CXLCCI *cci) +{ +/* CXL r3.0 Table 7-18: Get Physical Port State Request Payload */ +struct cxl_fmapi_get_phys_port_state_req_pl { +uint8_t num_ports; +uint8_t ports[]; + } QEMU_PACKED *in; + +/* +* CXL r3.0 Table 7-20: Get Physical Port State Port Information Block +* Format +*/ +struct cxl_fmapi_port_state_info_block { +uint8_t port_id; +uint8_t config_state; +uint8_t connected_device_cxl_version; +uint8_t rsv1; +uint8_t connected_device_type; +uint8_t port_cxl_version_bitmask; +uint8_t max_link_width; +uint8_t negotiated_link_width; +uint8_t supported_link_speeds_vector; +uint8_t max_link_speed; +uint8_t current_link_speed; +uint8_t ltssm_state; +uint8_t first_lane_num; +uint16_t link_state; +uint8_t supported_ld_count; + }QEMU_PACKED ; + +/* CXL r3.0 Table 7-19: Get Physical Port State Response Payload */ +struct cxl_fmapi_get_phys_port_state_resp_pl { +uint8_t num_ports; +uint8_t rsv1[3 ]; +struct cxl_fmapi_port_state_info_block ports[]; + } QEMU_PACKED *out;
...
Review
Quoted 2 lines
(quoted diff) +2
-0+ + pl_size = sizeof(out) + sizeof(*out->ports) * in->num_ports;
In cleaning up up my tests I added a missing check on the pl size.
First term should be sizeof(*out)
Quoted 6 lines
hw/cxl/cxl-mailbox-utils.c +6
-0+ + *len_out = pl_size; + +return CXL_MBOX_SUCCESS ; +} +
PATCH 13/19 hw/cxl/mbox: Add Get Background Operation Status Command
In reply to Jonathan CameronFor now, provide this command on type 3 main mailbox only.
--- hw/cxl/cxl-mailbox-utils.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
hw/cxl/cxl-mailbox-utils.c +33 -0
@@ -47,6 +47,7 @@enum {INFOSTAT =0x00 , #define IS_IDENTIFY 0x1 + #define BACKGROUND_OPERATION_STATUS 0x2EVENTS =0x01 ,#define GET_RECORDS 0x0 #define CLEAR_RECORDS 0x1
@@ -429,6 +430,36 @@ static CXLRetCode cmd_get_physical_port_state(const struct cxl_cmd *cmd,return CXL_MBOX_SUCCESS ; } +/* CXL r3.0 8.2.9.1.2 */ +static CXLRetCode cmd_infostat_bg_op_sts (const struct cxl_cmd *cmd, +uint8_t *payload_in, +size_t len_in, +uint8_t *payload_out, +size_t *len_out, +CXLCCI *cci) +{ +struct { +uint8_t status; +uint8_t rsvd; +uint16_t opcode; +uint16_t returncode; +uint16_t vendor_ext_status; + } QEMU_PACKED *bg_op_status; +QEMU_BUILD_BUG_ON (sizeof (*bg_op_status) !=8 ); + + bg_op_status = (void *)payload_out; +memset (bg_op_status,0 ,sizeof (*bg_op_status)); + bg_op_status->status = cci->bg.complete_pct <<1 ; +if (cci->bg.runtime >0 ) { + bg_op_status->status |=1U <<0 ; + } + bg_op_status->opcode = cci->bg.opcode; + bg_op_status->returncode = cci->bg.ret_code; + *len_out =sizeof (*bg_op_status); + +return CXL_MBOX_SUCCESS ; +} +/* 8.2.9.2.1 */ static CXLRetCode cmd_firmware_update_get_info(const struct cxl_cmd *cmd, uint8_t *payload_in,
@@ -982,6 +1013,8 @@ static const struct cxl_cmd cxl_cmd_set[256][256] = {static const struct cxl_cmd cxl_cmd_set_sw[256 ][256 ] = { [INFOSTAT ][IS_IDENTIFY ] = {"IDENTIFY" , cmd_infostat_identify,0 ,18 }, + [INFOSTAT ][BACKGROUND_OPERATION_STATUS ] = {"BACKGROUND_OPERATION_STATUS" , + cmd_infostat_bg_op_sts,0 ,8 }, [TIMESTAMP ][GET ] = {"TIMESTAMP_GET" , cmd_timestamp_get,0 ,0 }, [TIMESTAMP ][SET ] = {"TIMESTAMP_SET" , cmd_timestamp_set,8 ,IMMEDIATE_POLICY_CHANGE },
Signature · 1 line
2.39.2
PATCH 14/19 hw/cxl/mbox: Add support for background operations
In reply to Jonathan CameronFrom: Davidlohr Bueso <[email protected]>
Support background commands in the mailbox, and update cmd_infostat_bg_op_sts() accordingly. This patch does not implement mbox interrupts upon completion, so the kernel driver must rely on polling to know when the operation is done.
--- hw/cxl/cxl-device-utils.c | 5 +-- hw/cxl/cxl-mailbox-utils.c | 92 +++++++++++++++++++++++++++++++++++++- 2 files changed, 93 insertions(+), 4 deletions(-)
hw/cxl/cxl-device-utils.c +2 -3
@@ -133,8 +133,7 @@ static void mailbox_mem_writeq(uint64_t *reg_state, hwaddr offset,case A_CXL_DEV_MAILBOX_CMD :break ;case A_CXL_DEV_BG_CMD_STS : -/* BG not supported */ -/* fallthrough */ +break ;case A_CXL_DEV_MAILBOX_STS :/* Read only register, will get updated by the state machine */ return ;
@@ -346,7 +345,7 @@ static void device_reg_init_common(CXLDeviceState *cxl_dstate)static void mailbox_reg_init_common (CXLDeviceState *cxl_dstate) { -/* 2048 payload size, with no interrupt or background support */ +/* 2048 payload size, with no interrupt */ ARRAY_FIELD_DP32 (cxl_dstate->mbox_reg_state32,CXL_DEV_MAILBOX_CAP ,PAYLOAD_SIZE ,CXL_MAILBOX_PAYLOAD_SHIFT ); cxl_dstate->payload_size =CXL_MAILBOX_MAX_PAYLOAD_SIZE ;
hw/cxl/cxl-mailbox-utils.c +91 -1
120 lines not on this page · raw message
Signature · 1 line
2.39.2
PATCH 15/19 hw/cxl/mbox: Wire up interrupts for background completion
In reply to Jonathan CameronFrom: Davidlohr Bueso <[email protected]>
Notify when the background operation is done. Note that for now background commands are only supported on the main Type 3 mailbox.
--- include/hw/cxl/cxl_device.h | 1 + hw/cxl/cxl-device-utils.c | 10 +++++++++- hw/cxl/cxl-mailbox-utils.c | 31 ++++++++++++++----------------- 3 files changed, 24 insertions(+), 18 deletions(-)
include/hw/cxl/cxl_device.h +1 -0
@@ -193,6 +193,7 @@ typedef struct cxl_device_state {struct {MemoryRegion mailbox;uint16_t payload_size; +uint8_t mbox_msi_n;union {uint8_t mbox_reg_state[CXL_MAILBOX_REGISTERS_LENGTH ];uint16_t mbox_reg_state16[CXL_MAILBOX_REGISTERS_LENGTH /2 ];
hw/cxl/cxl-device-utils.c +9 -1
@@ -345,10 +345,18 @@ static void device_reg_init_common(CXLDeviceState *cxl_dstate)static void mailbox_reg_init_common (CXLDeviceState *cxl_dstate) { -/* 2048 payload size, with no interrupt */ +const uint8_t msi_n =9 ; + +/* 2048 payload size */ ARRAY_FIELD_DP32 (cxl_dstate->mbox_reg_state32,CXL_DEV_MAILBOX_CAP ,PAYLOAD_SIZE ,CXL_MAILBOX_PAYLOAD_SHIFT ); cxl_dstate->payload_size =CXL_MAILBOX_MAX_PAYLOAD_SIZE ; +/* irq support */ +ARRAY_FIELD_DP32 (cxl_dstate->mbox_reg_state32,CXL_DEV_MAILBOX_CAP , +BG_INT_CAP ,1 ); +ARRAY_FIELD_DP32 (cxl_dstate->mbox_reg_state32,CXL_DEV_MAILBOX_CAP , +MSI_N , msi_n); + cxl_dstate->mbox_msi_n = msi_n; }static void memdev_reg_init_common (CXLDeviceState *cxl_dstate) { }
hw/cxl/cxl-mailbox-utils.c +14 -17
@@ -8,6 +8,8 @@*/ #include "qemu/osdep.h" +#include "hw/pci/msi.h" +#include "hw/pci/msix.h" #include "hw/cxl/cxl.h" #include "hw/cxl/cxl_events.h" #include "hw/pci/pci.h"
@@ -1092,28 +1094,16 @@ int cxl_process_cci_message(CXLCCI *cci, uint8_t set, uint8_t cmd,static void bg_timercb (void *opaque) {CXLCCI *cci = opaque; -CXLDeviceState *cxl_dstate = &CXL_TYPE3 (cci->d)->cxl_dstate; -uint64_t bg_status_reg =0 ;uint64_t now =qemu_clock_get_ms (QEMU_CLOCK_VIRTUAL );uint64_t total_time = cci->bg.starttime + cci->bg.runtime;assert (cci->bg.runtime >0 ); - bg_status_reg =FIELD_DP64 (bg_status_reg,CXL_DEV_BG_CMD_STS , -OP , cci->bg.opcode);if (now >= total_time) {/* we are done */ -uint64_t status_reg;uint16_t ret =CXL_MBOX_SUCCESS ; cci->bg.complete_pct =100 ; -/* Clear bg */ - status_reg =FIELD_DP64 (0 ,CXL_DEV_MAILBOX_STS ,BG_OP ,0 ); - cxl_dstate->mbox_reg_state64[R_CXL_DEV_MAILBOX_STS ] = status_reg; - - bg_status_reg =FIELD_DP64 (bg_status_reg,CXL_DEV_BG_CMD_STS , -RET_CODE , ret); - -/* TODO add ad-hoc cmd succesful completion handling */ + cci->bg.ret_code = ret; qemu_log("Background command %04xh finished: %s\n", cci->bg.opcode,
@@ -1124,14 +1114,21 @@ static void bg_timercb(void *opaque)timer_mod (cci->bg.timer, now +CXL_MBOX_BG_UPDATE_FREQ ); } - bg_status_reg =FIELD_DP64 (bg_status_reg,CXL_DEV_BG_CMD_STS , -PERCENTAGE_COMP , cci->bg.complete_pct); - cxl_dstate->mbox_reg_state64[R_CXL_DEV_BG_CMD_STS ] = bg_status_reg; -if (cci->bg.complete_pct ==100 ) { +/* TODO: generalize to switch CCI */ +CXLType3Dev *ct3d =CXL_TYPE3 (cci->d); +CXLDeviceState *cxl_dstate = &ct3d->cxl_dstate; +PCIDevice *pdev =PCI_DEVICE (cci->d); + cci->bg.starttime =0 ;/* registers are updated, allow new bg-capable cmds */ cci->bg.runtime =0 ; + +if (msix_enabled (pdev)) { +msix_notify (pdev, cxl_dstate->mbox_msi_n); + }else if (msi_enabled (pdev)) { +msi_notify (pdev, cxl_dstate->mbox_msi_n); + } } }
Signature · 1 line
2.39.2
PATCH 16/19 hw/cxl: Add support for device sanitation
In reply to Jonathan CameronFrom: Davidlohr Bueso <[email protected]>
Make use of the background operations through the sanitize command, per CXL 3.0 specs. Traditionally run times can be rather long, depending on the size of the media.
Estimate times based on:
https://pmem.io/documents/NVDIMM_DSM_Interface-V1.8.pdf
--- include/hw/cxl/cxl_device.h | 17 +++++ hw/cxl/cxl-mailbox-utils.c | 140 ++++++++++++++++++++++++++++++++++++ hw/mem/cxl_type3.c | 10 +++ 3 files changed, 167 insertions(+)
include/hw/cxl/cxl_device.h +17 -0
@@ -347,6 +347,23 @@ REG64(CXL_MEM_DEV_STS, 0) FIELD(CXL_MEM_DEV_STS, MBOX_READY, 4, 1) FIELD(CXL_MEM_DEV_STS, RESET_NEEDED, 5, 3) +static inline void __toggle_media (CXLDeviceState *cxl_dstate,int val) +{ +uint64_t dev_status_reg; + + dev_status_reg =FIELD_DP64 (0 ,CXL_MEM_DEV_STS ,MEDIA_STATUS , val); + cxl_dstate->mbox_reg_state64[R_CXL_MEM_DEV_STS ] = dev_status_reg; +} +#define cxl_dev_disable_media (cxlds) \ + do { __toggle_media((cxlds), 0x3); } while (0) +#define cxl_dev_enable_media (cxlds) \ + do { __toggle_media((cxlds), 0x1); } while (0) + +static inline bool sanitize_running (CXLCCI *cci) +{ +return !!cci->bg.runtime && cci->bg.opcode ==0x4400 ; +} + typedef struct CXLError { QTAILQ_ENTRY(CXLError) node; int type; /* Error code as per FE definition */
hw/cxl/cxl-mailbox-utils.c +140 -0
176 lines not on this page · raw message
hw/mem/cxl_type3.c +10 -0
@@ -23,6 +23,7 @@#include "qemu/pmem.h" #include "qemu/range.h" #include "qemu/rcu.h" +#include "qemu/guest-random.h" #include "sysemu/hostmem.h" #include "sysemu/numa.h" #include "hw/cxl/cxl.h"
@@ -897,6 +898,11 @@ MemTxResult cxl_type3_read(PCIDevice *d, hwaddr host_addr, uint64_t *data,return MEMTX_ERROR ; } +if (sanitize_running (&CXL_TYPE3 (d)->cci)) { +qemu_guest_getrandom_nofail (data, size); +return MEMTX_OK ; + } +return address_space_read (as, dpa_offset, attrs, data, size); }
@@ -913,6 +919,10 @@ MemTxResult cxl_type3_write(PCIDevice *d, hwaddr host_addr, uint64_t data,return MEMTX_ERROR ; } +if (sanitize_running (&CXL_TYPE3 (d)->cci)) { +return MEMTX_OK ; + } +return address_space_write (as, dpa_offset, attrs, &data, size); }
Signature · 1 line
2.39.2
PATCH 17/19 hw/cxl/type3: Cleanup multiple CXL_TYPE3() calls in read/write functions
In reply to Jonathan CameronFrom: Gregory Price <[email protected]>
Call CXL_TYPE3 once at top of function to avoid multiple invocations.
--- hw/mem/cxl_type3.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
hw/mem/cxl_type3.c +6 -4
@@ -888,17 +888,18 @@ static int cxl_type3_hpa_to_as_and_dpa(CXLType3Dev *ct3d,MemTxResult cxl_type3_read (PCIDevice *d,hwaddr host_addr,uint64_t *data,unsigned size,MemTxAttrs attrs) { +CXLType3Dev *ct3d =CXL_TYPE3 (d);uint64_t dpa_offset =0 ;AddressSpace *as =NULL ;int res; - res =cxl_type3_hpa_to_as_and_dpa (CXL_TYPE3 (d), host_addr, size, + res =cxl_type3_hpa_to_as_and_dpa (ct3d, host_addr, size, &as, &dpa_offset);if (res) {return MEMTX_ERROR ; } -if (sanitize_running (&CXL_TYPE3 (d)->cci)) { +if (sanitize_running (&ct3d->cci)) {qemu_guest_getrandom_nofail (data, size);return MEMTX_OK ; }
@@ -909,17 +910,18 @@ MemTxResult cxl_type3_read(PCIDevice *d, hwaddr host_addr, uint64_t *data,MemTxResult cxl_type3_write (PCIDevice *d,hwaddr host_addr,uint64_t data,unsigned size,MemTxAttrs attrs) { +CXLType3Dev *ct3d =CXL_TYPE3 (d);uint64_t dpa_offset =0 ;AddressSpace *as =NULL ;int res; - res =cxl_type3_hpa_to_as_and_dpa (CXL_TYPE3 (d), host_addr, size, + res =cxl_type3_hpa_to_as_and_dpa (ct3d, host_addr, size, &as, &dpa_offset);if (res) {return MEMTX_ERROR ; } -if (sanitize_running (&CXL_TYPE3 (d)->cci)) { +if (sanitize_running (&ct3d->cci)) {return MEMTX_OK ; }
Signature · 1 line
2.39.2
PATCH 18/19 hw/cxl: Add dummy security state get
In reply to Jonathan CameronNeeded to allow the santize comamnds to be tested with proposed Linux Kernel support. Default value + no control of the security state will work for now.
--- hw/cxl/cxl-mailbox-utils.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
hw/cxl/cxl-mailbox-utils.c +17 -0
@@ -73,6 +73,8 @@ enum { SANITIZE = 0x44,#define OVERWRITE 0x0#define SECURE_ERASE 0x1 + PERSISTENT_MEM = 0x45, +#define GET_SECURITY_STATE 0x0 MEDIA_AND_POISON = 0x43,#define GET_POISON_LIST 0x0#define INJECT_POISON 0x1
@@ -869,6 +871,19 @@ static CXLRetCode cmd_sanitize_overwrite(const struct cxl_cmd *cmd, } } +static CXLRetCode cmd_get_security_state (const struct cxl_cmd *cmd, +uint8_t *payload_in, +size_t len_in, +uint8_t *payload_out, +size_t *len_out, +CXLCCI *cci) +{ +uint32_t *state = (uint32_t *)payload_out; + + *state =0 ; + *len_out =4 ; +return CXL_MBOX_SUCCESS ; +}/* * This is very inefficient, but good enough for now! * Also the payload will always fit, so no need to handle the MORE flag and
@@ -1115,6 +1130,8 @@ static const struct cxl_cmd cxl_cmd_set[256][256] = { ~0, IMMEDIATE_CONFIG_CHANGE | IMMEDIATE_DATA_CHANGE }, [SANITIZE][OVERWRITE] = { "SANITIZE_OVERWRITE", cmd_sanitize_overwrite, 0, IMMEDIATE_DATA_CHANGE | SECURITY_STATE_CHANGE | BACKGROUND_OPERATION }, + [PERSISTENT_MEM][GET_SECURITY_STATE] = { "GET_SECURITY_STATE", + cmd_get_security_state, 0, 0 }, [MEDIA_AND_POISON][GET_POISON_LIST] = { "MEDIA_AND_POISON_GET_POISON_LIST", cmd_media_get_poison_list, 16, 0 }, [MEDIA_AND_POISON][INJECT_POISON] = { "MEDIA_AND_POISON_INJECT_POISON",
Signature · 1 line
2.39.2
PATCH 19/19 hw/cxl: Add tunneled command support to mailbox for switch cci/mctp.
In reply to Jonathan CameronThe implementation of tunneling makes the choice that our Type 3 device is a Logical Device (LD) of a Multi-Logical Device (MLD) that just happens to only have one LD for now.
Tunneling is supported from a Switch Mailbox CCI or via MCTP over I2C connected to the switch mctp CCI via an outer level to the FM owned LD in the MLD Type 3 device. From there an inner tunnel may be used to access particular LDs.
Protocol wise, the following is what happens in a real system but we don't emulate the transports - just the destinations and the payloads.
( Host -> Switch Mailbox CCI - in band FM-API mailbox command
or
Host -> Switch MCTP CCI - MCTP over I2C using the CXL FM-API MCTP Binding.
)
then (if a tunnel command)
Switch -> Type 3 FM Owned LD - MCTP over PCI VDM using the CXL FM-API binding (addressed by switch port)
then (if next command also a tunnel)
Type 3 FM Owned LD to LD0 via internal transport (addressed by LD number)
or
Host to Type 3 FM Owned MCTP CCI - MCTP over I2C using the CXL FM-API MCTP Binding.
thn (if next comamnd alstunnel)
Type 3 FM Owned LD to LD0 via internal transport. (addressed by LD number)
It is worth noting that the tunneling commands over PCI VDM presumably use the FM-API MCTP binding not the CXL Memory Device Binding so it may not be possible to issue tunneled commands to an SLD. This and the near term usecase of controlling DCD motivated the decision to emulate an MLD from the start.
Additional commands will need to be added to make this useful beyond testing the tunneling works.
--- include/hw/cxl/cxl_device.h | 10 +++ hw/cxl/cxl-mailbox-utils.c | 152 ++++++++++++++++++++++++++++++++++++ hw/mem/cxl_type3.c | 11 +++ 3 files changed, 173 insertions(+)
include/hw/cxl/cxl_device.h +10 -0
@@ -281,6 +281,13 @@ int cxl_process_cci_message(CXLCCI *cci, uint8_t set, uint8_t cmd, bool *bg_started);void cxl_initialize_t3_mctpcci (CXLCCI *cci,DeviceState *d,DeviceState *intf,size_t payload_max); +void cxl_initialize_t3_fm_owned_ld_mctpcci (CXLCCI *cci,DeviceState *d, +DeviceState *intf, +size_t payload_max); + +void cxl_initialize_t3_ld_cci (CXLCCI *cci,DeviceState *d, +DeviceState *intf,size_t payload_max); +void cxl_initialize_usp_mctpcci (CXLCCI *cci,DeviceState *d,DeviceState *intf,size_t payload_max);
@@ -402,6 +409,9 @@ struct CXLType3Dev {CXLDeviceState cxl_dstate;CXLCCI cci;/* Primary PCI mailbox CCI */ CXLCCI oob_mctp_cci;/* Initialized only if targetted */ +/* Always intialized as no way to know if a VDM might show up */ +CXLCCI vdm_fm_owned_ld_mctp_cci; +CXLCCI ld0_cci;/* DOE */ DOECap doe_cdat;
hw/cxl/cxl-mailbox-utils.c +152 -0
184 lines not on this page · raw message
hw/mem/cxl_type3.c +11 -0
@@ -936,6 +936,17 @@ static void ct3d_reset(DeviceState *dev)cxl_component_register_init_common (reg_state, write_msk,CXL2_TYPE3_DEVICE );cxl_device_register_init_t3 (ct3d); + +/* +* Bring up an endpoint to target with MCTP over VDM. +* This device is emulating an MLD with single LD for now. +*/ +cxl_initialize_t3_fm_owned_ld_mctpcci (&ct3d->vdm_fm_owned_ld_mctp_cci, +DEVICE (ct3d),DEVICE (ct3d), +512 );/* Max payload made up */ +cxl_initialize_t3_ld_cci (&ct3d->ld0_cci,DEVICE (ct3d),DEVICE (ct3d), +512 );/* Max payload made up */ + }static Property ct3_props[] = {
Signature · 1 line
2.39.2
Quoted 2 lines · On Mon, 25 Sep 2023 17:11:05 +0100 Jonathan Cameron…
Based on: [PATCH] hw/cxl: Fix local variable shadowing of
cap_hdrsBased on: [PATCH v2 0/3] hw/cxl: Add dummy ACPI QTG DSM
Missed one.
Based on: [PATCH v4 0/4] hw/cxl: Support emulating 4 HDM decoders throughout topology
Quoted 10 lines
Based on: [PATCH V2] hw/pci-bridge/cxl-upstream: Add serial number extended capability support Based on: [PATCH v3 0/4] hw/cxl: Line length reduction and related
Based on: [PATCH v6 0/3] hw/{i2c,nvme}: mctp endpoint, nvme management interface modelI'm assuming this last dependency will go via a different tree though there is an outstanding request for tests. That equally applies to the CXL setup, but there are lot of moving parts. I'll experiment with basic testing of the MCTP I2C device whilst this is being reviewed.
Based on: Message ID: [email protected]
Based on: Message ID: [email protected]
Quoted 3 lines
Based on: Message ID: [email protected] Based on: Message ID: [email protected] Based on: Message ID: [email protected]
And to match above, the above should have been first.
Quoted 1 line
Based on: Message ID: [email protected]
So should be
Based on: [PATCH] hw/cxl: Fix local variable shadowing of cap_hdrs
Based on: [PATCH v2 0/3] hw/cxl: Add dummy ACPI QTG DSM
Based on: [PATCH v4 0/4] hw/cxl: Support emulating 4 HDM decoders throughout topology Based on: [PATCH V2] hw/pci-bridge/cxl-upstream: Add serial number extended capability support Based on: [PATCH v3 0/4] hw/cxl: Line length reduction and related
Based on: [PATCH v6 0/3] hw/{i2c,nvme}: mctp endpoint, nvme management interface model
Based on: Message ID: [email protected] Based on: Message ID: [email protected] Based on: Message ID: [email protected] Based on: Message ID: [email protected] Based on: Message ID: [email protected] Based on: Message ID: [email protected]
Sorry about that.
Jonathan
Quoted 6 lines · Jonathan Cameron
I've been carrying most of this series on our CXL staging tree
https://gitlab.com/jic23/qemu for some time and a lot of more recent work around Multi Head Devices and Dynamic Capacity that we need for Linux kernel enabling are backed up behind it. Hence I reorganized my queue to try and land this before other less 'central' features such as CXL PMUs and arm/virt support.
...
Quoted 9 lines
Jonathan Cameron (15):
hw/cxl/mbox: Pull the payload out of structcxl_cmdand make instances
constant
hw/cxl/mbox: Split mailbox command payload into separate input and
output
hw/cxl/mbox: Pull the CCI definition out of the CXLDeviceState hw/cxl/mbox: Generalize the CCI command processing hw/pci-bridge/cxl_upstream: Move defintion of device to header.
To save some list spam, I can't say i've reviewed and tested the entire set, but this patch series to help model the Niagara work so please add my tags as appropriate to the above.
~Gregory