e55e3329f99348c3b17aac08bf2594ee9e31a8e6
[dpdk.git] / drivers / net / virtio / virtio.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 Intel Corporation
3  * Copyright(c) 2021 Red Hat, Inc.
4  */
5
6 #ifndef _VIRTIO_H_
7 #define _VIRTIO_H_
8
9 #include <rte_ether.h>
10
11 struct virtio_hw {
12         struct virtqueue **vqs;
13         uint64_t guest_features;
14         uint16_t vtnet_hdr_size;
15         uint8_t started;
16         uint8_t weak_barriers;
17         uint8_t vlan_strip;
18         uint8_t has_tx_offload;
19         uint8_t has_rx_offload;
20         uint8_t use_vec_rx;
21         uint8_t use_vec_tx;
22         uint8_t use_inorder_rx;
23         uint8_t use_inorder_tx;
24         uint8_t opened;
25         uint16_t port_id;
26         uint8_t mac_addr[RTE_ETHER_ADDR_LEN];
27         uint32_t speed;  /* link speed in MB */
28         uint8_t duplex;
29         uint8_t use_msix;
30         uint16_t max_mtu;
31         /*
32          * App management thread and virtio interrupt handler thread
33          * both can change device state, this lock is meant to avoid
34          * such a contention.
35          */
36         rte_spinlock_t state_lock;
37         struct rte_mbuf **inject_pkts;
38         uint16_t max_queue_pairs;
39         uint64_t req_guest_features;
40         struct virtnet_ctl *cvq;
41 };
42
43 struct virtio_ops {
44         void (*read_dev_cfg)(struct virtio_hw *hw, size_t offset, void *dst, int len);
45         void (*write_dev_cfg)(struct virtio_hw *hw, size_t offset, const void *src, int len);
46         uint8_t (*get_status)(struct virtio_hw *hw);
47         void (*set_status)(struct virtio_hw *hw, uint8_t status);
48         uint64_t (*get_features)(struct virtio_hw *hw);
49         void (*set_features)(struct virtio_hw *hw, uint64_t features);
50         int (*features_ok)(struct virtio_hw *hw);
51         uint8_t (*get_isr)(struct virtio_hw *hw);
52         uint16_t (*set_config_irq)(struct virtio_hw *hw, uint16_t vec);
53         uint16_t (*set_queue_irq)(struct virtio_hw *hw, struct virtqueue *vq, uint16_t vec);
54         uint16_t (*get_queue_num)(struct virtio_hw *hw, uint16_t queue_id);
55         int (*setup_queue)(struct virtio_hw *hw, struct virtqueue *vq);
56         void (*del_queue)(struct virtio_hw *hw, struct virtqueue *vq);
57         void (*notify_queue)(struct virtio_hw *hw, struct virtqueue *vq);
58         void (*intr_detect)(struct virtio_hw *hw);
59         int (*dev_close)(struct virtio_hw *hw);
60 };
61
62 /*
63  * This structure stores per-process data. Only virtio_ops for now.
64  */
65 struct virtio_hw_internal {
66         const struct virtio_ops *virtio_ops;
67 };
68
69 #define VIRTIO_OPS(hw)  (virtio_hw_internal[(hw)->port_id].virtio_ops)
70
71 extern struct virtio_hw_internal virtio_hw_internal[RTE_MAX_ETHPORTS];
72
73
74 #endif /* _VIRTIO_H_ */