6 * Hyper-V network virtual service client
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
12 /** Maximum supported NetVSC message length */
13 #define NETVSC_MTU 512
15 /** Maximum time to wait for a transaction to complete
17 * This is a policy decision.
19 #define NETVSC_MAX_WAIT_MS 1000
21 /** Number of transmit ring entries
23 * Must be a power of two. This is a policy decision. This value
24 * must be sufficiently small to guarantee that we never run out of
25 * space in the VMBus outbound ring buffer.
27 #define NETVSC_TX_NUM_DESC 32
29 /** RX data buffer page set ID
31 * This is a policy decision.
33 #define NETVSC_RX_BUF_PAGESET 0xbead
35 /** RX data buffer length
37 * This is a policy decision.
39 #define NETVSC_RX_BUF_LEN ( 16 * PAGE_SIZE )
41 /** Base transaction ID
43 * This is a policy decision.
45 #define NETVSC_BASE_XID 0x18ae0000UL
47 /** Relative transaction IDs */
49 /** Transmit descriptors (one per transmit buffer ID) */
50 NETVSC_TX_BASE_XRID = 0,
52 NETVSC_INIT_XRID = ( NETVSC_TX_BASE_XRID + NETVSC_TX_NUM_DESC ),
54 NETVSC_NDIS_VERSION_XRID,
55 /** Establish receive buffer */
56 NETVSC_RX_ESTABLISH_XRID,
57 /** Revoke receive buffer */
58 NETVSC_RX_REVOKE_XRID,
61 /** NetVSC status codes */
68 NETVSC_BAD_PACKET = 5,
70 NETVSC_UNSUPPORTED = 7,
73 /** NetVSC message header */
74 struct netvsc_header {
77 } __attribute__ (( packed ));
79 /** NetVSC initialisation message */
80 #define NETVSC_INIT_MSG 1
82 /** NetVSC initialisation message */
83 struct netvsc_init_message {
85 struct netvsc_header header;
86 /** Minimum supported protocol version */
88 /** Maximum supported protocol version */
92 } __attribute__ (( packed ));
94 /** Oldest known NetVSC protocol version */
95 #define NETVSC_VERSION_1 2 /* sic */
97 /** NetVSC initialisation completion */
98 #define NETVSC_INIT_CMPLT 2
100 /** NetVSC initialisation completion */
101 struct netvsc_init_completion {
102 /** Message header */
103 struct netvsc_header header;
104 /** Protocol version */
106 /** Maximum memory descriptor list length */
107 uint32_t max_mdl_len;
111 uint8_t reserved[16];
112 } __attribute__ (( packed ));
114 /** NetVSC NDIS version message */
115 #define NETVSC_NDIS_VERSION_MSG 100
117 /** NetVSC NDIS version message */
118 struct netvsc_ndis_version_message {
119 /** Message header */
120 struct netvsc_header header;
126 uint8_t reserved[20];
127 } __attribute__ (( packed ));
129 /** NetVSC NDIS major version */
130 #define NETVSC_NDIS_MAJOR 6
132 /** NetVSC NDIS minor version */
133 #define NETVSC_NDIS_MINOR 1
135 /** NetVSC establish receive data buffer message */
136 #define NETVSC_RX_ESTABLISH_MSG 101
138 /** NetVSC establish receive data buffer completion */
139 #define NETVSC_RX_ESTABLISH_CMPLT 102
141 /** NetVSC revoke receive data buffer message */
142 #define NETVSC_RX_REVOKE_MSG 103
144 /** NetVSC establish transmit data buffer message */
145 #define NETVSC_TX_ESTABLISH_MSG 104
147 /** NetVSC establish transmit data buffer completion */
148 #define NETVSC_TX_ESTABLISH_CMPLT 105
150 /** NetVSC revoke transmit data buffer message */
151 #define NETVSC_TX_REVOKE_MSG 106
153 /** NetVSC establish data buffer message */
154 struct netvsc_establish_buffer_message {
155 /** Message header */
156 struct netvsc_header header;
162 uint8_t reserved[22];
163 } __attribute__ (( packed ));
165 /** NetVSC receive data buffer section */
166 struct netvsc_rx_buffer_section {
167 /** Starting offset */
169 /** Subsection length */
171 /** Number of subsections */
175 } __attribute__ (( packed ));
177 /** NetVSC establish receive data buffer completion */
178 struct netvsc_rx_establish_buffer_completion {
179 /** Message header */
180 struct netvsc_header header;
183 /** Number of sections (must be 1) */
185 /** Section descriptors */
186 struct netvsc_rx_buffer_section section[1];
187 } __attribute__ (( packed ));
189 /** NetVSC establish transmit data buffer completion */
190 struct netvsc_tx_establish_buffer_completion {
191 /** Message header */
192 struct netvsc_header header;
195 /** Section length */
197 } __attribute__ (( packed ));
199 /** NetVSC revoke data buffer message */
200 struct netvsc_revoke_buffer_message {
201 /** Message header */
202 struct netvsc_header header;
206 uint8_t reserved[26];
207 } __attribute__ (( packed ));
209 /** NetVSC RNDIS message */
210 #define NETVSC_RNDIS_MSG 107
212 /** NetVSC RNDIS message */
213 struct netvsc_rndis_message {
214 /** Message header */
215 struct netvsc_header header;
218 /** Buffer index (or NETVSC_RNDIS_NO_BUFFER) */
223 uint8_t reserved[16];
224 } __attribute__ (( packed ));
226 /** RNDIS data channel (for RNDIS_PACKET_MSG only) */
227 #define NETVSC_RNDIS_DATA 0
229 /** RNDIS control channel (for all other RNDIS messages) */
230 #define NETVSC_RNDIS_CONTROL 1
232 /** "No buffer used" index */
233 #define NETVSC_RNDIS_NO_BUFFER 0xffffffffUL
235 /** A NetVSC descriptor ring */
237 /** Number of descriptors */
239 /** I/O buffers, indexed by buffer ID */
240 struct io_buffer **iobufs;
241 /** Buffer ID ring */
243 /** Buffer ID producer counter */
244 unsigned int id_prod;
245 /** Buffer ID consumer counter */
246 unsigned int id_cons;
250 * Initialise descriptor ring
252 * @v ring Descriptor ring
253 * @v count Maximum number of used descriptors
254 * @v iobufs I/O buffers
257 static inline __attribute__ (( always_inline )) void
258 netvsc_init_ring ( struct netvsc_ring *ring, unsigned int count,
259 struct io_buffer **iobufs, uint8_t *ids ) {
262 ring->iobufs = iobufs;
267 * Check whether or not descriptor ring is full
269 * @v ring Descriptor ring
270 * @v is_full Ring is full
272 static inline __attribute__ (( always_inline )) int
273 netvsc_ring_is_full ( struct netvsc_ring *ring ) {
274 unsigned int fill_level;
276 fill_level = ( ring->id_prod - ring->id_cons );
277 assert ( fill_level <= ring->count );
278 return ( fill_level >= ring->count );
282 * Check whether or not descriptor ring is empty
284 * @v ring Descriptor ring
285 * @v is_empty Ring is empty
287 static inline __attribute__ (( always_inline )) int
288 netvsc_ring_is_empty ( struct netvsc_ring *ring ) {
290 return ( ring->id_prod == ring->id_cons );
293 /** A NetVSC data buffer */
294 struct netvsc_buffer {
295 /** Transfer page set */
296 struct vmbus_xfer_pages pages;
297 /** Establish data buffer message type */
298 uint8_t establish_type;
299 /** Establish data buffer relative transaction ID */
300 uint8_t establish_xrid;
301 /** Revoke data buffer message type */
303 /** Revoke data buffer relative transaction ID */
314 * Initialise data buffer
316 * @v buffer Data buffer
317 * @v pageset Page set ID
318 * @v op Page set operations
319 * @v establish_type Establish data buffer message type
320 * @v establish_xrid Establish data buffer relative transaction ID
321 * @v revoke_type Revoke data buffer message type
322 * @v revoke_type Revoke data buffer relative transaction ID
323 * @v len Required length
325 static inline __attribute__ (( always_inline )) void
326 netvsc_init_buffer ( struct netvsc_buffer *buffer, uint16_t pageset,
327 struct vmbus_xfer_pages_operations *op,
328 uint8_t establish_type, uint8_t establish_xrid,
329 uint8_t revoke_type, uint8_t revoke_xrid, size_t len ) {
331 buffer->pages.pageset = cpu_to_le16 ( pageset );
332 buffer->pages.op = op;
333 buffer->establish_type = establish_type;
334 buffer->establish_xrid = establish_xrid;
335 buffer->revoke_type = revoke_type;
336 buffer->revoke_xrid = revoke_xrid;
340 /** A NetVSC device */
341 struct netvsc_device {
343 struct vmbus_device *vmdev;
345 struct rndis_device *rndis;
350 struct netvsc_ring tx;
351 /** Transmit buffer IDs */
352 uint8_t tx_ids[NETVSC_TX_NUM_DESC];
353 /** Transmit I/O buffers */
354 struct io_buffer *tx_iobufs[NETVSC_TX_NUM_DESC];
356 /** Receive buffer */
357 struct netvsc_buffer rx;
359 /** Relative transaction ID for current blocking transaction */
360 unsigned int wait_xrid;
361 /** Return status code for current blocking transaction */
365 #endif /* _NETVSC_H */