Lines Matching +full:activate +full:- +full:to +full:- +full:activate
1 // SPDX-License-Identifier: GPL-2.0-only
4 #include <linux/io-64-nonatomic-lo-hi.h>
29 ida_free(&cxl_memdev_ida, cxlmd->id); in cxl_memdev_release()
43 struct cxl_dev_state *cxlds = cxlmd->cxlds; in firmware_version_show()
48 return sysfs_emit(buf, "%.16s\n", mds->firmware_version); in firmware_version_show()
56 struct cxl_dev_state *cxlds = cxlmd->cxlds; in payload_max_show()
61 return sysfs_emit(buf, "%zu\n", cxlds->cxl_mbox.payload_size); in payload_max_show()
69 struct cxl_dev_state *cxlds = cxlmd->cxlds; in label_storage_size_show()
74 return sysfs_emit(buf, "%zu\n", mds->lsa_size); in label_storage_size_show()
82 struct cxl_dev_state *cxlds = cxlmd->cxlds; in ram_size_show()
83 unsigned long long len = resource_size(&cxlds->ram_res); in ram_size_show()
95 struct cxl_dev_state *cxlds = cxlmd->cxlds; in pmem_size_show()
96 unsigned long long len = resource_size(&cxlds->pmem_res); in pmem_size_show()
108 struct cxl_dev_state *cxlds = cxlmd->cxlds; in serial_show()
110 return sysfs_emit(buf, "%#llx\n", cxlds->serial); in serial_show()
126 struct cxl_dev_state *cxlds = cxlmd->cxlds; in security_state_show()
127 struct cxl_mailbox *cxl_mbox = &cxlds->cxl_mbox; in security_state_show()
129 unsigned long state = mds->security.state; in security_state_show()
133 mutex_lock(&cxl_mbox->mbox_mutex); in security_state_show()
134 if (mds->security.sanitize_active) in security_state_show()
136 mutex_unlock(&cxl_mbox->mbox_mutex); in security_state_show()
163 return -EINVAL; in security_sanitize_store()
183 return -EINVAL; in security_erase_store()
196 struct cxl_dev_state *cxlds = cxlmd->cxlds; in cxl_get_poison_by_memdev()
201 if (resource_size(&cxlds->pmem_res)) { in cxl_get_poison_by_memdev()
202 offset = cxlds->pmem_res.start; in cxl_get_poison_by_memdev()
203 length = resource_size(&cxlds->pmem_res); in cxl_get_poison_by_memdev()
208 if (resource_size(&cxlds->ram_res)) { in cxl_get_poison_by_memdev()
209 offset = cxlds->ram_res.start; in cxl_get_poison_by_memdev()
210 length = resource_size(&cxlds->ram_res); in cxl_get_poison_by_memdev()
216 if (rc == -EFAULT) in cxl_get_poison_by_memdev()
227 port = cxlmd->endpoint; in cxl_trigger_poison_list()
229 return -EINVAL; in cxl_trigger_poison_list()
242 /* No regions mapped to this memdev */ in cxl_trigger_poison_list()
257 struct cxl_dev_state *cxlds = cxlmd->cxlds; in cxl_validate_poison_dpa()
262 if (!resource_size(&cxlds->dpa_res)) { in cxl_validate_poison_dpa()
263 dev_dbg(cxlds->dev, "device has no dpa resource\n"); in cxl_validate_poison_dpa()
264 return -EINVAL; in cxl_validate_poison_dpa()
266 if (dpa < cxlds->dpa_res.start || dpa > cxlds->dpa_res.end) { in cxl_validate_poison_dpa()
267 dev_dbg(cxlds->dev, "dpa:0x%llx not in resource:%pR\n", in cxl_validate_poison_dpa()
268 dpa, &cxlds->dpa_res); in cxl_validate_poison_dpa()
269 return -EINVAL; in cxl_validate_poison_dpa()
272 dev_dbg(cxlds->dev, "dpa:0x%llx is not 64-byte aligned\n", dpa); in cxl_validate_poison_dpa()
273 return -EINVAL; in cxl_validate_poison_dpa()
281 struct cxl_mailbox *cxl_mbox = &cxlmd->cxlds->cxl_mbox; in cxl_inject_poison()
317 dev_warn_once(cxl_mbox->host, in cxl_inject_poison()
319 dev_name(&cxlr->dev)); in cxl_inject_poison()
336 struct cxl_mailbox *cxl_mbox = &cxlmd->cxlds->cxl_mbox; in cxl_clear_poison()
362 * is defined to accept 64 bytes of write-data, along with the in cxl_clear_poison()
363 * address to clear. This driver uses zeroes as write-data. in cxl_clear_poison()
381 dev_warn_once(cxl_mbox->host, in cxl_clear_poison()
383 dev_name(&cxlr->dev)); in cxl_clear_poison()
411 struct cxl_dev_state *cxlds = cxlmd->cxlds; in pmem_qos_class_show()
414 return sysfs_emit(buf, "%d\n", mds->pmem_perf.qos_class); in pmem_qos_class_show()
430 struct cxl_dev_state *cxlds = cxlmd->cxlds; in ram_qos_class_show()
433 return sysfs_emit(buf, "%d\n", mds->ram_perf.qos_class); in ram_qos_class_show()
457 return a->mode; in cxl_memdev_visible()
469 struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlmd->cxlds); in cxl_ram_visible()
472 if (mds->ram_perf.qos_class == CXL_QOS_CLASS_INVALID) in cxl_ram_visible()
475 return a->mode; in cxl_ram_visible()
488 struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlmd->cxlds); in cxl_pmem_visible()
491 if (mds->pmem_perf.qos_class == CXL_QOS_CLASS_INVALID) in cxl_pmem_visible()
494 return a->mode; in cxl_pmem_visible()
508 struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlmd->cxlds); in cxl_memdev_security_visible()
511 !test_bit(CXL_SEC_ENABLED_SANITIZE, mds->security.enabled_cmds)) in cxl_memdev_security_visible()
515 !test_bit(CXL_SEC_ENABLED_SECURE_ERASE, mds->security.enabled_cmds)) in cxl_memdev_security_visible()
518 return a->mode; in cxl_memdev_security_visible()
537 sysfs_update_group(&cxlmd->dev.kobj, &cxl_memdev_ram_attribute_group); in cxl_memdev_update_perf()
538 sysfs_update_group(&cxlmd->dev.kobj, &cxl_memdev_pmem_attribute_group); in cxl_memdev_update_perf()
551 return dev->type == &cxl_memdev_type; in is_cxl_memdev()
556 * set_exclusive_cxl_commands() - atomically disable user cxl commands
557 * @mds: The device state to operate on
558 * @cmds: bitmap of commands to mark exclusive
560 * Grab the cxl_memdev_rwsem in write mode to flush in-flight
568 bitmap_or(mds->exclusive_cmds, mds->exclusive_cmds, cmds, in set_exclusive_cxl_commands()
575 * clear_exclusive_cxl_commands() - atomically enable user cxl commands
576 * @mds: The device state to modify
577 * @cmds: bitmap of commands to mark available for userspace
583 bitmap_andnot(mds->exclusive_cmds, mds->exclusive_cmds, cmds, in clear_exclusive_cxl_commands()
594 cxlmd->cxlds = NULL; in cxl_memdev_shutdown()
601 struct device *dev = &cxlmd->dev; in cxl_memdev_unregister()
603 cdev_device_del(&cxlmd->cdev, dev); in cxl_memdev_unregister()
613 device_release_driver(&cxlmd->dev); in detach_memdev()
614 put_device(&cxlmd->dev); in detach_memdev()
629 return ERR_PTR(-ENOMEM); in cxl_memdev_alloc()
631 rc = ida_alloc_max(&cxl_memdev_ida, CXL_MEM_MAX_DEVS - 1, GFP_KERNEL); in cxl_memdev_alloc()
634 cxlmd->id = rc; in cxl_memdev_alloc()
635 cxlmd->depth = -1; in cxl_memdev_alloc()
637 dev = &cxlmd->dev; in cxl_memdev_alloc()
639 lockdep_set_class(&dev->mutex, &cxl_memdev_key); in cxl_memdev_alloc()
640 dev->parent = cxlds->dev; in cxl_memdev_alloc()
641 dev->bus = &cxl_bus_type; in cxl_memdev_alloc()
642 dev->devt = MKDEV(cxl_mem_major, cxlmd->id); in cxl_memdev_alloc()
643 dev->type = &cxl_memdev_type; in cxl_memdev_alloc()
645 INIT_WORK(&cxlmd->detach_work, detach_memdev); in cxl_memdev_alloc()
647 cdev = &cxlmd->cdev; in cxl_memdev_alloc()
665 return -ENOTTY; in __cxl_memdev_ioctl()
672 struct cxl_memdev *cxlmd = file->private_data; in cxl_memdev_ioctl()
674 int rc = -ENXIO; in cxl_memdev_ioctl()
677 cxlds = cxlmd->cxlds; in cxl_memdev_ioctl()
678 if (cxlds && cxlds->type == CXL_DEVTYPE_CLASSMEM) in cxl_memdev_ioctl()
688 container_of(inode->i_cdev, typeof(*cxlmd), cdev); in cxl_memdev_open()
690 get_device(&cxlmd->dev); in cxl_memdev_open()
691 file->private_data = cxlmd; in cxl_memdev_open()
699 container_of(inode->i_cdev, typeof(*cxlmd), cdev); in cxl_memdev_release_file()
701 put_device(&cxlmd->dev); in cxl_memdev_release_file()
707 * cxl_mem_get_fw_info - Get Firmware info
714 * See CXL-3.0 8.2.9.3.1 Get FW Info
718 struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox; in cxl_mem_get_fw_info()
733 mds->fw.num_slots = info.num_slots; in cxl_mem_get_fw_info()
734 mds->fw.cur_slot = FIELD_GET(CXL_FW_INFO_SLOT_INFO_CUR_MASK, in cxl_mem_get_fw_info()
741 * cxl_mem_activate_fw - Activate Firmware
743 * @slot: slot number to activate
745 * Activate firmware in a given slot for the device specified.
749 * See CXL-3.0 8.2.9.3.3 Activate FW
753 struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox; in cxl_mem_activate_fw()
754 struct cxl_mbox_activate_fw activate; in cxl_mem_activate_fw() local
757 if (slot == 0 || slot > mds->fw.num_slots) in cxl_mem_activate_fw()
758 return -EINVAL; in cxl_mem_activate_fw()
762 .size_in = sizeof(activate), in cxl_mem_activate_fw()
763 .payload_in = &activate, in cxl_mem_activate_fw()
767 activate.action = CXL_FW_ACTIVATE_OFFLINE; in cxl_mem_activate_fw()
768 activate.slot = slot; in cxl_mem_activate_fw()
774 * cxl_mem_abort_fw_xfer - Abort an in-progress FW transfer
777 * Abort an in-progress firmware transfer for the device specified.
781 * See CXL-3.0 8.2.9.3.2 Transfer FW
785 struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox; in cxl_mem_abort_fw_xfer()
792 return -ENOMEM; in cxl_mem_abort_fw_xfer()
803 transfer->action = CXL_FW_TRANSFER_ACTION_ABORT; in cxl_mem_abort_fw_xfer()
812 struct cxl_memdev_state *mds = fwl->dd_handle; in cxl_fw_cleanup()
814 mds->fw.next_slot = 0; in cxl_fw_cleanup()
819 struct cxl_memdev_state *mds = fwl->dd_handle; in cxl_fw_do_cancel()
820 struct cxl_dev_state *cxlds = &mds->cxlds; in cxl_fw_do_cancel()
821 struct cxl_memdev *cxlmd = cxlds->cxlmd; in cxl_fw_do_cancel()
826 dev_err(&cxlmd->dev, "Error aborting FW transfer: %d\n", rc); in cxl_fw_do_cancel()
834 struct cxl_memdev_state *mds = fwl->dd_handle; in cxl_fw_prepare()
836 struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox; in cxl_fw_prepare()
841 mds->fw.oneshot = struct_size(transfer, data, size) < in cxl_fw_prepare()
842 cxl_mbox->payload_size; in cxl_fw_prepare()
851 if (test_and_clear_bit(CXL_FW_CANCEL, mds->fw.state)) in cxl_fw_prepare()
860 struct cxl_memdev_state *mds = fwl->dd_handle; in cxl_fw_write()
861 struct cxl_dev_state *cxlds = &mds->cxlds; in cxl_fw_write()
862 struct cxl_mailbox *cxl_mbox = &cxlds->cxl_mbox; in cxl_fw_write()
863 struct cxl_memdev *cxlmd = cxlds->cxlmd; in cxl_fw_write()
872 /* Offset has to be aligned to 128B (CXL-3.0 8.2.9.3.2 Table 8-57) */ in cxl_fw_write()
874 dev_err(&cxlmd->dev, in cxl_fw_write()
881 * Pick transfer size based on mds->payload_size @size must bw 128-byte in cxl_fw_write()
882 * aligned, ->payload_size is a power of 2 starting at 256 bytes, and in cxl_fw_write()
886 cur_size = min_t(size_t, size, cxl_mbox->payload_size - sizeof(*transfer)); in cxl_fw_write()
888 remaining = size - cur_size; in cxl_fw_write()
891 if (test_and_clear_bit(CXL_FW_CANCEL, mds->fw.state)) in cxl_fw_write()
895 * Slot numbers are 1-indexed in cxl_fw_write()
896 * cur_slot is the 0-indexed next_slot (i.e. 'cur_slot - 1 + 1') in cxl_fw_write()
897 * Check for rollover using modulo, and 1-index it by adding 1 in cxl_fw_write()
899 mds->fw.next_slot = (mds->fw.cur_slot % mds->fw.num_slots) + 1; in cxl_fw_write()
906 transfer->offset = cpu_to_le32(offset / CXL_FW_TRANSFER_ALIGNMENT); in cxl_fw_write()
907 memcpy(transfer->data, data + offset, cur_size); in cxl_fw_write()
908 if (mds->fw.oneshot) { in cxl_fw_write()
909 transfer->action = CXL_FW_TRANSFER_ACTION_FULL; in cxl_fw_write()
910 transfer->slot = mds->fw.next_slot; in cxl_fw_write()
913 transfer->action = CXL_FW_TRANSFER_ACTION_INITIATE; in cxl_fw_write()
915 transfer->action = CXL_FW_TRANSFER_ACTION_END; in cxl_fw_write()
916 transfer->slot = mds->fw.next_slot; in cxl_fw_write()
918 transfer->action = CXL_FW_TRANSFER_ACTION_CONTINUE; in cxl_fw_write()
938 /* Activate FW if oneshot or if the last slice was written */ in cxl_fw_write()
939 if (mds->fw.oneshot || remaining == 0) { in cxl_fw_write()
940 dev_dbg(&cxlmd->dev, "Activating firmware slot: %d\n", in cxl_fw_write()
941 mds->fw.next_slot); in cxl_fw_write()
942 rc = cxl_mem_activate_fw(mds, mds->fw.next_slot); in cxl_fw_write()
944 dev_err(&cxlmd->dev, "Error activating firmware: %d\n", in cxl_fw_write()
960 struct cxl_memdev_state *mds = fwl->dd_handle; in cxl_fw_poll_complete()
964 * No need to wait for completions here - any errors would've been in cxl_fw_poll_complete()
965 * reported and handled during the ->write() call(s). in cxl_fw_poll_complete()
968 if (test_and_clear_bit(CXL_FW_CANCEL, mds->fw.state)) in cxl_fw_poll_complete()
976 struct cxl_memdev_state *mds = fwl->dd_handle; in cxl_fw_cancel()
978 set_bit(CXL_FW_CANCEL, mds->fw.state); in cxl_fw_cancel()
996 struct cxl_dev_state *cxlds = &mds->cxlds; in devm_cxl_setup_fw_upload()
997 struct device *dev = &cxlds->cxlmd->dev; in devm_cxl_setup_fw_upload()
1000 if (!test_bit(CXL_MEM_COMMAND_ID_GET_FW_INFO, mds->enabled_cmds)) in devm_cxl_setup_fw_upload()
1032 dev = &cxlmd->dev; in devm_cxl_add_memdev()
1033 rc = dev_set_name(dev, "mem%d", cxlmd->id); in devm_cxl_add_memdev()
1038 * Activate ioctl operations, no cxl_memdev_rwsem manipulation in devm_cxl_add_memdev()
1041 cxlmd->cxlds = cxlds; in devm_cxl_add_memdev()
1042 cxlds->cxlmd = cxlmd; in devm_cxl_add_memdev()
1044 cdev = &cxlmd->cdev; in devm_cxl_add_memdev()
1068 struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox; in sanitize_teardown_notifier()
1075 mutex_lock(&cxl_mbox->mbox_mutex); in sanitize_teardown_notifier()
1076 state = mds->security.sanitize_node; in sanitize_teardown_notifier()
1077 mds->security.sanitize_node = NULL; in sanitize_teardown_notifier()
1078 mutex_unlock(&cxl_mbox->mbox_mutex); in sanitize_teardown_notifier()
1080 cancel_delayed_work_sync(&mds->security.poll_dwork); in sanitize_teardown_notifier()
1087 struct cxl_dev_state *cxlds = cxlmd->cxlds; in devm_cxl_sanitize_setup_notifier()
1091 if (!test_bit(CXL_SEC_ENABLED_SANITIZE, mds->security.enabled_cmds)) in devm_cxl_sanitize_setup_notifier()
1095 * Note, the expectation is that @cxlmd would have failed to be in devm_cxl_sanitize_setup_notifier()
1098 sec = sysfs_get_dirent(cxlmd->dev.kobj.sd, "security"); in devm_cxl_sanitize_setup_notifier()
1100 return -ENOENT; in devm_cxl_sanitize_setup_notifier()
1101 mds->security.sanitize_node = sysfs_get_dirent(sec, "state"); in devm_cxl_sanitize_setup_notifier()
1103 if (!mds->security.sanitize_node) in devm_cxl_sanitize_setup_notifier()
1104 return -ENOENT; in devm_cxl_sanitize_setup_notifier()