QEMU: CXL mailbox rework and features (Part 1)
v2 cover QEMU: CXL mailbox rework and features (Part 1)
v2:
- To make this easier to merge, shuffle patches so that the MCTP over I2C transport can be in a later patch set once the prerequisites are in place.
- Various fixes identified by tightening up and expanding the test code
http://gitlab.com/jic23/cxl-fmapi-tests
Instructions on how to use this can also be found in that repository.
- Expanded command support so that each CCI can support a more representative command set (variable length payloads in both directions). Note we are not yet at the point of having implemented the required commands, let alone all the optional ones. Adding all those commands in an initial command set would have been far to large to review.
- A few changes (mostly in comments and patch descriptions) reflecting answers to CXL specification queries.
Based-on: [PULL v3 00/62] virtio,pc,pci: features, cleanups
Based-on: [PATCH v5 0/5] hw/cxl: Line length reduction and related
Based-on: Message-ID: [email protected]
Based-on: Message-ID: [email protected]
I haven't picked up Gregory's tags as I've made a lot of changes and as such he may want to retest the niagara support on this. Similarly I've dropped some of Fan Ni's tags due to changes in particular patches.
Updated v1 message:
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 aspects of CXL to enable orchestration and tooling development and also to enable testing of related kernel features.
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 management 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. The afore mentioned tunneling support. Note this exercises most of the paths that will also be used by the CXL FMAPI/Device MCTP over I2C series when posted.
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 the Switch Mailbox CCI is left for future series.
A typical Qemu command line snippet for testing these...
-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
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 (13):
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: Add a switch mailbox CCI function
hw/cxl/mbox: Add Information and Status / Identify command hw/cxl/mbox: Add Physical Switch Identify command. 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.
include/hw/cxl/cxl.h | 6 + include/hw/cxl/cxl_component.h | 3 +- include/hw/cxl/cxl_device.h | 104 ++- include/hw/pci-bridge/cxl_upstream_port.h | 19 + hw/cxl/cxl-device-utils.c | 132 ++- hw/cxl/cxl-events.c | 2 +- hw/cxl/cxl-mailbox-utils.c | 1035 ++++++++++++++++++--- 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/meson.build | 1 + 12 files changed, 1289 insertions(+), 185 deletions(-) create mode 100644 include/hw/pci-bridge/cxl_upstream_port.h create mode 100644 hw/cxl/switch-mailbox-cci.c
Signature · 1 line
2.39.2
PATCH v2 1/17 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
PATCH v2 2/17 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. To avoid the complexities of implementing all commands to handle potential aliasing, take a copy of the input before use.
---
v2:
- Drop Fan's RB as significant changes.
- Avoid passing aliased pointers to the various command handlers. It was a source of subtle bugs in the switch-cci so let us just make a copy and use that instead.
--- include/hw/cxl/cxl_device.h | 7 +- hw/cxl/cxl-events.c | 2 +- hw/cxl/cxl-mailbox-utils.c | 230 +++++++++++++++++++++--------------- 3 files changed, 140 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 +135 -95
503 lines not on this page · raw message
Signature · 1 line
2.39.2
Re: [PATCH v2 02/17] 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. To avoid the complexities of implementing all commands to handle potential aliasing, take a copy of the input before use.
Signed-off-by Jonathan Cameron <[email protected]>
Quoted 585 lines
---
v2:
- Drop Fan's RB as significant changes.
- Avoid passing aliased pointers to the various command handlers. It was a source of subtle bugs in the switch-cci so let us just make a copy and use that instead.--- include/hw/cxl/cxl_device.h | 7 +- hw/cxl/cxl-events.c | 2 +- hw/cxl/cxl-mailbox-utils.c | 230 +++++++++++++++++++++--------------- 3 files changed, 140 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 +135
-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,24 @@ 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 ; +/* +* Copy taken to avoid need for individual command handlers to care +* about aliasing. +*/ + g_autofree uint8_t *pl_in_copy = NULL; +size_t len_out =0 ; + pl_in_copy =g_memdup2 (pl, len_in); +/* Avoid stale data - including from earlier commands */ +memset (pl,0 ,CXL_MAILBOX_MAX_PAYLOAD_SIZE ); 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_in_copy, len_in, pl, &len_out, cxl_dstate); +assert (len_out <= cxl_dstate->payload_size); }else { ret =CXL_MBOX_INVALID_PAYLOAD_LENGTH ; }@@ -748,7 +788,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 v2 3/17 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.
---
v2:
- Dropped Fan's RB as substantial changes
- Some of Davidlohr's series adding background command support had accidentally gotten dragged in here whilst reordering patches.
--- include/hw/cxl/cxl_device.h | 35 ++++++++++---- hw/cxl/cxl-device-utils.c | 31 +++++++++--- hw/cxl/cxl-mailbox-utils.c | 94 ++++++++++++++++++++++--------------- hw/mem/cxl_type3.c | 5 +- 4 files changed, 109 insertions(+), 56 deletions(-)
include/hw/cxl/cxl_device.h +25 -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,21 @@ 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; + +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 +189,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 +207,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 +258,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 +361,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 v2 03/17] 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 516 lines
---
v2:
- Dropped Fan's RB as substantial changes
- Some of Davidlohr's series adding background command support had accidentally gotten dragged in here whilst reordering patches.--- include/hw/cxl/cxl_device.h | 35 ++++++++++---- hw/cxl/cxl-device-utils.c | 31 +++++++++--- hw/cxl/cxl-mailbox-utils.c | 94 ++++++++++++++++++++++--------------- hw/mem/cxl_type3.c | 5 +- 4 files changed, 109 insertions(+), 56 deletions(-)include/hw/cxl/cxl_device.h +25
-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,21 @@ 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; + +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 +189,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 +207,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 +258,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 +361,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 );@@ -767,12 +777,12 @@ void cxl_process_mailbox(CXLDeviceState *cxl_dstate) pl_in_copy =g_memdup2 (pl, len_in);/* Avoid stale data - including from earlier commands */ memset (pl,0 ,CXL_MAILBOX_MAX_PAYLOAD_SIZE ); - 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_in_copy, 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 ; }@@ -798,20 +808,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
-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
PATCH v2 4/17 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.
Change the type3 mailbox handling (reused shortly for the switch mailbox CCI) to take a snapshot of the mailbox input data rather than operating on it in place. This reduces the chance of bugs due to aliasing going forwars.
---
v2:
Drop Fan RB as significant changes as follow on from the aliasing avoidance change.
Also cleared out some bg operation stuff that was here as result of a misshandled patch reorder.
--- include/hw/cxl/cxl_device.h | 5 +++- hw/cxl/cxl-device-utils.c | 44 +++++++++++++++++++++++++++++++- hw/cxl/cxl-mailbox-utils.c | 51 ++++++++----------------------------- 3 files changed, 57 insertions(+), 43 deletions(-)
include/hw/cxl/cxl_device.h +4 -1
@@ -260,7 +260,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 +43 -1
50 lines not on this page · raw message
hw/cxl/cxl-mailbox-utils.c +10 -41
68 lines not on this page · raw message
Signature · 1 line
2.39.2
PATCH v2 5/17 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
PATCH v2 6/17 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.
---
v2: Fixed wrong assumption that the second number in cxl_cmd
was expected return length - it's Effects Bitmap.
Patch reorg effects, some commands now introduced in later patches.
--- 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 | 18 ++++ hw/cxl/switch-mailbox-cci.c | 111 ++++++++++++++++++++++ hw/cxl/meson.build | 1 + 7 files changed, 175 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
@@ -211,8 +211,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
@@ -259,6 +261,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,
@@ -397,6 +401,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
@@ -11,6 +11,7 @@ typedef struct CXLUpstreamPort {/*< public >*/ CXLComponentState cxl_cstate; +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 ; }
@@ -135,6 +138,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 ; }
@@ -365,6 +371,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 +18 -0
@@ -754,6 +754,15 @@ 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 ] = { + [TIMESTAMP ][GET ] = {"TIMESTAMP_GET" , cmd_timestamp_get,0 ,0 }, + [TIMESTAMP ][SET ] = {"TIMESTAMP_SET" , cmd_timestamp_set,0 , +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 }, +}; +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)
@@ -795,6 +804,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 v2 7/17 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.
---
v2:
- The subsystem [vendor] ID is not set in the class if defaults are used so grab it directly from the config registers. I could have set this for the CXL devices, but then I'd need an ID to use and as the CXL type3 devices have Intel VID it would be odd to make them part of a Huawei subsystem even if I jumped through the necessary hoops to get a subsystem ID assigned.
--- hw/cxl/cxl-mailbox-utils.c | 55 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+)
hw/cxl/cxl-mailbox-utils.c +55 -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,57 @@ 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 )) { +PCIDevice *pci_dev =PCI_DEVICE (cci->d); + + is_identify->sn =CXL_TYPE3 (cci->d)->sn; +/* +* We can't always use class->subsystem_vendor_id as +* it is not set if the defaults are used. +*/ + is_identify->pcie_subsys_vid = +pci_get_word (pci_dev->config +PCI_SUBSYSTEM_VENDOR_ID ); + is_identify->pcie_subsys_id = +pci_get_word (pci_dev->config +PCI_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,
@@ -755,6 +809,7 @@ 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 ,0 }, [TIMESTAMP ][GET ] = {"TIMESTAMP_GET" , cmd_timestamp_get,0 ,0 }, [TIMESTAMP ][SET ] = {"TIMESTAMP_SET" , cmd_timestamp_set,0 ,IMMEDIATE_POLICY_CHANGE },
Signature · 1 line
2.39.2
PATCH v2 8/17 hw/cxl/mbox: Add Physical Switch Identify command.
In reply to Jonathan CameronEnable it for the switch CCI.
--- 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 v2 9/17 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 v2 10/17 hw/cxl: Implement Physical Ports status retrieval
In reply to Jonathan CameronAdd this command for both the Switch CCI in switch upstream ports.
---
v2:
- Fix wrong size of message.
- Fill in downstream connected device with correct device types. Note intially all emulated type 3 devices are considered MLDs.
--- hw/cxl/cxl-mailbox-utils.c | 128 +++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+)
hw/cxl/cxl-mailbox-utils.c +128 -0
@@ -72,6 +72,7 @@ enum {#define CLEAR_POISON 0x2 PHYSICAL_SWITCH = 0x51,#define IDENTIFY_SWITCH_DEVICE 0x0 +#define GET_PHYSICAL_PORT_STATE 0x1 };
@@ -320,6 +321,131 @@ 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 */ +PCIDevice *ds_dev =pci_bridge_get_sec_bus (PCI_BRIDGE (port_dev)) + ->devices[0 ]; + port->config_state =3 ; +if (ds_dev) { +if (object_dynamic_cast (OBJECT (ds_dev),TYPE_CXL_TYPE3 )) { + port->connected_device_type =5 ;/* Assume MLD for now */ + }else { + port->connected_device_type =1 ; + } + }else { + port->connected_device_type =0 ; + } + 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,
@@ -881,6 +1007,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, 0 }, + [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,
Signature · 1 line
2.39.2
PATCH v2 11/17 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.
---
v2 of CCI rework series containing this.
- Recover aspects that accidentally ended up in earlier patches.
--- include/hw/cxl/cxl_device.h | 10 ++++ hw/cxl/cxl-device-utils.c | 24 ++++++++-- hw/cxl/cxl-mailbox-utils.c | 92 ++++++++++++++++++++++++++++++++++++- 3 files changed, 122 insertions(+), 4 deletions(-)
include/hw/cxl/cxl_device.h +10 -0
@@ -149,6 +149,16 @@ typedef struct CXLCCI { } 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;
hw/cxl/cxl-device-utils.c +21 -3
@@ -82,6 +82,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 ();
@@ -114,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 ;
@@ -339,7 +357,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 v2 12/17 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
@@ -357,10 +357,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"
@@ -1076,28 +1078,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,
@@ -1108,14 +1098,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 v2 13/17 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
@@ -343,6 +343,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
Re: [PATCH v2 13/17] hw/cxl: Add support for device sanitation
Quoted 27 lines · Jonathan Cameron
From: 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.pdfSigned-off-by Davidlohr Bueso <[email protected]>Signed-off-by Jonathan Cameron <[email protected]>--- 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 +1
-0@@ -343,6 +343,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)
include/hw/cxl/cxl_device.h REG64(CXL_MEM_DEV_STS, 0) · line 356
Quoted 10 lines
include/hw/cxl/cxl_device.h +10
-0+{ +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)
Before this patch, it is assumed that "Media Status" and "Mailbox Interface Ready" were always 1,
thus mdev_reg_read() always returns 1 for both of them regardless of register values.
I think changes like below are needed as now the assumption is broken? Please note that it's only build-tested :)
Thanks,
Hyeonggon
hw/cxl/cxl-device-utils.c +0 -0
@@ -229,12 +229,9 @@ static void mailbox_reg_write(void *opaque,
hwaddr offset, uint64_t value,
static uint64_t mdev_reg_read(void *opaque, hwaddr offset, unsigned size) {
- uint64_t retval = 0;
-
- retval = FIELD_DP64(retval, CXL_MEM_DEV_STS, MEDIA_STATUS, 1); - retval = FIELD_DP64(retval, CXL_MEM_DEV_STS, MBOX_READY, 1); + CXLDeviceState *cxl_dstate = opaque;
- return retval;
+ return cxl_dstate->mbox_reg_state64[R_CXL_MEM_DEV_STS];
}
static void ro_reg_write(void *opaque, hwaddr offset, uint64_t value,
@@ -371,7 +368,13 @@ static void mailbox_reg_init_common(CXLDeviceState *cxl_dstate)
cxl_dstate->mbox_msi_n = msi_n;
}
-static void memdev_reg_init_common(CXLDeviceState *cxl_dstate) { } +static void memdev_reg_init_common(CXLDeviceState *cxl_dstate) {
+ uint64_t memdev_status_reg;
+
+ memdev_status_reg = FIELD_DP64(0, CXL_MEM_DEV_STS, MEDIA_STATUS, 1);
+ memdev_status_reg = FIELD_DP64(memdev_status_reg,CXL_MEM_DEV_STS, MBOX_READY, 1);
+ cxl_dstate->mbox_reg_state64[R_CXL_MEM_DEV_STS] = memdev_status_reg;
+}
void cxl_device_register_init_t3(CXLType3Dev *ct3d) {
include/hw/cxl/cxl_device.h +2 -2
@@ -351,9 +351,9 @@ REG64(CXL_MEM_DEV_STS, 0)static inline void __toggle_media (CXLDeviceState *cxl_dstate,int val) { -uint64_t dev_status_reg; +uint64_t dev_status_reg = cxl_dstate->mbox_reg_state64[R_CXL_MEM_DEV_STS ]; - dev_status_reg =FIELD_DP64 (0 ,CXL_MEM_DEV_STS ,MEDIA_STATUS , val); + dev_status_reg = FIELD_DP64(dev_status_reg, 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) \
PATCH v2 14/17 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
@@ -50,6 +50,7 @@enum {INFOSTAT =0x00 , #define IS_IDENTIFY 0x1 + #define BACKGROUND_OPERATION_STATUS 0x2EVENTS =0x01 ,#define GET_RECORDS 0x0 #define CLEAR_RECORDS 0x1
@@ -452,6 +453,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,
@@ -1111,6 +1142,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 ,0 }, + [INFOSTAT ][BACKGROUND_OPERATION_STATUS ] = {"BACKGROUND_OPERATION_STATUS" , + cmd_infostat_bg_op_sts,0 ,0 }, [TIMESTAMP ][GET ] = {"TIMESTAMP_GET" , cmd_timestamp_get,0 ,0 }, [TIMESTAMP ][SET ] = {"TIMESTAMP_SET" , cmd_timestamp_set,0 ,IMMEDIATE_POLICY_CHANGE },
Signature · 1 line
2.39.2
PATCH v2 15/17 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 v2 16/17 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
@@ -886,6 +888,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
@@ -1132,6 +1147,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 v2 17/17 hw/cxl: Add tunneled command support to mailbox for switch cci.
In reply to Jonathan CameronThis 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 (and shortly 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 unwrapped command also a tunnel command) Type 3 FM Owned LD to LD0 via internal transport (addressed by LD number)
or (added shortly)
Host to Type 3 FM Owned MCTP CCI - MCTP over I2C using the CXL FM-API MCTP Binding.
then (if unwrapped comand is a tunnel comamnd) 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 appropriate MCTP binding depending on opcode. This may be the CXL FMAPI binding or the CXL Memory Device Binding.
Additional commands will need to be added to make this useful beyond testing the tunneling works.
---
v2:
- Fix some missing element in tunneled responses (tag, cmd, cmd_set) Picked up by adding a more exhaustive test case.
- Reordering to move the MCTP over i2c support to after this resulted in various changes.
--- include/hw/cxl/cxl_device.h | 9 ++ hw/cxl/cxl-mailbox-utils.c | 162 ++++++++++++++++++++++++++++++++++++ hw/mem/cxl_type3.c | 11 +++ 3 files changed, 182 insertions(+)
include/hw/cxl/cxl_device.h +9 -0
@@ -279,6 +279,12 @@ 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_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);#define cxl_device_cap_init (dstate, reg, cap_id, ver) \ do { \
@@ -397,6 +403,9 @@ struct CXLType3Dev {CXLComponentState cxl_cstate;CXLDeviceState cxl_dstate;CXLCCI cci;/* Primary PCI mailbox CCI */ +/* 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 +162 -0
179 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 3 lines
This series is focused on enabling the Fabric Management aspects of CXL to enable orchestration and tooling development and also to enable testing of related kernel features.
This would be a better subject than "CXL mailbox" then ;)