Skip to content

Commit 6cd5403

Browse files
committed
mi: add nvme_mi_status_to_string()
Add a function, similar to nvme_status_to_string(), that returns a string value of the spec-defined wording for each status value. We keep this in the mi object for now, to keep the existing division of libnvme.so/libnvme-mi.so Signed-off-by: Jeremy Kerr <[email protected]>
1 parent d8b5bb8 commit 6cd5403

3 files changed

Lines changed: 50 additions & 0 deletions

File tree

src/libnvme-mi.map

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ LIBNVME_MI_1_2 {
88
nvme_mi_admin_sanitize_nvm;
99
nvme_mi_admin_fw_download;
1010
nvme_mi_admin_fw_commit;
11+
nvme_mi_status_to_string;
1112
};
1213

1314
LIBNVME_MI_1_1 {

src/nvme/mi.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <stdlib.h>
1212
#include <stdio.h>
1313

14+
#include <ccan/array_size/array_size.h>
1415
#include <ccan/endian/endian.h>
1516

1617
#include "log.h"
@@ -1282,3 +1283,37 @@ nvme_mi_ctrl_t nvme_mi_next_ctrl(nvme_mi_ep_t ep, nvme_mi_ctrl_t c)
12821283
{
12831284
return c ? list_next(&ep->controllers, c, ep_entry) : NULL;
12841285
}
1286+
1287+
1288+
static const char *const mi_status[] = {
1289+
[NVME_MI_RESP_MPR] = "More Processing Required: The command message is in progress and requires more time to complete processing",
1290+
[NVME_MI_RESP_INTERNAL_ERR] = "Internal Error: The request message could not be processed due to a vendor-specific error",
1291+
[NVME_MI_RESP_INVALID_OPCODE] = "Invalid Command Opcode",
1292+
[NVME_MI_RESP_INVALID_PARAM] = "Invalid Parameter",
1293+
[NVME_MI_RESP_INVALID_CMD_SIZE] = "Invalid Command Size: The size of the message body of the request was different than expected",
1294+
[NVME_MI_RESP_INVALID_INPUT_SIZE] = "Invalid Command Input Data Size: The command requires data and contains too much or too little data",
1295+
[NVME_MI_RESP_ACCESS_DENIED] = "Access Denied. Processing prohibited due to a vendor-specific mechanism of the Command and Feature lockdown function",
1296+
[NVME_MI_RESP_VPD_UPDATES_EXCEEDED] = "VPD Updates Exceeded",
1297+
[NVME_MI_RESP_PCIE_INACCESSIBLE] = "PCIe Inaccessible. The PCIe functionality is not available at this time",
1298+
[NVME_MI_RESP_MEB_SANITIZED] = "Management Endpoint Buffer Cleared Due to Sanitize",
1299+
[NVME_MI_RESP_ENC_SERV_FAILURE] = "Enclosure Services Failure",
1300+
[NVME_MI_RESP_ENC_SERV_XFER_FAILURE] = "Enclosure Services Transfer Failure: Communication with the Enclosure Services Process has failed",
1301+
[NVME_MI_RESP_ENC_FAILURE] = "An unrecoverable enclosure failure has been detected by the Enclosuer Services Process",
1302+
[NVME_MI_RESP_ENC_XFER_REFUSED] = "Enclosure Services Transfer Refused: The NVM Subsystem or Enclosure Services Process indicated an error or an invalid format in communication",
1303+
[NVME_MI_RESP_ENC_FUNC_UNSUP] = "Unsupported Enclosure Function: An SES Send command has been attempted to a simple Subenclosure",
1304+
[NVME_MI_RESP_ENC_SERV_UNAVAIL] = "Enclosure Services Unavailable: The NVM Subsystem or Enclosure Services Process has encountered an error but may become available again",
1305+
[NVME_MI_RESP_ENC_DEGRADED] = "Enclosure Degraded: A noncritical failure has been detected by the Enclosure Services Process",
1306+
[NVME_MI_RESP_SANITIZE_IN_PROGRESS] = "Sanitize In Progress: The requested command is prohibited while a sanitize operation is in progress",
1307+
};
1308+
1309+
/* kept in mi.c while we have a split libnvme/libnvme-mi; consider moving
1310+
* to utils.c (with nvme_status_to_string) if we ever merge. */
1311+
const char *nvme_mi_status_to_string(int status)
1312+
{
1313+
const char *s = "Unknown status";
1314+
1315+
if (status < ARRAY_SIZE(mi_status) && mi_status[status])
1316+
s = mi_status[status];
1317+
1318+
return s;
1319+
}

src/nvme/mi.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,20 @@ struct nvme_mi_admin_resp_hdr {
367367
__le32 cdw0, cdw1, cdw3;
368368
} __attribute__((packed));
369369

370+
/**
371+
* nvme_mi_status_to_string() - return a string representation of the MI
372+
* status.
373+
* @status: MI response status
374+
*
375+
* Gives a string description of @status, as per section 4.1.2 of the NVMe-MI
376+
* spec. The status value should be of type NVME_STATUS_MI, and extracted
377+
* from the return value using nvme_status_get_value().
378+
*
379+
* Returned string is const, and should not be free()ed.
380+
*
381+
* Returns: A string representing the status value
382+
*/
383+
const char *nvme_mi_status_to_string(int status);
370384

371385
/**
372386
* nvme_mi_create_root() - Create top-level MI (root) handle.

0 commit comments

Comments
 (0)