f-stack/dpdk/drivers/net/virtio/virtio_user/virtio_user_dev.h

86 lines
2.7 KiB
C
Raw Normal View History

2019-06-25 11:12:58 +00:00
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2010-2016 Intel Corporation
2017-04-21 10:43:26 +00:00
*/
#ifndef _VIRTIO_USER_DEV_H
#define _VIRTIO_USER_DEV_H
#include <limits.h>
2019-06-25 11:12:58 +00:00
#include <stdbool.h>
2017-04-21 10:43:26 +00:00
#include "../virtio_pci.h"
#include "../virtio_ring.h"
2020-06-18 16:55:50 +00:00
2021-02-05 08:48:47 +00:00
enum virtio_user_backend_type {
VIRTIO_USER_BACKEND_UNKNOWN,
VIRTIO_USER_BACKEND_VHOST_USER,
VIRTIO_USER_BACKEND_VHOST_KERNEL,
VIRTIO_USER_BACKEND_VHOST_VDPA,
};
2020-06-18 16:55:50 +00:00
struct virtio_user_queue {
uint16_t used_idx;
bool avail_wrap_counter;
bool used_wrap_counter;
};
2017-04-21 10:43:26 +00:00
struct virtio_user_dev {
2021-02-05 08:48:47 +00:00
enum virtio_user_backend_type backend_type;
/* for vhost_user backend */
2017-04-21 10:43:26 +00:00
int vhostfd;
2019-06-25 11:12:58 +00:00
int listenfd; /* listening fd */
bool is_server; /* server or client mode */
/* for vhost_kernel backend */
char *ifname;
int *vhostfds;
int *tapfds;
/* for both vhost_user and vhost_kernel */
int callfds[VIRTIO_MAX_VIRTQUEUES];
int kickfds[VIRTIO_MAX_VIRTQUEUES];
2017-04-21 10:43:26 +00:00
int mac_specified;
uint32_t max_queue_pairs;
uint32_t queue_pairs;
uint32_t queue_size;
uint64_t features; /* the negotiated features with driver,
* and will be sync with device
*/
uint64_t device_features; /* supported features by device */
2019-06-25 11:12:58 +00:00
uint64_t frontend_features; /* enabled frontend features */
uint64_t unsupported_features; /* unsupported features mask */
2022-09-02 04:40:05 +00:00
uint64_t protocol_features; /* negotiated protocol features */
2017-04-21 10:43:26 +00:00
uint8_t status;
2021-01-28 17:08:59 +00:00
uint16_t net_status;
2019-06-25 11:12:58 +00:00
uint16_t port_id;
2020-06-18 16:55:50 +00:00
uint8_t mac_addr[RTE_ETHER_ADDR_LEN];
2017-04-21 10:43:26 +00:00
char path[PATH_MAX];
2020-06-18 16:55:50 +00:00
union {
struct vring vrings[VIRTIO_MAX_VIRTQUEUES];
struct vring_packed packed_vrings[VIRTIO_MAX_VIRTQUEUES];
};
struct virtio_user_queue packed_queues[VIRTIO_MAX_VIRTQUEUES];
bool qp_enabled[VIRTIO_MAX_VIRTQUEUE_PAIRS];
struct virtio_user_backend_ops *ops;
2019-06-25 11:12:58 +00:00
pthread_mutex_t mutex;
bool started;
2017-04-21 10:43:26 +00:00
};
2021-02-05 08:48:47 +00:00
int virtio_user_dev_set_features(struct virtio_user_dev *dev);
2017-04-21 10:43:26 +00:00
int virtio_user_start_device(struct virtio_user_dev *dev);
int virtio_user_stop_device(struct virtio_user_dev *dev);
int virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues,
2019-06-25 11:12:58 +00:00
int cq, int queue_size, const char *mac, char **ifname,
2020-06-18 16:55:50 +00:00
int server, int mrg_rxbuf, int in_order,
2021-02-05 08:48:47 +00:00
int packed_vq,
enum virtio_user_backend_type backend_type);
2017-04-21 10:43:26 +00:00
void virtio_user_dev_uninit(struct virtio_user_dev *dev);
void virtio_user_handle_cq(struct virtio_user_dev *dev, uint16_t queue_idx);
2020-06-18 16:55:50 +00:00
void virtio_user_handle_cq_packed(struct virtio_user_dev *dev,
uint16_t queue_idx);
2019-06-25 11:12:58 +00:00
uint8_t virtio_user_handle_mq(struct virtio_user_dev *dev, uint16_t q_pairs);
2021-02-05 08:48:47 +00:00
int virtio_user_dev_set_status(struct virtio_user_dev *dev, uint8_t status);
int virtio_user_dev_update_status(struct virtio_user_dev *dev);
extern const char * const virtio_user_backend_strings[];
2017-04-21 10:43:26 +00:00
#endif