Changeset 28332 in vbox
- Timestamp:
- Apr 14, 2010 9:52:52 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/pdmnetifs.h
r28320 r28332 353 353 /** PDMINETWORKUP interface ID. */ 354 354 #define PDMINETWORKUP_IID "67e7e7a8-2594-4649-a1e3-7cee680c6083" 355 /** PDMINETWORKUP interface method names. */ 356 #define PDMINETWORKUP_SYM_LIST "BeginXmit;AllocBuf;FreeBuf;SendBuf;EndXmit;SetPromiscuousMode" 355 357 356 358 -
trunk/src/VBox/Devices/Makefile.kmk
r28290 r28332 568 568 Network/DevPCNet.cpp \ 569 569 Serial/DevSerial.cpp \ 570 Parallel/DevParallel.cpp \ 571 \ 572 Network/DrvIntNet.cpp 570 Parallel/DevParallel.cpp 573 571 574 572 ifdef VBOX_DYNAMIC_NET_ATTACH -
trunk/src/VBox/Devices/Network/DevE1000.cpp
r28328 r28332 3753 3753 if (pDrv) 3754 3754 { 3755 rc = pDrv->pfnBeginXmit(pDrv, true /*fOnWorkerThread*/);3755 rc = pDrv->pfnBeginXmit(pDrv, fOnWorkerThread); 3756 3756 if (RT_FAILURE(rc)) 3757 3757 return rc; -
trunk/src/VBox/Devices/Network/DrvIntNet.cpp
r28328 r28332 49 49 #include "../Builtins.h" 50 50 51 // To play with R0 drivers. 52 //#define VBOX_WITH_DRVINTNET_IN_R0 53 51 54 52 55 /******************************************************************************* … … 56 59 * The state of the asynchronous thread. 57 60 */ 58 typedef enum ASYNCSTATE61 typedef enum RECVSTATE 59 62 { 60 63 /** The thread is suspended. */ 61 ASYNCSTATE_SUSPENDED = 1,64 RECVSTATE_SUSPENDED = 1, 62 65 /** The thread is running. */ 63 ASYNCSTATE_RUNNING,66 RECVSTATE_RUNNING, 64 67 /** The thread must (/has) terminate. */ 65 ASYNCSTATE_TERMINATE,68 RECVSTATE_TERMINATE, 66 69 /** The usual 32-bit type blowup. */ 67 ASYNCSTATE_32BIT_HACK = 0x7fffffff68 } ASYNCSTATE;70 RECVSTATE_32BIT_HACK = 0x7fffffff 71 } RECVSTATE; 69 72 70 73 /** … … 108 111 /** Interface handle. */ 109 112 INTNETIFHANDLE hIf; 110 /** The thread state. */111 ASYNCSTATE volatile enmState;113 /** The receive thread state. */ 114 RECVSTATE volatile enmRecvState; 112 115 /** The receive thread. */ 113 116 RTTHREAD hRecvThread; … … 219 222 } 220 223 224 #endif /* IN_RING3 */ 221 225 222 226 /* -=-=-=-=- PDMINETWORKUP -=-=-=-=- */ … … 225 229 * @interface_method_impl{PDMINETWORKUP,pfnBeginXmit} 226 230 */ 227 static DECLCALLBACK(int) drvR3IntNetUp_BeginXmit(PPDMINETWORKUP pInterface, bool fOnWorkerThread) 228 { 229 PDRVINTNET pThis = RT_FROM_MEMBER(pInterface, DRVINTNET, INetworkUpR3); 230 #if 1 231 PDMBOTHCBDECL(int) drvIntNetUp_BeginXmit(PPDMINETWORKUP pInterface, bool fOnWorkerThread) 232 { 233 PDRVINTNET pThis = RT_FROM_MEMBER(pInterface, DRVINTNET, CTX_SUFF(INetworkUp)); 234 #if !defined(IN_RING3) 235 int rc = VERR_SEM_BUSY; 236 Assert(!fOnWorkerThread); 237 #elif 1 231 238 int rc = PDMCritSectTryEnter(&pThis->XmitLock); 232 239 #else … … 246 253 * forth? I seriously think this is ring-0 only... */ 247 254 if ( !fOnWorkerThread 248 && !ASMAtomicUoReadBool(&pThis->fXmitOnXmitThread)249 && ASMAtomicCmpXchgBool(&pThis->fXmitSignalled, true, false) )255 /*&& !ASMAtomicUoReadBool(&pThis->fXmitOnXmitThread) 256 && ASMAtomicCmpXchgBool(&pThis->fXmitSignalled, true, false)*/) 250 257 { 251 258 rc = SUPSemEventSignal(pThis->pSupDrvSession, pThis->hXmitEvt); … … 261 268 * @interface_method_impl{PDMINETWORKUP,pfnAllocBuf} 262 269 */ 263 static DECLCALLBACK(int) drvR3IntNetUp_AllocBuf(PPDMINETWORKUP pInterface, size_t cbMin,264 PCPDMNETWORKGSO pGso, PPPDMSCATTERGATHER ppSgBuf)265 { 266 PDRVINTNET pThis = RT_FROM_MEMBER(pInterface, DRVINTNET, INetworkUpR3);270 PDMBOTHCBDECL(int) drvIntNetUp_AllocBuf(PPDMINETWORKUP pInterface, size_t cbMin, 271 PCPDMNETWORKGSO pGso, PPPDMSCATTERGATHER ppSgBuf) 272 { 273 PDRVINTNET pThis = RT_FROM_MEMBER(pInterface, DRVINTNET, CTX_SUFF(INetworkUp)); 267 274 int rc = VINF_SUCCESS; 268 275 Assert(cbMin < UINT32_MAX / 2); 269 276 Assert(PDMCritSectIsOwner(&pThis->XmitLock)); 270 277 278 #ifdef IN_RING3 271 279 /* 272 280 * Allocate a S/G buffer. … … 330 338 /** @todo implement VERR_TRY_AGAIN */ 331 339 return rc; 340 341 #else /* !IN_RING3 */ 342 rc = VERR_TRY_AGAIN; 343 return rc; 344 #endif /* !IN_RING3 */ 332 345 } 333 346 … … 336 349 * @interface_method_impl{PDMINETWORKUP,pfnFreeBuf} 337 350 */ 338 static DECLCALLBACK(int) drvR3IntNetUp_FreeBuf(PPDMINETWORKUP pInterface, PPDMSCATTERGATHER pSgBuf)339 { 340 PDRVINTNET pThis = RT_FROM_MEMBER(pInterface, DRVINTNET, INetworkUpR3);351 PDMBOTHCBDECL(int) drvIntNetUp_FreeBuf(PPDMINETWORKUP pInterface, PPDMSCATTERGATHER pSgBuf) 352 { 353 PDRVINTNET pThis = RT_FROM_MEMBER(pInterface, DRVINTNET, CTX_SUFF(INetworkUp)); 341 354 PINTNETHDR pHdr = (PINTNETHDR)pSgBuf->pvAllocator; 342 355 Assert(pSgBuf->fFlags == (PDMSCATTERGATHER_FLAGS_MAGIC | PDMSCATTERGATHER_FLAGS_OWNER_1)); … … 346 359 Assert(PDMCritSectIsOwner(&pThis->XmitLock)); 347 360 361 #ifdef IN_RING3 348 362 /** @todo LATER: try unalloc the frame. */ 349 363 pHdr->u16Type = INTNETHDR_TYPE_PADDING; … … 352 366 RTMemCacheFree(pThis->hSgCache, pSgBuf); 353 367 return VINF_SUCCESS; 368 #else 369 return VERR_INTERNAL_ERROR_5; 370 #endif 354 371 } 355 372 … … 358 375 * @interface_method_impl{PDMINETWORKUP,pfnSendBuf} 359 376 */ 360 static DECLCALLBACK(int) drvR3IntNetUp_SendBuf(PPDMINETWORKUP pInterface, PPDMSCATTERGATHER pSgBuf, bool fOnWorkerThread)361 { 362 PDRVINTNET pThis = RT_FROM_MEMBER(pInterface, DRVINTNET, INetworkUpR3);377 PDMBOTHCBDECL(int) drvIntNetUp_SendBuf(PPDMINETWORKUP pInterface, PPDMSCATTERGATHER pSgBuf, bool fOnWorkerThread) 378 { 379 PDRVINTNET pThis = RT_FROM_MEMBER(pInterface, DRVINTNET, CTX_SUFF(INetworkUp)); 363 380 STAM_PROFILE_START(&pThis->StatTransmit, a); 364 381 … … 371 388 STAM_COUNTER_INC(&pThis->StatSentGso); 372 389 390 #ifdef IN_RING3 373 391 /* 374 392 * Commit the frame and push it thru the switch. … … 388 406 STAM_PROFILE_STOP(&pThis->StatTransmit, a); 389 407 return VINF_SUCCESS; 408 #else 409 return VERR_INTERNAL_ERROR_4; 410 #endif 390 411 } 391 412 … … 394 415 * @interface_method_impl{PDMINETWORKUP,pfnEndXmit} 395 416 */ 396 static DECLCALLBACK(void) drvR3IntNetUp_EndXmit(PPDMINETWORKUP pInterface)397 { 398 PDRVINTNET pThis = RT_FROM_MEMBER(pInterface, DRVINTNET, INetworkUpR3);417 PDMBOTHCBDECL(void) drvIntNetUp_EndXmit(PPDMINETWORKUP pInterface) 418 { 419 PDRVINTNET pThis = RT_FROM_MEMBER(pInterface, DRVINTNET, CTX_SUFF(INetworkUp)); 399 420 ASMAtomicUoWriteBool(&pThis->fXmitOnXmitThread, false); 400 421 PDMCritSectLeave(&pThis->XmitLock); … … 405 426 * @interface_method_impl{PDMINETWORKUP,pfnSetPromiscuousMode} 406 427 */ 407 static DECLCALLBACK(void) drvR3IntNetUp_SetPromiscuousMode(PPDMINETWORKUP pInterface, bool fPromiscuous) 408 { 409 PDRVINTNET pThis = RT_FROM_MEMBER(pInterface, DRVINTNET, INetworkUpR3); 428 PDMBOTHCBDECL(void) drvIntNetUp_SetPromiscuousMode(PPDMINETWORKUP pInterface, bool fPromiscuous) 429 { 430 PDRVINTNET pThis = RT_FROM_MEMBER(pInterface, DRVINTNET, CTX_SUFF(INetworkUp)); 431 #ifdef IN_RING3 410 432 INTNETIFSETPROMISCUOUSMODEREQ Req; 411 433 Req.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC; … … 415 437 Req.fPromiscuous = fPromiscuous; 416 438 int rc = PDMDrvHlpSUPCallVMMR0Ex(pThis->pDrvInsR3, VMMR0_DO_INTNET_IF_SET_PROMISCUOUS_MODE, &Req, sizeof(Req)); 417 LogFlow(("drv R3IntNetUp_SetPromiscuousMode: fPromiscuous=%RTbool\n", fPromiscuous));439 LogFlow(("drvIntNetUp_SetPromiscuousMode: fPromiscuous=%RTbool\n", fPromiscuous)); 418 440 AssertRC(rc); 419 } 420 441 #else 442 /** @todo */ 443 AssertFailed(); 444 #endif 445 } 446 447 #ifdef IN_RING3 421 448 422 449 /** … … 425 452 static DECLCALLBACK(void) drvR3IntNetUp_NotifyLinkChanged(PPDMINETWORKUP pInterface, PDMNETWORKLINKSTATE enmLinkState) 426 453 { 427 PDRVINTNET pThis = RT_FROM_MEMBER(pInterface, DRVINTNET, INetworkUpR3);454 PDRVINTNET pThis = RT_FROM_MEMBER(pInterface, DRVINTNET, CTX_SUFF(INetworkUp)); 428 455 bool fLinkDown; 429 456 switch (enmLinkState) … … 539 566 * Check the state and then inspect the packet. 540 567 */ 541 if (pThis->enm State != ASYNCSTATE_RUNNING)568 if (pThis->enmRecvState != RECVSTATE_RUNNING) 542 569 { 543 570 STAM_PROFILE_ADV_STOP(&pThis->StatReceive, a); … … 675 702 * Wait for data, checking the state before we block. 676 703 */ 677 if (pThis->enm State != ASYNCSTATE_RUNNING)704 if (pThis->enmRecvState != RECVSTATE_RUNNING) 678 705 { 679 706 STAM_PROFILE_ADV_STOP(&pThis->StatReceive, a); … … 719 746 for (;;) 720 747 { 721 ASYNCSTATE enmState = pThis->enmState;722 switch (enm State)748 RECVSTATE enmRecvState = pThis->enmRecvState; 749 switch (enmRecvState) 723 750 { 724 case ASYNCSTATE_SUSPENDED:751 case RECVSTATE_SUSPENDED: 725 752 { 726 753 int rc = RTSemEventWait(pThis->hRecvEvt, 30000); … … 734 761 } 735 762 736 case ASYNCSTATE_RUNNING:763 case RECVSTATE_RUNNING: 737 764 { 738 765 int rc = drvR3IntNetRecvRun(pThis); … … 747 774 748 775 default: 749 AssertMsgFailed(("Invalid state %d\n", enm State));750 case ASYNCSTATE_TERMINATE:776 AssertMsgFailed(("Invalid state %d\n", enmRecvState)); 777 case RECVSTATE_TERMINATE: 751 778 LogFlow(("drvR3IntNetRecvThread: returns VINF_SUCCESS\n")); 752 779 return VINF_SUCCESS; … … 765 792 PDRVINTNET pThis = RT_FROM_MEMBER(pInterface, DRVINTNET, IBaseRC); 766 793 767 #if def VBOX_WITH_R0_AND_RC_DRIVERS794 #if 0 768 795 PDMIBASERC_RETURN_INTERFACE(pThis->pDrvInsR3, pszIID, PDMINETWORKUP, &pThis->INetworkUpRC); 769 796 #endif … … 780 807 { 781 808 PDRVINTNET pThis = RT_FROM_MEMBER(pInterface, DRVINTNET, IBaseR0); 782 #ifdef VBOX_WITH_ R0_AND_RC_DRIVERS809 #ifdef VBOX_WITH_DRVINTNET_IN_R0 783 810 PDMIBASER0_RETURN_INTERFACE(pThis->pDrvInsR3, pszIID, PDMINETWORKUP, &pThis->INetworkUpR0); 784 811 #endif … … 818 845 if (!pThis->fActivateEarlyDeactivateLate) 819 846 { 820 ASMAtomicXchgSize(&pThis->enm State, ASYNCSTATE_SUSPENDED);847 ASMAtomicXchgSize(&pThis->enmRecvState, RECVSTATE_SUSPENDED); 821 848 drvR3IntNetSetActive(pThis, false /* fActive */); 822 849 } … … 872 899 if (!pThis->fActivateEarlyDeactivateLate) 873 900 { 874 ASMAtomicXchgSize(&pThis->enm State, ASYNCSTATE_RUNNING);901 ASMAtomicXchgSize(&pThis->enmRecvState, RECVSTATE_RUNNING); 875 902 RTSemEventSignal(pThis->hRecvEvt); 876 903 drvR3IntNetUpdateMacAddress(pThis); /* (could be a state restore) */ … … 917 944 if (!pThis->fActivateEarlyDeactivateLate) 918 945 { 919 ASMAtomicXchgSize(&pThis->enm State, ASYNCSTATE_SUSPENDED);946 ASMAtomicXchgSize(&pThis->enmRecvState, RECVSTATE_SUSPENDED); 920 947 drvR3IntNetSetActive(pThis, false /* fActive */); 921 948 } … … 934 961 if (!pThis->fActivateEarlyDeactivateLate) 935 962 { 936 ASMAtomicXchgSize(&pThis->enm State, ASYNCSTATE_RUNNING);963 ASMAtomicXchgSize(&pThis->enmRecvState, RECVSTATE_RUNNING); 937 964 RTSemEventSignal(pThis->hRecvEvt); 938 965 drvR3IntNetUpdateMacAddress(pThis); … … 968 995 * Indicate to the thread that it's time to quit. 969 996 */ 970 ASMAtomicXchgSize(&pThis->enm State, ASYNCSTATE_TERMINATE);997 ASMAtomicXchgSize(&pThis->enmRecvState, RECVSTATE_TERMINATE); 971 998 ASMAtomicXchgSize(&pThis->fLinkDown, true); 972 999 RTSEMEVENT hRecvEvt = pThis->hRecvEvt; … … 991 1018 * Wait for the thread to terminate. 992 1019 */ 1020 if (hRecvEvt != NIL_RTSEMEVENT) 1021 RTSemEventSignal(hRecvEvt); 1022 1023 if (pThis->pXmitThread) 1024 { 1025 int rc = PDMR3ThreadDestroy(pThis->pXmitThread, NULL); 1026 AssertRC(rc); 1027 pThis->pXmitThread = NULL; 1028 } 1029 993 1030 if (pThis->hRecvThread != NIL_RTTHREAD) 994 1031 { 995 if (hRecvEvt != NIL_RTSEMEVENT)996 RTSemEventSignal(hRecvEvt);997 1032 int rc = RTThreadWait(pThis->hRecvThread, 5000, NULL); 998 1033 AssertRC(rc); … … 1000 1035 } 1001 1036 1002 /* 1003 * Destroy the semaphore, S/G cache and xmit lock. 1037 1038 /* 1039 * Destroy the semaphores, S/G cache and xmit lock. 1004 1040 */ 1005 1041 if (hRecvEvt != NIL_RTSEMEVENT) 1006 1042 RTSemEventDestroy(hRecvEvt); 1043 1044 if (pThis->hXmitEvt != NIL_SUPSEMEVENT) 1045 { 1046 SUPSemEventClose(pThis->pSupDrvSession, pThis->hXmitEvt); 1047 pThis->hXmitEvt = NIL_SUPSEMEVENT; 1048 } 1007 1049 1008 1050 RTMemCacheDestroy(pThis->hSgCache); … … 1059 1101 pThis->pSupDrvSession = PDMDrvHlpGetSupDrvSession(pDrvIns); 1060 1102 pThis->hSgCache = NIL_RTMEMCACHE; 1061 pThis->enm State = ASYNCSTATE_SUSPENDED;1103 pThis->enmRecvState = RECVSTATE_SUSPENDED; 1062 1104 pThis->fActivateEarlyDeactivateLate = false; 1063 1105 /* IBase* */ … … 1066 1108 pThis->IBaseRC.pfnQueryInterface = drvR3IntNetIBaseRC_QueryInterface; 1067 1109 /* INetworkUp */ 1068 pThis->INetworkUpR3.pfnBeginXmit = drv R3IntNetUp_BeginXmit;1069 pThis->INetworkUpR3.pfnAllocBuf = drv R3IntNetUp_AllocBuf;1070 pThis->INetworkUpR3.pfnFreeBuf = drv R3IntNetUp_FreeBuf;1071 pThis->INetworkUpR3.pfnSendBuf = drv R3IntNetUp_SendBuf;1072 pThis->INetworkUpR3.pfnEndXmit = drv R3IntNetUp_EndXmit;1073 pThis->INetworkUpR3.pfnSetPromiscuousMode = drv R3IntNetUp_SetPromiscuousMode;1110 pThis->INetworkUpR3.pfnBeginXmit = drvIntNetUp_BeginXmit; 1111 pThis->INetworkUpR3.pfnAllocBuf = drvIntNetUp_AllocBuf; 1112 pThis->INetworkUpR3.pfnFreeBuf = drvIntNetUp_FreeBuf; 1113 pThis->INetworkUpR3.pfnSendBuf = drvIntNetUp_SendBuf; 1114 pThis->INetworkUpR3.pfnEndXmit = drvIntNetUp_EndXmit; 1115 pThis->INetworkUpR3.pfnSetPromiscuousMode = drvIntNetUp_SetPromiscuousMode; 1074 1116 pThis->INetworkUpR3.pfnNotifyLinkChanged = drvR3IntNetUp_NotifyLinkChanged; 1075 1117 … … 1378 1420 1379 1421 /* 1380 * Create the async I/O threads.1381 * Note! Using a PDM thread here doesn't fit with the IsService=true operation.1382 */1383 rc = RTThreadCreate(&pThis->hRecvThread, drvR3IntNetRecvThread, pThis, 0,1384 RTTHREADTYPE_IO, RTTHREADFLAGS_WAITABLE, "INTNET-RECV");1385 if (RT_FAILURE(rc))1386 {1387 AssertRC(rc);1388 return rc;1389 }1390 1391 rc = SUPSemEventCreate(pThis->pSupDrvSession, &pThis->hXmitEvt);1392 AssertRCReturn(rc, rc);1393 1394 rc = PDMDrvHlpThreadCreate(pDrvIns, &pThis->pXmitThread, pThis,1395 drvR3IntNetXmitThread, drvR3IntNetXmitWakeUp, 0, RTTHREADTYPE_IO, "INTNET-XMIT");1396 AssertRCReturn(rc, rc);1397 1398 /*1399 1422 * Register statistics. 1400 1423 */ … … 1418 1441 1419 1442 /* 1443 * Create the async I/O threads. 1444 * Note! Using a PDM thread here doesn't fit with the IsService=true operation. 1445 */ 1446 rc = RTThreadCreate(&pThis->hRecvThread, drvR3IntNetRecvThread, pThis, 0, 1447 RTTHREADTYPE_IO, RTTHREADFLAGS_WAITABLE, "INTNET-RECV"); 1448 if (RT_FAILURE(rc)) 1449 { 1450 AssertRC(rc); 1451 return rc; 1452 } 1453 1454 rc = SUPSemEventCreate(pThis->pSupDrvSession, &pThis->hXmitEvt); 1455 AssertRCReturn(rc, rc); 1456 1457 rc = PDMDrvHlpThreadCreate(pDrvIns, &pThis->pXmitThread, pThis, 1458 drvR3IntNetXmitThread, drvR3IntNetXmitWakeUp, 0, RTTHREADTYPE_IO, "INTNET-XMIT"); 1459 AssertRCReturn(rc, rc); 1460 1461 #ifdef VBOX_WITH_DRVINTNET_IN_R0 1462 /* 1463 * Resolve the ring-0 context interface addresses. 1464 */ 1465 rc = pDrvIns->pHlpR3->pfnLdrGetR0InterfaceSymbols(pDrvIns, &pThis->INetworkUpR0, sizeof(pThis->INetworkUpR0), 1466 "drvIntNetUp_", PDMINETWORKUP_SYM_LIST); 1467 AssertLogRelRCReturn(rc, rc); 1468 #endif 1469 1470 /* 1420 1471 * Activate data transmission as early as possible 1421 1472 */ 1422 1473 if (pThis->fActivateEarlyDeactivateLate) 1423 1474 { 1424 ASMAtomicXchgSize(&pThis->enm State, ASYNCSTATE_RUNNING);1475 ASMAtomicXchgSize(&pThis->enmRecvState, RECVSTATE_RUNNING); 1425 1476 RTSemEventSignal(pThis->hRecvEvt); 1426 1477 … … 1429 1480 } 1430 1481 1431 return rc;1482 return rc; 1432 1483 } 1433 1484 … … 1444 1495 "IntNet", 1445 1496 /* szRCMod */ 1446 "VBoxDD RC",1497 "VBoxDDGC.rc", 1447 1498 /* szR0Mod */ 1448 "VBoxDDR0 ",1499 "VBoxDDR0.r0", 1449 1500 /* pszDescription */ 1450 1501 "Internal Networking Transport Driver", 1451 1502 /* fFlags */ 1452 #ifdef VBOX_WITH_ R0_AND_RC_DRIVERS1453 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT | PDM_DRVREG_FLAGS_R0 | PDM_DRVREG_FLAGS_RC,1503 #ifdef VBOX_WITH_DRVINTNET_IN_R0 1504 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT | PDM_DRVREG_FLAGS_R0, 1454 1505 #else 1455 1506 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
Note:
See TracChangeset
for help on using the changeset viewer.