Changeset 25148 in vbox for trunk/src/VBox/Devices/Network
- Timestamp:
- Dec 2, 2009 2:20:41 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/DevVirtioNet.cpp
r24982 r25148 114 114 VPCISTATE VPCI; 115 115 116 PDMCRITSECT csRx; /**< Protects RX queue. */ 117 116 118 PDMINETWORKPORT INetworkPort; 117 119 PDMINETWORKCONFIG INetworkConfig; … … 250 252 } 251 253 254 DECLINLINE(int) vnetCsRxEnter(PVNETSTATE pState, int rcBusy) 255 { 256 return PDMCritSectEnter(&pState->csRx, rcBusy); 257 } 258 259 DECLINLINE(void) vnetCsRxLeave(PVNETSTATE pState) 260 { 261 PDMCritSectLeave(&pState->csRx); 262 } 263 252 264 253 265 PDMBOTHCBDECL(uint32_t) vnetGetHostFeatures(void *pvState) … … 313 325 VNETSTATE *pState = (VNETSTATE*)pvState; 314 326 Log(("%s Reset triggered\n", INSTANCE(pState))); 327 328 int rc = vnetCsRxEnter(pState, VERR_SEM_BUSY); 329 if (RT_UNLIKELY(rc != VINF_SUCCESS)) 330 { 331 LogRel(("vnetReset failed to enter RX critical section!\n")); 332 return; 333 } 315 334 vpciReset(&pState->VPCI); 335 vnetCsRxLeave(pState); 336 316 337 // TODO: Implement reset 317 338 if (pState->fCableConnected) … … 358 379 VNETSTATE *pState = (VNETSTATE *)pvUser; 359 380 381 int rc = vnetCsEnter(pState, VERR_SEM_BUSY); 382 if (RT_UNLIKELY(rc != VINF_SUCCESS)) 383 return; 360 384 STATUS |= VNET_S_LINK_UP; 361 385 vpciRaiseInterrupt(&pState->VPCI, VERR_SEM_BUSY, VPCI_ISR_CONFIG); 362 386 vnetWakeupReceive(pDevIns); 387 vnetCsLeave(pState); 363 388 } 364 389 … … 457 482 static int vnetCanReceive(VNETSTATE *pState) 458 483 { 459 int rc = vnetCsEnter(pState, VERR_SEM_BUSY); 484 int rc = vnetCsRxEnter(pState, VERR_SEM_BUSY); 485 AssertRCReturn(rc, rc); 486 460 487 LogFlow(("%s vnetCanReceive\n", INSTANCE(pState))); 461 488 if (!(pState->VPCI.uStatus & VPCI_STATUS_DRV_OK)) … … 475 502 476 503 LogFlow(("%s vnetCanReceive -> %Vrc\n", INSTANCE(pState), rc)); 477 vnetCs Leave(pState);504 vnetCsRxLeave(pState); 478 505 return rc; 479 506 } … … 675 702 { 676 703 VNETSTATE *pState = IFACE_TO_STATE(pInterface, INetworkPort); 677 int rc = VINF_SUCCESS;678 704 679 705 Log2(("%s vnetReceive: pvBuf=%p cb=%u\n", INSTANCE(pState), pvBuf, cb)); 680 rc = vnetCanReceive(pState);706 int rc = vnetCanReceive(pState); 681 707 if (RT_FAILURE(rc)) 682 708 return rc; … … 693 719 if (vnetAddressFilter(pState, pvBuf, cb)) 694 720 { 695 rc = vnetHandleRxPacket(pState, pvBuf, cb); 696 STAM_REL_COUNTER_ADD(&pState->StatReceiveBytes, cb); 721 rc = vnetCsRxEnter(pState, VERR_SEM_BUSY); 722 if (RT_SUCCESS(rc)) 723 { 724 rc = vnetHandleRxPacket(pState, pvBuf, cb); 725 STAM_REL_COUNTER_ADD(&pState->StatReceiveBytes, cb); 726 vnetCsRxLeave(pState); 727 } 697 728 } 698 729 vpciSetReadLed(&pState->VPCI, false); 699 730 STAM_PROFILE_ADV_STOP(&pState->StatReceive, a); 700 701 731 return rc; 702 732 } … … 856 886 VNETSTATE *pState = (VNETSTATE*)pvUser; 857 887 888 int rc = vnetCsEnter(pState, VERR_SEM_BUSY); 889 if (RT_UNLIKELY(rc != VINF_SUCCESS)) 890 return; 858 891 vringSetNotification(&pState->VPCI, &pState->pTxQueue->VRing, true); 859 892 Log3(("%s vnetTxTimer: Expired, %d packets pending\n", INSTANCE(pState), 860 893 vringReadAvailIndex(&pState->VPCI, &pState->pTxQueue->VRing) - pState->pTxQueue->uNextAvailIndex)); 861 894 vnetTransmitPendingPackets(pState, pState->pTxQueue); 895 vnetCsLeave(pState); 862 896 } 863 897 … … 1114 1148 VNETSTATE* pState = PDMINS_2_DATA(pDevIns, VNETSTATE*); 1115 1149 1116 int rc = vnetCs Enter(pState, VERR_SEM_BUSY);1150 int rc = vnetCsRxEnter(pState, VERR_SEM_BUSY); 1117 1151 if (RT_UNLIKELY(rc != VINF_SUCCESS)) 1118 1152 return rc; 1119 vnetCs Leave(pState);1153 vnetCsRxLeave(pState); 1120 1154 return VINF_SUCCESS; 1121 1155 } … … 1168 1202 VNETSTATE* pState = PDMINS_2_DATA(pDevIns, VNETSTATE*); 1169 1203 1170 int rc = vnetCs Enter(pState, VERR_SEM_BUSY);1204 int rc = vnetCsRxEnter(pState, VERR_SEM_BUSY); 1171 1205 if (RT_UNLIKELY(rc != VINF_SUCCESS)) 1172 1206 return rc; 1173 vnetCs Leave(pState);1207 vnetCsRxLeave(pState); 1174 1208 return VINF_SUCCESS; 1175 1209 } … … 1395 1429 ("Cannot allocate TX buffer for virtio-net device\n"), VERR_NO_MEMORY); 1396 1430 1431 /* Initialize critical section. */ 1432 char szTmp[sizeof(pState->VPCI.szInstance) + 2]; 1433 RTStrPrintf(szTmp, sizeof(szTmp), "%sRX", pState->VPCI.szInstance); 1434 rc = PDMDevHlpCritSectInit(pDevIns, &pState->csRx, szTmp); 1435 if (RT_FAILURE(rc)) 1436 return rc; 1437 1397 1438 /* Map our ports to IO space. */ 1398 1439 rc = PDMDevHlpPCIIORegionRegister(pDevIns, 0, … … 1505 1546 pState->pTxBuf = NULL; 1506 1547 } 1548 if (PDMCritSectIsInitialized(&pState->csRx)) 1549 PDMR3CritSectDelete(&pState->csRx); 1507 1550 1508 1551 return vpciDestruct(&pState->VPCI); … … 1563 1606 AssertLogRelReturnVoid(iLUN == 0); 1564 1607 1565 vnetCsEnter(pState, VERR_SEM_BUSY); 1608 int rc = vnetCsEnter(pState, VERR_SEM_BUSY); 1609 if (RT_FAILURE(rc)) 1610 { 1611 LogRel(("vnetDetach failed to enter critical section!\n")); 1612 return; 1613 } 1566 1614 1567 1615 /* … … 1594 1642 AssertLogRelReturn(iLUN == 0, VERR_PDM_NO_SUCH_LUN); 1595 1643 1596 vnetCsEnter(pState, VERR_SEM_BUSY); 1644 int rc = vnetCsEnter(pState, VERR_SEM_BUSY); 1645 if (RT_FAILURE(rc)) 1646 { 1647 LogRel(("vnetAttach failed to enter critical section!\n")); 1648 return rc; 1649 } 1597 1650 1598 1651 /* 1599 1652 * Attach the driver. 1600 1653 */ 1601 intrc = PDMDevHlpDriverAttach(pDevIns, 0, &pState->VPCI.IBase, &pState->pDrvBase, "Network Port");1654 rc = PDMDevHlpDriverAttach(pDevIns, 0, &pState->VPCI.IBase, &pState->pDrvBase, "Network Port"); 1602 1655 if (RT_SUCCESS(rc)) 1603 1656 {
Note:
See TracChangeset
for help on using the changeset viewer.