Lines Matching refs:nd_region

27 	struct nd_region *nd_region = to_nd_region(dev->parent);  in namespace_pmem_release()  local
30 ida_simple_remove(&nd_region->ns_ida, nspm->id); in namespace_pmem_release()
90 struct nd_region *nd_region = to_nd_region(dev->parent); in pmem_should_map_pages() local
97 if (!test_bit(ND_REGION_PAGEMAP, &nd_region->flags)) in pmem_should_map_pages()
142 struct nd_region *nd_region = to_nd_region(ndns->dev.parent); in nvdimm_namespace_disk_name() local
159 sprintf(name, "pmem%d.%d%s", nd_region->id, nsidx, in nvdimm_namespace_disk_name()
162 sprintf(name, "pmem%d%s", nd_region->id, in nvdimm_namespace_disk_name()
186 struct nd_region *nd_region = to_nd_region(dev->parent); in nstype_show() local
188 return sprintf(buf, "%d\n", nd_region_to_nstype(nd_region)); in nstype_show()
233 static int nd_namespace_label_update(struct nd_region *nd_region, in nd_namespace_label_update() argument
254 return nd_pmem_namespace_label_update(nd_region, nspm, size); in nd_namespace_label_update()
262 struct nd_region *nd_region = to_nd_region(dev->parent); in alt_name_store() local
270 rc = nd_namespace_label_update(nd_region, dev); in alt_name_store()
294 static int scan_free(struct nd_region *nd_region, in scan_free() argument
314 nd_dbg_dpa(nd_region, ndd, res, "delete %d\n", rc); in scan_free()
323 nd_dbg_dpa(nd_region, ndd, res, "shrink %d\n", rc); in scan_free()
341 static int shrink_dpa_allocation(struct nd_region *nd_region, in shrink_dpa_allocation() argument
346 for (i = 0; i < nd_region->ndr_mappings; i++) { in shrink_dpa_allocation()
347 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; in shrink_dpa_allocation()
350 rc = scan_free(nd_region, nd_mapping, label_id, n); in shrink_dpa_allocation()
359 struct nd_region *nd_region, struct nd_mapping *nd_mapping, in init_dpa_allocation() argument
371 nd_dbg_dpa(nd_region, ndd, res, "init %d\n", rc); in init_dpa_allocation()
392 static void space_valid(struct nd_region *nd_region, struct nvdimm_drvdata *ndd, in space_valid() argument
400 align = nd_region->align / nd_region->ndr_mappings; in space_valid()
432 static resource_size_t scan_allocate(struct nd_region *nd_region, in scan_allocate() argument
468 space_valid(nd_region, ndd, label_id, NULL, next, exist, in scan_allocate()
479 space_valid(nd_region, ndd, label_id, res, next, exist, in scan_allocate()
490 space_valid(nd_region, ndd, label_id, res, next, exist, in scan_allocate()
549 nd_dbg_dpa(nd_region, ndd, new_res, "%s(%d) %d\n", in scan_allocate()
570 return init_dpa_allocation(label_id, nd_region, nd_mapping, n); in scan_allocate()
574 static int merge_dpa(struct nd_region *nd_region, in merge_dpa() argument
595 nd_dbg_dpa(nd_region, ndd, res, "merge %d\n", rc); in merge_dpa()
608 struct nd_region *nd_region; in __reserve_free_pmem() local
615 nd_region = to_nd_region(dev); in __reserve_free_pmem()
616 if (nd_region->ndr_mappings == 0) in __reserve_free_pmem()
621 for (i = 0; i < nd_region->ndr_mappings; i++) { in __reserve_free_pmem()
622 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; in __reserve_free_pmem()
628 n = nd_pmem_available_dpa(nd_region, nd_mapping); in __reserve_free_pmem()
631 rem = scan_allocate(nd_region, nd_mapping, &label_id, n); in __reserve_free_pmem()
632 dev_WARN_ONCE(&nd_region->dev, rem, in __reserve_free_pmem()
666 static int grow_dpa_allocation(struct nd_region *nd_region, in grow_dpa_allocation() argument
671 for (i = 0; i < nd_region->ndr_mappings; i++) { in grow_dpa_allocation()
672 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; in grow_dpa_allocation()
676 rem = scan_allocate(nd_region, nd_mapping, label_id, rem); in grow_dpa_allocation()
677 dev_WARN_ONCE(&nd_region->dev, rem, in grow_dpa_allocation()
684 rc = merge_dpa(nd_region, nd_mapping, label_id); in grow_dpa_allocation()
692 static void nd_namespace_pmem_set_resource(struct nd_region *nd_region, in nd_namespace_pmem_set_resource() argument
704 struct nd_mapping *nd_mapping = &nd_region->mapping[0]; in nd_namespace_pmem_set_resource()
720 * nd_region->ndr_mappings; in nd_namespace_pmem_set_resource()
729 res->start = nd_region->ndr_start + offset; in nd_namespace_pmem_set_resource()
746 struct nd_region *nd_region = to_nd_region(dev->parent); in __size_store() local
771 if (nd_region->ndr_mappings == 0) { in __size_store()
776 div_u64_rem(val, nd_region->align, &remainder); in __size_store()
779 nd_region->align / SZ_1K); in __size_store()
784 for (i = 0; i < nd_region->ndr_mappings; i++) { in __size_store()
785 nd_mapping = &nd_region->mapping[i]; in __size_store()
797 available = nd_region_allocatable_dpa(nd_region); in __size_store()
805 val = div_u64(val, nd_region->ndr_mappings); in __size_store()
806 allocated = div_u64(allocated, nd_region->ndr_mappings); in __size_store()
808 rc = shrink_dpa_allocation(nd_region, &label_id, in __size_store()
811 rc = grow_dpa_allocation(nd_region, &label_id, val - allocated); in __size_store()
819 nd_namespace_pmem_set_resource(nd_region, nspm, in __size_store()
820 val * nd_region->ndr_mappings); in __size_store()
829 if (val == 0 && id != 0 && nd_region->ns_seed != dev && !ndns->claim) in __size_store()
838 struct nd_region *nd_region = to_nd_region(dev->parent); in size_store() local
851 rc = nd_namespace_label_update(nd_region, dev); in size_store()
903 struct nd_region *nd_region = to_nd_region(dev->parent); in nvdimm_namespace_locked() local
905 for (i = 0; i < nd_region->ndr_mappings; i++) { in nvdimm_namespace_locked()
906 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; in nvdimm_namespace_locked()
955 static int namespace_update_uuid(struct nd_region *nd_region, in namespace_update_uuid() argument
975 for (i = 0; i < nd_region->ndr_mappings; i++) { in namespace_update_uuid()
976 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; in namespace_update_uuid()
991 for (i = 0; i < nd_region->ndr_mappings; i++) { in namespace_update_uuid()
992 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; in namespace_update_uuid()
1027 struct nd_region *nd_region = to_nd_region(dev->parent); in uuid_store() local
1047 rc = namespace_update_uuid(nd_region, dev, uuid, ns_uuid); in uuid_store()
1049 rc = nd_namespace_label_update(nd_region, dev); in uuid_store()
1101 struct nd_region *nd_region = to_nd_region(dev->parent); in sector_size_store() local
1121 rc = nd_namespace_label_update(nd_region, dev); in sector_size_store()
1134 struct nd_region *nd_region = to_nd_region(dev->parent); in dpa_extents_show() local
1152 for (i = 0; i < nd_region->ndr_mappings; i++) { in dpa_extents_show()
1153 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; in dpa_extents_show()
1170 struct nd_region *nd_region = to_nd_region(dev->parent); in btt_claim_class() local
1173 for (i = 0; i < nd_region->ndr_mappings; i++) { in btt_claim_class()
1174 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; in btt_claim_class()
1271 struct nd_region *nd_region = to_nd_region(dev->parent); in holder_class_store() local
1279 rc = nd_namespace_label_update(nd_region, dev); in holder_class_store()
1525 static struct device **create_namespace_io(struct nd_region *nd_region) in create_namespace_io() argument
1543 dev->parent = &nd_region->dev; in create_namespace_io()
1545 res->name = dev_name(&nd_region->dev); in create_namespace_io()
1547 res->start = nd_region->ndr_start; in create_namespace_io()
1548 res->end = res->start + nd_region->ndr_size - 1; in create_namespace_io()
1554 static bool has_uuid_at_pos(struct nd_region *nd_region, const uuid_t *uuid, in has_uuid_at_pos() argument
1560 for (i = 0; i < nd_region->ndr_mappings; i++) { in has_uuid_at_pos()
1561 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; in has_uuid_at_pos()
1562 struct nd_interleave_set *nd_set = nd_region->nd_set; in has_uuid_at_pos()
1590 if (!nsl_validate_nlabel(nd_region, ndd, nd_label)) in has_uuid_at_pos()
1603 static int select_pmem_id(struct nd_region *nd_region, const uuid_t *pmem_id) in select_pmem_id() argument
1610 for (i = 0; i < nd_region->ndr_mappings; i++) { in select_pmem_id()
1611 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; in select_pmem_id()
1644 dev_dbg(&nd_region->dev, "%s invalid label for %pUb\n", in select_pmem_id()
1662 static struct device *create_namespace_pmem(struct nd_region *nd_region, in create_namespace_pmem() argument
1669 u64 cookie = nd_region_interleave_set_cookie(nd_region, nsindex); in create_namespace_pmem()
1670 u64 altcookie = nd_region_interleave_set_altcookie(nd_region); in create_namespace_pmem()
1681 dev_dbg(&nd_region->dev, "invalid interleave-set-cookie\n"); in create_namespace_pmem()
1686 dev_dbg(&nd_region->dev, "invalid cookie in label: %pUb\n", in create_namespace_pmem()
1691 dev_dbg(&nd_region->dev, "valid altcookie in label: %pUb\n", in create_namespace_pmem()
1702 dev->parent = &nd_region->dev; in create_namespace_pmem()
1704 res->name = dev_name(&nd_region->dev); in create_namespace_pmem()
1707 for (i = 0; i < nd_region->ndr_mappings; i++) { in create_namespace_pmem()
1709 if (has_uuid_at_pos(nd_region, &uuid, cookie, i)) in create_namespace_pmem()
1711 if (has_uuid_at_pos(nd_region, &uuid, altcookie, i)) in create_namespace_pmem()
1716 if (i < nd_region->ndr_mappings) { in create_namespace_pmem()
1717 struct nvdimm *nvdimm = nd_region->mapping[i].nvdimm; in create_namespace_pmem()
1724 dev_err(&nd_region->dev, "%s missing label for %pUb\n", in create_namespace_pmem()
1736 rc = select_pmem_id(nd_region, &uuid); in create_namespace_pmem()
1741 for (i = 0; i < nd_region->ndr_mappings; i++) { in create_namespace_pmem()
1745 nd_mapping = &nd_region->mapping[i]; in create_namespace_pmem()
1774 nd_namespace_pmem_set_resource(nd_region, nspm, size); in create_namespace_pmem()
1781 dev_dbg(&nd_region->dev, "invalid label(s)\n"); in create_namespace_pmem()
1784 dev_dbg(&nd_region->dev, "label not found\n"); in create_namespace_pmem()
1787 dev_dbg(&nd_region->dev, "unexpected err: %d\n", rc); in create_namespace_pmem()
1793 static struct device *nd_namespace_pmem_create(struct nd_region *nd_region) in nd_namespace_pmem_create() argument
1799 if (!is_memory(&nd_region->dev)) in nd_namespace_pmem_create()
1808 dev->parent = &nd_region->dev; in nd_namespace_pmem_create()
1810 res->name = dev_name(&nd_region->dev); in nd_namespace_pmem_create()
1813 nspm->id = ida_simple_get(&nd_region->ns_ida, 0, 0, GFP_KERNEL); in nd_namespace_pmem_create()
1818 dev_set_name(dev, "namespace%d.%d", nd_region->id, nspm->id); in nd_namespace_pmem_create()
1819 nd_namespace_pmem_set_resource(nd_region, nspm, 0); in nd_namespace_pmem_create()
1826 void nd_region_create_ns_seed(struct nd_region *nd_region) in nd_region_create_ns_seed() argument
1828 WARN_ON(!is_nvdimm_bus_locked(&nd_region->dev)); in nd_region_create_ns_seed()
1830 if (nd_region_to_nstype(nd_region) == ND_DEVICE_NAMESPACE_IO) in nd_region_create_ns_seed()
1833 nd_region->ns_seed = nd_namespace_pmem_create(nd_region); in nd_region_create_ns_seed()
1839 if (!nd_region->ns_seed) in nd_region_create_ns_seed()
1840 dev_err(&nd_region->dev, "failed to create namespace\n"); in nd_region_create_ns_seed()
1842 device_initialize(nd_region->ns_seed); in nd_region_create_ns_seed()
1843 lockdep_set_class(&nd_region->ns_seed->mutex, in nd_region_create_ns_seed()
1845 nd_device_register(nd_region->ns_seed); in nd_region_create_ns_seed()
1849 void nd_region_create_dax_seed(struct nd_region *nd_region) in nd_region_create_dax_seed() argument
1851 WARN_ON(!is_nvdimm_bus_locked(&nd_region->dev)); in nd_region_create_dax_seed()
1852 nd_region->dax_seed = nd_dax_create(nd_region); in nd_region_create_dax_seed()
1857 if (!nd_region->dax_seed) in nd_region_create_dax_seed()
1858 dev_err(&nd_region->dev, "failed to create dax namespace\n"); in nd_region_create_dax_seed()
1861 void nd_region_create_pfn_seed(struct nd_region *nd_region) in nd_region_create_pfn_seed() argument
1863 WARN_ON(!is_nvdimm_bus_locked(&nd_region->dev)); in nd_region_create_pfn_seed()
1864 nd_region->pfn_seed = nd_pfn_create(nd_region); in nd_region_create_pfn_seed()
1869 if (!nd_region->pfn_seed) in nd_region_create_pfn_seed()
1870 dev_err(&nd_region->dev, "failed to create pfn namespace\n"); in nd_region_create_pfn_seed()
1873 void nd_region_create_btt_seed(struct nd_region *nd_region) in nd_region_create_btt_seed() argument
1875 WARN_ON(!is_nvdimm_bus_locked(&nd_region->dev)); in nd_region_create_btt_seed()
1876 nd_region->btt_seed = nd_btt_create(nd_region); in nd_region_create_btt_seed()
1881 if (!nd_region->btt_seed) in nd_region_create_btt_seed()
1882 dev_err(&nd_region->dev, "failed to create btt namespace\n"); in nd_region_create_btt_seed()
1885 static int add_namespace_resource(struct nd_region *nd_region, in add_namespace_resource() argument
1889 struct nd_mapping *nd_mapping = &nd_region->mapping[0]; in add_namespace_resource()
1903 dev_err(&nd_region->dev, in add_namespace_resource()
1927 static struct device **scan_labels(struct nd_region *nd_region) in scan_labels() argument
1932 struct nd_mapping *nd_mapping = &nd_region->mapping[0]; in scan_labels()
1949 i = add_namespace_resource(nd_region, nd_label, devs, count); in scan_labels()
1961 dev = create_namespace_pmem(nd_region, nd_mapping, nd_label); in scan_labels()
1978 dev_dbg(&nd_region->dev, "discovered %d namespace%s\n", count, in scan_labels()
1996 nd_namespace_pmem_set_resource(nd_region, nspm, 0); in scan_labels()
1997 dev->parent = &nd_region->dev; in scan_labels()
1999 } else if (is_memory(&nd_region->dev)) { in scan_labels()
2001 for (i = 0; i < nd_region->ndr_mappings; i++) { in scan_labels()
2006 nd_mapping = &nd_region->mapping[i]; in scan_labels()
2037 static struct device **create_namespaces(struct nd_region *nd_region) in create_namespaces() argument
2043 if (nd_region->ndr_mappings == 0) in create_namespaces()
2047 for (i = 0; i < nd_region->ndr_mappings; i++) { in create_namespaces()
2048 nd_mapping = &nd_region->mapping[i]; in create_namespaces()
2052 devs = scan_labels(nd_region); in create_namespaces()
2054 for (i = 0; i < nd_region->ndr_mappings; i++) { in create_namespaces()
2055 int reverse = nd_region->ndr_mappings - 1 - i; in create_namespaces()
2057 nd_mapping = &nd_region->mapping[reverse]; in create_namespaces()
2066 struct nd_region *nd_region = region; in deactivate_labels() local
2069 for (i = 0; i < nd_region->ndr_mappings; i++) { in deactivate_labels()
2070 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; in deactivate_labels()
2085 static int init_active_labels(struct nd_region *nd_region) in init_active_labels() argument
2089 for (i = 0; i < nd_region->ndr_mappings; i++) { in init_active_labels()
2090 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; in init_active_labels()
2108 dev_err(&nd_region->dev, "%s: is %s, failing probe\n", in init_active_labels()
2141 if (i < nd_region->ndr_mappings) in init_active_labels()
2146 deactivate_labels(nd_region); in init_active_labels()
2150 return devm_add_action_or_reset(&nd_region->dev, deactivate_labels, in init_active_labels()
2151 nd_region); in init_active_labels()
2154 int nd_region_register_namespaces(struct nd_region *nd_region, int *err) in nd_region_register_namespaces() argument
2160 nvdimm_bus_lock(&nd_region->dev); in nd_region_register_namespaces()
2161 rc = init_active_labels(nd_region); in nd_region_register_namespaces()
2163 nvdimm_bus_unlock(&nd_region->dev); in nd_region_register_namespaces()
2167 type = nd_region_to_nstype(nd_region); in nd_region_register_namespaces()
2170 devs = create_namespace_io(nd_region); in nd_region_register_namespaces()
2173 devs = create_namespaces(nd_region); in nd_region_register_namespaces()
2178 nvdimm_bus_unlock(&nd_region->dev); in nd_region_register_namespaces()
2191 id = ida_simple_get(&nd_region->ns_ida, 0, 0, in nd_region_register_namespaces()
2199 dev_set_name(dev, "namespace%d.%d", nd_region->id, id); in nd_region_register_namespaces()
2205 nd_region->ns_seed = devs[0]; in nd_region_register_namespaces()