^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright(c) 2013-2015 Intel Corporation. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/libnvdimm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/sched/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/vmalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/fcntl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/async.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/genhd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/ndctl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/cpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/nd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include "nd-core.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include "nd.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include "pfn.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) int nvdimm_major;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) static int nvdimm_bus_major;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct class *nd_class;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) static DEFINE_IDA(nd_ida);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) static int to_nd_device_type(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) if (is_nvdimm(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) return ND_DEVICE_DIMM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) else if (is_memory(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) return ND_DEVICE_REGION_PMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) else if (is_nd_blk(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) return ND_DEVICE_REGION_BLK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) else if (is_nd_dax(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) return ND_DEVICE_DAX_PMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) else if (is_nd_region(dev->parent))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) return nd_region_to_nstype(to_nd_region(dev->parent));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) static int nvdimm_bus_uevent(struct device *dev, struct kobj_uevent_env *env)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) return add_uevent_var(env, "MODALIAS=" ND_DEVICE_MODALIAS_FMT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) to_nd_device_type(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) static struct module *to_bus_provider(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) /* pin bus providers while regions are enabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) if (is_nd_region(dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) return nvdimm_bus->nd_desc->module;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) static void nvdimm_bus_probe_start(struct nvdimm_bus *nvdimm_bus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) nvdimm_bus_lock(&nvdimm_bus->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) nvdimm_bus->probe_active++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) nvdimm_bus_unlock(&nvdimm_bus->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) static void nvdimm_bus_probe_end(struct nvdimm_bus *nvdimm_bus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) nvdimm_bus_lock(&nvdimm_bus->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) if (--nvdimm_bus->probe_active == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) wake_up(&nvdimm_bus->wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) nvdimm_bus_unlock(&nvdimm_bus->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) static int nvdimm_bus_probe(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) struct nd_device_driver *nd_drv = to_nd_device_driver(dev->driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) struct module *provider = to_bus_provider(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) if (!try_module_get(provider))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) dev_dbg(&nvdimm_bus->dev, "START: %s.probe(%s)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) dev->driver->name, dev_name(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) nvdimm_bus_probe_start(nvdimm_bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) debug_nvdimm_lock(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) rc = nd_drv->probe(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) debug_nvdimm_unlock(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) if ((rc == 0 || rc == -EOPNOTSUPP) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) dev->parent && is_nd_region(dev->parent))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) nd_region_advance_seeds(to_nd_region(dev->parent), dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) nvdimm_bus_probe_end(nvdimm_bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) dev_dbg(&nvdimm_bus->dev, "END: %s.probe(%s) = %d\n", dev->driver->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) dev_name(dev), rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) if (rc != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) module_put(provider);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static int nvdimm_bus_remove(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) struct nd_device_driver *nd_drv = to_nd_device_driver(dev->driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) struct module *provider = to_bus_provider(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) if (nd_drv->remove) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) debug_nvdimm_lock(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) rc = nd_drv->remove(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) debug_nvdimm_unlock(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) dev_dbg(&nvdimm_bus->dev, "%s.remove(%s) = %d\n", dev->driver->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) dev_name(dev), rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) module_put(provider);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) static void nvdimm_bus_shutdown(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) struct nd_device_driver *nd_drv = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) if (dev->driver)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) nd_drv = to_nd_device_driver(dev->driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) if (nd_drv && nd_drv->shutdown) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) nd_drv->shutdown(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) dev_dbg(&nvdimm_bus->dev, "%s.shutdown(%s)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) dev->driver->name, dev_name(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) void nd_device_notify(struct device *dev, enum nvdimm_event event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) nd_device_lock(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) if (dev->driver) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) struct nd_device_driver *nd_drv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) nd_drv = to_nd_device_driver(dev->driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) if (nd_drv->notify)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) nd_drv->notify(dev, event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) nd_device_unlock(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) EXPORT_SYMBOL(nd_device_notify);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) void nvdimm_region_notify(struct nd_region *nd_region, enum nvdimm_event event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(&nd_region->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) if (!nvdimm_bus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) /* caller is responsible for holding a reference on the device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) nd_device_notify(&nd_region->dev, event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) EXPORT_SYMBOL_GPL(nvdimm_region_notify);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) struct clear_badblocks_context {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) resource_size_t phys, cleared;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) static int nvdimm_clear_badblocks_region(struct device *dev, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) struct clear_badblocks_context *ctx = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) struct nd_region *nd_region;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) resource_size_t ndr_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) sector_t sector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) /* make sure device is a region */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) if (!is_memory(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) nd_region = to_nd_region(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) ndr_end = nd_region->ndr_start + nd_region->ndr_size - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) /* make sure we are in the region */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) if (ctx->phys < nd_region->ndr_start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) || (ctx->phys + ctx->cleared) > ndr_end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) sector = (ctx->phys - nd_region->ndr_start) / 512;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) badblocks_clear(&nd_region->bb, sector, ctx->cleared / 512);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) if (nd_region->bb_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) sysfs_notify_dirent(nd_region->bb_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) static void nvdimm_clear_badblocks_regions(struct nvdimm_bus *nvdimm_bus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) phys_addr_t phys, u64 cleared)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) struct clear_badblocks_context ctx = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) .phys = phys,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) .cleared = cleared,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) device_for_each_child(&nvdimm_bus->dev, &ctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) nvdimm_clear_badblocks_region);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) static void nvdimm_account_cleared_poison(struct nvdimm_bus *nvdimm_bus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) phys_addr_t phys, u64 cleared)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) if (cleared > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) badrange_forget(&nvdimm_bus->badrange, phys, cleared);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) if (cleared > 0 && cleared / 512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) nvdimm_clear_badblocks_regions(nvdimm_bus, phys, cleared);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) long nvdimm_clear_poison(struct device *dev, phys_addr_t phys,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) unsigned int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) struct nvdimm_bus_descriptor *nd_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) struct nd_cmd_clear_error clear_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) struct nd_cmd_ars_cap ars_cap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) u32 clear_err_unit, mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) unsigned int noio_flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) int cmd_rc, rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) if (!nvdimm_bus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) nd_desc = nvdimm_bus->nd_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) * if ndctl does not exist, it's PMEM_LEGACY and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) * we want to just pretend everything is handled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) if (!nd_desc->ndctl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) memset(&ars_cap, 0, sizeof(ars_cap));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) ars_cap.address = phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) ars_cap.length = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) noio_flag = memalloc_noio_save();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) rc = nd_desc->ndctl(nd_desc, NULL, ND_CMD_ARS_CAP, &ars_cap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) sizeof(ars_cap), &cmd_rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) memalloc_noio_restore(noio_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) if (cmd_rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) return cmd_rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) clear_err_unit = ars_cap.clear_err_unit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) if (!clear_err_unit || !is_power_of_2(clear_err_unit))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) mask = clear_err_unit - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) if ((phys | len) & mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) memset(&clear_err, 0, sizeof(clear_err));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) clear_err.address = phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) clear_err.length = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) noio_flag = memalloc_noio_save();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) rc = nd_desc->ndctl(nd_desc, NULL, ND_CMD_CLEAR_ERROR, &clear_err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) sizeof(clear_err), &cmd_rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) memalloc_noio_restore(noio_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) if (cmd_rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) return cmd_rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) nvdimm_account_cleared_poison(nvdimm_bus, phys, clear_err.cleared);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) return clear_err.cleared;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) EXPORT_SYMBOL_GPL(nvdimm_clear_poison);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) static int nvdimm_bus_match(struct device *dev, struct device_driver *drv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) static struct bus_type nvdimm_bus_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) .name = "nd",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) .uevent = nvdimm_bus_uevent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) .match = nvdimm_bus_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) .probe = nvdimm_bus_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) .remove = nvdimm_bus_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) .shutdown = nvdimm_bus_shutdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) static void nvdimm_bus_release(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) struct nvdimm_bus *nvdimm_bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) nvdimm_bus = container_of(dev, struct nvdimm_bus, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) ida_simple_remove(&nd_ida, nvdimm_bus->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) kfree(nvdimm_bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) static const struct device_type nvdimm_bus_dev_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) .release = nvdimm_bus_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) .groups = nvdimm_bus_attribute_groups,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) bool is_nvdimm_bus(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) return dev->type == &nvdimm_bus_dev_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) struct nvdimm_bus *walk_to_nvdimm_bus(struct device *nd_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) for (dev = nd_dev; dev; dev = dev->parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) if (is_nvdimm_bus(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) dev_WARN_ONCE(nd_dev, !dev, "invalid dev, not on nd bus\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) if (dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) return to_nvdimm_bus(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) struct nvdimm_bus *to_nvdimm_bus(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) struct nvdimm_bus *nvdimm_bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) nvdimm_bus = container_of(dev, struct nvdimm_bus, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) WARN_ON(!is_nvdimm_bus(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) return nvdimm_bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) EXPORT_SYMBOL_GPL(to_nvdimm_bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) struct nvdimm_bus *nvdimm_to_bus(struct nvdimm *nvdimm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) return to_nvdimm_bus(nvdimm->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) EXPORT_SYMBOL_GPL(nvdimm_to_bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) struct nvdimm_bus *nvdimm_bus_register(struct device *parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) struct nvdimm_bus_descriptor *nd_desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) struct nvdimm_bus *nvdimm_bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) nvdimm_bus = kzalloc(sizeof(*nvdimm_bus), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) if (!nvdimm_bus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) INIT_LIST_HEAD(&nvdimm_bus->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) INIT_LIST_HEAD(&nvdimm_bus->mapping_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) init_waitqueue_head(&nvdimm_bus->wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) nvdimm_bus->id = ida_simple_get(&nd_ida, 0, 0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) if (nvdimm_bus->id < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) kfree(nvdimm_bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) mutex_init(&nvdimm_bus->reconfig_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) badrange_init(&nvdimm_bus->badrange);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) nvdimm_bus->nd_desc = nd_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) nvdimm_bus->dev.parent = parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) nvdimm_bus->dev.type = &nvdimm_bus_dev_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) nvdimm_bus->dev.groups = nd_desc->attr_groups;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) nvdimm_bus->dev.bus = &nvdimm_bus_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) nvdimm_bus->dev.of_node = nd_desc->of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) dev_set_name(&nvdimm_bus->dev, "ndbus%d", nvdimm_bus->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) rc = device_register(&nvdimm_bus->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) dev_dbg(&nvdimm_bus->dev, "registration failed: %d\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) return nvdimm_bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) put_device(&nvdimm_bus->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) EXPORT_SYMBOL_GPL(nvdimm_bus_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) void nvdimm_bus_unregister(struct nvdimm_bus *nvdimm_bus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) if (!nvdimm_bus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) device_unregister(&nvdimm_bus->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) EXPORT_SYMBOL_GPL(nvdimm_bus_unregister);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) static int child_unregister(struct device *dev, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) * the singular ndctl class device per bus needs to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) * "device_destroy"ed, so skip it here
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) * i.e. remove classless children
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) if (dev->class)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) if (is_nvdimm(dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) struct nvdimm *nvdimm = to_nvdimm(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) bool dev_put = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) /* We are shutting down. Make state frozen artificially. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) nvdimm_bus_lock(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) set_bit(NVDIMM_SECURITY_FROZEN, &nvdimm->sec.flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) if (test_and_clear_bit(NDD_WORK_PENDING, &nvdimm->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) dev_put = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) nvdimm_bus_unlock(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) cancel_delayed_work_sync(&nvdimm->dwork);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) if (dev_put)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) put_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) nd_device_unregister(dev, ND_SYNC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) static void free_badrange_list(struct list_head *badrange_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) struct badrange_entry *bre, *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) list_for_each_entry_safe(bre, next, badrange_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) list_del(&bre->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) kfree(bre);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) list_del_init(badrange_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) static int nd_bus_remove(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) struct nvdimm_bus *nvdimm_bus = to_nvdimm_bus(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) mutex_lock(&nvdimm_bus_list_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) list_del_init(&nvdimm_bus->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) mutex_unlock(&nvdimm_bus_list_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) wait_event(nvdimm_bus->wait,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) atomic_read(&nvdimm_bus->ioctl_active) == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) nd_synchronize();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) device_for_each_child(&nvdimm_bus->dev, NULL, child_unregister);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) spin_lock(&nvdimm_bus->badrange.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) free_badrange_list(&nvdimm_bus->badrange.list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) spin_unlock(&nvdimm_bus->badrange.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) nvdimm_bus_destroy_ndctl(nvdimm_bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) static int nd_bus_probe(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) struct nvdimm_bus *nvdimm_bus = to_nvdimm_bus(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) rc = nvdimm_bus_create_ndctl(nvdimm_bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) mutex_lock(&nvdimm_bus_list_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) list_add_tail(&nvdimm_bus->list, &nvdimm_bus_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) mutex_unlock(&nvdimm_bus_list_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) /* enable bus provider attributes to look up their local context */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) dev_set_drvdata(dev, nvdimm_bus->nd_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) static struct nd_device_driver nd_bus_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) .probe = nd_bus_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) .remove = nd_bus_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) .drv = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) .name = "nd_bus",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) .suppress_bind_attrs = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) .bus = &nvdimm_bus_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) .mod_name = KBUILD_MODNAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) static int nvdimm_bus_match(struct device *dev, struct device_driver *drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) struct nd_device_driver *nd_drv = to_nd_device_driver(drv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) if (is_nvdimm_bus(dev) && nd_drv == &nd_bus_driver)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) return !!test_bit(to_nd_device_type(dev), &nd_drv->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) static ASYNC_DOMAIN_EXCLUSIVE(nd_async_domain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) void nd_synchronize(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) async_synchronize_full_domain(&nd_async_domain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) EXPORT_SYMBOL_GPL(nd_synchronize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) static void nd_async_device_register(void *d, async_cookie_t cookie)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) struct device *dev = d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) if (device_add(dev) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) dev_err(dev, "%s: failed\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) put_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) put_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) if (dev->parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) put_device(dev->parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) static void nd_async_device_unregister(void *d, async_cookie_t cookie)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) struct device *dev = d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) /* flush bus operations before delete */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) nvdimm_bus_lock(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) nvdimm_bus_unlock(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) device_unregister(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) put_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) void __nd_device_register(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) * Ensure that region devices always have their NUMA node set as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) * early as possible. This way we are able to make certain that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) * any memory associated with the creation and the creation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) * itself of the region is associated with the correct node.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) if (is_nd_region(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) set_dev_node(dev, to_nd_region(dev)->numa_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) dev->bus = &nvdimm_bus_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) if (dev->parent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) get_device(dev->parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) if (dev_to_node(dev) == NUMA_NO_NODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) set_dev_node(dev, dev_to_node(dev->parent));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) get_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) async_schedule_dev_domain(nd_async_device_register, dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) &nd_async_domain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) void nd_device_register(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) device_initialize(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) __nd_device_register(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) EXPORT_SYMBOL(nd_device_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) void nd_device_unregister(struct device *dev, enum nd_async_mode mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) bool killed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) switch (mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) case ND_ASYNC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) * In the async case this is being triggered with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) * device lock held and the unregistration work needs to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) * be moved out of line iff this is thread has won the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) * race to schedule the deletion.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) if (!kill_device(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) get_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) async_schedule_domain(nd_async_device_unregister, dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) &nd_async_domain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) case ND_SYNC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) * In the sync case the device is being unregistered due
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) * to a state change of the parent. Claim the kill state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) * to synchronize against other unregistration requests,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) * or otherwise let the async path handle it if the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) * unregistration was already queued.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) nd_device_lock(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) killed = kill_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) nd_device_unlock(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) if (!killed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) nd_synchronize();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) device_unregister(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) EXPORT_SYMBOL(nd_device_unregister);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) * __nd_driver_register() - register a region or a namespace driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) * @nd_drv: driver to register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) * @owner: automatically set by nd_driver_register() macro
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) * @mod_name: automatically set by nd_driver_register() macro
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) int __nd_driver_register(struct nd_device_driver *nd_drv, struct module *owner,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) const char *mod_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) struct device_driver *drv = &nd_drv->drv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) if (!nd_drv->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) pr_debug("driver type bitmask not set (%ps)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) __builtin_return_address(0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) if (!nd_drv->probe) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) pr_debug("%s ->probe() must be specified\n", mod_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) drv->bus = &nvdimm_bus_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) drv->owner = owner;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) drv->mod_name = mod_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) return driver_register(drv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) EXPORT_SYMBOL(__nd_driver_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) void nvdimm_check_and_set_ro(struct gendisk *disk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) struct device *dev = disk_to_dev(disk)->parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) struct nd_region *nd_region = to_nd_region(dev->parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) int disk_ro = get_disk_ro(disk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) * Upgrade to read-only if the region is read-only preserve as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) * read-only if the disk is already read-only.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) if (disk_ro || nd_region->ro == disk_ro)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) dev_info(dev, "%s read-only, marking %s read-only\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) dev_name(&nd_region->dev), disk->disk_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) set_disk_ro(disk, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) EXPORT_SYMBOL(nvdimm_check_and_set_ro);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) return sprintf(buf, ND_DEVICE_MODALIAS_FMT "\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) to_nd_device_type(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) static DEVICE_ATTR_RO(modalias);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) static ssize_t devtype_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) return sprintf(buf, "%s\n", dev->type->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) static DEVICE_ATTR_RO(devtype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) static struct attribute *nd_device_attributes[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) &dev_attr_modalias.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) &dev_attr_devtype.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) * nd_device_attribute_group - generic attributes for all devices on an nd bus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) const struct attribute_group nd_device_attribute_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) .attrs = nd_device_attributes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) static ssize_t numa_node_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) return sprintf(buf, "%d\n", dev_to_node(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) static DEVICE_ATTR_RO(numa_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) static int nvdimm_dev_to_target_node(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) struct device *parent = dev->parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) struct nd_region *nd_region = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) if (is_nd_region(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) nd_region = to_nd_region(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) else if (parent && is_nd_region(parent))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) nd_region = to_nd_region(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) if (!nd_region)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) return NUMA_NO_NODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) return nd_region->target_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) static ssize_t target_node_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) return sprintf(buf, "%d\n", nvdimm_dev_to_target_node(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) static DEVICE_ATTR_RO(target_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) static struct attribute *nd_numa_attributes[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) &dev_attr_numa_node.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) &dev_attr_target_node.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) static umode_t nd_numa_attr_visible(struct kobject *kobj, struct attribute *a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) int n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) struct device *dev = container_of(kobj, typeof(*dev), kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) if (!IS_ENABLED(CONFIG_NUMA))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) if (a == &dev_attr_target_node.attr &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) nvdimm_dev_to_target_node(dev) == NUMA_NO_NODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) return a->mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) * nd_numa_attribute_group - NUMA attributes for all devices on an nd bus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) const struct attribute_group nd_numa_attribute_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) .attrs = nd_numa_attributes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) .is_visible = nd_numa_attr_visible,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) int nvdimm_bus_create_ndctl(struct nvdimm_bus *nvdimm_bus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) dev_t devt = MKDEV(nvdimm_bus_major, nvdimm_bus->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) dev = device_create(nd_class, &nvdimm_bus->dev, devt, nvdimm_bus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) "ndctl%d", nvdimm_bus->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) if (IS_ERR(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) dev_dbg(&nvdimm_bus->dev, "failed to register ndctl%d: %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) nvdimm_bus->id, PTR_ERR(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) return PTR_ERR_OR_ZERO(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) void nvdimm_bus_destroy_ndctl(struct nvdimm_bus *nvdimm_bus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) device_destroy(nd_class, MKDEV(nvdimm_bus_major, nvdimm_bus->id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) static const struct nd_cmd_desc __nd_cmd_dimm_descs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) [ND_CMD_IMPLEMENTED] = { },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) [ND_CMD_SMART] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) .out_num = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) .out_sizes = { 4, 128, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) [ND_CMD_SMART_THRESHOLD] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) .out_num = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) .out_sizes = { 4, 8, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) [ND_CMD_DIMM_FLAGS] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) .out_num = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) .out_sizes = { 4, 4 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) [ND_CMD_GET_CONFIG_SIZE] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) .out_num = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) .out_sizes = { 4, 4, 4, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) [ND_CMD_GET_CONFIG_DATA] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) .in_num = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) .in_sizes = { 4, 4, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) .out_num = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) .out_sizes = { 4, UINT_MAX, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) [ND_CMD_SET_CONFIG_DATA] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) .in_num = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) .in_sizes = { 4, 4, UINT_MAX, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) .out_num = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) .out_sizes = { 4, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) [ND_CMD_VENDOR] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) .in_num = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) .in_sizes = { 4, 4, UINT_MAX, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) .out_num = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) .out_sizes = { 4, 4, UINT_MAX, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) [ND_CMD_CALL] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) .in_num = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) .in_sizes = { sizeof(struct nd_cmd_pkg), UINT_MAX, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) .out_num = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) .out_sizes = { UINT_MAX, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) const struct nd_cmd_desc *nd_cmd_dimm_desc(int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) if (cmd < ARRAY_SIZE(__nd_cmd_dimm_descs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) return &__nd_cmd_dimm_descs[cmd];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) EXPORT_SYMBOL_GPL(nd_cmd_dimm_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) static const struct nd_cmd_desc __nd_cmd_bus_descs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) [ND_CMD_IMPLEMENTED] = { },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) [ND_CMD_ARS_CAP] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) .in_num = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) .in_sizes = { 8, 8, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) .out_num = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) .out_sizes = { 4, 4, 4, 4, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) [ND_CMD_ARS_START] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) .in_num = 5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) .in_sizes = { 8, 8, 2, 1, 5, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) .out_num = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) .out_sizes = { 4, 4, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) [ND_CMD_ARS_STATUS] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) .out_num = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) .out_sizes = { 4, 4, UINT_MAX, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) [ND_CMD_CLEAR_ERROR] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) .in_num = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) .in_sizes = { 8, 8, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) .out_num = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) .out_sizes = { 4, 4, 8, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) [ND_CMD_CALL] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) .in_num = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) .in_sizes = { sizeof(struct nd_cmd_pkg), UINT_MAX, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) .out_num = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) .out_sizes = { UINT_MAX, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) const struct nd_cmd_desc *nd_cmd_bus_desc(int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) if (cmd < ARRAY_SIZE(__nd_cmd_bus_descs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) return &__nd_cmd_bus_descs[cmd];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) EXPORT_SYMBOL_GPL(nd_cmd_bus_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) u32 nd_cmd_in_size(struct nvdimm *nvdimm, int cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) const struct nd_cmd_desc *desc, int idx, void *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) if (idx >= desc->in_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) return UINT_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) if (desc->in_sizes[idx] < UINT_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) return desc->in_sizes[idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) if (nvdimm && cmd == ND_CMD_SET_CONFIG_DATA && idx == 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) struct nd_cmd_set_config_hdr *hdr = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) return hdr->in_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) } else if (nvdimm && cmd == ND_CMD_VENDOR && idx == 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) struct nd_cmd_vendor_hdr *hdr = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) return hdr->in_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) } else if (cmd == ND_CMD_CALL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) struct nd_cmd_pkg *pkg = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) return pkg->nd_size_in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) return UINT_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) EXPORT_SYMBOL_GPL(nd_cmd_in_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) u32 nd_cmd_out_size(struct nvdimm *nvdimm, int cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) const struct nd_cmd_desc *desc, int idx, const u32 *in_field,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) const u32 *out_field, unsigned long remainder)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) if (idx >= desc->out_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) return UINT_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) if (desc->out_sizes[idx] < UINT_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) return desc->out_sizes[idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) if (nvdimm && cmd == ND_CMD_GET_CONFIG_DATA && idx == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) return in_field[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) else if (nvdimm && cmd == ND_CMD_VENDOR && idx == 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) return out_field[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) else if (!nvdimm && cmd == ND_CMD_ARS_STATUS && idx == 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) * Per table 9-276 ARS Data in ACPI 6.1, out_field[1] is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) * "Size of Output Buffer in bytes, including this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) * field."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) if (out_field[1] < 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) * ACPI 6.1 is ambiguous if 'status' is included in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) * output size. If we encounter an output size that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) * overshoots the remainder by 4 bytes, assume it was
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) * including 'status'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) if (out_field[1] - 4 == remainder)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) return remainder;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) return out_field[1] - 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) } else if (cmd == ND_CMD_CALL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) struct nd_cmd_pkg *pkg = (struct nd_cmd_pkg *) in_field;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) return pkg->nd_size_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) return UINT_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) EXPORT_SYMBOL_GPL(nd_cmd_out_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) void wait_nvdimm_bus_probe_idle(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) if (nvdimm_bus->probe_active == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) nvdimm_bus_unlock(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) nd_device_unlock(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) wait_event(nvdimm_bus->wait,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) nvdimm_bus->probe_active == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) nd_device_lock(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) nvdimm_bus_lock(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) } while (true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) static int nd_pmem_forget_poison_check(struct device *dev, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) struct nd_cmd_clear_error *clear_err =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) (struct nd_cmd_clear_error *)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) struct nd_btt *nd_btt = is_nd_btt(dev) ? to_nd_btt(dev) : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) struct nd_pfn *nd_pfn = is_nd_pfn(dev) ? to_nd_pfn(dev) : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) struct nd_dax *nd_dax = is_nd_dax(dev) ? to_nd_dax(dev) : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) struct nd_namespace_common *ndns = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) struct nd_namespace_io *nsio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) resource_size_t offset = 0, end_trunc = 0, start, end, pstart, pend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) if (nd_dax || !dev->driver)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) start = clear_err->address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) end = clear_err->address + clear_err->cleared - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) if (nd_btt || nd_pfn || nd_dax) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) if (nd_btt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) ndns = nd_btt->ndns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) else if (nd_pfn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) ndns = nd_pfn->ndns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) else if (nd_dax)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) ndns = nd_dax->nd_pfn.ndns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) if (!ndns)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) ndns = to_ndns(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) nsio = to_nd_namespace_io(&ndns->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) pstart = nsio->res.start + offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) pend = nsio->res.end - end_trunc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) if ((pstart >= start) && (pend <= end))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) static int nd_ns_forget_poison_check(struct device *dev, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) return device_for_each_child(dev, data, nd_pmem_forget_poison_check);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) /* set_config requires an idle interleave set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) static int nd_cmd_clear_to_send(struct nvdimm_bus *nvdimm_bus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) struct nvdimm *nvdimm, unsigned int cmd, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) struct nvdimm_bus_descriptor *nd_desc = nvdimm_bus->nd_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) /* ask the bus provider if it would like to block this request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) if (nd_desc->clear_to_send) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) int rc = nd_desc->clear_to_send(nd_desc, nvdimm, cmd, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) /* require clear error to go through the pmem driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) if (!nvdimm && cmd == ND_CMD_CLEAR_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) return device_for_each_child(&nvdimm_bus->dev, data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) nd_ns_forget_poison_check);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) if (!nvdimm || cmd != ND_CMD_SET_CONFIG_DATA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) /* prevent label manipulation while the kernel owns label updates */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) wait_nvdimm_bus_probe_idle(&nvdimm_bus->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) if (atomic_read(&nvdimm->busy))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) static int __nd_ioctl(struct nvdimm_bus *nvdimm_bus, struct nvdimm *nvdimm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) int read_only, unsigned int ioctl_cmd, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) struct nvdimm_bus_descriptor *nd_desc = nvdimm_bus->nd_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) const struct nd_cmd_desc *desc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) unsigned int cmd = _IOC_NR(ioctl_cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) struct device *dev = &nvdimm_bus->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) void __user *p = (void __user *) arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) char *out_env = NULL, *in_env = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) const char *cmd_name, *dimm_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) u32 in_len = 0, out_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) unsigned int func = cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) unsigned long cmd_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) struct nd_cmd_pkg pkg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) int rc, i, cmd_rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) void *buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) u64 buf_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) if (nvdimm) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) desc = nd_cmd_dimm_desc(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) cmd_name = nvdimm_cmd_name(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) cmd_mask = nvdimm->cmd_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) dimm_name = dev_name(&nvdimm->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) desc = nd_cmd_bus_desc(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) cmd_name = nvdimm_bus_cmd_name(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) cmd_mask = nd_desc->cmd_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) dimm_name = "bus";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) /* Validate command family support against bus declared support */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) if (cmd == ND_CMD_CALL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) unsigned long *mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) if (copy_from_user(&pkg, p, sizeof(pkg)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) if (nvdimm) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) if (pkg.nd_family > NVDIMM_FAMILY_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) mask = &nd_desc->dimm_family_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) if (pkg.nd_family > NVDIMM_BUS_FAMILY_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) mask = &nd_desc->bus_family_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) if (!test_bit(pkg.nd_family, mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) if (!desc ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) (desc->out_num + desc->in_num == 0) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) cmd > ND_CMD_CALL ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) !test_bit(cmd, &cmd_mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) return -ENOTTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) /* fail write commands (when read-only) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) if (read_only)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) case ND_CMD_VENDOR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) case ND_CMD_SET_CONFIG_DATA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) case ND_CMD_ARS_START:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) case ND_CMD_CLEAR_ERROR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) case ND_CMD_CALL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) dev_dbg(dev, "'%s' command while read-only.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) nvdimm ? nvdimm_cmd_name(cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) : nvdimm_bus_cmd_name(cmd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) /* process an input envelope */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) in_env = kzalloc(ND_CMD_MAX_ENVELOPE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) if (!in_env)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) for (i = 0; i < desc->in_num; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) u32 in_size, copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) in_size = nd_cmd_in_size(nvdimm, cmd, desc, i, in_env);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) if (in_size == UINT_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) dev_err(dev, "%s:%s unknown input size cmd: %s field: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) __func__, dimm_name, cmd_name, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) rc = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) if (in_len < ND_CMD_MAX_ENVELOPE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) copy = min_t(u32, ND_CMD_MAX_ENVELOPE - in_len, in_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) copy = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) if (copy && copy_from_user(&in_env[in_len], p + in_len, copy)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) rc = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) in_len += in_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) if (cmd == ND_CMD_CALL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) func = pkg.nd_command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) dev_dbg(dev, "%s, idx: %llu, in: %u, out: %u, len %llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) dimm_name, pkg.nd_command,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) in_len, out_len, buf_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) /* process an output envelope */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) out_env = kzalloc(ND_CMD_MAX_ENVELOPE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) if (!out_env) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) for (i = 0; i < desc->out_num; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) u32 out_size = nd_cmd_out_size(nvdimm, cmd, desc, i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) (u32 *) in_env, (u32 *) out_env, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) u32 copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) if (out_size == UINT_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) dev_dbg(dev, "%s unknown output size cmd: %s field: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) dimm_name, cmd_name, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) rc = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) if (out_len < ND_CMD_MAX_ENVELOPE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) copy = min_t(u32, ND_CMD_MAX_ENVELOPE - out_len, out_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) copy = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) if (copy && copy_from_user(&out_env[out_len],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) p + in_len + out_len, copy)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) rc = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) out_len += out_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) buf_len = (u64) out_len + (u64) in_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) if (buf_len > ND_IOCTL_MAX_BUFLEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) dev_dbg(dev, "%s cmd: %s buf_len: %llu > %d\n", dimm_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) cmd_name, buf_len, ND_IOCTL_MAX_BUFLEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) buf = vmalloc(buf_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) if (!buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) if (copy_from_user(buf, p, buf_len)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) rc = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) nd_device_lock(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) nvdimm_bus_lock(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) rc = nd_cmd_clear_to_send(nvdimm_bus, nvdimm, func, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) rc = nd_desc->ndctl(nd_desc, nvdimm, cmd, buf, buf_len, &cmd_rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) if (!nvdimm && cmd == ND_CMD_CLEAR_ERROR && cmd_rc >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) struct nd_cmd_clear_error *clear_err = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) nvdimm_account_cleared_poison(nvdimm_bus, clear_err->address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) clear_err->cleared);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) if (copy_to_user(p, buf, buf_len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) rc = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) nvdimm_bus_unlock(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) nd_device_unlock(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) kfree(in_env);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) kfree(out_env);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) vfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) enum nd_ioctl_mode {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) BUS_IOCTL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) DIMM_IOCTL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) static int match_dimm(struct device *dev, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) long id = (long) data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) if (is_nvdimm(dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) struct nvdimm *nvdimm = to_nvdimm(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) return nvdimm->id == id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) static long nd_ioctl(struct file *file, unsigned int cmd, unsigned long arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) enum nd_ioctl_mode mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) struct nvdimm_bus *nvdimm_bus, *found = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) long id = (long) file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) struct nvdimm *nvdimm = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) int rc, ro;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) ro = ((file->f_flags & O_ACCMODE) == O_RDONLY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) mutex_lock(&nvdimm_bus_list_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) list_for_each_entry(nvdimm_bus, &nvdimm_bus_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) if (mode == DIMM_IOCTL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) dev = device_find_child(&nvdimm_bus->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) file->private_data, match_dimm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) nvdimm = to_nvdimm(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) found = nvdimm_bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) } else if (nvdimm_bus->id == id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) found = nvdimm_bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) if (found) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) atomic_inc(&nvdimm_bus->ioctl_active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) mutex_unlock(&nvdimm_bus_list_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) if (!found)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) nvdimm_bus = found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) rc = __nd_ioctl(nvdimm_bus, nvdimm, ro, cmd, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) if (nvdimm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) put_device(&nvdimm->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) if (atomic_dec_and_test(&nvdimm_bus->ioctl_active))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) wake_up(&nvdimm_bus->wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) static long bus_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) return nd_ioctl(file, cmd, arg, BUS_IOCTL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) static long dimm_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) return nd_ioctl(file, cmd, arg, DIMM_IOCTL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) static int nd_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) long minor = iminor(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) file->private_data = (void *) minor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) static const struct file_operations nvdimm_bus_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) .open = nd_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) .unlocked_ioctl = bus_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) .compat_ioctl = compat_ptr_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) .llseek = noop_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) static const struct file_operations nvdimm_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) .open = nd_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) .unlocked_ioctl = dimm_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) .compat_ioctl = compat_ptr_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) .llseek = noop_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) int __init nvdimm_bus_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) rc = bus_register(&nvdimm_bus_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) rc = register_chrdev(0, "ndctl", &nvdimm_bus_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) goto err_bus_chrdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) nvdimm_bus_major = rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) rc = register_chrdev(0, "dimmctl", &nvdimm_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) goto err_dimm_chrdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) nvdimm_major = rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) nd_class = class_create(THIS_MODULE, "nd");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) if (IS_ERR(nd_class)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) rc = PTR_ERR(nd_class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) goto err_class;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) rc = driver_register(&nd_bus_driver.drv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) goto err_nd_bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) err_nd_bus:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) class_destroy(nd_class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) err_class:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) unregister_chrdev(nvdimm_major, "dimmctl");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) err_dimm_chrdev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) unregister_chrdev(nvdimm_bus_major, "ndctl");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) err_bus_chrdev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) bus_unregister(&nvdimm_bus_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) void nvdimm_bus_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) driver_unregister(&nd_bus_driver.drv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) class_destroy(nd_class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) unregister_chrdev(nvdimm_bus_major, "ndctl");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) unregister_chrdev(nvdimm_major, "dimmctl");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) bus_unregister(&nvdimm_bus_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) ida_destroy(&nd_ida);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) }