VirtualBox

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

Last change on this file since 59704 was 59704, checked in by vboxsync, 9 years ago

VUSB: Some structural cleanup (#3 Make the VUSB URB specific data private to the VUSB stack, some interface changes required for XHCI because it previously required access to some VUsb members)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 64.6 KB
Line 
1/* $Id: DrvVUSBRootHub.cpp 59704 2016-02-16 14:13:25Z vboxsync $ */
2/** @file
3 * Virtual USB - Root Hub Driver.
4 */
5
6/*
7 * Copyright (C) 2005-2015 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_bulk 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 AssertMsg(pDev->enmState == VUSB_DEVICE_STATE_DETACHED, ("enmState=%d\n", pDev->enmState));
237
238 pDev->pHub = pHub;
239 pDev->enmState = VUSB_DEVICE_STATE_ATTACHED;
240
241 /* noone else ever messes with the default pipe while we are attached */
242 vusbDevMapEndpoint(pDev, &g_Endpoint0);
243 vusbDevDoSelectConfig(pDev, &g_Config0);
244
245 int rc = pHub->pOps->pfnAttach(pHub, pDev);
246 if (RT_FAILURE(rc))
247 {
248 pDev->pHub = NULL;
249 pDev->enmState = VUSB_DEVICE_STATE_DETACHED;
250 }
251 return rc;
252}
253
254
255/* -=-=-=-=-=- PDMUSBHUBREG methods -=-=-=-=-=- */
256
257/** @copydoc PDMUSBHUBREG::pfnAttachDevice */
258static DECLCALLBACK(int) vusbPDMHubAttachDevice(PPDMDRVINS pDrvIns, PPDMUSBINS pUsbIns, const char *pszCaptureFilename, uint32_t *piPort)
259{
260 PVUSBROOTHUB pThis = PDMINS_2_DATA(pDrvIns, PVUSBROOTHUB);
261
262 /*
263 * Allocate a new VUSB device and initialize it.
264 */
265 PVUSBDEV pDev = (PVUSBDEV)RTMemAllocZ(sizeof(*pDev));
266 AssertReturn(pDev, VERR_NO_MEMORY);
267 int rc = vusbDevInit(pDev, pUsbIns, pszCaptureFilename);
268 if (RT_SUCCESS(rc))
269 {
270 pUsbIns->pvVUsbDev2 = pDev;
271 rc = vusbHubAttach(&pThis->Hub, pDev);
272 if (RT_SUCCESS(rc))
273 {
274 *piPort = UINT32_MAX; ///@todo implement piPort
275 return rc;
276 }
277
278 RTMemFree(pDev->paIfStates);
279 pUsbIns->pvVUsbDev2 = NULL;
280 }
281 RTMemFree(pDev);
282 return rc;
283}
284
285
286/** @copydoc PDMUSBHUBREG::pfnDetachDevice */
287static DECLCALLBACK(int) vusbPDMHubDetachDevice(PPDMDRVINS pDrvIns, PPDMUSBINS pUsbIns, uint32_t iPort)
288{
289 PVUSBDEV pDev = (PVUSBDEV)pUsbIns->pvVUsbDev2;
290 Assert(pDev);
291 vusbDevDestroy(pDev);
292 RTMemFree(pDev);
293 pUsbIns->pvVUsbDev2 = NULL;
294 return VINF_SUCCESS;
295}
296
297/**
298 * The hub registration structure.
299 */
300static const PDMUSBHUBREG g_vusbHubReg =
301{
302 PDM_USBHUBREG_VERSION,
303 vusbPDMHubAttachDevice,
304 vusbPDMHubDetachDevice,
305 PDM_USBHUBREG_VERSION
306};
307
308
309/* -=-=-=-=-=- VUSBIROOTHUBCONNECTOR methods -=-=-=-=-=- */
310
311
312/**
313 * Finds an device attached to a roothub by it's address.
314 *
315 * @returns Pointer to the device.
316 * @returns NULL if not found.
317 * @param pRh Pointer to the root hub.
318 * @param Address The device address.
319 */
320static PVUSBDEV vusbRhFindDevByAddress(PVUSBROOTHUB pRh, uint8_t Address)
321{
322 unsigned iHash = vusbHashAddress(Address);
323 for (PVUSBDEV pDev = pRh->apAddrHash[iHash]; pDev; pDev = pDev->pNextHash)
324 if (pDev->u8Address == Address)
325 return pDev;
326 return NULL;
327}
328
329
330/**
331 * Callback for freeing an URB.
332 * @param pUrb The URB to free.
333 */
334static DECLCALLBACK(void) vusbRhFreeUrb(PVUSBURB pUrb)
335{
336 /*
337 * Assert sanity.
338 */
339 vusbUrbAssert(pUrb);
340 PVUSBROOTHUB pRh = (PVUSBROOTHUB)pUrb->pVUsb->pvFreeCtx;
341 Assert(pRh);
342
343 /*
344 * Free the URB description (logging builds only).
345 */
346 if (pUrb->pszDesc)
347 {
348 RTStrFree(pUrb->pszDesc);
349 pUrb->pszDesc = NULL;
350 }
351
352 /*
353 * Put it into the LIFO of free URBs.
354 * (No ppPrev is needed here.)
355 */
356 RTCritSectEnter(&pRh->CritSectFreeUrbs);
357 pUrb->enmState = VUSBURBSTATE_FREE;
358 pUrb->pVUsb->ppPrev = NULL;
359 pUrb->pVUsb->pNext = pRh->pFreeUrbs;
360 pRh->pFreeUrbs = pUrb;
361 Assert(pRh->pFreeUrbs->enmState == VUSBURBSTATE_FREE);
362 RTCritSectLeave(&pRh->CritSectFreeUrbs);
363}
364
365
366/**
367 * Worker routine for vusbRhConnNewUrb() and vusbDevNewIsocUrb().
368 */
369PVUSBURB vusbRhNewUrb(PVUSBROOTHUB pRh, uint8_t DstAddress, PVUSBDEV pDev, VUSBXFERTYPE enmType,
370 VUSBDIRECTION enmDir, uint32_t cbData, uint32_t cTds, const char *pszTag)
371{
372 /*
373 * Reuse or allocate a new URB.
374 */
375 /* Get the required amount of additional memory to allocate the whole state. */
376 size_t cbMem = cbData + sizeof(VUSBURBVUSBINT) + pRh->cbHci + cTds * pRh->cbHciTd;
377 uint32_t cbDataAllocated = 0;
378
379 /** @todo try find a best fit, MSD which submits rather big URBs intermixed with small control
380 * messages ends up with a 2+ of these big URBs when a single one is sufficient. */
381 /** @todo The allocations should be done by the device, at least as an option, since the devices
382 * frequently wish to associate their own stuff with the in-flight URB or need special buffering
383 * (isochronous on Darwin for instance). */
384 RTCritSectEnter(&pRh->CritSectFreeUrbs);
385 PVUSBURB pUrbPrev = NULL;
386 PVUSBURB pUrb = pRh->pFreeUrbs;
387 while (pUrb)
388 {
389 if (pUrb->pVUsb->cbDataAllocated >= cbData)
390 {
391 /* Unlink and verify part of the state. */
392 if (pUrbPrev)
393 pUrbPrev->pVUsb->pNext = pUrb->pVUsb->pNext;
394 else
395 pRh->pFreeUrbs = pUrb->pVUsb->pNext;
396 Assert(pUrb->u32Magic == VUSBURB_MAGIC);
397 Assert(pUrb->pVUsb->pvFreeCtx == pRh);
398 Assert(pUrb->pVUsb->pfnFree == vusbRhFreeUrb);
399 Assert(pUrb->enmState == VUSBURBSTATE_FREE);
400 Assert(!pUrb->pVUsb->pNext || pUrb->pVUsb->pNext->enmState == VUSBURBSTATE_FREE);
401 cbDataAllocated = pUrb->pVUsb->cbDataAllocated;
402 break;
403 }
404 pUrbPrev = pUrb;
405 pUrb = pUrb->pVUsb->pNext;
406 }
407
408 if (!pUrb)
409 {
410 /* allocate a new one. */
411 cbDataAllocated = cbMem <= _4K ? RT_ALIGN_32(cbMem, _1K)
412 : cbMem <= _32K ? RT_ALIGN_32(cbMem, _4K)
413 : RT_ALIGN_32(cbMem, 16*_1K);
414
415 pUrb = (PVUSBURB)RTMemAllocZ(RT_OFFSETOF(VUSBURB, abData[cbDataAllocated]));
416 if (RT_UNLIKELY(!pUrb))
417 {
418 RTCritSectLeave(&pRh->CritSectFreeUrbs);
419 AssertLogRelFailedReturn(NULL);
420 }
421
422 pRh->cUrbsInPool++;
423 pUrb->u32Magic = VUSBURB_MAGIC;
424
425 }
426 RTCritSectLeave(&pRh->CritSectFreeUrbs);
427
428 /*
429 * (Re)init the URB
430 */
431 uint32_t offAlloc = cbData;
432 pUrb->enmState = VUSBURBSTATE_ALLOCATED;
433 pUrb->fCompleting = false;
434 pUrb->pszDesc = NULL;
435 pUrb->pVUsb = (PVUSBURBVUSB)&pUrb->abData[offAlloc];
436 offAlloc += sizeof(VUSBURBVUSBINT);
437 pUrb->pVUsb->pvFreeCtx = pRh;
438 pUrb->pVUsb->pfnFree = vusbRhFreeUrb;
439 pUrb->pVUsb->cbDataAllocated = cbDataAllocated;
440 pUrb->pVUsb->pNext = NULL;
441 pUrb->pVUsb->ppPrev = NULL;
442 pUrb->pVUsb->pCtrlUrb = NULL;
443 pUrb->pVUsb->u64SubmitTS = 0;
444 pUrb->pVUsb->pvReadAhead = NULL;
445 pUrb->pVUsb->pDev = pDev ? pDev : vusbRhFindDevByAddress(pRh, DstAddress);
446 pUrb->Dev.pvPrivate = NULL;
447 pUrb->Dev.pNext = NULL;
448 pUrb->DstAddress = DstAddress;
449 pUrb->EndPt = ~0;
450 pUrb->enmType = enmType;
451 pUrb->enmDir = enmDir;
452 pUrb->fShortNotOk = false;
453 pUrb->enmStatus = VUSBSTATUS_INVALID;
454 pUrb->cbData = cbData;
455 pUrb->pHci = pRh->cbHci ? (PVUSBURBHCI)&pUrb->abData[offAlloc] : NULL;
456 offAlloc += pRh->cbHci;
457 pUrb->paTds = (pRh->cbHciTd && cTds) ? (PVUSBURBHCITD)&pUrb->abData[offAlloc] : NULL;
458
459#ifdef LOG_ENABLED
460 const char *pszType = NULL;
461
462 switch(pUrb->enmType)
463 {
464 case VUSBXFERTYPE_CTRL:
465 pszType = "ctrl";
466 break;
467 case VUSBXFERTYPE_INTR:
468 pszType = "intr";
469 break;
470 case VUSBXFERTYPE_BULK:
471 pszType = "bulk";
472 break;
473 case VUSBXFERTYPE_ISOC:
474 pszType = "isoc";
475 break;
476 default:
477 pszType = "invld";
478 break;
479 }
480
481 pRh->iSerial = (pRh->iSerial + 1) % 10000;
482 RTStrAPrintf(&pUrb->pszDesc, "URB %p %s%c%04d (%s)", pUrb, pszType,
483 (pUrb->enmDir == VUSBDIRECTION_IN) ? '<' : ((pUrb->enmDir == VUSBDIRECTION_SETUP) ? 's' : '>'),
484 pRh->iSerial, pszTag ? pszTag : "<none>");
485#endif
486
487 return pUrb;
488}
489
490
491/** @copydoc VUSBIROOTHUBCONNECTOR::pfnSetUrbParams */
492static DECLCALLBACK(int) vusbRhSetUrbParams(PVUSBIROOTHUBCONNECTOR pInterface, size_t cbHci, size_t cbHciTd)
493{
494 PVUSBROOTHUB pRh = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
495
496 pRh->cbHci = cbHci;
497 pRh->cbHciTd = cbHciTd;
498
499 return VINF_SUCCESS;
500}
501
502
503/** @copydoc VUSBIROOTHUBCONNECTOR::pfnNewUrb */
504static DECLCALLBACK(PVUSBURB) vusbRhConnNewUrb(PVUSBIROOTHUBCONNECTOR pInterface, uint8_t DstAddress, PVUSBIDEVICE pDev, VUSBXFERTYPE enmType,
505 VUSBDIRECTION enmDir, uint32_t cbData, uint32_t cTds, const char *pszTag)
506{
507 PVUSBROOTHUB pRh = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
508 return vusbRhNewUrb(pRh, DstAddress, (PVUSBDEV)pDev, enmType, enmDir, cbData, cTds, pszTag);
509}
510
511
512/** @copydoc VUSBIROOTHUBCONNECTOR::pfnFreeUrb */
513static DECLCALLBACK(int) vusbRhFreeUrb(PVUSBIROOTHUBCONNECTOR pInterface, PVUSBURB pUrb)
514{
515 PVUSBROOTHUB pRh = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
516
517 pUrb->pVUsb->pfnFree(pUrb);
518 return VINF_SUCCESS;
519}
520
521
522/** @copydoc VUSBIROOTHUBCONNECTOR::pfnSubmitUrb */
523static DECLCALLBACK(int) vusbRhSubmitUrb(PVUSBIROOTHUBCONNECTOR pInterface, PVUSBURB pUrb, PPDMLED pLed)
524{
525 PVUSBROOTHUB pRh = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
526 STAM_PROFILE_START(&pRh->StatSubmitUrb, a);
527
528#ifdef VBOX_WITH_STATISTICS
529 /*
530 * Total and per-type submit statistics.
531 */
532 Assert(pUrb->enmType >= 0 && pUrb->enmType < (int)RT_ELEMENTS(pRh->aTypes));
533 STAM_COUNTER_INC(&pRh->Total.StatUrbsSubmitted);
534 STAM_COUNTER_INC(&pRh->aTypes[pUrb->enmType].StatUrbsSubmitted);
535
536 STAM_COUNTER_ADD(&pRh->Total.StatReqBytes, pUrb->cbData);
537 STAM_COUNTER_ADD(&pRh->aTypes[pUrb->enmType].StatReqBytes, pUrb->cbData);
538 if (pUrb->enmDir == VUSBDIRECTION_IN)
539 {
540 STAM_COUNTER_ADD(&pRh->Total.StatReqReadBytes, pUrb->cbData);
541 STAM_COUNTER_ADD(&pRh->aTypes[pUrb->enmType].StatReqReadBytes, pUrb->cbData);
542 }
543 else
544 {
545 STAM_COUNTER_ADD(&pRh->Total.StatReqWriteBytes, pUrb->cbData);
546 STAM_COUNTER_ADD(&pRh->aTypes[pUrb->enmType].StatReqWriteBytes, pUrb->cbData);
547 }
548
549 if (pUrb->enmType == VUSBXFERTYPE_ISOC)
550 {
551 STAM_COUNTER_ADD(&pRh->StatIsocReqPkts, pUrb->cIsocPkts);
552 if (pUrb->enmDir == VUSBDIRECTION_IN)
553 STAM_COUNTER_ADD(&pRh->StatIsocReqReadPkts, pUrb->cIsocPkts);
554 else
555 STAM_COUNTER_ADD(&pRh->StatIsocReqWritePkts, pUrb->cIsocPkts);
556 }
557#endif
558
559 /* If there is a sniffer on the roothub record the URB there. */
560 if (pRh->hSniffer != VUSBSNIFFER_NIL)
561 {
562 int rc = VUSBSnifferRecordEvent(pRh->hSniffer, pUrb, VUSBSNIFFEREVENT_SUBMIT);
563 if (RT_FAILURE(rc))
564 LogRel(("VUSB: Capturing URB submit event on the root hub failed with %Rrc\n", rc));
565 }
566
567 /*
568 * The device was resolved when we allocated the URB.
569 * Submit it to the device if we found it, if not fail with device-not-ready.
570 */
571 int rc;
572 if ( pUrb->pVUsb->pDev
573 && pUrb->pVUsb->pDev->pUsbIns)
574 {
575 switch (pUrb->enmDir)
576 {
577 case VUSBDIRECTION_IN:
578 pLed->Asserted.s.fReading = pLed->Actual.s.fReading = 1;
579 rc = vusbUrbSubmit(pUrb);
580 pLed->Actual.s.fReading = 0;
581 break;
582 case VUSBDIRECTION_OUT:
583 pLed->Asserted.s.fWriting = pLed->Actual.s.fWriting = 1;
584 rc = vusbUrbSubmit(pUrb);
585 pLed->Actual.s.fWriting = 0;
586 break;
587 default:
588 rc = vusbUrbSubmit(pUrb);
589 break;
590 }
591
592 if (RT_FAILURE(rc))
593 {
594 LogFlow(("vusbRhSubmitUrb: freeing pUrb=%p\n", pUrb));
595 pUrb->pVUsb->pfnFree(pUrb);
596 }
597 }
598 else
599 {
600 pUrb->pVUsb->pDev = &pRh->Hub.Dev;
601 Log(("vusb: pRh=%p: SUBMIT: Address %i not found!!!\n", pRh, pUrb->DstAddress));
602
603 pUrb->enmState = VUSBURBSTATE_REAPED;
604 pUrb->enmStatus = VUSBSTATUS_DNR;
605 vusbUrbCompletionRh(pUrb);
606 rc = VINF_SUCCESS;
607 }
608
609 STAM_PROFILE_STOP(&pRh->StatSubmitUrb, a);
610 return rc;
611}
612
613
614static DECLCALLBACK(int) vusbRhReapAsyncUrbsWorker(PVUSBDEV pDev, RTMSINTERVAL cMillies)
615{
616 if (!cMillies)
617 vusbUrbDoReapAsync(pDev->pAsyncUrbHead, 0);
618 else
619 {
620 uint64_t u64Start = RTTimeMilliTS();
621 do
622 {
623 vusbUrbDoReapAsync(pDev->pAsyncUrbHead, RT_MIN(cMillies >> 8, 10));
624 } while ( pDev->pAsyncUrbHead
625 && RTTimeMilliTS() - u64Start < cMillies);
626 }
627
628 return VINF_SUCCESS;
629}
630
631/** @copydoc VUSBIROOTHUBCONNECTOR::pfnReapAsyncUrbs */
632static DECLCALLBACK(void) vusbRhReapAsyncUrbs(PVUSBIROOTHUBCONNECTOR pInterface, PVUSBIDEVICE pDevice, RTMSINTERVAL cMillies)
633{
634 PVUSBROOTHUB pRh = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
635 PVUSBDEV pDev = (PVUSBDEV)pDevice;
636
637 if (!pDev->pAsyncUrbHead)
638 return;
639
640 STAM_PROFILE_START(&pRh->StatReapAsyncUrbs, a);
641 int rc = vusbDevIoThreadExecSync(pDev, (PFNRT)vusbRhReapAsyncUrbsWorker, 2, pDev, cMillies);
642 AssertRC(rc);
643 STAM_PROFILE_STOP(&pRh->StatReapAsyncUrbs, a);
644}
645
646
647/** @copydoc VUSBIROOTHUBCONNECTOR::pfnCancelUrbsEp */
648static DECLCALLBACK(int) vusbRhCancelUrbsEp(PVUSBIROOTHUBCONNECTOR pInterface, PVUSBURB pUrb)
649{
650 PVUSBROOTHUB pRh = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
651 AssertReturn(pRh, VERR_INVALID_PARAMETER);
652 AssertReturn(pUrb, VERR_INVALID_PARAMETER);
653
654 //@todo: This method of URB canceling may not work on non-Linux hosts.
655 /*
656 * Cancel and reap the URB(s) on an endpoint.
657 */
658 LogFlow(("vusbRhCancelUrbsEp: pRh=%p pUrb=%p\n", pRh, pUrb));
659
660 vusbUrbCancelAsync(pUrb, CANCELMODE_UNDO);
661
662 /* The reaper thread will take care of completing the URB. */
663
664 return VINF_SUCCESS;
665}
666
667/**
668 * Worker doing the actual cancelling of all outstanding URBs on the device I/O thread.
669 *
670 * @returns VBox status code.
671 * @param pDev USB device instance data.
672 */
673static DECLCALLBACK(int) vusbRhCancelAllUrbsWorker(PVUSBDEV pDev)
674{
675 /*
676 * Cancel the URBS.
677 *
678 * Not using th CritAsyncUrbs critical section here is safe
679 * as the I/O thread is the only thread accessing this struture at the
680 * moment.
681 */
682 PVUSBURB pUrb = pDev->pAsyncUrbHead;
683
684 while (pUrb)
685 {
686 PVUSBURB pNext = pUrb->pVUsb->pNext;
687 /* Call the worker directly. */
688 vusbUrbCancelWorker(pUrb, CANCELMODE_FAIL);
689 pUrb = pNext;
690 }
691
692 return VINF_SUCCESS;
693}
694
695/** @copydoc VUSBIROOTHUBCONNECTOR::pfnCancelAllUrbs */
696static DECLCALLBACK(void) vusbRhCancelAllUrbs(PVUSBIROOTHUBCONNECTOR pInterface)
697{
698 PVUSBROOTHUB pRh = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
699
700 RTCritSectEnter(&pRh->CritSectDevices);
701 PVUSBDEV pDev = pRh->pDevices;
702 while (pDev)
703 {
704 vusbDevIoThreadExecSync(pDev, (PFNRT)vusbRhCancelAllUrbsWorker, 1, pDev);
705 pDev = pDev->pNext;
706 }
707 RTCritSectLeave(&pRh->CritSectDevices);
708}
709
710/**
711 * Worker doing the actual cancelling of all outstanding per-EP URBs on the
712 * device I/O thread.
713 *
714 * @returns VBox status code.
715 * @param pDev USB device instance data.
716 * @param EndPt Endpoint number.
717 * @param enmDir Endpoint direction.
718 */
719static DECLCALLBACK(int) vusbRhAbortEpWorker(PVUSBDEV pDev, int EndPt, VUSBDIRECTION enmDir)
720{
721 /*
722 * Iterate the URBs, find ones corresponding to given EP, and cancel them.
723 */
724 PVUSBURB pUrb = pDev->pAsyncUrbHead;
725 while (pUrb)
726 {
727 PVUSBURB pNext = pUrb->pVUsb->pNext;
728
729 Assert(pUrb->pVUsb->pDev == pDev);
730
731 if (pUrb->EndPt == EndPt && pUrb->enmDir == enmDir)
732 {
733 LogFlow(("%s: vusbRhAbortEpWorker: CANCELING URB\n", pUrb->pszDesc));
734 int rc = vusbUrbCancelWorker(pUrb, CANCELMODE_UNDO);
735 AssertRC(rc);
736 }
737 pUrb = pNext;
738 }
739
740 return VINF_SUCCESS;
741}
742
743
744/** @copydoc VUSBIROOTHUBCONNECTOR::pfnAbortEp */
745static DECLCALLBACK(int) vusbRhAbortEp(PVUSBIROOTHUBCONNECTOR pInterface, PVUSBIDEVICE pDevice, int EndPt, VUSBDIRECTION enmDir)
746{
747 PVUSBROOTHUB pRh = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
748 if (&pRh->Hub != ((PVUSBDEV)pDevice)->pHub)
749 AssertFailedReturn(VERR_INVALID_PARAMETER);
750
751 RTCritSectEnter(&pRh->CritSectDevices);
752 PVUSBDEV pDev = (PVUSBDEV)pDevice;
753 vusbDevIoThreadExecSync(pDev, (PFNRT)vusbRhAbortEpWorker, 3, pDev, EndPt, enmDir);
754 RTCritSectLeave(&pRh->CritSectDevices);
755
756 /* The reaper thread will take care of completing the URB. */
757
758 return VINF_SUCCESS;
759}
760
761
762/** @copydoc VUSBIROOTHUBCONNECTOR::pfnAttachDevice */
763static DECLCALLBACK(int) vusbRhAttachDevice(PVUSBIROOTHUBCONNECTOR pInterface, PVUSBIDEVICE pDevice)
764{
765 PVUSBROOTHUB pRh = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
766 return vusbHubAttach(&pRh->Hub, (PVUSBDEV)pDevice);
767}
768
769
770/** @copydoc VUSBIROOTHUBCONNECTOR::pfnDetachDevice */
771static DECLCALLBACK(int) vusbRhDetachDevice(PVUSBIROOTHUBCONNECTOR pInterface, PVUSBIDEVICE pDevice)
772{
773 PVUSBROOTHUB pRh = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
774 if (&pRh->Hub != ((PVUSBDEV)pDevice)->pHub)
775 AssertFailedReturn(VERR_INVALID_PARAMETER);
776 return vusbDevDetach((PVUSBDEV)pDevice);
777}
778
779
780/* -=-=-=-=-=- VUSB Device methods (for the root hub) -=-=-=-=-=- */
781
782
783/**
784 * @copydoc VUSBIDEVICE::pfnReset
785 */
786static DECLCALLBACK(int) vusbRhDevReset(PVUSBIDEVICE pInterface, bool fResetOnLinux, PFNVUSBRESETDONE pfnDone, void *pvUser, PVM pVM)
787{
788 PVUSBROOTHUB pRh = RT_FROM_MEMBER(pInterface, VUSBROOTHUB, Hub.Dev.IDevice);
789 Assert(!pfnDone);
790 return pRh->pIRhPort->pfnReset(pRh->pIRhPort, fResetOnLinux); /** @todo change rc from bool to vbox status everywhere! */
791}
792
793
794/**
795 * @copydoc VUSBIDEVICE::pfnPowerOn
796 */
797static DECLCALLBACK(int) vusbRhDevPowerOn(PVUSBIDEVICE pInterface)
798{
799 PVUSBROOTHUB pRh = RT_FROM_MEMBER(pInterface, VUSBROOTHUB, Hub.Dev.IDevice);
800 LogFlow(("vusbRhDevPowerOn: pRh=%p\n", pRh));
801
802 Assert( pRh->Hub.Dev.enmState != VUSB_DEVICE_STATE_DETACHED
803 && pRh->Hub.Dev.enmState != VUSB_DEVICE_STATE_RESET);
804
805 if (pRh->Hub.Dev.enmState == VUSB_DEVICE_STATE_ATTACHED)
806 pRh->Hub.Dev.enmState = VUSB_DEVICE_STATE_POWERED;
807
808 return VINF_SUCCESS;
809}
810
811
812/**
813 * @copydoc VUSBIDEVICE::pfnPowerOff
814 */
815static DECLCALLBACK(int) vusbRhDevPowerOff(PVUSBIDEVICE pInterface)
816{
817 PVUSBROOTHUB pRh = RT_FROM_MEMBER(pInterface, VUSBROOTHUB, Hub.Dev.IDevice);
818 LogFlow(("vusbRhDevPowerOff: pRh=%p\n", pRh));
819
820 Assert( pRh->Hub.Dev.enmState != VUSB_DEVICE_STATE_DETACHED
821 && pRh->Hub.Dev.enmState != VUSB_DEVICE_STATE_RESET);
822
823 /*
824 * Cancel all URBs and reap them.
825 */
826 VUSBIRhCancelAllUrbs(&pRh->IRhConnector);
827 RTCritSectEnter(&pRh->CritSectDevices);
828 PVUSBDEV pDev = pRh->pDevices;
829 while (pDev)
830 {
831 VUSBIRhReapAsyncUrbs(&pRh->IRhConnector, (PVUSBIDEVICE)pDev, 0);
832 pDev = pDev->pNext;
833 }
834 RTCritSectLeave(&pRh->CritSectDevices);
835
836 pRh->Hub.Dev.enmState = VUSB_DEVICE_STATE_ATTACHED;
837 return VINF_SUCCESS;
838}
839
840/**
841 * @copydoc VUSBIDEVICE::pfnGetState
842 */
843static DECLCALLBACK(VUSBDEVICESTATE) vusbRhDevGetState(PVUSBIDEVICE pInterface)
844{
845 PVUSBROOTHUB pRh = RT_FROM_MEMBER(pInterface, VUSBROOTHUB, Hub.Dev.IDevice);
846 return pRh->Hub.Dev.enmState;
847}
848
849
850
851
852/* -=-=-=-=-=- VUSB Hub methods -=-=-=-=-=- */
853
854
855/**
856 * Attach the device to the hub.
857 * Port assignments and all such stuff is up to this routine.
858 *
859 * @returns VBox status code.
860 * @param pHub Pointer to the hub.
861 * @param pDev Pointer to the device.
862 */
863static int vusbRhHubOpAttach(PVUSBHUB pHub, PVUSBDEV pDev)
864{
865 PVUSBROOTHUB pRh = (PVUSBROOTHUB)pHub;
866
867 /*
868 * Assign a port.
869 */
870 int iPort = ASMBitFirstSet(&pRh->Bitmap, sizeof(pRh->Bitmap) * 8);
871 if (iPort < 0)
872 {
873 LogRel(("VUSB: No ports available!\n"));
874 return VERR_VUSB_NO_PORTS;
875 }
876 ASMBitClear(&pRh->Bitmap, iPort);
877 pHub->cDevices++;
878 pDev->i16Port = iPort;
879
880 /*
881 * Call the HCI attach routine and let it have its say before the device is
882 * linked into the device list of this hub.
883 */
884 int rc = pRh->pIRhPort->pfnAttach(pRh->pIRhPort, &pDev->IDevice, iPort);
885 if (RT_SUCCESS(rc))
886 {
887 RTCritSectEnter(&pRh->CritSectDevices);
888 pDev->pNext = pRh->pDevices;
889 pRh->pDevices = pDev;
890 RTCritSectLeave(&pRh->CritSectDevices);
891 LogRel(("VUSB: Attached '%s' to port %d\n", pDev->pUsbIns->pszName, iPort));
892 }
893 else
894 {
895 ASMBitSet(&pRh->Bitmap, iPort);
896 pHub->cDevices--;
897 pDev->i16Port = -1;
898 LogRel(("VUSB: Failed to attach '%s' to port %d, rc=%Rrc\n", pDev->pUsbIns->pszName, iPort, rc));
899 }
900 return rc;
901}
902
903
904/**
905 * Detach the device from the hub.
906 *
907 * @returns VBox status code.
908 * @param pHub Pointer to the hub.
909 * @param pDev Pointer to the device.
910 */
911static void vusbRhHubOpDetach(PVUSBHUB pHub, PVUSBDEV pDev)
912{
913 PVUSBROOTHUB pRh = (PVUSBROOTHUB)pHub;
914 Assert(pDev->i16Port != -1);
915
916 /*
917 * Check that it's attached and unlink it from the linked list.
918 */
919 RTCritSectEnter(&pRh->CritSectDevices);
920 if (pRh->pDevices != pDev)
921 {
922 PVUSBDEV pPrev = pRh->pDevices;
923 while (pPrev && pPrev->pNext != pDev)
924 pPrev = pPrev->pNext;
925 Assert(pPrev);
926 pPrev->pNext = pDev->pNext;
927 }
928 else
929 pRh->pDevices = pDev->pNext;
930 pDev->pNext = NULL;
931 RTCritSectLeave(&pRh->CritSectDevices);
932
933 /*
934 * Detach the device and mark the port as available.
935 */
936 unsigned uPort = pDev->i16Port;
937 pRh->pIRhPort->pfnDetach(pRh->pIRhPort, &pDev->IDevice, uPort);
938 LogRel(("VUSB: Detached '%s' from port %u\n", pDev->pUsbIns->pszName, uPort));
939 ASMBitSet(&pRh->Bitmap, uPort);
940 pHub->cDevices--;
941}
942
943
944/**
945 * The Hub methods implemented by the root hub.
946 */
947static const VUSBHUBOPS s_VUsbRhHubOps =
948{
949 vusbRhHubOpAttach,
950 vusbRhHubOpDetach
951};
952
953
954
955/* -=-=-=-=-=- PDM Base interface methods -=-=-=-=-=- */
956
957
958/**
959 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
960 */
961static DECLCALLBACK(void *) vusbRhQueryInterface(PPDMIBASE pInterface, const char *pszIID)
962{
963 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
964 PVUSBROOTHUB pRh = PDMINS_2_DATA(pDrvIns, PVUSBROOTHUB);
965
966 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
967 PDMIBASE_RETURN_INTERFACE(pszIID, VUSBIROOTHUBCONNECTOR, &pRh->IRhConnector);
968 PDMIBASE_RETURN_INTERFACE(pszIID, VUSBIDEVICE, &pRh->Hub.Dev.IDevice);
969 return NULL;
970}
971
972
973/* -=-=-=-=-=- PDM Driver methods -=-=-=-=-=- */
974
975
976/**
977 * Destruct a driver instance.
978 *
979 * Most VM resources are freed by the VM. This callback is provided so that any non-VM
980 * resources can be freed correctly.
981 *
982 * @param pDrvIns The driver instance data.
983 */
984static DECLCALLBACK(void) vusbRhDestruct(PPDMDRVINS pDrvIns)
985{
986 PVUSBROOTHUB pRh = PDMINS_2_DATA(pDrvIns, PVUSBROOTHUB);
987 PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns);
988
989 /*
990 * Free all URBs.
991 */
992 while (pRh->pFreeUrbs)
993 {
994 PVUSBURB pUrb = pRh->pFreeUrbs;
995 pRh->pFreeUrbs = pUrb->pVUsb->pNext;
996
997 pUrb->u32Magic = 0;
998 pUrb->enmState = VUSBURBSTATE_INVALID;
999 pUrb->pVUsb->pNext = NULL;
1000 RTMemFree(pUrb);
1001 }
1002 if (pRh->Hub.pszName)
1003 {
1004 RTStrFree(pRh->Hub.pszName);
1005 pRh->Hub.pszName = NULL;
1006 }
1007 if (pRh->hSniffer != VUSBSNIFFER_NIL)
1008 VUSBSnifferDestroy(pRh->hSniffer);
1009 RTCritSectDelete(&pRh->CritSectDevices);
1010 RTCritSectDelete(&pRh->CritSectFreeUrbs);
1011}
1012
1013
1014/**
1015 * Construct a root hub driver instance.
1016 *
1017 * @copydoc FNPDMDRVCONSTRUCT
1018 */
1019static DECLCALLBACK(int) vusbRhConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
1020{
1021 LogFlow(("vusbRhConstruct: Instance %d\n", pDrvIns->iInstance));
1022 PVUSBROOTHUB pThis = PDMINS_2_DATA(pDrvIns, PVUSBROOTHUB);
1023 PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
1024
1025 /*
1026 * Validate configuration.
1027 */
1028 if (!CFGMR3AreValuesValid(pCfg, "CaptureFilename\0"))
1029 return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
1030
1031 /*
1032 * Check that there are no drivers below us.
1033 */
1034 AssertMsgReturn(PDMDrvHlpNoAttach(pDrvIns) == VERR_PDM_NO_ATTACHED_DRIVER,
1035 ("Configuration error: Not possible to attach anything to this driver!\n"),
1036 VERR_PDM_DRVINS_NO_ATTACH);
1037
1038 /*
1039 * Initialize the critical sections.
1040 */
1041 int rc = RTCritSectInit(&pThis->CritSectDevices);
1042 if (RT_FAILURE(rc))
1043 return rc;
1044
1045 rc = RTCritSectInit(&pThis->CritSectFreeUrbs);
1046 if (RT_FAILURE(rc))
1047 return rc;
1048
1049 char *pszCaptureFilename = NULL;
1050 rc = CFGMR3QueryStringAlloc(pCfg, "CaptureFilename", &pszCaptureFilename);
1051 if ( RT_FAILURE(rc)
1052 && rc != VERR_CFGM_VALUE_NOT_FOUND)
1053 return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS,
1054 N_("Configuration error: Failed to query value of \"CaptureFilename\""));
1055
1056 /*
1057 * Initialize the data members.
1058 */
1059 pDrvIns->IBase.pfnQueryInterface = vusbRhQueryInterface;
1060 /* the usb device */
1061 pThis->Hub.Dev.enmState = VUSB_DEVICE_STATE_ATTACHED;
1062 pThis->Hub.Dev.u8Address = VUSB_INVALID_ADDRESS;
1063 pThis->Hub.Dev.u8NewAddress = VUSB_INVALID_ADDRESS;
1064 pThis->Hub.Dev.i16Port = -1;
1065 pThis->Hub.Dev.IDevice.pfnReset = vusbRhDevReset;
1066 pThis->Hub.Dev.IDevice.pfnPowerOn = vusbRhDevPowerOn;
1067 pThis->Hub.Dev.IDevice.pfnPowerOff = vusbRhDevPowerOff;
1068 pThis->Hub.Dev.IDevice.pfnGetState = vusbRhDevGetState;
1069 /* the hub */
1070 pThis->Hub.pOps = &s_VUsbRhHubOps;
1071 pThis->Hub.pRootHub = pThis;
1072 //pThis->hub.cPorts - later
1073 pThis->Hub.cDevices = 0;
1074 pThis->Hub.Dev.pHub = &pThis->Hub;
1075 RTStrAPrintf(&pThis->Hub.pszName, "RootHub#%d", pDrvIns->iInstance);
1076 /* misc */
1077 pThis->pDrvIns = pDrvIns;
1078 /* the connector */
1079 pThis->IRhConnector.pfnSetUrbParams = vusbRhSetUrbParams;
1080 pThis->IRhConnector.pfnNewUrb = vusbRhConnNewUrb;
1081 pThis->IRhConnector.pfnSubmitUrb = vusbRhSubmitUrb;
1082 pThis->IRhConnector.pfnReapAsyncUrbs= vusbRhReapAsyncUrbs;
1083 pThis->IRhConnector.pfnCancelUrbsEp = vusbRhCancelUrbsEp;
1084 pThis->IRhConnector.pfnCancelAllUrbs= vusbRhCancelAllUrbs;
1085 pThis->IRhConnector.pfnAbortEp = vusbRhAbortEp;
1086 pThis->IRhConnector.pfnAttachDevice = vusbRhAttachDevice;
1087 pThis->IRhConnector.pfnDetachDevice = vusbRhDetachDevice;
1088 pThis->hSniffer = VUSBSNIFFER_NIL;
1089 pThis->cbHci = 0;
1090 pThis->cbHciTd = 0;
1091#ifdef LOG_ENABLED
1092 pThis->iSerial = 0;
1093#endif
1094 /*
1095 * Resolve interface(s).
1096 */
1097 pThis->pIRhPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, VUSBIROOTHUBPORT);
1098 AssertMsgReturn(pThis->pIRhPort, ("Configuration error: the device/driver above us doesn't expose any VUSBIROOTHUBPORT interface!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE);
1099
1100 /*
1101 * Get number of ports and the availability bitmap.
1102 * ASSUME that the number of ports reported now at creation time is the max number.
1103 */
1104 pThis->Hub.cPorts = pThis->pIRhPort->pfnGetAvailablePorts(pThis->pIRhPort, &pThis->Bitmap);
1105 Log(("vusbRhConstruct: cPorts=%d\n", pThis->Hub.cPorts));
1106
1107 /*
1108 * Get the USB version of the attached HC.
1109 * ASSUME that version 2.0 implies high-speed.
1110 */
1111 pThis->fHcVersions = pThis->pIRhPort->pfnGetUSBVersions(pThis->pIRhPort);
1112 Log(("vusbRhConstruct: fHcVersions=%u\n", pThis->fHcVersions));
1113
1114 if (pszCaptureFilename)
1115 {
1116 rc = VUSBSnifferCreate(&pThis->hSniffer, 0, pszCaptureFilename, NULL, NULL);
1117 if (RT_FAILURE(rc))
1118 return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS,
1119 N_("VUSBSniffer cannot open '%s' for writing. The directory must exist and it must be writable for the current user"),
1120 pszCaptureFilename);
1121
1122 MMR3HeapFree(pszCaptureFilename);
1123 }
1124
1125 /*
1126 * Register ourselves as a USB hub.
1127 * The current implementation uses the VUSBIRHCONFIG interface for communication.
1128 */
1129 PCPDMUSBHUBHLP pHlp; /* not used currently */
1130 rc = PDMDrvHlpUSBRegisterHub(pDrvIns, pThis->fHcVersions, pThis->Hub.cPorts, &g_vusbHubReg, &pHlp);
1131 if (RT_FAILURE(rc))
1132 return rc;
1133
1134 /*
1135 * Statistics. (It requires a 30" monitor or extremely tiny fonts to edit this "table".)
1136 */
1137#ifdef VBOX_WITH_STATISTICS
1138 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->Total.StatUrbsSubmitted, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "The number of URBs submitted.", "/VUSB/%d/UrbsSubmitted", pDrvIns->iInstance);
1139 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatUrbsSubmitted, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Bulk transfer.", "/VUSB/%d/UrbsSubmitted/Bulk", pDrvIns->iInstance);
1140 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatUrbsSubmitted, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Control transfer.", "/VUSB/%d/UrbsSubmitted/Ctrl", pDrvIns->iInstance);
1141 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatUrbsSubmitted, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Interrupt transfer.", "/VUSB/%d/UrbsSubmitted/Intr", pDrvIns->iInstance);
1142 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatUrbsSubmitted, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Isochronous transfer.", "/VUSB/%d/UrbsSubmitted/Isoc", pDrvIns->iInstance);
1143
1144 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->Total.StatUrbsCancelled, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "The number of URBs cancelled. (included in failed)", "/VUSB/%d/UrbsCancelled", pDrvIns->iInstance);
1145 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatUrbsCancelled, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Bulk transfer.", "/VUSB/%d/UrbsCancelled/Bulk", pDrvIns->iInstance);
1146 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatUrbsCancelled, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Control transfer.", "/VUSB/%d/UrbsCancelled/Ctrl", pDrvIns->iInstance);
1147 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatUrbsCancelled, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Interrupt transfer.", "/VUSB/%d/UrbsCancelled/Intr", pDrvIns->iInstance);
1148 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatUrbsCancelled, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Isochronous transfer.", "/VUSB/%d/UrbsCancelled/Isoc", pDrvIns->iInstance);
1149
1150 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->Total.StatUrbsFailed, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "The number of URBs failing.", "/VUSB/%d/UrbsFailed", pDrvIns->iInstance);
1151 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatUrbsFailed, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Bulk transfer.", "/VUSB/%d/UrbsFailed/Bulk", pDrvIns->iInstance);
1152 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatUrbsFailed, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Control transfer.", "/VUSB/%d/UrbsFailed/Ctrl", pDrvIns->iInstance);
1153 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatUrbsFailed, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Interrupt transfer.", "/VUSB/%d/UrbsFailed/Intr", pDrvIns->iInstance);
1154 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatUrbsFailed, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Isochronous transfer.", "/VUSB/%d/UrbsFailed/Isoc", pDrvIns->iInstance);
1155
1156 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->Total.StatReqBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Total requested transfer.", "/VUSB/%d/ReqBytes", pDrvIns->iInstance);
1157 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatReqBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Bulk transfer.", "/VUSB/%d/ReqBytes/Bulk", pDrvIns->iInstance);
1158 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatReqBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Control transfer.", "/VUSB/%d/ReqBytes/Ctrl", pDrvIns->iInstance);
1159 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatReqBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Interrupt transfer.", "/VUSB/%d/ReqBytes/Intr", pDrvIns->iInstance);
1160 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatReqBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Isochronous transfer.", "/VUSB/%d/ReqBytes/Isoc", pDrvIns->iInstance);
1161
1162 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->Total.StatReqReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Total requested read transfer.", "/VUSB/%d/ReqReadBytes", pDrvIns->iInstance);
1163 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatReqReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Bulk transfer.", "/VUSB/%d/ReqReadBytes/Bulk", pDrvIns->iInstance);
1164 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatReqReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Control transfer.", "/VUSB/%d/ReqReadBytes/Ctrl", pDrvIns->iInstance);
1165 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatReqReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Interrupt transfer.", "/VUSB/%d/ReqReadBytes/Intr", pDrvIns->iInstance);
1166 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatReqReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Isochronous transfer.", "/VUSB/%d/ReqReadBytes/Isoc", pDrvIns->iInstance);
1167
1168 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->Total.StatReqWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Total requested write transfer.", "/VUSB/%d/ReqWriteBytes", pDrvIns->iInstance);
1169 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatReqWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Bulk transfer.", "/VUSB/%d/ReqWriteBytes/Bulk", pDrvIns->iInstance);
1170 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatReqWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Control transfer.", "/VUSB/%d/ReqWriteBytes/Ctrl", pDrvIns->iInstance);
1171 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatReqWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Interrupt transfer.", "/VUSB/%d/ReqWriteBytes/Intr", pDrvIns->iInstance);
1172 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatReqWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Isochronous transfer.", "/VUSB/%d/ReqWriteBytes/Isoc", pDrvIns->iInstance);
1173
1174 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->Total.StatActBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Actual total transfer.", "/VUSB/%d/ActBytes", pDrvIns->iInstance);
1175 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatActBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Bulk transfer.", "/VUSB/%d/ActBytes/Bulk", pDrvIns->iInstance);
1176 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatActBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Control transfer.", "/VUSB/%d/ActBytes/Ctrl", pDrvIns->iInstance);
1177 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatActBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Interrupt transfer.", "/VUSB/%d/ActBytes/Intr", pDrvIns->iInstance);
1178 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatActBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Isochronous transfer.", "/VUSB/%d/ActBytes/Isoc", pDrvIns->iInstance);
1179
1180 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->Total.StatActReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Actual total read transfer.", "/VUSB/%d/ActReadBytes", pDrvIns->iInstance);
1181 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatActReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Bulk transfer.", "/VUSB/%d/ActReadBytes/Bulk", pDrvIns->iInstance);
1182 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatActReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Control transfer.", "/VUSB/%d/ActReadBytes/Ctrl", pDrvIns->iInstance);
1183 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatActReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Interrupt transfer.", "/VUSB/%d/ActReadBytes/Intr", pDrvIns->iInstance);
1184 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatActReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Isochronous transfer.", "/VUSB/%d/ActReadBytes/Isoc", pDrvIns->iInstance);
1185
1186 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->Total.StatActWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Actual total write transfer.", "/VUSB/%d/ActWriteBytes", pDrvIns->iInstance);
1187 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatActWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Bulk transfer.", "/VUSB/%d/ActWriteBytes/Bulk", pDrvIns->iInstance);
1188 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatActWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Control transfer.", "/VUSB/%d/ActWriteBytes/Ctrl", pDrvIns->iInstance);
1189 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatActWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Interrupt transfer.", "/VUSB/%d/ActWriteBytes/Intr", pDrvIns->iInstance);
1190 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatActWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Isochronous transfer.", "/VUSB/%d/ActWriteBytes/Isoc", pDrvIns->iInstance);
1191
1192 /* bulk */
1193 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatUrbsSubmitted, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of submitted URBs.", "/VUSB/%d/Bulk/Urbs", pDrvIns->iInstance);
1194 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatUrbsFailed, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of failed URBs.", "/VUSB/%d/Bulk/UrbsFailed", pDrvIns->iInstance);
1195 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatUrbsCancelled, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of cancelled URBs.", "/VUSB/%d/Bulk/UrbsFailed/Cancelled", pDrvIns->iInstance);
1196 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatActBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Number of bytes transferred.", "/VUSB/%d/Bulk/ActBytes", pDrvIns->iInstance);
1197 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatActReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Read.", "/VUSB/%d/Bulk/ActBytes/Read", pDrvIns->iInstance);
1198 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatActWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Write.", "/VUSB/%d/Bulk/ActBytes/Write", pDrvIns->iInstance);
1199 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatReqBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Requested number of bytes.", "/VUSB/%d/Bulk/ReqBytes", pDrvIns->iInstance);
1200 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatReqReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Read.", "/VUSB/%d/Bulk/ReqBytes/Read", pDrvIns->iInstance);
1201 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatReqWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Write.", "/VUSB/%d/Bulk/ReqBytes/Write", pDrvIns->iInstance);
1202
1203 /* control */
1204 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatUrbsSubmitted, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of submitted URBs.", "/VUSB/%d/Ctrl/Urbs", pDrvIns->iInstance);
1205 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatUrbsFailed, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of failed URBs.", "/VUSB/%d/Ctrl/UrbsFailed", pDrvIns->iInstance);
1206 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatUrbsCancelled, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of cancelled URBs.", "/VUSB/%d/Ctrl/UrbsFailed/Cancelled", pDrvIns->iInstance);
1207 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatActBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Number of bytes transferred.", "/VUSB/%d/Ctrl/ActBytes", pDrvIns->iInstance);
1208 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatActReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Read.", "/VUSB/%d/Ctrl/ActBytes/Read", pDrvIns->iInstance);
1209 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatActWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Write.", "/VUSB/%d/Ctrl/ActBytes/Write", pDrvIns->iInstance);
1210 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatReqBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Requested number of bytes.", "/VUSB/%d/Ctrl/ReqBytes", pDrvIns->iInstance);
1211 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatReqReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Read.", "/VUSB/%d/Ctrl/ReqBytes/Read", pDrvIns->iInstance);
1212 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatReqWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Write.", "/VUSB/%d/Ctrl/ReqBytes/Write", pDrvIns->iInstance);
1213
1214 /* interrupt */
1215 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatUrbsSubmitted, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of submitted URBs.", "/VUSB/%d/Intr/Urbs", pDrvIns->iInstance);
1216 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatUrbsFailed, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of failed URBs.", "/VUSB/%d/Intr/UrbsFailed", pDrvIns->iInstance);
1217 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatUrbsCancelled, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of cancelled URBs.", "/VUSB/%d/Intr/UrbsFailed/Cancelled", pDrvIns->iInstance);
1218 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatActBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Number of bytes transferred.", "/VUSB/%d/Intr/ActBytes", pDrvIns->iInstance);
1219 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatActReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Read.", "/VUSB/%d/Intr/ActBytes/Read", pDrvIns->iInstance);
1220 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatActWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Write.", "/VUSB/%d/Intr/ActBytes/Write", pDrvIns->iInstance);
1221 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatReqBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Requested number of bytes.", "/VUSB/%d/Intr/ReqBytes", pDrvIns->iInstance);
1222 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatReqReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Read.", "/VUSB/%d/Intr/ReqBytes/Read", pDrvIns->iInstance);
1223 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatReqWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Write.", "/VUSB/%d/Intr/ReqBytes/Write", pDrvIns->iInstance);
1224
1225 /* isochronous */
1226 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatUrbsSubmitted, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of submitted URBs.", "/VUSB/%d/Isoc/Urbs", pDrvIns->iInstance);
1227 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatUrbsFailed, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of failed URBs.", "/VUSB/%d/Isoc/UrbsFailed", pDrvIns->iInstance);
1228 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatUrbsCancelled, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of cancelled URBs.", "/VUSB/%d/Isoc/UrbsFailed/Cancelled", pDrvIns->iInstance);
1229 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatActBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Number of bytes transferred.", "/VUSB/%d/Isoc/ActBytes", pDrvIns->iInstance);
1230 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatActReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Read.", "/VUSB/%d/Isoc/ActBytes/Read", pDrvIns->iInstance);
1231 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatActWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Write.", "/VUSB/%d/Isoc/ActBytes/Write", pDrvIns->iInstance);
1232 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatReqBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Requested number of bytes.", "/VUSB/%d/Isoc/ReqBytes", pDrvIns->iInstance);
1233 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatReqReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Read.", "/VUSB/%d/Isoc/ReqBytes/Read", pDrvIns->iInstance);
1234 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatReqWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Write.", "/VUSB/%d/Isoc/ReqBytes/Write", pDrvIns->iInstance);
1235 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->StatIsocActPkts, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of isochronous packets returning data.", "/VUSB/%d/Isoc/ActPkts", pDrvIns->iInstance);
1236 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->StatIsocActReadPkts, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Read.", "/VUSB/%d/Isoc/ActPkts/Read", pDrvIns->iInstance);
1237 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->StatIsocActWritePkts, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Write.", "/VUSB/%d/Isoc/ActPkts/Write", pDrvIns->iInstance);
1238 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->StatIsocReqPkts, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Requested number of isochronous packets.", "/VUSB/%d/Isoc/ReqPkts", pDrvIns->iInstance);
1239 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->StatIsocReqReadPkts, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Read.", "/VUSB/%d/Isoc/ReqPkts/Read", pDrvIns->iInstance);
1240 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->StatIsocReqWritePkts, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Write.", "/VUSB/%d/Isoc/ReqPkts/Write", pDrvIns->iInstance);
1241
1242 for (unsigned i = 0; i < RT_ELEMENTS(pThis->aStatIsocDetails); i++)
1243 {
1244 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aStatIsocDetails[i].Pkts, STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_COUNT, ".", "/VUSB/%d/Isoc/%d", pDrvIns->iInstance, i);
1245 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aStatIsocDetails[i].Ok, STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_COUNT, ".", "/VUSB/%d/Isoc/%d/Ok", pDrvIns->iInstance, i);
1246 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aStatIsocDetails[i].Ok0, STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_COUNT, ".", "/VUSB/%d/Isoc/%d/Ok0", pDrvIns->iInstance, i);
1247 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aStatIsocDetails[i].DataUnderrun, STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_COUNT, ".", "/VUSB/%d/Isoc/%d/DataUnderrun", pDrvIns->iInstance, i);
1248 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aStatIsocDetails[i].DataUnderrun0, STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_COUNT, ".", "/VUSB/%d/Isoc/%d/DataUnderrun0", pDrvIns->iInstance, i);
1249 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aStatIsocDetails[i].DataOverrun, STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_COUNT, ".", "/VUSB/%d/Isoc/%d/DataOverrun", pDrvIns->iInstance, i);
1250 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aStatIsocDetails[i].NotAccessed, STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_COUNT, ".", "/VUSB/%d/Isoc/%d/NotAccessed", pDrvIns->iInstance, i);
1251 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aStatIsocDetails[i].Misc, STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_COUNT, ".", "/VUSB/%d/Isoc/%d/Misc", pDrvIns->iInstance, i);
1252 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aStatIsocDetails[i].Bytes, STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_BYTES, ".", "/VUSB/%d/Isoc/%d/Bytes", pDrvIns->iInstance, i);
1253 }
1254
1255 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);
1256 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->StatSubmitUrb, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, "Profiling the vusbRhSubmitUrb body.", "/VUSB/%d/SubmitUrb", pDrvIns->iInstance);
1257#endif
1258 PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->cUrbsInPool, STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "The number of URBs in the pool.", "/VUSB/%d/cUrbsInPool", pDrvIns->iInstance);
1259
1260 return VINF_SUCCESS;
1261}
1262
1263
1264/**
1265 * VUSB Root Hub driver registration record.
1266 */
1267const PDMDRVREG g_DrvVUSBRootHub =
1268{
1269 /* u32Version */
1270 PDM_DRVREG_VERSION,
1271 /* szName */
1272 "VUSBRootHub",
1273 /* szRCMod */
1274 "",
1275 /* szR0Mod */
1276 "",
1277 /* pszDescription */
1278 "VUSB Root Hub Driver.",
1279 /* fFlags */
1280 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
1281 /* fClass. */
1282 PDM_DRVREG_CLASS_USB,
1283 /* cMaxInstances */
1284 ~0U,
1285 /* cbInstance */
1286 sizeof(VUSBROOTHUB),
1287 /* pfnConstruct */
1288 vusbRhConstruct,
1289 /* pfnDestruct */
1290 vusbRhDestruct,
1291 /* pfnRelocate */
1292 NULL,
1293 /* pfnIOCtl */
1294 NULL,
1295 /* pfnPowerOn */
1296 NULL,
1297 /* pfnReset */
1298 NULL,
1299 /* pfnSuspend */
1300 NULL,
1301 /* pfnResume */
1302 NULL,
1303 /* pfnAttach */
1304 NULL,
1305 /* pfnDetach */
1306 NULL,
1307 /* pfnPowerOff */
1308 NULL,
1309 /* pfnSoftReset */
1310 NULL,
1311 /* u32EndVersion */
1312 PDM_DRVREG_VERSION
1313};
1314
1315/*
1316 * Local Variables:
1317 * mode: c
1318 * c-file-style: "bsd"
1319 * c-basic-offset: 4
1320 * tab-width: 4
1321 * indent-tabs-mode: s
1322 * End:
1323 */
1324
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