Lines Matching refs:nd_region
33 struct nd_region *nd_region = to_nd_region(dev->parent); in namespace_pmem_release() local
36 ida_simple_remove(&nd_region->ns_ida, nspm->id); in namespace_pmem_release()
45 struct nd_region *nd_region = to_nd_region(dev->parent); in namespace_blk_release() local
48 ida_simple_remove(&nd_region->ns_ida, nsblk->id); in namespace_blk_release()
140 struct nd_region *nd_region = to_nd_region(dev->parent); in pmem_should_map_pages() local
146 if (!test_bit(ND_REGION_PAGEMAP, &nd_region->flags)) in pmem_should_map_pages()
188 struct nd_region *nd_region = to_nd_region(ndns->dev.parent); in nvdimm_namespace_disk_name() local
205 sprintf(name, "pmem%d.%d%s", nd_region->id, nsidx, in nvdimm_namespace_disk_name()
208 sprintf(name, "pmem%d%s", nd_region->id, in nvdimm_namespace_disk_name()
214 sprintf(name, "ndblk%d.%d%s", nd_region->id, nsblk->id, in nvdimm_namespace_disk_name()
247 struct nd_region *nd_region = to_nd_region(dev->parent); in nstype_show() local
249 return sprintf(buf, "%d\n", nd_region_to_nstype(nd_region)); in nstype_show()
301 struct nd_region *nd_region = to_nd_region(nsblk->common.dev.parent); in nd_namespace_blk_size() local
302 struct nd_mapping *nd_mapping = &nd_region->mapping[0]; in nd_namespace_blk_size()
319 struct nd_region *nd_region = to_nd_region(nsblk->common.dev.parent); in __nd_namespace_blk_validate() local
320 struct nd_mapping *nd_mapping = &nd_region->mapping[0]; in __nd_namespace_blk_validate()
376 static int nd_namespace_label_update(struct nd_region *nd_region, in nd_namespace_label_update() argument
397 return nd_pmem_namespace_label_update(nd_region, nspm, size); in nd_namespace_label_update()
407 return nd_blk_namespace_label_update(nd_region, nsblk, size); in nd_namespace_label_update()
415 struct nd_region *nd_region = to_nd_region(dev->parent); in alt_name_store() local
423 rc = nd_namespace_label_update(nd_region, dev); in alt_name_store()
451 static int scan_free(struct nd_region *nd_region, in scan_free() argument
473 nd_dbg_dpa(nd_region, ndd, res, "delete %d\n", rc); in scan_free()
491 nd_dbg_dpa(nd_region, ndd, res, "shrink %d\n", rc); in scan_free()
509 static int shrink_dpa_allocation(struct nd_region *nd_region, in shrink_dpa_allocation() argument
514 for (i = 0; i < nd_region->ndr_mappings; i++) { in shrink_dpa_allocation()
515 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; in shrink_dpa_allocation()
518 rc = scan_free(nd_region, nd_mapping, label_id, n); in shrink_dpa_allocation()
527 struct nd_region *nd_region, struct nd_mapping *nd_mapping, in init_dpa_allocation() argument
547 nd_dbg_dpa(nd_region, ndd, res, "init %d\n", rc); in init_dpa_allocation()
568 static void space_valid(struct nd_region *nd_region, struct nvdimm_drvdata *ndd, in space_valid() argument
583 struct nd_mapping *nd_mapping = &nd_region->mapping[0]; in space_valid()
591 WARN_ON(!is_nd_blk(&nd_region->dev)); in space_valid()
592 nvdimm_bus = walk_to_nvdimm_bus(&nd_region->dev); in space_valid()
619 static resource_size_t scan_allocate(struct nd_region *nd_region, in scan_allocate() argument
656 space_valid(nd_region, ndd, label_id, NULL, next, exist, in scan_allocate()
667 space_valid(nd_region, ndd, label_id, res, next, exist, in scan_allocate()
678 space_valid(nd_region, ndd, label_id, res, next, exist, in scan_allocate()
741 nd_dbg_dpa(nd_region, ndd, new_res, "%s(%d) %d\n", in scan_allocate()
767 return init_dpa_allocation(label_id, nd_region, nd_mapping, n); in scan_allocate()
771 static int merge_dpa(struct nd_region *nd_region, in merge_dpa() argument
792 nd_dbg_dpa(nd_region, ndd, res, "merge %d\n", rc); in merge_dpa()
805 struct nd_region *nd_region; in __reserve_free_pmem() local
812 nd_region = to_nd_region(dev); in __reserve_free_pmem()
813 if (nd_region->ndr_mappings == 0) in __reserve_free_pmem()
818 for (i = 0; i < nd_region->ndr_mappings; i++) { in __reserve_free_pmem()
819 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; in __reserve_free_pmem()
825 n = nd_pmem_available_dpa(nd_region, nd_mapping, &rem); in __reserve_free_pmem()
828 rem = scan_allocate(nd_region, nd_mapping, &label_id, n); in __reserve_free_pmem()
829 dev_WARN_ONCE(&nd_region->dev, rem, in __reserve_free_pmem()
876 static int grow_dpa_allocation(struct nd_region *nd_region, in grow_dpa_allocation() argument
879 struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(&nd_region->dev); in grow_dpa_allocation()
883 for (i = 0; i < nd_region->ndr_mappings; i++) { in grow_dpa_allocation()
884 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; in grow_dpa_allocation()
900 rem = scan_allocate(nd_region, nd_mapping, in grow_dpa_allocation()
910 dev_WARN_ONCE(&nd_region->dev, rem, in grow_dpa_allocation()
917 rc = merge_dpa(nd_region, nd_mapping, label_id); in grow_dpa_allocation()
925 static void nd_namespace_pmem_set_resource(struct nd_region *nd_region, in nd_namespace_pmem_set_resource() argument
937 struct nd_mapping *nd_mapping = &nd_region->mapping[0]; in nd_namespace_pmem_set_resource()
953 * nd_region->ndr_mappings; in nd_namespace_pmem_set_resource()
962 res->start = nd_region->ndr_start + offset; in nd_namespace_pmem_set_resource()
978 struct nd_region *nd_region = to_nd_region(dev->parent); in __size_store() local
1009 if (nd_region->ndr_mappings == 0) { in __size_store()
1014 div_u64_rem(val, SZ_4K * nd_region->ndr_mappings, &remainder); in __size_store()
1017 (SZ_4K * nd_region->ndr_mappings) / SZ_1K); in __size_store()
1022 for (i = 0; i < nd_region->ndr_mappings; i++) { in __size_store()
1023 nd_mapping = &nd_region->mapping[i]; in __size_store()
1035 available = nd_region_allocatable_dpa(nd_region); in __size_store()
1043 val = div_u64(val, nd_region->ndr_mappings); in __size_store()
1044 allocated = div_u64(allocated, nd_region->ndr_mappings); in __size_store()
1046 rc = shrink_dpa_allocation(nd_region, &label_id, in __size_store()
1049 rc = grow_dpa_allocation(nd_region, &label_id, val - allocated); in __size_store()
1057 nd_namespace_pmem_set_resource(nd_region, nspm, in __size_store()
1058 val * nd_region->ndr_mappings); in __size_store()
1067 if (val == 0 && id != 0 && nd_region->ns_seed != dev && !ndns->claim) in __size_store()
1076 struct nd_region *nd_region = to_nd_region(dev->parent); in size_store() local
1090 rc = nd_namespace_label_update(nd_region, dev); in size_store()
1152 struct nd_region *nd_region = to_nd_region(dev->parent); in nvdimm_namespace_locked() local
1154 for (i = 0; i < nd_region->ndr_mappings; i++) { in nvdimm_namespace_locked()
1155 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; in nvdimm_namespace_locked()
1208 static int namespace_update_uuid(struct nd_region *nd_region, in namespace_update_uuid() argument
1228 for (i = 0; i < nd_region->ndr_mappings; i++) { in namespace_update_uuid()
1229 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; in namespace_update_uuid()
1244 for (i = 0; i < nd_region->ndr_mappings; i++) { in namespace_update_uuid()
1245 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; in namespace_update_uuid()
1263 struct nd_region *nd_region = to_nd_region(dev->parent); in uuid_store() local
1287 rc = namespace_update_uuid(nd_region, dev, uuid, ns_uuid); in uuid_store()
1289 rc = nd_namespace_label_update(nd_region, dev); in uuid_store()
1351 struct nd_region *nd_region = to_nd_region(dev->parent); in sector_size_store() local
1376 rc = nd_namespace_label_update(nd_region, dev); in sector_size_store()
1389 struct nd_region *nd_region = to_nd_region(dev->parent); in dpa_extents_show() local
1412 for (i = 0; i < nd_region->ndr_mappings; i++) { in dpa_extents_show()
1413 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; in dpa_extents_show()
1430 struct nd_region *nd_region = to_nd_region(dev->parent); in btt_claim_class() local
1433 for (i = 0; i < nd_region->ndr_mappings; i++) { in btt_claim_class()
1434 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; in btt_claim_class()
1531 struct nd_region *nd_region = to_nd_region(dev->parent); in holder_class_store() local
1539 rc = nd_namespace_label_update(nd_region, dev); in holder_class_store()
1752 static struct device **create_namespace_io(struct nd_region *nd_region) in create_namespace_io() argument
1770 dev->parent = &nd_region->dev; in create_namespace_io()
1772 res->name = dev_name(&nd_region->dev); in create_namespace_io()
1774 res->start = nd_region->ndr_start; in create_namespace_io()
1775 res->end = res->start + nd_region->ndr_size - 1; in create_namespace_io()
1781 static bool has_uuid_at_pos(struct nd_region *nd_region, u8 *uuid, in has_uuid_at_pos() argument
1787 for (i = 0; i < nd_region->ndr_mappings; i++) { in has_uuid_at_pos()
1788 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; in has_uuid_at_pos()
1789 struct nd_interleave_set *nd_set = nd_region->nd_set; in has_uuid_at_pos()
1825 if (nlabel != nd_region->ndr_mappings) in has_uuid_at_pos()
1838 static int select_pmem_id(struct nd_region *nd_region, u8 *pmem_id) in select_pmem_id() argument
1845 for (i = 0; i < nd_region->ndr_mappings; i++) { in select_pmem_id()
1846 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; in select_pmem_id()
1879 dev_dbg(&nd_region->dev, "%s invalid label for %pUb\n", in select_pmem_id()
1896 static struct device *create_namespace_pmem(struct nd_region *nd_region, in create_namespace_pmem() argument
1900 u64 cookie = nd_region_interleave_set_cookie(nd_region, nsindex); in create_namespace_pmem()
1901 u64 altcookie = nd_region_interleave_set_altcookie(nd_region); in create_namespace_pmem()
1912 dev_dbg(&nd_region->dev, "invalid interleave-set-cookie\n"); in create_namespace_pmem()
1917 dev_dbg(&nd_region->dev, "invalid cookie in label: %pUb\n", in create_namespace_pmem()
1922 dev_dbg(&nd_region->dev, "valid altcookie in label: %pUb\n", in create_namespace_pmem()
1933 dev->parent = &nd_region->dev; in create_namespace_pmem()
1935 res->name = dev_name(&nd_region->dev); in create_namespace_pmem()
1938 for (i = 0; i < nd_region->ndr_mappings; i++) { in create_namespace_pmem()
1939 if (has_uuid_at_pos(nd_region, nd_label->uuid, cookie, i)) in create_namespace_pmem()
1941 if (has_uuid_at_pos(nd_region, nd_label->uuid, altcookie, i)) in create_namespace_pmem()
1946 if (i < nd_region->ndr_mappings) { in create_namespace_pmem()
1947 struct nvdimm *nvdimm = nd_region->mapping[i].nvdimm; in create_namespace_pmem()
1954 dev_err(&nd_region->dev, "%s missing label for %pUb\n", in create_namespace_pmem()
1968 rc = select_pmem_id(nd_region, nd_label->uuid); in create_namespace_pmem()
1973 for (i = 0; i < nd_region->ndr_mappings; i++) { in create_namespace_pmem()
1977 nd_mapping = &nd_region->mapping[i]; in create_namespace_pmem()
2008 nd_namespace_pmem_set_resource(nd_region, nspm, size); in create_namespace_pmem()
2015 dev_dbg(&nd_region->dev, "invalid label(s)\n"); in create_namespace_pmem()
2018 dev_dbg(&nd_region->dev, "label not found\n"); in create_namespace_pmem()
2021 dev_dbg(&nd_region->dev, "unexpected err: %d\n", rc); in create_namespace_pmem()
2027 struct resource *nsblk_add_resource(struct nd_region *nd_region, in nsblk_add_resource() argument
2050 static struct device *nd_namespace_blk_create(struct nd_region *nd_region) in nd_namespace_blk_create() argument
2055 if (!is_nd_blk(&nd_region->dev)) in nd_namespace_blk_create()
2064 nsblk->id = ida_simple_get(&nd_region->ns_ida, 0, 0, GFP_KERNEL); in nd_namespace_blk_create()
2069 dev_set_name(dev, "namespace%d.%d", nd_region->id, nsblk->id); in nd_namespace_blk_create()
2070 dev->parent = &nd_region->dev; in nd_namespace_blk_create()
2076 static struct device *nd_namespace_pmem_create(struct nd_region *nd_region) in nd_namespace_pmem_create() argument
2082 if (!is_memory(&nd_region->dev)) in nd_namespace_pmem_create()
2091 dev->parent = &nd_region->dev; in nd_namespace_pmem_create()
2093 res->name = dev_name(&nd_region->dev); in nd_namespace_pmem_create()
2096 nspm->id = ida_simple_get(&nd_region->ns_ida, 0, 0, GFP_KERNEL); in nd_namespace_pmem_create()
2101 dev_set_name(dev, "namespace%d.%d", nd_region->id, nspm->id); in nd_namespace_pmem_create()
2102 dev->parent = &nd_region->dev; in nd_namespace_pmem_create()
2104 nd_namespace_pmem_set_resource(nd_region, nspm, 0); in nd_namespace_pmem_create()
2109 void nd_region_create_ns_seed(struct nd_region *nd_region) in nd_region_create_ns_seed() argument
2111 WARN_ON(!is_nvdimm_bus_locked(&nd_region->dev)); in nd_region_create_ns_seed()
2113 if (nd_region_to_nstype(nd_region) == ND_DEVICE_NAMESPACE_IO) in nd_region_create_ns_seed()
2116 if (is_nd_blk(&nd_region->dev)) in nd_region_create_ns_seed()
2117 nd_region->ns_seed = nd_namespace_blk_create(nd_region); in nd_region_create_ns_seed()
2119 nd_region->ns_seed = nd_namespace_pmem_create(nd_region); in nd_region_create_ns_seed()
2125 if (!nd_region->ns_seed) in nd_region_create_ns_seed()
2126 dev_err(&nd_region->dev, "failed to create %s namespace\n", in nd_region_create_ns_seed()
2127 is_nd_blk(&nd_region->dev) ? "blk" : "pmem"); in nd_region_create_ns_seed()
2129 nd_device_register(nd_region->ns_seed); in nd_region_create_ns_seed()
2132 void nd_region_create_dax_seed(struct nd_region *nd_region) in nd_region_create_dax_seed() argument
2134 WARN_ON(!is_nvdimm_bus_locked(&nd_region->dev)); in nd_region_create_dax_seed()
2135 nd_region->dax_seed = nd_dax_create(nd_region); in nd_region_create_dax_seed()
2140 if (!nd_region->dax_seed) in nd_region_create_dax_seed()
2141 dev_err(&nd_region->dev, "failed to create dax namespace\n"); in nd_region_create_dax_seed()
2144 void nd_region_create_pfn_seed(struct nd_region *nd_region) in nd_region_create_pfn_seed() argument
2146 WARN_ON(!is_nvdimm_bus_locked(&nd_region->dev)); in nd_region_create_pfn_seed()
2147 nd_region->pfn_seed = nd_pfn_create(nd_region); in nd_region_create_pfn_seed()
2152 if (!nd_region->pfn_seed) in nd_region_create_pfn_seed()
2153 dev_err(&nd_region->dev, "failed to create pfn namespace\n"); in nd_region_create_pfn_seed()
2156 void nd_region_create_btt_seed(struct nd_region *nd_region) in nd_region_create_btt_seed() argument
2158 WARN_ON(!is_nvdimm_bus_locked(&nd_region->dev)); in nd_region_create_btt_seed()
2159 nd_region->btt_seed = nd_btt_create(nd_region); in nd_region_create_btt_seed()
2164 if (!nd_region->btt_seed) in nd_region_create_btt_seed()
2165 dev_err(&nd_region->dev, "failed to create btt namespace\n"); in nd_region_create_btt_seed()
2168 static int add_namespace_resource(struct nd_region *nd_region, in add_namespace_resource() argument
2172 struct nd_mapping *nd_mapping = &nd_region->mapping[0]; in add_namespace_resource()
2188 res = nsblk_add_resource(nd_region, ndd, in add_namespace_resource()
2193 nd_dbg_dpa(nd_region, ndd, res, "%d assign\n", count); in add_namespace_resource()
2195 dev_err(&nd_region->dev, in add_namespace_resource()
2206 static struct device *create_namespace_blk(struct nd_region *nd_region, in create_namespace_blk() argument
2210 struct nd_mapping *nd_mapping = &nd_region->mapping[0]; in create_namespace_blk()
2211 struct nd_interleave_set *nd_set = nd_region->nd_set; in create_namespace_blk()
2239 dev->parent = &nd_region->dev; in create_namespace_blk()
2253 res = nsblk_add_resource(nd_region, ndd, nsblk, in create_namespace_blk()
2257 nd_dbg_dpa(nd_region, ndd, res, "%d: assign\n", count); in create_namespace_blk()
2289 static struct device **scan_labels(struct nd_region *nd_region) in scan_labels() argument
2294 struct nd_mapping *nd_mapping = &nd_region->mapping[0]; in scan_labels()
2306 if (is_nd_blk(&nd_region->dev) in scan_labels()
2316 i = add_namespace_resource(nd_region, nd_label, devs, count); in scan_labels()
2328 if (is_nd_blk(&nd_region->dev)) in scan_labels()
2329 dev = create_namespace_blk(nd_region, nd_label, count); in scan_labels()
2335 dev = create_namespace_pmem(nd_region, nsindex, nd_label); in scan_labels()
2354 dev_dbg(&nd_region->dev, "discovered %d %s namespace%s\n", in scan_labels()
2355 count, is_nd_blk(&nd_region->dev) in scan_labels()
2365 if (is_nd_blk(&nd_region->dev)) { in scan_labels()
2381 nd_namespace_pmem_set_resource(nd_region, nspm, 0); in scan_labels()
2383 dev->parent = &nd_region->dev; in scan_labels()
2385 } else if (is_memory(&nd_region->dev)) { in scan_labels()
2387 for (i = 0; i < nd_region->ndr_mappings; i++) { in scan_labels()
2392 nd_mapping = &nd_region->mapping[i]; in scan_labels()
2417 if (is_nd_blk(&nd_region->dev)) in scan_labels()
2426 static struct device **create_namespaces(struct nd_region *nd_region) in create_namespaces() argument
2432 if (nd_region->ndr_mappings == 0) in create_namespaces()
2436 for (i = 0; i < nd_region->ndr_mappings; i++) { in create_namespaces()
2437 nd_mapping = &nd_region->mapping[i]; in create_namespaces()
2441 devs = scan_labels(nd_region); in create_namespaces()
2443 for (i = 0; i < nd_region->ndr_mappings; i++) { in create_namespaces()
2444 int reverse = nd_region->ndr_mappings - 1 - i; in create_namespaces()
2446 nd_mapping = &nd_region->mapping[reverse]; in create_namespaces()
2453 static int init_active_labels(struct nd_region *nd_region) in init_active_labels() argument
2457 for (i = 0; i < nd_region->ndr_mappings; i++) { in init_active_labels()
2458 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; in init_active_labels()
2476 dev_err(&nd_region->dev, "%s: is %s, failing probe\n", in init_active_labels()
2516 int nd_region_register_namespaces(struct nd_region *nd_region, int *err) in nd_region_register_namespaces() argument
2522 nvdimm_bus_lock(&nd_region->dev); in nd_region_register_namespaces()
2523 rc = init_active_labels(nd_region); in nd_region_register_namespaces()
2525 nvdimm_bus_unlock(&nd_region->dev); in nd_region_register_namespaces()
2529 type = nd_region_to_nstype(nd_region); in nd_region_register_namespaces()
2532 devs = create_namespace_io(nd_region); in nd_region_register_namespaces()
2536 devs = create_namespaces(nd_region); in nd_region_register_namespaces()
2541 nvdimm_bus_unlock(&nd_region->dev); in nd_region_register_namespaces()
2554 id = ida_simple_get(&nd_region->ns_ida, 0, 0, in nd_region_register_namespaces()
2561 id = ida_simple_get(&nd_region->ns_ida, 0, 0, in nd_region_register_namespaces()
2569 dev_set_name(dev, "namespace%d.%d", nd_region->id, id); in nd_region_register_namespaces()
2574 nd_region->ns_seed = devs[0]; in nd_region_register_namespaces()