18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright(c) 2013-2015 Intel Corporation. All rights reserved. 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci#ifndef __NFIT_TEST_H__ 68c2ecf20Sopenharmony_ci#define __NFIT_TEST_H__ 78c2ecf20Sopenharmony_ci#include <linux/acpi.h> 88c2ecf20Sopenharmony_ci#include <linux/list.h> 98c2ecf20Sopenharmony_ci#include <linux/uuid.h> 108c2ecf20Sopenharmony_ci#include <linux/ioport.h> 118c2ecf20Sopenharmony_ci#include <linux/spinlock_types.h> 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_cistruct nfit_test_request { 148c2ecf20Sopenharmony_ci struct list_head list; 158c2ecf20Sopenharmony_ci struct resource res; 168c2ecf20Sopenharmony_ci}; 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_cistruct nfit_test_resource { 198c2ecf20Sopenharmony_ci struct list_head requests; 208c2ecf20Sopenharmony_ci struct list_head list; 218c2ecf20Sopenharmony_ci struct resource res; 228c2ecf20Sopenharmony_ci struct device *dev; 238c2ecf20Sopenharmony_ci spinlock_t lock; 248c2ecf20Sopenharmony_ci int req_count; 258c2ecf20Sopenharmony_ci void *buf; 268c2ecf20Sopenharmony_ci}; 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci#define ND_TRANSLATE_SPA_STATUS_INVALID_SPA 2 298c2ecf20Sopenharmony_ci#define NFIT_ARS_INJECT_INVALID 2 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_cienum err_inj_options { 328c2ecf20Sopenharmony_ci ND_ARS_ERR_INJ_OPT_NOTIFY = 0, 338c2ecf20Sopenharmony_ci}; 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci/* nfit commands */ 368c2ecf20Sopenharmony_cienum nfit_cmd_num { 378c2ecf20Sopenharmony_ci NFIT_CMD_TRANSLATE_SPA = 5, 388c2ecf20Sopenharmony_ci NFIT_CMD_ARS_INJECT_SET = 7, 398c2ecf20Sopenharmony_ci NFIT_CMD_ARS_INJECT_CLEAR = 8, 408c2ecf20Sopenharmony_ci NFIT_CMD_ARS_INJECT_GET = 9, 418c2ecf20Sopenharmony_ci}; 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_cistruct nd_cmd_translate_spa { 448c2ecf20Sopenharmony_ci __u64 spa; 458c2ecf20Sopenharmony_ci __u32 status; 468c2ecf20Sopenharmony_ci __u8 flags; 478c2ecf20Sopenharmony_ci __u8 _reserved[3]; 488c2ecf20Sopenharmony_ci __u64 translate_length; 498c2ecf20Sopenharmony_ci __u32 num_nvdimms; 508c2ecf20Sopenharmony_ci struct nd_nvdimm_device { 518c2ecf20Sopenharmony_ci __u32 nfit_device_handle; 528c2ecf20Sopenharmony_ci __u32 _reserved; 538c2ecf20Sopenharmony_ci __u64 dpa; 548c2ecf20Sopenharmony_ci } __packed devices[]; 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci} __packed; 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_cistruct nd_cmd_ars_err_inj { 598c2ecf20Sopenharmony_ci __u64 err_inj_spa_range_base; 608c2ecf20Sopenharmony_ci __u64 err_inj_spa_range_length; 618c2ecf20Sopenharmony_ci __u8 err_inj_options; 628c2ecf20Sopenharmony_ci __u32 status; 638c2ecf20Sopenharmony_ci} __packed; 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_cistruct nd_cmd_ars_err_inj_clr { 668c2ecf20Sopenharmony_ci __u64 err_inj_clr_spa_range_base; 678c2ecf20Sopenharmony_ci __u64 err_inj_clr_spa_range_length; 688c2ecf20Sopenharmony_ci __u32 status; 698c2ecf20Sopenharmony_ci} __packed; 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_cistruct nd_cmd_ars_err_inj_stat { 728c2ecf20Sopenharmony_ci __u32 status; 738c2ecf20Sopenharmony_ci __u32 inj_err_rec_count; 748c2ecf20Sopenharmony_ci struct nd_error_stat_query_record { 758c2ecf20Sopenharmony_ci __u64 err_inj_stat_spa_range_base; 768c2ecf20Sopenharmony_ci __u64 err_inj_stat_spa_range_length; 778c2ecf20Sopenharmony_ci } __packed record[]; 788c2ecf20Sopenharmony_ci} __packed; 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci#define ND_INTEL_SMART 1 818c2ecf20Sopenharmony_ci#define ND_INTEL_SMART_THRESHOLD 2 828c2ecf20Sopenharmony_ci#define ND_INTEL_ENABLE_LSS_STATUS 10 838c2ecf20Sopenharmony_ci#define ND_INTEL_FW_GET_INFO 12 848c2ecf20Sopenharmony_ci#define ND_INTEL_FW_START_UPDATE 13 858c2ecf20Sopenharmony_ci#define ND_INTEL_FW_SEND_DATA 14 868c2ecf20Sopenharmony_ci#define ND_INTEL_FW_FINISH_UPDATE 15 878c2ecf20Sopenharmony_ci#define ND_INTEL_FW_FINISH_QUERY 16 888c2ecf20Sopenharmony_ci#define ND_INTEL_SMART_SET_THRESHOLD 17 898c2ecf20Sopenharmony_ci#define ND_INTEL_SMART_INJECT 18 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ci#define ND_INTEL_SMART_HEALTH_VALID (1 << 0) 928c2ecf20Sopenharmony_ci#define ND_INTEL_SMART_SPARES_VALID (1 << 1) 938c2ecf20Sopenharmony_ci#define ND_INTEL_SMART_USED_VALID (1 << 2) 948c2ecf20Sopenharmony_ci#define ND_INTEL_SMART_MTEMP_VALID (1 << 3) 958c2ecf20Sopenharmony_ci#define ND_INTEL_SMART_CTEMP_VALID (1 << 4) 968c2ecf20Sopenharmony_ci#define ND_INTEL_SMART_SHUTDOWN_COUNT_VALID (1 << 5) 978c2ecf20Sopenharmony_ci#define ND_INTEL_SMART_AIT_STATUS_VALID (1 << 6) 988c2ecf20Sopenharmony_ci#define ND_INTEL_SMART_PTEMP_VALID (1 << 7) 998c2ecf20Sopenharmony_ci#define ND_INTEL_SMART_ALARM_VALID (1 << 9) 1008c2ecf20Sopenharmony_ci#define ND_INTEL_SMART_SHUTDOWN_VALID (1 << 10) 1018c2ecf20Sopenharmony_ci#define ND_INTEL_SMART_VENDOR_VALID (1 << 11) 1028c2ecf20Sopenharmony_ci#define ND_INTEL_SMART_SPARE_TRIP (1 << 0) 1038c2ecf20Sopenharmony_ci#define ND_INTEL_SMART_TEMP_TRIP (1 << 1) 1048c2ecf20Sopenharmony_ci#define ND_INTEL_SMART_CTEMP_TRIP (1 << 2) 1058c2ecf20Sopenharmony_ci#define ND_INTEL_SMART_NON_CRITICAL_HEALTH (1 << 0) 1068c2ecf20Sopenharmony_ci#define ND_INTEL_SMART_CRITICAL_HEALTH (1 << 1) 1078c2ecf20Sopenharmony_ci#define ND_INTEL_SMART_FATAL_HEALTH (1 << 2) 1088c2ecf20Sopenharmony_ci#define ND_INTEL_SMART_INJECT_MTEMP (1 << 0) 1098c2ecf20Sopenharmony_ci#define ND_INTEL_SMART_INJECT_SPARE (1 << 1) 1108c2ecf20Sopenharmony_ci#define ND_INTEL_SMART_INJECT_FATAL (1 << 2) 1118c2ecf20Sopenharmony_ci#define ND_INTEL_SMART_INJECT_SHUTDOWN (1 << 3) 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_cistruct nd_intel_smart_threshold { 1148c2ecf20Sopenharmony_ci __u32 status; 1158c2ecf20Sopenharmony_ci union { 1168c2ecf20Sopenharmony_ci struct { 1178c2ecf20Sopenharmony_ci __u16 alarm_control; 1188c2ecf20Sopenharmony_ci __u8 spares; 1198c2ecf20Sopenharmony_ci __u16 media_temperature; 1208c2ecf20Sopenharmony_ci __u16 ctrl_temperature; 1218c2ecf20Sopenharmony_ci __u8 reserved[1]; 1228c2ecf20Sopenharmony_ci } __packed; 1238c2ecf20Sopenharmony_ci __u8 data[8]; 1248c2ecf20Sopenharmony_ci }; 1258c2ecf20Sopenharmony_ci} __packed; 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_cistruct nd_intel_smart_set_threshold { 1288c2ecf20Sopenharmony_ci __u16 alarm_control; 1298c2ecf20Sopenharmony_ci __u8 spares; 1308c2ecf20Sopenharmony_ci __u16 media_temperature; 1318c2ecf20Sopenharmony_ci __u16 ctrl_temperature; 1328c2ecf20Sopenharmony_ci __u32 status; 1338c2ecf20Sopenharmony_ci} __packed; 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_cistruct nd_intel_smart_inject { 1368c2ecf20Sopenharmony_ci __u64 flags; 1378c2ecf20Sopenharmony_ci __u8 mtemp_enable; 1388c2ecf20Sopenharmony_ci __u16 media_temperature; 1398c2ecf20Sopenharmony_ci __u8 spare_enable; 1408c2ecf20Sopenharmony_ci __u8 spares; 1418c2ecf20Sopenharmony_ci __u8 fatal_enable; 1428c2ecf20Sopenharmony_ci __u8 unsafe_shutdown_enable; 1438c2ecf20Sopenharmony_ci __u32 status; 1448c2ecf20Sopenharmony_ci} __packed; 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_ci#define INTEL_FW_STORAGE_SIZE 0x100000 1478c2ecf20Sopenharmony_ci#define INTEL_FW_MAX_SEND_LEN 0xFFEC 1488c2ecf20Sopenharmony_ci#define INTEL_FW_QUERY_INTERVAL 250000 1498c2ecf20Sopenharmony_ci#define INTEL_FW_QUERY_MAX_TIME 3000000 1508c2ecf20Sopenharmony_ci#define INTEL_FW_FIS_VERSION 0x0105 1518c2ecf20Sopenharmony_ci#define INTEL_FW_FAKE_VERSION 0xffffffffabcd 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_cienum intel_fw_update_state { 1548c2ecf20Sopenharmony_ci FW_STATE_NEW = 0, 1558c2ecf20Sopenharmony_ci FW_STATE_IN_PROGRESS, 1568c2ecf20Sopenharmony_ci FW_STATE_VERIFY, 1578c2ecf20Sopenharmony_ci FW_STATE_UPDATED, 1588c2ecf20Sopenharmony_ci}; 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_cistruct nd_intel_fw_info { 1618c2ecf20Sopenharmony_ci __u32 status; 1628c2ecf20Sopenharmony_ci __u32 storage_size; 1638c2ecf20Sopenharmony_ci __u32 max_send_len; 1648c2ecf20Sopenharmony_ci __u32 query_interval; 1658c2ecf20Sopenharmony_ci __u32 max_query_time; 1668c2ecf20Sopenharmony_ci __u8 update_cap; 1678c2ecf20Sopenharmony_ci __u8 reserved[3]; 1688c2ecf20Sopenharmony_ci __u32 fis_version; 1698c2ecf20Sopenharmony_ci __u64 run_version; 1708c2ecf20Sopenharmony_ci __u64 updated_version; 1718c2ecf20Sopenharmony_ci} __packed; 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_cistruct nd_intel_fw_start { 1748c2ecf20Sopenharmony_ci __u32 status; 1758c2ecf20Sopenharmony_ci __u32 context; 1768c2ecf20Sopenharmony_ci} __packed; 1778c2ecf20Sopenharmony_ci 1788c2ecf20Sopenharmony_ci/* this one has the output first because the variable input data size */ 1798c2ecf20Sopenharmony_cistruct nd_intel_fw_send_data { 1808c2ecf20Sopenharmony_ci __u32 context; 1818c2ecf20Sopenharmony_ci __u32 offset; 1828c2ecf20Sopenharmony_ci __u32 length; 1838c2ecf20Sopenharmony_ci __u8 data[]; 1848c2ecf20Sopenharmony_ci/* this field is not declared due ot variable data from input */ 1858c2ecf20Sopenharmony_ci/* __u32 status; */ 1868c2ecf20Sopenharmony_ci} __packed; 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_cistruct nd_intel_fw_finish_update { 1898c2ecf20Sopenharmony_ci __u8 ctrl_flags; 1908c2ecf20Sopenharmony_ci __u8 reserved[3]; 1918c2ecf20Sopenharmony_ci __u32 context; 1928c2ecf20Sopenharmony_ci __u32 status; 1938c2ecf20Sopenharmony_ci} __packed; 1948c2ecf20Sopenharmony_ci 1958c2ecf20Sopenharmony_cistruct nd_intel_fw_finish_query { 1968c2ecf20Sopenharmony_ci __u32 context; 1978c2ecf20Sopenharmony_ci __u32 status; 1988c2ecf20Sopenharmony_ci __u64 updated_fw_rev; 1998c2ecf20Sopenharmony_ci} __packed; 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_cistruct nd_intel_lss { 2028c2ecf20Sopenharmony_ci __u8 enable; 2038c2ecf20Sopenharmony_ci __u32 status; 2048c2ecf20Sopenharmony_ci} __packed; 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_citypedef struct nfit_test_resource *(*nfit_test_lookup_fn)(resource_size_t); 2078c2ecf20Sopenharmony_citypedef union acpi_object *(*nfit_test_evaluate_dsm_fn)(acpi_handle handle, 2088c2ecf20Sopenharmony_ci const guid_t *guid, u64 rev, u64 func, 2098c2ecf20Sopenharmony_ci union acpi_object *argv4); 2108c2ecf20Sopenharmony_civoid __wrap_iounmap(volatile void __iomem *addr); 2118c2ecf20Sopenharmony_civoid nfit_test_setup(nfit_test_lookup_fn lookup, 2128c2ecf20Sopenharmony_ci nfit_test_evaluate_dsm_fn evaluate); 2138c2ecf20Sopenharmony_civoid nfit_test_teardown(void); 2148c2ecf20Sopenharmony_cistruct nfit_test_resource *get_nfit_res(resource_size_t resource); 2158c2ecf20Sopenharmony_ci#endif 216