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