wdc: Add device unit info log extraction
Subsystems (2)
PATCH 1/4 wdc: Add device unit info log extraction
--- plugins/wdc/wdc-nvme.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 125 insertions(+), 2 deletions(-)
plugins/wdc/wdc-nvme.c +125 -2
@@ -107,6 +107,10 @@#define WDC_NVME_CRASH_DUMP_TYPE 1#define WDC_NVME_PFAIL_DUMP_TYPE 2 +/* Capture Device Unit Info */ +#define WDC_NVME_CAP_DUI_HEADER_SIZE 0x400 +#define WDC_NVME_CAP_DUI_OPCODE 0xFA +/* Crash dump */ #define WDC_NVME_CRASH_DUMP_SIZE_OPCODE WDC_NVME_CAP_DIAG_CMD_OPCODE#define WDC_NVME_CRASH_DUMP_SIZE_DATA_LEN WDC_NVME_LOG_SIZE_DATA_LEN
@@ -384,6 +388,15 @@ struct wdc_e6_log_hdr {__u8 log_size[4 ]; }; +/* DUI log header */ +struct wdc_dui_log_hdr { +__u8 telemetry_hdr[512 ]; +__le16 hdr_version; +__le16 section_count; +__u8 log_size[4 ]; +__u8 log_data[504 ]; +}; +/* Purge monitor response */ struct wdc_nvme_purge_monitor_data {__le16 rsvd1;
@@ -863,6 +876,28 @@ static __u32 wdc_dump_length_e6(int fd, __u32 opcode, __u32 cdw10, __u32 cdw12,return ret; } +static __u32 wdc_dump_dui_data (int fd,__u32 dataLen,__u32 offset,__u8 *dump_data) +{ +int ret; +struct nvme_admin_cmd admin_cmd; + +memset (&admin_cmd,0 ,sizeof (struct nvme_admin_cmd )); + admin_cmd.opcode =WDC_NVME_CAP_DUI_OPCODE ; + admin_cmd.nsid =0xFFFFFFFF ; + admin_cmd.addr = (__u64 )(uintptr_t )dump_data; + admin_cmd.data_len = dataLen; + admin_cmd.cdw10 = ((dataLen >>2 ) -1 ); + admin_cmd.cdw12 = offset; + + ret =nvme_submit_passthru (fd,NVME_IOCTL_ADMIN_CMD , &admin_cmd); +if (ret !=0 ) { +fprintf (stderr,"ERROR : WDC : reading DUI length failed\n" ); +fprintf (stderr,"NVMe Status:%s(%x)\n" ,nvme_status_to_string (ret), ret); + } + +return ret; +} +static int wdc_do_dump (int fd,__u32 opcode,__u32 data_len,__u32 cdw12,char *file,__u32 xfer_size) {
@@ -1030,6 +1065,90 @@ static int wdc_do_cap_diag(int fd, char *file, __u32 xfer_size)return ret; } +static int wdc_do_cap_dui (int fd,char *file,__u32 xfer_size) +{ +int ret =0 ; +__u32 dui_log_hdr_size =WDC_NVME_CAP_DUI_HEADER_SIZE ; +struct wdc_dui_log_hdr *log_hdr; +__u32 cap_dui_length; +__u8 *dump_data; +__u64 buffer_addr; +__u32 curr_data_offset; +__s32 log_size; +int i; + + log_hdr = (struct wdc_dui_log_hdr *)malloc (dui_log_hdr_size); +if (log_hdr ==NULL ) { +fprintf (stderr,"%s: ERROR : malloc : %s\n" , __func__,strerror (errno)); +return -1 ; + } +memset (log_hdr,0 , dui_log_hdr_size); + +/* get the dui telemetry and log headers */ + ret =wdc_dump_dui_data (fd, +WDC_NVME_CAP_DUI_HEADER_SIZE , +0x00 , + (__u8 *)log_hdr); +if (ret !=0 ) { +free (log_hdr); +fprintf (stderr,"%s: ERROR : WDC : Get DUI headers failed\n" , __func__); +fprintf (stderr,"%s: ERROR : WDC : NVMe Status:%s(%x)\n" , __func__,nvme_status_to_string (ret), ret); + +return ret; + } + + cap_dui_length = (log_hdr->log_size[3 ] <<24 | log_hdr->log_size[2 ] <<16 | + log_hdr->log_size[1 ] <<8 | log_hdr->log_size[0 ]); + +if (cap_dui_length ==0 ) { +fprintf (stderr,"INFO : WDC : Capture Device Unit Info log is empty\n" ); + }else { +if (xfer_size ==0 ) + xfer_size = cap_dui_length; + + dump_data = (__u8 *)malloc (sizeof (__u8) * cap_dui_length); + +if (dump_data ==NULL ) { +fprintf (stderr,"%s: ERROR : malloc : %s\n" , __func__,strerror (errno)); +return -1 ; + } +memset (dump_data,0 ,sizeof (__u8) * cap_dui_length); + +/* copy the telemetry and log headers into the dump_data buffer */ +memcpy (dump_data, log_hdr,WDC_NVME_CAP_DUI_HEADER_SIZE ); + + curr_data_offset =WDC_NVME_CAP_DUI_HEADER_SIZE ; + i =0 ; + + log_size = (cap_dui_length -WDC_NVME_CAP_DUI_HEADER_SIZE ); +for (; log_size >0 ; log_size -= xfer_size) { + xfer_size =min (xfer_size, log_size); + + buffer_addr = (__u64 )(uintptr_t )dump_data + (__u64 )curr_data_offset; + ret =wdc_dump_dui_data (fd, xfer_size, curr_data_offset, (__u8 *)buffer_addr); +if (ret !=0 ) { +fprintf (stderr,"%s: ERROR : WDC : Get chunk %d, size = 0x%x, offset = 0x%x, addr = 0x%lx\n" , + __func__, i, cap_dui_length, curr_data_offset, (long unsigned int )buffer_addr); +fprintf (stderr,"%s: ERROR : WDC : NVMe Status:%s(%x)\n" , __func__,nvme_status_to_string (ret), ret); +break ; + } + + curr_data_offset += xfer_size; + i++; + } + +if (ret ==0 ) { +fprintf (stderr,"%s: NVMe Status:%s(%x)\n" , __func__,nvme_status_to_string (ret), ret); +fprintf (stderr,"INFO : WDC : Capture Device Unit Info log, length = 0x%x\n" , cap_dui_length); + + ret =wdc_create_log_file (file, dump_data, cap_dui_length); + } +free (dump_data); + } +free (log_hdr); +return ret; +} +static int wdc_cap_diag (int argc,char **argv,struct command *command,struct plugin *plugin) {
@@ -1072,10 +1191,11 @@ static int wdc_cap_diag(int argc, char **argv, struct command *command,fprintf (stderr,"ERROR : WDC: failed to generate file name\n" );return -1 ; } +if (cfg.file ==NULL ) +snprintf (f +strlen (f),PATH_MAX ,"%s" ,".bin" ); capabilities =wdc_get_drive_capabilities (fd);if ((capabilities &WDC_DRIVE_CAP_CAP_DIAG ) ==WDC_DRIVE_CAP_CAP_DIAG ) { -snprintf (f +strlen (f),PATH_MAX ,"%s" ,".bin" );return wdc_do_cap_diag (fd, f, xfer_size); }else fprintf (stderr,"ERROR : WDC: unsupported device for this command\n" );
@@ -1369,12 +1489,15 @@ static int wdc_vs_internal_fw_log(int argc, char **argv, struct command *commandreturn -1 ; } } +if (cfg.file ==NULL ) +snprintf (f +strlen (f),PATH_MAX ,"%s" ,".bin" );fprintf (stderr,"%s: filename = %s\n" , __func__, f); capabilities =wdc_get_drive_capabilities (fd);if ((capabilities &WDC_DRIVE_CAP_INTERNAL_LOG ) ==WDC_DRIVE_CAP_INTERNAL_LOG ) { -snprintf (f +strlen (f),PATH_MAX ,"%s" ,".bin" );return wdc_do_cap_diag (fd, f, xfer_size); + }else if ((capabilities &WDC_DRIVE_CAP_DUI_DATA ) ==WDC_DRIVE_CAP_DUI_DATA ) { +return wdc_do_cap_dui (fd, f, xfer_size); }else if ((capabilities &WDC_SN730_CAP_VUC_LOG ) ==WDC_SN730_CAP_VUC_LOG ) {return wdc_do_sn730_get_and_tar (fd, f); }else {
Signature · 1 line
2.7.4
PATCH 2/4 wdc: Add get drive status command
In addition, updated checks for supported log pages and capabilities
--- Documentation/nvme-wdc-get-drive-status.txt | 60 +++ plugins/wdc/wdc-nvme.c | 701 ++++++++++++++++++++++++++-- plugins/wdc/wdc-nvme.h | 1 + 3 files changed, 714 insertions(+), 48 deletions(-) create mode 100644 Documentation/nvme-wdc-get-drive-status.txt
Documentation/nvme-wdc-get-drive-status.txt new file +60 -0
@@ -0,0 +1,60 @@ +nvme-wdc-get-drive-status(1) +============================ + +NAME +---- +nvme-wdc-get-drive-status - Send the NVMe WDC get-drive-status command, return result + +SYNOPSIS +-------- +[verse] +'nvme wdc get-drive-status' <device> + +DESCRIPTION +----------- +For the NVMe device given, send the unique WDC get-drive-status command and +provide the additional drive status information. + +The <device> parameter is mandatory and may be either the NVMe character +device (ex: /dev/nvme0). + +This will only work on WDC devices supporting this feature. +Results for any other device are undefined. + +On success it returns 0, error code otherwise. + +Output Explanation +------------------ +[cols="2*", frame="topbot", align="center", options="header"] +|=== +|Field |Description + +|*Percent Life Used.* +|The percentage of drive function used. + +|*EOL (End of Life) Status* +|The 3 possible states are : Normal, Read Only, or End of Life. + +|*Assert Dump Status* +|The 2 possible states are : Present or Not Present. + +|*Thermal Throttling Status* +|The 3 possible states are : Off, On, or Unavaiable. + +|*Format Corrupt Reason* +|The 3 possible states are : Not Corrupted, Corrupt due to FW Assert, or Corrupt for Unknown Reason. + +|=== + + +EXAMPLES +-------- +* Has the program issue WDC get-drive-status command : ++ +------------ +# nvme wdc get-drive-status /dev/nvme0 +------------ + +NVME +---- +Part of the nvme-user suite.
plugins/wdc/wdc-nvme.c +653 -48
875 lines not on this page · raw message
plugins/wdc/wdc-nvme.h +1 -0
@@ -19,6 +19,7 @@ PLUGIN(NAME("wdc", "Western Digital vendor specific extensions"), ENTRY("vs-smart-add-log", "WDC Additional Smart Log", wdc_vs_smart_add_log) ENTRY("clear-pcie-correctable-errors", "WDC Clear PCIe Correctable Error Count", wdc_clear_pcie_correctable_errors) ENTRY("drive-essentials", "WDC Drive Essentials", wdc_drive_essentials) +ENTRY ("get-drive-status" ,"WDC Get Drive Status" , wdc_drive_status) ) );
Signature · 1 line
2.7.4
PATCH 3/4 wdc: Add clear assert dump status command
In reply to Dong Ho--- Documentation/nvme-wdc-clear-assert-dump.txt | 39 +++++++++++++++ plugins/wdc/wdc-nvme.c | 73 ++++++++++++++++++++++------ plugins/wdc/wdc-nvme.h | 1 + 3 files changed, 98 insertions(+), 15 deletions(-) create mode 100644 Documentation/nvme-wdc-clear-assert-dump.txt
Documentation/nvme-wdc-clear-assert-dump.txt new file +39 -0
@@ -0,0 +1,39 @@ +nvme-wdc-clear-assert-dump(1) +============================= + +NAME +---- +nvme-wdc-clear-assert-dump - Clears the assert dump (if present). + +SYNOPSIS +-------- +[verse] +'nvme wdc clear-assert-dump' <device> + +DESCRIPTION +----------- +For the NVMe device given, sends the wdc vendor unique clear assert +dump command. + +The <device> parameter is mandatory and must be the NVMe character +device (ex: /dev/nvme0). + +This will only work on WDC devices supporting this feature. +The command will not be executed on devices that don't support it. + +OPTIONS +------- +None + +EXAMPLES +-------- +* Clears the assert dump (if present): ++ +------------ +# nvme wdc clear-assert-dump /dev/nvme0 +------------ + + +NVME +---- +Part of the nvme-user suite
plugins/wdc/wdc-nvme.c +58 -15
170 lines not on this page · raw message
plugins/wdc/wdc-nvme.h +1 -0
@@ -20,6 +20,7 @@ PLUGIN(NAME("wdc", "Western Digital vendor specific extensions"), ENTRY("clear-pcie-correctable-errors", "WDC Clear PCIe Correctable Error Count", wdc_clear_pcie_correctable_errors) ENTRY("drive-essentials", "WDC Drive Essentials", wdc_drive_essentials) ENTRY("get-drive-status", "WDC Get Drive Status", wdc_drive_status) +ENTRY ("clear-assert-dump" ,"WDC Clear Assert Dump" , wdc_clear_assert_dump) ) );
Signature · 1 line
2.7.4
PATCH 4/4 wdc: Add drive resize command
In reply to Dong Ho--- Documentation/nvme-wdc-drive-resize.txt | 42 +++++++++++++++++++++ plugins/wdc/wdc-nvme.c | 66 ++++++++++++++++++++++++++++++++- plugins/wdc/wdc-nvme.h | 1 + 3 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 Documentation/nvme-wdc-drive-resize.txt
Documentation/nvme-wdc-drive-resize.txt new file +42 -0
@@ -0,0 +1,42 @@ +nvme-wdc-drive-resize(1) +======================== + +NAME +---- +nvme-wdc-drive-resize - Send NVMe WDC Resize Vendor Unique Command, +return result. + +SYNOPSIS +-------- +[verse] +'nvme wdc drive-resize' <device> [--size=<sz> | -s <sz>] + +DESCRIPTION +----------- +For the NVMe device given, sends a Vendor Unique WDC Resize command. + +The <device> parameter is mandatory and may be either the NVMe character +device (ex: /dev/nvme0), or a namespace block device (ex: /dev/nvme0n1). + +This will only work on WDC devices supporting this feature. +Results for any other device are undefined. + +On success it returns 0, error code otherwise. + +OPTIONS +------- +-s <sz>:: +--size=<sz>:: + The new size (in GB) to resize the drive to. + +EXAMPLES +-------- +* Has the program issue WDC Resize Vendor Unique Command : ++ +------------ +# nvme wdc drive-resize /dev/nvme0n1 --size=100 +------------ + +NVME +---- +Part of the nvme-user suite.
plugins/wdc/wdc-nvme.c +65 -1
93 lines not on this page · raw message
plugins/wdc/wdc-nvme.h +1 -0
@@ -21,6 +21,7 @@ PLUGIN(NAME("wdc", "Western Digital vendor specific extensions"), ENTRY("drive-essentials", "WDC Drive Essentials", wdc_drive_essentials) ENTRY("get-drive-status", "WDC Get Drive Status", wdc_drive_status) ENTRY("clear-assert-dump", "WDC Clear Assert Dump", wdc_clear_assert_dump) +ENTRY ("drive-resize" ,"WDC Drive Resize" , wdc_drive_resize) ) );
Signature · 1 line
2.7.4
PATCH 1/4 wdc: Add device unit info log extraction
In reply to Dong HoSeries applied, documentation generated. Thanks!