LCOV - code coverage report
Current view: top level - include/spdk - nvme.h (source / functions) Hit Total Coverage
Test: ut_cov_unit.info Lines: 2 2 100.0 %
Date: 2024-12-14 20:55:11 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /*   SPDX-License-Identifier: BSD-3-Clause
       2             :  *   Copyright (C) 2015 Intel Corporation. All rights reserved.
       3             :  *   Copyright (c) 2019-2021 Mellanox Technologies LTD. All rights reserved.
       4             :  *   Copyright (c) 2021-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
       5             :  *   Copyright (c) 2023 Samsung Electronics Co., Ltd. All rights reserved.
       6             :  */
       7             : 
       8             : /** \file
       9             :  * NVMe driver public API
      10             :  */
      11             : 
      12             : #ifndef SPDK_NVME_H
      13             : #define SPDK_NVME_H
      14             : 
      15             : #include "spdk/stdinc.h"
      16             : 
      17             : #ifdef __cplusplus
      18             : extern "C" {
      19             : #endif
      20             : 
      21             : #include "spdk/dma.h"
      22             : #include "spdk/env.h"
      23             : #include "spdk/keyring.h"
      24             : #include "spdk/nvme_spec.h"
      25             : #include "spdk/nvmf_spec.h"
      26             : #include "spdk/util.h"
      27             : 
      28             : #define SPDK_NVME_TRANSPORT_NAME_FC             "FC"
      29             : #define SPDK_NVME_TRANSPORT_NAME_PCIE           "PCIE"
      30             : #define SPDK_NVME_TRANSPORT_NAME_RDMA           "RDMA"
      31             : #define SPDK_NVME_TRANSPORT_NAME_TCP            "TCP"
      32             : #define SPDK_NVME_TRANSPORT_NAME_VFIOUSER       "VFIOUSER"
      33             : #define SPDK_NVME_TRANSPORT_NAME_CUSTOM         "CUSTOM"
      34             : 
      35             : #define SPDK_NVMF_PRIORITY_MAX_LEN 4
      36             : 
      37             : /**
      38             :  * Opaque handle to a controller. Returned by spdk_nvme_probe()'s attach_cb.
      39             :  */
      40             : struct spdk_nvme_ctrlr;
      41             : 
      42             : /**
      43             :  * NVMe controller initialization options.
      44             :  *
      45             :  * A pointer to this structure will be provided for each probe callback from spdk_nvme_probe() to
      46             :  * allow the user to request non-default options, and the actual options enabled on the controller
      47             :  * will be provided during the attach callback.
      48             :  */
      49             : struct spdk_nvme_ctrlr_opts {
      50             :         /**
      51             :          * Number of I/O queues to request (used to set Number of Queues feature)
      52             :          */
      53             :         uint32_t num_io_queues;
      54             : 
      55             :         /**
      56             :          * Enable submission queue in controller memory buffer
      57             :          */
      58             :         bool use_cmb_sqs;
      59             : 
      60             :         /**
      61             :          * Don't initiate shutdown processing
      62             :          */
      63             :         bool no_shn_notification;
      64             : 
      65             :         /**
      66             :          * Enable interrupts for completion notification. This is only supported within a primary
      67             :          * SPDK process, and if enabled SPDK will not support secondary processes.
      68             :          */
      69             :         bool enable_interrupts;
      70             : 
      71             :         /* Hole at byte 7. */
      72             :         uint8_t reserved7;
      73             : 
      74             :         /**
      75             :          * Type of arbitration mechanism
      76             :          */
      77             :         enum spdk_nvme_cc_ams arb_mechanism;
      78             : 
      79             :         /**
      80             :          * Maximum number of commands that the controller may launch at one time.  The
      81             :          * value is expressed as a power of two, valid values are from 0-7, and 7 means
      82             :          * unlimited.
      83             :          */
      84             :         uint8_t arbitration_burst;
      85             : 
      86             :         /**
      87             :          * Number of commands that may be executed from the low priority queue in each
      88             :          * arbitration round.  This field is only valid when arb_mechanism is set to
      89             :          * SPDK_NVME_CC_AMS_WRR (weighted round robin).
      90             :          */
      91             :         uint8_t low_priority_weight;
      92             : 
      93             :         /**
      94             :          * Number of commands that may be executed from the medium priority queue in each
      95             :          * arbitration round.  This field is only valid when arb_mechanism is set to
      96             :          * SPDK_NVME_CC_AMS_WRR (weighted round robin).
      97             :          */
      98             :         uint8_t medium_priority_weight;
      99             : 
     100             :         /**
     101             :          * Number of commands that may be executed from the high priority queue in each
     102             :          * arbitration round.  This field is only valid when arb_mechanism is set to
     103             :          * SPDK_NVME_CC_AMS_WRR (weighted round robin).
     104             :          */
     105             :         uint8_t high_priority_weight;
     106             : 
     107             :         /**
     108             :          * Keep alive timeout in milliseconds (0 = disabled).
     109             :          *
     110             :          * The NVMe library will set the Keep Alive Timer feature to this value and automatically
     111             :          * send Keep Alive commands as needed.  The library user must call
     112             :          * spdk_nvme_ctrlr_process_admin_completions() periodically to ensure Keep Alive commands
     113             :          * are sent.
     114             :          */
     115             :         uint32_t keep_alive_timeout_ms;
     116             : 
     117             :         /**
     118             :          * Specify the retry number when there is issue with the transport
     119             :          */
     120             :         uint8_t transport_retry_count;
     121             : 
     122             :         /* Hole at bytes 21-23. */
     123             :         uint8_t reserved21[3];
     124             : 
     125             :         /**
     126             :          * The queue depth of each NVMe I/O queue.
     127             :          */
     128             :         uint32_t io_queue_size;
     129             : 
     130             :         /**
     131             :          * The host NQN to use when connecting to NVMe over Fabrics controllers.
     132             :          *
     133             :          * If empty, a default value will be used.
     134             :          */
     135             :         char hostnqn[SPDK_NVMF_NQN_MAX_LEN + 1];
     136             : 
     137             :         /**
     138             :          * The number of requests to allocate for each NVMe I/O queue.
     139             :          *
     140             :          * This should be at least as large as io_queue_size.
     141             :          *
     142             :          * A single I/O may allocate more than one request, since splitting may be necessary to
     143             :          * conform to the device's maximum transfer size, PRP list compatibility requirements,
     144             :          * or driver-assisted striping.
     145             :          */
     146             :         uint32_t io_queue_requests;
     147             : 
     148             :         /**
     149             :          * Source address for NVMe-oF connections.
     150             :          * Set src_addr and src_svcid to empty strings if no source address should be
     151             :          * specified.
     152             :          */
     153             :         char src_addr[SPDK_NVMF_TRADDR_MAX_LEN + 1];
     154             : 
     155             :         /**
     156             :          * Source service ID (port) for NVMe-oF connections.
     157             :          * Set src_addr and src_svcid to empty strings if no source address should be
     158             :          * specified.
     159             :          */
     160             :         char src_svcid[SPDK_NVMF_TRSVCID_MAX_LEN + 1];
     161             : 
     162             :         /**
     163             :          * The host identifier to use when connecting to controllers with 64-bit host ID support.
     164             :          *
     165             :          * Set to all zeroes to specify that no host ID should be provided to the controller.
     166             :          */
     167             :         uint8_t host_id[8];
     168             : 
     169             :         /**
     170             :          * The host identifier to use when connecting to controllers with extended (128-bit) host ID support.
     171             :          *
     172             :          * Set to all zeroes to specify that no host ID should be provided to the controller.
     173             :          */
     174             :         uint8_t extended_host_id[16];
     175             : 
     176             :         /* Hole at bytes 570-571. */
     177             :         uint8_t reserved570[2];
     178             : 
     179             :         /**
     180             :          * The I/O command set to select.
     181             :          *
     182             :          * If the requested command set is not supported, the controller
     183             :          * initialization process will not proceed. By default, the NVM
     184             :          * command set is used.
     185             :          */
     186             :         enum spdk_nvme_cc_css command_set;
     187             : 
     188             :         /**
     189             :          * Admin commands timeout in milliseconds (0 = no timeout).
     190             :          *
     191             :          * The timeout value is used for admin commands submitted internally
     192             :          * by the nvme driver during initialization, before the user is able
     193             :          * to call spdk_nvme_ctrlr_register_timeout_callback(). By default,
     194             :          * this is set to 120 seconds, users can change it in the probing
     195             :          * callback.
     196             :          */
     197             :         uint32_t admin_timeout_ms;
     198             : 
     199             :         /**
     200             :          * It is used for TCP transport.
     201             :          *
     202             :          * Set to true, means having header digest for the header in the NVMe/TCP PDU
     203             :          */
     204             :         bool header_digest;
     205             : 
     206             :         /**
     207             :          * It is used for TCP transport.
     208             :          *
     209             :          * Set to true, means having data digest for the data in the NVMe/TCP PDU
     210             :          */
     211             :         bool data_digest;
     212             : 
     213             :         /**
     214             :          * Disable logging of requests that are completed with error status.
     215             :          *
     216             :          * Defaults to 'false' (errors are logged).
     217             :          */
     218             :         bool disable_error_logging;
     219             : 
     220             :         /**
     221             :          * It is used for both RDMA & TCP transport
     222             :          * Specify the transport ACK timeout. The value should be in range 0-31 where 0 means
     223             :          * use driver-specific default value.
     224             :          * RDMA: The value is applied to each qpair
     225             :          * and affects the time that qpair waits for transport layer acknowledgement
     226             :          * until it retransmits a packet. The value should be chosen empirically
     227             :          * to meet the needs of a particular application. A low value means less time
     228             :          * the qpair waits for ACK which can increase the number of retransmissions.
     229             :          * A large value can increase the time the connection is closed.
     230             :          * The value of ACK timeout is calculated according to the formula
     231             :          * 4.096 * 2^(transport_ack_timeout) usec.
     232             :          * TCP: The value is applied to each qpair
     233             :          * and affects the time that qpair waits for transport layer acknowledgement
     234             :          * until connection is closed forcefully.
     235             :          * The value of ACK timeout is calculated according to the formula
     236             :          * 2^(transport_ack_timeout) msec.
     237             :          */
     238             :         uint8_t transport_ack_timeout;
     239             : 
     240             :         /**
     241             :          * The queue depth of NVMe Admin queue.
     242             :          */
     243             :         uint16_t admin_queue_size;
     244             : 
     245             :         /* Hole at bytes 586-591. */
     246             :         uint8_t reserved586[6];
     247             : 
     248             :         /**
     249             :          * The size of spdk_nvme_ctrlr_opts according to the caller of this library is used for ABI
     250             :          * compatibility.  The library uses this field to know how many fields in this
     251             :          * structure are valid. And the library will populate any remaining fields with default values.
     252             :          */
     253             :         size_t opts_size;
     254             : 
     255             :         /**
     256             :          * The amount of time to spend before timing out during fabric connect on qpairs associated with
     257             :          * this controller in microseconds.
     258             :          */
     259             :         uint64_t fabrics_connect_timeout_us;
     260             : 
     261             :         /**
     262             :          * Disable reading ANA log page. The upper layer should reading ANA log page instead
     263             :          * if set to true.
     264             :          *
     265             :          * Default is `false` (ANA log page is read).
     266             :          */
     267             :         bool disable_read_ana_log_page;
     268             : 
     269             :         /* Hole at bytes 610-616. */
     270             :         uint8_t reserved610[7];
     271             : 
     272             :         /**
     273             :          * Disable reading CHANGED_NS_LIST log page in response to an NS_ATTR_CHANGED AEN
     274             :          * The upper layer should reading CHANGED_NS_LIST log page instead if set to true.
     275             :          *
     276             :          * Default is `false` (CHANGED_NS_LIST log page is read).
     277             :          */
     278             :         uint8_t disable_read_changed_ns_list_log_page;
     279             : 
     280             :         /* Hole at bytes 617-816. */
     281             :         uint8_t reserved617[200];
     282             : 
     283             :         /**
     284             :          * It is used for RDMA transport.
     285             :          *
     286             :          * Set the IP protocol type of service value for RDMA transport. Default is 0, which means that the TOS will not be set.
     287             :          */
     288             :         uint8_t transport_tos;
     289             : 
     290             :         /**
     291             :          * Pre-shared key for NVMe/TCP's TLS connection.
     292             :          */
     293             :         struct spdk_key *tls_psk;
     294             : 
     295             :         /**
     296             :          * In-band authentication DH-HMAC-CHAP host key.
     297             :          */
     298             :         struct spdk_key *dhchap_key;
     299             : 
     300             :         /**
     301             :          * In-band authentication DH-HMAC-CHAP controller key.
     302             :          */
     303             :         struct spdk_key *dhchap_ctrlr_key;
     304             : 
     305             :         /**
     306             :          * Allowed digests in in-band authentication.  Each bit corresponds to one of the
     307             :          * spdk_nvmf_dhchap_hash values.
     308             :          */
     309             :         uint32_t dhchap_digests;
     310             : 
     311             :         /**
     312             :          * Allowed Diffie-Hellman groups in in-band authentication.  Each bit corresponds to one of
     313             :          * the spdk_nvmf_dhchap_dhgroup values.
     314             :          */
     315             :         uint32_t dhchap_dhgroups;
     316             : };
     317             : SPDK_STATIC_ASSERT(sizeof(struct spdk_nvme_ctrlr_opts) == 856, "Incorrect size");
     318             : 
     319             : /**
     320             :  * NVMe acceleration operation callback.
     321             :  *
     322             :  * \param cb_arg The user provided arg which is passed to the corresponding accelerated function call
     323             :  * defined in struct spdk_nvme_accel_fn_table.
     324             :  * \param status 0 if it completed successfully, or negative errno if it failed.
     325             :  */
     326             : typedef void (*spdk_nvme_accel_completion_cb)(void *cb_arg, int status);
     327             : 
     328             : /**
     329             :  * Completion callback for a single operation in a sequence.
     330             :  *
     331             :  * \param cb_arg Argument provided by the user when appending an operation to a sequence.
     332             :  */
     333             : typedef void (*spdk_nvme_accel_step_cb)(void *cb_arg);
     334             : 
     335             : /**
     336             :  * Function table for the NVMe accelerator device.
     337             :  *
     338             :  * This table provides a set of APIs to allow user to leverage
     339             :  * accelerator functions.
     340             :  */
     341             : struct spdk_nvme_accel_fn_table {
     342             :         /**
     343             :          * The size of spdk_nvme_accel_fun_table according to the caller of
     344             :          * this library is used for ABI compatibility. The library uses this
     345             :          * field to know how many fields in this structure are valid.
     346             :          * And the library will populate any remaining fields with default values.
     347             :          * Newly added fields should be put at the end of the struct.
     348             :          */
     349             :         size_t table_size;
     350             : 
     351             :         /* Hole at bytes 8-15. */
     352             :         uint8_t reserved8[8];
     353             : 
     354             :         /** Finish an accel sequence */
     355             :         void (*finish_sequence)(void *seq, spdk_nvme_accel_completion_cb cb_fn, void *cb_arg);
     356             : 
     357             :         /** Reverse an accel sequence */
     358             :         void (*reverse_sequence)(void *seq);
     359             : 
     360             :         /** Abort an accel sequence */
     361             :         void (*abort_sequence)(void *seq);
     362             : 
     363             :         /** Append a crc32c operation to a sequence */
     364             :         int (*append_crc32c)(void *ctx, void **seq, uint32_t *dst, struct iovec *iovs, uint32_t iovcnt,
     365             :                              struct spdk_memory_domain *memory_domain, void *domain_ctx,
     366             :                              uint32_t seed, spdk_nvme_accel_step_cb cb_fn, void *cb_arg);
     367             : 
     368             :         /** Append a copy operation to a sequence */
     369             :         int (*append_copy)(void *ctx, void **seq, struct iovec *dst_iovs, uint32_t dst_iovcnt,
     370             :                            struct spdk_memory_domain *dst_domain, void *dst_domain_ctx,
     371             :                            struct iovec *src_iovs, uint32_t src_iovcnt,
     372             :                            struct spdk_memory_domain *src_domain, void *src_domain_ctx,
     373             :                            spdk_nvme_accel_step_cb cb_fn, void *cb_arg);
     374             : };
     375             : 
     376             : /**
     377             :  * Indicate whether a ctrlr handle is associated with a Discovery controller.
     378             :  *
     379             :  * \param ctrlr Opaque handle to NVMe controller.
     380             :  *
     381             :  * \return true if a discovery controller, else false.
     382             :  */
     383             : bool spdk_nvme_ctrlr_is_discovery(struct spdk_nvme_ctrlr *ctrlr);
     384             : 
     385             : /**
     386             :  * Indicate whether a ctrlr handle is associated with a fabrics controller.
     387             :  *
     388             :  * \param ctrlr Opaque handle to NVMe controller.
     389             :  *
     390             :  * \return true if a fabrics controller, else false.
     391             :  */
     392             : bool spdk_nvme_ctrlr_is_fabrics(struct spdk_nvme_ctrlr *ctrlr);
     393             : 
     394             : /**
     395             :  * Get the default options for the creation of a specific NVMe controller.
     396             :  *
     397             :  * \param[out] opts Will be filled with the default option.
     398             :  * \param opts_size Must be set to sizeof(struct spdk_nvme_ctrlr_opts).
     399             :  */
     400             : void spdk_nvme_ctrlr_get_default_ctrlr_opts(struct spdk_nvme_ctrlr_opts *opts,
     401             :                 size_t opts_size);
     402             : 
     403             : /*
     404             :  * Get the options in use for a given controller.
     405             :  *
     406             :  * \param ctrlr Opaque handle to NVMe controller.
     407             :  */
     408             : const struct spdk_nvme_ctrlr_opts *spdk_nvme_ctrlr_get_opts(struct spdk_nvme_ctrlr *ctrlr);
     409             : 
     410             : /**
     411             :  * Reason for qpair disconnect at the transport layer.
     412             :  *
     413             :  * NONE implies that the qpair is still connected while UNKNOWN means that the
     414             :  * qpair is disconnected, but the cause was not apparent.
     415             :  */
     416             : enum spdk_nvme_qp_failure_reason {
     417             :         SPDK_NVME_QPAIR_FAILURE_NONE = 0,
     418             :         SPDK_NVME_QPAIR_FAILURE_LOCAL,
     419             :         SPDK_NVME_QPAIR_FAILURE_REMOTE,
     420             :         SPDK_NVME_QPAIR_FAILURE_UNKNOWN,
     421             :         SPDK_NVME_QPAIR_FAILURE_RESET,
     422             : };
     423             : 
     424             : typedef enum spdk_nvme_qp_failure_reason spdk_nvme_qp_failure_reason;
     425             : 
     426             : /**
     427             :  * NVMe library transports
     428             :  *
     429             :  * NOTE: These are mapped directly to the NVMe over Fabrics TRTYPE values, except for PCIe,
     430             :  * which is a special case since NVMe over Fabrics does not define a TRTYPE for local PCIe.
     431             :  *
     432             :  * Currently, this uses 256 for PCIe which is intentionally outside of the 8-bit range of TRTYPE.
     433             :  * If the NVMe-oF specification ever defines a PCIe TRTYPE, this should be updated.
     434             :  */
     435             : enum spdk_nvme_transport_type {
     436             :         /**
     437             :          * PCIe Transport (locally attached devices)
     438             :          */
     439             :         SPDK_NVME_TRANSPORT_PCIE = 256,
     440             : 
     441             :         /**
     442             :          * RDMA Transport (RoCE, iWARP, etc.)
     443             :          */
     444             :         SPDK_NVME_TRANSPORT_RDMA = SPDK_NVMF_TRTYPE_RDMA,
     445             : 
     446             :         /**
     447             :          * Fibre Channel (FC) Transport
     448             :          */
     449             :         SPDK_NVME_TRANSPORT_FC = SPDK_NVMF_TRTYPE_FC,
     450             : 
     451             :         /**
     452             :          * TCP Transport
     453             :          */
     454             :         SPDK_NVME_TRANSPORT_TCP = SPDK_NVMF_TRTYPE_TCP,
     455             : 
     456             :         /**
     457             :          * Custom VFIO User Transport (Not spec defined)
     458             :          */
     459             :         SPDK_NVME_TRANSPORT_VFIOUSER = 1024,
     460             : 
     461             :         /**
     462             :          * Custom Transport (Not spec defined)
     463             :          */
     464             :         SPDK_NVME_TRANSPORT_CUSTOM = 4096,
     465             : 
     466             :         /**
     467             :          * Custom Fabric Transport (Not spec defined)
     468             :          */
     469             :         SPDK_NVME_TRANSPORT_CUSTOM_FABRICS = 4097,
     470             : };
     471             : 
     472         291 : static inline bool spdk_nvme_trtype_is_fabrics(enum spdk_nvme_transport_type trtype)
     473             : {
     474             :         /* We always define non-fabrics trtypes outside of the 8-bit range
     475             :          * of NVMe-oF trtype.
     476             :          */
     477         291 :         return trtype <= UINT8_MAX || trtype == SPDK_NVME_TRANSPORT_CUSTOM_FABRICS;
     478             : }
     479             : 
     480             : /* typedef added for coding style reasons */
     481             : typedef enum spdk_nvme_transport_type spdk_nvme_transport_type_t;
     482             : 
     483             : /**
     484             :  * NVMe transport identifier.
     485             :  *
     486             :  * This identifies a unique endpoint on an NVMe fabric.
     487             :  *
     488             :  * A string representation of a transport ID may be converted to this type using
     489             :  * spdk_nvme_transport_id_parse().
     490             :  */
     491             : struct spdk_nvme_transport_id {
     492             :         /**
     493             :          * NVMe transport string.
     494             :          */
     495             :         char trstring[SPDK_NVMF_TRSTRING_MAX_LEN + 1];
     496             : 
     497             :         /**
     498             :          * NVMe transport type.
     499             :          */
     500             :         enum spdk_nvme_transport_type trtype;
     501             : 
     502             :         /**
     503             :          * Address family of the transport address.
     504             :          *
     505             :          * For PCIe, this value is ignored.
     506             :          */
     507             :         enum spdk_nvmf_adrfam adrfam;
     508             : 
     509             :         /**
     510             :          * Transport address of the NVMe-oF endpoint. For transports which use IP
     511             :          * addressing (e.g. RDMA), this should be an IP address. For PCIe, this
     512             :          * can either be a zero length string (the whole bus) or a PCI address
     513             :          * in the format DDDD:BB:DD.FF or DDDD.BB.DD.FF. For FC the string is
     514             :          * formatted as: nn-0xWWNN:pn-0xWWPN” where WWNN is the Node_Name of the
     515             :          * target NVMe_Port and WWPN is the N_Port_Name of the target NVMe_Port.
     516             :          */
     517             :         char traddr[SPDK_NVMF_TRADDR_MAX_LEN + 1];
     518             : 
     519             :         /**
     520             :          * Transport service id of the NVMe-oF endpoint.  For transports which use
     521             :          * IP addressing (e.g. RDMA), this field should be the port number. For PCIe,
     522             :          * and FC this is always a zero length string.
     523             :          */
     524             :         char trsvcid[SPDK_NVMF_TRSVCID_MAX_LEN + 1];
     525             : 
     526             :         /**
     527             :          * Subsystem NQN of the NVMe over Fabrics endpoint. May be a zero length string.
     528             :          */
     529             :         char subnqn[SPDK_NVMF_NQN_MAX_LEN + 1];
     530             : 
     531             :         /**
     532             :          * The Transport connection priority of the NVMe-oF endpoint. Currently this is
     533             :          * only supported by posix based sock implementation on Kernel TCP stack. More
     534             :          * information of this field can be found from the socket(7) man page.
     535             :          */
     536             :         int priority;
     537             : };
     538             : 
     539             : /**
     540             :  * NVMe host identifier
     541             :  *
     542             :  * Used for defining the host identity for an NVMe-oF connection.
     543             :  *
     544             :  * In terms of configuration, this object can be considered a subtype of TransportID
     545             :  * Please see etc/spdk/nvmf.conf.in for more details.
     546             :  *
     547             :  * A string representation of this type may be converted to this type using
     548             :  * spdk_nvme_host_id_parse().
     549             :  */
     550             : struct spdk_nvme_host_id {
     551             :         /**
     552             :          * Transport address to be used by the host when connecting to the NVMe-oF endpoint.
     553             :          * May be an IP address or a zero length string for transports which
     554             :          * use IP addressing (e.g. RDMA).
     555             :          * For PCIe and FC this is always a zero length string.
     556             :          */
     557             :         char hostaddr[SPDK_NVMF_TRADDR_MAX_LEN + 1];
     558             : 
     559             :         /**
     560             :          * Transport service ID used by the host when connecting to the NVMe.
     561             :          * May be a port number or a zero length string for transports which
     562             :          * use IP addressing (e.g. RDMA).
     563             :          * For PCIe and FC this is always a zero length string.
     564             :          */
     565             :         char hostsvcid[SPDK_NVMF_TRSVCID_MAX_LEN + 1];
     566             : };
     567             : 
     568             : struct spdk_nvme_rdma_device_stat {
     569             :         const char *name;
     570             :         uint64_t polls;
     571             :         uint64_t idle_polls;
     572             :         uint64_t completions;
     573             :         uint64_t queued_requests;
     574             :         uint64_t total_send_wrs;
     575             :         uint64_t send_doorbell_updates;
     576             :         uint64_t total_recv_wrs;
     577             :         uint64_t recv_doorbell_updates;
     578             : };
     579             : 
     580             : struct spdk_nvme_pcie_stat {
     581             :         uint64_t polls;
     582             :         uint64_t idle_polls;
     583             :         uint64_t completions;
     584             :         uint64_t cq_mmio_doorbell_updates;
     585             :         uint64_t cq_shadow_doorbell_updates;
     586             :         uint64_t submitted_requests;
     587             :         uint64_t queued_requests;
     588             :         uint64_t sq_mmio_doorbell_updates;
     589             :         uint64_t sq_shadow_doorbell_updates;
     590             : };
     591             : 
     592             : struct spdk_nvme_tcp_stat {
     593             :         uint64_t polls;
     594             :         uint64_t idle_polls;
     595             :         uint64_t socket_completions;
     596             :         uint64_t nvme_completions;
     597             :         uint64_t submitted_requests;
     598             :         uint64_t queued_requests;
     599             : };
     600             : 
     601             : struct spdk_nvme_transport_poll_group_stat {
     602             :         spdk_nvme_transport_type_t trtype;
     603             :         union {
     604             :                 struct {
     605             :                         uint32_t num_devices;
     606             :                         struct spdk_nvme_rdma_device_stat *device_stats;
     607             :                 } rdma;
     608             :                 struct spdk_nvme_pcie_stat pcie;
     609             :                 struct spdk_nvme_tcp_stat tcp;
     610             :         };
     611             : };
     612             : 
     613             : struct spdk_nvme_poll_group_stat {
     614             :         uint32_t num_transports;
     615             :         struct spdk_nvme_transport_poll_group_stat **transport_stat;
     616             : };
     617             : 
     618             : /*
     619             :  * Controller support flags
     620             :  *
     621             :  * Used for identifying if the controller supports these flags.
     622             :  */
     623             : enum spdk_nvme_ctrlr_flags {
     624             :         SPDK_NVME_CTRLR_SGL_SUPPORTED                   = 1 << 0, /**< SGL is supported */
     625             :         SPDK_NVME_CTRLR_SECURITY_SEND_RECV_SUPPORTED    = 1 << 1, /**< security send/receive is supported */
     626             :         SPDK_NVME_CTRLR_WRR_SUPPORTED                   = 1 << 2, /**< Weighted Round Robin is supported */
     627             :         SPDK_NVME_CTRLR_COMPARE_AND_WRITE_SUPPORTED     = 1 << 3, /**< Compare and write fused operations supported */
     628             :         SPDK_NVME_CTRLR_SGL_REQUIRES_DWORD_ALIGNMENT    = 1 << 4, /**< Dword alignment is required for SGL */
     629             :         SPDK_NVME_CTRLR_ZONE_APPEND_SUPPORTED           = 1 << 5, /**< Zone Append is supported (within Zoned Namespaces) */
     630             :         SPDK_NVME_CTRLR_DIRECTIVES_SUPPORTED            = 1 << 6, /**< The Directives is supported */
     631             :         SPDK_NVME_CTRLR_MPTR_SGL_SUPPORTED              = 1 << 7, /**< MPTR containing SGL descriptor is supported */
     632             :         SPDK_NVME_CTRLR_ACCEL_SEQUENCE_SUPPORTED        = 1 << 8, /**< Support for sending I/O requests with accel sequence */
     633             : };
     634             : 
     635             : /**
     636             :  * Structure with optional IO request parameters
     637             :  */
     638             : struct spdk_nvme_ns_cmd_ext_io_opts {
     639             :         /** size of this structure in bytes, use SPDK_SIZEOF(opts, last_member) to obtain it */
     640             :         size_t size;
     641             :         /** Memory domain which describes data payload in IO request. The controller must support
     642             :          * the corresponding memory domain type, refer to \ref spdk_nvme_ctrlr_get_memory_domains */
     643             :         struct spdk_memory_domain *memory_domain;
     644             :         /** User context to be passed to memory domain operations */
     645             :         void *memory_domain_ctx;
     646             :         /** Flags for this IO, defined in nvme_spec.h */
     647             :         uint32_t io_flags;
     648             :         /* Hole at bytes 28-31. */
     649             :         uint8_t reserved28[4];
     650             :         /** Virtual address pointer to the metadata payload, the length of metadata is specified by \ref spdk_nvme_ns_get_md_size */
     651             :         void *metadata;
     652             :         /** Application tag mask to use end-to-end protection information. */
     653             :         uint16_t apptag_mask;
     654             :         /** Application tag to use end-to-end protection information. */
     655             :         uint16_t apptag;
     656             :         /** Command dword 13 specific field. */
     657             :         uint32_t cdw13;
     658             :         /** Accel sequence (only valid if SPDK_NVME_CTRLR_ACCEL_SEQUENCE_SUPPORTED is set and the
     659             :          *  qpair is part of a poll group).
     660             :          */
     661             :         void *accel_sequence;
     662             : };
     663             : SPDK_STATIC_ASSERT(sizeof(struct spdk_nvme_ns_cmd_ext_io_opts) == 56, "Incorrect size");
     664             : 
     665             : /**
     666             :  * Parse the string representation of a transport ID.
     667             :  *
     668             :  * \param trid Output transport ID structure (must be allocated and initialized by caller).
     669             :  * \param str Input string representation of a transport ID to parse.
     670             :  *
     671             :  * str must be a zero-terminated C string containing one or more key:value pairs
     672             :  * separated by whitespace.
     673             :  *
     674             :  * Key          | Value
     675             :  * ------------ | -----
     676             :  * trtype       | Transport type (e.g. PCIe, RDMA)
     677             :  * adrfam       | Address family (e.g. IPv4, IPv6)
     678             :  * traddr       | Transport address (e.g. 0000:04:00.0 for PCIe, 192.168.100.8 for RDMA, or WWN for FC)
     679             :  * trsvcid      | Transport service identifier (e.g. 4420)
     680             :  * subnqn       | Subsystem NQN
     681             :  *
     682             :  * Unspecified fields of trid are left unmodified, so the caller must initialize
     683             :  * trid (for example, memset() to 0) before calling this function.
     684             :  *
     685             :  * \return 0 if parsing was successful and trid is filled out, or negated errno
     686             :  * values on failure.
     687             :  */
     688             : int spdk_nvme_transport_id_parse(struct spdk_nvme_transport_id *trid, const char *str);
     689             : 
     690             : 
     691             : /**
     692             :  * Fill in the trtype and trstring fields of this trid based on a known transport type.
     693             :  *
     694             :  * \param trid The trid to fill out.
     695             :  * \param trtype The transport type to use for filling the trid fields. Only valid for
     696             :  * transport types referenced in the NVMe-oF spec.
     697             :  */
     698             : void spdk_nvme_trid_populate_transport(struct spdk_nvme_transport_id *trid,
     699             :                                        enum spdk_nvme_transport_type trtype);
     700             : 
     701             : /**
     702             :  * Parse the string representation of a host ID.
     703             :  *
     704             :  * \param hostid Output host ID structure (must be allocated and initialized by caller).
     705             :  * \param str Input string representation of a transport ID to parse (hostid is a sub-configuration).
     706             :  *
     707             :  * str must be a zero-terminated C string containing one or more key:value pairs
     708             :  * separated by whitespace.
     709             :  *
     710             :  * Key            | Value
     711             :  * -------------- | -----
     712             :  * hostaddr       | Transport address (e.g. 192.168.100.8 for RDMA)
     713             :  * hostsvcid      | Transport service identifier (e.g. 4420)
     714             :  *
     715             :  * Unspecified fields of trid are left unmodified, so the caller must initialize
     716             :  * hostid (for example, memset() to 0) before calling this function.
     717             :  *
     718             :  * This function should not be used with Fiber Channel or PCIe as these transports
     719             :  * do not require host information for connections.
     720             :  *
     721             :  * \return 0 if parsing was successful and hostid is filled out, or negated errno
     722             :  * values on failure.
     723             :  */
     724             : int spdk_nvme_host_id_parse(struct spdk_nvme_host_id *hostid, const char *str);
     725             : 
     726             : /**
     727             :  * Parse the string representation of a transport ID transport type into the trid struct.
     728             :  *
     729             :  * \param trid The trid to write to
     730             :  * \param trstring Input string representation of transport type (e.g. "PCIe", "RDMA").
     731             :  *
     732             :  * \return 0 if parsing was successful and trtype is filled out, or negated errno
     733             :  * values if the provided string was an invalid transport string.
     734             :  */
     735             : int spdk_nvme_transport_id_populate_trstring(struct spdk_nvme_transport_id *trid,
     736             :                 const char *trstring);
     737             : 
     738             : /**
     739             :  * Parse the string representation of a transport ID transport type.
     740             :  *
     741             :  * \param trtype Output transport type (allocated by caller).
     742             :  * \param str Input string representation of transport type (e.g. "PCIe", "RDMA").
     743             :  *
     744             :  * \return 0 if parsing was successful and trtype is filled out, or negated errno
     745             :  * values on failure.
     746             :  */
     747             : int spdk_nvme_transport_id_parse_trtype(enum spdk_nvme_transport_type *trtype, const char *str);
     748             : 
     749             : /**
     750             :  * Look up the string representation of a transport ID transport type.
     751             :  *
     752             :  * \param trtype Transport type to convert.
     753             :  *
     754             :  * \return static string constant describing trtype, or NULL if trtype not found.
     755             :  */
     756             : const char *spdk_nvme_transport_id_trtype_str(enum spdk_nvme_transport_type trtype);
     757             : 
     758             : /**
     759             :  * Look up the string representation of a transport ID address family.
     760             :  *
     761             :  * \param adrfam Address family to convert.
     762             :  *
     763             :  * \return static string constant describing adrfam, or NULL if adrfam not found.
     764             :  */
     765             : const char *spdk_nvme_transport_id_adrfam_str(enum spdk_nvmf_adrfam adrfam);
     766             : 
     767             : /**
     768             :  * Parse the string representation of a transport ID address family.
     769             :  *
     770             :  * \param adrfam Output address family (allocated by caller).
     771             :  * \param str Input string representation of address family (e.g. "IPv4", "IPv6").
     772             :  *
     773             :  * \return 0 if parsing was successful and adrfam is filled out, or negated errno
     774             :  * values on failure.
     775             :  */
     776             : int spdk_nvme_transport_id_parse_adrfam(enum spdk_nvmf_adrfam *adrfam, const char *str);
     777             : 
     778             : /**
     779             :  * Compare two transport IDs.
     780             :  *
     781             :  * The result of this function may be used to sort transport IDs in a consistent
     782             :  * order; however, the comparison result is not guaranteed to be consistent across
     783             :  * library versions.
     784             :  *
     785             :  * This function uses a case-insensitive comparison for string fields, but it does
     786             :  * not otherwise normalize the transport ID. It is the caller's responsibility to
     787             :  * provide the transport IDs in a consistent format.
     788             :  *
     789             :  * \param trid1 First transport ID to compare.
     790             :  * \param trid2 Second transport ID to compare.
     791             :  *
     792             :  * \return 0 if trid1 == trid2, less than 0 if trid1 < trid2, greater than 0 if
     793             :  * trid1 > trid2.
     794             :  */
     795             : int spdk_nvme_transport_id_compare(const struct spdk_nvme_transport_id *trid1,
     796             :                                    const struct spdk_nvme_transport_id *trid2);
     797             : 
     798             : /**
     799             :  * Parse the string representation of PI check settings (prchk:guard|reftag)
     800             :  *
     801             :  * \param prchk_flags Output PI check flags.
     802             :  * \param str Input string representation of PI check settings.
     803             :  *
     804             :  * \return 0 if parsing was successful and prchk_flags is set, or negated errno
     805             :  * values on failure.
     806             :  */
     807             : int spdk_nvme_prchk_flags_parse(uint32_t *prchk_flags, const char *str);
     808             : 
     809             : /**
     810             :  * Look up the string representation of PI check settings  (prchk:guard|reftag)
     811             :  *
     812             :  * \param prchk_flags PI check flags to convert.
     813             :  *
     814             :  * \return static string constant describing PI check settings. If prchk_flags is 0,
     815             :  * NULL is returned.
     816             :  */
     817             : const char *spdk_nvme_prchk_flags_str(uint32_t prchk_flags);
     818             : 
     819             : /**
     820             :  * Determine whether the NVMe library can handle a specific NVMe over Fabrics
     821             :  * transport type.
     822             :  *
     823             :  * \param trtype NVMe over Fabrics transport type to check.
     824             :  *
     825             :  * \return true if trtype is supported or false if it is not supported or if
     826             :  * SPDK_NVME_TRANSPORT_CUSTOM is supplied as trtype since it can represent multiple
     827             :  * transports.
     828             :  */
     829             : bool spdk_nvme_transport_available(enum spdk_nvme_transport_type trtype);
     830             : 
     831             : /**
     832             :  * Determine whether the NVMe library can handle a specific NVMe over Fabrics
     833             :  * transport type.
     834             :  *
     835             :  * \param transport_name Name of the NVMe over Fabrics transport type to check.
     836             :  *
     837             :  * \return true if transport_name is supported or false if it is not supported.
     838             :  */
     839             : bool spdk_nvme_transport_available_by_name(const char *transport_name);
     840             : 
     841             : /**
     842             :  * Callback for spdk_nvme_probe() enumeration.
     843             :  *
     844             :  * \param cb_ctx Opaque value passed to spdk_nvme_probe().
     845             :  * \param trid NVMe transport identifier.
     846             :  * \param opts NVMe controller initialization options. This structure will be
     847             :  * populated with the default values on entry, and the user callback may update
     848             :  * any options to request a different value. The controller may not support all
     849             :  * requested parameters, so the final values will be provided during the attach
     850             :  * callback.
     851             :  *
     852             :  * \return true to attach to this device.
     853             :  */
     854             : typedef bool (*spdk_nvme_probe_cb)(void *cb_ctx, const struct spdk_nvme_transport_id *trid,
     855             :                                    struct spdk_nvme_ctrlr_opts *opts);
     856             : 
     857             : /**
     858             :  * Callback for spdk_nvme_attach() to report a device that has been attached to
     859             :  * the userspace NVMe driver.
     860             :  *
     861             :  * \param cb_ctx Opaque value passed to spdk_nvme_attach_cb().
     862             :  * \param trid NVMe transport identifier.
     863             :  * \param ctrlr Opaque handle to NVMe controller.
     864             :  * \param opts NVMe controller initialization options that were actually used.
     865             :  * Options may differ from the requested options from the attach call depending
     866             :  * on what the controller supports.
     867             :  */
     868             : typedef void (*spdk_nvme_attach_cb)(void *cb_ctx, const struct spdk_nvme_transport_id *trid,
     869             :                                     struct spdk_nvme_ctrlr *ctrlr,
     870             :                                     const struct spdk_nvme_ctrlr_opts *opts);
     871             : 
     872             : /**
     873             :  * Callback for spdk_nvme_probe*_ext() to report a device that has been probed but
     874             :  * unable to attach to the userspace NVMe driver.
     875             :  *
     876             :  * \param cb_ctx Opaque value passed to spdk_nvme_probe*_ext().
     877             :  * \param trid NVMe transport identifier.
     878             :  * \param rc Negative error code that provides information about the failure.
     879             :  */
     880             : typedef void (*spdk_nvme_attach_fail_cb)(void *cb_ctx, const struct spdk_nvme_transport_id *trid,
     881             :                 int rc);
     882             : 
     883             : /**
     884             :  * Callback for spdk_nvme_remove() to report that a device attached to the userspace
     885             :  * NVMe driver has been removed from the system.
     886             :  *
     887             :  * The controller will remain in a failed state (any new I/O submitted will fail).
     888             :  *
     889             :  * The controller must be detached from the userspace driver by calling spdk_nvme_detach()
     890             :  * once the controller is no longer in use. It is up to the library user to ensure
     891             :  * that no other threads are using the controller before calling spdk_nvme_detach().
     892             :  *
     893             :  * \param cb_ctx Opaque value passed to spdk_nvme_remove_cb().
     894             :  * \param ctrlr NVMe controller instance that was removed.
     895             :  */
     896             : typedef void (*spdk_nvme_remove_cb)(void *cb_ctx, struct spdk_nvme_ctrlr *ctrlr);
     897             : 
     898             : typedef bool (*spdk_nvme_pcie_hotplug_filter_cb)(const struct spdk_pci_addr *addr);
     899             : 
     900             : /**
     901             :  * Register the associated function to allow filtering of hot-inserted PCIe SSDs.
     902             :  *
     903             :  * If an application is using spdk_nvme_probe() to detect hot-inserted SSDs,
     904             :  * this function may be used to register a function to filter those SSDs.
     905             :  * If the filter function returns true, the nvme library will notify the SPDK
     906             :  * env layer to allow probing of the device.
     907             :  *
     908             :  * Registering a filter function is optional.  If none is registered, the nvme
     909             :  * library will allow probing of all hot-inserted SSDs.
     910             :  *
     911             :  * \param filter_cb Filter function callback routine
     912             :  */
     913             : void
     914             : spdk_nvme_pcie_set_hotplug_filter(spdk_nvme_pcie_hotplug_filter_cb filter_cb);
     915             : 
     916             : /**
     917             :  * Enumerate the bus indicated by the transport ID and attach the userspace NVMe
     918             :  * driver to each device found if desired.
     919             :  *
     920             :  * This function is not thread safe and should only be called from one thread at
     921             :  * a time while no other threads are actively using any NVMe devices.
     922             :  *
     923             :  * If called from a secondary process, only devices that have been attached to
     924             :  * the userspace driver in the primary process will be probed.
     925             :  *
     926             :  * If called more than once, only devices that are not already attached to the
     927             :  * SPDK NVMe driver will be reported.
     928             :  *
     929             :  * To stop using the the controller and release its associated resources,
     930             :  * call spdk_nvme_detach() with the spdk_nvme_ctrlr instance from the attach_cb()
     931             :  * function.
     932             :  *
     933             :  * \param trid The transport ID indicating which bus to enumerate. If the trtype
     934             :  * is PCIe or trid is NULL, this will scan the local PCIe bus. If the trtype is
     935             :  * fabrics (e.g. RDMA, TCP), the traddr and trsvcid must point at the location of an
     936             :  * NVMe-oF discovery service.
     937             :  * \param cb_ctx Opaque value which will be passed back in cb_ctx parameter of
     938             :  * the callbacks.
     939             :  * \param probe_cb will be called once per NVMe device found in the system.
     940             :  * \param attach_cb will be called for devices for which probe_cb returned true
     941             :  * once that NVMe controller has been attached to the userspace driver.
     942             :  * \param remove_cb will be called for devices that were attached in a previous
     943             :  * spdk_nvme_probe() call but are no longer attached to the system. Optional;
     944             :  * specify NULL if removal notices are not desired.
     945             :  *
     946             :  * \return 0 on success, -1 on failure.
     947             :  */
     948             : int spdk_nvme_probe(const struct spdk_nvme_transport_id *trid,
     949             :                     void *cb_ctx,
     950             :                     spdk_nvme_probe_cb probe_cb,
     951             :                     spdk_nvme_attach_cb attach_cb,
     952             :                     spdk_nvme_remove_cb remove_cb);
     953             : 
     954             : /**
     955             :  * Enumerate the bus indicated by the transport ID and attach the userspace NVMe
     956             :  * driver to each device found if desired.
     957             :  *
     958             :  * This works just the same as spdk_nvme_probe(), except that it calls attach_fail_cb
     959             :  * for devices that are probed but unabled to attach.
     960             :  *
     961             :  * \param trid The transport ID indicating which bus to enumerate. If the trtype
     962             :  * is PCIe or trid is NULL, this will scan the local PCIe bus. If the trtype is
     963             :  * fabrics (e.g. RDMA, TCP), the traddr and trsvcid must point at the location of an
     964             :  * NVMe-oF discovery service.
     965             :  * \param cb_ctx Opaque value which will be passed back in cb_ctx parameter of
     966             :  * the callbacks.
     967             :  * \param probe_cb will be called once per NVMe device found in the system.
     968             :  * \param attach_cb will be called for devices for which probe_cb returned true
     969             :  * once that NVMe controller has been attached to the userspace driver.
     970             :  * \param attach_fail_cb will be called for devices which probe_cb returned true
     971             :  * but failed to attach to the userspace driver.
     972             :  * \param remove_cb will be called for devices that were attached in a previous
     973             :  * spdk_nvme_probe() call but are no longer attached to the system. Optional;
     974             :  * specify NULL if removal notices are not desired.
     975             :  *
     976             :  * \return 0 on success, -1 on failure.
     977             :  */
     978             : int spdk_nvme_probe_ext(const struct spdk_nvme_transport_id *trid,
     979             :                         void *cb_ctx,
     980             :                         spdk_nvme_probe_cb probe_cb,
     981             :                         spdk_nvme_attach_cb attach_cb,
     982             :                         spdk_nvme_attach_fail_cb attach_fail_cb,
     983             :                         spdk_nvme_remove_cb remove_cb);
     984             : 
     985             : /**
     986             :  * Connect the NVMe driver to the device located at the given transport ID.
     987             :  *
     988             :  * This function is not thread safe and should only be called from one thread at
     989             :  * a time while no other threads are actively using this NVMe device.
     990             :  *
     991             :  * If called from a secondary process, only the device that has been attached to
     992             :  * the userspace driver in the primary process will be connected.
     993             :  *
     994             :  * If connecting to multiple controllers, it is suggested to use spdk_nvme_probe()
     995             :  * and filter the requested controllers with the probe callback. For PCIe controllers,
     996             :  * spdk_nvme_probe() will be more efficient since the controller resets will happen
     997             :  * in parallel.
     998             :  *
     999             :  * To stop using the the controller and release its associated resources, call
    1000             :  * spdk_nvme_detach() with the spdk_nvme_ctrlr instance returned by this function.
    1001             :  *
    1002             :  * \param trid The transport ID indicating which device to connect. If the trtype
    1003             :  * is PCIe, this will connect the local PCIe bus. If the trtype is fabrics
    1004             :  * (e.g. RDMA, TCP), the traddr and trsvcid must point at the location of an NVMe-oF
    1005             :  * service.
    1006             :  * \param opts NVMe controller initialization options. Default values will be used
    1007             :  * if the user does not specify the options. The controller may not support all
    1008             :  * requested parameters.
    1009             :  * \param opts_size Must be set to sizeof(struct spdk_nvme_ctrlr_opts), or 0 if
    1010             :  * opts is NULL.
    1011             :  *
    1012             :  * \return pointer to the connected NVMe controller or NULL if there is any failure.
    1013             :  *
    1014             :  */
    1015             : struct spdk_nvme_ctrlr *spdk_nvme_connect(const struct spdk_nvme_transport_id *trid,
    1016             :                 const struct spdk_nvme_ctrlr_opts *opts,
    1017             :                 size_t opts_size);
    1018             : 
    1019             : struct spdk_nvme_probe_ctx;
    1020             : 
    1021             : /**
    1022             :  * Connect the NVMe driver to the device located at the given transport ID.
    1023             :  *
    1024             :  * The function will return a probe context on success, controller associates with
    1025             :  * the context is not ready for use, user must call spdk_nvme_probe_poll_async()
    1026             :  * until spdk_nvme_probe_poll_async() returns 0.
    1027             :  *
    1028             :  * \param trid The transport ID indicating which device to connect. If the trtype
    1029             :  * is PCIe, this will connect the local PCIe bus. If the trtype is fabrics
    1030             :  * (e.g. RDMA, TCP), the traddr and trsvcid must point at the location of an NVMe-oF
    1031             :  * service.
    1032             :  * \param opts NVMe controller initialization options. Default values will be used
    1033             :  * if the user does not specify the options. The controller may not support all
    1034             :  * requested parameters.
    1035             :  * \param attach_cb will be called once the NVMe controller has been attached
    1036             :  * to the userspace driver.
    1037             :  *
    1038             :  * \return probe context on success, NULL on failure.
    1039             :  *
    1040             :  */
    1041             : struct spdk_nvme_probe_ctx *spdk_nvme_connect_async(const struct spdk_nvme_transport_id *trid,
    1042             :                 const struct spdk_nvme_ctrlr_opts *opts,
    1043             :                 spdk_nvme_attach_cb attach_cb);
    1044             : 
    1045             : /**
    1046             :  * Probe and add controllers to the probe context list.
    1047             :  *
    1048             :  * Users must call spdk_nvme_probe_poll_async() to initialize
    1049             :  * controllers in the probe context list to the READY state.
    1050             :  *
    1051             :  * \param trid The transport ID indicating which bus to enumerate. If the trtype
    1052             :  * is PCIe or trid is NULL, this will scan the local PCIe bus. If the trtype is
    1053             :  * fabrics (e.g. RDMA, TCP), the traddr and trsvcid must point at the location of an
    1054             :  * NVMe-oF discovery service.
    1055             :  * \param cb_ctx Opaque value which will be passed back in cb_ctx parameter of
    1056             :  * the callbacks.
    1057             :  * \param probe_cb will be called once per NVMe device found in the system.
    1058             :  * \param attach_cb will be called for devices for which probe_cb returned true
    1059             :  * once that NVMe controller has been attached to the userspace driver.
    1060             :  * \param remove_cb will be called for devices that were attached in a previous
    1061             :  * spdk_nvme_probe() call but are no longer attached to the system. Optional;
    1062             :  * specify NULL if removal notices are not desired.
    1063             :  *
    1064             :  * \return probe context on success, NULL on failure.
    1065             :  */
    1066             : struct spdk_nvme_probe_ctx *spdk_nvme_probe_async(const struct spdk_nvme_transport_id *trid,
    1067             :                 void *cb_ctx,
    1068             :                 spdk_nvme_probe_cb probe_cb,
    1069             :                 spdk_nvme_attach_cb attach_cb,
    1070             :                 spdk_nvme_remove_cb remove_cb);
    1071             : 
    1072             : /**
    1073             :  * Probe and add controllers to the probe context list.
    1074             :  *
    1075             :  * Users must call spdk_nvme_probe_poll_async() to initialize
    1076             :  * controllers in the probe context list to the READY state.
    1077             :  *
    1078             :  * This works just the same as spdk_nvme_probe_async(), except that it calls
    1079             :  * attach_fail_cb for devices that are probed but unabled to attach.
    1080             :  *
    1081             :  * \param trid The transport ID indicating which bus to enumerate. If the trtype
    1082             :  * is PCIe or trid is NULL, this will scan the local PCIe bus. If the trtype is
    1083             :  * fabrics (e.g. RDMA, TCP), the traddr and trsvcid must point at the location of an
    1084             :  * NVMe-oF discovery service.
    1085             :  * \param cb_ctx Opaque value which will be passed back in cb_ctx parameter of
    1086             :  * the callbacks.
    1087             :  * \param probe_cb will be called once per NVMe device found in the system.
    1088             :  * \param attach_cb will be called for devices for which probe_cb returned true
    1089             :  * once that NVMe controller has been attached to the userspace driver.
    1090             :  * \param attach_fail_cb will be called for devices which probe_cb returned true
    1091             :  * but failed to attach to the userspace driver.
    1092             :  * \param remove_cb will be called for devices that were attached in a previous
    1093             :  * spdk_nvme_probe() call but are no longer attached to the system. Optional;
    1094             :  * specify NULL if removal notices are not desired.
    1095             :  *
    1096             :  * \return probe context on success, NULL on failure.
    1097             :  */
    1098             : struct spdk_nvme_probe_ctx *spdk_nvme_probe_async_ext(const struct spdk_nvme_transport_id *trid,
    1099             :                 void *cb_ctx,
    1100             :                 spdk_nvme_probe_cb probe_cb,
    1101             :                 spdk_nvme_attach_cb attach_cb,
    1102             :                 spdk_nvme_attach_fail_cb attach_fail_cb,
    1103             :                 spdk_nvme_remove_cb remove_cb);
    1104             : 
    1105             : /**
    1106             :  * Proceed with attaching controllers associated with the probe context.
    1107             :  *
    1108             :  * The probe context is one returned from a previous call to
    1109             :  * spdk_nvme_probe_async().  Users must call this function on the
    1110             :  * probe context until it returns 0.
    1111             :  *
    1112             :  * If any controllers fail to attach, there is no explicit notification.
    1113             :  * Users can detect attachment failure by comparing attach_cb invocations
    1114             :  * with the number of times where the user returned true for the
    1115             :  * probe_cb.
    1116             :  *
    1117             :  * \param probe_ctx Context used to track probe actions.
    1118             :  *
    1119             :  * \return 0 if all probe operations are complete; the probe_ctx
    1120             :  * is also freed and no longer valid.
    1121             :  * \return -EAGAIN if there are still pending probe operations; user must call
    1122             :  * spdk_nvme_probe_poll_async again to continue progress.
    1123             :  */
    1124             : int spdk_nvme_probe_poll_async(struct spdk_nvme_probe_ctx *probe_ctx);
    1125             : 
    1126             : /**
    1127             :  * Detach specified device returned by spdk_nvme_probe()'s attach_cb from the
    1128             :  * NVMe driver.
    1129             :  *
    1130             :  * On success, the spdk_nvme_ctrlr handle is no longer valid.
    1131             :  *
    1132             :  * This function should be called from a single thread while no other threads
    1133             :  * are actively using the NVMe device.
    1134             :  *
    1135             :  * \param ctrlr Opaque handle to NVMe controller.
    1136             :  *
    1137             :  * \return 0 on success, -1 on failure.
    1138             :  */
    1139             : int spdk_nvme_detach(struct spdk_nvme_ctrlr *ctrlr);
    1140             : 
    1141             : struct spdk_nvme_detach_ctx;
    1142             : 
    1143             : /**
    1144             :  * Allocate a context to track detachment of multiple controllers if this call is the
    1145             :  * first successful start of detachment in a sequence, or use the passed context otherwise.
    1146             :  *
    1147             :  * Then, start detaching the specified device returned by spdk_nvme_probe()'s attach_cb
    1148             :  * from the NVMe driver, and append this detachment to the context.
    1149             :  *
    1150             :  * User must call spdk_nvme_detach_poll_async() to complete the detachment.
    1151             :  *
    1152             :  * If the context is not allocated before this call, and if the specified device is detached
    1153             :  * locally from the caller process but any other process still attaches it or failed to be
    1154             :  * detached, context is not allocated.
    1155             :  *
    1156             :  * This function should be called from a single thread while no other threads are
    1157             :  * actively using the NVMe device.
    1158             :  *
    1159             :  * \param ctrlr Opaque handle to NVMe controller.
    1160             :  * \param detach_ctx Reference to the context in a sequence. An new context is allocated
    1161             :  * if this call is the first successful start of detachment in a sequence, or use the
    1162             :  * passed context.
    1163             :  */
    1164             : int spdk_nvme_detach_async(struct spdk_nvme_ctrlr *ctrlr,
    1165             :                            struct spdk_nvme_detach_ctx **detach_ctx);
    1166             : 
    1167             : /**
    1168             :  * Poll detachment of multiple controllers until they complete.
    1169             :  *
    1170             :  * User must call this function until it returns 0.
    1171             :  *
    1172             :  * \param detach_ctx Context to track the detachment.
    1173             :  *
    1174             :  * \return 0 if all detachments complete; the context is also freed and no longer valid.
    1175             :  * \return -EAGAIN if any detachment is still in progress; users must call
    1176             :  * spdk_nvme_detach_poll_async() again to continue progress.
    1177             :  */
    1178             : int spdk_nvme_detach_poll_async(struct spdk_nvme_detach_ctx *detach_ctx);
    1179             : 
    1180             : /**
    1181             :  * Continue calling spdk_nvme_detach_poll_async() internally until it returns 0.
    1182             :  *
    1183             :  * \param detach_ctx Context to track the detachment.
    1184             :  */
    1185             : void spdk_nvme_detach_poll(struct spdk_nvme_detach_ctx *detach_ctx);
    1186             : 
    1187             : /**
    1188             :  * Scan attached controllers for events.
    1189             :  *
    1190             :  * This function lets user act on events such as hot-remove without a need to
    1191             :  * enable hotplug explicitly. Only attached devices will be checked.
    1192             :  *
    1193             :  * \param trid Transport ID.
    1194             :  *
    1195             :  * \returns 0 on success, negative on failure.
    1196             :  */
    1197             : int spdk_nvme_scan_attached(const struct spdk_nvme_transport_id *trid);
    1198             : 
    1199             : /**
    1200             :  * Update the transport ID for a given controller.
    1201             :  *
    1202             :  * This function allows the user to set a new trid for a controller only if the
    1203             :  * controller is failed. The controller's failed state can be obtained from
    1204             :  * spdk_nvme_ctrlr_is_failed(). The controller can also be forced to the failed
    1205             :  * state using spdk_nvme_ctrlr_fail().
    1206             :  *
    1207             :  * This function also requires that the transport type and subnqn of the new trid
    1208             :  * be the same as the old trid.
    1209             :  *
    1210             :  * \param ctrlr Opaque handle to an NVMe controller.
    1211             :  * \param trid The new transport ID.
    1212             :  *
    1213             :  * \return 0 on success, -EINVAL if the trid is invalid,
    1214             :  * -EPERM if the ctrlr is not failed.
    1215             :  */
    1216             : int spdk_nvme_ctrlr_set_trid(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_transport_id *trid);
    1217             : 
    1218             : /**
    1219             :  * Set the remove callback and context to be invoked if the controller is removed.
    1220             :  *
    1221             :  * This will override any remove_cb and/or ctx specified when the controller was
    1222             :  * probed.
    1223             :  *
    1224             :  * This function may only be called from the primary process.  This function has
    1225             :  * no effect if called from a secondary process.
    1226             :  *
    1227             :  * \param ctrlr Opaque handle to an NVMe controller.
    1228             :  * \param remove_cb remove callback
    1229             :  * \param remove_ctx remove callback context
    1230             :  */
    1231             : void spdk_nvme_ctrlr_set_remove_cb(struct spdk_nvme_ctrlr *ctrlr,
    1232             :                                    spdk_nvme_remove_cb remove_cb, void *remove_ctx);
    1233             : 
    1234             : struct spdk_nvme_ctrlr_key_opts {
    1235             :         /** Size of this structure */
    1236             :         size_t size;
    1237             :         /** DH-HMAC-CHAP host key */
    1238             :         struct spdk_key *dhchap_key;
    1239             :         /** DH-HMAC-CHAP controller key */
    1240             :         struct spdk_key *dhchap_ctrlr_key;
    1241             : };
    1242             : 
    1243             : /**
    1244             :  * Set keys for a given NVMe controller.  These keys will override the keys specified in
    1245             :  * `spdk_nvme_ctrlr_opts` when attaching the controller and will be used from now on to authenticate
    1246             :  * all qpairs associated with this controller.
    1247             :  *
    1248             :  * This function only sets the keys, it doesn't force existing qpairs to use them.  To do that,
    1249             :  * users need to call `spdk_nvme_ctrlr_authenticate()` to authenticate the admin queue and
    1250             :  * `spdk_nvme_qpair_authenticate()` to authenticate IO queues.
    1251             :  *
    1252             :  * \param ctrlr NVMe controller.
    1253             :  * \param opts Key options.
    1254             :  *
    1255             :  * \return 0 on success, negative errno on failure.
    1256             :  */
    1257             : int spdk_nvme_ctrlr_set_keys(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_ctrlr_key_opts *opts);
    1258             : 
    1259             : /**
    1260             :  * Perform a full hardware reset of the NVMe controller.
    1261             :  *
    1262             :  * This function should be called from a single thread while no other threads
    1263             :  * are actively using the NVMe device.
    1264             :  *
    1265             :  * Any pointers returned from spdk_nvme_ctrlr_get_ns(), spdk_nvme_ns_get_data(),
    1266             :  * spdk_nvme_zns_ns_get_data(), and spdk_nvme_zns_ctrlr_get_data()
    1267             :  * may be invalidated by calling this function. The number of namespaces as returned
    1268             :  * by spdk_nvme_ctrlr_get_num_ns() may also change.
    1269             :  *
    1270             :  * \param ctrlr Opaque handle to NVMe controller.
    1271             :  *
    1272             :  * \return 0 on success, -1 on failure.
    1273             :  */
    1274             : int spdk_nvme_ctrlr_reset(struct spdk_nvme_ctrlr *ctrlr);
    1275             : 
    1276             : /**
    1277             :  * Disconnect the given NVMe controller.
    1278             :  *
    1279             :  * This function is used as the first operation of a full reset sequence of the given NVMe
    1280             :  * controller. The NVMe controller is ready to reconnect after completing this function.
    1281             :  *
    1282             :  * \param ctrlr Opaque handle to NVMe controller.
    1283             :  *
    1284             :  * \return 0 on success, -EBUSY if controller is already resetting, or -ENXIO if controller
    1285             :  * has been removed.
    1286             :  */
    1287             : int spdk_nvme_ctrlr_disconnect(struct spdk_nvme_ctrlr *ctrlr);
    1288             : 
    1289             : /**
    1290             :  * Start re-enabling the given NVMe controller in a full reset sequence
    1291             :  *
    1292             :  * \param ctrlr Opaque handle to NVMe controller.
    1293             :  */
    1294             : void spdk_nvme_ctrlr_reconnect_async(struct spdk_nvme_ctrlr *ctrlr);
    1295             : 
    1296             : /**
    1297             :  * Proceed with re-enabling the given NVMe controller.
    1298             :  *
    1299             :  * Users must call this function in a full reset sequence until it returns a value other
    1300             :  * than -EAGAIN.
    1301             :  *
    1302             :  * \return 0 if the given NVMe controller is enabled, or -EBUSY if there are still
    1303             :  * pending operations to enable it.
    1304             :  */
    1305             : int spdk_nvme_ctrlr_reconnect_poll_async(struct spdk_nvme_ctrlr *ctrlr);
    1306             : 
    1307             : /**
    1308             :  * Perform a NVMe subsystem reset.
    1309             :  *
    1310             :  * This function should be called from a single thread while no other threads
    1311             :  * are actively using the NVMe device.
    1312             :  * A subsystem reset is typically seen by the OS as a hot remove, followed by a
    1313             :  * hot add event.
    1314             :  *
    1315             :  * Any pointers returned from spdk_nvme_ctrlr_get_ns(), spdk_nvme_ns_get_data(),
    1316             :  * spdk_nvme_zns_ns_get_data(), and spdk_nvme_zns_ctrlr_get_data()
    1317             :  * may be invalidated by calling this function. The number of namespaces as returned
    1318             :  * by spdk_nvme_ctrlr_get_num_ns() may also change.
    1319             :  *
    1320             :  * \param ctrlr Opaque handle to NVMe controller.
    1321             :  *
    1322             :  * \return 0 on success, -1 on failure, -ENOTSUP if subsystem reset is not supported.
    1323             :  */
    1324             : int spdk_nvme_ctrlr_reset_subsystem(struct spdk_nvme_ctrlr *ctrlr);
    1325             : 
    1326             : /**
    1327             :  * Fail the given NVMe controller.
    1328             :  *
    1329             :  * This function gives the application the opportunity to fail a controller
    1330             :  * at will. When a controller is failed, any calls to process completions or
    1331             :  * submit I/O on qpairs associated with that controller will fail with an error
    1332             :  * code of -ENXIO.
    1333             :  * The controller can only be taken from the failed state by
    1334             :  * calling spdk_nvme_ctrlr_reset. After the controller has been successfully
    1335             :  * reset, any I/O pending when the controller was moved to failed will be
    1336             :  * aborted back to the application and can be resubmitted. I/O can then resume.
    1337             :  *
    1338             :  * \param ctrlr Opaque handle to an NVMe controller.
    1339             :  */
    1340             : void spdk_nvme_ctrlr_fail(struct spdk_nvme_ctrlr *ctrlr);
    1341             : 
    1342             : /**
    1343             :  * This function returns the failed status of a given controller.
    1344             :  *
    1345             :  * \param ctrlr Opaque handle to an NVMe controller.
    1346             :  *
    1347             :  * \return True if the controller is failed, false otherwise.
    1348             :  */
    1349             : bool spdk_nvme_ctrlr_is_failed(struct spdk_nvme_ctrlr *ctrlr);
    1350             : 
    1351             : /**
    1352             :  * Get the identify controller data as defined by the NVMe specification.
    1353             :  *
    1354             :  * This function is thread safe and can be called at any point while the controller
    1355             :  * is attached to the SPDK NVMe driver.
    1356             :  *
    1357             :  * \param ctrlr Opaque handle to NVMe controller.
    1358             :  *
    1359             :  * \return pointer to the identify controller data.
    1360             :  */
    1361             : const struct spdk_nvme_ctrlr_data *spdk_nvme_ctrlr_get_data(struct spdk_nvme_ctrlr *ctrlr);
    1362             : 
    1363             : /**
    1364             :  * Get the NVMe controller CSTS (Status) register.
    1365             :  *
    1366             :  * \param ctrlr Opaque handle to NVMe controller.
    1367             :  *
    1368             :  * \return the NVMe controller CSTS (Status) register.
    1369             :  */
    1370             : union spdk_nvme_csts_register spdk_nvme_ctrlr_get_regs_csts(struct spdk_nvme_ctrlr *ctrlr);
    1371             : 
    1372             : /**
    1373             :  * Get the NVMe controller CC (Configuration) register.
    1374             :  *
    1375             :  * \param ctrlr Opaque handle to NVMe controller.
    1376             :  *
    1377             :  * \return the NVMe controller CC (Configuration) register.
    1378             :  */
    1379             : union spdk_nvme_cc_register spdk_nvme_ctrlr_get_regs_cc(struct spdk_nvme_ctrlr *ctrlr);
    1380             : 
    1381             : /**
    1382             :  * Get the NVMe controller CAP (Capabilities) register.
    1383             :  *
    1384             :  * \param ctrlr Opaque handle to NVMe controller.
    1385             :  *
    1386             :  * \return the NVMe controller CAP (Capabilities) register.
    1387             :  */
    1388             : union spdk_nvme_cap_register spdk_nvme_ctrlr_get_regs_cap(struct spdk_nvme_ctrlr *ctrlr);
    1389             : 
    1390             : /**
    1391             :  * Get the NVMe controller VS (Version) register.
    1392             :  *
    1393             :  * \param ctrlr Opaque handle to NVMe controller.
    1394             :  *
    1395             :  * \return the NVMe controller VS (Version) register.
    1396             :  */
    1397             : union spdk_nvme_vs_register spdk_nvme_ctrlr_get_regs_vs(struct spdk_nvme_ctrlr *ctrlr);
    1398             : 
    1399             : /**
    1400             :  * Get the NVMe controller CMBSZ (Controller Memory Buffer Size) register
    1401             :  *
    1402             :  * \param ctrlr Opaque handle to NVMe controller.
    1403             :  *
    1404             :  * \return the NVMe controller CMBSZ (Controller Memory Buffer Size) register.
    1405             :  */
    1406             : union spdk_nvme_cmbsz_register spdk_nvme_ctrlr_get_regs_cmbsz(struct spdk_nvme_ctrlr *ctrlr);
    1407             : 
    1408             : /**
    1409             :  * Get the NVMe controller PMRCAP (Persistent Memory Region Capabilities) register.
    1410             :  *
    1411             :  * \param ctrlr Opaque handle to NVMe controller.
    1412             :  *
    1413             :  * \return the NVMe controller PMRCAP (Persistent Memory Region Capabilities) register.
    1414             :  */
    1415             : union spdk_nvme_pmrcap_register spdk_nvme_ctrlr_get_regs_pmrcap(struct spdk_nvme_ctrlr *ctrlr);
    1416             : 
    1417             : /**
    1418             :  * Get the NVMe controller BPINFO (Boot Partition Information) register.
    1419             :  *
    1420             :  * \param ctrlr Opaque handle to NVMe controller.
    1421             :  *
    1422             :  * \return the NVMe controller BPINFO (Boot Partition Information) register.
    1423             :  */
    1424             : union spdk_nvme_bpinfo_register spdk_nvme_ctrlr_get_regs_bpinfo(struct spdk_nvme_ctrlr *ctrlr);
    1425             : 
    1426             : /**
    1427             :  * Get the NVMe controller PMR size.
    1428             :  *
    1429             :  * \param ctrlr Opaque handle to NVMe controller.
    1430             :  *
    1431             :  * \return the NVMe controller PMR size or 0 if PMR is not supported.
    1432             :  */
    1433             : uint64_t spdk_nvme_ctrlr_get_pmrsz(struct spdk_nvme_ctrlr *ctrlr);
    1434             : 
    1435             : /**
    1436             :  * Get the maximum NSID value that will ever be used for the given controller
    1437             :  *
    1438             :  * This function is thread safe and can be called at any point while the
    1439             :  * controller is attached to the SPDK NVMe driver.
    1440             :  *
    1441             :  * This is equivalent to calling spdk_nvme_ctrlr_get_data() to get the
    1442             :  * spdk_nvme_ctrlr_data and then reading the nn field.
    1443             :  *
    1444             :  * The NN field in the NVMe specification represents the maximum value that a
    1445             :  * namespace ID can ever have. Prior to NVMe 1.2, this was also the number of
    1446             :  * active namespaces, but from 1.2 onward the list of namespaces may be
    1447             :  * sparsely populated. Unfortunately, the meaning of this field is often
    1448             :  * misinterpreted by drive manufacturers and NVMe-oF implementers so it is
    1449             :  * not considered reliable. AVOID USING THIS FUNCTION WHENEVER POSSIBLE.
    1450             :  *
    1451             :  * \param ctrlr Opaque handle to NVMe controller.
    1452             :  *
    1453             :  * \return the number of namespaces.
    1454             :  */
    1455             : uint32_t spdk_nvme_ctrlr_get_num_ns(struct spdk_nvme_ctrlr *ctrlr);
    1456             : 
    1457             : /**
    1458             :  * Get the PCI device of a given NVMe controller.
    1459             :  *
    1460             :  * This only works for local (PCIe-attached) NVMe controllers; other transports
    1461             :  * will return NULL.
    1462             :  *
    1463             :  * \param ctrlr Opaque handle to NVMe controller.
    1464             :  *
    1465             :  * \return PCI device of the NVMe controller, or NULL if not available.
    1466             :  */
    1467             : struct spdk_pci_device *spdk_nvme_ctrlr_get_pci_device(struct spdk_nvme_ctrlr *ctrlr);
    1468             : 
    1469             : /**
    1470             :  * Get the NUMA ID for the given NVMe controller.
    1471             :  *
    1472             :  * For network-based transports, the NUMA ID will be correlated to the
    1473             :  * network interface.
    1474             :  *
    1475             :  * \param ctrlr Opaque handle to NVMe controller
    1476             :  *
    1477             :  * \return NUMA ID of the NVMe controller, or SPDK_ENV_NUMA_ID_ANY if
    1478             :  *         the NUMA ID is unknown
    1479             :  */
    1480             : int32_t spdk_nvme_ctrlr_get_numa_id(struct spdk_nvme_ctrlr *ctrlr);
    1481             : 
    1482             : /**
    1483             :  * Get the NVMe controller ID for the given controller.
    1484             :  *
    1485             :  * \param ctrlr Opaque handle to NVMe controller.
    1486             :  *
    1487             :  * \return ID of the NVMe controller.
    1488             :  */
    1489             : uint16_t spdk_nvme_ctrlr_get_id(struct spdk_nvme_ctrlr *ctrlr);
    1490             : 
    1491             : /**
    1492             :  * Get the maximum data transfer size of a given NVMe controller.
    1493             :  *
    1494             :  * \param ctrlr Opaque handle to NVMe controller.
    1495             :  *
    1496             :  * \return Maximum data transfer size of the NVMe controller in bytes.
    1497             :  *
    1498             :  * The I/O command helper functions, such as spdk_nvme_ns_cmd_read(), will split
    1499             :  * large I/Os automatically; however, it is up to the user to obey this limit for
    1500             :  * commands submitted with the raw command functions, such as spdk_nvme_ctrlr_cmd_io_raw().
    1501             :  */
    1502             : uint32_t spdk_nvme_ctrlr_get_max_xfer_size(const struct spdk_nvme_ctrlr *ctrlr);
    1503             : 
    1504             : /**
    1505             :  * Get the maximum number of SGEs per request for the given NVMe controller.
    1506             :  *
    1507             :  * Controllers that do not support SGL will return UINT16_MAX.
    1508             :  *
    1509             :  * \param ctrlr Opaque handle to NVMe controller.
    1510             :  *
    1511             :  * \return Maximum number of SGEs per request
    1512             :  */
    1513             : uint16_t spdk_nvme_ctrlr_get_max_sges(const struct spdk_nvme_ctrlr *ctrlr);
    1514             : 
    1515             : /**
    1516             :  * Check whether the nsid is an active nv for the given NVMe controller.
    1517             :  *
    1518             :  * This function is thread safe and can be called at any point while the controller
    1519             :  * is attached to the SPDK NVMe driver.
    1520             :  *
    1521             :  * \param ctrlr Opaque handle to NVMe controller.
    1522             :  * \param nsid Namespace id.
    1523             :  *
    1524             :  * \return true if nsid is an active ns, or false otherwise.
    1525             :  */
    1526             : bool spdk_nvme_ctrlr_is_active_ns(struct spdk_nvme_ctrlr *ctrlr, uint32_t nsid);
    1527             : 
    1528             : /**
    1529             :  * Get the nsid of the first active namespace.
    1530             :  *
    1531             :  * This function is thread safe and can be called at any point while the controller
    1532             :  * is attached to the SPDK NVMe driver.
    1533             :  *
    1534             :  * \param ctrlr Opaque handle to NVMe controller.
    1535             :  *
    1536             :  * \return the nsid of the first active namespace, 0 if there are no active namespaces.
    1537             :  */
    1538             : uint32_t spdk_nvme_ctrlr_get_first_active_ns(struct spdk_nvme_ctrlr *ctrlr);
    1539             : 
    1540             : /**
    1541             :  * Get next active namespace given the previous nsid.
    1542             :  *
    1543             :  * This function is thread safe and can be called at any point while the controller
    1544             :  * is attached to the SPDK NVMe driver.
    1545             :  *
    1546             :  * \param ctrlr Opaque handle to NVMe controller.
    1547             :  * \param prev_nsid Namespace id.
    1548             :  *
    1549             :  * \return a next active namespace given the previous nsid, 0 when there are no
    1550             :  * more active namespaces.
    1551             :  */
    1552             : uint32_t spdk_nvme_ctrlr_get_next_active_ns(struct spdk_nvme_ctrlr *ctrlr, uint32_t prev_nsid);
    1553             : 
    1554             : /**
    1555             :  * Determine if a particular log page is supported by the given NVMe controller.
    1556             :  *
    1557             :  * This function is thread safe and can be called at any point while the controller
    1558             :  * is attached to the SPDK NVMe driver.
    1559             :  *
    1560             :  * \sa spdk_nvme_ctrlr_cmd_get_log_page().
    1561             :  *
    1562             :  * \param ctrlr Opaque handle to NVMe controller.
    1563             :  * \param log_page Log page to query.
    1564             :  *
    1565             :  * \return true if supported, or false otherwise.
    1566             :  */
    1567             : bool spdk_nvme_ctrlr_is_log_page_supported(struct spdk_nvme_ctrlr *ctrlr, uint8_t log_page);
    1568             : 
    1569             : /**
    1570             :  * Determine if a particular feature is supported by the given NVMe controller.
    1571             :  *
    1572             :  * This function is thread safe and can be called at any point while the controller
    1573             :  * is attached to the SPDK NVMe driver.
    1574             :  *
    1575             :  * \sa spdk_nvme_ctrlr_cmd_get_feature().
    1576             :  *
    1577             :  * \param ctrlr Opaque handle to NVMe controller.
    1578             :  * \param feature_code Feature to query.
    1579             :  *
    1580             :  * \return true if supported, or false otherwise.
    1581             :  */
    1582             : bool spdk_nvme_ctrlr_is_feature_supported(struct spdk_nvme_ctrlr *ctrlr, uint8_t feature_code);
    1583             : 
    1584             : /**
    1585             :  * Signature for callback function invoked when a command is completed.
    1586             :  *
    1587             :  * \param ctx Callback context provided when the command was submitted.
    1588             :  * \param cpl Completion queue entry that contains the completion status.
    1589             :  */
    1590             : typedef void (*spdk_nvme_cmd_cb)(void *ctx, const struct spdk_nvme_cpl *cpl);
    1591             : 
    1592             : /**
    1593             :  * Signature for callback function invoked when an asynchronous event request
    1594             :  * command is completed.
    1595             :  *
    1596             :  * \param aer_cb_arg Context specified by spdk_nvme_register_aer_callback().
    1597             :  * \param cpl Completion queue entry that contains the completion status
    1598             :  * of the asynchronous event request that was completed.
    1599             :  */
    1600             : typedef void (*spdk_nvme_aer_cb)(void *aer_cb_arg,
    1601             :                                  const struct spdk_nvme_cpl *cpl);
    1602             : 
    1603             : /**
    1604             :  * Register callback function invoked when an AER command is completed for the
    1605             :  * given NVMe controller.
    1606             :  *
    1607             :  * \param ctrlr Opaque handle to NVMe controller.
    1608             :  * \param aer_cb_fn Callback function invoked when an asynchronous event request
    1609             :  * command is completed.
    1610             :  * \param aer_cb_arg Argument passed to callback function.
    1611             :  */
    1612             : void spdk_nvme_ctrlr_register_aer_callback(struct spdk_nvme_ctrlr *ctrlr,
    1613             :                 spdk_nvme_aer_cb aer_cb_fn,
    1614             :                 void *aer_cb_arg);
    1615             : 
    1616             : /**
    1617             :  * Disable reading the CHANGED_NS_LIST log page for the specified controller.
    1618             :  *
    1619             :  * Applications that register an AER callback may wish to read the CHANGED_NS_LIST
    1620             :  * log page itself, rather than relying on the driver to do it.  Calling this
    1621             :  * function will ensure that the driver does not read this log page if the
    1622             :  * controller returns a NS_ATTR_CHANGED AEN.
    1623             :  *
    1624             :  * Reading of this log page can alternatively be disabled by setting the
    1625             :  * disable_read_changed_ns_list_log_page flag in the spdk_nvme_ctrlr_opts
    1626             :  * when attaching the controller.
    1627             :  *
    1628             :  * \param ctrlr NVMe controller on which to disable the log page read.
    1629             :  */
    1630             : void spdk_nvme_ctrlr_disable_read_changed_ns_list_log_page(struct spdk_nvme_ctrlr *ctrlr);
    1631             : 
    1632             : /**
    1633             :  * Opaque handle to a queue pair.
    1634             :  *
    1635             :  * I/O queue pairs may be allocated using spdk_nvme_ctrlr_alloc_io_qpair().
    1636             :  */
    1637             : struct spdk_nvme_qpair;
    1638             : 
    1639             : /**
    1640             :  * Signature for the callback function invoked when a timeout is detected on a
    1641             :  * request.
    1642             :  *
    1643             :  * For timeouts detected on the admin queue pair, the qpair returned here will
    1644             :  * be NULL.  If the controller has a serious error condition and is unable to
    1645             :  * communicate with driver via completion queue, the controller can set Controller
    1646             :  * Fatal Status field to 1, then reset is required to recover from such error.
    1647             :  * Users may detect Controller Fatal Status when timeout happens.
    1648             :  *
    1649             :  * \param cb_arg Argument passed to callback function.
    1650             :  * \param ctrlr Opaque handle to NVMe controller.
    1651             :  * \param qpair Opaque handle to a queue pair.
    1652             :  * \param cid Command ID.
    1653             :  */
    1654             : typedef void (*spdk_nvme_timeout_cb)(void *cb_arg,
    1655             :                                      struct spdk_nvme_ctrlr *ctrlr,
    1656             :                                      struct spdk_nvme_qpair *qpair,
    1657             :                                      uint16_t cid);
    1658             : 
    1659             : /**
    1660             :  * Register for timeout callback on a controller.
    1661             :  *
    1662             :  * The application can choose to register for timeout callback or not register
    1663             :  * for timeout callback.
    1664             :  *
    1665             :  * \param ctrlr NVMe controller on which to monitor for timeout.
    1666             :  * \param timeout_io_us Timeout value in microseconds for io commands.
    1667             :  * \param timeout_admin_us Timeout value in microseconds for admin commands.
    1668             :  * \param cb_fn A function pointer that points to the callback function.
    1669             :  * \param cb_arg Argument to the callback function.
    1670             :  */
    1671             : void spdk_nvme_ctrlr_register_timeout_callback(struct spdk_nvme_ctrlr *ctrlr,
    1672             :                 uint64_t timeout_io_us, uint64_t timeout_admin_us,
    1673             :                 spdk_nvme_timeout_cb cb_fn, void *cb_arg);
    1674             : 
    1675             : /**
    1676             :  * Signature for the callback function when a
    1677             :  * \ref spdk_nvme_ctrlr_get_discovery_log_page operation is completed.
    1678             :  *
    1679             :  * \param cb_arg Argument passed to callback function.
    1680             :  * \param rc Status of operation. 0 means success, and that the cpl argument is valid.
    1681             :  *           Failure indicated by negative errno value.
    1682             :  * \param cpl NVMe completion status of the operation. NULL if rc != 0. If multiple
    1683             :  *            completions with error status occurred during the operation, the cpl
    1684             :  *            value for the first error will be used here.
    1685             :  * \param log_page Pointer to the full discovery log page. The application is
    1686             :  *                 responsible for freeing this buffer using free().
    1687             :  */
    1688             : typedef void (*spdk_nvme_discovery_cb)(void *cb_arg, int rc,
    1689             :                                        const struct spdk_nvme_cpl *cpl,
    1690             :                                        struct spdk_nvmf_discovery_log_page *log_page);
    1691             : 
    1692             : /**
    1693             :  * Get a full discovery log page from the specified controller.
    1694             :  *
    1695             :  * This function will first read the discovery log header to determine the
    1696             :  * total number of valid entries in the discovery log, then it will allocate
    1697             :  * a buffer to hold the entire log and issue multiple GET_LOG_PAGE commands to
    1698             :  * get all of the entries.
    1699             :  *
    1700             :  * The application is responsible for calling
    1701             :  * \ref spdk_nvme_ctrlr_process_admin_completions to trigger processing of
    1702             :  * completions submitted by this function.
    1703             :  *
    1704             :  * \param ctrlr Pointer to the discovery controller.
    1705             :  * \param cb_fn Function to call when the operation is complete.
    1706             :  * \param cb_arg Argument to pass to cb_fn.
    1707             :  */
    1708             : int spdk_nvme_ctrlr_get_discovery_log_page(struct spdk_nvme_ctrlr *ctrlr,
    1709             :                 spdk_nvme_discovery_cb cb_fn, void *cb_arg);
    1710             : 
    1711             : /**
    1712             :  * NVMe I/O queue pair initialization options.
    1713             :  *
    1714             :  * These options may be passed to spdk_nvme_ctrlr_alloc_io_qpair() to configure queue pair
    1715             :  * options at queue creation time.
    1716             :  *
    1717             :  * The user may retrieve the default I/O queue pair creation options for a controller using
    1718             :  * spdk_nvme_ctrlr_get_default_io_qpair_opts().
    1719             :  */
    1720             : struct spdk_nvme_io_qpair_opts {
    1721             :         /**
    1722             :          * Queue priority for weighted round robin arbitration.  If a different arbitration
    1723             :          * method is in use, pass 0.
    1724             :          */
    1725             :         enum spdk_nvme_qprio qprio;
    1726             : 
    1727             :         /**
    1728             :          * The queue depth of this NVMe I/O queue. Overrides spdk_nvme_ctrlr_opts::io_queue_size.
    1729             :          */
    1730             :         uint32_t io_queue_size;
    1731             : 
    1732             :         /**
    1733             :          * The number of requests to allocate for this NVMe I/O queue.
    1734             :          *
    1735             :          * Overrides spdk_nvme_ctrlr_opts::io_queue_requests.
    1736             :          *
    1737             :          * This should be at least as large as io_queue_size.
    1738             :          *
    1739             :          * A single I/O may allocate more than one request, since splitting may be
    1740             :          * necessary to conform to the device's maximum transfer size, PRP list
    1741             :          * compatibility requirements, or driver-assisted striping.
    1742             :          */
    1743             :         uint32_t io_queue_requests;
    1744             : 
    1745             :         /**
    1746             :          * When submitting I/O via spdk_nvme_ns_read/write and similar functions,
    1747             :          * don't immediately submit it to hardware. Instead, queue up new commands
    1748             :          * and submit them to the hardware inside spdk_nvme_qpair_process_completions().
    1749             :          *
    1750             :          * This results in better batching of I/O commands. Often, it is more efficient
    1751             :          * to submit batches of commands to the underlying hardware than each command
    1752             :          * individually.
    1753             :          *
    1754             :          * This only applies to PCIe and RDMA transports.
    1755             :          *
    1756             :          * The flag was originally named delay_pcie_doorbell. To allow backward compatibility
    1757             :          * both names are kept in unnamed union.
    1758             :          */
    1759             :         union {
    1760             :                 bool delay_cmd_submit;
    1761             :                 bool delay_pcie_doorbell;
    1762             :         };
    1763             : 
    1764             :         /* Hole at bytes 13-15. */
    1765             :         uint8_t reserved13[3];
    1766             : 
    1767             :         /**
    1768             :          * These fields allow specifying the memory buffers for the submission and/or
    1769             :          * completion queues.
    1770             :          * By default, vaddr is set to NULL meaning SPDK will allocate the memory to be used.
    1771             :          * If vaddr is NULL then paddr must be set to 0.
    1772             :          * If vaddr is non-NULL, and paddr is zero, SPDK derives the physical
    1773             :          * address for the NVMe device, in this case the memory must be registered.
    1774             :          * If a paddr value is non-zero, SPDK uses the vaddr and paddr as passed
    1775             :          * SPDK assumes that the memory passed is both virtually and physically
    1776             :          * contiguous.
    1777             :          * If these fields are used, SPDK will NOT impose any restriction
    1778             :          * on the number of elements in the queues.
    1779             :          * The buffer sizes are in number of bytes, and are used to confirm
    1780             :          * that the buffers are large enough to contain the appropriate queue.
    1781             :          * These fields are only used by PCIe attached NVMe devices.  They
    1782             :          * are presently ignored for other transports.
    1783             :          */
    1784             :         struct {
    1785             :                 struct spdk_nvme_cmd *vaddr;
    1786             :                 uint64_t paddr;
    1787             :                 uint64_t buffer_size;
    1788             :         } sq;
    1789             :         struct {
    1790             :                 struct spdk_nvme_cpl *vaddr;
    1791             :                 uint64_t paddr;
    1792             :                 uint64_t buffer_size;
    1793             :         } cq;
    1794             : 
    1795             :         /**
    1796             :          * This flag indicates to the alloc_io_qpair function that it should not perform
    1797             :          * the connect portion on this qpair. This allows the user to add the qpair to a
    1798             :          * poll group and then connect it later.
    1799             :          */
    1800             :         bool create_only;
    1801             : 
    1802             :         /**
    1803             :          * This flag if set to true enables the creation of submission and completion queue
    1804             :          * asynchronously. Default mode is set to false to create io qpair synchronously.
    1805             :          */
    1806             :         bool async_mode;
    1807             : 
    1808             :         /**
    1809             :          * This flag if set to true disables the merging of physically
    1810             :          * contiguous SGL elements. Default mode is set to false to allow
    1811             :          * merging of physically contiguous SGL elements.
    1812             :          */
    1813             :         bool disable_pcie_sgl_merge;
    1814             : 
    1815             :         /* Hole at bytes 67-71. */
    1816             :         uint8_t reserved67[5];
    1817             : 
    1818             :         /**
    1819             :          * The size of spdk_nvme_io_qpair_opts according to the caller of this library is used for
    1820             :          * ABI compatibility. The library uses this field to know how many fields in this structure
    1821             :          * are valid. And the library will populate any remaining fields with default values.
    1822             :          * New added fields should be put at the end of the struct.
    1823             :          */
    1824             :         size_t opts_size;
    1825             : };
    1826             : SPDK_STATIC_ASSERT(sizeof(struct spdk_nvme_io_qpair_opts) == 80, "Incorrect size");
    1827             : 
    1828             : /**
    1829             :  * Get the default options for I/O qpair creation for a specific NVMe controller.
    1830             :  *
    1831             :  * \param ctrlr NVMe controller to retrieve the defaults from.
    1832             :  * \param[out] opts Will be filled with the default options for
    1833             :  * spdk_nvme_ctrlr_alloc_io_qpair().
    1834             :  * \param opts_size Must be set to sizeof(struct spdk_nvme_io_qpair_opts).
    1835             :  */
    1836             : void spdk_nvme_ctrlr_get_default_io_qpair_opts(struct spdk_nvme_ctrlr *ctrlr,
    1837             :                 struct spdk_nvme_io_qpair_opts *opts,
    1838             :                 size_t opts_size);
    1839             : 
    1840             : /**
    1841             :  * Allocate an I/O queue pair (submission and completion queue).
    1842             :  *
    1843             :  * This function by default also performs any connection activities required for
    1844             :  * a newly created qpair. To avoid that behavior, the user should set the create_only
    1845             :  * flag in the opts structure to true.
    1846             :  *
    1847             :  * Each queue pair should only be used from a single thread at a time (mutual
    1848             :  * exclusion must be enforced by the user).
    1849             :  *
    1850             :  * \param ctrlr NVMe controller for which to allocate the I/O queue pair.
    1851             :  * \param opts I/O qpair creation options, or NULL to use the defaults as returned
    1852             :  * by spdk_nvme_ctrlr_get_default_io_qpair_opts().
    1853             :  * \param opts_size Must be set to sizeof(struct spdk_nvme_io_qpair_opts), or 0
    1854             :  * if opts is NULL.
    1855             :  *
    1856             :  * \return a pointer to the allocated I/O queue pair.
    1857             :  */
    1858             : struct spdk_nvme_qpair *spdk_nvme_ctrlr_alloc_io_qpair(struct spdk_nvme_ctrlr *ctrlr,
    1859             :                 const struct spdk_nvme_io_qpair_opts *opts,
    1860             :                 size_t opts_size);
    1861             : 
    1862             : /**
    1863             :  * Connect a newly created I/O qpair.
    1864             :  *
    1865             :  * This function does any connection activities required for a newly created qpair.
    1866             :  * It should be called after spdk_nvme_ctrlr_alloc_io_qpair has been called with the
    1867             :  * create_only flag set to true in the spdk_nvme_io_qpair_opts structure.
    1868             :  *
    1869             :  * This call will fail if performed on a qpair that is already connected.
    1870             :  * For reconnecting qpairs, see spdk_nvme_ctrlr_reconnect_io_qpair.
    1871             :  *
    1872             :  * For fabrics like TCP and RDMA, this function actually sends the commands over the wire
    1873             :  * that connect the qpair. For PCIe, this function performs some internal state machine operations.
    1874             :  *
    1875             :  * \param ctrlr NVMe controller for which to allocate the I/O queue pair.
    1876             :  * \param qpair Opaque handle to the qpair to connect.
    1877             :  *
    1878             :  * return 0 on success or negated errno on failure. Specifically -EISCONN if the qpair is already connected.
    1879             :  *
    1880             :  */
    1881             : int spdk_nvme_ctrlr_connect_io_qpair(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qpair);
    1882             : 
    1883             : /**
    1884             :  * Disconnect the given I/O qpair.
    1885             :  *
    1886             :  * This function must be called from the same thread as spdk_nvme_qpair_process_completions
    1887             :  * and the spdk_nvme_ns_cmd_* functions.
    1888             :  *
    1889             :  * After disconnect, calling spdk_nvme_qpair_process_completions or one of the
    1890             :  * spdk_nvme_ns_cmd* on a qpair will result in a return value of -ENXIO. A
    1891             :  * disconnected qpair may be reconnected with either the spdk_nvme_ctrlr_connect_io_qpair
    1892             :  * or spdk_nvme_ctrlr_reconnect_io_qpair APIs.
    1893             :  *
    1894             :  * \param qpair The qpair to disconnect.
    1895             :  */
    1896             : void spdk_nvme_ctrlr_disconnect_io_qpair(struct spdk_nvme_qpair *qpair);
    1897             : 
    1898             : /**
    1899             :  * Attempt to reconnect the given qpair.
    1900             :  *
    1901             :  * This function is intended to be called on qpairs that have already been connected,
    1902             :  * but have since entered a failed state as indicated by a return value of -ENXIO from
    1903             :  * either spdk_nvme_qpair_process_completions or one of the spdk_nvme_ns_cmd_* functions.
    1904             :  * This function must be called from the same thread as spdk_nvme_qpair_process_completions
    1905             :  * and the spdk_nvme_ns_cmd_* functions.
    1906             :  *
    1907             :  * Calling this function has the same effect as calling spdk_nvme_ctrlr_disconnect_io_qpair
    1908             :  * followed by spdk_nvme_ctrlr_connect_io_qpair.
    1909             :  *
    1910             :  * This function may be called on newly created qpairs, but it does extra checks and attempts
    1911             :  * to disconnect the qpair before connecting it. The recommended API for newly created qpairs
    1912             :  * is spdk_nvme_ctrlr_connect_io_qpair.
    1913             :  *
    1914             :  * \param qpair The qpair to reconnect.
    1915             :  *
    1916             :  * \return 0 on success, or if the qpair was already connected.
    1917             :  * -EAGAIN if the driver was unable to reconnect during this call,
    1918             :  * but the controller is still connected and is either resetting or enabled.
    1919             :  * -ENODEV if the controller is removed. In this case, the controller cannot be recovered
    1920             :  * and the application will have to destroy it and the associated qpairs.
    1921             :  * -ENXIO if the controller is in a failed state but is not yet resetting. In this case,
    1922             :  * the application should call spdk_nvme_ctrlr_reset to reset the entire controller.
    1923             :  */
    1924             : int spdk_nvme_ctrlr_reconnect_io_qpair(struct spdk_nvme_qpair *qpair);
    1925             : 
    1926             : /**
    1927             :  * Opaque extended event handler options.
    1928             :  */
    1929             : struct spdk_event_handler_opts;
    1930             : 
    1931             : /**
    1932             :  * Get file descriptor for the admin queue pair of a controller.
    1933             :  *
    1934             :  * Applications that enable interrupts for completion notification will register and unregister
    1935             :  * interrupt event source on its queue pair file descriptor. This function returns file descriptor
    1936             :  * of the admin queue pair.
    1937             :  * This function also allows the transport layer to fill out event handler opts required by the
    1938             :  * application during interrupt registration phase.
    1939             :  *
    1940             :  * \param ctrlr Controller for which fd has to be fetched.
    1941             :  * \param[out] opts Event handler options to be filled by the transport, or NULL.
    1942             :  *
    1943             :  * \return a valid fd on success, with opts filled out if specified.
    1944             :  * -ENOTSUP if transport does not support fetching fd for this controller.
    1945             :  * -EINVAL if opts is specified, but its size is incorrect.
    1946             :  * -EINVAL if fds are not reserved, -1 if interrupts are not enabled for this controller.
    1947             :  */
    1948             : int spdk_nvme_ctrlr_get_admin_qp_fd(struct spdk_nvme_ctrlr *ctrlr,
    1949             :                                     struct spdk_event_handler_opts *opts);
    1950             : 
    1951             : /**
    1952             :  * Returns the reason the admin qpair for a given controller is disconnected.
    1953             :  *
    1954             :  * \param ctrlr The controller to check.
    1955             :  *
    1956             :  * \return a valid spdk_nvme_qp_failure_reason.
    1957             :  */
    1958             : spdk_nvme_qp_failure_reason spdk_nvme_ctrlr_get_admin_qp_failure_reason(
    1959             :         struct spdk_nvme_ctrlr *ctrlr);
    1960             : 
    1961             : /**
    1962             :  * Free an I/O queue pair that was allocated by spdk_nvme_ctrlr_alloc_io_qpair().
    1963             :  *
    1964             :  * The qpair must not be accessed after calling this function.
    1965             :  *
    1966             :  * \param qpair I/O queue pair to free.
    1967             :  *
    1968             :  * \return 0 on success.  This function will never return any value other than 0.
    1969             :  */
    1970             : int spdk_nvme_ctrlr_free_io_qpair(struct spdk_nvme_qpair *qpair);
    1971             : 
    1972             : /**
    1973             :  * Send the given NVM I/O command, I/O buffers, lists and all to the NVMe controller.
    1974             :  *
    1975             :  * This is a low level interface for submitting I/O commands directly.
    1976             :  *
    1977             :  * This function allows a caller to submit an I/O request that is
    1978             :  * COMPLETELY pre-defined, right down to the "physical" memory buffers.
    1979             :  * It is intended for testing hardware, specifying exact buffer location,
    1980             :  * alignment, and offset.  It also allows for specific choice of PRP
    1981             :  * and SGLs.
    1982             :  *
    1983             :  * The driver sets the CID.  EVERYTHING else is assumed set by the caller.
    1984             :  * Needless to say, this is potentially extremely dangerous for both the host
    1985             :  * (accidental/malicious storage usage/corruption), and the device.
    1986             :  * Thus its intent is for very specific hardware testing and environment
    1987             :  * reproduction.
    1988             :  *
    1989             :  * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
    1990             :  * The user must ensure that only one thread submits I/O on a given qpair at any
    1991             :  * given time.
    1992             :  *
    1993             :  * This function can only be used on PCIe controllers and qpairs.
    1994             :  *
    1995             :  * \param ctrlr Opaque handle to NVMe controller.
    1996             :  * \param qpair I/O qpair to submit command.
    1997             :  * \param cmd NVM I/O command to submit.
    1998             :  * \param cb_fn Callback function invoked when the I/O command completes.
    1999             :  * \param cb_arg Argument passed to callback function.
    2000             :  *
    2001             :  * \return 0 if successfully submitted, negated errnos on the following error conditions:
    2002             :  * -ENOMEM: The request cannot be allocated.
    2003             :  * -ENXIO: The qpair is failed at the transport level.
    2004             :  */
    2005             : 
    2006             : int spdk_nvme_ctrlr_io_cmd_raw_no_payload_build(struct spdk_nvme_ctrlr *ctrlr,
    2007             :                 struct spdk_nvme_qpair *qpair,
    2008             :                 struct spdk_nvme_cmd *cmd,
    2009             :                 spdk_nvme_cmd_cb cb_fn, void *cb_arg);
    2010             : 
    2011             : /**
    2012             :  * Send the given NVM I/O command to the NVMe controller.
    2013             :  *
    2014             :  * This is a low level interface for submitting I/O commands directly. Prefer
    2015             :  * the spdk_nvme_ns_cmd_* functions instead. The validity of the command will
    2016             :  * not be checked!
    2017             :  *
    2018             :  * When constructing the nvme_command it is not necessary to fill out the PRP
    2019             :  * list/SGL or the CID. The driver will handle both of those for you.
    2020             :  *
    2021             :  * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
    2022             :  * The user must ensure that only one thread submits I/O on a given qpair at any
    2023             :  * given time.
    2024             :  *
    2025             :  * \param ctrlr Opaque handle to NVMe controller.
    2026             :  * \param qpair I/O qpair to submit command.
    2027             :  * \param cmd NVM I/O command to submit.
    2028             :  * \param buf Virtual memory address of a single physically contiguous buffer.
    2029             :  * \param len Size of buffer.
    2030             :  * \param cb_fn Callback function invoked when the I/O command completes.
    2031             :  * \param cb_arg Argument passed to callback function.
    2032             :  *
    2033             :  * \return 0 if successfully submitted, negated errnos on the following error conditions:
    2034             :  * -ENOMEM: The request cannot be allocated.
    2035             :  * -ENXIO: The qpair is failed at the transport level.
    2036             :  */
    2037             : int spdk_nvme_ctrlr_cmd_io_raw(struct spdk_nvme_ctrlr *ctrlr,
    2038             :                                struct spdk_nvme_qpair *qpair,
    2039             :                                struct spdk_nvme_cmd *cmd,
    2040             :                                void *buf, uint32_t len,
    2041             :                                spdk_nvme_cmd_cb cb_fn, void *cb_arg);
    2042             : 
    2043             : /**
    2044             :  * Send the given NVM I/O command with metadata to the NVMe controller.
    2045             :  *
    2046             :  * This is a low level interface for submitting I/O commands directly. Prefer
    2047             :  * the spdk_nvme_ns_cmd_* functions instead. The validity of the command will
    2048             :  * not be checked!
    2049             :  *
    2050             :  * When constructing the nvme_command it is not necessary to fill out the PRP
    2051             :  * list/SGL or the CID. The driver will handle both of those for you.
    2052             :  *
    2053             :  * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
    2054             :  * The user must ensure that only one thread submits I/O on a given qpair at any
    2055             :  * given time.
    2056             :  *
    2057             :  * \param ctrlr Opaque handle to NVMe controller.
    2058             :  * \param qpair I/O qpair to submit command.
    2059             :  * \param cmd NVM I/O command to submit.
    2060             :  * \param buf Virtual memory address of a single physically contiguous buffer.
    2061             :  * \param len Size of buffer.
    2062             :  * \param md_buf Virtual memory address of a single physically contiguous metadata
    2063             :  * buffer.
    2064             :  * \param cb_fn Callback function invoked when the I/O command completes.
    2065             :  * \param cb_arg Argument passed to callback function.
    2066             :  *
    2067             :  * \return 0 if successfully submitted, negated errnos on the following error conditions:
    2068             :  * -ENOMEM: The request cannot be allocated.
    2069             :  * -ENXIO: The qpair is failed at the transport level.
    2070             :  */
    2071             : int spdk_nvme_ctrlr_cmd_io_raw_with_md(struct spdk_nvme_ctrlr *ctrlr,
    2072             :                                        struct spdk_nvme_qpair *qpair,
    2073             :                                        struct spdk_nvme_cmd *cmd,
    2074             :                                        void *buf, uint32_t len, void *md_buf,
    2075             :                                        spdk_nvme_cmd_cb cb_fn, void *cb_arg);
    2076             : 
    2077             : /**
    2078             :  * Restart the SGL walk to the specified offset when the command has scattered
    2079             :  * payloads.
    2080             :  *
    2081             :  * \param cb_arg Argument passed to readv/writev.
    2082             :  * \param offset Offset for SGL.
    2083             :  */
    2084             : typedef void (*spdk_nvme_req_reset_sgl_cb)(void *cb_arg, uint32_t offset);
    2085             : 
    2086             : /**
    2087             :  * Fill out *address and *length with the current SGL entry and advance to the
    2088             :  * next entry for the next time the callback is invoked.
    2089             :  *
    2090             :  * The described segment must be physically contiguous.
    2091             :  *
    2092             :  * \param cb_arg Argument passed to readv/writev.
    2093             :  * \param address Virtual address of this segment, a value of UINT64_MAX
    2094             :  * means the segment should be described via Bit Bucket SGL.
    2095             :  * \param length Length of this physical segment.
    2096             :  */
    2097             : typedef int (*spdk_nvme_req_next_sge_cb)(void *cb_arg, void **address,
    2098             :                 uint32_t *length);
    2099             : 
    2100             : /**
    2101             :  * Send the given NVM I/O command with metadata to the NVMe controller.
    2102             :  *
    2103             :  * This is a low level interface for submitting I/O commands directly. Prefer
    2104             :  * the spdk_nvme_ns_cmd_* functions instead. The validity of the command will
    2105             :  * not be checked!
    2106             :  *
    2107             :  * The command is submitted to a qpair allocated by  spdk_nvme_ctrlr_alloc_io_qpair().
    2108             :  * The user must ensure that only one thread submits I/O on a given qpair at any
    2109             :  * given time.
    2110             :  *
    2111             :  * \param ctrlr Opaque handle to NVMe controller.
    2112             :  * \param qpair I/O qpair to submit command.
    2113             :  * \param cmd NVM I/O command to submit.
    2114             :  * \param len Size of buffer.
    2115             :  * \param md_buf Virtual memory address of a single physically contiguous metadata buffer.
    2116             :  * \param cb_fn Callback function invoked when the I/O command completes.
    2117             :  * \param cb_arg Argument passed to callback function.
    2118             :  * \param reset_sgl_fn Callback function to reset scattered payload.
    2119             :  * \param next_sge_fn Callback function to iterate each scattered payload memory segment.
    2120             :  *
    2121             :  * \return 0 if successfully submitted, negated errnos on the following error
    2122             :  conditions:
    2123             :  * -ENOMEM: The request cannot be allocated.
    2124             :  * -ENXIO: The qpair is failed at the transport level.
    2125             :  */
    2126             : int spdk_nvme_ctrlr_cmd_iov_raw_with_md(struct spdk_nvme_ctrlr *ctrlr,
    2127             :                                         struct spdk_nvme_qpair *qpair,
    2128             :                                         struct spdk_nvme_cmd *cmd, uint32_t len,
    2129             :                                         void *md_buf, spdk_nvme_cmd_cb cb_fn,
    2130             :                                         void *cb_arg,
    2131             :                                         spdk_nvme_req_reset_sgl_cb reset_sgl_fn,
    2132             :                                         spdk_nvme_req_next_sge_cb next_sge_fn);
    2133             : 
    2134             : /**
    2135             :  * Get file descriptor for an I/O queue pair.
    2136             :  *
    2137             :  * Applications that enable interrupts for completion notification will register and unregister
    2138             :  * interrupt event source on its queue pair file descriptor. This function returns file descriptor
    2139             :  * for an I/O queue pair.
    2140             :  * This function also allows the transport layer to fill out event handler opts required by the
    2141             :  * application during interrupt registration phase.
    2142             :  *
    2143             :  * \param qpair Opaque handle of the queue pair for which fd has to be fetched.
    2144             :  * \param[out] opts Opaque event handler options to be filled by the transport, or NULL.
    2145             :  *
    2146             :  * \return a valid fd on success, with opts filled out if specified
    2147             :  * -ENOTSUP if transport does not support fetching fd for the queue pair.
    2148             :  * -EINVAL if opts is specified but its size is incorrect.
    2149             :  * -EINVAL if fds are not reserved, -1 if interrupts are not enabled for the qpair controller.
    2150             :  */
    2151             : int spdk_nvme_qpair_get_fd(struct spdk_nvme_qpair *qpair,
    2152             :                            struct spdk_event_handler_opts *opts);
    2153             : 
    2154             : /**
    2155             :  * Process any outstanding completions for I/O submitted on a queue pair.
    2156             :  *
    2157             :  * This call is non-blocking, i.e. it only processes completions that are ready
    2158             :  * at the time of this function call. It does not wait for outstanding commands
    2159             :  * to finish.
    2160             :  *
    2161             :  * For each completed command, the request's callback function will be called if
    2162             :  * specified as non-NULL when the request was submitted.
    2163             :  *
    2164             :  * The caller must ensure that each queue pair is only used from one thread at a
    2165             :  * time.
    2166             :  *
    2167             :  * This function may be called at any point while the controller is attached to
    2168             :  * the SPDK NVMe driver.
    2169             :  *
    2170             :  * \sa spdk_nvme_cmd_cb
    2171             :  *
    2172             :  * \param qpair Queue pair to check for completions.
    2173             :  * \param max_completions Limit the number of completions to be processed in one
    2174             :  * call, or 0 for unlimited.
    2175             :  *
    2176             :  * \return number of completions processed (may be 0) or negated on error. -ENXIO
    2177             :  * in the special case that the qpair is failed at the transport layer.
    2178             :  */
    2179             : int32_t spdk_nvme_qpair_process_completions(struct spdk_nvme_qpair *qpair,
    2180             :                 uint32_t max_completions);
    2181             : 
    2182             : /**
    2183             :  * Returns the reason the qpair is disconnected.
    2184             :  *
    2185             :  * \param qpair The qpair to check.
    2186             :  *
    2187             :  * \return a valid spdk_nvme_qp_failure_reason.
    2188             :  */
    2189             : spdk_nvme_qp_failure_reason spdk_nvme_qpair_get_failure_reason(struct spdk_nvme_qpair *qpair);
    2190             : 
    2191             : /**
    2192             :  * Control if DNR is set or not for aborted commands.
    2193             :  *
    2194             :  * The default value is false.
    2195             :  *
    2196             :  * \param qpair The qpair to set.
    2197             :  * \param dnr Set the DNR bit to 1 if true or 0 if false for aborted commands.
    2198             :  */
    2199             : void spdk_nvme_qpair_set_abort_dnr(struct spdk_nvme_qpair *qpair, bool dnr);
    2200             : 
    2201             : /**
    2202             :  * Return the connection status of a given qpair.
    2203             :  *
    2204             :  * \param qpair The qpair to check.
    2205             :  *
    2206             :  * \return true if the qpair is connected, or false otherwise.
    2207             :  */
    2208             : bool spdk_nvme_qpair_is_connected(struct spdk_nvme_qpair *qpair);
    2209             : 
    2210             : typedef void (*spdk_nvme_authenticate_cb)(void *ctx, int status);
    2211             : 
    2212             : /**
    2213             :  * Force a qpair to authenticate.  As part of initialization, qpairs are authenticated automatically
    2214             :  * if the controller is configured with DH-HMAC-CHAP keys.  However, this function can be used to
    2215             :  * force authentication after a connection has already been established.
    2216             :  *
    2217             :  * This function doesn't disconnect the qpair if the authentication is successful.
    2218             :  *
    2219             :  * \param qpair The qpair to authenticate.
    2220             :  * \param cb_fn Callback to be executed after the authentication is done.
    2221             :  * \param cb_ctx Context passed to `cb_fn`.
    2222             :  *
    2223             :  * \return 0 on success, negative errno on failure.
    2224             :  */
    2225             : int spdk_nvme_qpair_authenticate(struct spdk_nvme_qpair *qpair,
    2226             :                                  spdk_nvme_authenticate_cb cb_fn, void *cb_ctx);
    2227             : 
    2228             : /**
    2229             :  * Force authentication on the admin qpair of a controller.  As part of initialization, the admin
    2230             :  * qpair is authenticated automatically if the controller is configured with DH-HMAC-CHAP keys.
    2231             :  * However, this function can be used to force authentication after a connection has already been
    2232             :  * established.
    2233             :  *
    2234             :  * This function doesn't disconnect the admin qpair if the authentication is successful.
    2235             :  *
    2236             :  * \param ctrlr Controller to authenticate.
    2237             :  * \param cb_fn Callback to be executed after the authentication is done.
    2238             :  * \param cb_ctx Context passed to `cb_fn`.
    2239             :  *
    2240             :  * \return 0 on success, negative errno on failure.
    2241             :  */
    2242             : int spdk_nvme_ctrlr_authenticate(struct spdk_nvme_ctrlr *ctrlr,
    2243             :                                  spdk_nvme_authenticate_cb cb_fn, void *cb_ctx);
    2244             : 
    2245             : /**
    2246             :  * Send the given admin command to the NVMe controller.
    2247             :  *
    2248             :  * This is a low level interface for submitting admin commands directly. Prefer
    2249             :  * the spdk_nvme_ctrlr_cmd_* functions instead. The validity of the command will
    2250             :  * not be checked!
    2251             :  *
    2252             :  * When constructing the nvme_command it is not necessary to fill out the PRP
    2253             :  * list/SGL or the CID. The driver will handle both of those for you.
    2254             :  *
    2255             :  * This function is thread safe and can be called at any point while the controller
    2256             :  * is attached to the SPDK NVMe driver.
    2257             :  *
    2258             :  * Call spdk_nvme_ctrlr_process_admin_completions() to poll for completion
    2259             :  * of commands submitted through this function.
    2260             :  *
    2261             :  * \param ctrlr Opaque handle to NVMe controller.
    2262             :  * \param cmd NVM admin command to submit.
    2263             :  * \param buf Virtual memory address of a single physically contiguous buffer.
    2264             :  * \param len Size of buffer.
    2265             :  * \param cb_fn Callback function invoked when the admin command completes.
    2266             :  * \param cb_arg Argument passed to callback function.
    2267             :  *
    2268             :  * \return 0 if successfully submitted, negated errno if resources could not be
    2269             :  * allocated for this request, -ENXIO if the admin qpair is failed at the transport layer.
    2270             :  */
    2271             : int spdk_nvme_ctrlr_cmd_admin_raw(struct spdk_nvme_ctrlr *ctrlr,
    2272             :                                   struct spdk_nvme_cmd *cmd,
    2273             :                                   void *buf, uint32_t len,
    2274             :                                   spdk_nvme_cmd_cb cb_fn, void *cb_arg);
    2275             : 
    2276             : /**
    2277             :  * Process any outstanding completions for admin commands.
    2278             :  *
    2279             :  * This will process completions for admin commands submitted on any thread.
    2280             :  *
    2281             :  * This call is non-blocking, i.e. it only processes completions that are ready
    2282             :  * at the time of this function call. It does not wait for outstanding commands
    2283             :  * to finish.
    2284             :  *
    2285             :  * This function is thread safe and can be called at any point while the controller
    2286             :  * is attached to the SPDK NVMe driver.
    2287             :  *
    2288             :  * \param ctrlr Opaque handle to NVMe controller.
    2289             :  *
    2290             :  * \return number of completions processed (may be 0) or negated on error. -ENXIO
    2291             :  * in the special case that the qpair is failed at the transport layer.
    2292             :  */
    2293             : int32_t spdk_nvme_ctrlr_process_admin_completions(struct spdk_nvme_ctrlr *ctrlr);
    2294             : 
    2295             : 
    2296             : /**
    2297             :  * Opaque handle to a namespace. Obtained by calling spdk_nvme_ctrlr_get_ns().
    2298             :  */
    2299             : struct spdk_nvme_ns;
    2300             : 
    2301             : /**
    2302             :  * Get a handle to a namespace for the given controller.
    2303             :  *
    2304             :  * Namespaces are numbered from 1 to the total number of namespaces. There will
    2305             :  * never be any gaps in the numbering. The number of namespaces is obtained by
    2306             :  * calling spdk_nvme_ctrlr_get_num_ns().
    2307             :  *
    2308             :  * This function is thread safe and can be called at any point while the controller
    2309             :  * is attached to the SPDK NVMe driver.
    2310             :  *
    2311             :  * \param ctrlr Opaque handle to NVMe controller.
    2312             :  * \param ns_id Namespace id.
    2313             :  *
    2314             :  * \return a pointer to the namespace.
    2315             :  */
    2316             : struct spdk_nvme_ns *spdk_nvme_ctrlr_get_ns(struct spdk_nvme_ctrlr *ctrlr, uint32_t ns_id);
    2317             : 
    2318             : /**
    2319             :  * Get a specific log page from the NVMe controller.
    2320             :  *
    2321             :  * This function is thread safe and can be called at any point while the controller
    2322             :  * is attached to the SPDK NVMe driver.
    2323             :  *
    2324             :  * Call spdk_nvme_ctrlr_process_admin_completions() to poll for completion of
    2325             :  * commands submitted through this function.
    2326             :  *
    2327             :  * \sa spdk_nvme_ctrlr_is_log_page_supported()
    2328             :  *
    2329             :  * \param ctrlr Opaque handle to NVMe controller.
    2330             :  * \param log_page The log page identifier.
    2331             :  * \param nsid Depending on the log page, this may be 0, a namespace identifier,
    2332             :  * or SPDK_NVME_GLOBAL_NS_TAG.
    2333             :  * \param payload The pointer to the payload buffer.
    2334             :  * \param payload_size The size of payload buffer.
    2335             :  * \param offset Offset in bytes within the log page to start retrieving log page
    2336             :  * data. May only be non-zero if the controller supports extended data for Get Log
    2337             :  * Page as reported in the controller data log page attributes.
    2338             :  * \param cb_fn Callback function to invoke when the log page has been retrieved.
    2339             :  * \param cb_arg Argument to pass to the callback function.
    2340             :  *
    2341             :  * \return 0 if successfully submitted, negated errno if resources could not be
    2342             :  * allocated for this request, -ENXIO if the admin qpair is failed at the transport layer.
    2343             :  */
    2344             : int spdk_nvme_ctrlr_cmd_get_log_page(struct spdk_nvme_ctrlr *ctrlr,
    2345             :                                      uint8_t log_page, uint32_t nsid,
    2346             :                                      void *payload, uint32_t payload_size,
    2347             :                                      uint64_t offset,
    2348             :                                      spdk_nvme_cmd_cb cb_fn, void *cb_arg);
    2349             : 
    2350             : /**
    2351             :  * Get a specific log page from the NVMe controller.
    2352             :  *
    2353             :  * This function is thread safe and can be called at any point while the controller
    2354             :  * is attached to the SPDK NVMe driver.
    2355             :  *
    2356             :  * This function allows specifying extra fields in cdw10 and cdw11 such as
    2357             :  * Retain Asynchronous Event and Log Specific Field.
    2358             :  *
    2359             :  * Call spdk_nvme_ctrlr_process_admin_completions() to poll for completion of
    2360             :  * commands submitted through this function.
    2361             :  *
    2362             :  * \sa spdk_nvme_ctrlr_is_log_page_supported()
    2363             :  *
    2364             :  * \param ctrlr Opaque handle to NVMe controller.
    2365             :  * \param log_page The log page identifier.
    2366             :  * \param nsid Depending on the log page, this may be 0, a namespace identifier,
    2367             :  * or SPDK_NVME_GLOBAL_NS_TAG.
    2368             :  * \param payload The pointer to the payload buffer.
    2369             :  * \param payload_size The size of payload buffer.
    2370             :  * \param offset Offset in bytes within the log page to start retrieving log page
    2371             :  * data. May only be non-zero if the controller supports extended data for Get Log
    2372             :  * Page as reported in the controller data log page attributes.
    2373             :  * \param cdw10 Value to specify for cdw10.  Specify 0 for numdl - it will be
    2374             :  * set by this function based on the payload_size parameter.  Specify 0 for lid -
    2375             :  * it will be set by this function based on the log_page parameter.
    2376             :  * \param cdw11 Value to specify for cdw11.  Specify 0 for numdu - it will be
    2377             :  * set by this function based on the payload_size.
    2378             :  * \param cdw14 Value to specify for cdw14.
    2379             :  * \param cb_fn Callback function to invoke when the log page has been retrieved.
    2380             :  * \param cb_arg Argument to pass to the callback function.
    2381             :  *
    2382             :  * \return 0 if successfully submitted, negated errno if resources could not be
    2383             :  * allocated for this request, -ENXIO if the admin qpair is failed at the transport layer.
    2384             :  */
    2385             : int spdk_nvme_ctrlr_cmd_get_log_page_ext(struct spdk_nvme_ctrlr *ctrlr, uint8_t log_page,
    2386             :                 uint32_t nsid, void *payload, uint32_t payload_size,
    2387             :                 uint64_t offset, uint32_t cdw10, uint32_t cdw11,
    2388             :                 uint32_t cdw14, spdk_nvme_cmd_cb cb_fn, void *cb_arg);
    2389             : 
    2390             : /**
    2391             :  * Abort a specific previously-submitted NVMe command.
    2392             :  *
    2393             :  * \sa spdk_nvme_ctrlr_register_timeout_callback()
    2394             :  *
    2395             :  * \param ctrlr NVMe controller to which the command was submitted.
    2396             :  * \param qpair NVMe queue pair to which the command was submitted. For admin
    2397             :  *  commands, pass NULL for the qpair.
    2398             :  * \param cid Command ID of the command to abort.
    2399             :  * \param cb_fn Callback function to invoke when the abort has completed.
    2400             :  * \param cb_arg Argument to pass to the callback function.
    2401             :  *
    2402             :  * \return 0 if successfully submitted, negated errno if resources could not be
    2403             :  * allocated for this request, -ENXIO if the admin qpair is failed at the transport layer.
    2404             :  */
    2405             : int spdk_nvme_ctrlr_cmd_abort(struct spdk_nvme_ctrlr *ctrlr,
    2406             :                               struct spdk_nvme_qpair *qpair,
    2407             :                               uint16_t cid,
    2408             :                               spdk_nvme_cmd_cb cb_fn,
    2409             :                               void *cb_arg);
    2410             : 
    2411             : /**
    2412             :  * Abort previously submitted commands which have cmd_cb_arg as its callback argument.
    2413             :  *
    2414             :  * \param ctrlr NVMe controller to which the commands were submitted.
    2415             :  * \param qpair NVMe queue pair to which the commands were submitted. For admin
    2416             :  * commands, pass NULL for the qpair.
    2417             :  * \param cmd_cb_arg Callback argument for the NVMe commands which this function
    2418             :  * attempts to abort.
    2419             :  * \param cb_fn Callback function to invoke when this function has completed.
    2420             :  * \param cb_arg Argument to pass to the callback function.
    2421             :  *
    2422             :  * \return 0 if successfully submitted, negated errno otherwise.
    2423             :  */
    2424             : int spdk_nvme_ctrlr_cmd_abort_ext(struct spdk_nvme_ctrlr *ctrlr,
    2425             :                                   struct spdk_nvme_qpair *qpair,
    2426             :                                   void *cmd_cb_arg,
    2427             :                                   spdk_nvme_cmd_cb cb_fn,
    2428             :                                   void *cb_arg);
    2429             : 
    2430             : /**
    2431             :  * Set specific feature for the given NVMe controller.
    2432             :  *
    2433             :  * This function is thread safe and can be called at any point while the controller
    2434             :  * is attached to the SPDK NVMe driver.
    2435             :  *
    2436             :  * Call spdk_nvme_ctrlr_process_admin_completions() to poll for completion of
    2437             :  * commands submitted through this function.
    2438             :  *
    2439             :  * \sa spdk_nvme_ctrlr_cmd_get_feature().
    2440             :  *
    2441             :  * \param ctrlr NVMe controller to manipulate.
    2442             :  * \param feature The feature identifier.
    2443             :  * \param cdw11 as defined by the specification for this command.
    2444             :  * \param cdw12 as defined by the specification for this command.
    2445             :  * \param payload The pointer to the payload buffer.
    2446             :  * \param payload_size The size of payload buffer.
    2447             :  * \param cb_fn Callback function to invoke when the feature has been set.
    2448             :  * \param cb_arg Argument to pass to the callback function.
    2449             :  *
    2450             :  * \return 0 if successfully submitted, negated errno if resources could not be
    2451             :  * allocated for this request, -ENXIO if the admin qpair is failed at the transport layer.
    2452             :  */
    2453             : int spdk_nvme_ctrlr_cmd_set_feature(struct spdk_nvme_ctrlr *ctrlr,
    2454             :                                     uint8_t feature, uint32_t cdw11, uint32_t cdw12,
    2455             :                                     void *payload, uint32_t payload_size,
    2456             :                                     spdk_nvme_cmd_cb cb_fn, void *cb_arg);
    2457             : 
    2458             : /**
    2459             :  * Get specific feature from given NVMe controller.
    2460             :  *
    2461             :  * This function is thread safe and can be called at any point while the controller
    2462             :  * is attached to the SPDK NVMe driver.
    2463             :  *
    2464             :  * Call spdk_nvme_ctrlr_process_admin_completions() to poll for completion of
    2465             :  * commands submitted through this function.
    2466             :  *
    2467             :  * \sa spdk_nvme_ctrlr_cmd_set_feature()
    2468             :  *
    2469             :  * \param ctrlr NVMe controller to query.
    2470             :  * \param feature The feature identifier.
    2471             :  * \param cdw11 as defined by the specification for this command.
    2472             :  * \param payload The pointer to the payload buffer.
    2473             :  * \param payload_size The size of payload buffer.
    2474             :  * \param cb_fn Callback function to invoke when the feature has been retrieved.
    2475             :  * \param cb_arg Argument to pass to the callback function.
    2476             :  *
    2477             :  * \return 0 if successfully submitted, -ENOMEM if resources could not be allocated
    2478             :  * for this request, -ENXIO if the admin qpair is failed at the transport layer.
    2479             :  */
    2480             : int spdk_nvme_ctrlr_cmd_get_feature(struct spdk_nvme_ctrlr *ctrlr,
    2481             :                                     uint8_t feature, uint32_t cdw11,
    2482             :                                     void *payload, uint32_t payload_size,
    2483             :                                     spdk_nvme_cmd_cb cb_fn, void *cb_arg);
    2484             : 
    2485             : /**
    2486             :  * Get specific feature from given NVMe controller.
    2487             :  *
    2488             :  * \param ctrlr NVMe controller to query.
    2489             :  * \param feature The feature identifier.
    2490             :  * \param cdw11 as defined by the specification for this command.
    2491             :  * \param payload The pointer to the payload buffer.
    2492             :  * \param payload_size The size of payload buffer.
    2493             :  * \param cb_fn Callback function to invoke when the feature has been retrieved.
    2494             :  * \param cb_arg Argument to pass to the callback function.
    2495             :  * \param ns_id The namespace identifier.
    2496             :  *
    2497             :  * \return 0 if successfully submitted, -ENOMEM if resources could not be allocated
    2498             :  * for this request, -ENXIO if the admin qpair is failed at the transport layer.
    2499             :  *
    2500             :  * This function is thread safe and can be called at any point while the controller
    2501             :  * is attached to the SPDK NVMe driver.
    2502             :  *
    2503             :  * Call \ref spdk_nvme_ctrlr_process_admin_completions() to poll for completion
    2504             :  * of commands submitted through this function.
    2505             :  *
    2506             :  * \sa spdk_nvme_ctrlr_cmd_set_feature_ns()
    2507             :  */
    2508             : int spdk_nvme_ctrlr_cmd_get_feature_ns(struct spdk_nvme_ctrlr *ctrlr, uint8_t feature,
    2509             :                                        uint32_t cdw11, void *payload, uint32_t payload_size,
    2510             :                                        spdk_nvme_cmd_cb cb_fn, void *cb_arg, uint32_t ns_id);
    2511             : 
    2512             : /**
    2513             :  * Set specific feature for the given NVMe controller and namespace ID.
    2514             :  *
    2515             :  * \param ctrlr NVMe controller to manipulate.
    2516             :  * \param feature The feature identifier.
    2517             :  * \param cdw11 as defined by the specification for this command.
    2518             :  * \param cdw12 as defined by the specification for this command.
    2519             :  * \param payload The pointer to the payload buffer.
    2520             :  * \param payload_size The size of payload buffer.
    2521             :  * \param cb_fn Callback function to invoke when the feature has been set.
    2522             :  * \param cb_arg Argument to pass to the callback function.
    2523             :  * \param ns_id The namespace identifier.
    2524             :  *
    2525             :  * \return 0 if successfully submitted, -ENOMEM if resources could not be allocated
    2526             :  * for this request, -ENXIO if the admin qpair is failed at the transport layer.
    2527             :  *
    2528             :  * This function is thread safe and can be called at any point while the controller
    2529             :  * is attached to the SPDK NVMe driver.
    2530             :  *
    2531             :  * Call \ref spdk_nvme_ctrlr_process_admin_completions() to poll for completion
    2532             :  * of commands submitted through this function.
    2533             :  *
    2534             :  * \sa spdk_nvme_ctrlr_cmd_get_feature_ns()
    2535             :  */
    2536             : int spdk_nvme_ctrlr_cmd_set_feature_ns(struct spdk_nvme_ctrlr *ctrlr, uint8_t feature,
    2537             :                                        uint32_t cdw11, uint32_t cdw12, void *payload,
    2538             :                                        uint32_t payload_size, spdk_nvme_cmd_cb cb_fn,
    2539             :                                        void *cb_arg, uint32_t ns_id);
    2540             : 
    2541             : /**
    2542             :  * Receive security protocol data from controller.
    2543             :  *
    2544             :  * This function is thread safe and can be called at any point after spdk_nvme_probe().
    2545             :  *
    2546             :  * \param ctrlr NVMe controller to use for security receive command submission.
    2547             :  * \param secp Security Protocol that is used.
    2548             :  * \param spsp Security Protocol Specific field.
    2549             :  * \param nssf NVMe Security Specific field. Indicate RPMB target when using Security
    2550             :  * Protocol EAh.
    2551             :  * \param payload The pointer to the payload buffer.
    2552             :  * \param payload_size The size of payload buffer.
    2553             :  * \param cb_fn Callback function to invoke when the command has been completed.
    2554             :  * \param cb_arg Argument to pass to the callback function.
    2555             :  *
    2556             :  * \return 0 if successfully submitted, negated errno if resources could not be allocated
    2557             :  * for this request.
    2558             :  */
    2559             : int spdk_nvme_ctrlr_cmd_security_receive(struct spdk_nvme_ctrlr *ctrlr, uint8_t secp,
    2560             :                 uint16_t spsp, uint8_t nssf, void *payload,
    2561             :                 uint32_t payload_size,
    2562             :                 spdk_nvme_cmd_cb cb_fn, void *cb_arg);
    2563             : 
    2564             : /**
    2565             :  * Send security protocol data to controller.
    2566             :  *
    2567             :  * This function is thread safe and can be called at any point after spdk_nvme_probe().
    2568             :  *
    2569             :  * \param ctrlr NVMe controller to use for security send command submission.
    2570             :  * \param secp Security Protocol that is used.
    2571             :  * \param spsp Security Protocol Specific field.
    2572             :  * \param nssf NVMe Security Specific field. Indicate RPMB target when using Security
    2573             :  * Protocol EAh.
    2574             :  * \param payload The pointer to the payload buffer.
    2575             :  * \param payload_size The size of payload buffer.
    2576             :  * \param cb_fn Callback function to invoke when the command has been completed.
    2577             :  * \param cb_arg Argument to pass to the callback function.
    2578             :  *
    2579             :  * \return 0 if successfully submitted, negated errno if resources could not be allocated
    2580             :  * for this request.
    2581             :  */
    2582             : int spdk_nvme_ctrlr_cmd_security_send(struct spdk_nvme_ctrlr *ctrlr, uint8_t secp,
    2583             :                                       uint16_t spsp, uint8_t nssf, void *payload,
    2584             :                                       uint32_t payload_size, spdk_nvme_cmd_cb cb_fn, void *cb_arg);
    2585             : 
    2586             : /**
    2587             :  * Receive security protocol data from controller.
    2588             :  *
    2589             :  * This function is thread safe and can be called at any point after spdk_nvme_probe().
    2590             :  *
    2591             :  * \param ctrlr NVMe controller to use for security receive command submission.
    2592             :  * \param secp Security Protocol that is used.
    2593             :  * \param spsp Security Protocol Specific field.
    2594             :  * \param nssf NVMe Security Specific field. Indicate RPMB target when using Security
    2595             :  * Protocol EAh.
    2596             :  * \param payload The pointer to the payload buffer.
    2597             :  * \param size The size of payload buffer.
    2598             :  *
    2599             :  * \return 0 if successfully submitted, negated errno if resources could not be allocated
    2600             :  * for this request.
    2601             :  */
    2602             : int spdk_nvme_ctrlr_security_receive(struct spdk_nvme_ctrlr *ctrlr, uint8_t secp,
    2603             :                                      uint16_t spsp, uint8_t nssf, void *payload, size_t size);
    2604             : 
    2605             : /**
    2606             :  * Send security protocol data to controller.
    2607             :  *
    2608             :  * This function is thread safe and can be called at any point after spdk_nvme_probe().
    2609             :  *
    2610             :  * \param ctrlr NVMe controller to use for security send command submission.
    2611             :  * \param secp Security Protocol that is used.
    2612             :  * \param spsp Security Protocol Specific field.
    2613             :  * \param nssf NVMe Security Specific field. Indicate RPMB target when using Security
    2614             :  * Protocol EAh.
    2615             :  * \param payload The pointer to the payload buffer.
    2616             :  * \param size The size of payload buffer.
    2617             :  *
    2618             :  * \return 0 if successfully submitted, negated errno if resources could not be allocated
    2619             :  * for this request.
    2620             :  */
    2621             : int spdk_nvme_ctrlr_security_send(struct spdk_nvme_ctrlr *ctrlr, uint8_t secp,
    2622             :                                   uint16_t spsp, uint8_t nssf, void *payload, size_t size);
    2623             : 
    2624             : /**
    2625             :  * Receive data related to a specific Directive Type from the controller.
    2626             :  *
    2627             :  * This function is thread safe and can be called at any point after spdk_nvme_probe().
    2628             :  *
    2629             :  * Call spdk_nvme_ctrlr_process_admin_completions() to poll for completion of
    2630             :  * commands submitted through this function.
    2631             :  *
    2632             :  * \param ctrlr NVMe controller to use for directive receive command submission.
    2633             :  * \param nsid Specific Namespace Identifier.
    2634             :  * \param doper Directive Operation defined in nvme_spec.h.
    2635             :  * \param dtype Directive Type defined in nvme_spec.h.
    2636             :  * \param dspec Directive Specific defined in nvme_spec.h.
    2637             :  * \param payload The pointer to the payload buffer.
    2638             :  * \param payload_size The size of payload buffer.
    2639             :  * \param cdw12 Command dword 12.
    2640             :  * \param cdw13 Command dword 13.
    2641             :  * \param cb_fn Callback function to invoke when the command has been completed.
    2642             :  * \param cb_arg Argument to pass to the callback function.
    2643             :  *
    2644             :  * \return 0 if successfully submitted, negated errno if resources could not be allocated
    2645             :  * for this request.
    2646             :  */
    2647             : int spdk_nvme_ctrlr_cmd_directive_receive(struct spdk_nvme_ctrlr *ctrlr, uint32_t nsid,
    2648             :                 uint32_t doper, uint32_t dtype, uint32_t dspec,
    2649             :                 void *payload, uint32_t payload_size, uint32_t cdw12,
    2650             :                 uint32_t cdw13, spdk_nvme_cmd_cb cb_fn, void *cb_arg);
    2651             : 
    2652             : /**
    2653             :  * Send data related to a specific Directive Type to the controller.
    2654             :  *
    2655             :  * This function is thread safe and can be called at any point after spdk_nvme_probe().
    2656             :  *
    2657             :  * Call spdk_nvme_ctrlr_process_admin_completions() to poll for completion of
    2658             :  * commands submitted through this function.
    2659             :  *
    2660             :  * \param ctrlr NVMe controller to use for directive send command submission.
    2661             :  * \param nsid Specific Namespace Identifier.
    2662             :  * \param doper Directive Operation defined in nvme_spec.h.
    2663             :  * \param dtype Directive Type defined in nvme_spec.h.
    2664             :  * \param dspec Directive Specific defined in nvme_spec.h.
    2665             :  * \param payload The pointer to the payload buffer.
    2666             :  * \param payload_size The size of payload buffer.
    2667             :  * \param cdw12 Command dword 12.
    2668             :  * \param cdw13 Command dword 13.
    2669             :  * \param cb_fn Callback function to invoke when the command has been completed.
    2670             :  * \param cb_arg Argument to pass to the callback function.
    2671             :  *
    2672             :  * \return 0 if successfully submitted, negated errno if resources could not be allocated
    2673             :  * for this request.
    2674             :  */
    2675             : int spdk_nvme_ctrlr_cmd_directive_send(struct spdk_nvme_ctrlr *ctrlr, uint32_t nsid,
    2676             :                                        uint32_t doper, uint32_t dtype, uint32_t dspec,
    2677             :                                        void *payload, uint32_t payload_size, uint32_t cdw12,
    2678             :                                        uint32_t cdw13, spdk_nvme_cmd_cb cb_fn, void *cb_arg);
    2679             : 
    2680             : /**
    2681             :  * Get supported flags of the controller.
    2682             :  *
    2683             :  * \param ctrlr NVMe controller to get flags.
    2684             :  *
    2685             :  * \return supported flags of this controller.
    2686             :  */
    2687             : uint64_t spdk_nvme_ctrlr_get_flags(struct spdk_nvme_ctrlr *ctrlr);
    2688             : 
    2689             : /**
    2690             :  * Attach the specified namespace to controllers.
    2691             :  *
    2692             :  * This function is thread safe and can be called at any point after spdk_nvme_probe().
    2693             :  *
    2694             :  * \param ctrlr NVMe controller to use for command submission.
    2695             :  * \param nsid Namespace identifier for namespace to attach.
    2696             :  * \param payload The pointer to the controller list.
    2697             :  *
    2698             :  * \return 0 if successfully submitted, ENOMEM if resources could not be allocated
    2699             :  * for this request.
    2700             :  */
    2701             : int spdk_nvme_ctrlr_attach_ns(struct spdk_nvme_ctrlr *ctrlr, uint32_t nsid,
    2702             :                               struct spdk_nvme_ctrlr_list *payload);
    2703             : 
    2704             : /**
    2705             :  * Detach the specified namespace from controllers.
    2706             :  *
    2707             :  * This function is thread safe and can be called at any point after spdk_nvme_probe().
    2708             :  *
    2709             :  * \param ctrlr NVMe controller to use for command submission.
    2710             :  * \param nsid Namespace ID to detach.
    2711             :  * \param payload The pointer to the controller list.
    2712             :  *
    2713             :  * \return 0 if successfully submitted, ENOMEM if resources could not be allocated
    2714             :  * for this request
    2715             :  */
    2716             : int spdk_nvme_ctrlr_detach_ns(struct spdk_nvme_ctrlr *ctrlr, uint32_t nsid,
    2717             :                               struct spdk_nvme_ctrlr_list *payload);
    2718             : 
    2719             : /**
    2720             :  * Create a namespace.
    2721             :  *
    2722             :  * This function is thread safe and can be called at any point after spdk_nvme_probe().
    2723             :  *
    2724             :  * \param ctrlr NVMe controller to create namespace on.
    2725             :  * \param payload The pointer to the NVMe namespace data.
    2726             :  *
    2727             :  * \return Namespace ID (>= 1) if successfully created, or 0 if the request failed.
    2728             :  */
    2729             : uint32_t spdk_nvme_ctrlr_create_ns(struct spdk_nvme_ctrlr *ctrlr,
    2730             :                                    struct spdk_nvme_ns_data *payload);
    2731             : 
    2732             : /**
    2733             :  * Delete a namespace.
    2734             :  *
    2735             :  * This function is thread safe and can be called at any point after spdk_nvme_probe().
    2736             :  *
    2737             :  * \param ctrlr NVMe controller to delete namespace from.
    2738             :  * \param nsid The namespace identifier.
    2739             :  *
    2740             :  * \return 0 if successfully submitted, negated errno if resources could not be
    2741             :  * allocated
    2742             :  * for this request
    2743             :  */
    2744             : int spdk_nvme_ctrlr_delete_ns(struct spdk_nvme_ctrlr *ctrlr, uint32_t nsid);
    2745             : 
    2746             : /**
    2747             :  * Format NVM.
    2748             :  *
    2749             :  * This function requests a low-level format of the media.
    2750             :  *
    2751             :  * This function is thread safe and can be called at any point after spdk_nvme_probe().
    2752             :  *
    2753             :  * \param ctrlr NVMe controller to format.
    2754             :  * \param nsid The namespace identifier. May be SPDK_NVME_GLOBAL_NS_TAG to format
    2755             :  * all namespaces.
    2756             :  * \param format The format information for the command.
    2757             :  *
    2758             :  * \return 0 if successfully submitted, negated errno if resources could not be
    2759             :  * allocated for this request
    2760             :  */
    2761             : int spdk_nvme_ctrlr_format(struct spdk_nvme_ctrlr *ctrlr, uint32_t nsid,
    2762             :                            struct spdk_nvme_format *format);
    2763             : 
    2764             : /**
    2765             :  * Download a new firmware image.
    2766             :  *
    2767             :  * This function is thread safe and can be called at any point after spdk_nvme_probe().
    2768             :  *
    2769             :  * \param ctrlr NVMe controller to perform firmware operation on.
    2770             :  * \param payload The data buffer for the firmware image.
    2771             :  * \param size The data size will be downloaded.
    2772             :  * \param slot The slot that the firmware image will be committed to.
    2773             :  * \param commit_action The action to perform when firmware is committed.
    2774             :  * \param completion_status output parameter. Contains the completion status of
    2775             :  * the firmware commit operation.
    2776             :  *
    2777             :  * \return 0 if successfully submitted, ENOMEM if resources could not be allocated
    2778             :  * for this request, -1 if the size is not multiple of 4.
    2779             :  */
    2780             : int spdk_nvme_ctrlr_update_firmware(struct spdk_nvme_ctrlr *ctrlr, void *payload, uint32_t size,
    2781             :                                     int slot, enum spdk_nvme_fw_commit_action commit_action,
    2782             :                                     struct spdk_nvme_status *completion_status);
    2783             : 
    2784             : /**
    2785             :  * Start the Read from a Boot Partition.
    2786             :  *
    2787             :  * This function is thread safe and can be called at any point after spdk_nvme_probe().
    2788             :  *
    2789             :  * \param ctrlr NVMe controller to perform the Boot Partition read.
    2790             :  * \param payload The data buffer for Boot Partition read.
    2791             :  * \param bprsz Read size in multiples of 4 KiB to copy into the Boot Partition Memory Buffer.
    2792             :  * \param bprof Boot Partition offset to read from in 4 KiB units.
    2793             :  * \param bpid Boot Partition identifier for the Boot Partition read operation.
    2794             :  *
    2795             :  * \return 0 if Boot Partition read is successful. Negated errno on the following error conditions:
    2796             :  * -ENOMEM: if resources could not be allocated.
    2797             :  * -ENOTSUP: Boot Partition is not supported by the Controller.
    2798             :  * -EIO: Registers access failure.
    2799             :  * -EINVAL: Parameters are invalid.
    2800             :  * -EFAULT: Invalid address was specified as part of payload.
    2801             :  * -EALREADY: Boot Partition read already initiated.
    2802             :  */
    2803             : int spdk_nvme_ctrlr_read_boot_partition_start(struct spdk_nvme_ctrlr *ctrlr, void *payload,
    2804             :                 uint32_t bprsz, uint32_t bprof, uint32_t bpid);
    2805             : 
    2806             : /**
    2807             :  * Poll the status of the Read from a Boot Partition.
    2808             :  *
    2809             :  * This function is thread safe and can be called at any point after spdk_nvme_probe().
    2810             :  *
    2811             :  * \param ctrlr NVMe controller to perform the Boot Partition read.
    2812             :  *
    2813             :  * \return 0 if Boot Partition read is successful. Negated errno on the following error conditions:
    2814             :  * -EIO: Registers access failure.
    2815             :  * -EINVAL: Invalid read status or the Boot Partition read is not initiated yet.
    2816             :  * -EAGAIN: If the read is still in progress; users must call
    2817             :  * spdk_nvme_ctrlr_read_boot_partition_poll again to check the read status.
    2818             :  */
    2819             : int spdk_nvme_ctrlr_read_boot_partition_poll(struct spdk_nvme_ctrlr *ctrlr);
    2820             : 
    2821             : /**
    2822             :  * Write to a Boot Partition.
    2823             :  *
    2824             :  * This function is thread safe and can be called at any point after spdk_nvme_probe().
    2825             :  * Users will get the completion after the data is downloaded, image is replaced and
    2826             :  * Boot Partition is activated or when the sequence encounters an error.
    2827             :  *
    2828             :  * \param ctrlr NVMe controller to perform the Boot Partition write.
    2829             :  * \param payload The data buffer for Boot Partition write.
    2830             :  * \param size Data size to write to the Boot Partition.
    2831             :  * \param bpid Boot Partition identifier for the Boot Partition write operation.
    2832             :  * \param cb_fn Callback function to invoke when the operation is completed.
    2833             :  * \param cb_arg Argument to pass to the callback function.
    2834             :  *
    2835             :  * \return 0 if Boot Partition write submit is successful. Negated errno on the following error conditions:
    2836             :  * -ENOMEM: if resources could not be allocated.
    2837             :  * -ENOTSUP: Boot Partition is not supported by the Controller.
    2838             :  * -EIO: Registers access failure.
    2839             :  * -EINVAL: Parameters are invalid.
    2840             :  */
    2841             : int spdk_nvme_ctrlr_write_boot_partition(struct spdk_nvme_ctrlr *ctrlr, void *payload,
    2842             :                 uint32_t size, uint32_t bpid, spdk_nvme_cmd_cb cb_fn, void *cb_arg);
    2843             : 
    2844             : /**
    2845             :  * Return virtual address of PCIe NVM I/O registers
    2846             :  *
    2847             :  * This function returns a pointer to the PCIe I/O registers for a controller
    2848             :  * or NULL if unsupported for this transport.
    2849             :  *
    2850             :  * \param ctrlr Controller whose registers are to be accessed.
    2851             :  *
    2852             :  * \return Pointer to virtual address of register bank, or NULL.
    2853             :  */
    2854             : volatile struct spdk_nvme_registers *spdk_nvme_ctrlr_get_registers(struct spdk_nvme_ctrlr *ctrlr);
    2855             : 
    2856             : /**
    2857             :  * Reserve the controller memory buffer for data transfer use.
    2858             :  *
    2859             :  * This function reserves the full size of the controller memory buffer
    2860             :  * for use in data transfers. If submission queues or completion queues are
    2861             :  * already placed in the controller memory buffer, this call will fail.
    2862             :  *
    2863             :  * \param ctrlr Controller from which to allocate memory buffer
    2864             :  *
    2865             :  * \return The size of the controller memory buffer on success. Negated errno
    2866             :  * on failure.
    2867             :  */
    2868             : int spdk_nvme_ctrlr_reserve_cmb(struct spdk_nvme_ctrlr *ctrlr);
    2869             : 
    2870             : /**
    2871             :  * Map a previously reserved controller memory buffer so that it's data is
    2872             :  * visible from the CPU. This operation is not always possible.
    2873             :  *
    2874             :  * \param ctrlr Controller that contains the memory buffer
    2875             :  * \param size Size of buffer that was mapped.
    2876             :  *
    2877             :  * \return Pointer to controller memory buffer, or NULL on failure.
    2878             :  */
    2879             : void *spdk_nvme_ctrlr_map_cmb(struct spdk_nvme_ctrlr *ctrlr, size_t *size);
    2880             : 
    2881             : /**
    2882             :  * Free a controller memory I/O buffer.
    2883             :  *
    2884             :  * \param ctrlr Controller from which to unmap the memory buffer.
    2885             :  */
    2886             : void spdk_nvme_ctrlr_unmap_cmb(struct spdk_nvme_ctrlr *ctrlr);
    2887             : 
    2888             : /**
    2889             :  * Enable the Persistent Memory Region
    2890             :  *
    2891             :  * \param ctrlr Controller that contains the Persistent Memory Region
    2892             :  *
    2893             :  * \return 0 on success. Negated errno on the following error conditions:
    2894             :  * -ENOTSUP: PMR is not supported by the Controller.
    2895             :  * -EIO: Registers access failure.
    2896             :  * -EINVAL: PMR Time Units Invalid or PMR is already enabled.
    2897             :  * -ETIMEDOUT: Timed out to Enable PMR.
    2898             :  * -ENOSYS: Transport does not support Enable PMR function.
    2899             :  */
    2900             : int spdk_nvme_ctrlr_enable_pmr(struct spdk_nvme_ctrlr *ctrlr);
    2901             : 
    2902             : /**
    2903             :  * Disable the Persistent Memory Region
    2904             :  *
    2905             :  * \param ctrlr Controller that contains the Persistent Memory Region
    2906             :  *
    2907             :  * \return 0 on success. Negated errno on the following error conditions:
    2908             :  * -ENOTSUP: PMR is not supported by the Controller.
    2909             :  * -EIO: Registers access failure.
    2910             :  * -EINVAL: PMR Time Units Invalid or PMR is already disabled.
    2911             :  * -ETIMEDOUT: Timed out to Disable PMR.
    2912             :  * -ENOSYS: Transport does not support Disable PMR function.
    2913             :  */
    2914             : int spdk_nvme_ctrlr_disable_pmr(struct spdk_nvme_ctrlr *ctrlr);
    2915             : 
    2916             : /**
    2917             :  * Map the Persistent Memory Region so that it's data is
    2918             :  * visible from the CPU.
    2919             :  *
    2920             :  * \param ctrlr Controller that contains the Persistent Memory Region
    2921             :  * \param size Size of the region that was mapped.
    2922             :  *
    2923             :  * \return Pointer to Persistent Memory Region, or NULL on failure.
    2924             :  */
    2925             : void *spdk_nvme_ctrlr_map_pmr(struct spdk_nvme_ctrlr *ctrlr, size_t *size);
    2926             : 
    2927             : /**
    2928             :  * Free the Persistent Memory Region.
    2929             :  *
    2930             :  * \param ctrlr Controller from which to unmap the Persistent Memory Region.
    2931             :  *
    2932             :  * \return 0 on success, negative errno on failure.
    2933             :  * -ENXIO: Either PMR is not supported by the Controller or the PMR is already unmapped.
    2934             :  * -ENOSYS: Transport does not support Unmap PMR function.
    2935             :  */
    2936             : int spdk_nvme_ctrlr_unmap_pmr(struct spdk_nvme_ctrlr *ctrlr);
    2937             : 
    2938             : /**
    2939             :  * Get the transport ID for a given NVMe controller.
    2940             :  *
    2941             :  * \param ctrlr Controller to get the transport ID.
    2942             :  * \return Pointer to the controller's transport ID.
    2943             :  */
    2944             : const struct spdk_nvme_transport_id *spdk_nvme_ctrlr_get_transport_id(
    2945             :         struct spdk_nvme_ctrlr *ctrlr);
    2946             : 
    2947             : /**
    2948             :  * \brief Alloc NVMe I/O queue identifier.
    2949             :  *
    2950             :  * This function is only needed for the non-standard case of allocating queues using the raw
    2951             :  * command interface. In most cases \ref spdk_nvme_ctrlr_alloc_io_qpair should be sufficient.
    2952             :  *
    2953             :  * \param ctrlr Opaque handle to NVMe controller.
    2954             :  * \return qid on success, -1 on failure.
    2955             :  */
    2956             : int32_t spdk_nvme_ctrlr_alloc_qid(struct spdk_nvme_ctrlr *ctrlr);
    2957             : 
    2958             : /**
    2959             :  * \brief Free NVMe I/O queue identifier.
    2960             :  *
    2961             :  * This function must only be called with qids previously allocated with \ref spdk_nvme_ctrlr_alloc_qid.
    2962             :  *
    2963             :  * \param ctrlr Opaque handle to NVMe controller.
    2964             :  * \param qid NVMe Queue Identifier.
    2965             :  */
    2966             : void spdk_nvme_ctrlr_free_qid(struct spdk_nvme_ctrlr *ctrlr, uint16_t qid);
    2967             : 
    2968             : /**
    2969             :  * Opaque handle for a poll group. A poll group is a collection of spdk_nvme_qpair
    2970             :  * objects that are polled for completions as a unit.
    2971             :  *
    2972             :  * Returned by spdk_nvme_poll_group_create().
    2973             :  */
    2974             : struct spdk_nvme_poll_group;
    2975             : 
    2976             : 
    2977             : /**
    2978             :  * This function alerts the user to disconnected qpairs when calling
    2979             :  * spdk_nvme_poll_group_process_completions.
    2980             :  */
    2981             : typedef void (*spdk_nvme_disconnected_qpair_cb)(struct spdk_nvme_qpair *qpair,
    2982             :                 void *poll_group_ctx);
    2983             : 
    2984             : /**
    2985             :  * Create a new poll group.
    2986             :  *
    2987             :  * \param ctx A user supplied context that can be retrieved later with spdk_nvme_poll_group_get_ctx
    2988             :  * \param table The call back table defined by users which contains the accelerated functions
    2989             :  * which can be used to accelerate some operations such as crc32c.
    2990             :  *
    2991             :  * \return Pointer to the new poll group, or NULL on error.
    2992             :  */
    2993             : struct spdk_nvme_poll_group *spdk_nvme_poll_group_create(void *ctx,
    2994             :                 struct spdk_nvme_accel_fn_table *table);
    2995             : 
    2996             : /**
    2997             :  * Get a optimal poll group.
    2998             :  *
    2999             :  * \param qpair The qpair to get the optimal poll group.
    3000             :  *
    3001             :  * \return Pointer to the optimal poll group, or NULL if not found.
    3002             :  */
    3003             : struct spdk_nvme_poll_group *spdk_nvme_qpair_get_optimal_poll_group(struct spdk_nvme_qpair *qpair);
    3004             : 
    3005             : /**
    3006             :  * Add an spdk_nvme_qpair to a poll group. qpairs may only be added to
    3007             :  * a poll group if they are in the disconnected state; i.e. either they were
    3008             :  * just allocated and not yet connected or they have been disconnected with a call
    3009             :  * to spdk_nvme_ctrlr_disconnect_io_qpair.
    3010             :  *
    3011             :  * \param group The group to which the qpair will be added.
    3012             :  * \param qpair The qpair to add to the poll group.
    3013             :  *
    3014             :  * return 0 on success, -EINVAL if the qpair is not in the disabled state, -ENODEV if the transport
    3015             :  * doesn't exist, -ENOMEM on memory allocation failures, or -EPROTO on a protocol (transport) specific failure.
    3016             :  */
    3017             : int spdk_nvme_poll_group_add(struct spdk_nvme_poll_group *group, struct spdk_nvme_qpair *qpair);
    3018             : 
    3019             : /**
    3020             :  * Remove a disconnected spdk_nvme_qpair from a poll group.
    3021             :  *
    3022             :  * \param group The group from which to remove the qpair.
    3023             :  * \param qpair The qpair to remove from the poll group.
    3024             :  *
    3025             :  * return 0 on success, -ENOENT if the qpair is not found in the group, -EINVAL if the qpair is not
    3026             :  * disconnected in the group, or -EPROTO on a protocol (transport) specific failure.
    3027             :  */
    3028             : int spdk_nvme_poll_group_remove(struct spdk_nvme_poll_group *group, struct spdk_nvme_qpair *qpair);
    3029             : 
    3030             : /**
    3031             :  * Wait for interrupt events on file descriptors of all the qpairs in this poll group.
    3032             :  *
    3033             :  * In interrupt mode all the file descriptors of qpairs are registered to the fd group within the
    3034             :  * poll group. This can collectively wait for interrupt events on all those file descriptors.
    3035             :  *
    3036             :  * the disconnected_qpair_cb will be called for all disconnected qpairs in the poll group
    3037             :  * including qpairs which fail within the context of this call.
    3038             :  * The user is responsible for trying to reconnect or destroy those qpairs.
    3039             :  *
    3040             :  * \param group The poll group on which to wait for interrupt events.
    3041             :  * \param disconnected_qpair_cb A callback function of type spdk_nvme_disconnected_qpair_cb. Must
    3042             :  * be non-NULL.
    3043             :  *
    3044             :  * \return number of events processed on success, -EINVAL if no disconnected_qpair_cb is passed, or
    3045             :  * -errno in case of failure.
    3046             :  */
    3047             : int spdk_nvme_poll_group_wait(struct spdk_nvme_poll_group *group,
    3048             :                               spdk_nvme_disconnected_qpair_cb disconnected_qpair_cb);
    3049             : 
    3050             : /**
    3051             :  * Return the internal epoll file descriptor of this poll group.
    3052             :  *
    3053             :  * \param group The poll group for which epoll fd is requested.
    3054             :  *
    3055             :  * \return epoll fd for the poll group, -EINVAL if there is no fd group for this poll group.
    3056             :  */
    3057             : int spdk_nvme_poll_group_get_fd(struct spdk_nvme_poll_group *group);
    3058             : 
    3059             : /**
    3060             :  * Return the fd_group associated with this poll group.
    3061             :  *
    3062             :  * \param group Poll group.
    3063             :  *
    3064             :  * \return fd_group or NULL if there's no fd_group associated with this poll group.
    3065             :  */
    3066             : struct spdk_fd_group *spdk_nvme_poll_group_get_fd_group(struct spdk_nvme_poll_group *group);
    3067             : 
    3068             : typedef void (*spdk_nvme_poll_group_interrupt_cb)(struct spdk_nvme_poll_group *group, void *ctx);
    3069             : 
    3070             : /**
    3071             :  * Register a callback to notify that a poll group needs to be polled when in interrupt mode.  This
    3072             :  * isn't required to poll IO completions, but is necessary to process some events, e.g. qpair
    3073             :  * disconnection.
    3074             :  *
    3075             :  * \param group Poll group.
    3076             :  * \param cb_fn Callback to be executed when the poll group needs to be polled.
    3077             :  * \param cb_ctx Callback's context.
    3078             :  *
    3079             :  * \return 0 on success or negative errno otherwise.
    3080             :  */
    3081             : int spdk_nvme_poll_group_set_interrupt_callback(struct spdk_nvme_poll_group *group,
    3082             :                 spdk_nvme_poll_group_interrupt_cb cb_fn, void *cb_ctx);
    3083             : 
    3084             : /**
    3085             :  * Destroy an empty poll group.
    3086             :  *
    3087             :  * \param group The group to destroy.
    3088             :  *
    3089             :  * return 0 on success, -EBUSY if the poll group is not empty.
    3090             :  */
    3091             : int spdk_nvme_poll_group_destroy(struct spdk_nvme_poll_group *group);
    3092             : 
    3093             : /**
    3094             :  * Poll for completions on all qpairs in this poll group.
    3095             :  *
    3096             :  * the disconnected_qpair_cb will be called for all disconnected qpairs in the poll group
    3097             :  * including qpairs which fail within the context of this call.
    3098             :  * The user is responsible for trying to reconnect or destroy those qpairs.
    3099             :  *
    3100             :  * \param group The group on which to poll for completions.
    3101             :  * \param completions_per_qpair The maximum number of completions per qpair.
    3102             :  * \param disconnected_qpair_cb A callback function of type spdk_nvme_disconnected_qpair_cb. Must be non-NULL.
    3103             :  *
    3104             :  * return The number of completions across all qpairs, -EINVAL if no disconnected_qpair_cb is passed, or
    3105             :  * -EIO if the shared completion queue cannot be polled for the RDMA transport.
    3106             :  */
    3107             : int64_t spdk_nvme_poll_group_process_completions(struct spdk_nvme_poll_group *group,
    3108             :                 uint32_t completions_per_qpair, spdk_nvme_disconnected_qpair_cb disconnected_qpair_cb);
    3109             : 
    3110             : /**
    3111             :  * Check if all qpairs in the poll group are connected.
    3112             :  *
    3113             :  * This function allows the caller to check if all qpairs in a poll group are
    3114             :  * connected. This API is generally only suitable during application startup,
    3115             :  * to check when a large number of async connections have completed.
    3116             :  *
    3117             :  * It is useful for applications like benchmarking tools to create
    3118             :  * a large number of qpairs, but then ensuring they are all fully connected before
    3119             :  * proceeding with I/O.
    3120             :  *
    3121             :  * \param group The group on which to poll connecting qpairs.
    3122             :  *
    3123             :  * return 0 if all qpairs are in CONNECTED state, -EIO if any connections failed to connect, -EAGAIN if
    3124             :  * any qpairs are still trying to connected.
    3125             :  */
    3126             : int spdk_nvme_poll_group_all_connected(struct spdk_nvme_poll_group *group);
    3127             : 
    3128             : /**
    3129             :  * Retrieve the user context for this specific poll group.
    3130             :  *
    3131             :  * \param group The poll group from which to retrieve the context.
    3132             :  *
    3133             :  * \return A pointer to the user provided poll group context.
    3134             :  */
    3135             : void *spdk_nvme_poll_group_get_ctx(struct spdk_nvme_poll_group *group);
    3136             : 
    3137             : /**
    3138             :  * Retrieves transport statistics for the given poll group.
    3139             :  *
    3140             :  * Note: the structure returned by this function should later be freed with
    3141             :  * @b spdk_nvme_poll_group_free_stats function
    3142             :  *
    3143             :  * \param group Pointer to NVME poll group
    3144             :  * \param stats Double pointer to statistics to be filled by this function
    3145             :  * \return 0 on success or negated errno on failure
    3146             :  */
    3147             : int spdk_nvme_poll_group_get_stats(struct spdk_nvme_poll_group *group,
    3148             :                                    struct spdk_nvme_poll_group_stat **stats);
    3149             : 
    3150             : /**
    3151             :  * Frees poll group statistics retrieved using @b spdk_nvme_poll_group_get_stats function
    3152             :  *
    3153             :  * @param group Pointer to a poll group
    3154             :  * @param stat Pointer to statistics to be released
    3155             :  */
    3156             : void spdk_nvme_poll_group_free_stats(struct spdk_nvme_poll_group *group,
    3157             :                                      struct spdk_nvme_poll_group_stat *stat);
    3158             : 
    3159             : /**
    3160             :  * Get the identify namespace data as defined by the NVMe specification.
    3161             :  *
    3162             :  * This function is thread safe and can be called at any point while the controller
    3163             :  * is attached to the SPDK NVMe driver.
    3164             :  *
    3165             :  * \param ns Namespace.
    3166             :  *
    3167             :  * \return a pointer to the namespace data.
    3168             :  */
    3169             : const struct spdk_nvme_ns_data *spdk_nvme_ns_get_data(struct spdk_nvme_ns *ns);
    3170             : 
    3171             : /**
    3172             :  * Get the I/O command set specific identify namespace data for NVM command set
    3173             :  * as defined by the NVMe specification.
    3174             :  *
    3175             :  * This function is thread safe and can be called at any point while the controller
    3176             :  * is attached to the SPDK NVMe driver.
    3177             :  *
    3178             :  * \param ns Namespace.
    3179             :  *
    3180             :  * \return a pointer to the identify namespace data.
    3181             :  */
    3182             : const struct spdk_nvme_nvm_ns_data *spdk_nvme_nvm_ns_get_data(struct spdk_nvme_ns *ns);
    3183             : 
    3184             : /**
    3185             :  * Get the namespace id (index number) from the given namespace handle.
    3186             :  *
    3187             :  * This function is thread safe and can be called at any point while the controller
    3188             :  * is attached to the SPDK NVMe driver.
    3189             :  *
    3190             :  * \param ns Namespace.
    3191             :  *
    3192             :  * \return namespace id.
    3193             :  */
    3194             : uint32_t spdk_nvme_ns_get_id(struct spdk_nvme_ns *ns);
    3195             : 
    3196             : /**
    3197             :  * Get the controller with which this namespace is associated.
    3198             :  *
    3199             :  * This function is thread safe and can be called at any point while the controller
    3200             :  * is attached to the SPDK NVMe driver.
    3201             :  *
    3202             :  * \param ns Namespace.
    3203             :  *
    3204             :  * \return a pointer to the controller.
    3205             :  */
    3206             : struct spdk_nvme_ctrlr *spdk_nvme_ns_get_ctrlr(struct spdk_nvme_ns *ns);
    3207             : 
    3208             : /**
    3209             :  * Determine whether a namespace is active.
    3210             :  *
    3211             :  * Inactive namespaces cannot be the target of I/O commands.
    3212             :  *
    3213             :  * \param ns Namespace to query.
    3214             :  *
    3215             :  * \return true if active, or false if inactive.
    3216             :  */
    3217             : bool spdk_nvme_ns_is_active(struct spdk_nvme_ns *ns);
    3218             : 
    3219             : /**
    3220             :  * Get the maximum transfer size, in bytes, for an I/O sent to the given namespace.
    3221             :  *
    3222             :  * This function is thread safe and can be called at any point while the controller
    3223             :  * is attached to the SPDK NVMe driver.
    3224             :  *
    3225             :  * \param ns Namespace to query.
    3226             :  *
    3227             :  * \return the maximum transfer size in bytes.
    3228             :  */
    3229             : uint32_t spdk_nvme_ns_get_max_io_xfer_size(struct spdk_nvme_ns *ns);
    3230             : 
    3231             : /**
    3232             :  * Get the sector size, in bytes, of the given namespace.
    3233             :  *
    3234             :  * This function returns the size of the data sector only.  It does not
    3235             :  * include metadata size.
    3236             :  *
    3237             :  * This function is thread safe and can be called at any point while the controller
    3238             :  * is attached to the SPDK NVMe driver.
    3239             :  *
    3240             :  * \param ns Namespace to query.
    3241             :  *
    3242             :  * /return the sector size in bytes.
    3243             :  */
    3244             : uint32_t spdk_nvme_ns_get_sector_size(struct spdk_nvme_ns *ns);
    3245             : 
    3246             : /**
    3247             :  * Get the extended sector size, in bytes, of the given namespace.
    3248             :  *
    3249             :  * This function returns the size of the data sector plus metadata.
    3250             :  *
    3251             :  * This function is thread safe and can be called at any point while the controller
    3252             :  * is attached to the SPDK NVMe driver.
    3253             :  *
    3254             :  * \param ns Namespace to query.
    3255             :  *
    3256             :  * /return the extended sector size in bytes.
    3257             :  */
    3258             : uint32_t spdk_nvme_ns_get_extended_sector_size(struct spdk_nvme_ns *ns);
    3259             : 
    3260             : /**
    3261             :  * Get the number of sectors for the given namespace.
    3262             :  *
    3263             :  * This function is thread safe and can be called at any point while the controller
    3264             :  * is attached to the SPDK NVMe driver.
    3265             :  *
    3266             :  * \param ns Namespace to query.
    3267             :  *
    3268             :  * \return the number of sectors.
    3269             :  */
    3270             : uint64_t spdk_nvme_ns_get_num_sectors(struct spdk_nvme_ns *ns);
    3271             : 
    3272             : /**
    3273             :  * Get the size, in bytes, of the given namespace.
    3274             :  *
    3275             :  * This function is thread safe and can be called at any point while the controller
    3276             :  * is attached to the SPDK NVMe driver.
    3277             :  *
    3278             :  * \param ns Namespace to query.
    3279             :  *
    3280             :  * \return the size of the given namespace in bytes.
    3281             :  */
    3282             : uint64_t spdk_nvme_ns_get_size(struct spdk_nvme_ns *ns);
    3283             : 
    3284             : /**
    3285             :  * Get the end-to-end data protection information type of the given namespace.
    3286             :  *
    3287             :  * This function is thread safe and can be called at any point while the controller
    3288             :  * is attached to the SPDK NVMe driver.
    3289             :  *
    3290             :  * \param ns Namespace to query.
    3291             :  *
    3292             :  * \return the end-to-end data protection information type.
    3293             :  */
    3294             : enum spdk_nvme_pi_type spdk_nvme_ns_get_pi_type(struct spdk_nvme_ns *ns);
    3295             : 
    3296             : /**
    3297             :  * Get the end-to-end data protection information format of the given namespace.
    3298             :  *
    3299             :  * This function is thread safe and can be called at any point while the controller
    3300             :  * is attached to the SPDK NVMe driver.
    3301             :  *
    3302             :  * \param ns Namespace to query.
    3303             :  *
    3304             :  * \return the end-to-end data protection information format.
    3305             :  */
    3306             : enum spdk_nvme_pi_format spdk_nvme_ns_get_pi_format(struct spdk_nvme_ns *ns);
    3307             : 
    3308             : /**
    3309             :  * Get the metadata size, in bytes, of the given namespace.
    3310             :  *
    3311             :  * This function is thread safe and can be called at any point while the controller
    3312             :  * is attached to the SPDK NVMe driver.
    3313             :  *
    3314             :  * \param ns Namespace to query.
    3315             :  *
    3316             :  * \return the metadata size of the given namespace in bytes.
    3317             :  */
    3318             : uint32_t spdk_nvme_ns_get_md_size(struct spdk_nvme_ns *ns);
    3319             : 
    3320             : /**
    3321             :  * Get the format index of the given namespace.
    3322             :  *
    3323             :  * This function is thread safe and can be called at any point while the controller
    3324             :  * is attached to the SPDK NVMe driver.
    3325             :  *
    3326             :  * \param nsdata pointer to the NVMe namespace data.
    3327             :  *
    3328             :  * \return the format index of the given namespace.
    3329             :  */
    3330             : uint32_t spdk_nvme_ns_get_format_index(const struct spdk_nvme_ns_data *nsdata);
    3331             : 
    3332             : /**
    3333             :  * Check whether if the namespace can support extended LBA when end-to-end data
    3334             :  * protection enabled.
    3335             :  *
    3336             :  * This function is thread safe and can be called at any point while the controller
    3337             :  * is attached to the SPDK NVMe driver.
    3338             :  *
    3339             :  * \param ns Namespace to query.
    3340             :  *
    3341             :  * \return true if the namespace can support extended LBA when end-to-end data
    3342             :  * protection enabled, or false otherwise.
    3343             :  */
    3344             : bool spdk_nvme_ns_supports_extended_lba(struct spdk_nvme_ns *ns);
    3345             : 
    3346             : /**
    3347             :  * Check whether if the namespace supports compare operation
    3348             :  *
    3349             :  * This function is thread safe and can be called at any point while the controller
    3350             :  * is attached to the SPDK NVMe driver.
    3351             :  *
    3352             :  * \param ns Namespace to query.
    3353             :  *
    3354             :  * \return true if the namespace supports compare operation, or false otherwise.
    3355             :  */
    3356             : bool spdk_nvme_ns_supports_compare(struct spdk_nvme_ns *ns);
    3357             : 
    3358             : /**
    3359             :  * Determine the value returned when reading deallocated blocks.
    3360             :  *
    3361             :  * If deallocated blocks return 0, the deallocate command can be used as a more
    3362             :  * efficient alternative to the write_zeroes command, especially for large requests.
    3363             :  *
    3364             :  * \param ns Namespace.
    3365             :  *
    3366             :  * \return the logical block read value.
    3367             :  */
    3368             : enum spdk_nvme_dealloc_logical_block_read_value spdk_nvme_ns_get_dealloc_logical_block_read_value(
    3369             :         struct spdk_nvme_ns *ns);
    3370             : 
    3371             : /**
    3372             :  * Get the optimal I/O boundary, in blocks, for the given namespace.
    3373             :  *
    3374             :  * Read and write commands should not cross the optimal I/O boundary for best
    3375             :  * performance.
    3376             :  *
    3377             :  * \param ns Namespace to query.
    3378             :  *
    3379             :  * \return Optimal granularity of I/O commands, in blocks, or 0 if no optimal
    3380             :  * granularity is reported.
    3381             :  */
    3382             : uint32_t spdk_nvme_ns_get_optimal_io_boundary(struct spdk_nvme_ns *ns);
    3383             : 
    3384             : /**
    3385             :  * Get the NGUID for the given namespace.
    3386             :  *
    3387             :  * \param ns Namespace to query.
    3388             :  *
    3389             :  * \return a pointer to namespace NGUID, or NULL if ns does not have a NGUID.
    3390             :  */
    3391             : const uint8_t *spdk_nvme_ns_get_nguid(const struct spdk_nvme_ns *ns);
    3392             : 
    3393             : /**
    3394             :  * Get the UUID for the given namespace.
    3395             :  *
    3396             :  * \param ns Namespace to query.
    3397             :  *
    3398             :  * \return a pointer to namespace UUID, or NULL if ns does not have a UUID.
    3399             :  */
    3400             : const struct spdk_uuid *spdk_nvme_ns_get_uuid(const struct spdk_nvme_ns *ns);
    3401             : 
    3402             : /**
    3403             :  * Get the Command Set Identifier for the given namespace.
    3404             :  *
    3405             :  * \param ns Namespace to query.
    3406             :  *
    3407             :  * \return the namespace Command Set Identifier.
    3408             :  */
    3409             : enum spdk_nvme_csi spdk_nvme_ns_get_csi(const struct spdk_nvme_ns *ns);
    3410             : 
    3411             : /**
    3412             :  * \brief Namespace command support flags.
    3413             :  */
    3414             : enum spdk_nvme_ns_flags {
    3415             :         SPDK_NVME_NS_DEALLOCATE_SUPPORTED       = 1 << 0, /**< The deallocate command is supported */
    3416             :         SPDK_NVME_NS_FLUSH_SUPPORTED            = 1 << 1, /**< The flush command is supported */
    3417             :         SPDK_NVME_NS_RESERVATION_SUPPORTED      = 1 << 2, /**< The reservation command is supported */
    3418             :         SPDK_NVME_NS_WRITE_ZEROES_SUPPORTED     = 1 << 3, /**< The write zeroes command is supported */
    3419             :         SPDK_NVME_NS_DPS_PI_SUPPORTED           = 1 << 4, /**< The end-to-end data protection is supported */
    3420             :         SPDK_NVME_NS_EXTENDED_LBA_SUPPORTED     = 1 << 5, /**< The extended lba format is supported,
    3421             :                                                               metadata is transferred as a contiguous
    3422             :                                                               part of the logical block that it is associated with */
    3423             :         SPDK_NVME_NS_WRITE_UNCORRECTABLE_SUPPORTED      = 1 << 6, /**< The write uncorrectable command is supported */
    3424             :         SPDK_NVME_NS_COMPARE_SUPPORTED          = 1 << 7, /**< The compare command is supported */
    3425             : };
    3426             : 
    3427             : /**
    3428             :  * Get the flags for the given namespace.
    3429             :  *
    3430             :  * See spdk_nvme_ns_flags for the possible flags returned.
    3431             :  *
    3432             :  * This function is thread safe and can be called at any point while the controller
    3433             :  * is attached to the SPDK NVMe driver.
    3434             :  *
    3435             :  * \param ns Namespace to query.
    3436             :  *
    3437             :  * \return the flags for the given namespace.
    3438             :  */
    3439             : uint32_t spdk_nvme_ns_get_flags(struct spdk_nvme_ns *ns);
    3440             : 
    3441             : /**
    3442             :  * Get the ANA group ID for the given namespace.
    3443             :  *
    3444             :  * This function should be called only if spdk_nvme_ctrlr_is_log_page_supported() returns
    3445             :  * true for the controller and log page ID SPDK_NVME_LOG_ASYMMETRIC_NAMESPACE_ACCESS.
    3446             :  *
    3447             :  * This function is thread safe and can be called at any point while the controller
    3448             :  * is attached to the SPDK NVMe driver.
    3449             :  *
    3450             :  * \param ns Namespace to query.
    3451             :  *
    3452             :  * \return the ANA group ID for the given namespace.
    3453             :  */
    3454             : uint32_t spdk_nvme_ns_get_ana_group_id(const struct spdk_nvme_ns *ns);
    3455             : 
    3456             : /**
    3457             :  * Get the ANA state for the given namespace.
    3458             :  *
    3459             :  * This function should be called only if spdk_nvme_ctrlr_is_log_page_supported() returns
    3460             :  * true for the controller and log page ID SPDK_NVME_LOG_ASYMMETRIC_NAMESPACE_ACCESS.
    3461             :  *
    3462             :  * This function is thread safe and can be called at any point while the controller
    3463             :  * is attached to the SPDK NVMe driver.
    3464             :  *
    3465             :  * \param ns Namespace to query.
    3466             :  *
    3467             :  * \return the ANA state for the given namespace.
    3468             :  */
    3469             : enum spdk_nvme_ana_state spdk_nvme_ns_get_ana_state(const struct spdk_nvme_ns *ns);
    3470             : 
    3471             : /**
    3472             :  * Submit a write I/O to the specified NVMe namespace.
    3473             :  *
    3474             :  * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
    3475             :  * The user must ensure that only one thread submits I/O on a given qpair at any
    3476             :  * given time.
    3477             :  *
    3478             :  * \param ns NVMe namespace to submit the write I/O.
    3479             :  * \param qpair I/O queue pair to submit the request.
    3480             :  * \param payload Virtual address pointer to the data payload.
    3481             :  * \param lba Starting LBA to write the data.
    3482             :  * \param lba_count Length (in sectors) for the write operation.
    3483             :  * \param cb_fn Callback function to invoke when the I/O is completed.
    3484             :  * \param cb_arg Argument to pass to the callback function.
    3485             :  * \param io_flags Set flags, defined by the SPDK_NVME_IO_FLAGS_* entries in
    3486             :  * spdk/nvme_spec.h, for this I/O.
    3487             :  *
    3488             :  * \return 0 if successfully submitted, negated errnos on the following error conditions:
    3489             :  * -EINVAL: The request is malformed.
    3490             :  * -ENOMEM: The request cannot be allocated.
    3491             :  * -ENXIO: The qpair is failed at the transport level.
    3492             :  */
    3493             : int spdk_nvme_ns_cmd_write(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair, void *payload,
    3494             :                            uint64_t lba, uint32_t lba_count, spdk_nvme_cmd_cb cb_fn,
    3495             :                            void *cb_arg, uint32_t io_flags);
    3496             : 
    3497             : /**
    3498             :  * Submit a write I/O to the specified NVMe namespace.
    3499             :  *
    3500             :  * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
    3501             :  * The user must ensure that only one thread submits I/O on a given qpair at any
    3502             :  * given time.
    3503             :  *
    3504             :  * \param ns NVMe namespace to submit the write I/O.
    3505             :  * \param qpair I/O queue pair to submit the request.
    3506             :  * \param lba Starting LBA to write the data.
    3507             :  * \param lba_count Length (in sectors) for the write operation.
    3508             :  * \param cb_fn Callback function to invoke when the I/O is completed.
    3509             :  * \param cb_arg Argument to pass to the callback function.
    3510             :  * \param io_flags Set flags, defined in nvme_spec.h, for this I/O.
    3511             :  * \param reset_sgl_fn Callback function to reset scattered payload.
    3512             :  * \param next_sge_fn Callback function to iterate each scattered payload memory
    3513             :  * segment.
    3514             :  *
    3515             :  * \return 0 if successfully submitted, negated errnos on the following error conditions:
    3516             :  * -EINVAL: The request is malformed.
    3517             :  * -ENOMEM: The request cannot be allocated.
    3518             :  * -ENXIO: The qpair is failed at the transport level.
    3519             :  */
    3520             : int spdk_nvme_ns_cmd_writev(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
    3521             :                             uint64_t lba, uint32_t lba_count,
    3522             :                             spdk_nvme_cmd_cb cb_fn, void *cb_arg, uint32_t io_flags,
    3523             :                             spdk_nvme_req_reset_sgl_cb reset_sgl_fn,
    3524             :                             spdk_nvme_req_next_sge_cb next_sge_fn);
    3525             : 
    3526             : /**
    3527             :  * Submit a write I/O to the specified NVMe namespace.
    3528             :  *
    3529             :  * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
    3530             :  * The user must ensure that only one thread submits I/O on a given qpair at any
    3531             :  * given time.
    3532             :  *
    3533             :  * \param ns NVMe namespace to submit the write I/O
    3534             :  * \param qpair I/O queue pair to submit the request
    3535             :  * \param lba starting LBA to write the data
    3536             :  * \param lba_count length (in sectors) for the write operation
    3537             :  * \param cb_fn callback function to invoke when the I/O is completed
    3538             :  * \param cb_arg argument to pass to the callback function
    3539             :  * \param io_flags set flags, defined in nvme_spec.h, for this I/O
    3540             :  * \param reset_sgl_fn callback function to reset scattered payload
    3541             :  * \param next_sge_fn callback function to iterate each scattered
    3542             :  * payload memory segment
    3543             :  * \param metadata virtual address pointer to the metadata payload, the length
    3544             :  * of metadata is specified by spdk_nvme_ns_get_md_size()
    3545             :  * \param apptag_mask application tag mask.
    3546             :  * \param apptag application tag to use end-to-end protection information.
    3547             :  *
    3548             :  * \return 0 if successfully submitted, negated errnos on the following error conditions:
    3549             :  * -EINVAL: The request is malformed.
    3550             :  * -ENOMEM: The request cannot be allocated.
    3551             :  * -ENXIO: The qpair is failed at the transport level.
    3552             :  */
    3553             : int spdk_nvme_ns_cmd_writev_with_md(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
    3554             :                                     uint64_t lba, uint32_t lba_count,
    3555             :                                     spdk_nvme_cmd_cb cb_fn, void *cb_arg, uint32_t io_flags,
    3556             :                                     spdk_nvme_req_reset_sgl_cb reset_sgl_fn,
    3557             :                                     spdk_nvme_req_next_sge_cb next_sge_fn, void *metadata,
    3558             :                                     uint16_t apptag_mask, uint16_t apptag);
    3559             : 
    3560             : /**
    3561             :  * Submit a write I/O to the specified NVMe namespace.
    3562             :  *
    3563             :  * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
    3564             :  * The user must ensure that only one thread submits I/O on a given qpair at any
    3565             :  * given time.
    3566             :  *
    3567             :  * \param ns NVMe namespace to submit the write I/O
    3568             :  * \param qpair I/O queue pair to submit the request
    3569             :  * \param lba starting LBA to write the data
    3570             :  * \param lba_count length (in sectors) for the write operation
    3571             :  * \param cb_fn callback function to invoke when the I/O is completed
    3572             :  * \param cb_arg argument to pass to the callback function
    3573             :  * \param reset_sgl_fn callback function to reset scattered payload
    3574             :  * \param next_sge_fn callback function to iterate each scattered
    3575             :  * payload memory segment
    3576             :  * \param opts Optional structure with extended IO request options. If provided, the caller must
    3577             :  * guarantee that this structure is accessible until IO completes
    3578             :  *
    3579             :  * \return 0 if successfully submitted, negated errnos on the following error conditions:
    3580             :  * -EINVAL: The request is malformed.
    3581             :  * -ENOMEM: The request cannot be allocated.
    3582             :  * -ENXIO: The qpair is failed at the transport level.
    3583             :  * -EFAULT: Invalid address was specified as part of payload.  cb_fn is also called
    3584             :  *          with error status including dnr=1 in this case.
    3585             :  */
    3586             : int spdk_nvme_ns_cmd_writev_ext(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
    3587             :                                 uint64_t lba, uint32_t lba_count,
    3588             :                                 spdk_nvme_cmd_cb cb_fn, void *cb_arg,
    3589             :                                 spdk_nvme_req_reset_sgl_cb reset_sgl_fn,
    3590             :                                 spdk_nvme_req_next_sge_cb next_sge_fn,
    3591             :                                 struct spdk_nvme_ns_cmd_ext_io_opts *opts);
    3592             : 
    3593             : /**
    3594             :  * Submit a write I/O to the specified NVMe namespace.
    3595             :  *
    3596             :  * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
    3597             :  * The user must ensure that only one thread submits I/O on a given qpair at any
    3598             :  * given time.
    3599             :  *
    3600             :  * \param ns NVMe namespace to submit the write I/O
    3601             :  * \param qpair I/O queue pair to submit the request
    3602             :  * \param payload Virtual address pointer to the data payload.
    3603             :  * \param lba starting LBA to write the data
    3604             :  * \param lba_count length (in sectors) for the write operation
    3605             :  * \param cb_fn callback function to invoke when the I/O is completed
    3606             :  * \param cb_arg argument to pass to the callback function
    3607             :  * \param opts Optional structure with extended IO request options. If provided, the caller must
    3608             :  * guarantee that this structure is accessible until IO completes
    3609             :  *
    3610             :  * \return 0 if successfully submitted, negated errnos on the following error conditions:
    3611             :  * -EINVAL: The request is malformed.
    3612             :  * -ENOMEM: The request cannot be allocated.
    3613             :  * -ENXIO: The qpair is failed at the transport level.
    3614             :  * -EFAULT: Invalid address was specified as part of payload.  cb_fn is also called
    3615             :  *          with error status including dnr=1 in this case.
    3616             :  */
    3617             : int spdk_nvme_ns_cmd_write_ext(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
    3618             :                                void *payload, uint64_t lba, uint32_t lba_count, spdk_nvme_cmd_cb cb_fn, void *cb_arg,
    3619             :                                struct spdk_nvme_ns_cmd_ext_io_opts *opts);
    3620             : 
    3621             : /**
    3622             :  * Submit a write I/O to the specified NVMe namespace.
    3623             :  *
    3624             :  * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
    3625             :  * The user must ensure that only one thread submits I/O on a given qpair at any
    3626             :  * given time.
    3627             :  *
    3628             :  * \param ns NVMe namespace to submit the write I/O.
    3629             :  * \param qpair I/O queue pair to submit the request.
    3630             :  * \param payload Virtual address pointer to the data payload.
    3631             :  * \param metadata Virtual address pointer to the metadata payload, the length
    3632             :  * of metadata is specified by spdk_nvme_ns_get_md_size().
    3633             :  * \param lba Starting LBA to write the data.
    3634             :  * \param lba_count Length (in sectors) for the write operation.
    3635             :  * \param cb_fn Callback function to invoke when the I/O is completed.
    3636             :  * \param cb_arg Argument to pass to the callback function.
    3637             :  * \param io_flags Set flags, defined by the SPDK_NVME_IO_FLAGS_* entries in
    3638             :  * spdk/nvme_spec.h, for this I/O.
    3639             :  * \param apptag_mask Application tag mask.
    3640             :  * \param apptag Application tag to use end-to-end protection information.
    3641             :  *
    3642             :  * \return 0 if successfully submitted, negated errnos on the following error conditions:
    3643             :  * -EINVAL: The request is malformed.
    3644             :  * -ENOMEM: The request cannot be allocated.
    3645             :  * -ENXIO: The qpair is failed at the transport level.
    3646             :  */
    3647             : int spdk_nvme_ns_cmd_write_with_md(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
    3648             :                                    void *payload, void *metadata,
    3649             :                                    uint64_t lba, uint32_t lba_count, spdk_nvme_cmd_cb cb_fn,
    3650             :                                    void *cb_arg, uint32_t io_flags,
    3651             :                                    uint16_t apptag_mask, uint16_t apptag);
    3652             : 
    3653             : /**
    3654             :  * Submit a write zeroes I/O to the specified NVMe namespace.
    3655             :  *
    3656             :  * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
    3657             :  * The user must ensure that only one thread submits I/O on a given qpair at any
    3658             :  * given time.
    3659             :  *
    3660             :  * \param ns NVMe namespace to submit the write zeroes I/O.
    3661             :  * \param qpair I/O queue pair to submit the request.
    3662             :  * \param lba Starting LBA for this command.
    3663             :  * \param lba_count Length (in sectors) for the write zero operation.
    3664             :  * \param cb_fn Callback function to invoke when the I/O is completed.
    3665             :  * \param cb_arg Argument to pass to the callback function.
    3666             :  * \param io_flags Set flags, defined by the SPDK_NVME_IO_FLAGS_* entries in
    3667             :  * spdk/nvme_spec.h, for this I/O.
    3668             :  *
    3669             :  * \return 0 if successfully submitted, negated errnos on the following error conditions:
    3670             :  * -EINVAL: The request is malformed.
    3671             :  * -ENOMEM: The request cannot be allocated.
    3672             :  * -ENXIO: The qpair is failed at the transport level.
    3673             :  */
    3674             : int spdk_nvme_ns_cmd_write_zeroes(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
    3675             :                                   uint64_t lba, uint32_t lba_count,
    3676             :                                   spdk_nvme_cmd_cb cb_fn, void *cb_arg,
    3677             :                                   uint32_t io_flags);
    3678             : 
    3679             : /**
    3680             :  * Submit a verify I/O to the specified NVMe namespace.
    3681             :  *
    3682             :  * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
    3683             :  * The user must ensure that only one thread submits I/O on a given qpair at any
    3684             :  * given time.
    3685             :  *
    3686             :  * \param ns NVMe namespace to submit the verify I/O.
    3687             :  * \param qpair I/O queue pair to submit the request.
    3688             :  * \param lba Starting LBA to verify the data.
    3689             :  * \param lba_count Length (in sectors) for the verify operation.
    3690             :  * \param cb_fn Callback function to invoke when the I/O is completed.
    3691             :  * \param cb_arg Argument to pass to the callback function.
    3692             :  * \param io_flags Set flags, defined by the SPDK_NVME_IO_FLAGS_* entries in
    3693             :  * spdk/nvme_spec.h, for this I/O.
    3694             :  *
    3695             :  * \return 0 if successfully submitted, negated errnos on the following error conditions:
    3696             :  * -EINVAL: The request is malformed.
    3697             :  * -ENOMEM: The request cannot be allocated.
    3698             :  * -ENXIO: The qpair is failed at the transport level.
    3699             :  */
    3700             : int spdk_nvme_ns_cmd_verify(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
    3701             :                             uint64_t lba, uint32_t lba_count,
    3702             :                             spdk_nvme_cmd_cb cb_fn, void *cb_arg,
    3703             :                             uint32_t io_flags);
    3704             : 
    3705             : /**
    3706             :  * Submit a write uncorrectable I/O to the specified NVMe namespace.
    3707             :  *
    3708             :  * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
    3709             :  * The user must ensure that only one thread submits I/O on a given qpair at any
    3710             :  * given time.
    3711             :  *
    3712             :  * \param ns NVMe namespace to submit the write uncorrectable I/O.
    3713             :  * \param qpair I/O queue pair to submit the request.
    3714             :  * \param lba Starting LBA for this command.
    3715             :  * \param lba_count Length (in sectors) for the write uncorrectable operation.
    3716             :  * \param cb_fn Callback function to invoke when the I/O is completed.
    3717             :  * \param cb_arg Argument to pass to the callback function.
    3718             :  *
    3719             :  * \return 0 if successfully submitted, negated errnos on the following error conditions:
    3720             :  * -EINVAL: The request is malformed.
    3721             :  * -ENOMEM: The request cannot be allocated.
    3722             :  * -ENXIO: The qpair is failed at the transport level.
    3723             :  */
    3724             : int spdk_nvme_ns_cmd_write_uncorrectable(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
    3725             :                 uint64_t lba, uint32_t lba_count,
    3726             :                 spdk_nvme_cmd_cb cb_fn, void *cb_arg);
    3727             : 
    3728             : /**
    3729             :  * \brief Submits a read I/O to the specified NVMe namespace.
    3730             :  *
    3731             :  * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
    3732             :  * The user must ensure that only one thread submits I/O on a given qpair at any
    3733             :  * given time.
    3734             :  *
    3735             :  * \param ns NVMe namespace to submit the read I/O.
    3736             :  * \param qpair I/O queue pair to submit the request.
    3737             :  * \param payload Virtual address pointer to the data payload.
    3738             :  * \param lba Starting LBA to read the data.
    3739             :  * \param lba_count Length (in sectors) for the read operation.
    3740             :  * \param cb_fn Callback function to invoke when the I/O is completed.
    3741             :  * \param cb_arg Argument to pass to the callback function.
    3742             :  * \param io_flags Set flags, defined in nvme_spec.h, for this I/O.
    3743             :  *
    3744             :  * \return 0 if successfully submitted, negated errnos on the following error conditions:
    3745             :  * -EINVAL: The request is malformed.
    3746             :  * -ENOMEM: The request cannot be allocated.
    3747             :  * -ENXIO: The qpair is failed at the transport level.
    3748             :  */
    3749             : int spdk_nvme_ns_cmd_read(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair, void *payload,
    3750             :                           uint64_t lba, uint32_t lba_count, spdk_nvme_cmd_cb cb_fn,
    3751             :                           void *cb_arg, uint32_t io_flags);
    3752             : 
    3753             : /**
    3754             :  * Submit a read I/O to the specified NVMe namespace.
    3755             :  *
    3756             :  * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
    3757             :  * The user must ensure that only one thread submits I/O on a given qpair at any
    3758             :  * given time.
    3759             :  *
    3760             :  * \param ns NVMe namespace to submit the read I/O.
    3761             :  * \param qpair I/O queue pair to submit the request.
    3762             :  * \param lba Starting LBA to read the data.
    3763             :  * \param lba_count Length (in sectors) for the read operation.
    3764             :  * \param cb_fn Callback function to invoke when the I/O is completed.
    3765             :  * \param cb_arg Argument to pass to the callback function.
    3766             :  * \param io_flags Set flags, defined in nvme_spec.h, for this I/O.
    3767             :  * \param reset_sgl_fn Callback function to reset scattered payload.
    3768             :  * \param next_sge_fn Callback function to iterate each scattered payload memory
    3769             :  * segment.
    3770             :  *
    3771             :  * \return 0 if successfully submitted, negated errnos on the following error conditions:
    3772             :  * -EINVAL: The request is malformed.
    3773             :  * -ENOMEM: The request cannot be allocated.
    3774             :  * -ENXIO: The qpair is failed at the transport level.
    3775             :  */
    3776             : int spdk_nvme_ns_cmd_readv(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
    3777             :                            uint64_t lba, uint32_t lba_count,
    3778             :                            spdk_nvme_cmd_cb cb_fn, void *cb_arg, uint32_t io_flags,
    3779             :                            spdk_nvme_req_reset_sgl_cb reset_sgl_fn,
    3780             :                            spdk_nvme_req_next_sge_cb next_sge_fn);
    3781             : 
    3782             : /**
    3783             :  * Submit a read I/O to the specified NVMe namespace.
    3784             :  *
    3785             :  * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
    3786             :  * The user must ensure that only one thread submits I/O on a given qpair at any given time.
    3787             :  *
    3788             :  * \param ns NVMe namespace to submit the read I/O
    3789             :  * \param qpair I/O queue pair to submit the request
    3790             :  * \param lba starting LBA to read the data
    3791             :  * \param lba_count length (in sectors) for the read operation
    3792             :  * \param cb_fn callback function to invoke when the I/O is completed
    3793             :  * \param cb_arg argument to pass to the callback function
    3794             :  * \param io_flags set flags, defined in nvme_spec.h, for this I/O
    3795             :  * \param reset_sgl_fn callback function to reset scattered payload
    3796             :  * \param next_sge_fn callback function to iterate each scattered
    3797             :  * payload memory segment
    3798             :  * \param metadata virtual address pointer to the metadata payload, the length
    3799             :  *                 of metadata is specified by spdk_nvme_ns_get_md_size()
    3800             :  * \param apptag_mask application tag mask.
    3801             :  * \param apptag application tag to use end-to-end protection information.
    3802             :  *
    3803             :  * \return 0 if successfully submitted, negated errnos on the following error conditions:
    3804             :  * -EINVAL: The request is malformed.
    3805             :  * -ENOMEM: The request cannot be allocated.
    3806             :  * -ENXIO: The qpair is failed at the transport level.
    3807             :  */
    3808             : int spdk_nvme_ns_cmd_readv_with_md(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
    3809             :                                    uint64_t lba, uint32_t lba_count,
    3810             :                                    spdk_nvme_cmd_cb cb_fn, void *cb_arg, uint32_t io_flags,
    3811             :                                    spdk_nvme_req_reset_sgl_cb reset_sgl_fn,
    3812             :                                    spdk_nvme_req_next_sge_cb next_sge_fn, void *metadata,
    3813             :                                    uint16_t apptag_mask, uint16_t apptag);
    3814             : 
    3815             : /**
    3816             :  * Submit a read I/O to the specified NVMe namespace.
    3817             :  *
    3818             :  * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
    3819             :  * The user must ensure that only one thread submits I/O on a given qpair at any given time.
    3820             :  *
    3821             :  * \param ns NVMe namespace to submit the read I/O
    3822             :  * \param qpair I/O queue pair to submit the request
    3823             :  * \param lba starting LBA to read the data
    3824             :  * \param lba_count length (in sectors) for the read operation
    3825             :  * \param cb_fn callback function to invoke when the I/O is completed
    3826             :  * \param cb_arg argument to pass to the callback function
    3827             :  * \param reset_sgl_fn callback function to reset scattered payload
    3828             :  * \param next_sge_fn callback function to iterate each scattered
    3829             :  * payload memory segment
    3830             :  * \param opts Optional structure with extended IO request options. If provided, the caller must
    3831             :  * guarantee that this structure is accessible until IO completes
    3832             :  *
    3833             :  * \return 0 if successfully submitted, negated errnos on the following error conditions:
    3834             :  * -EINVAL: The request is malformed.
    3835             :  * -ENOMEM: The request cannot be allocated.
    3836             :  * -ENXIO: The qpair is failed at the transport level.
    3837             :  * -EFAULT: Invalid address was specified as part of payload.  cb_fn is also called
    3838             :  *          with error status including dnr=1 in this case.
    3839             :  */
    3840             : int spdk_nvme_ns_cmd_readv_ext(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
    3841             :                                uint64_t lba, uint32_t lba_count, spdk_nvme_cmd_cb cb_fn,
    3842             :                                void *cb_arg, spdk_nvme_req_reset_sgl_cb reset_sgl_fn,
    3843             :                                spdk_nvme_req_next_sge_cb next_sge_fn,
    3844             :                                struct spdk_nvme_ns_cmd_ext_io_opts *opts);
    3845             : 
    3846             : /**
    3847             :  * Submit a read I/O to the specified NVMe namespace.
    3848             :  *
    3849             :  * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
    3850             :  * The user must ensure that only one thread submits I/O on a given qpair at any given time.
    3851             :  *
    3852             :  * \param ns NVMe namespace to submit the read I/O
    3853             :  * \param qpair I/O queue pair to submit the request
    3854             :  * \param payload virtual address pointer to the data payload
    3855             :  * \param lba starting LBA to read the data
    3856             :  * \param lba_count length (in sectors) for the read operation
    3857             :  * \param cb_fn callback function to invoke when the I/O is completed
    3858             :  * \param cb_arg argument to pass to the callback function
    3859             :  * \param opts Optional structure with extended IO request options. If provided, the caller must
    3860             :  * guarantee that this structure is accessible until IO completes
    3861             :  *
    3862             :  * \return 0 if successfully submitted, negated errnos on the following error conditions:
    3863             :  * -EINVAL: The request is malformed.
    3864             :  * -ENOMEM: The request cannot be allocated.
    3865             :  * -ENXIO: The qpair is failed at the transport level.
    3866             :  * -EFAULT: Invalid address was specified as part of payload.  cb_fn is also called
    3867             :  *          with error status including dnr=1 in this case.
    3868             :  */
    3869             : int spdk_nvme_ns_cmd_read_ext(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair, void *payload,
    3870             :                               uint64_t lba, uint32_t lba_count, spdk_nvme_cmd_cb cb_fn, void *cb_arg,
    3871             :                               struct spdk_nvme_ns_cmd_ext_io_opts *opts);
    3872             : 
    3873             : /**
    3874             :  * Submits a read I/O to the specified NVMe namespace.
    3875             :  *
    3876             :  * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
    3877             :  * The user must ensure that only one thread submits I/O on a given qpair at any
    3878             :  * given time.
    3879             :  *
    3880             :  * \param ns NVMe namespace to submit the read I/O
    3881             :  * \param qpair I/O queue pair to submit the request
    3882             :  * \param payload virtual address pointer to the data payload
    3883             :  * \param metadata virtual address pointer to the metadata payload, the length
    3884             :  * of metadata is specified by spdk_nvme_ns_get_md_size().
    3885             :  * \param lba starting LBA to read the data.
    3886             :  * \param lba_count Length (in sectors) for the read operation.
    3887             :  * \param cb_fn Callback function to invoke when the I/O is completed.
    3888             :  * \param cb_arg Argument to pass to the callback function.
    3889             :  * \param io_flags Set flags, defined in nvme_spec.h, for this I/O.
    3890             :  * \param apptag_mask Application tag mask.
    3891             :  * \param apptag Application tag to use end-to-end protection information.
    3892             :  *
    3893             :  * \return 0 if successfully submitted, negated errnos on the following error conditions:
    3894             :  * -EINVAL: The request is malformed.
    3895             :  * -ENOMEM: The request cannot be allocated.
    3896             :  * -ENXIO: The qpair is failed at the transport level.
    3897             :  */
    3898             : int spdk_nvme_ns_cmd_read_with_md(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
    3899             :                                   void *payload, void *metadata,
    3900             :                                   uint64_t lba, uint32_t lba_count, spdk_nvme_cmd_cb cb_fn,
    3901             :                                   void *cb_arg, uint32_t io_flags,
    3902             :                                   uint16_t apptag_mask, uint16_t apptag);
    3903             : 
    3904             : /**
    3905             :  * Submit a data set management request to the specified NVMe namespace.
    3906             :  *
    3907             :  * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
    3908             :  * The user must ensure that only one thread submits I/O on a given qpair at any
    3909             :  * given time.
    3910             :  *
    3911             :  * This is a convenience wrapper that will automatically allocate and construct
    3912             :  * the correct data buffers. Therefore, ranges does not need to be allocated from
    3913             :  * pinned memory and can be placed on the stack. If a higher performance, zero-copy
    3914             :  * version of DSM is required, simply build and submit a raw command using
    3915             :  * spdk_nvme_ctrlr_cmd_io_raw().
    3916             :  *
    3917             :  * \param ns NVMe namespace to submit the DSM request
    3918             :  * \param type A bit field constructed from \ref spdk_nvme_dsm_attribute.
    3919             :  * \param qpair I/O queue pair to submit the request
    3920             :  * \param ranges An array of \ref spdk_nvme_dsm_range elements describing the LBAs
    3921             :  * to operate on.
    3922             :  * \param num_ranges The number of elements in the ranges array.
    3923             :  * \param cb_fn Callback function to invoke when the I/O is completed
    3924             :  * \param cb_arg Argument to pass to the callback function
    3925             :  *
    3926             :  * \return 0 if successfully submitted, negated errnos on the following error conditions:
    3927             :  * -ENOMEM: The request cannot be allocated.
    3928             :  * -ENXIO: The qpair is failed at the transport level.
    3929             :  */
    3930             : int spdk_nvme_ns_cmd_dataset_management(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
    3931             :                                         uint32_t type,
    3932             :                                         const struct spdk_nvme_dsm_range *ranges,
    3933             :                                         uint16_t num_ranges,
    3934             :                                         spdk_nvme_cmd_cb cb_fn,
    3935             :                                         void *cb_arg);
    3936             : 
    3937             : /**
    3938             :  * Submit a simple copy command request to the specified NVMe namespace.
    3939             :  *
    3940             :  * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
    3941             :  * The user must ensure that only one thread submits I/O on a given qpair at any
    3942             :  * given time.
    3943             :  *
    3944             :  * This is a convenience wrapper that will automatically allocate and construct
    3945             :  * the correct data buffers. Therefore, ranges does not need to be allocated from
    3946             :  * pinned memory and can be placed on the stack. If a higher performance, zero-copy
    3947             :  * version of SCC is required, simply build and submit a raw command using
    3948             :  * spdk_nvme_ctrlr_cmd_io_raw().
    3949             :  *
    3950             :  * \param ns NVMe namespace to submit the SCC request
    3951             :  * \param qpair I/O queue pair to submit the request
    3952             :  * \param ranges An array of \ref spdk_nvme_scc_source_range elements describing the LBAs
    3953             :  * to operate on.
    3954             :  * \param num_ranges The number of elements in the ranges array.
    3955             :  * \param dest_lba Destination LBA to copy the data.
    3956             :  * \param cb_fn Callback function to invoke when the I/O is completed
    3957             :  * \param cb_arg Argument to pass to the callback function
    3958             :  *
    3959             :  * \return 0 if successfully submitted, negated errnos on the following error conditions:
    3960             :  * -ENOMEM: The request cannot be allocated.
    3961             :  * -EINVAL: Invalid ranges.
    3962             :  * -ENXIO: The qpair is failed at the transport level.
    3963             :  */
    3964             : int spdk_nvme_ns_cmd_copy(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
    3965             :                           const struct spdk_nvme_scc_source_range *ranges,
    3966             :                           uint16_t num_ranges,
    3967             :                           uint64_t dest_lba,
    3968             :                           spdk_nvme_cmd_cb cb_fn,
    3969             :                           void *cb_arg);
    3970             : 
    3971             : /**
    3972             :  * Submit a flush request to the specified NVMe namespace.
    3973             :  *
    3974             :  * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
    3975             :  * The user must ensure that only one thread submits I/O on a given qpair at any
    3976             :  * given time.
    3977             :  *
    3978             :  * \param ns NVMe namespace to submit the flush request.
    3979             :  * \param qpair I/O queue pair to submit the request.
    3980             :  * \param cb_fn Callback function to invoke when the I/O is completed.
    3981             :  * \param cb_arg Argument to pass to the callback function.
    3982             :  *
    3983             :  * \return 0 if successfully submitted, negated errnos on the following error conditions:
    3984             :  * -ENOMEM: The request cannot be allocated.
    3985             :  * -ENXIO: The qpair is failed at the transport level.
    3986             :  */
    3987             : int spdk_nvme_ns_cmd_flush(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
    3988             :                            spdk_nvme_cmd_cb cb_fn, void *cb_arg);
    3989             : 
    3990             : /**
    3991             :  * Submit a reservation register to the specified NVMe namespace.
    3992             :  *
    3993             :  * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
    3994             :  * The user must ensure that only one thread submits I/O on a given qpair at any
    3995             :  * given time.
    3996             :  *
    3997             :  * \param ns NVMe namespace to submit the reservation register request.
    3998             :  * \param qpair I/O queue pair to submit the request.
    3999             :  * \param payload Virtual address pointer to the reservation register data.
    4000             :  * \param ignore_key '1' the current reservation key check is disabled.
    4001             :  * \param action Specifies the registration action.
    4002             :  * \param cptpl Change the Persist Through Power Loss state.
    4003             :  * \param cb_fn Callback function to invoke when the I/O is completed.
    4004             :  * \param cb_arg Argument to pass to the callback function.
    4005             :  *
    4006             :  * \return 0 if successfully submitted, negated errnos on the following error conditions:
    4007             :  * -ENOMEM: The request cannot be allocated.
    4008             :  * -ENXIO: The qpair is failed at the transport level.
    4009             :  */
    4010             : int spdk_nvme_ns_cmd_reservation_register(struct spdk_nvme_ns *ns,
    4011             :                 struct spdk_nvme_qpair *qpair,
    4012             :                 struct spdk_nvme_reservation_register_data *payload,
    4013             :                 bool ignore_key,
    4014             :                 enum spdk_nvme_reservation_register_action action,
    4015             :                 enum spdk_nvme_reservation_register_cptpl cptpl,
    4016             :                 spdk_nvme_cmd_cb cb_fn, void *cb_arg);
    4017             : 
    4018             : /**
    4019             :  * Submits a reservation release to the specified NVMe namespace.
    4020             :  *
    4021             :  * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
    4022             :  * The user must ensure that only one thread submits I/O on a given qpair at any
    4023             :  * given time.
    4024             :  *
    4025             :  * \param ns NVMe namespace to submit the reservation release request.
    4026             :  * \param qpair I/O queue pair to submit the request.
    4027             :  * \param payload Virtual address pointer to current reservation key.
    4028             :  * \param ignore_key '1' the current reservation key check is disabled.
    4029             :  * \param action Specifies the reservation release action.
    4030             :  * \param type Reservation type for the namespace.
    4031             :  * \param cb_fn Callback function to invoke when the I/O is completed.
    4032             :  * \param cb_arg Argument to pass to the callback function.
    4033             :  *
    4034             :  * \return 0 if successfully submitted, negated errnos on the following error conditions:
    4035             :  * -ENOMEM: The request cannot be allocated.
    4036             :  * -ENXIO: The qpair is failed at the transport level.
    4037             :  */
    4038             : int spdk_nvme_ns_cmd_reservation_release(struct spdk_nvme_ns *ns,
    4039             :                 struct spdk_nvme_qpair *qpair,
    4040             :                 struct spdk_nvme_reservation_key_data *payload,
    4041             :                 bool ignore_key,
    4042             :                 enum spdk_nvme_reservation_release_action action,
    4043             :                 enum spdk_nvme_reservation_type type,
    4044             :                 spdk_nvme_cmd_cb cb_fn, void *cb_arg);
    4045             : 
    4046             : /**
    4047             :  * Submits a reservation acquire to the specified NVMe namespace.
    4048             :  *
    4049             :  * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
    4050             :  * The user must ensure that only one thread submits I/O on a given qpair at any
    4051             :  * given time.
    4052             :  *
    4053             :  * \param ns NVMe namespace to submit the reservation acquire request.
    4054             :  * \param qpair I/O queue pair to submit the request.
    4055             :  * \param payload Virtual address pointer to reservation acquire data.
    4056             :  * \param ignore_key '1' the current reservation key check is disabled.
    4057             :  * \param action Specifies the reservation acquire action.
    4058             :  * \param type Reservation type for the namespace.
    4059             :  * \param cb_fn Callback function to invoke when the I/O is completed.
    4060             :  * \param cb_arg Argument to pass to the callback function.
    4061             :  *
    4062             :  * \return 0 if successfully submitted, negated errnos on the following error conditions:
    4063             :  * -ENOMEM: The request cannot be allocated.
    4064             :  * -ENXIO: The qpair is failed at the transport level.
    4065             :  */
    4066             : int spdk_nvme_ns_cmd_reservation_acquire(struct spdk_nvme_ns *ns,
    4067             :                 struct spdk_nvme_qpair *qpair,
    4068             :                 struct spdk_nvme_reservation_acquire_data *payload,
    4069             :                 bool ignore_key,
    4070             :                 enum spdk_nvme_reservation_acquire_action action,
    4071             :                 enum spdk_nvme_reservation_type type,
    4072             :                 spdk_nvme_cmd_cb cb_fn, void *cb_arg);
    4073             : 
    4074             : /**
    4075             :  * Submit a reservation report to the specified NVMe namespace.
    4076             :  *
    4077             :  * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
    4078             :  * The user must ensure that only one thread submits I/O on a given qpair at any
    4079             :  * given time.
    4080             :  *
    4081             :  * \param ns NVMe namespace to submit the reservation report request.
    4082             :  * \param qpair I/O queue pair to submit the request.
    4083             :  * \param payload Virtual address pointer for reservation status data.
    4084             :  * \param len Length bytes for reservation status data structure.
    4085             :  * \param cb_fn Callback function to invoke when the I/O is completed.
    4086             :  * \param cb_arg Argument to pass to the callback function.
    4087             :  *
    4088             :  * \return 0 if successfully submitted, negated errnos on the following error conditions:
    4089             :  * -ENOMEM: The request cannot be allocated.
    4090             :  * -ENXIO: The qpair is failed at the transport level.
    4091             :  */
    4092             : int spdk_nvme_ns_cmd_reservation_report(struct spdk_nvme_ns *ns,
    4093             :                                         struct spdk_nvme_qpair *qpair,
    4094             :                                         void *payload, uint32_t len,
    4095             :                                         spdk_nvme_cmd_cb cb_fn, void *cb_arg);
    4096             : 
    4097             : /**
    4098             :  * Submit an I/O management receive command to the specified NVMe namespace.
    4099             :  *
    4100             :  * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
    4101             :  * The user must ensure that only one thread submits I/O on a given qpair at any
    4102             :  * given time.
    4103             :  *
    4104             :  * \param ns NVMe namespace to submit the I/O mgmt receive request.
    4105             :  * \param qpair I/O queue pair to submit the request.
    4106             :  * \param payload Virtual address pointer for I/O mgmt receive data.
    4107             :  * \param len Length bytes for I/O mgmt receive data structure.
    4108             :  * \param mo Management operation to perform.
    4109             :  * \param mos Management operation specific field for the mo.
    4110             :  * \param cb_fn Callback function to invoke when the I/O is completed.
    4111             :  * \param cb_arg Argument to pass to the callback function.
    4112             :  *
    4113             :  * \return 0 if successfully submitted, negated errnos on the following error conditions:
    4114             :  * -ENOMEM: The request cannot be allocated.
    4115             :  * -ENXIO: The qpair is failed at the transport level.
    4116             :  */
    4117             : int spdk_nvme_ns_cmd_io_mgmt_recv(struct spdk_nvme_ns *ns,
    4118             :                                   struct spdk_nvme_qpair *qpair, void *payload,
    4119             :                                   uint32_t len, uint8_t mo, uint16_t mos,
    4120             :                                   spdk_nvme_cmd_cb cb_fn, void *cb_arg);
    4121             : 
    4122             : /**
    4123             :  * Submit an I/O management send command to the specified NVMe namespace.
    4124             :  *
    4125             :  * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
    4126             :  * The user must ensure that only one thread submits I/O on a given qpair at any
    4127             :  * given time.
    4128             :  *
    4129             :  * \param ns NVMe namespace to submit the I/O mgmt send request.
    4130             :  * \param qpair I/O queue pair to submit the request.
    4131             :  * \param payload Virtual address pointer for I/O mgmt send data.
    4132             :  * \param len Length bytes for I/O mgmt send data structure.
    4133             :  * \param mo Management operation to perform.
    4134             :  * \param mos Management operation specific field for the mo.
    4135             :  * \param cb_fn Callback function to invoke when the I/O is completed.
    4136             :  * \param cb_arg Argument to pass to the callback function.
    4137             :  *
    4138             :  * \return 0 if successfully submitted, negated errnos on the following error conditions:
    4139             :  * -ENOMEM: The request cannot be allocated.
    4140             :  * -ENXIO: The qpair is failed at the transport level.
    4141             :  */
    4142             : int spdk_nvme_ns_cmd_io_mgmt_send(struct spdk_nvme_ns *ns,
    4143             :                                   struct spdk_nvme_qpair *qpair, void *payload,
    4144             :                                   uint32_t len, uint8_t mo, uint16_t mos,
    4145             :                                   spdk_nvme_cmd_cb cb_fn, void *cb_arg);
    4146             : 
    4147             : /**
    4148             :  * Submit a compare I/O to the specified NVMe namespace.
    4149             :  *
    4150             :  * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
    4151             :  * The user must ensure that only one thread submits I/O on a given qpair at any
    4152             :  * given time.
    4153             :  *
    4154             :  * \param ns NVMe namespace to submit the compare I/O.
    4155             :  * \param qpair I/O queue pair to submit the request.
    4156             :  * \param payload Virtual address pointer to the data payload.
    4157             :  * \param lba Starting LBA to compare the data.
    4158             :  * \param lba_count Length (in sectors) for the compare operation.
    4159             :  * \param cb_fn Callback function to invoke when the I/O is completed.
    4160             :  * \param cb_arg Argument to pass to the callback function.
    4161             :  * \param io_flags Set flags, defined in nvme_spec.h, for this I/O.
    4162             :  *
    4163             :  * \return 0 if successfully submitted, negated errnos on the following error conditions:
    4164             :  * -EINVAL: The request is malformed.
    4165             :  * -ENOMEM: The request cannot be allocated.
    4166             :  * -ENXIO: The qpair is failed at the transport level.
    4167             :  */
    4168             : int spdk_nvme_ns_cmd_compare(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair, void *payload,
    4169             :                              uint64_t lba, uint32_t lba_count, spdk_nvme_cmd_cb cb_fn,
    4170             :                              void *cb_arg, uint32_t io_flags);
    4171             : 
    4172             : /**
    4173             :  * Submit a compare I/O to the specified NVMe namespace.
    4174             :  *
    4175             :  * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
    4176             :  * The user must ensure that only one thread submits I/O on a given qpair at any
    4177             :  * given time.
    4178             :  *
    4179             :  * \param ns NVMe namespace to submit the compare I/O.
    4180             :  * \param qpair I/O queue pair to submit the request.
    4181             :  * \param lba Starting LBA to compare the data.
    4182             :  * \param lba_count Length (in sectors) for the compare operation.
    4183             :  * \param cb_fn Callback function to invoke when the I/O is completed.
    4184             :  * \param cb_arg Argument to pass to the callback function.
    4185             :  * \param io_flags Set flags, defined in nvme_spec.h, for this I/O.
    4186             :  * \param reset_sgl_fn Callback function to reset scattered payload.
    4187             :  * \param next_sge_fn Callback function to iterate each scattered payload memory
    4188             :  * segment.
    4189             :  *
    4190             :  * \return 0 if successfully submitted, negated errnos on the following error conditions:
    4191             :  * -EINVAL: The request is malformed.
    4192             :  * -ENOMEM: The request cannot be allocated.
    4193             :  * -ENXIO: The qpair is failed at the transport level.
    4194             :  */
    4195             : int spdk_nvme_ns_cmd_comparev(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
    4196             :                               uint64_t lba, uint32_t lba_count,
    4197             :                               spdk_nvme_cmd_cb cb_fn, void *cb_arg, uint32_t io_flags,
    4198             :                               spdk_nvme_req_reset_sgl_cb reset_sgl_fn,
    4199             :                               spdk_nvme_req_next_sge_cb next_sge_fn);
    4200             : 
    4201             : /**
    4202             :  * Submit a compare I/O to the specified NVMe namespace.
    4203             :  *
    4204             :  * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
    4205             :  * The user must ensure that only one thread submits I/O on a given qpair at any
    4206             :  * given time.
    4207             :  *
    4208             :  * \param ns NVMe namespace to submit the compare I/O.
    4209             :  * \param qpair I/O queue pair to submit the request.
    4210             :  * \param lba Starting LBA to compare the data.
    4211             :  * \param lba_count Length (in sectors) for the compare operation.
    4212             :  * \param cb_fn Callback function to invoke when the I/O is completed.
    4213             :  * \param cb_arg Argument to pass to the callback function.
    4214             :  * \param io_flags Set flags, defined in nvme_spec.h, for this I/O.
    4215             :  * \param reset_sgl_fn Callback function to reset scattered payload.
    4216             :  * \param next_sge_fn Callback function to iterate each scattered payload memory
    4217             :  * segment.
    4218             :  * \param metadata Virtual address pointer to the metadata payload, the length
    4219             :  * of metadata is specified by spdk_nvme_ns_get_md_size()
    4220             :  * \param apptag_mask Application tag mask.
    4221             :  * \param apptag Application tag to use end-to-end protection information.
    4222             :  *
    4223             :  * \return 0 if successfully submitted, negated errnos on the following error conditions:
    4224             :  * -EINVAL: The request is malformed.
    4225             :  * -ENOMEM: The request cannot be allocated.
    4226             :  * -ENXIO: The qpair is failed at the transport level.
    4227             :  */
    4228             : int
    4229             : spdk_nvme_ns_cmd_comparev_with_md(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
    4230             :                                   uint64_t lba, uint32_t lba_count,
    4231             :                                   spdk_nvme_cmd_cb cb_fn, void *cb_arg, uint32_t io_flags,
    4232             :                                   spdk_nvme_req_reset_sgl_cb reset_sgl_fn,
    4233             :                                   spdk_nvme_req_next_sge_cb next_sge_fn, void *metadata,
    4234             :                                   uint16_t apptag_mask, uint16_t apptag);
    4235             : 
    4236             : /**
    4237             :  * Submit a compare I/O to the specified NVMe namespace.
    4238             :  *
    4239             :  * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
    4240             :  * The user must ensure that only one thread submits I/O on a given qpair at any
    4241             :  * given time.
    4242             :  *
    4243             :  * \param ns NVMe namespace to submit the compare I/O.
    4244             :  * \param qpair I/O queue pair to submit the request.
    4245             :  * \param payload Virtual address pointer to the data payload.
    4246             :  * \param metadata Virtual address pointer to the metadata payload, the length
    4247             :  * of metadata is specified by spdk_nvme_ns_get_md_size().
    4248             :  * \param lba Starting LBA to compare the data.
    4249             :  * \param lba_count Length (in sectors) for the compare operation.
    4250             :  * \param cb_fn Callback function to invoke when the I/O is completed.
    4251             :  * \param cb_arg Argument to pass to the callback function.
    4252             :  * \param io_flags Set flags, defined in nvme_spec.h, for this I/O.
    4253             :  * \param apptag_mask Application tag mask.
    4254             :  * \param apptag Application tag to use end-to-end protection information.
    4255             :  *
    4256             :  * \return 0 if successfully submitted, negated errnos on the following error conditions:
    4257             :  * -EINVAL: The request is malformed.
    4258             :  * -ENOMEM: The request cannot be allocated.
    4259             :  * -ENXIO: The qpair is failed at the transport level.
    4260             :  */
    4261             : int spdk_nvme_ns_cmd_compare_with_md(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
    4262             :                                      void *payload, void *metadata,
    4263             :                                      uint64_t lba, uint32_t lba_count, spdk_nvme_cmd_cb cb_fn,
    4264             :                                      void *cb_arg, uint32_t io_flags,
    4265             :                                      uint16_t apptag_mask, uint16_t apptag);
    4266             : 
    4267             : /**
    4268             :  * \brief Inject an error for the next request with a given opcode.
    4269             :  *
    4270             :  * \param ctrlr NVMe controller.
    4271             :  * \param qpair I/O queue pair to add the error command,
    4272             :  *              NULL for Admin queue pair.
    4273             :  * \param opc Opcode for Admin or I/O commands.
    4274             :  * \param do_not_submit True if matching requests should not be submitted
    4275             :  *                      to the controller, but instead completed manually
    4276             :  *                      after timeout_in_us has expired.  False if matching
    4277             :  *                      requests should be submitted to the controller and
    4278             :  *                      have their completion status modified after the
    4279             :  *                      controller completes the request.
    4280             :  * \param timeout_in_us Wait specified microseconds when do_not_submit is true.
    4281             :  * \param err_count Number of matching requests to inject errors.
    4282             :  * \param sct Status code type.
    4283             :  * \param sc Status code.
    4284             :  *
    4285             :  * \return 0 if successfully enabled, ENOMEM if an error command
    4286             :  *           structure cannot be allocated.
    4287             :  *
    4288             :  * The function can be called multiple times to inject errors for different
    4289             :  * commands.  If the opcode matches an existing entry, the existing entry
    4290             :  * will be updated with the values specified.
    4291             :  */
    4292             : int spdk_nvme_qpair_add_cmd_error_injection(struct spdk_nvme_ctrlr *ctrlr,
    4293             :                 struct spdk_nvme_qpair *qpair,
    4294             :                 uint8_t opc,
    4295             :                 bool do_not_submit,
    4296             :                 uint64_t timeout_in_us,
    4297             :                 uint32_t err_count,
    4298             :                 uint8_t sct, uint8_t sc);
    4299             : 
    4300             : /**
    4301             :  * \brief Clear the specified NVMe command with error status.
    4302             :  *
    4303             :  * \param ctrlr NVMe controller.
    4304             :  * \param qpair I/O queue pair to remove the error command,
    4305             :  * \            NULL for Admin queue pair.
    4306             :  * \param opc Opcode for Admin or I/O commands.
    4307             :  *
    4308             :  * The function will remove specified command in the error list.
    4309             :  */
    4310             : void spdk_nvme_qpair_remove_cmd_error_injection(struct spdk_nvme_ctrlr *ctrlr,
    4311             :                 struct spdk_nvme_qpair *qpair,
    4312             :                 uint8_t opc);
    4313             : 
    4314             : /**
    4315             :  * \brief Given NVMe status, return ASCII string for that error.
    4316             :  *
    4317             :  * \param status Status from NVMe completion queue element.
    4318             :  * \return Returns status as an ASCII string.
    4319             :  */
    4320             : const char *spdk_nvme_cpl_get_status_string(const struct spdk_nvme_status *status);
    4321             : 
    4322             : /**
    4323             :  * \brief Given NVMe status, return ASCII string for the type of that error.
    4324             :  *
    4325             :  * \param status Status from NVMe completion queue element.
    4326             :  * \return Returns status type as an ASCII string.
    4327             :  */
    4328             : const char *spdk_nvme_cpl_get_status_type_string(const struct spdk_nvme_status *status);
    4329             : 
    4330             : /**
    4331             :  * \brief Prints (SPDK_NOTICELOG) the contents of an NVMe submission queue entry (command).
    4332             :  *
    4333             :  * \param qpair Pointer to the NVMe queue pair - used to determine admin versus I/O queue.
    4334             :  * \param cmd Pointer to the submission queue command to be formatted.
    4335             :  */
    4336             : void spdk_nvme_qpair_print_command(struct spdk_nvme_qpair *qpair,
    4337             :                                    struct spdk_nvme_cmd *cmd);
    4338             : 
    4339             : /**
    4340             :  * \brief Prints (SPDK_NOTICELOG) the contents of an NVMe completion queue entry.
    4341             :  *
    4342             :  * \param qpair Pointer to the NVMe queue pair - presently unused.
    4343             :  * \param cpl Pointer to the completion queue element to be formatted.
    4344             :  */
    4345             : void spdk_nvme_qpair_print_completion(struct spdk_nvme_qpair *qpair,
    4346             :                                       struct spdk_nvme_cpl *cpl);
    4347             : 
    4348             : /**
    4349             :  * \brief Gets the NVMe qpair ID for the specified qpair.
    4350             :  *
    4351             :  * \param qpair Pointer to the NVMe queue pair.
    4352             :  * \returns ID for the specified qpair.
    4353             :  */
    4354             : uint16_t spdk_nvme_qpair_get_id(struct spdk_nvme_qpair *qpair);
    4355             : 
    4356             : /**
    4357             :  * Gets the number of outstanding requests for the specified qpair.
    4358             :  *
    4359             :  * This number is not decremented until after a request's callback function is completed.
    4360             :  *
    4361             :  * This number is not matched necessarily to the number of NVMe commands submitted by the
    4362             :  * user. For example, nvme driver may split a request due to MDTS limitations, that will
    4363             :  * also allocate a request for the parent, etc.
    4364             :  *
    4365             :  * \param qpair Pointer to the NVMe queue pair.
    4366             :  * \returns number of outstanding requests for the specified qpair.
    4367             :  */
    4368             : uint32_t spdk_nvme_qpair_get_num_outstanding_reqs(struct spdk_nvme_qpair *qpair);
    4369             : 
    4370             : /**
    4371             :  * \brief Prints (SPDK_NOTICELOG) the contents of an NVMe submission queue entry (command).
    4372             :  *
    4373             :  * \param qid Queue identifier.
    4374             :  * \param cmd Pointer to the submission queue command to be formatted.
    4375             :  */
    4376             : void spdk_nvme_print_command(uint16_t qid, struct spdk_nvme_cmd *cmd);
    4377             : 
    4378             : /**
    4379             :  * \brief Prints (SPDK_NOTICELOG) the contents of an NVMe completion queue entry.
    4380             :  *
    4381             :  * \param qid Queue identifier.
    4382             :  * \param cpl Pointer to the completion queue element to be formatted.
    4383             :  */
    4384             : void spdk_nvme_print_completion(uint16_t qid, struct spdk_nvme_cpl *cpl);
    4385             : 
    4386             : /**
    4387             :  * Return the name of a digest.
    4388             :  *
    4389             :  * \param id Digest identifier (see `enum spdk_nvmf_dhchap_hash`).
    4390             :  *
    4391             :  * \return Name of the digest.
    4392             :  */
    4393             : const char *spdk_nvme_dhchap_get_digest_name(int id);
    4394             : 
    4395             : /**
    4396             :  * Return the id of a digest.
    4397             :  *
    4398             :  * \param name Name of a digest.
    4399             :  *
    4400             :  * \return Digest id (see `enum spdk_nvmf_dhchap_hash`) or negative errno on failure.
    4401             :  */
    4402             : int spdk_nvme_dhchap_get_digest_id(const char *name);
    4403             : 
    4404             : /**
    4405             :  * Return the length of a digest.
    4406             :  *
    4407             :  * \param id Digest identifier (see `enum spdk_nvmf_dhchap_hash`).
    4408             :  *
    4409             :  * \return Length of a digest or 0 if the id is unknown.
    4410             :  */
    4411             : uint8_t spdk_nvme_dhchap_get_digest_length(int id);
    4412             : 
    4413             : /**
    4414             :  * Return the name of a Diffie-Hellman group.
    4415             :  *
    4416             :  * \param id Diffie-Hellman group identifier (see `enum spdk_nvmf_dhchap_dhgroup`).
    4417             :  *
    4418             :  * \return Name of the Diffie-Hellman group.
    4419             :  */
    4420             : const char *spdk_nvme_dhchap_get_dhgroup_name(int id);
    4421             : 
    4422             : /**
    4423             :  * Return the id of a Diffie-Hellman group.
    4424             :  *
    4425             :  * \param name Name of a Diffie-Hellman group.
    4426             :  *
    4427             :  * \return Diffie-Hellman group id (see `enum spdk_nvmf_dhchap_dhgroup`) or negative errno
    4428             :  * on failure.
    4429             :  */
    4430             : int spdk_nvme_dhchap_get_dhgroup_id(const char *name);
    4431             : 
    4432             : struct ibv_context;
    4433             : struct ibv_pd;
    4434             : struct ibv_mr;
    4435             : 
    4436             : /**
    4437             :  * RDMA Transport Hooks
    4438             :  */
    4439             : struct spdk_nvme_rdma_hooks {
    4440             :         /**
    4441             :          * \brief Get an InfiniBand Verbs protection domain.
    4442             :          *
    4443             :          * \param trid the transport id
    4444             :          * \param verbs Infiniband verbs context
    4445             :          *
    4446             :          * \return pd of the nvme ctrlr
    4447             :          */
    4448             :         struct ibv_pd *(*get_ibv_pd)(const struct spdk_nvme_transport_id *trid,
    4449             :                                      struct ibv_context *verbs);
    4450             : 
    4451             :         /**
    4452             :          * \brief Get an InfiniBand Verbs memory region for a buffer.
    4453             :          *
    4454             :          * \param pd The protection domain returned from get_ibv_pd
    4455             :          * \param buf Memory buffer for which an rkey should be returned.
    4456             :          * \param size size of buf
    4457             :          *
    4458             :          * \return Infiniband remote key (rkey) for this buf
    4459             :          */
    4460             :         uint64_t (*get_rkey)(struct ibv_pd *pd, void *buf, size_t size);
    4461             : 
    4462             :         /**
    4463             :          * \brief Put back keys got from get_rkey.
    4464             :          *
    4465             :          * \param key The Infiniband remote key (rkey) got from get_rkey
    4466             :          *
    4467             :          */
    4468             :         void (*put_rkey)(uint64_t key);
    4469             : };
    4470             : 
    4471             : /**
    4472             :  * \brief Set the global hooks for the RDMA transport, if necessary.
    4473             :  *
    4474             :  * This call is optional and must be performed prior to probing for
    4475             :  * any devices. By default, the RDMA transport will use the ibverbs
    4476             :  * library to create protection domains and register memory. This
    4477             :  * is a mechanism to subvert that and use an existing registration.
    4478             :  *
    4479             :  * This function may only be called one time per process.
    4480             :  *
    4481             :  * \param hooks for initializing global hooks
    4482             :  */
    4483             : void spdk_nvme_rdma_init_hooks(struct spdk_nvme_rdma_hooks *hooks);
    4484             : 
    4485             : /**
    4486             :  * Get name of cuse device associated with NVMe controller.
    4487             :  *
    4488             :  * \param ctrlr Opaque handle to NVMe controller.
    4489             :  * \param name  Buffer of be filled with cuse device name.
    4490             :  * \param size  Size of name buffer.
    4491             :  *
    4492             :  * \return 0 on success. Negated errno on the following error conditions:
    4493             :  * -ENODEV: No cuse device registered for the controller.
    4494             :  * -ENSPC: Too small buffer size passed. Value of size pointer changed to the required length.
    4495             :  */
    4496             : int spdk_nvme_cuse_get_ctrlr_name(struct spdk_nvme_ctrlr *ctrlr, char *name, size_t *size);
    4497             : 
    4498             : /**
    4499             :  * Get name of cuse device associated with NVMe namespace.
    4500             :  *
    4501             :  * \param ctrlr Opaque handle to NVMe controller.
    4502             :  * \param nsid  Namespace id.
    4503             :  * \param name  Buffer of be filled with cuse device name.
    4504             :  * \param size  Size of name buffer.
    4505             :  *
    4506             :  * \return 0 on success. Negated errno on the following error conditions:
    4507             :  * -ENODEV: No cuse device registered for the namespace.
    4508             :  * -ENSPC: Too small buffer size passed. Value of size pointer changed to the required length.
    4509             :  */
    4510             : int spdk_nvme_cuse_get_ns_name(struct spdk_nvme_ctrlr *ctrlr, uint32_t nsid,
    4511             :                                char *name, size_t *size);
    4512             : 
    4513             : /**
    4514             :  * Create a character device at the path specified
    4515             :  *
    4516             :  * The character device can handle ioctls and is compatible with a standard
    4517             :  * Linux kernel NVMe device. Tools such as nvme-cli can be used to configure
    4518             :  * SPDK devices through this interface.
    4519             :  *
    4520             :  * The user is expected to be polling the admin qpair for this controller periodically
    4521             :  * for the CUSE device to function.
    4522             :  *
    4523             :  * \param ctrlr Opaque handle to the NVMe controller.
    4524             :  *
    4525             :  * \return 0 on success. Negated errno on failure.
    4526             :  */
    4527             : int spdk_nvme_cuse_register(struct spdk_nvme_ctrlr *ctrlr);
    4528             : 
    4529             : /**
    4530             :  * Remove a previously created character device
    4531             :  *
    4532             :  * \param ctrlr Opaque handle to the NVMe controller.
    4533             :  *
    4534             :  * \return 0 on success. Negated errno on failure.
    4535             :  */
    4536             : int spdk_nvme_cuse_unregister(struct spdk_nvme_ctrlr *ctrlr);
    4537             : 
    4538             : /**
    4539             :  * Get SPDK memory domains used by the given nvme controller.
    4540             :  *
    4541             :  * The user can call this function with \b domains set to NULL and \b array_size set to 0 to get the
    4542             :  * number of memory domains used by nvme controller
    4543             :  *
    4544             :  * \param ctrlr Opaque handle to the NVMe controller.
    4545             :  * \param domains Pointer to an array of memory domains to be filled by this function. The user should allocate big enough
    4546             :  * array to keep all memory domains used by nvme controller
    4547             :  * \param array_size size of \b domains array
    4548             :  * \return the number of entries in \b domains array or negated errno. If returned value is bigger than \b array_size passed by the user
    4549             :  * then the user should increase the size of \b domains array and call this function again. There is no guarantees that
    4550             :  * the content of \b domains array is valid in that case.
    4551             :  *         -EINVAL if input parameters were invalid
    4552             : 
    4553             :  */
    4554             : int spdk_nvme_ctrlr_get_memory_domains(const struct spdk_nvme_ctrlr *ctrlr,
    4555             :                                        struct spdk_memory_domain **domains, int array_size);
    4556             : 
    4557             : /**
    4558             :  * Opaque handle for a transport poll group. Used by the transport function table.
    4559             :  */
    4560             : struct spdk_nvme_transport_poll_group;
    4561             : 
    4562             : /**
    4563             :  * Update and populate namespace CUSE devices (Experimental)
    4564             :  *
    4565             :  * \param ctrlr Opaque handle to the NVMe controller.
    4566             :  *
    4567             :  */
    4568             : void spdk_nvme_cuse_update_namespaces(struct spdk_nvme_ctrlr *ctrlr);
    4569             : 
    4570             : /**
    4571             :  * Signature for callback invoked after completing a register read/write operation.
    4572             :  *
    4573             :  * \param ctx Context passed by the user.
    4574             :  * \param value Value of the register, undefined in case of a failure.
    4575             :  * \param cpl Completion queue entry that contains the status of the command.
    4576             :  */
    4577             : typedef void (*spdk_nvme_reg_cb)(void *ctx, uint64_t value, const struct spdk_nvme_cpl *cpl);
    4578             : 
    4579             : struct nvme_request;
    4580             : 
    4581             : struct spdk_nvme_transport;
    4582             : 
    4583             : struct spdk_nvme_transport_ops {
    4584             :         char name[SPDK_NVMF_TRSTRING_MAX_LEN + 1];
    4585             : 
    4586             :         enum spdk_nvme_transport_type type;
    4587             : 
    4588             :         struct spdk_nvme_ctrlr *(*ctrlr_construct)(const struct spdk_nvme_transport_id *trid,
    4589             :                         const struct spdk_nvme_ctrlr_opts *opts,
    4590             :                         void *devhandle);
    4591             : 
    4592             :         int (*ctrlr_scan)(struct spdk_nvme_probe_ctx *probe_ctx, bool direct_connect);
    4593             : 
    4594             :         int (*ctrlr_destruct)(struct spdk_nvme_ctrlr *ctrlr);
    4595             : 
    4596             :         int (*ctrlr_enable)(struct spdk_nvme_ctrlr *ctrlr);
    4597             : 
    4598             :         int (*ctrlr_enable_interrupts)(struct spdk_nvme_ctrlr *ctrlr);
    4599             : 
    4600             :         int (*ctrlr_set_reg_4)(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint32_t value);
    4601             : 
    4602             :         int (*ctrlr_set_reg_8)(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint64_t value);
    4603             : 
    4604             :         int (*ctrlr_get_reg_4)(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint32_t *value);
    4605             : 
    4606             :         int (*ctrlr_get_reg_8)(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint64_t *value);
    4607             : 
    4608             :         int (*ctrlr_set_reg_4_async)(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint32_t value,
    4609             :                                      spdk_nvme_reg_cb cb_fn, void *cb_arg);
    4610             : 
    4611             :         int (*ctrlr_set_reg_8_async)(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint64_t value,
    4612             :                                      spdk_nvme_reg_cb cb_fn, void *cb_arg);
    4613             : 
    4614             :         int (*ctrlr_get_reg_4_async)(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset,
    4615             :                                      spdk_nvme_reg_cb cb_fn, void *cb_arg);
    4616             : 
    4617             :         int (*ctrlr_get_reg_8_async)(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset,
    4618             :                                      spdk_nvme_reg_cb cb_fn, void *cb_arg);
    4619             : 
    4620             :         uint32_t (*ctrlr_get_max_xfer_size)(struct spdk_nvme_ctrlr *ctrlr);
    4621             : 
    4622             :         uint16_t (*ctrlr_get_max_sges)(struct spdk_nvme_ctrlr *ctrlr);
    4623             : 
    4624             :         int (*ctrlr_reserve_cmb)(struct spdk_nvme_ctrlr *ctrlr);
    4625             : 
    4626             :         void *(*ctrlr_map_cmb)(struct spdk_nvme_ctrlr *ctrlr, size_t *size);
    4627             : 
    4628             :         int (*ctrlr_unmap_cmb)(struct spdk_nvme_ctrlr *ctrlr);
    4629             : 
    4630             :         int (*ctrlr_enable_pmr)(struct spdk_nvme_ctrlr *ctrlr);
    4631             : 
    4632             :         int (*ctrlr_disable_pmr)(struct spdk_nvme_ctrlr *ctrlr);
    4633             : 
    4634             :         void *(*ctrlr_map_pmr)(struct spdk_nvme_ctrlr *ctrlr, size_t *size);
    4635             : 
    4636             :         int (*ctrlr_unmap_pmr)(struct spdk_nvme_ctrlr *ctrlr);
    4637             : 
    4638             :         struct spdk_nvme_qpair *(*ctrlr_create_io_qpair)(struct spdk_nvme_ctrlr *ctrlr, uint16_t qid,
    4639             :                         const struct spdk_nvme_io_qpair_opts *opts);
    4640             : 
    4641             :         int (*ctrlr_delete_io_qpair)(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qpair);
    4642             : 
    4643             :         int (*ctrlr_connect_qpair)(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qpair);
    4644             : 
    4645             :         void (*ctrlr_disconnect_qpair)(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qpair);
    4646             : 
    4647             :         void (*qpair_abort_reqs)(struct spdk_nvme_qpair *qpair, uint32_t dnr);
    4648             : 
    4649             :         int (*qpair_reset)(struct spdk_nvme_qpair *qpair);
    4650             : 
    4651             :         int (*qpair_submit_request)(struct spdk_nvme_qpair *qpair, struct nvme_request *req);
    4652             : 
    4653             :         int (*qpair_authenticate)(struct spdk_nvme_qpair *qpair);
    4654             : 
    4655             :         int32_t (*qpair_process_completions)(struct spdk_nvme_qpair *qpair, uint32_t max_completions);
    4656             : 
    4657             :         int (*qpair_iterate_requests)(struct spdk_nvme_qpair *qpair,
    4658             :                                       int (*iter_fn)(struct nvme_request *req, void *arg),
    4659             :                                       void *arg);
    4660             : 
    4661             :         int (*qpair_get_fd)(struct spdk_nvme_qpair *qpair, struct spdk_event_handler_opts *opts);
    4662             : 
    4663             :         void (*admin_qpair_abort_aers)(struct spdk_nvme_qpair *qpair);
    4664             : 
    4665             :         struct spdk_nvme_transport_poll_group *(*poll_group_create)(void);
    4666             :         struct spdk_nvme_transport_poll_group *(*qpair_get_optimal_poll_group)(
    4667             :                 struct spdk_nvme_qpair *qpair);
    4668             : 
    4669             :         int (*poll_group_add)(struct spdk_nvme_transport_poll_group *tgroup, struct spdk_nvme_qpair *qpair);
    4670             : 
    4671             :         int (*poll_group_remove)(struct spdk_nvme_transport_poll_group *tgroup,
    4672             :                                  struct spdk_nvme_qpair *qpair);
    4673             : 
    4674             :         int (*poll_group_connect_qpair)(struct spdk_nvme_qpair *qpair);
    4675             : 
    4676             :         int (*poll_group_disconnect_qpair)(struct spdk_nvme_qpair *qpair);
    4677             : 
    4678             :         int64_t (*poll_group_process_completions)(struct spdk_nvme_transport_poll_group *tgroup,
    4679             :                         uint32_t completions_per_qpair, spdk_nvme_disconnected_qpair_cb disconnected_qpair_cb);
    4680             : 
    4681             :         void (*poll_group_check_disconnected_qpairs)(struct spdk_nvme_transport_poll_group *tgroup,
    4682             :                         spdk_nvme_disconnected_qpair_cb disconnected_qpair_cb);
    4683             : 
    4684             :         int (*poll_group_destroy)(struct spdk_nvme_transport_poll_group *tgroup);
    4685             : 
    4686             :         int (*poll_group_get_stats)(struct spdk_nvme_transport_poll_group *tgroup,
    4687             :                                     struct spdk_nvme_transport_poll_group_stat **stats);
    4688             : 
    4689             :         void (*poll_group_free_stats)(struct spdk_nvme_transport_poll_group *tgroup,
    4690             :                                       struct spdk_nvme_transport_poll_group_stat *stats);
    4691             : 
    4692             :         int (*ctrlr_get_memory_domains)(const struct spdk_nvme_ctrlr *ctrlr,
    4693             :                                         struct spdk_memory_domain **domains,
    4694             :                                         int array_size);
    4695             : 
    4696             :         int (*ctrlr_ready)(struct spdk_nvme_ctrlr *ctrlr);
    4697             : 
    4698             :         volatile struct spdk_nvme_registers *(*ctrlr_get_registers)(struct spdk_nvme_ctrlr *ctrlr);
    4699             : 
    4700             :         /* Optional callback for transports to process removal events of attached controllers. */
    4701             :         int (*ctrlr_scan_attached)(struct spdk_nvme_probe_ctx *probe_ctx);
    4702             : };
    4703             : 
    4704             : /**
    4705             :  * Register the operations for a given transport type.
    4706             :  *
    4707             :  * This function should be invoked by referencing the macro
    4708             :  * SPDK_NVME_TRANSPORT_REGISTER macro in the transport's .c file.
    4709             :  *
    4710             :  * \param ops The operations associated with an NVMe-oF transport.
    4711             :  */
    4712             : void spdk_nvme_transport_register(const struct spdk_nvme_transport_ops *ops);
    4713             : 
    4714             : /*
    4715             :  * Macro used to register new transports.
    4716             :  */
    4717             : #define SPDK_NVME_TRANSPORT_REGISTER(name, transport_ops) \
    4718             : static void __attribute__((constructor)) _spdk_nvme_transport_register_##name(void) \
    4719             : { \
    4720             :         spdk_nvme_transport_register(transport_ops); \
    4721             : }
    4722             : 
    4723             : /**
    4724             :  * NVMe transport options.
    4725             :  */
    4726             : struct spdk_nvme_transport_opts {
    4727             :         /**
    4728             :          * It is used for RDMA transport.
    4729             :          *
    4730             :          * The queue depth of a shared rdma receive queue.
    4731             :          */
    4732             :         uint32_t rdma_srq_size;
    4733             : 
    4734             :         /* Hole at bytes 4-7. */
    4735             :         uint8_t reserved4[4];
    4736             : 
    4737             :         /**
    4738             :          * The size of spdk_nvme_transport_opts according to the caller of this library is used for ABI
    4739             :          * compatibility.  The library uses this field to know how many fields in this
    4740             :          * structure are valid. And the library will populate any remaining fields with default values.
    4741             :          */
    4742             :         size_t opts_size;
    4743             : 
    4744             :         /**
    4745             :          * It is used for RDMA transport.
    4746             :          *
    4747             :          * The maximum queue depth of a rdma completion queue.
    4748             :          * It is zero, which means unlimited, by default.
    4749             :          */
    4750             :         uint32_t rdma_max_cq_size;
    4751             : 
    4752             :         /**
    4753             :          * It is used for RDMA transport.
    4754             :          *
    4755             :          * RDMA CM event timeout in milliseconds.
    4756             :          */
    4757             :         uint16_t rdma_cm_event_timeout_ms;
    4758             : 
    4759             :         /**
    4760             :          * It is used for RDMA transport.
    4761             :          *
    4762             :          * Configure UMR per IO request if supported by the system
    4763             :          */
    4764             :         bool rdma_umr_per_io;
    4765             : };
    4766             : SPDK_STATIC_ASSERT(sizeof(struct spdk_nvme_transport_opts) == 24, "Incorrect size");
    4767             : 
    4768             : /**
    4769             :  * Get the current NVMe transport options.
    4770             :  *
    4771             :  * \param[out] opts Will be filled with the current options for spdk_nvme_transport_set_opts().
    4772             :  * \param opts_size Must be set to sizeof(struct spdk_nvme_transport_opts).
    4773             :  */
    4774             : void spdk_nvme_transport_get_opts(struct spdk_nvme_transport_opts *opts, size_t opts_size);
    4775             : 
    4776             : /**
    4777             :  * Set the NVMe transport options.
    4778             :  *
    4779             :  * \param opts Pointer to the allocated spdk_nvme_transport_opts structure with new values.
    4780             :  * \param opts_size Must be set to sizeof(struct spdk_nvme_transport_opts).
    4781             :  *
    4782             :  * \return 0 on success, or negated errno on failure.
    4783             :  */
    4784             : int spdk_nvme_transport_set_opts(const struct spdk_nvme_transport_opts *opts, size_t opts_size);
    4785             : 
    4786             : #ifdef __cplusplus
    4787             : }
    4788             : #endif
    4789             : 
    4790             : #endif

Generated by: LCOV version 1.15