Lines Matching +full:add +full:- +full:pmem
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright(c) 2013-2015 Intel Corporation. All rights reserved.
12 #include "nd-core.h"
13 #include "pmem.h"
27 struct nd_region *nd_region = to_nd_region(dev->parent); in namespace_pmem_release()
29 if (nspm->id >= 0) in namespace_pmem_release()
30 ida_free(&nd_region->ns_ida, nspm->id); in namespace_pmem_release()
31 kfree(nspm->alt_name); in namespace_pmem_release()
32 kfree(nspm->uuid); in namespace_pmem_release()
46 uuid2 = nspm->uuid; in is_uuid_busy()
50 uuid2 = nd_btt->uuid; in is_uuid_busy()
54 uuid2 = nd_pfn->uuid; in is_uuid_busy()
58 return -EBUSY; in is_uuid_busy()
71 * nd_is_uuid_unique - verify that no other namespace has @uuid
83 WARN_ON_ONCE(!is_nvdimm_bus_locked(&nvdimm_bus->dev)); in nd_is_uuid_unique()
84 if (device_for_each_child(&nvdimm_bus->dev, uuid, in nd_is_uuid_unique()
92 struct nd_region *nd_region = to_nd_region(dev->parent); in pmem_should_map_pages()
99 if (!test_bit(ND_REGION_PAGEMAP, &nd_region->flags)) in pmem_should_map_pages()
105 if (ndns->force_raw) in pmem_should_map_pages()
109 if (region_intersects(nsio->res.start, resource_size(&nsio->res), in pmem_should_map_pages()
120 if (is_namespace_pmem(&ndns->dev)) { in pmem_sector_size()
123 nspm = to_nd_namespace_pmem(&ndns->dev); in pmem_sector_size()
124 if (nspm->lbasize == 0 || nspm->lbasize == 512) in pmem_sector_size()
126 else if (nspm->lbasize == 4096) in pmem_sector_size()
129 dev_WARN(&ndns->dev, "unsupported sector size: %ld\n", in pmem_sector_size()
130 nspm->lbasize); in pmem_sector_size()
144 struct nd_region *nd_region = to_nd_region(ndns->dev.parent); in nvdimm_namespace_disk_name()
147 if (ndns->claim && is_nd_btt(ndns->claim)) in nvdimm_namespace_disk_name()
150 if (is_namespace_pmem(&ndns->dev) || is_namespace_io(&ndns->dev)) { in nvdimm_namespace_disk_name()
153 if (is_namespace_pmem(&ndns->dev)) { in nvdimm_namespace_disk_name()
156 nspm = to_nd_namespace_pmem(&ndns->dev); in nvdimm_namespace_disk_name()
157 nsidx = nspm->id; in nvdimm_namespace_disk_name()
161 sprintf(name, "pmem%d.%d%s", nd_region->id, nsidx, in nvdimm_namespace_disk_name()
164 sprintf(name, "pmem%d%s", nd_region->id, in nvdimm_namespace_disk_name()
179 return nspm->uuid; in nd_dev_to_uuid()
188 struct nd_region *nd_region = to_nd_region(dev->parent); in nstype_show()
203 ns_altname = &nspm->alt_name; in __alt_name_store()
205 return -ENXIO; in __alt_name_store()
207 if (dev->driver || to_ndns(dev)->claim) in __alt_name_store()
208 return -EBUSY; in __alt_name_store()
212 return -ENOMEM; in __alt_name_store()
216 rc = -EINVAL; in __alt_name_store()
222 rc = -ENOMEM; in __alt_name_store()
238 dev_WARN_ONCE(dev, dev->driver || to_ndns(dev)->claim, in nd_namespace_label_update()
240 if (dev->driver || to_ndns(dev)->claim) in nd_namespace_label_update()
249 resource_size_t size = resource_size(&nspm->nsio.res); in nd_namespace_label_update()
251 if (size == 0 && nspm->uuid) in nd_namespace_label_update()
253 else if (!nspm->uuid) in nd_namespace_label_update()
258 return -ENXIO; in nd_namespace_label_update()
264 struct nd_region *nd_region = to_nd_region(dev->parent); in alt_name_store()
288 ns_altname = nspm->alt_name; in alt_name_show()
290 return -ENXIO; in alt_name_show()
308 if (strcmp(res->name, label_id->id) == 0) in scan_free()
315 n -= resource_size(res); in scan_free()
322 rc = adjust_resource(res, res->start, resource_size(res) - n); in scan_free()
324 res->flags |= DPA_RESOURCE_ADJUSTED; in scan_free()
333 * shrink_dpa_allocation - for each dimm in region free n bytes for label_id
336 * @n: number of bytes per-dimm to release
343 * Returns: %0 on success on -errno on error
350 for (i = 0; i < nd_region->ndr_mappings; i++) { in shrink_dpa_allocation()
351 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; in shrink_dpa_allocation()
370 /* first resource allocation for this label-id or dimm */ in init_dpa_allocation()
371 res = nvdimm_allocate_dpa(ndd, label_id, nd_mapping->start, n); in init_dpa_allocation()
373 rc = -EBUSY; in init_dpa_allocation()
381 * space_valid() - validate free dpa space against constraints
388 * @n: range that must satisfied for pmem allocations
391 * BLK-space is valid as long as it does not precede a PMEM
392 * allocation in a given region. PMEM-space must be contiguous
394 * exists). If reserving PMEM any space is valid.
401 bool is_reserve = strcmp(label_id->id, "pmem-reserve") == 0; in space_valid()
404 align = nd_region->align / nd_region->ndr_mappings; in space_valid()
405 valid->start = ALIGN(valid->start, align); in space_valid()
406 valid->end = ALIGN_DOWN(valid->end + 1, align) - 1; in space_valid()
408 if (valid->start >= valid->end) in space_valid()
423 if (valid->start == exist->end + 1 in space_valid()
424 || valid->end == exist->start - 1) in space_valid()
429 valid->end = valid->start - 1; in space_valid()
440 resource_size_t mapping_end = nd_mapping->start + nd_mapping->size - 1; in scan_allocate()
447 if (strcmp(label_id->id, res->name) == 0) in scan_allocate()
450 valid.start = nd_mapping->start; in scan_allocate()
456 struct resource *next = res->sibling, *new_res = NULL; in scan_allocate()
463 if (res->start > mapping_end) in scan_allocate()
465 if (res->end < nd_mapping->start) in scan_allocate()
469 if (!first++ && res->start > nd_mapping->start) { in scan_allocate()
470 valid.start = nd_mapping->start; in scan_allocate()
471 valid.end = res->start - 1; in scan_allocate()
481 valid.start = res->start + resource_size(res); in scan_allocate()
482 valid.end = min(mapping_end, next->start - 1); in scan_allocate()
492 valid.start = res->start + resource_size(res); in scan_allocate()
506 if (strcmp(res->name, label_id->id) == 0) { in scan_allocate()
508 rc = adjust_resource(res, res->start - allocate, in scan_allocate()
515 if (strcmp(next->name, label_id->id) == 0) { in scan_allocate()
517 rc = adjust_resource(next, next->start in scan_allocate()
518 - allocate, resource_size(next) in scan_allocate()
522 } else if (strcmp(res->name, label_id->id) == 0) { in scan_allocate()
528 if (strcmp(res->name, label_id->id) == 0) in scan_allocate()
541 rc = -EBUSY; in scan_allocate()
544 rc = adjust_resource(res, res->start, resource_size(res) in scan_allocate()
547 res->flags |= DPA_RESOURCE_ADJUSTED; in scan_allocate()
559 n -= allocate; in scan_allocate()
584 if (strncmp("pmem", label_id->id, 4) == 0) in merge_dpa()
589 struct resource *next = res->sibling; in merge_dpa()
590 resource_size_t end = res->start + resource_size(res); in merge_dpa()
592 if (!next || strcmp(res->name, label_id->id) != 0 in merge_dpa()
593 || strcmp(next->name, label_id->id) != 0 in merge_dpa()
594 || end != next->start) in merge_dpa()
598 rc = adjust_resource(res, res->start, end - res->start); in merge_dpa()
602 res->flags |= DPA_RESOURCE_ADJUSTED; in merge_dpa()
620 if (nd_region->ndr_mappings == 0) in __reserve_free_pmem()
624 strcat(label_id.id, "pmem-reserve"); in __reserve_free_pmem()
625 for (i = 0; i < nd_region->ndr_mappings; i++) { in __reserve_free_pmem()
626 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; in __reserve_free_pmem()
629 if (nd_mapping->nvdimm != nvdimm) in __reserve_free_pmem()
636 dev_WARN_ONCE(&nd_region->dev, rem, in __reserve_free_pmem()
637 "pmem reserve underrun: %#llx of %#llx bytes\n", in __reserve_free_pmem()
638 (unsigned long long) n - rem, in __reserve_free_pmem()
640 return rem ? -ENXIO : 0; in __reserve_free_pmem()
653 if (strcmp(res->name, "pmem-reserve") == 0) in release_free_pmem()
658 * grow_dpa_allocation - for each dimm allocate n bytes for @label_id
661 * @n: number of bytes per-dimm to add to the existing allocation
664 * BLK-only available DPA free space, then consume PMEM-aliased DPA
665 * space starting at the highest DPA. For PMEM regions start
670 * Returns: %0 on success on -errno on error
677 for (i = 0; i < nd_region->ndr_mappings; i++) { in grow_dpa_allocation()
678 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; in grow_dpa_allocation()
683 dev_WARN_ONCE(&nd_region->dev, rem, in grow_dpa_allocation()
685 (unsigned long long) n - rem, in grow_dpa_allocation()
688 return -ENXIO; in grow_dpa_allocation()
701 struct resource *res = &nspm->nsio.res; in nd_namespace_pmem_set_resource()
704 if (size && !nspm->uuid) { in nd_namespace_pmem_set_resource()
709 if (size && nspm->uuid) { in nd_namespace_pmem_set_resource()
710 struct nd_mapping *nd_mapping = &nd_region->mapping[0]; in nd_namespace_pmem_set_resource()
720 nd_label_gen_id(&label_id, nspm->uuid, 0); in nd_namespace_pmem_set_resource()
724 if (strcmp(res->name, label_id.id) == 0) { in nd_namespace_pmem_set_resource()
725 offset = (res->start - nd_mapping->start) in nd_namespace_pmem_set_resource()
726 * nd_region->ndr_mappings; in nd_namespace_pmem_set_resource()
735 res->start = nd_region->ndr_start + offset; in nd_namespace_pmem_set_resource()
736 res->end = res->start + size - 1; in nd_namespace_pmem_set_resource()
752 struct nd_region *nd_region = to_nd_region(dev->parent); in __size_store()
758 int rc, i, id = -1; in __size_store()
761 if (dev->driver || ndns->claim) in __size_store()
762 return -EBUSY; in __size_store()
767 uuid = nspm->uuid; in __size_store()
768 id = nspm->id; in __size_store()
772 * We need a uuid for the allocation-label and dimm(s) on which in __size_store()
776 return -ENXIO; in __size_store()
777 if (nd_region->ndr_mappings == 0) { in __size_store()
779 return -ENXIO; in __size_store()
782 div_u64_rem(val, nd_region->align, &remainder); in __size_store()
785 nd_region->align / SZ_1K); in __size_store()
786 return -EINVAL; in __size_store()
790 for (i = 0; i < nd_region->ndr_mappings; i++) { in __size_store()
791 nd_mapping = &nd_region->mapping[i]; in __size_store()
799 return -ENXIO; in __size_store()
806 return -ENOSPC; in __size_store()
811 val = div_u64(val, nd_region->ndr_mappings); in __size_store()
812 allocated = div_u64(allocated, nd_region->ndr_mappings); in __size_store()
815 allocated - val); in __size_store()
817 rc = grow_dpa_allocation(nd_region, &label_id, val - allocated); in __size_store()
826 val * nd_region->ndr_mappings); in __size_store()
835 if (val == 0 && id != 0 && nd_region->ns_seed != dev && !ndns->claim) in __size_store()
844 struct nd_region *nd_region = to_nd_region(dev->parent); in size_store()
863 kfree(nspm->uuid); in size_store()
864 nspm->uuid = NULL; in size_store()
877 struct device *dev = &ndns->dev; in __nvdimm_namespace_capacity()
882 return resource_size(&nspm->nsio.res); in __nvdimm_namespace_capacity()
886 return resource_size(&nsio->res); in __nvdimm_namespace_capacity()
896 nvdimm_bus_lock(&ndns->dev); in nvdimm_namespace_capacity()
898 nvdimm_bus_unlock(&ndns->dev); in nvdimm_namespace_capacity()
908 struct device *dev = &ndns->dev; in nvdimm_namespace_locked()
909 struct nd_region *nd_region = to_nd_region(dev->parent); in nvdimm_namespace_locked()
911 for (i = 0; i < nd_region->ndr_mappings; i++) { in nvdimm_namespace_locked()
912 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; in nvdimm_namespace_locked()
913 struct nvdimm *nvdimm = nd_mapping->nvdimm; in nvdimm_namespace_locked()
915 if (test_bit(NDD_LOCKED, &nvdimm->flags)) { in nvdimm_namespace_locked()
937 return nspm->uuid; in namespace_to_uuid()
939 return ERR_PTR(-ENXIO); in namespace_to_uuid()
955 * namespace_update_uuid - check for a unique uuid and whether we're "renaming"
961 * Returns: %0 on success on -errno on error
972 return -EINVAL; in namespace_update_uuid()
983 for (i = 0; i < nd_region->ndr_mappings; i++) { in namespace_update_uuid()
984 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; in namespace_update_uuid()
993 if (list_empty(&nd_mapping->labels)) in namespace_update_uuid()
994 return -EBUSY; in namespace_update_uuid()
999 for (i = 0; i < nd_region->ndr_mappings; i++) { in namespace_update_uuid()
1000 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; in namespace_update_uuid()
1006 if (strcmp(res->name, old_label_id.id) == 0) in namespace_update_uuid()
1007 sprintf((void *) res->name, "%s", in namespace_update_uuid()
1010 mutex_lock(&nd_mapping->lock); in namespace_update_uuid()
1011 list_for_each_entry(label_ent, &nd_mapping->labels, list) { in namespace_update_uuid()
1012 struct nd_namespace_label *nd_label = label_ent->label; in namespace_update_uuid()
1022 set_bit(ND_LABEL_REAP, &label_ent->flags); in namespace_update_uuid()
1024 mutex_unlock(&nd_mapping->lock); in namespace_update_uuid()
1035 struct nd_region *nd_region = to_nd_region(dev->parent); in uuid_store()
1043 ns_uuid = &nspm->uuid; in uuid_store()
1045 return -ENXIO; in uuid_store()
1050 if (to_ndns(dev)->claim) in uuid_store()
1051 rc = -EBUSY; in uuid_store()
1061 buf[len - 1] == '\n' ? "" : "\n"); in uuid_store()
1077 res = &nspm->nsio.res; in resource_show()
1081 res = &nsio->res; in resource_show()
1083 return -ENXIO; in resource_show()
1087 return -ENXIO; in resource_show()
1088 return sprintf(buf, "%#llx\n", (unsigned long long) res->start); in resource_show()
1100 return nd_size_select_show(nspm->lbasize, in sector_size_show()
1103 return -ENXIO; in sector_size_show()
1109 struct nd_region *nd_region = to_nd_region(dev->parent); in sector_size_store()
1117 lbasize = &nspm->lbasize; in sector_size_store()
1120 return -ENXIO; in sector_size_store()
1124 if (to_ndns(dev)->claim) in sector_size_store()
1125 rc = -EBUSY; in sector_size_store()
1131 buf, buf[len - 1] == '\n' ? "" : "\n"); in sector_size_store()
1142 struct nd_region *nd_region = to_nd_region(dev->parent); in dpa_extents_show()
1152 uuid = nspm->uuid; in dpa_extents_show()
1160 for (i = 0; i < nd_region->ndr_mappings; i++) { in dpa_extents_show()
1161 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; in dpa_extents_show()
1166 if (strcmp(res->name, label_id.id) == 0) in dpa_extents_show()
1178 struct nd_region *nd_region = to_nd_region(dev->parent); in btt_claim_class()
1181 for (i = 0; i < nd_region->ndr_mappings; i++) { in btt_claim_class()
1182 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; in btt_claim_class()
1195 nsindex = to_namespace_index(ndd, ndd->ns_current); in btt_claim_class()
1200 if (__le16_to_cpu(nsindex->major) == 1 in btt_claim_class()
1201 && __le16_to_cpu(nsindex->minor) == 1) in btt_claim_class()
1233 return -ENXIO; in btt_claim_class()
1244 rc = sprintf(buf, "%s\n", ndns->claim ? dev_name(ndns->claim) : ""); in holder_show()
1255 if (dev->driver || ndns->claim) in __holder_class_store()
1256 return -EBUSY; in __holder_class_store()
1263 ndns->claim_class = rc; in __holder_class_store()
1265 ndns->claim_class = NVDIMM_CCLASS_PFN; in __holder_class_store()
1267 ndns->claim_class = NVDIMM_CCLASS_DAX; in __holder_class_store()
1269 ndns->claim_class = NVDIMM_CCLASS_NONE; in __holder_class_store()
1271 return -EINVAL; in __holder_class_store()
1279 struct nd_region *nd_region = to_nd_region(dev->parent); in holder_class_store()
1302 if (ndns->claim_class == NVDIMM_CCLASS_NONE) in holder_class_show()
1304 else if ((ndns->claim_class == NVDIMM_CCLASS_BTT) || in holder_class_show()
1305 (ndns->claim_class == NVDIMM_CCLASS_BTT2)) in holder_class_show()
1307 else if (ndns->claim_class == NVDIMM_CCLASS_PFN) in holder_class_show()
1309 else if (ndns->claim_class == NVDIMM_CCLASS_DAX) in holder_class_show()
1328 claim = ndns->claim; in mode_show()
1355 to_ndns(dev)->force_raw = force_raw; in force_raw_store()
1362 return sprintf(buf, "%d\n", to_ndns(dev)->force_raw); in force_raw_show()
1390 return a->mode; in namespace_visible()
1398 return a->mode; in namespace_visible()
1429 return dev ? dev->type == &namespace_pmem_device_type : false; in is_namespace_pmem()
1434 return dev ? dev->type == &namespace_io_device_type : false; in is_namespace_io()
1447 ndns = nd_btt->ndns; in nvdimm_namespace_common_probe()
1449 ndns = nd_pfn->ndns; in nvdimm_namespace_common_probe()
1451 ndns = nd_dax->nd_pfn.ndns; in nvdimm_namespace_common_probe()
1454 return ERR_PTR(-ENODEV); in nvdimm_namespace_common_probe()
1457 * Flush any in-progess probes / removals in the driver in nvdimm_namespace_common_probe()
1460 device_lock(&ndns->dev); in nvdimm_namespace_common_probe()
1461 device_unlock(&ndns->dev); in nvdimm_namespace_common_probe()
1462 if (ndns->dev.driver) { in nvdimm_namespace_common_probe()
1463 dev_dbg(&ndns->dev, "is active, can't bind %s\n", in nvdimm_namespace_common_probe()
1465 return ERR_PTR(-EBUSY); in nvdimm_namespace_common_probe()
1467 if (dev_WARN_ONCE(&ndns->dev, ndns->claim != dev, in nvdimm_namespace_common_probe()
1470 dev_name(ndns->claim))) in nvdimm_namespace_common_probe()
1471 return ERR_PTR(-ENXIO); in nvdimm_namespace_common_probe()
1474 if (ndns->claim) { in nvdimm_namespace_common_probe()
1476 dev_name(ndns->claim)); in nvdimm_namespace_common_probe()
1478 return ERR_PTR(-ENXIO); in nvdimm_namespace_common_probe()
1483 return ERR_PTR(-EACCES); in nvdimm_namespace_common_probe()
1487 dev_dbg(&ndns->dev, "%pa, too small must be at least %#x\n", in nvdimm_namespace_common_probe()
1489 return ERR_PTR(-ENODEV); in nvdimm_namespace_common_probe()
1498 struct nd_namespace_io *nsio = to_nd_namespace_io(&ndns->dev); in nvdimm_namespace_common_probe()
1499 struct resource *res = &nsio->res; in nvdimm_namespace_common_probe()
1501 if (!IS_ALIGNED(res->start | (res->end + 1), in nvdimm_namespace_common_probe()
1503 dev_err(&ndns->dev, "%pr misaligned, unable to map\n", res); in nvdimm_namespace_common_probe()
1504 return ERR_PTR(-EOPNOTSUPP); in nvdimm_namespace_common_probe()
1508 if (is_namespace_pmem(&ndns->dev)) { in nvdimm_namespace_common_probe()
1511 nspm = to_nd_namespace_pmem(&ndns->dev); in nvdimm_namespace_common_probe()
1512 if (uuid_not_set(nspm->uuid, &ndns->dev, __func__)) in nvdimm_namespace_common_probe()
1513 return ERR_PTR(-ENODEV); in nvdimm_namespace_common_probe()
1523 return devm_nsio_enable(dev, to_nd_namespace_io(&ndns->dev), size); in devm_namespace_enable()
1529 devm_nsio_disable(dev, to_nd_namespace_io(&ndns->dev)); in devm_namespace_disable()
1549 dev = &nsio->common.dev; in create_namespace_io()
1550 dev->type = &namespace_io_device_type; in create_namespace_io()
1551 dev->parent = &nd_region->dev; in create_namespace_io()
1552 res = &nsio->res; in create_namespace_io()
1553 res->name = dev_name(&nd_region->dev); in create_namespace_io()
1554 res->flags = IORESOURCE_MEM; in create_namespace_io()
1555 res->start = nd_region->ndr_start; in create_namespace_io()
1556 res->end = res->start + nd_region->ndr_size - 1; in create_namespace_io()
1568 for (i = 0; i < nd_region->ndr_mappings; i++) { in has_uuid_at_pos()
1569 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; in has_uuid_at_pos()
1570 struct nd_interleave_set *nd_set = nd_region->nd_set; in has_uuid_at_pos()
1575 list_for_each_entry(label_ent, &nd_mapping->labels, list) { in has_uuid_at_pos()
1576 struct nd_namespace_label *nd_label = label_ent->label; in has_uuid_at_pos()
1590 &nd_set->type_guid)) in has_uuid_at_pos()
1594 dev_dbg(ndd->dev, "duplicate entry for uuid\n"); in has_uuid_at_pos()
1616 return -ENODEV; in select_pmem_id()
1618 for (i = 0; i < nd_region->ndr_mappings; i++) { in select_pmem_id()
1619 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; in select_pmem_id()
1625 lockdep_assert_held(&nd_mapping->lock); in select_pmem_id()
1626 list_for_each_entry(label_ent, &nd_mapping->labels, list) { in select_pmem_id()
1627 nd_label = label_ent->label; in select_pmem_id()
1637 return -EINVAL; in select_pmem_id()
1644 hw_start = nd_mapping->start; in select_pmem_id()
1645 hw_end = hw_start + nd_mapping->size; in select_pmem_id()
1652 dev_dbg(&nd_region->dev, "%s invalid label for %pUb\n", in select_pmem_id()
1653 dev_name(ndd->dev), in select_pmem_id()
1655 return -EINVAL; in select_pmem_id()
1659 list_move(&label_ent->list, &nd_mapping->labels); in select_pmem_id()
1665 * create_namespace_pmem - validate interleave set labelling, retrieve label0
1667 * @nd_mapping: container of dpa-resource-root + labels
1668 * @nd_label: target pmem namespace label to evaluate
1670 * Returns: the created &struct device on success or ERR_PTR(-errno) on error
1678 to_namespace_index(ndd, ndd->ns_current); in create_namespace_pmem()
1691 dev_dbg(&nd_region->dev, "invalid interleave-set-cookie\n"); in create_namespace_pmem()
1692 return ERR_PTR(-ENXIO); in create_namespace_pmem()
1696 dev_dbg(&nd_region->dev, "invalid cookie in label: %pUb\n", in create_namespace_pmem()
1699 return ERR_PTR(-EAGAIN); in create_namespace_pmem()
1701 dev_dbg(&nd_region->dev, "valid altcookie in label: %pUb\n", in create_namespace_pmem()
1707 return ERR_PTR(-ENOMEM); in create_namespace_pmem()
1709 nspm->id = -1; in create_namespace_pmem()
1710 dev = &nspm->nsio.common.dev; in create_namespace_pmem()
1711 dev->type = &namespace_pmem_device_type; in create_namespace_pmem()
1712 dev->parent = &nd_region->dev; in create_namespace_pmem()
1713 res = &nspm->nsio.res; in create_namespace_pmem()
1714 res->name = dev_name(&nd_region->dev); in create_namespace_pmem()
1715 res->flags = IORESOURCE_MEM; in create_namespace_pmem()
1717 for (i = 0; i < nd_region->ndr_mappings; i++) { in create_namespace_pmem()
1726 if (i < nd_region->ndr_mappings) { in create_namespace_pmem()
1727 struct nvdimm *nvdimm = nd_region->mapping[i].nvdimm; in create_namespace_pmem()
1731 * position (from 0 to nd_region->ndr_mappings - 1), or if we in create_namespace_pmem()
1734 dev_err(&nd_region->dev, "%s missing label for %pUb\n", in create_namespace_pmem()
1736 rc = -EINVAL; in create_namespace_pmem()
1741 * Fix up each mapping's 'labels' to have the validated pmem label for in create_namespace_pmem()
1743 * check that the namespace aligns with interleave-set. in create_namespace_pmem()
1751 for (i = 0; i < nd_region->ndr_mappings; i++) { in create_namespace_pmem()
1755 nd_mapping = &nd_region->mapping[i]; in create_namespace_pmem()
1756 label_ent = list_first_entry_or_null(&nd_mapping->labels, in create_namespace_pmem()
1758 label0 = label_ent ? label_ent->label : NULL; in create_namespace_pmem()
1769 WARN_ON(nspm->alt_name || nspm->uuid); in create_namespace_pmem()
1770 nspm->alt_name = kmemdup(nsl_ref_name(ndd, label0), in create_namespace_pmem()
1773 nspm->uuid = kmemdup(&uuid, sizeof(uuid_t), GFP_KERNEL); in create_namespace_pmem()
1774 nspm->lbasize = nsl_get_lbasize(ndd, label0); in create_namespace_pmem()
1775 nspm->nsio.common.claim_class = in create_namespace_pmem()
1779 if (!nspm->alt_name || !nspm->uuid) { in create_namespace_pmem()
1780 rc = -ENOMEM; in create_namespace_pmem()
1790 case -EINVAL: in create_namespace_pmem()
1791 dev_dbg(&nd_region->dev, "invalid label(s)\n"); in create_namespace_pmem()
1793 case -ENODEV: in create_namespace_pmem()
1794 dev_dbg(&nd_region->dev, "label not found\n"); in create_namespace_pmem()
1797 dev_dbg(&nd_region->dev, "unexpected err: %d\n", rc); in create_namespace_pmem()
1809 if (!is_memory(&nd_region->dev)) in nd_namespace_pmem_create()
1816 dev = &nspm->nsio.common.dev; in nd_namespace_pmem_create()
1817 dev->type = &namespace_pmem_device_type; in nd_namespace_pmem_create()
1818 dev->parent = &nd_region->dev; in nd_namespace_pmem_create()
1819 res = &nspm->nsio.res; in nd_namespace_pmem_create()
1820 res->name = dev_name(&nd_region->dev); in nd_namespace_pmem_create()
1821 res->flags = IORESOURCE_MEM; in nd_namespace_pmem_create()
1823 nspm->id = ida_alloc(&nd_region->ns_ida, GFP_KERNEL); in nd_namespace_pmem_create()
1824 if (nspm->id < 0) { in nd_namespace_pmem_create()
1828 dev_set_name(dev, "namespace%d.%d", nd_region->id, nspm->id); in nd_namespace_pmem_create()
1838 WARN_ON(!is_nvdimm_bus_locked(&nd_region->dev)); in nd_region_create_ns_seed()
1843 nd_region->ns_seed = nd_namespace_pmem_create(nd_region); in nd_region_create_ns_seed()
1849 if (!nd_region->ns_seed) in nd_region_create_ns_seed()
1850 dev_err(&nd_region->dev, "failed to create namespace\n"); in nd_region_create_ns_seed()
1852 device_initialize(nd_region->ns_seed); in nd_region_create_ns_seed()
1853 lockdep_set_class(&nd_region->ns_seed->mutex, in nd_region_create_ns_seed()
1855 nd_device_register(nd_region->ns_seed); in nd_region_create_ns_seed()
1861 WARN_ON(!is_nvdimm_bus_locked(&nd_region->dev)); in nd_region_create_dax_seed()
1862 nd_region->dax_seed = nd_dax_create(nd_region); in nd_region_create_dax_seed()
1867 if (!nd_region->dax_seed) in nd_region_create_dax_seed()
1868 dev_err(&nd_region->dev, "failed to create dax namespace\n"); in nd_region_create_dax_seed()
1873 WARN_ON(!is_nvdimm_bus_locked(&nd_region->dev)); in nd_region_create_pfn_seed()
1874 nd_region->pfn_seed = nd_pfn_create(nd_region); in nd_region_create_pfn_seed()
1879 if (!nd_region->pfn_seed) in nd_region_create_pfn_seed()
1880 dev_err(&nd_region->dev, "failed to create pfn namespace\n"); in nd_region_create_pfn_seed()
1885 WARN_ON(!is_nvdimm_bus_locked(&nd_region->dev)); in nd_region_create_btt_seed()
1886 nd_region->btt_seed = nd_btt_create(nd_region); in nd_region_create_btt_seed()
1891 if (!nd_region->btt_seed) in nd_region_create_btt_seed()
1892 dev_err(&nd_region->dev, "failed to create btt namespace\n"); in nd_region_create_btt_seed()
1899 struct nd_mapping *nd_mapping = &nd_region->mapping[0]; in add_namespace_resource()
1913 dev_err(&nd_region->dev, in add_namespace_resource()
1915 return -ENXIO; in add_namespace_resource()
1933 return memcmp(&nspm_a->nsio.res.start, &nspm_b->nsio.res.start, in cmp_dpa()
1942 struct nd_mapping *nd_mapping = &nd_region->mapping[0]; in scan_labels()
1944 resource_size_t map_end = nd_mapping->start + nd_mapping->size - 1; in scan_labels()
1947 list_for_each_entry_safe(label_ent, e, &nd_mapping->labels, list) { in scan_labels()
1948 struct nd_namespace_label *nd_label = label_ent->label; in scan_labels()
1955 if (nsl_get_dpa(ndd, nd_label) < nd_mapping->start || in scan_labels()
1974 case -EAGAIN: in scan_labels()
1977 case -ENODEV: in scan_labels()
1988 dev_dbg(&nd_region->dev, "discovered %d namespace%s\n", count, in scan_labels()
1994 /* Publish a zero-sized namespace for userspace to configure. */ in scan_labels()
2004 dev = &nspm->nsio.common.dev; in scan_labels()
2005 dev->type = &namespace_pmem_device_type; in scan_labels()
2007 dev->parent = &nd_region->dev; in scan_labels()
2009 } else if (is_memory(&nd_region->dev)) { in scan_labels()
2011 for (i = 0; i < nd_region->ndr_mappings; i++) { in scan_labels()
2016 nd_mapping = &nd_region->mapping[i]; in scan_labels()
2017 if (list_empty(&nd_mapping->labels)) { in scan_labels()
2023 list_for_each_safe(l, e, &nd_mapping->labels) { in scan_labels()
2024 if (!j--) in scan_labels()
2029 list_splice_init(&list, &nd_mapping->labels); in scan_labels()
2053 if (nd_region->ndr_mappings == 0) in create_namespaces()
2057 for (i = 0; i < nd_region->ndr_mappings; i++) { in create_namespaces()
2058 nd_mapping = &nd_region->mapping[i]; in create_namespaces()
2059 mutex_lock_nested(&nd_mapping->lock, i); in create_namespaces()
2064 for (i = 0; i < nd_region->ndr_mappings; i++) { in create_namespaces()
2065 int reverse = nd_region->ndr_mappings - 1 - i; in create_namespaces()
2067 nd_mapping = &nd_region->mapping[reverse]; in create_namespaces()
2068 mutex_unlock(&nd_mapping->lock); in create_namespaces()
2079 for (i = 0; i < nd_region->ndr_mappings; i++) { in deactivate_labels()
2080 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; in deactivate_labels()
2081 struct nvdimm_drvdata *ndd = nd_mapping->ndd; in deactivate_labels()
2082 struct nvdimm *nvdimm = nd_mapping->nvdimm; in deactivate_labels()
2084 mutex_lock(&nd_mapping->lock); in deactivate_labels()
2086 mutex_unlock(&nd_mapping->lock); in deactivate_labels()
2089 nd_mapping->ndd = NULL; in deactivate_labels()
2091 atomic_dec(&nvdimm->busy); in deactivate_labels()
2099 for (i = 0; i < nd_region->ndr_mappings; i++) { in init_active_labels()
2100 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; in init_active_labels()
2102 struct nvdimm *nvdimm = nd_mapping->nvdimm; in init_active_labels()
2111 if (test_bit(NDD_LOCKED, &nvdimm->flags)) in init_active_labels()
2113 else if (test_bit(NDD_LABELING, &nvdimm->flags)) in init_active_labels()
2118 dev_err(&nd_region->dev, "%s: is %s, failing probe\n", in init_active_labels()
2119 dev_name(&nd_mapping->nvdimm->dev), in init_active_labels()
2120 test_bit(NDD_LOCKED, &nvdimm->flags) in init_active_labels()
2122 rc = -ENXIO; in init_active_labels()
2125 nd_mapping->ndd = ndd; in init_active_labels()
2126 atomic_inc(&nvdimm->busy); in init_active_labels()
2130 dev_dbg(ndd->dev, "count: %d\n", count); in init_active_labels()
2140 label_ent->label = label; in init_active_labels()
2142 mutex_lock(&nd_mapping->lock); in init_active_labels()
2143 list_add_tail(&label_ent->list, &nd_mapping->labels); in init_active_labels()
2144 mutex_unlock(&nd_mapping->lock); in init_active_labels()
2151 if (i < nd_region->ndr_mappings) in init_active_labels()
2152 rc = -ENOMEM; in init_active_labels()
2160 return devm_add_action_or_reset(&nd_region->dev, deactivate_labels, in init_active_labels()
2170 nvdimm_bus_lock(&nd_region->dev); in nd_region_register_namespaces()
2173 nvdimm_bus_unlock(&nd_region->dev); in nd_region_register_namespaces()
2188 nvdimm_bus_unlock(&nd_region->dev); in nd_region_register_namespaces()
2191 return -ENODEV; in nd_region_register_namespaces()
2201 id = ida_alloc(&nd_region->ns_ida, GFP_KERNEL); in nd_region_register_namespaces()
2202 nspm->id = id; in nd_region_register_namespaces()
2208 dev_set_name(dev, "namespace%d.%d", nd_region->id, id); in nd_region_register_namespaces()
2210 lockdep_set_class(&dev->mutex, &nvdimm_namespace_key); in nd_region_register_namespaces()
2214 nd_region->ns_seed = devs[0]; in nd_region_register_namespaces()
2225 *err = j - i; in nd_region_register_namespaces()
2231 rc = -ENODEV; in nd_region_register_namespaces()
2235 if (rc == -ENODEV) in nd_region_register_namespaces()