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

libnvdimm, testing: Add emulation for smart injection commands

Add support for the smart injection command in the nvdimm unit test
framework. This allows for directly injecting to smart fields and flags
that are supported in the injection command. If the injected values are
past the threshold, then an acpi notification is also triggered.

Cc: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>

authored by

Vishal Verma and committed by
Dan Williams
4cf260fc 14c73f99

+53 -1
+37 -1
tools/testing/nvdimm/test/nfit.c
··· 711 711 >= thresh->media_temperature) 712 712 || ((thresh->alarm_control & ND_INTEL_SMART_CTEMP_TRIP) 713 713 && smart->ctrl_temperature 714 - >= thresh->ctrl_temperature)) { 714 + >= thresh->ctrl_temperature) 715 + || (smart->health != ND_INTEL_SMART_NON_CRITICAL_HEALTH) 716 + || (smart->shutdown_state != 0)) { 715 717 device_lock(bus_dev); 716 718 __acpi_nvdimm_notify(dimm_dev, 0x81); 717 719 device_unlock(bus_dev); ··· 734 732 return -EINVAL; 735 733 memcpy(thresh->data, in, size); 736 734 in->status = 0; 735 + smart_notify(bus_dev, dimm_dev, smart, thresh); 736 + 737 + return 0; 738 + } 739 + 740 + static int nfit_test_cmd_smart_inject( 741 + struct nd_intel_smart_inject *inj, 742 + unsigned int buf_len, 743 + struct nd_intel_smart_threshold *thresh, 744 + struct nd_intel_smart *smart, 745 + struct device *bus_dev, struct device *dimm_dev) 746 + { 747 + if (buf_len != sizeof(*inj)) 748 + return -EINVAL; 749 + 750 + if (inj->mtemp_enable) 751 + smart->media_temperature = inj->media_temperature; 752 + if (inj->spare_enable) 753 + smart->spares = inj->spares; 754 + if (inj->fatal_enable) 755 + smart->health = ND_INTEL_SMART_FATAL_HEALTH; 756 + if (inj->unsafe_shutdown_enable) { 757 + smart->shutdown_state = 1; 758 + smart->shutdown_count++; 759 + } 760 + inj->status = 0; 737 761 smart_notify(bus_dev, dimm_dev, smart, thresh); 738 762 739 763 return 0; ··· 960 932 t->dcr_idx]); 961 933 case ND_INTEL_SMART_SET_THRESHOLD: 962 934 return nfit_test_cmd_smart_set_threshold(buf, 935 + buf_len, 936 + &t->smart_threshold[i - 937 + t->dcr_idx], 938 + &t->smart[i - t->dcr_idx], 939 + &t->pdev.dev, t->dimm_dev[i]); 940 + case ND_INTEL_SMART_INJECT: 941 + return nfit_test_cmd_smart_inject(buf, 963 942 buf_len, 964 943 &t->smart_threshold[i - 965 944 t->dcr_idx], ··· 2101 2066 set_bit(ND_INTEL_SMART, &acpi_desc->dimm_cmd_force_en); 2102 2067 set_bit(ND_INTEL_SMART_THRESHOLD, &acpi_desc->dimm_cmd_force_en); 2103 2068 set_bit(ND_INTEL_SMART_SET_THRESHOLD, &acpi_desc->dimm_cmd_force_en); 2069 + set_bit(ND_INTEL_SMART_INJECT, &acpi_desc->dimm_cmd_force_en); 2104 2070 set_bit(ND_CMD_ARS_CAP, &acpi_desc->bus_cmd_force_en); 2105 2071 set_bit(ND_CMD_ARS_START, &acpi_desc->bus_cmd_force_en); 2106 2072 set_bit(ND_CMD_ARS_STATUS, &acpi_desc->bus_cmd_force_en);
+16
tools/testing/nvdimm/test/nfit_test.h
··· 93 93 #define ND_INTEL_FW_FINISH_UPDATE 15 94 94 #define ND_INTEL_FW_FINISH_QUERY 16 95 95 #define ND_INTEL_SMART_SET_THRESHOLD 17 96 + #define ND_INTEL_SMART_INJECT 18 96 97 97 98 #define ND_INTEL_SMART_HEALTH_VALID (1 << 0) 98 99 #define ND_INTEL_SMART_SPARES_VALID (1 << 1) ··· 112 111 #define ND_INTEL_SMART_NON_CRITICAL_HEALTH (1 << 0) 113 112 #define ND_INTEL_SMART_CRITICAL_HEALTH (1 << 1) 114 113 #define ND_INTEL_SMART_FATAL_HEALTH (1 << 2) 114 + #define ND_INTEL_SMART_INJECT_MTEMP (1 << 0) 115 + #define ND_INTEL_SMART_INJECT_SPARE (1 << 1) 116 + #define ND_INTEL_SMART_INJECT_FATAL (1 << 2) 117 + #define ND_INTEL_SMART_INJECT_SHUTDOWN (1 << 3) 115 118 116 119 struct nd_intel_smart { 117 120 __u32 status; ··· 160 155 __u8 spares; 161 156 __u16 media_temperature; 162 157 __u16 ctrl_temperature; 158 + __u32 status; 159 + } __packed; 160 + 161 + struct nd_intel_smart_inject { 162 + __u64 flags; 163 + __u8 mtemp_enable; 164 + __u16 media_temperature; 165 + __u8 spare_enable; 166 + __u8 spares; 167 + __u8 fatal_enable; 168 + __u8 unsafe_shutdown_enable; 163 169 __u32 status; 164 170 } __packed; 165 171