Skip to content

Commit d4fed09

Browse files
jeff-lien-sndkigaw
authored andcommitted
sndk: vs-internal-log command fixes and enhancements
The data-area parameter was being overwritten and set to the default data area value for all cases. This change will only set it when it's not specified. This set of changes fully deprecates a few of the optional parameters for this command across both WDC and Sandisk plugins, and tidies up some of the logic around how telemetry or vendor defined debug is returned. This adds a new --type value in the vs-internal-log command for capturing Host-initiated and Controller-initated telemetry in one command. Signed-off-by: Brandon Paupore <[email protected]> Fixes a compile warning on tar file creation. Fixes error that creates an empty file. Signed-off-by: jeff-lien-sndk <[email protected]>
1 parent 2b3f030 commit d4fed09

6 files changed

Lines changed: 199 additions & 85 deletions

File tree

Documentation/nvme-sndk-vs-internal-log.txt

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,25 @@ OPTIONS
4040
-d <DATA AREA>::
4141
--data-area=<DATA AREA>::
4242
Data area to retrieve. For capture with a --type value that includes
43-
telemetry (CONTROLLER or HOST), this specifies the NVMe telemetry data
44-
area to capture, containing data from areas 1 to <DATA AREA>. For
45-
capture without such a --type value, this specifies the amount of
46-
vendor defined debug data to capture, and this is only supported on the
47-
SN340, SN350, SN530, SN570, SN730, SN740, SN840, SN850X, SN5000,
48-
SN5100S, SN7000S, SN7100, and SN7150 devices.
43+
telemetry (CONTROLLER, HOST, or BOTH), this specifies the NVMe
44+
telemetry data area to capture, containing data from areas 1 to
45+
<DATA AREA>. For capture without such a --type value, this specifies
46+
the amount of vendor defined debug data to capture, and this is only
47+
supported on the SN340, SN350, SN530, SN570, SN730, SN740, SN840,
48+
SN850X, SN5000, SN5100S, SN7000S, SN7100, and SN7150 devices.
49+
50+
-t <TYPE>::
51+
--type=<TYPE>::
52+
Specifies the telemetry type - NONE, HOST, CONTROLLER, or BOTH. This
53+
parameter is used to get either the host-initiated or controller-
54+
initiated telemetry log page. If BOTH is specified, both host and
55+
controller telemetry are captured and packaged into a tar archive.
56+
If not specified or if <TYPE> is NONE, the command will return vendor
57+
defined debug data.
58+
59+
-v <VERBOSE>::
60+
--verbose=<VERBOSE>::
61+
Provides additional debug messages for certain drives.
4962

5063
-f <FILE SIZE>::
5164
--file-size=<FILE SIZE>::
@@ -64,17 +77,6 @@ OPTIONS
6477
--data-area parameter, and only for capture with --type=NONE or --type
6578
not specified.
6679

67-
-t <TYPE>::
68-
--type=<TYPE>::
69-
Specifies the telemetry type - NONE, HOST, or CONTROLLER. This parameter
70-
is used to get either the host-initiated or controller-initiated
71-
telemetry log page. If not specified or if <TYPE> is NONE, the command
72-
will return vendor defined debug data.
73-
74-
-v <VERBOSE>::
75-
--verbose=<VERBOSE>::
76-
Provides additional debug messages for certain drives.
77-
7880
EXAMPLES
7981
--------
8082
* Gets the internal firmware log from the device and saves to default file in current directory (e.g. STM00019F3F9_internal_fw_log_20171127_095704.bin):
@@ -119,6 +121,11 @@ EXAMPLES
119121
------------
120122
# nvme sndk vs-internal-log /dev/nvme1 -t controller -o ctlr-telem-log-da3.bin -d 3
121123
------------
124+
* Gets both host and controller telemetry log pages to data area 3 from the device and packages them in a tar file:
125+
+
126+
------------
127+
# nvme sndk vs-internal-log /dev/nvme1 -t both -o both-telem-log-da3.tar -d 3
128+
------------
122129

123130
NVME
124131
----

Documentation/nvme-wdc-vs-internal-log.txt

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,6 @@ OPTIONS
4747
SN340, SN350, SN530, SN570, SN730, SN740, SN840, SN850X, SN5000,
4848
SN5100S, SN7000S, SN7100, and SN7150 devices.
4949

50-
-f <FILE SIZE>::
51-
--file-size=<FILE SIZE>::
52-
Specifies the desired size of the data file starting at the passed in
53-
offset. This allows the user to retrieve the data in several smaller
54-
files of the passed in size. This parameter is only supported on the
55-
devices mentioned in the documentation of the --data-area parameter,
56-
and only for capture with --type=NONE or --type not specified.
57-
58-
-e <OFFSET>::
59-
--offset=<OFFSET>::
60-
Specifies the data offset at which to start retrieving the data. This
61-
parameter is used in combination with the file size parameter to
62-
retrieve the data in several smaller files. This parameter is only
63-
supported on the devices mentioned in the documentation of the
64-
--data-area parameter, and only for capture with --type=NONE or --type
65-
not specified.
66-
6750
-t <TYPE>::
6851
--type=<TYPE>::
6952
Specifies the telemetry type - NONE, HOST, or CONTROLLER. This parameter
@@ -75,6 +58,23 @@ OPTIONS
7558
--verbose=<VERBOSE>::
7659
Provides additional debug messages for certain drives.
7760

61+
-f <FILE SIZE>::
62+
--file-size=<FILE SIZE>::
63+
Deprecated. Specifies the desired size of the data file starting at the
64+
passed in offset. This allows the user to retrieve the data in several
65+
smaller files of the passed in size. This parameter is only supported on
66+
the devices mentioned in the documentation of the --data-area parameter,
67+
and only for capture with --type=NONE or --type not specified.
68+
69+
-e <OFFSET>::
70+
--offset=<OFFSET>::
71+
Deprecated. Specifies the data offset at which to start retrieving the
72+
data. This parameter is used in combination with the file size parameter
73+
to retrieve the data in several smaller files. This parameter is only
74+
supported on the devices mentioned in the documentation of the
75+
--data-area parameter, and only for capture with --type=NONE or --type
76+
not specified.
77+
7878
EXAMPLES
7979
--------
8080
* Gets the internal firmware log from the device and saves to default file in current directory (e.g. STM00019F3F9_internal_fw_log_20171127_095704.bin):

plugins/sandisk/sandisk-nvme.c

Lines changed: 136 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ static int sndk_do_cap_telemetry_log(struct nvme_global_ctx *ctx,
9191
}
9292
host_gen = 0;
9393
ctrl_init = 1;
94+
} else if (type == SNDK_TELEMETRY_TYPE_BOTH) {
95+
fprintf(stderr,
96+
"%s: BOTH type should be handled by sndk_do_cap_both_telemetry_log\n",
97+
__func__);
98+
return -EINVAL;
9499
} else {
95100
fprintf(stderr, "%s: Invalid type parameter; type = %d\n", __func__, type);
96101
return -EINVAL;
@@ -173,6 +178,81 @@ static int sndk_do_cap_telemetry_log(struct nvme_global_ctx *ctx,
173178
return err;
174179
}
175180

181+
static int sndk_do_cap_both_telemetry_log(struct nvme_global_ctx *ctx,
182+
struct nvme_transport_handle *hdl,
183+
const char *tar_file, __u32 bs,
184+
int data_area)
185+
{
186+
char host_file[PATH_MAX] = {0};
187+
char controller_file[PATH_MAX] = {0};
188+
char tar_cmd[PATH_MAX * 3] = {0};
189+
char *base_name;
190+
int ret = 0;
191+
192+
base_name = strdup(tar_file);
193+
if (!base_name) {
194+
fprintf(stderr, "%s: Memory allocation failed\n", __func__);
195+
return -ENOMEM;
196+
}
197+
198+
/* Remove .tar extension if present */
199+
char *tar_ext = strstr(base_name, ".tar");
200+
201+
if (tar_ext)
202+
*tar_ext = '\0';
203+
204+
/* Create temporary files for host and controller telemetry */
205+
snprintf(host_file, PATH_MAX, "%s_host_telemetry.bin", base_name);
206+
snprintf(controller_file, PATH_MAX, "%s_controller_telemetry.bin",
207+
base_name);
208+
209+
fprintf(stderr, "%s: Capturing HOST telemetry to %s\n", __func__,
210+
host_file);
211+
ret = sndk_do_cap_telemetry_log(ctx, hdl, host_file, bs,
212+
SNDK_TELEMETRY_TYPE_HOST, data_area);
213+
if (ret) {
214+
fprintf(stderr, "%s: Failed to capture HOST telemetry: %d\n",
215+
__func__, ret);
216+
goto cleanup;
217+
}
218+
219+
fprintf(stderr, "%s: Capturing CONTROLLER telemetry to %s\n", __func__,
220+
controller_file);
221+
ret = sndk_do_cap_telemetry_log(ctx, hdl, controller_file, bs,
222+
SNDK_TELEMETRY_TYPE_CONTROLLER,
223+
data_area);
224+
if (ret) {
225+
fprintf(stderr,
226+
"%s: Failed to capture CONTROLLER telemetry: %d\n",
227+
__func__, ret);
228+
goto cleanup_host;
229+
}
230+
231+
/* Create tar file containing both telemetry files */
232+
fprintf(stderr, "%s: Creating tar file %s\n", __func__, tar_file);
233+
snprintf(tar_cmd, sizeof(tar_cmd), "tar -cf \"%s\" \"%s\" \"%s\"",
234+
tar_file, host_file, controller_file);
235+
236+
ret = system(tar_cmd);
237+
if (ret) {
238+
fprintf(stderr, "%s: Failed to create tar file: %s\n",
239+
__func__, tar_file);
240+
ret = -1;
241+
} else {
242+
fprintf(stderr, "%s: Successfully created tar file: %s\n",
243+
__func__, tar_file);
244+
ret = 0;
245+
}
246+
247+
/* Clean up temporary files */
248+
unlink(controller_file);
249+
cleanup_host:
250+
unlink(host_file);
251+
cleanup:
252+
free(base_name);
253+
return ret;
254+
}
255+
176256
static __u32 sndk_dump_udui_data(struct nvme_transport_handle *hdl,
177257
__u32 dataLen, __u32 offset, __u8 *dump_data)
178258
{
@@ -196,8 +276,7 @@ static __u32 sndk_dump_udui_data(struct nvme_transport_handle *hdl,
196276
}
197277

198278
static int sndk_do_cap_udui(struct nvme_transport_handle *hdl, char *file,
199-
__u32 xfer_size, int verbose, __u64 file_size,
200-
__u64 offset)
279+
__u32 xfer_size, int verbose)
201280
{
202281
int ret = 0;
203282
int output;
@@ -206,6 +285,7 @@ static int sndk_do_cap_udui(struct nvme_transport_handle *hdl, char *file,
206285
__u32 udui_log_hdr_size = sizeof(struct nvme_telemetry_log);
207286
__u32 chunk_size = xfer_size;
208287
__u64 total_size;
288+
__u64 offset = 0;
209289

210290
log = (struct nvme_telemetry_log *)malloc(udui_log_hdr_size);
211291
if (!log) {
@@ -225,14 +305,6 @@ static int sndk_do_cap_udui(struct nvme_transport_handle *hdl, char *file,
225305
}
226306

227307
total_size = (le32_to_cpu(log->dalb4) + 1) * 512;
228-
if (offset > total_size) {
229-
fprintf(stderr, "%s: ERROR: SNDK: offset larger than log length = 0x%"PRIx64"\n",
230-
__func__, (uint64_t)total_size);
231-
goto out;
232-
}
233-
234-
if (file_size && (total_size - offset) > file_size)
235-
total_size = offset + file_size;
236308

237309
log = (struct nvme_telemetry_log *)realloc(log, chunk_size);
238310

@@ -311,16 +383,18 @@ static int sndk_vs_internal_fw_log(int argc, char **argv,
311383
const char *size = "Data retrieval transfer size.";
312384
const char *data_area =
313385
"Data area to retrieve up to. Supported for telemetry, see man page for other use cases.";
386+
const char *type =
387+
"Telemetry type - NONE, HOST, CONTROLLER, or BOTH:\n" \
388+
" NONE - Default, capture without using NVMe telemetry.\n" \
389+
" HOST - Host-initiated telemetry.\n" \
390+
" CONTROLLER - Controller-initiated telemetry.\n" \
391+
" BOTH - Both HOST and CONTROLLER telemetry packaged in tar file.";
392+
const char *verbose = "Display more debug messages.";
314393
const char *file_size =
315394
"Output file size. Deprecated, see man page for supported devices.";
316395
const char *offset =
317396
"Output file data offset. Deprecated, see man page for supported devices.";
318-
const char *type =
319-
"Telemetry type - NONE, HOST, or CONTROLLER:\n" \
320-
" NONE - Default, capture without using NVMe telemetry.\n" \
321-
" HOST - Host-initiated telemetry.\n" \
322-
" CONTROLLER - Controller-initiated telemetry.";
323-
char f[PATH_MAX] = {0};
397+
char f[PATH_MAX-4] = {0};
324398
char fileSuffix[PATH_MAX] = {0};
325399
__u32 xfer_size = 0;
326400
int telemetry_type = 0, telemetry_data_area = 0;
@@ -339,6 +413,7 @@ static int sndk_vs_internal_fw_log(int argc, char **argv,
339413
__u64 file_size;
340414
__u64 offset;
341415
char *type;
416+
bool verbose;
342417
};
343418

344419
struct config cfg = {
@@ -348,15 +423,18 @@ static int sndk_vs_internal_fw_log(int argc, char **argv,
348423
.file_size = 0,
349424
.offset = 0,
350425
.type = NULL,
426+
.verbose = false,
351427
};
352428

353429
NVME_ARGS(opts,
354430
OPT_FILE("output-file", 'o', &cfg.file, file),
355431
OPT_UINT("transfer-size", 's', &cfg.xfer_size, size),
356432
OPT_UINT("data-area", 'd', &cfg.data_area, data_area),
433+
OPT_FILE("type", 't', &cfg.type, type),
434+
OPT_FLAG("verbose", 'v', &cfg.verbose, verbose),
357435
OPT_LONG("file-size", 'f', &cfg.file_size, file_size),
358436
OPT_LONG("offset", 'e', &cfg.offset, offset),
359-
OPT_FILE("type", 't', &cfg.type, type));
437+
OPT_END());
360438

361439
ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts);
362440
if (ret)
@@ -385,7 +463,8 @@ static int sndk_vs_internal_fw_log(int argc, char **argv,
385463
goto out;
386464
}
387465
close(verify_file);
388-
strncpy(f, cfg.file, PATH_MAX - 1);
466+
remove(cfg.file);
467+
strncpy(f, cfg.file, PATH_MAX - 5);
389468
} else {
390469
sndk_UtilsGetTime(&timeInfo);
391470
memset(timeStamp, 0, sizeof(timeStamp));
@@ -423,54 +502,69 @@ static int sndk_vs_internal_fw_log(int argc, char **argv,
423502

424503
if (!cfg.type || !strcmp(cfg.type, "NONE") || !strcmp(cfg.type, "none")) {
425504
telemetry_type = SNDK_TELEMETRY_TYPE_NONE;
426-
data_area = 0;
505+
telemetry_data_area = 0;
427506
} else if (!strcmp(cfg.type, "HOST") || !strcmp(cfg.type, "host")) {
428507
telemetry_type = SNDK_TELEMETRY_TYPE_HOST;
429508
telemetry_data_area = cfg.data_area;
430509
} else if (!strcmp(cfg.type, "CONTROLLER") || !strcmp(cfg.type, "controller")) {
431510
telemetry_type = SNDK_TELEMETRY_TYPE_CONTROLLER;
432511
telemetry_data_area = cfg.data_area;
512+
} else if (!strcmp(cfg.type, "BOTH") || !strcmp(cfg.type, "both")) {
513+
telemetry_type = SNDK_TELEMETRY_TYPE_BOTH;
514+
telemetry_data_area = cfg.data_area;
433515
} else {
434516
fprintf(stderr,
435-
"ERROR: SNDK: Invalid type - Must be NONE, HOST or CONTROLLER\n");
517+
"ERROR: SNDK: Invalid type - Must be NONE, HOST, CONTROLLER, or BOTH\n");
436518
ret = -1;
437519
goto out;
438520
}
439521

440522
capabilities = sndk_get_drive_capabilities(ctx, hdl);
441523

442-
/* Supported through WDC plugin for non-telemetry */
443-
if ((capabilities & SNDK_DRIVE_CAP_INTERNAL_LOG) &&
524+
if ((capabilities & SNDK_DRIVE_CAP_INTERNAL_LOG_MASK) &&
444525
(telemetry_type != SNDK_TELEMETRY_TYPE_NONE)) {
445-
if (sndk_get_default_telemetry_da(hdl, &telemetry_data_area)) {
446-
fprintf(stderr, "%s: Error determining default telemetry data area\n",
447-
__func__);
448-
return -EINVAL;
449-
}
450-
451-
ret = sndk_do_cap_telemetry_log(ctx, hdl, f, xfer_size,
452-
telemetry_type, telemetry_data_area);
453-
goto out;
454-
}
455-
456-
if (capabilities & SNDK_DRIVE_CAP_UDUI) {
457-
if ((telemetry_type == SNDK_TELEMETRY_TYPE_HOST) ||
458-
(telemetry_type == SNDK_TELEMETRY_TYPE_CONTROLLER)) {
526+
/* If no data area specified, get the default value */
527+
if (telemetry_data_area == 0) {
459528
if (sndk_get_default_telemetry_da(hdl, &telemetry_data_area)) {
460529
fprintf(stderr, "%s: Error determining default telemetry data area\n",
461-
__func__);
530+
__func__);
462531
return -EINVAL;
463532
}
533+
}
534+
535+
if (telemetry_type == SNDK_TELEMETRY_TYPE_BOTH) {
536+
/* For BOTH type, ensure filename has .tar extension */
537+
char tar_file[PATH_MAX] = {0};
538+
539+
if (strstr(f, ".tar") == NULL) {
540+
char *bin_ext = strstr(f, ".bin");
541+
542+
if (bin_ext)
543+
*bin_ext = '\0';
464544

545+
snprintf(tar_file, PATH_MAX, "%s.tar", f);
546+
} else {
547+
snprintf(tar_file, PATH_MAX, "%s", f);
548+
}
549+
ret = sndk_do_cap_both_telemetry_log(ctx, hdl,
550+
tar_file, xfer_size,
551+
telemetry_data_area);
552+
} else {
465553
ret = sndk_do_cap_telemetry_log(ctx, hdl, f, xfer_size,
466554
telemetry_type, telemetry_data_area);
467-
goto out;
468-
} else {
469-
ret = sndk_do_cap_udui(hdl, f, xfer_size,
470-
nvme_args.verbose, cfg.file_size,
471-
cfg.offset);
555+
}
556+
goto out;
557+
}
558+
559+
if (capabilities & SNDK_DRIVE_CAP_UDUI) {
560+
if (cfg.data_area) {
561+
fprintf(stderr,
562+
"ERROR: SNDK: Data area parameter is not supported when type is NONE\n");
563+
ret = -1;
472564
goto out;
473565
}
566+
ret = sndk_do_cap_udui(hdl, f, xfer_size, cfg.verbose);
567+
goto out;
474568
}
475569

476570
/* Fallback to WDC plugin if otherwise not supported */

0 commit comments

Comments
 (0)