Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <vishal.l.verma@intel.com>
Signed-off-by: Dave Jiang <dave.jiang@intel.com>

authored by

Vishal Verma and committed by
Dave Jiang
b4d4702f 86ed913b

+47 -31
+47 -31
tools/testing/nvdimm/test/nfit.c
··· 142 142 static unsigned long dimm_fail_cmd_flags[NUM_DCR]; 143 143 static int dimm_fail_cmd_code[NUM_DCR]; 144 144 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 + 145 167 struct nfit_test_fw { 146 168 enum intel_fw_update_state state; 147 169 u32 context; ··· 774 752 if (buf_len != sizeof(*inj)) 775 753 return -EINVAL; 776 754 777 - if (inj->mtemp_enable) 778 - smart->media_temperature = inj->media_temperature; 779 - if (inj->spare_enable) 780 - smart->spares = inj->spares; 781 - if (inj->fatal_enable) 782 - smart->health = ND_INTEL_SMART_FATAL_HEALTH; 783 - if (inj->unsafe_shutdown_enable) { 784 - smart->shutdown_state = 1; 785 - smart->shutdown_count++; 755 + if (inj->flags & ND_INTEL_SMART_INJECT_MTEMP) { 756 + if (inj->mtemp_enable) 757 + smart->media_temperature = inj->media_temperature; 758 + else 759 + smart->media_temperature = smart_def.media_temperature; 760 + } 761 + if (inj->flags & ND_INTEL_SMART_INJECT_SPARE) { 762 + if (inj->spare_enable) 763 + smart->spares = inj->spares; 764 + else 765 + smart->spares = smart_def.spares; 766 + } 767 + if (inj->flags & ND_INTEL_SMART_INJECT_FATAL) { 768 + if (inj->fatal_enable) 769 + smart->health = ND_INTEL_SMART_FATAL_HEALTH; 770 + else 771 + smart->health = ND_INTEL_SMART_NON_CRITICAL_HEALTH; 772 + } 773 + if (inj->flags & ND_INTEL_SMART_INJECT_SHUTDOWN) { 774 + if (inj->unsafe_shutdown_enable) { 775 + smart->shutdown_state = 1; 776 + smart->shutdown_count++; 777 + } else 778 + smart->shutdown_state = 0; 786 779 } 787 780 inj->status = 0; 788 781 smart_notify(bus_dev, dimm_dev, smart, thresh); ··· 1354 1317 .ctrl_temperature = 30 * 16, 1355 1318 .spares = 5, 1356 1319 }; 1357 - const struct nd_intel_smart smart_data = { 1358 - .flags = ND_INTEL_SMART_HEALTH_VALID 1359 - | ND_INTEL_SMART_SPARES_VALID 1360 - | ND_INTEL_SMART_ALARM_VALID 1361 - | ND_INTEL_SMART_USED_VALID 1362 - | ND_INTEL_SMART_SHUTDOWN_VALID 1363 - | ND_INTEL_SMART_MTEMP_VALID 1364 - | ND_INTEL_SMART_CTEMP_VALID, 1365 - .health = ND_INTEL_SMART_NON_CRITICAL_HEALTH, 1366 - .media_temperature = 23 * 16, 1367 - .ctrl_temperature = 25 * 16, 1368 - .pmic_temperature = 40 * 16, 1369 - .spares = 75, 1370 - .alarm_flags = ND_INTEL_SMART_SPARE_TRIP 1371 - | ND_INTEL_SMART_TEMP_TRIP, 1372 - .ait_status = 1, 1373 - .life_used = 5, 1374 - .shutdown_state = 0, 1375 - .vendor_size = 0, 1376 - .shutdown_count = 100, 1377 - }; 1378 1320 1379 1321 for (i = 0; i < t->num_dcr; i++) { 1380 - memcpy(&t->smart[i], &smart_data, sizeof(smart_data)); 1322 + memcpy(&t->smart[i], &smart_def, sizeof(smart_def)); 1381 1323 memcpy(&t->smart_threshold[i], &smart_t_data, 1382 1324 sizeof(smart_t_data)); 1383 1325 }