VirtualBox

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

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

Network/D*,VMM: Moving the TX threads, part 1.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 16.0 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/** Mask of flags available to general use.
89 * The parties using the SG must all agree upon how to use these of course. */
90#define PDMSCATTERGATHER_FLAGS_AVL_MASK UINT32_C(0x0000f000)
91/** Flags reserved for future use, MBZ. */
92#define PDMSCATTERGATHER_FLAGS_RVD_MASK UINT32_C(0x00000ff8)
93/** @} */
94
95
96/**
97 * Sets the owner of a scatter/gather buffer.
98 *
99 * @param pSgBuf .
100 * @param uNewOwner The new owner.
101 */
102DECLINLINE(void) PDMScatterGatherSetOwner(PPDMSCATTERGATHER pSgBuf, uint32_t uNewOwner)
103{
104 pSgBuf->fFlags = (pSgBuf->fFlags & ~PDMSCATTERGATHER_FLAGS_OWNER_MASK) | uNewOwner;
105}
106
107
108
109/** Pointer to a network port interface */
110typedef struct PDMINETWORKDOWN *PPDMINETWORKDOWN;
111/**
112 * Network port interface (down).
113 * Pair with PDMINETWORKUP.
114 */
115typedef struct PDMINETWORKDOWN
116{
117 /**
118 * Wait until there is space for receiving data. We do not care how much space is available
119 * because pfnReceive() will re-check and notify the guest if necessary.
120 *
121 * This function must be called before the pfnRecieve() method is called.
122 *
123 * @returns VBox status code. VINF_SUCCESS means there is at least one receive descriptor available.
124 * @param pInterface Pointer to the interface structure containing the called function pointer.
125 * @param cMillies Number of milliseconds to wait. 0 means return immediately.
126 *
127 * @thread Non-EMT.
128 */
129 DECLR3CALLBACKMEMBER(int, pfnWaitReceiveAvail,(PPDMINETWORKDOWN pInterface, RTMSINTERVAL cMillies));
130
131 /**
132 * Receive data from the network.
133 *
134 * @returns VBox status code.
135 * @param pInterface Pointer to the interface structure containing the called function pointer.
136 * @param pvBuf The available data.
137 * @param cb Number of bytes available in the buffer.
138 *
139 * @thread Non-EMT.
140 */
141 DECLR3CALLBACKMEMBER(int, pfnReceive,(PPDMINETWORKDOWN pInterface, const void *pvBuf, size_t cb));
142
143 /**
144 * Do pending transmit work on the leaf driver's XMIT thread.
145 *
146 * When a PDMINETWORKUP::pfnBeginTransmit or PDMINETWORKUP::pfnAllocBuf call
147 * fails with VERR_TRY_AGAIN, the leaf drivers XMIT thread will offer to process
148 * the upstream device/driver when the the VERR_TRY_AGAIN condition has been
149 * removed. In some cases the VERR_TRY_AGAIN condition is simply being in an
150 * inconvenient context and the XMIT thread will start working ASAP.
151 *
152 * @param pInterface Pointer to this interface.
153 * @thread Non-EMT.
154 */
155 DECLR3CALLBACKMEMBER(void, pfnXmitPending,(PPDMINETWORKDOWN pInterface));
156
157} PDMINETWORKDOWN;
158/** PDMINETWORKDOWN inteface ID. */
159#define PDMINETWORKDOWN_IID "52b8cdbb-a087-493b-baa7-81ec3b803e06"
160
161
162/**
163 * Network link state.
164 */
165typedef enum PDMNETWORKLINKSTATE
166{
167 /** Invalid state. */
168 PDMNETWORKLINKSTATE_INVALID = 0,
169 /** The link is up. */
170 PDMNETWORKLINKSTATE_UP,
171 /** The link is down. */
172 PDMNETWORKLINKSTATE_DOWN,
173 /** The link is temporarily down while resuming. */
174 PDMNETWORKLINKSTATE_DOWN_RESUME
175} PDMNETWORKLINKSTATE;
176
177
178/** Pointer to a network connector interface */
179typedef R3PTRTYPE(struct PDMINETWORKUP *) PPDMINETWORKUPR3;
180/** Pointer to a network connector interface, ring-0 context. */
181typedef R0PTRTYPE(struct PDMINETWORKUPR0 *) PPDMINETWORKUPR0;
182/** Pointer to a network connector interface, raw-mode context. */
183typedef RCPTRTYPE(struct PDMINETWORKUPRC *) PPDMINETWORKUPRC;
184/** Pointer to a current context network connector interface. */
185typedef CTX_SUFF(PPDMINETWORKUP) PPDMINETWORKUP;
186
187/**
188 * Network connector interface (up).
189 * Pair with PDMINETWORKDOWN.
190 */
191typedef struct PDMINETWORKUP
192{
193 /**
194 * Begins a transmit session.
195 *
196 * The leaf driver guarantees that there are no concurrent sessions.
197 *
198 * @retval VINF_SUCCESS on success. Must always call
199 * PDMINETWORKUP::pfnEndXmit.
200 * @retval VERR_TRY_AGAIN if there is already an open transmit session or some
201 * important resource was unavailable (like buffer space). If it's a
202 * resources issue, the driver will signal its XMIT thread and have it
203 * work the device thru the PDMINETWORKDOWN::pfnNotifyBufAvailable
204 * callback method.
205 *
206 * @param pInterface Pointer to the interface structure containing the
207 * called function pointer.
208 * @param fOnWorkerThread Set if we're being called on a work thread. Clear
209 * if an EMT.
210 *
211 * @thread Any, but normally EMT or the XMIT thread.
212 */
213 DECLR3CALLBACKMEMBER(int, pfnBeginXmit,(PPDMINETWORKUP pInterface, bool fOnWorkerThread));
214
215 /**
216 * Get a send buffer for passing to pfnSendBuf.
217 *
218 * @retval VINF_SUCCESS on success.
219 * @retval VERR_TRY_AGAIN if temporarily out of buffer space. After this
220 * happens, the driver will call PDMINETWORKDOWN::pfnNotifyBufAvailable
221 * when this is a buffer of the required size available.
222 * @retval VERR_NO_MEMORY if really out of buffer space.
223 * @retval VERR_NET_DOWN if we cannot send anything to the network at this
224 * point in time. Drop the frame with a xmit error. This is typically
225 * only seen when pausing the VM since the device keeps the link state,
226 * but there could of course be races.
227 *
228 * @param pInterface Pointer to the interface structure containing the
229 * called function pointer.
230 * @param cbMin The minimum buffer size.
231 * @param pGso Pointer to a GSO context (only reference while in
232 * this call). NULL indicates no segmentation
233 * offloading. PDMSCATTERGATHER::pvUser is used to
234 * indicate that a network SG uses GSO, usually by
235 * pointing to a copy of @a pGso.
236 * @param ppSgBuf Where to return the buffer. The buffer will be
237 * owned by the caller, designation owner number 1.
238 *
239 * @thread Any, but normally EMT or the XMIT thread.
240 */
241 DECLR3CALLBACKMEMBER(int, pfnAllocBuf,(PPDMINETWORKUP pInterface, size_t cbMin, PCPDMNETWORKGSO pGso,
242 PPPDMSCATTERGATHER ppSgBuf));
243
244 /**
245 * Frees an unused buffer.
246 *
247 * @retval VINF_SUCCESS on success.
248 *
249 * @param pInterface Pointer to the interface structure containing the called function pointer.
250 * @param pSgBuf A buffer from PDMINETWORKUP::pfnAllocBuf or
251 * PDMINETWORKDOWN::pfnNotifyBufAvailable. The buffer
252 * ownership shall be 1.
253 *
254 * @thread Any, but normally EMT or the XMIT thread.
255 */
256 DECLR3CALLBACKMEMBER(int, pfnFreeBuf,(PPDMINETWORKUP pInterface, PPDMSCATTERGATHER pSgBuf));
257
258 /**
259 * Send data to the network.
260 *
261 * @retval VINF_SUCCESS on success.
262 * @retval VERR_NET_DOWN if the NIC is not connected to a network. pSgBuf will
263 * be freed.
264 * @retval VERR_NET_NO_BUFFER_SPACE if we're out of resources. pSgBuf will be
265 * freed.
266 *
267 * @param pInterface Pointer to the interface structure containing the
268 * called function pointer.
269 * @param pSgBuf The buffer containing the data to send. The buffer
270 * ownership shall be 1. The buffer will always be
271 * consumed, regardless of the status code.
272 *
273 * @param fOnWorkerThread Set if we're being called on a work thread. Clear
274 * if an EMT.
275 *
276 * @thread Any, but normally EMT or the XMIT thread.
277 */
278 DECLR3CALLBACKMEMBER(int, pfnSendBuf,(PPDMINETWORKUP pInterface, PPDMSCATTERGATHER pSgBuf, bool fOnWorkerThread));
279
280 /**
281 * Ends a transmit session.
282 *
283 * Pairs with successful PDMINETWORKUP::pfnBeginXmit calls.
284 *
285 * @param pInterface Pointer to the interface structure containing the
286 * called function pointer.
287 *
288 * @thread Any, but normally EMT or the XMIT thread.
289 */
290 DECLR3CALLBACKMEMBER(void, pfnEndXmit,(PPDMINETWORKUP pInterface));
291
292 /**
293 * Set promiscuous mode.
294 *
295 * This is called when the promiscuous mode is set. This means that there doesn't have
296 * to be a mode change when it's called.
297 *
298 * @param pInterface Pointer to the interface structure containing the called function pointer.
299 * @param fPromiscuous Set if the adaptor is now in promiscuous mode. Clear if it is not.
300 * @thread EMT ??
301 */
302 DECLR3CALLBACKMEMBER(void, pfnSetPromiscuousMode,(PPDMINETWORKUP pInterface, bool fPromiscuous));
303
304 /**
305 * Notification on link status changes.
306 *
307 * @param pInterface Pointer to the interface structure containing the called function pointer.
308 * @param enmLinkState The new link state.
309 * @thread EMT ??
310 */
311 DECLR3CALLBACKMEMBER(void, pfnNotifyLinkChanged,(PPDMINETWORKUP pInterface, PDMNETWORKLINKSTATE enmLinkState));
312
313 /** @todo Add a callback that informs the driver chain about MAC address changes if we ever implement that. */
314
315} PDMINETWORKUP;
316
317/** Ring-0 edition of PDMINETWORKUP. */
318typedef struct PDMINETWORKUPR0
319{
320 /** @copydoc PDMINETWORKUP::pfnBeginXmit */
321 DECLR0CALLBACKMEMBER(int, pfnBeginXmit,(PPDMINETWORKUPR0 pInterface, bool fOnWorkerThread));
322 /** @copydoc PDMINETWORKUP::pfnAllocBuf */
323 DECLR0CALLBACKMEMBER(int, pfnAllocBuf,(PPDMINETWORKUPR0 pInterface, size_t cbMin, PCPDMNETWORKGSO pGso,
324 PPPDMSCATTERGATHER ppSgBuf));
325 /** @copydoc PDMINETWORKUP::pfnFreeBuf */
326 DECLR0CALLBACKMEMBER(int, pfnFreeBuf,(PPDMINETWORKUPR0 pInterface, PPDMSCATTERGATHER pSgBuf));
327 /** @copydoc PDMINETWORKUP::pfnSendBuf */
328 DECLR0CALLBACKMEMBER(int, pfnSendBuf,(PPDMINETWORKUPR0 pInterface, PPDMSCATTERGATHER pSgBuf, bool fOnWorkerThread));
329 /** @copydoc PDMINETWORKUP::pfnEndBuf */
330 DECLR0CALLBACKMEMBER(void, pfnEndXmit,(PPDMINETWORKUPR0 pInterface));
331 /** @copydoc PDMINETWORKUP::pfnSetPromiscuousMode */
332 DECLR0CALLBACKMEMBER(void, pfnSetPromiscuousMode,(PPDMINETWORKUPR0 pInterface, bool fPromiscuous));
333} PDMINETWORKUPR0;
334
335/** Raw-mode context edition of PDMINETWORKUP. */
336typedef struct PDMINETWORKUPRC
337{
338 /** @copydoc PDMINETWORKUP::pfnBeginXmit */
339 DECLRCCALLBACKMEMBER(int, pfnBeginXmit,(PPDMINETWORKUPRC pInterface, bool fOnWorkerThread));
340 /** @copydoc PDMINETWORKUP::pfnAllocBuf */
341 DECLRCCALLBACKMEMBER(int, pfnAllocBuf,(PPDMINETWORKUPRC pInterface, size_t cbMin, PCPDMNETWORKGSO pGso,
342 PPPDMSCATTERGATHER ppSgBuf));
343 /** @copydoc PDMINETWORKUP::pfnFreeBuf */
344 DECLRCCALLBACKMEMBER(int, pfnFreeBuf,(PPDMINETWORKUPRC pInterface, PPDMSCATTERGATHER pSgBuf));
345 /** @copydoc PDMINETWORKUP::pfnSendBuf */
346 DECLRCCALLBACKMEMBER(int, pfnSendBuf,(PPDMINETWORKUPRC pInterface, PPDMSCATTERGATHER pSgBuf, bool fOnWorkerThread));
347 /** @copydoc PDMINETWORKUP::pfnEndBuf */
348 DECLRCCALLBACKMEMBER(void, pfnEndXmit,(PPDMINETWORKUPRC pInterface));
349 /** @copydoc PDMINETWORKUP::pfnSetPromiscuousMode */
350 DECLRCCALLBACKMEMBER(void, pfnSetPromiscuousMode,(PPDMINETWORKUPRC pInterface, bool fPromiscuous));
351} PDMINETWORKUPRC;
352
353/** PDMINETWORKUP interface ID. */
354#define PDMINETWORKUP_IID "67e7e7a8-2594-4649-a1e3-7cee680c6083"
355
356
357/** Pointer to a network config port interface */
358typedef struct PDMINETWORKCONFIG *PPDMINETWORKCONFIG;
359/**
360 * Network config port interface (main).
361 * No interface pair.
362 */
363typedef struct PDMINETWORKCONFIG
364{
365 /**
366 * Gets the current Media Access Control (MAC) address.
367 *
368 * @returns VBox status code.
369 * @param pInterface Pointer to the interface structure containing the called function pointer.
370 * @param pMac Where to store the MAC address.
371 * @thread EMT
372 */
373 DECLR3CALLBACKMEMBER(int, pfnGetMac,(PPDMINETWORKCONFIG pInterface, PRTMAC pMac));
374
375 /**
376 * Gets the new link state.
377 *
378 * @returns The current link state.
379 * @param pInterface Pointer to the interface structure containing the called function pointer.
380 * @thread EMT
381 */
382 DECLR3CALLBACKMEMBER(PDMNETWORKLINKSTATE, pfnGetLinkState,(PPDMINETWORKCONFIG pInterface));
383
384 /**
385 * Sets the new link state.
386 *
387 * @returns VBox status code.
388 * @param pInterface Pointer to the interface structure containing the called function pointer.
389 * @param enmState The new link state
390 * @thread EMT
391 */
392 DECLR3CALLBACKMEMBER(int, pfnSetLinkState,(PPDMINETWORKCONFIG pInterface, PDMNETWORKLINKSTATE enmState));
393
394} PDMINETWORKCONFIG;
395/** PDMINETWORKCONFIG interface ID. */
396#define PDMINETWORKCONFIG_IID "d6d909e8-716d-415d-b109-534e4478ff4e"
397
398/** @} */
399
400RT_C_DECLS_END
401
402#endif
403
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