VirtualBox

Changeset 59091 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Dec 11, 2015 2:29:16 PM (9 years ago)
Author:
vboxsync
Message:

USB/Solaris: Rewrite, cleanup and numerous bug fixes to get the Apple iPhone working.

Location:
trunk/src/VBox
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/USB/solaris/USBProxyDevice-solaris.cpp

    r58778 r59091  
    212212    if (RT_UNLIKELY(pDevSol->hFile == NIL_RTFILE))
    213213    {
    214         LogFlow((USBPROXY ":usbProxySolarisIOCtl connection to driver gone!\n"));
     214        LogFlow((USBPROXY ":usbProxySolarisIOCtl: Connection to driver gone!\n"));
    215215        return VERR_VUSB_DEVICE_NOT_ATTACHED;
    216216    }
     
    232232                pDevSol->pProxyDev->fDetached = true;
    233233                usbProxySolarisCloseFile(pDevSol);
    234                 LogRel((USBPROXY ":Command %#x failed, USB Device '%s' disconnected!\n", Function, pDevSol->pProxyDev->pUsbIns->pszName));
     234                LogRel((USBPROXY ": Command %#x failed, USB Device '%s' disconnected!\n", Function,
     235                        pDevSol->pProxyDev->pUsbIns->pszName));
    235236            }
    236237            else
    237                 LogRel((USBPROXY ":Command %#x failed. Req.rc=%Rrc\n", Function, Req.rc));
     238                LogRel((USBPROXY ": Command %#x failed. Req.rc=%Rrc\n", Function, Req.rc));
    238239        }
    239240
     
    241242    }
    242243
    243     LogRel((USBPROXY ":Function %#x failed. rc=%Rrc\n", Function, rc));
     244    LogRel((USBPROXY ": Function %#x failed. rc=%Rrc\n", Function, rc));
    244245    return rc;
    245246}
     
    268269    {
    269270        if (rc != VERR_VUSB_DEVICE_NOT_ATTACHED)
    270             LogRel((USBPROXY ":Failed to get configuration. rc=%Rrc\n", rc));
     271            LogRel((USBPROXY ": Failed to get configuration. rc=%Rrc\n", rc));
    271272
    272273        pDevSol->pProxyDev->iActiveCfg = -1;
     
    290291    PUSBPROXYDEVSOL pDevSol = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVSOL);
    291292
    292     LogFlowFunc((USBPROXY ":usbProxySolarisOpen pProxyDev=%p pszAddress=%s pvBackend=%p\n", pProxyDev, pszAddress, pvBackend));
     293    LogFlowFunc((USBPROXY ":usbProxySolarisOpen: pProxyDev=%p pszAddress=%s pvBackend=%p\n", pProxyDev, pszAddress, pvBackend));
    293294
    294295    /*
     
    351352                                else
    352353                                {
    353                                     LogRel((USBPROXY ":version mismatch! driver v%d.%d expecting ~v%d.%d\n", GetVersionReq.u32Major,
     354                                    LogRel((USBPROXY ": Version mismatch, Driver v%d.%d expecting ~v%d.%d\n", GetVersionReq.u32Major,
    354355                                            GetVersionReq.u32Minor, VBOXUSB_VERSION_MAJOR, VBOXUSB_VERSION_MINOR));
    355356                                    rc = VERR_VERSION_MISMATCH;
     
    357358                            }
    358359                            else
    359                                 LogRel((USBPROXY ":failed to query driver version. rc=%Rrc\n", rc));
     360                                LogRel((USBPROXY ": Failed to query driver version. rc=%Rrc\n", rc));
    360361
    361362                            RTFileClose(pDevSol->hFile);
     
    364365                        }
    365366                        else
    366                             LogRel((USBPROXY ":failed to open device. rc=%Rrc pszDevicePath=%s\n", rc, pDevSol->pszDevicePath));
     367                            LogRel((USBPROXY ": Failed to open device. rc=%Rrc pszDevicePath=%s\n", rc, pDevSol->pszDevicePath));
    367368
    368369                        RTStrFree(pDevSol->pszDevicePath);
     
    371372                    else
    372373                    {
    373                         LogRel((USBPROXY ":failed to get client info. rc=%Rrc pszDevicePath=%s\n", rc, pDevSol->pszDevicePath));
     374                        LogRel((USBPROXY ": Failed to get client info. rc=%Rrc szDeviceIdent=%s\n", rc, szDeviceIdent));
    374375                        if (rc == VERR_NOT_FOUND)
    375376                            rc = VERR_OPEN_FAILED;
     
    382383            }
    383384            else
    384                 LogRel((USBPROXY ":RTCritSectInit failed. rc=%Rrc pszAddress=%s\n", rc, pszAddress));
     385                LogRel((USBPROXY ": RTCritSectInit failed. rc=%Rrc pszAddress=%s\n", rc, pszAddress));
    385386        }
    386387        else
    387             LogRel((USBPROXY ":RTStrAPrintf failed. rc=%Rrc pszAddress=%s\n", rc, pszAddress));
     388            LogRel((USBPROXY ": RTStrAPrintf failed. rc=%Rrc pszAddress=%s\n", rc, pszAddress));
    388389    }
    389390    else
    390         LogRel((USBPROXY ":USBLibInit failed. rc=%Rrc\n", rc));
     391        LogRel((USBPROXY ": USBLibInit failed. rc=%Rrc\n", rc));
    391392
    392393    USBLibTerm();
     
    451452static DECLCALLBACK(int) usbProxySolarisReset(PUSBPROXYDEV pProxyDev, bool fRootHubReset)
    452453{
    453     LogFlowFunc((USBPROXY ":usbProxySolarisReset pProxyDev=%s fRootHubReset=%d\n", pProxyDev->pUsbIns->pszName, fRootHubReset));
     454    LogFlowFunc((USBPROXY ": usbProxySolarisReset: pProxyDev=%s fRootHubReset=%d\n", pProxyDev->pUsbIns->pszName, fRootHubReset));
    454455
    455456    /** Pass all resets to the device. The Trekstor USB (1.1) stick requires this to work. */
     
    466467    }
    467468    else if (rc != VERR_VUSB_DEVICE_NOT_ATTACHED)
    468         LogRel((USBPROXY ":usbProxySolarisReset failed. rc=%d\n", rc));
     469        LogRel((USBPROXY ": usbProxySolarisReset: Failed! rc=%d\n", rc));
    469470
    470471    return rc;
     
    484485static DECLCALLBACK(int) usbProxySolarisSetConfig(PUSBPROXYDEV pProxyDev, int iCfg)
    485486{
    486     LogFlowFunc((USBPROXY ":usbProxySolarisSetConfig: pProxyDev=%p iCfg=%#x\n", pProxyDev, iCfg));
     487    LogFlowFunc((USBPROXY ": usbProxySolarisSetConfig: pProxyDev=%p iCfg=%#x\n", pProxyDev, iCfg));
    487488
    488489    PUSBPROXYDEVSOL pDevSol = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVSOL);
     
    494495    if (   RT_FAILURE(rc)
    495496        && rc != VERR_VUSB_DEVICE_NOT_ATTACHED)
    496         LogRel((USBPROXY ":usbProxySolarisSetConfig failed to switch configuration. rc=%Rrc\n", rc));
     497        LogRel((USBPROXY ": usbProxySolarisSetConfig: Failed! rc=%Rrc\n", rc));
    497498
    498499    return rc;
     
    533534 * @returns success indicator.
    534535 */
    535 static DECLCALLBACK(int) usbProxySolarisSetInterface(PUSBPROXYDEV pProxyDev, int iIf, int iAlt)
    536 {
    537     LogFlowFunc((USBPROXY ":usbProxySolarisSetInterface: pProxyDev=%p iIf=%d iAlt=%d\n", pProxyDev, iIf, iAlt));
     536static DECLCALLBACK(int) usbProxySolarisSetInterface(PUSBPROXYDEV pProxyDev, int bIf, int bAlt)
     537{
     538    LogFlowFunc((USBPROXY ": usbProxySolarisSetInterface: pProxyDev=%p bIf=%#x iAlt=%#x\n", pProxyDev, bIf, bAlt));
    538539
    539540    PUSBPROXYDEVSOL pDevSol = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVSOL);
     
    541542
    542543    VBOXUSBREQ_SET_INTERFACE SetInterfaceReq;
    543     SetInterfaceReq.bInterface = iIf;
    544     SetInterfaceReq.bAlternate = iAlt;
     544    SetInterfaceReq.bInterface = bIf;
     545    SetInterfaceReq.bAlternate = bAlt;
    545546    int rc = usbProxySolarisIOCtl(pDevSol, VBOXUSB_IOCTL_SET_INTERFACE, &SetInterfaceReq, sizeof(SetInterfaceReq));
    546547    if (   RT_FAILURE(rc)
    547548        && rc != VERR_VUSB_DEVICE_NOT_ATTACHED)
    548         LogRel((USBPROXY ":usbProxySolarisSetInterface failed to set interface. rc=%Rrc\n", rc));
     549        LogRel((USBPROXY ": usbProxySolarisSetInterface: Failed! rc=%Rrc\n", rc));
    549550
    550551    return rc;
     
    557558static DECLCALLBACK(int) usbProxySolarisClearHaltedEp(PUSBPROXYDEV pProxyDev, unsigned int EndPt)
    558559{
    559     LogFlowFunc((USBPROXY ":usbProxySolarisClearHaltedEp pProxyDev=%p EndPt=%#x\n", pProxyDev, EndPt));
     560    LogFlowFunc((USBPROXY ": usbProxySolarisClearHaltedEp: pProxyDev=%p EndPt=%#x\n", pProxyDev, EndPt));
    560561
    561562    PUSBPROXYDEVSOL pDevSol = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVSOL);
     
    567568    if (   RT_FAILURE(rc)
    568569        && rc != VERR_VUSB_DEVICE_NOT_ATTACHED)
    569         LogRel((USBPROXY ":usbProxySolarisClearHaltedEp failed! rc=%Rrc\n", rc));
     570        LogRel((USBPROXY ": usbProxySolarisClearHaltedEp: Failed! rc=%Rrc\n", rc));
    570571
    571572    return rc;
     
    580581    PUSBPROXYDEVSOL pDevSol = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVSOL);
    581582
    582     LogFlowFunc((USBPROXY ": usbProxySolarisUrbQueue: pProxyDev=%s pUrb=%p EndPt=%#x enmDir=%d cbData=%d pvData=%p\n",
    583              pProxyDev->pUsbIns->pszName, pUrb, pUrb->EndPt, pUrb->enmDir, pUrb->cbData, pUrb->abData));
     583    LogFlowFunc((USBPROXY ": usbProxySolarisUrbQueue: pProxyDev=%s pUrb=%p pszDesc=%s EndPt=%#x enmDir=%d cbData=%d pvData=%p\n",
     584             pProxyDev->pUsbIns->pszName, pUrb, pUrb->pszDesc, pUrb->EndPt, pUrb->enmDir, pUrb->cbData, pUrb->abData));
    584585
    585586    PUSBPROXYURBSOL pUrbSol = usbProxySolarisUrbAlloc(pDevSol);
    586587    if (RT_UNLIKELY(!pUrbSol))
    587588    {
    588         LogRel((USBPROXY ":usbProxySolarisUrbQueue: Failed to allocate URB.\n"));
     589        LogRel((USBPROXY ": usbProxySolarisUrbQueue: Failed to allocate URB\n"));
    589590        return VERR_NO_MEMORY;
    590591    }
     
    605606    UrbReq.fShortOk     = !pUrb->fShortNotOk;
    606607    UrbReq.cbData       = pUrb->cbData;
    607     UrbReq.pvData       = pUrb->abData;
     608    UrbReq.pvData       = &pUrb->abData[0];
     609
     610    Log6((USBPROXY ": Sending: EndPt=%#x Dir=%d cbData=%u\n", pUrb->EndPt, pUrb->enmDir, pUrb->cbData));
     611
    608612    if (pUrb->enmType == VUSBXFERTYPE_ISOC)
    609613    {
     
    621625    {
    622626        if (pUrb->enmType == VUSBXFERTYPE_ISOC)
    623             LogFlow((USBPROXY ":usbProxySolarisUrbQueue success cbData=%d.\n", pUrb->cbData));
     627            LogFlow((USBPROXY ":usbProxySolarisUrbQueue: Success cbData=%d\n", pUrb->cbData));
    624628        pUrb->Dev.pvPrivate = pUrbSol;
    625629        return VINF_SUCCESS;
     
    627631
    628632    if (rc != VERR_VUSB_DEVICE_NOT_ATTACHED)
    629         LogRel((USBPROXY ":usbProxySolarisUrbQueue Failed!! pProxyDev=%s pUrb=%p EndPt=%#x bEndpoint=%#x enmType=%d enmDir=%d cbData=%u rc=%Rrc\n",
    630              pProxyDev->pUsbIns->pszName, pUrb, pUrb->EndPt, UrbReq.bEndpoint, pUrb->enmType, pUrb->enmDir, pUrb->cbData, rc));
     633    {
     634        LogRel((USBPROXY ": usbProxySolarisUrbQueue: Failed! pProxyDev=%s pUrb=%p EndPt=%#x bEndpoint=%#x enmType=%d "
     635                "enmDir=%d cbData=%u rc=%Rrc\n", pProxyDev->pUsbIns->pszName, pUrb, pUrb->EndPt,
     636                UrbReq.bEndpoint, pUrb->enmType, pUrb->enmDir, pUrb->cbData, rc));
     637    }
    631638
    632639    return rc;
     
    647654    AssertPtrReturn(pDevSol, VERR_INVALID_POINTER);
    648655
    649     LogFlowFunc((USBPROXY ":usbProxySolarisUrbCancel pUrb=%p pUrbSol=%p pDevSol=%p\n", pUrb, pUrbSol, pUrbSol->pDevSol));
     656    LogFlowFunc((USBPROXY ": usbProxySolarisUrbCancel: pUrb=%p pUrbSol=%p pDevSol=%p\n", pUrb, pUrbSol, pUrbSol->pDevSol));
    650657
    651658    /* Aborting the control pipe isn't supported, pretend success. */
     
    658665    if (   RT_FAILURE(rc)
    659666        && rc != VERR_VUSB_DEVICE_NOT_ATTACHED)
    660         LogRel((USBPROXY ":usbProxySolarisUrbCancel failed to abort pipe. rc=%Rrc\n", rc));
    661 
    662     LogFlow((USBPROXY ":usbProxySolarisUrbCancel: rc=%Rrc.\n", rc));
     667        LogRel((USBPROXY ": usbProxySolarisUrbCancel: Failed to abort pipe. rc=%Rrc\n", rc));
     668
     669    LogFlow((USBPROXY ": usbProxySolarisUrbCancel: returns rc=%Rrc\n", rc));
    663670    return rc;
    664671}
     
    675682static DECLCALLBACK(PVUSBURB) usbProxySolarisUrbReap(PUSBPROXYDEV pProxyDev, RTMSINTERVAL cMillies)
    676683{
    677     //LogFlowFunc((USBPROXY ":usbProxySolarisUrbReap pProxyDev=%p cMillies=%u\n", pProxyDev, cMillies));
     684    LogFlowFunc((USBPROXY ":usbProxySolarisUrbReap pProxyDev=%p cMillies=%u\n", pProxyDev, cMillies));
    678685
    679686    PUSBPROXYDEVSOL pDevSol = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVSOL);
     
    693700        {
    694701            int cMilliesWait = cMillies == RT_INDEFINITE_WAIT ? -1 : (int)cMillies;
    695             struct pollfd pfd[2];
    696 
    697             pfd[0].fd = RTFileToNative(pDevSol->hFile);
    698             pfd[0].events = POLLIN;
    699             pfd[0].revents = 0;
    700 
    701             pfd[1].fd = RTPipeToNative(pDevSol->hPipeWakeupR);
    702             pfd[1].events = POLLIN;
    703             pfd[1].revents = 0;
    704 
    705             int rc = poll(&pfd[0], 2, cMilliesWait);
     702
     703            struct pollfd aFd[2];
     704            size_t const  cFds = RT_ELEMENTS(aFd);
     705
     706            aFd[0].fd      = RTFileToNative(pDevSol->hFile);
     707            aFd[0].events  = POLLIN;
     708            aFd[0].revents = 0;
     709
     710            aFd[1].fd      = RTPipeToNative(pDevSol->hPipeWakeupR);
     711            aFd[1].events  = POLLIN;
     712            aFd[1].revents = 0;
     713
     714            int rc = poll(&aFd[0], cFds, cMilliesWait);
    706715            if (rc > 0)
    707716            {
    708                 if (pfd[0].revents & POLLHUP)
     717                if (aFd[0].revents & POLLHUP)
    709718                {
    710                     LogRel((USBPROXY ":Reaping failed, USB Device '%s' disconnected!\n", pDevSol->pProxyDev->pUsbIns->pszName));
     719                    LogRel((USBPROXY ": USB Device '%s' disconnected!\n", pDevSol->pProxyDev->pUsbIns->pszName));
    711720                    pProxyDev->fDetached = true;
    712721                    usbProxySolarisCloseFile(pDevSol);
    713722                }
    714723
    715                 if (pfd[1].revents & POLLIN)
     724                if (aFd[1].revents & POLLIN)
    716725                {
    717726                    /* Got woken up, drain pipe. */
     
    725734                     * immediately to the caller.
    726735                     */
    727                     if (!(pfd[0].revents & POLLIN))
     736                    if (!(aFd[0].revents & POLLIN))
    728737                        return NULL;
    729738                }
    730 
    731739                break;
    732740            }
    733 
    734             if (rc == 0)
    735             {
    736                 //LogFlow((USBPROXY ":usbProxySolarisUrbReap: Timed out\n"));
     741            else if (rc == 0)
    737742                return NULL;
    738             }
    739             else if (rc != EAGAIN)
     743            else if (errno != EAGAIN)
    740744            {
    741745                LogFlow((USBPROXY ":usbProxySolarisUrbReap Poll rc=%d errno=%d\n", rc, errno));
     
    751755     */
    752756    PVUSBURB pUrb = NULL;
    753     while (pDevSol->pTaxingHead)
     757    while (    pDevSol->pTaxingHead
     758           && !pUrb)
    754759    {
    755760        RTCritSectEnter(&pDevSol->CritSect);
     
    761766            if (pUrb)
    762767            {
     768                /*
     769                 * Remove it from the taxing list and move it to the free list.
     770                 */
    763771                pUrb->Dev.pvPrivate = NULL;
    764772                usbProxySolarisUrbFree(pDevSol, pUrbSol);
     
    779787static PVUSBURB usbProxySolarisUrbComplete(PUSBPROXYDEVSOL pDevSol)
    780788{
    781     LogFlowFunc((USBPROXY ":usbProxySolarisUrbComplete pDevSol=%p\n", pDevSol));
     789    LogFlowFunc((USBPROXY ": usbProxySolarisUrbComplete: pDevSol=%p\n", pDevSol));
    782790
    783791    VBOXUSBREQ_URB UrbReq;
     
    809817                    }
    810818
    811                     LogFlow((USBPROXY ":usbProxySolarisUrbComplete ISOC cbData=%d cbActPktSum=%d\n", pUrb->cbData, cbData));
     819                    LogFlow((USBPROXY ":usbProxySolarisUrbComplete: Isoc cbData=%d cbActPktSum=%d\n", pUrb->cbData, cbData));
    812820                    pUrb->cbData = cbData;
    813821                    pUrb->enmStatus = UrbReq.enmStatus;
     
    835843
    836844                /*
    837                  * Link it into the taxing list.
     845                 * Add to the tail of the taxing list.
    838846                 */
    839847                pUrbSol->pNext = NULL;
     
    847855                RTCritSectLeave(&pDevSol->CritSect);
    848856
    849                 LogFlow((USBPROXY "usbProxySolarisUrbComplete: cb=%d EndPt=%#x enmDir=%d enmStatus=%s (%d) \n",
    850                          pUrb->cbData, pUrb->EndPt, pUrb->enmDir, pUrb->enmStatus == VUSBSTATUS_OK ? "OK" : "** Failed **", pUrb->enmStatus));
    851 //                if (pUrb->cbData < 2049)
    852 //                    LogFlow((USBPROXY "%.*Rhxd\n", pUrb->cbData, pUrb->abData));
     857                Log6((USBPROXY ": Reaping: EndPt=%#x Dir=%d cbData=%u\n", pUrb->EndPt, pUrb->enmDir, pUrb->cbData));
     858                if (pUrb->cbData < 1024)
     859                    Log6(("%.*Rhxd\n", pUrb->cbData, pUrb->abData));
    853860                return pUrb;
    854861            }
     
    858865    {
    859866        if (rc != VERR_VUSB_DEVICE_NOT_ATTACHED)
    860             LogRel((USBPROXY ":Reaping URB failed. rc=%Rrc\n", rc));
     867            LogRel((USBPROXY ": Reaping URB failed. rc=%Rrc\n", rc));
    861868    }
    862869
  • trunk/src/VBox/HostDrivers/VBoxUSB/solaris/USBLib-solaris.cpp

    r57358 r59091  
    210210    LogFlow((USBLIBR3 ":USBLibResetDevice pszDevicePath=%s\n", pszDevicePath));
    211211
    212     size_t cbReq = sizeof(VBOXUSBREQ_RESET_DEVICE) + strlen(pszDevicePath);
     212    size_t cbPath = strlen(pszDevicePath) + 1;
     213    size_t cbReq  = sizeof(VBOXUSBREQ_RESET_DEVICE) + cbPath;
    213214    VBOXUSBREQ_RESET_DEVICE *pReq = (VBOXUSBREQ_RESET_DEVICE *)RTMemTmpAllocZ(cbReq);
    214215    if (RT_UNLIKELY(!pReq))
     
    216217
    217218    pReq->fReattach = fReattach;
    218     strcpy(pReq->szDevicePath, pszDevicePath);
     219    if (strlcpy(pReq->szDevicePath, pszDevicePath, cbPath) >= cbPath)
     220    {
     221        LogRel((USBLIBR3 ":USBLibResetDevice buffer overflow. cbPath=%u pszDevicePath=%s\n", cbPath, pszDevicePath));
     222        return VERR_BUFFER_OVERFLOW;
     223    }
    219224
    220225    int rc = usblibDoIOCtl(VBOXUSBMON_IOCTL_RESET_DEVICE, pReq, cbReq);
  • trunk/src/VBox/HostDrivers/VBoxUSB/solaris/VBoxUSB-solaris.c

    r58340 r59091  
    4545#include <iprt/path.h>
    4646#include <iprt/thread.h>
     47#include <iprt/dbg.h>
    4748
    4849#define USBDRV_MAJOR_VER    2
     
    5152#include <sys/strsun.h>
    5253#include "usbai_private.h"
    53 #include <sys/archsystm.h>
    54 #include <sys/disp.h>
    55 
    56 /** @todo review the locking here, verify assumptions about code executed
    57  *        without the vboxusb_state_t::Mtx mutex */
    5854
    5955
     
    6662#define DEVICE_DESC_DRV                                 "VirtualBox USB"
    6763
    68 /** Endpoint states */
     64/** Endpoint states. */
    6965#define VBOXUSB_EP_INITIALIZED                          0xa1fa1fa
    7066#define VBOXUSB_EP_STATE_NONE                           RT_BIT(0)
    7167#define VBOXUSB_EP_STATE_CLOSED                         RT_BIT(1)
    7268#define VBOXUSB_EP_STATE_OPENED                         RT_BIT(2)
    73 /** Polling states */
    74 #define VBOXUSB_POLL_OFF                                RT_BIT(0)
    75 #define VBOXUSB_POLL_ON                                 RT_BIT(1)
    76 #define VBOXUSB_POLL_REAP_PENDING                       RT_BIT(2)
    77 #define VBOXUSB_POLL_DEV_UNPLUGGED                      RT_BIT(3)
    7869
    7970/** -=-=-=-=-=-=- Standard Specifics -=-=-=-=-=-=- */
    80 /** Max. supported endpoints */
     71/** Max. supported endpoints. */
    8172#define VBOXUSB_MAX_ENDPOINTS                           32
    82 /** Size of USB Ctrl Xfer Header */
    83 #define VBOXUSB_CTRL_XFER_SIZE                          0x08
     73/** Size of USB Ctrl Xfer Header in bytes. */
     74#define VBOXUSB_CTRL_XFER_SIZE                          8
    8475/**
    8576 * USB2.0 (Sec. 9-13) Bits 10..0 is the max packet size; for high speed Isoc/Intr, bits 12..11 is
     
    8778 */
    8879#define VBOXUSB_PKT_SIZE(pkt)                          (pkt & 0x07FF) * (1 + ((pkt >> 11) & 3))
    89 /** Endpoint Xfer Type */
     80/** Endpoint Xfer Type. */
    9081#define VBOXUSB_XFER_TYPE(endp)                        ((endp)->EpDesc.bmAttributes & USB_EP_ATTR_MASK)
    91 /** Endpoint Xfer Direction */
     82/** Endpoint Xfer Direction. */
    9283#define VBOXUSB_XFER_DIR(endp)                         ((endp)->EpDesc.bEndpointAddress & USB_EP_DIR_IN)
     84/** Create an Endpoint index from an Endpoint address. */
     85#define VBOXUSB_GET_EP_INDEX(epaddr)                   (((epaddr) & USB_EP_NUM_MASK) + \
     86                                                       (((epaddr) & USB_EP_DIR_MASK) ? 16 : 0))
     87
    9388
    9489/** -=-=-=-=-=-=- Tunable Parameters -=-=-=-=-=-=- */
     
    9691#define VBOXUSB_DRAIN_TIME                              20
    9792/** Ctrl Xfer timeout in seconds. */
    98 #define VBOXUSB_CTRL_XFER_TIMEOUT                       10
    99 /** Bulk Xfer timeout in seconds. */
    100 #define VBOXUSB_BULK_XFER_TIMEOUT                       10
    101 /** Intr Xfer timeout in seconds. */
    102 #define VBOXUSB_INTR_XFER_TIMEOUT                       10
     93#define VBOXUSB_CTRL_XFER_TIMEOUT                       15
    10394/** Maximum URB queue length. */
    104 #define VBOXUSB_URB_QUEUE_SIZE                          64
    105 /** Maximum asynchronous requests per pipe */
     95#define VBOXUSB_URB_QUEUE_SIZE                         512
     96/** Maximum asynchronous requests per pipe. */
    10697#define VBOXUSB_MAX_PIPE_ASYNC_REQS                     2
    10798
    108 /** For enabling global symbols while debugging  **/
     99/** For enabling global symbols while debugging. **/
    109100#if defined(DEBUG_ramshankar)
    110101# define LOCAL
     
    201192typedef struct vboxusb_ep_t
    202193{
    203     uint_t                  fInitialized;    /* Whether this Endpoint is initialized */
    204     uint_t                  EpState;         /* Endpoint state */
    205     usb_ep_descr_t          EpDesc;          /* Endpoint descriptor */
    206     uchar_t                 uCfgValue;       /* Configuration value */
    207     uchar_t                 uInterface;      /* Interface number */
    208     uchar_t                 uAlt;            /* Alternate number */
    209     usb_pipe_handle_t       pPipe;           /* Endpoint pipe handle */
    210     usb_pipe_policy_t       PipePolicy;      /* Endpoint policy */
    211     bool                    fIsocPolling;    /* Whether Isoc. IN polling is enabled */
    212     list_t                  hIsocInUrbs;     /* Isoc. IN inflight URBs */
    213     uint16_t                cIsocInUrbs;     /* Number of Isoc. IN inflight URBs */
     194    bool                    fInitialized;        /* Whether this Endpoint is initialized */
     195    uint_t                  EpState;             /* Endpoint state */
     196    usb_ep_descr_t          EpDesc;              /* Endpoint descriptor */
     197    usb_pipe_handle_t       pPipe;               /* Endpoint pipe handle */
     198    usb_pipe_policy_t       PipePolicy;          /* Endpoint policy */
     199    bool                    fIsocPolling;        /* Whether Isoc. IN polling is enabled */
     200    list_t                  hIsocInUrbs;         /* Isoc. IN inflight URBs */
     201    uint16_t                cIsocInUrbs;         /* Number of Isoc. IN inflight URBs */
    214202    list_t                  hIsocInLandedReqs;   /* Isoc. IN landed requests */
    215203    uint16_t                cbIsocInLandedReqs;  /* Cumulative size of landed Isoc. IN requests */
    216     size_t                  cbMaxIsocData;   /* Maximum size of Isoc. IN landed buffer */
     204    size_t                  cbMaxIsocData;       /* Maximum size of Isoc. IN landed buffer */
    217205} vboxusb_ep_t;
    218206
     
    222210typedef struct vboxusb_isoc_req_t
    223211{
    224     mblk_t                 *pMsg;            /* Pointer to the data buffer */
    225     uint32_t                cIsocPkts;       /* Number of Isoc pkts */
    226     VUSBISOC_PKT_DESC       aIsocPkts[8];    /* Array of Isoc pkt descriptors */
     212    mblk_t                 *pMsg;                /* Pointer to the data buffer */
     213    uint32_t                cIsocPkts;           /* Number of Isoc pkts */
     214    VUSBISOC_PKT_DESC       aIsocPkts[8];        /* Array of Isoc pkt descriptors */
    227215    list_node_t             hListLink;
    228216} vboxusb_isoc_req_t;
     
    243231typedef struct vboxusb_urb_t
    244232{
    245     void                   *pvUrbR3;         /* Userspace URB address (untouched, returned while reaping) */
    246     uint8_t                 bEndpoint;       /* Endpoint address */
    247     VUSBXFERTYPE            enmType;         /* Xfer type */
    248     VUSBDIRECTION           enmDir;          /* Xfer direction */
    249     VUSBSTATUS              enmStatus;       /* URB status */
    250     bool                    fShortOk;        /* Whether receiving less data than requested is acceptable. */
    251     RTR3PTR                 pvDataR3;        /* Userspace address of the original data buffer */
    252     size_t                  cbDataR3;        /* Size of the data buffer */
    253     mblk_t                 *pMsg;            /* Pointer to the data buffer */
    254     uint32_t                cIsocPkts;       /* Number of Isoc pkts */
    255     VUSBISOC_PKT_DESC       aIsocPkts[8];    /* Array of Isoc pkt descriptors */
    256     VBOXUSB_URB_STATE       enmState;        /* Whether free/in-flight etc. */
    257     struct vboxusb_state_t *pState;          /* Pointer to the device instance */
    258     list_node_t             hListLink;       /* List node link handle */
     233    void                   *pvUrbR3;             /* Userspace URB address (untouched, returned while reaping) */
     234    uint8_t                 bEndpoint;           /* Endpoint address */
     235    VUSBXFERTYPE            enmType;             /* Xfer type */
     236    VUSBDIRECTION           enmDir;              /* Xfer direction */
     237    VUSBSTATUS              enmStatus;           /* URB status */
     238    bool                    fShortOk;            /* Whether receiving less data than requested is acceptable */
     239    RTR3PTR                 pvDataR3;            /* Userspace address of the original data buffer */
     240    size_t                  cbDataR3;            /* Size of the data buffer */
     241    mblk_t                 *pMsg;                /* Pointer to the data buffer */
     242    uint32_t                cIsocPkts;           /* Number of Isoc pkts */
     243    VUSBISOC_PKT_DESC       aIsocPkts[8];        /* Array of Isoc pkt descriptors */
     244    VBOXUSB_URB_STATE       enmState;            /* URB state (free/in-flight/landed). */
     245    struct vboxusb_state_t *pState;              /* Pointer to the device instance */
     246    list_node_t             hListLink;           /* List node link handle */
    259247} vboxusb_urb_t;
    260248
     
    264252typedef struct vboxusb_power_t
    265253{
    266     uint_t                  PowerStates;     /* Bit mask of the power states */
    267     int                     PowerBusy;       /* Busy counter */
    268     bool                    fPowerWakeup;    /* Whether remote power wakeup is enabled */
    269     bool                    fPowerRaise;     /* Whether to raise the power level */
    270     uint8_t                 PowerLevel;      /* Current power level */
     254    uint_t                  PowerStates;         /* Bit mask of the power states */
     255    int                     PowerBusy;           /* Busy reference counter */
     256    bool                    fPowerWakeup;        /* Whether remote power wakeup is enabled */
     257    bool                    fPowerRaise;         /* Whether to raise the power level */
     258    uint8_t                 PowerLevel;          /* Current power level */
    271259} vboxusb_power_t;
    272260
     
    276264typedef struct vboxusb_state_t
    277265{
    278     dev_info_t             *pDip;            /* Per instance device info. */
    279     usb_client_dev_data_t  *pDevDesc;        /* Parsed & complete device descriptor */
    280     uint8_t                 DevState;        /* Current USB Device state */
    281     bool                    fClosed;         /* Whether the device (default control pipe) is closed */
    282     bool                    fRestoreCfg;     /* Whether we changed configs to restore while tearing down */
    283     bool                    fGetCfgReqDone;  /* First GET_CONFIG request has been circumvented */
    284     kmutex_t                Mtx;             /* Mutex state protection */
    285     usb_serialization_t     StateMulti;      /* State serialization */
    286     size_t                  cbMaxBulkXfer;   /* Maximum bulk xfer size */
    287     vboxusb_ep_t            aEps[VBOXUSB_MAX_ENDPOINTS]; /* All endpoints structures */
    288     list_t                  hUrbs;           /* Handle to list of free/inflight URBs */
    289     list_t                  hLandedUrbs;     /* Handle to list of landed URBs */
    290     uint16_t                cInflightUrbs;   /* Number of inflight URBs. */
    291     pollhead_t              PollHead;        /* Handle to pollhead for waking polling processes  */
    292     int                     fPoll;           /* Polling status flag */
    293     RTPROCESS               Process;         /* The process (id) of the session */
    294     VBOXUSBREQ_CLIENT_INFO  ClientInfo;      /* Registration data */
    295     vboxusb_power_t        *pPower;          /* Power Management */
     266    dev_info_t             *pDip;                /* Per instance device info. */
     267    usb_client_dev_data_t  *pDevDesc;            /* Parsed & complete device descriptor */
     268    uint8_t                 DevState;            /* Current USB Device state */
     269    bool                    fDefaultPipeOpen;    /* Whether the device (default control pipe) is closed */
     270    bool                    fPollPending;        /* Whether the userland process' poll is pending */
     271    kmutex_t                Mtx;                 /* Mutex state protection */
     272    usb_serialization_t     StateMulti;          /* State serialization */
     273    size_t                  cbMaxBulkXfer;       /* Maximum bulk xfer size */
     274    vboxusb_ep_t            aEps[VBOXUSB_MAX_ENDPOINTS]; /* Array of all endpoints structures */
     275    list_t                  hFreeUrbs;           /* List of free URBs */
     276    list_t                  hInflightUrbs;       /* List of inflight URBs */
     277    list_t                  hLandedUrbs;         /* List of landed URBs */
     278    uint32_t                cFreeUrbs;           /* Number of free URBs */
     279    uint32_t                cInflightUrbs;       /* Number of inflight URBs */
     280    uint32_t                cLandedUrbs;         /* Number of landed URBs */
     281    pollhead_t              PollHead;            /* Handle to pollhead for waking polling processes  */
     282    RTPROCESS               Process;             /* The process (pid) of the user session */
     283    VBOXUSBREQ_CLIENT_INFO  ClientInfo;          /* Registration data */
     284    vboxusb_power_t        *pPower;              /* Power Management */
     285    char                    szMfg[255];          /* Parsed manufacturer string */
     286    char                    szProduct[255];      /* Parsed product string */
    296287} vboxusb_state_t;
     288AssertCompileMemberSize(vboxusb_state_t, szMfg,     USB_MAXSTRINGLEN);
     289AssertCompileMemberSize(vboxusb_state_t, szProduct, USB_MAXSTRINGLEN);
    297290
    298291
     
    300293*   Internal Functions                                                                                                           *
    301294*********************************************************************************************************************************/
    302 LOCAL int vboxUSBSolarisInitEndPoint(vboxusb_state_t *pState, usb_ep_data_t *pEpData, uchar_t uCfgValue,
    303                                 uchar_t uInterface, uchar_t uAlt);
    304 LOCAL int vboxUSBSolarisInitAllEndPoints(vboxusb_state_t *pState);
    305 LOCAL int vboxUSBSolarisInitEndPointsForConfig(vboxusb_state_t *pState, uint8_t uCfgIndex);
    306 LOCAL int vboxUSBSolarisInitEndPointsForInterfaceAlt(vboxusb_state_t *pState, uint8_t uInterface, uint8_t uAlt);
    307 LOCAL void vboxUSBSolarisDestroyAllEndPoints(vboxusb_state_t *pState);
    308 LOCAL void vboxUSBSolarisDestroyEndPoint(vboxusb_state_t *pState, vboxusb_ep_t *pEp);
    309 LOCAL void vboxUSBSolarisCloseAllPipes(vboxusb_state_t *pState, bool fControlPipe);
    310 LOCAL int vboxUSBSolarisOpenPipe(vboxusb_state_t *pState, vboxusb_ep_t *pEp);
    311 LOCAL void vboxUSBSolarisClosePipe(vboxusb_state_t *pState, vboxusb_ep_t *pEp);
    312 LOCAL int vboxUSBSolarisCtrlXfer(vboxusb_state_t *pState, vboxusb_ep_t *pEp, vboxusb_urb_t *pUrb);
    313 LOCAL void vboxUSBSolarisCtrlXferCompleted(usb_pipe_handle_t pPipe, usb_ctrl_req_t *pReq);
    314 LOCAL int vboxUSBSolarisBulkXfer(vboxusb_state_t *pState, vboxusb_ep_t *pEp, vboxusb_urb_t *purb);
    315 LOCAL void vboxUSBSolarisBulkXferCompleted(usb_pipe_handle_t pPipe, usb_bulk_req_t *pReq);
    316 LOCAL int vboxUSBSolarisIntrXfer(vboxusb_state_t *pState, vboxusb_ep_t *pEp, vboxusb_urb_t *pUrb);
    317 LOCAL void vboxUSBSolarisIntrXferCompleted(usb_pipe_handle_t pPipe, usb_intr_req_t *pReq);
    318 LOCAL int vboxUSBSolarisIsocXfer(vboxusb_state_t *pState, vboxusb_ep_t *pEp, vboxusb_urb_t *pUrb);
    319 LOCAL void vboxUSBSolarisIsocInXferCompleted(usb_pipe_handle_t pPipe, usb_isoc_req_t *pReq);
    320 LOCAL void vboxUSBSolarisIsocInXferError(usb_pipe_handle_t pPipe, usb_isoc_req_t *pReq);
    321 LOCAL void vboxUSBSolarisIsocOutXferCompleted(usb_pipe_handle_t pPipe, usb_isoc_req_t *pReq);
    322 LOCAL vboxusb_urb_t *vboxUSBSolarisGetIsocInURB(vboxusb_state_t *pState, PVBOXUSBREQ_URB pUrbReq);
    323 LOCAL vboxusb_urb_t *vboxUSBSolarisQueueURB(vboxusb_state_t *pState, PVBOXUSBREQ_URB pUrbReq, mblk_t *pMsg);
    324 LOCAL inline void vboxUSBSolarisConcatMsg(vboxusb_urb_t *pUrb);
    325 LOCAL inline VUSBSTATUS vboxUSBSolarisGetUrbStatus(usb_cr_t Status);
    326 LOCAL inline void vboxUSBSolarisDeQueueURB(vboxusb_urb_t *pUrb, int URBStatus);
    327 LOCAL inline void vboxUSBSolarisNotifyComplete(vboxusb_state_t *pState);
    328 LOCAL int vboxUSBSolarisProcessIOCtl(int iFunction, void *pvState, int Mode, PVBOXUSBREQ pUSBReq, void *pvBuf,
    329                                      size_t *pcbDataOut);
    330 LOCAL bool vboxUSBSolarisIsUSBDevice(dev_info_t *pDip);
     295LOCAL int    vboxUsbSolarisInitEp(vboxusb_state_t *pState, usb_ep_data_t *pEpData);
     296LOCAL int    vboxUsbSolarisInitEpsForCfg(vboxusb_state_t *pState);
     297LOCAL int    vboxUsbSolarisInitEpsForIfAlt(vboxusb_state_t *pState, uint8_t bIf, uint8_t bAlt);
     298LOCAL void   vboxUsbSolarisDestroyAllEps(vboxusb_state_t *pState);
     299LOCAL void   vboxUsbSolarisDestroyEp(vboxusb_state_t *pState, vboxusb_ep_t *pEp);
     300LOCAL void   vboxUsbSolarisCloseAllPipes(vboxusb_state_t *pState, bool fControlPipe);
     301LOCAL int    vboxUsbSolarisOpenPipe(vboxusb_state_t *pState, vboxusb_ep_t *pEp);
     302LOCAL void   vboxUsbSolarisClosePipe(vboxusb_state_t *pState, vboxusb_ep_t *pEp);
     303LOCAL int    vboxUsbSolarisCtrlXfer(vboxusb_state_t *pState, vboxusb_ep_t *pEp, vboxusb_urb_t *pUrb);
     304LOCAL void   vboxUsbSolarisCtrlXferCompleted(usb_pipe_handle_t pPipe, usb_ctrl_req_t *pReq);
     305LOCAL int    vboxUsbSolarisBulkXfer(vboxusb_state_t *pState, vboxusb_ep_t *pEp, vboxusb_urb_t *purb);
     306LOCAL void   vboxUsbSolarisBulkXferCompleted(usb_pipe_handle_t pPipe, usb_bulk_req_t *pReq);
     307LOCAL int    vboxUsbSolarisIntrXfer(vboxusb_state_t *pState, vboxusb_ep_t *pEp, vboxusb_urb_t *pUrb);
     308LOCAL void   vboxUsbSolarisIntrXferCompleted(usb_pipe_handle_t pPipe, usb_intr_req_t *pReq);
     309LOCAL int    vboxUsbSolarisIsocXfer(vboxusb_state_t *pState, vboxusb_ep_t *pEp, vboxusb_urb_t *pUrb);
     310LOCAL void   vboxUsbSolarisIsocInXferCompleted(usb_pipe_handle_t pPipe, usb_isoc_req_t *pReq);
     311LOCAL void   vboxUsbSolarisIsocInXferError(usb_pipe_handle_t pPipe, usb_isoc_req_t *pReq);
     312LOCAL void   vboxUsbSolarisIsocOutXferCompleted(usb_pipe_handle_t pPipe, usb_isoc_req_t *pReq);
     313LOCAL vboxusb_urb_t  *vboxUsbSolarisGetIsocInUrb(vboxusb_state_t *pState, PVBOXUSBREQ_URB pUrbReq);
     314LOCAL vboxusb_urb_t  *vboxUsbSolarisQueueUrb(vboxusb_state_t *pState, PVBOXUSBREQ_URB pUrbReq, mblk_t *pMsg);
     315LOCAL VUSBSTATUS      vboxUsbSolarisGetUrbStatus(usb_cr_t Status);
     316LOCAL void   vboxUsbSolarisConcatMsg(vboxusb_urb_t *pUrb);
     317LOCAL void   vboxUsbSolarisDeQueueUrb(vboxusb_urb_t *pUrb, int URBStatus);
     318LOCAL void   vboxUsbSolarisNotifyComplete(vboxusb_state_t *pState);
     319LOCAL int    vboxUsbSolarisProcessIOCtl(int iFunction, void *pvState, int Mode, PVBOXUSBREQ pUSBReq, void *pvBuf,
     320                                        size_t *pcbDataOut);
     321LOCAL bool   vboxUsbSolarisIsUSBDevice(dev_info_t *pDip);
    331322
    332323/** @name Device Operation Hooks
    333324 * @{ */
    334 LOCAL int vboxUSBSolarisSendURB(vboxusb_state_t *pState, PVBOXUSBREQ_URB pUrbReq, int Mode);
    335 LOCAL int vboxUSBSolarisReapURB(vboxusb_state_t *pState, PVBOXUSBREQ_URB pUrbReq, int Mode);
    336 LOCAL int vboxUSBSolarisClearEndPoint(vboxusb_state_t *pState, uint8_t bEndpoint);
    337 LOCAL int vboxUSBSolarisSetConfig(vboxusb_state_t *pState, uint8_t bCfgValue);
    338 LOCAL int vboxUSBSolarisGetConfig(vboxusb_state_t *pState, uint8_t *pCfgValue);
    339 LOCAL int vboxUSBSolarisSetInterface(vboxusb_state_t *pState, uint8_t uInterface, uint8_t uAlt);
    340 LOCAL int vboxUSBSolarisCloseDevice(vboxusb_state_t *pState, VBOXUSB_RESET_LEVEL enmReset);
    341 LOCAL int vboxUSBSolarisAbortPipe(vboxusb_state_t *pState, uint8_t bEndpoint);
    342 LOCAL int vboxUSBSolarisGetConfigIndex(vboxusb_state_t *pState, uint_t uCfgValue);
     325LOCAL int    vboxUsbSolarisSendUrb(vboxusb_state_t *pState, PVBOXUSBREQ_URB pUrbReq, int Mode);
     326LOCAL int    vboxUsbSolarisReapUrb(vboxusb_state_t *pState, PVBOXUSBREQ_URB pUrbReq, int Mode);
     327LOCAL int    vboxUsbSolarisClearEndPoint(vboxusb_state_t *pState, uint8_t bEndpoint);
     328LOCAL int    vboxUsbSolarisSetConfig(vboxusb_state_t *pState, uint8_t bCfgValue);
     329LOCAL int    vboxUsbSolarisGetConfig(vboxusb_state_t *pState, uint8_t *pCfgValue);
     330LOCAL int    vboxUsbSolarisSetInterface(vboxusb_state_t *pState, uint8_t bIf, uint8_t bAlt);
     331LOCAL int    vboxUsbSolarisCloseDevice(vboxusb_state_t *pState, VBOXUSB_RESET_LEVEL enmReset);
     332LOCAL int    vboxUsbSolarisAbortPipe(vboxusb_state_t *pState, uint8_t bEndpoint);
     333LOCAL int    vboxUsbSolarisGetConfigIndex(vboxusb_state_t *pState, uint_t bCfgValue);
    343334/** @} */
    344335
    345336/** @name Hotplug & Power Management Hooks
    346337 * @{ */
    347 LOCAL inline void vboxUSBSolarisNotifyHotplug(vboxusb_state_t *pState);
    348 LOCAL int vboxUSBSolarisDeviceDisconnected(dev_info_t *pDip);
    349 LOCAL int vboxUSBSolarisDeviceReconnected(dev_info_t *pDip);
    350 
    351 LOCAL int vboxUSBSolarisInitPower(vboxusb_state_t *pState);
    352 LOCAL void vboxUSBSolarisDestroyPower(vboxusb_state_t *pState);
    353 LOCAL int vboxUSBSolarisDeviceSuspend(vboxusb_state_t *pState);
    354 LOCAL void vboxUSBSolarisDeviceResume(vboxusb_state_t *pState);
    355 LOCAL void vboxUSBSolarisDeviceRestore(vboxusb_state_t *pState);
    356 LOCAL void vboxUSBSolarisPowerBusy(vboxusb_state_t *pState);
    357 LOCAL void vboxUSBSolarisPowerIdle(vboxusb_state_t *pState);
     338LOCAL void   vboxUsbSolarisNotifyUnplug(vboxusb_state_t *pState);
     339LOCAL int    vboxUsbSolarisDeviceDisconnected(dev_info_t *pDip);
     340LOCAL int    vboxUsbSolarisDeviceReconnected(dev_info_t *pDip);
     341
     342LOCAL int    vboxUsbSolarisInitPower(vboxusb_state_t *pState);
     343LOCAL void   vboxUsbSolarisDestroyPower(vboxusb_state_t *pState);
     344LOCAL int    vboxUsbSolarisDeviceSuspend(vboxusb_state_t *pState);
     345LOCAL void   vboxUsbSolarisDeviceResume(vboxusb_state_t *pState);
     346LOCAL void   vboxUsbSolarisDeviceRestore(vboxusb_state_t *pState);
     347LOCAL void   vboxUsbSolarisPowerBusy(vboxusb_state_t *pState);
     348LOCAL void   vboxUsbSolarisPowerIdle(vboxusb_state_t *pState);
    358349/** @} */
    359350
    360351/** @name Monitor Hooks
    361352 * @{ */
    362 int VBoxUSBMonSolarisRegisterClient(dev_info_t *pClientDip, PVBOXUSB_CLIENT_INFO pClientInfo);
    363 int VBoxUSBMonSolarisUnregisterClient(dev_info_t *pClientDip);
     353int          VBoxUSBMonSolarisRegisterClient(dev_info_t *pClientDip, PVBOXUSB_CLIENT_INFO pClientInfo);
     354int          VBoxUSBMonSolarisUnregisterClient(dev_info_t *pClientDip);
    364355/** @} */
    365356
    366357/** @name Callbacks from Monitor
    367358 * @{ */
    368 LOCAL int vboxUSBSolarisSetConsumerCredentials(RTPROCESS Process, int Instance, void *pvReserved);
     359LOCAL int    vboxUsbSolarisSetConsumerCredentials(RTPROCESS Process, int Instance, void *pvReserved);
    369360/** @} */
    370361
     
    377368
    378369/** The default endpoint descriptor */
    379 static usb_ep_descr_t g_VBoxUSBSolarisDefaultEpDesc = {7, 5, 0, USB_EP_ATTR_CONTROL, 8, 0};
    380 
    381 /** Hotplug events */
    382 static usb_event_t g_VBoxUSBSolarisEvents =
    383 {
    384     vboxUSBSolarisDeviceDisconnected,
    385     vboxUSBSolarisDeviceReconnected,
    386     NULL,                             /* presuspend */
    387     NULL                              /* postresume */
    388 };
     370static usb_ep_descr_t g_VBoxUSBSolarisDefaultEpDesc = { 7, 5, 0, USB_EP_ATTR_CONTROL, 8, 0 };
     371
     372/** Size of the usb_ep_data_t struct (used to index into data). */
     373static size_t g_cbUsbEpData       = ~0UL;
     374
     375/** The offset of usb_ep_data_t::ep_desc. */
     376static size_t g_offUsbEpDataDescr = ~0UL;
     377
     378
     379#ifdef LOG_ENABLED
     380/**
     381 * Gets the description of an Endpoint's transfer type.
     382 *
     383 * @param pEp       The Endpoint.
     384 * @returns The type of the Endpoint.
     385 */
     386static const char *vboxUsbSolarisEpType(vboxusb_ep_t *pEp)
     387{
     388    uint8_t uType = VBOXUSB_XFER_TYPE(pEp);
     389    switch (uType)
     390    {
     391        case 0:  return "CTRL";
     392        case 1:  return "ISOC";
     393        case 2:  return "BULK";
     394        default: return "INTR";
     395    }
     396}
     397
     398
     399/**
     400 * Gets the description of an Endpoint's direction.
     401 *
     402 * @param pEp       The Endpoint.
     403 * @returns The direction of the Endpoint.
     404 */
     405static const char *vboxUsbSolarisEpDir(vboxusb_ep_t *pEp)
     406{
     407    return VBOXUSB_XFER_DIR(pEp) == USB_EP_DIR_IN ? "IN " : "OUT";
     408}
     409#endif
     410
     411
     412/**
     413 * Caches device strings from the parsed device descriptors.
     414 *
     415 * @param   pState          The USB device instance.
     416 *
     417 * @remarks Must only be called after usb_get_dev_data().
     418 */
     419static void vboxUsbSolarisGetDeviceStrings(vboxusb_state_t *pState)
     420{
     421    AssertReturnVoid(pState);
     422    AssertReturnVoid(pState->pDevDesc);
     423
     424    if (pState->pDevDesc->dev_product)
     425        strlcpy(&pState->szMfg[0], pState->pDevDesc->dev_mfg, sizeof(pState->szMfg));
     426    else
     427        strlcpy(&pState->szMfg[0], "<Unknown Manufacturer>", sizeof(pState->szMfg));
     428
     429    if (pState->pDevDesc->dev_product)
     430        strlcpy(&pState->szProduct[0], pState->pDevDesc->dev_product, sizeof(pState->szProduct));
     431    else
     432        strlcpy(&pState->szProduct[0], "<Unnamed USB device>", sizeof(pState->szProduct));
     433}
     434
     435
     436/**
     437 * Queries the necessary symbols at runtime.
     438 *
     439 * @returns VBox status code.
     440 */
     441LOCAL int vboxUsbSolarisQuerySymbols(void)
     442{
     443    RTDBGKRNLINFO hKrnlDbgInfo;
     444    int rc = RTR0DbgKrnlInfoOpen(&hKrnlDbgInfo, 0 /* fFlags */);
     445    if (RT_SUCCESS(rc))
     446    {
     447        /*
     448         * Query and sanitize the size of usb_ep_data_t struct.
     449         */
     450        size_t cbPrevUsbEpData = g_cbUsbEpData;
     451        rc = RTR0DbgKrnlInfoQuerySize(hKrnlDbgInfo, "usba", "usb_ep_data_t", &g_cbUsbEpData);
     452        if (RT_FAILURE(rc))
     453        {
     454            LogRel(("Failed to query size of \"usb_ep_data_t\" in the \"usba\" module, rc=%Rrc\n", rc));
     455            return rc;
     456        }
     457        if (g_cbUsbEpData > _4K)
     458        {
     459            LogRel(("Size of \"usb_ep_data_t\" (%u bytes) seems implausible, too paranoid to continue\n", g_cbUsbEpData));
     460            return VERR_MISMATCH;
     461        }
     462
     463        /*
     464         * Query and sanitizie the offset of usb_ep_data_t::ep_descr.
     465         */
     466        size_t offPrevUsbEpDataDescr = g_offUsbEpDataDescr;
     467        rc = RTR0DbgKrnlInfoQueryMember(hKrnlDbgInfo, "usba", "usb_ep_data_t", "ep_descr", &g_offUsbEpDataDescr);
     468        if (RT_FAILURE(rc))
     469        {
     470            LogRel(("Failed to query offset of usb_ep_data_t::ep_descr, rc=%Rrc\n", rc));
     471            return rc;
     472        }
     473        if (g_offUsbEpDataDescr > _4K - sizeof(usb_ep_descr_t))
     474        {
     475            LogRel(("Offset of \"ep_desrc\" (%u) seems implausible, too paranoid to continue\n", g_offUsbEpDataDescr));
     476            return VERR_MISMATCH;
     477        }
     478
     479        /*
     480         * Log only when it changes / first time, since _init() seems to be called often (e.g. on failed attaches).
     481         * cmn_err, CE_CONT and '!' is used to not show the message on console during boot each time.
     482         */
     483        if (   cbPrevUsbEpData       != g_cbUsbEpData
     484            || offPrevUsbEpDataDescr != g_offUsbEpDataDescr)
     485        {
     486            cmn_err(CE_CONT, "!usba_ep_data_t is %lu bytes\n", g_cbUsbEpData);
     487            cmn_err(CE_CONT, "!usba_ep_data_t::ep_descr @ 0x%lx (%ld)\n", g_offUsbEpDataDescr, g_offUsbEpDataDescr);
     488        }
     489
     490        RTR0DbgKrnlInfoRelease(hKrnlDbgInfo);
     491    }
     492}
    389493
    390494
     
    394498int _init(void)
    395499{
    396     LogFunc((DEVICE_NAME ":_init\n"));
     500    LogFunc((DEVICE_NAME ": _init\n"));
    397501
    398502    /*
     
    403507        pModCtl->mod_loadflags |= MOD_NOAUTOUNLOAD;
    404508    else
    405         LogRel((DEVICE_NAME ":failed to disable autounloading!\n"));
     509        LogRel((DEVICE_NAME ": _init: failed to disable autounloading!\n"));
    406510
    407511    /*
     
    411515    if (RT_SUCCESS(rc))
    412516    {
     517        rc = vboxUsbSolarisQuerySymbols();
     518        if (RT_FAILURE(rc))
     519            return EINVAL;
     520
    413521        rc = ddi_soft_state_init(&g_pVBoxUSBSolarisState, sizeof(vboxusb_state_t), 4 /* pre-alloc */);
    414522        if (!rc)
     
    418526                return rc;
    419527
    420             LogRel((DEVICE_NAME ":mod_install failed! rc=%d\n", rc));
     528            LogRel((DEVICE_NAME ": _init: mod_install failed! rc=%d\n", rc));
    421529            ddi_soft_state_fini(&g_pVBoxUSBSolarisState);
    422530        }
    423531        else
    424             LogRel((DEVICE_NAME ":failed to initialize soft state.\n"));
     532            LogRel((DEVICE_NAME ": _init: failed to initialize soft state\n"));
    425533
    426534        RTR0Term();
    427535    }
    428536    else
    429         LogRel((DEVICE_NAME ":RTR0Init failed! rc=%d\n", rc));
     537        LogRel((DEVICE_NAME ": _init: RTR0Init failed! rc=%d\n", rc));
    430538    return RTErrConvertToErrno(rc);
    431539}
     
    436544    int rc;
    437545
    438     LogFunc((DEVICE_NAME ":_fini\n"));
     546    LogFunc((DEVICE_NAME ": _fini\n"));
    439547
    440548    rc = mod_remove(&g_VBoxUSBSolarisModLinkage);
     
    451559int _info(struct modinfo *pModInfo)
    452560{
    453     LogFunc((DEVICE_NAME ":_info\n"));
     561    LogFunc((DEVICE_NAME ": _info\n"));
    454562
    455563    return mod_info(&g_VBoxUSBSolarisModLinkage, pModInfo);
     
    463571 * @param   enmCmd          Attach type (ddi_attach_cmd_t)
    464572 *
    465  * @returns corresponding solaris error code.
     573 * @returns Solaris error code.
    466574 */
    467575int VBoxUSBSolarisAttach(dev_info_t *pDip, ddi_attach_cmd_t enmCmd)
    468576{
    469     LogFunc((DEVICE_NAME ":VBoxUSBSolarisAttach pDip=%p enmCmd=%d\n", pDip, enmCmd));
     577    LogFunc((DEVICE_NAME ": VBoxUSBSolarisAttach: pDip=%p enmCmd=%d\n", pDip, enmCmd));
    470578
    471579    int rc;
     
    483591                if (RT_LIKELY(pState))
    484592                {
    485                     pState->pDip = pDip;
    486                     pState->pDevDesc = NULL;
    487                     pState->fClosed = false;
    488                     pState->fRestoreCfg = false;
    489                     pState->fGetCfgReqDone = false;
     593                    pState->pDip             = pDip;
     594                    pState->pDevDesc         = NULL;
     595                    pState->fPollPending     = false;
     596                    pState->cInflightUrbs    = 0;
     597                    pState->cFreeUrbs        = 0;
     598                    pState->cLandedUrbs      = 0;
     599                    pState->Process          = NIL_RTPROCESS;
     600                    pState->pPower           = NULL;
    490601                    bzero(pState->aEps, sizeof(pState->aEps));
    491                     list_create(&pState->hUrbs, sizeof(vboxusb_urb_t), offsetof(vboxusb_urb_t, hListLink));
     602                    list_create(&pState->hFreeUrbs, sizeof(vboxusb_urb_t), offsetof(vboxusb_urb_t, hListLink));
     603                    list_create(&pState->hInflightUrbs, sizeof(vboxusb_urb_t), offsetof(vboxusb_urb_t, hListLink));
    492604                    list_create(&pState->hLandedUrbs, sizeof(vboxusb_urb_t), offsetof(vboxusb_urb_t, hListLink));
    493                     pState->cInflightUrbs = 0;
    494                     pState->fPoll = VBOXUSB_POLL_OFF;
    495                     pState->Process = NIL_RTPROCESS;
    496                     pState->pPower = NULL;
    497605
    498606                    /*
     
    500608                     * a non-USB device. So check if we are really binding to a USB device or not.
    501609                     */
    502                     if (vboxUSBSolarisIsUSBDevice(pState->pDip))
     610                    if (vboxUsbSolarisIsUSBDevice(pState->pDip))
    503611                    {
    504612                        /*
     
    508616                        if (rc == USB_SUCCESS)
    509617                        {
     618                            pState->fDefaultPipeOpen = true;
     619
    510620                            /*
    511621                             * Parse out the entire descriptor.
     
    514624                            if (rc == USB_SUCCESS)
    515625                            {
     626                                /*
     627                                 * Cache some device descriptor strings.
     628                                 */
     629                                vboxUsbSolarisGetDeviceStrings(pState);
    516630#ifdef DEBUG_ramshankar
    517631                                usb_print_descr_tree(pState->pDip, pState->pDevDesc);
     
    530644                                if (rc == USB_SUCCESS)
    531645                                {
    532                                     Log((DEVICE_NAME ":VBoxUSBSolarisAttach cbMaxBulkXfer=%d\n", pState->cbMaxBulkXfer));
     646                                    Log((DEVICE_NAME ": VBoxUSBSolarisAttach: cbMaxBulkXfer=%d\n", pState->cbMaxBulkXfer));
    533647
    534648                                    /*
    535                                      * Initialize all endpoints.
     649                                     * Initialize the default endpoint.
    536650                                     */
    537                                     rc = vboxUSBSolarisInitAllEndPoints(pState);
     651                                    rc = vboxUsbSolarisInitEp(pState, NULL /* pEp */);
    538652                                    if (RT_SUCCESS(rc))
    539653                                    {
     
    546660                                         * Initialize power management for the device.
    547661                                         */
    548                                         rc = vboxUSBSolarisInitPower(pState);
     662                                        rc = vboxUsbSolarisInitPower(pState);
    549663                                        if (RT_SUCCESS(rc))
    550664                                        {
    551665                                            /*
    552                                              * Update endpoints (descriptors) for the current config.
     666                                             * Initialize endpoints for the current config.
    553667                                             */
    554                                             vboxUSBSolarisInitEndPointsForConfig(pState, usb_get_current_cfgidx(pState->pDip));
     668                                            rc = vboxUsbSolarisInitEpsForCfg(pState);
     669                                            AssertRC(rc);
    555670
    556671                                            /*
     
    564679                                                 * Register hotplug callbacks.
    565680                                                 */
    566                                                 rc = usb_register_event_cbs(pState->pDip, &g_VBoxUSBSolarisEvents, 0 /* flags */);
     681                                                rc = usb_register_hotplug_cbs(pState->pDip, &vboxUsbSolarisDeviceDisconnected,
     682                                                                              &vboxUsbSolarisDeviceReconnected);
    567683                                                if (RT_LIKELY(rc == USB_SUCCESS))
    568684                                                {
     
    575691                                                    RTStrPrintf(pState->ClientInfo.szClientPath,
    576692                                                                sizeof(pState->ClientInfo.szClientPath),
    577                                                                 "/devices%s:%s", szDevicePath,DEVICE_NAME);
    578                                                     RTPathStripFilename(szDevicePath);
     693                                                                "/devices%s:%s", szDevicePath, DEVICE_NAME);
    579694                                                    RTStrPrintf(pState->ClientInfo.szDeviceIdent,
    580695                                                                sizeof(pState->ClientInfo.szDeviceIdent),
     
    584699                                                                pState->pDevDesc->dev_descr->bcdDevice, szDevicePath);
    585700                                                    pState->ClientInfo.Instance = instance;
    586                                                     pState->ClientInfo.pfnSetConsumerCredentials = &vboxUSBSolarisSetConsumerCredentials;
     701                                                    pState->ClientInfo.pfnSetConsumerCredentials = &vboxUsbSolarisSetConsumerCredentials;
    587702                                                    rc = VBoxUSBMonSolarisRegisterClient(pState->pDip, &pState->ClientInfo);
    588703                                                    if (RT_SUCCESS(rc))
    589704                                                    {
    590                                                         LogRel((DEVICE_NAME ": Captured %s %#x:%#x:%d:%s\n",
    591                                                                 pState->pDevDesc->dev_product ? pState->pDevDesc->dev_product
    592                                                                     : "<Unnamed USB device>",
    593                                                                 pState->pDevDesc->dev_descr->idVendor,
    594                                                                 pState->pDevDesc->dev_descr->idProduct,
    595                                                                 pState->pDevDesc->dev_descr->bcdDevice,
    596                                                                 pState->ClientInfo.szClientPath));
    597 
     705                                                        LogRel((DEVICE_NAME ": Captured %s %s (Ident=%s)\n", pState->szMfg,
     706                                                                pState->szProduct, pState->ClientInfo.szDeviceIdent));
    598707                                                        return DDI_SUCCESS;
    599708                                                    }
    600                                                     else
    601                                                     {
    602                                                         LogRel((DEVICE_NAME ":VBoxUSBMonSolarisRegisterClient failed! rc=%d "
    603                                                                 "path=%s instance=%d\n", rc, pState->ClientInfo.szClientPath,
    604                                                                 instance));
    605                                                     }
    606 
    607                                                     usb_unregister_event_cbs(pState->pDip, &g_VBoxUSBSolarisEvents);
     709
     710                                                    LogRel((DEVICE_NAME ": VBoxUSBMonSolarisRegisterClient failed! rc=%d "
     711                                                            "path=%s instance=%d\n", rc, pState->ClientInfo.szClientPath,
     712                                                            instance));
     713
     714                                                    usb_unregister_hotplug_cbs(pState->pDip);
    608715                                                }
    609716                                                else
    610                                                     LogRel((DEVICE_NAME ":VBoxUSBSolarisAttach failed to register hotplug "
    611                                                             "callbacks! rc=%d\n", rc));
     717                                                    LogRel((DEVICE_NAME ": VBoxUSBSolarisAttach: Failed to register hotplug callbacks! rc=%d\n", rc));
    612718
    613719                                                ddi_remove_minor_node(pState->pDip, NULL);
    614720                                            }
    615721                                            else
    616                                             {
    617                                                 LogRel((DEVICE_NAME ":VBoxUSBSolarisAttach ddi_create_minor_node failed! rc=%d\n",
    618                                                         rc));
    619                                             }
     722                                                LogRel((DEVICE_NAME ": VBoxUSBSolarisAttach: ddi_create_minor_node failed! rc=%d\n", rc));
     723
     724                                            mutex_enter(&pState->Mtx);
     725                                            vboxUsbSolarisDestroyPower(pState);
     726                                            mutex_exit(&pState->Mtx);
    620727                                        }
    621728                                        else
    622                                         {
    623                                             LogRel((DEVICE_NAME ":VBoxUSBSolarisAttach failed to initialize power management! "
    624                                                     "rc=%d\n", rc));
    625                                         }
     729                                            LogRel((DEVICE_NAME ": VBoxUSBSolarisAttach: Failed to init power management! rc=%d\n", rc));
    626730                                    }
    627731                                    else
    628                                     {
    629                                         LogRel((DEVICE_NAME ":VBoxUSBSolarisAttach vboxUSBSolarisInitAllEndPoints failed! "
    630                                                 "rc=%d\n"));
    631                                     }
     732                                        LogRel((DEVICE_NAME ": VBoxUSBSolarisAttach: vboxUsbSolarisInitEp failed! rc=%d\n", rc));
    632733                                }
    633734                                else
    634                                 {
    635                                     LogRel((DEVICE_NAME ":VBoxUSBSolarisAttach usb_pipe_get_max_bulk_transfer_size failed! "
    636                                             "rc=%d\n", rc));
    637                                 }
     735                                    LogRel((DEVICE_NAME ": VBoxUSBSolarisAttach: usb_pipe_get_max_bulk_transfer_size failed! rc=%d\n", rc));
    638736
    639737                                usb_fini_serialization(pState->StateMulti);
     
    642740                            }
    643741                            else
    644                                 LogRel((DEVICE_NAME ":VBoxUSBSolarisAttach failed to get device descriptor. rc=%d\n", rc));
     742                                LogRel((DEVICE_NAME ": VBoxUSBSolarisAttach: Failed to get device descriptor. rc=%d\n", rc));
    645743
    646744                            usb_client_detach(pState->pDip, NULL);
    647745                        }
    648746                        else
    649                             LogRel((DEVICE_NAME ":VBoxUSBSolarisAttach usb_client_attach failed! rc=%d\n", rc));
     747                            LogRel((DEVICE_NAME ": VBoxUSBSolarisAttach: usb_client_attach failed! rc=%d\n", rc));
    650748                    }
    651749                    else
    652750                    {
    653751                        /* This would appear on every boot if it were LogRel() */
    654                         Log((DEVICE_NAME ":VBoxUSBSolarisAttach not a USB device.\n"));
     752                        Log((DEVICE_NAME ": VBoxUSBSolarisAttach: Not a USB device\n"));
    655753                    }
    656754                }
    657755                else
    658                     LogRel((DEVICE_NAME ":VBoxUSBSolarisAttach failed to get soft state\n", sizeof(*pState)));
     756                    LogRel((DEVICE_NAME ": VBoxUSBSolarisAttach: Failed to get soft state\n", sizeof(*pState)));
    659757
    660758                ddi_soft_state_free(g_pVBoxUSBSolarisState, instance);
    661759            }
    662760            else
    663                 LogRel((DEVICE_NAME ":VBoxUSBSolarisAttach failed to alloc soft state. rc=%d\n", rc));
     761                LogRel((DEVICE_NAME ": VBoxUSBSolarisAttach: Failed to alloc soft state. rc=%d\n", rc));
    664762
    665763            return DDI_FAILURE;
     
    671769            if (RT_UNLIKELY(!pState))
    672770            {
    673                 LogRel((DEVICE_NAME ":VBoxUSBSolarisAttach DDI_RESUME: failed to get soft state on detach.\n"));
     771                LogRel((DEVICE_NAME ": VBoxUSBSolarisAttach: DDI_RESUME failed to get soft state on detach\n"));
    674772                return DDI_FAILURE;
    675773            }
    676774
    677             vboxUSBSolarisDeviceResume(pState);
     775            vboxUsbSolarisDeviceResume(pState);
    678776            return DDI_SUCCESS;
    679777        }
     
    691789 * @param   enmCmd          Attach type (ddi_attach_cmd_t)
    692790 *
    693  * @returns corresponding solaris error code.
     791 * @returns Solaris error code.
    694792 */
    695793int VBoxUSBSolarisDetach(dev_info_t *pDip, ddi_detach_cmd_t enmCmd)
    696794{
    697     LogFunc((DEVICE_NAME ":VBoxUSBSolarisDetach pDip=%p enmCmd=%d\n", pDip, enmCmd));
     795    LogFunc((DEVICE_NAME ": VBoxUSBSolarisDetach: pDip=%p enmCmd=%d\n", pDip, enmCmd));
    698796
    699797    int instance = ddi_get_instance(pDip);
     
    701799    if (RT_UNLIKELY(!pState))
    702800    {
    703         LogRel((DEVICE_NAME ":VBoxUSBSolarisDetach failed to get soft state on detach.\n"));
     801        LogRel((DEVICE_NAME ": VBoxUSBSolarisDetach: Failed to get soft state on detach\n"));
    704802        return DDI_FAILURE;
    705803    }
     
    718816             * Notify userland if any that we're gone (while resetting device held by us).
    719817             */
    720             vboxUSBSolarisNotifyHotplug(pState);
     818            mutex_enter(&pState->Mtx);
     819            pState->DevState = USB_DEV_DISCONNECTED;
     820            vboxUsbSolarisNotifyUnplug(pState);
     821            mutex_exit(&pState->Mtx);
     822
    721823
    722824            /*
     
    724826             * would otherwise block on the mutex.
    725827             */
    726             usb_unregister_event_cbs(pDip, &g_VBoxUSBSolarisEvents);
    727 
     828            usb_unregister_hotplug_cbs(pDip);
    728829
    729830            /*
    730831             * Serialize: paranoid; drain other driver activity.
    731832             */
    732             usb_serialize_access(pState->StateMulti, USB_WAIT, 0);
     833            usb_serialize_access(pState->StateMulti, USB_WAIT, 0 /* timeout */);
    733834            usb_release_access(pState->StateMulti);
    734835            mutex_enter(&pState->Mtx);
    735836
    736837            /*
    737              * Close all endpoints.
     838             * Close all pipes.
    738839             */
    739             vboxUSBSolarisCloseAllPipes(pState, true /* ControlPipe */);
    740             pState->fClosed = true;
     840            vboxUsbSolarisCloseAllPipes(pState, true /* ControlPipe */);
     841            Assert(!pState->fDefaultPipeOpen);
    741842
    742843            /*
    743              * Deinitialize power, destroy endpoints.
     844             * Deinitialize power, destroy all endpoints.
    744845             */
    745             vboxUSBSolarisDestroyPower(pState);
    746             vboxUSBSolarisDestroyAllEndPoints(pState);
     846            vboxUsbSolarisDestroyPower(pState);
     847            vboxUsbSolarisDestroyAllEps(pState);
    747848
    748849            /*
    749              * Free up all URBs.
     850             * Free up all URB lists.
    750851             */
    751852            vboxusb_urb_t *pUrb = NULL;
    752             while ((pUrb = list_remove_head(&pState->hUrbs)) != NULL)
     853            while ((pUrb = list_remove_head(&pState->hFreeUrbs)) != NULL)
    753854            {
    754855                if (pUrb->pMsg)
     
    756857                RTMemFree(pUrb);
    757858            }
    758 
     859            while ((pUrb = list_remove_head(&pState->hInflightUrbs)) != NULL)
     860            {
     861                if (pUrb->pMsg)
     862                    freemsg(pUrb->pMsg);
     863                RTMemFree(pUrb);
     864            }
    759865            while ((pUrb = list_remove_head(&pState->hLandedUrbs)) != NULL)
    760866            {
     
    763869                RTMemFree(pUrb);
    764870            }
     871            pState->cFreeUrbs     = 0;
     872            pState->cLandedUrbs   = 0;
    765873            pState->cInflightUrbs = 0;
    766             list_destroy(&pState->hUrbs);
     874            list_destroy(&pState->hFreeUrbs);
     875            list_destroy(&pState->hInflightUrbs);
    767876            list_destroy(&pState->hLandedUrbs);
    768877
     
    784893            ddi_remove_minor_node(pState->pDip, NULL);
    785894
    786             LogRel((DEVICE_NAME ": Released %s %s\n",
    787                     pState->pDevDesc->dev_product ? pState->pDevDesc->dev_product : "<Unnamed USB device>",
     895            LogRel((DEVICE_NAME ": Released %s %s (Ident=%s)\n", pState->szMfg, pState->szProduct,
    788896                    pState->ClientInfo.szDeviceIdent));
    789897
    790898            ddi_soft_state_free(g_pVBoxUSBSolarisState, instance);
    791899            pState = NULL;
    792 
    793900            return DDI_SUCCESS;
    794901        }
     
    796903        case DDI_SUSPEND:
    797904        {
    798             int rc = vboxUSBSolarisDeviceSuspend(pState);
     905            int rc = vboxUsbSolarisDeviceSuspend(pState);
    799906            if (RT_SUCCESS(rc))
    800907                return DDI_SUCCESS;
     
    817924 * @param   ppvResult       Where to store the requested info.
    818925 *
    819  * @returns corresponding solaris error code.
     926 * @returns Solaris error code.
    820927 */
    821928int VBoxUSBSolarisGetInfo(dev_info_t *pDip, ddi_info_cmd_t enmCmd, void *pvArg, void **ppvResult)
    822929{
    823     LogFunc((DEVICE_NAME ":VBoxUSBSolarisGetInfo\n"));
     930    LogFunc((DEVICE_NAME ": VBoxUSBSolarisGetInfo\n"));
    824931
    825932    vboxusb_state_t *pState = NULL;
     
    840947            }
    841948            else
    842                 LogRel((DEVICE_NAME ":VBoxUSBSolarisGetInfo failed to get device state.\n"));
     949                LogRel((DEVICE_NAME ": VBoxUSBSolarisGetInfo: Failed to get device state\n"));
    843950            return DDI_FAILURE;
    844951        }
     
    857964
    858965/**
    859  * Callback invoked from the Monitor driver when a VM process tries to access
    860  * this client instance. This determines which VM process will be allowed to
    861  * open and access the USB device.
     966 * Callback invoked from the VirtualBox USB Monitor driver when a VM process
     967 * tries to access this USB client instance.
     968 *
     969 * This determines which VM process will be allowed to open and access this USB
     970 * device.
    862971 *
    863972 * @returns  VBox status code.
     
    868977 * @param    pvReserved     Reserved for future, unused.
    869978 */
    870 LOCAL int vboxUSBSolarisSetConsumerCredentials(RTPROCESS Process, int Instance, void *pvReserved)
    871 {
    872     LogFunc((DEVICE_NAME ":vboxUSBSolarisSetConsumerCredentials Process=%u Instance=%d\n", Process, Instance));
     979LOCAL int vboxUsbSolarisSetConsumerCredentials(RTPROCESS Process, int Instance, void *pvReserved)
     980{
     981    LogFunc((DEVICE_NAME ": vboxUsbSolarisSetConsumerCredentials: Process=%u Instance=%d\n", Process, Instance));
    873982    vboxusb_state_t *pState = ddi_get_soft_state(g_pVBoxUSBSolarisState, Instance);
    874983    if (!pState)
    875984    {
    876         LogRel((DEVICE_NAME ":vboxUSBSolarisSetConsumerCredentials failed to get device state for instance %d\n", Instance));
     985        LogRel((DEVICE_NAME ": vboxUsbSolarisSetConsumerCredentials: Failed to get device state for instance %d\n", Instance));
    877986        return VERR_INVALID_STATE;
    878987    }
     
    885994    else
    886995    {
    887         LogRel((DEVICE_NAME ":vboxUSBSolarisSetConsumerCredentials failed! Process %u already has client open.\n",
     996        LogRel((DEVICE_NAME ": vboxUsbSolarisSetConsumerCredentials: Failed! Process %u already has client open\n",
    888997                pState->Process));
    889998        rc = VERR_RESOURCE_BUSY;
     
    8981007int VBoxUSBSolarisOpen(dev_t *pDev, int fFlag, int fType, cred_t *pCred)
    8991008{
    900     LogFunc((DEVICE_NAME ":VBoxUSBSolarisOpen pDev=%p fFlag=%d fType=%d pCred=%p\n", pDev, fFlag, fType, pCred));
     1009    LogFunc((DEVICE_NAME ": VBoxUSBSolarisOpen: pDev=%p fFlag=%d fType=%d pCred=%p\n", pDev, fFlag, fType, pCred));
    9011010
    9021011    /*
     
    9131022    if (!pState)
    9141023    {
    915         LogRel((DEVICE_NAME ":VBoxUSBSolarisOpen failed to get device state for instance %d\n", instance));
     1024        LogRel((DEVICE_NAME ": VBoxUSBSolarisOpen: Failed to get device state for instance %d\n", instance));
    9161025        return ENXIO;
    9171026    }
     
    9251034    {
    9261035        if (pState->Process == NIL_RTPROCESS)
    927             LogRel((DEVICE_NAME ":VBoxUSBSolarisOpen No prior information about authorized process.\n"));
     1036            LogRel((DEVICE_NAME ": VBoxUSBSolarisOpen: No prior information about authorized process\n"));
    9281037        else
    929             LogRel((DEVICE_NAME ":VBoxUSBSolarisOpen Process %u is already using this device instance.\n", pState->Process));
     1038            LogRel((DEVICE_NAME ": VBoxUSBSolarisOpen: Process %u is already using this device instance\n", pState->Process));
    9301039
    9311040        mutex_exit(&pState->Mtx);
     
    9331042    }
    9341043
    935     pState->fPoll = VBOXUSB_POLL_ON;
    936 
    9371044    mutex_exit(&pState->Mtx);
    9381045
     
    9461053int VBoxUSBSolarisClose(dev_t Dev, int fFlag, int fType, cred_t *pCred)
    9471054{
    948     LogFunc((DEVICE_NAME ":VBoxUSBSolarisClose Dev=%d fFlag=%d fType=%d pCred=%p\n", Dev, fFlag, fType, pCred));
     1055    LogFunc((DEVICE_NAME ": VBoxUSBSolarisClose: Dev=%d fFlag=%d fType=%d pCred=%p\n", Dev, fFlag, fType, pCred));
    9491056
    9501057    int instance = getminor((dev_t)Dev);
     
    9521059    if (RT_UNLIKELY(!pState))
    9531060    {
    954         LogRel((DEVICE_NAME ":VBoxUSBSolarisClose failed to get device state for instance %d\n", instance));
     1061        LogRel((DEVICE_NAME ": VBoxUSBSolarisClose: Failed to get device state for instance %d\n", instance));
    9551062        return ENXIO;
    9561063    }
    9571064
    9581065    mutex_enter(&pState->Mtx);
    959     pState->fPoll = VBOXUSB_POLL_OFF;
    960     pState->Process = NIL_RTPROCESS;
     1066    pState->fPollPending  = false;
     1067    pState->Process       = NIL_RTPROCESS;
    9611068    mutex_exit(&pState->Mtx);
    9621069
     
    9671074int VBoxUSBSolarisRead(dev_t Dev, struct uio *pUio, cred_t *pCred)
    9681075{
    969     LogFunc((DEVICE_NAME ":VBoxUSBSolarisRead\n"));
     1076    LogFunc((DEVICE_NAME ": VBoxUSBSolarisRead\n"));
    9701077    return ENOTSUP;
    9711078}
     
    9741081int VBoxUSBSolarisWrite(dev_t Dev, struct uio *pUio, cred_t *pCred)
    9751082{
    976     LogFunc((DEVICE_NAME ":VBoxUSBSolarisWrite\n"));
     1083    LogFunc((DEVICE_NAME ": VBoxUSBSolarisWrite\n"));
    9771084    return ENOTSUP;
    9781085}
     
    9811088int VBoxUSBSolarisPoll(dev_t Dev, short fEvents, int fAnyYet, short *pReqEvents, struct pollhead **ppPollHead)
    9821089{
    983     LogFunc((DEVICE_NAME ":VBoxUSBSolarisPoll Dev=%d fEvents=%d fAnyYet=%d pReqEvents=%p\n", Dev, fEvents, fAnyYet, pReqEvents));
     1090    LogFunc((DEVICE_NAME ": VBoxUSBSolarisPoll: Dev=%d fEvents=%d fAnyYet=%d pReqEvents=%p\n", Dev, fEvents, fAnyYet, pReqEvents));
    9841091
    9851092    /*
     
    9901097    if (RT_UNLIKELY(!pState))
    9911098    {
    992         LogRel((DEVICE_NAME ":VBoxUSBSolarisPoll: no state data for %d\n", instance));
     1099        LogRel((DEVICE_NAME ": VBoxUSBSolarisPoll: No state data for %d\n", instance));
    9931100        return ENXIO;
    9941101    }
     
    9971104
    9981105    /*
    999      * "fEvents" HAS to be POLLIN. We won't bother to test it. The caller
    1000      * must always requests input events. Disconnect event (POLLHUP) is invalid in "fEvents".
     1106     * Disconnect event (POLLHUP) is invalid in "fEvents".
    10011107     */
    1002     fEvents = 0;
    1003     if (pState->fPoll & VBOXUSB_POLL_DEV_UNPLUGGED)
    1004     {
    1005         fEvents |= POLLHUP;
    1006         pState->fPoll &= ~VBOXUSB_POLL_DEV_UNPLUGGED;
    1007     }
    1008 
    1009     if (pState->fPoll & VBOXUSB_POLL_REAP_PENDING)
    1010     {
    1011         fEvents |= POLLIN;
    1012         pState->fPoll &= ~VBOXUSB_POLL_REAP_PENDING;
    1013     }
    1014 
    1015     if (   !fEvents
    1016         && !fAnyYet)
    1017     {
    1018         *ppPollHead = &pState->PollHead;
    1019     }
    1020 
    1021     *pReqEvents = fEvents;
     1108    if (pState->DevState == USB_DEV_DISCONNECTED)
     1109        *pReqEvents |= POLLHUP;
     1110    else if (pState->cLandedUrbs)
     1111        *pReqEvents |= POLLIN;
     1112    else
     1113    {
     1114        *pReqEvents = 0;
     1115        if (!fAnyYet)
     1116        {
     1117            *ppPollHead = &pState->PollHead;
     1118            pState->fPollPending = true;
     1119        }
     1120    }
    10221121
    10231122    mutex_exit(&pState->Mtx);
     
    10291128int VBoxUSBSolarisPower(dev_info_t *pDip, int Component, int Level)
    10301129{
    1031     LogFunc((DEVICE_NAME ":VBoxUSBSolarisPower pDip=%p Component=%d Level=%d\n", pDip, Component, Level));
     1130    LogFunc((DEVICE_NAME ": VBoxUSBSolarisPower: pDip=%p Component=%d Level=%d\n", pDip, Component, Level));
    10321131
    10331132    int instance = ddi_get_instance(pDip);
     
    10351134    if (RT_UNLIKELY(!pState))
    10361135    {
    1037         LogRel((DEVICE_NAME ":VBoxUSBSolarisPower Failed! missing state.\n"));
     1136        LogRel((DEVICE_NAME ": VBoxUSBSolarisPower: Failed! State Gone\n"));
    10381137        return DDI_FAILURE;
    10391138    }
     
    10651164                    pState->pPower->PowerLevel = USB_DEV_OS_PWR_OFF;
    10661165                    mutex_exit(&pState->Mtx);
    1067                     rc = usb_set_device_pwrlvl3(pDip);
     1166                    rc = USB_SUCCESS; /* usb_set_device_pwrlvl3(pDip); */
    10681167                    mutex_enter(&pState->Mtx);
    10691168                    break;
     
    10771176                    pState->pPower->PowerLevel = USB_DEV_OS_FULL_PWR;
    10781177                    mutex_exit(&pState->Mtx);
    1079                     rc = usb_set_device_pwrlvl0(pDip);
     1178                    rc = USB_SUCCESS; /* usb_set_device_pwrlvl0(pDip); */
    10801179                    mutex_enter(&pState->Mtx);
    10811180                    break;
     
    10871186        }
    10881187        else
    1089             Log((DEVICE_NAME ":USB_DEV_PWRSTATE_OK failed.\n"));
     1188            Log((DEVICE_NAME ": VBoxUSBSolarisPower: USB_DEV_PWRSTATE_OK failed\n"));
    10901189    }
    10911190    else
     
    11081207int VBoxUSBSolarisIOCtl(dev_t Dev, int Cmd, intptr_t pArg, int Mode, cred_t *pCred, int *pVal)
    11091208{
    1110 /*    LogFunc((DEVICE_NAME ":VBoxUSBSolarisIOCtl Dev=%d Cmd=%d pArg=%p Mode=%d\n", Dev, Cmd, pArg)); */
     1209    /* LogFunc((DEVICE_NAME ": VBoxUSBSolarisIOCtl: Dev=%d Cmd=%d pArg=%p Mode=%d\n", Dev, Cmd, pArg)); */
    11111210
    11121211    /*
     
    11171216    if (RT_UNLIKELY(!pState))
    11181217    {
    1119         LogRel((DEVICE_NAME ":VBoxUSBSolarisIOCtl: no state data for %d\n", instance));
     1218        LogRel((DEVICE_NAME ": VBoxUSBSolarisIOCtl: No state data for %d\n", instance));
    11201219        return EINVAL;
    11211220    }
     
    11271226    if (IOCPARM_LEN(Cmd) != sizeof(ReqWrap))
    11281227    {
    1129         LogRel((DEVICE_NAME ": VBoxUSBSolarisIOCtl: bad request %#x size=%d expected=%d\n", Cmd, IOCPARM_LEN(Cmd),
     1228        LogRel((DEVICE_NAME ": VBoxUSBSolarisIOCtl: Bad request %#x size=%d expected=%d\n", Cmd, IOCPARM_LEN(Cmd),
    11301229                sizeof(ReqWrap)));
    11311230        return ENOTTY;
     
    11351234    if (RT_UNLIKELY(rc))
    11361235    {
    1137         LogRel((DEVICE_NAME ": VBoxUSBSolarisIOCtl: ddi_copyin failed to read header pArg=%p Cmd=%d. rc=%d.\n", pArg, Cmd, rc));
     1236        LogRel((DEVICE_NAME ": VBoxUSBSolarisIOCtl: ddi_copyin failed to read header pArg=%p Cmd=%d. rc=%d\n", pArg, Cmd, rc));
    11381237        return EINVAL;
    11391238    }
     
    11411240    if (ReqWrap.u32Magic != VBOXUSB_MAGIC)
    11421241    {
    1143         LogRel((DEVICE_NAME ": VBoxUSBSolarisIOCtl: bad magic %#x; pArg=%p Cmd=%d.\n", ReqWrap.u32Magic, pArg, Cmd));
     1242        LogRel((DEVICE_NAME ": VBoxUSBSolarisIOCtl: Bad magic %#x; pArg=%p Cmd=%d\n", ReqWrap.u32Magic, pArg, Cmd));
    11441243        return EINVAL;
    11451244    }
     
    11471246                    || ReqWrap.cbData > _1M*16))
    11481247    {
    1149         LogRel((DEVICE_NAME ": VBoxUSBSolarisIOCtl: bad size %#x; pArg=%p Cmd=%d.\n", ReqWrap.cbData, pArg, Cmd));
     1248        LogRel((DEVICE_NAME ": VBoxUSBSolarisIOCtl: Bad size %#x; pArg=%p Cmd=%d\n", ReqWrap.cbData, pArg, Cmd));
    11501249        return EINVAL;
    11511250    }
     
    11571256    if (RT_UNLIKELY(!pvBuf))
    11581257    {
    1159         LogRel((DEVICE_NAME ":VBoxUSBSolarisIOCtl: RTMemTmpAlloc failed to alloc %d bytes.\n", ReqWrap.cbData));
     1258        LogRel((DEVICE_NAME ": VBoxUSBSolarisIOCtl: RTMemTmpAlloc failed to alloc %d bytes\n", ReqWrap.cbData));
    11601259        return ENOMEM;
    11611260    }
     
    11651264    {
    11661265        RTMemTmpFree(pvBuf);
    1167         LogRel((DEVICE_NAME ":VBoxUSBSolarisIOCtl: ddi_copyin failed; pvBuf=%p pArg=%p Cmd=%d. rc=%d\n", pvBuf, pArg, Cmd, rc));
     1266        LogRel((DEVICE_NAME ": VBoxUSBSolarisIOCtl: ddi_copyin failed! pvBuf=%p pArg=%p Cmd=%d. rc=%d\n", pvBuf, pArg, Cmd, rc));
    11681267        return EFAULT;
    11691268    }
     
    11721271    {
    11731272        RTMemTmpFree(pvBuf);
    1174         LogRel((DEVICE_NAME ":VBoxUSBSolarisIOCtl: invalid request pvBuf=%p cbData=%d\n", pvBuf, ReqWrap.cbData));
     1273        LogRel((DEVICE_NAME ": VBoxUSBSolarisIOCtl: Invalid request! pvBuf=%p cbData=%d\n", pvBuf, ReqWrap.cbData));
    11751274        return EINVAL;
    11761275    }
     
    11801279     */
    11811280    size_t cbDataOut = 0;
    1182     rc = vboxUSBSolarisProcessIOCtl(Cmd, pState, Mode, &ReqWrap, pvBuf, &cbDataOut);
     1281    rc = vboxUsbSolarisProcessIOCtl(Cmd, pState, Mode, &ReqWrap, pvBuf, &cbDataOut);
    11831282    ReqWrap.rc = rc;
    11841283    rc = 0;
     
    11861285    if (RT_UNLIKELY(cbDataOut > ReqWrap.cbData))
    11871286    {
    1188         LogRel((DEVICE_NAME ":VBoxUSBSolarisIOCtl: too much output data %d expected %d Truncating!\n", cbDataOut,
     1287        LogRel((DEVICE_NAME ": VBoxUSBSolarisIOCtl: Too much output data %d expected %d Truncating!\n", cbDataOut,
    11891288                ReqWrap.cbData));
    11901289        cbDataOut = ReqWrap.cbData;
     
    12071306            if (RT_UNLIKELY(rc))
    12081307            {
    1209                 LogRel((DEVICE_NAME ":VBoxUSBSolarisIOCtl: ddi_copyout failed; pvBuf=%p pArg=%p Cmd=%d. rc=%d\n", pvBuf, pArg,
     1308                LogRel((DEVICE_NAME ": VBoxUSBSolarisIOCtl: ddi_copyout failed! pvBuf=%p pArg=%p Cmd=%d. rc=%d\n", pvBuf, pArg,
    12101309                        Cmd, rc));
    12111310                rc = EFAULT;
     
    12151314    else
    12161315    {
    1217         LogRel((DEVICE_NAME ":VBoxUSBSolarisIOCtl: ddi_copyout(1)failed; pReqWrap=%p pArg=%p Cmd=%d. rc=%d\n", &ReqWrap, pArg,
     1316        LogRel((DEVICE_NAME ": VBoxUSBSolarisIOCtl: ddi_copyout(1)failed! pReqWrap=%p pArg=%p Cmd=%d. rc=%d\n", &ReqWrap, pArg,
    12181317                Cmd, rc));
    12191318        rc = EFAULT;
     
    12381337 * @param   pcbDataOut          Where to store the IOCtl OUT data size.
    12391338 */
    1240 LOCAL int vboxUSBSolarisProcessIOCtl(int iFunction, void *pvState, int Mode, PVBOXUSBREQ pUSBReq, void *pvBuf, size_t *pcbDataOut)
    1241 {
    1242 //    LogFunc((DEVICE_NAME ":vboxUSBSolarisProcessIOCtl iFunction=%d pvState=%p pUSBReq=%p\n", iFunction, pvState, pUSBReq));
     1339LOCAL int vboxUsbSolarisProcessIOCtl(int iFunction, void *pvState, int Mode, PVBOXUSBREQ pUSBReq, void *pvBuf,
     1340                                     size_t *pcbDataOut)
     1341{
     1342    /* LogFunc((DEVICE_NAME ": vboxUsbSolarisProcessIOCtl: iFunction=%d pvState=%p pUSBReq=%p\n", iFunction, pvState, pUSBReq)); */
    12431343
    12441344    AssertPtrReturn(pvState, VERR_INVALID_PARAMETER);
     
    12511351        if (cbData < (cbMin)) \
    12521352        { \
    1253             LogRel((DEVICE_NAME ":vboxUSBSolarisProcessIOCtl: " mnemonic ": cbData=%#zx (%zu) min is %#zx (%zu)\n", \
     1353            LogRel((DEVICE_NAME ": vboxUsbSolarisProcessIOCtl: " mnemonic ": cbData=%#zx (%zu) min is %#zx (%zu)\n", \
    12541354                 cbData, cbData, (size_t)(cbMin), (size_t)(cbMin))); \
    12551355            return VERR_BUFFER_OVERFLOW; \
     
    12571357        if ((cbMin) != 0 && !VALID_PTR(pvBuf)) \
    12581358        { \
    1259             LogRel((DEVICE_NAME ":vboxUSBSolarisProcessIOCtl: " mnemonic ": Invalid pointer %p\n", pvBuf)); \
     1359            LogRel((DEVICE_NAME ": vboxUsbSolarisProcessIOCtl: " mnemonic ": Invalid pointer %p\n", pvBuf)); \
    12601360            return VERR_INVALID_PARAMETER; \
    12611361        } \
     
    12691369
    12701370            PVBOXUSBREQ_URB pUrbReq = (PVBOXUSBREQ_URB)pvBuf;
    1271             rc = vboxUSBSolarisSendURB(pState, pUrbReq, Mode);
     1371            rc = vboxUsbSolarisSendUrb(pState, pUrbReq, Mode);
    12721372            *pcbDataOut = 0;
    1273             Log((DEVICE_NAME ":vboxUSBSolarisProcessIOCtl: SEND_URB returned %d\n", rc));
     1373            Log((DEVICE_NAME ": vboxUsbSolarisProcessIOCtl: SEND_URB returned %d\n", rc));
    12741374            break;
    12751375        }
     
    12801380
    12811381            PVBOXUSBREQ_URB pUrbReq = (PVBOXUSBREQ_URB)pvBuf;
    1282             rc = vboxUSBSolarisReapURB(pState, pUrbReq, Mode);
     1382            rc = vboxUsbSolarisReapUrb(pState, pUrbReq, Mode);
    12831383            *pcbDataOut = sizeof(VBOXUSBREQ_URB);
    1284             Log((DEVICE_NAME ":vboxUSBSolarisProcessIOCtl: REAP_URB returned %d\n", rc));
     1384            Log((DEVICE_NAME ": vboxUsbSolarisProcessIOCtl: REAP_URB returned %d\n", rc));
    12851385            break;
    12861386        }
     
    12911391
    12921392            PVBOXUSBREQ_CLEAR_EP pClearEpReq = (PVBOXUSBREQ_CLEAR_EP)pvBuf;
    1293             rc = vboxUSBSolarisClearEndPoint(pState, pClearEpReq->bEndpoint);
     1393            rc = vboxUsbSolarisClearEndPoint(pState, pClearEpReq->bEndpoint);
    12941394            *pcbDataOut = 0;
    1295             Log((DEVICE_NAME ":vboxUSBSolarisProcessIOCtl: CLEAR_EP returned %d\n", rc));
     1395            Log((DEVICE_NAME ": vboxUsbSolarisProcessIOCtl: CLEAR_EP returned %d\n", rc));
    12961396            break;
    12971397        }
     
    13021402
    13031403            PVBOXUSBREQ_SET_CONFIG pSetCfgReq = (PVBOXUSBREQ_SET_CONFIG)pvBuf;
    1304             rc = vboxUSBSolarisSetConfig(pState, pSetCfgReq->bConfigValue);
     1404            rc = vboxUsbSolarisSetConfig(pState, pSetCfgReq->bConfigValue);
    13051405            *pcbDataOut = 0;
    1306             Log((DEVICE_NAME ":vboxUSBSolarisProcessIOCtl: SET_CONFIG returned %d\n", rc));
     1406            Log((DEVICE_NAME ": vboxUsbSolarisProcessIOCtl: SET_CONFIG returned %d\n", rc));
    13071407            break;
    13081408        }
     
    13131413
    13141414            PVBOXUSBREQ_SET_INTERFACE pSetInterfaceReq = (PVBOXUSBREQ_SET_INTERFACE)pvBuf;
    1315             rc = vboxUSBSolarisSetInterface(pState, pSetInterfaceReq->bInterface, pSetInterfaceReq->bAlternate);
     1415            rc = vboxUsbSolarisSetInterface(pState, pSetInterfaceReq->bInterface, pSetInterfaceReq->bAlternate);
    13161416            *pcbDataOut = 0;
    1317             Log((DEVICE_NAME ":vboxUSBSolarisProcessIOCtl: SET_INTERFACE returned %d\n", rc));
     1417            Log((DEVICE_NAME ": vboxUsbSolarisProcessIOCtl: SET_INTERFACE returned %d\n", rc));
    13181418            break;
    13191419        }
     
    13241424
    13251425            PVBOXUSBREQ_CLOSE_DEVICE pCloseDeviceReq = (PVBOXUSBREQ_CLOSE_DEVICE)pvBuf;
    1326             rc = vboxUSBSolarisCloseDevice(pState, pCloseDeviceReq->ResetLevel);
     1426            if (   pCloseDeviceReq->ResetLevel != VBOXUSB_RESET_LEVEL_REATTACH
     1427                || (Mode & FKIOCTL))
     1428            {
     1429                rc = vboxUsbSolarisCloseDevice(pState, pCloseDeviceReq->ResetLevel);
     1430            }
     1431            else
     1432            {
     1433                /* Userland IOCtls are not allowed to perform a reattach of the device. */
     1434                rc = VERR_NOT_SUPPORTED;
     1435            }
    13271436            *pcbDataOut = 0;
    1328             Log((DEVICE_NAME ":vboxUSBSolarisProcessIOCtl: CLOSE_DEVICE returned %d\n", rc));
     1437            Log((DEVICE_NAME ": vboxUsbSolarisProcessIOCtl: CLOSE_DEVICE returned %d\n", rc));
    13291438            break;
    13301439        }
     
    13351444
    13361445            PVBOXUSBREQ_ABORT_PIPE pAbortPipeReq = (PVBOXUSBREQ_ABORT_PIPE)pvBuf;
    1337             rc = vboxUSBSolarisAbortPipe(pState, pAbortPipeReq->bEndpoint);
     1446            rc = vboxUsbSolarisAbortPipe(pState, pAbortPipeReq->bEndpoint);
    13381447            *pcbDataOut = 0;
    1339             Log((DEVICE_NAME ":vboxUSBSolarisProcessIOCtl: ABORT_PIPE returned %d\n", rc));
     1448            Log((DEVICE_NAME ": vboxUsbSolarisProcessIOCtl: ABORT_PIPE returned %d\n", rc));
    13401449            break;
    13411450        }
     
    13461455
    13471456            PVBOXUSBREQ_GET_CONFIG pGetCfgReq = (PVBOXUSBREQ_GET_CONFIG)pvBuf;
    1348             rc = vboxUSBSolarisGetConfig(pState, &pGetCfgReq->bConfigValue);
     1457            rc = vboxUsbSolarisGetConfig(pState, &pGetCfgReq->bConfigValue);
    13491458            *pcbDataOut = sizeof(VBOXUSBREQ_GET_CONFIG);
    1350             Log((DEVICE_NAME ":vboxUSBSolarisProcessIOCtl: GET_CONFIG returned %d\n", rc));
     1459            Log((DEVICE_NAME ": vboxUsbSolarisProcessIOCtl: GET_CONFIG returned %d\n", rc));
    13511460            break;
    13521461        }
     
    13611470            *pcbDataOut = sizeof(VBOXUSBREQ_GET_VERSION);
    13621471            rc = VINF_SUCCESS;
    1363             Log((DEVICE_NAME ":vboxUSBSolarisProcessIOCtl: GET_VERSION returned %d\n", rc));
     1472            Log((DEVICE_NAME ": vboxUsbSolarisProcessIOCtl: GET_VERSION returned %d\n", rc));
    13641473            break;
    13651474        }
     
    13671476        default:
    13681477        {
    1369             LogRel((DEVICE_NAME ":solarisUSBProcessIOCtl: Unknown request %#x\n", iFunction));
     1478            LogRel((DEVICE_NAME ": vboxUsbSolarisProcessIOCtl: Unknown request %#x\n", iFunction));
    13701479            rc = VERR_NOT_SUPPORTED;
    13711480            *pcbDataOut = 0;
     
    13801489
    13811490/**
    1382  * Initialize device power management functions.
     1491 * Initializes device power management.
    13831492 *
    13841493 * @param   pState          The USB device instance.
     
    13861495 * @returns VBox status code.
    13871496 */
    1388 LOCAL int vboxUSBSolarisInitPower(vboxusb_state_t *pState)
    1389 {
    1390     LogFunc((DEVICE_NAME ":vboxUSBSolarisInitPower pState=%p\n", pState));
     1497LOCAL int vboxUsbSolarisInitPower(vboxusb_state_t *pState)
     1498{
     1499    LogFunc((DEVICE_NAME ": vboxUsbSolarisInitPower: pState=%p\n", pState));
    13911500
    13921501    int rc = usb_handle_remote_wakeup(pState->pDip, USB_REMOTE_WAKEUP_ENABLE);
    13931502    if (rc == USB_SUCCESS)
    13941503    {
    1395         vboxusb_power_t *pPower = RTMemAlloc(sizeof(vboxusb_power_t));
     1504        vboxusb_power_t *pPower = RTMemAllocZ(sizeof(vboxusb_power_t));
    13961505        if (RT_LIKELY(pPower))
    13971506        {
     
    14131522                if (rc != DDI_SUCCESS)
    14141523                {
    1415                     LogRel((DEVICE_NAME ":vboxUSBSolarisInitPower failed to raise power level usb(%#x,%#x).\n",
     1524                    LogRel((DEVICE_NAME ": vboxUsbSolarisInitPower: Failed to raise power level usb(%#x,%#x)\n",
    14161525                            pState->pDevDesc->dev_descr->idVendor, pState->pDevDesc->dev_descr->idProduct));
    14171526                }
    14181527            }
    14191528            else
    1420                 Log((DEVICE_NAME ":vboxUSBSolarisInitPower failed to create power components.\n"));
     1529                Log((DEVICE_NAME ": vboxUsbSolarisInitPower: Failed to create power components\n"));
    14211530
    14221531            return VINF_SUCCESS;
     
    14271536    else
    14281537    {
    1429         Log((DEVICE_NAME ":vboxUSBSolarisInitPower failed to enable remote wakeup. No PM.\n"));
     1538        Log((DEVICE_NAME ": vboxUsbSolarisInitPower: Failed to enable remote wakeup, No PM!\n"));
    14301539        rc = VINF_SUCCESS;
    14311540    }
     
    14361545
    14371546/**
    1438  * Destroy device power management functions.
     1547 * Destroys device power management.
    14391548 *
    14401549 * @param   pState          The USB device instance.
     
    14431552 * @returns VBox status code.
    14441553 */
    1445 LOCAL void vboxUSBSolarisDestroyPower(vboxusb_state_t *pState)
    1446 {
    1447     LogFunc((DEVICE_NAME ":vboxUSBSolarisDestroyPower pState=%p\n", pState));
     1554LOCAL void vboxUsbSolarisDestroyPower(vboxusb_state_t *pState)
     1555{
     1556    LogFunc((DEVICE_NAME ": vboxUsbSolarisDestroyPower: pState=%p\n", pState));
    14481557
    14491558    if (pState->pPower)
    14501559    {
    14511560        mutex_exit(&pState->Mtx);
    1452         vboxUSBSolarisPowerBusy(pState);
     1561        vboxUsbSolarisPowerBusy(pState);
    14531562        mutex_enter(&pState->Mtx);
    14541563
     
    14601569            rc = pm_raise_power(pState->pDip, 0 /* component */, USB_DEV_OS_FULL_PWR);
    14611570            if (rc != DDI_SUCCESS)
    1462                 Log((DEVICE_NAME ":vboxUSBSolarisDestroyPower raising power failed! rc=%d\n", rc));
     1571                Log((DEVICE_NAME ": vboxUsbSolarisDestroyPower: Raising power failed! rc=%d\n", rc));
    14631572
    14641573            rc = usb_handle_remote_wakeup(pState->pDip, USB_REMOTE_WAKEUP_DISABLE);
    14651574            if (rc != DDI_SUCCESS)
    1466                 Log((DEVICE_NAME ":vboxUSBSolarisDestroyPower failed to disable remote wakeup.\n"));
     1575                Log((DEVICE_NAME ": vboxUsbSolarisDestroyPower: Failed to disable remote wakeup\n"));
    14671576        }
    14681577        else
     
    14711580        rc = pm_lower_power(pState->pDip, 0 /* component */, USB_DEV_OS_PWR_OFF);
    14721581        if (rc != DDI_SUCCESS)
    1473             Log((DEVICE_NAME ":vboxUSBSolarisDestroyPower lowering power failed! rc=%d\n", rc));
    1474 
    1475         vboxUSBSolarisPowerIdle(pState);
     1582            Log((DEVICE_NAME ": vboxUsbSolarisDestroyPower: Lowering power failed! rc=%d\n", rc));
     1583
     1584        vboxUsbSolarisPowerIdle(pState);
    14761585        mutex_enter(&pState->Mtx);
    14771586        RTMemFree(pState->pPower);
     
    14821591
    14831592/**
    1484  * Convert Solaris' USBA URB status to VBox's USB URB status.
     1593 * Converts Solaris' USBA URB status to VBox's USB URB status.
    14851594 *
    14861595 * @param   Status          Solaris USBA USB URB status.
     
    14881597 * @returns VBox USB URB status.
    14891598 */
    1490 LOCAL inline VUSBSTATUS vboxUSBSolarisGetUrbStatus(usb_cr_t Status)
     1599LOCAL VUSBSTATUS vboxUsbSolarisGetUrbStatus(usb_cr_t Status)
    14911600{
    14921601    switch (Status)
     
    15221631
    15231632/**
    1524  * Convert Solaris' USBA error code to VBox's error code.
     1633 * Converts Solaris' USBA error code to VBox's error code.
    15251634 *
    15261635 * @param   UsbRc           Solaris USBA error code.
     
    15281637 * @returns VBox error code.
    15291638 */
    1530 static inline int vboxUSBSolarisToVBoxRC(int UsbRc)
     1639static int vboxUsbSolarisToVBoxRC(int UsbRc)
    15311640{
    15321641    switch (UsbRc)
     
    15571666
    15581667/**
    1559  * Convert Solaris' USBA device state to VBox's error code.
     1668 * Converts Solaris' USBA device state to VBox's error code.
    15601669 *
    15611670 * @param   uDeviceState        The USB device state to convert.
     
    15631672 * @returns VBox error code.
    15641673 */
    1565 static inline int vboxUSBSolarisDeviceState(uint8_t uDeviceState)
     1674static int vboxUsbSolarisDeviceState(uint8_t uDeviceState)
    15661675{
    15671676    switch (uDeviceState)
     
    15771686
    15781687/**
    1579  * Check if the device is a USB device.
     1688 * Checks if the device is a USB device.
    15801689 *
    15811690 * @param   pDip            Pointer to this device info. structure.
     
    15831692 * @returns If this is really a USB device returns true, otherwise false.
    15841693 */
    1585 LOCAL bool vboxUSBSolarisIsUSBDevice(dev_info_t *pDip)
     1694LOCAL bool vboxUsbSolarisIsUSBDevice(dev_info_t *pDip)
    15861695{
    15871696    int rc = DDI_FAILURE;
     
    15971706        while (cCompatible--)
    15981707        {
    1599             Log((DEVICE_NAME ":vboxUSBSolarisIsUSBDevice compatible[%d]=%s\n", cCompatible, ppszCompatible[cCompatible]));
     1708            Log((DEVICE_NAME ": vboxUsbSolarisIsUSBDevice: Compatible[%d]=%s\n", cCompatible, ppszCompatible[cCompatible]));
    16001709            if (!strncmp(ppszCompatible[cCompatible], "usb", 3))
    16011710            {
    1602                 Log((DEVICE_NAME ":vboxUSBSolarisIsUSBDevice verified device as USB. pszCompatible=%s\n",
     1711                Log((DEVICE_NAME ": vboxUsbSolarisIsUSBDevice: Verified device as USB. pszCompatible=%s\n",
    16031712                     ppszCompatible[cCompatible]));
    16041713                ddi_prop_free(ppszCompatible);
     
    16111720    }
    16121721    else
    1613         Log((DEVICE_NAME ":vboxUSBSolarisIsUSBDevice USB property lookup failed. rc=%d\n", rc));
     1722        Log((DEVICE_NAME ": vboxUsbSolarisIsUSBDevice: USB property lookup failed, rc=%d\n", rc));
    16141723
    16151724    /*
     
    16251734            while (cCompatible--)
    16261735            {
    1627                 Log((DEVICE_NAME ":vboxUSBSolarisIsUSBDevice parent compatible[%d]=%s\n", cCompatible,
     1736                Log((DEVICE_NAME ": vboxUsbSolarisIsUSBDevice: Parent compatible[%d]=%s\n", cCompatible,
    16281737                     ppszCompatible[cCompatible]));
    16291738                if (!strncmp(ppszCompatible[cCompatible], "usb", 3))
    16301739                {
    1631                     Log((DEVICE_NAME ":vboxUSBSolarisIsUSBDevice verified device as USB. parent pszCompatible=%s\n",
     1740                    Log((DEVICE_NAME ": vboxUsbSolarisIsUSBDevice: Verified device as USB. parent pszCompatible=%s\n",
    16321741                            ppszCompatible[cCompatible]));
    16331742                    ddi_prop_free(ppszCompatible);
     
    16401749        }
    16411750        else
    1642             Log((DEVICE_NAME ":vboxUSBSolarisIsUSBDevice USB parent property lookup failed. rc=%d\n", rc));
     1751            Log((DEVICE_NAME ": vboxUsbSolarisIsUSBDevice: USB parent property lookup failed. rc=%d\n", rc));
    16431752    }
    16441753    else
    1645         Log((DEVICE_NAME ":vboxUSBSolarisIsUSBDevice failed to obtain parent device for property lookup.\n"));
     1754        Log((DEVICE_NAME ": vboxUsbSolarisIsUSBDevice: Failed to obtain parent device for property lookup\n"));
    16461755
    16471756    return false;
     
    16501759
    16511760/**
    1652  * Submit a URB.
     1761 * Submits a URB.
    16531762 *
    16541763 * @param   pState          The USB device instance.
     
    16581767 * @returns VBox error code.
    16591768 */
    1660 LOCAL int vboxUSBSolarisSendURB(vboxusb_state_t *pState, PVBOXUSBREQ_URB pUrbReq, int Mode)
    1661 {
    1662     uchar_t EndPtIndex = usb_get_ep_index(pUrbReq->bEndpoint);
    1663     vboxusb_ep_t *pEp = &pState->aEps[EndPtIndex];
     1769LOCAL int vboxUsbSolarisSendUrb(vboxusb_state_t *pState, PVBOXUSBREQ_URB pUrbReq, int Mode)
     1770{
     1771    int iEpIndex = VBOXUSB_GET_EP_INDEX(pUrbReq->bEndpoint);
     1772    Assert(iEpIndex >= 0 && iEpIndex < RT_ELEMENTS(pState->aEps));
     1773    vboxusb_ep_t *pEp = &pState->aEps[iEpIndex];
    16641774    AssertPtrReturn(pEp, VERR_INVALID_POINTER);
    1665 
    1666     /* LogFunc((DEVICE_NAME ":vboxUSBSolarisSendUrb pState=%p pUrbReq=%p bEndpoint=%#x[%d] enmDir=%#x enmType=%#x cbData=%d pvData=%p\n",
    1667             pState, pUrbReq, pUrbReq->bEndpoint, EndPtIndex, pUrbReq->enmDir, pUrbReq->enmType, pUrbReq->cbData, pUrbReq->pvData)); */
     1775    Assert(pUrbReq);
     1776
     1777#if 0
     1778    LogFunc((DEVICE_NAME ": vboxUsbSolarisSendUrb: pState=%p pUrbReq=%p bEndpoint=%#x[%d] enmDir=%#x enmType=%#x "
     1779             "cbData=%d pvData=%p\n", pState, pUrbReq, pUrbReq->bEndpoint, iEpIndex, pUrbReq->enmDir,
     1780             pUrbReq->enmType, pUrbReq->cbData, pUrbReq->pvData));
     1781#endif
    16681782
    16691783    if (RT_UNLIKELY(!pUrbReq->pvData))
    16701784    {
    1671         LogRel((DEVICE_NAME ":vboxUSBSolarisSendUrb Invalid request. No data.\n"));
     1785        LogRel((DEVICE_NAME ": vboxUsbSolarisSendUrb: Invalid request - No data\n"));
    16721786        return VERR_INVALID_POINTER;
    16731787    }
     
    16851799        if (RT_UNLIKELY(!pMsg))
    16861800        {
    1687             LogRel((DEVICE_NAME ":vboxUSBSolarisSendUrb: failed to allocate %d bytes\n", pUrbReq->cbData));
     1801            LogRel((DEVICE_NAME ": vboxUsbSolarisSendUrb: Failed to allocate %u bytes\n", pUrbReq->cbData));
    16881802            return VERR_NO_MEMORY;
    16891803        }
     
    16921806        if (RT_UNLIKELY(rc))
    16931807        {
    1694             LogRel((DEVICE_NAME ":vboxUSBSolarisSendUrb: ddi_copyin failed! rc=%d\n", rc));
     1808            LogRel((DEVICE_NAME ": vboxUsbSolarisSendUrb: ddi_copyin failed! rc=%d\n", rc));
    16951809            freemsg(pMsg);
    16961810            return VERR_NO_MEMORY;
     
    17011815
    17021816    mutex_enter(&pState->Mtx);
    1703     rc = vboxUSBSolarisDeviceState(pState->DevState);
    1704 
    1705     if (pState->fClosed)    /* Required for Isoc. IN Xfers which don't Xfer through the pipe after polling starts */
     1817    rc = vboxUsbSolarisDeviceState(pState->DevState);
     1818    if (!pState->fDefaultPipeOpen)    /* Required for Isoc. IN Xfers which don't Xfer through the pipe after polling starts */
    17061819        rc = VERR_VUSB_DEVICE_NOT_ATTACHED;
    1707 
    17081820    if (RT_SUCCESS(rc))
    17091821    {
     
    17111823         * Open the pipe if needed.
    17121824         */
    1713         rc = vboxUSBSolarisOpenPipe(pState, pEp);
     1825        rc = vboxUsbSolarisOpenPipe(pState, pEp);
    17141826        if (RT_UNLIKELY(RT_FAILURE(rc)))
    17151827        {
    17161828            mutex_exit(&pState->Mtx);
    17171829            freemsg(pMsg);
    1718             LogRel((DEVICE_NAME ":vboxUSBSolarisSendUrb OpenPipe failed. pState=%p pUrbReq=%p bEndpoint=%#x enmDir=%#x "
     1830            LogRel((DEVICE_NAME ": vboxUsbSolarisSendUrb: OpenPipe failed! pState=%p pUrbReq=%p bEndpoint=%#x enmDir=%#x "
    17191831                    "enmType=%#x cbData=%d pvData=%p rc=%d\n", pState, pUrbReq, pUrbReq->bEndpoint, pUrbReq->enmDir,
    17201832                    pUrbReq->enmType, pUrbReq->cbData, pUrbReq->pvData, rc));
     
    17261838        vboxusb_urb_t *pUrb = NULL;
    17271839        if (   pUrbReq->enmType == VUSBXFERTYPE_ISOC
    1728             && pUrbReq->enmDir == VUSBDIRECTION_IN)
    1729             pUrb = vboxUSBSolarisGetIsocInURB(pState, pUrbReq);
     1840            && pUrbReq->enmDir  == VUSBDIRECTION_IN)
     1841            pUrb = vboxUsbSolarisGetIsocInUrb(pState, pUrbReq);
    17301842        else
    1731             pUrb = vboxUSBSolarisQueueURB(pState, pUrbReq, pMsg);
     1843            pUrb = vboxUsbSolarisQueueUrb(pState, pUrbReq, pMsg);
    17321844
    17331845        if (RT_LIKELY(pUrb))
     
    17371849                case VUSBXFERTYPE_MSG:
    17381850                {
    1739                     rc = vboxUSBSolarisCtrlXfer(pState, pEp, pUrb);
     1851                    rc = vboxUsbSolarisCtrlXfer(pState, pEp, pUrb);
    17401852                    break;
    17411853                }
     
    17431855                case VUSBXFERTYPE_BULK:
    17441856                {
    1745                     rc = vboxUSBSolarisBulkXfer(pState, pEp, pUrb);
     1857                    rc = vboxUsbSolarisBulkXfer(pState, pEp, pUrb);
    17461858                    break;
    17471859                }
     
    17491861                case VUSBXFERTYPE_INTR:
    17501862                {
    1751                     rc = vboxUSBSolarisIntrXfer(pState, pEp, pUrb);
     1863                    rc = vboxUsbSolarisIntrXfer(pState, pEp, pUrb);
    17521864                    break;
    17531865                }
     
    17551867                case VUSBXFERTYPE_ISOC:
    17561868                {
    1757                     rc = vboxUSBSolarisIsocXfer(pState, pEp, pUrb);
     1869                    rc = vboxUsbSolarisIsocXfer(pState, pEp, pUrb);
    17581870                    break;
    17591871                }
     
    17611873                default:
    17621874                {
     1875                    LogRelMax(5, (DEVICE_NAME ": vboxUsbSolarisSendUrb: URB type unsupported %d\n", pUrb->enmType));
    17631876                    rc = VERR_NOT_SUPPORTED;
    17641877                    break;
     
    17681881            if (RT_FAILURE(rc))
    17691882            {
    1770                 /** @todo We share the state mutex for protecting concurrent accesses to both
    1771                  *        the inflight URB list as well as pUrb->pMsg (data). Probably make this
    1772                  *        more fine grained later by having a different mutex for the URB if
    1773                  *        it's really worth the trouble. */
    17741883                mutex_enter(&pState->Mtx);
    1775                 if (pUrb->pMsg)
    1776                 {
    1777                     freemsg(pUrb->pMsg);
    1778                     pUrb->pMsg = NULL;
    1779                 }
     1884                freemsg(pUrb->pMsg);
     1885                pUrb->pMsg = NULL;
     1886                pMsg = NULL;
    17801887
    17811888                if (   pUrb->enmType == VUSBXFERTYPE_ISOC
     
    17871894                else
    17881895                {
    1789                     pUrb->pMsg = NULL;
     1896                    /*
     1897                     * Xfer failed, move URB back to the free list.
     1898                     */
     1899                    list_remove(&pState->hInflightUrbs, pUrb);
     1900                    Assert(pState->cInflightUrbs > 0);
     1901                    --pState->cInflightUrbs;
     1902
    17901903                    pUrb->enmState = VBOXUSB_URB_STATE_FREE;
     1904                    Assert(!pUrb->pMsg);
     1905                    list_insert_head(&pState->hFreeUrbs, pUrb);
     1906                    ++pState->cFreeUrbs;
    17911907                }
    17921908                mutex_exit(&pState->Mtx);
     
    17951911        else
    17961912        {
    1797             LogRel((DEVICE_NAME ":vboxUSBSolarisSendUrb failed to queue URB.\n"));
     1913            LogRel((DEVICE_NAME ": vboxUsbSolarisSendUrb: Failed to queue URB\n"));
    17981914            rc = VERR_NO_MEMORY;
    1799         }
    1800 
    1801         if (   RT_FAILURE(rc)
    1802             && pUrb)
    1803         {
    1804             if (   pUrb->enmType != VUSBXFERTYPE_ISOC
    1805                 || pUrb->enmDir  != VUSBDIRECTION_IN)
    1806             {
    1807                 mutex_enter(&pState->Mtx);
    1808                 pState->cInflightUrbs--;
    1809                 mutex_exit(&pState->Mtx);
    1810             }
     1915            freemsg(pMsg);
    18111916        }
    18121917    }
     
    18221927
    18231928/**
    1824  * Reap a completed/error'd URB.
     1929 * Reaps a completed URB.
    18251930 *
    18261931 * @param   pState          The USB device instance.
     
    18301935 * @returns VBox error code.
    18311936 */
    1832 LOCAL int vboxUSBSolarisReapURB(vboxusb_state_t *pState, PVBOXUSBREQ_URB pUrbReq, int Mode)
    1833 {
    1834 //    LogFunc((DEVICE_NAME ":vboxUSBSolarisReapUrb pState=%p pUrbReq=%p\n", pState, pUrbReq));
     1937LOCAL int vboxUsbSolarisReapUrb(vboxusb_state_t *pState, PVBOXUSBREQ_URB pUrbReq, int Mode)
     1938{
     1939    /* LogFunc((DEVICE_NAME ": vboxUsbSolarisReapUrb: pState=%p pUrbReq=%p\n", pState, pUrbReq)); */
    18351940
    18361941    AssertPtrReturn(pUrbReq, VERR_INVALID_POINTER);
     
    18381943    int rc = VINF_SUCCESS;
    18391944    mutex_enter(&pState->Mtx);
    1840     rc = vboxUSBSolarisDeviceState(pState->DevState);
    1841     if (pState->fClosed)
     1945    rc = vboxUsbSolarisDeviceState(pState->DevState);
     1946    if (!pState->fDefaultPipeOpen)
    18421947        rc = VERR_VUSB_DEVICE_NOT_ATTACHED;
    18431948    if (RT_SUCCESS(rc))
    18441949    {
    18451950        vboxusb_urb_t *pUrb = list_remove_head(&pState->hLandedUrbs);
     1951        if (pUrb)
     1952        {
     1953            Assert(pState->cLandedUrbs > 0);
     1954            --pState->cLandedUrbs;
     1955        }
    18461956
    18471957        /*
     
    18601970            pUrbReq->enmDir    = pUrb->enmDir;
    18611971            pUrbReq->enmStatus = pUrb->enmStatus;
     1972            pUrbReq->pvData    = (void *)pUrb->pvDataR3;
     1973            pUrbReq->cbData    = pUrb->cbDataR3;
    18621974
    18631975            if (RT_LIKELY(pUrb->pMsg))
    18641976            {
    18651977                /*
    1866                  * Chain copy the message back into the user buffer.
     1978                 * Copy the message back into the user buffer.
    18671979                 */
    18681980                if (RT_LIKELY(pUrb->pvDataR3 != NIL_RTR3PTR))
    18691981                {
    1870                     size_t cbData = RT_MIN(msgdsize(pUrb->pMsg), pUrb->cbDataR3);
     1982                    Assert(!pUrb->pMsg->b_cont);      /* We really should have a single message block always. */
     1983                    size_t cbData = RT_MIN(MBLKL(pUrb->pMsg), pUrb->cbDataR3);
    18711984                    pUrbReq->cbData = cbData;
    1872                     pUrbReq->pvData = (void *)pUrb->pvDataR3;
    1873 
    1874                     /*
    1875                      * Paranoia: we should have a single message block almost always.
    1876                      */
    1877                     if (RT_LIKELY(   !pUrb->pMsg->b_cont
    1878                                   && cbData))
     1985
     1986                    if (RT_LIKELY(cbData))
    18791987                    {
    18801988                        rc = ddi_copyout(pUrb->pMsg->b_rptr, (void *)pUrbReq->pvData, cbData, Mode);
    18811989                        if (RT_UNLIKELY(rc))
    18821990                        {
    1883                             LogRel((DEVICE_NAME ":vboxUSBSolarisReapUrb ddi_copyout failed! rc=%d\n", rc));
     1991                            LogRel((DEVICE_NAME ": vboxUsbSolarisReapUrb: ddi_copyout failed! rc=%d\n", rc));
    18841992                            pUrbReq->enmStatus = VUSBSTATUS_INVALID;
    18851993                        }
    18861994                    }
    1887                     else
    1888                     {
    1889                         RTR3PTR pvDataR3 = pUrb->pvDataR3;
    1890                         mblk_t *pMsg = pUrb->pMsg;
    1891                         while (pMsg)
    1892                         {
    1893                             size_t cbMsg = MBLKL(pMsg);
    1894                             if (cbMsg > 0)
    1895                             {
    1896                                 rc = ddi_copyout(pMsg->b_rptr, (void *)pvDataR3, cbMsg, Mode);
    1897                                 if (RT_UNLIKELY(rc != 0))
    1898                                 {
    1899                                     LogRel((DEVICE_NAME ":vboxUSBSolarisReapUrb ddi_copyout (2) failed! rc=%d\n", rc));
    1900                                     pUrbReq->enmStatus = VUSBSTATUS_INVALID;
    1901                                     break;
    1902                                 }
    1903                             }
    1904 
    1905                             pMsg = pMsg->b_cont;
    1906                             pvDataR3 += cbMsg;
    1907                             if ((pvDataR3 - pUrb->pvDataR3) >= cbData)
    1908                                 break;
    1909                         }
    1910                     }
    1911 
    1912                     Log((DEVICE_NAME ":vboxUSBSolarisReapUrb pvUrbR3=%p pvDataR3=%p cbData=%d\n", pUrbReq->pvUrbR3,
     1995
     1996                    Log((DEVICE_NAME ": vboxUsbSolarisReapUrb: pvUrbR3=%p pvDataR3=%p cbData=%d\n", pUrbReq->pvUrbR3,
    19131997                         pUrbReq->pvData, pUrbReq->cbData));
    19141998                }
     
    19172001                    pUrbReq->cbData = 0;
    19182002                    rc = VERR_INVALID_POINTER;
    1919                     Log((DEVICE_NAME ":vboxUSBSolarisReapUrb missing pvDataR3!!\n"));
     2003                    LogRel((DEVICE_NAME ": vboxUsbSolarisReapUrb: Missing pvDataR3!!\n"));
    19202004                }
    19212005
    19222006                /*
    1923                  * Free buffer allocated in VBOXUSB_IOCTL_SEND_URB.
     2007                 * Free buffer allocated in vboxUsbSolarisSendUrb or vboxUsbSolaris[Ctrl|Bulk|Intr]Xfer().
    19242008                 */
    19252009                freemsg(pUrb->pMsg);
     
    19282012            else
    19292013            {
    1930                 if (pUrb->enmType == VUSBXFERTYPE_ISOC)
     2014                if (   pUrb->enmType == VUSBXFERTYPE_ISOC
     2015                    && pUrb->enmDir == VUSBDIRECTION_IN)
    19312016                {
    1932                     if (pUrb->enmDir == VUSBDIRECTION_OUT)
    1933                         pUrbReq->cbData = pUrb->cbDataR3;
    1934                     else
    1935                     {
    1936                         pUrbReq->enmStatus = VUSBSTATUS_INVALID;
    1937                         pUrbReq->cbData = 0;
    1938                     }
    1939                 }
    1940                 else
    1941                 {
    1942                     Log((DEVICE_NAME ":vboxUSBSolarisReapUrb missing message.\n"));
     2017                    pUrbReq->enmStatus = VUSBSTATUS_INVALID;
    19432018                    pUrbReq->cbData = 0;
    19442019                }
     
    19702045            {
    19712046                /*
    1972                  * Add URB back to the head of the free/inflight list.
     2047                 * Add URB back to the free list.
    19732048                 */
     2049                Assert(!pUrb->pMsg);
    19742050                pUrb->cbDataR3 = 0;
    19752051                pUrb->pvDataR3 = NIL_RTR3PTR;
    19762052                pUrb->enmState = VBOXUSB_URB_STATE_FREE;
    19772053                mutex_enter(&pState->Mtx);
    1978                 list_insert_head(&pState->hUrbs, pUrb);
     2054                list_insert_head(&pState->hFreeUrbs, pUrb);
     2055                ++pState->cFreeUrbs;
    19792056                mutex_exit(&pState->Mtx);
    19802057            }
    19812058        }
    19822059        else
     2060        {
    19832061            pUrbReq->pvUrbR3 = NULL;
     2062            pUrbReq->cbData  = 0;
     2063            pUrbReq->pvData  = NULL;
     2064            pUrbReq->enmStatus = VUSBSTATUS_INVALID;
     2065        }
    19842066    }
    19852067    else
     
    19912073
    19922074/**
    1993  * Clear a pipe (CLEAR_FEATURE).
     2075 * Clears a pipe (CLEAR_FEATURE).
    19942076 *
    19952077 * @param   pState          The USB device instance.
     
    19982080 * @returns VBox error code.
    19992081 */
    2000 LOCAL int vboxUSBSolarisClearEndPoint(vboxusb_state_t *pState, uint8_t bEndpoint)
    2001 {
    2002     LogFunc((DEVICE_NAME ":vboxUSBSolarisClearEndPoint pState=%p bEndpoint=%#x\n", pState, bEndpoint));
    2003 
    2004     /*
    2005      * Serialize access: single threaded per Endpoint, one request at a time.
    2006      */
     2082LOCAL int vboxUsbSolarisClearEndPoint(vboxusb_state_t *pState, uint8_t bEndpoint)
     2083{
     2084    LogFunc((DEVICE_NAME ": vboxUsbSolarisClearEndPoint: pState=%p bEndpoint=%#x\n", pState, bEndpoint));
     2085
    20072086    mutex_enter(&pState->Mtx);
    2008     int rc = vboxUSBSolarisDeviceState(pState->DevState);
     2087    int rc = vboxUsbSolarisDeviceState(pState->DevState);
    20092088    if (RT_SUCCESS(rc))
    20102089    {
    2011         uchar_t EndPtIndex = usb_get_ep_index(bEndpoint);
    2012         vboxusb_ep_t *pEp = &pState->aEps[EndPtIndex];
     2090        int iEpIndex = VBOXUSB_GET_EP_INDEX(bEndpoint);
     2091        Assert(iEpIndex >= 0 && iEpIndex < RT_ELEMENTS(pState->aEps));
     2092        vboxusb_ep_t *pEp = &pState->aEps[iEpIndex];
    20132093        if (RT_LIKELY(pEp))
    20142094        {
     
    20192099            {
    20202100                mutex_exit(&pState->Mtx);
    2021 #if 0
    2022                 /*
    2023                  * Asynchronous clear pipe.
    2024                  */
    2025                 rc = usb_clr_feature(pState->pDip, USB_DEV_REQ_RCPT_EP, USB_EP_HALT, bEndpoint,
    2026                                         USB_FLAGS_NOSLEEP, /* Asynchronous */
    2027                                         NULL,              /* Completion callback */
    2028                                         NULL);             /* Exception callback */
    2029 #endif
     2101
    20302102                /*
    20312103                 * Synchronous reset pipe.
     
    20382110                mutex_enter(&pState->Mtx);
    20392111
    2040                 Log((DEVICE_NAME ":vboxUSBSolarisClearEndPoint bEndpoint=%#x[%d] returns %d\n", bEndpoint, EndPtIndex, rc));
     2112                Log((DEVICE_NAME ": vboxUsbSolarisClearEndPoint: bEndpoint=%#x[%d] returns %d\n", bEndpoint, iEpIndex, rc));
    20412113
    20422114                rc = VINF_SUCCESS;
     
    20442116            else
    20452117            {
    2046                 Log((DEVICE_NAME ":vboxUSBSolarisClearEndPoint not opened to be cleared. Faking success. bEndpoint=%#x.\n",
     2118                Log((DEVICE_NAME ": vboxUsbSolarisClearEndPoint: Not opened to be cleared. Faking success. bEndpoint=%#x\n",
    20472119                     bEndpoint));
    20482120                rc = VINF_SUCCESS;
     
    20512123        else
    20522124        {
    2053             LogRel((DEVICE_NAME ":vboxUSBSolarisClearEndPoint Endpoint missing!! bEndpoint=%#x EndPtIndex=%d.\n", bEndpoint,
    2054                     EndPtIndex));
     2125            LogRel((DEVICE_NAME ": vboxUsbSolarisClearEndPoint: Endpoint missing! bEndpoint=%#x[%d]\n", bEndpoint, iEpIndex));
    20552126            rc = VERR_GENERAL_FAILURE;
    20562127        }
    20572128    }
    20582129    else
    2059         Log((DEVICE_NAME ":vboxUSBSolarisClearEndPoint device state=%d not online.\n", pState->DevState));
     2130        Log((DEVICE_NAME ": vboxUsbSolarisClearEndPoint: Device not online, state=%d\n", pState->DevState));
    20602131
    20612132    mutex_exit(&pState->Mtx);
     
    20652136
    20662137/**
    2067  * Set configuration (SET_CONFIGURATION)
     2138 * Sets configuration (SET_CONFIGURATION)
    20682139 *
    20692140 * @param   pState          The USB device instance.
    2070  * @param   bCfgValue       The Configuration value.
     2141 * @param   bConfig         The Configuration.
    20712142 *
    20722143 * @returns VBox error code.
    20732144 */
    2074 LOCAL int vboxUSBSolarisSetConfig(vboxusb_state_t *pState, uint8_t bCfgValue)
    2075 {
    2076     LogFunc((DEVICE_NAME ":vboxUSBSolarisSetConfig pState=%p bCfgValue=%#x\n", pState, bCfgValue));
    2077 
    2078     /*
    2079      * Serialize access: single threaded per Endpoint, one request at a time.
    2080      */
     2145LOCAL int vboxUsbSolarisSetConfig(vboxusb_state_t *pState, uint8_t bConfig)
     2146{
     2147    LogFunc((DEVICE_NAME ": vboxUsbSolarisSetConfig: pState=%p bConfig=%u\n", pState, bConfig));
     2148
    20812149    mutex_enter(&pState->Mtx);
    2082     int rc = vboxUSBSolarisDeviceState(pState->DevState);
     2150    int rc = vboxUsbSolarisDeviceState(pState->DevState);
    20832151    if (RT_SUCCESS(rc))
    20842152    {
    2085         vboxUSBSolarisCloseAllPipes(pState, false /* ControlPipe */);
    2086         int iCfgIndex = vboxUSBSolarisGetConfigIndex(pState, bCfgValue);
    2087 
    2088         if (iCfgIndex >= 0)
     2153        vboxUsbSolarisCloseAllPipes(pState, false /* ControlPipe */);
     2154        int iCfgIndex = vboxUsbSolarisGetConfigIndex(pState, bConfig);
     2155
     2156        if (   iCfgIndex >= 0
     2157            && iCfgIndex < pState->pDevDesc->dev_n_cfg)
    20892158        {
    20902159            /*
     
    20972166            if (rc == USB_SUCCESS)
    20982167            {
    2099                 pState->fRestoreCfg = true;
    2100                 vboxUSBSolarisInitEndPointsForConfig(pState, iCfgIndex);
     2168                int rc2 = vboxUsbSolarisInitEpsForCfg(pState);
     2169                AssertRC(rc2); NOREF(rc2);
    21012170                rc = VINF_SUCCESS;
    21022171            }
    21032172            else
    21042173            {
    2105                 LogRel((DEVICE_NAME ":vboxUSBSolarisSetConfig usb_set_cfg failed for iCfgIndex=%#x bCfgValue=%#x rc=%d\n",
    2106                             iCfgIndex, bCfgValue, rc));
    2107                 rc = vboxUSBSolarisToVBoxRC(rc);
     2174                LogRel((DEVICE_NAME ": vboxUsbSolarisSetConfig: usb_set_cfg failed for iCfgIndex=%#x bConfig=%u rc=%d\n",
     2175                            iCfgIndex, bConfig, rc));
     2176                rc = vboxUsbSolarisToVBoxRC(rc);
    21082177            }
    21092178        }
    21102179        else
    21112180        {
    2112             LogRel((DEVICE_NAME ":vboxUSBSolarisSetConfig invalid iCfgIndex=%d bCfgValue=%#x\n", iCfgIndex, bCfgValue));
    2113             rc = VERR_INVALID_HANDLE;
     2181            LogRel((DEVICE_NAME ": vboxUsbSolarisSetConfig: Invalid iCfgIndex=%d bConfig=%u\n", iCfgIndex, bConfig));
     2182            rc = VERR_OUT_OF_RANGE;
    21142183        }
    21152184    }
     
    21222191
    21232192/**
    2124  * Get configuration (GET_CONFIGURATION)
     2193 * Gets configuration (GET_CONFIGURATION)
    21252194 *
    21262195 * @param   pState          The USB device instance.
    2127  * @param   pCfgValue       Where to store the configuration value.
     2196 * @param   pbConfig        Where to store the Configuration.
    21282197 *
    21292198 * @returns VBox error code.
    21302199 */
    2131 LOCAL int vboxUSBSolarisGetConfig(vboxusb_state_t *pState, uint8_t *pCfgValue)
    2132 {
    2133     LogFunc((DEVICE_NAME ":vboxUSBSolarisGetConfig pState=%p pCfgValue=%p\n", pState, pCfgValue));
    2134     AssertPtrReturn(pCfgValue, VERR_INVALID_POINTER);
    2135 
    2136     /*
    2137      * Solaris keeps the currently active configuration for the first time. Thus for the first request
    2138      * we simply pass the cached configuration back to the user.
    2139      */
    2140     if (!pState->fGetCfgReqDone)
    2141     {
    2142         pState->fGetCfgReqDone = true;
    2143         AssertPtrReturn(pState->pDevDesc, VERR_GENERAL_FAILURE);
    2144         usb_cfg_data_t *pCurrCfg = pState->pDevDesc->dev_curr_cfg;
    2145         if (pCurrCfg)
    2146         {
    2147             *pCfgValue = pCurrCfg->cfg_descr.bConfigurationValue;
    2148             Log((DEVICE_NAME ":vboxUSBSolarisGetConfig cached config returned. CfgValue=%d\n", *pCfgValue));
    2149             return VINF_SUCCESS;
    2150         }
    2151     }
     2200LOCAL int vboxUsbSolarisGetConfig(vboxusb_state_t *pState, uint8_t *pbConfig)
     2201{
     2202    LogFunc((DEVICE_NAME ": vboxUsbSolarisGetConfig: pState=%p pbConfig=%p\n", pState, pbConfig));
     2203    AssertPtrReturn(pbConfig, VERR_INVALID_POINTER);
    21522204
    21532205    /*
    21542206     * Get Config synchronously.
    21552207     */
    2156     uint_t bCfgValue;
    2157     int rc = usb_get_cfg(pState->pDip, &bCfgValue, USB_FLAGS_SLEEP);
     2208    uint_t bConfig;
     2209    int rc = usb_get_cfg(pState->pDip, &bConfig, USB_FLAGS_SLEEP);
    21582210    if (RT_LIKELY(rc == USB_SUCCESS))
    21592211    {
    2160         *pCfgValue = bCfgValue;
     2212        *pbConfig = bConfig;
    21612213        rc = VINF_SUCCESS;
    21622214    }
    21632215    else
    21642216    {
    2165         LogRel((DEVICE_NAME ":vboxUSBSolarisGetConfig failed. rc=%d\n", rc));
    2166         rc = vboxUSBSolarisToVBoxRC(rc);
    2167     }
    2168 
    2169     Log((DEVICE_NAME ":vboxUSBSolarisGetConfig returns %d CfgValue=%d\n", rc, *pCfgValue));
     2217        LogRel((DEVICE_NAME ": vboxUsbSolarisGetConfig: Failed, rc=%d\n", rc));
     2218        rc = vboxUsbSolarisToVBoxRC(rc);
     2219    }
     2220
     2221    Log((DEVICE_NAME ": vboxUsbSolarisGetConfig: Returns %d bConfig=%u\n", rc, *pbConfig));
    21702222    return rc;
    21712223}
     
    21732225
    21742226/**
    2175  * Set interface (SET_INTERFACE)
     2227 * Sets interface (SET_INTERFACE) and alternate.
    21762228 *
    21772229 * @param   pState          The USB device instance.
    2178  * @param   uInterface      The Interface number.
    2179  * @param   uAlt            The Alternate setting number.
     2230 * @param   bIf             The Interface.
     2231 * @param   bAlt            The Alternate setting.
    21802232 *
    21812233 * @returns VBox error code.
    21822234 */
    2183 LOCAL int vboxUSBSolarisSetInterface(vboxusb_state_t *pState, uint8_t uInterface, uint8_t uAlt)
    2184 {
    2185     LogFunc((DEVICE_NAME ":vboxUSBSolarisSetInterface pState=%p uInterface=%#x uAlt=%#x\n", pState, uInterface, uAlt));
    2186 
    2187     /*
    2188      * Serialize access: single threaded per Endpoint, one request at a time.
    2189      */
     2235LOCAL int vboxUsbSolarisSetInterface(vboxusb_state_t *pState, uint8_t bIf, uint8_t bAlt)
     2236{
     2237    LogFunc((DEVICE_NAME ": vboxUsbSolarisSetInterface: pState=%p bIf=%#x bAlt=%#x\n", pState, bIf, bAlt));
     2238
    21902239    mutex_enter(&pState->Mtx);
    2191     int rc = vboxUSBSolarisDeviceState(pState->DevState);
     2240    int rc = vboxUsbSolarisDeviceState(pState->DevState);
    21922241    if (RT_SUCCESS(rc))
    21932242    {
    2194         vboxUSBSolarisCloseAllPipes(pState, false /* ControlPipe */);
    2195 
    21962243        /*
    21972244         * Set Interface & Alt setting synchronously.
    21982245         */
    21992246        mutex_exit(&pState->Mtx);
    2200         rc = usb_set_alt_if(pState->pDip, uInterface, uAlt, USB_FLAGS_SLEEP, NULL /* callback */, NULL /* callback data */);
     2247        rc = usb_set_alt_if(pState->pDip, bIf, bAlt, USB_FLAGS_SLEEP, NULL /* callback */, NULL /* callback data */);
    22012248        mutex_enter(&pState->Mtx);
    22022249
    22032250        if (rc == USB_SUCCESS)
    22042251        {
    2205             vboxUSBSolarisInitEndPointsForInterfaceAlt(pState, uInterface, uAlt);
     2252            Log((DEVICE_NAME ": vboxUsbSolarisSetInterface: Success, bIf=%#x bAlt=%#x\n", bIf, bAlt, rc));
     2253            int rc2 = vboxUsbSolarisInitEpsForIfAlt(pState, bIf, bAlt);
     2254            AssertRC(rc2); NOREF(rc2);
    22062255            rc = VINF_SUCCESS;
    22072256        }
    22082257        else
    22092258        {
    2210             LogRel((DEVICE_NAME ":vboxUSBSolarisSetInterface usb_set_alt_if failed for uInterface=%#x bAlt=%#x rc=%d\n",
    2211                         uInterface, uAlt, rc));
    2212             rc = vboxUSBSolarisToVBoxRC(rc);
     2259            LogRel((DEVICE_NAME ": vboxUsbSolarisSetInterface: usb_set_alt_if failed for bIf=%#x bAlt=%#x rc=%d\n", bIf, bAlt, rc));
     2260            rc = vboxUsbSolarisToVBoxRC(rc);
    22132261        }
    22142262    }
     
    22212269
    22222270/**
    2223  * Close the USB device and reset it if required.
     2271 * Closes the USB device and optionally resets it.
    22242272 *
    22252273 * @param   pState          The USB device instance.
     
    22282276 * @returns VBox error code.
    22292277 */
    2230 LOCAL int vboxUSBSolarisCloseDevice(vboxusb_state_t *pState, VBOXUSB_RESET_LEVEL enmReset)
    2231 {
    2232     Log((DEVICE_NAME ":vboxUSBSolarisCloseDevice pState=%p enmReset=%d\n", pState, enmReset));
    2233 
    2234     /*
    2235      * Serialize access: single threaded per Endpoint, one request at a time.
    2236      */
     2278LOCAL int vboxUsbSolarisCloseDevice(vboxusb_state_t *pState, VBOXUSB_RESET_LEVEL enmReset)
     2279{
     2280    LogFunc((DEVICE_NAME ": vboxUsbSolarisCloseDevice: pState=%p enmReset=%d\n", pState, enmReset));
     2281
    22372282    mutex_enter(&pState->Mtx);
    2238     int rc = vboxUSBSolarisDeviceState(pState->DevState);
     2283    int rc = vboxUsbSolarisDeviceState(pState->DevState);
    22392284
    22402285    if (enmReset == VBOXUSB_RESET_LEVEL_CLOSE)
    2241     {
    2242         vboxUSBSolarisCloseAllPipes(pState, true /* ControlPipe */);
    2243         pState->fClosed = true;
    2244     }
     2286        vboxUsbSolarisCloseAllPipes(pState, true /* ControlPipe */);
    22452287    else
    2246         vboxUSBSolarisCloseAllPipes(pState, false /* ControlPipe */);
    2247 
     2288        vboxUsbSolarisCloseAllPipes(pState, false /* ControlPipe */);
    22482289
    22492290    mutex_exit(&pState->Mtx);
     
    22662307        }
    22672308
    2268         rc = vboxUSBSolarisToVBoxRC(rc);
    2269     }
    2270 
    2271     Log((DEVICE_NAME ":vboxUSBSolarisCloseDevice returns %d\n", rc));
     2309        rc = vboxUsbSolarisToVBoxRC(rc);
     2310    }
     2311
     2312    Log((DEVICE_NAME ": vboxUsbSolarisCloseDevice: Returns %d\n", rc));
    22722313    return rc;
    22732314}
     
    22752316
    22762317/**
    2277  * Abort pending requests and reset the pipe.
     2318 * Aborts pending requests and reset the pipe.
    22782319 *
    22792320 * @param   pState          The USB device instance.
     
    22822323 * @returns VBox error code.
    22832324 */
    2284 LOCAL int vboxUSBSolarisAbortPipe(vboxusb_state_t *pState, uint8_t bEndpoint)
    2285 {
    2286     LogFunc((DEVICE_NAME ":vboxUSBSolarisAbortPipe pState=%p bEndpoint=%#x\n", pState, bEndpoint));
    2287 
    2288     /*
    2289      * Serialize access: single threaded per Endpoint, one request at a time.
    2290      */
     2325LOCAL int vboxUsbSolarisAbortPipe(vboxusb_state_t *pState, uint8_t bEndpoint)
     2326{
     2327    LogFunc((DEVICE_NAME ": vboxUsbSolarisAbortPipe: pState=%p bEndpoint=%#x\n", pState, bEndpoint));
     2328
    22912329    mutex_enter(&pState->Mtx);
    2292     int rc = vboxUSBSolarisDeviceState(pState->DevState);
     2330    int rc = vboxUsbSolarisDeviceState(pState->DevState);
    22932331    if (RT_SUCCESS(rc))
    22942332    {
    2295         uchar_t EndPtIndex = usb_get_ep_index(bEndpoint);
    2296         vboxusb_ep_t *pEp = &pState->aEps[EndPtIndex];
     2333        int iEpIndex = VBOXUSB_GET_EP_INDEX(bEndpoint);
     2334        Assert(iEpIndex >= 0 && iEpIndex < RT_ELEMENTS(pState->aEps));
     2335        vboxusb_ep_t *pEp = &pState->aEps[iEpIndex];
    22972336        if (RT_LIKELY(pEp))
    22982337        {
     
    23002339            {
    23012340                /*
    2302                  * Default Endpoint; aborting requests not supported, fake success.
     2341                 * Aborting requests not supported for the default control pipe.
    23032342                 */
    23042343                if ((pEp->EpDesc.bEndpointAddress & USB_EP_NUM_MASK) == 0)
    23052344                {
    23062345                    mutex_exit(&pState->Mtx);
    2307                     LogRel((DEVICE_NAME ":vboxUSBSolarisAbortPipe Cannot reset control pipe.\n"));
     2346                    LogRel((DEVICE_NAME ": vboxUsbSolarisAbortPipe: Cannot reset default control pipe\n"));
    23082347                    return VERR_NOT_SUPPORTED;
    23092348                }
    23102349
    2311                 /*
    2312                  * Serialize access: single threaded per Endpoint, one request at a time.
    2313                  */
    23142350                mutex_exit(&pState->Mtx);
    23152351                usb_pipe_reset(pState->pDip, pEp->pPipe,
    2316                                 USB_FLAGS_SLEEP, /* Synchronous */
    2317                                 NULL,            /* Completion callback */
    2318                                 NULL);           /* Callback data */
     2352                               USB_FLAGS_SLEEP, /* Synchronous */
     2353                               NULL,             /* Completion callback */
     2354                               NULL);            /* Callback's parameter */
    23192355
    23202356                /*
    23212357                 * Allow pending async requests to complete.
    23222358                 */
     2359                /** @todo this is most likely not required. */
    23232360                rc = usb_pipe_drain_reqs(pState->pDip, pEp->pPipe,
    23242361                                USB_FLAGS_SLEEP, /* Synchronous */
    23252362                                5,               /* Timeout (seconds) */
    23262363                                NULL,            /* Completion callback */
    2327                                 NULL);           /* Callback data*/
     2364                                NULL);           /* Callback's parameter */
    23282365
    23292366                mutex_enter(&pState->Mtx);
    23302367
    2331                 Log((DEVICE_NAME ":usb_pipe_drain_reqs returns %d\n", rc));
    2332                 rc = vboxUSBSolarisToVBoxRC(rc);
     2368                Log((DEVICE_NAME ": vboxUsbSolarisAbortPipe: usb_pipe_drain_reqs returns %d\n", rc));
     2369                rc = vboxUsbSolarisToVBoxRC(rc);
    23332370            }
    23342371            else
    23352372            {
    2336                 LogRel((DEVICE_NAME ":vboxUSBSolarisAbortPipe pipe not open. bEndpoint=%#x\n", bEndpoint));
     2373                LogRel((DEVICE_NAME ": vboxUsbSolarisAbortPipe: pipe not open. bEndpoint=%#x\n", bEndpoint));
    23372374                rc = VERR_PIPE_IO_ERROR;
    23382375            }
     
    23402377        else
    23412378        {
    2342             LogRel((DEVICE_NAME ":vboxUSBSolarisAbortPipe invalid pipe index %d bEndpoint=%#x\n", EndPtIndex, bEndpoint));
     2379            LogRel((DEVICE_NAME ": vboxUsbSolarisAbortPipe: Invalid pipe bEndpoint=%#x[%d]\n", bEndpoint, iEpIndex));
    23432380            rc = VERR_INVALID_HANDLE;
    23442381        }
     
    23472384    mutex_exit(&pState->Mtx);
    23482385
    2349     LogFunc((DEVICE_NAME ":vboxUSBSolarisAbortPipe returns %d\n", rc));
     2386    LogFunc((DEVICE_NAME ": vboxUsbSolarisAbortPipe: Returns %d\n", rc));
    23502387    return rc;
    23512388}
     
    23532390
    23542391/**
    2355  * Initialize an endpoint.
     2392 * Initializes an Endpoint.
    23562393 *
    23572394 * @param   pState          The USB device instance.
    2358  * @param   pEpData         The Endpoint data.
    2359  * @param   uCfgValue       The Configuration value.
    2360  * @param   uInterface      The Interface.
    2361  * @param   uAlt            The Alternate setting.
     2395 * @param   pEpData         The Endpoint data (NULL implies the default
     2396 *                          endpoint).
    23622397 *
    23632398 * @returns VBox error code.
    23642399 */
    2365 LOCAL int vboxUSBSolarisInitEndPoint(vboxusb_state_t *pState, usb_ep_data_t *pEpData, uchar_t uCfgValue,
    2366                                      uchar_t uInterface, uchar_t uAlt)
    2367 {
    2368     LogFunc((DEVICE_NAME ":vboxUSBSolarisInitEndPoint pState=%p pEpData=%p CfgVal=%d Iface=%d Alt=%d", pState,
    2369                     pEpData, uCfgValue, uInterface, uAlt));
     2400LOCAL int vboxUsbSolarisInitEp(vboxusb_state_t *pState, usb_ep_data_t *pEpData)
     2401{
     2402    LogFunc((DEVICE_NAME ": vboxUsbSolarisInitEp: pState=%p pEpData=%p", pState, pEpData));
    23702403
    23712404    /*
     
    23742407    usb_ep_descr_t *pEpDesc = NULL;
    23752408    vboxusb_ep_t *pEp = NULL;
    2376     int EpIndex = 0;
     2409    int iEpIndex;
    23772410    if (!pEpData)
    23782411    {
    2379         EpIndex = 0;
     2412        iEpIndex = 0;
    23802413        pEpDesc = &g_VBoxUSBSolarisDefaultEpDesc;
    23812414    }
    23822415    else
    23832416    {
    2384         EpIndex = usb_get_ep_index(pEpData->ep_descr.bEndpointAddress);
    2385         pEpDesc = &pEpData->ep_descr;
    2386     }
    2387 
    2388     pEp = &pState->aEps[EpIndex];
    2389     AssertRelease(pEp);
     2417        iEpIndex = VBOXUSB_GET_EP_INDEX(pEpData->ep_descr.bEndpointAddress);
     2418        pEpDesc  = (usb_ep_descr_t *)((uint8_t *)pEpData + g_offUsbEpDataDescr);
     2419    }
     2420
     2421    Assert(iEpIndex >= 0 && iEpIndex < RT_ELEMENTS(pState->aEps));
     2422    pEp = &pState->aEps[iEpIndex];
    23902423
    23912424    /*
    2392      * Initialize the endpoint data structure.
     2425     * Initialize the endpoint.
    23932426     */
    23942427    pEp->EpDesc = *pEpDesc;
    2395     pEp->uCfgValue = uCfgValue;
    2396     pEp->uInterface = uInterface;
    2397     pEp->uAlt = uAlt;
    2398     if (pEp->fInitialized != VBOXUSB_EP_INITIALIZED)
     2428    if (!pEp->fInitialized)
    23992429    {
    24002430        pEp->pPipe = NULL;
     
    24082438        pEp->cbIsocInLandedReqs = 0;
    24092439        pEp->cbMaxIsocData = 0;
    2410         pEp->fInitialized = VBOXUSB_EP_INITIALIZED;
    2411     }
    2412     Log((DEVICE_NAME ":vboxUSBSolarisInitEndPoint done. %s:[%d] bEndpoint=%#x\n", !pEpData ? "Default " : "Endpoint",
    2413                     EpIndex, pEp->EpDesc.bEndpointAddress));
     2440        pEp->fInitialized = true;
     2441    }
     2442
     2443    Log((DEVICE_NAME ": vboxUsbSolarisInitEp: Success, %s[%2d] %s %s bEndpoint=%#x\n", !pEpData ? "Default " : "Endpoint",
     2444         iEpIndex, vboxUsbSolarisEpType(pEp), vboxUsbSolarisEpDir(pEp), pEp->EpDesc.bEndpointAddress));
    24142445    return VINF_SUCCESS;
    24152446}
     
    24172448
    24182449/**
    2419  * Initialize all Endpoint structures.
     2450 * Initializes Endpoints for the current configuration, all interfaces and
     2451 * alternate setting 0 for each interface.
    24202452 *
    24212453 * @param   pState          The USB device instance.
     
    24232455 * @returns VBox status code.
    24242456 */
    2425 LOCAL int vboxUSBSolarisInitAllEndPoints(vboxusb_state_t *pState)
    2426 {
    2427     LogFunc((DEVICE_NAME ":vboxUSBSolarisInitAllEndPoints pState=%p\n", pState));
    2428 
    2429     /*
    2430      * Initialize all Endpoints for all Alternate settings of all Interfaces of all Configs.
    2431      */
    2432     int rc = vboxUSBSolarisInitEndPoint(pState, NULL /* pEp */, 0 /* uCfgValue */, 0 /* uInterface */, 0 /* uAlt */);
    2433 
    2434     if (RT_SUCCESS(rc))
    2435     {
    2436         /*
    2437          * Initialize all Endpoints for all Alternate settings of all Interfaces of all Configs.
    2438          */
    2439         for (uchar_t uCfgIndex = 0; uCfgIndex < pState->pDevDesc->dev_n_cfg; uCfgIndex++)
    2440         {
    2441             rc = vboxUSBSolarisInitEndPointsForConfig(pState, uCfgIndex);
    2442             if (RT_FAILURE(rc))
     2457LOCAL int vboxUsbSolarisInitEpsForCfg(vboxusb_state_t *pState)
     2458{
     2459    uint_t uCfgIndex = usb_get_current_cfgidx(pState->pDip);
     2460    if (uCfgIndex >= pState->pDevDesc->dev_n_cfg)
     2461    {
     2462        LogRel((DEVICE_NAME ": vboxUsbSolarisInitEpsForCfg: Invalid current config index %u\n", uCfgIndex));
     2463        return VERR_OUT_OF_RANGE;
     2464    }
     2465
     2466    usb_cfg_data_t *pConfig = &pState->pDevDesc->dev_cfg[uCfgIndex];
     2467    uchar_t bConfig = pConfig->cfg_descr.bConfigurationValue;
     2468
     2469    LogFunc((DEVICE_NAME ": vboxUsbSolarisInitEpsForCfg: pState=%p bConfig=%u uCfgIndex=%u\n", pState, bConfig, uCfgIndex));
     2470
     2471    const uint_t cIfs = pConfig->cfg_n_if;
     2472    for (uchar_t uIf = 0; uIf < cIfs; uIf++)
     2473    {
     2474        usb_if_data_t *pIf = &pConfig->cfg_if[uIf];
     2475        const uint_t cAlts = pIf->if_n_alt;
     2476        for (uchar_t uAlt = 0; uAlt < cAlts; uAlt++)
     2477        {
     2478            usb_alt_if_data_t *pAlt = &pIf->if_alt[uAlt];
     2479            if (pAlt->altif_descr.bAlternateSetting == 0)   /* Refer USB 2.0 spec 9.6.5 "Interface" */
    24432480            {
    2444                 LogRel((DEVICE_NAME ":vboxUSBSolarisInitAllEndPoints: vboxUSBSolarisInitEndPoints uCfgIndex=%d failed. rc=%d\n",
    2445                         uCfgIndex, rc));
    2446                 return rc;
     2481                const uint_t cEps = pAlt->altif_n_ep;
     2482                for (uchar_t uEp = 0; uEp < cEps; uEp++)
     2483                {
     2484                    uint8_t       *pbEpData = (uint8_t *)&pAlt->altif_ep[0];
     2485                    usb_ep_data_t *pEpData  = (usb_ep_data_t *)(pbEpData + uEp * g_cbUsbEpData);
     2486                    int rc = vboxUsbSolarisInitEp(pState, pEpData);
     2487                    if (RT_FAILURE(rc))
     2488                    {
     2489                        LogRel((DEVICE_NAME ": vboxUsbSolarisInitEpsForCfg: Failed to init endpoint! "
     2490                                "bConfig=%u bIf=%#x bAlt=%#x\n", bConfig, pAlt->altif_descr.bInterfaceNumber,
     2491                                pAlt->altif_descr.bAlternateSetting));
     2492                        return rc;
     2493                    }
     2494                }
     2495                break;  /* move on to next interface. */
    24472496            }
    24482497        }
    24492498    }
    2450     else
    2451         LogRel((DEVICE_NAME ":vboxUSBSolarisInitAllEndPoints default Endpoint initialization failed!\n"));
    2452 
    2453     return rc;
    2454 }
    2455 
    2456 
    2457 /**
    2458  * Initialize Endpoints structures for the given Config.
    2459  *
    2460  * @param   pState          The USB device instance.
    2461  * @param   uCfgIndex       The current Config. index.
     2499    return VINF_SUCCESS;
     2500}
     2501
     2502
     2503/**
     2504 * Initializes Endpoints for the given Interface & Alternate setting.
     2505 *
     2506 * @param   pState   The USB device instance.
     2507 * @param   bIf      The Interface.
     2508 * @param   bAlt     The Alterate.
    24622509 *
    24632510 * @returns VBox status code.
    24642511 */
    2465 LOCAL int vboxUSBSolarisInitEndPointsForConfig(vboxusb_state_t *pState, uint8_t uCfgIndex)
    2466 {
    2467     LogFunc((DEVICE_NAME ":vboxUSBSolarisInitEndPointsForConfig pState=%p uCfgIndex=%d\n", pState, uCfgIndex));
    2468     usb_cfg_data_t *pConfig = &pState->pDevDesc->dev_cfg[uCfgIndex];
    2469     uchar_t uCfgValue = pConfig->cfg_descr.bConfigurationValue;
    2470 
    2471     for (uchar_t uInterface = 0; uInterface < pConfig->cfg_n_if; uInterface++)
    2472     {
    2473         usb_if_data_t *pInterface = &pConfig->cfg_if[uInterface];
    2474 
    2475         for (uchar_t uAlt = 0; uAlt < pInterface->if_n_alt; uAlt++)
    2476         {
    2477             usb_alt_if_data_t *pAlt = &pInterface->if_alt[uAlt];
    2478 
    2479             for (uchar_t uEp = 0; uEp < pAlt->altif_n_ep; uEp++)
    2480             {
    2481                 usb_ep_data_t *pEpData = &pAlt->altif_ep[uEp];
    2482 
    2483                 int rc = vboxUSBSolarisInitEndPoint(pState, pEpData, uCfgValue, uInterface, uAlt);
    2484                 if (RT_FAILURE(rc))
    2485                 {
    2486                     LogRel((DEVICE_NAME ":vboxUSBSolarisInitEndPointsForConfig: vboxUSBSolarisInitEndPoint failed! pEp=%p "
    2487                             "uCfgValue=%u uCfgIndex=%u uInterface=%u, uAlt=%u\n", uCfgValue, uCfgIndex, uInterface, uAlt));
    2488                     return rc;
    2489                 }
    2490             }
    2491         }
    2492     }
    2493     return VINF_SUCCESS;
    2494 }
    2495 
    2496 
    2497 /**
    2498  * Initialize Endpoints structures for the given Interface & Alternate setting.
    2499  *
    2500  * @param   pState          The USB device instance.
    2501  * @param   uInterface      The interface being switched to.
    2502  * @param   uAlt            The alt being switched to.
    2503  *
    2504  * @returns VBox status code.
    2505  */
    2506 LOCAL int vboxUSBSolarisInitEndPointsForInterfaceAlt(vboxusb_state_t *pState, uint8_t uInterface, uint8_t uAlt)
    2507 {
    2508     LogFunc((DEVICE_NAME ":vboxUSBSolarisInitEndPointsForInterfaceAlt pState=%p uInterface=%d uAlt=%d\n", pState, uInterface,
    2509              uAlt));
     2512LOCAL int vboxUsbSolarisInitEpsForIfAlt(vboxusb_state_t *pState, uint8_t bIf, uint8_t bAlt)
     2513{
     2514    LogFunc((DEVICE_NAME ": vboxUsbSolarisInitEpsForIfAlt: pState=%p bIf=%d uAlt=%d\n", pState, bIf, bAlt));
    25102515
    25112516    /* Doesn't hurt to be paranoid */
    25122517    uint_t uCfgIndex = usb_get_current_cfgidx(pState->pDip);
    2513     if (RT_UNLIKELY(uCfgIndex >= pState->pDevDesc->dev_n_cfg))
    2514     {
    2515         LogRel((DEVICE_NAME ":vboxUSBSolarisInitEndPointsForInterfaceAlt invalid current config index %d\n", uCfgIndex));
    2516         return VERR_GENERAL_FAILURE;
     2518    if (uCfgIndex >= pState->pDevDesc->dev_n_cfg)
     2519    {
     2520        LogRel((DEVICE_NAME ": vboxUsbSolarisInitEpsForIfAlt: Invalid current config index %d\n", uCfgIndex));
     2521        return VERR_OUT_OF_RANGE;
    25172522    }
    25182523
    25192524    usb_cfg_data_t *pConfig = &pState->pDevDesc->dev_cfg[uCfgIndex];
    2520     uchar_t uCfgValue = pConfig->cfg_descr.bConfigurationValue;
    2521     usb_if_data_t *pInterface = &pConfig->cfg_if[uInterface];
    2522 
    2523     int rc = VINF_SUCCESS;
    2524     if (RT_LIKELY(pInterface))
    2525     {
    2526         usb_alt_if_data_t *pAlt = &pInterface->if_alt[uAlt];
    2527         if (RT_LIKELY(pAlt))
    2528         {
    2529             for (uchar_t uEp = 0; uEp < pAlt->altif_n_ep; uEp++)
     2525    for (uchar_t uIf = 0; uIf < pConfig->cfg_n_if; uIf++)
     2526    {
     2527        usb_if_data_t *pInterface = &pConfig->cfg_if[uIf];
     2528        const uint_t cAlts = pInterface->if_n_alt;
     2529        for (uchar_t uAlt = 0; uAlt < cAlts; uAlt++)
     2530        {
     2531            usb_alt_if_data_t *pAlt = &pInterface->if_alt[uAlt];
     2532            if (   pAlt->altif_descr.bInterfaceNumber  == bIf
     2533                && pAlt->altif_descr.bAlternateSetting == bAlt)
    25302534            {
    2531                 usb_ep_data_t *pEpData = &pAlt->altif_ep[uEp];
    2532                 rc = vboxUSBSolarisInitEndPoint(pState, pEpData, uCfgValue, uInterface, uAlt);
    2533                 if (RT_FAILURE(rc))
     2535                const uint_t cEps = pAlt->altif_n_ep;
     2536                for (uchar_t uEp = 0; uEp < cEps; uEp++)
    25342537                {
    2535                     LogRel((DEVICE_NAME ":vboxUSBSolarisInitEndPointsForInterfaceAlt: vboxUSBSolarisInitEndPoint failed! pEp=%p "
    2536                             "uCfgValue=%u uCfgIndex=%u uInterface=%u, uAlt=%u\n", uCfgValue, uCfgIndex, uInterface, uAlt));
    2537                     return rc;
     2538                    uint8_t       *pbEpData = (uint8_t *)&pAlt->altif_ep[0];
     2539                    usb_ep_data_t *pEpData  = (usb_ep_data_t *)(pbEpData + uEp * g_cbUsbEpData);
     2540                    int rc = vboxUsbSolarisInitEp(pState, pEpData);
     2541                    if (RT_FAILURE(rc))
     2542                    {
     2543                        uint8_t bCfgValue = pConfig->cfg_descr.bConfigurationValue;
     2544                        LogRel((DEVICE_NAME ": vboxUsbSolarisInitEpsForIfAlt: Failed to init endpoint! "
     2545                                "bCfgValue=%u bIf=%#x bAlt=%#x\n", bCfgValue, bIf, bAlt));
     2546                        return rc;
     2547                    }
    25382548                }
     2549                return VINF_SUCCESS;
    25392550            }
    25402551        }
    2541         else
    2542         {
    2543             LogRel((DEVICE_NAME ":vboxUSBSolarisInitEndPointsForInterfaceAlt missing alternate.\n"));
    2544             rc = VERR_INVALID_POINTER;
    2545         }
    2546     }
    2547     else
    2548     {
    2549         LogRel((DEVICE_NAME ":vboxUSBSolarisInitEndPointsForInterfaceAlt missing interface.\n"));
    2550         rc = VERR_INVALID_POINTER;
    2551     }
    2552 
    2553     Log((DEVICE_NAME ":vboxUSBSolarisInitEndPointsForInterfaceAlt returns %d\n", rc));
    2554     return rc;
    2555 }
    2556 
    2557 
    2558 /**
    2559  * Destroy all Endpoint Xfer structures.
     2552    }
     2553    return VERR_NOT_FOUND;
     2554}
     2555
     2556
     2557/**
     2558 * Destroys all Endpoints.
    25602559 *
    25612560 * @param   pState          The USB device instance.
     2561 *
    25622562 * @remarks Requires the state mutex to be held.
    25632563 *          Call only from Detach() or similar as callbacks
    25642564 */
    2565 LOCAL void vboxUSBSolarisDestroyAllEndPoints(vboxusb_state_t *pState)
    2566 {
    2567     LogFunc((DEVICE_NAME ":vboxUSBSolarisDestroyAllEndPoints pState=%p\n", pState));
     2565LOCAL void vboxUsbSolarisDestroyAllEps(vboxusb_state_t *pState)
     2566{
     2567    LogFunc((DEVICE_NAME ": vboxUsbSolarisDestroyAllEps: pState=%p\n", pState));
    25682568
    25692569    Assert(mutex_owned(&pState->Mtx));
     
    25712571    {
    25722572        vboxusb_ep_t *pEp = &pState->aEps[i];
    2573         if (pEp)
    2574         {
    2575             vboxUSBSolarisDestroyEndPoint(pState, pEp);
    2576             pEp = NULL;
    2577         }
    2578     }
    2579 }
    2580 
    2581 
    2582 /**
    2583  * Destroy an Endpoint.
     2573        if (pEp->fInitialized)
     2574            vboxUsbSolarisDestroyEp(pState, pEp);
     2575    }
     2576}
     2577
     2578
     2579/**
     2580 * Destroys an Endpoint.
    25842581 *
    25852582 * @param   pState          The USB device instance.
    25862583 * @param   pEp             The Endpoint.
     2584 *
    25872585 * @remarks Requires the state mutex to be held.
    25882586 */
    2589 LOCAL void vboxUSBSolarisDestroyEndPoint(vboxusb_state_t *pState, vboxusb_ep_t *pEp)
    2590 {
    2591     LogFunc((DEVICE_NAME ":vboxUSBSolarisDestroyEndPoint pState=%p pEp=%p\n", pState, pEp));
    2592 
     2587LOCAL void vboxUsbSolarisDestroyEp(vboxusb_state_t *pState, vboxusb_ep_t *pEp)
     2588{
     2589    LogFunc((DEVICE_NAME ": vboxUsbSolarisDestroyEp: pState=%p pEp=%p\n", pState, pEp));
     2590
     2591    Assert(pEp->fInitialized);
    25932592    Assert(mutex_owned(&pState->Mtx));
    2594     if (pEp->fInitialized == VBOXUSB_EP_INITIALIZED)
    2595     {
    2596         vboxusb_urb_t *pUrb = list_remove_head(&pEp->hIsocInUrbs);
    2597         while (pUrb)
    2598         {
    2599             if (pUrb->pMsg)
    2600                 freemsg(pUrb->pMsg);
    2601             RTMemFree(pUrb);
    2602             pUrb = list_remove_head(&pEp->hIsocInUrbs);
    2603         }
    2604         pEp->cIsocInUrbs = 0;
    2605         list_destroy(&pEp->hIsocInUrbs);
    2606 
    2607         vboxusb_isoc_req_t *pIsocReq = list_remove_head(&pEp->hIsocInLandedReqs);
    2608         while (pIsocReq)
    2609         {
    2610             kmem_free(pIsocReq, sizeof(vboxusb_isoc_req_t));
    2611             pIsocReq = list_remove_head(&pEp->hIsocInLandedReqs);
    2612         }
    2613         pEp->cbIsocInLandedReqs = 0;
    2614         list_destroy(&pEp->hIsocInLandedReqs);
    2615 
    2616         pEp->fInitialized = 0;
    2617     }
    2618 }
    2619 
    2620 
    2621 /**
    2622  * Close all non-default Endpoints and drains the default pipe.
     2593    vboxusb_urb_t *pUrb = list_remove_head(&pEp->hIsocInUrbs);
     2594    while (pUrb)
     2595    {
     2596        if (pUrb->pMsg)
     2597            freemsg(pUrb->pMsg);
     2598        RTMemFree(pUrb);
     2599        pUrb = list_remove_head(&pEp->hIsocInUrbs);
     2600    }
     2601    pEp->cIsocInUrbs = 0;
     2602    list_destroy(&pEp->hIsocInUrbs);
     2603
     2604    vboxusb_isoc_req_t *pIsocReq = list_remove_head(&pEp->hIsocInLandedReqs);
     2605    while (pIsocReq)
     2606    {
     2607        kmem_free(pIsocReq, sizeof(vboxusb_isoc_req_t));
     2608        pIsocReq = list_remove_head(&pEp->hIsocInLandedReqs);
     2609    }
     2610    pEp->cbIsocInLandedReqs = 0;
     2611    list_destroy(&pEp->hIsocInLandedReqs);
     2612
     2613    pEp->fInitialized = false;
     2614}
     2615
     2616
     2617/**
     2618 * Closes all non-default pipes and drains the default pipe.
    26232619 *
    26242620 * @param   pState          The USB device instance.
     
    26272623 * @remarks Requires the device state mutex to be held.
    26282624 */
    2629 LOCAL void vboxUSBSolarisCloseAllPipes(vboxusb_state_t *pState, bool fDefault)
    2630 {
    2631     LogFunc((DEVICE_NAME ":vboxUSBSolarisCloseAllPipes pState=%p\n", pState));
     2625LOCAL void vboxUsbSolarisCloseAllPipes(vboxusb_state_t *pState, bool fDefault)
     2626{
     2627    LogFunc((DEVICE_NAME ": vboxUsbSolarisCloseAllPipes: pState=%p\n", pState));
    26322628
    26332629    for (int i = 1; i < VBOXUSB_MAX_ENDPOINTS; i++)
     
    26372633            && pEp->pPipe)
    26382634        {
    2639             Log((DEVICE_NAME ":vboxUSBSolarisCloseAllPipes closing[%d]\n", i));
    2640             vboxUSBSolarisClosePipe(pState, pEp);
     2635            Log((DEVICE_NAME ": vboxUsbSolarisCloseAllPipes: Closing[%d]\n", i));
     2636            vboxUsbSolarisClosePipe(pState, pEp);
    26412637        }
    26422638    }
     
    26482644            && pEp->pPipe)
    26492645        {
    2650             vboxUSBSolarisClosePipe(pState, pEp);
    2651             Log((DEVICE_NAME ":vboxUSBSolarisCloseAllPipes closed default pipe.\n"));
    2652         }
    2653     }
    2654 }
    2655 
    2656 
    2657 /**
    2658  * Open the pipe for an Endpoint.
     2646            vboxUsbSolarisClosePipe(pState, pEp);
     2647            Log((DEVICE_NAME ": vboxUsbSolarisCloseAllPipes: Closed default pipe\n"));
     2648        }
     2649    }
     2650}
     2651
     2652
     2653/**
     2654 * Opens the pipe associated with an Endpoint.
    26592655 *
    26602656 * @param   pState          The USB device instance.
     
    26642660 * @returns VBox status code.
    26652661 */
    2666 LOCAL int vboxUSBSolarisOpenPipe(vboxusb_state_t *pState, vboxusb_ep_t *pEp)
     2662LOCAL int vboxUsbSolarisOpenPipe(vboxusb_state_t *pState, vboxusb_ep_t *pEp)
    26672663{
    26682664    Assert(mutex_owned(&pState->Mtx));
     
    26742670        return VINF_SUCCESS;
    26752671
    2676 
    26772672    /*
    26782673     * Default Endpoint; already opened just copy the pipe handle.
     
    26822677        pEp->pPipe = pState->pDevDesc->dev_default_ph;
    26832678        pEp->EpState |= VBOXUSB_EP_STATE_OPENED;
    2684         Log((DEVICE_NAME ":vboxUSBSolarisOpenPipe default pipe opened.\n"));
     2679        Log((DEVICE_NAME ": vboxUsbSolarisOpenPipe: Default pipe opened\n"));
    26852680        return VINF_SUCCESS;
    26862681    }
     
    26942689    if (rc == USB_SUCCESS)
    26952690    {
    2696         LogFunc((DEVICE_NAME ":vboxUSBSolarisOpenPipe: Opened pipe. pState=%p pEp=%p\n", pState, pEp));
     2691        LogFunc((DEVICE_NAME ": vboxUsbSolarisOpenPipe: Opened pipe, pState=%p pEp=%p\n", pState, pEp));
    26972692        usb_pipe_set_private(pEp->pPipe, (usb_opaque_t)pEp);
    26982693
     
    27192714                pEp->cbMaxIsocData = 400 * cbMax * 8;
    27202715            }
    2721             Log((DEVICE_NAME ":vboxUSBSolarisOpenPipe pEp=%p cbMaxIsocData=%u\n", pEp->cbMaxIsocData));
     2716            Log((DEVICE_NAME ": vboxUsbSolarisOpenPipe: bEndpoint=%#x cbMaxIsocData=%u\n", pEp->EpDesc.bEndpointAddress,
     2717                 pEp->cbMaxIsocData));
    27222718        }
    27232719
     
    27272723    else
    27282724    {
    2729         LogRel((DEVICE_NAME ":vboxUSBSolarisOpenPipe failed! rc=%d pState=%p pEp=%p\n", rc, pState, pEp));
     2725        LogRel((DEVICE_NAME ": vboxUsbSolarisOpenPipe: Failed! rc=%d pState=%p pEp=%p\n", rc, pState, pEp));
    27302726        rc = VERR_BAD_PIPE;
    27312727    }
     
    27362732
    27372733/**
    2738  * Close the pipe of the Endpoint.
     2734 * Closes the pipe associated with an Endpoint.
    27392735 *
    27402736 * @param   pState          The USB device instance.
     
    27432739 * @remarks Requires the device state mutex to be held.
    27442740 */
    2745 LOCAL void vboxUSBSolarisClosePipe(vboxusb_state_t *pState, vboxusb_ep_t *pEp)
    2746 {
    2747     LogFunc((DEVICE_NAME ":vboxUSBSolarisClosePipe pState=%p pEp=%p\n", pState, pEp));
     2741LOCAL void vboxUsbSolarisClosePipe(vboxusb_state_t *pState, vboxusb_ep_t *pEp)
     2742{
     2743    LogFunc((DEVICE_NAME ": vboxUsbSolarisClosePipe: pState=%p pEp=%p\n", pState, pEp));
    27482744    AssertPtr(pEp);
    27492745
     
    27602756            usb_pipe_drain_reqs(pState->pDip, pEp->pPipe, 0, USB_FLAGS_SLEEP, NULL /* callback */, NULL /* callback arg. */);
    27612757            mutex_enter(&pState->Mtx);
    2762             Log((DEVICE_NAME ":vboxUSBSolarisClosePipe closed default pipe\n"));
     2758            Log((DEVICE_NAME ": vboxUsbSolarisClosePipe: Closed default pipe\n"));
     2759            pState->fDefaultPipeOpen = false;
    27632760        }
    27642761        else
     
    27782775             * Non-default pipe: close it.
    27792776             */
    2780             Log((DEVICE_NAME ":vboxUSBSolarisClosePipe pipe bmAttributes=%#x bEndpointAddress=%#x\n", pEp->EpDesc.bmAttributes,
     2777            Log((DEVICE_NAME ": vboxUsbSolarisClosePipe: Pipe bmAttributes=%#x bEndpoint=%#x\n", pEp->EpDesc.bmAttributes,
    27812778                 pEp->EpDesc.bEndpointAddress));
    27822779            mutex_exit(&pState->Mtx);
     
    27902787        pEp->pPipe = NULL;
    27912788
    2792         Log((DEVICE_NAME ":vboxUSBSolarisClosePipe successful. pEp=%p\n", pEp));
     2789        Log((DEVICE_NAME ": vboxUsbSolarisClosePipe: Success, bEndpoint=%#x\n", pEp->EpDesc.bEndpointAddress));
    27932790    }
    27942791
     
    27982795
    27992796/**
    2800  * Find the Configuration index for the passed in Configuration value.
     2797 * Finds the Configuration index for the passed in Configuration value.
    28012798 *
    28022799 * @param   pState          The USB device instance.
    2803  * @param   uCfgValue       The Configuration value.
     2800 * @param   bConfig         The Configuration.
    28042801 *
    28052802 * @returns The configuration index if found, otherwise -1.
    28062803 */
    2807 LOCAL int vboxUSBSolarisGetConfigIndex(vboxusb_state_t *pState, uint_t uCfgValue)
     2804LOCAL int vboxUsbSolarisGetConfigIndex(vboxusb_state_t *pState, uint_t bConfig)
    28082805{
    28092806    for (int CfgIndex = 0; CfgIndex < pState->pDevDesc->dev_n_cfg; CfgIndex++)
    28102807    {
    28112808        usb_cfg_data_t *pConfig = &pState->pDevDesc->dev_cfg[CfgIndex];
    2812         if (pConfig->cfg_descr.bConfigurationValue == uCfgValue)
     2809        if (pConfig->cfg_descr.bConfigurationValue == bConfig)
    28132810            return CfgIndex;
    28142811    }
     
    28262823 * @returns The allocated Isoc. In URB to be used.
    28272824 */
    2828 LOCAL vboxusb_urb_t *vboxUSBSolarisGetIsocInURB(vboxusb_state_t *pState, PVBOXUSBREQ_URB pUrbReq)
     2825LOCAL vboxusb_urb_t *vboxUsbSolarisGetIsocInUrb(vboxusb_state_t *pState, PVBOXUSBREQ_URB pUrbReq)
    28292826{
    28302827    /*
     
    28562853    }
    28572854    else
    2858         LogRel((DEVICE_NAME ":vboxUSBSolarisGetIsocInURB failed to alloc %d bytes.\n", sizeof(vboxusb_urb_t)));
     2855        LogRel((DEVICE_NAME ": vboxUsbSolarisGetIsocInUrb: Failed to alloc %d bytes\n", sizeof(vboxusb_urb_t)));
    28592856    return pUrb;
    28602857}
     
    28702867 * @returns The allocated URB to be used, or NULL upon failure.
    28712868 */
    2872 LOCAL vboxusb_urb_t *vboxUSBSolarisQueueURB(vboxusb_state_t *pState, PVBOXUSBREQ_URB pUrbReq, mblk_t *pMsg)
    2873 {
    2874     LogFunc((DEVICE_NAME ":vboxUSBSolarisQueueURB pState=%p pUrbReq=%p\n", pState, pUrbReq));
     2869LOCAL vboxusb_urb_t *vboxUsbSolarisQueueUrb(vboxusb_state_t *pState, PVBOXUSBREQ_URB pUrbReq, mblk_t *pMsg)
     2870{
     2871    Assert(pUrbReq);
     2872    LogFunc((DEVICE_NAME ": vboxUsbSolarisQueueUrb: pState=%p pUrbReq=%p\n", pState, pUrbReq));
    28752873
    28762874    mutex_enter(&pState->Mtx);
    28772875
    28782876    /*
    2879      * Discard oldest queued URB if we've queued max URBs and none of them have completed.
     2877     * Grab a URB from the free list.
    28802878     */
    2881     if (pState->cInflightUrbs >= VBOXUSB_URB_QUEUE_SIZE)
    2882     {
    2883         vboxusb_urb_t *pUrb = list_head(&pState->hUrbs);
    2884         if (RT_LIKELY(pUrb))
    2885         {
    2886             if (pUrb->pMsg)
    2887             {
    2888                 freemsg(pUrb->pMsg);
    2889                 pUrb->pMsg = NULL;
    2890             }
    2891             pUrb->enmState = VBOXUSB_URB_STATE_FREE;
    2892         }
    2893     }
    2894 
    2895     vboxusb_urb_t *pUrb = list_head(&pState->hUrbs);
    2896     if (   !pUrb
    2897         || (   pUrb
    2898             && pUrb->enmState != VBOXUSB_URB_STATE_FREE))
    2899     {
     2879    vboxusb_urb_t *pUrb = list_remove_head(&pState->hFreeUrbs);
     2880    if (pUrb)
     2881    {
     2882        Assert(pUrb->enmState == VBOXUSB_URB_STATE_FREE);
     2883        Assert(!pUrb->pMsg);
     2884        Assert(pState->cFreeUrbs > 0);
     2885        --pState->cFreeUrbs;
     2886    }
     2887    else
     2888    {
     2889        /*
     2890         * We can't discard "old" URBs. For instance, INTR IN URBs that don't complete as
     2891         * they don't have a timeout can essentially take arbitrarily long to complete depending
     2892         * on the device and it's not safe to discard them in case they -do- complete. However,
     2893         * we also have to reasonably assume a device doesn't have too many pending URBs always.
     2894         *
     2895         * Thus we just use a large queue and simply refuse further transfers. This is not
     2896         * a situation which normally ever happens as usually there are at most than 4 or 5 URBs
     2897         * in-flight until we reap them.
     2898         */
     2899        uint32_t const cTotalUrbs = pState->cInflightUrbs + pState->cFreeUrbs + pState->cLandedUrbs;
     2900        if (cTotalUrbs >= VBOXUSB_URB_QUEUE_SIZE)
     2901        {
     2902            mutex_exit(&pState->Mtx);
     2903            LogRelMax(5, (DEVICE_NAME ": vboxUsbSolarisQueueUrb: Max queue size %u reached, refusing further transfers",
     2904                          cTotalUrbs));
     2905            return NULL;
     2906        }
     2907
     2908        /*
     2909         * Allocate a new URB as we have no free URBs.
     2910         */
    29002911        mutex_exit(&pState->Mtx);
    29012912        pUrb = RTMemAllocZ(sizeof(vboxusb_urb_t));
    29022913        if (RT_UNLIKELY(!pUrb))
    29032914        {
    2904             LogRel((DEVICE_NAME ":vboxUSBSolarisQueueURB failed to alloc %d bytes.\n", sizeof(vboxusb_urb_t)));
     2915            LogRel((DEVICE_NAME ": vboxUsbSolarisQueueUrb: Failed to alloc %d bytes\n", sizeof(vboxusb_urb_t)));
    29052916            return NULL;
    29062917        }
    29072918        mutex_enter(&pState->Mtx);
    29082919    }
    2909     else
    2910     {
    2911         /*
    2912          * Remove from head and move to tail so that when several URBs are reaped continuously we get to use
    2913          * up each one free 'head'.
    2914          */
    2915         Assert(pUrb && pUrb->enmState == VBOXUSB_URB_STATE_FREE);
    2916         list_remove_head(&pState->hUrbs);
    2917     }
    2918 
    2919     list_insert_tail(&pState->hUrbs, pUrb);
     2920
     2921    /*
     2922     * Add the URB to the inflight list.
     2923     */
     2924    list_insert_tail(&pState->hInflightUrbs, pUrb);
    29202925    ++pState->cInflightUrbs;
    29212926
    2922     pUrb->enmState = VBOXUSB_URB_STATE_INFLIGHT;
    2923 
    2924     Assert(pUrb->pMsg == NULL);
    2925     pUrb->pState = pState;
    2926     Log((DEVICE_NAME ":vboxUSBSolarisQueueURB cInflightUrbs=%d\n", pState->cInflightUrbs));
    2927 
    2928     if (RT_LIKELY(pUrbReq))
    2929     {
    2930         pUrb->pvUrbR3   = pUrbReq->pvUrbR3;
    2931         pUrb->bEndpoint = pUrbReq->bEndpoint;
    2932         pUrb->enmType   = pUrbReq->enmType;
    2933         pUrb->enmDir    = pUrbReq->enmDir;
    2934         pUrb->enmStatus = pUrbReq->enmStatus;
    2935         pUrb->fShortOk  = pUrbReq->fShortOk;
    2936         pUrb->pvDataR3  = (RTR3PTR)pUrbReq->pvData;
    2937         pUrb->cbDataR3  = pUrbReq->cbData;
    2938         pUrb->cIsocPkts = pUrbReq->cIsocPkts;
    2939 
    2940         if (pUrbReq->enmType == VUSBXFERTYPE_ISOC)
    2941         {
    2942             for (unsigned i = 0; i < pUrbReq->cIsocPkts; i++)
    2943                 pUrb->aIsocPkts[i].cbPkt = pUrbReq->aIsocPkts[i].cbPkt;
    2944         }
    2945 
    2946         pUrb->pMsg = pMsg;
     2927    Assert(!pUrb->pMsg);
     2928    pUrb->pMsg      = pMsg;
     2929    pUrb->pState    = pState;
     2930    pUrb->enmState  = VBOXUSB_URB_STATE_INFLIGHT;
     2931    pUrb->pvUrbR3   = pUrbReq->pvUrbR3;
     2932    pUrb->bEndpoint = pUrbReq->bEndpoint;
     2933    pUrb->enmType   = pUrbReq->enmType;
     2934    pUrb->enmDir    = pUrbReq->enmDir;
     2935    pUrb->enmStatus = pUrbReq->enmStatus;
     2936    pUrb->fShortOk  = pUrbReq->fShortOk;
     2937    pUrb->pvDataR3  = (RTR3PTR)pUrbReq->pvData;
     2938    pUrb->cbDataR3  = pUrbReq->cbData;
     2939    pUrb->cIsocPkts = pUrbReq->cIsocPkts;
     2940    if (pUrbReq->enmType == VUSBXFERTYPE_ISOC)
     2941    {
     2942        for (unsigned i = 0; i < pUrbReq->cIsocPkts; i++)
     2943            pUrb->aIsocPkts[i].cbPkt = pUrbReq->aIsocPkts[i].cbPkt;
    29472944    }
    29482945
    29492946    mutex_exit(&pState->Mtx);
    2950 
    29512947    return pUrb;
    29522948}
     
    29612957 * @remarks All pipes could be closed at this point (e.g. Device disconnected during inflight URBs)
    29622958 */
    2963 LOCAL inline void vboxUSBSolarisDeQueueURB(vboxusb_urb_t *pUrb, int URBStatus)
    2964 {
    2965     LogFunc((DEVICE_NAME ":vboxUSBSolarisDeQueue pUrb=%p\n", pUrb));
     2959LOCAL void vboxUsbSolarisDeQueueUrb(vboxusb_urb_t *pUrb, int URBStatus)
     2960{
     2961    LogFunc((DEVICE_NAME ": vboxUsbSolarisDeQueue: pUrb=%p\n", pUrb));
    29662962    AssertPtrReturnVoid(pUrb);
    29672963
    2968     pUrb->enmStatus = vboxUSBSolarisGetUrbStatus(URBStatus);
     2964    pUrb->enmStatus = vboxUsbSolarisGetUrbStatus(URBStatus);
     2965    if (pUrb->enmStatus != VUSBSTATUS_OK)
     2966        Log((DEVICE_NAME ": vboxUsbSolarisDeQueueUrb: URB failed! URBStatus=%d bEndpoint=%#x\n", URBStatus, pUrb->bEndpoint));
    29692967
    29702968    vboxusb_state_t *pState = pUrb->pState;
     
    29752973
    29762974        /*
    2977          * Remove it from the inflight list & move it to landed list.
     2975         * Remove it from the inflight list & move it to the landed list.
    29782976         */
    2979         list_remove(&pState->hUrbs, pUrb);
     2977        list_remove(&pState->hInflightUrbs, pUrb);
     2978        Assert(pState->cInflightUrbs > 0);
    29802979        --pState->cInflightUrbs;
     2980
    29812981        list_insert_tail(&pState->hLandedUrbs, pUrb);
    2982 
    2983         vboxUSBSolarisNotifyComplete(pUrb->pState);
     2982        ++pState->cLandedUrbs;
     2983
     2984        vboxUsbSolarisNotifyComplete(pUrb->pState);
    29842985        mutex_exit(&pState->Mtx);
    2985     }
    2986     else
    2987     {
    2988         Log((DEVICE_NAME ":vboxUSBSolarisDeQueue State Gone.\n"));
    2989         freemsg(pUrb->pMsg);
    2990         pUrb->pMsg = NULL;
    2991         pUrb->enmStatus = VUSBSTATUS_INVALID;
    2992     }
     2986        return;
     2987    }
     2988
     2989    /* Well, let's at least not leak memory... */
     2990    freemsg(pUrb->pMsg);
     2991    pUrb->pMsg = NULL;
     2992    pUrb->enmStatus = VUSBSTATUS_INVALID;
     2993
     2994    LogRel((DEVICE_NAME ": vboxUsbSolarisDeQueue: State Gone\n"));
    29932995}
    29942996
     
    29993001 * @param   pUrb                The URB to move.
    30003002 */
    3001 LOCAL inline void vboxUSBSolarisConcatMsg(vboxusb_urb_t *pUrb)
     3003LOCAL void vboxUsbSolarisConcatMsg(vboxusb_urb_t *pUrb)
    30023004{
    30033005    /*
     
    30133015            pUrb->pMsg = pFullMsg;
    30143016        }
    3015     }
    3016 }
    3017 
    3018 
    3019 /**
    3020  * User process poll wake up wrapper for asynchronous URB completion.
     3017        else
     3018            LogRel((DEVICE_NAME ": vboxUsbSolarisConcatMsg: Failed. Expect glitches due to truncated data!\n"));
     3019    }
     3020}
     3021
     3022
     3023/**
     3024 * Wakes up a user process signalling URB completion.
    30213025 *
    30223026 * @param   pState          The USB device instance.
    30233027 * @remarks Requires the device state mutex to be held.
    30243028 */
    3025 LOCAL inline void vboxUSBSolarisNotifyComplete(vboxusb_state_t *pState)
    3026 {
    3027     if (pState->fPoll & VBOXUSB_POLL_ON)
     3029LOCAL void vboxUsbSolarisNotifyComplete(vboxusb_state_t *pState)
     3030{
     3031    if (pState->fPollPending)
    30283032    {
    30293033        pollhead_t *pPollHead = &pState->PollHead;
    3030         pState->fPoll |= VBOXUSB_POLL_REAP_PENDING;
     3034        pState->fPollPending = false;
    30313035        mutex_exit(&pState->Mtx);
    30323036        pollwakeup(pPollHead, POLLIN);
     
    30373041
    30383042/**
    3039  * User process poll wake up wrapper for hotplug events.
     3043 * Wakes up a user process signalling a device unplug events.
    30403044 *
    30413045 * @param   pState          The USB device instance.
    30423046 * @remarks Requires the device state mutex to be held.
    30433047 */
    3044 LOCAL inline void vboxUSBSolarisNotifyHotplug(vboxusb_state_t *pState)
    3045 {
    3046     if (pState->fPoll & VBOXUSB_POLL_ON)
     3048LOCAL void vboxUsbSolarisNotifyUnplug(vboxusb_state_t *pState)
     3049{
     3050    if (pState->fPollPending)
    30473051    {
    30483052        pollhead_t *pPollHead = &pState->PollHead;
    3049         pState->fPoll |= VBOXUSB_POLL_DEV_UNPLUGGED;
     3053        pState->fPollPending = false;
    30503054        mutex_exit(&pState->Mtx);
    30513055        pollwakeup(pPollHead, POLLHUP);
     
    30563060
    30573061/**
    3058  * Perform a Control Xfer.
     3062 * Performs a Control Xfer.
    30593063 *
    30603064 * @param   pState          The USB device instance.
     
    30633067 *
    30643068 * @returns VBox status code.
    3065  * @remarks Any errors, the caller should free pUrb->pMsg.
    3066  */
    3067 LOCAL int vboxUSBSolarisCtrlXfer(vboxusb_state_t *pState, vboxusb_ep_t *pEp, vboxusb_urb_t *pUrb)
    3068 {
    3069     LogFunc((DEVICE_NAME ":vboxUSBSolarisCtrlXfer pState=%p pEp=%p pUrb=%p enmDir=%d cbData=%d\n", pState, pEp, pUrb,
     3069 */
     3070LOCAL int vboxUsbSolarisCtrlXfer(vboxusb_state_t *pState, vboxusb_ep_t *pEp, vboxusb_urb_t *pUrb)
     3071{
     3072    LogFunc((DEVICE_NAME ": vboxUsbSolarisCtrlXfer: pState=%p pEp=%p pUrb=%p enmDir=%d cbData=%d\n", pState, pEp, pUrb,
    30703073             pUrb->enmDir, pUrb->cbDataR3));
    30713074
    30723075    AssertPtrReturn(pUrb->pMsg, VERR_INVALID_PARAMETER);
    3073     uchar_t *pSetupData = pUrb->pMsg->b_rptr;
    3074     size_t cbData = pUrb->cbDataR3 > VBOXUSB_CTRL_XFER_SIZE ? pUrb->cbDataR3 - VBOXUSB_CTRL_XFER_SIZE : 0;
     3076    const size_t cbData = pUrb->cbDataR3 > VBOXUSB_CTRL_XFER_SIZE ? pUrb->cbDataR3 - VBOXUSB_CTRL_XFER_SIZE : 0;
    30753077
    30763078    /*
    30773079     * Allocate a wrapper request.
    30783080     */
    3079     int rc = VINF_SUCCESS;
    3080     usb_ctrl_req_t *pReq = usb_alloc_ctrl_req(pState->pDip, cbData, USB_FLAGS_NOSLEEP);
     3081    usb_ctrl_req_t *pReq = usb_alloc_ctrl_req(pState->pDip, cbData, USB_FLAGS_SLEEP);
    30813082    if (RT_LIKELY(pReq))
    30823083    {
     3084        uchar_t *pSetupData = pUrb->pMsg->b_rptr;
     3085
    30833086        /*
    30843087         * Initialize the Ctrl Xfer Header.
     
    30933096            && cbData)
    30943097        {
    3095             pUrb->pMsg->b_rptr += VBOXUSB_CTRL_XFER_SIZE;
    3096             bcopy(pUrb->pMsg->b_rptr, pReq->ctrl_data->b_wptr, cbData);
     3098            bcopy(pSetupData + VBOXUSB_CTRL_XFER_SIZE, pReq->ctrl_data->b_wptr, cbData);
    30973099            pReq->ctrl_data->b_wptr += cbData;
    30983100        }
     
    31043106         * Initialize callbacks and timeouts.
    31053107         */
    3106         usb_req_attrs_t fAttributes = USB_ATTRS_AUTOCLEARING;
    3107         if (   pUrb->enmDir == VUSBDIRECTION_IN
    3108             && pUrb->fShortOk)
    3109         {
    3110             fAttributes |= USB_ATTRS_SHORT_XFER_OK;
    3111         }
    3112         pReq->ctrl_cb             = vboxUSBSolarisCtrlXferCompleted;
    3113         pReq->ctrl_exc_cb         = vboxUSBSolarisCtrlXferCompleted;
     3108        pReq->ctrl_cb             = vboxUsbSolarisCtrlXferCompleted;
     3109        pReq->ctrl_exc_cb         = vboxUsbSolarisCtrlXferCompleted;
    31143110        pReq->ctrl_timeout        = VBOXUSB_CTRL_XFER_TIMEOUT;
    3115         pReq->ctrl_attributes     = fAttributes;
    3116 
     3111        pReq->ctrl_attributes     = USB_ATTRS_AUTOCLEARING | USB_ATTRS_SHORT_XFER_OK;
    31173112        pReq->ctrl_client_private = (usb_opaque_t)pUrb;
    3118 
    3119         LogFunc((DEVICE_NAME ":vboxUSBSolarisCtrlXfer ctrl_wLength=%#RX16 cbData=%#zx fShortOk=%RTbool\n", pReq->ctrl_wLength,
    3120                  cbData, !!(fAttributes & USB_ATTRS_SHORT_XFER_OK)));
    3121         Log((DEVICE_NAME ":vboxUSBSolarisCtrlXfer %.*Rhxd\n", VBOXUSB_CTRL_XFER_SIZE, pSetupData));
    31223113
    31233114        /*
    31243115         * Submit the request.
    31253116         */
    3126         rc = usb_pipe_ctrl_xfer(pEp->pPipe, pReq, USB_FLAGS_NOSLEEP);
    3127 
     3117        int rc = usb_pipe_ctrl_xfer(pEp->pPipe, pReq, USB_FLAGS_NOSLEEP);
    31283118        if (RT_LIKELY(rc == USB_SUCCESS))
    31293119            return VINF_SUCCESS;
    3130         else
    3131         {
    3132             LogRel((DEVICE_NAME ":vboxUSBSolarisCtrlXfer usb_pipe_ctrl_xfer failed! rc=%d\n", rc));
    3133             rc = VERR_PIPE_IO_ERROR;
    3134         }
     3120
     3121        LogRel((DEVICE_NAME ": vboxUsbSolarisCtrlXfer: Request failed! bEndpoint=%#x rc=%d\n", pUrb->bEndpoint, rc));
    31353122
    31363123        usb_free_ctrl_req(pReq);
    3137     }
    3138     else
    3139     {
    3140         LogRel((DEVICE_NAME ":vboxUSBSolarisCtrlXfer failed to alloc request.\n"));
    3141         rc = VERR_NO_MEMORY;
    3142     }
    3143 
    3144     return rc;
     3124        return VERR_PIPE_IO_ERROR;
     3125    }
     3126
     3127    LogRel((DEVICE_NAME ": vboxUsbSolarisCtrlXfer: Failed to alloc request for %u bytes\n", cbData));
     3128    return VERR_NO_MEMORY;
    31453129}
    31463130
     
    31523136 * @param   pReq             The Ctrl request.
    31533137 */
    3154 LOCAL void vboxUSBSolarisCtrlXferCompleted(usb_pipe_handle_t pPipe, usb_ctrl_req_t *pReq)
    3155 {
    3156     LogFunc((DEVICE_NAME ":vboxUSBSolarisCtrlXferCompleted pPipe=%p pReq=%p\n", pPipe, pReq));
     3138LOCAL void vboxUsbSolarisCtrlXferCompleted(usb_pipe_handle_t pPipe, usb_ctrl_req_t *pReq)
     3139{
     3140    LogFunc((DEVICE_NAME ": vboxUsbSolarisCtrlXferCompleted: pPipe=%p pReq=%p\n", pPipe, pReq));
     3141    Assert(pReq);
     3142    Assert(!(pReq->ctrl_cb_flags & USB_CB_INTR_CONTEXT));
    31573143
    31583144    vboxusb_urb_t *pUrb   = (vboxusb_urb_t *)pReq->ctrl_client_private;
     
    31613147        /*
    31623148         * Funky stuff: We need to reconstruct the header for control transfers.
    3163          * Let us chain along the data and while we dequeue the URB we attempt to
    3164          * concatenate the entire message there.
     3149         * Let us chain along the data and concatenate the entire message.
    31653150         */
    31663151        mblk_t *pSetupMsg = allocb(sizeof(VUSBSETUP), BPRI_MED);
     
    31693154            VUSBSETUP SetupData;
    31703155            SetupData.bmRequestType = pReq->ctrl_bmRequestType;
    3171             SetupData.bRequest = pReq->ctrl_bRequest;
    3172             SetupData.wValue = pReq->ctrl_wValue;
    3173             SetupData.wIndex = pReq->ctrl_wIndex;
    3174             SetupData.wLength = pReq->ctrl_wLength;
     3156            SetupData.bRequest      = pReq->ctrl_bRequest;
     3157            SetupData.wValue        = pReq->ctrl_wValue;
     3158            SetupData.wIndex        = pReq->ctrl_wIndex;
     3159            SetupData.wLength       = pReq->ctrl_wLength;
     3160
    31753161            bcopy(&SetupData, pSetupMsg->b_wptr, sizeof(VUSBSETUP));
    31763162            pSetupMsg->b_wptr += sizeof(VUSBSETUP);
    31773163
    31783164            /*
    3179              * Should be safe to update pMsg here without the state mutex, see vboxUSBSolarisSendURB()
    3180              * and vboxUSBSolarisQueueURB() as the URB state is (still) not VBOXUSB_URB_STATE_FREE.
     3165             * Should be safe to update pMsg here without the state mutex as typically nobody else
     3166             * touches this URB in the inflight list.
     3167             *
     3168             * The reason we choose to use vboxUsbSolarisConcatMsg here is that we don't assume the
     3169             * message returned by Solaris is one contiguous chunk in 'pMsg->b_rptr'.
    31813170             */
     3171            Assert(!pUrb->pMsg);
    31823172            pUrb->pMsg = pSetupMsg;
    31833173            pUrb->pMsg->b_cont = pReq->ctrl_data;
    31843174            pReq->ctrl_data = NULL;
    3185             vboxUSBSolarisConcatMsg(pUrb);
    3186 
    3187 #ifdef DEBUG_ramshankar
    3188             if (   pUrb->pMsg
    3189                 && pUrb->pMsg->b_cont == NULL)  /* Concat succeeded */
    3190             {
    3191                 Log((DEVICE_NAME ":vboxUSBSolarisCtrlXferCompleted prepended header rc=%d cbData=%d.\n",
    3192                      pReq->ctrl_completion_reason, MBLKL(pUrb->pMsg)));
    3193                 Log((DEVICE_NAME ":%.*Rhxd\n", MBLKL(pUrb->pMsg), pUrb->pMsg->b_rptr));
    3194             }
    3195 #endif
    3196 
    3197             /*
    3198              * Update the URB and move to landed list for reaping.
    3199              */
    3200             vboxUSBSolarisDeQueueURB(pUrb, pReq->ctrl_completion_reason);
     3175            vboxUsbSolarisConcatMsg(pUrb);
    32013176        }
    32023177        else
    3203         {
    3204             LogRel((DEVICE_NAME ":vboxUSBSolarisCtrlXferCompleted failed to alloc %d bytes for Setup Header.\n",
    3205                     sizeof(VUSBSETUP)));
    3206         }
     3178            LogRel((DEVICE_NAME ": vboxUsbSolarisCtrlXferCompleted: Failed to alloc %u bytes for header\n", sizeof(VUSBSETUP)));
     3179
     3180        /*
     3181         * Update the URB and move to landed list for reaping.
     3182         */
     3183        vboxUsbSolarisDeQueueUrb(pUrb, pReq->ctrl_completion_reason);
    32073184    }
    32083185    else
    3209         LogRel((DEVICE_NAME ":vboxUSBSolarisCtrlXferCompleted Extreme error! missing private data.\n"));
     3186        LogRel((DEVICE_NAME ": vboxUsbSolarisCtrlXferCompleted: Extreme error! missing private data\n"));
    32103187
    32113188    usb_free_ctrl_req(pReq);
     
    32143191
    32153192/**
    3216  * Perform a Bulk Xfer.
     3193 * Performs a Bulk Xfer.
    32173194 *
    32183195 * @param   pState          The USB device instance.
     
    32233200 * @remarks Any errors, the caller should free pUrb->pMsg.
    32243201 */
    3225 LOCAL int vboxUSBSolarisBulkXfer(vboxusb_state_t *pState, vboxusb_ep_t *pEp, vboxusb_urb_t *pUrb)
    3226 {
    3227     LogFunc((DEVICE_NAME ":vboxUSBSolarisBulkXfer pState=%p pEp=%p pUrb=%p enmDir=%d cbData=%d\n", pState, pEp, pUrb,
     3202LOCAL int vboxUsbSolarisBulkXfer(vboxusb_state_t *pState, vboxusb_ep_t *pEp, vboxusb_urb_t *pUrb)
     3203{
     3204    LogFunc((DEVICE_NAME ": vboxUsbSolarisBulkXfer: pState=%p pEp=%p pUrb=%p enmDir=%d cbData=%d\n", pState, pEp, pUrb,
    32283205             pUrb->enmDir, pUrb->cbDataR3));
    32293206
     
    32313208     * Allocate a wrapper request.
    32323209     */
    3233     int rc = VINF_SUCCESS;
    3234     usb_bulk_req_t *pReq = usb_alloc_bulk_req(pState->pDip, pUrb->enmDir == VUSBDIRECTION_IN ? pUrb->cbDataR3 : 0,
    3235                                               USB_FLAGS_NOSLEEP);
     3210    size_t const cbAlloc = pUrb->enmDir == VUSBDIRECTION_IN ? pUrb->cbDataR3 : 0;
     3211    usb_bulk_req_t *pReq = usb_alloc_bulk_req(pState->pDip, cbAlloc, USB_FLAGS_SLEEP);
    32363212    if (RT_LIKELY(pReq))
    32373213    {
     
    32413217        usb_req_attrs_t fAttributes = USB_ATTRS_AUTOCLEARING;
    32423218        if (pUrb->enmDir == VUSBDIRECTION_OUT)
     3219        {
    32433220            pReq->bulk_data = pUrb->pMsg;
     3221            pUrb->pMsg = NULL;
     3222        }
    32443223        else if (   pUrb->enmDir == VUSBDIRECTION_IN
    32453224                 && pUrb->fShortOk)
     
    32483227        }
    32493228
     3229        Assert(!pUrb->pMsg);
    32503230        pReq->bulk_len            = pUrb->cbDataR3;
    3251         pReq->bulk_cb             = vboxUSBSolarisBulkXferCompleted;
    3252         pReq->bulk_exc_cb         = vboxUSBSolarisBulkXferCompleted;
    3253         pReq->bulk_timeout        = VBOXUSB_BULK_XFER_TIMEOUT;
     3231        pReq->bulk_cb             = vboxUsbSolarisBulkXferCompleted;
     3232        pReq->bulk_exc_cb         = vboxUsbSolarisBulkXferCompleted;
     3233        pReq->bulk_timeout        = 0;
    32543234        pReq->bulk_attributes     = fAttributes;
    32553235        pReq->bulk_client_private = (usb_opaque_t)pUrb;
     
    32583238        if (RT_UNLIKELY(pUrb->cbDataR3 > pState->cbMaxBulkXfer))
    32593239        {
    3260             LogRel((DEVICE_NAME ":vboxUSBSolarisBulkXfer requesting %d bytes when only %d bytes supported by device\n",
     3240            LogRel((DEVICE_NAME ": vboxUsbSolarisBulkXfer: Requesting %d bytes when only %d bytes supported by device\n",
    32613241                        pUrb->cbDataR3, pState->cbMaxBulkXfer));
    32623242        }
     
    32653245         * Submit the request.
    32663246         */
    3267         rc = usb_pipe_bulk_xfer(pEp->pPipe, pReq, USB_FLAGS_NOSLEEP);
    3268 
     3247        int rc = usb_pipe_bulk_xfer(pEp->pPipe, pReq, USB_FLAGS_NOSLEEP);
    32693248        if (RT_LIKELY(rc == USB_SUCCESS))
    32703249            return VINF_SUCCESS;
    3271         else
    3272         {
    3273             LogRel((DEVICE_NAME ":vboxUSBSolarisBulkXfer usb_pipe_bulk_xfer enmDir=%#x Ep=%#x failed! rc=%d\n", pUrb->enmDir,
    3274                     pUrb->bEndpoint, rc));
    3275             rc = VERR_PIPE_IO_ERROR;
    3276         }
    3277 
    3278         if (pUrb->enmDir == VUSBDIRECTION_OUT) /* pUrb->pMsg freed by caller */
    3279             pReq->bulk_data = NULL;
     3250
     3251        LogRel((DEVICE_NAME ": vboxUsbSolarisBulkXfer: Request failed! Ep=%#x rc=%d cbData=%u\n", pUrb->bEndpoint, rc,
     3252                pReq->bulk_len));
    32803253
    32813254        usb_free_bulk_req(pReq);
    3282     }
    3283     else
    3284     {
    3285         LogRel((DEVICE_NAME ":vboxUSBSolarisBulkXfer failed to alloc bulk request.\n"));
    3286         rc = VERR_NO_MEMORY;
    3287     }
    3288 
    3289     return rc;
     3255        return VERR_PIPE_IO_ERROR;
     3256    }
     3257
     3258    LogRel((DEVICE_NAME ": vboxUsbSolarisBulkXfer: Failed to alloc bulk request\n"));
     3259    return VERR_NO_MEMORY;
    32903260}
    32913261
     
    32973267 * @param   pReq            The Bulk request.
    32983268 */
    3299 LOCAL void vboxUSBSolarisBulkXferCompleted(usb_pipe_handle_t pPipe, usb_bulk_req_t *pReq)
    3300 {
    3301     LogFunc((DEVICE_NAME ":vboxUSBSolarisBulkXferCompleted pPipe=%p pReq=%p\n", pPipe, pReq));
     3269LOCAL void vboxUsbSolarisBulkXferCompleted(usb_pipe_handle_t pPipe, usb_bulk_req_t *pReq)
     3270{
     3271    LogFunc((DEVICE_NAME ": vboxUsbSolarisBulkXferCompleted: pPipe=%p pReq=%p\n", pPipe, pReq));
     3272
     3273    Assert(pReq);
     3274    Assert(!(pReq->bulk_cb_flags & USB_CB_INTR_CONTEXT));
    33023275
    33033276    vboxusb_ep_t *pEp = (vboxusb_ep_t *)usb_pipe_get_private(pPipe);
     
    33073280        if (RT_LIKELY(pUrb))
    33083281        {
    3309             if (pUrb->enmDir == VUSBDIRECTION_OUT)
     3282            Assert(!pUrb->pMsg);
     3283            if (   pUrb->enmDir == VUSBDIRECTION_IN
     3284                && pReq->bulk_data)
     3285            {
     3286                pUrb->pMsg = pReq->bulk_data;
    33103287                pReq->bulk_data = NULL;
    3311             else
    3312             {
    3313                 if (pReq->bulk_completion_reason == USB_CR_OK)
    3314                 {
    3315                     pUrb->pMsg = pReq->bulk_data;
    3316                     pReq->bulk_data = NULL;
    3317                     vboxUSBSolarisConcatMsg(pUrb);
    3318                 }
     3288                vboxUsbSolarisConcatMsg(pUrb);
    33193289            }
    3320 
    3321             Log((DEVICE_NAME ":vboxUSBSolarisBulkXferCompleted %s. rc=%d cbData=%d\n",
    3322                     pReq->bulk_completion_reason != USB_CR_OK ? "failed URB" : "success",
    3323                     pReq->bulk_completion_reason, pUrb->pMsg ? MBLKL(pUrb->pMsg) : 0));
    33243290
    33253291            /*
    33263292             * Update the URB and move to tail for reaping.
    33273293             */
    3328             vboxUSBSolarisDeQueueURB(pUrb, pReq->bulk_completion_reason);
    3329             usb_free_bulk_req(pReq);
    3330             return;
     3294            vboxUsbSolarisDeQueueUrb(pUrb, pReq->bulk_completion_reason);
    33313295        }
    33323296        else
    3333             LogRel((DEVICE_NAME ":vboxUSBSolarisBulkXferCompleted Extreme error! private request data missing.\n"));
     3297            LogRel((DEVICE_NAME ": vboxUsbSolarisBulkXferCompleted: Extreme error! private request data missing!\n"));
    33343298    }
    33353299    else
    3336         Log((DEVICE_NAME ":vboxUSBSolarisBulkXferCompleted Pipe Gone.\n"));
     3300        Log((DEVICE_NAME ": vboxUsbSolarisBulkXferCompleted: Pipe Gone!\n"));
    33373301
    33383302    usb_free_bulk_req(pReq);
     
    33413305
    33423306/**
    3343  * Perform an Interrupt Xfer.
     3307 * Performs an Interrupt Xfer.
    33443308 *
    33453309 * @param   pState          The USB device instance.
     
    33503314 * @remarks Any errors, the caller should free pUrb->pMsg.
    33513315 */
    3352 LOCAL int vboxUSBSolarisIntrXfer(vboxusb_state_t *pState, vboxusb_ep_t *pEp, vboxusb_urb_t *pUrb)
    3353 {
    3354     LogFunc((DEVICE_NAME ":vboxUSBSolarisIntrXfer pState=%p pEp=%p pUrb=%p enmDir=%d cbData=%d\n", pState, pEp, pUrb,
     3316LOCAL int vboxUsbSolarisIntrXfer(vboxusb_state_t *pState, vboxusb_ep_t *pEp, vboxusb_urb_t *pUrb)
     3317{
     3318    LogFunc((DEVICE_NAME ": vboxUsbSolarisIntrXfer: pState=%p pEp=%p pUrb=%p enmDir=%d cbData=%d\n", pState, pEp, pUrb,
    33553319             pUrb->enmDir, pUrb->cbDataR3));
    33563320
    3357     int rc = VINF_SUCCESS;
    3358     usb_intr_req_t *pReq = usb_alloc_intr_req(pState->pDip, 0 /* length */, USB_FLAGS_NOSLEEP);
     3321    usb_intr_req_t *pReq = usb_alloc_intr_req(pState->pDip, 0 /* length */, USB_FLAGS_SLEEP);
    33593322    if (RT_LIKELY(pReq))
    33603323    {
     
    33623325         * Initialize Intr Xfer, callbacks & timeouts.
    33633326         */
     3327        usb_req_attrs_t fAttributes = USB_ATTRS_AUTOCLEARING;
    33643328        if (pUrb->enmDir == VUSBDIRECTION_OUT)
    33653329        {
    3366             pReq->intr_data       = pUrb->pMsg;
    3367             pReq->intr_attributes = USB_ATTRS_AUTOCLEARING;
     3330            pReq->intr_data = pUrb->pMsg;
     3331            pUrb->pMsg = NULL;
    33683332        }
    33693333        else
    33703334        {
    33713335            Assert(pUrb->enmDir == VUSBDIRECTION_IN);
    3372             pReq->intr_data       = NULL;
    3373             pReq->intr_attributes = USB_ATTRS_AUTOCLEARING | USB_ATTRS_ONE_XFER | (pUrb->fShortOk ? USB_ATTRS_SHORT_XFER_OK : 0);
    3374         }
    3375 
     3336            fAttributes |= USB_ATTRS_ONE_XFER;
     3337            if (pUrb->fShortOk)
     3338                fAttributes |= USB_ATTRS_SHORT_XFER_OK;
     3339        }
     3340
     3341        Assert(!pUrb->pMsg);
    33763342        pReq->intr_len            = pUrb->cbDataR3; /* Not pEp->EpDesc.wMaxPacketSize */
    3377         pReq->intr_cb             = vboxUSBSolarisIntrXferCompleted;
    3378         pReq->intr_exc_cb         = vboxUSBSolarisIntrXferCompleted;
    3379         pReq->intr_timeout        = VBOXUSB_INTR_XFER_TIMEOUT;
     3343        pReq->intr_cb             = vboxUsbSolarisIntrXferCompleted;
     3344        pReq->intr_exc_cb         = vboxUsbSolarisIntrXferCompleted;
     3345        pReq->intr_timeout        = 0;
     3346        pReq->intr_attributes     = fAttributes;
    33803347        pReq->intr_client_private = (usb_opaque_t)pUrb;
    33813348
     
    33833350         * Submit the request.
    33843351         */
    3385         rc = usb_pipe_intr_xfer(pEp->pPipe, pReq, USB_FLAGS_NOSLEEP);
    3386 
     3352        int rc = usb_pipe_intr_xfer(pEp->pPipe, pReq, USB_FLAGS_NOSLEEP);
    33873353        if (RT_LIKELY(rc == USB_SUCCESS))
    33883354            return VINF_SUCCESS;
    3389         else
    3390         {
    3391             LogRel((DEVICE_NAME ":vboxUSBSolarisIntrXfer usb_pipe_intr_xfer failed! rc=%d\n", rc));
    3392             rc = VERR_PIPE_IO_ERROR;
    3393         }
    3394 
    3395         pReq->intr_data = NULL;
     3355
     3356        LogRel((DEVICE_NAME ": vboxUsbSolarisIntrXfer: usb_pipe_intr_xfer failed! rc=%d bEndpoint=%#x\n", rc, pUrb->bEndpoint));
     3357
    33963358        usb_free_intr_req(pReq);
    3397     }
    3398     else
    3399     {
    3400         LogRel((DEVICE_NAME ":vboxUSBSolarisIntrXfer failed to alloc intr request.\n"));
    3401         rc = VERR_NO_MEMORY;
    3402     }
    3403 
    3404     return rc;
     3359        return VERR_PIPE_IO_ERROR;
     3360    }
     3361
     3362    LogRel((DEVICE_NAME ": vboxUsbSolarisIntrXfer: Failed to alloc intr request\n"));
     3363    return VERR_NO_MEMORY;
    34053364}
    34063365
     
    34123371 * @param   pReq            The Intr request.
    34133372 */
    3414 LOCAL void vboxUSBSolarisIntrXferCompleted(usb_pipe_handle_t pPipe, usb_intr_req_t *pReq)
    3415 {
    3416     LogFunc((DEVICE_NAME ":vboxUSBSolarisIntrXferCompleted pPipe=%p pReq=%p\n", pPipe, pReq));
    3417 
    3418     vboxusb_ep_t *pEp = (vboxusb_ep_t *)usb_pipe_get_private(pPipe);
    3419     if (RT_LIKELY(pEp))
    3420     {
    3421         vboxusb_urb_t *pUrb = (vboxusb_urb_t *)pReq->intr_client_private;
    3422         if (RT_LIKELY(pUrb))
    3423         {
    3424             if (pUrb->enmDir == VUSBDIRECTION_OUT)
    3425                 pReq->intr_data = NULL;
    3426             else
    3427             {
    3428                 if (pReq->intr_completion_reason == USB_CR_OK)
    3429                 {
    3430                     pUrb->pMsg = pReq->intr_data;
    3431                     pReq->intr_data = NULL;
    3432                 }
    3433             }
    3434 
    3435             Log((DEVICE_NAME ":vboxUSBSolarisIntrXferCompleted rc=%d pMsg=%p enmDir=%#x\n", pReq->intr_completion_reason,
    3436                  pUrb->pMsg, pUrb->enmDir));
    3437 
    3438             /*
    3439              * Update the URB and move to landed list for reaping.
    3440              */
    3441             vboxUSBSolarisDeQueueURB(pUrb, pReq->intr_completion_reason);
    3442             usb_free_intr_req(pReq);
    3443             return;
    3444         }
    3445         else
    3446             LogRel((DEVICE_NAME ":vboxUSBSolarisIntrXferCompleted Extreme error! private request data missing.\n"));
     3373LOCAL void vboxUsbSolarisIntrXferCompleted(usb_pipe_handle_t pPipe, usb_intr_req_t *pReq)
     3374{
     3375    LogFunc((DEVICE_NAME ": vboxUsbSolarisIntrXferCompleted: pPipe=%p pReq=%p\n", pPipe, pReq));
     3376
     3377    Assert(pReq);
     3378    Assert(!(pReq->intr_cb_flags & USB_CB_INTR_CONTEXT));
     3379
     3380    vboxusb_urb_t *pUrb = (vboxusb_urb_t *)pReq->intr_client_private;
     3381    if (RT_LIKELY(pUrb))
     3382    {
     3383        if (   pUrb->enmDir == VUSBDIRECTION_IN
     3384            && pReq->intr_data)
     3385        {
     3386            pUrb->pMsg = pReq->intr_data;
     3387            pReq->intr_data = NULL;
     3388            vboxUsbSolarisConcatMsg(pUrb);
     3389        }
     3390
     3391        /*
     3392         * Update the URB and move to landed list for reaping.
     3393         */
     3394        vboxUsbSolarisDeQueueUrb(pUrb, pReq->intr_completion_reason);
    34473395    }
    34483396    else
    3449         Log((DEVICE_NAME ":vboxUSBSolarisIntrXferCompleted Pipe Gone.\n"));
     3397        LogRel((DEVICE_NAME ": vboxUsbSolarisIntrXferCompleted: Extreme error! private request data missing\n"));
    34503398
    34513399    usb_free_intr_req(pReq);
     
    34543402
    34553403/**
    3456  * Perform an Isochronous Xfer.
     3404 * Performs an Isochronous Xfer.
    34573405 *
    34583406 * @param   pState          The USB device instance.
     
    34633411 * @remarks Any errors, the caller should free pUrb->pMsg.
    34643412 */
    3465 LOCAL int vboxUSBSolarisIsocXfer(vboxusb_state_t *pState, vboxusb_ep_t *pEp, vboxusb_urb_t *pUrb)
    3466 {
    3467 //    LogFunc((DEVICE_NAME ":vboxUSBSolarisIsocXfer pState=%p pEp=%p pUrb=%p\n", pState, pEp, pUrb));
     3413LOCAL int vboxUsbSolarisIsocXfer(vboxusb_state_t *pState, vboxusb_ep_t *pEp, vboxusb_urb_t *pUrb)
     3414{
     3415    /* LogFunc((DEVICE_NAME ": vboxUsbSolarisIsocXfer: pState=%p pEp=%p pUrb=%p\n", pState, pEp, pUrb)); */
    34683416
    34693417    /*
     
    34743422    if (pUrb->enmDir == VUSBDIRECTION_IN)
    34753423    {
    3476         Log((DEVICE_NAME ":vboxUSBSolarisIsocXfer Isoc. In queueing.\n"));
     3424        Log((DEVICE_NAME ": vboxUsbSolarisIsocXfer: Isoc. IN - Queueing\n"));
    34773425
    34783426        mutex_enter(&pState->Mtx);
     
    34853433            {
    34863434                mutex_exit(&pState->Mtx);
    3487                 Log((DEVICE_NAME ":vboxUSBSolarisIsocXfer Max Isoc. data %d bytes queued\n", pEp->cbMaxIsocData));
     3435                Log((DEVICE_NAME ": vboxUsbSolarisIsocXfer: Max Isoc. data %d bytes queued\n", pEp->cbMaxIsocData));
    34883436                return VERR_TOO_MUCH_DATA;
    34893437            }
     
    35003448    int rc = VINF_SUCCESS;
    35013449    usb_isoc_req_t *pReq = usb_alloc_isoc_req(pState->pDip, pUrb->cIsocPkts, cbData, USB_FLAGS_NOSLEEP);
    3502     Log((DEVICE_NAME ":vboxUSBSolarisIsocXfer enmDir=%#x cIsocPkts=%d aIsocPkts[0]=%d cbDataR3=%d\n", pUrb->enmDir,
     3450    Log((DEVICE_NAME ": vboxUsbSolarisIsocXfer: enmDir=%#x cIsocPkts=%d aIsocPkts[0]=%d cbDataR3=%d\n", pUrb->enmDir,
    35033451                    pUrb->cIsocPkts, pUrb->aIsocPkts[0].cbPkt, pUrb->cbDataR3));
    35043452    if (RT_LIKELY(pReq))
     
    35143462            pReq->isoc_data           = pUrb->pMsg;
    35153463            pReq->isoc_attributes     = USB_ATTRS_AUTOCLEARING | USB_ATTRS_ISOC_XFER_ASAP;
    3516             pReq->isoc_cb             = vboxUSBSolarisIsocOutXferCompleted;
    3517             pReq->isoc_exc_cb         = vboxUSBSolarisIsocOutXferCompleted;
     3464            pReq->isoc_cb             = vboxUsbSolarisIsocOutXferCompleted;
     3465            pReq->isoc_exc_cb         = vboxUsbSolarisIsocOutXferCompleted;
    35183466            pReq->isoc_client_private = (usb_opaque_t)pUrb;
    35193467        }
     
    35213469        {
    35223470            pReq->isoc_attributes     = USB_ATTRS_AUTOCLEARING | USB_ATTRS_ISOC_XFER_ASAP | USB_ATTRS_SHORT_XFER_OK;
    3523             pReq->isoc_cb             = vboxUSBSolarisIsocInXferCompleted;
    3524             pReq->isoc_exc_cb         = vboxUSBSolarisIsocInXferError;
     3471            pReq->isoc_cb             = vboxUsbSolarisIsocInXferCompleted;
     3472            pReq->isoc_exc_cb         = vboxUsbSolarisIsocInXferError;
    35253473            pReq->isoc_client_private = (usb_opaque_t)pState;
    35263474        }
     
    35503498        else
    35513499        {
    3552             LogRel((DEVICE_NAME ":vboxUSBSolarisIsocXfer usb_pipe_isoc_xfer failed! rc=%d\n", rc));
     3500            LogRel((DEVICE_NAME ": vboxUsbSolarisIsocXfer: usb_pipe_isoc_xfer failed! rc=%d\n", rc));
    35533501            rc = VERR_PIPE_IO_ERROR;
    35543502
     
    35673515        }
    35683516
    3569         if (pUrb->enmDir == VUSBDIRECTION_OUT) /* pUrb->pMsg freed by caller */
    3570             pReq->isoc_data = NULL;
     3517        if (pUrb->enmDir == VUSBDIRECTION_OUT)
     3518        {
     3519            freemsg(pUrb->pMsg);
     3520            pUrb->pMsg = NULL;
     3521        }
    35713522
    35723523        usb_free_isoc_req(pReq);
     
    35743525    else
    35753526    {
    3576         LogRel((DEVICE_NAME ":vboxUSBSolarisIsocXfer failed to alloc isoc req for %d packets\n", pUrb->cIsocPkts));
     3527        LogRel((DEVICE_NAME ": vboxUsbSolarisIsocXfer: Failed to alloc isoc req for %d packets\n", pUrb->cIsocPkts));
    35773528        rc = VERR_NO_MEMORY;
    35783529    }
     
    35903541 * @remarks Completion callback executes in interrupt context!
    35913542 */
    3592 LOCAL void vboxUSBSolarisIsocInXferCompleted(usb_pipe_handle_t pPipe, usb_isoc_req_t *pReq)
    3593 {
    3594 //    LogFunc((DEVICE_NAME ":vboxUSBSolarisIsocInXferCompleted pPipe=%p pReq=%p\n", pPipe, pReq));
     3543LOCAL void vboxUsbSolarisIsocInXferCompleted(usb_pipe_handle_t pPipe, usb_isoc_req_t *pReq)
     3544{
     3545    /* LogFunc((DEVICE_NAME ": vboxUsbSolarisIsocInXferCompleted: pPipe=%p pReq=%p\n", pPipe, pReq)); */
    35953546
    35963547    vboxusb_state_t *pState = (vboxusb_state_t *)pReq->isoc_client_private;
     
    36073558            if (pReq->isoc_error_count == pReq->isoc_pkts_count)
    36083559            {
    3609                 Log((DEVICE_NAME ":vboxUSBSolarisIsocInXferCompleted stopping polling! Too many errors.\n"));
     3560                Log((DEVICE_NAME ": vboxUsbSolarisIsocInXferCompleted: Stopping polling! Too many errors\n"));
    36103561                mutex_exit(&pState->Mtx);
    36113562                usb_pipe_stop_isoc_polling(pPipe, USB_FLAGS_NOSLEEP);
     
    36153566#endif
    36163567
     3568            /** @todo Query and verify this at runtime. */
    36173569            AssertCompile(sizeof(VUSBISOC_PKT_DESC) == sizeof(usb_isoc_pkt_descr_t));
    3618 
    36193570            if (RT_LIKELY(pReq->isoc_data))
    36203571            {
    3621                 Log((DEVICE_NAME ":vboxUSBSolarisIsocInXferCompleted cIsocInUrbs=%d cbIsocInLandedReqs=%d\n", pEp->cIsocInUrbs,
     3572                Log((DEVICE_NAME ": vboxUsbSolarisIsocInXferCompleted: cIsocInUrbs=%d cbIsocInLandedReqs=%d\n", pEp->cIsocInUrbs,
    36223573                     pEp->cbIsocInLandedReqs));
    36233574
     
    36393590                        {
    36403591                            pUrb->aIsocPkts[i].cbActPkt = pReq->isoc_pkt_descr[i].isoc_pkt_actual_length;
    3641                             pUrb->aIsocPkts[i].enmStatus = vboxUSBSolarisGetUrbStatus(pReq->isoc_pkt_descr[i].isoc_pkt_status);
     3592                            pUrb->aIsocPkts[i].enmStatus = vboxUsbSolarisGetUrbStatus(pReq->isoc_pkt_descr[i].isoc_pkt_status);
    36423593                        }
    36433594
     
    36503601                        mutex_enter(&pState->Mtx);
    36513602                        list_insert_tail(&pState->hLandedUrbs, pUrb);
    3652                         vboxUSBSolarisNotifyComplete(pState);
     3603                        ++pState->cLandedUrbs;
     3604                        vboxUsbSolarisNotifyComplete(pState);
    36533605                    }
    36543606                    else
     
    36573609                           Reap time */
    36583610                        pEp->cIsocInUrbs = 0;
    3659                         LogRel((DEVICE_NAME ":vboxUSBSolarisIsocInXferCompleted Extreme error! Isoc. counter b0rked!\n"));
     3611                        LogRel((DEVICE_NAME ": vboxUsbSolarisIsocInXferCompleted: Extreme error! Isoc. counter borked!\n"));
    36603612                    }
    36613613
     
    36653617                }
    36663618
    3667 #if 0
    3668                 /*
    3669                  * If the maximum buffer size is reached, discard the oldest data.
    3670                  */
    3671                 if (pEp->cbIsocInLandedReqs + MBLKL(pReq->isoc_data) > pEp->cbMaxIsocData)
    3672                 {
    3673                     vboxusb_isoc_req_t *pOldReq = list_remove_head(&pEp->hIsocInLandedReqs);
    3674                     if (RT_LIKELY(pOldReq))
    3675                     {
    3676                         pEp->cbIsocInLandedReqs -= MBLKL(pOldReq->pMsg);
    3677                         kmem_free(pOldReq, sizeof(vboxusb_isoc_req_t));
    3678                     }
    3679                 }
    3680 
    36813619                mutex_exit(&pState->Mtx);
    3682 
    3683                 /*
    3684                  * Buffer incoming data if the guest has not yet queued any Input URBs.
    3685                  */
    3686                 Log((DEVICE_NAME ":vboxUSBSolarisIsocInXferCompleted Buffering\n"));
    3687                 vboxusb_isoc_req_t *pIsocReq = kmem_alloc(sizeof(vboxusb_isoc_req_t), KM_NOSLEEP);
    3688                 if (RT_LIKELY(pIsocReq))
    3689                 {
    3690                     pIsocReq->pMsg = pReq->isoc_data;
    3691                     pReq->isoc_data = NULL;
    3692                     pIsocReq->cIsocPkts = pReq->isoc_pkts_count;
    3693 #if 0
    3694                     for (unsigned i = 0; i < pReq->isoc_pkts_count; i++)
    3695                     {
    3696                         pIsocReq->aIsocPkts[i].cbActPkt = pReq->isoc_pkt_descr[i].isoc_pkt_actual_length;
    3697                         pIsocReq->aIsocPkts[i].enmStatus = vboxUSBSolarisGetUrbStatus(pReq->isoc_pkt_descr[i].isoc_pkt_status);
    3698                     }
    3699 #else
    3700                     bcopy(pReq->isoc_pkt_descr, pIsocReq->aIsocPkts, pReq->isoc_pkts_count * sizeof(VUSBISOC_PKT_DESC));
    3701 #endif
    3702 
    3703                     mutex_enter(&pState->Mtx);
    3704                     list_insert_tail(&pEp->hIsocInLandedReqs, pIsocReq);
    3705                     pEp->cbIsocInLandedReqs += MBLKL(pIsocReq->pMsg);
    3706                     mutex_exit(&pState->Mtx);
    3707                 }
    3708                 else
    3709                 {
    3710                     LogRel((DEVICE_NAME ":vboxUSBSolarisIsocInXferCompleted failed to alloc %d bytes for Isoc. queueing\n",
    3711                             sizeof(vboxusb_isoc_req_t)));
    3712                 }
    3713 
    3714                 /*
    3715                  * Drain the input URB buffer with the device buffer, queueing them with the landed URBs.
    3716                  */
    3717                 mutex_enter(&pState->Mtx);
    3718                 while (pEp->cIsocInUrbs)
    3719                 {
    3720                     vboxusb_urb_t *pUrb = list_remove_head(&pEp->hIsocInUrbs);
    3721                     if (RT_UNLIKELY(!pUrb))
    3722                         break;
    3723 
    3724                     vboxusb_isoc_req_t *pBuffReq = list_remove_head(&pEp->hIsocInLandedReqs);
    3725                     if (!pBuffReq)
    3726                     {
    3727                         list_insert_head(&pEp->hIsocInUrbs, pUrb);
    3728                         break;
    3729                     }
    3730 
    3731                     --pEp->cIsocInUrbs;
    3732                     pEp->cbIsocInLandedReqs -= MBLKL(pBuffReq->pMsg);
    3733                     mutex_exit(&pState->Mtx);
    3734 
    3735 #if 0
    3736                     for (unsigned i = 0; i < pBuffReq->cIsocPkts; i++)
    3737                     {
    3738                         pUrb->aIsocPkts[i].cbActPkt = pBuffReq->aIsocPkts[i].cbActPkt;
    3739                         pUrb->aIsocPkts[i].enmStatus = pBuffReq->aIsocPkts[i].enmStatus;
    3740                     }
    3741 #else
    3742                     bcopy(pBuffReq->aIsocPkts, pUrb->aIsocPkts, pBuffReq->cIsocPkts * sizeof(VUSBISOC_PKT_DESC));
    3743 #endif
    3744                     pUrb->pMsg = pBuffReq->pMsg;
    3745                     pBuffReq->pMsg = NULL;
    3746                     kmem_free(pBuffReq, sizeof(vboxusb_isoc_req_t));
    3747 
    3748                     /*
    3749                      * Move to landed list
    3750                      */
    3751                     mutex_enter(&pState->Mtx);
    3752                     list_insert_tail(&pState->hLandedUrbs, pUrb);
    3753                     vboxUSBSolarisNotifyComplete(pState);
    3754                 }
    3755 #endif
    3756 
    3757                 mutex_exit(&pState->Mtx);
    3758                 usb_free_isoc_req(pReq);
    3759                 return;
    37603620            }
    37613621            else
    3762                 LogRel((DEVICE_NAME ":vboxUSBSolarisIsocInXferCompleted data missing.\n"));
     3622                LogRel((DEVICE_NAME ": vboxUsbSolarisIsocInXferCompleted: Data missing\n"));
    37633623        }
    37643624        else
    3765             LogRel((DEVICE_NAME ":vboxUSBSolarisIsocInXferCompleted Pipe Gone.\n"));
     3625            LogRel((DEVICE_NAME ": vboxUsbSolarisIsocInXferCompleted: Pipe Gone\n"));
    37663626    }
    37673627    else
    3768         Log((DEVICE_NAME ":vboxUSBSolarisIsocInXferCompleted State Gone.\n"));
     3628        Log((DEVICE_NAME ": vboxUsbSolarisIsocInXferCompleted: State Gone\n"));
    37693629
    37703630    usb_free_isoc_req(pReq);
     
    37793639 * @remarks Completion callback executes in interrupt context!
    37803640 */
    3781 LOCAL void vboxUSBSolarisIsocInXferError(usb_pipe_handle_t pPipe, usb_isoc_req_t *pReq)
    3782 {
    3783     LogFunc((DEVICE_NAME ":vboxUSBSolarisIsocInXferError pPipe=%p pReq=%p\n", pPipe, pReq));
     3641LOCAL void vboxUsbSolarisIsocInXferError(usb_pipe_handle_t pPipe, usb_isoc_req_t *pReq)
     3642{
     3643    LogFunc((DEVICE_NAME ": vboxUsbSolarisIsocInXferError: pPipe=%p pReq=%p\n", pPipe, pReq));
    37843644
    37853645    vboxusb_state_t *pState = (vboxusb_state_t *)pReq->isoc_client_private;
    37863646    if (RT_UNLIKELY(!pState))
    37873647    {
    3788         Log((DEVICE_NAME ":vboxUSBSolarisIsocInXferError State Gone.\n"));
     3648        Log((DEVICE_NAME ": vboxUsbSolarisIsocInXferError: State Gone\n"));
    37893649        usb_free_isoc_req(pReq);
    37903650        return;
     
    37953655    if (RT_UNLIKELY(!pEp))
    37963656    {
    3797         Log((DEVICE_NAME ":vboxUSBSolarisIsocInXferError Pipe Gone.\n"));
     3657        Log((DEVICE_NAME ": vboxUsbSolarisIsocInXferError: Pipe Gone\n"));
    37983658        mutex_exit(&pState->Mtx);
    37993659        usb_free_isoc_req(pReq);
     
    38113671            mutex_exit(&pState->Mtx);
    38123672            usb_pipe_isoc_xfer(pPipe, pReq, USB_FLAGS_NOSLEEP);
    3813             Log((DEVICE_NAME ":vboxUSBSolarisIsocInXferError resubmitted Isoc. IN request due to immediately unavailable "
    3814                  "resources.\n"));
    3815 
     3673            Log((DEVICE_NAME ": vboxUsbSolarisIsocInXferError: Resubmitted Isoc. IN request due to unavailable resources\n"));
    38163674            return;
    38173675        }
     
    38283686        default:
    38293687        {
    3830             Log((DEVICE_NAME ":vboxUSBSolarisIsocInXferError stopping Isoc. In. polling due to rc=%d\n",
     3688            Log((DEVICE_NAME ": vboxUsbSolarisIsocInXferError: Stopping Isoc. IN polling due to rc=%d\n",
    38313689                 pReq->isoc_completion_reason));
    38323690            pEp->fIsocPolling = false;
     
    38463704    {
    38473705        --pEp->cIsocInUrbs;
    3848         Log((DEVICE_NAME ":vboxUSBSolarisIsocInXferError Deleting last queued URB as it failed.\n"));
     3706        Log((DEVICE_NAME ": vboxUsbSolarisIsocInXferError: Deleting last queued URB as it failed\n"));
    38493707        freemsg(pUrb->pMsg);
    38503708        RTMemFree(pUrb);
    3851         vboxUSBSolarisNotifyComplete(pState);
     3709        vboxUsbSolarisNotifyComplete(pState);
    38523710    }
    38533711
     
    38633721 * @remarks Completion callback executes in interrupt context!
    38643722 */
    3865 LOCAL void vboxUSBSolarisIsocOutXferCompleted(usb_pipe_handle_t pPipe, usb_isoc_req_t *pReq)
    3866 {
    3867     LogFunc((DEVICE_NAME ":vboxUSBSolarisIsocOutXferCompleted pPipe=%p pReq=%p\n", pPipe, pReq));
     3723LOCAL void vboxUsbSolarisIsocOutXferCompleted(usb_pipe_handle_t pPipe, usb_isoc_req_t *pReq)
     3724{
     3725    LogFunc((DEVICE_NAME ": vboxUsbSolarisIsocOutXferCompleted: pPipe=%p pReq=%p\n", pPipe, pReq));
    38683726
    38693727    vboxusb_ep_t *pEp = (vboxusb_ep_t *)usb_pipe_get_private(pPipe);
     
    38783736                cbActPkt += pReq->isoc_pkt_descr[i].isoc_pkt_actual_length;
    38793737                pUrb->aIsocPkts[i].cbActPkt = pReq->isoc_pkt_descr[i].isoc_pkt_actual_length;
    3880                 pUrb->aIsocPkts[i].enmStatus = vboxUSBSolarisGetUrbStatus(pReq->isoc_pkt_descr[i].isoc_pkt_status);
     3738                pUrb->aIsocPkts[i].enmStatus = vboxUsbSolarisGetUrbStatus(pReq->isoc_pkt_descr[i].isoc_pkt_status);
    38813739            }
    38823740
    3883             Log((DEVICE_NAME ":vboxUSBSolarisIsocOutXferCompleted cIsocPkts=%d cbData=%d cbActPkt=%d\n", pUrb->cIsocPkts,
     3741            Log((DEVICE_NAME ": vboxUsbSolarisIsocOutXferCompleted: cIsocPkts=%d cbData=%d cbActPkt=%d\n", pUrb->cIsocPkts,
    38843742                 pUrb->cbDataR3, cbActPkt));
    38853743
     
    39003758             * Update the URB and move to landed list for reaping.
    39013759             */
    3902             vboxUSBSolarisDeQueueURB(pUrb, pReq->isoc_completion_reason);
    3903             usb_free_isoc_req(pReq);
    3904             return;
     3760            vboxUsbSolarisDeQueueUrb(pUrb, pReq->isoc_completion_reason);
    39053761        }
    39063762        else
    3907             Log((DEVICE_NAME ":vboxUSBSolarisIsocOutXferCompleted missing private data!?! Dropping OUT pUrb.\n"));
     3763            Log((DEVICE_NAME ": vboxUsbSolarisIsocOutXferCompleted: Missing private data!?! Dropping OUT pUrb\n"));
    39083764    }
    39093765    else
    3910         Log((DEVICE_NAME ":vboxUSBSolarisIsocOutXferCompleted Pipe Gone.\n"));
     3766        Log((DEVICE_NAME ": vboxUsbSolarisIsocOutXferCompleted: Pipe Gone\n"));
    39113767
    39123768    usb_free_isoc_req(pReq);
     
    39213777 * @returns Solaris USB error code.
    39223778 */
    3923 LOCAL int vboxUSBSolarisDeviceDisconnected(dev_info_t *pDip)
    3924 {
    3925     LogFunc((DEVICE_NAME ":vboxUSBSolarisDeviceDisconnected pDip=%p\n", pDip));
     3779LOCAL int vboxUsbSolarisDeviceDisconnected(dev_info_t *pDip)
     3780{
     3781    LogFunc((DEVICE_NAME ": vboxUsbSolarisDeviceDisconnected: pDip=%p\n", pDip));
    39263782
    39273783    int instance = ddi_get_instance(pDip);
     
    39383794        pState->DevState = USB_DEV_DISCONNECTED;
    39393795
    3940         vboxUSBSolarisCloseAllPipes(pState, true /* ControlPipe */);
    3941         vboxUSBSolarisNotifyHotplug(pState);
     3796        vboxUsbSolarisCloseAllPipes(pState, true /* ControlPipe */);
     3797        vboxUsbSolarisNotifyUnplug(pState);
    39423798
    39433799        mutex_exit(&pState->Mtx);
     
    39473803    }
    39483804
    3949     LogRel((DEVICE_NAME ":vboxUSBSolarisDeviceDisconnected failed to get device state!\n"));
     3805    LogRel((DEVICE_NAME ": vboxUsbSolarisDeviceDisconnected: Failed to get device state!\n"));
    39503806    return USB_FAILURE;
    39513807}
     
    39593815 * @returns Solaris USB error code.
    39603816 */
    3961 LOCAL int vboxUSBSolarisDeviceReconnected(dev_info_t *pDip)
    3962 {
    3963     LogFunc((DEVICE_NAME ":vboxUSBSolarisDeviceReconnected pDip=%p\n", pDip));
     3817LOCAL int vboxUsbSolarisDeviceReconnected(dev_info_t *pDip)
     3818{
     3819    LogFunc((DEVICE_NAME ": vboxUsbSolarisDeviceReconnected: pDip=%p\n", pDip));
    39643820
    39653821    int instance = ddi_get_instance(pDip);
     
    39683824    if (RT_LIKELY(pState))
    39693825    {
    3970         vboxUSBSolarisDeviceRestore(pState);
     3826        vboxUsbSolarisDeviceRestore(pState);
    39713827        return USB_SUCCESS;
    39723828    }
    39733829
    3974     LogRel((DEVICE_NAME ":vboxUSBSolarisDeviceReconnected failed to get device state!\n"));
     3830    LogRel((DEVICE_NAME ": vboxUsbSolarisDeviceReconnected: Failed to get device state!\n"));
    39753831    return USB_FAILURE;
    39763832}
     
    39783834
    39793835/**
    3980  * Restore device state after a reconnect or resume.
     3836 * Restores device state after a reconnect or resume.
    39813837 *
    39823838 * @param   pState          The USB device instance.
    39833839 */
    3984 LOCAL void vboxUSBSolarisDeviceRestore(vboxusb_state_t *pState)
    3985 {
    3986     LogFunc((DEVICE_NAME ":vboxUSBSolarisDeviceRestore pState=%p\n", pState));
     3840LOCAL void vboxUsbSolarisDeviceRestore(vboxusb_state_t *pState)
     3841{
     3842    LogFunc((DEVICE_NAME ": vboxUsbSolarisDeviceRestore: pState=%p\n", pState));
    39873843    AssertPtrReturnVoid(pState);
    39883844
     
    39903846     * Raise device power.
    39913847     */
    3992     vboxUSBSolarisPowerBusy(pState);
     3848    vboxUsbSolarisPowerBusy(pState);
    39933849    int rc = pm_raise_power(pState->pDip, 0 /* component */, USB_DEV_OS_FULL_PWR);
    39943850
     
    40103866
    40113867        /* Do we need to inform userland here? */
    4012         vboxUSBSolarisPowerIdle(pState);
    4013         Log((DEVICE_NAME ":vboxUSBSolarisDeviceRestore not the same device.\n"));
     3868        vboxUsbSolarisPowerIdle(pState);
     3869        Log((DEVICE_NAME ": vboxUsbSolarisDeviceRestore: Not the same device\n"));
    40143870        return;
    40153871    }
     
    40293885    usb_release_access(pState->StateMulti);
    40303886
    4031     vboxUSBSolarisPowerIdle(pState);
    4032 }
    4033 
    4034 
    4035 /**
    4036  * Restore device state after a reconnect or resume.
     3887    vboxUsbSolarisPowerIdle(pState);
     3888}
     3889
     3890
     3891/**
     3892 * Restores device state after a reconnect or resume.
    40373893 *
    40383894 * @param   pState          The USB device instance.
     
    40403896 * @returns VBox status code.
    40413897 */
    4042 LOCAL int vboxUSBSolarisDeviceSuspend(vboxusb_state_t *pState)
    4043 {
    4044     LogFunc((DEVICE_NAME ":vboxUSBSolarisDeviceSuspend pState=%p\n", pState));
     3898LOCAL int vboxUsbSolarisDeviceSuspend(vboxusb_state_t *pState)
     3899{
     3900    LogFunc((DEVICE_NAME ": vboxUsbSolarisDeviceSuspend: pState=%p\n", pState));
    40453901
    40463902    int rc = VERR_VUSB_DEVICE_IS_SUSPENDED;
     
    40513907        case USB_DEV_SUSPENDED:
    40523908        {
    4053             LogRel((DEVICE_NAME ":vboxUSBSolarisDeviceSuspend: Invalid device state %d\n", pState->DevState));
     3909            LogRel((DEVICE_NAME ": vboxUsbSolarisDeviceSuspend: Invalid device state %d\n", pState->DevState));
    40543910            break;
    40553911        }
     
    40623918            pState->DevState = USB_DEV_DISCONNECTED;
    40633919
     3920            /** @todo this doesn't make sense when for e.g. an INTR IN URB with infinite
     3921             *        timeout is pending on the device. Fix suspend logic later. */
    40643922            /*
    40653923             * Drain pending URBs.
     
    40813939            {
    40823940                pState->DevState = PreviousState;
    4083                 LogRel((DEVICE_NAME ":Cannot suspend, still have %d inflight URBs.\n", pState->cInflightUrbs));
     3941                LogRel((DEVICE_NAME ": Cannot suspend %s %s (Ident=%s), %d inflight URBs\n", pState->szMfg, pState->szProduct,
     3942                        pState->ClientInfo.szDeviceIdent, pState->cInflightUrbs));
    40843943
    40853944                mutex_exit(&pState->Mtx);
     
    40973956            mutex_enter(&pState->Mtx);
    40983957
    4099             vboxUSBSolarisCloseAllPipes(pState, true /* default pipe */);
    4100             vboxUSBSolarisNotifyHotplug(pState);
     3958            vboxUsbSolarisCloseAllPipes(pState, true /* default pipe */);
     3959            vboxUsbSolarisNotifyUnplug(pState);
    41013960
    41023961            mutex_exit(&pState->Mtx);
    41033962            usb_release_access(pState->StateMulti);
     3963
     3964            LogRel((DEVICE_NAME ": Suspended %s %s (Ident=%s)\n", pState->szMfg, pState->szProduct,
     3965                    pState->ClientInfo.szDeviceIdent));
    41043966            return VINF_SUCCESS;
    41053967        }
     
    41073969
    41083970    mutex_exit(&pState->Mtx);
    4109     Log((DEVICE_NAME ":vboxUSBSolarisDeviceSuspend returns %d\n", rc));
     3971    Log((DEVICE_NAME ": vboxUsbSolarisDeviceSuspend: Returns %d\n", rc));
    41103972    return rc;
    41113973}
     
    41133975
    41143976/**
    4115  * Restore device state after a reconnect or resume.
     3977 * Restores device state after a reconnect or resume.
    41163978 *
    41173979 * @param   pState          The USB device instance.
    41183980 */
    4119 LOCAL void vboxUSBSolarisDeviceResume(vboxusb_state_t *pState)
    4120 {
    4121     LogFunc((DEVICE_NAME ":vboxUSBSolarisDeviceResume pState=%p\n", pState));
    4122     return vboxUSBSolarisDeviceRestore(pState);
    4123 }
    4124 
    4125 
    4126 /**
    4127  * Flag the PM component as busy so the system will not manage it's power.
     3981LOCAL void vboxUsbSolarisDeviceResume(vboxusb_state_t *pState)
     3982{
     3983    LogFunc((DEVICE_NAME ": vboxUsbSolarisDeviceResume: pState=%p\n", pState));
     3984    return vboxUsbSolarisDeviceRestore(pState);
     3985}
     3986
     3987
     3988/**
     3989 * Flags the PM component as busy so the system will not manage it's power.
    41283990 *
    41293991 * @param   pState          The USB device instance.
    41303992 */
    4131 LOCAL void vboxUSBSolarisPowerBusy(vboxusb_state_t *pState)
    4132 {
    4133     LogFunc((DEVICE_NAME ":vboxUSBSolarisPowerBusy pState=%p\n", pState));
     3993LOCAL void vboxUsbSolarisPowerBusy(vboxusb_state_t *pState)
     3994{
     3995    LogFunc((DEVICE_NAME ": vboxUsbSolarisPowerBusy: pState=%p\n", pState));
    41343996    AssertPtrReturnVoid(pState);
    41353997
     
    41434005        if (rc != DDI_SUCCESS)
    41444006        {
    4145             Log((DEVICE_NAME ":vboxUSBSolarisPowerBusy busy component failed! rc=%d\n", rc));
     4007            Log((DEVICE_NAME ": vboxUsbSolarisPowerBusy: Busy component failed! rc=%d\n", rc));
    41464008            mutex_enter(&pState->Mtx);
    41474009            pState->pPower->PowerBusy--;
     
    41554017
    41564018/**
    4157  * Flag the PM component as idle so its power managed by the system.
     4019 * Flags the PM component as idle so its power managed by the system.
    41584020 *
    41594021 * @param   pState          The USB device instance.
    41604022 */
    4161 LOCAL void vboxUSBSolarisPowerIdle(vboxusb_state_t *pState)
    4162 {
    4163     LogFunc((DEVICE_NAME ":vboxUSBSolarisPowerIdle pState=%p\n", pState));
     4023LOCAL void vboxUsbSolarisPowerIdle(vboxusb_state_t *pState)
     4024{
     4025    LogFunc((DEVICE_NAME ": vboxUsbSolarisPowerIdle: pState=%p\n", pState));
    41644026    AssertPtrReturnVoid(pState);
    41654027
     
    41754037        }
    41764038        else
    4177             Log((DEVICE_NAME ":vboxUSBSolarisPowerIdle idle component failed! rc=%d\n", rc));
    4178     }
    4179 }
    4180 
     4039            Log((DEVICE_NAME ": vboxUsbSolarisPowerIdle: Idle component failed! rc=%d\n", rc));
     4040    }
     4041}
     4042
  • trunk/src/VBox/HostDrivers/VBoxUSB/solaris/VBoxUSBMon-solaris.c

    r58340 r59091  
    172172/** Global Mutex. */
    173173static kmutex_t g_VBoxUSBMonSolarisMtx;
    174 /** Number of userland clients that have kept us open. */
    175 static uint64_t g_cVBoxUSBMonSolarisClient = 0;
    176174/** Global list of client drivers registered with us. */
    177175vboxusbmon_client_t *g_pVBoxUSBMonSolarisClients = NULL;
     
    204202    int rc;
    205203
    206     LogFunc((DEVICE_NAME ":_init\n"));
     204    LogFunc((DEVICE_NAME ": _init\n"));
    207205
    208206    g_pDip = NULL;
     
    215213        pModCtl->mod_loadflags |= MOD_NOAUTOUNLOAD;
    216214    else
    217         LogRel((DEVICE_NAME ":failed to disable autounloading!\n"));
     215        LogRel((DEVICE_NAME ": _init: Failed to disable autounloading!\n"));
    218216
    219217    /*
     
    237235                    return rc;
    238236
    239                 LogRel((DEVICE_NAME ":mod_install failed! rc=%d\n", rc));
     237                LogRel((DEVICE_NAME ": _init: mod_install failed! rc=%d\n", rc));
    240238                ddi_soft_state_fini(&g_pVBoxUSBMonSolarisState);
    241239            }
    242240            else
    243                 LogRel((DEVICE_NAME ":ddi_soft_state_init failed! rc=%d\n", rc));
     241                LogRel((DEVICE_NAME ": _init: ddi_soft_state_init failed! rc=%d\n", rc));
    244242        }
    245243        else
    246             LogRel((DEVICE_NAME ":VBoxUSBFilterInit failed! rc=%d\n", rc));
     244            LogRel((DEVICE_NAME ": _init: VBoxUSBFilterInit failed! rc=%d\n", rc));
    247245
    248246        mutex_destroy(&g_VBoxUSBMonSolarisMtx);
     
    250248    }
    251249    else
    252         LogRel((DEVICE_NAME ":RTR0Init failed! rc=%d\n", rc));
     250        LogRel((DEVICE_NAME ": _init: RTR0Init failed! rc=%d\n", rc));
    253251
    254252    return -1;
     
    260258    int rc;
    261259
    262     LogFunc((DEVICE_NAME ":_fini\n"));
     260    LogFunc((DEVICE_NAME ": _fini\n"));
    263261
    264262    rc = mod_remove(&g_VBoxUSBMonSolarisModLinkage);
     
    277275int _info(struct modinfo *pModInfo)
    278276{
    279     LogFunc((DEVICE_NAME ":_info\n"));
     277    LogFunc((DEVICE_NAME ": _info\n"));
    280278
    281279    return mod_info(&g_VBoxUSBMonSolarisModLinkage, pModInfo);
     
    293291static int VBoxUSBMonSolarisAttach(dev_info_t *pDip, ddi_attach_cmd_t enmCmd)
    294292{
    295     LogFunc((DEVICE_NAME ":VBoxUSBMonSolarisAttach pDip=%p enmCmd=%d\n", pDip, enmCmd));
     293    LogFunc((DEVICE_NAME ": VBoxUSBMonSolarisAttach: pDip=%p enmCmd=%d\n", pDip, enmCmd));
    296294    switch (enmCmd)
    297295    {
     
    300298            if (RT_UNLIKELY(g_pDip))
    301299            {
    302                 LogRel((DEVICE_NAME ":VBoxUSBMonSolarisAttach global instance already initialized.\n"));
     300                LogRel((DEVICE_NAME ": VBoxUSBMonSolarisAttach: Global instance already initialized\n"));
    303301                return DDI_FAILURE;
    304302            }
     
    310308            if (rc == DDI_SUCCESS)
    311309            {
    312                 ddi_report_dev(pDip);
    313                 return rc;
     310                rc = usb_register_dev_driver(g_pDip, VBoxUSBMonSolarisElectDriver);
     311                if (rc == DDI_SUCCESS)
     312                {
     313                    ddi_report_dev(pDip);
     314                    return DDI_SUCCESS;
     315                }
     316
     317                LogRel((DEVICE_NAME ": VBoxUSBMonSolarisAttach: Failed to register driver election callback! rc=%d\n", rc));
    314318            }
    315319            else
    316                 LogRel((DEVICE_NAME ":VBoxUSBMonSolarisAttach ddi_create_minor_node failed! rc=%d\n", rc));
     320                LogRel((DEVICE_NAME ": VBoxUSBMonSolarisAttach: ddi_create_minor_node failed! rc=%d\n", rc));
    317321            return DDI_FAILURE;
    318322        }
     
    340344static int VBoxUSBMonSolarisDetach(dev_info_t *pDip, ddi_detach_cmd_t enmCmd)
    341345{
    342     LogFunc((DEVICE_NAME ":VBoxUSBMonSolarisDetach\n"));
     346    LogFunc((DEVICE_NAME ": VBoxUSBMonSolarisDetach\n"));
    343347
    344348    switch (enmCmd)
     
    359363            mutex_exit(&g_VBoxUSBMonSolarisMtx);
    360364
     365            usb_unregister_dev_driver(g_pDip);
     366
    361367            ddi_remove_minor_node(pDip, NULL);
    362368            g_pDip = NULL;
     
    390396    int rc = DDI_SUCCESS;
    391397
    392     LogFunc((DEVICE_NAME ":VBoxUSBMonSolarisGetInfo\n"));
     398    LogFunc((DEVICE_NAME ": VBoxUSBMonSolarisGetInfo\n"));
    393399
    394400    switch (enmCmd)
     
    415421    unsigned iOpenInstance;
    416422
    417     LogFunc((DEVICE_NAME ":VBoxUSBMonSolarisOpen\n"));
     423    LogFunc((DEVICE_NAME ": VBoxUSBMonSolarisOpen\n"));
    418424
    419425    /*
     
    428434    if (!g_pDip)
    429435    {
    430         LogRel((DEVICE_NAME ":VBoxUSBMonSolarisOpen invalid state for opening.\n"));
     436        LogRel((DEVICE_NAME ": VBoxUSBMonSolarisOpen: Invalid state for opening\n"));
    431437        return ENXIO;
    432438    }
    433 
    434     mutex_enter(&g_VBoxUSBMonSolarisMtx);
    435     if (!g_cVBoxUSBMonSolarisClient)
    436     {
    437         mutex_exit(&g_VBoxUSBMonSolarisMtx);
    438         int rc = usb_register_dev_driver(g_pDip, VBoxUSBMonSolarisElectDriver);
    439         if (RT_UNLIKELY(rc != DDI_SUCCESS))
    440         {
    441             LogRel((DEVICE_NAME ":Failed to register driver election callback with USBA rc=%d\n", rc));
    442             return EINVAL;
    443         }
    444         Log((DEVICE_NAME ":Successfully registered election callback with USBA\n"));
    445         mutex_enter(&g_VBoxUSBMonSolarisMtx);
    446     }
    447     g_cVBoxUSBMonSolarisClient++;
    448     mutex_exit(&g_VBoxUSBMonSolarisMtx);
    449439
    450440    for (iOpenInstance = 0; iOpenInstance < 4096; iOpenInstance++)
     
    459449    if (!pState)
    460450    {
    461         LogRel((DEVICE_NAME ":VBoxUSBMonSolarisOpen: too many open instances."));
    462         mutex_enter(&g_VBoxUSBMonSolarisMtx);
    463         g_cVBoxUSBMonSolarisClient--;
    464         mutex_exit(&g_VBoxUSBMonSolarisMtx);
     451        LogRel((DEVICE_NAME ": VBoxUSBMonSolarisOpen: Too many open instances"));
    465452        return ENXIO;
    466453    }
     
    479466{
    480467    vboxusbmon_state_t *pState = NULL;
    481 
    482     LogFunc((DEVICE_NAME ":VBoxUSBMonSolarisClose\n"));
     468    LogFunc((DEVICE_NAME ": VBoxUSBMonSolarisClose\n"));
    483469
    484470    pState = ddi_get_soft_state(g_pVBoxUSBMonSolarisState, getminor(Dev));
    485471    if (!pState)
    486472    {
    487         LogRel((DEVICE_NAME ":VBoxUSBMonSolarisClose: failed to get pState.\n"));
     473        LogRel((DEVICE_NAME ": VBoxUSBMonSolarisClose: Failed to get state\n"));
    488474        return EFAULT;
    489475    }
    490 
    491     mutex_enter(&g_VBoxUSBMonSolarisMtx);
    492     g_cVBoxUSBMonSolarisClient--;
    493     if (!g_cVBoxUSBMonSolarisClient)
    494     {
    495         if (RT_LIKELY(g_pDip))
    496         {
    497             mutex_exit(&g_VBoxUSBMonSolarisMtx);
    498             usb_unregister_dev_driver(g_pDip);
    499             Log((DEVICE_NAME ":Successfully deregistered driver election callback\n"));
    500         }
    501         else
    502         {
    503             mutex_exit(&g_VBoxUSBMonSolarisMtx);
    504             LogRel((DEVICE_NAME ":Extreme error! Missing device info during close.\n"));
    505         }
    506     }
    507     else
    508         mutex_exit(&g_VBoxUSBMonSolarisMtx);
    509476
    510477    /*
     
    526493static int VBoxUSBMonSolarisRead(dev_t Dev, struct uio *pUio, cred_t *pCred)
    527494{
    528     LogFunc((DEVICE_NAME ":VBoxUSBMonSolarisRead\n"));
     495    LogFunc((DEVICE_NAME ": VBoxUSBMonSolarisRead\n"));
    529496    return 0;
    530497}
     
    533500static int VBoxUSBMonSolarisWrite(dev_t Dev, struct uio *pUio, cred_t *pCred)
    534501{
    535     LogFunc((DEVICE_NAME ":VBoxUSBMonSolarisWrite\n"));
     502    LogFunc((DEVICE_NAME ": VBoxUSBMonSolarisWrite\n"));
    536503    return 0;
    537504}
     
    548515static int VBoxUSBMonSolarisIOCtl(dev_t Dev, int Cmd, intptr_t pArg, int Mode, cred_t *pCred, int *pVal)
    549516{
    550     LogFunc((DEVICE_NAME ":VBoxUSBMonSolarisIOCtl Dev=%d Cmd=%d pArg=%p Mode=%d\n", Dev, Cmd, pArg));
     517    LogFunc((DEVICE_NAME ": VBoxUSBMonSolarisIOCtl: Dev=%d Cmd=%d pArg=%p Mode=%d\n", Dev, Cmd, pArg));
    551518
    552519    /*
     
    556523    if (!pState)
    557524    {
    558         LogRel((DEVICE_NAME ":VBoxUSBMonSolarisIOCtl: no state data for %d\n", getminor(Dev)));
     525        LogRel((DEVICE_NAME ": VBoxUSBMonSolarisIOCtl: No state data for minor instance %d\n", getminor(Dev)));
    559526        return EINVAL;
    560527    }
     
    567534    if (IOCPARM_LEN(Cmd) != sizeof(ReqWrap))
    568535    {
    569         LogRel((DEVICE_NAME ": VBoxUSBMonSolarisIOCtl: bad request %#x size=%d expected=%d\n", Cmd, IOCPARM_LEN(Cmd), sizeof(ReqWrap)));
     536        LogRel((DEVICE_NAME ": VBoxUSBMonSolarisIOCtl: bad request %#x size=%d expected=%d\n", Cmd, IOCPARM_LEN(Cmd),
     537                sizeof(ReqWrap)));
    570538        return ENOTTY;
    571539    }
     
    574542    if (RT_UNLIKELY(rc))
    575543    {
    576         LogRel((DEVICE_NAME ": VBoxUSBMonSolarisIOCtl: ddi_copyin failed to read header pArg=%p Cmd=%d. rc=%d.\n", pArg, Cmd, rc));
     544        LogRel((DEVICE_NAME ": VBoxUSBMonSolarisIOCtl: ddi_copyin failed to read header pArg=%p Cmd=%d. rc=%d\n", pArg, Cmd, rc));
    577545        return EINVAL;
    578546    }
     
    580548    if (ReqWrap.u32Magic != VBOXUSBMON_MAGIC)
    581549    {
    582         LogRel((DEVICE_NAME ": VBoxUSBMonSolarisIOCtl: bad magic %#x; pArg=%p Cmd=%d.\n", ReqWrap.u32Magic, pArg, Cmd));
     550        LogRel((DEVICE_NAME ": VBoxUSBMonSolarisIOCtl: Bad magic %#x; pArg=%p Cmd=%d\n", ReqWrap.u32Magic, pArg, Cmd));
    583551        return EINVAL;
    584552    }
     
    586554                    || ReqWrap.cbData > _1M*16))
    587555    {
    588         LogRel((DEVICE_NAME ": VBoxUSBMonSolarisIOCtl: bad size %#x; pArg=%p Cmd=%d.\n", ReqWrap.cbData, pArg, Cmd));
     556        LogRel((DEVICE_NAME ": VBoxUSBMonSolarisIOCtl: Bad size %#x; pArg=%p Cmd=%d\n", ReqWrap.cbData, pArg, Cmd));
    589557        return EINVAL;
    590558    }
     
    596564    if (RT_UNLIKELY(!pvBuf))
    597565    {
    598         LogRel((DEVICE_NAME ":VBoxUSBMonSolarisIOCtl: RTMemTmpAlloc failed to alloc %d bytes.\n", ReqWrap.cbData));
     566        LogRel((DEVICE_NAME ": VBoxUSBMonSolarisIOCtl: RTMemTmpAlloc failed to alloc %d bytes\n", ReqWrap.cbData));
    599567        return ENOMEM;
    600568    }
     
    604572    {
    605573        RTMemTmpFree(pvBuf);
    606         LogRel((DEVICE_NAME ":VBoxUSBMonSolarisIOCtl: ddi_copyin failed; pvBuf=%p pArg=%p Cmd=%d. rc=%d\n", pvBuf, pArg, Cmd, rc));
     574        LogRel((DEVICE_NAME ": VBoxUSBMonSolarisIOCtl: ddi_copyin failed; pvBuf=%p pArg=%p Cmd=%d. rc=%d\n", pvBuf, pArg, Cmd,
     575                rc));
    607576        return EFAULT;
    608577    }
     
    611580    {
    612581        RTMemTmpFree(pvBuf);
    613         LogRel((DEVICE_NAME ":VBoxUSBMonSolarisIOCtl: pvBuf invalid pointer %p\n", pvBuf));
     582        LogRel((DEVICE_NAME ": VBoxUSBMonSolarisIOCtl: pvBuf Invalid pointer %p\n", pvBuf));
    614583        return EINVAL;
    615584    }
    616     Log((DEVICE_NAME ":VBoxUSBMonSolarisIOCtl: pid=%d.\n", (int)RTProcSelf()));
     585    Log((DEVICE_NAME ": VBoxUSBMonSolarisIOCtl: pid=%d\n", (int)RTProcSelf()));
    617586
    618587    /*
     
    626595    if (RT_UNLIKELY(cbDataReturned > ReqWrap.cbData))
    627596    {
    628         LogRel((DEVICE_NAME ":VBoxUSBMonSolarisIOCtl: too much output data %d expected %d\n", cbDataReturned, ReqWrap.cbData));
     597        LogRel((DEVICE_NAME ": VBoxUSBMonSolarisIOCtl: Too much output data %d expected %d\n", cbDataReturned, ReqWrap.cbData));
    629598        cbDataReturned = ReqWrap.cbData;
    630599    }
     
    646615            if (RT_UNLIKELY(rc))
    647616            {
    648                 LogRel((DEVICE_NAME ":VBoxUSBMonSolarisIOCtl: ddi_copyout failed; pvBuf=%p pArg=%p Cmd=%d. rc=%d\n", pvBuf, pArg, Cmd, rc));
     617                LogRel((DEVICE_NAME ": VBoxUSBMonSolarisIOCtl: ddi_copyout failed; pvBuf=%p pArg=%p Cmd=%d. rc=%d\n", pvBuf,
     618                        pArg, Cmd, rc));
    649619                rc = EFAULT;
    650620            }
     
    653623    else
    654624    {
    655         LogRel((DEVICE_NAME ":VBoxUSBMonSolarisIOCtl: ddi_copyout(1) failed pArg=%p Cmd=%d\n", pArg, Cmd));
     625        LogRel((DEVICE_NAME ": VBoxUSBMonSolarisIOCtl: ddi_copyout(1) failed pArg=%p Cmd=%d\n", pArg, Cmd));
    656626        rc = EFAULT;
    657627    }
     
    679649static int vboxUSBMonSolarisProcessIOCtl(int iFunction, void *pvState, void *pvData, size_t cbData, size_t *pcbReturnedData)
    680650{
    681     LogFunc((DEVICE_NAME ":solarisUSBProcessIOCtl iFunction=%d pvBuf=%p cbBuf=%zu\n", iFunction, pvData, cbData));
     651    LogFunc((DEVICE_NAME ": vboxUSBMonSolarisProcessIOCtl: iFunction=%d pvBuf=%p cbBuf=%zu\n", iFunction, pvData, cbData));
    682652
    683653    AssertPtrReturn(pvState, VERR_INVALID_POINTER);
     
    709679            PUSBFILTER pFilter = (PUSBFILTER)&pReq->Filter;
    710680
    711             Log(("vboxUSBMonSolarisProcessIOCtl: idVendor=%#x idProduct=%#x bcdDevice=%#x bDeviceClass=%#x bDeviceSubClass=%#x bDeviceProtocol=%#x bBus=%#x bPort=%#x\n",
     681            Log(("vboxUSBMonSolarisProcessIOCtl: idVendor=%#x idProduct=%#x bcdDevice=%#x bDeviceClass=%#x "
     682                 "bDeviceSubClass=%#x bDeviceProtocol=%#x bBus=%#x bPort=%#x\n",
    712683                      USBFilterGetNum(pFilter, USBFILTERIDX_VENDOR_ID),
    713684                      USBFilterGetNum(pFilter, USBFILTERIDX_PRODUCT_ID),
     
    727698            rc = VBoxUSBFilterAdd(pFilter, pState->Process, &pReq->uId);
    728699            *pcbReturnedData = cbData;
    729             Log((DEVICE_NAME ":vboxUSBMonSolarisProcessIOCtl: ADD_FILTER (Process:%d) returned %d\n", pState->Process, rc));
     700            Log((DEVICE_NAME ": vboxUSBMonSolarisProcessIOCtl: ADD_FILTER (Process:%d) returned %d\n", pState->Process, rc));
    730701            break;
    731702        }
     
    738709            rc = VBoxUSBFilterRemove(pState->Process, (uintptr_t)pReq->uId);
    739710            *pcbReturnedData = 0;
    740             Log((DEVICE_NAME ":vboxUSBMonSolarisProcessIOCtl: REMOVE_FILTER (Process:%d) returned %d\n", pState->Process, rc));
     711            Log((DEVICE_NAME ": vboxUSBMonSolarisProcessIOCtl: REMOVE_FILTER (Process:%d) returned %d\n", pState->Process, rc));
    741712            break;
    742713        }
     
    749720            rc = vboxUSBMonSolarisResetDevice(pReq->szDevicePath, pReq->fReattach);
    750721            *pcbReturnedData = 0;
    751             Log((DEVICE_NAME ":vboxUSBMonSolarisProcessIOCtl: RESET_DEVICE (Process:%d) returned %d\n", pState->Process, rc));
     722            Log((DEVICE_NAME ": vboxUSBMonSolarisProcessIOCtl: RESET_DEVICE (Process:%d) returned %d\n", pState->Process, rc));
    752723            break;
    753724        }
     
    760731            rc = vboxUSBMonSolarisClientInfo(pState, pReq);
    761732            *pcbReturnedData = cbData;
    762             Log((DEVICE_NAME ":vboxUSBMonSolarisProcessIOCtl: CLIENT_INFO (Process:%d) returned %d\n", pState->Process, rc));
     733            Log((DEVICE_NAME ": vboxUSBMonSolarisProcessIOCtl: CLIENT_INFO (Process:%d) returned %d\n", pState->Process, rc));
    763734            break;
    764735        }
     
    773744            *pcbReturnedData = sizeof(VBOXUSBREQ_GET_VERSION);
    774745            rc = VINF_SUCCESS;
    775             Log((DEVICE_NAME ":vboxUSBMonSolarisProcessIOCtl: GET_VERSION returned %d\n", rc));
     746            Log((DEVICE_NAME ": vboxUSBMonSolarisProcessIOCtl: GET_VERSION returned %d\n", rc));
    776747            break;
    777748        }
     
    779750        default:
    780751        {
    781             LogRel((DEVICE_NAME ":vboxUSBMonSolarisProcessIOCtl: Unknown request (Process:%d) %#x\n", pState->Process, iFunction));
     752            LogRel((DEVICE_NAME ": vboxUSBMonSolarisProcessIOCtl: Unknown request (Process:%d) %#x\n", pState->Process,
     753                    iFunction));
    782754            *pcbReturnedData = 0;
    783755            rc = VERR_NOT_SUPPORTED;
     
    793765    int rc = VERR_GENERAL_FAILURE;
    794766
    795     LogFunc((DEVICE_NAME ":vboxUSBMonSolarisResetDevice pszDevicePath=%s fReattach=%d\n", pszDevicePath, fReattach));
     767    LogFunc((DEVICE_NAME ": vboxUSBMonSolarisResetDevice: pszDevicePath=%s fReattach=%d\n", pszDevicePath, fReattach));
    796768
    797769    /*
     
    812784            if (!pTmpDeviceInfo)
    813785            {
    814                 LogRel((DEVICE_NAME ":vboxUSBMonSolarisResetDevice failed to get parent device info for %s\n", pszDevicePath));
     786                LogRel((DEVICE_NAME ":vboxUSBMonSolarisResetDevice: Failed to get parent device info for %s\n", pszDevicePath));
    815787                return VERR_GENERAL_FAILURE;
    816788            }
     
    826798         */
    827799        rc = usb_reset_device(pDeviceInfo, fReattach ? USB_RESET_LVL_REATTACH : USB_RESET_LVL_DEFAULT);
    828         Log((DEVICE_NAME ":usb_reset_device for %s level=%s returned %d\n", pszDevicePath, fReattach ? "ReAttach" : "Default", rc));
     800        Log((DEVICE_NAME ": vboxUSBMonSolarisResetDevice: usb_reset_device for %s level=%s rc=%d\n", pszDevicePath,
     801             fReattach ? "ReAttach" : "Default", rc));
     802
    829803        switch (rc)
    830804        {
     
    842816    {
    843817        rc = VERR_INVALID_HANDLE;
    844         LogRel((DEVICE_NAME ":vboxUSBMonSolarisResetDevice Cannot obtain device info for %s\n", pszDevicePath));
     818        LogRel((DEVICE_NAME ": vboxUSBMonSolarisResetDevice: Cannot obtain device info for %s\n", pszDevicePath));
    845819    }
    846820
     
    859833static int vboxUSBMonSolarisClientInfo(vboxusbmon_state_t *pState, PVBOXUSB_CLIENT_INFO pClientInfo)
    860834{
    861     LogFunc((DEVICE_NAME ":vboxUSBMonSolarisClientInfo pState=%p pClientInfo=%p\n", pState, pClientInfo));
     835    LogFunc((DEVICE_NAME ": vboxUSBMonSolarisClientInfo: pState=%p pClientInfo=%p\n", pState, pClientInfo));
    862836
    863837    AssertPtrReturn(pState, VERR_INVALID_POINTER);
     
    882856                rc = pCur->Info.pfnSetConsumerCredentials(pState->Process, pCur->Info.Instance, NULL /* pvReserved */);
    883857                if (RT_FAILURE(rc))
    884                     LogRel((DEVICE_NAME ":vboxUSBMonSolarisClientInfo pfnSetConsumerCredentials failed. rc=%d\n", rc));
     858                    LogRel((DEVICE_NAME ": vboxUSBMonSolarisClientInfo: pfnSetConsumerCredentials failed! rc=%d\n", rc));
    885859            }
    886860            else
     
    889863            mutex_exit(&g_VBoxUSBMonSolarisMtx);
    890864
    891             Log((DEVICE_NAME ":vboxUSBMonSolarisClientInfo found. %s rc=%d\n", pClientInfo->szDeviceIdent, rc));
     865            Log((DEVICE_NAME ": vboxUSBMonSolarisClientInfo: Found %s, rc=%d\n", pClientInfo->szDeviceIdent, rc));
    892866            return rc;
    893867        }
     
    898872    mutex_exit(&g_VBoxUSBMonSolarisMtx);
    899873
    900     LogRel((DEVICE_NAME ":vboxUSBMonSolarisClientInfo Failed to find client %s\n", pClientInfo->szDeviceIdent));
     874    LogRel((DEVICE_NAME ": vboxUSBMonSolarisClientInfo: Failed to find client %s\n", pClientInfo->szDeviceIdent));
    901875    return VERR_NOT_FOUND;
    902876}
     
    910884int VBoxUSBMonSolarisRegisterClient(dev_info_t *pClientDip, PVBOXUSB_CLIENT_INFO pClientInfo)
    911885{
    912     LogFunc((DEVICE_NAME ":VBoxUSBMonSolarisRegisterClient pClientDip=%p pClientInfo=%p\n", pClientDip, pClientInfo));
     886    LogFunc((DEVICE_NAME ": VBoxUSBMonSolarisRegisterClient: pClientDip=%p pClientInfo=%p\n", pClientDip, pClientInfo));
    913887    AssertPtrReturn(pClientInfo, VERR_INVALID_PARAMETER);
    914888
     
    929903            mutex_exit(&g_VBoxUSBMonSolarisMtx);
    930904
    931             Log((DEVICE_NAME ":VBoxUSBMonSolarisRegisterClient registered. %d %s %s\n",
    932                         pClient->Info.Instance, pClient->Info.szClientPath, pClient->Info.szDeviceIdent));
    933 
     905            Log((DEVICE_NAME ": Client registered (ClientPath=%s Ident=%s)\n", pClient->Info.szClientPath,
     906                 pClient->Info.szDeviceIdent));
    934907            return VINF_SUCCESS;
    935908        }
     
    947920int VBoxUSBMonSolarisUnregisterClient(dev_info_t *pClientDip)
    948921{
    949     LogFunc((DEVICE_NAME ":VBoxUSBMonSolarisUnregisterClient pClientDip=%p\n", pClientDip));
     922    LogFunc((DEVICE_NAME ": VBoxUSBMonSolarisUnregisterClient: pClientDip=%p\n", pClientDip));
    950923    AssertReturn(pClientDip, VERR_INVALID_PARAMETER);
    951924
     
    967940                mutex_exit(&g_VBoxUSBMonSolarisMtx);
    968941
    969                 Log((DEVICE_NAME ":VBoxUSBMonSolarisUnregisterClient unregistered. %d %s %s\n",
    970                             pCur->Info.Instance, pCur->Info.szClientPath, pCur->Info.szDeviceIdent));
     942                Log((DEVICE_NAME ": Client unregistered (ClientPath=%s Ident=%s)\n", pCur->Info.szClientPath,
     943                     pCur->Info.szDeviceIdent));
    971944                RTMemFree(pCur);
    972                 pCur = NULL;
    973945                return VINF_SUCCESS;
    974946            }
     
    979951        mutex_exit(&g_VBoxUSBMonSolarisMtx);
    980952
    981         LogRel((DEVICE_NAME ":VBoxUSBMonSolarisUnregisterClient Failed to find registered client %p\n", pClientDip));
     953        LogRel((DEVICE_NAME ": VBoxUSBMonSolarisUnregisterClient: Failed to find registered client %p\n", pClientDip));
    982954        return VERR_NOT_FOUND;
    983955    }
     
    1001973                                char **ppszDrv, void *pvReserved)
    1002974{
    1003     LogFunc((DEVICE_NAME ":VBoxUSBMonSolarisElectDriver pDevDesc=%p pDevStrings=%p pszDevicePath=%s Bus=%d Port=%d\n", pDevDesc,
     975    LogFunc((DEVICE_NAME ": VBoxUSBMonSolarisElectDriver: pDevDesc=%p pDevStrings=%p pszDevicePath=%s Bus=%d Port=%d\n", pDevDesc,
    1004976            pDevStrings, pszDevicePath, Bus, Port));
    1005977
     
    1027999    USBFilterSetMustBePresent(&Filter, USBFILTERIDX_BUS, false /* fMustBePresent */);
    10281000
    1029     Log((DEVICE_NAME ":VBoxUSBMonSolarisElectDriver: idVendor=%#x idProduct=%#x bcdDevice=%#x bDeviceClass=%#x bDeviceSubClass=%#x bDeviceProtocol=%#x bBus=%#x bPort=%#x\n",
     1001    Log((DEVICE_NAME ": VBoxUSBMonSolarisElectDriver: idVendor=%#x idProduct=%#x bcdDevice=%#x bDeviceClass=%#x "
     1002         "bDeviceSubClass=%#x bDeviceProtocol=%#x bBus=%#x bPort=%#x\n",
    10301003              USBFilterGetNum(&Filter, USBFILTERIDX_VENDOR_ID),
    10311004              USBFilterGetNum(&Filter, USBFILTERIDX_PRODUCT_ID),
     
    10361009              USBFilterGetNum(&Filter, USBFILTERIDX_BUS),
    10371010              USBFilterGetNum(&Filter, USBFILTERIDX_PORT)));
    1038     Log((DEVICE_NAME ":VBoxUSBMonSolarisElectDriver: Manufacturer=%s Product=%s Serial=%s\n",
     1011    Log((DEVICE_NAME ": VBoxUSBMonSolarisElectDriver: Manufacturer=%s Product=%s Serial=%s\n",
    10391012              USBFilterGetString(&Filter, USBFILTERIDX_MANUFACTURER_STR)  ? USBFilterGetString(&Filter, USBFILTERIDX_MANUFACTURER_STR)  : "<null>",
    10401013              USBFilterGetString(&Filter, USBFILTERIDX_PRODUCT_STR)       ? USBFilterGetString(&Filter, USBFILTERIDX_PRODUCT_STR)       : "<null>",
     
    10491022    if (Owner == NIL_RTPROCESS)
    10501023    {
    1051         Log((DEVICE_NAME ":No matching filters, device %#x:%#x uninteresting.\n", pDevDesc->idVendor, pDevDesc->idProduct));
     1024        Log((DEVICE_NAME ": VBoxUSBMonSolarisElectDriver: No matching filters, device %#x:%#x uninteresting\n",
     1025             pDevDesc->idVendor, pDevDesc->idProduct));
    10521026        return USB_FAILURE;
    10531027    }
    10541028
    10551029    *ppszDrv = ddi_strdup(VBOXUSB_DRIVER_NAME, KM_SLEEP);
    1056     LogRel((DEVICE_NAME ": Capturing %s %#x:%#x:%s\n", pDevStrings->usb_product ? pDevStrings->usb_product : "<Unnamed USB device>",
    1057                     pDevDesc->idVendor, pDevDesc->idProduct, pszDevicePath));
     1030    LogRel((DEVICE_NAME ": Capturing %s %s %#x:%#x:%s Bus=%d Port=%d\n",
     1031            pDevStrings->usb_mfg ? pDevStrings->usb_mfg : "<Unknown Manufacturer>",
     1032            pDevStrings->usb_product ? pDevStrings->usb_product : "<Unnamed USB device>",
     1033            pDevDesc->idVendor, pDevDesc->idProduct, pszDevicePath, Bus, Port));
    10581034    return USB_SUCCESS;
    10591035}
  • trunk/src/VBox/HostDrivers/VBoxUSB/solaris/include/usbai_private.h

    r33540 r59091  
    2424 */
    2525
    26 #ifndef _SYS_USB_USBA_USBAI_PRIVATE_H
    27 #define _SYS_USB_USBA_USBAI_PRIVATE_H
    28 
     26#ifndef    _SYS_USB_USBA_USBAI_PRIVATE_H
     27#define    _SYS_USB_USBA_USBAI_PRIVATE_H
    2928
    3029/*
     
    3433 *
    3534 * Status key:
    36  *      C = Remove from Sun client drivers before removing from this file
    37  *      D = May be needed by legacy (DDK) drivers.
     35 *    C = Remove from Sun client drivers before removing from this file
     36 *    D = May be needed by legacy (DDK) drivers.
    3837 */
    3938
    40 #ifdef  __cplusplus
     39#ifdef    __cplusplus
    4140extern "C" {
    4241#endif
     
    5150
    5251/*
    53  * **************************************************************************
    54  * Error and status definitions, and reporting functions
    55  * **************************************************************************
    56  */
    57 
    58 
    59 /*
    60  * convenience functions to get string corresponding to value
    61  * usb_cb_flags_name requires a workbuffer of sufficient length
    62  * for the concatenation of all strings as usb_cb_flags_t is a bit
    63  * mask
    64  *
    65  * Status: C and D
    66  */
    67 const char      *usb_str_cr(usb_cr_t cr);
    68 char            *usb_str_cb_flags(usb_cb_flags_t cb_flags,
    69                 char *buffer, size_t length);
    70 const char      *usb_str_pipe_state(usb_pipe_state_t state);
    71 const char      *usb_str_dev_state(int state);
    72 const char      *usb_str_rval(int rval);
    73 
    74 /* function convert a USB return value to an errno */
    75 int             usb_rval2errno(int rval);
    76 
    77 /*
    78  * **************************************************************************
    79  * Transfer-related definitions and functions
    80  * **************************************************************************
    81  */
    82 
    83 /* Status C and D for whole section. */
    84 
    85 /* Serialize callbacks per interface or device. */
    86 #define USB_FLAGS_SERIALIZED_CB 0x8000
    87 
    88 /* default timeout for control requests (in seconds) */
    89 #define USB_PIPE_TIMEOUT        3
    90 
    91 /*
    92  * usb_pipe_sync_ctrl_xfer():
    93  *      for simple synchronous control transactions this wrapper function
    94  *      will perform the allocation, xfer, and deallocation.
    95  *      USB_ATTRS_AUTOCLEARING will be enabled
    96  *
    97  * ARGUMENTS:
    98  *      dip             - pointer to clients devinfo.
    99  *      pipe_handle     - control pipe pipehandle (obtained via usb_pipe_open().
    100  *      bmRequestType   - characteristics of request.
    101  *      bRequest        - specific request.
    102  *      wValue          - varies according to request.
    103  *      wIndex          - index or offset.
    104  *      wLength         - number of bytes to xfer.
    105  *      data            - pointer to pointer to data
    106  *                        IN: HCD will allocate data
    107  *                        OUT: clients driver allocates data.
    108  *      attrs           - required request attributes.
    109  *      completion_reason - completion status.
    110  *      cb_flags        - request completions flags.
    111  *      flags           - none.
    112  *
    113  * RETURN VALUES:
    114  *      USB_SUCCESS     - request successfully executed.
    115  *      USB_FAILURE     - request failed.
    116  *
    117  * NOTES:
    118  * - in the case of failure, the client should check completion_reason and
    119  *   and cb_flags and determine further recovery action
    120  * - the client should check data and if non-zero, free the data on
    121  *   completion
    122  */
    123 int usb_pipe_sync_ctrl_xfer(
    124         dev_info_t      *dip,
    125         usb_pipe_handle_t pipe_handle,
    126         uchar_t         bmRequestType,
    127         uchar_t         bRequest,
    128         uint16_t        wValue,
    129         uint16_t        wIndex,
    130         uint16_t        wLength,
    131         mblk_t          **data,
    132         usb_req_attrs_t attrs,
    133         usb_cr_t        *completion_reason,
    134         usb_cb_flags_t  *cb_flags,
    135         usb_flags_t     flags);
    136 
    137 /*
    138  * **************************************************************************
    139  * Event registration / pre-suspend and post-resume handling
    140  * **************************************************************************
    141  */
    142 
    143 /* Status: C and D for whole section. */
    144 
    145 /*
    146  * Event registration info for both hotplug and pre-suspend/post-resume
    147  * callbacks.  Eventually pre-suspend and post-resume callbacks will not be
    148  * needed, so this is for this OS release only and will go away in a
    149  * subsequent release.
    150  */
    151 typedef struct usb_event {
    152         /* device disconnected/unplugged */
    153         int     (*disconnect_event_handler)(dev_info_t *dip);
    154 
    155         /* device reconnected */
    156         int     (*reconnect_event_handler)(dev_info_t *dip);
    157 
    158         /* notification that system is about to checkpoint */
    159         int     (*pre_suspend_event_handler)(dev_info_t *dip);
    160 
    161         /* notification that system resumed after a checkpoint */
    162         int     (*post_resume_event_handler)(dev_info_t *dip);
    163 } usb_event_t;
    164 
    165 /*
    166  * Event callbacks
    167  *      the callbacks should always return USB_SUCCESS.
    168  */
    169 int usb_register_event_cbs(
    170         dev_info_t      *dip,
    171         usb_event_t     *usb_evt_data,
    172         usb_flags_t     flags);
    173 
    174 void usb_unregister_event_cbs(
    175         dev_info_t      *dip,
    176         usb_event_t     *usb_evt_data);
    177 
    178 /*
    179  * USB CPR support
    180  *      A client driver must call this function in pre-suspend event handler
    181  *      to inform the USBA framework that it can't suspend because
    182  *      driver instance or device could not be quiesced.
    183  */
    184 void usb_fail_checkpoint(
    185         dev_info_t      *dip,
    186         usb_flags_t     flags);
    187 
    188 
    189 /*
    190  * **************************************************************************
    191  * Logging functions remaining Contracted Consolidation Private
    192  * **************************************************************************
    193  */
    194 
    195 /* Status: C and D for whole section. */
    196 
    197 /*
    19852 * Usb logging, debug and console message handling.
    19953 */
    20054typedef struct usb_log_handle *usb_log_handle_t;
    20155
    202 #define USB_LOG_L0      0       /* warnings, console & syslog buffer */
    203 #define USB_LOG_L1      1       /* errors, syslog buffer */
    204 #define USB_LOG_L2      2       /* recoverable errors, debug only */
    205 #define USB_LOG_L3      3       /* interesting data, debug only */
    206 #define USB_LOG_L4      4       /* tracing, debug only */
     56#define    USB_LOG_L0    0    /* warnings, console & syslog buffer */
     57#define    USB_LOG_L1    1    /* errors, syslog buffer */
     58#define    USB_LOG_L2    2    /* recoverable errors, debug only */
     59#define    USB_LOG_L3    3    /* interesting data, debug only */
     60#define    USB_LOG_L4    4    /* tracing, debug only */
    20761
    208 #ifdef DEBUG
    209 #define USB_DPRINTF_L4  usb_dprintf4
    210 #define USB_DPRINTF_L3  usb_dprintf3
     62#define    USB_CHK_BASIC  0             /* Empty mask.    Basics always done. */
     63#define    USB_CHK_SERIAL 0x00000001    /* Compare device serial numbers. */
     64#define    USB_CHK_CFG    0x00000002    /* Compare raw config clouds. */
     65#define    USB_CHK_VIDPID 0x00000004    /* Compare product and vendor ID. */
     66#define    USB_CHK_ALL    0xFFFFFFFF    /* Perform maximum checking. */
    21167
    212 /*PRINTFLIKE3*/
    213 void usb_dprintf4(
    214         uint_t          mask,
    215         usb_log_handle_t handle,
    216         char            *fmt, ...);
    217 /*PRINTFLIKE3*/
    218 void usb_dprintf3(
    219         uint_t          mask,
    220         usb_log_handle_t handle,
    221         char            *fmt, ...);
    222 #else
    223 #define USB_DPRINTF_L4 0 &&
    224 #define USB_DPRINTF_L3 0 &&
    225 #endif
    226 
    227 #define USB_DPRINTF_L2  usb_dprintf2
    228 #define USB_DPRINTF_L1  usb_dprintf1
    229 #define USB_DPRINTF_L0  usb_dprintf0
    230 
    231 /*PRINTFLIKE3*/
    232 void usb_dprintf2(
    233         uint_t          mask,
    234         usb_log_handle_t handle,
    235         char            *fmt, ...);
    236 /*PRINTFLIKE3*/
    237 void usb_dprintf1(
    238         uint_t          mask,
    239         usb_log_handle_t handle,
    240         char            *fmt, ...);
    241 /*PRINTFLIKE3*/
    242 void usb_dprintf0(
    243         uint_t          mask,
    244         usb_log_handle_t handle,
    245         char            *fmt, ...);
    246 
    247 usb_log_handle_t usb_alloc_log_hdl(
    248         dev_info_t      *dip,
    249         char            *name,
    250         uint_t          *errlevel,
    251         uint_t          *mask,
    252         uint_t          *instance_filter,
    253         usb_flags_t     flags);
    254 
    255 /* free the log handle */
    256 void usb_free_log_hdl(
    257         usb_log_handle_t handle);
    258 
    259 /* log message */
    260 /*PRINTFLIKE4*/
    261 int usb_log(
    262         usb_log_handle_t handle,
    263         uint_t          level,
    264         uint_t          mask,
    265         char            *fmt, ...);
    266 
    267 /*
    268  * usb_check_same_device:
    269  *      Check if the device connected to the port is the same as
    270  *      the previous device that was in the port.  The previous device is
    271  *      represented by the dip on record for the port.  Print a message
    272  *      if the device is different.  If device_string arg is not NULL, it is
    273  *      included in the message.  Can block.
    274  *
    275  * Arguments:
    276  *      dip                     - pointer to devinfo of the client
    277  *      log_handle              - handle to which messages are logged
    278  *      log_level               - one of USB_LOG_*
    279  *      log_mask                - logging mask
    280  *      check_mask              - one mask containing things to check:
    281  *                                      USB_CHK_BASIC: empty mask;
    282  *                                              these checks are always done.
    283  *                                      USB_CHK_SERIAL: check match on device
    284  *                                              serial number.
    285  *                                      USB_CHK_CFG: compare config clouds
    286  *                                              byte by byte
    287  *                                      USB_CHK_VIDPID: compare product
    288  *                                              and vendor ID
    289  *                                      USB_CHK_ALL: perform all checks
    290  *
    291  *                              NOTE: descr length and content always checked
    292  *      device_string           - Device string to appear in error message
    293  *
    294  * return values:
    295  *      USB_SUCCESS:            same device
    296  *      USB_INVALID_VERSION     not same device
    297  *      USB_FAILURE:            Failure processing request
    298  *      USB_INVALID_ARG:        dip is invalid
    299  */
    300 
    301 /* Checking bits for checks made by usb_check_same_device */
    302 #define USB_CHK_BASIC   0               /* Empty mask.  Basics always done. */
    303 #define USB_CHK_SERIAL  0x00000001      /* Compare device serial numbers. */
    304 #define USB_CHK_CFG     0x00000002      /* Compare raw config clouds. */
    305 #define USB_CHK_VIDPID  0x00000004      /* Compare product and vendor ID. */
    306 #define USB_CHK_ALL     0xFFFFFFFF      /* Perform maximum checking. */
    307 
    308 int usb_check_same_device(
    309         dev_info_t              *dip,
    310         usb_log_handle_t        log_handle,
    311         int                     log_level,
    312         int                     log_mask,
    313         uint_t                  check_mask,
    314         char                    *device_string);
    315 
    316 /*
    317  * **************************************************************************
    318  * Power management functions remaining Contracted Consolidation Private
    319  * **************************************************************************
    320  */
    321 
    322 /*
    323  * usb wrapper around pm_raise_power & pm_lower_power to allow for
    324  * non blocking behavior
    325  *
    326  * Arguments:
    327  *      dip             - pointer to devinfo node of client.
    328  *      comp            - component.
    329  *      level           - power level.
    330  *      flags           - USB_FLAGS_SLEEP:
    331  *                              wait for completion.
    332  *      cb              - function called on completion, may be NULL.
    333  *      arg             - callback argument.
    334  *      rval            - USB_SUCCESS or USB_FAILURE.
    335  *
    336  * Return Values:
    337  *      USB_SUCCESS     -  if no USB_FLAGS_SLEEP has been specified, the request
    338  *                         has been queued for async execution. If
    339  *                         USB_FLAGS_SLEEP has been specified, the raising or
    340  *                         lowering of power
    341  *                         succeeded.
    342  *      USB_FAILURE     -  request could not be queued or raising or lowering
    343  *                         of power failed.
    344  */
    345 
    346 /* Status: C and D */
    347 int usb_req_raise_power(
    348         dev_info_t      *dip,
    349         int             comp,
    350         int             level,
    351         void            (*cb)(void *arg, int rval),
    352         void            *arg,
    353         usb_flags_t     flags);
    354 
    355 /* Status: D */
    356 int usb_req_lower_power(
    357         dev_info_t      *dip,
    358         int             comp,
    359         int             level,
    360         void            (*cb)(void *arg, int rval),
    361         void            *arg,
    362         usb_flags_t     flags);
    363 
    364 /*
    365  * USB wrapper functions to set usb device power level.
    366  * Note : Power levels indicated here are USB power levels
    367  * and not OS power levels.
    368  *
    369  * Note that these were never implemented, and are noops.  However, they are
    370  * included here as the skeleton driver in DDK 0.8 and 0.9 mentioned them.
    371  *
    372  * Status: C and D.
    373  */
    374 int usb_set_device_pwrlvl0(
    375         dev_info_t      *dip);
    376 int usb_set_device_pwrlvl1(
    377         dev_info_t      *dip);
    378 int usb_set_device_pwrlvl2(
    379         dev_info_t      *dip);
    380 int usb_set_device_pwrlvl3(
    381         dev_info_t      *dip);
    382 
     68int usb_check_same_device(dev_info_t        *dip,
     69                          usb_log_handle_t   log_handle,
     70                          int                log_level,
     71                          int                log_mask,
     72                          uint_t             check_mask,
     73                          char              *device_string);
    38374
    38475/*
     
    39283/*
    39384 * opaque serialization handle.
    394  *      Used by all usb_serialization routines.
     85 *    Used by all usb_serialization routines.
    39586 *
    396  *      This handle is opaque to the client driver.
     87 *    This handle is opaque to the client driver.
    39788 */
    398 typedef struct usb_serialization        *usb_serialization_t;
     89typedef struct usb_serialization *usb_serialization_t;
    39990
    40091/*
    40192 * usb_init_serialization
    402  *      setup for serialization
     93 *    setup for serialization
    40394 *
    40495 * ARGUMENTS:
    405  *      s_dip           - devinfo pointer
    406  *      flag            - USB_INIT_SER_CHECK_SAME_THREAD
    407  *                        when set, usb_release_access() will
    408  *                        verify that the same thread releases
    409  *                        access. If not, a console warning will
    410  *                        be issued but access will be released
    411  *                        anyways.
     96 *    s_dip        - devinfo pointer
     97 *    flag         - USB_INIT_SER_CHECK_SAME_THREAD
     98 *                   when set, usb_release_access() will verify that the same
     99 *                   thread releases access. If not, a console warning will
     100 *                   be issued but access will be released anyways.
    412101 *
    413102 * RETURNS:
    414  *      usb_serialization handle
     103 *    usb_serialization handle
    415104 *
    416105 */
    417 usb_serialization_t usb_init_serialization(
    418         dev_info_t      *s_dip,
    419         uint_t          flag);
     106usb_serialization_t usb_init_serialization(dev_info_t    *s_dip,
     107                                           uint_t         flag);
    420108
    421 #define USB_INIT_SER_CHECK_SAME_THREAD  1
     109#define    USB_INIT_SER_CHECK_SAME_THREAD    1
    422110
    423111/* fini for serialization */
    424 void usb_fini_serialization(
    425         usb_serialization_t usb_serp);
     112void usb_fini_serialization(usb_serialization_t usb_serp);
    426113
    427114/*
    428  * Various ways of calling usb_serialize_access.  These correspond to
     115 * Various ways of calling usb_serialize_access. These correspond to
    429116 * their cv_*wait* function counterparts for usb_serialize_access.
    430117 */
    431 #define USB_WAIT                0
    432 #define USB_WAIT_SIG            1
    433 #define USB_TIMEDWAIT           2
    434 #define USB_TIMEDWAIT_SIG       3
     118#define USB_WAIT            0
     119#define USB_WAIT_SIG        1
     120#define USB_TIMEDWAIT       2
     121#define USB_TIMEDWAIT_SIG   3
    435122
    436123/*
    437124 * usb_serialize_access:
    438  *      acquire serialized access
    439  * ARGUMENTS:
    440  *      usb_serp        - usb_serialization handle
    441  *      how_to_wait     - Which cv_*wait* function to wait for condition.
    442  *                              USB_WAIT:               use cv_wait
    443  *                              USB_WAIT_SIG:           use cv_wait_sig
    444  *                              USB_TIMEDWAIT:          use cv_timedwait
    445  *                              USB_TIMEDWAIT_SIG:      use cv_timedwait_sig
    446  *      delta_timeout   - Time in ms from current time to timeout.  Checked
    447  *                        only if USB_TIMEDWAIT or USB_TIMEDWAIT_SIG
    448  *                        specified in how_to_wait.
    449  * RETURNS:
    450  *      Same as values returned by cv_*wait* functions,
    451  *      except for when how_to_wait == USB_WAIT, where 0 is always returned.
    452  *      For calls where a timeout or signal could be expected, use this value
    453  *      to tell whether a kill(2) signal or timeout occurred.
    454  */
    455 int usb_serialize_access(
    456         usb_serialization_t     usb_serp,
    457         uint_t                  how_to_wait,
    458         uint_t                  delta_timeout);
    459 
    460 /*
    461  * usb_try_serialize_access:
    462  *      try acquiring serialized access
     125 *    acquire serialized access
    463126 *
    464127 * ARGUMENTS:
    465  *      usb_serp        - usb_serialization handle
    466  *      flag            - unused
    467  *
     128 *    usb_serp      - usb_serialization handle
     129 *    how_to_wait   - Which cv_*wait* function to wait for condition.
     130 *       USB_WAIT:           use cv_wait
     131 *       USB_WAIT_SIG:       use cv_wait_sig
     132 *       USB_TIMEDWAIT:      use cv_timedwait
     133 *       USB_TIMEDWAIT_SIG:  use cv_timedwait_sig
     134 *    delta_timeout - Time in ms from current time to timeout.  Checked
     135 *                    only if USB_TIMEDWAIT or USB_TIMEDWAIT_SIG
     136 *                    specified in how_to_wait.
    468137 * RETURNS:
    469  *      USB_SUCCESS     - access has been acquired
    470  *      USB_FAILURE     - access has not been acquired
     138 *    Same as values returned by cv_*wait* functions,
     139 *    except for when how_to_wait == USB_WAIT, where 0 is always returned.
     140 *    For calls where a timeout or signal could be expected, use this value
     141 *    to tell whether a kill(2) signal or timeout occurred.
    471142 */
    472 int usb_try_serialize_access(usb_serialization_t usb_serp, uint_t flag);
     143int usb_serialize_access(usb_serialization_t    usb_serp,
     144                         uint_t                 how_to_wait,
     145                         uint_t                 delta_timeout);
    473146
    474147/*
    475148 * usb_release_access:
    476  *      release serialized access
     149 *    release serialized access
    477150 *
    478151 * ARGUMENTS:
    479  *      usb_serp        - usb_serialization handle
     152 *    usb_serp    - usb_serialization handle
    480153 */
    481154void usb_release_access(usb_serialization_t usb_serp);
    482 
    483 
    484 /*
    485  * **************************************************************************
    486  * Asynchronous functions remaining Contracted Consolidation Private
    487  * **************************************************************************
    488  */
    489 
    490 /* This whole section: status: C and D. */
    491 
    492 /* For async_req functions. */
    493 #define USB_FLAGS_NOQUEUE       0x200
    494 
    495 /*
    496  * Issue a request to the asynchronous request service
    497  * All async request functions return USB_SUCCESS or USB_FAILURE
    498  * Arguments:
    499  *      dip             - pointer to devinfo node
    500  *      func            - pointer of function to execute asynchronously
    501  *      arg             - argument to function
    502  *      flag            - USB_FLAGS_SLEEP or USB_FLAGS_NOSLEEP or
    503  *                        USB_FLAGS_NOQUEUE
    504  * Return Values:
    505  *      USB_SUCCESS     - function was scheduled
    506  *      USB_FAILURE     - function could not be scheduled
    507  *
    508  * Flag combinations:
    509  *      SLEEP           - block waiting for resources. always succeeds
    510  *      NOSLEEP         - do not wait for resources, may fail.
    511  *      NOSLEEP+NOQUEUE - do not wait for resources, do not queue
    512  *      SLEEP+NOQUEUE   - block waiting for resources but may still fail
    513  *                        if no thread available
    514  */
    515 int usb_async_req(
    516         dev_info_t      *dip,
    517         void            (*func)(void *),
    518         void            *arg,
    519         usb_flags_t     flag);
    520 
    521 
    522 /*
    523  * index for getting to usb_pipehandle_list in usba_device
    524  */
    525 uchar_t usb_get_ep_index(uint8_t ep_addr);
    526 
    527 /*
    528  * **************************************************************************
    529  * USB device driver registration and callback functions remaining
    530  * Contracted Project Private (for VirtualBox USB Device Capture)
    531  * **************************************************************************
    532  */
    533 
    534 #if 0       /* Uncomment this section if usbai.h doesn't have this these bits (required for snv < 123) */
    535 
    536 /*
    537  * getting the device strings of manufacturer, product and serial number
    538  */
    539 typedef struct usb_dev_str {
    540         char    *usb_mfg;       /* manufacturer string */
    541         char    *usb_product;   /* product string */
    542         char    *usb_serialno;  /* serial number string */
    543 } usb_dev_str_t;
    544 
    545 /*
    546  * It is the callback function type for capture driver.
    547  * Arguments:
    548  *      dev_descr       - pointer to device descriptor
    549  *      dev_str         - pointer to device strings
    550  *      path            - pointer to device physical path
    551  *      bus             - USB bus address
    552  *      port            - USB port number
    553  *      drv             - capture driver name.
    554  *                        It is returned by the callback func.
    555  * Return Values:
    556  *      USB_SUCCESS     - VirtualBox will capture the device
    557  *      USB_FAILURE     - VirtualBox will not capture the device
    558  */
    559 typedef int (*usb_dev_driver_callback_t)(
    560         usb_dev_descr_t *dev_descr,
    561         usb_dev_str_t   *dev_str,
    562         char            *path,
    563         int             bus,
    564         int             port,
    565         char            **drv,
    566         void            *reserved);
    567 
    568 /*
    569  * Register the callback function in the usba.
    570  * Argument:
    571  *      dip             - client driver's devinfo pointer
    572  *      cb              - callback function
    573  *
    574  * Return Values:
    575  *      USB_SUCCESS     - the registration was successful
    576  *      USB_FAILURE     - the registration failed
    577  */
    578 int usb_register_dev_driver(
    579         dev_info_t                      *dip,
    580         usb_dev_driver_callback_t       cb);
    581 
    582 /*
    583  * Unregister the callback function in the usba.
    584  */
    585 void usb_unregister_dev_driver(dev_info_t *dip);
    586 #endif
    587 
    588 
    589 #ifdef ALLOCB_TEST
    590 #define allocb(s, p) usba_test_allocb(s, p)
    591 mblk_t *usba_test_allocb(size_t, uint_t);
    592 #endif /* ALLOCB_TEST */
    593 
    594 /* create an USB style M_CTL message */
    595 mblk_t *usba_mk_mctl(struct iocblk, void *, size_t);
    596155
    597156#ifdef __cplusplus
     
    599158#endif
    600159
    601 #endif  /* _SYS_USB_USBA_USBAI_PRIVATE_H */
     160#endif    /* _SYS_USB_USBA_USBAI_PRIVATE_H */
     161
  • trunk/src/VBox/Main/src-server/solaris/USBProxyServiceSolaris.cpp

    r57358 r59091  
    262262                pCur->bPort = 0;
    263263
    264             char pathBuf[PATH_MAX];
    265             RTStrPrintf(pathBuf, sizeof(pathBuf), "%s", pszDevicePath);
    266             RTPathStripFilename(pathBuf);
    267 
    268264            char szBuf[PATH_MAX + 48];
    269             RTStrPrintf(szBuf, sizeof(szBuf), "%#x:%#x:%d:%s", pCur->idVendor, pCur->idProduct, pCur->bcdDevice, pathBuf);
     265            RTStrPrintf(szBuf, sizeof(szBuf), "%#x:%#x:%d:%s", pCur->idVendor, pCur->idProduct, pCur->bcdDevice, pszDevicePath);
    270266            pCur->pszAddress = RTStrDup(szBuf);
    271267
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