1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright (C) 2018 Intel Corporation. 3 * All rights reserved. 4 */ 5 6 /** 7 * \file 8 * NVMe driver public API extension for Open-Channel 9 */ 10 11 #ifndef SPDK_NVME_OCSSD_H 12 #define SPDK_NVME_OCSSD_H 13 14 #include "spdk/stdinc.h" 15 16 #ifdef __cplusplus 17 extern "C" { 18 #endif 19 20 #include "spdk/nvme.h" 21 #include "spdk/nvme_ocssd_spec.h" 22 23 /** 24 * \brief Determine if OpenChannel is supported by the given NVMe controller. 25 * \param ctrlr NVMe controller to check. 26 * 27 * \return true if support OpenChannel 28 */ 29 bool spdk_nvme_ctrlr_is_ocssd_supported(struct spdk_nvme_ctrlr *ctrlr); 30 31 /** 32 * \brief Identify geometry of the given namespace. 33 * \param ctrlr NVMe controller to query. 34 * \param nsid Id of the given namespace. 35 * \param payload The pointer to the payload buffer. 36 * \param payload_size The size of payload buffer. Shall be multiple of 4K. 37 * \param cb_fn Callback function to invoke when the feature has been retrieved. 38 * \param cb_arg Argument to pass to the callback function. 39 * 40 * \return 0 if successfully submitted, ENOMEM if resources could not be 41 * allocated for this request, EINVAL if wrong payload size. 42 * 43 */ 44 int spdk_nvme_ocssd_ctrlr_cmd_geometry(struct spdk_nvme_ctrlr *ctrlr, uint32_t nsid, 45 void *payload, uint32_t payload_size, 46 spdk_nvme_cmd_cb cb_fn, void *cb_arg); 47 48 /** 49 * \brief Submits a vector reset command to the specified NVMe namespace. 50 * 51 * \param ns NVMe namespace to submit the command 52 * \param qpair I/O queue pair to submit the request 53 * \param lba_list an array of LBAs for processing. 54 * LBAs must correspond to the start of chunks to reset. 55 * Must be allocated through spdk_dma_malloc() or its variants 56 * \param num_lbas number of LBAs stored in lba_list 57 * \param chunk_info an array of chunk info on DMA-able memory 58 * \param cb_fn callback function to invoke when the I/O is completed 59 * \param cb_arg argument to pass to the callback function 60 * 61 * \return 0 if successfully submitted, ENOMEM if an nvme_request 62 * structure cannot be allocated for the I/O request 63 */ 64 int spdk_nvme_ocssd_ns_cmd_vector_reset(struct spdk_nvme_ns *ns, 65 struct spdk_nvme_qpair *qpair, 66 uint64_t *lba_list, uint32_t num_lbas, 67 struct spdk_ocssd_chunk_information_entry *chunk_info, 68 spdk_nvme_cmd_cb cb_fn, void *cb_arg); 69 70 /** 71 * \brief Submits a vector write command to the specified NVMe namespace. 72 * 73 * \param ns NVMe namespace to submit the command 74 * \param qpair I/O queue pair to submit the request 75 * \param buffer virtual address pointer to the data payload 76 * \param lba_list an array of LBAs for processing. 77 * Must be allocated through spdk_dma_malloc() or its variants 78 * \param num_lbas number of LBAs stored in lba_list 79 * \param cb_fn callback function to invoke when the I/O is completed 80 * \param cb_arg argument to pass to the callback function 81 * \param io_flags set flags, defined by the SPDK_OCSSD_IO_FLAGS_* entries 82 * in spdk/nvme_ocssd_spec.h, for this I/O. 83 * 84 * \return 0 if successfully submitted, ENOMEM if an nvme_request 85 * structure cannot be allocated for the I/O request 86 */ 87 int spdk_nvme_ocssd_ns_cmd_vector_write(struct spdk_nvme_ns *ns, 88 struct spdk_nvme_qpair *qpair, 89 void *buffer, 90 uint64_t *lba_list, uint32_t num_lbas, 91 spdk_nvme_cmd_cb cb_fn, void *cb_arg, 92 uint32_t io_flags); 93 94 /** 95 * \brief Submits a vector write command to the specified NVMe namespace. 96 * 97 * \param ns NVMe namespace to submit the command 98 * \param qpair I/O queue pair to submit the request 99 * \param buffer virtual address pointer to the data payload 100 * \param metadata virtual address pointer to the metadata payload, the length 101 * of metadata is specified by spdk_nvme_ns_get_md_size() 102 * \param lba_list an array of LBAs for processing. 103 * Must be allocated through spdk_dma_malloc() or its variants 104 * \param num_lbas number of LBAs stored in lba_list 105 * \param cb_fn callback function to invoke when the I/O is completed 106 * \param cb_arg argument to pass to the callback function 107 * \param io_flags set flags, defined by the SPDK_OCSSD_IO_FLAGS_* entries 108 * in spdk/nvme_ocssd_spec.h, for this I/O. 109 * 110 * \return 0 if successfully submitted, ENOMEM if an nvme_request 111 * structure cannot be allocated for the I/O request 112 */ 113 int spdk_nvme_ocssd_ns_cmd_vector_write_with_md(struct spdk_nvme_ns *ns, 114 struct spdk_nvme_qpair *qpair, 115 void *buffer, void *metadata, 116 uint64_t *lba_list, uint32_t num_lbas, 117 spdk_nvme_cmd_cb cb_fn, void *cb_arg, 118 uint32_t io_flags); 119 120 /** 121 * \brief Submits a vector read command to the specified NVMe namespace. 122 * 123 * \param ns NVMe namespace to submit the command 124 * \param qpair I/O queue pair to submit the request 125 * \param buffer virtual address pointer to the data payload 126 * \param lba_list an array of LBAs for processing. 127 * Must be allocated through spdk_dma_malloc() or its variants 128 * \param num_lbas number of LBAs stored in lba_list 129 * \param cb_fn callback function to invoke when the I/O is completed 130 * \param cb_arg argument to pass to the callback function 131 * \param io_flags set flags, defined by the SPDK_OCSSD_IO_FLAGS_* entries 132 * in spdk/nvme_ocssd_spec.h, for this I/O. 133 * 134 * \return 0 if successfully submitted, ENOMEM if an nvme_request 135 * structure cannot be allocated for the I/O request 136 */ 137 int spdk_nvme_ocssd_ns_cmd_vector_read(struct spdk_nvme_ns *ns, 138 struct spdk_nvme_qpair *qpair, 139 void *buffer, 140 uint64_t *lba_list, uint32_t num_lbas, 141 spdk_nvme_cmd_cb cb_fn, void *cb_arg, 142 uint32_t io_flags); 143 144 /** 145 * \brief Submits a vector read command to the specified NVMe namespace. 146 * 147 * \param ns NVMe namespace to submit the command 148 * \param qpair I/O queue pair to submit the request 149 * \param buffer virtual address pointer to the data payload 150 * \param metadata virtual address pointer to the metadata payload, the length 151 * of metadata is specified by spdk_nvme_ns_get_md_size() 152 * \param lba_list an array of LBAs for processing. 153 * Must be allocated through spdk_dma_malloc() or its variants 154 * \param num_lbas number of LBAs stored in lba_list 155 * \param cb_fn callback function to invoke when the I/O is completed 156 * \param cb_arg argument to pass to the callback function 157 * \param io_flags set flags, defined by the SPDK_OCSSD_IO_FLAGS_* entries 158 * in spdk/nvme_ocssd_spec.h, for this I/O. 159 * 160 * \return 0 if successfully submitted, ENOMEM if an nvme_request 161 * structure cannot be allocated for the I/O request 162 */ 163 int spdk_nvme_ocssd_ns_cmd_vector_read_with_md(struct spdk_nvme_ns *ns, 164 struct spdk_nvme_qpair *qpair, 165 void *buffer, void *metadata, 166 uint64_t *lba_list, uint32_t num_lbas, 167 spdk_nvme_cmd_cb cb_fn, void *cb_arg, 168 uint32_t io_flags); 169 170 /** 171 * \brief Submits a vector copy command to the specified NVMe namespace. 172 * 173 * \param ns NVMe namespace to submit the command 174 * \param qpair I/O queue pair to submit the request 175 * \param dst_lba_list an array of destination LBAs for processing. 176 * Must be allocated through spdk_dma_malloc() or its variants 177 * \param src_lba_list an array of source LBAs for processing. 178 * Must be allocated through spdk_dma_malloc() or its variants 179 * \param num_lbas number of LBAs stored in src_lba_list and dst_lba_list 180 * \param cb_fn callback function to invoke when the I/O is completed 181 * \param cb_arg argument to pass to the callback function 182 * \param io_flags set flags, defined by the SPDK_OCSSD_IO_FLAGS_* entries 183 * in spdk/nvme_ocssd_spec.h, for this I/O. 184 * 185 * \return 0 if successfully submitted, ENOMEM if an nvme_request 186 * structure cannot be allocated for the I/O request 187 */ 188 int spdk_nvme_ocssd_ns_cmd_vector_copy(struct spdk_nvme_ns *ns, 189 struct spdk_nvme_qpair *qpair, 190 uint64_t *dst_lba_list, uint64_t *src_lba_list, 191 uint32_t num_lbas, 192 spdk_nvme_cmd_cb cb_fn, void *cb_arg, 193 uint32_t io_flags); 194 195 #ifdef __cplusplus 196 } 197 #endif 198 199 #endif 200