Skip to content

Commit b4d4702

Browse files
stellarhopperdavejiang
authored andcommitted
tools/testing/nvdimm: improve emulation of smart injection
The emulation for smart injection commands for nfit neglected to check the smart field validity flags before injecting to that field. This is required as a way to distinguish un-injection vs. leave-alone. The emulation was also missing support for un-injection entirely. To add this support, first, fix the above flags check. Second, use the 'enable' field in the injection command to determine injection vs un-injection. Third, move the smart initialization struct to be a global static structure for the nfit_test module. Reference this to get the smart 'defaults' when un-injecting a smart field. Signed-off-by: Vishal Verma <[email protected]> Signed-off-by: Dave Jiang <[email protected]>
1 parent 86ed913 commit b4d4702

File tree

1 file changed

+47
-31
lines changed
  • tools/testing/nvdimm/test

1 file changed

+47
-31
lines changed

tools/testing/nvdimm/test/nfit.c

Lines changed: 47 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,28 @@ static u32 handle[] = {
142142
static unsigned long dimm_fail_cmd_flags[NUM_DCR];
143143
static int dimm_fail_cmd_code[NUM_DCR];
144144

145+
static const struct nd_intel_smart smart_def = {
146+
.flags = ND_INTEL_SMART_HEALTH_VALID
147+
| ND_INTEL_SMART_SPARES_VALID
148+
| ND_INTEL_SMART_ALARM_VALID
149+
| ND_INTEL_SMART_USED_VALID
150+
| ND_INTEL_SMART_SHUTDOWN_VALID
151+
| ND_INTEL_SMART_MTEMP_VALID
152+
| ND_INTEL_SMART_CTEMP_VALID,
153+
.health = ND_INTEL_SMART_NON_CRITICAL_HEALTH,
154+
.media_temperature = 23 * 16,
155+
.ctrl_temperature = 25 * 16,
156+
.pmic_temperature = 40 * 16,
157+
.spares = 75,
158+
.alarm_flags = ND_INTEL_SMART_SPARE_TRIP
159+
| ND_INTEL_SMART_TEMP_TRIP,
160+
.ait_status = 1,
161+
.life_used = 5,
162+
.shutdown_state = 0,
163+
.vendor_size = 0,
164+
.shutdown_count = 100,
165+
};
166+
145167
struct nfit_test_fw {
146168
enum intel_fw_update_state state;
147169
u32 context;
@@ -752,15 +774,30 @@ static int nfit_test_cmd_smart_inject(
752774
if (buf_len != sizeof(*inj))
753775
return -EINVAL;
754776

755-
if (inj->mtemp_enable)
756-
smart->media_temperature = inj->media_temperature;
757-
if (inj->spare_enable)
758-
smart->spares = inj->spares;
759-
if (inj->fatal_enable)
760-
smart->health = ND_INTEL_SMART_FATAL_HEALTH;
761-
if (inj->unsafe_shutdown_enable) {
762-
smart->shutdown_state = 1;
763-
smart->shutdown_count++;
777+
if (inj->flags & ND_INTEL_SMART_INJECT_MTEMP) {
778+
if (inj->mtemp_enable)
779+
smart->media_temperature = inj->media_temperature;
780+
else
781+
smart->media_temperature = smart_def.media_temperature;
782+
}
783+
if (inj->flags & ND_INTEL_SMART_INJECT_SPARE) {
784+
if (inj->spare_enable)
785+
smart->spares = inj->spares;
786+
else
787+
smart->spares = smart_def.spares;
788+
}
789+
if (inj->flags & ND_INTEL_SMART_INJECT_FATAL) {
790+
if (inj->fatal_enable)
791+
smart->health = ND_INTEL_SMART_FATAL_HEALTH;
792+
else
793+
smart->health = ND_INTEL_SMART_NON_CRITICAL_HEALTH;
794+
}
795+
if (inj->flags & ND_INTEL_SMART_INJECT_SHUTDOWN) {
796+
if (inj->unsafe_shutdown_enable) {
797+
smart->shutdown_state = 1;
798+
smart->shutdown_count++;
799+
} else
800+
smart->shutdown_state = 0;
764801
}
765802
inj->status = 0;
766803
smart_notify(bus_dev, dimm_dev, smart, thresh);
@@ -1317,30 +1354,9 @@ static void smart_init(struct nfit_test *t)
13171354
.ctrl_temperature = 30 * 16,
13181355
.spares = 5,
13191356
};
1320-
const struct nd_intel_smart smart_data = {
1321-
.flags = ND_INTEL_SMART_HEALTH_VALID
1322-
| ND_INTEL_SMART_SPARES_VALID
1323-
| ND_INTEL_SMART_ALARM_VALID
1324-
| ND_INTEL_SMART_USED_VALID
1325-
| ND_INTEL_SMART_SHUTDOWN_VALID
1326-
| ND_INTEL_SMART_MTEMP_VALID
1327-
| ND_INTEL_SMART_CTEMP_VALID,
1328-
.health = ND_INTEL_SMART_NON_CRITICAL_HEALTH,
1329-
.media_temperature = 23 * 16,
1330-
.ctrl_temperature = 25 * 16,
1331-
.pmic_temperature = 40 * 16,
1332-
.spares = 75,
1333-
.alarm_flags = ND_INTEL_SMART_SPARE_TRIP
1334-
| ND_INTEL_SMART_TEMP_TRIP,
1335-
.ait_status = 1,
1336-
.life_used = 5,
1337-
.shutdown_state = 0,
1338-
.vendor_size = 0,
1339-
.shutdown_count = 100,
1340-
};
13411357

13421358
for (i = 0; i < t->num_dcr; i++) {
1343-
memcpy(&t->smart[i], &smart_data, sizeof(smart_data));
1359+
memcpy(&t->smart[i], &smart_def, sizeof(smart_def));
13441360
memcpy(&t->smart_threshold[i], &smart_t_data,
13451361
sizeof(smart_t_data));
13461362
}

0 commit comments

Comments
 (0)