Large USB transfers may not be completed on Windows Server systems with 4GB of memory or more


Symptoms


Large transfers to USB devices (for example, 256KB or larger) may not be completed successfully by the Microsoft Windows USB stack, but simply appear to hang (fail to complete). In such cases, the pending transfer must be cancelled by the USB client device driver that submitted the transfer to the USB stack.

This problem may occur on Windows Server 2003 and Windows Server 2008 32-bit (x86) systems with 4 GB (4 Gigabytes) or more of physical memory, or any physical memory located at addresses above 4 GB.

Cause


On Windows Server 2003 and Windows Server 2008 32-bit (x86) systems with 4 GB (4 Gigabytes) or more of physical memory, or any physical memory located at addresses above 4 GB, the Page Address Extension (PAE) kernel is loaded, and System Map Registers are used to map physical memory addresses of buffers that are used for Direct Memory Access (DMA) transfers. In such scenarios, only a limited number of System Map Registers are available to be used for mapping physical memory buffers used for DMA transfers.

If the buffer for a USB transfer spans more than 16 (sixteen) 4-KB pages, the buffer may fail to be mapped into the DMA scatter-gather lists to be submitted to the USB host controller by the USB host controller driver. This may occur as a result of how the USB host controller port driver (Usbport) allocates system Map Registers from the system master DMA adapter for the purpose of mapping DMA transfers to be processed by the USB host controller. Usbport initially requests 16 system Map Registers for mapping the USB transfer buffers to the host controller, each of which can map a single 4-KB (4 kilobyte, or 4096 byte) page. If additional system Map Registers are required in order to map larger transfer buffers, Usbport requests additional system Map Registers from the system master DMA adapter.

Requests from Usbport for additional system Map Registers are issued while Usbport is mapping the USB transfer request submitted by the USB client driver to physical memory addresses that can be accessed by the USB host controller. If the number of Map Registers requested exceeds the number currently available in the system, a system worker thread runs to allocate additional system Map Registers. This worker thread may not be triggered to run under certain circumstances, thus the available system Map Registers will not be increased, and the request from Usbport for additional Map Registers will not be completed.

This problem is more likely to occur if there are no other USB transfers active on the USB host controller involved at the time the large transfer is submitted.

Resolution


To ensure that this problem is never encountered, USB client drivers (including UMDF-based drivers) can limit the size of USB transfers submitted to the USB stack (or USB I/O Target). A transfer that spans no more than 16 (sixteen) 4-KB pages is not expected to encounter this problem, although larger transfers (e.g., 128KB) may prove successful in typical real-world scenarios. Larger Read/Write requests submitted to the USB client driver can be broken up into smaller transfers to be submitted to the USB stack or USB IO target.

More Information


Ideally, a buffer of up to 64 KB (65,536 bytes) can be contained within 16 (sixteen) 4-KB pages, if the beginning of the buffer is aligned to the beginning of the first of the 16 pages. However, if the beginning of the buffer is not aligned to the beginning of the page, then a 64 KB buffer would actually span 17 pages. It's possible that a buffer slightly larger than 56 KB would begin near the end of the first page, fill the following 14 pages, then occupy the first few bytes of the last (16th) page. For this issue, the limiting factor is the number of pages spanned, not the actual number of bytes in the buffer.

For more information on System Map Registers, see the following topic in the Microsoft Windows Driver Kit (WDK) documentation:
Map Registers

For more information on USB transfers, see the following topics in the Microsoft Windows Driver Kit (WDK) documentation:
USB Device I/O (WDM)
USB I/O Targets (KMDF)
USB I/O Targets in UMDF
How to Access a USB Device by Using WinUSB Functions