VirtualBox

Changeset 44849 in vbox


Ignore:
Timestamp:
Feb 27, 2013 8:22:06 PM (12 years ago)
Author:
vboxsync
Message:

DevirtioNet.cpp: cleanups.

Location:
trunk/src/VBox/Devices
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Network/DevVirtioNet.cpp

    r44528 r44849  
    55
    66/*
    7  * Copyright (C) 2009-2012 Oracle Corporation
     7 * Copyright (C) 2009-2013 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1717
    1818
     19/*******************************************************************************
     20*   Header Files                                                               *
     21*******************************************************************************/
    1922#define LOG_GROUP LOG_GROUP_DEV_VIRTIO_NET
    2023#define VNET_GC_SUPPORT
     
    3538
    3639
     40/*******************************************************************************
     41*   Defined Constants And Macros                                               *
     42*******************************************************************************/
    3743#ifndef VBOX_DEVICE_STRUCT_TESTCASE
    3844
    39 #define INSTANCE(pState) pState->VPCI.szInstance
    40 #define STATUS pState->config.uStatus
     45#define INSTANCE(pThis) pThis->VPCI.szInstance
     46#define STATUS pThis->config.uStatus
    4147
    4248#ifdef IN_RING3
     
    5763#endif /* IN_RING3 */
    5864
    59 /* Forward declarations ******************************************************/
    60 RT_C_DECLS_BEGIN
    61 PDMBOTHCBDECL(int) vnetIOPortIn (PPDMDEVINS pDevIns, void *pvUser, RTIOPORT port, uint32_t *pu32, unsigned cb);
    62 PDMBOTHCBDECL(int) vnetIOPortOut(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT port, uint32_t u32, unsigned cb);
    63 RT_C_DECLS_END
    64 
    6565#endif /* VBOX_DEVICE_STRUCT_TESTCASE */
    6666
    6767
    68 #define VNET_TX_DELAY           150   /* 150 microseconds */
    69 #define VNET_MAX_FRAME_SIZE     65536  // TODO: Is it the right limit?
     68#define VNET_TX_DELAY           150   /**< 150 microseconds */
     69#define VNET_MAX_FRAME_SIZE     65536  ///< @todo Is it the right limit?
    7070#define VNET_MAC_FILTER_LEN     32
    7171#define VNET_MAX_VID            (1 << 12)
    7272
    73 /* Virtio net features */
    74 #define VNET_F_CSUM       0x00000001  /* Host handles pkts w/ partial csum */
    75 #define VNET_F_GUEST_CSUM 0x00000002  /* Guest handles pkts w/ partial csum */
    76 #define VNET_F_MAC        0x00000020  /* Host has given MAC address. */
    77 #define VNET_F_GSO        0x00000040  /* Host handles pkts w/ any GSO type */
    78 #define VNET_F_GUEST_TSO4 0x00000080  /* Guest can handle TSOv4 in. */
    79 #define VNET_F_GUEST_TSO6 0x00000100  /* Guest can handle TSOv6 in. */
    80 #define VNET_F_GUEST_ECN  0x00000200  /* Guest can handle TSO[6] w/ ECN in. */
    81 #define VNET_F_GUEST_UFO  0x00000400  /* Guest can handle UFO in. */
    82 #define VNET_F_HOST_TSO4  0x00000800  /* Host can handle TSOv4 in. */
    83 #define VNET_F_HOST_TSO6  0x00001000  /* Host can handle TSOv6 in. */
    84 #define VNET_F_HOST_ECN   0x00002000  /* Host can handle TSO[6] w/ ECN in. */
    85 #define VNET_F_HOST_UFO   0x00004000  /* Host can handle UFO in. */
    86 #define VNET_F_MRG_RXBUF  0x00008000  /* Host can merge receive buffers. */
    87 #define VNET_F_STATUS     0x00010000  /* virtio_net_config.status available */
    88 #define VNET_F_CTRL_VQ    0x00020000  /* Control channel available */
    89 #define VNET_F_CTRL_RX    0x00040000  /* Control channel RX mode support */
    90 #define VNET_F_CTRL_VLAN  0x00080000  /* Control channel VLAN filtering */
     73/** @name Virtio net features
     74 * @{  */
     75#define VNET_F_CSUM       0x00000001  /**< Host handles pkts w/ partial csum */
     76#define VNET_F_GUEST_CSUM 0x00000002  /**< Guest handles pkts w/ partial csum */
     77#define VNET_F_MAC        0x00000020  /**< Host has given MAC address. */
     78#define VNET_F_GSO        0x00000040  /**< Host handles pkts w/ any GSO type */
     79#define VNET_F_GUEST_TSO4 0x00000080  /**< Guest can handle TSOv4 in. */
     80#define VNET_F_GUEST_TSO6 0x00000100  /**< Guest can handle TSOv6 in. */
     81#define VNET_F_GUEST_ECN  0x00000200  /**< Guest can handle TSO[6] w/ ECN in. */
     82#define VNET_F_GUEST_UFO  0x00000400  /**< Guest can handle UFO in. */
     83#define VNET_F_HOST_TSO4  0x00000800  /**< Host can handle TSOv4 in. */
     84#define VNET_F_HOST_TSO6  0x00001000  /**< Host can handle TSOv6 in. */
     85#define VNET_F_HOST_ECN   0x00002000  /**< Host can handle TSO[6] w/ ECN in. */
     86#define VNET_F_HOST_UFO   0x00004000  /**< Host can handle UFO in. */
     87#define VNET_F_MRG_RXBUF  0x00008000  /**< Host can merge receive buffers. */
     88#define VNET_F_STATUS     0x00010000  /**< virtio_net_config.status available */
     89#define VNET_F_CTRL_VQ    0x00020000  /**< Control channel available */
     90#define VNET_F_CTRL_RX    0x00040000  /**< Control channel RX mode support */
     91#define VNET_F_CTRL_VLAN  0x00080000  /**< Control channel VLAN filtering */
     92/** @} */
    9193
    9294#define VNET_S_LINK_UP    1
    9395
    9496
     97/*******************************************************************************
     98*   Structures and Typedefs                                                    *
     99*******************************************************************************/
    95100#ifdef _MSC_VER
    96101struct VNetPCIConfig
    97102#else /* !_MSC_VER */
    98 struct __attribute__ ((__packed__)) VNetPCIConfig
     103struct __attribute__ ((__packed__)) VNetPCIConfig /** @todo r=bird: Use #pragma pack if necessary, that's portable! */
    99104#endif /* !_MSC_VER */
    100105{
     
    111116 * @implements  PDMINETWORKCONFIG
    112117 */
    113 struct VNetState_st
     118typedef struct VNetState_st
    114119{
    115120    /* VPCISTATE must be the first member! */
     
    191196    RTSEMEVENT              hEventMoreRxDescAvail;
    192197
    193     /* Statistic fields ******************************************************/
    194 
     198    /** @name Statistic
     199     * @{ */
    195200    STAMCOUNTER             StatReceiveBytes;
    196201    STAMCOUNTER             StatTransmitBytes;
     
    207212    STAMCOUNTER             StatRxOverflowWakeup;
    208213#endif /* VBOX_WITH_STATISTICS */
    209 
    210 };
    211 typedef struct VNetState_st VNETSTATE;
     214    /** @}  */
     215} VNETSTATE;
     216/** Pointer to a virtual I/O network device state. */
    212217typedef VNETSTATE *PVNETSTATE;
    213218
     
    271276AssertCompileSize(VNETCTLHDR, 2);
    272277
    273 /* Returns true if large packets are written into several RX buffers. */
    274 DECLINLINE(bool) vnetMergeableRxBuffers(PVNETSTATE pState)
    275 {
    276     return !!(pState->VPCI.uGuestFeatures & VNET_F_MRG_RXBUF);
    277 }
    278 
    279 DECLINLINE(int) vnetCsEnter(PVNETSTATE pState, int rcBusy)
    280 {
    281     return vpciCsEnter(&pState->VPCI, rcBusy);
    282 }
    283 
    284 DECLINLINE(void) vnetCsLeave(PVNETSTATE pState)
    285 {
    286     vpciCsLeave(&pState->VPCI);
    287 }
    288 
    289 DECLINLINE(int) vnetCsRxEnter(PVNETSTATE pState, int rcBusy)
    290 {
    291     // STAM_PROFILE_START(&pState->CTXSUFF(StatCsRx), a);
    292     // int rc = PDMCritSectEnter(&pState->csRx, rcBusy);
    293     // STAM_PROFILE_STOP(&pState->CTXSUFF(StatCsRx), a);
     278/** Returns true if large packets are written into several RX buffers. */
     279DECLINLINE(bool) vnetMergeableRxBuffers(PVNETSTATE pThis)
     280{
     281    return !!(pThis->VPCI.uGuestFeatures & VNET_F_MRG_RXBUF);
     282}
     283
     284DECLINLINE(int) vnetCsEnter(PVNETSTATE pThis, int rcBusy)
     285{
     286    return vpciCsEnter(&pThis->VPCI, rcBusy);
     287}
     288
     289DECLINLINE(void) vnetCsLeave(PVNETSTATE pThis)
     290{
     291    vpciCsLeave(&pThis->VPCI);
     292}
     293
     294DECLINLINE(int) vnetCsRxEnter(PVNETSTATE pThis, int rcBusy)
     295{
     296    // STAM_PROFILE_START(&pThis->CTXSUFF(StatCsRx), a);
     297    // int rc = PDMCritSectEnter(&pThis->csRx, rcBusy);
     298    // STAM_PROFILE_STOP(&pThis->CTXSUFF(StatCsRx), a);
    294299    // return rc;
    295300    return VINF_SUCCESS;
    296301}
    297302
    298 DECLINLINE(void) vnetCsRxLeave(PVNETSTATE pState)
    299 {
    300     // PDMCritSectLeave(&pState->csRx);
     303DECLINLINE(void) vnetCsRxLeave(PVNETSTATE pThis)
     304{
     305    // PDMCritSectLeave(&pThis->csRx);
    301306}
    302307
     
    304309 * Dump a packet to debug log.
    305310 *
    306  * @param   pState      The device state structure.
     311 * @param   pThis      The device state structure.
    307312 * @param   cpPacket    The packet.
    308313 * @param   cb          The size of the packet.
    309314 * @param   cszText     A string denoting direction of packet transfer.
    310315 */
    311 DECLINLINE(void) vnetPacketDump(PVNETSTATE pState, const uint8_t *cpPacket, size_t cb, const char *cszText)
     316DECLINLINE(void) vnetPacketDump(PVNETSTATE pThis, const uint8_t *cpPacket, size_t cb, const char *cszText)
    312317{
    313318#ifdef DEBUG
    314319    Log(("%s %s packet #%d (%d bytes):\n",
    315          INSTANCE(pState), cszText, ++pState->u32PktNo, cb));
     320         INSTANCE(pThis), cszText, ++pThis->u32PktNo, cb));
    316321    Log3(("%.*Rhxd\n", cb, cpPacket));
    317322#endif
     
    321326 * Print features given in uFeatures to debug log.
    322327 *
    323  * @param   pState      The device state structure.
    324  * @param   uFeatures   Descriptions of which features to print.
     328 * @param   pThis      The device state structure.
     329 * @param   fFeatures   Descriptions of which features to print.
    325330 * @param   pcszText    A string to print before the list of features.
    326331 */
    327 DECLINLINE(void) vnetPrintFeatures(PVNETSTATE pState, uint32_t uFeatures, const char *pcszText)
     332DECLINLINE(void) vnetPrintFeatures(PVNETSTATE pThis, uint32_t fFeatures, const char *pcszText)
    328333{
    329334#ifdef DEBUG
     
    332337        uint32_t uMask;
    333338        const char *pcszDesc;
    334     } aFeatures[] = {
     339    } const s_aFeatures[] =
     340    {
    335341        { VNET_F_CSUM,       "host handles pkts w/ partial csum" },
    336342        { VNET_F_GUEST_CSUM, "guest handles pkts w/ partial csum" },
     
    352358    };
    353359
    354     Log3(("%s %s:\n", INSTANCE(pState), pcszText));
    355     for (unsigned i = 0; i < RT_ELEMENTS(aFeatures); ++i)
    356     {
    357         if (aFeatures[i].uMask & uFeatures)
    358             Log3(("%s --> %s\n", INSTANCE(pState), aFeatures[i].pcszDesc));
     360    Log3(("%s %s:\n", INSTANCE(pThis), pcszText));
     361    for (unsigned i = 0; i < RT_ELEMENTS(s_aFeatures); ++i)
     362    {
     363        if (s_aFeatures[i].uMask & fFeatures)
     364            Log3(("%s --> %s\n", INSTANCE(pThis), s_aFeatures[i].pcszDesc));
    359365    }
    360366#endif /* DEBUG */
     
    396402}
    397403
    398 PDMBOTHCBDECL(void) vnetSetHostFeatures(void *pvState, uint32_t uFeatures)
    399 {
    400     // TODO: Nothing to do here yet
    401     VNETSTATE *pState = (VNETSTATE *)pvState;
    402     LogFlow(("%s vnetSetHostFeatures: uFeatures=%x\n", INSTANCE(pState), uFeatures));
    403     vnetPrintFeatures(pState, uFeatures, "The guest negotiated the following features");
     404PDMBOTHCBDECL(void) vnetSetHostFeatures(void *pvState, uint32_t fFeatures)
     405{
     406    /** @todo Nothing to do here yet */
     407    PVNETSTATE pThis = (PVNETSTATE)pvState;
     408    LogFlow(("%s vnetSetHostFeatures: uFeatures=%x\n", INSTANCE(pThis), fFeatures));
     409    vnetPrintFeatures(pThis, fFeatures, "The guest negotiated the following features");
    404410}
    405411
    406412PDMBOTHCBDECL(int) vnetGetConfig(void *pvState, uint32_t port, uint32_t cb, void *data)
    407413{
    408     VNETSTATE *pState = (VNETSTATE *)pvState;
     414    PVNETSTATE pThis = (PVNETSTATE)pvState;
    409415    if (port + cb > sizeof(struct VNetPCIConfig))
    410416    {
    411         Log(("%s vnetGetConfig: Read beyond the config structure is attempted (port=%RTiop cb=%x).\n", INSTANCE(pState), port, cb));
     417        Log(("%s vnetGetConfig: Read beyond the config structure is attempted (port=%RTiop cb=%x).\n", INSTANCE(pThis), port, cb));
    412418        return VERR_IOM_IOPORT_UNUSED;
    413419    }
    414     memcpy(data, ((uint8_t*)&pState->config) + port, cb);
     420    memcpy(data, ((uint8_t*)&pThis->config) + port, cb);
    415421    return VINF_SUCCESS;
    416422}
     
    418424PDMBOTHCBDECL(int) vnetSetConfig(void *pvState, uint32_t port, uint32_t cb, void *data)
    419425{
    420     VNETSTATE *pState = (VNETSTATE *)pvState;
     426    PVNETSTATE pThis = (PVNETSTATE)pvState;
    421427    if (port + cb > sizeof(struct VNetPCIConfig))
    422428    {
    423         Log(("%s vnetGetConfig: Write beyond the config structure is attempted (port=%RTiop cb=%x).\n", INSTANCE(pState), port, cb));
     429        Log(("%s vnetGetConfig: Write beyond the config structure is attempted (port=%RTiop cb=%x).\n", INSTANCE(pThis), port, cb));
    424430        if (port < sizeof(struct VNetPCIConfig))
    425             memcpy(((uint8_t*)&pState->config) + port, data,
     431            memcpy(((uint8_t*)&pThis->config) + port, data,
    426432                   sizeof(struct VNetPCIConfig) - port);
    427433        return VINF_SUCCESS;
    428434    }
    429     memcpy(((uint8_t*)&pState->config) + port, data, cb);
     435    memcpy(((uint8_t*)&pThis->config) + port, data, cb);
    430436    return VINF_SUCCESS;
    431437}
     
    434440 * Hardware reset. Revert all registers to initial values.
    435441 *
    436  * @param   pState      The device state structure.
     442 * @param   pThis      The device state structure.
    437443 */
    438444PDMBOTHCBDECL(int) vnetReset(void *pvState)
    439445{
    440     VNETSTATE *pState = (VNETSTATE*)pvState;
    441     Log(("%s Reset triggered\n", INSTANCE(pState)));
    442 
    443     int rc = vnetCsRxEnter(pState, VERR_SEM_BUSY);
     446    PVNETSTATE pThis = (PVNETSTATE)pvState;
     447    Log(("%s Reset triggered\n", INSTANCE(pThis)));
     448
     449    int rc = vnetCsRxEnter(pThis, VERR_SEM_BUSY);
    444450    if (RT_UNLIKELY(rc != VINF_SUCCESS))
    445451    {
     
    447453        return rc;
    448454    }
    449     vpciReset(&pState->VPCI);
    450     vnetCsRxLeave(pState);
     455    vpciReset(&pThis->VPCI);
     456    vnetCsRxLeave(pThis);
    451457
    452458    // TODO: Implement reset
    453     if (pState->fCableConnected)
     459    if (pThis->fCableConnected)
    454460        STATUS = VNET_S_LINK_UP;
    455461    else
     
    460466     * virtio mode.
    461467     */
    462     pState->fPromiscuous      = true;
    463     pState->fAllMulti         = false;
    464     pState->nMacFilterEntries = 0;
    465     memset(pState->aMacFilter,  0, VNET_MAC_FILTER_LEN * sizeof(RTMAC));
    466     memset(pState->aVlanFilter, 0, sizeof(pState->aVlanFilter));
    467     pState->uIsTransmitting   = 0;
     468    pThis->fPromiscuous      = true;
     469    pThis->fAllMulti         = false;
     470    pThis->nMacFilterEntries = 0;
     471    memset(pThis->aMacFilter,  0, VNET_MAC_FILTER_LEN * sizeof(RTMAC));
     472    memset(pThis->aVlanFilter, 0, sizeof(pThis->aVlanFilter));
     473    pThis->uIsTransmitting   = 0;
    468474#ifndef IN_RING3
    469475    return VINF_IOM_R3_IOPORT_WRITE;
    470476#else
    471     if (pState->pDrv)
    472         pState->pDrv->pfnSetPromiscuousMode(pState->pDrv, true);
     477    if (pThis->pDrv)
     478        pThis->pDrv->pfnSetPromiscuousMode(pThis->pDrv, true);
    473479    return VINF_SUCCESS;
    474480#endif
     
    482488static void vnetWakeupReceive(PPDMDEVINS pDevIns)
    483489{
    484     VNETSTATE *pState = PDMINS_2_DATA(pDevIns, VNETSTATE *);
    485     if (    pState->fMaybeOutOfSpace
    486         &&  pState->hEventMoreRxDescAvail != NIL_RTSEMEVENT)
    487     {
    488         STAM_COUNTER_INC(&pState->StatRxOverflowWakeup);
    489         Log(("%s Waking up Out-of-RX-space semaphore\n",  INSTANCE(pState)));
    490         RTSemEventSignal(pState->hEventMoreRxDescAvail);
    491     }
    492 }
    493 
    494 /**
    495  * Link Up Timer handler.
    496  *
    497  * @param   pDevIns     Pointer to device instance structure.
    498  * @param   pTimer      Pointer to the timer.
    499  * @param   pvUser      NULL.
    500  * @thread  EMT
     490    PVNETSTATE pThis = PDMINS_2_DATA(pDevIns, PVNETSTATE);
     491    if (    pThis->fMaybeOutOfSpace
     492        &&  pThis->hEventMoreRxDescAvail != NIL_RTSEMEVENT)
     493    {
     494        STAM_COUNTER_INC(&pThis->StatRxOverflowWakeup);
     495        Log(("%s Waking up Out-of-RX-space semaphore\n",  INSTANCE(pThis)));
     496        RTSemEventSignal(pThis->hEventMoreRxDescAvail);
     497    }
     498}
     499
     500
     501/**
     502 * @callback_method_impl{FNTMTIMERDEV, Link Up Timer handler.}
    501503 */
    502504static DECLCALLBACK(void) vnetLinkUpTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser)
    503505{
    504     VNETSTATE *pState = (VNETSTATE *)pvUser;
    505 
    506     int rc = vnetCsEnter(pState, VERR_SEM_BUSY);
     506    PVNETSTATE pThis = (PVNETSTATE)pvUser;
     507
     508    int rc = vnetCsEnter(pThis, VERR_SEM_BUSY);
    507509    if (RT_UNLIKELY(rc != VINF_SUCCESS))
    508510        return;
    509511    STATUS |= VNET_S_LINK_UP;
    510     vpciRaiseInterrupt(&pState->VPCI, VERR_SEM_BUSY, VPCI_ISR_CONFIG);
     512    vpciRaiseInterrupt(&pThis->VPCI, VERR_SEM_BUSY, VPCI_ISR_CONFIG);
    511513    vnetWakeupReceive(pDevIns);
    512     vnetCsLeave(pState);
    513 }
    514 
    515 
    516 
    517 
    518 /**
    519  * Handler for the wakeup signaller queue.
     514    vnetCsLeave(pThis);
     515}
     516
     517
     518/**
     519 * @callback_method_impl{FNPDMQUEUEDEV, Handler for the wakeup signaller queue.}
    520520 */
    521521static DECLCALLBACK(bool) vnetCanRxQueueConsumer(PPDMDEVINS pDevIns, PPDMQUEUEITEMCORE pItem)
     
    530530 * This function is called when the driver becomes ready.
    531531 *
    532  * @param   pState      The device state structure.
    533  */
    534 PDMBOTHCBDECL(void) vnetReady(void *pvState)
    535 {
    536     VNETSTATE *pState = (VNETSTATE*)pvState;
    537     Log(("%s Driver became ready, waking up RX thread...\n", INSTANCE(pState)));
     532 * @param   pThis      The device state structure.
     533 */
     534static void vnetReady(void *pvState)
     535{
     536    PVNETSTATE pThis = (PVNETSTATE)pvState;
     537    Log(("%s Driver became ready, waking up RX thread...\n", INSTANCE(pThis)));
    538538#ifdef IN_RING3
    539     vnetWakeupReceive(pState->VPCI.CTX_SUFF(pDevIns));
     539    vnetWakeupReceive(pThis->VPCI.CTX_SUFF(pDevIns));
    540540#else
    541     PPDMQUEUEITEMCORE pItem = PDMQueueAlloc(pState->CTX_SUFF(pCanRxQueue));
     541    PPDMQUEUEITEMCORE pItem = PDMQueueAlloc(pThis->CTX_SUFF(pCanRxQueue));
    542542    if (pItem)
    543         PDMQueueInsert(pState->CTX_SUFF(pCanRxQueue), pItem);
     543        PDMQueueInsert(pThis->CTX_SUFF(pCanRxQueue), pItem);
    544544#endif
    545545}
    546546
    547547/**
    548  * Port I/O Handler for IN operations.
    549  *
    550  * @returns VBox status code.
    551  *
    552  * @param   pDevIns     The device instance.
    553  * @param   pvUser      Pointer to the device state structure.
    554  * @param   port        Port number used for the IN operation.
    555  * @param   pu32        Where to store the result.
    556  * @param   cb          Number of bytes read.
    557  * @thread  EMT
    558  */
    559 PDMBOTHCBDECL(int) vnetIOPortIn(PPDMDEVINS pDevIns, void *pvUser,
    560                                 RTIOPORT port, uint32_t *pu32, unsigned cb)
     548 * @callback_method_impl{FNIOMIOPORTIN}
     549 */
     550PDMBOTHCBDECL(int) vnetIOPortIn(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT port, uint32_t *pu32, unsigned cb)
    561551{
    562552    return vpciIOPortIn(pDevIns, pvUser, port, pu32, cb,
     
    567557
    568558/**
    569  * Port I/O Handler for OUT operations.
    570  *
    571  * @returns VBox status code.
    572  *
    573  * @param   pDevIns     The device instance.
    574  * @param   pvUser      User argument.
    575  * @param   Port        Port number used for the IN operation.
    576  * @param   u32         The value to output.
    577  * @param   cb          The value size in bytes.
    578  * @thread  EMT
    579  */
    580 PDMBOTHCBDECL(int) vnetIOPortOut(PPDMDEVINS pDevIns, void *pvUser,
    581                                  RTIOPORT port, uint32_t u32, unsigned cb)
     559 * @callback_method_impl{FNIOMIOPORTOUT}
     560 */
     561PDMBOTHCBDECL(int) vnetIOPortOut(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT port, uint32_t u32, unsigned cb)
    582562{
    583563    return vpciIOPortOut(pDevIns, pvUser, port, u32, cb,
     
    605585 * @thread  RX
    606586 */
    607 static int vnetCanReceive(VNETSTATE *pState)
    608 {
    609     int rc = vnetCsRxEnter(pState, VERR_SEM_BUSY);
     587static int vnetCanReceive(PVNETSTATE pThis)
     588{
     589    int rc = vnetCsRxEnter(pThis, VERR_SEM_BUSY);
    610590    AssertRCReturn(rc, rc);
    611591
    612     LogFlow(("%s vnetCanReceive\n", INSTANCE(pState)));
    613     if (!(pState->VPCI.uStatus & VPCI_STATUS_DRV_OK))
     592    LogFlow(("%s vnetCanReceive\n", INSTANCE(pThis)));
     593    if (!(pThis->VPCI.uStatus & VPCI_STATUS_DRV_OK))
    614594        rc = VERR_NET_NO_BUFFER_SPACE;
    615     else if (!vqueueIsReady(&pState->VPCI, pState->pRxQueue))
     595    else if (!vqueueIsReady(&pThis->VPCI, pThis->pRxQueue))
    616596        rc = VERR_NET_NO_BUFFER_SPACE;
    617     else if (vqueueIsEmpty(&pState->VPCI, pState->pRxQueue))
    618     {
    619         vringSetNotification(&pState->VPCI, &pState->pRxQueue->VRing, true);
     597    else if (vqueueIsEmpty(&pThis->VPCI, pThis->pRxQueue))
     598    {
     599        vringSetNotification(&pThis->VPCI, &pThis->pRxQueue->VRing, true);
    620600        rc = VERR_NET_NO_BUFFER_SPACE;
    621601    }
    622602    else
    623603    {
    624         vringSetNotification(&pState->VPCI, &pState->pRxQueue->VRing, false);
     604        vringSetNotification(&pThis->VPCI, &pThis->pRxQueue->VRing, false);
    625605        rc = VINF_SUCCESS;
    626606    }
    627607
    628     LogFlow(("%s vnetCanReceive -> %Rrc\n", INSTANCE(pState), rc));
    629     vnetCsRxLeave(pState);
     608    LogFlow(("%s vnetCanReceive -> %Rrc\n", INSTANCE(pThis), rc));
     609    vnetCsRxLeave(pThis);
    630610    return rc;
    631611}
     
    636616static DECLCALLBACK(int) vnetNetworkDown_WaitReceiveAvail(PPDMINETWORKDOWN pInterface, RTMSINTERVAL cMillies)
    637617{
    638     VNETSTATE *pState = RT_FROM_MEMBER(pInterface, VNETSTATE, INetworkDown);
    639     LogFlow(("%s vnetNetworkDown_WaitReceiveAvail(cMillies=%u)\n", INSTANCE(pState), cMillies));
    640     int rc = vnetCanReceive(pState);
     618    PVNETSTATE pThis = RT_FROM_MEMBER(pInterface, VNETSTATE, INetworkDown);
     619    LogFlow(("%s vnetNetworkDown_WaitReceiveAvail(cMillies=%u)\n", INSTANCE(pThis), cMillies));
     620    int rc = vnetCanReceive(pThis);
    641621
    642622    if (RT_SUCCESS(rc))
     
    646626
    647627    rc = VERR_INTERRUPTED;
    648     ASMAtomicXchgBool(&pState->fMaybeOutOfSpace, true);
    649     STAM_PROFILE_START(&pState->StatRxOverflow, a);
     628    ASMAtomicXchgBool(&pThis->fMaybeOutOfSpace, true);
     629    STAM_PROFILE_START(&pThis->StatRxOverflow, a);
    650630
    651631    VMSTATE enmVMState;
    652     while (RT_LIKELY(   (enmVMState = PDMDevHlpVMState(pState->VPCI.CTX_SUFF(pDevIns))) == VMSTATE_RUNNING
     632    while (RT_LIKELY(   (enmVMState = PDMDevHlpVMState(pThis->VPCI.CTX_SUFF(pDevIns))) == VMSTATE_RUNNING
    653633                     ||  enmVMState == VMSTATE_RUNNING_LS))
    654634    {
    655         int rc2 = vnetCanReceive(pState);
     635        int rc2 = vnetCanReceive(pThis);
    656636        if (RT_SUCCESS(rc2))
    657637        {
     
    660640        }
    661641        Log(("%s vnetNetworkDown_WaitReceiveAvail: waiting cMillies=%u...\n",
    662                 INSTANCE(pState), cMillies));
    663         RTSemEventWait(pState->hEventMoreRxDescAvail, cMillies);
    664     }
    665     STAM_PROFILE_STOP(&pState->StatRxOverflow, a);
    666     ASMAtomicXchgBool(&pState->fMaybeOutOfSpace, false);
    667 
    668     LogFlow(("%s vnetNetworkDown_WaitReceiveAvail -> %d\n", INSTANCE(pState), rc));
     642                INSTANCE(pThis), cMillies));
     643        RTSemEventWait(pThis->hEventMoreRxDescAvail, cMillies);
     644    }
     645    STAM_PROFILE_STOP(&pThis->StatRxOverflow, a);
     646    ASMAtomicXchgBool(&pThis->fMaybeOutOfSpace, false);
     647
     648    LogFlow(("%s vnetNetworkDown_WaitReceiveAvail -> %d\n", INSTANCE(pThis), rc));
    669649    return rc;
    670650}
     
    676656static DECLCALLBACK(void *) vnetQueryInterface(struct PDMIBASE *pInterface, const char *pszIID)
    677657{
    678     VNETSTATE *pThis = RT_FROM_MEMBER(pInterface, VNETSTATE, VPCI.IBase);
     658    PVNETSTATE pThis = RT_FROM_MEMBER(pInterface, VNETSTATE, VPCI.IBase);
    679659    Assert(&pThis->VPCI.IBase == pInterface);
    680660
     
    712692 *
    713693 * @returns true if packet is intended for this node.
    714  * @param   pState          Pointer to the state structure.
     694 * @param   pThis          Pointer to the state structure.
    715695 * @param   pvBuf           The ethernet packet.
    716696 * @param   cb              Number of bytes available in the packet.
    717697 */
    718 static bool vnetAddressFilter(PVNETSTATE pState, const void *pvBuf, size_t cb)
    719 {
    720     if (pState->fPromiscuous)
     698static bool vnetAddressFilter(PVNETSTATE pThis, const void *pvBuf, size_t cb)
     699{
     700    if (pThis->fPromiscuous)
    721701        return true;
    722702
     
    725705    /* Compare TPID with VLAN Ether Type */
    726706    if (   u16Ptr[6] == RT_H2BE_U16(0x8100)
    727         && !ASMBitTest(pState->aVlanFilter, RT_BE2H_U16(u16Ptr[7]) & 0xFFF))
    728     {
    729         Log4(("%s vnetAddressFilter: not our VLAN, returning false\n", INSTANCE(pState)));
     707        && !ASMBitTest(pThis->aVlanFilter, RT_BE2H_U16(u16Ptr[7]) & 0xFFF))
     708    {
     709        Log4(("%s vnetAddressFilter: not our VLAN, returning false\n", INSTANCE(pThis)));
    730710        return false;
    731711    }
     
    734714        return true;
    735715
    736     if (pState->fAllMulti && vnetIsMulticast(pvBuf))
     716    if (pThis->fAllMulti && vnetIsMulticast(pvBuf))
    737717        return true;
    738718
    739     if (!memcmp(pState->config.mac.au8, pvBuf, sizeof(RTMAC)))
     719    if (!memcmp(pThis->config.mac.au8, pvBuf, sizeof(RTMAC)))
    740720        return true;
    741721    Log4(("%s vnetAddressFilter: %RTmac (conf) != %RTmac (dest)\n",
    742           INSTANCE(pState), pState->config.mac.au8, pvBuf));
    743 
    744     for (unsigned i = 0; i < pState->nMacFilterEntries; i++)
    745         if (!memcmp(&pState->aMacFilter[i], pvBuf, sizeof(RTMAC)))
     722          INSTANCE(pThis), pThis->config.mac.au8, pvBuf));
     723
     724    for (unsigned i = 0; i < pThis->nMacFilterEntries; i++)
     725        if (!memcmp(&pThis->aMacFilter[i], pvBuf, sizeof(RTMAC)))
    746726            return true;
    747727
    748     Log2(("%s vnetAddressFilter: failed all tests, returning false, packet dump follows:\n", INSTANCE(pState)));
    749     vnetPacketDump(pState, (const uint8_t*)pvBuf, cb, "<-- Incoming");
     728    Log2(("%s vnetAddressFilter: failed all tests, returning false, packet dump follows:\n", INSTANCE(pThis)));
     729    vnetPacketDump(pThis, (const uint8_t*)pvBuf, cb, "<-- Incoming");
    750730
    751731    return false;
     
    759739 *
    760740 * @returns VBox status code.
    761  * @param   pState          The device state structure.
     741 * @param   pThis          The device state structure.
    762742 * @param   pvBuf           The available data.
    763743 * @param   cb              Number of bytes available in the buffer.
    764744 * @thread  RX
    765745 */
    766 static int vnetHandleRxPacket(PVNETSTATE pState, const void *pvBuf, size_t cb,
     746static int vnetHandleRxPacket(PVNETSTATE pThis, const void *pvBuf, size_t cb,
    767747                              PCPDMNETWORKGSO pGso)
    768748{
     
    775755    {
    776756        Log2(("%s vnetHandleRxPacket: gso type=%x cbHdrsTotal=%u cbHdrsSeg=%u mss=%u"
    777               " off1=0x%x off2=0x%x\n", INSTANCE(pState), pGso->u8Type,
     757              " off1=0x%x off2=0x%x\n", INSTANCE(pThis), pGso->u8Type,
    778758              pGso->cbHdrsTotal, pGso->cbHdrsSeg, pGso->cbMaxSeg, pGso->offHdr1, pGso->offHdr2));
    779759        Hdr.Hdr.u8Flags = VNETHDR_F_NEEDS_CSUM;
     
    798778        Hdr.Hdr.u16GSOSize = pGso->cbMaxSeg;
    799779        Hdr.Hdr.u16CSumStart = pGso->offHdr2;
    800         STAM_REL_COUNTER_INC(&pState->StatReceiveGSO);
     780        STAM_REL_COUNTER_INC(&pThis->StatReceiveGSO);
    801781    }
    802782    else
     
    806786    }
    807787
    808     if (vnetMergeableRxBuffers(pState))
     788    if (vnetMergeableRxBuffers(pThis))
    809789        uHdrLen = sizeof(VNETHDRMRX);
    810790    else
    811791        uHdrLen = sizeof(VNETHDR);
    812792
    813     vnetPacketDump(pState, (const uint8_t*)pvBuf, cb, "<-- Incoming");
     793    vnetPacketDump(pThis, (const uint8_t*)pvBuf, cb, "<-- Incoming");
    814794
    815795    unsigned int uOffset = 0;
     
    820800        unsigned int nSeg = 0, uElemSize = 0, cbReserved = 0;
    821801
    822         if (!vqueueGet(&pState->VPCI, pState->pRxQueue, &elem))
     802        if (!vqueueGet(&pThis->VPCI, pThis->pRxQueue, &elem))
    823803        {
    824804            /*
     
    826806             * were added and we received a big packet.
    827807             */
    828             Log(("%s vnetHandleRxPacket: Suddenly there is no space in receive queue!\n", INSTANCE(pState)));
     808            Log(("%s vnetHandleRxPacket: Suddenly there is no space in receive queue!\n", INSTANCE(pThis)));
    829809            return VERR_INTERNAL_ERROR;
    830810        }
     
    832812        if (elem.nIn < 1)
    833813        {
    834             Log(("%s vnetHandleRxPacket: No writable descriptors in receive queue!\n", INSTANCE(pState)));
     814            Log(("%s vnetHandleRxPacket: No writable descriptors in receive queue!\n", INSTANCE(pThis)));
    835815            return VERR_INTERNAL_ERROR;
    836816        }
     
    838818        if (nElem == 0)
    839819        {
    840             if (vnetMergeableRxBuffers(pState))
     820            if (vnetMergeableRxBuffers(pThis))
    841821            {
    842822                addrHdrMrx = elem.aSegsIn[nSeg].addr;
     
    848828                if (elem.aSegsIn[nSeg].cb != sizeof(VNETHDR))
    849829                {
    850                     Log(("%s vnetHandleRxPacket: The first descriptor does match the header size!\n", INSTANCE(pState)));
     830                    Log(("%s vnetHandleRxPacket: The first descriptor does match the header size!\n", INSTANCE(pThis)));
    851831                    return VERR_INTERNAL_ERROR;
    852832                }
     
    863843            uElemSize += uSize;
    864844        }
    865         STAM_PROFILE_START(&pState->StatReceiveStore, a);
    866         vqueuePut(&pState->VPCI, pState->pRxQueue, &elem, uElemSize, cbReserved);
    867         STAM_PROFILE_STOP(&pState->StatReceiveStore, a);
    868         if (!vnetMergeableRxBuffers(pState))
     845        STAM_PROFILE_START(&pThis->StatReceiveStore, a);
     846        vqueuePut(&pThis->VPCI, pThis->pRxQueue, &elem, uElemSize, cbReserved);
     847        STAM_PROFILE_STOP(&pThis->StatReceiveStore, a);
     848        if (!vnetMergeableRxBuffers(pThis))
    869849            break;
    870850        cbReserved = 0;
    871851    }
    872     if (vnetMergeableRxBuffers(pState))
     852    if (vnetMergeableRxBuffers(pThis))
    873853    {
    874854        Hdr.u16NumBufs = nElem;
    875         int rc = PDMDevHlpPhysWrite(pState->VPCI.CTX_SUFF(pDevIns), addrHdrMrx,
     855        int rc = PDMDevHlpPhysWrite(pThis->VPCI.CTX_SUFF(pDevIns), addrHdrMrx,
    876856                                    &Hdr, sizeof(Hdr));
    877857        if (RT_FAILURE(rc))
    878858        {
    879859            Log(("%s vnetHandleRxPacket: Failed to write merged RX buf header: %Rrc\n",
    880                  INSTANCE(pState), rc));
     860                 INSTANCE(pThis), rc));
    881861            return rc;
    882862        }
    883863    }
    884     vqueueSync(&pState->VPCI, pState->pRxQueue);
     864    vqueueSync(&pThis->VPCI, pThis->pRxQueue);
    885865    if (uOffset < cb)
    886866    {
    887867        Log(("%s vnetHandleRxPacket: Packet did not fit into RX queue (packet size=%u)!\n",
    888              INSTANCE(pState), cb));
     868             INSTANCE(pThis), cb));
    889869        return VERR_TOO_MUCH_DATA;
    890870    }
     
    900880                                                    PCPDMNETWORKGSO pGso)
    901881{
    902     VNETSTATE *pState = RT_FROM_MEMBER(pInterface, VNETSTATE, INetworkDown);
     882    PVNETSTATE pThis = RT_FROM_MEMBER(pInterface, VNETSTATE, INetworkDown);
    903883
    904884    if (pGso)
    905885    {
    906         uint32_t uFeatures = pState->VPCI.uGuestFeatures;
     886        uint32_t uFeatures = pThis->VPCI.uGuestFeatures;
    907887
    908888        switch (pGso->u8Type)
     
    925905        {
    926906            Log2(("%s vnetNetworkDown_ReceiveGso: GSO type (0x%x) not supported\n",
    927                   INSTANCE(pState), pGso->u8Type));
     907                  INSTANCE(pThis), pGso->u8Type));
    928908            return VERR_NOT_SUPPORTED;
    929909        }
     
    931911
    932912    Log2(("%s vnetNetworkDown_ReceiveGso: pvBuf=%p cb=%u pGso=%p\n",
    933           INSTANCE(pState), pvBuf, cb, pGso));
    934     int rc = vnetCanReceive(pState);
     913          INSTANCE(pThis), pvBuf, cb, pGso));
     914    int rc = vnetCanReceive(pThis);
    935915    if (RT_FAILURE(rc))
    936916        return rc;
    937917
    938918    /* Drop packets if VM is not running or cable is disconnected. */
    939     VMSTATE enmVMState = PDMDevHlpVMState(pState->VPCI.CTX_SUFF(pDevIns));
     919    VMSTATE enmVMState = PDMDevHlpVMState(pThis->VPCI.CTX_SUFF(pDevIns));
    940920    if ((   enmVMState != VMSTATE_RUNNING
    941921         && enmVMState != VMSTATE_RUNNING_LS)
     
    943923        return VINF_SUCCESS;
    944924
    945     STAM_PROFILE_START(&pState->StatReceive, a);
    946     vpciSetReadLed(&pState->VPCI, true);
    947     if (vnetAddressFilter(pState, pvBuf, cb))
    948     {
    949         rc = vnetCsRxEnter(pState, VERR_SEM_BUSY);
     925    STAM_PROFILE_START(&pThis->StatReceive, a);
     926    vpciSetReadLed(&pThis->VPCI, true);
     927    if (vnetAddressFilter(pThis, pvBuf, cb))
     928    {
     929        rc = vnetCsRxEnter(pThis, VERR_SEM_BUSY);
    950930        if (RT_SUCCESS(rc))
    951931        {
    952             rc = vnetHandleRxPacket(pState, pvBuf, cb, pGso);
    953             STAM_REL_COUNTER_ADD(&pState->StatReceiveBytes, cb);
    954             vnetCsRxLeave(pState);
    955         }
    956     }
    957     vpciSetReadLed(&pState->VPCI, false);
    958     STAM_PROFILE_STOP(&pState->StatReceive, a);
     932            rc = vnetHandleRxPacket(pThis, pvBuf, cb, pGso);
     933            STAM_REL_COUNTER_ADD(&pThis->StatReceiveBytes, cb);
     934            vnetCsRxLeave(pThis);
     935        }
     936    }
     937    vpciSetReadLed(&pThis->VPCI, false);
     938    STAM_PROFILE_STOP(&pThis->StatReceive, a);
    959939    return rc;
    960940}
     
    978958static DECLCALLBACK(int) vnetGetMac(PPDMINETWORKCONFIG pInterface, PRTMAC pMac)
    979959{
    980     VNETSTATE *pState = RT_FROM_MEMBER(pInterface, VNETSTATE, INetworkConfig);
    981     memcpy(pMac, pState->config.mac.au8, sizeof(RTMAC));
     960    PVNETSTATE pThis = RT_FROM_MEMBER(pInterface, VNETSTATE, INetworkConfig);
     961    memcpy(pMac, pThis->config.mac.au8, sizeof(RTMAC));
    982962    return VINF_SUCCESS;
    983963}
     
    992972static DECLCALLBACK(PDMNETWORKLINKSTATE) vnetGetLinkState(PPDMINETWORKCONFIG pInterface)
    993973{
    994     VNETSTATE *pState = RT_FROM_MEMBER(pInterface, VNETSTATE, INetworkConfig);
     974    PVNETSTATE pThis = RT_FROM_MEMBER(pInterface, VNETSTATE, INetworkConfig);
    995975    if (STATUS & VNET_S_LINK_UP)
    996976        return PDMNETWORKLINKSTATE_UP;
     
    1008988static DECLCALLBACK(int) vnetSetLinkState(PPDMINETWORKCONFIG pInterface, PDMNETWORKLINKSTATE enmState)
    1009989{
    1010     VNETSTATE *pState = RT_FROM_MEMBER(pInterface, VNETSTATE, INetworkConfig);
     990    PVNETSTATE pThis = RT_FROM_MEMBER(pInterface, VNETSTATE, INetworkConfig);
    1011991    bool fOldUp = !!(STATUS & VNET_S_LINK_UP);
    1012992    bool fNewUp = enmState == PDMNETWORKLINKSTATE_UP;
     
    1016996        if (fNewUp)
    1017997        {
    1018             Log(("%s Link is up\n", INSTANCE(pState)));
     998            Log(("%s Link is up\n", INSTANCE(pThis)));
    1019999            STATUS |= VNET_S_LINK_UP;
    1020             vpciRaiseInterrupt(&pState->VPCI, VERR_SEM_BUSY, VPCI_ISR_CONFIG);
     1000            vpciRaiseInterrupt(&pThis->VPCI, VERR_SEM_BUSY, VPCI_ISR_CONFIG);
    10211001        }
    10221002        else
    10231003        {
    1024             Log(("%s Link is down\n", INSTANCE(pState)));
     1004            Log(("%s Link is down\n", INSTANCE(pThis)));
    10251005            STATUS &= ~VNET_S_LINK_UP;
    1026             vpciRaiseInterrupt(&pState->VPCI, VERR_SEM_BUSY, VPCI_ISR_CONFIG);
    1027         }
    1028         if (pState->pDrv)
    1029             pState->pDrv->pfnNotifyLinkChanged(pState->pDrv, enmState);
     1006            vpciRaiseInterrupt(&pThis->VPCI, VERR_SEM_BUSY, VPCI_ISR_CONFIG);
     1007        }
     1008        if (pThis->pDrv)
     1009            pThis->pDrv->pfnNotifyLinkChanged(pThis->pDrv, enmState);
    10301010    }
    10311011    return VINF_SUCCESS;
     
    10341014static DECLCALLBACK(void) vnetQueueReceive(void *pvState, PVQUEUE pQueue)
    10351015{
    1036     VNETSTATE *pState = (VNETSTATE*)pvState;
    1037     Log(("%s Receive buffers has been added, waking up receive thread.\n", INSTANCE(pState)));
    1038     vnetWakeupReceive(pState->VPCI.CTX_SUFF(pDevIns));
     1016    PVNETSTATE pThis = (PVNETSTATE)pvState;
     1017    Log(("%s Receive buffers has been added, waking up receive thread.\n", INSTANCE(pThis)));
     1018    vnetWakeupReceive(pThis->VPCI.CTX_SUFF(pDevIns));
    10391019}
    10401020
     
    11061086}
    11071087
    1108 static void vnetTransmitPendingPackets(PVNETSTATE pState, PVQUEUE pQueue, bool fOnWorkerThread)
     1088static void vnetTransmitPendingPackets(PVNETSTATE pThis, PVQUEUE pQueue, bool fOnWorkerThread)
    11091089{
    11101090    /*
     
    11131093     * thread.
    11141094     */
    1115     if (!ASMAtomicCmpXchgU32(&pState->uIsTransmitting, 1, 0))
     1095    if (!ASMAtomicCmpXchgU32(&pThis->uIsTransmitting, 1, 0))
    11161096        return;
    11171097
    1118     if ((pState->VPCI.uStatus & VPCI_STATUS_DRV_OK) == 0)
     1098    if ((pThis->VPCI.uStatus & VPCI_STATUS_DRV_OK) == 0)
    11191099    {
    11201100        Log(("%s Ignoring transmit requests from non-existent driver (status=0x%x).\n",
    1121              INSTANCE(pState), pState->VPCI.uStatus));
     1101             INSTANCE(pThis), pThis->VPCI.uStatus));
    11221102        return;
    11231103    }
    11241104
    1125     PPDMINETWORKUP pDrv = pState->pDrv;
     1105    PPDMINETWORKUP pDrv = pThis->pDrv;
    11261106    if (pDrv)
    11271107    {
     
    11301110        if (rc == VERR_TRY_AGAIN)
    11311111        {
    1132             ASMAtomicWriteU32(&pState->uIsTransmitting, 0);
     1112            ASMAtomicWriteU32(&pThis->uIsTransmitting, 0);
    11331113            return;
    11341114        }
     
    11361116
    11371117    unsigned int uHdrLen;
    1138     if (vnetMergeableRxBuffers(pState))
     1118    if (vnetMergeableRxBuffers(pThis))
    11391119        uHdrLen = sizeof(VNETHDRMRX);
    11401120    else
    11411121        uHdrLen = sizeof(VNETHDR);
    11421122
    1143     Log3(("%s vnetTransmitPendingPackets: About to transmit %d pending packets\n", INSTANCE(pState),
    1144           vringReadAvailIndex(&pState->VPCI, &pState->pTxQueue->VRing) - pState->pTxQueue->uNextAvailIndex));
    1145 
    1146     vpciSetWriteLed(&pState->VPCI, true);
     1123    Log3(("%s vnetTransmitPendingPackets: About to transmit %d pending packets\n", INSTANCE(pThis),
     1124          vringReadAvailIndex(&pThis->VPCI, &pThis->pTxQueue->VRing) - pThis->pTxQueue->uNextAvailIndex));
     1125
     1126    vpciSetWriteLed(&pThis->VPCI, true);
    11471127
    11481128    VQUEUEELEM elem;
     
    11511131     * buffer first.
    11521132     */
    1153     while (vqueuePeek(&pState->VPCI, pQueue, &elem))
     1133    while (vqueuePeek(&pThis->VPCI, pQueue, &elem))
    11541134    {
    11551135        unsigned int uOffset = 0;
     
    11571137        {
    11581138            Log(("%s vnetQueueTransmit: The first segment is not the header! (%u < 2 || %u != %u).\n",
    1159                  INSTANCE(pState), elem.nOut, elem.aSegsOut[0].cb, uHdrLen));
     1139                 INSTANCE(pThis), elem.nOut, elem.aSegsOut[0].cb, uHdrLen));
    11601140            break; /* For now we simply ignore the header, but it must be there anyway! */
    11611141        }
     
    11631143        {
    11641144            unsigned int uSize = 0;
    1165             STAM_PROFILE_ADV_START(&pState->StatTransmit, a);
     1145            STAM_PROFILE_ADV_START(&pThis->StatTransmit, a);
    11661146            /* Compute total frame size. */
    11671147            for (unsigned int i = 1; i < elem.nOut; i++)
    11681148                uSize += elem.aSegsOut[i].cb;
    11691149            Assert(uSize <= VNET_MAX_FRAME_SIZE);
    1170             if (pState->pDrv)
     1150            if (pThis->pDrv)
    11711151            {
    11721152                VNETHDR Hdr;
    11731153                PDMNETWORKGSO Gso, *pGso;
    11741154
    1175                 PDMDevHlpPhysRead(pState->VPCI.CTX_SUFF(pDevIns), elem.aSegsOut[0].addr,
     1155                PDMDevHlpPhysRead(pThis->VPCI.CTX_SUFF(pDevIns), elem.aSegsOut[0].addr,
    11761156                                  &Hdr, sizeof(Hdr));
    11771157
    1178                 STAM_REL_COUNTER_INC(&pState->StatTransmitPackets);
    1179 
    1180                 STAM_PROFILE_START(&pState->StatTransmitSend, a);
     1158                STAM_REL_COUNTER_INC(&pThis->StatTransmitPackets);
     1159
     1160                STAM_PROFILE_START(&pThis->StatTransmitSend, a);
    11811161
    11821162                pGso = vnetSetupGsoCtx(&Gso, &Hdr);
    11831163                /** @todo Optimize away the extra copying! (lazy bird) */
    11841164                PPDMSCATTERGATHER pSgBuf;
    1185                 int rc = pState->pDrv->pfnAllocBuf(pState->pDrv, uSize, pGso, &pSgBuf);
     1165                int rc = pThis->pDrv->pfnAllocBuf(pThis->pDrv, uSize, pGso, &pSgBuf);
    11861166                if (RT_SUCCESS(rc))
    11871167                {
     
    11901170                    for (unsigned int i = 1; i < elem.nOut; i++)
    11911171                    {
    1192                         PDMDevHlpPhysRead(pState->VPCI.CTX_SUFF(pDevIns), elem.aSegsOut[i].addr,
     1172                        PDMDevHlpPhysRead(pThis->VPCI.CTX_SUFF(pDevIns), elem.aSegsOut[i].addr,
    11931173                                          ((uint8_t*)pSgBuf->aSegs[0].pvSeg) + uOffset,
    11941174                                          elem.aSegsOut[i].cb);
     
    11961176                    }
    11971177                    pSgBuf->cbUsed = uSize;
    1198                     vnetPacketDump(pState, (uint8_t*)pSgBuf->aSegs[0].pvSeg, uSize, "--> Outgoing");
     1178                    vnetPacketDump(pThis, (uint8_t*)pSgBuf->aSegs[0].pvSeg, uSize, "--> Outgoing");
    11991179                    if (pGso)
    12001180                    {
     
    12071187                        {
    12081188                            Log4(("%s vnetTransmitPendingPackets: HdrLen before adjustment %d.\n",
    1209                                   INSTANCE(pState), pGso->cbHdrsTotal));
     1189                                  INSTANCE(pThis), pGso->cbHdrsTotal));
    12101190                            switch (pGso->u8Type)
    12111191                            {
     
    12251205                            ((PPDMNETWORKGSO)pSgBuf->pvUser)->cbHdrsSeg   = pGso->cbHdrsTotal;
    12261206                            Log4(("%s vnetTransmitPendingPackets: adjusted HdrLen to %d.\n",
    1227                                   INSTANCE(pState), pGso->cbHdrsTotal));
     1207                                  INSTANCE(pThis), pGso->cbHdrsTotal));
    12281208                        }
    12291209                        Log2(("%s vnetTransmitPendingPackets: gso type=%x cbHdrsTotal=%u cbHdrsSeg=%u mss=%u"
    1230                               " off1=0x%x off2=0x%x\n", INSTANCE(pState), pGso->u8Type,
     1210                              " off1=0x%x off2=0x%x\n", INSTANCE(pThis), pGso->u8Type,
    12311211                              pGso->cbHdrsTotal, pGso->cbHdrsSeg, pGso->cbMaxSeg, pGso->offHdr1, pGso->offHdr2));
    1232                         STAM_REL_COUNTER_INC(&pState->StatTransmitGSO);
     1212                        STAM_REL_COUNTER_INC(&pThis->StatTransmitGSO);
    12331213                    }
    12341214                    else if (Hdr.u8Flags & VNETHDR_F_NEEDS_CSUM)
    12351215                    {
    1236                         STAM_REL_COUNTER_INC(&pState->StatTransmitCSum);
     1216                        STAM_REL_COUNTER_INC(&pThis->StatTransmitCSum);
    12371217                        /*
    12381218                         * This is not GSO frame but checksum offloading is requested.
     
    12421222                    }
    12431223
    1244                     rc = pState->pDrv->pfnSendBuf(pState->pDrv, pSgBuf, false);
     1224                    rc = pThis->pDrv->pfnSendBuf(pThis->pDrv, pSgBuf, false);
    12451225                }
    12461226                else
    12471227                {
    12481228                    Log4(("virtio-net: failed to allocate SG buffer: size=%u rc=%Rrc\n", uSize, rc));
    1249                     STAM_PROFILE_STOP(&pState->StatTransmitSend, a);
    1250                     STAM_PROFILE_ADV_STOP(&pState->StatTransmit, a);
     1229                    STAM_PROFILE_STOP(&pThis->StatTransmitSend, a);
     1230                    STAM_PROFILE_ADV_STOP(&pThis->StatTransmit, a);
    12511231                    /* Stop trying to fetch TX descriptors until we get more bandwidth. */
    12521232                    break;
    12531233                }
    12541234
    1255                 STAM_PROFILE_STOP(&pState->StatTransmitSend, a);
    1256                 STAM_REL_COUNTER_ADD(&pState->StatTransmitBytes, uOffset);
     1235                STAM_PROFILE_STOP(&pThis->StatTransmitSend, a);
     1236                STAM_REL_COUNTER_ADD(&pThis->StatTransmitBytes, uOffset);
    12571237            }
    12581238        }
    12591239        /* Remove this descriptor chain from the available ring */
    1260         vqueueSkip(&pState->VPCI, pQueue);
    1261         vqueuePut(&pState->VPCI, pQueue, &elem, sizeof(VNETHDR) + uOffset);
    1262         vqueueSync(&pState->VPCI, pQueue);
    1263         STAM_PROFILE_ADV_STOP(&pState->StatTransmit, a);
    1264     }
    1265     vpciSetWriteLed(&pState->VPCI, false);
     1240        vqueueSkip(&pThis->VPCI, pQueue);
     1241        vqueuePut(&pThis->VPCI, pQueue, &elem, sizeof(VNETHDR) + uOffset);
     1242        vqueueSync(&pThis->VPCI, pQueue);
     1243        STAM_PROFILE_ADV_STOP(&pThis->StatTransmit, a);
     1244    }
     1245    vpciSetWriteLed(&pThis->VPCI, false);
    12661246
    12671247    if (pDrv)
    12681248        pDrv->pfnEndXmit(pDrv);
    1269     ASMAtomicWriteU32(&pState->uIsTransmitting, 0);
     1249    ASMAtomicWriteU32(&pThis->uIsTransmitting, 0);
    12701250}
    12711251
     
    12751255static DECLCALLBACK(void) vnetNetworkDown_XmitPending(PPDMINETWORKDOWN pInterface)
    12761256{
    1277     VNETSTATE *pThis = RT_FROM_MEMBER(pInterface, VNETSTATE, INetworkDown);
     1257    PVNETSTATE pThis = RT_FROM_MEMBER(pInterface, VNETSTATE, INetworkDown);
    12781258    vnetTransmitPendingPackets(pThis, pThis->pTxQueue, false /*fOnWorkerThread*/);
    12791259}
     
    12831263static DECLCALLBACK(void) vnetQueueTransmit(void *pvState, PVQUEUE pQueue)
    12841264{
    1285     VNETSTATE *pState = (VNETSTATE*)pvState;
    1286 
    1287     if (TMTimerIsActive(pState->CTX_SUFF(pTxTimer)))
    1288     {
    1289         int rc = TMTimerStop(pState->CTX_SUFF(pTxTimer));
     1265    PVNETSTATE pThis = (PVNETSTATE)pvState;
     1266
     1267    if (TMTimerIsActive(pThis->CTX_SUFF(pTxTimer)))
     1268    {
     1269        int rc = TMTimerStop(pThis->CTX_SUFF(pTxTimer));
    12901270        Log3(("%s vnetQueueTransmit: Got kicked with notification disabled, "
    1291               "re-enable notification and flush TX queue\n", INSTANCE(pState)));
    1292         vnetTransmitPendingPackets(pState, pQueue, false /*fOnWorkerThread*/);
    1293         if (RT_FAILURE(vnetCsEnter(pState, VERR_SEM_BUSY)))
     1271              "re-enable notification and flush TX queue\n", INSTANCE(pThis)));
     1272        vnetTransmitPendingPackets(pThis, pQueue, false /*fOnWorkerThread*/);
     1273        if (RT_FAILURE(vnetCsEnter(pThis, VERR_SEM_BUSY)))
    12941274            LogRel(("vnetQueueTransmit: Failed to enter critical section!/n"));
    12951275        else
    12961276        {
    1297             vringSetNotification(&pState->VPCI, &pState->pTxQueue->VRing, true);
    1298             vnetCsLeave(pState);
     1277            vringSetNotification(&pThis->VPCI, &pThis->pTxQueue->VRing, true);
     1278            vnetCsLeave(pThis);
    12991279        }
    13001280    }
    13011281    else
    13021282    {
    1303         if (RT_FAILURE(vnetCsEnter(pState, VERR_SEM_BUSY)))
     1283        if (RT_FAILURE(vnetCsEnter(pThis, VERR_SEM_BUSY)))
    13041284            LogRel(("vnetQueueTransmit: Failed to enter critical section!/n"));
    13051285        else
    13061286        {
    1307             vringSetNotification(&pState->VPCI, &pState->pTxQueue->VRing, false);
    1308             TMTimerSetMicro(pState->CTX_SUFF(pTxTimer), VNET_TX_DELAY);
    1309             pState->u64NanoTS = RTTimeNanoTS();
    1310             vnetCsLeave(pState);
    1311         }
    1312     }
    1313 }
    1314 
    1315 /**
    1316  * Transmit Delay Timer handler.
    1317  *
    1318  * @remarks We only get here when the timer expires.
    1319  *
    1320  * @param   pDevIns     Pointer to device instance structure.
    1321  * @param   pTimer      Pointer to the timer.
    1322  * @param   pvUser      NULL.
    1323  * @thread  EMT
     1287            vringSetNotification(&pThis->VPCI, &pThis->pTxQueue->VRing, false);
     1288            TMTimerSetMicro(pThis->CTX_SUFF(pTxTimer), VNET_TX_DELAY);
     1289            pThis->u64NanoTS = RTTimeNanoTS();
     1290            vnetCsLeave(pThis);
     1291        }
     1292    }
     1293}
     1294
     1295/**
     1296 * @callback_method_impl{FNTMTIMERDEV, Transmit Delay Timer handler.}
    13241297 */
    13251298static DECLCALLBACK(void) vnetTxTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser)
    13261299{
    1327     VNETSTATE *pState = (VNETSTATE*)pvUser;
    1328 
    1329     uint32_t u32MicroDiff = (uint32_t)((RTTimeNanoTS() - pState->u64NanoTS)/1000);
    1330     if (u32MicroDiff < pState->u32MinDiff)
    1331         pState->u32MinDiff = u32MicroDiff;
    1332     if (u32MicroDiff > pState->u32MaxDiff)
    1333         pState->u32MaxDiff = u32MicroDiff;
    1334     pState->u32AvgDiff = (pState->u32AvgDiff * pState->u32i + u32MicroDiff) / (pState->u32i + 1);
    1335     pState->u32i++;
     1300    PVNETSTATE pThis = (PVNETSTATE)pvUser;
     1301
     1302    uint32_t u32MicroDiff = (uint32_t)((RTTimeNanoTS() - pThis->u64NanoTS)/1000);
     1303    if (u32MicroDiff < pThis->u32MinDiff)
     1304        pThis->u32MinDiff = u32MicroDiff;
     1305    if (u32MicroDiff > pThis->u32MaxDiff)
     1306        pThis->u32MaxDiff = u32MicroDiff;
     1307    pThis->u32AvgDiff = (pThis->u32AvgDiff * pThis->u32i + u32MicroDiff) / (pThis->u32i + 1);
     1308    pThis->u32i++;
    13361309    Log3(("vnetTxTimer: Expired, diff %9d usec, avg %9d usec, min %9d usec, max %9d usec\n",
    1337             u32MicroDiff, pState->u32AvgDiff, pState->u32MinDiff, pState->u32MaxDiff));
    1338 
    1339 //    Log3(("%s vnetTxTimer: Expired\n", INSTANCE(pState)));
    1340     vnetTransmitPendingPackets(pState, pState->pTxQueue, false /*fOnWorkerThread*/);
    1341     if (RT_FAILURE(vnetCsEnter(pState, VERR_SEM_BUSY)))
     1310            u32MicroDiff, pThis->u32AvgDiff, pThis->u32MinDiff, pThis->u32MaxDiff));
     1311
     1312//    Log3(("%s vnetTxTimer: Expired\n", INSTANCE(pThis)));
     1313    vnetTransmitPendingPackets(pThis, pThis->pTxQueue, false /*fOnWorkerThread*/);
     1314    if (RT_FAILURE(vnetCsEnter(pThis, VERR_SEM_BUSY)))
    13421315    {
    13431316        LogRel(("vnetTxTimer: Failed to enter critical section!/n"));
    13441317        return;
    13451318    }
    1346     vringSetNotification(&pState->VPCI, &pState->pTxQueue->VRing, true);
    1347     vnetCsLeave(pState);
     1319    vringSetNotification(&pThis->VPCI, &pThis->pTxQueue->VRing, true);
     1320    vnetCsLeave(pThis);
    13481321}
    13491322
     
    13521325static DECLCALLBACK(void) vnetQueueTransmit(void *pvState, PVQUEUE pQueue)
    13531326{
    1354     VNETSTATE *pState = (VNETSTATE*)pvState;
    1355 
    1356     vnetTransmitPendingPackets(pState, pQueue, false /*fOnWorkerThread*/);
     1327    PVNETSTATE pThis = (PVNETSTATE)pvState;
     1328
     1329    vnetTransmitPendingPackets(pThis, pQueue, false /*fOnWorkerThread*/);
    13571330}
    13581331
    13591332#endif /* !VNET_TX_DELAY */
    13601333
    1361 static uint8_t vnetControlRx(PVNETSTATE pState, PVNETCTLHDR pCtlHdr, PVQUEUEELEM pElem)
     1334static uint8_t vnetControlRx(PVNETSTATE pThis, PVNETCTLHDR pCtlHdr, PVQUEUEELEM pElem)
    13621335{
    13631336    uint8_t u8Ack = VNET_OK;
    1364     uint8_t fOn, fDrvWasPromisc = pState->fPromiscuous | pState->fAllMulti;
    1365     PDMDevHlpPhysRead(pState->VPCI.CTX_SUFF(pDevIns),
     1337    uint8_t fOn, fDrvWasPromisc = pThis->fPromiscuous | pThis->fAllMulti;
     1338    PDMDevHlpPhysRead(pThis->VPCI.CTX_SUFF(pDevIns),
    13661339                      pElem->aSegsOut[1].addr,
    13671340                      &fOn, sizeof(fOn));
    1368     Log(("%s vnetControlRx: uCommand=%u fOn=%u\n", INSTANCE(pState), pCtlHdr->u8Command, fOn));
     1341    Log(("%s vnetControlRx: uCommand=%u fOn=%u\n", INSTANCE(pThis), pCtlHdr->u8Command, fOn));
    13691342    switch (pCtlHdr->u8Command)
    13701343    {
    13711344        case VNET_CTRL_CMD_RX_MODE_PROMISC:
    1372             pState->fPromiscuous = !!fOn;
     1345            pThis->fPromiscuous = !!fOn;
    13731346            break;
    13741347        case VNET_CTRL_CMD_RX_MODE_ALLMULTI:
    1375             pState->fAllMulti = !!fOn;
     1348            pThis->fAllMulti = !!fOn;
    13761349            break;
    13771350        default:
    13781351            u8Ack = VNET_ERROR;
    13791352    }
    1380     if (fDrvWasPromisc != (pState->fPromiscuous | pState->fAllMulti) && pState->pDrv)
    1381         pState->pDrv->pfnSetPromiscuousMode(pState->pDrv,
    1382             (pState->fPromiscuous | pState->fAllMulti));
     1353    if (fDrvWasPromisc != (pThis->fPromiscuous | pThis->fAllMulti) && pThis->pDrv)
     1354        pThis->pDrv->pfnSetPromiscuousMode(pThis->pDrv,
     1355            (pThis->fPromiscuous | pThis->fAllMulti));
    13831356
    13841357    return u8Ack;
    13851358}
    13861359
    1387 static uint8_t vnetControlMac(PVNETSTATE pState, PVNETCTLHDR pCtlHdr, PVQUEUEELEM pElem)
     1360static uint8_t vnetControlMac(PVNETSTATE pThis, PVNETCTLHDR pCtlHdr, PVQUEUEELEM pElem)
    13881361{
    13891362    uint32_t nMacs = 0;
     
    13951368    {
    13961369        Log(("%s vnetControlMac: Segment layout is wrong "
    1397              "(u8Command=%u nOut=%u cb1=%u cb2=%u)\n", INSTANCE(pState),
     1370             "(u8Command=%u nOut=%u cb1=%u cb2=%u)\n", INSTANCE(pThis),
    13981371             pCtlHdr->u8Command, pElem->nOut,
    13991372             pElem->aSegsOut[1].cb, pElem->aSegsOut[2].cb));
     
    14021375
    14031376    /* Load unicast addresses */
    1404     PDMDevHlpPhysRead(pState->VPCI.CTX_SUFF(pDevIns),
     1377    PDMDevHlpPhysRead(pThis->VPCI.CTX_SUFF(pDevIns),
    14051378                      pElem->aSegsOut[1].addr,
    14061379                      &nMacs, sizeof(nMacs));
     
    14091382    {
    14101383        Log(("%s vnetControlMac: The unicast mac segment is too small "
    1411              "(nMacs=%u cb=%u)\n", INSTANCE(pState), pElem->aSegsOut[1].cb));
     1384             "(nMacs=%u cb=%u)\n", INSTANCE(pThis), pElem->aSegsOut[1].cb));
    14121385        return VNET_ERROR;
    14131386    }
     
    14161389    {
    14171390        Log(("%s vnetControlMac: MAC table is too big, have to use promiscuous"
    1418              " mode (nMacs=%u)\n", INSTANCE(pState), nMacs));
    1419         pState->fPromiscuous = true;
     1391             " mode (nMacs=%u)\n", INSTANCE(pThis), nMacs));
     1392        pThis->fPromiscuous = true;
    14201393    }
    14211394    else
    14221395    {
    14231396        if (nMacs)
    1424             PDMDevHlpPhysRead(pState->VPCI.CTX_SUFF(pDevIns),
     1397            PDMDevHlpPhysRead(pThis->VPCI.CTX_SUFF(pDevIns),
    14251398                              pElem->aSegsOut[1].addr + sizeof(nMacs),
    1426                               pState->aMacFilter, nMacs * sizeof(RTMAC));
    1427         pState->nMacFilterEntries = nMacs;
     1399                              pThis->aMacFilter, nMacs * sizeof(RTMAC));
     1400        pThis->nMacFilterEntries = nMacs;
    14281401#ifdef DEBUG
    1429         Log(("%s vnetControlMac: unicast macs:\n", INSTANCE(pState)));
     1402        Log(("%s vnetControlMac: unicast macs:\n", INSTANCE(pThis)));
    14301403        for(unsigned i = 0; i < nMacs; i++)
    1431             Log(("         %RTmac\n", &pState->aMacFilter[i]));
     1404            Log(("         %RTmac\n", &pThis->aMacFilter[i]));
    14321405#endif /* DEBUG */
    14331406    }
    14341407
    14351408    /* Load multicast addresses */
    1436     PDMDevHlpPhysRead(pState->VPCI.CTX_SUFF(pDevIns),
     1409    PDMDevHlpPhysRead(pThis->VPCI.CTX_SUFF(pDevIns),
    14371410                      pElem->aSegsOut[2].addr,
    14381411                      &nMacs, sizeof(nMacs));
     
    14411414    {
    14421415        Log(("%s vnetControlMac: The multicast mac segment is too small "
    1443              "(nMacs=%u cb=%u)\n", INSTANCE(pState), pElem->aSegsOut[2].cb));
     1416             "(nMacs=%u cb=%u)\n", INSTANCE(pThis), pElem->aSegsOut[2].cb));
    14441417        return VNET_ERROR;
    14451418    }
    14461419
    1447     if (nMacs > VNET_MAC_FILTER_LEN - pState->nMacFilterEntries)
     1420    if (nMacs > VNET_MAC_FILTER_LEN - pThis->nMacFilterEntries)
    14481421    {
    14491422        Log(("%s vnetControlMac: MAC table is too big, have to use allmulti"
    1450              " mode (nMacs=%u)\n", INSTANCE(pState), nMacs));
    1451         pState->fAllMulti = true;
     1423             " mode (nMacs=%u)\n", INSTANCE(pThis), nMacs));
     1424        pThis->fAllMulti = true;
    14521425    }
    14531426    else
    14541427    {
    14551428        if (nMacs)
    1456             PDMDevHlpPhysRead(pState->VPCI.CTX_SUFF(pDevIns),
     1429            PDMDevHlpPhysRead(pThis->VPCI.CTX_SUFF(pDevIns),
    14571430                              pElem->aSegsOut[2].addr + sizeof(nMacs),
    1458                               &pState->aMacFilter[pState->nMacFilterEntries],
     1431                              &pThis->aMacFilter[pThis->nMacFilterEntries],
    14591432                              nMacs * sizeof(RTMAC));
    14601433#ifdef DEBUG
    1461         Log(("%s vnetControlMac: multicast macs:\n", INSTANCE(pState)));
     1434        Log(("%s vnetControlMac: multicast macs:\n", INSTANCE(pThis)));
    14621435        for(unsigned i = 0; i < nMacs; i++)
    14631436            Log(("         %RTmac\n",
    1464                  &pState->aMacFilter[i+pState->nMacFilterEntries]));
     1437                 &pThis->aMacFilter[i+pThis->nMacFilterEntries]));
    14651438#endif /* DEBUG */
    1466         pState->nMacFilterEntries += nMacs;
     1439        pThis->nMacFilterEntries += nMacs;
    14671440    }
    14681441
     
    14701443}
    14711444
    1472 static uint8_t vnetControlVlan(PVNETSTATE pState, PVNETCTLHDR pCtlHdr, PVQUEUEELEM pElem)
     1445static uint8_t vnetControlVlan(PVNETSTATE pThis, PVNETCTLHDR pCtlHdr, PVQUEUEELEM pElem)
    14731446{
    14741447    uint8_t  u8Ack = VNET_OK;
     
    14781451    {
    14791452        Log(("%s vnetControlVlan: Segment layout is wrong "
    1480              "(u8Command=%u nOut=%u cb=%u)\n", INSTANCE(pState),
     1453             "(u8Command=%u nOut=%u cb=%u)\n", INSTANCE(pThis),
    14811454             pCtlHdr->u8Command, pElem->nOut, pElem->aSegsOut[1].cb));
    14821455        return VNET_ERROR;
    14831456    }
    14841457
    1485     PDMDevHlpPhysRead(pState->VPCI.CTX_SUFF(pDevIns),
     1458    PDMDevHlpPhysRead(pThis->VPCI.CTX_SUFF(pDevIns),
    14861459                      pElem->aSegsOut[1].addr,
    14871460                      &u16Vid, sizeof(u16Vid));
     
    14901463    {
    14911464        Log(("%s vnetControlVlan: VLAN ID is out of range "
    1492              "(VID=%u)\n", INSTANCE(pState), u16Vid));
     1465             "(VID=%u)\n", INSTANCE(pThis), u16Vid));
    14931466        return VNET_ERROR;
    14941467    }
    14951468
    1496     Log(("%s vnetControlVlan: uCommand=%u VID=%u\n", INSTANCE(pState),
     1469    Log(("%s vnetControlVlan: uCommand=%u VID=%u\n", INSTANCE(pThis),
    14971470         pCtlHdr->u8Command, u16Vid));
    14981471
     
    15001473    {
    15011474        case VNET_CTRL_CMD_VLAN_ADD:
    1502             ASMBitSet(pState->aVlanFilter, u16Vid);
     1475            ASMBitSet(pThis->aVlanFilter, u16Vid);
    15031476            break;
    15041477        case VNET_CTRL_CMD_VLAN_DEL:
    1505             ASMBitClear(pState->aVlanFilter, u16Vid);
     1478            ASMBitClear(pThis->aVlanFilter, u16Vid);
    15061479            break;
    15071480        default:
     
    15151488static DECLCALLBACK(void) vnetQueueControl(void *pvState, PVQUEUE pQueue)
    15161489{
    1517     VNETSTATE *pState = (VNETSTATE*)pvState;
     1490    PVNETSTATE pThis = (PVNETSTATE)pvState;
    15181491    uint8_t u8Ack;
    15191492    VQUEUEELEM elem;
    1520     while (vqueueGet(&pState->VPCI, pQueue, &elem))
     1493    while (vqueueGet(&pThis->VPCI, pQueue, &elem))
    15211494    {
    15221495        unsigned int uOffset = 0;
     
    15241497        {
    15251498            Log(("%s vnetQueueControl: The first 'out' segment is not the "
    1526                  "header! (%u < 1 || %u < %u).\n", INSTANCE(pState), elem.nOut,
     1499                 "header! (%u < 1 || %u < %u).\n", INSTANCE(pThis), elem.nOut,
    15271500                 elem.aSegsOut[0].cb,sizeof(VNETCTLHDR)));
    15281501            break; /* Skip the element and hope the next one is good. */
     
    15331506            Log(("%s vnetQueueControl: The last 'in' segment is too small "
    15341507                 "to hold the acknowledge! (%u < 1 || %u < %u).\n",
    1535                  INSTANCE(pState), elem.nIn, elem.aSegsIn[elem.nIn - 1].cb,
     1508                 INSTANCE(pThis), elem.nIn, elem.aSegsIn[elem.nIn - 1].cb,
    15361509                 sizeof(VNETCTLACK)));
    15371510            break; /* Skip the element and hope the next one is good. */
     
    15401513        {
    15411514            VNETCTLHDR CtlHdr;
    1542             PDMDevHlpPhysRead(pState->VPCI.CTX_SUFF(pDevIns),
     1515            PDMDevHlpPhysRead(pThis->VPCI.CTX_SUFF(pDevIns),
    15431516                              elem.aSegsOut[0].addr,
    15441517                              &CtlHdr, sizeof(CtlHdr));
     
    15461519            {
    15471520                case VNET_CTRL_CLS_RX_MODE:
    1548                     u8Ack = vnetControlRx(pState, &CtlHdr, &elem);
     1521                    u8Ack = vnetControlRx(pThis, &CtlHdr, &elem);
    15491522                    break;
    15501523                case VNET_CTRL_CLS_MAC:
    1551                     u8Ack = vnetControlMac(pState, &CtlHdr, &elem);
     1524                    u8Ack = vnetControlMac(pThis, &CtlHdr, &elem);
    15521525                    break;
    15531526                case VNET_CTRL_CLS_VLAN:
    1554                     u8Ack = vnetControlVlan(pState, &CtlHdr, &elem);
     1527                    u8Ack = vnetControlVlan(pThis, &CtlHdr, &elem);
    15551528                    break;
    15561529                default:
    15571530                    u8Ack = VNET_ERROR;
    15581531            }
    1559             Log(("%s Processed control message %u, ack=%u.\n", INSTANCE(pState),
     1532            Log(("%s Processed control message %u, ack=%u.\n", INSTANCE(pThis),
    15601533                 CtlHdr.u8Class, u8Ack));
    1561             PDMDevHlpPhysWrite(pState->VPCI.CTX_SUFF(pDevIns),
     1534            PDMDevHlpPhysWrite(pThis->VPCI.CTX_SUFF(pDevIns),
    15621535                               elem.aSegsIn[elem.nIn - 1].addr,
    15631536                               &u8Ack, sizeof(u8Ack));
    15641537        }
    1565         vqueuePut(&pState->VPCI, pQueue, &elem, sizeof(u8Ack));
    1566         vqueueSync(&pState->VPCI, pQueue);
    1567     }
    1568 }
     1538        vqueuePut(&pThis->VPCI, pQueue, &elem, sizeof(u8Ack));
     1539        vqueueSync(&pThis->VPCI, pQueue);
     1540    }
     1541}
     1542
     1543
     1544/* -=-=-=-=- Saved state -=-=-=-=- */
    15691545
    15701546/**
    15711547 * Saves the configuration.
    15721548 *
    1573  * @param   pState      The VNET state.
     1549 * @param   pThis      The VNET state.
    15741550 * @param   pSSM        The handle to the saved state.
    15751551 */
    1576 static void vnetSaveConfig(VNETSTATE *pState, PSSMHANDLE pSSM)
    1577 {
    1578     SSMR3PutMem(pSSM, &pState->macConfigured, sizeof(pState->macConfigured));
    1579 }
    1580 
    1581 /**
    1582  * Live save - save basic configuration.
    1583  *
    1584  * @returns VBox status code.
    1585  * @param   pDevIns     The device instance.
    1586  * @param   pSSM        The handle to the saved state.
    1587  * @param   uPass
     1552static void vnetSaveConfig(PVNETSTATE pThis, PSSMHANDLE pSSM)
     1553{
     1554    SSMR3PutMem(pSSM, &pThis->macConfigured, sizeof(pThis->macConfigured));
     1555}
     1556
     1557
     1558/**
     1559 * @callback_method_impl{FNSSMDEVLIVEEXEC}
    15881560 */
    15891561static DECLCALLBACK(int) vnetLiveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uPass)
    15901562{
    1591     VNETSTATE *pState = PDMINS_2_DATA(pDevIns, VNETSTATE*);
    1592     vnetSaveConfig(pState, pSSM);
     1563    PVNETSTATE pThis = PDMINS_2_DATA(pDevIns, PVNETSTATE);
     1564    vnetSaveConfig(pThis, pSSM);
    15931565    return VINF_SSM_DONT_CALL_AGAIN;
    15941566}
    15951567
    1596 /**
    1597  * Prepares for state saving.
    1598  *
    1599  * @returns VBox status code.
    1600  * @param   pDevIns     The device instance.
    1601  * @param   pSSM        The handle to the saved state.
     1568
     1569/**
     1570 * @callback_method_impl{FNSSMDEVSAVEPREP}
    16021571 */
    16031572static DECLCALLBACK(int) vnetSavePrep(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
    16041573{
    1605     VNETSTATE* pState = PDMINS_2_DATA(pDevIns, VNETSTATE*);
    1606 
    1607     int rc = vnetCsRxEnter(pState, VERR_SEM_BUSY);
     1574    PVNETSTATE pThis = PDMINS_2_DATA(pDevIns, PVNETSTATE);
     1575
     1576    int rc = vnetCsRxEnter(pThis, VERR_SEM_BUSY);
    16081577    if (RT_UNLIKELY(rc != VINF_SUCCESS))
    16091578        return rc;
    1610     vnetCsRxLeave(pState);
     1579    vnetCsRxLeave(pThis);
    16111580    return VINF_SUCCESS;
    16121581}
    16131582
    1614 /**
    1615  * Saves the state of device.
    1616  *
    1617  * @returns VBox status code.
    1618  * @param   pDevIns     The device instance.
    1619  * @param   pSSM        The handle to the saved state.
     1583
     1584/**
     1585 * @callback_method_impl{FNSSMDEVSAVEEXEC}
    16201586 */
    16211587static DECLCALLBACK(int) vnetSaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
    16221588{
    1623     VNETSTATE* pState = PDMINS_2_DATA(pDevIns, VNETSTATE*);
     1589    PVNETSTATE pThis = PDMINS_2_DATA(pDevIns, PVNETSTATE);
    16241590
    16251591    /* Save config first */
    1626     vnetSaveConfig(pState, pSSM);
     1592    vnetSaveConfig(pThis, pSSM);
    16271593
    16281594    /* Save the common part */
    1629     int rc = vpciSaveExec(&pState->VPCI, pSSM);
     1595    int rc = vpciSaveExec(&pThis->VPCI, pSSM);
    16301596    AssertRCReturn(rc, rc);
    16311597    /* Save device-specific part */
    1632     rc = SSMR3PutMem( pSSM, pState->config.mac.au8, sizeof(pState->config.mac));
     1598    rc = SSMR3PutMem( pSSM, pThis->config.mac.au8, sizeof(pThis->config.mac));
    16331599    AssertRCReturn(rc, rc);
    1634     rc = SSMR3PutBool(pSSM, pState->fPromiscuous);
     1600    rc = SSMR3PutBool(pSSM, pThis->fPromiscuous);
    16351601    AssertRCReturn(rc, rc);
    1636     rc = SSMR3PutBool(pSSM, pState->fAllMulti);
     1602    rc = SSMR3PutBool(pSSM, pThis->fAllMulti);
    16371603    AssertRCReturn(rc, rc);
    1638     rc = SSMR3PutU32( pSSM, pState->nMacFilterEntries);
     1604    rc = SSMR3PutU32( pSSM, pThis->nMacFilterEntries);
    16391605    AssertRCReturn(rc, rc);
    1640     rc = SSMR3PutMem( pSSM, pState->aMacFilter,
    1641                       pState->nMacFilterEntries * sizeof(RTMAC));
     1606    rc = SSMR3PutMem( pSSM, pThis->aMacFilter,
     1607                      pThis->nMacFilterEntries * sizeof(RTMAC));
    16421608    AssertRCReturn(rc, rc);
    1643     rc = SSMR3PutMem( pSSM, pState->aVlanFilter, sizeof(pState->aVlanFilter));
     1609    rc = SSMR3PutMem( pSSM, pThis->aVlanFilter, sizeof(pThis->aVlanFilter));
    16441610    AssertRCReturn(rc, rc);
    1645     Log(("%s State has been saved\n", INSTANCE(pState)));
     1611    Log(("%s State has been saved\n", INSTANCE(pThis)));
    16461612    return VINF_SUCCESS;
    16471613}
     
    16491615
    16501616/**
    1651  * Serializes the receive thread, it may be working inside the critsect.
    1652  *
    1653  * @returns VBox status code.
    1654  * @param   pDevIns     The device instance.
    1655  * @param   pSSM        The handle to the saved state.
     1617 * @callback_method_impl{FNSSMDEVLOADPREP, Serializes the receive thread, it may
     1618 *                      be working inside the critsect. }
    16561619 */
    16571620static DECLCALLBACK(int) vnetLoadPrep(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
    16581621{
    1659     VNETSTATE* pState = PDMINS_2_DATA(pDevIns, VNETSTATE*);
    1660 
    1661     int rc = vnetCsRxEnter(pState, VERR_SEM_BUSY);
     1622    PVNETSTATE pThis = PDMINS_2_DATA(pDevIns, PVNETSTATE);
     1623
     1624    int rc = vnetCsRxEnter(pThis, VERR_SEM_BUSY);
    16621625    if (RT_UNLIKELY(rc != VINF_SUCCESS))
    16631626        return rc;
    1664     vnetCsRxLeave(pState);
     1627    vnetCsRxLeave(pThis);
    16651628    return VINF_SUCCESS;
    16661629}
     1630
    16671631
    16681632/**
     
    16751639 * renegotiate any DHCP lease.
    16761640 *
    1677  * @param  pThis        The PCNet instance data.
    1678  */
    1679 static void vnetTempLinkDown(PVNETSTATE pState)
     1641 * @param  pThis        The Virtual I/O network device state.
     1642 */
     1643static void vnetTempLinkDown(PVNETSTATE pThis)
    16801644{
    16811645    if (STATUS & VNET_S_LINK_UP)
    16821646    {
    16831647        STATUS &= ~VNET_S_LINK_UP;
    1684         vpciRaiseInterrupt(&pState->VPCI, VERR_SEM_BUSY, VPCI_ISR_CONFIG);
     1648        vpciRaiseInterrupt(&pThis->VPCI, VERR_SEM_BUSY, VPCI_ISR_CONFIG);
    16851649        /* Restore the link back in 5 seconds. */
    1686         int rc = TMTimerSetMillies(pState->pLinkUpTimer, pState->cMsLinkUpDelay);
     1650        int rc = TMTimerSetMillies(pThis->pLinkUpTimer, pThis->cMsLinkUpDelay);
    16871651        AssertRC(rc);
    16881652    }
     
    16911655
    16921656/**
    1693  * Restore previously saved state of device.
    1694  *
    1695  * @returns VBox status code.
    1696  * @param   pDevIns     The device instance.
    1697  * @param   pSSM        The handle to the saved state.
    1698  * @param   uVersion    The data unit version number.
    1699  * @param   uPass       The data pass.
     1657 * @callback_method_impl{FNSSMDEVLOADEXEC}
    17001658 */
    17011659static DECLCALLBACK(int) vnetLoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
    17021660{
    1703     VNETSTATE *pState = PDMINS_2_DATA(pDevIns, VNETSTATE*);
     1661    PVNETSTATE pThis = PDMINS_2_DATA(pDevIns, PVNETSTATE);
    17041662    int       rc;
    17051663
     
    17081666    rc = SSMR3GetMem(pSSM, &macConfigured, sizeof(macConfigured));
    17091667    AssertRCReturn(rc, rc);
    1710     if (memcmp(&macConfigured, &pState->macConfigured, sizeof(macConfigured))
     1668    if (memcmp(&macConfigured, &pThis->macConfigured, sizeof(macConfigured))
    17111669        && (uPass == 0 || !PDMDevHlpVMTeleportedAndNotFullyResumedYet(pDevIns)))
    1712         LogRel(("%s: The mac address differs: config=%RTmac saved=%RTmac\n", INSTANCE(pState), &pState->macConfigured, &macConfigured));
    1713 
    1714     rc = vpciLoadExec(&pState->VPCI, pSSM, uVersion, uPass, VNET_N_QUEUES);
     1670        LogRel(("%s: The mac address differs: config=%RTmac saved=%RTmac\n", INSTANCE(pThis), &pThis->macConfigured, &macConfigured));
     1671
     1672    rc = vpciLoadExec(&pThis->VPCI, pSSM, uVersion, uPass, VNET_N_QUEUES);
    17151673    AssertRCReturn(rc, rc);
    17161674
    17171675    if (uPass == SSM_PASS_FINAL)
    17181676    {
    1719         rc = SSMR3GetMem( pSSM, pState->config.mac.au8,
    1720                           sizeof(pState->config.mac));
     1677        rc = SSMR3GetMem( pSSM, pThis->config.mac.au8,
     1678                          sizeof(pThis->config.mac));
    17211679        AssertRCReturn(rc, rc);
    17221680
    17231681        if (uVersion > VIRTIO_SAVEDSTATE_VERSION_3_1_BETA1)
    17241682        {
    1725             rc = SSMR3GetBool(pSSM, &pState->fPromiscuous);
     1683            rc = SSMR3GetBool(pSSM, &pThis->fPromiscuous);
    17261684            AssertRCReturn(rc, rc);
    1727             rc = SSMR3GetBool(pSSM, &pState->fAllMulti);
     1685            rc = SSMR3GetBool(pSSM, &pThis->fAllMulti);
    17281686            AssertRCReturn(rc, rc);
    1729             rc = SSMR3GetU32(pSSM, &pState->nMacFilterEntries);
     1687            rc = SSMR3GetU32(pSSM, &pThis->nMacFilterEntries);
    17301688            AssertRCReturn(rc, rc);
    1731             rc = SSMR3GetMem(pSSM, pState->aMacFilter,
    1732                              pState->nMacFilterEntries * sizeof(RTMAC));
     1689            rc = SSMR3GetMem(pSSM, pThis->aMacFilter,
     1690                             pThis->nMacFilterEntries * sizeof(RTMAC));
    17331691            AssertRCReturn(rc, rc);
    17341692            /* Clear the rest. */
    1735             if (pState->nMacFilterEntries < VNET_MAC_FILTER_LEN)
    1736                 memset(&pState->aMacFilter[pState->nMacFilterEntries],
     1693            if (pThis->nMacFilterEntries < VNET_MAC_FILTER_LEN)
     1694                memset(&pThis->aMacFilter[pThis->nMacFilterEntries],
    17371695                       0,
    1738                        (VNET_MAC_FILTER_LEN - pState->nMacFilterEntries)
     1696                       (VNET_MAC_FILTER_LEN - pThis->nMacFilterEntries)
    17391697                       * sizeof(RTMAC));
    1740             rc = SSMR3GetMem(pSSM, pState->aVlanFilter,
    1741                              sizeof(pState->aVlanFilter));
     1698            rc = SSMR3GetMem(pSSM, pThis->aVlanFilter,
     1699                             sizeof(pThis->aVlanFilter));
    17421700            AssertRCReturn(rc, rc);
    17431701        }
    17441702        else
    17451703        {
    1746             pState->fPromiscuous = true;
    1747             pState->fAllMulti = false;
    1748             pState->nMacFilterEntries = 0;
    1749             memset(pState->aMacFilter, 0, VNET_MAC_FILTER_LEN * sizeof(RTMAC));
    1750             memset(pState->aVlanFilter, 0, sizeof(pState->aVlanFilter));
    1751             if (pState->pDrv)
    1752                 pState->pDrv->pfnSetPromiscuousMode(pState->pDrv, true);
     1704            pThis->fPromiscuous = true;
     1705            pThis->fAllMulti = false;
     1706            pThis->nMacFilterEntries = 0;
     1707            memset(pThis->aMacFilter, 0, VNET_MAC_FILTER_LEN * sizeof(RTMAC));
     1708            memset(pThis->aVlanFilter, 0, sizeof(pThis->aVlanFilter));
     1709            if (pThis->pDrv)
     1710                pThis->pDrv->pfnSetPromiscuousMode(pThis->pDrv, true);
    17531711        }
    17541712    }
     
    17571715}
    17581716
    1759 /**
    1760  * Link status adjustments after loading.
    1761  *
    1762  * @returns VBox status code.
    1763  * @param   pDevIns     The device instance.
    1764  * @param   pSSM        The handle to the saved state.
     1717
     1718/**
     1719 * @callback_method_impl{FNSSMDEVLOADDONE, Link status adjustments after
     1720 *                      loading.}
    17651721 */
    17661722static DECLCALLBACK(int) vnetLoadDone(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
    17671723{
    1768     VNETSTATE *pState = PDMINS_2_DATA(pDevIns, VNETSTATE*);
    1769 
    1770     if (pState->pDrv)
    1771         pState->pDrv->pfnSetPromiscuousMode(pState->pDrv,
    1772             (pState->fPromiscuous | pState->fAllMulti));
     1724    PVNETSTATE pThis = PDMINS_2_DATA(pDevIns, PVNETSTATE);
     1725
     1726    if (pThis->pDrv)
     1727        pThis->pDrv->pfnSetPromiscuousMode(pThis->pDrv,
     1728            (pThis->fPromiscuous | pThis->fAllMulti));
    17731729    /*
    17741730     * Indicate link down to the guest OS that all network connections have
     
    17761732     */
    17771733    if (!PDMDevHlpVMTeleportedAndNotFullyResumedYet(pDevIns))
    1778         vnetTempLinkDown(pState);
     1734        vnetTempLinkDown(pThis);
    17791735
    17801736    return VINF_SUCCESS;
    17811737}
    17821738
    1783 /**
    1784  * Map PCI I/O region.
    1785  *
    1786  * @return  VBox status code.
    1787  * @param   pPciDev         Pointer to PCI device. Use pPciDev->pDevIns to get the device instance.
    1788  * @param   iRegion         The region number.
    1789  * @param   GCPhysAddress   Physical address of the region. If iType is PCI_ADDRESS_SPACE_IO, this is an
    1790  *                          I/O port, else it's a physical address.
    1791  *                          This address is *NOT* relative to pci_mem_base like earlier!
    1792  * @param   cb              Region size.
    1793  * @param   enmType         One of the PCI_ADDRESS_SPACE_* values.
    1794  * @thread  EMT
     1739
     1740/* -=-=-=-=- PCI Device -=-=-=-=- */
     1741
     1742/**
     1743 * @callback_method_impl{FNPCIIOREGIONMAP}
    17951744 */
    17961745static DECLCALLBACK(int) vnetMap(PPCIDEVICE pPciDev, int iRegion,
    17971746                                 RTGCPHYS GCPhysAddress, uint32_t cb, PCIADDRESSSPACE enmType)
    17981747{
     1748    PVNETSTATE pThis = PDMINS_2_DATA(pPciDev->pDevIns, PVNETSTATE);
    17991749    int       rc;
    1800     VNETSTATE *pState = PDMINS_2_DATA(pPciDev->pDevIns, VNETSTATE*);
    18011750
    18021751    if (enmType != PCI_ADDRESS_SPACE_IO)
     
    18071756    }
    18081757
    1809     pState->VPCI.addrIOPort = (RTIOPORT)GCPhysAddress;
    1810     rc = PDMDevHlpIOPortRegister(pPciDev->pDevIns, pState->VPCI.addrIOPort,
     1758    pThis->VPCI.addrIOPort = (RTIOPORT)GCPhysAddress;
     1759    rc = PDMDevHlpIOPortRegister(pPciDev->pDevIns, pThis->VPCI.addrIOPort,
    18111760                                 cb, 0, vnetIOPortOut, vnetIOPortIn,
    18121761                                 NULL, NULL, "VirtioNet");
    18131762#ifdef VNET_GC_SUPPORT
    18141763    AssertRCReturn(rc, rc);
    1815     rc = PDMDevHlpIOPortRegisterR0(pPciDev->pDevIns, pState->VPCI.addrIOPort,
     1764    rc = PDMDevHlpIOPortRegisterR0(pPciDev->pDevIns, pThis->VPCI.addrIOPort,
    18161765                                   cb, 0, "vnetIOPortOut", "vnetIOPortIn",
    18171766                                   NULL, NULL, "VirtioNet");
    18181767    AssertRCReturn(rc, rc);
    1819     rc = PDMDevHlpIOPortRegisterRC(pPciDev->pDevIns, pState->VPCI.addrIOPort,
     1768    rc = PDMDevHlpIOPortRegisterRC(pPciDev->pDevIns, pThis->VPCI.addrIOPort,
    18201769                                   cb, 0, "vnetIOPortOut", "vnetIOPortIn",
    18211770                                   NULL, NULL, "VirtioNet");
     
    18291778
    18301779/**
    1831  * Detach notification.
    1832  *
    1833  * One port on the network card has been disconnected from the network.
    1834  *
    1835  * @param   pDevIns     The device instance.
    1836  * @param   iLUN        The logical unit which is being detached.
    1837  * @param   fFlags      Flags, combination of the PDMDEVATT_FLAGS_* \#defines.
     1780 * @interface_method_impl{PDMDEVREG,pfnDetach}
    18381781 */
    18391782static DECLCALLBACK(void) vnetDetach(PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags)
    18401783{
    1841     VNETSTATE *pState = PDMINS_2_DATA(pDevIns, VNETSTATE*);
    1842     Log(("%s vnetDetach:\n", INSTANCE(pState)));
     1784    PVNETSTATE pThis = PDMINS_2_DATA(pDevIns, PVNETSTATE);
     1785    Log(("%s vnetDetach:\n", INSTANCE(pThis)));
    18431786
    18441787    AssertLogRelReturnVoid(iLUN == 0);
    18451788
    1846     int rc = vnetCsEnter(pState, VERR_SEM_BUSY);
     1789    int rc = vnetCsEnter(pThis, VERR_SEM_BUSY);
    18471790    if (RT_FAILURE(rc))
    18481791    {
     
    18541797     * Zero some important members.
    18551798     */
    1856     pState->pDrvBase = NULL;
    1857     pState->pDrv = NULL;
    1858 
    1859     vnetCsLeave(pState);
    1860 }
    1861 
    1862 /**
    1863  * Attach the Network attachment.
    1864  *
    1865  * One port on the network card has been connected to a network.
    1866  *
    1867  * @returns VBox status code.
    1868  * @param   pDevIns     The device instance.
    1869  * @param   iLUN        The logical unit which is being attached.
    1870  * @param   fFlags      Flags, combination of the PDMDEVATT_FLAGS_* \#defines.
    1871  *
    1872  * @remarks This code path is not used during construction.
     1799    pThis->pDrvBase = NULL;
     1800    pThis->pDrv = NULL;
     1801
     1802    vnetCsLeave(pThis);
     1803}
     1804
     1805
     1806/**
     1807 * @interface_method_impl{PDMDEVREG,pfnAttach}
    18731808 */
    18741809static DECLCALLBACK(int) vnetAttach(PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags)
    18751810{
    1876     VNETSTATE *pState = PDMINS_2_DATA(pDevIns, VNETSTATE*);
    1877     LogFlow(("%s vnetAttach:\n",  INSTANCE(pState)));
     1811    PVNETSTATE pThis = PDMINS_2_DATA(pDevIns, PVNETSTATE);
     1812    LogFlow(("%s vnetAttach:\n",  INSTANCE(pThis)));
    18781813
    18791814    AssertLogRelReturn(iLUN == 0, VERR_PDM_NO_SUCH_LUN);
    18801815
    1881     int rc = vnetCsEnter(pState, VERR_SEM_BUSY);
     1816    int rc = vnetCsEnter(pThis, VERR_SEM_BUSY);
    18821817    if (RT_FAILURE(rc))
    18831818    {
     
    18891824     * Attach the driver.
    18901825     */
    1891     rc = PDMDevHlpDriverAttach(pDevIns, 0, &pState->VPCI.IBase, &pState->pDrvBase, "Network Port");
     1826    rc = PDMDevHlpDriverAttach(pDevIns, 0, &pThis->VPCI.IBase, &pThis->pDrvBase, "Network Port");
    18921827    if (RT_SUCCESS(rc))
    18931828    {
     
    19021837#endif
    19031838        }
    1904         pState->pDrv = PDMIBASE_QUERY_INTERFACE(pState->pDrvBase, PDMINETWORKUP);
    1905         AssertMsgStmt(pState->pDrv, ("Failed to obtain the PDMINETWORKUP interface!\n"),
     1839        pThis->pDrv = PDMIBASE_QUERY_INTERFACE(pThis->pDrvBase, PDMINETWORKUP);
     1840        AssertMsgStmt(pThis->pDrv, ("Failed to obtain the PDMINETWORKUP interface!\n"),
    19061841                      rc = VERR_PDM_MISSING_INTERFACE_BELOW);
    19071842    }
     
    19111846        /* This should never happen because this function is not called
    19121847         * if there is no driver to attach! */
    1913         Log(("%s No attached driver!\n", INSTANCE(pState)));
     1848        Log(("%s No attached driver!\n", INSTANCE(pThis)));
    19141849    }
    19151850
     
    19201855     */
    19211856    if (RT_SUCCESS(rc))
    1922         vnetTempLinkDown(pState);
    1923 
    1924     vnetCsLeave(pState);
     1857        vnetTempLinkDown(pThis);
     1858
     1859    vnetCsLeave(pThis);
    19251860    return rc;
    19261861
    19271862}
    19281863
    1929 /**
    1930  * @copydoc FNPDMDEVSUSPEND
     1864
     1865/**
     1866 * @interface_method_impl{PDMDEVREG,pfnSuspend}
    19311867 */
    19321868static DECLCALLBACK(void) vnetSuspend(PPDMDEVINS pDevIns)
     
    19361872}
    19371873
    1938 /**
    1939  * @copydoc FNPDMDEVPOWEROFF
     1874
     1875/**
     1876 * @interface_method_impl{PDMDEVREG,pfnPowerOff}
    19401877 */
    19411878static DECLCALLBACK(void) vnetPowerOff(PPDMDEVINS pDevIns)
     
    19451882}
    19461883
    1947 /**
    1948  * Device relocation callback.
    1949  *
    1950  * When this callback is called the device instance data, and if the
    1951  * device have a GC component, is being relocated, or/and the selectors
    1952  * have been changed. The device must use the chance to perform the
    1953  * necessary pointer relocations and data updates.
    1954  *
    1955  * Before the GC code is executed the first time, this function will be
    1956  * called with a 0 delta so GC pointer calculations can be one in one place.
    1957  *
    1958  * @param   pDevIns     Pointer to the device instance.
    1959  * @param   offDelta    The relocation delta relative to the old location.
    1960  *
    1961  * @remark  A relocation CANNOT fail.
     1884
     1885/**
     1886 * @interface_method_impl{PDMDEVREG,pfnRelocate}
    19621887 */
    19631888static DECLCALLBACK(void) vnetRelocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta)
    19641889{
    1965     VNETSTATE* pState = PDMINS_2_DATA(pDevIns, VNETSTATE*);
     1890    PVNETSTATE pThis = PDMINS_2_DATA(pDevIns, PVNETSTATE);
    19661891    vpciRelocate(pDevIns, offDelta);
    1967     pState->pCanRxQueueRC = PDMQueueRCPtr(pState->pCanRxQueueR3);
     1892    pThis->pCanRxQueueRC = PDMQueueRCPtr(pThis->pCanRxQueueR3);
    19681893#ifdef VNET_TX_DELAY
    1969     pState->pTxTimerRC    = TMTimerRCPtr(pState->pTxTimerR3);
     1894    pThis->pTxTimerRC    = TMTimerRCPtr(pThis->pTxTimerR3);
    19701895#endif /* VNET_TX_DELAY */
    19711896    // TBD
    19721897}
    19731898
    1974 /**
    1975  * Destruct a device instance.
    1976  *
    1977  * We need to free non-VM resources only.
    1978  *
    1979  * @returns VBox status.
    1980  * @param   pDevIns     The device instance data.
    1981  * @thread  EMT
     1899
     1900/**
     1901 * @interface_method_impl{PDMDEVREG,pfnDestruct}
    19821902 */
    19831903static DECLCALLBACK(int) vnetDestruct(PPDMDEVINS pDevIns)
    19841904{
    1985     VNETSTATE* pState = PDMINS_2_DATA(pDevIns, VNETSTATE*);
     1905    PVNETSTATE pThis = PDMINS_2_DATA(pDevIns, PVNETSTATE);
    19861906    PDMDEV_CHECK_VERSIONS_RETURN_QUIET(pDevIns);
    19871907
    19881908    LogRel(("TxTimer stats (avg/min/max): %7d usec %7d usec %7d usec\n",
    1989             pState->u32AvgDiff, pState->u32MinDiff, pState->u32MaxDiff));
    1990     Log(("%s Destroying instance\n", INSTANCE(pState)));
    1991     if (pState->hEventMoreRxDescAvail != NIL_RTSEMEVENT)
    1992     {
    1993         RTSemEventSignal(pState->hEventMoreRxDescAvail);
    1994         RTSemEventDestroy(pState->hEventMoreRxDescAvail);
    1995         pState->hEventMoreRxDescAvail = NIL_RTSEMEVENT;
    1996     }
    1997 
    1998     // if (PDMCritSectIsInitialized(&pState->csRx))
    1999     //     PDMR3CritSectDelete(&pState->csRx);
    2000 
    2001     return vpciDestruct(&pState->VPCI);
    2002 }
     1909            pThis->u32AvgDiff, pThis->u32MinDiff, pThis->u32MaxDiff));
     1910    Log(("%s Destroying instance\n", INSTANCE(pThis)));
     1911    if (pThis->hEventMoreRxDescAvail != NIL_RTSEMEVENT)
     1912    {
     1913        RTSemEventSignal(pThis->hEventMoreRxDescAvail);
     1914        RTSemEventDestroy(pThis->hEventMoreRxDescAvail);
     1915        pThis->hEventMoreRxDescAvail = NIL_RTSEMEVENT;
     1916    }
     1917
     1918    // if (PDMCritSectIsInitialized(&pThis->csRx))
     1919    //     PDMR3CritSectDelete(&pThis->csRx);
     1920
     1921    return vpciDestruct(&pThis->VPCI);
     1922}
     1923
    20031924
    20041925/**
     
    20071928static DECLCALLBACK(int) vnetConstruct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)
    20081929{
    2009     VNETSTATE* pState = PDMINS_2_DATA(pDevIns, VNETSTATE*);
     1930    PVNETSTATE pThis = PDMINS_2_DATA(pDevIns, PVNETSTATE);
    20101931    int        rc;
    20111932    PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
    20121933
    20131934    /* Initialize PCI part first. */
    2014     pState->VPCI.IBase.pfnQueryInterface    = vnetQueryInterface;
    2015     rc = vpciConstruct(pDevIns, &pState->VPCI, iInstance,
     1935    pThis->VPCI.IBase.pfnQueryInterface    = vnetQueryInterface;
     1936    rc = vpciConstruct(pDevIns, &pThis->VPCI, iInstance,
    20161937                       VNET_NAME_FMT, VNET_PCI_SUBSYSTEM_ID,
    20171938                       VNET_PCI_CLASS, VNET_N_QUEUES);
    2018     pState->pRxQueue  = vpciAddQueue(&pState->VPCI, 256, vnetQueueReceive,  "RX ");
    2019     pState->pTxQueue  = vpciAddQueue(&pState->VPCI, 256, vnetQueueTransmit, "TX ");
    2020     pState->pCtlQueue = vpciAddQueue(&pState->VPCI, 16,  vnetQueueControl,  "CTL");
    2021 
    2022     Log(("%s Constructing new instance\n", INSTANCE(pState)));
    2023 
    2024     pState->hEventMoreRxDescAvail = NIL_RTSEMEVENT;
     1939    pThis->pRxQueue  = vpciAddQueue(&pThis->VPCI, 256, vnetQueueReceive,  "RX ");
     1940    pThis->pTxQueue  = vpciAddQueue(&pThis->VPCI, 256, vnetQueueTransmit, "TX ");
     1941    pThis->pCtlQueue = vpciAddQueue(&pThis->VPCI, 16,  vnetQueueControl,  "CTL");
     1942
     1943    Log(("%s Constructing new instance\n", INSTANCE(pThis)));
     1944
     1945    pThis->hEventMoreRxDescAvail = NIL_RTSEMEVENT;
    20251946
    20261947    /*
     
    20321953
    20331954    /* Get config params */
    2034     rc = CFGMR3QueryBytes(pCfg, "MAC", pState->macConfigured.au8,
    2035                           sizeof(pState->macConfigured));
     1955    rc = CFGMR3QueryBytes(pCfg, "MAC", pThis->macConfigured.au8,
     1956                          sizeof(pThis->macConfigured));
    20361957    if (RT_FAILURE(rc))
    20371958        return PDMDEV_SET_ERROR(pDevIns, rc,
    20381959                                N_("Configuration error: Failed to get MAC address"));
    2039     rc = CFGMR3QueryBool(pCfg, "CableConnected", &pState->fCableConnected);
     1960    rc = CFGMR3QueryBool(pCfg, "CableConnected", &pThis->fCableConnected);
    20401961    if (RT_FAILURE(rc))
    20411962        return PDMDEV_SET_ERROR(pDevIns, rc,
    20421963                                N_("Configuration error: Failed to get the value of 'CableConnected'"));
    2043     rc = CFGMR3QueryU32Def(pCfg, "LinkUpDelay", (uint32_t*)&pState->cMsLinkUpDelay, 5000); /* ms */
     1964    rc = CFGMR3QueryU32Def(pCfg, "LinkUpDelay", (uint32_t*)&pThis->cMsLinkUpDelay, 5000); /* ms */
    20441965    if (RT_FAILURE(rc))
    20451966        return PDMDEV_SET_ERROR(pDevIns, rc,
    20461967                                N_("Configuration error: Failed to get the value of 'LinkUpDelay'"));
    2047     Assert(pState->cMsLinkUpDelay <= 300000); /* less than 5 minutes */
    2048     if (pState->cMsLinkUpDelay > 5000 || pState->cMsLinkUpDelay < 100)
     1968    Assert(pThis->cMsLinkUpDelay <= 300000); /* less than 5 minutes */
     1969    if (pThis->cMsLinkUpDelay > 5000 || pThis->cMsLinkUpDelay < 100)
    20491970    {
    20501971        LogRel(("%s WARNING! Link up delay is set to %u seconds!\n",
    2051                 INSTANCE(pState), pState->cMsLinkUpDelay / 1000));
     1972                INSTANCE(pThis), pThis->cMsLinkUpDelay / 1000));
    20521973    }
    20531974    Log(("%s Link up delay is set to %u seconds\n",
    2054          INSTANCE(pState), pState->cMsLinkUpDelay / 1000));
    2055 
    2056 
    2057     vnetPrintFeatures(pState, vnetGetHostFeatures(pState), "Device supports the following features");
     1975         INSTANCE(pThis), pThis->cMsLinkUpDelay / 1000));
     1976
     1977
     1978    vnetPrintFeatures(pThis, vnetGetHostFeatures(pThis), "Device supports the following features");
    20581979
    20591980    /* Initialize PCI config space */
    2060     memcpy(pState->config.mac.au8, pState->macConfigured.au8, sizeof(pState->config.mac.au8));
    2061     pState->config.uStatus = 0;
     1981    memcpy(pThis->config.mac.au8, pThis->macConfigured.au8, sizeof(pThis->config.mac.au8));
     1982    pThis->config.uStatus = 0;
    20621983
    20631984    /* Initialize state structure */
    2064     pState->u32PktNo     = 1;
     1985    pThis->u32PktNo     = 1;
    20651986
    20661987    /* Interfaces */
    2067     pState->INetworkDown.pfnWaitReceiveAvail = vnetNetworkDown_WaitReceiveAvail;
    2068     pState->INetworkDown.pfnReceive          = vnetNetworkDown_Receive;
    2069     pState->INetworkDown.pfnReceiveGso       = vnetNetworkDown_ReceiveGso;
    2070     pState->INetworkDown.pfnXmitPending      = vnetNetworkDown_XmitPending;
    2071 
    2072     pState->INetworkConfig.pfnGetMac         = vnetGetMac;
    2073     pState->INetworkConfig.pfnGetLinkState   = vnetGetLinkState;
    2074     pState->INetworkConfig.pfnSetLinkState   = vnetSetLinkState;
     1988    pThis->INetworkDown.pfnWaitReceiveAvail = vnetNetworkDown_WaitReceiveAvail;
     1989    pThis->INetworkDown.pfnReceive          = vnetNetworkDown_Receive;
     1990    pThis->INetworkDown.pfnReceiveGso       = vnetNetworkDown_ReceiveGso;
     1991    pThis->INetworkDown.pfnXmitPending      = vnetNetworkDown_XmitPending;
     1992
     1993    pThis->INetworkConfig.pfnGetMac         = vnetGetMac;
     1994    pThis->INetworkConfig.pfnGetLinkState   = vnetGetLinkState;
     1995    pThis->INetworkConfig.pfnSetLinkState   = vnetSetLinkState;
    20751996
    20761997    /* Initialize critical section. */
    2077     // char szTmp[sizeof(pState->VPCI.szInstance) + 2];
    2078     // RTStrPrintf(szTmp, sizeof(szTmp), "%sRX", pState->VPCI.szInstance);
    2079     // rc = PDMDevHlpCritSectInit(pDevIns, &pState->csRx, szTmp);
     1998    // char szTmp[sizeof(pThis->VPCI.szInstance) + 2];
     1999    // RTStrPrintf(szTmp, sizeof(szTmp), "%sRX", pThis->VPCI.szInstance);
     2000    // rc = PDMDevHlpCritSectInit(pDevIns, &pThis->csRx, szTmp);
    20802001    // if (RT_FAILURE(rc))
    20812002    //     return rc;
     
    20992020    /* Create the RX notifier signaller. */
    21002021    rc = PDMDevHlpQueueCreate(pDevIns, sizeof(PDMQUEUEITEMCORE), 1, 0,
    2101                               vnetCanRxQueueConsumer, true, "VNet-Rcv", &pState->pCanRxQueueR3);
     2022                              vnetCanRxQueueConsumer, true, "VNet-Rcv", &pThis->pCanRxQueueR3);
    21022023    if (RT_FAILURE(rc))
    21032024        return rc;
    2104     pState->pCanRxQueueR0 = PDMQueueR0Ptr(pState->pCanRxQueueR3);
    2105     pState->pCanRxQueueRC = PDMQueueRCPtr(pState->pCanRxQueueR3);
     2025    pThis->pCanRxQueueR0 = PDMQueueR0Ptr(pThis->pCanRxQueueR3);
     2026    pThis->pCanRxQueueRC = PDMQueueRCPtr(pThis->pCanRxQueueR3);
    21062027
    21072028    /* Create Link Up Timer */
    2108     rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL, vnetLinkUpTimer, pState,
     2029    rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL, vnetLinkUpTimer, pThis,
    21092030                                TMTIMER_FLAGS_NO_CRIT_SECT,
    2110                                 "VirtioNet Link Up Timer", &pState->pLinkUpTimer);
     2031                                "VirtioNet Link Up Timer", &pThis->pLinkUpTimer);
    21112032    if (RT_FAILURE(rc))
    21122033        return rc;
     
    21142035#ifdef VNET_TX_DELAY
    21152036    /* Create Transmit Delay Timer */
    2116     rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL, vnetTxTimer, pState,
     2037    rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL, vnetTxTimer, pThis,
    21172038                                TMTIMER_FLAGS_NO_CRIT_SECT,
    2118                                 "VirtioNet TX Delay Timer", &pState->pTxTimerR3);
     2039                                "VirtioNet TX Delay Timer", &pThis->pTxTimerR3);
    21192040    if (RT_FAILURE(rc))
    21202041        return rc;
    2121     pState->pTxTimerR0 = TMTimerR0Ptr(pState->pTxTimerR3);
    2122     pState->pTxTimerRC = TMTimerRCPtr(pState->pTxTimerR3);
    2123 
    2124     pState->u32i = pState->u32AvgDiff = pState->u32MaxDiff = 0;
    2125     pState->u32MinDiff = ~0;
     2042    pThis->pTxTimerR0 = TMTimerR0Ptr(pThis->pTxTimerR3);
     2043    pThis->pTxTimerRC = TMTimerRCPtr(pThis->pTxTimerR3);
     2044
     2045    pThis->u32i = pThis->u32AvgDiff = pThis->u32MaxDiff = 0;
     2046    pThis->u32MinDiff = ~0;
    21262047#endif /* VNET_TX_DELAY */
    21272048
    2128     rc = PDMDevHlpDriverAttach(pDevIns, 0, &pState->VPCI.IBase, &pState->pDrvBase, "Network Port");
     2049    rc = PDMDevHlpDriverAttach(pDevIns, 0, &pThis->VPCI.IBase, &pThis->pDrvBase, "Network Port");
    21292050    if (RT_SUCCESS(rc))
    21302051    {
     
    21342055                                       N_("A Domain Name Server (DNS) for NAT networking could not be determined. Ensure that your host is correctly connected to an ISP. If you ignore this warning the guest will not be able to perform nameserver lookups and it will probably observe delays if trying so"));
    21352056        }
    2136         pState->pDrv = PDMIBASE_QUERY_INTERFACE(pState->pDrvBase, PDMINETWORKUP);
    2137         AssertMsgReturn(pState->pDrv, ("Failed to obtain the PDMINETWORKUP interface!\n"),
     2057        pThis->pDrv = PDMIBASE_QUERY_INTERFACE(pThis->pDrvBase, PDMINETWORKUP);
     2058        AssertMsgReturn(pThis->pDrv, ("Failed to obtain the PDMINETWORKUP interface!\n"),
    21382059                        VERR_PDM_MISSING_INTERFACE_BELOW);
    21392060    }
     
    21422063    {
    21432064         /* No error! */
    2144         Log(("%s This adapter is not attached to any network!\n", INSTANCE(pState)));
     2065        Log(("%s This adapter is not attached to any network!\n", INSTANCE(pThis)));
    21452066    }
    21462067    else
    21472068        return PDMDEV_SET_ERROR(pDevIns, rc, N_("Failed to attach the network LUN"));
    21482069
    2149     rc = RTSemEventCreate(&pState->hEventMoreRxDescAvail);
     2070    rc = RTSemEventCreate(&pThis->hEventMoreRxDescAvail);
    21502071    if (RT_FAILURE(rc))
    21512072        return rc;
    21522073
    2153     rc = vnetReset(pState);
     2074    rc = vnetReset(pThis);
    21542075    AssertRC(rc);
    21552076
    2156     PDMDevHlpSTAMRegisterF(pDevIns, &pState->StatReceiveBytes,       STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES,          "Amount of data received",            "/Devices/VNet%d/ReceiveBytes", iInstance);
    2157     PDMDevHlpSTAMRegisterF(pDevIns, &pState->StatTransmitBytes,      STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES,          "Amount of data transmitted",         "/Devices/VNet%d/TransmitBytes", iInstance);
    2158     PDMDevHlpSTAMRegisterF(pDevIns, &pState->StatReceiveGSO,         STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT,          "Number of received GSO packets",     "/Devices/VNet%d/Packets/ReceiveGSO", iInstance);
    2159     PDMDevHlpSTAMRegisterF(pDevIns, &pState->StatTransmitPackets,    STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT,          "Number of sent packets",             "/Devices/VNet%d/Packets/Transmit", iInstance);
    2160     PDMDevHlpSTAMRegisterF(pDevIns, &pState->StatTransmitGSO,        STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT,          "Number of sent GSO packets",         "/Devices/VNet%d/Packets/Transmit-Gso", iInstance);
    2161     PDMDevHlpSTAMRegisterF(pDevIns, &pState->StatTransmitCSum,       STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT,          "Number of completed TX checksums",   "/Devices/VNet%d/Packets/Transmit-Csum", iInstance);
     2077    PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatReceiveBytes,       STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES,          "Amount of data received",            "/Devices/VNet%d/ReceiveBytes", iInstance);
     2078    PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatTransmitBytes,      STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES,          "Amount of data transmitted",         "/Devices/VNet%d/TransmitBytes", iInstance);
     2079    PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatReceiveGSO,         STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT,          "Number of received GSO packets",     "/Devices/VNet%d/Packets/ReceiveGSO", iInstance);
     2080    PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatTransmitPackets,    STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT,          "Number of sent packets",             "/Devices/VNet%d/Packets/Transmit", iInstance);
     2081    PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatTransmitGSO,        STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT,          "Number of sent GSO packets",         "/Devices/VNet%d/Packets/Transmit-Gso", iInstance);
     2082    PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatTransmitCSum,       STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT,          "Number of completed TX checksums",   "/Devices/VNet%d/Packets/Transmit-Csum", iInstance);
    21622083#if defined(VBOX_WITH_STATISTICS)
    2163     PDMDevHlpSTAMRegisterF(pDevIns, &pState->StatReceive,            STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling receive",                  "/Devices/VNet%d/Receive/Total", iInstance);
    2164     PDMDevHlpSTAMRegisterF(pDevIns, &pState->StatReceiveStore,       STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling receive storing",          "/Devices/VNet%d/Receive/Store", iInstance);
    2165     PDMDevHlpSTAMRegisterF(pDevIns, &pState->StatRxOverflow,         STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_OCCURENCE, "Profiling RX overflows",        "/Devices/VNet%d/RxOverflow", iInstance);
    2166     PDMDevHlpSTAMRegisterF(pDevIns, &pState->StatRxOverflowWakeup,   STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,     "Nr of RX overflow wakeups",          "/Devices/VNet%d/RxOverflowWakeup", iInstance);
    2167     PDMDevHlpSTAMRegisterF(pDevIns, &pState->StatTransmit,           STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling transmits in HC",          "/Devices/VNet%d/Transmit/Total", iInstance);
    2168     PDMDevHlpSTAMRegisterF(pDevIns, &pState->StatTransmitSend,       STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling send transmit in HC",      "/Devices/VNet%d/Transmit/Send", iInstance);
     2084    PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatReceive,            STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling receive",                  "/Devices/VNet%d/Receive/Total", iInstance);
     2085    PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatReceiveStore,       STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling receive storing",          "/Devices/VNet%d/Receive/Store", iInstance);
     2086    PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatRxOverflow,         STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_OCCURENCE, "Profiling RX overflows",        "/Devices/VNet%d/RxOverflow", iInstance);
     2087    PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatRxOverflowWakeup,   STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,     "Nr of RX overflow wakeups",          "/Devices/VNet%d/RxOverflowWakeup", iInstance);
     2088    PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatTransmit,           STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling transmits in HC",          "/Devices/VNet%d/Transmit/Total", iInstance);
     2089    PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatTransmitSend,       STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling send transmit in HC",      "/Devices/VNet%d/Transmit/Send", iInstance);
    21692090#endif /* VBOX_WITH_STATISTICS */
    21702091
  • trunk/src/VBox/Devices/VirtIO/Virtio.cpp

    r44528 r44849  
    308308 * @param   pDevIns     The device instance.
    309309 * @param   pvUser      Pointer to the device state structure.
    310  * @param   port        Port number used for the IN operation.
     310 * @param   Port        Port number used for the IN operation.
    311311 * @param   pu32        Where to store the result.
    312312 * @param   cb          Number of bytes read.
     
    315315int vpciIOPortIn(PPDMDEVINS         pDevIns,
    316316                 void              *pvUser,
    317                  RTIOPORT           port,
     317                 RTIOPORT           Port,
    318318                 uint32_t          *pu32,
    319319                 unsigned           cb,
     
    342342        }*/
    343343
    344     port -= pState->addrIOPort;
    345     switch (port)
     344    Port -= pState->addrIOPort;
     345    switch (Port)
    346346    {
    347347        case VPCI_HOST_FEATURES:
     
    382382
    383383        default:
    384             if (port >= VPCI_CONFIG)
    385             {
    386                 rc = pfnGetConfig(pState, port - VPCI_CONFIG, cb, pu32);
    387             }
     384            if (Port >= VPCI_CONFIG)
     385                rc = pfnGetConfig(pState, Port - VPCI_CONFIG, cb, pu32);
    388386            else
    389387            {
    390388                *pu32 = 0xFFFFFFFF;
    391                 rc = PDMDevHlpDBGFStop(pDevIns, RT_SRC_POS, "%s vpciIOPortIn: "
    392                                        "no valid port at offset port=%RTiop "
    393                                        "cb=%08x\n", szInst, port, cb);
     389                rc = PDMDevHlpDBGFStop(pDevIns, RT_SRC_POS, "%s vpciIOPortIn: no valid port at offset port=%RTiop cb=%08x\n",
     390                                       szInst, Port, cb);
    394391            }
    395392            break;
    396393    }
    397     Log3(("%s vpciIOPortIn:  At %RTiop in  %0*x\n",
    398           szInst, port, cb*2, *pu32));
     394    Log3(("%s vpciIOPortIn:  At %RTiop in  %0*x\n", szInst, Port, cb*2, *pu32));
    399395    STAM_PROFILE_ADV_STOP(&pState->CTXSUFF(StatIORead), a);
    400396    //vpciCsLeave(pState);
     
    413409 * @param   u32         The value to output.
    414410 * @param   cb          The value size in bytes.
     411 * @todo    r=bird: Use a callback table instead of passing 6 function pointers
     412 *          for potential operations with each I/O port write.
    415413 * @thread  EMT
    416414 */
    417415int vpciIOPortOut(PPDMDEVINS                pDevIns,
    418416                  void                     *pvUser,
    419                   RTIOPORT                  port,
     417                  RTIOPORT                  Port,
    420418                  uint32_t                  u32,
    421419                  unsigned                  cb,
     
    434432    STAM_PROFILE_ADV_START(&pState->CTXSUFF(StatIOWrite), a);
    435433
    436     port -= pState->addrIOPort;
    437     Log3(("%s virtioIOPortOut: At %RTiop out          %0*x\n", szInst, port, cb*2, u32));
    438 
    439     switch (port)
     434    Port -= pState->addrIOPort;
     435    Log3(("%s virtioIOPortOut: At %RTiop out          %0*x\n", szInst, Port, cb*2, u32));
     436
     437    switch (Port)
    440438    {
    441439        case VPCI_GUEST_FEATURES:
     
    521519
    522520        default:
    523             if (port >= VPCI_CONFIG)
    524                 rc = pfnSetConfig(pState, port - VPCI_CONFIG, cb, &u32);
     521            if (Port >= VPCI_CONFIG)
     522                rc = pfnSetConfig(pState, Port - VPCI_CONFIG, cb, &u32);
    525523            else
    526                 rc = PDMDevHlpDBGFStop(pDevIns, RT_SRC_POS, "%s vpciIOPortOut: no valid port at offset port=%RTiop cb=%08x\n", szInst, port, cb);
     524                rc = PDMDevHlpDBGFStop(pDevIns, RT_SRC_POS, "%s vpciIOPortOut: no valid port at offset Port=%RTiop cb=%08x\n",
     525                                       szInst, Port, cb);
    527526            break;
    528527    }
  • trunk/src/VBox/Devices/VirtIO/Virtio.h

    r44529 r44849  
    55
    66/*
    7  * Copyright (C) 2009-2012 Oracle Corporation
     7 * Copyright (C) 2009-2013 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2121#include <iprt/ctype.h>
    2222
    23 #define VIRTIO_RELOCATE(p, o) *(RTHCUINTPTR *)&p += o
    24 
    25 /*
     23
     24/** @name Saved state versions.
    2625 * The saved state version is changed if either common or any of specific
    2726 * parts are changed. That is, it is perfectly possible that the version
     
    3130#define VIRTIO_SAVEDSTATE_VERSION_3_1_BETA1 1
    3231#define VIRTIO_SAVEDSTATE_VERSION           2
     32/** @} */
    3333
    3434#define DEVICE_PCI_VENDOR_ID                0x1AF4
     
    6363#define VRINGDESC_F_WRITE                   0x02
    6464
    65 struct VRingDesc
     65typedef struct VRingDesc
    6666{
    6767    uint64_t u64Addr;
     
    6969    uint16_t u16Flags;
    7070    uint16_t u16Next;
    71 };
    72 typedef struct VRingDesc VRINGDESC;
     71} VRINGDESC;
    7372typedef VRINGDESC *PVRINGDESC;
    7473
    7574#define VRINGAVAIL_F_NO_INTERRUPT 0x01
    7675
    77 struct VRingAvail
     76typedef struct VRingAvail
    7877{
    7978    uint16_t uFlags;
    8079    uint16_t uNextFreeIndex;
    8180    uint16_t auRing[1];
    82 };
    83 typedef struct VRingAvail VRINGAVAIL;
    84 
    85 struct VRingUsedElem
     81} VRINGAVAIL;
     82
     83typedef struct VRingUsedElem
    8684{
    8785    uint32_t uId;
    8886    uint32_t uLen;
    89 };
    90 typedef struct VRingUsedElem VRINGUSEDELEM;
     87} VRINGUSEDELEM;
    9188
    9289#define VRINGUSED_F_NO_NOTIFY 0x01
    9390
    94 struct VRingUsed
     91typedef struct VRingUsed
    9592{
    9693    uint16_t      uFlags;
    9794    uint16_t      uIndex;
    9895    VRINGUSEDELEM aRing[1];
    99 };
    100 typedef struct VRingUsed VRINGUSED;
     96} VRINGUSED;
    10197typedef VRINGUSED *PVRINGUSED;
    10298
    10399#define VRING_MAX_SIZE 1024
    104100
    105 struct VRing
     101typedef struct VRing
    106102{
    107103    uint16_t   uSize;
     
    110106    RTGCPHYS   addrAvail;
    111107    RTGCPHYS   addrUsed;
    112 };
    113 typedef struct VRing VRING;
     108} VRING;
    114109typedef VRING *PVRING;
    115110
    116 struct VQueue
     111typedef struct VQueue
    117112{
    118113    VRING    VRing;
     
    126121#endif
    127122    R3PTRTYPE(const char *) pcszName;
    128 };
    129 typedef struct VQueue VQUEUE;
     123} VQUEUE;
    130124typedef VQUEUE *PVQUEUE;
    131125
    132 struct VQueueElemSeg
     126typedef struct VQueueElemSeg
    133127{
    134128    RTGCPHYS addr;
    135129    void    *pv;
    136130    uint32_t cb;
    137 };
    138 typedef struct VQueueElemSeg VQUEUESEG;
    139 
    140 struct VQueueElem
     131} VQUEUESEG;
     132
     133typedef struct VQueueElem
    141134{
    142135    uint32_t  uIndex;
     
    145138    VQUEUESEG aSegsIn[VRING_MAX_SIZE];
    146139    VQUEUESEG aSegsOut[VRING_MAX_SIZE];
    147 };
    148 typedef struct VQueueElem VQUEUEELEM;
     140} VQUEUEELEM;
    149141typedef VQUEUEELEM *PVQUEUEELEM;
    150142
     
    159151
    160152/**
    161  * The state of the VirtIO PCI device
     153 * The core (/common) state of the VirtIO PCI device
    162154 *
    163155 * @implements  PDMILEDPORTS
    164156 */
    165 struct VPCIState_st
     157typedef struct VPCIState_st
    166158{
    167159    PDMCRITSECT            cs;      /**< Critical section - what is it protecting? */
     
    219211    STAMPROFILE            StatCsHC;
    220212#endif /* VBOX_WITH_STATISTICS */
    221 };
    222 typedef struct VPCIState_st VPCISTATE;
     213} VPCISTATE;
     214/** Pointer to the core (/common) state of a VirtIO PCI device. */
    223215typedef VPCISTATE *PVPCISTATE;
    224216
    225 /* Callbacks *****************************************************************/
     217/** @name Callbacks
     218 * @{ */
    226219typedef uint32_t (*PFNGETHOSTFEATURES)(void *pState);
    227220typedef uint32_t (*PFNGETHOSTMINIMALFEATURES)(void *pState);
     
    231224typedef int      (*PFNRESET)(void *pState);
    232225typedef void     (*PFNREADY)(void *pState);
    233 /*****************************************************************************/
     226/** @} */
    234227
    235228int vpciRaiseInterrupt(VPCISTATE *pState, int rcBusy, uint8_t u8IntCause);
     
    326319}
    327320
    328 #endif /* ___VBox_Virtio_h */
     321#endif /* !___VBox_Virtio_h */
Note: See TracChangeset for help on using the changeset viewer.

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