2
* PDM - Pluggable Device Manager, Network Interfaces.
6
* Copyright (C) 2006-2010 Oracle Corporation
8
* This file is part of VirtualBox Open Source Edition (OSE), as
9
* available from http://www.virtualbox.org. This file is free software;
10
* you can redistribute it and/or modify it under the terms of the GNU
11
* General Public License (GPL) as published by the Free Software
12
* Foundation, in version 2 as it comes in the "COPYING" file of the
13
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16
* The contents of this file may alternatively be used under the terms
17
* of the Common Development and Distribution License Version 1.0
18
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19
* VirtualBox OSE distribution, in which case the provisions of the
20
* CDDL are applicable instead of those of the GPL.
22
* You may elect to license modified versions of this file under the
23
* terms and conditions of either the GPL or the CDDL or both.
26
#ifndef ___VBox_vmm_pdmnetifs_h
27
#define ___VBox_vmm_pdmnetifs_h
29
#include <VBox/types.h>
34
/** @defgroup grp_pdm_ifs_net PDM Network Interfaces
35
* @ingroup grp_pdm_interfaces
41
* PDM scatter/gather buffer.
43
* @todo Promote this to VBox/types.h, VBox/vmm/pdmcommon.h or some such place.
45
typedef struct PDMSCATTERGATHER
49
/** The number of bytes used.
50
* This is cleared on alloc and set by the user. */
52
/** The number of bytes available.
53
* This is set on alloc and not changed by the user. */
55
/** Private data member for the allocator side. */
57
/** Private data member for the user side. */
59
/** The number of segments
60
* This is set on alloc and not changed by the user. */
62
/** Variable sized array of segments. */
65
/** Pointer to a PDM scatter/gather buffer. */
66
typedef PDMSCATTERGATHER *PPDMSCATTERGATHER;
67
/** Pointer to a PDM scatter/gather buffer pointer. */
68
typedef PPDMSCATTERGATHER *PPPDMSCATTERGATHER;
71
/** @name PDMSCATTERGATHER::fFlags
74
#define PDMSCATTERGATHER_FLAGS_MAGIC UINT32_C(0xb1b10000)
76
#define PDMSCATTERGATHER_FLAGS_MAGIC_MASK UINT32_C(0xffff0000)
77
/** Owned by owner number 1. */
78
#define PDMSCATTERGATHER_FLAGS_OWNER_1 UINT32_C(0x00000001)
79
/** Owned by owner number 2. */
80
#define PDMSCATTERGATHER_FLAGS_OWNER_2 UINT32_C(0x00000002)
81
/** Owned by owner number 3. */
82
#define PDMSCATTERGATHER_FLAGS_OWNER_3 UINT32_C(0x00000002)
84
#define PDMSCATTERGATHER_FLAGS_OWNER_MASK UINT32_C(0x00000003)
85
/** Mask of flags available to general use.
86
* The parties using the SG must all agree upon how to use these of course. */
87
#define PDMSCATTERGATHER_FLAGS_AVL_MASK UINT32_C(0x0000f000)
88
/** Flags reserved for future use, MBZ. */
89
#define PDMSCATTERGATHER_FLAGS_RVD_MASK UINT32_C(0x00000ff8)
94
* Sets the owner of a scatter/gather buffer.
97
* @param uNewOwner The new owner.
99
DECLINLINE(void) PDMScatterGatherSetOwner(PPDMSCATTERGATHER pSgBuf, uint32_t uNewOwner)
101
pSgBuf->fFlags = (pSgBuf->fFlags & ~PDMSCATTERGATHER_FLAGS_OWNER_MASK) | uNewOwner;
106
/** Pointer to a network port interface */
107
typedef struct PDMINETWORKDOWN *PPDMINETWORKDOWN;
109
* Network port interface (down).
110
* Pair with PDMINETWORKUP.
112
typedef struct PDMINETWORKDOWN
115
* Wait until there is space for receiving data. We do not care how much space is available
116
* because pfnReceive() will re-check and notify the guest if necessary.
118
* This function must be called before the pfnRecieve() method is called.
120
* @returns VBox status code. VINF_SUCCESS means there is at least one receive descriptor available.
121
* @param pInterface Pointer to the interface structure containing the called function pointer.
122
* @param cMillies Number of milliseconds to wait. 0 means return immediately.
126
DECLR3CALLBACKMEMBER(int, pfnWaitReceiveAvail,(PPDMINETWORKDOWN pInterface, RTMSINTERVAL cMillies));
129
* Receive data from the network.
131
* @returns VBox status code.
132
* @param pInterface Pointer to the interface structure containing the called function pointer.
133
* @param pvBuf The available data.
134
* @param cb Number of bytes available in the buffer.
138
DECLR3CALLBACKMEMBER(int, pfnReceive,(PPDMINETWORKDOWN pInterface, const void *pvBuf, size_t cb));
141
* Receive data with segmentation context from the network.
143
* @returns VBox status code.
144
* @param pInterface Pointer to the interface structure containing the called function pointer.
145
* @param pvBuf The available data.
146
* @param cb Number of bytes available in the buffer.
147
* @param pGso Segmentation context.
151
DECLR3CALLBACKMEMBER(int, pfnReceiveGso,(PPDMINETWORKDOWN pInterface, const void *pvBuf, size_t cb, PCPDMNETWORKGSO pGso));
154
* Do pending transmit work on the leaf driver's XMIT thread.
156
* When a PDMINETWORKUP::pfnBeginTransmit or PDMINETWORKUP::pfnAllocBuf call
157
* fails with VERR_TRY_AGAIN, the leaf drivers XMIT thread will offer to process
158
* the upstream device/driver when the the VERR_TRY_AGAIN condition has been
159
* removed. In some cases the VERR_TRY_AGAIN condition is simply being in an
160
* inconvenient context and the XMIT thread will start working ASAP.
162
* @param pInterface Pointer to this interface.
165
DECLR3CALLBACKMEMBER(void, pfnXmitPending,(PPDMINETWORKDOWN pInterface));
168
/** PDMINETWORKDOWN interface ID. */
169
#define PDMINETWORKDOWN_IID "52b8cdbb-a087-493b-baa7-81ec3b803e06"
173
* Network link state.
175
typedef enum PDMNETWORKLINKSTATE
177
/** Invalid state. */
178
PDMNETWORKLINKSTATE_INVALID = 0,
179
/** The link is up. */
180
PDMNETWORKLINKSTATE_UP,
181
/** The link is down. */
182
PDMNETWORKLINKSTATE_DOWN,
183
/** The link is temporarily down while resuming. */
184
PDMNETWORKLINKSTATE_DOWN_RESUME
185
} PDMNETWORKLINKSTATE;
188
/** Pointer to a network connector interface */
189
typedef R3PTRTYPE(struct PDMINETWORKUP *) PPDMINETWORKUPR3;
190
/** Pointer to a network connector interface, ring-0 context. */
191
typedef R0PTRTYPE(struct PDMINETWORKUPR0 *) PPDMINETWORKUPR0;
192
/** Pointer to a network connector interface, raw-mode context. */
193
typedef RCPTRTYPE(struct PDMINETWORKUPRC *) PPDMINETWORKUPRC;
194
/** Pointer to a current context network connector interface. */
195
typedef CTX_SUFF(PPDMINETWORKUP) PPDMINETWORKUP;
198
* Network connector interface (up).
199
* Pair with PDMINETWORKDOWN.
201
typedef struct PDMINETWORKUP
204
* Begins a transmit session.
206
* The leaf driver guarantees that there are no concurrent sessions.
208
* @retval VINF_SUCCESS on success. Must always call
209
* PDMINETWORKUP::pfnEndXmit.
210
* @retval VERR_TRY_AGAIN if there is already an open transmit session or some
211
* important resource was unavailable (like buffer space). If it's a
212
* resources issue, the driver will signal its XMIT thread and have it
213
* work the device thru the PDMINETWORKDOWN::pfnNotifyBufAvailable
216
* @param pInterface Pointer to the interface structure containing the
217
* called function pointer.
218
* @param fOnWorkerThread Set if we're being called on a work thread. Clear
221
* @thread Any, but normally EMT or the XMIT thread.
223
DECLR3CALLBACKMEMBER(int, pfnBeginXmit,(PPDMINETWORKUP pInterface, bool fOnWorkerThread));
226
* Get a send buffer for passing to pfnSendBuf.
228
* @retval VINF_SUCCESS on success.
229
* @retval VERR_TRY_AGAIN if temporarily out of buffer space. After this
230
* happens, the driver will call PDMINETWORKDOWN::pfnNotifyBufAvailable
231
* when this is a buffer of the required size available.
232
* @retval VERR_NO_MEMORY if really out of buffer space.
233
* @retval VERR_NET_DOWN if we cannot send anything to the network at this
234
* point in time. Drop the frame with a xmit error. This is typically
235
* only seen when pausing the VM since the device keeps the link state,
236
* but there could of course be races.
238
* @param pInterface Pointer to the interface structure containing the
239
* called function pointer.
240
* @param cbMin The minimum buffer size.
241
* @param pGso Pointer to a GSO context (only reference while in
242
* this call). NULL indicates no segmentation
243
* offloading. PDMSCATTERGATHER::pvUser is used to
244
* indicate that a network SG uses GSO, usually by
245
* pointing to a copy of @a pGso.
246
* @param ppSgBuf Where to return the buffer. The buffer will be
247
* owned by the caller, designation owner number 1.
249
* @thread Any, but normally EMT or the XMIT thread.
251
DECLR3CALLBACKMEMBER(int, pfnAllocBuf,(PPDMINETWORKUP pInterface, size_t cbMin, PCPDMNETWORKGSO pGso,
252
PPPDMSCATTERGATHER ppSgBuf));
255
* Frees an unused buffer.
257
* @retval VINF_SUCCESS on success.
259
* @param pInterface Pointer to the interface structure containing the called function pointer.
260
* @param pSgBuf A buffer from PDMINETWORKUP::pfnAllocBuf or
261
* PDMINETWORKDOWN::pfnNotifyBufAvailable. The buffer
262
* ownership shall be 1.
264
* @thread Any, but normally EMT or the XMIT thread.
266
DECLR3CALLBACKMEMBER(int, pfnFreeBuf,(PPDMINETWORKUP pInterface, PPDMSCATTERGATHER pSgBuf));
269
* Send data to the network.
271
* @retval VINF_SUCCESS on success.
272
* @retval VERR_NET_DOWN if the NIC is not connected to a network. pSgBuf will
274
* @retval VERR_NET_NO_BUFFER_SPACE if we're out of resources. pSgBuf will be
277
* @param pInterface Pointer to the interface structure containing the
278
* called function pointer.
279
* @param pSgBuf The buffer containing the data to send. The buffer
280
* ownership shall be 1. The buffer will always be
281
* consumed, regardless of the status code.
283
* @param fOnWorkerThread Set if we're being called on a work thread. Clear
286
* @thread Any, but normally EMT or the XMIT thread.
288
DECLR3CALLBACKMEMBER(int, pfnSendBuf,(PPDMINETWORKUP pInterface, PPDMSCATTERGATHER pSgBuf, bool fOnWorkerThread));
291
* Ends a transmit session.
293
* Pairs with successful PDMINETWORKUP::pfnBeginXmit calls.
295
* @param pInterface Pointer to the interface structure containing the
296
* called function pointer.
298
* @thread Any, but normally EMT or the XMIT thread.
300
DECLR3CALLBACKMEMBER(void, pfnEndXmit,(PPDMINETWORKUP pInterface));
303
* Set promiscuous mode.
305
* This is called when the promiscuous mode is set. This means that there doesn't have
306
* to be a mode change when it's called.
308
* @param pInterface Pointer to the interface structure containing the called function pointer.
309
* @param fPromiscuous Set if the adaptor is now in promiscuous mode. Clear if it is not.
312
DECLR3CALLBACKMEMBER(void, pfnSetPromiscuousMode,(PPDMINETWORKUP pInterface, bool fPromiscuous));
315
* Notification on link status changes.
317
* @param pInterface Pointer to the interface structure containing the called function pointer.
318
* @param enmLinkState The new link state.
321
DECLR3CALLBACKMEMBER(void, pfnNotifyLinkChanged,(PPDMINETWORKUP pInterface, PDMNETWORKLINKSTATE enmLinkState));
323
/** @todo Add a callback that informs the driver chain about MAC address changes if we ever implement that. */
327
/** Ring-0 edition of PDMINETWORKUP. */
328
typedef struct PDMINETWORKUPR0
330
/** @copydoc PDMINETWORKUP::pfnBeginXmit */
331
DECLR0CALLBACKMEMBER(int, pfnBeginXmit,(PPDMINETWORKUPR0 pInterface, bool fOnWorkerThread));
332
/** @copydoc PDMINETWORKUP::pfnAllocBuf */
333
DECLR0CALLBACKMEMBER(int, pfnAllocBuf,(PPDMINETWORKUPR0 pInterface, size_t cbMin, PCPDMNETWORKGSO pGso,
334
PPPDMSCATTERGATHER ppSgBuf));
335
/** @copydoc PDMINETWORKUP::pfnFreeBuf */
336
DECLR0CALLBACKMEMBER(int, pfnFreeBuf,(PPDMINETWORKUPR0 pInterface, PPDMSCATTERGATHER pSgBuf));
337
/** @copydoc PDMINETWORKUP::pfnSendBuf */
338
DECLR0CALLBACKMEMBER(int, pfnSendBuf,(PPDMINETWORKUPR0 pInterface, PPDMSCATTERGATHER pSgBuf, bool fOnWorkerThread));
339
/** @copydoc PDMINETWORKUP::pfnEndBuf */
340
DECLR0CALLBACKMEMBER(void, pfnEndXmit,(PPDMINETWORKUPR0 pInterface));
341
/** @copydoc PDMINETWORKUP::pfnSetPromiscuousMode */
342
DECLR0CALLBACKMEMBER(void, pfnSetPromiscuousMode,(PPDMINETWORKUPR0 pInterface, bool fPromiscuous));
345
/** Raw-mode context edition of PDMINETWORKUP. */
346
typedef struct PDMINETWORKUPRC
348
/** @copydoc PDMINETWORKUP::pfnBeginXmit */
349
DECLRCCALLBACKMEMBER(int, pfnBeginXmit,(PPDMINETWORKUPRC pInterface, bool fOnWorkerThread));
350
/** @copydoc PDMINETWORKUP::pfnAllocBuf */
351
DECLRCCALLBACKMEMBER(int, pfnAllocBuf,(PPDMINETWORKUPRC pInterface, size_t cbMin, PCPDMNETWORKGSO pGso,
352
PPPDMSCATTERGATHER ppSgBuf));
353
/** @copydoc PDMINETWORKUP::pfnFreeBuf */
354
DECLRCCALLBACKMEMBER(int, pfnFreeBuf,(PPDMINETWORKUPRC pInterface, PPDMSCATTERGATHER pSgBuf));
355
/** @copydoc PDMINETWORKUP::pfnSendBuf */
356
DECLRCCALLBACKMEMBER(int, pfnSendBuf,(PPDMINETWORKUPRC pInterface, PPDMSCATTERGATHER pSgBuf, bool fOnWorkerThread));
357
/** @copydoc PDMINETWORKUP::pfnEndBuf */
358
DECLRCCALLBACKMEMBER(void, pfnEndXmit,(PPDMINETWORKUPRC pInterface));
359
/** @copydoc PDMINETWORKUP::pfnSetPromiscuousMode */
360
DECLRCCALLBACKMEMBER(void, pfnSetPromiscuousMode,(PPDMINETWORKUPRC pInterface, bool fPromiscuous));
363
/** PDMINETWORKUP interface ID. */
364
#define PDMINETWORKUP_IID "67e7e7a8-2594-4649-a1e3-7cee680c6083"
365
/** PDMINETWORKUP interface method names. */
366
#define PDMINETWORKUP_SYM_LIST "BeginXmit;AllocBuf;FreeBuf;SendBuf;EndXmit;SetPromiscuousMode"
369
/** Pointer to a network config port interface */
370
typedef struct PDMINETWORKCONFIG *PPDMINETWORKCONFIG;
372
* Network config port interface (main).
375
typedef struct PDMINETWORKCONFIG
378
* Gets the current Media Access Control (MAC) address.
380
* @returns VBox status code.
381
* @param pInterface Pointer to the interface structure containing the called function pointer.
382
* @param pMac Where to store the MAC address.
385
DECLR3CALLBACKMEMBER(int, pfnGetMac,(PPDMINETWORKCONFIG pInterface, PRTMAC pMac));
388
* Gets the new link state.
390
* @returns The current link state.
391
* @param pInterface Pointer to the interface structure containing the called function pointer.
394
DECLR3CALLBACKMEMBER(PDMNETWORKLINKSTATE, pfnGetLinkState,(PPDMINETWORKCONFIG pInterface));
397
* Sets the new link state.
399
* @returns VBox status code.
400
* @param pInterface Pointer to the interface structure containing the called function pointer.
401
* @param enmState The new link state
404
DECLR3CALLBACKMEMBER(int, pfnSetLinkState,(PPDMINETWORKCONFIG pInterface, PDMNETWORKLINKSTATE enmState));
407
/** PDMINETWORKCONFIG interface ID. */
408
#define PDMINETWORKCONFIG_IID "d6d909e8-716d-415d-b109-534e4478ff4e"
411
/** Pointer to a NAT configuration port. */
412
typedef struct PDMINETWORKNATCONFIG *PPDMINETWORKNATCONFIG;
414
* Network config port interface (main).
417
typedef struct PDMINETWORKNATCONFIG
420
* Inform NAT about the adding/removing redirection rule
422
* @todo D O C U M E N T M E !
425
DECLR3CALLBACKMEMBER(int, pfnRedirectRuleCommand ,(PPDMINETWORKNATCONFIG pInterface, bool fRemove,
426
bool fUdp, const char *pHostIp, uint16_t u16HostPort,
427
const char *pGuestIp, uint16_t u16GuestPort));
429
} PDMINETWORKNATCONFIG;
430
/** PDMINETWORKNATCONFIG interface ID. */
431
#define PDMINETWORKNATCONFIG_IID "0f001d62-4d2f-11df-93b3-2fd0b3a36a6b"