Dan Williams | 45def22 | 2015-04-26 19:26:48 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright(c) 2013-2015 Intel Corporation. All rights reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of version 2 of the GNU General Public License as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, but |
| 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 | * General Public License for more details. |
| 12 | */ |
| 13 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 14 | #include <linux/vmalloc.h> |
Dan Williams | 45def22 | 2015-04-26 19:26:48 -0400 | [diff] [blame] | 15 | #include <linux/uaccess.h> |
Dan Williams | 3d88002 | 2015-05-31 15:02:11 -0400 | [diff] [blame] | 16 | #include <linux/module.h> |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 17 | #include <linux/blkdev.h> |
Dan Williams | 45def22 | 2015-04-26 19:26:48 -0400 | [diff] [blame] | 18 | #include <linux/fcntl.h> |
Dan Williams | e6dfb2d | 2015-04-25 03:56:17 -0400 | [diff] [blame] | 19 | #include <linux/async.h> |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 20 | #include <linux/genhd.h> |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 21 | #include <linux/ndctl.h> |
Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 22 | #include <linux/sched.h> |
Dan Williams | 45def22 | 2015-04-26 19:26:48 -0400 | [diff] [blame] | 23 | #include <linux/slab.h> |
| 24 | #include <linux/fs.h> |
| 25 | #include <linux/io.h> |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 26 | #include <linux/mm.h> |
Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 27 | #include <linux/nd.h> |
Dan Williams | 45def22 | 2015-04-26 19:26:48 -0400 | [diff] [blame] | 28 | #include "nd-core.h" |
Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 29 | #include "nd.h" |
Dan Williams | 45def22 | 2015-04-26 19:26:48 -0400 | [diff] [blame] | 30 | |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 31 | int nvdimm_major; |
Dan Williams | 45def22 | 2015-04-26 19:26:48 -0400 | [diff] [blame] | 32 | static int nvdimm_bus_major; |
| 33 | static struct class *nd_class; |
| 34 | |
Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 35 | static int to_nd_device_type(struct device *dev) |
| 36 | { |
| 37 | if (is_nvdimm(dev)) |
| 38 | return ND_DEVICE_DIMM; |
Dan Williams | 3d88002 | 2015-05-31 15:02:11 -0400 | [diff] [blame] | 39 | else if (is_nd_pmem(dev)) |
| 40 | return ND_DEVICE_REGION_PMEM; |
| 41 | else if (is_nd_blk(dev)) |
| 42 | return ND_DEVICE_REGION_BLK; |
| 43 | else if (is_nd_pmem(dev->parent) || is_nd_blk(dev->parent)) |
| 44 | return nd_region_to_nstype(to_nd_region(dev->parent)); |
Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 45 | |
| 46 | return 0; |
| 47 | } |
| 48 | |
| 49 | static int nvdimm_bus_uevent(struct device *dev, struct kobj_uevent_env *env) |
| 50 | { |
Toshi Kani | 41d7a6d | 2015-06-19 12:18:33 -0600 | [diff] [blame] | 51 | /* |
| 52 | * Ensure that region devices always have their numa node set as |
| 53 | * early as possible. |
| 54 | */ |
| 55 | if (is_nd_pmem(dev) || is_nd_blk(dev)) |
| 56 | set_dev_node(dev, to_nd_region(dev)->numa_node); |
Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 57 | return add_uevent_var(env, "MODALIAS=" ND_DEVICE_MODALIAS_FMT, |
| 58 | to_nd_device_type(dev)); |
| 59 | } |
| 60 | |
| 61 | static int nvdimm_bus_match(struct device *dev, struct device_driver *drv) |
| 62 | { |
| 63 | struct nd_device_driver *nd_drv = to_nd_device_driver(drv); |
| 64 | |
| 65 | return test_bit(to_nd_device_type(dev), &nd_drv->type); |
| 66 | } |
| 67 | |
Dan Williams | 3d88002 | 2015-05-31 15:02:11 -0400 | [diff] [blame] | 68 | static struct module *to_bus_provider(struct device *dev) |
| 69 | { |
| 70 | /* pin bus providers while regions are enabled */ |
| 71 | if (is_nd_pmem(dev) || is_nd_blk(dev)) { |
| 72 | struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(dev); |
| 73 | |
| 74 | return nvdimm_bus->module; |
| 75 | } |
| 76 | return NULL; |
| 77 | } |
| 78 | |
Dan Williams | eaf9615 | 2015-05-01 13:11:27 -0400 | [diff] [blame] | 79 | static void nvdimm_bus_probe_start(struct nvdimm_bus *nvdimm_bus) |
| 80 | { |
| 81 | nvdimm_bus_lock(&nvdimm_bus->dev); |
| 82 | nvdimm_bus->probe_active++; |
| 83 | nvdimm_bus_unlock(&nvdimm_bus->dev); |
| 84 | } |
| 85 | |
| 86 | static void nvdimm_bus_probe_end(struct nvdimm_bus *nvdimm_bus) |
| 87 | { |
| 88 | nvdimm_bus_lock(&nvdimm_bus->dev); |
| 89 | if (--nvdimm_bus->probe_active == 0) |
| 90 | wake_up(&nvdimm_bus->probe_wait); |
| 91 | nvdimm_bus_unlock(&nvdimm_bus->dev); |
| 92 | } |
| 93 | |
Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 94 | static int nvdimm_bus_probe(struct device *dev) |
| 95 | { |
| 96 | struct nd_device_driver *nd_drv = to_nd_device_driver(dev->driver); |
Dan Williams | 3d88002 | 2015-05-31 15:02:11 -0400 | [diff] [blame] | 97 | struct module *provider = to_bus_provider(dev); |
Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 98 | struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(dev); |
| 99 | int rc; |
| 100 | |
Dan Williams | 3d88002 | 2015-05-31 15:02:11 -0400 | [diff] [blame] | 101 | if (!try_module_get(provider)) |
| 102 | return -ENXIO; |
| 103 | |
Dan Williams | eaf9615 | 2015-05-01 13:11:27 -0400 | [diff] [blame] | 104 | nvdimm_bus_probe_start(nvdimm_bus); |
Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 105 | rc = nd_drv->probe(dev); |
Dan Williams | eaf9615 | 2015-05-01 13:11:27 -0400 | [diff] [blame] | 106 | if (rc == 0) |
| 107 | nd_region_probe_success(nvdimm_bus, dev); |
Dan Williams | bf9bccc | 2015-06-17 17:14:46 -0400 | [diff] [blame] | 108 | else |
| 109 | nd_region_disable(nvdimm_bus, dev); |
Dan Williams | eaf9615 | 2015-05-01 13:11:27 -0400 | [diff] [blame] | 110 | nvdimm_bus_probe_end(nvdimm_bus); |
| 111 | |
Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 112 | dev_dbg(&nvdimm_bus->dev, "%s.probe(%s) = %d\n", dev->driver->name, |
| 113 | dev_name(dev), rc); |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 114 | |
Dan Williams | 3d88002 | 2015-05-31 15:02:11 -0400 | [diff] [blame] | 115 | if (rc != 0) |
| 116 | module_put(provider); |
Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 117 | return rc; |
| 118 | } |
| 119 | |
| 120 | static int nvdimm_bus_remove(struct device *dev) |
| 121 | { |
| 122 | struct nd_device_driver *nd_drv = to_nd_device_driver(dev->driver); |
Dan Williams | 3d88002 | 2015-05-31 15:02:11 -0400 | [diff] [blame] | 123 | struct module *provider = to_bus_provider(dev); |
Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 124 | struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(dev); |
| 125 | int rc; |
| 126 | |
| 127 | rc = nd_drv->remove(dev); |
Dan Williams | eaf9615 | 2015-05-01 13:11:27 -0400 | [diff] [blame] | 128 | nd_region_disable(nvdimm_bus, dev); |
| 129 | |
Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 130 | dev_dbg(&nvdimm_bus->dev, "%s.remove(%s) = %d\n", dev->driver->name, |
| 131 | dev_name(dev), rc); |
Dan Williams | 3d88002 | 2015-05-31 15:02:11 -0400 | [diff] [blame] | 132 | module_put(provider); |
Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 133 | return rc; |
| 134 | } |
| 135 | |
Dan Williams | 7199946 | 2016-02-18 10:29:49 -0800 | [diff] [blame] | 136 | void nd_device_notify(struct device *dev, enum nvdimm_event event) |
| 137 | { |
| 138 | device_lock(dev); |
| 139 | if (dev->driver) { |
| 140 | struct nd_device_driver *nd_drv; |
| 141 | |
| 142 | nd_drv = to_nd_device_driver(dev->driver); |
| 143 | if (nd_drv->notify) |
| 144 | nd_drv->notify(dev, event); |
| 145 | } |
| 146 | device_unlock(dev); |
| 147 | } |
| 148 | EXPORT_SYMBOL(nd_device_notify); |
| 149 | |
| 150 | void nvdimm_region_notify(struct nd_region *nd_region, enum nvdimm_event event) |
| 151 | { |
| 152 | struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(&nd_region->dev); |
| 153 | |
| 154 | if (!nvdimm_bus) |
| 155 | return; |
| 156 | |
| 157 | /* caller is responsible for holding a reference on the device */ |
| 158 | nd_device_notify(&nd_region->dev, event); |
| 159 | } |
| 160 | EXPORT_SYMBOL_GPL(nvdimm_region_notify); |
| 161 | |
Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 162 | static struct bus_type nvdimm_bus_type = { |
Dan Williams | e6dfb2d | 2015-04-25 03:56:17 -0400 | [diff] [blame] | 163 | .name = "nd", |
Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 164 | .uevent = nvdimm_bus_uevent, |
| 165 | .match = nvdimm_bus_match, |
| 166 | .probe = nvdimm_bus_probe, |
| 167 | .remove = nvdimm_bus_remove, |
Dan Williams | e6dfb2d | 2015-04-25 03:56:17 -0400 | [diff] [blame] | 168 | }; |
| 169 | |
Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 170 | static ASYNC_DOMAIN_EXCLUSIVE(nd_async_domain); |
| 171 | |
| 172 | void nd_synchronize(void) |
| 173 | { |
| 174 | async_synchronize_full_domain(&nd_async_domain); |
| 175 | } |
| 176 | EXPORT_SYMBOL_GPL(nd_synchronize); |
| 177 | |
| 178 | static void nd_async_device_register(void *d, async_cookie_t cookie) |
| 179 | { |
| 180 | struct device *dev = d; |
| 181 | |
| 182 | if (device_add(dev) != 0) { |
| 183 | dev_err(dev, "%s: failed\n", __func__); |
| 184 | put_device(dev); |
| 185 | } |
| 186 | put_device(dev); |
| 187 | } |
| 188 | |
| 189 | static void nd_async_device_unregister(void *d, async_cookie_t cookie) |
| 190 | { |
| 191 | struct device *dev = d; |
| 192 | |
Dan Williams | 0ba1c63 | 2015-05-30 12:35:36 -0400 | [diff] [blame] | 193 | /* flush bus operations before delete */ |
| 194 | nvdimm_bus_lock(dev); |
| 195 | nvdimm_bus_unlock(dev); |
| 196 | |
Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 197 | device_unregister(dev); |
| 198 | put_device(dev); |
| 199 | } |
| 200 | |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 201 | void __nd_device_register(struct device *dev) |
Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 202 | { |
| 203 | dev->bus = &nvdimm_bus_type; |
Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 204 | get_device(dev); |
| 205 | async_schedule_domain(nd_async_device_register, dev, |
| 206 | &nd_async_domain); |
| 207 | } |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 208 | |
| 209 | void nd_device_register(struct device *dev) |
| 210 | { |
| 211 | device_initialize(dev); |
| 212 | __nd_device_register(dev); |
| 213 | } |
Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 214 | EXPORT_SYMBOL(nd_device_register); |
| 215 | |
| 216 | void nd_device_unregister(struct device *dev, enum nd_async_mode mode) |
| 217 | { |
| 218 | switch (mode) { |
| 219 | case ND_ASYNC: |
| 220 | get_device(dev); |
| 221 | async_schedule_domain(nd_async_device_unregister, dev, |
| 222 | &nd_async_domain); |
| 223 | break; |
| 224 | case ND_SYNC: |
| 225 | nd_synchronize(); |
| 226 | device_unregister(dev); |
| 227 | break; |
| 228 | } |
| 229 | } |
| 230 | EXPORT_SYMBOL(nd_device_unregister); |
| 231 | |
| 232 | /** |
| 233 | * __nd_driver_register() - register a region or a namespace driver |
| 234 | * @nd_drv: driver to register |
| 235 | * @owner: automatically set by nd_driver_register() macro |
| 236 | * @mod_name: automatically set by nd_driver_register() macro |
| 237 | */ |
| 238 | int __nd_driver_register(struct nd_device_driver *nd_drv, struct module *owner, |
| 239 | const char *mod_name) |
| 240 | { |
| 241 | struct device_driver *drv = &nd_drv->drv; |
| 242 | |
| 243 | if (!nd_drv->type) { |
| 244 | pr_debug("driver type bitmask not set (%pf)\n", |
| 245 | __builtin_return_address(0)); |
| 246 | return -EINVAL; |
| 247 | } |
| 248 | |
| 249 | if (!nd_drv->probe || !nd_drv->remove) { |
| 250 | pr_debug("->probe() and ->remove() must be specified\n"); |
| 251 | return -EINVAL; |
| 252 | } |
| 253 | |
| 254 | drv->bus = &nvdimm_bus_type; |
| 255 | drv->owner = owner; |
| 256 | drv->mod_name = mod_name; |
| 257 | |
| 258 | return driver_register(drv); |
| 259 | } |
| 260 | EXPORT_SYMBOL(__nd_driver_register); |
| 261 | |
Dan Williams | 5813882 | 2015-06-23 20:08:34 -0400 | [diff] [blame] | 262 | int nvdimm_revalidate_disk(struct gendisk *disk) |
| 263 | { |
| 264 | struct device *dev = disk->driverfs_dev; |
| 265 | struct nd_region *nd_region = to_nd_region(dev->parent); |
| 266 | const char *pol = nd_region->ro ? "only" : "write"; |
| 267 | |
| 268 | if (nd_region->ro == get_disk_ro(disk)) |
| 269 | return 0; |
| 270 | |
| 271 | dev_info(dev, "%s read-%s, marking %s read-%s\n", |
| 272 | dev_name(&nd_region->dev), pol, disk->disk_name, pol); |
| 273 | set_disk_ro(disk, nd_region->ro); |
| 274 | |
| 275 | return 0; |
| 276 | |
| 277 | } |
| 278 | EXPORT_SYMBOL(nvdimm_revalidate_disk); |
| 279 | |
Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 280 | static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, |
| 281 | char *buf) |
| 282 | { |
| 283 | return sprintf(buf, ND_DEVICE_MODALIAS_FMT "\n", |
| 284 | to_nd_device_type(dev)); |
| 285 | } |
| 286 | static DEVICE_ATTR_RO(modalias); |
| 287 | |
| 288 | static ssize_t devtype_show(struct device *dev, struct device_attribute *attr, |
| 289 | char *buf) |
| 290 | { |
| 291 | return sprintf(buf, "%s\n", dev->type->name); |
| 292 | } |
| 293 | static DEVICE_ATTR_RO(devtype); |
| 294 | |
| 295 | static struct attribute *nd_device_attributes[] = { |
| 296 | &dev_attr_modalias.attr, |
| 297 | &dev_attr_devtype.attr, |
| 298 | NULL, |
| 299 | }; |
| 300 | |
| 301 | /** |
| 302 | * nd_device_attribute_group - generic attributes for all devices on an nd bus |
| 303 | */ |
| 304 | struct attribute_group nd_device_attribute_group = { |
| 305 | .attrs = nd_device_attributes, |
| 306 | }; |
| 307 | EXPORT_SYMBOL_GPL(nd_device_attribute_group); |
| 308 | |
Toshi Kani | 74ae66c | 2015-06-19 12:18:34 -0600 | [diff] [blame] | 309 | static ssize_t numa_node_show(struct device *dev, |
| 310 | struct device_attribute *attr, char *buf) |
| 311 | { |
| 312 | return sprintf(buf, "%d\n", dev_to_node(dev)); |
| 313 | } |
| 314 | static DEVICE_ATTR_RO(numa_node); |
| 315 | |
| 316 | static struct attribute *nd_numa_attributes[] = { |
| 317 | &dev_attr_numa_node.attr, |
| 318 | NULL, |
| 319 | }; |
| 320 | |
| 321 | static umode_t nd_numa_attr_visible(struct kobject *kobj, struct attribute *a, |
| 322 | int n) |
| 323 | { |
| 324 | if (!IS_ENABLED(CONFIG_NUMA)) |
| 325 | return 0; |
| 326 | |
| 327 | return a->mode; |
| 328 | } |
| 329 | |
| 330 | /** |
| 331 | * nd_numa_attribute_group - NUMA attributes for all devices on an nd bus |
| 332 | */ |
| 333 | struct attribute_group nd_numa_attribute_group = { |
| 334 | .attrs = nd_numa_attributes, |
| 335 | .is_visible = nd_numa_attr_visible, |
| 336 | }; |
| 337 | EXPORT_SYMBOL_GPL(nd_numa_attribute_group); |
| 338 | |
Dan Williams | 45def22 | 2015-04-26 19:26:48 -0400 | [diff] [blame] | 339 | int nvdimm_bus_create_ndctl(struct nvdimm_bus *nvdimm_bus) |
| 340 | { |
| 341 | dev_t devt = MKDEV(nvdimm_bus_major, nvdimm_bus->id); |
| 342 | struct device *dev; |
| 343 | |
| 344 | dev = device_create(nd_class, &nvdimm_bus->dev, devt, nvdimm_bus, |
| 345 | "ndctl%d", nvdimm_bus->id); |
| 346 | |
| 347 | if (IS_ERR(dev)) { |
| 348 | dev_dbg(&nvdimm_bus->dev, "failed to register ndctl%d: %ld\n", |
| 349 | nvdimm_bus->id, PTR_ERR(dev)); |
| 350 | return PTR_ERR(dev); |
| 351 | } |
| 352 | return 0; |
| 353 | } |
| 354 | |
| 355 | void nvdimm_bus_destroy_ndctl(struct nvdimm_bus *nvdimm_bus) |
| 356 | { |
| 357 | device_destroy(nd_class, MKDEV(nvdimm_bus_major, nvdimm_bus->id)); |
| 358 | } |
| 359 | |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 360 | static const struct nd_cmd_desc __nd_cmd_dimm_descs[] = { |
| 361 | [ND_CMD_IMPLEMENTED] = { }, |
| 362 | [ND_CMD_SMART] = { |
| 363 | .out_num = 2, |
| 364 | .out_sizes = { 4, 8, }, |
| 365 | }, |
| 366 | [ND_CMD_SMART_THRESHOLD] = { |
| 367 | .out_num = 2, |
| 368 | .out_sizes = { 4, 8, }, |
| 369 | }, |
| 370 | [ND_CMD_DIMM_FLAGS] = { |
| 371 | .out_num = 2, |
| 372 | .out_sizes = { 4, 4 }, |
| 373 | }, |
| 374 | [ND_CMD_GET_CONFIG_SIZE] = { |
| 375 | .out_num = 3, |
| 376 | .out_sizes = { 4, 4, 4, }, |
| 377 | }, |
| 378 | [ND_CMD_GET_CONFIG_DATA] = { |
| 379 | .in_num = 2, |
| 380 | .in_sizes = { 4, 4, }, |
| 381 | .out_num = 2, |
| 382 | .out_sizes = { 4, UINT_MAX, }, |
| 383 | }, |
| 384 | [ND_CMD_SET_CONFIG_DATA] = { |
| 385 | .in_num = 3, |
| 386 | .in_sizes = { 4, 4, UINT_MAX, }, |
| 387 | .out_num = 1, |
| 388 | .out_sizes = { 4, }, |
| 389 | }, |
| 390 | [ND_CMD_VENDOR] = { |
| 391 | .in_num = 3, |
| 392 | .in_sizes = { 4, 4, UINT_MAX, }, |
| 393 | .out_num = 3, |
| 394 | .out_sizes = { 4, 4, UINT_MAX, }, |
| 395 | }, |
| 396 | }; |
| 397 | |
| 398 | const struct nd_cmd_desc *nd_cmd_dimm_desc(int cmd) |
| 399 | { |
| 400 | if (cmd < ARRAY_SIZE(__nd_cmd_dimm_descs)) |
| 401 | return &__nd_cmd_dimm_descs[cmd]; |
| 402 | return NULL; |
| 403 | } |
| 404 | EXPORT_SYMBOL_GPL(nd_cmd_dimm_desc); |
| 405 | |
| 406 | static const struct nd_cmd_desc __nd_cmd_bus_descs[] = { |
| 407 | [ND_CMD_IMPLEMENTED] = { }, |
| 408 | [ND_CMD_ARS_CAP] = { |
| 409 | .in_num = 2, |
| 410 | .in_sizes = { 8, 8, }, |
Dan Williams | 4577b06 | 2016-02-17 13:08:58 -0800 | [diff] [blame] | 411 | .out_num = 4, |
| 412 | .out_sizes = { 4, 4, 4, 4, }, |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 413 | }, |
| 414 | [ND_CMD_ARS_START] = { |
Dan Williams | 4577b06 | 2016-02-17 13:08:58 -0800 | [diff] [blame] | 415 | .in_num = 5, |
| 416 | .in_sizes = { 8, 8, 2, 1, 5, }, |
| 417 | .out_num = 2, |
| 418 | .out_sizes = { 4, 4, }, |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 419 | }, |
| 420 | [ND_CMD_ARS_STATUS] = { |
Dan Williams | 747ffe1 | 2016-02-19 15:21:14 -0800 | [diff] [blame] | 421 | .out_num = 3, |
| 422 | .out_sizes = { 4, 4, UINT_MAX, }, |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 423 | }, |
Dan Williams | d4f3236 | 2016-03-03 16:08:54 -0800 | [diff] [blame^] | 424 | [ND_CMD_CLEAR_ERROR] = { |
| 425 | .in_num = 2, |
| 426 | .in_sizes = { 8, 8, }, |
| 427 | .out_num = 3, |
| 428 | .out_sizes = { 4, 4, 8, }, |
| 429 | }, |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 430 | }; |
| 431 | |
| 432 | const struct nd_cmd_desc *nd_cmd_bus_desc(int cmd) |
| 433 | { |
| 434 | if (cmd < ARRAY_SIZE(__nd_cmd_bus_descs)) |
| 435 | return &__nd_cmd_bus_descs[cmd]; |
| 436 | return NULL; |
| 437 | } |
| 438 | EXPORT_SYMBOL_GPL(nd_cmd_bus_desc); |
| 439 | |
| 440 | u32 nd_cmd_in_size(struct nvdimm *nvdimm, int cmd, |
| 441 | const struct nd_cmd_desc *desc, int idx, void *buf) |
| 442 | { |
| 443 | if (idx >= desc->in_num) |
| 444 | return UINT_MAX; |
| 445 | |
| 446 | if (desc->in_sizes[idx] < UINT_MAX) |
| 447 | return desc->in_sizes[idx]; |
| 448 | |
| 449 | if (nvdimm && cmd == ND_CMD_SET_CONFIG_DATA && idx == 2) { |
| 450 | struct nd_cmd_set_config_hdr *hdr = buf; |
| 451 | |
| 452 | return hdr->in_length; |
| 453 | } else if (nvdimm && cmd == ND_CMD_VENDOR && idx == 2) { |
| 454 | struct nd_cmd_vendor_hdr *hdr = buf; |
| 455 | |
| 456 | return hdr->in_length; |
| 457 | } |
| 458 | |
| 459 | return UINT_MAX; |
| 460 | } |
| 461 | EXPORT_SYMBOL_GPL(nd_cmd_in_size); |
| 462 | |
| 463 | u32 nd_cmd_out_size(struct nvdimm *nvdimm, int cmd, |
| 464 | const struct nd_cmd_desc *desc, int idx, const u32 *in_field, |
| 465 | const u32 *out_field) |
| 466 | { |
| 467 | if (idx >= desc->out_num) |
| 468 | return UINT_MAX; |
| 469 | |
| 470 | if (desc->out_sizes[idx] < UINT_MAX) |
| 471 | return desc->out_sizes[idx]; |
| 472 | |
| 473 | if (nvdimm && cmd == ND_CMD_GET_CONFIG_DATA && idx == 1) |
| 474 | return in_field[1]; |
| 475 | else if (nvdimm && cmd == ND_CMD_VENDOR && idx == 2) |
| 476 | return out_field[1]; |
Dan Williams | 747ffe1 | 2016-02-19 15:21:14 -0800 | [diff] [blame] | 477 | else if (!nvdimm && cmd == ND_CMD_ARS_STATUS && idx == 2) |
| 478 | return out_field[1] - 8; |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 479 | |
| 480 | return UINT_MAX; |
| 481 | } |
| 482 | EXPORT_SYMBOL_GPL(nd_cmd_out_size); |
| 483 | |
Dan Williams | bf9bccc | 2015-06-17 17:14:46 -0400 | [diff] [blame] | 484 | void wait_nvdimm_bus_probe_idle(struct device *dev) |
Dan Williams | eaf9615 | 2015-05-01 13:11:27 -0400 | [diff] [blame] | 485 | { |
Dan Williams | bf9bccc | 2015-06-17 17:14:46 -0400 | [diff] [blame] | 486 | struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(dev); |
| 487 | |
Dan Williams | eaf9615 | 2015-05-01 13:11:27 -0400 | [diff] [blame] | 488 | do { |
| 489 | if (nvdimm_bus->probe_active == 0) |
| 490 | break; |
| 491 | nvdimm_bus_unlock(&nvdimm_bus->dev); |
| 492 | wait_event(nvdimm_bus->probe_wait, |
| 493 | nvdimm_bus->probe_active == 0); |
| 494 | nvdimm_bus_lock(&nvdimm_bus->dev); |
| 495 | } while (true); |
| 496 | } |
| 497 | |
Dan Williams | d4f3236 | 2016-03-03 16:08:54 -0800 | [diff] [blame^] | 498 | static int pmem_active(struct device *dev, void *data) |
| 499 | { |
| 500 | if (is_nd_pmem(dev) && dev->driver) |
| 501 | return -EBUSY; |
| 502 | return 0; |
| 503 | } |
| 504 | |
Dan Williams | eaf9615 | 2015-05-01 13:11:27 -0400 | [diff] [blame] | 505 | /* set_config requires an idle interleave set */ |
Dan Williams | 87bf572 | 2016-02-22 21:50:31 -0800 | [diff] [blame] | 506 | static int nd_cmd_clear_to_send(struct nvdimm_bus *nvdimm_bus, |
| 507 | struct nvdimm *nvdimm, unsigned int cmd) |
Dan Williams | eaf9615 | 2015-05-01 13:11:27 -0400 | [diff] [blame] | 508 | { |
Dan Williams | 87bf572 | 2016-02-22 21:50:31 -0800 | [diff] [blame] | 509 | struct nvdimm_bus_descriptor *nd_desc = nvdimm_bus->nd_desc; |
| 510 | |
| 511 | /* ask the bus provider if it would like to block this request */ |
| 512 | if (nd_desc->clear_to_send) { |
| 513 | int rc = nd_desc->clear_to_send(nd_desc, nvdimm, cmd); |
| 514 | |
| 515 | if (rc) |
| 516 | return rc; |
| 517 | } |
Dan Williams | eaf9615 | 2015-05-01 13:11:27 -0400 | [diff] [blame] | 518 | |
Dan Williams | d4f3236 | 2016-03-03 16:08:54 -0800 | [diff] [blame^] | 519 | /* require clear error to go through the pmem driver */ |
| 520 | if (!nvdimm && cmd == ND_CMD_CLEAR_ERROR) |
| 521 | return device_for_each_child(&nvdimm_bus->dev, NULL, |
| 522 | pmem_active); |
| 523 | |
Dan Williams | eaf9615 | 2015-05-01 13:11:27 -0400 | [diff] [blame] | 524 | if (!nvdimm || cmd != ND_CMD_SET_CONFIG_DATA) |
| 525 | return 0; |
| 526 | |
Dan Williams | 87bf572 | 2016-02-22 21:50:31 -0800 | [diff] [blame] | 527 | /* prevent label manipulation while the kernel owns label updates */ |
Dan Williams | bf9bccc | 2015-06-17 17:14:46 -0400 | [diff] [blame] | 528 | wait_nvdimm_bus_probe_idle(&nvdimm_bus->dev); |
Dan Williams | eaf9615 | 2015-05-01 13:11:27 -0400 | [diff] [blame] | 529 | if (atomic_read(&nvdimm->busy)) |
| 530 | return -EBUSY; |
| 531 | return 0; |
| 532 | } |
| 533 | |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 534 | static int __nd_ioctl(struct nvdimm_bus *nvdimm_bus, struct nvdimm *nvdimm, |
| 535 | int read_only, unsigned int ioctl_cmd, unsigned long arg) |
| 536 | { |
| 537 | struct nvdimm_bus_descriptor *nd_desc = nvdimm_bus->nd_desc; |
| 538 | size_t buf_len = 0, in_len = 0, out_len = 0; |
| 539 | static char out_env[ND_CMD_MAX_ENVELOPE]; |
| 540 | static char in_env[ND_CMD_MAX_ENVELOPE]; |
| 541 | const struct nd_cmd_desc *desc = NULL; |
| 542 | unsigned int cmd = _IOC_NR(ioctl_cmd); |
| 543 | void __user *p = (void __user *) arg; |
| 544 | struct device *dev = &nvdimm_bus->dev; |
| 545 | const char *cmd_name, *dimm_name; |
| 546 | unsigned long dsm_mask; |
| 547 | void *buf; |
| 548 | int rc, i; |
| 549 | |
| 550 | if (nvdimm) { |
| 551 | desc = nd_cmd_dimm_desc(cmd); |
| 552 | cmd_name = nvdimm_cmd_name(cmd); |
| 553 | dsm_mask = nvdimm->dsm_mask ? *(nvdimm->dsm_mask) : 0; |
| 554 | dimm_name = dev_name(&nvdimm->dev); |
| 555 | } else { |
| 556 | desc = nd_cmd_bus_desc(cmd); |
| 557 | cmd_name = nvdimm_bus_cmd_name(cmd); |
| 558 | dsm_mask = nd_desc->dsm_mask; |
| 559 | dimm_name = "bus"; |
| 560 | } |
| 561 | |
| 562 | if (!desc || (desc->out_num + desc->in_num == 0) || |
| 563 | !test_bit(cmd, &dsm_mask)) |
| 564 | return -ENOTTY; |
| 565 | |
| 566 | /* fail write commands (when read-only) */ |
| 567 | if (read_only) |
Jerry Hoemann | 07accfa | 2016-01-06 16:03:41 -0700 | [diff] [blame] | 568 | switch (cmd) { |
| 569 | case ND_CMD_VENDOR: |
| 570 | case ND_CMD_SET_CONFIG_DATA: |
| 571 | case ND_CMD_ARS_START: |
Dan Williams | d4f3236 | 2016-03-03 16:08:54 -0800 | [diff] [blame^] | 572 | case ND_CMD_CLEAR_ERROR: |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 573 | dev_dbg(&nvdimm_bus->dev, "'%s' command while read-only.\n", |
| 574 | nvdimm ? nvdimm_cmd_name(cmd) |
| 575 | : nvdimm_bus_cmd_name(cmd)); |
| 576 | return -EPERM; |
| 577 | default: |
| 578 | break; |
| 579 | } |
| 580 | |
| 581 | /* process an input envelope */ |
| 582 | for (i = 0; i < desc->in_num; i++) { |
| 583 | u32 in_size, copy; |
| 584 | |
| 585 | in_size = nd_cmd_in_size(nvdimm, cmd, desc, i, in_env); |
| 586 | if (in_size == UINT_MAX) { |
| 587 | dev_err(dev, "%s:%s unknown input size cmd: %s field: %d\n", |
| 588 | __func__, dimm_name, cmd_name, i); |
| 589 | return -ENXIO; |
| 590 | } |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 591 | if (in_len < sizeof(in_env)) |
| 592 | copy = min_t(u32, sizeof(in_env) - in_len, in_size); |
| 593 | else |
| 594 | copy = 0; |
| 595 | if (copy && copy_from_user(&in_env[in_len], p + in_len, copy)) |
| 596 | return -EFAULT; |
| 597 | in_len += in_size; |
| 598 | } |
| 599 | |
| 600 | /* process an output envelope */ |
| 601 | for (i = 0; i < desc->out_num; i++) { |
| 602 | u32 out_size = nd_cmd_out_size(nvdimm, cmd, desc, i, |
| 603 | (u32 *) in_env, (u32 *) out_env); |
| 604 | u32 copy; |
| 605 | |
| 606 | if (out_size == UINT_MAX) { |
| 607 | dev_dbg(dev, "%s:%s unknown output size cmd: %s field: %d\n", |
| 608 | __func__, dimm_name, cmd_name, i); |
| 609 | return -EFAULT; |
| 610 | } |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 611 | if (out_len < sizeof(out_env)) |
| 612 | copy = min_t(u32, sizeof(out_env) - out_len, out_size); |
| 613 | else |
| 614 | copy = 0; |
| 615 | if (copy && copy_from_user(&out_env[out_len], |
| 616 | p + in_len + out_len, copy)) |
| 617 | return -EFAULT; |
| 618 | out_len += out_size; |
| 619 | } |
| 620 | |
| 621 | buf_len = out_len + in_len; |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 622 | if (buf_len > ND_IOCTL_MAX_BUFLEN) { |
| 623 | dev_dbg(dev, "%s:%s cmd: %s buf_len: %zu > %d\n", __func__, |
| 624 | dimm_name, cmd_name, buf_len, |
| 625 | ND_IOCTL_MAX_BUFLEN); |
| 626 | return -EINVAL; |
| 627 | } |
| 628 | |
| 629 | buf = vmalloc(buf_len); |
| 630 | if (!buf) |
| 631 | return -ENOMEM; |
| 632 | |
| 633 | if (copy_from_user(buf, p, buf_len)) { |
| 634 | rc = -EFAULT; |
| 635 | goto out; |
| 636 | } |
| 637 | |
Dan Williams | eaf9615 | 2015-05-01 13:11:27 -0400 | [diff] [blame] | 638 | nvdimm_bus_lock(&nvdimm_bus->dev); |
Dan Williams | 87bf572 | 2016-02-22 21:50:31 -0800 | [diff] [blame] | 639 | rc = nd_cmd_clear_to_send(nvdimm_bus, nvdimm, cmd); |
Dan Williams | eaf9615 | 2015-05-01 13:11:27 -0400 | [diff] [blame] | 640 | if (rc) |
| 641 | goto out_unlock; |
| 642 | |
Dan Williams | aef2533 | 2016-02-12 17:01:11 -0800 | [diff] [blame] | 643 | rc = nd_desc->ndctl(nd_desc, nvdimm, cmd, buf, buf_len, NULL); |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 644 | if (rc < 0) |
Dan Williams | eaf9615 | 2015-05-01 13:11:27 -0400 | [diff] [blame] | 645 | goto out_unlock; |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 646 | if (copy_to_user(p, buf, buf_len)) |
| 647 | rc = -EFAULT; |
Dan Williams | eaf9615 | 2015-05-01 13:11:27 -0400 | [diff] [blame] | 648 | out_unlock: |
| 649 | nvdimm_bus_unlock(&nvdimm_bus->dev); |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 650 | out: |
| 651 | vfree(buf); |
| 652 | return rc; |
| 653 | } |
| 654 | |
Dan Williams | 45def22 | 2015-04-26 19:26:48 -0400 | [diff] [blame] | 655 | static long nd_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
| 656 | { |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 657 | long id = (long) file->private_data; |
Jerry Hoemann | 4dc0e7be | 2016-01-06 16:03:39 -0700 | [diff] [blame] | 658 | int rc = -ENXIO, ro; |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 659 | struct nvdimm_bus *nvdimm_bus; |
| 660 | |
Jerry Hoemann | 4dc0e7be | 2016-01-06 16:03:39 -0700 | [diff] [blame] | 661 | ro = ((file->f_flags & O_ACCMODE) == O_RDONLY); |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 662 | mutex_lock(&nvdimm_bus_list_mutex); |
| 663 | list_for_each_entry(nvdimm_bus, &nvdimm_bus_list, list) { |
| 664 | if (nvdimm_bus->id == id) { |
Jerry Hoemann | 4dc0e7be | 2016-01-06 16:03:39 -0700 | [diff] [blame] | 665 | rc = __nd_ioctl(nvdimm_bus, NULL, ro, cmd, arg); |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 666 | break; |
| 667 | } |
| 668 | } |
| 669 | mutex_unlock(&nvdimm_bus_list_mutex); |
| 670 | |
| 671 | return rc; |
| 672 | } |
| 673 | |
| 674 | static int match_dimm(struct device *dev, void *data) |
| 675 | { |
| 676 | long id = (long) data; |
| 677 | |
| 678 | if (is_nvdimm(dev)) { |
| 679 | struct nvdimm *nvdimm = to_nvdimm(dev); |
| 680 | |
| 681 | return nvdimm->id == id; |
| 682 | } |
| 683 | |
| 684 | return 0; |
| 685 | } |
| 686 | |
| 687 | static long nvdimm_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
| 688 | { |
Jerry Hoemann | 4dc0e7be | 2016-01-06 16:03:39 -0700 | [diff] [blame] | 689 | int rc = -ENXIO, ro; |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 690 | struct nvdimm_bus *nvdimm_bus; |
| 691 | |
Jerry Hoemann | 4dc0e7be | 2016-01-06 16:03:39 -0700 | [diff] [blame] | 692 | ro = ((file->f_flags & O_ACCMODE) == O_RDONLY); |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 693 | mutex_lock(&nvdimm_bus_list_mutex); |
| 694 | list_for_each_entry(nvdimm_bus, &nvdimm_bus_list, list) { |
| 695 | struct device *dev = device_find_child(&nvdimm_bus->dev, |
| 696 | file->private_data, match_dimm); |
| 697 | struct nvdimm *nvdimm; |
| 698 | |
| 699 | if (!dev) |
| 700 | continue; |
| 701 | |
| 702 | nvdimm = to_nvdimm(dev); |
Jerry Hoemann | 4dc0e7be | 2016-01-06 16:03:39 -0700 | [diff] [blame] | 703 | rc = __nd_ioctl(nvdimm_bus, nvdimm, ro, cmd, arg); |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 704 | put_device(dev); |
| 705 | break; |
| 706 | } |
| 707 | mutex_unlock(&nvdimm_bus_list_mutex); |
| 708 | |
| 709 | return rc; |
| 710 | } |
| 711 | |
| 712 | static int nd_open(struct inode *inode, struct file *file) |
| 713 | { |
| 714 | long minor = iminor(inode); |
| 715 | |
| 716 | file->private_data = (void *) minor; |
| 717 | return 0; |
Dan Williams | 45def22 | 2015-04-26 19:26:48 -0400 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | static const struct file_operations nvdimm_bus_fops = { |
| 721 | .owner = THIS_MODULE, |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 722 | .open = nd_open, |
Dan Williams | 45def22 | 2015-04-26 19:26:48 -0400 | [diff] [blame] | 723 | .unlocked_ioctl = nd_ioctl, |
| 724 | .compat_ioctl = nd_ioctl, |
| 725 | .llseek = noop_llseek, |
| 726 | }; |
| 727 | |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 728 | static const struct file_operations nvdimm_fops = { |
| 729 | .owner = THIS_MODULE, |
| 730 | .open = nd_open, |
| 731 | .unlocked_ioctl = nvdimm_ioctl, |
| 732 | .compat_ioctl = nvdimm_ioctl, |
| 733 | .llseek = noop_llseek, |
| 734 | }; |
| 735 | |
Dan Williams | 45def22 | 2015-04-26 19:26:48 -0400 | [diff] [blame] | 736 | int __init nvdimm_bus_init(void) |
| 737 | { |
| 738 | int rc; |
| 739 | |
Dan Williams | e6dfb2d | 2015-04-25 03:56:17 -0400 | [diff] [blame] | 740 | rc = bus_register(&nvdimm_bus_type); |
| 741 | if (rc) |
| 742 | return rc; |
| 743 | |
Dan Williams | 45def22 | 2015-04-26 19:26:48 -0400 | [diff] [blame] | 744 | rc = register_chrdev(0, "ndctl", &nvdimm_bus_fops); |
| 745 | if (rc < 0) |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 746 | goto err_bus_chrdev; |
Dan Williams | 45def22 | 2015-04-26 19:26:48 -0400 | [diff] [blame] | 747 | nvdimm_bus_major = rc; |
| 748 | |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 749 | rc = register_chrdev(0, "dimmctl", &nvdimm_fops); |
| 750 | if (rc < 0) |
| 751 | goto err_dimm_chrdev; |
| 752 | nvdimm_major = rc; |
| 753 | |
Dan Williams | 45def22 | 2015-04-26 19:26:48 -0400 | [diff] [blame] | 754 | nd_class = class_create(THIS_MODULE, "nd"); |
Axel Lin | daa1dee | 2015-06-28 17:00:57 +0800 | [diff] [blame] | 755 | if (IS_ERR(nd_class)) { |
| 756 | rc = PTR_ERR(nd_class); |
Dan Williams | 45def22 | 2015-04-26 19:26:48 -0400 | [diff] [blame] | 757 | goto err_class; |
Axel Lin | daa1dee | 2015-06-28 17:00:57 +0800 | [diff] [blame] | 758 | } |
Dan Williams | 45def22 | 2015-04-26 19:26:48 -0400 | [diff] [blame] | 759 | |
| 760 | return 0; |
| 761 | |
| 762 | err_class: |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 763 | unregister_chrdev(nvdimm_major, "dimmctl"); |
| 764 | err_dimm_chrdev: |
Dan Williams | 45def22 | 2015-04-26 19:26:48 -0400 | [diff] [blame] | 765 | unregister_chrdev(nvdimm_bus_major, "ndctl"); |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 766 | err_bus_chrdev: |
Dan Williams | e6dfb2d | 2015-04-25 03:56:17 -0400 | [diff] [blame] | 767 | bus_unregister(&nvdimm_bus_type); |
Dan Williams | 45def22 | 2015-04-26 19:26:48 -0400 | [diff] [blame] | 768 | |
| 769 | return rc; |
| 770 | } |
| 771 | |
Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 772 | void nvdimm_bus_exit(void) |
Dan Williams | 45def22 | 2015-04-26 19:26:48 -0400 | [diff] [blame] | 773 | { |
| 774 | class_destroy(nd_class); |
| 775 | unregister_chrdev(nvdimm_bus_major, "ndctl"); |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 776 | unregister_chrdev(nvdimm_major, "dimmctl"); |
Dan Williams | e6dfb2d | 2015-04-25 03:56:17 -0400 | [diff] [blame] | 777 | bus_unregister(&nvdimm_bus_type); |
Dan Williams | 45def22 | 2015-04-26 19:26:48 -0400 | [diff] [blame] | 778 | } |