1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright (C) 2017 Intel Corporation. 3 * All rights reserved. 4 */ 5 6 #ifndef SPDK_VHOST_INTERNAL_H 7 #define SPDK_VHOST_INTERNAL_H 8 #include <linux/virtio_config.h> 9 10 #include "spdk/stdinc.h" 11 12 #include <rte_vhost.h> 13 14 #include "spdk_internal/vhost_user.h" 15 #include "spdk/bdev.h" 16 #include "spdk/log.h" 17 #include "spdk/util.h" 18 #include "spdk/rpc.h" 19 #include "spdk/config.h" 20 21 #define SPDK_VHOST_MAX_VQUEUES 256 22 #define SPDK_VHOST_MAX_VQ_SIZE 1024 23 24 #define SPDK_VHOST_SCSI_CTRLR_MAX_DEVS 8 25 26 #define SPDK_VHOST_IOVS_MAX 129 27 28 #define SPDK_VHOST_VQ_MAX_SUBMISSIONS 32 29 30 /* 31 * Rate at which stats are checked for interrupt coalescing. 32 */ 33 #define SPDK_VHOST_STATS_CHECK_INTERVAL_MS 10 34 /* 35 * Default threshold at which interrupts start to be coalesced. 36 */ 37 #define SPDK_VHOST_VQ_IOPS_COALESCING_THRESHOLD 60000 38 39 /* 40 * Currently coalescing is not used by default. 41 * Setting this to value > 0 here or by RPC will enable coalescing. 42 */ 43 #define SPDK_VHOST_COALESCING_DELAY_BASE_US 0 44 45 #define SPDK_VHOST_FEATURES ((1ULL << VHOST_F_LOG_ALL) | \ 46 (1ULL << VHOST_USER_F_PROTOCOL_FEATURES) | \ 47 (1ULL << VIRTIO_F_VERSION_1) | \ 48 (1ULL << VIRTIO_F_NOTIFY_ON_EMPTY) | \ 49 (1ULL << VIRTIO_RING_F_EVENT_IDX) | \ 50 (1ULL << VIRTIO_RING_F_INDIRECT_DESC) | \ 51 (1ULL << VIRTIO_F_RING_PACKED) | \ 52 (1ULL << VIRTIO_F_ANY_LAYOUT)) 53 54 #define SPDK_VHOST_DISABLED_FEATURES ((1ULL << VIRTIO_RING_F_EVENT_IDX) | \ 55 (1ULL << VIRTIO_F_NOTIFY_ON_EMPTY)) 56 57 #define VRING_DESC_F_AVAIL (1ULL << VRING_PACKED_DESC_F_AVAIL) 58 #define VRING_DESC_F_USED (1ULL << VRING_PACKED_DESC_F_USED) 59 #define VRING_DESC_F_AVAIL_USED (VRING_DESC_F_AVAIL | VRING_DESC_F_USED) 60 61 typedef struct rte_vhost_resubmit_desc spdk_vhost_resubmit_desc; 62 typedef struct rte_vhost_resubmit_info spdk_vhost_resubmit_info; 63 typedef struct rte_vhost_inflight_desc_packed spdk_vhost_inflight_desc; 64 65 struct spdk_vhost_virtqueue { 66 struct rte_vhost_vring vring; 67 struct rte_vhost_ring_inflight vring_inflight; 68 uint16_t last_avail_idx; 69 uint16_t last_used_idx; 70 71 struct { 72 /* To mark a descriptor as available in packed ring 73 * Equal to avail_wrap_counter in spec. 74 */ 75 uint8_t avail_phase : 1; 76 /* To mark a descriptor as used in packed ring 77 * Equal to used_wrap_counter in spec. 78 */ 79 uint8_t used_phase : 1; 80 uint8_t padding : 5; 81 bool packed_ring : 1; 82 } packed; 83 84 void *tasks; 85 86 /* Request count from last stats check */ 87 uint32_t req_cnt; 88 89 /* Request count from last event */ 90 uint16_t used_req_cnt; 91 92 /* How long interrupt is delayed */ 93 uint32_t irq_delay_time; 94 95 /* Next time when we need to send event */ 96 uint64_t next_event_time; 97 98 /* Associated vhost_virtqueue in the virtio device's virtqueue list */ 99 uint32_t vring_idx; 100 101 struct spdk_vhost_session *vsession; 102 103 struct spdk_interrupt *intr; 104 } __attribute((aligned(SPDK_CACHE_LINE_SIZE))); 105 106 struct spdk_vhost_session { 107 struct spdk_vhost_dev *vdev; 108 109 /* rte_vhost connection ID. */ 110 int vid; 111 112 /* Unique session ID. */ 113 uint64_t id; 114 /* Unique session name. */ 115 char *name; 116 117 bool started; 118 bool interrupt_mode; 119 120 struct rte_vhost_memory *mem; 121 122 int task_cnt; 123 124 uint16_t max_queues; 125 126 uint64_t negotiated_features; 127 128 /* Local copy of device coalescing settings. */ 129 uint32_t coalescing_delay_time_base; 130 uint32_t coalescing_io_rate_threshold; 131 132 /* Next time when stats for event coalescing will be checked. */ 133 uint64_t next_stats_check_time; 134 135 /* Interval used for event coalescing checking. */ 136 uint64_t stats_check_interval; 137 138 /* Session's stop poller will only try limited times to destroy the session. */ 139 uint32_t stop_retry_count; 140 141 struct spdk_vhost_virtqueue virtqueue[SPDK_VHOST_MAX_VQUEUES]; 142 143 TAILQ_ENTRY(spdk_vhost_session) tailq; 144 }; 145 146 struct spdk_vhost_user_dev { 147 struct spdk_vhost_dev *vdev; 148 149 const struct spdk_vhost_user_dev_backend *user_backend; 150 151 /* Saved original values used to setup coalescing to avoid integer 152 * rounding issues during save/load config. 153 */ 154 uint32_t coalescing_delay_us; 155 uint32_t coalescing_iops_threshold; 156 157 bool registered; 158 159 /* Current connections to the device */ 160 TAILQ_HEAD(, spdk_vhost_session) vsessions; 161 162 /* Increment-only session counter */ 163 uint64_t vsessions_num; 164 165 /* Number of started and actively polled sessions */ 166 uint32_t active_session_num; 167 168 /* Number of pending asynchronous operations */ 169 uint32_t pending_async_op_num; 170 }; 171 172 struct spdk_vhost_dev { 173 char *name; 174 char *path; 175 176 struct spdk_thread *thread; 177 178 uint64_t virtio_features; 179 uint64_t disabled_features; 180 uint64_t protocol_features; 181 bool packed_ring_recovery; 182 183 const struct spdk_vhost_dev_backend *backend; 184 185 /* Context passed from transport */ 186 void *ctxt; 187 188 TAILQ_ENTRY(spdk_vhost_dev) tailq; 189 }; 190 191 /** 192 * \param vdev vhost device. 193 * \param vsession vhost session. 194 * \param arg user-provided parameter. 195 * 196 * \return negative values will break the foreach call, meaning 197 * the function won't be called again. Return codes zero and 198 * positive don't have any effect. 199 */ 200 typedef int (*spdk_vhost_session_fn)(struct spdk_vhost_dev *vdev, 201 struct spdk_vhost_session *vsession, 202 void *arg); 203 204 /** 205 * \param vdev vhost device. 206 * \param arg user-provided parameter. 207 */ 208 typedef void (*spdk_vhost_dev_fn)(struct spdk_vhost_dev *vdev, void *arg); 209 210 struct spdk_vhost_user_dev_backend { 211 /** 212 * Size of additional per-session context data 213 * allocated whenever a new client connects. 214 */ 215 size_t session_ctx_size; 216 217 spdk_vhost_session_fn start_session; 218 int (*stop_session)(struct spdk_vhost_session *vsession); 219 int (*alloc_vq_tasks)(struct spdk_vhost_session *vsession, uint16_t qid); 220 }; 221 222 enum vhost_backend_type { 223 VHOST_BACKEND_BLK = 0, 224 VHOST_BACKEND_SCSI, 225 }; 226 227 struct spdk_vhost_dev_backend { 228 enum vhost_backend_type type; 229 230 int (*vhost_get_config)(struct spdk_vhost_dev *vdev, uint8_t *config, uint32_t len); 231 int (*vhost_set_config)(struct spdk_vhost_dev *vdev, uint8_t *config, 232 uint32_t offset, uint32_t size, uint32_t flags); 233 234 void (*dump_info_json)(struct spdk_vhost_dev *vdev, struct spdk_json_write_ctx *w); 235 void (*write_config_json)(struct spdk_vhost_dev *vdev, struct spdk_json_write_ctx *w); 236 int (*remove_device)(struct spdk_vhost_dev *vdev); 237 int (*set_coalescing)(struct spdk_vhost_dev *vdev, uint32_t delay_base_us, 238 uint32_t iops_threshold); 239 void (*get_coalescing)(struct spdk_vhost_dev *vdev, uint32_t *delay_base_us, 240 uint32_t *iops_threshold); 241 }; 242 243 void *vhost_gpa_to_vva(struct spdk_vhost_session *vsession, uint64_t addr, uint64_t len); 244 245 uint16_t vhost_vq_avail_ring_get(struct spdk_vhost_virtqueue *vq, uint16_t *reqs, 246 uint16_t reqs_len); 247 248 /** 249 * Get a virtio split descriptor at given index in given virtqueue. 250 * The descriptor will provide access to the entire descriptor 251 * chain. The subsequent descriptors are accessible via 252 * \c spdk_vhost_vring_desc_get_next. 253 * \param vsession vhost session 254 * \param vq virtqueue 255 * \param req_idx descriptor index 256 * \param desc pointer to be set to the descriptor 257 * \param desc_table descriptor table to be used with 258 * \c spdk_vhost_vring_desc_get_next. This might be either 259 * default virtqueue descriptor table or per-chain indirect 260 * table. 261 * \param desc_table_size size of the *desc_table* 262 * \return 0 on success, -1 if given index is invalid. 263 * If -1 is returned, the content of params is undefined. 264 */ 265 int vhost_vq_get_desc(struct spdk_vhost_session *vsession, struct spdk_vhost_virtqueue *vq, 266 uint16_t req_idx, struct vring_desc **desc, struct vring_desc **desc_table, 267 uint32_t *desc_table_size); 268 269 /** 270 * Get a virtio packed descriptor at given index in given virtqueue. 271 * The descriptor will provide access to the entire descriptor 272 * chain. The subsequent descriptors are accessible via 273 * \c vhost_vring_packed_desc_get_next. 274 * \param vsession vhost session 275 * \param vq virtqueue 276 * \param req_idx descriptor index 277 * \param desc pointer to be set to the descriptor 278 * \param desc_table descriptor table to be used with 279 * \c spdk_vhost_vring_desc_get_next. This might be either 280 * \c NULL or per-chain indirect table. 281 * \param desc_table_size size of the *desc_table* 282 * \return 0 on success, -1 if given index is invalid. 283 * If -1 is returned, the content of params is undefined. 284 */ 285 int vhost_vq_get_desc_packed(struct spdk_vhost_session *vsession, 286 struct spdk_vhost_virtqueue *virtqueue, 287 uint16_t req_idx, struct vring_packed_desc **desc, 288 struct vring_packed_desc **desc_table, uint32_t *desc_table_size); 289 290 int vhost_inflight_queue_get_desc(struct spdk_vhost_session *vsession, 291 spdk_vhost_inflight_desc *desc_array, 292 uint16_t req_idx, spdk_vhost_inflight_desc **desc, 293 struct vring_packed_desc **desc_table, uint32_t *desc_table_size); 294 295 /** 296 * Send IRQ/call client (if pending) for \c vq. 297 * \param vsession vhost session 298 * \param vq virtqueue 299 * \return 300 * 0 - if no interrupt was signalled 301 * 1 - if interrupt was signalled 302 */ 303 int vhost_vq_used_signal(struct spdk_vhost_session *vsession, struct spdk_vhost_virtqueue *vq); 304 305 /** 306 * Send IRQs for the queue that need to be signaled. 307 * \param vq virtqueue 308 */ 309 void vhost_session_vq_used_signal(struct spdk_vhost_virtqueue *virtqueue); 310 311 void vhost_vq_used_ring_enqueue(struct spdk_vhost_session *vsession, 312 struct spdk_vhost_virtqueue *vq, 313 uint16_t id, uint32_t len); 314 315 /** 316 * Enqueue the entry to the used ring when device complete the request. 317 * \param vsession vhost session 318 * \param vq virtqueue 319 * \req_idx descriptor index. It's the first index of this descriptor chain. 320 * \num_descs descriptor count. It's the count of the number of buffers in the chain. 321 * \buffer_id descriptor buffer ID. 322 * \length device write length. Specify the length of the buffer that has been initialized 323 * (written to) by the device 324 * \inflight_head the head idx of this IO inflight desc chain. 325 */ 326 void vhost_vq_packed_ring_enqueue(struct spdk_vhost_session *vsession, 327 struct spdk_vhost_virtqueue *virtqueue, 328 uint16_t num_descs, uint16_t buffer_id, 329 uint32_t length, uint16_t inflight_head); 330 331 /** 332 * Get subsequent descriptor from given table. 333 * \param desc current descriptor, will be set to the 334 * next descriptor (NULL in case this is the last 335 * descriptor in the chain or the next desc is invalid) 336 * \param desc_table descriptor table 337 * \param desc_table_size size of the *desc_table* 338 * \return 0 on success, -1 if given index is invalid 339 * The *desc* param will be set regardless of the 340 * return value. 341 */ 342 int vhost_vring_desc_get_next(struct vring_desc **desc, 343 struct vring_desc *desc_table, uint32_t desc_table_size); 344 static inline bool 345 vhost_vring_desc_is_wr(struct vring_desc *cur_desc) 346 { 347 return !!(cur_desc->flags & VRING_DESC_F_WRITE); 348 } 349 350 int vhost_vring_desc_to_iov(struct spdk_vhost_session *vsession, struct iovec *iov, 351 uint16_t *iov_index, const struct vring_desc *desc); 352 353 bool vhost_vq_packed_ring_is_avail(struct spdk_vhost_virtqueue *virtqueue); 354 355 /** 356 * Get subsequent descriptor from vq or desc table. 357 * \param desc current descriptor, will be set to the 358 * next descriptor (NULL in case this is the last 359 * descriptor in the chain or the next desc is invalid) 360 * \req_idx index of current desc, will be set to the next 361 * index. If desc_table != NULL the req_idx is the the vring index 362 * or the req_idx is the desc_table index. 363 * \param desc_table descriptor table 364 * \param desc_table_size size of the *desc_table* 365 * \return 0 on success, -1 if given index is invalid 366 * The *desc* param will be set regardless of the 367 * return value. 368 */ 369 int vhost_vring_packed_desc_get_next(struct vring_packed_desc **desc, uint16_t *req_idx, 370 struct spdk_vhost_virtqueue *vq, 371 struct vring_packed_desc *desc_table, 372 uint32_t desc_table_size); 373 374 bool vhost_vring_packed_desc_is_wr(struct vring_packed_desc *cur_desc); 375 376 int vhost_vring_packed_desc_to_iov(struct spdk_vhost_session *vsession, struct iovec *iov, 377 uint16_t *iov_index, const struct vring_packed_desc *desc); 378 379 bool vhost_vring_inflight_desc_is_wr(spdk_vhost_inflight_desc *cur_desc); 380 381 int vhost_vring_inflight_desc_to_iov(struct spdk_vhost_session *vsession, struct iovec *iov, 382 uint16_t *iov_index, const spdk_vhost_inflight_desc *desc); 383 384 uint16_t vhost_vring_packed_desc_get_buffer_id(struct spdk_vhost_virtqueue *vq, uint16_t req_idx, 385 uint16_t *num_descs); 386 387 static inline bool 388 __attribute__((always_inline)) 389 vhost_dev_has_feature(struct spdk_vhost_session *vsession, unsigned feature_id) 390 { 391 return vsession->negotiated_features & (1ULL << feature_id); 392 } 393 394 int vhost_dev_register(struct spdk_vhost_dev *vdev, const char *name, const char *mask_str, 395 const struct spdk_json_val *params, 396 const struct spdk_vhost_dev_backend *backend, 397 const struct spdk_vhost_user_dev_backend *user_backend); 398 int vhost_dev_unregister(struct spdk_vhost_dev *vdev); 399 400 void vhost_dump_info_json(struct spdk_vhost_dev *vdev, struct spdk_json_write_ctx *w); 401 402 /* 403 * Set vhost session to run in interrupt or poll mode 404 */ 405 void vhost_user_session_set_interrupt_mode(struct spdk_vhost_session *vsession, 406 bool interrupt_mode); 407 408 /* 409 * Memory registration functions used in start/stop device callbacks 410 */ 411 void vhost_session_mem_register(struct rte_vhost_memory *mem); 412 void vhost_session_mem_unregister(struct rte_vhost_memory *mem); 413 414 /* 415 * Call a function for each session of the provided vhost device. 416 * The function will be called one-by-one on each session's thread. 417 * 418 * \param vdev vhost device 419 * \param fn function to call on each session's thread 420 * \param cpl_fn function to be called at the end of the iteration on 421 * the vhost management thread. 422 * Optional, can be NULL. 423 * \param arg additional argument to the both callbacks 424 */ 425 void vhost_user_dev_foreach_session(struct spdk_vhost_dev *dev, 426 spdk_vhost_session_fn fn, 427 spdk_vhost_dev_fn cpl_fn, 428 void *arg); 429 430 /** 431 * Call a function on the provided lcore and block until either 432 * vhost_user_session_start_done() or vhost_user_session_stop_done() 433 * is called. 434 * 435 * This must be called under the global vhost mutex, which this function 436 * will unlock for the time it's waiting. It's meant to be called only 437 * from start/stop session callbacks. 438 * 439 * \param vsession vhost session 440 * \param cb_fn the function to call. The void *arg parameter in cb_fn 441 * is always NULL. 442 * \param timeout_sec timeout in seconds. This function will still 443 * block after the timeout expires, but will print the provided errmsg. 444 * \param errmsg error message to print once the timeout expires 445 * \return return the code passed to spdk_vhost_session_event_done(). 446 */ 447 int vhost_user_session_send_event(struct spdk_vhost_session *vsession, 448 spdk_vhost_session_fn cb_fn, unsigned timeout_sec, 449 const char *errmsg); 450 451 /** 452 * Finish a blocking spdk_vhost_user_session_send_event() call and finally 453 * start the session. This must be called on the target lcore, which 454 * will now receive all session-related messages (e.g. from 455 * vhost_user_dev_foreach_session()). 456 * 457 * Must be called under the global vhost lock. 458 * 459 * \param vsession vhost session 460 * \param response return code 461 */ 462 void vhost_user_session_start_done(struct spdk_vhost_session *vsession, int response); 463 464 /** 465 * Finish a blocking spdk_vhost_user_session_send_event() call and finally 466 * stop the session. This must be called on the session's lcore which 467 * used to receive all session-related messages (e.g. from 468 * vhost_user_dev_foreach_session()). After this call, the session- 469 * related messages will be once again processed by any arbitrary thread. 470 * 471 * Must be called under the global vhost lock. 472 * 473 * Must be called under the global vhost mutex. 474 * 475 * \param vsession vhost session 476 * \param response return code 477 */ 478 void vhost_user_session_stop_done(struct spdk_vhost_session *vsession, int response); 479 480 struct spdk_vhost_session *vhost_session_find_by_vid(int vid); 481 void vhost_session_install_rte_compat_hooks(struct spdk_vhost_session *vsession); 482 int vhost_register_unix_socket(const char *path, const char *ctrl_name, 483 uint64_t virtio_features, uint64_t disabled_features, uint64_t protocol_features); 484 int vhost_driver_unregister(const char *path); 485 int vhost_get_mem_table(int vid, struct rte_vhost_memory **mem); 486 int vhost_get_negotiated_features(int vid, uint64_t *negotiated_features); 487 488 int remove_vhost_controller(struct spdk_vhost_dev *vdev); 489 490 struct spdk_io_channel *vhost_blk_get_io_channel(struct spdk_vhost_dev *vdev); 491 void vhost_blk_put_io_channel(struct spdk_io_channel *ch); 492 493 /* The spdk_bdev pointer should only be used to retrieve 494 * the device properties, ex. number of blocks or I/O type supported. */ 495 struct spdk_bdev *vhost_blk_get_bdev(struct spdk_vhost_dev *vdev); 496 497 /* Function calls from vhost.c to rte_vhost_user.c, 498 * shall removed once virtio transport abstraction is complete. */ 499 int vhost_user_session_set_coalescing(struct spdk_vhost_dev *dev, 500 struct spdk_vhost_session *vsession, void *ctx); 501 int vhost_user_dev_set_coalescing(struct spdk_vhost_user_dev *user_dev, uint32_t delay_base_us, 502 uint32_t iops_threshold); 503 int vhost_user_dev_register(struct spdk_vhost_dev *vdev, const char *name, 504 struct spdk_cpuset *cpumask, const struct spdk_vhost_user_dev_backend *user_backend); 505 int vhost_user_dev_unregister(struct spdk_vhost_dev *vdev); 506 int vhost_user_init(void); 507 void vhost_user_fini(spdk_vhost_fini_cb vhost_cb); 508 int vhost_user_set_coalescing(struct spdk_vhost_dev *vdev, uint32_t delay_base_us, 509 uint32_t iops_threshold); 510 void vhost_user_get_coalescing(struct spdk_vhost_dev *vdev, uint32_t *delay_base_us, 511 uint32_t *iops_threshold); 512 513 int virtio_blk_construct_ctrlr(struct spdk_vhost_dev *vdev, const char *address, 514 struct spdk_cpuset *cpumask, const struct spdk_json_val *params, 515 const struct spdk_vhost_user_dev_backend *user_backend); 516 int virtio_blk_destroy_ctrlr(struct spdk_vhost_dev *vdev); 517 518 struct spdk_vhost_blk_task; 519 520 typedef void (*virtio_blk_request_cb)(uint8_t status, struct spdk_vhost_blk_task *task, 521 void *cb_arg); 522 523 struct spdk_vhost_blk_task { 524 struct spdk_bdev_io *bdev_io; 525 virtio_blk_request_cb cb; 526 void *cb_arg; 527 528 volatile uint8_t *status; 529 530 /* for io wait */ 531 struct spdk_bdev_io_wait_entry bdev_io_wait; 532 struct spdk_io_channel *bdev_io_wait_ch; 533 struct spdk_vhost_dev *bdev_io_wait_vdev; 534 535 /** Number of bytes that were written. */ 536 uint32_t used_len; 537 uint16_t iovcnt; 538 struct iovec iovs[SPDK_VHOST_IOVS_MAX]; 539 540 /** Size of whole payload in bytes */ 541 uint32_t payload_size; 542 }; 543 544 int virtio_blk_process_request(struct spdk_vhost_dev *vdev, struct spdk_io_channel *ch, 545 struct spdk_vhost_blk_task *task, virtio_blk_request_cb cb, void *cb_arg); 546 547 typedef void (*bdev_event_cb_complete)(struct spdk_vhost_dev *vdev, void *ctx); 548 549 #define SPDK_VIRTIO_BLK_TRSTRING_MAX_LEN 32 550 551 struct spdk_virtio_blk_transport_ops { 552 /** 553 * Transport name 554 */ 555 char name[SPDK_VIRTIO_BLK_TRSTRING_MAX_LEN]; 556 557 /** 558 * Create a transport for the given transport opts 559 */ 560 struct spdk_virtio_blk_transport *(*create)(const struct spdk_json_val *params); 561 562 /** 563 * Dump transport-specific opts into JSON 564 */ 565 void (*dump_opts)(struct spdk_virtio_blk_transport *transport, struct spdk_json_write_ctx *w); 566 567 /** 568 * Destroy the transport 569 */ 570 int (*destroy)(struct spdk_virtio_blk_transport *transport, 571 spdk_vhost_fini_cb cb_fn); 572 573 /** 574 * Create vhost block controller 575 */ 576 int (*create_ctrlr)(struct spdk_vhost_dev *vdev, struct spdk_cpuset *cpumask, 577 const char *address, const struct spdk_json_val *params, 578 void *custom_opts); 579 580 /** 581 * Destroy vhost block controller 582 */ 583 int (*destroy_ctrlr)(struct spdk_vhost_dev *vdev); 584 585 /* 586 * Signal removal of the bdev. 587 */ 588 void (*bdev_event)(enum spdk_bdev_event_type type, struct spdk_vhost_dev *vdev, 589 bdev_event_cb_complete cb, void *cb_arg); 590 591 /** 592 * Set coalescing parameters. 593 */ 594 int (*set_coalescing)(struct spdk_vhost_dev *vdev, uint32_t delay_base_us, 595 uint32_t iops_threshold); 596 597 /** 598 * Get coalescing parameters. 599 */ 600 void (*get_coalescing)(struct spdk_vhost_dev *vdev, uint32_t *delay_base_us, 601 uint32_t *iops_threshold); 602 }; 603 604 struct spdk_virtio_blk_transport { 605 const struct spdk_virtio_blk_transport_ops *ops; 606 TAILQ_ENTRY(spdk_virtio_blk_transport) tailq; 607 }; 608 609 struct virtio_blk_transport_ops_list_element { 610 struct spdk_virtio_blk_transport_ops ops; 611 TAILQ_ENTRY(virtio_blk_transport_ops_list_element) link; 612 }; 613 614 void virtio_blk_transport_register(const struct spdk_virtio_blk_transport_ops *ops); 615 int virtio_blk_transport_create(const char *transport_name, const struct spdk_json_val *params); 616 int virtio_blk_transport_destroy(struct spdk_virtio_blk_transport *transport, 617 spdk_vhost_fini_cb cb_fn); 618 619 const struct spdk_virtio_blk_transport_ops *virtio_blk_get_transport_ops( 620 const char *transport_name); 621 622 623 /* 624 * Macro used to register new transports. 625 */ 626 #define SPDK_VIRTIO_BLK_TRANSPORT_REGISTER(name, transport_ops) \ 627 static void __attribute__((constructor)) _virtio_blk_transport_register_##name(void) \ 628 { \ 629 virtio_blk_transport_register(transport_ops); \ 630 } 631 632 #endif /* SPDK_VHOST_INTERNAL_H */ 633