Changeset 44849 in vbox
- Timestamp:
- Feb 27, 2013 8:22:06 PM (12 years ago)
- Location:
- trunk/src/VBox/Devices
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/DevVirtioNet.cpp
r44528 r44849 5 5 6 6 /* 7 * Copyright (C) 2009-201 2Oracle Corporation7 * Copyright (C) 2009-2013 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 17 17 18 18 19 /******************************************************************************* 20 * Header Files * 21 *******************************************************************************/ 19 22 #define LOG_GROUP LOG_GROUP_DEV_VIRTIO_NET 20 23 #define VNET_GC_SUPPORT … … 35 38 36 39 40 /******************************************************************************* 41 * Defined Constants And Macros * 42 *******************************************************************************/ 37 43 #ifndef VBOX_DEVICE_STRUCT_TESTCASE 38 44 39 #define INSTANCE(p State) pState->VPCI.szInstance40 #define STATUS p State->config.uStatus45 #define INSTANCE(pThis) pThis->VPCI.szInstance 46 #define STATUS pThis->config.uStatus 41 47 42 48 #ifdef IN_RING3 … … 57 63 #endif /* IN_RING3 */ 58 64 59 /* Forward declarations ******************************************************/60 RT_C_DECLS_BEGIN61 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_END64 65 65 #endif /* VBOX_DEVICE_STRUCT_TESTCASE */ 66 66 67 67 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? 70 70 #define VNET_MAC_FILTER_LEN 32 71 71 #define VNET_MAX_VID (1 << 12) 72 72 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 /** @} */ 91 93 92 94 #define VNET_S_LINK_UP 1 93 95 94 96 97 /******************************************************************************* 98 * Structures and Typedefs * 99 *******************************************************************************/ 95 100 #ifdef _MSC_VER 96 101 struct VNetPCIConfig 97 102 #else /* !_MSC_VER */ 98 struct __attribute__ ((__packed__)) VNetPCIConfig 103 struct __attribute__ ((__packed__)) VNetPCIConfig /** @todo r=bird: Use #pragma pack if necessary, that's portable! */ 99 104 #endif /* !_MSC_VER */ 100 105 { … … 111 116 * @implements PDMINETWORKCONFIG 112 117 */ 113 struct VNetState_st118 typedef struct VNetState_st 114 119 { 115 120 /* VPCISTATE must be the first member! */ … … 191 196 RTSEMEVENT hEventMoreRxDescAvail; 192 197 193 /* Statistic fields ******************************************************/194 198 /** @name Statistic 199 * @{ */ 195 200 STAMCOUNTER StatReceiveBytes; 196 201 STAMCOUNTER StatTransmitBytes; … … 207 212 STAMCOUNTER StatRxOverflowWakeup; 208 213 #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. */ 212 217 typedef VNETSTATE *PVNETSTATE; 213 218 … … 271 276 AssertCompileSize(VNETCTLHDR, 2); 272 277 273 /* Returns true if large packets are written into several RX buffers. */274 DECLINLINE(bool) vnetMergeableRxBuffers(PVNETSTATE p State)275 { 276 return !!(p State->VPCI.uGuestFeatures & VNET_F_MRG_RXBUF);277 } 278 279 DECLINLINE(int) vnetCsEnter(PVNETSTATE p State, int rcBusy)280 { 281 return vpciCsEnter(&p State->VPCI, rcBusy);282 } 283 284 DECLINLINE(void) vnetCsLeave(PVNETSTATE p State)285 { 286 vpciCsLeave(&p State->VPCI);287 } 288 289 DECLINLINE(int) vnetCsRxEnter(PVNETSTATE p State, int rcBusy)290 { 291 // STAM_PROFILE_START(&p State->CTXSUFF(StatCsRx), a);292 // int rc = PDMCritSectEnter(&p State->csRx, rcBusy);293 // STAM_PROFILE_STOP(&p State->CTXSUFF(StatCsRx), a);278 /** Returns true if large packets are written into several RX buffers. */ 279 DECLINLINE(bool) vnetMergeableRxBuffers(PVNETSTATE pThis) 280 { 281 return !!(pThis->VPCI.uGuestFeatures & VNET_F_MRG_RXBUF); 282 } 283 284 DECLINLINE(int) vnetCsEnter(PVNETSTATE pThis, int rcBusy) 285 { 286 return vpciCsEnter(&pThis->VPCI, rcBusy); 287 } 288 289 DECLINLINE(void) vnetCsLeave(PVNETSTATE pThis) 290 { 291 vpciCsLeave(&pThis->VPCI); 292 } 293 294 DECLINLINE(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); 294 299 // return rc; 295 300 return VINF_SUCCESS; 296 301 } 297 302 298 DECLINLINE(void) vnetCsRxLeave(PVNETSTATE p State)299 { 300 // PDMCritSectLeave(&p State->csRx);303 DECLINLINE(void) vnetCsRxLeave(PVNETSTATE pThis) 304 { 305 // PDMCritSectLeave(&pThis->csRx); 301 306 } 302 307 … … 304 309 * Dump a packet to debug log. 305 310 * 306 * @param p StateThe device state structure.311 * @param pThis The device state structure. 307 312 * @param cpPacket The packet. 308 313 * @param cb The size of the packet. 309 314 * @param cszText A string denoting direction of packet transfer. 310 315 */ 311 DECLINLINE(void) vnetPacketDump(PVNETSTATE p State, const uint8_t *cpPacket, size_t cb, const char *cszText)316 DECLINLINE(void) vnetPacketDump(PVNETSTATE pThis, const uint8_t *cpPacket, size_t cb, const char *cszText) 312 317 { 313 318 #ifdef DEBUG 314 319 Log(("%s %s packet #%d (%d bytes):\n", 315 INSTANCE(p State), cszText, ++pState->u32PktNo, cb));320 INSTANCE(pThis), cszText, ++pThis->u32PktNo, cb)); 316 321 Log3(("%.*Rhxd\n", cb, cpPacket)); 317 322 #endif … … 321 326 * Print features given in uFeatures to debug log. 322 327 * 323 * @param p StateThe 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. 325 330 * @param pcszText A string to print before the list of features. 326 331 */ 327 DECLINLINE(void) vnetPrintFeatures(PVNETSTATE p State, uint32_t uFeatures, const char *pcszText)332 DECLINLINE(void) vnetPrintFeatures(PVNETSTATE pThis, uint32_t fFeatures, const char *pcszText) 328 333 { 329 334 #ifdef DEBUG … … 332 337 uint32_t uMask; 333 338 const char *pcszDesc; 334 } aFeatures[] = { 339 } const s_aFeatures[] = 340 { 335 341 { VNET_F_CSUM, "host handles pkts w/ partial csum" }, 336 342 { VNET_F_GUEST_CSUM, "guest handles pkts w/ partial csum" }, … … 352 358 }; 353 359 354 Log3(("%s %s:\n", INSTANCE(p State), pcszText));355 for (unsigned i = 0; i < RT_ELEMENTS( aFeatures); ++i)356 { 357 if ( aFeatures[i].uMask & uFeatures)358 Log3(("%s --> %s\n", INSTANCE(p State),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)); 359 365 } 360 366 #endif /* DEBUG */ … … 396 402 } 397 403 398 PDMBOTHCBDECL(void) vnetSetHostFeatures(void *pvState, uint32_t uFeatures)399 { 400 / / TODO: Nothing to do here yet401 VNETSTATE *pState = (VNETSTATE *)pvState;402 LogFlow(("%s vnetSetHostFeatures: uFeatures=%x\n", INSTANCE(p State), uFeatures));403 vnetPrintFeatures(p State, uFeatures, "The guest negotiated the following features");404 PDMBOTHCBDECL(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"); 404 410 } 405 411 406 412 PDMBOTHCBDECL(int) vnetGetConfig(void *pvState, uint32_t port, uint32_t cb, void *data) 407 413 { 408 VNETSTATE *pState = (VNETSTATE *)pvState;414 PVNETSTATE pThis = (PVNETSTATE)pvState; 409 415 if (port + cb > sizeof(struct VNetPCIConfig)) 410 416 { 411 Log(("%s vnetGetConfig: Read beyond the config structure is attempted (port=%RTiop cb=%x).\n", INSTANCE(p State), port, cb));417 Log(("%s vnetGetConfig: Read beyond the config structure is attempted (port=%RTiop cb=%x).\n", INSTANCE(pThis), port, cb)); 412 418 return VERR_IOM_IOPORT_UNUSED; 413 419 } 414 memcpy(data, ((uint8_t*)&p State->config) + port, cb);420 memcpy(data, ((uint8_t*)&pThis->config) + port, cb); 415 421 return VINF_SUCCESS; 416 422 } … … 418 424 PDMBOTHCBDECL(int) vnetSetConfig(void *pvState, uint32_t port, uint32_t cb, void *data) 419 425 { 420 VNETSTATE *pState = (VNETSTATE *)pvState;426 PVNETSTATE pThis = (PVNETSTATE)pvState; 421 427 if (port + cb > sizeof(struct VNetPCIConfig)) 422 428 { 423 Log(("%s vnetGetConfig: Write beyond the config structure is attempted (port=%RTiop cb=%x).\n", INSTANCE(p State), port, cb));429 Log(("%s vnetGetConfig: Write beyond the config structure is attempted (port=%RTiop cb=%x).\n", INSTANCE(pThis), port, cb)); 424 430 if (port < sizeof(struct VNetPCIConfig)) 425 memcpy(((uint8_t*)&p State->config) + port, data,431 memcpy(((uint8_t*)&pThis->config) + port, data, 426 432 sizeof(struct VNetPCIConfig) - port); 427 433 return VINF_SUCCESS; 428 434 } 429 memcpy(((uint8_t*)&p State->config) + port, data, cb);435 memcpy(((uint8_t*)&pThis->config) + port, data, cb); 430 436 return VINF_SUCCESS; 431 437 } … … 434 440 * Hardware reset. Revert all registers to initial values. 435 441 * 436 * @param p StateThe device state structure.442 * @param pThis The device state structure. 437 443 */ 438 444 PDMBOTHCBDECL(int) vnetReset(void *pvState) 439 445 { 440 VNETSTATE *pState = (VNETSTATE*)pvState;441 Log(("%s Reset triggered\n", INSTANCE(p State)));442 443 int rc = vnetCsRxEnter(p State, 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); 444 450 if (RT_UNLIKELY(rc != VINF_SUCCESS)) 445 451 { … … 447 453 return rc; 448 454 } 449 vpciReset(&p State->VPCI);450 vnetCsRxLeave(p State);455 vpciReset(&pThis->VPCI); 456 vnetCsRxLeave(pThis); 451 457 452 458 // TODO: Implement reset 453 if (p State->fCableConnected)459 if (pThis->fCableConnected) 454 460 STATUS = VNET_S_LINK_UP; 455 461 else … … 460 466 * virtio mode. 461 467 */ 462 p State->fPromiscuous = true;463 p State->fAllMulti = false;464 p State->nMacFilterEntries = 0;465 memset(p State->aMacFilter, 0, VNET_MAC_FILTER_LEN * sizeof(RTMAC));466 memset(p State->aVlanFilter, 0, sizeof(pState->aVlanFilter));467 p State->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; 468 474 #ifndef IN_RING3 469 475 return VINF_IOM_R3_IOPORT_WRITE; 470 476 #else 471 if (p State->pDrv)472 p State->pDrv->pfnSetPromiscuousMode(pState->pDrv, true);477 if (pThis->pDrv) 478 pThis->pDrv->pfnSetPromiscuousMode(pThis->pDrv, true); 473 479 return VINF_SUCCESS; 474 480 #endif … … 482 488 static void vnetWakeupReceive(PPDMDEVINS pDevIns) 483 489 { 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.} 501 503 */ 502 504 static DECLCALLBACK(void) vnetLinkUpTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser) 503 505 { 504 VNETSTATE *pState = (VNETSTATE *)pvUser;505 506 int rc = vnetCsEnter(p State, VERR_SEM_BUSY);506 PVNETSTATE pThis = (PVNETSTATE)pvUser; 507 508 int rc = vnetCsEnter(pThis, VERR_SEM_BUSY); 507 509 if (RT_UNLIKELY(rc != VINF_SUCCESS)) 508 510 return; 509 511 STATUS |= VNET_S_LINK_UP; 510 vpciRaiseInterrupt(&p State->VPCI, VERR_SEM_BUSY, VPCI_ISR_CONFIG);512 vpciRaiseInterrupt(&pThis->VPCI, VERR_SEM_BUSY, VPCI_ISR_CONFIG); 511 513 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.} 520 520 */ 521 521 static DECLCALLBACK(bool) vnetCanRxQueueConsumer(PPDMDEVINS pDevIns, PPDMQUEUEITEMCORE pItem) … … 530 530 * This function is called when the driver becomes ready. 531 531 * 532 * @param p StateThe 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(p State)));532 * @param pThis The device state structure. 533 */ 534 static void vnetReady(void *pvState) 535 { 536 PVNETSTATE pThis = (PVNETSTATE)pvState; 537 Log(("%s Driver became ready, waking up RX thread...\n", INSTANCE(pThis))); 538 538 #ifdef IN_RING3 539 vnetWakeupReceive(p State->VPCI.CTX_SUFF(pDevIns));539 vnetWakeupReceive(pThis->VPCI.CTX_SUFF(pDevIns)); 540 540 #else 541 PPDMQUEUEITEMCORE pItem = PDMQueueAlloc(p State->CTX_SUFF(pCanRxQueue));541 PPDMQUEUEITEMCORE pItem = PDMQueueAlloc(pThis->CTX_SUFF(pCanRxQueue)); 542 542 if (pItem) 543 PDMQueueInsert(p State->CTX_SUFF(pCanRxQueue), pItem);543 PDMQueueInsert(pThis->CTX_SUFF(pCanRxQueue), pItem); 544 544 #endif 545 545 } 546 546 547 547 /** 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 */ 550 PDMBOTHCBDECL(int) vnetIOPortIn(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT port, uint32_t *pu32, unsigned cb) 561 551 { 562 552 return vpciIOPortIn(pDevIns, pvUser, port, pu32, cb, … … 567 557 568 558 /** 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 */ 561 PDMBOTHCBDECL(int) vnetIOPortOut(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT port, uint32_t u32, unsigned cb) 582 562 { 583 563 return vpciIOPortOut(pDevIns, pvUser, port, u32, cb, … … 605 585 * @thread RX 606 586 */ 607 static int vnetCanReceive( VNETSTATE *pState)608 { 609 int rc = vnetCsRxEnter(p State, VERR_SEM_BUSY);587 static int vnetCanReceive(PVNETSTATE pThis) 588 { 589 int rc = vnetCsRxEnter(pThis, VERR_SEM_BUSY); 610 590 AssertRCReturn(rc, rc); 611 591 612 LogFlow(("%s vnetCanReceive\n", INSTANCE(p State)));613 if (!(p State->VPCI.uStatus & VPCI_STATUS_DRV_OK))592 LogFlow(("%s vnetCanReceive\n", INSTANCE(pThis))); 593 if (!(pThis->VPCI.uStatus & VPCI_STATUS_DRV_OK)) 614 594 rc = VERR_NET_NO_BUFFER_SPACE; 615 else if (!vqueueIsReady(&p State->VPCI, pState->pRxQueue))595 else if (!vqueueIsReady(&pThis->VPCI, pThis->pRxQueue)) 616 596 rc = VERR_NET_NO_BUFFER_SPACE; 617 else if (vqueueIsEmpty(&p State->VPCI, pState->pRxQueue))618 { 619 vringSetNotification(&p State->VPCI, &pState->pRxQueue->VRing, true);597 else if (vqueueIsEmpty(&pThis->VPCI, pThis->pRxQueue)) 598 { 599 vringSetNotification(&pThis->VPCI, &pThis->pRxQueue->VRing, true); 620 600 rc = VERR_NET_NO_BUFFER_SPACE; 621 601 } 622 602 else 623 603 { 624 vringSetNotification(&p State->VPCI, &pState->pRxQueue->VRing, false);604 vringSetNotification(&pThis->VPCI, &pThis->pRxQueue->VRing, false); 625 605 rc = VINF_SUCCESS; 626 606 } 627 607 628 LogFlow(("%s vnetCanReceive -> %Rrc\n", INSTANCE(p State), rc));629 vnetCsRxLeave(p State);608 LogFlow(("%s vnetCanReceive -> %Rrc\n", INSTANCE(pThis), rc)); 609 vnetCsRxLeave(pThis); 630 610 return rc; 631 611 } … … 636 616 static DECLCALLBACK(int) vnetNetworkDown_WaitReceiveAvail(PPDMINETWORKDOWN pInterface, RTMSINTERVAL cMillies) 637 617 { 638 VNETSTATE *pState= RT_FROM_MEMBER(pInterface, VNETSTATE, INetworkDown);639 LogFlow(("%s vnetNetworkDown_WaitReceiveAvail(cMillies=%u)\n", INSTANCE(p State), cMillies));640 int rc = vnetCanReceive(p State);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); 641 621 642 622 if (RT_SUCCESS(rc)) … … 646 626 647 627 rc = VERR_INTERRUPTED; 648 ASMAtomicXchgBool(&p State->fMaybeOutOfSpace, true);649 STAM_PROFILE_START(&p State->StatRxOverflow, a);628 ASMAtomicXchgBool(&pThis->fMaybeOutOfSpace, true); 629 STAM_PROFILE_START(&pThis->StatRxOverflow, a); 650 630 651 631 VMSTATE enmVMState; 652 while (RT_LIKELY( (enmVMState = PDMDevHlpVMState(p State->VPCI.CTX_SUFF(pDevIns))) == VMSTATE_RUNNING632 while (RT_LIKELY( (enmVMState = PDMDevHlpVMState(pThis->VPCI.CTX_SUFF(pDevIns))) == VMSTATE_RUNNING 653 633 || enmVMState == VMSTATE_RUNNING_LS)) 654 634 { 655 int rc2 = vnetCanReceive(p State);635 int rc2 = vnetCanReceive(pThis); 656 636 if (RT_SUCCESS(rc2)) 657 637 { … … 660 640 } 661 641 Log(("%s vnetNetworkDown_WaitReceiveAvail: waiting cMillies=%u...\n", 662 INSTANCE(p State), cMillies));663 RTSemEventWait(p State->hEventMoreRxDescAvail, cMillies);664 } 665 STAM_PROFILE_STOP(&p State->StatRxOverflow, a);666 ASMAtomicXchgBool(&p State->fMaybeOutOfSpace, false);667 668 LogFlow(("%s vnetNetworkDown_WaitReceiveAvail -> %d\n", INSTANCE(p State), 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)); 669 649 return rc; 670 650 } … … 676 656 static DECLCALLBACK(void *) vnetQueryInterface(struct PDMIBASE *pInterface, const char *pszIID) 677 657 { 678 VNETSTATE *pThis = RT_FROM_MEMBER(pInterface, VNETSTATE, VPCI.IBase);658 PVNETSTATE pThis = RT_FROM_MEMBER(pInterface, VNETSTATE, VPCI.IBase); 679 659 Assert(&pThis->VPCI.IBase == pInterface); 680 660 … … 712 692 * 713 693 * @returns true if packet is intended for this node. 714 * @param p StatePointer to the state structure.694 * @param pThis Pointer to the state structure. 715 695 * @param pvBuf The ethernet packet. 716 696 * @param cb Number of bytes available in the packet. 717 697 */ 718 static bool vnetAddressFilter(PVNETSTATE p State, const void *pvBuf, size_t cb)719 { 720 if (p State->fPromiscuous)698 static bool vnetAddressFilter(PVNETSTATE pThis, const void *pvBuf, size_t cb) 699 { 700 if (pThis->fPromiscuous) 721 701 return true; 722 702 … … 725 705 /* Compare TPID with VLAN Ether Type */ 726 706 if ( u16Ptr[6] == RT_H2BE_U16(0x8100) 727 && !ASMBitTest(p State->aVlanFilter, RT_BE2H_U16(u16Ptr[7]) & 0xFFF))728 { 729 Log4(("%s vnetAddressFilter: not our VLAN, returning false\n", INSTANCE(p State)));707 && !ASMBitTest(pThis->aVlanFilter, RT_BE2H_U16(u16Ptr[7]) & 0xFFF)) 708 { 709 Log4(("%s vnetAddressFilter: not our VLAN, returning false\n", INSTANCE(pThis))); 730 710 return false; 731 711 } … … 734 714 return true; 735 715 736 if (p State->fAllMulti && vnetIsMulticast(pvBuf))716 if (pThis->fAllMulti && vnetIsMulticast(pvBuf)) 737 717 return true; 738 718 739 if (!memcmp(p State->config.mac.au8, pvBuf, sizeof(RTMAC)))719 if (!memcmp(pThis->config.mac.au8, pvBuf, sizeof(RTMAC))) 740 720 return true; 741 721 Log4(("%s vnetAddressFilter: %RTmac (conf) != %RTmac (dest)\n", 742 INSTANCE(p State), pState->config.mac.au8, pvBuf));743 744 for (unsigned i = 0; i < p State->nMacFilterEntries; i++)745 if (!memcmp(&p State->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))) 746 726 return true; 747 727 748 Log2(("%s vnetAddressFilter: failed all tests, returning false, packet dump follows:\n", INSTANCE(p State)));749 vnetPacketDump(p State, (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"); 750 730 751 731 return false; … … 759 739 * 760 740 * @returns VBox status code. 761 * @param p StateThe device state structure.741 * @param pThis The device state structure. 762 742 * @param pvBuf The available data. 763 743 * @param cb Number of bytes available in the buffer. 764 744 * @thread RX 765 745 */ 766 static int vnetHandleRxPacket(PVNETSTATE p State, const void *pvBuf, size_t cb,746 static int vnetHandleRxPacket(PVNETSTATE pThis, const void *pvBuf, size_t cb, 767 747 PCPDMNETWORKGSO pGso) 768 748 { … … 775 755 { 776 756 Log2(("%s vnetHandleRxPacket: gso type=%x cbHdrsTotal=%u cbHdrsSeg=%u mss=%u" 777 " off1=0x%x off2=0x%x\n", INSTANCE(p State), pGso->u8Type,757 " off1=0x%x off2=0x%x\n", INSTANCE(pThis), pGso->u8Type, 778 758 pGso->cbHdrsTotal, pGso->cbHdrsSeg, pGso->cbMaxSeg, pGso->offHdr1, pGso->offHdr2)); 779 759 Hdr.Hdr.u8Flags = VNETHDR_F_NEEDS_CSUM; … … 798 778 Hdr.Hdr.u16GSOSize = pGso->cbMaxSeg; 799 779 Hdr.Hdr.u16CSumStart = pGso->offHdr2; 800 STAM_REL_COUNTER_INC(&p State->StatReceiveGSO);780 STAM_REL_COUNTER_INC(&pThis->StatReceiveGSO); 801 781 } 802 782 else … … 806 786 } 807 787 808 if (vnetMergeableRxBuffers(p State))788 if (vnetMergeableRxBuffers(pThis)) 809 789 uHdrLen = sizeof(VNETHDRMRX); 810 790 else 811 791 uHdrLen = sizeof(VNETHDR); 812 792 813 vnetPacketDump(p State, (const uint8_t*)pvBuf, cb, "<-- Incoming");793 vnetPacketDump(pThis, (const uint8_t*)pvBuf, cb, "<-- Incoming"); 814 794 815 795 unsigned int uOffset = 0; … … 820 800 unsigned int nSeg = 0, uElemSize = 0, cbReserved = 0; 821 801 822 if (!vqueueGet(&p State->VPCI, pState->pRxQueue, &elem))802 if (!vqueueGet(&pThis->VPCI, pThis->pRxQueue, &elem)) 823 803 { 824 804 /* … … 826 806 * were added and we received a big packet. 827 807 */ 828 Log(("%s vnetHandleRxPacket: Suddenly there is no space in receive queue!\n", INSTANCE(p State)));808 Log(("%s vnetHandleRxPacket: Suddenly there is no space in receive queue!\n", INSTANCE(pThis))); 829 809 return VERR_INTERNAL_ERROR; 830 810 } … … 832 812 if (elem.nIn < 1) 833 813 { 834 Log(("%s vnetHandleRxPacket: No writable descriptors in receive queue!\n", INSTANCE(p State)));814 Log(("%s vnetHandleRxPacket: No writable descriptors in receive queue!\n", INSTANCE(pThis))); 835 815 return VERR_INTERNAL_ERROR; 836 816 } … … 838 818 if (nElem == 0) 839 819 { 840 if (vnetMergeableRxBuffers(p State))820 if (vnetMergeableRxBuffers(pThis)) 841 821 { 842 822 addrHdrMrx = elem.aSegsIn[nSeg].addr; … … 848 828 if (elem.aSegsIn[nSeg].cb != sizeof(VNETHDR)) 849 829 { 850 Log(("%s vnetHandleRxPacket: The first descriptor does match the header size!\n", INSTANCE(p State)));830 Log(("%s vnetHandleRxPacket: The first descriptor does match the header size!\n", INSTANCE(pThis))); 851 831 return VERR_INTERNAL_ERROR; 852 832 } … … 863 843 uElemSize += uSize; 864 844 } 865 STAM_PROFILE_START(&p State->StatReceiveStore, a);866 vqueuePut(&p State->VPCI, pState->pRxQueue, &elem, uElemSize, cbReserved);867 STAM_PROFILE_STOP(&p State->StatReceiveStore, a);868 if (!vnetMergeableRxBuffers(p State))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)) 869 849 break; 870 850 cbReserved = 0; 871 851 } 872 if (vnetMergeableRxBuffers(p State))852 if (vnetMergeableRxBuffers(pThis)) 873 853 { 874 854 Hdr.u16NumBufs = nElem; 875 int rc = PDMDevHlpPhysWrite(p State->VPCI.CTX_SUFF(pDevIns), addrHdrMrx,855 int rc = PDMDevHlpPhysWrite(pThis->VPCI.CTX_SUFF(pDevIns), addrHdrMrx, 876 856 &Hdr, sizeof(Hdr)); 877 857 if (RT_FAILURE(rc)) 878 858 { 879 859 Log(("%s vnetHandleRxPacket: Failed to write merged RX buf header: %Rrc\n", 880 INSTANCE(p State), rc));860 INSTANCE(pThis), rc)); 881 861 return rc; 882 862 } 883 863 } 884 vqueueSync(&p State->VPCI, pState->pRxQueue);864 vqueueSync(&pThis->VPCI, pThis->pRxQueue); 885 865 if (uOffset < cb) 886 866 { 887 867 Log(("%s vnetHandleRxPacket: Packet did not fit into RX queue (packet size=%u)!\n", 888 INSTANCE(p State), cb));868 INSTANCE(pThis), cb)); 889 869 return VERR_TOO_MUCH_DATA; 890 870 } … … 900 880 PCPDMNETWORKGSO pGso) 901 881 { 902 VNETSTATE *pState= RT_FROM_MEMBER(pInterface, VNETSTATE, INetworkDown);882 PVNETSTATE pThis = RT_FROM_MEMBER(pInterface, VNETSTATE, INetworkDown); 903 883 904 884 if (pGso) 905 885 { 906 uint32_t uFeatures = p State->VPCI.uGuestFeatures;886 uint32_t uFeatures = pThis->VPCI.uGuestFeatures; 907 887 908 888 switch (pGso->u8Type) … … 925 905 { 926 906 Log2(("%s vnetNetworkDown_ReceiveGso: GSO type (0x%x) not supported\n", 927 INSTANCE(p State), pGso->u8Type));907 INSTANCE(pThis), pGso->u8Type)); 928 908 return VERR_NOT_SUPPORTED; 929 909 } … … 931 911 932 912 Log2(("%s vnetNetworkDown_ReceiveGso: pvBuf=%p cb=%u pGso=%p\n", 933 INSTANCE(p State), pvBuf, cb, pGso));934 int rc = vnetCanReceive(p State);913 INSTANCE(pThis), pvBuf, cb, pGso)); 914 int rc = vnetCanReceive(pThis); 935 915 if (RT_FAILURE(rc)) 936 916 return rc; 937 917 938 918 /* Drop packets if VM is not running or cable is disconnected. */ 939 VMSTATE enmVMState = PDMDevHlpVMState(p State->VPCI.CTX_SUFF(pDevIns));919 VMSTATE enmVMState = PDMDevHlpVMState(pThis->VPCI.CTX_SUFF(pDevIns)); 940 920 if (( enmVMState != VMSTATE_RUNNING 941 921 && enmVMState != VMSTATE_RUNNING_LS) … … 943 923 return VINF_SUCCESS; 944 924 945 STAM_PROFILE_START(&p State->StatReceive, a);946 vpciSetReadLed(&p State->VPCI, true);947 if (vnetAddressFilter(p State, pvBuf, cb))948 { 949 rc = vnetCsRxEnter(p State, 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); 950 930 if (RT_SUCCESS(rc)) 951 931 { 952 rc = vnetHandleRxPacket(p State, pvBuf, cb, pGso);953 STAM_REL_COUNTER_ADD(&p State->StatReceiveBytes, cb);954 vnetCsRxLeave(p State);955 } 956 } 957 vpciSetReadLed(&p State->VPCI, false);958 STAM_PROFILE_STOP(&p State->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); 959 939 return rc; 960 940 } … … 978 958 static DECLCALLBACK(int) vnetGetMac(PPDMINETWORKCONFIG pInterface, PRTMAC pMac) 979 959 { 980 VNETSTATE *pState= RT_FROM_MEMBER(pInterface, VNETSTATE, INetworkConfig);981 memcpy(pMac, p State->config.mac.au8, sizeof(RTMAC));960 PVNETSTATE pThis = RT_FROM_MEMBER(pInterface, VNETSTATE, INetworkConfig); 961 memcpy(pMac, pThis->config.mac.au8, sizeof(RTMAC)); 982 962 return VINF_SUCCESS; 983 963 } … … 992 972 static DECLCALLBACK(PDMNETWORKLINKSTATE) vnetGetLinkState(PPDMINETWORKCONFIG pInterface) 993 973 { 994 VNETSTATE *pState= RT_FROM_MEMBER(pInterface, VNETSTATE, INetworkConfig);974 PVNETSTATE pThis = RT_FROM_MEMBER(pInterface, VNETSTATE, INetworkConfig); 995 975 if (STATUS & VNET_S_LINK_UP) 996 976 return PDMNETWORKLINKSTATE_UP; … … 1008 988 static DECLCALLBACK(int) vnetSetLinkState(PPDMINETWORKCONFIG pInterface, PDMNETWORKLINKSTATE enmState) 1009 989 { 1010 VNETSTATE *pState= RT_FROM_MEMBER(pInterface, VNETSTATE, INetworkConfig);990 PVNETSTATE pThis = RT_FROM_MEMBER(pInterface, VNETSTATE, INetworkConfig); 1011 991 bool fOldUp = !!(STATUS & VNET_S_LINK_UP); 1012 992 bool fNewUp = enmState == PDMNETWORKLINKSTATE_UP; … … 1016 996 if (fNewUp) 1017 997 { 1018 Log(("%s Link is up\n", INSTANCE(p State)));998 Log(("%s Link is up\n", INSTANCE(pThis))); 1019 999 STATUS |= VNET_S_LINK_UP; 1020 vpciRaiseInterrupt(&p State->VPCI, VERR_SEM_BUSY, VPCI_ISR_CONFIG);1000 vpciRaiseInterrupt(&pThis->VPCI, VERR_SEM_BUSY, VPCI_ISR_CONFIG); 1021 1001 } 1022 1002 else 1023 1003 { 1024 Log(("%s Link is down\n", INSTANCE(p State)));1004 Log(("%s Link is down\n", INSTANCE(pThis))); 1025 1005 STATUS &= ~VNET_S_LINK_UP; 1026 vpciRaiseInterrupt(&p State->VPCI, VERR_SEM_BUSY, VPCI_ISR_CONFIG);1027 } 1028 if (p State->pDrv)1029 p State->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); 1030 1010 } 1031 1011 return VINF_SUCCESS; … … 1034 1014 static DECLCALLBACK(void) vnetQueueReceive(void *pvState, PVQUEUE pQueue) 1035 1015 { 1036 VNETSTATE *pState = (VNETSTATE*)pvState;1037 Log(("%s Receive buffers has been added, waking up receive thread.\n", INSTANCE(p State)));1038 vnetWakeupReceive(p State->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)); 1039 1019 } 1040 1020 … … 1106 1086 } 1107 1087 1108 static void vnetTransmitPendingPackets(PVNETSTATE p State, PVQUEUE pQueue, bool fOnWorkerThread)1088 static void vnetTransmitPendingPackets(PVNETSTATE pThis, PVQUEUE pQueue, bool fOnWorkerThread) 1109 1089 { 1110 1090 /* … … 1113 1093 * thread. 1114 1094 */ 1115 if (!ASMAtomicCmpXchgU32(&p State->uIsTransmitting, 1, 0))1095 if (!ASMAtomicCmpXchgU32(&pThis->uIsTransmitting, 1, 0)) 1116 1096 return; 1117 1097 1118 if ((p State->VPCI.uStatus & VPCI_STATUS_DRV_OK) == 0)1098 if ((pThis->VPCI.uStatus & VPCI_STATUS_DRV_OK) == 0) 1119 1099 { 1120 1100 Log(("%s Ignoring transmit requests from non-existent driver (status=0x%x).\n", 1121 INSTANCE(p State), pState->VPCI.uStatus));1101 INSTANCE(pThis), pThis->VPCI.uStatus)); 1122 1102 return; 1123 1103 } 1124 1104 1125 PPDMINETWORKUP pDrv = p State->pDrv;1105 PPDMINETWORKUP pDrv = pThis->pDrv; 1126 1106 if (pDrv) 1127 1107 { … … 1130 1110 if (rc == VERR_TRY_AGAIN) 1131 1111 { 1132 ASMAtomicWriteU32(&p State->uIsTransmitting, 0);1112 ASMAtomicWriteU32(&pThis->uIsTransmitting, 0); 1133 1113 return; 1134 1114 } … … 1136 1116 1137 1117 unsigned int uHdrLen; 1138 if (vnetMergeableRxBuffers(p State))1118 if (vnetMergeableRxBuffers(pThis)) 1139 1119 uHdrLen = sizeof(VNETHDRMRX); 1140 1120 else 1141 1121 uHdrLen = sizeof(VNETHDR); 1142 1122 1143 Log3(("%s vnetTransmitPendingPackets: About to transmit %d pending packets\n", INSTANCE(p State),1144 vringReadAvailIndex(&p State->VPCI, &pState->pTxQueue->VRing) - pState->pTxQueue->uNextAvailIndex));1145 1146 vpciSetWriteLed(&p State->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); 1147 1127 1148 1128 VQUEUEELEM elem; … … 1151 1131 * buffer first. 1152 1132 */ 1153 while (vqueuePeek(&p State->VPCI, pQueue, &elem))1133 while (vqueuePeek(&pThis->VPCI, pQueue, &elem)) 1154 1134 { 1155 1135 unsigned int uOffset = 0; … … 1157 1137 { 1158 1138 Log(("%s vnetQueueTransmit: The first segment is not the header! (%u < 2 || %u != %u).\n", 1159 INSTANCE(p State), elem.nOut, elem.aSegsOut[0].cb, uHdrLen));1139 INSTANCE(pThis), elem.nOut, elem.aSegsOut[0].cb, uHdrLen)); 1160 1140 break; /* For now we simply ignore the header, but it must be there anyway! */ 1161 1141 } … … 1163 1143 { 1164 1144 unsigned int uSize = 0; 1165 STAM_PROFILE_ADV_START(&p State->StatTransmit, a);1145 STAM_PROFILE_ADV_START(&pThis->StatTransmit, a); 1166 1146 /* Compute total frame size. */ 1167 1147 for (unsigned int i = 1; i < elem.nOut; i++) 1168 1148 uSize += elem.aSegsOut[i].cb; 1169 1149 Assert(uSize <= VNET_MAX_FRAME_SIZE); 1170 if (p State->pDrv)1150 if (pThis->pDrv) 1171 1151 { 1172 1152 VNETHDR Hdr; 1173 1153 PDMNETWORKGSO Gso, *pGso; 1174 1154 1175 PDMDevHlpPhysRead(p State->VPCI.CTX_SUFF(pDevIns), elem.aSegsOut[0].addr,1155 PDMDevHlpPhysRead(pThis->VPCI.CTX_SUFF(pDevIns), elem.aSegsOut[0].addr, 1176 1156 &Hdr, sizeof(Hdr)); 1177 1157 1178 STAM_REL_COUNTER_INC(&p State->StatTransmitPackets);1179 1180 STAM_PROFILE_START(&p State->StatTransmitSend, a);1158 STAM_REL_COUNTER_INC(&pThis->StatTransmitPackets); 1159 1160 STAM_PROFILE_START(&pThis->StatTransmitSend, a); 1181 1161 1182 1162 pGso = vnetSetupGsoCtx(&Gso, &Hdr); 1183 1163 /** @todo Optimize away the extra copying! (lazy bird) */ 1184 1164 PPDMSCATTERGATHER pSgBuf; 1185 int rc = p State->pDrv->pfnAllocBuf(pState->pDrv, uSize, pGso, &pSgBuf);1165 int rc = pThis->pDrv->pfnAllocBuf(pThis->pDrv, uSize, pGso, &pSgBuf); 1186 1166 if (RT_SUCCESS(rc)) 1187 1167 { … … 1190 1170 for (unsigned int i = 1; i < elem.nOut; i++) 1191 1171 { 1192 PDMDevHlpPhysRead(p State->VPCI.CTX_SUFF(pDevIns), elem.aSegsOut[i].addr,1172 PDMDevHlpPhysRead(pThis->VPCI.CTX_SUFF(pDevIns), elem.aSegsOut[i].addr, 1193 1173 ((uint8_t*)pSgBuf->aSegs[0].pvSeg) + uOffset, 1194 1174 elem.aSegsOut[i].cb); … … 1196 1176 } 1197 1177 pSgBuf->cbUsed = uSize; 1198 vnetPacketDump(p State, (uint8_t*)pSgBuf->aSegs[0].pvSeg, uSize, "--> Outgoing");1178 vnetPacketDump(pThis, (uint8_t*)pSgBuf->aSegs[0].pvSeg, uSize, "--> Outgoing"); 1199 1179 if (pGso) 1200 1180 { … … 1207 1187 { 1208 1188 Log4(("%s vnetTransmitPendingPackets: HdrLen before adjustment %d.\n", 1209 INSTANCE(p State), pGso->cbHdrsTotal));1189 INSTANCE(pThis), pGso->cbHdrsTotal)); 1210 1190 switch (pGso->u8Type) 1211 1191 { … … 1225 1205 ((PPDMNETWORKGSO)pSgBuf->pvUser)->cbHdrsSeg = pGso->cbHdrsTotal; 1226 1206 Log4(("%s vnetTransmitPendingPackets: adjusted HdrLen to %d.\n", 1227 INSTANCE(p State), pGso->cbHdrsTotal));1207 INSTANCE(pThis), pGso->cbHdrsTotal)); 1228 1208 } 1229 1209 Log2(("%s vnetTransmitPendingPackets: gso type=%x cbHdrsTotal=%u cbHdrsSeg=%u mss=%u" 1230 " off1=0x%x off2=0x%x\n", INSTANCE(p State), pGso->u8Type,1210 " off1=0x%x off2=0x%x\n", INSTANCE(pThis), pGso->u8Type, 1231 1211 pGso->cbHdrsTotal, pGso->cbHdrsSeg, pGso->cbMaxSeg, pGso->offHdr1, pGso->offHdr2)); 1232 STAM_REL_COUNTER_INC(&p State->StatTransmitGSO);1212 STAM_REL_COUNTER_INC(&pThis->StatTransmitGSO); 1233 1213 } 1234 1214 else if (Hdr.u8Flags & VNETHDR_F_NEEDS_CSUM) 1235 1215 { 1236 STAM_REL_COUNTER_INC(&p State->StatTransmitCSum);1216 STAM_REL_COUNTER_INC(&pThis->StatTransmitCSum); 1237 1217 /* 1238 1218 * This is not GSO frame but checksum offloading is requested. … … 1242 1222 } 1243 1223 1244 rc = p State->pDrv->pfnSendBuf(pState->pDrv, pSgBuf, false);1224 rc = pThis->pDrv->pfnSendBuf(pThis->pDrv, pSgBuf, false); 1245 1225 } 1246 1226 else 1247 1227 { 1248 1228 Log4(("virtio-net: failed to allocate SG buffer: size=%u rc=%Rrc\n", uSize, rc)); 1249 STAM_PROFILE_STOP(&p State->StatTransmitSend, a);1250 STAM_PROFILE_ADV_STOP(&p State->StatTransmit, a);1229 STAM_PROFILE_STOP(&pThis->StatTransmitSend, a); 1230 STAM_PROFILE_ADV_STOP(&pThis->StatTransmit, a); 1251 1231 /* Stop trying to fetch TX descriptors until we get more bandwidth. */ 1252 1232 break; 1253 1233 } 1254 1234 1255 STAM_PROFILE_STOP(&p State->StatTransmitSend, a);1256 STAM_REL_COUNTER_ADD(&p State->StatTransmitBytes, uOffset);1235 STAM_PROFILE_STOP(&pThis->StatTransmitSend, a); 1236 STAM_REL_COUNTER_ADD(&pThis->StatTransmitBytes, uOffset); 1257 1237 } 1258 1238 } 1259 1239 /* Remove this descriptor chain from the available ring */ 1260 vqueueSkip(&p State->VPCI, pQueue);1261 vqueuePut(&p State->VPCI, pQueue, &elem, sizeof(VNETHDR) + uOffset);1262 vqueueSync(&p State->VPCI, pQueue);1263 STAM_PROFILE_ADV_STOP(&p State->StatTransmit, a);1264 } 1265 vpciSetWriteLed(&p State->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); 1266 1246 1267 1247 if (pDrv) 1268 1248 pDrv->pfnEndXmit(pDrv); 1269 ASMAtomicWriteU32(&p State->uIsTransmitting, 0);1249 ASMAtomicWriteU32(&pThis->uIsTransmitting, 0); 1270 1250 } 1271 1251 … … 1275 1255 static DECLCALLBACK(void) vnetNetworkDown_XmitPending(PPDMINETWORKDOWN pInterface) 1276 1256 { 1277 VNETSTATE *pThis = RT_FROM_MEMBER(pInterface, VNETSTATE, INetworkDown);1257 PVNETSTATE pThis = RT_FROM_MEMBER(pInterface, VNETSTATE, INetworkDown); 1278 1258 vnetTransmitPendingPackets(pThis, pThis->pTxQueue, false /*fOnWorkerThread*/); 1279 1259 } … … 1283 1263 static DECLCALLBACK(void) vnetQueueTransmit(void *pvState, PVQUEUE pQueue) 1284 1264 { 1285 VNETSTATE *pState = (VNETSTATE*)pvState;1286 1287 if (TMTimerIsActive(p State->CTX_SUFF(pTxTimer)))1288 { 1289 int rc = TMTimerStop(p State->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)); 1290 1270 Log3(("%s vnetQueueTransmit: Got kicked with notification disabled, " 1291 "re-enable notification and flush TX queue\n", INSTANCE(p State)));1292 vnetTransmitPendingPackets(p State, pQueue, false /*fOnWorkerThread*/);1293 if (RT_FAILURE(vnetCsEnter(p State, 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))) 1294 1274 LogRel(("vnetQueueTransmit: Failed to enter critical section!/n")); 1295 1275 else 1296 1276 { 1297 vringSetNotification(&p State->VPCI, &pState->pTxQueue->VRing, true);1298 vnetCsLeave(p State);1277 vringSetNotification(&pThis->VPCI, &pThis->pTxQueue->VRing, true); 1278 vnetCsLeave(pThis); 1299 1279 } 1300 1280 } 1301 1281 else 1302 1282 { 1303 if (RT_FAILURE(vnetCsEnter(p State, VERR_SEM_BUSY)))1283 if (RT_FAILURE(vnetCsEnter(pThis, VERR_SEM_BUSY))) 1304 1284 LogRel(("vnetQueueTransmit: Failed to enter critical section!/n")); 1305 1285 else 1306 1286 { 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.} 1324 1297 */ 1325 1298 static DECLCALLBACK(void) vnetTxTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser) 1326 1299 { 1327 VNETSTATE *pState = (VNETSTATE*)pvUser;1328 1329 uint32_t u32MicroDiff = (uint32_t)((RTTimeNanoTS() - p State->u64NanoTS)/1000);1330 if (u32MicroDiff < p State->u32MinDiff)1331 p State->u32MinDiff = u32MicroDiff;1332 if (u32MicroDiff > p State->u32MaxDiff)1333 p State->u32MaxDiff = u32MicroDiff;1334 p State->u32AvgDiff = (pState->u32AvgDiff * pState->u32i + u32MicroDiff) / (pState->u32i + 1);1335 p State->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++; 1336 1309 Log3(("vnetTxTimer: Expired, diff %9d usec, avg %9d usec, min %9d usec, max %9d usec\n", 1337 u32MicroDiff, p State->u32AvgDiff, pState->u32MinDiff, pState->u32MaxDiff));1338 1339 // Log3(("%s vnetTxTimer: Expired\n", INSTANCE(p State)));1340 vnetTransmitPendingPackets(p State, pState->pTxQueue, false /*fOnWorkerThread*/);1341 if (RT_FAILURE(vnetCsEnter(p State, 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))) 1342 1315 { 1343 1316 LogRel(("vnetTxTimer: Failed to enter critical section!/n")); 1344 1317 return; 1345 1318 } 1346 vringSetNotification(&p State->VPCI, &pState->pTxQueue->VRing, true);1347 vnetCsLeave(p State);1319 vringSetNotification(&pThis->VPCI, &pThis->pTxQueue->VRing, true); 1320 vnetCsLeave(pThis); 1348 1321 } 1349 1322 … … 1352 1325 static DECLCALLBACK(void) vnetQueueTransmit(void *pvState, PVQUEUE pQueue) 1353 1326 { 1354 VNETSTATE *pState = (VNETSTATE*)pvState;1355 1356 vnetTransmitPendingPackets(p State, pQueue, false /*fOnWorkerThread*/);1327 PVNETSTATE pThis = (PVNETSTATE)pvState; 1328 1329 vnetTransmitPendingPackets(pThis, pQueue, false /*fOnWorkerThread*/); 1357 1330 } 1358 1331 1359 1332 #endif /* !VNET_TX_DELAY */ 1360 1333 1361 static uint8_t vnetControlRx(PVNETSTATE p State, PVNETCTLHDR pCtlHdr, PVQUEUEELEM pElem)1334 static uint8_t vnetControlRx(PVNETSTATE pThis, PVNETCTLHDR pCtlHdr, PVQUEUEELEM pElem) 1362 1335 { 1363 1336 uint8_t u8Ack = VNET_OK; 1364 uint8_t fOn, fDrvWasPromisc = p State->fPromiscuous | pState->fAllMulti;1365 PDMDevHlpPhysRead(p State->VPCI.CTX_SUFF(pDevIns),1337 uint8_t fOn, fDrvWasPromisc = pThis->fPromiscuous | pThis->fAllMulti; 1338 PDMDevHlpPhysRead(pThis->VPCI.CTX_SUFF(pDevIns), 1366 1339 pElem->aSegsOut[1].addr, 1367 1340 &fOn, sizeof(fOn)); 1368 Log(("%s vnetControlRx: uCommand=%u fOn=%u\n", INSTANCE(p State), pCtlHdr->u8Command, fOn));1341 Log(("%s vnetControlRx: uCommand=%u fOn=%u\n", INSTANCE(pThis), pCtlHdr->u8Command, fOn)); 1369 1342 switch (pCtlHdr->u8Command) 1370 1343 { 1371 1344 case VNET_CTRL_CMD_RX_MODE_PROMISC: 1372 p State->fPromiscuous = !!fOn;1345 pThis->fPromiscuous = !!fOn; 1373 1346 break; 1374 1347 case VNET_CTRL_CMD_RX_MODE_ALLMULTI: 1375 p State->fAllMulti = !!fOn;1348 pThis->fAllMulti = !!fOn; 1376 1349 break; 1377 1350 default: 1378 1351 u8Ack = VNET_ERROR; 1379 1352 } 1380 if (fDrvWasPromisc != (p State->fPromiscuous | pState->fAllMulti) && pState->pDrv)1381 p State->pDrv->pfnSetPromiscuousMode(pState->pDrv,1382 (p State->fPromiscuous | pState->fAllMulti));1353 if (fDrvWasPromisc != (pThis->fPromiscuous | pThis->fAllMulti) && pThis->pDrv) 1354 pThis->pDrv->pfnSetPromiscuousMode(pThis->pDrv, 1355 (pThis->fPromiscuous | pThis->fAllMulti)); 1383 1356 1384 1357 return u8Ack; 1385 1358 } 1386 1359 1387 static uint8_t vnetControlMac(PVNETSTATE p State, PVNETCTLHDR pCtlHdr, PVQUEUEELEM pElem)1360 static uint8_t vnetControlMac(PVNETSTATE pThis, PVNETCTLHDR pCtlHdr, PVQUEUEELEM pElem) 1388 1361 { 1389 1362 uint32_t nMacs = 0; … … 1395 1368 { 1396 1369 Log(("%s vnetControlMac: Segment layout is wrong " 1397 "(u8Command=%u nOut=%u cb1=%u cb2=%u)\n", INSTANCE(p State),1370 "(u8Command=%u nOut=%u cb1=%u cb2=%u)\n", INSTANCE(pThis), 1398 1371 pCtlHdr->u8Command, pElem->nOut, 1399 1372 pElem->aSegsOut[1].cb, pElem->aSegsOut[2].cb)); … … 1402 1375 1403 1376 /* Load unicast addresses */ 1404 PDMDevHlpPhysRead(p State->VPCI.CTX_SUFF(pDevIns),1377 PDMDevHlpPhysRead(pThis->VPCI.CTX_SUFF(pDevIns), 1405 1378 pElem->aSegsOut[1].addr, 1406 1379 &nMacs, sizeof(nMacs)); … … 1409 1382 { 1410 1383 Log(("%s vnetControlMac: The unicast mac segment is too small " 1411 "(nMacs=%u cb=%u)\n", INSTANCE(p State), pElem->aSegsOut[1].cb));1384 "(nMacs=%u cb=%u)\n", INSTANCE(pThis), pElem->aSegsOut[1].cb)); 1412 1385 return VNET_ERROR; 1413 1386 } … … 1416 1389 { 1417 1390 Log(("%s vnetControlMac: MAC table is too big, have to use promiscuous" 1418 " mode (nMacs=%u)\n", INSTANCE(p State), nMacs));1419 p State->fPromiscuous = true;1391 " mode (nMacs=%u)\n", INSTANCE(pThis), nMacs)); 1392 pThis->fPromiscuous = true; 1420 1393 } 1421 1394 else 1422 1395 { 1423 1396 if (nMacs) 1424 PDMDevHlpPhysRead(p State->VPCI.CTX_SUFF(pDevIns),1397 PDMDevHlpPhysRead(pThis->VPCI.CTX_SUFF(pDevIns), 1425 1398 pElem->aSegsOut[1].addr + sizeof(nMacs), 1426 p State->aMacFilter, nMacs * sizeof(RTMAC));1427 p State->nMacFilterEntries = nMacs;1399 pThis->aMacFilter, nMacs * sizeof(RTMAC)); 1400 pThis->nMacFilterEntries = nMacs; 1428 1401 #ifdef DEBUG 1429 Log(("%s vnetControlMac: unicast macs:\n", INSTANCE(p State)));1402 Log(("%s vnetControlMac: unicast macs:\n", INSTANCE(pThis))); 1430 1403 for(unsigned i = 0; i < nMacs; i++) 1431 Log((" %RTmac\n", &p State->aMacFilter[i]));1404 Log((" %RTmac\n", &pThis->aMacFilter[i])); 1432 1405 #endif /* DEBUG */ 1433 1406 } 1434 1407 1435 1408 /* Load multicast addresses */ 1436 PDMDevHlpPhysRead(p State->VPCI.CTX_SUFF(pDevIns),1409 PDMDevHlpPhysRead(pThis->VPCI.CTX_SUFF(pDevIns), 1437 1410 pElem->aSegsOut[2].addr, 1438 1411 &nMacs, sizeof(nMacs)); … … 1441 1414 { 1442 1415 Log(("%s vnetControlMac: The multicast mac segment is too small " 1443 "(nMacs=%u cb=%u)\n", INSTANCE(p State), pElem->aSegsOut[2].cb));1416 "(nMacs=%u cb=%u)\n", INSTANCE(pThis), pElem->aSegsOut[2].cb)); 1444 1417 return VNET_ERROR; 1445 1418 } 1446 1419 1447 if (nMacs > VNET_MAC_FILTER_LEN - p State->nMacFilterEntries)1420 if (nMacs > VNET_MAC_FILTER_LEN - pThis->nMacFilterEntries) 1448 1421 { 1449 1422 Log(("%s vnetControlMac: MAC table is too big, have to use allmulti" 1450 " mode (nMacs=%u)\n", INSTANCE(p State), nMacs));1451 p State->fAllMulti = true;1423 " mode (nMacs=%u)\n", INSTANCE(pThis), nMacs)); 1424 pThis->fAllMulti = true; 1452 1425 } 1453 1426 else 1454 1427 { 1455 1428 if (nMacs) 1456 PDMDevHlpPhysRead(p State->VPCI.CTX_SUFF(pDevIns),1429 PDMDevHlpPhysRead(pThis->VPCI.CTX_SUFF(pDevIns), 1457 1430 pElem->aSegsOut[2].addr + sizeof(nMacs), 1458 &p State->aMacFilter[pState->nMacFilterEntries],1431 &pThis->aMacFilter[pThis->nMacFilterEntries], 1459 1432 nMacs * sizeof(RTMAC)); 1460 1433 #ifdef DEBUG 1461 Log(("%s vnetControlMac: multicast macs:\n", INSTANCE(p State)));1434 Log(("%s vnetControlMac: multicast macs:\n", INSTANCE(pThis))); 1462 1435 for(unsigned i = 0; i < nMacs; i++) 1463 1436 Log((" %RTmac\n", 1464 &p State->aMacFilter[i+pState->nMacFilterEntries]));1437 &pThis->aMacFilter[i+pThis->nMacFilterEntries])); 1465 1438 #endif /* DEBUG */ 1466 p State->nMacFilterEntries += nMacs;1439 pThis->nMacFilterEntries += nMacs; 1467 1440 } 1468 1441 … … 1470 1443 } 1471 1444 1472 static uint8_t vnetControlVlan(PVNETSTATE p State, PVNETCTLHDR pCtlHdr, PVQUEUEELEM pElem)1445 static uint8_t vnetControlVlan(PVNETSTATE pThis, PVNETCTLHDR pCtlHdr, PVQUEUEELEM pElem) 1473 1446 { 1474 1447 uint8_t u8Ack = VNET_OK; … … 1478 1451 { 1479 1452 Log(("%s vnetControlVlan: Segment layout is wrong " 1480 "(u8Command=%u nOut=%u cb=%u)\n", INSTANCE(p State),1453 "(u8Command=%u nOut=%u cb=%u)\n", INSTANCE(pThis), 1481 1454 pCtlHdr->u8Command, pElem->nOut, pElem->aSegsOut[1].cb)); 1482 1455 return VNET_ERROR; 1483 1456 } 1484 1457 1485 PDMDevHlpPhysRead(p State->VPCI.CTX_SUFF(pDevIns),1458 PDMDevHlpPhysRead(pThis->VPCI.CTX_SUFF(pDevIns), 1486 1459 pElem->aSegsOut[1].addr, 1487 1460 &u16Vid, sizeof(u16Vid)); … … 1490 1463 { 1491 1464 Log(("%s vnetControlVlan: VLAN ID is out of range " 1492 "(VID=%u)\n", INSTANCE(p State), u16Vid));1465 "(VID=%u)\n", INSTANCE(pThis), u16Vid)); 1493 1466 return VNET_ERROR; 1494 1467 } 1495 1468 1496 Log(("%s vnetControlVlan: uCommand=%u VID=%u\n", INSTANCE(p State),1469 Log(("%s vnetControlVlan: uCommand=%u VID=%u\n", INSTANCE(pThis), 1497 1470 pCtlHdr->u8Command, u16Vid)); 1498 1471 … … 1500 1473 { 1501 1474 case VNET_CTRL_CMD_VLAN_ADD: 1502 ASMBitSet(p State->aVlanFilter, u16Vid);1475 ASMBitSet(pThis->aVlanFilter, u16Vid); 1503 1476 break; 1504 1477 case VNET_CTRL_CMD_VLAN_DEL: 1505 ASMBitClear(p State->aVlanFilter, u16Vid);1478 ASMBitClear(pThis->aVlanFilter, u16Vid); 1506 1479 break; 1507 1480 default: … … 1515 1488 static DECLCALLBACK(void) vnetQueueControl(void *pvState, PVQUEUE pQueue) 1516 1489 { 1517 VNETSTATE *pState = (VNETSTATE*)pvState;1490 PVNETSTATE pThis = (PVNETSTATE)pvState; 1518 1491 uint8_t u8Ack; 1519 1492 VQUEUEELEM elem; 1520 while (vqueueGet(&p State->VPCI, pQueue, &elem))1493 while (vqueueGet(&pThis->VPCI, pQueue, &elem)) 1521 1494 { 1522 1495 unsigned int uOffset = 0; … … 1524 1497 { 1525 1498 Log(("%s vnetQueueControl: The first 'out' segment is not the " 1526 "header! (%u < 1 || %u < %u).\n", INSTANCE(p State), elem.nOut,1499 "header! (%u < 1 || %u < %u).\n", INSTANCE(pThis), elem.nOut, 1527 1500 elem.aSegsOut[0].cb,sizeof(VNETCTLHDR))); 1528 1501 break; /* Skip the element and hope the next one is good. */ … … 1533 1506 Log(("%s vnetQueueControl: The last 'in' segment is too small " 1534 1507 "to hold the acknowledge! (%u < 1 || %u < %u).\n", 1535 INSTANCE(p State), elem.nIn, elem.aSegsIn[elem.nIn - 1].cb,1508 INSTANCE(pThis), elem.nIn, elem.aSegsIn[elem.nIn - 1].cb, 1536 1509 sizeof(VNETCTLACK))); 1537 1510 break; /* Skip the element and hope the next one is good. */ … … 1540 1513 { 1541 1514 VNETCTLHDR CtlHdr; 1542 PDMDevHlpPhysRead(p State->VPCI.CTX_SUFF(pDevIns),1515 PDMDevHlpPhysRead(pThis->VPCI.CTX_SUFF(pDevIns), 1543 1516 elem.aSegsOut[0].addr, 1544 1517 &CtlHdr, sizeof(CtlHdr)); … … 1546 1519 { 1547 1520 case VNET_CTRL_CLS_RX_MODE: 1548 u8Ack = vnetControlRx(p State, &CtlHdr, &elem);1521 u8Ack = vnetControlRx(pThis, &CtlHdr, &elem); 1549 1522 break; 1550 1523 case VNET_CTRL_CLS_MAC: 1551 u8Ack = vnetControlMac(p State, &CtlHdr, &elem);1524 u8Ack = vnetControlMac(pThis, &CtlHdr, &elem); 1552 1525 break; 1553 1526 case VNET_CTRL_CLS_VLAN: 1554 u8Ack = vnetControlVlan(p State, &CtlHdr, &elem);1527 u8Ack = vnetControlVlan(pThis, &CtlHdr, &elem); 1555 1528 break; 1556 1529 default: 1557 1530 u8Ack = VNET_ERROR; 1558 1531 } 1559 Log(("%s Processed control message %u, ack=%u.\n", INSTANCE(p State),1532 Log(("%s Processed control message %u, ack=%u.\n", INSTANCE(pThis), 1560 1533 CtlHdr.u8Class, u8Ack)); 1561 PDMDevHlpPhysWrite(p State->VPCI.CTX_SUFF(pDevIns),1534 PDMDevHlpPhysWrite(pThis->VPCI.CTX_SUFF(pDevIns), 1562 1535 elem.aSegsIn[elem.nIn - 1].addr, 1563 1536 &u8Ack, sizeof(u8Ack)); 1564 1537 } 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 -=-=-=-=- */ 1569 1545 1570 1546 /** 1571 1547 * Saves the configuration. 1572 1548 * 1573 * @param p StateThe VNET state.1549 * @param pThis The VNET state. 1574 1550 * @param pSSM The handle to the saved state. 1575 1551 */ 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 1552 static void vnetSaveConfig(PVNETSTATE pThis, PSSMHANDLE pSSM) 1553 { 1554 SSMR3PutMem(pSSM, &pThis->macConfigured, sizeof(pThis->macConfigured)); 1555 } 1556 1557 1558 /** 1559 * @callback_method_impl{FNSSMDEVLIVEEXEC} 1588 1560 */ 1589 1561 static DECLCALLBACK(int) vnetLiveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uPass) 1590 1562 { 1591 VNETSTATE *pState = PDMINS_2_DATA(pDevIns, VNETSTATE*);1592 vnetSaveConfig(p State, pSSM);1563 PVNETSTATE pThis = PDMINS_2_DATA(pDevIns, PVNETSTATE); 1564 vnetSaveConfig(pThis, pSSM); 1593 1565 return VINF_SSM_DONT_CALL_AGAIN; 1594 1566 } 1595 1567 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} 1602 1571 */ 1603 1572 static DECLCALLBACK(int) vnetSavePrep(PPDMDEVINS pDevIns, PSSMHANDLE pSSM) 1604 1573 { 1605 VNETSTATE* pState = PDMINS_2_DATA(pDevIns, VNETSTATE*);1606 1607 int rc = vnetCsRxEnter(p State, VERR_SEM_BUSY);1574 PVNETSTATE pThis = PDMINS_2_DATA(pDevIns, PVNETSTATE); 1575 1576 int rc = vnetCsRxEnter(pThis, VERR_SEM_BUSY); 1608 1577 if (RT_UNLIKELY(rc != VINF_SUCCESS)) 1609 1578 return rc; 1610 vnetCsRxLeave(p State);1579 vnetCsRxLeave(pThis); 1611 1580 return VINF_SUCCESS; 1612 1581 } 1613 1582 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} 1620 1586 */ 1621 1587 static DECLCALLBACK(int) vnetSaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM) 1622 1588 { 1623 VNETSTATE* pState = PDMINS_2_DATA(pDevIns, VNETSTATE*);1589 PVNETSTATE pThis = PDMINS_2_DATA(pDevIns, PVNETSTATE); 1624 1590 1625 1591 /* Save config first */ 1626 vnetSaveConfig(p State, pSSM);1592 vnetSaveConfig(pThis, pSSM); 1627 1593 1628 1594 /* Save the common part */ 1629 int rc = vpciSaveExec(&p State->VPCI, pSSM);1595 int rc = vpciSaveExec(&pThis->VPCI, pSSM); 1630 1596 AssertRCReturn(rc, rc); 1631 1597 /* Save device-specific part */ 1632 rc = SSMR3PutMem( pSSM, p State->config.mac.au8, sizeof(pState->config.mac));1598 rc = SSMR3PutMem( pSSM, pThis->config.mac.au8, sizeof(pThis->config.mac)); 1633 1599 AssertRCReturn(rc, rc); 1634 rc = SSMR3PutBool(pSSM, p State->fPromiscuous);1600 rc = SSMR3PutBool(pSSM, pThis->fPromiscuous); 1635 1601 AssertRCReturn(rc, rc); 1636 rc = SSMR3PutBool(pSSM, p State->fAllMulti);1602 rc = SSMR3PutBool(pSSM, pThis->fAllMulti); 1637 1603 AssertRCReturn(rc, rc); 1638 rc = SSMR3PutU32( pSSM, p State->nMacFilterEntries);1604 rc = SSMR3PutU32( pSSM, pThis->nMacFilterEntries); 1639 1605 AssertRCReturn(rc, rc); 1640 rc = SSMR3PutMem( pSSM, p State->aMacFilter,1641 p State->nMacFilterEntries * sizeof(RTMAC));1606 rc = SSMR3PutMem( pSSM, pThis->aMacFilter, 1607 pThis->nMacFilterEntries * sizeof(RTMAC)); 1642 1608 AssertRCReturn(rc, rc); 1643 rc = SSMR3PutMem( pSSM, p State->aVlanFilter, sizeof(pState->aVlanFilter));1609 rc = SSMR3PutMem( pSSM, pThis->aVlanFilter, sizeof(pThis->aVlanFilter)); 1644 1610 AssertRCReturn(rc, rc); 1645 Log(("%s State has been saved\n", INSTANCE(p State)));1611 Log(("%s State has been saved\n", INSTANCE(pThis))); 1646 1612 return VINF_SUCCESS; 1647 1613 } … … 1649 1615 1650 1616 /** 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. } 1656 1619 */ 1657 1620 static DECLCALLBACK(int) vnetLoadPrep(PPDMDEVINS pDevIns, PSSMHANDLE pSSM) 1658 1621 { 1659 VNETSTATE* pState = PDMINS_2_DATA(pDevIns, VNETSTATE*);1660 1661 int rc = vnetCsRxEnter(p State, VERR_SEM_BUSY);1622 PVNETSTATE pThis = PDMINS_2_DATA(pDevIns, PVNETSTATE); 1623 1624 int rc = vnetCsRxEnter(pThis, VERR_SEM_BUSY); 1662 1625 if (RT_UNLIKELY(rc != VINF_SUCCESS)) 1663 1626 return rc; 1664 vnetCsRxLeave(p State);1627 vnetCsRxLeave(pThis); 1665 1628 return VINF_SUCCESS; 1666 1629 } 1630 1667 1631 1668 1632 /** … … 1675 1639 * renegotiate any DHCP lease. 1676 1640 * 1677 * @param pThis The PCNet instance data.1678 */ 1679 static void vnetTempLinkDown(PVNETSTATE p State)1641 * @param pThis The Virtual I/O network device state. 1642 */ 1643 static void vnetTempLinkDown(PVNETSTATE pThis) 1680 1644 { 1681 1645 if (STATUS & VNET_S_LINK_UP) 1682 1646 { 1683 1647 STATUS &= ~VNET_S_LINK_UP; 1684 vpciRaiseInterrupt(&p State->VPCI, VERR_SEM_BUSY, VPCI_ISR_CONFIG);1648 vpciRaiseInterrupt(&pThis->VPCI, VERR_SEM_BUSY, VPCI_ISR_CONFIG); 1685 1649 /* Restore the link back in 5 seconds. */ 1686 int rc = TMTimerSetMillies(p State->pLinkUpTimer, pState->cMsLinkUpDelay);1650 int rc = TMTimerSetMillies(pThis->pLinkUpTimer, pThis->cMsLinkUpDelay); 1687 1651 AssertRC(rc); 1688 1652 } … … 1691 1655 1692 1656 /** 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} 1700 1658 */ 1701 1659 static DECLCALLBACK(int) vnetLoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass) 1702 1660 { 1703 VNETSTATE *pState = PDMINS_2_DATA(pDevIns, VNETSTATE*);1661 PVNETSTATE pThis = PDMINS_2_DATA(pDevIns, PVNETSTATE); 1704 1662 int rc; 1705 1663 … … 1708 1666 rc = SSMR3GetMem(pSSM, &macConfigured, sizeof(macConfigured)); 1709 1667 AssertRCReturn(rc, rc); 1710 if (memcmp(&macConfigured, &p State->macConfigured, sizeof(macConfigured))1668 if (memcmp(&macConfigured, &pThis->macConfigured, sizeof(macConfigured)) 1711 1669 && (uPass == 0 || !PDMDevHlpVMTeleportedAndNotFullyResumedYet(pDevIns))) 1712 LogRel(("%s: The mac address differs: config=%RTmac saved=%RTmac\n", INSTANCE(p State), &pState->macConfigured, &macConfigured));1713 1714 rc = vpciLoadExec(&p State->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); 1715 1673 AssertRCReturn(rc, rc); 1716 1674 1717 1675 if (uPass == SSM_PASS_FINAL) 1718 1676 { 1719 rc = SSMR3GetMem( pSSM, p State->config.mac.au8,1720 sizeof(p State->config.mac));1677 rc = SSMR3GetMem( pSSM, pThis->config.mac.au8, 1678 sizeof(pThis->config.mac)); 1721 1679 AssertRCReturn(rc, rc); 1722 1680 1723 1681 if (uVersion > VIRTIO_SAVEDSTATE_VERSION_3_1_BETA1) 1724 1682 { 1725 rc = SSMR3GetBool(pSSM, &p State->fPromiscuous);1683 rc = SSMR3GetBool(pSSM, &pThis->fPromiscuous); 1726 1684 AssertRCReturn(rc, rc); 1727 rc = SSMR3GetBool(pSSM, &p State->fAllMulti);1685 rc = SSMR3GetBool(pSSM, &pThis->fAllMulti); 1728 1686 AssertRCReturn(rc, rc); 1729 rc = SSMR3GetU32(pSSM, &p State->nMacFilterEntries);1687 rc = SSMR3GetU32(pSSM, &pThis->nMacFilterEntries); 1730 1688 AssertRCReturn(rc, rc); 1731 rc = SSMR3GetMem(pSSM, p State->aMacFilter,1732 p State->nMacFilterEntries * sizeof(RTMAC));1689 rc = SSMR3GetMem(pSSM, pThis->aMacFilter, 1690 pThis->nMacFilterEntries * sizeof(RTMAC)); 1733 1691 AssertRCReturn(rc, rc); 1734 1692 /* Clear the rest. */ 1735 if (p State->nMacFilterEntries < VNET_MAC_FILTER_LEN)1736 memset(&p State->aMacFilter[pState->nMacFilterEntries],1693 if (pThis->nMacFilterEntries < VNET_MAC_FILTER_LEN) 1694 memset(&pThis->aMacFilter[pThis->nMacFilterEntries], 1737 1695 0, 1738 (VNET_MAC_FILTER_LEN - p State->nMacFilterEntries)1696 (VNET_MAC_FILTER_LEN - pThis->nMacFilterEntries) 1739 1697 * sizeof(RTMAC)); 1740 rc = SSMR3GetMem(pSSM, p State->aVlanFilter,1741 sizeof(p State->aVlanFilter));1698 rc = SSMR3GetMem(pSSM, pThis->aVlanFilter, 1699 sizeof(pThis->aVlanFilter)); 1742 1700 AssertRCReturn(rc, rc); 1743 1701 } 1744 1702 else 1745 1703 { 1746 p State->fPromiscuous = true;1747 p State->fAllMulti = false;1748 p State->nMacFilterEntries = 0;1749 memset(p State->aMacFilter, 0, VNET_MAC_FILTER_LEN * sizeof(RTMAC));1750 memset(p State->aVlanFilter, 0, sizeof(pState->aVlanFilter));1751 if (p State->pDrv)1752 p State->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); 1753 1711 } 1754 1712 } … … 1757 1715 } 1758 1716 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.} 1765 1721 */ 1766 1722 static DECLCALLBACK(int) vnetLoadDone(PPDMDEVINS pDevIns, PSSMHANDLE pSSM) 1767 1723 { 1768 VNETSTATE *pState = PDMINS_2_DATA(pDevIns, VNETSTATE*);1769 1770 if (p State->pDrv)1771 p State->pDrv->pfnSetPromiscuousMode(pState->pDrv,1772 (p State->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)); 1773 1729 /* 1774 1730 * Indicate link down to the guest OS that all network connections have … … 1776 1732 */ 1777 1733 if (!PDMDevHlpVMTeleportedAndNotFullyResumedYet(pDevIns)) 1778 vnetTempLinkDown(p State);1734 vnetTempLinkDown(pThis); 1779 1735 1780 1736 return VINF_SUCCESS; 1781 1737 } 1782 1738 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} 1795 1744 */ 1796 1745 static DECLCALLBACK(int) vnetMap(PPCIDEVICE pPciDev, int iRegion, 1797 1746 RTGCPHYS GCPhysAddress, uint32_t cb, PCIADDRESSSPACE enmType) 1798 1747 { 1748 PVNETSTATE pThis = PDMINS_2_DATA(pPciDev->pDevIns, PVNETSTATE); 1799 1749 int rc; 1800 VNETSTATE *pState = PDMINS_2_DATA(pPciDev->pDevIns, VNETSTATE*);1801 1750 1802 1751 if (enmType != PCI_ADDRESS_SPACE_IO) … … 1807 1756 } 1808 1757 1809 p State->VPCI.addrIOPort = (RTIOPORT)GCPhysAddress;1810 rc = PDMDevHlpIOPortRegister(pPciDev->pDevIns, p State->VPCI.addrIOPort,1758 pThis->VPCI.addrIOPort = (RTIOPORT)GCPhysAddress; 1759 rc = PDMDevHlpIOPortRegister(pPciDev->pDevIns, pThis->VPCI.addrIOPort, 1811 1760 cb, 0, vnetIOPortOut, vnetIOPortIn, 1812 1761 NULL, NULL, "VirtioNet"); 1813 1762 #ifdef VNET_GC_SUPPORT 1814 1763 AssertRCReturn(rc, rc); 1815 rc = PDMDevHlpIOPortRegisterR0(pPciDev->pDevIns, p State->VPCI.addrIOPort,1764 rc = PDMDevHlpIOPortRegisterR0(pPciDev->pDevIns, pThis->VPCI.addrIOPort, 1816 1765 cb, 0, "vnetIOPortOut", "vnetIOPortIn", 1817 1766 NULL, NULL, "VirtioNet"); 1818 1767 AssertRCReturn(rc, rc); 1819 rc = PDMDevHlpIOPortRegisterRC(pPciDev->pDevIns, p State->VPCI.addrIOPort,1768 rc = PDMDevHlpIOPortRegisterRC(pPciDev->pDevIns, pThis->VPCI.addrIOPort, 1820 1769 cb, 0, "vnetIOPortOut", "vnetIOPortIn", 1821 1770 NULL, NULL, "VirtioNet"); … … 1829 1778 1830 1779 /** 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} 1838 1781 */ 1839 1782 static DECLCALLBACK(void) vnetDetach(PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags) 1840 1783 { 1841 VNETSTATE *pState = PDMINS_2_DATA(pDevIns, VNETSTATE*);1842 Log(("%s vnetDetach:\n", INSTANCE(p State)));1784 PVNETSTATE pThis = PDMINS_2_DATA(pDevIns, PVNETSTATE); 1785 Log(("%s vnetDetach:\n", INSTANCE(pThis))); 1843 1786 1844 1787 AssertLogRelReturnVoid(iLUN == 0); 1845 1788 1846 int rc = vnetCsEnter(p State, VERR_SEM_BUSY);1789 int rc = vnetCsEnter(pThis, VERR_SEM_BUSY); 1847 1790 if (RT_FAILURE(rc)) 1848 1791 { … … 1854 1797 * Zero some important members. 1855 1798 */ 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} 1873 1808 */ 1874 1809 static DECLCALLBACK(int) vnetAttach(PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags) 1875 1810 { 1876 VNETSTATE *pState = PDMINS_2_DATA(pDevIns, VNETSTATE*);1877 LogFlow(("%s vnetAttach:\n", INSTANCE(p State)));1811 PVNETSTATE pThis = PDMINS_2_DATA(pDevIns, PVNETSTATE); 1812 LogFlow(("%s vnetAttach:\n", INSTANCE(pThis))); 1878 1813 1879 1814 AssertLogRelReturn(iLUN == 0, VERR_PDM_NO_SUCH_LUN); 1880 1815 1881 int rc = vnetCsEnter(p State, VERR_SEM_BUSY);1816 int rc = vnetCsEnter(pThis, VERR_SEM_BUSY); 1882 1817 if (RT_FAILURE(rc)) 1883 1818 { … … 1889 1824 * Attach the driver. 1890 1825 */ 1891 rc = PDMDevHlpDriverAttach(pDevIns, 0, &p State->VPCI.IBase, &pState->pDrvBase, "Network Port");1826 rc = PDMDevHlpDriverAttach(pDevIns, 0, &pThis->VPCI.IBase, &pThis->pDrvBase, "Network Port"); 1892 1827 if (RT_SUCCESS(rc)) 1893 1828 { … … 1902 1837 #endif 1903 1838 } 1904 p State->pDrv = PDMIBASE_QUERY_INTERFACE(pState->pDrvBase, PDMINETWORKUP);1905 AssertMsgStmt(p State->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"), 1906 1841 rc = VERR_PDM_MISSING_INTERFACE_BELOW); 1907 1842 } … … 1911 1846 /* This should never happen because this function is not called 1912 1847 * if there is no driver to attach! */ 1913 Log(("%s No attached driver!\n", INSTANCE(p State)));1848 Log(("%s No attached driver!\n", INSTANCE(pThis))); 1914 1849 } 1915 1850 … … 1920 1855 */ 1921 1856 if (RT_SUCCESS(rc)) 1922 vnetTempLinkDown(p State);1923 1924 vnetCsLeave(p State);1857 vnetTempLinkDown(pThis); 1858 1859 vnetCsLeave(pThis); 1925 1860 return rc; 1926 1861 1927 1862 } 1928 1863 1929 /** 1930 * @copydoc FNPDMDEVSUSPEND 1864 1865 /** 1866 * @interface_method_impl{PDMDEVREG,pfnSuspend} 1931 1867 */ 1932 1868 static DECLCALLBACK(void) vnetSuspend(PPDMDEVINS pDevIns) … … 1936 1872 } 1937 1873 1938 /** 1939 * @copydoc FNPDMDEVPOWEROFF 1874 1875 /** 1876 * @interface_method_impl{PDMDEVREG,pfnPowerOff} 1940 1877 */ 1941 1878 static DECLCALLBACK(void) vnetPowerOff(PPDMDEVINS pDevIns) … … 1945 1882 } 1946 1883 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} 1962 1887 */ 1963 1888 static DECLCALLBACK(void) vnetRelocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta) 1964 1889 { 1965 VNETSTATE* pState = PDMINS_2_DATA(pDevIns, VNETSTATE*);1890 PVNETSTATE pThis = PDMINS_2_DATA(pDevIns, PVNETSTATE); 1966 1891 vpciRelocate(pDevIns, offDelta); 1967 p State->pCanRxQueueRC = PDMQueueRCPtr(pState->pCanRxQueueR3);1892 pThis->pCanRxQueueRC = PDMQueueRCPtr(pThis->pCanRxQueueR3); 1968 1893 #ifdef VNET_TX_DELAY 1969 p State->pTxTimerRC = TMTimerRCPtr(pState->pTxTimerR3);1894 pThis->pTxTimerRC = TMTimerRCPtr(pThis->pTxTimerR3); 1970 1895 #endif /* VNET_TX_DELAY */ 1971 1896 // TBD 1972 1897 } 1973 1898 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} 1982 1902 */ 1983 1903 static DECLCALLBACK(int) vnetDestruct(PPDMDEVINS pDevIns) 1984 1904 { 1985 VNETSTATE* pState = PDMINS_2_DATA(pDevIns, VNETSTATE*);1905 PVNETSTATE pThis = PDMINS_2_DATA(pDevIns, PVNETSTATE); 1986 1906 PDMDEV_CHECK_VERSIONS_RETURN_QUIET(pDevIns); 1987 1907 1988 1908 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 2003 1924 2004 1925 /** … … 2007 1928 static DECLCALLBACK(int) vnetConstruct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg) 2008 1929 { 2009 VNETSTATE* pState = PDMINS_2_DATA(pDevIns, VNETSTATE*);1930 PVNETSTATE pThis = PDMINS_2_DATA(pDevIns, PVNETSTATE); 2010 1931 int rc; 2011 1932 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns); 2012 1933 2013 1934 /* Initialize PCI part first. */ 2014 p State->VPCI.IBase.pfnQueryInterface = vnetQueryInterface;2015 rc = vpciConstruct(pDevIns, &p State->VPCI, iInstance,1935 pThis->VPCI.IBase.pfnQueryInterface = vnetQueryInterface; 1936 rc = vpciConstruct(pDevIns, &pThis->VPCI, iInstance, 2016 1937 VNET_NAME_FMT, VNET_PCI_SUBSYSTEM_ID, 2017 1938 VNET_PCI_CLASS, VNET_N_QUEUES); 2018 p State->pRxQueue = vpciAddQueue(&pState->VPCI, 256, vnetQueueReceive, "RX ");2019 p State->pTxQueue = vpciAddQueue(&pState->VPCI, 256, vnetQueueTransmit, "TX ");2020 p State->pCtlQueue = vpciAddQueue(&pState->VPCI, 16, vnetQueueControl, "CTL");2021 2022 Log(("%s Constructing new instance\n", INSTANCE(p State)));2023 2024 p State->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; 2025 1946 2026 1947 /* … … 2032 1953 2033 1954 /* Get config params */ 2034 rc = CFGMR3QueryBytes(pCfg, "MAC", p State->macConfigured.au8,2035 sizeof(p State->macConfigured));1955 rc = CFGMR3QueryBytes(pCfg, "MAC", pThis->macConfigured.au8, 1956 sizeof(pThis->macConfigured)); 2036 1957 if (RT_FAILURE(rc)) 2037 1958 return PDMDEV_SET_ERROR(pDevIns, rc, 2038 1959 N_("Configuration error: Failed to get MAC address")); 2039 rc = CFGMR3QueryBool(pCfg, "CableConnected", &p State->fCableConnected);1960 rc = CFGMR3QueryBool(pCfg, "CableConnected", &pThis->fCableConnected); 2040 1961 if (RT_FAILURE(rc)) 2041 1962 return PDMDEV_SET_ERROR(pDevIns, rc, 2042 1963 N_("Configuration error: Failed to get the value of 'CableConnected'")); 2043 rc = CFGMR3QueryU32Def(pCfg, "LinkUpDelay", (uint32_t*)&p State->cMsLinkUpDelay, 5000); /* ms */1964 rc = CFGMR3QueryU32Def(pCfg, "LinkUpDelay", (uint32_t*)&pThis->cMsLinkUpDelay, 5000); /* ms */ 2044 1965 if (RT_FAILURE(rc)) 2045 1966 return PDMDEV_SET_ERROR(pDevIns, rc, 2046 1967 N_("Configuration error: Failed to get the value of 'LinkUpDelay'")); 2047 Assert(p State->cMsLinkUpDelay <= 300000); /* less than 5 minutes */2048 if (p State->cMsLinkUpDelay > 5000 || pState->cMsLinkUpDelay < 100)1968 Assert(pThis->cMsLinkUpDelay <= 300000); /* less than 5 minutes */ 1969 if (pThis->cMsLinkUpDelay > 5000 || pThis->cMsLinkUpDelay < 100) 2049 1970 { 2050 1971 LogRel(("%s WARNING! Link up delay is set to %u seconds!\n", 2051 INSTANCE(p State), pState->cMsLinkUpDelay / 1000));1972 INSTANCE(pThis), pThis->cMsLinkUpDelay / 1000)); 2052 1973 } 2053 1974 Log(("%s Link up delay is set to %u seconds\n", 2054 INSTANCE(p State), pState->cMsLinkUpDelay / 1000));2055 2056 2057 vnetPrintFeatures(p State, 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"); 2058 1979 2059 1980 /* Initialize PCI config space */ 2060 memcpy(p State->config.mac.au8, pState->macConfigured.au8, sizeof(pState->config.mac.au8));2061 p State->config.uStatus = 0;1981 memcpy(pThis->config.mac.au8, pThis->macConfigured.au8, sizeof(pThis->config.mac.au8)); 1982 pThis->config.uStatus = 0; 2062 1983 2063 1984 /* Initialize state structure */ 2064 p State->u32PktNo = 1;1985 pThis->u32PktNo = 1; 2065 1986 2066 1987 /* Interfaces */ 2067 p State->INetworkDown.pfnWaitReceiveAvail = vnetNetworkDown_WaitReceiveAvail;2068 p State->INetworkDown.pfnReceive = vnetNetworkDown_Receive;2069 p State->INetworkDown.pfnReceiveGso = vnetNetworkDown_ReceiveGso;2070 p State->INetworkDown.pfnXmitPending = vnetNetworkDown_XmitPending;2071 2072 p State->INetworkConfig.pfnGetMac = vnetGetMac;2073 p State->INetworkConfig.pfnGetLinkState = vnetGetLinkState;2074 p State->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; 2075 1996 2076 1997 /* Initialize critical section. */ 2077 // char szTmp[sizeof(p State->VPCI.szInstance) + 2];2078 // RTStrPrintf(szTmp, sizeof(szTmp), "%sRX", p State->VPCI.szInstance);2079 // rc = PDMDevHlpCritSectInit(pDevIns, &p State->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); 2080 2001 // if (RT_FAILURE(rc)) 2081 2002 // return rc; … … 2099 2020 /* Create the RX notifier signaller. */ 2100 2021 rc = PDMDevHlpQueueCreate(pDevIns, sizeof(PDMQUEUEITEMCORE), 1, 0, 2101 vnetCanRxQueueConsumer, true, "VNet-Rcv", &p State->pCanRxQueueR3);2022 vnetCanRxQueueConsumer, true, "VNet-Rcv", &pThis->pCanRxQueueR3); 2102 2023 if (RT_FAILURE(rc)) 2103 2024 return rc; 2104 p State->pCanRxQueueR0 = PDMQueueR0Ptr(pState->pCanRxQueueR3);2105 p State->pCanRxQueueRC = PDMQueueRCPtr(pState->pCanRxQueueR3);2025 pThis->pCanRxQueueR0 = PDMQueueR0Ptr(pThis->pCanRxQueueR3); 2026 pThis->pCanRxQueueRC = PDMQueueRCPtr(pThis->pCanRxQueueR3); 2106 2027 2107 2028 /* Create Link Up Timer */ 2108 rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL, vnetLinkUpTimer, p State,2029 rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL, vnetLinkUpTimer, pThis, 2109 2030 TMTIMER_FLAGS_NO_CRIT_SECT, 2110 "VirtioNet Link Up Timer", &p State->pLinkUpTimer);2031 "VirtioNet Link Up Timer", &pThis->pLinkUpTimer); 2111 2032 if (RT_FAILURE(rc)) 2112 2033 return rc; … … 2114 2035 #ifdef VNET_TX_DELAY 2115 2036 /* Create Transmit Delay Timer */ 2116 rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL, vnetTxTimer, p State,2037 rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL, vnetTxTimer, pThis, 2117 2038 TMTIMER_FLAGS_NO_CRIT_SECT, 2118 "VirtioNet TX Delay Timer", &p State->pTxTimerR3);2039 "VirtioNet TX Delay Timer", &pThis->pTxTimerR3); 2119 2040 if (RT_FAILURE(rc)) 2120 2041 return rc; 2121 p State->pTxTimerR0 = TMTimerR0Ptr(pState->pTxTimerR3);2122 p State->pTxTimerRC = TMTimerRCPtr(pState->pTxTimerR3);2123 2124 p State->u32i = pState->u32AvgDiff = pState->u32MaxDiff = 0;2125 p State->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; 2126 2047 #endif /* VNET_TX_DELAY */ 2127 2048 2128 rc = PDMDevHlpDriverAttach(pDevIns, 0, &p State->VPCI.IBase, &pState->pDrvBase, "Network Port");2049 rc = PDMDevHlpDriverAttach(pDevIns, 0, &pThis->VPCI.IBase, &pThis->pDrvBase, "Network Port"); 2129 2050 if (RT_SUCCESS(rc)) 2130 2051 { … … 2134 2055 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")); 2135 2056 } 2136 p State->pDrv = PDMIBASE_QUERY_INTERFACE(pState->pDrvBase, PDMINETWORKUP);2137 AssertMsgReturn(p State->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"), 2138 2059 VERR_PDM_MISSING_INTERFACE_BELOW); 2139 2060 } … … 2142 2063 { 2143 2064 /* No error! */ 2144 Log(("%s This adapter is not attached to any network!\n", INSTANCE(p State)));2065 Log(("%s This adapter is not attached to any network!\n", INSTANCE(pThis))); 2145 2066 } 2146 2067 else 2147 2068 return PDMDEV_SET_ERROR(pDevIns, rc, N_("Failed to attach the network LUN")); 2148 2069 2149 rc = RTSemEventCreate(&p State->hEventMoreRxDescAvail);2070 rc = RTSemEventCreate(&pThis->hEventMoreRxDescAvail); 2150 2071 if (RT_FAILURE(rc)) 2151 2072 return rc; 2152 2073 2153 rc = vnetReset(p State);2074 rc = vnetReset(pThis); 2154 2075 AssertRC(rc); 2155 2076 2156 PDMDevHlpSTAMRegisterF(pDevIns, &p State->StatReceiveBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Amount of data received", "/Devices/VNet%d/ReceiveBytes", iInstance);2157 PDMDevHlpSTAMRegisterF(pDevIns, &p State->StatTransmitBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Amount of data transmitted", "/Devices/VNet%d/TransmitBytes", iInstance);2158 PDMDevHlpSTAMRegisterF(pDevIns, &p State->StatReceiveGSO, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of received GSO packets", "/Devices/VNet%d/Packets/ReceiveGSO", iInstance);2159 PDMDevHlpSTAMRegisterF(pDevIns, &p State->StatTransmitPackets, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of sent packets", "/Devices/VNet%d/Packets/Transmit", iInstance);2160 PDMDevHlpSTAMRegisterF(pDevIns, &p State->StatTransmitGSO, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of sent GSO packets", "/Devices/VNet%d/Packets/Transmit-Gso", iInstance);2161 PDMDevHlpSTAMRegisterF(pDevIns, &p State->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); 2162 2083 #if defined(VBOX_WITH_STATISTICS) 2163 PDMDevHlpSTAMRegisterF(pDevIns, &p State->StatReceive, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling receive", "/Devices/VNet%d/Receive/Total", iInstance);2164 PDMDevHlpSTAMRegisterF(pDevIns, &p State->StatReceiveStore, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling receive storing", "/Devices/VNet%d/Receive/Store", iInstance);2165 PDMDevHlpSTAMRegisterF(pDevIns, &p State->StatRxOverflow, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_OCCURENCE, "Profiling RX overflows", "/Devices/VNet%d/RxOverflow", iInstance);2166 PDMDevHlpSTAMRegisterF(pDevIns, &p State->StatRxOverflowWakeup, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, "Nr of RX overflow wakeups", "/Devices/VNet%d/RxOverflowWakeup", iInstance);2167 PDMDevHlpSTAMRegisterF(pDevIns, &p State->StatTransmit, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling transmits in HC", "/Devices/VNet%d/Transmit/Total", iInstance);2168 PDMDevHlpSTAMRegisterF(pDevIns, &p State->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); 2169 2090 #endif /* VBOX_WITH_STATISTICS */ 2170 2091 -
trunk/src/VBox/Devices/VirtIO/Virtio.cpp
r44528 r44849 308 308 * @param pDevIns The device instance. 309 309 * @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. 311 311 * @param pu32 Where to store the result. 312 312 * @param cb Number of bytes read. … … 315 315 int vpciIOPortIn(PPDMDEVINS pDevIns, 316 316 void *pvUser, 317 RTIOPORT port,317 RTIOPORT Port, 318 318 uint32_t *pu32, 319 319 unsigned cb, … … 342 342 }*/ 343 343 344 port -= pState->addrIOPort;345 switch ( port)344 Port -= pState->addrIOPort; 345 switch (Port) 346 346 { 347 347 case VPCI_HOST_FEATURES: … … 382 382 383 383 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); 388 386 else 389 387 { 390 388 *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); 394 391 } 395 392 break; 396 393 } 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)); 399 395 STAM_PROFILE_ADV_STOP(&pState->CTXSUFF(StatIORead), a); 400 396 //vpciCsLeave(pState); … … 413 409 * @param u32 The value to output. 414 410 * @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. 415 413 * @thread EMT 416 414 */ 417 415 int vpciIOPortOut(PPDMDEVINS pDevIns, 418 416 void *pvUser, 419 RTIOPORT port,417 RTIOPORT Port, 420 418 uint32_t u32, 421 419 unsigned cb, … … 434 432 STAM_PROFILE_ADV_START(&pState->CTXSUFF(StatIOWrite), a); 435 433 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) 440 438 { 441 439 case VPCI_GUEST_FEATURES: … … 521 519 522 520 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); 525 523 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); 527 526 break; 528 527 } -
trunk/src/VBox/Devices/VirtIO/Virtio.h
r44529 r44849 5 5 6 6 /* 7 * Copyright (C) 2009-201 2Oracle Corporation7 * Copyright (C) 2009-2013 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 21 21 #include <iprt/ctype.h> 22 22 23 #define VIRTIO_RELOCATE(p, o) *(RTHCUINTPTR *)&p += o 24 25 /* 23 24 /** @name Saved state versions. 26 25 * The saved state version is changed if either common or any of specific 27 26 * parts are changed. That is, it is perfectly possible that the version … … 31 30 #define VIRTIO_SAVEDSTATE_VERSION_3_1_BETA1 1 32 31 #define VIRTIO_SAVEDSTATE_VERSION 2 32 /** @} */ 33 33 34 34 #define DEVICE_PCI_VENDOR_ID 0x1AF4 … … 63 63 #define VRINGDESC_F_WRITE 0x02 64 64 65 struct VRingDesc65 typedef struct VRingDesc 66 66 { 67 67 uint64_t u64Addr; … … 69 69 uint16_t u16Flags; 70 70 uint16_t u16Next; 71 }; 72 typedef struct VRingDesc VRINGDESC; 71 } VRINGDESC; 73 72 typedef VRINGDESC *PVRINGDESC; 74 73 75 74 #define VRINGAVAIL_F_NO_INTERRUPT 0x01 76 75 77 struct VRingAvail76 typedef struct VRingAvail 78 77 { 79 78 uint16_t uFlags; 80 79 uint16_t uNextFreeIndex; 81 80 uint16_t auRing[1]; 82 }; 83 typedef struct VRingAvail VRINGAVAIL; 84 85 struct VRingUsedElem 81 } VRINGAVAIL; 82 83 typedef struct VRingUsedElem 86 84 { 87 85 uint32_t uId; 88 86 uint32_t uLen; 89 }; 90 typedef struct VRingUsedElem VRINGUSEDELEM; 87 } VRINGUSEDELEM; 91 88 92 89 #define VRINGUSED_F_NO_NOTIFY 0x01 93 90 94 struct VRingUsed91 typedef struct VRingUsed 95 92 { 96 93 uint16_t uFlags; 97 94 uint16_t uIndex; 98 95 VRINGUSEDELEM aRing[1]; 99 }; 100 typedef struct VRingUsed VRINGUSED; 96 } VRINGUSED; 101 97 typedef VRINGUSED *PVRINGUSED; 102 98 103 99 #define VRING_MAX_SIZE 1024 104 100 105 struct VRing101 typedef struct VRing 106 102 { 107 103 uint16_t uSize; … … 110 106 RTGCPHYS addrAvail; 111 107 RTGCPHYS addrUsed; 112 }; 113 typedef struct VRing VRING; 108 } VRING; 114 109 typedef VRING *PVRING; 115 110 116 struct VQueue111 typedef struct VQueue 117 112 { 118 113 VRING VRing; … … 126 121 #endif 127 122 R3PTRTYPE(const char *) pcszName; 128 }; 129 typedef struct VQueue VQUEUE; 123 } VQUEUE; 130 124 typedef VQUEUE *PVQUEUE; 131 125 132 struct VQueueElemSeg126 typedef struct VQueueElemSeg 133 127 { 134 128 RTGCPHYS addr; 135 129 void *pv; 136 130 uint32_t cb; 137 }; 138 typedef struct VQueueElemSeg VQUEUESEG; 139 140 struct VQueueElem 131 } VQUEUESEG; 132 133 typedef struct VQueueElem 141 134 { 142 135 uint32_t uIndex; … … 145 138 VQUEUESEG aSegsIn[VRING_MAX_SIZE]; 146 139 VQUEUESEG aSegsOut[VRING_MAX_SIZE]; 147 }; 148 typedef struct VQueueElem VQUEUEELEM; 140 } VQUEUEELEM; 149 141 typedef VQUEUEELEM *PVQUEUEELEM; 150 142 … … 159 151 160 152 /** 161 * The state of the VirtIO PCI device153 * The core (/common) state of the VirtIO PCI device 162 154 * 163 155 * @implements PDMILEDPORTS 164 156 */ 165 struct VPCIState_st157 typedef struct VPCIState_st 166 158 { 167 159 PDMCRITSECT cs; /**< Critical section - what is it protecting? */ … … 219 211 STAMPROFILE StatCsHC; 220 212 #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. */ 223 215 typedef VPCISTATE *PVPCISTATE; 224 216 225 /* Callbacks *****************************************************************/ 217 /** @name Callbacks 218 * @{ */ 226 219 typedef uint32_t (*PFNGETHOSTFEATURES)(void *pState); 227 220 typedef uint32_t (*PFNGETHOSTMINIMALFEATURES)(void *pState); … … 231 224 typedef int (*PFNRESET)(void *pState); 232 225 typedef void (*PFNREADY)(void *pState); 233 /** ***************************************************************************/226 /** @} */ 234 227 235 228 int vpciRaiseInterrupt(VPCISTATE *pState, int rcBusy, uint8_t u8IntCause); … … 326 319 } 327 320 328 #endif /* ___VBox_Virtio_h */321 #endif /* !___VBox_Virtio_h */
Note:
See TracChangeset
for help on using the changeset viewer.