Showing posts with label USB. Show all posts
Showing posts with label USB. Show all posts

8/03/2010

Removal Policy for a Device


http://download.microsoft.com/download/1/6/1/161ba512-40e2-4cc9-843a-923143f3456c/Designing%20Hardware%20for%20Surprise%20Removal_v8.doc

http://msdn.microsoft.com/en-us/library/ff551967(VS.85).aspx


Removal Scenarios for Devices
1.Orderly-Removal Scenarios
2.Surprise-Removal Scenarios

Removal-related device capabilities that are relevant to this include SurpriseRemovalOK and Removable.
1.Removable. This capability is set by the bus driver for the bus on which a given device is installed.
2.SurpriseRemovalOK. This capability is set by the driver for the device. It specifies whether the device can be safely removed without using the Safely Remove Hardware applet.
3.If both Removable and SurpriseRemovalOK are set, the device can be removed without using the applet. If Removable is TRUE, the device is displayed in the Safely Remove Hardware applet unless SurpriseRemovalOK is also set to TRUE.

Windows XP has the following removal policy options:
1.ExpectNoRemoval.
2.ExpectOrderlyRemoval
3.ExpectSurpriseRemoval


The operating system uses the following algorithm to determine removal policy defaults:
1.The bus driver sets the Removable device capability according to the operating system default for the device. ACPI BIOS can override the Removable capability by using the _RMV method.
2.If the device is determined to be removable, the operating system checks to see if there is an INF override for removal policy.
3.If no INF override is provided, Windows checks IEEE 1394 devices for any override value in the configuration ROM.
4.In the absence of either an INF or hardware override, Windows bases the removal policy on the bus of the removable device. USB,IEEE1394,PCMCIA---ExpectSurpriseRemoval. Others---ExpectOrderlyRemoval

Override Removal Policy in a Device INF File
[DDInstall.NT] <-- Replace DDInstall with the name of the install section for the device ; Contains CopyFiles and other directives
[DDInstall.NT.Services]
; Contains AddService directive to install driver
[DDInstall.NT.HW]
; Contains AddReg/DelReg sections to manage hardware-specific registry settings
AddReg=DDInstall_AddReg_HW_Removal_Policy
[DDInstall_AddReg_HW_Removal_Policy]
HKR,,"RemovalPolicy",0x00010001,Policy <--- See legend below for Policy values

The Policy value can be one of the following:
• Policy = 2 - ExpectOrderlyRemoval. The user will rarely remove the device, or will initiate removal only through software or hardware.
• Policy = 3 - ExpectSurpriseRemoval. The user will regularly remove the device with no warning to the operating system.

Override Removal Policy in a Device INF File (
SetupDiGetDeviceRegistryProperty
SetupDiSetDeviceRegistryProperty (SPDRP_REMOVAL_POLICY is reserved for use by the operating system and cannot be used in the Property parameter)

SPDRP_REMOVAL_POLICY
(Windows XP and later) The function retrieves the device's current removal policy as a DWORD that contains one of the CM_REMOVAL_POLICY_Xxx values that are defined in Cfgmgr32.h.

SPDRP_REMOVAL_POLICY_HW_DEFAULT
(Windows XP and later) The function retrieves the device's hardware-specified default removal policy as a DWORD that contains one of the CM_REMOVAL_POLICY_Xxx values that are defined in Cfgmgr32.h.

SPDRP_REMOVAL_POLICY_OVERRIDE
(Windows XP and later) The function retrieves the device's override removal policy (if it exists) from the registry, as a DWORD that contains one of the CM_REMOVAL_POLICY_Xxx values that are defined in Cfgmgr32.h.

7/29/2010

USB Event Tracking (ETW log in USB Core Stack)

Background:
=========
Event Tracing for Windows (ETW)
In Windows 7, ETW provides an event logging mechanism that the USB driver stack can exploit to aid in investigating, diagnosing, and debugging USB-related issues.

USB Core Stack
The USB host controller driver layer includes the host controller port driver (usbport.sys) and the miniport drivers (usbehci.sys, usbohci.sys, and usbuhci.sys). The USB hub driver layer consists of the USB hub driver (usbhub.sys).

Using USB ETW
============
Capture a USB event trace: logman
1. In the command-prompt window, enter the following two commands to begin the trace:
Logman start Usbtrace -p Microsoft-Windows-USB-USBPORT -o usbtrace.etl -ets -nb 128 640 -bs 128

Logman update Usbtrace -p Microsoft-Windows-USB-USBHUB -ets

After each of these commands completes, Logman should display the following message:
“The command completed successfully.”
2. Perform the steps in your USB device usage scenario.
3. Stop USB hub and port event collection by running the following command:
Logman stop Usbtrace –ets


Analyze an event trace log to troubleshoot a failure
: netmon
Capture a system event trace and analyze timing or performance issues: Xperf

Using Xperf with USB ETW
1. start
Xperf –on Diag
Logman start Usbtrace -p Microsoft-Windows-USB-USBPORT -o usbtrace.etl -ets -nb 128 640 -bs 128
Logman update Usbtrace -p Microsoft-Windows-USB-USBHUB –ets

2.stop
Logman stop Usbtrace -ets
Xperf –stop

3. merge
Xperf –merge usbtrace.etl C:\kernel.etl merged.etl


Reference:
=======
http://blogs.msdn.com/b/usbcoreblog/archive/2010/03/17/new-whitepaper-on-usb-event-tracing.aspx
http://www.microsoft.com/whdc/connect/usb/Event-Tracing.mspx

8/19/2009

USB Port busy, or not

How to detect USB Port status connected with a USB Flash drive? (working or idle).

It seems no APIs or interfaces to get the status of a USB Port (working or idle).

As workarounds, it may work to force reflush cache by unmounting and re-mounting volume or remove and rescan usb key device.

1. Flush disk cache by unmounting and re-mounting volume

2. Devcon remove "USB\VID_XXXX&PID_XXXX" and then "devcon rescan"

4/14/2009

To ignore a device's serial number

http://www.lvr.com/usbfaq.htm

During device testing, we attach many devices that are identical except for the serial numbers. How can I prevent Windows from asking to install a new driver every time a device is attached?

This method causes Windows 2000 and XP to ignore a device's serial number. It's recommended for test environments only.

This registry key controls whether Windows uses or ignores device serial numbers:

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\UsbFlags]


It's possible to ignore all serial numbers, though this approach is NOT recommended. To ignore all serial numbers, in the above key, change this value to zero:

GlobalDisableSerNumGen = 1

To ignore the serial number for an individual device, create an entry under the above ...\UsbFlags key. The name must
start with "IgnoreHWSerNum" followed by the vendor and product ID of the device. A value of 1 = disable the serial number.

Example (Vendor ID = 0925h, Product ID = 016Ah):

IgnoreHWSerNum0925016A= 1

2/09/2009

MaximumTransferSize is oboslete after Win2000

MaximumTransferSize member of the USBD_PIPE_INFORMATION structure is obsolete after Win2000. Systems after win2000 don't care about this value anyway.The USB stack ignores the value in MaximumTransferSize for both composite and non-composite devices, this values will be set to the default.The default values of MaximumTransferSize under Vista are listed below.


1. http://msdn.microsoft.com/en-us/library/ms790486.aspx
2. http://msdn.microsoft.com/en-us/library/ms793357.aspx

8/27/2008

USB Device ENUMERATION PROCESS

( Copy From Microchip AN1003)


The following summarizes the steps involved in theenumeration of a USB device and explains how thedevice goes from Powered to Default, Address and theConfigured state during the enumeration process.

1. User plugs a USB device into a USB port. The hub provides power to the port and the device isin the Powered state.

2. The hub detects the device.

3. The hub uses an interrupt pipe to report the event to the host.

4. Host sends Get_Port_Status request to obtain more information about the device.

5. Hub detects whether device is Low-Speed orFull-Speed operation and sends the information to the host in response to Get_Port_Status.

6. Host sends a Set_Port_Feature request, asking the hub to reset the port.

7. Hub resets the device.

8. Host learns if a Full-Speed device supports High-Speed operation (using Chirp K signal).

9. Host verifies if the device has exited the Reset state using Get_Port_Status.

10. At this point, the device is in the Default state(device is ready to respond to control transfersover the default pipe at Endpoint 0, default address is 00h and the device can draw up to100 mA from the bus).

11. Host sends Get_Descriptor to learn the maximum packet size (Note: eighth byte of the device descriptor is bMaxPacketSize).

12. The host assigns an address by sending a Set_Address request. Device is now in the Address state.
13. Host sends Get_Descriptor to learn more about the device. The host responds by sending the descriptor followed by all other subordinate descriptors.

14. Host assigns and loads a device driver.

15. Host’s device driver selects a configuration bysending a Set_Configuration request. The device is now in the Configured state.

16. Host assigns drivers for interfaces in composite devices.

17. If the hub detects an overcurrent, or if the host requests the hub to remove power, the device will be unpowered by the USB bus. In this case, the device and host cannot communicate and the device is in the Attached state.

18. If the device does not see any activity on the busfor 3 ms, it goes into the Suspend state. The device consumes minimal bus power in thisstate.