Lines Matching refs:nd_pfn
21 struct nd_pfn *nd_pfn = to_nd_pfn(dev); in nd_pfn_release() local
24 nd_detach_ndns(&nd_pfn->dev, &nd_pfn->ndns); in nd_pfn_release()
25 ida_simple_remove(&nd_region->pfn_ida, nd_pfn->id); in nd_pfn_release()
26 kfree(nd_pfn->uuid); in nd_pfn_release()
27 kfree(nd_pfn); in nd_pfn_release()
30 struct nd_pfn *to_nd_pfn(struct device *dev) in to_nd_pfn()
32 struct nd_pfn *nd_pfn = container_of(dev, struct nd_pfn, dev); in to_nd_pfn() local
35 return nd_pfn; in to_nd_pfn()
42 struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev); in mode_show() local
44 switch (nd_pfn->mode) { in mode_show()
57 struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev); in mode_store() local
69 nd_pfn->mode = PFN_MODE_PMEM; in mode_store()
72 nd_pfn->mode = PFN_MODE_RAM; in mode_store()
75 nd_pfn->mode = PFN_MODE_NONE; in mode_store()
91 struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev); in align_show() local
93 return sprintf(buf, "%ld\n", nd_pfn->align); in align_show()
124 struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev); in align_store() local
130 rc = nd_size_select_store(dev, buf, &nd_pfn->align, in align_store()
144 struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev); in uuid_show() local
146 if (nd_pfn->uuid) in uuid_show()
147 return sprintf(buf, "%pUb\n", nd_pfn->uuid); in uuid_show()
154 struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev); in uuid_store() local
158 rc = nd_uuid_store(dev, &nd_pfn->uuid, buf, len); in uuid_store()
170 struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev); in namespace_show() local
174 rc = sprintf(buf, "%s\n", nd_pfn->ndns in namespace_show()
175 ? dev_name(&nd_pfn->ndns->dev) : ""); in namespace_show()
183 struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev); in namespace_store() local
188 rc = nd_namespace_store(dev, &nd_pfn->ndns, buf, len); in namespace_store()
201 struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev); in resource_show() local
206 struct nd_pfn_sb *pfn_sb = nd_pfn->pfn_sb; in resource_show()
208 struct nd_namespace_common *ndns = nd_pfn->ndns; in resource_show()
227 struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev); in size_show() local
232 struct nd_pfn_sb *pfn_sb = nd_pfn->pfn_sb; in size_show()
234 struct nd_namespace_common *ndns = nd_pfn->ndns; in size_show()
298 struct device *nd_pfn_devinit(struct nd_pfn *nd_pfn, in nd_pfn_devinit() argument
303 if (!nd_pfn) in nd_pfn_devinit()
306 nd_pfn->mode = PFN_MODE_NONE; in nd_pfn_devinit()
307 nd_pfn->align = nd_pfn_default_alignment(); in nd_pfn_devinit()
308 dev = &nd_pfn->dev; in nd_pfn_devinit()
309 device_initialize(&nd_pfn->dev); in nd_pfn_devinit()
310 lockdep_set_class(&nd_pfn->dev.mutex, &nvdimm_pfn_key); in nd_pfn_devinit()
311 if (ndns && !__nd_attach_ndns(&nd_pfn->dev, ndns, &nd_pfn->ndns)) { in nd_pfn_devinit()
320 static struct nd_pfn *nd_pfn_alloc(struct nd_region *nd_region) in nd_pfn_alloc()
322 struct nd_pfn *nd_pfn; in nd_pfn_alloc() local
325 nd_pfn = kzalloc(sizeof(*nd_pfn), GFP_KERNEL); in nd_pfn_alloc()
326 if (!nd_pfn) in nd_pfn_alloc()
329 nd_pfn->id = ida_simple_get(&nd_region->pfn_ida, 0, 0, GFP_KERNEL); in nd_pfn_alloc()
330 if (nd_pfn->id < 0) { in nd_pfn_alloc()
331 kfree(nd_pfn); in nd_pfn_alloc()
335 dev = &nd_pfn->dev; in nd_pfn_alloc()
336 dev_set_name(dev, "pfn%d.%d", nd_region->id, nd_pfn->id); in nd_pfn_alloc()
340 return nd_pfn; in nd_pfn_alloc()
345 struct nd_pfn *nd_pfn; in nd_pfn_create() local
351 nd_pfn = nd_pfn_alloc(nd_region); in nd_pfn_create()
352 dev = nd_pfn_devinit(nd_pfn, NULL); in nd_pfn_create()
364 static int nd_pfn_clear_memmap_errors(struct nd_pfn *nd_pfn) in nd_pfn_clear_memmap_errors() argument
366 struct nd_region *nd_region = to_nd_region(nd_pfn->dev.parent); in nd_pfn_clear_memmap_errors()
367 struct nd_namespace_common *ndns = nd_pfn->ndns; in nd_pfn_clear_memmap_errors()
369 struct nd_pfn_sb *pfn_sb = nd_pfn->pfn_sb; in nd_pfn_clear_memmap_errors()
374 if (nd_pfn->mode != PFN_MODE_PMEM) in nd_pfn_clear_memmap_errors()
385 devm_namespace_disable(&nd_pfn->dev, ndns); in nd_pfn_clear_memmap_errors()
386 rc = devm_namespace_enable(&nd_pfn->dev, ndns, le64_to_cpu(pfn_sb->dataoff)); in nd_pfn_clear_memmap_errors()
397 dev_dbg(&nd_pfn->dev, "meta: %x badblocks at %llx\n", in nd_pfn_clear_memmap_errors()
415 dev_err(&nd_pfn->dev, in nd_pfn_clear_memmap_errors()
450 int nd_pfn_validate(struct nd_pfn *nd_pfn, const char *sig) in nd_pfn_validate() argument
458 struct nd_pfn_sb *pfn_sb = nd_pfn->pfn_sb; in nd_pfn_validate()
459 struct nd_namespace_common *ndns = nd_pfn->ndns; in nd_pfn_validate()
465 if (!is_memory(nd_pfn->dev.parent)) in nd_pfn_validate()
514 dev_err(&nd_pfn->dev, in nd_pfn_validate()
522 dev_err(&nd_pfn->dev, in nd_pfn_validate()
535 dev_err(&nd_pfn->dev, "init failed, alignment mismatch: " in nd_pfn_validate()
536 "%ld:%ld\n", nd_pfn->align, align); in nd_pfn_validate()
540 if (!nd_pfn->uuid) { in nd_pfn_validate()
546 nd_pfn->uuid = kmemdup(pfn_sb->uuid, 16, GFP_KERNEL); in nd_pfn_validate()
547 if (!nd_pfn->uuid) in nd_pfn_validate()
549 nd_pfn->align = align; in nd_pfn_validate()
550 nd_pfn->mode = mode; in nd_pfn_validate()
556 if (memcmp(nd_pfn->uuid, pfn_sb->uuid, 16) != 0) in nd_pfn_validate()
565 if (nd_pfn->align != align || nd_pfn->mode != mode) { in nd_pfn_validate()
566 dev_err(&nd_pfn->dev, in nd_pfn_validate()
568 dev_dbg(&nd_pfn->dev, "align: %lx:%lx mode: %d:%d\n", in nd_pfn_validate()
569 nd_pfn->align, align, nd_pfn->mode, in nd_pfn_validate()
576 dev_err(&nd_pfn->dev, "alignment: %lx exceeds capacity %llx\n", in nd_pfn_validate()
591 dev_err(&nd_pfn->dev, "pfn array size exceeds capacity of %s\n", in nd_pfn_validate()
598 dev_err(&nd_pfn->dev, in nd_pfn_validate()
605 dev_err(&nd_pfn->dev, "resource start misaligned\n"); in nd_pfn_validate()
610 dev_err(&nd_pfn->dev, "resource end misaligned\n"); in nd_pfn_validate()
615 dev_err(&nd_pfn->dev, "bad offset with small namespace\n"); in nd_pfn_validate()
625 struct nd_pfn *nd_pfn; in nd_pfn_probe() local
642 nd_pfn = nd_pfn_alloc(nd_region); in nd_pfn_probe()
643 pfn_dev = nd_pfn_devinit(nd_pfn, ndns); in nd_pfn_probe()
648 nd_pfn = to_nd_pfn(pfn_dev); in nd_pfn_probe()
649 nd_pfn->pfn_sb = pfn_sb; in nd_pfn_probe()
650 rc = nd_pfn_validate(nd_pfn, PFN_SIG); in nd_pfn_probe()
653 nd_detach_ndns(pfn_dev, &nd_pfn->ndns); in nd_pfn_probe()
682 static int __nvdimm_setup_pfn(struct nd_pfn *nd_pfn, struct dev_pagemap *pgmap) in __nvdimm_setup_pfn() argument
686 struct nd_pfn_sb *pfn_sb = nd_pfn->pfn_sb; in __nvdimm_setup_pfn()
691 struct nd_namespace_common *ndns = nd_pfn->ndns; in __nvdimm_setup_pfn()
706 if (nd_pfn->mode == PFN_MODE_RAM) { in __nvdimm_setup_pfn()
709 nd_pfn->npfns = le64_to_cpu(pfn_sb->npfns); in __nvdimm_setup_pfn()
710 } else if (nd_pfn->mode == PFN_MODE_PMEM) { in __nvdimm_setup_pfn()
711 nd_pfn->npfns = PHYS_PFN((range_len(range) - offset)); in __nvdimm_setup_pfn()
712 if (le64_to_cpu(nd_pfn->pfn_sb->npfns) > nd_pfn->npfns) in __nvdimm_setup_pfn()
713 dev_info(&nd_pfn->dev, in __nvdimm_setup_pfn()
715 le64_to_cpu(nd_pfn->pfn_sb->npfns), in __nvdimm_setup_pfn()
716 nd_pfn->npfns); in __nvdimm_setup_pfn()
727 static int nd_pfn_init(struct nd_pfn *nd_pfn) in nd_pfn_init() argument
729 struct nd_namespace_common *ndns = nd_pfn->ndns; in nd_pfn_init()
741 pfn_sb = devm_kmalloc(&nd_pfn->dev, sizeof(*pfn_sb), GFP_KERNEL); in nd_pfn_init()
745 nd_pfn->pfn_sb = pfn_sb; in nd_pfn_init()
746 if (is_nd_dax(&nd_pfn->dev)) in nd_pfn_init()
751 rc = nd_pfn_validate(nd_pfn, sig); in nd_pfn_init()
753 return nd_pfn_clear_memmap_errors(nd_pfn); in nd_pfn_init()
760 nd_region = to_nd_region(nd_pfn->dev.parent); in nd_pfn_init()
762 dev_info(&nd_pfn->dev, in nd_pfn_init()
771 align = max(nd_pfn->align, memremap_compat_align()); in nd_pfn_init()
779 dev_err(&nd_pfn->dev, "%s: start %pa misaligned to %#lx\n", in nd_pfn_init()
785 if (nd_pfn->mode == PFN_MODE_PMEM) { in nd_pfn_init()
807 dev_err(&nd_pfn->dev, in nd_pfn_init()
813 } else if (nd_pfn->mode == PFN_MODE_RAM) in nd_pfn_init()
820 dev_err(&nd_pfn->dev, "%s unable to satisfy requested alignment\n", in nd_pfn_init()
826 pfn_sb->mode = cpu_to_le32(nd_pfn->mode); in nd_pfn_init()
830 memcpy(pfn_sb->uuid, nd_pfn->uuid, 16); in nd_pfn_init()
835 pfn_sb->align = cpu_to_le32(nd_pfn->align); in nd_pfn_init()
844 rc = nd_pfn_clear_memmap_errors(nd_pfn); in nd_pfn_init()
855 int nvdimm_setup_pfn(struct nd_pfn *nd_pfn, struct dev_pagemap *pgmap) in nvdimm_setup_pfn() argument
859 if (!nd_pfn->uuid || !nd_pfn->ndns) in nvdimm_setup_pfn()
862 rc = nd_pfn_init(nd_pfn); in nvdimm_setup_pfn()
867 return __nvdimm_setup_pfn(nd_pfn, pgmap); in nvdimm_setup_pfn()