VirtualBox

source: vbox/trunk/include/VBox/pdmnetifs.h@ 27965

Last change on this file since 27965 was 27841, checked in by vboxsync, 15 years ago

pdmnetifs.h: doc correction.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 11.7 KB
Line 
1/** @file
2 * PDM - Pluggable Device Manager, Network Interfaces. (VMM)
3 */
4
5/*
6 * Copyright (C) 2006-2010 Sun Microsystems, Inc.
7 *
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.
15 *
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.
21 *
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.
24 *
25 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
26 * Clara, CA 95054 USA or visit http://www.sun.com if you need
27 * additional information or have any questions.
28 */
29
30#ifndef ___VBox_pdmnetifs_h
31#define ___VBox_pdmnetifs_h
32
33#include <VBox/types.h>
34
35RT_C_DECLS_BEGIN
36
37/** @defgroup grp_pdm_ifs_net PDM Network Interfaces
38 * @ingroup grp_pdm_interfaces
39 * @{
40 */
41
42
43/**
44 * PDM scatter/gather buffer.
45 *
46 * @todo Promote this to VBox/types.h, VBox/pdmcommon.h or some such place.
47 */
48typedef struct PDMSCATTERGATHER
49{
50 /** Flags. */
51 size_t fFlags;
52 /** The number of bytes used.
53 * This is cleared on alloc and set by the user. */
54 size_t cbUsed;
55 /** The number of bytes available.
56 * This is set on alloc and not changed by the user. */
57 size_t cbAvailable;
58 /** Private data member for the allocator side. */
59 void *pvAllocator;
60 /** Private data member for the user side. */
61 void *pvUser;
62 /** The number of segments
63 * This is set on alloc and not changed by the user. */
64 size_t cSegs;
65 /** Variable sized array of segments. */
66 PDMDATASEG aSegs[1];
67} PDMSCATTERGATHER;
68/** Pointer to a PDM scatter/gather buffer. */
69typedef PDMSCATTERGATHER *PPDMSCATTERGATHER;
70/** Pointer to a PDM scatter/gather buffer pointer. */
71typedef PPDMSCATTERGATHER *PPPDMSCATTERGATHER;
72
73
74/** @name PDMSCATTERGATHER::fFlags
75 * @{ */
76/** Magic value. */
77#define PDMSCATTERGATHER_FLAGS_MAGIC UINT32_C(0xb1b10000)
78/** Magic mask. */
79#define PDMSCATTERGATHER_FLAGS_MAGIC_MASK UINT32_C(0xffff0000)
80/** Owned by owner number 1. */
81#define PDMSCATTERGATHER_FLAGS_OWNER_1 UINT32_C(0x00000001)
82/** Owned by owner number 2. */
83#define PDMSCATTERGATHER_FLAGS_OWNER_2 UINT32_C(0x00000002)
84/** Owned by owner number 3. */
85#define PDMSCATTERGATHER_FLAGS_OWNER_3 UINT32_C(0x00000002)
86/** Owner mask. */
87#define PDMSCATTERGATHER_FLAGS_OWNER_MASK UINT32_C(0x00000003)
88/** @} */
89
90
91/**
92 * Sets the owner of a scatter/gather buffer.
93 *
94 * @param pSgBuf .
95 * @param uNewOwner The new owner.
96 */
97DECLINLINE(void) PDMScatterGatherSetOwner(PPDMSCATTERGATHER pSgBuf, uint32_t uNewOwner)
98{
99 pSgBuf->fFlags = (pSgBuf->fFlags & ~PDMSCATTERGATHER_FLAGS_OWNER_MASK) | uNewOwner;
100}
101
102
103
104/** Pointer to a network port interface */
105typedef struct PDMINETWORKDOWN *PPDMINETWORKDOWN;
106/**
107 * Network port interface (down).
108 * Pair with PDMINETWORKUP.
109 */
110typedef struct PDMINETWORKDOWN
111{
112 /**
113 * Wait until there is space for receiving data. We do not care how much space is available
114 * because pfnReceive() will re-check and notify the guest if necessary.
115 *
116 * This function must be called before the pfnRecieve() method is called.
117 *
118 * @returns VBox status code. VINF_SUCCESS means there is at least one receive descriptor available.
119 * @param pInterface Pointer to the interface structure containing the called function pointer.
120 * @param cMillies Number of milliseconds to wait. 0 means return immediately.
121 *
122 * @thread Non-EMT.
123 */
124 DECLR3CALLBACKMEMBER(int, pfnWaitReceiveAvail,(PPDMINETWORKDOWN pInterface, RTMSINTERVAL cMillies));
125
126 /**
127 * Receive data from the network.
128 *
129 * @returns VBox status code.
130 * @param pInterface Pointer to the interface structure containing the called function pointer.
131 * @param pvBuf The available data.
132 * @param cb Number of bytes available in the buffer.
133 *
134 * @thread Non-EMT.
135 */
136 DECLR3CALLBACKMEMBER(int, pfnReceive,(PPDMINETWORKDOWN pInterface, const void *pvBuf, size_t cb));
137
138
139 /**
140 * Called when there is a buffered of the required size available.
141 *
142 * When a PDMINETWORKUP::pfnAllocBuf call fails with VERR_TRY_AGAIN, the
143 * driver will notify the device/driver up stream when a large enough buffer
144 * becomes available via this method.
145 *
146 * @param pInterface Pointer to this interface.
147 * @param pSgBuf Scatter/gather buffer of the size previously
148 * requested. Pass to PDMINETWORKUP::pfnSendBuf or
149 * PDMINETWORKUP::pfnFreeBuf.
150 *
151 * @thread Non-EMT.
152 */
153 DECLR3CALLBACKMEMBER(void, pfnNotifyBufAvailable,(PPDMINETWORKDOWN pInterface));
154
155} PDMINETWORKDOWN;
156/** PDMINETWORKDOWN inteface ID. */
157#define PDMINETWORKDOWN_IID "eb66670b-7998-4470-8e72-886e30f6a9c3"
158
159
160/**
161 * Network link state.
162 */
163typedef enum PDMNETWORKLINKSTATE
164{
165 /** Invalid state. */
166 PDMNETWORKLINKSTATE_INVALID = 0,
167 /** The link is up. */
168 PDMNETWORKLINKSTATE_UP,
169 /** The link is down. */
170 PDMNETWORKLINKSTATE_DOWN,
171 /** The link is temporarily down while resuming. */
172 PDMNETWORKLINKSTATE_DOWN_RESUME
173} PDMNETWORKLINKSTATE;
174
175
176/** Pointer to a network connector interface */
177typedef struct PDMINETWORKUP *PPDMINETWORKUP;
178/**
179 * Network connector interface (up).
180 * Pair with PDMINETWORKDOWN.
181 */
182typedef struct PDMINETWORKUP
183{
184 /**
185 * Get a send buffer for passing to pfnSendBuf.
186 *
187 * @retval VINF_SUCCESS on success.
188 * @retval VERR_TRY_AGAIN if temporarily out of buffer space. After this
189 * happens, the driver will call PDMINETWORKDOWN::pfnNotifyBufAvailable
190 * when this is a buffer of the required size available.
191 * @retval VERR_NO_MEMORY if really out of buffer space.
192 * @retval VERR_NET_DOWN if we cannot send anything to the network at this
193 * point in time. Drop the frame with a xmit error. This is typically
194 * only seen when pausing the VM since the device keeps the link state,
195 * but there could of course be races.
196 *
197 * @param pInterface Pointer to the interface structure containing the called function pointer.
198 * @param cbMin The minimum buffer size.
199 * @param ppSgBuf Where to return the buffer. The buffer will be
200 * owned by the caller, designation owner number 1.
201 *
202 * @thread Any, but normally EMT.
203 */
204 DECLR3CALLBACKMEMBER(int, pfnAllocBuf,(PPDMINETWORKUP pInterface, size_t cbMin, PPPDMSCATTERGATHER ppSgBuf));
205
206 /**
207 * Frees an unused buffer.
208 *
209 * @retval VINF_SUCCESS on success.
210 *
211 * @param pInterface Pointer to the interface structure containing the called function pointer.
212 * @param pSgBuf A buffer from PDMINETWORKUP::pfnAllocBuf or
213 * PDMINETWORKDOWN::pfnNotifyBufAvailable. The buffer
214 * ownership shall be 1.
215 *
216 * @thread Any.
217 */
218 DECLR3CALLBACKMEMBER(int, pfnFreeBuf,(PPDMINETWORKUP pInterface, PPDMSCATTERGATHER pSgBuf));
219
220 /**
221 * Send data to the network.
222 *
223 * @retval VINF_SUCCESS on success.
224 * @retval VERR_NET_DOWN if the NIC is not connected to a network. pSgBuf will
225 * be freed.
226 * @retval VERR_NET_NO_BUFFER_SPACE if we're out of resources. pSgBuf will be
227 * freed.
228 *
229 * @param pInterface Pointer to the interface structure containing the
230 * called function pointer.
231 * @param pSgBuf The buffer containing the data to send. The buffer
232 * ownership shall be 1. The buffer will always be
233 * consumed, regardless of the status code.
234 *
235 * @param fOnWorkerThread Set if we're being called on a work thread. Clear
236 * if an EMT.
237 *
238 * @thread Any.
239 */
240 DECLR3CALLBACKMEMBER(int, pfnSendBuf,(PPDMINETWORKUP pInterface, PPDMSCATTERGATHER pSgBuf, bool fOnWorkerThread));
241
242 /**
243 * Set promiscuous mode.
244 *
245 * This is called when the promiscuous mode is set. This means that there doesn't have
246 * to be a mode change when it's called.
247 *
248 * @param pInterface Pointer to the interface structure containing the called function pointer.
249 * @param fPromiscuous Set if the adaptor is now in promiscuous mode. Clear if it is not.
250 * @thread EMT ??
251 */
252 DECLR3CALLBACKMEMBER(void, pfnSetPromiscuousMode,(PPDMINETWORKUP pInterface, bool fPromiscuous));
253
254 /**
255 * Notification on link status changes.
256 *
257 * @param pInterface Pointer to the interface structure containing the called function pointer.
258 * @param enmLinkState The new link state.
259 * @thread EMT ??
260 */
261 DECLR3CALLBACKMEMBER(void, pfnNotifyLinkChanged,(PPDMINETWORKUP pInterface, PDMNETWORKLINKSTATE enmLinkState));
262
263 /** @todo Add a callback that informs the driver chain about MAC address changes if we ever implement that. */
264
265 /**
266 * Send data to the network.
267 *
268 * @returns VBox status code.
269 * @param pInterface Pointer to the interface structure containing the called function pointer.
270 * @param pvBuf Data to send.
271 * @param cb Number of bytes to send.
272 * @thread EMT ??
273 * @deprecated
274 */
275 DECLR3CALLBACKMEMBER(int, pfnSendDeprecated,(PPDMINETWORKUP pInterface, const void *pvBuf, size_t cb));
276
277
278} PDMINETWORKUP;
279/** PDMINETWORKUP interface ID. */
280#define PDMINETWORKUP_IID "f915243e-801a-4868-8979-b6b8594b09cc"
281
282
283/** Pointer to a network config port interface */
284typedef struct PDMINETWORKCONFIG *PPDMINETWORKCONFIG;
285/**
286 * Network config port interface (main).
287 * No interface pair.
288 */
289typedef struct PDMINETWORKCONFIG
290{
291 /**
292 * Gets the current Media Access Control (MAC) address.
293 *
294 * @returns VBox status code.
295 * @param pInterface Pointer to the interface structure containing the called function pointer.
296 * @param pMac Where to store the MAC address.
297 * @thread EMT
298 */
299 DECLR3CALLBACKMEMBER(int, pfnGetMac,(PPDMINETWORKCONFIG pInterface, PRTMAC pMac));
300
301 /**
302 * Gets the new link state.
303 *
304 * @returns The current link state.
305 * @param pInterface Pointer to the interface structure containing the called function pointer.
306 * @thread EMT
307 */
308 DECLR3CALLBACKMEMBER(PDMNETWORKLINKSTATE, pfnGetLinkState,(PPDMINETWORKCONFIG pInterface));
309
310 /**
311 * Sets the new link state.
312 *
313 * @returns VBox status code.
314 * @param pInterface Pointer to the interface structure containing the called function pointer.
315 * @param enmState The new link state
316 * @thread EMT
317 */
318 DECLR3CALLBACKMEMBER(int, pfnSetLinkState,(PPDMINETWORKCONFIG pInterface, PDMNETWORKLINKSTATE enmState));
319
320} PDMINETWORKCONFIG;
321/** PDMINETWORKCONFIG interface ID. */
322#define PDMINETWORKCONFIG_IID "d6d909e8-716d-415d-b109-534e4478ff4e"
323
324/** @} */
325
326RT_C_DECLS_END
327
328#endif
329
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette