From b0dc2feab3271dbcb42df6e6d8a37138a90c44a1 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 5 Nov 2022 19:17:21 +0100 Subject: Merging upstream version 1.2. Signed-off-by: Daniel Baumann --- .github/cross/ubuntu-armhf.txt | 17 + .github/cross/ubuntu-ppc64le.txt | 17 + .github/workflows/meson.yml | 60 + .github/workflows/python-publish.yml | 12 +- .github/workflows/release.yml | 2 +- Makefile | 4 + doc/conf.py | 2 +- doc/config-schema.json | 4 + doc/config-schema.json.in | 4 + doc/list-man-pages.sh | 6 +- doc/list-pre-compiled.sh | 5 + doc/man/nvme_admin_opcode.2 | 2 +- doc/man/nvme_admin_passthru.2 | 2 +- doc/man/nvme_admin_passthru64.2 | 71 + doc/man/nvme_ae_info_css_nvm.2 | 2 +- doc/man/nvme_ae_info_error.2 | 2 +- doc/man/nvme_ae_info_notice.2 | 2 +- doc/man/nvme_ae_info_smart.2 | 2 +- doc/man/nvme_ae_type.2 | 2 +- doc/man/nvme_aggregate_endurance_group_event.2 | 2 +- doc/man/nvme_aggregate_predictable_lat_event.2 | 2 +- doc/man/nvme_ana_group_desc.2 | 2 +- doc/man/nvme_ana_log.2 | 2 +- doc/man/nvme_ana_state.2 | 2 +- doc/man/nvme_apst_entry.2 | 2 +- doc/man/nvme_boot_partition.2 | 2 +- doc/man/nvme_capacity_config_desc.2 | 2 +- doc/man/nvme_capacity_mgmt.2 | 2 +- doc/man/nvme_change_ns_event.2 | 2 +- doc/man/nvme_channel_config_desc.2 | 2 +- doc/man/nvme_cmb_size.2 | 2 +- doc/man/nvme_cmd_effects.2 | 2 +- doc/man/nvme_cmd_effects_log.2 | 2 +- doc/man/nvme_cmd_format_mset.2 | 2 +- doc/man/nvme_cmd_format_pi.2 | 2 +- doc/man/nvme_cmd_format_pil.2 | 2 +- doc/man/nvme_cmd_format_ses.2 | 2 +- doc/man/nvme_cmd_get_log_lid.2 | 2 +- doc/man/nvme_cmd_get_log_telemetry_host_lsp.2 | 2 +- doc/man/nvme_compare.2 | 2 +- doc/man/nvme_connect_err.2 | 2 +- doc/man/nvme_constants.2 | 2 +- doc/man/nvme_copy.2 | 2 +- doc/man/nvme_copy_range.2 | 2 +- doc/man/nvme_copy_range_f1.2 | 40 + doc/man/nvme_create_ctrl.2 | 2 +- doc/man/nvme_create_root.2 | 2 +- doc/man/nvme_csi.2 | 2 +- doc/man/nvme_ctrl_first_ns.2 | 2 +- doc/man/nvme_ctrl_first_path.2 | 2 +- doc/man/nvme_ctrl_for_each_ns.2 | 2 +- doc/man/nvme_ctrl_for_each_ns_safe.2 | 2 +- doc/man/nvme_ctrl_for_each_path.2 | 2 +- doc/man/nvme_ctrl_for_each_path_safe.2 | 2 +- doc/man/nvme_ctrl_get_address.2 | 2 +- doc/man/nvme_ctrl_get_config.2 | 2 +- doc/man/nvme_ctrl_get_dhchap_host_key.2 | 11 + doc/man/nvme_ctrl_get_dhchap_key.2 | 2 +- doc/man/nvme_ctrl_get_fd.2 | 2 +- doc/man/nvme_ctrl_get_firmware.2 | 2 +- doc/man/nvme_ctrl_get_host_iface.2 | 2 +- doc/man/nvme_ctrl_get_host_traddr.2 | 2 +- doc/man/nvme_ctrl_get_model.2 | 2 +- doc/man/nvme_ctrl_get_name.2 | 2 +- doc/man/nvme_ctrl_get_numa_node.2 | 2 +- doc/man/nvme_ctrl_get_queue_count.2 | 2 +- doc/man/nvme_ctrl_get_serial.2 | 2 +- doc/man/nvme_ctrl_get_sqsize.2 | 2 +- doc/man/nvme_ctrl_get_state.2 | 2 +- doc/man/nvme_ctrl_get_subsysnqn.2 | 2 +- doc/man/nvme_ctrl_get_subsystem.2 | 2 +- doc/man/nvme_ctrl_get_sysfs_dir.2 | 2 +- doc/man/nvme_ctrl_get_traddr.2 | 2 +- doc/man/nvme_ctrl_get_transport.2 | 2 +- doc/man/nvme_ctrl_get_trsvcid.2 | 2 +- doc/man/nvme_ctrl_identify.2 | 2 +- doc/man/nvme_ctrl_is_discovered.2 | 2 +- doc/man/nvme_ctrl_is_discovery_ctrl.2 | 2 +- doc/man/nvme_ctrl_is_persistent.2 | 2 +- doc/man/nvme_ctrl_list.2 | 2 +- doc/man/nvme_ctrl_metadata_type.2 | 2 +- doc/man/nvme_ctrl_next_ns.2 | 2 +- doc/man/nvme_ctrl_next_path.2 | 2 +- doc/man/nvme_ctrl_reset.2 | 2 +- doc/man/nvme_ctrl_set_dhchap_host_key.2 | 12 + doc/man/nvme_ctrl_set_dhchap_key.2 | 2 +- doc/man/nvme_ctrl_set_discovered.2 | 2 +- doc/man/nvme_ctrl_set_discovery_ctrl.2 | 2 +- doc/man/nvme_ctrl_set_persistent.2 | 2 +- doc/man/nvme_ctrls_filter.2 | 2 +- doc/man/nvme_data_tfr.2 | 30 + doc/man/nvme_default_host.2 | 2 +- doc/man/nvme_dev_self_test.2 | 2 +- doc/man/nvme_directive_dtype.2 | 2 +- doc/man/nvme_directive_receive_doper.2 | 2 +- doc/man/nvme_directive_recv.2 | 2 +- doc/man/nvme_directive_recv_identify_parameters.2 | 2 +- doc/man/nvme_directive_recv_stream_allocate.2 | 2 +- doc/man/nvme_directive_recv_stream_parameters.2 | 2 +- doc/man/nvme_directive_recv_stream_status.2 | 2 +- doc/man/nvme_directive_send.2 | 2 +- doc/man/nvme_directive_send_doper.2 | 2 +- doc/man/nvme_directive_send_id_endir.2 | 2 +- doc/man/nvme_directive_send_identify_endir.2 | 2 +- ...nvme_directive_send_stream_release_identifier.2 | 2 +- .../nvme_directive_send_stream_release_resource.2 | 2 +- doc/man/nvme_directive_types.2 | 2 +- doc/man/nvme_disconnect_ctrl.2 | 2 +- doc/man/nvme_dsm.2 | 2 +- doc/man/nvme_dsm_attributes.2 | 2 +- doc/man/nvme_dsm_range.2 | 2 +- doc/man/nvme_dst_stc.2 | 2 +- doc/man/nvme_dump_config.2 | 2 +- doc/man/nvme_dump_tree.2 | 2 +- doc/man/nvme_eg_critical_warning_flags.2 | 2 +- doc/man/nvme_eg_event_aggregate_log.2 | 2 +- doc/man/nvme_end_grp_chan_desc.2 | 2 +- doc/man/nvme_end_grp_config_desc.2 | 2 +- doc/man/nvme_endurance_group_log.2 | 2 +- doc/man/nvme_errno_to_string.2 | 2 +- doc/man/nvme_error_log_page.2 | 2 +- doc/man/nvme_fabrics_config.2 | 2 +- doc/man/nvme_fctype.2 | 2 +- doc/man/nvme_feat.2 | 2 +- doc/man/nvme_feat_auto_pst.2 | 2 +- doc/man/nvme_feat_host_behavior.2 | 2 +- doc/man/nvme_feat_nswpcfg_state.2 | 2 +- doc/man/nvme_feat_plm_window_select.2 | 2 +- doc/man/nvme_feat_resv_notify_flags.2 | 2 +- doc/man/nvme_feat_tmpthresh_thsel.2 | 2 +- doc/man/nvme_features_async_event_config_flags.2 | 2 +- doc/man/nvme_features_id.2 | 2 +- doc/man/nvme_fid_supported_effects.2 | 2 +- doc/man/nvme_fid_supported_effects_log.2 | 2 +- doc/man/nvme_firmware_slot.2 | 2 +- doc/man/nvme_first_host.2 | 2 +- doc/man/nvme_first_subsystem.2 | 2 +- doc/man/nvme_flush.2 | 2 +- doc/man/nvme_for_each_host.2 | 2 +- doc/man/nvme_for_each_host_safe.2 | 2 +- doc/man/nvme_for_each_subsystem.2 | 2 +- doc/man/nvme_for_each_subsystem_safe.2 | 2 +- doc/man/nvme_format_nvm.2 | 2 +- doc/man/nvme_format_nvm_compln_event.2 | 2 +- doc/man/nvme_format_nvm_start_event.2 | 2 +- doc/man/nvme_free_ctrl.2 | 2 +- doc/man/nvme_free_host.2 | 2 +- doc/man/nvme_free_ns.2 | 2 +- doc/man/nvme_free_subsystem.2 | 2 +- doc/man/nvme_free_tree.2 | 2 +- doc/man/nvme_fw_commit.2 | 2 +- doc/man/nvme_fw_commit_ca.2 | 2 +- doc/man/nvme_fw_commit_event.2 | 2 +- doc/man/nvme_fw_download.2 | 2 +- doc/man/nvme_fw_download_seq.2 | 2 +- doc/man/nvme_gen_dhchap_key.2 | 2 +- doc/man/nvme_get_ana_log_len.2 | 2 +- doc/man/nvme_get_attr.2 | 2 +- doc/man/nvme_get_ctrl_attr.2 | 2 +- doc/man/nvme_get_ctrl_telemetry.2 | 2 +- doc/man/nvme_get_directive_receive_length.2 | 2 +- doc/man/nvme_get_discovery_args.2 | 35 + doc/man/nvme_get_feature_length.2 | 2 +- doc/man/nvme_get_feature_length2.2 | 24 + doc/man/nvme_get_features.2 | 2 +- doc/man/nvme_get_features_arbitration.2 | 2 +- doc/man/nvme_get_features_async_event.2 | 2 +- doc/man/nvme_get_features_auto_pst.2 | 2 +- doc/man/nvme_get_features_data.2 | 2 +- doc/man/nvme_get_features_endurance_event_cfg.2 | 2 +- doc/man/nvme_get_features_err_recovery.2 | 2 +- doc/man/nvme_get_features_hctm.2 | 2 +- doc/man/nvme_get_features_host_behavior.2 | 2 +- doc/man/nvme_get_features_host_id.2 | 2 +- doc/man/nvme_get_features_host_mem_buf.2 | 2 +- doc/man/nvme_get_features_iocs_profile.2 | 2 +- doc/man/nvme_get_features_irq_coalesce.2 | 2 +- doc/man/nvme_get_features_irq_config.2 | 2 +- doc/man/nvme_get_features_kato.2 | 2 +- doc/man/nvme_get_features_lba_range.2 | 2 +- doc/man/nvme_get_features_lba_sts_interval.2 | 2 +- doc/man/nvme_get_features_nopsc.2 | 2 +- doc/man/nvme_get_features_num_queues.2 | 2 +- doc/man/nvme_get_features_plm_config.2 | 2 +- doc/man/nvme_get_features_plm_window.2 | 2 +- doc/man/nvme_get_features_power_mgmt.2 | 2 +- doc/man/nvme_get_features_resv_mask.2 | 2 +- doc/man/nvme_get_features_resv_persist.2 | 2 +- doc/man/nvme_get_features_rrl.2 | 2 +- doc/man/nvme_get_features_sanitize.2 | 2 +- doc/man/nvme_get_features_sel.2 | 2 +- doc/man/nvme_get_features_simple.2 | 2 +- doc/man/nvme_get_features_sw_progress.2 | 2 +- doc/man/nvme_get_features_temp_thresh.2 | 2 +- doc/man/nvme_get_features_timestamp.2 | 2 +- doc/man/nvme_get_features_volatile_wc.2 | 2 +- doc/man/nvme_get_features_write_atomic.2 | 2 +- doc/man/nvme_get_features_write_protect.2 | 2 +- doc/man/nvme_get_host_telemetry.2 | 2 +- doc/man/nvme_get_lba_status.2 | 2 +- doc/man/nvme_get_lba_status_log.2 | 2 +- doc/man/nvme_get_log.2 | 2 +- doc/man/nvme_get_log_ana.2 | 2 +- doc/man/nvme_get_log_ana_groups.2 | 2 +- doc/man/nvme_get_log_boot_partition.2 | 2 +- doc/man/nvme_get_log_changed_ns_list.2 | 2 +- doc/man/nvme_get_log_cmd_effects.2 | 2 +- doc/man/nvme_get_log_create_telemetry_host.2 | 2 +- doc/man/nvme_get_log_device_self_test.2 | 2 +- doc/man/nvme_get_log_discovery.2 | 2 +- doc/man/nvme_get_log_endurance_group.2 | 2 +- doc/man/nvme_get_log_endurance_grp_evt.2 | 2 +- doc/man/nvme_get_log_error.2 | 2 +- doc/man/nvme_get_log_fid_supported_effects.2 | 2 +- doc/man/nvme_get_log_fw_slot.2 | 2 +- doc/man/nvme_get_log_lba_status.2 | 2 +- doc/man/nvme_get_log_media_unit_stat.2 | 2 +- doc/man/nvme_get_log_mi_cmd_supported_effects.2 | 2 +- doc/man/nvme_get_log_page.2 | 2 +- doc/man/nvme_get_log_persistent_event.2 | 2 +- doc/man/nvme_get_log_predictable_lat_event.2 | 2 +- doc/man/nvme_get_log_predictable_lat_nvmset.2 | 2 +- doc/man/nvme_get_log_reservation.2 | 2 +- doc/man/nvme_get_log_sanitize.2 | 2 +- doc/man/nvme_get_log_smart.2 | 2 +- doc/man/nvme_get_log_support_cap_config_list.2 | 2 +- doc/man/nvme_get_log_supported_log_pages.2 | 2 +- doc/man/nvme_get_log_telemetry_ctrl.2 | 2 +- doc/man/nvme_get_log_telemetry_host.2 | 2 +- doc/man/nvme_get_log_zns_changed_zones.2 | 2 +- doc/man/nvme_get_logical_block_size.2 | 2 +- doc/man/nvme_get_new_host_telemetry.2 | 2 +- doc/man/nvme_get_ns_attr.2 | 2 +- doc/man/nvme_get_nsid.2 | 2 +- doc/man/nvme_get_path_attr.2 | 2 +- doc/man/nvme_get_property.2 | 2 +- doc/man/nvme_get_subsys_attr.2 | 2 +- doc/man/nvme_hmac_alg.2 | 2 +- doc/man/nvme_host_behavior_support.2 | 2 +- doc/man/nvme_host_get_dhchap_key.2 | 2 +- doc/man/nvme_host_get_hostid.2 | 2 +- doc/man/nvme_host_get_hostnqn.2 | 2 +- doc/man/nvme_host_get_hostsymname.2 | 2 +- doc/man/nvme_host_get_root.2 | 2 +- doc/man/nvme_host_mem_buf_attrs.2 | 2 +- doc/man/nvme_host_metadata.2 | 2 +- doc/man/nvme_host_set_dhchap_key.2 | 2 +- doc/man/nvme_host_set_hostsymname.2 | 2 +- doc/man/nvme_id_ctrl.2 | 2 +- doc/man/nvme_id_ctrl_anacap.2 | 2 +- doc/man/nvme_id_ctrl_apsta.2 | 2 +- doc/man/nvme_id_ctrl_avscc.2 | 2 +- doc/man/nvme_id_ctrl_cmic.2 | 2 +- doc/man/nvme_id_ctrl_cntrltype.2 | 2 +- doc/man/nvme_id_ctrl_cqes.2 | 2 +- doc/man/nvme_id_ctrl_ctratt.2 | 2 +- doc/man/nvme_id_ctrl_dctype.2 | 2 +- doc/man/nvme_id_ctrl_dsto.2 | 2 +- doc/man/nvme_id_ctrl_fcatt.2 | 2 +- doc/man/nvme_id_ctrl_fna.2 | 2 +- doc/man/nvme_id_ctrl_frmw.2 | 2 +- doc/man/nvme_id_ctrl_fuses.2 | 2 +- doc/man/nvme_id_ctrl_hctm.2 | 2 +- doc/man/nvme_id_ctrl_lpa.2 | 2 +- doc/man/nvme_id_ctrl_mec.2 | 2 +- doc/man/nvme_id_ctrl_nvm.2 | 2 +- doc/man/nvme_id_ctrl_nvmsr.2 | 2 +- doc/man/nvme_id_ctrl_nvscc.2 | 2 +- doc/man/nvme_id_ctrl_nwpc.2 | 2 +- doc/man/nvme_id_ctrl_oacs.2 | 2 +- doc/man/nvme_id_ctrl_oaes.2 | 2 +- doc/man/nvme_id_ctrl_ofcs.2 | 2 +- doc/man/nvme_id_ctrl_oncs.2 | 2 +- doc/man/nvme_id_ctrl_rpmbs.2 | 2 +- doc/man/nvme_id_ctrl_sanicap.2 | 2 +- doc/man/nvme_id_ctrl_sgls.2 | 2 +- doc/man/nvme_id_ctrl_sqes.2 | 2 +- doc/man/nvme_id_ctrl_vwc.2 | 2 +- doc/man/nvme_id_ctrl_vwci.2 | 2 +- doc/man/nvme_id_directives.2 | 2 +- doc/man/nvme_id_domain_attr.2 | 2 +- doc/man/nvme_id_domain_list.2 | 2 +- doc/man/nvme_id_endurance_group_list.2 | 2 +- doc/man/nvme_id_independent_id_ns.2 | 2 +- doc/man/nvme_id_iocs.2 | 2 +- doc/man/nvme_id_ns.2 | 2 +- doc/man/nvme_id_ns_attr.2 | 2 +- doc/man/nvme_id_ns_dlfeat.2 | 2 +- doc/man/nvme_id_ns_dpc.2 | 2 +- doc/man/nvme_id_ns_dps.2 | 2 +- doc/man/nvme_id_ns_flbas.2 | 2 +- doc/man/nvme_id_ns_granularity_desc.2 | 2 +- doc/man/nvme_id_ns_granularity_list.2 | 2 +- doc/man/nvme_id_ns_mc.2 | 2 +- doc/man/nvme_id_ns_nmic.2 | 2 +- doc/man/nvme_id_ns_rescap.2 | 2 +- doc/man/nvme_id_nsfeat.2 | 2 +- doc/man/nvme_id_nvmset_list.2 | 2 +- doc/man/nvme_id_psd.2 | 2 +- doc/man/nvme_id_uuid.2 | 2 +- doc/man/nvme_id_uuid_list.2 | 2 +- doc/man/nvme_id_uuid_list_entry.2 | 2 +- doc/man/nvme_identify.2 | 2 +- doc/man/nvme_identify_active_ns_list.2 | 2 +- doc/man/nvme_identify_active_ns_list_csi.2 | 2 +- doc/man/nvme_identify_allocated_ns.2 | 2 +- doc/man/nvme_identify_allocated_ns_list.2 | 2 +- doc/man/nvme_identify_allocated_ns_list_csi.2 | 2 +- doc/man/nvme_identify_cns.2 | 2 +- doc/man/nvme_identify_ctrl.2 | 2 +- doc/man/nvme_identify_ctrl_csi.2 | 2 +- doc/man/nvme_identify_ctrl_list.2 | 2 +- doc/man/nvme_identify_domain_list.2 | 2 +- doc/man/nvme_identify_endurance_group_list.2 | 2 +- doc/man/nvme_identify_independent_identify_ns.2 | 2 +- doc/man/nvme_identify_iocs.2 | 2 +- .../nvme_identify_iocs_ns_csi_user_data_format.2 | 2 +- doc/man/nvme_identify_ns.2 | 2 +- doc/man/nvme_identify_ns_csi.2 | 2 +- doc/man/nvme_identify_ns_csi_user_data_format.2 | 2 +- doc/man/nvme_identify_ns_descs.2 | 2 +- doc/man/nvme_identify_ns_granularity.2 | 2 +- doc/man/nvme_identify_nsid_ctrl_list.2 | 2 +- doc/man/nvme_identify_nvmset_list.2 | 2 +- doc/man/nvme_identify_primary_ctrl.2 | 2 +- doc/man/nvme_identify_secondary_ctrl_list.2 | 2 +- doc/man/nvme_identify_uuid.2 | 2 +- doc/man/nvme_init_copy_range.2 | 2 +- doc/man/nvme_init_copy_range_f1.2 | 27 + doc/man/nvme_init_ctrl.2 | 2 +- doc/man/nvme_init_ctrl_list.2 | 2 +- doc/man/nvme_init_dsm_range.2 | 2 +- doc/man/nvme_init_logging.2 | 2 +- doc/man/nvme_io.2 | 2 +- doc/man/nvme_io_control_flags.2 | 2 +- doc/man/nvme_io_dsm_flags.2 | 2 +- doc/man/nvme_io_opcode.2 | 2 +- doc/man/nvme_io_passthru.2 | 2 +- doc/man/nvme_io_passthru64.2 | 71 + doc/man/nvme_is_64bit_reg.2 | 16 + doc/man/nvme_lba_range_type.2 | 2 +- doc/man/nvme_lba_range_type_entry.2 | 2 +- doc/man/nvme_lba_rd.2 | 2 +- doc/man/nvme_lba_status.2 | 2 +- doc/man/nvme_lba_status_atype.2 | 2 +- doc/man/nvme_lba_status_desc.2 | 2 +- doc/man/nvme_lba_status_log.2 | 2 +- doc/man/nvme_lbaf.2 | 2 +- doc/man/nvme_lbaf_rp.2 | 2 +- doc/man/nvme_lbart.2 | 2 +- doc/man/nvme_lbas_ns_element.2 | 2 +- doc/man/nvme_lockdown.2 | 2 +- doc/man/nvme_log_ana_lsp.2 | 2 +- doc/man/nvme_lookup_ctrl.2 | 2 +- doc/man/nvme_lookup_host.2 | 2 +- doc/man/nvme_lookup_subsystem.2 | 2 +- doc/man/nvme_media_unit_config_desc.2 | 2 +- doc/man/nvme_media_unit_stat_desc.2 | 2 +- doc/man/nvme_media_unit_stat_log.2 | 2 +- doc/man/nvme_metadata_element_desc.2 | 2 +- doc/man/nvme_mi_admin_format_nvm.2 | 18 + doc/man/nvme_mi_admin_fw_commit.2 | 16 + doc/man/nvme_mi_admin_fw_download.2 | 27 + doc/man/nvme_mi_admin_get_features_data.2 | 30 + doc/man/nvme_mi_admin_get_log.2 | 5 +- doc/man/nvme_mi_admin_get_log_ana.2 | 33 + doc/man/nvme_mi_admin_get_log_ana_groups.2 | 23 + doc/man/nvme_mi_admin_get_log_boot_partition.2 | 25 + doc/man/nvme_mi_admin_get_log_changed_ns_list.2 | 22 + doc/man/nvme_mi_admin_get_log_cmd_effects.2 | 21 + .../nvme_mi_admin_get_log_create_telemetry_host.2 | 15 + doc/man/nvme_mi_admin_get_log_device_self_test.2 | 19 + doc/man/nvme_mi_admin_get_log_discovery.2 | 27 + doc/man/nvme_mi_admin_get_log_endurance_group.2 | 25 + doc/man/nvme_mi_admin_get_log_endurance_grp_evt.2 | 24 + doc/man/nvme_mi_admin_get_log_error.2 | 25 + .../nvme_mi_admin_get_log_fid_supported_effects.2 | 18 + doc/man/nvme_mi_admin_get_log_fw_slot.2 | 22 + doc/man/nvme_mi_admin_get_log_lba_status.2 | 24 + doc/man/nvme_mi_admin_get_log_media_unit_stat.2 | 18 + ...vme_mi_admin_get_log_mi_cmd_supported_effects.2 | 18 + doc/man/nvme_mi_admin_get_log_persistent_event.2 | 21 + .../nvme_mi_admin_get_log_predictable_lat_event.2 | 24 + .../nvme_mi_admin_get_log_predictable_lat_nvmset.2 | 18 + doc/man/nvme_mi_admin_get_log_reservation.2 | 18 + doc/man/nvme_mi_admin_get_log_sanitize.2 | 21 + doc/man/nvme_mi_admin_get_log_simple.2 | 24 + doc/man/nvme_mi_admin_get_log_smart.2 | 28 + ...nvme_mi_admin_get_log_support_cap_config_list.2 | 18 + .../nvme_mi_admin_get_log_supported_log_pages.2 | 18 + doc/man/nvme_mi_admin_get_log_telemetry_ctrl.2 | 27 + doc/man/nvme_mi_admin_get_log_telemetry_host.2 | 24 + doc/man/nvme_mi_admin_get_log_zns_changed_zones.2 | 23 + doc/man/nvme_mi_admin_get_nsid_log.2 | 32 + doc/man/nvme_mi_admin_identify.2 | 5 +- doc/man/nvme_mi_admin_identify_active_ns_list.2 | 28 + doc/man/nvme_mi_admin_identify_allocated_ns.2 | 21 + doc/man/nvme_mi_admin_identify_allocated_ns_list.2 | 28 + doc/man/nvme_mi_admin_identify_cns_nsid.2 | 5 +- doc/man/nvme_mi_admin_identify_ctrl.2 | 5 +- doc/man/nvme_mi_admin_identify_ctrl_list.2 | 5 +- doc/man/nvme_mi_admin_identify_ns.2 | 21 + doc/man/nvme_mi_admin_identify_ns_descs.2 | 21 + doc/man/nvme_mi_admin_identify_nsid_ctrl_list.2 | 30 + doc/man/nvme_mi_admin_identify_partial.2 | 5 +- doc/man/nvme_mi_admin_identify_primary_ctrl.2 | 26 + .../nvme_mi_admin_identify_secondary_ctrl_list.2 | 30 + doc/man/nvme_mi_admin_ns_attach.2 | 15 + doc/man/nvme_mi_admin_ns_attach_ctrls.2 | 18 + doc/man/nvme_mi_admin_ns_detach_ctrls.2 | 18 + doc/man/nvme_mi_admin_req_hdr.2 | 2 +- doc/man/nvme_mi_admin_resp_hdr.2 | 2 +- doc/man/nvme_mi_admin_sanitize_nvm.2 | 25 + doc/man/nvme_mi_admin_security_recv.2 | 5 +- doc/man/nvme_mi_admin_security_send.2 | 5 +- doc/man/nvme_mi_admin_xfer.2 | 5 +- doc/man/nvme_mi_ccs.2 | 2 +- doc/man/nvme_mi_close.2 | 2 +- doc/man/nvme_mi_close_ctrl.2 | 2 +- doc/man/nvme_mi_cmd_supported_effects.2 | 2 +- doc/man/nvme_mi_cmd_supported_effects_log.2 | 2 +- doc/man/nvme_mi_config_id.2 | 2 +- doc/man/nvme_mi_config_smbus_freq.2 | 2 +- doc/man/nvme_mi_create_root.2 | 2 +- doc/man/nvme_mi_csts.2 | 2 +- doc/man/nvme_mi_ctrl_health_status.2 | 2 +- doc/man/nvme_mi_cwarn.2 | 2 +- doc/man/nvme_mi_dtyp.2 | 2 +- doc/man/nvme_mi_elem.2 | 2 +- doc/man/nvme_mi_free_root.2 | 2 +- doc/man/nvme_mi_init_ctrl.2 | 2 +- doc/man/nvme_mi_message_type.2 | 2 +- doc/man/nvme_mi_mi_opcode.2 | 2 +- doc/man/nvme_mi_mi_read_mi_data_ctrl.2 | 5 +- doc/man/nvme_mi_mi_read_mi_data_ctrl_list.2 | 5 +- doc/man/nvme_mi_mi_read_mi_data_port.2 | 5 +- doc/man/nvme_mi_mi_read_mi_data_subsys.2 | 5 +- doc/man/nvme_mi_mi_req_hdr.2 | 2 +- doc/man/nvme_mi_mi_resp_hdr.2 | 2 +- doc/man/nvme_mi_mi_subsystem_health_status_poll.2 | 5 +- doc/man/nvme_mi_msg_hdr.2 | 2 +- doc/man/nvme_mi_msg_resp.2 | 2 +- doc/man/nvme_mi_nvm_ss_health_status.2 | 2 +- doc/man/nvme_mi_open_mctp.2 | 2 +- doc/man/nvme_mi_osc.2 | 2 +- doc/man/nvme_mi_port_pcie.2 | 2 +- doc/man/nvme_mi_port_smb.2 | 2 +- doc/man/nvme_mi_read_ctrl_info.2 | 2 +- doc/man/nvme_mi_read_nvm_ss_info.2 | 2 +- doc/man/nvme_mi_read_port_info.2 | 2 +- doc/man/nvme_mi_read_sc_list.2 | 2 +- doc/man/nvme_mi_resp_status.2 | 2 +- doc/man/nvme_mi_status_to_string.2 | 17 + doc/man/nvme_mi_vpd_hdr.2 | 2 +- doc/man/nvme_mi_vpd_mr_common.2 | 2 +- doc/man/nvme_mi_vpd_mra.2 | 2 +- doc/man/nvme_mi_vpd_ppmra.2 | 2 +- doc/man/nvme_mi_vpd_telem.2 | 2 +- doc/man/nvme_mi_vpd_tra.2 | 2 +- doc/man/nvme_namespace_attach_ctrls.2 | 2 +- doc/man/nvme_namespace_detach_ctrls.2 | 2 +- doc/man/nvme_namespace_filter.2 | 2 +- doc/man/nvme_namespace_first_path.2 | 2 +- doc/man/nvme_namespace_for_each_path.2 | 2 +- doc/man/nvme_namespace_for_each_path_safe.2 | 2 +- doc/man/nvme_namespace_next_path.2 | 2 +- doc/man/nvme_nd_ns_fpi.2 | 2 +- doc/man/nvme_next_host.2 | 2 +- doc/man/nvme_next_subsystem.2 | 2 +- doc/man/nvme_ns_attach.2 | 2 +- doc/man/nvme_ns_attach_ctrls.2 | 2 +- doc/man/nvme_ns_attach_sel.2 | 2 +- doc/man/nvme_ns_compare.2 | 2 +- doc/man/nvme_ns_detach_ctrls.2 | 2 +- doc/man/nvme_ns_flush.2 | 2 +- doc/man/nvme_ns_get_csi.2 | 2 +- doc/man/nvme_ns_get_ctrl.2 | 2 +- doc/man/nvme_ns_get_eui64.2 | 11 + doc/man/nvme_ns_get_fd.2 | 2 +- doc/man/nvme_ns_get_firmware.2 | 2 +- doc/man/nvme_ns_get_generic_name.2 | 2 +- doc/man/nvme_ns_get_lba_count.2 | 2 +- doc/man/nvme_ns_get_lba_size.2 | 2 +- doc/man/nvme_ns_get_lba_util.2 | 2 +- doc/man/nvme_ns_get_meta_size.2 | 2 +- doc/man/nvme_ns_get_model.2 | 2 +- doc/man/nvme_ns_get_name.2 | 2 +- doc/man/nvme_ns_get_nguid.2 | 2 +- doc/man/nvme_ns_get_nsid.2 | 2 +- doc/man/nvme_ns_get_serial.2 | 2 +- doc/man/nvme_ns_get_subsystem.2 | 2 +- doc/man/nvme_ns_get_sysfs_dir.2 | 2 +- doc/man/nvme_ns_get_uuid.2 | 4 +- doc/man/nvme_ns_id_desc.2 | 2 +- doc/man/nvme_ns_id_desc_nidt.2 | 2 +- doc/man/nvme_ns_identify.2 | 2 +- doc/man/nvme_ns_identify_descs.2 | 2 +- doc/man/nvme_ns_list.2 | 2 +- doc/man/nvme_ns_metadata_type.2 | 2 +- doc/man/nvme_ns_mgmt.2 | 2 +- doc/man/nvme_ns_mgmt_create.2 | 2 +- doc/man/nvme_ns_mgmt_delete.2 | 2 +- doc/man/nvme_ns_mgmt_sel.2 | 2 +- doc/man/nvme_ns_read.2 | 2 +- doc/man/nvme_ns_rescan.2 | 2 +- doc/man/nvme_ns_verify.2 | 2 +- doc/man/nvme_ns_write.2 | 2 +- doc/man/nvme_ns_write_protect_cfg.2 | 2 +- doc/man/nvme_ns_write_uncorrectable.2 | 2 +- doc/man/nvme_ns_write_zeros.2 | 2 +- doc/man/nvme_nss_hw_err_event.2 | 2 +- doc/man/nvme_nvm_id_ns.2 | 2 +- doc/man/nvme_nvm_id_ns_elbaf.2 | 2 +- doc/man/nvme_nvm_identify_ctrl.2 | 2 +- doc/man/nvme_nvmeset_pl_status.2 | 2 +- doc/man/nvme_nvmset_attr.2 | 2 +- doc/man/nvme_nvmset_pl_events.2 | 2 +- doc/man/nvme_nvmset_predictable_lat_log.2 | 2 +- doc/man/nvme_open.2 | 2 +- doc/man/nvme_passthru_cmd.2 | 2 +- doc/man/nvme_passthru_cmd64.2 | 87 ++ doc/man/nvme_path_get_ana_state.2 | 2 +- doc/man/nvme_path_get_ctrl.2 | 2 +- doc/man/nvme_path_get_name.2 | 2 +- doc/man/nvme_path_get_ns.2 | 2 +- doc/man/nvme_path_get_sysfs_dir.2 | 2 +- doc/man/nvme_paths_filter.2 | 2 +- doc/man/nvme_persistent_event_entry.2 | 2 +- doc/man/nvme_persistent_event_log.2 | 2 +- doc/man/nvme_persistent_event_types.2 | 2 +- doc/man/nvme_pevent_log_action.2 | 2 +- doc/man/nvme_plm_config.2 | 2 +- doc/man/nvme_pmr_size.2 | 2 +- doc/man/nvme_pmr_throughput.2 | 2 +- doc/man/nvme_power_on_reset_info_list.2 | 2 +- doc/man/nvme_primary_ctrl_cap.2 | 2 +- doc/man/nvme_psd_flags.2 | 2 +- doc/man/nvme_psd_power_scale.2 | 2 +- doc/man/nvme_psd_ps.2 | 2 +- doc/man/nvme_psd_workload.2 | 2 +- doc/man/nvme_read.2 | 2 +- doc/man/nvme_read_config.2 | 2 +- doc/man/nvme_refresh_topology.2 | 2 +- doc/man/nvme_register_offsets.2 | 2 +- doc/man/nvme_registered_ctrl.2 | 2 +- doc/man/nvme_registered_ctrl_ext.2 | 2 +- doc/man/nvme_rescan_ctrl.2 | 2 +- doc/man/nvme_resv_acquire.2 | 2 +- doc/man/nvme_resv_cptpl.2 | 2 +- doc/man/nvme_resv_notification_log.2 | 2 +- doc/man/nvme_resv_notify_rnlpt.2 | 2 +- doc/man/nvme_resv_racqa.2 | 2 +- doc/man/nvme_resv_register.2 | 2 +- doc/man/nvme_resv_release.2 | 2 +- doc/man/nvme_resv_report.2 | 2 +- doc/man/nvme_resv_rrega.2 | 2 +- doc/man/nvme_resv_rrela.2 | 2 +- doc/man/nvme_resv_rtype.2 | 2 +- doc/man/nvme_resv_status.2 | 2 +- doc/man/nvme_sanitize_compln_event.2 | 2 +- doc/man/nvme_sanitize_log_page.2 | 2 +- doc/man/nvme_sanitize_nvm.2 | 2 +- doc/man/nvme_sanitize_sanact.2 | 2 +- doc/man/nvme_sanitize_sstat.2 | 2 +- doc/man/nvme_sanitize_start_event.2 | 2 +- doc/man/nvme_scan.2 | 2 +- doc/man/nvme_scan_ctrl.2 | 2 +- doc/man/nvme_scan_ctrl_namespace_paths.2 | 2 +- doc/man/nvme_scan_ctrl_namespaces.2 | 2 +- doc/man/nvme_scan_ctrls.2 | 2 +- doc/man/nvme_scan_namespace.2 | 2 +- doc/man/nvme_scan_subsystem_namespaces.2 | 2 +- doc/man/nvme_scan_subsystems.2 | 2 +- doc/man/nvme_scan_topology.2 | 2 +- doc/man/nvme_secondary_ctrl.2 | 2 +- doc/man/nvme_secondary_ctrl_list.2 | 2 +- doc/man/nvme_security_receive.2 | 2 +- doc/man/nvme_security_send.2 | 2 +- doc/man/nvme_self_test_log.2 | 2 +- doc/man/nvme_set_feature_event.2 | 2 +- doc/man/nvme_set_features.2 | 2 +- doc/man/nvme_set_features_arbitration.2 | 2 +- doc/man/nvme_set_features_async_event.2 | 2 +- doc/man/nvme_set_features_auto_pst.2 | 2 +- doc/man/nvme_set_features_data.2 | 2 +- doc/man/nvme_set_features_endurance_evt_cfg.2 | 2 +- doc/man/nvme_set_features_err_recovery.2 | 2 +- doc/man/nvme_set_features_hctm.2 | 2 +- doc/man/nvme_set_features_host_behavior.2 | 2 +- doc/man/nvme_set_features_host_id.2 | 2 +- doc/man/nvme_set_features_irq_coalesce.2 | 2 +- doc/man/nvme_set_features_irq_config.2 | 2 +- doc/man/nvme_set_features_lba_range.2 | 2 +- doc/man/nvme_set_features_lba_sts_interval.2 | 2 +- doc/man/nvme_set_features_nopsc.2 | 2 +- doc/man/nvme_set_features_plm_config.2 | 2 +- doc/man/nvme_set_features_plm_window.2 | 2 +- doc/man/nvme_set_features_power_mgmt.2 | 2 +- doc/man/nvme_set_features_resv_mask.2 | 2 +- doc/man/nvme_set_features_resv_persist.2 | 2 +- doc/man/nvme_set_features_rrl.2 | 2 +- doc/man/nvme_set_features_sanitize.2 | 2 +- doc/man/nvme_set_features_simple.2 | 2 +- doc/man/nvme_set_features_sw_progress.2 | 2 +- doc/man/nvme_set_features_temp_thresh.2 | 2 +- doc/man/nvme_set_features_timestamp.2 | 2 +- doc/man/nvme_set_features_volatile_wc.2 | 2 +- doc/man/nvme_set_features_write_atomic.2 | 2 +- doc/man/nvme_set_features_write_protect.2 | 2 +- doc/man/nvme_set_property.2 | 2 +- doc/man/nvme_smart_crit.2 | 2 +- doc/man/nvme_smart_egcw.2 | 2 +- doc/man/nvme_smart_log.2 | 2 +- doc/man/nvme_st_code.2 | 2 +- doc/man/nvme_st_curr_op.2 | 2 +- doc/man/nvme_st_result.2 | 2 +- doc/man/nvme_st_valid_diag_info.2 | 2 +- doc/man/nvme_status_code.2 | 2 +- doc/man/nvme_status_code_type.2 | 2 +- doc/man/nvme_status_equals.2 | 17 + doc/man/nvme_status_field.2 | 2 +- doc/man/nvme_status_get_type.2 | 11 + doc/man/nvme_status_get_value.2 | 12 + doc/man/nvme_status_result.2 | 2 +- doc/man/nvme_status_to_errno.2 | 2 +- doc/man/nvme_status_to_string.2 | 2 +- doc/man/nvme_status_type.2 | 40 + doc/man/nvme_streams_directive_params.2 | 2 +- doc/man/nvme_streams_directive_status.2 | 2 +- doc/man/nvme_submit_admin_passthru.2 | 2 +- doc/man/nvme_submit_admin_passthru64.2 | 20 + doc/man/nvme_submit_io_passthru.2 | 2 +- doc/man/nvme_submit_io_passthru64.2 | 20 + doc/man/nvme_subsys_filter.2 | 2 +- doc/man/nvme_subsys_type.2 | 2 +- doc/man/nvme_subsystem_first_ctrl.2 | 2 +- doc/man/nvme_subsystem_first_ns.2 | 2 +- doc/man/nvme_subsystem_for_each_ctrl.2 | 2 +- doc/man/nvme_subsystem_for_each_ctrl_safe.2 | 2 +- doc/man/nvme_subsystem_for_each_ns.2 | 2 +- doc/man/nvme_subsystem_for_each_ns_safe.2 | 2 +- doc/man/nvme_subsystem_get_host.2 | 2 +- doc/man/nvme_subsystem_get_name.2 | 2 +- doc/man/nvme_subsystem_get_nqn.2 | 2 +- doc/man/nvme_subsystem_get_sysfs_dir.2 | 2 +- doc/man/nvme_subsystem_get_type.2 | 2 +- doc/man/nvme_subsystem_lookup_namespace.2 | 2 +- doc/man/nvme_subsystem_next_ctrl.2 | 2 +- doc/man/nvme_subsystem_next_ns.2 | 2 +- doc/man/nvme_subsystem_reset.2 | 2 +- doc/man/nvme_supported_cap_config_list_log.2 | 2 +- doc/man/nvme_supported_log_pages.2 | 2 +- doc/man/nvme_telemetry_da.2 | 2 +- doc/man/nvme_telemetry_log.2 | 2 +- doc/man/nvme_thermal_exc_event.2 | 2 +- doc/man/nvme_time_stamp_change_event.2 | 2 +- doc/man/nvme_timestamp.2 | 2 +- doc/man/nvme_unlink_ctrl.2 | 2 +- doc/man/nvme_update_config.2 | 2 +- doc/man/nvme_uring_cmd.2 | 2 +- doc/man/nvme_verify.2 | 2 +- doc/man/nvme_version.2 | 2 +- doc/man/nvme_virt_mgmt_act.2 | 2 +- doc/man/nvme_virt_mgmt_rt.2 | 2 +- doc/man/nvme_virtual_mgmt.2 | 2 +- doc/man/nvme_write.2 | 2 +- doc/man/nvme_write_uncorrectable.2 | 2 +- doc/man/nvme_write_zeros.2 | 2 +- doc/man/nvme_zns_append.2 | 2 +- doc/man/nvme_zns_changed_zone_log.2 | 2 +- doc/man/nvme_zns_desc.2 | 2 +- doc/man/nvme_zns_id_ctrl.2 | 2 +- doc/man/nvme_zns_id_ns.2 | 2 +- doc/man/nvme_zns_identify_ctrl.2 | 2 +- doc/man/nvme_zns_identify_ns.2 | 2 +- doc/man/nvme_zns_lbafe.2 | 2 +- doc/man/nvme_zns_mgmt_recv.2 | 2 +- doc/man/nvme_zns_mgmt_send.2 | 2 +- doc/man/nvme_zns_recv_action.2 | 2 +- doc/man/nvme_zns_report_options.2 | 2 +- doc/man/nvme_zns_report_zones.2 | 2 +- doc/man/nvme_zns_send_action.2 | 2 +- doc/man/nvme_zns_za.2 | 2 +- doc/man/nvme_zns_zs.2 | 2 +- doc/man/nvme_zns_zt.2 | 2 +- doc/man/nvme_zone_report.2 | 2 +- doc/man/nvmf_add_ctrl.2 | 2 +- doc/man/nvmf_addr_family.2 | 2 +- doc/man/nvmf_adrfam_str.2 | 2 +- doc/man/nvmf_cms_str.2 | 2 +- doc/man/nvmf_connect_data.2 | 2 +- doc/man/nvmf_connect_disc_entry.2 | 2 +- doc/man/nvmf_default_config.2 | 2 +- doc/man/nvmf_dim_data.2 | 2 +- doc/man/nvmf_dim_entfmt.2 | 2 +- doc/man/nvmf_dim_etype.2 | 2 +- doc/man/nvmf_dim_tas.2 | 2 +- doc/man/nvmf_disc_eflags.2 | 2 +- doc/man/nvmf_disc_log_entry.2 | 2 +- doc/man/nvmf_discovery_log.2 | 2 +- doc/man/nvmf_eflags_str.2 | 2 +- doc/man/nvmf_exat_len.2 | 2 +- doc/man/nvmf_exattype.2 | 2 +- doc/man/nvmf_ext_attr.2 | 2 +- doc/man/nvmf_ext_die.2 | 2 +- doc/man/nvmf_get_discovery_log.2 | 11 +- doc/man/nvmf_get_discovery_wargs.2 | 20 + doc/man/nvmf_hostid_from_file.2 | 2 +- doc/man/nvmf_hostnqn_from_file.2 | 2 +- doc/man/nvmf_hostnqn_generate.2 | 2 +- doc/man/nvmf_log_discovery_lid_support.2 | 30 + doc/man/nvmf_log_discovery_lsp.2 | 30 + doc/man/nvmf_prtype_str.2 | 2 +- doc/man/nvmf_qptype_str.2 | 2 +- doc/man/nvmf_rdma_cms.2 | 2 +- doc/man/nvmf_rdma_prtype.2 | 2 +- doc/man/nvmf_rdma_qptype.2 | 2 +- doc/man/nvmf_register_ctrl.2 | 2 +- doc/man/nvmf_sectype_str.2 | 2 +- doc/man/nvmf_subtype_str.2 | 2 +- doc/man/nvmf_tcp_sectype.2 | 2 +- doc/man/nvmf_treq.2 | 2 +- doc/man/nvmf_treq_str.2 | 2 +- doc/man/nvmf_trtype.2 | 2 +- doc/man/nvmf_trtype_str.2 | 2 +- doc/man/nvmf_update_config.2 | 2 +- doc/meson.build | 5 +- doc/rst/fabrics.rst | 79 +- doc/rst/mi.rst | 1509 ++++++++++++++++++- doc/rst/tree.rst | 31 +- doc/rst/types.rst | 145 ++ doc/rst/util.rst | 80 ++ examples/discover-loop.c | 1 + examples/discover-loop.py | 45 +- examples/meson.build | 9 + examples/mi-conf.c | 196 +++ examples/mi-mctp.c | 6 + libnvme/README.md | 28 +- libnvme/nvme.i | 80 +- meson.build | 34 +- release.sh | 61 +- src/libnvme-mi.map | 13 + src/libnvme.map | 12 + src/meson.build | 9 - src/nvme/fabrics.c | 146 +- src/nvme/fabrics.h | 44 +- src/nvme/ioctl.h | 2 +- src/nvme/json.c | 61 +- src/nvme/mi-mctp.c | 57 +- src/nvme/mi.c | 406 +++++- src/nvme/mi.h | 1510 +++++++++++++++++++- src/nvme/private.h | 5 +- src/nvme/tree.c | 42 +- src/nvme/tree.h | 18 +- src/nvme/types.h | 111 ++ src/nvme/util.c | 77 + src/nvme/util.h | 49 + test/meson.build | 11 +- test/mi-mctp.c | 38 +- test/mi.c | 1050 ++++++++++++++ test/test.c | 7 +- test/uuid.c | 120 ++ 762 files changed, 8293 insertions(+), 965 deletions(-) create mode 100644 .github/cross/ubuntu-armhf.txt create mode 100644 .github/cross/ubuntu-ppc64le.txt create mode 100755 doc/list-pre-compiled.sh create mode 100644 doc/man/nvme_admin_passthru64.2 create mode 100644 doc/man/nvme_copy_range_f1.2 create mode 100644 doc/man/nvme_ctrl_get_dhchap_host_key.2 create mode 100644 doc/man/nvme_ctrl_set_dhchap_host_key.2 create mode 100644 doc/man/nvme_data_tfr.2 create mode 100644 doc/man/nvme_get_discovery_args.2 create mode 100644 doc/man/nvme_get_feature_length2.2 create mode 100644 doc/man/nvme_init_copy_range_f1.2 create mode 100644 doc/man/nvme_io_passthru64.2 create mode 100644 doc/man/nvme_is_64bit_reg.2 create mode 100644 doc/man/nvme_mi_admin_format_nvm.2 create mode 100644 doc/man/nvme_mi_admin_fw_commit.2 create mode 100644 doc/man/nvme_mi_admin_fw_download.2 create mode 100644 doc/man/nvme_mi_admin_get_features_data.2 create mode 100644 doc/man/nvme_mi_admin_get_log_ana.2 create mode 100644 doc/man/nvme_mi_admin_get_log_ana_groups.2 create mode 100644 doc/man/nvme_mi_admin_get_log_boot_partition.2 create mode 100644 doc/man/nvme_mi_admin_get_log_changed_ns_list.2 create mode 100644 doc/man/nvme_mi_admin_get_log_cmd_effects.2 create mode 100644 doc/man/nvme_mi_admin_get_log_create_telemetry_host.2 create mode 100644 doc/man/nvme_mi_admin_get_log_device_self_test.2 create mode 100644 doc/man/nvme_mi_admin_get_log_discovery.2 create mode 100644 doc/man/nvme_mi_admin_get_log_endurance_group.2 create mode 100644 doc/man/nvme_mi_admin_get_log_endurance_grp_evt.2 create mode 100644 doc/man/nvme_mi_admin_get_log_error.2 create mode 100644 doc/man/nvme_mi_admin_get_log_fid_supported_effects.2 create mode 100644 doc/man/nvme_mi_admin_get_log_fw_slot.2 create mode 100644 doc/man/nvme_mi_admin_get_log_lba_status.2 create mode 100644 doc/man/nvme_mi_admin_get_log_media_unit_stat.2 create mode 100644 doc/man/nvme_mi_admin_get_log_mi_cmd_supported_effects.2 create mode 100644 doc/man/nvme_mi_admin_get_log_persistent_event.2 create mode 100644 doc/man/nvme_mi_admin_get_log_predictable_lat_event.2 create mode 100644 doc/man/nvme_mi_admin_get_log_predictable_lat_nvmset.2 create mode 100644 doc/man/nvme_mi_admin_get_log_reservation.2 create mode 100644 doc/man/nvme_mi_admin_get_log_sanitize.2 create mode 100644 doc/man/nvme_mi_admin_get_log_simple.2 create mode 100644 doc/man/nvme_mi_admin_get_log_smart.2 create mode 100644 doc/man/nvme_mi_admin_get_log_support_cap_config_list.2 create mode 100644 doc/man/nvme_mi_admin_get_log_supported_log_pages.2 create mode 100644 doc/man/nvme_mi_admin_get_log_telemetry_ctrl.2 create mode 100644 doc/man/nvme_mi_admin_get_log_telemetry_host.2 create mode 100644 doc/man/nvme_mi_admin_get_log_zns_changed_zones.2 create mode 100644 doc/man/nvme_mi_admin_get_nsid_log.2 create mode 100644 doc/man/nvme_mi_admin_identify_active_ns_list.2 create mode 100644 doc/man/nvme_mi_admin_identify_allocated_ns.2 create mode 100644 doc/man/nvme_mi_admin_identify_allocated_ns_list.2 create mode 100644 doc/man/nvme_mi_admin_identify_ns.2 create mode 100644 doc/man/nvme_mi_admin_identify_ns_descs.2 create mode 100644 doc/man/nvme_mi_admin_identify_nsid_ctrl_list.2 create mode 100644 doc/man/nvme_mi_admin_identify_primary_ctrl.2 create mode 100644 doc/man/nvme_mi_admin_identify_secondary_ctrl_list.2 create mode 100644 doc/man/nvme_mi_admin_ns_attach.2 create mode 100644 doc/man/nvme_mi_admin_ns_attach_ctrls.2 create mode 100644 doc/man/nvme_mi_admin_ns_detach_ctrls.2 create mode 100644 doc/man/nvme_mi_admin_sanitize_nvm.2 create mode 100644 doc/man/nvme_mi_status_to_string.2 create mode 100644 doc/man/nvme_ns_get_eui64.2 create mode 100644 doc/man/nvme_passthru_cmd64.2 create mode 100644 doc/man/nvme_status_equals.2 create mode 100644 doc/man/nvme_status_get_type.2 create mode 100644 doc/man/nvme_status_get_value.2 create mode 100644 doc/man/nvme_status_type.2 create mode 100644 doc/man/nvme_submit_admin_passthru64.2 create mode 100644 doc/man/nvme_submit_io_passthru64.2 create mode 100644 doc/man/nvmf_get_discovery_wargs.2 create mode 100644 doc/man/nvmf_log_discovery_lid_support.2 create mode 100644 doc/man/nvmf_log_discovery_lsp.2 create mode 100644 examples/mi-conf.c create mode 100644 test/uuid.c diff --git a/.github/cross/ubuntu-armhf.txt b/.github/cross/ubuntu-armhf.txt new file mode 100644 index 0000000..2eee70b --- /dev/null +++ b/.github/cross/ubuntu-armhf.txt @@ -0,0 +1,17 @@ +[binaries] +c = '/usr/bin/arm-linux-gnueabihf-gcc' +ar = '/usr/arm-linux-gnueabihf/bin/ar' +strip = '/usr/arm-linux-gnueabihf/bin/strip' +pkgconfig = '/usr/bin/arm-linux-gnueabihf-pkg-config' +ld = '/usr/bin/arm-linux/gnueabihf-ld' + +[properties] +root = '/usr/arm-linux-gnueabihf' +has_function_printf = true +skip_sanity_check = true + +[host_machine] +system = 'linux' +cpu_family = 'arm' +cpu = 'armv7' +endian = 'little' diff --git a/.github/cross/ubuntu-ppc64le.txt b/.github/cross/ubuntu-ppc64le.txt new file mode 100644 index 0000000..4cf6a92 --- /dev/null +++ b/.github/cross/ubuntu-ppc64le.txt @@ -0,0 +1,17 @@ +[binaries] +c = '/usr/bin/powerpc64le-linux-gnu-gcc' +ar = '/usr/powerpc64le-linux-gnu/bin/ar' +strip = '/usr/powerpc64le-linux-gnu/bin/strip' +pkgconfig = '/usr/bin/powerpc64le-linux-gnu-pkg-config' +ld = '/usr/bin/powerpc64le-linux-gnu-ld' + +[properties] +root = '/usr/powerpc64le-linux-gnu' +has_function_printf = true +skip_sanity_check = true + +[host_machine] +system = 'linux' +cpu_family = 'ppc64' +cpu = '' +endian = 'little' diff --git a/.github/workflows/meson.yml b/.github/workflows/meson.yml index 9006eae..52b2b6a 100644 --- a/.github/workflows/meson.yml +++ b/.github/workflows/meson.yml @@ -30,6 +30,66 @@ jobs: name: Linux_Meson_Testlog path: build/meson-logs/testlog.txt + build-cross-armhf: + runs-on: ubuntu-latest + steps: + - name: set up arm architecture + run: | + export release=$(lsb_release -c -s) + sudo dpkg --add-architecture armhf + sudo sed -i -e 's/deb http/deb [arch=amd64] http/g' /etc/apt/sources.list + sudo dd of=/etc/apt/sources.list.d/armhf.list <`) or -1 with errno set otherwise. .. c:function:: nvme_mi_ctrl_t nvme_mi_init_ctrl (nvme_mi_ep_t ep, __u16 ctrl_id) @@ -1027,7 +1050,8 @@ NVMe version information. See :c:type:`struct nvme_mi_read_nvm_ss_info `) or -1 with errno set otherwise.. .. c:function:: int nvme_mi_mi_read_mi_data_port (nvme_mi_ep_t ep, __u8 portid, struct nvme_mi_read_port_info *p) @@ -1055,7 +1079,8 @@ See :c:type:`struct nvme_mi_read_port_info `. **Return** -0 on success, non-zero on failure. +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise.. .. c:function:: int nvme_mi_mi_read_mi_data_ctrl_list (nvme_mi_ep_t ep, __u8 start_ctrlid, struct nvme_ctrl_list *list) @@ -1082,7 +1107,8 @@ See :c:type:`struct nvme_ctrl_list `. **Return** -0 on success, non-zero on failure. +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise.. .. c:function:: int nvme_mi_mi_read_mi_data_ctrl (nvme_mi_ep_t ep, __u16 ctrl_id, struct nvme_mi_read_ctrl_info *ctrl) @@ -1109,7 +1135,8 @@ See :c:type:`struct nvme_mi_read_ctrl_info `. **Return** -0 on success, non-zero on failure. +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise.. .. c:function:: int nvme_mi_mi_subsystem_health_status_poll (nvme_mi_ep_t ep, bool clear, struct nvme_mi_nvm_ss_health_status *nshds) @@ -1137,7 +1164,8 @@ See :c:type:`struct nvme_mi_nvm_ss_health_status ` **Return** -0 on success, non-zero on failure. +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise.. .. c:function:: int nvme_mi_mi_config_get (nvme_mi_ep_t ep, __u32 dw0, __u32 dw1, __u32 *nmresp) @@ -1172,7 +1200,8 @@ See :c:type:`enum nvme_mi_config_id ` for identifiers. **Return** -0 on success, non-zero on failure. +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise.. .. c:function:: int nvme_mi_mi_config_set (nvme_mi_ep_t ep, __u32 dw0, __u32 dw1) @@ -1200,7 +1229,8 @@ See :c:type:`enum nvme_mi_config_id ` for identifiers. **Return** -0 on success, non-zero on failure. +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise.. .. c:function:: int nvme_mi_mi_config_get_smbus_freq (nvme_mi_ep_t ep, __u8 port, enum nvme_mi_config_smbus_freq *freq) @@ -1226,7 +1256,8 @@ frequency **Return** -0 on success, non-zero on failure. +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise.. .. c:function:: int nvme_mi_mi_config_set_smbus_freq (nvme_mi_ep_t ep, __u8 port, enum nvme_mi_config_smbus_freq freq) @@ -1254,7 +1285,8 @@ for the port. **Return** -0 on success, non-zero on failure. +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise.. .. c:function:: int nvme_mi_mi_config_set_health_status_change (nvme_mi_ep_t ep, __u32 mask) @@ -1281,7 +1313,8 @@ values in **mask**. **Return** -0 on success, non-zero on failure. +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise.. .. c:function:: int nvme_mi_mi_config_get_mctp_mtu (nvme_mi_ep_t ep, __u8 port, __u16 *mtu) @@ -1312,7 +1345,8 @@ may not accept MCTP messages larger than the configured MTU. **Return** -0 on success, non-zero on failure. +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise.. .. c:function:: int nvme_mi_mi_config_set_mctp_mtu (nvme_mi_ep_t ep, __u8 port, __u16 mtu) @@ -1342,7 +1376,8 @@ interface(s) to match. **Return** -0 on success, non-zero on failure. +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise.. .. c:function:: int nvme_mi_admin_xfer (nvme_mi_ctrl_t ctrl, struct nvme_mi_admin_req_hdr *admin_req, size_t req_data_size, struct nvme_mi_admin_resp_hdr *admin_resp, off_t resp_data_offset, size_t *resp_data_size) @@ -1388,7 +1423,8 @@ See: :c:type:`struct nvme_mi_admin_req_hdr ` and :c:type: **Return** -0 on success, non-zero on failure. +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise.. .. c:function:: int nvme_mi_admin_identify_partial (nvme_mi_ctrl_t ctrl, struct nvme_identify_args *args, off_t offset, size_t size) @@ -1429,7 +1465,8 @@ See: :c:type:`struct nvme_identify_args ` **Return** -0 on success, non-zero on failure +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. .. c:function:: int nvme_mi_admin_identify (nvme_mi_ctrl_t ctrl, struct nvme_identify_args *args) @@ -1457,7 +1494,8 @@ See: :c:type:`struct nvme_identify_args ` **Return** -0 on success, non-zero on failure +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. .. c:function:: int nvme_mi_admin_identify_cns_nsid (nvme_mi_ctrl_t ctrl, enum nvme_identify_cns cns, __u32 nsid, void *data) @@ -1491,7 +1529,86 @@ controller) is not a full :c:type:`NVME_IDENTIFY_DATA_SIZE`. **Return** -0 on success, non-zero on failure +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_identify_ns (nvme_mi_ctrl_t ctrl, __u32 nsid, struct nvme_id_ns *ns) + + Perform an Admin identify command for a namespace + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to process identify command + +``__u32 nsid`` + namespace ID + +``struct nvme_id_ns *ns`` + Namespace identification to populate + +**Description** + +Perform an Identify (namespace) command, setting the namespace id data +in **ns**. The namespace is expected to active and allocated. + +**Return** + +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_identify_ns_descs (nvme_mi_ctrl_t ctrl, __u32 nsid, struct nvme_ns_id_desc *descs) + + Perform an Admin identify Namespace Identification Descriptor list command for a namespace + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to process identify command + +``__u32 nsid`` + Namespace ID + +``struct nvme_ns_id_desc *descs`` + Namespace Identification Descriptor list to populate + +**Description** + +Perform an Identify namespace identification description list command, +setting the namespace identification description list in **descs** + +**Return** + +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_identify_allocated_ns (nvme_mi_ctrl_t ctrl, __u32 nsid, struct nvme_id_ns *ns) + + Perform an Admin identify command for an allocated namespace + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to process identify command + +``__u32 nsid`` + namespace ID + +``struct nvme_id_ns *ns`` + Namespace identification to populate + +**Description** + +Perform an Identify (namespace) command, setting the namespace id data +in **ns**. + +**Return** + +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. .. c:function:: int nvme_mi_admin_identify_ctrl (nvme_mi_ctrl_t ctrl, struct nvme_id_ctrl *id) @@ -1519,7 +1636,8 @@ See: :c:type:`struct nvme_id_ctrl ` **Return** -0 on success, non-zero on failure +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. .. c:function:: int nvme_mi_admin_identify_ctrl_list (nvme_mi_ctrl_t ctrl, __u16 cntid, struct nvme_ctrl_list *list) @@ -1550,6 +1668,174 @@ See: :c:type:`struct nvme_ctrl_list ` **Return** +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_identify_nsid_ctrl_list (nvme_mi_ctrl_t ctrl, __u32 nsid, __u16 cntid, struct nvme_ctrl_list *list) + + Perform an Admin identify for a controller list with specific namespace ID + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to process identify command + +``__u32 nsid`` + Namespace identifier + +``__u16 cntid`` + Controller ID to specify list start + +``struct nvme_ctrl_list *list`` + List data to populate + +**Description** + +Perform an Identify command, for the controller list for **nsid**, starting +with IDs greater than or equal to **cntid**. + +Will return an error if the length of the response data (from the +controller) is not a full :c:type:`NVME_IDENTIFY_DATA_SIZE`, so **id** will be +fully populated on success. + +See: :c:type:`struct nvme_ctrl_list ` + +**Return** + +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_identify_allocated_ns_list (nvme_mi_ctrl_t ctrl, __u32 nsid, struct nvme_ns_list *list) + + Perform an Admin identify for an allocated namespace list + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to process identify command + +``__u32 nsid`` + Namespace ID to specify list start + +``struct nvme_ns_list *list`` + List data to populate + +**Description** + +Perform an Identify command, for the allocated namespace list starting with +IDs greater than or equal to **nsid**. Specify :c:type:`NVME_NSID_NONE` for the start +of the list. + +Will return an error if the length of the response data (from the +controller) is not a full :c:type:`NVME_IDENTIFY_DATA_SIZE`, so **list** will be +be fully populated on success. + +See: :c:type:`struct nvme_ns_list ` + +**Return** + +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_identify_active_ns_list (nvme_mi_ctrl_t ctrl, __u32 nsid, struct nvme_ns_list *list) + + Perform an Admin identify for an active namespace list + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to process identify command + +``__u32 nsid`` + Namespace ID to specify list start + +``struct nvme_ns_list *list`` + List data to populate + +**Description** + +Perform an Identify command, for the active namespace list starting with +IDs greater than or equal to **nsid**. Specify :c:type:`NVME_NSID_NONE` for the start +of the list. + +Will return an error if the length of the response data (from the +controller) is not a full :c:type:`NVME_IDENTIFY_DATA_SIZE`, so **list** will be +be fully populated on success. + +See: :c:type:`struct nvme_ns_list ` + +**Return** + +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_identify_primary_ctrl (nvme_mi_ctrl_t ctrl, __u16 cntid, struct nvme_primary_ctrl_cap *cap) + + Perform an Admin identify for primary controller capabilities data structure. + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to process identify command + +``__u16 cntid`` + Controller ID to specify + +``struct nvme_primary_ctrl_cap *cap`` + Primary Controller Capabilities data structure to populate + +**Description** + +Perform an Identify command to get the Primary Controller Capabilities data +for the controller specified by **cntid** + +Will return an error if the length of the response data (from the +controller) is not a full :c:type:`NVME_IDENTIFY_DATA_SIZE`, so **cap** will be +be fully populated on success. + +See: :c:type:`struct nvme_primary_ctrl_cap ` + +**Return** + +0 on success, non-zero on failure + + +.. c:function:: int nvme_mi_admin_identify_secondary_ctrl_list (nvme_mi_ctrl_t ctrl, __u32 nsid, __u16 cntid, struct nvme_secondary_ctrl_list *list) + + Perform an Admin identify for a secondary controller list. + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to process identify command + +``__u32 nsid`` + Namespace ID to specify list start + +``__u16 cntid`` + Controller ID to specify list start + +``struct nvme_secondary_ctrl_list *list`` + List data to populate + +**Description** + +Perform an Identify command, for the secondary controllers associated with +the current primary controller. Only entries with IDs greater than or +equal to **cntid** are returned. + +Will return an error if the length of the response data (from the +controller) is not a full :c:type:`NVME_IDENTIFY_DATA_SIZE`, so **list** will be +be fully populated on success. + +See: :c:type:`struct nvme_secondary_ctrl_list ` + +**Return** + 0 on success, non-zero on failure @@ -1579,64 +1865,1195 @@ See: :c:type:`struct nvme_get_log_args ` **Return** -0 on success, non-zero on failure +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. -.. c:function:: int nvme_mi_admin_security_send (nvme_mi_ctrl_t ctrl, struct nvme_security_send_args *args) +.. c:function:: int nvme_mi_admin_get_nsid_log (nvme_mi_ctrl_t ctrl, bool rae, enum nvme_cmd_get_log_lid lid, __u32 nsid, __u32 len, void *log) - Perform a Security Send command on a controller. + Helper for Get Log Page functions **Parameters** ``nvme_mi_ctrl_t ctrl`` - Controller to send command to + Controller to query -``struct nvme_security_send_args *args`` - Security Send command arguments +``bool rae`` + Retain Asynchronous Events -**Description** +``enum nvme_cmd_get_log_lid lid`` + Log identifier -Performs a Security Send Admin command as specified by **args**. Response data -is stored in **args->data**, which should be a buffer of **args->data_len** bytes. -Resulting data length is stored in **args->data_len** on successful -command completion. +``__u32 nsid`` + Namespace ID -Security Send data length should not be greater than 4096 bytes to -comply with specification limits. +``__u32 len`` + length of log buffer -See: :c:type:`struct nvme_get_log_args ` +``void *log`` + pointer for resulting log data + +**Description** + +Performs a Get Log Page Admin command for a specific log ID **lid** and +namespace ID **nsid**. Log data is expected to be **len** bytes, and is stored +in **log** on success. The **rae** flag is passed as-is to the Get Log Page +command, and is specific to the Log Page requested. **Return** -0 on success, non-zero on failure +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. -.. c:function:: int nvme_mi_admin_security_recv (nvme_mi_ctrl_t ctrl, struct nvme_security_receive_args *args) +.. c:function:: int nvme_mi_admin_get_log_simple (nvme_mi_ctrl_t ctrl, enum nvme_cmd_get_log_lid lid, __u32 len, void *log) - Perform a Security Receive command on a controller. + Helper for Get Log Page functions with no NSID or RAE requirements **Parameters** ``nvme_mi_ctrl_t ctrl`` - Controller to send command to + Controller to query -``struct nvme_security_receive_args *args`` - Security Receive command arguments +``enum nvme_cmd_get_log_lid lid`` + Log identifier + +``__u32 len`` + length of log buffer + +``void *log`` + pointer for resulting log data **Description** -Performs a Security Receive Admin command as specified by **args**. Response -data is stored in **args->data**, which should be a buffer of **args->data_len** -bytes. Resulting data length is stored in **args->data_len** on successful -command completion. +Performs a Get Log Page Admin command for a specific log ID **lid**, using +NVME_NSID_ALL for the namespace identifier, and rae set to false. -Security Receive data length should not be greater than 4096 bytes to -comply with specification limits. +**Return** -See: :c:type:`struct nvme_get_log_args ` +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_get_log_supported_log_pages (nvme_mi_ctrl_t ctrl, bool rae, struct nvme_supported_log_pages *log) + + Retrieve nmve supported log pages + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to query + +``bool rae`` + Retain asynchronous events + +``struct nvme_supported_log_pages *log`` + Array of LID supported and Effects data structures **Return** -0 on success, non-zero on failure +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_get_log_error (nvme_mi_ctrl_t ctrl, unsigned int nr_entries, bool rae, struct nvme_error_log_page *err_log) + + Retrieve nvme error log + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to query + +``unsigned int nr_entries`` + Number of error log entries allocated + +``bool rae`` + Retain asynchronous events + +``struct nvme_error_log_page *err_log`` + Array of error logs of size 'entries' + +**Description** + +This log page describes extended error information for a command that +completed with error, or may report an error that is not specific to a +particular command. + +**Return** + +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_get_log_smart (nvme_mi_ctrl_t ctrl, __u32 nsid, bool rae, struct nvme_smart_log *smart_log) + + Retrieve nvme smart log + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to query + +``__u32 nsid`` + Optional namespace identifier + +``bool rae`` + Retain asynchronous events + +``struct nvme_smart_log *smart_log`` + User address to store the smart log + +**Description** + +This log page provides SMART and general health information. The information +provided is over the life of the controller and is retained across power +cycles. To request the controller log page, the namespace identifier +specified is FFFFFFFFh. The controller may also support requesting the log +page on a per namespace basis, as indicated by bit 0 of the LPA field in the +Identify Controller data structure. + +**Return** + +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_get_log_fw_slot (nvme_mi_ctrl_t ctrl, bool rae, struct nvme_firmware_slot *fw_log) + + Retrieves the controller firmware log + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to query + +``bool rae`` + Retain asynchronous events + +``struct nvme_firmware_slot *fw_log`` + User address to store the log page + +**Description** + +This log page describes the firmware revision stored in each firmware slot +supported. The firmware revision is indicated as an ASCII string. The log +page also indicates the active slot number. + +**Return** + +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_get_log_changed_ns_list (nvme_mi_ctrl_t ctrl, bool rae, struct nvme_ns_list *ns_log) + + Retrieve namespace changed list + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to query + +``bool rae`` + Retain asynchronous events + +``struct nvme_ns_list *ns_log`` + User address to store the log page + +**Description** + +This log page describes namespaces attached to this controller that have +changed since the last time the namespace was identified, been added, or +deleted. + +**Return** + +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_get_log_cmd_effects (nvme_mi_ctrl_t ctrl, enum nvme_csi csi, struct nvme_cmd_effects_log *effects_log) + + Retrieve nvme command effects log + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to query + +``enum nvme_csi csi`` + Command Set Identifier + +``struct nvme_cmd_effects_log *effects_log`` + User address to store the effects log + +**Description** + +This log page describes the commands that the controller supports and the +effects of those commands on the state of the NVM subsystem. + +**Return** + +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_get_log_device_self_test (nvme_mi_ctrl_t ctrl, struct nvme_self_test_log *log) + + Retrieve the device self test log + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to query + +``struct nvme_self_test_log *log`` + Userspace address of the log payload + +**Description** + +The log page indicates the status of an in progress self test and the +percent complete of that operation, and the results of the previous 20 +self-test operations. + +**Return** + +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_get_log_create_telemetry_host (nvme_mi_ctrl_t ctrl, struct nvme_telemetry_log *log) + + Create host telemetry log + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to query + +``struct nvme_telemetry_log *log`` + Userspace address of the log payload + +**Return** + +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_get_log_telemetry_host (nvme_mi_ctrl_t ctrl, __u64 offset, __u32 len, void *log) + + Get Telemetry Host-Initiated log page + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to query + +``__u64 offset`` + Offset into the telemetry data + +``__u32 len`` + Length of provided user buffer to hold the log data in bytes + +``void *log`` + User address for log page data + +**Description** + +Retrieves the Telemetry Host-Initiated log page at the requested offset +using the previously existing capture. + +**Return** + +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_get_log_telemetry_ctrl (nvme_mi_ctrl_t ctrl, bool rae, __u64 offset, __u32 len, void *log) + + Get Telemetry Controller-Initiated log page + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to query + +``bool rae`` + Retain asynchronous events + +``__u64 offset`` + Offset into the telemetry data + +``__u32 len`` + Length of provided user buffer to hold the log data in bytes + +``void *log`` + User address for log page data + +**Description** + +Retrieves the Telemetry Controller-Initiated log page at the requested offset +using the previously existing capture. + +**Return** + +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_get_log_endurance_group (nvme_mi_ctrl_t ctrl, __u16 endgid, struct nvme_endurance_group_log *log) + + Get Endurance Group log + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to query + +``__u16 endgid`` + Starting group identifier to return in the list + +``struct nvme_endurance_group_log *log`` + User address to store the endurance log + +**Description** + +This log page indicates if an Endurance Group Event has occurred for a +particular Endurance Group. If an Endurance Group Event has occurred, the +details of the particular event are included in the Endurance Group +Information log page for that Endurance Group. An asynchronous event is +generated when an entry for an Endurance Group is newly added to this log +page. + +**Return** + +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_get_log_predictable_lat_nvmset (nvme_mi_ctrl_t ctrl, __u16 nvmsetid, struct nvme_nvmset_predictable_lat_log *log) + + Predictable Latency Per NVM Set + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to query + +``__u16 nvmsetid`` + NVM set id + +``struct nvme_nvmset_predictable_lat_log *log`` + User address to store the predictable latency log + +**Return** + +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_get_log_predictable_lat_event (nvme_mi_ctrl_t ctrl, bool rae, __u32 offset, __u32 len, void *log) + + Retrieve Predictable Latency Event Aggregate Log Page + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to query + +``bool rae`` + Retain asynchronous events + +``__u32 offset`` + Offset into the predictable latency event + +``__u32 len`` + Length of provided user buffer to hold the log data in bytes + +``void *log`` + User address for log page data + +**Return** + +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_get_log_ana (nvme_mi_ctrl_t ctrl, enum nvme_log_ana_lsp lsp, bool rae, __u64 offset, __u32 len, void *log) + + Retrieve Asymmetric Namespace Access log page + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to query + +``enum nvme_log_ana_lsp lsp`` + Log specific, see :c:type:`enum nvme_get_log_ana_lsp ` + +``bool rae`` + Retain asynchronous events + +``__u64 offset`` + Offset to the start of the log page + +``__u32 len`` + The allocated length of the log page + +``void *log`` + User address to store the ana log + +**Description** + +This log consists of a header describing the log and descriptors containing +the asymmetric namespace access information for ANA Groups that contain +namespaces that are attached to the controller processing the command. + +See :c:type:`struct nvme_ana_rsp_hdr ` for the definition of the returned structure. + +**Return** + +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_get_log_ana_groups (nvme_mi_ctrl_t ctrl, bool rae, __u32 len, struct nvme_ana_group_desc *log) + + Retrieve Asymmetric Namespace Access groups only log page + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to query + +``bool rae`` + Retain asynchronous events + +``__u32 len`` + The allocated length of the log page + +``struct nvme_ana_group_desc *log`` + User address to store the ana group log + +**Description** + +See :c:type:`struct nvme_ana_group_desc ` for the definition of the returned structure. + +**Return** + +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_get_log_lba_status (nvme_mi_ctrl_t ctrl, bool rae, __u64 offset, __u32 len, void *log) + + Retrieve LBA Status + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to query + +``bool rae`` + Retain asynchronous events + +``__u64 offset`` + Offset to the start of the log page + +``__u32 len`` + The allocated length of the log page + +``void *log`` + User address to store the log page + +**Return** + +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_get_log_endurance_grp_evt (nvme_mi_ctrl_t ctrl, bool rae, __u32 offset, __u32 len, void *log) + + Retrieve Rotational Media Information + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to query + +``bool rae`` + Retain asynchronous events + +``__u32 offset`` + Offset to the start of the log page + +``__u32 len`` + The allocated length of the log page + +``void *log`` + User address to store the log page + +**Return** + +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_get_log_fid_supported_effects (nvme_mi_ctrl_t ctrl, bool rae, struct nvme_fid_supported_effects_log *log) + + Retrieve Feature Identifiers Supported and Effects + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to query + +``bool rae`` + Retain asynchronous events + +``struct nvme_fid_supported_effects_log *log`` + FID Supported and Effects data structure + +**Return** + +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_get_log_mi_cmd_supported_effects (nvme_mi_ctrl_t ctrl, bool rae, struct nvme_mi_cmd_supported_effects_log *log) + + displays the MI Commands Supported by the controller + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to query + +``bool rae`` + Retain asynchronous events + +``struct nvme_mi_cmd_supported_effects_log *log`` + MI Command Supported and Effects data structure + +**Return** + +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_get_log_boot_partition (nvme_mi_ctrl_t ctrl, bool rae, __u8 lsp, __u32 len, struct nvme_boot_partition *part) + + Retrieve Boot Partition + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to query + +``bool rae`` + Retain asynchronous events + +``__u8 lsp`` + The log specified field of LID + +``__u32 len`` + The allocated size, minimum + struct nvme_boot_partition + +``struct nvme_boot_partition *part`` + User address to store the log page + +**Return** + +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_get_log_discovery (nvme_mi_ctrl_t ctrl, bool rae, __u32 offset, __u32 len, void *log) + + Retrieve Discovery log page + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to query + +``bool rae`` + Retain asynchronous events + +``__u32 offset`` + Offset of this log to retrieve + +``__u32 len`` + The allocated size for this portion of the log + +``void *log`` + User address to store the discovery log + +**Description** + +Supported only by fabrics discovery controllers, returning discovery +records. + +**Return** + +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_get_log_media_unit_stat (nvme_mi_ctrl_t ctrl, __u16 domid, struct nvme_media_unit_stat_log *mus) + + Retrieve Media Unit Status + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to query + +``__u16 domid`` + Domain Identifier selection, if supported + +``struct nvme_media_unit_stat_log *mus`` + User address to store the Media Unit statistics log + +**Return** + +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_get_log_support_cap_config_list (nvme_mi_ctrl_t ctrl, __u16 domid, struct nvme_supported_cap_config_list_log *cap) + + Retrieve Supported Capacity Configuration List + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to query + +``__u16 domid`` + Domain Identifier selection, if supported + +``struct nvme_supported_cap_config_list_log *cap`` + User address to store supported capabilities config list + +**Return** + +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_get_log_reservation (nvme_mi_ctrl_t ctrl, bool rae, struct nvme_resv_notification_log *log) + + Retrieve Reservation Notification + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to query + +``bool rae`` + Retain asynchronous events + +``struct nvme_resv_notification_log *log`` + User address to store the reservation log + +**Return** + +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_get_log_sanitize (nvme_mi_ctrl_t ctrl, bool rae, struct nvme_sanitize_log_page *log) + + Retrieve Sanitize Status + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to query + +``bool rae`` + Retain asynchronous events + +``struct nvme_sanitize_log_page *log`` + User address to store the sanitize log + +**Description** + +The Sanitize Status log page reports sanitize operation time estimates and +information about the most recent sanitize operation. + +**Return** + +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_get_log_zns_changed_zones (nvme_mi_ctrl_t ctrl, __u32 nsid, bool rae, struct nvme_zns_changed_zone_log *log) + + Retrieve list of zones that have changed + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to query + +``__u32 nsid`` + Namespace ID + +``bool rae`` + Retain asynchronous events + +``struct nvme_zns_changed_zone_log *log`` + User address to store the changed zone log + +**Description** + +The list of zones that have changed state due to an exceptional event. + +**Return** + +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_get_log_persistent_event (nvme_mi_ctrl_t ctrl, enum nvme_pevent_log_action action, __u32 size, void *pevent_log) + + Retrieve Persistent Event Log + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to query + +``enum nvme_pevent_log_action action`` + Action the controller should take during processing this command + +``__u32 size`` + Size of **pevent_log** + +``void *pevent_log`` + User address to store the persistent event log + +**Return** + +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_security_send (nvme_mi_ctrl_t ctrl, struct nvme_security_send_args *args) + + Perform a Security Send command on a controller. + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to send command to + +``struct nvme_security_send_args *args`` + Security Send command arguments + +**Description** + +Performs a Security Send Admin command as specified by **args**. Response data +is stored in **args->data**, which should be a buffer of **args->data_len** bytes. +Resulting data length is stored in **args->data_len** on successful +command completion. + +Security Send data length should not be greater than 4096 bytes to +comply with specification limits. + +See: :c:type:`struct nvme_get_log_args ` + +**Return** + +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_security_recv (nvme_mi_ctrl_t ctrl, struct nvme_security_receive_args *args) + + Perform a Security Receive command on a controller. + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to send command to + +``struct nvme_security_receive_args *args`` + Security Receive command arguments + +**Description** + +Performs a Security Receive Admin command as specified by **args**. Response +data is stored in **args->data**, which should be a buffer of **args->data_len** +bytes. Resulting data length is stored in **args->data_len** on successful +command completion. + +Security Receive data length should not be greater than 4096 bytes to +comply with specification limits. + +See: :c:type:`struct nvme_get_log_args ` + +**Return** + +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_get_features (nvme_mi_ctrl_t ctrl, struct nvme_get_features_args *args) + + Perform a Get Feature command on a controller + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to send command to + +``struct nvme_get_features_args *args`` + Get Features command arguments + +**Description** + +Performs a Get Features Admin command as specified by **args**. Returned +feature data will be stored in **args->result** and **args->data**, depending +on the specification of the feature itself; most features do not return +additional data. See section 5.27.1 of the NVMe spec (v2.0b) for +feature-specific information. + +On success, **args->data_len** will be updated with the actual data length +received. + +**Return** + +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_get_features_data (nvme_mi_ctrl_t ctrl, enum nvme_features_id fid, __u32 nsid, __u32 data_len, void *data, __u32 *result) + + Helper function for :c:type:`nvme_mi_admin_get_features`() + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to send command to + +``enum nvme_features_id fid`` + Feature identifier + +``__u32 nsid`` + Namespace ID, if applicable for **fid** + +``__u32 data_len`` + Length of feature data, if applicable for **fid**, in bytes + +``void *data`` + User address of feature data, if applicable + +``__u32 *result`` + The command completion result from CQE dword0 + +**Description** + +Helper for optionally features that optionally return data, using the +SEL_CURRENT selector value. + +**Return** + +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_get_features_simple (nvme_mi_ctrl_t ctrl, enum nvme_features_id fid, __u32 nsid, __u32 *result) + + Get a simple feature value with no data + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to send command to + +``enum nvme_features_id fid`` + Feature identifier + +``__u32 nsid`` + Namespace id, if required by **fid** + +``__u32 *result`` + output feature data + + +.. c:function:: int nvme_mi_admin_set_features (nvme_mi_ctrl_t ctrl, struct nvme_set_features_args *args) + + Perform a Set Features command on a controller + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to send command to + +``struct nvme_set_features_args *args`` + Set Features command arguments + +**Description** + +Performs a Set Features Admin command as specified by **args**. Result +data will be stored in **args->result**. +on the specification of the feature itself; most features do not return +additional data. See section 5.27.1 of the NVMe spec (v2.0b) for +feature-specific information. + +On success, **args->data_len** will be updated with the actual data length +received. + +**Return** + +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_ns_mgmt (nvme_mi_ctrl_t ctrl, struct nvme_ns_mgmt_args *args) + + Issue a Namespace Management command + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to send command to + +``struct nvme_ns_mgmt_args *args`` + Namespace management command arguments + +**Description** + +Issues a Namespace Management command to **ctrl**, with arguments specified +from **args**. + +**Return** + +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_ns_mgmt_create (nvme_mi_ctrl_t ctrl, struct nvme_id_ns *ns, __u8 csi, __u32 *nsid) + + Helper for Namespace Management Create command + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to send command to + +``struct nvme_id_ns *ns`` + New namespace parameters + +``__u8 csi`` + Command Set Identifier for new NS + +``__u32 *nsid`` + Set to new namespace ID on create + +**Description** + +Issues a Namespace Management (Create) command to **ctrl**, to create a +new namespace specified by **ns**, using command set **csi**. On success, +the new namespace ID will be written to **nsid**. + +**Return** + +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_ns_mgmt_delete (nvme_mi_ctrl_t ctrl, __u32 nsid) + + Helper for Namespace Management Delete command + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to send command to + +``__u32 nsid`` + Namespace ID to delete + +**Description** + +Issues a Namespace Management (Delete) command to **ctrl**, to delete the +namespace with id **nsid**. + +**Return** + +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_ns_attach (nvme_mi_ctrl_t ctrl, struct nvme_ns_attach_args *args) + + Attach or detach namespace to controller(s) + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to send command to + +``struct nvme_ns_attach_args *args`` + Namespace Attach command arguments + +**Return** + +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_ns_attach_ctrls (nvme_mi_ctrl_t ctrl, __u32 nsid, struct nvme_ctrl_list *ctrlist) + + Attach namespace to controllers + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to send command to + +``__u32 nsid`` + Namespace ID to attach + +``struct nvme_ctrl_list *ctrlist`` + Controller list to modify attachment state of nsid + +**Return** + +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_ns_detach_ctrls (nvme_mi_ctrl_t ctrl, __u32 nsid, struct nvme_ctrl_list *ctrlist) + + Detach namespace from controllers + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to send command to + +``__u32 nsid`` + Namespace ID to detach + +``struct nvme_ctrl_list *ctrlist`` + Controller list to modify attachment state of nsid + +**Return** + +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_fw_download (nvme_mi_ctrl_t ctrl, struct nvme_fw_download_args *args) + + Download part or all of a firmware image to the controller + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to send firmware data to + +``struct nvme_fw_download_args *args`` + :c:type:`struct nvme_fw_download_args ` argument structure + +**Description** + +The Firmware Image Download command downloads all or a portion of an image +for a future update to the controller. The Firmware Image Download command +downloads a new image (in whole or in part) to the controller. + +The image may be constructed of multiple pieces that are individually +downloaded with separate Firmware Image Download commands. Each Firmware +Image Download command includes a Dword Offset and Number of Dwords that +specify a dword range. + +The new firmware image is not activated as part of the Firmware Image +Download command. Use the nvme_mi_admin_fw_commit() to activate a newly +downloaded image. + +**Return** + +0 on success, non-zero on failure + + +.. c:function:: int nvme_mi_admin_fw_commit (nvme_mi_ctrl_t ctrl, struct nvme_fw_commit_args *args) + + Commit firmware using the specified action + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to send firmware data to + +``struct nvme_fw_commit_args *args`` + :c:type:`struct nvme_fw_download_args ` argument structure + +**Description** + +The Firmware Commit command modifies the firmware image or Boot Partitions. + +**Return** + +0 on success, non-zero on failure + + +.. c:function:: int nvme_mi_admin_format_nvm (nvme_mi_ctrl_t ctrl, struct nvme_format_nvm_args *args) + + Format NVMe namespace + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to send command to + +``struct nvme_format_nvm_args *args`` + Format NVM command arguments + +**Description** + +Perform a low-level format to set the LBA data & metadata size. May destroy +data & metadata on the specified namespaces + +**Return** + +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. + + +.. c:function:: int nvme_mi_admin_sanitize_nvm (nvme_mi_ctrl_t ctrl, struct nvme_sanitize_nvm_args *args) + + Start a subsystem Sanitize operation + +**Parameters** + +``nvme_mi_ctrl_t ctrl`` + Controller to send command to + +``struct nvme_sanitize_nvm_args *args`` + Sanitize command arguments + +**Description** + +A sanitize operation alters all user data in the NVM subsystem such that +recovery of any previous user data from any cache, the non-volatile media, +or any Controller Memory Buffer is not possible. + +The Sanitize command starts a sanitize operation or to recover from a +previously failed sanitize operation. The sanitize operation types that may +be supported are Block Erase, Crypto Erase, and Overwrite. All sanitize +operations are processed in the background, i.e., completion of the sanitize +command does not indicate completion of the sanitize operation. + +**Return** + +The nvme command status if a response was received (see +:c:type:`enum nvme_status_field `) or -1 with errno set otherwise. diff --git a/doc/rst/tree.rst b/doc/rst/tree.rst index 2334464..d6f270d 100644 --- a/doc/rst/tree.rst +++ b/doc/rst/tree.rst @@ -824,7 +824,7 @@ A pointer to the 64-bit eui A pointer to the 128-bit nguid -.. c:function:: void nvme_ns_get_uuid (nvme_ns_t n, uuid_t out) +.. c:function:: void nvme_ns_get_uuid (nvme_ns_t n, unsigned char out[NVME_UUID_LEN]) UUID of a namespace @@ -833,7 +833,7 @@ A pointer to the 128-bit nguid ``nvme_ns_t n`` Namespace instance -``uuid_t out`` +``unsigned char out[NVME_UUID_LEN]`` buffer for the UUID **Description** @@ -1477,6 +1477,33 @@ Host transport address of **c** (if present) Host interface name of **c** (if present) +.. c:function:: const char * nvme_ctrl_get_dhchap_host_key (nvme_ctrl_t c) + + Return host key + +**Parameters** + +``nvme_ctrl_t c`` + Controller to be checked + +**Return** + +DH-HMAC-CHAP host key or NULL if not set + + +.. c:function:: void nvme_ctrl_set_dhchap_host_key (nvme_ctrl_t c, const char *key) + + Set host key + +**Parameters** + +``nvme_ctrl_t c`` + Host for which the key should be set + +``const char *key`` + DH-HMAC-CHAP Key to set or NULL to clear existing key + + .. c:function:: const char * nvme_ctrl_get_dhchap_key (nvme_ctrl_t c) Return controller key diff --git a/doc/rst/types.rst b/doc/rst/types.rst index 43e2049..9140821 100644 --- a/doc/rst/types.rst +++ b/doc/rst/types.rst @@ -7551,6 +7551,48 @@ bytes, in size. This log captures the controller’s internal state. +.. c:enum:: nvmf_log_discovery_lid_support + + Discovery log specific support + +**Constants** + +``NVMF_LOG_DISC_LID_NONE`` + None + +``NVMF_LOG_DISC_LID_EXTDLPES`` + Extended Discovery Log Page Entries Supported + +``NVMF_LOG_DISC_LID_PLEOS`` + Port Local Entries Only Supported + +``NVMF_LOG_DISC_LID_ALLSUBES`` + All NVM Subsystem Entries Supported + + + + +.. c:enum:: nvmf_log_discovery_lsp + + Discovery log specific field + +**Constants** + +``NVMF_LOG_DISC_LSP_NONE`` + None + +``NVMF_LOG_DISC_LSP_EXTDLPE`` + Extended Discovery Log Page Entries + +``NVMF_LOG_DISC_LSP_PLEO`` + Port Local Entries Only + +``NVMF_LOG_DISC_LSP_ALLSUBE`` + All NVM Subsystem Entries + + + + .. c:struct:: nvmf_discovery_log Discovery Log Page (Log Identifier 70h) @@ -9483,6 +9525,88 @@ status code +.. c:enum:: nvme_status_type + + type encoding for NVMe return values, when represented as an int. + +**Constants** + +``NVME_STATUS_TYPE_SHIFT`` + shift value for status bits + +``NVME_STATUS_TYPE_MASK`` + mask value for status bits + +``NVME_STATUS_TYPE_NVME`` + NVMe command status value, typically from CDW3 + +``NVME_STATUS_TYPE_MI`` + NVMe-MI header status + +**Description** + + +The nvme_* api returns an int, with negative values indicating an internal +or syscall error, zero signifying success, positive values representing +the NVMe status. + +That latter case (the NVMe status) may represent status values from +different parts of the transport/controller/etc, and are at most 16 bits of +data. So, we use the most-significant 3 bits of the signed int to indicate +which type of status this is. + + +.. c:function:: __u32 nvme_status_get_type (int status) + + extract the type from a nvme_* return value + +**Parameters** + +``int status`` + the (non-negative) return value from the NVMe API + +**Return** + +the type component of the status. + + +.. c:function:: __u32 nvme_status_get_value (int status) + + extract the status value from a nvme_* return value + +**Parameters** + +``int status`` + the (non-negative) return value from the NVMe API + +**Return** + +the value component of the status; the set of values will depend +on the status type. + + +.. c:function:: __u32 nvme_status_equals (int status, enum nvme_status_type type, unsigned int value) + + helper to check a status against a type and value + +**Parameters** + +``int status`` + the (non-negative) return value from the NVMe API + +``enum nvme_status_type type`` + the status type + +``unsigned int value`` + the status value + +**Return** + +true if **status** is of the specified type and value + + + + .. c:enum:: nvme_admin_opcode Known NVMe admin opcodes @@ -10592,6 +10716,27 @@ status code +.. c:enum:: nvme_data_tfr + + Data transfer direction of the command + +**Constants** + +``NVME_DATA_TFR_NO_DATA_TFR`` + No data transfer + +``NVME_DATA_TFR_HOST_TO_CTRL`` + Host to controller + +``NVME_DATA_TFR_CTRL_TO_HOST`` + Controller to host + +``NVME_DATA_TFR_BIDIRECTIONAL`` + Bidirectional + + + + .. c:enum:: nvme_io_opcode Opcodes for I/O Commands diff --git a/doc/rst/util.rst b/doc/rst/util.rst index 68ac03b..87ea945 100644 --- a/doc/rst/util.rst +++ b/doc/rst/util.rst @@ -246,6 +246,33 @@ otherwise. recognize :c:type:`fid`. +.. c:function:: int nvme_get_feature_length2 (int fid, __u32 cdw11, enum nvme_data_tfr dir, __u32 *len) + + Retreive the command payload length for a specific feature identifier + +**Parameters** + +``int fid`` + Feature identifier, see :c:type:`enum nvme_features_id `. + +``__u32 cdw11`` + The cdw11 value may affect the transfer (only known fid is + ``NVME_FEAT_FID_HOST_ID``) + +``enum nvme_data_tfr dir`` + Data transfer direction: false - host to controller, true - + controller to host may affect the transfer (only known fid is + ``NVME_FEAT_FID_HOST_MEM_BUF``). + +``__u32 *len`` + On success, set to this features payload length in bytes. + +**Return** + +0 on success, -1 with errno set to EINVAL if the function did not +recognize :c:type:`fid`. + + .. c:function:: int nvme_get_directive_receive_length (enum nvme_directive_dtype dtype, enum nvme_directive_receive_doper doper, __u32 *len) Get directive receive length @@ -492,3 +519,56 @@ Pointer to the next element in the array. Returns version string for known types or else "n/a" +.. c:function:: int nvme_uuid_to_string (unsigned char uuid[NVME_UUID_LEN], char *str) + + Return string represenation of encoded UUID + +**Parameters** + +``unsigned char uuid[NVME_UUID_LEN]`` + Binary encoded input UUID + +``char *str`` + Output string represenation of UUID + +**Return** + +Returns error code if type conversion fails. + + +.. c:function:: int nvme_uuid_from_string (const char *str, unsigned char uuid[NVME_UUID_LEN]) + + Return encoded UUID represenation of string UUID + +**Parameters** + +``const char *str`` + Output string represenation of UUID + +``unsigned char uuid[NVME_UUID_LEN]`` + Binary encoded input UUID + +**Return** + +Returns error code if type conversion fails. + + +.. c:function:: int nvme_uuid_random (unsigned char uuid[NVME_UUID_LEN]) + + Generate random UUID + +**Parameters** + +``unsigned char uuid[NVME_UUID_LEN]`` + Generated random UUID + +**Description** + +Generate random number according +https://www.rfc-editor.org/rfc/rfc4122#section-4.4 + +**Return** + +Returns error code if generating of random number fails. + + diff --git a/examples/discover-loop.c b/examples/discover-loop.c index 10c72b8..7528067 100644 --- a/examples/discover-loop.c +++ b/examples/discover-loop.c @@ -87,5 +87,6 @@ int main() print_discover_log(log); nvme_free_tree(r); + free(log); return 0; } diff --git a/examples/discover-loop.py b/examples/discover-loop.py index 22c51e6..09a976b 100644 --- a/examples/discover-loop.py +++ b/examples/discover-loop.py @@ -17,20 +17,49 @@ License for the specific language governing permissions and limitations under the License. ''' +import sys +import pprint from libnvme import nvme + +def disc_supp_str(dlp_supp_opts): + d = { + nvme.NVMF_LOG_DISC_LID_EXTDLPES: "Extended Discovery Log Page Entry Supported (EXTDLPES)", + nvme.NVMF_LOG_DISC_LID_PLEOS: "Port Local Entries Only Supported (PLEOS)", + nvme.NVMF_LOG_DISC_LID_ALLSUBES: "All NVM Subsystem Entries Supported (ALLSUBES)", + } + return [txt for msk, txt in d.items() if dlp_supp_opts & msk] + r = nvme.root() h = nvme.host(r) -c = nvme.ctrl(nvme.NVME_DISC_SUBSYS_NAME, 'loop') +c = nvme.ctrl(r, nvme.NVME_DISC_SUBSYS_NAME, 'loop') try: c.connect(h) -except: - sys.exit("Failed to connect!") +except Exception as e: + sys.exit(f'Failed to connect: {e}') print("connected to %s subsys %s" % (c.name, c.subsystem.name)) + +slp = c.supported_log_pages() + +try: + dlp_supp_opts = slp[nvme.NVME_LOG_LID_DISCOVER] >> 16 +except (TypeError, IndexError): + dlp_supp_opts = 0 + +print(f"LID {nvme.NVME_LOG_LID_DISCOVER}h (Discovery), supports: {disc_supp_str(dlp_supp_opts)}") + +try: + lsp = nvme.NVMF_LOG_DISC_LSP_PLEO if dlp_supp_opts & nvme.NVMF_LOG_DISC_LID_PLEOS else 0 + d = c.discover(lsp=lsp) + print(pprint.pformat(d)) +except Exception as e: + sys.exit(f'Failed to discover: {e}') + try: - d = c.discover() - print (d) -except: - print("Failed to discover!") - pass c.disconnect() +except Exception as e: + sys.exit(f'Failed to disconnect: {e}') + +c = None +h = None +r = None diff --git a/examples/meson.build b/examples/meson.build index fcea3fb..31d05d7 100644 --- a/examples/meson.build +++ b/examples/meson.build @@ -39,3 +39,12 @@ executable( dependencies: libnvme_mi_dep, include_directories: [incdir, internal_incdir] ) + +if libsystemd_dep.found() + executable( + 'mi-conf', + ['mi-conf.c'], + dependencies: [libnvme_mi_dep, libsystemd_dep], + include_directories: [incdir, internal_incdir] + ) +endif diff --git a/examples/mi-conf.c b/examples/mi-conf.c new file mode 100644 index 0000000..90d590e --- /dev/null +++ b/examples/mi-conf.c @@ -0,0 +1,196 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/** + * This file is part of libnvme. + * Copyright (c) 2022 Code Construct Pty Ltd. + * + * Authors: Jeremy Kerr + */ + +/** + * mi-conf: query a device for optimal MTU and set for both the local MCTP + * route (through dbus to mctpd) and the device itself (through NVMe-MI + * configuration commands) + */ + +#include +#include +#include +#include +#include + +#include + +#include +#include + +#include + +#define MCTP_DBUS_NAME "xyz.openbmc_project.MCTP" +#define MCTP_DBUS_PATH "/xyz/openbmc_project/mctp" +#define MCTP_DBUS_EP_IFACE "au.com.CodeConstruct.MCTP.Endpoint" + +static int parse_mctp(const char *devstr, unsigned int *net, uint8_t *eid) +{ + int rc; + + rc = sscanf(devstr, "mctp:%u,%hhu", net, eid); + if (rc != 2) + return -1; + + return 0; +} + +int find_port(nvme_mi_ep_t ep, uint8_t *portp, uint16_t *mtup) +{ + struct nvme_mi_read_nvm_ss_info ss_info; + struct nvme_mi_read_port_info port_info; + uint8_t port; + bool found; + int rc; + + /* query number of ports */ + rc = nvme_mi_mi_read_mi_data_subsys(ep, &ss_info); + if (rc) { + warn("Failed reading subsystem info"); + return -1; + } + + found = false; + for (port = 0; port <= ss_info.nump; port++) { + rc = nvme_mi_mi_read_mi_data_port(ep, port, &port_info); + if (rc) { + warn("Failed reading port info for port %ud", port); + return -1; + } + + /* skip non-SMBus ports */ + if (port_info.portt != 0x2) + continue; + + if (found) { + warn("Mutliple SMBus ports; skipping duplicate"); + } else { + *portp = port; + *mtup = port_info.mmctptus; + found = true; + } + } + + return found ? 0 : 1; +} + +int set_local_mtu(sd_bus *bus, unsigned int net, uint8_t eid, uint32_t mtu) +{ + sd_bus_error err = SD_BUS_ERROR_NULL; + sd_bus_message *resp; + char *ep_path; + int rc; + + rc = asprintf(&ep_path, "%s/%u/%hhu", MCTP_DBUS_PATH, net, eid); + if (rc < 0) { + warn("Failed to create dbus path"); + return -1; + } + + /* The NVMe-MI interfaces refer to their MTU as *not* including the + * 4-byte MCTP header, whereas the MCTP specs *do* include it. When + * we're setting the route MTU, we're using to the MCTP-style MTU, + * which needs the extra four bytes included + */ + mtu += 4; + + rc = sd_bus_call_method(bus, MCTP_DBUS_NAME, ep_path, + MCTP_DBUS_EP_IFACE, "SetMTU", &err, &resp, + "u", mtu); + if (rc < 0) { + warnx("Failed to set local MTU: %s", strerror(-rc)); + return -1; + } + + return 0; +} + +int main(int argc, char **argv) +{ + uint16_t cur_mtu, mtu; + const char *devstr; + uint8_t eid, port; + nvme_root_t root; + unsigned int net; + nvme_mi_ep_t ep; + sd_bus *bus; + int rc; + + if (argc != 2) { + fprintf(stderr, "usage: %s mctp:,\n", argv[0]); + return EXIT_FAILURE; + } + + devstr = argv[1]; + rc = parse_mctp(devstr, &net, &eid); + if (rc) + errx(EXIT_FAILURE, "can't parse MI device string '%s'", devstr); + + root = nvme_mi_create_root(stderr, DEFAULT_LOGLEVEL); + if (!root) + err(EXIT_FAILURE, "can't create NVMe root"); + + ep = nvme_mi_open_mctp(root, net, eid); + if (!ep) { + warnx("can't open MCTP endpoint %d:%d", net, eid); + goto out_free_root; + } + + rc = sd_bus_default_system(&bus); + if (rc < 0) { + goto out_close_ep; + warnx("Failed opening D-Bus: %s\n", strerror(-rc)); + } + + rc = find_port(ep, &port, &mtu); + if (rc) { + warnx("Can't find SMBus port information"); + goto out_close_bus; + } + + rc = nvme_mi_mi_config_get_mctp_mtu(ep, port, &cur_mtu); + if (rc) { + cur_mtu = 0; + warn("Can't query current MTU; no way to revert on failure"); + } + + if (mtu == cur_mtu) { + printf("Current MTU (%d) is already at max\n", cur_mtu); + goto out_close_bus; + } + + rc = nvme_mi_mi_config_set_mctp_mtu(ep, port, mtu); + if (rc) { + warn("Can't set MCTP MTU"); + goto out_close_bus; + } + + rc = set_local_mtu(bus, net, eid, mtu); + if (rc) { + /* revert if we have an old setting */ + if (cur_mtu) { + rc = nvme_mi_mi_config_set_mctp_mtu(ep, port, cur_mtu); + if (rc) + warn("Failed to restore previous MTU!"); + rc = -1; + } + } else { + printf("MTU for port %u set to %d (was %d)\n", + port, mtu, cur_mtu); + } + +out_close_bus: + sd_bus_close(bus); +out_close_ep: + nvme_mi_close(ep); +out_free_root: + nvme_mi_free_root(root); + + return rc ? EXIT_FAILURE : EXIT_SUCCESS; +} + diff --git a/examples/mi-mctp.c b/examples/mi-mctp.c index 589bb44..8d660af 100644 --- a/examples/mi-mctp.c +++ b/examples/mi-mctp.c @@ -661,6 +661,12 @@ static int do_action_endpoint(enum action action, nvme_mi_ep_t ep, int argc, cha case ACTION_CONFIG_SET: rc = do_config_set(ep, argc, argv); break; + default: + /* This shouldn't be possible, as we should be covering all + * of the enum action options above. Hoever, keep the compilers + * happy and fail gracefully. */ + fprintf(stderr, "invalid action %d?\n", action); + rc = -1; } return rc; } diff --git a/libnvme/README.md b/libnvme/README.md index f61e5cc..3195715 100644 --- a/libnvme/README.md +++ b/libnvme/README.md @@ -10,16 +10,24 @@ import sys import pprint from libnvme import nvme +def disc_supp_str(dlp_supp_opts): + bitmap = { + nvme.NVMF_LOG_DISC_LID_EXTDLPES: "EXTDLPES", + nvme.NVMF_LOG_DISC_LID_PLEOS: "PLEOS", + nvme.NVMF_LOG_DISC_LID_ALLSUBES: "ALLSUBES", + } + return [txt for msk, txt in bitmap.items() if dlp_supp_opts & msk] + root = nvme.root() # This is a singleton root.log_level('debug') # Optional: extra debug info host = nvme.host(root) # This "may be" a singleton. -sybsysnqn = [string] # e.g. 'nqn.2014-08.org.nvmexpress.discovery', nvme.NVME_DISC_SUBSYS_NAME, ... -transport = [string] # One of: 'tcp, 'rdma', 'fc', 'loop'. +subsysnqn = [string] # e.g. nvme.NVME_DISC_SUBSYS_NAME, ... +transport = [string] # One of: 'tcp', 'rdma', 'fc', 'loop'. traddr = [IPv4 or IPv6] # e.g. '192.168.10.10', 'fd2e:853b:3cad:e135:506a:65ee:29f2:1b18', ... trsvcid = [string] # e.g. '8009', '4420', ... host_iface = [interface] # e.g. 'eth1', ens256', ... -ctrl = nvme.ctrl(subsysnqn=subsysnqn, transport=transport, traddr=traddr, trsvcid=trsvcid, host_iface=host_iface) +ctrl = nvme.ctrl(root, subsysnqn=subsysnqn, transport=transport, traddr=traddr, trsvcid=trsvcid, host_iface=host_iface) try: cfg = { @@ -31,8 +39,17 @@ try: except Exception as e: sys.exit(f'Failed to connect: {e}') +supported_log_pages = ctrl.supported_log_pages() +try: + # Get the supported options for the Get Discovery Log Page command + dlp_supp_opts = supported_log_pages[nvme.NVME_LOG_LID_DISCOVER] >> 16 +except (TypeError, IndexError): + dlp_supp_opts = 0 + +print(f"LID {nvme.NVME_LOG_LID_DISCOVER:02x}h (Discovery), supports: {disc_supp_str(dlp_supp_opts)}") try: - log_pages = ctrl.discover() + lsp = nvme.NVMF_LOG_DISC_LSP_PLEO if dlp_supp_opts & nvme.NVMF_LOG_DISC_LID_PLEOS else 0 + log_pages = ctrl.discover(lsp=lsp) print(pprint.pformat(log_pages)) except Exception as e: sys.exit(f'Failed to retrieve log pages: {e}') @@ -42,5 +59,8 @@ try: except Exception as e: sys.exit(f'Failed to disconnect: {e}') +ctrl = None +host = None +root = None ``` diff --git a/libnvme/nvme.i b/libnvme/nvme.i index 14e2415..6f20e2c 100644 --- a/libnvme/nvme.i +++ b/libnvme/nvme.i @@ -21,10 +21,13 @@ %{ #include +#include #include "nvme/tree.h" #include "nvme/fabrics.h" #include "nvme/private.h" #include "nvme/log.h" +#include "nvme/ioctl.h" +#include "nvme/types.h" static int host_iter_err = 0; static int subsys_iter_err = 0; @@ -287,7 +290,9 @@ struct nvme_host { char *hostnqn; char *hostid; char *hostsymname; - char *dhchap_key; + %extend { + char *dhchap_key; + } }; struct nvme_subsystem { @@ -314,6 +319,7 @@ struct nvme_ctrl { %immutable subsysnqn; %immutable traddr; %immutable trsvcid; + %immutable dhchap_host_key; %immutable dhchap_key; %immutable cntrltype; %immutable dctype; @@ -332,7 +338,10 @@ struct nvme_ctrl { char *subsysnqn; char *traddr; char *trsvcid; - char *dhchap_key; + %extend { + char *dhchap_host_key: + char *dhchap_key; + } char *cntrltype; char *dctype; bool discovery_ctrl; @@ -448,6 +457,15 @@ struct nvme_ns { } } +%{ + const char *nvme_host_dhchap_key_get(struct nvme_host *h) { + return nvme_host_get_dhchap_key(h); + } + void nvme_host_dhchap_key_set(struct nvme_host *h, char *key) { + nvme_host_set_dhchap_key(h, key); + } +%}; + %extend subsystem_iter { struct subsystem_iter *__iter__() { return $self; @@ -610,25 +628,46 @@ struct nvme_ns { } %newobject discover; - struct nvmf_discovery_log *discover(int max_retries = 6) { - struct nvmf_discovery_log *logp = NULL; + struct nvmf_discovery_log *discover(int lsp = 0, int max_retries = 6) { + struct nvme_get_discovery_args args = { + .c = $self, + .args_size = sizeof(args), + .max_retries = max_retries, + .result = NULL, + .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, + .lsp = lsp, + }; + struct nvmf_discovery_log *logp = nvmf_get_discovery_wargs(&args); + if (logp == NULL) + discover_err = 1; + return logp; + } + + %feature("autodoc", "@return: List of supported log pages") supported_log_pages; + PyObject * supported_log_pages(bool rae=true) { + struct nvme_supported_log_pages log; + PyObject *obj = NULL; int ret = 0; - ret = nvmf_get_discovery_log($self, &logp, max_retries); + + ret = nvme_get_log_supported_log_pages(nvme_ctrl_get_fd($self), rae, &log); if (ret < 0) { - discover_err = 1; - return NULL; + Py_RETURN_NONE; } - return logp; + + obj = PyList_New(NVME_LOG_SUPPORTED_LOG_PAGES_MAX); + if (!obj) + Py_RETURN_NONE; + + for (int i = 0; i < NVME_LOG_SUPPORTED_LOG_PAGES_MAX; i++) + PyList_SetItem(obj, i, PyLong_FromLong(le32_to_cpu(log.lid_support[i]))); /* steals ref. */ + + return obj; } - char *__str__() { - static char tmp[1024]; - if ($self->address) - sprintf(tmp, "nvme_ctrl(transport=%s,%s)", $self->transport, - $self->address); - else - sprintf(tmp, "nvme_ctrl(transport=%s)", $self->transport); - return tmp; + PyObject *__str__() { + return $self->address ? + PyUnicode_FromFormat("nvme_ctrl(transport=%s,%s)", $self->transport, $self->address) : + PyUnicode_FromFormat("nvme_ctrl(transport=%s)", $self->transport); } struct ctrl_iter __iter__() { struct ctrl_iter ret = { .subsystem = nvme_ctrl_get_subsystem($self), @@ -656,6 +695,12 @@ struct nvme_ns { const char *nvme_ctrl_state_get(struct nvme_ctrl *c) { return nvme_ctrl_get_state(c); } + const char *nvme_ctrl_dhchap_key_get(struct nvme_ctrl *c) { + return nvme_ctrl_get_dhchap_key(c); + } + const char *nvme_ctrl_dhchap_host_key_get(struct nvme_ctrl *c) { + return nvme_ctrl_get_dhchap_host_key(c); + } %}; %extend nvme_ns { @@ -689,9 +734,6 @@ struct nvme_ns { // We want to swig all the #define and enum from types.h, but none of the structs. -%{ -#include "nvme/types.h" -%} #define __attribute__(x) %rename($ignore, %$isclass) ""; // ignore all classes/structs %rename($ignore, %$isfunction) ""; // ignore all functions diff --git a/meson.build b/meson.build index bd13fe9..5c2e73a 100644 --- a/meson.build +++ b/meson.build @@ -7,8 +7,8 @@ # project( 'libnvme', ['c'], - meson_version: '>= 0.47.0', - version: '1.1', + meson_version: '>= 0.48.0', + version: '1.2', license: 'LGPL-2.1-or-later', default_options: [ 'c_std=gnu99', @@ -18,7 +18,8 @@ project( ] ) -library_version = meson.project_version() + '.0' +maj_min = meson.project_version().split('-rc')[0] +library_version = maj_min + '.0' ################################################################################ cc = meson.get_compiler('c') @@ -51,10 +52,6 @@ conf.set('PROJECT_VERSION', '"@0@"'.format(meson.project_version())) conf.set('SYSCONFDIR', '"@0@"'.format(sysconfdir)) -# Check for libuuid availability -libuuid_dep = dependency('uuid', required: true, fallback : ['uuid', 'uuid_dep']) -conf.set('CONFIG_LIBUUID', libuuid_dep.found(), description: 'Is libuuid required?') - # Check for json-c availability json_c_dep = dependency('json-c', version: '>=0.13', @@ -185,6 +182,29 @@ conf.set10( description: 'Is linux/mctp.h include-able?' ) +if meson.version().version_compare('>= 0.48') + has_fallthrough = cc.has_function_attribute('fallthrough') +else + has_fallthrough = cc.compiles( + '''int main(int argc, char **argv) { + switch(argc) { + case 0: + __attribute__((__fallthrough__)); + case 1: + return 1; + } + return 0; + } + ''', + name: 'has fallthrough') +endif + +if has_fallthrough + conf.set('fallthrough', '__attribute__((__fallthrough__))') +else + conf.set('fallthrough', 'do {} while (0) /* fallthrough */') +endif + ################################################################################ substs = configuration_data() substs.set('NAME', meson.project_name()) diff --git a/release.sh b/release.sh index 2199eac..320da46 100755 --- a/release.sh +++ b/release.sh @@ -1,39 +1,50 @@ #!/bin/bash usage() { - echo "release.sh: VERSION" + echo "Usage: release.sh [-d] VERSION" echo "" echo "The script does all necessary steps to create a new release." echo "" + echo " -d: no documentation update" + echo "" echo "Note: The version number needs to be exactly" - echo " '^v[\d]+.[\d]+(-rc[0-9]+)?$'" + echo " '^v[\d]+.[\d]+(.[\d\]+(-rc[0-9]+)?$'" echo "" echo "example:" - echo " release.sh v2.1-rc0 # v2.1 release candidate 0 -> sets the project " - echo " # version to '1.1' and sets the tag" - echo " release.sh v2.1-rc1 # v2.1 release canditate 1 -> only sets the tag" - echo " release.sh v2.1 # v2.1 release -> sets the final tag" + echo " release.sh v2.1-rc0 # v2.1 release candidate 0" + echo " release.sh v2.1 # v2.1 release" } -VERSION=$1 +build_doc=true + +while getopts "d" o; do + case "${o}" in + d) + build_doc=false + ;; + *) + usage + ;; + esac +done +shift $((OPTIND-1)) + +VERSION=${1:-} if [ -z "$VERSION" ] ; then usage exit 1 fi -new_ver="" -rc="" +ver="" -re='^v([0-9]+\.[0-9]+)(-rc[0-9]+)?$' +re='^v([0-9]+\.[0-9]+(\.[0-9]+)?)(-rc[0-9]+)?$' if [[ "$VERSION" =~ $re ]]; then echo "Valid version $VERSION string" - new_ver=${BASH_REMATCH[1]} - rc=${BASH_REMATCH[2]} + # remove the leading 'v' + ver=${VERSION#v} else echo "Invalid version string $VERSION" - echo "" - usage exit 1 fi @@ -58,22 +69,18 @@ else exit 1 fi -./$doc_dir/update-docs.sh -git add $doc_dir -git commit -s -m "Regenerate all documentation" \ - -m "Regenerate documentation for $VERSION release" - # update meson.build -old_ver=$(sed -n "0,/[ \t]\+version: /s/[ \t]\+version: '\([0-9]\+.[0-9]\+\)',$/\1/p" meson.build) -if [ "$old_ver" != "$new_ver" ]; then - # Only update project version once, that is either - # - for the first RC phase or - # - for the release when there was no RC - sed -i -e "0,/[ \t]version: /s/\([ \t]version: \).*/\1\'$new_ver\',/" meson.build - git add meson.build +sed -i -e "0,/[ \t]version: /s/\([ \t]version: \).*/\1\'$ver\',/" meson.build +git add meson.build +git commit -s -m "build: Update version to $VERSION" + +if [ "$build_doc" = true ]; then + # update documentation + ./$doc_dir/update-docs.sh + git add $doc_dir + git commit -s -m "doc: Regenerate all docs for $VERSION" fi -git commit -s -m "Release $VERSION" git tag -s -m "Release $VERSION" "$VERSION" git push --dry-run origin "$VERSION"^{}:master tag "$VERSION" diff --git a/src/libnvme-mi.map b/src/libnvme-mi.map index e16b400..53af942 100644 --- a/src/libnvme-mi.map +++ b/src/libnvme-mi.map @@ -1,3 +1,16 @@ +LIBNVME_MI_1_2 { + global: + nvme_mi_admin_get_features; + nvme_mi_admin_set_features; + nvme_mi_admin_ns_mgmt; + nvme_mi_admin_ns_attach; + nvme_mi_admin_format_nvm; + nvme_mi_admin_sanitize_nvm; + nvme_mi_admin_fw_download; + nvme_mi_admin_fw_commit; + nvme_mi_status_to_string; +}; + LIBNVME_MI_1_1 { global: nvme_mi_create_root; diff --git a/src/libnvme.map b/src/libnvme.map index 50a688d..be9bca3 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -1,5 +1,17 @@ # SPDX-License-Identifier: LGPL-2.1-or-later +LIBNVME_1_2 { + global: + nvme_ctrl_get_dhchap_host_key; + nvme_ctrl_set_dhchap_host_key; + nvmf_get_discovery_wargs; + nvme_get_feature_length2; + nvme_ctrl_is_persistent; + nvme_uuid_from_string; + nvme_uuid_to_string; + nvme_uuid_random; +}; + LIBNVME_1_1 { global: nvme_get_version; diff --git a/src/meson.build b/src/meson.build index 3076be6..9e49a07 100644 --- a/src/meson.build +++ b/src/meson.build @@ -28,13 +28,11 @@ if conf.get('CONFIG_JSONC') endif deps = [ - libuuid_dep, json_c_dep, openssl_dep, ] mi_deps = [ - libuuid_dep, libsystemd_dep, ] @@ -68,7 +66,6 @@ pkg.generate(libnvme, libnvme_dep = declare_dependency( include_directories: ['.'], dependencies: [ - libuuid_dep.partial_dependency(compile_args: true, includes: true), json_c_dep.partial_dependency(compile_args: true, includes: true), ], link_with: libnvme, @@ -88,9 +85,6 @@ libnvme_mi = library( libnvme_mi_dep = declare_dependency( include_directories: ['.'], - dependencies: [ - libuuid_dep.partial_dependency(compile_args: true, includes: true), - ], link_with: libnvme_mi, ) @@ -107,9 +101,6 @@ libnvme_mi_test = library( libnvme_mi_test_dep = declare_dependency( include_directories: ['.'], - dependencies: [ - libuuid_dep.partial_dependency(compile_args: true, includes: true), - ], link_with: libnvme_mi_test, ) diff --git a/src/nvme/fabrics.c b/src/nvme/fabrics.c index b68b7b9..a501f79 100644 --- a/src/nvme/fabrics.c +++ b/src/nvme/fabrics.c @@ -39,7 +39,6 @@ #include "private.h" #define NVMF_HOSTID_SIZE 37 -#define UUID_SIZE 37 /* 1b4e28ba-2fa1-11d2-883f-0016d3cca427 + \0 */ #define NVMF_HOSTNQN_FILE SYSCONFDIR "/nvme/hostnqn" #define NVMF_HOSTID_FILE SYSCONFDIR "/nvme/hostid" @@ -192,13 +191,15 @@ void nvmf_default_config(struct nvme_fabrics_config *cfg) #define MERGE_CFG_OPTION(c, n, o, d) \ if ((c)->o == d) (c)->o = (n)->o +#define MERGE_CFG_OPTION_STR(c, n, o, d) \ + if ((c)->o == d && (n)->o) (c)->o = strdup((n)->o) static struct nvme_fabrics_config *merge_config(nvme_ctrl_t c, const struct nvme_fabrics_config *cfg) { struct nvme_fabrics_config *ctrl_cfg = nvme_ctrl_get_config(c); - MERGE_CFG_OPTION(ctrl_cfg, cfg, host_traddr, NULL); - MERGE_CFG_OPTION(ctrl_cfg, cfg, host_iface, NULL); + MERGE_CFG_OPTION_STR(ctrl_cfg, cfg, host_traddr, NULL); + MERGE_CFG_OPTION_STR(ctrl_cfg, cfg, host_iface, NULL); MERGE_CFG_OPTION(ctrl_cfg, cfg, nr_io_queues, 0); MERGE_CFG_OPTION(ctrl_cfg, cfg, nr_write_queues, 0); MERGE_CFG_OPTION(ctrl_cfg, cfg, nr_poll_queues, 0); @@ -295,7 +296,7 @@ static int add_argument(char **argstr, const char *tok, const char *arg) { char *nstr; - if (!(arg && strcmp(arg, "none"))) + if (!arg || arg[0] == '\0' || !strcmp(arg, "none")) return 0; if (asprintf(&nstr, "%s,%s=%s", *argstr, tok, arg) < 0) { errno = ENOMEM; @@ -465,6 +466,8 @@ static int build_options(nvme_host_t h, nvme_ctrl_t c, char **argstr) hostnqn = nvme_host_get_hostnqn(h); hostid = nvme_host_get_hostid(h); hostkey = nvme_host_get_dhchap_key(h); + if (!hostkey) + hostkey = nvme_ctrl_get_dhchap_host_key(c); ctrlkey = nvme_ctrl_get_dhchap_key(c); if (add_argument(argstr, "transport", transport) || add_argument(argstr, "traddr", @@ -613,14 +616,20 @@ int nvmf_add_ctrl(nvme_host_t h, nvme_ctrl_t c, nvme_ctrl_get_trsvcid(c), NULL); if (fc) { + const char *key; + cfg = merge_config(c, nvme_ctrl_get_config(fc)); /* * An authentication key might already been set * in @cfg, so ensure to update @c with the correct * controller key. */ - if (fc->dhchap_key) - nvme_ctrl_set_dhchap_key(c, fc->dhchap_key); + key = nvme_ctrl_get_dhchap_host_key(fc); + if (key) + nvme_ctrl_set_dhchap_host_key(c, key); + key = nvme_ctrl_get_dhchap_key(fc); + if (key) + nvme_ctrl_set_dhchap_key(c, key); } } @@ -734,7 +743,7 @@ nvme_ctrl_t nvmf_connect_disc_entry(nvme_host_t h, default: nvme_msg(h->r, LOG_ERR, "unsupported subtype %d\n", e->subtype); - /* fallthrough */ + fallthrough; case NVME_NQN_NVME: nvme_ctrl_set_discovery_ctrl(c, false); break; @@ -772,30 +781,9 @@ nvme_ctrl_t nvmf_connect_disc_entry(nvme_host_t h, return NULL; } -static int nvme_discovery_log(int fd, __u32 len, struct nvmf_discovery_log *log, bool rae) -{ - struct nvme_get_log_args args = { - .args_size = sizeof(args), - .fd = fd, - .nsid = NVME_NSID_NONE, - .lsp = NVME_LOG_LSP_NONE, - .lsi = NVME_LOG_LSI_NONE, - .uuidx = NVME_UUID_NONE, - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, - .result = NULL, - .lid = NVME_LOG_LID_DISCOVER, - .log = log, - .len = len, - .csi = NVME_CSI_NVM, - .rae = rae, - .ot = false, - }; - - return nvme_get_log_page(fd, 4096, &args); -} - -int nvmf_get_discovery_log(nvme_ctrl_t c, struct nvmf_discovery_log **logp, - int max_retries) +static struct nvmf_discovery_log *nvme_discovery_log(nvme_ctrl_t c, + struct nvme_get_log_args *args, + int max_retries) { nvme_root_t r = c->s && c->s->h ? c->s->h->r : NULL; struct nvmf_discovery_log *log = NULL; @@ -803,6 +791,9 @@ int nvmf_get_discovery_log(nvme_ctrl_t c, struct nvmf_discovery_log **logp, const char *name = nvme_ctrl_get_name(c); uint64_t genctr, numrec; unsigned int size; + int fd = nvme_ctrl_get_fd(c); + + args->fd = fd; do { size = sizeof(struct nvmf_discovery_log); @@ -813,12 +804,15 @@ int nvmf_get_discovery_log(nvme_ctrl_t c, struct nvmf_discovery_log **logp, nvme_msg(r, LOG_ERR, "could not allocate memory for discovery log header\n"); errno = ENOMEM; - return -1; + return NULL; } nvme_msg(r, LOG_DEBUG, "%s: get header (try %d/%d)\n", name, retries, max_retries); - ret = nvme_discovery_log(nvme_ctrl_get_fd(c), size, log, true); + args->rae = true; + args->len = size; + args->log = log; + ret = nvme_get_log_page(fd, 4096, args); if (ret) { nvme_msg(r, LOG_INFO, "%s: discover try %d/%d failed, error %d\n", @@ -841,14 +835,19 @@ int nvmf_get_discovery_log(nvme_ctrl_t c, struct nvmf_discovery_log **logp, nvme_msg(r, LOG_ERR, "could not alloc memory for discovery log page\n"); errno = ENOMEM; - return -1; + return NULL; } nvme_msg(r, LOG_DEBUG, "%s: get header and %" PRIu64 " records (length %d genctr %" PRIu64 ")\n", name, numrec, size, genctr); - ret = nvme_discovery_log(nvme_ctrl_get_fd(c), size, log, false); + + args->rae = false; + args->len = size; + args->log = log; + ret = nvme_get_log_page(fd, 4096, args); + if (ret) { nvme_msg(r, LOG_INFO, "%s: discover try %d/%d failed, error %d\n", @@ -861,21 +860,63 @@ int nvmf_get_discovery_log(nvme_ctrl_t c, struct nvmf_discovery_log **logp, if (genctr != le64_to_cpu(log->genctr)) { nvme_msg(r, LOG_INFO, "%s: discover genctr mismatch\n", name); errno = EAGAIN; - ret = -1; } else if (numrec != le64_to_cpu(log->numrec)) { nvme_msg(r, LOG_INFO, "%s: could only fetch %" PRIu64 " of %" PRIu64 " records\n", name, numrec, le64_to_cpu(log->numrec)); errno = EBADSLT; - ret = -1; } else { - *logp = log; - return 0; + return log; } out_free_log: free(log); - return ret; + return NULL; +} + +int nvmf_get_discovery_log(nvme_ctrl_t c, struct nvmf_discovery_log **logp, + int max_retries) +{ + struct nvme_get_log_args args = { + .args_size = sizeof(args), + .fd = nvme_ctrl_get_fd(c), + .nsid = NVME_NSID_NONE, + .lsp = NVMF_LOG_DISC_LSP_NONE, + .lsi = NVME_LOG_LSI_NONE, + .uuidx = NVME_UUID_NONE, + .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, + .result = NULL, + .lid = NVME_LOG_LID_DISCOVER, + .log = NULL, + .len = 0, + .csi = NVME_CSI_NVM, + .rae = false, + .ot = false, + }; + *logp = nvme_discovery_log(c, &args, max_retries); + return logp ? 0 : -1; +} + +struct nvmf_discovery_log *nvmf_get_discovery_wargs(struct nvme_get_discovery_args *args) +{ + struct nvme_get_log_args _args = { + .args_size = sizeof(_args), + .fd = nvme_ctrl_get_fd(args->c), + .nsid = NVME_NSID_NONE, + .lsp = args->lsp, + .lsi = NVME_LOG_LSI_NONE, + .uuidx = NVME_UUID_NONE, + .timeout = args->timeout, + .result = args->result, + .lid = NVME_LOG_LID_DISCOVER, + .log = NULL, + .len = 0, + .csi = NVME_CSI_NVM, + .rae = false, + .ot = false, + }; + + return nvme_discovery_log(args->c, &_args, args->max_retries); } #define PATH_UUID_IBM "/proc/device-tree/ibm,partition-uuid" @@ -889,8 +930,8 @@ static int uuid_from_device_tree(char *system_uuid) if (f < 0) return -ENXIO; - memset(system_uuid, 0, UUID_SIZE); - len = read(f, system_uuid, UUID_SIZE - 1); + memset(system_uuid, 0, NVME_UUID_LEN_STRING); + len = read(f, system_uuid, NVME_UUID_LEN_STRING - 1); close(f); if (len < 0) return -ENXIO; @@ -978,7 +1019,7 @@ static int uuid_from_product_uuid(char *system_uuid) system_uuid[0] = '\0'; nread = getline(&line, &len, stream); - if (nread != UUID_SIZE) { + if (nread != NVME_UUID_LEN_STRING) { ret = -ENXIO; goto out; } @@ -986,8 +1027,8 @@ static int uuid_from_product_uuid(char *system_uuid) /* The kernel is handling the byte swapping according DMTF * SMBIOS 3.0 Section 7.2.1 System UUID */ - memcpy(system_uuid, line, UUID_SIZE - 1); - system_uuid[UUID_SIZE - 1] = '\0'; + memcpy(system_uuid, line, NVME_UUID_LEN_STRING - 1); + system_uuid[NVME_UUID_LEN_STRING - 1] = '\0'; ret = 0; @@ -1023,16 +1064,17 @@ char *nvmf_hostnqn_generate() { char *hostnqn; int ret; - char uuid_str[UUID_SIZE]; - uuid_t uuid; + char uuid_str[NVME_UUID_LEN_STRING]; + unsigned char uuid[NVME_UUID_LEN]; ret = uuid_from_dmi(uuid_str); if (ret < 0) { ret = uuid_from_device_tree(uuid_str); } if (ret < 0) { - uuid_generate_random(uuid); - uuid_unparse_lower(uuid, uuid_str); + if (nvme_uuid_random(uuid) < 0) + memset(uuid, 0, NVME_UUID_LEN); + nvme_uuid_to_string(uuid, uuid_str); } if (asprintf(&hostnqn, "nqn.2014-08.org.nvmexpress:uuid:%s", uuid_str) < 0) @@ -1085,7 +1127,7 @@ static __u32 nvmf_get_tel(const char *hostsymname) __u16 len; /* Host ID is mandatory */ - tel += nvmf_exat_size(sizeof(uuid_t)); + tel += nvmf_exat_size(NVME_UUID_LEN_STRING); /* Symbolic name is optional */ len = hostsymname ? strlen(hostsymname) : 0; @@ -1129,8 +1171,8 @@ static void nvmf_fill_die(struct nvmf_ext_die *die, struct nvme_host *h, numexat++; exat = die->exat; exat->exattype = cpu_to_le16(NVMF_EXATTYPE_HOSTID); - exat->exatlen = cpu_to_le16(nvmf_exat_len(sizeof(uuid_t))); - uuid_parse(h->hostid, exat->exatval); + exat->exatlen = cpu_to_le16(nvmf_exat_len(NVME_UUID_LEN)); + nvme_uuid_from_string(h->hostid, exat->exatval); /* Extended Attribute for the Symbolic Name (optional) */ symname_len = h->hostsymname ? strlen(h->hostsymname) : 0; diff --git a/src/nvme/fabrics.h b/src/nvme/fabrics.h index 9e099fe..272bb40 100644 --- a/src/nvme/fabrics.h +++ b/src/nvme/fabrics.h @@ -195,15 +195,55 @@ int nvmf_add_ctrl(nvme_host_t h, nvme_ctrl_t c, /** * nvmf_get_discovery_log() - Return the discovery log page - * @c: Discover controller to use + * @c: Discovery controller to use * @logp: Pointer to the log page to be returned - * @max_retries: maximum number of log page entries to be returned + * @max_retries: Number of retries in case of failure + * + * The memory allocated for the log page and returned in @logp + * must be freed by the caller using free(). + * + * Note: Consider using nvmf_get_discovery_wargs() instead. * * Return: 0 on success; on failure -1 is returned and errno is set */ int nvmf_get_discovery_log(nvme_ctrl_t c, struct nvmf_discovery_log **logp, int max_retries); +/** + * struct nvme_get_discovery_args - Arguments for nvmf_get_discovery_wargs() + * @c: Discovery controller + * @args_size: Length of the structure + * @max_retries: Number of retries in case of failure + * @result: The command completion result from CQE dword0 + * @timeout: Timeout in ms (default: NVME_DEFAULT_IOCTL_TIMEOUT) + * @lsp: Log specific field (See enum nvmf_log_discovery_lsp) + */ +struct nvme_get_discovery_args { + nvme_ctrl_t c; + int args_size; + int max_retries; + __u32 *result; + __u32 timeout; + __u8 lsp; +}; + +/** + * nvmf_get_discovery_wargs() - Get the discovery log page with args + * @args: Argument structure + * + * This function is similar to nvmf_get_discovery_log(), but + * takes an extensible @args parameter. @args provides more + * options than nvmf_get_discovery_log(). + * + * This function performs a get discovery log page (DLP) command + * and returns the DLP. The memory allocated for the returned + * DLP must be freed by the caller using free(). + * + * Return: Pointer to the discovery log page (to be freed). NULL + * on failure and errno is set. + */ +struct nvmf_discovery_log *nvmf_get_discovery_wargs(struct nvme_get_discovery_args *args); + /** * nvmf_hostnqn_generate() - Generate a machine specific host nqn * Returns: An nvm namespace qualified name string based on the machine diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index d559b12..af95851 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -1461,7 +1461,7 @@ static inline int nvme_get_log_telemetry_host(int fd, __u64 offset, __u32 len, void *log) { struct nvme_get_log_args args = { - .lpo = 0, + .lpo = offset, .result = NULL, .log = log, .args_size = sizeof(args), diff --git a/src/nvme/json.c b/src/nvme/json.c index b42cd51..f0c2ab4 100644 --- a/src/nvme/json.c +++ b/src/nvme/json.c @@ -95,6 +95,9 @@ static void json_parse_port(nvme_subsystem_t s, struct json_object *port_obj) if (!c) return; json_update_attributes(c, port_obj); + attr_obj = json_object_object_get(port_obj, "dhchap_key"); + if (attr_obj) + nvme_ctrl_set_dhchap_host_key(c, json_object_get_string(attr_obj)); attr_obj = json_object_object_get(port_obj, "dhchap_ctrl_key"); if (attr_obj) nvme_ctrl_set_dhchap_key(c, json_object_get_string(attr_obj)); @@ -155,6 +158,43 @@ static void json_parse_host(nvme_root_t r, struct json_object *host_obj) } } +static struct json_object *parse_json(nvme_root_t r, int fd) +{ + char buf[JSON_FILE_BUF_SIZE]; + struct json_object *obj = NULL; + struct printbuf *pb; + json_tokener *tok = NULL; + int ret; + + pb = printbuf_new(); + if (!pb) + return NULL; + + while ((ret = read(fd, buf, JSON_FILE_BUF_SIZE)) > 0) + printbuf_memappend(pb, buf, ret); + + if (ret < 0) + goto out; + + tok = json_tokener_new_ex(JSON_TOKENER_DEFAULT_DEPTH); + if (!tok) + goto out; + + /* Enforce correctly formatted JSON */ + tok->flags = JSON_TOKENER_STRICT; + + obj = json_tokener_parse_ex(tok, pb->buf, printbuf_length(pb)); + if (!obj) + nvme_msg(r, LOG_DEBUG, "JSON parsing failed: %s\n", + json_util_get_last_err()); +out: + if (tok) + json_tokener_free(tok); + printbuf_free(pb); + + return obj; +} + int json_read_config(nvme_root_t r, const char *config_file) { struct json_object *json_root, *host_obj; @@ -166,12 +206,16 @@ int json_read_config(nvme_root_t r, const char *config_file) config_file, strerror(errno)); return fd; } - json_root = json_object_from_fd(fd); + json_root = parse_json(r, fd); + close(fd); if (!json_root) { - nvme_msg(r, LOG_DEBUG, "Failed to read %s, %s\n", - config_file, json_util_get_last_err()); errno = EPROTO; - close(fd); + return -1; + } + if (!json_object_is_type(json_root, json_type_array)) { + nvme_msg(r, LOG_DEBUG, "Wrong format, expected array\n"); + json_object_put(json_root); + errno = EPROTO; return -1; } for (h = 0; h < json_object_array_length(json_root); h++) { @@ -180,7 +224,6 @@ int json_read_config(nvme_root_t r, const char *config_file) json_parse_host(r, host_obj); } json_object_put(json_root); - close(fd); return 0; } @@ -222,6 +265,10 @@ static void json_update_port(struct json_object *ctrl_array, nvme_ctrl_t c) if (value) json_object_object_add(port_obj, "trsvcid", json_object_new_string(value)); + value = nvme_ctrl_get_dhchap_host_key(c); + if (value) + json_object_object_add(port_obj, "dhchap_key", + json_object_new_string(value)); value = nvme_ctrl_get_dhchap_key(c); if (value) json_object_object_add(port_obj, "dhchap_ctrl_key", @@ -365,6 +412,10 @@ static void json_dump_ctrl(struct json_object *ctrl_array, nvme_ctrl_t c) if (value) json_object_object_add(ctrl_obj, "trsvcid", json_object_new_string(value)); + value = nvme_ctrl_get_dhchap_host_key(c); + if (value) + json_object_object_add(ctrl_obj, "dhchap_key", + json_object_new_string(value)); value = nvme_ctrl_get_dhchap_key(c); if (value) json_object_object_add(ctrl_obj, "dhchap_ctrl_key", diff --git a/src/nvme/mi-mctp.c b/src/nvme/mi-mctp.c index ae604f2..86f5df6 100644 --- a/src/nvme/mi-mctp.c +++ b/src/nvme/mi-mctp.c @@ -179,13 +179,15 @@ struct nvme_mi_msg_resp_mpr { * populate the worst-case expected processing time, given in milliseconds. */ static bool nvme_mi_mctp_resp_is_mpr(struct nvme_mi_resp *resp, size_t len, - unsigned int *mpr_time) + __le32 mic, unsigned int *mpr_time) { + struct nvme_mi_admin_resp_hdr *admin_msg; struct nvme_mi_msg_resp_mpr *msg; - __le32 mic; + size_t clen; __u32 crc; - if (len != sizeof(*msg) + sizeof(mic)) + /* We need at least the minimal header plus checksum */ + if (len < sizeof(*msg) + sizeof(mic)) return false; msg = (struct nvme_mi_msg_resp_mpr *)resp->hdr; @@ -193,22 +195,42 @@ static bool nvme_mi_mctp_resp_is_mpr(struct nvme_mi_resp *resp, size_t len, if (msg->status != NVME_MI_RESP_MPR) return false; - /* We can't use verify_resp_mic here, as the response structure has - * not been laid-out properly in resp yet (this is deferred until - * we have the actual response). + /* Find and verify the MIC from the response, which may not be laid out + * in resp as we expect. We have to preserve resp->hdr_len and + * resp->data_len, as we will need them for the eventual reply message. + * Because of that, we can't use verify_resp_mic here. * - * We know the data is a fixed size, and linear in the hdr buf, so - * calculation is fairly simple. We do need to find the MIC data - * though, which could either be in the header buf (if the original - * header was larger than the minimal header message), or the start of - * the data buf (otherwise). + * If the packet was at the expected response size, then mic will + * be set already; if not, find it within the header/data buffers. + */ + + /* Devices may send a MPR response as a full-sized Admin response, + * rather than the minimal MI-only header. Allow this, but only if the + * type indicates admin, and the allocated response header is the + * correct size for an Admin response. + */ + if (((msg->hdr.nmp >> 3) & 0xf) == NVME_MI_MT_ADMIN && + len == sizeof(*admin_msg) + sizeof(mic) && + resp->hdr_len == sizeof(*admin_msg)) { + if (resp->data_len) + mic = *(__le32 *)resp->data; + } else if (len == sizeof(*msg) + sizeof(mic)) { + if (resp->hdr_len > sizeof(*msg)) + mic = *(__le32 *)(msg + 1); + else if (resp->data_len) + mic = *(__le32 *)(resp->data); + } else { + return false; + } + + /* Since our response is just a header, we're guaranteed to have + * all data in resp->hdr. The response may be shorter than the expected + * header though, so clamp to len. */ - if (resp->hdr_len > sizeof(*msg)) - mic = *(__le32 *)(msg + 1); - else - mic = *(__le32 *)(resp->data); + len -= sizeof(mic); + clen = len < resp->hdr_len ? len : resp->hdr_len; - crc = ~nvme_mi_crc32_update(0xffffffff, msg, sizeof(*msg)); + crc = ~nvme_mi_crc32_update(0xffffffff, resp->hdr, clen); if (le32_to_cpu(mic) != crc) return false; @@ -369,7 +391,7 @@ retry: * header fields. However, we need to do this in the transport in order * to keep the tag allocated and retry the recvmsg */ - if (nvme_mi_mctp_resp_is_mpr(resp, len, &mpr_time)) { + if (nvme_mi_mctp_resp_is_mpr(resp, len, mic, &mpr_time)) { nvme_msg(ep->root, LOG_DEBUG, "Received More Processing Required, waiting for response\n"); @@ -493,6 +515,7 @@ nvme_mi_ep_t nvme_mi_open_mctp(nvme_root_t root, unsigned int netid, __u8 eid) err_free_ep: errno_save = errno; free(ep); + free(mctp); errno = errno_save; return NULL; } diff --git a/src/nvme/mi.c b/src/nvme/mi.c index 181a16c..6ff0a6f 100644 --- a/src/nvme/mi.c +++ b/src/nvme/mi.c @@ -11,6 +11,7 @@ #include #include +#include #include #include "log.h" @@ -295,6 +296,52 @@ static void nvme_mi_admin_init_resp(struct nvme_mi_resp *resp, resp->hdr_len = sizeof(*hdr); } +static int nvme_mi_admin_parse_status(struct nvme_mi_resp *resp, __u32 *result) +{ + struct nvme_mi_admin_resp_hdr *admin_hdr; + struct nvme_mi_msg_resp *resp_hdr; + __u32 nvme_status; + __u32 nvme_result; + + /* we have a few different sources of "result" here: the status header + * in the MI response, the cdw3 status field, and (command specific) + * return values in cdw0. The latter is returned in the result pointer, + * the former two generate return values here + */ + + if (resp->hdr_len < sizeof(*resp_hdr)) { + errno = -EPROTO; + return -1; + } + resp_hdr = (struct nvme_mi_msg_resp *)resp->hdr; + + /* If we have a MI error, we can't be sure there's an admin header + * following; return just the MI status, with the status type + * indicator of MI. + */ + if (resp_hdr->status) + return resp_hdr->status | + (NVME_STATUS_TYPE_MI << NVME_STATUS_TYPE_SHIFT); + + /* We shouldn't hit this, as we'd have an error reported earlier. + * However, for pointer safety, ensure we have a full admin header + */ + if (resp->hdr_len < sizeof(*admin_hdr)) { + errno = EPROTO; + return -1; + } + + admin_hdr = (struct nvme_mi_admin_resp_hdr *)resp->hdr; + nvme_result = le32_to_cpu(admin_hdr->cdw0); + nvme_status = le32_to_cpu(admin_hdr->cdw3) >> 16; + + /* the result pointer, optionally stored if the caller needs it */ + if (result) + *result = nvme_result; + + return nvme_status; +} + int nvme_mi_admin_xfer(nvme_mi_ctrl_t ctrl, struct nvme_mi_admin_req_hdr *admin_req, size_t req_data_size, @@ -343,6 +390,7 @@ int nvme_mi_admin_xfer(nvme_mi_ctrl_t ctrl, admin_req->hdr.type = NVME_MI_MSGTYPE_NVME; admin_req->hdr.nmp = (NVME_MI_ROR_REQ << 7) | (NVME_MI_MT_ADMIN << 3); + admin_req->ctrl_id = cpu_to_le16(ctrl->id); memset(&req, 0, sizeof(req)); req.hdr = &admin_req->hdr; req.hdr_len = sizeof(*admin_req); @@ -414,11 +462,9 @@ int nvme_mi_admin_identify_partial(nvme_mi_ctrl_t ctrl, if (rc) return rc; - if (resp_hdr.status) - return resp_hdr.status; - - if (args->result) - *args->result = le32_to_cpu(resp_hdr.cdw0); + rc = nvme_mi_admin_parse_status(&resp, args->result); + if (rc) + return rc; /* callers will expect a full response; if the data buffer isn't * fully valid, return an error */ @@ -452,7 +498,7 @@ static int __nvme_mi_admin_get_log(nvme_mi_ctrl_t ctrl, return -1; } - if (offset < 0 || offset >= len) { + if (offset < 0 || offset >= args->len || offset + len > args->len) { errno = EINVAL; return -1; } @@ -489,12 +535,11 @@ static int __nvme_mi_admin_get_log(nvme_mi_ctrl_t ctrl, if (rc) return rc; - if (resp_hdr.status) - return resp_hdr.status; - - *lenp = resp.data_len; + rc = nvme_mi_admin_parse_status(&resp, args->result); + if (!rc) + *lenp = resp.data_len; - return 0; + return rc; } int nvme_mi_admin_get_log(nvme_mi_ctrl_t ctrl, struct nvme_get_log_args *args) @@ -580,13 +625,7 @@ int nvme_mi_admin_security_send(nvme_mi_ctrl_t ctrl, if (rc) return rc; - if (resp_hdr.status) - return resp_hdr.status; - - if (args->result) - *args->result = le32_to_cpu(resp_hdr.cdw0); - - return 0; + return nvme_mi_admin_parse_status(&resp, args->result); } int nvme_mi_admin_security_recv(nvme_mi_ctrl_t ctrl, @@ -632,17 +671,306 @@ int nvme_mi_admin_security_recv(nvme_mi_ctrl_t ctrl, if (rc) return rc; - if (resp_hdr.status) - return resp_hdr.status; + rc = nvme_mi_admin_parse_status(&resp, args->result); + if (rc) + return rc; + + args->data_len = resp.data_len; + + return 0; +} + +int nvme_mi_admin_get_features(nvme_mi_ctrl_t ctrl, + struct nvme_get_features_args *args) +{ + struct nvme_mi_admin_resp_hdr resp_hdr; + struct nvme_mi_admin_req_hdr req_hdr; + struct nvme_mi_resp resp; + struct nvme_mi_req req; + int rc; + + if (args->args_size < sizeof(*args)) + return -EINVAL; + + nvme_mi_admin_init_req(&req, &req_hdr, ctrl->id, + nvme_admin_get_features); + + req_hdr.cdw1 = cpu_to_le32(args->nsid); + req_hdr.cdw10 = cpu_to_le32((args->sel & 0x7) << 8 | args->fid); + req_hdr.cdw14 = cpu_to_le32(args->uuidx & 0x7f); + req_hdr.cdw11 = cpu_to_le32(args->cdw11); + + nvme_mi_calc_req_mic(&req); + + nvme_mi_admin_init_resp(&resp, &resp_hdr); + resp.data = args->data; + resp.data_len = args->data_len; - if (args->result) - *args->result = resp_hdr.cdw0; + rc = nvme_mi_submit(ctrl->ep, &req, &resp); + if (rc) + return rc; + + rc = nvme_mi_admin_parse_status(&resp, args->result); + if (rc) + return rc; + + args->data_len = resp.data_len; + + return 0; +} + +int nvme_mi_admin_set_features(nvme_mi_ctrl_t ctrl, + struct nvme_set_features_args *args) +{ + struct nvme_mi_admin_resp_hdr resp_hdr; + struct nvme_mi_admin_req_hdr req_hdr; + struct nvme_mi_resp resp; + struct nvme_mi_req req; + int rc; + + if (args->args_size < sizeof(*args)) + return -EINVAL; + + nvme_mi_admin_init_req(&req, &req_hdr, ctrl->id, + nvme_admin_set_features); + + req_hdr.cdw1 = cpu_to_le32(args->nsid); + req_hdr.cdw10 = cpu_to_le32((args->save ? 1 : 0) << 31 | + (args->fid & 0xff)); + req_hdr.cdw14 = cpu_to_le32(args->uuidx & 0x7f); + req_hdr.cdw11 = cpu_to_le32(args->cdw11); + req_hdr.cdw12 = cpu_to_le32(args->cdw12); + req_hdr.cdw13 = cpu_to_le32(args->cdw13); + req_hdr.cdw15 = cpu_to_le32(args->cdw15); + + req.data_len = args->data_len; + req.data = args->data; + + nvme_mi_calc_req_mic(&req); + + nvme_mi_admin_init_resp(&resp, &resp_hdr); + + rc = nvme_mi_submit(ctrl->ep, &req, &resp); + if (rc) + return rc; + + rc = nvme_mi_admin_parse_status(&resp, args->result); + if (rc) + return rc; args->data_len = resp.data_len; return 0; } +int nvme_mi_admin_ns_mgmt(nvme_mi_ctrl_t ctrl, + struct nvme_ns_mgmt_args *args) +{ + struct nvme_mi_admin_resp_hdr resp_hdr; + struct nvme_mi_admin_req_hdr req_hdr; + struct nvme_mi_resp resp; + struct nvme_mi_req req; + int rc; + + if (args->args_size < sizeof(*args)) + return -EINVAL; + + nvme_mi_admin_init_req(&req, &req_hdr, ctrl->id, + nvme_admin_ns_mgmt); + + req_hdr.cdw1 = cpu_to_le32(args->nsid); + req_hdr.cdw10 = cpu_to_le32(args->sel & 0xf); + req_hdr.cdw11 = cpu_to_le32(args->csi << 24); + if (args->ns) { + req.data = args->ns; + req.data_len = sizeof(*args->ns); + req_hdr.dlen = cpu_to_le32(sizeof(*args->ns)); + req_hdr.flags = 0x1; + } + + nvme_mi_calc_req_mic(&req); + + nvme_mi_admin_init_resp(&resp, &resp_hdr); + + rc = nvme_mi_submit(ctrl->ep, &req, &resp); + if (rc) + return rc; + + return nvme_mi_admin_parse_status(&resp, args->result); +} + +int nvme_mi_admin_ns_attach(nvme_mi_ctrl_t ctrl, + struct nvme_ns_attach_args *args) +{ + struct nvme_mi_admin_resp_hdr resp_hdr; + struct nvme_mi_admin_req_hdr req_hdr; + struct nvme_mi_resp resp; + struct nvme_mi_req req; + int rc; + + if (args->args_size < sizeof(*args)) + return -EINVAL; + + nvme_mi_admin_init_req(&req, &req_hdr, ctrl->id, + nvme_admin_ns_attach); + + req_hdr.cdw1 = cpu_to_le32(args->nsid); + req_hdr.cdw10 = cpu_to_le32(args->sel & 0xf); + req.data = args->ctrlist; + req.data_len = sizeof(*args->ctrlist); + req_hdr.dlen = cpu_to_le32(sizeof(*args->ctrlist)); + req_hdr.flags = 0x1; + + nvme_mi_calc_req_mic(&req); + + nvme_mi_admin_init_resp(&resp, &resp_hdr); + + rc = nvme_mi_submit(ctrl->ep, &req, &resp); + if (rc) + return rc; + + return nvme_mi_admin_parse_status(&resp, args->result); +} + +int nvme_mi_admin_fw_download(nvme_mi_ctrl_t ctrl, + struct nvme_fw_download_args *args) +{ + struct nvme_mi_admin_resp_hdr resp_hdr; + struct nvme_mi_admin_req_hdr req_hdr; + struct nvme_mi_resp resp; + struct nvme_mi_req req; + int rc; + + if (args->args_size < sizeof(*args)) + return -EINVAL; + + if (args->data_len & 0x3) + return -EINVAL; + + if (args->offset & 0x3) + return -EINVAL; + + if (!args->data_len) + return -EINVAL; + + nvme_mi_admin_init_req(&req, &req_hdr, ctrl->id, + nvme_admin_fw_download); + + req_hdr.cdw10 = cpu_to_le32((args->data_len >> 2) - 1); + req_hdr.cdw11 = cpu_to_le32(args->offset >> 2); + req.data = args->data; + req.data_len = args->data_len; + req_hdr.dlen = cpu_to_le32(args->data_len); + req_hdr.flags = 0x1; + + nvme_mi_calc_req_mic(&req); + + nvme_mi_admin_init_resp(&resp, &resp_hdr); + + rc = nvme_mi_submit(ctrl->ep, &req, &resp); + if (rc) + return rc; + + return nvme_mi_admin_parse_status(&resp, NULL); +} + +int nvme_mi_admin_fw_commit(nvme_mi_ctrl_t ctrl, + struct nvme_fw_commit_args *args) +{ + struct nvme_mi_admin_resp_hdr resp_hdr; + struct nvme_mi_admin_req_hdr req_hdr; + struct nvme_mi_resp resp; + struct nvme_mi_req req; + int rc; + + if (args->args_size < sizeof(*args)) + return -EINVAL; + + nvme_mi_admin_init_req(&req, &req_hdr, ctrl->id, + nvme_admin_fw_commit); + + req_hdr.cdw10 = cpu_to_le32(((args->bpid & 0x1) << 31) | + ((args->action & 0x7) << 3) | + ((args->slot & 0x7) << 0)); + + nvme_mi_calc_req_mic(&req); + + nvme_mi_admin_init_resp(&resp, &resp_hdr); + + rc = nvme_mi_submit(ctrl->ep, &req, &resp); + if (rc) + return rc; + + return nvme_mi_admin_parse_status(&resp, NULL); +} + +int nvme_mi_admin_format_nvm(nvme_mi_ctrl_t ctrl, + struct nvme_format_nvm_args *args) +{ + struct nvme_mi_admin_resp_hdr resp_hdr; + struct nvme_mi_admin_req_hdr req_hdr; + struct nvme_mi_resp resp; + struct nvme_mi_req req; + int rc; + + if (args->args_size < sizeof(*args)) + return -EINVAL; + + nvme_mi_admin_init_req(&req, &req_hdr, ctrl->id, + nvme_admin_format_nvm); + + req_hdr.cdw1 = cpu_to_le32(args->nsid); + req_hdr.cdw10 = cpu_to_le32(((args->lbafu & 0x3) << 12) + | ((args->ses & 0x7) << 9) + | ((args->pil & 0x1) << 8) + | ((args->pi & 0x7) << 5) + | ((args->mset & 0x1) << 4) + | ((args->lbaf & 0xf) << 0)); + + nvme_mi_calc_req_mic(&req); + + nvme_mi_admin_init_resp(&resp, &resp_hdr); + + rc = nvme_mi_submit(ctrl->ep, &req, &resp); + if (rc) + return rc; + + return nvme_mi_admin_parse_status(&resp, args->result); +} + +int nvme_mi_admin_sanitize_nvm(nvme_mi_ctrl_t ctrl, + struct nvme_sanitize_nvm_args *args) +{ + struct nvme_mi_admin_resp_hdr resp_hdr; + struct nvme_mi_admin_req_hdr req_hdr; + struct nvme_mi_resp resp; + struct nvme_mi_req req; + int rc; + + if (args->args_size < sizeof(*args)) + return -EINVAL; + + nvme_mi_admin_init_req(&req, &req_hdr, ctrl->id, + nvme_admin_sanitize_nvm); + + req_hdr.cdw10 = cpu_to_le32(((args->nodas ? 1 : 0) << 9) + | ((args->oipbp ? 1 : 0) << 8) + | ((args->owpass & 0xf) << 4) + | ((args->ause ? 1 : 0) << 3) + | ((args->sanact & 0x7) << 0)); + req_hdr.cdw11 = cpu_to_le32(args->ovrpat); + + nvme_mi_calc_req_mic(&req); + + nvme_mi_admin_init_resp(&resp, &resp_hdr); + + rc = nvme_mi_submit(ctrl->ep, &req, &resp); + if (rc) + return rc; + + return nvme_mi_admin_parse_status(&resp, args->result); +} + static int nvme_mi_read_data(nvme_mi_ep_t ep, __u32 cdw0, void *data, size_t *data_len) { @@ -955,3 +1283,37 @@ nvme_mi_ctrl_t nvme_mi_next_ctrl(nvme_mi_ep_t ep, nvme_mi_ctrl_t c) { return c ? list_next(&ep->controllers, c, ep_entry) : NULL; } + + +static const char *const mi_status[] = { + [NVME_MI_RESP_MPR] = "More Processing Required: The command message is in progress and requires more time to complete processing", + [NVME_MI_RESP_INTERNAL_ERR] = "Internal Error: The request message could not be processed due to a vendor-specific error", + [NVME_MI_RESP_INVALID_OPCODE] = "Invalid Command Opcode", + [NVME_MI_RESP_INVALID_PARAM] = "Invalid Parameter", + [NVME_MI_RESP_INVALID_CMD_SIZE] = "Invalid Command Size: The size of the message body of the request was different than expected", + [NVME_MI_RESP_INVALID_INPUT_SIZE] = "Invalid Command Input Data Size: The command requires data and contains too much or too little data", + [NVME_MI_RESP_ACCESS_DENIED] = "Access Denied. Processing prohibited due to a vendor-specific mechanism of the Command and Feature lockdown function", + [NVME_MI_RESP_VPD_UPDATES_EXCEEDED] = "VPD Updates Exceeded", + [NVME_MI_RESP_PCIE_INACCESSIBLE] = "PCIe Inaccessible. The PCIe functionality is not available at this time", + [NVME_MI_RESP_MEB_SANITIZED] = "Management Endpoint Buffer Cleared Due to Sanitize", + [NVME_MI_RESP_ENC_SERV_FAILURE] = "Enclosure Services Failure", + [NVME_MI_RESP_ENC_SERV_XFER_FAILURE] = "Enclosure Services Transfer Failure: Communication with the Enclosure Services Process has failed", + [NVME_MI_RESP_ENC_FAILURE] = "An unrecoverable enclosure failure has been detected by the Enclosuer Services Process", + [NVME_MI_RESP_ENC_XFER_REFUSED] = "Enclosure Services Transfer Refused: The NVM Subsystem or Enclosure Services Process indicated an error or an invalid format in communication", + [NVME_MI_RESP_ENC_FUNC_UNSUP] = "Unsupported Enclosure Function: An SES Send command has been attempted to a simple Subenclosure", + [NVME_MI_RESP_ENC_SERV_UNAVAIL] = "Enclosure Services Unavailable: The NVM Subsystem or Enclosure Services Process has encountered an error but may become available again", + [NVME_MI_RESP_ENC_DEGRADED] = "Enclosure Degraded: A noncritical failure has been detected by the Enclosure Services Process", + [NVME_MI_RESP_SANITIZE_IN_PROGRESS] = "Sanitize In Progress: The requested command is prohibited while a sanitize operation is in progress", +}; + +/* kept in mi.c while we have a split libnvme/libnvme-mi; consider moving + * to utils.c (with nvme_status_to_string) if we ever merge. */ +const char *nvme_mi_status_to_string(int status) +{ + const char *s = "Unknown status"; + + if (status < ARRAY_SIZE(mi_status) && mi_status[status]) + s = mi_status[status]; + + return s; +} diff --git a/src/nvme/mi.h b/src/nvme/mi.h index a7ed240..ab4216d 100644 --- a/src/nvme/mi.h +++ b/src/nvme/mi.h @@ -367,6 +367,20 @@ struct nvme_mi_admin_resp_hdr { __le32 cdw0, cdw1, cdw3; } __attribute__((packed)); +/** + * nvme_mi_status_to_string() - return a string representation of the MI + * status. + * @status: MI response status + * + * Gives a string description of @status, as per section 4.1.2 of the NVMe-MI + * spec. The status value should be of type NVME_STATUS_MI, and extracted + * from the return value using nvme_status_get_value(). + * + * Returned string is const, and should not be free()ed. + * + * Returns: A string representing the status value + */ +const char *nvme_mi_status_to_string(int status); /** * nvme_mi_create_root() - Create top-level MI (root) handle. @@ -601,7 +615,8 @@ nvme_root_t nvme_mi_scan_mctp(void); * so, all existing controller objects will be freed - the caller must not * hold a reference to those across this call. * - * Return: 0 on success, non-zero on failure + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. * * See: &nvme_mi_for_each_ctrl */ @@ -652,7 +667,8 @@ char *nvme_mi_endpoint_desc(nvme_mi_ep_t ep); * Retrieves the Subsystem information - number of external ports and * NVMe version information. See &struct nvme_mi_read_nvm_ss_info. * - * Return: 0 on success, non-zero on failure. + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise.. */ int nvme_mi_mi_read_mi_data_subsys(nvme_mi_ep_t ep, struct nvme_mi_read_nvm_ss_info *s); @@ -670,7 +686,8 @@ int nvme_mi_mi_read_mi_data_subsys(nvme_mi_ep_t ep, * * See &struct nvme_mi_read_port_info. * - * Return: 0 on success, non-zero on failure. + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise.. */ int nvme_mi_mi_read_mi_data_port(nvme_mi_ep_t ep, __u8 portid, struct nvme_mi_read_port_info *p); @@ -687,7 +704,8 @@ int nvme_mi_mi_read_mi_data_port(nvme_mi_ep_t ep, __u8 portid, * * See &struct nvme_ctrl_list. * - * Return: 0 on success, non-zero on failure. + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise.. */ int nvme_mi_mi_read_mi_data_ctrl_list(nvme_mi_ep_t ep, __u8 start_ctrlid, struct nvme_ctrl_list *list); @@ -704,7 +722,8 @@ int nvme_mi_mi_read_mi_data_ctrl_list(nvme_mi_ep_t ep, __u8 start_ctrlid, * * See &struct nvme_mi_read_ctrl_info. * - * Return: 0 on success, non-zero on failure. + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise.. */ int nvme_mi_mi_read_mi_data_ctrl(nvme_mi_ep_t ep, __u16 ctrl_id, struct nvme_mi_read_ctrl_info *ctrl); @@ -722,7 +741,8 @@ int nvme_mi_mi_read_mi_data_ctrl(nvme_mi_ep_t ep, __u16 ctrl_id, * * See &struct nvme_mi_nvm_ss_health_status. * - * Return: 0 on success, non-zero on failure. + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise.. */ int nvme_mi_mi_subsystem_health_status_poll(nvme_mi_ep_t ep, bool clear, struct nvme_mi_nvm_ss_health_status *nshds); @@ -744,7 +764,8 @@ int nvme_mi_mi_subsystem_health_status_poll(nvme_mi_ep_t ep, bool clear, * * See &enum nvme_mi_config_id for identifiers. * - * Return: 0 on success, non-zero on failure. + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise.. */ int nvme_mi_mi_config_get(nvme_mi_ep_t ep, __u32 dw0, __u32 dw1, __u32 *nmresp); @@ -761,7 +782,8 @@ int nvme_mi_mi_config_get(nvme_mi_ep_t ep, __u32 dw0, __u32 dw1, * * See &enum nvme_mi_config_id for identifiers. * - * Return: 0 on success, non-zero on failure. + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise.. */ int nvme_mi_mi_config_set(nvme_mi_ep_t ep, __u32 dw0, __u32 dw1); @@ -775,7 +797,8 @@ int nvme_mi_mi_config_set(nvme_mi_ep_t ep, __u32 dw0, __u32 dw1); * the port specified in @port. On success, populates @freq with the port * frequency * - * Return: 0 on success, non-zero on failure. + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise.. */ static inline int nvme_mi_mi_config_get_smbus_freq(nvme_mi_ep_t ep, __u8 port, enum nvme_mi_config_smbus_freq *freq) @@ -787,7 +810,7 @@ static inline int nvme_mi_mi_config_get_smbus_freq(nvme_mi_ep_t ep, __u8 port, rc = nvme_mi_mi_config_get(ep, dw0, 0, &tmp); if (!rc) - *freq = tmp & 0x3; + *freq = (enum nvme_mi_config_smbus_freq)(tmp & 0x3); return rc; } @@ -803,7 +826,8 @@ static inline int nvme_mi_mi_config_get_smbus_freq(nvme_mi_ep_t ep, __u8 port, * See &struct nvme_mi_read_port_info for the maximum supported SMBus frequency * for the port. * - * Return: 0 on success, non-zero on failure. + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise.. */ static inline int nvme_mi_mi_config_set_smbus_freq(nvme_mi_ep_t ep, __u8 port, enum nvme_mi_config_smbus_freq freq) @@ -828,7 +852,8 @@ static inline int nvme_mi_mi_config_set_smbus_freq(nvme_mi_ep_t ep, __u8 port, * See &nvme_mi_mi_subsystem_health_status_poll(), &enum nvme_mi_ccs for * values in @mask. * - * Return: 0 on success, non-zero on failure. + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise.. */ static inline int nvme_mi_mi_config_set_health_status_change(nvme_mi_ep_t ep, __u32 mask) @@ -852,7 +877,8 @@ static inline int nvme_mi_mi_config_set_health_status_change(nvme_mi_ep_t ep, * Some controllers may also use this as the maximum receive unit size, and * may not accept MCTP messages larger than the configured MTU. * - * Return: 0 on success, non-zero on failure. + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise.. */ static inline int nvme_mi_mi_config_get_mctp_mtu(nvme_mi_ep_t ep, __u8 port, __u16 *mtu) @@ -882,7 +908,8 @@ static inline int nvme_mi_mi_config_get_mctp_mtu(nvme_mi_ep_t ep, __u8 port, * this value, you will likely need to change the MTU of the local MCTP * interface(s) to match. * - * Return: 0 on success, non-zero on failure. + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise.. */ static inline int nvme_mi_mi_config_set_mctp_mtu(nvme_mi_ep_t ep, __u8 port, __u16 mtu) @@ -918,7 +945,8 @@ static inline int nvme_mi_mi_config_set_mctp_mtu(nvme_mi_ep_t ep, __u8 port, * * See: &struct nvme_mi_admin_req_hdr and &struct nvme_mi_admin_resp_hdr. * - * Return: 0 on success, non-zero on failure. + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise.. */ int nvme_mi_admin_xfer(nvme_mi_ctrl_t ctrl, struct nvme_mi_admin_req_hdr *admin_req, @@ -949,7 +977,8 @@ int nvme_mi_admin_xfer(nvme_mi_ctrl_t ctrl, * of this. If the type of your identify command is standardized but not * yet supported by libnvme-mi, please contact the maintainers. * - * Return: 0 on success, non-zero on failure + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. * * See: &struct nvme_identify_args */ @@ -969,7 +998,8 @@ int nvme_mi_admin_identify_partial(nvme_mi_ctrl_t ctrl, * Will return an error if the length of the response data (from the * controller) is not a full &NVME_IDENTIFY_DATA_SIZE. * - * Return: 0 on success, non-zero on failure + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. * * See: &struct nvme_identify_args */ @@ -997,7 +1027,8 @@ static inline int nvme_mi_admin_identify(nvme_mi_ctrl_t ctrl, * Will return an error if the length of the response data (from the * controller) is not a full &NVME_IDENTIFY_DATA_SIZE. * - * Return: 0 on success, non-zero on failure + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. */ static inline int nvme_mi_admin_identify_cns_nsid(nvme_mi_ctrl_t ctrl, enum nvme_identify_cns cns, @@ -1018,6 +1049,69 @@ static inline int nvme_mi_admin_identify_cns_nsid(nvme_mi_ctrl_t ctrl, return nvme_mi_admin_identify(ctrl, &args); } +/** + * nvme_mi_admin_identify_ns() - Perform an Admin identify command for a + * namespace + * @ctrl: Controller to process identify command + * @nsid: namespace ID + * @ns: Namespace identification to populate + * + * Perform an Identify (namespace) command, setting the namespace id data + * in @ns. The namespace is expected to active and allocated. + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +static inline int nvme_mi_admin_identify_ns(nvme_mi_ctrl_t ctrl, __u32 nsid, + struct nvme_id_ns *ns) +{ + return nvme_mi_admin_identify_cns_nsid(ctrl, NVME_IDENTIFY_CNS_NS, + nsid, ns); +} + +/** + * nvme_mi_admin_identify_ns_descs() - Perform an Admin identify Namespace + * Identification Descriptor list command for a namespace + * @ctrl: Controller to process identify command + * @nsid: Namespace ID + * @descs: Namespace Identification Descriptor list to populate + * + * Perform an Identify namespace identification description list command, + * setting the namespace identification description list in @descs + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +static inline int nvme_mi_admin_identify_ns_descs(nvme_mi_ctrl_t ctrl, + __u32 nsid, + struct nvme_ns_id_desc *descs) +{ + return nvme_mi_admin_identify_cns_nsid(ctrl, NVME_IDENTIFY_CNS_NS_DESC_LIST, + nsid, descs); +} + +/** + * nvme_mi_admin_identify_allocated_ns() - Perform an Admin identify command + * for an allocated namespace + * @ctrl: Controller to process identify command + * @nsid: namespace ID + * @ns: Namespace identification to populate + * + * Perform an Identify (namespace) command, setting the namespace id data + * in @ns. + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +static inline int nvme_mi_admin_identify_allocated_ns(nvme_mi_ctrl_t ctrl, + __u32 nsid, + struct nvme_id_ns *ns) +{ + return nvme_mi_admin_identify_cns_nsid(ctrl, + NVME_IDENTIFY_CNS_ALLOCATED_NS, + nsid, ns); +} + /** * nvme_mi_admin_identify_ctrl() - Perform an Admin identify for a controller * @ctrl: Controller to process identify command @@ -1030,7 +1124,8 @@ static inline int nvme_mi_admin_identify_cns_nsid(nvme_mi_ctrl_t ctrl, * controller) is not a full &NVME_IDENTIFY_DATA_SIZE, so @id will be * fully populated on success. * - * Return: 0 on success, non-zero on failure + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. * * See: &struct nvme_id_ctrl */ @@ -1055,7 +1150,8 @@ static inline int nvme_mi_admin_identify_ctrl(nvme_mi_ctrl_t ctrl, * controller) is not a full &NVME_IDENTIFY_DATA_SIZE, so @id will be * fully populated on success. * - * Return: 0 on success, non-zero on failure + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. * * See: &struct nvme_ctrl_list */ @@ -1078,6 +1174,198 @@ static inline int nvme_mi_admin_identify_ctrl_list(nvme_mi_ctrl_t ctrl, return nvme_mi_admin_identify(ctrl, &args); } +/** + * nvme_mi_admin_identify_nsid_ctrl_list() - Perform an Admin identify for a + * controller list with specific namespace ID + * @ctrl: Controller to process identify command + * @nsid: Namespace identifier + * @cntid: Controller ID to specify list start + * @list: List data to populate + * + * Perform an Identify command, for the controller list for @nsid, starting + * with IDs greater than or equal to @cntid. + * + * Will return an error if the length of the response data (from the + * controller) is not a full &NVME_IDENTIFY_DATA_SIZE, so @id will be + * fully populated on success. + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + * + * See: &struct nvme_ctrl_list + */ +static inline int nvme_mi_admin_identify_nsid_ctrl_list(nvme_mi_ctrl_t ctrl, + __u32 nsid, __u16 cntid, + struct nvme_ctrl_list *list) +{ + struct nvme_identify_args args = { + .result = NULL, + .data = list, + .args_size = sizeof(args), + .cns = NVME_IDENTIFY_CNS_CTRL_LIST, + .csi = NVME_CSI_NVM, + .nsid = nsid, + .cntid = cntid, + .cns_specific_id = NVME_CNSSPECID_NONE, + .uuidx = NVME_UUID_NONE, + }; + + return nvme_mi_admin_identify(ctrl, &args); +} + +/** + * nvme_mi_admin_identify_allocated_ns_list() - Perform an Admin identify for + * an allocated namespace list + * @ctrl: Controller to process identify command + * @nsid: Namespace ID to specify list start + * @list: List data to populate + * + * Perform an Identify command, for the allocated namespace list starting with + * IDs greater than or equal to @nsid. Specify &NVME_NSID_NONE for the start + * of the list. + * + * Will return an error if the length of the response data (from the + * controller) is not a full &NVME_IDENTIFY_DATA_SIZE, so @list will be + * be fully populated on success. + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + * + * See: &struct nvme_ns_list + */ +static inline int nvme_mi_admin_identify_allocated_ns_list(nvme_mi_ctrl_t ctrl, + __u32 nsid, + struct nvme_ns_list *list) +{ + struct nvme_identify_args args = { + .result = NULL, + .data = list, + .args_size = sizeof(args), + .cns = NVME_IDENTIFY_CNS_ALLOCATED_NS_LIST, + .csi = NVME_CSI_NVM, + .nsid = nsid, + .cns_specific_id = NVME_CNSSPECID_NONE, + .uuidx = NVME_UUID_NONE, + }; + + return nvme_mi_admin_identify(ctrl, &args); +} + +/** + * nvme_mi_admin_identify_active_ns_list() - Perform an Admin identify for an + * active namespace list + * @ctrl: Controller to process identify command + * @nsid: Namespace ID to specify list start + * @list: List data to populate + * + * Perform an Identify command, for the active namespace list starting with + * IDs greater than or equal to @nsid. Specify &NVME_NSID_NONE for the start + * of the list. + * + * Will return an error if the length of the response data (from the + * controller) is not a full &NVME_IDENTIFY_DATA_SIZE, so @list will be + * be fully populated on success. + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + * + * See: &struct nvme_ns_list + */ +static inline int nvme_mi_admin_identify_active_ns_list(nvme_mi_ctrl_t ctrl, + __u32 nsid, + struct nvme_ns_list *list) +{ + struct nvme_identify_args args = { + .result = NULL, + .data = list, + .args_size = sizeof(args), + .cns = NVME_IDENTIFY_CNS_NS_ACTIVE_LIST, + .csi = NVME_CSI_NVM, + .nsid = nsid, + .cns_specific_id = NVME_CNSSPECID_NONE, + .uuidx = NVME_UUID_NONE, + }; + + return nvme_mi_admin_identify(ctrl, &args); +} + +/** + * nvme_mi_admin_identify_primary_ctrl() - Perform an Admin identify for + * primary controller capabilities data structure. + * @ctrl: Controller to process identify command + * @cntid: Controller ID to specify + * @cap: Primary Controller Capabilities data structure to populate + * + * Perform an Identify command to get the Primary Controller Capabilities data + * for the controller specified by @cntid + * + * Will return an error if the length of the response data (from the + * controller) is not a full &NVME_IDENTIFY_DATA_SIZE, so @cap will be + * be fully populated on success. + * + * Return: 0 on success, non-zero on failure + * + * See: &struct nvme_primary_ctrl_cap + */ +static inline int nvme_mi_admin_identify_primary_ctrl(nvme_mi_ctrl_t ctrl, + __u16 cntid, + struct nvme_primary_ctrl_cap *cap) +{ + struct nvme_identify_args args = { + .result = NULL, + .data = cap, + .args_size = sizeof(args), + .cns = NVME_IDENTIFY_CNS_PRIMARY_CTRL_CAP, + .csi = NVME_CSI_NVM, + .nsid = NVME_NSID_NONE, + .cntid = cntid, + .cns_specific_id = NVME_CNSSPECID_NONE, + .uuidx = NVME_UUID_NONE, + }; + + return nvme_mi_admin_identify(ctrl, &args); +} + +/** + * nvme_mi_admin_identify_secondary_ctrl_list() - Perform an Admin identify for + * a secondary controller list. + * @ctrl: Controller to process identify command + * @nsid: Namespace ID to specify list start + * @cntid: Controller ID to specify list start + * @list: List data to populate + * + * Perform an Identify command, for the secondary controllers associated with + * the current primary controller. Only entries with IDs greater than or + * equal to @cntid are returned. + * + * Will return an error if the length of the response data (from the + * controller) is not a full &NVME_IDENTIFY_DATA_SIZE, so @list will be + * be fully populated on success. + * + * Return: 0 on success, non-zero on failure + * + * See: &struct nvme_secondary_ctrl_list + */ +static inline int nvme_mi_admin_identify_secondary_ctrl_list(nvme_mi_ctrl_t ctrl, + __u32 nsid, + __u16 cntid, + struct nvme_secondary_ctrl_list *list) +{ + struct nvme_identify_args args = { + .result = NULL, + .data = list, + .args_size = sizeof(args), + .cns = NVME_IDENTIFY_CNS_SECONDARY_CTRL_LIST, + .csi = NVME_CSI_NVM, + .nsid = nsid, + .cntid = cntid, + .cns_specific_id = NVME_CNSSPECID_NONE, + .uuidx = NVME_UUID_NONE, + }; + + return nvme_mi_admin_identify(ctrl, &args); +} + /** * nvme_mi_admin_get_log() - Retrieve log page data from controller * @ctrl: Controller to query @@ -1091,53 +1379,1177 @@ static inline int nvme_mi_admin_identify_ctrl_list(nvme_mi_ctrl_t ctrl, * This request may be implemented as multiple log page commands, in order * to fit within MI message-size limits. * - * Return: 0 on success, non-zero on failure + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. * * See: &struct nvme_get_log_args */ int nvme_mi_admin_get_log(nvme_mi_ctrl_t ctrl, struct nvme_get_log_args *args); /** - * nvme_mi_admin_security_send() - Perform a Security Send command on a - * controller. - * @ctrl: Controller to send command to - * @args: Security Send command arguments + * nvme_mi_admin_get_nsid_log() - Helper for Get Log Page functions + * @ctrl: Controller to query + * @rae: Retain Asynchronous Events + * @lid: Log identifier + * @nsid: Namespace ID + * @len: length of log buffer + * @log: pointer for resulting log data + * + * Performs a Get Log Page Admin command for a specific log ID @lid and + * namespace ID @nsid. Log data is expected to be @len bytes, and is stored + * in @log on success. The @rae flag is passed as-is to the Get Log Page + * command, and is specific to the Log Page requested. + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +static inline int nvme_mi_admin_get_nsid_log(nvme_mi_ctrl_t ctrl, bool rae, + enum nvme_cmd_get_log_lid lid, + __u32 nsid, __u32 len, void *log) +{ + struct nvme_get_log_args args = { + .lpo = 0, + .result = NULL, + .log = log, + .args_size = sizeof(args), + .lid = lid, + .len = len, + .nsid = nsid, + .csi = NVME_CSI_NVM, + .lsi = NVME_LOG_LSI_NONE, + .lsp = NVME_LOG_LSP_NONE, + .uuidx = NVME_UUID_NONE, + .rae = rae, + .ot = false, + }; + + return nvme_mi_admin_get_log(ctrl, &args); +} + +/** + * nvme_mi_admin_get_log_simple() - Helper for Get Log Page functions with no + * NSID or RAE requirements + * @ctrl: Controller to query + * @lid: Log identifier + * @len: length of log buffer + * @log: pointer for resulting log data * - * Performs a Security Send Admin command as specified by @args. Response data - * is stored in @args->data, which should be a buffer of @args->data_len bytes. - * Resulting data length is stored in @args->data_len on successful - * command completion. + * Performs a Get Log Page Admin command for a specific log ID @lid, using + * NVME_NSID_ALL for the namespace identifier, and rae set to false. * - * Security Send data length should not be greater than 4096 bytes to - * comply with specification limits. + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +static inline int nvme_mi_admin_get_log_simple(nvme_mi_ctrl_t ctrl, + enum nvme_cmd_get_log_lid lid, + __u32 len, void *log) +{ + return nvme_mi_admin_get_nsid_log(ctrl, false, lid, NVME_NSID_ALL, + len, log); +} + +/** + * nvme_mi_admin_get_log_supported_log_pages() - Retrieve nmve supported log + * pages + * @ctrl: Controller to query + * @rae: Retain asynchronous events + * @log: Array of LID supported and Effects data structures * - * Return: 0 on success, non-zero on failure + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +static inline int nvme_mi_admin_get_log_supported_log_pages(nvme_mi_ctrl_t ctrl, + bool rae, + struct nvme_supported_log_pages *log) +{ + return nvme_mi_admin_get_nsid_log(ctrl, rae, + NVME_LOG_LID_SUPPORTED_LOG_PAGES, + NVME_NSID_ALL, sizeof(*log), log); +} + +/** + * nvme_mi_admin_get_log_error() - Retrieve nvme error log + * @ctrl: Controller to query + * @nr_entries: Number of error log entries allocated + * @rae: Retain asynchronous events + * @err_log: Array of error logs of size 'entries' * - * See: &struct nvme_get_log_args + * This log page describes extended error information for a command that + * completed with error, or may report an error that is not specific to a + * particular command. + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_mi_admin_security_send(nvme_mi_ctrl_t ctrl, - struct nvme_security_send_args *args); +static inline int nvme_mi_admin_get_log_error(nvme_mi_ctrl_t ctrl, + unsigned int nr_entries, bool rae, + struct nvme_error_log_page *err_log) +{ + return nvme_mi_admin_get_nsid_log(ctrl, rae, NVME_LOG_LID_ERROR, + NVME_NSID_ALL, sizeof(*err_log) * nr_entries, + err_log); +} /** - * nvme_mi_admin_security_recv() - Perform a Security Receive command on a - * controller. - * @ctrl: Controller to send command to - * @args: Security Receive command arguments + * nvme_mi_admin_get_log_smart() - Retrieve nvme smart log + * @ctrl: Controller to query + * @nsid: Optional namespace identifier + * @rae: Retain asynchronous events + * @smart_log: User address to store the smart log + * + * This log page provides SMART and general health information. The information + * provided is over the life of the controller and is retained across power + * cycles. To request the controller log page, the namespace identifier + * specified is FFFFFFFFh. The controller may also support requesting the log + * page on a per namespace basis, as indicated by bit 0 of the LPA field in the + * Identify Controller data structure. + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +static inline int nvme_mi_admin_get_log_smart(nvme_mi_ctrl_t ctrl, __u32 nsid, + bool rae, + struct nvme_smart_log *smart_log) +{ + return nvme_mi_admin_get_nsid_log(ctrl, rae, NVME_LOG_LID_SMART, + nsid, sizeof(*smart_log), smart_log); +} + +/** + * nvme_mi_admin_get_log_fw_slot() - Retrieves the controller firmware log + * @ctrl: Controller to query + * @rae: Retain asynchronous events + * @fw_log: User address to store the log page * - * Performs a Security Receive Admin command as specified by @args. Response - * data is stored in @args->data, which should be a buffer of @args->data_len - * bytes. Resulting data length is stored in @args->data_len on successful - * command completion. + * This log page describes the firmware revision stored in each firmware slot + * supported. The firmware revision is indicated as an ASCII string. The log + * page also indicates the active slot number. * - * Security Receive data length should not be greater than 4096 bytes to - * comply with specification limits. + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +static inline int nvme_mi_admin_get_log_fw_slot(nvme_mi_ctrl_t ctrl, bool rae, + struct nvme_firmware_slot *fw_log) +{ + return nvme_mi_admin_get_nsid_log(ctrl, rae, NVME_LOG_LID_FW_SLOT, + NVME_NSID_ALL, sizeof(*fw_log), fw_log); +} + +/** + * nvme_mi_admin_get_log_changed_ns_list() - Retrieve namespace changed list + * @ctrl: Controller to query + * @rae: Retain asynchronous events + * @ns_log: User address to store the log page * - * Return: 0 on success, non-zero on failure + * This log page describes namespaces attached to this controller that have + * changed since the last time the namespace was identified, been added, or + * deleted. * - * See: &struct nvme_get_log_args + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_mi_admin_security_recv(nvme_mi_ctrl_t ctrl, - struct nvme_security_receive_args *args); +static inline int nvme_mi_admin_get_log_changed_ns_list(nvme_mi_ctrl_t ctrl, + bool rae, + struct nvme_ns_list *ns_log) +{ + return nvme_mi_admin_get_nsid_log(ctrl, rae, NVME_LOG_LID_CHANGED_NS, + NVME_NSID_ALL, sizeof(*ns_log), ns_log); +} + +/** + * nvme_mi_admin_get_log_cmd_effects() - Retrieve nvme command effects log + * @ctrl: Controller to query + * @csi: Command Set Identifier + * @effects_log: User address to store the effects log + * + * This log page describes the commands that the controller supports and the + * effects of those commands on the state of the NVM subsystem. + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +static inline int nvme_mi_admin_get_log_cmd_effects(nvme_mi_ctrl_t ctrl, + enum nvme_csi csi, + struct nvme_cmd_effects_log *effects_log) +{ + struct nvme_get_log_args args = { + .lpo = 0, + .result = NULL, + .log = effects_log, + .args_size = sizeof(args), + .lid = NVME_LOG_LID_CMD_EFFECTS, + .len = sizeof(*effects_log), + .nsid = NVME_NSID_ALL, + .csi = csi, + .lsi = NVME_LOG_LSI_NONE, + .lsp = NVME_LOG_LSP_NONE, + .uuidx = NVME_UUID_NONE, + .rae = false, + .ot = false, + }; + return nvme_mi_admin_get_log(ctrl, &args); +} + +/** + * nvme_mi_admin_get_log_device_self_test() - Retrieve the device self test log + * @ctrl: Controller to query + * @log: Userspace address of the log payload + * + * The log page indicates the status of an in progress self test and the + * percent complete of that operation, and the results of the previous 20 + * self-test operations. + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +static inline int nvme_mi_admin_get_log_device_self_test(nvme_mi_ctrl_t ctrl, + struct nvme_self_test_log *log) +{ + return nvme_mi_admin_get_nsid_log(ctrl, false, + NVME_LOG_LID_DEVICE_SELF_TEST, + NVME_NSID_ALL, sizeof(*log), log); +} +/** + * nvme_mi_admin_get_log_create_telemetry_host() - Create host telemetry log + * @ctrl: Controller to query + * @log: Userspace address of the log payload + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +static inline int nvme_mi_admin_get_log_create_telemetry_host(nvme_mi_ctrl_t ctrl, + struct nvme_telemetry_log *log) +{ + struct nvme_get_log_args args = { + .lpo = 0, + .result = NULL, + .log = log, + .args_size = sizeof(args), + .lid = NVME_LOG_LID_TELEMETRY_HOST, + .len = sizeof(*log), + .nsid = NVME_NSID_NONE, + .csi = NVME_CSI_NVM, + .lsi = NVME_LOG_LSI_NONE, + .lsp = NVME_LOG_TELEM_HOST_LSP_CREATE, + .uuidx = NVME_UUID_NONE, + .rae = false, + .ot = false, + }; + return nvme_mi_admin_get_log(ctrl, &args); +} + +/** + * nvme_mi_admin_get_log_telemetry_host() - Get Telemetry Host-Initiated log + * page + * @ctrl: Controller to query + * @offset: Offset into the telemetry data + * @len: Length of provided user buffer to hold the log data in bytes + * @log: User address for log page data + * + * Retrieves the Telemetry Host-Initiated log page at the requested offset + * using the previously existing capture. + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +static inline int nvme_mi_admin_get_log_telemetry_host(nvme_mi_ctrl_t ctrl, + __u64 offset, __u32 len, + void *log) +{ + struct nvme_get_log_args args = { + .lpo = offset, + .result = NULL, + .log = log, + .args_size = sizeof(args), + .lid = NVME_LOG_LID_TELEMETRY_HOST, + .len = len, + .nsid = NVME_NSID_NONE, + .csi = NVME_CSI_NVM, + .lsi = NVME_LOG_LSI_NONE, + .lsp = NVME_LOG_TELEM_HOST_LSP_RETAIN, + .uuidx = NVME_UUID_NONE, + .rae = false, + .ot = false, + }; + return nvme_mi_admin_get_log(ctrl, &args); +} + +/** + * nvme_mi_admin_get_log_telemetry_ctrl() - Get Telemetry Controller-Initiated + * log page + * @ctrl: Controller to query + * @rae: Retain asynchronous events + * @offset: Offset into the telemetry data + * @len: Length of provided user buffer to hold the log data in bytes + * @log: User address for log page data + * + * Retrieves the Telemetry Controller-Initiated log page at the requested offset + * using the previously existing capture. + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +static inline int nvme_mi_admin_get_log_telemetry_ctrl(nvme_mi_ctrl_t ctrl, + bool rae, + __u64 offset, __u32 len, + void *log) +{ + struct nvme_get_log_args args = { + .lpo = offset, + .result = NULL, + .log = log, + .args_size = sizeof(args), + .lid = NVME_LOG_LID_TELEMETRY_CTRL, + .len = len, + .nsid = NVME_NSID_NONE, + .csi = NVME_CSI_NVM, + .lsi = NVME_LOG_LSI_NONE, + .lsp = NVME_LOG_LSP_NONE, + .uuidx = NVME_UUID_NONE, + .rae = rae, + .ot = false, + }; + return nvme_mi_admin_get_log(ctrl, &args); +} + +/** + * nvme_mi_admin_get_log_endurance_group() - Get Endurance Group log + * @ctrl: Controller to query + * @endgid: Starting group identifier to return in the list + * @log: User address to store the endurance log + * + * This log page indicates if an Endurance Group Event has occurred for a + * particular Endurance Group. If an Endurance Group Event has occurred, the + * details of the particular event are included in the Endurance Group + * Information log page for that Endurance Group. An asynchronous event is + * generated when an entry for an Endurance Group is newly added to this log + * page. + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +static inline int nvme_mi_admin_get_log_endurance_group(nvme_mi_ctrl_t ctrl, + __u16 endgid, + struct nvme_endurance_group_log *log) +{ + struct nvme_get_log_args args = { + .lpo = 0, + .result = NULL, + .log = log, + .args_size = sizeof(args), + .lid = NVME_LOG_LID_ENDURANCE_GROUP, + .len = sizeof(*log), + .nsid = NVME_NSID_NONE, + .csi = NVME_CSI_NVM, + .lsi = endgid, + .lsp = NVME_LOG_LSP_NONE, + .uuidx = NVME_UUID_NONE, + .rae = false, + .ot = false, + }; + return nvme_mi_admin_get_log(ctrl, &args); +} + +/** + * nvme_mi_admin_get_log_predictable_lat_nvmset() - Predictable Latency Per NVM + * Set + * @ctrl: Controller to query + * @nvmsetid: NVM set id + * @log: User address to store the predictable latency log + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +static inline int nvme_mi_admin_get_log_predictable_lat_nvmset(nvme_mi_ctrl_t ctrl, + __u16 nvmsetid, + struct nvme_nvmset_predictable_lat_log *log) +{ + struct nvme_get_log_args args = { + .lpo = 0, + .result = NULL, + .log = log, + .args_size = sizeof(args), + .lid = NVME_LOG_LID_PREDICTABLE_LAT_NVMSET, + .len = sizeof(*log), + .nsid = NVME_NSID_NONE, + .csi = NVME_CSI_NVM, + .lsi = nvmsetid, + .lsp = NVME_LOG_LSP_NONE, + .uuidx = NVME_UUID_NONE, + .rae = false, + .ot = false, + }; + return nvme_mi_admin_get_log(ctrl, &args); +} + +/** + * nvme_mi_admin_get_log_predictable_lat_event() - Retrieve Predictable Latency + * Event Aggregate Log Page + * @ctrl: Controller to query + * @rae: Retain asynchronous events + * @offset: Offset into the predictable latency event + * @len: Length of provided user buffer to hold the log data in bytes + * @log: User address for log page data + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +static inline int nvme_mi_admin_get_log_predictable_lat_event(nvme_mi_ctrl_t ctrl, + bool rae, + __u32 offset, + __u32 len, + void *log) +{ + struct nvme_get_log_args args = { + .lpo = offset, + .result = NULL, + .log = log, + .args_size = sizeof(args), + .lid = NVME_LOG_LID_PREDICTABLE_LAT_AGG, + .len = len, + .nsid = NVME_NSID_NONE, + .csi = NVME_CSI_NVM, + .lsi = NVME_LOG_LSI_NONE, + .lsp = NVME_LOG_LSP_NONE, + .uuidx = NVME_UUID_NONE, + .rae = rae, + .ot = false, + }; + return nvme_mi_admin_get_log(ctrl, &args); +} + +/** + * nvme_mi_admin_get_log_ana() - Retrieve Asymmetric Namespace Access log page + * @ctrl: Controller to query + * @lsp: Log specific, see &enum nvme_get_log_ana_lsp + * @rae: Retain asynchronous events + * @offset: Offset to the start of the log page + * @len: The allocated length of the log page + * @log: User address to store the ana log + * + * This log consists of a header describing the log and descriptors containing + * the asymmetric namespace access information for ANA Groups that contain + * namespaces that are attached to the controller processing the command. + * + * See &struct nvme_ana_rsp_hdr for the definition of the returned structure. + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +static inline int nvme_mi_admin_get_log_ana(nvme_mi_ctrl_t ctrl, + enum nvme_log_ana_lsp lsp, bool rae, + __u64 offset, __u32 len, void *log) +{ + struct nvme_get_log_args args = { + .lpo = offset, + .result = NULL, + .log = log, + .args_size = sizeof(args), + .lid = NVME_LOG_LID_ANA, + .len = len, + .nsid = NVME_NSID_NONE, + .csi = NVME_CSI_NVM, + .lsi = NVME_LOG_LSI_NONE, + .lsp = (__u8)lsp, + .uuidx = NVME_UUID_NONE, + .rae = false, + .ot = false, + }; + return nvme_mi_admin_get_log(ctrl, &args); +} + +/** + * nvme_mi_admin_get_log_ana_groups() - Retrieve Asymmetric Namespace Access + * groups only log page + * @ctrl: Controller to query + * @rae: Retain asynchronous events + * @len: The allocated length of the log page + * @log: User address to store the ana group log + * + * See &struct nvme_ana_group_desc for the definition of the returned structure. + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +static inline int nvme_mi_admin_get_log_ana_groups(nvme_mi_ctrl_t ctrl, + bool rae, __u32 len, + struct nvme_ana_group_desc *log) +{ + return nvme_mi_admin_get_log_ana(ctrl, NVME_LOG_ANA_LSP_RGO_GROUPS_ONLY, rae, 0, + len, log); +} + +/** + * nvme_mi_admin_get_log_lba_status() - Retrieve LBA Status + * @ctrl: Controller to query + * @rae: Retain asynchronous events + * @offset: Offset to the start of the log page + * @len: The allocated length of the log page + * @log: User address to store the log page + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +static inline int nvme_mi_admin_get_log_lba_status(nvme_mi_ctrl_t ctrl, bool rae, + __u64 offset, __u32 len, + void *log) +{ + struct nvme_get_log_args args = { + .lpo = offset, + .result = NULL, + .log = log, + .args_size = sizeof(args), + .lid = NVME_LOG_LID_LBA_STATUS, + .len = len, + .nsid = NVME_NSID_NONE, + .csi = NVME_CSI_NVM, + .lsi = NVME_LOG_LSI_NONE, + .lsp = NVME_LOG_LSP_NONE, + .uuidx = NVME_UUID_NONE, + .rae = rae, + .ot = false, + }; + return nvme_mi_admin_get_log(ctrl, &args); +} + +/** + * nvme_mi_admin_get_log_endurance_grp_evt() - Retrieve Rotational Media + * Information + * @ctrl: Controller to query + * @rae: Retain asynchronous events + * @offset: Offset to the start of the log page + * @len: The allocated length of the log page + * @log: User address to store the log page + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +static inline int nvme_mi_admin_get_log_endurance_grp_evt(nvme_mi_ctrl_t ctrl, + bool rae, + __u32 offset, + __u32 len, + void *log) +{ + struct nvme_get_log_args args = { + .lpo = offset, + .result = NULL, + .log = log, + .args_size = sizeof(args), + .lid = NVME_LOG_LID_ENDURANCE_GRP_EVT, + .len = len, + .nsid = NVME_NSID_NONE, + .csi = NVME_CSI_NVM, + .lsi = NVME_LOG_LSI_NONE, + .lsp = NVME_LOG_LSP_NONE, + .uuidx = NVME_UUID_NONE, + .rae = rae, + .ot = false, + }; + return nvme_mi_admin_get_log(ctrl, &args); +} + +/** + * nvme_mi_admin_get_log_fid_supported_effects() - Retrieve Feature Identifiers + * Supported and Effects + * @ctrl: Controller to query + * @rae: Retain asynchronous events + * @log: FID Supported and Effects data structure + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +static inline int nvme_mi_admin_get_log_fid_supported_effects(nvme_mi_ctrl_t ctrl, + bool rae, + struct nvme_fid_supported_effects_log *log) +{ + return nvme_mi_admin_get_nsid_log(ctrl, rae, + NVME_LOG_LID_FID_SUPPORTED_EFFECTS, + NVME_NSID_NONE, sizeof(*log), log); +} + +/** + * nvme_mi_admin_get_log_mi_cmd_supported_effects() - displays the MI Commands + * Supported by the controller + * @ctrl: Controller to query + * @rae: Retain asynchronous events + * @log: MI Command Supported and Effects data structure + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +static inline int nvme_mi_admin_get_log_mi_cmd_supported_effects(nvme_mi_ctrl_t ctrl, + bool rae, + struct nvme_mi_cmd_supported_effects_log *log) +{ + return nvme_mi_admin_get_nsid_log(ctrl, rae, NVME_LOG_LID_MI_CMD_SUPPORTED_EFFECTS, + NVME_NSID_NONE, sizeof(*log), log); +} + +/** + * nvme_mi_admin_get_log_boot_partition() - Retrieve Boot Partition + * @ctrl: Controller to query + * @rae: Retain asynchronous events + * @lsp: The log specified field of LID + * @len: The allocated size, minimum + * struct nvme_boot_partition + * @part: User address to store the log page + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +static inline int nvme_mi_admin_get_log_boot_partition(nvme_mi_ctrl_t ctrl, + bool rae, __u8 lsp, + __u32 len, + struct nvme_boot_partition *part) +{ + struct nvme_get_log_args args = { + .lpo = 0, + .result = NULL, + .log = part, + .args_size = sizeof(args), + .lid = NVME_LOG_LID_BOOT_PARTITION, + .len = len, + .nsid = NVME_NSID_NONE, + .csi = NVME_CSI_NVM, + .lsi = NVME_LOG_LSI_NONE, + .lsp = NVME_LOG_LSP_NONE, + .uuidx = NVME_UUID_NONE, + .rae = rae, + .ot = false, + }; + return nvme_mi_admin_get_log(ctrl, &args); +} + +/** + * nvme_mi_admin_get_log_discovery() - Retrieve Discovery log page + * @ctrl: Controller to query + * @rae: Retain asynchronous events + * @offset: Offset of this log to retrieve + * @len: The allocated size for this portion of the log + * @log: User address to store the discovery log + * + * Supported only by fabrics discovery controllers, returning discovery + * records. + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +static inline int nvme_mi_admin_get_log_discovery(nvme_mi_ctrl_t ctrl, bool rae, + __u32 offset, __u32 len, + void *log) +{ + struct nvme_get_log_args args = { + .lpo = offset, + .result = NULL, + .log = log, + .args_size = sizeof(args), + .lid = NVME_LOG_LID_DISCOVER, + .len = len, + .nsid = NVME_NSID_NONE, + .csi = NVME_CSI_NVM, + .lsi = NVME_LOG_LSI_NONE, + .lsp = NVME_LOG_LSP_NONE, + .uuidx = NVME_UUID_NONE, + .rae = rae, + .ot = false, + }; + return nvme_mi_admin_get_log(ctrl, &args); +} + +/** + * nvme_mi_admin_get_log_media_unit_stat() - Retrieve Media Unit Status + * @ctrl: Controller to query + * @domid: Domain Identifier selection, if supported + * @mus: User address to store the Media Unit statistics log + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +static inline int nvme_mi_admin_get_log_media_unit_stat(nvme_mi_ctrl_t ctrl, + __u16 domid, + struct nvme_media_unit_stat_log *mus) +{ + struct nvme_get_log_args args = { + .lpo = 0, + .result = NULL, + .log = mus, + .args_size = sizeof(args), + .lid = NVME_LOG_LID_MEDIA_UNIT_STATUS, + .len = sizeof(*mus), + .nsid = NVME_NSID_NONE, + .csi = NVME_CSI_NVM, + .lsi = domid, + .lsp = NVME_LOG_LSP_NONE, + .uuidx = NVME_UUID_NONE, + .rae = false, + .ot = false, + }; + return nvme_mi_admin_get_log(ctrl, &args); +} + +/** + * nvme_mi_admin_get_log_support_cap_config_list() - Retrieve Supported + * Capacity Configuration List + * @ctrl: Controller to query + * @domid: Domain Identifier selection, if supported + * @cap: User address to store supported capabilities config list + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +static inline int nvme_mi_admin_get_log_support_cap_config_list(nvme_mi_ctrl_t ctrl, + __u16 domid, + struct nvme_supported_cap_config_list_log *cap) +{ + struct nvme_get_log_args args = { + .lpo = 0, + .result = NULL, + .log = cap, + .args_size = sizeof(args), + .lid = NVME_LOG_LID_SUPPORTED_CAP_CONFIG_LIST, + .len = sizeof(*cap), + .nsid = NVME_NSID_NONE, + .csi = NVME_CSI_NVM, + .lsi = domid, + .lsp = NVME_LOG_LSP_NONE, + .uuidx = NVME_UUID_NONE, + .rae = false, + .ot = false, + }; + return nvme_mi_admin_get_log(ctrl, &args); +} + +/** + * nvme_mi_admin_get_log_reservation() - Retrieve Reservation Notification + * @ctrl: Controller to query + * @rae: Retain asynchronous events + * @log: User address to store the reservation log + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +static inline int nvme_mi_admin_get_log_reservation(nvme_mi_ctrl_t ctrl, + bool rae, + struct nvme_resv_notification_log *log) +{ + return nvme_mi_admin_get_nsid_log(ctrl, rae, NVME_LOG_LID_RESERVATION, + NVME_NSID_ALL, sizeof(*log), log); +} + +/** + * nvme_mi_admin_get_log_sanitize() - Retrieve Sanitize Status + * @ctrl: Controller to query + * @rae: Retain asynchronous events + * @log: User address to store the sanitize log + * + * The Sanitize Status log page reports sanitize operation time estimates and + * information about the most recent sanitize operation. + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +static inline int nvme_mi_admin_get_log_sanitize(nvme_mi_ctrl_t ctrl, bool rae, + struct nvme_sanitize_log_page *log) +{ + return nvme_mi_admin_get_nsid_log(ctrl, rae, NVME_LOG_LID_SANITIZE, + NVME_NSID_ALL, sizeof(*log), log); +} + +/** + * nvme_mi_admin_get_log_zns_changed_zones() - Retrieve list of zones that have + * changed + * @ctrl: Controller to query + * @nsid: Namespace ID + * @rae: Retain asynchronous events + * @log: User address to store the changed zone log + * + * The list of zones that have changed state due to an exceptional event. + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +static inline int nvme_mi_admin_get_log_zns_changed_zones(nvme_mi_ctrl_t ctrl, + __u32 nsid, bool rae, + struct nvme_zns_changed_zone_log *log) +{ + struct nvme_get_log_args args = { + .lpo = 0, + .result = NULL, + .log = log, + .args_size = sizeof(args), + .lid = NVME_LOG_LID_ZNS_CHANGED_ZONES, + .len = sizeof(*log), + .nsid = nsid, + .csi = NVME_CSI_ZNS, + .lsi = NVME_LOG_LSI_NONE, + .lsp = NVME_LOG_LSP_NONE, + .uuidx = NVME_UUID_NONE, + .rae = rae, + .ot = false, + }; + return nvme_mi_admin_get_log(ctrl, &args); +} + +/** + * nvme_mi_admin_get_log_persistent_event() - Retrieve Persistent Event Log + * @ctrl: Controller to query + * @action: Action the controller should take during processing this command + * @size: Size of @pevent_log + * @pevent_log: User address to store the persistent event log + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +static inline int nvme_mi_admin_get_log_persistent_event(nvme_mi_ctrl_t ctrl, + enum nvme_pevent_log_action action, + __u32 size, void *pevent_log) +{ + struct nvme_get_log_args args = { + .lpo = 0, + .result = NULL, + .log = pevent_log, + .args_size = sizeof(args), + .lid = NVME_LOG_LID_PERSISTENT_EVENT, + .len = size, + .nsid = NVME_NSID_ALL, + .csi = NVME_CSI_NVM, + .lsi = NVME_LOG_LSI_NONE, + .lsp = (__u8)action, + .uuidx = NVME_UUID_NONE, + .rae = false, + .ot = false, + }; + return nvme_mi_admin_get_log(ctrl, &args); +} + +/** + * nvme_mi_admin_security_send() - Perform a Security Send command on a + * controller. + * @ctrl: Controller to send command to + * @args: Security Send command arguments + * + * Performs a Security Send Admin command as specified by @args. Response data + * is stored in @args->data, which should be a buffer of @args->data_len bytes. + * Resulting data length is stored in @args->data_len on successful + * command completion. + * + * Security Send data length should not be greater than 4096 bytes to + * comply with specification limits. + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + * + * See: &struct nvme_get_log_args + */ +int nvme_mi_admin_security_send(nvme_mi_ctrl_t ctrl, + struct nvme_security_send_args *args); + +/** + * nvme_mi_admin_security_recv() - Perform a Security Receive command on a + * controller. + * @ctrl: Controller to send command to + * @args: Security Receive command arguments + * + * Performs a Security Receive Admin command as specified by @args. Response + * data is stored in @args->data, which should be a buffer of @args->data_len + * bytes. Resulting data length is stored in @args->data_len on successful + * command completion. + * + * Security Receive data length should not be greater than 4096 bytes to + * comply with specification limits. + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + * + * See: &struct nvme_get_log_args + */ +int nvme_mi_admin_security_recv(nvme_mi_ctrl_t ctrl, + struct nvme_security_receive_args *args); + +/** + * nvme_mi_admin_get_features - Perform a Get Feature command on a controller + * @ctrl: Controller to send command to + * @args: Get Features command arguments + * + * Performs a Get Features Admin command as specified by @args. Returned + * feature data will be stored in @args->result and @args->data, depending + * on the specification of the feature itself; most features do not return + * additional data. See section 5.27.1 of the NVMe spec (v2.0b) for + * feature-specific information. + * + * On success, @args->data_len will be updated with the actual data length + * received. + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +int nvme_mi_admin_get_features(nvme_mi_ctrl_t ctrl, + struct nvme_get_features_args *args); + +/** + * nvme_mi_admin_get_features_data() - Helper function for &nvme_mi_admin_get_features() + * @ctrl: Controller to send command to + * @fid: Feature identifier + * @nsid: Namespace ID, if applicable for @fid + * @data_len: Length of feature data, if applicable for @fid, in bytes + * @data: User address of feature data, if applicable + * @result: The command completion result from CQE dword0 + * + * Helper for optionally features that optionally return data, using the + * SEL_CURRENT selector value. + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +static inline int nvme_mi_admin_get_features_data(nvme_mi_ctrl_t ctrl, + enum nvme_features_id fid, + __u32 nsid, __u32 data_len, + void *data, __u32 *result) +{ + struct nvme_get_features_args args = { + .result = result, + .data = data, + .args_size = sizeof(args), + .nsid = nsid, + .sel = NVME_GET_FEATURES_SEL_CURRENT, + .cdw11 = 0, + .data_len = data_len, + .fid = (__u8)fid, + .uuidx = NVME_UUID_NONE, + }; + + return nvme_mi_admin_get_features(ctrl, &args); +} + +/** + * nvme_mi_admin_get_features_simple - Get a simple feature value with no data + * @ctrl: Controller to send command to + * @fid: Feature identifier + * @nsid: Namespace id, if required by @fid + * @result: output feature data + */ +static inline int nvme_mi_admin_get_features_simple(nvme_mi_ctrl_t ctrl, + enum nvme_features_id fid, + __u32 nsid, + __u32 *result) +{ + return nvme_mi_admin_get_features_data(ctrl, fid, nsid, + 0, NULL, result); +} + +/** + * nvme_mi_admin_set_features - Perform a Set Features command on a controller + * @ctrl: Controller to send command to + * @args: Set Features command arguments + * + * Performs a Set Features Admin command as specified by @args. Result + * data will be stored in @args->result. + * on the specification of the feature itself; most features do not return + * additional data. See section 5.27.1 of the NVMe spec (v2.0b) for + * feature-specific information. + * + * On success, @args->data_len will be updated with the actual data length + * received. + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +int nvme_mi_admin_set_features(nvme_mi_ctrl_t ctrl, + struct nvme_set_features_args *args); + +/** + * nvme_mi_admin_ns_mgmt - Issue a Namespace Management command + * @ctrl: Controller to send command to + * @args: Namespace management command arguments + * + * Issues a Namespace Management command to @ctrl, with arguments specified + * from @args. + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +int nvme_mi_admin_ns_mgmt(nvme_mi_ctrl_t ctrl, + struct nvme_ns_mgmt_args *args); + +/** + * nvme_mi_admin_ns_mgmt_create - Helper for Namespace Management Create command + * @ctrl: Controller to send command to + * @ns: New namespace parameters + * @csi: Command Set Identifier for new NS + * @nsid: Set to new namespace ID on create + * + * Issues a Namespace Management (Create) command to @ctrl, to create a + * new namespace specified by @ns, using command set @csi. On success, + * the new namespace ID will be written to @nsid. + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +static inline int nvme_mi_admin_ns_mgmt_create(nvme_mi_ctrl_t ctrl, + struct nvme_id_ns *ns, + __u8 csi, __u32 *nsid) +{ + struct nvme_ns_mgmt_args args = { + .result = nsid, + .ns = ns, + .args_size = sizeof(args), + .nsid = NVME_NSID_NONE, + .sel = NVME_NS_MGMT_SEL_CREATE, + .csi = csi, + }; + + return nvme_mi_admin_ns_mgmt(ctrl, &args); +} + +/** + * nvme_mi_admin_ns_mgmt_delete - Helper for Namespace Management Delete command + * @ctrl: Controller to send command to + * @nsid: Namespace ID to delete + * + * Issues a Namespace Management (Delete) command to @ctrl, to delete the + * namespace with id @nsid. + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +static inline int nvme_mi_admin_ns_mgmt_delete(nvme_mi_ctrl_t ctrl, __u32 nsid) +{ + struct nvme_ns_mgmt_args args = { + .args_size = sizeof(args), + .nsid = nsid, + .sel = NVME_NS_MGMT_SEL_DELETE, + }; + + return nvme_mi_admin_ns_mgmt(ctrl, &args); +} + +/** + * nvme_mi_admin_ns_attach() - Attach or detach namespace to controller(s) + * @ctrl: Controller to send command to + * @args: Namespace Attach command arguments + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +int nvme_mi_admin_ns_attach(nvme_mi_ctrl_t ctrl, + struct nvme_ns_attach_args *args); + +/** + * nvme_mi_admin_ns_attach_ctrls() - Attach namespace to controllers + * @ctrl: Controller to send command to + * @nsid: Namespace ID to attach + * @ctrlist: Controller list to modify attachment state of nsid + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +static inline int nvme_mi_admin_ns_attach_ctrls(nvme_mi_ctrl_t ctrl, __u32 nsid, + struct nvme_ctrl_list *ctrlist) +{ + struct nvme_ns_attach_args args = { + .result = NULL, + .ctrlist = ctrlist, + .args_size = sizeof(args), + .nsid = nsid, + .sel = NVME_NS_ATTACH_SEL_CTRL_ATTACH, + }; + + return nvme_mi_admin_ns_attach(ctrl, &args); +} + +/** + * nvme_mi_admin_ns_detach_ctrls() - Detach namespace from controllers + * @ctrl: Controller to send command to + * @nsid: Namespace ID to detach + * @ctrlist: Controller list to modify attachment state of nsid + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +static inline int nvme_mi_admin_ns_detach_ctrls(nvme_mi_ctrl_t ctrl, __u32 nsid, + struct nvme_ctrl_list *ctrlist) +{ + struct nvme_ns_attach_args args = { + .result = NULL, + .ctrlist = ctrlist, + .args_size = sizeof(args), + .nsid = nsid, + .sel = NVME_NS_ATTACH_SEL_CTRL_DEATTACH, + }; + + return nvme_mi_admin_ns_attach(ctrl, &args); +} + +/** + * nvme_mi_admin_fw_download() - Download part or all of a firmware image to + * the controller + * @ctrl: Controller to send firmware data to + * @args: &struct nvme_fw_download_args argument structure + * + * The Firmware Image Download command downloads all or a portion of an image + * for a future update to the controller. The Firmware Image Download command + * downloads a new image (in whole or in part) to the controller. + * + * The image may be constructed of multiple pieces that are individually + * downloaded with separate Firmware Image Download commands. Each Firmware + * Image Download command includes a Dword Offset and Number of Dwords that + * specify a dword range. + * + * The new firmware image is not activated as part of the Firmware Image + * Download command. Use the nvme_mi_admin_fw_commit() to activate a newly + * downloaded image. + * + * Return: 0 on success, non-zero on failure + */ +int nvme_mi_admin_fw_download(nvme_mi_ctrl_t ctrl, + struct nvme_fw_download_args *args); + +/** + * nvme_mi_admin_fw_commit() - Commit firmware using the specified action + * @ctrl: Controller to send firmware data to + * @args: &struct nvme_fw_download_args argument structure + * + * The Firmware Commit command modifies the firmware image or Boot Partitions. + * + * Return: 0 on success, non-zero on failure + */ +int nvme_mi_admin_fw_commit(nvme_mi_ctrl_t ctrl, + struct nvme_fw_commit_args *args); + +/** + * nvme_mi_admin_format_nvm() - Format NVMe namespace + * @ctrl: Controller to send command to + * @args: Format NVM command arguments + * + * Perform a low-level format to set the LBA data & metadata size. May destroy + * data & metadata on the specified namespaces + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +int nvme_mi_admin_format_nvm(nvme_mi_ctrl_t ctrl, + struct nvme_format_nvm_args *args); + +/** + * nvme_mi_admin_sanitize_nvm() - Start a subsystem Sanitize operation + * @ctrl: Controller to send command to + * @args: Sanitize command arguments + * + * A sanitize operation alters all user data in the NVM subsystem such that + * recovery of any previous user data from any cache, the non-volatile media, + * or any Controller Memory Buffer is not possible. + * + * The Sanitize command starts a sanitize operation or to recover from a + * previously failed sanitize operation. The sanitize operation types that may + * be supported are Block Erase, Crypto Erase, and Overwrite. All sanitize + * operations are processed in the background, i.e., completion of the sanitize + * command does not indicate completion of the sanitize operation. + * + * Return: The nvme command status if a response was received (see + * &enum nvme_status_field) or -1 with errno set otherwise. + */ +int nvme_mi_admin_sanitize_nvm(nvme_mi_ctrl_t ctrl, + struct nvme_sanitize_nvm_args *args); #endif /* _LIBNVME_MI_MI_H */ diff --git a/src/nvme/private.h b/src/nvme/private.h index b5610f5..cdd1bbf 100644 --- a/src/nvme/private.h +++ b/src/nvme/private.h @@ -16,8 +16,6 @@ #include "fabrics.h" #include "mi.h" -#include - extern const char *nvme_ctrl_sysfs_dir; extern const char *nvme_subsys_sysfs_dir; @@ -57,7 +55,7 @@ struct nvme_ns { uint8_t eui64[8]; uint8_t nguid[16]; - uuid_t uuid; + unsigned char uuid[NVME_UUID_LEN]; enum nvme_csi csi; }; @@ -83,6 +81,7 @@ struct nvme_ctrl { char *traddr; char *trsvcid; char *dhchap_key; + char *dhchap_ctrl_key; char *cntrltype; char *dctype; bool discovery_ctrl; diff --git a/src/nvme/tree.c b/src/nvme/tree.c index e3b41e7..b992824 100644 --- a/src/nvme/tree.c +++ b/src/nvme/tree.c @@ -810,12 +810,12 @@ struct nvme_fabrics_config *nvme_ctrl_get_config(nvme_ctrl_t c) return &c->cfg; } -const char *nvme_ctrl_get_dhchap_key(nvme_ctrl_t c) +const char *nvme_ctrl_get_dhchap_host_key(nvme_ctrl_t c) { return c->dhchap_key; } -void nvme_ctrl_set_dhchap_key(nvme_ctrl_t c, const char *key) +void nvme_ctrl_set_dhchap_host_key(nvme_ctrl_t c, const char *key) { if (c->dhchap_key) { free(c->dhchap_key); @@ -825,6 +825,21 @@ void nvme_ctrl_set_dhchap_key(nvme_ctrl_t c, const char *key) c->dhchap_key = strdup(key); } +const char *nvme_ctrl_get_dhchap_key(nvme_ctrl_t c) +{ + return c->dhchap_ctrl_key; +} + +void nvme_ctrl_set_dhchap_key(nvme_ctrl_t c, const char *key) +{ + if (c->dhchap_ctrl_key) { + free(c->dhchap_ctrl_key); + c->dhchap_ctrl_key = NULL; + } + if (key) + c->dhchap_ctrl_key = strdup(key); +} + void nvme_ctrl_set_discovered(nvme_ctrl_t c, bool discovered) { c->discovered = discovered; @@ -898,6 +913,7 @@ void nvme_deconfigure_ctrl(nvme_ctrl_t c) FREE_CTRL_ATTR(c->serial); FREE_CTRL_ATTR(c->sqsize); FREE_CTRL_ATTR(c->dhchap_key); + FREE_CTRL_ATTR(c->dhchap_ctrl_key); FREE_CTRL_ATTR(c->address); FREE_CTRL_ATTR(c->dctype); FREE_CTRL_ATTR(c->cntrltype); @@ -1146,6 +1162,7 @@ static int nvme_configure_ctrl(nvme_root_t r, nvme_ctrl_t c, const char *path, const char *name) { DIR *d; + char *host_key; d = opendir(path); if (!d) { @@ -1166,10 +1183,19 @@ static int nvme_configure_ctrl(nvme_root_t r, nvme_ctrl_t c, const char *path, c->queue_count = nvme_get_ctrl_attr(c, "queue_count"); c->serial = nvme_get_ctrl_attr(c, "serial"); c->sqsize = nvme_get_ctrl_attr(c, "sqsize"); - c->dhchap_key = nvme_get_ctrl_attr(c, "dhchap_ctrl_secret"); - if (c->dhchap_key && !strcmp(c->dhchap_key, "none")) { - free(c->dhchap_key); - c->dhchap_key = NULL; + host_key = nvme_get_ctrl_attr(c, "dhchap_secret"); + if (host_key && c->s && c->s->h && c->s->h->dhchap_key && + (!strcmp(c->s->h->dhchap_key, host_key) || + !strcmp("none", host_key))) { + free(host_key); + host_key = NULL; + } + if (host_key) + c->dhchap_key = host_key; + c->dhchap_ctrl_key = nvme_get_ctrl_attr(c, "dhchap_ctrl_secret"); + if (c->dhchap_ctrl_key && !strcmp(c->dhchap_ctrl_key, "none")) { + free(c->dhchap_ctrl_key); + c->dhchap_ctrl_key = NULL; } c->cntrltype = nvme_get_ctrl_attr(c, "cntrltype"); c->dctype = nvme_get_ctrl_attr(c, "dctype"); @@ -1525,9 +1551,9 @@ const uint8_t *nvme_ns_get_nguid(nvme_ns_t n) return n->nguid; } -void nvme_ns_get_uuid(nvme_ns_t n, uuid_t out) +void nvme_ns_get_uuid(nvme_ns_t n, unsigned char out[NVME_UUID_LEN]) { - uuid_copy(out, n->uuid); + memcpy(out, n->uuid, NVME_UUID_LEN); } int nvme_ns_identify(nvme_ns_t n, struct nvme_id_ns *ns) diff --git a/src/nvme/tree.h b/src/nvme/tree.h index 3a103c0..156cb79 100644 --- a/src/nvme/tree.h +++ b/src/nvme/tree.h @@ -15,7 +15,6 @@ #include #include -#include #include "ioctl.h" #include "util.h" @@ -521,7 +520,7 @@ const uint8_t *nvme_ns_get_nguid(nvme_ns_t n); * * Copies the namespace's uuid into @out */ -void nvme_ns_get_uuid(nvme_ns_t n, uuid_t out); +void nvme_ns_get_uuid(nvme_ns_t n, unsigned char out[NVME_UUID_LEN]); /** * nvme_ns_get_sysfs_dir() - sysfs directory of a namespace @@ -875,6 +874,21 @@ const char *nvme_ctrl_get_host_traddr(nvme_ctrl_t c); */ const char *nvme_ctrl_get_host_iface(nvme_ctrl_t c); +/** + * nvme_ctrl_get_dhchap_host_key() - Return host key + * @c: Controller to be checked + * + * Return: DH-HMAC-CHAP host key or NULL if not set + */ +const char *nvme_ctrl_get_dhchap_host_key(nvme_ctrl_t c); + +/** + * nvme_ctrl_set_dhchap_host_key() - Set host key + * @c: Host for which the key should be set + * @key: DH-HMAC-CHAP Key to set or NULL to clear existing key + */ +void nvme_ctrl_set_dhchap_host_key(nvme_ctrl_t c, const char *key); + /** * nvme_ctrl_get_dhchap_key() - Return controller key * @c: Controller for which the key should be set diff --git a/src/nvme/types.h b/src/nvme/types.h index 3d67bc8..94066fc 100644 --- a/src/nvme/types.h +++ b/src/nvme/types.h @@ -4856,6 +4856,34 @@ enum nvmf_tcp_sectype { NVMF_TCP_SECTYPE_TLS13 = 2, }; +/** + * enum nvmf_log_discovery_lid_support - Discovery log specific support + * @NVMF_LOG_DISC_LID_NONE: None + * @NVMF_LOG_DISC_LID_EXTDLPES: Extended Discovery Log Page Entries Supported + * @NVMF_LOG_DISC_LID_PLEOS: Port Local Entries Only Supported + * @NVMF_LOG_DISC_LID_ALLSUBES: All NVM Subsystem Entries Supported + */ +enum nvmf_log_discovery_lid_support { + NVMF_LOG_DISC_LID_NONE = 0, + NVMF_LOG_DISC_LID_EXTDLPES = (1 << 0), + NVMF_LOG_DISC_LID_PLEOS = (1 << 1), + NVMF_LOG_DISC_LID_ALLSUBES = (1 << 2), +}; + +/** + * enum nvmf_log_discovery_lsp - Discovery log specific field + * @NVMF_LOG_DISC_LSP_NONE: None + * @NVMF_LOG_DISC_LSP_EXTDLPE: Extended Discovery Log Page Entries + * @NVMF_LOG_DISC_LSP_PLEO: Port Local Entries Only + * @NVMF_LOG_DISC_LSP_ALLSUBE: All NVM Subsystem Entries + */ +enum nvmf_log_discovery_lsp { + NVMF_LOG_DISC_LSP_NONE = 0, + NVMF_LOG_DISC_LSP_EXTDLPE = (1 << 0), + NVMF_LOG_DISC_LSP_PLEO = (1 << 1), + NVMF_LOG_DISC_LSP_ALLSUBE = (1 << 2), +}; + /** * struct nvmf_discovery_log - Discovery Log Page (Log Identifier 70h) * @genctr: Generation Counter (GENCTR): Indicates the version of the discovery @@ -6113,6 +6141,75 @@ static inline __u16 nvme_status_code(__u16 status_field) return NVME_GET(status_field, SC); } +/** + * enum nvme_status_type - type encoding for NVMe return values, when + * represented as an int. + * + * The nvme_* api returns an int, with negative values indicating an internal + * or syscall error, zero signifying success, positive values representing + * the NVMe status. + * + * That latter case (the NVMe status) may represent status values from + * different parts of the transport/controller/etc, and are at most 16 bits of + * data. So, we use the most-significant 3 bits of the signed int to indicate + * which type of status this is. + * + * @NVME_STATUS_TYPE_SHIFT: shift value for status bits + * @NVME_STATUS_TYPE_MASK: mask value for status bits + * + * @NVME_STATUS_TYPE_NVME: NVMe command status value, typically from CDW3 + * @NVME_STATUS_TYPE_MI: NVMe-MI header status + */ +enum nvme_status_type { + NVME_STATUS_TYPE_SHIFT = 27, + NVME_STATUS_TYPE_MASK = 0x7, + + NVME_STATUS_TYPE_NVME = 0, + NVME_STATUS_TYPE_MI = 1, +}; + +/** + * nvme_status_get_type() - extract the type from a nvme_* return value + * @status: the (non-negative) return value from the NVMe API + * + * Returns: the type component of the status. + */ +static inline __u32 nvme_status_get_type(int status) +{ + return NVME_GET(status, STATUS_TYPE); +} + +/** + * nvme_status_get_value() - extract the status value from a nvme_* return + * value + * @status: the (non-negative) return value from the NVMe API + * + * Returns: the value component of the status; the set of values will depend + * on the status type. + */ +static inline __u32 nvme_status_get_value(int status) +{ + return status & ~(NVME_STATUS_TYPE_MASK << NVME_STATUS_TYPE_SHIFT); +} + +/** + * nvme_status_equals() - helper to check a status against a type and value + * @status: the (non-negative) return value from the NVMe API + * @type: the status type + * @value: the status value + * + * Returns: true if @status is of the specified type and value + */ +static inline __u32 nvme_status_equals(int status, enum nvme_status_type type, + unsigned int value) +{ + if (status < 0) + return false; + + return nvme_status_get_type(status) == type && + nvme_status_get_value(status) == value; +} + /** * enum nvme_admin_opcode - Known NVMe admin opcodes * @nvme_admin_delete_sq: Delete I/O Submission Queue @@ -6949,6 +7046,20 @@ enum nvme_fctype { nvme_fabrics_type_disconnect = 0x08, }; +/** + * enum nvme_data_tfr - Data transfer direction of the command + * @NVME_DATA_TFR_NO_DATA_TFR: No data transfer + * @NVME_DATA_TFR_HOST_TO_CTRL: Host to controller + * @NVME_DATA_TFR_CTRL_TO_HOST: Controller to host + * @NVME_DATA_TFR_BIDIRECTIONAL: Bidirectional + */ +enum nvme_data_tfr { + NVME_DATA_TFR_NO_DATA_TFR = 0x0, + NVME_DATA_TFR_HOST_TO_CTRL = 0x1, + NVME_DATA_TFR_CTRL_TO_HOST = 0x2, + NVME_DATA_TFR_BIDIRECTIONAL = 0x3, +}; + /** * enum nvme_io_opcode - Opcodes for I/O Commands * @nvme_cmd_flush: Flush diff --git a/src/nvme/util.c b/src/nvme/util.c index ff5e0d8..c61dbe9 100644 --- a/src/nvme/util.c +++ b/src/nvme/util.c @@ -11,6 +11,8 @@ #include #include +#include +#include #include #include #include @@ -23,6 +25,11 @@ #include "util.h" #include "log.h" +/* The bionic libc implementation doesn't define LINE_MAX */ +#ifndef LINE_MAX +#define LINE_MAX 2048 +#endif + /* Source Code Control System, query version of binary with 'what' */ const char sccsid[] = "@(#)libnvme " GIT_VERSION; @@ -489,6 +496,22 @@ int nvme_get_feature_length(int fid, __u32 cdw11, __u32 *len) return 0; } +int nvme_get_feature_length2(int fid, __u32 cdw11, enum nvme_data_tfr dir, + __u32 *len) +{ + switch (fid) { + case NVME_FEAT_FID_HOST_MEM_BUF: + if (dir == NVME_DATA_TFR_HOST_TO_CTRL) { + *len = 0; + break; + } + fallthrough; + default: + return nvme_get_feature_length(fid, cdw11, len); + } + return 0; +} + int nvme_get_directive_receive_length(enum nvme_directive_dtype dtype, enum nvme_directive_receive_doper doper, __u32 *len) { @@ -812,3 +835,57 @@ const char *nvme_get_version(enum nvme_version type) return "n/a"; } } + +int nvme_uuid_to_string(unsigned char uuid[NVME_UUID_LEN], char *str) +{ + int n; + n = snprintf(str, NVME_UUID_LEN_STRING, + "%02x%02x%02x%02x-%02x%02x-%02x%02x-" + "%02x%02x-%02x%02x%02x%02x%02x%02x", + uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5], + uuid[6], uuid[7], uuid[8], uuid[9], uuid[10], uuid[11], + uuid[12], uuid[13], uuid[14], uuid[15]); + return n != NVME_UUID_LEN_STRING - 1 ? -EINVAL : 0; +} + +int nvme_uuid_from_string(const char *str, unsigned char uuid[NVME_UUID_LEN]) +{ + int n; + + n = sscanf(str, + "%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-" + "%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx", + &uuid[0], &uuid[1], &uuid[2], &uuid[3], &uuid[4], &uuid[5], + &uuid[6], &uuid[7], &uuid[8], &uuid[9], &uuid[10], &uuid[11], + &uuid[12], &uuid[13], &uuid[14], &uuid[15]); + return n != NVME_UUID_LEN ? -EINVAL : 0; + +} + +int nvme_uuid_random(unsigned char uuid[NVME_UUID_LEN]) +{ + int f; + ssize_t n; + + f = open("/dev/urandom", O_RDONLY); + if (f < 0) + return -errno; + n = read(f, uuid, NVME_UUID_LEN); + if (n < 0) { + close(f); + return -errno; + } else if (n != NVME_UUID_LEN) { + close(f); + return -EIO; + } + + /* + * See https://www.rfc-editor.org/rfc/rfc4122#section-4.4 + * Algorithms for Creating a UUID from Truly Random + * or Pseudo-Random Numbers + */ + uuid[6] = (uuid[6] & 0x0f) | 0x40; + uuid[8] = (uuid[8] & 0x3f) | 0x80; + + return 0; +} diff --git a/src/nvme/util.h b/src/nvme/util.h index 6f1d3e9..e72c156 100644 --- a/src/nvme/util.h +++ b/src/nvme/util.h @@ -155,6 +155,23 @@ void nvme_init_copy_range_f1(struct nvme_copy_range_f1 *copy, __u16 *nlbs, */ int nvme_get_feature_length(int fid, __u32 cdw11, __u32 *len); +/** + * nvme_get_feature_length2() - Retreive the command payload length for a + * specific feature identifier + * @fid: Feature identifier, see &enum nvme_features_id. + * @cdw11: The cdw11 value may affect the transfer (only known fid is + * %NVME_FEAT_FID_HOST_ID) + * @dir: Data transfer direction: false - host to controller, true - + * controller to host may affect the transfer (only known fid is + * %NVME_FEAT_FID_HOST_MEM_BUF). + * @len: On success, set to this features payload length in bytes. + * + * Return: 0 on success, -1 with errno set to EINVAL if the function did not + * recognize &fid. + */ +int nvme_get_feature_length2(int fid, __u32 cdw11, enum nvme_data_tfr dir, + __u32 *len); + /** * nvme_get_directive_receive_length() - Get directive receive length * @dtype: Directive type, see &enum nvme_directive_dtype @@ -575,4 +592,36 @@ enum nvme_version { */ const char *nvme_get_version(enum nvme_version type); +#define NVME_UUID_LEN_STRING 37 /* 1b4e28ba-2fa1-11d2-883f-0016d3cca427 + \0 */ +#define NVME_UUID_LEN 16 + +/** + * nvme_uuid_to_string - Return string represenation of encoded UUID + * @uuid: Binary encoded input UUID + * @str: Output string represenation of UUID + * + * Return: Returns error code if type conversion fails. + */ +int nvme_uuid_to_string(unsigned char uuid[NVME_UUID_LEN], char *str); + +/** + * nvme_uuid_from_string - Return encoded UUID represenation of string UUID + * @uuid: Binary encoded input UUID + * @str: Output string represenation of UUID + * + * Return: Returns error code if type conversion fails. + */ +int nvme_uuid_from_string(const char *str, unsigned char uuid[NVME_UUID_LEN]); + +/** + * nvme_uuid_random - Generate random UUID + * @uuid: Generated random UUID + * + * Generate random number according + * https://www.rfc-editor.org/rfc/rfc4122#section-4.4 + * + * Return: Returns error code if generating of random number fails. + */ +int nvme_uuid_random(unsigned char uuid[NVME_UUID_LEN]); + #endif /* _LIBNVME_UTIL_H */ diff --git a/test/meson.build b/test/meson.build index 00c9ceb..d90f835 100644 --- a/test/meson.build +++ b/test/meson.build @@ -12,7 +12,7 @@ main = executable( 'main-test', ['test.c'], - dependencies: [libnvme_dep, libuuid_dep], + dependencies: [libnvme_dep], include_directories: [incdir, internal_incdir] ) @@ -56,3 +56,12 @@ mi_mctp = executable( ) test('mi-mctp', mi_mctp) + +uuid = executable( + 'test-uuid', + ['uuid.c'], + dependencies: libnvme_dep, + include_directories: [incdir, internal_incdir] +) + +test('uuid', uuid) diff --git a/test/mi-mctp.c b/test/mi-mctp.c index 5b1a154..6d83d42 100644 --- a/test/mi-mctp.c +++ b/test/mi-mctp.c @@ -308,7 +308,8 @@ static void test_admin_resp_err(nvme_mi_ep_t ep, struct test_peer *peer) peer->tx_buf_len = 8; rc = nvme_mi_admin_identify_ctrl(ctrl, &id); - assert(rc == 0x2); + assert(nvme_status_get_type(rc) == NVME_STATUS_TYPE_MI); + assert(nvme_status_get_value(rc) == NVME_MI_RESP_INTERNAL_ERR); } /* test: all 4-byte aligned response sizes - should be decoded into the @@ -332,7 +333,8 @@ static void test_admin_resp_sizes(nvme_mi_ep_t ep, struct test_peer *peer) for (i = 8; i <= 4096 + 8; i+=4) { peer->tx_buf_len = i; rc = nvme_mi_admin_identify_ctrl(ctrl, &id); - assert(rc == 2); + assert(nvme_status_get_type(rc) == NVME_STATUS_TYPE_MI); + assert(nvme_status_get_value(rc) == NVME_MI_RESP_INTERNAL_ERR); } nvme_mi_close_ctrl(ctrl); @@ -407,6 +409,7 @@ static void test_poll_timeout(nvme_mi_ep_t ep, struct test_peer *peer) /* test: send a More Processing Required response, then the actual response */ struct mpr_tx_info { int msg_no; + bool admin_quirk; size_t final_len; }; @@ -422,6 +425,9 @@ static int tx_mpr(struct test_peer *peer, void *buf, size_t len) case 1: peer->tx_buf[4] = NVME_MI_RESP_MPR; peer->tx_buf_len = 8; + if (tx_info->admin_quirk) { + peer->tx_buf_len = 20; + } break; case 2: peer->tx_buf[4] = NVME_MI_RESP_SUCCESS; @@ -446,6 +452,7 @@ static void test_mpr_mi(nvme_mi_ep_t ep, struct test_peer *peer) tx_info.msg_no = 1; tx_info.final_len = sizeof(struct nvme_mi_mi_resp_hdr) + sizeof(ss_info); + tx_info.admin_quirk = false; peer->tx_fn = tx_mpr; peer->tx_data = &tx_info; @@ -463,6 +470,32 @@ static void test_mpr_admin(nvme_mi_ep_t ep, struct test_peer *peer) tx_info.msg_no = 1; tx_info.final_len = sizeof(struct nvme_mi_admin_resp_hdr) + sizeof(id); + tx_info.admin_quirk = false; + + peer->tx_fn = tx_mpr; + peer->tx_data = &tx_info; + + ctrl = nvme_mi_init_ctrl(ep, 1); + + rc = nvme_mi_admin_identify_ctrl(ctrl, &id); + assert(rc == 0); + + nvme_mi_close_ctrl(ctrl); +} + +/* We have seen drives that send a MPR response as a full Admin message, + * rather than a MI message; these have a larger message body + */ +static void test_mpr_admin_quirked(nvme_mi_ep_t ep, struct test_peer *peer) +{ + struct mpr_tx_info tx_info; + struct nvme_id_ctrl id; + nvme_mi_ctrl_t ctrl; + int rc; + + tx_info.msg_no = 1; + tx_info.final_len = sizeof(struct nvme_mi_admin_resp_hdr) + sizeof(id); + tx_info.admin_quirk = true; peer->tx_fn = tx_mpr; peer->tx_data = &tx_info; @@ -638,6 +671,7 @@ struct test { DEFINE_TEST(poll_timeout), DEFINE_TEST(mpr_mi), DEFINE_TEST(mpr_admin), + DEFINE_TEST(mpr_admin_quirked), DEFINE_TEST(mpr_timeouts), DEFINE_TEST(mpr_timeout_clamp), DEFINE_TEST(mpr_mprt_zero), diff --git a/test/mi.c b/test/mi.c index d269060..c21f9db 100644 --- a/test/mi.c +++ b/test/mi.c @@ -11,6 +11,7 @@ #include #include +#include /* we define a custom transport, so need the internal headers */ #include "nvme/private.h" @@ -747,6 +748,1037 @@ static void test_mi_config_set_freq_invalid(nvme_mi_ep_t ep) assert(rc == 4); } +/* Get Features callback, implementing Arbitration (which doesn't return + * additional data) and Timestamp (which does). + */ +static int test_admin_get_features_cb(struct nvme_mi_ep *ep, + struct nvme_mi_req *req, + struct nvme_mi_resp *resp, + void *data) +{ + __u8 sel, fid, ror, mt, *rq_hdr, *rs_hdr, *rs_data; + __u16 ctrl_id; + int i; + + assert(req->hdr->type == NVME_MI_MSGTYPE_NVME); + + ror = req->hdr->nmp >> 7; + mt = req->hdr->nmp >> 3 & 0x7; + assert(ror == NVME_MI_ROR_REQ); + assert(mt == NVME_MI_MT_ADMIN); + + /* do we have enough for a mi header? */ + assert(req->hdr_len == sizeof(struct nvme_mi_admin_req_hdr)); + + /* inspect response as raw bytes */ + rq_hdr = (__u8 *)req->hdr; + + /* opcode */ + assert(rq_hdr[4] == nvme_admin_get_features); + + /* controller */ + ctrl_id = rq_hdr[7] << 8 | rq_hdr[6]; + assert(ctrl_id == 0x5); /* controller id */ + + /* sel & fid from lower bytes of cdw10 */ + fid = rq_hdr[44]; + sel = rq_hdr[45] & 0x7; + + /* reserved fields */ + assert(!(rq_hdr[46] || rq_hdr[47] || rq_hdr[45] & 0xf8)); + + assert(sel == 0x00); + + rs_hdr = (__u8 *)resp->hdr; + rs_hdr[4] = 0x00; /* status: success */ + rs_data = resp->data; + + /* feature-id specific checks, and response generation */ + switch (fid) { + case NVME_FEAT_FID_ARBITRATION: + /* arbitrary (hah!) arbitration value in cdw0 of response */ + rs_hdr[8] = 1; + rs_hdr[9] = 2; + rs_hdr[10] = 3; + rs_hdr[11] = 4; + resp->data_len = 0; + break; + + case NVME_FEAT_FID_TIMESTAMP: + resp->data_len = 8; + for (i = 0; i < 6; i++) + rs_data[i] = i; + rs_data[6] = 1; + break; + + default: + assert(0); + } + + test_transport_resp_calc_mic(resp); + + return 0; +} + +static void test_get_features_nodata(nvme_mi_ep_t ep) +{ + struct nvme_get_features_args args = { 0 }; + nvme_mi_ctrl_t ctrl; + uint32_t res; + int rc; + + test_set_transport_callback(ep, test_admin_get_features_cb, NULL); + + ctrl = nvme_mi_init_ctrl(ep, 5); + assert(ctrl); + + args.args_size = sizeof(args); + args.fid = NVME_FEAT_FID_ARBITRATION; + args.sel = 0; + args.result = &res; + + rc = nvme_mi_admin_get_features(ctrl, &args); + assert(rc == 0); + assert(args.data_len == 0); + assert(res == 0x04030201); +} + +static void test_get_features_data(nvme_mi_ep_t ep) +{ + struct nvme_get_features_args args = { 0 }; + struct nvme_timestamp tstamp; + nvme_mi_ctrl_t ctrl; + uint8_t exp[6]; + uint32_t res; + int rc, i; + + test_set_transport_callback(ep, test_admin_get_features_cb, NULL); + + ctrl = nvme_mi_init_ctrl(ep, 5); + assert(ctrl); + + args.args_size = sizeof(args); + args.fid = NVME_FEAT_FID_TIMESTAMP; + args.sel = 0; + args.result = &res; + args.data = &tstamp; + args.data_len = sizeof(tstamp); + + /* expected timestamp value */ + for (i = 0; i < sizeof(tstamp.timestamp); i++) + exp[i] = i; + + rc = nvme_mi_admin_get_features(ctrl, &args); + assert(rc == 0); + assert(args.data_len == sizeof(tstamp)); + assert(tstamp.attr == 1); + assert(!memcmp(tstamp.timestamp, exp, sizeof(tstamp.timestamp))); +} + +/* Set Features callback for timestamp */ +static int test_admin_set_features_cb(struct nvme_mi_ep *ep, + struct nvme_mi_req *req, + struct nvme_mi_resp *resp, + void *data) +{ + __u8 save, fid, ror, mt, *rq_hdr, *rq_data, *rs_hdr; + __u16 ctrl_id; + uint8_t ts[6]; + int i; + + assert(req->hdr->type == NVME_MI_MSGTYPE_NVME); + + ror = req->hdr->nmp >> 7; + mt = req->hdr->nmp >> 3 & 0x7; + assert(ror == NVME_MI_ROR_REQ); + assert(mt == NVME_MI_MT_ADMIN); + assert(req->hdr_len == sizeof(struct nvme_mi_admin_req_hdr)); + assert(req->data_len == 8); + + rq_hdr = (__u8 *)req->hdr; + rq_data = req->data; + + /* opcode */ + assert(rq_hdr[4] == nvme_admin_set_features); + + /* controller */ + ctrl_id = rq_hdr[7] << 8 | rq_hdr[6]; + assert(ctrl_id == 0x5); /* controller id */ + + /* fid from lower bytes of cdw10, save from top bit */ + fid = rq_hdr[44]; + save = rq_hdr[47] & 0x80; + + /* reserved fields */ + assert(!(rq_hdr[45] || rq_hdr[46])); + + assert(fid == NVME_FEAT_FID_TIMESTAMP); + assert(save == 0x80); + + for (i = 0; i < sizeof(ts); i++) + ts[i] = i; + assert(!memcmp(ts, rq_data, sizeof(ts))); + + rs_hdr = (__u8 *)resp->hdr; + rs_hdr[4] = 0x00; + + test_transport_resp_calc_mic(resp); + + return 0; +} + +static void test_set_features(nvme_mi_ep_t ep) +{ + struct nvme_set_features_args args = { 0 }; + struct nvme_timestamp tstamp; + nvme_mi_ctrl_t ctrl; + uint32_t res; + int rc, i; + + test_set_transport_callback(ep, test_admin_set_features_cb, NULL); + + ctrl = nvme_mi_init_ctrl(ep, 5); + assert(ctrl); + + for (i = 0; i < sizeof(tstamp.timestamp); i++) + tstamp.timestamp[i] = i; + + args.args_size = sizeof(args); + args.fid = NVME_FEAT_FID_TIMESTAMP; + args.save = 1; + args.result = &res; + args.data = &tstamp; + args.data_len = sizeof(tstamp); + + rc = nvme_mi_admin_set_features(ctrl, &args); + assert(rc == 0); + assert(args.data_len == 0); +} + +enum ns_type { + NS_ACTIVE, + NS_ALLOC, +}; + +static int test_admin_id_ns_list_cb(struct nvme_mi_ep *ep, + struct nvme_mi_req *req, + struct nvme_mi_resp *resp, + void *data) +{ + struct nvme_ns_list *list; + enum ns_type type; + int offset; + __u8 *hdr; + __u16 cns; + + hdr = (__u8 *)req->hdr; + assert(hdr[4] == nvme_admin_identify); + + assert(req->data_len == 0); + + cns = hdr[45] << 8 | hdr[44]; + + /* NSID */ + assert(hdr[8] == 1 && !hdr[9] && !hdr[10] && !hdr[11]); + + type = *(enum ns_type *)data; + resp->data_len = sizeof(*list); + list = resp->data; + + switch (type) { + case NS_ALLOC: + assert(cns == NVME_IDENTIFY_CNS_ALLOCATED_NS_LIST); + offset = 2; + break; + case NS_ACTIVE: + assert(cns == NVME_IDENTIFY_CNS_NS_ACTIVE_LIST); + offset = 4; + break; + default: + assert(0); + } + + list->ns[0] = cpu_to_le32(offset); + list->ns[1] = cpu_to_le32(offset + 1); + + test_transport_resp_calc_mic(resp); + + return 0; +} + +static void test_admin_id_alloc_ns_list(struct nvme_mi_ep *ep) +{ + struct nvme_ns_list list; + nvme_mi_ctrl_t ctrl; + enum ns_type type; + int rc; + + type = NS_ALLOC; + test_set_transport_callback(ep, test_admin_id_ns_list_cb, &type); + + ctrl = nvme_mi_init_ctrl(ep, 5); + assert(ctrl); + + rc = nvme_mi_admin_identify_allocated_ns_list(ctrl, 1, &list); + assert(!rc); + + assert(le32_to_cpu(list.ns[0]) == 2); + assert(le32_to_cpu(list.ns[1]) == 3); + assert(le32_to_cpu(list.ns[2]) == 0); +} + +static void test_admin_id_active_ns_list(struct nvme_mi_ep *ep) +{ + struct nvme_ns_list list; + nvme_mi_ctrl_t ctrl; + enum ns_type type; + int rc; + + type = NS_ACTIVE; + test_set_transport_callback(ep, test_admin_id_ns_list_cb, &type); + + ctrl = nvme_mi_init_ctrl(ep, 5); + assert(ctrl); + + rc = nvme_mi_admin_identify_active_ns_list(ctrl, 1, &list); + assert(!rc); + + assert(le32_to_cpu(list.ns[0]) == 4); + assert(le32_to_cpu(list.ns[1]) == 5); + assert(le32_to_cpu(list.ns[2]) == 0); +} + +static int test_admin_id_ns_cb(struct nvme_mi_ep *ep, + struct nvme_mi_req *req, + struct nvme_mi_resp *resp, + void *data) +{ + struct nvme_id_ns *id; + enum ns_type type; + __u16 nsid, cns; + __u8 *hdr; + + hdr = (__u8 *)req->hdr; + assert(hdr[4] == nvme_admin_identify); + + assert(req->data_len == 0); + + cns = hdr[45] << 8 | hdr[44]; + + /* NSID */ + nsid = hdr[8]; + assert(!hdr[9] && !hdr[10] && !hdr[11]); + + type = *(enum ns_type *)data; + resp->data_len = sizeof(*id); + id = resp->data; + id->nsze = cpu_to_le64(nsid); + + switch (type) { + case NS_ALLOC: + assert(cns == NVME_IDENTIFY_CNS_ALLOCATED_NS); + break; + case NS_ACTIVE: + assert(cns == NVME_IDENTIFY_CNS_NS); + break; + default: + assert(0); + } + + test_transport_resp_calc_mic(resp); + + return 0; +} + +static void test_admin_id_alloc_ns(struct nvme_mi_ep *ep) +{ + struct nvme_id_ns id; + nvme_mi_ctrl_t ctrl; + enum ns_type type; + int rc; + + type = NS_ALLOC; + test_set_transport_callback(ep, test_admin_id_ns_cb, &type); + + ctrl = nvme_mi_init_ctrl(ep, 5); + assert(ctrl); + + rc = nvme_mi_admin_identify_allocated_ns(ctrl, 1, &id); + assert(!rc); + assert(le64_to_cpu(id.nsze) == 1); +} + +static void test_admin_id_active_ns(struct nvme_mi_ep *ep) +{ + struct nvme_id_ns id; + nvme_mi_ctrl_t ctrl; + enum ns_type type; + int rc; + + type = NS_ACTIVE; + test_set_transport_callback(ep, test_admin_id_ns_cb, &type); + + ctrl = nvme_mi_init_ctrl(ep, 5); + assert(ctrl); + + rc = nvme_mi_admin_identify_ns(ctrl, 1, &id); + assert(!rc); + assert(le64_to_cpu(id.nsze) == 1); +} + +static int test_admin_id_nsid_ctrl_list_cb(struct nvme_mi_ep *ep, + struct nvme_mi_req *req, + struct nvme_mi_resp *resp, + void *data) +{ + __u16 cns, ctrlid; + __u32 nsid; + __u8 *hdr; + + hdr = (__u8 *)req->hdr; + assert(hdr[4] == nvme_admin_identify); + + assert(req->data_len == 0); + + cns = hdr[45] << 8 | hdr[44]; + assert(cns == NVME_IDENTIFY_CNS_CTRL_LIST); + + nsid = hdr[11] << 24 | hdr[10] << 16 | hdr[9] << 8 | hdr[8]; + assert(nsid == 0x01020304); + + ctrlid = hdr[47] << 8 | hdr[46]; + assert(ctrlid == 5); + + resp->data_len = sizeof(struct nvme_ctrl_list); + test_transport_resp_calc_mic(resp); + + return 0; +} + +static void test_admin_id_nsid_ctrl_list(struct nvme_mi_ep *ep) +{ + struct nvme_ctrl_list list; + nvme_mi_ctrl_t ctrl; + int rc; + + test_set_transport_callback(ep, test_admin_id_nsid_ctrl_list_cb, NULL); + + ctrl = nvme_mi_init_ctrl(ep, 5); + assert(ctrl); + + rc = nvme_mi_admin_identify_nsid_ctrl_list(ctrl, 0x01020304, 5, &list); + assert(!rc); +} + +static int test_admin_id_secondary_ctrl_list_cb(struct nvme_mi_ep *ep, + struct nvme_mi_req *req, + struct nvme_mi_resp *resp, + void *data) +{ + __u16 cns, ctrlid; + __u32 nsid; + __u8 *hdr; + + hdr = (__u8 *)req->hdr; + assert(hdr[4] == nvme_admin_identify); + + assert(req->data_len == 0); + + cns = hdr[45] << 8 | hdr[44]; + assert(cns == NVME_IDENTIFY_CNS_SECONDARY_CTRL_LIST); + + nsid = hdr[11] << 24 | hdr[10] << 16 | hdr[9] << 8 | hdr[8]; + assert(nsid == 0x01020304); + + ctrlid = hdr[47] << 8 | hdr[46]; + assert(ctrlid == 5); + + resp->data_len = sizeof(struct nvme_secondary_ctrl_list); + test_transport_resp_calc_mic(resp); + + return 0; +} + +static void test_admin_id_secondary_ctrl_list(struct nvme_mi_ep *ep) +{ + struct nvme_secondary_ctrl_list list; + nvme_mi_ctrl_t ctrl; + int rc; + + test_set_transport_callback(ep, test_admin_id_secondary_ctrl_list_cb, + NULL); + + ctrl = nvme_mi_init_ctrl(ep, 5); + assert(ctrl); + + rc = nvme_mi_admin_identify_secondary_ctrl_list(ctrl, 0x01020304, + 5, &list); + assert(!rc); +} + +static int test_admin_ns_mgmt_cb(struct nvme_mi_ep *ep, + struct nvme_mi_req *req, + struct nvme_mi_resp *resp, + void *data) +{ + __u8 *rq_hdr, *rs_hdr, sel, csi; + struct nvme_id_ns *id; + __u32 nsid; + + rq_hdr = (__u8 *)req->hdr; + assert(rq_hdr[4] == nvme_admin_ns_mgmt); + + sel = rq_hdr[44]; + csi = rq_hdr[45]; + nsid = rq_hdr[11] << 24 | rq_hdr[10] << 16 | rq_hdr[9] << 8 | rq_hdr[8]; + + rs_hdr = (__u8 *)resp->hdr; + + switch (sel) { + case NVME_NS_MGMT_SEL_CREATE: + assert(req->data_len == sizeof(struct nvme_id_ns)); + id = req->data; + + /* No NSID on created namespaces */ + assert(nsid == 0); + assert(csi == 0); + + /* allow operations on nsze == 42, reject others */ + if (le64_to_cpu(id->nsze) != 42) { + rs_hdr[4] = 0; + /* response cdw0 is created NSID */ + rs_hdr[8] = 0x04; + rs_hdr[9] = 0x03; + rs_hdr[10] = 0x02; + rs_hdr[11] = 0x01; + } else { + rs_hdr[4] = NVME_MI_RESP_INVALID_PARAM; + } + break; + + case NVME_NS_MGMT_SEL_DELETE: + assert(req->data_len == 0); + /* NSID required on delete */ + assert(nsid == 0x05060708); + break; + + default: + assert(0); + } + + test_transport_resp_calc_mic(resp); + + return 0; +} + +static void test_admin_ns_mgmt_create(struct nvme_mi_ep *ep) +{ + struct nvme_id_ns nsid; + nvme_mi_ctrl_t ctrl; + __u32 ns; + int rc; + + test_set_transport_callback(ep, test_admin_ns_mgmt_cb, NULL); + + ctrl = nvme_mi_init_ctrl(ep, 5); + assert(ctrl); + + rc = nvme_mi_admin_ns_mgmt_create(ctrl, &nsid, 0, &ns); + assert(!rc); + assert(ns == 0x01020304); + + nsid.nsze = 42; + rc = nvme_mi_admin_ns_mgmt_create(ctrl, &nsid, 0, &ns); + assert(rc); +} + +static void test_admin_ns_mgmt_delete(struct nvme_mi_ep *ep) +{ + nvme_mi_ctrl_t ctrl; + int rc; + + test_set_transport_callback(ep, test_admin_ns_mgmt_cb, NULL); + + ctrl = nvme_mi_init_ctrl(ep, 5); + assert(ctrl); + + rc = nvme_mi_admin_ns_mgmt_delete(ctrl, 0x05060708); + assert(!rc); +} + +struct attach_op { + enum { + NS_ATTACH, + NS_DETACH, + } op; + struct nvme_ctrl_list *list; +}; + +static int test_admin_ns_attach_cb(struct nvme_mi_ep *ep, + struct nvme_mi_req *req, + struct nvme_mi_resp *resp, + void *data) +{ + struct attach_op *op = data; + __u8 *rq_hdr, sel; + __u32 nsid; + + rq_hdr = (__u8 *)req->hdr; + assert(rq_hdr[4] == nvme_admin_ns_attach); + + sel = rq_hdr[44]; + nsid = rq_hdr[11] << 24 | rq_hdr[10] << 16 | rq_hdr[9] << 8 | rq_hdr[8]; + + assert(req->data_len == sizeof(*op->list)); + + assert(nsid == 0x02030405); + switch (op->op) { + case NS_ATTACH: + assert(sel == NVME_NS_ATTACH_SEL_CTRL_ATTACH); + break; + case NS_DETACH: + assert(sel == NVME_NS_ATTACH_SEL_CTRL_DEATTACH); + break; + default: + assert(0); + } + + assert(!memcmp(req->data, op->list, sizeof(*op->list))); + + test_transport_resp_calc_mic(resp); + + return 0; +} + +static void test_admin_ns_attach(struct nvme_mi_ep *ep) +{ + struct nvme_ctrl_list list = { 0 }; + struct attach_op aop; + nvme_mi_ctrl_t ctrl; + int rc; + + list.num = cpu_to_le16(2); + list.identifier[0] = 4; + list.identifier[1] = 5; + + aop.op = NS_ATTACH; + aop.list = &list; + + test_set_transport_callback(ep, test_admin_ns_attach_cb, &aop); + + ctrl = nvme_mi_init_ctrl(ep, 5); + assert(ctrl); + + rc = nvme_mi_admin_ns_attach_ctrls(ctrl, 0x02030405, &list); + assert(!rc); +} + +static void test_admin_ns_detach(struct nvme_mi_ep *ep) +{ + struct nvme_ctrl_list list = { 0 }; + struct attach_op aop; + nvme_mi_ctrl_t ctrl; + int rc; + + list.num = cpu_to_le16(2); + list.identifier[0] = 6; + list.identifier[1] = 7; + + aop.op = NS_DETACH; + aop.list = &list; + + test_set_transport_callback(ep, test_admin_ns_attach_cb, &aop); + + ctrl = nvme_mi_init_ctrl(ep, 5); + assert(ctrl); + + rc = nvme_mi_admin_ns_detach_ctrls(ctrl, 0x02030405, &list); + assert(!rc); +} + +struct fw_download_info { + uint32_t offset; + uint32_t len; + void *data; +}; + +static int test_admin_fw_download_cb(struct nvme_mi_ep *ep, + struct nvme_mi_req *req, + struct nvme_mi_resp *resp, + void *data) +{ + struct fw_download_info *info = data; + __u32 len, off; + __u8 *rq_hdr; + + rq_hdr = (__u8 *)req->hdr; + assert(rq_hdr[4] == nvme_admin_fw_download); + + len = rq_hdr[47] << 24 | rq_hdr[46] << 16 | rq_hdr[45] << 8 | rq_hdr[44]; + off = rq_hdr[51] << 24 | rq_hdr[50] << 16 | rq_hdr[49] << 8 | rq_hdr[48]; + + assert(off << 2 == info->offset); + assert(((len+1) << 2) == info->len); + + /* ensure that the request len matches too */ + assert(req->data_len == info->len); + + assert(!memcmp(req->data, info->data, len)); + + test_transport_resp_calc_mic(resp); + + return 0; +} + +static void test_admin_fw_download(struct nvme_mi_ep *ep) +{ + struct nvme_fw_download_args args; + struct fw_download_info info; + unsigned char fw[4096]; + nvme_mi_ctrl_t ctrl; + int rc, i; + + for (i = 0; i < sizeof(fw); i++) + fw[i] = i % 0xff; + + info.offset = 0; + info.len = 0; + info.data = fw; + args.data = fw; + args.args_size = sizeof(args); + + test_set_transport_callback(ep, test_admin_fw_download_cb, &info); + + ctrl = nvme_mi_init_ctrl(ep, 5); + assert(ctrl); + + /* invalid (zero) len */ + args.data_len = info.len = 1; + args.offset = info.offset = 0; + rc = nvme_mi_admin_fw_download(ctrl, &args); + assert(rc); + + /* invalid (unaligned) len */ + args.data_len = info.len = 1; + args.offset = info.offset = 0; + rc = nvme_mi_admin_fw_download(ctrl, &args); + assert(rc); + + /* invalid offset */ + args.data_len = info.len = 4; + args.offset = info.offset = 1; + rc = nvme_mi_admin_fw_download(ctrl, &args); + assert(rc); + + /* smallest len */ + args.data_len = info.len = 4; + args.offset = info.offset = 0; + rc = nvme_mi_admin_fw_download(ctrl, &args); + assert(!rc); + + /* largest len */ + args.data_len = info.len = 4096; + args.offset = info.offset = 0; + rc = nvme_mi_admin_fw_download(ctrl, &args); + assert(!rc); + + /* offset value */ + args.data_len = info.len = 4096; + args.offset = info.offset = 4096; + rc = nvme_mi_admin_fw_download(ctrl, &args); + assert(!rc); +} + +struct fw_commit_info { + __u8 bpid; + __u8 action; + __u8 slot; +}; + +static int test_admin_fw_commit_cb(struct nvme_mi_ep *ep, + struct nvme_mi_req *req, + struct nvme_mi_resp *resp, + void *data) +{ + struct fw_commit_info *info = data; + __u8 bpid, action, slot; + __u8 *rq_hdr; + + rq_hdr = (__u8 *)req->hdr; + assert(rq_hdr[4] == nvme_admin_fw_commit); + + bpid = (rq_hdr[47] >> 7) & 0x1; + slot = rq_hdr[44] & 0x7; + action = (rq_hdr[44] >> 3) & 0x7; + + assert(!!bpid == !!info->bpid); + assert(slot == info->slot); + assert(action == info->action); + + test_transport_resp_calc_mic(resp); + + return 0; +} + +static void test_admin_fw_commit(struct nvme_mi_ep *ep) +{ + struct nvme_fw_commit_args args; + struct fw_commit_info info; + nvme_mi_ctrl_t ctrl; + int rc; + + args.args_size = sizeof(args); + info.bpid = args.bpid = 0; + + test_set_transport_callback(ep, test_admin_fw_commit_cb, &info); + + ctrl = nvme_mi_init_ctrl(ep, 5); + assert(ctrl); + + /* all zeros */ + info.bpid = args.bpid = 0; + info.slot = args.slot = 0; + info.action = args.action = 0; + rc = nvme_mi_admin_fw_commit(ctrl, &args); + assert(!rc); + + /* all ones */ + info.bpid = args.bpid = 1; + info.slot = args.slot = 0x7; + info.action = args.action = 0x7; + rc = nvme_mi_admin_fw_commit(ctrl, &args); + assert(!rc); + + /* correct fields */ + info.bpid = args.bpid = 1; + info.slot = args.slot = 2; + info.action = args.action = 3; + rc = nvme_mi_admin_fw_commit(ctrl, &args); + assert(!rc); +} + +struct format_data { + __u32 nsid; + __u8 lbafu; + __u8 ses; + __u8 pil; + __u8 pi; + __u8 mset; + __u8 lbafl; +}; + +static int test_admin_format_nvm_cb(struct nvme_mi_ep *ep, + struct nvme_mi_req *req, + struct nvme_mi_resp *resp, + void *data) +{ + struct nvme_format_nvm_args *args = data; + __u8 *rq_hdr; + __u32 nsid; + + assert(req->data_len == 0); + + rq_hdr = (__u8 *)req->hdr; + + assert(rq_hdr[4] == nvme_admin_format_nvm); + + nsid = rq_hdr[11] << 24 | rq_hdr[10] << 16 | rq_hdr[9] << 8 | rq_hdr[8]; + assert(nsid == args->nsid); + + assert(((rq_hdr[44] >> 0) & 0xf) == args->lbaf); + assert(((rq_hdr[44] >> 4) & 0x1) == args->mset); + assert(((rq_hdr[44] >> 5) & 0x7) == args->pi); + + assert(((rq_hdr[45] >> 0) & 0x1) == args->pil); + assert(((rq_hdr[45] >> 1) & 0x7) == args->ses); + assert(((rq_hdr[45] >> 4) & 0x3) == args->lbafu); + + test_transport_resp_calc_mic(resp); + + return 0; +} + +static void test_admin_format_nvm(struct nvme_mi_ep *ep) +{ + struct nvme_format_nvm_args args = { 0 }; + nvme_mi_ctrl_t ctrl; + int rc; + + ctrl = nvme_mi_init_ctrl(ep, 5); + assert(ctrl); + + test_set_transport_callback(ep, test_admin_format_nvm_cb, &args); + + /* ensure we have the cdw0 bit field encoding correct, by testing twice + * with inverted bit values */ + args.args_size = sizeof(args); + args.nsid = 0x04030201; + args.lbafu = 0x3; + args.ses = 0x0; + args.pil = 0x1; + args.pi = 0x0; + args.mset = 0x1; + args.lbaf = 0x0; + + rc = nvme_mi_admin_format_nvm(ctrl, &args); + assert(!rc); + + args.nsid = ~args.nsid; + args.lbafu = 0; + args.ses = 0x7; + args.pil = 0x0; + args.pi = 0x7; + args.mset = 0x0; + args.lbaf = 0xf; + + rc = nvme_mi_admin_format_nvm(ctrl, &args); + assert(!rc); +} + +static int test_admin_sanitize_nvm_cb(struct nvme_mi_ep *ep, + struct nvme_mi_req *req, + struct nvme_mi_resp *resp, + void *data) +{ + struct nvme_sanitize_nvm_args *args = data; + __u8 *rq_hdr; + __u32 ovrpat; + + assert(req->data_len == 0); + + rq_hdr = (__u8 *)req->hdr; + + assert(rq_hdr[4] == nvme_admin_sanitize_nvm); + + assert(((rq_hdr[44] >> 0) & 0x7) == args->sanact); + assert(((rq_hdr[44] >> 3) & 0x1) == args->ause); + assert(((rq_hdr[44] >> 4) & 0xf) == args->owpass); + + assert(((rq_hdr[45] >> 0) & 0x1) == args->oipbp); + assert(((rq_hdr[45] >> 1) & 0x1) == args->nodas); + + ovrpat = rq_hdr[51] << 24 | rq_hdr[50] << 16 | + rq_hdr[49] << 8 | rq_hdr[48]; + assert(ovrpat == args->ovrpat); + + test_transport_resp_calc_mic(resp); + + return 0; +} + +static void test_admin_sanitize_nvm(struct nvme_mi_ep *ep) +{ + struct nvme_sanitize_nvm_args args = { 0 }; + nvme_mi_ctrl_t ctrl; + int rc; + + ctrl = nvme_mi_init_ctrl(ep, 5); + assert(ctrl); + + test_set_transport_callback(ep, test_admin_sanitize_nvm_cb, &args); + + args.args_size = sizeof(args); + args.sanact = 0x7; + args.ause = 0x0; + args.owpass = 0xf; + args.oipbp = 0x0; + args.nodas = 0x1; + args.ovrpat = ~0x04030201; + + rc = nvme_mi_admin_sanitize_nvm(ctrl, &args); + assert(!rc); + + args.sanact = 0x0; + args.ause = 0x1; + args.owpass = 0x0; + args.oipbp = 0x1; + args.nodas = 0x0; + args.ovrpat = 0x04030201; + + rc = nvme_mi_admin_sanitize_nvm(ctrl, &args); + assert(!rc); +} + +/* test that we set the correct offset and size on get_log() calls that + * are split into multiple requests */ +struct log_data { + int n; +}; + +static int test_admin_get_log_split_cb(struct nvme_mi_ep *ep, + struct nvme_mi_req *req, + struct nvme_mi_resp *resp, + void *data) +{ + struct log_data *ldata = data; + uint32_t len, off; + __u8 *rq_hdr; + + assert(req->data_len == 0); + + rq_hdr = (__u8 *)req->hdr; + + assert(rq_hdr[4] == nvme_admin_get_log_page); + + /* from the MI message's DOFST/DLEN fields */ + off = rq_hdr[31] << 24 | rq_hdr[30] << 16 | rq_hdr[29] << 8 | rq_hdr[28]; + len = rq_hdr[35] << 24 | rq_hdr[34] << 16 | rq_hdr[33] << 8 | rq_hdr[32]; + + /* we should have a full-sized start and middle, and a short end */ + switch (ldata->n) { + case 0: + assert(len == 4096); + assert(off == 0); + break; + case 1: + assert(len == 4096); + assert(off == 4096); + break; + case 2: + assert(len == 4); + assert(off == 4096 * 2); + break; + default: + assert(0); + } + + /* ensure we've sized the expected response correctly */ + assert(resp->data_len == len); + memset(resp->data, ldata->n & 0xff, len); + + test_transport_resp_calc_mic(resp); + + ldata->n++; + + return 0; +} + +static void test_admin_get_log_split(struct nvme_mi_ep *ep) +{ + unsigned char buf[4096 * 2 + 4]; + struct nvme_get_log_args args; + struct log_data ldata; + nvme_mi_ctrl_t ctrl; + int rc; + + ldata.n = 0; + test_set_transport_callback(ep, test_admin_get_log_split_cb, &ldata); + + ctrl = nvme_mi_init_ctrl(ep, 5); + + args.args_size = sizeof(args); + args.lid = 1; + args.log = buf; + args.len = sizeof(buf); + + rc = nvme_mi_admin_get_log(ctrl, &args); + + assert(!rc); + + /* we should have sent three commands */ + assert(ldata.n == 3); +} + #define DEFINE_TEST(name) { #name, test_ ## name } struct test { const char *name; @@ -769,6 +1801,24 @@ struct test { DEFINE_TEST(mi_config_get_mtu), DEFINE_TEST(mi_config_set_freq), DEFINE_TEST(mi_config_set_freq_invalid), + DEFINE_TEST(get_features_nodata), + DEFINE_TEST(get_features_data), + DEFINE_TEST(set_features), + DEFINE_TEST(admin_id_alloc_ns_list), + DEFINE_TEST(admin_id_active_ns_list), + DEFINE_TEST(admin_id_alloc_ns), + DEFINE_TEST(admin_id_active_ns), + DEFINE_TEST(admin_id_nsid_ctrl_list), + DEFINE_TEST(admin_id_secondary_ctrl_list), + DEFINE_TEST(admin_ns_mgmt_create), + DEFINE_TEST(admin_ns_mgmt_delete), + DEFINE_TEST(admin_ns_attach), + DEFINE_TEST(admin_ns_detach), + DEFINE_TEST(admin_fw_download), + DEFINE_TEST(admin_fw_commit), + DEFINE_TEST(admin_format_nvm), + DEFINE_TEST(admin_sanitize_nvm), + DEFINE_TEST(admin_get_log_split), }; static void run_test(struct test *test, FILE *logfd, nvme_mi_ep_t ep) diff --git a/test/test.c b/test/test.c index bc5393b..2f24e1e 100644 --- a/test/test.c +++ b/test/test.c @@ -19,7 +19,6 @@ #include #include #include -#include #include #include @@ -377,8 +376,8 @@ int main(int argc, char **argv) nvme_ctrl_get_state(c)); nvme_ctrl_for_each_ns(c, n) { - char uuid_str[40]; - uuid_t uuid; + char uuid_str[NVME_UUID_LEN_STRING]; + unsigned char uuid[NVME_UUID_LEN]; printf(" `- %s lba size:%d lba max:%" PRIu64 "\n", nvme_ns_get_name(n), nvme_ns_get_lba_size(n), @@ -388,7 +387,7 @@ int main(int argc, char **argv) printf(" nguid:"); print_hex(nvme_ns_get_nguid(n), 16); nvme_ns_get_uuid(n, uuid); - uuid_unparse_lower(uuid, uuid_str); + nvme_uuid_to_string(uuid, uuid_str); printf(" uuid:%s csi:%d\n", uuid_str, nvme_ns_get_csi(n)); } diff --git a/test/uuid.c b/test/uuid.c new file mode 100644 index 0000000..9146453 --- /dev/null +++ b/test/uuid.c @@ -0,0 +1,120 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/** + * This file is part of libnvme. + * Copyright (c) 2022 Daniel Wagner, SUSE Software Solutions + */ + +#include +#include + +#include + +#include + +static int test_rc; + +struct test_data { + unsigned char uuid[NVME_UUID_LEN]; + const char *str; +}; + +static struct test_data test_data[] = { + { { 0 }, "00000000-0000-0000-0000-000000000000" }, + { { [0 ... 15] = 0xff }, "ffffffff-ffff-ffff-ffff-ffffffffffff" }, + { { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0f, 0x10 }, + "00010203-0405-0607-0809-0a0b0c0d0f10" }, +}; + +static void check_str(const char *exp, const char *res) +{ + if (!strcmp(res, exp)) + return; + + printf("ERROR: got '%s', expected '%s'\n", res, exp); + + test_rc = 1; +} + +static void print_uuid_hex(const unsigned char uuid[NVME_UUID_LEN]) +{ + for (int i = 0; i < NVME_UUID_LEN; i++) + printf("%02x", uuid[i]); +} + +static void check_uuid(unsigned char exp[NVME_UUID_LEN], + unsigned char res[NVME_UUID_LEN]) +{ + if (!memcmp(exp, res, NVME_UUID_LEN)) + return; + + printf("ERROR: got '"); + print_uuid_hex(exp); + printf("', expected '"); + print_uuid_hex(res); + printf("'\n"); +} + +static void tostr_test(struct test_data *test) +{ + char str[NVME_UUID_LEN_STRING]; + + if (nvme_uuid_to_string(test->uuid, str)) { + test_rc = 1; + printf("ERROR: nvme_uuid_to_string() failed\n"); + return; + } + check_str(test->str, str); +} + +static void fromstr_test(struct test_data *test) +{ + + unsigned char uuid[NVME_UUID_LEN]; + + if (nvme_uuid_from_string(test->str, uuid)) { + test_rc = 1; + printf("ERROR: nvme_uuid_from_string() failed\n"); + return; + } + check_uuid(test->uuid, uuid); +} + +static void random_uuid_test(void) +{ + unsigned char uuid1[NVME_UUID_LEN], uuid2[NVME_UUID_LEN]; + char str1[NVME_UUID_LEN_STRING], str2[NVME_UUID_LEN_STRING]; + + if (nvme_uuid_random(uuid1) || nvme_uuid_random(uuid2)) { + test_rc = 1; + printf("ERROR: nvme_uuid_random() failed\n"); + return; + } + + if (!memcmp(uuid1, uuid2, NVME_UUID_LEN)) { + test_rc = 1; + printf("ERROR: generated random numbers are equal\n"); + return; + } + + if (nvme_uuid_to_string(uuid1, str1) || + nvme_uuid_to_string(uuid2, str2)) { + test_rc = 1; + printf("ERROR: could not stringify randomly generated UUID\n"); + return; + } + printf("PASS: generated UUIDs %s %s\n", str1, str2); +} + +int main(void) +{ + for (int i = 0; i < ARRAY_SIZE(test_data); i++) + tostr_test(&test_data[i]); + + for (int i = 0; i < ARRAY_SIZE(test_data); i++) + fromstr_test(&test_data[i]); + + random_uuid_test(); + + return test_rc ? EXIT_FAILURE : EXIT_SUCCESS; +} -- cgit v1.2.3