Lines Matching refs:ndd
37 size_t sizeof_namespace_index(struct nvdimm_drvdata *ndd) in sizeof_namespace_index() argument
41 if (ndd->nsindex_size) in sizeof_namespace_index()
42 return ndd->nsindex_size; in sizeof_namespace_index()
52 index_span = ndd->nsarea.config_size / 129; in sizeof_namespace_index()
54 ndd->nsindex_size = index_span * NSINDEX_ALIGN; in sizeof_namespace_index()
56 return ndd->nsindex_size; in sizeof_namespace_index()
59 int nvdimm_num_label_slots(struct nvdimm_drvdata *ndd) in nvdimm_num_label_slots() argument
61 return ndd->nsarea.config_size / 129; in nvdimm_num_label_slots()
64 int nd_label_validate(struct nvdimm_drvdata *ndd) in nd_label_validate() argument
94 to_namespace_index(ndd, 0), in nd_label_validate()
95 to_namespace_index(ndd, 1), in nd_label_validate()
98 struct device *dev = ndd->dev; in nd_label_validate()
116 sum = nd_fletcher64(nsindex[i], sizeof_namespace_index(ndd), 1); in nd_label_validate()
133 != i * sizeof_namespace_index(ndd)) { in nd_label_validate()
140 != (!i) * sizeof_namespace_index(ndd)) { in nd_label_validate()
148 if (size > sizeof_namespace_index(ndd) in nd_label_validate()
157 + 2 * sizeof_namespace_index(ndd) in nd_label_validate()
158 > ndd->nsarea.config_size) { in nd_label_validate()
161 ndd->nsarea.config_size); in nd_label_validate()
192 void nd_label_copy(struct nvdimm_drvdata *ndd, struct nd_namespace_index *dst, in nd_label_copy() argument
200 memcpy(dst, src, sizeof_namespace_index(ndd)); in nd_label_copy()
203 static struct nd_namespace_label *nd_label_base(struct nvdimm_drvdata *ndd) in nd_label_base() argument
205 void *base = to_namespace_index(ndd, 0); in nd_label_base()
207 return base + 2 * sizeof_namespace_index(ndd); in nd_label_base()
210 static int to_slot(struct nvdimm_drvdata *ndd, in to_slot() argument
213 return nd_label - nd_label_base(ndd); in to_slot()
229 static bool preamble_index(struct nvdimm_drvdata *ndd, int idx, in preamble_index() argument
235 nsindex = to_namespace_index(ndd, idx); in preamble_index()
255 static bool preamble_current(struct nvdimm_drvdata *ndd, in preamble_current() argument
259 return preamble_index(ndd, ndd->ns_current, nsindex, in preamble_current()
263 static bool preamble_next(struct nvdimm_drvdata *ndd, in preamble_next() argument
267 return preamble_index(ndd, ndd->ns_next, nsindex, in preamble_next()
285 int nd_label_reserve_dpa(struct nvdimm_drvdata *ndd) in nd_label_reserve_dpa() argument
291 if (!preamble_current(ndd, &nsindex, &free, &nslot)) in nd_label_reserve_dpa()
302 nd_label = nd_label_base(ndd) + slot; in nd_label_reserve_dpa()
310 res = nvdimm_allocate_dpa(ndd, &label_id, in nd_label_reserve_dpa()
313 nd_dbg_dpa(nd_region, ndd, res, "reserve\n"); in nd_label_reserve_dpa()
321 int nd_label_active_count(struct nvdimm_drvdata *ndd) in nd_label_active_count() argument
328 if (!preamble_current(ndd, &nsindex, &free, &nslot)) in nd_label_active_count()
334 nd_label = nd_label_base(ndd) + slot; in nd_label_active_count()
341 dev_dbg(ndd->dev, in nd_label_active_count()
351 struct nd_namespace_label *nd_label_active(struct nvdimm_drvdata *ndd, int n) in nd_label_active() argument
357 if (!preamble_current(ndd, &nsindex, &free, &nslot)) in nd_label_active()
363 nd_label = nd_label_base(ndd) + slot; in nd_label_active()
368 return nd_label_base(ndd) + slot; in nd_label_active()
374 u32 nd_label_alloc_slot(struct nvdimm_drvdata *ndd) in nd_label_alloc_slot() argument
380 if (!preamble_next(ndd, &nsindex, &free, &nslot)) in nd_label_alloc_slot()
383 WARN_ON(!is_nvdimm_bus_locked(ndd->dev)); in nd_label_alloc_slot()
394 bool nd_label_free_slot(struct nvdimm_drvdata *ndd, u32 slot) in nd_label_free_slot() argument
400 if (!preamble_next(ndd, &nsindex, &free, &nslot)) in nd_label_free_slot()
403 WARN_ON(!is_nvdimm_bus_locked(ndd->dev)); in nd_label_free_slot()
410 u32 nd_label_nfree(struct nvdimm_drvdata *ndd) in nd_label_nfree() argument
416 WARN_ON(!is_nvdimm_bus_locked(ndd->dev)); in nd_label_nfree()
418 if (!preamble_next(ndd, &nsindex, &free, &nslot)) in nd_label_nfree()
419 return nvdimm_num_label_slots(ndd); in nd_label_nfree()
424 static int nd_label_write_index(struct nvdimm_drvdata *ndd, int index, u32 seq, in nd_label_write_index() argument
433 nsindex = to_namespace_index(ndd, index); in nd_label_write_index()
435 nslot = nvdimm_num_label_slots(ndd); in nd_label_write_index()
443 - (unsigned long) to_namespace_index(ndd, 0); in nd_label_write_index()
445 nsindex->mysize = __cpu_to_le64(sizeof_namespace_index(ndd)); in nd_label_write_index()
446 offset = (unsigned long) to_namespace_index(ndd, in nd_label_write_index()
448 - (unsigned long) to_namespace_index(ndd, 0); in nd_label_write_index()
450 offset = (unsigned long) nd_label_base(ndd) in nd_label_write_index()
451 - (unsigned long) to_namespace_index(ndd, 0); in nd_label_write_index()
466 checksum = nd_fletcher64(nsindex, sizeof_namespace_index(ndd), 1); in nd_label_write_index()
468 rc = nvdimm_set_config_data(ndd, __le64_to_cpu(nsindex->myoff), in nd_label_write_index()
469 nsindex, sizeof_namespace_index(ndd)); in nd_label_write_index()
477 WARN_ON(index != ndd->ns_next); in nd_label_write_index()
478 nd_label_copy(ndd, to_current_namespace_index(ndd), nsindex); in nd_label_write_index()
479 ndd->ns_current = nd_label_next_nsindex(ndd->ns_current); in nd_label_write_index()
480 ndd->ns_next = nd_label_next_nsindex(ndd->ns_next); in nd_label_write_index()
481 WARN_ON(ndd->ns_current == ndd->ns_next); in nd_label_write_index()
486 static unsigned long nd_label_offset(struct nvdimm_drvdata *ndd, in nd_label_offset() argument
490 - (unsigned long) to_namespace_index(ndd, 0); in nd_label_offset()
498 struct nvdimm_drvdata *ndd = to_ndd(nd_mapping); in __pmem_label_update() local
509 if (!preamble_next(ndd, &nsindex, &free, &nslot)) in __pmem_label_update()
513 for_each_dpa_resource(ndd, res) in __pmem_label_update()
523 slot = nd_label_alloc_slot(ndd); in __pmem_label_update()
526 dev_dbg(ndd->dev, "%s: allocated: %d\n", __func__, slot); in __pmem_label_update()
528 nd_label = nd_label_base(ndd) + slot; in __pmem_label_update()
540 nd_dbg_dpa(nd_region, ndd, res, "%s\n", __func__); in __pmem_label_update()
543 offset = nd_label_offset(ndd, nd_label); in __pmem_label_update()
544 rc = nvdimm_set_config_data(ndd, offset, nd_label, in __pmem_label_update()
562 dev_dbg(ndd->dev, "%s: free: %d\n", __func__, slot); in __pmem_label_update()
563 slot = to_slot(ndd, victim->label); in __pmem_label_update()
564 nd_label_free_slot(ndd, slot); in __pmem_label_update()
569 rc = nd_label_write_index(ndd, ndd->ns_next, in __pmem_label_update()
580 to_slot(ndd, nd_label)); in __pmem_label_update()
601 static struct resource *to_resource(struct nvdimm_drvdata *ndd, in to_resource() argument
606 for_each_dpa_resource(ndd, res) { in to_resource()
627 struct nvdimm_drvdata *ndd = to_ndd(nd_mapping); in __blk_label_update() local
638 if (!preamble_next(ndd, &nsindex, &free, &nslot)) in __blk_label_update()
642 nfree = nd_label_nfree(ndd); in __blk_label_update()
654 for_each_dpa_resource(ndd, res) { in __blk_label_update()
671 nd_label = nd_label_base(ndd) + slot; in __blk_label_update()
675 res = to_resource(ndd, nd_label); in __blk_label_update()
679 slot = to_slot(ndd, nd_label); in __blk_label_update()
697 for_each_dpa_resource(ndd, res) { in __blk_label_update()
700 if (!nsblk_add_resource(nd_region, ndd, nsblk, res->start)) { in __blk_label_update()
712 slot = nd_label_alloc_slot(ndd); in __blk_label_update()
715 dev_dbg(ndd->dev, "%s: allocated: %d\n", __func__, slot); in __blk_label_update()
717 nd_label = nd_label_base(ndd) + slot; in __blk_label_update()
733 offset = nd_label_offset(ndd, nd_label); in __blk_label_update()
734 rc = nvdimm_set_config_data(ndd, offset, nd_label, in __blk_label_update()
742 dev_dbg(ndd->dev, "%s: free: %d\n", __func__, slot); in __blk_label_update()
743 nd_label_free_slot(ndd, slot); in __blk_label_update()
747 rc = nd_label_write_index(ndd, ndd->ns_next, in __blk_label_update()
793 nd_label = nd_label_base(ndd) + slot; in __blk_label_update()
797 res = to_resource(ndd, nd_label); in __blk_label_update()
823 nd_label_copy(ndd, nsindex, to_current_namespace_index(ndd)); in __blk_label_update()
836 struct nvdimm_drvdata *ndd = to_ndd(nd_mapping); in init_labels() local
856 if (ndd->ns_current == -1 || ndd->ns_next == -1) in init_labels()
861 nsindex = to_namespace_index(ndd, 0); in init_labels()
862 memset(nsindex, 0, ndd->nsarea.config_size); in init_labels()
864 int rc = nd_label_write_index(ndd, i, 3 - i, ND_NSINDEX_INIT); in init_labels()
869 ndd->ns_next = 1; in init_labels()
870 ndd->ns_current = 0; in init_labels()
877 struct nvdimm_drvdata *ndd = to_ndd(nd_mapping); in del_labels() local
890 if (!preamble_next(ndd, &nsindex, &free, &nslot)) in del_labels()
904 slot = to_slot(ndd, nd_label); in del_labels()
905 nd_label_free_slot(ndd, slot); in del_labels()
906 dev_dbg(ndd->dev, "%s: free: %d\n", __func__, slot); in del_labels()
914 dev_dbg(ndd->dev, "%s: no more active labels\n", __func__); in del_labels()
918 return nd_label_write_index(ndd, ndd->ns_next, in del_labels()
929 struct nvdimm_drvdata *ndd = to_ndd(nd_mapping); in nd_pmem_namespace_label_update() local
940 for_each_dpa_resource(ndd, res) in nd_pmem_namespace_label_update()