VirtualBox

Changeset 84803 in vbox for trunk/src/VBox/Devices/Storage


Ignore:
Timestamp:
Jun 12, 2020 6:17:35 AM (5 years ago)
Author:
vboxsync
Message:

Network/DevVirtioNet_1_0.cpp: Rename API functions to refer to Virtq instead of Queue to be more Virtio like and disambiguate from other queue types. Temporarily enable build in Config.kmk to let the build machines catch errors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Storage/DevVirtioSCSI.cpp

    r84786 r84803  
    8181#define VIRTIOSCSI_HOST_SCSI_FEATURES_OFFERED       VIRTIOSCSI_HOST_SCSI_FEATURES_NONE
    8282
    83 #define VIRTIOSCSI_REQ_QUEUE_CNT                    4           /**< T.B.D. Consider increasing                      */
    84 #define VIRTIOSCSI_QUEUE_CNT                        (VIRTIOSCSI_REQ_QUEUE_CNT + 2)
     83#define VIRTIOSCSI_REQ_VIRTQ_CNT                    4           /**< T.B.D. Consider increasing                      */
     84#define VIRTIOSCSI_VIRTQ_CNT                        (VIRTIOSCSI_REQ_VIRTQ_CNT + 2)
    8585#define VIRTIOSCSI_MAX_TARGETS                      256         /**< T.B.D. Figure out a a good value for this.      */
    8686#define VIRTIOSCSI_MAX_LUN                          256         /**< VirtIO specification, section 5.6.4             */
     
    112112#define VIRTQ_REQ_BASE                              2           /**< Spec-defined base index of request queues       */
    113113
    114 #define VIRTQNAME(idxQueue) (pThis->aszVirtqNames[idxQueue])            /**< Macro to get queue name from its index          */
    115 #define CBVIRTQNAME(idxQueue) RTStrNLen(VIRTQNAME(idxQueue), sizeof(VIRTQNAME(idxQueue)))
    116 
    117 #define IS_REQ_QUEUE(idxQueue) (idxQueue >= VIRTQ_REQ_BASE && idxQueue < VIRTIOSCSI_QUEUE_CNT)
     114#define VIRTQNAME(idxVirtq) (pThis->aszVirtqNames[idxVirtq])            /**< Macro to get queue name from its index          */
     115#define CBVIRTQNAME(idxVirtq) RTStrNLen(VIRTQNAME(idxVirtq), sizeof(VIRTQNAME(idxVirtq)))
     116
     117#define IS_REQ_VIRTQ(idxVirtq) (idxVirtq >= VIRTQ_REQ_BASE && idxVirtq < VIRTIOSCSI_VIRTQ_CNT)
    118118
    119119#define VIRTIO_IS_IN_DIRECTION(pMediaExTxDirEnumValue) \
     
    123123    ((pMediaExTxDirEnumValue) == PDMMEDIAEXIOREQSCSITXDIR_TO_DEVICE)
    124124
    125 #define IS_VIRTQ_EMPTY(pDevIns, pVirtio, idxQueue) \
    126             (virtioCoreQueueAvailCount(pDevIns, pVirtio, idxQueue) == 0)
     125#define IS_VIRTQ_EMPTY(pDevIns, pVirtio, idxVirtq) \
     126            (virtioCoreVirtqAvailCount(pDevIns, pVirtio, idxVirtq) == 0)
    127127
    128128
     
    137137typedef struct virtio_scsi_config
    138138{
    139     uint32_t uNumQueues;                                        /**< num_queues       \# of req q's exposed by dev   */
     139    uint32_t uNumVirtqs;                                        /**< num_queues       \# of req q's exposed by dev   */
    140140    uint32_t uSegMax;                                           /**< seg_max          Max \# of segs allowed in cmd  */
    141141    uint32_t uMaxSectors;                                       /**< max_sectors      Hint to guest max xfer to use  */
     
    427427
    428428    /** Per device-bound virtq worker-thread contexts (eventq slot unused) */
    429     VIRTIOSCSIWORKER                aWorkers[VIRTIOSCSI_QUEUE_CNT];
     429    VIRTIOSCSIWORKER                aWorkers[VIRTIOSCSI_VIRTQ_CNT];
    430430
    431431    /** Instance name */
     
    433433
    434434    /** Device-specific spec-based VirtIO VIRTQNAMEs */
    435     char                            aszVirtqNames[VIRTIOSCSI_QUEUE_CNT][VIRTIO_MAX_QUEUE_NAME_SIZE];
     435    char                            aszVirtqNames[VIRTIOSCSI_VIRTQ_CNT][VIRTIO_MAX_VIRTQ_NAME_SIZE];
    436436
    437437    /** Track which VirtIO queues we've attached to */
    438     bool                            afQueueAttached[VIRTIOSCSI_QUEUE_CNT];
     438    bool                            afVirtqAttached[VIRTIOSCSI_VIRTQ_CNT];
    439439
    440440    /** Set if events missed due to lack of bufs avail on eventq */
     
    488488
    489489    /** Per device-bound virtq worker-thread contexts (eventq slot unused) */
    490     VIRTIOSCSIWORKERR3              aWorkers[VIRTIOSCSI_QUEUE_CNT];
     490    VIRTIOSCSIWORKERR3              aWorkers[VIRTIOSCSI_VIRTQ_CNT];
    491491
    492492    /** Device base interface. */
     
    503503    R3PTRTYPE(PPDMIMEDIANOTIFY)     pMediaNotify;
    504504
    505     /** Queue to send tasks to R3. - HC ptr */
    506     R3PTRTYPE(PPDMQUEUE)            pNotifierQueueR3;
     505    /** Virtq to send tasks to R3. - HC ptr */
     506    R3PTRTYPE(PPDMQUEUE)            pNotifierVirtqR3;
    507507
    508508    /** True if in the process of quiescing I/O */
     
    557557    PDMMEDIAEXIOREQ                hIoReq;                      /**< Handle of I/O request                             */
    558558    PVIRTIOSCSITARGET              pTarget;                     /**< Target                                            */
    559     uint16_t                       idxQueue;                        /**< Index of queue this request arrived on            */
     559    uint16_t                       idxVirtq;                        /**< Index of queue this request arrived on            */
    560560    PVIRTIO_DESC_CHAIN_T           pDescChain;                  /**< Prepared desc chain pulled from virtq avail ring  */
    561561    size_t                         cbDataIn;                    /**< size of dataout buffer                            */
     
    573573
    574574/**
    575  * callback_method_impl{VIRTIOCORER0,pfnQueueNotified}
     575 * callback_method_impl{VIRTIOCORER0,pfnVirtqNotified}
    576576 * @todo this causes burn if I prefix with at-sign. This callback is in VIRTIOCORER0 and VIRTIOCORER3
    577577 */
    578 static DECLCALLBACK(void) virtioScsiNotified(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t idxQueue)
     578static DECLCALLBACK(void) virtioScsiNotified(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t idxVirtq)
    579579{
    580580
     
    582582    PVIRTIOSCSI pThis   = PDMDEVINS_2_DATA(pDevIns, PVIRTIOSCSI);
    583583
    584     AssertReturnVoid(idxQueue < VIRTIOSCSI_QUEUE_CNT);
    585     PVIRTIOSCSIWORKER pWorker = &pThis->aWorkers[idxQueue];
     584    AssertReturnVoid(idxVirtq < VIRTIOSCSI_VIRTQ_CNT);
     585    PVIRTIOSCSIWORKER pWorker = &pThis->aWorkers[idxVirtq];
    586586
    587587#if defined (IN_RING3) && defined (LOG_ENABLED)
     
    589589#endif
    590590
    591     if (idxQueue == CONTROLQ_IDX || IS_REQ_QUEUE(idxQueue))
    592     {
    593         Log6Func(("%s has available data\n", VIRTQNAME(idxQueue)));
     591    if (idxVirtq == CONTROLQ_IDX || IS_REQ_VIRTQ(idxVirtq))
     592    {
     593        Log6Func(("%s has available data\n", VIRTQNAME(idxVirtq)));
    594594        /* Wake queue's worker thread up if sleeping */
    595595        if (!ASMAtomicXchgBool(&pWorker->fNotified, true))
     
    597597            if (ASMAtomicReadBool(&pWorker->fSleeping))
    598598            {
    599                 Log6Func(("waking %s worker.\n", VIRTQNAME(idxQueue)));
     599                Log6Func(("waking %s worker.\n", VIRTQNAME(idxVirtq)));
    600600                int rc = PDMDevHlpSUPSemEventSignal(pDevIns, pWorker->hEvtProcess);
    601601                AssertRC(rc);
     
    603603        }
    604604    }
    605     else if (idxQueue == EVENTQ_IDX)
    606     {
    607         Log3Func(("Driver queued buffer(s) to %s\n", VIRTQNAME(idxQueue)));
     605    else if (idxVirtq == EVENTQ_IDX)
     606    {
     607        Log3Func(("Driver queued buffer(s) to %s\n", VIRTQNAME(idxVirtq)));
    608608//        if (ASMAtomicXchgBool(&pThis->fEventsMissed, false))
    609609//            virtioScsiR3ReportEventsMissed(pDevIns, pThis, 0);
    610610    }
    611611    else
    612         LogFunc(("Unexpected queue idx (ignoring): %d\n", idxQueue));
     612        LogFunc(("Unexpected queue idx (ignoring): %d\n", idxVirtq));
    613613}
    614614
     
    619619DECLINLINE(void) virtioScsiSetVirtqNames(PVIRTIOSCSI pThis)
    620620{
    621     RTStrCopy(pThis->aszVirtqNames[CONTROLQ_IDX], VIRTIO_MAX_QUEUE_NAME_SIZE, "controlq");
    622     RTStrCopy(pThis->aszVirtqNames[EVENTQ_IDX],   VIRTIO_MAX_QUEUE_NAME_SIZE, "eventq");
    623     for (uint16_t idxQueue = VIRTQ_REQ_BASE; idxQueue < VIRTQ_REQ_BASE + VIRTIOSCSI_REQ_QUEUE_CNT; idxQueue++)
    624         RTStrPrintf(pThis->aszVirtqNames[idxQueue], VIRTIO_MAX_QUEUE_NAME_SIZE,
    625                     "requestq<%d>", idxQueue - VIRTQ_REQ_BASE);
     621    RTStrCopy(pThis->aszVirtqNames[CONTROLQ_IDX], VIRTIO_MAX_VIRTQ_NAME_SIZE, "controlq");
     622    RTStrCopy(pThis->aszVirtqNames[EVENTQ_IDX],   VIRTIO_MAX_VIRTQ_NAME_SIZE, "eventq");
     623    for (uint16_t idxVirtq = VIRTQ_REQ_BASE; idxVirtq < VIRTQ_REQ_BASE + VIRTIOSCSI_REQ_VIRTQ_CNT; idxVirtq++)
     624        RTStrPrintf(pThis->aszVirtqNames[idxVirtq], VIRTIO_MAX_VIRTQ_NAME_SIZE,
     625                    "requestq<%d>", idxVirtq - VIRTQ_REQ_BASE);
    626626}
    627627
     
    755755
    756756    PVIRTIO_DESC_CHAIN_T pDescChain = NULL;
    757     int rc = virtioCoreR3QueueGet(pDevIns, &pThis->Virtio, EVENTQ_IDX, &pDescChain, true);
     757    int rc = virtioCoreR3VirtqGet(pDevIns, &pThis->Virtio, EVENTQ_IDX, &pDescChain, true);
    758758    if (rc == VERR_NOT_AVAILABLE)
    759759    {
     
    783783    RTSgBufInit(&ReqSgBuf, aReqSegs, RT_ELEMENTS(aReqSegs));
    784784
    785     rc = virtioCoreR3QueuePut(pDevIns, &pThis->Virtio, EVENTQ_IDX, &ReqSgBuf, pDescChain, true /*fFence*/);
     785    rc = virtioCoreR3VirtqPut(pDevIns, &pThis->Virtio, EVENTQ_IDX, &ReqSgBuf, pDescChain, true /*fFence*/);
    786786    if (rc == VINF_SUCCESS)
    787         virtioCoreQueueSync(pDevIns, &pThis->Virtio, EVENTQ_IDX, false);
     787        virtioCoreVirtqSync(pDevIns, &pThis->Virtio, EVENTQ_IDX, false);
    788788    else
    789789        LogRel(("Error writing control message to guest\n"));
     
    811811 * @param   pThis       VirtIO SCSI shared instance data.
    812812 * @param   pThisCC     VirtIO SCSI ring-3 instance data.
    813  * @param   idxQueue        Queue index
     813 * @param   idxVirtq        Virtq index
    814814 * @param   pDescChain  Pointer to pre-processed descriptor chain pulled from virtq
    815815 * @param   pRespHdr    Response header
     
    819819 * @returns VINF_SUCCESS
    820820 */
    821 static int virtioScsiR3ReqErr(PPDMDEVINS pDevIns, PVIRTIOSCSI pThis, PVIRTIOSCSICC pThisCC, uint16_t idxQueue,
     821static int virtioScsiR3ReqErr(PPDMDEVINS pDevIns, PVIRTIOSCSI pThis, PVIRTIOSCSICC pThisCC, uint16_t idxVirtq,
    822822                              PVIRTIO_DESC_CHAIN_T pDescChain, REQ_RESP_HDR_T *pRespHdr, uint8_t *pbSense,
    823823                              size_t cbSenseCfg)
     
    853853        pRespHdr->uResponse = VIRTIOSCSI_S_RESET;
    854854
    855     virtioCoreR3QueuePut(pDevIns, &pThis->Virtio, idxQueue, &ReqSgBuf, pDescChain, true /* fFence */);
    856     virtioCoreQueueSync(pDevIns, &pThis->Virtio, idxQueue);
     855    virtioCoreR3VirtqPut(pDevIns, &pThis->Virtio, idxVirtq, &ReqSgBuf, pDescChain, true /* fFence */);
     856    virtioCoreVirtqSync(pDevIns, &pThis->Virtio, idxVirtq);
    857857
    858858    if (!ASMAtomicDecU32(&pThis->cActiveReqs) && pThisCC->fQuiescing)
     
    872872 * @param   pThis       VirtIO SCSI shared instance data.
    873873 * @param   pThisCC     VirtIO SCSI ring-3 instance data.
    874  * @param   idxQueue        Queue index
     874 * @param   idxVirtq        Virtq index
    875875 * @param   pDescChain  Pointer to pre-processed descriptor chain pulled from virtq
    876876 * @param   cbResidual  The number of residual bytes or something like that.
     
    883883 * @returns VINF_SUCCESS
    884884 */
    885 static int virtioScsiR3ReqErr4(PPDMDEVINS pDevIns, PVIRTIOSCSI pThis, PVIRTIOSCSICC pThisCC, uint16_t idxQueue,
     885static int virtioScsiR3ReqErr4(PPDMDEVINS pDevIns, PVIRTIOSCSI pThis, PVIRTIOSCSICC pThisCC, uint16_t idxVirtq,
    886886                               PVIRTIO_DESC_CHAIN_T pDescChain, size_t cbResidual, uint8_t bStatus, uint8_t bResponse,
    887887                               uint8_t *pbSense, size_t cbSense, size_t cbSenseCfg)
     
    894894    RespHdr.uResponse        = bResponse;
    895895
    896     return virtioScsiR3ReqErr(pDevIns, pThis, pThisCC, idxQueue, pDescChain, &RespHdr, pbSense, cbSenseCfg);
     896    return virtioScsiR3ReqErr(pDevIns, pThis, pThisCC, idxVirtq, pDescChain, &RespHdr, pbSense, cbSenseCfg);
    897897}
    898898
     
    10161016        respHdr.uResidual  = pReq->cbDataIn & UINT32_MAX;
    10171017
    1018         virtioScsiR3ReqErr(pDevIns, pThis, pThisCC, pReq->idxQueue, pReq->pDescChain, &respHdr, abSense,
     1018        virtioScsiR3ReqErr(pDevIns, pThis, pThisCC, pReq->idxVirtq, pReq->pDescChain, &respHdr, abSense,
    10191019                           RT_MIN(pThis->virtioScsiConfig.uSenseSize, VIRTIOSCSI_SENSE_SIZE_MAX));
    10201020    }
     
    10421042                        VERR_BUFFER_OVERFLOW);
    10431043
    1044         virtioCoreR3QueuePut(pDevIns, &pThis->Virtio, pReq->idxQueue, &ReqSgBuf, pReq->pDescChain, true /* fFence TBD */);
    1045         virtioCoreQueueSync(pDevIns, &pThis->Virtio, pReq->idxQueue);
     1044        virtioCoreR3VirtqPut(pDevIns, &pThis->Virtio, pReq->idxVirtq, &ReqSgBuf, pReq->pDescChain, true /* fFence TBD */);
     1045        virtioCoreVirtqSync(pDevIns, &pThis->Virtio, pReq->idxVirtq);
    10461046
    10471047        Log2(("-----------------------------------------------------------------------------------------\n"));
     
    10581058/**
    10591059 * @interface_method_impl{PDMIMEDIAEXPORT,pfnIoReqCopyFromBuf}
    1060  *
     1060
    10611061 * Copy virtual memory from VSCSI layer to guest physical memory
    10621062 */
     
    11441144 */
    11451145static int virtioScsiR3ReqSubmit(PPDMDEVINS pDevIns, PVIRTIOSCSI pThis, PVIRTIOSCSICC pThisCC,
    1146                                  uint16_t idxQueue, PVIRTIO_DESC_CHAIN_T pDescChain)
     1146                                 uint16_t idxVirtq, PVIRTIO_DESC_CHAIN_T pDescChain)
    11471147{
    11481148
     
    11941194    if (uType == 0xc1 && uTarget == 0x01)
    11951195    {
    1196         LogRel(("* * * REPORT LUNS LU ACCESSED * * * "));
     1196        LogRel(("* * * WARNING: REPORT LUNS LU ACCESSED. FEATURE NOT IMPLEMENTED SEE DevVirtioScsi.cpp * * * "));
    11971197        /* Force rejection. */ /** @todo figure out right way to handle. Note this is a very
    11981198         * vague and confusing part of the VirtIO spec (which deviates from the SCSI standard).
    11991199         * I have not been able to determine how to implement this properly.  I've checked the
    1200          * source code of Guest drivers, and so far none seem to use it. If logs show
    1201          * this warning, implementing it can be re-visited */
     1200         * source code of Guest drivers, and so far none seem to use it. If this message is logged,
     1201         * meaning a guest expects this feature, implementing it can be re-visited */
    12021202        uScsiLun = 0xff;
    12031203    }
     
    12321232    {
    12331233        Log2Func(("Error submitting request, bad LUN format\n"));
    1234         return virtioScsiR3ReqErr4(pDevIns, pThis, pThisCC, idxQueue, pDescChain, cbDataIn + cbDataOut, 0 /*bStatus*/,
     1234        return virtioScsiR3ReqErr4(pDevIns, pThis, pThisCC, idxVirtq, pDescChain, cbDataIn + cbDataOut, 0 /*bStatus*/,
    12351235                                   VIRTIOSCSI_S_FAILURE, NULL /*pbSense*/, 0 /*cbSense*/, cbSenseCfg);
    12361236    }
     
    12471247                              0, SCSI_SENSE_ILLEGAL_REQUEST,
    12481248                              0, 0, 0, 0, 10, SCSI_ASC_LOGICAL_UNIT_NOT_SUPPORTED, 0, 0 };
    1249         return virtioScsiR3ReqErr4(pDevIns, pThis, pThisCC, idxQueue, pDescChain, cbDataIn + cbDataOut, SCSI_STATUS_CHECK_CONDITION,
     1249        return virtioScsiR3ReqErr4(pDevIns, pThis, pThisCC, idxVirtq, pDescChain, cbDataIn + cbDataOut, SCSI_STATUS_CHECK_CONDITION,
    12501250                                   VIRTIOSCSI_S_BAD_TARGET, abSense, sizeof(abSense), cbSenseCfg);
    12511251    }
     
    12581258                              0, SCSI_SENSE_ILLEGAL_REQUEST,
    12591259                              0, 0, 0, 0, 10, SCSI_ASC_LOGICAL_UNIT_NOT_SUPPORTED, 0, 0 };
    1260         return virtioScsiR3ReqErr4(pDevIns, pThis, pThisCC, idxQueue, pDescChain, cbDataIn + cbDataOut, SCSI_STATUS_CHECK_CONDITION,
     1260        return virtioScsiR3ReqErr4(pDevIns, pThis, pThisCC, idxVirtq, pDescChain, cbDataIn + cbDataOut, SCSI_STATUS_CHECK_CONDITION,
    12611261                                   VIRTIOSCSI_S_OK, abSense, sizeof(abSense), cbSenseCfg);
    12621262    }
     
    12661266    {
    12671267        Log2Func(("Aborting req submission because reset is in progress\n"));
    1268         return virtioScsiR3ReqErr4(pDevIns, pThis, pThisCC, idxQueue, pDescChain, cbDataIn + cbDataOut, SCSI_STATUS_OK,
     1268        return virtioScsiR3ReqErr4(pDevIns, pThis, pThisCC, idxVirtq, pDescChain, cbDataIn + cbDataOut, SCSI_STATUS_OK,
    12691269                                   VIRTIOSCSI_S_RESET, NULL /*pbSense*/, 0 /*cbSense*/, cbSenseCfg);
    12701270    }
     
    12771277        uint8_t abSense[] = { RT_BIT(7) | SCSI_SENSE_RESPONSE_CODE_CURR_FIXED,
    12781278                              0, SCSI_SENSE_ILLEGAL_REQUEST, 0, 0, 0, 0, 10, 0, 0, 0 };
    1279         return virtioScsiR3ReqErr4(pDevIns, pThis, pThisCC, idxQueue, pDescChain, cbDataIn + cbDataOut, SCSI_STATUS_CHECK_CONDITION,
     1279        return virtioScsiR3ReqErr4(pDevIns, pThis, pThisCC, idxVirtq, pDescChain, cbDataIn + cbDataOut, SCSI_STATUS_CHECK_CONDITION,
    12801280                                   VIRTIOSCSI_S_FAILURE, abSense, sizeof(abSense), cbSenseCfg);
    12811281    }
     
    12951295    pReq->hIoReq      = hIoReq;
    12961296    pReq->pTarget     = pTarget;
    1297     pReq->idxQueue        = idxQueue;
     1297    pReq->idxVirtq    = idxVirtq;
    12981298    pReq->cbDataIn    = cbDataIn;
    12991299    pReq->cbDataOut   = cbDataOut;
     
    13231323         */
    13241324        Assert(RT_FAILURE_NP(rc));
    1325         Log2Func(("Request submission error from lower-level driver\n"));
     1325        Log2Func(("Request-submission error from lower-level driver\n"));
    13261326        uint8_t uASC, uASCQ = 0;
    13271327        switch (rc)
     
    13421342        respHdr.uResponse  = VIRTIOSCSI_S_FAILURE;
    13431343        respHdr.uResidual  = (cbDataIn + cbDataOut) & UINT32_MAX;
    1344         virtioScsiR3ReqErr(pDevIns, pThis, pThisCC, idxQueue, pDescChain, &respHdr, abSense, cbSenseCfg);
     1344        virtioScsiR3ReqErr(pDevIns, pThis, pThisCC, idxVirtq, pDescChain, &respHdr, abSense, cbSenseCfg);
    13451345        virtioScsiR3FreeReq(pTarget, pReq);
    13461346    }
     
    13561356 * @param   pThis       VirtIO SCSI shared instance data.
    13571357 * @param   pThisCC     VirtIO SCSI ring-3 instance data.
    1358  * @param   idxQueue    CONTROLQ_IDX
     1358 * @param   idxVirtq    CONTROLQ_IDX
    13591359 * @param   pDescChain  Descriptor chain to process.
    13601360 */
    13611361static int virtioScsiR3Ctrl(PPDMDEVINS pDevIns, PVIRTIOSCSI pThis, PVIRTIOSCSICC pThisCC,
    1362                             uint16_t idxQueue, PVIRTIO_DESC_CHAIN_T pDescChain)
     1362                            uint16_t idxVirtq, PVIRTIO_DESC_CHAIN_T pDescChain)
    13631363{
    13641364    AssertReturn(pDescChain->cbPhysSend >= RT_MIN(sizeof(VIRTIOSCSI_CTRL_AN_T),
     
    14011401            uint32_t uScsiLun = RT_MAKE_U16(ScsiCtrlUnion.Tmf.abScsiLun[3], ScsiCtrlUnion.Tmf.abScsiLun[2]) & 0x3fff;
    14021402            Log2Func(("[%s] (Target: %d LUN: %d)  Task Mgt Function: %s\n",
    1403                       VIRTQNAME(idxQueue), uTarget, uScsiLun, virtioGetTMFTypeText(ScsiCtrlUnion.Tmf.uSubtype)));
     1403                      VIRTQNAME(idxVirtq), uTarget, uScsiLun, virtioGetTMFTypeText(ScsiCtrlUnion.Tmf.uSubtype)));
    14041404
    14051405            if (uTarget >= pThis->cTargets || !pThisCC->paTargetInstances[uTarget].fPresent)
     
    14621462                virtioGetControlAsyncMaskText(szTypeText, sizeof(szTypeText), ScsiCtrlUnion.AsyncNotify.fEventsRequested);
    14631463                Log2Func(("[%s] (Target: %d LUN: %d)  Async. Notification Query: %s\n",
    1464                           VIRTQNAME(idxQueue), uTarget, uScsiLun, szTypeText));
     1464                          VIRTQNAME(idxVirtq), uTarget, uScsiLun, szTypeText));
    14651465            }
    14661466#endif
     
    14871487                virtioGetControlAsyncMaskText(szTypeText, sizeof(szTypeText), ScsiCtrlUnion.AsyncNotify.fEventsRequested);
    14881488                Log2Func(("[%s] (Target: %d LUN: %d)  Async. Notification Subscribe: %s\n",
    1489                           VIRTQNAME(idxQueue), uTarget, uScsiLun, szTypeText));
     1489                          VIRTQNAME(idxVirtq), uTarget, uScsiLun, szTypeText));
    14901490            }
    14911491#endif
     
    15081508        default:
    15091509        {
    1510             LogFunc(("Unknown control type extracted from %s: %u\n", VIRTQNAME(idxQueue), ScsiCtrlUnion.Type.uType));
     1510            LogFunc(("Unknown control type extracted from %s: %u\n", VIRTQNAME(idxVirtq), ScsiCtrlUnion.Type.uType));
    15111511
    15121512            bResponse = VIRTIOSCSI_S_FAILURE;
     
    15271527    RTSgBufInit(&ReqSgBuf, aReqSegs, cSegs);
    15281528
    1529     virtioCoreR3QueuePut(pDevIns, &pThis->Virtio, idxQueue, &ReqSgBuf, pDescChain, true /*fFence*/);
    1530     virtioCoreQueueSync(pDevIns, &pThis->Virtio, idxQueue);
     1529    virtioCoreR3VirtqPut(pDevIns, &pThis->Virtio, idxVirtq, &ReqSgBuf, pDescChain, true /*fFence*/);
     1530    virtioCoreVirtqSync(pDevIns, &pThis->Virtio, idxVirtq);
    15311531
    15321532    return VINF_SUCCESS;
     
    15471547static DECLCALLBACK(int) virtioScsiR3WorkerThread(PPDMDEVINS pDevIns, PPDMTHREAD pThread)
    15481548{
    1549     uint16_t const      idxQueue  = (uint16_t)(uintptr_t)pThread->pvUser;
     1549    uint16_t const      idxVirtq  = (uint16_t)(uintptr_t)pThread->pvUser;
    15501550    PVIRTIOSCSI         pThis     = PDMDEVINS_2_DATA(pDevIns, PVIRTIOSCSI);
    15511551    PVIRTIOSCSICC       pThisCC   = PDMDEVINS_2_DATA_CC(pDevIns, PVIRTIOSCSICC);
    1552     PVIRTIOSCSIWORKER   pWorker   = &pThis->aWorkers[idxQueue];
    1553     PVIRTIOSCSIWORKERR3 pWorkerR3 = &pThisCC->aWorkers[idxQueue];
     1552    PVIRTIOSCSIWORKER   pWorker   = &pThis->aWorkers[idxVirtq];
     1553    PVIRTIOSCSIWORKERR3 pWorkerR3 = &pThisCC->aWorkers[idxVirtq];
    15541554
    15551555    if (pThread->enmState == PDMTHREADSTATE_INITIALIZING)
     
    15581558    while (pThread->enmState == PDMTHREADSTATE_RUNNING)
    15591559    {
    1560         if (!pWorkerR3->cRedoDescs && IS_VIRTQ_EMPTY(pDevIns, &pThis->Virtio, idxQueue))
     1560        if (!pWorkerR3->cRedoDescs && IS_VIRTQ_EMPTY(pDevIns, &pThis->Virtio, idxVirtq))
    15611561        {
    15621562            /* Atomic interlocks avoid missing alarm while going to sleep & notifier waking the awoken */
     
    15651565            if (!fNotificationSent)
    15661566            {
    1567                 Log6Func(("%s worker sleeping...\n", VIRTQNAME(idxQueue)));
     1567                Log6Func(("%s worker sleeping...\n", VIRTQNAME(idxVirtq)));
    15681568                Assert(ASMAtomicReadBool(&pWorker->fSleeping));
    15691569                int rc = PDMDevHlpSUPSemEventWaitNoResume(pDevIns, pWorker->hEvtProcess, RT_INDEFINITE_WAIT);
     
    15731573                if (rc == VERR_INTERRUPTED)
    15741574                    continue;
    1575                 Log6Func(("%s worker woken\n", VIRTQNAME(idxQueue)));
     1575                Log6Func(("%s worker woken\n", VIRTQNAME(idxVirtq)));
    15761576                ASMAtomicWriteBool(&pWorker->fNotified, false);
    15771577            }
     
    15791579        }
    15801580
    1581         if (!pThis->afQueueAttached[idxQueue])
     1581        if (!pThis->afVirtqAttached[idxVirtq])
    15821582        {
    1583             LogFunc(("%s queue not attached, worker aborting...\n", VIRTQNAME(idxQueue)));
     1583            LogFunc(("%s queue not attached, worker aborting...\n", VIRTQNAME(idxVirtq)));
    15841584            break;
    15851585        }
     
    15901590             {
    15911591                  PVIRTIO_DESC_CHAIN_T pDescChain;
    1592                   int rc = virtioCoreR3DescChainGet(pDevIns, &pThis->Virtio, idxQueue,
     1592                  int rc = virtioCoreR3DescChainGet(pDevIns, &pThis->Virtio, idxVirtq,
    15931593                                                    pWorkerR3->auRedoDescs[i], &pDescChain);
    15941594                  if (RT_FAILURE(rc))
    15951595                      LogRel(("Error fetching desc chain to redo, %Rrc", rc));
    15961596
    1597                   rc = virtioScsiR3ReqSubmit(pDevIns, pThis, pThisCC, idxQueue, pDescChain);
     1597                  rc = virtioScsiR3ReqSubmit(pDevIns, pThis, pThisCC, idxVirtq, pDescChain);
    15981598                  if (RT_FAILURE(rc))
    15991599                      LogRel(("Error submitting req packet, resetting %Rrc", rc));
     
    16031603             pWorkerR3->cRedoDescs = 0;
    16041604
    1605              Log6Func(("fetching next descriptor chain from %s\n", VIRTQNAME(idxQueue)));
     1605             Log6Func(("fetching next descriptor chain from %s\n", VIRTQNAME(idxVirtq)));
    16061606             PVIRTIO_DESC_CHAIN_T pDescChain = NULL;
    1607              int rc = virtioCoreR3QueueGet(pDevIns, &pThis->Virtio, idxQueue, &pDescChain, true);
     1607             int rc = virtioCoreR3VirtqGet(pDevIns, &pThis->Virtio, idxVirtq, &pDescChain, true);
    16081608             if (rc == VERR_NOT_AVAILABLE)
    16091609             {
    1610                  Log6Func(("Nothing found in %s\n", VIRTQNAME(idxQueue)));
     1610                 Log6Func(("Nothing found in %s\n", VIRTQNAME(idxVirtq)));
    16111611                 continue;
    16121612             }
    16131613
    16141614             AssertRC(rc);
    1615              if (idxQueue == CONTROLQ_IDX)
    1616                  virtioScsiR3Ctrl(pDevIns, pThis, pThisCC, idxQueue, pDescChain);
     1615             if (idxVirtq == CONTROLQ_IDX)
     1616                 virtioScsiR3Ctrl(pDevIns, pThis, pThisCC, idxVirtq, pDescChain);
    16171617             else /* request queue index */
    16181618             {
    1619                  rc = virtioScsiR3ReqSubmit(pDevIns, pThis, pThisCC, idxQueue, pDescChain);
     1619                 rc = virtioScsiR3ReqSubmit(pDevIns, pThis, pThisCC, idxVirtq, pDescChain);
    16201620                 if (RT_FAILURE(rc))
    16211621                     LogRel(("Error submitting req packet, resetting %Rrc", rc));
     
    17031703        pThisCC->fQuiescing  = false;
    17041704
    1705         for (unsigned i = 0; i < VIRTIOSCSI_QUEUE_CNT; i++)
    1706             pThis->afQueueAttached[i] = true;
     1705        for (unsigned i = 0; i < VIRTIOSCSI_VIRTQ_CNT; i++)
     1706            pThis->afVirtqAttached[i] = true;
    17071707    }
    17081708    else
    17091709    {
    17101710        LogFunc(("VirtIO is resetting\n"));
    1711         for (unsigned i = 0; i < VIRTIOSCSI_QUEUE_CNT; i++)
    1712             pThis->afQueueAttached[i] = false;
     1711        for (unsigned i = 0; i < VIRTIOSCSI_VIRTQ_CNT; i++)
     1712            pThis->afVirtqAttached[i] = false;
    17131713    }
    17141714}
     
    18351835    AssertReturn(pv && cb <= sizeof(uint32_t), fWrite ? VINF_SUCCESS : VINF_IOM_MMIO_UNUSED_00);
    18361836
    1837     if (MATCH_SCSI_CONFIG(uNumQueues))
    1838         SCSI_CONFIG_ACCESSOR_READONLY(uNumQueues);
     1837    if (MATCH_SCSI_CONFIG(uNumVirtqs))
     1838        SCSI_CONFIG_ACCESSOR_READONLY(uNumVirtqs);
    18391839    else
    18401840    if (MATCH_SCSI_CONFIG(uSegMax))
     
    19671967
    19681968    virtioScsiSetVirtqNames(pThis);
    1969     for (int idxQueue = 0; idxQueue < VIRTIOSCSI_QUEUE_CNT; idxQueue++)
    1970         pHlp->pfnSSMGetBool(pSSM, &pThis->afQueueAttached[idxQueue]);
    1971 
    1972     pHlp->pfnSSMGetU32(pSSM,  &pThis->virtioScsiConfig.uNumQueues);
     1969    for (int idxVirtq = 0; idxVirtq < VIRTIOSCSI_VIRTQ_CNT; idxVirtq++)
     1970        pHlp->pfnSSMGetBool(pSSM, &pThis->afVirtqAttached[idxVirtq]);
     1971
     1972    pHlp->pfnSSMGetU32(pSSM,  &pThis->virtioScsiConfig.uNumVirtqs);
    19731973    pHlp->pfnSSMGetU32(pSSM,  &pThis->virtioScsiConfig.uSegMax);
    19741974    pHlp->pfnSSMGetU32(pSSM,  &pThis->virtioScsiConfig.uMaxSectors);
     
    20072007                                              cReqsRedo, VIRTQ_MAX_ENTRIES));
    20082008
    2009         for (uint16_t idxQueue = VIRTQ_REQ_BASE; idxQueue < VIRTIOSCSI_QUEUE_CNT; idxQueue++)
     2009        for (uint16_t idxVirtq = VIRTQ_REQ_BASE; idxVirtq < VIRTIOSCSI_VIRTQ_CNT; idxVirtq++)
    20102010        {
    2011             PVIRTIOSCSIWORKERR3 pWorkerR3 = &pThisCC->aWorkers[idxQueue];
     2011            PVIRTIOSCSIWORKERR3 pWorkerR3 = &pThisCC->aWorkers[idxVirtq];
    20122012            pWorkerR3->cRedoDescs = 0;
    20132013        }
     
    20152015        for (int i = 0; i < cReqsRedo; i++)
    20162016        {
    2017             uint16_t idxQueue;
    2018             rc = pHlp->pfnSSMGetU16(pSSM, &idxQueue);
     2017            uint16_t idxVirtq;
     2018            rc = pHlp->pfnSSMGetU16(pSSM, &idxVirtq);
    20192019            AssertRCReturn(rc, rc);
    2020             AssertReturn(idxQueue < VIRTIOSCSI_QUEUE_CNT,
     2020            AssertReturn(idxVirtq < VIRTIOSCSI_VIRTQ_CNT,
    20212021                         pHlp->pfnSSMSetLoadError(pSSM, VERR_SSM_DATA_UNIT_FORMAT_CHANGED, RT_SRC_POS,
    20222022                                                  N_("Bad queue index for re-do in saved state (%#x, max %#x)"),
    2023                                                   idxQueue, VIRTIOSCSI_QUEUE_CNT - 1));
     2023                                                  idxVirtq, VIRTIOSCSI_VIRTQ_CNT - 1));
    20242024
    20252025            uint16_t idxHead;
     
    20312031                                                  idxHead, VIRTQ_MAX_ENTRIES - 1));
    20322032
    2033             PVIRTIOSCSIWORKERR3 pWorkerR3 = &pThisCC->aWorkers[idxQueue];
     2033            PVIRTIOSCSIWORKERR3 pWorkerR3 = &pThisCC->aWorkers[idxVirtq];
    20342034            pWorkerR3->auRedoDescs[pWorkerR3->cRedoDescs++] = idxHead;
    20352035            pWorkerR3->cRedoDescs %= VIRTQ_MAX_ENTRIES;
     
    20452045     * Nudge request queue workers
    20462046     */
    2047     for (int idxQueue = VIRTQ_REQ_BASE; idxQueue < VIRTIOSCSI_QUEUE_CNT; idxQueue++)
    2048     {
    2049         if (pThis->afQueueAttached[idxQueue])
     2047    for (int idxVirtq = VIRTQ_REQ_BASE; idxVirtq < VIRTIOSCSI_VIRTQ_CNT; idxVirtq++)
     2048    {
     2049        if (pThis->afVirtqAttached[idxVirtq])
    20502050        {
    2051             LogFunc(("Waking %s worker.\n", VIRTQNAME(idxQueue)));
    2052             int rc2 = PDMDevHlpSUPSemEventSignal(pDevIns, pThis->aWorkers[idxQueue].hEvtProcess);
     2051            LogFunc(("Waking %s worker.\n", VIRTQNAME(idxVirtq)));
     2052            int rc2 = PDMDevHlpSUPSemEventSignal(pDevIns, pThis->aWorkers[idxVirtq].hEvtProcess);
    20532053            AssertRCReturn(rc, rc2);
    20542054        }
     
    20692069    LogFunc(("SAVE EXEC!!\n"));
    20702070
    2071     for (int idxQueue = 0; idxQueue < VIRTIOSCSI_QUEUE_CNT; idxQueue++)
    2072         pHlp->pfnSSMPutBool(pSSM, pThis->afQueueAttached[idxQueue]);
    2073 
    2074     pHlp->pfnSSMPutU32(pSSM,  pThis->virtioScsiConfig.uNumQueues);
     2071    for (int idxVirtq = 0; idxVirtq < VIRTIOSCSI_VIRTQ_CNT; idxVirtq++)
     2072        pHlp->pfnSSMPutBool(pSSM, pThis->afVirtqAttached[idxVirtq]);
     2073
     2074    pHlp->pfnSSMPutU32(pSSM,  pThis->virtioScsiConfig.uNumVirtqs);
    20752075    pHlp->pfnSSMPutU32(pSSM,  pThis->virtioScsiConfig.uSegMax);
    20762076    pHlp->pfnSSMPutU32(pSSM,  pThis->virtioScsiConfig.uMaxSectors);
     
    21172117                 while(--cReqsRedo)
    21182118                 {
    2119                     pHlp->pfnSSMPutU16(pSSM, pReq->idxQueue);
     2119                    pHlp->pfnSSMPutU16(pSSM, pReq->idxVirtq);
    21202120                    pHlp->pfnSSMPutU16(pSSM, pReq->pDescChain->uHeadIdx);
    21212121
     
    23352335     * be awake due to new reqs coming in.
    23362336     */
    2337     for (uint16_t idxQueue = 0; idxQueue < VIRTIOSCSI_REQ_QUEUE_CNT; idxQueue++)
    2338     {
    2339         if (ASMAtomicReadBool(&pThis->aWorkers[idxQueue].fSleeping))
     2337    for (uint16_t idxVirtq = 0; idxVirtq < VIRTIOSCSI_REQ_VIRTQ_CNT; idxVirtq++)
     2338    {
     2339        if (ASMAtomicReadBool(&pThis->aWorkers[idxVirtq].fSleeping))
    23402340        {
    2341             Log6Func(("waking %s worker.\n", VIRTQNAME(idxQueue)));
    2342             int rc = PDMDevHlpSUPSemEventSignal(pDevIns, pThis->aWorkers[idxQueue].hEvtProcess);
     2341            Log6Func(("waking %s worker.\n", VIRTQNAME(idxVirtq)));
     2342            int rc = PDMDevHlpSUPSemEventSignal(pDevIns, pThis->aWorkers[idxVirtq].hEvtProcess);
    23432343            AssertRC(rc);
    23442344        }
     
    24142414    pThisCC->pMediaNotify = NULL;
    24152415
    2416     for (unsigned idxQueue = 0; idxQueue < VIRTIOSCSI_QUEUE_CNT; idxQueue++)
    2417     {
    2418         PVIRTIOSCSIWORKER pWorker = &pThis->aWorkers[idxQueue];
     2416    for (unsigned idxVirtq = 0; idxVirtq < VIRTIOSCSI_VIRTQ_CNT; idxVirtq++)
     2417    {
     2418        PVIRTIOSCSIWORKER pWorker = &pThis->aWorkers[idxVirtq];
    24192419        if (pWorker->hEvtProcess != NIL_SUPSEMEVENT)
    24202420        {
     
    24232423        }
    24242424
    2425         if (pThisCC->aWorkers[idxQueue].pThread)
     2425        if (pThisCC->aWorkers[idxVirtq].pThread)
    24262426        {
    24272427            /* Destroy the thread. */
    24282428            int rcThread;
    2429             int rc = PDMDevHlpThreadDestroy(pDevIns, pThisCC->aWorkers[idxQueue].pThread, &rcThread);
     2429            int rc = PDMDevHlpThreadDestroy(pDevIns, pThisCC->aWorkers[idxVirtq].pThread, &rcThread);
    24302430            if (RT_FAILURE(rc) || RT_FAILURE(rcThread))
    24312431                AssertMsgFailed(("%s Failed to destroythread rc=%Rrc rcThread=%Rrc\n",
    24322432                                 __FUNCTION__, rc, rcThread));
    2433            pThisCC->aWorkers[idxQueue].pThread = NULL;
     2433           pThisCC->aWorkers[idxVirtq].pThread = NULL;
    24342434        }
    24352435    }
     
    24872487
    24882488    /* Configure virtio_scsi_config that transacts via VirtIO implementation's Dev. Specific Cap callbacks */
    2489     pThis->virtioScsiConfig.uNumQueues      = VIRTIOSCSI_REQ_QUEUE_CNT;
     2489    pThis->virtioScsiConfig.uNumVirtqs      = VIRTIOSCSI_REQ_VIRTQ_CNT;
    24902490    pThis->virtioScsiConfig.uSegMax         = VIRTIOSCSI_MAX_SEG_COUNT;
    24912491    pThis->virtioScsiConfig.uMaxSectors     = VIRTIOSCSI_MAX_SECTORS_HINT;
     
    24992499
    25002500    /* Initialize the generic Virtio core: */
    2501     pThisCC->Virtio.pfnQueueNotified        = virtioScsiNotified;
     2501    pThisCC->Virtio.pfnVirtqNotified        = virtioScsiNotified;
    25022502    pThisCC->Virtio.pfnStatusChanged        = virtioScsiR3StatusChanged;
    25032503    pThisCC->Virtio.pfnDevCapRead           = virtioScsiR3DevCapRead;
     
    25262526
    25272527    /* Attach the queues and create worker threads for them: */
    2528     for (uint16_t idxQueue = 0; idxQueue < VIRTIOSCSI_QUEUE_CNT; idxQueue++)
    2529     {
    2530         rc = virtioCoreR3QueueAttach(&pThis->Virtio, idxQueue, VIRTQNAME(idxQueue));
     2528    for (uint16_t idxVirtq = 0; idxVirtq < VIRTIOSCSI_VIRTQ_CNT; idxVirtq++)
     2529    {
     2530        rc = virtioCoreR3VirtqAttach(&pThis->Virtio, idxVirtq, VIRTQNAME(idxVirtq));
    25312531        if (RT_FAILURE(rc))
    25322532            continue;
    2533         if (idxQueue == CONTROLQ_IDX || IS_REQ_QUEUE(idxQueue))
     2533        if (idxVirtq == CONTROLQ_IDX || IS_REQ_VIRTQ(idxVirtq))
    25342534        {
    2535             rc = PDMDevHlpThreadCreate(pDevIns, &pThisCC->aWorkers[idxQueue].pThread,
    2536                                        (void *)(uintptr_t)idxQueue, virtioScsiR3WorkerThread,
    2537                                        virtioScsiR3WorkerWakeUp, 0, RTTHREADTYPE_IO, VIRTQNAME(idxQueue));
     2535            rc = PDMDevHlpThreadCreate(pDevIns, &pThisCC->aWorkers[idxVirtq].pThread,
     2536                                       (void *)(uintptr_t)idxVirtq, virtioScsiR3WorkerThread,
     2537                                       virtioScsiR3WorkerWakeUp, 0, RTTHREADTYPE_IO, VIRTQNAME(idxVirtq));
    25382538            if (rc != VINF_SUCCESS)
    25392539            {
    2540                 LogRel(("Error creating thread for Virtual Queue %s: %Rrc\n", VIRTQNAME(idxQueue), rc));
     2540                LogRel(("Error creating thread for Virtual Virtq %s: %Rrc\n", VIRTQNAME(idxVirtq), rc));
    25412541                return rc;
    25422542            }
    25432543
    2544             rc = PDMDevHlpSUPSemEventCreate(pDevIns, &pThis->aWorkers[idxQueue].hEvtProcess);
     2544            rc = PDMDevHlpSUPSemEventCreate(pDevIns, &pThis->aWorkers[idxVirtq].hEvtProcess);
    25452545            if (RT_FAILURE(rc))
    25462546                return PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS,
    25472547                                           N_("DevVirtioSCSI: Failed to create SUP event semaphore"));
    25482548        }
    2549         pThis->afQueueAttached[idxQueue] = true;
     2549        pThis->afVirtqAttached[idxVirtq] = true;
    25502550    }
    25512551
     
    26662666
    26672667
    2668     pThisCC->Virtio.pfnQueueNotified = virtioScsiNotified;
     2668    pThisCC->Virtio.pfnVirtqNotified = virtioScsiNotified;
    26692669    return virtioCoreRZInit(pDevIns, &pThis->Virtio);
    26702670}
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