16bc75619SDan Williams /* 26bc75619SDan Williams * Copyright(c) 2013-2015 Intel Corporation. All rights reserved. 36bc75619SDan Williams * 46bc75619SDan Williams * This program is free software; you can redistribute it and/or modify 56bc75619SDan Williams * it under the terms of version 2 of the GNU General Public License as 66bc75619SDan Williams * published by the Free Software Foundation. 76bc75619SDan Williams * 86bc75619SDan Williams * This program is distributed in the hope that it will be useful, but 96bc75619SDan Williams * WITHOUT ANY WARRANTY; without even the implied warranty of 106bc75619SDan Williams * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 116bc75619SDan Williams * General Public License for more details. 126bc75619SDan Williams */ 136bc75619SDan Williams #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 146bc75619SDan Williams #include <linux/platform_device.h> 156bc75619SDan Williams #include <linux/dma-mapping.h> 16d8d378faSDan Williams #include <linux/workqueue.h> 176bc75619SDan Williams #include <linux/libnvdimm.h> 186bc75619SDan Williams #include <linux/vmalloc.h> 196bc75619SDan Williams #include <linux/device.h> 206bc75619SDan Williams #include <linux/module.h> 2120985164SVishal Verma #include <linux/mutex.h> 226bc75619SDan Williams #include <linux/ndctl.h> 236bc75619SDan Williams #include <linux/sizes.h> 2420985164SVishal Verma #include <linux/list.h> 256bc75619SDan Williams #include <linux/slab.h> 26a7de92daSDan Williams #include <nd-core.h> 276bc75619SDan Williams #include <nfit.h> 286bc75619SDan Williams #include <nd.h> 296bc75619SDan Williams #include "nfit_test.h" 306bc75619SDan Williams 316bc75619SDan Williams /* 326bc75619SDan Williams * Generate an NFIT table to describe the following topology: 336bc75619SDan Williams * 346bc75619SDan Williams * BUS0: Interleaved PMEM regions, and aliasing with BLK regions 356bc75619SDan Williams * 366bc75619SDan Williams * (a) (b) DIMM BLK-REGION 376bc75619SDan Williams * +----------+--------------+----------+---------+ 386bc75619SDan Williams * +------+ | blk2.0 | pm0.0 | blk2.1 | pm1.0 | 0 region2 396bc75619SDan Williams * | imc0 +--+- - - - - region0 - - - -+----------+ + 406bc75619SDan Williams * +--+---+ | blk3.0 | pm0.0 | blk3.1 | pm1.0 | 1 region3 416bc75619SDan Williams * | +----------+--------------v----------v v 426bc75619SDan Williams * +--+---+ | | 436bc75619SDan Williams * | cpu0 | region1 446bc75619SDan Williams * +--+---+ | | 456bc75619SDan Williams * | +-------------------------^----------^ ^ 466bc75619SDan Williams * +--+---+ | blk4.0 | pm1.0 | 2 region4 476bc75619SDan Williams * | imc1 +--+-------------------------+----------+ + 486bc75619SDan Williams * +------+ | blk5.0 | pm1.0 | 3 region5 496bc75619SDan Williams * +-------------------------+----------+-+-------+ 506bc75619SDan Williams * 5120985164SVishal Verma * +--+---+ 5220985164SVishal Verma * | cpu1 | 5320985164SVishal Verma * +--+---+ (Hotplug DIMM) 5420985164SVishal Verma * | +----------------------------------------------+ 5520985164SVishal Verma * +--+---+ | blk6.0/pm7.0 | 4 region6/7 5620985164SVishal Verma * | imc0 +--+----------------------------------------------+ 5720985164SVishal Verma * +------+ 5820985164SVishal Verma * 5920985164SVishal Verma * 606bc75619SDan Williams * *) In this layout we have four dimms and two memory controllers in one 616bc75619SDan Williams * socket. Each unique interface (BLK or PMEM) to DPA space 626bc75619SDan Williams * is identified by a region device with a dynamically assigned id. 636bc75619SDan Williams * 646bc75619SDan Williams * *) The first portion of dimm0 and dimm1 are interleaved as REGION0. 656bc75619SDan Williams * A single PMEM namespace "pm0.0" is created using half of the 666bc75619SDan Williams * REGION0 SPA-range. REGION0 spans dimm0 and dimm1. PMEM namespace 676bc75619SDan Williams * allocate from from the bottom of a region. The unallocated 686bc75619SDan Williams * portion of REGION0 aliases with REGION2 and REGION3. That 696bc75619SDan Williams * unallacted capacity is reclaimed as BLK namespaces ("blk2.0" and 706bc75619SDan Williams * "blk3.0") starting at the base of each DIMM to offset (a) in those 716bc75619SDan Williams * DIMMs. "pm0.0", "blk2.0" and "blk3.0" are free-form readable 726bc75619SDan Williams * names that can be assigned to a namespace. 736bc75619SDan Williams * 746bc75619SDan Williams * *) In the last portion of dimm0 and dimm1 we have an interleaved 756bc75619SDan Williams * SPA range, REGION1, that spans those two dimms as well as dimm2 766bc75619SDan Williams * and dimm3. Some of REGION1 allocated to a PMEM namespace named 776bc75619SDan Williams * "pm1.0" the rest is reclaimed in 4 BLK namespaces (for each 786bc75619SDan Williams * dimm in the interleave set), "blk2.1", "blk3.1", "blk4.0", and 796bc75619SDan Williams * "blk5.0". 806bc75619SDan Williams * 816bc75619SDan Williams * *) The portion of dimm2 and dimm3 that do not participate in the 826bc75619SDan Williams * REGION1 interleaved SPA range (i.e. the DPA address below offset 836bc75619SDan Williams * (b) are also included in the "blk4.0" and "blk5.0" namespaces. 846bc75619SDan Williams * Note, that BLK namespaces need not be contiguous in DPA-space, and 856bc75619SDan Williams * can consume aliased capacity from multiple interleave sets. 866bc75619SDan Williams * 876bc75619SDan Williams * BUS1: Legacy NVDIMM (single contiguous range) 886bc75619SDan Williams * 896bc75619SDan Williams * region2 906bc75619SDan Williams * +---------------------+ 916bc75619SDan Williams * |---------------------| 926bc75619SDan Williams * || pm2.0 || 936bc75619SDan Williams * |---------------------| 946bc75619SDan Williams * +---------------------+ 956bc75619SDan Williams * 966bc75619SDan Williams * *) A NFIT-table may describe a simple system-physical-address range 976bc75619SDan Williams * with no BLK aliasing. This type of region may optionally 986bc75619SDan Williams * reference an NVDIMM. 996bc75619SDan Williams */ 1006bc75619SDan Williams enum { 10120985164SVishal Verma NUM_PM = 3, 10220985164SVishal Verma NUM_DCR = 5, 10385d3fa02SDan Williams NUM_HINTS = 8, 1046bc75619SDan Williams NUM_BDW = NUM_DCR, 1056bc75619SDan Williams NUM_SPA = NUM_PM + NUM_DCR + NUM_BDW, 1066bc75619SDan Williams NUM_MEM = NUM_DCR + NUM_BDW + 2 /* spa0 iset */ + 4 /* spa1 iset */, 1076bc75619SDan Williams DIMM_SIZE = SZ_32M, 1086bc75619SDan Williams LABEL_SIZE = SZ_128K, 1097bfe97c7SDan Williams SPA_VCD_SIZE = SZ_4M, 1106bc75619SDan Williams SPA0_SIZE = DIMM_SIZE, 1116bc75619SDan Williams SPA1_SIZE = DIMM_SIZE*2, 1126bc75619SDan Williams SPA2_SIZE = DIMM_SIZE, 1136bc75619SDan Williams BDW_SIZE = 64 << 8, 1146bc75619SDan Williams DCR_SIZE = 12, 1156bc75619SDan Williams NUM_NFITS = 2, /* permit testing multiple NFITs per system */ 1166bc75619SDan Williams }; 1176bc75619SDan Williams 1186bc75619SDan Williams struct nfit_test_dcr { 1196bc75619SDan Williams __le64 bdw_addr; 1206bc75619SDan Williams __le32 bdw_status; 1216bc75619SDan Williams __u8 aperature[BDW_SIZE]; 1226bc75619SDan Williams }; 1236bc75619SDan Williams 1246bc75619SDan Williams #define NFIT_DIMM_HANDLE(node, socket, imc, chan, dimm) \ 1256bc75619SDan Williams (((node & 0xfff) << 16) | ((socket & 0xf) << 12) \ 1266bc75619SDan Williams | ((imc & 0xf) << 8) | ((chan & 0xf) << 4) | (dimm & 0xf)) 1276bc75619SDan Williams 128dafb1048SDan Williams static u32 handle[] = { 1296bc75619SDan Williams [0] = NFIT_DIMM_HANDLE(0, 0, 0, 0, 0), 1306bc75619SDan Williams [1] = NFIT_DIMM_HANDLE(0, 0, 0, 0, 1), 1316bc75619SDan Williams [2] = NFIT_DIMM_HANDLE(0, 0, 1, 0, 0), 1326bc75619SDan Williams [3] = NFIT_DIMM_HANDLE(0, 0, 1, 0, 1), 13320985164SVishal Verma [4] = NFIT_DIMM_HANDLE(0, 1, 0, 0, 0), 134dafb1048SDan Williams [5] = NFIT_DIMM_HANDLE(1, 0, 0, 0, 0), 135ac40b675SDan Williams [6] = NFIT_DIMM_HANDLE(1, 0, 0, 0, 1), 1366bc75619SDan Williams }; 1376bc75619SDan Williams 13873606afdSDan Williams static unsigned long dimm_fail_cmd_flags[NUM_DCR]; 13973606afdSDan Williams 140*bfbaa952SDave Jiang struct nfit_test_fw { 141*bfbaa952SDave Jiang enum intel_fw_update_state state; 142*bfbaa952SDave Jiang u32 context; 143*bfbaa952SDave Jiang u64 version; 144*bfbaa952SDave Jiang u32 size_received; 145*bfbaa952SDave Jiang u64 end_time; 146*bfbaa952SDave Jiang }; 147*bfbaa952SDave Jiang 1486bc75619SDan Williams struct nfit_test { 1496bc75619SDan Williams struct acpi_nfit_desc acpi_desc; 1506bc75619SDan Williams struct platform_device pdev; 1516bc75619SDan Williams struct list_head resources; 1526bc75619SDan Williams void *nfit_buf; 1536bc75619SDan Williams dma_addr_t nfit_dma; 1546bc75619SDan Williams size_t nfit_size; 155dafb1048SDan Williams int dcr_idx; 1566bc75619SDan Williams int num_dcr; 1576bc75619SDan Williams int num_pm; 1586bc75619SDan Williams void **dimm; 1596bc75619SDan Williams dma_addr_t *dimm_dma; 1609d27a87eSDan Williams void **flush; 1619d27a87eSDan Williams dma_addr_t *flush_dma; 1626bc75619SDan Williams void **label; 1636bc75619SDan Williams dma_addr_t *label_dma; 1646bc75619SDan Williams void **spa_set; 1656bc75619SDan Williams dma_addr_t *spa_set_dma; 1666bc75619SDan Williams struct nfit_test_dcr **dcr; 1676bc75619SDan Williams dma_addr_t *dcr_dma; 1686bc75619SDan Williams int (*alloc)(struct nfit_test *t); 1696bc75619SDan Williams void (*setup)(struct nfit_test *t); 17020985164SVishal Verma int setup_hotplug; 171c14a868aSDan Williams union acpi_object **_fit; 172c14a868aSDan Williams dma_addr_t _fit_dma; 173f471f1a7SDan Williams struct ars_state { 174f471f1a7SDan Williams struct nd_cmd_ars_status *ars_status; 175f471f1a7SDan Williams unsigned long deadline; 176f471f1a7SDan Williams spinlock_t lock; 177f471f1a7SDan Williams } ars_state; 178231bf117SDan Williams struct device *dimm_dev[NUM_DCR]; 179ed07c433SDan Williams struct nd_intel_smart *smart; 180ed07c433SDan Williams struct nd_intel_smart_threshold *smart_threshold; 1819fb1a190SDave Jiang struct badrange badrange; 1829fb1a190SDave Jiang struct work_struct work; 183*bfbaa952SDave Jiang struct nfit_test_fw *fw; 1846bc75619SDan Williams }; 1856bc75619SDan Williams 1869fb1a190SDave Jiang static struct workqueue_struct *nfit_wq; 1879fb1a190SDave Jiang 1886bc75619SDan Williams static struct nfit_test *to_nfit_test(struct device *dev) 1896bc75619SDan Williams { 1906bc75619SDan Williams struct platform_device *pdev = to_platform_device(dev); 1916bc75619SDan Williams 1926bc75619SDan Williams return container_of(pdev, struct nfit_test, pdev); 1936bc75619SDan Williams } 1946bc75619SDan Williams 195*bfbaa952SDave Jiang static int nd_intel_test_get_fw_info(struct nfit_test *t, 196*bfbaa952SDave Jiang struct nd_intel_fw_info *nd_cmd, unsigned int buf_len, 197*bfbaa952SDave Jiang int idx) 198*bfbaa952SDave Jiang { 199*bfbaa952SDave Jiang struct device *dev = &t->pdev.dev; 200*bfbaa952SDave Jiang struct nfit_test_fw *fw = &t->fw[idx]; 201*bfbaa952SDave Jiang 202*bfbaa952SDave Jiang dev_dbg(dev, "%s(nfit_test: %p nd_cmd: %p, buf_len: %u, idx: %d\n", 203*bfbaa952SDave Jiang __func__, t, nd_cmd, buf_len, idx); 204*bfbaa952SDave Jiang 205*bfbaa952SDave Jiang if (buf_len < sizeof(*nd_cmd)) 206*bfbaa952SDave Jiang return -EINVAL; 207*bfbaa952SDave Jiang 208*bfbaa952SDave Jiang nd_cmd->status = 0; 209*bfbaa952SDave Jiang nd_cmd->storage_size = INTEL_FW_STORAGE_SIZE; 210*bfbaa952SDave Jiang nd_cmd->max_send_len = INTEL_FW_MAX_SEND_LEN; 211*bfbaa952SDave Jiang nd_cmd->query_interval = INTEL_FW_QUERY_INTERVAL; 212*bfbaa952SDave Jiang nd_cmd->max_query_time = INTEL_FW_QUERY_MAX_TIME; 213*bfbaa952SDave Jiang nd_cmd->update_cap = 0; 214*bfbaa952SDave Jiang nd_cmd->fis_version = INTEL_FW_FIS_VERSION; 215*bfbaa952SDave Jiang nd_cmd->run_version = 0; 216*bfbaa952SDave Jiang nd_cmd->updated_version = fw->version; 217*bfbaa952SDave Jiang 218*bfbaa952SDave Jiang return 0; 219*bfbaa952SDave Jiang } 220*bfbaa952SDave Jiang 221*bfbaa952SDave Jiang static int nd_intel_test_start_update(struct nfit_test *t, 222*bfbaa952SDave Jiang struct nd_intel_fw_start *nd_cmd, unsigned int buf_len, 223*bfbaa952SDave Jiang int idx) 224*bfbaa952SDave Jiang { 225*bfbaa952SDave Jiang struct device *dev = &t->pdev.dev; 226*bfbaa952SDave Jiang struct nfit_test_fw *fw = &t->fw[idx]; 227*bfbaa952SDave Jiang 228*bfbaa952SDave Jiang dev_dbg(dev, "%s(nfit_test: %p nd_cmd: %p buf_len: %u idx: %d)\n", 229*bfbaa952SDave Jiang __func__, t, nd_cmd, buf_len, idx); 230*bfbaa952SDave Jiang 231*bfbaa952SDave Jiang if (buf_len < sizeof(*nd_cmd)) 232*bfbaa952SDave Jiang return -EINVAL; 233*bfbaa952SDave Jiang 234*bfbaa952SDave Jiang if (fw->state != FW_STATE_NEW) { 235*bfbaa952SDave Jiang /* extended status, FW update in progress */ 236*bfbaa952SDave Jiang nd_cmd->status = 0x10007; 237*bfbaa952SDave Jiang return 0; 238*bfbaa952SDave Jiang } 239*bfbaa952SDave Jiang 240*bfbaa952SDave Jiang fw->state = FW_STATE_IN_PROGRESS; 241*bfbaa952SDave Jiang fw->context++; 242*bfbaa952SDave Jiang fw->size_received = 0; 243*bfbaa952SDave Jiang nd_cmd->status = 0; 244*bfbaa952SDave Jiang nd_cmd->context = fw->context; 245*bfbaa952SDave Jiang 246*bfbaa952SDave Jiang dev_dbg(dev, "%s: context issued: %#x\n", __func__, nd_cmd->context); 247*bfbaa952SDave Jiang 248*bfbaa952SDave Jiang return 0; 249*bfbaa952SDave Jiang } 250*bfbaa952SDave Jiang 251*bfbaa952SDave Jiang static int nd_intel_test_send_data(struct nfit_test *t, 252*bfbaa952SDave Jiang struct nd_intel_fw_send_data *nd_cmd, unsigned int buf_len, 253*bfbaa952SDave Jiang int idx) 254*bfbaa952SDave Jiang { 255*bfbaa952SDave Jiang struct device *dev = &t->pdev.dev; 256*bfbaa952SDave Jiang struct nfit_test_fw *fw = &t->fw[idx]; 257*bfbaa952SDave Jiang u32 *status = (u32 *)&nd_cmd->data[nd_cmd->length]; 258*bfbaa952SDave Jiang 259*bfbaa952SDave Jiang dev_dbg(dev, "%s(nfit_test: %p nd_cmd: %p buf_len: %u idx: %d)\n", 260*bfbaa952SDave Jiang __func__, t, nd_cmd, buf_len, idx); 261*bfbaa952SDave Jiang 262*bfbaa952SDave Jiang if (buf_len < sizeof(*nd_cmd)) 263*bfbaa952SDave Jiang return -EINVAL; 264*bfbaa952SDave Jiang 265*bfbaa952SDave Jiang 266*bfbaa952SDave Jiang dev_dbg(dev, "%s: cmd->status: %#x\n", __func__, *status); 267*bfbaa952SDave Jiang dev_dbg(dev, "%s: cmd->data[0]: %#x\n", __func__, nd_cmd->data[0]); 268*bfbaa952SDave Jiang dev_dbg(dev, "%s: cmd->data[%u]: %#x\n", __func__, nd_cmd->length-1, 269*bfbaa952SDave Jiang nd_cmd->data[nd_cmd->length-1]); 270*bfbaa952SDave Jiang 271*bfbaa952SDave Jiang if (fw->state != FW_STATE_IN_PROGRESS) { 272*bfbaa952SDave Jiang dev_dbg(dev, "%s: not in IN_PROGRESS state\n", __func__); 273*bfbaa952SDave Jiang *status = 0x5; 274*bfbaa952SDave Jiang return 0; 275*bfbaa952SDave Jiang } 276*bfbaa952SDave Jiang 277*bfbaa952SDave Jiang if (nd_cmd->context != fw->context) { 278*bfbaa952SDave Jiang dev_dbg(dev, "%s: incorrect context: in: %#x correct: %#x\n", 279*bfbaa952SDave Jiang __func__, nd_cmd->context, fw->context); 280*bfbaa952SDave Jiang *status = 0x10007; 281*bfbaa952SDave Jiang return 0; 282*bfbaa952SDave Jiang } 283*bfbaa952SDave Jiang 284*bfbaa952SDave Jiang /* 285*bfbaa952SDave Jiang * check offset + len > size of fw storage 286*bfbaa952SDave Jiang * check length is > max send length 287*bfbaa952SDave Jiang */ 288*bfbaa952SDave Jiang if (nd_cmd->offset + nd_cmd->length > INTEL_FW_STORAGE_SIZE || 289*bfbaa952SDave Jiang nd_cmd->length > INTEL_FW_MAX_SEND_LEN) { 290*bfbaa952SDave Jiang *status = 0x3; 291*bfbaa952SDave Jiang dev_dbg(dev, "%s: buffer boundary violation\n", __func__); 292*bfbaa952SDave Jiang return 0; 293*bfbaa952SDave Jiang } 294*bfbaa952SDave Jiang 295*bfbaa952SDave Jiang fw->size_received += nd_cmd->length; 296*bfbaa952SDave Jiang dev_dbg(dev, "%s: copying %u bytes, %u bytes so far\n", 297*bfbaa952SDave Jiang __func__, nd_cmd->length, fw->size_received); 298*bfbaa952SDave Jiang *status = 0; 299*bfbaa952SDave Jiang return 0; 300*bfbaa952SDave Jiang } 301*bfbaa952SDave Jiang 302*bfbaa952SDave Jiang static int nd_intel_test_finish_fw(struct nfit_test *t, 303*bfbaa952SDave Jiang struct nd_intel_fw_finish_update *nd_cmd, 304*bfbaa952SDave Jiang unsigned int buf_len, int idx) 305*bfbaa952SDave Jiang { 306*bfbaa952SDave Jiang struct device *dev = &t->pdev.dev; 307*bfbaa952SDave Jiang struct nfit_test_fw *fw = &t->fw[idx]; 308*bfbaa952SDave Jiang 309*bfbaa952SDave Jiang dev_dbg(dev, "%s(nfit_test: %p nd_cmd: %p buf_len: %u idx: %d)\n", 310*bfbaa952SDave Jiang __func__, t, nd_cmd, buf_len, idx); 311*bfbaa952SDave Jiang 312*bfbaa952SDave Jiang if (fw->state == FW_STATE_UPDATED) { 313*bfbaa952SDave Jiang /* update already done, need cold boot */ 314*bfbaa952SDave Jiang nd_cmd->status = 0x20007; 315*bfbaa952SDave Jiang return 0; 316*bfbaa952SDave Jiang } 317*bfbaa952SDave Jiang 318*bfbaa952SDave Jiang dev_dbg(dev, "%s: context: %#x ctrl_flags: %#x\n", 319*bfbaa952SDave Jiang __func__, nd_cmd->context, nd_cmd->ctrl_flags); 320*bfbaa952SDave Jiang 321*bfbaa952SDave Jiang switch (nd_cmd->ctrl_flags) { 322*bfbaa952SDave Jiang case 0: /* finish */ 323*bfbaa952SDave Jiang if (nd_cmd->context != fw->context) { 324*bfbaa952SDave Jiang dev_dbg(dev, "%s: incorrect context: in: %#x correct: %#x\n", 325*bfbaa952SDave Jiang __func__, nd_cmd->context, 326*bfbaa952SDave Jiang fw->context); 327*bfbaa952SDave Jiang nd_cmd->status = 0x10007; 328*bfbaa952SDave Jiang return 0; 329*bfbaa952SDave Jiang } 330*bfbaa952SDave Jiang nd_cmd->status = 0; 331*bfbaa952SDave Jiang fw->state = FW_STATE_VERIFY; 332*bfbaa952SDave Jiang /* set 1 second of time for firmware "update" */ 333*bfbaa952SDave Jiang fw->end_time = jiffies + HZ; 334*bfbaa952SDave Jiang break; 335*bfbaa952SDave Jiang 336*bfbaa952SDave Jiang case 1: /* abort */ 337*bfbaa952SDave Jiang fw->size_received = 0; 338*bfbaa952SDave Jiang /* successfully aborted status */ 339*bfbaa952SDave Jiang nd_cmd->status = 0x40007; 340*bfbaa952SDave Jiang fw->state = FW_STATE_NEW; 341*bfbaa952SDave Jiang dev_dbg(dev, "%s: abort successful\n", __func__); 342*bfbaa952SDave Jiang break; 343*bfbaa952SDave Jiang 344*bfbaa952SDave Jiang default: /* bad control flag */ 345*bfbaa952SDave Jiang dev_warn(dev, "%s: unknown control flag: %#x\n", 346*bfbaa952SDave Jiang __func__, nd_cmd->ctrl_flags); 347*bfbaa952SDave Jiang return -EINVAL; 348*bfbaa952SDave Jiang } 349*bfbaa952SDave Jiang 350*bfbaa952SDave Jiang return 0; 351*bfbaa952SDave Jiang } 352*bfbaa952SDave Jiang 353*bfbaa952SDave Jiang static int nd_intel_test_finish_query(struct nfit_test *t, 354*bfbaa952SDave Jiang struct nd_intel_fw_finish_query *nd_cmd, 355*bfbaa952SDave Jiang unsigned int buf_len, int idx) 356*bfbaa952SDave Jiang { 357*bfbaa952SDave Jiang struct device *dev = &t->pdev.dev; 358*bfbaa952SDave Jiang struct nfit_test_fw *fw = &t->fw[idx]; 359*bfbaa952SDave Jiang 360*bfbaa952SDave Jiang dev_dbg(dev, "%s(nfit_test: %p nd_cmd: %p buf_len: %u idx: %d)\n", 361*bfbaa952SDave Jiang __func__, t, nd_cmd, buf_len, idx); 362*bfbaa952SDave Jiang 363*bfbaa952SDave Jiang if (buf_len < sizeof(*nd_cmd)) 364*bfbaa952SDave Jiang return -EINVAL; 365*bfbaa952SDave Jiang 366*bfbaa952SDave Jiang if (nd_cmd->context != fw->context) { 367*bfbaa952SDave Jiang dev_dbg(dev, "%s: incorrect context: in: %#x correct: %#x\n", 368*bfbaa952SDave Jiang __func__, nd_cmd->context, fw->context); 369*bfbaa952SDave Jiang nd_cmd->status = 0x10007; 370*bfbaa952SDave Jiang return 0; 371*bfbaa952SDave Jiang } 372*bfbaa952SDave Jiang 373*bfbaa952SDave Jiang dev_dbg(dev, "%s context: %#x\n", __func__, nd_cmd->context); 374*bfbaa952SDave Jiang 375*bfbaa952SDave Jiang switch (fw->state) { 376*bfbaa952SDave Jiang case FW_STATE_NEW: 377*bfbaa952SDave Jiang nd_cmd->updated_fw_rev = 0; 378*bfbaa952SDave Jiang nd_cmd->status = 0; 379*bfbaa952SDave Jiang dev_dbg(dev, "%s: new state\n", __func__); 380*bfbaa952SDave Jiang break; 381*bfbaa952SDave Jiang 382*bfbaa952SDave Jiang case FW_STATE_IN_PROGRESS: 383*bfbaa952SDave Jiang /* sequencing error */ 384*bfbaa952SDave Jiang nd_cmd->status = 0x40007; 385*bfbaa952SDave Jiang nd_cmd->updated_fw_rev = 0; 386*bfbaa952SDave Jiang dev_dbg(dev, "%s: sequence error\n", __func__); 387*bfbaa952SDave Jiang break; 388*bfbaa952SDave Jiang 389*bfbaa952SDave Jiang case FW_STATE_VERIFY: 390*bfbaa952SDave Jiang if (time_is_after_jiffies64(fw->end_time)) { 391*bfbaa952SDave Jiang nd_cmd->updated_fw_rev = 0; 392*bfbaa952SDave Jiang nd_cmd->status = 0x20007; 393*bfbaa952SDave Jiang dev_dbg(dev, "%s: still verifying\n", __func__); 394*bfbaa952SDave Jiang break; 395*bfbaa952SDave Jiang } 396*bfbaa952SDave Jiang 397*bfbaa952SDave Jiang dev_dbg(dev, "%s: transition out verify\n", __func__); 398*bfbaa952SDave Jiang fw->state = FW_STATE_UPDATED; 399*bfbaa952SDave Jiang /* we are going to fall through if it's "done" */ 400*bfbaa952SDave Jiang case FW_STATE_UPDATED: 401*bfbaa952SDave Jiang nd_cmd->status = 0; 402*bfbaa952SDave Jiang /* bogus test version */ 403*bfbaa952SDave Jiang fw->version = nd_cmd->updated_fw_rev = 404*bfbaa952SDave Jiang INTEL_FW_FAKE_VERSION; 405*bfbaa952SDave Jiang dev_dbg(dev, "%s: updated\n", __func__); 406*bfbaa952SDave Jiang break; 407*bfbaa952SDave Jiang 408*bfbaa952SDave Jiang default: /* we should never get here */ 409*bfbaa952SDave Jiang return -EINVAL; 410*bfbaa952SDave Jiang } 411*bfbaa952SDave Jiang 412*bfbaa952SDave Jiang return 0; 413*bfbaa952SDave Jiang } 414*bfbaa952SDave Jiang 41539c686b8SVishal Verma static int nfit_test_cmd_get_config_size(struct nd_cmd_get_config_size *nd_cmd, 4166bc75619SDan Williams unsigned int buf_len) 4176bc75619SDan Williams { 4186bc75619SDan Williams if (buf_len < sizeof(*nd_cmd)) 4196bc75619SDan Williams return -EINVAL; 42039c686b8SVishal Verma 4216bc75619SDan Williams nd_cmd->status = 0; 4226bc75619SDan Williams nd_cmd->config_size = LABEL_SIZE; 4236bc75619SDan Williams nd_cmd->max_xfer = SZ_4K; 42439c686b8SVishal Verma 42539c686b8SVishal Verma return 0; 4266bc75619SDan Williams } 42739c686b8SVishal Verma 42839c686b8SVishal Verma static int nfit_test_cmd_get_config_data(struct nd_cmd_get_config_data_hdr 42939c686b8SVishal Verma *nd_cmd, unsigned int buf_len, void *label) 43039c686b8SVishal Verma { 4316bc75619SDan Williams unsigned int len, offset = nd_cmd->in_offset; 43239c686b8SVishal Verma int rc; 4336bc75619SDan Williams 4346bc75619SDan Williams if (buf_len < sizeof(*nd_cmd)) 4356bc75619SDan Williams return -EINVAL; 4366bc75619SDan Williams if (offset >= LABEL_SIZE) 4376bc75619SDan Williams return -EINVAL; 4386bc75619SDan Williams if (nd_cmd->in_length + sizeof(*nd_cmd) > buf_len) 4396bc75619SDan Williams return -EINVAL; 4406bc75619SDan Williams 4416bc75619SDan Williams nd_cmd->status = 0; 4426bc75619SDan Williams len = min(nd_cmd->in_length, LABEL_SIZE - offset); 44339c686b8SVishal Verma memcpy(nd_cmd->out_buf, label + offset, len); 4446bc75619SDan Williams rc = buf_len - sizeof(*nd_cmd) - len; 44539c686b8SVishal Verma 44639c686b8SVishal Verma return rc; 4476bc75619SDan Williams } 44839c686b8SVishal Verma 44939c686b8SVishal Verma static int nfit_test_cmd_set_config_data(struct nd_cmd_set_config_hdr *nd_cmd, 45039c686b8SVishal Verma unsigned int buf_len, void *label) 45139c686b8SVishal Verma { 4526bc75619SDan Williams unsigned int len, offset = nd_cmd->in_offset; 4536bc75619SDan Williams u32 *status; 45439c686b8SVishal Verma int rc; 4556bc75619SDan Williams 4566bc75619SDan Williams if (buf_len < sizeof(*nd_cmd)) 4576bc75619SDan Williams return -EINVAL; 4586bc75619SDan Williams if (offset >= LABEL_SIZE) 4596bc75619SDan Williams return -EINVAL; 4606bc75619SDan Williams if (nd_cmd->in_length + sizeof(*nd_cmd) + 4 > buf_len) 4616bc75619SDan Williams return -EINVAL; 4626bc75619SDan Williams 46339c686b8SVishal Verma status = (void *)nd_cmd + nd_cmd->in_length + sizeof(*nd_cmd); 4646bc75619SDan Williams *status = 0; 4656bc75619SDan Williams len = min(nd_cmd->in_length, LABEL_SIZE - offset); 46639c686b8SVishal Verma memcpy(label + offset, nd_cmd->in_buf, len); 4676bc75619SDan Williams rc = buf_len - sizeof(*nd_cmd) - (len + 4); 46839c686b8SVishal Verma 46939c686b8SVishal Verma return rc; 4706bc75619SDan Williams } 47139c686b8SVishal Verma 472d4f32367SDan Williams #define NFIT_TEST_CLEAR_ERR_UNIT 256 473747ffe11SDan Williams 47439c686b8SVishal Verma static int nfit_test_cmd_ars_cap(struct nd_cmd_ars_cap *nd_cmd, 47539c686b8SVishal Verma unsigned int buf_len) 47639c686b8SVishal Verma { 4779fb1a190SDave Jiang int ars_recs; 4789fb1a190SDave Jiang 47939c686b8SVishal Verma if (buf_len < sizeof(*nd_cmd)) 48039c686b8SVishal Verma return -EINVAL; 48139c686b8SVishal Verma 4829fb1a190SDave Jiang /* for testing, only store up to n records that fit within 4k */ 4839fb1a190SDave Jiang ars_recs = SZ_4K / sizeof(struct nd_ars_record); 4849fb1a190SDave Jiang 485747ffe11SDan Williams nd_cmd->max_ars_out = sizeof(struct nd_cmd_ars_status) 4869fb1a190SDave Jiang + ars_recs * sizeof(struct nd_ars_record); 48739c686b8SVishal Verma nd_cmd->status = (ND_ARS_PERSISTENT | ND_ARS_VOLATILE) << 16; 488d4f32367SDan Williams nd_cmd->clear_err_unit = NFIT_TEST_CLEAR_ERR_UNIT; 48939c686b8SVishal Verma 49039c686b8SVishal Verma return 0; 49139c686b8SVishal Verma } 49239c686b8SVishal Verma 4939fb1a190SDave Jiang static void post_ars_status(struct ars_state *ars_state, 4949fb1a190SDave Jiang struct badrange *badrange, u64 addr, u64 len) 49539c686b8SVishal Verma { 496f471f1a7SDan Williams struct nd_cmd_ars_status *ars_status; 497f471f1a7SDan Williams struct nd_ars_record *ars_record; 4989fb1a190SDave Jiang struct badrange_entry *be; 4999fb1a190SDave Jiang u64 end = addr + len - 1; 5009fb1a190SDave Jiang int i = 0; 501f471f1a7SDan Williams 502f471f1a7SDan Williams ars_state->deadline = jiffies + 1*HZ; 503f471f1a7SDan Williams ars_status = ars_state->ars_status; 504f471f1a7SDan Williams ars_status->status = 0; 505f471f1a7SDan Williams ars_status->address = addr; 506f471f1a7SDan Williams ars_status->length = len; 507f471f1a7SDan Williams ars_status->type = ND_ARS_PERSISTENT; 5089fb1a190SDave Jiang 5099fb1a190SDave Jiang spin_lock(&badrange->lock); 5109fb1a190SDave Jiang list_for_each_entry(be, &badrange->list, list) { 5119fb1a190SDave Jiang u64 be_end = be->start + be->length - 1; 5129fb1a190SDave Jiang u64 rstart, rend; 5139fb1a190SDave Jiang 5149fb1a190SDave Jiang /* skip entries outside the range */ 5159fb1a190SDave Jiang if (be_end < addr || be->start > end) 5169fb1a190SDave Jiang continue; 5179fb1a190SDave Jiang 5189fb1a190SDave Jiang rstart = (be->start < addr) ? addr : be->start; 5199fb1a190SDave Jiang rend = (be_end < end) ? be_end : end; 5209fb1a190SDave Jiang ars_record = &ars_status->records[i]; 521f471f1a7SDan Williams ars_record->handle = 0; 5229fb1a190SDave Jiang ars_record->err_address = rstart; 5239fb1a190SDave Jiang ars_record->length = rend - rstart + 1; 5249fb1a190SDave Jiang i++; 5259fb1a190SDave Jiang } 5269fb1a190SDave Jiang spin_unlock(&badrange->lock); 5279fb1a190SDave Jiang ars_status->num_records = i; 5289fb1a190SDave Jiang ars_status->out_length = sizeof(struct nd_cmd_ars_status) 5299fb1a190SDave Jiang + i * sizeof(struct nd_ars_record); 530f471f1a7SDan Williams } 531f471f1a7SDan Williams 5329fb1a190SDave Jiang static int nfit_test_cmd_ars_start(struct nfit_test *t, 5339fb1a190SDave Jiang struct ars_state *ars_state, 534f471f1a7SDan Williams struct nd_cmd_ars_start *ars_start, unsigned int buf_len, 535f471f1a7SDan Williams int *cmd_rc) 536f471f1a7SDan Williams { 537f471f1a7SDan Williams if (buf_len < sizeof(*ars_start)) 53839c686b8SVishal Verma return -EINVAL; 53939c686b8SVishal Verma 540f471f1a7SDan Williams spin_lock(&ars_state->lock); 541f471f1a7SDan Williams if (time_before(jiffies, ars_state->deadline)) { 542f471f1a7SDan Williams ars_start->status = NFIT_ARS_START_BUSY; 543f471f1a7SDan Williams *cmd_rc = -EBUSY; 544f471f1a7SDan Williams } else { 545f471f1a7SDan Williams ars_start->status = 0; 546f471f1a7SDan Williams ars_start->scrub_time = 1; 5479fb1a190SDave Jiang post_ars_status(ars_state, &t->badrange, ars_start->address, 548f471f1a7SDan Williams ars_start->length); 549f471f1a7SDan Williams *cmd_rc = 0; 550f471f1a7SDan Williams } 551f471f1a7SDan Williams spin_unlock(&ars_state->lock); 55239c686b8SVishal Verma 55339c686b8SVishal Verma return 0; 55439c686b8SVishal Verma } 55539c686b8SVishal Verma 556f471f1a7SDan Williams static int nfit_test_cmd_ars_status(struct ars_state *ars_state, 557f471f1a7SDan Williams struct nd_cmd_ars_status *ars_status, unsigned int buf_len, 558f471f1a7SDan Williams int *cmd_rc) 55939c686b8SVishal Verma { 560f471f1a7SDan Williams if (buf_len < ars_state->ars_status->out_length) 56139c686b8SVishal Verma return -EINVAL; 56239c686b8SVishal Verma 563f471f1a7SDan Williams spin_lock(&ars_state->lock); 564f471f1a7SDan Williams if (time_before(jiffies, ars_state->deadline)) { 565f471f1a7SDan Williams memset(ars_status, 0, buf_len); 566f471f1a7SDan Williams ars_status->status = NFIT_ARS_STATUS_BUSY; 567f471f1a7SDan Williams ars_status->out_length = sizeof(*ars_status); 568f471f1a7SDan Williams *cmd_rc = -EBUSY; 569f471f1a7SDan Williams } else { 570f471f1a7SDan Williams memcpy(ars_status, ars_state->ars_status, 571f471f1a7SDan Williams ars_state->ars_status->out_length); 572f471f1a7SDan Williams *cmd_rc = 0; 573f471f1a7SDan Williams } 574f471f1a7SDan Williams spin_unlock(&ars_state->lock); 57539c686b8SVishal Verma return 0; 57639c686b8SVishal Verma } 57739c686b8SVishal Verma 5785e096ef3SVishal Verma static int nfit_test_cmd_clear_error(struct nfit_test *t, 5795e096ef3SVishal Verma struct nd_cmd_clear_error *clear_err, 580d4f32367SDan Williams unsigned int buf_len, int *cmd_rc) 581d4f32367SDan Williams { 582d4f32367SDan Williams const u64 mask = NFIT_TEST_CLEAR_ERR_UNIT - 1; 583d4f32367SDan Williams if (buf_len < sizeof(*clear_err)) 584d4f32367SDan Williams return -EINVAL; 585d4f32367SDan Williams 586d4f32367SDan Williams if ((clear_err->address & mask) || (clear_err->length & mask)) 587d4f32367SDan Williams return -EINVAL; 588d4f32367SDan Williams 5895e096ef3SVishal Verma badrange_forget(&t->badrange, clear_err->address, clear_err->length); 590d4f32367SDan Williams clear_err->status = 0; 591d4f32367SDan Williams clear_err->cleared = clear_err->length; 592d4f32367SDan Williams *cmd_rc = 0; 593d4f32367SDan Williams return 0; 594d4f32367SDan Williams } 595d4f32367SDan Williams 59610246dc8SYasunori Goto struct region_search_spa { 59710246dc8SYasunori Goto u64 addr; 59810246dc8SYasunori Goto struct nd_region *region; 59910246dc8SYasunori Goto }; 60010246dc8SYasunori Goto 60110246dc8SYasunori Goto static int is_region_device(struct device *dev) 60210246dc8SYasunori Goto { 60310246dc8SYasunori Goto return !strncmp(dev->kobj.name, "region", 6); 60410246dc8SYasunori Goto } 60510246dc8SYasunori Goto 60610246dc8SYasunori Goto static int nfit_test_search_region_spa(struct device *dev, void *data) 60710246dc8SYasunori Goto { 60810246dc8SYasunori Goto struct region_search_spa *ctx = data; 60910246dc8SYasunori Goto struct nd_region *nd_region; 61010246dc8SYasunori Goto resource_size_t ndr_end; 61110246dc8SYasunori Goto 61210246dc8SYasunori Goto if (!is_region_device(dev)) 61310246dc8SYasunori Goto return 0; 61410246dc8SYasunori Goto 61510246dc8SYasunori Goto nd_region = to_nd_region(dev); 61610246dc8SYasunori Goto ndr_end = nd_region->ndr_start + nd_region->ndr_size; 61710246dc8SYasunori Goto 61810246dc8SYasunori Goto if (ctx->addr >= nd_region->ndr_start && ctx->addr < ndr_end) { 61910246dc8SYasunori Goto ctx->region = nd_region; 62010246dc8SYasunori Goto return 1; 62110246dc8SYasunori Goto } 62210246dc8SYasunori Goto 62310246dc8SYasunori Goto return 0; 62410246dc8SYasunori Goto } 62510246dc8SYasunori Goto 62610246dc8SYasunori Goto static int nfit_test_search_spa(struct nvdimm_bus *bus, 62710246dc8SYasunori Goto struct nd_cmd_translate_spa *spa) 62810246dc8SYasunori Goto { 62910246dc8SYasunori Goto int ret; 63010246dc8SYasunori Goto struct nd_region *nd_region = NULL; 63110246dc8SYasunori Goto struct nvdimm *nvdimm = NULL; 63210246dc8SYasunori Goto struct nd_mapping *nd_mapping = NULL; 63310246dc8SYasunori Goto struct region_search_spa ctx = { 63410246dc8SYasunori Goto .addr = spa->spa, 63510246dc8SYasunori Goto .region = NULL, 63610246dc8SYasunori Goto }; 63710246dc8SYasunori Goto u64 dpa; 63810246dc8SYasunori Goto 63910246dc8SYasunori Goto ret = device_for_each_child(&bus->dev, &ctx, 64010246dc8SYasunori Goto nfit_test_search_region_spa); 64110246dc8SYasunori Goto 64210246dc8SYasunori Goto if (!ret) 64310246dc8SYasunori Goto return -ENODEV; 64410246dc8SYasunori Goto 64510246dc8SYasunori Goto nd_region = ctx.region; 64610246dc8SYasunori Goto 64710246dc8SYasunori Goto dpa = ctx.addr - nd_region->ndr_start; 64810246dc8SYasunori Goto 64910246dc8SYasunori Goto /* 65010246dc8SYasunori Goto * last dimm is selected for test 65110246dc8SYasunori Goto */ 65210246dc8SYasunori Goto nd_mapping = &nd_region->mapping[nd_region->ndr_mappings - 1]; 65310246dc8SYasunori Goto nvdimm = nd_mapping->nvdimm; 65410246dc8SYasunori Goto 65510246dc8SYasunori Goto spa->devices[0].nfit_device_handle = handle[nvdimm->id]; 65610246dc8SYasunori Goto spa->num_nvdimms = 1; 65710246dc8SYasunori Goto spa->devices[0].dpa = dpa; 65810246dc8SYasunori Goto 65910246dc8SYasunori Goto return 0; 66010246dc8SYasunori Goto } 66110246dc8SYasunori Goto 66210246dc8SYasunori Goto static int nfit_test_cmd_translate_spa(struct nvdimm_bus *bus, 66310246dc8SYasunori Goto struct nd_cmd_translate_spa *spa, unsigned int buf_len) 66410246dc8SYasunori Goto { 66510246dc8SYasunori Goto if (buf_len < spa->translate_length) 66610246dc8SYasunori Goto return -EINVAL; 66710246dc8SYasunori Goto 66810246dc8SYasunori Goto if (nfit_test_search_spa(bus, spa) < 0 || !spa->num_nvdimms) 66910246dc8SYasunori Goto spa->status = 2; 67010246dc8SYasunori Goto 67110246dc8SYasunori Goto return 0; 67210246dc8SYasunori Goto } 67310246dc8SYasunori Goto 674ed07c433SDan Williams static int nfit_test_cmd_smart(struct nd_intel_smart *smart, unsigned int buf_len, 675ed07c433SDan Williams struct nd_intel_smart *smart_data) 676baa51277SDan Williams { 677baa51277SDan Williams if (buf_len < sizeof(*smart)) 678baa51277SDan Williams return -EINVAL; 679ed07c433SDan Williams memcpy(smart, smart_data, sizeof(*smart)); 680baa51277SDan Williams return 0; 681baa51277SDan Williams } 682baa51277SDan Williams 683cdd77d3eSDan Williams static int nfit_test_cmd_smart_threshold( 684ed07c433SDan Williams struct nd_intel_smart_threshold *out, 685ed07c433SDan Williams unsigned int buf_len, 686ed07c433SDan Williams struct nd_intel_smart_threshold *smart_t) 687baa51277SDan Williams { 688baa51277SDan Williams if (buf_len < sizeof(*smart_t)) 689baa51277SDan Williams return -EINVAL; 690ed07c433SDan Williams memcpy(out, smart_t, sizeof(*smart_t)); 691ed07c433SDan Williams return 0; 692ed07c433SDan Williams } 693ed07c433SDan Williams 694ed07c433SDan Williams static void smart_notify(struct device *bus_dev, 695ed07c433SDan Williams struct device *dimm_dev, struct nd_intel_smart *smart, 696ed07c433SDan Williams struct nd_intel_smart_threshold *thresh) 697ed07c433SDan Williams { 698ed07c433SDan Williams dev_dbg(dimm_dev, "%s: alarm: %#x spares: %d (%d) mtemp: %d (%d) ctemp: %d (%d)\n", 699ed07c433SDan Williams __func__, thresh->alarm_control, thresh->spares, 700ed07c433SDan Williams smart->spares, thresh->media_temperature, 701ed07c433SDan Williams smart->media_temperature, thresh->ctrl_temperature, 702ed07c433SDan Williams smart->ctrl_temperature); 703ed07c433SDan Williams if (((thresh->alarm_control & ND_INTEL_SMART_SPARE_TRIP) 704ed07c433SDan Williams && smart->spares 705ed07c433SDan Williams <= thresh->spares) 706ed07c433SDan Williams || ((thresh->alarm_control & ND_INTEL_SMART_TEMP_TRIP) 707ed07c433SDan Williams && smart->media_temperature 708ed07c433SDan Williams >= thresh->media_temperature) 709ed07c433SDan Williams || ((thresh->alarm_control & ND_INTEL_SMART_CTEMP_TRIP) 710ed07c433SDan Williams && smart->ctrl_temperature 711ed07c433SDan Williams >= thresh->ctrl_temperature)) { 712ed07c433SDan Williams device_lock(bus_dev); 713ed07c433SDan Williams __acpi_nvdimm_notify(dimm_dev, 0x81); 714ed07c433SDan Williams device_unlock(bus_dev); 715ed07c433SDan Williams } 716ed07c433SDan Williams } 717ed07c433SDan Williams 718ed07c433SDan Williams static int nfit_test_cmd_smart_set_threshold( 719ed07c433SDan Williams struct nd_intel_smart_set_threshold *in, 720ed07c433SDan Williams unsigned int buf_len, 721ed07c433SDan Williams struct nd_intel_smart_threshold *thresh, 722ed07c433SDan Williams struct nd_intel_smart *smart, 723ed07c433SDan Williams struct device *bus_dev, struct device *dimm_dev) 724ed07c433SDan Williams { 725ed07c433SDan Williams unsigned int size; 726ed07c433SDan Williams 727ed07c433SDan Williams size = sizeof(*in) - 4; 728ed07c433SDan Williams if (buf_len < size) 729ed07c433SDan Williams return -EINVAL; 730ed07c433SDan Williams memcpy(thresh->data, in, size); 731ed07c433SDan Williams in->status = 0; 732ed07c433SDan Williams smart_notify(bus_dev, dimm_dev, smart, thresh); 733ed07c433SDan Williams 734baa51277SDan Williams return 0; 735baa51277SDan Williams } 736baa51277SDan Williams 7379fb1a190SDave Jiang static void uc_error_notify(struct work_struct *work) 7389fb1a190SDave Jiang { 7399fb1a190SDave Jiang struct nfit_test *t = container_of(work, typeof(*t), work); 7409fb1a190SDave Jiang 7419fb1a190SDave Jiang __acpi_nfit_notify(&t->pdev.dev, t, NFIT_NOTIFY_UC_MEMORY_ERROR); 7429fb1a190SDave Jiang } 7439fb1a190SDave Jiang 7449fb1a190SDave Jiang static int nfit_test_cmd_ars_error_inject(struct nfit_test *t, 7459fb1a190SDave Jiang struct nd_cmd_ars_err_inj *err_inj, unsigned int buf_len) 7469fb1a190SDave Jiang { 7479fb1a190SDave Jiang int rc; 7489fb1a190SDave Jiang 74941cb3301SVishal Verma if (buf_len != sizeof(*err_inj)) { 7509fb1a190SDave Jiang rc = -EINVAL; 7519fb1a190SDave Jiang goto err; 7529fb1a190SDave Jiang } 7539fb1a190SDave Jiang 7549fb1a190SDave Jiang if (err_inj->err_inj_spa_range_length <= 0) { 7559fb1a190SDave Jiang rc = -EINVAL; 7569fb1a190SDave Jiang goto err; 7579fb1a190SDave Jiang } 7589fb1a190SDave Jiang 7599fb1a190SDave Jiang rc = badrange_add(&t->badrange, err_inj->err_inj_spa_range_base, 7609fb1a190SDave Jiang err_inj->err_inj_spa_range_length); 7619fb1a190SDave Jiang if (rc < 0) 7629fb1a190SDave Jiang goto err; 7639fb1a190SDave Jiang 7649fb1a190SDave Jiang if (err_inj->err_inj_options & (1 << ND_ARS_ERR_INJ_OPT_NOTIFY)) 7659fb1a190SDave Jiang queue_work(nfit_wq, &t->work); 7669fb1a190SDave Jiang 7679fb1a190SDave Jiang err_inj->status = 0; 7689fb1a190SDave Jiang return 0; 7699fb1a190SDave Jiang 7709fb1a190SDave Jiang err: 7719fb1a190SDave Jiang err_inj->status = NFIT_ARS_INJECT_INVALID; 7729fb1a190SDave Jiang return rc; 7739fb1a190SDave Jiang } 7749fb1a190SDave Jiang 7759fb1a190SDave Jiang static int nfit_test_cmd_ars_inject_clear(struct nfit_test *t, 7769fb1a190SDave Jiang struct nd_cmd_ars_err_inj_clr *err_clr, unsigned int buf_len) 7779fb1a190SDave Jiang { 7789fb1a190SDave Jiang int rc; 7799fb1a190SDave Jiang 78041cb3301SVishal Verma if (buf_len != sizeof(*err_clr)) { 7819fb1a190SDave Jiang rc = -EINVAL; 7829fb1a190SDave Jiang goto err; 7839fb1a190SDave Jiang } 7849fb1a190SDave Jiang 7859fb1a190SDave Jiang if (err_clr->err_inj_clr_spa_range_length <= 0) { 7869fb1a190SDave Jiang rc = -EINVAL; 7879fb1a190SDave Jiang goto err; 7889fb1a190SDave Jiang } 7899fb1a190SDave Jiang 7909fb1a190SDave Jiang badrange_forget(&t->badrange, err_clr->err_inj_clr_spa_range_base, 7919fb1a190SDave Jiang err_clr->err_inj_clr_spa_range_length); 7929fb1a190SDave Jiang 7939fb1a190SDave Jiang err_clr->status = 0; 7949fb1a190SDave Jiang return 0; 7959fb1a190SDave Jiang 7969fb1a190SDave Jiang err: 7979fb1a190SDave Jiang err_clr->status = NFIT_ARS_INJECT_INVALID; 7989fb1a190SDave Jiang return rc; 7999fb1a190SDave Jiang } 8009fb1a190SDave Jiang 8019fb1a190SDave Jiang static int nfit_test_cmd_ars_inject_status(struct nfit_test *t, 8029fb1a190SDave Jiang struct nd_cmd_ars_err_inj_stat *err_stat, 8039fb1a190SDave Jiang unsigned int buf_len) 8049fb1a190SDave Jiang { 8059fb1a190SDave Jiang struct badrange_entry *be; 8069fb1a190SDave Jiang int max = SZ_4K / sizeof(struct nd_error_stat_query_record); 8079fb1a190SDave Jiang int i = 0; 8089fb1a190SDave Jiang 8099fb1a190SDave Jiang err_stat->status = 0; 8109fb1a190SDave Jiang spin_lock(&t->badrange.lock); 8119fb1a190SDave Jiang list_for_each_entry(be, &t->badrange.list, list) { 8129fb1a190SDave Jiang err_stat->record[i].err_inj_stat_spa_range_base = be->start; 8139fb1a190SDave Jiang err_stat->record[i].err_inj_stat_spa_range_length = be->length; 8149fb1a190SDave Jiang i++; 8159fb1a190SDave Jiang if (i > max) 8169fb1a190SDave Jiang break; 8179fb1a190SDave Jiang } 8189fb1a190SDave Jiang spin_unlock(&t->badrange.lock); 8199fb1a190SDave Jiang err_stat->inj_err_rec_count = i; 8209fb1a190SDave Jiang 8219fb1a190SDave Jiang return 0; 8229fb1a190SDave Jiang } 8239fb1a190SDave Jiang 824*bfbaa952SDave Jiang static int get_dimm(struct nfit_mem *nfit_mem, unsigned int func) 825*bfbaa952SDave Jiang { 826*bfbaa952SDave Jiang int i; 827*bfbaa952SDave Jiang 828*bfbaa952SDave Jiang /* lookup per-dimm data */ 829*bfbaa952SDave Jiang for (i = 0; i < ARRAY_SIZE(handle); i++) 830*bfbaa952SDave Jiang if (__to_nfit_memdev(nfit_mem)->device_handle == handle[i]) 831*bfbaa952SDave Jiang break; 832*bfbaa952SDave Jiang if (i >= ARRAY_SIZE(handle)) 833*bfbaa952SDave Jiang return -ENXIO; 834*bfbaa952SDave Jiang 835*bfbaa952SDave Jiang if ((1 << func) & dimm_fail_cmd_flags[i]) 836*bfbaa952SDave Jiang return -EIO; 837*bfbaa952SDave Jiang 838*bfbaa952SDave Jiang return i; 839*bfbaa952SDave Jiang } 840*bfbaa952SDave Jiang 84139c686b8SVishal Verma static int nfit_test_ctl(struct nvdimm_bus_descriptor *nd_desc, 84239c686b8SVishal Verma struct nvdimm *nvdimm, unsigned int cmd, void *buf, 843aef25338SDan Williams unsigned int buf_len, int *cmd_rc) 84439c686b8SVishal Verma { 84539c686b8SVishal Verma struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc); 84639c686b8SVishal Verma struct nfit_test *t = container_of(acpi_desc, typeof(*t), acpi_desc); 8476634fb06SDan Williams unsigned int func = cmd; 848f471f1a7SDan Williams int i, rc = 0, __cmd_rc; 849f471f1a7SDan Williams 850f471f1a7SDan Williams if (!cmd_rc) 851f471f1a7SDan Williams cmd_rc = &__cmd_rc; 852f471f1a7SDan Williams *cmd_rc = 0; 85339c686b8SVishal Verma 85439c686b8SVishal Verma if (nvdimm) { 85539c686b8SVishal Verma struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm); 856e3654ecaSDan Williams unsigned long cmd_mask = nvdimm_cmd_mask(nvdimm); 85739c686b8SVishal Verma 8586634fb06SDan Williams if (!nfit_mem) 8596634fb06SDan Williams return -ENOTTY; 8606634fb06SDan Williams 8616634fb06SDan Williams if (cmd == ND_CMD_CALL) { 8626634fb06SDan Williams struct nd_cmd_pkg *call_pkg = buf; 8636634fb06SDan Williams 8646634fb06SDan Williams buf_len = call_pkg->nd_size_in + call_pkg->nd_size_out; 8656634fb06SDan Williams buf = (void *) call_pkg->nd_payload; 8666634fb06SDan Williams func = call_pkg->nd_command; 8676634fb06SDan Williams if (call_pkg->nd_family != nfit_mem->family) 8686634fb06SDan Williams return -ENOTTY; 869*bfbaa952SDave Jiang 870*bfbaa952SDave Jiang i = get_dimm(nfit_mem, func); 871*bfbaa952SDave Jiang if (i < 0) 872*bfbaa952SDave Jiang return i; 873*bfbaa952SDave Jiang 874*bfbaa952SDave Jiang switch (func) { 875*bfbaa952SDave Jiang case ND_INTEL_FW_GET_INFO: 876*bfbaa952SDave Jiang return nd_intel_test_get_fw_info(t, buf, 877*bfbaa952SDave Jiang buf_len, i - t->dcr_idx); 878*bfbaa952SDave Jiang case ND_INTEL_FW_START_UPDATE: 879*bfbaa952SDave Jiang return nd_intel_test_start_update(t, buf, 880*bfbaa952SDave Jiang buf_len, i - t->dcr_idx); 881*bfbaa952SDave Jiang case ND_INTEL_FW_SEND_DATA: 882*bfbaa952SDave Jiang return nd_intel_test_send_data(t, buf, 883*bfbaa952SDave Jiang buf_len, i - t->dcr_idx); 884*bfbaa952SDave Jiang case ND_INTEL_FW_FINISH_UPDATE: 885*bfbaa952SDave Jiang return nd_intel_test_finish_fw(t, buf, 886*bfbaa952SDave Jiang buf_len, i - t->dcr_idx); 887*bfbaa952SDave Jiang case ND_INTEL_FW_FINISH_QUERY: 888*bfbaa952SDave Jiang return nd_intel_test_finish_query(t, buf, 889*bfbaa952SDave Jiang buf_len, i - t->dcr_idx); 890*bfbaa952SDave Jiang case ND_INTEL_SMART: 891*bfbaa952SDave Jiang return nfit_test_cmd_smart(buf, buf_len, 892*bfbaa952SDave Jiang &t->smart[i - t->dcr_idx]); 893*bfbaa952SDave Jiang case ND_INTEL_SMART_THRESHOLD: 894*bfbaa952SDave Jiang return nfit_test_cmd_smart_threshold(buf, 895*bfbaa952SDave Jiang buf_len, 896*bfbaa952SDave Jiang &t->smart_threshold[i - 897*bfbaa952SDave Jiang t->dcr_idx]); 898*bfbaa952SDave Jiang case ND_INTEL_SMART_SET_THRESHOLD: 899*bfbaa952SDave Jiang return nfit_test_cmd_smart_set_threshold(buf, 900*bfbaa952SDave Jiang buf_len, 901*bfbaa952SDave Jiang &t->smart_threshold[i - 902*bfbaa952SDave Jiang t->dcr_idx], 903*bfbaa952SDave Jiang &t->smart[i - t->dcr_idx], 904*bfbaa952SDave Jiang &t->pdev.dev, t->dimm_dev[i]); 905*bfbaa952SDave Jiang default: 906*bfbaa952SDave Jiang return -ENOTTY; 907*bfbaa952SDave Jiang } 9086634fb06SDan Williams } 9096634fb06SDan Williams 9106634fb06SDan Williams if (!test_bit(cmd, &cmd_mask) 9116634fb06SDan Williams || !test_bit(func, &nfit_mem->dsm_mask)) 91239c686b8SVishal Verma return -ENOTTY; 91339c686b8SVishal Verma 914*bfbaa952SDave Jiang i = get_dimm(nfit_mem, func); 915*bfbaa952SDave Jiang if (i < 0) 916*bfbaa952SDave Jiang return i; 91773606afdSDan Williams 9186634fb06SDan Williams switch (func) { 91939c686b8SVishal Verma case ND_CMD_GET_CONFIG_SIZE: 92039c686b8SVishal Verma rc = nfit_test_cmd_get_config_size(buf, buf_len); 92139c686b8SVishal Verma break; 92239c686b8SVishal Verma case ND_CMD_GET_CONFIG_DATA: 92339c686b8SVishal Verma rc = nfit_test_cmd_get_config_data(buf, buf_len, 924dafb1048SDan Williams t->label[i - t->dcr_idx]); 92539c686b8SVishal Verma break; 92639c686b8SVishal Verma case ND_CMD_SET_CONFIG_DATA: 92739c686b8SVishal Verma rc = nfit_test_cmd_set_config_data(buf, buf_len, 928dafb1048SDan Williams t->label[i - t->dcr_idx]); 92939c686b8SVishal Verma break; 9306bc75619SDan Williams default: 9316bc75619SDan Williams return -ENOTTY; 9326bc75619SDan Williams } 93339c686b8SVishal Verma } else { 934f471f1a7SDan Williams struct ars_state *ars_state = &t->ars_state; 93510246dc8SYasunori Goto struct nd_cmd_pkg *call_pkg = buf; 93610246dc8SYasunori Goto 93710246dc8SYasunori Goto if (!nd_desc) 93810246dc8SYasunori Goto return -ENOTTY; 93910246dc8SYasunori Goto 94010246dc8SYasunori Goto if (cmd == ND_CMD_CALL) { 94110246dc8SYasunori Goto func = call_pkg->nd_command; 94210246dc8SYasunori Goto 94310246dc8SYasunori Goto buf_len = call_pkg->nd_size_in + call_pkg->nd_size_out; 94410246dc8SYasunori Goto buf = (void *) call_pkg->nd_payload; 94510246dc8SYasunori Goto 94610246dc8SYasunori Goto switch (func) { 94710246dc8SYasunori Goto case NFIT_CMD_TRANSLATE_SPA: 94810246dc8SYasunori Goto rc = nfit_test_cmd_translate_spa( 94910246dc8SYasunori Goto acpi_desc->nvdimm_bus, buf, buf_len); 95010246dc8SYasunori Goto return rc; 9519fb1a190SDave Jiang case NFIT_CMD_ARS_INJECT_SET: 9529fb1a190SDave Jiang rc = nfit_test_cmd_ars_error_inject(t, buf, 9539fb1a190SDave Jiang buf_len); 9549fb1a190SDave Jiang return rc; 9559fb1a190SDave Jiang case NFIT_CMD_ARS_INJECT_CLEAR: 9569fb1a190SDave Jiang rc = nfit_test_cmd_ars_inject_clear(t, buf, 9579fb1a190SDave Jiang buf_len); 9589fb1a190SDave Jiang return rc; 9599fb1a190SDave Jiang case NFIT_CMD_ARS_INJECT_GET: 9609fb1a190SDave Jiang rc = nfit_test_cmd_ars_inject_status(t, buf, 9619fb1a190SDave Jiang buf_len); 9629fb1a190SDave Jiang return rc; 96310246dc8SYasunori Goto default: 96410246dc8SYasunori Goto return -ENOTTY; 96510246dc8SYasunori Goto } 96610246dc8SYasunori Goto } 967f471f1a7SDan Williams 968e3654ecaSDan Williams if (!nd_desc || !test_bit(cmd, &nd_desc->cmd_mask)) 96939c686b8SVishal Verma return -ENOTTY; 97039c686b8SVishal Verma 9716634fb06SDan Williams switch (func) { 97239c686b8SVishal Verma case ND_CMD_ARS_CAP: 97339c686b8SVishal Verma rc = nfit_test_cmd_ars_cap(buf, buf_len); 97439c686b8SVishal Verma break; 97539c686b8SVishal Verma case ND_CMD_ARS_START: 9769fb1a190SDave Jiang rc = nfit_test_cmd_ars_start(t, ars_state, buf, 9779fb1a190SDave Jiang buf_len, cmd_rc); 97839c686b8SVishal Verma break; 97939c686b8SVishal Verma case ND_CMD_ARS_STATUS: 980f471f1a7SDan Williams rc = nfit_test_cmd_ars_status(ars_state, buf, buf_len, 981f471f1a7SDan Williams cmd_rc); 98239c686b8SVishal Verma break; 983d4f32367SDan Williams case ND_CMD_CLEAR_ERROR: 9845e096ef3SVishal Verma rc = nfit_test_cmd_clear_error(t, buf, buf_len, cmd_rc); 985d4f32367SDan Williams break; 98639c686b8SVishal Verma default: 98739c686b8SVishal Verma return -ENOTTY; 98839c686b8SVishal Verma } 98939c686b8SVishal Verma } 9906bc75619SDan Williams 9916bc75619SDan Williams return rc; 9926bc75619SDan Williams } 9936bc75619SDan Williams 9946bc75619SDan Williams static DEFINE_SPINLOCK(nfit_test_lock); 9956bc75619SDan Williams static struct nfit_test *instances[NUM_NFITS]; 9966bc75619SDan Williams 9976bc75619SDan Williams static void release_nfit_res(void *data) 9986bc75619SDan Williams { 9996bc75619SDan Williams struct nfit_test_resource *nfit_res = data; 10006bc75619SDan Williams 10016bc75619SDan Williams spin_lock(&nfit_test_lock); 10026bc75619SDan Williams list_del(&nfit_res->list); 10036bc75619SDan Williams spin_unlock(&nfit_test_lock); 10046bc75619SDan Williams 10056bc75619SDan Williams vfree(nfit_res->buf); 10066bc75619SDan Williams kfree(nfit_res); 10076bc75619SDan Williams } 10086bc75619SDan Williams 10096bc75619SDan Williams static void *__test_alloc(struct nfit_test *t, size_t size, dma_addr_t *dma, 10106bc75619SDan Williams void *buf) 10116bc75619SDan Williams { 10126bc75619SDan Williams struct device *dev = &t->pdev.dev; 10136bc75619SDan Williams struct nfit_test_resource *nfit_res = kzalloc(sizeof(*nfit_res), 10146bc75619SDan Williams GFP_KERNEL); 10156bc75619SDan Williams int rc; 10166bc75619SDan Williams 1017bd4cd745SDan Williams if (!buf || !nfit_res) 10186bc75619SDan Williams goto err; 10196bc75619SDan Williams rc = devm_add_action(dev, release_nfit_res, nfit_res); 10206bc75619SDan Williams if (rc) 10216bc75619SDan Williams goto err; 10226bc75619SDan Williams INIT_LIST_HEAD(&nfit_res->list); 10236bc75619SDan Williams memset(buf, 0, size); 10246bc75619SDan Williams nfit_res->dev = dev; 10256bc75619SDan Williams nfit_res->buf = buf; 1026bd4cd745SDan Williams nfit_res->res.start = *dma; 1027bd4cd745SDan Williams nfit_res->res.end = *dma + size - 1; 1028bd4cd745SDan Williams nfit_res->res.name = "NFIT"; 1029bd4cd745SDan Williams spin_lock_init(&nfit_res->lock); 1030bd4cd745SDan Williams INIT_LIST_HEAD(&nfit_res->requests); 10316bc75619SDan Williams spin_lock(&nfit_test_lock); 10326bc75619SDan Williams list_add(&nfit_res->list, &t->resources); 10336bc75619SDan Williams spin_unlock(&nfit_test_lock); 10346bc75619SDan Williams 10356bc75619SDan Williams return nfit_res->buf; 10366bc75619SDan Williams err: 1037ee8520feSDan Williams if (buf) 10386bc75619SDan Williams vfree(buf); 10396bc75619SDan Williams kfree(nfit_res); 10406bc75619SDan Williams return NULL; 10416bc75619SDan Williams } 10426bc75619SDan Williams 10436bc75619SDan Williams static void *test_alloc(struct nfit_test *t, size_t size, dma_addr_t *dma) 10446bc75619SDan Williams { 10456bc75619SDan Williams void *buf = vmalloc(size); 10466bc75619SDan Williams 10476bc75619SDan Williams *dma = (unsigned long) buf; 10486bc75619SDan Williams return __test_alloc(t, size, dma, buf); 10496bc75619SDan Williams } 10506bc75619SDan Williams 10516bc75619SDan Williams static struct nfit_test_resource *nfit_test_lookup(resource_size_t addr) 10526bc75619SDan Williams { 10536bc75619SDan Williams int i; 10546bc75619SDan Williams 10556bc75619SDan Williams for (i = 0; i < ARRAY_SIZE(instances); i++) { 10566bc75619SDan Williams struct nfit_test_resource *n, *nfit_res = NULL; 10576bc75619SDan Williams struct nfit_test *t = instances[i]; 10586bc75619SDan Williams 10596bc75619SDan Williams if (!t) 10606bc75619SDan Williams continue; 10616bc75619SDan Williams spin_lock(&nfit_test_lock); 10626bc75619SDan Williams list_for_each_entry(n, &t->resources, list) { 1063bd4cd745SDan Williams if (addr >= n->res.start && (addr < n->res.start 1064bd4cd745SDan Williams + resource_size(&n->res))) { 10656bc75619SDan Williams nfit_res = n; 10666bc75619SDan Williams break; 10676bc75619SDan Williams } else if (addr >= (unsigned long) n->buf 10686bc75619SDan Williams && (addr < (unsigned long) n->buf 1069bd4cd745SDan Williams + resource_size(&n->res))) { 10706bc75619SDan Williams nfit_res = n; 10716bc75619SDan Williams break; 10726bc75619SDan Williams } 10736bc75619SDan Williams } 10746bc75619SDan Williams spin_unlock(&nfit_test_lock); 10756bc75619SDan Williams if (nfit_res) 10766bc75619SDan Williams return nfit_res; 10776bc75619SDan Williams } 10786bc75619SDan Williams 10796bc75619SDan Williams return NULL; 10806bc75619SDan Williams } 10816bc75619SDan Williams 1082f471f1a7SDan Williams static int ars_state_init(struct device *dev, struct ars_state *ars_state) 1083f471f1a7SDan Williams { 10849fb1a190SDave Jiang /* for testing, only store up to n records that fit within 4k */ 1085f471f1a7SDan Williams ars_state->ars_status = devm_kzalloc(dev, 10869fb1a190SDave Jiang sizeof(struct nd_cmd_ars_status) + SZ_4K, GFP_KERNEL); 1087f471f1a7SDan Williams if (!ars_state->ars_status) 1088f471f1a7SDan Williams return -ENOMEM; 1089f471f1a7SDan Williams spin_lock_init(&ars_state->lock); 1090f471f1a7SDan Williams return 0; 1091f471f1a7SDan Williams } 1092f471f1a7SDan Williams 1093231bf117SDan Williams static void put_dimms(void *data) 1094231bf117SDan Williams { 1095231bf117SDan Williams struct device **dimm_dev = data; 1096231bf117SDan Williams int i; 1097231bf117SDan Williams 1098231bf117SDan Williams for (i = 0; i < NUM_DCR; i++) 1099231bf117SDan Williams if (dimm_dev[i]) 1100231bf117SDan Williams device_unregister(dimm_dev[i]); 1101231bf117SDan Williams } 1102231bf117SDan Williams 1103231bf117SDan Williams static struct class *nfit_test_dimm; 1104231bf117SDan Williams 110573606afdSDan Williams static int dimm_name_to_id(struct device *dev) 110673606afdSDan Williams { 110773606afdSDan Williams int dimm; 110873606afdSDan Williams 110973606afdSDan Williams if (sscanf(dev_name(dev), "test_dimm%d", &dimm) != 1 111073606afdSDan Williams || dimm >= NUM_DCR || dimm < 0) 111173606afdSDan Williams return -ENXIO; 111273606afdSDan Williams return dimm; 111373606afdSDan Williams } 111473606afdSDan Williams 111573606afdSDan Williams 111673606afdSDan Williams static ssize_t handle_show(struct device *dev, struct device_attribute *attr, 111773606afdSDan Williams char *buf) 111873606afdSDan Williams { 111973606afdSDan Williams int dimm = dimm_name_to_id(dev); 112073606afdSDan Williams 112173606afdSDan Williams if (dimm < 0) 112273606afdSDan Williams return dimm; 112373606afdSDan Williams 112473606afdSDan Williams return sprintf(buf, "%#x", handle[dimm]); 112573606afdSDan Williams } 112673606afdSDan Williams DEVICE_ATTR_RO(handle); 112773606afdSDan Williams 112873606afdSDan Williams static ssize_t fail_cmd_show(struct device *dev, struct device_attribute *attr, 112973606afdSDan Williams char *buf) 113073606afdSDan Williams { 113173606afdSDan Williams int dimm = dimm_name_to_id(dev); 113273606afdSDan Williams 113373606afdSDan Williams if (dimm < 0) 113473606afdSDan Williams return dimm; 113573606afdSDan Williams 113673606afdSDan Williams return sprintf(buf, "%#lx\n", dimm_fail_cmd_flags[dimm]); 113773606afdSDan Williams } 113873606afdSDan Williams 113973606afdSDan Williams static ssize_t fail_cmd_store(struct device *dev, struct device_attribute *attr, 114073606afdSDan Williams const char *buf, size_t size) 114173606afdSDan Williams { 114273606afdSDan Williams int dimm = dimm_name_to_id(dev); 114373606afdSDan Williams unsigned long val; 114473606afdSDan Williams ssize_t rc; 114573606afdSDan Williams 114673606afdSDan Williams if (dimm < 0) 114773606afdSDan Williams return dimm; 114873606afdSDan Williams 114973606afdSDan Williams rc = kstrtol(buf, 0, &val); 115073606afdSDan Williams if (rc) 115173606afdSDan Williams return rc; 115273606afdSDan Williams 115373606afdSDan Williams dimm_fail_cmd_flags[dimm] = val; 115473606afdSDan Williams return size; 115573606afdSDan Williams } 115673606afdSDan Williams static DEVICE_ATTR_RW(fail_cmd); 115773606afdSDan Williams 115873606afdSDan Williams static struct attribute *nfit_test_dimm_attributes[] = { 115973606afdSDan Williams &dev_attr_fail_cmd.attr, 116073606afdSDan Williams &dev_attr_handle.attr, 116173606afdSDan Williams NULL, 116273606afdSDan Williams }; 116373606afdSDan Williams 116473606afdSDan Williams static struct attribute_group nfit_test_dimm_attribute_group = { 116573606afdSDan Williams .attrs = nfit_test_dimm_attributes, 116673606afdSDan Williams }; 116773606afdSDan Williams 116873606afdSDan Williams static const struct attribute_group *nfit_test_dimm_attribute_groups[] = { 116973606afdSDan Williams &nfit_test_dimm_attribute_group, 117073606afdSDan Williams NULL, 117173606afdSDan Williams }; 117273606afdSDan Williams 1173ed07c433SDan Williams static void smart_init(struct nfit_test *t) 1174ed07c433SDan Williams { 1175ed07c433SDan Williams int i; 1176ed07c433SDan Williams const struct nd_intel_smart_threshold smart_t_data = { 1177ed07c433SDan Williams .alarm_control = ND_INTEL_SMART_SPARE_TRIP 1178ed07c433SDan Williams | ND_INTEL_SMART_TEMP_TRIP, 1179ed07c433SDan Williams .media_temperature = 40 * 16, 1180ed07c433SDan Williams .ctrl_temperature = 30 * 16, 1181ed07c433SDan Williams .spares = 5, 1182ed07c433SDan Williams }; 1183ed07c433SDan Williams const struct nd_intel_smart smart_data = { 1184ed07c433SDan Williams .flags = ND_INTEL_SMART_HEALTH_VALID 1185ed07c433SDan Williams | ND_INTEL_SMART_SPARES_VALID 1186ed07c433SDan Williams | ND_INTEL_SMART_ALARM_VALID 1187ed07c433SDan Williams | ND_INTEL_SMART_USED_VALID 1188ed07c433SDan Williams | ND_INTEL_SMART_SHUTDOWN_VALID 1189ed07c433SDan Williams | ND_INTEL_SMART_MTEMP_VALID, 1190ed07c433SDan Williams .health = ND_INTEL_SMART_NON_CRITICAL_HEALTH, 1191ed07c433SDan Williams .media_temperature = 23 * 16, 1192ed07c433SDan Williams .ctrl_temperature = 30 * 16, 1193ed07c433SDan Williams .pmic_temperature = 40 * 16, 1194ed07c433SDan Williams .spares = 75, 1195ed07c433SDan Williams .alarm_flags = ND_INTEL_SMART_SPARE_TRIP 1196ed07c433SDan Williams | ND_INTEL_SMART_TEMP_TRIP, 1197ed07c433SDan Williams .ait_status = 1, 1198ed07c433SDan Williams .life_used = 5, 1199ed07c433SDan Williams .shutdown_state = 0, 1200ed07c433SDan Williams .vendor_size = 0, 1201ed07c433SDan Williams .shutdown_count = 100, 1202ed07c433SDan Williams }; 1203ed07c433SDan Williams 1204ed07c433SDan Williams for (i = 0; i < t->num_dcr; i++) { 1205ed07c433SDan Williams memcpy(&t->smart[i], &smart_data, sizeof(smart_data)); 1206ed07c433SDan Williams memcpy(&t->smart_threshold[i], &smart_t_data, 1207ed07c433SDan Williams sizeof(smart_t_data)); 1208ed07c433SDan Williams } 1209ed07c433SDan Williams } 1210ed07c433SDan Williams 12116bc75619SDan Williams static int nfit_test0_alloc(struct nfit_test *t) 12126bc75619SDan Williams { 12136b577c9dSLinda Knippers size_t nfit_size = sizeof(struct acpi_nfit_system_address) * NUM_SPA 12146bc75619SDan Williams + sizeof(struct acpi_nfit_memory_map) * NUM_MEM 12156bc75619SDan Williams + sizeof(struct acpi_nfit_control_region) * NUM_DCR 12163b87356fSDan Williams + offsetof(struct acpi_nfit_control_region, 12173b87356fSDan Williams window_size) * NUM_DCR 12189d27a87eSDan Williams + sizeof(struct acpi_nfit_data_region) * NUM_BDW 121985d3fa02SDan Williams + (sizeof(struct acpi_nfit_flush_address) 122085d3fa02SDan Williams + sizeof(u64) * NUM_HINTS) * NUM_DCR; 12216bc75619SDan Williams int i; 12226bc75619SDan Williams 12236bc75619SDan Williams t->nfit_buf = test_alloc(t, nfit_size, &t->nfit_dma); 12246bc75619SDan Williams if (!t->nfit_buf) 12256bc75619SDan Williams return -ENOMEM; 12266bc75619SDan Williams t->nfit_size = nfit_size; 12276bc75619SDan Williams 1228ee8520feSDan Williams t->spa_set[0] = test_alloc(t, SPA0_SIZE, &t->spa_set_dma[0]); 12296bc75619SDan Williams if (!t->spa_set[0]) 12306bc75619SDan Williams return -ENOMEM; 12316bc75619SDan Williams 1232ee8520feSDan Williams t->spa_set[1] = test_alloc(t, SPA1_SIZE, &t->spa_set_dma[1]); 12336bc75619SDan Williams if (!t->spa_set[1]) 12346bc75619SDan Williams return -ENOMEM; 12356bc75619SDan Williams 1236ee8520feSDan Williams t->spa_set[2] = test_alloc(t, SPA0_SIZE, &t->spa_set_dma[2]); 123720985164SVishal Verma if (!t->spa_set[2]) 123820985164SVishal Verma return -ENOMEM; 123920985164SVishal Verma 1240dafb1048SDan Williams for (i = 0; i < t->num_dcr; i++) { 12416bc75619SDan Williams t->dimm[i] = test_alloc(t, DIMM_SIZE, &t->dimm_dma[i]); 12426bc75619SDan Williams if (!t->dimm[i]) 12436bc75619SDan Williams return -ENOMEM; 12446bc75619SDan Williams 12456bc75619SDan Williams t->label[i] = test_alloc(t, LABEL_SIZE, &t->label_dma[i]); 12466bc75619SDan Williams if (!t->label[i]) 12476bc75619SDan Williams return -ENOMEM; 12486bc75619SDan Williams sprintf(t->label[i], "label%d", i); 12499d27a87eSDan Williams 12509d15ce9cSDan Williams t->flush[i] = test_alloc(t, max(PAGE_SIZE, 12519d15ce9cSDan Williams sizeof(u64) * NUM_HINTS), 125285d3fa02SDan Williams &t->flush_dma[i]); 12539d27a87eSDan Williams if (!t->flush[i]) 12549d27a87eSDan Williams return -ENOMEM; 12556bc75619SDan Williams } 12566bc75619SDan Williams 1257dafb1048SDan Williams for (i = 0; i < t->num_dcr; i++) { 12586bc75619SDan Williams t->dcr[i] = test_alloc(t, LABEL_SIZE, &t->dcr_dma[i]); 12596bc75619SDan Williams if (!t->dcr[i]) 12606bc75619SDan Williams return -ENOMEM; 12616bc75619SDan Williams } 12626bc75619SDan Williams 1263c14a868aSDan Williams t->_fit = test_alloc(t, sizeof(union acpi_object **), &t->_fit_dma); 1264c14a868aSDan Williams if (!t->_fit) 1265c14a868aSDan Williams return -ENOMEM; 1266c14a868aSDan Williams 1267231bf117SDan Williams if (devm_add_action_or_reset(&t->pdev.dev, put_dimms, t->dimm_dev)) 1268231bf117SDan Williams return -ENOMEM; 1269231bf117SDan Williams for (i = 0; i < NUM_DCR; i++) { 127073606afdSDan Williams t->dimm_dev[i] = device_create_with_groups(nfit_test_dimm, 127173606afdSDan Williams &t->pdev.dev, 0, NULL, 127273606afdSDan Williams nfit_test_dimm_attribute_groups, 127373606afdSDan Williams "test_dimm%d", i); 1274231bf117SDan Williams if (!t->dimm_dev[i]) 1275231bf117SDan Williams return -ENOMEM; 1276231bf117SDan Williams } 1277231bf117SDan Williams 1278ed07c433SDan Williams smart_init(t); 1279f471f1a7SDan Williams return ars_state_init(&t->pdev.dev, &t->ars_state); 12806bc75619SDan Williams } 12816bc75619SDan Williams 12826bc75619SDan Williams static int nfit_test1_alloc(struct nfit_test *t) 12836bc75619SDan Williams { 12847bfe97c7SDan Williams size_t nfit_size = sizeof(struct acpi_nfit_system_address) * 2 1285ac40b675SDan Williams + sizeof(struct acpi_nfit_memory_map) * 2 1286ac40b675SDan Williams + offsetof(struct acpi_nfit_control_region, window_size) * 2; 1287dafb1048SDan Williams int i; 12886bc75619SDan Williams 12896bc75619SDan Williams t->nfit_buf = test_alloc(t, nfit_size, &t->nfit_dma); 12906bc75619SDan Williams if (!t->nfit_buf) 12916bc75619SDan Williams return -ENOMEM; 12926bc75619SDan Williams t->nfit_size = nfit_size; 12936bc75619SDan Williams 1294ee8520feSDan Williams t->spa_set[0] = test_alloc(t, SPA2_SIZE, &t->spa_set_dma[0]); 12956bc75619SDan Williams if (!t->spa_set[0]) 12966bc75619SDan Williams return -ENOMEM; 12976bc75619SDan Williams 1298dafb1048SDan Williams for (i = 0; i < t->num_dcr; i++) { 1299dafb1048SDan Williams t->label[i] = test_alloc(t, LABEL_SIZE, &t->label_dma[i]); 1300dafb1048SDan Williams if (!t->label[i]) 1301dafb1048SDan Williams return -ENOMEM; 1302dafb1048SDan Williams sprintf(t->label[i], "label%d", i); 1303dafb1048SDan Williams } 1304dafb1048SDan Williams 13057bfe97c7SDan Williams t->spa_set[1] = test_alloc(t, SPA_VCD_SIZE, &t->spa_set_dma[1]); 13067bfe97c7SDan Williams if (!t->spa_set[1]) 13077bfe97c7SDan Williams return -ENOMEM; 13087bfe97c7SDan Williams 1309ed07c433SDan Williams smart_init(t); 1310f471f1a7SDan Williams return ars_state_init(&t->pdev.dev, &t->ars_state); 13116bc75619SDan Williams } 13126bc75619SDan Williams 13135dc68e55SDan Williams static void dcr_common_init(struct acpi_nfit_control_region *dcr) 13145dc68e55SDan Williams { 13155dc68e55SDan Williams dcr->vendor_id = 0xabcd; 13165dc68e55SDan Williams dcr->device_id = 0; 13175dc68e55SDan Williams dcr->revision_id = 1; 13185dc68e55SDan Williams dcr->valid_fields = 1; 13195dc68e55SDan Williams dcr->manufacturing_location = 0xa; 13205dc68e55SDan Williams dcr->manufacturing_date = cpu_to_be16(2016); 13215dc68e55SDan Williams } 13225dc68e55SDan Williams 13236bc75619SDan Williams static void nfit_test0_setup(struct nfit_test *t) 13246bc75619SDan Williams { 132585d3fa02SDan Williams const int flush_hint_size = sizeof(struct acpi_nfit_flush_address) 132685d3fa02SDan Williams + (sizeof(u64) * NUM_HINTS); 13276bc75619SDan Williams struct acpi_nfit_desc *acpi_desc; 13286bc75619SDan Williams struct acpi_nfit_memory_map *memdev; 13296bc75619SDan Williams void *nfit_buf = t->nfit_buf; 13306bc75619SDan Williams struct acpi_nfit_system_address *spa; 13316bc75619SDan Williams struct acpi_nfit_control_region *dcr; 13326bc75619SDan Williams struct acpi_nfit_data_region *bdw; 13339d27a87eSDan Williams struct acpi_nfit_flush_address *flush; 133485d3fa02SDan Williams unsigned int offset, i; 13356bc75619SDan Williams 13366bc75619SDan Williams /* 13376bc75619SDan Williams * spa0 (interleave first half of dimm0 and dimm1, note storage 13386bc75619SDan Williams * does not actually alias the related block-data-window 13396bc75619SDan Williams * regions) 13406bc75619SDan Williams */ 13416b577c9dSLinda Knippers spa = nfit_buf; 13426bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 13436bc75619SDan Williams spa->header.length = sizeof(*spa); 13446bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 13456bc75619SDan Williams spa->range_index = 0+1; 13466bc75619SDan Williams spa->address = t->spa_set_dma[0]; 13476bc75619SDan Williams spa->length = SPA0_SIZE; 13486bc75619SDan Williams 13496bc75619SDan Williams /* 13506bc75619SDan Williams * spa1 (interleave last half of the 4 DIMMS, note storage 13516bc75619SDan Williams * does not actually alias the related block-data-window 13526bc75619SDan Williams * regions) 13536bc75619SDan Williams */ 13546b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa); 13556bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 13566bc75619SDan Williams spa->header.length = sizeof(*spa); 13576bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 13586bc75619SDan Williams spa->range_index = 1+1; 13596bc75619SDan Williams spa->address = t->spa_set_dma[1]; 13606bc75619SDan Williams spa->length = SPA1_SIZE; 13616bc75619SDan Williams 13626bc75619SDan Williams /* spa2 (dcr0) dimm0 */ 13636b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 2; 13646bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 13656bc75619SDan Williams spa->header.length = sizeof(*spa); 13666bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 13676bc75619SDan Williams spa->range_index = 2+1; 13686bc75619SDan Williams spa->address = t->dcr_dma[0]; 13696bc75619SDan Williams spa->length = DCR_SIZE; 13706bc75619SDan Williams 13716bc75619SDan Williams /* spa3 (dcr1) dimm1 */ 13726b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 3; 13736bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 13746bc75619SDan Williams spa->header.length = sizeof(*spa); 13756bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 13766bc75619SDan Williams spa->range_index = 3+1; 13776bc75619SDan Williams spa->address = t->dcr_dma[1]; 13786bc75619SDan Williams spa->length = DCR_SIZE; 13796bc75619SDan Williams 13806bc75619SDan Williams /* spa4 (dcr2) dimm2 */ 13816b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 4; 13826bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 13836bc75619SDan Williams spa->header.length = sizeof(*spa); 13846bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 13856bc75619SDan Williams spa->range_index = 4+1; 13866bc75619SDan Williams spa->address = t->dcr_dma[2]; 13876bc75619SDan Williams spa->length = DCR_SIZE; 13886bc75619SDan Williams 13896bc75619SDan Williams /* spa5 (dcr3) dimm3 */ 13906b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 5; 13916bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 13926bc75619SDan Williams spa->header.length = sizeof(*spa); 13936bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 13946bc75619SDan Williams spa->range_index = 5+1; 13956bc75619SDan Williams spa->address = t->dcr_dma[3]; 13966bc75619SDan Williams spa->length = DCR_SIZE; 13976bc75619SDan Williams 13986bc75619SDan Williams /* spa6 (bdw for dcr0) dimm0 */ 13996b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 6; 14006bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 14016bc75619SDan Williams spa->header.length = sizeof(*spa); 14026bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 14036bc75619SDan Williams spa->range_index = 6+1; 14046bc75619SDan Williams spa->address = t->dimm_dma[0]; 14056bc75619SDan Williams spa->length = DIMM_SIZE; 14066bc75619SDan Williams 14076bc75619SDan Williams /* spa7 (bdw for dcr1) dimm1 */ 14086b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 7; 14096bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 14106bc75619SDan Williams spa->header.length = sizeof(*spa); 14116bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 14126bc75619SDan Williams spa->range_index = 7+1; 14136bc75619SDan Williams spa->address = t->dimm_dma[1]; 14146bc75619SDan Williams spa->length = DIMM_SIZE; 14156bc75619SDan Williams 14166bc75619SDan Williams /* spa8 (bdw for dcr2) dimm2 */ 14176b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 8; 14186bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 14196bc75619SDan Williams spa->header.length = sizeof(*spa); 14206bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 14216bc75619SDan Williams spa->range_index = 8+1; 14226bc75619SDan Williams spa->address = t->dimm_dma[2]; 14236bc75619SDan Williams spa->length = DIMM_SIZE; 14246bc75619SDan Williams 14256bc75619SDan Williams /* spa9 (bdw for dcr3) dimm3 */ 14266b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 9; 14276bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 14286bc75619SDan Williams spa->header.length = sizeof(*spa); 14296bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 14306bc75619SDan Williams spa->range_index = 9+1; 14316bc75619SDan Williams spa->address = t->dimm_dma[3]; 14326bc75619SDan Williams spa->length = DIMM_SIZE; 14336bc75619SDan Williams 14346b577c9dSLinda Knippers offset = sizeof(*spa) * 10; 14356bc75619SDan Williams /* mem-region0 (spa0, dimm0) */ 14366bc75619SDan Williams memdev = nfit_buf + offset; 14376bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 14386bc75619SDan Williams memdev->header.length = sizeof(*memdev); 14396bc75619SDan Williams memdev->device_handle = handle[0]; 14406bc75619SDan Williams memdev->physical_id = 0; 14416bc75619SDan Williams memdev->region_id = 0; 14426bc75619SDan Williams memdev->range_index = 0+1; 14433b87356fSDan Williams memdev->region_index = 4+1; 14446bc75619SDan Williams memdev->region_size = SPA0_SIZE/2; 1445df06a2d5SDan Williams memdev->region_offset = 1; 14466bc75619SDan Williams memdev->address = 0; 14476bc75619SDan Williams memdev->interleave_index = 0; 14486bc75619SDan Williams memdev->interleave_ways = 2; 14496bc75619SDan Williams 14506bc75619SDan Williams /* mem-region1 (spa0, dimm1) */ 14516bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map); 14526bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 14536bc75619SDan Williams memdev->header.length = sizeof(*memdev); 14546bc75619SDan Williams memdev->device_handle = handle[1]; 14556bc75619SDan Williams memdev->physical_id = 1; 14566bc75619SDan Williams memdev->region_id = 0; 14576bc75619SDan Williams memdev->range_index = 0+1; 14583b87356fSDan Williams memdev->region_index = 5+1; 14596bc75619SDan Williams memdev->region_size = SPA0_SIZE/2; 1460df06a2d5SDan Williams memdev->region_offset = (1 << 8); 14616bc75619SDan Williams memdev->address = 0; 14626bc75619SDan Williams memdev->interleave_index = 0; 14636bc75619SDan Williams memdev->interleave_ways = 2; 1464ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED; 14656bc75619SDan Williams 14666bc75619SDan Williams /* mem-region2 (spa1, dimm0) */ 14676bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 2; 14686bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 14696bc75619SDan Williams memdev->header.length = sizeof(*memdev); 14706bc75619SDan Williams memdev->device_handle = handle[0]; 14716bc75619SDan Williams memdev->physical_id = 0; 14726bc75619SDan Williams memdev->region_id = 1; 14736bc75619SDan Williams memdev->range_index = 1+1; 14743b87356fSDan Williams memdev->region_index = 4+1; 14756bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 1476df06a2d5SDan Williams memdev->region_offset = (1 << 16); 14776bc75619SDan Williams memdev->address = SPA0_SIZE/2; 14786bc75619SDan Williams memdev->interleave_index = 0; 14796bc75619SDan Williams memdev->interleave_ways = 4; 1480ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED; 14816bc75619SDan Williams 14826bc75619SDan Williams /* mem-region3 (spa1, dimm1) */ 14836bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 3; 14846bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 14856bc75619SDan Williams memdev->header.length = sizeof(*memdev); 14866bc75619SDan Williams memdev->device_handle = handle[1]; 14876bc75619SDan Williams memdev->physical_id = 1; 14886bc75619SDan Williams memdev->region_id = 1; 14896bc75619SDan Williams memdev->range_index = 1+1; 14903b87356fSDan Williams memdev->region_index = 5+1; 14916bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 1492df06a2d5SDan Williams memdev->region_offset = (1 << 24); 14936bc75619SDan Williams memdev->address = SPA0_SIZE/2; 14946bc75619SDan Williams memdev->interleave_index = 0; 14956bc75619SDan Williams memdev->interleave_ways = 4; 14966bc75619SDan Williams 14976bc75619SDan Williams /* mem-region4 (spa1, dimm2) */ 14986bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 4; 14996bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 15006bc75619SDan Williams memdev->header.length = sizeof(*memdev); 15016bc75619SDan Williams memdev->device_handle = handle[2]; 15026bc75619SDan Williams memdev->physical_id = 2; 15036bc75619SDan Williams memdev->region_id = 0; 15046bc75619SDan Williams memdev->range_index = 1+1; 15053b87356fSDan Williams memdev->region_index = 6+1; 15066bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 1507df06a2d5SDan Williams memdev->region_offset = (1ULL << 32); 15086bc75619SDan Williams memdev->address = SPA0_SIZE/2; 15096bc75619SDan Williams memdev->interleave_index = 0; 15106bc75619SDan Williams memdev->interleave_ways = 4; 1511ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED; 15126bc75619SDan Williams 15136bc75619SDan Williams /* mem-region5 (spa1, dimm3) */ 15146bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 5; 15156bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 15166bc75619SDan Williams memdev->header.length = sizeof(*memdev); 15176bc75619SDan Williams memdev->device_handle = handle[3]; 15186bc75619SDan Williams memdev->physical_id = 3; 15196bc75619SDan Williams memdev->region_id = 0; 15206bc75619SDan Williams memdev->range_index = 1+1; 15213b87356fSDan Williams memdev->region_index = 7+1; 15226bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 1523df06a2d5SDan Williams memdev->region_offset = (1ULL << 40); 15246bc75619SDan Williams memdev->address = SPA0_SIZE/2; 15256bc75619SDan Williams memdev->interleave_index = 0; 15266bc75619SDan Williams memdev->interleave_ways = 4; 15276bc75619SDan Williams 15286bc75619SDan Williams /* mem-region6 (spa/dcr0, dimm0) */ 15296bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 6; 15306bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 15316bc75619SDan Williams memdev->header.length = sizeof(*memdev); 15326bc75619SDan Williams memdev->device_handle = handle[0]; 15336bc75619SDan Williams memdev->physical_id = 0; 15346bc75619SDan Williams memdev->region_id = 0; 15356bc75619SDan Williams memdev->range_index = 2+1; 15366bc75619SDan Williams memdev->region_index = 0+1; 15376bc75619SDan Williams memdev->region_size = 0; 15386bc75619SDan Williams memdev->region_offset = 0; 15396bc75619SDan Williams memdev->address = 0; 15406bc75619SDan Williams memdev->interleave_index = 0; 15416bc75619SDan Williams memdev->interleave_ways = 1; 15426bc75619SDan Williams 15436bc75619SDan Williams /* mem-region7 (spa/dcr1, dimm1) */ 15446bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 7; 15456bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 15466bc75619SDan Williams memdev->header.length = sizeof(*memdev); 15476bc75619SDan Williams memdev->device_handle = handle[1]; 15486bc75619SDan Williams memdev->physical_id = 1; 15496bc75619SDan Williams memdev->region_id = 0; 15506bc75619SDan Williams memdev->range_index = 3+1; 15516bc75619SDan Williams memdev->region_index = 1+1; 15526bc75619SDan Williams memdev->region_size = 0; 15536bc75619SDan Williams memdev->region_offset = 0; 15546bc75619SDan Williams memdev->address = 0; 15556bc75619SDan Williams memdev->interleave_index = 0; 15566bc75619SDan Williams memdev->interleave_ways = 1; 15576bc75619SDan Williams 15586bc75619SDan Williams /* mem-region8 (spa/dcr2, dimm2) */ 15596bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 8; 15606bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 15616bc75619SDan Williams memdev->header.length = sizeof(*memdev); 15626bc75619SDan Williams memdev->device_handle = handle[2]; 15636bc75619SDan Williams memdev->physical_id = 2; 15646bc75619SDan Williams memdev->region_id = 0; 15656bc75619SDan Williams memdev->range_index = 4+1; 15666bc75619SDan Williams memdev->region_index = 2+1; 15676bc75619SDan Williams memdev->region_size = 0; 15686bc75619SDan Williams memdev->region_offset = 0; 15696bc75619SDan Williams memdev->address = 0; 15706bc75619SDan Williams memdev->interleave_index = 0; 15716bc75619SDan Williams memdev->interleave_ways = 1; 15726bc75619SDan Williams 15736bc75619SDan Williams /* mem-region9 (spa/dcr3, dimm3) */ 15746bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 9; 15756bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 15766bc75619SDan Williams memdev->header.length = sizeof(*memdev); 15776bc75619SDan Williams memdev->device_handle = handle[3]; 15786bc75619SDan Williams memdev->physical_id = 3; 15796bc75619SDan Williams memdev->region_id = 0; 15806bc75619SDan Williams memdev->range_index = 5+1; 15816bc75619SDan Williams memdev->region_index = 3+1; 15826bc75619SDan Williams memdev->region_size = 0; 15836bc75619SDan Williams memdev->region_offset = 0; 15846bc75619SDan Williams memdev->address = 0; 15856bc75619SDan Williams memdev->interleave_index = 0; 15866bc75619SDan Williams memdev->interleave_ways = 1; 15876bc75619SDan Williams 15886bc75619SDan Williams /* mem-region10 (spa/bdw0, dimm0) */ 15896bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 10; 15906bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 15916bc75619SDan Williams memdev->header.length = sizeof(*memdev); 15926bc75619SDan Williams memdev->device_handle = handle[0]; 15936bc75619SDan Williams memdev->physical_id = 0; 15946bc75619SDan Williams memdev->region_id = 0; 15956bc75619SDan Williams memdev->range_index = 6+1; 15966bc75619SDan Williams memdev->region_index = 0+1; 15976bc75619SDan Williams memdev->region_size = 0; 15986bc75619SDan Williams memdev->region_offset = 0; 15996bc75619SDan Williams memdev->address = 0; 16006bc75619SDan Williams memdev->interleave_index = 0; 16016bc75619SDan Williams memdev->interleave_ways = 1; 16026bc75619SDan Williams 16036bc75619SDan Williams /* mem-region11 (spa/bdw1, dimm1) */ 16046bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 11; 16056bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 16066bc75619SDan Williams memdev->header.length = sizeof(*memdev); 16076bc75619SDan Williams memdev->device_handle = handle[1]; 16086bc75619SDan Williams memdev->physical_id = 1; 16096bc75619SDan Williams memdev->region_id = 0; 16106bc75619SDan Williams memdev->range_index = 7+1; 16116bc75619SDan Williams memdev->region_index = 1+1; 16126bc75619SDan Williams memdev->region_size = 0; 16136bc75619SDan Williams memdev->region_offset = 0; 16146bc75619SDan Williams memdev->address = 0; 16156bc75619SDan Williams memdev->interleave_index = 0; 16166bc75619SDan Williams memdev->interleave_ways = 1; 16176bc75619SDan Williams 16186bc75619SDan Williams /* mem-region12 (spa/bdw2, dimm2) */ 16196bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 12; 16206bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 16216bc75619SDan Williams memdev->header.length = sizeof(*memdev); 16226bc75619SDan Williams memdev->device_handle = handle[2]; 16236bc75619SDan Williams memdev->physical_id = 2; 16246bc75619SDan Williams memdev->region_id = 0; 16256bc75619SDan Williams memdev->range_index = 8+1; 16266bc75619SDan Williams memdev->region_index = 2+1; 16276bc75619SDan Williams memdev->region_size = 0; 16286bc75619SDan Williams memdev->region_offset = 0; 16296bc75619SDan Williams memdev->address = 0; 16306bc75619SDan Williams memdev->interleave_index = 0; 16316bc75619SDan Williams memdev->interleave_ways = 1; 16326bc75619SDan Williams 16336bc75619SDan Williams /* mem-region13 (spa/dcr3, dimm3) */ 16346bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 13; 16356bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 16366bc75619SDan Williams memdev->header.length = sizeof(*memdev); 16376bc75619SDan Williams memdev->device_handle = handle[3]; 16386bc75619SDan Williams memdev->physical_id = 3; 16396bc75619SDan Williams memdev->region_id = 0; 16406bc75619SDan Williams memdev->range_index = 9+1; 16416bc75619SDan Williams memdev->region_index = 3+1; 16426bc75619SDan Williams memdev->region_size = 0; 16436bc75619SDan Williams memdev->region_offset = 0; 16446bc75619SDan Williams memdev->address = 0; 16456bc75619SDan Williams memdev->interleave_index = 0; 16466bc75619SDan Williams memdev->interleave_ways = 1; 1647ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED; 16486bc75619SDan Williams 16496bc75619SDan Williams offset = offset + sizeof(struct acpi_nfit_memory_map) * 14; 16503b87356fSDan Williams /* dcr-descriptor0: blk */ 16516bc75619SDan Williams dcr = nfit_buf + offset; 16526bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 16536bc75619SDan Williams dcr->header.length = sizeof(struct acpi_nfit_control_region); 16546bc75619SDan Williams dcr->region_index = 0+1; 16555dc68e55SDan Williams dcr_common_init(dcr); 16566bc75619SDan Williams dcr->serial_number = ~handle[0]; 1657be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 16586bc75619SDan Williams dcr->windows = 1; 16596bc75619SDan Williams dcr->window_size = DCR_SIZE; 16606bc75619SDan Williams dcr->command_offset = 0; 16616bc75619SDan Williams dcr->command_size = 8; 16626bc75619SDan Williams dcr->status_offset = 8; 16636bc75619SDan Williams dcr->status_size = 4; 16646bc75619SDan Williams 16653b87356fSDan Williams /* dcr-descriptor1: blk */ 16666bc75619SDan Williams dcr = nfit_buf + offset + sizeof(struct acpi_nfit_control_region); 16676bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 16686bc75619SDan Williams dcr->header.length = sizeof(struct acpi_nfit_control_region); 16696bc75619SDan Williams dcr->region_index = 1+1; 16705dc68e55SDan Williams dcr_common_init(dcr); 16716bc75619SDan Williams dcr->serial_number = ~handle[1]; 1672be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 16736bc75619SDan Williams dcr->windows = 1; 16746bc75619SDan Williams dcr->window_size = DCR_SIZE; 16756bc75619SDan Williams dcr->command_offset = 0; 16766bc75619SDan Williams dcr->command_size = 8; 16776bc75619SDan Williams dcr->status_offset = 8; 16786bc75619SDan Williams dcr->status_size = 4; 16796bc75619SDan Williams 16803b87356fSDan Williams /* dcr-descriptor2: blk */ 16816bc75619SDan Williams dcr = nfit_buf + offset + sizeof(struct acpi_nfit_control_region) * 2; 16826bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 16836bc75619SDan Williams dcr->header.length = sizeof(struct acpi_nfit_control_region); 16846bc75619SDan Williams dcr->region_index = 2+1; 16855dc68e55SDan Williams dcr_common_init(dcr); 16866bc75619SDan Williams dcr->serial_number = ~handle[2]; 1687be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 16886bc75619SDan Williams dcr->windows = 1; 16896bc75619SDan Williams dcr->window_size = DCR_SIZE; 16906bc75619SDan Williams dcr->command_offset = 0; 16916bc75619SDan Williams dcr->command_size = 8; 16926bc75619SDan Williams dcr->status_offset = 8; 16936bc75619SDan Williams dcr->status_size = 4; 16946bc75619SDan Williams 16953b87356fSDan Williams /* dcr-descriptor3: blk */ 16966bc75619SDan Williams dcr = nfit_buf + offset + sizeof(struct acpi_nfit_control_region) * 3; 16976bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 16986bc75619SDan Williams dcr->header.length = sizeof(struct acpi_nfit_control_region); 16996bc75619SDan Williams dcr->region_index = 3+1; 17005dc68e55SDan Williams dcr_common_init(dcr); 17016bc75619SDan Williams dcr->serial_number = ~handle[3]; 1702be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 17036bc75619SDan Williams dcr->windows = 1; 17046bc75619SDan Williams dcr->window_size = DCR_SIZE; 17056bc75619SDan Williams dcr->command_offset = 0; 17066bc75619SDan Williams dcr->command_size = 8; 17076bc75619SDan Williams dcr->status_offset = 8; 17086bc75619SDan Williams dcr->status_size = 4; 17096bc75619SDan Williams 17106bc75619SDan Williams offset = offset + sizeof(struct acpi_nfit_control_region) * 4; 17113b87356fSDan Williams /* dcr-descriptor0: pmem */ 17123b87356fSDan Williams dcr = nfit_buf + offset; 17133b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 17143b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 17153b87356fSDan Williams window_size); 17163b87356fSDan Williams dcr->region_index = 4+1; 17175dc68e55SDan Williams dcr_common_init(dcr); 17183b87356fSDan Williams dcr->serial_number = ~handle[0]; 17193b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 17203b87356fSDan Williams dcr->windows = 0; 17213b87356fSDan Williams 17223b87356fSDan Williams /* dcr-descriptor1: pmem */ 17233b87356fSDan Williams dcr = nfit_buf + offset + offsetof(struct acpi_nfit_control_region, 17243b87356fSDan Williams window_size); 17253b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 17263b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 17273b87356fSDan Williams window_size); 17283b87356fSDan Williams dcr->region_index = 5+1; 17295dc68e55SDan Williams dcr_common_init(dcr); 17303b87356fSDan Williams dcr->serial_number = ~handle[1]; 17313b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 17323b87356fSDan Williams dcr->windows = 0; 17333b87356fSDan Williams 17343b87356fSDan Williams /* dcr-descriptor2: pmem */ 17353b87356fSDan Williams dcr = nfit_buf + offset + offsetof(struct acpi_nfit_control_region, 17363b87356fSDan Williams window_size) * 2; 17373b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 17383b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 17393b87356fSDan Williams window_size); 17403b87356fSDan Williams dcr->region_index = 6+1; 17415dc68e55SDan Williams dcr_common_init(dcr); 17423b87356fSDan Williams dcr->serial_number = ~handle[2]; 17433b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 17443b87356fSDan Williams dcr->windows = 0; 17453b87356fSDan Williams 17463b87356fSDan Williams /* dcr-descriptor3: pmem */ 17473b87356fSDan Williams dcr = nfit_buf + offset + offsetof(struct acpi_nfit_control_region, 17483b87356fSDan Williams window_size) * 3; 17493b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 17503b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 17513b87356fSDan Williams window_size); 17523b87356fSDan Williams dcr->region_index = 7+1; 17535dc68e55SDan Williams dcr_common_init(dcr); 17543b87356fSDan Williams dcr->serial_number = ~handle[3]; 17553b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 17563b87356fSDan Williams dcr->windows = 0; 17573b87356fSDan Williams 17583b87356fSDan Williams offset = offset + offsetof(struct acpi_nfit_control_region, 17593b87356fSDan Williams window_size) * 4; 17606bc75619SDan Williams /* bdw0 (spa/dcr0, dimm0) */ 17616bc75619SDan Williams bdw = nfit_buf + offset; 17626bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 17636bc75619SDan Williams bdw->header.length = sizeof(struct acpi_nfit_data_region); 17646bc75619SDan Williams bdw->region_index = 0+1; 17656bc75619SDan Williams bdw->windows = 1; 17666bc75619SDan Williams bdw->offset = 0; 17676bc75619SDan Williams bdw->size = BDW_SIZE; 17686bc75619SDan Williams bdw->capacity = DIMM_SIZE; 17696bc75619SDan Williams bdw->start_address = 0; 17706bc75619SDan Williams 17716bc75619SDan Williams /* bdw1 (spa/dcr1, dimm1) */ 17726bc75619SDan Williams bdw = nfit_buf + offset + sizeof(struct acpi_nfit_data_region); 17736bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 17746bc75619SDan Williams bdw->header.length = sizeof(struct acpi_nfit_data_region); 17756bc75619SDan Williams bdw->region_index = 1+1; 17766bc75619SDan Williams bdw->windows = 1; 17776bc75619SDan Williams bdw->offset = 0; 17786bc75619SDan Williams bdw->size = BDW_SIZE; 17796bc75619SDan Williams bdw->capacity = DIMM_SIZE; 17806bc75619SDan Williams bdw->start_address = 0; 17816bc75619SDan Williams 17826bc75619SDan Williams /* bdw2 (spa/dcr2, dimm2) */ 17836bc75619SDan Williams bdw = nfit_buf + offset + sizeof(struct acpi_nfit_data_region) * 2; 17846bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 17856bc75619SDan Williams bdw->header.length = sizeof(struct acpi_nfit_data_region); 17866bc75619SDan Williams bdw->region_index = 2+1; 17876bc75619SDan Williams bdw->windows = 1; 17886bc75619SDan Williams bdw->offset = 0; 17896bc75619SDan Williams bdw->size = BDW_SIZE; 17906bc75619SDan Williams bdw->capacity = DIMM_SIZE; 17916bc75619SDan Williams bdw->start_address = 0; 17926bc75619SDan Williams 17936bc75619SDan Williams /* bdw3 (spa/dcr3, dimm3) */ 17946bc75619SDan Williams bdw = nfit_buf + offset + sizeof(struct acpi_nfit_data_region) * 3; 17956bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 17966bc75619SDan Williams bdw->header.length = sizeof(struct acpi_nfit_data_region); 17976bc75619SDan Williams bdw->region_index = 3+1; 17986bc75619SDan Williams bdw->windows = 1; 17996bc75619SDan Williams bdw->offset = 0; 18006bc75619SDan Williams bdw->size = BDW_SIZE; 18016bc75619SDan Williams bdw->capacity = DIMM_SIZE; 18026bc75619SDan Williams bdw->start_address = 0; 18036bc75619SDan Williams 18049d27a87eSDan Williams offset = offset + sizeof(struct acpi_nfit_data_region) * 4; 18059d27a87eSDan Williams /* flush0 (dimm0) */ 18069d27a87eSDan Williams flush = nfit_buf + offset; 18079d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 180885d3fa02SDan Williams flush->header.length = flush_hint_size; 18099d27a87eSDan Williams flush->device_handle = handle[0]; 181085d3fa02SDan Williams flush->hint_count = NUM_HINTS; 181185d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 181285d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[0] + i * sizeof(u64); 18139d27a87eSDan Williams 18149d27a87eSDan Williams /* flush1 (dimm1) */ 181585d3fa02SDan Williams flush = nfit_buf + offset + flush_hint_size * 1; 18169d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 181785d3fa02SDan Williams flush->header.length = flush_hint_size; 18189d27a87eSDan Williams flush->device_handle = handle[1]; 181985d3fa02SDan Williams flush->hint_count = NUM_HINTS; 182085d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 182185d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[1] + i * sizeof(u64); 18229d27a87eSDan Williams 18239d27a87eSDan Williams /* flush2 (dimm2) */ 182485d3fa02SDan Williams flush = nfit_buf + offset + flush_hint_size * 2; 18259d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 182685d3fa02SDan Williams flush->header.length = flush_hint_size; 18279d27a87eSDan Williams flush->device_handle = handle[2]; 182885d3fa02SDan Williams flush->hint_count = NUM_HINTS; 182985d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 183085d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[2] + i * sizeof(u64); 18319d27a87eSDan Williams 18329d27a87eSDan Williams /* flush3 (dimm3) */ 183385d3fa02SDan Williams flush = nfit_buf + offset + flush_hint_size * 3; 18349d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 183585d3fa02SDan Williams flush->header.length = flush_hint_size; 18369d27a87eSDan Williams flush->device_handle = handle[3]; 183785d3fa02SDan Williams flush->hint_count = NUM_HINTS; 183885d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 183985d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[3] + i * sizeof(u64); 18409d27a87eSDan Williams 184120985164SVishal Verma if (t->setup_hotplug) { 184285d3fa02SDan Williams offset = offset + flush_hint_size * 4; 18433b87356fSDan Williams /* dcr-descriptor4: blk */ 184420985164SVishal Verma dcr = nfit_buf + offset; 184520985164SVishal Verma dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 184620985164SVishal Verma dcr->header.length = sizeof(struct acpi_nfit_control_region); 18473b87356fSDan Williams dcr->region_index = 8+1; 18485dc68e55SDan Williams dcr_common_init(dcr); 184920985164SVishal Verma dcr->serial_number = ~handle[4]; 1850be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 185120985164SVishal Verma dcr->windows = 1; 185220985164SVishal Verma dcr->window_size = DCR_SIZE; 185320985164SVishal Verma dcr->command_offset = 0; 185420985164SVishal Verma dcr->command_size = 8; 185520985164SVishal Verma dcr->status_offset = 8; 185620985164SVishal Verma dcr->status_size = 4; 185720985164SVishal Verma 185820985164SVishal Verma offset = offset + sizeof(struct acpi_nfit_control_region); 18593b87356fSDan Williams /* dcr-descriptor4: pmem */ 18603b87356fSDan Williams dcr = nfit_buf + offset; 18613b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 18623b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 18633b87356fSDan Williams window_size); 18643b87356fSDan Williams dcr->region_index = 9+1; 18655dc68e55SDan Williams dcr_common_init(dcr); 18663b87356fSDan Williams dcr->serial_number = ~handle[4]; 18673b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 18683b87356fSDan Williams dcr->windows = 0; 18693b87356fSDan Williams 18703b87356fSDan Williams offset = offset + offsetof(struct acpi_nfit_control_region, 18713b87356fSDan Williams window_size); 187220985164SVishal Verma /* bdw4 (spa/dcr4, dimm4) */ 187320985164SVishal Verma bdw = nfit_buf + offset; 187420985164SVishal Verma bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 187520985164SVishal Verma bdw->header.length = sizeof(struct acpi_nfit_data_region); 18763b87356fSDan Williams bdw->region_index = 8+1; 187720985164SVishal Verma bdw->windows = 1; 187820985164SVishal Verma bdw->offset = 0; 187920985164SVishal Verma bdw->size = BDW_SIZE; 188020985164SVishal Verma bdw->capacity = DIMM_SIZE; 188120985164SVishal Verma bdw->start_address = 0; 188220985164SVishal Verma 188320985164SVishal Verma offset = offset + sizeof(struct acpi_nfit_data_region); 188420985164SVishal Verma /* spa10 (dcr4) dimm4 */ 188520985164SVishal Verma spa = nfit_buf + offset; 188620985164SVishal Verma spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 188720985164SVishal Verma spa->header.length = sizeof(*spa); 188820985164SVishal Verma memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 188920985164SVishal Verma spa->range_index = 10+1; 189020985164SVishal Verma spa->address = t->dcr_dma[4]; 189120985164SVishal Verma spa->length = DCR_SIZE; 189220985164SVishal Verma 189320985164SVishal Verma /* 189420985164SVishal Verma * spa11 (single-dimm interleave for hotplug, note storage 189520985164SVishal Verma * does not actually alias the related block-data-window 189620985164SVishal Verma * regions) 189720985164SVishal Verma */ 189820985164SVishal Verma spa = nfit_buf + offset + sizeof(*spa); 189920985164SVishal Verma spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 190020985164SVishal Verma spa->header.length = sizeof(*spa); 190120985164SVishal Verma memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 190220985164SVishal Verma spa->range_index = 11+1; 190320985164SVishal Verma spa->address = t->spa_set_dma[2]; 190420985164SVishal Verma spa->length = SPA0_SIZE; 190520985164SVishal Verma 190620985164SVishal Verma /* spa12 (bdw for dcr4) dimm4 */ 190720985164SVishal Verma spa = nfit_buf + offset + sizeof(*spa) * 2; 190820985164SVishal Verma spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 190920985164SVishal Verma spa->header.length = sizeof(*spa); 191020985164SVishal Verma memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 191120985164SVishal Verma spa->range_index = 12+1; 191220985164SVishal Verma spa->address = t->dimm_dma[4]; 191320985164SVishal Verma spa->length = DIMM_SIZE; 191420985164SVishal Verma 191520985164SVishal Verma offset = offset + sizeof(*spa) * 3; 191620985164SVishal Verma /* mem-region14 (spa/dcr4, dimm4) */ 191720985164SVishal Verma memdev = nfit_buf + offset; 191820985164SVishal Verma memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 191920985164SVishal Verma memdev->header.length = sizeof(*memdev); 192020985164SVishal Verma memdev->device_handle = handle[4]; 192120985164SVishal Verma memdev->physical_id = 4; 192220985164SVishal Verma memdev->region_id = 0; 192320985164SVishal Verma memdev->range_index = 10+1; 19243b87356fSDan Williams memdev->region_index = 8+1; 192520985164SVishal Verma memdev->region_size = 0; 192620985164SVishal Verma memdev->region_offset = 0; 192720985164SVishal Verma memdev->address = 0; 192820985164SVishal Verma memdev->interleave_index = 0; 192920985164SVishal Verma memdev->interleave_ways = 1; 193020985164SVishal Verma 193120985164SVishal Verma /* mem-region15 (spa0, dimm4) */ 193220985164SVishal Verma memdev = nfit_buf + offset + 193320985164SVishal Verma sizeof(struct acpi_nfit_memory_map); 193420985164SVishal Verma memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 193520985164SVishal Verma memdev->header.length = sizeof(*memdev); 193620985164SVishal Verma memdev->device_handle = handle[4]; 193720985164SVishal Verma memdev->physical_id = 4; 193820985164SVishal Verma memdev->region_id = 0; 193920985164SVishal Verma memdev->range_index = 11+1; 19403b87356fSDan Williams memdev->region_index = 9+1; 194120985164SVishal Verma memdev->region_size = SPA0_SIZE; 1942df06a2d5SDan Williams memdev->region_offset = (1ULL << 48); 194320985164SVishal Verma memdev->address = 0; 194420985164SVishal Verma memdev->interleave_index = 0; 194520985164SVishal Verma memdev->interleave_ways = 1; 1946ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED; 194720985164SVishal Verma 19483b87356fSDan Williams /* mem-region16 (spa/bdw4, dimm4) */ 194920985164SVishal Verma memdev = nfit_buf + offset + 195020985164SVishal Verma sizeof(struct acpi_nfit_memory_map) * 2; 195120985164SVishal Verma memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 195220985164SVishal Verma memdev->header.length = sizeof(*memdev); 195320985164SVishal Verma memdev->device_handle = handle[4]; 195420985164SVishal Verma memdev->physical_id = 4; 195520985164SVishal Verma memdev->region_id = 0; 195620985164SVishal Verma memdev->range_index = 12+1; 19573b87356fSDan Williams memdev->region_index = 8+1; 195820985164SVishal Verma memdev->region_size = 0; 195920985164SVishal Verma memdev->region_offset = 0; 196020985164SVishal Verma memdev->address = 0; 196120985164SVishal Verma memdev->interleave_index = 0; 196220985164SVishal Verma memdev->interleave_ways = 1; 196320985164SVishal Verma 196420985164SVishal Verma offset = offset + sizeof(struct acpi_nfit_memory_map) * 3; 196520985164SVishal Verma /* flush3 (dimm4) */ 196620985164SVishal Verma flush = nfit_buf + offset; 196720985164SVishal Verma flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 196885d3fa02SDan Williams flush->header.length = flush_hint_size; 196920985164SVishal Verma flush->device_handle = handle[4]; 197085d3fa02SDan Williams flush->hint_count = NUM_HINTS; 197185d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 197285d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[4] 197385d3fa02SDan Williams + i * sizeof(u64); 197420985164SVishal Verma } 197520985164SVishal Verma 19769fb1a190SDave Jiang post_ars_status(&t->ars_state, &t->badrange, t->spa_set_dma[0], 19779fb1a190SDave Jiang SPA0_SIZE); 1978f471f1a7SDan Williams 19796bc75619SDan Williams acpi_desc = &t->acpi_desc; 1980e3654ecaSDan Williams set_bit(ND_CMD_GET_CONFIG_SIZE, &acpi_desc->dimm_cmd_force_en); 1981e3654ecaSDan Williams set_bit(ND_CMD_GET_CONFIG_DATA, &acpi_desc->dimm_cmd_force_en); 1982e3654ecaSDan Williams set_bit(ND_CMD_SET_CONFIG_DATA, &acpi_desc->dimm_cmd_force_en); 1983ed07c433SDan Williams set_bit(ND_INTEL_SMART, &acpi_desc->dimm_cmd_force_en); 1984ed07c433SDan Williams set_bit(ND_INTEL_SMART_THRESHOLD, &acpi_desc->dimm_cmd_force_en); 1985ed07c433SDan Williams set_bit(ND_INTEL_SMART_SET_THRESHOLD, &acpi_desc->dimm_cmd_force_en); 1986e3654ecaSDan Williams set_bit(ND_CMD_ARS_CAP, &acpi_desc->bus_cmd_force_en); 1987e3654ecaSDan Williams set_bit(ND_CMD_ARS_START, &acpi_desc->bus_cmd_force_en); 1988e3654ecaSDan Williams set_bit(ND_CMD_ARS_STATUS, &acpi_desc->bus_cmd_force_en); 1989e3654ecaSDan Williams set_bit(ND_CMD_CLEAR_ERROR, &acpi_desc->bus_cmd_force_en); 199010246dc8SYasunori Goto set_bit(ND_CMD_CALL, &acpi_desc->bus_cmd_force_en); 199110246dc8SYasunori Goto set_bit(NFIT_CMD_TRANSLATE_SPA, &acpi_desc->bus_nfit_cmd_force_en); 19929fb1a190SDave Jiang set_bit(NFIT_CMD_ARS_INJECT_SET, &acpi_desc->bus_nfit_cmd_force_en); 19939fb1a190SDave Jiang set_bit(NFIT_CMD_ARS_INJECT_CLEAR, &acpi_desc->bus_nfit_cmd_force_en); 19949fb1a190SDave Jiang set_bit(NFIT_CMD_ARS_INJECT_GET, &acpi_desc->bus_nfit_cmd_force_en); 1995*bfbaa952SDave Jiang set_bit(ND_INTEL_FW_GET_INFO, &acpi_desc->dimm_cmd_force_en); 1996*bfbaa952SDave Jiang set_bit(ND_INTEL_FW_START_UPDATE, &acpi_desc->dimm_cmd_force_en); 1997*bfbaa952SDave Jiang set_bit(ND_INTEL_FW_SEND_DATA, &acpi_desc->dimm_cmd_force_en); 1998*bfbaa952SDave Jiang set_bit(ND_INTEL_FW_FINISH_UPDATE, &acpi_desc->dimm_cmd_force_en); 1999*bfbaa952SDave Jiang set_bit(ND_INTEL_FW_FINISH_QUERY, &acpi_desc->dimm_cmd_force_en); 20006bc75619SDan Williams } 20016bc75619SDan Williams 20026bc75619SDan Williams static void nfit_test1_setup(struct nfit_test *t) 20036bc75619SDan Williams { 20046b577c9dSLinda Knippers size_t offset; 20056bc75619SDan Williams void *nfit_buf = t->nfit_buf; 20066bc75619SDan Williams struct acpi_nfit_memory_map *memdev; 20076bc75619SDan Williams struct acpi_nfit_control_region *dcr; 20086bc75619SDan Williams struct acpi_nfit_system_address *spa; 2009d26f73f0SDan Williams struct acpi_nfit_desc *acpi_desc; 20106bc75619SDan Williams 20116b577c9dSLinda Knippers offset = 0; 20126bc75619SDan Williams /* spa0 (flat range with no bdw aliasing) */ 20136bc75619SDan Williams spa = nfit_buf + offset; 20146bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 20156bc75619SDan Williams spa->header.length = sizeof(*spa); 20166bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 20176bc75619SDan Williams spa->range_index = 0+1; 20186bc75619SDan Williams spa->address = t->spa_set_dma[0]; 20196bc75619SDan Williams spa->length = SPA2_SIZE; 20206bc75619SDan Williams 20217bfe97c7SDan Williams /* virtual cd region */ 20227bfe97c7SDan Williams spa = nfit_buf + sizeof(*spa); 20237bfe97c7SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 20247bfe97c7SDan Williams spa->header.length = sizeof(*spa); 20257bfe97c7SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_VCD), 16); 20267bfe97c7SDan Williams spa->range_index = 0; 20277bfe97c7SDan Williams spa->address = t->spa_set_dma[1]; 20287bfe97c7SDan Williams spa->length = SPA_VCD_SIZE; 20297bfe97c7SDan Williams 20307bfe97c7SDan Williams offset += sizeof(*spa) * 2; 20316bc75619SDan Williams /* mem-region0 (spa0, dimm0) */ 20326bc75619SDan Williams memdev = nfit_buf + offset; 20336bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 20346bc75619SDan Williams memdev->header.length = sizeof(*memdev); 2035dafb1048SDan Williams memdev->device_handle = handle[5]; 20366bc75619SDan Williams memdev->physical_id = 0; 20376bc75619SDan Williams memdev->region_id = 0; 20386bc75619SDan Williams memdev->range_index = 0+1; 20396bc75619SDan Williams memdev->region_index = 0+1; 20406bc75619SDan Williams memdev->region_size = SPA2_SIZE; 20416bc75619SDan Williams memdev->region_offset = 0; 20426bc75619SDan Williams memdev->address = 0; 20436bc75619SDan Williams memdev->interleave_index = 0; 20446bc75619SDan Williams memdev->interleave_ways = 1; 204558138820SDan Williams memdev->flags = ACPI_NFIT_MEM_SAVE_FAILED | ACPI_NFIT_MEM_RESTORE_FAILED 204658138820SDan Williams | ACPI_NFIT_MEM_FLUSH_FAILED | ACPI_NFIT_MEM_HEALTH_OBSERVED 2047f4295796SDan Williams | ACPI_NFIT_MEM_NOT_ARMED; 20486bc75619SDan Williams 20496bc75619SDan Williams offset += sizeof(*memdev); 20506bc75619SDan Williams /* dcr-descriptor0 */ 20516bc75619SDan Williams dcr = nfit_buf + offset; 20526bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 20533b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 20543b87356fSDan Williams window_size); 20556bc75619SDan Williams dcr->region_index = 0+1; 20565dc68e55SDan Williams dcr_common_init(dcr); 2057dafb1048SDan Williams dcr->serial_number = ~handle[5]; 2058be26f9aeSDan Williams dcr->code = NFIT_FIC_BYTE; 20596bc75619SDan Williams dcr->windows = 0; 2060d26f73f0SDan Williams 2061ac40b675SDan Williams offset += dcr->header.length; 2062ac40b675SDan Williams memdev = nfit_buf + offset; 2063ac40b675SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 2064ac40b675SDan Williams memdev->header.length = sizeof(*memdev); 2065ac40b675SDan Williams memdev->device_handle = handle[6]; 2066ac40b675SDan Williams memdev->physical_id = 0; 2067ac40b675SDan Williams memdev->region_id = 0; 2068ac40b675SDan Williams memdev->range_index = 0; 2069ac40b675SDan Williams memdev->region_index = 0+2; 2070ac40b675SDan Williams memdev->region_size = SPA2_SIZE; 2071ac40b675SDan Williams memdev->region_offset = 0; 2072ac40b675SDan Williams memdev->address = 0; 2073ac40b675SDan Williams memdev->interleave_index = 0; 2074ac40b675SDan Williams memdev->interleave_ways = 1; 2075ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_MAP_FAILED; 2076ac40b675SDan Williams 2077ac40b675SDan Williams /* dcr-descriptor1 */ 2078ac40b675SDan Williams offset += sizeof(*memdev); 2079ac40b675SDan Williams dcr = nfit_buf + offset; 2080ac40b675SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 2081ac40b675SDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 2082ac40b675SDan Williams window_size); 2083ac40b675SDan Williams dcr->region_index = 0+2; 2084ac40b675SDan Williams dcr_common_init(dcr); 2085ac40b675SDan Williams dcr->serial_number = ~handle[6]; 2086ac40b675SDan Williams dcr->code = NFIT_FIC_BYTE; 2087ac40b675SDan Williams dcr->windows = 0; 2088ac40b675SDan Williams 20899fb1a190SDave Jiang post_ars_status(&t->ars_state, &t->badrange, t->spa_set_dma[0], 20909fb1a190SDave Jiang SPA2_SIZE); 2091f471f1a7SDan Williams 2092d26f73f0SDan Williams acpi_desc = &t->acpi_desc; 2093e3654ecaSDan Williams set_bit(ND_CMD_ARS_CAP, &acpi_desc->bus_cmd_force_en); 2094e3654ecaSDan Williams set_bit(ND_CMD_ARS_START, &acpi_desc->bus_cmd_force_en); 2095e3654ecaSDan Williams set_bit(ND_CMD_ARS_STATUS, &acpi_desc->bus_cmd_force_en); 2096e3654ecaSDan Williams set_bit(ND_CMD_CLEAR_ERROR, &acpi_desc->bus_cmd_force_en); 20976bc75619SDan Williams } 20986bc75619SDan Williams 20996bc75619SDan Williams static int nfit_test_blk_do_io(struct nd_blk_region *ndbr, resource_size_t dpa, 21006bc75619SDan Williams void *iobuf, u64 len, int rw) 21016bc75619SDan Williams { 21026bc75619SDan Williams struct nfit_blk *nfit_blk = ndbr->blk_provider_data; 21036bc75619SDan Williams struct nfit_blk_mmio *mmio = &nfit_blk->mmio[BDW]; 21046bc75619SDan Williams struct nd_region *nd_region = &ndbr->nd_region; 21056bc75619SDan Williams unsigned int lane; 21066bc75619SDan Williams 21076bc75619SDan Williams lane = nd_region_acquire_lane(nd_region); 21086bc75619SDan Williams if (rw) 210967a3e8feSRoss Zwisler memcpy(mmio->addr.base + dpa, iobuf, len); 211067a3e8feSRoss Zwisler else { 211167a3e8feSRoss Zwisler memcpy(iobuf, mmio->addr.base + dpa, len); 211267a3e8feSRoss Zwisler 21135deb67f7SRobin Murphy /* give us some some coverage of the arch_invalidate_pmem() API */ 21145deb67f7SRobin Murphy arch_invalidate_pmem(mmio->addr.base + dpa, len); 211567a3e8feSRoss Zwisler } 21166bc75619SDan Williams nd_region_release_lane(nd_region, lane); 21176bc75619SDan Williams 21186bc75619SDan Williams return 0; 21196bc75619SDan Williams } 21206bc75619SDan Williams 2121a7de92daSDan Williams static unsigned long nfit_ctl_handle; 2122a7de92daSDan Williams 2123a7de92daSDan Williams union acpi_object *result; 2124a7de92daSDan Williams 2125a7de92daSDan Williams static union acpi_object *nfit_test_evaluate_dsm(acpi_handle handle, 212694116f81SAndy Shevchenko const guid_t *guid, u64 rev, u64 func, union acpi_object *argv4) 2127a7de92daSDan Williams { 2128a7de92daSDan Williams if (handle != &nfit_ctl_handle) 2129a7de92daSDan Williams return ERR_PTR(-ENXIO); 2130a7de92daSDan Williams 2131a7de92daSDan Williams return result; 2132a7de92daSDan Williams } 2133a7de92daSDan Williams 2134a7de92daSDan Williams static int setup_result(void *buf, size_t size) 2135a7de92daSDan Williams { 2136a7de92daSDan Williams result = kmalloc(sizeof(union acpi_object) + size, GFP_KERNEL); 2137a7de92daSDan Williams if (!result) 2138a7de92daSDan Williams return -ENOMEM; 2139a7de92daSDan Williams result->package.type = ACPI_TYPE_BUFFER, 2140a7de92daSDan Williams result->buffer.pointer = (void *) (result + 1); 2141a7de92daSDan Williams result->buffer.length = size; 2142a7de92daSDan Williams memcpy(result->buffer.pointer, buf, size); 2143a7de92daSDan Williams memset(buf, 0, size); 2144a7de92daSDan Williams return 0; 2145a7de92daSDan Williams } 2146a7de92daSDan Williams 2147a7de92daSDan Williams static int nfit_ctl_test(struct device *dev) 2148a7de92daSDan Williams { 2149a7de92daSDan Williams int rc, cmd_rc; 2150a7de92daSDan Williams struct nvdimm *nvdimm; 2151a7de92daSDan Williams struct acpi_device *adev; 2152a7de92daSDan Williams struct nfit_mem *nfit_mem; 2153a7de92daSDan Williams struct nd_ars_record *record; 2154a7de92daSDan Williams struct acpi_nfit_desc *acpi_desc; 2155a7de92daSDan Williams const u64 test_val = 0x0123456789abcdefULL; 2156a7de92daSDan Williams unsigned long mask, cmd_size, offset; 2157a7de92daSDan Williams union { 2158a7de92daSDan Williams struct nd_cmd_get_config_size cfg_size; 2159fb2a1748SDan Williams struct nd_cmd_clear_error clear_err; 2160a7de92daSDan Williams struct nd_cmd_ars_status ars_stat; 2161a7de92daSDan Williams struct nd_cmd_ars_cap ars_cap; 2162a7de92daSDan Williams char buf[sizeof(struct nd_cmd_ars_status) 2163a7de92daSDan Williams + sizeof(struct nd_ars_record)]; 2164a7de92daSDan Williams } cmds; 2165a7de92daSDan Williams 2166a7de92daSDan Williams adev = devm_kzalloc(dev, sizeof(*adev), GFP_KERNEL); 2167a7de92daSDan Williams if (!adev) 2168a7de92daSDan Williams return -ENOMEM; 2169a7de92daSDan Williams *adev = (struct acpi_device) { 2170a7de92daSDan Williams .handle = &nfit_ctl_handle, 2171a7de92daSDan Williams .dev = { 2172a7de92daSDan Williams .init_name = "test-adev", 2173a7de92daSDan Williams }, 2174a7de92daSDan Williams }; 2175a7de92daSDan Williams 2176a7de92daSDan Williams acpi_desc = devm_kzalloc(dev, sizeof(*acpi_desc), GFP_KERNEL); 2177a7de92daSDan Williams if (!acpi_desc) 2178a7de92daSDan Williams return -ENOMEM; 2179a7de92daSDan Williams *acpi_desc = (struct acpi_nfit_desc) { 2180a7de92daSDan Williams .nd_desc = { 2181a7de92daSDan Williams .cmd_mask = 1UL << ND_CMD_ARS_CAP 2182a7de92daSDan Williams | 1UL << ND_CMD_ARS_START 2183a7de92daSDan Williams | 1UL << ND_CMD_ARS_STATUS 218410246dc8SYasunori Goto | 1UL << ND_CMD_CLEAR_ERROR 218510246dc8SYasunori Goto | 1UL << ND_CMD_CALL, 2186a7de92daSDan Williams .module = THIS_MODULE, 2187a7de92daSDan Williams .provider_name = "ACPI.NFIT", 2188a7de92daSDan Williams .ndctl = acpi_nfit_ctl, 21899fb1a190SDave Jiang .bus_dsm_mask = 1UL << NFIT_CMD_TRANSLATE_SPA 21909fb1a190SDave Jiang | 1UL << NFIT_CMD_ARS_INJECT_SET 21919fb1a190SDave Jiang | 1UL << NFIT_CMD_ARS_INJECT_CLEAR 21929fb1a190SDave Jiang | 1UL << NFIT_CMD_ARS_INJECT_GET, 2193a7de92daSDan Williams }, 2194a7de92daSDan Williams .dev = &adev->dev, 2195a7de92daSDan Williams }; 2196a7de92daSDan Williams 2197a7de92daSDan Williams nfit_mem = devm_kzalloc(dev, sizeof(*nfit_mem), GFP_KERNEL); 2198a7de92daSDan Williams if (!nfit_mem) 2199a7de92daSDan Williams return -ENOMEM; 2200a7de92daSDan Williams 2201a7de92daSDan Williams mask = 1UL << ND_CMD_SMART | 1UL << ND_CMD_SMART_THRESHOLD 2202a7de92daSDan Williams | 1UL << ND_CMD_DIMM_FLAGS | 1UL << ND_CMD_GET_CONFIG_SIZE 2203a7de92daSDan Williams | 1UL << ND_CMD_GET_CONFIG_DATA | 1UL << ND_CMD_SET_CONFIG_DATA 2204a7de92daSDan Williams | 1UL << ND_CMD_VENDOR; 2205a7de92daSDan Williams *nfit_mem = (struct nfit_mem) { 2206a7de92daSDan Williams .adev = adev, 2207a7de92daSDan Williams .family = NVDIMM_FAMILY_INTEL, 2208a7de92daSDan Williams .dsm_mask = mask, 2209a7de92daSDan Williams }; 2210a7de92daSDan Williams 2211a7de92daSDan Williams nvdimm = devm_kzalloc(dev, sizeof(*nvdimm), GFP_KERNEL); 2212a7de92daSDan Williams if (!nvdimm) 2213a7de92daSDan Williams return -ENOMEM; 2214a7de92daSDan Williams *nvdimm = (struct nvdimm) { 2215a7de92daSDan Williams .provider_data = nfit_mem, 2216a7de92daSDan Williams .cmd_mask = mask, 2217a7de92daSDan Williams .dev = { 2218a7de92daSDan Williams .init_name = "test-dimm", 2219a7de92daSDan Williams }, 2220a7de92daSDan Williams }; 2221a7de92daSDan Williams 2222a7de92daSDan Williams 2223a7de92daSDan Williams /* basic checkout of a typical 'get config size' command */ 2224a7de92daSDan Williams cmd_size = sizeof(cmds.cfg_size); 2225a7de92daSDan Williams cmds.cfg_size = (struct nd_cmd_get_config_size) { 2226a7de92daSDan Williams .status = 0, 2227a7de92daSDan Williams .config_size = SZ_128K, 2228a7de92daSDan Williams .max_xfer = SZ_4K, 2229a7de92daSDan Williams }; 2230a7de92daSDan Williams rc = setup_result(cmds.buf, cmd_size); 2231a7de92daSDan Williams if (rc) 2232a7de92daSDan Williams return rc; 2233a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, nvdimm, ND_CMD_GET_CONFIG_SIZE, 2234a7de92daSDan Williams cmds.buf, cmd_size, &cmd_rc); 2235a7de92daSDan Williams 2236a7de92daSDan Williams if (rc < 0 || cmd_rc || cmds.cfg_size.status != 0 2237a7de92daSDan Williams || cmds.cfg_size.config_size != SZ_128K 2238a7de92daSDan Williams || cmds.cfg_size.max_xfer != SZ_4K) { 2239a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 2240a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 2241a7de92daSDan Williams return -EIO; 2242a7de92daSDan Williams } 2243a7de92daSDan Williams 2244a7de92daSDan Williams 2245a7de92daSDan Williams /* test ars_status with zero output */ 2246a7de92daSDan Williams cmd_size = offsetof(struct nd_cmd_ars_status, address); 2247a7de92daSDan Williams cmds.ars_stat = (struct nd_cmd_ars_status) { 2248a7de92daSDan Williams .out_length = 0, 2249a7de92daSDan Williams }; 2250a7de92daSDan Williams rc = setup_result(cmds.buf, cmd_size); 2251a7de92daSDan Williams if (rc) 2252a7de92daSDan Williams return rc; 2253a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_ARS_STATUS, 2254a7de92daSDan Williams cmds.buf, cmd_size, &cmd_rc); 2255a7de92daSDan Williams 2256a7de92daSDan Williams if (rc < 0 || cmd_rc) { 2257a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 2258a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 2259a7de92daSDan Williams return -EIO; 2260a7de92daSDan Williams } 2261a7de92daSDan Williams 2262a7de92daSDan Williams 2263a7de92daSDan Williams /* test ars_cap with benign extended status */ 2264a7de92daSDan Williams cmd_size = sizeof(cmds.ars_cap); 2265a7de92daSDan Williams cmds.ars_cap = (struct nd_cmd_ars_cap) { 2266a7de92daSDan Williams .status = ND_ARS_PERSISTENT << 16, 2267a7de92daSDan Williams }; 2268a7de92daSDan Williams offset = offsetof(struct nd_cmd_ars_cap, status); 2269a7de92daSDan Williams rc = setup_result(cmds.buf + offset, cmd_size - offset); 2270a7de92daSDan Williams if (rc) 2271a7de92daSDan Williams return rc; 2272a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_ARS_CAP, 2273a7de92daSDan Williams cmds.buf, cmd_size, &cmd_rc); 2274a7de92daSDan Williams 2275a7de92daSDan Williams if (rc < 0 || cmd_rc) { 2276a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 2277a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 2278a7de92daSDan Williams return -EIO; 2279a7de92daSDan Williams } 2280a7de92daSDan Williams 2281a7de92daSDan Williams 2282a7de92daSDan Williams /* test ars_status with 'status' trimmed from 'out_length' */ 2283a7de92daSDan Williams cmd_size = sizeof(cmds.ars_stat) + sizeof(struct nd_ars_record); 2284a7de92daSDan Williams cmds.ars_stat = (struct nd_cmd_ars_status) { 2285a7de92daSDan Williams .out_length = cmd_size - 4, 2286a7de92daSDan Williams }; 2287a7de92daSDan Williams record = &cmds.ars_stat.records[0]; 2288a7de92daSDan Williams *record = (struct nd_ars_record) { 2289a7de92daSDan Williams .length = test_val, 2290a7de92daSDan Williams }; 2291a7de92daSDan Williams rc = setup_result(cmds.buf, cmd_size); 2292a7de92daSDan Williams if (rc) 2293a7de92daSDan Williams return rc; 2294a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_ARS_STATUS, 2295a7de92daSDan Williams cmds.buf, cmd_size, &cmd_rc); 2296a7de92daSDan Williams 2297a7de92daSDan Williams if (rc < 0 || cmd_rc || record->length != test_val) { 2298a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 2299a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 2300a7de92daSDan Williams return -EIO; 2301a7de92daSDan Williams } 2302a7de92daSDan Williams 2303a7de92daSDan Williams 2304a7de92daSDan Williams /* test ars_status with 'Output (Size)' including 'status' */ 2305a7de92daSDan Williams cmd_size = sizeof(cmds.ars_stat) + sizeof(struct nd_ars_record); 2306a7de92daSDan Williams cmds.ars_stat = (struct nd_cmd_ars_status) { 2307a7de92daSDan Williams .out_length = cmd_size, 2308a7de92daSDan Williams }; 2309a7de92daSDan Williams record = &cmds.ars_stat.records[0]; 2310a7de92daSDan Williams *record = (struct nd_ars_record) { 2311a7de92daSDan Williams .length = test_val, 2312a7de92daSDan Williams }; 2313a7de92daSDan Williams rc = setup_result(cmds.buf, cmd_size); 2314a7de92daSDan Williams if (rc) 2315a7de92daSDan Williams return rc; 2316a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_ARS_STATUS, 2317a7de92daSDan Williams cmds.buf, cmd_size, &cmd_rc); 2318a7de92daSDan Williams 2319a7de92daSDan Williams if (rc < 0 || cmd_rc || record->length != test_val) { 2320a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 2321a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 2322a7de92daSDan Williams return -EIO; 2323a7de92daSDan Williams } 2324a7de92daSDan Williams 2325a7de92daSDan Williams 2326a7de92daSDan Williams /* test extended status for get_config_size results in failure */ 2327a7de92daSDan Williams cmd_size = sizeof(cmds.cfg_size); 2328a7de92daSDan Williams cmds.cfg_size = (struct nd_cmd_get_config_size) { 2329a7de92daSDan Williams .status = 1 << 16, 2330a7de92daSDan Williams }; 2331a7de92daSDan Williams rc = setup_result(cmds.buf, cmd_size); 2332a7de92daSDan Williams if (rc) 2333a7de92daSDan Williams return rc; 2334a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, nvdimm, ND_CMD_GET_CONFIG_SIZE, 2335a7de92daSDan Williams cmds.buf, cmd_size, &cmd_rc); 2336a7de92daSDan Williams 2337a7de92daSDan Williams if (rc < 0 || cmd_rc >= 0) { 2338a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 2339a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 2340a7de92daSDan Williams return -EIO; 2341a7de92daSDan Williams } 2342a7de92daSDan Williams 2343fb2a1748SDan Williams /* test clear error */ 2344fb2a1748SDan Williams cmd_size = sizeof(cmds.clear_err); 2345fb2a1748SDan Williams cmds.clear_err = (struct nd_cmd_clear_error) { 2346fb2a1748SDan Williams .length = 512, 2347fb2a1748SDan Williams .cleared = 512, 2348fb2a1748SDan Williams }; 2349fb2a1748SDan Williams rc = setup_result(cmds.buf, cmd_size); 2350fb2a1748SDan Williams if (rc) 2351fb2a1748SDan Williams return rc; 2352fb2a1748SDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_CLEAR_ERROR, 2353fb2a1748SDan Williams cmds.buf, cmd_size, &cmd_rc); 2354fb2a1748SDan Williams if (rc < 0 || cmd_rc) { 2355fb2a1748SDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 2356fb2a1748SDan Williams __func__, __LINE__, rc, cmd_rc); 2357fb2a1748SDan Williams return -EIO; 2358fb2a1748SDan Williams } 2359fb2a1748SDan Williams 2360a7de92daSDan Williams return 0; 2361a7de92daSDan Williams } 2362a7de92daSDan Williams 23636bc75619SDan Williams static int nfit_test_probe(struct platform_device *pdev) 23646bc75619SDan Williams { 23656bc75619SDan Williams struct nvdimm_bus_descriptor *nd_desc; 23666bc75619SDan Williams struct acpi_nfit_desc *acpi_desc; 23676bc75619SDan Williams struct device *dev = &pdev->dev; 23686bc75619SDan Williams struct nfit_test *nfit_test; 2369231bf117SDan Williams struct nfit_mem *nfit_mem; 2370c14a868aSDan Williams union acpi_object *obj; 23716bc75619SDan Williams int rc; 23726bc75619SDan Williams 2373a7de92daSDan Williams if (strcmp(dev_name(&pdev->dev), "nfit_test.0") == 0) { 2374a7de92daSDan Williams rc = nfit_ctl_test(&pdev->dev); 2375a7de92daSDan Williams if (rc) 2376a7de92daSDan Williams return rc; 2377a7de92daSDan Williams } 2378a7de92daSDan Williams 23796bc75619SDan Williams nfit_test = to_nfit_test(&pdev->dev); 23806bc75619SDan Williams 23816bc75619SDan Williams /* common alloc */ 23826bc75619SDan Williams if (nfit_test->num_dcr) { 23836bc75619SDan Williams int num = nfit_test->num_dcr; 23846bc75619SDan Williams 23856bc75619SDan Williams nfit_test->dimm = devm_kcalloc(dev, num, sizeof(void *), 23866bc75619SDan Williams GFP_KERNEL); 23876bc75619SDan Williams nfit_test->dimm_dma = devm_kcalloc(dev, num, sizeof(dma_addr_t), 23886bc75619SDan Williams GFP_KERNEL); 23899d27a87eSDan Williams nfit_test->flush = devm_kcalloc(dev, num, sizeof(void *), 23909d27a87eSDan Williams GFP_KERNEL); 23919d27a87eSDan Williams nfit_test->flush_dma = devm_kcalloc(dev, num, sizeof(dma_addr_t), 23929d27a87eSDan Williams GFP_KERNEL); 23936bc75619SDan Williams nfit_test->label = devm_kcalloc(dev, num, sizeof(void *), 23946bc75619SDan Williams GFP_KERNEL); 23956bc75619SDan Williams nfit_test->label_dma = devm_kcalloc(dev, num, 23966bc75619SDan Williams sizeof(dma_addr_t), GFP_KERNEL); 23976bc75619SDan Williams nfit_test->dcr = devm_kcalloc(dev, num, 23986bc75619SDan Williams sizeof(struct nfit_test_dcr *), GFP_KERNEL); 23996bc75619SDan Williams nfit_test->dcr_dma = devm_kcalloc(dev, num, 24006bc75619SDan Williams sizeof(dma_addr_t), GFP_KERNEL); 2401ed07c433SDan Williams nfit_test->smart = devm_kcalloc(dev, num, 2402ed07c433SDan Williams sizeof(struct nd_intel_smart), GFP_KERNEL); 2403ed07c433SDan Williams nfit_test->smart_threshold = devm_kcalloc(dev, num, 2404ed07c433SDan Williams sizeof(struct nd_intel_smart_threshold), 2405ed07c433SDan Williams GFP_KERNEL); 2406*bfbaa952SDave Jiang nfit_test->fw = devm_kcalloc(dev, num, 2407*bfbaa952SDave Jiang sizeof(struct nfit_test_fw), GFP_KERNEL); 24086bc75619SDan Williams if (nfit_test->dimm && nfit_test->dimm_dma && nfit_test->label 24096bc75619SDan Williams && nfit_test->label_dma && nfit_test->dcr 24109d27a87eSDan Williams && nfit_test->dcr_dma && nfit_test->flush 2411*bfbaa952SDave Jiang && nfit_test->flush_dma 2412*bfbaa952SDave Jiang && nfit_test->fw) 24136bc75619SDan Williams /* pass */; 24146bc75619SDan Williams else 24156bc75619SDan Williams return -ENOMEM; 24166bc75619SDan Williams } 24176bc75619SDan Williams 24186bc75619SDan Williams if (nfit_test->num_pm) { 24196bc75619SDan Williams int num = nfit_test->num_pm; 24206bc75619SDan Williams 24216bc75619SDan Williams nfit_test->spa_set = devm_kcalloc(dev, num, sizeof(void *), 24226bc75619SDan Williams GFP_KERNEL); 24236bc75619SDan Williams nfit_test->spa_set_dma = devm_kcalloc(dev, num, 24246bc75619SDan Williams sizeof(dma_addr_t), GFP_KERNEL); 24256bc75619SDan Williams if (nfit_test->spa_set && nfit_test->spa_set_dma) 24266bc75619SDan Williams /* pass */; 24276bc75619SDan Williams else 24286bc75619SDan Williams return -ENOMEM; 24296bc75619SDan Williams } 24306bc75619SDan Williams 24316bc75619SDan Williams /* per-nfit specific alloc */ 24326bc75619SDan Williams if (nfit_test->alloc(nfit_test)) 24336bc75619SDan Williams return -ENOMEM; 24346bc75619SDan Williams 24356bc75619SDan Williams nfit_test->setup(nfit_test); 24366bc75619SDan Williams acpi_desc = &nfit_test->acpi_desc; 2437a61fe6f7SDan Williams acpi_nfit_desc_init(acpi_desc, &pdev->dev); 24386bc75619SDan Williams acpi_desc->blk_do_io = nfit_test_blk_do_io; 24396bc75619SDan Williams nd_desc = &acpi_desc->nd_desc; 2440a61fe6f7SDan Williams nd_desc->provider_name = NULL; 2441bc9775d8SDan Williams nd_desc->module = THIS_MODULE; 2442a61fe6f7SDan Williams nd_desc->ndctl = nfit_test_ctl; 24436bc75619SDan Williams 2444e7a11b44SDan Williams rc = acpi_nfit_init(acpi_desc, nfit_test->nfit_buf, 2445e7a11b44SDan Williams nfit_test->nfit_size); 244658cd71b4SDan Williams if (rc) 244720985164SVishal Verma return rc; 244820985164SVishal Verma 2449fbabd829SDan Williams rc = devm_add_action_or_reset(&pdev->dev, acpi_nfit_shutdown, acpi_desc); 2450fbabd829SDan Williams if (rc) 2451fbabd829SDan Williams return rc; 2452fbabd829SDan Williams 245320985164SVishal Verma if (nfit_test->setup != nfit_test0_setup) 245420985164SVishal Verma return 0; 245520985164SVishal Verma 245620985164SVishal Verma nfit_test->setup_hotplug = 1; 245720985164SVishal Verma nfit_test->setup(nfit_test); 245820985164SVishal Verma 2459c14a868aSDan Williams obj = kzalloc(sizeof(*obj), GFP_KERNEL); 2460c14a868aSDan Williams if (!obj) 2461c14a868aSDan Williams return -ENOMEM; 2462c14a868aSDan Williams obj->type = ACPI_TYPE_BUFFER; 2463c14a868aSDan Williams obj->buffer.length = nfit_test->nfit_size; 2464c14a868aSDan Williams obj->buffer.pointer = nfit_test->nfit_buf; 2465c14a868aSDan Williams *(nfit_test->_fit) = obj; 2466c14a868aSDan Williams __acpi_nfit_notify(&pdev->dev, nfit_test, 0x80); 2467231bf117SDan Williams 2468231bf117SDan Williams /* associate dimm devices with nfit_mem data for notification testing */ 2469231bf117SDan Williams mutex_lock(&acpi_desc->init_mutex); 2470231bf117SDan Williams list_for_each_entry(nfit_mem, &acpi_desc->dimms, list) { 2471231bf117SDan Williams u32 nfit_handle = __to_nfit_memdev(nfit_mem)->device_handle; 2472231bf117SDan Williams int i; 2473231bf117SDan Williams 2474231bf117SDan Williams for (i = 0; i < NUM_DCR; i++) 2475231bf117SDan Williams if (nfit_handle == handle[i]) 2476231bf117SDan Williams dev_set_drvdata(nfit_test->dimm_dev[i], 2477231bf117SDan Williams nfit_mem); 2478231bf117SDan Williams } 2479231bf117SDan Williams mutex_unlock(&acpi_desc->init_mutex); 24806bc75619SDan Williams 24816bc75619SDan Williams return 0; 24826bc75619SDan Williams } 24836bc75619SDan Williams 24846bc75619SDan Williams static int nfit_test_remove(struct platform_device *pdev) 24856bc75619SDan Williams { 24866bc75619SDan Williams return 0; 24876bc75619SDan Williams } 24886bc75619SDan Williams 24896bc75619SDan Williams static void nfit_test_release(struct device *dev) 24906bc75619SDan Williams { 24916bc75619SDan Williams struct nfit_test *nfit_test = to_nfit_test(dev); 24926bc75619SDan Williams 24936bc75619SDan Williams kfree(nfit_test); 24946bc75619SDan Williams } 24956bc75619SDan Williams 24966bc75619SDan Williams static const struct platform_device_id nfit_test_id[] = { 24976bc75619SDan Williams { KBUILD_MODNAME }, 24986bc75619SDan Williams { }, 24996bc75619SDan Williams }; 25006bc75619SDan Williams 25016bc75619SDan Williams static struct platform_driver nfit_test_driver = { 25026bc75619SDan Williams .probe = nfit_test_probe, 25036bc75619SDan Williams .remove = nfit_test_remove, 25046bc75619SDan Williams .driver = { 25056bc75619SDan Williams .name = KBUILD_MODNAME, 25066bc75619SDan Williams }, 25076bc75619SDan Williams .id_table = nfit_test_id, 25086bc75619SDan Williams }; 25096bc75619SDan Williams 25106bc75619SDan Williams static __init int nfit_test_init(void) 25116bc75619SDan Williams { 25126bc75619SDan Williams int rc, i; 25136bc75619SDan Williams 2514a7de92daSDan Williams nfit_test_setup(nfit_test_lookup, nfit_test_evaluate_dsm); 2515231bf117SDan Williams 25169fb1a190SDave Jiang nfit_wq = create_singlethread_workqueue("nfit"); 25179fb1a190SDave Jiang if (!nfit_wq) 25189fb1a190SDave Jiang return -ENOMEM; 25199fb1a190SDave Jiang 2520a7de92daSDan Williams nfit_test_dimm = class_create(THIS_MODULE, "nfit_test_dimm"); 2521a7de92daSDan Williams if (IS_ERR(nfit_test_dimm)) { 2522a7de92daSDan Williams rc = PTR_ERR(nfit_test_dimm); 2523a7de92daSDan Williams goto err_register; 2524a7de92daSDan Williams } 25256bc75619SDan Williams 25266bc75619SDan Williams for (i = 0; i < NUM_NFITS; i++) { 25276bc75619SDan Williams struct nfit_test *nfit_test; 25286bc75619SDan Williams struct platform_device *pdev; 25296bc75619SDan Williams 25306bc75619SDan Williams nfit_test = kzalloc(sizeof(*nfit_test), GFP_KERNEL); 25316bc75619SDan Williams if (!nfit_test) { 25326bc75619SDan Williams rc = -ENOMEM; 25336bc75619SDan Williams goto err_register; 25346bc75619SDan Williams } 25356bc75619SDan Williams INIT_LIST_HEAD(&nfit_test->resources); 25369fb1a190SDave Jiang badrange_init(&nfit_test->badrange); 25376bc75619SDan Williams switch (i) { 25386bc75619SDan Williams case 0: 25396bc75619SDan Williams nfit_test->num_pm = NUM_PM; 2540dafb1048SDan Williams nfit_test->dcr_idx = 0; 25416bc75619SDan Williams nfit_test->num_dcr = NUM_DCR; 25426bc75619SDan Williams nfit_test->alloc = nfit_test0_alloc; 25436bc75619SDan Williams nfit_test->setup = nfit_test0_setup; 25446bc75619SDan Williams break; 25456bc75619SDan Williams case 1: 2546a117699cSYasunori Goto nfit_test->num_pm = 2; 2547dafb1048SDan Williams nfit_test->dcr_idx = NUM_DCR; 2548ac40b675SDan Williams nfit_test->num_dcr = 2; 25496bc75619SDan Williams nfit_test->alloc = nfit_test1_alloc; 25506bc75619SDan Williams nfit_test->setup = nfit_test1_setup; 25516bc75619SDan Williams break; 25526bc75619SDan Williams default: 25536bc75619SDan Williams rc = -EINVAL; 25546bc75619SDan Williams goto err_register; 25556bc75619SDan Williams } 25566bc75619SDan Williams pdev = &nfit_test->pdev; 25576bc75619SDan Williams pdev->name = KBUILD_MODNAME; 25586bc75619SDan Williams pdev->id = i; 25596bc75619SDan Williams pdev->dev.release = nfit_test_release; 25606bc75619SDan Williams rc = platform_device_register(pdev); 25616bc75619SDan Williams if (rc) { 25626bc75619SDan Williams put_device(&pdev->dev); 25636bc75619SDan Williams goto err_register; 25646bc75619SDan Williams } 25658b06b884SDan Williams get_device(&pdev->dev); 25666bc75619SDan Williams 25676bc75619SDan Williams rc = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); 25686bc75619SDan Williams if (rc) 25696bc75619SDan Williams goto err_register; 25706bc75619SDan Williams 25716bc75619SDan Williams instances[i] = nfit_test; 25729fb1a190SDave Jiang INIT_WORK(&nfit_test->work, uc_error_notify); 25736bc75619SDan Williams } 25746bc75619SDan Williams 25756bc75619SDan Williams rc = platform_driver_register(&nfit_test_driver); 25766bc75619SDan Williams if (rc) 25776bc75619SDan Williams goto err_register; 25786bc75619SDan Williams return 0; 25796bc75619SDan Williams 25806bc75619SDan Williams err_register: 25819fb1a190SDave Jiang destroy_workqueue(nfit_wq); 25826bc75619SDan Williams for (i = 0; i < NUM_NFITS; i++) 25836bc75619SDan Williams if (instances[i]) 25846bc75619SDan Williams platform_device_unregister(&instances[i]->pdev); 25856bc75619SDan Williams nfit_test_teardown(); 25868b06b884SDan Williams for (i = 0; i < NUM_NFITS; i++) 25878b06b884SDan Williams if (instances[i]) 25888b06b884SDan Williams put_device(&instances[i]->pdev.dev); 25898b06b884SDan Williams 25906bc75619SDan Williams return rc; 25916bc75619SDan Williams } 25926bc75619SDan Williams 25936bc75619SDan Williams static __exit void nfit_test_exit(void) 25946bc75619SDan Williams { 25956bc75619SDan Williams int i; 25966bc75619SDan Williams 25979fb1a190SDave Jiang flush_workqueue(nfit_wq); 25989fb1a190SDave Jiang destroy_workqueue(nfit_wq); 25996bc75619SDan Williams for (i = 0; i < NUM_NFITS; i++) 26006bc75619SDan Williams platform_device_unregister(&instances[i]->pdev); 26018b06b884SDan Williams platform_driver_unregister(&nfit_test_driver); 26026bc75619SDan Williams nfit_test_teardown(); 26038b06b884SDan Williams 26048b06b884SDan Williams for (i = 0; i < NUM_NFITS; i++) 26058b06b884SDan Williams put_device(&instances[i]->pdev.dev); 2606231bf117SDan Williams class_destroy(nfit_test_dimm); 26076bc75619SDan Williams } 26086bc75619SDan Williams 26096bc75619SDan Williams module_init(nfit_test_init); 26106bc75619SDan Williams module_exit(nfit_test_exit); 26116bc75619SDan Williams MODULE_LICENSE("GPL v2"); 26126bc75619SDan Williams MODULE_AUTHOR("Intel Corporation"); 2613