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