xref: /illumos-gate/usr/src/uts/intel/sys/viona_io.h (revision ce489a5e0a9c618cd26b66d6b1fd397d8545db9b)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2013 Pluribus Networks Inc.
14  * Copyright 2018 Joyent, Inc.
15  * Copyright 2022 OmniOS Community Edition (OmniOSce) Association.
16  * Copyright 2024 Oxide Computer Company
17  */
18 
19 #ifndef	_VIONA_IO_H_
20 #define	_VIONA_IO_H_
21 
22 #define	VNA_IOC			(('V' << 16)|('C' << 8))
23 #define	VNA_IOC_CREATE		(VNA_IOC | 0x01)
24 #define	VNA_IOC_DELETE		(VNA_IOC | 0x02)
25 #define	VNA_IOC_VERSION		(VNA_IOC | 0x03)
26 #define	VNA_IOC_DEFAULT_PARAMS	(VNA_IOC | 0x04)
27 
28 #define	VNA_IOC_RING_INIT	(VNA_IOC | 0x10)
29 #define	VNA_IOC_RING_RESET	(VNA_IOC | 0x11)
30 #define	VNA_IOC_RING_KICK	(VNA_IOC | 0x12)
31 #define	VNA_IOC_RING_SET_MSI	(VNA_IOC | 0x13)
32 #define	VNA_IOC_RING_INTR_CLR	(VNA_IOC | 0x14)
33 #define	VNA_IOC_RING_SET_STATE	(VNA_IOC | 0x15)
34 #define	VNA_IOC_RING_GET_STATE	(VNA_IOC | 0x16)
35 #define	VNA_IOC_RING_PAUSE	(VNA_IOC | 0x17)
36 
37 #define	VNA_IOC_INTR_POLL	(VNA_IOC | 0x20)
38 #define	VNA_IOC_SET_FEATURES	(VNA_IOC | 0x21)
39 #define	VNA_IOC_GET_FEATURES	(VNA_IOC | 0x22)
40 #define	VNA_IOC_SET_NOTIFY_IOP	(VNA_IOC | 0x23)
41 #define	VNA_IOC_SET_PROMISC	(VNA_IOC | 0x24)
42 #define	VNA_IOC_GET_PARAMS	(VNA_IOC | 0x25)
43 #define	VNA_IOC_SET_PARAMS	(VNA_IOC | 0x26)
44 
45 
46 /*
47  * Viona Interface Version
48  *
49  * Like bhyve, viona exposes Private interfaces which are nonetheless consumed
50  * by out-of-gate consumers.  While those consumers assume all risk of breakage
51  * incurred by subsequent changes, it would be nice to equip them to potentially
52  * detect (and handle) those modifications.
53  *
54  * There are no established criteria for the magnitude of change which requires
55  * this version to be incremented, and maintenance of it is considered a
56  * best-effort activity.  Nothing is to be inferred about the magnitude of a
57  * change when the version is modified.  It follows no rules like semver.
58  *
59  */
60 #define	VIONA_CURRENT_INTERFACE_VERSION	3
61 
62 typedef struct vioc_create {
63 	datalink_id_t	c_linkid;
64 	int		c_vmfd;
65 } vioc_create_t;
66 
67 typedef struct vioc_ring_init {
68 	uint16_t	ri_index;
69 	uint16_t	ri_qsize;
70 	uint64_t	ri_qaddr;
71 } vioc_ring_init_t;
72 
73 typedef struct vioc_ring_state {
74 	uint16_t	vrs_index;
75 	uint16_t	vrs_avail_idx;
76 	uint16_t	vrs_used_idx;
77 	uint16_t	vrs_qsize;
78 	uint64_t	vrs_qaddr;
79 } vioc_ring_state_t;
80 
81 typedef struct vioc_ring_msi {
82 	uint16_t	rm_index;
83 	uint64_t	rm_addr;
84 	uint64_t	rm_msg;
85 } vioc_ring_msi_t;
86 
87 enum viona_vq_id {
88 	VIONA_VQ_RX = 0,
89 	VIONA_VQ_TX = 1,
90 	VIONA_VQ_MAX = 2
91 };
92 
93 typedef enum {
94 	VIONA_PROMISC_NONE = 0,
95 	VIONA_PROMISC_MULTI,
96 	VIONA_PROMISC_ALL,
97 	VIONA_PROMISC_MAX,
98 } viona_promisc_t;
99 
100 typedef struct vioc_intr_poll {
101 	uint32_t	vip_status[VIONA_VQ_MAX];
102 } vioc_intr_poll_t;
103 
104 
105 /*
106  * Viona Parameter Interfaces
107  *
108  * A viona link can have various configuration parameters set upon it.  This is
109  * done using packed nvlists in order to communicate those parameters to/from
110  * the device driver.
111  *
112  *
113  * Currently supported parameters are:
114  * - tx_copy_data (boolean): During packet transmission, should viona copy all
115  *   of the packet data, rather than "loaning" those regions of guest memory
116  *   (other than the packet headers) in the mblk.
117  * - tx_header_pad (uint16): How many bytes (if any) should be left as empty
118  *   padding on transmitted packets?  These could be used by subsequent
119  *   encapsulation mechanisms in the network stack without the need to
120  *   reallocate space for the then-longer header.
121  *
122  */
123 
124 /* Maximum size for parameter (or error) packed nvlist buffers */
125 #define	VIONA_MAX_PARAM_NVLIST_SZ	4096
126 
127 typedef struct vioc_get_params {
128 	void	*vgp_param;
129 	size_t	vgp_param_sz;
130 } vioc_get_params_t;
131 
132 typedef struct vioc_set_params {
133 	void	*vsp_param;
134 	size_t	vsp_param_sz;
135 	void	*vsp_error;
136 	size_t	vsp_error_sz;
137 } vioc_set_params_t;
138 
139 #endif	/* _VIONA_IO_H_ */
140