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 : /**
3069 : * Destroy an empty poll group.
3070 : *
3071 : * \param group The group to destroy.
3072 : *
3073 : * return 0 on success, -EBUSY if the poll group is not empty.
3074 : */
3075 : int spdk_nvme_poll_group_destroy(struct spdk_nvme_poll_group *group);
3076 :
3077 : /**
3078 : * Poll for completions on all qpairs in this poll group.
3079 : *
3080 : * the disconnected_qpair_cb will be called for all disconnected qpairs in the poll group
3081 : * including qpairs which fail within the context of this call.
3082 : * The user is responsible for trying to reconnect or destroy those qpairs.
3083 : *
3084 : * \param group The group on which to poll for completions.
3085 : * \param completions_per_qpair The maximum number of completions per qpair.
3086 : * \param disconnected_qpair_cb A callback function of type spdk_nvme_disconnected_qpair_cb. Must be non-NULL.
3087 : *
3088 : * return The number of completions across all qpairs, -EINVAL if no disconnected_qpair_cb is passed, or
3089 : * -EIO if the shared completion queue cannot be polled for the RDMA transport.
3090 : */
3091 : int64_t spdk_nvme_poll_group_process_completions(struct spdk_nvme_poll_group *group,
3092 : uint32_t completions_per_qpair, spdk_nvme_disconnected_qpair_cb disconnected_qpair_cb);
3093 :
3094 : /**
3095 : * Check if all qpairs in the poll group are connected.
3096 : *
3097 : * This function allows the caller to check if all qpairs in a poll group are
3098 : * connected. This API is generally only suitable during application startup,
3099 : * to check when a large number of async connections have completed.
3100 : *
3101 : * It is useful for applications like benchmarking tools to create
3102 : * a large number of qpairs, but then ensuring they are all fully connected before
3103 : * proceeding with I/O.
3104 : *
3105 : * \param group The group on which to poll connecting qpairs.
3106 : *
3107 : * return 0 if all qpairs are in CONNECTED state, -EIO if any connections failed to connect, -EAGAIN if
3108 : * any qpairs are still trying to connected.
3109 : */
3110 : int spdk_nvme_poll_group_all_connected(struct spdk_nvme_poll_group *group);
3111 :
3112 : /**
3113 : * Retrieve the user context for this specific poll group.
3114 : *
3115 : * \param group The poll group from which to retrieve the context.
3116 : *
3117 : * \return A pointer to the user provided poll group context.
3118 : */
3119 : void *spdk_nvme_poll_group_get_ctx(struct spdk_nvme_poll_group *group);
3120 :
3121 : /**
3122 : * Retrieves transport statistics for the given poll group.
3123 : *
3124 : * Note: the structure returned by this function should later be freed with
3125 : * @b spdk_nvme_poll_group_free_stats function
3126 : *
3127 : * \param group Pointer to NVME poll group
3128 : * \param stats Double pointer to statistics to be filled by this function
3129 : * \return 0 on success or negated errno on failure
3130 : */
3131 : int spdk_nvme_poll_group_get_stats(struct spdk_nvme_poll_group *group,
3132 : struct spdk_nvme_poll_group_stat **stats);
3133 :
3134 : /**
3135 : * Frees poll group statistics retrieved using @b spdk_nvme_poll_group_get_stats function
3136 : *
3137 : * @param group Pointer to a poll group
3138 : * @param stat Pointer to statistics to be released
3139 : */
3140 : void spdk_nvme_poll_group_free_stats(struct spdk_nvme_poll_group *group,
3141 : struct spdk_nvme_poll_group_stat *stat);
3142 :
3143 : /**
3144 : * Get the identify namespace data as defined by the NVMe specification.
3145 : *
3146 : * This function is thread safe and can be called at any point while the controller
3147 : * is attached to the SPDK NVMe driver.
3148 : *
3149 : * \param ns Namespace.
3150 : *
3151 : * \return a pointer to the namespace data.
3152 : */
3153 : const struct spdk_nvme_ns_data *spdk_nvme_ns_get_data(struct spdk_nvme_ns *ns);
3154 :
3155 : /**
3156 : * Get the I/O command set specific identify namespace data for NVM command set
3157 : * as defined by the NVMe specification.
3158 : *
3159 : * This function is thread safe and can be called at any point while the controller
3160 : * is attached to the SPDK NVMe driver.
3161 : *
3162 : * \param ns Namespace.
3163 : *
3164 : * \return a pointer to the identify namespace data.
3165 : */
3166 : const struct spdk_nvme_nvm_ns_data *spdk_nvme_nvm_ns_get_data(struct spdk_nvme_ns *ns);
3167 :
3168 : /**
3169 : * Get the namespace id (index number) from the given namespace handle.
3170 : *
3171 : * This function is thread safe and can be called at any point while the controller
3172 : * is attached to the SPDK NVMe driver.
3173 : *
3174 : * \param ns Namespace.
3175 : *
3176 : * \return namespace id.
3177 : */
3178 : uint32_t spdk_nvme_ns_get_id(struct spdk_nvme_ns *ns);
3179 :
3180 : /**
3181 : * Get the controller with which this namespace is associated.
3182 : *
3183 : * This function is thread safe and can be called at any point while the controller
3184 : * is attached to the SPDK NVMe driver.
3185 : *
3186 : * \param ns Namespace.
3187 : *
3188 : * \return a pointer to the controller.
3189 : */
3190 : struct spdk_nvme_ctrlr *spdk_nvme_ns_get_ctrlr(struct spdk_nvme_ns *ns);
3191 :
3192 : /**
3193 : * Determine whether a namespace is active.
3194 : *
3195 : * Inactive namespaces cannot be the target of I/O commands.
3196 : *
3197 : * \param ns Namespace to query.
3198 : *
3199 : * \return true if active, or false if inactive.
3200 : */
3201 : bool spdk_nvme_ns_is_active(struct spdk_nvme_ns *ns);
3202 :
3203 : /**
3204 : * Get the maximum transfer size, in bytes, for an I/O sent to the given namespace.
3205 : *
3206 : * This function is thread safe and can be called at any point while the controller
3207 : * is attached to the SPDK NVMe driver.
3208 : *
3209 : * \param ns Namespace to query.
3210 : *
3211 : * \return the maximum transfer size in bytes.
3212 : */
3213 : uint32_t spdk_nvme_ns_get_max_io_xfer_size(struct spdk_nvme_ns *ns);
3214 :
3215 : /**
3216 : * Get the sector size, in bytes, of the given namespace.
3217 : *
3218 : * This function returns the size of the data sector only. It does not
3219 : * include metadata size.
3220 : *
3221 : * This function is thread safe and can be called at any point while the controller
3222 : * is attached to the SPDK NVMe driver.
3223 : *
3224 : * \param ns Namespace to query.
3225 : *
3226 : * /return the sector size in bytes.
3227 : */
3228 : uint32_t spdk_nvme_ns_get_sector_size(struct spdk_nvme_ns *ns);
3229 :
3230 : /**
3231 : * Get the extended sector size, in bytes, of the given namespace.
3232 : *
3233 : * This function returns the size of the data sector plus metadata.
3234 : *
3235 : * This function is thread safe and can be called at any point while the controller
3236 : * is attached to the SPDK NVMe driver.
3237 : *
3238 : * \param ns Namespace to query.
3239 : *
3240 : * /return the extended sector size in bytes.
3241 : */
3242 : uint32_t spdk_nvme_ns_get_extended_sector_size(struct spdk_nvme_ns *ns);
3243 :
3244 : /**
3245 : * Get the number of sectors for the given namespace.
3246 : *
3247 : * This function is thread safe and can be called at any point while the controller
3248 : * is attached to the SPDK NVMe driver.
3249 : *
3250 : * \param ns Namespace to query.
3251 : *
3252 : * \return the number of sectors.
3253 : */
3254 : uint64_t spdk_nvme_ns_get_num_sectors(struct spdk_nvme_ns *ns);
3255 :
3256 : /**
3257 : * Get the size, in bytes, of the given namespace.
3258 : *
3259 : * This function is thread safe and can be called at any point while the controller
3260 : * is attached to the SPDK NVMe driver.
3261 : *
3262 : * \param ns Namespace to query.
3263 : *
3264 : * \return the size of the given namespace in bytes.
3265 : */
3266 : uint64_t spdk_nvme_ns_get_size(struct spdk_nvme_ns *ns);
3267 :
3268 : /**
3269 : * Get the end-to-end data protection information type of the given namespace.
3270 : *
3271 : * This function is thread safe and can be called at any point while the controller
3272 : * is attached to the SPDK NVMe driver.
3273 : *
3274 : * \param ns Namespace to query.
3275 : *
3276 : * \return the end-to-end data protection information type.
3277 : */
3278 : enum spdk_nvme_pi_type spdk_nvme_ns_get_pi_type(struct spdk_nvme_ns *ns);
3279 :
3280 : /**
3281 : * Get the end-to-end data protection information format of the given namespace.
3282 : *
3283 : * This function is thread safe and can be called at any point while the controller
3284 : * is attached to the SPDK NVMe driver.
3285 : *
3286 : * \param ns Namespace to query.
3287 : *
3288 : * \return the end-to-end data protection information format.
3289 : */
3290 : enum spdk_nvme_pi_format spdk_nvme_ns_get_pi_format(struct spdk_nvme_ns *ns);
3291 :
3292 : /**
3293 : * Get the metadata size, in bytes, of the given namespace.
3294 : *
3295 : * This function is thread safe and can be called at any point while the controller
3296 : * is attached to the SPDK NVMe driver.
3297 : *
3298 : * \param ns Namespace to query.
3299 : *
3300 : * \return the metadata size of the given namespace in bytes.
3301 : */
3302 : uint32_t spdk_nvme_ns_get_md_size(struct spdk_nvme_ns *ns);
3303 :
3304 : /**
3305 : * Get the format index of the given namespace.
3306 : *
3307 : * This function is thread safe and can be called at any point while the controller
3308 : * is attached to the SPDK NVMe driver.
3309 : *
3310 : * \param nsdata pointer to the NVMe namespace data.
3311 : *
3312 : * \return the format index of the given namespace.
3313 : */
3314 : uint32_t spdk_nvme_ns_get_format_index(const struct spdk_nvme_ns_data *nsdata);
3315 :
3316 : /**
3317 : * Check whether if the namespace can support extended LBA when end-to-end data
3318 : * protection enabled.
3319 : *
3320 : * This function is thread safe and can be called at any point while the controller
3321 : * is attached to the SPDK NVMe driver.
3322 : *
3323 : * \param ns Namespace to query.
3324 : *
3325 : * \return true if the namespace can support extended LBA when end-to-end data
3326 : * protection enabled, or false otherwise.
3327 : */
3328 : bool spdk_nvme_ns_supports_extended_lba(struct spdk_nvme_ns *ns);
3329 :
3330 : /**
3331 : * Check whether if the namespace supports compare operation
3332 : *
3333 : * This function is thread safe and can be called at any point while the controller
3334 : * is attached to the SPDK NVMe driver.
3335 : *
3336 : * \param ns Namespace to query.
3337 : *
3338 : * \return true if the namespace supports compare operation, or false otherwise.
3339 : */
3340 : bool spdk_nvme_ns_supports_compare(struct spdk_nvme_ns *ns);
3341 :
3342 : /**
3343 : * Determine the value returned when reading deallocated blocks.
3344 : *
3345 : * If deallocated blocks return 0, the deallocate command can be used as a more
3346 : * efficient alternative to the write_zeroes command, especially for large requests.
3347 : *
3348 : * \param ns Namespace.
3349 : *
3350 : * \return the logical block read value.
3351 : */
3352 : enum spdk_nvme_dealloc_logical_block_read_value spdk_nvme_ns_get_dealloc_logical_block_read_value(
3353 : struct spdk_nvme_ns *ns);
3354 :
3355 : /**
3356 : * Get the optimal I/O boundary, in blocks, for the given namespace.
3357 : *
3358 : * Read and write commands should not cross the optimal I/O boundary for best
3359 : * performance.
3360 : *
3361 : * \param ns Namespace to query.
3362 : *
3363 : * \return Optimal granularity of I/O commands, in blocks, or 0 if no optimal
3364 : * granularity is reported.
3365 : */
3366 : uint32_t spdk_nvme_ns_get_optimal_io_boundary(struct spdk_nvme_ns *ns);
3367 :
3368 : /**
3369 : * Get the NGUID for the given namespace.
3370 : *
3371 : * \param ns Namespace to query.
3372 : *
3373 : * \return a pointer to namespace NGUID, or NULL if ns does not have a NGUID.
3374 : */
3375 : const uint8_t *spdk_nvme_ns_get_nguid(const struct spdk_nvme_ns *ns);
3376 :
3377 : /**
3378 : * Get the UUID for the given namespace.
3379 : *
3380 : * \param ns Namespace to query.
3381 : *
3382 : * \return a pointer to namespace UUID, or NULL if ns does not have a UUID.
3383 : */
3384 : const struct spdk_uuid *spdk_nvme_ns_get_uuid(const struct spdk_nvme_ns *ns);
3385 :
3386 : /**
3387 : * Get the Command Set Identifier for the given namespace.
3388 : *
3389 : * \param ns Namespace to query.
3390 : *
3391 : * \return the namespace Command Set Identifier.
3392 : */
3393 : enum spdk_nvme_csi spdk_nvme_ns_get_csi(const struct spdk_nvme_ns *ns);
3394 :
3395 : /**
3396 : * \brief Namespace command support flags.
3397 : */
3398 : enum spdk_nvme_ns_flags {
3399 : SPDK_NVME_NS_DEALLOCATE_SUPPORTED = 1 << 0, /**< The deallocate command is supported */
3400 : SPDK_NVME_NS_FLUSH_SUPPORTED = 1 << 1, /**< The flush command is supported */
3401 : SPDK_NVME_NS_RESERVATION_SUPPORTED = 1 << 2, /**< The reservation command is supported */
3402 : SPDK_NVME_NS_WRITE_ZEROES_SUPPORTED = 1 << 3, /**< The write zeroes command is supported */
3403 : SPDK_NVME_NS_DPS_PI_SUPPORTED = 1 << 4, /**< The end-to-end data protection is supported */
3404 : SPDK_NVME_NS_EXTENDED_LBA_SUPPORTED = 1 << 5, /**< The extended lba format is supported,
3405 : metadata is transferred as a contiguous
3406 : part of the logical block that it is associated with */
3407 : SPDK_NVME_NS_WRITE_UNCORRECTABLE_SUPPORTED = 1 << 6, /**< The write uncorrectable command is supported */
3408 : SPDK_NVME_NS_COMPARE_SUPPORTED = 1 << 7, /**< The compare command is supported */
3409 : };
3410 :
3411 : /**
3412 : * Get the flags for the given namespace.
3413 : *
3414 : * See spdk_nvme_ns_flags for the possible flags returned.
3415 : *
3416 : * This function is thread safe and can be called at any point while the controller
3417 : * is attached to the SPDK NVMe driver.
3418 : *
3419 : * \param ns Namespace to query.
3420 : *
3421 : * \return the flags for the given namespace.
3422 : */
3423 : uint32_t spdk_nvme_ns_get_flags(struct spdk_nvme_ns *ns);
3424 :
3425 : /**
3426 : * Get the ANA group ID for the given namespace.
3427 : *
3428 : * This function should be called only if spdk_nvme_ctrlr_is_log_page_supported() returns
3429 : * true for the controller and log page ID SPDK_NVME_LOG_ASYMMETRIC_NAMESPACE_ACCESS.
3430 : *
3431 : * This function is thread safe and can be called at any point while the controller
3432 : * is attached to the SPDK NVMe driver.
3433 : *
3434 : * \param ns Namespace to query.
3435 : *
3436 : * \return the ANA group ID for the given namespace.
3437 : */
3438 : uint32_t spdk_nvme_ns_get_ana_group_id(const struct spdk_nvme_ns *ns);
3439 :
3440 : /**
3441 : * Get the ANA state for the given namespace.
3442 : *
3443 : * This function should be called only if spdk_nvme_ctrlr_is_log_page_supported() returns
3444 : * true for the controller and log page ID SPDK_NVME_LOG_ASYMMETRIC_NAMESPACE_ACCESS.
3445 : *
3446 : * This function is thread safe and can be called at any point while the controller
3447 : * is attached to the SPDK NVMe driver.
3448 : *
3449 : * \param ns Namespace to query.
3450 : *
3451 : * \return the ANA state for the given namespace.
3452 : */
3453 : enum spdk_nvme_ana_state spdk_nvme_ns_get_ana_state(const struct spdk_nvme_ns *ns);
3454 :
3455 : /**
3456 : * Submit a write I/O to the specified NVMe namespace.
3457 : *
3458 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3459 : * The user must ensure that only one thread submits I/O on a given qpair at any
3460 : * given time.
3461 : *
3462 : * \param ns NVMe namespace to submit the write I/O.
3463 : * \param qpair I/O queue pair to submit the request.
3464 : * \param payload Virtual address pointer to the data payload.
3465 : * \param lba Starting LBA to write the data.
3466 : * \param lba_count Length (in sectors) for the write operation.
3467 : * \param cb_fn Callback function to invoke when the I/O is completed.
3468 : * \param cb_arg Argument to pass to the callback function.
3469 : * \param io_flags Set flags, defined by the SPDK_NVME_IO_FLAGS_* entries in
3470 : * spdk/nvme_spec.h, for this I/O.
3471 : *
3472 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3473 : * -EINVAL: The request is malformed.
3474 : * -ENOMEM: The request cannot be allocated.
3475 : * -ENXIO: The qpair is failed at the transport level.
3476 : */
3477 : int spdk_nvme_ns_cmd_write(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair, void *payload,
3478 : uint64_t lba, uint32_t lba_count, spdk_nvme_cmd_cb cb_fn,
3479 : void *cb_arg, uint32_t io_flags);
3480 :
3481 : /**
3482 : * Submit a write I/O to the specified NVMe namespace.
3483 : *
3484 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3485 : * The user must ensure that only one thread submits I/O on a given qpair at any
3486 : * given time.
3487 : *
3488 : * \param ns NVMe namespace to submit the write I/O.
3489 : * \param qpair I/O queue pair to submit the request.
3490 : * \param lba Starting LBA to write the data.
3491 : * \param lba_count Length (in sectors) for the write operation.
3492 : * \param cb_fn Callback function to invoke when the I/O is completed.
3493 : * \param cb_arg Argument to pass to the callback function.
3494 : * \param io_flags Set flags, defined in nvme_spec.h, for this I/O.
3495 : * \param reset_sgl_fn Callback function to reset scattered payload.
3496 : * \param next_sge_fn Callback function to iterate each scattered payload memory
3497 : * segment.
3498 : *
3499 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3500 : * -EINVAL: The request is malformed.
3501 : * -ENOMEM: The request cannot be allocated.
3502 : * -ENXIO: The qpair is failed at the transport level.
3503 : */
3504 : int spdk_nvme_ns_cmd_writev(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
3505 : uint64_t lba, uint32_t lba_count,
3506 : spdk_nvme_cmd_cb cb_fn, void *cb_arg, uint32_t io_flags,
3507 : spdk_nvme_req_reset_sgl_cb reset_sgl_fn,
3508 : spdk_nvme_req_next_sge_cb next_sge_fn);
3509 :
3510 : /**
3511 : * Submit a write I/O to the specified NVMe namespace.
3512 : *
3513 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3514 : * The user must ensure that only one thread submits I/O on a given qpair at any
3515 : * given time.
3516 : *
3517 : * \param ns NVMe namespace to submit the write I/O
3518 : * \param qpair I/O queue pair to submit the request
3519 : * \param lba starting LBA to write the data
3520 : * \param lba_count length (in sectors) for the write operation
3521 : * \param cb_fn callback function to invoke when the I/O is completed
3522 : * \param cb_arg argument to pass to the callback function
3523 : * \param io_flags set flags, defined in nvme_spec.h, for this I/O
3524 : * \param reset_sgl_fn callback function to reset scattered payload
3525 : * \param next_sge_fn callback function to iterate each scattered
3526 : * payload memory segment
3527 : * \param metadata virtual address pointer to the metadata payload, the length
3528 : * of metadata is specified by spdk_nvme_ns_get_md_size()
3529 : * \param apptag_mask application tag mask.
3530 : * \param apptag application tag to use end-to-end protection information.
3531 : *
3532 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3533 : * -EINVAL: The request is malformed.
3534 : * -ENOMEM: The request cannot be allocated.
3535 : * -ENXIO: The qpair is failed at the transport level.
3536 : */
3537 : int spdk_nvme_ns_cmd_writev_with_md(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
3538 : uint64_t lba, uint32_t lba_count,
3539 : spdk_nvme_cmd_cb cb_fn, void *cb_arg, uint32_t io_flags,
3540 : spdk_nvme_req_reset_sgl_cb reset_sgl_fn,
3541 : spdk_nvme_req_next_sge_cb next_sge_fn, void *metadata,
3542 : uint16_t apptag_mask, uint16_t apptag);
3543 :
3544 : /**
3545 : * Submit a write I/O to the specified NVMe namespace.
3546 : *
3547 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3548 : * The user must ensure that only one thread submits I/O on a given qpair at any
3549 : * given time.
3550 : *
3551 : * \param ns NVMe namespace to submit the write I/O
3552 : * \param qpair I/O queue pair to submit the request
3553 : * \param lba starting LBA to write the data
3554 : * \param lba_count length (in sectors) for the write operation
3555 : * \param cb_fn callback function to invoke when the I/O is completed
3556 : * \param cb_arg argument to pass to the callback function
3557 : * \param reset_sgl_fn callback function to reset scattered payload
3558 : * \param next_sge_fn callback function to iterate each scattered
3559 : * payload memory segment
3560 : * \param opts Optional structure with extended IO request options. If provided, the caller must
3561 : * guarantee that this structure is accessible until IO completes
3562 : *
3563 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3564 : * -EINVAL: The request is malformed.
3565 : * -ENOMEM: The request cannot be allocated.
3566 : * -ENXIO: The qpair is failed at the transport level.
3567 : * -EFAULT: Invalid address was specified as part of payload. cb_fn is also called
3568 : * with error status including dnr=1 in this case.
3569 : */
3570 : int spdk_nvme_ns_cmd_writev_ext(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
3571 : uint64_t lba, uint32_t lba_count,
3572 : spdk_nvme_cmd_cb cb_fn, void *cb_arg,
3573 : spdk_nvme_req_reset_sgl_cb reset_sgl_fn,
3574 : spdk_nvme_req_next_sge_cb next_sge_fn,
3575 : struct spdk_nvme_ns_cmd_ext_io_opts *opts);
3576 :
3577 : /**
3578 : * Submit a write I/O to the specified NVMe namespace.
3579 : *
3580 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3581 : * The user must ensure that only one thread submits I/O on a given qpair at any
3582 : * given time.
3583 : *
3584 : * \param ns NVMe namespace to submit the write I/O
3585 : * \param qpair I/O queue pair to submit the request
3586 : * \param payload Virtual address pointer to the data payload.
3587 : * \param lba starting LBA to write the data
3588 : * \param lba_count length (in sectors) for the write operation
3589 : * \param cb_fn callback function to invoke when the I/O is completed
3590 : * \param cb_arg argument to pass to the callback function
3591 : * \param opts Optional structure with extended IO request options. If provided, the caller must
3592 : * guarantee that this structure is accessible until IO completes
3593 : *
3594 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3595 : * -EINVAL: The request is malformed.
3596 : * -ENOMEM: The request cannot be allocated.
3597 : * -ENXIO: The qpair is failed at the transport level.
3598 : * -EFAULT: Invalid address was specified as part of payload. cb_fn is also called
3599 : * with error status including dnr=1 in this case.
3600 : */
3601 : int spdk_nvme_ns_cmd_write_ext(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
3602 : void *payload, uint64_t lba, uint32_t lba_count, spdk_nvme_cmd_cb cb_fn, void *cb_arg,
3603 : struct spdk_nvme_ns_cmd_ext_io_opts *opts);
3604 :
3605 : /**
3606 : * Submit a write I/O to the specified NVMe namespace.
3607 : *
3608 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3609 : * The user must ensure that only one thread submits I/O on a given qpair at any
3610 : * given time.
3611 : *
3612 : * \param ns NVMe namespace to submit the write I/O.
3613 : * \param qpair I/O queue pair to submit the request.
3614 : * \param payload Virtual address pointer to the data payload.
3615 : * \param metadata Virtual address pointer to the metadata payload, the length
3616 : * of metadata is specified by spdk_nvme_ns_get_md_size().
3617 : * \param lba Starting LBA to write the data.
3618 : * \param lba_count Length (in sectors) for the write operation.
3619 : * \param cb_fn Callback function to invoke when the I/O is completed.
3620 : * \param cb_arg Argument to pass to the callback function.
3621 : * \param io_flags Set flags, defined by the SPDK_NVME_IO_FLAGS_* entries in
3622 : * spdk/nvme_spec.h, for this I/O.
3623 : * \param apptag_mask Application tag mask.
3624 : * \param apptag Application tag to use end-to-end protection information.
3625 : *
3626 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3627 : * -EINVAL: The request is malformed.
3628 : * -ENOMEM: The request cannot be allocated.
3629 : * -ENXIO: The qpair is failed at the transport level.
3630 : */
3631 : int spdk_nvme_ns_cmd_write_with_md(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
3632 : void *payload, void *metadata,
3633 : uint64_t lba, uint32_t lba_count, spdk_nvme_cmd_cb cb_fn,
3634 : void *cb_arg, uint32_t io_flags,
3635 : uint16_t apptag_mask, uint16_t apptag);
3636 :
3637 : /**
3638 : * Submit a write zeroes I/O to the specified NVMe namespace.
3639 : *
3640 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3641 : * The user must ensure that only one thread submits I/O on a given qpair at any
3642 : * given time.
3643 : *
3644 : * \param ns NVMe namespace to submit the write zeroes I/O.
3645 : * \param qpair I/O queue pair to submit the request.
3646 : * \param lba Starting LBA for this command.
3647 : * \param lba_count Length (in sectors) for the write zero operation.
3648 : * \param cb_fn Callback function to invoke when the I/O is completed.
3649 : * \param cb_arg Argument to pass to the callback function.
3650 : * \param io_flags Set flags, defined by the SPDK_NVME_IO_FLAGS_* entries in
3651 : * spdk/nvme_spec.h, for this I/O.
3652 : *
3653 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3654 : * -EINVAL: The request is malformed.
3655 : * -ENOMEM: The request cannot be allocated.
3656 : * -ENXIO: The qpair is failed at the transport level.
3657 : */
3658 : int spdk_nvme_ns_cmd_write_zeroes(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
3659 : uint64_t lba, uint32_t lba_count,
3660 : spdk_nvme_cmd_cb cb_fn, void *cb_arg,
3661 : uint32_t io_flags);
3662 :
3663 : /**
3664 : * Submit a verify I/O to the specified NVMe namespace.
3665 : *
3666 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3667 : * The user must ensure that only one thread submits I/O on a given qpair at any
3668 : * given time.
3669 : *
3670 : * \param ns NVMe namespace to submit the verify I/O.
3671 : * \param qpair I/O queue pair to submit the request.
3672 : * \param lba Starting LBA to verify the data.
3673 : * \param lba_count Length (in sectors) for the verify operation.
3674 : * \param cb_fn Callback function to invoke when the I/O is completed.
3675 : * \param cb_arg Argument to pass to the callback function.
3676 : * \param io_flags Set flags, defined by the SPDK_NVME_IO_FLAGS_* entries in
3677 : * spdk/nvme_spec.h, for this I/O.
3678 : *
3679 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3680 : * -EINVAL: The request is malformed.
3681 : * -ENOMEM: The request cannot be allocated.
3682 : * -ENXIO: The qpair is failed at the transport level.
3683 : */
3684 : int spdk_nvme_ns_cmd_verify(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
3685 : uint64_t lba, uint32_t lba_count,
3686 : spdk_nvme_cmd_cb cb_fn, void *cb_arg,
3687 : uint32_t io_flags);
3688 :
3689 : /**
3690 : * Submit a write uncorrectable I/O to the specified NVMe namespace.
3691 : *
3692 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3693 : * The user must ensure that only one thread submits I/O on a given qpair at any
3694 : * given time.
3695 : *
3696 : * \param ns NVMe namespace to submit the write uncorrectable I/O.
3697 : * \param qpair I/O queue pair to submit the request.
3698 : * \param lba Starting LBA for this command.
3699 : * \param lba_count Length (in sectors) for the write uncorrectable operation.
3700 : * \param cb_fn Callback function to invoke when the I/O is completed.
3701 : * \param cb_arg Argument to pass to the callback function.
3702 : *
3703 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3704 : * -EINVAL: The request is malformed.
3705 : * -ENOMEM: The request cannot be allocated.
3706 : * -ENXIO: The qpair is failed at the transport level.
3707 : */
3708 : int spdk_nvme_ns_cmd_write_uncorrectable(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
3709 : uint64_t lba, uint32_t lba_count,
3710 : spdk_nvme_cmd_cb cb_fn, void *cb_arg);
3711 :
3712 : /**
3713 : * \brief Submits a read I/O to the specified NVMe namespace.
3714 : *
3715 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3716 : * The user must ensure that only one thread submits I/O on a given qpair at any
3717 : * given time.
3718 : *
3719 : * \param ns NVMe namespace to submit the read I/O.
3720 : * \param qpair I/O queue pair to submit the request.
3721 : * \param payload Virtual address pointer to the data payload.
3722 : * \param lba Starting LBA to read the data.
3723 : * \param lba_count Length (in sectors) for the read operation.
3724 : * \param cb_fn Callback function to invoke when the I/O is completed.
3725 : * \param cb_arg Argument to pass to the callback function.
3726 : * \param io_flags Set flags, defined in nvme_spec.h, for this I/O.
3727 : *
3728 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3729 : * -EINVAL: The request is malformed.
3730 : * -ENOMEM: The request cannot be allocated.
3731 : * -ENXIO: The qpair is failed at the transport level.
3732 : */
3733 : int spdk_nvme_ns_cmd_read(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair, void *payload,
3734 : uint64_t lba, uint32_t lba_count, spdk_nvme_cmd_cb cb_fn,
3735 : void *cb_arg, uint32_t io_flags);
3736 :
3737 : /**
3738 : * Submit a read I/O to the specified NVMe namespace.
3739 : *
3740 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3741 : * The user must ensure that only one thread submits I/O on a given qpair at any
3742 : * given time.
3743 : *
3744 : * \param ns NVMe namespace to submit the read I/O.
3745 : * \param qpair I/O queue pair to submit the request.
3746 : * \param lba Starting LBA to read the data.
3747 : * \param lba_count Length (in sectors) for the read operation.
3748 : * \param cb_fn Callback function to invoke when the I/O is completed.
3749 : * \param cb_arg Argument to pass to the callback function.
3750 : * \param io_flags Set flags, defined in nvme_spec.h, for this I/O.
3751 : * \param reset_sgl_fn Callback function to reset scattered payload.
3752 : * \param next_sge_fn Callback function to iterate each scattered payload memory
3753 : * segment.
3754 : *
3755 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3756 : * -EINVAL: The request is malformed.
3757 : * -ENOMEM: The request cannot be allocated.
3758 : * -ENXIO: The qpair is failed at the transport level.
3759 : */
3760 : int spdk_nvme_ns_cmd_readv(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
3761 : uint64_t lba, uint32_t lba_count,
3762 : spdk_nvme_cmd_cb cb_fn, void *cb_arg, uint32_t io_flags,
3763 : spdk_nvme_req_reset_sgl_cb reset_sgl_fn,
3764 : spdk_nvme_req_next_sge_cb next_sge_fn);
3765 :
3766 : /**
3767 : * Submit a read I/O to the specified NVMe namespace.
3768 : *
3769 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3770 : * The user must ensure that only one thread submits I/O on a given qpair at any given time.
3771 : *
3772 : * \param ns NVMe namespace to submit the read I/O
3773 : * \param qpair I/O queue pair to submit the request
3774 : * \param lba starting LBA to read the data
3775 : * \param lba_count length (in sectors) for the read operation
3776 : * \param cb_fn callback function to invoke when the I/O is completed
3777 : * \param cb_arg argument to pass to the callback function
3778 : * \param io_flags set flags, defined in nvme_spec.h, for this I/O
3779 : * \param reset_sgl_fn callback function to reset scattered payload
3780 : * \param next_sge_fn callback function to iterate each scattered
3781 : * payload memory segment
3782 : * \param metadata virtual address pointer to the metadata payload, the length
3783 : * of metadata is specified by spdk_nvme_ns_get_md_size()
3784 : * \param apptag_mask application tag mask.
3785 : * \param apptag application tag to use end-to-end protection information.
3786 : *
3787 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3788 : * -EINVAL: The request is malformed.
3789 : * -ENOMEM: The request cannot be allocated.
3790 : * -ENXIO: The qpair is failed at the transport level.
3791 : */
3792 : int spdk_nvme_ns_cmd_readv_with_md(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
3793 : uint64_t lba, uint32_t lba_count,
3794 : spdk_nvme_cmd_cb cb_fn, void *cb_arg, uint32_t io_flags,
3795 : spdk_nvme_req_reset_sgl_cb reset_sgl_fn,
3796 : spdk_nvme_req_next_sge_cb next_sge_fn, void *metadata,
3797 : uint16_t apptag_mask, uint16_t apptag);
3798 :
3799 : /**
3800 : * Submit a read I/O to the specified NVMe namespace.
3801 : *
3802 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3803 : * The user must ensure that only one thread submits I/O on a given qpair at any given time.
3804 : *
3805 : * \param ns NVMe namespace to submit the read I/O
3806 : * \param qpair I/O queue pair to submit the request
3807 : * \param lba starting LBA to read the data
3808 : * \param lba_count length (in sectors) for the read operation
3809 : * \param cb_fn callback function to invoke when the I/O is completed
3810 : * \param cb_arg argument to pass to the callback function
3811 : * \param reset_sgl_fn callback function to reset scattered payload
3812 : * \param next_sge_fn callback function to iterate each scattered
3813 : * payload memory segment
3814 : * \param opts Optional structure with extended IO request options. If provided, the caller must
3815 : * guarantee that this structure is accessible until IO completes
3816 : *
3817 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3818 : * -EINVAL: The request is malformed.
3819 : * -ENOMEM: The request cannot be allocated.
3820 : * -ENXIO: The qpair is failed at the transport level.
3821 : * -EFAULT: Invalid address was specified as part of payload. cb_fn is also called
3822 : * with error status including dnr=1 in this case.
3823 : */
3824 : int spdk_nvme_ns_cmd_readv_ext(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
3825 : uint64_t lba, uint32_t lba_count, spdk_nvme_cmd_cb cb_fn,
3826 : void *cb_arg, spdk_nvme_req_reset_sgl_cb reset_sgl_fn,
3827 : spdk_nvme_req_next_sge_cb next_sge_fn,
3828 : struct spdk_nvme_ns_cmd_ext_io_opts *opts);
3829 :
3830 : /**
3831 : * Submit a read I/O to the specified NVMe namespace.
3832 : *
3833 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3834 : * The user must ensure that only one thread submits I/O on a given qpair at any given time.
3835 : *
3836 : * \param ns NVMe namespace to submit the read I/O
3837 : * \param qpair I/O queue pair to submit the request
3838 : * \param payload virtual address pointer to the data payload
3839 : * \param lba starting LBA to read the data
3840 : * \param lba_count length (in sectors) for the read operation
3841 : * \param cb_fn callback function to invoke when the I/O is completed
3842 : * \param cb_arg argument to pass to the callback function
3843 : * \param opts Optional structure with extended IO request options. If provided, the caller must
3844 : * guarantee that this structure is accessible until IO completes
3845 : *
3846 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3847 : * -EINVAL: The request is malformed.
3848 : * -ENOMEM: The request cannot be allocated.
3849 : * -ENXIO: The qpair is failed at the transport level.
3850 : * -EFAULT: Invalid address was specified as part of payload. cb_fn is also called
3851 : * with error status including dnr=1 in this case.
3852 : */
3853 : int spdk_nvme_ns_cmd_read_ext(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair, void *payload,
3854 : uint64_t lba, uint32_t lba_count, spdk_nvme_cmd_cb cb_fn, void *cb_arg,
3855 : struct spdk_nvme_ns_cmd_ext_io_opts *opts);
3856 :
3857 : /**
3858 : * Submits a read I/O to the specified NVMe namespace.
3859 : *
3860 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3861 : * The user must ensure that only one thread submits I/O on a given qpair at any
3862 : * given time.
3863 : *
3864 : * \param ns NVMe namespace to submit the read I/O
3865 : * \param qpair I/O queue pair to submit the request
3866 : * \param payload virtual address pointer to the data payload
3867 : * \param metadata virtual address pointer to the metadata payload, the length
3868 : * of metadata is specified by spdk_nvme_ns_get_md_size().
3869 : * \param lba starting LBA to read the data.
3870 : * \param lba_count Length (in sectors) for the read operation.
3871 : * \param cb_fn Callback function to invoke when the I/O is completed.
3872 : * \param cb_arg Argument to pass to the callback function.
3873 : * \param io_flags Set flags, defined in nvme_spec.h, for this I/O.
3874 : * \param apptag_mask Application tag mask.
3875 : * \param apptag Application tag to use end-to-end protection information.
3876 : *
3877 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3878 : * -EINVAL: The request is malformed.
3879 : * -ENOMEM: The request cannot be allocated.
3880 : * -ENXIO: The qpair is failed at the transport level.
3881 : */
3882 : int spdk_nvme_ns_cmd_read_with_md(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
3883 : void *payload, void *metadata,
3884 : uint64_t lba, uint32_t lba_count, spdk_nvme_cmd_cb cb_fn,
3885 : void *cb_arg, uint32_t io_flags,
3886 : uint16_t apptag_mask, uint16_t apptag);
3887 :
3888 : /**
3889 : * Submit a data set management request to the specified NVMe namespace.
3890 : *
3891 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3892 : * The user must ensure that only one thread submits I/O on a given qpair at any
3893 : * given time.
3894 : *
3895 : * This is a convenience wrapper that will automatically allocate and construct
3896 : * the correct data buffers. Therefore, ranges does not need to be allocated from
3897 : * pinned memory and can be placed on the stack. If a higher performance, zero-copy
3898 : * version of DSM is required, simply build and submit a raw command using
3899 : * spdk_nvme_ctrlr_cmd_io_raw().
3900 : *
3901 : * \param ns NVMe namespace to submit the DSM request
3902 : * \param type A bit field constructed from \ref spdk_nvme_dsm_attribute.
3903 : * \param qpair I/O queue pair to submit the request
3904 : * \param ranges An array of \ref spdk_nvme_dsm_range elements describing the LBAs
3905 : * to operate on.
3906 : * \param num_ranges The number of elements in the ranges array.
3907 : * \param cb_fn Callback function to invoke when the I/O is completed
3908 : * \param cb_arg Argument to pass to the callback function
3909 : *
3910 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3911 : * -ENOMEM: The request cannot be allocated.
3912 : * -ENXIO: The qpair is failed at the transport level.
3913 : */
3914 : int spdk_nvme_ns_cmd_dataset_management(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
3915 : uint32_t type,
3916 : const struct spdk_nvme_dsm_range *ranges,
3917 : uint16_t num_ranges,
3918 : spdk_nvme_cmd_cb cb_fn,
3919 : void *cb_arg);
3920 :
3921 : /**
3922 : * Submit a simple copy command request to the specified NVMe namespace.
3923 : *
3924 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3925 : * The user must ensure that only one thread submits I/O on a given qpair at any
3926 : * given time.
3927 : *
3928 : * This is a convenience wrapper that will automatically allocate and construct
3929 : * the correct data buffers. Therefore, ranges does not need to be allocated from
3930 : * pinned memory and can be placed on the stack. If a higher performance, zero-copy
3931 : * version of SCC is required, simply build and submit a raw command using
3932 : * spdk_nvme_ctrlr_cmd_io_raw().
3933 : *
3934 : * \param ns NVMe namespace to submit the SCC request
3935 : * \param qpair I/O queue pair to submit the request
3936 : * \param ranges An array of \ref spdk_nvme_scc_source_range elements describing the LBAs
3937 : * to operate on.
3938 : * \param num_ranges The number of elements in the ranges array.
3939 : * \param dest_lba Destination LBA to copy the data.
3940 : * \param cb_fn Callback function to invoke when the I/O is completed
3941 : * \param cb_arg Argument to pass to the callback function
3942 : *
3943 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3944 : * -ENOMEM: The request cannot be allocated.
3945 : * -EINVAL: Invalid ranges.
3946 : * -ENXIO: The qpair is failed at the transport level.
3947 : */
3948 : int spdk_nvme_ns_cmd_copy(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
3949 : const struct spdk_nvme_scc_source_range *ranges,
3950 : uint16_t num_ranges,
3951 : uint64_t dest_lba,
3952 : spdk_nvme_cmd_cb cb_fn,
3953 : void *cb_arg);
3954 :
3955 : /**
3956 : * Submit a flush request to the specified NVMe namespace.
3957 : *
3958 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3959 : * The user must ensure that only one thread submits I/O on a given qpair at any
3960 : * given time.
3961 : *
3962 : * \param ns NVMe namespace to submit the flush request.
3963 : * \param qpair I/O queue pair to submit the request.
3964 : * \param cb_fn Callback function to invoke when the I/O is completed.
3965 : * \param cb_arg Argument to pass to the callback function.
3966 : *
3967 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3968 : * -ENOMEM: The request cannot be allocated.
3969 : * -ENXIO: The qpair is failed at the transport level.
3970 : */
3971 : int spdk_nvme_ns_cmd_flush(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
3972 : spdk_nvme_cmd_cb cb_fn, void *cb_arg);
3973 :
3974 : /**
3975 : * Submit a reservation register to the specified NVMe namespace.
3976 : *
3977 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3978 : * The user must ensure that only one thread submits I/O on a given qpair at any
3979 : * given time.
3980 : *
3981 : * \param ns NVMe namespace to submit the reservation register request.
3982 : * \param qpair I/O queue pair to submit the request.
3983 : * \param payload Virtual address pointer to the reservation register data.
3984 : * \param ignore_key '1' the current reservation key check is disabled.
3985 : * \param action Specifies the registration action.
3986 : * \param cptpl Change the Persist Through Power Loss state.
3987 : * \param cb_fn Callback function to invoke when the I/O is completed.
3988 : * \param cb_arg Argument to pass to the callback function.
3989 : *
3990 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3991 : * -ENOMEM: The request cannot be allocated.
3992 : * -ENXIO: The qpair is failed at the transport level.
3993 : */
3994 : int spdk_nvme_ns_cmd_reservation_register(struct spdk_nvme_ns *ns,
3995 : struct spdk_nvme_qpair *qpair,
3996 : struct spdk_nvme_reservation_register_data *payload,
3997 : bool ignore_key,
3998 : enum spdk_nvme_reservation_register_action action,
3999 : enum spdk_nvme_reservation_register_cptpl cptpl,
4000 : spdk_nvme_cmd_cb cb_fn, void *cb_arg);
4001 :
4002 : /**
4003 : * Submits a reservation release to the specified NVMe namespace.
4004 : *
4005 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
4006 : * The user must ensure that only one thread submits I/O on a given qpair at any
4007 : * given time.
4008 : *
4009 : * \param ns NVMe namespace to submit the reservation release request.
4010 : * \param qpair I/O queue pair to submit the request.
4011 : * \param payload Virtual address pointer to current reservation key.
4012 : * \param ignore_key '1' the current reservation key check is disabled.
4013 : * \param action Specifies the reservation release action.
4014 : * \param type Reservation type for the namespace.
4015 : * \param cb_fn Callback function to invoke when the I/O is completed.
4016 : * \param cb_arg Argument to pass to the callback function.
4017 : *
4018 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
4019 : * -ENOMEM: The request cannot be allocated.
4020 : * -ENXIO: The qpair is failed at the transport level.
4021 : */
4022 : int spdk_nvme_ns_cmd_reservation_release(struct spdk_nvme_ns *ns,
4023 : struct spdk_nvme_qpair *qpair,
4024 : struct spdk_nvme_reservation_key_data *payload,
4025 : bool ignore_key,
4026 : enum spdk_nvme_reservation_release_action action,
4027 : enum spdk_nvme_reservation_type type,
4028 : spdk_nvme_cmd_cb cb_fn, void *cb_arg);
4029 :
4030 : /**
4031 : * Submits a reservation acquire to the specified NVMe namespace.
4032 : *
4033 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
4034 : * The user must ensure that only one thread submits I/O on a given qpair at any
4035 : * given time.
4036 : *
4037 : * \param ns NVMe namespace to submit the reservation acquire request.
4038 : * \param qpair I/O queue pair to submit the request.
4039 : * \param payload Virtual address pointer to reservation acquire data.
4040 : * \param ignore_key '1' the current reservation key check is disabled.
4041 : * \param action Specifies the reservation acquire action.
4042 : * \param type Reservation type for the namespace.
4043 : * \param cb_fn Callback function to invoke when the I/O is completed.
4044 : * \param cb_arg Argument to pass to the callback function.
4045 : *
4046 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
4047 : * -ENOMEM: The request cannot be allocated.
4048 : * -ENXIO: The qpair is failed at the transport level.
4049 : */
4050 : int spdk_nvme_ns_cmd_reservation_acquire(struct spdk_nvme_ns *ns,
4051 : struct spdk_nvme_qpair *qpair,
4052 : struct spdk_nvme_reservation_acquire_data *payload,
4053 : bool ignore_key,
4054 : enum spdk_nvme_reservation_acquire_action action,
4055 : enum spdk_nvme_reservation_type type,
4056 : spdk_nvme_cmd_cb cb_fn, void *cb_arg);
4057 :
4058 : /**
4059 : * Submit a reservation report to the specified NVMe namespace.
4060 : *
4061 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
4062 : * The user must ensure that only one thread submits I/O on a given qpair at any
4063 : * given time.
4064 : *
4065 : * \param ns NVMe namespace to submit the reservation report request.
4066 : * \param qpair I/O queue pair to submit the request.
4067 : * \param payload Virtual address pointer for reservation status data.
4068 : * \param len Length bytes for reservation status data structure.
4069 : * \param cb_fn Callback function to invoke when the I/O is completed.
4070 : * \param cb_arg Argument to pass to the callback function.
4071 : *
4072 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
4073 : * -ENOMEM: The request cannot be allocated.
4074 : * -ENXIO: The qpair is failed at the transport level.
4075 : */
4076 : int spdk_nvme_ns_cmd_reservation_report(struct spdk_nvme_ns *ns,
4077 : struct spdk_nvme_qpair *qpair,
4078 : void *payload, uint32_t len,
4079 : spdk_nvme_cmd_cb cb_fn, void *cb_arg);
4080 :
4081 : /**
4082 : * Submit an I/O management receive command to the specified NVMe namespace.
4083 : *
4084 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
4085 : * The user must ensure that only one thread submits I/O on a given qpair at any
4086 : * given time.
4087 : *
4088 : * \param ns NVMe namespace to submit the I/O mgmt receive request.
4089 : * \param qpair I/O queue pair to submit the request.
4090 : * \param payload Virtual address pointer for I/O mgmt receive data.
4091 : * \param len Length bytes for I/O mgmt receive data structure.
4092 : * \param mo Management operation to perform.
4093 : * \param mos Management operation specific field for the mo.
4094 : * \param cb_fn Callback function to invoke when the I/O is completed.
4095 : * \param cb_arg Argument to pass to the callback function.
4096 : *
4097 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
4098 : * -ENOMEM: The request cannot be allocated.
4099 : * -ENXIO: The qpair is failed at the transport level.
4100 : */
4101 : int spdk_nvme_ns_cmd_io_mgmt_recv(struct spdk_nvme_ns *ns,
4102 : struct spdk_nvme_qpair *qpair, void *payload,
4103 : uint32_t len, uint8_t mo, uint16_t mos,
4104 : spdk_nvme_cmd_cb cb_fn, void *cb_arg);
4105 :
4106 : /**
4107 : * Submit an I/O management send command to the specified NVMe namespace.
4108 : *
4109 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
4110 : * The user must ensure that only one thread submits I/O on a given qpair at any
4111 : * given time.
4112 : *
4113 : * \param ns NVMe namespace to submit the I/O mgmt send request.
4114 : * \param qpair I/O queue pair to submit the request.
4115 : * \param payload Virtual address pointer for I/O mgmt send data.
4116 : * \param len Length bytes for I/O mgmt send data structure.
4117 : * \param mo Management operation to perform.
4118 : * \param mos Management operation specific field for the mo.
4119 : * \param cb_fn Callback function to invoke when the I/O is completed.
4120 : * \param cb_arg Argument to pass to the callback function.
4121 : *
4122 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
4123 : * -ENOMEM: The request cannot be allocated.
4124 : * -ENXIO: The qpair is failed at the transport level.
4125 : */
4126 : int spdk_nvme_ns_cmd_io_mgmt_send(struct spdk_nvme_ns *ns,
4127 : struct spdk_nvme_qpair *qpair, void *payload,
4128 : uint32_t len, uint8_t mo, uint16_t mos,
4129 : spdk_nvme_cmd_cb cb_fn, void *cb_arg);
4130 :
4131 : /**
4132 : * Submit a compare I/O to the specified NVMe namespace.
4133 : *
4134 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
4135 : * The user must ensure that only one thread submits I/O on a given qpair at any
4136 : * given time.
4137 : *
4138 : * \param ns NVMe namespace to submit the compare I/O.
4139 : * \param qpair I/O queue pair to submit the request.
4140 : * \param payload Virtual address pointer to the data payload.
4141 : * \param lba Starting LBA to compare the data.
4142 : * \param lba_count Length (in sectors) for the compare operation.
4143 : * \param cb_fn Callback function to invoke when the I/O is completed.
4144 : * \param cb_arg Argument to pass to the callback function.
4145 : * \param io_flags Set flags, defined in nvme_spec.h, for this I/O.
4146 : *
4147 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
4148 : * -EINVAL: The request is malformed.
4149 : * -ENOMEM: The request cannot be allocated.
4150 : * -ENXIO: The qpair is failed at the transport level.
4151 : */
4152 : int spdk_nvme_ns_cmd_compare(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair, void *payload,
4153 : uint64_t lba, uint32_t lba_count, spdk_nvme_cmd_cb cb_fn,
4154 : void *cb_arg, uint32_t io_flags);
4155 :
4156 : /**
4157 : * Submit a compare I/O to the specified NVMe namespace.
4158 : *
4159 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
4160 : * The user must ensure that only one thread submits I/O on a given qpair at any
4161 : * given time.
4162 : *
4163 : * \param ns NVMe namespace to submit the compare I/O.
4164 : * \param qpair I/O queue pair to submit the request.
4165 : * \param lba Starting LBA to compare the data.
4166 : * \param lba_count Length (in sectors) for the compare operation.
4167 : * \param cb_fn Callback function to invoke when the I/O is completed.
4168 : * \param cb_arg Argument to pass to the callback function.
4169 : * \param io_flags Set flags, defined in nvme_spec.h, for this I/O.
4170 : * \param reset_sgl_fn Callback function to reset scattered payload.
4171 : * \param next_sge_fn Callback function to iterate each scattered payload memory
4172 : * segment.
4173 : *
4174 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
4175 : * -EINVAL: The request is malformed.
4176 : * -ENOMEM: The request cannot be allocated.
4177 : * -ENXIO: The qpair is failed at the transport level.
4178 : */
4179 : int spdk_nvme_ns_cmd_comparev(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
4180 : uint64_t lba, uint32_t lba_count,
4181 : spdk_nvme_cmd_cb cb_fn, void *cb_arg, uint32_t io_flags,
4182 : spdk_nvme_req_reset_sgl_cb reset_sgl_fn,
4183 : spdk_nvme_req_next_sge_cb next_sge_fn);
4184 :
4185 : /**
4186 : * Submit a compare I/O to the specified NVMe namespace.
4187 : *
4188 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
4189 : * The user must ensure that only one thread submits I/O on a given qpair at any
4190 : * given time.
4191 : *
4192 : * \param ns NVMe namespace to submit the compare I/O.
4193 : * \param qpair I/O queue pair to submit the request.
4194 : * \param lba Starting LBA to compare the data.
4195 : * \param lba_count Length (in sectors) for the compare operation.
4196 : * \param cb_fn Callback function to invoke when the I/O is completed.
4197 : * \param cb_arg Argument to pass to the callback function.
4198 : * \param io_flags Set flags, defined in nvme_spec.h, for this I/O.
4199 : * \param reset_sgl_fn Callback function to reset scattered payload.
4200 : * \param next_sge_fn Callback function to iterate each scattered payload memory
4201 : * segment.
4202 : * \param metadata Virtual address pointer to the metadata payload, the length
4203 : * of metadata is specified by spdk_nvme_ns_get_md_size()
4204 : * \param apptag_mask Application tag mask.
4205 : * \param apptag Application tag to use end-to-end protection information.
4206 : *
4207 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
4208 : * -EINVAL: The request is malformed.
4209 : * -ENOMEM: The request cannot be allocated.
4210 : * -ENXIO: The qpair is failed at the transport level.
4211 : */
4212 : int
4213 : spdk_nvme_ns_cmd_comparev_with_md(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
4214 : uint64_t lba, uint32_t lba_count,
4215 : spdk_nvme_cmd_cb cb_fn, void *cb_arg, uint32_t io_flags,
4216 : spdk_nvme_req_reset_sgl_cb reset_sgl_fn,
4217 : spdk_nvme_req_next_sge_cb next_sge_fn, void *metadata,
4218 : uint16_t apptag_mask, uint16_t apptag);
4219 :
4220 : /**
4221 : * Submit a compare I/O to the specified NVMe namespace.
4222 : *
4223 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
4224 : * The user must ensure that only one thread submits I/O on a given qpair at any
4225 : * given time.
4226 : *
4227 : * \param ns NVMe namespace to submit the compare I/O.
4228 : * \param qpair I/O queue pair to submit the request.
4229 : * \param payload Virtual address pointer to the data payload.
4230 : * \param metadata Virtual address pointer to the metadata payload, the length
4231 : * of metadata is specified by spdk_nvme_ns_get_md_size().
4232 : * \param lba Starting LBA to compare the data.
4233 : * \param lba_count Length (in sectors) for the compare operation.
4234 : * \param cb_fn Callback function to invoke when the I/O is completed.
4235 : * \param cb_arg Argument to pass to the callback function.
4236 : * \param io_flags Set flags, defined in nvme_spec.h, for this I/O.
4237 : * \param apptag_mask Application tag mask.
4238 : * \param apptag Application tag to use end-to-end protection information.
4239 : *
4240 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
4241 : * -EINVAL: The request is malformed.
4242 : * -ENOMEM: The request cannot be allocated.
4243 : * -ENXIO: The qpair is failed at the transport level.
4244 : */
4245 : int spdk_nvme_ns_cmd_compare_with_md(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
4246 : void *payload, void *metadata,
4247 : uint64_t lba, uint32_t lba_count, spdk_nvme_cmd_cb cb_fn,
4248 : void *cb_arg, uint32_t io_flags,
4249 : uint16_t apptag_mask, uint16_t apptag);
4250 :
4251 : /**
4252 : * \brief Inject an error for the next request with a given opcode.
4253 : *
4254 : * \param ctrlr NVMe controller.
4255 : * \param qpair I/O queue pair to add the error command,
4256 : * NULL for Admin queue pair.
4257 : * \param opc Opcode for Admin or I/O commands.
4258 : * \param do_not_submit True if matching requests should not be submitted
4259 : * to the controller, but instead completed manually
4260 : * after timeout_in_us has expired. False if matching
4261 : * requests should be submitted to the controller and
4262 : * have their completion status modified after the
4263 : * controller completes the request.
4264 : * \param timeout_in_us Wait specified microseconds when do_not_submit is true.
4265 : * \param err_count Number of matching requests to inject errors.
4266 : * \param sct Status code type.
4267 : * \param sc Status code.
4268 : *
4269 : * \return 0 if successfully enabled, ENOMEM if an error command
4270 : * structure cannot be allocated.
4271 : *
4272 : * The function can be called multiple times to inject errors for different
4273 : * commands. If the opcode matches an existing entry, the existing entry
4274 : * will be updated with the values specified.
4275 : */
4276 : int spdk_nvme_qpair_add_cmd_error_injection(struct spdk_nvme_ctrlr *ctrlr,
4277 : struct spdk_nvme_qpair *qpair,
4278 : uint8_t opc,
4279 : bool do_not_submit,
4280 : uint64_t timeout_in_us,
4281 : uint32_t err_count,
4282 : uint8_t sct, uint8_t sc);
4283 :
4284 : /**
4285 : * \brief Clear the specified NVMe command with error status.
4286 : *
4287 : * \param ctrlr NVMe controller.
4288 : * \param qpair I/O queue pair to remove the error command,
4289 : * \ NULL for Admin queue pair.
4290 : * \param opc Opcode for Admin or I/O commands.
4291 : *
4292 : * The function will remove specified command in the error list.
4293 : */
4294 : void spdk_nvme_qpair_remove_cmd_error_injection(struct spdk_nvme_ctrlr *ctrlr,
4295 : struct spdk_nvme_qpair *qpair,
4296 : uint8_t opc);
4297 :
4298 : /**
4299 : * \brief Given NVMe status, return ASCII string for that error.
4300 : *
4301 : * \param status Status from NVMe completion queue element.
4302 : * \return Returns status as an ASCII string.
4303 : */
4304 : const char *spdk_nvme_cpl_get_status_string(const struct spdk_nvme_status *status);
4305 :
4306 : /**
4307 : * \brief Given NVMe status, return ASCII string for the type of that error.
4308 : *
4309 : * \param status Status from NVMe completion queue element.
4310 : * \return Returns status type as an ASCII string.
4311 : */
4312 : const char *spdk_nvme_cpl_get_status_type_string(const struct spdk_nvme_status *status);
4313 :
4314 : /**
4315 : * \brief Prints (SPDK_NOTICELOG) the contents of an NVMe submission queue entry (command).
4316 : *
4317 : * \param qpair Pointer to the NVMe queue pair - used to determine admin versus I/O queue.
4318 : * \param cmd Pointer to the submission queue command to be formatted.
4319 : */
4320 : void spdk_nvme_qpair_print_command(struct spdk_nvme_qpair *qpair,
4321 : struct spdk_nvme_cmd *cmd);
4322 :
4323 : /**
4324 : * \brief Prints (SPDK_NOTICELOG) the contents of an NVMe completion queue entry.
4325 : *
4326 : * \param qpair Pointer to the NVMe queue pair - presently unused.
4327 : * \param cpl Pointer to the completion queue element to be formatted.
4328 : */
4329 : void spdk_nvme_qpair_print_completion(struct spdk_nvme_qpair *qpair,
4330 : struct spdk_nvme_cpl *cpl);
4331 :
4332 : /**
4333 : * \brief Gets the NVMe qpair ID for the specified qpair.
4334 : *
4335 : * \param qpair Pointer to the NVMe queue pair.
4336 : * \returns ID for the specified qpair.
4337 : */
4338 : uint16_t spdk_nvme_qpair_get_id(struct spdk_nvme_qpair *qpair);
4339 :
4340 : /**
4341 : * Gets the number of outstanding requests for the specified qpair.
4342 : *
4343 : * This number is not decremented until after a request's callback function is completed.
4344 : *
4345 : * This number is not matched necessarily to the number of NVMe commands submitted by the
4346 : * user. For example, nvme driver may split a request due to MDTS limitations, that will
4347 : * also allocate a request for the parent, etc.
4348 : *
4349 : * \param qpair Pointer to the NVMe queue pair.
4350 : * \returns number of outstanding requests for the specified qpair.
4351 : */
4352 : uint32_t spdk_nvme_qpair_get_num_outstanding_reqs(struct spdk_nvme_qpair *qpair);
4353 :
4354 : /**
4355 : * \brief Prints (SPDK_NOTICELOG) the contents of an NVMe submission queue entry (command).
4356 : *
4357 : * \param qid Queue identifier.
4358 : * \param cmd Pointer to the submission queue command to be formatted.
4359 : */
4360 : void spdk_nvme_print_command(uint16_t qid, struct spdk_nvme_cmd *cmd);
4361 :
4362 : /**
4363 : * \brief Prints (SPDK_NOTICELOG) the contents of an NVMe completion queue entry.
4364 : *
4365 : * \param qid Queue identifier.
4366 : * \param cpl Pointer to the completion queue element to be formatted.
4367 : */
4368 : void spdk_nvme_print_completion(uint16_t qid, struct spdk_nvme_cpl *cpl);
4369 :
4370 : /**
4371 : * Return the name of a digest.
4372 : *
4373 : * \param id Digest identifier (see `enum spdk_nvmf_dhchap_hash`).
4374 : *
4375 : * \return Name of the digest.
4376 : */
4377 : const char *spdk_nvme_dhchap_get_digest_name(int id);
4378 :
4379 : /**
4380 : * Return the id of a digest.
4381 : *
4382 : * \param name Name of a digest.
4383 : *
4384 : * \return Digest id (see `enum spdk_nvmf_dhchap_hash`) or negative errno on failure.
4385 : */
4386 : int spdk_nvme_dhchap_get_digest_id(const char *name);
4387 :
4388 : /**
4389 : * Return the length of a digest.
4390 : *
4391 : * \param id Digest identifier (see `enum spdk_nvmf_dhchap_hash`).
4392 : *
4393 : * \return Length of a digest or 0 if the id is unknown.
4394 : */
4395 : uint8_t spdk_nvme_dhchap_get_digest_length(int id);
4396 :
4397 : /**
4398 : * Return the name of a Diffie-Hellman group.
4399 : *
4400 : * \param id Diffie-Hellman group identifier (see `enum spdk_nvmf_dhchap_dhgroup`).
4401 : *
4402 : * \return Name of the Diffie-Hellman group.
4403 : */
4404 : const char *spdk_nvme_dhchap_get_dhgroup_name(int id);
4405 :
4406 : /**
4407 : * Return the id of a Diffie-Hellman group.
4408 : *
4409 : * \param name Name of a Diffie-Hellman group.
4410 : *
4411 : * \return Diffie-Hellman group id (see `enum spdk_nvmf_dhchap_dhgroup`) or negative errno
4412 : * on failure.
4413 : */
4414 : int spdk_nvme_dhchap_get_dhgroup_id(const char *name);
4415 :
4416 : struct ibv_context;
4417 : struct ibv_pd;
4418 : struct ibv_mr;
4419 :
4420 : /**
4421 : * RDMA Transport Hooks
4422 : */
4423 : struct spdk_nvme_rdma_hooks {
4424 : /**
4425 : * \brief Get an InfiniBand Verbs protection domain.
4426 : *
4427 : * \param trid the transport id
4428 : * \param verbs Infiniband verbs context
4429 : *
4430 : * \return pd of the nvme ctrlr
4431 : */
4432 : struct ibv_pd *(*get_ibv_pd)(const struct spdk_nvme_transport_id *trid,
4433 : struct ibv_context *verbs);
4434 :
4435 : /**
4436 : * \brief Get an InfiniBand Verbs memory region for a buffer.
4437 : *
4438 : * \param pd The protection domain returned from get_ibv_pd
4439 : * \param buf Memory buffer for which an rkey should be returned.
4440 : * \param size size of buf
4441 : *
4442 : * \return Infiniband remote key (rkey) for this buf
4443 : */
4444 : uint64_t (*get_rkey)(struct ibv_pd *pd, void *buf, size_t size);
4445 :
4446 : /**
4447 : * \brief Put back keys got from get_rkey.
4448 : *
4449 : * \param key The Infiniband remote key (rkey) got from get_rkey
4450 : *
4451 : */
4452 : void (*put_rkey)(uint64_t key);
4453 : };
4454 :
4455 : /**
4456 : * \brief Set the global hooks for the RDMA transport, if necessary.
4457 : *
4458 : * This call is optional and must be performed prior to probing for
4459 : * any devices. By default, the RDMA transport will use the ibverbs
4460 : * library to create protection domains and register memory. This
4461 : * is a mechanism to subvert that and use an existing registration.
4462 : *
4463 : * This function may only be called one time per process.
4464 : *
4465 : * \param hooks for initializing global hooks
4466 : */
4467 : void spdk_nvme_rdma_init_hooks(struct spdk_nvme_rdma_hooks *hooks);
4468 :
4469 : /**
4470 : * Get name of cuse device associated with NVMe controller.
4471 : *
4472 : * \param ctrlr Opaque handle to NVMe controller.
4473 : * \param name Buffer of be filled with cuse device name.
4474 : * \param size Size of name buffer.
4475 : *
4476 : * \return 0 on success. Negated errno on the following error conditions:
4477 : * -ENODEV: No cuse device registered for the controller.
4478 : * -ENSPC: Too small buffer size passed. Value of size pointer changed to the required length.
4479 : */
4480 : int spdk_nvme_cuse_get_ctrlr_name(struct spdk_nvme_ctrlr *ctrlr, char *name, size_t *size);
4481 :
4482 : /**
4483 : * Get name of cuse device associated with NVMe namespace.
4484 : *
4485 : * \param ctrlr Opaque handle to NVMe controller.
4486 : * \param nsid Namespace id.
4487 : * \param name Buffer of be filled with cuse device name.
4488 : * \param size Size of name buffer.
4489 : *
4490 : * \return 0 on success. Negated errno on the following error conditions:
4491 : * -ENODEV: No cuse device registered for the namespace.
4492 : * -ENSPC: Too small buffer size passed. Value of size pointer changed to the required length.
4493 : */
4494 : int spdk_nvme_cuse_get_ns_name(struct spdk_nvme_ctrlr *ctrlr, uint32_t nsid,
4495 : char *name, size_t *size);
4496 :
4497 : /**
4498 : * Create a character device at the path specified
4499 : *
4500 : * The character device can handle ioctls and is compatible with a standard
4501 : * Linux kernel NVMe device. Tools such as nvme-cli can be used to configure
4502 : * SPDK devices through this interface.
4503 : *
4504 : * The user is expected to be polling the admin qpair for this controller periodically
4505 : * for the CUSE device to function.
4506 : *
4507 : * \param ctrlr Opaque handle to the NVMe controller.
4508 : *
4509 : * \return 0 on success. Negated errno on failure.
4510 : */
4511 : int spdk_nvme_cuse_register(struct spdk_nvme_ctrlr *ctrlr);
4512 :
4513 : /**
4514 : * Remove a previously created character device
4515 : *
4516 : * \param ctrlr Opaque handle to the NVMe controller.
4517 : *
4518 : * \return 0 on success. Negated errno on failure.
4519 : */
4520 : int spdk_nvme_cuse_unregister(struct spdk_nvme_ctrlr *ctrlr);
4521 :
4522 : /**
4523 : * Get SPDK memory domains used by the given nvme controller.
4524 : *
4525 : * The user can call this function with \b domains set to NULL and \b array_size set to 0 to get the
4526 : * number of memory domains used by nvme controller
4527 : *
4528 : * \param ctrlr Opaque handle to the NVMe controller.
4529 : * \param domains Pointer to an array of memory domains to be filled by this function. The user should allocate big enough
4530 : * array to keep all memory domains used by nvme controller
4531 : * \param array_size size of \b domains array
4532 : * \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
4533 : * then the user should increase the size of \b domains array and call this function again. There is no guarantees that
4534 : * the content of \b domains array is valid in that case.
4535 : * -EINVAL if input parameters were invalid
4536 :
4537 : */
4538 : int spdk_nvme_ctrlr_get_memory_domains(const struct spdk_nvme_ctrlr *ctrlr,
4539 : struct spdk_memory_domain **domains, int array_size);
4540 :
4541 : /**
4542 : * Opaque handle for a transport poll group. Used by the transport function table.
4543 : */
4544 : struct spdk_nvme_transport_poll_group;
4545 :
4546 : /**
4547 : * Update and populate namespace CUSE devices (Experimental)
4548 : *
4549 : * \param ctrlr Opaque handle to the NVMe controller.
4550 : *
4551 : */
4552 : void spdk_nvme_cuse_update_namespaces(struct spdk_nvme_ctrlr *ctrlr);
4553 :
4554 : /**
4555 : * Signature for callback invoked after completing a register read/write operation.
4556 : *
4557 : * \param ctx Context passed by the user.
4558 : * \param value Value of the register, undefined in case of a failure.
4559 : * \param cpl Completion queue entry that contains the status of the command.
4560 : */
4561 : typedef void (*spdk_nvme_reg_cb)(void *ctx, uint64_t value, const struct spdk_nvme_cpl *cpl);
4562 :
4563 : struct nvme_request;
4564 :
4565 : struct spdk_nvme_transport;
4566 :
4567 : struct spdk_nvme_transport_ops {
4568 : char name[SPDK_NVMF_TRSTRING_MAX_LEN + 1];
4569 :
4570 : enum spdk_nvme_transport_type type;
4571 :
4572 : struct spdk_nvme_ctrlr *(*ctrlr_construct)(const struct spdk_nvme_transport_id *trid,
4573 : const struct spdk_nvme_ctrlr_opts *opts,
4574 : void *devhandle);
4575 :
4576 : int (*ctrlr_scan)(struct spdk_nvme_probe_ctx *probe_ctx, bool direct_connect);
4577 :
4578 : int (*ctrlr_destruct)(struct spdk_nvme_ctrlr *ctrlr);
4579 :
4580 : int (*ctrlr_enable)(struct spdk_nvme_ctrlr *ctrlr);
4581 :
4582 : int (*ctrlr_enable_interrupts)(struct spdk_nvme_ctrlr *ctrlr);
4583 :
4584 : int (*ctrlr_set_reg_4)(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint32_t value);
4585 :
4586 : int (*ctrlr_set_reg_8)(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint64_t value);
4587 :
4588 : int (*ctrlr_get_reg_4)(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint32_t *value);
4589 :
4590 : int (*ctrlr_get_reg_8)(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint64_t *value);
4591 :
4592 : int (*ctrlr_set_reg_4_async)(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint32_t value,
4593 : spdk_nvme_reg_cb cb_fn, void *cb_arg);
4594 :
4595 : int (*ctrlr_set_reg_8_async)(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint64_t value,
4596 : spdk_nvme_reg_cb cb_fn, void *cb_arg);
4597 :
4598 : int (*ctrlr_get_reg_4_async)(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset,
4599 : spdk_nvme_reg_cb cb_fn, void *cb_arg);
4600 :
4601 : int (*ctrlr_get_reg_8_async)(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset,
4602 : spdk_nvme_reg_cb cb_fn, void *cb_arg);
4603 :
4604 : uint32_t (*ctrlr_get_max_xfer_size)(struct spdk_nvme_ctrlr *ctrlr);
4605 :
4606 : uint16_t (*ctrlr_get_max_sges)(struct spdk_nvme_ctrlr *ctrlr);
4607 :
4608 : int (*ctrlr_reserve_cmb)(struct spdk_nvme_ctrlr *ctrlr);
4609 :
4610 : void *(*ctrlr_map_cmb)(struct spdk_nvme_ctrlr *ctrlr, size_t *size);
4611 :
4612 : int (*ctrlr_unmap_cmb)(struct spdk_nvme_ctrlr *ctrlr);
4613 :
4614 : int (*ctrlr_enable_pmr)(struct spdk_nvme_ctrlr *ctrlr);
4615 :
4616 : int (*ctrlr_disable_pmr)(struct spdk_nvme_ctrlr *ctrlr);
4617 :
4618 : void *(*ctrlr_map_pmr)(struct spdk_nvme_ctrlr *ctrlr, size_t *size);
4619 :
4620 : int (*ctrlr_unmap_pmr)(struct spdk_nvme_ctrlr *ctrlr);
4621 :
4622 : struct spdk_nvme_qpair *(*ctrlr_create_io_qpair)(struct spdk_nvme_ctrlr *ctrlr, uint16_t qid,
4623 : const struct spdk_nvme_io_qpair_opts *opts);
4624 :
4625 : int (*ctrlr_delete_io_qpair)(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qpair);
4626 :
4627 : int (*ctrlr_connect_qpair)(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qpair);
4628 :
4629 : void (*ctrlr_disconnect_qpair)(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qpair);
4630 :
4631 : void (*qpair_abort_reqs)(struct spdk_nvme_qpair *qpair, uint32_t dnr);
4632 :
4633 : int (*qpair_reset)(struct spdk_nvme_qpair *qpair);
4634 :
4635 : int (*qpair_submit_request)(struct spdk_nvme_qpair *qpair, struct nvme_request *req);
4636 :
4637 : int (*qpair_authenticate)(struct spdk_nvme_qpair *qpair);
4638 :
4639 : int32_t (*qpair_process_completions)(struct spdk_nvme_qpair *qpair, uint32_t max_completions);
4640 :
4641 : int (*qpair_iterate_requests)(struct spdk_nvme_qpair *qpair,
4642 : int (*iter_fn)(struct nvme_request *req, void *arg),
4643 : void *arg);
4644 :
4645 : int (*qpair_get_fd)(struct spdk_nvme_qpair *qpair, struct spdk_event_handler_opts *opts);
4646 :
4647 : void (*admin_qpair_abort_aers)(struct spdk_nvme_qpair *qpair);
4648 :
4649 : struct spdk_nvme_transport_poll_group *(*poll_group_create)(void);
4650 : struct spdk_nvme_transport_poll_group *(*qpair_get_optimal_poll_group)(
4651 : struct spdk_nvme_qpair *qpair);
4652 :
4653 : int (*poll_group_add)(struct spdk_nvme_transport_poll_group *tgroup, struct spdk_nvme_qpair *qpair);
4654 :
4655 : int (*poll_group_remove)(struct spdk_nvme_transport_poll_group *tgroup,
4656 : struct spdk_nvme_qpair *qpair);
4657 :
4658 : int (*poll_group_connect_qpair)(struct spdk_nvme_qpair *qpair);
4659 :
4660 : int (*poll_group_disconnect_qpair)(struct spdk_nvme_qpair *qpair);
4661 :
4662 : int64_t (*poll_group_process_completions)(struct spdk_nvme_transport_poll_group *tgroup,
4663 : uint32_t completions_per_qpair, spdk_nvme_disconnected_qpair_cb disconnected_qpair_cb);
4664 :
4665 : void (*poll_group_check_disconnected_qpairs)(struct spdk_nvme_transport_poll_group *tgroup,
4666 : spdk_nvme_disconnected_qpair_cb disconnected_qpair_cb);
4667 :
4668 : int (*poll_group_destroy)(struct spdk_nvme_transport_poll_group *tgroup);
4669 :
4670 : int (*poll_group_get_stats)(struct spdk_nvme_transport_poll_group *tgroup,
4671 : struct spdk_nvme_transport_poll_group_stat **stats);
4672 :
4673 : void (*poll_group_free_stats)(struct spdk_nvme_transport_poll_group *tgroup,
4674 : struct spdk_nvme_transport_poll_group_stat *stats);
4675 :
4676 : int (*ctrlr_get_memory_domains)(const struct spdk_nvme_ctrlr *ctrlr,
4677 : struct spdk_memory_domain **domains,
4678 : int array_size);
4679 :
4680 : int (*ctrlr_ready)(struct spdk_nvme_ctrlr *ctrlr);
4681 :
4682 : volatile struct spdk_nvme_registers *(*ctrlr_get_registers)(struct spdk_nvme_ctrlr *ctrlr);
4683 :
4684 : /* Optional callback for transports to process removal events of attached controllers. */
4685 : int (*ctrlr_scan_attached)(struct spdk_nvme_probe_ctx *probe_ctx);
4686 : };
4687 :
4688 : /**
4689 : * Register the operations for a given transport type.
4690 : *
4691 : * This function should be invoked by referencing the macro
4692 : * SPDK_NVME_TRANSPORT_REGISTER macro in the transport's .c file.
4693 : *
4694 : * \param ops The operations associated with an NVMe-oF transport.
4695 : */
4696 : void spdk_nvme_transport_register(const struct spdk_nvme_transport_ops *ops);
4697 :
4698 : /*
4699 : * Macro used to register new transports.
4700 : */
4701 : #define SPDK_NVME_TRANSPORT_REGISTER(name, transport_ops) \
4702 : static void __attribute__((constructor)) _spdk_nvme_transport_register_##name(void) \
4703 : { \
4704 : spdk_nvme_transport_register(transport_ops); \
4705 : }
4706 :
4707 : /**
4708 : * NVMe transport options.
4709 : */
4710 : struct spdk_nvme_transport_opts {
4711 : /**
4712 : * It is used for RDMA transport.
4713 : *
4714 : * The queue depth of a shared rdma receive queue.
4715 : */
4716 : uint32_t rdma_srq_size;
4717 :
4718 : /* Hole at bytes 4-7. */
4719 : uint8_t reserved4[4];
4720 :
4721 : /**
4722 : * The size of spdk_nvme_transport_opts according to the caller of this library is used for ABI
4723 : * compatibility. The library uses this field to know how many fields in this
4724 : * structure are valid. And the library will populate any remaining fields with default values.
4725 : */
4726 : size_t opts_size;
4727 :
4728 : /**
4729 : * It is used for RDMA transport.
4730 : *
4731 : * The maximum queue depth of a rdma completion queue.
4732 : * It is zero, which means unlimited, by default.
4733 : */
4734 : uint32_t rdma_max_cq_size;
4735 :
4736 : /**
4737 : * It is used for RDMA transport.
4738 : *
4739 : * RDMA CM event timeout in milliseconds.
4740 : */
4741 : uint16_t rdma_cm_event_timeout_ms;
4742 : };
4743 : SPDK_STATIC_ASSERT(sizeof(struct spdk_nvme_transport_opts) == 24, "Incorrect size");
4744 :
4745 : /**
4746 : * Get the current NVMe transport options.
4747 : *
4748 : * \param[out] opts Will be filled with the current options for spdk_nvme_transport_set_opts().
4749 : * \param opts_size Must be set to sizeof(struct spdk_nvme_transport_opts).
4750 : */
4751 : void spdk_nvme_transport_get_opts(struct spdk_nvme_transport_opts *opts, size_t opts_size);
4752 :
4753 : /**
4754 : * Set the NVMe transport options.
4755 : *
4756 : * \param opts Pointer to the allocated spdk_nvme_transport_opts structure with new values.
4757 : * \param opts_size Must be set to sizeof(struct spdk_nvme_transport_opts).
4758 : *
4759 : * \return 0 on success, or negated errno on failure.
4760 : */
4761 : int spdk_nvme_transport_set_opts(const struct spdk_nvme_transport_opts *opts, size_t opts_size);
4762 :
4763 : #ifdef __cplusplus
4764 : }
4765 : #endif
4766 :
4767 : #endif
|