Lines Matching +full:state +full:- +full:labels
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright(c) 2013-2015 Intel Corporation. All rights reserved.
14 #include "nd-core.h"
29 if (!nvdimm->cmd_mask || in nvdimm_check_config_data()
30 !test_bit(ND_CMD_GET_CONFIG_DATA, &nvdimm->cmd_mask)) { in nvdimm_check_config_data()
31 if (test_bit(NDD_LABELING, &nvdimm->flags)) in nvdimm_check_config_data()
32 return -ENXIO; in nvdimm_check_config_data()
34 return -ENOTTY; in nvdimm_check_config_data()
45 return -EINVAL; in validate_dimm()
47 rc = nvdimm_check_config_data(ndd->dev); in validate_dimm()
49 dev_dbg(ndd->dev, "%ps: %s error: %d\n", in validate_dimm()
55 * nvdimm_init_nsarea - determine the geometry of a dimm's namespace area
58 * Returns: %0 if the area is already valid, -errno on error
62 struct nd_cmd_get_config_size *cmd = &ndd->nsarea; in nvdimm_init_nsarea()
63 struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(ndd->dev); in nvdimm_init_nsarea()
71 if (cmd->config_size) in nvdimm_init_nsarea()
75 nd_desc = nvdimm_bus->nd_desc; in nvdimm_init_nsarea()
76 rc = nd_desc->ndctl(nd_desc, to_nvdimm(ndd->dev), in nvdimm_init_nsarea()
86 struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(ndd->dev); in nvdimm_get_config_data()
87 struct nvdimm_bus_descriptor *nd_desc = nvdimm_bus->nd_desc; in nvdimm_get_config_data()
95 if (offset + len > ndd->nsarea.config_size) in nvdimm_get_config_data()
96 return -ENXIO; in nvdimm_get_config_data()
98 max_cmd_size = min_t(u32, len, ndd->nsarea.max_xfer); in nvdimm_get_config_data()
101 return -ENOMEM; in nvdimm_get_config_data()
104 len -= cmd->in_length, buf_offset += cmd->in_length) { in nvdimm_get_config_data()
107 cmd->in_offset = offset + buf_offset; in nvdimm_get_config_data()
108 cmd->in_length = min(max_cmd_size, len); in nvdimm_get_config_data()
110 cmd_size = sizeof(*cmd) + cmd->in_length; in nvdimm_get_config_data()
112 rc = nd_desc->ndctl(nd_desc, to_nvdimm(ndd->dev), in nvdimm_get_config_data()
122 memcpy(buf + buf_offset, cmd->out_buf, cmd->in_length); in nvdimm_get_config_data()
135 struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(ndd->dev); in nvdimm_set_config_data()
136 struct nvdimm_bus_descriptor *nd_desc = nvdimm_bus->nd_desc; in nvdimm_set_config_data()
141 if (offset + len > ndd->nsarea.config_size) in nvdimm_set_config_data()
142 return -ENXIO; in nvdimm_set_config_data()
144 max_cmd_size = min_t(u32, len, ndd->nsarea.max_xfer); in nvdimm_set_config_data()
147 return -ENOMEM; in nvdimm_set_config_data()
149 for (buf_offset = 0; len; len -= cmd->in_length, in nvdimm_set_config_data()
150 buf_offset += cmd->in_length) { in nvdimm_set_config_data()
153 cmd->in_offset = offset + buf_offset; in nvdimm_set_config_data()
154 cmd->in_length = min(max_cmd_size, len); in nvdimm_set_config_data()
155 memcpy(cmd->in_buf, buf + buf_offset, cmd->in_length); in nvdimm_set_config_data()
157 /* status is output in the last 4-bytes of the command buffer */ in nvdimm_set_config_data()
158 cmd_size = sizeof(*cmd) + cmd->in_length + sizeof(u32); in nvdimm_set_config_data()
160 rc = nd_desc->ndctl(nd_desc, to_nvdimm(ndd->dev), in nvdimm_set_config_data()
178 set_bit(NDD_LABELING, &nvdimm->flags); in nvdimm_set_labeling()
185 set_bit(NDD_LOCKED, &nvdimm->flags); in nvdimm_set_locked()
192 clear_bit(NDD_LOCKED, &nvdimm->flags); in nvdimm_clear_locked()
199 ida_free(&dimm_ida, nvdimm->id); in nvdimm_release()
214 struct nvdimm *nvdimm = nd_mapping->nvdimm; in to_ndd()
216 WARN_ON_ONCE(!is_nvdimm_bus_locked(&nvdimm->dev)); in to_ndd()
218 return dev_get_drvdata(&nvdimm->dev); in to_ndd()
225 struct device *dev = ndd->dev; in nvdimm_drvdata_release()
234 kvfree(ndd->data); in nvdimm_drvdata_release()
241 kref_get(&ndd->kref); in get_ndd()
247 kref_put(&ndd->kref, nvdimm_drvdata_release); in put_ndd()
252 return dev_name(&nvdimm->dev); in nvdimm_name()
258 return &nvdimm->dev.kobj; in nvdimm_kobj()
264 return nvdimm->cmd_mask; in nvdimm_cmd_mask()
271 return nvdimm->provider_data; in nvdimm_provider_data()
282 if (!nvdimm->cmd_mask) in commands_show()
285 for_each_set_bit(cmd, &nvdimm->cmd_mask, BITS_PER_LONG) in commands_show()
298 test_bit(NDD_LABELING, &nvdimm->flags) ? "label " : "", in flags_show()
299 test_bit(NDD_LOCKED, &nvdimm->flags) ? "lock " : ""); in flags_show()
309 * The state may be in the process of changing, userspace should in state_show()
314 return sprintf(buf, "%s\n", atomic_read(&nvdimm->busy) in state_show()
317 static DEVICE_ATTR_RO(state);
326 return -ENXIO; in __available_slots_show()
328 dev = ndd->dev; in __available_slots_show()
331 if (nfree - 1 > nfree) { in __available_slots_show()
335 nfree--; in __available_slots_show()
364 nvdimm->sec.flags = nvdimm_security_flags(nvdimm, NVDIMM_USER); in security_show()
366 if (test_bit(NVDIMM_SECURITY_OVERWRITE, &nvdimm->sec.flags)) in security_show()
368 if (test_bit(NVDIMM_SECURITY_DISABLED, &nvdimm->sec.flags)) in security_show()
370 if (test_bit(NVDIMM_SECURITY_UNLOCKED, &nvdimm->sec.flags)) in security_show()
372 if (test_bit(NVDIMM_SECURITY_LOCKED, &nvdimm->sec.flags)) in security_show()
374 return -ENOTTY; in security_show()
383 &nvdimm->sec.flags)); in frozen_show()
425 return a->mode; in nvdimm_visible()
426 if (!nvdimm->sec.flags) in nvdimm_visible()
430 /* Are there any state mutation ops (make writable)? */ in nvdimm_visible()
431 if (nvdimm->sec.ops->freeze || nvdimm->sec.ops->disable in nvdimm_visible()
432 || nvdimm->sec.ops->change_key in nvdimm_visible()
433 || nvdimm->sec.ops->erase in nvdimm_visible()
434 || nvdimm->sec.ops->overwrite) in nvdimm_visible()
435 return a->mode; in nvdimm_visible()
439 if (nvdimm->sec.ops->freeze) in nvdimm_visible()
440 return a->mode; in nvdimm_visible()
454 if (!nvdimm->fw_ops) in result_show()
455 return -EOPNOTSUPP; in result_show()
458 result = nvdimm->fw_ops->activate_result(nvdimm); in result_show()
473 return -ENXIO; in result_show()
481 enum nvdimm_fwa_state state; in activate_show() local
483 if (!nvdimm->fw_ops) in activate_show()
484 return -EOPNOTSUPP; in activate_show()
487 state = nvdimm->fw_ops->activate_state(nvdimm); in activate_show()
490 switch (state) { in activate_show()
498 return -ENXIO; in activate_show()
509 if (!nvdimm->fw_ops) in activate_store()
510 return -EOPNOTSUPP; in activate_store()
517 return -EINVAL; in activate_store()
520 rc = nvdimm->fw_ops->arm(nvdimm, arg); in activate_store()
539 struct nvdimm_bus_descriptor *nd_desc = nvdimm_bus->nd_desc; in nvdimm_firmware_visible()
543 if (!nd_desc->fw_ops) in nvdimm_firmware_visible()
545 if (!nvdimm->fw_ops) in nvdimm_firmware_visible()
549 cap = nd_desc->fw_ops->capability(nd_desc); in nvdimm_firmware_visible()
555 return a->mode; in nvdimm_firmware_visible()
579 return dev->type == &nvdimm_device_type; in is_nvdimm()
597 nvdimm->id = ida_alloc(&dimm_ida, GFP_KERNEL); in __nvdimm_create()
598 if (nvdimm->id < 0) { in __nvdimm_create()
603 nvdimm->dimm_id = dimm_id; in __nvdimm_create()
604 nvdimm->provider_data = provider_data; in __nvdimm_create()
605 nvdimm->flags = flags; in __nvdimm_create()
606 nvdimm->cmd_mask = cmd_mask; in __nvdimm_create()
607 nvdimm->num_flush = num_flush; in __nvdimm_create()
608 nvdimm->flush_wpq = flush_wpq; in __nvdimm_create()
609 atomic_set(&nvdimm->busy, 0); in __nvdimm_create()
610 dev = &nvdimm->dev; in __nvdimm_create()
611 dev_set_name(dev, "nmem%d", nvdimm->id); in __nvdimm_create()
612 dev->parent = &nvdimm_bus->dev; in __nvdimm_create()
613 dev->type = &nvdimm_device_type; in __nvdimm_create()
614 dev->devt = MKDEV(nvdimm_major, nvdimm->id); in __nvdimm_create()
615 dev->groups = groups; in __nvdimm_create()
616 nvdimm->sec.ops = sec_ops; in __nvdimm_create()
617 nvdimm->fw_ops = fw_ops; in __nvdimm_create()
618 nvdimm->sec.overwrite_tmo = 0; in __nvdimm_create()
619 INIT_DELAYED_WORK(&nvdimm->dwork, nvdimm_security_overwrite_query); in __nvdimm_create()
621 * Security state must be initialized before device_add() for in __nvdimm_create()
624 /* get security state and extended (master) state */ in __nvdimm_create()
625 nvdimm->sec.flags = nvdimm_security_flags(nvdimm, NVDIMM_USER); in __nvdimm_create()
626 nvdimm->sec.ext_flags = nvdimm_security_flags(nvdimm, NVDIMM_MASTER); in __nvdimm_create()
628 lockdep_set_class(&dev->mutex, &nvdimm_key); in __nvdimm_create()
640 struct device *dev = &nvdimm->dev; in nvdimm_delete()
643 /* We are shutting down. Make state frozen artificially. */ in nvdimm_delete()
645 set_bit(NVDIMM_SECURITY_FROZEN, &nvdimm->sec.flags); in nvdimm_delete()
646 if (test_and_clear_bit(NDD_WORK_PENDING, &nvdimm->flags)) in nvdimm_delete()
649 cancel_delayed_work_sync(&nvdimm->dwork); in nvdimm_delete()
660 sysfs_put(nvdimm->sec.overwrite_state); in shutdown_security_notify()
667 if (!nvdimm->sec.flags || !nvdimm->sec.ops in nvdimm_security_setup_events()
668 || !nvdimm->sec.ops->overwrite) in nvdimm_security_setup_events()
670 nvdimm->sec.overwrite_state = sysfs_get_dirent(dev->kobj.sd, "security"); in nvdimm_security_setup_events()
671 if (!nvdimm->sec.overwrite_state) in nvdimm_security_setup_events()
672 return -ENOMEM; in nvdimm_security_setup_events()
680 return test_bit(NDD_SECURITY_OVERWRITE, &nvdimm->flags); in nvdimm_in_overwrite()
688 WARN_ON_ONCE(!is_nvdimm_bus_locked(&nvdimm->dev)); in nvdimm_security_freeze()
690 if (!nvdimm->sec.ops || !nvdimm->sec.ops->freeze) in nvdimm_security_freeze()
691 return -EOPNOTSUPP; in nvdimm_security_freeze()
693 if (!nvdimm->sec.flags) in nvdimm_security_freeze()
694 return -EIO; in nvdimm_security_freeze()
696 if (test_bit(NDD_SECURITY_OVERWRITE, &nvdimm->flags)) { in nvdimm_security_freeze()
697 dev_warn(&nvdimm->dev, "Overwrite operation in progress.\n"); in nvdimm_security_freeze()
698 return -EBUSY; in nvdimm_security_freeze()
701 rc = nvdimm->sec.ops->freeze(nvdimm); in nvdimm_security_freeze()
702 nvdimm->sec.flags = nvdimm_security_flags(nvdimm, NVDIMM_USER); in nvdimm_security_freeze()
709 struct device *dev = &nd_region->dev; in dpa_align()
714 if (dev_WARN_ONCE(dev, !nd_region->ndr_mappings || nd_region->align in dpa_align()
715 % nd_region->ndr_mappings, in dpa_align()
717 nd_region->align, nd_region->ndr_mappings)) in dpa_align()
719 return nd_region->align / nd_region->ndr_mappings; in dpa_align()
723 * nd_pmem_max_contiguous_dpa - For the given dimm+region, return the max
726 * @nd_mapping: container of dpa-resource-root + labels
748 nvdimm_bus = walk_to_nvdimm_bus(ndd->dev); in nd_pmem_max_contiguous_dpa()
749 if (__reserve_free_pmem(&nd_region->dev, nd_mapping->nvdimm)) in nd_pmem_max_contiguous_dpa()
754 if (strcmp(res->name, "pmem-reserve") != 0) in nd_pmem_max_contiguous_dpa()
757 start = ALIGN(res->start, align); in nd_pmem_max_contiguous_dpa()
758 end = ALIGN_DOWN(res->end + 1, align) - 1; in nd_pmem_max_contiguous_dpa()
761 if (end - start + 1 > max) in nd_pmem_max_contiguous_dpa()
762 max = end - start + 1; in nd_pmem_max_contiguous_dpa()
769 * nd_pmem_available_dpa - for the given dimm+region account unallocated dpa
770 * @nd_mapping: container of dpa-resource-root + labels
793 map_start = nd_mapping->start; in nd_pmem_available_dpa()
794 map_end = map_start + nd_mapping->size - 1; in nd_pmem_available_dpa()
798 start = ALIGN_DOWN(res->start, align); in nd_pmem_available_dpa()
799 end = ALIGN(res->end + 1, align) - 1; in nd_pmem_available_dpa()
806 busy += end - start + 1; in nd_pmem_available_dpa()
808 busy += end - start + 1; in nd_pmem_available_dpa()
811 busy += nd_mapping->size; in nd_pmem_available_dpa()
815 if (busy < nd_mapping->size) in nd_pmem_available_dpa()
816 return ALIGN_DOWN(nd_mapping->size - busy, align); in nd_pmem_available_dpa()
822 WARN_ON_ONCE(!is_nvdimm_bus_locked(ndd->dev)); in nvdimm_free_dpa()
823 kfree(res->name); in nvdimm_free_dpa()
824 __release_region(&ndd->dpa, res->start, resource_size(res)); in nvdimm_free_dpa()
837 WARN_ON_ONCE(!is_nvdimm_bus_locked(ndd->dev)); in nvdimm_allocate_dpa()
838 res = __request_region(&ndd->dpa, start, n, name, 0); in nvdimm_allocate_dpa()
845 * nvdimm_allocated_dpa - sum up the dpa currently allocated to this label_id
846 * @ndd: container of dpa-resource-root + labels
847 * @label_id: dpa resource name of the form pmem-<human readable uuid>
858 if (strcmp(res->name, label_id->id) == 0) in nvdimm_allocated_dpa()
879 device_for_each_child(&nvdimm_bus->dev, &count, count_dimms); in nvdimm_bus_check_dimm_count()
880 dev_dbg(&nvdimm_bus->dev, "count: %d\n", count); in nvdimm_bus_check_dimm_count()
882 return -ENXIO; in nvdimm_bus_check_dimm_count()