Line data Source code
1 : /* SPDX-License-Identifier: BSD-3-Clause
2 : * Copyright (C) 2020 Intel Corporation. All rights reserved.
3 : * Copyright (c) 2019, 2021 Mellanox Technologies LTD. All rights reserved.
4 : */
5 :
6 : /** \file
7 : * NVMe-oF Target transport plugin API
8 : */
9 :
10 : #ifndef SPDK_NVMF_TRANSPORT_H_
11 : #define SPDK_NVMF_TRANSPORT_H_
12 :
13 : #include "spdk/bdev.h"
14 : #include "spdk/thread.h"
15 : #include "spdk/nvme_spec.h"
16 : #include "spdk/nvmf.h"
17 : #include "spdk/nvmf_cmd.h"
18 : #include "spdk/nvmf_spec.h"
19 : #include "spdk/memory.h"
20 : #include "spdk/trace.h"
21 :
22 : #ifdef __cplusplus
23 : extern "C" {
24 : #endif
25 :
26 : #define SPDK_NVMF_MAX_SGL_ENTRIES 16
27 :
28 : /* The maximum number of buffers per request */
29 : #define NVMF_REQ_MAX_BUFFERS (SPDK_NVMF_MAX_SGL_ENTRIES * 2 + 1)
30 :
31 : /* Maximum pending AERs that can be migrated */
32 : #define SPDK_NVMF_MIGR_MAX_PENDING_AERS 256
33 :
34 : #define SPDK_NVMF_MAX_ASYNC_EVENTS 4
35 :
36 : /* Some backends require 4K aligned buffers. The iobuf library gives us that
37 : * naturally, but there are buffers allocated other ways that need to use this.
38 : */
39 : #define NVMF_DATA_BUFFER_ALIGNMENT VALUE_4KB
40 : #define NVMF_DATA_BUFFER_MASK (NVMF_DATA_BUFFER_ALIGNMENT - 1LL)
41 :
42 : #define SPDK_NVMF_DEFAULT_ACCEPT_POLL_RATE_US 10000
43 :
44 : union nvmf_h2c_msg {
45 : struct spdk_nvmf_capsule_cmd nvmf_cmd;
46 : struct spdk_nvme_cmd nvme_cmd;
47 : struct spdk_nvmf_fabric_prop_set_cmd prop_set_cmd;
48 : struct spdk_nvmf_fabric_prop_get_cmd prop_get_cmd;
49 : struct spdk_nvmf_fabric_connect_cmd connect_cmd;
50 : struct spdk_nvmf_fabric_auth_send_cmd auth_send_cmd;
51 : struct spdk_nvmf_fabric_auth_recv_cmd auth_recv_cmd;
52 : };
53 : SPDK_STATIC_ASSERT(sizeof(union nvmf_h2c_msg) == 64, "Incorrect size");
54 :
55 : union nvmf_c2h_msg {
56 : struct spdk_nvme_cpl nvme_cpl;
57 : struct spdk_nvmf_fabric_prop_get_rsp prop_get_rsp;
58 : struct spdk_nvmf_fabric_connect_rsp connect_rsp;
59 : };
60 : SPDK_STATIC_ASSERT(sizeof(union nvmf_c2h_msg) == 16, "Incorrect size");
61 :
62 : struct spdk_nvmf_dif_info {
63 : struct spdk_dif_ctx dif_ctx;
64 : uint32_t elba_length;
65 : uint32_t orig_length;
66 : };
67 :
68 : struct spdk_nvmf_stripped_data {
69 : uint32_t iovcnt;
70 : struct iovec iov[NVMF_REQ_MAX_BUFFERS];
71 : };
72 :
73 : enum spdk_nvmf_zcopy_phase {
74 : NVMF_ZCOPY_PHASE_NONE, /* Request is not using ZCOPY */
75 : NVMF_ZCOPY_PHASE_INIT, /* Requesting Buffers */
76 : NVMF_ZCOPY_PHASE_EXECUTE, /* Got buffers processing commands */
77 : NVMF_ZCOPY_PHASE_END_PENDING, /* Releasing buffers */
78 : NVMF_ZCOPY_PHASE_COMPLETE, /* Buffers Released */
79 : NVMF_ZCOPY_PHASE_INIT_FAILED /* Failed to get the buffers */
80 : };
81 :
82 : struct spdk_nvmf_request {
83 : struct spdk_nvmf_qpair *qpair;
84 : uint32_t length;
85 : uint8_t xfer; /* type enum spdk_nvme_data_transfer */
86 : union {
87 : uint8_t raw;
88 : struct {
89 : uint8_t data_from_pool : 1;
90 : uint8_t dif_enabled : 1;
91 : uint8_t first_fused : 1;
92 : uint8_t rsvd : 5;
93 : };
94 : };
95 : uint8_t zcopy_phase; /* type enum spdk_nvmf_zcopy_phase */
96 : uint8_t iovcnt;
97 : union nvmf_h2c_msg *cmd;
98 : union nvmf_c2h_msg *rsp;
99 : STAILQ_ENTRY(spdk_nvmf_request) buf_link;
100 : TAILQ_ENTRY(spdk_nvmf_request) link;
101 :
102 : /* Memory domain which describes payload in this request. If the bdev doesn't support memory
103 : * domains, bdev layer will do the necessary push or pull operation. */
104 : struct spdk_memory_domain *memory_domain;
105 : /* Context to be passed to memory domain operations. */
106 : void *memory_domain_ctx;
107 : struct spdk_accel_sequence *accel_sequence;
108 :
109 : struct iovec iov[NVMF_REQ_MAX_BUFFERS];
110 :
111 : struct spdk_nvmf_stripped_data *stripped_data;
112 :
113 : struct spdk_nvmf_dif_info dif;
114 :
115 : struct spdk_bdev_io_wait_entry bdev_io_wait;
116 : spdk_nvmf_nvme_passthru_cmd_cb cmd_cb_fn;
117 : struct spdk_nvmf_request *first_fused_req;
118 : struct spdk_nvmf_request *req_to_abort;
119 : struct spdk_poller *poller;
120 : struct spdk_bdev_io *zcopy_bdev_io; /* Contains the bdev_io when using ZCOPY */
121 :
122 : /* Timeout tracked for connect and abort flows. */
123 : uint64_t timeout_tsc;
124 : };
125 : SPDK_STATIC_ASSERT(sizeof(struct spdk_nvmf_request) == 776, "Incorrect size");
126 :
127 : enum spdk_nvmf_qpair_state {
128 : SPDK_NVMF_QPAIR_UNINITIALIZED = 0,
129 : SPDK_NVMF_QPAIR_CONNECTING,
130 : SPDK_NVMF_QPAIR_AUTHENTICATING,
131 : SPDK_NVMF_QPAIR_ENABLED,
132 : SPDK_NVMF_QPAIR_DEACTIVATING,
133 : SPDK_NVMF_QPAIR_ERROR,
134 : };
135 :
136 : typedef void (*spdk_nvmf_state_change_done)(void *cb_arg, int status);
137 :
138 : struct spdk_nvmf_qpair_auth;
139 :
140 : struct spdk_nvmf_qpair {
141 : uint8_t state; /* ref spdk_nvmf_qpair_state */
142 : uint8_t rsvd;
143 : uint16_t qid;
144 : uint16_t sq_head;
145 : uint16_t sq_head_max;
146 :
147 : struct spdk_nvmf_transport *transport;
148 : struct spdk_nvmf_ctrlr *ctrlr;
149 : struct spdk_nvmf_poll_group *group;
150 :
151 : union {
152 : struct spdk_nvmf_request *first_fused_req;
153 : struct spdk_nvmf_request *connect_req;
154 : };
155 :
156 : TAILQ_HEAD(, spdk_nvmf_request) outstanding;
157 : TAILQ_ENTRY(spdk_nvmf_qpair) link;
158 :
159 : spdk_nvmf_state_change_done state_cb;
160 : void *state_cb_arg;
161 :
162 : bool connect_received;
163 : bool disconnect_started;
164 :
165 : uint16_t trace_id;
166 :
167 : /* Number of IO outstanding at transport level */
168 : uint16_t queue_depth;
169 :
170 : struct spdk_nvmf_qpair_auth *auth;
171 : };
172 :
173 : struct spdk_nvmf_transport_poll_group {
174 : struct spdk_nvmf_transport *transport;
175 : /* Requests that are waiting to obtain a data buffer */
176 : STAILQ_HEAD(, spdk_nvmf_request) pending_buf_queue;
177 : struct spdk_iobuf_channel *buf_cache;
178 : struct spdk_nvmf_poll_group *group;
179 : TAILQ_ENTRY(spdk_nvmf_transport_poll_group) link;
180 : };
181 :
182 : struct spdk_nvmf_poll_group {
183 : struct spdk_thread *thread;
184 : struct spdk_poller *poller;
185 :
186 : TAILQ_HEAD(, spdk_nvmf_transport_poll_group) tgroups;
187 :
188 : /* Array of poll groups indexed by subsystem id (sid) */
189 : struct spdk_nvmf_subsystem_poll_group *sgroups;
190 : uint32_t num_sgroups;
191 :
192 : /* Protected by mutex. Counts qpairs that have connected at a
193 : * transport level, but are not associated with a subsystem
194 : * or controller yet (because the CONNECT capsule hasn't
195 : * been received). */
196 : uint32_t current_unassociated_qpairs;
197 :
198 : /* All of the queue pairs that belong to this poll group */
199 : TAILQ_HEAD(, spdk_nvmf_qpair) qpairs;
200 :
201 : /* Statistics */
202 : struct spdk_nvmf_poll_group_stat stat;
203 :
204 : spdk_nvmf_poll_group_destroy_done_fn destroy_cb_fn;
205 : void *destroy_cb_arg;
206 :
207 : struct spdk_nvmf_tgt *tgt;
208 :
209 : TAILQ_ENTRY(spdk_nvmf_poll_group) link;
210 :
211 : pthread_mutex_t mutex;
212 : };
213 :
214 : struct spdk_nvmf_listener {
215 : struct spdk_nvme_transport_id trid;
216 : uint32_t ref;
217 :
218 : TAILQ_ENTRY(spdk_nvmf_listener) link;
219 : };
220 :
221 : /**
222 : * A subset of struct spdk_nvme_ctrlr_data that are emulated by a fabrics device.
223 : */
224 : struct spdk_nvmf_ctrlr_data {
225 : uint8_t aerl;
226 : uint16_t kas;
227 : /** pci vendor id */
228 : uint16_t vid;
229 : /** pci subsystem vendor id */
230 : uint16_t ssvid;
231 : /** ieee oui identifier */
232 : uint8_t ieee[3];
233 : struct spdk_nvme_cdata_oacs oacs;
234 : struct spdk_nvme_cdata_oncs oncs;
235 : struct spdk_nvme_cdata_fuses fuses;
236 : struct spdk_nvme_cdata_sgls sgls;
237 : struct spdk_nvme_cdata_nvmf_specific nvmf_specific;
238 : };
239 :
240 : #define MAX_MEMPOOL_NAME_LENGTH 40
241 :
242 : /* abidiff has a problem with changes in spdk_nvmf_transport_opts, so spdk_nvmf_transport had to be
243 : * added to the suppression list, so if spdk_nvmf_transport is changed, we need to remove the
244 : * suppression and bump up the major version.
245 : */
246 : struct spdk_nvmf_transport {
247 : struct spdk_nvmf_tgt *tgt;
248 : const struct spdk_nvmf_transport_ops *ops;
249 : struct spdk_nvmf_transport_opts opts;
250 :
251 : char iobuf_name[MAX_MEMPOOL_NAME_LENGTH];
252 :
253 : TAILQ_HEAD(, spdk_nvmf_listener) listeners;
254 : TAILQ_ENTRY(spdk_nvmf_transport) link;
255 :
256 : pthread_mutex_t mutex;
257 : };
258 :
259 : typedef void (*spdk_nvmf_transport_qpair_fini_cb)(void *cb_arg);
260 :
261 : struct spdk_nvmf_transport_ops {
262 : /**
263 : * Transport name
264 : */
265 : char name[SPDK_NVMF_TRSTRING_MAX_LEN];
266 :
267 : /**
268 : * Transport type
269 : */
270 : enum spdk_nvme_transport_type type;
271 :
272 : /**
273 : * Initialize transport options to default value
274 : */
275 : void (*opts_init)(struct spdk_nvmf_transport_opts *opts);
276 :
277 : /**
278 : * Create a transport for the given transport opts. Either synchronous
279 : * or asynchronous version shall be implemented.
280 : */
281 : struct spdk_nvmf_transport *(*create)(struct spdk_nvmf_transport_opts *opts);
282 : int (*create_async)(struct spdk_nvmf_transport_opts *opts, spdk_nvmf_transport_create_done_cb cb_fn,
283 : void *cb_arg);
284 :
285 : /**
286 : * Dump transport-specific opts into JSON
287 : */
288 : void (*dump_opts)(struct spdk_nvmf_transport *transport,
289 : struct spdk_json_write_ctx *w);
290 :
291 : /**
292 : * Destroy the transport
293 : */
294 : int (*destroy)(struct spdk_nvmf_transport *transport,
295 : spdk_nvmf_transport_destroy_done_cb cb_fn, void *cb_arg);
296 :
297 : /**
298 : * Instruct the transport to accept new connections at the address
299 : * provided. This may be called multiple times.
300 : */
301 : int (*listen)(struct spdk_nvmf_transport *transport, const struct spdk_nvme_transport_id *trid,
302 : struct spdk_nvmf_listen_opts *opts);
303 :
304 : /**
305 : * Dump transport-specific listen opts into JSON
306 : */
307 : void (*listen_dump_opts)(struct spdk_nvmf_transport *transport,
308 : const struct spdk_nvme_transport_id *trid, struct spdk_json_write_ctx *w);
309 :
310 : /**
311 : * Stop accepting new connections at the given address.
312 : */
313 : void (*stop_listen)(struct spdk_nvmf_transport *transport,
314 : const struct spdk_nvme_transport_id *trid);
315 :
316 : /**
317 : * It is a notification that a listener is being associated with the subsystem.
318 : * Most transports will not need to take any action here, as the enforcement
319 : * of the association is done in the generic code.
320 : *
321 : * Returns a negated errno code to block the association. 0 to allow.
322 : */
323 : int (*listen_associate)(struct spdk_nvmf_transport *transport,
324 : const struct spdk_nvmf_subsystem *subsystem,
325 : const struct spdk_nvme_transport_id *trid);
326 :
327 : /**
328 : * It is a notification that a namespace is being added to the subsystem.
329 : * Most transports will not need to take any action here.
330 : *
331 : * Returns a negated errno code to block the attachment. 0 to allow.
332 : */
333 : int (*subsystem_add_ns)(struct spdk_nvmf_transport *transport,
334 : const struct spdk_nvmf_subsystem *subsystem, struct spdk_nvmf_ns *ns);
335 :
336 : /**
337 : * It is a notification that a namespace has been removed from the subsystem.
338 : * Most transports will not need to take any action here.
339 : */
340 : void (*subsystem_remove_ns)(struct spdk_nvmf_transport *transport,
341 : const struct spdk_nvmf_subsystem *subsystem, uint32_t nsid);
342 :
343 : /**
344 : * Initialize subset of identify controller data.
345 : */
346 : void (*cdata_init)(struct spdk_nvmf_transport *transport, struct spdk_nvmf_subsystem *subsystem,
347 : struct spdk_nvmf_ctrlr_data *cdata);
348 :
349 : /**
350 : * Fill out a discovery log entry for a specific listen address.
351 : */
352 : void (*listener_discover)(struct spdk_nvmf_transport *transport,
353 : struct spdk_nvme_transport_id *trid,
354 : struct spdk_nvmf_discovery_log_page_entry *entry);
355 :
356 : /**
357 : * Create a new poll group
358 : */
359 : struct spdk_nvmf_transport_poll_group *(*poll_group_create)(struct spdk_nvmf_transport *transport,
360 : struct spdk_nvmf_poll_group *group);
361 :
362 : /**
363 : * Get the polling group of the queue pair optimal for the specific transport
364 : */
365 : struct spdk_nvmf_transport_poll_group *(*get_optimal_poll_group)(struct spdk_nvmf_qpair *qpair);
366 :
367 : /**
368 : * Destroy a poll group
369 : */
370 : void (*poll_group_destroy)(struct spdk_nvmf_transport_poll_group *group);
371 :
372 : /**
373 : * Add a qpair to a poll group
374 : */
375 : int (*poll_group_add)(struct spdk_nvmf_transport_poll_group *group,
376 : struct spdk_nvmf_qpair *qpair);
377 :
378 : /**
379 : * Remove a qpair from a poll group
380 : */
381 : int (*poll_group_remove)(struct spdk_nvmf_transport_poll_group *group,
382 : struct spdk_nvmf_qpair *qpair);
383 :
384 : /**
385 : * Poll the group to process I/O
386 : */
387 : int (*poll_group_poll)(struct spdk_nvmf_transport_poll_group *group);
388 :
389 : /*
390 : * Free the request without sending a response
391 : * to the originator. Release memory tied to this request.
392 : */
393 : int (*req_free)(struct spdk_nvmf_request *req);
394 :
395 : /*
396 : * Signal request completion, which sends a response
397 : * to the originator.
398 : */
399 : int (*req_complete)(struct spdk_nvmf_request *req);
400 :
401 : /*
402 : * Deinitialize a connection.
403 : */
404 : void (*qpair_fini)(struct spdk_nvmf_qpair *qpair,
405 : spdk_nvmf_transport_qpair_fini_cb cb_fn,
406 : void *cb_args);
407 :
408 : /*
409 : * Get the peer transport ID for the queue pair.
410 : */
411 : int (*qpair_get_peer_trid)(struct spdk_nvmf_qpair *qpair,
412 : struct spdk_nvme_transport_id *trid);
413 :
414 : /*
415 : * Get the local transport ID for the queue pair.
416 : */
417 : int (*qpair_get_local_trid)(struct spdk_nvmf_qpair *qpair,
418 : struct spdk_nvme_transport_id *trid);
419 :
420 : /*
421 : * Get the listener transport ID that accepted this qpair originally.
422 : */
423 : int (*qpair_get_listen_trid)(struct spdk_nvmf_qpair *qpair,
424 : struct spdk_nvme_transport_id *trid);
425 :
426 : /*
427 : * Abort the request which the abort request specifies.
428 : * This function can complete synchronously or asynchronously, but
429 : * is expected to call spdk_nvmf_request_complete() in the end
430 : * for both cases.
431 : */
432 : void (*qpair_abort_request)(struct spdk_nvmf_qpair *qpair,
433 : struct spdk_nvmf_request *req);
434 :
435 : /*
436 : * Dump transport poll group statistics into JSON.
437 : */
438 : void (*poll_group_dump_stat)(struct spdk_nvmf_transport_poll_group *group,
439 : struct spdk_json_write_ctx *w);
440 :
441 : /*
442 : * A notification that a subsystem has been configured to allow access
443 : * from the given host.
444 : * This callback is optional and not all transports need to implement it.
445 : */
446 : int (*subsystem_add_host)(struct spdk_nvmf_transport *transport,
447 : const struct spdk_nvmf_subsystem *subsystem,
448 : const char *hostnqn,
449 : const struct spdk_json_val *transport_specific);
450 :
451 : /*
452 : * A notification that a subsystem is no longer configured to allow access
453 : * from the given host.
454 : * This callback is optional and not all transports need to implement it.
455 : */
456 : void (*subsystem_remove_host)(struct spdk_nvmf_transport *transport,
457 : const struct spdk_nvmf_subsystem *subsystem,
458 : const char *hostnqn);
459 :
460 : /*
461 : * A callback used to dump subsystem's host data for a specific transport.
462 : * This callback is optional and not all transports need to implement it.
463 : */
464 : void (*subsystem_dump_host)(struct spdk_nvmf_transport *transport,
465 : const struct spdk_nvmf_subsystem *subsystem,
466 : const char *hostnqn, struct spdk_json_write_ctx *w);
467 : };
468 :
469 : /**
470 : * Register the operations for a given transport type.
471 : *
472 : * This function should be invoked by referencing the macro
473 : * SPDK_NVMF_TRANSPORT_REGISTER macro in the transport's .c file.
474 : *
475 : * \param ops The operations associated with an NVMe-oF transport.
476 : */
477 : void spdk_nvmf_transport_register(const struct spdk_nvmf_transport_ops *ops);
478 :
479 : int spdk_nvmf_ctrlr_connect(struct spdk_nvmf_request *req);
480 :
481 : /**
482 : * Function to be called for each newly discovered qpair.
483 : *
484 : * \param tgt The nvmf target
485 : * \param qpair The newly discovered qpair.
486 : */
487 : void spdk_nvmf_tgt_new_qpair(struct spdk_nvmf_tgt *tgt, struct spdk_nvmf_qpair *qpair);
488 :
489 : static inline bool
490 53 : spdk_nvmf_qpair_is_active(struct spdk_nvmf_qpair *qpair)
491 : {
492 94 : return qpair->state == SPDK_NVMF_QPAIR_CONNECTING ||
493 94 : qpair->state == SPDK_NVMF_QPAIR_AUTHENTICATING ||
494 41 : qpair->state == SPDK_NVMF_QPAIR_ENABLED;
495 : }
496 :
497 : /**
498 : * A subset of struct spdk_nvme_registers that are emulated by a fabrics device.
499 : */
500 : struct spdk_nvmf_registers {
501 : union spdk_nvme_cap_register cap;
502 : union spdk_nvme_vs_register vs;
503 : union spdk_nvme_cc_register cc;
504 : union spdk_nvme_csts_register csts;
505 : union spdk_nvme_aqa_register aqa;
506 : uint64_t asq;
507 : uint64_t acq;
508 : };
509 : SPDK_STATIC_ASSERT(sizeof(struct spdk_nvmf_registers) == 40, "Incorrect size");
510 :
511 : const struct spdk_nvmf_registers *spdk_nvmf_ctrlr_get_regs(struct spdk_nvmf_ctrlr *ctrlr);
512 :
513 : void spdk_nvmf_request_free_buffers(struct spdk_nvmf_request *req,
514 : struct spdk_nvmf_transport_poll_group *group,
515 : struct spdk_nvmf_transport *transport);
516 : int spdk_nvmf_request_get_buffers(struct spdk_nvmf_request *req,
517 : struct spdk_nvmf_transport_poll_group *group,
518 : struct spdk_nvmf_transport *transport,
519 : uint32_t length);
520 :
521 : bool spdk_nvmf_request_get_dif_ctx(struct spdk_nvmf_request *req, struct spdk_dif_ctx *dif_ctx);
522 :
523 : void spdk_nvmf_request_exec(struct spdk_nvmf_request *req);
524 : void spdk_nvmf_request_exec_fabrics(struct spdk_nvmf_request *req);
525 : int spdk_nvmf_request_free(struct spdk_nvmf_request *req);
526 : int spdk_nvmf_request_complete(struct spdk_nvmf_request *req);
527 : void spdk_nvmf_request_zcopy_start(struct spdk_nvmf_request *req);
528 : void spdk_nvmf_request_zcopy_end(struct spdk_nvmf_request *req, bool commit);
529 :
530 : static inline bool
531 8 : spdk_nvmf_request_using_zcopy(const struct spdk_nvmf_request *req)
532 : {
533 8 : return req->zcopy_phase != NVMF_ZCOPY_PHASE_NONE;
534 : }
535 :
536 : /**
537 : * Remove the given qpair from the poll group.
538 : *
539 : * \param qpair The qpair to remove.
540 : */
541 : void spdk_nvmf_poll_group_remove(struct spdk_nvmf_qpair *qpair);
542 :
543 : /**
544 : * Get the NVMe-oF subsystem associated with this controller.
545 : *
546 : * \param ctrlr The NVMe-oF controller
547 : *
548 : * \return The NVMe-oF subsystem
549 : */
550 : struct spdk_nvmf_subsystem *
551 : spdk_nvmf_ctrlr_get_subsystem(struct spdk_nvmf_ctrlr *ctrlr);
552 :
553 : /**
554 : * Get the NVMe-oF controller ID.
555 : *
556 : * \param ctrlr The NVMe-oF controller
557 : *
558 : * \return The NVMe-oF controller ID
559 : */
560 : uint16_t spdk_nvmf_ctrlr_get_id(struct spdk_nvmf_ctrlr *ctrlr);
561 :
562 : struct spdk_nvmf_ctrlr_feat {
563 : union spdk_nvme_feat_arbitration arbitration;
564 : union spdk_nvme_feat_power_management power_management;
565 : union spdk_nvme_feat_error_recovery error_recovery;
566 : union spdk_nvme_feat_volatile_write_cache volatile_write_cache;
567 : union spdk_nvme_feat_number_of_queues number_of_queues;
568 : union spdk_nvme_feat_interrupt_coalescing interrupt_coalescing;
569 : union spdk_nvme_feat_interrupt_vector_configuration interrupt_vector_configuration;
570 : union spdk_nvme_feat_write_atomicity write_atomicity;
571 : union spdk_nvme_feat_async_event_configuration async_event_configuration;
572 : union spdk_nvme_feat_keep_alive_timer keep_alive_timer;
573 : };
574 : SPDK_STATIC_ASSERT(sizeof(struct spdk_nvmf_ctrlr_feat) == 40, "Incorrect size");
575 :
576 : /*
577 : * Migration data structure used to save & restore a NVMe-oF controller.
578 : *
579 : * The data structure is experimental.
580 : *
581 : */
582 : struct spdk_nvmf_ctrlr_migr_data {
583 : /* `data_size` is valid size of `spdk_nvmf_ctrlr_migr_data` without counting `unused`.
584 : * We use this field to migrate `spdk_nvmf_ctrlr_migr_data` from source VM and restore
585 : * it in destination VM.
586 : */
587 : uint32_t data_size;
588 : /* `regs_size` is valid size of `spdk_nvmf_registers`. */
589 : uint32_t regs_size;
590 : /* `feat_size` is valid size of `spdk_nvmf_ctrlr_feat`. */
591 : uint32_t feat_size;
592 : uint32_t reserved;
593 :
594 : struct spdk_nvmf_registers regs;
595 : uint8_t regs_reserved[216];
596 :
597 : struct spdk_nvmf_ctrlr_feat feat;
598 : uint8_t feat_reserved[216];
599 :
600 : uint16_t cntlid;
601 : uint8_t acre;
602 : uint8_t num_aer_cids;
603 : uint32_t num_async_events;
604 :
605 : union spdk_nvme_async_event_completion async_events[SPDK_NVMF_MIGR_MAX_PENDING_AERS];
606 : uint16_t aer_cids[SPDK_NVMF_MAX_ASYNC_EVENTS];
607 : uint64_t notice_aen_mask;
608 :
609 : uint8_t unused[2516];
610 : };
611 : SPDK_STATIC_ASSERT(offsetof(struct spdk_nvmf_ctrlr_migr_data,
612 : regs) - offsetof(struct spdk_nvmf_ctrlr_migr_data, data_size) == 16, "Incorrect header size");
613 : SPDK_STATIC_ASSERT(offsetof(struct spdk_nvmf_ctrlr_migr_data,
614 : feat) - offsetof(struct spdk_nvmf_ctrlr_migr_data, regs) == 256, "Incorrect regs size");
615 : SPDK_STATIC_ASSERT(offsetof(struct spdk_nvmf_ctrlr_migr_data,
616 : cntlid) - offsetof(struct spdk_nvmf_ctrlr_migr_data, feat) == 256, "Incorrect feat size");
617 : SPDK_STATIC_ASSERT(sizeof(struct spdk_nvmf_ctrlr_migr_data) == 4096, "Incorrect size");
618 :
619 : /**
620 : * Save the NVMe-oF controller state and configuration.
621 : *
622 : * The API is experimental.
623 : *
624 : * It is allowed to save the data only when the nvmf subystem is in paused
625 : * state i.e. there are no outstanding cmds in nvmf layer (other than aer),
626 : * pending async event completions are getting blocked.
627 : *
628 : * To preserve thread safety this function must be executed on the same thread
629 : * the NVMe-OF controller was created.
630 : *
631 : * \param ctrlr The NVMe-oF controller
632 : * \param data The NVMe-oF controller state and configuration to be saved
633 : *
634 : * \return 0 on success or a negated errno on failure.
635 : */
636 : int spdk_nvmf_ctrlr_save_migr_data(struct spdk_nvmf_ctrlr *ctrlr,
637 : struct spdk_nvmf_ctrlr_migr_data *data);
638 :
639 : /**
640 : * Restore the NVMe-oF controller state and configuration.
641 : *
642 : * The API is experimental.
643 : *
644 : * It is allowed to restore the data only when the nvmf subystem is in paused
645 : * state.
646 : *
647 : * To preserve thread safety this function must be executed on the same thread
648 : * the NVMe-OF controller was created.
649 : *
650 : * AERs shall be restored using spdk_nvmf_request_exec after this function is executed.
651 : *
652 : * \param ctrlr The NVMe-oF controller
653 : * \param data The NVMe-oF controller state and configuration to be restored
654 : *
655 : * \return 0 on success or a negated errno on failure.
656 : */
657 : int spdk_nvmf_ctrlr_restore_migr_data(struct spdk_nvmf_ctrlr *ctrlr,
658 : const struct spdk_nvmf_ctrlr_migr_data *data);
659 :
660 : static inline enum spdk_nvme_data_transfer
661 10 : spdk_nvmf_req_get_xfer(struct spdk_nvmf_request *req) {
662 : enum spdk_nvme_data_transfer xfer;
663 10 : struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
664 10 : struct spdk_nvme_sgl_descriptor *sgl = &cmd->dptr.sgl1;
665 :
666 : /* Figure out data transfer direction */
667 10 : if (cmd->opc == SPDK_NVME_OPC_FABRIC)
668 : {
669 2 : xfer = spdk_nvme_opc_get_data_transfer(req->cmd->nvmf_cmd.fctype);
670 : } else
671 : {
672 8 : xfer = spdk_nvme_opc_get_data_transfer(cmd->opc);
673 : }
674 :
675 10 : if (xfer == SPDK_NVME_DATA_NONE)
676 : {
677 0 : return xfer;
678 : }
679 :
680 : /* Even for commands that may transfer data, they could have specified 0 length.
681 : * We want those to show up with xfer SPDK_NVME_DATA_NONE.
682 : */
683 10 : switch (sgl->generic.type)
684 : {
685 4 : case SPDK_NVME_SGL_TYPE_DATA_BLOCK:
686 : case SPDK_NVME_SGL_TYPE_BIT_BUCKET:
687 : case SPDK_NVME_SGL_TYPE_SEGMENT:
688 : case SPDK_NVME_SGL_TYPE_LAST_SEGMENT:
689 : case SPDK_NVME_SGL_TYPE_TRANSPORT_DATA_BLOCK:
690 4 : if (sgl->unkeyed.length == 0) {
691 0 : xfer = SPDK_NVME_DATA_NONE;
692 : }
693 4 : break;
694 6 : case SPDK_NVME_SGL_TYPE_KEYED_DATA_BLOCK:
695 6 : if (sgl->keyed.length == 0) {
696 0 : xfer = SPDK_NVME_DATA_NONE;
697 : }
698 6 : break;
699 : }
700 :
701 10 : return xfer;
702 : }
703 :
704 : /**
705 : * Complete Asynchronous Event as Error.
706 : *
707 : * \param ctrlr Controller whose AER is going to be completed.
708 : * \param info Asynchronous Event Error Information to be reported.
709 : *
710 : * \return int. 0 if it completed successfully, or negative errno if it failed.
711 : */
712 : int spdk_nvmf_ctrlr_async_event_error_event(struct spdk_nvmf_ctrlr *ctrlr,
713 : enum spdk_nvme_async_event_info_error info);
714 :
715 : /**
716 : * Abort outstanding Asynchronous Event Requests (AERs).
717 : *
718 : * Completes AERs with ABORTED_BY_REQUEST status code.
719 : *
720 : * \param ctrlr Controller whose AERs are going to be aborted.
721 : */
722 : void spdk_nvmf_ctrlr_abort_aer(struct spdk_nvmf_ctrlr *ctrlr);
723 :
724 : /*
725 : * Macro used to register new transports.
726 : */
727 : #define SPDK_NVMF_TRANSPORT_REGISTER(name, transport_ops) \
728 : static void __attribute__((constructor)) _spdk_nvmf_transport_register_##name(void) \
729 : { \
730 : spdk_nvmf_transport_register(transport_ops); \
731 : }
732 :
733 : #ifdef __cplusplus
734 : }
735 : #endif
736 :
737 : #endif
|