[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 09/63] hw/cxl: Add get scan media results cmd support
From: |
Michael S. Tsirkin |
Subject: |
[PULL 09/63] hw/cxl: Add get scan media results cmd support |
Date: |
Sun, 21 Jul 2024 20:17:08 -0400 |
From: Davidlohr Bueso <dave@stgolabs.net>
Iterate over the list keeping the output payload size into account,
returning the results from a previous scan media operation. The
scan media operation does not fail prematurely due to device being
out of storage, so this implementation does not deal with the
retry/restart functionality.
Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>
Link: https://lore.kernel.org/r/20230908073152.4386-5-dave@stgolabs.net
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Message-Id: <20240705120643.959422-5-Jonathan.Cameron@huawei.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
include/hw/cxl/cxl_device.h | 1 +
hw/cxl/cxl-mailbox-utils.c | 85 +++++++++++++++++++++++++++++++++++++
2 files changed, 86 insertions(+)
diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h
index 0509d961c3..cc98553583 100644
--- a/include/hw/cxl/cxl_device.h
+++ b/include/hw/cxl/cxl_device.h
@@ -499,6 +499,7 @@ struct CXLType3Dev {
/* Poison Injection - backup */
CXLPoisonList poison_list_bkp;
CXLPoisonList scan_media_results;
+ bool scan_media_hasrun;
struct dynamic_capacity {
HostMemoryBackend *host_dc;
diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
index 3c9600c39c..82120a6e7b 100644
--- a/hw/cxl/cxl-mailbox-utils.c
+++ b/hw/cxl/cxl-mailbox-utils.c
@@ -85,6 +85,7 @@ enum {
#define CLEAR_POISON 0x2
#define GET_SCAN_MEDIA_CAPABILITIES 0x3
#define SCAN_MEDIA 0x4
+ #define GET_SCAN_MEDIA_RESULTS 0x5
DCD_CONFIG = 0x48,
#define GET_DC_CONFIG 0x0
#define GET_DYN_CAP_EXT_LIST 0x1
@@ -1339,6 +1340,8 @@ static void __do_scan_media(CXLType3Dev *ct3d)
ct3d->poison_list_cnt == results_cnt) {
cxl_clear_poison_list_overflowed(ct3d);
}
+ /* scan media has run since last conventional reset */
+ ct3d->scan_media_hasrun = true;
}
/*
@@ -1443,6 +1446,85 @@ static CXLRetCode cmd_media_scan_media(const struct
cxl_cmd *cmd,
return CXL_MBOX_BG_STARTED;
}
+/*
+ * CXL r3.1 section 8.2.9.9.4.6: Get Scan Media Results
+ */
+static CXLRetCode cmd_media_get_scan_media_results(const struct cxl_cmd *cmd,
+ uint8_t *payload_in,
+ size_t len_in,
+ uint8_t *payload_out,
+ size_t *len_out,
+ CXLCCI *cci)
+{
+ struct get_scan_media_results_out_pl {
+ uint64_t dpa_restart;
+ uint64_t length;
+ uint8_t flags;
+ uint8_t rsvd1;
+ uint16_t count;
+ uint8_t rsvd2[0xc];
+ struct {
+ uint64_t addr;
+ uint32_t length;
+ uint32_t resv;
+ } QEMU_PACKED records[];
+ } QEMU_PACKED;
+
+ struct get_scan_media_results_out_pl *out = (void *)payload_out;
+ CXLType3Dev *ct3d = CXL_TYPE3(cci->d);
+ CXLPoisonList *scan_media_results = &ct3d->scan_media_results;
+ CXLPoison *ent, *next;
+ uint16_t total_count = 0, record_count = 0, i = 0;
+ uint16_t out_pl_len;
+
+ if (!ct3d->scan_media_hasrun) {
+ return CXL_MBOX_UNSUPPORTED;
+ }
+
+ /*
+ * Calculate limits, all entries are within the same address range of the
+ * last scan media call.
+ */
+ QLIST_FOREACH(ent, scan_media_results, node) {
+ size_t rec_size = record_count * sizeof(out->records[0]);
+
+ if (sizeof(*out) + rec_size < CXL_MAILBOX_MAX_PAYLOAD_SIZE) {
+ record_count++;
+ }
+ total_count++;
+ }
+
+ out_pl_len = sizeof(*out) + record_count * sizeof(out->records[0]);
+ assert(out_pl_len <= CXL_MAILBOX_MAX_PAYLOAD_SIZE);
+
+ memset(out, 0, out_pl_len);
+ QLIST_FOREACH_SAFE(ent, scan_media_results, node, next) {
+ uint64_t start, stop;
+
+ if (i == record_count) {
+ break;
+ }
+
+ start = ROUND_DOWN(ent->start, 64ull);
+ stop = ROUND_DOWN(ent->start, 64ull) + ent->length;
+ stq_le_p(&out->records[i].addr, start | (ent->type & 0x7));
+ stl_le_p(&out->records[i].length, (stop - start) /
CXL_CACHE_LINE_SIZE);
+ i++;
+
+ /* consume the returning entry */
+ QLIST_REMOVE(ent, node);
+ g_free(ent);
+ }
+
+ stw_le_p(&out->count, record_count);
+ if (total_count > record_count) {
+ out->flags = (1 << 0); /* More Media Error Records */
+ }
+
+ *len_out = out_pl_len;
+ return CXL_MBOX_SUCCESS;
+}
+
/*
* CXL r3.1 section 8.2.9.9.9.1: Get Dynamic Capacity Configuration
* (Opcode: 4800h)
@@ -2060,6 +2142,9 @@ static const struct cxl_cmd cxl_cmd_set[256][256] = {
cmd_media_get_scan_media_capabilities, 16, 0 },
[MEDIA_AND_POISON][SCAN_MEDIA] = { "MEDIA_AND_POISON_SCAN_MEDIA",
cmd_media_scan_media, 17, BACKGROUND_OPERATION },
+ [MEDIA_AND_POISON][GET_SCAN_MEDIA_RESULTS] = {
+ "MEDIA_AND_POISON_GET_SCAN_MEDIA_RESULTS",
+ cmd_media_get_scan_media_results, 0, 0 },
};
static const struct cxl_cmd cxl_cmd_set_dcd[256][256] = {
--
MST
- [PULL 00/63] virtio,pci,pc: features,fixes, Michael S. Tsirkin, 2024/07/21
- [PULL 01/63] hw/virtio/virtio-crypto: Fix op_code assignment in virtio_crypto_create_asym_session, Michael S. Tsirkin, 2024/07/21
- [PULL 02/63] MAINTAINERS: add Stefano Garzarella as vhost/vhost-user reviewer, Michael S. Tsirkin, 2024/07/21
- [PULL 04/63] hw/cxl: Check for multiple mappings of memory backends., Michael S. Tsirkin, 2024/07/21
- [PULL 05/63] hw/cxl/cxl-host: Fix segmentation fault when getting cxl-fmw property, Michael S. Tsirkin, 2024/07/21
- [PULL 03/63] hw/cxl/cxl-mailbox-utils: remove unneeded mailbox output payload space zeroing, Michael S. Tsirkin, 2024/07/21
- [PULL 07/63] hw/cxl/mbox: replace sanitize_running() with cxl_dev_media_disabled(), Michael S. Tsirkin, 2024/07/21
- [PULL 06/63] hw/cxl: Add get scan media capabilities cmd support, Michael S. Tsirkin, 2024/07/21
- [PULL 08/63] hw/cxl/events: discard all event records during sanitation, Michael S. Tsirkin, 2024/07/21
- [PULL 09/63] hw/cxl: Add get scan media results cmd support,
Michael S. Tsirkin <=
- [PULL 10/63] cxl/mailbox: move mailbox effect definitions to a header, Michael S. Tsirkin, 2024/07/21
- [PULL 11/63] hw/cxl/cxl-mailbox-utils: Add support for feature commands (8.2.9.6), Michael S. Tsirkin, 2024/07/21
- [PULL 12/63] hw/cxl/cxl-mailbox-utils: Add device patrol scrub control feature, Michael S. Tsirkin, 2024/07/21
- [PULL 13/63] hw/cxl/cxl-mailbox-utils: Add device DDR5 ECS control feature, Michael S. Tsirkin, 2024/07/21
- [PULL 14/63] hw/cxl: Support firmware updates, Michael S. Tsirkin, 2024/07/21
- [PULL 15/63] MAINTAINERS: Add myself as a VT-d reviewer, Michael S. Tsirkin, 2024/07/21
- [PULL 16/63] virtio-snd: add max size bounds check in input cb, Michael S. Tsirkin, 2024/07/21
- [PULL 17/63] virtio-snd: check for invalid param shift operands, Michael S. Tsirkin, 2024/07/21
- [PULL 18/63] intel_iommu: fix FRCD construction macro, Michael S. Tsirkin, 2024/07/21
- [PULL 19/63] intel_iommu: move VTD_FRCD_PV and VTD_FRCD_PP declarations, Michael S. Tsirkin, 2024/07/21