iPXE
netvsc.h
Go to the documentation of this file.
1 #ifndef _NETVSC_H
2 #define _NETVSC_H
3 
4 /** @file
5  *
6  * Hyper-V network virtual service client
7  *
8  */
9 
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11 
12 /** Maximum supported NetVSC message length */
13 #define NETVSC_MTU 512
14 
15 /** Maximum time to wait for a transaction to complete
16  *
17  * This is a policy decision.
18  */
19 #define NETVSC_MAX_WAIT_MS 1000
20 
21 /** Number of transmit ring entries
22  *
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.
26  */
27 #define NETVSC_TX_NUM_DESC 32
28 
29 /** RX data buffer page set ID
30  *
31  * This is a policy decision.
32  */
33 #define NETVSC_RX_BUF_PAGESET 0xbead
34 
35 /** RX data buffer length
36  *
37  * This is a policy decision.
38  */
39 #define NETVSC_RX_BUF_LEN ( 16 * PAGE_SIZE )
40 
41 /** Base transaction ID
42  *
43  * This is a policy decision.
44  */
45 #define NETVSC_BASE_XID 0x18ae0000UL
46 
47 /** Relative transaction IDs */
49  /** Transmit descriptors (one per transmit buffer ID) */
51  /** Initialisation */
53  /** NDIS version */
55  /** Establish receive buffer */
57  /** Revoke receive buffer */
59 };
60 
61 /** NetVSC status codes */
64  NETVSC_OK = 1,
71 };
72 
73 /** NetVSC message header */
74 struct netvsc_header {
75  /** Type */
77 } __attribute__ (( packed ));
78 
79 /** NetVSC initialisation message */
80 #define NETVSC_INIT_MSG 1
81 
82 /** NetVSC initialisation message */
84  /** Message header */
86  /** Minimum supported protocol version */
88  /** Maximum supported protocol version */
90  /** Reserved */
92 } __attribute__ (( packed ));
93 
94 /** Oldest known NetVSC protocol version */
95 #define NETVSC_VERSION_1 2 /* sic */
96 
97 /** NetVSC initialisation completion */
98 #define NETVSC_INIT_CMPLT 2
99 
100 /** NetVSC initialisation completion */
102  /** Message header */
104  /** Protocol version */
106  /** Maximum memory descriptor list length */
108  /** Status */
110  /** Reserved */
112 } __attribute__ (( packed ));
113 
114 /** NetVSC NDIS version message */
115 #define NETVSC_NDIS_VERSION_MSG 100
116 
117 /** NetVSC NDIS version message */
119  /** Message header */
121  /** Major version */
123  /** Minor version */
125  /** Reserved */
127 } __attribute__ (( packed ));
128 
129 /** NetVSC NDIS major version */
130 #define NETVSC_NDIS_MAJOR 6
131 
132 /** NetVSC NDIS minor version */
133 #define NETVSC_NDIS_MINOR 1
134 
135 /** NetVSC establish receive data buffer message */
136 #define NETVSC_RX_ESTABLISH_MSG 101
137 
138 /** NetVSC establish receive data buffer completion */
139 #define NETVSC_RX_ESTABLISH_CMPLT 102
140 
141 /** NetVSC revoke receive data buffer message */
142 #define NETVSC_RX_REVOKE_MSG 103
143 
144 /** NetVSC establish transmit data buffer message */
145 #define NETVSC_TX_ESTABLISH_MSG 104
146 
147 /** NetVSC establish transmit data buffer completion */
148 #define NETVSC_TX_ESTABLISH_CMPLT 105
149 
150 /** NetVSC revoke transmit data buffer message */
151 #define NETVSC_TX_REVOKE_MSG 106
152 
153 /** NetVSC establish data buffer message */
155  /** Message header */
157  /** GPADL ID */
159  /** Page set ID */
161  /** Reserved */
163 } __attribute__ (( packed ));
164 
165 /** NetVSC receive data buffer section */
167  /** Starting offset */
169  /** Subsection length */
171  /** Number of subsections */
173  /** Ending offset */
175 } __attribute__ (( packed ));
176 
177 /** NetVSC establish receive data buffer completion */
179  /** Message header */
181  /** Status */
183  /** Number of sections (must be 1) */
185  /** Section descriptors */
187 } __attribute__ (( packed ));
188 
189 /** NetVSC establish transmit data buffer completion */
191  /** Message header */
193  /** Status */
195  /** Section length */
197 } __attribute__ (( packed ));
198 
199 /** NetVSC revoke data buffer message */
201  /** Message header */
203  /** Page set ID */
205  /** Reserved */
207 } __attribute__ (( packed ));
208 
209 /** NetVSC RNDIS message */
210 #define NETVSC_RNDIS_MSG 107
211 
212 /** NetVSC RNDIS message */
214  /** Message header */
216  /** RNDIS channel */
218  /** Buffer index (or NETVSC_RNDIS_NO_BUFFER) */
220  /** Buffer length */
222  /** Reserved */
224 } __attribute__ (( packed ));
225 
226 /** RNDIS data channel (for RNDIS_PACKET_MSG only) */
227 #define NETVSC_RNDIS_DATA 0
228 
229 /** RNDIS control channel (for all other RNDIS messages) */
230 #define NETVSC_RNDIS_CONTROL 1
231 
232 /** "No buffer used" index */
233 #define NETVSC_RNDIS_NO_BUFFER 0xffffffffUL
234 
235 /** A NetVSC descriptor ring */
236 struct netvsc_ring {
237  /** Number of descriptors */
238  unsigned int count;
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;
247 };
248 
249 /**
250  * Initialise descriptor ring
251  *
252  * @v ring Descriptor ring
253  * @v count Maximum number of used descriptors
254  * @v iobufs I/O buffers
255  * @v ids Buffer IDs
256  */
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 ) {
260 
261  ring->count = count;
262  ring->iobufs = iobufs;
263  ring->ids = ids;
264 }
265 
266 /**
267  * Check whether or not descriptor ring is full
268  *
269  * @v ring Descriptor ring
270  * @v is_full Ring is full
271  */
272 static inline __attribute__ (( always_inline )) int
273 netvsc_ring_is_full ( struct netvsc_ring *ring ) {
274  unsigned int fill_level;
275 
276  fill_level = ( ring->id_prod - ring->id_cons );
277  assert ( fill_level <= ring->count );
278  return ( fill_level >= ring->count );
279 }
280 
281 /**
282  * Check whether or not descriptor ring is empty
283  *
284  * @v ring Descriptor ring
285  * @v is_empty Ring is empty
286  */
287 static inline __attribute__ (( always_inline )) int
288 netvsc_ring_is_empty ( struct netvsc_ring *ring ) {
289 
290  return ( ring->id_prod == ring->id_cons );
291 }
292 
293 /** A NetVSC data buffer */
295  /** Transfer page set */
297  /** Establish data buffer message type */
299  /** Establish data buffer relative transaction ID */
301  /** Revoke data buffer message type */
303  /** Revoke data buffer relative transaction ID */
305  /** Buffer length */
306  size_t len;
307  /** Buffer */
309  /** GPADL ID */
310  unsigned int gpadl;
311 };
312 
313 /**
314  * Initialise data buffer
315  *
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
324  */
325 static inline __attribute__ (( always_inline )) void
326 netvsc_init_buffer ( struct netvsc_buffer *buffer, uint16_t pageset,
330 
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;
337  buffer->len = len;
338 }
339 
340 /** A NetVSC device */
342  /** VMBus device */
344  /** RNDIS device */
346  /** Name */
347  const char *name;
348 
349  /** Transmit ring */
350  struct netvsc_ring tx;
351  /** Transmit buffer IDs */
353  /** Transmit I/O buffers */
355 
356  /** Receive buffer */
358 
359  /** Relative transaction ID for current blocking transaction */
360  unsigned int wait_xrid;
361  /** Return status code for current blocking transaction */
362  int wait_rc;
363 };
364 
365 /**
366  * Check if NetVSC device is obsolete
367  *
368  * @v netvsc NetVSC device
369  * @v is_obsolete NetVSC device is obsolete
370  *
371  * Check if NetVSC device is obsolete (i.e. was opened before the most
372  * recent Hyper-V reset).
373  */
374 static inline __attribute__ (( always_inline )) int
375 netvsc_is_obsolete ( struct netvsc_device *netvsc ) {
376 
377  return vmbus_gpadl_is_obsolete ( netvsc->rx.gpadl );
378 }
379 
380 #endif /* _NETVSC_H */
uint32_t count
Number of subsections.
Definition: netvsc.h:172
unsigned int count
Number of descriptors.
Definition: netvsc.h:238
uint32_t gpadl
GPADL ID.
Definition: netvsc.h:158
NDIS version.
Definition: netvsc.h:54
NetVSC initialisation message.
Definition: netvsc.h:83
unsigned short uint16_t
Definition: stdint.h:11
static unsigned int struct io_buffer ** iobufs
Definition: netvsc.h:259
uint16_t pageset
Page set ID.
Definition: netvsc.h:16
static uint16_t struct vmbus_xfer_pages_operations uint8_t uint8_t uint8_t revoke_type
Definition: netvsc.h:327
uint8_t reserved[22]
Reserved.
Definition: netvsc.h:162
uint32_t minor
Minor version.
Definition: netvsc.h:124
uint32_t max
Maximum supported protocol version.
Definition: netvsc.h:89
NetVSC RNDIS message.
Definition: netvsc.h:213
struct netvsc_header header
Message header.
Definition: netvsc.h:215
A VMBus device.
Definition: vmbus.h:476
A NetVSC data buffer.
Definition: netvsc.h:294
uint32_t len
Subsection length.
Definition: netvsc.h:14
Establish receive buffer.
Definition: netvsc.h:56
unsigned int id_cons
Buffer ID consumer counter.
Definition: netvsc.h:246
uint32_t buffer
Buffer index (or NETVSC_RNDIS_NO_BUFFER)
Definition: netvsc.h:16
uint32_t end
Ending offset.
Definition: netvsc.h:174
NetVSC establish transmit data buffer completion.
Definition: netvsc.h:190
uint32_t channel
RNDIS channel.
Definition: netvsc.h:217
const char * name
Name.
Definition: netvsc.h:347
struct netvsc_header header
Message header.
Definition: netvsc.h:103
NetVSC establish receive data buffer completion.
Definition: netvsc.h:178
uint8_t reserved[20]
Reserved.
Definition: netvsc.h:91
uint16_t pageset
Page set ID.
Definition: netvsc.h:160
struct netvsc_header header
Message header.
Definition: netvsc.h:192
uint32_t len
Buffer length.
Definition: netvsc.h:221
uint32_t len
Section length.
Definition: netvsc.h:196
struct io_buffer ** iobufs
I/O buffers, indexed by buffer ID.
Definition: netvsc.h:240
struct netvsc_ring __attribute__
static uint16_t struct vmbus_xfer_pages_operations uint8_t uint8_t establish_xrid
Definition: netvsc.h:327
static int vmbus_gpadl_is_obsolete(unsigned int gpadl)
Check if GPADL is obsolete.
Definition: vmbus.h:632
struct netvsc_header header
Message header.
Definition: netvsc.h:156
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
unsigned int id_prod
Buffer ID producer counter.
Definition: netvsc.h:244
NetVSC establish data buffer message.
Definition: netvsc.h:154
An RNDIS device.
Definition: rndis.h:317
struct netvsc_ring tx
Transmit ring.
Definition: netvsc.h:350
static unsigned int struct io_buffer uint8_t * ids
Definition: netvsc.h:259
static uint16_t struct vmbus_xfer_pages_operations uint8_t uint8_t uint8_t uint8_t revoke_xrid
Definition: netvsc.h:327
struct netvsc_header header
Message header.
Definition: netvsc.h:120
A NetVSC device.
Definition: netvsc.h:341
Revoke receive buffer.
Definition: netvsc.h:58
userptr_t data
Buffer.
Definition: netvsc.h:308
uint32_t count
Number of sections (must be 1)
Definition: netvsc.h:184
uint32_t major
Major version.
Definition: netvsc.h:122
uint32_t max_mdl_len
Maximum memory descriptor list length.
Definition: netvsc.h:107
uint8_t reserved[26]
Reserved.
Definition: netvsc.h:206
unsigned char uint8_t
Definition: stdint.h:10
uint8_t reserved[16]
Reserved.
Definition: netvsc.h:223
uint32_t type
Type.
Definition: netvsc.h:76
uint32_t status
Status.
Definition: netvsc.h:109
uint8_t revoke_type
Revoke data buffer message type.
Definition: netvsc.h:302
uint8_t reserved[20]
Reserved.
Definition: netvsc.h:126
uint16_t pageset
Page set ID.
Definition: netvsc.h:204
struct vmbus_xfer_pages pages
Transfer page set.
Definition: netvsc.h:296
unsigned int uint32_t
Definition: stdint.h:12
struct io_buffer * tx_iobufs[NETVSC_TX_NUM_DESC]
Transmit I/O buffers.
Definition: netvsc.h:354
#define NETVSC_TX_NUM_DESC
Number of transmit ring entries.
Definition: netvsc.h:27
netvsc_xrid
Relative transaction IDs.
Definition: netvsc.h:48
uint8_t revoke_xrid
Revoke data buffer relative transaction ID.
Definition: netvsc.h:304
unsigned int gpadl
GPADL ID.
Definition: netvsc.h:310
uint8_t tx_ids[NETVSC_TX_NUM_DESC]
Transmit buffer IDs.
Definition: netvsc.h:352
unsigned int wait_xrid
Relative transaction ID for current blocking transaction.
Definition: netvsc.h:360
uint32_t buffer
Buffer index (or NETVSC_RNDIS_NO_BUFFER)
Definition: netvsc.h:219
A NetVSC descriptor ring.
Definition: netvsc.h:236
struct netvsc_header header
Message header.
Definition: netvsc.h:85
VMBus transfer page set operations.
Definition: vmbus.h:451
NetVSC message header.
Definition: netvsc.h:74
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
uint32_t min
Minimum supported protocol version.
Definition: netvsc.h:87
uint32_t count
Number of subsections.
Definition: netvsc.h:16
VMBus transfer page set.
Definition: vmbus.h:466
struct vmbus_device * vmdev
VMBus device.
Definition: netvsc.h:343
uint32_t len
Subsection length.
Definition: netvsc.h:170
NetVSC receive data buffer section.
Definition: netvsc.h:166
size_t len
Buffer length.
Definition: netvsc.h:306
struct netvsc_rx_buffer_section section[1]
Section descriptors.
Definition: netvsc.h:186
uint32_t start
Starting offset.
Definition: netvsc.h:168
uint8_t establish_xrid
Establish data buffer relative transaction ID.
Definition: netvsc.h:300
#define cpu_to_le16(value)
Definition: byteswap.h:106
NetVSC NDIS version message.
Definition: netvsc.h:118
netvsc_status
NetVSC status codes.
Definition: netvsc.h:62
Initialisation.
Definition: netvsc.h:52
NetVSC revoke data buffer message.
Definition: netvsc.h:200
Transmit descriptors (one per transmit buffer ID)
Definition: netvsc.h:50
static uint16_t struct vmbus_xfer_pages_operations uint8_t establish_type
Definition: netvsc.h:327
uint8_t reserved[16]
Reserved.
Definition: netvsc.h:111
struct rndis_device * rndis
RNDIS device.
Definition: netvsc.h:345
struct netvsc_header header
Message header.
Definition: netvsc.h:180
NetVSC initialisation completion.
Definition: netvsc.h:101
struct netvsc_buffer rx
Receive buffer.
Definition: netvsc.h:357
int wait_rc
Return status code for current blocking transaction.
Definition: netvsc.h:362
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
unsigned long userptr_t
A pointer to a user buffer.
Definition: uaccess.h:33
uint8_t * ids
Buffer ID ring.
Definition: netvsc.h:242
A persistent I/O buffer.
Definition: iobuf.h:32
uint8_t establish_type
Establish data buffer message type.
Definition: netvsc.h:298
struct netvsc_header header
Message header.
Definition: netvsc.h:202
uint32_t version
Protocol version.
Definition: netvsc.h:105