xref: /illumos-gate/usr/src/uts/common/io/vio9p/vio9p_impl.h (revision b8052df9f609edb713f6828c9eecc3d7be19dfb3)
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 #define	VIRTIO_9P_MAX_REQS		16
66 #define	VIRTIO_9P_REQ_SIZE		8192
67 
68 /*
69  * It is not clear that there is a well-defined number of cookies for this
70  * interface; QEMU may support as many as there are direct descriptors in the
71  * ring, and bhyve may support something like 128.  We'll use a conservative
72  * number that's large enough to ensure we'll be able to allocate without
73  * requiring contiguous pages.
74  */
75 #define	VIRTIO_9P_MAX_SGL		8
76 
77 /*
78  * TYPE DEFINITIONS
79  */
80 
81 typedef enum vio9p_teardown_style {
82 	VIRTIO_9P_TEARDOWN_PRE_MUTEX,
83 	VIRTIO_9P_TEARDOWN_ATTACH,
84 	VIRTIO_9P_TEARDOWN_DETACH,
85 } vio9p_teardown_style_t;
86 
87 typedef struct vio9p_req {
88 	virtio_dma_t			*vnr_dma_in;
89 	virtio_dma_t			*vnr_dma_out;
90 	virtio_chain_t			*vnr_chain;
91 	list_node_t			vnr_link;
92 	list_node_t			vnr_link_complete;
93 	list_node_t			vnr_link_free;
94 	uint64_t			vnr_generation;
95 } vio9p_req_t;
96 
97 typedef struct vio9p {
98 	dev_info_t			*vin_dip;
99 	virtio_t			*vin_virtio;
100 	virtio_queue_t			*vin_vq;
101 
102 	kmutex_t			vin_mutex;
103 	kcondvar_t			vin_cv;
104 
105 	/*
106 	 * When the device is opened, select a generation number.  This will be
107 	 * used to discard completed responses that arrive after the device was
108 	 * closed and reopened.
109 	 */
110 	uint64_t			vin_generation;
111 	bool				vin_open;
112 
113 	uint_t				vin_nreqs;
114 	list_t				vin_reqs;
115 	list_t				vin_completes;
116 
117 	list_t				vin_req_freelist;
118 
119 	char				vin_tag[VIO9P_MOUNT_TAG_SIZE];
120 } vio9p_t;
121 
122 #ifdef __cplusplus
123 }
124 #endif
125 
126 #endif /* _VIO9P_IMPL_H */
127