VirtualBox

source: vbox/trunk/src/VBox/Devices/USB/DrvVUSBRootHub.cpp@ 78046

Last change on this file since 78046 was 77000, checked in by vboxsync, 6 years ago

Devices/USB: Create the USB I/O thread for each device during the attach phase (as it was destructed during a detach) to fix a debug assertion when saving a VM state where the device gets reattached during the process

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 73.8 KB
Line 
1/* $Id: DrvVUSBRootHub.cpp 77000 2019-01-26 10:30:14Z vboxsync $ */
2/** @file
3 * Virtual USB - Root Hub Driver.
4 */
5
6/*
7 * Copyright (C) 2005-2019 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18
19/** @page pg_dev_vusb VUSB - Virtual USB
20 *
21 * @todo read thru this and correct typos. Merge with old docs.
22 *
23 *
24 * The Virtual USB component glues USB devices and host controllers together.
25 * The VUSB takes the form of a PDM driver which is attached to the HCI. USB
26 * devices are created by, attached to, and managed by the VUSB roothub. The
27 * VUSB also exposes an interface which is used by Main to attach and detach
28 * proxied USB devices.
29 *
30 *
31 * @section sec_dev_vusb_urb The Life of an URB
32 *
33 * The URB is created when the HCI calls the roothub (VUSB) method pfnNewUrb.
34 * VUSB has a pool of URBs, if no free URBs are available a new one is
35 * allocated. The returned URB starts life in the ALLOCATED state and all
36 * fields are initialized with sensible defaults.
37 *
38 * The HCI then copies any request data into the URB if it's an host2dev
39 * transfer. It then submits the URB by calling the pfnSubmitUrb roothub
40 * method.
41 *
42 * pfnSubmitUrb will start by checking if it knows the device address, and if
43 * it doesn't the URB is completed with a device-not-ready error. When the
44 * device address is known to it, action is taken based on the kind of
45 * transfer it is. There are four kinds of transfers: 1. control, 2. bulk,
46 * 3. interrupt, and 4. isochronous. In either case something eventually ends
47 * up being submitted to the device.
48 *
49 *
50 * If an URB fails submitting, may or may not be completed. This depends on
51 * heuristics in some cases and on the kind of failure in others. If
52 * pfnSubmitUrb returns a failure, the HCI should retry submitting it at a
53 * later time. If pfnSubmitUrb returns success the URB is submitted, and it
54 * can even been completed.
55 *
56 * The URB is in the IN_FLIGHT state from the time it's successfully submitted
57 * and till it's reaped or cancelled.
58 *
59 * When an URB transfer or in some case submit failure occurs, the pfnXferError
60 * callback of the HCI is consulted about what to do. If pfnXferError indicates
61 * that the URB should be retried, pfnSubmitUrb will fail. If it indicates that
62 * it should fail, the URB will be completed.
63 *
64 * Completing an URB means that the URB status is set and the HCI
65 * pfnXferCompletion callback is invoked with the URB. The HCI is the supposed
66 * to report the transfer status to the guest OS. After completion the URB
67 * is freed and returned to the pool, unless it was cancelled. If it was
68 * cancelled it will have to await reaping before it's actually freed.
69 *
70 *
71 * @subsection subsec_dev_vusb_urb_ctrl Control
72 *
73 * The control transfer is the most complex one, from VUSB's point of view,
74 * with its three stages and being bi-directional. A control transfer starts
75 * with a SETUP packet containing the request description and two basic
76 * parameters. It is followed by zero or more DATA packets which either picks
77 * up incoming data (dev2host) or supplies the request data (host2dev). This
78 * can then be followed by a STATUS packet which gets the status of the whole
79 * transfer.
80 *
81 * What makes the control transfer complicated is that for a host2dev request
82 * the URB is assembled from the SETUP and DATA stage, and for a dev2host
83 * request the returned data must be kept around for the DATA stage. For both
84 * transfer directions the status of the transfer has to be kept around for
85 * the STATUS stage.
86 *
87 * To complicate matters further, VUSB must intercept and in some cases emulate
88 * some of the standard requests in order to keep the virtual device state
89 * correct and provide the correct virtualization of a device.
90 *
91 * @subsection subsec_dev_vusb_urb_bulk Bulk and Interrupt
92 *
93 * The bulk and interrupt transfer types are relativly simple compared to the
94 * control transfer. VUSB is not inspecting the request content or anything,
95 * but passes it down the device.
96 *
97 * @subsection subsec_dev_vusb_urb_isoc Isochronous
98 *
99 * This kind of transfers hasn't yet been implemented.
100 *
101 */
102
103
104/** @page pg_dev_vusb_old VUSB - Virtual USB Core
105 *
106 * The virtual USB core is controlled by the roothub and the underlying HCI
107 * emulator, it is responsible for device addressing, managing configurations,
108 * interfaces and endpoints, assembling and splitting multi-part control
109 * messages and in general acts as a middle layer between the USB device
110 * emulation code and USB HCI emulation code.
111 *
112 * All USB devices are represented by a struct vusb_dev. This structure
113 * contains things like the device state, device address, all the configuration
114 * descriptors, the currently selected configuration and a mapping between
115 * endpoint addresses and endpoint descriptors.
116 *
117 * Each vusb_dev also has a pointer to a vusb_dev_ops structure which serves as
118 * the virtual method table and includes a virtual constructor and destructor.
119 * After a vusb_dev is created it may be attached to a hub device such as a
120 * roothub (using vusbHubAttach). Although each hub structure has cPorts
121 * and cDevices fields, it is the responsibility of the hub device to allocate
122 * a free port for the new device.
123 *
124 * Devices can chose one of two interfaces for dealing with requests, the
125 * synchronous interface or the asynchronous interface. The synchronous
126 * interface is much simpler and ought to be used for devices which are
127 * unlikely to sleep for long periods in order to serve requests. The
128 * asynchronous interface on the other hand is more difficult to use but is
129 * useful for the USB proxy or if one were to write a mass storage device
130 * emulator. Currently the synchronous interface only supports control and bulk
131 * endpoints and is no longer used by anything.
132 *
133 * In order to use the asynchronous interface, the queue_urb, cancel_urb and
134 * pfnUrbReap fields must be set in the devices vusb_dev_ops structure. The
135 * queue_urb method is used to submit a request to a device without blocking,
136 * it returns 1 if successful and 0 on any kind of failure. A successfully
137 * queued URB is completed when the pfnUrbReap method returns it. Each function
138 * address is reference counted so that pfnUrbReap will only be called if there
139 * are URBs outstanding. For a roothub to reap an URB from any one of it's
140 * devices, the vusbRhReapAsyncUrbs() function is used.
141 *
142 * There are four types of messages an URB may contain:
143 * -# Control - represents a single packet of a multi-packet control
144 * transfer, these are only really used by the host controller to
145 * submit the parts to the usb core.
146 * -# Message - the usb core assembles multiple control transfers in
147 * to single message transfers. In this case the data buffer
148 * contains the setup packet in little endian followed by the full
149 * buffer. In the case of an host-to-device control message, the
150 * message packet is created when the STATUS transfer is seen. In
151 * the case of device-to-host messages, the message packet is
152 * created after the SETUP transfer is seen. Also, certain control
153 * requests never go the real device and get handled synchronously.
154 * -# Bulk - Currently the only endpoint type that does error checking
155 * and endpoint halting.
156 * -# Interrupt - The only non-periodic type supported.
157 *
158 * Hubs are special cases of devices, they have a number of downstream ports
159 * that other devices can be attached to and removed from.
160 *
161 * After a device has been attached (vusbHubAttach):
162 * -# The hub attach method is called, which sends a hub status
163 * change message to the OS.
164 * -# The OS resets the device, and it appears on the default
165 * address with it's config 0 selected (a pseudo-config that
166 * contains only 1 interface with 1 endpoint - the default
167 * message pipe).
168 * -# The OS assigns the device a new address and selects an
169 * appropriate config.
170 * -# The device is ready.
171 *
172 * After a device has been detached (vusbDevDetach):
173 * -# All pending URBs are cancelled.
174 * -# The devices address is unassigned.
175 * -# The hub detach method is called which signals the OS
176 * of the status change.
177 * -# The OS unlinks the ED's for that device.
178 *
179 * A device can also request detachment from within its own methods by
180 * calling vusbDevUnplugged().
181 *
182 * Roothubs are responsible for driving the whole system, they are special
183 * cases of hubs and as such implement attach and detach methods, each one
184 * is described by a struct vusb_roothub. Once a roothub has submitted an
185 * URB to the USB core, a number of callbacks to the roothub are required
186 * for when the URB completes, since the roothub typically wants to inform
187 * the OS when transfers are completed.
188 *
189 * There are four callbacks to be concerned with:
190 * -# prepare - This is called after the URB is successfully queued.
191 * -# completion - This is called after the URB completed.
192 * -# error - This is called if the URB errored, some systems have
193 * automatic resubmission of failed requests, so this callback
194 * should keep track of the error count and return 1 if the count
195 * is above the number of allowed resubmissions.
196 * -# halt_ep - This is called after errors on bulk pipes in order
197 * to halt the pipe.
198 *
199 */
200
201
202/*********************************************************************************************************************************
203* Header Files *
204*********************************************************************************************************************************/
205#define LOG_GROUP LOG_GROUP_DRV_VUSB
206#include <VBox/vmm/pdm.h>
207#include <VBox/vmm/vmapi.h>
208#include <VBox/err.h>
209#include <iprt/alloc.h>
210#include <VBox/log.h>
211#include <iprt/time.h>
212#include <iprt/thread.h>
213#include <iprt/semaphore.h>
214#include <iprt/string.h>
215#include <iprt/assert.h>
216#include <iprt/asm.h>
217#include <iprt/uuid.h>
218#include "VUSBInternal.h"
219#include "VBoxDD.h"
220
221
222
223/**
224 * Attaches a device to a specific hub.
225 *
226 * This function is called by the vusb_add_device() and vusbRhAttachDevice().
227 *
228 * @returns VBox status code.
229 * @param pHub The hub to attach it to.
230 * @param pDev The device to attach.
231 * @thread EMT
232 */
233static int vusbHubAttach(PVUSBHUB pHub, PVUSBDEV pDev)
234{
235 LogFlow(("vusbHubAttach: pHub=%p[%s] pDev=%p[%s]\n", pHub, pHub->pszName, pDev, pDev->pUsbIns->pszName));
236 return vusbDevAttach(pDev, pHub);
237}
238
239
240/* -=-=-=-=-=- PDMUSBHUBREG methods -=-=-=-=-=- */
241
242/** @interface_method_impl{PDMUSBHUBREG,pfnAttachDevice} */
243static DECLCALLBACK(int) vusbPDMHubAttachDevice(PPDMDRVINS pDrvIns, PPDMUSBINS pUsbIns, const char *pszCaptureFilename, uint32_t *piPort)
244{
245 PVUSBROOTHUB pThis = PDMINS_2_DATA(pDrvIns, PVUSBROOTHUB);
246
247 /*
248 * Allocate a new VUSB device and initialize it.
249 */
250 PVUSBDEV pDev = (PVUSBDEV)RTMemAllocZ(sizeof(*pDev));
251 AssertReturn(pDev, VERR_NO_MEMORY);
252 int rc = vusbDevInit(pDev, pUsbIns, pszCaptureFilename);
253 if (RT_SUCCESS(rc))
254 {
255 pUsbIns->pvVUsbDev2 = pDev;
256 rc = vusbHubAttach(&pThis->Hub, pDev);
257 if (RT_SUCCESS(rc))
258 {
259 *piPort = UINT32_MAX; /// @todo implement piPort
260 return rc;
261 }
262
263 RTMemFree(pDev->paIfStates);
264 pUsbIns->pvVUsbDev2 = NULL;
265 }
266 vusbDevRelease(pDev);
267 return rc;
268}
269
270
271/** @interface_method_impl{PDMUSBHUBREG,pfnDetachDevice} */
272static DECLCALLBACK(int) vusbPDMHubDetachDevice(PPDMDRVINS pDrvIns, PPDMUSBINS pUsbIns, uint32_t iPort)
273{
274 RT_NOREF(pDrvIns, iPort);
275 PVUSBDEV pDev = (PVUSBDEV)pUsbIns->pvVUsbDev2;
276 Assert(pDev);
277
278 /*
279 * Deal with pending async reset.
280 * (anything but reset)
281 */
282 vusbDevSetStateCmp(pDev, VUSB_DEVICE_STATE_DEFAULT, VUSB_DEVICE_STATE_RESET);
283
284 /*
285 * Detach and free resources.
286 */
287 if (pDev->pHub)
288 vusbDevDetach(pDev);
289
290 vusbDevRelease(pDev);
291 return VINF_SUCCESS;
292}
293
294/**
295 * The hub registration structure.
296 */
297static const PDMUSBHUBREG g_vusbHubReg =
298{
299 PDM_USBHUBREG_VERSION,
300 vusbPDMHubAttachDevice,
301 vusbPDMHubDetachDevice,
302 PDM_USBHUBREG_VERSION
303};
304
305
306/* -=-=-=-=-=- VUSBIROOTHUBCONNECTOR methods -=-=-=-=-=- */
307
308
309/**
310 * Finds an device attached to a roothub by it's address.
311 *
312 * @returns Pointer to the device.
313 * @returns NULL if not found.
314 * @param pRh Pointer to the root hub.
315 * @param Address The device address.
316 */
317static PVUSBDEV vusbRhFindDevByAddress(PVUSBROOTHUB pRh, uint8_t Address)
318{
319 unsigned iHash = vusbHashAddress(Address);
320 PVUSBDEV pDev = NULL;
321
322 RTCritSectEnter(&pRh->CritSectDevices);
323 for (PVUSBDEV pCur = pRh->apAddrHash[iHash]; pCur; pCur = pCur->pNextHash)
324 if (pCur->u8Address == Address)
325 {
326 pDev = pCur;
327 break;
328 }
329
330 if (pDev)
331 vusbDevRetain(pDev);
332 RTCritSectLeave(&pRh->CritSectDevices);
333 return pDev;
334}
335
336
337/**
338 * Callback for freeing an URB.
339 * @param pUrb The URB to free.
340 */
341static DECLCALLBACK(void) vusbRhFreeUrb(PVUSBURB pUrb)
342{
343 /*
344 * Assert sanity.
345 */
346 vusbUrbAssert(pUrb);
347 PVUSBROOTHUB pRh = (PVUSBROOTHUB)pUrb->pVUsb->pvFreeCtx;
348 Assert(pRh);
349
350 Assert(pUrb->enmState != VUSBURBSTATE_FREE);
351
352 /*
353 * Free the URB description (logging builds only).
354 */
355 if (pUrb->pszDesc)
356 {
357 RTStrFree(pUrb->pszDesc);
358 pUrb->pszDesc = NULL;
359 }
360
361 /* The URB comes from the roothub if there is no device (invalid address). */
362 if (pUrb->pVUsb->pDev)
363 {
364 PVUSBDEV pDev = pUrb->pVUsb->pDev;
365
366 vusbUrbPoolFree(&pUrb->pVUsb->pDev->UrbPool, pUrb);
367 vusbDevRelease(pDev);
368 }
369 else
370 vusbUrbPoolFree(&pRh->Hub.Dev.UrbPool, pUrb);
371}
372
373
374/**
375 * Worker routine for vusbRhConnNewUrb().
376 */
377static PVUSBURB vusbRhNewUrb(PVUSBROOTHUB pRh, uint8_t DstAddress, PVUSBDEV pDev, VUSBXFERTYPE enmType,
378 VUSBDIRECTION enmDir, uint32_t cbData, uint32_t cTds, const char *pszTag)
379{
380 RT_NOREF(pszTag);
381 PVUSBURBPOOL pUrbPool = &pRh->Hub.Dev.UrbPool;
382
383 if (!pDev)
384 pDev = vusbRhFindDevByAddress(pRh, DstAddress);
385 else
386 vusbDevRetain(pDev);
387
388 if (pDev)
389 pUrbPool = &pDev->UrbPool;
390
391 PVUSBURB pUrb = vusbUrbPoolAlloc(pUrbPool, enmType, enmDir, cbData,
392 pRh->cbHci, pRh->cbHciTd, cTds);
393 if (RT_LIKELY(pUrb))
394 {
395 pUrb->pVUsb->pvFreeCtx = pRh;
396 pUrb->pVUsb->pfnFree = vusbRhFreeUrb;
397 pUrb->DstAddress = DstAddress;
398 pUrb->pVUsb->pDev = pDev;
399
400#ifdef LOG_ENABLED
401 const char *pszType = NULL;
402
403 switch(pUrb->enmType)
404 {
405 case VUSBXFERTYPE_CTRL:
406 pszType = "ctrl";
407 break;
408 case VUSBXFERTYPE_INTR:
409 pszType = "intr";
410 break;
411 case VUSBXFERTYPE_BULK:
412 pszType = "bulk";
413 break;
414 case VUSBXFERTYPE_ISOC:
415 pszType = "isoc";
416 break;
417 default:
418 pszType = "invld";
419 break;
420 }
421
422 pRh->iSerial = (pRh->iSerial + 1) % 10000;
423 RTStrAPrintf(&pUrb->pszDesc, "URB %p %s%c%04d (%s)", pUrb, pszType,
424 (pUrb->enmDir == VUSBDIRECTION_IN) ? '<' : ((pUrb->enmDir == VUSBDIRECTION_SETUP) ? 's' : '>'),
425 pRh->iSerial, pszTag ? pszTag : "<none>");
426#endif
427 }
428
429 return pUrb;
430}
431
432
433/**
434 * Calculate frame timer variables given a frame rate.
435 */
436static void vusbRhR3CalcTimerIntervals(PVUSBROOTHUB pThis, uint32_t u32FrameRate)
437{
438 pThis->nsWait = RT_NS_1SEC / u32FrameRate;
439 pThis->uFrameRate = u32FrameRate;
440 /* Inform the HCD about the new frame rate. */
441 pThis->pIRhPort->pfnFrameRateChanged(pThis->pIRhPort, u32FrameRate);
442}
443
444
445/**
446 * Calculates the new frame rate based on the idle detection and number of idle
447 * cycles.
448 *
449 * @returns nothing.
450 * @param pThis The roothub instance data.
451 * @param fIdle Flag whether the last frame didn't produce any activity.
452 */
453static void vusbRhR3FrameRateCalcNew(PVUSBROOTHUB pThis, bool fIdle)
454{
455 uint32_t uNewFrameRate = pThis->uFrameRate;
456
457 /*
458 * Adjust the frame timer interval based on idle detection.
459 */
460 if (fIdle)
461 {
462 pThis->cIdleCycles++;
463 /* Set the new frame rate based on how long we've been idle. Tunable. */
464 switch (pThis->cIdleCycles)
465 {
466 case 4: uNewFrameRate = 500; break; /* 2ms interval */
467 case 16:uNewFrameRate = 125; break; /* 8ms interval */
468 case 24:uNewFrameRate = 50; break; /* 20ms interval */
469 default: break;
470 }
471 /* Avoid overflow. */
472 if (pThis->cIdleCycles > 60000)
473 pThis->cIdleCycles = 20000;
474 }
475 else
476 {
477 if (pThis->cIdleCycles)
478 {
479 pThis->cIdleCycles = 0;
480 uNewFrameRate = pThis->uFrameRateDefault;
481 }
482 }
483
484 if ( uNewFrameRate != pThis->uFrameRate
485 && uNewFrameRate)
486 {
487 LogFlow(("Frame rate changed from %u to %u\n", pThis->uFrameRate, uNewFrameRate));
488 vusbRhR3CalcTimerIntervals(pThis, uNewFrameRate);
489 }
490}
491
492
493/**
494 * The core frame processing routine keeping track of the elapsed time and calling into
495 * the device emulation above us to do the work.
496 *
497 * @returns Relative timespan when to process the next frame.
498 * @param pThis The roothub instance data.
499 * @param fCallback Flag whether this method is called from the URB completion callback or
500 * from the worker thread (only used for statistics).
501 */
502DECLHIDDEN(uint64_t) vusbRhR3ProcessFrame(PVUSBROOTHUB pThis, bool fCallback)
503{
504 uint64_t tsNext = 0;
505 uint64_t tsNanoStart = RTTimeNanoTS();
506
507 /* Don't do anything if we are not supposed to process anything (EHCI and XHCI). */
508 if (!pThis->uFrameRateDefault)
509 return 0;
510
511 if (ASMAtomicXchgBool(&pThis->fFrameProcessing, true))
512 return pThis->nsWait;
513
514 if ( tsNanoStart > pThis->tsFrameProcessed
515 && tsNanoStart - pThis->tsFrameProcessed >= 750 * RT_NS_1US)
516 {
517 LogFlowFunc(("Starting new frame at ts %llu\n", tsNanoStart));
518
519 bool fIdle = pThis->pIRhPort->pfnStartFrame(pThis->pIRhPort, 0 /* u32FrameNo */);
520 vusbRhR3FrameRateCalcNew(pThis, fIdle);
521
522 uint64_t tsNow = RTTimeNanoTS();
523 tsNext = (tsNanoStart + pThis->nsWait) > tsNow ? (tsNanoStart + pThis->nsWait) - tsNow : 0;
524 pThis->tsFrameProcessed = tsNanoStart;
525 LogFlowFunc(("Current frame took %llu nano seconds to process, next frame in %llu ns\n", tsNow - tsNanoStart, tsNext));
526 if (fCallback)
527 STAM_COUNTER_INC(&pThis->StatFramesProcessedClbk);
528 else
529 STAM_COUNTER_INC(&pThis->StatFramesProcessedThread);
530 }
531 else
532 {
533 tsNext = (pThis->tsFrameProcessed + pThis->nsWait) > tsNanoStart ? (pThis->tsFrameProcessed + pThis->nsWait) - tsNanoStart : 0;
534 LogFlowFunc(("Next frame is too far away in the future, waiting... (tsNanoStart=%llu tsFrameProcessed=%llu)\n",
535 tsNanoStart, pThis->tsFrameProcessed));
536 }
537
538 ASMAtomicXchgBool(&pThis->fFrameProcessing, false);
539 LogFlowFunc(("returns %llu\n", tsNext));
540 return tsNext;
541}
542
543
544/**
545 * Worker for processing frames periodically.
546 *
547 * @returns VBox status code.
548 * @param pDrvIns The driver instance.
549 * @param pThread The PDM thread structure for the thread this worker runs on.
550 */
551static DECLCALLBACK(int) vusbRhR3PeriodFrameWorker(PPDMDRVINS pDrvIns, PPDMTHREAD pThread)
552{
553 RT_NOREF(pDrvIns);
554 int rc = VINF_SUCCESS;
555 PVUSBROOTHUB pThis = (PVUSBROOTHUB)pThread->pvUser;
556
557 if (pThread->enmState == PDMTHREADSTATE_INITIALIZING)
558 return VINF_SUCCESS;
559
560 while (pThread->enmState == PDMTHREADSTATE_RUNNING)
561 {
562 while ( !ASMAtomicReadU32(&pThis->uFrameRateDefault)
563 && pThread->enmState == PDMTHREADSTATE_RUNNING)
564 {
565 /* Signal the waiter that we are stopped now. */
566 rc = RTSemEventMultiSignal(pThis->hSemEventPeriodFrameStopped);
567 AssertRC(rc);
568
569 rc = RTSemEventMultiWait(pThis->hSemEventPeriodFrame, RT_INDEFINITE_WAIT);
570 RTSemEventMultiReset(pThis->hSemEventPeriodFrame);
571
572 /*
573 * Notify the device above about the frame rate changed if we are supposed to
574 * process frames.
575 */
576 uint32_t uFrameRate = ASMAtomicReadU32(&pThis->uFrameRateDefault);
577 if (uFrameRate)
578 vusbRhR3CalcTimerIntervals(pThis, uFrameRate);
579 }
580
581 AssertLogRelMsgReturn(RT_SUCCESS(rc) || rc == VERR_TIMEOUT, ("%Rrc\n", rc), rc);
582 if (RT_UNLIKELY(pThread->enmState != PDMTHREADSTATE_RUNNING))
583 break;
584
585 uint64_t tsNext = vusbRhR3ProcessFrame(pThis, false /* fCallback */);
586
587 if (tsNext >= 250 * RT_NS_1US)
588 {
589 rc = RTSemEventMultiWaitEx(pThis->hSemEventPeriodFrame, RTSEMWAIT_FLAGS_RELATIVE | RTSEMWAIT_FLAGS_NANOSECS | RTSEMWAIT_FLAGS_UNINTERRUPTIBLE,
590 tsNext);
591 AssertLogRelMsg(RT_SUCCESS(rc) || rc == VERR_TIMEOUT, ("%Rrc\n", rc));
592 RTSemEventMultiReset(pThis->hSemEventPeriodFrame);
593 }
594 }
595
596 return VINF_SUCCESS;
597}
598
599
600/**
601 * Unblock the periodic frame thread so it can respond to a state change.
602 *
603 * @returns VBox status code.
604 * @param pDrvIns The driver instance.
605 * @param pThread The send thread.
606 */
607static DECLCALLBACK(int) vusbRhR3PeriodFrameWorkerWakeup(PPDMDRVINS pDrvIns, PPDMTHREAD pThread)
608{
609 RT_NOREF(pThread);
610 PVUSBROOTHUB pThis = PDMINS_2_DATA(pDrvIns, PVUSBROOTHUB);
611 return RTSemEventMultiSignal(pThis->hSemEventPeriodFrame);
612}
613
614
615/** @interface_method_impl{VUSBIROOTHUBCONNECTOR,pfnSetUrbParams} */
616static DECLCALLBACK(int) vusbRhSetUrbParams(PVUSBIROOTHUBCONNECTOR pInterface, size_t cbHci, size_t cbHciTd)
617{
618 PVUSBROOTHUB pRh = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
619
620 pRh->cbHci = cbHci;
621 pRh->cbHciTd = cbHciTd;
622
623 return VINF_SUCCESS;
624}
625
626
627/** @interface_method_impl{VUSBIROOTHUBCONNECTOR,pfnNewUrb} */
628static DECLCALLBACK(PVUSBURB) vusbRhConnNewUrb(PVUSBIROOTHUBCONNECTOR pInterface, uint8_t DstAddress, PVUSBIDEVICE pDev, VUSBXFERTYPE enmType,
629 VUSBDIRECTION enmDir, uint32_t cbData, uint32_t cTds, const char *pszTag)
630{
631 PVUSBROOTHUB pRh = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
632 return vusbRhNewUrb(pRh, DstAddress, (PVUSBDEV)pDev, enmType, enmDir, cbData, cTds, pszTag);
633}
634
635
636/** @interface_method_impl{VUSBIROOTHUBCONNECTOR,pfnFreeUrb} */
637static DECLCALLBACK(int) vusbRhConnFreeUrb(PVUSBIROOTHUBCONNECTOR pInterface, PVUSBURB pUrb)
638{
639 RT_NOREF(pInterface);
640 pUrb->pVUsb->pfnFree(pUrb);
641 return VINF_SUCCESS;
642}
643
644
645/** @interface_method_impl{VUSBIROOTHUBCONNECTOR,pfnSubmitUrb} */
646static DECLCALLBACK(int) vusbRhSubmitUrb(PVUSBIROOTHUBCONNECTOR pInterface, PVUSBURB pUrb, PPDMLED pLed)
647{
648 PVUSBROOTHUB pRh = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
649 STAM_PROFILE_START(&pRh->StatSubmitUrb, a);
650
651#ifdef VBOX_WITH_STATISTICS
652 /*
653 * Total and per-type submit statistics.
654 */
655 Assert(pUrb->enmType >= 0 && pUrb->enmType < (int)RT_ELEMENTS(pRh->aTypes));
656 STAM_COUNTER_INC(&pRh->Total.StatUrbsSubmitted);
657 STAM_COUNTER_INC(&pRh->aTypes[pUrb->enmType].StatUrbsSubmitted);
658
659 STAM_COUNTER_ADD(&pRh->Total.StatReqBytes, pUrb->cbData);
660 STAM_COUNTER_ADD(&pRh->aTypes[pUrb->enmType].StatReqBytes, pUrb->cbData);
661 if (pUrb->enmDir == VUSBDIRECTION_IN)
662 {
663 STAM_COUNTER_ADD(&pRh->Total.StatReqReadBytes, pUrb->cbData);
664 STAM_COUNTER_ADD(&pRh->aTypes[pUrb->enmType].StatReqReadBytes, pUrb->cbData);
665 }
666 else
667 {
668 STAM_COUNTER_ADD(&pRh->Total.StatReqWriteBytes, pUrb->cbData);
669 STAM_COUNTER_ADD(&pRh->aTypes[pUrb->enmType].StatReqWriteBytes, pUrb->cbData);
670 }
671
672 if (pUrb->enmType == VUSBXFERTYPE_ISOC)
673 {
674 STAM_COUNTER_ADD(&pRh->StatIsocReqPkts, pUrb->cIsocPkts);
675 if (pUrb->enmDir == VUSBDIRECTION_IN)
676 STAM_COUNTER_ADD(&pRh->StatIsocReqReadPkts, pUrb->cIsocPkts);
677 else
678 STAM_COUNTER_ADD(&pRh->StatIsocReqWritePkts, pUrb->cIsocPkts);
679 }
680#endif
681
682 /* If there is a sniffer on the roothub record the URB there. */
683 if (pRh->hSniffer != VUSBSNIFFER_NIL)
684 {
685 int rc = VUSBSnifferRecordEvent(pRh->hSniffer, pUrb, VUSBSNIFFEREVENT_SUBMIT);
686 if (RT_FAILURE(rc))
687 LogRel(("VUSB: Capturing URB submit event on the root hub failed with %Rrc\n", rc));
688 }
689
690 /*
691 * The device was resolved when we allocated the URB.
692 * Submit it to the device if we found it, if not fail with device-not-ready.
693 */
694 int rc;
695 if ( pUrb->pVUsb->pDev
696 && pUrb->pVUsb->pDev->pUsbIns)
697 {
698 switch (pUrb->enmDir)
699 {
700 case VUSBDIRECTION_IN:
701 pLed->Asserted.s.fReading = pLed->Actual.s.fReading = 1;
702 rc = vusbUrbSubmit(pUrb);
703 pLed->Actual.s.fReading = 0;
704 break;
705 case VUSBDIRECTION_OUT:
706 pLed->Asserted.s.fWriting = pLed->Actual.s.fWriting = 1;
707 rc = vusbUrbSubmit(pUrb);
708 pLed->Actual.s.fWriting = 0;
709 break;
710 default:
711 rc = vusbUrbSubmit(pUrb);
712 break;
713 }
714
715 if (RT_FAILURE(rc))
716 {
717 LogFlow(("vusbRhSubmitUrb: freeing pUrb=%p\n", pUrb));
718 pUrb->pVUsb->pfnFree(pUrb);
719 }
720 }
721 else
722 {
723 vusbDevRetain(&pRh->Hub.Dev);
724 pUrb->pVUsb->pDev = &pRh->Hub.Dev;
725 Log(("vusb: pRh=%p: SUBMIT: Address %i not found!!!\n", pRh, pUrb->DstAddress));
726
727 pUrb->enmState = VUSBURBSTATE_REAPED;
728 pUrb->enmStatus = VUSBSTATUS_DNR;
729 vusbUrbCompletionRh(pUrb);
730 rc = VINF_SUCCESS;
731 }
732
733 STAM_PROFILE_STOP(&pRh->StatSubmitUrb, a);
734 return rc;
735}
736
737
738static DECLCALLBACK(int) vusbRhReapAsyncUrbsWorker(PVUSBDEV pDev, RTMSINTERVAL cMillies)
739{
740 if (!cMillies)
741 vusbUrbDoReapAsync(&pDev->LstAsyncUrbs, 0);
742 else
743 {
744 uint64_t u64Start = RTTimeMilliTS();
745 do
746 {
747 vusbUrbDoReapAsync(&pDev->LstAsyncUrbs, RT_MIN(cMillies >> 8, 10));
748 } while ( !RTListIsEmpty(&pDev->LstAsyncUrbs)
749 && RTTimeMilliTS() - u64Start < cMillies);
750 }
751
752 return VINF_SUCCESS;
753}
754
755/** @interface_method_impl{VUSBIROOTHUBCONNECTOR,pfnReapAsyncUrbs} */
756static DECLCALLBACK(void) vusbRhReapAsyncUrbs(PVUSBIROOTHUBCONNECTOR pInterface, PVUSBIDEVICE pDevice, RTMSINTERVAL cMillies)
757{
758 PVUSBROOTHUB pRh = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface); NOREF(pRh);
759 PVUSBDEV pDev = (PVUSBDEV)pDevice;
760
761 if (RTListIsEmpty(&pDev->LstAsyncUrbs))
762 return;
763
764 STAM_PROFILE_START(&pRh->StatReapAsyncUrbs, a);
765 int rc = vusbDevIoThreadExecSync(pDev, (PFNRT)vusbRhReapAsyncUrbsWorker, 2, pDev, cMillies);
766 AssertRC(rc);
767 STAM_PROFILE_STOP(&pRh->StatReapAsyncUrbs, a);
768}
769
770
771/** @interface_method_impl{VUSBIROOTHUBCONNECTOR,pfnCancelUrbsEp} */
772static DECLCALLBACK(int) vusbRhCancelUrbsEp(PVUSBIROOTHUBCONNECTOR pInterface, PVUSBURB pUrb)
773{
774 PVUSBROOTHUB pRh = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
775 AssertReturn(pRh, VERR_INVALID_PARAMETER);
776 AssertReturn(pUrb, VERR_INVALID_PARAMETER);
777
778 /// @todo This method of URB canceling may not work on non-Linux hosts.
779 /*
780 * Cancel and reap the URB(s) on an endpoint.
781 */
782 LogFlow(("vusbRhCancelUrbsEp: pRh=%p pUrb=%p\n", pRh, pUrb));
783
784 vusbUrbCancelAsync(pUrb, CANCELMODE_UNDO);
785
786 /* The reaper thread will take care of completing the URB. */
787
788 return VINF_SUCCESS;
789}
790
791/**
792 * Worker doing the actual cancelling of all outstanding URBs on the device I/O thread.
793 *
794 * @returns VBox status code.
795 * @param pDev USB device instance data.
796 */
797static DECLCALLBACK(int) vusbRhCancelAllUrbsWorker(PVUSBDEV pDev)
798{
799 /*
800 * Cancel the URBS.
801 *
802 * Not using th CritAsyncUrbs critical section here is safe
803 * as the I/O thread is the only thread accessing this struture at the
804 * moment.
805 */
806 PVUSBURBVUSB pVUsbUrb, pVUsbUrbNext;
807 RTListForEachSafe(&pDev->LstAsyncUrbs, pVUsbUrb, pVUsbUrbNext, VUSBURBVUSBINT, NdLst)
808 {
809 PVUSBURB pUrb = pVUsbUrb->pUrb;
810 /* Call the worker directly. */
811 vusbUrbCancelWorker(pUrb, CANCELMODE_FAIL);
812 }
813
814 return VINF_SUCCESS;
815}
816
817/** @interface_method_impl{VUSBIROOTHUBCONNECTOR,pfnCancelAllUrbs} */
818static DECLCALLBACK(void) vusbRhCancelAllUrbs(PVUSBIROOTHUBCONNECTOR pInterface)
819{
820 PVUSBROOTHUB pRh = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
821
822 RTCritSectEnter(&pRh->CritSectDevices);
823 PVUSBDEV pDev = pRh->pDevices;
824 while (pDev)
825 {
826 vusbDevIoThreadExecSync(pDev, (PFNRT)vusbRhCancelAllUrbsWorker, 1, pDev);
827 pDev = pDev->pNext;
828 }
829 RTCritSectLeave(&pRh->CritSectDevices);
830}
831
832/**
833 * Worker doing the actual cancelling of all outstanding per-EP URBs on the
834 * device I/O thread.
835 *
836 * @returns VBox status code.
837 * @param pDev USB device instance data.
838 * @param EndPt Endpoint number.
839 * @param enmDir Endpoint direction.
840 */
841static DECLCALLBACK(int) vusbRhAbortEpWorker(PVUSBDEV pDev, int EndPt, VUSBDIRECTION enmDir)
842{
843 /*
844 * Iterate the URBs, find ones corresponding to given EP, and cancel them.
845 */
846 PVUSBURBVUSB pVUsbUrb, pVUsbUrbNext;
847 RTListForEachSafe(&pDev->LstAsyncUrbs, pVUsbUrb, pVUsbUrbNext, VUSBURBVUSBINT, NdLst)
848 {
849 PVUSBURB pUrb = pVUsbUrb->pUrb;
850
851 Assert(pUrb->pVUsb->pDev == pDev);
852
853 /* For the default control EP, direction does not matter. */
854 if (pUrb->EndPt == EndPt && (pUrb->enmDir == enmDir || !EndPt))
855 {
856 LogFlow(("%s: vusbRhAbortEpWorker: CANCELING URB\n", pUrb->pszDesc));
857 int rc = vusbUrbCancelWorker(pUrb, CANCELMODE_UNDO);
858 AssertRC(rc);
859 }
860 }
861
862 return VINF_SUCCESS;
863}
864
865
866/** @interface_method_impl{VUSBIROOTHUBCONNECTOR,pfnAbortEp} */
867static DECLCALLBACK(int) vusbRhAbortEp(PVUSBIROOTHUBCONNECTOR pInterface, PVUSBIDEVICE pDevice, int EndPt, VUSBDIRECTION enmDir)
868{
869 PVUSBROOTHUB pRh = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
870 if (&pRh->Hub != ((PVUSBDEV)pDevice)->pHub)
871 AssertFailedReturn(VERR_INVALID_PARAMETER);
872
873 RTCritSectEnter(&pRh->CritSectDevices);
874 PVUSBDEV pDev = (PVUSBDEV)pDevice;
875 vusbDevIoThreadExecSync(pDev, (PFNRT)vusbRhAbortEpWorker, 3, pDev, EndPt, enmDir);
876 RTCritSectLeave(&pRh->CritSectDevices);
877
878 /* The reaper thread will take care of completing the URB. */
879
880 return VINF_SUCCESS;
881}
882
883
884/** @interface_method_impl{VUSBIROOTHUBCONNECTOR,pfnAttachDevice} */
885static DECLCALLBACK(int) vusbRhAttachDevice(PVUSBIROOTHUBCONNECTOR pInterface, PVUSBIDEVICE pDevice)
886{
887 PVUSBROOTHUB pRh = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
888 return vusbHubAttach(&pRh->Hub, (PVUSBDEV)pDevice);
889}
890
891
892/** @interface_method_impl{VUSBIROOTHUBCONNECTOR,pfnDetachDevice} */
893static DECLCALLBACK(int) vusbRhDetachDevice(PVUSBIROOTHUBCONNECTOR pInterface, PVUSBIDEVICE pDevice)
894{
895 PVUSBROOTHUB pRh = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
896 if (&pRh->Hub != ((PVUSBDEV)pDevice)->pHub)
897 AssertFailedReturn(VERR_INVALID_PARAMETER);
898 return vusbDevDetach((PVUSBDEV)pDevice);
899}
900
901
902/** @interface_method_impl{VUSBIROOTHUBCONNECTOR,pfnSetPeriodicFrameProcessing} */
903static DECLCALLBACK(int) vusbRhSetFrameProcessing(PVUSBIROOTHUBCONNECTOR pInterface, uint32_t uFrameRate)
904{
905 int rc = VINF_SUCCESS;
906 PVUSBROOTHUB pThis = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
907
908 /* Create the frame thread lazily. */
909 if ( !pThis->hThreadPeriodFrame
910 && uFrameRate)
911 {
912 ASMAtomicXchgU32(&pThis->uFrameRateDefault, uFrameRate);
913 pThis->uFrameRate = uFrameRate;
914 vusbRhR3CalcTimerIntervals(pThis, uFrameRate);
915
916 rc = RTSemEventMultiCreate(&pThis->hSemEventPeriodFrame);
917 AssertRCReturn(rc, rc);
918
919 rc = RTSemEventMultiCreate(&pThis->hSemEventPeriodFrameStopped);
920 AssertRCReturn(rc, rc);
921
922 rc = PDMDrvHlpThreadCreate(pThis->pDrvIns, &pThis->hThreadPeriodFrame, pThis, vusbRhR3PeriodFrameWorker,
923 vusbRhR3PeriodFrameWorkerWakeup, 0, RTTHREADTYPE_IO, "VUsbPeriodFrm");
924 AssertRCReturn(rc, rc);
925
926 VMSTATE enmState = PDMDrvHlpVMState(pThis->pDrvIns);
927 if ( enmState == VMSTATE_RUNNING
928 || enmState == VMSTATE_RUNNING_LS
929 || enmState == VMSTATE_RUNNING_FT)
930 {
931 rc = PDMR3ThreadResume(pThis->hThreadPeriodFrame);
932 AssertRCReturn(rc, rc);
933 }
934 }
935 else if ( pThis->hThreadPeriodFrame
936 && !uFrameRate)
937 {
938 /* Stop processing. */
939 uint32_t uFrameRateOld = ASMAtomicXchgU32(&pThis->uFrameRateDefault, uFrameRate);
940 if (uFrameRateOld)
941 {
942 rc = RTSemEventMultiReset(pThis->hSemEventPeriodFrameStopped);
943 AssertRC(rc);
944
945 /* Signal the frame thread to stop. */
946 RTSemEventMultiSignal(pThis->hSemEventPeriodFrame);
947
948 /* Wait for signal from the thread that it stopped. */
949 rc = RTSemEventMultiWait(pThis->hSemEventPeriodFrameStopped, RT_INDEFINITE_WAIT);
950 AssertRC(rc);
951 }
952 }
953 else if ( pThis->hThreadPeriodFrame
954 && uFrameRate)
955 {
956 /* Just switch to the new frame rate and let the periodic frame thread pick it up. */
957 uint32_t uFrameRateOld = ASMAtomicXchgU32(&pThis->uFrameRateDefault, uFrameRate);
958
959 /* Signal the frame thread to continue if it was stopped. */
960 if (!uFrameRateOld)
961 RTSemEventMultiSignal(pThis->hSemEventPeriodFrame);
962 }
963
964 return rc;
965}
966
967
968/** @interface_method_impl{VUSBIROOTHUBCONNECTOR,pfnGetPeriodicFrameRate} */
969static DECLCALLBACK(uint32_t) vusbRhGetPeriodicFrameRate(PVUSBIROOTHUBCONNECTOR pInterface)
970{
971 PVUSBROOTHUB pThis = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
972
973 return pThis->uFrameRate;
974}
975
976/** @interface_method_impl{VUSBIROOTHUBCONNECTOR,pfnUpdateIsocFrameDelta} */
977static DECLCALLBACK(uint32_t) vusbRhUpdateIsocFrameDelta(PVUSBIROOTHUBCONNECTOR pInterface, PVUSBIDEVICE pDevice,
978 int EndPt, VUSBDIRECTION enmDir, uint16_t uNewFrameID, uint8_t uBits)
979{
980 PVUSBROOTHUB pRh = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
981 AssertReturn(pRh, 0);
982 PVUSBDEV pDev = (PVUSBDEV)pDevice;
983 PVUSBPIPE pPipe = &pDev->aPipes[EndPt];
984 uint32_t *puLastFrame;
985 int32_t uFrameDelta;
986 uint32_t uMaxVal = 1 << uBits;
987
988 puLastFrame = enmDir == VUSBDIRECTION_IN ? &pPipe->uLastFrameIn : &pPipe->uLastFrameOut;
989 uFrameDelta = uNewFrameID - *puLastFrame;
990 *puLastFrame = uNewFrameID;
991 /* Take care of wrap-around. */
992 if (uFrameDelta < 0)
993 uFrameDelta += uMaxVal;
994
995 return (uint16_t)uFrameDelta;
996}
997
998/* -=-=-=-=-=- VUSB Device methods (for the root hub) -=-=-=-=-=- */
999
1000
1001/**
1002 * @interface_method_impl{VUSBIDEVICE,pfnReset}
1003 */
1004static DECLCALLBACK(int) vusbRhDevReset(PVUSBIDEVICE pInterface, bool fResetOnLinux,
1005 PFNVUSBRESETDONE pfnDone, void *pvUser, PVM pVM)
1006{
1007 RT_NOREF(pfnDone, pvUser, pVM);
1008 PVUSBROOTHUB pRh = RT_FROM_MEMBER(pInterface, VUSBROOTHUB, Hub.Dev.IDevice);
1009 Assert(!pfnDone);
1010 return pRh->pIRhPort->pfnReset(pRh->pIRhPort, fResetOnLinux); /** @todo change rc from bool to vbox status everywhere! */
1011}
1012
1013
1014/**
1015 * @interface_method_impl{VUSBIDEVICE,pfnPowerOn}
1016 */
1017static DECLCALLBACK(int) vusbRhDevPowerOn(PVUSBIDEVICE pInterface)
1018{
1019 PVUSBROOTHUB pRh = RT_FROM_MEMBER(pInterface, VUSBROOTHUB, Hub.Dev.IDevice);
1020 LogFlow(("vusbRhDevPowerOn: pRh=%p\n", pRh));
1021
1022 Assert( pRh->Hub.Dev.enmState != VUSB_DEVICE_STATE_DETACHED
1023 && pRh->Hub.Dev.enmState != VUSB_DEVICE_STATE_RESET);
1024
1025 if (pRh->Hub.Dev.enmState == VUSB_DEVICE_STATE_ATTACHED)
1026 pRh->Hub.Dev.enmState = VUSB_DEVICE_STATE_POWERED;
1027
1028 return VINF_SUCCESS;
1029}
1030
1031
1032/**
1033 * @interface_method_impl{VUSBIDEVICE,pfnPowerOff}
1034 */
1035static DECLCALLBACK(int) vusbRhDevPowerOff(PVUSBIDEVICE pInterface)
1036{
1037 PVUSBROOTHUB pRh = RT_FROM_MEMBER(pInterface, VUSBROOTHUB, Hub.Dev.IDevice);
1038 LogFlow(("vusbRhDevPowerOff: pRh=%p\n", pRh));
1039
1040 Assert( pRh->Hub.Dev.enmState != VUSB_DEVICE_STATE_DETACHED
1041 && pRh->Hub.Dev.enmState != VUSB_DEVICE_STATE_RESET);
1042
1043 /*
1044 * Cancel all URBs and reap them.
1045 */
1046 VUSBIRhCancelAllUrbs(&pRh->IRhConnector);
1047 RTCritSectEnter(&pRh->CritSectDevices);
1048 PVUSBDEV pDev = pRh->pDevices;
1049 while (pDev)
1050 {
1051 VUSBIRhReapAsyncUrbs(&pRh->IRhConnector, (PVUSBIDEVICE)pDev, 0);
1052 pDev = pDev->pNext;
1053 }
1054 RTCritSectLeave(&pRh->CritSectDevices);
1055
1056 pRh->Hub.Dev.enmState = VUSB_DEVICE_STATE_ATTACHED;
1057 return VINF_SUCCESS;
1058}
1059
1060/**
1061 * @interface_method_impl{VUSBIDEVICE,pfnGetState}
1062 */
1063static DECLCALLBACK(VUSBDEVICESTATE) vusbRhDevGetState(PVUSBIDEVICE pInterface)
1064{
1065 PVUSBROOTHUB pRh = RT_FROM_MEMBER(pInterface, VUSBROOTHUB, Hub.Dev.IDevice);
1066 return pRh->Hub.Dev.enmState;
1067}
1068
1069
1070static const char *vusbGetSpeedString(VUSBSPEED enmSpeed)
1071{
1072 const char *pszSpeed = NULL;
1073
1074 switch (enmSpeed)
1075 {
1076 case VUSB_SPEED_LOW:
1077 pszSpeed = "Low";
1078 break;
1079 case VUSB_SPEED_FULL:
1080 pszSpeed = "Full";
1081 break;
1082 case VUSB_SPEED_HIGH:
1083 pszSpeed = "High";
1084 break;
1085 case VUSB_SPEED_VARIABLE:
1086 pszSpeed = "Variable";
1087 break;
1088 case VUSB_SPEED_SUPER:
1089 pszSpeed = "Super";
1090 break;
1091 case VUSB_SPEED_SUPERPLUS:
1092 pszSpeed = "SuperPlus";
1093 break;
1094 default:
1095 pszSpeed = "Unknown";
1096 break;
1097 }
1098 return pszSpeed;
1099}
1100
1101/* -=-=-=-=-=- VUSB Hub methods -=-=-=-=-=- */
1102
1103
1104/**
1105 * Attach the device to the hub.
1106 * Port assignments and all such stuff is up to this routine.
1107 *
1108 * @returns VBox status code.
1109 * @param pHub Pointer to the hub.
1110 * @param pDev Pointer to the device.
1111 */
1112static int vusbRhHubOpAttach(PVUSBHUB pHub, PVUSBDEV pDev)
1113{
1114 PVUSBROOTHUB pRh = (PVUSBROOTHUB)pHub;
1115
1116 /*
1117 * Assign a port.
1118 */
1119 int iPort = ASMBitFirstSet(&pRh->Bitmap, sizeof(pRh->Bitmap) * 8);
1120 if (iPort < 0)
1121 {
1122 LogRel(("VUSB: No ports available!\n"));
1123 return VERR_VUSB_NO_PORTS;
1124 }
1125 ASMBitClear(&pRh->Bitmap, iPort);
1126 pHub->cDevices++;
1127 pDev->i16Port = iPort;
1128
1129 /*
1130 * Call the HCI attach routine and let it have its say before the device is
1131 * linked into the device list of this hub.
1132 */
1133 int rc = pRh->pIRhPort->pfnAttach(pRh->pIRhPort, &pDev->IDevice, iPort);
1134 if (RT_SUCCESS(rc))
1135 {
1136 RTCritSectEnter(&pRh->CritSectDevices);
1137 pDev->pNext = pRh->pDevices;
1138 pRh->pDevices = pDev;
1139 RTCritSectLeave(&pRh->CritSectDevices);
1140 LogRel(("VUSB: Attached '%s' to port %d on %s (%sSpeed)\n", pDev->pUsbIns->pszName,
1141 iPort, pHub->pszName, vusbGetSpeedString(pDev->pUsbIns->enmSpeed)));
1142 }
1143 else
1144 {
1145 ASMBitSet(&pRh->Bitmap, iPort);
1146 pHub->cDevices--;
1147 pDev->i16Port = -1;
1148 LogRel(("VUSB: Failed to attach '%s' to port %d, rc=%Rrc\n", pDev->pUsbIns->pszName, iPort, rc));
1149 }
1150 return rc;
1151}
1152
1153
1154/**
1155 * Detach the device from the hub.
1156 *
1157 * @returns VBox status code.
1158 * @param pHub Pointer to the hub.
1159 * @param pDev Pointer to the device.
1160 */
1161static void vusbRhHubOpDetach(PVUSBHUB pHub, PVUSBDEV pDev)
1162{
1163 PVUSBROOTHUB pRh = (PVUSBROOTHUB)pHub;
1164 Assert(pDev->i16Port != -1);
1165
1166 /*
1167 * Check that it's attached and unlink it from the linked list.
1168 */
1169 RTCritSectEnter(&pRh->CritSectDevices);
1170 if (pRh->pDevices != pDev)
1171 {
1172 PVUSBDEV pPrev = pRh->pDevices;
1173 while (pPrev && pPrev->pNext != pDev)
1174 pPrev = pPrev->pNext;
1175 Assert(pPrev);
1176 pPrev->pNext = pDev->pNext;
1177 }
1178 else
1179 pRh->pDevices = pDev->pNext;
1180 pDev->pNext = NULL;
1181 RTCritSectLeave(&pRh->CritSectDevices);
1182
1183 /*
1184 * Detach the device and mark the port as available.
1185 */
1186 unsigned uPort = pDev->i16Port;
1187 pRh->pIRhPort->pfnDetach(pRh->pIRhPort, &pDev->IDevice, uPort);
1188 LogRel(("VUSB: Detached '%s' from port %u on %s\n", pDev->pUsbIns->pszName, uPort, pHub->pszName));
1189 ASMBitSet(&pRh->Bitmap, uPort);
1190 pHub->cDevices--;
1191}
1192
1193
1194/**
1195 * The Hub methods implemented by the root hub.
1196 */
1197static const VUSBHUBOPS s_VUsbRhHubOps =
1198{
1199 vusbRhHubOpAttach,
1200 vusbRhHubOpDetach
1201};
1202
1203
1204
1205/* -=-=-=-=-=- PDM Base interface methods -=-=-=-=-=- */
1206
1207
1208/**
1209 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
1210 */
1211static DECLCALLBACK(void *) vusbRhQueryInterface(PPDMIBASE pInterface, const char *pszIID)
1212{
1213 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
1214 PVUSBROOTHUB pRh = PDMINS_2_DATA(pDrvIns, PVUSBROOTHUB);
1215
1216 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
1217 PDMIBASE_RETURN_INTERFACE(pszIID, VUSBIROOTHUBCONNECTOR, &pRh->IRhConnector);
1218 PDMIBASE_RETURN_INTERFACE(pszIID, VUSBIDEVICE, &pRh->Hub.Dev.IDevice);
1219 return NULL;
1220}
1221
1222
1223/* -=-=-=-=-=- PDM Driver methods -=-=-=-=-=- */
1224
1225
1226/**
1227 * Destruct a driver instance.
1228 *
1229 * Most VM resources are freed by the VM. This callback is provided so that any non-VM
1230 * resources can be freed correctly.
1231 *
1232 * @param pDrvIns The driver instance data.
1233 */
1234static DECLCALLBACK(void) vusbRhDestruct(PPDMDRVINS pDrvIns)
1235{
1236 PVUSBROOTHUB pRh = PDMINS_2_DATA(pDrvIns, PVUSBROOTHUB);
1237 PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns);
1238
1239 vusbUrbPoolDestroy(&pRh->Hub.Dev.UrbPool);
1240 if (pRh->Hub.pszName)
1241 {
1242 RTStrFree(pRh->Hub.pszName);
1243 pRh->Hub.pszName = NULL;
1244 }
1245 if (pRh->hSniffer != VUSBSNIFFER_NIL)
1246 VUSBSnifferDestroy(pRh->hSniffer);
1247
1248 if (pRh->hSemEventPeriodFrame)
1249 RTSemEventMultiDestroy(pRh->hSemEventPeriodFrame);
1250
1251 if (pRh->hSemEventPeriodFrameStopped)
1252 RTSemEventMultiDestroy(pRh->hSemEventPeriodFrameStopped);
1253
1254 RTCritSectDelete(&pRh->CritSectDevices);
1255}
1256
1257
1258/**
1259 * Construct a root hub driver instance.
1260 *
1261 * @copydoc FNPDMDRVCONSTRUCT
1262 */
1263static DECLCALLBACK(int) vusbRhConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
1264{
1265 RT_NOREF(fFlags);
1266 PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
1267 LogFlow(("vusbRhConstruct: Instance %d\n", pDrvIns->iInstance));
1268 PVUSBROOTHUB pThis = PDMINS_2_DATA(pDrvIns, PVUSBROOTHUB);
1269
1270 /*
1271 * Validate configuration.
1272 */
1273 if (!CFGMR3AreValuesValid(pCfg, "CaptureFilename\0"))
1274 return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
1275
1276 /*
1277 * Check that there are no drivers below us.
1278 */
1279 AssertMsgReturn(PDMDrvHlpNoAttach(pDrvIns) == VERR_PDM_NO_ATTACHED_DRIVER,
1280 ("Configuration error: Not possible to attach anything to this driver!\n"),
1281 VERR_PDM_DRVINS_NO_ATTACH);
1282
1283 /*
1284 * Initialize the critical sections.
1285 */
1286 int rc = RTCritSectInit(&pThis->CritSectDevices);
1287 if (RT_FAILURE(rc))
1288 return rc;
1289
1290 char *pszCaptureFilename = NULL;
1291 rc = CFGMR3QueryStringAlloc(pCfg, "CaptureFilename", &pszCaptureFilename);
1292 if ( RT_FAILURE(rc)
1293 && rc != VERR_CFGM_VALUE_NOT_FOUND)
1294 return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS,
1295 N_("Configuration error: Failed to query value of \"CaptureFilename\""));
1296
1297 /*
1298 * Initialize the data members.
1299 */
1300 pDrvIns->IBase.pfnQueryInterface = vusbRhQueryInterface;
1301 /* the usb device */
1302 pThis->Hub.Dev.enmState = VUSB_DEVICE_STATE_ATTACHED;
1303 pThis->Hub.Dev.u8Address = VUSB_INVALID_ADDRESS;
1304 pThis->Hub.Dev.u8NewAddress = VUSB_INVALID_ADDRESS;
1305 pThis->Hub.Dev.i16Port = -1;
1306 pThis->Hub.Dev.cRefs = 1;
1307 pThis->Hub.Dev.IDevice.pfnReset = vusbRhDevReset;
1308 pThis->Hub.Dev.IDevice.pfnPowerOn = vusbRhDevPowerOn;
1309 pThis->Hub.Dev.IDevice.pfnPowerOff = vusbRhDevPowerOff;
1310 pThis->Hub.Dev.IDevice.pfnGetState = vusbRhDevGetState;
1311 /* the hub */
1312 pThis->Hub.pOps = &s_VUsbRhHubOps;
1313 pThis->Hub.pRootHub = pThis;
1314 //pThis->hub.cPorts - later
1315 pThis->Hub.cDevices = 0;
1316 pThis->Hub.Dev.pHub = &pThis->Hub;
1317 RTStrAPrintf(&pThis->Hub.pszName, "RootHub#%d", pDrvIns->iInstance);
1318 /* misc */
1319 pThis->pDrvIns = pDrvIns;
1320 /* the connector */
1321 pThis->IRhConnector.pfnSetUrbParams = vusbRhSetUrbParams;
1322 pThis->IRhConnector.pfnNewUrb = vusbRhConnNewUrb;
1323 pThis->IRhConnector.pfnFreeUrb = vusbRhConnFreeUrb;
1324 pThis->IRhConnector.pfnSubmitUrb = vusbRhSubmitUrb;
1325 pThis->IRhConnector.pfnReapAsyncUrbs = vusbRhReapAsyncUrbs;
1326 pThis->IRhConnector.pfnCancelUrbsEp = vusbRhCancelUrbsEp;
1327 pThis->IRhConnector.pfnCancelAllUrbs = vusbRhCancelAllUrbs;
1328 pThis->IRhConnector.pfnAbortEp = vusbRhAbortEp;
1329 pThis->IRhConnector.pfnAttachDevice = vusbRhAttachDevice;
1330 pThis->IRhConnector.pfnDetachDevice = vusbRhDetachDevice;
1331 pThis->IRhConnector.pfnSetPeriodicFrameProcessing = vusbRhSetFrameProcessing;
1332 pThis->IRhConnector.pfnGetPeriodicFrameRate = vusbRhGetPeriodicFrameRate;
1333 pThis->IRhConnector.pfnUpdateIsocFrameDelta = vusbRhUpdateIsocFrameDelta;
1334 pThis->hSniffer = VUSBSNIFFER_NIL;
1335 pThis->cbHci = 0;
1336 pThis->cbHciTd = 0;
1337 pThis->fFrameProcessing = false;
1338#ifdef LOG_ENABLED
1339 pThis->iSerial = 0;
1340#endif
1341 /*
1342 * Resolve interface(s).
1343 */
1344 pThis->pIRhPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, VUSBIROOTHUBPORT);
1345 AssertMsgReturn(pThis->pIRhPort, ("Configuration error: the device/driver above us doesn't expose any VUSBIROOTHUBPORT interface!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE);
1346
1347 /*
1348 * Get number of ports and the availability bitmap.
1349 * ASSUME that the number of ports reported now at creation time is the max number.
1350 */
1351 pThis->Hub.cPorts = pThis->pIRhPort->pfnGetAvailablePorts(pThis->pIRhPort, &pThis->Bitmap);
1352 Log(("vusbRhConstruct: cPorts=%d\n", pThis->Hub.cPorts));
1353
1354 /*
1355 * Get the USB version of the attached HC.
1356 * ASSUME that version 2.0 implies high-speed.
1357 */
1358 pThis->fHcVersions = pThis->pIRhPort->pfnGetUSBVersions(pThis->pIRhPort);
1359 Log(("vusbRhConstruct: fHcVersions=%u\n", pThis->fHcVersions));
1360
1361 rc = vusbUrbPoolInit(&pThis->Hub.Dev.UrbPool);
1362 if (RT_FAILURE(rc))
1363 return rc;
1364
1365 if (pszCaptureFilename)
1366 {
1367 rc = VUSBSnifferCreate(&pThis->hSniffer, 0, pszCaptureFilename, NULL, NULL);
1368 if (RT_FAILURE(rc))
1369 return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS,
1370 N_("VUSBSniffer cannot open '%s' for writing. The directory must exist and it must be writable for the current user"),
1371 pszCaptureFilename);
1372
1373 MMR3HeapFree(pszCaptureFilename);
1374 }
1375
1376 /*
1377 * Register ourselves as a USB hub.
1378 * The current implementation uses the VUSBIRHCONFIG interface for communication.
1379 */
1380 PCPDMUSBHUBHLP pHlp; /* not used currently */
1381 rc = PDMDrvHlpUSBRegisterHub(pDrvIns, pThis->fHcVersions, pThis->Hub.cPorts, &g_vusbHubReg, &pHlp);
1382 if (RT_FAILURE(rc))
1383 return rc;
1384
1385 /*
1386 * Statistics. (It requires a 30" monitor or extremely tiny fonts to edit this "table".)
1387 */
1388#ifdef VBOX_WITH_STATISTICS
1389 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->Total.StatUrbsSubmitted, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "The number of URBs submitted.", "/VUSB/%d/UrbsSubmitted", pDrvIns->iInstance);
1390 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatUrbsSubmitted, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Bulk transfer.", "/VUSB/%d/UrbsSubmitted/Bulk", pDrvIns->iInstance);
1391 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatUrbsSubmitted, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Control transfer.", "/VUSB/%d/UrbsSubmitted/Ctrl", pDrvIns->iInstance);
1392 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatUrbsSubmitted, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Interrupt transfer.", "/VUSB/%d/UrbsSubmitted/Intr", pDrvIns->iInstance);
1393 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatUrbsSubmitted, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Isochronous transfer.", "/VUSB/%d/UrbsSubmitted/Isoc", pDrvIns->iInstance);
1394
1395 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->Total.StatUrbsCancelled, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "The number of URBs cancelled. (included in failed)", "/VUSB/%d/UrbsCancelled", pDrvIns->iInstance);
1396 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatUrbsCancelled, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Bulk transfer.", "/VUSB/%d/UrbsCancelled/Bulk", pDrvIns->iInstance);
1397 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatUrbsCancelled, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Control transfer.", "/VUSB/%d/UrbsCancelled/Ctrl", pDrvIns->iInstance);
1398 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatUrbsCancelled, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Interrupt transfer.", "/VUSB/%d/UrbsCancelled/Intr", pDrvIns->iInstance);
1399 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatUrbsCancelled, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Isochronous transfer.", "/VUSB/%d/UrbsCancelled/Isoc", pDrvIns->iInstance);
1400
1401 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->Total.StatUrbsFailed, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "The number of URBs failing.", "/VUSB/%d/UrbsFailed", pDrvIns->iInstance);
1402 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatUrbsFailed, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Bulk transfer.", "/VUSB/%d/UrbsFailed/Bulk", pDrvIns->iInstance);
1403 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatUrbsFailed, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Control transfer.", "/VUSB/%d/UrbsFailed/Ctrl", pDrvIns->iInstance);
1404 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatUrbsFailed, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Interrupt transfer.", "/VUSB/%d/UrbsFailed/Intr", pDrvIns->iInstance);
1405 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatUrbsFailed, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Isochronous transfer.", "/VUSB/%d/UrbsFailed/Isoc", pDrvIns->iInstance);
1406
1407 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->Total.StatReqBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Total requested transfer.", "/VUSB/%d/ReqBytes", pDrvIns->iInstance);
1408 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatReqBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Bulk transfer.", "/VUSB/%d/ReqBytes/Bulk", pDrvIns->iInstance);
1409 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatReqBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Control transfer.", "/VUSB/%d/ReqBytes/Ctrl", pDrvIns->iInstance);
1410 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatReqBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Interrupt transfer.", "/VUSB/%d/ReqBytes/Intr", pDrvIns->iInstance);
1411 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatReqBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Isochronous transfer.", "/VUSB/%d/ReqBytes/Isoc", pDrvIns->iInstance);
1412
1413 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->Total.StatReqReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Total requested read transfer.", "/VUSB/%d/ReqReadBytes", pDrvIns->iInstance);
1414 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatReqReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Bulk transfer.", "/VUSB/%d/ReqReadBytes/Bulk", pDrvIns->iInstance);
1415 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatReqReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Control transfer.", "/VUSB/%d/ReqReadBytes/Ctrl", pDrvIns->iInstance);
1416 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatReqReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Interrupt transfer.", "/VUSB/%d/ReqReadBytes/Intr", pDrvIns->iInstance);
1417 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatReqReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Isochronous transfer.", "/VUSB/%d/ReqReadBytes/Isoc", pDrvIns->iInstance);
1418
1419 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->Total.StatReqWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Total requested write transfer.", "/VUSB/%d/ReqWriteBytes", pDrvIns->iInstance);
1420 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatReqWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Bulk transfer.", "/VUSB/%d/ReqWriteBytes/Bulk", pDrvIns->iInstance);
1421 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatReqWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Control transfer.", "/VUSB/%d/ReqWriteBytes/Ctrl", pDrvIns->iInstance);
1422 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatReqWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Interrupt transfer.", "/VUSB/%d/ReqWriteBytes/Intr", pDrvIns->iInstance);
1423 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatReqWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Isochronous transfer.", "/VUSB/%d/ReqWriteBytes/Isoc", pDrvIns->iInstance);
1424
1425 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->Total.StatActBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Actual total transfer.", "/VUSB/%d/ActBytes", pDrvIns->iInstance);
1426 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatActBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Bulk transfer.", "/VUSB/%d/ActBytes/Bulk", pDrvIns->iInstance);
1427 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatActBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Control transfer.", "/VUSB/%d/ActBytes/Ctrl", pDrvIns->iInstance);
1428 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatActBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Interrupt transfer.", "/VUSB/%d/ActBytes/Intr", pDrvIns->iInstance);
1429 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatActBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Isochronous transfer.", "/VUSB/%d/ActBytes/Isoc", pDrvIns->iInstance);
1430
1431 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->Total.StatActReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Actual total read transfer.", "/VUSB/%d/ActReadBytes", pDrvIns->iInstance);
1432 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatActReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Bulk transfer.", "/VUSB/%d/ActReadBytes/Bulk", pDrvIns->iInstance);
1433 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatActReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Control transfer.", "/VUSB/%d/ActReadBytes/Ctrl", pDrvIns->iInstance);
1434 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatActReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Interrupt transfer.", "/VUSB/%d/ActReadBytes/Intr", pDrvIns->iInstance);
1435 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatActReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Isochronous transfer.", "/VUSB/%d/ActReadBytes/Isoc", pDrvIns->iInstance);
1436
1437 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->Total.StatActWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Actual total write transfer.", "/VUSB/%d/ActWriteBytes", pDrvIns->iInstance);
1438 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatActWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Bulk transfer.", "/VUSB/%d/ActWriteBytes/Bulk", pDrvIns->iInstance);
1439 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatActWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Control transfer.", "/VUSB/%d/ActWriteBytes/Ctrl", pDrvIns->iInstance);
1440 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatActWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Interrupt transfer.", "/VUSB/%d/ActWriteBytes/Intr", pDrvIns->iInstance);
1441 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatActWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Isochronous transfer.", "/VUSB/%d/ActWriteBytes/Isoc", pDrvIns->iInstance);
1442
1443 /* bulk */
1444 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatUrbsSubmitted, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of submitted URBs.", "/VUSB/%d/Bulk/Urbs", pDrvIns->iInstance);
1445 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatUrbsFailed, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of failed URBs.", "/VUSB/%d/Bulk/UrbsFailed", pDrvIns->iInstance);
1446 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatUrbsCancelled, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of cancelled URBs.", "/VUSB/%d/Bulk/UrbsFailed/Cancelled", pDrvIns->iInstance);
1447 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatActBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Number of bytes transferred.", "/VUSB/%d/Bulk/ActBytes", pDrvIns->iInstance);
1448 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatActReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Read.", "/VUSB/%d/Bulk/ActBytes/Read", pDrvIns->iInstance);
1449 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatActWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Write.", "/VUSB/%d/Bulk/ActBytes/Write", pDrvIns->iInstance);
1450 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatReqBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Requested number of bytes.", "/VUSB/%d/Bulk/ReqBytes", pDrvIns->iInstance);
1451 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatReqReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Read.", "/VUSB/%d/Bulk/ReqBytes/Read", pDrvIns->iInstance);
1452 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatReqWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Write.", "/VUSB/%d/Bulk/ReqBytes/Write", pDrvIns->iInstance);
1453
1454 /* control */
1455 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatUrbsSubmitted, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of submitted URBs.", "/VUSB/%d/Ctrl/Urbs", pDrvIns->iInstance);
1456 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatUrbsFailed, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of failed URBs.", "/VUSB/%d/Ctrl/UrbsFailed", pDrvIns->iInstance);
1457 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatUrbsCancelled, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of cancelled URBs.", "/VUSB/%d/Ctrl/UrbsFailed/Cancelled", pDrvIns->iInstance);
1458 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatActBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Number of bytes transferred.", "/VUSB/%d/Ctrl/ActBytes", pDrvIns->iInstance);
1459 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatActReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Read.", "/VUSB/%d/Ctrl/ActBytes/Read", pDrvIns->iInstance);
1460 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatActWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Write.", "/VUSB/%d/Ctrl/ActBytes/Write", pDrvIns->iInstance);
1461 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatReqBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Requested number of bytes.", "/VUSB/%d/Ctrl/ReqBytes", pDrvIns->iInstance);
1462 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatReqReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Read.", "/VUSB/%d/Ctrl/ReqBytes/Read", pDrvIns->iInstance);
1463 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatReqWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Write.", "/VUSB/%d/Ctrl/ReqBytes/Write", pDrvIns->iInstance);
1464
1465 /* interrupt */
1466 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatUrbsSubmitted, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of submitted URBs.", "/VUSB/%d/Intr/Urbs", pDrvIns->iInstance);
1467 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatUrbsFailed, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of failed URBs.", "/VUSB/%d/Intr/UrbsFailed", pDrvIns->iInstance);
1468 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatUrbsCancelled, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of cancelled URBs.", "/VUSB/%d/Intr/UrbsFailed/Cancelled", pDrvIns->iInstance);
1469 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatActBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Number of bytes transferred.", "/VUSB/%d/Intr/ActBytes", pDrvIns->iInstance);
1470 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatActReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Read.", "/VUSB/%d/Intr/ActBytes/Read", pDrvIns->iInstance);
1471 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatActWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Write.", "/VUSB/%d/Intr/ActBytes/Write", pDrvIns->iInstance);
1472 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatReqBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Requested number of bytes.", "/VUSB/%d/Intr/ReqBytes", pDrvIns->iInstance);
1473 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatReqReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Read.", "/VUSB/%d/Intr/ReqBytes/Read", pDrvIns->iInstance);
1474 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatReqWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Write.", "/VUSB/%d/Intr/ReqBytes/Write", pDrvIns->iInstance);
1475
1476 /* isochronous */
1477 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatUrbsSubmitted, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of submitted URBs.", "/VUSB/%d/Isoc/Urbs", pDrvIns->iInstance);
1478 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatUrbsFailed, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of failed URBs.", "/VUSB/%d/Isoc/UrbsFailed", pDrvIns->iInstance);
1479 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatUrbsCancelled, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of cancelled URBs.", "/VUSB/%d/Isoc/UrbsFailed/Cancelled", pDrvIns->iInstance);
1480 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatActBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Number of bytes transferred.", "/VUSB/%d/Isoc/ActBytes", pDrvIns->iInstance);
1481 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatActReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Read.", "/VUSB/%d/Isoc/ActBytes/Read", pDrvIns->iInstance);
1482 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatActWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Write.", "/VUSB/%d/Isoc/ActBytes/Write", pDrvIns->iInstance);
1483 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatReqBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Requested number of bytes.", "/VUSB/%d/Isoc/ReqBytes", pDrvIns->iInstance);
1484 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatReqReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Read.", "/VUSB/%d/Isoc/ReqBytes/Read", pDrvIns->iInstance);
1485 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatReqWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Write.", "/VUSB/%d/Isoc/ReqBytes/Write", pDrvIns->iInstance);
1486 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->StatIsocActPkts, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of isochronous packets returning data.", "/VUSB/%d/Isoc/ActPkts", pDrvIns->iInstance);
1487 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->StatIsocActReadPkts, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Read.", "/VUSB/%d/Isoc/ActPkts/Read", pDrvIns->iInstance);
1488 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->StatIsocActWritePkts, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Write.", "/VUSB/%d/Isoc/ActPkts/Write", pDrvIns->iInstance);
1489 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->StatIsocReqPkts, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Requested number of isochronous packets.", "/VUSB/%d/Isoc/ReqPkts", pDrvIns->iInstance);
1490 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->StatIsocReqReadPkts, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Read.", "/VUSB/%d/Isoc/ReqPkts/Read", pDrvIns->iInstance);
1491 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->StatIsocReqWritePkts, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Write.", "/VUSB/%d/Isoc/ReqPkts/Write", pDrvIns->iInstance);
1492
1493 for (unsigned i = 0; i < RT_ELEMENTS(pThis->aStatIsocDetails); i++)
1494 {
1495 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aStatIsocDetails[i].Pkts, STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_COUNT, ".", "/VUSB/%d/Isoc/%d", pDrvIns->iInstance, i);
1496 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aStatIsocDetails[i].Ok, STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_COUNT, ".", "/VUSB/%d/Isoc/%d/Ok", pDrvIns->iInstance, i);
1497 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aStatIsocDetails[i].Ok0, STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_COUNT, ".", "/VUSB/%d/Isoc/%d/Ok0", pDrvIns->iInstance, i);
1498 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aStatIsocDetails[i].DataUnderrun, STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_COUNT, ".", "/VUSB/%d/Isoc/%d/DataUnderrun", pDrvIns->iInstance, i);
1499 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aStatIsocDetails[i].DataUnderrun0, STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_COUNT, ".", "/VUSB/%d/Isoc/%d/DataUnderrun0", pDrvIns->iInstance, i);
1500 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aStatIsocDetails[i].DataOverrun, STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_COUNT, ".", "/VUSB/%d/Isoc/%d/DataOverrun", pDrvIns->iInstance, i);
1501 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aStatIsocDetails[i].NotAccessed, STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_COUNT, ".", "/VUSB/%d/Isoc/%d/NotAccessed", pDrvIns->iInstance, i);
1502 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aStatIsocDetails[i].Misc, STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_COUNT, ".", "/VUSB/%d/Isoc/%d/Misc", pDrvIns->iInstance, i);
1503 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aStatIsocDetails[i].Bytes, STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_BYTES, ".", "/VUSB/%d/Isoc/%d/Bytes", pDrvIns->iInstance, i);
1504 }
1505
1506 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->StatReapAsyncUrbs, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, "Profiling the vusbRhReapAsyncUrbs body (omitting calls when nothing is in-flight).", "/VUSB/%d/ReapAsyncUrbs", pDrvIns->iInstance);
1507 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->StatSubmitUrb, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, "Profiling the vusbRhSubmitUrb body.", "/VUSB/%d/SubmitUrb", pDrvIns->iInstance);
1508 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->StatFramesProcessedThread, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, "Processed frames in the dedicated thread", "/VUSB/%d/FramesProcessedThread", pDrvIns->iInstance);
1509 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->StatFramesProcessedClbk, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, "Processed frames in the URB completion callback", "/VUSB/%d/FramesProcessedClbk", pDrvIns->iInstance);
1510#endif
1511 PDMDrvHlpSTAMRegisterF(pDrvIns, (void *)&pThis->Hub.Dev.UrbPool.cUrbsInPool, STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "The number of URBs in the pool.", "/VUSB/%d/cUrbsInPool", pDrvIns->iInstance);
1512
1513 return VINF_SUCCESS;
1514}
1515
1516
1517/**
1518 * VUSB Root Hub driver registration record.
1519 */
1520const PDMDRVREG g_DrvVUSBRootHub =
1521{
1522 /* u32Version */
1523 PDM_DRVREG_VERSION,
1524 /* szName */
1525 "VUSBRootHub",
1526 /* szRCMod */
1527 "",
1528 /* szR0Mod */
1529 "",
1530 /* pszDescription */
1531 "VUSB Root Hub Driver.",
1532 /* fFlags */
1533 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
1534 /* fClass. */
1535 PDM_DRVREG_CLASS_USB,
1536 /* cMaxInstances */
1537 ~0U,
1538 /* cbInstance */
1539 sizeof(VUSBROOTHUB),
1540 /* pfnConstruct */
1541 vusbRhConstruct,
1542 /* pfnDestruct */
1543 vusbRhDestruct,
1544 /* pfnRelocate */
1545 NULL,
1546 /* pfnIOCtl */
1547 NULL,
1548 /* pfnPowerOn */
1549 NULL,
1550 /* pfnReset */
1551 NULL,
1552 /* pfnSuspend */
1553 NULL,
1554 /* pfnResume */
1555 NULL,
1556 /* pfnAttach */
1557 NULL,
1558 /* pfnDetach */
1559 NULL,
1560 /* pfnPowerOff */
1561 NULL,
1562 /* pfnSoftReset */
1563 NULL,
1564 /* u32EndVersion */
1565 PDM_DRVREG_VERSION
1566};
1567
1568/*
1569 * Local Variables:
1570 * mode: c
1571 * c-file-style: "bsd"
1572 * c-basic-offset: 4
1573 * tab-width: 4
1574 * indent-tabs-mode: s
1575 * End:
1576 */
1577
Note: See TracBrowser for help on using the repository browser.

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