VirtualBox

Changeset 83186 in vbox for trunk/src/VBox/Devices/Network


Ignore:
Timestamp:
Mar 2, 2020 5:50:00 PM (5 years ago)
Author:
vboxsync
Message:

Network/DevVirtioNet.cpp: Some clean up. Have verified that received packets are formatted properly, conveyed to and read by guest properly. Still no Tx packets from guest yet. Continuing to investigate

File:
1 edited

Legend:

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

    r83165 r83186  
    416416
    417417    bool                    fLog;
    418 
     418    bool                    fBp;
    419419    /* Receive-blocking-related fields ***************************************/
    420420
     
    568568}
    569569
    570 DECLINLINE(void) virtioNetPrintFeatures(PVIRTIONET pThis, uint32_t fFeatures, const char *pcszText)
     570void virtioNetDumpGcPhysRxBuf(PPDMDEVINS pDevIns, PVIRTIONET_PKT_HDR_T pRxPktHdr,
     571                     uint16_t cDescs, uint8_t *pvBuf, uint16_t cb, RTGCPHYS gcPhysRxBuf, uint8_t cbRxBuf)
     572{
     573    PVIRTIONET pThis = PDMDEVINS_2_DATA(pDevIns, PVIRTIONET);
     574    pRxPktHdr->uNumBuffers = cDescs;
     575    LogFunc(("-------------------------------------------------------------------\n"));
     576    LogFunc(("rxPktHdr\n"
     577             "    uFlags ......... %2.2x\n"
     578             "    uGsoType ....... %2.2x\n"
     579             "    uHdrLen ........ %4.4x\n"
     580             "    uGsoSize ....... %4.4x\n"
     581             "    uChksumStart ... %4.4x\n"
     582             "    uChksumOffset .. %4.4x\n"
     583             "    uNumBuffers .... %4.4x\n",
     584                    pRxPktHdr->uFlags,
     585                    pRxPktHdr->uGsoType, pRxPktHdr->uHdrLen, pRxPktHdr->uGsoSize,
     586                    pRxPktHdr->uChksumStart, pRxPktHdr->uChksumOffset, pRxPktHdr->uNumBuffers));
     587
     588    virtioCoreHexDump((uint8_t *)pRxPktHdr, sizeof(VIRTIONET_PKT_HDR_T), 0, "Dump of virtual rPktHdr");
     589    virtioNetR3PacketDump(pThis, (const uint8_t *)pvBuf, cb, "<-- Incoming");
     590    LogFunc((". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\n"));
     591    virtioCoreGcPhysHexDump(pDevIns, gcPhysRxBuf, cbRxBuf, 0, "Phys Mem Dump of Rx pkt");
     592    LogFunc(("-------------------------------------------------------------------\n"));
     593}
     594
     595DECLINLINE(void) virtioNetPrintFeatures(uint32_t fFeatures, const char *pcszText)
    571596{
    572597#ifdef LOG_ENABLED
     
    577602    } const s_aFeatures[] =
    578603    {
    579         { VIRTIONET_F_CSUM,                "Host handles packets with partial checksum." },
    580         { VIRTIONET_F_GUEST_CSUM,          "Guest handles packets with partial checksum." },
    581         { VIRTIONET_F_CTRL_GUEST_OFFLOADS, "Control channel offloads reconfiguration support." },
    582         { VIRTIONET_F_MAC,                 "Host has given MAC address." },
    583         { VIRTIONET_F_GUEST_TSO4,          "Guest can receive TSOv4." },
    584         { VIRTIONET_F_GUEST_TSO6,          "Guest can receive TSOv6." },
    585         { VIRTIONET_F_GUEST_ECN,           "Guest can receive TSO with ECN." },
    586         { VIRTIONET_F_GUEST_UFO,           "Guest can receive UFO." },
    587         { VIRTIONET_F_HOST_TSO4,           "Host can receive TSOv4." },
    588         { VIRTIONET_F_HOST_TSO6,           "Host can receive TSOv6." },
    589         { VIRTIONET_F_HOST_ECN,            "Host can receive TSO with ECN." },
    590         { VIRTIONET_F_HOST_UFO,            "Host can receive UFO." },
    591         { VIRTIONET_F_MRG_RXBUF,           "Guest can merge receive buffers." },
    592         { VIRTIONET_F_STATUS,              "Configuration status field is available." },
    593         { VIRTIONET_F_CTRL_VQ,             "Control channel is available." },
    594         { VIRTIONET_F_CTRL_RX,             "Control channel RX mode support." },
    595         { VIRTIONET_F_CTRL_VLAN,           "Control channel VLAN filtering." },
    596         { VIRTIONET_F_GUEST_ANNOUNCE,      "Guest can send gratuitous packets." },
    597         { VIRTIONET_F_MQ,                  "Host supports multiqueue with automatic receive steering." },
    598         { VIRTIONET_F_CTRL_MAC_ADDR,       "Set MAC address through control channel." }
     604        { VIRTIONET_F_CSUM,                "   CSUM:                Host handles packets with partial checksum.\n" },
     605        { VIRTIONET_F_GUEST_CSUM,          "   GUEST_CSUM:          Guest handles packets with partial checksum.\n" },
     606        { VIRTIONET_F_CTRL_GUEST_OFFLOADS, "   CTRL_GUEST_OFFLOADS: Control channel offloads reconfiguration support.\n" },
     607        { VIRTIONET_F_MAC,                 "   MAC:                 Host has given MAC address.\n" },
     608        { VIRTIONET_F_GUEST_TSO4,          "   GUEST_TSO4:          Guest can receive TSOv4.\n" },
     609        { VIRTIONET_F_GUEST_TSO6,          "   GUEST_TSO6:          Guest can receive TSOv6.\n" },
     610        { VIRTIONET_F_GUEST_ECN,           "   GUEST_ECN:           Guest can receive TSO with ECN.\n" },
     611        { VIRTIONET_F_GUEST_UFO,           "   GUEST_UFO:           Guest can receive UFO.\n" },
     612        { VIRTIONET_F_HOST_TSO4,           "   HOST_TSO4:           Host can receive TSOv4.\n" },
     613        { VIRTIONET_F_HOST_TSO6,           "   HOST_TSO6:           Host can receive TSOv6.\n" },
     614        { VIRTIONET_F_HOST_ECN,            "   HOST_ECN:            Host can receive TSO with ECN.\n" },
     615        { VIRTIONET_F_HOST_UFO,            "   HOST_UFO:            Host can receive UFO.\n" },
     616        { VIRTIONET_F_MRG_RXBUF,           "   MRG_RXBUF:           Guest can merge receive buffers.\n" },
     617        { VIRTIONET_F_STATUS,              "   STATUS:              Configuration status field is available.\n" },
     618        { VIRTIONET_F_CTRL_VQ,             "   CTRL_VQ:             Control channel is available.\n" },
     619        { VIRTIONET_F_CTRL_RX,             "   CTRL_RX:             Control channel RX mode support.\n" },
     620        { VIRTIONET_F_CTRL_VLAN,           "   CTRL_VLAN:           Control channel VLAN filtering.\n" },
     621        { VIRTIONET_F_GUEST_ANNOUNCE,      "   GUEST_ANNOUNCE:      Guest can send gratuitous packets.\n" },
     622        { VIRTIONET_F_MQ,                  "   MQ:                  Host supports multiqueue with automatic receive steering.\n" },
     623        { VIRTIONET_F_CTRL_MAC_ADDR,       "   CTRL_MAC_ADDR:       Set MAC address through control channel.\n" }
    599624    };
    600625
    601     Log3(("%s %s:\n", INSTANCE(pThis), pcszText));
     626#define MAXLINE 80
     627    /* Display as a single buf to prevent interceding log messages */
     628    char *pszBuf = (char *)RTMemAllocZ(RT_ELEMENTS(s_aFeatures) * 80), *cp = pszBuf;
     629    Assert(pszBuf);
    602630    for (unsigned i = 0; i < RT_ELEMENTS(s_aFeatures); ++i)
    603     {
    604         if (s_aFeatures[i].fMask & fFeatures)
    605             Log3(("%s --> %s\n", INSTANCE(pThis), s_aFeatures[i].pcszDesc));
    606     }
     631        if (s_aFeatures[i].fMask & fFeatures) {
     632            int len = RTStrNLen(s_aFeatures[i].pcszDesc, MAXLINE);
     633            memcpy(cp, s_aFeatures[i].pcszDesc, len); /* intentionally drop trailing '\0' */
     634            cp += len;
     635        }
     636    Log3(("%s:\n%s\n", pcszText, pszBuf));
     637    RTMemFree(pszBuf);
     638
    607639#else  /* !LOG_ENABLED */
    608640    RT_NOREF3(pThis, fFeatures, pcszText);
     
    12761308        return false;
    12771309    }
    1278 
     1310/* @todo remove this debug hack that detects ARP from specific ping on development setup - pk */
    12791311uint8_t src[6] = { 0xA8, 0x20, 0x66, 0x57, 0x50, 0x3C };
    12801312uint8_t dst[6] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
     
    13551387
    13561388    LogFunc(("%s (%RTmac) pGso %s\n", INSTANCE(pThis), pvBuf, pGso ? "present" : "not present"));
    1357     VIRTIONET_PKT_HDR_T rxPktHdr;
     1389    VIRTIONET_PKT_HDR_T rxPktHdr = { 0 };
    13581390
    13591391    if (pGso)
     
    13831415        rxPktHdr.uHdrLen = pGso->cbHdrsTotal;
    13841416        rxPktHdr.uGsoSize = pGso->cbMaxSeg;
    1385         rxPktHdr.uChksumOffset = pGso->offHdr2;
     1417        rxPktHdr.uChksumStart = pGso->offHdr2;
    13861418    }
    13871419    else
     
    13901422        rxPktHdr.uGsoType = VIRTIONET_HDR_GSO_NONE;
    13911423    }
    1392 
    1393 //    virtioNetR3PacketDump(pThis, (const uint8_t *)pvBuf, cb, "<-- Incoming");
    13941424
    13951425    uint16_t cSegsAllocated = VIRTIONET_PREALLOCATE_RX_SEG_COUNT;
     
    13991429    AssertReturn(paVirtSegsToGuest, VERR_NO_MEMORY);
    14001430
     1431
     1432    uint8_t fAddPktHdr = true;
    14011433    RTGCPHYS gcPhysPktHdrNumBuffers;
    1402     uint32_t cDescs = 0;
    1403 
    1404     uint8_t fAddPktHdr = !!FEATURE_ENABLED(MRG_RXBUF);
    1405 
     1434    uint16_t cDescs;
    14061435    uint32_t uOffset;
    1407     for (uOffset = 0; uOffset < cb; )
    1408     {
    1409         /* Pull the next empty Guest Rx buffer from the  queue */
    1410 
     1436    for (cDescs = uOffset = 0; uOffset < cb; )
     1437    {
    14111438        PVIRTIO_DESC_CHAIN_T pDescChain;
     1439
    14121440        int rc = virtioCoreR3QueueGet(pDevIns, &pThis->Virtio, RXQIDX_QPAIR(idxQueue), &pDescChain, true);
    1413 
    14141441        AssertRC(rc == VINF_SUCCESS || rc == VERR_NOT_AVAILABLE);
    14151442
    14161443        /** @todo  Find a better way to deal with this */
    1417 
    14181444        AssertMsgReturn(rc == VINF_SUCCESS && pDescChain->cbPhysReturn,
    14191445                        ("Not enough Rx buffers in queue to accomodate ethernet packet\n"),
     
    14231449         * Assert it to reduce complexity. Robust solution would entail finding seg idx and offset of
    14241450         * virtio_net_header.num_buffers (to update field *after* hdr & pkts copied to gcPhys) */
    1425 
    14261451        AssertMsgReturn(pDescChain->pSgPhysReturn->paSegs[0].cbSeg >= sizeof(VIRTIONET_PKT_HDR_T),
    14271452                        ("Desc chain's first seg has insufficient space for pkt header!\n"),
     
    14311456
    14321457        /* Fill the Guest Rx buffer with data received from the interface */
    1433         for (uint16_t cSegs = 0; uOffset < cb && cbDescChainLeft; cSegs++)
     1458        for (uint16_t cSegs = 0; uOffset < cb && cbDescChainLeft; )
    14341459        {
    14351460            if (fAddPktHdr)
     
    14631488            uOffset += cbCropped;
    14641489            cDescs++;
    1465             RTSgBufInit(pVirtSegBufToGuest, paVirtSegsToGuest, cSegs + 1);
     1490            cSegs++;
     1491            RTSgBufInit(pVirtSegBufToGuest, paVirtSegsToGuest, cSegs);
    14661492            Log7Func(("Send Rx pkt to guest...\n"));
    14671493            virtioCoreR3QueuePut(pDevIns, &pThis->Virtio, RXQIDX_QPAIR(idxQueue),
     
    14771503    int rc = PDMDevHlpPCIPhysWrite(pDevIns, gcPhysPktHdrNumBuffers, &cDescs, sizeof(cDescs));
    14781504    AssertMsgRCReturn(rc,
    1479                       ("Failure updating descriptor count in pkt hdr in guest physical memory\n"),
    1480                       rc);
     1505                  ("Failure updating descriptor count in pkt hdr in guest physical memory\n"),
     1506                  rc);
     1507
     1508 /* Dump Rx Pkt after it's been written to guest physical memory via the virtio core API */
     1509    if (pThis->fLog)
     1510    {
     1511        virtioNetDumpGcPhysRxBuf(pDevIns, &rxPktHdr, cDescs, (uint8_t *)pvBuf, cb,
     1512                                 gcPhysPktHdrNumBuffers - RT_UOFFSETOF(VIRTIONET_PKT_HDR_T, uNumBuffers),
     1513                                 cb + sizeof(VIRTIONET_PKT_HDR_T));
     1514    }
    14811515
    14821516    virtioCoreQueueSync(pDevIns, &pThis->Virtio, RXQIDX_QPAIR(idxQueue));
    14831517
     1518
     1519if (pThis->fLog) {
     1520    RTThreadSleep(500);
     1521    RT_BREAKPOINT();
     1522    pThis->fBp = false;
     1523}
    14841524    RTMemFree(paVirtSegsToGuest);
    14851525    RTMemFree(pVirtSegBufToGuest);
     
    18151855            {
    18161856                LogFunc(("%s Ignoring CTRL class VIRTIONET_CTRL_ANNOUNCE. Not configured to handle it\n", INSTANCE(pThis)));
    1817                 virtioNetPrintFeatures(pThis, pThis->fNegotiatedFeatures, "Features");
     1857                virtioNetPrintFeatures(pThis->fNegotiatedFeatures, "Features");
    18181858                break;
    18191859            }
     
    21732213static DECLCALLBACK(int) virtioNetR3WorkerThread(PPDMDEVINS pDevIns, PPDMTHREAD pThread)
    21742214{
    2175     uint16_t const     idxQueue      = (uint16_t)(uintptr_t)pThread->pvUser;
     2215    uint16_t const     idxQueue  = (uint16_t)(uintptr_t)pThread->pvUser;
    21762216    PVIRTIONET         pThis     = PDMDEVINS_2_DATA(pDevIns, PVIRTIONET);
    21772217    PVIRTIONETCC       pThisCC   = PDMDEVINS_2_DATA_CC(pDevIns, PVIRTIONETCC);
     
    24382478    if (fVirtioReady)
    24392479    {
     2480pThis->fBp = true;
    24402481        LogFunc(("%s VirtIO ready\n-----------------------------------------------------------------------------------------\n",
    24412482                 INSTANCE(pThis)));
     
    24442485        pThisCC->fQuiescing  = false;
    24452486        pThis->fNegotiatedFeatures = virtioCoreGetAcceptedFeatures(pVirtio);
    2446 
     2487        virtioNetPrintFeatures(VIRTIONET_HOST_FEATURES_OFFERED, "Offered Features");
     2488        virtioNetPrintFeatures(pThis->fNegotiatedFeatures, "Negotiated Features");
    24472489        for (unsigned idxQueue = 0; idxQueue < pThis->cVirtQueues; idxQueue++)
    24482490        {
Note: See TracChangeset for help on using the changeset viewer.

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