On 11/28/14 10:06, Klaus Espenlaub wrote:
Hi Hans Petter,

On 28.11.2014 09:46, Hans Petter Selasky wrote:
Hi,

I see that VirtualBOX has made some changes to the USB APIs recently,
not updating all the USB backends. Next time you plan to change
anything, can the VirtualBOX USB developers drop me an e-mail, so we
don't have this situation again!

Sorry that there have been some inconvenience, but it's unavoidable to
temporarily break a few things during the ongoing USB3/xHCI work on trunk.

The USB backend changes aren't finalized, there might be more to come.
We have a few cases which don't work (e.g. support for UASP), and it's
hard to predict how far the necessary changes have to ripple through.

Thank you!

Who can accept and review USB patches for the FreeBSD USB backend?

Easiest way is sending them to this mailing list, we'll apply them as
quickly as possible.

Cheers,
Klaus

Hi,

The attached patch fixes some issues with FreeBSD and the VirtualBOX USB backend:

Issue #1)
Change wrong callback area size from "sizeof(PUSBPROXYDEVFBSD)" into "sizeof(USBPROXYDEVFBSD)"

Issue #2)
Implement new "usbProxyFreeBSDWakeup" callback function.

Issue #3)
Don't free the private USB data in the USB close function.

Can you get the attached patch into your SVN trunk and send me a confirmation back? Thank you!

I see some more issues, which appear to be in the generic VirtualBox USB code.


BTW: UASP and USB 3.0 streams mode is somewhat controverisal in some circles. Not all USB 3.0 controllers support streams mode, and I think that a two pairs of regular BULK endpoints would provide more than enough performance for USB mass storage. I don't mind if you leave out streams support in VirtualBox ;-)

--HPS

--- src/VBox/Devices/USB/freebsd/USBProxyDevice-freebsd.cpp.orig	2014-11-21 16:22:08.000000000 +0100
+++ src/VBox/Devices/USB/freebsd/USBProxyDevice-freebsd.cpp	2014-11-28 17:25:16.000000000 +0100
@@ -52,6 +52,7 @@
 #include <iprt/asm.h>
 #include <iprt/string.h>
 #include <iprt/file.h>
+#include <iprt/pipe.h>
 #include "../USBProxyDevice.h"
 
 /** Maximum endpoints supported. */
@@ -95,12 +96,16 @@
 {
     /** The open file. */
     RTFILE                 hFile;
-    /** Software endpoint structures */
-    USBENDPOINTFBSD        aSwEndpoint[USBFBSD_MAXENDPOINTS];
     /** Flag whether an URB is cancelling. */
     bool                   fCancelling;
     /** Flag whether initialised or not */
     bool                   fInit;
+    /** Pipe handle for waking up - writing end. */
+    RTPIPE                 hPipeWakeupW;
+    /** Pipe handle for waking up - reading end. */
+    RTPIPE                 hPipeWakeupR;
+    /** Software endpoint structures */
+    USBENDPOINTFBSD        aSwEndpoint[USBFBSD_MAXENDPOINTS];
     /** Kernel endpoint structures */
     struct usb_fs_endpoint aHwEndpoint[USBFBSD_MAXENDPOINTS];
 } USBPROXYDEVFBSD, *PUSBPROXYDEVFBSD;
@@ -383,10 +388,17 @@
         rc = usbProxyFreeBSDFsInit(pProxyDev);
         if (RT_SUCCESS(rc))
         {
-            LogFlow(("usbProxyFreeBSDOpen(%p, %s): returns successfully hFile=%RTfile iActiveCfg=%d\n",
-                     pProxyDev, pszAddress, pDevFBSD->hFile, pProxyDev->iActiveCfg));
+            /*
+             * Create wakeup pipe.
+             */
+            rc = RTPipeCreate(&pDevFBSD->hPipeWakeupR, &pDevFBSD->hPipeWakeupW, 0);
+            if (RT_SUCCESS(rc))
+            {
+                LogFlow(("usbProxyFreeBSDOpen(%p, %s): returns successfully hFile=%RTfile iActiveCfg=%d\n",
+                         pProxyDev, pszAddress, pDevFBSD->hFile, pProxyDev->iActiveCfg));
 
-            return VINF_SUCCESS;
+                return VINF_SUCCESS;
+            }
         }
 
         RTFileClose(hFile);
@@ -449,12 +461,12 @@
 
     usbProxyFreeBSDFsUnInit(pProxyDev);
 
+    RTPipeClose(pDevFBSD->hPipeWakeupR);
+    RTPipeClose(pDevFBSD->hPipeWakeupW);
+
     RTFileClose(pDevFBSD->hFile);
     pDevFBSD->hFile = NIL_RTFILE;
 
-    RTMemFree(pDevFBSD);
-    pProxyDev->Backend.pv = NULL;
-
     LogFlow(("usbProxyFreeBSDClose: returns\n"));
 }
 
@@ -688,9 +700,10 @@
              pUrb, (unsigned)pUrb->EndPt, (unsigned)pUrb->enmDir));
 
     ep_num = pUrb->EndPt;
-
-    if ((pUrb->enmType != VUSBXFERTYPE_MSG) && (pUrb->enmDir == VUSBDIRECTION_IN))
+    if ((pUrb->enmType != VUSBXFERTYPE_MSG) && (pUrb->enmDir == VUSBDIRECTION_IN)) {
+        /* set IN-direction bit */
         ep_num |= 0x80;
+    }
 
     index = 0;
 
@@ -822,7 +835,7 @@
     PUSBENDPOINTFBSD pEndpointFBSD;
     PVUSBURB pUrb;
     struct usb_fs_complete UsbFsComplete;
-    struct pollfd PollFd;
+    struct pollfd pfd[2];
     int rc;
 
     LogFlow(("usbProxyFreeBSDUrbReap: pProxyDev=%p, cMillies=%u\n",
@@ -946,23 +959,38 @@
                  (unsigned)pEndpointFBSD->acbData[1]));
 
     }
-    else if (cMillies && rc == VERR_RESOURCE_BUSY)
+    else if (cMillies != 0 && rc == VERR_RESOURCE_BUSY)
     {
-        /* Poll for finished transfers */
-        PollFd.fd = RTFileToNative(pDevFBSD->hFile);
-        PollFd.events = POLLIN | POLLRDNORM;
-        PollFd.revents = 0;
-
-        rc = poll(&PollFd, 1, (cMillies == RT_INDEFINITE_WAIT) ? INFTIM : cMillies);
-        if (rc >= 1)
-        {
-            goto repeat;
-        }
-        else
+        for (;;)
         {
-            LogFlow(("usbProxyFreeBSDUrbReap: "
-                     "poll returned rc=%d\n", rc));
+            pfd[0].fd = RTFileToNative(pDevFBSD->hFile);
+            pfd[0].events = POLLIN | POLLRDNORM;
+            pfd[0].revents = 0;
+
+            pfd[1].fd = RTPipeToNative(pDevFBSD->hPipeWakeupR);
+            pfd[1].events = POLLIN | POLLRDNORM;
+            pfd[1].revents = 0;
+
+            rc = poll(pfd, 2, (cMillies == RT_INDEFINITE_WAIT) ? INFTIM : cMillies);
+            if (rc > 0)
+            {
+                if (pfd[1].revents & POLLIN)
+                {
+                    /* Got woken up, drain pipe. */
+                    uint8_t bRead;
+                    size_t cbIgnored = 0;
+                    RTPipeRead(pDevFBSD->hPipeWakeupR, &bRead, 1, &cbIgnored);
+                    /* Make sure we return from this function */
+                    cMillies = 0;
+                }
+                break;
+            }
+            if (rc == 0)
+                return NULL;
+            if (errno != EAGAIN)
+                return NULL;
         }
+        goto repeat;
     }
     return pUrb;
 }
@@ -984,6 +1012,16 @@
     return usbProxyFreeBSDEndpointClose(pProxyDev, index);
 }
 
+static DECLCALLBACK(int) usbProxyFreeBSDWakeup(PUSBPROXYDEV pProxyDev)
+{
+    PUSBPROXYDEVFBSD pDevFBSD = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVFBSD);
+    size_t cbIgnored;
+
+    LogFlowFunc(("pProxyDev=%p\n", pProxyDev));
+
+    return RTPipeWrite(pDevFBSD->hPipeWakeupW, "", 1, &cbIgnored);
+}
+
 /**
  * The FreeBSD USB Proxy Backend.
  */
@@ -992,7 +1030,7 @@
     /* pszName */
     "host",
     /* cbBackend */
-    sizeof(PUSBPROXYDEVFBSD),
+    sizeof(USBPROXYDEVFBSD),
     usbProxyFreeBSDOpen,
     usbProxyFreeBSDInit,
     usbProxyFreeBSDClose,
@@ -1005,6 +1043,7 @@
     usbProxyFreeBSDUrbQueue,
     usbProxyFreeBSDUrbCancel,
     usbProxyFreeBSDUrbReap,
+    usbProxyFreeBSDWakeup,
     0
 };
 
_______________________________________________
vbox-dev mailing list
[email protected]
https://www.virtualbox.org/mailman/listinfo/vbox-dev

Reply via email to