1 /* 2 * Copyright(c) 2013-2015 Intel Corporation. All rights reserved. 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of version 2 of the GNU General Public License as 6 * published by the Free Software Foundation. 7 * 8 * This program is distributed in the hope that it will be useful, but 9 * WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 * General Public License for more details. 12 */ 13 #ifndef __NFIT_TEST_H__ 14 #define __NFIT_TEST_H__ 15 #include <linux/list.h> 16 #include <linux/uuid.h> 17 #include <linux/ioport.h> 18 #include <linux/spinlock_types.h> 19 20 struct nfit_test_request { 21 struct list_head list; 22 struct resource res; 23 }; 24 25 struct nfit_test_resource { 26 struct list_head requests; 27 struct list_head list; 28 struct resource res; 29 struct device *dev; 30 spinlock_t lock; 31 int req_count; 32 void *buf; 33 }; 34 35 #define ND_TRANSLATE_SPA_STATUS_INVALID_SPA 2 36 #define NFIT_ARS_INJECT_INVALID 2 37 38 enum err_inj_options { 39 ND_ARS_ERR_INJ_OPT_NOTIFY = 0, 40 }; 41 42 /* nfit commands */ 43 enum nfit_cmd_num { 44 NFIT_CMD_TRANSLATE_SPA = 5, 45 NFIT_CMD_ARS_INJECT_SET = 7, 46 NFIT_CMD_ARS_INJECT_CLEAR = 8, 47 NFIT_CMD_ARS_INJECT_GET = 9, 48 }; 49 50 struct nd_cmd_translate_spa { 51 __u64 spa; 52 __u32 status; 53 __u8 flags; 54 __u8 _reserved[3]; 55 __u64 translate_length; 56 __u32 num_nvdimms; 57 struct nd_nvdimm_device { 58 __u32 nfit_device_handle; 59 __u32 _reserved; 60 __u64 dpa; 61 } __packed devices[0]; 62 63 } __packed; 64 65 struct nd_cmd_ars_err_inj { 66 __u64 err_inj_spa_range_base; 67 __u64 err_inj_spa_range_length; 68 __u8 err_inj_options; 69 __u32 status; 70 } __packed; 71 72 struct nd_cmd_ars_err_inj_clr { 73 __u64 err_inj_clr_spa_range_base; 74 __u64 err_inj_clr_spa_range_length; 75 __u32 status; 76 } __packed; 77 78 struct nd_cmd_ars_err_inj_stat { 79 __u32 status; 80 __u32 inj_err_rec_count; 81 struct nd_error_stat_query_record { 82 __u64 err_inj_stat_spa_range_base; 83 __u64 err_inj_stat_spa_range_length; 84 } __packed record[0]; 85 } __packed; 86 87 #define ND_INTEL_SMART 1 88 #define ND_INTEL_SMART_THRESHOLD 2 89 #define ND_INTEL_ENABLE_LSS_STATUS 10 90 #define ND_INTEL_FW_GET_INFO 12 91 #define ND_INTEL_FW_START_UPDATE 13 92 #define ND_INTEL_FW_SEND_DATA 14 93 #define ND_INTEL_FW_FINISH_UPDATE 15 94 #define ND_INTEL_FW_FINISH_QUERY 16 95 #define ND_INTEL_SMART_SET_THRESHOLD 17 96 97 #define ND_INTEL_SMART_HEALTH_VALID (1 << 0) 98 #define ND_INTEL_SMART_SPARES_VALID (1 << 1) 99 #define ND_INTEL_SMART_USED_VALID (1 << 2) 100 #define ND_INTEL_SMART_MTEMP_VALID (1 << 3) 101 #define ND_INTEL_SMART_CTEMP_VALID (1 << 4) 102 #define ND_INTEL_SMART_SHUTDOWN_COUNT_VALID (1 << 5) 103 #define ND_INTEL_SMART_AIT_STATUS_VALID (1 << 6) 104 #define ND_INTEL_SMART_PTEMP_VALID (1 << 7) 105 #define ND_INTEL_SMART_ALARM_VALID (1 << 9) 106 #define ND_INTEL_SMART_SHUTDOWN_VALID (1 << 10) 107 #define ND_INTEL_SMART_VENDOR_VALID (1 << 11) 108 #define ND_INTEL_SMART_SPARE_TRIP (1 << 0) 109 #define ND_INTEL_SMART_TEMP_TRIP (1 << 1) 110 #define ND_INTEL_SMART_CTEMP_TRIP (1 << 2) 111 #define ND_INTEL_SMART_NON_CRITICAL_HEALTH (1 << 0) 112 #define ND_INTEL_SMART_CRITICAL_HEALTH (1 << 1) 113 #define ND_INTEL_SMART_FATAL_HEALTH (1 << 2) 114 115 struct nd_intel_smart { 116 __u32 status; 117 union { 118 struct { 119 __u32 flags; 120 __u8 reserved0[4]; 121 __u8 health; 122 __u8 spares; 123 __u8 life_used; 124 __u8 alarm_flags; 125 __u16 media_temperature; 126 __u16 ctrl_temperature; 127 __u32 shutdown_count; 128 __u8 ait_status; 129 __u16 pmic_temperature; 130 __u8 reserved1[8]; 131 __u8 shutdown_state; 132 __u32 vendor_size; 133 __u8 vendor_data[92]; 134 } __packed; 135 __u8 data[128]; 136 }; 137 } __packed; 138 139 struct nd_intel_smart_threshold { 140 __u32 status; 141 union { 142 struct { 143 __u16 alarm_control; 144 __u8 spares; 145 __u16 media_temperature; 146 __u16 ctrl_temperature; 147 __u8 reserved[1]; 148 } __packed; 149 __u8 data[8]; 150 }; 151 } __packed; 152 153 struct nd_intel_smart_set_threshold { 154 __u16 alarm_control; 155 __u8 spares; 156 __u16 media_temperature; 157 __u16 ctrl_temperature; 158 __u32 status; 159 } __packed; 160 161 #define INTEL_FW_STORAGE_SIZE 0x100000 162 #define INTEL_FW_MAX_SEND_LEN 0xFFEC 163 #define INTEL_FW_QUERY_INTERVAL 250000 164 #define INTEL_FW_QUERY_MAX_TIME 3000000 165 #define INTEL_FW_FIS_VERSION 0x0105 166 #define INTEL_FW_FAKE_VERSION 0xffffffffabcd 167 168 enum intel_fw_update_state { 169 FW_STATE_NEW = 0, 170 FW_STATE_IN_PROGRESS, 171 FW_STATE_VERIFY, 172 FW_STATE_UPDATED, 173 }; 174 175 struct nd_intel_fw_info { 176 __u32 status; 177 __u32 storage_size; 178 __u32 max_send_len; 179 __u32 query_interval; 180 __u32 max_query_time; 181 __u8 update_cap; 182 __u8 reserved[3]; 183 __u32 fis_version; 184 __u64 run_version; 185 __u64 updated_version; 186 } __packed; 187 188 struct nd_intel_fw_start { 189 __u32 status; 190 __u32 context; 191 } __packed; 192 193 /* this one has the output first because the variable input data size */ 194 struct nd_intel_fw_send_data { 195 __u32 context; 196 __u32 offset; 197 __u32 length; 198 __u8 data[0]; 199 /* this field is not declared due ot variable data from input */ 200 /* __u32 status; */ 201 } __packed; 202 203 struct nd_intel_fw_finish_update { 204 __u8 ctrl_flags; 205 __u8 reserved[3]; 206 __u32 context; 207 __u32 status; 208 } __packed; 209 210 struct nd_intel_fw_finish_query { 211 __u32 context; 212 __u32 status; 213 __u64 updated_fw_rev; 214 } __packed; 215 216 struct nd_intel_lss { 217 __u8 enable; 218 __u32 status; 219 } __packed; 220 221 union acpi_object; 222 typedef void *acpi_handle; 223 224 typedef struct nfit_test_resource *(*nfit_test_lookup_fn)(resource_size_t); 225 typedef union acpi_object *(*nfit_test_evaluate_dsm_fn)(acpi_handle handle, 226 const guid_t *guid, u64 rev, u64 func, 227 union acpi_object *argv4); 228 void __iomem *__wrap_ioremap_nocache(resource_size_t offset, 229 unsigned long size); 230 void __wrap_iounmap(volatile void __iomem *addr); 231 void nfit_test_setup(nfit_test_lookup_fn lookup, 232 nfit_test_evaluate_dsm_fn evaluate); 233 void nfit_test_teardown(void); 234 struct nfit_test_resource *get_nfit_res(resource_size_t resource); 235 #endif 236