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 26ec6347bbSDan Williams #include <asm/mce.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; 176916566aeSDan Williams bool armed; 177916566aeSDan Williams bool missed_activate; 178916566aeSDan 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) { 351916566aeSDan 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; 436916566aeSDan Williams fw->missed_activate = false; 437*f21453b0SDan Williams fallthrough; 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 1185916566aeSDan Williams static unsigned long last_activate; 1186916566aeSDan Williams 1187916566aeSDan Williams static int nvdimm_bus_intel_fw_activate_businfo(struct nfit_test *t, 1188916566aeSDan Williams struct nd_intel_bus_fw_activate_businfo *nd_cmd, 1189916566aeSDan Williams unsigned int buf_len) 1190916566aeSDan Williams { 1191916566aeSDan Williams int i, armed = 0; 1192916566aeSDan Williams int state; 1193916566aeSDan Williams u64 tmo; 1194916566aeSDan Williams 1195916566aeSDan Williams for (i = 0; i < NUM_DCR; i++) { 1196916566aeSDan Williams struct nfit_test_fw *fw = &t->fw[i]; 1197916566aeSDan Williams 1198916566aeSDan Williams if (fw->armed) 1199916566aeSDan Williams armed++; 1200916566aeSDan Williams } 1201916566aeSDan Williams 1202916566aeSDan Williams /* 1203916566aeSDan Williams * Emulate 3 second activation max, and 1 second incremental 1204916566aeSDan Williams * quiesce time per dimm requiring multiple activates to get all 1205916566aeSDan Williams * DIMMs updated. 1206916566aeSDan Williams */ 1207916566aeSDan Williams if (armed) 1208916566aeSDan Williams state = ND_INTEL_FWA_ARMED; 1209916566aeSDan Williams else if (!last_activate || time_after(jiffies, last_activate + 3 * HZ)) 1210916566aeSDan Williams state = ND_INTEL_FWA_IDLE; 1211916566aeSDan Williams else 1212916566aeSDan Williams state = ND_INTEL_FWA_BUSY; 1213916566aeSDan Williams 1214916566aeSDan Williams tmo = armed * USEC_PER_SEC; 1215916566aeSDan Williams *nd_cmd = (struct nd_intel_bus_fw_activate_businfo) { 1216916566aeSDan Williams .capability = ND_INTEL_BUS_FWA_CAP_FWQUIESCE 1217916566aeSDan Williams | ND_INTEL_BUS_FWA_CAP_OSQUIESCE 1218916566aeSDan Williams | ND_INTEL_BUS_FWA_CAP_RESET, 1219916566aeSDan Williams .state = state, 1220916566aeSDan Williams .activate_tmo = tmo, 1221916566aeSDan Williams .cpu_quiesce_tmo = tmo, 1222916566aeSDan Williams .io_quiesce_tmo = tmo, 1223916566aeSDan Williams .max_quiesce_tmo = 3 * USEC_PER_SEC, 1224916566aeSDan Williams }; 1225916566aeSDan Williams 1226916566aeSDan Williams return 0; 1227916566aeSDan Williams } 1228916566aeSDan Williams 1229916566aeSDan Williams static int nvdimm_bus_intel_fw_activate(struct nfit_test *t, 1230916566aeSDan Williams struct nd_intel_bus_fw_activate *nd_cmd, 1231916566aeSDan Williams unsigned int buf_len) 1232916566aeSDan Williams { 1233916566aeSDan Williams struct nd_intel_bus_fw_activate_businfo info; 1234916566aeSDan Williams u32 status = 0; 1235916566aeSDan Williams int i; 1236916566aeSDan Williams 1237916566aeSDan Williams nvdimm_bus_intel_fw_activate_businfo(t, &info, sizeof(info)); 1238916566aeSDan Williams if (info.state == ND_INTEL_FWA_BUSY) 1239916566aeSDan Williams status = ND_INTEL_BUS_FWA_STATUS_BUSY; 1240916566aeSDan Williams else if (info.activate_tmo > info.max_quiesce_tmo) 1241916566aeSDan Williams status = ND_INTEL_BUS_FWA_STATUS_TMO; 1242916566aeSDan Williams else if (info.state == ND_INTEL_FWA_IDLE) 1243916566aeSDan Williams status = ND_INTEL_BUS_FWA_STATUS_NOARM; 1244916566aeSDan Williams 1245916566aeSDan Williams dev_dbg(&t->pdev.dev, "status: %d\n", status); 1246916566aeSDan Williams nd_cmd->status = status; 1247916566aeSDan Williams if (status && status != ND_INTEL_BUS_FWA_STATUS_TMO) 1248916566aeSDan Williams return 0; 1249916566aeSDan Williams 1250916566aeSDan Williams last_activate = jiffies; 1251916566aeSDan Williams for (i = 0; i < NUM_DCR; i++) { 1252916566aeSDan Williams struct nfit_test_fw *fw = &t->fw[i]; 1253916566aeSDan Williams 1254916566aeSDan Williams if (!fw->armed) 1255916566aeSDan Williams continue; 1256916566aeSDan Williams if (fw->state != FW_STATE_UPDATED) 1257916566aeSDan Williams fw->missed_activate = true; 1258916566aeSDan Williams else 1259916566aeSDan Williams fw->state = FW_STATE_NEW; 1260916566aeSDan Williams fw->armed = false; 1261916566aeSDan Williams fw->last_activate = last_activate; 1262916566aeSDan Williams } 1263916566aeSDan Williams 1264916566aeSDan Williams return 0; 1265916566aeSDan Williams } 1266916566aeSDan Williams 1267916566aeSDan Williams static int nd_intel_test_cmd_fw_activate_dimminfo(struct nfit_test *t, 1268916566aeSDan Williams struct nd_intel_fw_activate_dimminfo *nd_cmd, 1269916566aeSDan Williams unsigned int buf_len, int dimm) 1270916566aeSDan Williams { 1271916566aeSDan Williams struct nd_intel_bus_fw_activate_businfo info; 1272916566aeSDan Williams struct nfit_test_fw *fw = &t->fw[dimm]; 1273916566aeSDan Williams u32 result, state; 1274916566aeSDan Williams 1275916566aeSDan Williams nvdimm_bus_intel_fw_activate_businfo(t, &info, sizeof(info)); 1276916566aeSDan Williams 1277916566aeSDan Williams if (info.state == ND_INTEL_FWA_BUSY) 1278916566aeSDan Williams state = ND_INTEL_FWA_BUSY; 1279916566aeSDan Williams else if (info.state == ND_INTEL_FWA_IDLE) 1280916566aeSDan Williams state = ND_INTEL_FWA_IDLE; 1281916566aeSDan Williams else if (fw->armed) 1282916566aeSDan Williams state = ND_INTEL_FWA_ARMED; 1283916566aeSDan Williams else 1284916566aeSDan Williams state = ND_INTEL_FWA_IDLE; 1285916566aeSDan Williams 1286916566aeSDan Williams result = ND_INTEL_DIMM_FWA_NONE; 1287916566aeSDan Williams if (last_activate && fw->last_activate == last_activate && 1288916566aeSDan Williams state == ND_INTEL_FWA_IDLE) { 1289916566aeSDan Williams if (fw->missed_activate) 1290916566aeSDan Williams result = ND_INTEL_DIMM_FWA_NOTSTAGED; 1291916566aeSDan Williams else 1292916566aeSDan Williams result = ND_INTEL_DIMM_FWA_SUCCESS; 1293916566aeSDan Williams } 1294916566aeSDan Williams 1295916566aeSDan Williams *nd_cmd = (struct nd_intel_fw_activate_dimminfo) { 1296916566aeSDan Williams .result = result, 1297916566aeSDan Williams .state = state, 1298916566aeSDan Williams }; 1299916566aeSDan Williams 1300916566aeSDan Williams return 0; 1301916566aeSDan Williams } 1302916566aeSDan Williams 1303916566aeSDan Williams static int nd_intel_test_cmd_fw_activate_arm(struct nfit_test *t, 1304916566aeSDan Williams struct nd_intel_fw_activate_arm *nd_cmd, 1305916566aeSDan Williams unsigned int buf_len, int dimm) 1306916566aeSDan Williams { 1307916566aeSDan Williams struct nfit_test_fw *fw = &t->fw[dimm]; 1308916566aeSDan Williams 1309916566aeSDan Williams fw->armed = nd_cmd->activate_arm == ND_INTEL_DIMM_FWA_ARM; 1310916566aeSDan Williams nd_cmd->status = 0; 1311916566aeSDan Williams return 0; 1312916566aeSDan 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; 1431916566aeSDan Williams case NVDIMM_INTEL_FW_ACTIVATE_DIMMINFO: 1432916566aeSDan Williams rc = nd_intel_test_cmd_fw_activate_dimminfo( 1433916566aeSDan Williams t, buf, buf_len, i); 1434916566aeSDan Williams break; 1435916566aeSDan Williams case NVDIMM_INTEL_FW_ACTIVATE_ARM: 1436916566aeSDan Williams rc = nd_intel_test_cmd_fw_activate_arm( 1437916566aeSDan Williams t, buf, buf_len, i); 1438916566aeSDan 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 1523916566aeSDan Williams if (cmd == ND_CMD_CALL && call_pkg->nd_family 1524916566aeSDan 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 } 1549916566aeSDan Williams } else if (cmd == ND_CMD_CALL && call_pkg->nd_family 1550916566aeSDan Williams == NVDIMM_BUS_FAMILY_INTEL) { 1551916566aeSDan Williams func = call_pkg->nd_command; 1552916566aeSDan Williams buf_len = call_pkg->nd_size_in + call_pkg->nd_size_out; 1553916566aeSDan Williams buf = (void *) call_pkg->nd_payload; 1554916566aeSDan Williams 1555916566aeSDan Williams switch (func) { 1556916566aeSDan Williams case NVDIMM_BUS_INTEL_FW_ACTIVATE_BUSINFO: 1557916566aeSDan Williams rc = nvdimm_bus_intel_fw_activate_businfo(t, 1558916566aeSDan Williams buf, buf_len); 1559916566aeSDan Williams return rc; 1560916566aeSDan Williams case NVDIMM_BUS_INTEL_FW_ACTIVATE: 1561916566aeSDan Williams rc = nvdimm_bus_intel_fw_activate(t, buf, 1562916566aeSDan Williams buf_len); 1563916566aeSDan Williams return rc; 1564916566aeSDan Williams default: 1565916566aeSDan Williams return -ENOTTY; 156610246dc8SYasunori Goto } 1567916566aeSDan Williams } else if (cmd == ND_CMD_CALL) 1568916566aeSDan 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 1874e9cfd259SDan Williams static size_t sizeof_spa(struct acpi_nfit_system_address *spa) 1875e9cfd259SDan Williams { 1876e9cfd259SDan Williams /* until spa location cookie support is added... */ 1877e9cfd259SDan Williams return sizeof(*spa) - 8; 1878e9cfd259SDan Williams } 1879e9cfd259SDan Williams 18806bc75619SDan Williams static int nfit_test0_alloc(struct nfit_test *t) 18816bc75619SDan Williams { 1882e9cfd259SDan Williams struct acpi_nfit_system_address *spa = NULL; 1883e9cfd259SDan Williams size_t nfit_size = sizeof_spa(spa) * NUM_SPA 18846bc75619SDan Williams + sizeof(struct acpi_nfit_memory_map) * NUM_MEM 18856bc75619SDan Williams + sizeof(struct acpi_nfit_control_region) * NUM_DCR 18863b87356fSDan Williams + offsetof(struct acpi_nfit_control_region, 18873b87356fSDan Williams window_size) * NUM_DCR 18889d27a87eSDan Williams + sizeof(struct acpi_nfit_data_region) * NUM_BDW 188985d3fa02SDan Williams + (sizeof(struct acpi_nfit_flush_address) 1890f81e1d35SDave Jiang + sizeof(u64) * NUM_HINTS) * NUM_DCR 1891f81e1d35SDave Jiang + sizeof(struct acpi_nfit_capabilities); 18926bc75619SDan Williams int i; 18936bc75619SDan Williams 18946bc75619SDan Williams t->nfit_buf = test_alloc(t, nfit_size, &t->nfit_dma); 18956bc75619SDan Williams if (!t->nfit_buf) 18966bc75619SDan Williams return -ENOMEM; 18976bc75619SDan Williams t->nfit_size = nfit_size; 18986bc75619SDan Williams 1899ee8520feSDan Williams t->spa_set[0] = test_alloc(t, SPA0_SIZE, &t->spa_set_dma[0]); 19006bc75619SDan Williams if (!t->spa_set[0]) 19016bc75619SDan Williams return -ENOMEM; 19026bc75619SDan Williams 1903ee8520feSDan Williams t->spa_set[1] = test_alloc(t, SPA1_SIZE, &t->spa_set_dma[1]); 19046bc75619SDan Williams if (!t->spa_set[1]) 19056bc75619SDan Williams return -ENOMEM; 19066bc75619SDan Williams 1907ee8520feSDan Williams t->spa_set[2] = test_alloc(t, SPA0_SIZE, &t->spa_set_dma[2]); 190820985164SVishal Verma if (!t->spa_set[2]) 190920985164SVishal Verma return -ENOMEM; 191020985164SVishal Verma 1911dafb1048SDan Williams for (i = 0; i < t->num_dcr; i++) { 19126bc75619SDan Williams t->dimm[i] = test_alloc(t, DIMM_SIZE, &t->dimm_dma[i]); 19136bc75619SDan Williams if (!t->dimm[i]) 19146bc75619SDan Williams return -ENOMEM; 19156bc75619SDan Williams 19166bc75619SDan Williams t->label[i] = test_alloc(t, LABEL_SIZE, &t->label_dma[i]); 19176bc75619SDan Williams if (!t->label[i]) 19186bc75619SDan Williams return -ENOMEM; 19196bc75619SDan Williams sprintf(t->label[i], "label%d", i); 19209d27a87eSDan Williams 19219d15ce9cSDan Williams t->flush[i] = test_alloc(t, max(PAGE_SIZE, 19229d15ce9cSDan Williams sizeof(u64) * NUM_HINTS), 192385d3fa02SDan Williams &t->flush_dma[i]); 19249d27a87eSDan Williams if (!t->flush[i]) 19259d27a87eSDan Williams return -ENOMEM; 19266bc75619SDan Williams } 19276bc75619SDan Williams 1928dafb1048SDan Williams for (i = 0; i < t->num_dcr; i++) { 19296bc75619SDan Williams t->dcr[i] = test_alloc(t, LABEL_SIZE, &t->dcr_dma[i]); 19306bc75619SDan Williams if (!t->dcr[i]) 19316bc75619SDan Williams return -ENOMEM; 19326bc75619SDan Williams } 19336bc75619SDan Williams 1934c14a868aSDan Williams t->_fit = test_alloc(t, sizeof(union acpi_object **), &t->_fit_dma); 1935c14a868aSDan Williams if (!t->_fit) 1936c14a868aSDan Williams return -ENOMEM; 1937c14a868aSDan Williams 1938718fda67SDan Williams if (nfit_test_dimm_init(t)) 1939231bf117SDan Williams return -ENOMEM; 1940ed07c433SDan Williams smart_init(t); 1941ecaa4a97SDave Jiang security_init(t); 1942f471f1a7SDan Williams return ars_state_init(&t->pdev.dev, &t->ars_state); 19436bc75619SDan Williams } 19446bc75619SDan Williams 19456bc75619SDan Williams static int nfit_test1_alloc(struct nfit_test *t) 19466bc75619SDan Williams { 1947e9cfd259SDan Williams struct acpi_nfit_system_address *spa = NULL; 1948e9cfd259SDan Williams size_t nfit_size = sizeof_spa(spa) * 2 1949ac40b675SDan Williams + sizeof(struct acpi_nfit_memory_map) * 2 1950ac40b675SDan Williams + offsetof(struct acpi_nfit_control_region, window_size) * 2; 1951dafb1048SDan Williams int i; 19526bc75619SDan Williams 19536bc75619SDan Williams t->nfit_buf = test_alloc(t, nfit_size, &t->nfit_dma); 19546bc75619SDan Williams if (!t->nfit_buf) 19556bc75619SDan Williams return -ENOMEM; 19566bc75619SDan Williams t->nfit_size = nfit_size; 19576bc75619SDan Williams 1958ee8520feSDan Williams t->spa_set[0] = test_alloc(t, SPA2_SIZE, &t->spa_set_dma[0]); 19596bc75619SDan Williams if (!t->spa_set[0]) 19606bc75619SDan Williams return -ENOMEM; 19616bc75619SDan Williams 1962dafb1048SDan Williams for (i = 0; i < t->num_dcr; i++) { 1963dafb1048SDan Williams t->label[i] = test_alloc(t, LABEL_SIZE, &t->label_dma[i]); 1964dafb1048SDan Williams if (!t->label[i]) 1965dafb1048SDan Williams return -ENOMEM; 1966dafb1048SDan Williams sprintf(t->label[i], "label%d", i); 1967dafb1048SDan Williams } 1968dafb1048SDan Williams 19697bfe97c7SDan Williams t->spa_set[1] = test_alloc(t, SPA_VCD_SIZE, &t->spa_set_dma[1]); 19707bfe97c7SDan Williams if (!t->spa_set[1]) 19717bfe97c7SDan Williams return -ENOMEM; 19727bfe97c7SDan Williams 1973718fda67SDan Williams if (nfit_test_dimm_init(t)) 1974718fda67SDan Williams return -ENOMEM; 1975ed07c433SDan Williams smart_init(t); 1976f471f1a7SDan Williams return ars_state_init(&t->pdev.dev, &t->ars_state); 19776bc75619SDan Williams } 19786bc75619SDan Williams 19795dc68e55SDan Williams static void dcr_common_init(struct acpi_nfit_control_region *dcr) 19805dc68e55SDan Williams { 19815dc68e55SDan Williams dcr->vendor_id = 0xabcd; 19825dc68e55SDan Williams dcr->device_id = 0; 19835dc68e55SDan Williams dcr->revision_id = 1; 19845dc68e55SDan Williams dcr->valid_fields = 1; 19855dc68e55SDan Williams dcr->manufacturing_location = 0xa; 19865dc68e55SDan Williams dcr->manufacturing_date = cpu_to_be16(2016); 19875dc68e55SDan Williams } 19885dc68e55SDan Williams 19896bc75619SDan Williams static void nfit_test0_setup(struct nfit_test *t) 19906bc75619SDan Williams { 199185d3fa02SDan Williams const int flush_hint_size = sizeof(struct acpi_nfit_flush_address) 199285d3fa02SDan Williams + (sizeof(u64) * NUM_HINTS); 19936bc75619SDan Williams struct acpi_nfit_desc *acpi_desc; 19946bc75619SDan Williams struct acpi_nfit_memory_map *memdev; 19956bc75619SDan Williams void *nfit_buf = t->nfit_buf; 19966bc75619SDan Williams struct acpi_nfit_system_address *spa; 19976bc75619SDan Williams struct acpi_nfit_control_region *dcr; 19986bc75619SDan Williams struct acpi_nfit_data_region *bdw; 19999d27a87eSDan Williams struct acpi_nfit_flush_address *flush; 2000f81e1d35SDave Jiang struct acpi_nfit_capabilities *pcap; 2001d7d8464dSRoss Zwisler unsigned int offset = 0, i; 2002916566aeSDan Williams unsigned long *acpi_mask; 20036bc75619SDan Williams 20046bc75619SDan Williams /* 20056bc75619SDan Williams * spa0 (interleave first half of dimm0 and dimm1, note storage 20066bc75619SDan Williams * does not actually alias the related block-data-window 20076bc75619SDan Williams * regions) 20086bc75619SDan Williams */ 20096b577c9dSLinda Knippers spa = nfit_buf; 20106bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 2011e9cfd259SDan Williams spa->header.length = sizeof_spa(spa); 20126bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 20136bc75619SDan Williams spa->range_index = 0+1; 20146bc75619SDan Williams spa->address = t->spa_set_dma[0]; 20156bc75619SDan Williams spa->length = SPA0_SIZE; 2016d7d8464dSRoss Zwisler offset += spa->header.length; 20176bc75619SDan Williams 20186bc75619SDan Williams /* 20196bc75619SDan Williams * spa1 (interleave last half of the 4 DIMMS, note storage 20206bc75619SDan Williams * does not actually alias the related block-data-window 20216bc75619SDan Williams * regions) 20226bc75619SDan Williams */ 2023d7d8464dSRoss Zwisler spa = nfit_buf + offset; 20246bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 2025e9cfd259SDan Williams spa->header.length = sizeof_spa(spa); 20266bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 20276bc75619SDan Williams spa->range_index = 1+1; 20286bc75619SDan Williams spa->address = t->spa_set_dma[1]; 20296bc75619SDan Williams spa->length = SPA1_SIZE; 2030d7d8464dSRoss Zwisler offset += spa->header.length; 20316bc75619SDan Williams 20326bc75619SDan Williams /* spa2 (dcr0) dimm0 */ 2033d7d8464dSRoss Zwisler spa = nfit_buf + offset; 20346bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 2035e9cfd259SDan Williams spa->header.length = sizeof_spa(spa); 20366bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 20376bc75619SDan Williams spa->range_index = 2+1; 20386bc75619SDan Williams spa->address = t->dcr_dma[0]; 20396bc75619SDan Williams spa->length = DCR_SIZE; 2040d7d8464dSRoss Zwisler offset += spa->header.length; 20416bc75619SDan Williams 20426bc75619SDan Williams /* spa3 (dcr1) dimm1 */ 2043d7d8464dSRoss Zwisler spa = nfit_buf + offset; 20446bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 2045e9cfd259SDan Williams spa->header.length = sizeof_spa(spa); 20466bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 20476bc75619SDan Williams spa->range_index = 3+1; 20486bc75619SDan Williams spa->address = t->dcr_dma[1]; 20496bc75619SDan Williams spa->length = DCR_SIZE; 2050d7d8464dSRoss Zwisler offset += spa->header.length; 20516bc75619SDan Williams 20526bc75619SDan Williams /* spa4 (dcr2) dimm2 */ 2053d7d8464dSRoss Zwisler spa = nfit_buf + offset; 20546bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 2055e9cfd259SDan Williams spa->header.length = sizeof_spa(spa); 20566bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 20576bc75619SDan Williams spa->range_index = 4+1; 20586bc75619SDan Williams spa->address = t->dcr_dma[2]; 20596bc75619SDan Williams spa->length = DCR_SIZE; 2060d7d8464dSRoss Zwisler offset += spa->header.length; 20616bc75619SDan Williams 20626bc75619SDan Williams /* spa5 (dcr3) dimm3 */ 2063d7d8464dSRoss Zwisler spa = nfit_buf + offset; 20646bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 2065e9cfd259SDan Williams spa->header.length = sizeof_spa(spa); 20666bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 20676bc75619SDan Williams spa->range_index = 5+1; 20686bc75619SDan Williams spa->address = t->dcr_dma[3]; 20696bc75619SDan Williams spa->length = DCR_SIZE; 2070d7d8464dSRoss Zwisler offset += spa->header.length; 20716bc75619SDan Williams 20726bc75619SDan Williams /* spa6 (bdw for dcr0) dimm0 */ 2073d7d8464dSRoss Zwisler spa = nfit_buf + offset; 20746bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 2075e9cfd259SDan Williams spa->header.length = sizeof_spa(spa); 20766bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 20776bc75619SDan Williams spa->range_index = 6+1; 20786bc75619SDan Williams spa->address = t->dimm_dma[0]; 20796bc75619SDan Williams spa->length = DIMM_SIZE; 2080d7d8464dSRoss Zwisler offset += spa->header.length; 20816bc75619SDan Williams 20826bc75619SDan Williams /* spa7 (bdw for dcr1) dimm1 */ 2083d7d8464dSRoss Zwisler spa = nfit_buf + offset; 20846bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 2085e9cfd259SDan Williams spa->header.length = sizeof_spa(spa); 20866bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 20876bc75619SDan Williams spa->range_index = 7+1; 20886bc75619SDan Williams spa->address = t->dimm_dma[1]; 20896bc75619SDan Williams spa->length = DIMM_SIZE; 2090d7d8464dSRoss Zwisler offset += spa->header.length; 20916bc75619SDan Williams 20926bc75619SDan Williams /* spa8 (bdw for dcr2) dimm2 */ 2093d7d8464dSRoss Zwisler spa = nfit_buf + offset; 20946bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 2095e9cfd259SDan Williams spa->header.length = sizeof_spa(spa); 20966bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 20976bc75619SDan Williams spa->range_index = 8+1; 20986bc75619SDan Williams spa->address = t->dimm_dma[2]; 20996bc75619SDan Williams spa->length = DIMM_SIZE; 2100d7d8464dSRoss Zwisler offset += spa->header.length; 21016bc75619SDan Williams 21026bc75619SDan Williams /* spa9 (bdw for dcr3) dimm3 */ 2103d7d8464dSRoss Zwisler spa = nfit_buf + offset; 21046bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 2105e9cfd259SDan Williams spa->header.length = sizeof_spa(spa); 21066bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 21076bc75619SDan Williams spa->range_index = 9+1; 21086bc75619SDan Williams spa->address = t->dimm_dma[3]; 21096bc75619SDan Williams spa->length = DIMM_SIZE; 2110d7d8464dSRoss Zwisler offset += spa->header.length; 21116bc75619SDan Williams 21126bc75619SDan Williams /* mem-region0 (spa0, dimm0) */ 21136bc75619SDan Williams memdev = nfit_buf + offset; 21146bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 21156bc75619SDan Williams memdev->header.length = sizeof(*memdev); 21166bc75619SDan Williams memdev->device_handle = handle[0]; 21176bc75619SDan Williams memdev->physical_id = 0; 21186bc75619SDan Williams memdev->region_id = 0; 21196bc75619SDan Williams memdev->range_index = 0+1; 21203b87356fSDan Williams memdev->region_index = 4+1; 21216bc75619SDan Williams memdev->region_size = SPA0_SIZE/2; 2122df06a2d5SDan Williams memdev->region_offset = 1; 21236bc75619SDan Williams memdev->address = 0; 21246bc75619SDan Williams memdev->interleave_index = 0; 21256bc75619SDan Williams memdev->interleave_ways = 2; 2126d7d8464dSRoss Zwisler offset += memdev->header.length; 21276bc75619SDan Williams 21286bc75619SDan Williams /* mem-region1 (spa0, dimm1) */ 2129d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 21306bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 21316bc75619SDan Williams memdev->header.length = sizeof(*memdev); 21326bc75619SDan Williams memdev->device_handle = handle[1]; 21336bc75619SDan Williams memdev->physical_id = 1; 21346bc75619SDan Williams memdev->region_id = 0; 21356bc75619SDan Williams memdev->range_index = 0+1; 21363b87356fSDan Williams memdev->region_index = 5+1; 21376bc75619SDan Williams memdev->region_size = SPA0_SIZE/2; 2138df06a2d5SDan Williams memdev->region_offset = (1 << 8); 21396bc75619SDan Williams memdev->address = 0; 21406bc75619SDan Williams memdev->interleave_index = 0; 21416bc75619SDan Williams memdev->interleave_ways = 2; 2142ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED; 2143d7d8464dSRoss Zwisler offset += memdev->header.length; 21446bc75619SDan Williams 21456bc75619SDan Williams /* mem-region2 (spa1, dimm0) */ 2146d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 21476bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 21486bc75619SDan Williams memdev->header.length = sizeof(*memdev); 21496bc75619SDan Williams memdev->device_handle = handle[0]; 21506bc75619SDan Williams memdev->physical_id = 0; 21516bc75619SDan Williams memdev->region_id = 1; 21526bc75619SDan Williams memdev->range_index = 1+1; 21533b87356fSDan Williams memdev->region_index = 4+1; 21546bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 2155df06a2d5SDan Williams memdev->region_offset = (1 << 16); 21566bc75619SDan Williams memdev->address = SPA0_SIZE/2; 21576bc75619SDan Williams memdev->interleave_index = 0; 21586bc75619SDan Williams memdev->interleave_ways = 4; 2159ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED; 2160d7d8464dSRoss Zwisler offset += memdev->header.length; 21616bc75619SDan Williams 21626bc75619SDan Williams /* mem-region3 (spa1, dimm1) */ 2163d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 21646bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 21656bc75619SDan Williams memdev->header.length = sizeof(*memdev); 21666bc75619SDan Williams memdev->device_handle = handle[1]; 21676bc75619SDan Williams memdev->physical_id = 1; 21686bc75619SDan Williams memdev->region_id = 1; 21696bc75619SDan Williams memdev->range_index = 1+1; 21703b87356fSDan Williams memdev->region_index = 5+1; 21716bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 2172df06a2d5SDan Williams memdev->region_offset = (1 << 24); 21736bc75619SDan Williams memdev->address = SPA0_SIZE/2; 21746bc75619SDan Williams memdev->interleave_index = 0; 21756bc75619SDan Williams memdev->interleave_ways = 4; 2176d7d8464dSRoss Zwisler offset += memdev->header.length; 21776bc75619SDan Williams 21786bc75619SDan Williams /* mem-region4 (spa1, dimm2) */ 2179d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 21806bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 21816bc75619SDan Williams memdev->header.length = sizeof(*memdev); 21826bc75619SDan Williams memdev->device_handle = handle[2]; 21836bc75619SDan Williams memdev->physical_id = 2; 21846bc75619SDan Williams memdev->region_id = 0; 21856bc75619SDan Williams memdev->range_index = 1+1; 21863b87356fSDan Williams memdev->region_index = 6+1; 21876bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 2188df06a2d5SDan Williams memdev->region_offset = (1ULL << 32); 21896bc75619SDan Williams memdev->address = SPA0_SIZE/2; 21906bc75619SDan Williams memdev->interleave_index = 0; 21916bc75619SDan Williams memdev->interleave_ways = 4; 2192ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED; 2193d7d8464dSRoss Zwisler offset += memdev->header.length; 21946bc75619SDan Williams 21956bc75619SDan Williams /* mem-region5 (spa1, dimm3) */ 2196d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 21976bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 21986bc75619SDan Williams memdev->header.length = sizeof(*memdev); 21996bc75619SDan Williams memdev->device_handle = handle[3]; 22006bc75619SDan Williams memdev->physical_id = 3; 22016bc75619SDan Williams memdev->region_id = 0; 22026bc75619SDan Williams memdev->range_index = 1+1; 22033b87356fSDan Williams memdev->region_index = 7+1; 22046bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 2205df06a2d5SDan Williams memdev->region_offset = (1ULL << 40); 22066bc75619SDan Williams memdev->address = SPA0_SIZE/2; 22076bc75619SDan Williams memdev->interleave_index = 0; 22086bc75619SDan Williams memdev->interleave_ways = 4; 2209d7d8464dSRoss Zwisler offset += memdev->header.length; 22106bc75619SDan Williams 22116bc75619SDan Williams /* mem-region6 (spa/dcr0, dimm0) */ 2212d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 22136bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 22146bc75619SDan Williams memdev->header.length = sizeof(*memdev); 22156bc75619SDan Williams memdev->device_handle = handle[0]; 22166bc75619SDan Williams memdev->physical_id = 0; 22176bc75619SDan Williams memdev->region_id = 0; 22186bc75619SDan Williams memdev->range_index = 2+1; 22196bc75619SDan Williams memdev->region_index = 0+1; 22206bc75619SDan Williams memdev->region_size = 0; 22216bc75619SDan Williams memdev->region_offset = 0; 22226bc75619SDan Williams memdev->address = 0; 22236bc75619SDan Williams memdev->interleave_index = 0; 22246bc75619SDan Williams memdev->interleave_ways = 1; 2225d7d8464dSRoss Zwisler offset += memdev->header.length; 22266bc75619SDan Williams 22276bc75619SDan Williams /* mem-region7 (spa/dcr1, dimm1) */ 2228d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 22296bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 22306bc75619SDan Williams memdev->header.length = sizeof(*memdev); 22316bc75619SDan Williams memdev->device_handle = handle[1]; 22326bc75619SDan Williams memdev->physical_id = 1; 22336bc75619SDan Williams memdev->region_id = 0; 22346bc75619SDan Williams memdev->range_index = 3+1; 22356bc75619SDan Williams memdev->region_index = 1+1; 22366bc75619SDan Williams memdev->region_size = 0; 22376bc75619SDan Williams memdev->region_offset = 0; 22386bc75619SDan Williams memdev->address = 0; 22396bc75619SDan Williams memdev->interleave_index = 0; 22406bc75619SDan Williams memdev->interleave_ways = 1; 2241d7d8464dSRoss Zwisler offset += memdev->header.length; 22426bc75619SDan Williams 22436bc75619SDan Williams /* mem-region8 (spa/dcr2, dimm2) */ 2244d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 22456bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 22466bc75619SDan Williams memdev->header.length = sizeof(*memdev); 22476bc75619SDan Williams memdev->device_handle = handle[2]; 22486bc75619SDan Williams memdev->physical_id = 2; 22496bc75619SDan Williams memdev->region_id = 0; 22506bc75619SDan Williams memdev->range_index = 4+1; 22516bc75619SDan Williams memdev->region_index = 2+1; 22526bc75619SDan Williams memdev->region_size = 0; 22536bc75619SDan Williams memdev->region_offset = 0; 22546bc75619SDan Williams memdev->address = 0; 22556bc75619SDan Williams memdev->interleave_index = 0; 22566bc75619SDan Williams memdev->interleave_ways = 1; 2257d7d8464dSRoss Zwisler offset += memdev->header.length; 22586bc75619SDan Williams 22596bc75619SDan Williams /* mem-region9 (spa/dcr3, dimm3) */ 2260d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 22616bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 22626bc75619SDan Williams memdev->header.length = sizeof(*memdev); 22636bc75619SDan Williams memdev->device_handle = handle[3]; 22646bc75619SDan Williams memdev->physical_id = 3; 22656bc75619SDan Williams memdev->region_id = 0; 22666bc75619SDan Williams memdev->range_index = 5+1; 22676bc75619SDan Williams memdev->region_index = 3+1; 22686bc75619SDan Williams memdev->region_size = 0; 22696bc75619SDan Williams memdev->region_offset = 0; 22706bc75619SDan Williams memdev->address = 0; 22716bc75619SDan Williams memdev->interleave_index = 0; 22726bc75619SDan Williams memdev->interleave_ways = 1; 2273d7d8464dSRoss Zwisler offset += memdev->header.length; 22746bc75619SDan Williams 22756bc75619SDan Williams /* mem-region10 (spa/bdw0, dimm0) */ 2276d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 22776bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 22786bc75619SDan Williams memdev->header.length = sizeof(*memdev); 22796bc75619SDan Williams memdev->device_handle = handle[0]; 22806bc75619SDan Williams memdev->physical_id = 0; 22816bc75619SDan Williams memdev->region_id = 0; 22826bc75619SDan Williams memdev->range_index = 6+1; 22836bc75619SDan Williams memdev->region_index = 0+1; 22846bc75619SDan Williams memdev->region_size = 0; 22856bc75619SDan Williams memdev->region_offset = 0; 22866bc75619SDan Williams memdev->address = 0; 22876bc75619SDan Williams memdev->interleave_index = 0; 22886bc75619SDan Williams memdev->interleave_ways = 1; 2289d7d8464dSRoss Zwisler offset += memdev->header.length; 22906bc75619SDan Williams 22916bc75619SDan Williams /* mem-region11 (spa/bdw1, dimm1) */ 2292d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 22936bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 22946bc75619SDan Williams memdev->header.length = sizeof(*memdev); 22956bc75619SDan Williams memdev->device_handle = handle[1]; 22966bc75619SDan Williams memdev->physical_id = 1; 22976bc75619SDan Williams memdev->region_id = 0; 22986bc75619SDan Williams memdev->range_index = 7+1; 22996bc75619SDan Williams memdev->region_index = 1+1; 23006bc75619SDan Williams memdev->region_size = 0; 23016bc75619SDan Williams memdev->region_offset = 0; 23026bc75619SDan Williams memdev->address = 0; 23036bc75619SDan Williams memdev->interleave_index = 0; 23046bc75619SDan Williams memdev->interleave_ways = 1; 2305d7d8464dSRoss Zwisler offset += memdev->header.length; 23066bc75619SDan Williams 23076bc75619SDan Williams /* mem-region12 (spa/bdw2, dimm2) */ 2308d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 23096bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 23106bc75619SDan Williams memdev->header.length = sizeof(*memdev); 23116bc75619SDan Williams memdev->device_handle = handle[2]; 23126bc75619SDan Williams memdev->physical_id = 2; 23136bc75619SDan Williams memdev->region_id = 0; 23146bc75619SDan Williams memdev->range_index = 8+1; 23156bc75619SDan Williams memdev->region_index = 2+1; 23166bc75619SDan Williams memdev->region_size = 0; 23176bc75619SDan Williams memdev->region_offset = 0; 23186bc75619SDan Williams memdev->address = 0; 23196bc75619SDan Williams memdev->interleave_index = 0; 23206bc75619SDan Williams memdev->interleave_ways = 1; 2321d7d8464dSRoss Zwisler offset += memdev->header.length; 23226bc75619SDan Williams 23236bc75619SDan Williams /* mem-region13 (spa/dcr3, dimm3) */ 2324d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 23256bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 23266bc75619SDan Williams memdev->header.length = sizeof(*memdev); 23276bc75619SDan Williams memdev->device_handle = handle[3]; 23286bc75619SDan Williams memdev->physical_id = 3; 23296bc75619SDan Williams memdev->region_id = 0; 23306bc75619SDan Williams memdev->range_index = 9+1; 23316bc75619SDan Williams memdev->region_index = 3+1; 23326bc75619SDan Williams memdev->region_size = 0; 23336bc75619SDan Williams memdev->region_offset = 0; 23346bc75619SDan Williams memdev->address = 0; 23356bc75619SDan Williams memdev->interleave_index = 0; 23366bc75619SDan Williams memdev->interleave_ways = 1; 2337ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED; 2338d7d8464dSRoss Zwisler offset += memdev->header.length; 23396bc75619SDan Williams 23403b87356fSDan Williams /* dcr-descriptor0: blk */ 23416bc75619SDan Williams dcr = nfit_buf + offset; 23426bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 2343d7d8464dSRoss Zwisler dcr->header.length = sizeof(*dcr); 23446bc75619SDan Williams dcr->region_index = 0+1; 23455dc68e55SDan Williams dcr_common_init(dcr); 23466bc75619SDan Williams dcr->serial_number = ~handle[0]; 2347be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 23486bc75619SDan Williams dcr->windows = 1; 23496bc75619SDan Williams dcr->window_size = DCR_SIZE; 23506bc75619SDan Williams dcr->command_offset = 0; 23516bc75619SDan Williams dcr->command_size = 8; 23526bc75619SDan Williams dcr->status_offset = 8; 23536bc75619SDan Williams dcr->status_size = 4; 2354d7d8464dSRoss Zwisler offset += dcr->header.length; 23556bc75619SDan Williams 23563b87356fSDan Williams /* dcr-descriptor1: blk */ 2357d7d8464dSRoss Zwisler dcr = nfit_buf + offset; 23586bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 2359d7d8464dSRoss Zwisler dcr->header.length = sizeof(*dcr); 23606bc75619SDan Williams dcr->region_index = 1+1; 23615dc68e55SDan Williams dcr_common_init(dcr); 23626bc75619SDan Williams dcr->serial_number = ~handle[1]; 2363be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 23646bc75619SDan Williams dcr->windows = 1; 23656bc75619SDan Williams dcr->window_size = DCR_SIZE; 23666bc75619SDan Williams dcr->command_offset = 0; 23676bc75619SDan Williams dcr->command_size = 8; 23686bc75619SDan Williams dcr->status_offset = 8; 23696bc75619SDan Williams dcr->status_size = 4; 2370d7d8464dSRoss Zwisler offset += dcr->header.length; 23716bc75619SDan Williams 23723b87356fSDan Williams /* dcr-descriptor2: blk */ 2373d7d8464dSRoss Zwisler dcr = nfit_buf + offset; 23746bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 2375d7d8464dSRoss Zwisler dcr->header.length = sizeof(*dcr); 23766bc75619SDan Williams dcr->region_index = 2+1; 23775dc68e55SDan Williams dcr_common_init(dcr); 23786bc75619SDan Williams dcr->serial_number = ~handle[2]; 2379be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 23806bc75619SDan Williams dcr->windows = 1; 23816bc75619SDan Williams dcr->window_size = DCR_SIZE; 23826bc75619SDan Williams dcr->command_offset = 0; 23836bc75619SDan Williams dcr->command_size = 8; 23846bc75619SDan Williams dcr->status_offset = 8; 23856bc75619SDan Williams dcr->status_size = 4; 2386d7d8464dSRoss Zwisler offset += dcr->header.length; 23876bc75619SDan Williams 23883b87356fSDan Williams /* dcr-descriptor3: blk */ 2389d7d8464dSRoss Zwisler dcr = nfit_buf + offset; 23906bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 2391d7d8464dSRoss Zwisler dcr->header.length = sizeof(*dcr); 23926bc75619SDan Williams dcr->region_index = 3+1; 23935dc68e55SDan Williams dcr_common_init(dcr); 23946bc75619SDan Williams dcr->serial_number = ~handle[3]; 2395be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 23966bc75619SDan Williams dcr->windows = 1; 23976bc75619SDan Williams dcr->window_size = DCR_SIZE; 23986bc75619SDan Williams dcr->command_offset = 0; 23996bc75619SDan Williams dcr->command_size = 8; 24006bc75619SDan Williams dcr->status_offset = 8; 24016bc75619SDan Williams dcr->status_size = 4; 2402d7d8464dSRoss Zwisler offset += dcr->header.length; 24036bc75619SDan Williams 24043b87356fSDan Williams /* dcr-descriptor0: pmem */ 24053b87356fSDan Williams dcr = nfit_buf + offset; 24063b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 24073b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 24083b87356fSDan Williams window_size); 24093b87356fSDan Williams dcr->region_index = 4+1; 24105dc68e55SDan Williams dcr_common_init(dcr); 24113b87356fSDan Williams dcr->serial_number = ~handle[0]; 24123b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 24133b87356fSDan Williams dcr->windows = 0; 2414d7d8464dSRoss Zwisler offset += dcr->header.length; 24153b87356fSDan Williams 24163b87356fSDan Williams /* dcr-descriptor1: pmem */ 2417d7d8464dSRoss Zwisler dcr = nfit_buf + offset; 24183b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 24193b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 24203b87356fSDan Williams window_size); 24213b87356fSDan Williams dcr->region_index = 5+1; 24225dc68e55SDan Williams dcr_common_init(dcr); 24233b87356fSDan Williams dcr->serial_number = ~handle[1]; 24243b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 24253b87356fSDan Williams dcr->windows = 0; 2426d7d8464dSRoss Zwisler offset += dcr->header.length; 24273b87356fSDan Williams 24283b87356fSDan Williams /* dcr-descriptor2: pmem */ 2429d7d8464dSRoss Zwisler dcr = nfit_buf + offset; 24303b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 24313b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 24323b87356fSDan Williams window_size); 24333b87356fSDan Williams dcr->region_index = 6+1; 24345dc68e55SDan Williams dcr_common_init(dcr); 24353b87356fSDan Williams dcr->serial_number = ~handle[2]; 24363b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 24373b87356fSDan Williams dcr->windows = 0; 2438d7d8464dSRoss Zwisler offset += dcr->header.length; 24393b87356fSDan Williams 24403b87356fSDan Williams /* dcr-descriptor3: pmem */ 2441d7d8464dSRoss Zwisler dcr = nfit_buf + offset; 24423b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 24433b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 24443b87356fSDan Williams window_size); 24453b87356fSDan Williams dcr->region_index = 7+1; 24465dc68e55SDan Williams dcr_common_init(dcr); 24473b87356fSDan Williams dcr->serial_number = ~handle[3]; 24483b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 24493b87356fSDan Williams dcr->windows = 0; 2450d7d8464dSRoss Zwisler offset += dcr->header.length; 24513b87356fSDan Williams 24526bc75619SDan Williams /* bdw0 (spa/dcr0, dimm0) */ 24536bc75619SDan Williams bdw = nfit_buf + offset; 24546bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 2455d7d8464dSRoss Zwisler bdw->header.length = sizeof(*bdw); 24566bc75619SDan Williams bdw->region_index = 0+1; 24576bc75619SDan Williams bdw->windows = 1; 24586bc75619SDan Williams bdw->offset = 0; 24596bc75619SDan Williams bdw->size = BDW_SIZE; 24606bc75619SDan Williams bdw->capacity = DIMM_SIZE; 24616bc75619SDan Williams bdw->start_address = 0; 2462d7d8464dSRoss Zwisler offset += bdw->header.length; 24636bc75619SDan Williams 24646bc75619SDan Williams /* bdw1 (spa/dcr1, dimm1) */ 2465d7d8464dSRoss Zwisler bdw = nfit_buf + offset; 24666bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 2467d7d8464dSRoss Zwisler bdw->header.length = sizeof(*bdw); 24686bc75619SDan Williams bdw->region_index = 1+1; 24696bc75619SDan Williams bdw->windows = 1; 24706bc75619SDan Williams bdw->offset = 0; 24716bc75619SDan Williams bdw->size = BDW_SIZE; 24726bc75619SDan Williams bdw->capacity = DIMM_SIZE; 24736bc75619SDan Williams bdw->start_address = 0; 2474d7d8464dSRoss Zwisler offset += bdw->header.length; 24756bc75619SDan Williams 24766bc75619SDan Williams /* bdw2 (spa/dcr2, dimm2) */ 2477d7d8464dSRoss Zwisler bdw = nfit_buf + offset; 24786bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 2479d7d8464dSRoss Zwisler bdw->header.length = sizeof(*bdw); 24806bc75619SDan Williams bdw->region_index = 2+1; 24816bc75619SDan Williams bdw->windows = 1; 24826bc75619SDan Williams bdw->offset = 0; 24836bc75619SDan Williams bdw->size = BDW_SIZE; 24846bc75619SDan Williams bdw->capacity = DIMM_SIZE; 24856bc75619SDan Williams bdw->start_address = 0; 2486d7d8464dSRoss Zwisler offset += bdw->header.length; 24876bc75619SDan Williams 24886bc75619SDan Williams /* bdw3 (spa/dcr3, dimm3) */ 2489d7d8464dSRoss Zwisler bdw = nfit_buf + offset; 24906bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 2491d7d8464dSRoss Zwisler bdw->header.length = sizeof(*bdw); 24926bc75619SDan Williams bdw->region_index = 3+1; 24936bc75619SDan Williams bdw->windows = 1; 24946bc75619SDan Williams bdw->offset = 0; 24956bc75619SDan Williams bdw->size = BDW_SIZE; 24966bc75619SDan Williams bdw->capacity = DIMM_SIZE; 24976bc75619SDan Williams bdw->start_address = 0; 2498d7d8464dSRoss Zwisler offset += bdw->header.length; 24996bc75619SDan Williams 25009d27a87eSDan Williams /* flush0 (dimm0) */ 25019d27a87eSDan Williams flush = nfit_buf + offset; 25029d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 250385d3fa02SDan Williams flush->header.length = flush_hint_size; 25049d27a87eSDan Williams flush->device_handle = handle[0]; 250585d3fa02SDan Williams flush->hint_count = NUM_HINTS; 250685d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 250785d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[0] + i * sizeof(u64); 2508d7d8464dSRoss Zwisler offset += flush->header.length; 25099d27a87eSDan Williams 25109d27a87eSDan Williams /* flush1 (dimm1) */ 2511d7d8464dSRoss Zwisler flush = nfit_buf + offset; 25129d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 251385d3fa02SDan Williams flush->header.length = flush_hint_size; 25149d27a87eSDan Williams flush->device_handle = handle[1]; 251585d3fa02SDan Williams flush->hint_count = NUM_HINTS; 251685d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 251785d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[1] + i * sizeof(u64); 2518d7d8464dSRoss Zwisler offset += flush->header.length; 25199d27a87eSDan Williams 25209d27a87eSDan Williams /* flush2 (dimm2) */ 2521d7d8464dSRoss Zwisler flush = nfit_buf + offset; 25229d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 252385d3fa02SDan Williams flush->header.length = flush_hint_size; 25249d27a87eSDan Williams flush->device_handle = handle[2]; 252585d3fa02SDan Williams flush->hint_count = NUM_HINTS; 252685d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 252785d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[2] + i * sizeof(u64); 2528d7d8464dSRoss Zwisler offset += flush->header.length; 25299d27a87eSDan Williams 25309d27a87eSDan Williams /* flush3 (dimm3) */ 2531d7d8464dSRoss Zwisler flush = nfit_buf + offset; 25329d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 253385d3fa02SDan Williams flush->header.length = flush_hint_size; 25349d27a87eSDan Williams flush->device_handle = handle[3]; 253585d3fa02SDan Williams flush->hint_count = NUM_HINTS; 253685d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 253785d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[3] + i * sizeof(u64); 2538d7d8464dSRoss Zwisler offset += flush->header.length; 25399d27a87eSDan Williams 2540f81e1d35SDave Jiang /* platform capabilities */ 2541d7d8464dSRoss Zwisler pcap = nfit_buf + offset; 2542f81e1d35SDave Jiang pcap->header.type = ACPI_NFIT_TYPE_CAPABILITIES; 2543f81e1d35SDave Jiang pcap->header.length = sizeof(*pcap); 2544f81e1d35SDave Jiang pcap->highest_capability = 1; 25451273c253SVishal Verma pcap->capabilities = ACPI_NFIT_CAPABILITY_MEM_FLUSH; 2546d7d8464dSRoss Zwisler offset += pcap->header.length; 2547f81e1d35SDave Jiang 254820985164SVishal Verma if (t->setup_hotplug) { 25493b87356fSDan Williams /* dcr-descriptor4: blk */ 255020985164SVishal Verma dcr = nfit_buf + offset; 255120985164SVishal Verma dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 2552d7d8464dSRoss Zwisler dcr->header.length = sizeof(*dcr); 25533b87356fSDan Williams dcr->region_index = 8+1; 25545dc68e55SDan Williams dcr_common_init(dcr); 255520985164SVishal Verma dcr->serial_number = ~handle[4]; 2556be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 255720985164SVishal Verma dcr->windows = 1; 255820985164SVishal Verma dcr->window_size = DCR_SIZE; 255920985164SVishal Verma dcr->command_offset = 0; 256020985164SVishal Verma dcr->command_size = 8; 256120985164SVishal Verma dcr->status_offset = 8; 256220985164SVishal Verma dcr->status_size = 4; 2563d7d8464dSRoss Zwisler offset += dcr->header.length; 256420985164SVishal Verma 25653b87356fSDan Williams /* dcr-descriptor4: pmem */ 25663b87356fSDan Williams dcr = nfit_buf + offset; 25673b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 25683b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 25693b87356fSDan Williams window_size); 25703b87356fSDan Williams dcr->region_index = 9+1; 25715dc68e55SDan Williams dcr_common_init(dcr); 25723b87356fSDan Williams dcr->serial_number = ~handle[4]; 25733b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 25743b87356fSDan Williams dcr->windows = 0; 2575d7d8464dSRoss Zwisler offset += dcr->header.length; 25763b87356fSDan Williams 257720985164SVishal Verma /* bdw4 (spa/dcr4, dimm4) */ 257820985164SVishal Verma bdw = nfit_buf + offset; 257920985164SVishal Verma bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 2580d7d8464dSRoss Zwisler bdw->header.length = sizeof(*bdw); 25813b87356fSDan Williams bdw->region_index = 8+1; 258220985164SVishal Verma bdw->windows = 1; 258320985164SVishal Verma bdw->offset = 0; 258420985164SVishal Verma bdw->size = BDW_SIZE; 258520985164SVishal Verma bdw->capacity = DIMM_SIZE; 258620985164SVishal Verma bdw->start_address = 0; 2587d7d8464dSRoss Zwisler offset += bdw->header.length; 258820985164SVishal Verma 258920985164SVishal Verma /* spa10 (dcr4) dimm4 */ 259020985164SVishal Verma spa = nfit_buf + offset; 259120985164SVishal Verma spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 2592e9cfd259SDan Williams spa->header.length = sizeof_spa(spa); 259320985164SVishal Verma memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 259420985164SVishal Verma spa->range_index = 10+1; 259520985164SVishal Verma spa->address = t->dcr_dma[4]; 259620985164SVishal Verma spa->length = DCR_SIZE; 2597d7d8464dSRoss Zwisler offset += spa->header.length; 259820985164SVishal Verma 259920985164SVishal Verma /* 260020985164SVishal Verma * spa11 (single-dimm interleave for hotplug, note storage 260120985164SVishal Verma * does not actually alias the related block-data-window 260220985164SVishal Verma * regions) 260320985164SVishal Verma */ 2604d7d8464dSRoss Zwisler spa = nfit_buf + offset; 260520985164SVishal Verma spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 2606e9cfd259SDan Williams spa->header.length = sizeof_spa(spa); 260720985164SVishal Verma memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 260820985164SVishal Verma spa->range_index = 11+1; 260920985164SVishal Verma spa->address = t->spa_set_dma[2]; 261020985164SVishal Verma spa->length = SPA0_SIZE; 2611d7d8464dSRoss Zwisler offset += spa->header.length; 261220985164SVishal Verma 261320985164SVishal Verma /* spa12 (bdw for dcr4) dimm4 */ 2614d7d8464dSRoss Zwisler spa = nfit_buf + offset; 261520985164SVishal Verma spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 2616e9cfd259SDan Williams spa->header.length = sizeof_spa(spa); 261720985164SVishal Verma memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 261820985164SVishal Verma spa->range_index = 12+1; 261920985164SVishal Verma spa->address = t->dimm_dma[4]; 262020985164SVishal Verma spa->length = DIMM_SIZE; 2621d7d8464dSRoss Zwisler offset += spa->header.length; 262220985164SVishal Verma 262320985164SVishal Verma /* mem-region14 (spa/dcr4, dimm4) */ 262420985164SVishal Verma memdev = nfit_buf + offset; 262520985164SVishal Verma memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 262620985164SVishal Verma memdev->header.length = sizeof(*memdev); 262720985164SVishal Verma memdev->device_handle = handle[4]; 262820985164SVishal Verma memdev->physical_id = 4; 262920985164SVishal Verma memdev->region_id = 0; 263020985164SVishal Verma memdev->range_index = 10+1; 26313b87356fSDan Williams memdev->region_index = 8+1; 263220985164SVishal Verma memdev->region_size = 0; 263320985164SVishal Verma memdev->region_offset = 0; 263420985164SVishal Verma memdev->address = 0; 263520985164SVishal Verma memdev->interleave_index = 0; 263620985164SVishal Verma memdev->interleave_ways = 1; 2637d7d8464dSRoss Zwisler offset += memdev->header.length; 263820985164SVishal Verma 2639d7d8464dSRoss Zwisler /* mem-region15 (spa11, dimm4) */ 2640d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 264120985164SVishal Verma memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 264220985164SVishal Verma memdev->header.length = sizeof(*memdev); 264320985164SVishal Verma memdev->device_handle = handle[4]; 264420985164SVishal Verma memdev->physical_id = 4; 264520985164SVishal Verma memdev->region_id = 0; 264620985164SVishal Verma memdev->range_index = 11+1; 26473b87356fSDan Williams memdev->region_index = 9+1; 264820985164SVishal Verma memdev->region_size = SPA0_SIZE; 2649df06a2d5SDan Williams memdev->region_offset = (1ULL << 48); 265020985164SVishal Verma memdev->address = 0; 265120985164SVishal Verma memdev->interleave_index = 0; 265220985164SVishal Verma memdev->interleave_ways = 1; 2653ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED; 2654d7d8464dSRoss Zwisler offset += memdev->header.length; 265520985164SVishal Verma 26563b87356fSDan Williams /* mem-region16 (spa/bdw4, dimm4) */ 2657d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 265820985164SVishal Verma memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 265920985164SVishal Verma memdev->header.length = sizeof(*memdev); 266020985164SVishal Verma memdev->device_handle = handle[4]; 266120985164SVishal Verma memdev->physical_id = 4; 266220985164SVishal Verma memdev->region_id = 0; 266320985164SVishal Verma memdev->range_index = 12+1; 26643b87356fSDan Williams memdev->region_index = 8+1; 266520985164SVishal Verma memdev->region_size = 0; 266620985164SVishal Verma memdev->region_offset = 0; 266720985164SVishal Verma memdev->address = 0; 266820985164SVishal Verma memdev->interleave_index = 0; 266920985164SVishal Verma memdev->interleave_ways = 1; 2670d7d8464dSRoss Zwisler offset += memdev->header.length; 267120985164SVishal Verma 267220985164SVishal Verma /* flush3 (dimm4) */ 267320985164SVishal Verma flush = nfit_buf + offset; 267420985164SVishal Verma flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 267585d3fa02SDan Williams flush->header.length = flush_hint_size; 267620985164SVishal Verma flush->device_handle = handle[4]; 267785d3fa02SDan Williams flush->hint_count = NUM_HINTS; 267885d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 267985d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[4] 268085d3fa02SDan Williams + i * sizeof(u64); 2681d7d8464dSRoss Zwisler offset += flush->header.length; 26829741a559SRoss Zwisler 26839741a559SRoss Zwisler /* sanity check to make sure we've filled the buffer */ 26849741a559SRoss Zwisler WARN_ON(offset != t->nfit_size); 268520985164SVishal Verma } 268620985164SVishal Verma 26871526f9e2SRoss Zwisler t->nfit_filled = offset; 26881526f9e2SRoss Zwisler 26899fb1a190SDave Jiang post_ars_status(&t->ars_state, &t->badrange, t->spa_set_dma[0], 26909fb1a190SDave Jiang SPA0_SIZE); 2691f471f1a7SDan Williams 26926bc75619SDan Williams acpi_desc = &t->acpi_desc; 2693e3654ecaSDan Williams set_bit(ND_CMD_GET_CONFIG_SIZE, &acpi_desc->dimm_cmd_force_en); 2694e3654ecaSDan Williams set_bit(ND_CMD_GET_CONFIG_DATA, &acpi_desc->dimm_cmd_force_en); 2695e3654ecaSDan Williams set_bit(ND_CMD_SET_CONFIG_DATA, &acpi_desc->dimm_cmd_force_en); 2696ed07c433SDan Williams set_bit(ND_INTEL_SMART, &acpi_desc->dimm_cmd_force_en); 2697ed07c433SDan Williams set_bit(ND_INTEL_SMART_THRESHOLD, &acpi_desc->dimm_cmd_force_en); 2698ed07c433SDan Williams set_bit(ND_INTEL_SMART_SET_THRESHOLD, &acpi_desc->dimm_cmd_force_en); 26994cf260fcSVishal Verma set_bit(ND_INTEL_SMART_INJECT, &acpi_desc->dimm_cmd_force_en); 2700e3654ecaSDan Williams set_bit(ND_CMD_ARS_CAP, &acpi_desc->bus_cmd_force_en); 2701e3654ecaSDan Williams set_bit(ND_CMD_ARS_START, &acpi_desc->bus_cmd_force_en); 2702e3654ecaSDan Williams set_bit(ND_CMD_ARS_STATUS, &acpi_desc->bus_cmd_force_en); 2703e3654ecaSDan Williams set_bit(ND_CMD_CLEAR_ERROR, &acpi_desc->bus_cmd_force_en); 270410246dc8SYasunori Goto set_bit(ND_CMD_CALL, &acpi_desc->bus_cmd_force_en); 2705d46e6a21SDan Williams set_bit(NFIT_CMD_TRANSLATE_SPA, &acpi_desc->bus_dsm_mask); 2706d46e6a21SDan Williams set_bit(NFIT_CMD_ARS_INJECT_SET, &acpi_desc->bus_dsm_mask); 2707d46e6a21SDan Williams set_bit(NFIT_CMD_ARS_INJECT_CLEAR, &acpi_desc->bus_dsm_mask); 2708d46e6a21SDan Williams set_bit(NFIT_CMD_ARS_INJECT_GET, &acpi_desc->bus_dsm_mask); 2709bfbaa952SDave Jiang set_bit(ND_INTEL_FW_GET_INFO, &acpi_desc->dimm_cmd_force_en); 2710bfbaa952SDave Jiang set_bit(ND_INTEL_FW_START_UPDATE, &acpi_desc->dimm_cmd_force_en); 2711bfbaa952SDave Jiang set_bit(ND_INTEL_FW_SEND_DATA, &acpi_desc->dimm_cmd_force_en); 2712bfbaa952SDave Jiang set_bit(ND_INTEL_FW_FINISH_UPDATE, &acpi_desc->dimm_cmd_force_en); 2713bfbaa952SDave Jiang set_bit(ND_INTEL_FW_FINISH_QUERY, &acpi_desc->dimm_cmd_force_en); 2714674d8bdeSDave Jiang set_bit(ND_INTEL_ENABLE_LSS_STATUS, &acpi_desc->dimm_cmd_force_en); 27153c13e2acSDave Jiang set_bit(NVDIMM_INTEL_GET_SECURITY_STATE, 27163c13e2acSDave Jiang &acpi_desc->dimm_cmd_force_en); 27173c13e2acSDave Jiang set_bit(NVDIMM_INTEL_SET_PASSPHRASE, &acpi_desc->dimm_cmd_force_en); 27183c13e2acSDave Jiang set_bit(NVDIMM_INTEL_DISABLE_PASSPHRASE, 27193c13e2acSDave Jiang &acpi_desc->dimm_cmd_force_en); 27203c13e2acSDave Jiang set_bit(NVDIMM_INTEL_UNLOCK_UNIT, &acpi_desc->dimm_cmd_force_en); 27213c13e2acSDave Jiang set_bit(NVDIMM_INTEL_FREEZE_LOCK, &acpi_desc->dimm_cmd_force_en); 27223c13e2acSDave Jiang set_bit(NVDIMM_INTEL_SECURE_ERASE, &acpi_desc->dimm_cmd_force_en); 2723926f7480SDave Jiang set_bit(NVDIMM_INTEL_OVERWRITE, &acpi_desc->dimm_cmd_force_en); 2724926f7480SDave Jiang set_bit(NVDIMM_INTEL_QUERY_OVERWRITE, &acpi_desc->dimm_cmd_force_en); 2725ecaa4a97SDave Jiang set_bit(NVDIMM_INTEL_SET_MASTER_PASSPHRASE, 2726ecaa4a97SDave Jiang &acpi_desc->dimm_cmd_force_en); 2727ecaa4a97SDave Jiang set_bit(NVDIMM_INTEL_MASTER_SECURE_ERASE, 2728ecaa4a97SDave Jiang &acpi_desc->dimm_cmd_force_en); 2729916566aeSDan Williams set_bit(NVDIMM_INTEL_FW_ACTIVATE_DIMMINFO, &acpi_desc->dimm_cmd_force_en); 2730916566aeSDan Williams set_bit(NVDIMM_INTEL_FW_ACTIVATE_ARM, &acpi_desc->dimm_cmd_force_en); 2731916566aeSDan Williams 2732916566aeSDan Williams acpi_mask = &acpi_desc->family_dsm_mask[NVDIMM_BUS_FAMILY_INTEL]; 2733916566aeSDan Williams set_bit(NVDIMM_BUS_INTEL_FW_ACTIVATE_BUSINFO, acpi_mask); 2734916566aeSDan Williams set_bit(NVDIMM_BUS_INTEL_FW_ACTIVATE, acpi_mask); 27356bc75619SDan Williams } 27366bc75619SDan Williams 27376bc75619SDan Williams static void nfit_test1_setup(struct nfit_test *t) 27386bc75619SDan Williams { 27396b577c9dSLinda Knippers size_t offset; 27406bc75619SDan Williams void *nfit_buf = t->nfit_buf; 27416bc75619SDan Williams struct acpi_nfit_memory_map *memdev; 27426bc75619SDan Williams struct acpi_nfit_control_region *dcr; 27436bc75619SDan Williams struct acpi_nfit_system_address *spa; 2744d26f73f0SDan Williams struct acpi_nfit_desc *acpi_desc; 27456bc75619SDan Williams 27466b577c9dSLinda Knippers offset = 0; 27476bc75619SDan Williams /* spa0 (flat range with no bdw aliasing) */ 27486bc75619SDan Williams spa = nfit_buf + offset; 27496bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 2750e9cfd259SDan Williams spa->header.length = sizeof_spa(spa); 27516bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 27526bc75619SDan Williams spa->range_index = 0+1; 27536bc75619SDan Williams spa->address = t->spa_set_dma[0]; 27546bc75619SDan Williams spa->length = SPA2_SIZE; 2755d7d8464dSRoss Zwisler offset += spa->header.length; 27566bc75619SDan Williams 27577bfe97c7SDan Williams /* virtual cd region */ 2758d7d8464dSRoss Zwisler spa = nfit_buf + offset; 27597bfe97c7SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 2760e9cfd259SDan Williams spa->header.length = sizeof_spa(spa); 27617bfe97c7SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_VCD), 16); 27627bfe97c7SDan Williams spa->range_index = 0; 27637bfe97c7SDan Williams spa->address = t->spa_set_dma[1]; 27647bfe97c7SDan Williams spa->length = SPA_VCD_SIZE; 2765d7d8464dSRoss Zwisler offset += spa->header.length; 27667bfe97c7SDan Williams 27676bc75619SDan Williams /* mem-region0 (spa0, dimm0) */ 27686bc75619SDan Williams memdev = nfit_buf + offset; 27696bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 27706bc75619SDan Williams memdev->header.length = sizeof(*memdev); 2771dafb1048SDan Williams memdev->device_handle = handle[5]; 27726bc75619SDan Williams memdev->physical_id = 0; 27736bc75619SDan Williams memdev->region_id = 0; 27746bc75619SDan Williams memdev->range_index = 0+1; 27756bc75619SDan Williams memdev->region_index = 0+1; 27766bc75619SDan Williams memdev->region_size = SPA2_SIZE; 27776bc75619SDan Williams memdev->region_offset = 0; 27786bc75619SDan Williams memdev->address = 0; 27796bc75619SDan Williams memdev->interleave_index = 0; 27806bc75619SDan Williams memdev->interleave_ways = 1; 278158138820SDan Williams memdev->flags = ACPI_NFIT_MEM_SAVE_FAILED | ACPI_NFIT_MEM_RESTORE_FAILED 278258138820SDan Williams | ACPI_NFIT_MEM_FLUSH_FAILED | ACPI_NFIT_MEM_HEALTH_OBSERVED 2783f4295796SDan Williams | ACPI_NFIT_MEM_NOT_ARMED; 2784d7d8464dSRoss Zwisler offset += memdev->header.length; 27856bc75619SDan Williams 27866bc75619SDan Williams /* dcr-descriptor0 */ 27876bc75619SDan Williams dcr = nfit_buf + offset; 27886bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 27893b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 27903b87356fSDan Williams window_size); 27916bc75619SDan Williams dcr->region_index = 0+1; 27925dc68e55SDan Williams dcr_common_init(dcr); 2793dafb1048SDan Williams dcr->serial_number = ~handle[5]; 2794be26f9aeSDan Williams dcr->code = NFIT_FIC_BYTE; 27956bc75619SDan Williams dcr->windows = 0; 2796ac40b675SDan Williams offset += dcr->header.length; 2797d7d8464dSRoss Zwisler 2798ac40b675SDan Williams memdev = nfit_buf + offset; 2799ac40b675SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 2800ac40b675SDan Williams memdev->header.length = sizeof(*memdev); 2801ac40b675SDan Williams memdev->device_handle = handle[6]; 2802ac40b675SDan Williams memdev->physical_id = 0; 2803ac40b675SDan Williams memdev->region_id = 0; 2804ac40b675SDan Williams memdev->range_index = 0; 2805ac40b675SDan Williams memdev->region_index = 0+2; 2806ac40b675SDan Williams memdev->region_size = SPA2_SIZE; 2807ac40b675SDan Williams memdev->region_offset = 0; 2808ac40b675SDan Williams memdev->address = 0; 2809ac40b675SDan Williams memdev->interleave_index = 0; 2810ac40b675SDan Williams memdev->interleave_ways = 1; 2811ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_MAP_FAILED; 2812d7d8464dSRoss Zwisler offset += memdev->header.length; 2813ac40b675SDan Williams 2814ac40b675SDan Williams /* dcr-descriptor1 */ 2815ac40b675SDan Williams dcr = nfit_buf + offset; 2816ac40b675SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 2817ac40b675SDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 2818ac40b675SDan Williams window_size); 2819ac40b675SDan Williams dcr->region_index = 0+2; 2820ac40b675SDan Williams dcr_common_init(dcr); 2821ac40b675SDan Williams dcr->serial_number = ~handle[6]; 2822ac40b675SDan Williams dcr->code = NFIT_FIC_BYTE; 2823ac40b675SDan Williams dcr->windows = 0; 2824d7d8464dSRoss Zwisler offset += dcr->header.length; 2825ac40b675SDan Williams 28269741a559SRoss Zwisler /* sanity check to make sure we've filled the buffer */ 28279741a559SRoss Zwisler WARN_ON(offset != t->nfit_size); 28289741a559SRoss Zwisler 28291526f9e2SRoss Zwisler t->nfit_filled = offset; 28301526f9e2SRoss Zwisler 28319fb1a190SDave Jiang post_ars_status(&t->ars_state, &t->badrange, t->spa_set_dma[0], 28329fb1a190SDave Jiang SPA2_SIZE); 2833f471f1a7SDan Williams 2834d26f73f0SDan Williams acpi_desc = &t->acpi_desc; 2835e3654ecaSDan Williams set_bit(ND_CMD_ARS_CAP, &acpi_desc->bus_cmd_force_en); 2836e3654ecaSDan Williams set_bit(ND_CMD_ARS_START, &acpi_desc->bus_cmd_force_en); 2837e3654ecaSDan Williams set_bit(ND_CMD_ARS_STATUS, &acpi_desc->bus_cmd_force_en); 2838e3654ecaSDan Williams set_bit(ND_CMD_CLEAR_ERROR, &acpi_desc->bus_cmd_force_en); 2839674d8bdeSDave Jiang set_bit(ND_INTEL_ENABLE_LSS_STATUS, &acpi_desc->dimm_cmd_force_en); 28409484e12dSDan Williams set_bit(ND_CMD_GET_CONFIG_SIZE, &acpi_desc->dimm_cmd_force_en); 28419484e12dSDan Williams set_bit(ND_CMD_GET_CONFIG_DATA, &acpi_desc->dimm_cmd_force_en); 28429484e12dSDan Williams set_bit(ND_CMD_SET_CONFIG_DATA, &acpi_desc->dimm_cmd_force_en); 28436bc75619SDan Williams } 28446bc75619SDan Williams 28456bc75619SDan Williams static int nfit_test_blk_do_io(struct nd_blk_region *ndbr, resource_size_t dpa, 28466bc75619SDan Williams void *iobuf, u64 len, int rw) 28476bc75619SDan Williams { 28486bc75619SDan Williams struct nfit_blk *nfit_blk = ndbr->blk_provider_data; 28496bc75619SDan Williams struct nfit_blk_mmio *mmio = &nfit_blk->mmio[BDW]; 28506bc75619SDan Williams struct nd_region *nd_region = &ndbr->nd_region; 28516bc75619SDan Williams unsigned int lane; 28526bc75619SDan Williams 28536bc75619SDan Williams lane = nd_region_acquire_lane(nd_region); 28546bc75619SDan Williams if (rw) 285567a3e8feSRoss Zwisler memcpy(mmio->addr.base + dpa, iobuf, len); 285667a3e8feSRoss Zwisler else { 285767a3e8feSRoss Zwisler memcpy(iobuf, mmio->addr.base + dpa, len); 285867a3e8feSRoss Zwisler 28595deb67f7SRobin Murphy /* give us some some coverage of the arch_invalidate_pmem() API */ 28605deb67f7SRobin Murphy arch_invalidate_pmem(mmio->addr.base + dpa, len); 286167a3e8feSRoss Zwisler } 28626bc75619SDan Williams nd_region_release_lane(nd_region, lane); 28636bc75619SDan Williams 28646bc75619SDan Williams return 0; 28656bc75619SDan Williams } 28666bc75619SDan Williams 2867a7de92daSDan Williams static unsigned long nfit_ctl_handle; 2868a7de92daSDan Williams 2869a7de92daSDan Williams union acpi_object *result; 2870a7de92daSDan Williams 2871a7de92daSDan Williams static union acpi_object *nfit_test_evaluate_dsm(acpi_handle handle, 287294116f81SAndy Shevchenko const guid_t *guid, u64 rev, u64 func, union acpi_object *argv4) 2873a7de92daSDan Williams { 2874a7de92daSDan Williams if (handle != &nfit_ctl_handle) 2875a7de92daSDan Williams return ERR_PTR(-ENXIO); 2876a7de92daSDan Williams 2877a7de92daSDan Williams return result; 2878a7de92daSDan Williams } 2879a7de92daSDan Williams 2880a7de92daSDan Williams static int setup_result(void *buf, size_t size) 2881a7de92daSDan Williams { 2882a7de92daSDan Williams result = kmalloc(sizeof(union acpi_object) + size, GFP_KERNEL); 2883a7de92daSDan Williams if (!result) 2884a7de92daSDan Williams return -ENOMEM; 2885a7de92daSDan Williams result->package.type = ACPI_TYPE_BUFFER, 2886a7de92daSDan Williams result->buffer.pointer = (void *) (result + 1); 2887a7de92daSDan Williams result->buffer.length = size; 2888a7de92daSDan Williams memcpy(result->buffer.pointer, buf, size); 2889a7de92daSDan Williams memset(buf, 0, size); 2890a7de92daSDan Williams return 0; 2891a7de92daSDan Williams } 2892a7de92daSDan Williams 2893a7de92daSDan Williams static int nfit_ctl_test(struct device *dev) 2894a7de92daSDan Williams { 2895a7de92daSDan Williams int rc, cmd_rc; 2896a7de92daSDan Williams struct nvdimm *nvdimm; 2897a7de92daSDan Williams struct acpi_device *adev; 2898a7de92daSDan Williams struct nfit_mem *nfit_mem; 2899a7de92daSDan Williams struct nd_ars_record *record; 2900a7de92daSDan Williams struct acpi_nfit_desc *acpi_desc; 2901a7de92daSDan Williams const u64 test_val = 0x0123456789abcdefULL; 2902a7de92daSDan Williams unsigned long mask, cmd_size, offset; 2903abfd4d9cSDan Williams struct nfit_ctl_test_cmd { 2904abfd4d9cSDan Williams struct nd_cmd_pkg pkg; 2905a7de92daSDan Williams union { 2906a7de92daSDan Williams struct nd_cmd_get_config_size cfg_size; 2907fb2a1748SDan Williams struct nd_cmd_clear_error clear_err; 2908a7de92daSDan Williams struct nd_cmd_ars_status ars_stat; 2909a7de92daSDan Williams struct nd_cmd_ars_cap ars_cap; 2910916566aeSDan Williams struct nd_intel_bus_fw_activate_businfo fwa_info; 2911a7de92daSDan Williams char buf[sizeof(struct nd_cmd_ars_status) 2912a7de92daSDan Williams + sizeof(struct nd_ars_record)]; 2913abfd4d9cSDan Williams }; 2914abfd4d9cSDan Williams } cmd; 2915a7de92daSDan Williams 2916a7de92daSDan Williams adev = devm_kzalloc(dev, sizeof(*adev), GFP_KERNEL); 2917a7de92daSDan Williams if (!adev) 2918a7de92daSDan Williams return -ENOMEM; 2919a7de92daSDan Williams *adev = (struct acpi_device) { 2920a7de92daSDan Williams .handle = &nfit_ctl_handle, 2921a7de92daSDan Williams .dev = { 2922a7de92daSDan Williams .init_name = "test-adev", 2923a7de92daSDan Williams }, 2924a7de92daSDan Williams }; 2925a7de92daSDan Williams 2926a7de92daSDan Williams acpi_desc = devm_kzalloc(dev, sizeof(*acpi_desc), GFP_KERNEL); 2927a7de92daSDan Williams if (!acpi_desc) 2928a7de92daSDan Williams return -ENOMEM; 2929a7de92daSDan Williams *acpi_desc = (struct acpi_nfit_desc) { 2930a7de92daSDan Williams .nd_desc = { 2931a7de92daSDan Williams .cmd_mask = 1UL << ND_CMD_ARS_CAP 2932a7de92daSDan Williams | 1UL << ND_CMD_ARS_START 2933a7de92daSDan Williams | 1UL << ND_CMD_ARS_STATUS 293410246dc8SYasunori Goto | 1UL << ND_CMD_CLEAR_ERROR 293510246dc8SYasunori Goto | 1UL << ND_CMD_CALL, 2936a7de92daSDan Williams .module = THIS_MODULE, 2937a7de92daSDan Williams .provider_name = "ACPI.NFIT", 2938a7de92daSDan Williams .ndctl = acpi_nfit_ctl, 2939916566aeSDan Williams .bus_family_mask = 1UL << NVDIMM_BUS_FAMILY_NFIT 2940916566aeSDan Williams | 1UL << NVDIMM_BUS_FAMILY_INTEL, 2941d46e6a21SDan Williams }, 29429fb1a190SDave Jiang .bus_dsm_mask = 1UL << NFIT_CMD_TRANSLATE_SPA 29439fb1a190SDave Jiang | 1UL << NFIT_CMD_ARS_INJECT_SET 29449fb1a190SDave Jiang | 1UL << NFIT_CMD_ARS_INJECT_CLEAR 29459fb1a190SDave Jiang | 1UL << NFIT_CMD_ARS_INJECT_GET, 2946916566aeSDan Williams .family_dsm_mask[NVDIMM_BUS_FAMILY_INTEL] = 2947916566aeSDan Williams NVDIMM_BUS_INTEL_FW_ACTIVATE_CMDMASK, 2948a7de92daSDan Williams .dev = &adev->dev, 2949a7de92daSDan Williams }; 2950a7de92daSDan Williams 2951a7de92daSDan Williams nfit_mem = devm_kzalloc(dev, sizeof(*nfit_mem), GFP_KERNEL); 2952a7de92daSDan Williams if (!nfit_mem) 2953a7de92daSDan Williams return -ENOMEM; 2954a7de92daSDan Williams 2955a7de92daSDan Williams mask = 1UL << ND_CMD_SMART | 1UL << ND_CMD_SMART_THRESHOLD 2956a7de92daSDan Williams | 1UL << ND_CMD_DIMM_FLAGS | 1UL << ND_CMD_GET_CONFIG_SIZE 2957a7de92daSDan Williams | 1UL << ND_CMD_GET_CONFIG_DATA | 1UL << ND_CMD_SET_CONFIG_DATA 2958a7de92daSDan Williams | 1UL << ND_CMD_VENDOR; 2959a7de92daSDan Williams *nfit_mem = (struct nfit_mem) { 2960a7de92daSDan Williams .adev = adev, 2961a7de92daSDan Williams .family = NVDIMM_FAMILY_INTEL, 2962a7de92daSDan Williams .dsm_mask = mask, 2963a7de92daSDan Williams }; 2964a7de92daSDan Williams 2965a7de92daSDan Williams nvdimm = devm_kzalloc(dev, sizeof(*nvdimm), GFP_KERNEL); 2966a7de92daSDan Williams if (!nvdimm) 2967a7de92daSDan Williams return -ENOMEM; 2968a7de92daSDan Williams *nvdimm = (struct nvdimm) { 2969a7de92daSDan Williams .provider_data = nfit_mem, 2970a7de92daSDan Williams .cmd_mask = mask, 2971a7de92daSDan Williams .dev = { 2972a7de92daSDan Williams .init_name = "test-dimm", 2973a7de92daSDan Williams }, 2974a7de92daSDan Williams }; 2975a7de92daSDan Williams 2976a7de92daSDan Williams 2977a7de92daSDan Williams /* basic checkout of a typical 'get config size' command */ 2978abfd4d9cSDan Williams cmd_size = sizeof(cmd.cfg_size); 2979abfd4d9cSDan Williams cmd.cfg_size = (struct nd_cmd_get_config_size) { 2980a7de92daSDan Williams .status = 0, 2981a7de92daSDan Williams .config_size = SZ_128K, 2982a7de92daSDan Williams .max_xfer = SZ_4K, 2983a7de92daSDan Williams }; 2984abfd4d9cSDan Williams rc = setup_result(cmd.buf, cmd_size); 2985a7de92daSDan Williams if (rc) 2986a7de92daSDan Williams return rc; 2987a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, nvdimm, ND_CMD_GET_CONFIG_SIZE, 2988abfd4d9cSDan Williams cmd.buf, cmd_size, &cmd_rc); 2989a7de92daSDan Williams 2990abfd4d9cSDan Williams if (rc < 0 || cmd_rc || cmd.cfg_size.status != 0 2991abfd4d9cSDan Williams || cmd.cfg_size.config_size != SZ_128K 2992abfd4d9cSDan Williams || cmd.cfg_size.max_xfer != SZ_4K) { 2993a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 2994a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 2995a7de92daSDan Williams return -EIO; 2996a7de92daSDan Williams } 2997a7de92daSDan Williams 2998a7de92daSDan Williams 2999a7de92daSDan Williams /* test ars_status with zero output */ 3000a7de92daSDan Williams cmd_size = offsetof(struct nd_cmd_ars_status, address); 3001abfd4d9cSDan Williams cmd.ars_stat = (struct nd_cmd_ars_status) { 3002a7de92daSDan Williams .out_length = 0, 3003a7de92daSDan Williams }; 3004abfd4d9cSDan Williams rc = setup_result(cmd.buf, cmd_size); 3005a7de92daSDan Williams if (rc) 3006a7de92daSDan Williams return rc; 3007a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_ARS_STATUS, 3008abfd4d9cSDan Williams cmd.buf, cmd_size, &cmd_rc); 3009a7de92daSDan Williams 3010a7de92daSDan Williams if (rc < 0 || cmd_rc) { 3011a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 3012a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 3013a7de92daSDan Williams return -EIO; 3014a7de92daSDan Williams } 3015a7de92daSDan Williams 3016a7de92daSDan Williams 3017a7de92daSDan Williams /* test ars_cap with benign extended status */ 3018abfd4d9cSDan Williams cmd_size = sizeof(cmd.ars_cap); 3019abfd4d9cSDan Williams cmd.ars_cap = (struct nd_cmd_ars_cap) { 3020a7de92daSDan Williams .status = ND_ARS_PERSISTENT << 16, 3021a7de92daSDan Williams }; 3022a7de92daSDan Williams offset = offsetof(struct nd_cmd_ars_cap, status); 3023abfd4d9cSDan Williams rc = setup_result(cmd.buf + offset, cmd_size - offset); 3024a7de92daSDan Williams if (rc) 3025a7de92daSDan Williams return rc; 3026a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_ARS_CAP, 3027abfd4d9cSDan Williams cmd.buf, cmd_size, &cmd_rc); 3028a7de92daSDan Williams 3029a7de92daSDan Williams if (rc < 0 || cmd_rc) { 3030a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 3031a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 3032a7de92daSDan Williams return -EIO; 3033a7de92daSDan Williams } 3034a7de92daSDan Williams 3035a7de92daSDan Williams 3036a7de92daSDan Williams /* test ars_status with 'status' trimmed from 'out_length' */ 3037abfd4d9cSDan Williams cmd_size = sizeof(cmd.ars_stat) + sizeof(struct nd_ars_record); 3038abfd4d9cSDan Williams cmd.ars_stat = (struct nd_cmd_ars_status) { 3039a7de92daSDan Williams .out_length = cmd_size - 4, 3040a7de92daSDan Williams }; 3041abfd4d9cSDan Williams record = &cmd.ars_stat.records[0]; 3042a7de92daSDan Williams *record = (struct nd_ars_record) { 3043a7de92daSDan Williams .length = test_val, 3044a7de92daSDan Williams }; 3045abfd4d9cSDan Williams rc = setup_result(cmd.buf, cmd_size); 3046a7de92daSDan Williams if (rc) 3047a7de92daSDan Williams return rc; 3048a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_ARS_STATUS, 3049abfd4d9cSDan Williams cmd.buf, cmd_size, &cmd_rc); 3050a7de92daSDan Williams 3051a7de92daSDan Williams if (rc < 0 || cmd_rc || record->length != test_val) { 3052a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 3053a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 3054a7de92daSDan Williams return -EIO; 3055a7de92daSDan Williams } 3056a7de92daSDan Williams 3057a7de92daSDan Williams 3058a7de92daSDan Williams /* test ars_status with 'Output (Size)' including 'status' */ 3059abfd4d9cSDan Williams cmd_size = sizeof(cmd.ars_stat) + sizeof(struct nd_ars_record); 3060abfd4d9cSDan Williams cmd.ars_stat = (struct nd_cmd_ars_status) { 3061a7de92daSDan Williams .out_length = cmd_size, 3062a7de92daSDan Williams }; 3063abfd4d9cSDan Williams record = &cmd.ars_stat.records[0]; 3064a7de92daSDan Williams *record = (struct nd_ars_record) { 3065a7de92daSDan Williams .length = test_val, 3066a7de92daSDan Williams }; 3067abfd4d9cSDan Williams rc = setup_result(cmd.buf, cmd_size); 3068a7de92daSDan Williams if (rc) 3069a7de92daSDan Williams return rc; 3070a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_ARS_STATUS, 3071abfd4d9cSDan Williams cmd.buf, cmd_size, &cmd_rc); 3072a7de92daSDan Williams 3073a7de92daSDan Williams if (rc < 0 || cmd_rc || record->length != test_val) { 3074a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 3075a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 3076a7de92daSDan Williams return -EIO; 3077a7de92daSDan Williams } 3078a7de92daSDan Williams 3079a7de92daSDan Williams 3080a7de92daSDan Williams /* test extended status for get_config_size results in failure */ 3081abfd4d9cSDan Williams cmd_size = sizeof(cmd.cfg_size); 3082abfd4d9cSDan Williams cmd.cfg_size = (struct nd_cmd_get_config_size) { 3083a7de92daSDan Williams .status = 1 << 16, 3084a7de92daSDan Williams }; 3085abfd4d9cSDan Williams rc = setup_result(cmd.buf, cmd_size); 3086a7de92daSDan Williams if (rc) 3087a7de92daSDan Williams return rc; 3088a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, nvdimm, ND_CMD_GET_CONFIG_SIZE, 3089abfd4d9cSDan Williams cmd.buf, cmd_size, &cmd_rc); 3090a7de92daSDan Williams 3091a7de92daSDan Williams if (rc < 0 || cmd_rc >= 0) { 3092a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 3093a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 3094a7de92daSDan Williams return -EIO; 3095a7de92daSDan Williams } 3096a7de92daSDan Williams 3097fb2a1748SDan Williams /* test clear error */ 3098abfd4d9cSDan Williams cmd_size = sizeof(cmd.clear_err); 3099abfd4d9cSDan Williams cmd.clear_err = (struct nd_cmd_clear_error) { 3100fb2a1748SDan Williams .length = 512, 3101fb2a1748SDan Williams .cleared = 512, 3102fb2a1748SDan Williams }; 3103abfd4d9cSDan Williams rc = setup_result(cmd.buf, cmd_size); 3104fb2a1748SDan Williams if (rc) 3105fb2a1748SDan Williams return rc; 3106fb2a1748SDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_CLEAR_ERROR, 3107abfd4d9cSDan Williams cmd.buf, cmd_size, &cmd_rc); 3108fb2a1748SDan Williams if (rc < 0 || cmd_rc) { 3109fb2a1748SDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 3110fb2a1748SDan Williams __func__, __LINE__, rc, cmd_rc); 3111fb2a1748SDan Williams return -EIO; 3112fb2a1748SDan Williams } 3113fb2a1748SDan Williams 3114916566aeSDan Williams /* test firmware activate bus info */ 3115916566aeSDan Williams cmd_size = sizeof(cmd.fwa_info); 3116916566aeSDan Williams cmd = (struct nfit_ctl_test_cmd) { 3117916566aeSDan Williams .pkg = { 3118916566aeSDan Williams .nd_command = NVDIMM_BUS_INTEL_FW_ACTIVATE_BUSINFO, 3119916566aeSDan Williams .nd_family = NVDIMM_BUS_FAMILY_INTEL, 3120916566aeSDan Williams .nd_size_out = cmd_size, 3121916566aeSDan Williams .nd_fw_size = cmd_size, 3122916566aeSDan Williams }, 3123916566aeSDan Williams .fwa_info = { 3124916566aeSDan Williams .state = ND_INTEL_FWA_IDLE, 3125916566aeSDan Williams .capability = ND_INTEL_BUS_FWA_CAP_FWQUIESCE 3126916566aeSDan Williams | ND_INTEL_BUS_FWA_CAP_OSQUIESCE, 3127916566aeSDan Williams .activate_tmo = 1, 3128916566aeSDan Williams .cpu_quiesce_tmo = 1, 3129916566aeSDan Williams .io_quiesce_tmo = 1, 3130916566aeSDan Williams .max_quiesce_tmo = 1, 3131916566aeSDan Williams }, 3132916566aeSDan Williams }; 3133916566aeSDan Williams rc = setup_result(cmd.buf, cmd_size); 3134916566aeSDan Williams if (rc) 3135916566aeSDan Williams return rc; 3136916566aeSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_CALL, 3137916566aeSDan Williams &cmd, sizeof(cmd.pkg) + cmd_size, &cmd_rc); 3138916566aeSDan Williams if (rc < 0 || cmd_rc) { 3139916566aeSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 3140916566aeSDan Williams __func__, __LINE__, rc, cmd_rc); 3141916566aeSDan Williams return -EIO; 3142916566aeSDan Williams } 3143916566aeSDan Williams 3144a7de92daSDan Williams return 0; 3145a7de92daSDan Williams } 3146a7de92daSDan Williams 31476bc75619SDan Williams static int nfit_test_probe(struct platform_device *pdev) 31486bc75619SDan Williams { 31496bc75619SDan Williams struct nvdimm_bus_descriptor *nd_desc; 31506bc75619SDan Williams struct acpi_nfit_desc *acpi_desc; 31516bc75619SDan Williams struct device *dev = &pdev->dev; 31526bc75619SDan Williams struct nfit_test *nfit_test; 3153231bf117SDan Williams struct nfit_mem *nfit_mem; 3154c14a868aSDan Williams union acpi_object *obj; 31556bc75619SDan Williams int rc; 31566bc75619SDan Williams 3157a7de92daSDan Williams if (strcmp(dev_name(&pdev->dev), "nfit_test.0") == 0) { 3158a7de92daSDan Williams rc = nfit_ctl_test(&pdev->dev); 3159a7de92daSDan Williams if (rc) 3160a7de92daSDan Williams return rc; 3161a7de92daSDan Williams } 3162a7de92daSDan Williams 31636bc75619SDan Williams nfit_test = to_nfit_test(&pdev->dev); 31646bc75619SDan Williams 31656bc75619SDan Williams /* common alloc */ 31666bc75619SDan Williams if (nfit_test->num_dcr) { 31676bc75619SDan Williams int num = nfit_test->num_dcr; 31686bc75619SDan Williams 31696bc75619SDan Williams nfit_test->dimm = devm_kcalloc(dev, num, sizeof(void *), 31706bc75619SDan Williams GFP_KERNEL); 31716bc75619SDan Williams nfit_test->dimm_dma = devm_kcalloc(dev, num, sizeof(dma_addr_t), 31726bc75619SDan Williams GFP_KERNEL); 31739d27a87eSDan Williams nfit_test->flush = devm_kcalloc(dev, num, sizeof(void *), 31749d27a87eSDan Williams GFP_KERNEL); 31759d27a87eSDan Williams nfit_test->flush_dma = devm_kcalloc(dev, num, sizeof(dma_addr_t), 31769d27a87eSDan Williams GFP_KERNEL); 31776bc75619SDan Williams nfit_test->label = devm_kcalloc(dev, num, sizeof(void *), 31786bc75619SDan Williams GFP_KERNEL); 31796bc75619SDan Williams nfit_test->label_dma = devm_kcalloc(dev, num, 31806bc75619SDan Williams sizeof(dma_addr_t), GFP_KERNEL); 31816bc75619SDan Williams nfit_test->dcr = devm_kcalloc(dev, num, 31826bc75619SDan Williams sizeof(struct nfit_test_dcr *), GFP_KERNEL); 31836bc75619SDan Williams nfit_test->dcr_dma = devm_kcalloc(dev, num, 31846bc75619SDan Williams sizeof(dma_addr_t), GFP_KERNEL); 3185ed07c433SDan Williams nfit_test->smart = devm_kcalloc(dev, num, 3186ed07c433SDan Williams sizeof(struct nd_intel_smart), GFP_KERNEL); 3187ed07c433SDan Williams nfit_test->smart_threshold = devm_kcalloc(dev, num, 3188ed07c433SDan Williams sizeof(struct nd_intel_smart_threshold), 3189ed07c433SDan Williams GFP_KERNEL); 3190bfbaa952SDave Jiang nfit_test->fw = devm_kcalloc(dev, num, 3191bfbaa952SDave Jiang sizeof(struct nfit_test_fw), GFP_KERNEL); 31926bc75619SDan Williams if (nfit_test->dimm && nfit_test->dimm_dma && nfit_test->label 31936bc75619SDan Williams && nfit_test->label_dma && nfit_test->dcr 31949d27a87eSDan Williams && nfit_test->dcr_dma && nfit_test->flush 3195bfbaa952SDave Jiang && nfit_test->flush_dma 3196bfbaa952SDave Jiang && nfit_test->fw) 31976bc75619SDan Williams /* pass */; 31986bc75619SDan Williams else 31996bc75619SDan Williams return -ENOMEM; 32006bc75619SDan Williams } 32016bc75619SDan Williams 32026bc75619SDan Williams if (nfit_test->num_pm) { 32036bc75619SDan Williams int num = nfit_test->num_pm; 32046bc75619SDan Williams 32056bc75619SDan Williams nfit_test->spa_set = devm_kcalloc(dev, num, sizeof(void *), 32066bc75619SDan Williams GFP_KERNEL); 32076bc75619SDan Williams nfit_test->spa_set_dma = devm_kcalloc(dev, num, 32086bc75619SDan Williams sizeof(dma_addr_t), GFP_KERNEL); 32096bc75619SDan Williams if (nfit_test->spa_set && nfit_test->spa_set_dma) 32106bc75619SDan Williams /* pass */; 32116bc75619SDan Williams else 32126bc75619SDan Williams return -ENOMEM; 32136bc75619SDan Williams } 32146bc75619SDan Williams 32156bc75619SDan Williams /* per-nfit specific alloc */ 32166bc75619SDan Williams if (nfit_test->alloc(nfit_test)) 32176bc75619SDan Williams return -ENOMEM; 32186bc75619SDan Williams 32196bc75619SDan Williams nfit_test->setup(nfit_test); 32206bc75619SDan Williams acpi_desc = &nfit_test->acpi_desc; 3221a61fe6f7SDan Williams acpi_nfit_desc_init(acpi_desc, &pdev->dev); 32226bc75619SDan Williams acpi_desc->blk_do_io = nfit_test_blk_do_io; 32236bc75619SDan Williams nd_desc = &acpi_desc->nd_desc; 3224a61fe6f7SDan Williams nd_desc->provider_name = NULL; 3225bc9775d8SDan Williams nd_desc->module = THIS_MODULE; 3226a61fe6f7SDan Williams nd_desc->ndctl = nfit_test_ctl; 32276bc75619SDan Williams 3228e7a11b44SDan Williams rc = acpi_nfit_init(acpi_desc, nfit_test->nfit_buf, 32291526f9e2SRoss Zwisler nfit_test->nfit_filled); 323058cd71b4SDan Williams if (rc) 323120985164SVishal Verma return rc; 323220985164SVishal Verma 3233fbabd829SDan Williams rc = devm_add_action_or_reset(&pdev->dev, acpi_nfit_shutdown, acpi_desc); 3234fbabd829SDan Williams if (rc) 3235fbabd829SDan Williams return rc; 3236fbabd829SDan Williams 323720985164SVishal Verma if (nfit_test->setup != nfit_test0_setup) 323820985164SVishal Verma return 0; 323920985164SVishal Verma 324020985164SVishal Verma nfit_test->setup_hotplug = 1; 324120985164SVishal Verma nfit_test->setup(nfit_test); 324220985164SVishal Verma 3243c14a868aSDan Williams obj = kzalloc(sizeof(*obj), GFP_KERNEL); 3244c14a868aSDan Williams if (!obj) 3245c14a868aSDan Williams return -ENOMEM; 3246c14a868aSDan Williams obj->type = ACPI_TYPE_BUFFER; 3247c14a868aSDan Williams obj->buffer.length = nfit_test->nfit_size; 3248c14a868aSDan Williams obj->buffer.pointer = nfit_test->nfit_buf; 3249c14a868aSDan Williams *(nfit_test->_fit) = obj; 3250c14a868aSDan Williams __acpi_nfit_notify(&pdev->dev, nfit_test, 0x80); 3251231bf117SDan Williams 3252231bf117SDan Williams /* associate dimm devices with nfit_mem data for notification testing */ 3253231bf117SDan Williams mutex_lock(&acpi_desc->init_mutex); 3254231bf117SDan Williams list_for_each_entry(nfit_mem, &acpi_desc->dimms, list) { 3255231bf117SDan Williams u32 nfit_handle = __to_nfit_memdev(nfit_mem)->device_handle; 3256231bf117SDan Williams int i; 3257231bf117SDan Williams 3258af31b04bSMasayoshi Mizuma for (i = 0; i < ARRAY_SIZE(handle); i++) 3259231bf117SDan Williams if (nfit_handle == handle[i]) 3260231bf117SDan Williams dev_set_drvdata(nfit_test->dimm_dev[i], 3261231bf117SDan Williams nfit_mem); 3262231bf117SDan Williams } 3263231bf117SDan Williams mutex_unlock(&acpi_desc->init_mutex); 32646bc75619SDan Williams 32656bc75619SDan Williams return 0; 32666bc75619SDan Williams } 32676bc75619SDan Williams 32686bc75619SDan Williams static int nfit_test_remove(struct platform_device *pdev) 32696bc75619SDan Williams { 32706bc75619SDan Williams return 0; 32716bc75619SDan Williams } 32726bc75619SDan Williams 32736bc75619SDan Williams static void nfit_test_release(struct device *dev) 32746bc75619SDan Williams { 32756bc75619SDan Williams struct nfit_test *nfit_test = to_nfit_test(dev); 32766bc75619SDan Williams 32776bc75619SDan Williams kfree(nfit_test); 32786bc75619SDan Williams } 32796bc75619SDan Williams 32806bc75619SDan Williams static const struct platform_device_id nfit_test_id[] = { 32816bc75619SDan Williams { KBUILD_MODNAME }, 32826bc75619SDan Williams { }, 32836bc75619SDan Williams }; 32846bc75619SDan Williams 32856bc75619SDan Williams static struct platform_driver nfit_test_driver = { 32866bc75619SDan Williams .probe = nfit_test_probe, 32876bc75619SDan Williams .remove = nfit_test_remove, 32886bc75619SDan Williams .driver = { 32896bc75619SDan Williams .name = KBUILD_MODNAME, 32906bc75619SDan Williams }, 32916bc75619SDan Williams .id_table = nfit_test_id, 32926bc75619SDan Williams }; 32936bc75619SDan Williams 32946bc75619SDan Williams static __init int nfit_test_init(void) 32956bc75619SDan Williams { 32966bc75619SDan Williams int rc, i; 32976bc75619SDan Williams 32980fb5c8dfSDan Williams pmem_test(); 32990fb5c8dfSDan Williams libnvdimm_test(); 33000fb5c8dfSDan Williams acpi_nfit_test(); 33010fb5c8dfSDan Williams device_dax_test(); 330292f6f2d7SVishal Verma dax_pmem_test(); 330392f6f2d7SVishal Verma dax_pmem_core_test(); 3304c0e71d60SJan Kara #ifdef CONFIG_DEV_DAX_PMEM_COMPAT 330592f6f2d7SVishal Verma dax_pmem_compat_test(); 3306c0e71d60SJan Kara #endif 33070fb5c8dfSDan Williams 3308a7de92daSDan Williams nfit_test_setup(nfit_test_lookup, nfit_test_evaluate_dsm); 3309231bf117SDan Williams 33109fb1a190SDave Jiang nfit_wq = create_singlethread_workqueue("nfit"); 33119fb1a190SDave Jiang if (!nfit_wq) 33129fb1a190SDave Jiang return -ENOMEM; 33139fb1a190SDave Jiang 3314a7de92daSDan Williams nfit_test_dimm = class_create(THIS_MODULE, "nfit_test_dimm"); 3315a7de92daSDan Williams if (IS_ERR(nfit_test_dimm)) { 3316a7de92daSDan Williams rc = PTR_ERR(nfit_test_dimm); 3317a7de92daSDan Williams goto err_register; 3318a7de92daSDan Williams } 33196bc75619SDan Williams 3320e3f5df76SDan Williams nfit_pool = gen_pool_create(ilog2(SZ_4M), NUMA_NO_NODE); 3321e3f5df76SDan Williams if (!nfit_pool) { 3322e3f5df76SDan Williams rc = -ENOMEM; 3323e3f5df76SDan Williams goto err_register; 3324e3f5df76SDan Williams } 3325e3f5df76SDan Williams 3326e3f5df76SDan Williams if (gen_pool_add(nfit_pool, SZ_4G, SZ_4G, NUMA_NO_NODE)) { 3327e3f5df76SDan Williams rc = -ENOMEM; 3328e3f5df76SDan Williams goto err_register; 3329e3f5df76SDan Williams } 3330e3f5df76SDan Williams 33316bc75619SDan Williams for (i = 0; i < NUM_NFITS; i++) { 33326bc75619SDan Williams struct nfit_test *nfit_test; 33336bc75619SDan Williams struct platform_device *pdev; 33346bc75619SDan Williams 33356bc75619SDan Williams nfit_test = kzalloc(sizeof(*nfit_test), GFP_KERNEL); 33366bc75619SDan Williams if (!nfit_test) { 33376bc75619SDan Williams rc = -ENOMEM; 33386bc75619SDan Williams goto err_register; 33396bc75619SDan Williams } 33406bc75619SDan Williams INIT_LIST_HEAD(&nfit_test->resources); 33419fb1a190SDave Jiang badrange_init(&nfit_test->badrange); 33426bc75619SDan Williams switch (i) { 33436bc75619SDan Williams case 0: 33446bc75619SDan Williams nfit_test->num_pm = NUM_PM; 3345dafb1048SDan Williams nfit_test->dcr_idx = 0; 33466bc75619SDan Williams nfit_test->num_dcr = NUM_DCR; 33476bc75619SDan Williams nfit_test->alloc = nfit_test0_alloc; 33486bc75619SDan Williams nfit_test->setup = nfit_test0_setup; 33496bc75619SDan Williams break; 33506bc75619SDan Williams case 1: 3351a117699cSYasunori Goto nfit_test->num_pm = 2; 3352dafb1048SDan Williams nfit_test->dcr_idx = NUM_DCR; 3353ac40b675SDan Williams nfit_test->num_dcr = 2; 33546bc75619SDan Williams nfit_test->alloc = nfit_test1_alloc; 33556bc75619SDan Williams nfit_test->setup = nfit_test1_setup; 33566bc75619SDan Williams break; 33576bc75619SDan Williams default: 33586bc75619SDan Williams rc = -EINVAL; 33596bc75619SDan Williams goto err_register; 33606bc75619SDan Williams } 33616bc75619SDan Williams pdev = &nfit_test->pdev; 33626bc75619SDan Williams pdev->name = KBUILD_MODNAME; 33636bc75619SDan Williams pdev->id = i; 33646bc75619SDan Williams pdev->dev.release = nfit_test_release; 33656bc75619SDan Williams rc = platform_device_register(pdev); 33666bc75619SDan Williams if (rc) { 33676bc75619SDan Williams put_device(&pdev->dev); 33686bc75619SDan Williams goto err_register; 33696bc75619SDan Williams } 33708b06b884SDan Williams get_device(&pdev->dev); 33716bc75619SDan Williams 33726bc75619SDan Williams rc = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); 33736bc75619SDan Williams if (rc) 33746bc75619SDan Williams goto err_register; 33756bc75619SDan Williams 33766bc75619SDan Williams instances[i] = nfit_test; 33779fb1a190SDave Jiang INIT_WORK(&nfit_test->work, uc_error_notify); 33786bc75619SDan Williams } 33796bc75619SDan Williams 33806bc75619SDan Williams rc = platform_driver_register(&nfit_test_driver); 33816bc75619SDan Williams if (rc) 33826bc75619SDan Williams goto err_register; 33836bc75619SDan Williams return 0; 33846bc75619SDan Williams 33856bc75619SDan Williams err_register: 3386e3f5df76SDan Williams if (nfit_pool) 3387e3f5df76SDan Williams gen_pool_destroy(nfit_pool); 3388e3f5df76SDan Williams 33899fb1a190SDave Jiang destroy_workqueue(nfit_wq); 33906bc75619SDan Williams for (i = 0; i < NUM_NFITS; i++) 33916bc75619SDan Williams if (instances[i]) 33926bc75619SDan Williams platform_device_unregister(&instances[i]->pdev); 33936bc75619SDan Williams nfit_test_teardown(); 33948b06b884SDan Williams for (i = 0; i < NUM_NFITS; i++) 33958b06b884SDan Williams if (instances[i]) 33968b06b884SDan Williams put_device(&instances[i]->pdev.dev); 33978b06b884SDan Williams 33986bc75619SDan Williams return rc; 33996bc75619SDan Williams } 34006bc75619SDan Williams 34016bc75619SDan Williams static __exit void nfit_test_exit(void) 34026bc75619SDan Williams { 34036bc75619SDan Williams int i; 34046bc75619SDan Williams 34059fb1a190SDave Jiang flush_workqueue(nfit_wq); 34069fb1a190SDave Jiang destroy_workqueue(nfit_wq); 34076bc75619SDan Williams for (i = 0; i < NUM_NFITS; i++) 34086bc75619SDan Williams platform_device_unregister(&instances[i]->pdev); 34098b06b884SDan Williams platform_driver_unregister(&nfit_test_driver); 34106bc75619SDan Williams nfit_test_teardown(); 34118b06b884SDan Williams 3412e3f5df76SDan Williams gen_pool_destroy(nfit_pool); 3413e3f5df76SDan Williams 34148b06b884SDan Williams for (i = 0; i < NUM_NFITS; i++) 34158b06b884SDan Williams put_device(&instances[i]->pdev.dev); 3416231bf117SDan Williams class_destroy(nfit_test_dimm); 34176bc75619SDan Williams } 34186bc75619SDan Williams 34196bc75619SDan Williams module_init(nfit_test_init); 34206bc75619SDan Williams module_exit(nfit_test_exit); 34216bc75619SDan Williams MODULE_LICENSE("GPL v2"); 34226bc75619SDan Williams MODULE_AUTHOR("Intel Corporation"); 3423