iPXE
netvsc.h
Go to the documentation of this file.
1#ifndef _NETVSC_H
2#define _NETVSC_H
4/** @file
5 *
6 * Hyper-V network virtual service client
7 *
8 */
9
10FILE_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 */
72
73/** NetVSC message 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 */
237 /** Number of descriptors */
238 unsigned int count;
239 /** I/O buffers, indexed by buffer ID */
241 /** Buffer ID ring */
243 /** Buffer ID producer counter */
244 unsigned int id_prod;
245 /** Buffer ID consumer counter */
246 unsigned int id_cons;
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 */
257static inline __attribute__ (( always_inline )) void
258netvsc_init_ring ( struct netvsc_ring *ring, unsigned int count,
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 */
272static inline __attribute__ (( always_inline )) int
273netvsc_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 */
287static inline __attribute__ (( always_inline )) int
288netvsc_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 */
308 void *data;
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 */
325static inline __attribute__ (( always_inline )) void
326netvsc_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 */
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 */
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 */
374static inline __attribute__ (( always_inline )) int
375netvsc_is_obsolete ( struct netvsc_device *netvsc ) {
376
377 return vmbus_gpadl_is_obsolete ( netvsc->rx.gpadl );
378}
379
380#endif /* _NETVSC_H */
unsigned short uint16_t
Definition stdint.h:11
unsigned int uint32_t
Definition stdint.h:12
unsigned char uint8_t
Definition stdint.h:10
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:50
ring len
Length.
Definition dwmac.h:226
static unsigned int unsigned int size_t uint8_t * ids
Definition ena.h:770
static unsigned int count
Number of entries.
Definition dwmac.h:220
uint32_t buffer
Buffer index (or NETVSC_RNDIS_NO_BUFFER)
Definition netvsc.h:5
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
struct netvsc_ring __attribute__
#define cpu_to_le16(value)
Definition byteswap.h:107
static const char grant_ref_t unsigned int struct io_buffer ** iobufs
Definition netfront.h:94
static uint16_t struct vmbus_xfer_pages_operations uint8_t establish_type
Definition netvsc.h:328
netvsc_xrid
Relative transaction IDs.
Definition netvsc.h:48
@ NETVSC_RX_ESTABLISH_XRID
Establish receive buffer.
Definition netvsc.h:56
@ NETVSC_RX_REVOKE_XRID
Revoke receive buffer.
Definition netvsc.h:58
@ NETVSC_NDIS_VERSION_XRID
NDIS version.
Definition netvsc.h:54
@ NETVSC_INIT_XRID
Initialisation.
Definition netvsc.h:52
@ NETVSC_TX_BASE_XRID
Transmit descriptors (one per transmit buffer ID)
Definition netvsc.h:50
static uint16_t struct vmbus_xfer_pages_operations uint8_t uint8_t uint8_t uint8_t revoke_xrid
Definition netvsc.h:329
netvsc_status
NetVSC status codes.
Definition netvsc.h:62
@ NETVSC_BAD_PACKET
Definition netvsc.h:68
@ NETVSC_TOO_OLD
Definition netvsc.h:67
@ NETVSC_OK
Definition netvsc.h:64
@ NETVSC_TOO_NEW
Definition netvsc.h:66
@ NETVSC_BUSY
Definition netvsc.h:69
@ NETVSC_FAIL
Definition netvsc.h:65
@ NETVSC_UNSUPPORTED
Definition netvsc.h:70
@ NETVSC_NONE
Definition netvsc.h:63
uint16_t pageset
Page set ID.
Definition netvsc.h:5
#define NETVSC_TX_NUM_DESC
Number of transmit ring entries.
Definition netvsc.h:27
static uint16_t struct vmbus_xfer_pages_operations * op
Definition netvsc.h:327
static uint16_t struct vmbus_xfer_pages_operations uint8_t uint8_t uint8_t revoke_type
Definition netvsc.h:329
static uint16_t struct vmbus_xfer_pages_operations uint8_t uint8_t establish_xrid
Definition netvsc.h:328
A persistent I/O buffer.
Definition iobuf.h:38
A NetVSC data buffer.
Definition netvsc.h:294
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 revoke_type
Revoke data buffer message type.
Definition netvsc.h:302
uint8_t establish_xrid
Establish data buffer relative transaction ID.
Definition netvsc.h:300
struct vmbus_xfer_pages pages
Transfer page set.
Definition netvsc.h:296
void * data
Buffer.
Definition netvsc.h:308
size_t len
Buffer length.
Definition netvsc.h:306
uint8_t establish_type
Establish data buffer message type.
Definition netvsc.h:298
A NetVSC device.
Definition netvsc.h:341
struct netvsc_buffer rx
Receive buffer.
Definition netvsc.h:357
const char * name
Name.
Definition netvsc.h:347
int wait_rc
Return status code for current blocking transaction.
Definition netvsc.h:362
struct io_buffer * tx_iobufs[NETVSC_TX_NUM_DESC]
Transmit I/O buffers.
Definition netvsc.h:354
struct vmbus_device * vmdev
VMBus device.
Definition netvsc.h:343
unsigned int wait_xrid
Relative transaction ID for current blocking transaction.
Definition netvsc.h:360
struct rndis_device * rndis
RNDIS device.
Definition netvsc.h:345
struct netvsc_ring tx
Transmit ring.
Definition netvsc.h:350
uint8_t tx_ids[NETVSC_TX_NUM_DESC]
Transmit buffer IDs.
Definition netvsc.h:352
NetVSC establish data buffer message.
Definition netvsc.h:154
uint32_t gpadl
GPADL ID.
Definition netvsc.h:158
uint8_t reserved[22]
Reserved.
Definition netvsc.h:162
uint16_t pageset
Page set ID.
Definition netvsc.h:160
struct netvsc_header header
Message header.
Definition netvsc.h:156
NetVSC message header.
Definition netvsc.h:74
uint32_t type
Type.
Definition netvsc.h:76
NetVSC initialisation completion.
Definition netvsc.h:101
uint32_t max_mdl_len
Maximum memory descriptor list length.
Definition netvsc.h:107
struct netvsc_header header
Message header.
Definition netvsc.h:103
uint32_t status
Status.
Definition netvsc.h:109
uint8_t reserved[16]
Reserved.
Definition netvsc.h:111
uint32_t version
Protocol version.
Definition netvsc.h:105
NetVSC initialisation message.
Definition netvsc.h:83
uint32_t min
Minimum supported protocol version.
Definition netvsc.h:87
uint8_t reserved[20]
Reserved.
Definition netvsc.h:91
uint32_t max
Maximum supported protocol version.
Definition netvsc.h:89
struct netvsc_header header
Message header.
Definition netvsc.h:85
NetVSC NDIS version message.
Definition netvsc.h:118
struct netvsc_header header
Message header.
Definition netvsc.h:120
uint8_t reserved[20]
Reserved.
Definition netvsc.h:126
uint32_t minor
Minor version.
Definition netvsc.h:124
uint32_t major
Major version.
Definition netvsc.h:122
NetVSC revoke data buffer message.
Definition netvsc.h:200
struct netvsc_header header
Message header.
Definition netvsc.h:202
uint8_t reserved[26]
Reserved.
Definition netvsc.h:206
uint16_t pageset
Page set ID.
Definition netvsc.h:204
A NetVSC descriptor ring.
Definition netvsc.h:236
unsigned int id_prod
Buffer ID producer counter.
Definition netvsc.h:244
struct io_buffer ** iobufs
I/O buffers, indexed by buffer ID.
Definition netvsc.h:240
unsigned int id_cons
Buffer ID consumer counter.
Definition netvsc.h:246
uint8_t * ids
Buffer ID ring.
Definition netvsc.h:242
unsigned int count
Number of descriptors.
Definition netvsc.h:238
NetVSC RNDIS message.
Definition netvsc.h:213
uint8_t reserved[16]
Reserved.
Definition netvsc.h:223
uint32_t channel
RNDIS channel.
Definition netvsc.h:217
uint32_t buffer
Buffer index (or NETVSC_RNDIS_NO_BUFFER)
Definition netvsc.h:219
struct netvsc_header header
Message header.
Definition netvsc.h:215
uint32_t len
Buffer length.
Definition netvsc.h:221
NetVSC receive data buffer section.
Definition netvsc.h:166
uint32_t start
Starting offset.
Definition netvsc.h:168
uint32_t count
Number of subsections.
Definition netvsc.h:172
uint32_t len
Subsection length.
Definition netvsc.h:170
uint32_t end
Ending offset.
Definition netvsc.h:174
NetVSC establish receive data buffer completion.
Definition netvsc.h:178
struct netvsc_rx_buffer_section section[1]
Section descriptors.
Definition netvsc.h:186
struct netvsc_header header
Message header.
Definition netvsc.h:180
uint32_t count
Number of sections (must be 1)
Definition netvsc.h:184
NetVSC establish transmit data buffer completion.
Definition netvsc.h:190
struct netvsc_header header
Message header.
Definition netvsc.h:192
uint32_t len
Section length.
Definition netvsc.h:196
An RNDIS device.
Definition rndis.h:318
A VMBus device.
Definition vmbus.h:475
VMBus transfer page set operations.
Definition vmbus.h:450
VMBus transfer page set.
Definition vmbus.h:465
static int vmbus_gpadl_is_obsolete(unsigned int gpadl)
Check if GPADL is obsolete.
Definition vmbus.h:634