15b497af4SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 26bc75619SDan Williams /* 36bc75619SDan Williams * Copyright(c) 2013-2015 Intel Corporation. All rights reserved. 46bc75619SDan Williams */ 56bc75619SDan Williams #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 66bc75619SDan Williams #include <linux/platform_device.h> 76bc75619SDan Williams #include <linux/dma-mapping.h> 8d8d378faSDan Williams #include <linux/workqueue.h> 96bc75619SDan Williams #include <linux/libnvdimm.h> 10e3f5df76SDan Williams #include <linux/genalloc.h> 116bc75619SDan Williams #include <linux/vmalloc.h> 126bc75619SDan Williams #include <linux/device.h> 136bc75619SDan Williams #include <linux/module.h> 1420985164SVishal Verma #include <linux/mutex.h> 156bc75619SDan Williams #include <linux/ndctl.h> 166bc75619SDan Williams #include <linux/sizes.h> 1720985164SVishal Verma #include <linux/list.h> 186bc75619SDan Williams #include <linux/slab.h> 19a7de92daSDan Williams #include <nd-core.h> 200ead1118SDan Williams #include <intel.h> 216bc75619SDan Williams #include <nfit.h> 226bc75619SDan Williams #include <nd.h> 236bc75619SDan Williams #include "nfit_test.h" 240fb5c8dfSDan Williams #include "../watermark.h" 256bc75619SDan Williams 265d8beee2SDan Williams #include <asm/mcsafe_test.h> 275d8beee2SDan Williams 286bc75619SDan Williams /* 296bc75619SDan Williams * Generate an NFIT table to describe the following topology: 306bc75619SDan Williams * 316bc75619SDan Williams * BUS0: Interleaved PMEM regions, and aliasing with BLK regions 326bc75619SDan Williams * 336bc75619SDan Williams * (a) (b) DIMM BLK-REGION 346bc75619SDan Williams * +----------+--------------+----------+---------+ 356bc75619SDan Williams * +------+ | blk2.0 | pm0.0 | blk2.1 | pm1.0 | 0 region2 366bc75619SDan Williams * | imc0 +--+- - - - - region0 - - - -+----------+ + 376bc75619SDan Williams * +--+---+ | blk3.0 | pm0.0 | blk3.1 | pm1.0 | 1 region3 386bc75619SDan Williams * | +----------+--------------v----------v v 396bc75619SDan Williams * +--+---+ | | 406bc75619SDan Williams * | cpu0 | region1 416bc75619SDan Williams * +--+---+ | | 426bc75619SDan Williams * | +-------------------------^----------^ ^ 436bc75619SDan Williams * +--+---+ | blk4.0 | pm1.0 | 2 region4 446bc75619SDan Williams * | imc1 +--+-------------------------+----------+ + 456bc75619SDan Williams * +------+ | blk5.0 | pm1.0 | 3 region5 466bc75619SDan Williams * +-------------------------+----------+-+-------+ 476bc75619SDan Williams * 4820985164SVishal Verma * +--+---+ 4920985164SVishal Verma * | cpu1 | 5020985164SVishal Verma * +--+---+ (Hotplug DIMM) 5120985164SVishal Verma * | +----------------------------------------------+ 5220985164SVishal Verma * +--+---+ | blk6.0/pm7.0 | 4 region6/7 5320985164SVishal Verma * | imc0 +--+----------------------------------------------+ 5420985164SVishal Verma * +------+ 5520985164SVishal Verma * 5620985164SVishal Verma * 576bc75619SDan Williams * *) In this layout we have four dimms and two memory controllers in one 586bc75619SDan Williams * socket. Each unique interface (BLK or PMEM) to DPA space 596bc75619SDan Williams * is identified by a region device with a dynamically assigned id. 606bc75619SDan Williams * 616bc75619SDan Williams * *) The first portion of dimm0 and dimm1 are interleaved as REGION0. 626bc75619SDan Williams * A single PMEM namespace "pm0.0" is created using half of the 636bc75619SDan Williams * REGION0 SPA-range. REGION0 spans dimm0 and dimm1. PMEM namespace 646bc75619SDan Williams * allocate from from the bottom of a region. The unallocated 656bc75619SDan Williams * portion of REGION0 aliases with REGION2 and REGION3. That 666bc75619SDan Williams * unallacted capacity is reclaimed as BLK namespaces ("blk2.0" and 676bc75619SDan Williams * "blk3.0") starting at the base of each DIMM to offset (a) in those 686bc75619SDan Williams * DIMMs. "pm0.0", "blk2.0" and "blk3.0" are free-form readable 696bc75619SDan Williams * names that can be assigned to a namespace. 706bc75619SDan Williams * 716bc75619SDan Williams * *) In the last portion of dimm0 and dimm1 we have an interleaved 726bc75619SDan Williams * SPA range, REGION1, that spans those two dimms as well as dimm2 736bc75619SDan Williams * and dimm3. Some of REGION1 allocated to a PMEM namespace named 746bc75619SDan Williams * "pm1.0" the rest is reclaimed in 4 BLK namespaces (for each 756bc75619SDan Williams * dimm in the interleave set), "blk2.1", "blk3.1", "blk4.0", and 766bc75619SDan Williams * "blk5.0". 776bc75619SDan Williams * 786bc75619SDan Williams * *) The portion of dimm2 and dimm3 that do not participate in the 796bc75619SDan Williams * REGION1 interleaved SPA range (i.e. the DPA address below offset 806bc75619SDan Williams * (b) are also included in the "blk4.0" and "blk5.0" namespaces. 816bc75619SDan Williams * Note, that BLK namespaces need not be contiguous in DPA-space, and 826bc75619SDan Williams * can consume aliased capacity from multiple interleave sets. 836bc75619SDan Williams * 846bc75619SDan Williams * BUS1: Legacy NVDIMM (single contiguous range) 856bc75619SDan Williams * 866bc75619SDan Williams * region2 876bc75619SDan Williams * +---------------------+ 886bc75619SDan Williams * |---------------------| 896bc75619SDan Williams * || pm2.0 || 906bc75619SDan Williams * |---------------------| 916bc75619SDan Williams * +---------------------+ 926bc75619SDan Williams * 936bc75619SDan Williams * *) A NFIT-table may describe a simple system-physical-address range 946bc75619SDan Williams * with no BLK aliasing. This type of region may optionally 956bc75619SDan Williams * reference an NVDIMM. 966bc75619SDan Williams */ 976bc75619SDan Williams enum { 9820985164SVishal Verma NUM_PM = 3, 9920985164SVishal Verma NUM_DCR = 5, 10085d3fa02SDan Williams NUM_HINTS = 8, 1016bc75619SDan Williams NUM_BDW = NUM_DCR, 1026bc75619SDan Williams NUM_SPA = NUM_PM + NUM_DCR + NUM_BDW, 1039741a559SRoss Zwisler NUM_MEM = NUM_DCR + NUM_BDW + 2 /* spa0 iset */ 1049741a559SRoss Zwisler + 4 /* spa1 iset */ + 1 /* spa11 iset */, 1056bc75619SDan Williams DIMM_SIZE = SZ_32M, 1066bc75619SDan Williams LABEL_SIZE = SZ_128K, 1077bfe97c7SDan Williams SPA_VCD_SIZE = SZ_4M, 1086bc75619SDan Williams SPA0_SIZE = DIMM_SIZE, 1096bc75619SDan Williams SPA1_SIZE = DIMM_SIZE*2, 1106bc75619SDan Williams SPA2_SIZE = DIMM_SIZE, 1116bc75619SDan Williams BDW_SIZE = 64 << 8, 1126bc75619SDan Williams DCR_SIZE = 12, 1136bc75619SDan Williams NUM_NFITS = 2, /* permit testing multiple NFITs per system */ 1146bc75619SDan Williams }; 1156bc75619SDan Williams 1166bc75619SDan Williams struct nfit_test_dcr { 1176bc75619SDan Williams __le64 bdw_addr; 1186bc75619SDan Williams __le32 bdw_status; 1196bc75619SDan Williams __u8 aperature[BDW_SIZE]; 1206bc75619SDan Williams }; 1216bc75619SDan Williams 1226bc75619SDan Williams #define NFIT_DIMM_HANDLE(node, socket, imc, chan, dimm) \ 1236bc75619SDan Williams (((node & 0xfff) << 16) | ((socket & 0xf) << 12) \ 1246bc75619SDan Williams | ((imc & 0xf) << 8) | ((chan & 0xf) << 4) | (dimm & 0xf)) 1256bc75619SDan Williams 126dafb1048SDan Williams static u32 handle[] = { 1276bc75619SDan Williams [0] = NFIT_DIMM_HANDLE(0, 0, 0, 0, 0), 1286bc75619SDan Williams [1] = NFIT_DIMM_HANDLE(0, 0, 0, 0, 1), 1296bc75619SDan Williams [2] = NFIT_DIMM_HANDLE(0, 0, 1, 0, 0), 1306bc75619SDan Williams [3] = NFIT_DIMM_HANDLE(0, 0, 1, 0, 1), 13120985164SVishal Verma [4] = NFIT_DIMM_HANDLE(0, 1, 0, 0, 0), 132dafb1048SDan Williams [5] = NFIT_DIMM_HANDLE(1, 0, 0, 0, 0), 133ac40b675SDan Williams [6] = NFIT_DIMM_HANDLE(1, 0, 0, 0, 1), 1346bc75619SDan Williams }; 1356bc75619SDan Williams 136af31b04bSMasayoshi Mizuma static unsigned long dimm_fail_cmd_flags[ARRAY_SIZE(handle)]; 137af31b04bSMasayoshi Mizuma static int dimm_fail_cmd_code[ARRAY_SIZE(handle)]; 1383c13e2acSDave Jiang struct nfit_test_sec { 1393c13e2acSDave Jiang u8 state; 140ecaa4a97SDave Jiang u8 ext_state; 1412170a0d5SDave Jiang u8 old_state; 1423c13e2acSDave Jiang u8 passphrase[32]; 143ecaa4a97SDave Jiang u8 master_passphrase[32]; 144926f7480SDave Jiang u64 overwrite_end_time; 1453c13e2acSDave Jiang } dimm_sec_info[NUM_DCR]; 14673606afdSDan Williams 147b4d4702fSVishal Verma static const struct nd_intel_smart smart_def = { 148b4d4702fSVishal Verma .flags = ND_INTEL_SMART_HEALTH_VALID 149b4d4702fSVishal Verma | ND_INTEL_SMART_SPARES_VALID 150b4d4702fSVishal Verma | ND_INTEL_SMART_ALARM_VALID 151b4d4702fSVishal Verma | ND_INTEL_SMART_USED_VALID 152b4d4702fSVishal Verma | ND_INTEL_SMART_SHUTDOWN_VALID 153f1101766SDan Williams | ND_INTEL_SMART_SHUTDOWN_COUNT_VALID 154b4d4702fSVishal Verma | ND_INTEL_SMART_MTEMP_VALID 155b4d4702fSVishal Verma | ND_INTEL_SMART_CTEMP_VALID, 156b4d4702fSVishal Verma .health = ND_INTEL_SMART_NON_CRITICAL_HEALTH, 157b4d4702fSVishal Verma .media_temperature = 23 * 16, 158b4d4702fSVishal Verma .ctrl_temperature = 25 * 16, 159b4d4702fSVishal Verma .pmic_temperature = 40 * 16, 160b4d4702fSVishal Verma .spares = 75, 161b4d4702fSVishal Verma .alarm_flags = ND_INTEL_SMART_SPARE_TRIP 162b4d4702fSVishal Verma | ND_INTEL_SMART_TEMP_TRIP, 163b4d4702fSVishal Verma .ait_status = 1, 164b4d4702fSVishal Verma .life_used = 5, 165b4d4702fSVishal Verma .shutdown_state = 0, 166f1101766SDan Williams .shutdown_count = 42, 167b4d4702fSVishal Verma .vendor_size = 0, 168b4d4702fSVishal Verma }; 169b4d4702fSVishal Verma 170bfbaa952SDave Jiang struct nfit_test_fw { 171bfbaa952SDave Jiang enum intel_fw_update_state state; 172bfbaa952SDave Jiang u32 context; 173bfbaa952SDave Jiang u64 version; 174bfbaa952SDave Jiang u32 size_received; 175bfbaa952SDave Jiang u64 end_time; 176*916566aeSDan Williams bool armed; 177*916566aeSDan Williams bool missed_activate; 178*916566aeSDan Williams unsigned long last_activate; 179bfbaa952SDave Jiang }; 180bfbaa952SDave Jiang 1816bc75619SDan Williams struct nfit_test { 1826bc75619SDan Williams struct acpi_nfit_desc acpi_desc; 1836bc75619SDan Williams struct platform_device pdev; 1846bc75619SDan Williams struct list_head resources; 1856bc75619SDan Williams void *nfit_buf; 1866bc75619SDan Williams dma_addr_t nfit_dma; 1876bc75619SDan Williams size_t nfit_size; 1881526f9e2SRoss Zwisler size_t nfit_filled; 189dafb1048SDan Williams int dcr_idx; 1906bc75619SDan Williams int num_dcr; 1916bc75619SDan Williams int num_pm; 1926bc75619SDan Williams void **dimm; 1936bc75619SDan Williams dma_addr_t *dimm_dma; 1949d27a87eSDan Williams void **flush; 1959d27a87eSDan Williams dma_addr_t *flush_dma; 1966bc75619SDan Williams void **label; 1976bc75619SDan Williams dma_addr_t *label_dma; 1986bc75619SDan Williams void **spa_set; 1996bc75619SDan Williams dma_addr_t *spa_set_dma; 2006bc75619SDan Williams struct nfit_test_dcr **dcr; 2016bc75619SDan Williams dma_addr_t *dcr_dma; 2026bc75619SDan Williams int (*alloc)(struct nfit_test *t); 2036bc75619SDan Williams void (*setup)(struct nfit_test *t); 20420985164SVishal Verma int setup_hotplug; 205c14a868aSDan Williams union acpi_object **_fit; 206c14a868aSDan Williams dma_addr_t _fit_dma; 207f471f1a7SDan Williams struct ars_state { 208f471f1a7SDan Williams struct nd_cmd_ars_status *ars_status; 209f471f1a7SDan Williams unsigned long deadline; 210f471f1a7SDan Williams spinlock_t lock; 211f471f1a7SDan Williams } ars_state; 212af31b04bSMasayoshi Mizuma struct device *dimm_dev[ARRAY_SIZE(handle)]; 213ed07c433SDan Williams struct nd_intel_smart *smart; 214ed07c433SDan Williams struct nd_intel_smart_threshold *smart_threshold; 2159fb1a190SDave Jiang struct badrange badrange; 2169fb1a190SDave Jiang struct work_struct work; 217bfbaa952SDave Jiang struct nfit_test_fw *fw; 2186bc75619SDan Williams }; 2196bc75619SDan Williams 2209fb1a190SDave Jiang static struct workqueue_struct *nfit_wq; 2219fb1a190SDave Jiang 222e3f5df76SDan Williams static struct gen_pool *nfit_pool; 223e3f5df76SDan Williams 224037c8489SDave Jiang static const char zero_key[NVDIMM_PASSPHRASE_LEN]; 225037c8489SDave Jiang 2266bc75619SDan Williams static struct nfit_test *to_nfit_test(struct device *dev) 2276bc75619SDan Williams { 2286bc75619SDan Williams struct platform_device *pdev = to_platform_device(dev); 2296bc75619SDan Williams 2306bc75619SDan Williams return container_of(pdev, struct nfit_test, pdev); 2316bc75619SDan Williams } 2326bc75619SDan Williams 233bfbaa952SDave Jiang static int nd_intel_test_get_fw_info(struct nfit_test *t, 234bfbaa952SDave Jiang struct nd_intel_fw_info *nd_cmd, unsigned int buf_len, 235bfbaa952SDave Jiang int idx) 236bfbaa952SDave Jiang { 237bfbaa952SDave Jiang struct device *dev = &t->pdev.dev; 238bfbaa952SDave Jiang struct nfit_test_fw *fw = &t->fw[idx]; 239bfbaa952SDave Jiang 240bfbaa952SDave Jiang dev_dbg(dev, "%s(nfit_test: %p nd_cmd: %p, buf_len: %u, idx: %d\n", 241bfbaa952SDave Jiang __func__, t, nd_cmd, buf_len, idx); 242bfbaa952SDave Jiang 243bfbaa952SDave Jiang if (buf_len < sizeof(*nd_cmd)) 244bfbaa952SDave Jiang return -EINVAL; 245bfbaa952SDave Jiang 246bfbaa952SDave Jiang nd_cmd->status = 0; 247bfbaa952SDave Jiang nd_cmd->storage_size = INTEL_FW_STORAGE_SIZE; 248bfbaa952SDave Jiang nd_cmd->max_send_len = INTEL_FW_MAX_SEND_LEN; 249bfbaa952SDave Jiang nd_cmd->query_interval = INTEL_FW_QUERY_INTERVAL; 250bfbaa952SDave Jiang nd_cmd->max_query_time = INTEL_FW_QUERY_MAX_TIME; 251bfbaa952SDave Jiang nd_cmd->update_cap = 0; 252bfbaa952SDave Jiang nd_cmd->fis_version = INTEL_FW_FIS_VERSION; 253bfbaa952SDave Jiang nd_cmd->run_version = 0; 254bfbaa952SDave Jiang nd_cmd->updated_version = fw->version; 255bfbaa952SDave Jiang 256bfbaa952SDave Jiang return 0; 257bfbaa952SDave Jiang } 258bfbaa952SDave Jiang 259bfbaa952SDave Jiang static int nd_intel_test_start_update(struct nfit_test *t, 260bfbaa952SDave Jiang struct nd_intel_fw_start *nd_cmd, unsigned int buf_len, 261bfbaa952SDave Jiang int idx) 262bfbaa952SDave Jiang { 263bfbaa952SDave Jiang struct device *dev = &t->pdev.dev; 264bfbaa952SDave Jiang struct nfit_test_fw *fw = &t->fw[idx]; 265bfbaa952SDave Jiang 266bfbaa952SDave Jiang dev_dbg(dev, "%s(nfit_test: %p nd_cmd: %p buf_len: %u idx: %d)\n", 267bfbaa952SDave Jiang __func__, t, nd_cmd, buf_len, idx); 268bfbaa952SDave Jiang 269bfbaa952SDave Jiang if (buf_len < sizeof(*nd_cmd)) 270bfbaa952SDave Jiang return -EINVAL; 271bfbaa952SDave Jiang 272bfbaa952SDave Jiang if (fw->state != FW_STATE_NEW) { 273bfbaa952SDave Jiang /* extended status, FW update in progress */ 274bfbaa952SDave Jiang nd_cmd->status = 0x10007; 275bfbaa952SDave Jiang return 0; 276bfbaa952SDave Jiang } 277bfbaa952SDave Jiang 278bfbaa952SDave Jiang fw->state = FW_STATE_IN_PROGRESS; 279bfbaa952SDave Jiang fw->context++; 280bfbaa952SDave Jiang fw->size_received = 0; 281bfbaa952SDave Jiang nd_cmd->status = 0; 282bfbaa952SDave Jiang nd_cmd->context = fw->context; 283bfbaa952SDave Jiang 284bfbaa952SDave Jiang dev_dbg(dev, "%s: context issued: %#x\n", __func__, nd_cmd->context); 285bfbaa952SDave Jiang 286bfbaa952SDave Jiang return 0; 287bfbaa952SDave Jiang } 288bfbaa952SDave Jiang 289bfbaa952SDave Jiang static int nd_intel_test_send_data(struct nfit_test *t, 290bfbaa952SDave Jiang struct nd_intel_fw_send_data *nd_cmd, unsigned int buf_len, 291bfbaa952SDave Jiang int idx) 292bfbaa952SDave Jiang { 293bfbaa952SDave Jiang struct device *dev = &t->pdev.dev; 294bfbaa952SDave Jiang struct nfit_test_fw *fw = &t->fw[idx]; 295bfbaa952SDave Jiang u32 *status = (u32 *)&nd_cmd->data[nd_cmd->length]; 296bfbaa952SDave Jiang 297bfbaa952SDave Jiang dev_dbg(dev, "%s(nfit_test: %p nd_cmd: %p buf_len: %u idx: %d)\n", 298bfbaa952SDave Jiang __func__, t, nd_cmd, buf_len, idx); 299bfbaa952SDave Jiang 300bfbaa952SDave Jiang if (buf_len < sizeof(*nd_cmd)) 301bfbaa952SDave Jiang return -EINVAL; 302bfbaa952SDave Jiang 303bfbaa952SDave Jiang 304bfbaa952SDave Jiang dev_dbg(dev, "%s: cmd->status: %#x\n", __func__, *status); 305bfbaa952SDave Jiang dev_dbg(dev, "%s: cmd->data[0]: %#x\n", __func__, nd_cmd->data[0]); 306bfbaa952SDave Jiang dev_dbg(dev, "%s: cmd->data[%u]: %#x\n", __func__, nd_cmd->length-1, 307bfbaa952SDave Jiang nd_cmd->data[nd_cmd->length-1]); 308bfbaa952SDave Jiang 309bfbaa952SDave Jiang if (fw->state != FW_STATE_IN_PROGRESS) { 310bfbaa952SDave Jiang dev_dbg(dev, "%s: not in IN_PROGRESS state\n", __func__); 311bfbaa952SDave Jiang *status = 0x5; 312bfbaa952SDave Jiang return 0; 313bfbaa952SDave Jiang } 314bfbaa952SDave Jiang 315bfbaa952SDave Jiang if (nd_cmd->context != fw->context) { 316bfbaa952SDave Jiang dev_dbg(dev, "%s: incorrect context: in: %#x correct: %#x\n", 317bfbaa952SDave Jiang __func__, nd_cmd->context, fw->context); 318bfbaa952SDave Jiang *status = 0x10007; 319bfbaa952SDave Jiang return 0; 320bfbaa952SDave Jiang } 321bfbaa952SDave Jiang 322bfbaa952SDave Jiang /* 323bfbaa952SDave Jiang * check offset + len > size of fw storage 324bfbaa952SDave Jiang * check length is > max send length 325bfbaa952SDave Jiang */ 326bfbaa952SDave Jiang if (nd_cmd->offset + nd_cmd->length > INTEL_FW_STORAGE_SIZE || 327bfbaa952SDave Jiang nd_cmd->length > INTEL_FW_MAX_SEND_LEN) { 328bfbaa952SDave Jiang *status = 0x3; 329bfbaa952SDave Jiang dev_dbg(dev, "%s: buffer boundary violation\n", __func__); 330bfbaa952SDave Jiang return 0; 331bfbaa952SDave Jiang } 332bfbaa952SDave Jiang 333bfbaa952SDave Jiang fw->size_received += nd_cmd->length; 334bfbaa952SDave Jiang dev_dbg(dev, "%s: copying %u bytes, %u bytes so far\n", 335bfbaa952SDave Jiang __func__, nd_cmd->length, fw->size_received); 336bfbaa952SDave Jiang *status = 0; 337bfbaa952SDave Jiang return 0; 338bfbaa952SDave Jiang } 339bfbaa952SDave Jiang 340bfbaa952SDave Jiang static int nd_intel_test_finish_fw(struct nfit_test *t, 341bfbaa952SDave Jiang struct nd_intel_fw_finish_update *nd_cmd, 342bfbaa952SDave Jiang unsigned int buf_len, int idx) 343bfbaa952SDave Jiang { 344bfbaa952SDave Jiang struct device *dev = &t->pdev.dev; 345bfbaa952SDave Jiang struct nfit_test_fw *fw = &t->fw[idx]; 346bfbaa952SDave Jiang 347bfbaa952SDave Jiang dev_dbg(dev, "%s(nfit_test: %p nd_cmd: %p buf_len: %u idx: %d)\n", 348bfbaa952SDave Jiang __func__, t, nd_cmd, buf_len, idx); 349bfbaa952SDave Jiang 350bfbaa952SDave Jiang if (fw->state == FW_STATE_UPDATED) { 351*916566aeSDan Williams /* update already done, need activation */ 352bfbaa952SDave Jiang nd_cmd->status = 0x20007; 353bfbaa952SDave Jiang return 0; 354bfbaa952SDave Jiang } 355bfbaa952SDave Jiang 356bfbaa952SDave Jiang dev_dbg(dev, "%s: context: %#x ctrl_flags: %#x\n", 357bfbaa952SDave Jiang __func__, nd_cmd->context, nd_cmd->ctrl_flags); 358bfbaa952SDave Jiang 359bfbaa952SDave Jiang switch (nd_cmd->ctrl_flags) { 360bfbaa952SDave Jiang case 0: /* finish */ 361bfbaa952SDave Jiang if (nd_cmd->context != fw->context) { 362bfbaa952SDave Jiang dev_dbg(dev, "%s: incorrect context: in: %#x correct: %#x\n", 363bfbaa952SDave Jiang __func__, nd_cmd->context, 364bfbaa952SDave Jiang fw->context); 365bfbaa952SDave Jiang nd_cmd->status = 0x10007; 366bfbaa952SDave Jiang return 0; 367bfbaa952SDave Jiang } 368bfbaa952SDave Jiang nd_cmd->status = 0; 369bfbaa952SDave Jiang fw->state = FW_STATE_VERIFY; 370bfbaa952SDave Jiang /* set 1 second of time for firmware "update" */ 371bfbaa952SDave Jiang fw->end_time = jiffies + HZ; 372bfbaa952SDave Jiang break; 373bfbaa952SDave Jiang 374bfbaa952SDave Jiang case 1: /* abort */ 375bfbaa952SDave Jiang fw->size_received = 0; 376bfbaa952SDave Jiang /* successfully aborted status */ 377bfbaa952SDave Jiang nd_cmd->status = 0x40007; 378bfbaa952SDave Jiang fw->state = FW_STATE_NEW; 379bfbaa952SDave Jiang dev_dbg(dev, "%s: abort successful\n", __func__); 380bfbaa952SDave Jiang break; 381bfbaa952SDave Jiang 382bfbaa952SDave Jiang default: /* bad control flag */ 383bfbaa952SDave Jiang dev_warn(dev, "%s: unknown control flag: %#x\n", 384bfbaa952SDave Jiang __func__, nd_cmd->ctrl_flags); 385bfbaa952SDave Jiang return -EINVAL; 386bfbaa952SDave Jiang } 387bfbaa952SDave Jiang 388bfbaa952SDave Jiang return 0; 389bfbaa952SDave Jiang } 390bfbaa952SDave Jiang 391bfbaa952SDave Jiang static int nd_intel_test_finish_query(struct nfit_test *t, 392bfbaa952SDave Jiang struct nd_intel_fw_finish_query *nd_cmd, 393bfbaa952SDave Jiang unsigned int buf_len, int idx) 394bfbaa952SDave Jiang { 395bfbaa952SDave Jiang struct device *dev = &t->pdev.dev; 396bfbaa952SDave Jiang struct nfit_test_fw *fw = &t->fw[idx]; 397bfbaa952SDave Jiang 398bfbaa952SDave Jiang dev_dbg(dev, "%s(nfit_test: %p nd_cmd: %p buf_len: %u idx: %d)\n", 399bfbaa952SDave Jiang __func__, t, nd_cmd, buf_len, idx); 400bfbaa952SDave Jiang 401bfbaa952SDave Jiang if (buf_len < sizeof(*nd_cmd)) 402bfbaa952SDave Jiang return -EINVAL; 403bfbaa952SDave Jiang 404bfbaa952SDave Jiang if (nd_cmd->context != fw->context) { 405bfbaa952SDave Jiang dev_dbg(dev, "%s: incorrect context: in: %#x correct: %#x\n", 406bfbaa952SDave Jiang __func__, nd_cmd->context, fw->context); 407bfbaa952SDave Jiang nd_cmd->status = 0x10007; 408bfbaa952SDave Jiang return 0; 409bfbaa952SDave Jiang } 410bfbaa952SDave Jiang 411bfbaa952SDave Jiang dev_dbg(dev, "%s context: %#x\n", __func__, nd_cmd->context); 412bfbaa952SDave Jiang 413bfbaa952SDave Jiang switch (fw->state) { 414bfbaa952SDave Jiang case FW_STATE_NEW: 415bfbaa952SDave Jiang nd_cmd->updated_fw_rev = 0; 416bfbaa952SDave Jiang nd_cmd->status = 0; 417bfbaa952SDave Jiang dev_dbg(dev, "%s: new state\n", __func__); 418bfbaa952SDave Jiang break; 419bfbaa952SDave Jiang 420bfbaa952SDave Jiang case FW_STATE_IN_PROGRESS: 421bfbaa952SDave Jiang /* sequencing error */ 422bfbaa952SDave Jiang nd_cmd->status = 0x40007; 423bfbaa952SDave Jiang nd_cmd->updated_fw_rev = 0; 424bfbaa952SDave Jiang dev_dbg(dev, "%s: sequence error\n", __func__); 425bfbaa952SDave Jiang break; 426bfbaa952SDave Jiang 427bfbaa952SDave Jiang case FW_STATE_VERIFY: 428bfbaa952SDave Jiang if (time_is_after_jiffies64(fw->end_time)) { 429bfbaa952SDave Jiang nd_cmd->updated_fw_rev = 0; 430bfbaa952SDave Jiang nd_cmd->status = 0x20007; 431bfbaa952SDave Jiang dev_dbg(dev, "%s: still verifying\n", __func__); 432bfbaa952SDave Jiang break; 433bfbaa952SDave Jiang } 434bfbaa952SDave Jiang dev_dbg(dev, "%s: transition out verify\n", __func__); 435bfbaa952SDave Jiang fw->state = FW_STATE_UPDATED; 436*916566aeSDan Williams fw->missed_activate = false; 4375518ba4eSDan Williams /* fall through */ 438bfbaa952SDave Jiang case FW_STATE_UPDATED: 439bfbaa952SDave Jiang nd_cmd->status = 0; 440bfbaa952SDave Jiang /* bogus test version */ 441bfbaa952SDave Jiang fw->version = nd_cmd->updated_fw_rev = 442bfbaa952SDave Jiang INTEL_FW_FAKE_VERSION; 443bfbaa952SDave Jiang dev_dbg(dev, "%s: updated\n", __func__); 444bfbaa952SDave Jiang break; 445bfbaa952SDave Jiang 446bfbaa952SDave Jiang default: /* we should never get here */ 447bfbaa952SDave Jiang return -EINVAL; 448bfbaa952SDave Jiang } 449bfbaa952SDave Jiang 450bfbaa952SDave Jiang return 0; 451bfbaa952SDave Jiang } 452bfbaa952SDave Jiang 45339c686b8SVishal Verma static int nfit_test_cmd_get_config_size(struct nd_cmd_get_config_size *nd_cmd, 4546bc75619SDan Williams unsigned int buf_len) 4556bc75619SDan Williams { 4566bc75619SDan Williams if (buf_len < sizeof(*nd_cmd)) 4576bc75619SDan Williams return -EINVAL; 45839c686b8SVishal Verma 4596bc75619SDan Williams nd_cmd->status = 0; 4606bc75619SDan Williams nd_cmd->config_size = LABEL_SIZE; 4616bc75619SDan Williams nd_cmd->max_xfer = SZ_4K; 46239c686b8SVishal Verma 46339c686b8SVishal Verma return 0; 4646bc75619SDan Williams } 46539c686b8SVishal Verma 46639c686b8SVishal Verma static int nfit_test_cmd_get_config_data(struct nd_cmd_get_config_data_hdr 46739c686b8SVishal Verma *nd_cmd, unsigned int buf_len, void *label) 46839c686b8SVishal Verma { 4696bc75619SDan Williams unsigned int len, offset = nd_cmd->in_offset; 47039c686b8SVishal Verma int rc; 4716bc75619SDan Williams 4726bc75619SDan Williams if (buf_len < sizeof(*nd_cmd)) 4736bc75619SDan Williams return -EINVAL; 4746bc75619SDan Williams if (offset >= LABEL_SIZE) 4756bc75619SDan Williams return -EINVAL; 4766bc75619SDan Williams if (nd_cmd->in_length + sizeof(*nd_cmd) > buf_len) 4776bc75619SDan Williams return -EINVAL; 4786bc75619SDan Williams 4796bc75619SDan Williams nd_cmd->status = 0; 4806bc75619SDan Williams len = min(nd_cmd->in_length, LABEL_SIZE - offset); 48139c686b8SVishal Verma memcpy(nd_cmd->out_buf, label + offset, len); 4826bc75619SDan Williams rc = buf_len - sizeof(*nd_cmd) - len; 48339c686b8SVishal Verma 48439c686b8SVishal Verma return rc; 4856bc75619SDan Williams } 48639c686b8SVishal Verma 48739c686b8SVishal Verma static int nfit_test_cmd_set_config_data(struct nd_cmd_set_config_hdr *nd_cmd, 48839c686b8SVishal Verma unsigned int buf_len, void *label) 48939c686b8SVishal Verma { 4906bc75619SDan Williams unsigned int len, offset = nd_cmd->in_offset; 4916bc75619SDan Williams u32 *status; 49239c686b8SVishal Verma int rc; 4936bc75619SDan Williams 4946bc75619SDan Williams if (buf_len < sizeof(*nd_cmd)) 4956bc75619SDan Williams return -EINVAL; 4966bc75619SDan Williams if (offset >= LABEL_SIZE) 4976bc75619SDan Williams return -EINVAL; 4986bc75619SDan Williams if (nd_cmd->in_length + sizeof(*nd_cmd) + 4 > buf_len) 4996bc75619SDan Williams return -EINVAL; 5006bc75619SDan Williams 50139c686b8SVishal Verma status = (void *)nd_cmd + nd_cmd->in_length + sizeof(*nd_cmd); 5026bc75619SDan Williams *status = 0; 5036bc75619SDan Williams len = min(nd_cmd->in_length, LABEL_SIZE - offset); 50439c686b8SVishal Verma memcpy(label + offset, nd_cmd->in_buf, len); 5056bc75619SDan Williams rc = buf_len - sizeof(*nd_cmd) - (len + 4); 50639c686b8SVishal Verma 50739c686b8SVishal Verma return rc; 5086bc75619SDan Williams } 50939c686b8SVishal Verma 510d4f32367SDan Williams #define NFIT_TEST_CLEAR_ERR_UNIT 256 511747ffe11SDan Williams 51239c686b8SVishal Verma static int nfit_test_cmd_ars_cap(struct nd_cmd_ars_cap *nd_cmd, 51339c686b8SVishal Verma unsigned int buf_len) 51439c686b8SVishal Verma { 5159fb1a190SDave Jiang int ars_recs; 5169fb1a190SDave Jiang 51739c686b8SVishal Verma if (buf_len < sizeof(*nd_cmd)) 51839c686b8SVishal Verma return -EINVAL; 51939c686b8SVishal Verma 5209fb1a190SDave Jiang /* for testing, only store up to n records that fit within 4k */ 5219fb1a190SDave Jiang ars_recs = SZ_4K / sizeof(struct nd_ars_record); 5229fb1a190SDave Jiang 523747ffe11SDan Williams nd_cmd->max_ars_out = sizeof(struct nd_cmd_ars_status) 5249fb1a190SDave Jiang + ars_recs * sizeof(struct nd_ars_record); 52539c686b8SVishal Verma nd_cmd->status = (ND_ARS_PERSISTENT | ND_ARS_VOLATILE) << 16; 526d4f32367SDan Williams nd_cmd->clear_err_unit = NFIT_TEST_CLEAR_ERR_UNIT; 52739c686b8SVishal Verma 52839c686b8SVishal Verma return 0; 52939c686b8SVishal Verma } 53039c686b8SVishal Verma 5319fb1a190SDave Jiang static void post_ars_status(struct ars_state *ars_state, 5329fb1a190SDave Jiang struct badrange *badrange, u64 addr, u64 len) 53339c686b8SVishal Verma { 534f471f1a7SDan Williams struct nd_cmd_ars_status *ars_status; 535f471f1a7SDan Williams struct nd_ars_record *ars_record; 5369fb1a190SDave Jiang struct badrange_entry *be; 5379fb1a190SDave Jiang u64 end = addr + len - 1; 5389fb1a190SDave Jiang int i = 0; 539f471f1a7SDan Williams 540f471f1a7SDan Williams ars_state->deadline = jiffies + 1*HZ; 541f471f1a7SDan Williams ars_status = ars_state->ars_status; 542f471f1a7SDan Williams ars_status->status = 0; 543f471f1a7SDan Williams ars_status->address = addr; 544f471f1a7SDan Williams ars_status->length = len; 545f471f1a7SDan Williams ars_status->type = ND_ARS_PERSISTENT; 5469fb1a190SDave Jiang 5479fb1a190SDave Jiang spin_lock(&badrange->lock); 5489fb1a190SDave Jiang list_for_each_entry(be, &badrange->list, list) { 5499fb1a190SDave Jiang u64 be_end = be->start + be->length - 1; 5509fb1a190SDave Jiang u64 rstart, rend; 5519fb1a190SDave Jiang 5529fb1a190SDave Jiang /* skip entries outside the range */ 5539fb1a190SDave Jiang if (be_end < addr || be->start > end) 5549fb1a190SDave Jiang continue; 5559fb1a190SDave Jiang 5569fb1a190SDave Jiang rstart = (be->start < addr) ? addr : be->start; 5579fb1a190SDave Jiang rend = (be_end < end) ? be_end : end; 5589fb1a190SDave Jiang ars_record = &ars_status->records[i]; 559f471f1a7SDan Williams ars_record->handle = 0; 5609fb1a190SDave Jiang ars_record->err_address = rstart; 5619fb1a190SDave Jiang ars_record->length = rend - rstart + 1; 5629fb1a190SDave Jiang i++; 5639fb1a190SDave Jiang } 5649fb1a190SDave Jiang spin_unlock(&badrange->lock); 5659fb1a190SDave Jiang ars_status->num_records = i; 5669fb1a190SDave Jiang ars_status->out_length = sizeof(struct nd_cmd_ars_status) 5679fb1a190SDave Jiang + i * sizeof(struct nd_ars_record); 568f471f1a7SDan Williams } 569f471f1a7SDan Williams 5709fb1a190SDave Jiang static int nfit_test_cmd_ars_start(struct nfit_test *t, 5719fb1a190SDave Jiang struct ars_state *ars_state, 572f471f1a7SDan Williams struct nd_cmd_ars_start *ars_start, unsigned int buf_len, 573f471f1a7SDan Williams int *cmd_rc) 574f471f1a7SDan Williams { 575f471f1a7SDan Williams if (buf_len < sizeof(*ars_start)) 57639c686b8SVishal Verma return -EINVAL; 57739c686b8SVishal Verma 578f471f1a7SDan Williams spin_lock(&ars_state->lock); 579f471f1a7SDan Williams if (time_before(jiffies, ars_state->deadline)) { 580f471f1a7SDan Williams ars_start->status = NFIT_ARS_START_BUSY; 581f471f1a7SDan Williams *cmd_rc = -EBUSY; 582f471f1a7SDan Williams } else { 583f471f1a7SDan Williams ars_start->status = 0; 584f471f1a7SDan Williams ars_start->scrub_time = 1; 5859fb1a190SDave Jiang post_ars_status(ars_state, &t->badrange, ars_start->address, 586f471f1a7SDan Williams ars_start->length); 587f471f1a7SDan Williams *cmd_rc = 0; 588f471f1a7SDan Williams } 589f471f1a7SDan Williams spin_unlock(&ars_state->lock); 59039c686b8SVishal Verma 59139c686b8SVishal Verma return 0; 59239c686b8SVishal Verma } 59339c686b8SVishal Verma 594f471f1a7SDan Williams static int nfit_test_cmd_ars_status(struct ars_state *ars_state, 595f471f1a7SDan Williams struct nd_cmd_ars_status *ars_status, unsigned int buf_len, 596f471f1a7SDan Williams int *cmd_rc) 59739c686b8SVishal Verma { 598f471f1a7SDan Williams if (buf_len < ars_state->ars_status->out_length) 59939c686b8SVishal Verma return -EINVAL; 60039c686b8SVishal Verma 601f471f1a7SDan Williams spin_lock(&ars_state->lock); 602f471f1a7SDan Williams if (time_before(jiffies, ars_state->deadline)) { 603f471f1a7SDan Williams memset(ars_status, 0, buf_len); 604f471f1a7SDan Williams ars_status->status = NFIT_ARS_STATUS_BUSY; 605f471f1a7SDan Williams ars_status->out_length = sizeof(*ars_status); 606f471f1a7SDan Williams *cmd_rc = -EBUSY; 607f471f1a7SDan Williams } else { 608f471f1a7SDan Williams memcpy(ars_status, ars_state->ars_status, 609f471f1a7SDan Williams ars_state->ars_status->out_length); 610f471f1a7SDan Williams *cmd_rc = 0; 611f471f1a7SDan Williams } 612f471f1a7SDan Williams spin_unlock(&ars_state->lock); 61339c686b8SVishal Verma return 0; 61439c686b8SVishal Verma } 61539c686b8SVishal Verma 6165e096ef3SVishal Verma static int nfit_test_cmd_clear_error(struct nfit_test *t, 6175e096ef3SVishal Verma struct nd_cmd_clear_error *clear_err, 618d4f32367SDan Williams unsigned int buf_len, int *cmd_rc) 619d4f32367SDan Williams { 620d4f32367SDan Williams const u64 mask = NFIT_TEST_CLEAR_ERR_UNIT - 1; 621d4f32367SDan Williams if (buf_len < sizeof(*clear_err)) 622d4f32367SDan Williams return -EINVAL; 623d4f32367SDan Williams 624d4f32367SDan Williams if ((clear_err->address & mask) || (clear_err->length & mask)) 625d4f32367SDan Williams return -EINVAL; 626d4f32367SDan Williams 6275e096ef3SVishal Verma badrange_forget(&t->badrange, clear_err->address, clear_err->length); 628d4f32367SDan Williams clear_err->status = 0; 629d4f32367SDan Williams clear_err->cleared = clear_err->length; 630d4f32367SDan Williams *cmd_rc = 0; 631d4f32367SDan Williams return 0; 632d4f32367SDan Williams } 633d4f32367SDan Williams 63410246dc8SYasunori Goto struct region_search_spa { 63510246dc8SYasunori Goto u64 addr; 63610246dc8SYasunori Goto struct nd_region *region; 63710246dc8SYasunori Goto }; 63810246dc8SYasunori Goto 63910246dc8SYasunori Goto static int is_region_device(struct device *dev) 64010246dc8SYasunori Goto { 64110246dc8SYasunori Goto return !strncmp(dev->kobj.name, "region", 6); 64210246dc8SYasunori Goto } 64310246dc8SYasunori Goto 64410246dc8SYasunori Goto static int nfit_test_search_region_spa(struct device *dev, void *data) 64510246dc8SYasunori Goto { 64610246dc8SYasunori Goto struct region_search_spa *ctx = data; 64710246dc8SYasunori Goto struct nd_region *nd_region; 64810246dc8SYasunori Goto resource_size_t ndr_end; 64910246dc8SYasunori Goto 65010246dc8SYasunori Goto if (!is_region_device(dev)) 65110246dc8SYasunori Goto return 0; 65210246dc8SYasunori Goto 65310246dc8SYasunori Goto nd_region = to_nd_region(dev); 65410246dc8SYasunori Goto ndr_end = nd_region->ndr_start + nd_region->ndr_size; 65510246dc8SYasunori Goto 65610246dc8SYasunori Goto if (ctx->addr >= nd_region->ndr_start && ctx->addr < ndr_end) { 65710246dc8SYasunori Goto ctx->region = nd_region; 65810246dc8SYasunori Goto return 1; 65910246dc8SYasunori Goto } 66010246dc8SYasunori Goto 66110246dc8SYasunori Goto return 0; 66210246dc8SYasunori Goto } 66310246dc8SYasunori Goto 66410246dc8SYasunori Goto static int nfit_test_search_spa(struct nvdimm_bus *bus, 66510246dc8SYasunori Goto struct nd_cmd_translate_spa *spa) 66610246dc8SYasunori Goto { 66710246dc8SYasunori Goto int ret; 66810246dc8SYasunori Goto struct nd_region *nd_region = NULL; 66910246dc8SYasunori Goto struct nvdimm *nvdimm = NULL; 67010246dc8SYasunori Goto struct nd_mapping *nd_mapping = NULL; 67110246dc8SYasunori Goto struct region_search_spa ctx = { 67210246dc8SYasunori Goto .addr = spa->spa, 67310246dc8SYasunori Goto .region = NULL, 67410246dc8SYasunori Goto }; 67510246dc8SYasunori Goto u64 dpa; 67610246dc8SYasunori Goto 67710246dc8SYasunori Goto ret = device_for_each_child(&bus->dev, &ctx, 67810246dc8SYasunori Goto nfit_test_search_region_spa); 67910246dc8SYasunori Goto 68010246dc8SYasunori Goto if (!ret) 68110246dc8SYasunori Goto return -ENODEV; 68210246dc8SYasunori Goto 68310246dc8SYasunori Goto nd_region = ctx.region; 68410246dc8SYasunori Goto 68510246dc8SYasunori Goto dpa = ctx.addr - nd_region->ndr_start; 68610246dc8SYasunori Goto 68710246dc8SYasunori Goto /* 68810246dc8SYasunori Goto * last dimm is selected for test 68910246dc8SYasunori Goto */ 69010246dc8SYasunori Goto nd_mapping = &nd_region->mapping[nd_region->ndr_mappings - 1]; 69110246dc8SYasunori Goto nvdimm = nd_mapping->nvdimm; 69210246dc8SYasunori Goto 69310246dc8SYasunori Goto spa->devices[0].nfit_device_handle = handle[nvdimm->id]; 69410246dc8SYasunori Goto spa->num_nvdimms = 1; 69510246dc8SYasunori Goto spa->devices[0].dpa = dpa; 69610246dc8SYasunori Goto 69710246dc8SYasunori Goto return 0; 69810246dc8SYasunori Goto } 69910246dc8SYasunori Goto 70010246dc8SYasunori Goto static int nfit_test_cmd_translate_spa(struct nvdimm_bus *bus, 70110246dc8SYasunori Goto struct nd_cmd_translate_spa *spa, unsigned int buf_len) 70210246dc8SYasunori Goto { 70310246dc8SYasunori Goto if (buf_len < spa->translate_length) 70410246dc8SYasunori Goto return -EINVAL; 70510246dc8SYasunori Goto 70610246dc8SYasunori Goto if (nfit_test_search_spa(bus, spa) < 0 || !spa->num_nvdimms) 70710246dc8SYasunori Goto spa->status = 2; 70810246dc8SYasunori Goto 70910246dc8SYasunori Goto return 0; 71010246dc8SYasunori Goto } 71110246dc8SYasunori Goto 712ed07c433SDan Williams static int nfit_test_cmd_smart(struct nd_intel_smart *smart, unsigned int buf_len, 713ed07c433SDan Williams struct nd_intel_smart *smart_data) 714baa51277SDan Williams { 715baa51277SDan Williams if (buf_len < sizeof(*smart)) 716baa51277SDan Williams return -EINVAL; 717ed07c433SDan Williams memcpy(smart, smart_data, sizeof(*smart)); 718baa51277SDan Williams return 0; 719baa51277SDan Williams } 720baa51277SDan Williams 721cdd77d3eSDan Williams static int nfit_test_cmd_smart_threshold( 722ed07c433SDan Williams struct nd_intel_smart_threshold *out, 723ed07c433SDan Williams unsigned int buf_len, 724ed07c433SDan Williams struct nd_intel_smart_threshold *smart_t) 725baa51277SDan Williams { 726baa51277SDan Williams if (buf_len < sizeof(*smart_t)) 727baa51277SDan Williams return -EINVAL; 728ed07c433SDan Williams memcpy(out, smart_t, sizeof(*smart_t)); 729ed07c433SDan Williams return 0; 730ed07c433SDan Williams } 731ed07c433SDan Williams 732ed07c433SDan Williams static void smart_notify(struct device *bus_dev, 733ed07c433SDan Williams struct device *dimm_dev, struct nd_intel_smart *smart, 734ed07c433SDan Williams struct nd_intel_smart_threshold *thresh) 735ed07c433SDan Williams { 736ed07c433SDan Williams dev_dbg(dimm_dev, "%s: alarm: %#x spares: %d (%d) mtemp: %d (%d) ctemp: %d (%d)\n", 737ed07c433SDan Williams __func__, thresh->alarm_control, thresh->spares, 738ed07c433SDan Williams smart->spares, thresh->media_temperature, 739ed07c433SDan Williams smart->media_temperature, thresh->ctrl_temperature, 740ed07c433SDan Williams smart->ctrl_temperature); 741ed07c433SDan Williams if (((thresh->alarm_control & ND_INTEL_SMART_SPARE_TRIP) 742ed07c433SDan Williams && smart->spares 743ed07c433SDan Williams <= thresh->spares) 744ed07c433SDan Williams || ((thresh->alarm_control & ND_INTEL_SMART_TEMP_TRIP) 745ed07c433SDan Williams && smart->media_temperature 746ed07c433SDan Williams >= thresh->media_temperature) 747ed07c433SDan Williams || ((thresh->alarm_control & ND_INTEL_SMART_CTEMP_TRIP) 748ed07c433SDan Williams && smart->ctrl_temperature 7494cf260fcSVishal Verma >= thresh->ctrl_temperature) 7504cf260fcSVishal Verma || (smart->health != ND_INTEL_SMART_NON_CRITICAL_HEALTH) 7514cf260fcSVishal Verma || (smart->shutdown_state != 0)) { 752ed07c433SDan Williams device_lock(bus_dev); 753ed07c433SDan Williams __acpi_nvdimm_notify(dimm_dev, 0x81); 754ed07c433SDan Williams device_unlock(bus_dev); 755ed07c433SDan Williams } 756ed07c433SDan Williams } 757ed07c433SDan Williams 758ed07c433SDan Williams static int nfit_test_cmd_smart_set_threshold( 759ed07c433SDan Williams struct nd_intel_smart_set_threshold *in, 760ed07c433SDan Williams unsigned int buf_len, 761ed07c433SDan Williams struct nd_intel_smart_threshold *thresh, 762ed07c433SDan Williams struct nd_intel_smart *smart, 763ed07c433SDan Williams struct device *bus_dev, struct device *dimm_dev) 764ed07c433SDan Williams { 765ed07c433SDan Williams unsigned int size; 766ed07c433SDan Williams 767ed07c433SDan Williams size = sizeof(*in) - 4; 768ed07c433SDan Williams if (buf_len < size) 769ed07c433SDan Williams return -EINVAL; 770ed07c433SDan Williams memcpy(thresh->data, in, size); 771ed07c433SDan Williams in->status = 0; 772ed07c433SDan Williams smart_notify(bus_dev, dimm_dev, smart, thresh); 773ed07c433SDan Williams 774baa51277SDan Williams return 0; 775baa51277SDan Williams } 776baa51277SDan Williams 7774cf260fcSVishal Verma static int nfit_test_cmd_smart_inject( 7784cf260fcSVishal Verma struct nd_intel_smart_inject *inj, 7794cf260fcSVishal Verma unsigned int buf_len, 7804cf260fcSVishal Verma struct nd_intel_smart_threshold *thresh, 7814cf260fcSVishal Verma struct nd_intel_smart *smart, 7824cf260fcSVishal Verma struct device *bus_dev, struct device *dimm_dev) 7834cf260fcSVishal Verma { 7844cf260fcSVishal Verma if (buf_len != sizeof(*inj)) 7854cf260fcSVishal Verma return -EINVAL; 7864cf260fcSVishal Verma 787b4d4702fSVishal Verma if (inj->flags & ND_INTEL_SMART_INJECT_MTEMP) { 7884cf260fcSVishal Verma if (inj->mtemp_enable) 7894cf260fcSVishal Verma smart->media_temperature = inj->media_temperature; 790b4d4702fSVishal Verma else 791b4d4702fSVishal Verma smart->media_temperature = smart_def.media_temperature; 792b4d4702fSVishal Verma } 793b4d4702fSVishal Verma if (inj->flags & ND_INTEL_SMART_INJECT_SPARE) { 7944cf260fcSVishal Verma if (inj->spare_enable) 7954cf260fcSVishal Verma smart->spares = inj->spares; 796b4d4702fSVishal Verma else 797b4d4702fSVishal Verma smart->spares = smart_def.spares; 798b4d4702fSVishal Verma } 799b4d4702fSVishal Verma if (inj->flags & ND_INTEL_SMART_INJECT_FATAL) { 8004cf260fcSVishal Verma if (inj->fatal_enable) 8014cf260fcSVishal Verma smart->health = ND_INTEL_SMART_FATAL_HEALTH; 802b4d4702fSVishal Verma else 803b4d4702fSVishal Verma smart->health = ND_INTEL_SMART_NON_CRITICAL_HEALTH; 804b4d4702fSVishal Verma } 805b4d4702fSVishal Verma if (inj->flags & ND_INTEL_SMART_INJECT_SHUTDOWN) { 8064cf260fcSVishal Verma if (inj->unsafe_shutdown_enable) { 8074cf260fcSVishal Verma smart->shutdown_state = 1; 8084cf260fcSVishal Verma smart->shutdown_count++; 809b4d4702fSVishal Verma } else 810b4d4702fSVishal Verma smart->shutdown_state = 0; 8114cf260fcSVishal Verma } 8124cf260fcSVishal Verma inj->status = 0; 8134cf260fcSVishal Verma smart_notify(bus_dev, dimm_dev, smart, thresh); 8144cf260fcSVishal Verma 8154cf260fcSVishal Verma return 0; 8164cf260fcSVishal Verma } 8174cf260fcSVishal Verma 8189fb1a190SDave Jiang static void uc_error_notify(struct work_struct *work) 8199fb1a190SDave Jiang { 8209fb1a190SDave Jiang struct nfit_test *t = container_of(work, typeof(*t), work); 8219fb1a190SDave Jiang 8229fb1a190SDave Jiang __acpi_nfit_notify(&t->pdev.dev, t, NFIT_NOTIFY_UC_MEMORY_ERROR); 8239fb1a190SDave Jiang } 8249fb1a190SDave Jiang 8259fb1a190SDave Jiang static int nfit_test_cmd_ars_error_inject(struct nfit_test *t, 8269fb1a190SDave Jiang struct nd_cmd_ars_err_inj *err_inj, unsigned int buf_len) 8279fb1a190SDave Jiang { 8289fb1a190SDave Jiang int rc; 8299fb1a190SDave Jiang 83041cb3301SVishal Verma if (buf_len != sizeof(*err_inj)) { 8319fb1a190SDave Jiang rc = -EINVAL; 8329fb1a190SDave Jiang goto err; 8339fb1a190SDave Jiang } 8349fb1a190SDave Jiang 8359fb1a190SDave Jiang if (err_inj->err_inj_spa_range_length <= 0) { 8369fb1a190SDave Jiang rc = -EINVAL; 8379fb1a190SDave Jiang goto err; 8389fb1a190SDave Jiang } 8399fb1a190SDave Jiang 8409fb1a190SDave Jiang rc = badrange_add(&t->badrange, err_inj->err_inj_spa_range_base, 8419fb1a190SDave Jiang err_inj->err_inj_spa_range_length); 8429fb1a190SDave Jiang if (rc < 0) 8439fb1a190SDave Jiang goto err; 8449fb1a190SDave Jiang 8459fb1a190SDave Jiang if (err_inj->err_inj_options & (1 << ND_ARS_ERR_INJ_OPT_NOTIFY)) 8469fb1a190SDave Jiang queue_work(nfit_wq, &t->work); 8479fb1a190SDave Jiang 8489fb1a190SDave Jiang err_inj->status = 0; 8499fb1a190SDave Jiang return 0; 8509fb1a190SDave Jiang 8519fb1a190SDave Jiang err: 8529fb1a190SDave Jiang err_inj->status = NFIT_ARS_INJECT_INVALID; 8539fb1a190SDave Jiang return rc; 8549fb1a190SDave Jiang } 8559fb1a190SDave Jiang 8569fb1a190SDave Jiang static int nfit_test_cmd_ars_inject_clear(struct nfit_test *t, 8579fb1a190SDave Jiang struct nd_cmd_ars_err_inj_clr *err_clr, unsigned int buf_len) 8589fb1a190SDave Jiang { 8599fb1a190SDave Jiang int rc; 8609fb1a190SDave Jiang 86141cb3301SVishal Verma if (buf_len != sizeof(*err_clr)) { 8629fb1a190SDave Jiang rc = -EINVAL; 8639fb1a190SDave Jiang goto err; 8649fb1a190SDave Jiang } 8659fb1a190SDave Jiang 8669fb1a190SDave Jiang if (err_clr->err_inj_clr_spa_range_length <= 0) { 8679fb1a190SDave Jiang rc = -EINVAL; 8689fb1a190SDave Jiang goto err; 8699fb1a190SDave Jiang } 8709fb1a190SDave Jiang 8719fb1a190SDave Jiang badrange_forget(&t->badrange, err_clr->err_inj_clr_spa_range_base, 8729fb1a190SDave Jiang err_clr->err_inj_clr_spa_range_length); 8739fb1a190SDave Jiang 8749fb1a190SDave Jiang err_clr->status = 0; 8759fb1a190SDave Jiang return 0; 8769fb1a190SDave Jiang 8779fb1a190SDave Jiang err: 8789fb1a190SDave Jiang err_clr->status = NFIT_ARS_INJECT_INVALID; 8799fb1a190SDave Jiang return rc; 8809fb1a190SDave Jiang } 8819fb1a190SDave Jiang 8829fb1a190SDave Jiang static int nfit_test_cmd_ars_inject_status(struct nfit_test *t, 8839fb1a190SDave Jiang struct nd_cmd_ars_err_inj_stat *err_stat, 8849fb1a190SDave Jiang unsigned int buf_len) 8859fb1a190SDave Jiang { 8869fb1a190SDave Jiang struct badrange_entry *be; 8879fb1a190SDave Jiang int max = SZ_4K / sizeof(struct nd_error_stat_query_record); 8889fb1a190SDave Jiang int i = 0; 8899fb1a190SDave Jiang 8909fb1a190SDave Jiang err_stat->status = 0; 8919fb1a190SDave Jiang spin_lock(&t->badrange.lock); 8929fb1a190SDave Jiang list_for_each_entry(be, &t->badrange.list, list) { 8939fb1a190SDave Jiang err_stat->record[i].err_inj_stat_spa_range_base = be->start; 8949fb1a190SDave Jiang err_stat->record[i].err_inj_stat_spa_range_length = be->length; 8959fb1a190SDave Jiang i++; 8969fb1a190SDave Jiang if (i > max) 8979fb1a190SDave Jiang break; 8989fb1a190SDave Jiang } 8999fb1a190SDave Jiang spin_unlock(&t->badrange.lock); 9009fb1a190SDave Jiang err_stat->inj_err_rec_count = i; 9019fb1a190SDave Jiang 9029fb1a190SDave Jiang return 0; 9039fb1a190SDave Jiang } 9049fb1a190SDave Jiang 905674d8bdeSDave Jiang static int nd_intel_test_cmd_set_lss_status(struct nfit_test *t, 906674d8bdeSDave Jiang struct nd_intel_lss *nd_cmd, unsigned int buf_len) 907674d8bdeSDave Jiang { 908674d8bdeSDave Jiang struct device *dev = &t->pdev.dev; 909674d8bdeSDave Jiang 910674d8bdeSDave Jiang if (buf_len < sizeof(*nd_cmd)) 911674d8bdeSDave Jiang return -EINVAL; 912674d8bdeSDave Jiang 913674d8bdeSDave Jiang switch (nd_cmd->enable) { 914674d8bdeSDave Jiang case 0: 915674d8bdeSDave Jiang nd_cmd->status = 0; 916674d8bdeSDave Jiang dev_dbg(dev, "%s: Latch System Shutdown Status disabled\n", 917674d8bdeSDave Jiang __func__); 918674d8bdeSDave Jiang break; 919674d8bdeSDave Jiang case 1: 920674d8bdeSDave Jiang nd_cmd->status = 0; 921674d8bdeSDave Jiang dev_dbg(dev, "%s: Latch System Shutdown Status enabled\n", 922674d8bdeSDave Jiang __func__); 923674d8bdeSDave Jiang break; 924674d8bdeSDave Jiang default: 925674d8bdeSDave Jiang dev_warn(dev, "Unknown enable value: %#x\n", nd_cmd->enable); 926674d8bdeSDave Jiang nd_cmd->status = 0x3; 927674d8bdeSDave Jiang break; 928674d8bdeSDave Jiang } 929674d8bdeSDave Jiang 930674d8bdeSDave Jiang 931674d8bdeSDave Jiang return 0; 932674d8bdeSDave Jiang } 933674d8bdeSDave Jiang 93439611e83SDan Williams static int override_return_code(int dimm, unsigned int func, int rc) 93539611e83SDan Williams { 93639611e83SDan Williams if ((1 << func) & dimm_fail_cmd_flags[dimm]) { 93739611e83SDan Williams if (dimm_fail_cmd_code[dimm]) 93839611e83SDan Williams return dimm_fail_cmd_code[dimm]; 93939611e83SDan Williams return -EIO; 94039611e83SDan Williams } 94139611e83SDan Williams return rc; 94239611e83SDan Williams } 94339611e83SDan Williams 9443c13e2acSDave Jiang static int nd_intel_test_cmd_security_status(struct nfit_test *t, 9453c13e2acSDave Jiang struct nd_intel_get_security_state *nd_cmd, 9463c13e2acSDave Jiang unsigned int buf_len, int dimm) 9473c13e2acSDave Jiang { 9483c13e2acSDave Jiang struct device *dev = &t->pdev.dev; 9493c13e2acSDave Jiang struct nfit_test_sec *sec = &dimm_sec_info[dimm]; 9503c13e2acSDave Jiang 9513c13e2acSDave Jiang nd_cmd->status = 0; 9523c13e2acSDave Jiang nd_cmd->state = sec->state; 953ecaa4a97SDave Jiang nd_cmd->extended_state = sec->ext_state; 9543c13e2acSDave Jiang dev_dbg(dev, "security state (%#x) returned\n", nd_cmd->state); 9553c13e2acSDave Jiang 9563c13e2acSDave Jiang return 0; 9573c13e2acSDave Jiang } 9583c13e2acSDave Jiang 9593c13e2acSDave Jiang static int nd_intel_test_cmd_unlock_unit(struct nfit_test *t, 9603c13e2acSDave Jiang struct nd_intel_unlock_unit *nd_cmd, 9613c13e2acSDave Jiang unsigned int buf_len, int dimm) 9623c13e2acSDave Jiang { 9633c13e2acSDave Jiang struct device *dev = &t->pdev.dev; 9643c13e2acSDave Jiang struct nfit_test_sec *sec = &dimm_sec_info[dimm]; 9653c13e2acSDave Jiang 9663c13e2acSDave Jiang if (!(sec->state & ND_INTEL_SEC_STATE_LOCKED) || 9673c13e2acSDave Jiang (sec->state & ND_INTEL_SEC_STATE_FROZEN)) { 9683c13e2acSDave Jiang nd_cmd->status = ND_INTEL_STATUS_INVALID_STATE; 9693c13e2acSDave Jiang dev_dbg(dev, "unlock unit: invalid state: %#x\n", 9703c13e2acSDave Jiang sec->state); 9713c13e2acSDave Jiang } else if (memcmp(nd_cmd->passphrase, sec->passphrase, 9723c13e2acSDave Jiang ND_INTEL_PASSPHRASE_SIZE) != 0) { 9733c13e2acSDave Jiang nd_cmd->status = ND_INTEL_STATUS_INVALID_PASS; 9743c13e2acSDave Jiang dev_dbg(dev, "unlock unit: invalid passphrase\n"); 9753c13e2acSDave Jiang } else { 9763c13e2acSDave Jiang nd_cmd->status = 0; 9773c13e2acSDave Jiang sec->state = ND_INTEL_SEC_STATE_ENABLED; 9783c13e2acSDave Jiang dev_dbg(dev, "Unit unlocked\n"); 9793c13e2acSDave Jiang } 9803c13e2acSDave Jiang 9813c13e2acSDave Jiang dev_dbg(dev, "unlocking status returned: %#x\n", nd_cmd->status); 9823c13e2acSDave Jiang return 0; 9833c13e2acSDave Jiang } 9843c13e2acSDave Jiang 9853c13e2acSDave Jiang static int nd_intel_test_cmd_set_pass(struct nfit_test *t, 9863c13e2acSDave Jiang struct nd_intel_set_passphrase *nd_cmd, 9873c13e2acSDave Jiang unsigned int buf_len, int dimm) 9883c13e2acSDave Jiang { 9893c13e2acSDave Jiang struct device *dev = &t->pdev.dev; 9903c13e2acSDave Jiang struct nfit_test_sec *sec = &dimm_sec_info[dimm]; 9913c13e2acSDave Jiang 9923c13e2acSDave Jiang if (sec->state & ND_INTEL_SEC_STATE_FROZEN) { 9933c13e2acSDave Jiang nd_cmd->status = ND_INTEL_STATUS_INVALID_STATE; 9943c13e2acSDave Jiang dev_dbg(dev, "set passphrase: wrong security state\n"); 9953c13e2acSDave Jiang } else if (memcmp(nd_cmd->old_pass, sec->passphrase, 9963c13e2acSDave Jiang ND_INTEL_PASSPHRASE_SIZE) != 0) { 9973c13e2acSDave Jiang nd_cmd->status = ND_INTEL_STATUS_INVALID_PASS; 9983c13e2acSDave Jiang dev_dbg(dev, "set passphrase: wrong passphrase\n"); 9993c13e2acSDave Jiang } else { 10003c13e2acSDave Jiang memcpy(sec->passphrase, nd_cmd->new_pass, 10013c13e2acSDave Jiang ND_INTEL_PASSPHRASE_SIZE); 10023c13e2acSDave Jiang sec->state |= ND_INTEL_SEC_STATE_ENABLED; 10033c13e2acSDave Jiang nd_cmd->status = 0; 10043c13e2acSDave Jiang dev_dbg(dev, "passphrase updated\n"); 10053c13e2acSDave Jiang } 10063c13e2acSDave Jiang 10073c13e2acSDave Jiang return 0; 10083c13e2acSDave Jiang } 10093c13e2acSDave Jiang 10103c13e2acSDave Jiang static int nd_intel_test_cmd_freeze_lock(struct nfit_test *t, 10113c13e2acSDave Jiang struct nd_intel_freeze_lock *nd_cmd, 10123c13e2acSDave Jiang unsigned int buf_len, int dimm) 10133c13e2acSDave Jiang { 10143c13e2acSDave Jiang struct device *dev = &t->pdev.dev; 10153c13e2acSDave Jiang struct nfit_test_sec *sec = &dimm_sec_info[dimm]; 10163c13e2acSDave Jiang 10173c13e2acSDave Jiang if (!(sec->state & ND_INTEL_SEC_STATE_ENABLED)) { 10183c13e2acSDave Jiang nd_cmd->status = ND_INTEL_STATUS_INVALID_STATE; 10193c13e2acSDave Jiang dev_dbg(dev, "freeze lock: wrong security state\n"); 10203c13e2acSDave Jiang } else { 10213c13e2acSDave Jiang sec->state |= ND_INTEL_SEC_STATE_FROZEN; 10223c13e2acSDave Jiang nd_cmd->status = 0; 10233c13e2acSDave Jiang dev_dbg(dev, "security frozen\n"); 10243c13e2acSDave Jiang } 10253c13e2acSDave Jiang 10263c13e2acSDave Jiang return 0; 10273c13e2acSDave Jiang } 10283c13e2acSDave Jiang 10293c13e2acSDave Jiang static int nd_intel_test_cmd_disable_pass(struct nfit_test *t, 10303c13e2acSDave Jiang struct nd_intel_disable_passphrase *nd_cmd, 10313c13e2acSDave Jiang unsigned int buf_len, int dimm) 10323c13e2acSDave Jiang { 10333c13e2acSDave Jiang struct device *dev = &t->pdev.dev; 10343c13e2acSDave Jiang struct nfit_test_sec *sec = &dimm_sec_info[dimm]; 10353c13e2acSDave Jiang 10363c13e2acSDave Jiang if (!(sec->state & ND_INTEL_SEC_STATE_ENABLED) || 10373c13e2acSDave Jiang (sec->state & ND_INTEL_SEC_STATE_FROZEN)) { 10383c13e2acSDave Jiang nd_cmd->status = ND_INTEL_STATUS_INVALID_STATE; 10393c13e2acSDave Jiang dev_dbg(dev, "disable passphrase: wrong security state\n"); 10403c13e2acSDave Jiang } else if (memcmp(nd_cmd->passphrase, sec->passphrase, 10413c13e2acSDave Jiang ND_INTEL_PASSPHRASE_SIZE) != 0) { 10423c13e2acSDave Jiang nd_cmd->status = ND_INTEL_STATUS_INVALID_PASS; 10433c13e2acSDave Jiang dev_dbg(dev, "disable passphrase: wrong passphrase\n"); 10443c13e2acSDave Jiang } else { 10453c13e2acSDave Jiang memset(sec->passphrase, 0, ND_INTEL_PASSPHRASE_SIZE); 10463c13e2acSDave Jiang sec->state = 0; 10473c13e2acSDave Jiang dev_dbg(dev, "disable passphrase: done\n"); 10483c13e2acSDave Jiang } 10493c13e2acSDave Jiang 10503c13e2acSDave Jiang return 0; 10513c13e2acSDave Jiang } 10523c13e2acSDave Jiang 10533c13e2acSDave Jiang static int nd_intel_test_cmd_secure_erase(struct nfit_test *t, 10543c13e2acSDave Jiang struct nd_intel_secure_erase *nd_cmd, 10553c13e2acSDave Jiang unsigned int buf_len, int dimm) 10563c13e2acSDave Jiang { 10573c13e2acSDave Jiang struct device *dev = &t->pdev.dev; 10583c13e2acSDave Jiang struct nfit_test_sec *sec = &dimm_sec_info[dimm]; 10593c13e2acSDave Jiang 1060037c8489SDave Jiang if (sec->state & ND_INTEL_SEC_STATE_FROZEN) { 10613c13e2acSDave Jiang nd_cmd->status = ND_INTEL_STATUS_INVALID_STATE; 10623c13e2acSDave Jiang dev_dbg(dev, "secure erase: wrong security state\n"); 10633c13e2acSDave Jiang } else if (memcmp(nd_cmd->passphrase, sec->passphrase, 10643c13e2acSDave Jiang ND_INTEL_PASSPHRASE_SIZE) != 0) { 10653c13e2acSDave Jiang nd_cmd->status = ND_INTEL_STATUS_INVALID_PASS; 10663c13e2acSDave Jiang dev_dbg(dev, "secure erase: wrong passphrase\n"); 10673c13e2acSDave Jiang } else { 1068037c8489SDave Jiang if (!(sec->state & ND_INTEL_SEC_STATE_ENABLED) 1069037c8489SDave Jiang && (memcmp(nd_cmd->passphrase, zero_key, 1070037c8489SDave Jiang ND_INTEL_PASSPHRASE_SIZE) != 0)) { 1071037c8489SDave Jiang dev_dbg(dev, "invalid zero key\n"); 1072037c8489SDave Jiang return 0; 1073037c8489SDave Jiang } 10743c13e2acSDave Jiang memset(sec->passphrase, 0, ND_INTEL_PASSPHRASE_SIZE); 1075ecaa4a97SDave Jiang memset(sec->master_passphrase, 0, ND_INTEL_PASSPHRASE_SIZE); 10763c13e2acSDave Jiang sec->state = 0; 1077ecaa4a97SDave Jiang sec->ext_state = ND_INTEL_SEC_ESTATE_ENABLED; 10783c13e2acSDave Jiang dev_dbg(dev, "secure erase: done\n"); 10793c13e2acSDave Jiang } 10803c13e2acSDave Jiang 10813c13e2acSDave Jiang return 0; 10823c13e2acSDave Jiang } 10833c13e2acSDave Jiang 1084926f7480SDave Jiang static int nd_intel_test_cmd_overwrite(struct nfit_test *t, 1085926f7480SDave Jiang struct nd_intel_overwrite *nd_cmd, 1086926f7480SDave Jiang unsigned int buf_len, int dimm) 1087926f7480SDave Jiang { 1088926f7480SDave Jiang struct device *dev = &t->pdev.dev; 1089926f7480SDave Jiang struct nfit_test_sec *sec = &dimm_sec_info[dimm]; 1090926f7480SDave Jiang 1091926f7480SDave Jiang if ((sec->state & ND_INTEL_SEC_STATE_ENABLED) && 1092926f7480SDave Jiang memcmp(nd_cmd->passphrase, sec->passphrase, 1093926f7480SDave Jiang ND_INTEL_PASSPHRASE_SIZE) != 0) { 1094926f7480SDave Jiang nd_cmd->status = ND_INTEL_STATUS_INVALID_PASS; 1095926f7480SDave Jiang dev_dbg(dev, "overwrite: wrong passphrase\n"); 1096926f7480SDave Jiang return 0; 1097926f7480SDave Jiang } 1098926f7480SDave Jiang 10992170a0d5SDave Jiang sec->old_state = sec->state; 1100926f7480SDave Jiang sec->state = ND_INTEL_SEC_STATE_OVERWRITE; 1101926f7480SDave Jiang dev_dbg(dev, "overwrite progressing.\n"); 1102926f7480SDave Jiang sec->overwrite_end_time = get_jiffies_64() + 5 * HZ; 1103926f7480SDave Jiang 1104926f7480SDave Jiang return 0; 1105926f7480SDave Jiang } 1106926f7480SDave Jiang 1107926f7480SDave Jiang static int nd_intel_test_cmd_query_overwrite(struct nfit_test *t, 1108926f7480SDave Jiang struct nd_intel_query_overwrite *nd_cmd, 1109926f7480SDave Jiang unsigned int buf_len, int dimm) 1110926f7480SDave Jiang { 1111926f7480SDave Jiang struct device *dev = &t->pdev.dev; 1112926f7480SDave Jiang struct nfit_test_sec *sec = &dimm_sec_info[dimm]; 1113926f7480SDave Jiang 1114926f7480SDave Jiang if (!(sec->state & ND_INTEL_SEC_STATE_OVERWRITE)) { 1115926f7480SDave Jiang nd_cmd->status = ND_INTEL_STATUS_OQUERY_SEQUENCE_ERR; 1116926f7480SDave Jiang return 0; 1117926f7480SDave Jiang } 1118926f7480SDave Jiang 1119926f7480SDave Jiang if (time_is_before_jiffies64(sec->overwrite_end_time)) { 1120926f7480SDave Jiang sec->overwrite_end_time = 0; 11212170a0d5SDave Jiang sec->state = sec->old_state; 11222170a0d5SDave Jiang sec->old_state = 0; 1123ecaa4a97SDave Jiang sec->ext_state = ND_INTEL_SEC_ESTATE_ENABLED; 1124926f7480SDave Jiang dev_dbg(dev, "overwrite is complete\n"); 1125926f7480SDave Jiang } else 1126926f7480SDave Jiang nd_cmd->status = ND_INTEL_STATUS_OQUERY_INPROGRESS; 1127926f7480SDave Jiang return 0; 1128926f7480SDave Jiang } 1129926f7480SDave Jiang 1130ecaa4a97SDave Jiang static int nd_intel_test_cmd_master_set_pass(struct nfit_test *t, 1131ecaa4a97SDave Jiang struct nd_intel_set_master_passphrase *nd_cmd, 1132ecaa4a97SDave Jiang unsigned int buf_len, int dimm) 1133ecaa4a97SDave Jiang { 1134ecaa4a97SDave Jiang struct device *dev = &t->pdev.dev; 1135ecaa4a97SDave Jiang struct nfit_test_sec *sec = &dimm_sec_info[dimm]; 1136ecaa4a97SDave Jiang 1137ecaa4a97SDave Jiang if (!(sec->ext_state & ND_INTEL_SEC_ESTATE_ENABLED)) { 1138ecaa4a97SDave Jiang nd_cmd->status = ND_INTEL_STATUS_NOT_SUPPORTED; 1139ecaa4a97SDave Jiang dev_dbg(dev, "master set passphrase: in wrong state\n"); 1140ecaa4a97SDave Jiang } else if (sec->ext_state & ND_INTEL_SEC_ESTATE_PLIMIT) { 1141ecaa4a97SDave Jiang nd_cmd->status = ND_INTEL_STATUS_INVALID_STATE; 1142ecaa4a97SDave Jiang dev_dbg(dev, "master set passphrase: in wrong security state\n"); 1143ecaa4a97SDave Jiang } else if (memcmp(nd_cmd->old_pass, sec->master_passphrase, 1144ecaa4a97SDave Jiang ND_INTEL_PASSPHRASE_SIZE) != 0) { 1145ecaa4a97SDave Jiang nd_cmd->status = ND_INTEL_STATUS_INVALID_PASS; 1146ecaa4a97SDave Jiang dev_dbg(dev, "master set passphrase: wrong passphrase\n"); 1147ecaa4a97SDave Jiang } else { 1148ecaa4a97SDave Jiang memcpy(sec->master_passphrase, nd_cmd->new_pass, 1149ecaa4a97SDave Jiang ND_INTEL_PASSPHRASE_SIZE); 1150ecaa4a97SDave Jiang sec->ext_state = ND_INTEL_SEC_ESTATE_ENABLED; 1151ecaa4a97SDave Jiang dev_dbg(dev, "master passphrase: updated\n"); 1152ecaa4a97SDave Jiang } 1153ecaa4a97SDave Jiang 1154ecaa4a97SDave Jiang return 0; 1155ecaa4a97SDave Jiang } 1156ecaa4a97SDave Jiang 1157ecaa4a97SDave Jiang static int nd_intel_test_cmd_master_secure_erase(struct nfit_test *t, 1158ecaa4a97SDave Jiang struct nd_intel_master_secure_erase *nd_cmd, 1159ecaa4a97SDave Jiang unsigned int buf_len, int dimm) 1160ecaa4a97SDave Jiang { 1161ecaa4a97SDave Jiang struct device *dev = &t->pdev.dev; 1162ecaa4a97SDave Jiang struct nfit_test_sec *sec = &dimm_sec_info[dimm]; 1163ecaa4a97SDave Jiang 1164ecaa4a97SDave Jiang if (!(sec->ext_state & ND_INTEL_SEC_ESTATE_ENABLED)) { 1165ecaa4a97SDave Jiang nd_cmd->status = ND_INTEL_STATUS_NOT_SUPPORTED; 1166ecaa4a97SDave Jiang dev_dbg(dev, "master secure erase: in wrong state\n"); 1167ecaa4a97SDave Jiang } else if (sec->ext_state & ND_INTEL_SEC_ESTATE_PLIMIT) { 1168ecaa4a97SDave Jiang nd_cmd->status = ND_INTEL_STATUS_INVALID_STATE; 1169ecaa4a97SDave Jiang dev_dbg(dev, "master secure erase: in wrong security state\n"); 1170ecaa4a97SDave Jiang } else if (memcmp(nd_cmd->passphrase, sec->master_passphrase, 1171ecaa4a97SDave Jiang ND_INTEL_PASSPHRASE_SIZE) != 0) { 1172ecaa4a97SDave Jiang nd_cmd->status = ND_INTEL_STATUS_INVALID_PASS; 1173ecaa4a97SDave Jiang dev_dbg(dev, "master secure erase: wrong passphrase\n"); 1174ecaa4a97SDave Jiang } else { 1175ecaa4a97SDave Jiang /* we do not erase master state passphrase ever */ 1176ecaa4a97SDave Jiang sec->ext_state = ND_INTEL_SEC_ESTATE_ENABLED; 1177ecaa4a97SDave Jiang memset(sec->passphrase, 0, ND_INTEL_PASSPHRASE_SIZE); 1178ecaa4a97SDave Jiang sec->state = 0; 1179ecaa4a97SDave Jiang dev_dbg(dev, "master secure erase: done\n"); 1180ecaa4a97SDave Jiang } 1181ecaa4a97SDave Jiang 1182ecaa4a97SDave Jiang return 0; 1183ecaa4a97SDave Jiang } 1184ecaa4a97SDave Jiang 1185*916566aeSDan Williams static unsigned long last_activate; 1186*916566aeSDan Williams 1187*916566aeSDan Williams static int nvdimm_bus_intel_fw_activate_businfo(struct nfit_test *t, 1188*916566aeSDan Williams struct nd_intel_bus_fw_activate_businfo *nd_cmd, 1189*916566aeSDan Williams unsigned int buf_len) 1190*916566aeSDan Williams { 1191*916566aeSDan Williams int i, armed = 0; 1192*916566aeSDan Williams int state; 1193*916566aeSDan Williams u64 tmo; 1194*916566aeSDan Williams 1195*916566aeSDan Williams for (i = 0; i < NUM_DCR; i++) { 1196*916566aeSDan Williams struct nfit_test_fw *fw = &t->fw[i]; 1197*916566aeSDan Williams 1198*916566aeSDan Williams if (fw->armed) 1199*916566aeSDan Williams armed++; 1200*916566aeSDan Williams } 1201*916566aeSDan Williams 1202*916566aeSDan Williams /* 1203*916566aeSDan Williams * Emulate 3 second activation max, and 1 second incremental 1204*916566aeSDan Williams * quiesce time per dimm requiring multiple activates to get all 1205*916566aeSDan Williams * DIMMs updated. 1206*916566aeSDan Williams */ 1207*916566aeSDan Williams if (armed) 1208*916566aeSDan Williams state = ND_INTEL_FWA_ARMED; 1209*916566aeSDan Williams else if (!last_activate || time_after(jiffies, last_activate + 3 * HZ)) 1210*916566aeSDan Williams state = ND_INTEL_FWA_IDLE; 1211*916566aeSDan Williams else 1212*916566aeSDan Williams state = ND_INTEL_FWA_BUSY; 1213*916566aeSDan Williams 1214*916566aeSDan Williams tmo = armed * USEC_PER_SEC; 1215*916566aeSDan Williams *nd_cmd = (struct nd_intel_bus_fw_activate_businfo) { 1216*916566aeSDan Williams .capability = ND_INTEL_BUS_FWA_CAP_FWQUIESCE 1217*916566aeSDan Williams | ND_INTEL_BUS_FWA_CAP_OSQUIESCE 1218*916566aeSDan Williams | ND_INTEL_BUS_FWA_CAP_RESET, 1219*916566aeSDan Williams .state = state, 1220*916566aeSDan Williams .activate_tmo = tmo, 1221*916566aeSDan Williams .cpu_quiesce_tmo = tmo, 1222*916566aeSDan Williams .io_quiesce_tmo = tmo, 1223*916566aeSDan Williams .max_quiesce_tmo = 3 * USEC_PER_SEC, 1224*916566aeSDan Williams }; 1225*916566aeSDan Williams 1226*916566aeSDan Williams return 0; 1227*916566aeSDan Williams } 1228*916566aeSDan Williams 1229*916566aeSDan Williams static int nvdimm_bus_intel_fw_activate(struct nfit_test *t, 1230*916566aeSDan Williams struct nd_intel_bus_fw_activate *nd_cmd, 1231*916566aeSDan Williams unsigned int buf_len) 1232*916566aeSDan Williams { 1233*916566aeSDan Williams struct nd_intel_bus_fw_activate_businfo info; 1234*916566aeSDan Williams u32 status = 0; 1235*916566aeSDan Williams int i; 1236*916566aeSDan Williams 1237*916566aeSDan Williams nvdimm_bus_intel_fw_activate_businfo(t, &info, sizeof(info)); 1238*916566aeSDan Williams if (info.state == ND_INTEL_FWA_BUSY) 1239*916566aeSDan Williams status = ND_INTEL_BUS_FWA_STATUS_BUSY; 1240*916566aeSDan Williams else if (info.activate_tmo > info.max_quiesce_tmo) 1241*916566aeSDan Williams status = ND_INTEL_BUS_FWA_STATUS_TMO; 1242*916566aeSDan Williams else if (info.state == ND_INTEL_FWA_IDLE) 1243*916566aeSDan Williams status = ND_INTEL_BUS_FWA_STATUS_NOARM; 1244*916566aeSDan Williams 1245*916566aeSDan Williams dev_dbg(&t->pdev.dev, "status: %d\n", status); 1246*916566aeSDan Williams nd_cmd->status = status; 1247*916566aeSDan Williams if (status && status != ND_INTEL_BUS_FWA_STATUS_TMO) 1248*916566aeSDan Williams return 0; 1249*916566aeSDan Williams 1250*916566aeSDan Williams last_activate = jiffies; 1251*916566aeSDan Williams for (i = 0; i < NUM_DCR; i++) { 1252*916566aeSDan Williams struct nfit_test_fw *fw = &t->fw[i]; 1253*916566aeSDan Williams 1254*916566aeSDan Williams if (!fw->armed) 1255*916566aeSDan Williams continue; 1256*916566aeSDan Williams if (fw->state != FW_STATE_UPDATED) 1257*916566aeSDan Williams fw->missed_activate = true; 1258*916566aeSDan Williams else 1259*916566aeSDan Williams fw->state = FW_STATE_NEW; 1260*916566aeSDan Williams fw->armed = false; 1261*916566aeSDan Williams fw->last_activate = last_activate; 1262*916566aeSDan Williams } 1263*916566aeSDan Williams 1264*916566aeSDan Williams return 0; 1265*916566aeSDan Williams } 1266*916566aeSDan Williams 1267*916566aeSDan Williams static int nd_intel_test_cmd_fw_activate_dimminfo(struct nfit_test *t, 1268*916566aeSDan Williams struct nd_intel_fw_activate_dimminfo *nd_cmd, 1269*916566aeSDan Williams unsigned int buf_len, int dimm) 1270*916566aeSDan Williams { 1271*916566aeSDan Williams struct nd_intel_bus_fw_activate_businfo info; 1272*916566aeSDan Williams struct nfit_test_fw *fw = &t->fw[dimm]; 1273*916566aeSDan Williams u32 result, state; 1274*916566aeSDan Williams 1275*916566aeSDan Williams nvdimm_bus_intel_fw_activate_businfo(t, &info, sizeof(info)); 1276*916566aeSDan Williams 1277*916566aeSDan Williams if (info.state == ND_INTEL_FWA_BUSY) 1278*916566aeSDan Williams state = ND_INTEL_FWA_BUSY; 1279*916566aeSDan Williams else if (info.state == ND_INTEL_FWA_IDLE) 1280*916566aeSDan Williams state = ND_INTEL_FWA_IDLE; 1281*916566aeSDan Williams else if (fw->armed) 1282*916566aeSDan Williams state = ND_INTEL_FWA_ARMED; 1283*916566aeSDan Williams else 1284*916566aeSDan Williams state = ND_INTEL_FWA_IDLE; 1285*916566aeSDan Williams 1286*916566aeSDan Williams result = ND_INTEL_DIMM_FWA_NONE; 1287*916566aeSDan Williams if (last_activate && fw->last_activate == last_activate && 1288*916566aeSDan Williams state == ND_INTEL_FWA_IDLE) { 1289*916566aeSDan Williams if (fw->missed_activate) 1290*916566aeSDan Williams result = ND_INTEL_DIMM_FWA_NOTSTAGED; 1291*916566aeSDan Williams else 1292*916566aeSDan Williams result = ND_INTEL_DIMM_FWA_SUCCESS; 1293*916566aeSDan Williams } 1294*916566aeSDan Williams 1295*916566aeSDan Williams *nd_cmd = (struct nd_intel_fw_activate_dimminfo) { 1296*916566aeSDan Williams .result = result, 1297*916566aeSDan Williams .state = state, 1298*916566aeSDan Williams }; 1299*916566aeSDan Williams 1300*916566aeSDan Williams return 0; 1301*916566aeSDan Williams } 1302*916566aeSDan Williams 1303*916566aeSDan Williams static int nd_intel_test_cmd_fw_activate_arm(struct nfit_test *t, 1304*916566aeSDan Williams struct nd_intel_fw_activate_arm *nd_cmd, 1305*916566aeSDan Williams unsigned int buf_len, int dimm) 1306*916566aeSDan Williams { 1307*916566aeSDan Williams struct nfit_test_fw *fw = &t->fw[dimm]; 1308*916566aeSDan Williams 1309*916566aeSDan Williams fw->armed = nd_cmd->activate_arm == ND_INTEL_DIMM_FWA_ARM; 1310*916566aeSDan Williams nd_cmd->status = 0; 1311*916566aeSDan Williams return 0; 1312*916566aeSDan Williams } 1313ecaa4a97SDave Jiang 1314bfbaa952SDave Jiang static int get_dimm(struct nfit_mem *nfit_mem, unsigned int func) 1315bfbaa952SDave Jiang { 1316bfbaa952SDave Jiang int i; 1317bfbaa952SDave Jiang 1318bfbaa952SDave Jiang /* lookup per-dimm data */ 1319bfbaa952SDave Jiang for (i = 0; i < ARRAY_SIZE(handle); i++) 1320bfbaa952SDave Jiang if (__to_nfit_memdev(nfit_mem)->device_handle == handle[i]) 1321bfbaa952SDave Jiang break; 1322bfbaa952SDave Jiang if (i >= ARRAY_SIZE(handle)) 1323bfbaa952SDave Jiang return -ENXIO; 1324bfbaa952SDave Jiang return i; 1325bfbaa952SDave Jiang } 1326bfbaa952SDave Jiang 13270d47c4dfSDan Williams static void nfit_ctl_dbg(struct acpi_nfit_desc *acpi_desc, 13280d47c4dfSDan Williams struct nvdimm *nvdimm, unsigned int cmd, void *buf, 13290d47c4dfSDan Williams unsigned int len) 13300d47c4dfSDan Williams { 13310d47c4dfSDan Williams struct nfit_test *t = container_of(acpi_desc, typeof(*t), acpi_desc); 13320d47c4dfSDan Williams unsigned int func = cmd; 13330d47c4dfSDan Williams unsigned int family = 0; 13340d47c4dfSDan Williams 13350d47c4dfSDan Williams if (cmd == ND_CMD_CALL) { 13360d47c4dfSDan Williams struct nd_cmd_pkg *pkg = buf; 13370d47c4dfSDan Williams 13380d47c4dfSDan Williams len = pkg->nd_size_in; 13390d47c4dfSDan Williams family = pkg->nd_family; 13400d47c4dfSDan Williams buf = pkg->nd_payload; 13410d47c4dfSDan Williams func = pkg->nd_command; 13420d47c4dfSDan Williams } 13430d47c4dfSDan Williams dev_dbg(&t->pdev.dev, "%s family: %d cmd: %d: func: %d input length: %d\n", 13440d47c4dfSDan Williams nvdimm ? nvdimm_name(nvdimm) : "bus", family, cmd, func, 13450d47c4dfSDan Williams len); 13460d47c4dfSDan Williams print_hex_dump_debug("nvdimm in ", DUMP_PREFIX_OFFSET, 16, 4, 13470d47c4dfSDan Williams buf, min(len, 256u), true); 13480d47c4dfSDan Williams } 13490d47c4dfSDan Williams 135039c686b8SVishal Verma static int nfit_test_ctl(struct nvdimm_bus_descriptor *nd_desc, 135139c686b8SVishal Verma struct nvdimm *nvdimm, unsigned int cmd, void *buf, 1352aef25338SDan Williams unsigned int buf_len, int *cmd_rc) 135339c686b8SVishal Verma { 135439c686b8SVishal Verma struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc); 135539c686b8SVishal Verma struct nfit_test *t = container_of(acpi_desc, typeof(*t), acpi_desc); 13566634fb06SDan Williams unsigned int func = cmd; 1357f471f1a7SDan Williams int i, rc = 0, __cmd_rc; 1358f471f1a7SDan Williams 1359f471f1a7SDan Williams if (!cmd_rc) 1360f471f1a7SDan Williams cmd_rc = &__cmd_rc; 1361f471f1a7SDan Williams *cmd_rc = 0; 136239c686b8SVishal Verma 13630d47c4dfSDan Williams nfit_ctl_dbg(acpi_desc, nvdimm, cmd, buf, buf_len); 13640d47c4dfSDan Williams 136539c686b8SVishal Verma if (nvdimm) { 136639c686b8SVishal Verma struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm); 1367e3654ecaSDan Williams unsigned long cmd_mask = nvdimm_cmd_mask(nvdimm); 136839c686b8SVishal Verma 13696634fb06SDan Williams if (!nfit_mem) 13706634fb06SDan Williams return -ENOTTY; 13716634fb06SDan Williams 13726634fb06SDan Williams if (cmd == ND_CMD_CALL) { 13736634fb06SDan Williams struct nd_cmd_pkg *call_pkg = buf; 13746634fb06SDan Williams 13756634fb06SDan Williams buf_len = call_pkg->nd_size_in + call_pkg->nd_size_out; 13766634fb06SDan Williams buf = (void *) call_pkg->nd_payload; 13776634fb06SDan Williams func = call_pkg->nd_command; 13786634fb06SDan Williams if (call_pkg->nd_family != nfit_mem->family) 13796634fb06SDan Williams return -ENOTTY; 1380bfbaa952SDave Jiang 1381bfbaa952SDave Jiang i = get_dimm(nfit_mem, func); 1382bfbaa952SDave Jiang if (i < 0) 1383bfbaa952SDave Jiang return i; 138424770658SDan Williams if (i >= NUM_DCR) { 138524770658SDan Williams dev_WARN_ONCE(&t->pdev.dev, 1, 138624770658SDan Williams "ND_CMD_CALL only valid for nfit_test0\n"); 138724770658SDan Williams return -EINVAL; 138824770658SDan Williams } 1389bfbaa952SDave Jiang 1390bfbaa952SDave Jiang switch (func) { 13913c13e2acSDave Jiang case NVDIMM_INTEL_GET_SECURITY_STATE: 13923c13e2acSDave Jiang rc = nd_intel_test_cmd_security_status(t, 13933c13e2acSDave Jiang buf, buf_len, i); 13943c13e2acSDave Jiang break; 13953c13e2acSDave Jiang case NVDIMM_INTEL_UNLOCK_UNIT: 13963c13e2acSDave Jiang rc = nd_intel_test_cmd_unlock_unit(t, 13973c13e2acSDave Jiang buf, buf_len, i); 13983c13e2acSDave Jiang break; 13993c13e2acSDave Jiang case NVDIMM_INTEL_SET_PASSPHRASE: 14003c13e2acSDave Jiang rc = nd_intel_test_cmd_set_pass(t, 14013c13e2acSDave Jiang buf, buf_len, i); 14023c13e2acSDave Jiang break; 14033c13e2acSDave Jiang case NVDIMM_INTEL_DISABLE_PASSPHRASE: 14043c13e2acSDave Jiang rc = nd_intel_test_cmd_disable_pass(t, 14053c13e2acSDave Jiang buf, buf_len, i); 14063c13e2acSDave Jiang break; 14073c13e2acSDave Jiang case NVDIMM_INTEL_FREEZE_LOCK: 14083c13e2acSDave Jiang rc = nd_intel_test_cmd_freeze_lock(t, 14093c13e2acSDave Jiang buf, buf_len, i); 14103c13e2acSDave Jiang break; 14113c13e2acSDave Jiang case NVDIMM_INTEL_SECURE_ERASE: 14123c13e2acSDave Jiang rc = nd_intel_test_cmd_secure_erase(t, 14133c13e2acSDave Jiang buf, buf_len, i); 14143c13e2acSDave Jiang break; 1415926f7480SDave Jiang case NVDIMM_INTEL_OVERWRITE: 1416926f7480SDave Jiang rc = nd_intel_test_cmd_overwrite(t, 141724770658SDan Williams buf, buf_len, i); 1418926f7480SDave Jiang break; 1419926f7480SDave Jiang case NVDIMM_INTEL_QUERY_OVERWRITE: 1420926f7480SDave Jiang rc = nd_intel_test_cmd_query_overwrite(t, 142124770658SDan Williams buf, buf_len, i); 1422926f7480SDave Jiang break; 1423ecaa4a97SDave Jiang case NVDIMM_INTEL_SET_MASTER_PASSPHRASE: 1424ecaa4a97SDave Jiang rc = nd_intel_test_cmd_master_set_pass(t, 1425ecaa4a97SDave Jiang buf, buf_len, i); 1426ecaa4a97SDave Jiang break; 1427ecaa4a97SDave Jiang case NVDIMM_INTEL_MASTER_SECURE_ERASE: 1428ecaa4a97SDave Jiang rc = nd_intel_test_cmd_master_secure_erase(t, 1429ecaa4a97SDave Jiang buf, buf_len, i); 1430ecaa4a97SDave Jiang break; 1431*916566aeSDan Williams case NVDIMM_INTEL_FW_ACTIVATE_DIMMINFO: 1432*916566aeSDan Williams rc = nd_intel_test_cmd_fw_activate_dimminfo( 1433*916566aeSDan Williams t, buf, buf_len, i); 1434*916566aeSDan Williams break; 1435*916566aeSDan Williams case NVDIMM_INTEL_FW_ACTIVATE_ARM: 1436*916566aeSDan Williams rc = nd_intel_test_cmd_fw_activate_arm( 1437*916566aeSDan Williams t, buf, buf_len, i); 1438*916566aeSDan Williams break; 1439674d8bdeSDave Jiang case ND_INTEL_ENABLE_LSS_STATUS: 144039611e83SDan Williams rc = nd_intel_test_cmd_set_lss_status(t, 1441674d8bdeSDave Jiang buf, buf_len); 144239611e83SDan Williams break; 1443bfbaa952SDave Jiang case ND_INTEL_FW_GET_INFO: 144439611e83SDan Williams rc = nd_intel_test_get_fw_info(t, buf, 144524770658SDan Williams buf_len, i); 144639611e83SDan Williams break; 1447bfbaa952SDave Jiang case ND_INTEL_FW_START_UPDATE: 144839611e83SDan Williams rc = nd_intel_test_start_update(t, buf, 144924770658SDan Williams buf_len, i); 145039611e83SDan Williams break; 1451bfbaa952SDave Jiang case ND_INTEL_FW_SEND_DATA: 145239611e83SDan Williams rc = nd_intel_test_send_data(t, buf, 145324770658SDan Williams buf_len, i); 145439611e83SDan Williams break; 1455bfbaa952SDave Jiang case ND_INTEL_FW_FINISH_UPDATE: 145639611e83SDan Williams rc = nd_intel_test_finish_fw(t, buf, 145724770658SDan Williams buf_len, i); 145839611e83SDan Williams break; 1459bfbaa952SDave Jiang case ND_INTEL_FW_FINISH_QUERY: 146039611e83SDan Williams rc = nd_intel_test_finish_query(t, buf, 146124770658SDan Williams buf_len, i); 146239611e83SDan Williams break; 1463bfbaa952SDave Jiang case ND_INTEL_SMART: 146439611e83SDan Williams rc = nfit_test_cmd_smart(buf, buf_len, 146524770658SDan Williams &t->smart[i]); 146639611e83SDan Williams break; 1467bfbaa952SDave Jiang case ND_INTEL_SMART_THRESHOLD: 146839611e83SDan Williams rc = nfit_test_cmd_smart_threshold(buf, 1469bfbaa952SDave Jiang buf_len, 147024770658SDan Williams &t->smart_threshold[i]); 147139611e83SDan Williams break; 1472bfbaa952SDave Jiang case ND_INTEL_SMART_SET_THRESHOLD: 147339611e83SDan Williams rc = nfit_test_cmd_smart_set_threshold(buf, 1474bfbaa952SDave Jiang buf_len, 147524770658SDan Williams &t->smart_threshold[i], 147624770658SDan Williams &t->smart[i], 1477bfbaa952SDave Jiang &t->pdev.dev, t->dimm_dev[i]); 147839611e83SDan Williams break; 14794cf260fcSVishal Verma case ND_INTEL_SMART_INJECT: 148039611e83SDan Williams rc = nfit_test_cmd_smart_inject(buf, 14814cf260fcSVishal Verma buf_len, 148224770658SDan Williams &t->smart_threshold[i], 148324770658SDan Williams &t->smart[i], 14844cf260fcSVishal Verma &t->pdev.dev, t->dimm_dev[i]); 148539611e83SDan Williams break; 1486bfbaa952SDave Jiang default: 1487bfbaa952SDave Jiang return -ENOTTY; 1488bfbaa952SDave Jiang } 148939611e83SDan Williams return override_return_code(i, func, rc); 14906634fb06SDan Williams } 14916634fb06SDan Williams 14926634fb06SDan Williams if (!test_bit(cmd, &cmd_mask) 14936634fb06SDan Williams || !test_bit(func, &nfit_mem->dsm_mask)) 149439c686b8SVishal Verma return -ENOTTY; 149539c686b8SVishal Verma 1496bfbaa952SDave Jiang i = get_dimm(nfit_mem, func); 1497bfbaa952SDave Jiang if (i < 0) 1498bfbaa952SDave Jiang return i; 149973606afdSDan Williams 15006634fb06SDan Williams switch (func) { 150139c686b8SVishal Verma case ND_CMD_GET_CONFIG_SIZE: 150239c686b8SVishal Verma rc = nfit_test_cmd_get_config_size(buf, buf_len); 150339c686b8SVishal Verma break; 150439c686b8SVishal Verma case ND_CMD_GET_CONFIG_DATA: 150539c686b8SVishal Verma rc = nfit_test_cmd_get_config_data(buf, buf_len, 1506dafb1048SDan Williams t->label[i - t->dcr_idx]); 150739c686b8SVishal Verma break; 150839c686b8SVishal Verma case ND_CMD_SET_CONFIG_DATA: 150939c686b8SVishal Verma rc = nfit_test_cmd_set_config_data(buf, buf_len, 1510dafb1048SDan Williams t->label[i - t->dcr_idx]); 151139c686b8SVishal Verma break; 15126bc75619SDan Williams default: 15136bc75619SDan Williams return -ENOTTY; 15146bc75619SDan Williams } 151539611e83SDan Williams return override_return_code(i, func, rc); 151639c686b8SVishal Verma } else { 1517f471f1a7SDan Williams struct ars_state *ars_state = &t->ars_state; 151810246dc8SYasunori Goto struct nd_cmd_pkg *call_pkg = buf; 151910246dc8SYasunori Goto 152010246dc8SYasunori Goto if (!nd_desc) 152110246dc8SYasunori Goto return -ENOTTY; 152210246dc8SYasunori Goto 1523*916566aeSDan Williams if (cmd == ND_CMD_CALL && call_pkg->nd_family 1524*916566aeSDan Williams == NVDIMM_BUS_FAMILY_NFIT) { 152510246dc8SYasunori Goto func = call_pkg->nd_command; 152610246dc8SYasunori Goto buf_len = call_pkg->nd_size_in + call_pkg->nd_size_out; 152710246dc8SYasunori Goto buf = (void *) call_pkg->nd_payload; 152810246dc8SYasunori Goto 152910246dc8SYasunori Goto switch (func) { 153010246dc8SYasunori Goto case NFIT_CMD_TRANSLATE_SPA: 153110246dc8SYasunori Goto rc = nfit_test_cmd_translate_spa( 153210246dc8SYasunori Goto acpi_desc->nvdimm_bus, buf, buf_len); 153310246dc8SYasunori Goto return rc; 15349fb1a190SDave Jiang case NFIT_CMD_ARS_INJECT_SET: 15359fb1a190SDave Jiang rc = nfit_test_cmd_ars_error_inject(t, buf, 15369fb1a190SDave Jiang buf_len); 15379fb1a190SDave Jiang return rc; 15389fb1a190SDave Jiang case NFIT_CMD_ARS_INJECT_CLEAR: 15399fb1a190SDave Jiang rc = nfit_test_cmd_ars_inject_clear(t, buf, 15409fb1a190SDave Jiang buf_len); 15419fb1a190SDave Jiang return rc; 15429fb1a190SDave Jiang case NFIT_CMD_ARS_INJECT_GET: 15439fb1a190SDave Jiang rc = nfit_test_cmd_ars_inject_status(t, buf, 15449fb1a190SDave Jiang buf_len); 15459fb1a190SDave Jiang return rc; 154610246dc8SYasunori Goto default: 154710246dc8SYasunori Goto return -ENOTTY; 154810246dc8SYasunori Goto } 1549*916566aeSDan Williams } else if (cmd == ND_CMD_CALL && call_pkg->nd_family 1550*916566aeSDan Williams == NVDIMM_BUS_FAMILY_INTEL) { 1551*916566aeSDan Williams func = call_pkg->nd_command; 1552*916566aeSDan Williams buf_len = call_pkg->nd_size_in + call_pkg->nd_size_out; 1553*916566aeSDan Williams buf = (void *) call_pkg->nd_payload; 1554*916566aeSDan Williams 1555*916566aeSDan Williams switch (func) { 1556*916566aeSDan Williams case NVDIMM_BUS_INTEL_FW_ACTIVATE_BUSINFO: 1557*916566aeSDan Williams rc = nvdimm_bus_intel_fw_activate_businfo(t, 1558*916566aeSDan Williams buf, buf_len); 1559*916566aeSDan Williams return rc; 1560*916566aeSDan Williams case NVDIMM_BUS_INTEL_FW_ACTIVATE: 1561*916566aeSDan Williams rc = nvdimm_bus_intel_fw_activate(t, buf, 1562*916566aeSDan Williams buf_len); 1563*916566aeSDan Williams return rc; 1564*916566aeSDan Williams default: 1565*916566aeSDan Williams return -ENOTTY; 156610246dc8SYasunori Goto } 1567*916566aeSDan Williams } else if (cmd == ND_CMD_CALL) 1568*916566aeSDan Williams return -ENOTTY; 1569f471f1a7SDan Williams 1570e3654ecaSDan Williams if (!nd_desc || !test_bit(cmd, &nd_desc->cmd_mask)) 157139c686b8SVishal Verma return -ENOTTY; 157239c686b8SVishal Verma 15736634fb06SDan Williams switch (func) { 157439c686b8SVishal Verma case ND_CMD_ARS_CAP: 157539c686b8SVishal Verma rc = nfit_test_cmd_ars_cap(buf, buf_len); 157639c686b8SVishal Verma break; 157739c686b8SVishal Verma case ND_CMD_ARS_START: 15789fb1a190SDave Jiang rc = nfit_test_cmd_ars_start(t, ars_state, buf, 15799fb1a190SDave Jiang buf_len, cmd_rc); 158039c686b8SVishal Verma break; 158139c686b8SVishal Verma case ND_CMD_ARS_STATUS: 1582f471f1a7SDan Williams rc = nfit_test_cmd_ars_status(ars_state, buf, buf_len, 1583f471f1a7SDan Williams cmd_rc); 158439c686b8SVishal Verma break; 1585d4f32367SDan Williams case ND_CMD_CLEAR_ERROR: 15865e096ef3SVishal Verma rc = nfit_test_cmd_clear_error(t, buf, buf_len, cmd_rc); 1587d4f32367SDan Williams break; 158839c686b8SVishal Verma default: 158939c686b8SVishal Verma return -ENOTTY; 159039c686b8SVishal Verma } 159139c686b8SVishal Verma } 15926bc75619SDan Williams 15936bc75619SDan Williams return rc; 15946bc75619SDan Williams } 15956bc75619SDan Williams 15966bc75619SDan Williams static DEFINE_SPINLOCK(nfit_test_lock); 15976bc75619SDan Williams static struct nfit_test *instances[NUM_NFITS]; 15986bc75619SDan Williams 15996bc75619SDan Williams static void release_nfit_res(void *data) 16006bc75619SDan Williams { 16016bc75619SDan Williams struct nfit_test_resource *nfit_res = data; 16026bc75619SDan Williams 16036bc75619SDan Williams spin_lock(&nfit_test_lock); 16046bc75619SDan Williams list_del(&nfit_res->list); 16056bc75619SDan Williams spin_unlock(&nfit_test_lock); 16066bc75619SDan Williams 1607e3f5df76SDan Williams if (resource_size(&nfit_res->res) >= DIMM_SIZE) 1608e3f5df76SDan Williams gen_pool_free(nfit_pool, nfit_res->res.start, 1609e3f5df76SDan Williams resource_size(&nfit_res->res)); 16106bc75619SDan Williams vfree(nfit_res->buf); 16116bc75619SDan Williams kfree(nfit_res); 16126bc75619SDan Williams } 16136bc75619SDan Williams 16146bc75619SDan Williams static void *__test_alloc(struct nfit_test *t, size_t size, dma_addr_t *dma, 16156bc75619SDan Williams void *buf) 16166bc75619SDan Williams { 16176bc75619SDan Williams struct device *dev = &t->pdev.dev; 16186bc75619SDan Williams struct nfit_test_resource *nfit_res = kzalloc(sizeof(*nfit_res), 16196bc75619SDan Williams GFP_KERNEL); 16206bc75619SDan Williams int rc; 16216bc75619SDan Williams 1622e3f5df76SDan Williams if (!buf || !nfit_res || !*dma) 16236bc75619SDan Williams goto err; 16246bc75619SDan Williams rc = devm_add_action(dev, release_nfit_res, nfit_res); 16256bc75619SDan Williams if (rc) 16266bc75619SDan Williams goto err; 16276bc75619SDan Williams INIT_LIST_HEAD(&nfit_res->list); 16286bc75619SDan Williams memset(buf, 0, size); 16296bc75619SDan Williams nfit_res->dev = dev; 16306bc75619SDan Williams nfit_res->buf = buf; 1631bd4cd745SDan Williams nfit_res->res.start = *dma; 1632bd4cd745SDan Williams nfit_res->res.end = *dma + size - 1; 1633bd4cd745SDan Williams nfit_res->res.name = "NFIT"; 1634bd4cd745SDan Williams spin_lock_init(&nfit_res->lock); 1635bd4cd745SDan Williams INIT_LIST_HEAD(&nfit_res->requests); 16366bc75619SDan Williams spin_lock(&nfit_test_lock); 16376bc75619SDan Williams list_add(&nfit_res->list, &t->resources); 16386bc75619SDan Williams spin_unlock(&nfit_test_lock); 16396bc75619SDan Williams 16406bc75619SDan Williams return nfit_res->buf; 16416bc75619SDan Williams err: 1642e3f5df76SDan Williams if (*dma && size >= DIMM_SIZE) 1643e3f5df76SDan Williams gen_pool_free(nfit_pool, *dma, size); 1644ee8520feSDan Williams if (buf) 16456bc75619SDan Williams vfree(buf); 16466bc75619SDan Williams kfree(nfit_res); 16476bc75619SDan Williams return NULL; 16486bc75619SDan Williams } 16496bc75619SDan Williams 16506bc75619SDan Williams static void *test_alloc(struct nfit_test *t, size_t size, dma_addr_t *dma) 16516bc75619SDan Williams { 1652e3f5df76SDan Williams struct genpool_data_align data = { 1653e3f5df76SDan Williams .align = SZ_128M, 1654e3f5df76SDan Williams }; 16556bc75619SDan Williams void *buf = vmalloc(size); 16566bc75619SDan Williams 1657e3f5df76SDan Williams if (size >= DIMM_SIZE) 1658e3f5df76SDan Williams *dma = gen_pool_alloc_algo(nfit_pool, size, 1659e3f5df76SDan Williams gen_pool_first_fit_align, &data); 1660e3f5df76SDan Williams else 16616bc75619SDan Williams *dma = (unsigned long) buf; 16626bc75619SDan Williams return __test_alloc(t, size, dma, buf); 16636bc75619SDan Williams } 16646bc75619SDan Williams 16656bc75619SDan Williams static struct nfit_test_resource *nfit_test_lookup(resource_size_t addr) 16666bc75619SDan Williams { 16676bc75619SDan Williams int i; 16686bc75619SDan Williams 16696bc75619SDan Williams for (i = 0; i < ARRAY_SIZE(instances); i++) { 16706bc75619SDan Williams struct nfit_test_resource *n, *nfit_res = NULL; 16716bc75619SDan Williams struct nfit_test *t = instances[i]; 16726bc75619SDan Williams 16736bc75619SDan Williams if (!t) 16746bc75619SDan Williams continue; 16756bc75619SDan Williams spin_lock(&nfit_test_lock); 16766bc75619SDan Williams list_for_each_entry(n, &t->resources, list) { 1677bd4cd745SDan Williams if (addr >= n->res.start && (addr < n->res.start 1678bd4cd745SDan Williams + resource_size(&n->res))) { 16796bc75619SDan Williams nfit_res = n; 16806bc75619SDan Williams break; 16816bc75619SDan Williams } else if (addr >= (unsigned long) n->buf 16826bc75619SDan Williams && (addr < (unsigned long) n->buf 1683bd4cd745SDan Williams + resource_size(&n->res))) { 16846bc75619SDan Williams nfit_res = n; 16856bc75619SDan Williams break; 16866bc75619SDan Williams } 16876bc75619SDan Williams } 16886bc75619SDan Williams spin_unlock(&nfit_test_lock); 16896bc75619SDan Williams if (nfit_res) 16906bc75619SDan Williams return nfit_res; 16916bc75619SDan Williams } 16926bc75619SDan Williams 16936bc75619SDan Williams return NULL; 16946bc75619SDan Williams } 16956bc75619SDan Williams 1696f471f1a7SDan Williams static int ars_state_init(struct device *dev, struct ars_state *ars_state) 1697f471f1a7SDan Williams { 16989fb1a190SDave Jiang /* for testing, only store up to n records that fit within 4k */ 1699f471f1a7SDan Williams ars_state->ars_status = devm_kzalloc(dev, 17009fb1a190SDave Jiang sizeof(struct nd_cmd_ars_status) + SZ_4K, GFP_KERNEL); 1701f471f1a7SDan Williams if (!ars_state->ars_status) 1702f471f1a7SDan Williams return -ENOMEM; 1703f471f1a7SDan Williams spin_lock_init(&ars_state->lock); 1704f471f1a7SDan Williams return 0; 1705f471f1a7SDan Williams } 1706f471f1a7SDan Williams 1707231bf117SDan Williams static void put_dimms(void *data) 1708231bf117SDan Williams { 1709718fda67SDan Williams struct nfit_test *t = data; 1710231bf117SDan Williams int i; 1711231bf117SDan Williams 1712718fda67SDan Williams for (i = 0; i < t->num_dcr; i++) 1713718fda67SDan Williams if (t->dimm_dev[i]) 1714718fda67SDan Williams device_unregister(t->dimm_dev[i]); 1715231bf117SDan Williams } 1716231bf117SDan Williams 1717231bf117SDan Williams static struct class *nfit_test_dimm; 1718231bf117SDan Williams 171973606afdSDan Williams static int dimm_name_to_id(struct device *dev) 172073606afdSDan Williams { 172173606afdSDan Williams int dimm; 172273606afdSDan Williams 1723718fda67SDan Williams if (sscanf(dev_name(dev), "test_dimm%d", &dimm) != 1) 172473606afdSDan Williams return -ENXIO; 172573606afdSDan Williams return dimm; 172673606afdSDan Williams } 172773606afdSDan Williams 172873606afdSDan Williams static ssize_t handle_show(struct device *dev, struct device_attribute *attr, 172973606afdSDan Williams char *buf) 173073606afdSDan Williams { 173173606afdSDan Williams int dimm = dimm_name_to_id(dev); 173273606afdSDan Williams 173373606afdSDan Williams if (dimm < 0) 173473606afdSDan Williams return dimm; 173573606afdSDan Williams 173619357a68SDan Williams return sprintf(buf, "%#x\n", handle[dimm]); 173773606afdSDan Williams } 173873606afdSDan Williams DEVICE_ATTR_RO(handle); 173973606afdSDan Williams 174073606afdSDan Williams static ssize_t fail_cmd_show(struct device *dev, struct device_attribute *attr, 174173606afdSDan Williams char *buf) 174273606afdSDan Williams { 174373606afdSDan Williams int dimm = dimm_name_to_id(dev); 174473606afdSDan Williams 174573606afdSDan Williams if (dimm < 0) 174673606afdSDan Williams return dimm; 174773606afdSDan Williams 174873606afdSDan Williams return sprintf(buf, "%#lx\n", dimm_fail_cmd_flags[dimm]); 174973606afdSDan Williams } 175073606afdSDan Williams 175173606afdSDan Williams static ssize_t fail_cmd_store(struct device *dev, struct device_attribute *attr, 175273606afdSDan Williams const char *buf, size_t size) 175373606afdSDan Williams { 175473606afdSDan Williams int dimm = dimm_name_to_id(dev); 175573606afdSDan Williams unsigned long val; 175673606afdSDan Williams ssize_t rc; 175773606afdSDan Williams 175873606afdSDan Williams if (dimm < 0) 175973606afdSDan Williams return dimm; 176073606afdSDan Williams 176173606afdSDan Williams rc = kstrtol(buf, 0, &val); 176273606afdSDan Williams if (rc) 176373606afdSDan Williams return rc; 176473606afdSDan Williams 176573606afdSDan Williams dimm_fail_cmd_flags[dimm] = val; 176673606afdSDan Williams return size; 176773606afdSDan Williams } 176873606afdSDan Williams static DEVICE_ATTR_RW(fail_cmd); 176973606afdSDan Williams 177055c72ab6SDan Williams static ssize_t fail_cmd_code_show(struct device *dev, struct device_attribute *attr, 177155c72ab6SDan Williams char *buf) 177255c72ab6SDan Williams { 177355c72ab6SDan Williams int dimm = dimm_name_to_id(dev); 177455c72ab6SDan Williams 177555c72ab6SDan Williams if (dimm < 0) 177655c72ab6SDan Williams return dimm; 177755c72ab6SDan Williams 177855c72ab6SDan Williams return sprintf(buf, "%d\n", dimm_fail_cmd_code[dimm]); 177955c72ab6SDan Williams } 178055c72ab6SDan Williams 178155c72ab6SDan Williams static ssize_t fail_cmd_code_store(struct device *dev, struct device_attribute *attr, 178255c72ab6SDan Williams const char *buf, size_t size) 178355c72ab6SDan Williams { 178455c72ab6SDan Williams int dimm = dimm_name_to_id(dev); 178555c72ab6SDan Williams unsigned long val; 178655c72ab6SDan Williams ssize_t rc; 178755c72ab6SDan Williams 178855c72ab6SDan Williams if (dimm < 0) 178955c72ab6SDan Williams return dimm; 179055c72ab6SDan Williams 179155c72ab6SDan Williams rc = kstrtol(buf, 0, &val); 179255c72ab6SDan Williams if (rc) 179355c72ab6SDan Williams return rc; 179455c72ab6SDan Williams 179555c72ab6SDan Williams dimm_fail_cmd_code[dimm] = val; 179655c72ab6SDan Williams return size; 179755c72ab6SDan Williams } 179855c72ab6SDan Williams static DEVICE_ATTR_RW(fail_cmd_code); 179955c72ab6SDan Williams 18003c13e2acSDave Jiang static ssize_t lock_dimm_store(struct device *dev, 18013c13e2acSDave Jiang struct device_attribute *attr, const char *buf, size_t size) 18023c13e2acSDave Jiang { 18033c13e2acSDave Jiang int dimm = dimm_name_to_id(dev); 18043c13e2acSDave Jiang struct nfit_test_sec *sec = &dimm_sec_info[dimm]; 18053c13e2acSDave Jiang 18063c13e2acSDave Jiang sec->state = ND_INTEL_SEC_STATE_ENABLED | ND_INTEL_SEC_STATE_LOCKED; 18073c13e2acSDave Jiang return size; 18083c13e2acSDave Jiang } 18093c13e2acSDave Jiang static DEVICE_ATTR_WO(lock_dimm); 18103c13e2acSDave Jiang 181173606afdSDan Williams static struct attribute *nfit_test_dimm_attributes[] = { 181273606afdSDan Williams &dev_attr_fail_cmd.attr, 181355c72ab6SDan Williams &dev_attr_fail_cmd_code.attr, 181473606afdSDan Williams &dev_attr_handle.attr, 18153c13e2acSDave Jiang &dev_attr_lock_dimm.attr, 181673606afdSDan Williams NULL, 181773606afdSDan Williams }; 181873606afdSDan Williams 181973606afdSDan Williams static struct attribute_group nfit_test_dimm_attribute_group = { 182073606afdSDan Williams .attrs = nfit_test_dimm_attributes, 182173606afdSDan Williams }; 182273606afdSDan Williams 182373606afdSDan Williams static const struct attribute_group *nfit_test_dimm_attribute_groups[] = { 182473606afdSDan Williams &nfit_test_dimm_attribute_group, 182573606afdSDan Williams NULL, 182673606afdSDan Williams }; 182773606afdSDan Williams 1828718fda67SDan Williams static int nfit_test_dimm_init(struct nfit_test *t) 1829718fda67SDan Williams { 1830718fda67SDan Williams int i; 1831718fda67SDan Williams 1832718fda67SDan Williams if (devm_add_action_or_reset(&t->pdev.dev, put_dimms, t)) 1833718fda67SDan Williams return -ENOMEM; 1834718fda67SDan Williams for (i = 0; i < t->num_dcr; i++) { 1835718fda67SDan Williams t->dimm_dev[i] = device_create_with_groups(nfit_test_dimm, 1836718fda67SDan Williams &t->pdev.dev, 0, NULL, 1837718fda67SDan Williams nfit_test_dimm_attribute_groups, 1838718fda67SDan Williams "test_dimm%d", i + t->dcr_idx); 1839718fda67SDan Williams if (!t->dimm_dev[i]) 1840718fda67SDan Williams return -ENOMEM; 1841718fda67SDan Williams } 1842718fda67SDan Williams return 0; 1843718fda67SDan Williams } 1844718fda67SDan Williams 1845ecaa4a97SDave Jiang static void security_init(struct nfit_test *t) 1846ecaa4a97SDave Jiang { 1847ecaa4a97SDave Jiang int i; 1848ecaa4a97SDave Jiang 1849ecaa4a97SDave Jiang for (i = 0; i < t->num_dcr; i++) { 1850ecaa4a97SDave Jiang struct nfit_test_sec *sec = &dimm_sec_info[i]; 1851ecaa4a97SDave Jiang 1852ecaa4a97SDave Jiang sec->ext_state = ND_INTEL_SEC_ESTATE_ENABLED; 1853ecaa4a97SDave Jiang } 1854ecaa4a97SDave Jiang } 1855ecaa4a97SDave Jiang 1856ed07c433SDan Williams static void smart_init(struct nfit_test *t) 1857ed07c433SDan Williams { 1858ed07c433SDan Williams int i; 1859ed07c433SDan Williams const struct nd_intel_smart_threshold smart_t_data = { 1860ed07c433SDan Williams .alarm_control = ND_INTEL_SMART_SPARE_TRIP 1861ed07c433SDan Williams | ND_INTEL_SMART_TEMP_TRIP, 1862ed07c433SDan Williams .media_temperature = 40 * 16, 1863ed07c433SDan Williams .ctrl_temperature = 30 * 16, 1864ed07c433SDan Williams .spares = 5, 1865ed07c433SDan Williams }; 1866ed07c433SDan Williams 1867ed07c433SDan Williams for (i = 0; i < t->num_dcr; i++) { 1868b4d4702fSVishal Verma memcpy(&t->smart[i], &smart_def, sizeof(smart_def)); 1869ed07c433SDan Williams memcpy(&t->smart_threshold[i], &smart_t_data, 1870ed07c433SDan Williams sizeof(smart_t_data)); 1871ed07c433SDan Williams } 1872ed07c433SDan Williams } 1873ed07c433SDan Williams 18746bc75619SDan Williams static int nfit_test0_alloc(struct nfit_test *t) 18756bc75619SDan Williams { 18766b577c9dSLinda Knippers size_t nfit_size = sizeof(struct acpi_nfit_system_address) * NUM_SPA 18776bc75619SDan Williams + sizeof(struct acpi_nfit_memory_map) * NUM_MEM 18786bc75619SDan Williams + sizeof(struct acpi_nfit_control_region) * NUM_DCR 18793b87356fSDan Williams + offsetof(struct acpi_nfit_control_region, 18803b87356fSDan Williams window_size) * NUM_DCR 18819d27a87eSDan Williams + sizeof(struct acpi_nfit_data_region) * NUM_BDW 188285d3fa02SDan Williams + (sizeof(struct acpi_nfit_flush_address) 1883f81e1d35SDave Jiang + sizeof(u64) * NUM_HINTS) * NUM_DCR 1884f81e1d35SDave Jiang + sizeof(struct acpi_nfit_capabilities); 18856bc75619SDan Williams int i; 18866bc75619SDan Williams 18876bc75619SDan Williams t->nfit_buf = test_alloc(t, nfit_size, &t->nfit_dma); 18886bc75619SDan Williams if (!t->nfit_buf) 18896bc75619SDan Williams return -ENOMEM; 18906bc75619SDan Williams t->nfit_size = nfit_size; 18916bc75619SDan Williams 1892ee8520feSDan Williams t->spa_set[0] = test_alloc(t, SPA0_SIZE, &t->spa_set_dma[0]); 18936bc75619SDan Williams if (!t->spa_set[0]) 18946bc75619SDan Williams return -ENOMEM; 18956bc75619SDan Williams 1896ee8520feSDan Williams t->spa_set[1] = test_alloc(t, SPA1_SIZE, &t->spa_set_dma[1]); 18976bc75619SDan Williams if (!t->spa_set[1]) 18986bc75619SDan Williams return -ENOMEM; 18996bc75619SDan Williams 1900ee8520feSDan Williams t->spa_set[2] = test_alloc(t, SPA0_SIZE, &t->spa_set_dma[2]); 190120985164SVishal Verma if (!t->spa_set[2]) 190220985164SVishal Verma return -ENOMEM; 190320985164SVishal Verma 1904dafb1048SDan Williams for (i = 0; i < t->num_dcr; i++) { 19056bc75619SDan Williams t->dimm[i] = test_alloc(t, DIMM_SIZE, &t->dimm_dma[i]); 19066bc75619SDan Williams if (!t->dimm[i]) 19076bc75619SDan Williams return -ENOMEM; 19086bc75619SDan Williams 19096bc75619SDan Williams t->label[i] = test_alloc(t, LABEL_SIZE, &t->label_dma[i]); 19106bc75619SDan Williams if (!t->label[i]) 19116bc75619SDan Williams return -ENOMEM; 19126bc75619SDan Williams sprintf(t->label[i], "label%d", i); 19139d27a87eSDan Williams 19149d15ce9cSDan Williams t->flush[i] = test_alloc(t, max(PAGE_SIZE, 19159d15ce9cSDan Williams sizeof(u64) * NUM_HINTS), 191685d3fa02SDan Williams &t->flush_dma[i]); 19179d27a87eSDan Williams if (!t->flush[i]) 19189d27a87eSDan Williams return -ENOMEM; 19196bc75619SDan Williams } 19206bc75619SDan Williams 1921dafb1048SDan Williams for (i = 0; i < t->num_dcr; i++) { 19226bc75619SDan Williams t->dcr[i] = test_alloc(t, LABEL_SIZE, &t->dcr_dma[i]); 19236bc75619SDan Williams if (!t->dcr[i]) 19246bc75619SDan Williams return -ENOMEM; 19256bc75619SDan Williams } 19266bc75619SDan Williams 1927c14a868aSDan Williams t->_fit = test_alloc(t, sizeof(union acpi_object **), &t->_fit_dma); 1928c14a868aSDan Williams if (!t->_fit) 1929c14a868aSDan Williams return -ENOMEM; 1930c14a868aSDan Williams 1931718fda67SDan Williams if (nfit_test_dimm_init(t)) 1932231bf117SDan Williams return -ENOMEM; 1933ed07c433SDan Williams smart_init(t); 1934ecaa4a97SDave Jiang security_init(t); 1935f471f1a7SDan Williams return ars_state_init(&t->pdev.dev, &t->ars_state); 19366bc75619SDan Williams } 19376bc75619SDan Williams 19386bc75619SDan Williams static int nfit_test1_alloc(struct nfit_test *t) 19396bc75619SDan Williams { 19407bfe97c7SDan Williams size_t nfit_size = sizeof(struct acpi_nfit_system_address) * 2 1941ac40b675SDan Williams + sizeof(struct acpi_nfit_memory_map) * 2 1942ac40b675SDan Williams + offsetof(struct acpi_nfit_control_region, window_size) * 2; 1943dafb1048SDan Williams int i; 19446bc75619SDan Williams 19456bc75619SDan Williams t->nfit_buf = test_alloc(t, nfit_size, &t->nfit_dma); 19466bc75619SDan Williams if (!t->nfit_buf) 19476bc75619SDan Williams return -ENOMEM; 19486bc75619SDan Williams t->nfit_size = nfit_size; 19496bc75619SDan Williams 1950ee8520feSDan Williams t->spa_set[0] = test_alloc(t, SPA2_SIZE, &t->spa_set_dma[0]); 19516bc75619SDan Williams if (!t->spa_set[0]) 19526bc75619SDan Williams return -ENOMEM; 19536bc75619SDan Williams 1954dafb1048SDan Williams for (i = 0; i < t->num_dcr; i++) { 1955dafb1048SDan Williams t->label[i] = test_alloc(t, LABEL_SIZE, &t->label_dma[i]); 1956dafb1048SDan Williams if (!t->label[i]) 1957dafb1048SDan Williams return -ENOMEM; 1958dafb1048SDan Williams sprintf(t->label[i], "label%d", i); 1959dafb1048SDan Williams } 1960dafb1048SDan Williams 19617bfe97c7SDan Williams t->spa_set[1] = test_alloc(t, SPA_VCD_SIZE, &t->spa_set_dma[1]); 19627bfe97c7SDan Williams if (!t->spa_set[1]) 19637bfe97c7SDan Williams return -ENOMEM; 19647bfe97c7SDan Williams 1965718fda67SDan Williams if (nfit_test_dimm_init(t)) 1966718fda67SDan Williams return -ENOMEM; 1967ed07c433SDan Williams smart_init(t); 1968f471f1a7SDan Williams return ars_state_init(&t->pdev.dev, &t->ars_state); 19696bc75619SDan Williams } 19706bc75619SDan Williams 19715dc68e55SDan Williams static void dcr_common_init(struct acpi_nfit_control_region *dcr) 19725dc68e55SDan Williams { 19735dc68e55SDan Williams dcr->vendor_id = 0xabcd; 19745dc68e55SDan Williams dcr->device_id = 0; 19755dc68e55SDan Williams dcr->revision_id = 1; 19765dc68e55SDan Williams dcr->valid_fields = 1; 19775dc68e55SDan Williams dcr->manufacturing_location = 0xa; 19785dc68e55SDan Williams dcr->manufacturing_date = cpu_to_be16(2016); 19795dc68e55SDan Williams } 19805dc68e55SDan Williams 19816bc75619SDan Williams static void nfit_test0_setup(struct nfit_test *t) 19826bc75619SDan Williams { 198385d3fa02SDan Williams const int flush_hint_size = sizeof(struct acpi_nfit_flush_address) 198485d3fa02SDan Williams + (sizeof(u64) * NUM_HINTS); 19856bc75619SDan Williams struct acpi_nfit_desc *acpi_desc; 19866bc75619SDan Williams struct acpi_nfit_memory_map *memdev; 19876bc75619SDan Williams void *nfit_buf = t->nfit_buf; 19886bc75619SDan Williams struct acpi_nfit_system_address *spa; 19896bc75619SDan Williams struct acpi_nfit_control_region *dcr; 19906bc75619SDan Williams struct acpi_nfit_data_region *bdw; 19919d27a87eSDan Williams struct acpi_nfit_flush_address *flush; 1992f81e1d35SDave Jiang struct acpi_nfit_capabilities *pcap; 1993d7d8464dSRoss Zwisler unsigned int offset = 0, i; 1994*916566aeSDan Williams unsigned long *acpi_mask; 19956bc75619SDan Williams 19966bc75619SDan Williams /* 19976bc75619SDan Williams * spa0 (interleave first half of dimm0 and dimm1, note storage 19986bc75619SDan Williams * does not actually alias the related block-data-window 19996bc75619SDan Williams * regions) 20006bc75619SDan Williams */ 20016b577c9dSLinda Knippers spa = nfit_buf; 20026bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 20036bc75619SDan Williams spa->header.length = sizeof(*spa); 20046bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 20056bc75619SDan Williams spa->range_index = 0+1; 20066bc75619SDan Williams spa->address = t->spa_set_dma[0]; 20076bc75619SDan Williams spa->length = SPA0_SIZE; 2008d7d8464dSRoss Zwisler offset += spa->header.length; 20096bc75619SDan Williams 20106bc75619SDan Williams /* 20116bc75619SDan Williams * spa1 (interleave last half of the 4 DIMMS, note storage 20126bc75619SDan Williams * does not actually alias the related block-data-window 20136bc75619SDan Williams * regions) 20146bc75619SDan Williams */ 2015d7d8464dSRoss Zwisler spa = nfit_buf + offset; 20166bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 20176bc75619SDan Williams spa->header.length = sizeof(*spa); 20186bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 20196bc75619SDan Williams spa->range_index = 1+1; 20206bc75619SDan Williams spa->address = t->spa_set_dma[1]; 20216bc75619SDan Williams spa->length = SPA1_SIZE; 2022d7d8464dSRoss Zwisler offset += spa->header.length; 20236bc75619SDan Williams 20246bc75619SDan Williams /* spa2 (dcr0) dimm0 */ 2025d7d8464dSRoss Zwisler spa = nfit_buf + offset; 20266bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 20276bc75619SDan Williams spa->header.length = sizeof(*spa); 20286bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 20296bc75619SDan Williams spa->range_index = 2+1; 20306bc75619SDan Williams spa->address = t->dcr_dma[0]; 20316bc75619SDan Williams spa->length = DCR_SIZE; 2032d7d8464dSRoss Zwisler offset += spa->header.length; 20336bc75619SDan Williams 20346bc75619SDan Williams /* spa3 (dcr1) dimm1 */ 2035d7d8464dSRoss Zwisler spa = nfit_buf + offset; 20366bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 20376bc75619SDan Williams spa->header.length = sizeof(*spa); 20386bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 20396bc75619SDan Williams spa->range_index = 3+1; 20406bc75619SDan Williams spa->address = t->dcr_dma[1]; 20416bc75619SDan Williams spa->length = DCR_SIZE; 2042d7d8464dSRoss Zwisler offset += spa->header.length; 20436bc75619SDan Williams 20446bc75619SDan Williams /* spa4 (dcr2) dimm2 */ 2045d7d8464dSRoss Zwisler spa = nfit_buf + offset; 20466bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 20476bc75619SDan Williams spa->header.length = sizeof(*spa); 20486bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 20496bc75619SDan Williams spa->range_index = 4+1; 20506bc75619SDan Williams spa->address = t->dcr_dma[2]; 20516bc75619SDan Williams spa->length = DCR_SIZE; 2052d7d8464dSRoss Zwisler offset += spa->header.length; 20536bc75619SDan Williams 20546bc75619SDan Williams /* spa5 (dcr3) dimm3 */ 2055d7d8464dSRoss Zwisler spa = nfit_buf + offset; 20566bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 20576bc75619SDan Williams spa->header.length = sizeof(*spa); 20586bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 20596bc75619SDan Williams spa->range_index = 5+1; 20606bc75619SDan Williams spa->address = t->dcr_dma[3]; 20616bc75619SDan Williams spa->length = DCR_SIZE; 2062d7d8464dSRoss Zwisler offset += spa->header.length; 20636bc75619SDan Williams 20646bc75619SDan Williams /* spa6 (bdw for dcr0) dimm0 */ 2065d7d8464dSRoss Zwisler spa = nfit_buf + offset; 20666bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 20676bc75619SDan Williams spa->header.length = sizeof(*spa); 20686bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 20696bc75619SDan Williams spa->range_index = 6+1; 20706bc75619SDan Williams spa->address = t->dimm_dma[0]; 20716bc75619SDan Williams spa->length = DIMM_SIZE; 2072d7d8464dSRoss Zwisler offset += spa->header.length; 20736bc75619SDan Williams 20746bc75619SDan Williams /* spa7 (bdw for dcr1) dimm1 */ 2075d7d8464dSRoss Zwisler spa = nfit_buf + offset; 20766bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 20776bc75619SDan Williams spa->header.length = sizeof(*spa); 20786bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 20796bc75619SDan Williams spa->range_index = 7+1; 20806bc75619SDan Williams spa->address = t->dimm_dma[1]; 20816bc75619SDan Williams spa->length = DIMM_SIZE; 2082d7d8464dSRoss Zwisler offset += spa->header.length; 20836bc75619SDan Williams 20846bc75619SDan Williams /* spa8 (bdw for dcr2) dimm2 */ 2085d7d8464dSRoss Zwisler spa = nfit_buf + offset; 20866bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 20876bc75619SDan Williams spa->header.length = sizeof(*spa); 20886bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 20896bc75619SDan Williams spa->range_index = 8+1; 20906bc75619SDan Williams spa->address = t->dimm_dma[2]; 20916bc75619SDan Williams spa->length = DIMM_SIZE; 2092d7d8464dSRoss Zwisler offset += spa->header.length; 20936bc75619SDan Williams 20946bc75619SDan Williams /* spa9 (bdw for dcr3) dimm3 */ 2095d7d8464dSRoss Zwisler spa = nfit_buf + offset; 20966bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 20976bc75619SDan Williams spa->header.length = sizeof(*spa); 20986bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 20996bc75619SDan Williams spa->range_index = 9+1; 21006bc75619SDan Williams spa->address = t->dimm_dma[3]; 21016bc75619SDan Williams spa->length = DIMM_SIZE; 2102d7d8464dSRoss Zwisler offset += spa->header.length; 21036bc75619SDan Williams 21046bc75619SDan Williams /* mem-region0 (spa0, dimm0) */ 21056bc75619SDan Williams memdev = nfit_buf + offset; 21066bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 21076bc75619SDan Williams memdev->header.length = sizeof(*memdev); 21086bc75619SDan Williams memdev->device_handle = handle[0]; 21096bc75619SDan Williams memdev->physical_id = 0; 21106bc75619SDan Williams memdev->region_id = 0; 21116bc75619SDan Williams memdev->range_index = 0+1; 21123b87356fSDan Williams memdev->region_index = 4+1; 21136bc75619SDan Williams memdev->region_size = SPA0_SIZE/2; 2114df06a2d5SDan Williams memdev->region_offset = 1; 21156bc75619SDan Williams memdev->address = 0; 21166bc75619SDan Williams memdev->interleave_index = 0; 21176bc75619SDan Williams memdev->interleave_ways = 2; 2118d7d8464dSRoss Zwisler offset += memdev->header.length; 21196bc75619SDan Williams 21206bc75619SDan Williams /* mem-region1 (spa0, dimm1) */ 2121d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 21226bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 21236bc75619SDan Williams memdev->header.length = sizeof(*memdev); 21246bc75619SDan Williams memdev->device_handle = handle[1]; 21256bc75619SDan Williams memdev->physical_id = 1; 21266bc75619SDan Williams memdev->region_id = 0; 21276bc75619SDan Williams memdev->range_index = 0+1; 21283b87356fSDan Williams memdev->region_index = 5+1; 21296bc75619SDan Williams memdev->region_size = SPA0_SIZE/2; 2130df06a2d5SDan Williams memdev->region_offset = (1 << 8); 21316bc75619SDan Williams memdev->address = 0; 21326bc75619SDan Williams memdev->interleave_index = 0; 21336bc75619SDan Williams memdev->interleave_ways = 2; 2134ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED; 2135d7d8464dSRoss Zwisler offset += memdev->header.length; 21366bc75619SDan Williams 21376bc75619SDan Williams /* mem-region2 (spa1, dimm0) */ 2138d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 21396bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 21406bc75619SDan Williams memdev->header.length = sizeof(*memdev); 21416bc75619SDan Williams memdev->device_handle = handle[0]; 21426bc75619SDan Williams memdev->physical_id = 0; 21436bc75619SDan Williams memdev->region_id = 1; 21446bc75619SDan Williams memdev->range_index = 1+1; 21453b87356fSDan Williams memdev->region_index = 4+1; 21466bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 2147df06a2d5SDan Williams memdev->region_offset = (1 << 16); 21486bc75619SDan Williams memdev->address = SPA0_SIZE/2; 21496bc75619SDan Williams memdev->interleave_index = 0; 21506bc75619SDan Williams memdev->interleave_ways = 4; 2151ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED; 2152d7d8464dSRoss Zwisler offset += memdev->header.length; 21536bc75619SDan Williams 21546bc75619SDan Williams /* mem-region3 (spa1, dimm1) */ 2155d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 21566bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 21576bc75619SDan Williams memdev->header.length = sizeof(*memdev); 21586bc75619SDan Williams memdev->device_handle = handle[1]; 21596bc75619SDan Williams memdev->physical_id = 1; 21606bc75619SDan Williams memdev->region_id = 1; 21616bc75619SDan Williams memdev->range_index = 1+1; 21623b87356fSDan Williams memdev->region_index = 5+1; 21636bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 2164df06a2d5SDan Williams memdev->region_offset = (1 << 24); 21656bc75619SDan Williams memdev->address = SPA0_SIZE/2; 21666bc75619SDan Williams memdev->interleave_index = 0; 21676bc75619SDan Williams memdev->interleave_ways = 4; 2168d7d8464dSRoss Zwisler offset += memdev->header.length; 21696bc75619SDan Williams 21706bc75619SDan Williams /* mem-region4 (spa1, dimm2) */ 2171d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 21726bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 21736bc75619SDan Williams memdev->header.length = sizeof(*memdev); 21746bc75619SDan Williams memdev->device_handle = handle[2]; 21756bc75619SDan Williams memdev->physical_id = 2; 21766bc75619SDan Williams memdev->region_id = 0; 21776bc75619SDan Williams memdev->range_index = 1+1; 21783b87356fSDan Williams memdev->region_index = 6+1; 21796bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 2180df06a2d5SDan Williams memdev->region_offset = (1ULL << 32); 21816bc75619SDan Williams memdev->address = SPA0_SIZE/2; 21826bc75619SDan Williams memdev->interleave_index = 0; 21836bc75619SDan Williams memdev->interleave_ways = 4; 2184ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED; 2185d7d8464dSRoss Zwisler offset += memdev->header.length; 21866bc75619SDan Williams 21876bc75619SDan Williams /* mem-region5 (spa1, dimm3) */ 2188d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 21896bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 21906bc75619SDan Williams memdev->header.length = sizeof(*memdev); 21916bc75619SDan Williams memdev->device_handle = handle[3]; 21926bc75619SDan Williams memdev->physical_id = 3; 21936bc75619SDan Williams memdev->region_id = 0; 21946bc75619SDan Williams memdev->range_index = 1+1; 21953b87356fSDan Williams memdev->region_index = 7+1; 21966bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 2197df06a2d5SDan Williams memdev->region_offset = (1ULL << 40); 21986bc75619SDan Williams memdev->address = SPA0_SIZE/2; 21996bc75619SDan Williams memdev->interleave_index = 0; 22006bc75619SDan Williams memdev->interleave_ways = 4; 2201d7d8464dSRoss Zwisler offset += memdev->header.length; 22026bc75619SDan Williams 22036bc75619SDan Williams /* mem-region6 (spa/dcr0, dimm0) */ 2204d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 22056bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 22066bc75619SDan Williams memdev->header.length = sizeof(*memdev); 22076bc75619SDan Williams memdev->device_handle = handle[0]; 22086bc75619SDan Williams memdev->physical_id = 0; 22096bc75619SDan Williams memdev->region_id = 0; 22106bc75619SDan Williams memdev->range_index = 2+1; 22116bc75619SDan Williams memdev->region_index = 0+1; 22126bc75619SDan Williams memdev->region_size = 0; 22136bc75619SDan Williams memdev->region_offset = 0; 22146bc75619SDan Williams memdev->address = 0; 22156bc75619SDan Williams memdev->interleave_index = 0; 22166bc75619SDan Williams memdev->interleave_ways = 1; 2217d7d8464dSRoss Zwisler offset += memdev->header.length; 22186bc75619SDan Williams 22196bc75619SDan Williams /* mem-region7 (spa/dcr1, dimm1) */ 2220d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 22216bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 22226bc75619SDan Williams memdev->header.length = sizeof(*memdev); 22236bc75619SDan Williams memdev->device_handle = handle[1]; 22246bc75619SDan Williams memdev->physical_id = 1; 22256bc75619SDan Williams memdev->region_id = 0; 22266bc75619SDan Williams memdev->range_index = 3+1; 22276bc75619SDan Williams memdev->region_index = 1+1; 22286bc75619SDan Williams memdev->region_size = 0; 22296bc75619SDan Williams memdev->region_offset = 0; 22306bc75619SDan Williams memdev->address = 0; 22316bc75619SDan Williams memdev->interleave_index = 0; 22326bc75619SDan Williams memdev->interleave_ways = 1; 2233d7d8464dSRoss Zwisler offset += memdev->header.length; 22346bc75619SDan Williams 22356bc75619SDan Williams /* mem-region8 (spa/dcr2, dimm2) */ 2236d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 22376bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 22386bc75619SDan Williams memdev->header.length = sizeof(*memdev); 22396bc75619SDan Williams memdev->device_handle = handle[2]; 22406bc75619SDan Williams memdev->physical_id = 2; 22416bc75619SDan Williams memdev->region_id = 0; 22426bc75619SDan Williams memdev->range_index = 4+1; 22436bc75619SDan Williams memdev->region_index = 2+1; 22446bc75619SDan Williams memdev->region_size = 0; 22456bc75619SDan Williams memdev->region_offset = 0; 22466bc75619SDan Williams memdev->address = 0; 22476bc75619SDan Williams memdev->interleave_index = 0; 22486bc75619SDan Williams memdev->interleave_ways = 1; 2249d7d8464dSRoss Zwisler offset += memdev->header.length; 22506bc75619SDan Williams 22516bc75619SDan Williams /* mem-region9 (spa/dcr3, dimm3) */ 2252d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 22536bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 22546bc75619SDan Williams memdev->header.length = sizeof(*memdev); 22556bc75619SDan Williams memdev->device_handle = handle[3]; 22566bc75619SDan Williams memdev->physical_id = 3; 22576bc75619SDan Williams memdev->region_id = 0; 22586bc75619SDan Williams memdev->range_index = 5+1; 22596bc75619SDan Williams memdev->region_index = 3+1; 22606bc75619SDan Williams memdev->region_size = 0; 22616bc75619SDan Williams memdev->region_offset = 0; 22626bc75619SDan Williams memdev->address = 0; 22636bc75619SDan Williams memdev->interleave_index = 0; 22646bc75619SDan Williams memdev->interleave_ways = 1; 2265d7d8464dSRoss Zwisler offset += memdev->header.length; 22666bc75619SDan Williams 22676bc75619SDan Williams /* mem-region10 (spa/bdw0, dimm0) */ 2268d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 22696bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 22706bc75619SDan Williams memdev->header.length = sizeof(*memdev); 22716bc75619SDan Williams memdev->device_handle = handle[0]; 22726bc75619SDan Williams memdev->physical_id = 0; 22736bc75619SDan Williams memdev->region_id = 0; 22746bc75619SDan Williams memdev->range_index = 6+1; 22756bc75619SDan Williams memdev->region_index = 0+1; 22766bc75619SDan Williams memdev->region_size = 0; 22776bc75619SDan Williams memdev->region_offset = 0; 22786bc75619SDan Williams memdev->address = 0; 22796bc75619SDan Williams memdev->interleave_index = 0; 22806bc75619SDan Williams memdev->interleave_ways = 1; 2281d7d8464dSRoss Zwisler offset += memdev->header.length; 22826bc75619SDan Williams 22836bc75619SDan Williams /* mem-region11 (spa/bdw1, dimm1) */ 2284d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 22856bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 22866bc75619SDan Williams memdev->header.length = sizeof(*memdev); 22876bc75619SDan Williams memdev->device_handle = handle[1]; 22886bc75619SDan Williams memdev->physical_id = 1; 22896bc75619SDan Williams memdev->region_id = 0; 22906bc75619SDan Williams memdev->range_index = 7+1; 22916bc75619SDan Williams memdev->region_index = 1+1; 22926bc75619SDan Williams memdev->region_size = 0; 22936bc75619SDan Williams memdev->region_offset = 0; 22946bc75619SDan Williams memdev->address = 0; 22956bc75619SDan Williams memdev->interleave_index = 0; 22966bc75619SDan Williams memdev->interleave_ways = 1; 2297d7d8464dSRoss Zwisler offset += memdev->header.length; 22986bc75619SDan Williams 22996bc75619SDan Williams /* mem-region12 (spa/bdw2, dimm2) */ 2300d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 23016bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 23026bc75619SDan Williams memdev->header.length = sizeof(*memdev); 23036bc75619SDan Williams memdev->device_handle = handle[2]; 23046bc75619SDan Williams memdev->physical_id = 2; 23056bc75619SDan Williams memdev->region_id = 0; 23066bc75619SDan Williams memdev->range_index = 8+1; 23076bc75619SDan Williams memdev->region_index = 2+1; 23086bc75619SDan Williams memdev->region_size = 0; 23096bc75619SDan Williams memdev->region_offset = 0; 23106bc75619SDan Williams memdev->address = 0; 23116bc75619SDan Williams memdev->interleave_index = 0; 23126bc75619SDan Williams memdev->interleave_ways = 1; 2313d7d8464dSRoss Zwisler offset += memdev->header.length; 23146bc75619SDan Williams 23156bc75619SDan Williams /* mem-region13 (spa/dcr3, dimm3) */ 2316d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 23176bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 23186bc75619SDan Williams memdev->header.length = sizeof(*memdev); 23196bc75619SDan Williams memdev->device_handle = handle[3]; 23206bc75619SDan Williams memdev->physical_id = 3; 23216bc75619SDan Williams memdev->region_id = 0; 23226bc75619SDan Williams memdev->range_index = 9+1; 23236bc75619SDan Williams memdev->region_index = 3+1; 23246bc75619SDan Williams memdev->region_size = 0; 23256bc75619SDan Williams memdev->region_offset = 0; 23266bc75619SDan Williams memdev->address = 0; 23276bc75619SDan Williams memdev->interleave_index = 0; 23286bc75619SDan Williams memdev->interleave_ways = 1; 2329ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED; 2330d7d8464dSRoss Zwisler offset += memdev->header.length; 23316bc75619SDan Williams 23323b87356fSDan Williams /* dcr-descriptor0: blk */ 23336bc75619SDan Williams dcr = nfit_buf + offset; 23346bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 2335d7d8464dSRoss Zwisler dcr->header.length = sizeof(*dcr); 23366bc75619SDan Williams dcr->region_index = 0+1; 23375dc68e55SDan Williams dcr_common_init(dcr); 23386bc75619SDan Williams dcr->serial_number = ~handle[0]; 2339be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 23406bc75619SDan Williams dcr->windows = 1; 23416bc75619SDan Williams dcr->window_size = DCR_SIZE; 23426bc75619SDan Williams dcr->command_offset = 0; 23436bc75619SDan Williams dcr->command_size = 8; 23446bc75619SDan Williams dcr->status_offset = 8; 23456bc75619SDan Williams dcr->status_size = 4; 2346d7d8464dSRoss Zwisler offset += dcr->header.length; 23476bc75619SDan Williams 23483b87356fSDan Williams /* dcr-descriptor1: blk */ 2349d7d8464dSRoss Zwisler dcr = nfit_buf + offset; 23506bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 2351d7d8464dSRoss Zwisler dcr->header.length = sizeof(*dcr); 23526bc75619SDan Williams dcr->region_index = 1+1; 23535dc68e55SDan Williams dcr_common_init(dcr); 23546bc75619SDan Williams dcr->serial_number = ~handle[1]; 2355be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 23566bc75619SDan Williams dcr->windows = 1; 23576bc75619SDan Williams dcr->window_size = DCR_SIZE; 23586bc75619SDan Williams dcr->command_offset = 0; 23596bc75619SDan Williams dcr->command_size = 8; 23606bc75619SDan Williams dcr->status_offset = 8; 23616bc75619SDan Williams dcr->status_size = 4; 2362d7d8464dSRoss Zwisler offset += dcr->header.length; 23636bc75619SDan Williams 23643b87356fSDan Williams /* dcr-descriptor2: blk */ 2365d7d8464dSRoss Zwisler dcr = nfit_buf + offset; 23666bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 2367d7d8464dSRoss Zwisler dcr->header.length = sizeof(*dcr); 23686bc75619SDan Williams dcr->region_index = 2+1; 23695dc68e55SDan Williams dcr_common_init(dcr); 23706bc75619SDan Williams dcr->serial_number = ~handle[2]; 2371be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 23726bc75619SDan Williams dcr->windows = 1; 23736bc75619SDan Williams dcr->window_size = DCR_SIZE; 23746bc75619SDan Williams dcr->command_offset = 0; 23756bc75619SDan Williams dcr->command_size = 8; 23766bc75619SDan Williams dcr->status_offset = 8; 23776bc75619SDan Williams dcr->status_size = 4; 2378d7d8464dSRoss Zwisler offset += dcr->header.length; 23796bc75619SDan Williams 23803b87356fSDan Williams /* dcr-descriptor3: blk */ 2381d7d8464dSRoss Zwisler dcr = nfit_buf + offset; 23826bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 2383d7d8464dSRoss Zwisler dcr->header.length = sizeof(*dcr); 23846bc75619SDan Williams dcr->region_index = 3+1; 23855dc68e55SDan Williams dcr_common_init(dcr); 23866bc75619SDan Williams dcr->serial_number = ~handle[3]; 2387be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 23886bc75619SDan Williams dcr->windows = 1; 23896bc75619SDan Williams dcr->window_size = DCR_SIZE; 23906bc75619SDan Williams dcr->command_offset = 0; 23916bc75619SDan Williams dcr->command_size = 8; 23926bc75619SDan Williams dcr->status_offset = 8; 23936bc75619SDan Williams dcr->status_size = 4; 2394d7d8464dSRoss Zwisler offset += dcr->header.length; 23956bc75619SDan Williams 23963b87356fSDan Williams /* dcr-descriptor0: pmem */ 23973b87356fSDan Williams dcr = nfit_buf + offset; 23983b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 23993b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 24003b87356fSDan Williams window_size); 24013b87356fSDan Williams dcr->region_index = 4+1; 24025dc68e55SDan Williams dcr_common_init(dcr); 24033b87356fSDan Williams dcr->serial_number = ~handle[0]; 24043b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 24053b87356fSDan Williams dcr->windows = 0; 2406d7d8464dSRoss Zwisler offset += dcr->header.length; 24073b87356fSDan Williams 24083b87356fSDan Williams /* dcr-descriptor1: pmem */ 2409d7d8464dSRoss Zwisler dcr = nfit_buf + offset; 24103b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 24113b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 24123b87356fSDan Williams window_size); 24133b87356fSDan Williams dcr->region_index = 5+1; 24145dc68e55SDan Williams dcr_common_init(dcr); 24153b87356fSDan Williams dcr->serial_number = ~handle[1]; 24163b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 24173b87356fSDan Williams dcr->windows = 0; 2418d7d8464dSRoss Zwisler offset += dcr->header.length; 24193b87356fSDan Williams 24203b87356fSDan Williams /* dcr-descriptor2: pmem */ 2421d7d8464dSRoss Zwisler dcr = nfit_buf + offset; 24223b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 24233b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 24243b87356fSDan Williams window_size); 24253b87356fSDan Williams dcr->region_index = 6+1; 24265dc68e55SDan Williams dcr_common_init(dcr); 24273b87356fSDan Williams dcr->serial_number = ~handle[2]; 24283b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 24293b87356fSDan Williams dcr->windows = 0; 2430d7d8464dSRoss Zwisler offset += dcr->header.length; 24313b87356fSDan Williams 24323b87356fSDan Williams /* dcr-descriptor3: pmem */ 2433d7d8464dSRoss Zwisler dcr = nfit_buf + offset; 24343b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 24353b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 24363b87356fSDan Williams window_size); 24373b87356fSDan Williams dcr->region_index = 7+1; 24385dc68e55SDan Williams dcr_common_init(dcr); 24393b87356fSDan Williams dcr->serial_number = ~handle[3]; 24403b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 24413b87356fSDan Williams dcr->windows = 0; 2442d7d8464dSRoss Zwisler offset += dcr->header.length; 24433b87356fSDan Williams 24446bc75619SDan Williams /* bdw0 (spa/dcr0, dimm0) */ 24456bc75619SDan Williams bdw = nfit_buf + offset; 24466bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 2447d7d8464dSRoss Zwisler bdw->header.length = sizeof(*bdw); 24486bc75619SDan Williams bdw->region_index = 0+1; 24496bc75619SDan Williams bdw->windows = 1; 24506bc75619SDan Williams bdw->offset = 0; 24516bc75619SDan Williams bdw->size = BDW_SIZE; 24526bc75619SDan Williams bdw->capacity = DIMM_SIZE; 24536bc75619SDan Williams bdw->start_address = 0; 2454d7d8464dSRoss Zwisler offset += bdw->header.length; 24556bc75619SDan Williams 24566bc75619SDan Williams /* bdw1 (spa/dcr1, dimm1) */ 2457d7d8464dSRoss Zwisler bdw = nfit_buf + offset; 24586bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 2459d7d8464dSRoss Zwisler bdw->header.length = sizeof(*bdw); 24606bc75619SDan Williams bdw->region_index = 1+1; 24616bc75619SDan Williams bdw->windows = 1; 24626bc75619SDan Williams bdw->offset = 0; 24636bc75619SDan Williams bdw->size = BDW_SIZE; 24646bc75619SDan Williams bdw->capacity = DIMM_SIZE; 24656bc75619SDan Williams bdw->start_address = 0; 2466d7d8464dSRoss Zwisler offset += bdw->header.length; 24676bc75619SDan Williams 24686bc75619SDan Williams /* bdw2 (spa/dcr2, dimm2) */ 2469d7d8464dSRoss Zwisler bdw = nfit_buf + offset; 24706bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 2471d7d8464dSRoss Zwisler bdw->header.length = sizeof(*bdw); 24726bc75619SDan Williams bdw->region_index = 2+1; 24736bc75619SDan Williams bdw->windows = 1; 24746bc75619SDan Williams bdw->offset = 0; 24756bc75619SDan Williams bdw->size = BDW_SIZE; 24766bc75619SDan Williams bdw->capacity = DIMM_SIZE; 24776bc75619SDan Williams bdw->start_address = 0; 2478d7d8464dSRoss Zwisler offset += bdw->header.length; 24796bc75619SDan Williams 24806bc75619SDan Williams /* bdw3 (spa/dcr3, dimm3) */ 2481d7d8464dSRoss Zwisler bdw = nfit_buf + offset; 24826bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 2483d7d8464dSRoss Zwisler bdw->header.length = sizeof(*bdw); 24846bc75619SDan Williams bdw->region_index = 3+1; 24856bc75619SDan Williams bdw->windows = 1; 24866bc75619SDan Williams bdw->offset = 0; 24876bc75619SDan Williams bdw->size = BDW_SIZE; 24886bc75619SDan Williams bdw->capacity = DIMM_SIZE; 24896bc75619SDan Williams bdw->start_address = 0; 2490d7d8464dSRoss Zwisler offset += bdw->header.length; 24916bc75619SDan Williams 24929d27a87eSDan Williams /* flush0 (dimm0) */ 24939d27a87eSDan Williams flush = nfit_buf + offset; 24949d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 249585d3fa02SDan Williams flush->header.length = flush_hint_size; 24969d27a87eSDan Williams flush->device_handle = handle[0]; 249785d3fa02SDan Williams flush->hint_count = NUM_HINTS; 249885d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 249985d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[0] + i * sizeof(u64); 2500d7d8464dSRoss Zwisler offset += flush->header.length; 25019d27a87eSDan Williams 25029d27a87eSDan Williams /* flush1 (dimm1) */ 2503d7d8464dSRoss Zwisler flush = nfit_buf + offset; 25049d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 250585d3fa02SDan Williams flush->header.length = flush_hint_size; 25069d27a87eSDan Williams flush->device_handle = handle[1]; 250785d3fa02SDan Williams flush->hint_count = NUM_HINTS; 250885d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 250985d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[1] + i * sizeof(u64); 2510d7d8464dSRoss Zwisler offset += flush->header.length; 25119d27a87eSDan Williams 25129d27a87eSDan Williams /* flush2 (dimm2) */ 2513d7d8464dSRoss Zwisler flush = nfit_buf + offset; 25149d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 251585d3fa02SDan Williams flush->header.length = flush_hint_size; 25169d27a87eSDan Williams flush->device_handle = handle[2]; 251785d3fa02SDan Williams flush->hint_count = NUM_HINTS; 251885d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 251985d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[2] + i * sizeof(u64); 2520d7d8464dSRoss Zwisler offset += flush->header.length; 25219d27a87eSDan Williams 25229d27a87eSDan Williams /* flush3 (dimm3) */ 2523d7d8464dSRoss Zwisler flush = nfit_buf + offset; 25249d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 252585d3fa02SDan Williams flush->header.length = flush_hint_size; 25269d27a87eSDan Williams flush->device_handle = handle[3]; 252785d3fa02SDan Williams flush->hint_count = NUM_HINTS; 252885d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 252985d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[3] + i * sizeof(u64); 2530d7d8464dSRoss Zwisler offset += flush->header.length; 25319d27a87eSDan Williams 2532f81e1d35SDave Jiang /* platform capabilities */ 2533d7d8464dSRoss Zwisler pcap = nfit_buf + offset; 2534f81e1d35SDave Jiang pcap->header.type = ACPI_NFIT_TYPE_CAPABILITIES; 2535f81e1d35SDave Jiang pcap->header.length = sizeof(*pcap); 2536f81e1d35SDave Jiang pcap->highest_capability = 1; 25371273c253SVishal Verma pcap->capabilities = ACPI_NFIT_CAPABILITY_MEM_FLUSH; 2538d7d8464dSRoss Zwisler offset += pcap->header.length; 2539f81e1d35SDave Jiang 254020985164SVishal Verma if (t->setup_hotplug) { 25413b87356fSDan Williams /* dcr-descriptor4: blk */ 254220985164SVishal Verma dcr = nfit_buf + offset; 254320985164SVishal Verma dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 2544d7d8464dSRoss Zwisler dcr->header.length = sizeof(*dcr); 25453b87356fSDan Williams dcr->region_index = 8+1; 25465dc68e55SDan Williams dcr_common_init(dcr); 254720985164SVishal Verma dcr->serial_number = ~handle[4]; 2548be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 254920985164SVishal Verma dcr->windows = 1; 255020985164SVishal Verma dcr->window_size = DCR_SIZE; 255120985164SVishal Verma dcr->command_offset = 0; 255220985164SVishal Verma dcr->command_size = 8; 255320985164SVishal Verma dcr->status_offset = 8; 255420985164SVishal Verma dcr->status_size = 4; 2555d7d8464dSRoss Zwisler offset += dcr->header.length; 255620985164SVishal Verma 25573b87356fSDan Williams /* dcr-descriptor4: pmem */ 25583b87356fSDan Williams dcr = nfit_buf + offset; 25593b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 25603b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 25613b87356fSDan Williams window_size); 25623b87356fSDan Williams dcr->region_index = 9+1; 25635dc68e55SDan Williams dcr_common_init(dcr); 25643b87356fSDan Williams dcr->serial_number = ~handle[4]; 25653b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 25663b87356fSDan Williams dcr->windows = 0; 2567d7d8464dSRoss Zwisler offset += dcr->header.length; 25683b87356fSDan Williams 256920985164SVishal Verma /* bdw4 (spa/dcr4, dimm4) */ 257020985164SVishal Verma bdw = nfit_buf + offset; 257120985164SVishal Verma bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 2572d7d8464dSRoss Zwisler bdw->header.length = sizeof(*bdw); 25733b87356fSDan Williams bdw->region_index = 8+1; 257420985164SVishal Verma bdw->windows = 1; 257520985164SVishal Verma bdw->offset = 0; 257620985164SVishal Verma bdw->size = BDW_SIZE; 257720985164SVishal Verma bdw->capacity = DIMM_SIZE; 257820985164SVishal Verma bdw->start_address = 0; 2579d7d8464dSRoss Zwisler offset += bdw->header.length; 258020985164SVishal Verma 258120985164SVishal Verma /* spa10 (dcr4) dimm4 */ 258220985164SVishal Verma spa = nfit_buf + offset; 258320985164SVishal Verma spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 258420985164SVishal Verma spa->header.length = sizeof(*spa); 258520985164SVishal Verma memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 258620985164SVishal Verma spa->range_index = 10+1; 258720985164SVishal Verma spa->address = t->dcr_dma[4]; 258820985164SVishal Verma spa->length = DCR_SIZE; 2589d7d8464dSRoss Zwisler offset += spa->header.length; 259020985164SVishal Verma 259120985164SVishal Verma /* 259220985164SVishal Verma * spa11 (single-dimm interleave for hotplug, note storage 259320985164SVishal Verma * does not actually alias the related block-data-window 259420985164SVishal Verma * regions) 259520985164SVishal Verma */ 2596d7d8464dSRoss Zwisler spa = nfit_buf + offset; 259720985164SVishal Verma spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 259820985164SVishal Verma spa->header.length = sizeof(*spa); 259920985164SVishal Verma memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 260020985164SVishal Verma spa->range_index = 11+1; 260120985164SVishal Verma spa->address = t->spa_set_dma[2]; 260220985164SVishal Verma spa->length = SPA0_SIZE; 2603d7d8464dSRoss Zwisler offset += spa->header.length; 260420985164SVishal Verma 260520985164SVishal Verma /* spa12 (bdw for dcr4) dimm4 */ 2606d7d8464dSRoss Zwisler spa = nfit_buf + offset; 260720985164SVishal Verma spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 260820985164SVishal Verma spa->header.length = sizeof(*spa); 260920985164SVishal Verma memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 261020985164SVishal Verma spa->range_index = 12+1; 261120985164SVishal Verma spa->address = t->dimm_dma[4]; 261220985164SVishal Verma spa->length = DIMM_SIZE; 2613d7d8464dSRoss Zwisler offset += spa->header.length; 261420985164SVishal Verma 261520985164SVishal Verma /* mem-region14 (spa/dcr4, dimm4) */ 261620985164SVishal Verma memdev = nfit_buf + offset; 261720985164SVishal Verma memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 261820985164SVishal Verma memdev->header.length = sizeof(*memdev); 261920985164SVishal Verma memdev->device_handle = handle[4]; 262020985164SVishal Verma memdev->physical_id = 4; 262120985164SVishal Verma memdev->region_id = 0; 262220985164SVishal Verma memdev->range_index = 10+1; 26233b87356fSDan Williams memdev->region_index = 8+1; 262420985164SVishal Verma memdev->region_size = 0; 262520985164SVishal Verma memdev->region_offset = 0; 262620985164SVishal Verma memdev->address = 0; 262720985164SVishal Verma memdev->interleave_index = 0; 262820985164SVishal Verma memdev->interleave_ways = 1; 2629d7d8464dSRoss Zwisler offset += memdev->header.length; 263020985164SVishal Verma 2631d7d8464dSRoss Zwisler /* mem-region15 (spa11, dimm4) */ 2632d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 263320985164SVishal Verma memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 263420985164SVishal Verma memdev->header.length = sizeof(*memdev); 263520985164SVishal Verma memdev->device_handle = handle[4]; 263620985164SVishal Verma memdev->physical_id = 4; 263720985164SVishal Verma memdev->region_id = 0; 263820985164SVishal Verma memdev->range_index = 11+1; 26393b87356fSDan Williams memdev->region_index = 9+1; 264020985164SVishal Verma memdev->region_size = SPA0_SIZE; 2641df06a2d5SDan Williams memdev->region_offset = (1ULL << 48); 264220985164SVishal Verma memdev->address = 0; 264320985164SVishal Verma memdev->interleave_index = 0; 264420985164SVishal Verma memdev->interleave_ways = 1; 2645ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED; 2646d7d8464dSRoss Zwisler offset += memdev->header.length; 264720985164SVishal Verma 26483b87356fSDan Williams /* mem-region16 (spa/bdw4, dimm4) */ 2649d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 265020985164SVishal Verma memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 265120985164SVishal Verma memdev->header.length = sizeof(*memdev); 265220985164SVishal Verma memdev->device_handle = handle[4]; 265320985164SVishal Verma memdev->physical_id = 4; 265420985164SVishal Verma memdev->region_id = 0; 265520985164SVishal Verma memdev->range_index = 12+1; 26563b87356fSDan Williams memdev->region_index = 8+1; 265720985164SVishal Verma memdev->region_size = 0; 265820985164SVishal Verma memdev->region_offset = 0; 265920985164SVishal Verma memdev->address = 0; 266020985164SVishal Verma memdev->interleave_index = 0; 266120985164SVishal Verma memdev->interleave_ways = 1; 2662d7d8464dSRoss Zwisler offset += memdev->header.length; 266320985164SVishal Verma 266420985164SVishal Verma /* flush3 (dimm4) */ 266520985164SVishal Verma flush = nfit_buf + offset; 266620985164SVishal Verma flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 266785d3fa02SDan Williams flush->header.length = flush_hint_size; 266820985164SVishal Verma flush->device_handle = handle[4]; 266985d3fa02SDan Williams flush->hint_count = NUM_HINTS; 267085d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 267185d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[4] 267285d3fa02SDan Williams + i * sizeof(u64); 2673d7d8464dSRoss Zwisler offset += flush->header.length; 26749741a559SRoss Zwisler 26759741a559SRoss Zwisler /* sanity check to make sure we've filled the buffer */ 26769741a559SRoss Zwisler WARN_ON(offset != t->nfit_size); 267720985164SVishal Verma } 267820985164SVishal Verma 26791526f9e2SRoss Zwisler t->nfit_filled = offset; 26801526f9e2SRoss Zwisler 26819fb1a190SDave Jiang post_ars_status(&t->ars_state, &t->badrange, t->spa_set_dma[0], 26829fb1a190SDave Jiang SPA0_SIZE); 2683f471f1a7SDan Williams 26846bc75619SDan Williams acpi_desc = &t->acpi_desc; 2685e3654ecaSDan Williams set_bit(ND_CMD_GET_CONFIG_SIZE, &acpi_desc->dimm_cmd_force_en); 2686e3654ecaSDan Williams set_bit(ND_CMD_GET_CONFIG_DATA, &acpi_desc->dimm_cmd_force_en); 2687e3654ecaSDan Williams set_bit(ND_CMD_SET_CONFIG_DATA, &acpi_desc->dimm_cmd_force_en); 2688ed07c433SDan Williams set_bit(ND_INTEL_SMART, &acpi_desc->dimm_cmd_force_en); 2689ed07c433SDan Williams set_bit(ND_INTEL_SMART_THRESHOLD, &acpi_desc->dimm_cmd_force_en); 2690ed07c433SDan Williams set_bit(ND_INTEL_SMART_SET_THRESHOLD, &acpi_desc->dimm_cmd_force_en); 26914cf260fcSVishal Verma set_bit(ND_INTEL_SMART_INJECT, &acpi_desc->dimm_cmd_force_en); 2692e3654ecaSDan Williams set_bit(ND_CMD_ARS_CAP, &acpi_desc->bus_cmd_force_en); 2693e3654ecaSDan Williams set_bit(ND_CMD_ARS_START, &acpi_desc->bus_cmd_force_en); 2694e3654ecaSDan Williams set_bit(ND_CMD_ARS_STATUS, &acpi_desc->bus_cmd_force_en); 2695e3654ecaSDan Williams set_bit(ND_CMD_CLEAR_ERROR, &acpi_desc->bus_cmd_force_en); 269610246dc8SYasunori Goto set_bit(ND_CMD_CALL, &acpi_desc->bus_cmd_force_en); 2697d46e6a21SDan Williams set_bit(NFIT_CMD_TRANSLATE_SPA, &acpi_desc->bus_dsm_mask); 2698d46e6a21SDan Williams set_bit(NFIT_CMD_ARS_INJECT_SET, &acpi_desc->bus_dsm_mask); 2699d46e6a21SDan Williams set_bit(NFIT_CMD_ARS_INJECT_CLEAR, &acpi_desc->bus_dsm_mask); 2700d46e6a21SDan Williams set_bit(NFIT_CMD_ARS_INJECT_GET, &acpi_desc->bus_dsm_mask); 2701bfbaa952SDave Jiang set_bit(ND_INTEL_FW_GET_INFO, &acpi_desc->dimm_cmd_force_en); 2702bfbaa952SDave Jiang set_bit(ND_INTEL_FW_START_UPDATE, &acpi_desc->dimm_cmd_force_en); 2703bfbaa952SDave Jiang set_bit(ND_INTEL_FW_SEND_DATA, &acpi_desc->dimm_cmd_force_en); 2704bfbaa952SDave Jiang set_bit(ND_INTEL_FW_FINISH_UPDATE, &acpi_desc->dimm_cmd_force_en); 2705bfbaa952SDave Jiang set_bit(ND_INTEL_FW_FINISH_QUERY, &acpi_desc->dimm_cmd_force_en); 2706674d8bdeSDave Jiang set_bit(ND_INTEL_ENABLE_LSS_STATUS, &acpi_desc->dimm_cmd_force_en); 27073c13e2acSDave Jiang set_bit(NVDIMM_INTEL_GET_SECURITY_STATE, 27083c13e2acSDave Jiang &acpi_desc->dimm_cmd_force_en); 27093c13e2acSDave Jiang set_bit(NVDIMM_INTEL_SET_PASSPHRASE, &acpi_desc->dimm_cmd_force_en); 27103c13e2acSDave Jiang set_bit(NVDIMM_INTEL_DISABLE_PASSPHRASE, 27113c13e2acSDave Jiang &acpi_desc->dimm_cmd_force_en); 27123c13e2acSDave Jiang set_bit(NVDIMM_INTEL_UNLOCK_UNIT, &acpi_desc->dimm_cmd_force_en); 27133c13e2acSDave Jiang set_bit(NVDIMM_INTEL_FREEZE_LOCK, &acpi_desc->dimm_cmd_force_en); 27143c13e2acSDave Jiang set_bit(NVDIMM_INTEL_SECURE_ERASE, &acpi_desc->dimm_cmd_force_en); 2715926f7480SDave Jiang set_bit(NVDIMM_INTEL_OVERWRITE, &acpi_desc->dimm_cmd_force_en); 2716926f7480SDave Jiang set_bit(NVDIMM_INTEL_QUERY_OVERWRITE, &acpi_desc->dimm_cmd_force_en); 2717ecaa4a97SDave Jiang set_bit(NVDIMM_INTEL_SET_MASTER_PASSPHRASE, 2718ecaa4a97SDave Jiang &acpi_desc->dimm_cmd_force_en); 2719ecaa4a97SDave Jiang set_bit(NVDIMM_INTEL_MASTER_SECURE_ERASE, 2720ecaa4a97SDave Jiang &acpi_desc->dimm_cmd_force_en); 2721*916566aeSDan Williams set_bit(NVDIMM_INTEL_FW_ACTIVATE_DIMMINFO, &acpi_desc->dimm_cmd_force_en); 2722*916566aeSDan Williams set_bit(NVDIMM_INTEL_FW_ACTIVATE_ARM, &acpi_desc->dimm_cmd_force_en); 2723*916566aeSDan Williams 2724*916566aeSDan Williams acpi_mask = &acpi_desc->family_dsm_mask[NVDIMM_BUS_FAMILY_INTEL]; 2725*916566aeSDan Williams set_bit(NVDIMM_BUS_INTEL_FW_ACTIVATE_BUSINFO, acpi_mask); 2726*916566aeSDan Williams set_bit(NVDIMM_BUS_INTEL_FW_ACTIVATE, acpi_mask); 27276bc75619SDan Williams } 27286bc75619SDan Williams 27296bc75619SDan Williams static void nfit_test1_setup(struct nfit_test *t) 27306bc75619SDan Williams { 27316b577c9dSLinda Knippers size_t offset; 27326bc75619SDan Williams void *nfit_buf = t->nfit_buf; 27336bc75619SDan Williams struct acpi_nfit_memory_map *memdev; 27346bc75619SDan Williams struct acpi_nfit_control_region *dcr; 27356bc75619SDan Williams struct acpi_nfit_system_address *spa; 2736d26f73f0SDan Williams struct acpi_nfit_desc *acpi_desc; 27376bc75619SDan Williams 27386b577c9dSLinda Knippers offset = 0; 27396bc75619SDan Williams /* spa0 (flat range with no bdw aliasing) */ 27406bc75619SDan Williams spa = nfit_buf + offset; 27416bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 27426bc75619SDan Williams spa->header.length = sizeof(*spa); 27436bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 27446bc75619SDan Williams spa->range_index = 0+1; 27456bc75619SDan Williams spa->address = t->spa_set_dma[0]; 27466bc75619SDan Williams spa->length = SPA2_SIZE; 2747d7d8464dSRoss Zwisler offset += spa->header.length; 27486bc75619SDan Williams 27497bfe97c7SDan Williams /* virtual cd region */ 2750d7d8464dSRoss Zwisler spa = nfit_buf + offset; 27517bfe97c7SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 27527bfe97c7SDan Williams spa->header.length = sizeof(*spa); 27537bfe97c7SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_VCD), 16); 27547bfe97c7SDan Williams spa->range_index = 0; 27557bfe97c7SDan Williams spa->address = t->spa_set_dma[1]; 27567bfe97c7SDan Williams spa->length = SPA_VCD_SIZE; 2757d7d8464dSRoss Zwisler offset += spa->header.length; 27587bfe97c7SDan Williams 27596bc75619SDan Williams /* mem-region0 (spa0, dimm0) */ 27606bc75619SDan Williams memdev = nfit_buf + offset; 27616bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 27626bc75619SDan Williams memdev->header.length = sizeof(*memdev); 2763dafb1048SDan Williams memdev->device_handle = handle[5]; 27646bc75619SDan Williams memdev->physical_id = 0; 27656bc75619SDan Williams memdev->region_id = 0; 27666bc75619SDan Williams memdev->range_index = 0+1; 27676bc75619SDan Williams memdev->region_index = 0+1; 27686bc75619SDan Williams memdev->region_size = SPA2_SIZE; 27696bc75619SDan Williams memdev->region_offset = 0; 27706bc75619SDan Williams memdev->address = 0; 27716bc75619SDan Williams memdev->interleave_index = 0; 27726bc75619SDan Williams memdev->interleave_ways = 1; 277358138820SDan Williams memdev->flags = ACPI_NFIT_MEM_SAVE_FAILED | ACPI_NFIT_MEM_RESTORE_FAILED 277458138820SDan Williams | ACPI_NFIT_MEM_FLUSH_FAILED | ACPI_NFIT_MEM_HEALTH_OBSERVED 2775f4295796SDan Williams | ACPI_NFIT_MEM_NOT_ARMED; 2776d7d8464dSRoss Zwisler offset += memdev->header.length; 27776bc75619SDan Williams 27786bc75619SDan Williams /* dcr-descriptor0 */ 27796bc75619SDan Williams dcr = nfit_buf + offset; 27806bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 27813b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 27823b87356fSDan Williams window_size); 27836bc75619SDan Williams dcr->region_index = 0+1; 27845dc68e55SDan Williams dcr_common_init(dcr); 2785dafb1048SDan Williams dcr->serial_number = ~handle[5]; 2786be26f9aeSDan Williams dcr->code = NFIT_FIC_BYTE; 27876bc75619SDan Williams dcr->windows = 0; 2788ac40b675SDan Williams offset += dcr->header.length; 2789d7d8464dSRoss Zwisler 2790ac40b675SDan Williams memdev = nfit_buf + offset; 2791ac40b675SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 2792ac40b675SDan Williams memdev->header.length = sizeof(*memdev); 2793ac40b675SDan Williams memdev->device_handle = handle[6]; 2794ac40b675SDan Williams memdev->physical_id = 0; 2795ac40b675SDan Williams memdev->region_id = 0; 2796ac40b675SDan Williams memdev->range_index = 0; 2797ac40b675SDan Williams memdev->region_index = 0+2; 2798ac40b675SDan Williams memdev->region_size = SPA2_SIZE; 2799ac40b675SDan Williams memdev->region_offset = 0; 2800ac40b675SDan Williams memdev->address = 0; 2801ac40b675SDan Williams memdev->interleave_index = 0; 2802ac40b675SDan Williams memdev->interleave_ways = 1; 2803ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_MAP_FAILED; 2804d7d8464dSRoss Zwisler offset += memdev->header.length; 2805ac40b675SDan Williams 2806ac40b675SDan Williams /* dcr-descriptor1 */ 2807ac40b675SDan Williams dcr = nfit_buf + offset; 2808ac40b675SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 2809ac40b675SDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 2810ac40b675SDan Williams window_size); 2811ac40b675SDan Williams dcr->region_index = 0+2; 2812ac40b675SDan Williams dcr_common_init(dcr); 2813ac40b675SDan Williams dcr->serial_number = ~handle[6]; 2814ac40b675SDan Williams dcr->code = NFIT_FIC_BYTE; 2815ac40b675SDan Williams dcr->windows = 0; 2816d7d8464dSRoss Zwisler offset += dcr->header.length; 2817ac40b675SDan Williams 28189741a559SRoss Zwisler /* sanity check to make sure we've filled the buffer */ 28199741a559SRoss Zwisler WARN_ON(offset != t->nfit_size); 28209741a559SRoss Zwisler 28211526f9e2SRoss Zwisler t->nfit_filled = offset; 28221526f9e2SRoss Zwisler 28239fb1a190SDave Jiang post_ars_status(&t->ars_state, &t->badrange, t->spa_set_dma[0], 28249fb1a190SDave Jiang SPA2_SIZE); 2825f471f1a7SDan Williams 2826d26f73f0SDan Williams acpi_desc = &t->acpi_desc; 2827e3654ecaSDan Williams set_bit(ND_CMD_ARS_CAP, &acpi_desc->bus_cmd_force_en); 2828e3654ecaSDan Williams set_bit(ND_CMD_ARS_START, &acpi_desc->bus_cmd_force_en); 2829e3654ecaSDan Williams set_bit(ND_CMD_ARS_STATUS, &acpi_desc->bus_cmd_force_en); 2830e3654ecaSDan Williams set_bit(ND_CMD_CLEAR_ERROR, &acpi_desc->bus_cmd_force_en); 2831674d8bdeSDave Jiang set_bit(ND_INTEL_ENABLE_LSS_STATUS, &acpi_desc->dimm_cmd_force_en); 28329484e12dSDan Williams set_bit(ND_CMD_GET_CONFIG_SIZE, &acpi_desc->dimm_cmd_force_en); 28339484e12dSDan Williams set_bit(ND_CMD_GET_CONFIG_DATA, &acpi_desc->dimm_cmd_force_en); 28349484e12dSDan Williams set_bit(ND_CMD_SET_CONFIG_DATA, &acpi_desc->dimm_cmd_force_en); 28356bc75619SDan Williams } 28366bc75619SDan Williams 28376bc75619SDan Williams static int nfit_test_blk_do_io(struct nd_blk_region *ndbr, resource_size_t dpa, 28386bc75619SDan Williams void *iobuf, u64 len, int rw) 28396bc75619SDan Williams { 28406bc75619SDan Williams struct nfit_blk *nfit_blk = ndbr->blk_provider_data; 28416bc75619SDan Williams struct nfit_blk_mmio *mmio = &nfit_blk->mmio[BDW]; 28426bc75619SDan Williams struct nd_region *nd_region = &ndbr->nd_region; 28436bc75619SDan Williams unsigned int lane; 28446bc75619SDan Williams 28456bc75619SDan Williams lane = nd_region_acquire_lane(nd_region); 28466bc75619SDan Williams if (rw) 284767a3e8feSRoss Zwisler memcpy(mmio->addr.base + dpa, iobuf, len); 284867a3e8feSRoss Zwisler else { 284967a3e8feSRoss Zwisler memcpy(iobuf, mmio->addr.base + dpa, len); 285067a3e8feSRoss Zwisler 28515deb67f7SRobin Murphy /* give us some some coverage of the arch_invalidate_pmem() API */ 28525deb67f7SRobin Murphy arch_invalidate_pmem(mmio->addr.base + dpa, len); 285367a3e8feSRoss Zwisler } 28546bc75619SDan Williams nd_region_release_lane(nd_region, lane); 28556bc75619SDan Williams 28566bc75619SDan Williams return 0; 28576bc75619SDan Williams } 28586bc75619SDan Williams 2859a7de92daSDan Williams static unsigned long nfit_ctl_handle; 2860a7de92daSDan Williams 2861a7de92daSDan Williams union acpi_object *result; 2862a7de92daSDan Williams 2863a7de92daSDan Williams static union acpi_object *nfit_test_evaluate_dsm(acpi_handle handle, 286494116f81SAndy Shevchenko const guid_t *guid, u64 rev, u64 func, union acpi_object *argv4) 2865a7de92daSDan Williams { 2866a7de92daSDan Williams if (handle != &nfit_ctl_handle) 2867a7de92daSDan Williams return ERR_PTR(-ENXIO); 2868a7de92daSDan Williams 2869a7de92daSDan Williams return result; 2870a7de92daSDan Williams } 2871a7de92daSDan Williams 2872a7de92daSDan Williams static int setup_result(void *buf, size_t size) 2873a7de92daSDan Williams { 2874a7de92daSDan Williams result = kmalloc(sizeof(union acpi_object) + size, GFP_KERNEL); 2875a7de92daSDan Williams if (!result) 2876a7de92daSDan Williams return -ENOMEM; 2877a7de92daSDan Williams result->package.type = ACPI_TYPE_BUFFER, 2878a7de92daSDan Williams result->buffer.pointer = (void *) (result + 1); 2879a7de92daSDan Williams result->buffer.length = size; 2880a7de92daSDan Williams memcpy(result->buffer.pointer, buf, size); 2881a7de92daSDan Williams memset(buf, 0, size); 2882a7de92daSDan Williams return 0; 2883a7de92daSDan Williams } 2884a7de92daSDan Williams 2885a7de92daSDan Williams static int nfit_ctl_test(struct device *dev) 2886a7de92daSDan Williams { 2887a7de92daSDan Williams int rc, cmd_rc; 2888a7de92daSDan Williams struct nvdimm *nvdimm; 2889a7de92daSDan Williams struct acpi_device *adev; 2890a7de92daSDan Williams struct nfit_mem *nfit_mem; 2891a7de92daSDan Williams struct nd_ars_record *record; 2892a7de92daSDan Williams struct acpi_nfit_desc *acpi_desc; 2893a7de92daSDan Williams const u64 test_val = 0x0123456789abcdefULL; 2894a7de92daSDan Williams unsigned long mask, cmd_size, offset; 2895abfd4d9cSDan Williams struct nfit_ctl_test_cmd { 2896abfd4d9cSDan Williams struct nd_cmd_pkg pkg; 2897a7de92daSDan Williams union { 2898a7de92daSDan Williams struct nd_cmd_get_config_size cfg_size; 2899fb2a1748SDan Williams struct nd_cmd_clear_error clear_err; 2900a7de92daSDan Williams struct nd_cmd_ars_status ars_stat; 2901a7de92daSDan Williams struct nd_cmd_ars_cap ars_cap; 2902*916566aeSDan Williams struct nd_intel_bus_fw_activate_businfo fwa_info; 2903a7de92daSDan Williams char buf[sizeof(struct nd_cmd_ars_status) 2904a7de92daSDan Williams + sizeof(struct nd_ars_record)]; 2905abfd4d9cSDan Williams }; 2906abfd4d9cSDan Williams } cmd; 2907a7de92daSDan Williams 2908a7de92daSDan Williams adev = devm_kzalloc(dev, sizeof(*adev), GFP_KERNEL); 2909a7de92daSDan Williams if (!adev) 2910a7de92daSDan Williams return -ENOMEM; 2911a7de92daSDan Williams *adev = (struct acpi_device) { 2912a7de92daSDan Williams .handle = &nfit_ctl_handle, 2913a7de92daSDan Williams .dev = { 2914a7de92daSDan Williams .init_name = "test-adev", 2915a7de92daSDan Williams }, 2916a7de92daSDan Williams }; 2917a7de92daSDan Williams 2918a7de92daSDan Williams acpi_desc = devm_kzalloc(dev, sizeof(*acpi_desc), GFP_KERNEL); 2919a7de92daSDan Williams if (!acpi_desc) 2920a7de92daSDan Williams return -ENOMEM; 2921a7de92daSDan Williams *acpi_desc = (struct acpi_nfit_desc) { 2922a7de92daSDan Williams .nd_desc = { 2923a7de92daSDan Williams .cmd_mask = 1UL << ND_CMD_ARS_CAP 2924a7de92daSDan Williams | 1UL << ND_CMD_ARS_START 2925a7de92daSDan Williams | 1UL << ND_CMD_ARS_STATUS 292610246dc8SYasunori Goto | 1UL << ND_CMD_CLEAR_ERROR 292710246dc8SYasunori Goto | 1UL << ND_CMD_CALL, 2928a7de92daSDan Williams .module = THIS_MODULE, 2929a7de92daSDan Williams .provider_name = "ACPI.NFIT", 2930a7de92daSDan Williams .ndctl = acpi_nfit_ctl, 2931*916566aeSDan Williams .bus_family_mask = 1UL << NVDIMM_BUS_FAMILY_NFIT 2932*916566aeSDan Williams | 1UL << NVDIMM_BUS_FAMILY_INTEL, 2933d46e6a21SDan Williams }, 29349fb1a190SDave Jiang .bus_dsm_mask = 1UL << NFIT_CMD_TRANSLATE_SPA 29359fb1a190SDave Jiang | 1UL << NFIT_CMD_ARS_INJECT_SET 29369fb1a190SDave Jiang | 1UL << NFIT_CMD_ARS_INJECT_CLEAR 29379fb1a190SDave Jiang | 1UL << NFIT_CMD_ARS_INJECT_GET, 2938*916566aeSDan Williams .family_dsm_mask[NVDIMM_BUS_FAMILY_INTEL] = 2939*916566aeSDan Williams NVDIMM_BUS_INTEL_FW_ACTIVATE_CMDMASK, 2940a7de92daSDan Williams .dev = &adev->dev, 2941a7de92daSDan Williams }; 2942a7de92daSDan Williams 2943a7de92daSDan Williams nfit_mem = devm_kzalloc(dev, sizeof(*nfit_mem), GFP_KERNEL); 2944a7de92daSDan Williams if (!nfit_mem) 2945a7de92daSDan Williams return -ENOMEM; 2946a7de92daSDan Williams 2947a7de92daSDan Williams mask = 1UL << ND_CMD_SMART | 1UL << ND_CMD_SMART_THRESHOLD 2948a7de92daSDan Williams | 1UL << ND_CMD_DIMM_FLAGS | 1UL << ND_CMD_GET_CONFIG_SIZE 2949a7de92daSDan Williams | 1UL << ND_CMD_GET_CONFIG_DATA | 1UL << ND_CMD_SET_CONFIG_DATA 2950a7de92daSDan Williams | 1UL << ND_CMD_VENDOR; 2951a7de92daSDan Williams *nfit_mem = (struct nfit_mem) { 2952a7de92daSDan Williams .adev = adev, 2953a7de92daSDan Williams .family = NVDIMM_FAMILY_INTEL, 2954a7de92daSDan Williams .dsm_mask = mask, 2955a7de92daSDan Williams }; 2956a7de92daSDan Williams 2957a7de92daSDan Williams nvdimm = devm_kzalloc(dev, sizeof(*nvdimm), GFP_KERNEL); 2958a7de92daSDan Williams if (!nvdimm) 2959a7de92daSDan Williams return -ENOMEM; 2960a7de92daSDan Williams *nvdimm = (struct nvdimm) { 2961a7de92daSDan Williams .provider_data = nfit_mem, 2962a7de92daSDan Williams .cmd_mask = mask, 2963a7de92daSDan Williams .dev = { 2964a7de92daSDan Williams .init_name = "test-dimm", 2965a7de92daSDan Williams }, 2966a7de92daSDan Williams }; 2967a7de92daSDan Williams 2968a7de92daSDan Williams 2969a7de92daSDan Williams /* basic checkout of a typical 'get config size' command */ 2970abfd4d9cSDan Williams cmd_size = sizeof(cmd.cfg_size); 2971abfd4d9cSDan Williams cmd.cfg_size = (struct nd_cmd_get_config_size) { 2972a7de92daSDan Williams .status = 0, 2973a7de92daSDan Williams .config_size = SZ_128K, 2974a7de92daSDan Williams .max_xfer = SZ_4K, 2975a7de92daSDan Williams }; 2976abfd4d9cSDan Williams rc = setup_result(cmd.buf, cmd_size); 2977a7de92daSDan Williams if (rc) 2978a7de92daSDan Williams return rc; 2979a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, nvdimm, ND_CMD_GET_CONFIG_SIZE, 2980abfd4d9cSDan Williams cmd.buf, cmd_size, &cmd_rc); 2981a7de92daSDan Williams 2982abfd4d9cSDan Williams if (rc < 0 || cmd_rc || cmd.cfg_size.status != 0 2983abfd4d9cSDan Williams || cmd.cfg_size.config_size != SZ_128K 2984abfd4d9cSDan Williams || cmd.cfg_size.max_xfer != SZ_4K) { 2985a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 2986a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 2987a7de92daSDan Williams return -EIO; 2988a7de92daSDan Williams } 2989a7de92daSDan Williams 2990a7de92daSDan Williams 2991a7de92daSDan Williams /* test ars_status with zero output */ 2992a7de92daSDan Williams cmd_size = offsetof(struct nd_cmd_ars_status, address); 2993abfd4d9cSDan Williams cmd.ars_stat = (struct nd_cmd_ars_status) { 2994a7de92daSDan Williams .out_length = 0, 2995a7de92daSDan Williams }; 2996abfd4d9cSDan Williams rc = setup_result(cmd.buf, cmd_size); 2997a7de92daSDan Williams if (rc) 2998a7de92daSDan Williams return rc; 2999a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_ARS_STATUS, 3000abfd4d9cSDan Williams cmd.buf, cmd_size, &cmd_rc); 3001a7de92daSDan Williams 3002a7de92daSDan Williams if (rc < 0 || cmd_rc) { 3003a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 3004a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 3005a7de92daSDan Williams return -EIO; 3006a7de92daSDan Williams } 3007a7de92daSDan Williams 3008a7de92daSDan Williams 3009a7de92daSDan Williams /* test ars_cap with benign extended status */ 3010abfd4d9cSDan Williams cmd_size = sizeof(cmd.ars_cap); 3011abfd4d9cSDan Williams cmd.ars_cap = (struct nd_cmd_ars_cap) { 3012a7de92daSDan Williams .status = ND_ARS_PERSISTENT << 16, 3013a7de92daSDan Williams }; 3014a7de92daSDan Williams offset = offsetof(struct nd_cmd_ars_cap, status); 3015abfd4d9cSDan Williams rc = setup_result(cmd.buf + offset, cmd_size - offset); 3016a7de92daSDan Williams if (rc) 3017a7de92daSDan Williams return rc; 3018a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_ARS_CAP, 3019abfd4d9cSDan Williams cmd.buf, cmd_size, &cmd_rc); 3020a7de92daSDan Williams 3021a7de92daSDan Williams if (rc < 0 || cmd_rc) { 3022a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 3023a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 3024a7de92daSDan Williams return -EIO; 3025a7de92daSDan Williams } 3026a7de92daSDan Williams 3027a7de92daSDan Williams 3028a7de92daSDan Williams /* test ars_status with 'status' trimmed from 'out_length' */ 3029abfd4d9cSDan Williams cmd_size = sizeof(cmd.ars_stat) + sizeof(struct nd_ars_record); 3030abfd4d9cSDan Williams cmd.ars_stat = (struct nd_cmd_ars_status) { 3031a7de92daSDan Williams .out_length = cmd_size - 4, 3032a7de92daSDan Williams }; 3033abfd4d9cSDan Williams record = &cmd.ars_stat.records[0]; 3034a7de92daSDan Williams *record = (struct nd_ars_record) { 3035a7de92daSDan Williams .length = test_val, 3036a7de92daSDan Williams }; 3037abfd4d9cSDan Williams rc = setup_result(cmd.buf, cmd_size); 3038a7de92daSDan Williams if (rc) 3039a7de92daSDan Williams return rc; 3040a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_ARS_STATUS, 3041abfd4d9cSDan Williams cmd.buf, cmd_size, &cmd_rc); 3042a7de92daSDan Williams 3043a7de92daSDan Williams if (rc < 0 || cmd_rc || record->length != test_val) { 3044a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 3045a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 3046a7de92daSDan Williams return -EIO; 3047a7de92daSDan Williams } 3048a7de92daSDan Williams 3049a7de92daSDan Williams 3050a7de92daSDan Williams /* test ars_status with 'Output (Size)' including 'status' */ 3051abfd4d9cSDan Williams cmd_size = sizeof(cmd.ars_stat) + sizeof(struct nd_ars_record); 3052abfd4d9cSDan Williams cmd.ars_stat = (struct nd_cmd_ars_status) { 3053a7de92daSDan Williams .out_length = cmd_size, 3054a7de92daSDan Williams }; 3055abfd4d9cSDan Williams record = &cmd.ars_stat.records[0]; 3056a7de92daSDan Williams *record = (struct nd_ars_record) { 3057a7de92daSDan Williams .length = test_val, 3058a7de92daSDan Williams }; 3059abfd4d9cSDan Williams rc = setup_result(cmd.buf, cmd_size); 3060a7de92daSDan Williams if (rc) 3061a7de92daSDan Williams return rc; 3062a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_ARS_STATUS, 3063abfd4d9cSDan Williams cmd.buf, cmd_size, &cmd_rc); 3064a7de92daSDan Williams 3065a7de92daSDan Williams if (rc < 0 || cmd_rc || record->length != test_val) { 3066a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 3067a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 3068a7de92daSDan Williams return -EIO; 3069a7de92daSDan Williams } 3070a7de92daSDan Williams 3071a7de92daSDan Williams 3072a7de92daSDan Williams /* test extended status for get_config_size results in failure */ 3073abfd4d9cSDan Williams cmd_size = sizeof(cmd.cfg_size); 3074abfd4d9cSDan Williams cmd.cfg_size = (struct nd_cmd_get_config_size) { 3075a7de92daSDan Williams .status = 1 << 16, 3076a7de92daSDan Williams }; 3077abfd4d9cSDan Williams rc = setup_result(cmd.buf, cmd_size); 3078a7de92daSDan Williams if (rc) 3079a7de92daSDan Williams return rc; 3080a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, nvdimm, ND_CMD_GET_CONFIG_SIZE, 3081abfd4d9cSDan Williams cmd.buf, cmd_size, &cmd_rc); 3082a7de92daSDan Williams 3083a7de92daSDan Williams if (rc < 0 || cmd_rc >= 0) { 3084a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 3085a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 3086a7de92daSDan Williams return -EIO; 3087a7de92daSDan Williams } 3088a7de92daSDan Williams 3089fb2a1748SDan Williams /* test clear error */ 3090abfd4d9cSDan Williams cmd_size = sizeof(cmd.clear_err); 3091abfd4d9cSDan Williams cmd.clear_err = (struct nd_cmd_clear_error) { 3092fb2a1748SDan Williams .length = 512, 3093fb2a1748SDan Williams .cleared = 512, 3094fb2a1748SDan Williams }; 3095abfd4d9cSDan Williams rc = setup_result(cmd.buf, cmd_size); 3096fb2a1748SDan Williams if (rc) 3097fb2a1748SDan Williams return rc; 3098fb2a1748SDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_CLEAR_ERROR, 3099abfd4d9cSDan Williams cmd.buf, cmd_size, &cmd_rc); 3100fb2a1748SDan Williams if (rc < 0 || cmd_rc) { 3101fb2a1748SDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 3102fb2a1748SDan Williams __func__, __LINE__, rc, cmd_rc); 3103fb2a1748SDan Williams return -EIO; 3104fb2a1748SDan Williams } 3105fb2a1748SDan Williams 3106*916566aeSDan Williams /* test firmware activate bus info */ 3107*916566aeSDan Williams cmd_size = sizeof(cmd.fwa_info); 3108*916566aeSDan Williams cmd = (struct nfit_ctl_test_cmd) { 3109*916566aeSDan Williams .pkg = { 3110*916566aeSDan Williams .nd_command = NVDIMM_BUS_INTEL_FW_ACTIVATE_BUSINFO, 3111*916566aeSDan Williams .nd_family = NVDIMM_BUS_FAMILY_INTEL, 3112*916566aeSDan Williams .nd_size_out = cmd_size, 3113*916566aeSDan Williams .nd_fw_size = cmd_size, 3114*916566aeSDan Williams }, 3115*916566aeSDan Williams .fwa_info = { 3116*916566aeSDan Williams .state = ND_INTEL_FWA_IDLE, 3117*916566aeSDan Williams .capability = ND_INTEL_BUS_FWA_CAP_FWQUIESCE 3118*916566aeSDan Williams | ND_INTEL_BUS_FWA_CAP_OSQUIESCE, 3119*916566aeSDan Williams .activate_tmo = 1, 3120*916566aeSDan Williams .cpu_quiesce_tmo = 1, 3121*916566aeSDan Williams .io_quiesce_tmo = 1, 3122*916566aeSDan Williams .max_quiesce_tmo = 1, 3123*916566aeSDan Williams }, 3124*916566aeSDan Williams }; 3125*916566aeSDan Williams rc = setup_result(cmd.buf, cmd_size); 3126*916566aeSDan Williams if (rc) 3127*916566aeSDan Williams return rc; 3128*916566aeSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_CALL, 3129*916566aeSDan Williams &cmd, sizeof(cmd.pkg) + cmd_size, &cmd_rc); 3130*916566aeSDan Williams if (rc < 0 || cmd_rc) { 3131*916566aeSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 3132*916566aeSDan Williams __func__, __LINE__, rc, cmd_rc); 3133*916566aeSDan Williams return -EIO; 3134*916566aeSDan Williams } 3135*916566aeSDan Williams 3136a7de92daSDan Williams return 0; 3137a7de92daSDan Williams } 3138a7de92daSDan Williams 31396bc75619SDan Williams static int nfit_test_probe(struct platform_device *pdev) 31406bc75619SDan Williams { 31416bc75619SDan Williams struct nvdimm_bus_descriptor *nd_desc; 31426bc75619SDan Williams struct acpi_nfit_desc *acpi_desc; 31436bc75619SDan Williams struct device *dev = &pdev->dev; 31446bc75619SDan Williams struct nfit_test *nfit_test; 3145231bf117SDan Williams struct nfit_mem *nfit_mem; 3146c14a868aSDan Williams union acpi_object *obj; 31476bc75619SDan Williams int rc; 31486bc75619SDan Williams 3149a7de92daSDan Williams if (strcmp(dev_name(&pdev->dev), "nfit_test.0") == 0) { 3150a7de92daSDan Williams rc = nfit_ctl_test(&pdev->dev); 3151a7de92daSDan Williams if (rc) 3152a7de92daSDan Williams return rc; 3153a7de92daSDan Williams } 3154a7de92daSDan Williams 31556bc75619SDan Williams nfit_test = to_nfit_test(&pdev->dev); 31566bc75619SDan Williams 31576bc75619SDan Williams /* common alloc */ 31586bc75619SDan Williams if (nfit_test->num_dcr) { 31596bc75619SDan Williams int num = nfit_test->num_dcr; 31606bc75619SDan Williams 31616bc75619SDan Williams nfit_test->dimm = devm_kcalloc(dev, num, sizeof(void *), 31626bc75619SDan Williams GFP_KERNEL); 31636bc75619SDan Williams nfit_test->dimm_dma = devm_kcalloc(dev, num, sizeof(dma_addr_t), 31646bc75619SDan Williams GFP_KERNEL); 31659d27a87eSDan Williams nfit_test->flush = devm_kcalloc(dev, num, sizeof(void *), 31669d27a87eSDan Williams GFP_KERNEL); 31679d27a87eSDan Williams nfit_test->flush_dma = devm_kcalloc(dev, num, sizeof(dma_addr_t), 31689d27a87eSDan Williams GFP_KERNEL); 31696bc75619SDan Williams nfit_test->label = devm_kcalloc(dev, num, sizeof(void *), 31706bc75619SDan Williams GFP_KERNEL); 31716bc75619SDan Williams nfit_test->label_dma = devm_kcalloc(dev, num, 31726bc75619SDan Williams sizeof(dma_addr_t), GFP_KERNEL); 31736bc75619SDan Williams nfit_test->dcr = devm_kcalloc(dev, num, 31746bc75619SDan Williams sizeof(struct nfit_test_dcr *), GFP_KERNEL); 31756bc75619SDan Williams nfit_test->dcr_dma = devm_kcalloc(dev, num, 31766bc75619SDan Williams sizeof(dma_addr_t), GFP_KERNEL); 3177ed07c433SDan Williams nfit_test->smart = devm_kcalloc(dev, num, 3178ed07c433SDan Williams sizeof(struct nd_intel_smart), GFP_KERNEL); 3179ed07c433SDan Williams nfit_test->smart_threshold = devm_kcalloc(dev, num, 3180ed07c433SDan Williams sizeof(struct nd_intel_smart_threshold), 3181ed07c433SDan Williams GFP_KERNEL); 3182bfbaa952SDave Jiang nfit_test->fw = devm_kcalloc(dev, num, 3183bfbaa952SDave Jiang sizeof(struct nfit_test_fw), GFP_KERNEL); 31846bc75619SDan Williams if (nfit_test->dimm && nfit_test->dimm_dma && nfit_test->label 31856bc75619SDan Williams && nfit_test->label_dma && nfit_test->dcr 31869d27a87eSDan Williams && nfit_test->dcr_dma && nfit_test->flush 3187bfbaa952SDave Jiang && nfit_test->flush_dma 3188bfbaa952SDave Jiang && nfit_test->fw) 31896bc75619SDan Williams /* pass */; 31906bc75619SDan Williams else 31916bc75619SDan Williams return -ENOMEM; 31926bc75619SDan Williams } 31936bc75619SDan Williams 31946bc75619SDan Williams if (nfit_test->num_pm) { 31956bc75619SDan Williams int num = nfit_test->num_pm; 31966bc75619SDan Williams 31976bc75619SDan Williams nfit_test->spa_set = devm_kcalloc(dev, num, sizeof(void *), 31986bc75619SDan Williams GFP_KERNEL); 31996bc75619SDan Williams nfit_test->spa_set_dma = devm_kcalloc(dev, num, 32006bc75619SDan Williams sizeof(dma_addr_t), GFP_KERNEL); 32016bc75619SDan Williams if (nfit_test->spa_set && nfit_test->spa_set_dma) 32026bc75619SDan Williams /* pass */; 32036bc75619SDan Williams else 32046bc75619SDan Williams return -ENOMEM; 32056bc75619SDan Williams } 32066bc75619SDan Williams 32076bc75619SDan Williams /* per-nfit specific alloc */ 32086bc75619SDan Williams if (nfit_test->alloc(nfit_test)) 32096bc75619SDan Williams return -ENOMEM; 32106bc75619SDan Williams 32116bc75619SDan Williams nfit_test->setup(nfit_test); 32126bc75619SDan Williams acpi_desc = &nfit_test->acpi_desc; 3213a61fe6f7SDan Williams acpi_nfit_desc_init(acpi_desc, &pdev->dev); 32146bc75619SDan Williams acpi_desc->blk_do_io = nfit_test_blk_do_io; 32156bc75619SDan Williams nd_desc = &acpi_desc->nd_desc; 3216a61fe6f7SDan Williams nd_desc->provider_name = NULL; 3217bc9775d8SDan Williams nd_desc->module = THIS_MODULE; 3218a61fe6f7SDan Williams nd_desc->ndctl = nfit_test_ctl; 32196bc75619SDan Williams 3220e7a11b44SDan Williams rc = acpi_nfit_init(acpi_desc, nfit_test->nfit_buf, 32211526f9e2SRoss Zwisler nfit_test->nfit_filled); 322258cd71b4SDan Williams if (rc) 322320985164SVishal Verma return rc; 322420985164SVishal Verma 3225fbabd829SDan Williams rc = devm_add_action_or_reset(&pdev->dev, acpi_nfit_shutdown, acpi_desc); 3226fbabd829SDan Williams if (rc) 3227fbabd829SDan Williams return rc; 3228fbabd829SDan Williams 322920985164SVishal Verma if (nfit_test->setup != nfit_test0_setup) 323020985164SVishal Verma return 0; 323120985164SVishal Verma 323220985164SVishal Verma nfit_test->setup_hotplug = 1; 323320985164SVishal Verma nfit_test->setup(nfit_test); 323420985164SVishal Verma 3235c14a868aSDan Williams obj = kzalloc(sizeof(*obj), GFP_KERNEL); 3236c14a868aSDan Williams if (!obj) 3237c14a868aSDan Williams return -ENOMEM; 3238c14a868aSDan Williams obj->type = ACPI_TYPE_BUFFER; 3239c14a868aSDan Williams obj->buffer.length = nfit_test->nfit_size; 3240c14a868aSDan Williams obj->buffer.pointer = nfit_test->nfit_buf; 3241c14a868aSDan Williams *(nfit_test->_fit) = obj; 3242c14a868aSDan Williams __acpi_nfit_notify(&pdev->dev, nfit_test, 0x80); 3243231bf117SDan Williams 3244231bf117SDan Williams /* associate dimm devices with nfit_mem data for notification testing */ 3245231bf117SDan Williams mutex_lock(&acpi_desc->init_mutex); 3246231bf117SDan Williams list_for_each_entry(nfit_mem, &acpi_desc->dimms, list) { 3247231bf117SDan Williams u32 nfit_handle = __to_nfit_memdev(nfit_mem)->device_handle; 3248231bf117SDan Williams int i; 3249231bf117SDan Williams 3250af31b04bSMasayoshi Mizuma for (i = 0; i < ARRAY_SIZE(handle); i++) 3251231bf117SDan Williams if (nfit_handle == handle[i]) 3252231bf117SDan Williams dev_set_drvdata(nfit_test->dimm_dev[i], 3253231bf117SDan Williams nfit_mem); 3254231bf117SDan Williams } 3255231bf117SDan Williams mutex_unlock(&acpi_desc->init_mutex); 32566bc75619SDan Williams 32576bc75619SDan Williams return 0; 32586bc75619SDan Williams } 32596bc75619SDan Williams 32606bc75619SDan Williams static int nfit_test_remove(struct platform_device *pdev) 32616bc75619SDan Williams { 32626bc75619SDan Williams return 0; 32636bc75619SDan Williams } 32646bc75619SDan Williams 32656bc75619SDan Williams static void nfit_test_release(struct device *dev) 32666bc75619SDan Williams { 32676bc75619SDan Williams struct nfit_test *nfit_test = to_nfit_test(dev); 32686bc75619SDan Williams 32696bc75619SDan Williams kfree(nfit_test); 32706bc75619SDan Williams } 32716bc75619SDan Williams 32726bc75619SDan Williams static const struct platform_device_id nfit_test_id[] = { 32736bc75619SDan Williams { KBUILD_MODNAME }, 32746bc75619SDan Williams { }, 32756bc75619SDan Williams }; 32766bc75619SDan Williams 32776bc75619SDan Williams static struct platform_driver nfit_test_driver = { 32786bc75619SDan Williams .probe = nfit_test_probe, 32796bc75619SDan Williams .remove = nfit_test_remove, 32806bc75619SDan Williams .driver = { 32816bc75619SDan Williams .name = KBUILD_MODNAME, 32826bc75619SDan Williams }, 32836bc75619SDan Williams .id_table = nfit_test_id, 32846bc75619SDan Williams }; 32856bc75619SDan Williams 32865d8beee2SDan Williams static char mcsafe_buf[PAGE_SIZE] __attribute__((__aligned__(PAGE_SIZE))); 32875d8beee2SDan Williams 32885d8beee2SDan Williams enum INJECT { 32895d8beee2SDan Williams INJECT_NONE, 32905d8beee2SDan Williams INJECT_SRC, 32915d8beee2SDan Williams INJECT_DST, 32925d8beee2SDan Williams }; 32935d8beee2SDan Williams 32945d8beee2SDan Williams static void mcsafe_test_init(char *dst, char *src, size_t size) 32955d8beee2SDan Williams { 32965d8beee2SDan Williams size_t i; 32975d8beee2SDan Williams 32985d8beee2SDan Williams memset(dst, 0xff, size); 32995d8beee2SDan Williams for (i = 0; i < size; i++) 33005d8beee2SDan Williams src[i] = (char) i; 33015d8beee2SDan Williams } 33025d8beee2SDan Williams 33035d8beee2SDan Williams static bool mcsafe_test_validate(unsigned char *dst, unsigned char *src, 33045d8beee2SDan Williams size_t size, unsigned long rem) 33055d8beee2SDan Williams { 33065d8beee2SDan Williams size_t i; 33075d8beee2SDan Williams 33085d8beee2SDan Williams for (i = 0; i < size - rem; i++) 33095d8beee2SDan Williams if (dst[i] != (unsigned char) i) { 33105d8beee2SDan Williams pr_info_once("%s:%d: offset: %zd got: %#x expect: %#x\n", 33115d8beee2SDan Williams __func__, __LINE__, i, dst[i], 33125d8beee2SDan Williams (unsigned char) i); 33135d8beee2SDan Williams return false; 33145d8beee2SDan Williams } 33155d8beee2SDan Williams for (i = size - rem; i < size; i++) 33165d8beee2SDan Williams if (dst[i] != 0xffU) { 33175d8beee2SDan Williams pr_info_once("%s:%d: offset: %zd got: %#x expect: 0xff\n", 33185d8beee2SDan Williams __func__, __LINE__, i, dst[i]); 33195d8beee2SDan Williams return false; 33205d8beee2SDan Williams } 33215d8beee2SDan Williams return true; 33225d8beee2SDan Williams } 33235d8beee2SDan Williams 33245d8beee2SDan Williams void mcsafe_test(void) 33255d8beee2SDan Williams { 33265d8beee2SDan Williams char *inject_desc[] = { "none", "source", "destination" }; 33275d8beee2SDan Williams enum INJECT inj; 33285d8beee2SDan Williams 33295d8beee2SDan Williams if (IS_ENABLED(CONFIG_MCSAFE_TEST)) { 33305d8beee2SDan Williams pr_info("%s: run...\n", __func__); 33315d8beee2SDan Williams } else { 33325d8beee2SDan Williams pr_info("%s: disabled, skip.\n", __func__); 33335d8beee2SDan Williams return; 33345d8beee2SDan Williams } 33355d8beee2SDan Williams 33365d8beee2SDan Williams for (inj = INJECT_NONE; inj <= INJECT_DST; inj++) { 33375d8beee2SDan Williams int i; 33385d8beee2SDan Williams 33395d8beee2SDan Williams pr_info("%s: inject: %s\n", __func__, inject_desc[inj]); 33405d8beee2SDan Williams for (i = 0; i < 512; i++) { 33415d8beee2SDan Williams unsigned long expect, rem; 33425d8beee2SDan Williams void *src, *dst; 33435d8beee2SDan Williams bool valid; 33445d8beee2SDan Williams 33455d8beee2SDan Williams switch (inj) { 33465d8beee2SDan Williams case INJECT_NONE: 33475d8beee2SDan Williams mcsafe_inject_src(NULL); 33485d8beee2SDan Williams mcsafe_inject_dst(NULL); 33495d8beee2SDan Williams dst = &mcsafe_buf[2048]; 33505d8beee2SDan Williams src = &mcsafe_buf[1024 - i]; 33515d8beee2SDan Williams expect = 0; 33525d8beee2SDan Williams break; 33535d8beee2SDan Williams case INJECT_SRC: 33545d8beee2SDan Williams mcsafe_inject_src(&mcsafe_buf[1024]); 33555d8beee2SDan Williams mcsafe_inject_dst(NULL); 33565d8beee2SDan Williams dst = &mcsafe_buf[2048]; 33575d8beee2SDan Williams src = &mcsafe_buf[1024 - i]; 33585d8beee2SDan Williams expect = 512 - i; 33595d8beee2SDan Williams break; 33605d8beee2SDan Williams case INJECT_DST: 33615d8beee2SDan Williams mcsafe_inject_src(NULL); 33625d8beee2SDan Williams mcsafe_inject_dst(&mcsafe_buf[2048]); 33635d8beee2SDan Williams dst = &mcsafe_buf[2048 - i]; 33645d8beee2SDan Williams src = &mcsafe_buf[1024]; 33655d8beee2SDan Williams expect = 512 - i; 33665d8beee2SDan Williams break; 33675d8beee2SDan Williams } 33685d8beee2SDan Williams 33695d8beee2SDan Williams mcsafe_test_init(dst, src, 512); 33705d8beee2SDan Williams rem = __memcpy_mcsafe(dst, src, 512); 33715d8beee2SDan Williams valid = mcsafe_test_validate(dst, src, 512, expect); 33725d8beee2SDan Williams if (rem == expect && valid) 33735d8beee2SDan Williams continue; 33745d8beee2SDan Williams pr_info("%s: copy(%#lx, %#lx, %d) off: %d rem: %ld %s expect: %ld\n", 33755d8beee2SDan Williams __func__, 33765d8beee2SDan Williams ((unsigned long) dst) & ~PAGE_MASK, 33775d8beee2SDan Williams ((unsigned long ) src) & ~PAGE_MASK, 33785d8beee2SDan Williams 512, i, rem, valid ? "valid" : "bad", 33795d8beee2SDan Williams expect); 33805d8beee2SDan Williams } 33815d8beee2SDan Williams } 33825d8beee2SDan Williams 33835d8beee2SDan Williams mcsafe_inject_src(NULL); 33845d8beee2SDan Williams mcsafe_inject_dst(NULL); 33855d8beee2SDan Williams } 33865d8beee2SDan Williams 33876bc75619SDan Williams static __init int nfit_test_init(void) 33886bc75619SDan Williams { 33896bc75619SDan Williams int rc, i; 33906bc75619SDan Williams 33910fb5c8dfSDan Williams pmem_test(); 33920fb5c8dfSDan Williams libnvdimm_test(); 33930fb5c8dfSDan Williams acpi_nfit_test(); 33940fb5c8dfSDan Williams device_dax_test(); 33955d8beee2SDan Williams mcsafe_test(); 339692f6f2d7SVishal Verma dax_pmem_test(); 339792f6f2d7SVishal Verma dax_pmem_core_test(); 3398c0e71d60SJan Kara #ifdef CONFIG_DEV_DAX_PMEM_COMPAT 339992f6f2d7SVishal Verma dax_pmem_compat_test(); 3400c0e71d60SJan Kara #endif 34010fb5c8dfSDan Williams 3402a7de92daSDan Williams nfit_test_setup(nfit_test_lookup, nfit_test_evaluate_dsm); 3403231bf117SDan Williams 34049fb1a190SDave Jiang nfit_wq = create_singlethread_workqueue("nfit"); 34059fb1a190SDave Jiang if (!nfit_wq) 34069fb1a190SDave Jiang return -ENOMEM; 34079fb1a190SDave Jiang 3408a7de92daSDan Williams nfit_test_dimm = class_create(THIS_MODULE, "nfit_test_dimm"); 3409a7de92daSDan Williams if (IS_ERR(nfit_test_dimm)) { 3410a7de92daSDan Williams rc = PTR_ERR(nfit_test_dimm); 3411a7de92daSDan Williams goto err_register; 3412a7de92daSDan Williams } 34136bc75619SDan Williams 3414e3f5df76SDan Williams nfit_pool = gen_pool_create(ilog2(SZ_4M), NUMA_NO_NODE); 3415e3f5df76SDan Williams if (!nfit_pool) { 3416e3f5df76SDan Williams rc = -ENOMEM; 3417e3f5df76SDan Williams goto err_register; 3418e3f5df76SDan Williams } 3419e3f5df76SDan Williams 3420e3f5df76SDan Williams if (gen_pool_add(nfit_pool, SZ_4G, SZ_4G, NUMA_NO_NODE)) { 3421e3f5df76SDan Williams rc = -ENOMEM; 3422e3f5df76SDan Williams goto err_register; 3423e3f5df76SDan Williams } 3424e3f5df76SDan Williams 34256bc75619SDan Williams for (i = 0; i < NUM_NFITS; i++) { 34266bc75619SDan Williams struct nfit_test *nfit_test; 34276bc75619SDan Williams struct platform_device *pdev; 34286bc75619SDan Williams 34296bc75619SDan Williams nfit_test = kzalloc(sizeof(*nfit_test), GFP_KERNEL); 34306bc75619SDan Williams if (!nfit_test) { 34316bc75619SDan Williams rc = -ENOMEM; 34326bc75619SDan Williams goto err_register; 34336bc75619SDan Williams } 34346bc75619SDan Williams INIT_LIST_HEAD(&nfit_test->resources); 34359fb1a190SDave Jiang badrange_init(&nfit_test->badrange); 34366bc75619SDan Williams switch (i) { 34376bc75619SDan Williams case 0: 34386bc75619SDan Williams nfit_test->num_pm = NUM_PM; 3439dafb1048SDan Williams nfit_test->dcr_idx = 0; 34406bc75619SDan Williams nfit_test->num_dcr = NUM_DCR; 34416bc75619SDan Williams nfit_test->alloc = nfit_test0_alloc; 34426bc75619SDan Williams nfit_test->setup = nfit_test0_setup; 34436bc75619SDan Williams break; 34446bc75619SDan Williams case 1: 3445a117699cSYasunori Goto nfit_test->num_pm = 2; 3446dafb1048SDan Williams nfit_test->dcr_idx = NUM_DCR; 3447ac40b675SDan Williams nfit_test->num_dcr = 2; 34486bc75619SDan Williams nfit_test->alloc = nfit_test1_alloc; 34496bc75619SDan Williams nfit_test->setup = nfit_test1_setup; 34506bc75619SDan Williams break; 34516bc75619SDan Williams default: 34526bc75619SDan Williams rc = -EINVAL; 34536bc75619SDan Williams goto err_register; 34546bc75619SDan Williams } 34556bc75619SDan Williams pdev = &nfit_test->pdev; 34566bc75619SDan Williams pdev->name = KBUILD_MODNAME; 34576bc75619SDan Williams pdev->id = i; 34586bc75619SDan Williams pdev->dev.release = nfit_test_release; 34596bc75619SDan Williams rc = platform_device_register(pdev); 34606bc75619SDan Williams if (rc) { 34616bc75619SDan Williams put_device(&pdev->dev); 34626bc75619SDan Williams goto err_register; 34636bc75619SDan Williams } 34648b06b884SDan Williams get_device(&pdev->dev); 34656bc75619SDan Williams 34666bc75619SDan Williams rc = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); 34676bc75619SDan Williams if (rc) 34686bc75619SDan Williams goto err_register; 34696bc75619SDan Williams 34706bc75619SDan Williams instances[i] = nfit_test; 34719fb1a190SDave Jiang INIT_WORK(&nfit_test->work, uc_error_notify); 34726bc75619SDan Williams } 34736bc75619SDan Williams 34746bc75619SDan Williams rc = platform_driver_register(&nfit_test_driver); 34756bc75619SDan Williams if (rc) 34766bc75619SDan Williams goto err_register; 34776bc75619SDan Williams return 0; 34786bc75619SDan Williams 34796bc75619SDan Williams err_register: 3480e3f5df76SDan Williams if (nfit_pool) 3481e3f5df76SDan Williams gen_pool_destroy(nfit_pool); 3482e3f5df76SDan Williams 34839fb1a190SDave Jiang destroy_workqueue(nfit_wq); 34846bc75619SDan Williams for (i = 0; i < NUM_NFITS; i++) 34856bc75619SDan Williams if (instances[i]) 34866bc75619SDan Williams platform_device_unregister(&instances[i]->pdev); 34876bc75619SDan Williams nfit_test_teardown(); 34888b06b884SDan Williams for (i = 0; i < NUM_NFITS; i++) 34898b06b884SDan Williams if (instances[i]) 34908b06b884SDan Williams put_device(&instances[i]->pdev.dev); 34918b06b884SDan Williams 34926bc75619SDan Williams return rc; 34936bc75619SDan Williams } 34946bc75619SDan Williams 34956bc75619SDan Williams static __exit void nfit_test_exit(void) 34966bc75619SDan Williams { 34976bc75619SDan Williams int i; 34986bc75619SDan Williams 34999fb1a190SDave Jiang flush_workqueue(nfit_wq); 35009fb1a190SDave Jiang destroy_workqueue(nfit_wq); 35016bc75619SDan Williams for (i = 0; i < NUM_NFITS; i++) 35026bc75619SDan Williams platform_device_unregister(&instances[i]->pdev); 35038b06b884SDan Williams platform_driver_unregister(&nfit_test_driver); 35046bc75619SDan Williams nfit_test_teardown(); 35058b06b884SDan Williams 3506e3f5df76SDan Williams gen_pool_destroy(nfit_pool); 3507e3f5df76SDan Williams 35088b06b884SDan Williams for (i = 0; i < NUM_NFITS; i++) 35098b06b884SDan Williams put_device(&instances[i]->pdev.dev); 3510231bf117SDan Williams class_destroy(nfit_test_dimm); 35116bc75619SDan Williams } 35126bc75619SDan Williams 35136bc75619SDan Williams module_init(nfit_test_init); 35146bc75619SDan Williams module_exit(nfit_test_exit); 35156bc75619SDan Williams MODULE_LICENSE("GPL v2"); 35166bc75619SDan Williams MODULE_AUTHOR("Intel Corporation"); 3517