Changeset 94969 in vbox for trunk/src/VBox/Devices/Network
- Timestamp:
- May 9, 2022 5:06:17 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/DevVirtioNet_1_0.cpp
r93165 r94969 1900 1900 /* Cache address of uNumBuffers field of pkthdr to update ex post facto */ 1901 1901 RTGCPHYS GCPhysNumBuffers = pVirtqBuf->pSgPhysReturn->paSegs[0].GCPhys + RT_UOFFSETOF(VIRTIONETPKTHDR, uNumBuffers); 1902 uint16_t cVirtqBufsUsed = 1;1902 uint16_t cVirtqBufsUsed = 0; 1903 1903 cbBufRemaining -= cbPktHdr; 1904 1904 /* … … 1915 1915 ++cVirtqBufsUsed; 1916 1916 cbBufRemaining -= cbBounded; 1917 uPktOffset -= cbBounded;1917 uPktOffset += cbBounded; 1918 1918 if (uPktOffset < cb) 1919 1919 { 1920 1920 cbHdrEnqueued = cbPktHdr; 1921 #ifdef VIRTIO_VBUF_ON_STACK 1922 int rc = virtioCoreR3VirtqAvailBufGet(pDevIns, &pThis->Virtio, pRxVirtq->uIdx, pVirtqBuf, true); 1923 #else /* !VIRTIO_VBUF_ON_STACK */ 1924 virtioCoreR3VirtqBufRelease(&pThis->Virtio, pVirtqBuf); 1921 1925 int rc = virtioCoreR3VirtqAvailBufGet(pDevIns, &pThis->Virtio, pRxVirtq->uIdx, &pVirtqBuf, true); 1926 #endif /* !VIRTIO_VBUF_ON_STACK */ 1922 1927 1923 1928 AssertMsgReturn(rc == VINF_SUCCESS || rc == VERR_NOT_AVAILABLE, ("%Rrc\n", rc), rc); 1924 1929 1930 #ifdef VIRTIO_VBUF_ON_STACK 1931 AssertMsgReturn(rc == VINF_SUCCESS && pVirtqBuf->cbPhysReturn, 1932 ("Not enough Rx buffers in queue to accomodate ethernet packet\n"), 1933 VERR_INTERNAL_ERROR); 1934 #else /* !VIRTIO_VBUF_ON_STACK */ 1925 1935 AssertMsgReturnStmt(rc == VINF_SUCCESS && pVirtqBuf->cbPhysReturn, 1926 1936 ("Not enough Rx buffers in queue to accomodate ethernet packet\n"), 1927 1937 virtioCoreR3VirtqBufRelease(&pThis->Virtio, pVirtqBuf), 1928 1938 VERR_INTERNAL_ERROR); 1939 #endif /* !VIRTIO_VBUF_ON_STACK */ 1940 cbBufRemaining = pVirtqBuf->cbPhysReturn; 1929 1941 } 1930 1942 } … … 1934 1946 AssertMsgRCReturn(rc, ("Failure updating descriptor count in pkt hdr in guest physical memory\n"), rc); 1935 1947 1948 #ifndef VIRTIO_VBUF_ON_STACK 1936 1949 virtioCoreR3VirtqBufRelease(&pThis->Virtio, pVirtqBuf); 1950 #endif /* !VIRTIO_VBUF_ON_STACK */ 1937 1951 virtioCoreVirtqUsedRingSync(pDevIns, &pThis->Virtio, pRxVirtq->uIdx); 1938 1952 Log7(("\n")); … … 1960 1974 { 1961 1975 RT_NOREF(pThisCC); 1976 #ifdef VIRTIO_VBUF_ON_STACK 1977 VIRTQBUF_T VirtqBuf; 1978 PVIRTQBUF pVirtqBuf = &VirtqBuf; 1979 int rc = virtioCoreR3VirtqAvailBufGet(pDevIns, &pThis->Virtio, pRxVirtq->uIdx, pVirtqBuf, true); 1980 #else /* !VIRTIO_VBUF_ON_STACK */ 1962 1981 PVIRTQBUF pVirtqBuf; 1963 1982 int rc = virtioCoreR3VirtqAvailBufGet(pDevIns, &pThis->Virtio, pRxVirtq->uIdx, &pVirtqBuf, true); 1983 #endif /* !VIRTIO_VBUF_ON_STACK */ 1964 1984 1965 1985 AssertMsgReturn(rc == VINF_SUCCESS || rc == VERR_NOT_AVAILABLE, ("%Rrc\n", rc), rc); 1966 1986 1987 #ifdef VIRTIO_VBUF_ON_STACK 1988 AssertMsgReturn(rc == VINF_SUCCESS && pVirtqBuf->cbPhysReturn, 1989 ("Not enough Rx buffers or capacity to accommodate ethernet packet\n"), 1990 VERR_INTERNAL_ERROR); 1991 #else /* !VIRTIO_VBUF_ON_STACK */ 1967 1992 AssertMsgReturnStmt(rc == VINF_SUCCESS && pVirtqBuf->cbPhysReturn, 1968 1993 ("Not enough Rx buffers or capacity to accommodate ethernet packet\n"), 1969 1994 virtioCoreR3VirtqBufRelease(&pThis->Virtio, pVirtqBuf), 1970 1995 VERR_INTERNAL_ERROR); 1996 #endif /* !VIRTIO_VBUF_ON_STACK */ 1971 1997 /* 1972 1998 * Try to do fast (e.g. single-buffer) copy to guest, even if MRG_RXBUF feature is enabled … … 1981 2007 if (rc == VINF_SUCCESS) 1982 2008 rc = virtioCoreR3VirtqUsedBufPut(pDevIns, &pThis->Virtio, pRxVirtq->uIdx, cb, pvBuf, pVirtqBuf, cbPktHdr + cb /* cbEnqueue */); 2009 #ifndef VIRTIO_VBUF_ON_STACK 1983 2010 virtioCoreR3VirtqBufRelease(&pThis->Virtio, pVirtqBuf); 2011 #endif /* !VIRTIO_VBUF_ON_STACK */ 1984 2012 virtioCoreVirtqUsedRingSync(pDevIns, &pThis->Virtio, pRxVirtq->uIdx); 1985 2013 AssertMsgReturn(rc == VINF_SUCCESS, ("%Rrc\n", rc), rc); … … 2674 2702 virtioNetR3SetWriteLed(pThisCC, true); 2675 2703 2704 /* Disable notifications until all available descriptors have been processed */ 2705 if (!(pVirtio->uDriverFeatures & VIRTIO_F_EVENT_IDX)) 2706 virtioCoreVirtqEnableNotify(&pThis->Virtio, pTxVirtq->uIdx, false /* fEnable */); 2707 2676 2708 int rc; 2709 #ifdef VIRTIO_VBUF_ON_STACK 2710 VIRTQBUF_T VirtqBuf; 2711 PVIRTQBUF pVirtqBuf = &VirtqBuf; 2712 while ((rc = virtioCoreR3VirtqAvailBufPeek(pVirtio->pDevInsR3, pVirtio, pTxVirtq->uIdx, pVirtqBuf)) == VINF_SUCCESS) 2713 #else /* !VIRTIO_VBUF_ON_STACK */ 2677 2714 PVIRTQBUF pVirtqBuf = NULL; 2678 2715 while ((rc = virtioCoreR3VirtqAvailBufPeek(pVirtio->pDevInsR3, pVirtio, pTxVirtq->uIdx, &pVirtqBuf)) == VINF_SUCCESS) 2716 #endif /* !VIRTIO_VBUF_ON_STACK */ 2679 2717 { 2680 2718 Log10Func(("[%s] fetched descriptor chain from %s\n", pThis->szInst, pTxVirtq->szName)); … … 2689 2727 VERR_INTERNAL_ERROR); 2690 2728 2729 #ifdef VIRTIO_VBUF_ON_STACK 2730 VIRTIONETPKTHDR PktHdr; 2731 PVIRTIONETPKTHDR pPktHdr = &PktHdr; 2732 #else /* !VIRTIO_VBUF_ON_STACK */ 2691 2733 PVIRTIONETPKTHDR pPktHdr = (PVIRTIONETPKTHDR)RTMemAllocZ(pThis->cbPktHdr); 2692 2734 AssertMsgReturn(pPktHdr, ("Out of Memory\n"), VERR_NO_MEMORY); 2735 #endif /* !VIRTIO_VBUF_ON_STACK */ 2693 2736 2694 2737 /* Compute total frame size from guest (including virtio-net pkt hdr) */ … … 2765 2808 Log4Func(("Failed to allocate S/G buffer: frame size=%u rc=%Rrc\n", uFrameSize, rc)); 2766 2809 /* Stop trying to fetch TX descriptors until we get more bandwidth. */ 2810 #ifndef VIRTIO_VBUF_ON_STACK 2767 2811 virtioCoreR3VirtqBufRelease(pVirtio, pVirtqBuf); 2812 #endif /* !VIRTIO_VBUF_ON_STACK */ 2768 2813 break; 2769 2814 } … … 2776 2821 } 2777 2822 2823 #ifndef VIRTIO_VBUF_ON_STACK 2778 2824 virtioCoreR3VirtqBufRelease(pVirtio, pVirtqBuf); 2779 2825 pVirtqBuf = NULL; 2826 #endif /* !VIRTIO_VBUF_ON_STACK */ 2827 /* Before we break the loop we need to check if the queue is empty, 2828 * re-enable notifications, and then re-check again to avoid missing 2829 * a notification for the descriptor that is added to the queue 2830 * after we have checked it on being empty, but before we re-enabled 2831 * notifications. 2832 */ 2833 if (!(pVirtio->uDriverFeatures & VIRTIO_F_EVENT_IDX) 2834 && IS_VIRTQ_EMPTY(pDevIns, &pThis->Virtio, pTxVirtq->uIdx)) 2835 virtioCoreVirtqEnableNotify(&pThis->Virtio, pTxVirtq->uIdx, true /* fEnable */); 2780 2836 } 2781 2837 virtioNetR3SetWriteLed(pThisCC, false); … … 3108 3164 { 3109 3165 Log10Func(("[%s] %s worker woken. Fetching desc chain\n", pThis->szInst, pVirtq->szName)); 3166 #ifdef VIRTIO_VBUF_ON_STACK 3167 VIRTQBUF_T VirtqBuf; 3168 PVIRTQBUF pVirtqBuf = &VirtqBuf; 3169 int rc = virtioCoreR3VirtqAvailBufGet(pDevIns, &pThis->Virtio, pVirtq->uIdx, pVirtqBuf, true); 3170 #else /* !VIRTIO_VBUF_ON_STACK */ 3110 3171 PVIRTQBUF pVirtqBuf = NULL; 3111 3172 int rc = virtioCoreR3VirtqAvailBufGet(pDevIns, &pThis->Virtio, pVirtq->uIdx, &pVirtqBuf, true); 3173 #endif /* !VIRTIO_VBUF_ON_STACK */ 3112 3174 if (rc == VERR_NOT_AVAILABLE) 3113 3175 { … … 3116 3178 } 3117 3179 virtioNetR3Ctrl(pDevIns, pThis, pThisCC, pVirtqBuf); 3180 #ifndef VIRTIO_VBUF_ON_STACK 3118 3181 virtioCoreR3VirtqBufRelease(&pThis->Virtio, pVirtqBuf); 3182 #endif /* !VIRTIO_VBUF_ON_STACK */ 3119 3183 } 3120 3184 else /* Must be Tx queue */
Note:
See TracChangeset
for help on using the changeset viewer.