Lines Matching refs:ndd

37 unsigned sizeof_namespace_label(struct nvdimm_drvdata *ndd)  in sizeof_namespace_label()  argument
39 return ndd->nslabel_size; in sizeof_namespace_label()
48 static int __nvdimm_num_label_slots(struct nvdimm_drvdata *ndd, in __nvdimm_num_label_slots() argument
51 return (ndd->nsarea.config_size - index_size * 2) / in __nvdimm_num_label_slots()
52 sizeof_namespace_label(ndd); in __nvdimm_num_label_slots()
55 int nvdimm_num_label_slots(struct nvdimm_drvdata *ndd) in nvdimm_num_label_slots() argument
59 tmp_nslot = ndd->nsarea.config_size / sizeof_namespace_label(ndd); in nvdimm_num_label_slots()
62 return __nvdimm_num_label_slots(ndd, NSINDEX_ALIGN * n); in nvdimm_num_label_slots()
65 size_t sizeof_namespace_index(struct nvdimm_drvdata *ndd) in sizeof_namespace_index() argument
75 nslot = nvdimm_num_label_slots(ndd); in sizeof_namespace_index()
76 space = ndd->nsarea.config_size - nslot * sizeof_namespace_label(ndd); in sizeof_namespace_index()
81 dev_err(ndd->dev, "label area (%d) too small to host (%d byte) labels\n", in sizeof_namespace_index()
82 ndd->nsarea.config_size, sizeof_namespace_label(ndd)); in sizeof_namespace_index()
86 static int __nd_label_validate(struct nvdimm_drvdata *ndd) in __nd_label_validate() argument
116 to_namespace_index(ndd, 0), in __nd_label_validate()
117 to_namespace_index(ndd, 1), in __nd_label_validate()
120 struct device *dev = ndd->dev; in __nd_label_validate()
145 if (labelsize != sizeof_namespace_label(ndd)) { in __nd_label_validate()
153 sum = nd_fletcher64(nsindex[i], sizeof_namespace_index(ndd), 1); in __nd_label_validate()
168 != i * sizeof_namespace_index(ndd)) { in __nd_label_validate()
175 != (!i) * sizeof_namespace_index(ndd)) { in __nd_label_validate()
182 != 2 * sizeof_namespace_index(ndd)) { in __nd_label_validate()
190 if (size > sizeof_namespace_index(ndd) in __nd_label_validate()
197 if (nslot * sizeof_namespace_label(ndd) in __nd_label_validate()
198 + 2 * sizeof_namespace_index(ndd) in __nd_label_validate()
199 > ndd->nsarea.config_size) { in __nd_label_validate()
201 i, nslot, ndd->nsarea.config_size); in __nd_label_validate()
232 static int nd_label_validate(struct nvdimm_drvdata *ndd) in nd_label_validate() argument
246 ndd->nslabel_size = label_size[i]; in nd_label_validate()
247 rc = __nd_label_validate(ndd); in nd_label_validate()
255 static void nd_label_copy(struct nvdimm_drvdata *ndd, in nd_label_copy() argument
263 memcpy(dst, src, sizeof_namespace_index(ndd)); in nd_label_copy()
266 static struct nd_namespace_label *nd_label_base(struct nvdimm_drvdata *ndd) in nd_label_base() argument
268 void *base = to_namespace_index(ndd, 0); in nd_label_base()
270 return base + 2 * sizeof_namespace_index(ndd); in nd_label_base()
273 static int to_slot(struct nvdimm_drvdata *ndd, in to_slot() argument
279 base = (unsigned long) nd_label_base(ndd); in to_slot()
281 return (label - base) / sizeof_namespace_label(ndd); in to_slot()
284 static struct nd_namespace_label *to_label(struct nvdimm_drvdata *ndd, int slot) in to_label() argument
288 base = (unsigned long) nd_label_base(ndd); in to_label()
289 label = base + sizeof_namespace_label(ndd) * slot; in to_label()
307 static bool preamble_index(struct nvdimm_drvdata *ndd, int idx, in preamble_index() argument
313 nsindex = to_namespace_index(ndd, idx); in preamble_index()
333 static bool preamble_current(struct nvdimm_drvdata *ndd, in preamble_current() argument
337 return preamble_index(ndd, ndd->ns_current, nsindex, in preamble_current()
341 static bool preamble_next(struct nvdimm_drvdata *ndd, in preamble_next() argument
345 return preamble_index(ndd, ndd->ns_next, nsindex, in preamble_next()
349 static bool slot_valid(struct nvdimm_drvdata *ndd, in slot_valid() argument
357 if (namespace_label_has(ndd, checksum)) { in slot_valid()
362 sum = nd_fletcher64(nd_label, sizeof_namespace_label(ndd), 1); in slot_valid()
365 dev_dbg(ndd->dev, "fail checksum. slot: %d expect: %#llx\n", in slot_valid()
374 int nd_label_reserve_dpa(struct nvdimm_drvdata *ndd) in nd_label_reserve_dpa() argument
380 if (!preamble_current(ndd, &nsindex, &free, &nslot)) in nd_label_reserve_dpa()
384 struct nvdimm *nvdimm = to_nvdimm(ndd->dev); in nd_label_reserve_dpa()
392 nd_label = to_label(ndd, slot); in nd_label_reserve_dpa()
394 if (!slot_valid(ndd, nd_label, slot)) in nd_label_reserve_dpa()
402 res = nvdimm_allocate_dpa(ndd, &label_id, in nd_label_reserve_dpa()
405 nd_dbg_dpa(nd_region, ndd, res, "reserve\n"); in nd_label_reserve_dpa()
413 int nd_label_data_init(struct nvdimm_drvdata *ndd) in nd_label_data_init() argument
421 if (ndd->data) in nd_label_data_init()
424 if (ndd->nsarea.status || ndd->nsarea.max_xfer == 0) { in nd_label_data_init()
425 dev_dbg(ndd->dev, "failed to init config data area: (%u:%u)\n", in nd_label_data_init()
426 ndd->nsarea.max_xfer, ndd->nsarea.config_size); in nd_label_data_init()
440 ndd->nslabel_size = 128; in nd_label_data_init()
441 read_size = sizeof_namespace_index(ndd) * 2; in nd_label_data_init()
446 config_size = ndd->nsarea.config_size; in nd_label_data_init()
447 ndd->data = kvzalloc(config_size, GFP_KERNEL); in nd_label_data_init()
448 if (!ndd->data) in nd_label_data_init()
458 max_xfer = min_t(size_t, ndd->nsarea.max_xfer, config_size); in nd_label_data_init()
473 rc = nvdimm_get_config_data(ndd, ndd->data, 0, read_size); in nd_label_data_init()
478 ndd->ns_current = nd_label_validate(ndd); in nd_label_data_init()
479 if (ndd->ns_current < 0) in nd_label_data_init()
483 ndd->ns_next = nd_label_next_nsindex(ndd->ns_current); in nd_label_data_init()
486 nsindex = to_current_namespace_index(ndd); in nd_label_data_init()
487 nd_label_copy(ndd, to_next_namespace_index(ndd), nsindex); in nd_label_data_init()
494 for (i = 0; i < nslot; i++, offset += ndd->nslabel_size) { in nd_label_data_init()
499 memset(ndd->data + offset, 0, ndd->nslabel_size); in nd_label_data_init()
504 if (offset + ndd->nslabel_size <= read_size) in nd_label_data_init()
512 label_read_size = offset + ndd->nslabel_size - read_size; in nd_label_data_init()
521 rc = nvdimm_get_config_data(ndd, ndd->data + read_size, in nd_label_data_init()
530 dev_dbg(ndd->dev, "len: %zu rc: %d\n", offset, rc); in nd_label_data_init()
535 int nd_label_active_count(struct nvdimm_drvdata *ndd) in nd_label_active_count() argument
542 if (!preamble_current(ndd, &nsindex, &free, &nslot)) in nd_label_active_count()
548 nd_label = to_label(ndd, slot); in nd_label_active_count()
550 if (!slot_valid(ndd, nd_label, slot)) { in nd_label_active_count()
555 dev_dbg(ndd->dev, in nd_label_active_count()
565 struct nd_namespace_label *nd_label_active(struct nvdimm_drvdata *ndd, int n) in nd_label_active() argument
571 if (!preamble_current(ndd, &nsindex, &free, &nslot)) in nd_label_active()
577 nd_label = to_label(ndd, slot); in nd_label_active()
578 if (!slot_valid(ndd, nd_label, slot)) in nd_label_active()
582 return to_label(ndd, slot); in nd_label_active()
588 u32 nd_label_alloc_slot(struct nvdimm_drvdata *ndd) in nd_label_alloc_slot() argument
594 if (!preamble_next(ndd, &nsindex, &free, &nslot)) in nd_label_alloc_slot()
597 WARN_ON(!is_nvdimm_bus_locked(ndd->dev)); in nd_label_alloc_slot()
608 bool nd_label_free_slot(struct nvdimm_drvdata *ndd, u32 slot) in nd_label_free_slot() argument
614 if (!preamble_next(ndd, &nsindex, &free, &nslot)) in nd_label_free_slot()
617 WARN_ON(!is_nvdimm_bus_locked(ndd->dev)); in nd_label_free_slot()
624 u32 nd_label_nfree(struct nvdimm_drvdata *ndd) in nd_label_nfree() argument
630 WARN_ON(!is_nvdimm_bus_locked(ndd->dev)); in nd_label_nfree()
632 if (!preamble_next(ndd, &nsindex, &free, &nslot)) in nd_label_nfree()
633 return nvdimm_num_label_slots(ndd); in nd_label_nfree()
638 static int nd_label_write_index(struct nvdimm_drvdata *ndd, int index, u32 seq, in nd_label_write_index() argument
647 nsindex = to_namespace_index(ndd, index); in nd_label_write_index()
649 nslot = nvdimm_num_label_slots(ndd); in nd_label_write_index()
655 nsindex->labelsize = sizeof_namespace_label(ndd) >> 8; in nd_label_write_index()
658 - (unsigned long) to_namespace_index(ndd, 0); in nd_label_write_index()
660 nsindex->mysize = __cpu_to_le64(sizeof_namespace_index(ndd)); in nd_label_write_index()
661 offset = (unsigned long) to_namespace_index(ndd, in nd_label_write_index()
663 - (unsigned long) to_namespace_index(ndd, 0); in nd_label_write_index()
665 offset = (unsigned long) nd_label_base(ndd) in nd_label_write_index()
666 - (unsigned long) to_namespace_index(ndd, 0); in nd_label_write_index()
670 if (sizeof_namespace_label(ndd) < 256) in nd_label_write_index()
684 checksum = nd_fletcher64(nsindex, sizeof_namespace_index(ndd), 1); in nd_label_write_index()
686 rc = nvdimm_set_config_data(ndd, __le64_to_cpu(nsindex->myoff), in nd_label_write_index()
687 nsindex, sizeof_namespace_index(ndd)); in nd_label_write_index()
695 WARN_ON(index != ndd->ns_next); in nd_label_write_index()
696 nd_label_copy(ndd, to_current_namespace_index(ndd), nsindex); in nd_label_write_index()
697 ndd->ns_current = nd_label_next_nsindex(ndd->ns_current); in nd_label_write_index()
698 ndd->ns_next = nd_label_next_nsindex(ndd->ns_next); in nd_label_write_index()
699 WARN_ON(ndd->ns_current == ndd->ns_next); in nd_label_write_index()
704 static unsigned long nd_label_offset(struct nvdimm_drvdata *ndd, in nd_label_offset() argument
708 - (unsigned long) to_namespace_index(ndd, 0); in nd_label_offset()
751 struct nvdimm_drvdata *ndd = to_ndd(nd_mapping); in reap_victim() local
752 u32 slot = to_slot(ndd, victim->label); in reap_victim()
754 dev_dbg(ndd->dev, "free: %d\n", slot); in reap_victim()
755 nd_label_free_slot(ndd, slot); in reap_victim()
765 struct nvdimm_drvdata *ndd = to_ndd(nd_mapping); in __pmem_label_update() local
777 if (!preamble_next(ndd, &nsindex, &free, &nslot)) in __pmem_label_update()
782 for_each_dpa_resource(ndd, res) in __pmem_label_update()
792 slot = nd_label_alloc_slot(ndd); in __pmem_label_update()
795 dev_dbg(ndd->dev, "allocated: %d\n", slot); in __pmem_label_update()
797 nd_label = to_label(ndd, slot); in __pmem_label_update()
798 memset(nd_label, 0, sizeof_namespace_label(ndd)); in __pmem_label_update()
810 if (namespace_label_has(ndd, type_guid)) in __pmem_label_update()
812 if (namespace_label_has(ndd, abstraction_guid)) in __pmem_label_update()
816 if (namespace_label_has(ndd, checksum)) { in __pmem_label_update()
820 sum = nd_fletcher64(nd_label, sizeof_namespace_label(ndd), 1); in __pmem_label_update()
823 nd_dbg_dpa(nd_region, ndd, res, "\n"); in __pmem_label_update()
826 offset = nd_label_offset(ndd, nd_label); in __pmem_label_update()
827 rc = nvdimm_set_config_data(ndd, offset, nd_label, in __pmem_label_update()
828 sizeof_namespace_label(ndd)); in __pmem_label_update()
844 rc = nd_label_write_index(ndd, ndd->ns_next, in __pmem_label_update()
855 to_slot(ndd, nd_label)); in __pmem_label_update()
876 static struct resource *to_resource(struct nvdimm_drvdata *ndd, in to_resource() argument
881 for_each_dpa_resource(ndd, res) { in to_resource()
904 struct nvdimm_drvdata *ndd = to_ndd(nd_mapping); in __blk_label_update() local
916 if (!preamble_next(ndd, &nsindex, &free, &nslot)) in __blk_label_update()
920 nfree = nd_label_nfree(ndd); in __blk_label_update()
932 for_each_dpa_resource(ndd, res) { in __blk_label_update()
948 nd_label = to_label(ndd, slot); in __blk_label_update()
952 res = to_resource(ndd, nd_label); in __blk_label_update()
956 slot = to_slot(ndd, nd_label); in __blk_label_update()
974 for_each_dpa_resource(ndd, res) { in __blk_label_update()
977 if (!nsblk_add_resource(nd_region, ndd, nsblk, res->start)) { in __blk_label_update()
1001 slot = nd_label_alloc_slot(ndd); in __blk_label_update()
1004 dev_dbg(ndd->dev, "allocated: %d\n", slot); in __blk_label_update()
1006 nd_label = to_label(ndd, slot); in __blk_label_update()
1007 memset(nd_label, 0, sizeof_namespace_label(ndd)); in __blk_label_update()
1019 if (namespace_label_has(ndd, type_guid)) { in __blk_label_update()
1038 if (namespace_label_has(ndd, type_guid)) in __blk_label_update()
1040 if (namespace_label_has(ndd, abstraction_guid)) in __blk_label_update()
1045 if (namespace_label_has(ndd, checksum)) { in __blk_label_update()
1050 sizeof_namespace_label(ndd), 1); in __blk_label_update()
1055 offset = nd_label_offset(ndd, nd_label); in __blk_label_update()
1056 rc = nvdimm_set_config_data(ndd, offset, nd_label, in __blk_label_update()
1057 sizeof_namespace_label(ndd)); in __blk_label_update()
1064 dev_dbg(ndd->dev, "free: %d\n", slot); in __blk_label_update()
1065 nd_label_free_slot(ndd, slot); in __blk_label_update()
1069 rc = nd_label_write_index(ndd, ndd->ns_next, in __blk_label_update()
1115 nd_label = to_label(ndd, slot); in __blk_label_update()
1119 res = to_resource(ndd, nd_label); in __blk_label_update()
1145 nd_label_copy(ndd, nsindex, to_current_namespace_index(ndd)); in __blk_label_update()
1158 struct nvdimm_drvdata *ndd = to_ndd(nd_mapping); in init_labels() local
1178 if (ndd->ns_current == -1 || ndd->ns_next == -1) in init_labels()
1183 nsindex = to_namespace_index(ndd, 0); in init_labels()
1184 memset(nsindex, 0, ndd->nsarea.config_size); in init_labels()
1186 int rc = nd_label_write_index(ndd, i, 3 - i, ND_NSINDEX_INIT); in init_labels()
1191 ndd->ns_next = 1; in init_labels()
1192 ndd->ns_current = 0; in init_labels()
1199 struct nvdimm_drvdata *ndd = to_ndd(nd_mapping); in del_labels() local
1212 if (!preamble_next(ndd, &nsindex, &free, &nslot)) in del_labels()
1226 slot = to_slot(ndd, nd_label); in del_labels()
1227 nd_label_free_slot(ndd, slot); in del_labels()
1228 dev_dbg(ndd->dev, "free: %d\n", slot); in del_labels()
1236 dev_dbg(ndd->dev, "no more active labels\n"); in del_labels()
1240 return nd_label_write_index(ndd, ndd->ns_next, in del_labels()
1251 struct nvdimm_drvdata *ndd = to_ndd(nd_mapping); in nd_pmem_namespace_label_update() local
1262 for_each_dpa_resource(ndd, res) in nd_pmem_namespace_label_update()