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