2 * Copyright(c) 2013-2015 Intel Corporation. All rights reserved.
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.
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.
13 #include <linux/vmalloc.h>
14 #include <linux/module.h>
15 #include <linux/device.h>
16 #include <linux/sizes.h>
17 #include <linux/ndctl.h>
18 #include <linux/slab.h>
24 static int nvdimm_probe(struct device *dev)
26 struct nvdimm_drvdata *ndd;
29 rc = nvdimm_check_config_data(dev);
31 /* not required for non-aliased nvdimm, ex. NVDIMM-N */
38 * The locked status bit reflects explicit status codes from the
39 * label reading commands, revalidate it each time the driver is
40 * activated and re-reads the label area.
42 nvdimm_clear_locked(dev);
44 ndd = kzalloc(sizeof(*ndd), GFP_KERNEL);
48 dev_set_drvdata(dev, ndd);
49 ndd->dpa.name = dev_name(dev);
56 kref_init(&ndd->kref);
59 * Attempt to unlock, if the DIMM supports security commands,
60 * otherwise the locked indication is determined by explicit
61 * status codes from the label reading commands.
63 rc = nvdimm_security_unlock(dev);
65 dev_dbg(dev, "failed to unlock dimm: %d\n", rc);
69 * EACCES failures reading the namespace label-area-properties
70 * are interpreted as the DIMM capacity being locked but the
71 * namespace labels themselves being accessible.
73 rc = nvdimm_init_nsarea(ndd);
76 * See nvdimm_namespace_common_probe() where we fail to
77 * allow namespaces to probe while the DIMM is locked,
78 * but we do allow for namespace enumeration.
80 nvdimm_set_locked(dev);
87 * EACCES failures reading the namespace label-data are
88 * interpreted as the label area being locked in addition to the
89 * DIMM capacity. We fail the dimm probe to prevent regions from
90 * attempting to parse the label area.
92 rc = nd_label_data_init(ndd);
94 nvdimm_set_locked(dev);
98 dev_dbg(dev, "config data size: %d\n", ndd->nsarea.config_size);
100 nvdimm_bus_lock(dev);
101 if (ndd->ns_current >= 0) {
102 rc = nd_label_reserve_dpa(ndd);
104 nvdimm_set_aliasing(dev);
106 nvdimm_bus_unlock(dev);
118 static int nvdimm_remove(struct device *dev)
120 struct nvdimm_drvdata *ndd = dev_get_drvdata(dev);
125 nvdimm_bus_lock(dev);
126 dev_set_drvdata(dev, NULL);
127 nvdimm_bus_unlock(dev);
133 static struct nd_device_driver nvdimm_driver = {
134 .probe = nvdimm_probe,
135 .remove = nvdimm_remove,
139 .type = ND_DRIVER_DIMM,
142 int __init nvdimm_init(void)
144 return nd_driver_register(&nvdimm_driver);
147 void nvdimm_exit(void)
149 driver_unregister(&nvdimm_driver.drv);
152 MODULE_ALIAS_ND_DEVICE(ND_DEVICE_DIMM);