New upstream version 18.11-rc1
[deb_dpdk.git] / lib / librte_vhost / rte_vdpa.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Intel Corporation
3  */
4
5 #ifndef _RTE_VDPA_H_
6 #define _RTE_VDPA_H_
7
8 /**
9  * @file
10  *
11  * Device specific vhost lib
12  */
13
14 #include <rte_pci.h>
15 #include "rte_vhost.h"
16
17 #define MAX_VDPA_NAME_LEN 128
18
19 enum vdpa_addr_type {
20         PCI_ADDR,
21         VDPA_ADDR_MAX
22 };
23
24 /**
25  * vdpa device address
26  */
27 struct rte_vdpa_dev_addr {
28         /** vdpa address type */
29         enum vdpa_addr_type type;
30
31         /** vdpa pci address */
32         union {
33                 uint8_t __dummy[64];
34                 struct rte_pci_addr pci_addr;
35         };
36 };
37
38 /**
39  * vdpa device operations
40  */
41 struct rte_vdpa_dev_ops {
42         /** Get capabilities of this device */
43         int (*get_queue_num)(int did, uint32_t *queue_num);
44
45         /** Get supported features of this device */
46         int (*get_features)(int did, uint64_t *features);
47
48         /** Get supported protocol features of this device */
49         int (*get_protocol_features)(int did, uint64_t *protocol_features);
50
51         /** Driver configure/close the device */
52         int (*dev_conf)(int vid);
53         int (*dev_close)(int vid);
54
55         /** Enable/disable this vring */
56         int (*set_vring_state)(int vid, int vring, int state);
57
58         /** Set features when changed */
59         int (*set_features)(int vid);
60
61         /** Destination operations when migration done */
62         int (*migration_done)(int vid);
63
64         /** Get the vfio group fd */
65         int (*get_vfio_group_fd)(int vid);
66
67         /** Get the vfio device fd */
68         int (*get_vfio_device_fd)(int vid);
69
70         /** Get the notify area info of the queue */
71         int (*get_notify_area)(int vid, int qid,
72                         uint64_t *offset, uint64_t *size);
73
74         /** Reserved for future extension */
75         void *reserved[5];
76 };
77
78 /**
79  * vdpa device structure includes device address and device operations.
80  */
81 struct rte_vdpa_device {
82         /** vdpa device address */
83         struct rte_vdpa_dev_addr addr;
84         /** vdpa device operations */
85         struct rte_vdpa_dev_ops *ops;
86 } __rte_cache_aligned;
87
88 /**
89  * @warning
90  * @b EXPERIMENTAL: this API may change without prior notice
91  *
92  * Register a vdpa device
93  *
94  * @param addr
95  *  the vdpa device address
96  * @param ops
97  *  the vdpa device operations
98  * @return
99  *  device id on success, -1 on failure
100  */
101 int __rte_experimental
102 rte_vdpa_register_device(struct rte_vdpa_dev_addr *addr,
103                 struct rte_vdpa_dev_ops *ops);
104
105 /**
106  * @warning
107  * @b EXPERIMENTAL: this API may change without prior notice
108  *
109  * Unregister a vdpa device
110  *
111  * @param did
112  *  vdpa device id
113  * @return
114  *  device id on success, -1 on failure
115  */
116 int __rte_experimental
117 rte_vdpa_unregister_device(int did);
118
119 /**
120  * @warning
121  * @b EXPERIMENTAL: this API may change without prior notice
122  *
123  * Find the device id of a vdpa device
124  *
125  * @param addr
126  *  the vdpa device address
127  * @return
128  *  device id on success, -1 on failure
129  */
130 int __rte_experimental
131 rte_vdpa_find_device_id(struct rte_vdpa_dev_addr *addr);
132
133 /**
134  * @warning
135  * @b EXPERIMENTAL: this API may change without prior notice
136  *
137  * Find a vdpa device based on device id
138  *
139  * @param did
140  *  device id
141  * @return
142  *  rte_vdpa_device on success, NULL on failure
143  */
144 struct rte_vdpa_device * __rte_experimental
145 rte_vdpa_get_device(int did);
146
147 /**
148  * @warning
149  * @b EXPERIMENTAL: this API may change without prior notice
150  *
151  * Get current available vdpa device number
152  *
153  * @return
154  *  available vdpa device number
155  */
156 int __rte_experimental
157 rte_vdpa_get_device_num(void);
158 #endif /* _RTE_VDPA_H_ */