LCOV - code coverage report
Current view: top level - lib/vhost - vhost_internal.h (source / functions) Hit Total Coverage
Test: ut_cov_unit.info Lines: 4 6 66.7 %
Date: 2024-07-14 01:39:21 Functions: 1 2 50.0 %

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

Generated by: LCOV version 1.15