@@ -47,6 +47,7 @@ static const char *hctm_feat = "host controlled thermal management feature";
4747static const char *timestamp_feat = "timestamp feature";
4848static const char *temp_thresh_feat = "temperature threshold feature";
4949static const char *arbitration_feat = "arbitration feature";
50+ static const char *volatile_wc_feat = "volatile write cache feature";
5051
5152static int feat_get(struct nvme_dev *dev, const __u8 fid, __u32 cdw11, __u8 sel, const char *feat)
5253{
@@ -560,3 +561,66 @@ static int feat_arbitration(int argc, char **argv, struct command *cmd, struct p
560561
561562 return arbitration_set(dev_fd(dev), fid, opts, &cfg);
562563}
564+
565+ static int volatile_wc_set(struct nvme_dev *dev, const __u8 fid, bool wce, bool save)
566+ {
567+ __u32 result;
568+ int err;
569+
570+ struct nvme_set_features_args args = {
571+ .args_size = sizeof(args),
572+ .fd = dev_fd(dev),
573+ .fid = fid,
574+ .cdw11 = NVME_SET(wce, FEAT_VWC_WCE),
575+ .save = save,
576+ .timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
577+ .result = &result,
578+ };
579+
580+ err = nvme_set_features(&args);
581+
582+ nvme_show_init();
583+
584+ if (err > 0) {
585+ nvme_show_status(err);
586+ } else if (err < 0) {
587+ nvme_show_perror("Set %s", volatile_wc_feat);
588+ } else {
589+ nvme_show_result("Set %s: 0x%04x (%s)", volatile_wc_feat, args.cdw11,
590+ save ? "Save" : "Not save");
591+ nvme_feature_show_fields(fid, args.cdw11, NULL);
592+ }
593+
594+ nvme_show_finish();
595+
596+ return err;
597+ }
598+
599+ static int feat_volatile_wc(int argc, char **argv, struct command *cmd, struct plugin *plugin)
600+ {
601+ const __u8 fid = NVME_FEAT_FID_VOLATILE_WC;
602+ const char *wce = "volatile write cache enable";
603+
604+ _cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
605+ int err;
606+
607+ struct config {
608+ bool wce;
609+ __u8 sel;
610+ };
611+
612+ struct config cfg = { 0 };
613+
614+ FEAT_ARGS(opts, OPT_FLAG("wce", 'w', &cfg.wce, wce));
615+
616+ err = parse_and_open(&dev, argc, argv, VOLATILE_WC_DESC, opts);
617+ if (err)
618+ return err;
619+
620+ if (argconfig_parse_seen(opts, "wce"))
621+ err = volatile_wc_set(dev, fid, cfg.wce, argconfig_parse_seen(opts, "save"));
622+ else
623+ err = feat_get(dev, fid, 0, cfg.sel, volatile_wc_feat);
624+
625+ return err;
626+ }
0 commit comments