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 : * Update the transport ID for a given controller.
1105 : *
1106 : * This function allows the user to set a new trid for a controller only if the
1107 : * controller is failed. The controller's failed state can be obtained from
1108 : * spdk_nvme_ctrlr_is_failed(). The controller can also be forced to the failed
1109 : * state using spdk_nvme_ctrlr_fail().
1110 : *
1111 : * This function also requires that the transport type and subnqn of the new trid
1112 : * be the same as the old trid.
1113 : *
1114 : * \param ctrlr Opaque handle to an NVMe controller.
1115 : * \param trid The new transport ID.
1116 : *
1117 : * \return 0 on success, -EINVAL if the trid is invalid,
1118 : * -EPERM if the ctrlr is not failed.
1119 : */
1120 : int spdk_nvme_ctrlr_set_trid(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_transport_id *trid);
1121 :
1122 : /**
1123 : * Set the remove callback and context to be invoked if the controller is removed.
1124 : *
1125 : * This will override any remove_cb and/or ctx specified when the controller was
1126 : * probed.
1127 : *
1128 : * This function may only be called from the primary process. This function has
1129 : * no effect if called from a secondary process.
1130 : *
1131 : * \param ctrlr Opaque handle to an NVMe controller.
1132 : * \param remove_cb remove callback
1133 : * \param remove_ctx remove callback context
1134 : */
1135 : void spdk_nvme_ctrlr_set_remove_cb(struct spdk_nvme_ctrlr *ctrlr,
1136 : spdk_nvme_remove_cb remove_cb, void *remove_ctx);
1137 :
1138 : /**
1139 : * Perform a full hardware reset of the NVMe controller.
1140 : *
1141 : * This function should be called from a single thread while no other threads
1142 : * are actively using the NVMe device.
1143 : *
1144 : * Any pointers returned from spdk_nvme_ctrlr_get_ns(), spdk_nvme_ns_get_data(),
1145 : * spdk_nvme_zns_ns_get_data(), and spdk_nvme_zns_ctrlr_get_data()
1146 : * may be invalidated by calling this function. The number of namespaces as returned
1147 : * by spdk_nvme_ctrlr_get_num_ns() may also change.
1148 : *
1149 : * \param ctrlr Opaque handle to NVMe controller.
1150 : *
1151 : * \return 0 on success, -1 on failure.
1152 : */
1153 : int spdk_nvme_ctrlr_reset(struct spdk_nvme_ctrlr *ctrlr);
1154 :
1155 : /**
1156 : * Disconnect the given NVMe controller.
1157 : *
1158 : * This function is used as the first operation of a full reset sequence of the given NVMe
1159 : * controller. The NVMe controller is ready to reconnect after completing this function.
1160 : *
1161 : * \param ctrlr Opaque handle to NVMe controller.
1162 : *
1163 : * \return 0 on success, -EBUSY if controller is already resetting, or -ENXIO if controller
1164 : * has been removed.
1165 : */
1166 : int spdk_nvme_ctrlr_disconnect(struct spdk_nvme_ctrlr *ctrlr);
1167 :
1168 : /**
1169 : * Start re-enabling the given NVMe controller in a full reset sequence
1170 : *
1171 : * \param ctrlr Opaque handle to NVMe controller.
1172 : */
1173 : void spdk_nvme_ctrlr_reconnect_async(struct spdk_nvme_ctrlr *ctrlr);
1174 :
1175 : /**
1176 : * Proceed with re-enabling the given NVMe controller.
1177 : *
1178 : * Users must call this function in a full reset sequence until it returns a value other
1179 : * than -EAGAIN.
1180 : *
1181 : * \return 0 if the given NVMe controller is enabled, or -EBUSY if there are still
1182 : * pending operations to enable it.
1183 : */
1184 : int spdk_nvme_ctrlr_reconnect_poll_async(struct spdk_nvme_ctrlr *ctrlr);
1185 :
1186 : /**
1187 : * Perform a NVMe subsystem reset.
1188 : *
1189 : * This function should be called from a single thread while no other threads
1190 : * are actively using the NVMe device.
1191 : * A subsystem reset is typically seen by the OS as a hot remove, followed by a
1192 : * hot add event.
1193 : *
1194 : * Any pointers returned from spdk_nvme_ctrlr_get_ns(), spdk_nvme_ns_get_data(),
1195 : * spdk_nvme_zns_ns_get_data(), and spdk_nvme_zns_ctrlr_get_data()
1196 : * may be invalidated by calling this function. The number of namespaces as returned
1197 : * by spdk_nvme_ctrlr_get_num_ns() may also change.
1198 : *
1199 : * \param ctrlr Opaque handle to NVMe controller.
1200 : *
1201 : * \return 0 on success, -1 on failure, -ENOTSUP if subsystem reset is not supported.
1202 : */
1203 : int spdk_nvme_ctrlr_reset_subsystem(struct spdk_nvme_ctrlr *ctrlr);
1204 :
1205 : /**
1206 : * Fail the given NVMe controller.
1207 : *
1208 : * This function gives the application the opportunity to fail a controller
1209 : * at will. When a controller is failed, any calls to process completions or
1210 : * submit I/O on qpairs associated with that controller will fail with an error
1211 : * code of -ENXIO.
1212 : * The controller can only be taken from the failed state by
1213 : * calling spdk_nvme_ctrlr_reset. After the controller has been successfully
1214 : * reset, any I/O pending when the controller was moved to failed will be
1215 : * aborted back to the application and can be resubmitted. I/O can then resume.
1216 : *
1217 : * \param ctrlr Opaque handle to an NVMe controller.
1218 : */
1219 : void spdk_nvme_ctrlr_fail(struct spdk_nvme_ctrlr *ctrlr);
1220 :
1221 : /**
1222 : * This function returns the failed status of a given controller.
1223 : *
1224 : * \param ctrlr Opaque handle to an NVMe controller.
1225 : *
1226 : * \return True if the controller is failed, false otherwise.
1227 : */
1228 : bool spdk_nvme_ctrlr_is_failed(struct spdk_nvme_ctrlr *ctrlr);
1229 :
1230 : /**
1231 : * Get the identify controller data as defined by the NVMe specification.
1232 : *
1233 : * This function is thread safe and can be called at any point while the controller
1234 : * is attached to the SPDK NVMe driver.
1235 : *
1236 : * \param ctrlr Opaque handle to NVMe controller.
1237 : *
1238 : * \return pointer to the identify controller data.
1239 : */
1240 : const struct spdk_nvme_ctrlr_data *spdk_nvme_ctrlr_get_data(struct spdk_nvme_ctrlr *ctrlr);
1241 :
1242 : /**
1243 : * Get the NVMe controller CSTS (Status) register.
1244 : *
1245 : * \param ctrlr Opaque handle to NVMe controller.
1246 : *
1247 : * \return the NVMe controller CSTS (Status) register.
1248 : */
1249 : union spdk_nvme_csts_register spdk_nvme_ctrlr_get_regs_csts(struct spdk_nvme_ctrlr *ctrlr);
1250 :
1251 : /**
1252 : * Get the NVMe controller CC (Configuration) register.
1253 : *
1254 : * \param ctrlr Opaque handle to NVMe controller.
1255 : *
1256 : * \return the NVMe controller CC (Configuration) register.
1257 : */
1258 : union spdk_nvme_cc_register spdk_nvme_ctrlr_get_regs_cc(struct spdk_nvme_ctrlr *ctrlr);
1259 :
1260 : /**
1261 : * Get the NVMe controller CAP (Capabilities) register.
1262 : *
1263 : * \param ctrlr Opaque handle to NVMe controller.
1264 : *
1265 : * \return the NVMe controller CAP (Capabilities) register.
1266 : */
1267 : union spdk_nvme_cap_register spdk_nvme_ctrlr_get_regs_cap(struct spdk_nvme_ctrlr *ctrlr);
1268 :
1269 : /**
1270 : * Get the NVMe controller VS (Version) register.
1271 : *
1272 : * \param ctrlr Opaque handle to NVMe controller.
1273 : *
1274 : * \return the NVMe controller VS (Version) register.
1275 : */
1276 : union spdk_nvme_vs_register spdk_nvme_ctrlr_get_regs_vs(struct spdk_nvme_ctrlr *ctrlr);
1277 :
1278 : /**
1279 : * Get the NVMe controller CMBSZ (Controller Memory Buffer Size) register
1280 : *
1281 : * \param ctrlr Opaque handle to NVMe controller.
1282 : *
1283 : * \return the NVMe controller CMBSZ (Controller Memory Buffer Size) register.
1284 : */
1285 : union spdk_nvme_cmbsz_register spdk_nvme_ctrlr_get_regs_cmbsz(struct spdk_nvme_ctrlr *ctrlr);
1286 :
1287 : /**
1288 : * Get the NVMe controller PMRCAP (Persistent Memory Region Capabilities) register.
1289 : *
1290 : * \param ctrlr Opaque handle to NVMe controller.
1291 : *
1292 : * \return the NVMe controller PMRCAP (Persistent Memory Region Capabilities) register.
1293 : */
1294 : union spdk_nvme_pmrcap_register spdk_nvme_ctrlr_get_regs_pmrcap(struct spdk_nvme_ctrlr *ctrlr);
1295 :
1296 : /**
1297 : * Get the NVMe controller BPINFO (Boot Partition Information) register.
1298 : *
1299 : * \param ctrlr Opaque handle to NVMe controller.
1300 : *
1301 : * \return the NVMe controller BPINFO (Boot Partition Information) register.
1302 : */
1303 : union spdk_nvme_bpinfo_register spdk_nvme_ctrlr_get_regs_bpinfo(struct spdk_nvme_ctrlr *ctrlr);
1304 :
1305 : /**
1306 : * Get the NVMe controller PMR size.
1307 : *
1308 : * \param ctrlr Opaque handle to NVMe controller.
1309 : *
1310 : * \return the NVMe controller PMR size or 0 if PMR is not supported.
1311 : */
1312 : uint64_t spdk_nvme_ctrlr_get_pmrsz(struct spdk_nvme_ctrlr *ctrlr);
1313 :
1314 : /**
1315 : * Get the maximum NSID value that will ever be used for the given controller
1316 : *
1317 : * This function is thread safe and can be called at any point while the
1318 : * controller is attached to the SPDK NVMe driver.
1319 : *
1320 : * This is equivalent to calling spdk_nvme_ctrlr_get_data() to get the
1321 : * spdk_nvme_ctrlr_data and then reading the nn field.
1322 : *
1323 : * The NN field in the NVMe specification represents the maximum value that a
1324 : * namespace ID can ever have. Prior to NVMe 1.2, this was also the number of
1325 : * active namespaces, but from 1.2 onward the list of namespaces may be
1326 : * sparsely populated. Unfortunately, the meaning of this field is often
1327 : * misinterpreted by drive manufacturers and NVMe-oF implementers so it is
1328 : * not considered reliable. AVOID USING THIS FUNCTION WHENEVER POSSIBLE.
1329 : *
1330 : * \param ctrlr Opaque handle to NVMe controller.
1331 : *
1332 : * \return the number of namespaces.
1333 : */
1334 : uint32_t spdk_nvme_ctrlr_get_num_ns(struct spdk_nvme_ctrlr *ctrlr);
1335 :
1336 : /**
1337 : * Get the PCI device of a given NVMe controller.
1338 : *
1339 : * This only works for local (PCIe-attached) NVMe controllers; other transports
1340 : * will return NULL.
1341 : *
1342 : * \param ctrlr Opaque handle to NVMe controller.
1343 : *
1344 : * \return PCI device of the NVMe controller, or NULL if not available.
1345 : */
1346 : struct spdk_pci_device *spdk_nvme_ctrlr_get_pci_device(struct spdk_nvme_ctrlr *ctrlr);
1347 :
1348 : /**
1349 : * Get the NUMA socket ID for the given NVMe controller.
1350 : *
1351 : * For network-based transports, the NUMA socket ID will be correlated to the
1352 : * network interface.
1353 : *
1354 : * \param ctrlr Opaque handle to NVMe controller
1355 : *
1356 : * \return NUMA socket ID of the NVMe controller, or SPDK_ENV_SOCKET_ID_ANY if
1357 : * the socket ID is unknown
1358 : */
1359 : uint32_t spdk_nvme_ctrlr_get_socket_id(struct spdk_nvme_ctrlr *ctrlr);
1360 :
1361 : /**
1362 : * Get the maximum data transfer size of a given NVMe controller.
1363 : *
1364 : * \param ctrlr Opaque handle to NVMe controller.
1365 : *
1366 : * \return Maximum data transfer size of the NVMe controller in bytes.
1367 : *
1368 : * The I/O command helper functions, such as spdk_nvme_ns_cmd_read(), will split
1369 : * large I/Os automatically; however, it is up to the user to obey this limit for
1370 : * commands submitted with the raw command functions, such as spdk_nvme_ctrlr_cmd_io_raw().
1371 : */
1372 : uint32_t spdk_nvme_ctrlr_get_max_xfer_size(const struct spdk_nvme_ctrlr *ctrlr);
1373 :
1374 : /**
1375 : * Get the maximum number of SGEs per request for the given NVMe controller.
1376 : *
1377 : * Controllers that do not support SGL will return UINT16_MAX.
1378 : *
1379 : * \param ctrlr Opaque handle to NVMe controller.
1380 : *
1381 : * \return Maximum number of SGEs per request
1382 : */
1383 : uint16_t spdk_nvme_ctrlr_get_max_sges(const struct spdk_nvme_ctrlr *ctrlr);
1384 :
1385 : /**
1386 : * Check whether the nsid is an active nv for the given NVMe controller.
1387 : *
1388 : * This function is thread safe and can be called at any point while the controller
1389 : * is attached to the SPDK NVMe driver.
1390 : *
1391 : * \param ctrlr Opaque handle to NVMe controller.
1392 : * \param nsid Namespace id.
1393 : *
1394 : * \return true if nsid is an active ns, or false otherwise.
1395 : */
1396 : bool spdk_nvme_ctrlr_is_active_ns(struct spdk_nvme_ctrlr *ctrlr, uint32_t nsid);
1397 :
1398 : /**
1399 : * Get the nsid of the first active namespace.
1400 : *
1401 : * This function is thread safe and can be called at any point while the controller
1402 : * is attached to the SPDK NVMe driver.
1403 : *
1404 : * \param ctrlr Opaque handle to NVMe controller.
1405 : *
1406 : * \return the nsid of the first active namespace, 0 if there are no active namespaces.
1407 : */
1408 : uint32_t spdk_nvme_ctrlr_get_first_active_ns(struct spdk_nvme_ctrlr *ctrlr);
1409 :
1410 : /**
1411 : * Get next active namespace given the previous nsid.
1412 : *
1413 : * This function is thread safe and can be called at any point while the controller
1414 : * is attached to the SPDK NVMe driver.
1415 : *
1416 : * \param ctrlr Opaque handle to NVMe controller.
1417 : * \param prev_nsid Namespace id.
1418 : *
1419 : * \return a next active namespace given the previous nsid, 0 when there are no
1420 : * more active namespaces.
1421 : */
1422 : uint32_t spdk_nvme_ctrlr_get_next_active_ns(struct spdk_nvme_ctrlr *ctrlr, uint32_t prev_nsid);
1423 :
1424 : /**
1425 : * Determine if a particular log page is supported by the given NVMe controller.
1426 : *
1427 : * This function is thread safe and can be called at any point while the controller
1428 : * is attached to the SPDK NVMe driver.
1429 : *
1430 : * \sa spdk_nvme_ctrlr_cmd_get_log_page().
1431 : *
1432 : * \param ctrlr Opaque handle to NVMe controller.
1433 : * \param log_page Log page to query.
1434 : *
1435 : * \return true if supported, or false otherwise.
1436 : */
1437 : bool spdk_nvme_ctrlr_is_log_page_supported(struct spdk_nvme_ctrlr *ctrlr, uint8_t log_page);
1438 :
1439 : /**
1440 : * Determine if a particular feature is supported by the given NVMe controller.
1441 : *
1442 : * This function is thread safe and can be called at any point while the controller
1443 : * is attached to the SPDK NVMe driver.
1444 : *
1445 : * \sa spdk_nvme_ctrlr_cmd_get_feature().
1446 : *
1447 : * \param ctrlr Opaque handle to NVMe controller.
1448 : * \param feature_code Feature to query.
1449 : *
1450 : * \return true if supported, or false otherwise.
1451 : */
1452 : bool spdk_nvme_ctrlr_is_feature_supported(struct spdk_nvme_ctrlr *ctrlr, uint8_t feature_code);
1453 :
1454 : /**
1455 : * Signature for callback function invoked when a command is completed.
1456 : *
1457 : * \param ctx Callback context provided when the command was submitted.
1458 : * \param cpl Completion queue entry that contains the completion status.
1459 : */
1460 : typedef void (*spdk_nvme_cmd_cb)(void *ctx, const struct spdk_nvme_cpl *cpl);
1461 :
1462 : /**
1463 : * Signature for callback function invoked when an asynchronous event request
1464 : * command is completed.
1465 : *
1466 : * \param aer_cb_arg Context specified by spdk_nvme_register_aer_callback().
1467 : * \param cpl Completion queue entry that contains the completion status
1468 : * of the asynchronous event request that was completed.
1469 : */
1470 : typedef void (*spdk_nvme_aer_cb)(void *aer_cb_arg,
1471 : const struct spdk_nvme_cpl *cpl);
1472 :
1473 : /**
1474 : * Register callback function invoked when an AER command is completed for the
1475 : * given NVMe controller.
1476 : *
1477 : * \param ctrlr Opaque handle to NVMe controller.
1478 : * \param aer_cb_fn Callback function invoked when an asynchronous event request
1479 : * command is completed.
1480 : * \param aer_cb_arg Argument passed to callback function.
1481 : */
1482 : void spdk_nvme_ctrlr_register_aer_callback(struct spdk_nvme_ctrlr *ctrlr,
1483 : spdk_nvme_aer_cb aer_cb_fn,
1484 : void *aer_cb_arg);
1485 :
1486 : /**
1487 : * Disable reading the CHANGED_NS_LIST log page for the specified controller.
1488 : *
1489 : * Applications that register an AER callback may wish to read the CHANGED_NS_LIST
1490 : * log page itself, rather than relying on the driver to do it. Calling this
1491 : * function will ensure that the driver does not read this log page if the
1492 : * controller returns a NS_ATTR_CHANGED AEN.
1493 : *
1494 : * Reading of this log page can alternatively be disabled by setting the
1495 : * disable_read_changed_ns_list_log_page flag in the spdk_nvme_ctrlr_opts
1496 : * when attaching the controller.
1497 : *
1498 : * \param ctrlr NVMe controller on which to disable the log page read.
1499 : */
1500 : void spdk_nvme_ctrlr_disable_read_changed_ns_list_log_page(struct spdk_nvme_ctrlr *ctrlr);
1501 :
1502 : /**
1503 : * Opaque handle to a queue pair.
1504 : *
1505 : * I/O queue pairs may be allocated using spdk_nvme_ctrlr_alloc_io_qpair().
1506 : */
1507 : struct spdk_nvme_qpair;
1508 :
1509 : /**
1510 : * Signature for the callback function invoked when a timeout is detected on a
1511 : * request.
1512 : *
1513 : * For timeouts detected on the admin queue pair, the qpair returned here will
1514 : * be NULL. If the controller has a serious error condition and is unable to
1515 : * communicate with driver via completion queue, the controller can set Controller
1516 : * Fatal Status field to 1, then reset is required to recover from such error.
1517 : * Users may detect Controller Fatal Status when timeout happens.
1518 : *
1519 : * \param cb_arg Argument passed to callback function.
1520 : * \param ctrlr Opaque handle to NVMe controller.
1521 : * \param qpair Opaque handle to a queue pair.
1522 : * \param cid Command ID.
1523 : */
1524 : typedef void (*spdk_nvme_timeout_cb)(void *cb_arg,
1525 : struct spdk_nvme_ctrlr *ctrlr,
1526 : struct spdk_nvme_qpair *qpair,
1527 : uint16_t cid);
1528 :
1529 : /**
1530 : * Register for timeout callback on a controller.
1531 : *
1532 : * The application can choose to register for timeout callback or not register
1533 : * for timeout callback.
1534 : *
1535 : * \param ctrlr NVMe controller on which to monitor for timeout.
1536 : * \param timeout_io_us Timeout value in microseconds for io commands.
1537 : * \param timeout_admin_us Timeout value in microseconds for admin commands.
1538 : * \param cb_fn A function pointer that points to the callback function.
1539 : * \param cb_arg Argument to the callback function.
1540 : */
1541 : void spdk_nvme_ctrlr_register_timeout_callback(struct spdk_nvme_ctrlr *ctrlr,
1542 : uint64_t timeout_io_us, uint64_t timeout_admin_us,
1543 : spdk_nvme_timeout_cb cb_fn, void *cb_arg);
1544 :
1545 : /**
1546 : * Signature for the callback function when a
1547 : * \ref spdk_nvme_ctrlr_get_discovery_log_page operation is completed.
1548 : *
1549 : * \param cb_arg Argument passed to callback function.
1550 : * \param rc Status of operation. 0 means success, and that the cpl argument is valid.
1551 : * Failure indicated by negative errno value.
1552 : * \param cpl NVMe completion status of the operation. NULL if rc != 0. If multiple
1553 : * completions with error status occurred during the operation, the cpl
1554 : * value for the first error will be used here.
1555 : * \param log_page Pointer to the full discovery log page. The application is
1556 : * responsible for freeing this buffer using free().
1557 : */
1558 : typedef void (*spdk_nvme_discovery_cb)(void *cb_arg, int rc,
1559 : const struct spdk_nvme_cpl *cpl,
1560 : struct spdk_nvmf_discovery_log_page *log_page);
1561 :
1562 : /**
1563 : * Get a full discovery log page from the specified controller.
1564 : *
1565 : * This function will first read the discovery log header to determine the
1566 : * total number of valid entries in the discovery log, then it will allocate
1567 : * a buffer to hold the entire log and issue multiple GET_LOG_PAGE commands to
1568 : * get all of the entries.
1569 : *
1570 : * The application is responsible for calling
1571 : * \ref spdk_nvme_ctrlr_process_admin_completions to trigger processing of
1572 : * completions submitted by this function.
1573 : *
1574 : * \param ctrlr Pointer to the discovery controller.
1575 : * \param cb_fn Function to call when the operation is complete.
1576 : * \param cb_arg Argument to pass to cb_fn.
1577 : */
1578 : int spdk_nvme_ctrlr_get_discovery_log_page(struct spdk_nvme_ctrlr *ctrlr,
1579 : spdk_nvme_discovery_cb cb_fn, void *cb_arg);
1580 :
1581 : /**
1582 : * NVMe I/O queue pair initialization options.
1583 : *
1584 : * These options may be passed to spdk_nvme_ctrlr_alloc_io_qpair() to configure queue pair
1585 : * options at queue creation time.
1586 : *
1587 : * The user may retrieve the default I/O queue pair creation options for a controller using
1588 : * spdk_nvme_ctrlr_get_default_io_qpair_opts().
1589 : */
1590 : struct spdk_nvme_io_qpair_opts {
1591 : /**
1592 : * Queue priority for weighted round robin arbitration. If a different arbitration
1593 : * method is in use, pass 0.
1594 : */
1595 : enum spdk_nvme_qprio qprio;
1596 :
1597 : /**
1598 : * The queue depth of this NVMe I/O queue. Overrides spdk_nvme_ctrlr_opts::io_queue_size.
1599 : */
1600 : uint32_t io_queue_size;
1601 :
1602 : /**
1603 : * The number of requests to allocate for this NVMe I/O queue.
1604 : *
1605 : * Overrides spdk_nvme_ctrlr_opts::io_queue_requests.
1606 : *
1607 : * This should be at least as large as io_queue_size.
1608 : *
1609 : * A single I/O may allocate more than one request, since splitting may be
1610 : * necessary to conform to the device's maximum transfer size, PRP list
1611 : * compatibility requirements, or driver-assisted striping.
1612 : */
1613 : uint32_t io_queue_requests;
1614 :
1615 : /**
1616 : * When submitting I/O via spdk_nvme_ns_read/write and similar functions,
1617 : * don't immediately submit it to hardware. Instead, queue up new commands
1618 : * and submit them to the hardware inside spdk_nvme_qpair_process_completions().
1619 : *
1620 : * This results in better batching of I/O commands. Often, it is more efficient
1621 : * to submit batches of commands to the underlying hardware than each command
1622 : * individually.
1623 : *
1624 : * This only applies to PCIe and RDMA transports.
1625 : *
1626 : * The flag was originally named delay_pcie_doorbell. To allow backward compatibility
1627 : * both names are kept in unnamed union.
1628 : */
1629 : union {
1630 : bool delay_cmd_submit;
1631 : bool delay_pcie_doorbell;
1632 : };
1633 :
1634 : /* Hole at bytes 13-15. */
1635 : uint8_t reserved13[3];
1636 :
1637 : /**
1638 : * These fields allow specifying the memory buffers for the submission and/or
1639 : * completion queues.
1640 : * By default, vaddr is set to NULL meaning SPDK will allocate the memory to be used.
1641 : * If vaddr is NULL then paddr must be set to 0.
1642 : * If vaddr is non-NULL, and paddr is zero, SPDK derives the physical
1643 : * address for the NVMe device, in this case the memory must be registered.
1644 : * If a paddr value is non-zero, SPDK uses the vaddr and paddr as passed
1645 : * SPDK assumes that the memory passed is both virtually and physically
1646 : * contiguous.
1647 : * If these fields are used, SPDK will NOT impose any restriction
1648 : * on the number of elements in the queues.
1649 : * The buffer sizes are in number of bytes, and are used to confirm
1650 : * that the buffers are large enough to contain the appropriate queue.
1651 : * These fields are only used by PCIe attached NVMe devices. They
1652 : * are presently ignored for other transports.
1653 : */
1654 : struct {
1655 : struct spdk_nvme_cmd *vaddr;
1656 : uint64_t paddr;
1657 : uint64_t buffer_size;
1658 : } sq;
1659 : struct {
1660 : struct spdk_nvme_cpl *vaddr;
1661 : uint64_t paddr;
1662 : uint64_t buffer_size;
1663 : } cq;
1664 :
1665 : /**
1666 : * This flag indicates to the alloc_io_qpair function that it should not perform
1667 : * the connect portion on this qpair. This allows the user to add the qpair to a
1668 : * poll group and then connect it later.
1669 : */
1670 : bool create_only;
1671 :
1672 : /**
1673 : * This flag if set to true enables the creation of submission and completion queue
1674 : * asynchronously. Default mode is set to false to create io qpair synchronously.
1675 : */
1676 : bool async_mode;
1677 :
1678 : /* Hole at bytes 66-71. */
1679 : uint8_t reserved66[6];
1680 : };
1681 : SPDK_STATIC_ASSERT(sizeof(struct spdk_nvme_io_qpair_opts) == 72, "Incorrect size");
1682 :
1683 : /**
1684 : * Get the default options for I/O qpair creation for a specific NVMe controller.
1685 : *
1686 : * \param ctrlr NVMe controller to retrieve the defaults from.
1687 : * \param[out] opts Will be filled with the default options for
1688 : * spdk_nvme_ctrlr_alloc_io_qpair().
1689 : * \param opts_size Must be set to sizeof(struct spdk_nvme_io_qpair_opts).
1690 : */
1691 : void spdk_nvme_ctrlr_get_default_io_qpair_opts(struct spdk_nvme_ctrlr *ctrlr,
1692 : struct spdk_nvme_io_qpair_opts *opts,
1693 : size_t opts_size);
1694 :
1695 : /**
1696 : * Allocate an I/O queue pair (submission and completion queue).
1697 : *
1698 : * This function by default also performs any connection activities required for
1699 : * a newly created qpair. To avoid that behavior, the user should set the create_only
1700 : * flag in the opts structure to true.
1701 : *
1702 : * Each queue pair should only be used from a single thread at a time (mutual
1703 : * exclusion must be enforced by the user).
1704 : *
1705 : * \param ctrlr NVMe controller for which to allocate the I/O queue pair.
1706 : * \param opts I/O qpair creation options, or NULL to use the defaults as returned
1707 : * by spdk_nvme_ctrlr_get_default_io_qpair_opts().
1708 : * \param opts_size Must be set to sizeof(struct spdk_nvme_io_qpair_opts), or 0
1709 : * if opts is NULL.
1710 : *
1711 : * \return a pointer to the allocated I/O queue pair.
1712 : */
1713 : struct spdk_nvme_qpair *spdk_nvme_ctrlr_alloc_io_qpair(struct spdk_nvme_ctrlr *ctrlr,
1714 : const struct spdk_nvme_io_qpair_opts *opts,
1715 : size_t opts_size);
1716 :
1717 : /**
1718 : * Connect a newly created I/O qpair.
1719 : *
1720 : * This function does any connection activities required for a newly created qpair.
1721 : * It should be called after spdk_nvme_ctrlr_alloc_io_qpair has been called with the
1722 : * create_only flag set to true in the spdk_nvme_io_qpair_opts structure.
1723 : *
1724 : * This call will fail if performed on a qpair that is already connected.
1725 : * For reconnecting qpairs, see spdk_nvme_ctrlr_reconnect_io_qpair.
1726 : *
1727 : * For fabrics like TCP and RDMA, this function actually sends the commands over the wire
1728 : * that connect the qpair. For PCIe, this function performs some internal state machine operations.
1729 : *
1730 : * \param ctrlr NVMe controller for which to allocate the I/O queue pair.
1731 : * \param qpair Opaque handle to the qpair to connect.
1732 : *
1733 : * return 0 on success or negated errno on failure. Specifically -EISCONN if the qpair is already connected.
1734 : *
1735 : */
1736 : int spdk_nvme_ctrlr_connect_io_qpair(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qpair);
1737 :
1738 : /**
1739 : * Disconnect the given I/O qpair.
1740 : *
1741 : * This function must be called from the same thread as spdk_nvme_qpair_process_completions
1742 : * and the spdk_nvme_ns_cmd_* functions.
1743 : *
1744 : * After disconnect, calling spdk_nvme_qpair_process_completions or one of the
1745 : * spdk_nvme_ns_cmd* on a qpair will result in a return value of -ENXIO. A
1746 : * disconnected qpair may be reconnected with either the spdk_nvme_ctrlr_connect_io_qpair
1747 : * or spdk_nvme_ctrlr_reconnect_io_qpair APIs.
1748 : *
1749 : * \param qpair The qpair to disconnect.
1750 : */
1751 : void spdk_nvme_ctrlr_disconnect_io_qpair(struct spdk_nvme_qpair *qpair);
1752 :
1753 : /**
1754 : * Attempt to reconnect the given qpair.
1755 : *
1756 : * This function is intended to be called on qpairs that have already been connected,
1757 : * but have since entered a failed state as indicated by a return value of -ENXIO from
1758 : * either spdk_nvme_qpair_process_completions or one of the spdk_nvme_ns_cmd_* functions.
1759 : * This function must be called from the same thread as spdk_nvme_qpair_process_completions
1760 : * and the spdk_nvme_ns_cmd_* functions.
1761 : *
1762 : * Calling this function has the same effect as calling spdk_nvme_ctrlr_disconnect_io_qpair
1763 : * followed by spdk_nvme_ctrlr_connect_io_qpair.
1764 : *
1765 : * This function may be called on newly created qpairs, but it does extra checks and attempts
1766 : * to disconnect the qpair before connecting it. The recommended API for newly created qpairs
1767 : * is spdk_nvme_ctrlr_connect_io_qpair.
1768 : *
1769 : * \param qpair The qpair to reconnect.
1770 : *
1771 : * \return 0 on success, or if the qpair was already connected.
1772 : * -EAGAIN if the driver was unable to reconnect during this call,
1773 : * but the controller is still connected and is either resetting or enabled.
1774 : * -ENODEV if the controller is removed. In this case, the controller cannot be recovered
1775 : * and the application will have to destroy it and the associated qpairs.
1776 : * -ENXIO if the controller is in a failed state but is not yet resetting. In this case,
1777 : * the application should call spdk_nvme_ctrlr_reset to reset the entire controller.
1778 : */
1779 : int spdk_nvme_ctrlr_reconnect_io_qpair(struct spdk_nvme_qpair *qpair);
1780 :
1781 : /**
1782 : * Returns the reason the admin qpair for a given controller is disconnected.
1783 : *
1784 : * \param ctrlr The controller to check.
1785 : *
1786 : * \return a valid spdk_nvme_qp_failure_reason.
1787 : */
1788 : spdk_nvme_qp_failure_reason spdk_nvme_ctrlr_get_admin_qp_failure_reason(
1789 : struct spdk_nvme_ctrlr *ctrlr);
1790 :
1791 : /**
1792 : * Free an I/O queue pair that was allocated by spdk_nvme_ctrlr_alloc_io_qpair().
1793 : *
1794 : * The qpair must not be accessed after calling this function.
1795 : *
1796 : * \param qpair I/O queue pair to free.
1797 : *
1798 : * \return 0 on success. This function will never return any value other than 0.
1799 : */
1800 : int spdk_nvme_ctrlr_free_io_qpair(struct spdk_nvme_qpair *qpair);
1801 :
1802 : /**
1803 : * Send the given NVM I/O command, I/O buffers, lists and all to the NVMe controller.
1804 : *
1805 : * This is a low level interface for submitting I/O commands directly.
1806 : *
1807 : * This function allows a caller to submit an I/O request that is
1808 : * COMPLETELY pre-defined, right down to the "physical" memory buffers.
1809 : * It is intended for testing hardware, specifying exact buffer location,
1810 : * alignment, and offset. It also allows for specific choice of PRP
1811 : * and SGLs.
1812 : *
1813 : * The driver sets the CID. EVERYTHING else is assumed set by the caller.
1814 : * Needless to say, this is potentially extremely dangerous for both the host
1815 : * (accidental/malicious storage usage/corruption), and the device.
1816 : * Thus its intent is for very specific hardware testing and environment
1817 : * reproduction.
1818 : *
1819 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
1820 : * The user must ensure that only one thread submits I/O on a given qpair at any
1821 : * given time.
1822 : *
1823 : * This function can only be used on PCIe controllers and qpairs.
1824 : *
1825 : * \param ctrlr Opaque handle to NVMe controller.
1826 : * \param qpair I/O qpair to submit command.
1827 : * \param cmd NVM I/O command to submit.
1828 : * \param cb_fn Callback function invoked when the I/O command completes.
1829 : * \param cb_arg Argument passed to callback function.
1830 : *
1831 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
1832 : * -ENOMEM: The request cannot be allocated.
1833 : * -ENXIO: The qpair is failed at the transport level.
1834 : */
1835 :
1836 : int spdk_nvme_ctrlr_io_cmd_raw_no_payload_build(struct spdk_nvme_ctrlr *ctrlr,
1837 : struct spdk_nvme_qpair *qpair,
1838 : struct spdk_nvme_cmd *cmd,
1839 : spdk_nvme_cmd_cb cb_fn, void *cb_arg);
1840 :
1841 : /**
1842 : * Send the given NVM I/O command to the NVMe controller.
1843 : *
1844 : * This is a low level interface for submitting I/O commands directly. Prefer
1845 : * the spdk_nvme_ns_cmd_* functions instead. The validity of the command will
1846 : * not be checked!
1847 : *
1848 : * When constructing the nvme_command it is not necessary to fill out the PRP
1849 : * list/SGL or the CID. The driver will handle both of those for you.
1850 : *
1851 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
1852 : * The user must ensure that only one thread submits I/O on a given qpair at any
1853 : * given time.
1854 : *
1855 : * \param ctrlr Opaque handle to NVMe controller.
1856 : * \param qpair I/O qpair to submit command.
1857 : * \param cmd NVM I/O command to submit.
1858 : * \param buf Virtual memory address of a single physically contiguous buffer.
1859 : * \param len Size of buffer.
1860 : * \param cb_fn Callback function invoked when the I/O command completes.
1861 : * \param cb_arg Argument passed to callback function.
1862 : *
1863 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
1864 : * -ENOMEM: The request cannot be allocated.
1865 : * -ENXIO: The qpair is failed at the transport level.
1866 : */
1867 : int spdk_nvme_ctrlr_cmd_io_raw(struct spdk_nvme_ctrlr *ctrlr,
1868 : struct spdk_nvme_qpair *qpair,
1869 : struct spdk_nvme_cmd *cmd,
1870 : void *buf, uint32_t len,
1871 : spdk_nvme_cmd_cb cb_fn, void *cb_arg);
1872 :
1873 : /**
1874 : * Send the given NVM I/O command with metadata to the NVMe controller.
1875 : *
1876 : * This is a low level interface for submitting I/O commands directly. Prefer
1877 : * the spdk_nvme_ns_cmd_* functions instead. The validity of the command will
1878 : * not be checked!
1879 : *
1880 : * When constructing the nvme_command it is not necessary to fill out the PRP
1881 : * list/SGL or the CID. The driver will handle both of those for you.
1882 : *
1883 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
1884 : * The user must ensure that only one thread submits I/O on a given qpair at any
1885 : * given time.
1886 : *
1887 : * \param ctrlr Opaque handle to NVMe controller.
1888 : * \param qpair I/O qpair to submit command.
1889 : * \param cmd NVM I/O command to submit.
1890 : * \param buf Virtual memory address of a single physically contiguous buffer.
1891 : * \param len Size of buffer.
1892 : * \param md_buf Virtual memory address of a single physically contiguous metadata
1893 : * buffer.
1894 : * \param cb_fn Callback function invoked when the I/O command completes.
1895 : * \param cb_arg Argument passed to callback function.
1896 : *
1897 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
1898 : * -ENOMEM: The request cannot be allocated.
1899 : * -ENXIO: The qpair is failed at the transport level.
1900 : */
1901 : int spdk_nvme_ctrlr_cmd_io_raw_with_md(struct spdk_nvme_ctrlr *ctrlr,
1902 : struct spdk_nvme_qpair *qpair,
1903 : struct spdk_nvme_cmd *cmd,
1904 : void *buf, uint32_t len, void *md_buf,
1905 : spdk_nvme_cmd_cb cb_fn, void *cb_arg);
1906 :
1907 : /**
1908 : * Restart the SGL walk to the specified offset when the command has scattered
1909 : * payloads.
1910 : *
1911 : * \param cb_arg Argument passed to readv/writev.
1912 : * \param offset Offset for SGL.
1913 : */
1914 : typedef void (*spdk_nvme_req_reset_sgl_cb)(void *cb_arg, uint32_t offset);
1915 :
1916 : /**
1917 : * Fill out *address and *length with the current SGL entry and advance to the
1918 : * next entry for the next time the callback is invoked.
1919 : *
1920 : * The described segment must be physically contiguous.
1921 : *
1922 : * \param cb_arg Argument passed to readv/writev.
1923 : * \param address Virtual address of this segment, a value of UINT64_MAX
1924 : * means the segment should be described via Bit Bucket SGL.
1925 : * \param length Length of this physical segment.
1926 : */
1927 : typedef int (*spdk_nvme_req_next_sge_cb)(void *cb_arg, void **address,
1928 : uint32_t *length);
1929 :
1930 : /**
1931 : * Send the given NVM I/O command with metadata to the NVMe controller.
1932 : *
1933 : * This is a low level interface for submitting I/O commands directly. Prefer
1934 : * the spdk_nvme_ns_cmd_* functions instead. The validity of the command will
1935 : * not be checked!
1936 : *
1937 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
1938 : * The user must ensure that only one thread submits I/O on a given qpair at any
1939 : * given time.
1940 : *
1941 : * \param ctrlr Opaque handle to NVMe controller.
1942 : * \param qpair I/O qpair to submit command.
1943 : * \param cmd NVM I/O command to submit.
1944 : * \param len Size of buffer.
1945 : * \param md_buf Virtual memory address of a single physically contiguous metadata buffer.
1946 : * \param cb_fn Callback function invoked when the I/O command completes.
1947 : * \param cb_arg Argument passed to callback function.
1948 : * \param reset_sgl_fn Callback function to reset scattered payload.
1949 : * \param next_sge_fn Callback function to iterate each scattered payload memory segment.
1950 : *
1951 : * \return 0 if successfully submitted, negated errnos on the following error
1952 : conditions:
1953 : * -ENOMEM: The request cannot be allocated.
1954 : * -ENXIO: The qpair is failed at the transport level.
1955 : */
1956 : int spdk_nvme_ctrlr_cmd_iov_raw_with_md(struct spdk_nvme_ctrlr *ctrlr,
1957 : struct spdk_nvme_qpair *qpair,
1958 : struct spdk_nvme_cmd *cmd, uint32_t len,
1959 : void *md_buf, spdk_nvme_cmd_cb cb_fn,
1960 : void *cb_arg,
1961 : spdk_nvme_req_reset_sgl_cb reset_sgl_fn,
1962 : spdk_nvme_req_next_sge_cb next_sge_fn);
1963 :
1964 : /**
1965 : * Process any outstanding completions for I/O submitted on a queue pair.
1966 : *
1967 : * This call is non-blocking, i.e. it only processes completions that are ready
1968 : * at the time of this function call. It does not wait for outstanding commands
1969 : * to finish.
1970 : *
1971 : * For each completed command, the request's callback function will be called if
1972 : * specified as non-NULL when the request was submitted.
1973 : *
1974 : * The caller must ensure that each queue pair is only used from one thread at a
1975 : * time.
1976 : *
1977 : * This function may be called at any point while the controller is attached to
1978 : * the SPDK NVMe driver.
1979 : *
1980 : * \sa spdk_nvme_cmd_cb
1981 : *
1982 : * \param qpair Queue pair to check for completions.
1983 : * \param max_completions Limit the number of completions to be processed in one
1984 : * call, or 0 for unlimited.
1985 : *
1986 : * \return number of completions processed (may be 0) or negated on error. -ENXIO
1987 : * in the special case that the qpair is failed at the transport layer.
1988 : */
1989 : int32_t spdk_nvme_qpair_process_completions(struct spdk_nvme_qpair *qpair,
1990 : uint32_t max_completions);
1991 :
1992 : /**
1993 : * Returns the reason the qpair is disconnected.
1994 : *
1995 : * \param qpair The qpair to check.
1996 : *
1997 : * \return a valid spdk_nvme_qp_failure_reason.
1998 : */
1999 : spdk_nvme_qp_failure_reason spdk_nvme_qpair_get_failure_reason(struct spdk_nvme_qpair *qpair);
2000 :
2001 : /**
2002 : * Control if DNR is set or not for aborted commands.
2003 : *
2004 : * The default value is false.
2005 : *
2006 : * \param qpair The qpair to set.
2007 : * \param dnr Set the DNR bit to 1 if true or 0 if false for aborted commands.
2008 : */
2009 : void spdk_nvme_qpair_set_abort_dnr(struct spdk_nvme_qpair *qpair, bool dnr);
2010 :
2011 : /**
2012 : * Return the connection status of a given qpair.
2013 : *
2014 : * \param qpair The qpair to check.
2015 : *
2016 : * \return true if the qpair is connected, or false otherwise.
2017 : */
2018 : bool spdk_nvme_qpair_is_connected(struct spdk_nvme_qpair *qpair);
2019 :
2020 : /**
2021 : * Send the given admin command to the NVMe controller.
2022 : *
2023 : * This is a low level interface for submitting admin commands directly. Prefer
2024 : * the spdk_nvme_ctrlr_cmd_* functions instead. The validity of the command will
2025 : * not be checked!
2026 : *
2027 : * When constructing the nvme_command it is not necessary to fill out the PRP
2028 : * list/SGL or the CID. The driver will handle both of those for you.
2029 : *
2030 : * This function is thread safe and can be called at any point while the controller
2031 : * is attached to the SPDK NVMe driver.
2032 : *
2033 : * Call spdk_nvme_ctrlr_process_admin_completions() to poll for completion
2034 : * of commands submitted through this function.
2035 : *
2036 : * \param ctrlr Opaque handle to NVMe controller.
2037 : * \param cmd NVM admin command to submit.
2038 : * \param buf Virtual memory address of a single physically contiguous buffer.
2039 : * \param len Size of buffer.
2040 : * \param cb_fn Callback function invoked when the admin command completes.
2041 : * \param cb_arg Argument passed to callback function.
2042 : *
2043 : * \return 0 if successfully submitted, negated errno if resources could not be
2044 : * allocated for this request, -ENXIO if the admin qpair is failed at the transport layer.
2045 : */
2046 : int spdk_nvme_ctrlr_cmd_admin_raw(struct spdk_nvme_ctrlr *ctrlr,
2047 : struct spdk_nvme_cmd *cmd,
2048 : void *buf, uint32_t len,
2049 : spdk_nvme_cmd_cb cb_fn, void *cb_arg);
2050 :
2051 : /**
2052 : * Process any outstanding completions for admin commands.
2053 : *
2054 : * This will process completions for admin commands submitted on any thread.
2055 : *
2056 : * This call is non-blocking, i.e. it only processes completions that are ready
2057 : * at the time of this function call. It does not wait for outstanding commands
2058 : * to finish.
2059 : *
2060 : * This function is thread safe and can be called at any point while the controller
2061 : * is attached to the SPDK NVMe driver.
2062 : *
2063 : * \param ctrlr Opaque handle to NVMe controller.
2064 : *
2065 : * \return number of completions processed (may be 0) or negated on error. -ENXIO
2066 : * in the special case that the qpair is failed at the transport layer.
2067 : */
2068 : int32_t spdk_nvme_ctrlr_process_admin_completions(struct spdk_nvme_ctrlr *ctrlr);
2069 :
2070 :
2071 : /**
2072 : * Opaque handle to a namespace. Obtained by calling spdk_nvme_ctrlr_get_ns().
2073 : */
2074 : struct spdk_nvme_ns;
2075 :
2076 : /**
2077 : * Get a handle to a namespace for the given controller.
2078 : *
2079 : * Namespaces are numbered from 1 to the total number of namespaces. There will
2080 : * never be any gaps in the numbering. The number of namespaces is obtained by
2081 : * calling spdk_nvme_ctrlr_get_num_ns().
2082 : *
2083 : * This function is thread safe and can be called at any point while the controller
2084 : * is attached to the SPDK NVMe driver.
2085 : *
2086 : * \param ctrlr Opaque handle to NVMe controller.
2087 : * \param ns_id Namespace id.
2088 : *
2089 : * \return a pointer to the namespace.
2090 : */
2091 : struct spdk_nvme_ns *spdk_nvme_ctrlr_get_ns(struct spdk_nvme_ctrlr *ctrlr, uint32_t ns_id);
2092 :
2093 : /**
2094 : * Get a specific log page from the NVMe controller.
2095 : *
2096 : * This function is thread safe and can be called at any point while the controller
2097 : * is attached to the SPDK NVMe driver.
2098 : *
2099 : * Call spdk_nvme_ctrlr_process_admin_completions() to poll for completion of
2100 : * commands submitted through this function.
2101 : *
2102 : * \sa spdk_nvme_ctrlr_is_log_page_supported()
2103 : *
2104 : * \param ctrlr Opaque handle to NVMe controller.
2105 : * \param log_page The log page identifier.
2106 : * \param nsid Depending on the log page, this may be 0, a namespace identifier,
2107 : * or SPDK_NVME_GLOBAL_NS_TAG.
2108 : * \param payload The pointer to the payload buffer.
2109 : * \param payload_size The size of payload buffer.
2110 : * \param offset Offset in bytes within the log page to start retrieving log page
2111 : * data. May only be non-zero if the controller supports extended data for Get Log
2112 : * Page as reported in the controller data log page attributes.
2113 : * \param cb_fn Callback function to invoke when the log page has been retrieved.
2114 : * \param cb_arg Argument to pass to the callback function.
2115 : *
2116 : * \return 0 if successfully submitted, negated errno if resources could not be
2117 : * allocated for this request, -ENXIO if the admin qpair is failed at the transport layer.
2118 : */
2119 : int spdk_nvme_ctrlr_cmd_get_log_page(struct spdk_nvme_ctrlr *ctrlr,
2120 : uint8_t log_page, uint32_t nsid,
2121 : void *payload, uint32_t payload_size,
2122 : uint64_t offset,
2123 : spdk_nvme_cmd_cb cb_fn, void *cb_arg);
2124 :
2125 : /**
2126 : * Get a specific log page from the NVMe controller.
2127 : *
2128 : * This function is thread safe and can be called at any point while the controller
2129 : * is attached to the SPDK NVMe driver.
2130 : *
2131 : * This function allows specifying extra fields in cdw10 and cdw11 such as
2132 : * Retain Asynchronous Event and Log Specific Field.
2133 : *
2134 : * Call spdk_nvme_ctrlr_process_admin_completions() to poll for completion of
2135 : * commands submitted through this function.
2136 : *
2137 : * \sa spdk_nvme_ctrlr_is_log_page_supported()
2138 : *
2139 : * \param ctrlr Opaque handle to NVMe controller.
2140 : * \param log_page The log page identifier.
2141 : * \param nsid Depending on the log page, this may be 0, a namespace identifier,
2142 : * or SPDK_NVME_GLOBAL_NS_TAG.
2143 : * \param payload The pointer to the payload buffer.
2144 : * \param payload_size The size of payload buffer.
2145 : * \param offset Offset in bytes within the log page to start retrieving log page
2146 : * data. May only be non-zero if the controller supports extended data for Get Log
2147 : * Page as reported in the controller data log page attributes.
2148 : * \param cdw10 Value to specify for cdw10. Specify 0 for numdl - it will be
2149 : * set by this function based on the payload_size parameter. Specify 0 for lid -
2150 : * it will be set by this function based on the log_page parameter.
2151 : * \param cdw11 Value to specify for cdw11. Specify 0 for numdu - it will be
2152 : * set by this function based on the payload_size.
2153 : * \param cdw14 Value to specify for cdw14.
2154 : * \param cb_fn Callback function to invoke when the log page has been retrieved.
2155 : * \param cb_arg Argument to pass to the callback function.
2156 : *
2157 : * \return 0 if successfully submitted, negated errno if resources could not be
2158 : * allocated for this request, -ENXIO if the admin qpair is failed at the transport layer.
2159 : */
2160 : int spdk_nvme_ctrlr_cmd_get_log_page_ext(struct spdk_nvme_ctrlr *ctrlr, uint8_t log_page,
2161 : uint32_t nsid, void *payload, uint32_t payload_size,
2162 : uint64_t offset, uint32_t cdw10, uint32_t cdw11,
2163 : uint32_t cdw14, spdk_nvme_cmd_cb cb_fn, void *cb_arg);
2164 :
2165 : /**
2166 : * Abort a specific previously-submitted NVMe command.
2167 : *
2168 : * \sa spdk_nvme_ctrlr_register_timeout_callback()
2169 : *
2170 : * \param ctrlr NVMe controller to which the command was submitted.
2171 : * \param qpair NVMe queue pair to which the command was submitted. For admin
2172 : * commands, pass NULL for the qpair.
2173 : * \param cid Command ID of the command to abort.
2174 : * \param cb_fn Callback function to invoke when the abort has completed.
2175 : * \param cb_arg Argument to pass to the callback function.
2176 : *
2177 : * \return 0 if successfully submitted, negated errno if resources could not be
2178 : * allocated for this request, -ENXIO if the admin qpair is failed at the transport layer.
2179 : */
2180 : int spdk_nvme_ctrlr_cmd_abort(struct spdk_nvme_ctrlr *ctrlr,
2181 : struct spdk_nvme_qpair *qpair,
2182 : uint16_t cid,
2183 : spdk_nvme_cmd_cb cb_fn,
2184 : void *cb_arg);
2185 :
2186 : /**
2187 : * Abort previously submitted commands which have cmd_cb_arg as its callback argument.
2188 : *
2189 : * \param ctrlr NVMe controller to which the commands were submitted.
2190 : * \param qpair NVMe queue pair to which the commands were submitted. For admin
2191 : * commands, pass NULL for the qpair.
2192 : * \param cmd_cb_arg Callback argument for the NVMe commands which this function
2193 : * attempts to abort.
2194 : * \param cb_fn Callback function to invoke when this function has completed.
2195 : * \param cb_arg Argument to pass to the callback function.
2196 : *
2197 : * \return 0 if successfully submitted, negated errno otherwise.
2198 : */
2199 : int spdk_nvme_ctrlr_cmd_abort_ext(struct spdk_nvme_ctrlr *ctrlr,
2200 : struct spdk_nvme_qpair *qpair,
2201 : void *cmd_cb_arg,
2202 : spdk_nvme_cmd_cb cb_fn,
2203 : void *cb_arg);
2204 :
2205 : /**
2206 : * Set specific feature for the given NVMe controller.
2207 : *
2208 : * This function is thread safe and can be called at any point while the controller
2209 : * is attached to the SPDK NVMe driver.
2210 : *
2211 : * Call spdk_nvme_ctrlr_process_admin_completions() to poll for completion of
2212 : * commands submitted through this function.
2213 : *
2214 : * \sa spdk_nvme_ctrlr_cmd_get_feature().
2215 : *
2216 : * \param ctrlr NVMe controller to manipulate.
2217 : * \param feature The feature identifier.
2218 : * \param cdw11 as defined by the specification for this command.
2219 : * \param cdw12 as defined by the specification for this command.
2220 : * \param payload The pointer to the payload buffer.
2221 : * \param payload_size The size of payload buffer.
2222 : * \param cb_fn Callback function to invoke when the feature has been set.
2223 : * \param cb_arg Argument to pass to the callback function.
2224 : *
2225 : * \return 0 if successfully submitted, negated errno if resources could not be
2226 : * allocated for this request, -ENXIO if the admin qpair is failed at the transport layer.
2227 : */
2228 : int spdk_nvme_ctrlr_cmd_set_feature(struct spdk_nvme_ctrlr *ctrlr,
2229 : uint8_t feature, uint32_t cdw11, uint32_t cdw12,
2230 : void *payload, uint32_t payload_size,
2231 : spdk_nvme_cmd_cb cb_fn, void *cb_arg);
2232 :
2233 : /**
2234 : * Get specific feature from given NVMe controller.
2235 : *
2236 : * This function is thread safe and can be called at any point while the controller
2237 : * is attached to the SPDK NVMe driver.
2238 : *
2239 : * Call spdk_nvme_ctrlr_process_admin_completions() to poll for completion of
2240 : * commands submitted through this function.
2241 : *
2242 : * \sa spdk_nvme_ctrlr_cmd_set_feature()
2243 : *
2244 : * \param ctrlr NVMe controller to query.
2245 : * \param feature The feature identifier.
2246 : * \param cdw11 as defined by the specification for this command.
2247 : * \param payload The pointer to the payload buffer.
2248 : * \param payload_size The size of payload buffer.
2249 : * \param cb_fn Callback function to invoke when the feature has been retrieved.
2250 : * \param cb_arg Argument to pass to the callback function.
2251 : *
2252 : * \return 0 if successfully submitted, -ENOMEM if resources could not be allocated
2253 : * for this request, -ENXIO if the admin qpair is failed at the transport layer.
2254 : */
2255 : int spdk_nvme_ctrlr_cmd_get_feature(struct spdk_nvme_ctrlr *ctrlr,
2256 : uint8_t feature, uint32_t cdw11,
2257 : void *payload, uint32_t payload_size,
2258 : spdk_nvme_cmd_cb cb_fn, void *cb_arg);
2259 :
2260 : /**
2261 : * Get specific feature from given NVMe controller.
2262 : *
2263 : * \param ctrlr NVMe controller to query.
2264 : * \param feature The feature identifier.
2265 : * \param cdw11 as defined by the specification for this command.
2266 : * \param payload The pointer to the payload buffer.
2267 : * \param payload_size The size of payload buffer.
2268 : * \param cb_fn Callback function to invoke when the feature has been retrieved.
2269 : * \param cb_arg Argument to pass to the callback function.
2270 : * \param ns_id The namespace identifier.
2271 : *
2272 : * \return 0 if successfully submitted, -ENOMEM if resources could not be allocated
2273 : * for this request, -ENXIO if the admin qpair is failed at the transport layer.
2274 : *
2275 : * This function is thread safe and can be called at any point while the controller
2276 : * is attached to the SPDK NVMe driver.
2277 : *
2278 : * Call \ref spdk_nvme_ctrlr_process_admin_completions() to poll for completion
2279 : * of commands submitted through this function.
2280 : *
2281 : * \sa spdk_nvme_ctrlr_cmd_set_feature_ns()
2282 : */
2283 : int spdk_nvme_ctrlr_cmd_get_feature_ns(struct spdk_nvme_ctrlr *ctrlr, uint8_t feature,
2284 : uint32_t cdw11, void *payload, uint32_t payload_size,
2285 : spdk_nvme_cmd_cb cb_fn, void *cb_arg, uint32_t ns_id);
2286 :
2287 : /**
2288 : * Set specific feature for the given NVMe controller and namespace ID.
2289 : *
2290 : * \param ctrlr NVMe controller to manipulate.
2291 : * \param feature The feature identifier.
2292 : * \param cdw11 as defined by the specification for this command.
2293 : * \param cdw12 as defined by the specification for this command.
2294 : * \param payload The pointer to the payload buffer.
2295 : * \param payload_size The size of payload buffer.
2296 : * \param cb_fn Callback function to invoke when the feature has been set.
2297 : * \param cb_arg Argument to pass to the callback function.
2298 : * \param ns_id The namespace identifier.
2299 : *
2300 : * \return 0 if successfully submitted, -ENOMEM if resources could not be allocated
2301 : * for this request, -ENXIO if the admin qpair is failed at the transport layer.
2302 : *
2303 : * This function is thread safe and can be called at any point while the controller
2304 : * is attached to the SPDK NVMe driver.
2305 : *
2306 : * Call \ref spdk_nvme_ctrlr_process_admin_completions() to poll for completion
2307 : * of commands submitted through this function.
2308 : *
2309 : * \sa spdk_nvme_ctrlr_cmd_get_feature_ns()
2310 : */
2311 : int spdk_nvme_ctrlr_cmd_set_feature_ns(struct spdk_nvme_ctrlr *ctrlr, uint8_t feature,
2312 : uint32_t cdw11, uint32_t cdw12, void *payload,
2313 : uint32_t payload_size, spdk_nvme_cmd_cb cb_fn,
2314 : void *cb_arg, uint32_t ns_id);
2315 :
2316 : /**
2317 : * Receive security protocol data from controller.
2318 : *
2319 : * This function is thread safe and can be called at any point after spdk_nvme_probe().
2320 : *
2321 : * \param ctrlr NVMe controller to use for security receive command submission.
2322 : * \param secp Security Protocol that is used.
2323 : * \param spsp Security Protocol Specific field.
2324 : * \param nssf NVMe Security Specific field. Indicate RPMB target when using Security
2325 : * Protocol EAh.
2326 : * \param payload The pointer to the payload buffer.
2327 : * \param payload_size The size of payload buffer.
2328 : * \param cb_fn Callback function to invoke when the command has been completed.
2329 : * \param cb_arg Argument to pass to the callback function.
2330 : *
2331 : * \return 0 if successfully submitted, negated errno if resources could not be allocated
2332 : * for this request.
2333 : */
2334 : int spdk_nvme_ctrlr_cmd_security_receive(struct spdk_nvme_ctrlr *ctrlr, uint8_t secp,
2335 : uint16_t spsp, uint8_t nssf, void *payload,
2336 : uint32_t payload_size,
2337 : spdk_nvme_cmd_cb cb_fn, void *cb_arg);
2338 :
2339 : /**
2340 : * Send security protocol data to controller.
2341 : *
2342 : * This function is thread safe and can be called at any point after spdk_nvme_probe().
2343 : *
2344 : * \param ctrlr NVMe controller to use for security send command submission.
2345 : * \param secp Security Protocol that is used.
2346 : * \param spsp Security Protocol Specific field.
2347 : * \param nssf NVMe Security Specific field. Indicate RPMB target when using Security
2348 : * Protocol EAh.
2349 : * \param payload The pointer to the payload buffer.
2350 : * \param payload_size The size of payload buffer.
2351 : * \param cb_fn Callback function to invoke when the command has been completed.
2352 : * \param cb_arg Argument to pass to the callback function.
2353 : *
2354 : * \return 0 if successfully submitted, negated errno if resources could not be allocated
2355 : * for this request.
2356 : */
2357 : int spdk_nvme_ctrlr_cmd_security_send(struct spdk_nvme_ctrlr *ctrlr, uint8_t secp,
2358 : uint16_t spsp, uint8_t nssf, void *payload,
2359 : uint32_t payload_size, spdk_nvme_cmd_cb cb_fn, void *cb_arg);
2360 :
2361 : /**
2362 : * Receive security protocol data from controller.
2363 : *
2364 : * This function is thread safe and can be called at any point after spdk_nvme_probe().
2365 : *
2366 : * \param ctrlr NVMe controller to use for security receive command submission.
2367 : * \param secp Security Protocol that is used.
2368 : * \param spsp Security Protocol Specific field.
2369 : * \param nssf NVMe Security Specific field. Indicate RPMB target when using Security
2370 : * Protocol EAh.
2371 : * \param payload The pointer to the payload buffer.
2372 : * \param size The size of payload buffer.
2373 : *
2374 : * \return 0 if successfully submitted, negated errno if resources could not be allocated
2375 : * for this request.
2376 : */
2377 : int spdk_nvme_ctrlr_security_receive(struct spdk_nvme_ctrlr *ctrlr, uint8_t secp,
2378 : uint16_t spsp, uint8_t nssf, void *payload, size_t size);
2379 :
2380 : /**
2381 : * Send security protocol data to controller.
2382 : *
2383 : * This function is thread safe and can be called at any point after spdk_nvme_probe().
2384 : *
2385 : * \param ctrlr NVMe controller to use for security send command submission.
2386 : * \param secp Security Protocol that is used.
2387 : * \param spsp Security Protocol Specific field.
2388 : * \param nssf NVMe Security Specific field. Indicate RPMB target when using Security
2389 : * Protocol EAh.
2390 : * \param payload The pointer to the payload buffer.
2391 : * \param size The size of payload buffer.
2392 : *
2393 : * \return 0 if successfully submitted, negated errno if resources could not be allocated
2394 : * for this request.
2395 : */
2396 : int spdk_nvme_ctrlr_security_send(struct spdk_nvme_ctrlr *ctrlr, uint8_t secp,
2397 : uint16_t spsp, uint8_t nssf, void *payload, size_t size);
2398 :
2399 : /**
2400 : * Receive data related to a specific Directive Type from the controller.
2401 : *
2402 : * This function is thread safe and can be called at any point after spdk_nvme_probe().
2403 : *
2404 : * Call spdk_nvme_ctrlr_process_admin_completions() to poll for completion of
2405 : * commands submitted through this function.
2406 : *
2407 : * \param ctrlr NVMe controller to use for directive receive command submission.
2408 : * \param nsid Specific Namespace Identifier.
2409 : * \param doper Directive Operation defined in nvme_spec.h.
2410 : * \param dtype Directive Type defined in nvme_spec.h.
2411 : * \param dspec Directive Specific defined in nvme_spec.h.
2412 : * \param payload The pointer to the payload buffer.
2413 : * \param payload_size The size of payload buffer.
2414 : * \param cdw12 Command dword 12.
2415 : * \param cdw13 Command dword 13.
2416 : * \param cb_fn Callback function to invoke when the command has been completed.
2417 : * \param cb_arg Argument to pass to the callback function.
2418 : *
2419 : * \return 0 if successfully submitted, negated errno if resources could not be allocated
2420 : * for this request.
2421 : */
2422 : int spdk_nvme_ctrlr_cmd_directive_receive(struct spdk_nvme_ctrlr *ctrlr, uint32_t nsid,
2423 : uint32_t doper, uint32_t dtype, uint32_t dspec,
2424 : void *payload, uint32_t payload_size, uint32_t cdw12,
2425 : uint32_t cdw13, spdk_nvme_cmd_cb cb_fn, void *cb_arg);
2426 :
2427 : /**
2428 : * Send data related to a specific Directive Type to the controller.
2429 : *
2430 : * This function is thread safe and can be called at any point after spdk_nvme_probe().
2431 : *
2432 : * Call spdk_nvme_ctrlr_process_admin_completions() to poll for completion of
2433 : * commands submitted through this function.
2434 : *
2435 : * \param ctrlr NVMe controller to use for directive send command submission.
2436 : * \param nsid Specific Namespace Identifier.
2437 : * \param doper Directive Operation defined in nvme_spec.h.
2438 : * \param dtype Directive Type defined in nvme_spec.h.
2439 : * \param dspec Directive Specific defined in nvme_spec.h.
2440 : * \param payload The pointer to the payload buffer.
2441 : * \param payload_size The size of payload buffer.
2442 : * \param cdw12 Command dword 12.
2443 : * \param cdw13 Command dword 13.
2444 : * \param cb_fn Callback function to invoke when the command has been completed.
2445 : * \param cb_arg Argument to pass to the callback function.
2446 : *
2447 : * \return 0 if successfully submitted, negated errno if resources could not be allocated
2448 : * for this request.
2449 : */
2450 : int spdk_nvme_ctrlr_cmd_directive_send(struct spdk_nvme_ctrlr *ctrlr, uint32_t nsid,
2451 : uint32_t doper, uint32_t dtype, uint32_t dspec,
2452 : void *payload, uint32_t payload_size, uint32_t cdw12,
2453 : uint32_t cdw13, spdk_nvme_cmd_cb cb_fn, void *cb_arg);
2454 :
2455 : /**
2456 : * Get supported flags of the controller.
2457 : *
2458 : * \param ctrlr NVMe controller to get flags.
2459 : *
2460 : * \return supported flags of this controller.
2461 : */
2462 : uint64_t spdk_nvme_ctrlr_get_flags(struct spdk_nvme_ctrlr *ctrlr);
2463 :
2464 : /**
2465 : * Attach the specified namespace to controllers.
2466 : *
2467 : * This function is thread safe and can be called at any point after spdk_nvme_probe().
2468 : *
2469 : * \param ctrlr NVMe controller to use for command submission.
2470 : * \param nsid Namespace identifier for namespace to attach.
2471 : * \param payload The pointer to the controller list.
2472 : *
2473 : * \return 0 if successfully submitted, ENOMEM if resources could not be allocated
2474 : * for this request.
2475 : */
2476 : int spdk_nvme_ctrlr_attach_ns(struct spdk_nvme_ctrlr *ctrlr, uint32_t nsid,
2477 : struct spdk_nvme_ctrlr_list *payload);
2478 :
2479 : /**
2480 : * Detach the specified namespace from controllers.
2481 : *
2482 : * This function is thread safe and can be called at any point after spdk_nvme_probe().
2483 : *
2484 : * \param ctrlr NVMe controller to use for command submission.
2485 : * \param nsid Namespace ID to detach.
2486 : * \param payload The pointer to the controller list.
2487 : *
2488 : * \return 0 if successfully submitted, ENOMEM if resources could not be allocated
2489 : * for this request
2490 : */
2491 : int spdk_nvme_ctrlr_detach_ns(struct spdk_nvme_ctrlr *ctrlr, uint32_t nsid,
2492 : struct spdk_nvme_ctrlr_list *payload);
2493 :
2494 : /**
2495 : * Create a namespace.
2496 : *
2497 : * This function is thread safe and can be called at any point after spdk_nvme_probe().
2498 : *
2499 : * \param ctrlr NVMe controller to create namespace on.
2500 : * \param payload The pointer to the NVMe namespace data.
2501 : *
2502 : * \return Namespace ID (>= 1) if successfully created, or 0 if the request failed.
2503 : */
2504 : uint32_t spdk_nvme_ctrlr_create_ns(struct spdk_nvme_ctrlr *ctrlr,
2505 : struct spdk_nvme_ns_data *payload);
2506 :
2507 : /**
2508 : * Delete a namespace.
2509 : *
2510 : * This function is thread safe and can be called at any point after spdk_nvme_probe().
2511 : *
2512 : * \param ctrlr NVMe controller to delete namespace from.
2513 : * \param nsid The namespace identifier.
2514 : *
2515 : * \return 0 if successfully submitted, negated errno if resources could not be
2516 : * allocated
2517 : * for this request
2518 : */
2519 : int spdk_nvme_ctrlr_delete_ns(struct spdk_nvme_ctrlr *ctrlr, uint32_t nsid);
2520 :
2521 : /**
2522 : * Format NVM.
2523 : *
2524 : * This function requests a low-level format of the media.
2525 : *
2526 : * This function is thread safe and can be called at any point after spdk_nvme_probe().
2527 : *
2528 : * \param ctrlr NVMe controller to format.
2529 : * \param nsid The namespace identifier. May be SPDK_NVME_GLOBAL_NS_TAG to format
2530 : * all namespaces.
2531 : * \param format The format information for the command.
2532 : *
2533 : * \return 0 if successfully submitted, negated errno if resources could not be
2534 : * allocated for this request
2535 : */
2536 : int spdk_nvme_ctrlr_format(struct spdk_nvme_ctrlr *ctrlr, uint32_t nsid,
2537 : struct spdk_nvme_format *format);
2538 :
2539 : /**
2540 : * Download a new firmware image.
2541 : *
2542 : * This function is thread safe and can be called at any point after spdk_nvme_probe().
2543 : *
2544 : * \param ctrlr NVMe controller to perform firmware operation on.
2545 : * \param payload The data buffer for the firmware image.
2546 : * \param size The data size will be downloaded.
2547 : * \param slot The slot that the firmware image will be committed to.
2548 : * \param commit_action The action to perform when firmware is committed.
2549 : * \param completion_status output parameter. Contains the completion status of
2550 : * the firmware commit operation.
2551 : *
2552 : * \return 0 if successfully submitted, ENOMEM if resources could not be allocated
2553 : * for this request, -1 if the size is not multiple of 4.
2554 : */
2555 : int spdk_nvme_ctrlr_update_firmware(struct spdk_nvme_ctrlr *ctrlr, void *payload, uint32_t size,
2556 : int slot, enum spdk_nvme_fw_commit_action commit_action,
2557 : struct spdk_nvme_status *completion_status);
2558 :
2559 : /**
2560 : * Start the Read from a Boot Partition.
2561 : *
2562 : * This function is thread safe and can be called at any point after spdk_nvme_probe().
2563 : *
2564 : * \param ctrlr NVMe controller to perform the Boot Partition read.
2565 : * \param payload The data buffer for Boot Partition read.
2566 : * \param bprsz Read size in multiples of 4 KiB to copy into the Boot Partition Memory Buffer.
2567 : * \param bprof Boot Partition offset to read from in 4 KiB units.
2568 : * \param bpid Boot Partition identifier for the Boot Partition read operation.
2569 : *
2570 : * \return 0 if Boot Partition read is successful. Negated errno on the following error conditions:
2571 : * -ENOMEM: if resources could not be allocated.
2572 : * -ENOTSUP: Boot Partition is not supported by the Controller.
2573 : * -EIO: Registers access failure.
2574 : * -EINVAL: Parameters are invalid.
2575 : * -EFAULT: Invalid address was specified as part of payload.
2576 : * -EALREADY: Boot Partition read already initiated.
2577 : */
2578 : int spdk_nvme_ctrlr_read_boot_partition_start(struct spdk_nvme_ctrlr *ctrlr, void *payload,
2579 : uint32_t bprsz, uint32_t bprof, uint32_t bpid);
2580 :
2581 : /**
2582 : * Poll the status of the Read from a Boot Partition.
2583 : *
2584 : * This function is thread safe and can be called at any point after spdk_nvme_probe().
2585 : *
2586 : * \param ctrlr NVMe controller to perform the Boot Partition read.
2587 : *
2588 : * \return 0 if Boot Partition read is successful. Negated errno on the following error conditions:
2589 : * -EIO: Registers access failure.
2590 : * -EINVAL: Invalid read status or the Boot Partition read is not initiated yet.
2591 : * -EAGAIN: If the read is still in progress; users must call
2592 : * spdk_nvme_ctrlr_read_boot_partition_poll again to check the read status.
2593 : */
2594 : int spdk_nvme_ctrlr_read_boot_partition_poll(struct spdk_nvme_ctrlr *ctrlr);
2595 :
2596 : /**
2597 : * Write to a Boot Partition.
2598 : *
2599 : * This function is thread safe and can be called at any point after spdk_nvme_probe().
2600 : * Users will get the completion after the data is downloaded, image is replaced and
2601 : * Boot Partition is activated or when the sequence encounters an error.
2602 : *
2603 : * \param ctrlr NVMe controller to perform the Boot Partition write.
2604 : * \param payload The data buffer for Boot Partition write.
2605 : * \param size Data size to write to the Boot Partition.
2606 : * \param bpid Boot Partition identifier for the Boot Partition write operation.
2607 : * \param cb_fn Callback function to invoke when the operation is completed.
2608 : * \param cb_arg Argument to pass to the callback function.
2609 : *
2610 : * \return 0 if Boot Partition write submit is successful. Negated errno on the following error conditions:
2611 : * -ENOMEM: if resources could not be allocated.
2612 : * -ENOTSUP: Boot Partition is not supported by the Controller.
2613 : * -EIO: Registers access failure.
2614 : * -EINVAL: Parameters are invalid.
2615 : */
2616 : int spdk_nvme_ctrlr_write_boot_partition(struct spdk_nvme_ctrlr *ctrlr, void *payload,
2617 : uint32_t size, uint32_t bpid, spdk_nvme_cmd_cb cb_fn, void *cb_arg);
2618 :
2619 : /**
2620 : * Return virtual address of PCIe NVM I/O registers
2621 : *
2622 : * This function returns a pointer to the PCIe I/O registers for a controller
2623 : * or NULL if unsupported for this transport.
2624 : *
2625 : * \param ctrlr Controller whose registers are to be accessed.
2626 : *
2627 : * \return Pointer to virtual address of register bank, or NULL.
2628 : */
2629 : volatile struct spdk_nvme_registers *spdk_nvme_ctrlr_get_registers(struct spdk_nvme_ctrlr *ctrlr);
2630 :
2631 : /**
2632 : * Reserve the controller memory buffer for data transfer use.
2633 : *
2634 : * This function reserves the full size of the controller memory buffer
2635 : * for use in data transfers. If submission queues or completion queues are
2636 : * already placed in the controller memory buffer, this call will fail.
2637 : *
2638 : * \param ctrlr Controller from which to allocate memory buffer
2639 : *
2640 : * \return The size of the controller memory buffer on success. Negated errno
2641 : * on failure.
2642 : */
2643 : int spdk_nvme_ctrlr_reserve_cmb(struct spdk_nvme_ctrlr *ctrlr);
2644 :
2645 : /**
2646 : * Map a previously reserved controller memory buffer so that it's data is
2647 : * visible from the CPU. This operation is not always possible.
2648 : *
2649 : * \param ctrlr Controller that contains the memory buffer
2650 : * \param size Size of buffer that was mapped.
2651 : *
2652 : * \return Pointer to controller memory buffer, or NULL on failure.
2653 : */
2654 : void *spdk_nvme_ctrlr_map_cmb(struct spdk_nvme_ctrlr *ctrlr, size_t *size);
2655 :
2656 : /**
2657 : * Free a controller memory I/O buffer.
2658 : *
2659 : * \param ctrlr Controller from which to unmap the memory buffer.
2660 : */
2661 : void spdk_nvme_ctrlr_unmap_cmb(struct spdk_nvme_ctrlr *ctrlr);
2662 :
2663 : /**
2664 : * Enable the Persistent Memory Region
2665 : *
2666 : * \param ctrlr Controller that contains the Persistent Memory Region
2667 : *
2668 : * \return 0 on success. Negated errno on the following error conditions:
2669 : * -ENOTSUP: PMR is not supported by the Controller.
2670 : * -EIO: Registers access failure.
2671 : * -EINVAL: PMR Time Units Invalid or PMR is already enabled.
2672 : * -ETIMEDOUT: Timed out to Enable PMR.
2673 : * -ENOSYS: Transport does not support Enable PMR function.
2674 : */
2675 : int spdk_nvme_ctrlr_enable_pmr(struct spdk_nvme_ctrlr *ctrlr);
2676 :
2677 : /**
2678 : * Disable the Persistent Memory Region
2679 : *
2680 : * \param ctrlr Controller that contains the Persistent Memory Region
2681 : *
2682 : * \return 0 on success. Negated errno on the following error conditions:
2683 : * -ENOTSUP: PMR is not supported by the Controller.
2684 : * -EIO: Registers access failure.
2685 : * -EINVAL: PMR Time Units Invalid or PMR is already disabled.
2686 : * -ETIMEDOUT: Timed out to Disable PMR.
2687 : * -ENOSYS: Transport does not support Disable PMR function.
2688 : */
2689 : int spdk_nvme_ctrlr_disable_pmr(struct spdk_nvme_ctrlr *ctrlr);
2690 :
2691 : /**
2692 : * Map the Persistent Memory Region so that it's data is
2693 : * visible from the CPU.
2694 : *
2695 : * \param ctrlr Controller that contains the Persistent Memory Region
2696 : * \param size Size of the region that was mapped.
2697 : *
2698 : * \return Pointer to Persistent Memory Region, or NULL on failure.
2699 : */
2700 : void *spdk_nvme_ctrlr_map_pmr(struct spdk_nvme_ctrlr *ctrlr, size_t *size);
2701 :
2702 : /**
2703 : * Free the Persistent Memory Region.
2704 : *
2705 : * \param ctrlr Controller from which to unmap the Persistent Memory Region.
2706 : *
2707 : * \return 0 on success, negative errno on failure.
2708 : * -ENXIO: Either PMR is not supported by the Controller or the PMR is already unmapped.
2709 : * -ENOSYS: Transport does not support Unmap PMR function.
2710 : */
2711 : int spdk_nvme_ctrlr_unmap_pmr(struct spdk_nvme_ctrlr *ctrlr);
2712 :
2713 : /**
2714 : * Get the transport ID for a given NVMe controller.
2715 : *
2716 : * \param ctrlr Controller to get the transport ID.
2717 : * \return Pointer to the controller's transport ID.
2718 : */
2719 : const struct spdk_nvme_transport_id *spdk_nvme_ctrlr_get_transport_id(
2720 : struct spdk_nvme_ctrlr *ctrlr);
2721 :
2722 : /**
2723 : * \brief Alloc NVMe I/O queue identifier.
2724 : *
2725 : * This function is only needed for the non-standard case of allocating queues using the raw
2726 : * command interface. In most cases \ref spdk_nvme_ctrlr_alloc_io_qpair should be sufficient.
2727 : *
2728 : * \param ctrlr Opaque handle to NVMe controller.
2729 : * \return qid on success, -1 on failure.
2730 : */
2731 : int32_t spdk_nvme_ctrlr_alloc_qid(struct spdk_nvme_ctrlr *ctrlr);
2732 :
2733 : /**
2734 : * \brief Free NVMe I/O queue identifier.
2735 : *
2736 : * This function must only be called with qids previously allocated with \ref spdk_nvme_ctrlr_alloc_qid.
2737 : *
2738 : * \param ctrlr Opaque handle to NVMe controller.
2739 : * \param qid NVMe Queue Identifier.
2740 : */
2741 : void spdk_nvme_ctrlr_free_qid(struct spdk_nvme_ctrlr *ctrlr, uint16_t qid);
2742 :
2743 : /**
2744 : * Opaque handle for a poll group. A poll group is a collection of spdk_nvme_qpair
2745 : * objects that are polled for completions as a unit.
2746 : *
2747 : * Returned by spdk_nvme_poll_group_create().
2748 : */
2749 : struct spdk_nvme_poll_group;
2750 :
2751 :
2752 : /**
2753 : * This function alerts the user to disconnected qpairs when calling
2754 : * spdk_nvme_poll_group_process_completions.
2755 : */
2756 : typedef void (*spdk_nvme_disconnected_qpair_cb)(struct spdk_nvme_qpair *qpair,
2757 : void *poll_group_ctx);
2758 :
2759 : /**
2760 : * Create a new poll group.
2761 : *
2762 : * \param ctx A user supplied context that can be retrieved later with spdk_nvme_poll_group_get_ctx
2763 : * \param table The call back table defined by users which contains the accelerated functions
2764 : * which can be used to accelerate some operations such as crc32c.
2765 : *
2766 : * \return Pointer to the new poll group, or NULL on error.
2767 : */
2768 : struct spdk_nvme_poll_group *spdk_nvme_poll_group_create(void *ctx,
2769 : struct spdk_nvme_accel_fn_table *table);
2770 :
2771 : /**
2772 : * Get a optimal poll group.
2773 : *
2774 : * \param qpair The qpair to get the optimal poll group.
2775 : *
2776 : * \return Pointer to the optimal poll group, or NULL if not found.
2777 : */
2778 : struct spdk_nvme_poll_group *spdk_nvme_qpair_get_optimal_poll_group(struct spdk_nvme_qpair *qpair);
2779 :
2780 : /**
2781 : * Add an spdk_nvme_qpair to a poll group. qpairs may only be added to
2782 : * a poll group if they are in the disconnected state; i.e. either they were
2783 : * just allocated and not yet connected or they have been disconnected with a call
2784 : * to spdk_nvme_ctrlr_disconnect_io_qpair.
2785 : *
2786 : * \param group The group to which the qpair will be added.
2787 : * \param qpair The qpair to add to the poll group.
2788 : *
2789 : * return 0 on success, -EINVAL if the qpair is not in the disabled state, -ENODEV if the transport
2790 : * doesn't exist, -ENOMEM on memory allocation failures, or -EPROTO on a protocol (transport) specific failure.
2791 : */
2792 : int spdk_nvme_poll_group_add(struct spdk_nvme_poll_group *group, struct spdk_nvme_qpair *qpair);
2793 :
2794 : /**
2795 : * Remove a disconnected spdk_nvme_qpair from a poll group.
2796 : *
2797 : * \param group The group from which to remove the qpair.
2798 : * \param qpair The qpair to remove from the poll group.
2799 : *
2800 : * return 0 on success, -ENOENT if the qpair is not found in the group, -EINVAL if the qpair is not
2801 : * disconnected in the group, or -EPROTO on a protocol (transport) specific failure.
2802 : */
2803 : int spdk_nvme_poll_group_remove(struct spdk_nvme_poll_group *group, struct spdk_nvme_qpair *qpair);
2804 :
2805 : /**
2806 : * Destroy an empty poll group.
2807 : *
2808 : * \param group The group to destroy.
2809 : *
2810 : * return 0 on success, -EBUSY if the poll group is not empty.
2811 : */
2812 : int spdk_nvme_poll_group_destroy(struct spdk_nvme_poll_group *group);
2813 :
2814 : /**
2815 : * Poll for completions on all qpairs in this poll group.
2816 : *
2817 : * the disconnected_qpair_cb will be called for all disconnected qpairs in the poll group
2818 : * including qpairs which fail within the context of this call.
2819 : * The user is responsible for trying to reconnect or destroy those qpairs.
2820 : *
2821 : * \param group The group on which to poll for completions.
2822 : * \param completions_per_qpair The maximum number of completions per qpair.
2823 : * \param disconnected_qpair_cb A callback function of type spdk_nvme_disconnected_qpair_cb. Must be non-NULL.
2824 : *
2825 : * return The number of completions across all qpairs, -EINVAL if no disconnected_qpair_cb is passed, or
2826 : * -EIO if the shared completion queue cannot be polled for the RDMA transport.
2827 : */
2828 : int64_t spdk_nvme_poll_group_process_completions(struct spdk_nvme_poll_group *group,
2829 : uint32_t completions_per_qpair, spdk_nvme_disconnected_qpair_cb disconnected_qpair_cb);
2830 :
2831 : /**
2832 : * Check if all qpairs in the poll group are connected.
2833 : *
2834 : * This function allows the caller to check if all qpairs in a poll group are
2835 : * connected. This API is generally only suitable during application startup,
2836 : * to check when a large number of async connections have completed.
2837 : *
2838 : * It is useful for applications like benchmarking tools to create
2839 : * a large number of qpairs, but then ensuring they are all fully connected before
2840 : * proceeding with I/O.
2841 : *
2842 : * \param group The group on which to poll connecting qpairs.
2843 : *
2844 : * return 0 if all qpairs are in CONNECTED state, -EIO if any connections failed to connect, -EAGAIN if
2845 : * any qpairs are still trying to connected.
2846 : */
2847 : int spdk_nvme_poll_group_all_connected(struct spdk_nvme_poll_group *group);
2848 :
2849 : /**
2850 : * Retrieve the user context for this specific poll group.
2851 : *
2852 : * \param group The poll group from which to retrieve the context.
2853 : *
2854 : * \return A pointer to the user provided poll group context.
2855 : */
2856 : void *spdk_nvme_poll_group_get_ctx(struct spdk_nvme_poll_group *group);
2857 :
2858 : /**
2859 : * Retrieves transport statistics for the given poll group.
2860 : *
2861 : * Note: the structure returned by this function should later be freed with
2862 : * @b spdk_nvme_poll_group_free_stats function
2863 : *
2864 : * \param group Pointer to NVME poll group
2865 : * \param stats Double pointer to statistics to be filled by this function
2866 : * \return 0 on success or negated errno on failure
2867 : */
2868 : int spdk_nvme_poll_group_get_stats(struct spdk_nvme_poll_group *group,
2869 : struct spdk_nvme_poll_group_stat **stats);
2870 :
2871 : /**
2872 : * Frees poll group statistics retrieved using @b spdk_nvme_poll_group_get_stats function
2873 : *
2874 : * @param group Pointer to a poll group
2875 : * @param stat Pointer to statistics to be released
2876 : */
2877 : void spdk_nvme_poll_group_free_stats(struct spdk_nvme_poll_group *group,
2878 : struct spdk_nvme_poll_group_stat *stat);
2879 :
2880 : /**
2881 : * Get the identify namespace data as defined by the NVMe specification.
2882 : *
2883 : * This function is thread safe and can be called at any point while the controller
2884 : * is attached to the SPDK NVMe driver.
2885 : *
2886 : * \param ns Namespace.
2887 : *
2888 : * \return a pointer to the namespace data.
2889 : */
2890 : const struct spdk_nvme_ns_data *spdk_nvme_ns_get_data(struct spdk_nvme_ns *ns);
2891 :
2892 : /**
2893 : * Get the I/O command set specific identify namespace data for NVM command set
2894 : * as defined by the NVMe specification.
2895 : *
2896 : * This function is thread safe and can be called at any point while the controller
2897 : * is attached to the SPDK NVMe driver.
2898 : *
2899 : * \param ns Namespace.
2900 : *
2901 : * \return a pointer to the identify namespace data.
2902 : */
2903 : const struct spdk_nvme_nvm_ns_data *spdk_nvme_nvm_ns_get_data(struct spdk_nvme_ns *ns);
2904 :
2905 : /**
2906 : * Get the namespace id (index number) from the given namespace handle.
2907 : *
2908 : * This function is thread safe and can be called at any point while the controller
2909 : * is attached to the SPDK NVMe driver.
2910 : *
2911 : * \param ns Namespace.
2912 : *
2913 : * \return namespace id.
2914 : */
2915 : uint32_t spdk_nvme_ns_get_id(struct spdk_nvme_ns *ns);
2916 :
2917 : /**
2918 : * Get the controller with which this namespace is associated.
2919 : *
2920 : * This function is thread safe and can be called at any point while the controller
2921 : * is attached to the SPDK NVMe driver.
2922 : *
2923 : * \param ns Namespace.
2924 : *
2925 : * \return a pointer to the controller.
2926 : */
2927 : struct spdk_nvme_ctrlr *spdk_nvme_ns_get_ctrlr(struct spdk_nvme_ns *ns);
2928 :
2929 : /**
2930 : * Determine whether a namespace is active.
2931 : *
2932 : * Inactive namespaces cannot be the target of I/O commands.
2933 : *
2934 : * \param ns Namespace to query.
2935 : *
2936 : * \return true if active, or false if inactive.
2937 : */
2938 : bool spdk_nvme_ns_is_active(struct spdk_nvme_ns *ns);
2939 :
2940 : /**
2941 : * Get the maximum transfer size, in bytes, for an I/O sent to the given namespace.
2942 : *
2943 : * This function is thread safe and can be called at any point while the controller
2944 : * is attached to the SPDK NVMe driver.
2945 : *
2946 : * \param ns Namespace to query.
2947 : *
2948 : * \return the maximum transfer size in bytes.
2949 : */
2950 : uint32_t spdk_nvme_ns_get_max_io_xfer_size(struct spdk_nvme_ns *ns);
2951 :
2952 : /**
2953 : * Get the sector size, in bytes, of the given namespace.
2954 : *
2955 : * This function returns the size of the data sector only. It does not
2956 : * include metadata size.
2957 : *
2958 : * This function is thread safe and can be called at any point while the controller
2959 : * is attached to the SPDK NVMe driver.
2960 : *
2961 : * \param ns Namespace to query.
2962 : *
2963 : * /return the sector size in bytes.
2964 : */
2965 : uint32_t spdk_nvme_ns_get_sector_size(struct spdk_nvme_ns *ns);
2966 :
2967 : /**
2968 : * Get the extended sector size, in bytes, of the given namespace.
2969 : *
2970 : * This function returns the size of the data sector plus metadata.
2971 : *
2972 : * This function is thread safe and can be called at any point while the controller
2973 : * is attached to the SPDK NVMe driver.
2974 : *
2975 : * \param ns Namespace to query.
2976 : *
2977 : * /return the extended sector size in bytes.
2978 : */
2979 : uint32_t spdk_nvme_ns_get_extended_sector_size(struct spdk_nvme_ns *ns);
2980 :
2981 : /**
2982 : * Get the number of sectors for the given namespace.
2983 : *
2984 : * This function is thread safe and can be called at any point while the controller
2985 : * is attached to the SPDK NVMe driver.
2986 : *
2987 : * \param ns Namespace to query.
2988 : *
2989 : * \return the number of sectors.
2990 : */
2991 : uint64_t spdk_nvme_ns_get_num_sectors(struct spdk_nvme_ns *ns);
2992 :
2993 : /**
2994 : * Get the size, in bytes, of the given namespace.
2995 : *
2996 : * This function is thread safe and can be called at any point while the controller
2997 : * is attached to the SPDK NVMe driver.
2998 : *
2999 : * \param ns Namespace to query.
3000 : *
3001 : * \return the size of the given namespace in bytes.
3002 : */
3003 : uint64_t spdk_nvme_ns_get_size(struct spdk_nvme_ns *ns);
3004 :
3005 : /**
3006 : * Get the end-to-end data protection information type of the given namespace.
3007 : *
3008 : * This function is thread safe and can be called at any point while the controller
3009 : * is attached to the SPDK NVMe driver.
3010 : *
3011 : * \param ns Namespace to query.
3012 : *
3013 : * \return the end-to-end data protection information type.
3014 : */
3015 : enum spdk_nvme_pi_type spdk_nvme_ns_get_pi_type(struct spdk_nvme_ns *ns);
3016 :
3017 : /**
3018 : * Get the end-to-end data protection information format of the given namespace.
3019 : *
3020 : * This function is thread safe and can be called at any point while the controller
3021 : * is attached to the SPDK NVMe driver.
3022 : *
3023 : * \param ns Namespace to query.
3024 : *
3025 : * \return the end-to-end data protection information format.
3026 : */
3027 : enum spdk_nvme_pi_format spdk_nvme_ns_get_pi_format(struct spdk_nvme_ns *ns);
3028 :
3029 : /**
3030 : * Get the metadata size, in bytes, of the given namespace.
3031 : *
3032 : * This function is thread safe and can be called at any point while the controller
3033 : * is attached to the SPDK NVMe driver.
3034 : *
3035 : * \param ns Namespace to query.
3036 : *
3037 : * \return the metadata size of the given namespace in bytes.
3038 : */
3039 : uint32_t spdk_nvme_ns_get_md_size(struct spdk_nvme_ns *ns);
3040 :
3041 : /**
3042 : * Get the format index of the given namespace.
3043 : *
3044 : * This function is thread safe and can be called at any point while the controller
3045 : * is attached to the SPDK NVMe driver.
3046 : *
3047 : * \param nsdata pointer to the NVMe namespace data.
3048 : *
3049 : * \return the format index of the given namespace.
3050 : */
3051 : uint32_t spdk_nvme_ns_get_format_index(const struct spdk_nvme_ns_data *nsdata);
3052 :
3053 : /**
3054 : * Check whether if the namespace can support extended LBA when end-to-end data
3055 : * protection enabled.
3056 : *
3057 : * This function is thread safe and can be called at any point while the controller
3058 : * is attached to the SPDK NVMe driver.
3059 : *
3060 : * \param ns Namespace to query.
3061 : *
3062 : * \return true if the namespace can support extended LBA when end-to-end data
3063 : * protection enabled, or false otherwise.
3064 : */
3065 : bool spdk_nvme_ns_supports_extended_lba(struct spdk_nvme_ns *ns);
3066 :
3067 : /**
3068 : * Check whether if the namespace supports compare operation
3069 : *
3070 : * This function is thread safe and can be called at any point while the controller
3071 : * is attached to the SPDK NVMe driver.
3072 : *
3073 : * \param ns Namespace to query.
3074 : *
3075 : * \return true if the namespace supports compare operation, or false otherwise.
3076 : */
3077 : bool spdk_nvme_ns_supports_compare(struct spdk_nvme_ns *ns);
3078 :
3079 : /**
3080 : * Determine the value returned when reading deallocated blocks.
3081 : *
3082 : * If deallocated blocks return 0, the deallocate command can be used as a more
3083 : * efficient alternative to the write_zeroes command, especially for large requests.
3084 : *
3085 : * \param ns Namespace.
3086 : *
3087 : * \return the logical block read value.
3088 : */
3089 : enum spdk_nvme_dealloc_logical_block_read_value spdk_nvme_ns_get_dealloc_logical_block_read_value(
3090 : struct spdk_nvme_ns *ns);
3091 :
3092 : /**
3093 : * Get the optimal I/O boundary, in blocks, for the given namespace.
3094 : *
3095 : * Read and write commands should not cross the optimal I/O boundary for best
3096 : * performance.
3097 : *
3098 : * \param ns Namespace to query.
3099 : *
3100 : * \return Optimal granularity of I/O commands, in blocks, or 0 if no optimal
3101 : * granularity is reported.
3102 : */
3103 : uint32_t spdk_nvme_ns_get_optimal_io_boundary(struct spdk_nvme_ns *ns);
3104 :
3105 : /**
3106 : * Get the NGUID for the given namespace.
3107 : *
3108 : * \param ns Namespace to query.
3109 : *
3110 : * \return a pointer to namespace NGUID, or NULL if ns does not have a NGUID.
3111 : */
3112 : const uint8_t *spdk_nvme_ns_get_nguid(const struct spdk_nvme_ns *ns);
3113 :
3114 : /**
3115 : * Get the UUID for the given namespace.
3116 : *
3117 : * \param ns Namespace to query.
3118 : *
3119 : * \return a pointer to namespace UUID, or NULL if ns does not have a UUID.
3120 : */
3121 : const struct spdk_uuid *spdk_nvme_ns_get_uuid(const struct spdk_nvme_ns *ns);
3122 :
3123 : /**
3124 : * Get the Command Set Identifier for the given namespace.
3125 : *
3126 : * \param ns Namespace to query.
3127 : *
3128 : * \return the namespace Command Set Identifier.
3129 : */
3130 : enum spdk_nvme_csi spdk_nvme_ns_get_csi(const struct spdk_nvme_ns *ns);
3131 :
3132 : /**
3133 : * \brief Namespace command support flags.
3134 : */
3135 : enum spdk_nvme_ns_flags {
3136 : SPDK_NVME_NS_DEALLOCATE_SUPPORTED = 1 << 0, /**< The deallocate command is supported */
3137 : SPDK_NVME_NS_FLUSH_SUPPORTED = 1 << 1, /**< The flush command is supported */
3138 : SPDK_NVME_NS_RESERVATION_SUPPORTED = 1 << 2, /**< The reservation command is supported */
3139 : SPDK_NVME_NS_WRITE_ZEROES_SUPPORTED = 1 << 3, /**< The write zeroes command is supported */
3140 : SPDK_NVME_NS_DPS_PI_SUPPORTED = 1 << 4, /**< The end-to-end data protection is supported */
3141 : SPDK_NVME_NS_EXTENDED_LBA_SUPPORTED = 1 << 5, /**< The extended lba format is supported,
3142 : metadata is transferred as a contiguous
3143 : part of the logical block that it is associated with */
3144 : SPDK_NVME_NS_WRITE_UNCORRECTABLE_SUPPORTED = 1 << 6, /**< The write uncorrectable command is supported */
3145 : SPDK_NVME_NS_COMPARE_SUPPORTED = 1 << 7, /**< The compare command is supported */
3146 : };
3147 :
3148 : /**
3149 : * Get the flags for the given namespace.
3150 : *
3151 : * See spdk_nvme_ns_flags for the possible flags returned.
3152 : *
3153 : * This function is thread safe and can be called at any point while the controller
3154 : * is attached to the SPDK NVMe driver.
3155 : *
3156 : * \param ns Namespace to query.
3157 : *
3158 : * \return the flags for the given namespace.
3159 : */
3160 : uint32_t spdk_nvme_ns_get_flags(struct spdk_nvme_ns *ns);
3161 :
3162 : /**
3163 : * Get the ANA group ID for the given namespace.
3164 : *
3165 : * This function should be called only if spdk_nvme_ctrlr_is_log_page_supported() returns
3166 : * true for the controller and log page ID SPDK_NVME_LOG_ASYMMETRIC_NAMESPACE_ACCESS.
3167 : *
3168 : * This function is thread safe and can be called at any point while the controller
3169 : * is attached to the SPDK NVMe driver.
3170 : *
3171 : * \param ns Namespace to query.
3172 : *
3173 : * \return the ANA group ID for the given namespace.
3174 : */
3175 : uint32_t spdk_nvme_ns_get_ana_group_id(const struct spdk_nvme_ns *ns);
3176 :
3177 : /**
3178 : * Get the ANA state for the given namespace.
3179 : *
3180 : * This function should be called only if spdk_nvme_ctrlr_is_log_page_supported() returns
3181 : * true for the controller and log page ID SPDK_NVME_LOG_ASYMMETRIC_NAMESPACE_ACCESS.
3182 : *
3183 : * This function is thread safe and can be called at any point while the controller
3184 : * is attached to the SPDK NVMe driver.
3185 : *
3186 : * \param ns Namespace to query.
3187 : *
3188 : * \return the ANA state for the given namespace.
3189 : */
3190 : enum spdk_nvme_ana_state spdk_nvme_ns_get_ana_state(const struct spdk_nvme_ns *ns);
3191 :
3192 : /**
3193 : * Submit a write I/O to the specified NVMe namespace.
3194 : *
3195 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3196 : * The user must ensure that only one thread submits I/O on a given qpair at any
3197 : * given time.
3198 : *
3199 : * \param ns NVMe namespace to submit the write I/O.
3200 : * \param qpair I/O queue pair to submit the request.
3201 : * \param payload Virtual address pointer to the data payload.
3202 : * \param lba Starting LBA to write the data.
3203 : * \param lba_count Length (in sectors) for the write operation.
3204 : * \param cb_fn Callback function to invoke when the I/O is completed.
3205 : * \param cb_arg Argument to pass to the callback function.
3206 : * \param io_flags Set flags, defined by the SPDK_NVME_IO_FLAGS_* entries in
3207 : * spdk/nvme_spec.h, for this I/O.
3208 : *
3209 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3210 : * -EINVAL: The request is malformed.
3211 : * -ENOMEM: The request cannot be allocated.
3212 : * -ENXIO: The qpair is failed at the transport level.
3213 : */
3214 : int spdk_nvme_ns_cmd_write(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair, void *payload,
3215 : uint64_t lba, uint32_t lba_count, spdk_nvme_cmd_cb cb_fn,
3216 : void *cb_arg, uint32_t io_flags);
3217 :
3218 : /**
3219 : * Submit a write I/O to the specified NVMe namespace.
3220 : *
3221 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3222 : * The user must ensure that only one thread submits I/O on a given qpair at any
3223 : * given time.
3224 : *
3225 : * \param ns NVMe namespace to submit the write I/O.
3226 : * \param qpair I/O queue pair to submit the request.
3227 : * \param lba Starting LBA to write the data.
3228 : * \param lba_count Length (in sectors) for the write operation.
3229 : * \param cb_fn Callback function to invoke when the I/O is completed.
3230 : * \param cb_arg Argument to pass to the callback function.
3231 : * \param io_flags Set flags, defined in nvme_spec.h, for this I/O.
3232 : * \param reset_sgl_fn Callback function to reset scattered payload.
3233 : * \param next_sge_fn Callback function to iterate each scattered payload memory
3234 : * segment.
3235 : *
3236 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3237 : * -EINVAL: The request is malformed.
3238 : * -ENOMEM: The request cannot be allocated.
3239 : * -ENXIO: The qpair is failed at the transport level.
3240 : */
3241 : int spdk_nvme_ns_cmd_writev(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
3242 : uint64_t lba, uint32_t lba_count,
3243 : spdk_nvme_cmd_cb cb_fn, void *cb_arg, uint32_t io_flags,
3244 : spdk_nvme_req_reset_sgl_cb reset_sgl_fn,
3245 : spdk_nvme_req_next_sge_cb next_sge_fn);
3246 :
3247 : /**
3248 : * Submit a write I/O to the specified NVMe namespace.
3249 : *
3250 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3251 : * The user must ensure that only one thread submits I/O on a given qpair at any
3252 : * given time.
3253 : *
3254 : * \param ns NVMe namespace to submit the write I/O
3255 : * \param qpair I/O queue pair to submit the request
3256 : * \param lba starting LBA to write the data
3257 : * \param lba_count length (in sectors) for the write operation
3258 : * \param cb_fn callback function to invoke when the I/O is completed
3259 : * \param cb_arg argument to pass to the callback function
3260 : * \param io_flags set flags, defined in nvme_spec.h, for this I/O
3261 : * \param reset_sgl_fn callback function to reset scattered payload
3262 : * \param next_sge_fn callback function to iterate each scattered
3263 : * payload memory segment
3264 : * \param metadata virtual address pointer to the metadata payload, the length
3265 : * of metadata is specified by spdk_nvme_ns_get_md_size()
3266 : * \param apptag_mask application tag mask.
3267 : * \param apptag application tag to use end-to-end protection information.
3268 : *
3269 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3270 : * -EINVAL: The request is malformed.
3271 : * -ENOMEM: The request cannot be allocated.
3272 : * -ENXIO: The qpair is failed at the transport level.
3273 : */
3274 : int spdk_nvme_ns_cmd_writev_with_md(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
3275 : uint64_t lba, uint32_t lba_count,
3276 : spdk_nvme_cmd_cb cb_fn, void *cb_arg, uint32_t io_flags,
3277 : spdk_nvme_req_reset_sgl_cb reset_sgl_fn,
3278 : spdk_nvme_req_next_sge_cb next_sge_fn, void *metadata,
3279 : uint16_t apptag_mask, uint16_t apptag);
3280 :
3281 : /**
3282 : * Submit a write I/O to the specified NVMe namespace.
3283 : *
3284 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3285 : * The user must ensure that only one thread submits I/O on a given qpair at any
3286 : * given time.
3287 : *
3288 : * \param ns NVMe namespace to submit the write I/O
3289 : * \param qpair I/O queue pair to submit the request
3290 : * \param lba starting LBA to write the data
3291 : * \param lba_count length (in sectors) for the write operation
3292 : * \param cb_fn callback function to invoke when the I/O is completed
3293 : * \param cb_arg argument to pass to the callback function
3294 : * \param reset_sgl_fn callback function to reset scattered payload
3295 : * \param next_sge_fn callback function to iterate each scattered
3296 : * payload memory segment
3297 : * \param opts Optional structure with extended IO request options. If provided, the caller must
3298 : * guarantee that this structure is accessible until IO completes
3299 : *
3300 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3301 : * -EINVAL: The request is malformed.
3302 : * -ENOMEM: The request cannot be allocated.
3303 : * -ENXIO: The qpair is failed at the transport level.
3304 : * -EFAULT: Invalid address was specified as part of payload. cb_fn is also called
3305 : * with error status including dnr=1 in this case.
3306 : */
3307 : int spdk_nvme_ns_cmd_writev_ext(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
3308 : uint64_t lba, uint32_t lba_count,
3309 : spdk_nvme_cmd_cb cb_fn, void *cb_arg,
3310 : spdk_nvme_req_reset_sgl_cb reset_sgl_fn,
3311 : spdk_nvme_req_next_sge_cb next_sge_fn,
3312 : struct spdk_nvme_ns_cmd_ext_io_opts *opts);
3313 :
3314 : /**
3315 : * Submit a write I/O to the specified NVMe namespace.
3316 : *
3317 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3318 : * The user must ensure that only one thread submits I/O on a given qpair at any
3319 : * given time.
3320 : *
3321 : * \param ns NVMe namespace to submit the write I/O
3322 : * \param qpair I/O queue pair to submit the request
3323 : * \param payload Virtual address pointer to the data payload.
3324 : * \param lba starting LBA to write the data
3325 : * \param lba_count length (in sectors) for the write operation
3326 : * \param cb_fn callback function to invoke when the I/O is completed
3327 : * \param cb_arg argument to pass to the callback function
3328 : * \param opts Optional structure with extended IO request options. If provided, the caller must
3329 : * guarantee that this structure is accessible until IO completes
3330 : *
3331 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3332 : * -EINVAL: The request is malformed.
3333 : * -ENOMEM: The request cannot be allocated.
3334 : * -ENXIO: The qpair is failed at the transport level.
3335 : * -EFAULT: Invalid address was specified as part of payload. cb_fn is also called
3336 : * with error status including dnr=1 in this case.
3337 : */
3338 : int spdk_nvme_ns_cmd_write_ext(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
3339 : void *payload, uint64_t lba, uint32_t lba_count, spdk_nvme_cmd_cb cb_fn, void *cb_arg,
3340 : struct spdk_nvme_ns_cmd_ext_io_opts *opts);
3341 :
3342 : /**
3343 : * Submit a write I/O to the specified NVMe namespace.
3344 : *
3345 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3346 : * The user must ensure that only one thread submits I/O on a given qpair at any
3347 : * given time.
3348 : *
3349 : * \param ns NVMe namespace to submit the write I/O.
3350 : * \param qpair I/O queue pair to submit the request.
3351 : * \param payload Virtual address pointer to the data payload.
3352 : * \param metadata Virtual address pointer to the metadata payload, the length
3353 : * of metadata is specified by spdk_nvme_ns_get_md_size().
3354 : * \param lba Starting LBA to write the data.
3355 : * \param lba_count Length (in sectors) for the write operation.
3356 : * \param cb_fn Callback function to invoke when the I/O is completed.
3357 : * \param cb_arg Argument to pass to the callback function.
3358 : * \param io_flags Set flags, defined by the SPDK_NVME_IO_FLAGS_* entries in
3359 : * spdk/nvme_spec.h, for this I/O.
3360 : * \param apptag_mask Application tag mask.
3361 : * \param apptag Application tag to use end-to-end protection information.
3362 : *
3363 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3364 : * -EINVAL: The request is malformed.
3365 : * -ENOMEM: The request cannot be allocated.
3366 : * -ENXIO: The qpair is failed at the transport level.
3367 : */
3368 : int spdk_nvme_ns_cmd_write_with_md(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
3369 : void *payload, void *metadata,
3370 : uint64_t lba, uint32_t lba_count, spdk_nvme_cmd_cb cb_fn,
3371 : void *cb_arg, uint32_t io_flags,
3372 : uint16_t apptag_mask, uint16_t apptag);
3373 :
3374 : /**
3375 : * Submit a write zeroes I/O to the specified NVMe namespace.
3376 : *
3377 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3378 : * The user must ensure that only one thread submits I/O on a given qpair at any
3379 : * given time.
3380 : *
3381 : * \param ns NVMe namespace to submit the write zeroes I/O.
3382 : * \param qpair I/O queue pair to submit the request.
3383 : * \param lba Starting LBA for this command.
3384 : * \param lba_count Length (in sectors) for the write zero operation.
3385 : * \param cb_fn Callback function to invoke when the I/O is completed.
3386 : * \param cb_arg Argument to pass to the callback function.
3387 : * \param io_flags Set flags, defined by the SPDK_NVME_IO_FLAGS_* entries in
3388 : * spdk/nvme_spec.h, for this I/O.
3389 : *
3390 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3391 : * -EINVAL: The request is malformed.
3392 : * -ENOMEM: The request cannot be allocated.
3393 : * -ENXIO: The qpair is failed at the transport level.
3394 : */
3395 : int spdk_nvme_ns_cmd_write_zeroes(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
3396 : uint64_t lba, uint32_t lba_count,
3397 : spdk_nvme_cmd_cb cb_fn, void *cb_arg,
3398 : uint32_t io_flags);
3399 :
3400 : /**
3401 : * Submit a verify I/O to the specified NVMe namespace.
3402 : *
3403 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3404 : * The user must ensure that only one thread submits I/O on a given qpair at any
3405 : * given time.
3406 : *
3407 : * \param ns NVMe namespace to submit the verify I/O.
3408 : * \param qpair I/O queue pair to submit the request.
3409 : * \param lba Starting LBA to verify the data.
3410 : * \param lba_count Length (in sectors) for the verify operation.
3411 : * \param cb_fn Callback function to invoke when the I/O is completed.
3412 : * \param cb_arg Argument to pass to the callback function.
3413 : * \param io_flags Set flags, defined by the SPDK_NVME_IO_FLAGS_* entries in
3414 : * spdk/nvme_spec.h, for this I/O.
3415 : *
3416 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3417 : * -EINVAL: The request is malformed.
3418 : * -ENOMEM: The request cannot be allocated.
3419 : * -ENXIO: The qpair is failed at the transport level.
3420 : */
3421 : int spdk_nvme_ns_cmd_verify(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
3422 : uint64_t lba, uint32_t lba_count,
3423 : spdk_nvme_cmd_cb cb_fn, void *cb_arg,
3424 : uint32_t io_flags);
3425 :
3426 : /**
3427 : * Submit a write uncorrectable I/O to the specified NVMe namespace.
3428 : *
3429 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3430 : * The user must ensure that only one thread submits I/O on a given qpair at any
3431 : * given time.
3432 : *
3433 : * \param ns NVMe namespace to submit the write uncorrectable I/O.
3434 : * \param qpair I/O queue pair to submit the request.
3435 : * \param lba Starting LBA for this command.
3436 : * \param lba_count Length (in sectors) for the write uncorrectable operation.
3437 : * \param cb_fn Callback function to invoke when the I/O is completed.
3438 : * \param cb_arg Argument to pass to the callback function.
3439 : *
3440 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3441 : * -EINVAL: The request is malformed.
3442 : * -ENOMEM: The request cannot be allocated.
3443 : * -ENXIO: The qpair is failed at the transport level.
3444 : */
3445 : int spdk_nvme_ns_cmd_write_uncorrectable(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
3446 : uint64_t lba, uint32_t lba_count,
3447 : spdk_nvme_cmd_cb cb_fn, void *cb_arg);
3448 :
3449 : /**
3450 : * \brief Submits a read I/O to the specified NVMe namespace.
3451 : *
3452 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3453 : * The user must ensure that only one thread submits I/O on a given qpair at any
3454 : * given time.
3455 : *
3456 : * \param ns NVMe namespace to submit the read I/O.
3457 : * \param qpair I/O queue pair to submit the request.
3458 : * \param payload Virtual address pointer to the data payload.
3459 : * \param lba Starting LBA to read the data.
3460 : * \param lba_count Length (in sectors) for the read operation.
3461 : * \param cb_fn Callback function to invoke when the I/O is completed.
3462 : * \param cb_arg Argument to pass to the callback function.
3463 : * \param io_flags Set flags, defined in nvme_spec.h, for this I/O.
3464 : *
3465 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3466 : * -EINVAL: The request is malformed.
3467 : * -ENOMEM: The request cannot be allocated.
3468 : * -ENXIO: The qpair is failed at the transport level.
3469 : */
3470 : int spdk_nvme_ns_cmd_read(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair, void *payload,
3471 : uint64_t lba, uint32_t lba_count, spdk_nvme_cmd_cb cb_fn,
3472 : void *cb_arg, uint32_t io_flags);
3473 :
3474 : /**
3475 : * Submit a read I/O to the specified NVMe namespace.
3476 : *
3477 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3478 : * The user must ensure that only one thread submits I/O on a given qpair at any
3479 : * given time.
3480 : *
3481 : * \param ns NVMe namespace to submit the read I/O.
3482 : * \param qpair I/O queue pair to submit the request.
3483 : * \param lba Starting LBA to read the data.
3484 : * \param lba_count Length (in sectors) for the read operation.
3485 : * \param cb_fn Callback function to invoke when the I/O is completed.
3486 : * \param cb_arg Argument to pass to the callback function.
3487 : * \param io_flags Set flags, defined in nvme_spec.h, for this I/O.
3488 : * \param reset_sgl_fn Callback function to reset scattered payload.
3489 : * \param next_sge_fn Callback function to iterate each scattered payload memory
3490 : * segment.
3491 : *
3492 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3493 : * -EINVAL: The request is malformed.
3494 : * -ENOMEM: The request cannot be allocated.
3495 : * -ENXIO: The qpair is failed at the transport level.
3496 : */
3497 : int spdk_nvme_ns_cmd_readv(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
3498 : uint64_t lba, uint32_t lba_count,
3499 : spdk_nvme_cmd_cb cb_fn, void *cb_arg, uint32_t io_flags,
3500 : spdk_nvme_req_reset_sgl_cb reset_sgl_fn,
3501 : spdk_nvme_req_next_sge_cb next_sge_fn);
3502 :
3503 : /**
3504 : * Submit a read I/O to the specified NVMe namespace.
3505 : *
3506 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3507 : * The user must ensure that only one thread submits I/O on a given qpair at any given time.
3508 : *
3509 : * \param ns NVMe namespace to submit the read I/O
3510 : * \param qpair I/O queue pair to submit the request
3511 : * \param lba starting LBA to read the data
3512 : * \param lba_count length (in sectors) for the read operation
3513 : * \param cb_fn callback function to invoke when the I/O is completed
3514 : * \param cb_arg argument to pass to the callback function
3515 : * \param io_flags set flags, defined in nvme_spec.h, for this I/O
3516 : * \param reset_sgl_fn callback function to reset scattered payload
3517 : * \param next_sge_fn callback function to iterate each scattered
3518 : * payload memory segment
3519 : * \param metadata virtual address pointer to the metadata payload, the length
3520 : * of metadata is specified by spdk_nvme_ns_get_md_size()
3521 : * \param apptag_mask application tag mask.
3522 : * \param apptag application tag to use end-to-end protection information.
3523 : *
3524 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3525 : * -EINVAL: The request is malformed.
3526 : * -ENOMEM: The request cannot be allocated.
3527 : * -ENXIO: The qpair is failed at the transport level.
3528 : */
3529 : int spdk_nvme_ns_cmd_readv_with_md(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
3530 : uint64_t lba, uint32_t lba_count,
3531 : spdk_nvme_cmd_cb cb_fn, void *cb_arg, uint32_t io_flags,
3532 : spdk_nvme_req_reset_sgl_cb reset_sgl_fn,
3533 : spdk_nvme_req_next_sge_cb next_sge_fn, void *metadata,
3534 : uint16_t apptag_mask, uint16_t apptag);
3535 :
3536 : /**
3537 : * Submit a read I/O to the specified NVMe namespace.
3538 : *
3539 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3540 : * The user must ensure that only one thread submits I/O on a given qpair at any given time.
3541 : *
3542 : * \param ns NVMe namespace to submit the read I/O
3543 : * \param qpair I/O queue pair to submit the request
3544 : * \param lba starting LBA to read the data
3545 : * \param lba_count length (in sectors) for the read operation
3546 : * \param cb_fn callback function to invoke when the I/O is completed
3547 : * \param cb_arg argument to pass to the callback function
3548 : * \param reset_sgl_fn callback function to reset scattered payload
3549 : * \param next_sge_fn callback function to iterate each scattered
3550 : * payload memory segment
3551 : * \param opts Optional structure with extended IO request options. If provided, the caller must
3552 : * guarantee that this structure is accessible until IO completes
3553 : *
3554 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3555 : * -EINVAL: The request is malformed.
3556 : * -ENOMEM: The request cannot be allocated.
3557 : * -ENXIO: The qpair is failed at the transport level.
3558 : * -EFAULT: Invalid address was specified as part of payload. cb_fn is also called
3559 : * with error status including dnr=1 in this case.
3560 : */
3561 : int spdk_nvme_ns_cmd_readv_ext(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
3562 : uint64_t lba, uint32_t lba_count, spdk_nvme_cmd_cb cb_fn,
3563 : void *cb_arg, spdk_nvme_req_reset_sgl_cb reset_sgl_fn,
3564 : spdk_nvme_req_next_sge_cb next_sge_fn,
3565 : struct spdk_nvme_ns_cmd_ext_io_opts *opts);
3566 :
3567 : /**
3568 : * Submit a read I/O to the specified NVMe namespace.
3569 : *
3570 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3571 : * The user must ensure that only one thread submits I/O on a given qpair at any given time.
3572 : *
3573 : * \param ns NVMe namespace to submit the read I/O
3574 : * \param qpair I/O queue pair to submit the request
3575 : * \param payload virtual address pointer to the data payload
3576 : * \param lba starting LBA to read the data
3577 : * \param lba_count length (in sectors) for the read operation
3578 : * \param cb_fn callback function to invoke when the I/O is completed
3579 : * \param cb_arg argument to pass to the callback function
3580 : * \param opts Optional structure with extended IO request options. If provided, the caller must
3581 : * guarantee that this structure is accessible until IO completes
3582 : *
3583 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3584 : * -EINVAL: The request is malformed.
3585 : * -ENOMEM: The request cannot be allocated.
3586 : * -ENXIO: The qpair is failed at the transport level.
3587 : * -EFAULT: Invalid address was specified as part of payload. cb_fn is also called
3588 : * with error status including dnr=1 in this case.
3589 : */
3590 : int spdk_nvme_ns_cmd_read_ext(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair, void *payload,
3591 : uint64_t lba, uint32_t lba_count, spdk_nvme_cmd_cb cb_fn, void *cb_arg,
3592 : struct spdk_nvme_ns_cmd_ext_io_opts *opts);
3593 :
3594 : /**
3595 : * Submits a read I/O to the specified NVMe namespace.
3596 : *
3597 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3598 : * The user must ensure that only one thread submits I/O on a given qpair at any
3599 : * given time.
3600 : *
3601 : * \param ns NVMe namespace to submit the read I/O
3602 : * \param qpair I/O queue pair to submit the request
3603 : * \param payload virtual address pointer to the data payload
3604 : * \param metadata virtual address pointer to the metadata payload, the length
3605 : * of metadata is specified by spdk_nvme_ns_get_md_size().
3606 : * \param lba starting LBA to read the data.
3607 : * \param lba_count Length (in sectors) for the read operation.
3608 : * \param cb_fn Callback function to invoke when the I/O is completed.
3609 : * \param cb_arg Argument to pass to the callback function.
3610 : * \param io_flags Set flags, defined in nvme_spec.h, for this I/O.
3611 : * \param apptag_mask Application tag mask.
3612 : * \param apptag Application tag to use end-to-end protection information.
3613 : *
3614 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3615 : * -EINVAL: The request is malformed.
3616 : * -ENOMEM: The request cannot be allocated.
3617 : * -ENXIO: The qpair is failed at the transport level.
3618 : */
3619 : int spdk_nvme_ns_cmd_read_with_md(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
3620 : void *payload, void *metadata,
3621 : uint64_t lba, uint32_t lba_count, spdk_nvme_cmd_cb cb_fn,
3622 : void *cb_arg, uint32_t io_flags,
3623 : uint16_t apptag_mask, uint16_t apptag);
3624 :
3625 : /**
3626 : * Submit a data set management request to the specified NVMe namespace.
3627 : *
3628 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3629 : * The user must ensure that only one thread submits I/O on a given qpair at any
3630 : * given time.
3631 : *
3632 : * This is a convenience wrapper that will automatically allocate and construct
3633 : * the correct data buffers. Therefore, ranges does not need to be allocated from
3634 : * pinned memory and can be placed on the stack. If a higher performance, zero-copy
3635 : * version of DSM is required, simply build and submit a raw command using
3636 : * spdk_nvme_ctrlr_cmd_io_raw().
3637 : *
3638 : * \param ns NVMe namespace to submit the DSM request
3639 : * \param type A bit field constructed from \ref spdk_nvme_dsm_attribute.
3640 : * \param qpair I/O queue pair to submit the request
3641 : * \param ranges An array of \ref spdk_nvme_dsm_range elements describing the LBAs
3642 : * to operate on.
3643 : * \param num_ranges The number of elements in the ranges array.
3644 : * \param cb_fn Callback function to invoke when the I/O is completed
3645 : * \param cb_arg Argument to pass to the callback function
3646 : *
3647 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3648 : * -ENOMEM: The request cannot be allocated.
3649 : * -ENXIO: The qpair is failed at the transport level.
3650 : */
3651 : int spdk_nvme_ns_cmd_dataset_management(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
3652 : uint32_t type,
3653 : const struct spdk_nvme_dsm_range *ranges,
3654 : uint16_t num_ranges,
3655 : spdk_nvme_cmd_cb cb_fn,
3656 : void *cb_arg);
3657 :
3658 : /**
3659 : * Submit a simple copy command request to the specified NVMe namespace.
3660 : *
3661 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3662 : * The user must ensure that only one thread submits I/O on a given qpair at any
3663 : * given time.
3664 : *
3665 : * This is a convenience wrapper that will automatically allocate and construct
3666 : * the correct data buffers. Therefore, ranges does not need to be allocated from
3667 : * pinned memory and can be placed on the stack. If a higher performance, zero-copy
3668 : * version of SCC is required, simply build and submit a raw command using
3669 : * spdk_nvme_ctrlr_cmd_io_raw().
3670 : *
3671 : * \param ns NVMe namespace to submit the SCC request
3672 : * \param qpair I/O queue pair to submit the request
3673 : * \param ranges An array of \ref spdk_nvme_scc_source_range elements describing the LBAs
3674 : * to operate on.
3675 : * \param num_ranges The number of elements in the ranges array.
3676 : * \param dest_lba Destination LBA to copy the data.
3677 : * \param cb_fn Callback function to invoke when the I/O is completed
3678 : * \param cb_arg Argument to pass to the callback function
3679 : *
3680 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3681 : * -ENOMEM: The request cannot be allocated.
3682 : * -EINVAL: Invalid ranges.
3683 : * -ENXIO: The qpair is failed at the transport level.
3684 : */
3685 : int spdk_nvme_ns_cmd_copy(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
3686 : const struct spdk_nvme_scc_source_range *ranges,
3687 : uint16_t num_ranges,
3688 : uint64_t dest_lba,
3689 : spdk_nvme_cmd_cb cb_fn,
3690 : void *cb_arg);
3691 :
3692 : /**
3693 : * Submit a flush request to the specified NVMe namespace.
3694 : *
3695 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3696 : * The user must ensure that only one thread submits I/O on a given qpair at any
3697 : * given time.
3698 : *
3699 : * \param ns NVMe namespace to submit the flush request.
3700 : * \param qpair I/O queue pair to submit the request.
3701 : * \param cb_fn Callback function to invoke when the I/O is completed.
3702 : * \param cb_arg Argument to pass to the callback function.
3703 : *
3704 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3705 : * -ENOMEM: The request cannot be allocated.
3706 : * -ENXIO: The qpair is failed at the transport level.
3707 : */
3708 : int spdk_nvme_ns_cmd_flush(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
3709 : spdk_nvme_cmd_cb cb_fn, void *cb_arg);
3710 :
3711 : /**
3712 : * Submit a reservation register to the specified NVMe namespace.
3713 : *
3714 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3715 : * The user must ensure that only one thread submits I/O on a given qpair at any
3716 : * given time.
3717 : *
3718 : * \param ns NVMe namespace to submit the reservation register request.
3719 : * \param qpair I/O queue pair to submit the request.
3720 : * \param payload Virtual address pointer to the reservation register data.
3721 : * \param ignore_key '1' the current reservation key check is disabled.
3722 : * \param action Specifies the registration action.
3723 : * \param cptpl Change the Persist Through Power Loss state.
3724 : * \param cb_fn Callback function to invoke when the I/O is completed.
3725 : * \param cb_arg Argument to pass to the callback function.
3726 : *
3727 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3728 : * -ENOMEM: The request cannot be allocated.
3729 : * -ENXIO: The qpair is failed at the transport level.
3730 : */
3731 : int spdk_nvme_ns_cmd_reservation_register(struct spdk_nvme_ns *ns,
3732 : struct spdk_nvme_qpair *qpair,
3733 : struct spdk_nvme_reservation_register_data *payload,
3734 : bool ignore_key,
3735 : enum spdk_nvme_reservation_register_action action,
3736 : enum spdk_nvme_reservation_register_cptpl cptpl,
3737 : spdk_nvme_cmd_cb cb_fn, void *cb_arg);
3738 :
3739 : /**
3740 : * Submits a reservation release to the specified NVMe namespace.
3741 : *
3742 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3743 : * The user must ensure that only one thread submits I/O on a given qpair at any
3744 : * given time.
3745 : *
3746 : * \param ns NVMe namespace to submit the reservation release request.
3747 : * \param qpair I/O queue pair to submit the request.
3748 : * \param payload Virtual address pointer to current reservation key.
3749 : * \param ignore_key '1' the current reservation key check is disabled.
3750 : * \param action Specifies the reservation release action.
3751 : * \param type Reservation type for the namespace.
3752 : * \param cb_fn Callback function to invoke when the I/O is completed.
3753 : * \param cb_arg Argument to pass to the callback function.
3754 : *
3755 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3756 : * -ENOMEM: The request cannot be allocated.
3757 : * -ENXIO: The qpair is failed at the transport level.
3758 : */
3759 : int spdk_nvme_ns_cmd_reservation_release(struct spdk_nvme_ns *ns,
3760 : struct spdk_nvme_qpair *qpair,
3761 : struct spdk_nvme_reservation_key_data *payload,
3762 : bool ignore_key,
3763 : enum spdk_nvme_reservation_release_action action,
3764 : enum spdk_nvme_reservation_type type,
3765 : spdk_nvme_cmd_cb cb_fn, void *cb_arg);
3766 :
3767 : /**
3768 : * Submits a reservation acquire to the specified NVMe namespace.
3769 : *
3770 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3771 : * The user must ensure that only one thread submits I/O on a given qpair at any
3772 : * given time.
3773 : *
3774 : * \param ns NVMe namespace to submit the reservation acquire request.
3775 : * \param qpair I/O queue pair to submit the request.
3776 : * \param payload Virtual address pointer to reservation acquire data.
3777 : * \param ignore_key '1' the current reservation key check is disabled.
3778 : * \param action Specifies the reservation acquire action.
3779 : * \param type Reservation type for the namespace.
3780 : * \param cb_fn Callback function to invoke when the I/O is completed.
3781 : * \param cb_arg Argument to pass to the callback function.
3782 : *
3783 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3784 : * -ENOMEM: The request cannot be allocated.
3785 : * -ENXIO: The qpair is failed at the transport level.
3786 : */
3787 : int spdk_nvme_ns_cmd_reservation_acquire(struct spdk_nvme_ns *ns,
3788 : struct spdk_nvme_qpair *qpair,
3789 : struct spdk_nvme_reservation_acquire_data *payload,
3790 : bool ignore_key,
3791 : enum spdk_nvme_reservation_acquire_action action,
3792 : enum spdk_nvme_reservation_type type,
3793 : spdk_nvme_cmd_cb cb_fn, void *cb_arg);
3794 :
3795 : /**
3796 : * Submit a reservation report to the specified NVMe namespace.
3797 : *
3798 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3799 : * The user must ensure that only one thread submits I/O on a given qpair at any
3800 : * given time.
3801 : *
3802 : * \param ns NVMe namespace to submit the reservation report request.
3803 : * \param qpair I/O queue pair to submit the request.
3804 : * \param payload Virtual address pointer for reservation status data.
3805 : * \param len Length bytes for reservation status data structure.
3806 : * \param cb_fn Callback function to invoke when the I/O is completed.
3807 : * \param cb_arg Argument to pass to the callback function.
3808 : *
3809 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3810 : * -ENOMEM: The request cannot be allocated.
3811 : * -ENXIO: The qpair is failed at the transport level.
3812 : */
3813 : int spdk_nvme_ns_cmd_reservation_report(struct spdk_nvme_ns *ns,
3814 : struct spdk_nvme_qpair *qpair,
3815 : void *payload, uint32_t len,
3816 : spdk_nvme_cmd_cb cb_fn, void *cb_arg);
3817 :
3818 : /**
3819 : * Submit an I/O management receive command to the specified NVMe namespace.
3820 : *
3821 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3822 : * The user must ensure that only one thread submits I/O on a given qpair at any
3823 : * given time.
3824 : *
3825 : * \param ns NVMe namespace to submit the I/O mgmt receive request.
3826 : * \param qpair I/O queue pair to submit the request.
3827 : * \param payload Virtual address pointer for I/O mgmt receive data.
3828 : * \param len Length bytes for I/O mgmt receive data structure.
3829 : * \param mo Management operation to perform.
3830 : * \param mos Management operation specific field for the mo.
3831 : * \param cb_fn Callback function to invoke when the I/O is completed.
3832 : * \param cb_arg Argument to pass to the callback function.
3833 : *
3834 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3835 : * -ENOMEM: The request cannot be allocated.
3836 : * -ENXIO: The qpair is failed at the transport level.
3837 : */
3838 : int spdk_nvme_ns_cmd_io_mgmt_recv(struct spdk_nvme_ns *ns,
3839 : struct spdk_nvme_qpair *qpair, void *payload,
3840 : uint32_t len, uint8_t mo, uint16_t mos,
3841 : spdk_nvme_cmd_cb cb_fn, void *cb_arg);
3842 :
3843 : /**
3844 : * Submit an I/O management send command to the specified NVMe namespace.
3845 : *
3846 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3847 : * The user must ensure that only one thread submits I/O on a given qpair at any
3848 : * given time.
3849 : *
3850 : * \param ns NVMe namespace to submit the I/O mgmt send request.
3851 : * \param qpair I/O queue pair to submit the request.
3852 : * \param payload Virtual address pointer for I/O mgmt send data.
3853 : * \param len Length bytes for I/O mgmt send data structure.
3854 : * \param mo Management operation to perform.
3855 : * \param mos Management operation specific field for the mo.
3856 : * \param cb_fn Callback function to invoke when the I/O is completed.
3857 : * \param cb_arg Argument to pass to the callback function.
3858 : *
3859 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3860 : * -ENOMEM: The request cannot be allocated.
3861 : * -ENXIO: The qpair is failed at the transport level.
3862 : */
3863 : int spdk_nvme_ns_cmd_io_mgmt_send(struct spdk_nvme_ns *ns,
3864 : struct spdk_nvme_qpair *qpair, void *payload,
3865 : uint32_t len, uint8_t mo, uint16_t mos,
3866 : spdk_nvme_cmd_cb cb_fn, void *cb_arg);
3867 :
3868 : /**
3869 : * Submit a compare I/O to the specified NVMe namespace.
3870 : *
3871 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3872 : * The user must ensure that only one thread submits I/O on a given qpair at any
3873 : * given time.
3874 : *
3875 : * \param ns NVMe namespace to submit the compare I/O.
3876 : * \param qpair I/O queue pair to submit the request.
3877 : * \param payload Virtual address pointer to the data payload.
3878 : * \param lba Starting LBA to compare the data.
3879 : * \param lba_count Length (in sectors) for the compare operation.
3880 : * \param cb_fn Callback function to invoke when the I/O is completed.
3881 : * \param cb_arg Argument to pass to the callback function.
3882 : * \param io_flags Set flags, defined in nvme_spec.h, for this I/O.
3883 : *
3884 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3885 : * -EINVAL: The request is malformed.
3886 : * -ENOMEM: The request cannot be allocated.
3887 : * -ENXIO: The qpair is failed at the transport level.
3888 : */
3889 : int spdk_nvme_ns_cmd_compare(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair, void *payload,
3890 : uint64_t lba, uint32_t lba_count, spdk_nvme_cmd_cb cb_fn,
3891 : void *cb_arg, uint32_t io_flags);
3892 :
3893 : /**
3894 : * Submit a compare I/O to the specified NVMe namespace.
3895 : *
3896 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3897 : * The user must ensure that only one thread submits I/O on a given qpair at any
3898 : * given time.
3899 : *
3900 : * \param ns NVMe namespace to submit the compare I/O.
3901 : * \param qpair I/O queue pair to submit the request.
3902 : * \param lba Starting LBA to compare the data.
3903 : * \param lba_count Length (in sectors) for the compare operation.
3904 : * \param cb_fn Callback function to invoke when the I/O is completed.
3905 : * \param cb_arg Argument to pass to the callback function.
3906 : * \param io_flags Set flags, defined in nvme_spec.h, for this I/O.
3907 : * \param reset_sgl_fn Callback function to reset scattered payload.
3908 : * \param next_sge_fn Callback function to iterate each scattered payload memory
3909 : * segment.
3910 : *
3911 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3912 : * -EINVAL: The request is malformed.
3913 : * -ENOMEM: The request cannot be allocated.
3914 : * -ENXIO: The qpair is failed at the transport level.
3915 : */
3916 : int spdk_nvme_ns_cmd_comparev(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
3917 : uint64_t lba, uint32_t lba_count,
3918 : spdk_nvme_cmd_cb cb_fn, void *cb_arg, uint32_t io_flags,
3919 : spdk_nvme_req_reset_sgl_cb reset_sgl_fn,
3920 : spdk_nvme_req_next_sge_cb next_sge_fn);
3921 :
3922 : /**
3923 : * Submit a compare I/O to the specified NVMe namespace.
3924 : *
3925 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3926 : * The user must ensure that only one thread submits I/O on a given qpair at any
3927 : * given time.
3928 : *
3929 : * \param ns NVMe namespace to submit the compare I/O.
3930 : * \param qpair I/O queue pair to submit the request.
3931 : * \param lba Starting LBA to compare the data.
3932 : * \param lba_count Length (in sectors) for the compare operation.
3933 : * \param cb_fn Callback function to invoke when the I/O is completed.
3934 : * \param cb_arg Argument to pass to the callback function.
3935 : * \param io_flags Set flags, defined in nvme_spec.h, for this I/O.
3936 : * \param reset_sgl_fn Callback function to reset scattered payload.
3937 : * \param next_sge_fn Callback function to iterate each scattered payload memory
3938 : * segment.
3939 : * \param metadata Virtual address pointer to the metadata payload, the length
3940 : * of metadata is specified by spdk_nvme_ns_get_md_size()
3941 : * \param apptag_mask Application tag mask.
3942 : * \param apptag Application tag to use end-to-end protection information.
3943 : *
3944 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3945 : * -EINVAL: The request is malformed.
3946 : * -ENOMEM: The request cannot be allocated.
3947 : * -ENXIO: The qpair is failed at the transport level.
3948 : */
3949 : int
3950 : spdk_nvme_ns_cmd_comparev_with_md(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
3951 : uint64_t lba, uint32_t lba_count,
3952 : spdk_nvme_cmd_cb cb_fn, void *cb_arg, uint32_t io_flags,
3953 : spdk_nvme_req_reset_sgl_cb reset_sgl_fn,
3954 : spdk_nvme_req_next_sge_cb next_sge_fn, void *metadata,
3955 : uint16_t apptag_mask, uint16_t apptag);
3956 :
3957 : /**
3958 : * Submit a compare I/O to the specified NVMe namespace.
3959 : *
3960 : * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair().
3961 : * The user must ensure that only one thread submits I/O on a given qpair at any
3962 : * given time.
3963 : *
3964 : * \param ns NVMe namespace to submit the compare I/O.
3965 : * \param qpair I/O queue pair to submit the request.
3966 : * \param payload Virtual address pointer to the data payload.
3967 : * \param metadata Virtual address pointer to the metadata payload, the length
3968 : * of metadata is specified by spdk_nvme_ns_get_md_size().
3969 : * \param lba Starting LBA to compare the data.
3970 : * \param lba_count Length (in sectors) for the compare operation.
3971 : * \param cb_fn Callback function to invoke when the I/O is completed.
3972 : * \param cb_arg Argument to pass to the callback function.
3973 : * \param io_flags Set flags, defined in nvme_spec.h, for this I/O.
3974 : * \param apptag_mask Application tag mask.
3975 : * \param apptag Application tag to use end-to-end protection information.
3976 : *
3977 : * \return 0 if successfully submitted, negated errnos on the following error conditions:
3978 : * -EINVAL: The request is malformed.
3979 : * -ENOMEM: The request cannot be allocated.
3980 : * -ENXIO: The qpair is failed at the transport level.
3981 : */
3982 : int spdk_nvme_ns_cmd_compare_with_md(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
3983 : void *payload, void *metadata,
3984 : uint64_t lba, uint32_t lba_count, spdk_nvme_cmd_cb cb_fn,
3985 : void *cb_arg, uint32_t io_flags,
3986 : uint16_t apptag_mask, uint16_t apptag);
3987 :
3988 : /**
3989 : * \brief Inject an error for the next request with a given opcode.
3990 : *
3991 : * \param ctrlr NVMe controller.
3992 : * \param qpair I/O queue pair to add the error command,
3993 : * NULL for Admin queue pair.
3994 : * \param opc Opcode for Admin or I/O commands.
3995 : * \param do_not_submit True if matching requests should not be submitted
3996 : * to the controller, but instead completed manually
3997 : * after timeout_in_us has expired. False if matching
3998 : * requests should be submitted to the controller and
3999 : * have their completion status modified after the
4000 : * controller completes the request.
4001 : * \param timeout_in_us Wait specified microseconds when do_not_submit is true.
4002 : * \param err_count Number of matching requests to inject errors.
4003 : * \param sct Status code type.
4004 : * \param sc Status code.
4005 : *
4006 : * \return 0 if successfully enabled, ENOMEM if an error command
4007 : * structure cannot be allocated.
4008 : *
4009 : * The function can be called multiple times to inject errors for different
4010 : * commands. If the opcode matches an existing entry, the existing entry
4011 : * will be updated with the values specified.
4012 : */
4013 : int spdk_nvme_qpair_add_cmd_error_injection(struct spdk_nvme_ctrlr *ctrlr,
4014 : struct spdk_nvme_qpair *qpair,
4015 : uint8_t opc,
4016 : bool do_not_submit,
4017 : uint64_t timeout_in_us,
4018 : uint32_t err_count,
4019 : uint8_t sct, uint8_t sc);
4020 :
4021 : /**
4022 : * \brief Clear the specified NVMe command with error status.
4023 : *
4024 : * \param ctrlr NVMe controller.
4025 : * \param qpair I/O queue pair to remove the error command,
4026 : * \ NULL for Admin queue pair.
4027 : * \param opc Opcode for Admin or I/O commands.
4028 : *
4029 : * The function will remove specified command in the error list.
4030 : */
4031 : void spdk_nvme_qpair_remove_cmd_error_injection(struct spdk_nvme_ctrlr *ctrlr,
4032 : struct spdk_nvme_qpair *qpair,
4033 : uint8_t opc);
4034 :
4035 : /**
4036 : * \brief Given NVMe status, return ASCII string for that error.
4037 : *
4038 : * \param status Status from NVMe completion queue element.
4039 : * \return Returns status as an ASCII string.
4040 : */
4041 : const char *spdk_nvme_cpl_get_status_string(const struct spdk_nvme_status *status);
4042 :
4043 : /**
4044 : * \brief Given NVMe status, return ASCII string for the type of that error.
4045 : *
4046 : * \param status Status from NVMe completion queue element.
4047 : * \return Returns status type as an ASCII string.
4048 : */
4049 : const char *spdk_nvme_cpl_get_status_type_string(const struct spdk_nvme_status *status);
4050 :
4051 : /**
4052 : * \brief Prints (SPDK_NOTICELOG) the contents of an NVMe submission queue entry (command).
4053 : *
4054 : * \param qpair Pointer to the NVMe queue pair - used to determine admin versus I/O queue.
4055 : * \param cmd Pointer to the submission queue command to be formatted.
4056 : */
4057 : void spdk_nvme_qpair_print_command(struct spdk_nvme_qpair *qpair,
4058 : struct spdk_nvme_cmd *cmd);
4059 :
4060 : /**
4061 : * \brief Prints (SPDK_NOTICELOG) the contents of an NVMe completion queue entry.
4062 : *
4063 : * \param qpair Pointer to the NVMe queue pair - presently unused.
4064 : * \param cpl Pointer to the completion queue element to be formatted.
4065 : */
4066 : void spdk_nvme_qpair_print_completion(struct spdk_nvme_qpair *qpair,
4067 : struct spdk_nvme_cpl *cpl);
4068 :
4069 : /**
4070 : * \brief Gets the NVMe qpair ID for the specified qpair.
4071 : *
4072 : * \param qpair Pointer to the NVMe queue pair.
4073 : * \returns ID for the specified qpair.
4074 : */
4075 : uint16_t spdk_nvme_qpair_get_id(struct spdk_nvme_qpair *qpair);
4076 :
4077 : /**
4078 : * Gets the number of outstanding requests for the specified qpair.
4079 : *
4080 : * This number is not decremented until after a request's callback function is completed.
4081 : *
4082 : * This number is not matched necessarily to the number of NVMe commands submitted by the
4083 : * user. For example, nvme driver may split a request due to MDTS limitations, that will
4084 : * also allocate a request for the parent, etc.
4085 : *
4086 : * \param qpair Pointer to the NVMe queue pair.
4087 : * \returns number of outstanding requests for the specified qpair.
4088 : */
4089 : uint32_t spdk_nvme_qpair_get_num_outstanding_reqs(struct spdk_nvme_qpair *qpair);
4090 :
4091 : /**
4092 : * \brief Prints (SPDK_NOTICELOG) the contents of an NVMe submission queue entry (command).
4093 : *
4094 : * \param qid Queue identifier.
4095 : * \param cmd Pointer to the submission queue command to be formatted.
4096 : */
4097 : void spdk_nvme_print_command(uint16_t qid, struct spdk_nvme_cmd *cmd);
4098 :
4099 : /**
4100 : * \brief Prints (SPDK_NOTICELOG) the contents of an NVMe completion queue entry.
4101 : *
4102 : * \param qid Queue identifier.
4103 : * \param cpl Pointer to the completion queue element to be formatted.
4104 : */
4105 : void spdk_nvme_print_completion(uint16_t qid, struct spdk_nvme_cpl *cpl);
4106 :
4107 : /**
4108 : * Return the name of a digest.
4109 : *
4110 : * \param id Digest identifier (see `enum spdk_nvmf_dhchap_hash`).
4111 : *
4112 : * \return Name of the digest.
4113 : */
4114 : const char *spdk_nvme_dhchap_get_digest_name(int id);
4115 :
4116 : /**
4117 : * Return the id of a digest.
4118 : *
4119 : * \param name Name of a digest.
4120 : *
4121 : * \return Digest id (see `enum spdk_nvmf_dhchap_hash`) or negative errno on failure.
4122 : */
4123 : int spdk_nvme_dhchap_get_digest_id(const char *name);
4124 :
4125 : /**
4126 : * Return the length of a digest.
4127 : *
4128 : * \param id Digest identifier (see `enum spdk_nvmf_dhchap_hash`).
4129 : *
4130 : * \return Length of a digest or 0 if the id is unknown.
4131 : */
4132 : uint8_t spdk_nvme_dhchap_get_digest_length(int id);
4133 :
4134 : /**
4135 : * Return the name of a Diffie-Hellman group.
4136 : *
4137 : * \param id Diffie-Hellman group identifier (see `enum spdk_nvmf_dhchap_dhgroup`).
4138 : *
4139 : * \return Name of the Diffie-Hellman group.
4140 : */
4141 : const char *spdk_nvme_dhchap_get_dhgroup_name(int id);
4142 :
4143 : /**
4144 : * Return the id of a Diffie-Hellman group.
4145 : *
4146 : * \param name Name of a Diffie-Hellman group.
4147 : *
4148 : * \return Diffie-Hellman group id (see `enum spdk_nvmf_dhchap_dhgroup`) or negative errno
4149 : * on failure.
4150 : */
4151 : int spdk_nvme_dhchap_get_dhgroup_id(const char *name);
4152 :
4153 : struct ibv_context;
4154 : struct ibv_pd;
4155 : struct ibv_mr;
4156 :
4157 : /**
4158 : * RDMA Transport Hooks
4159 : */
4160 : struct spdk_nvme_rdma_hooks {
4161 : /**
4162 : * \brief Get an InfiniBand Verbs protection domain.
4163 : *
4164 : * \param trid the transport id
4165 : * \param verbs Infiniband verbs context
4166 : *
4167 : * \return pd of the nvme ctrlr
4168 : */
4169 : struct ibv_pd *(*get_ibv_pd)(const struct spdk_nvme_transport_id *trid,
4170 : struct ibv_context *verbs);
4171 :
4172 : /**
4173 : * \brief Get an InfiniBand Verbs memory region for a buffer.
4174 : *
4175 : * \param pd The protection domain returned from get_ibv_pd
4176 : * \param buf Memory buffer for which an rkey should be returned.
4177 : * \param size size of buf
4178 : *
4179 : * \return Infiniband remote key (rkey) for this buf
4180 : */
4181 : uint64_t (*get_rkey)(struct ibv_pd *pd, void *buf, size_t size);
4182 :
4183 : /**
4184 : * \brief Put back keys got from get_rkey.
4185 : *
4186 : * \param key The Infiniband remote key (rkey) got from get_rkey
4187 : *
4188 : */
4189 : void (*put_rkey)(uint64_t key);
4190 : };
4191 :
4192 : /**
4193 : * \brief Set the global hooks for the RDMA transport, if necessary.
4194 : *
4195 : * This call is optional and must be performed prior to probing for
4196 : * any devices. By default, the RDMA transport will use the ibverbs
4197 : * library to create protection domains and register memory. This
4198 : * is a mechanism to subvert that and use an existing registration.
4199 : *
4200 : * This function may only be called one time per process.
4201 : *
4202 : * \param hooks for initializing global hooks
4203 : */
4204 : void spdk_nvme_rdma_init_hooks(struct spdk_nvme_rdma_hooks *hooks);
4205 :
4206 : /**
4207 : * Get name of cuse device associated with NVMe controller.
4208 : *
4209 : * \param ctrlr Opaque handle to NVMe controller.
4210 : * \param name Buffer of be filled with cuse device name.
4211 : * \param size Size of name buffer.
4212 : *
4213 : * \return 0 on success. Negated errno on the following error conditions:
4214 : * -ENODEV: No cuse device registered for the controller.
4215 : * -ENSPC: Too small buffer size passed. Value of size pointer changed to the required length.
4216 : */
4217 : int spdk_nvme_cuse_get_ctrlr_name(struct spdk_nvme_ctrlr *ctrlr, char *name, size_t *size);
4218 :
4219 : /**
4220 : * Get name of cuse device associated with NVMe namespace.
4221 : *
4222 : * \param ctrlr Opaque handle to NVMe controller.
4223 : * \param nsid Namespace id.
4224 : * \param name Buffer of be filled with cuse device name.
4225 : * \param size Size of name buffer.
4226 : *
4227 : * \return 0 on success. Negated errno on the following error conditions:
4228 : * -ENODEV: No cuse device registered for the namespace.
4229 : * -ENSPC: Too small buffer size passed. Value of size pointer changed to the required length.
4230 : */
4231 : int spdk_nvme_cuse_get_ns_name(struct spdk_nvme_ctrlr *ctrlr, uint32_t nsid,
4232 : char *name, size_t *size);
4233 :
4234 : /**
4235 : * Create a character device at the path specified
4236 : *
4237 : * The character device can handle ioctls and is compatible with a standard
4238 : * Linux kernel NVMe device. Tools such as nvme-cli can be used to configure
4239 : * SPDK devices through this interface.
4240 : *
4241 : * The user is expected to be polling the admin qpair for this controller periodically
4242 : * for the CUSE device to function.
4243 : *
4244 : * \param ctrlr Opaque handle to the NVMe controller.
4245 : *
4246 : * \return 0 on success. Negated errno on failure.
4247 : */
4248 : int spdk_nvme_cuse_register(struct spdk_nvme_ctrlr *ctrlr);
4249 :
4250 : /**
4251 : * Remove a previously created character device
4252 : *
4253 : * \param ctrlr Opaque handle to the NVMe controller.
4254 : *
4255 : * \return 0 on success. Negated errno on failure.
4256 : */
4257 : int spdk_nvme_cuse_unregister(struct spdk_nvme_ctrlr *ctrlr);
4258 :
4259 : /**
4260 : * Get SPDK memory domains used by the given nvme controller.
4261 : *
4262 : * The user can call this function with \b domains set to NULL and \b array_size set to 0 to get the
4263 : * number of memory domains used by nvme controller
4264 : *
4265 : * \param ctrlr Opaque handle to the NVMe controller.
4266 : * \param domains Pointer to an array of memory domains to be filled by this function. The user should allocate big enough
4267 : * array to keep all memory domains used by nvme controller
4268 : * \param array_size size of \b domains array
4269 : * \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
4270 : * then the user should increase the size of \b domains array and call this function again. There is no guarantees that
4271 : * the content of \b domains array is valid in that case.
4272 : * -EINVAL if input parameters were invalid
4273 :
4274 : */
4275 : int spdk_nvme_ctrlr_get_memory_domains(const struct spdk_nvme_ctrlr *ctrlr,
4276 : struct spdk_memory_domain **domains, int array_size);
4277 :
4278 : /**
4279 : * Opaque handle for a transport poll group. Used by the transport function table.
4280 : */
4281 : struct spdk_nvme_transport_poll_group;
4282 :
4283 : /**
4284 : * Update and populate namespace CUSE devices (Experimental)
4285 : *
4286 : * \param ctrlr Opaque handle to the NVMe controller.
4287 : *
4288 : */
4289 : void spdk_nvme_cuse_update_namespaces(struct spdk_nvme_ctrlr *ctrlr);
4290 :
4291 : /**
4292 : * Signature for callback invoked after completing a register read/write operation.
4293 : *
4294 : * \param ctx Context passed by the user.
4295 : * \param value Value of the register, undefined in case of a failure.
4296 : * \param cpl Completion queue entry that contains the status of the command.
4297 : */
4298 : typedef void (*spdk_nvme_reg_cb)(void *ctx, uint64_t value, const struct spdk_nvme_cpl *cpl);
4299 :
4300 : struct nvme_request;
4301 :
4302 : struct spdk_nvme_transport;
4303 :
4304 : struct spdk_nvme_transport_ops {
4305 : char name[SPDK_NVMF_TRSTRING_MAX_LEN + 1];
4306 :
4307 : enum spdk_nvme_transport_type type;
4308 :
4309 : struct spdk_nvme_ctrlr *(*ctrlr_construct)(const struct spdk_nvme_transport_id *trid,
4310 : const struct spdk_nvme_ctrlr_opts *opts,
4311 : void *devhandle);
4312 :
4313 : int (*ctrlr_scan)(struct spdk_nvme_probe_ctx *probe_ctx, bool direct_connect);
4314 :
4315 : int (*ctrlr_destruct)(struct spdk_nvme_ctrlr *ctrlr);
4316 :
4317 : int (*ctrlr_enable)(struct spdk_nvme_ctrlr *ctrlr);
4318 :
4319 : int (*ctrlr_set_reg_4)(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint32_t value);
4320 :
4321 : int (*ctrlr_set_reg_8)(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint64_t value);
4322 :
4323 : int (*ctrlr_get_reg_4)(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint32_t *value);
4324 :
4325 : int (*ctrlr_get_reg_8)(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint64_t *value);
4326 :
4327 : int (*ctrlr_set_reg_4_async)(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint32_t value,
4328 : spdk_nvme_reg_cb cb_fn, void *cb_arg);
4329 :
4330 : int (*ctrlr_set_reg_8_async)(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint64_t value,
4331 : spdk_nvme_reg_cb cb_fn, void *cb_arg);
4332 :
4333 : int (*ctrlr_get_reg_4_async)(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset,
4334 : spdk_nvme_reg_cb cb_fn, void *cb_arg);
4335 :
4336 : int (*ctrlr_get_reg_8_async)(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset,
4337 : spdk_nvme_reg_cb cb_fn, void *cb_arg);
4338 :
4339 : uint32_t (*ctrlr_get_max_xfer_size)(struct spdk_nvme_ctrlr *ctrlr);
4340 :
4341 : uint16_t (*ctrlr_get_max_sges)(struct spdk_nvme_ctrlr *ctrlr);
4342 :
4343 : int (*ctrlr_reserve_cmb)(struct spdk_nvme_ctrlr *ctrlr);
4344 :
4345 : void *(*ctrlr_map_cmb)(struct spdk_nvme_ctrlr *ctrlr, size_t *size);
4346 :
4347 : int (*ctrlr_unmap_cmb)(struct spdk_nvme_ctrlr *ctrlr);
4348 :
4349 : int (*ctrlr_enable_pmr)(struct spdk_nvme_ctrlr *ctrlr);
4350 :
4351 : int (*ctrlr_disable_pmr)(struct spdk_nvme_ctrlr *ctrlr);
4352 :
4353 : void *(*ctrlr_map_pmr)(struct spdk_nvme_ctrlr *ctrlr, size_t *size);
4354 :
4355 : int (*ctrlr_unmap_pmr)(struct spdk_nvme_ctrlr *ctrlr);
4356 :
4357 : struct spdk_nvme_qpair *(*ctrlr_create_io_qpair)(struct spdk_nvme_ctrlr *ctrlr, uint16_t qid,
4358 : const struct spdk_nvme_io_qpair_opts *opts);
4359 :
4360 : int (*ctrlr_delete_io_qpair)(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qpair);
4361 :
4362 : int (*ctrlr_connect_qpair)(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qpair);
4363 :
4364 : void (*ctrlr_disconnect_qpair)(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qpair);
4365 :
4366 : void (*qpair_abort_reqs)(struct spdk_nvme_qpair *qpair, uint32_t dnr);
4367 :
4368 : int (*qpair_reset)(struct spdk_nvme_qpair *qpair);
4369 :
4370 : int (*qpair_submit_request)(struct spdk_nvme_qpair *qpair, struct nvme_request *req);
4371 :
4372 : int32_t (*qpair_process_completions)(struct spdk_nvme_qpair *qpair, uint32_t max_completions);
4373 :
4374 : int (*qpair_iterate_requests)(struct spdk_nvme_qpair *qpair,
4375 : int (*iter_fn)(struct nvme_request *req, void *arg),
4376 : void *arg);
4377 :
4378 : void (*admin_qpair_abort_aers)(struct spdk_nvme_qpair *qpair);
4379 :
4380 : struct spdk_nvme_transport_poll_group *(*poll_group_create)(void);
4381 : struct spdk_nvme_transport_poll_group *(*qpair_get_optimal_poll_group)(
4382 : struct spdk_nvme_qpair *qpair);
4383 :
4384 : int (*poll_group_add)(struct spdk_nvme_transport_poll_group *tgroup, struct spdk_nvme_qpair *qpair);
4385 :
4386 : int (*poll_group_remove)(struct spdk_nvme_transport_poll_group *tgroup,
4387 : struct spdk_nvme_qpair *qpair);
4388 :
4389 : int (*poll_group_connect_qpair)(struct spdk_nvme_qpair *qpair);
4390 :
4391 : int (*poll_group_disconnect_qpair)(struct spdk_nvme_qpair *qpair);
4392 :
4393 : int64_t (*poll_group_process_completions)(struct spdk_nvme_transport_poll_group *tgroup,
4394 : uint32_t completions_per_qpair, spdk_nvme_disconnected_qpair_cb disconnected_qpair_cb);
4395 :
4396 : int (*poll_group_destroy)(struct spdk_nvme_transport_poll_group *tgroup);
4397 :
4398 : int (*poll_group_get_stats)(struct spdk_nvme_transport_poll_group *tgroup,
4399 : struct spdk_nvme_transport_poll_group_stat **stats);
4400 :
4401 : void (*poll_group_free_stats)(struct spdk_nvme_transport_poll_group *tgroup,
4402 : struct spdk_nvme_transport_poll_group_stat *stats);
4403 :
4404 : int (*ctrlr_get_memory_domains)(const struct spdk_nvme_ctrlr *ctrlr,
4405 : struct spdk_memory_domain **domains,
4406 : int array_size);
4407 :
4408 : int (*ctrlr_ready)(struct spdk_nvme_ctrlr *ctrlr);
4409 :
4410 : volatile struct spdk_nvme_registers *(*ctrlr_get_registers)(struct spdk_nvme_ctrlr *ctrlr);
4411 : };
4412 :
4413 : /**
4414 : * Register the operations for a given transport type.
4415 : *
4416 : * This function should be invoked by referencing the macro
4417 : * SPDK_NVME_TRANSPORT_REGISTER macro in the transport's .c file.
4418 : *
4419 : * \param ops The operations associated with an NVMe-oF transport.
4420 : */
4421 : void spdk_nvme_transport_register(const struct spdk_nvme_transport_ops *ops);
4422 :
4423 : /*
4424 : * Macro used to register new transports.
4425 : */
4426 : #define SPDK_NVME_TRANSPORT_REGISTER(name, transport_ops) \
4427 : static void __attribute__((constructor)) _spdk_nvme_transport_register_##name(void) \
4428 : { \
4429 : spdk_nvme_transport_register(transport_ops); \
4430 : }
4431 :
4432 : /**
4433 : * NVMe transport options.
4434 : */
4435 : struct spdk_nvme_transport_opts {
4436 : /**
4437 : * It is used for RDMA transport.
4438 : *
4439 : * The queue depth of a shared rdma receive queue.
4440 : */
4441 : uint32_t rdma_srq_size;
4442 :
4443 : /* Hole at bytes 4-7. */
4444 : uint8_t reserved4[4];
4445 :
4446 : /**
4447 : * The size of spdk_nvme_transport_opts according to the caller of this library is used for ABI
4448 : * compatibility. The library uses this field to know how many fields in this
4449 : * structure are valid. And the library will populate any remaining fields with default values.
4450 : */
4451 : size_t opts_size;
4452 :
4453 : /**
4454 : * It is used for RDMA transport.
4455 : *
4456 : * The maximum queue depth of a rdma completion queue.
4457 : * It is zero, which means unlimited, by default.
4458 : */
4459 : uint32_t rdma_max_cq_size;
4460 :
4461 : /**
4462 : * It is used for RDMA transport.
4463 : *
4464 : * RDMA CM event timeout in milliseconds.
4465 : */
4466 : uint16_t rdma_cm_event_timeout_ms;
4467 : };
4468 : SPDK_STATIC_ASSERT(sizeof(struct spdk_nvme_transport_opts) == 24, "Incorrect size");
4469 :
4470 : /**
4471 : * Get the current NVMe transport options.
4472 : *
4473 : * \param[out] opts Will be filled with the current options for spdk_nvme_transport_set_opts().
4474 : * \param opts_size Must be set to sizeof(struct spdk_nvme_transport_opts).
4475 : */
4476 : void spdk_nvme_transport_get_opts(struct spdk_nvme_transport_opts *opts, size_t opts_size);
4477 :
4478 : /**
4479 : * Set the NVMe transport options.
4480 : *
4481 : * \param opts Pointer to the allocated spdk_nvme_transport_opts structure with new values.
4482 : * \param opts_size Must be set to sizeof(struct spdk_nvme_transport_opts).
4483 : *
4484 : * \return 0 on success, or negated errno on failure.
4485 : */
4486 : int spdk_nvme_transport_set_opts(const struct spdk_nvme_transport_opts *opts, size_t opts_size);
4487 :
4488 : #ifdef __cplusplus
4489 : }
4490 : #endif
4491 :
4492 : #endif
|