Presentation is loading. Please wait.

Presentation is loading. Please wait.

May 8, 20012 USB Client Driver Etiquette Jay Senior Windows Base Developer Microsoft.

Similar presentations


Presentation on theme: "May 8, 20012 USB Client Driver Etiquette Jay Senior Windows Base Developer Microsoft."— Presentation transcript:

1

2 May 8, 20012 USB Client Driver Etiquette Jay Senior Windows Base Developer Microsoft

3 May 8, 20013 Agenda w What not to do: Wreak Havoc. How? w Proper setup methods w Fun with IRPs and URBs w USB specific issues w High-speed specific issues w Power management w Testing tips and tools

4 May 8, 20014 Installing Your Device w Two install apis – UpdateDriverForPlugAndPlayDevices u Used if device has been plugged in. – SetupCopyOEMInf u Used if the inf is not being copied by the install. w Includes and Needs pragmas – No recursion on W2K w No redistribution of system files - specify sourcediskfiles – USBhub is always present on the system, so no need to copy – USBhub no longer backward compatible on W2K. w New section suffixes:.ntx86,.ntia64, see DDK for more.

5 May 8, 20015 Driver Basics w Think in terms of multithreaded – How many times should an URB be submitted? We’ve seen the same one get submitted more than once. w Never make assumptions in filter drivers w Tear down symbolic links on surprise removal IRP – IoSetDeviceInterfaceState(&SymbolicLinkName, FALSE); w Synchronize requests with pnp – Wait for aborts to complete before completing remove. – IoReleaseRemoveLockAndWait is your friend. w Don't leave a DbgBreakPoint in production code!

6 May 8, 20016 Ping-Pong IRPs w Make sure not to recursively send ping-pong IRP w On hot unplug, requests will complete quickly. – Don’t spin tightly on requests when a device returns error. Make sure to wait a while before re-submitting. w When you create an IRP and specify a completion routine, don't call IoMarkIRPPending in the completion routine. – There’s no more stack locations. – There’s no more stack locations.

7 May 8, 20017 USB Hand Grenade w Freeing the URB/IRP while it is pending in the USB stack w Don't free anything attached to an active request w Concept of ownership – Just because IoCancelIRP called, doesn't mean that the IRP is yours yet – To guard, make sure to wait for completion routine to get hit w In IRP_MN_REMOVE, can wait forever for requests to complete – IoReleaseRemoveLockAndWait

8 May 8, 20018 Timing Out Requests w USB stack has no concept of timing out requests w Client driver's responsibility to timeout their own requests – Otherwise, the request might stay on the HW getting NAK'ed the whole time w Cancel after timeout case. – If you created the IRP, better have a completion routine! w USB specific Abort pipe – Keep track of outstanding requests and wait for requests to complete

9 May 8, 20019 Isochronous Devices w Need to be able to turn around requests quickly. w Put out two 4 ms frames -> Can’t keep up. w Submit two 32 ms frames and then party on one while it's pending -> Uh… Bad! w To get low latency use many small requests. w Proper solution: – Put down eight 4-ms requests.

10 May 8, 200110 Bus Interface w Available in W2K, WinME, and XP w Can be called at high IRQL w Expandable by specifying higher version number w IsDeviceHighSpeed w Example: – Is my device high speed? – Allows driver writer to write one driver

11 May 8, 200111 High-Speed USB w Making a device that works both 1.1 and 2.0. – Mostly only an issue when working with ISO. w Don't assume that there is still a max packet size of 64 bytes. – Retrieve it from endpoint descriptor. Potential max of 512 bytes. w Microframes - 8 microframes whereas there is only one frame on 1.1 – 32 packets would have gone in 32 frames previously. One frame is still 1 ms, but there are 8 microframes per frame. So queuing 32 packets will go over 4 frames.

12 May 8, 200112 Power Management on USB w Device States: – D0 is on – D2 is suspend. i.e. <= 500 uA – D3 is off w Once the hub PDO is not in D0, all requests will fail, so… – Cancel all pending requests before you send on the power down request to the hub PDO. w Don’t forget, power dispatch should at least have: – PoStartNextPowerIRP, – IoSkipCurrentIRPStackLocation – PoCallDriver

13 May 8, 200113 Selective Suspend w Allows bus to go to low power while PC is on w Allows processor to go to C3 and save battery w Understand the difference between system power down and selective power down – Track system power state, so that you don't power up without receiving a corresponding S0 IRP w USBhub does not power manage its PDOS – Whenever an idle IRP completes, must understand what power state you're in w See “SelSus” DDK example for more info

14 May 8, 200114 Testing Tips and Tools w Run the driver verifier! – More tests every day w Test devices – On all flavors - UHCI, OHCI and now EHCI. – On both XP and Win2K – While connected to an external hub u Slight electrical differences - overcurrent protection... w Test unplugging devices – While in use – While in low-power mode – While selectively suspended

15 May 8, 200115 Call to Action! w Use DDK tools like GenINF and CheckINF w Run appropriate WHQL HCT Kits on your devices – www.microsoft.com/hwtest www.microsoft.com/hwtest w The Windows XP DDK has the most recent sample code – DDK Developer / Product Support offers various support options w Contact the OEM / IHV Recon teams w Subscribe to the Windows Hardware Newsletter – http://www.microsoft.com/hwdev http://www.microsoft.com/hwdev


Download ppt "May 8, 20012 USB Client Driver Etiquette Jay Senior Windows Base Developer Microsoft."

Similar presentations


Ads by Google