Thomas Gleixner | 5b497af | 2019-05-29 07:18:09 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 2 | /* |
| 3 | * Copyright(c) 2013-2015 Intel Corporation. All rights reserved. |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 4 | */ |
| 5 | #include <linux/blkdev.h> |
| 6 | #include <linux/device.h> |
| 7 | #include <linux/genhd.h> |
| 8 | #include <linux/sizes.h> |
| 9 | #include <linux/slab.h> |
| 10 | #include <linux/fs.h> |
| 11 | #include <linux/mm.h> |
| 12 | #include "nd-core.h" |
| 13 | #include "btt.h" |
| 14 | #include "nd.h" |
| 15 | |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 16 | static void nd_btt_release(struct device *dev) |
| 17 | { |
| 18 | struct nd_region *nd_region = to_nd_region(dev->parent); |
| 19 | struct nd_btt *nd_btt = to_nd_btt(dev); |
| 20 | |
Dan Williams | 426824d | 2018-03-05 16:39:31 -0800 | [diff] [blame] | 21 | dev_dbg(dev, "trace\n"); |
Dan Williams | e145574 | 2015-07-30 17:57:47 -0400 | [diff] [blame] | 22 | nd_detach_ndns(&nd_btt->dev, &nd_btt->ndns); |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 23 | ida_simple_remove(&nd_region->btt_ida, nd_btt->id); |
| 24 | kfree(nd_btt->uuid); |
| 25 | kfree(nd_btt); |
| 26 | } |
| 27 | |
| 28 | static struct device_type nd_btt_device_type = { |
| 29 | .name = "nd_btt", |
| 30 | .release = nd_btt_release, |
| 31 | }; |
| 32 | |
| 33 | bool is_nd_btt(struct device *dev) |
| 34 | { |
| 35 | return dev->type == &nd_btt_device_type; |
| 36 | } |
| 37 | EXPORT_SYMBOL(is_nd_btt); |
| 38 | |
| 39 | struct nd_btt *to_nd_btt(struct device *dev) |
| 40 | { |
| 41 | struct nd_btt *nd_btt = container_of(dev, struct nd_btt, dev); |
| 42 | |
| 43 | WARN_ON(!is_nd_btt(dev)); |
| 44 | return nd_btt; |
| 45 | } |
| 46 | EXPORT_SYMBOL(to_nd_btt); |
| 47 | |
Vishal Verma | 41cd8b7 | 2015-06-25 04:21:52 -0400 | [diff] [blame] | 48 | static const unsigned long btt_lbasize_supported[] = { 512, 520, 528, |
| 49 | 4096, 4104, 4160, 4224, 0 }; |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 50 | |
| 51 | static ssize_t sector_size_show(struct device *dev, |
| 52 | struct device_attribute *attr, char *buf) |
| 53 | { |
| 54 | struct nd_btt *nd_btt = to_nd_btt(dev); |
| 55 | |
Dan Williams | b2c48f9 | 2017-08-11 17:36:54 -0700 | [diff] [blame] | 56 | return nd_size_select_show(nd_btt->lbasize, btt_lbasize_supported, buf); |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | static ssize_t sector_size_store(struct device *dev, |
| 60 | struct device_attribute *attr, const char *buf, size_t len) |
| 61 | { |
| 62 | struct nd_btt *nd_btt = to_nd_btt(dev); |
| 63 | ssize_t rc; |
| 64 | |
Dan Williams | 87a30e1 | 2019-07-17 18:08:26 -0700 | [diff] [blame] | 65 | nd_device_lock(dev); |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 66 | nvdimm_bus_lock(dev); |
Dan Williams | b2c48f9 | 2017-08-11 17:36:54 -0700 | [diff] [blame] | 67 | rc = nd_size_select_store(dev, buf, &nd_btt->lbasize, |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 68 | btt_lbasize_supported); |
Dan Williams | 426824d | 2018-03-05 16:39:31 -0800 | [diff] [blame] | 69 | dev_dbg(dev, "result: %zd wrote: %s%s", rc, buf, |
| 70 | buf[len - 1] == '\n' ? "" : "\n"); |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 71 | nvdimm_bus_unlock(dev); |
Dan Williams | 87a30e1 | 2019-07-17 18:08:26 -0700 | [diff] [blame] | 72 | nd_device_unlock(dev); |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 73 | |
| 74 | return rc ? rc : len; |
| 75 | } |
| 76 | static DEVICE_ATTR_RW(sector_size); |
| 77 | |
| 78 | static ssize_t uuid_show(struct device *dev, |
| 79 | struct device_attribute *attr, char *buf) |
| 80 | { |
| 81 | struct nd_btt *nd_btt = to_nd_btt(dev); |
| 82 | |
| 83 | if (nd_btt->uuid) |
| 84 | return sprintf(buf, "%pUb\n", nd_btt->uuid); |
| 85 | return sprintf(buf, "\n"); |
| 86 | } |
| 87 | |
| 88 | static ssize_t uuid_store(struct device *dev, |
| 89 | struct device_attribute *attr, const char *buf, size_t len) |
| 90 | { |
| 91 | struct nd_btt *nd_btt = to_nd_btt(dev); |
| 92 | ssize_t rc; |
| 93 | |
Dan Williams | 87a30e1 | 2019-07-17 18:08:26 -0700 | [diff] [blame] | 94 | nd_device_lock(dev); |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 95 | rc = nd_uuid_store(dev, &nd_btt->uuid, buf, len); |
Dan Williams | 426824d | 2018-03-05 16:39:31 -0800 | [diff] [blame] | 96 | dev_dbg(dev, "result: %zd wrote: %s%s", rc, buf, |
| 97 | buf[len - 1] == '\n' ? "" : "\n"); |
Dan Williams | 87a30e1 | 2019-07-17 18:08:26 -0700 | [diff] [blame] | 98 | nd_device_unlock(dev); |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 99 | |
| 100 | return rc ? rc : len; |
| 101 | } |
| 102 | static DEVICE_ATTR_RW(uuid); |
| 103 | |
| 104 | static ssize_t namespace_show(struct device *dev, |
| 105 | struct device_attribute *attr, char *buf) |
| 106 | { |
| 107 | struct nd_btt *nd_btt = to_nd_btt(dev); |
| 108 | ssize_t rc; |
| 109 | |
| 110 | nvdimm_bus_lock(dev); |
| 111 | rc = sprintf(buf, "%s\n", nd_btt->ndns |
| 112 | ? dev_name(&nd_btt->ndns->dev) : ""); |
| 113 | nvdimm_bus_unlock(dev); |
| 114 | return rc; |
| 115 | } |
| 116 | |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 117 | static ssize_t namespace_store(struct device *dev, |
| 118 | struct device_attribute *attr, const char *buf, size_t len) |
| 119 | { |
Dan Williams | e145574 | 2015-07-30 17:57:47 -0400 | [diff] [blame] | 120 | struct nd_btt *nd_btt = to_nd_btt(dev); |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 121 | ssize_t rc; |
| 122 | |
Dan Williams | 87a30e1 | 2019-07-17 18:08:26 -0700 | [diff] [blame] | 123 | nd_device_lock(dev); |
Axel Lin | 4be9c1f | 2015-09-16 21:24:47 +0800 | [diff] [blame] | 124 | nvdimm_bus_lock(dev); |
Dan Williams | e145574 | 2015-07-30 17:57:47 -0400 | [diff] [blame] | 125 | rc = nd_namespace_store(dev, &nd_btt->ndns, buf, len); |
Dan Williams | 426824d | 2018-03-05 16:39:31 -0800 | [diff] [blame] | 126 | dev_dbg(dev, "result: %zd wrote: %s%s", rc, buf, |
| 127 | buf[len - 1] == '\n' ? "" : "\n"); |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 128 | nvdimm_bus_unlock(dev); |
Dan Williams | 87a30e1 | 2019-07-17 18:08:26 -0700 | [diff] [blame] | 129 | nd_device_unlock(dev); |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 130 | |
| 131 | return rc; |
| 132 | } |
| 133 | static DEVICE_ATTR_RW(namespace); |
| 134 | |
Vishal Verma | abe8b4e | 2016-07-27 16:38:59 -0600 | [diff] [blame] | 135 | static ssize_t size_show(struct device *dev, |
| 136 | struct device_attribute *attr, char *buf) |
| 137 | { |
| 138 | struct nd_btt *nd_btt = to_nd_btt(dev); |
| 139 | ssize_t rc; |
| 140 | |
Dan Williams | 87a30e1 | 2019-07-17 18:08:26 -0700 | [diff] [blame] | 141 | nd_device_lock(dev); |
Vishal Verma | abe8b4e | 2016-07-27 16:38:59 -0600 | [diff] [blame] | 142 | if (dev->driver) |
| 143 | rc = sprintf(buf, "%llu\n", nd_btt->size); |
| 144 | else { |
| 145 | /* no size to convey if the btt instance is disabled */ |
| 146 | rc = -ENXIO; |
| 147 | } |
Dan Williams | 87a30e1 | 2019-07-17 18:08:26 -0700 | [diff] [blame] | 148 | nd_device_unlock(dev); |
Vishal Verma | abe8b4e | 2016-07-27 16:38:59 -0600 | [diff] [blame] | 149 | |
| 150 | return rc; |
| 151 | } |
| 152 | static DEVICE_ATTR_RO(size); |
| 153 | |
Vishal Verma | 9dedc73 | 2019-02-27 17:06:27 -0700 | [diff] [blame] | 154 | static ssize_t log_zero_flags_show(struct device *dev, |
| 155 | struct device_attribute *attr, char *buf) |
| 156 | { |
| 157 | return sprintf(buf, "Y\n"); |
| 158 | } |
| 159 | static DEVICE_ATTR_RO(log_zero_flags); |
| 160 | |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 161 | static struct attribute *nd_btt_attributes[] = { |
| 162 | &dev_attr_sector_size.attr, |
| 163 | &dev_attr_namespace.attr, |
| 164 | &dev_attr_uuid.attr, |
Vishal Verma | abe8b4e | 2016-07-27 16:38:59 -0600 | [diff] [blame] | 165 | &dev_attr_size.attr, |
Vishal Verma | 9dedc73 | 2019-02-27 17:06:27 -0700 | [diff] [blame] | 166 | &dev_attr_log_zero_flags.attr, |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 167 | NULL, |
| 168 | }; |
| 169 | |
| 170 | static struct attribute_group nd_btt_attribute_group = { |
| 171 | .attrs = nd_btt_attributes, |
| 172 | }; |
| 173 | |
| 174 | static const struct attribute_group *nd_btt_attribute_groups[] = { |
| 175 | &nd_btt_attribute_group, |
| 176 | &nd_device_attribute_group, |
Toshi Kani | 74ae66c | 2015-06-19 12:18:34 -0600 | [diff] [blame] | 177 | &nd_numa_attribute_group, |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 178 | NULL, |
| 179 | }; |
| 180 | |
| 181 | static struct device *__nd_btt_create(struct nd_region *nd_region, |
| 182 | unsigned long lbasize, u8 *uuid, |
| 183 | struct nd_namespace_common *ndns) |
| 184 | { |
| 185 | struct nd_btt *nd_btt; |
| 186 | struct device *dev; |
| 187 | |
| 188 | nd_btt = kzalloc(sizeof(*nd_btt), GFP_KERNEL); |
| 189 | if (!nd_btt) |
| 190 | return NULL; |
| 191 | |
| 192 | nd_btt->id = ida_simple_get(&nd_region->btt_ida, 0, 0, GFP_KERNEL); |
Aditya Pakki | 486fa92 | 2019-03-25 16:55:27 -0500 | [diff] [blame] | 193 | if (nd_btt->id < 0) |
| 194 | goto out_nd_btt; |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 195 | |
| 196 | nd_btt->lbasize = lbasize; |
Aditya Pakki | 486fa92 | 2019-03-25 16:55:27 -0500 | [diff] [blame] | 197 | if (uuid) { |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 198 | uuid = kmemdup(uuid, 16, GFP_KERNEL); |
Aditya Pakki | 486fa92 | 2019-03-25 16:55:27 -0500 | [diff] [blame] | 199 | if (!uuid) |
| 200 | goto out_put_id; |
| 201 | } |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 202 | nd_btt->uuid = uuid; |
| 203 | dev = &nd_btt->dev; |
| 204 | dev_set_name(dev, "btt%d.%d", nd_region->id, nd_btt->id); |
| 205 | dev->parent = &nd_region->dev; |
| 206 | dev->type = &nd_btt_device_type; |
| 207 | dev->groups = nd_btt_attribute_groups; |
| 208 | device_initialize(&nd_btt->dev); |
Dan Williams | e145574 | 2015-07-30 17:57:47 -0400 | [diff] [blame] | 209 | if (ndns && !__nd_attach_ndns(&nd_btt->dev, ndns, &nd_btt->ndns)) { |
Dan Williams | 426824d | 2018-03-05 16:39:31 -0800 | [diff] [blame] | 210 | dev_dbg(&ndns->dev, "failed, already claimed by %s\n", |
| 211 | dev_name(ndns->claim)); |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 212 | put_device(dev); |
| 213 | return NULL; |
| 214 | } |
| 215 | return dev; |
Aditya Pakki | 486fa92 | 2019-03-25 16:55:27 -0500 | [diff] [blame] | 216 | |
| 217 | out_put_id: |
| 218 | ida_simple_remove(&nd_region->btt_ida, nd_btt->id); |
| 219 | |
| 220 | out_nd_btt: |
| 221 | kfree(nd_btt); |
| 222 | return NULL; |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | struct device *nd_btt_create(struct nd_region *nd_region) |
| 226 | { |
| 227 | struct device *dev = __nd_btt_create(nd_region, 0, NULL, NULL); |
| 228 | |
Markus Elfring | d4c5725 | 2016-07-24 11:05:34 +0200 | [diff] [blame] | 229 | __nd_device_register(dev); |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 230 | return dev; |
| 231 | } |
| 232 | |
Vishal Verma | ab45e76 | 2015-07-29 14:58:08 -0600 | [diff] [blame] | 233 | /** |
| 234 | * nd_btt_arena_is_valid - check if the metadata layout is valid |
| 235 | * @nd_btt: device with BTT geometry and backing device info |
| 236 | * @super: pointer to the arena's info block being tested |
| 237 | * |
| 238 | * Check consistency of the btt info block with itself by validating |
Vishal Verma | 6ec6895 | 2015-07-29 14:58:09 -0600 | [diff] [blame] | 239 | * the checksum, and with the parent namespace by verifying the |
| 240 | * parent_uuid contained in the info block with the one supplied in. |
Vishal Verma | ab45e76 | 2015-07-29 14:58:08 -0600 | [diff] [blame] | 241 | * |
| 242 | * Returns: |
| 243 | * false for an invalid info block, true for a valid one |
| 244 | */ |
| 245 | bool nd_btt_arena_is_valid(struct nd_btt *nd_btt, struct btt_sb *super) |
| 246 | { |
Vishal Verma | 6ec6895 | 2015-07-29 14:58:09 -0600 | [diff] [blame] | 247 | const u8 *parent_uuid = nd_dev_to_uuid(&nd_btt->ndns->dev); |
Vishal Verma | ab45e76 | 2015-07-29 14:58:08 -0600 | [diff] [blame] | 248 | u64 checksum; |
| 249 | |
| 250 | if (memcmp(super->signature, BTT_SIG, BTT_SIG_LEN) != 0) |
| 251 | return false; |
| 252 | |
Christoph Hellwig | ef40dda | 2017-05-11 09:01:42 +0200 | [diff] [blame] | 253 | if (!guid_is_null((guid_t *)&super->parent_uuid)) |
Vishal Verma | 6ec6895 | 2015-07-29 14:58:09 -0600 | [diff] [blame] | 254 | if (memcmp(super->parent_uuid, parent_uuid, 16) != 0) |
| 255 | return false; |
| 256 | |
Vishal Verma | ab45e76 | 2015-07-29 14:58:08 -0600 | [diff] [blame] | 257 | checksum = le64_to_cpu(super->checksum); |
| 258 | super->checksum = 0; |
Dan Williams | e145574 | 2015-07-30 17:57:47 -0400 | [diff] [blame] | 259 | if (checksum != nd_sb_checksum((struct nd_gen_sb *) super)) |
Vishal Verma | ab45e76 | 2015-07-29 14:58:08 -0600 | [diff] [blame] | 260 | return false; |
| 261 | super->checksum = cpu_to_le64(checksum); |
| 262 | |
| 263 | /* TODO: figure out action for this */ |
| 264 | if ((le32_to_cpu(super->flags) & IB_FLAG_ERROR_MASK) != 0) |
| 265 | dev_info(&nd_btt->dev, "Found arena with an error flag\n"); |
| 266 | |
| 267 | return true; |
| 268 | } |
| 269 | EXPORT_SYMBOL(nd_btt_arena_is_valid); |
| 270 | |
Vishal Verma | 14e4945 | 2017-06-28 14:25:00 -0600 | [diff] [blame] | 271 | int nd_btt_version(struct nd_btt *nd_btt, struct nd_namespace_common *ndns, |
| 272 | struct btt_sb *btt_sb) |
| 273 | { |
| 274 | if (ndns->claim_class == NVDIMM_CCLASS_BTT2) { |
| 275 | /* Probe/setup for BTT v2.0 */ |
| 276 | nd_btt->initial_offset = 0; |
| 277 | nd_btt->version_major = 2; |
| 278 | nd_btt->version_minor = 0; |
| 279 | if (nvdimm_read_bytes(ndns, 0, btt_sb, sizeof(*btt_sb), 0)) |
| 280 | return -ENXIO; |
| 281 | if (!nd_btt_arena_is_valid(nd_btt, btt_sb)) |
| 282 | return -ENODEV; |
| 283 | if ((le16_to_cpu(btt_sb->version_major) != 2) || |
| 284 | (le16_to_cpu(btt_sb->version_minor) != 0)) |
| 285 | return -ENODEV; |
| 286 | } else { |
| 287 | /* |
| 288 | * Probe/setup for BTT v1.1 (NVDIMM_CCLASS_NONE or |
| 289 | * NVDIMM_CCLASS_BTT) |
| 290 | */ |
| 291 | nd_btt->initial_offset = SZ_4K; |
| 292 | nd_btt->version_major = 1; |
| 293 | nd_btt->version_minor = 1; |
| 294 | if (nvdimm_read_bytes(ndns, SZ_4K, btt_sb, sizeof(*btt_sb), 0)) |
| 295 | return -ENXIO; |
| 296 | if (!nd_btt_arena_is_valid(nd_btt, btt_sb)) |
| 297 | return -ENODEV; |
| 298 | if ((le16_to_cpu(btt_sb->version_major) != 1) || |
| 299 | (le16_to_cpu(btt_sb->version_minor) != 1)) |
| 300 | return -ENODEV; |
| 301 | } |
| 302 | return 0; |
| 303 | } |
| 304 | EXPORT_SYMBOL(nd_btt_version); |
| 305 | |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 306 | static int __nd_btt_probe(struct nd_btt *nd_btt, |
| 307 | struct nd_namespace_common *ndns, struct btt_sb *btt_sb) |
| 308 | { |
Vishal Verma | 14e4945 | 2017-06-28 14:25:00 -0600 | [diff] [blame] | 309 | int rc; |
| 310 | |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 311 | if (!btt_sb || !ndns || !nd_btt) |
| 312 | return -ENODEV; |
| 313 | |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 314 | if (nvdimm_namespace_capacity(ndns) < SZ_16M) |
| 315 | return -ENXIO; |
| 316 | |
Vishal Verma | 14e4945 | 2017-06-28 14:25:00 -0600 | [diff] [blame] | 317 | rc = nd_btt_version(nd_btt, ndns, btt_sb); |
| 318 | if (rc < 0) |
| 319 | return rc; |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 320 | |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 321 | nd_btt->lbasize = le32_to_cpu(btt_sb->external_lbasize); |
| 322 | nd_btt->uuid = kmemdup(btt_sb->uuid, 16, GFP_KERNEL); |
| 323 | if (!nd_btt->uuid) |
| 324 | return -ENOMEM; |
| 325 | |
| 326 | __nd_device_register(&nd_btt->dev); |
| 327 | |
| 328 | return 0; |
| 329 | } |
| 330 | |
Dan Williams | 200c79d | 2016-03-22 00:22:16 -0700 | [diff] [blame] | 331 | int nd_btt_probe(struct device *dev, struct nd_namespace_common *ndns) |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 332 | { |
| 333 | int rc; |
Dan Williams | e32bc72 | 2016-03-17 18:23:09 -0700 | [diff] [blame] | 334 | struct device *btt_dev; |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 335 | struct btt_sb *btt_sb; |
| 336 | struct nd_region *nd_region = to_nd_region(ndns->dev.parent); |
| 337 | |
| 338 | if (ndns->force_raw) |
| 339 | return -ENODEV; |
| 340 | |
Dan Williams | b3fde74 | 2017-06-04 10:18:39 +0900 | [diff] [blame] | 341 | switch (ndns->claim_class) { |
| 342 | case NVDIMM_CCLASS_NONE: |
| 343 | case NVDIMM_CCLASS_BTT: |
Vishal Verma | 14e4945 | 2017-06-28 14:25:00 -0600 | [diff] [blame] | 344 | case NVDIMM_CCLASS_BTT2: |
Dan Williams | b3fde74 | 2017-06-04 10:18:39 +0900 | [diff] [blame] | 345 | break; |
| 346 | default: |
| 347 | return -ENODEV; |
| 348 | } |
| 349 | |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 350 | nvdimm_bus_lock(&ndns->dev); |
Dan Williams | e32bc72 | 2016-03-17 18:23:09 -0700 | [diff] [blame] | 351 | btt_dev = __nd_btt_create(nd_region, 0, NULL, ndns); |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 352 | nvdimm_bus_unlock(&ndns->dev); |
Dan Williams | e32bc72 | 2016-03-17 18:23:09 -0700 | [diff] [blame] | 353 | if (!btt_dev) |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 354 | return -ENOMEM; |
Dan Williams | e32bc72 | 2016-03-17 18:23:09 -0700 | [diff] [blame] | 355 | btt_sb = devm_kzalloc(dev, sizeof(*btt_sb), GFP_KERNEL); |
| 356 | rc = __nd_btt_probe(to_nd_btt(btt_dev), ndns, btt_sb); |
Dan Williams | 426824d | 2018-03-05 16:39:31 -0800 | [diff] [blame] | 357 | dev_dbg(dev, "btt: %s\n", rc == 0 ? dev_name(btt_dev) : "<none>"); |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 358 | if (rc < 0) { |
Dan Williams | e32bc72 | 2016-03-17 18:23:09 -0700 | [diff] [blame] | 359 | struct nd_btt *nd_btt = to_nd_btt(btt_dev); |
Dan Williams | e145574 | 2015-07-30 17:57:47 -0400 | [diff] [blame] | 360 | |
Dan Williams | 452bae0 | 2017-04-28 22:05:14 -0700 | [diff] [blame] | 361 | nd_detach_ndns(btt_dev, &nd_btt->ndns); |
Dan Williams | e32bc72 | 2016-03-17 18:23:09 -0700 | [diff] [blame] | 362 | put_device(btt_dev); |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | return rc; |
| 366 | } |
| 367 | EXPORT_SYMBOL(nd_btt_probe); |