VirtualBox

Changeset 26574 in vbox for trunk/include


Ignore:
Timestamp:
Feb 16, 2010 12:44:10 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
57756
Message:

Networking: Preparing to make the driver return a send buffer to the device emulation.

Location:
trunk/include
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/Makefile.kmk

    r26304 r26574  
    2424include $(KBUILD_PATH)/header.kmk
    2525
    26 LIBRARIES = SyntaxVBoxIncludeR3 SyntaxVBoxIncludeR0 SyntaxVBoxIncludeGC
     26LIBRARIES = SyntaxVBoxIncludeR3 SyntaxVBoxIncludeR0 SyntaxVBoxIncludeRC
    2727
    2828cpp_hdrs := \
     
    7979        $(addprefix $(PATH_TARGET)/,$(subst .h,-cpp.cpp, $(subst /,_,$(hdrs.r0))))
    8080
    81 SyntaxVBoxIncludeGC_TEMPLATE = VBoxRc
    82 SyntaxVBoxIncludeGC_DEFS = VBOX_WITH_HGCM
    83 SyntaxVBoxIncludeGC_SOURCES := \
     81SyntaxVBoxIncludeRC_TEMPLATE = VBoxRc
     82SyntaxVBoxIncludeRC_DEFS = VBOX_WITH_HGCM
     83SyntaxVBoxIncludeRC_SOURCES := \
    8484        $(addprefix $(PATH_TARGET)/,$(subst .h,-c.c,     $(subst /,_,$(hdrs.gc)))) \
    8585        $(addprefix $(PATH_TARGET)/,$(subst .h,-cpp.cpp, $(subst /,_,$(hdrs.gc))))
     
    9898
    9999$$(PATH_TARGET)/$(flatname)-c.c: $(VBOX_ROOT_INCLUDE_MAKEFILE)  | $$(PATH_TARGET)/
    100 ifn1of ($(hdr),$(cpp_hdrs))
     100ifn1of ($(hdr), $(cpp_hdrs) VBox/intnetinline.h)
    101101        $(QUIET)$$(APPEND) -t -n $$@ '#include <$(hdr)>' 'int main(int argc, char **argv) {(void)argc; (void)argv; return 0;}'
    102102else
  • trunk/include/VBox/intnet.h

    r23209 r26574  
    11/** @file
    2  * INETNET - Internal Networking. (DEV,++)
     2 * INTNET - Internal Networking. (DEV,++)
    33 */
    44
     
    5252typedef struct INTNETRINGBUF
    5353{
    54     /** The start of the buffer offset relative to the. (inclusive) */
     54    /** The offset from this structure to the start of the buffer. */
    5555    uint32_t            offStart;
    56     /** The offset to the end of the buffer. (exclusive) */
     56    /** The offset from this structure to the end of the buffer. (exclusive). */
    5757    uint32_t            offEnd;
    5858    /** The current read offset. */
    59     uint32_t volatile   offRead;
    60     /** The current write offset. */
    61     uint32_t volatile   offWrite;
     59    uint32_t volatile   offReadX;
     60    /** Alignment. */
     61    uint32_t            u32Align0;
     62
     63    /** The committed write offset. */
     64    uint32_t volatile   offWriteCom;
     65    /** Writer internal current write offset.
     66     * This is ahead of offWriteCom when buffer space is handed to a third party for
     67     * data gathering.  offWriteCom will be assigned this value by the writer then
     68     * the frame is ready. */
     69    uint32_t volatile   offWriteInt;
     70    /** The number of bytes written (not counting overflows). */
     71    STAMCOUNTER         cbStatWritten;
     72    /** The number of frames written (not counting overflows). */
     73    STAMCOUNTER         cStatFrames;
     74    /** The number of overflows. */
     75    STAMCOUNTER         cOverflows;
    6276} INTNETRINGBUF;
     77AssertCompileSize(INTNETRINGBUF, 48);
    6378/** Pointer to a ring buffer. */
    6479typedef INTNETRINGBUF *PINTNETRINGBUF;
    6580
    66 /**
    67  * Get the amount of space available for writing.
    68  *
    69  * @returns Number of available bytes.
    70  * @param   pRingBuf        The ring buffer.
    71  */
    72 DECLINLINE(uint32_t) INTNETRingGetWritable(PINTNETRINGBUF pRingBuf)
    73 {
    74     return pRingBuf->offRead <= pRingBuf->offWrite
    75         ?  pRingBuf->offEnd  - pRingBuf->offWrite + pRingBuf->offRead - pRingBuf->offStart - 1
    76         :  pRingBuf->offRead - pRingBuf->offWrite - 1;
    77 }
    78 
    79 
    80 /**
    81  * Get the amount of data ready for reading.
    82  *
    83  * @returns Number of ready bytes.
    84  * @param   pRingBuf        The ring buffer.
    85  */
    86 DECLINLINE(uint32_t) INTNETRingGetReadable(PINTNETRINGBUF pRingBuf)
    87 {
    88     return pRingBuf->offRead <= pRingBuf->offWrite
    89         ?  pRingBuf->offWrite - pRingBuf->offRead
    90         :  pRingBuf->offEnd - pRingBuf->offRead + pRingBuf->offWrite - pRingBuf->offStart;
    91 }
     81/** The alignment of a ring buffer. */
     82#define INTNETRINGBUF_ALIGNMENT     sizeof(INTNETHDR)
     83
     84/**
     85 * Asserts the sanity of the specified INTNETRINGBUF structure.
     86 */
     87#define INTNETRINGBUF_ASSERT_SANITY(pRingBuf) \
     88    do \
     89    { \
     90        AssertPtr(pRingBuf); \
     91        { \
     92            uint32_t const offWriteCom = (pRingBuf)->offWriteCom; \
     93            uint32_t const offRead     = (pRingBuf)->offReadX; \
     94            uint32_t const offWriteInt = (pRingBuf)->offWriteInt; \
     95            \
     96            AssertMsg(offWriteCom == RT_ALIGN_32(offWriteCom, INTNETHDR_ALIGNMENT), ("%#x\n", offWriteCom)); \
     97            AssertMsg(offWriteCom >= (pRingBuf)->offStart, ("%#x %#x\n", offWriteCom, (pRingBuf)->offStart)); \
     98            AssertMsg(offWriteCom <  (pRingBuf)->offEnd,   ("%#x %#x\n", offWriteCom, (pRingBuf)->offEnd)); \
     99            \
     100            AssertMsg(offRead == RT_ALIGN_32(offRead, INTNETHDR_ALIGNMENT), ("%#x\n", offRead)); \
     101            AssertMsg(offRead >= (pRingBuf)->offStart, ("%#x %#x\n", offRead, (pRingBuf)->offStart)); \
     102            AssertMsg(offRead <  (pRingBuf)->offEnd,   ("%#x %#x\n", offRead, (pRingBuf)->offEnd)); \
     103            \
     104            AssertMsg(offWriteInt == RT_ALIGN_32(offWriteInt, INTNETHDR_ALIGNMENT), ("%#x\n", offWriteInt)); \
     105            AssertMsg(offWriteInt >= (pRingBuf)->offStart, ("%#x %#x\n", offWriteInt, (pRingBuf)->offStart)); \
     106            AssertMsg(offWriteInt <  (pRingBuf)->offEnd,   ("%#x %#x\n", offWriteInt, (pRingBuf)->offEnd)); \
     107            AssertMsg(  offRead <= offWriteCom \
     108                      ? offWriteCom <= offWriteInt || offWriteInt < offRead \
     109                      : offWriteCom <= offWriteInt, \
     110                      ("W=%#x W'=%#x R=%#x\n", offWriteCom, offWriteInt, offRead)); \
     111        } \
     112    } while (0)
     113
    92114
    93115
     
    97119typedef struct INTNETBUF
    98120{
     121    /** Magic number (INTNETBUF_MAGIC). */
     122    uint32_t        u32Magic;
    99123    /** The size of the entire buffer. */
    100124    uint32_t        cbBuf;
     
    103127    /** The size of the receive area. */
    104128    uint32_t        cbRecv;
    105     /** Alignment. */
    106     uint32_t        u32Align;
    107129    /** The receive buffer. */
    108130    INTNETRINGBUF   Recv;
     
    115137    /** Number of lost packets due to overflows. */
    116138    STAMCOUNTER     cStatLost;
    117     /** Number of packets received (not counting lost ones). */
    118     STAMCOUNTER     cStatRecvs;
    119     /** Number of frame bytes received (not couting lost frames). */
    120     STAMCOUNTER     cbStatRecv;
    121     /** Number of packets received. */
    122     STAMCOUNTER     cStatSends;
    123     /** Number of frame bytes sent. */
    124     STAMCOUNTER     cbStatSend;
     139    /** Number of bad frames (both rings). */
     140    STAMCOUNTER     cStatBadFrames;
     141    /** Reserved for future use. */
     142    STAMCOUNTER     aStatReserved[2];
    125143} INTNETBUF;
     144AssertCompileSize(INTNETBUF, 160);
     145AssertCompileMemberOffset(INTNETBUF, Recv, 16);
     146AssertCompileMemberOffset(INTNETBUF, Send, 64);
     147
    126148/** Pointer to an interface buffer. */
    127149typedef INTNETBUF *PINTNETBUF;
    128150/** Pointer to a const interface buffer. */
    129151typedef INTNETBUF const *PCINTNETBUF;
     152
     153/** Magic number for INTNETBUF::u32Magic (Sir William Gerald Golding). */
     154#define INTNETBUF_MAGIC             UINT32_C(0x19110919)
     155
     156/**
     157 * Asserts the sanity of the specified INTNETBUF structure.
     158 */
     159#define INTNETBUF_ASSERT_SANITY(pBuf) \
     160    do \
     161    { \
     162        AssertPtr(pBuf); \
     163        Assert((pBuf)->u32Magic == INTNETBUF_MAGIC); \
     164        { \
     165            uint32_t const offRecvStart = (pBuf)->Recv.offStart + RT_OFFSETOF(INTNETBUF, Recv); \
     166            uint32_t const offRecvEnd   = (pBuf)->Recv.offStart + RT_OFFSETOF(INTNETBUF, Recv); \
     167            uint32_t const offSendStart = (pBuf)->Send.offStart + RT_OFFSETOF(INTNETBUF, Send); \
     168            uint32_t const offSendEnd   = (pBuf)->Send.offStart + RT_OFFSETOF(INTNETBUF, Send); \
     169            \
     170            Assert(offRecvEnd > offRecvStart); \
     171            Assert(offRecvEnd - offRecvStart == (pBuf)->cbRecv); \
     172            Assert(offRecvStart == sizeof(INTNETBUF)); \
     173            \
     174            Assert(offSendEnd > offSendStart); \
     175            Assert(offSendEnd - offSendStart == (pBuf)->cbSend); \
     176            Assert(pffSendEnd <= (pBuf)->cbBuf); \
     177            \
     178            Assert(offSendStart == offRecvEnd); \
     179        } \
     180    } while (0)
     181
    130182
    131183/** Internal networking interface handle. */
     
    153205 * memory.
    154206 */
    155 #pragma pack(1)
    156207typedef struct INTNETHDR
    157208{
     
    163214    /** The offset from the start of this header to where the actual frame starts.
    164215     * This is used to keep the frame it self continguous in virtual memory and
    165      * thereby both simplify reading and  */
     216     * thereby both simplify access as well as the descriptor. */
    166217    int32_t         offFrame;
    167218} INTNETHDR;
    168 #pragma pack()
     219AssertCompileSize(INTNETHDR, 8);
     220AssertCompileSizeAlignment(INTNETBUF, sizeof(INTNETHDR));
    169221/** Pointer to a packet header.*/
    170222typedef INTNETHDR *PINTNETHDR;
     
    172224typedef INTNETHDR const *PCINTNETHDR;
    173225
     226/** The alignment of a packet header. */
     227#define INTNETHDR_ALIGNMENT         sizeof(INTNETHDR)
     228AssertCompile(sizeof(INTNETHDR) == INTNETHDR_ALIGNMENT);
     229AssertCompile(INTNETHDR_ALIGNMENT <= INTNETRINGBUF_ALIGNMENT);
     230
    174231/** INTNETHDR::u16Type value for normal frames. */
    175 #define INTNETHDR_TYPE_FRAME    0x2442
    176 
    177 
    178 /**
    179  * Calculates the pointer to the frame.
    180  *
    181  * @returns Pointer to the start of the frame.
    182  * @param   pHdr        Pointer to the packet header
    183  * @param   pBuf        The buffer the header is within. Only used in strict builds.
    184  */
    185 DECLINLINE(void *) INTNETHdrGetFramePtr(PCINTNETHDR pHdr, PCINTNETBUF pBuf)
    186 {
    187     uint8_t *pu8 = (uint8_t *)pHdr + pHdr->offFrame;
    188 #ifdef VBOX_STRICT
    189     const uintptr_t off = (uintptr_t)pu8 - (uintptr_t)pBuf;
    190     Assert(pHdr->u16Type == INTNETHDR_TYPE_FRAME);
    191     Assert(off < pBuf->cbBuf);
    192     Assert(off + pHdr->cbFrame <= pBuf->cbBuf);
    193 #endif
    194     NOREF(pBuf);
    195     return pu8;
    196 }
    197 
    198 
    199 /**
    200  * Skips to the next (read) frame in the buffer.
    201  *
    202  * @param   pBuf        The buffer.
    203  * @param   pRingBuf    The ring buffer in question.
    204  */
    205 DECLINLINE(void) INTNETRingSkipFrame(PINTNETBUF pBuf, PINTNETRINGBUF pRingBuf)
    206 {
    207     uint32_t    offRead   = pRingBuf->offRead;
    208     PINTNETHDR  pHdr      = (PINTNETHDR)((uint8_t *)pBuf + offRead);
    209     Assert(pRingBuf->offRead < pBuf->cbBuf);
    210     Assert(pRingBuf->offRead >= pRingBuf->offStart);
    211     Assert(pRingBuf->offRead < pRingBuf->offEnd);
    212 
    213     /* skip the frame */
    214     offRead += pHdr->offFrame + pHdr->cbFrame;
    215     offRead = RT_ALIGN_32(offRead, sizeof(INTNETHDR));
    216     Assert(offRead <= pRingBuf->offEnd && offRead >= pRingBuf->offStart);
    217     if (offRead >= pRingBuf->offEnd)
    218         offRead = pRingBuf->offStart;
    219     ASMAtomicXchgU32(&pRingBuf->offRead, offRead);
    220 }
     232#define INTNETHDR_TYPE_FRAME        0x2442
     233
     234/**
     235 * Asserts the sanity of the specified INTNETHDR.
     236 */
     237#define INTNETHDR_ASSERT_SANITY(pHdr, pRingBuf) \
     238    do \
     239    { \
     240        AssertPtr(pHdr); \
     241        Assert(RT_ALIGN_PT(pHdr, INTNETHDR_ALIGNMENT, INTNETHDR *) == pHdr); \
     242        Assert((pHdr)->u16Type == INTNETHDR_TYPE_FRAME); \
     243        { \
     244            uintptr_t const offHdr   = (uintptr_t)pHdr - (uintptr_t)pRingBuf; \
     245            uintptr_t const offFrame = offHdr + (pHdr)->offFrame; \
     246            \
     247            Assert(offHdr >= (pRingBuf)->offStart); \
     248            Assert(offHdr <  (pRingBuf)->offEnd); \
     249            \
     250            /* could do more thorough work here... later, perhaps. */ \
     251            Assert(offFrame >= (pRingBuf)->offStart); \
     252            Assert(offFrame <  (pRingBuf)->offEnd); \
     253        } \
     254    } while (0)
    221255
    222256
  • trunk/include/VBox/pdmnetifs.h

    r26305 r26574  
    190190     *          when this is a buffer of the required size available.
    191191     * @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.
    192196     *
    193197     * @param   pInterface      Pointer to the interface structure containing the called function pointer.
     
    222226     *
    223227     * @retval  VINF_SUCCESS on success.
    224      * @retval  VERR_NET_NO_NETWORK if the NIC is not connected to a network.
    225      *
    226      * @param   pInterface      Pointer to the interface structure containing the called function pointer.
     228     * @retval  VERR_NET_DOWN if the NIC is not connected to a network.  pSgBuf will
     229     *          be freed.
     230     * @retval  VERR_NET_NO_BUFFER_SPACE if we're out of resources.  pSgBuf will be
     231     *          freed.
     232     *
     233     * @param   pInterface      Pointer to the interface structure containing the
     234     *                          called function pointer.
    227235     * @param   pSgBuf          The buffer containing the data to send.  The buffer
    228      *                          ownership shall be 1.  Upon sucessfull return the
    229      *                          buffer will be owned by the downstream driver and
    230      *                          have ownership set to 2.  The caller must not ever
    231      *                          touch it again.  On failure the buffer remains in
    232      *                          the callers ownership and it should be handed over
    233      *                          to PDMINETWORKUP::pfnFreeBuf.
     236     *                          ownership shall be 1.  The buffer will always be
     237     *                          consumed, regardless of the status code.
     238     *
    234239     * @param   fOnWorkerThread Set if we're being called on a work thread.  Clear
    235240     *                          if an EMT.
Note: See TracChangeset for help on using the changeset viewer.

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