xref: /illumos-gate/usr/src/uts/common/io/vio9p/vio9p_impl.h (revision dd72704bd9e794056c558153663c739e2012d721)
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 2022 Oxide Computer Company
14  */
15 
16 /*
17  * VIRTIO 9P DRIVER
18  */
19 
20 #ifndef _VIO9P_IMPL_H
21 #define	_VIO9P_IMPL_H
22 
23 #include "virtio.h"
24 #include <sys/vio9p.h>
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 /*
31  * VIRTIO 9P CONFIGURATION REGISTERS
32  *
33  * These are offsets into the device-specific configuration space available
34  * through the virtio_dev_*() family of functions.
35  */
36 #define	VIRTIO_9P_CONFIG_TAG_SZ			0x00	/* 16 R   */
37 #define	VIRTIO_9P_CONFIG_TAG			0x02	/* SZ R   */
38 
39 /*
40  * VIRTIO 9P VIRTQUEUES
41  *
42  * Virtio 9P devices have just one queue which is used to make 9P requests.
43  * Each submitted chain should include appropriately sized inbound and outbound
44  * descriptors for the request and response messages.  The maximum size is
45  * negotiated via the "msize" member of the 9P TVERSION request and RVERSION
46  * response.  Some hypervisors may require the first 7 bytes (size, type, tag)
47  * to be contiguous in the first descriptor.
48  */
49 #define	VIRTIO_9P_VIRTQ_REQUESTS	0
50 
51 /*
52  * VIRTIO 9P FEATURE BITS
53  */
54 #define	VIRTIO_9P_F_MOUNT_TAG		(1ULL << 0)
55 
56 /*
57  * These features are supported by the driver and we will request them from the
58  * device.
59  */
60 #define	VIRTIO_9P_WANTED_FEATURES	(VIRTIO_9P_F_MOUNT_TAG)
61 
62 /*
63  * DRIVER PARAMETERS
64  */
65 
66 /*
67  * A limit on the number of requests that can be allocated for a vio9p device.
68  */
69 #define	VIRTIO_9P_MAX_REQS		8
70 
71 /*
72  * This parameter defines an upper bound on 9P protocol message size (msize). 9P
73  * servers may negotiate an msize up to this value. An attempt to transfer a
74  * message larger than this will result in a EMSGISZE error.
75  */
76 #define	VIRTIO_9P_REQ_SIZE		65536
77 
78 /*
79  * It is not clear that there is a well-defined number of cookies for this
80  * interface; QEMU may support as many as there are direct descriptors in the
81  * ring, and bhyve may support something like 128.  We'll use a conservative
82  * number that's large enough to ensure we'll be able to allocate without
83  * requiring contiguous pages.
84  */
85 #define	VIRTIO_9P_MAX_SGL		64
86 
87 /*
88  * TYPE DEFINITIONS
89  */
90 
91 typedef enum vio9p_teardown_style {
92 	VIRTIO_9P_TEARDOWN_PRE_MUTEX,
93 	VIRTIO_9P_TEARDOWN_ATTACH,
94 	VIRTIO_9P_TEARDOWN_DETACH,
95 } vio9p_teardown_style_t;
96 
97 typedef struct vio9p_req {
98 	virtio_dma_t			*vnr_dma_in;
99 	virtio_dma_t			*vnr_dma_out;
100 	virtio_chain_t			*vnr_chain;
101 	list_node_t			vnr_link;
102 	list_node_t			vnr_link_complete;
103 	list_node_t			vnr_link_free;
104 	uint64_t			vnr_generation;
105 } vio9p_req_t;
106 
107 typedef struct vio9p {
108 	dev_info_t			*vin_dip;
109 	virtio_t			*vin_virtio;
110 	virtio_queue_t			*vin_vq;
111 
112 	kmutex_t			vin_mutex;
113 	kcondvar_t			vin_cv;
114 
115 	/*
116 	 * When the device is opened, select a generation number.  This will be
117 	 * used to discard completed responses that arrive after the device was
118 	 * closed and reopened.
119 	 */
120 	uint64_t			vin_generation;
121 	bool				vin_open;
122 
123 	uint_t				vin_nreqs;
124 	list_t				vin_reqs;
125 	list_t				vin_completes;
126 
127 	list_t				vin_req_freelist;
128 
129 	char				vin_tag[VIO9P_MOUNT_TAG_SIZE];
130 } vio9p_t;
131 
132 #ifdef __cplusplus
133 }
134 #endif
135 
136 #endif /* _VIO9P_IMPL_H */
137