From: <ajay.opensrc@micron.com>
To: <Jonathan.Cameron@Huawei.com>
Cc: <linux-cxl@vger.kernel.org>, <john@jagalactic.com>,
<emirakhur@micron.com>, <ajayjoshi@micron.com>,
<sthanneeru@micron.com>, <ravis.opensrc@micron.com>,
<arramesh@micron.com>, Ajay Joshi <ajay.opensrc@micron.com>,
Tushar Mulgund <tmmulgund@micron.com>
Subject: [PATCH] hw/cxl: Add support for abort of background operation
Date: Mon, 29 Jul 2024 15:50:10 +0530 [thread overview]
Message-ID: <20240729102010.20996-1-ajay.opensrc@micron.com> (raw)
From: Ajay Joshi <ajay.opensrc@micron.com>
This patch adds the support for aborting the background
operation if one is progress(r3.1 8.2.9.1.5)
"Request Abort Background Operation" command is requested
by the host to cancel an ongoing background operation. When
the command is sent, the device will abort the ongoing
background operation. When the operation is aborted,
background command status register will maintain a completion
percentage value of less then 100. The "Request Abort
Background Operation" command support has to be advertised in
the Command Effects Log to be honoured.
Tested-by: Tushar Mulgund <tmmulgund@micron.com>
Signed-off-by: Ajay Joshi <ajay.opensrc@micron.com>
---
hw/cxl/cxl-mailbox-utils.c | 77 ++++++++++++++++++++++++++++--------
include/hw/cxl/cxl_device.h | 1 +
include/hw/cxl/cxl_mailbox.h | 1 +
3 files changed, 63 insertions(+), 16 deletions(-)
diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
index c2ed251bb3..43c934f1fc 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 REQUEST_ABORT_BACKGROUND_OPERATION 0x5
EVENTS = 0x01,
#define GET_RECORDS 0x0
#define CLEAR_RECORDS 0x1
@@ -641,6 +642,28 @@ 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 Background Abort Operation
+ * (Opcode 0005h)
+ */
+static CXLRetCode cmd_infostat_bg_abort_op(const struct cxl_cmd *cmd,
+ uint8_t *payload_in,
+ size_t len_in,
+ uint8_t *payload_out,
+ size_t *len_out,
+ CXLCCI *cci)
+{
+ if (cci->bg.runtime > 0) {
+ if (cci->bg.abort != true) {
+ cci->bg.abort = true;
+ }
+ } else {
+ return CXL_MBOX_REQUEST_ABORT_NOTSUP;
+ }
+
+ return CXL_MBOX_SUCCESS;
+}
+
/* CXL r3.1 Section 8.2.9.3.1: Get FW Info (Opcode 0200h) */
static CXLRetCode cmd_firmware_update_get_info(const struct cxl_cmd *cmd,
uint8_t *payload_in,
@@ -2502,6 +2525,9 @@ static CXLRetCode cmd_dcd_release_dyn_cap(const struct cxl_cmd *cmd,
}
static const struct cxl_cmd cxl_cmd_set[256][256] = {
+ [INFOSTAT][REQUEST_ABORT_BACKGROUND_OPERATION] = {
+ "REQUEST_ABORT_BACKGROUND_OPERATION",
+ cmd_infostat_bg_abort_op, 0, 0 },
[EVENTS][GET_RECORDS] = { "EVENTS_GET_RECORDS",
cmd_events_get_records, 1, 0 },
[EVENTS][CLEAR_RECORDS] = { "EVENTS_CLEAR_RECORDS",
@@ -2541,7 +2567,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_REQUEST_ABORT_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",
@@ -2554,7 +2581,9 @@ 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_REQUEST_ABORT_BACKGROUND_OPERATION)},
[MEDIA_AND_POISON][GET_SCAN_MEDIA_RESULTS] = {
"MEDIA_AND_POISON_GET_SCAN_MEDIA_RESULTS",
cmd_media_get_scan_media_results, 0, 0 },
@@ -2579,6 +2608,9 @@ 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][REQUEST_ABORT_BACKGROUND_OPERATION] = {
+ "REQUEST_ABORT_BACKGROUND_OPERATION",
+ cmd_infostat_bg_abort_op, 0, 0 },
[TIMESTAMP][GET] = { "TIMESTAMP_GET", cmd_timestamp_get, 0, 0 },
[TIMESTAMP][SET] = { "TIMESTAMP_SET", cmd_timestamp_set, 8,
CXL_MBOX_IMMEDIATE_POLICY_CHANGE },
@@ -2673,6 +2705,24 @@ int cxl_process_cci_message(CXLCCI *cci, uint8_t set, uint8_t cmd,
return ret;
}
+static void bg_notify_host(CXLCCI *cci)
+{
+ /* TODO: generalize to switch CCI */
+ CXLType3Dev *ct3d = CXL_TYPE3(cci->d);
+ CXLDeviceState *cxl_dstate = &ct3d->cxl_dstate;
+ PCIDevice *pdev = PCI_DEVICE(cci->d);
+
+ cci->bg.starttime = 0;
+ /* registers are updated, allow new bg-capable cmds */
+ cci->bg.runtime = 0;
+
+ if (msix_enabled(pdev)) {
+ msix_notify(pdev, cxl_dstate->mbox_msi_n);
+ } else if (msi_enabled(pdev)) {
+ msi_notify(pdev, cxl_dstate->mbox_msi_n);
+ }
+}
+
static void bg_timercb(void *opaque)
{
CXLCCI *cci = opaque;
@@ -2709,24 +2759,19 @@ static void bg_timercb(void *opaque)
} else {
/* estimate only */
cci->bg.complete_pct = 100 * now / total_time;
+ if (cci->bg.abort == true) {
+ uint16_t ret = CXL_MBOX_SUCCESS;
+
+ cci->bg.ret_code = ret;
+ cci->bg.abort = false;
+ bg_notify_host(cci);
+ return;
+ }
timer_mod(cci->bg.timer, now + CXL_MBOX_BG_UPDATE_FREQ);
}
if (cci->bg.complete_pct == 100) {
- /* TODO: generalize to switch CCI */
- CXLType3Dev *ct3d = CXL_TYPE3(cci->d);
- CXLDeviceState *cxl_dstate = &ct3d->cxl_dstate;
- PCIDevice *pdev = PCI_DEVICE(cci->d);
-
- cci->bg.starttime = 0;
- /* registers are updated, allow new bg-capable cmds */
- cci->bg.runtime = 0;
-
- if (msix_enabled(pdev)) {
- msix_notify(pdev, cxl_dstate->mbox_msi_n);
- } else if (msi_enabled(pdev)) {
- msi_notify(pdev, cxl_dstate->mbox_msi_n);
- }
+ bg_notify_host(cci);
}
}
diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h
index dd02adda27..daad578027 100644
--- a/include/hw/cxl/cxl_device.h
+++ b/include/hw/cxl/cxl_device.h
@@ -201,6 +201,7 @@ typedef struct CXLCCI {
uint64_t starttime;
/* set by each bg cmd, cleared by the bg_timer when complete */
uint64_t runtime;
+ bool abort; /*abort if the bg operation is in progress*/
QEMUTimer *timer;
} bg;
size_t payload_max;
diff --git a/include/hw/cxl/cxl_mailbox.h b/include/hw/cxl/cxl_mailbox.h
index beb048052e..a8a6beb712 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_REQUEST_ABORT_BACKGROUND_OPERATION (1 << 8)
#endif
--
2.34.1
next reply other threads:[~2024-07-29 10:20 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-29 10:20 ajay.opensrc [this message]
2024-07-30 6:07 ` [PATCH] hw/cxl: Add support for abort of background operation Davidlohr Bueso
2024-08-02 13:04 ` [EXT] " ajay.opensrc
2024-08-04 16:16 ` Jonathan Cameron
2024-08-07 9:04 ` ajay.opensrc
2024-08-12 20:04 ` Davidlohr Bueso
2024-08-15 17:04 ` Jonathan Cameron
2024-08-20 20:11 ` Jonathan Cameron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240729102010.20996-1-ajay.opensrc@micron.com \
--to=ajay.opensrc@micron.com \
--cc=Jonathan.Cameron@Huawei.com \
--cc=ajayjoshi@micron.com \
--cc=arramesh@micron.com \
--cc=emirakhur@micron.com \
--cc=john@jagalactic.com \
--cc=linux-cxl@vger.kernel.org \
--cc=ravis.opensrc@micron.com \
--cc=sthanneeru@micron.com \
--cc=tmmulgund@micron.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox