Skip to content

Commit 6b3e5f6

Browse files
committed
nvme-print-stdout: add NVMe 2.1 identify power state descriptor fields
Since power loss signaling function introduced by NVMe 2.1. Signed-off-by: Tokunori Ikegami <[email protected]>
1 parent 021c693 commit 6b3e5f6

File tree

3 files changed

+106
-1
lines changed

3 files changed

+106
-1
lines changed

nvme-print-stdout.c

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3020,6 +3020,72 @@ static void print_ps_power_and_scale(__le16 ctr_power, __u8 scale)
30203020
}
30213021
}
30223022

3023+
static void print_epfrt(__u8 epfrt, __u8 epfr_fqv_ts)
3024+
{
3025+
const char *desc = "emergency power fail recovery time";
3026+
int width = 12 + strlen(desc);
3027+
char value[STR_LEN] = { 0 };
3028+
3029+
switch (epfrt) {
3030+
case 0:
3031+
snprintf(value, sizeof(value), "-");
3032+
break;
3033+
case 1 ... 99:
3034+
snprintf(value, sizeof(value), "%d (unit: %s)", epfrt,
3035+
nvme_time_scale_to_string(epfr_fqv_ts & 0xf));
3036+
break;
3037+
default:
3038+
snprintf(value, sizeof(value), "reserved");
3039+
break;
3040+
}
3041+
3042+
printf("%*s: %s\n", width, desc, value);
3043+
}
3044+
3045+
static void print_fqvt(__u8 fqvt, __u8 epfr_fqv_ts)
3046+
{
3047+
const char *desc = "forced quiescence vault time";
3048+
int width = 12 + strlen(desc);
3049+
char value[STR_LEN] = { 0 };
3050+
3051+
switch (fqvt) {
3052+
case 0:
3053+
snprintf(value, sizeof(value), "-");
3054+
break;
3055+
case 1 ... 99:
3056+
snprintf(value, sizeof(value), "%d (unit: %s)", fqvt,
3057+
nvme_time_scale_to_string(epfr_fqv_ts >> 4));
3058+
break;
3059+
default:
3060+
snprintf(value, sizeof(value), "reserved");
3061+
break;
3062+
}
3063+
3064+
printf("%*s: %s\n", width, desc, value);
3065+
}
3066+
3067+
static void print_epfvt(__u8 epfvt, __u8 epfvts)
3068+
{
3069+
const char *desc = "emergency power fail vault time";
3070+
int width = 12 + strlen(desc);
3071+
char value[STR_LEN] = { 0 };
3072+
3073+
switch (epfvt) {
3074+
case 0:
3075+
snprintf(value, sizeof(value), "-");
3076+
break;
3077+
case 1 ... 99:
3078+
snprintf(value, sizeof(value), "%d (unit: %s)", epfvt,
3079+
nvme_time_scale_to_string(epfvts & 0xf));
3080+
break;
3081+
default:
3082+
snprintf(value, sizeof(value), "reserved");
3083+
break;
3084+
}
3085+
3086+
printf("%*s: %s\n", width, desc, value);
3087+
}
3088+
30233089
static void stdout_id_ctrl_power(struct nvme_id_ctrl *ctrl)
30243090
{
30253091
int i;
@@ -3051,7 +3117,9 @@ static void stdout_id_ctrl_power(struct nvme_id_ctrl *ctrl)
30513117
printf("\n active_power_workload:");
30523118
print_psd_workload(ctrl->psd[i].apws);
30533119
printf("\n");
3054-
3120+
print_epfrt(ctrl->psd[i].epfrt, ctrl->psd[i].epfr_fqv_ts);
3121+
print_fqvt(ctrl->psd[i].fqvt, ctrl->psd[i].epfr_fqv_ts);
3122+
print_epfvt(ctrl->psd[i].epfvt, ctrl->psd[i].epfvts);
30553123
}
30563124
}
30573125

nvme-print.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,6 +1313,42 @@ const char *nvme_register_symbol_to_string(int offset)
13131313
return "unknown";
13141314
}
13151315

1316+
const char *nvme_time_scale_to_string(__u8 ts)
1317+
{
1318+
switch (ts) {
1319+
case 0:
1320+
return "1 microsecond";
1321+
case 1:
1322+
return "10 microseconds";
1323+
case 2:
1324+
return "100 microseconds";
1325+
case 3:
1326+
return "1 millisecond";
1327+
case 4:
1328+
return "10 milliseconds";
1329+
case 5:
1330+
return "100 milliseconds";
1331+
case 6:
1332+
return "1 second";
1333+
case 7:
1334+
return "10 seconds";
1335+
case 8:
1336+
return "100 seconds";
1337+
case 9:
1338+
return "1,000 seconds";
1339+
case 0xa:
1340+
return "10,000 seconds";
1341+
case 0xb:
1342+
return "100,000 seconds";
1343+
case 0xc:
1344+
return "1,000,000 seconds";
1345+
default:
1346+
break;
1347+
}
1348+
1349+
return "Reserved";
1350+
}
1351+
13161352
void nvme_feature_show(enum nvme_features_id fid, int sel, unsigned int result)
13171353
{
13181354
nvme_print(show_feature, NORMAL, fid, sel, result);

nvme-print.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ const char *nvme_ns_wp_cfg_to_string(enum nvme_ns_write_protect_cfg state);
311311
const char *nvme_pel_rci_rcpit_to_string(enum nvme_pel_rci_rcpit rcpit);
312312
const char *nvme_pel_ehai_pit_to_string(enum nvme_pel_ehai_pit pit);
313313
const char *nvme_ssi_state_to_string(__u8 state);
314+
const char *nvme_time_scale_to_string(__u8 ts);
314315

315316
void nvme_dev_full_path(nvme_ns_t n, char *path, size_t len);
316317
void nvme_generic_full_path(nvme_ns_t n, char *path, size_t len);

0 commit comments

Comments
 (0)