Skip to content

Commit a5741a3

Browse files
jeff-lien-sndkigaw
authored andcommitted
sndk: Use libnvme functions to set/clear etdas bit
To get telemetry log da4, the code needs to set the etdas bit. The bit will be restored after the log has been retrieved. Reviewed-by: brandon-paupore-sndk <[email protected]> Signed-off-by: jeff-lien-sndk <[email protected]>
1 parent e6deb5e commit a5741a3

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

plugins/sandisk/sandisk-nvme.c

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@ static int sndk_do_cap_telemetry_log(struct nvme_dev *dev, const char *file,
4242
__u64 capabilities = 0;
4343
nvme_root_t r;
4444
bool host_behavior_changed = false;
45-
struct nvme_feat_host_behavior prev = {0};
46-
__u32 result;
47-
48-
4945

5046
memset(&ctrl, 0, sizeof(struct nvme_id_ctrl));
5147
err = nvme_identify_ctrl(dev_fd(dev), &ctrl);
@@ -62,26 +58,23 @@ static int sndk_do_cap_telemetry_log(struct nvme_dev *dev, const char *file,
6258
r = nvme_scan(NULL);
6359
capabilities = sndk_get_drive_capabilities(r, dev);
6460

61+
if (data_area == 4) {
62+
if (!(ctrl.lpa & 0x40)) {
63+
fprintf(stderr, "%s: Telemetry data area 4 not supported by device\n",
64+
__func__);
65+
return -EINVAL;
66+
}
67+
68+
err = nvme_set_etdas(dev_fd(dev), &host_behavior_changed);
69+
if (err) {
70+
fprintf(stderr, "%s: Failed to set ETDAS bit\n", __func__);
71+
return err;
72+
}
73+
}
74+
6575
if (type == SNDK_TELEMETRY_TYPE_HOST) {
6676
host_gen = 1;
6777
ctrl_init = 0;
68-
69-
if (data_area == 4) {
70-
if (!(ctrl.lpa & 0x40)) {
71-
fprintf(stderr, "Telemetry data area 4 not supported by device\n");
72-
return -EINVAL;
73-
}
74-
75-
int err = nvme_get_features_host_behavior(dev_fd(dev), 0, &prev, &result);
76-
77-
if (!err && !prev.etdas) {
78-
struct nvme_feat_host_behavior da4_enable = prev;
79-
80-
da4_enable.etdas = 1;
81-
nvme_set_features_host_behavior(dev_fd(dev), 0, &da4_enable);
82-
host_behavior_changed = true;
83-
}
84-
}
8578
} else if (type == SNDK_TELEMETRY_TYPE_CONTROLLER) {
8679
if (capabilities & SNDK_DRIVE_CAP_INTERNAL_LOG) {
8780
err = sndk_check_ctrl_telemetry_option_disabled(dev);
@@ -157,8 +150,14 @@ static int sndk_do_cap_telemetry_log(struct nvme_dev *dev, const char *file,
157150
err = -1;
158151
}
159152

160-
if (host_behavior_changed)
161-
nvme_set_features_host_behavior(dev_fd(dev), 0, &prev);
153+
if (host_behavior_changed) {
154+
host_behavior_changed = false;
155+
err = nvme_clear_etdas(dev_fd(dev), &host_behavior_changed);
156+
if (err) {
157+
fprintf(stderr, "%s: Failed to clear ETDAS bit\n", __func__);
158+
return err;
159+
}
160+
}
162161

163162
free(log);
164163
close_output:

plugins/sandisk/sandisk-nvme.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#if !defined(SANDISK_NVME) || defined(CMD_HEADER_MULTI_READ)
66
#define SANDISK_NVME
77

8-
#define SANDISK_PLUGIN_VERSION "3.0.3"
8+
#define SANDISK_PLUGIN_VERSION "3.0.4"
99
#include "cmd.h"
1010

1111
PLUGIN(NAME("sndk", "Sandisk vendor specific extensions", SANDISK_PLUGIN_VERSION),

0 commit comments

Comments
 (0)