* [PATCH qemu 0/8] hw/cxl: new features for 10.0 (possibly)
@ 2025-03-05 9:24 Jonathan Cameron via
2025-03-05 9:24 ` [PATCH qemu 1/8] hw/cxl: Support aborting background commands Jonathan Cameron via
` (7 more replies)
0 siblings, 8 replies; 17+ messages in thread
From: Jonathan Cameron via @ 2025-03-05 9:24 UTC (permalink / raw)
To: linux-cxl, qemu-devel, mst
Cc: linuxarm, fan.ni, Yuquan Wang, Arpit Kumar, Sweta Kumari,
Vinayak Holikatti, Davidlohr Bueso, Ajay Joshi
Hi Michael / All,
This is a bit late in the cycle due to some travel and alignment with the
end of a kernel cycle which has made me very busy. If needed I'll send a
rebased version of these right at the start of the 10.1 cycle.
As in previous cycles I have been gathering up reviewed patches so as to
resolve merge conflicts etc before proposing a set to merge to Michael
Tsirkin (and for additional review). The focus of the CXL support continues
to be on emulating a subset of features useful to Linux kernel testing +
more limited support for out of band management over mctp
(one patch in here)
Note that I've only picked up the first of Arpit's series for log
manipulation as the clear and populate log functions are only useful if
any of the supported logs actually allow those functions otherwise they
will always return an error (which will occur for all logs we currently
emulate) The capabilities query is applicable for the Command Effects Log
and indeed indicates that we can't clear or populate it. So that is fine
on it's own.
Otherwise this is a mixed bag of features. The media operations are
particularly interesting as they enable offloading of memory zeroing
/ wiping. Support for aborting background operations is needed to
enable testing of a feature that allows us to enable userspace access
to background commands without risking lockout of urgent kernel commands
Thanks,
Jonathan
Arpit Kumar (1):
hw/cxl/cxl-mailbox-utils: Added support for Get Log Capabilities
(Opcode 0402h)
Davidlohr Bueso (2):
hw/cxl: Support aborting background commands
hw/cxl: Support get/set mctp response payload size
Sweta Kumari (1):
hw/cxl/cxl-mailbox-utils: CXL CCI Get/Set alert config commands
Vinayak Holikatti (3):
hw/cxl/cxl-mailbox-utils: Add support for Media operations discovery
commands cxl r3.2 (8.2.10.9.5.3)
hw/cxl: factor out calculation of sanitize duration from
cmd_santize_overwrite
hw/cxl/cxl-mailbox-utils: Media operations Sanitize and Write Zeros
commands CXL r3.2(8.2.10.9.5.3)
Yuquan Wang (1):
docs/cxl: Add serial number for persistent-memdev
docs/system/devices/cxl.rst | 18 +-
include/hw/cxl/cxl_device.h | 43 +++
include/hw/cxl/cxl_mailbox.h | 6 +
hw/cxl/cxl-device-utils.c | 14 +-
hw/cxl/cxl-mailbox-utils.c | 668 +++++++++++++++++++++++++++++++++--
hw/mem/cxl_type3.c | 22 +-
6 files changed, 722 insertions(+), 49 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH qemu 1/8] hw/cxl: Support aborting background commands
2025-03-05 9:24 [PATCH qemu 0/8] hw/cxl: new features for 10.0 (possibly) Jonathan Cameron via
@ 2025-03-05 9:24 ` Jonathan Cameron via
2025-03-05 9:24 ` [PATCH qemu 2/8] hw/cxl: Support get/set mctp response payload size Jonathan Cameron via
` (6 subsequent siblings)
7 siblings, 0 replies; 17+ messages in thread
From: Jonathan Cameron via @ 2025-03-05 9:24 UTC (permalink / raw)
To: linux-cxl, qemu-devel, mst
Cc: linuxarm, fan.ni, Yuquan Wang, Arpit Kumar, Sweta Kumari,
Vinayak Holikatti, Davidlohr Bueso, Ajay Joshi
From: Davidlohr Bueso <dave@stgolabs.net>
As of 3.1 spec, background commands can be canceled with a new
abort command. Implement the support, which is advertised in
the CEL. No ad-hoc context undoing is necessary as all the
command logic of the running bg command is done upon completion.
Arbitrarily, the on-going background cmd will not be aborted if
already at least 85% done;
A mutex is introduced to stabilize mbox request cancel command vs
the timer callback being fired scenarios (as well as reading the
mbox registers). While some operations under critical regions
may be unnecessary (irq notifying, cmd callbacks), this is not
a path where performance is important, so simplicity is preferred.
Tested-by: Ajay Joshi <ajay.opensrc@micron.com>
Reviewed-by: Ajay Joshi <ajay.opensrc@micron.com>
Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
Modified with changes Davidlohr posted on list.
---
include/hw/cxl/cxl_device.h | 4 ++
include/hw/cxl/cxl_mailbox.h | 1 +
hw/cxl/cxl-device-utils.c | 14 ++++---
hw/cxl/cxl-mailbox-utils.c | 72 ++++++++++++++++++++++++++++++++----
hw/mem/cxl_type3.c | 8 +++-
5 files changed, 86 insertions(+), 13 deletions(-)
diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h
index 3a0ee7e8e7..d21695507f 100644
--- a/include/hw/cxl/cxl_device.h
+++ b/include/hw/cxl/cxl_device.h
@@ -176,10 +176,12 @@ typedef struct CXLCCI {
uint16_t opcode;
uint16_t complete_pct;
uint16_t ret_code; /* Current value of retcode */
+ bool aborted;
uint64_t starttime;
/* set by each bg cmd, cleared by the bg_timer when complete */
uint64_t runtime;
QEMUTimer *timer;
+ QemuMutex lock; /* serializes mbox abort vs timer cb */
} bg;
/* firmware update */
@@ -201,6 +203,7 @@ typedef struct CXLCCI {
DeviceState *d;
/* Pointer to the device hosting the protocol conversion */
DeviceState *intf;
+ bool initialized;
} CXLCCI;
typedef struct cxl_device_state {
@@ -316,6 +319,7 @@ 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);
+void cxl_destroy_cci(CXLCCI *cci);
void cxl_add_cci_commands(CXLCCI *cci, const struct cxl_cmd (*cxl_cmd_set)[256],
size_t payload_max);
int cxl_process_cci_message(CXLCCI *cci, uint8_t set, uint8_t cmd,
diff --git a/include/hw/cxl/cxl_mailbox.h b/include/hw/cxl/cxl_mailbox.h
index beb048052e..9008402d1c 100644
--- a/include/hw/cxl/cxl_mailbox.h
+++ b/include/hw/cxl/cxl_mailbox.h
@@ -14,5 +14,6 @@
#define CXL_MBOX_IMMEDIATE_LOG_CHANGE (1 << 4)
#define CXL_MBOX_SECURITY_STATE_CHANGE (1 << 5)
#define CXL_MBOX_BACKGROUND_OPERATION (1 << 6)
+#define CXL_MBOX_BACKGROUND_OPERATION_ABORT (1 << 7)
#endif
diff --git a/hw/cxl/cxl-device-utils.c b/hw/cxl/cxl-device-utils.c
index 52ad1e4c3f..e150d74457 100644
--- a/hw/cxl/cxl-device-utils.c
+++ b/hw/cxl/cxl-device-utils.c
@@ -95,11 +95,15 @@ static uint64_t mailbox_reg_read(void *opaque, hwaddr offset, unsigned size)
}
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;
- }
+ int bgop;
+
+ qemu_mutex_lock(&cci->bg.lock);
+ bgop = !(cci->bg.complete_pct == 100 || cci->bg.aborted);
+
+ status_reg = FIELD_DP64(status_reg, CXL_DEV_MAILBOX_STS, BG_OP,
+ bgop);
+ cxl_dstate->mbox_reg_state64[offset / size] = status_reg;
+ qemu_mutex_unlock(&cci->bg.lock);
}
return cxl_dstate->mbox_reg_state64[offset / size];
default:
diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
index 516c01d840..4401f446d9 100644
--- a/hw/cxl/cxl-mailbox-utils.c
+++ b/hw/cxl/cxl-mailbox-utils.c
@@ -56,6 +56,7 @@ enum {
INFOSTAT = 0x00,
#define IS_IDENTIFY 0x1
#define BACKGROUND_OPERATION_STATUS 0x2
+ #define BACKGROUND_OPERATION_ABORT 0x5
EVENTS = 0x01,
#define GET_RECORDS 0x0
#define CLEAR_RECORDS 0x1
@@ -636,6 +637,41 @@ static CXLRetCode cmd_infostat_bg_op_sts(const struct cxl_cmd *cmd,
return CXL_MBOX_SUCCESS;
}
+/*
+ * CXL r3.1 Section 8.2.9.1.5:
+ * Request Abort Background Operation (Opcode 0005h)
+ */
+static CXLRetCode cmd_infostat_bg_op_abort(const struct cxl_cmd *cmd,
+ uint8_t *payload_in,
+ size_t len_in,
+ uint8_t *payload_out,
+ size_t *len_out,
+ CXLCCI *cci)
+{
+ int bg_set = cci->bg.opcode >> 8;
+ int bg_cmd = cci->bg.opcode & 0xff;
+ const struct cxl_cmd *bg_c = &cci->cxl_cmd_set[bg_set][bg_cmd];
+
+ if (!(bg_c->effect & CXL_MBOX_BACKGROUND_OPERATION_ABORT)) {
+ return CXL_MBOX_REQUEST_ABORT_NOTSUP;
+ }
+
+ qemu_mutex_lock(&cci->bg.lock);
+ if (cci->bg.runtime) {
+ /* operation is near complete, let it finish */
+ if (cci->bg.complete_pct < 85) {
+ timer_del(cci->bg.timer);
+ cci->bg.ret_code = CXL_MBOX_ABORTED;
+ cci->bg.starttime = 0;
+ cci->bg.runtime = 0;
+ cci->bg.aborted = true;
+ }
+ }
+ qemu_mutex_unlock(&cci->bg.lock);
+
+ return CXL_MBOX_SUCCESS;
+}
+
#define CXL_FW_SLOTS 2
#define CXL_FW_SIZE 0x02000000 /* 32 mb */
@@ -2715,6 +2751,8 @@ static CXLRetCode cmd_dcd_release_dyn_cap(const struct cxl_cmd *cmd,
}
static const struct cxl_cmd cxl_cmd_set[256][256] = {
+ [INFOSTAT][BACKGROUND_OPERATION_ABORT] = { "BACKGROUND_OPERATION_ABORT",
+ cmd_infostat_bg_op_abort, 0, 0 },
[EVENTS][GET_RECORDS] = { "EVENTS_GET_RECORDS",
cmd_events_get_records, 1, 0 },
[EVENTS][CLEAR_RECORDS] = { "EVENTS_CLEAR_RECORDS",
@@ -2727,9 +2765,11 @@ static const struct cxl_cmd cxl_cmd_set[256][256] = {
[FIRMWARE_UPDATE][GET_INFO] = { "FIRMWARE_UPDATE_GET_INFO",
cmd_firmware_update_get_info, 0, 0 },
[FIRMWARE_UPDATE][TRANSFER] = { "FIRMWARE_UPDATE_TRANSFER",
- cmd_firmware_update_transfer, ~0, CXL_MBOX_BACKGROUND_OPERATION },
+ cmd_firmware_update_transfer, ~0,
+ CXL_MBOX_BACKGROUND_OPERATION | CXL_MBOX_BACKGROUND_OPERATION_ABORT },
[FIRMWARE_UPDATE][ACTIVATE] = { "FIRMWARE_UPDATE_ACTIVATE",
- cmd_firmware_update_activate, 2, CXL_MBOX_BACKGROUND_OPERATION },
+ cmd_firmware_update_activate, 2,
+ CXL_MBOX_BACKGROUND_OPERATION | CXL_MBOX_BACKGROUND_OPERATION_ABORT },
[TIMESTAMP][GET] = { "TIMESTAMP_GET", cmd_timestamp_get, 0, 0 },
[TIMESTAMP][SET] = { "TIMESTAMP_SET", cmd_timestamp_set,
8, CXL_MBOX_IMMEDIATE_POLICY_CHANGE },
@@ -2758,7 +2798,8 @@ static const struct cxl_cmd cxl_cmd_set[256][256] = {
[SANITIZE][OVERWRITE] = { "SANITIZE_OVERWRITE", cmd_sanitize_overwrite, 0,
(CXL_MBOX_IMMEDIATE_DATA_CHANGE |
CXL_MBOX_SECURITY_STATE_CHANGE |
- CXL_MBOX_BACKGROUND_OPERATION)},
+ CXL_MBOX_BACKGROUND_OPERATION |
+ CXL_MBOX_BACKGROUND_OPERATION_ABORT)},
[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",
@@ -2771,7 +2812,8 @@ static const struct cxl_cmd cxl_cmd_set[256][256] = {
"MEDIA_AND_POISON_GET_SCAN_MEDIA_CAPABILITIES",
cmd_media_get_scan_media_capabilities, 16, 0 },
[MEDIA_AND_POISON][SCAN_MEDIA] = { "MEDIA_AND_POISON_SCAN_MEDIA",
- cmd_media_scan_media, 17, CXL_MBOX_BACKGROUND_OPERATION },
+ cmd_media_scan_media, 17,
+ (CXL_MBOX_BACKGROUND_OPERATION | CXL_MBOX_BACKGROUND_OPERATION_ABORT)},
[MEDIA_AND_POISON][GET_SCAN_MEDIA_RESULTS] = {
"MEDIA_AND_POISON_GET_SCAN_MEDIA_RESULTS",
cmd_media_get_scan_media_results, 0, 0 },
@@ -2795,6 +2837,8 @@ 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 },
+ [INFOSTAT][BACKGROUND_OPERATION_ABORT] = { "BACKGROUND_OPERATION_ABORT",
+ cmd_infostat_bg_op_abort, 0, 0 },
[TIMESTAMP][GET] = { "TIMESTAMP_GET", cmd_timestamp_get, 0, 0 },
[TIMESTAMP][SET] = { "TIMESTAMP_SET", cmd_timestamp_set, 8,
CXL_MBOX_IMMEDIATE_POLICY_CHANGE },
@@ -2881,6 +2925,7 @@ int cxl_process_cci_message(CXLCCI *cci, uint8_t set, uint8_t cmd,
cci->bg.opcode = (set << 8) | cmd;
cci->bg.complete_pct = 0;
+ cci->bg.aborted = false;
cci->bg.ret_code = 0;
now = qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL);
@@ -2894,10 +2939,12 @@ int cxl_process_cci_message(CXLCCI *cci, uint8_t set, uint8_t cmd,
static void bg_timercb(void *opaque)
{
CXLCCI *cci = opaque;
- uint64_t now = qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL);
- uint64_t total_time = cci->bg.starttime + cci->bg.runtime;
+ uint64_t now, total_time;
+
+ qemu_mutex_lock(&cci->bg.lock);
- assert(cci->bg.runtime > 0);
+ now = qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL);
+ total_time = cci->bg.starttime + cci->bg.runtime;
if (now >= total_time) { /* we are done */
uint16_t ret = CXL_MBOX_SUCCESS;
@@ -2950,6 +2997,8 @@ static void bg_timercb(void *opaque)
msi_notify(pdev, cxl_dstate->mbox_msi_n);
}
}
+
+ qemu_mutex_unlock(&cci->bg.lock);
}
static void cxl_rebuild_cel(CXLCCI *cci)
@@ -2978,12 +3027,21 @@ void cxl_init_cci(CXLCCI *cci, size_t payload_max)
cci->bg.complete_pct = 0;
cci->bg.starttime = 0;
cci->bg.runtime = 0;
+ cci->bg.aborted = false;
cci->bg.timer = timer_new_ms(QEMU_CLOCK_VIRTUAL,
bg_timercb, cci);
+ qemu_mutex_init(&cci->bg.lock);
memset(&cci->fw, 0, sizeof(cci->fw));
cci->fw.active_slot = 1;
cci->fw.slot[cci->fw.active_slot - 1] = true;
+ cci->initialized = true;
+}
+
+void cxl_destroy_cci(CXLCCI *cci)
+{
+ qemu_mutex_destroy(&cci->bg.lock);
+ cci->initialized = false;
}
static void cxl_copy_cci_commands(CXLCCI *cci, const struct cxl_cmd (*cxl_cmds)[256])
diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c
index 6fffa21ead..be670ae3f3 100644
--- a/hw/mem/cxl_type3.c
+++ b/hw/mem/cxl_type3.c
@@ -970,6 +970,7 @@ static void ct3_exit(PCIDevice *pci_dev)
cxl_doe_cdat_release(cxl_cstate);
msix_uninit_exclusive_bar(pci_dev);
g_free(regs->special_ops);
+ cxl_destroy_cci(&ct3d->cci);
if (ct3d->dc.host_dc) {
cxl_destroy_dc_regions(ct3d);
address_space_destroy(&ct3d->dc.host_dc_as);
@@ -1225,12 +1226,17 @@ static void ct3d_reset(DeviceState *dev)
* Bring up an endpoint to target with MCTP over VDM.
* This device is emulating an MLD with single LD for now.
*/
+ if (ct3d->vdm_fm_owned_ld_mctp_cci.initialized) {
+ cxl_destroy_cci(&ct3d->vdm_fm_owned_ld_mctp_cci);
+ }
cxl_initialize_t3_fm_owned_ld_mctpcci(&ct3d->vdm_fm_owned_ld_mctp_cci,
DEVICE(ct3d), DEVICE(ct3d),
512); /* Max payload made up */
+ if (ct3d->ld0_cci.initialized) {
+ cxl_destroy_cci(&ct3d->ld0_cci);
+ }
cxl_initialize_t3_ld_cci(&ct3d->ld0_cci, DEVICE(ct3d), DEVICE(ct3d),
512); /* Max payload made up */
-
}
static const Property ct3_props[] = {
--
2.43.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH qemu 2/8] hw/cxl: Support get/set mctp response payload size
2025-03-05 9:24 [PATCH qemu 0/8] hw/cxl: new features for 10.0 (possibly) Jonathan Cameron via
2025-03-05 9:24 ` [PATCH qemu 1/8] hw/cxl: Support aborting background commands Jonathan Cameron via
@ 2025-03-05 9:24 ` Jonathan Cameron via
2025-03-05 9:24 ` [PATCH qemu 3/8] hw/cxl/cxl-mailbox-utils: Add support for Media operations discovery commands cxl r3.2 (8.2.10.9.5.3) Jonathan Cameron via
` (5 subsequent siblings)
7 siblings, 0 replies; 17+ messages in thread
From: Jonathan Cameron via @ 2025-03-05 9:24 UTC (permalink / raw)
To: linux-cxl, qemu-devel, mst
Cc: linuxarm, fan.ni, Yuquan Wang, Arpit Kumar, Sweta Kumari,
Vinayak Holikatti, Davidlohr Bueso, Ajay Joshi
From: Davidlohr Bueso <dave@stgolabs.net>
Add Get/Set Response Message Limit commands.
Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>
Reviewed-by: Fan Ni <fan.ni@samsung.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
hw/cxl/cxl-mailbox-utils.c | 58 ++++++++++++++++++++++++++++++++++++--
1 file changed, 56 insertions(+), 2 deletions(-)
diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
index 4401f446d9..bd25df033a 100644
--- a/hw/cxl/cxl-mailbox-utils.c
+++ b/hw/cxl/cxl-mailbox-utils.c
@@ -7,6 +7,8 @@
* COPYING file in the top-level directory.
*/
+#include <math.h>
+
#include "qemu/osdep.h"
#include "hw/pci/msi.h"
#include "hw/pci/msix.h"
@@ -56,6 +58,8 @@ enum {
INFOSTAT = 0x00,
#define IS_IDENTIFY 0x1
#define BACKGROUND_OPERATION_STATUS 0x2
+ #define GET_RESPONSE_MSG_LIMIT 0x3
+ #define SET_RESPONSE_MSG_LIMIT 0x4
#define BACKGROUND_OPERATION_ABORT 0x5
EVENTS = 0x01,
#define GET_RECORDS 0x0
@@ -413,12 +417,58 @@ static CXLRetCode cmd_infostat_identify(const struct cxl_cmd *cmd,
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 */
+ is_identify->max_message_size = (uint8_t)log2(cci->payload_max);
*len_out = sizeof(*is_identify);
return CXL_MBOX_SUCCESS;
}
+/* CXL r3.1 section 8.2.9.1.3: Get Response Message Limit (Opcode 0003h) */
+static CXLRetCode cmd_get_response_msg_limit(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 rsp_limit;
+ } QEMU_PACKED *get_rsp_msg_limit = (void *)payload_out;
+ QEMU_BUILD_BUG_ON(sizeof(*get_rsp_msg_limit) != 1);
+
+ get_rsp_msg_limit->rsp_limit = (uint8_t)log2(cci->payload_max);
+
+ *len_out = sizeof(*get_rsp_msg_limit);
+ return CXL_MBOX_SUCCESS;
+}
+
+/* CXL r3.1 section 8.2.9.1.4: Set Response Message Limit (Opcode 0004h) */
+static CXLRetCode cmd_set_response_msg_limit(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 rsp_limit;
+ } QEMU_PACKED *in = (void *)payload_in;
+ QEMU_BUILD_BUG_ON(sizeof(*in) != 1);
+ struct {
+ uint8_t rsp_limit;
+ } QEMU_PACKED *out = (void *)payload_out;
+ QEMU_BUILD_BUG_ON(sizeof(*out) != 1);
+
+ if (in->rsp_limit < 8 || in->rsp_limit > 10) {
+ return CXL_MBOX_INVALID_INPUT;
+ }
+
+ cci->payload_max = 1 << in->rsp_limit;
+ out->rsp_limit = in->rsp_limit;
+
+ *len_out = sizeof(*out);
+ return CXL_MBOX_SUCCESS;
+}
+
static void cxl_set_dsp_active_bm(PCIBus *b, PCIDevice *d,
void *private)
{
@@ -3105,6 +3155,10 @@ void cxl_initialize_t3_ld_cci(CXLCCI *cci, DeviceState *d, DeviceState *intf,
static const struct cxl_cmd cxl_cmd_set_t3_fm_owned_ld_mctp[256][256] = {
[INFOSTAT][IS_IDENTIFY] = { "IDENTIFY", cmd_infostat_identify, 0, 0},
+ [INFOSTAT][GET_RESPONSE_MSG_LIMIT] = { "GET_RESPONSE_MSG_LIMIT",
+ cmd_get_response_msg_limit, 0, 0 },
+ [INFOSTAT][SET_RESPONSE_MSG_LIMIT] = { "SET_RESPONSE_MSG_LIMIT",
+ cmd_set_response_msg_limit, 1, 0 },
[LOGS][GET_SUPPORTED] = { "LOGS_GET_SUPPORTED", cmd_logs_get_supported, 0,
0 },
[LOGS][GET_LOG] = { "LOGS_GET_LOG", cmd_logs_get_log, 0x18, 0 },
--
2.43.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH qemu 3/8] hw/cxl/cxl-mailbox-utils: Add support for Media operations discovery commands cxl r3.2 (8.2.10.9.5.3)
2025-03-05 9:24 [PATCH qemu 0/8] hw/cxl: new features for 10.0 (possibly) Jonathan Cameron via
2025-03-05 9:24 ` [PATCH qemu 1/8] hw/cxl: Support aborting background commands Jonathan Cameron via
2025-03-05 9:24 ` [PATCH qemu 2/8] hw/cxl: Support get/set mctp response payload size Jonathan Cameron via
@ 2025-03-05 9:24 ` Jonathan Cameron via
2025-03-05 9:24 ` [PATCH qemu 4/8] hw/cxl: factor out calculation of sanitize duration from cmd_santize_overwrite Jonathan Cameron via
` (4 subsequent siblings)
7 siblings, 0 replies; 17+ messages in thread
From: Jonathan Cameron via @ 2025-03-05 9:24 UTC (permalink / raw)
To: linux-cxl, qemu-devel, mst
Cc: linuxarm, fan.ni, Yuquan Wang, Arpit Kumar, Sweta Kumari,
Vinayak Holikatti, Davidlohr Bueso, Ajay Joshi
From: Vinayak Holikatti <vinayak.kh@samsung.com>
CXL spec 3.2 section 8.2.10.9.5.3 describes media operations commands.
CXL devices supports media operations discovery command.
Signed-off-by: Vinayak Holikatti <vinayak.kh@samsung.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
hw/cxl/cxl-mailbox-utils.c | 125 +++++++++++++++++++++++++++++++++++++
1 file changed, 125 insertions(+)
diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
index bd25df033a..79b35d1405 100644
--- a/hw/cxl/cxl-mailbox-utils.c
+++ b/hw/cxl/cxl-mailbox-utils.c
@@ -89,6 +89,7 @@ enum {
SANITIZE = 0x44,
#define OVERWRITE 0x0
#define SECURE_ERASE 0x1
+ #define MEDIA_OPERATIONS 0x2
PERSISTENT_MEM = 0x45,
#define GET_SECURITY_STATE 0x0
MEDIA_AND_POISON = 0x43,
@@ -1705,6 +1706,126 @@ static CXLRetCode cmd_sanitize_overwrite(const struct cxl_cmd *cmd,
return CXL_MBOX_BG_STARTED;
}
+enum {
+ MEDIA_OP_CLASS_GENERAL = 0x0,
+ #define MEDIA_OP_GEN_SUBC_DISCOVERY 0x0
+ MEDIA_OP_CLASS_SANITIZE = 0x1,
+ #define MEDIA_OP_SAN_SUBC_SANITIZE 0x0
+ #define MEDIA_OP_SAN_SUBC_ZERO 0x1
+};
+
+struct media_op_supported_list_entry {
+ uint8_t media_op_class;
+ uint8_t media_op_subclass;
+};
+
+struct media_op_discovery_out_pl {
+ uint64_t dpa_range_granularity;
+ uint16_t total_supported_operations;
+ uint16_t num_of_supported_operations;
+ struct media_op_supported_list_entry entry[];
+} QEMU_PACKED;
+
+static const struct media_op_supported_list_entry media_op_matrix[] = {
+ { MEDIA_OP_CLASS_GENERAL, MEDIA_OP_GEN_SUBC_DISCOVERY },
+ { MEDIA_OP_CLASS_SANITIZE, MEDIA_OP_SAN_SUBC_SANITIZE },
+ { MEDIA_OP_CLASS_SANITIZE, MEDIA_OP_SAN_SUBC_ZERO },
+};
+
+static CXLRetCode media_operations_discovery(uint8_t *payload_in,
+ size_t len_in,
+ uint8_t *payload_out,
+ size_t *len_out)
+{
+ struct {
+ uint8_t media_operation_class;
+ uint8_t media_operation_subclass;
+ uint8_t rsvd[2];
+ uint32_t dpa_range_count;
+ struct {
+ uint16_t start_index;
+ uint16_t num_ops;
+ } discovery_osa;
+ } QEMU_PACKED *media_op_in_disc_pl = (void *)payload_in;
+ struct media_op_discovery_out_pl *media_out_pl =
+ (struct media_op_discovery_out_pl *)payload_out;
+ int num_ops, start_index, i;
+ int count = 0;
+
+ if (len_in < sizeof(*media_op_in_disc_pl)) {
+ return CXL_MBOX_INVALID_PAYLOAD_LENGTH;
+ }
+
+ num_ops = media_op_in_disc_pl->discovery_osa.num_ops;
+ start_index = media_op_in_disc_pl->discovery_osa.start_index;
+
+ /*
+ * As per spec CXL r3.2 8.2.10.9.5.3 dpa_range_count should be zero and
+ * start index should not exceed the total number of entries for discovery
+ * sub class command.
+ */
+ if (media_op_in_disc_pl->dpa_range_count ||
+ start_index > ARRAY_SIZE(media_op_matrix)) {
+ return CXL_MBOX_INVALID_INPUT;
+ }
+
+ media_out_pl->dpa_range_granularity = CXL_CACHE_LINE_SIZE;
+ media_out_pl->total_supported_operations =
+ ARRAY_SIZE(media_op_matrix);
+ if (num_ops > 0) {
+ for (i = start_index; i < start_index + num_ops; i++) {
+ media_out_pl->entry[count].media_op_class =
+ media_op_matrix[i].media_op_class;
+ media_out_pl->entry[count].media_op_subclass =
+ media_op_matrix[i].media_op_subclass;
+ count++;
+ if (count == num_ops) {
+ break;
+ }
+ }
+ }
+
+ media_out_pl->num_of_supported_operations = count;
+ *len_out = sizeof(*media_out_pl) + count * sizeof(*media_out_pl->entry);
+ return CXL_MBOX_SUCCESS;
+}
+
+static CXLRetCode cmd_media_operations(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 media_operation_class;
+ uint8_t media_operation_subclass;
+ uint8_t rsvd[2];
+ uint32_t dpa_range_count;
+ } QEMU_PACKED *media_op_in_common_pl = (void *)payload_in;
+ uint8_t media_op_cl = 0;
+ uint8_t media_op_subclass = 0;
+
+ if (len_in < sizeof(*media_op_in_common_pl)) {
+ return CXL_MBOX_INVALID_PAYLOAD_LENGTH;
+ }
+
+ media_op_cl = media_op_in_common_pl->media_operation_class;
+ media_op_subclass = media_op_in_common_pl->media_operation_subclass;
+
+ switch (media_op_cl) {
+ case MEDIA_OP_CLASS_GENERAL:
+ if (media_op_subclass != MEDIA_OP_GEN_SUBC_DISCOVERY) {
+ return CXL_MBOX_UNSUPPORTED;
+ }
+
+ return media_operations_discovery(payload_in, len_in, payload_out,
+ len_out);
+ default:
+ return CXL_MBOX_UNSUPPORTED;
+ }
+}
+
static CXLRetCode cmd_get_security_state(const struct cxl_cmd *cmd,
uint8_t *payload_in,
size_t len_in,
@@ -2850,6 +2971,10 @@ static const struct cxl_cmd cxl_cmd_set[256][256] = {
CXL_MBOX_SECURITY_STATE_CHANGE |
CXL_MBOX_BACKGROUND_OPERATION |
CXL_MBOX_BACKGROUND_OPERATION_ABORT)},
+ [SANITIZE][MEDIA_OPERATIONS] = { "MEDIA_OPERATIONS", cmd_media_operations,
+ ~0,
+ (CXL_MBOX_IMMEDIATE_DATA_CHANGE |
+ CXL_MBOX_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",
--
2.43.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH qemu 4/8] hw/cxl: factor out calculation of sanitize duration from cmd_santize_overwrite
2025-03-05 9:24 [PATCH qemu 0/8] hw/cxl: new features for 10.0 (possibly) Jonathan Cameron via
` (2 preceding siblings ...)
2025-03-05 9:24 ` [PATCH qemu 3/8] hw/cxl/cxl-mailbox-utils: Add support for Media operations discovery commands cxl r3.2 (8.2.10.9.5.3) Jonathan Cameron via
@ 2025-03-05 9:24 ` Jonathan Cameron via
2025-03-05 9:24 ` [PATCH qemu 5/8] hw/cxl/cxl-mailbox-utils: Media operations Sanitize and Write Zeros commands CXL r3.2(8.2.10.9.5.3) Jonathan Cameron via
` (3 subsequent siblings)
7 siblings, 0 replies; 17+ messages in thread
From: Jonathan Cameron via @ 2025-03-05 9:24 UTC (permalink / raw)
To: linux-cxl, qemu-devel, mst
Cc: linuxarm, fan.ni, Yuquan Wang, Arpit Kumar, Sweta Kumari,
Vinayak Holikatti, Davidlohr Bueso, Ajay Joshi
From: Vinayak Holikatti <vinayak.kh@samsung.com>
Move the code of calculation of sanitize duration into function
for usability by other sanitize routines
Estimate times based on:
https://pmem.io/documents/NVDIMM_DSM_Interface-V1.8.pdf
Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>
Signed-off-by: Vinayak Holikatti <vinayak.kh@samsung.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
hw/cxl/cxl-mailbox-utils.c | 61 ++++++++++++++++++++++----------------
1 file changed, 35 insertions(+), 26 deletions(-)
diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
index 79b35d1405..9f9d475678 100644
--- a/hw/cxl/cxl-mailbox-utils.c
+++ b/hw/cxl/cxl-mailbox-utils.c
@@ -1640,34 +1640,10 @@ static void __do_sanitization(CXLType3Dev *ct3d)
cxl_discard_all_event_records(&ct3d->cxl_dstate);
}
-/*
- * CXL r3.1 Section 8.2.9.9.5.1: Sanitize (Opcode 4400h)
- *
- * Once the Sanitize command has started successfully, the device shall be
- * placed in the media disabled state. If the command fails or is interrupted
- * by a reset or power failure, it shall remain in the media disabled state
- * until a successful Sanitize command has been completed. During this state:
- *
- * 1. Memory writes to the device will have no effect, and all memory reads
- * will return random values (no user data returned, even for locations that
- * the failed Sanitize operation didn’t sanitize yet).
- *
- * 2. Mailbox commands shall still be processed in the disabled state, except
- * that commands that access Sanitized areas shall fail with the Media Disabled
- * error code.
- */
-static CXLRetCode cmd_sanitize_overwrite(const struct cxl_cmd *cmd,
- uint8_t *payload_in,
- size_t len_in,
- uint8_t *payload_out,
- size_t *len_out,
- CXLCCI *cci)
+static int get_sanitize_duration(uint64_t total_mem)
{
- CXLType3Dev *ct3d = CXL_TYPE3(cci->d);
- uint64_t total_mem; /* in Mb */
- int secs;
+ int secs = 0;
- total_mem = (ct3d->cxl_dstate.vmem_size + ct3d->cxl_dstate.pmem_size) >> 20;
if (total_mem <= 512) {
secs = 4;
} else if (total_mem <= 1024) {
@@ -1696,6 +1672,39 @@ static CXLRetCode cmd_sanitize_overwrite(const struct cxl_cmd *cmd,
secs = 240 * 60; /* max 4 hrs */
}
+ return secs;
+}
+
+/*
+ * CXL r3.1 Section 8.2.9.9.5.1: Sanitize (Opcode 4400h)
+ *
+ * Once the Sanitize command has started successfully, the device shall be
+ * placed in the media disabled state. If the command fails or is interrupted
+ * by a reset or power failure, it shall remain in the media disabled state
+ * until a successful Sanitize command has been completed. During this state:
+ *
+ * 1. Memory writes to the device will have no effect, and all memory reads
+ * will return random values (no user data returned, even for locations that
+ * the failed Sanitize operation didn’t sanitize yet).
+ *
+ * 2. Mailbox commands shall still be processed in the disabled state, except
+ * that commands that access Sanitized areas shall fail with the Media Disabled
+ * error code.
+ */
+static CXLRetCode cmd_sanitize_overwrite(const struct cxl_cmd *cmd,
+ uint8_t *payload_in,
+ size_t len_in,
+ uint8_t *payload_out,
+ size_t *len_out,
+ CXLCCI *cci)
+{
+ CXLType3Dev *ct3d = CXL_TYPE3(cci->d);
+ uint64_t total_mem; /* in Mb */
+ int secs;
+
+ total_mem = (ct3d->cxl_dstate.vmem_size + ct3d->cxl_dstate.pmem_size) >> 20;
+ secs = get_sanitize_duration(total_mem);
+
/* EBUSY other bg cmds as of now */
cci->bg.runtime = secs * 1000UL;
*len_out = 0;
--
2.43.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH qemu 5/8] hw/cxl/cxl-mailbox-utils: Media operations Sanitize and Write Zeros commands CXL r3.2(8.2.10.9.5.3)
2025-03-05 9:24 [PATCH qemu 0/8] hw/cxl: new features for 10.0 (possibly) Jonathan Cameron via
` (3 preceding siblings ...)
2025-03-05 9:24 ` [PATCH qemu 4/8] hw/cxl: factor out calculation of sanitize duration from cmd_santize_overwrite Jonathan Cameron via
@ 2025-03-05 9:24 ` Jonathan Cameron via
2025-03-05 9:24 ` [PATCH qemu 6/8] hw/cxl/cxl-mailbox-utils: CXL CCI Get/Set alert config commands Jonathan Cameron via
` (2 subsequent siblings)
7 siblings, 0 replies; 17+ messages in thread
From: Jonathan Cameron via @ 2025-03-05 9:24 UTC (permalink / raw)
To: linux-cxl, qemu-devel, mst
Cc: linuxarm, fan.ni, Yuquan Wang, Arpit Kumar, Sweta Kumari,
Vinayak Holikatti, Davidlohr Bueso, Ajay Joshi
From: Vinayak Holikatti <vinayak.kh@samsung.com>
CXL spec 3.2 section 8.2.10.9.5.3 describes media operations commands.
CXL devices supports media operations Sanitize and Write zero command.
Signed-off-by: Vinayak Holikatti <vinayak.kh@samsung.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
include/hw/cxl/cxl_device.h | 4 +
hw/cxl/cxl-mailbox-utils.c | 204 ++++++++++++++++++++++++++++++++++++
2 files changed, 208 insertions(+)
diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h
index d21695507f..3ec7be3809 100644
--- a/include/hw/cxl/cxl_device.h
+++ b/include/hw/cxl/cxl_device.h
@@ -540,6 +540,8 @@ typedef struct CXLSetFeatureInfo {
size_t data_size;
} CXLSetFeatureInfo;
+struct CXLSanitizeInfo;
+
struct CXLType3Dev {
/* Private */
PCIDevice parent_obj;
@@ -606,6 +608,8 @@ struct CXLType3Dev {
uint8_t num_regions; /* 0-8 regions */
CXLDCRegion regions[DCD_MAX_NUM_REGION];
} dc;
+
+ struct CXLSanitizeInfo *media_op_sanitize;
};
#define TYPE_CXL_TYPE3 "cxl-type3"
diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
index 9f9d475678..2c6db70e5f 100644
--- a/hw/cxl/cxl-mailbox-utils.c
+++ b/hw/cxl/cxl-mailbox-utils.c
@@ -1715,6 +1715,131 @@ static CXLRetCode cmd_sanitize_overwrite(const struct cxl_cmd *cmd,
return CXL_MBOX_BG_STARTED;
}
+struct dpa_range_list_entry {
+ uint64_t starting_dpa;
+ uint64_t length;
+} QEMU_PACKED;
+
+struct CXLSanitizeInfo {
+ uint32_t dpa_range_count;
+ uint8_t fill_value;
+ struct dpa_range_list_entry dpa_range_list[];
+} QEMU_PACKED;
+
+static uint64_t get_vmr_size(CXLType3Dev *ct3d, MemoryRegion **vmr)
+{
+ MemoryRegion *mr;
+ if (ct3d->hostvmem) {
+ mr = host_memory_backend_get_memory(ct3d->hostvmem);
+ if (vmr) {
+ *vmr = mr;
+ }
+ return memory_region_size(mr);
+ }
+ return 0;
+}
+
+static uint64_t get_pmr_size(CXLType3Dev *ct3d, MemoryRegion **pmr)
+{
+ MemoryRegion *mr;
+ if (ct3d->hostpmem) {
+ mr = host_memory_backend_get_memory(ct3d->hostpmem);
+ if (pmr) {
+ *pmr = mr;
+ }
+ return memory_region_size(mr);
+ }
+ return 0;
+}
+
+static uint64_t get_dc_size(CXLType3Dev *ct3d, MemoryRegion **dc_mr)
+{
+ MemoryRegion *mr;
+ if (ct3d->dc.host_dc) {
+ mr = host_memory_backend_get_memory(ct3d->dc.host_dc);
+ if (dc_mr) {
+ *dc_mr = mr;
+ }
+ return memory_region_size(mr);
+ }
+ return 0;
+}
+
+static int validate_dpa_addr(CXLType3Dev *ct3d, uint64_t dpa_addr,
+ size_t length)
+{
+ uint64_t vmr_size, pmr_size, dc_size;
+
+ if ((dpa_addr % CXL_CACHE_LINE_SIZE) ||
+ (length % CXL_CACHE_LINE_SIZE) ||
+ (length <= 0)) {
+ return -EINVAL;
+ }
+
+ vmr_size = get_vmr_size(ct3d, NULL);
+ pmr_size = get_pmr_size(ct3d, NULL);
+ dc_size = get_dc_size(ct3d, NULL);
+
+ if (dpa_addr + length > vmr_size + pmr_size + dc_size) {
+ return -EINVAL;
+ }
+
+ if (dpa_addr > vmr_size + pmr_size) {
+ if (!ct3_test_region_block_backed(ct3d, dpa_addr, length)) {
+ return -ENODEV;
+ }
+ }
+
+ return 0;
+}
+
+static int sanitize_range(CXLType3Dev *ct3d, uint64_t dpa_addr, size_t length,
+ uint8_t fill_value)
+{
+
+ uint64_t vmr_size, pmr_size;
+ AddressSpace *as = NULL;
+ MemTxAttrs mem_attrs = {};
+
+ vmr_size = get_vmr_size(ct3d, NULL);
+ pmr_size = get_pmr_size(ct3d, NULL);
+
+ if (dpa_addr < vmr_size) {
+ as = &ct3d->hostvmem_as;
+ } else if (dpa_addr < vmr_size + pmr_size) {
+ as = &ct3d->hostpmem_as;
+ } else {
+ if (!ct3_test_region_block_backed(ct3d, dpa_addr, length)) {
+ return -ENODEV;
+ }
+ as = &ct3d->dc.host_dc_as;
+ }
+
+ return address_space_set(as, dpa_addr, fill_value, length, mem_attrs);
+}
+
+/* Perform the actual device zeroing */
+static void __do_sanitize(CXLType3Dev *ct3d)
+{
+ struct CXLSanitizeInfo *san_info = ct3d->media_op_sanitize;
+ int dpa_range_count = san_info->dpa_range_count;
+ int rc = 0;
+ int i;
+
+ for (i = 0; i < dpa_range_count; i++) {
+ rc = sanitize_range(ct3d, san_info->dpa_range_list[i].starting_dpa,
+ san_info->dpa_range_list[i].length,
+ san_info->fill_value);
+ if (rc) {
+ goto exit;
+ }
+ }
+exit:
+ g_free(ct3d->media_op_sanitize);
+ ct3d->media_op_sanitize = NULL;
+ return;
+}
+
enum {
MEDIA_OP_CLASS_GENERAL = 0x0,
#define MEDIA_OP_GEN_SUBC_DISCOVERY 0x0
@@ -1799,6 +1924,65 @@ static CXLRetCode media_operations_discovery(uint8_t *payload_in,
return CXL_MBOX_SUCCESS;
}
+static CXLRetCode media_operations_sanitize(CXLType3Dev *ct3d,
+ uint8_t *payload_in,
+ size_t len_in,
+ uint8_t *payload_out,
+ size_t *len_out,
+ uint8_t fill_value,
+ CXLCCI *cci)
+{
+ struct media_operations_sanitize {
+ uint8_t media_operation_class;
+ uint8_t media_operation_subclass;
+ uint8_t rsvd[2];
+ uint32_t dpa_range_count;
+ struct dpa_range_list_entry dpa_range_list[];
+ } QEMU_PACKED *media_op_in_sanitize_pl = (void *)payload_in;
+ uint32_t dpa_range_count = media_op_in_sanitize_pl->dpa_range_count;
+ uint64_t total_mem = 0;
+ size_t dpa_range_list_size;
+ int secs = 0, i;
+
+ if (dpa_range_count == 0) {
+ return CXL_MBOX_SUCCESS;
+ }
+
+ dpa_range_list_size = dpa_range_count * sizeof(struct dpa_range_list_entry);
+ if (len_in < (sizeof(*media_op_in_sanitize_pl) + dpa_range_list_size)) {
+ return CXL_MBOX_INVALID_PAYLOAD_LENGTH;
+ }
+
+ for (i = 0; i < dpa_range_count; i++) {
+ uint64_t start_dpa =
+ media_op_in_sanitize_pl->dpa_range_list[i].starting_dpa;
+ uint64_t length = media_op_in_sanitize_pl->dpa_range_list[i].length;
+
+ if (validate_dpa_addr(ct3d, start_dpa, length)) {
+ return CXL_MBOX_INVALID_INPUT;
+ }
+ total_mem += length;
+ }
+ ct3d->media_op_sanitize = g_malloc0(sizeof(struct CXLSanitizeInfo) +
+ dpa_range_list_size);
+
+ ct3d->media_op_sanitize->dpa_range_count = dpa_range_count;
+ ct3d->media_op_sanitize->fill_value = fill_value;
+ memcpy(ct3d->media_op_sanitize->dpa_range_list,
+ media_op_in_sanitize_pl->dpa_range_list,
+ dpa_range_list_size);
+ secs = get_sanitize_duration(total_mem >> 20);
+
+ /* EBUSY other bg cmds as of now */
+ cci->bg.runtime = secs * 1000UL;
+ *len_out = 0;
+ /*
+ * media op sanitize is targeted so no need to disable media or
+ * clear event logs
+ */
+ return CXL_MBOX_BG_STARTED;
+}
+
static CXLRetCode cmd_media_operations(const struct cxl_cmd *cmd,
uint8_t *payload_in,
size_t len_in,
@@ -1812,6 +1996,7 @@ static CXLRetCode cmd_media_operations(const struct cxl_cmd *cmd,
uint8_t rsvd[2];
uint32_t dpa_range_count;
} QEMU_PACKED *media_op_in_common_pl = (void *)payload_in;
+ CXLType3Dev *ct3d = CXL_TYPE3(cci->d);
uint8_t media_op_cl = 0;
uint8_t media_op_subclass = 0;
@@ -1830,6 +2015,19 @@ static CXLRetCode cmd_media_operations(const struct cxl_cmd *cmd,
return media_operations_discovery(payload_in, len_in, payload_out,
len_out);
+ case MEDIA_OP_CLASS_SANITIZE:
+ switch (media_op_subclass) {
+ case MEDIA_OP_SAN_SUBC_SANITIZE:
+ return media_operations_sanitize(ct3d, payload_in, len_in,
+ payload_out, len_out, 0xF,
+ cci);
+ case MEDIA_OP_SAN_SUBC_ZERO:
+ return media_operations_sanitize(ct3d, payload_in, len_in,
+ payload_out, len_out, 0,
+ cci);
+ default:
+ return CXL_MBOX_UNSUPPORTED;
+ }
default:
return CXL_MBOX_UNSUPPORTED;
}
@@ -3147,6 +3345,12 @@ static void bg_timercb(void *opaque)
cxl_dev_enable_media(&ct3d->cxl_dstate);
}
break;
+ case 0x4402: /* Media Operations sanitize */
+ {
+ CXLType3Dev *ct3d = CXL_TYPE3(cci->d);
+ __do_sanitize(ct3d);
+ }
+ break;
case 0x4304: /* scan media */
{
CXLType3Dev *ct3d = CXL_TYPE3(cci->d);
--
2.43.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH qemu 6/8] hw/cxl/cxl-mailbox-utils: CXL CCI Get/Set alert config commands
2025-03-05 9:24 [PATCH qemu 0/8] hw/cxl: new features for 10.0 (possibly) Jonathan Cameron via
` (4 preceding siblings ...)
2025-03-05 9:24 ` [PATCH qemu 5/8] hw/cxl/cxl-mailbox-utils: Media operations Sanitize and Write Zeros commands CXL r3.2(8.2.10.9.5.3) Jonathan Cameron via
@ 2025-03-05 9:24 ` Jonathan Cameron via
2025-03-05 9:24 ` [PATCH qemu 7/8] hw/cxl/cxl-mailbox-utils: Added support for Get Log Capabilities (Opcode 0402h) Jonathan Cameron via
2025-03-05 9:24 ` [PATCH qemu 8/8] docs/cxl: Add serial number for persistent-memdev Jonathan Cameron via
7 siblings, 0 replies; 17+ messages in thread
From: Jonathan Cameron via @ 2025-03-05 9:24 UTC (permalink / raw)
To: linux-cxl, qemu-devel, mst
Cc: linuxarm, fan.ni, Yuquan Wang, Arpit Kumar, Sweta Kumari,
Vinayak Holikatti, Davidlohr Bueso, Ajay Joshi
From: Sweta Kumari <s5.kumari@samsung.com>
1) get alert configuration(Opcode 4201h)
2) set alert configuration(Opcode 4202h)
Signed-off-by: Sweta Kumari <s5.kumari@samsung.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
include/hw/cxl/cxl_device.h | 15 ++++++
hw/cxl/cxl-mailbox-utils.c | 105 ++++++++++++++++++++++++++++++++++++
hw/mem/cxl_type3.c | 14 +++++
3 files changed, 134 insertions(+)
diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h
index 3ec7be3809..ed6cd50c67 100644
--- a/include/hw/cxl/cxl_device.h
+++ b/include/hw/cxl/cxl_device.h
@@ -542,6 +542,19 @@ typedef struct CXLSetFeatureInfo {
struct CXLSanitizeInfo;
+typedef struct CXLAlertConfig {
+ uint8_t valid_alerts;
+ uint8_t enable_alerts;
+ uint8_t life_used_crit_alert_thresh;
+ uint8_t life_used_warn_thresh;
+ uint16_t over_temp_crit_alert_thresh;
+ uint16_t under_temp_crit_alert_thresh;
+ uint16_t over_temp_warn_thresh;
+ uint16_t under_temp_warn_thresh;
+ uint16_t cor_vmem_err_warn_thresh;
+ uint16_t cor_pmem_err_warn_thresh;
+} QEMU_PACKED CXLAlertConfig;
+
struct CXLType3Dev {
/* Private */
PCIDevice parent_obj;
@@ -563,6 +576,8 @@ struct CXLType3Dev {
CXLCCI vdm_fm_owned_ld_mctp_cci;
CXLCCI ld0_cci;
+ CXLAlertConfig alert_config;
+
/* PCIe link characteristics */
PCIExpLinkSpeed speed;
PCIExpLinkWidth width;
diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
index 2c6db70e5f..299f232f26 100644
--- a/hw/cxl/cxl-mailbox-utils.c
+++ b/hw/cxl/cxl-mailbox-utils.c
@@ -28,6 +28,11 @@
#define CXL_DC_EVENT_LOG_SIZE 8
#define CXL_NUM_EXTENTS_SUPPORTED 512
#define CXL_NUM_TAGS_SUPPORTED 0
+#define CXL_ALERTS_LIFE_USED_WARN_THRESH (1 << 0)
+#define CXL_ALERTS_OVER_TEMP_WARN_THRESH (1 << 1)
+#define CXL_ALERTS_UNDER_TEMP_WARN_THRESH (1 << 2)
+#define CXL_ALERTS_COR_VMEM_ERR_WARN_THRESH (1 << 3)
+#define CXL_ALERTS_COR_PMEM_ERR_WARN_THRESH (1 << 4)
/*
* How to add a new command, example. The command set FOO, with cmd BAR.
@@ -86,6 +91,9 @@ enum {
#define GET_PARTITION_INFO 0x0
#define GET_LSA 0x2
#define SET_LSA 0x3
+ HEALTH_INFO_ALERTS = 0x42,
+ #define GET_ALERT_CONFIG 0x1
+ #define SET_ALERT_CONFIG 0x2
SANITIZE = 0x44,
#define OVERWRITE 0x0
#define SECURE_ERASE 0x1
@@ -1610,6 +1618,97 @@ static CXLRetCode cmd_ccls_set_lsa(const struct cxl_cmd *cmd,
return CXL_MBOX_SUCCESS;
}
+/* CXL r3.2 Section 8.2.10.9.3.2 Get Alert Configuration (Opcode 4201h) */
+static CXLRetCode cmd_get_alert_config(const struct cxl_cmd *cmd,
+ uint8_t *payload_in,
+ size_t len_in,
+ uint8_t *payload_out,
+ size_t *len_out,
+ CXLCCI *cci)
+{
+ CXLType3Dev *ct3d = CXL_TYPE3(cci->d);
+ CXLAlertConfig *out = (CXLAlertConfig *)payload_out;
+
+ memcpy(out, &ct3d->alert_config, sizeof(ct3d->alert_config));
+ *len_out = sizeof(ct3d->alert_config);
+
+ return CXL_MBOX_SUCCESS;
+}
+
+/* CXL r3.2 Section 8.2.10.9.3.3 Set Alert Configuration (Opcode 4202h) */
+static CXLRetCode cmd_set_alert_config(const struct cxl_cmd *cmd,
+ uint8_t *payload_in,
+ size_t len_in,
+ uint8_t *payload_out,
+ size_t *len_out,
+ CXLCCI *cci)
+{
+ CXLType3Dev *ct3d = CXL_TYPE3(cci->d);
+ CXLAlertConfig *alert_config = &ct3d->alert_config;
+ struct {
+ uint8_t valid_alert_actions;
+ uint8_t enable_alert_actions;
+ uint8_t life_used_warn_thresh;
+ uint8_t rsvd;
+ uint16_t over_temp_warn_thresh;
+ uint16_t under_temp_warn_thresh;
+ uint16_t cor_vmem_err_warn_thresh;
+ uint16_t cor_pmem_err_warn_thresh;
+ } QEMU_PACKED *in = (void *)payload_in;
+
+ if (in->valid_alert_actions & CXL_ALERTS_LIFE_USED_WARN_THRESH) {
+ /*
+ * CXL r3.2 Table 8-149 The life used warning threshold shall be
+ * less than the life used critical alert value.
+ */
+ if (in->life_used_warn_thresh >=
+ alert_config->life_used_crit_alert_thresh) {
+ return CXL_MBOX_INVALID_INPUT;
+ }
+ alert_config->life_used_warn_thresh = in->life_used_warn_thresh;
+ alert_config->enable_alerts |= CXL_ALERTS_LIFE_USED_WARN_THRESH;
+ }
+
+ if (in->valid_alert_actions & CXL_ALERTS_OVER_TEMP_WARN_THRESH) {
+ /*
+ * CXL r3.2 Table 8-149 The Device Over-Temperature Warning Threshold
+ * shall be less than the the Device Over-Temperature Critical
+ * Alert Threshold.
+ */
+ if (in->over_temp_warn_thresh >=
+ alert_config->over_temp_crit_alert_thresh) {
+ return CXL_MBOX_INVALID_INPUT;
+ }
+ alert_config->over_temp_warn_thresh = in->over_temp_warn_thresh;
+ alert_config->enable_alerts |= CXL_ALERTS_OVER_TEMP_WARN_THRESH;
+ }
+
+ if (in->valid_alert_actions & CXL_ALERTS_UNDER_TEMP_WARN_THRESH) {
+ /*
+ * CXL r3.2 Table 8-149 The Device Under-Temperature Warning Threshold
+ * shall be higher than the the Device Under-Temperature Critical
+ * Alert Threshold.
+ */
+ if (in->under_temp_warn_thresh <=
+ alert_config->under_temp_crit_alert_thresh) {
+ return CXL_MBOX_INVALID_INPUT;
+ }
+ alert_config->under_temp_warn_thresh = in->under_temp_warn_thresh;
+ alert_config->enable_alerts |= CXL_ALERTS_UNDER_TEMP_WARN_THRESH;
+ }
+
+ if (in->valid_alert_actions & CXL_ALERTS_COR_VMEM_ERR_WARN_THRESH) {
+ alert_config->cor_vmem_err_warn_thresh = in->cor_vmem_err_warn_thresh;
+ alert_config->enable_alerts |= CXL_ALERTS_COR_VMEM_ERR_WARN_THRESH;
+ }
+
+ if (in->valid_alert_actions & CXL_ALERTS_COR_PMEM_ERR_WARN_THRESH) {
+ alert_config->cor_pmem_err_warn_thresh = in->cor_pmem_err_warn_thresh;
+ alert_config->enable_alerts |= CXL_ALERTS_COR_PMEM_ERR_WARN_THRESH;
+ }
+ return CXL_MBOX_SUCCESS;
+}
+
/* Perform the actual device zeroing */
static void __do_sanitization(CXLType3Dev *ct3d)
{
@@ -3173,6 +3272,12 @@ static const struct cxl_cmd cxl_cmd_set[256][256] = {
[CCLS][GET_LSA] = { "CCLS_GET_LSA", cmd_ccls_get_lsa, 8, 0 },
[CCLS][SET_LSA] = { "CCLS_SET_LSA", cmd_ccls_set_lsa,
~0, CXL_MBOX_IMMEDIATE_CONFIG_CHANGE | CXL_MBOX_IMMEDIATE_DATA_CHANGE },
+ [HEALTH_INFO_ALERTS][GET_ALERT_CONFIG] = {
+ "HEALTH_INFO_ALERTS_GET_ALERT_CONFIG",
+ cmd_get_alert_config, 0, 0 },
+ [HEALTH_INFO_ALERTS][SET_ALERT_CONFIG] = {
+ "HEALTH_INFO_ALERTS_SET_ALERT_CONFIG",
+ cmd_set_alert_config, 12, CXL_MBOX_IMMEDIATE_POLICY_CHANGE },
[SANITIZE][OVERWRITE] = { "SANITIZE_OVERWRITE", cmd_sanitize_overwrite, 0,
(CXL_MBOX_IMMEDIATE_DATA_CHANGE |
CXL_MBOX_SECURITY_STATE_CHANGE |
diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c
index be670ae3f3..73845dd50d 100644
--- a/hw/mem/cxl_type3.c
+++ b/hw/mem/cxl_type3.c
@@ -843,6 +843,19 @@ static DOEProtocol doe_cdat_prot[] = {
{ }
};
+/* Initialize CXL device alerts with default threshold values. */
+static void init_alert_config(CXLType3Dev *ct3d)
+{
+ ct3d->alert_config = (CXLAlertConfig) {
+ .life_used_crit_alert_thresh = 75,
+ .life_used_warn_thresh = 40,
+ .over_temp_crit_alert_thresh = 35,
+ .under_temp_crit_alert_thresh = 10,
+ .over_temp_warn_thresh = 25,
+ .under_temp_warn_thresh = 20
+ };
+}
+
static void ct3_realize(PCIDevice *pci_dev, Error **errp)
{
ERRP_GUARD();
@@ -910,6 +923,7 @@ static void ct3_realize(PCIDevice *pci_dev, Error **errp)
goto err_msix_uninit;
}
+ init_alert_config(ct3d);
pcie_cap_deverr_init(pci_dev);
/* Leave a bit of room for expansion */
rc = pcie_aer_init(pci_dev, PCI_ERR_VER, 0x200, PCI_ERR_SIZEOF, errp);
--
2.43.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH qemu 7/8] hw/cxl/cxl-mailbox-utils: Added support for Get Log Capabilities (Opcode 0402h)
2025-03-05 9:24 [PATCH qemu 0/8] hw/cxl: new features for 10.0 (possibly) Jonathan Cameron via
` (5 preceding siblings ...)
2025-03-05 9:24 ` [PATCH qemu 6/8] hw/cxl/cxl-mailbox-utils: CXL CCI Get/Set alert config commands Jonathan Cameron via
@ 2025-03-05 9:24 ` Jonathan Cameron via
2025-05-12 8:42 ` Michael S. Tsirkin
2025-03-05 9:24 ` [PATCH qemu 8/8] docs/cxl: Add serial number for persistent-memdev Jonathan Cameron via
7 siblings, 1 reply; 17+ messages in thread
From: Jonathan Cameron via @ 2025-03-05 9:24 UTC (permalink / raw)
To: linux-cxl, qemu-devel, mst
Cc: linuxarm, fan.ni, Yuquan Wang, Arpit Kumar, Sweta Kumari,
Vinayak Holikatti, Davidlohr Bueso, Ajay Joshi
From: Arpit Kumar <arpit1.kumar@samsung.com>
CXL spec 3.2 section 8.2.10.5.3 describes Get Log Capabilities.
It provides log capabilities supported by specified log.
Signed-off-by: Arpit Kumar <arpit1.kumar@samsung.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
include/hw/cxl/cxl_device.h | 20 ++++++++++++++++
include/hw/cxl/cxl_mailbox.h | 5 ++++
hw/cxl/cxl-mailbox-utils.c | 45 ++++++++++++++++++++++++++++++++++++
3 files changed, 70 insertions(+)
diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h
index ed6cd50c67..87a376c982 100644
--- a/include/hw/cxl/cxl_device.h
+++ b/include/hw/cxl/cxl_device.h
@@ -133,6 +133,18 @@ typedef enum {
CXL_MBOX_MAX = 0x20
} CXLRetCode;
+/* types of logs */
+typedef enum {
+ CXL_LOG_COMMAND_EFFECT,
+ CXL_LOG_VENDOR_DEBUG,
+ CXL_LOG_COMPONENT_STATE_DUMP,
+ CXL_LOG_ERROR_CHECK_SCRUB,
+ CXL_LOG_MEDIA_TEST_CAPABILITY,
+ CXL_LOG_MEDIA_TEST_RESULTS_SHORT,
+ CXL_LOG_MEDIA_TEST_RESULTS_LONG,
+ MAX_LOG_TYPE
+} CXLLogType;
+
typedef struct CXLCCI CXLCCI;
typedef struct cxl_device_state CXLDeviceState;
struct cxl_cmd;
@@ -163,6 +175,11 @@ typedef struct CXLEventLog {
QSIMPLEQ_HEAD(, CXLEvent) events;
} CXLEventLog;
+typedef struct CXLLogCapabilities {
+ uint32_t param_flags;
+ QemuUUID uuid;
+} CXLLogCapabilities;
+
typedef struct CXLCCI {
struct cxl_cmd cxl_cmd_set[256][256];
struct cel_log {
@@ -171,6 +188,9 @@ typedef struct CXLCCI {
} cel_log[1 << 16];
size_t cel_size;
+ /* get log capabilities */
+ const CXLLogCapabilities *supported_log_cap;
+
/* background command handling (times in ms) */
struct {
uint16_t opcode;
diff --git a/include/hw/cxl/cxl_mailbox.h b/include/hw/cxl/cxl_mailbox.h
index 9008402d1c..8e1c7c5f15 100644
--- a/include/hw/cxl/cxl_mailbox.h
+++ b/include/hw/cxl/cxl_mailbox.h
@@ -16,4 +16,9 @@
#define CXL_MBOX_BACKGROUND_OPERATION (1 << 6)
#define CXL_MBOX_BACKGROUND_OPERATION_ABORT (1 << 7)
+#define CXL_LOG_CAP_CLEAR_SUPPORTED (1 << 0)
+#define CXL_LOG_CAP_POPULATE_SUPPORTED (1 << 1)
+#define CXL_LOG_CAP_AUTO_POPULATE_SUPPORTED (1 << 2)
+#define CXL_LOG_CAP_PERSISTENT_COLD_RESET_SUPPORTED (1 << 3)
+
#endif
diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
index 299f232f26..f35fc4f112 100644
--- a/hw/cxl/cxl-mailbox-utils.c
+++ b/hw/cxl/cxl-mailbox-utils.c
@@ -81,6 +81,7 @@ enum {
LOGS = 0x04,
#define GET_SUPPORTED 0x0
#define GET_LOG 0x1
+ #define GET_LOG_CAPABILITIES 0x2
FEATURES = 0x05,
#define GET_SUPPORTED 0x0
#define GET_FEATURE 0x1
@@ -1068,6 +1069,43 @@ static CXLRetCode cmd_logs_get_log(const struct cxl_cmd *cmd,
return CXL_MBOX_SUCCESS;
}
+static const struct CXLLogCapabilities *find_log_index(QemuUUID *uuid, CXLCCI *cci)
+{
+ for (int i = CXL_LOG_COMMAND_EFFECT; i < MAX_LOG_TYPE; i++) {
+ if (qemu_uuid_is_equal(uuid,
+ &cci->supported_log_cap[i].uuid)) {
+ return &cci->supported_log_cap[i];
+ }
+ }
+ return NULL;
+}
+
+/* CXL r3.2 Section 8.2.10.5.3: Get Log Capabilities (Opcode 0402h) */
+static CXLRetCode cmd_logs_get_log_capabilities(const struct cxl_cmd *cmd,
+ uint8_t *payload_in,
+ size_t len_in,
+ uint8_t *payload_out,
+ size_t *len_out,
+ CXLCCI *cci)
+{
+ const CXLLogCapabilities *cap;
+ struct {
+ QemuUUID uuid;
+ } QEMU_PACKED QEMU_ALIGNED(8) *get_log_capabilities_in = (void *)payload_in;
+
+ uint32_t *get_log_capabilities_out = (uint32_t *)payload_out;
+
+ cap = find_log_index(&get_log_capabilities_in->uuid, cci);
+ if (!cap) {
+ return CXL_MBOX_INVALID_LOG;
+ }
+
+ memcpy(get_log_capabilities_out, &cap->param_flags,
+ sizeof(cap->param_flags));
+ *len_out = sizeof(*get_log_capabilities_out);
+ return CXL_MBOX_SUCCESS;
+}
+
/* CXL r3.1 section 8.2.9.6: Features */
/*
* Get Supported Features output payload
@@ -3253,6 +3291,8 @@ static const struct cxl_cmd cxl_cmd_set[256][256] = {
[LOGS][GET_SUPPORTED] = { "LOGS_GET_SUPPORTED", cmd_logs_get_supported,
0, 0 },
[LOGS][GET_LOG] = { "LOGS_GET_LOG", cmd_logs_get_log, 0x18, 0 },
+ [LOGS][GET_LOG_CAPABILITIES] = { "LOGS_GET_LOG_CAPABILITIES",
+ cmd_logs_get_log_capabilities, 0x10, 0 },
[FEATURES][GET_SUPPORTED] = { "FEATURES_GET_SUPPORTED",
cmd_features_get_supported, 0x8, 0 },
[FEATURES][GET_FEATURE] = { "FEATURES_GET_FEATURE",
@@ -3512,10 +3552,15 @@ static void cxl_rebuild_cel(CXLCCI *cci)
}
}
+static const struct CXLLogCapabilities cxl_get_log_cap[MAX_LOG_TYPE] = {
+ [CXL_LOG_COMMAND_EFFECT] = { .param_flags = 0, .uuid = cel_uuid },
+};
+
void cxl_init_cci(CXLCCI *cci, size_t payload_max)
{
cci->payload_max = payload_max;
cxl_rebuild_cel(cci);
+ cci->supported_log_cap = cxl_get_log_cap;
cci->bg.complete_pct = 0;
cci->bg.starttime = 0;
--
2.43.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH qemu 8/8] docs/cxl: Add serial number for persistent-memdev
2025-03-05 9:24 [PATCH qemu 0/8] hw/cxl: new features for 10.0 (possibly) Jonathan Cameron via
` (6 preceding siblings ...)
2025-03-05 9:24 ` [PATCH qemu 7/8] hw/cxl/cxl-mailbox-utils: Added support for Get Log Capabilities (Opcode 0402h) Jonathan Cameron via
@ 2025-03-05 9:24 ` Jonathan Cameron via
7 siblings, 0 replies; 17+ messages in thread
From: Jonathan Cameron via @ 2025-03-05 9:24 UTC (permalink / raw)
To: linux-cxl, qemu-devel, mst
Cc: linuxarm, fan.ni, Yuquan Wang, Arpit Kumar, Sweta Kumari,
Vinayak Holikatti, Davidlohr Bueso, Ajay Joshi
From: Yuquan Wang <wangyuquan1236@phytium.com.cn>
Add serial number parameter in the cxl persistent examples.
Signed-off-by: Yuquan Wang <wangyuquan1236@phytium.com.cn>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
docs/system/devices/cxl.rst | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/docs/system/devices/cxl.rst b/docs/system/devices/cxl.rst
index 882b036f5e..e307caf3f8 100644
--- a/docs/system/devices/cxl.rst
+++ b/docs/system/devices/cxl.rst
@@ -308,7 +308,7 @@ A very simple setup with just one directly attached CXL Type 3 Persistent Memory
-object memory-backend-file,id=cxl-lsa1,share=on,mem-path=/tmp/lsa.raw,size=256M \
-device pxb-cxl,bus_nr=12,bus=pcie.0,id=cxl.1 \
-device cxl-rp,port=0,bus=cxl.1,id=root_port13,chassis=0,slot=2 \
- -device cxl-type3,bus=root_port13,persistent-memdev=cxl-mem1,lsa=cxl-lsa1,id=cxl-pmem0 \
+ -device cxl-type3,bus=root_port13,persistent-memdev=cxl-mem1,lsa=cxl-lsa1,id=cxl-pmem0,sn=0x1 \
-M cxl-fmw.0.targets.0=cxl.1,cxl-fmw.0.size=4G
A very simple setup with just one directly attached CXL Type 3 Volatile Memory device::
@@ -349,13 +349,13 @@ the CXL Type3 device directly attached (no switches).::
-device pxb-cxl,bus_nr=12,bus=pcie.0,id=cxl.1 \
-device pxb-cxl,bus_nr=222,bus=pcie.0,id=cxl.2 \
-device cxl-rp,port=0,bus=cxl.1,id=root_port13,chassis=0,slot=2 \
- -device cxl-type3,bus=root_port13,persistent-memdev=cxl-mem1,lsa=cxl-lsa1,id=cxl-pmem0 \
+ -device cxl-type3,bus=root_port13,persistent-memdev=cxl-mem1,lsa=cxl-lsa1,id=cxl-pmem0,sn=0x1 \
-device cxl-rp,port=1,bus=cxl.1,id=root_port14,chassis=0,slot=3 \
- -device cxl-type3,bus=root_port14,persistent-memdev=cxl-mem2,lsa=cxl-lsa2,id=cxl-pmem1 \
+ -device cxl-type3,bus=root_port14,persistent-memdev=cxl-mem2,lsa=cxl-lsa2,id=cxl-pmem1,sn=0x2 \
-device cxl-rp,port=0,bus=cxl.2,id=root_port15,chassis=0,slot=5 \
- -device cxl-type3,bus=root_port15,persistent-memdev=cxl-mem3,lsa=cxl-lsa3,id=cxl-pmem2 \
+ -device cxl-type3,bus=root_port15,persistent-memdev=cxl-mem3,lsa=cxl-lsa3,id=cxl-pmem2,sn=0x3 \
-device cxl-rp,port=1,bus=cxl.2,id=root_port16,chassis=0,slot=6 \
- -device cxl-type3,bus=root_port16,persistent-memdev=cxl-mem4,lsa=cxl-lsa4,id=cxl-pmem3 \
+ -device cxl-type3,bus=root_port16,persistent-memdev=cxl-mem4,lsa=cxl-lsa4,id=cxl-pmem3,sn=0x4 \
-M cxl-fmw.0.targets.0=cxl.1,cxl-fmw.0.targets.1=cxl.2,cxl-fmw.0.size=4G,cxl-fmw.0.interleave-granularity=8k
An example of 4 devices below a switch suitable for 1, 2 or 4 way interleave::
@@ -375,13 +375,13 @@ An example of 4 devices below a switch suitable for 1, 2 or 4 way interleave::
-device cxl-rp,port=1,bus=cxl.1,id=root_port1,chassis=0,slot=1 \
-device cxl-upstream,bus=root_port0,id=us0 \
-device cxl-downstream,port=0,bus=us0,id=swport0,chassis=0,slot=4 \
- -device cxl-type3,bus=swport0,persistent-memdev=cxl-mem0,lsa=cxl-lsa0,id=cxl-pmem0 \
+ -device cxl-type3,bus=swport0,persistent-memdev=cxl-mem0,lsa=cxl-lsa0,id=cxl-pmem0,sn=0x1 \
-device cxl-downstream,port=1,bus=us0,id=swport1,chassis=0,slot=5 \
- -device cxl-type3,bus=swport1,persistent-memdev=cxl-mem1,lsa=cxl-lsa1,id=cxl-pmem1 \
+ -device cxl-type3,bus=swport1,persistent-memdev=cxl-mem1,lsa=cxl-lsa1,id=cxl-pmem1,sn=0x2 \
-device cxl-downstream,port=2,bus=us0,id=swport2,chassis=0,slot=6 \
- -device cxl-type3,bus=swport2,persistent-memdev=cxl-mem2,lsa=cxl-lsa2,id=cxl-pmem2 \
+ -device cxl-type3,bus=swport2,persistent-memdev=cxl-mem2,lsa=cxl-lsa2,id=cxl-pmem2,sn=0x3 \
-device cxl-downstream,port=3,bus=us0,id=swport3,chassis=0,slot=7 \
- -device cxl-type3,bus=swport3,persistent-memdev=cxl-mem3,lsa=cxl-lsa3,id=cxl-pmem3 \
+ -device cxl-type3,bus=swport3,persistent-memdev=cxl-mem3,lsa=cxl-lsa3,id=cxl-pmem3,sn=0x4 \
-M cxl-fmw.0.targets.0=cxl.1,cxl-fmw.0.size=4G,cxl-fmw.0.interleave-granularity=4k
Deprecations
--
2.43.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH qemu 7/8] hw/cxl/cxl-mailbox-utils: Added support for Get Log Capabilities (Opcode 0402h)
2025-03-05 9:24 ` [PATCH qemu 7/8] hw/cxl/cxl-mailbox-utils: Added support for Get Log Capabilities (Opcode 0402h) Jonathan Cameron via
@ 2025-05-12 8:42 ` Michael S. Tsirkin
2025-05-12 10:14 ` Jonathan Cameron via
2025-05-12 13:37 ` Michael S. Tsirkin
0 siblings, 2 replies; 17+ messages in thread
From: Michael S. Tsirkin @ 2025-05-12 8:42 UTC (permalink / raw)
To: Jonathan Cameron
Cc: linux-cxl, qemu-devel, linuxarm, fan.ni, Yuquan Wang, Arpit Kumar,
Sweta Kumari, Vinayak Holikatti, Davidlohr Bueso, Ajay Joshi
On Wed, Mar 05, 2025 at 09:24:58AM +0000, Jonathan Cameron wrote:
> From: Arpit Kumar <arpit1.kumar@samsung.com>
>
> CXL spec 3.2 section 8.2.10.5.3 describes Get Log Capabilities.
> It provides log capabilities supported by specified log.
>
> Signed-off-by: Arpit Kumar <arpit1.kumar@samsung.com>
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
> include/hw/cxl/cxl_device.h | 20 ++++++++++++++++
> include/hw/cxl/cxl_mailbox.h | 5 ++++
> hw/cxl/cxl-mailbox-utils.c | 45 ++++++++++++++++++++++++++++++++++++
> 3 files changed, 70 insertions(+)
>
> diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h
> index ed6cd50c67..87a376c982 100644
> --- a/include/hw/cxl/cxl_device.h
> +++ b/include/hw/cxl/cxl_device.h
> @@ -133,6 +133,18 @@ typedef enum {
> CXL_MBOX_MAX = 0x20
> } CXLRetCode;
>
> +/* types of logs */
> +typedef enum {
> + CXL_LOG_COMMAND_EFFECT,
> + CXL_LOG_VENDOR_DEBUG,
> + CXL_LOG_COMPONENT_STATE_DUMP,
> + CXL_LOG_ERROR_CHECK_SCRUB,
> + CXL_LOG_MEDIA_TEST_CAPABILITY,
> + CXL_LOG_MEDIA_TEST_RESULTS_SHORT,
> + CXL_LOG_MEDIA_TEST_RESULTS_LONG,
> + MAX_LOG_TYPE
> +} CXLLogType;
> +
> typedef struct CXLCCI CXLCCI;
> typedef struct cxl_device_state CXLDeviceState;
> struct cxl_cmd;
> @@ -163,6 +175,11 @@ typedef struct CXLEventLog {
> QSIMPLEQ_HEAD(, CXLEvent) events;
> } CXLEventLog;
>
> +typedef struct CXLLogCapabilities {
> + uint32_t param_flags;
> + QemuUUID uuid;
> +} CXLLogCapabilities;
> +
> typedef struct CXLCCI {
> struct cxl_cmd cxl_cmd_set[256][256];
> struct cel_log {
> @@ -171,6 +188,9 @@ typedef struct CXLCCI {
> } cel_log[1 << 16];
> size_t cel_size;
>
> + /* get log capabilities */
> + const CXLLogCapabilities *supported_log_cap;
> +
> /* background command handling (times in ms) */
> struct {
> uint16_t opcode;
> diff --git a/include/hw/cxl/cxl_mailbox.h b/include/hw/cxl/cxl_mailbox.h
> index 9008402d1c..8e1c7c5f15 100644
> --- a/include/hw/cxl/cxl_mailbox.h
> +++ b/include/hw/cxl/cxl_mailbox.h
> @@ -16,4 +16,9 @@
> #define CXL_MBOX_BACKGROUND_OPERATION (1 << 6)
> #define CXL_MBOX_BACKGROUND_OPERATION_ABORT (1 << 7)
>
> +#define CXL_LOG_CAP_CLEAR_SUPPORTED (1 << 0)
> +#define CXL_LOG_CAP_POPULATE_SUPPORTED (1 << 1)
> +#define CXL_LOG_CAP_AUTO_POPULATE_SUPPORTED (1 << 2)
> +#define CXL_LOG_CAP_PERSISTENT_COLD_RESET_SUPPORTED (1 << 3)
> +
> #endif
> diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
> index 299f232f26..f35fc4f112 100644
> --- a/hw/cxl/cxl-mailbox-utils.c
> +++ b/hw/cxl/cxl-mailbox-utils.c
> @@ -81,6 +81,7 @@ enum {
> LOGS = 0x04,
> #define GET_SUPPORTED 0x0
> #define GET_LOG 0x1
> + #define GET_LOG_CAPABILITIES 0x2
> FEATURES = 0x05,
> #define GET_SUPPORTED 0x0
> #define GET_FEATURE 0x1
> @@ -1068,6 +1069,43 @@ static CXLRetCode cmd_logs_get_log(const struct cxl_cmd *cmd,
> return CXL_MBOX_SUCCESS;
> }
>
> +static const struct CXLLogCapabilities *find_log_index(QemuUUID *uuid, CXLCCI *cci)
> +{
> + for (int i = CXL_LOG_COMMAND_EFFECT; i < MAX_LOG_TYPE; i++) {
> + if (qemu_uuid_is_equal(uuid,
> + &cci->supported_log_cap[i].uuid)) {
> + return &cci->supported_log_cap[i];
> + }
> + }
> + return NULL;
> +}
> +
> +/* CXL r3.2 Section 8.2.10.5.3: Get Log Capabilities (Opcode 0402h) */
> +static CXLRetCode cmd_logs_get_log_capabilities(const struct cxl_cmd *cmd,
> + uint8_t *payload_in,
> + size_t len_in,
> + uint8_t *payload_out,
> + size_t *len_out,
> + CXLCCI *cci)
> +{
> + const CXLLogCapabilities *cap;
> + struct {
> + QemuUUID uuid;
> + } QEMU_PACKED QEMU_ALIGNED(8) *get_log_capabilities_in = (void *)payload_in;
> +
> + uint32_t *get_log_capabilities_out = (uint32_t *)payload_out;
> +
> + cap = find_log_index(&get_log_capabilities_in->uuid, cci);
> + if (!cap) {
> + return CXL_MBOX_INVALID_LOG;
> + }
> +
> + memcpy(get_log_capabilities_out, &cap->param_flags,
> + sizeof(cap->param_flags));
> + *len_out = sizeof(*get_log_capabilities_out);
> + return CXL_MBOX_SUCCESS;
> +}
> +
> /* CXL r3.1 section 8.2.9.6: Features */
> /*
> * Get Supported Features output payload
> @@ -3253,6 +3291,8 @@ static const struct cxl_cmd cxl_cmd_set[256][256] = {
> [LOGS][GET_SUPPORTED] = { "LOGS_GET_SUPPORTED", cmd_logs_get_supported,
> 0, 0 },
> [LOGS][GET_LOG] = { "LOGS_GET_LOG", cmd_logs_get_log, 0x18, 0 },
> + [LOGS][GET_LOG_CAPABILITIES] = { "LOGS_GET_LOG_CAPABILITIES",
> + cmd_logs_get_log_capabilities, 0x10, 0 },
> [FEATURES][GET_SUPPORTED] = { "FEATURES_GET_SUPPORTED",
> cmd_features_get_supported, 0x8, 0 },
> [FEATURES][GET_FEATURE] = { "FEATURES_GET_FEATURE",
> @@ -3512,10 +3552,15 @@ static void cxl_rebuild_cel(CXLCCI *cci)
> }
> }
>
> +static const struct CXLLogCapabilities cxl_get_log_cap[MAX_LOG_TYPE] = {
> + [CXL_LOG_COMMAND_EFFECT] = { .param_flags = 0, .uuid = cel_uuid },
> +};
> +
causes ci build failures:
https://gitlab.com/mstredhat/qemu/-/jobs/9999980051
../hw/cxl/cxl-mailbox-utils.c:3556:60: error: initializer element is not constant
[CXL_LOG_COMMAND_EFFECT] = { .param_flags = 0, .uuid = cel_uuid },
^~~~~~~~
../hw/cxl/cxl-mailbox-utils.c:3556:60: note: (near initialization for ‘cxl_get_log_cap[0].uuid’)
Fixed it up like this:
diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
index f35fc4f112..13d26e391b 100644
--- a/hw/cxl/cxl-mailbox-utils.c
+++ b/hw/cxl/cxl-mailbox-utils.c
@@ -992,9 +992,10 @@ static CXLRetCode cmd_timestamp_set(const struct cxl_cmd *cmd,
}
/* CXL r3.1 Section 8.2.9.5.2.1: Command Effects Log (CEL) */
-static const QemuUUID cel_uuid = {
- .data = UUID(0x0da9c0b5, 0xbf41, 0x4b78, 0x8f, 0x79,
+#define CEL_UUID UUID(0x0da9c0b5, 0xbf41, 0x4b78, 0x8f, 0x79, \
0x96, 0xb1, 0x62, 0x3b, 0x3f, 0x17)
+static const QemuUUID cel_uuid = {
+ .data = CEL_UUID
};
/* CXL r3.1 Section 8.2.9.5.1: Get Supported Logs (Opcode 0400h) */
@@ -3553,7 +3554,7 @@ static void cxl_rebuild_cel(CXLCCI *cci)
}
static const struct CXLLogCapabilities cxl_get_log_cap[MAX_LOG_TYPE] = {
- [CXL_LOG_COMMAND_EFFECT] = { .param_flags = 0, .uuid = cel_uuid },
+ [CXL_LOG_COMMAND_EFFECT] = { .param_flags = 0, .uuid = CEL_UUID },
};
void cxl_init_cci(CXLCCI *cci, size_t payload_max)
> void cxl_init_cci(CXLCCI *cci, size_t payload_max)
> {
> cci->payload_max = payload_max;
> cxl_rebuild_cel(cci);
> + cci->supported_log_cap = cxl_get_log_cap;
>
> cci->bg.complete_pct = 0;
> cci->bg.starttime = 0;
> --
> 2.43.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH qemu 7/8] hw/cxl/cxl-mailbox-utils: Added support for Get Log Capabilities (Opcode 0402h)
2025-05-12 8:42 ` Michael S. Tsirkin
@ 2025-05-12 10:14 ` Jonathan Cameron via
2025-05-12 13:37 ` Michael S. Tsirkin
1 sibling, 0 replies; 17+ messages in thread
From: Jonathan Cameron via @ 2025-05-12 10:14 UTC (permalink / raw)
To: Michael S. Tsirkin
Cc: linux-cxl, qemu-devel, linuxarm, fan.ni, Yuquan Wang, Arpit Kumar,
Sweta Kumari, Vinayak Holikatti, Davidlohr Bueso, Ajay Joshi
On Mon, 12 May 2025 04:42:37 -0400
"Michael S. Tsirkin" <mst@redhat.com> wrote:
> On Wed, Mar 05, 2025 at 09:24:58AM +0000, Jonathan Cameron wrote:
> > From: Arpit Kumar <arpit1.kumar@samsung.com>
> >
> > CXL spec 3.2 section 8.2.10.5.3 describes Get Log Capabilities.
> > It provides log capabilities supported by specified log.
> >
> > Signed-off-by: Arpit Kumar <arpit1.kumar@samsung.com>
> > Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > ---
> > include/hw/cxl/cxl_device.h | 20 ++++++++++++++++
> > include/hw/cxl/cxl_mailbox.h | 5 ++++
> > hw/cxl/cxl-mailbox-utils.c | 45 ++++++++++++++++++++++++++++++++++++
> > 3 files changed, 70 insertions(+)
> >
> > diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h
> > index ed6cd50c67..87a376c982 100644
> > --- a/include/hw/cxl/cxl_device.h
> > +++ b/include/hw/cxl/cxl_device.h
> > @@ -133,6 +133,18 @@ typedef enum {
> > CXL_MBOX_MAX = 0x20
> > } CXLRetCode;
> >
> > +/* types of logs */
> > +typedef enum {
> > + CXL_LOG_COMMAND_EFFECT,
> > + CXL_LOG_VENDOR_DEBUG,
> > + CXL_LOG_COMPONENT_STATE_DUMP,
> > + CXL_LOG_ERROR_CHECK_SCRUB,
> > + CXL_LOG_MEDIA_TEST_CAPABILITY,
> > + CXL_LOG_MEDIA_TEST_RESULTS_SHORT,
> > + CXL_LOG_MEDIA_TEST_RESULTS_LONG,
> > + MAX_LOG_TYPE
> > +} CXLLogType;
> > +
> > typedef struct CXLCCI CXLCCI;
> > typedef struct cxl_device_state CXLDeviceState;
> > struct cxl_cmd;
> > @@ -163,6 +175,11 @@ typedef struct CXLEventLog {
> > QSIMPLEQ_HEAD(, CXLEvent) events;
> > } CXLEventLog;
> >
> > +typedef struct CXLLogCapabilities {
> > + uint32_t param_flags;
> > + QemuUUID uuid;
> > +} CXLLogCapabilities;
> > +
> > typedef struct CXLCCI {
> > struct cxl_cmd cxl_cmd_set[256][256];
> > struct cel_log {
> > @@ -171,6 +188,9 @@ typedef struct CXLCCI {
> > } cel_log[1 << 16];
> > size_t cel_size;
> >
> > + /* get log capabilities */
> > + const CXLLogCapabilities *supported_log_cap;
> > +
> > /* background command handling (times in ms) */
> > struct {
> > uint16_t opcode;
> > diff --git a/include/hw/cxl/cxl_mailbox.h b/include/hw/cxl/cxl_mailbox.h
> > index 9008402d1c..8e1c7c5f15 100644
> > --- a/include/hw/cxl/cxl_mailbox.h
> > +++ b/include/hw/cxl/cxl_mailbox.h
> > @@ -16,4 +16,9 @@
> > #define CXL_MBOX_BACKGROUND_OPERATION (1 << 6)
> > #define CXL_MBOX_BACKGROUND_OPERATION_ABORT (1 << 7)
> >
> > +#define CXL_LOG_CAP_CLEAR_SUPPORTED (1 << 0)
> > +#define CXL_LOG_CAP_POPULATE_SUPPORTED (1 << 1)
> > +#define CXL_LOG_CAP_AUTO_POPULATE_SUPPORTED (1 << 2)
> > +#define CXL_LOG_CAP_PERSISTENT_COLD_RESET_SUPPORTED (1 << 3)
> > +
> > #endif
> > diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
> > index 299f232f26..f35fc4f112 100644
> > --- a/hw/cxl/cxl-mailbox-utils.c
> > +++ b/hw/cxl/cxl-mailbox-utils.c
> > @@ -81,6 +81,7 @@ enum {
> > LOGS = 0x04,
> > #define GET_SUPPORTED 0x0
> > #define GET_LOG 0x1
> > + #define GET_LOG_CAPABILITIES 0x2
> > FEATURES = 0x05,
> > #define GET_SUPPORTED 0x0
> > #define GET_FEATURE 0x1
> > @@ -1068,6 +1069,43 @@ static CXLRetCode cmd_logs_get_log(const struct cxl_cmd *cmd,
> > return CXL_MBOX_SUCCESS;
> > }
> >
> > +static const struct CXLLogCapabilities *find_log_index(QemuUUID *uuid, CXLCCI *cci)
> > +{
> > + for (int i = CXL_LOG_COMMAND_EFFECT; i < MAX_LOG_TYPE; i++) {
> > + if (qemu_uuid_is_equal(uuid,
> > + &cci->supported_log_cap[i].uuid)) {
> > + return &cci->supported_log_cap[i];
> > + }
> > + }
> > + return NULL;
> > +}
> > +
> > +/* CXL r3.2 Section 8.2.10.5.3: Get Log Capabilities (Opcode 0402h) */
> > +static CXLRetCode cmd_logs_get_log_capabilities(const struct cxl_cmd *cmd,
> > + uint8_t *payload_in,
> > + size_t len_in,
> > + uint8_t *payload_out,
> > + size_t *len_out,
> > + CXLCCI *cci)
> > +{
> > + const CXLLogCapabilities *cap;
> > + struct {
> > + QemuUUID uuid;
> > + } QEMU_PACKED QEMU_ALIGNED(8) *get_log_capabilities_in = (void *)payload_in;
> > +
> > + uint32_t *get_log_capabilities_out = (uint32_t *)payload_out;
> > +
> > + cap = find_log_index(&get_log_capabilities_in->uuid, cci);
> > + if (!cap) {
> > + return CXL_MBOX_INVALID_LOG;
> > + }
> > +
> > + memcpy(get_log_capabilities_out, &cap->param_flags,
> > + sizeof(cap->param_flags));
> > + *len_out = sizeof(*get_log_capabilities_out);
> > + return CXL_MBOX_SUCCESS;
> > +}
> > +
> > /* CXL r3.1 section 8.2.9.6: Features */
> > /*
> > * Get Supported Features output payload
> > @@ -3253,6 +3291,8 @@ static const struct cxl_cmd cxl_cmd_set[256][256] = {
> > [LOGS][GET_SUPPORTED] = { "LOGS_GET_SUPPORTED", cmd_logs_get_supported,
> > 0, 0 },
> > [LOGS][GET_LOG] = { "LOGS_GET_LOG", cmd_logs_get_log, 0x18, 0 },
> > + [LOGS][GET_LOG_CAPABILITIES] = { "LOGS_GET_LOG_CAPABILITIES",
> > + cmd_logs_get_log_capabilities, 0x10, 0 },
> > [FEATURES][GET_SUPPORTED] = { "FEATURES_GET_SUPPORTED",
> > cmd_features_get_supported, 0x8, 0 },
> > [FEATURES][GET_FEATURE] = { "FEATURES_GET_FEATURE",
> > @@ -3512,10 +3552,15 @@ static void cxl_rebuild_cel(CXLCCI *cci)
> > }
> > }
> >
> > +static const struct CXLLogCapabilities cxl_get_log_cap[MAX_LOG_TYPE] = {
> > + [CXL_LOG_COMMAND_EFFECT] = { .param_flags = 0, .uuid = cel_uuid },
> > +};
> > +
>
>
> causes ci build failures:
>
> https://gitlab.com/mstredhat/qemu/-/jobs/9999980051
>
> ../hw/cxl/cxl-mailbox-utils.c:3556:60: error: initializer element is not constant
> [CXL_LOG_COMMAND_EFFECT] = { .param_flags = 0, .uuid = cel_uuid },
> ^~~~~~~~
> ../hw/cxl/cxl-mailbox-utils.c:3556:60: note: (near initialization for ‘cxl_get_log_cap[0].uuid’)
>
>
Looks good. Thanks for fixing it up!
> Fixed it up like this:
>
> diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
> index f35fc4f112..13d26e391b 100644
> --- a/hw/cxl/cxl-mailbox-utils.c
> +++ b/hw/cxl/cxl-mailbox-utils.c
> @@ -992,9 +992,10 @@ static CXLRetCode cmd_timestamp_set(const struct cxl_cmd *cmd,
> }
>
> /* CXL r3.1 Section 8.2.9.5.2.1: Command Effects Log (CEL) */
> -static const QemuUUID cel_uuid = {
> - .data = UUID(0x0da9c0b5, 0xbf41, 0x4b78, 0x8f, 0x79,
> +#define CEL_UUID UUID(0x0da9c0b5, 0xbf41, 0x4b78, 0x8f, 0x79, \
> 0x96, 0xb1, 0x62, 0x3b, 0x3f, 0x17)
> +static const QemuUUID cel_uuid = {
> + .data = CEL_UUID
> };
>
> /* CXL r3.1 Section 8.2.9.5.1: Get Supported Logs (Opcode 0400h) */
> @@ -3553,7 +3554,7 @@ static void cxl_rebuild_cel(CXLCCI *cci)
> }
>
> static const struct CXLLogCapabilities cxl_get_log_cap[MAX_LOG_TYPE] = {
> - [CXL_LOG_COMMAND_EFFECT] = { .param_flags = 0, .uuid = cel_uuid },
> + [CXL_LOG_COMMAND_EFFECT] = { .param_flags = 0, .uuid = CEL_UUID },
> };
>
> void cxl_init_cci(CXLCCI *cci, size_t payload_max)
>
>
> > void cxl_init_cci(CXLCCI *cci, size_t payload_max)
> > {
> > cci->payload_max = payload_max;
> > cxl_rebuild_cel(cci);
> > + cci->supported_log_cap = cxl_get_log_cap;
> >
> > cci->bg.complete_pct = 0;
> > cci->bg.starttime = 0;
> > --
> > 2.43.0
>
>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH qemu 7/8] hw/cxl/cxl-mailbox-utils: Added support for Get Log Capabilities (Opcode 0402h)
2025-05-12 8:42 ` Michael S. Tsirkin
2025-05-12 10:14 ` Jonathan Cameron via
@ 2025-05-12 13:37 ` Michael S. Tsirkin
2025-05-12 16:40 ` Jonathan Cameron via
1 sibling, 1 reply; 17+ messages in thread
From: Michael S. Tsirkin @ 2025-05-12 13:37 UTC (permalink / raw)
To: Jonathan Cameron
Cc: linux-cxl, qemu-devel, linuxarm, fan.ni, Yuquan Wang, Arpit Kumar,
Sweta Kumari, Vinayak Holikatti, Davidlohr Bueso, Ajay Joshi
On Mon, May 12, 2025 at 04:42:41AM -0400, Michael S. Tsirkin wrote:
> On Wed, Mar 05, 2025 at 09:24:58AM +0000, Jonathan Cameron wrote:
> > From: Arpit Kumar <arpit1.kumar@samsung.com>
> >
> > CXL spec 3.2 section 8.2.10.5.3 describes Get Log Capabilities.
> > It provides log capabilities supported by specified log.
> >
> > Signed-off-by: Arpit Kumar <arpit1.kumar@samsung.com>
> > Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > ---
> > include/hw/cxl/cxl_device.h | 20 ++++++++++++++++
> > include/hw/cxl/cxl_mailbox.h | 5 ++++
> > hw/cxl/cxl-mailbox-utils.c | 45 ++++++++++++++++++++++++++++++++++++
> > 3 files changed, 70 insertions(+)
> >
> > diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h
> > index ed6cd50c67..87a376c982 100644
> > --- a/include/hw/cxl/cxl_device.h
> > +++ b/include/hw/cxl/cxl_device.h
> > @@ -133,6 +133,18 @@ typedef enum {
> > CXL_MBOX_MAX = 0x20
> > } CXLRetCode;
> >
> > +/* types of logs */
> > +typedef enum {
> > + CXL_LOG_COMMAND_EFFECT,
> > + CXL_LOG_VENDOR_DEBUG,
> > + CXL_LOG_COMPONENT_STATE_DUMP,
> > + CXL_LOG_ERROR_CHECK_SCRUB,
> > + CXL_LOG_MEDIA_TEST_CAPABILITY,
> > + CXL_LOG_MEDIA_TEST_RESULTS_SHORT,
> > + CXL_LOG_MEDIA_TEST_RESULTS_LONG,
> > + MAX_LOG_TYPE
> > +} CXLLogType;
> > +
> > typedef struct CXLCCI CXLCCI;
> > typedef struct cxl_device_state CXLDeviceState;
> > struct cxl_cmd;
> > @@ -163,6 +175,11 @@ typedef struct CXLEventLog {
> > QSIMPLEQ_HEAD(, CXLEvent) events;
> > } CXLEventLog;
> >
> > +typedef struct CXLLogCapabilities {
> > + uint32_t param_flags;
> > + QemuUUID uuid;
> > +} CXLLogCapabilities;
> > +
> > typedef struct CXLCCI {
> > struct cxl_cmd cxl_cmd_set[256][256];
> > struct cel_log {
> > @@ -171,6 +188,9 @@ typedef struct CXLCCI {
> > } cel_log[1 << 16];
> > size_t cel_size;
> >
> > + /* get log capabilities */
> > + const CXLLogCapabilities *supported_log_cap;
> > +
> > /* background command handling (times in ms) */
> > struct {
> > uint16_t opcode;
> > diff --git a/include/hw/cxl/cxl_mailbox.h b/include/hw/cxl/cxl_mailbox.h
> > index 9008402d1c..8e1c7c5f15 100644
> > --- a/include/hw/cxl/cxl_mailbox.h
> > +++ b/include/hw/cxl/cxl_mailbox.h
> > @@ -16,4 +16,9 @@
> > #define CXL_MBOX_BACKGROUND_OPERATION (1 << 6)
> > #define CXL_MBOX_BACKGROUND_OPERATION_ABORT (1 << 7)
> >
> > +#define CXL_LOG_CAP_CLEAR_SUPPORTED (1 << 0)
> > +#define CXL_LOG_CAP_POPULATE_SUPPORTED (1 << 1)
> > +#define CXL_LOG_CAP_AUTO_POPULATE_SUPPORTED (1 << 2)
> > +#define CXL_LOG_CAP_PERSISTENT_COLD_RESET_SUPPORTED (1 << 3)
> > +
> > #endif
> > diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
> > index 299f232f26..f35fc4f112 100644
> > --- a/hw/cxl/cxl-mailbox-utils.c
> > +++ b/hw/cxl/cxl-mailbox-utils.c
> > @@ -81,6 +81,7 @@ enum {
> > LOGS = 0x04,
> > #define GET_SUPPORTED 0x0
> > #define GET_LOG 0x1
> > + #define GET_LOG_CAPABILITIES 0x2
> > FEATURES = 0x05,
> > #define GET_SUPPORTED 0x0
> > #define GET_FEATURE 0x1
> > @@ -1068,6 +1069,43 @@ static CXLRetCode cmd_logs_get_log(const struct cxl_cmd *cmd,
> > return CXL_MBOX_SUCCESS;
> > }
> >
> > +static const struct CXLLogCapabilities *find_log_index(QemuUUID *uuid, CXLCCI *cci)
> > +{
> > + for (int i = CXL_LOG_COMMAND_EFFECT; i < MAX_LOG_TYPE; i++) {
> > + if (qemu_uuid_is_equal(uuid,
> > + &cci->supported_log_cap[i].uuid)) {
> > + return &cci->supported_log_cap[i];
> > + }
> > + }
> > + return NULL;
> > +}
> > +
> > +/* CXL r3.2 Section 8.2.10.5.3: Get Log Capabilities (Opcode 0402h) */
> > +static CXLRetCode cmd_logs_get_log_capabilities(const struct cxl_cmd *cmd,
> > + uint8_t *payload_in,
> > + size_t len_in,
> > + uint8_t *payload_out,
> > + size_t *len_out,
> > + CXLCCI *cci)
> > +{
> > + const CXLLogCapabilities *cap;
> > + struct {
> > + QemuUUID uuid;
> > + } QEMU_PACKED QEMU_ALIGNED(8) *get_log_capabilities_in = (void *)payload_in;
> > +
> > + uint32_t *get_log_capabilities_out = (uint32_t *)payload_out;
> > +
> > + cap = find_log_index(&get_log_capabilities_in->uuid, cci);
> > + if (!cap) {
> > + return CXL_MBOX_INVALID_LOG;
> > + }
> > +
> > + memcpy(get_log_capabilities_out, &cap->param_flags,
> > + sizeof(cap->param_flags));
> > + *len_out = sizeof(*get_log_capabilities_out);
> > + return CXL_MBOX_SUCCESS;
> > +}
> > +
> > /* CXL r3.1 section 8.2.9.6: Features */
> > /*
> > * Get Supported Features output payload
> > @@ -3253,6 +3291,8 @@ static const struct cxl_cmd cxl_cmd_set[256][256] = {
> > [LOGS][GET_SUPPORTED] = { "LOGS_GET_SUPPORTED", cmd_logs_get_supported,
> > 0, 0 },
> > [LOGS][GET_LOG] = { "LOGS_GET_LOG", cmd_logs_get_log, 0x18, 0 },
> > + [LOGS][GET_LOG_CAPABILITIES] = { "LOGS_GET_LOG_CAPABILITIES",
> > + cmd_logs_get_log_capabilities, 0x10, 0 },
> > [FEATURES][GET_SUPPORTED] = { "FEATURES_GET_SUPPORTED",
> > cmd_features_get_supported, 0x8, 0 },
> > [FEATURES][GET_FEATURE] = { "FEATURES_GET_FEATURE",
> > @@ -3512,10 +3552,15 @@ static void cxl_rebuild_cel(CXLCCI *cci)
> > }
> > }
> >
> > +static const struct CXLLogCapabilities cxl_get_log_cap[MAX_LOG_TYPE] = {
> > + [CXL_LOG_COMMAND_EFFECT] = { .param_flags = 0, .uuid = cel_uuid },
> > +};
> > +
>
>
> causes ci build failures:
>
> https://gitlab.com/mstredhat/qemu/-/jobs/9999980051
>
> ../hw/cxl/cxl-mailbox-utils.c:3556:60: error: initializer element is not constant
> [CXL_LOG_COMMAND_EFFECT] = { .param_flags = 0, .uuid = cel_uuid },
> ^~~~~~~~
> ../hw/cxl/cxl-mailbox-utils.c:3556:60: note: (near initialization for ‘cxl_get_log_cap[0].uuid’)
>
>
> Fixed it up like this:
>
> diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
> index f35fc4f112..13d26e391b 100644
> --- a/hw/cxl/cxl-mailbox-utils.c
> +++ b/hw/cxl/cxl-mailbox-utils.c
> @@ -992,9 +992,10 @@ static CXLRetCode cmd_timestamp_set(const struct cxl_cmd *cmd,
> }
>
> /* CXL r3.1 Section 8.2.9.5.2.1: Command Effects Log (CEL) */
> -static const QemuUUID cel_uuid = {
> - .data = UUID(0x0da9c0b5, 0xbf41, 0x4b78, 0x8f, 0x79,
> +#define CEL_UUID UUID(0x0da9c0b5, 0xbf41, 0x4b78, 0x8f, 0x79, \
> 0x96, 0xb1, 0x62, 0x3b, 0x3f, 0x17)
> +static const QemuUUID cel_uuid = {
> + .data = CEL_UUID
> };
>
> /* CXL r3.1 Section 8.2.9.5.1: Get Supported Logs (Opcode 0400h) */
> @@ -3553,7 +3554,7 @@ static void cxl_rebuild_cel(CXLCCI *cci)
> }
>
> static const struct CXLLogCapabilities cxl_get_log_cap[MAX_LOG_TYPE] = {
> - [CXL_LOG_COMMAND_EFFECT] = { .param_flags = 0, .uuid = cel_uuid },
> + [CXL_LOG_COMMAND_EFFECT] = { .param_flags = 0, .uuid = CEL_UUID },
> };
>
> void cxl_init_cci(CXLCCI *cci, size_t payload_max)
>
Actually no, does not help either. Dropped for now.
Next patch does not depend on this one, right?
> > void cxl_init_cci(CXLCCI *cci, size_t payload_max)
> > {
> > cci->payload_max = payload_max;
> > cxl_rebuild_cel(cci);
> > + cci->supported_log_cap = cxl_get_log_cap;
> >
> > cci->bg.complete_pct = 0;
> > cci->bg.starttime = 0;
> > --
> > 2.43.0
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH qemu 7/8] hw/cxl/cxl-mailbox-utils: Added support for Get Log Capabilities (Opcode 0402h)
2025-05-12 13:37 ` Michael S. Tsirkin
@ 2025-05-12 16:40 ` Jonathan Cameron via
[not found] ` <CGME20250516134255epcas5p378dda7fbda7db62fe73cc6163c5e7043@epcas5p3.samsung.com>
0 siblings, 1 reply; 17+ messages in thread
From: Jonathan Cameron via @ 2025-05-12 16:40 UTC (permalink / raw)
To: Michael S. Tsirkin
Cc: linux-cxl, qemu-devel, linuxarm, fan.ni, Yuquan Wang, Arpit Kumar,
Sweta Kumari, Vinayak Holikatti, Davidlohr Bueso, Ajay Joshi
On Mon, 12 May 2025 09:37:07 -0400
"Michael S. Tsirkin" <mst@redhat.com> wrote:
> On Mon, May 12, 2025 at 04:42:41AM -0400, Michael S. Tsirkin wrote:
> > On Wed, Mar 05, 2025 at 09:24:58AM +0000, Jonathan Cameron wrote:
> > > From: Arpit Kumar <arpit1.kumar@samsung.com>
> > >
> > > CXL spec 3.2 section 8.2.10.5.3 describes Get Log Capabilities.
> > > It provides log capabilities supported by specified log.
> > >
> > > Signed-off-by: Arpit Kumar <arpit1.kumar@samsung.com>
> > > Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > > ---
> > > include/hw/cxl/cxl_device.h | 20 ++++++++++++++++
> > > include/hw/cxl/cxl_mailbox.h | 5 ++++
> > > hw/cxl/cxl-mailbox-utils.c | 45 ++++++++++++++++++++++++++++++++++++
> > > 3 files changed, 70 insertions(+)
> > >
> > > diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h
> > > index ed6cd50c67..87a376c982 100644
> > > --- a/include/hw/cxl/cxl_device.h
> > > +++ b/include/hw/cxl/cxl_device.h
> > > @@ -133,6 +133,18 @@ typedef enum {
> > > CXL_MBOX_MAX = 0x20
> > > } CXLRetCode;
> > >
> > > +/* types of logs */
> > > +typedef enum {
> > > + CXL_LOG_COMMAND_EFFECT,
> > > + CXL_LOG_VENDOR_DEBUG,
> > > + CXL_LOG_COMPONENT_STATE_DUMP,
> > > + CXL_LOG_ERROR_CHECK_SCRUB,
> > > + CXL_LOG_MEDIA_TEST_CAPABILITY,
> > > + CXL_LOG_MEDIA_TEST_RESULTS_SHORT,
> > > + CXL_LOG_MEDIA_TEST_RESULTS_LONG,
> > > + MAX_LOG_TYPE
> > > +} CXLLogType;
> > > +
> > > typedef struct CXLCCI CXLCCI;
> > > typedef struct cxl_device_state CXLDeviceState;
> > > struct cxl_cmd;
> > > @@ -163,6 +175,11 @@ typedef struct CXLEventLog {
> > > QSIMPLEQ_HEAD(, CXLEvent) events;
> > > } CXLEventLog;
> > >
> > > +typedef struct CXLLogCapabilities {
> > > + uint32_t param_flags;
> > > + QemuUUID uuid;
> > > +} CXLLogCapabilities;
> > > +
> > > typedef struct CXLCCI {
> > > struct cxl_cmd cxl_cmd_set[256][256];
> > > struct cel_log {
> > > @@ -171,6 +188,9 @@ typedef struct CXLCCI {
> > > } cel_log[1 << 16];
> > > size_t cel_size;
> > >
> > > + /* get log capabilities */
> > > + const CXLLogCapabilities *supported_log_cap;
> > > +
> > > /* background command handling (times in ms) */
> > > struct {
> > > uint16_t opcode;
> > > diff --git a/include/hw/cxl/cxl_mailbox.h b/include/hw/cxl/cxl_mailbox.h
> > > index 9008402d1c..8e1c7c5f15 100644
> > > --- a/include/hw/cxl/cxl_mailbox.h
> > > +++ b/include/hw/cxl/cxl_mailbox.h
> > > @@ -16,4 +16,9 @@
> > > #define CXL_MBOX_BACKGROUND_OPERATION (1 << 6)
> > > #define CXL_MBOX_BACKGROUND_OPERATION_ABORT (1 << 7)
> > >
> > > +#define CXL_LOG_CAP_CLEAR_SUPPORTED (1 << 0)
> > > +#define CXL_LOG_CAP_POPULATE_SUPPORTED (1 << 1)
> > > +#define CXL_LOG_CAP_AUTO_POPULATE_SUPPORTED (1 << 2)
> > > +#define CXL_LOG_CAP_PERSISTENT_COLD_RESET_SUPPORTED (1 << 3)
> > > +
> > > #endif
> > > diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
> > > index 299f232f26..f35fc4f112 100644
> > > --- a/hw/cxl/cxl-mailbox-utils.c
> > > +++ b/hw/cxl/cxl-mailbox-utils.c
> > > @@ -81,6 +81,7 @@ enum {
> > > LOGS = 0x04,
> > > #define GET_SUPPORTED 0x0
> > > #define GET_LOG 0x1
> > > + #define GET_LOG_CAPABILITIES 0x2
> > > FEATURES = 0x05,
> > > #define GET_SUPPORTED 0x0
> > > #define GET_FEATURE 0x1
> > > @@ -1068,6 +1069,43 @@ static CXLRetCode cmd_logs_get_log(const struct cxl_cmd *cmd,
> > > return CXL_MBOX_SUCCESS;
> > > }
> > >
> > > +static const struct CXLLogCapabilities *find_log_index(QemuUUID *uuid, CXLCCI *cci)
> > > +{
> > > + for (int i = CXL_LOG_COMMAND_EFFECT; i < MAX_LOG_TYPE; i++) {
> > > + if (qemu_uuid_is_equal(uuid,
> > > + &cci->supported_log_cap[i].uuid)) {
> > > + return &cci->supported_log_cap[i];
> > > + }
> > > + }
> > > + return NULL;
> > > +}
> > > +
> > > +/* CXL r3.2 Section 8.2.10.5.3: Get Log Capabilities (Opcode 0402h) */
> > > +static CXLRetCode cmd_logs_get_log_capabilities(const struct cxl_cmd *cmd,
> > > + uint8_t *payload_in,
> > > + size_t len_in,
> > > + uint8_t *payload_out,
> > > + size_t *len_out,
> > > + CXLCCI *cci)
> > > +{
> > > + const CXLLogCapabilities *cap;
> > > + struct {
> > > + QemuUUID uuid;
> > > + } QEMU_PACKED QEMU_ALIGNED(8) *get_log_capabilities_in = (void *)payload_in;
> > > +
> > > + uint32_t *get_log_capabilities_out = (uint32_t *)payload_out;
> > > +
> > > + cap = find_log_index(&get_log_capabilities_in->uuid, cci);
> > > + if (!cap) {
> > > + return CXL_MBOX_INVALID_LOG;
> > > + }
> > > +
> > > + memcpy(get_log_capabilities_out, &cap->param_flags,
> > > + sizeof(cap->param_flags));
> > > + *len_out = sizeof(*get_log_capabilities_out);
> > > + return CXL_MBOX_SUCCESS;
> > > +}
> > > +
> > > /* CXL r3.1 section 8.2.9.6: Features */
> > > /*
> > > * Get Supported Features output payload
> > > @@ -3253,6 +3291,8 @@ static const struct cxl_cmd cxl_cmd_set[256][256] = {
> > > [LOGS][GET_SUPPORTED] = { "LOGS_GET_SUPPORTED", cmd_logs_get_supported,
> > > 0, 0 },
> > > [LOGS][GET_LOG] = { "LOGS_GET_LOG", cmd_logs_get_log, 0x18, 0 },
> > > + [LOGS][GET_LOG_CAPABILITIES] = { "LOGS_GET_LOG_CAPABILITIES",
> > > + cmd_logs_get_log_capabilities, 0x10, 0 },
> > > [FEATURES][GET_SUPPORTED] = { "FEATURES_GET_SUPPORTED",
> > > cmd_features_get_supported, 0x8, 0 },
> > > [FEATURES][GET_FEATURE] = { "FEATURES_GET_FEATURE",
> > > @@ -3512,10 +3552,15 @@ static void cxl_rebuild_cel(CXLCCI *cci)
> > > }
> > > }
> > >
> > > +static const struct CXLLogCapabilities cxl_get_log_cap[MAX_LOG_TYPE] = {
> > > + [CXL_LOG_COMMAND_EFFECT] = { .param_flags = 0, .uuid = cel_uuid },
> > > +};
> > > +
> >
> >
> > causes ci build failures:
> >
> > https://gitlab.com/mstredhat/qemu/-/jobs/9999980051
> >
> > ../hw/cxl/cxl-mailbox-utils.c:3556:60: error: initializer element is not constant
> > [CXL_LOG_COMMAND_EFFECT] = { .param_flags = 0, .uuid = cel_uuid },
> > ^~~~~~~~
> > ../hw/cxl/cxl-mailbox-utils.c:3556:60: note: (near initialization for ‘cxl_get_log_cap[0].uuid’)
> >
> >
> > Fixed it up like this:
> >
> > diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
> > index f35fc4f112..13d26e391b 100644
> > --- a/hw/cxl/cxl-mailbox-utils.c
> > +++ b/hw/cxl/cxl-mailbox-utils.c
> > @@ -992,9 +992,10 @@ static CXLRetCode cmd_timestamp_set(const struct cxl_cmd *cmd,
> > }
> >
> > /* CXL r3.1 Section 8.2.9.5.2.1: Command Effects Log (CEL) */
> > -static const QemuUUID cel_uuid = {
> > - .data = UUID(0x0da9c0b5, 0xbf41, 0x4b78, 0x8f, 0x79,
> > +#define CEL_UUID UUID(0x0da9c0b5, 0xbf41, 0x4b78, 0x8f, 0x79, \
> > 0x96, 0xb1, 0x62, 0x3b, 0x3f, 0x17)
> > +static const QemuUUID cel_uuid = {
> > + .data = CEL_UUID
> > };
> >
> > /* CXL r3.1 Section 8.2.9.5.1: Get Supported Logs (Opcode 0400h) */
> > @@ -3553,7 +3554,7 @@ static void cxl_rebuild_cel(CXLCCI *cci)
> > }
> >
> > static const struct CXLLogCapabilities cxl_get_log_cap[MAX_LOG_TYPE] = {
> > - [CXL_LOG_COMMAND_EFFECT] = { .param_flags = 0, .uuid = cel_uuid },
> > + [CXL_LOG_COMMAND_EFFECT] = { .param_flags = 0, .uuid = CEL_UUID },
> > };
> >
> > void cxl_init_cci(CXLCCI *cci, size_t payload_max)
> >
>
>
> Actually no, does not help either. Dropped for now.
> Next patch does not depend on this one, right?
Indeed. Unrelated.
Thanks,
J
>
> > > void cxl_init_cci(CXLCCI *cci, size_t payload_max)
> > > {
> > > cci->payload_max = payload_max;
> > > cxl_rebuild_cel(cci);
> > > + cci->supported_log_cap = cxl_get_log_cap;
> > >
> > > cci->bg.complete_pct = 0;
> > > cci->bg.starttime = 0;
> > > --
> > > 2.43.0
>
>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH qemu 7/8] hw/cxl/cxl-mailbox-utils: Added support for Get Log Capabilities (Opcode 0402h)
[not found] ` <CGME20250516134255epcas5p378dda7fbda7db62fe73cc6163c5e7043@epcas5p3.samsung.com>
@ 2025-05-16 13:42 ` Arpit Kumar
2025-05-28 12:31 ` Jonathan Cameron via
0 siblings, 1 reply; 17+ messages in thread
From: Arpit Kumar @ 2025-05-16 13:42 UTC (permalink / raw)
To: Jonathan Cameron
Cc: Michael S. Tsirkin, linux-cxl, qemu-devel, linuxarm, fan.ni,
Yuquan Wang, Sweta Kumari, Vinayak Holikatti, Davidlohr Bueso,
Ajay Joshi, cpgs
[-- Attachment #1: Type: text/plain, Size: 9229 bytes --]
On 12/05/25 05:40PM, Jonathan Cameron wrote:
>On Mon, 12 May 2025 09:37:07 -0400
>"Michael S. Tsirkin" <mst@redhat.com> wrote:
>
>> On Mon, May 12, 2025 at 04:42:41AM -0400, Michael S. Tsirkin wrote:
>> > On Wed, Mar 05, 2025 at 09:24:58AM +0000, Jonathan Cameron wrote:
>> > > From: Arpit Kumar <arpit1.kumar@samsung.com>
>> > >
>> > > CXL spec 3.2 section 8.2.10.5.3 describes Get Log Capabilities.
>> > > It provides log capabilities supported by specified log.
>> > >
>> > > Signed-off-by: Arpit Kumar <arpit1.kumar@samsung.com>
>> > > Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>> > > ---
>> > > include/hw/cxl/cxl_device.h | 20 ++++++++++++++++
>> > > include/hw/cxl/cxl_mailbox.h | 5 ++++
>> > > hw/cxl/cxl-mailbox-utils.c | 45 ++++++++++++++++++++++++++++++++++++
>> > > 3 files changed, 70 insertions(+)
>> > >
>> > > diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h
>> > > index ed6cd50c67..87a376c982 100644
>> > > --- a/include/hw/cxl/cxl_device.h
>> > > +++ b/include/hw/cxl/cxl_device.h
>> > > @@ -133,6 +133,18 @@ typedef enum {
>> > > CXL_MBOX_MAX = 0x20
>> > > } CXLRetCode;
>> > >
>> > > +/* types of logs */
>> > > +typedef enum {
>> > > + CXL_LOG_COMMAND_EFFECT,
>> > > + CXL_LOG_VENDOR_DEBUG,
>> > > + CXL_LOG_COMPONENT_STATE_DUMP,
>> > > + CXL_LOG_ERROR_CHECK_SCRUB,
>> > > + CXL_LOG_MEDIA_TEST_CAPABILITY,
>> > > + CXL_LOG_MEDIA_TEST_RESULTS_SHORT,
>> > > + CXL_LOG_MEDIA_TEST_RESULTS_LONG,
>> > > + MAX_LOG_TYPE
>> > > +} CXLLogType;
>> > > +
>> > > typedef struct CXLCCI CXLCCI;
>> > > typedef struct cxl_device_state CXLDeviceState;
>> > > struct cxl_cmd;
>> > > @@ -163,6 +175,11 @@ typedef struct CXLEventLog {
>> > > QSIMPLEQ_HEAD(, CXLEvent) events;
>> > > } CXLEventLog;
>> > >
>> > > +typedef struct CXLLogCapabilities {
>> > > + uint32_t param_flags;
>> > > + QemuUUID uuid;
>> > > +} CXLLogCapabilities;
>> > > +
>> > > typedef struct CXLCCI {
>> > > struct cxl_cmd cxl_cmd_set[256][256];
>> > > struct cel_log {
>> > > @@ -171,6 +188,9 @@ typedef struct CXLCCI {
>> > > } cel_log[1 << 16];
>> > > size_t cel_size;
>> > >
>> > > + /* get log capabilities */
>> > > + const CXLLogCapabilities *supported_log_cap;
>> > > +
>> > > /* background command handling (times in ms) */
>> > > struct {
>> > > uint16_t opcode;
>> > > diff --git a/include/hw/cxl/cxl_mailbox.h b/include/hw/cxl/cxl_mailbox.h
>> > > index 9008402d1c..8e1c7c5f15 100644
>> > > --- a/include/hw/cxl/cxl_mailbox.h
>> > > +++ b/include/hw/cxl/cxl_mailbox.h
>> > > @@ -16,4 +16,9 @@
>> > > #define CXL_MBOX_BACKGROUND_OPERATION (1 << 6)
>> > > #define CXL_MBOX_BACKGROUND_OPERATION_ABORT (1 << 7)
>> > >
>> > > +#define CXL_LOG_CAP_CLEAR_SUPPORTED (1 << 0)
>> > > +#define CXL_LOG_CAP_POPULATE_SUPPORTED (1 << 1)
>> > > +#define CXL_LOG_CAP_AUTO_POPULATE_SUPPORTED (1 << 2)
>> > > +#define CXL_LOG_CAP_PERSISTENT_COLD_RESET_SUPPORTED (1 << 3)
>> > > +
>> > > #endif
>> > > diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
>> > > index 299f232f26..f35fc4f112 100644
>> > > --- a/hw/cxl/cxl-mailbox-utils.c
>> > > +++ b/hw/cxl/cxl-mailbox-utils.c
>> > > @@ -81,6 +81,7 @@ enum {
>> > > LOGS = 0x04,
>> > > #define GET_SUPPORTED 0x0
>> > > #define GET_LOG 0x1
>> > > + #define GET_LOG_CAPABILITIES 0x2
>> > > FEATURES = 0x05,
>> > > #define GET_SUPPORTED 0x0
>> > > #define GET_FEATURE 0x1
>> > > @@ -1068,6 +1069,43 @@ static CXLRetCode cmd_logs_get_log(const struct cxl_cmd *cmd,
>> > > return CXL_MBOX_SUCCESS;
>> > > }
>> > >
>> > > +static const struct CXLLogCapabilities *find_log_index(QemuUUID *uuid, CXLCCI *cci)
>> > > +{
>> > > + for (int i = CXL_LOG_COMMAND_EFFECT; i < MAX_LOG_TYPE; i++) {
>> > > + if (qemu_uuid_is_equal(uuid,
>> > > + &cci->supported_log_cap[i].uuid)) {
>> > > + return &cci->supported_log_cap[i];
>> > > + }
>> > > + }
>> > > + return NULL;
>> > > +}
>> > > +
>> > > +/* CXL r3.2 Section 8.2.10.5.3: Get Log Capabilities (Opcode 0402h) */
>> > > +static CXLRetCode cmd_logs_get_log_capabilities(const struct cxl_cmd *cmd,
>> > > + uint8_t *payload_in,
>> > > + size_t len_in,
>> > > + uint8_t *payload_out,
>> > > + size_t *len_out,
>> > > + CXLCCI *cci)
>> > > +{
>> > > + const CXLLogCapabilities *cap;
>> > > + struct {
>> > > + QemuUUID uuid;
>> > > + } QEMU_PACKED QEMU_ALIGNED(8) *get_log_capabilities_in = (void *)payload_in;
>> > > +
>> > > + uint32_t *get_log_capabilities_out = (uint32_t *)payload_out;
>> > > +
>> > > + cap = find_log_index(&get_log_capabilities_in->uuid, cci);
>> > > + if (!cap) {
>> > > + return CXL_MBOX_INVALID_LOG;
>> > > + }
>> > > +
>> > > + memcpy(get_log_capabilities_out, &cap->param_flags,
>> > > + sizeof(cap->param_flags));
>> > > + *len_out = sizeof(*get_log_capabilities_out);
>> > > + return CXL_MBOX_SUCCESS;
>> > > +}
>> > > +
>> > > /* CXL r3.1 section 8.2.9.6: Features */
>> > > /*
>> > > * Get Supported Features output payload
>> > > @@ -3253,6 +3291,8 @@ static const struct cxl_cmd cxl_cmd_set[256][256] = {
>> > > [LOGS][GET_SUPPORTED] = { "LOGS_GET_SUPPORTED", cmd_logs_get_supported,
>> > > 0, 0 },
>> > > [LOGS][GET_LOG] = { "LOGS_GET_LOG", cmd_logs_get_log, 0x18, 0 },
>> > > + [LOGS][GET_LOG_CAPABILITIES] = { "LOGS_GET_LOG_CAPABILITIES",
>> > > + cmd_logs_get_log_capabilities, 0x10, 0 },
>> > > [FEATURES][GET_SUPPORTED] = { "FEATURES_GET_SUPPORTED",
>> > > cmd_features_get_supported, 0x8, 0 },
>> > > [FEATURES][GET_FEATURE] = { "FEATURES_GET_FEATURE",
>> > > @@ -3512,10 +3552,15 @@ static void cxl_rebuild_cel(CXLCCI *cci)
>> > > }
>> > > }
>> > >
>> > > +static const struct CXLLogCapabilities cxl_get_log_cap[MAX_LOG_TYPE] = {
>> > > + [CXL_LOG_COMMAND_EFFECT] = { .param_flags = 0, .uuid = cel_uuid },
>> > > +};
>> > > +
>> >
>> >
>> > causes ci build failures:
>> >
>> > https://gitlab.com/mstredhat/qemu/-/jobs/9999980051
>> >
>> > ../hw/cxl/cxl-mailbox-utils.c:3556:60: error: initializer element is not constant
>> > [CXL_LOG_COMMAND_EFFECT] = { .param_flags = 0, .uuid = cel_uuid },
>> > ^~~~~~~~
>> > ../hw/cxl/cxl-mailbox-utils.c:3556:60: note: (near initialization for ‘cxl_get_log_cap[0].uuid’)
>> >
>> >
>> > Fixed it up like this:
>> >
>> > diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
>> > index f35fc4f112..13d26e391b 100644
>> > --- a/hw/cxl/cxl-mailbox-utils.c
>> > +++ b/hw/cxl/cxl-mailbox-utils.c
>> > @@ -992,9 +992,10 @@ static CXLRetCode cmd_timestamp_set(const struct cxl_cmd *cmd,
>> > }
>> >
>> > /* CXL r3.1 Section 8.2.9.5.2.1: Command Effects Log (CEL) */
>> > -static const QemuUUID cel_uuid = {
>> > - .data = UUID(0x0da9c0b5, 0xbf41, 0x4b78, 0x8f, 0x79,
>> > +#define CEL_UUID UUID(0x0da9c0b5, 0xbf41, 0x4b78, 0x8f, 0x79, \
>> > 0x96, 0xb1, 0x62, 0x3b, 0x3f, 0x17)
>> > +static const QemuUUID cel_uuid = {
>> > + .data = CEL_UUID
>> > };
>> >
>> > /* CXL r3.1 Section 8.2.9.5.1: Get Supported Logs (Opcode 0400h) */
>> > @@ -3553,7 +3554,7 @@ static void cxl_rebuild_cel(CXLCCI *cci)
>> > }
>> >
>> > static const struct CXLLogCapabilities cxl_get_log_cap[MAX_LOG_TYPE] = {
>> > - [CXL_LOG_COMMAND_EFFECT] = { .param_flags = 0, .uuid = cel_uuid },
>> > + [CXL_LOG_COMMAND_EFFECT] = { .param_flags = 0, .uuid = CEL_UUID },
>> > };
>> >
>> > void cxl_init_cci(CXLCCI *cci, size_t payload_max)
>> >
>>
>>
>> Actually no, does not help either. Dropped for now.
>> Next patch does not depend on this one, right?
>
>Indeed. Unrelated.
>
>Thanks,
>
>J
Thanks for pointing this out. The code builds successfully on my setup
with gcc version: 11.4.0. However, it fails to compile on gcc 7.5.0
"cc (SUSE Linux) 7.5.0" as used by Michael. This could be a compiler
issue as per the link:
https://stackoverflow.com/questions/54135942/why-initializer-
element-is-not-a-constant-is-not-working-anymore.
My setup doesn't allow me to regenerate the error using lower version
of compiler. A probable fix to it would be
type casting cel_uuid as: [CXL_LOG_COMMAND_EFFECT] =
{ .param_flags = 0,.uuid = (QemuUUID)cel_uuid }. It will be helpful
if you could test the same.
Also, In the existing code,
function: cmd_logs_get_supported(), cel_uuid(const) is assigned to a
non-const variable but I am unsure of why it is not throwing an error.
Thanks,
Arpit
>>
>> > > void cxl_init_cci(CXLCCI *cci, size_t payload_max)
>> > > {
>> > > cci->payload_max = payload_max;
>> > > cxl_rebuild_cel(cci);
>> > > + cci->supported_log_cap = cxl_get_log_cap;
>> > >
>> > > cci->bg.complete_pct = 0;
>> > > cci->bg.starttime = 0;
>> > > --
>> > > 2.43.0
>>
>>
>
[-- Attachment #2: Type: text/plain, Size: 0 bytes --]
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH qemu 7/8] hw/cxl/cxl-mailbox-utils: Added support for Get Log Capabilities (Opcode 0402h)
2025-05-16 13:42 ` Arpit Kumar
@ 2025-05-28 12:31 ` Jonathan Cameron via
2025-05-28 12:38 ` Jonathan Cameron via
0 siblings, 1 reply; 17+ messages in thread
From: Jonathan Cameron via @ 2025-05-28 12:31 UTC (permalink / raw)
To: Arpit Kumar
Cc: Michael S. Tsirkin, linux-cxl, qemu-devel, linuxarm, fan.ni,
Yuquan Wang, Sweta Kumari, Vinayak Holikatti, Davidlohr Bueso,
Ajay Joshi, cpgs
On Fri, 16 May 2025 19:12:45 +0530
Arpit Kumar <arpit1.kumar@samsung.com> wrote:
> On 12/05/25 05:40PM, Jonathan Cameron wrote:
> >On Mon, 12 May 2025 09:37:07 -0400
> >"Michael S. Tsirkin" <mst@redhat.com> wrote:
> >
> >> On Mon, May 12, 2025 at 04:42:41AM -0400, Michael S. Tsirkin wrote:
> >> > On Wed, Mar 05, 2025 at 09:24:58AM +0000, Jonathan Cameron wrote:
> >> > > From: Arpit Kumar <arpit1.kumar@samsung.com>
> >> > >
> >> > > CXL spec 3.2 section 8.2.10.5.3 describes Get Log Capabilities.
> >> > > It provides log capabilities supported by specified log.
> >> > >
> >> > > Signed-off-by: Arpit Kumar <arpit1.kumar@samsung.com>
> >> > > Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> >> > > ---
> >> > > include/hw/cxl/cxl_device.h | 20 ++++++++++++++++
> >> > > include/hw/cxl/cxl_mailbox.h | 5 ++++
> >> > > hw/cxl/cxl-mailbox-utils.c | 45 ++++++++++++++++++++++++++++++++++++
> >> > > 3 files changed, 70 insertions(+)
> >> > >
> >> > > diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h
> >> > > index ed6cd50c67..87a376c982 100644
> >> > > --- a/include/hw/cxl/cxl_device.h
> >> > > +++ b/include/hw/cxl/cxl_device.h
> >> > > @@ -133,6 +133,18 @@ typedef enum {
> >> > > CXL_MBOX_MAX = 0x20
> >> > > } CXLRetCode;
> >> > >
> >> > > +/* types of logs */
> >> > > +typedef enum {
> >> > > + CXL_LOG_COMMAND_EFFECT,
> >> > > + CXL_LOG_VENDOR_DEBUG,
> >> > > + CXL_LOG_COMPONENT_STATE_DUMP,
> >> > > + CXL_LOG_ERROR_CHECK_SCRUB,
> >> > > + CXL_LOG_MEDIA_TEST_CAPABILITY,
> >> > > + CXL_LOG_MEDIA_TEST_RESULTS_SHORT,
> >> > > + CXL_LOG_MEDIA_TEST_RESULTS_LONG,
> >> > > + MAX_LOG_TYPE
> >> > > +} CXLLogType;
> >> > > +
> >> > > typedef struct CXLCCI CXLCCI;
> >> > > typedef struct cxl_device_state CXLDeviceState;
> >> > > struct cxl_cmd;
> >> > > @@ -163,6 +175,11 @@ typedef struct CXLEventLog {
> >> > > QSIMPLEQ_HEAD(, CXLEvent) events;
> >> > > } CXLEventLog;
> >> > >
> >> > > +typedef struct CXLLogCapabilities {
> >> > > + uint32_t param_flags;
> >> > > + QemuUUID uuid;
> >> > > +} CXLLogCapabilities;
> >> > > +
> >> > > typedef struct CXLCCI {
> >> > > struct cxl_cmd cxl_cmd_set[256][256];
> >> > > struct cel_log {
> >> > > @@ -171,6 +188,9 @@ typedef struct CXLCCI {
> >> > > } cel_log[1 << 16];
> >> > > size_t cel_size;
> >> > >
> >> > > + /* get log capabilities */
> >> > > + const CXLLogCapabilities *supported_log_cap;
> >> > > +
> >> > > /* background command handling (times in ms) */
> >> > > struct {
> >> > > uint16_t opcode;
> >> > > diff --git a/include/hw/cxl/cxl_mailbox.h b/include/hw/cxl/cxl_mailbox.h
> >> > > index 9008402d1c..8e1c7c5f15 100644
> >> > > --- a/include/hw/cxl/cxl_mailbox.h
> >> > > +++ b/include/hw/cxl/cxl_mailbox.h
> >> > > @@ -16,4 +16,9 @@
> >> > > #define CXL_MBOX_BACKGROUND_OPERATION (1 << 6)
> >> > > #define CXL_MBOX_BACKGROUND_OPERATION_ABORT (1 << 7)
> >> > >
> >> > > +#define CXL_LOG_CAP_CLEAR_SUPPORTED (1 << 0)
> >> > > +#define CXL_LOG_CAP_POPULATE_SUPPORTED (1 << 1)
> >> > > +#define CXL_LOG_CAP_AUTO_POPULATE_SUPPORTED (1 << 2)
> >> > > +#define CXL_LOG_CAP_PERSISTENT_COLD_RESET_SUPPORTED (1 << 3)
> >> > > +
> >> > > #endif
> >> > > diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
> >> > > index 299f232f26..f35fc4f112 100644
> >> > > --- a/hw/cxl/cxl-mailbox-utils.c
> >> > > +++ b/hw/cxl/cxl-mailbox-utils.c
> >> > > @@ -81,6 +81,7 @@ enum {
> >> > > LOGS = 0x04,
> >> > > #define GET_SUPPORTED 0x0
> >> > > #define GET_LOG 0x1
> >> > > + #define GET_LOG_CAPABILITIES 0x2
> >> > > FEATURES = 0x05,
> >> > > #define GET_SUPPORTED 0x0
> >> > > #define GET_FEATURE 0x1
> >> > > @@ -1068,6 +1069,43 @@ static CXLRetCode cmd_logs_get_log(const struct cxl_cmd *cmd,
> >> > > return CXL_MBOX_SUCCESS;
> >> > > }
> >> > >
> >> > > +static const struct CXLLogCapabilities *find_log_index(QemuUUID *uuid, CXLCCI *cci)
> >> > > +{
> >> > > + for (int i = CXL_LOG_COMMAND_EFFECT; i < MAX_LOG_TYPE; i++) {
> >> > > + if (qemu_uuid_is_equal(uuid,
> >> > > + &cci->supported_log_cap[i].uuid)) {
> >> > > + return &cci->supported_log_cap[i];
> >> > > + }
> >> > > + }
> >> > > + return NULL;
> >> > > +}
> >> > > +
> >> > > +/* CXL r3.2 Section 8.2.10.5.3: Get Log Capabilities (Opcode 0402h) */
> >> > > +static CXLRetCode cmd_logs_get_log_capabilities(const struct cxl_cmd *cmd,
> >> > > + uint8_t *payload_in,
> >> > > + size_t len_in,
> >> > > + uint8_t *payload_out,
> >> > > + size_t *len_out,
> >> > > + CXLCCI *cci)
> >> > > +{
> >> > > + const CXLLogCapabilities *cap;
> >> > > + struct {
> >> > > + QemuUUID uuid;
> >> > > + } QEMU_PACKED QEMU_ALIGNED(8) *get_log_capabilities_in = (void *)payload_in;
> >> > > +
> >> > > + uint32_t *get_log_capabilities_out = (uint32_t *)payload_out;
> >> > > +
> >> > > + cap = find_log_index(&get_log_capabilities_in->uuid, cci);
> >> > > + if (!cap) {
> >> > > + return CXL_MBOX_INVALID_LOG;
> >> > > + }
> >> > > +
> >> > > + memcpy(get_log_capabilities_out, &cap->param_flags,
> >> > > + sizeof(cap->param_flags));
> >> > > + *len_out = sizeof(*get_log_capabilities_out);
> >> > > + return CXL_MBOX_SUCCESS;
> >> > > +}
> >> > > +
> >> > > /* CXL r3.1 section 8.2.9.6: Features */
> >> > > /*
> >> > > * Get Supported Features output payload
> >> > > @@ -3253,6 +3291,8 @@ static const struct cxl_cmd cxl_cmd_set[256][256] = {
> >> > > [LOGS][GET_SUPPORTED] = { "LOGS_GET_SUPPORTED", cmd_logs_get_supported,
> >> > > 0, 0 },
> >> > > [LOGS][GET_LOG] = { "LOGS_GET_LOG", cmd_logs_get_log, 0x18, 0 },
> >> > > + [LOGS][GET_LOG_CAPABILITIES] = { "LOGS_GET_LOG_CAPABILITIES",
> >> > > + cmd_logs_get_log_capabilities, 0x10, 0 },
> >> > > [FEATURES][GET_SUPPORTED] = { "FEATURES_GET_SUPPORTED",
> >> > > cmd_features_get_supported, 0x8, 0 },
> >> > > [FEATURES][GET_FEATURE] = { "FEATURES_GET_FEATURE",
> >> > > @@ -3512,10 +3552,15 @@ static void cxl_rebuild_cel(CXLCCI *cci)
> >> > > }
> >> > > }
> >> > >
> >> > > +static const struct CXLLogCapabilities cxl_get_log_cap[MAX_LOG_TYPE] = {
> >> > > + [CXL_LOG_COMMAND_EFFECT] = { .param_flags = 0, .uuid = cel_uuid },
> >> > > +};
> >> > > +
> >> >
> >> >
> >> > causes ci build failures:
> >> >
> >> > https://gitlab.com/mstredhat/qemu/-/jobs/9999980051
> >> >
> >> > ../hw/cxl/cxl-mailbox-utils.c:3556:60: error: initializer element is not constant
> >> > [CXL_LOG_COMMAND_EFFECT] = { .param_flags = 0, .uuid = cel_uuid },
> >> > ^~~~~~~~
> >> > ../hw/cxl/cxl-mailbox-utils.c:3556:60: note: (near initialization for ‘cxl_get_log_cap[0].uuid’)
> >> >
> >> >
> >> > Fixed it up like this:
> >> >
> >> > diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
> >> > index f35fc4f112..13d26e391b 100644
> >> > --- a/hw/cxl/cxl-mailbox-utils.c
> >> > +++ b/hw/cxl/cxl-mailbox-utils.c
> >> > @@ -992,9 +992,10 @@ static CXLRetCode cmd_timestamp_set(const struct cxl_cmd *cmd,
> >> > }
> >> >
> >> > /* CXL r3.1 Section 8.2.9.5.2.1: Command Effects Log (CEL) */
> >> > -static const QemuUUID cel_uuid = {
> >> > - .data = UUID(0x0da9c0b5, 0xbf41, 0x4b78, 0x8f, 0x79,
> >> > +#define CEL_UUID UUID(0x0da9c0b5, 0xbf41, 0x4b78, 0x8f, 0x79, \
> >> > 0x96, 0xb1, 0x62, 0x3b, 0x3f, 0x17)
> >> > +static const QemuUUID cel_uuid = {
> >> > + .data = CEL_UUID
> >> > };
> >> >
> >> > /* CXL r3.1 Section 8.2.9.5.1: Get Supported Logs (Opcode 0400h) */
> >> > @@ -3553,7 +3554,7 @@ static void cxl_rebuild_cel(CXLCCI *cci)
> >> > }
> >> >
> >> > static const struct CXLLogCapabilities cxl_get_log_cap[MAX_LOG_TYPE] = {
> >> > - [CXL_LOG_COMMAND_EFFECT] = { .param_flags = 0, .uuid = cel_uuid },
> >> > + [CXL_LOG_COMMAND_EFFECT] = { .param_flags = 0, .uuid = CEL_UUID },
> >> > };
> >> >
> >> > void cxl_init_cci(CXLCCI *cci, size_t payload_max)
> >> >
> >>
> >>
> >> Actually no, does not help either. Dropped for now.
> >> Next patch does not depend on this one, right?
> >
> >Indeed. Unrelated.
> >
> >Thanks,
> >
> >J
>
> Thanks for pointing this out. The code builds successfully on my setup
> with gcc version: 11.4.0. However, it fails to compile on gcc 7.5.0
> "cc (SUSE Linux) 7.5.0" as used by Michael. This could be a compiler
> issue as per the link:
> https://stackoverflow.com/questions/54135942/why-initializer-
> element-is-not-a-constant-is-not-working-anymore.
>
> My setup doesn't allow me to regenerate the error using lower version
> of compiler. A probable fix to it would be
> type casting cel_uuid as: [CXL_LOG_COMMAND_EFFECT] =
> { .param_flags = 0,.uuid = (QemuUUID)cel_uuid }. It will be helpful
> if you could test the same.
I wonder if we are better off just filling it in in cxl_init_cci()
So change the type of the element in struct CXLCCI to
CXLLogCapabiliites supported_log_cap[MAX_LOGS];
then assign the elements at runtime.
That should avoid any issues with whether it is const or not at the
cost of a little more code.
>
> Also, In the existing code,
> function: cmd_logs_get_supported(), cel_uuid(const) is assigned to a
> non-const variable but I am unsure of why it is not throwing an error.
Isn't it just copying the content which should be fine?
>
> Thanks,
> Arpit
> >>
> >> > > void cxl_init_cci(CXLCCI *cci, size_t payload_max)
> >> > > {
> >> > > cci->payload_max = payload_max;
> >> > > cxl_rebuild_cel(cci);
> >> > > + cci->supported_log_cap = cxl_get_log_cap;
> >> > >
> >> > > cci->bg.complete_pct = 0;
> >> > > cci->bg.starttime = 0;
> >> > > --
> >> > > 2.43.0
> >>
> >>
> >
>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH qemu 7/8] hw/cxl/cxl-mailbox-utils: Added support for Get Log Capabilities (Opcode 0402h)
2025-05-28 12:31 ` Jonathan Cameron via
@ 2025-05-28 12:38 ` Jonathan Cameron via
2025-05-29 11:45 ` Arpit Kumar
0 siblings, 1 reply; 17+ messages in thread
From: Jonathan Cameron via @ 2025-05-28 12:38 UTC (permalink / raw)
To: Arpit Kumar
Cc: Michael S. Tsirkin, linux-cxl, qemu-devel, linuxarm, fan.ni,
Yuquan Wang, Sweta Kumari, Vinayak Holikatti, Davidlohr Bueso,
Ajay Joshi, cpgs
On Wed, 28 May 2025 13:31:06 +0100
Jonathan Cameron <Jonathan.Cameron@huawei.com> wrote:
> On Fri, 16 May 2025 19:12:45 +0530
> Arpit Kumar <arpit1.kumar@samsung.com> wrote:
>
> > On 12/05/25 05:40PM, Jonathan Cameron wrote:
> > >On Mon, 12 May 2025 09:37:07 -0400
> > >"Michael S. Tsirkin" <mst@redhat.com> wrote:
> > >
> > >> On Mon, May 12, 2025 at 04:42:41AM -0400, Michael S. Tsirkin wrote:
> > >> > On Wed, Mar 05, 2025 at 09:24:58AM +0000, Jonathan Cameron wrote:
> > >> > > From: Arpit Kumar <arpit1.kumar@samsung.com>
> > >> > >
> > >> > > CXL spec 3.2 section 8.2.10.5.3 describes Get Log Capabilities.
> > >> > > It provides log capabilities supported by specified log.
> > >> > >
> > >> > > Signed-off-by: Arpit Kumar <arpit1.kumar@samsung.com>
> > >> > > Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > >> > > ---
> > >> > > include/hw/cxl/cxl_device.h | 20 ++++++++++++++++
> > >> > > include/hw/cxl/cxl_mailbox.h | 5 ++++
> > >> > > hw/cxl/cxl-mailbox-utils.c | 45 ++++++++++++++++++++++++++++++++++++
> > >> > > 3 files changed, 70 insertions(+)
> > >> > >
> > >> > > diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h
> > >> > > index ed6cd50c67..87a376c982 100644
> > >> > > --- a/include/hw/cxl/cxl_device.h
> > >> > > +++ b/include/hw/cxl/cxl_device.h
> > >> > > @@ -133,6 +133,18 @@ typedef enum {
> > >> > > CXL_MBOX_MAX = 0x20
> > >> > > } CXLRetCode;
> > >> > >
> > >> > > +/* types of logs */
> > >> > > +typedef enum {
> > >> > > + CXL_LOG_COMMAND_EFFECT,
> > >> > > + CXL_LOG_VENDOR_DEBUG,
> > >> > > + CXL_LOG_COMPONENT_STATE_DUMP,
> > >> > > + CXL_LOG_ERROR_CHECK_SCRUB,
> > >> > > + CXL_LOG_MEDIA_TEST_CAPABILITY,
> > >> > > + CXL_LOG_MEDIA_TEST_RESULTS_SHORT,
> > >> > > + CXL_LOG_MEDIA_TEST_RESULTS_LONG,
> > >> > > + MAX_LOG_TYPE
> > >> > > +} CXLLogType;
> > >> > > +
> > >> > > typedef struct CXLCCI CXLCCI;
> > >> > > typedef struct cxl_device_state CXLDeviceState;
> > >> > > struct cxl_cmd;
> > >> > > @@ -163,6 +175,11 @@ typedef struct CXLEventLog {
> > >> > > QSIMPLEQ_HEAD(, CXLEvent) events;
> > >> > > } CXLEventLog;
> > >> > >
> > >> > > +typedef struct CXLLogCapabilities {
> > >> > > + uint32_t param_flags;
> > >> > > + QemuUUID uuid;
> > >> > > +} CXLLogCapabilities;
> > >> > > +
> > >> > > typedef struct CXLCCI {
> > >> > > struct cxl_cmd cxl_cmd_set[256][256];
> > >> > > struct cel_log {
> > >> > > @@ -171,6 +188,9 @@ typedef struct CXLCCI {
> > >> > > } cel_log[1 << 16];
> > >> > > size_t cel_size;
> > >> > >
> > >> > > + /* get log capabilities */
> > >> > > + const CXLLogCapabilities *supported_log_cap;
> > >> > > +
> > >> > > /* background command handling (times in ms) */
> > >> > > struct {
> > >> > > uint16_t opcode;
> > >> > > diff --git a/include/hw/cxl/cxl_mailbox.h b/include/hw/cxl/cxl_mailbox.h
> > >> > > index 9008402d1c..8e1c7c5f15 100644
> > >> > > --- a/include/hw/cxl/cxl_mailbox.h
> > >> > > +++ b/include/hw/cxl/cxl_mailbox.h
> > >> > > @@ -16,4 +16,9 @@
> > >> > > #define CXL_MBOX_BACKGROUND_OPERATION (1 << 6)
> > >> > > #define CXL_MBOX_BACKGROUND_OPERATION_ABORT (1 << 7)
> > >> > >
> > >> > > +#define CXL_LOG_CAP_CLEAR_SUPPORTED (1 << 0)
> > >> > > +#define CXL_LOG_CAP_POPULATE_SUPPORTED (1 << 1)
> > >> > > +#define CXL_LOG_CAP_AUTO_POPULATE_SUPPORTED (1 << 2)
> > >> > > +#define CXL_LOG_CAP_PERSISTENT_COLD_RESET_SUPPORTED (1 << 3)
> > >> > > +
> > >> > > #endif
> > >> > > diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
> > >> > > index 299f232f26..f35fc4f112 100644
> > >> > > --- a/hw/cxl/cxl-mailbox-utils.c
> > >> > > +++ b/hw/cxl/cxl-mailbox-utils.c
> > >> > > @@ -81,6 +81,7 @@ enum {
> > >> > > LOGS = 0x04,
> > >> > > #define GET_SUPPORTED 0x0
> > >> > > #define GET_LOG 0x1
> > >> > > + #define GET_LOG_CAPABILITIES 0x2
> > >> > > FEATURES = 0x05,
> > >> > > #define GET_SUPPORTED 0x0
> > >> > > #define GET_FEATURE 0x1
> > >> > > @@ -1068,6 +1069,43 @@ static CXLRetCode cmd_logs_get_log(const struct cxl_cmd *cmd,
> > >> > > return CXL_MBOX_SUCCESS;
> > >> > > }
> > >> > >
> > >> > > +static const struct CXLLogCapabilities *find_log_index(QemuUUID *uuid, CXLCCI *cci)
> > >> > > +{
> > >> > > + for (int i = CXL_LOG_COMMAND_EFFECT; i < MAX_LOG_TYPE; i++) {
> > >> > > + if (qemu_uuid_is_equal(uuid,
> > >> > > + &cci->supported_log_cap[i].uuid)) {
> > >> > > + return &cci->supported_log_cap[i];
> > >> > > + }
> > >> > > + }
> > >> > > + return NULL;
> > >> > > +}
> > >> > > +
> > >> > > +/* CXL r3.2 Section 8.2.10.5.3: Get Log Capabilities (Opcode 0402h) */
> > >> > > +static CXLRetCode cmd_logs_get_log_capabilities(const struct cxl_cmd *cmd,
> > >> > > + uint8_t *payload_in,
> > >> > > + size_t len_in,
> > >> > > + uint8_t *payload_out,
> > >> > > + size_t *len_out,
> > >> > > + CXLCCI *cci)
> > >> > > +{
> > >> > > + const CXLLogCapabilities *cap;
> > >> > > + struct {
> > >> > > + QemuUUID uuid;
> > >> > > + } QEMU_PACKED QEMU_ALIGNED(8) *get_log_capabilities_in = (void *)payload_in;
> > >> > > +
> > >> > > + uint32_t *get_log_capabilities_out = (uint32_t *)payload_out;
> > >> > > +
> > >> > > + cap = find_log_index(&get_log_capabilities_in->uuid, cci);
> > >> > > + if (!cap) {
> > >> > > + return CXL_MBOX_INVALID_LOG;
> > >> > > + }
> > >> > > +
> > >> > > + memcpy(get_log_capabilities_out, &cap->param_flags,
> > >> > > + sizeof(cap->param_flags));
> > >> > > + *len_out = sizeof(*get_log_capabilities_out);
> > >> > > + return CXL_MBOX_SUCCESS;
> > >> > > +}
> > >> > > +
> > >> > > /* CXL r3.1 section 8.2.9.6: Features */
> > >> > > /*
> > >> > > * Get Supported Features output payload
> > >> > > @@ -3253,6 +3291,8 @@ static const struct cxl_cmd cxl_cmd_set[256][256] = {
> > >> > > [LOGS][GET_SUPPORTED] = { "LOGS_GET_SUPPORTED", cmd_logs_get_supported,
> > >> > > 0, 0 },
> > >> > > [LOGS][GET_LOG] = { "LOGS_GET_LOG", cmd_logs_get_log, 0x18, 0 },
> > >> > > + [LOGS][GET_LOG_CAPABILITIES] = { "LOGS_GET_LOG_CAPABILITIES",
> > >> > > + cmd_logs_get_log_capabilities, 0x10, 0 },
> > >> > > [FEATURES][GET_SUPPORTED] = { "FEATURES_GET_SUPPORTED",
> > >> > > cmd_features_get_supported, 0x8, 0 },
> > >> > > [FEATURES][GET_FEATURE] = { "FEATURES_GET_FEATURE",
> > >> > > @@ -3512,10 +3552,15 @@ static void cxl_rebuild_cel(CXLCCI *cci)
> > >> > > }
> > >> > > }
> > >> > >
> > >> > > +static const struct CXLLogCapabilities cxl_get_log_cap[MAX_LOG_TYPE] = {
> > >> > > + [CXL_LOG_COMMAND_EFFECT] = { .param_flags = 0, .uuid = cel_uuid },
> > >> > > +};
> > >> > > +
> > >> >
> > >> >
> > >> > causes ci build failures:
> > >> >
> > >> > https://gitlab.com/mstredhat/qemu/-/jobs/9999980051
> > >> >
> > >> > ../hw/cxl/cxl-mailbox-utils.c:3556:60: error: initializer element is not constant
> > >> > [CXL_LOG_COMMAND_EFFECT] = { .param_flags = 0, .uuid = cel_uuid },
> > >> > ^~~~~~~~
> > >> > ../hw/cxl/cxl-mailbox-utils.c:3556:60: note: (near initialization for ‘cxl_get_log_cap[0].uuid’)
> > >> >
> > >> >
> > >> > Fixed it up like this:
> > >> >
> > >> > diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
> > >> > index f35fc4f112..13d26e391b 100644
> > >> > --- a/hw/cxl/cxl-mailbox-utils.c
> > >> > +++ b/hw/cxl/cxl-mailbox-utils.c
> > >> > @@ -992,9 +992,10 @@ static CXLRetCode cmd_timestamp_set(const struct cxl_cmd *cmd,
> > >> > }
> > >> >
> > >> > /* CXL r3.1 Section 8.2.9.5.2.1: Command Effects Log (CEL) */
> > >> > -static const QemuUUID cel_uuid = {
> > >> > - .data = UUID(0x0da9c0b5, 0xbf41, 0x4b78, 0x8f, 0x79,
> > >> > +#define CEL_UUID UUID(0x0da9c0b5, 0xbf41, 0x4b78, 0x8f, 0x79, \
> > >> > 0x96, 0xb1, 0x62, 0x3b, 0x3f, 0x17)
> > >> > +static const QemuUUID cel_uuid = {
> > >> > + .data = CEL_UUID
> > >> > };
> > >> >
> > >> > /* CXL r3.1 Section 8.2.9.5.1: Get Supported Logs (Opcode 0400h) */
> > >> > @@ -3553,7 +3554,7 @@ static void cxl_rebuild_cel(CXLCCI *cci)
> > >> > }
> > >> >
> > >> > static const struct CXLLogCapabilities cxl_get_log_cap[MAX_LOG_TYPE] = {
> > >> > - [CXL_LOG_COMMAND_EFFECT] = { .param_flags = 0, .uuid = cel_uuid },
> > >> > + [CXL_LOG_COMMAND_EFFECT] = { .param_flags = 0, .uuid = CEL_UUID },
> > >> > };
> > >> >
> > >> > void cxl_init_cci(CXLCCI *cci, size_t payload_max)
> > >> >
> > >>
> > >>
> > >> Actually no, does not help either. Dropped for now.
> > >> Next patch does not depend on this one, right?
> > >
> > >Indeed. Unrelated.
> > >
> > >Thanks,
> > >
> > >J
> >
> > Thanks for pointing this out. The code builds successfully on my setup
> > with gcc version: 11.4.0. However, it fails to compile on gcc 7.5.0
> > "cc (SUSE Linux) 7.5.0" as used by Michael. This could be a compiler
> > issue as per the link:
> > https://stackoverflow.com/questions/54135942/why-initializer-
> > element-is-not-a-constant-is-not-working-anymore.
> >
> > My setup doesn't allow me to regenerate the error using lower version
> > of compiler. A probable fix to it would be
> > type casting cel_uuid as: [CXL_LOG_COMMAND_EFFECT] =
> > { .param_flags = 0,.uuid = (QemuUUID)cel_uuid }. It will be helpful
> > if you could test the same.
>
> I wonder if we are better off just filling it in in cxl_init_cci()
> So change the type of the element in struct CXLCCI to
> CXLLogCapabiliites supported_log_cap[MAX_LOGS];
>
> then assign the elements at runtime.
>
> That should avoid any issues with whether it is const or not at the
> cost of a little more code.
e.g.
diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h
index 87a376c982..86fc6e03a1 100644
--- a/include/hw/cxl/cxl_device.h
+++ b/include/hw/cxl/cxl_device.h
@@ -189,7 +189,7 @@ typedef struct CXLCCI {
size_t cel_size;
/* get log capabilities */
- const CXLLogCapabilities *supported_log_cap;
+ CXLLogCapabilities supported_log_cap[MAX_LOG_TYPE];
/* background command handling (times in ms) */
struct {
diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
index f35fc4f112..4ef81c058e 100644
--- a/hw/cxl/cxl-mailbox-utils.c
+++ b/hw/cxl/cxl-mailbox-utils.c
@@ -3552,15 +3552,14 @@ static void cxl_rebuild_cel(CXLCCI *cci)
}
}
-static const struct CXLLogCapabilities cxl_get_log_cap[MAX_LOG_TYPE] = {
- [CXL_LOG_COMMAND_EFFECT] = { .param_flags = 0, .uuid = cel_uuid },
-};
-
void cxl_init_cci(CXLCCI *cci, size_t payload_max)
{
cci->payload_max = payload_max;
cxl_rebuild_cel(cci);
- cci->supported_log_cap = cxl_get_log_cap;
+ cci->supported_log_cap[0] = (CXLLogCapabilities) {
+ .param_flags = 0,
+ .uuid = cel_uuid,
+ };
cci->bg.complete_pct = 0;
cci->bg.starttime = 0;
Should I think do the job.
I don't have a test to hand for this, so please let me know if I messed it up!
>
> >
> > Also, In the existing code,
> > function: cmd_logs_get_supported(), cel_uuid(const) is assigned to a
> > non-const variable but I am unsure of why it is not throwing an error.
>
> Isn't it just copying the content which should be fine?
>
> >
> > Thanks,
> > Arpit
> > >>
> > >> > > void cxl_init_cci(CXLCCI *cci, size_t payload_max)
> > >> > > {
> > >> > > cci->payload_max = payload_max;
> > >> > > cxl_rebuild_cel(cci);
> > >> > > + cci->supported_log_cap = cxl_get_log_cap;
> > >> > >
> > >> > > cci->bg.complete_pct = 0;
> > >> > > cci->bg.starttime = 0;
> > >> > > --
> > >> > > 2.43.0
> > >>
> > >>
> > >
> >
>
>
^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH qemu 7/8] hw/cxl/cxl-mailbox-utils: Added support for Get Log Capabilities (Opcode 0402h)
2025-05-28 12:38 ` Jonathan Cameron via
@ 2025-05-29 11:45 ` Arpit Kumar
0 siblings, 0 replies; 17+ messages in thread
From: Arpit Kumar @ 2025-05-29 11:45 UTC (permalink / raw)
To: Jonathan Cameron
Cc: Michael S. Tsirkin, linux-cxl, qemu-devel, linuxarm, fan.ni,
Yuquan Wang, Sweta Kumari, Vinayak Holikatti, Davidlohr Bueso,
Ajay Joshi, cpgs
[-- Attachment #1: Type: text/plain, Size: 12640 bytes --]
On 28/05/25 01:38PM, Jonathan Cameron wrote:
>On Wed, 28 May 2025 13:31:06 +0100
>Jonathan Cameron <Jonathan.Cameron@huawei.com> wrote:
>
>> On Fri, 16 May 2025 19:12:45 +0530
>> Arpit Kumar <arpit1.kumar@samsung.com> wrote:
>>
>> > On 12/05/25 05:40PM, Jonathan Cameron wrote:
>> > >On Mon, 12 May 2025 09:37:07 -0400
>> > >"Michael S. Tsirkin" <mst@redhat.com> wrote:
>> > >
>> > >> On Mon, May 12, 2025 at 04:42:41AM -0400, Michael S. Tsirkin wrote:
>> > >> > On Wed, Mar 05, 2025 at 09:24:58AM +0000, Jonathan Cameron wrote:
>> > >> > > From: Arpit Kumar <arpit1.kumar@samsung.com>
>> > >> > >
>> > >> > > CXL spec 3.2 section 8.2.10.5.3 describes Get Log Capabilities.
>> > >> > > It provides log capabilities supported by specified log.
>> > >> > >
>> > >> > > Signed-off-by: Arpit Kumar <arpit1.kumar@samsung.com>
>> > >> > > Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>> > >> > > ---
>> > >> > > include/hw/cxl/cxl_device.h | 20 ++++++++++++++++
>> > >> > > include/hw/cxl/cxl_mailbox.h | 5 ++++
>> > >> > > hw/cxl/cxl-mailbox-utils.c | 45 ++++++++++++++++++++++++++++++++++++
>> > >> > > 3 files changed, 70 insertions(+)
>> > >> > >
>> > >> > > diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h
>> > >> > > index ed6cd50c67..87a376c982 100644
>> > >> > > --- a/include/hw/cxl/cxl_device.h
>> > >> > > +++ b/include/hw/cxl/cxl_device.h
>> > >> > > @@ -133,6 +133,18 @@ typedef enum {
>> > >> > > CXL_MBOX_MAX = 0x20
>> > >> > > } CXLRetCode;
>> > >> > >
>> > >> > > +/* types of logs */
>> > >> > > +typedef enum {
>> > >> > > + CXL_LOG_COMMAND_EFFECT,
>> > >> > > + CXL_LOG_VENDOR_DEBUG,
>> > >> > > + CXL_LOG_COMPONENT_STATE_DUMP,
>> > >> > > + CXL_LOG_ERROR_CHECK_SCRUB,
>> > >> > > + CXL_LOG_MEDIA_TEST_CAPABILITY,
>> > >> > > + CXL_LOG_MEDIA_TEST_RESULTS_SHORT,
>> > >> > > + CXL_LOG_MEDIA_TEST_RESULTS_LONG,
>> > >> > > + MAX_LOG_TYPE
>> > >> > > +} CXLLogType;
>> > >> > > +
>> > >> > > typedef struct CXLCCI CXLCCI;
>> > >> > > typedef struct cxl_device_state CXLDeviceState;
>> > >> > > struct cxl_cmd;
>> > >> > > @@ -163,6 +175,11 @@ typedef struct CXLEventLog {
>> > >> > > QSIMPLEQ_HEAD(, CXLEvent) events;
>> > >> > > } CXLEventLog;
>> > >> > >
>> > >> > > +typedef struct CXLLogCapabilities {
>> > >> > > + uint32_t param_flags;
>> > >> > > + QemuUUID uuid;
>> > >> > > +} CXLLogCapabilities;
>> > >> > > +
>> > >> > > typedef struct CXLCCI {
>> > >> > > struct cxl_cmd cxl_cmd_set[256][256];
>> > >> > > struct cel_log {
>> > >> > > @@ -171,6 +188,9 @@ typedef struct CXLCCI {
>> > >> > > } cel_log[1 << 16];
>> > >> > > size_t cel_size;
>> > >> > >
>> > >> > > + /* get log capabilities */
>> > >> > > + const CXLLogCapabilities *supported_log_cap;
>> > >> > > +
>> > >> > > /* background command handling (times in ms) */
>> > >> > > struct {
>> > >> > > uint16_t opcode;
>> > >> > > diff --git a/include/hw/cxl/cxl_mailbox.h b/include/hw/cxl/cxl_mailbox.h
>> > >> > > index 9008402d1c..8e1c7c5f15 100644
>> > >> > > --- a/include/hw/cxl/cxl_mailbox.h
>> > >> > > +++ b/include/hw/cxl/cxl_mailbox.h
>> > >> > > @@ -16,4 +16,9 @@
>> > >> > > #define CXL_MBOX_BACKGROUND_OPERATION (1 << 6)
>> > >> > > #define CXL_MBOX_BACKGROUND_OPERATION_ABORT (1 << 7)
>> > >> > >
>> > >> > > +#define CXL_LOG_CAP_CLEAR_SUPPORTED (1 << 0)
>> > >> > > +#define CXL_LOG_CAP_POPULATE_SUPPORTED (1 << 1)
>> > >> > > +#define CXL_LOG_CAP_AUTO_POPULATE_SUPPORTED (1 << 2)
>> > >> > > +#define CXL_LOG_CAP_PERSISTENT_COLD_RESET_SUPPORTED (1 << 3)
>> > >> > > +
>> > >> > > #endif
>> > >> > > diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
>> > >> > > index 299f232f26..f35fc4f112 100644
>> > >> > > --- a/hw/cxl/cxl-mailbox-utils.c
>> > >> > > +++ b/hw/cxl/cxl-mailbox-utils.c
>> > >> > > @@ -81,6 +81,7 @@ enum {
>> > >> > > LOGS = 0x04,
>> > >> > > #define GET_SUPPORTED 0x0
>> > >> > > #define GET_LOG 0x1
>> > >> > > + #define GET_LOG_CAPABILITIES 0x2
>> > >> > > FEATURES = 0x05,
>> > >> > > #define GET_SUPPORTED 0x0
>> > >> > > #define GET_FEATURE 0x1
>> > >> > > @@ -1068,6 +1069,43 @@ static CXLRetCode cmd_logs_get_log(const struct cxl_cmd *cmd,
>> > >> > > return CXL_MBOX_SUCCESS;
>> > >> > > }
>> > >> > >
>> > >> > > +static const struct CXLLogCapabilities *find_log_index(QemuUUID *uuid, CXLCCI *cci)
>> > >> > > +{
>> > >> > > + for (int i = CXL_LOG_COMMAND_EFFECT; i < MAX_LOG_TYPE; i++) {
>> > >> > > + if (qemu_uuid_is_equal(uuid,
>> > >> > > + &cci->supported_log_cap[i].uuid)) {
>> > >> > > + return &cci->supported_log_cap[i];
>> > >> > > + }
>> > >> > > + }
>> > >> > > + return NULL;
>> > >> > > +}
>> > >> > > +
>> > >> > > +/* CXL r3.2 Section 8.2.10.5.3: Get Log Capabilities (Opcode 0402h) */
>> > >> > > +static CXLRetCode cmd_logs_get_log_capabilities(const struct cxl_cmd *cmd,
>> > >> > > + uint8_t *payload_in,
>> > >> > > + size_t len_in,
>> > >> > > + uint8_t *payload_out,
>> > >> > > + size_t *len_out,
>> > >> > > + CXLCCI *cci)
>> > >> > > +{
>> > >> > > + const CXLLogCapabilities *cap;
>> > >> > > + struct {
>> > >> > > + QemuUUID uuid;
>> > >> > > + } QEMU_PACKED QEMU_ALIGNED(8) *get_log_capabilities_in = (void *)payload_in;
>> > >> > > +
>> > >> > > + uint32_t *get_log_capabilities_out = (uint32_t *)payload_out;
>> > >> > > +
>> > >> > > + cap = find_log_index(&get_log_capabilities_in->uuid, cci);
>> > >> > > + if (!cap) {
>> > >> > > + return CXL_MBOX_INVALID_LOG;
>> > >> > > + }
>> > >> > > +
>> > >> > > + memcpy(get_log_capabilities_out, &cap->param_flags,
>> > >> > > + sizeof(cap->param_flags));
>> > >> > > + *len_out = sizeof(*get_log_capabilities_out);
>> > >> > > + return CXL_MBOX_SUCCESS;
>> > >> > > +}
>> > >> > > +
>> > >> > > /* CXL r3.1 section 8.2.9.6: Features */
>> > >> > > /*
>> > >> > > * Get Supported Features output payload
>> > >> > > @@ -3253,6 +3291,8 @@ static const struct cxl_cmd cxl_cmd_set[256][256] = {
>> > >> > > [LOGS][GET_SUPPORTED] = { "LOGS_GET_SUPPORTED", cmd_logs_get_supported,
>> > >> > > 0, 0 },
>> > >> > > [LOGS][GET_LOG] = { "LOGS_GET_LOG", cmd_logs_get_log, 0x18, 0 },
>> > >> > > + [LOGS][GET_LOG_CAPABILITIES] = { "LOGS_GET_LOG_CAPABILITIES",
>> > >> > > + cmd_logs_get_log_capabilities, 0x10, 0 },
>> > >> > > [FEATURES][GET_SUPPORTED] = { "FEATURES_GET_SUPPORTED",
>> > >> > > cmd_features_get_supported, 0x8, 0 },
>> > >> > > [FEATURES][GET_FEATURE] = { "FEATURES_GET_FEATURE",
>> > >> > > @@ -3512,10 +3552,15 @@ static void cxl_rebuild_cel(CXLCCI *cci)
>> > >> > > }
>> > >> > > }
>> > >> > >
>> > >> > > +static const struct CXLLogCapabilities cxl_get_log_cap[MAX_LOG_TYPE] = {
>> > >> > > + [CXL_LOG_COMMAND_EFFECT] = { .param_flags = 0, .uuid = cel_uuid },
>> > >> > > +};
>> > >> > > +
>> > >> >
>> > >> >
>> > >> > causes ci build failures:
>> > >> >
>> > >> > https://gitlab.com/mstredhat/qemu/-/jobs/9999980051
>> > >> >
>> > >> > ../hw/cxl/cxl-mailbox-utils.c:3556:60: error: initializer element is not constant
>> > >> > [CXL_LOG_COMMAND_EFFECT] = { .param_flags = 0, .uuid = cel_uuid },
>> > >> > ^~~~~~~~
>> > >> > ../hw/cxl/cxl-mailbox-utils.c:3556:60: note: (near initialization for ‘cxl_get_log_cap[0].uuid’)
>> > >> >
>> > >> >
>> > >> > Fixed it up like this:
>> > >> >
>> > >> > diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
>> > >> > index f35fc4f112..13d26e391b 100644
>> > >> > --- a/hw/cxl/cxl-mailbox-utils.c
>> > >> > +++ b/hw/cxl/cxl-mailbox-utils.c
>> > >> > @@ -992,9 +992,10 @@ static CXLRetCode cmd_timestamp_set(const struct cxl_cmd *cmd,
>> > >> > }
>> > >> >
>> > >> > /* CXL r3.1 Section 8.2.9.5.2.1: Command Effects Log (CEL) */
>> > >> > -static const QemuUUID cel_uuid = {
>> > >> > - .data = UUID(0x0da9c0b5, 0xbf41, 0x4b78, 0x8f, 0x79,
>> > >> > +#define CEL_UUID UUID(0x0da9c0b5, 0xbf41, 0x4b78, 0x8f, 0x79, \
>> > >> > 0x96, 0xb1, 0x62, 0x3b, 0x3f, 0x17)
>> > >> > +static const QemuUUID cel_uuid = {
>> > >> > + .data = CEL_UUID
>> > >> > };
>> > >> >
>> > >> > /* CXL r3.1 Section 8.2.9.5.1: Get Supported Logs (Opcode 0400h) */
>> > >> > @@ -3553,7 +3554,7 @@ static void cxl_rebuild_cel(CXLCCI *cci)
>> > >> > }
>> > >> >
>> > >> > static const struct CXLLogCapabilities cxl_get_log_cap[MAX_LOG_TYPE] = {
>> > >> > - [CXL_LOG_COMMAND_EFFECT] = { .param_flags = 0, .uuid = cel_uuid },
>> > >> > + [CXL_LOG_COMMAND_EFFECT] = { .param_flags = 0, .uuid = CEL_UUID },
>> > >> > };
>> > >> >
>> > >> > void cxl_init_cci(CXLCCI *cci, size_t payload_max)
>> > >> >
>> > >>
>> > >>
>> > >> Actually no, does not help either. Dropped for now.
>> > >> Next patch does not depend on this one, right?
>> > >
>> > >Indeed. Unrelated.
>> > >
>> > >Thanks,
>> > >
>> > >J
>> >
>> > Thanks for pointing this out. The code builds successfully on my setup
>> > with gcc version: 11.4.0. However, it fails to compile on gcc 7.5.0
>> > "cc (SUSE Linux) 7.5.0" as used by Michael. This could be a compiler
>> > issue as per the link:
>> > https://stackoverflow.com/questions/54135942/why-initializer-
>> > element-is-not-a-constant-is-not-working-anymore.
>> >
>> > My setup doesn't allow me to regenerate the error using lower version
>> > of compiler. A probable fix to it would be
>> > type casting cel_uuid as: [CXL_LOG_COMMAND_EFFECT] =
>> > { .param_flags = 0,.uuid = (QemuUUID)cel_uuid }. It will be helpful
>> > if you could test the same.
>>
>> I wonder if we are better off just filling it in in cxl_init_cci()
>> So change the type of the element in struct CXLCCI to
>> CXLLogCapabiliites supported_log_cap[MAX_LOGS];
>>
>> then assign the elements at runtime.
>>
>> That should avoid any issues with whether it is const or not at the
>> cost of a little more code.
>e.g.
>diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h
>index 87a376c982..86fc6e03a1 100644
>--- a/include/hw/cxl/cxl_device.h
>+++ b/include/hw/cxl/cxl_device.h
>@@ -189,7 +189,7 @@ typedef struct CXLCCI {
> size_t cel_size;
>
> /* get log capabilities */
>- const CXLLogCapabilities *supported_log_cap;
>+ CXLLogCapabilities supported_log_cap[MAX_LOG_TYPE];
>
> /* background command handling (times in ms) */
> struct {
>diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
>index f35fc4f112..4ef81c058e 100644
>--- a/hw/cxl/cxl-mailbox-utils.c
>+++ b/hw/cxl/cxl-mailbox-utils.c
>@@ -3552,15 +3552,14 @@ static void cxl_rebuild_cel(CXLCCI *cci)
> }
> }
>
>-static const struct CXLLogCapabilities cxl_get_log_cap[MAX_LOG_TYPE] = {
>- [CXL_LOG_COMMAND_EFFECT] = { .param_flags = 0, .uuid = cel_uuid },
>-};
>-
> void cxl_init_cci(CXLCCI *cci, size_t payload_max)
> {
> cci->payload_max = payload_max;
> cxl_rebuild_cel(cci);
>- cci->supported_log_cap = cxl_get_log_cap;
>+ cci->supported_log_cap[0] = (CXLLogCapabilities) {
>+ .param_flags = 0,
>+ .uuid = cel_uuid,
>+ };
>
> cci->bg.complete_pct = 0;
> cci->bg.starttime = 0;
>
>Should I think do the job.
>
>I don't have a test to hand for this, so please let me know if I messed it up!
>
Thanks Jonathan for your input. I tested the code changes
suggested by you and it is working fine.
Also, there was no compilation issue in my setup.
@michael, can you please check for compilation issues if any
observed in your setup for the same?
>>
>> >
>> > Also, In the existing code,
>> > function: cmd_logs_get_supported(), cel_uuid(const) is assigned to a
>> > non-const variable but I am unsure of why it is not throwing an error.
>>
>> Isn't it just copying the content which should be fine?
>>
>> >
>> > Thanks,
>> > Arpit
>> > >>
>> > >> > > void cxl_init_cci(CXLCCI *cci, size_t payload_max)
>> > >> > > {
>> > >> > > cci->payload_max = payload_max;
>> > >> > > cxl_rebuild_cel(cci);
>> > >> > > + cci->supported_log_cap = cxl_get_log_cap;
>> > >> > >
>> > >> > > cci->bg.complete_pct = 0;
>> > >> > > cci->bg.starttime = 0;
>> > >> > > --
>> > >> > > 2.43.0
>> > >>
>> > >>
>> > >
>> >
>>
>>
>
[-- Attachment #2: Type: text/plain, Size: 0 bytes --]
^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2025-06-02 6:54 UTC | newest]
Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-05 9:24 [PATCH qemu 0/8] hw/cxl: new features for 10.0 (possibly) Jonathan Cameron via
2025-03-05 9:24 ` [PATCH qemu 1/8] hw/cxl: Support aborting background commands Jonathan Cameron via
2025-03-05 9:24 ` [PATCH qemu 2/8] hw/cxl: Support get/set mctp response payload size Jonathan Cameron via
2025-03-05 9:24 ` [PATCH qemu 3/8] hw/cxl/cxl-mailbox-utils: Add support for Media operations discovery commands cxl r3.2 (8.2.10.9.5.3) Jonathan Cameron via
2025-03-05 9:24 ` [PATCH qemu 4/8] hw/cxl: factor out calculation of sanitize duration from cmd_santize_overwrite Jonathan Cameron via
2025-03-05 9:24 ` [PATCH qemu 5/8] hw/cxl/cxl-mailbox-utils: Media operations Sanitize and Write Zeros commands CXL r3.2(8.2.10.9.5.3) Jonathan Cameron via
2025-03-05 9:24 ` [PATCH qemu 6/8] hw/cxl/cxl-mailbox-utils: CXL CCI Get/Set alert config commands Jonathan Cameron via
2025-03-05 9:24 ` [PATCH qemu 7/8] hw/cxl/cxl-mailbox-utils: Added support for Get Log Capabilities (Opcode 0402h) Jonathan Cameron via
2025-05-12 8:42 ` Michael S. Tsirkin
2025-05-12 10:14 ` Jonathan Cameron via
2025-05-12 13:37 ` Michael S. Tsirkin
2025-05-12 16:40 ` Jonathan Cameron via
[not found] ` <CGME20250516134255epcas5p378dda7fbda7db62fe73cc6163c5e7043@epcas5p3.samsung.com>
2025-05-16 13:42 ` Arpit Kumar
2025-05-28 12:31 ` Jonathan Cameron via
2025-05-28 12:38 ` Jonathan Cameron via
2025-05-29 11:45 ` Arpit Kumar
2025-03-05 9:24 ` [PATCH qemu 8/8] docs/cxl: Add serial number for persistent-memdev Jonathan Cameron via
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).