Linux Audio

Check our new training course

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