How can USB driver disable/enable itself on PC sleep/wakeup?

Hi NtDev,

Is there any way from a WDF driver EvtDeviceD0Entry callback to
simulate what happens when running “devcon restart”?

I am writing a WDF driver for a self-powered USB peripheral with a
Cypress FX1. Most normal situations work fine. But if power to the
self powered peripheral is removed while the PC is sleeping, waking up
the PC leads to a BSOD in the usbhub driver. This happens even if the
power is reconnected to the peripheral before waking the PC.

It appears this case is similar to the error Doronh discussed in his
2006/03/20 blog. I’m guessing the peripheral loses its USB address
when its power is removed, but on wakeup the usbhub driver is still
trying to talk to my device at that lost address.

While getting a hotfix might take care of the problem on my XPSP2
machine, it will be difficult to get all of our customers to upgrade
their systems. So I need to find a workaround.

Right now, I’m failing EvtDeviceD0Exit. So, when the PC wakes up, my
driver shows a yellow exclamation mark in Device Manager with error 43
CM_PROB_FAILED_POST_START. I have to run “devcon restart” or
disable/enable from the Device Manager before it works properly again.

I would like to find something I can call in EvtDeviceD0Entry that
will make the driver automatically come back alive without having to
run devcon or Device Manager.

Thanks for any help you can give.

Best regards, Wendy Tucker

How looks your Sx -> Dx mapping? If S1 and S3 states map to D2, try to
change it to D3.

Have you tried USB analyser to see what happens on the bus?

Best regards,

Michal Vodicka
UPEK, Inc.
[xxxxx@upek.com, http://www.upek.com]

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@symres.com
Sent: Tuesday, November 24, 2009 2:21 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] How can USB driver disable/enable itself on
PC sleep/wakeup?

Hi NtDev,

Is there any way from a WDF driver EvtDeviceD0Entry callback to
simulate what happens when running “devcon restart”?

I am writing a WDF driver for a self-powered USB peripheral with a
Cypress FX1. Most normal situations work fine. But if power to the
self powered peripheral is removed while the PC is sleeping, waking up
the PC leads to a BSOD in the usbhub driver. This happens even if the
power is reconnected to the peripheral before waking the PC.

It appears this case is similar to the error Doronh discussed in his
2006/03/20 blog. I’m guessing the peripheral loses its USB address
when its power is removed, but on wakeup the usbhub driver is still
trying to talk to my device at that lost address.

While getting a hotfix might take care of the problem on my XPSP2
machine, it will be difficult to get all of our customers to upgrade
their systems. So I need to find a workaround.

Right now, I’m failing EvtDeviceD0Exit. So, when the PC wakes up, my
driver shows a yellow exclamation mark in Device Manager with error 43
CM_PROB_FAILED_POST_START. I have to run “devcon restart” or
disable/enable from the Device Manager before it works properly again.

I would like to find something I can call in EvtDeviceD0Entry that
will make the driver automatically come back alive without having to
run devcon or Device Manager.

Thanks for any help you can give.

Best regards, Wendy Tucker


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online
at http://www.osronline.com/page.cfm?name=ListServer

You cannot fix this in your driver. Outside of the s to d state mapping michal mentioned (and i do not know if it will actually help), there is nothing you can do in a driver to fix this. Trying to work around the problem will only cause way more fragile code in your software than you really need

d

-----Original Message-----
From: xxxxx@symres.com
Sent: Monday, November 23, 2009 5:19 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] How can USB driver disable/enable itself on PC sleep/wakeup?

Hi NtDev,

Is there any way from a WDF driver EvtDeviceD0Entry callback to
simulate what happens when running “devcon restart”?

I am writing a WDF driver for a self-powered USB peripheral with a
Cypress FX1. Most normal situations work fine. But if power to the
self powered peripheral is removed while the PC is sleeping, waking up
the PC leads to a BSOD in the usbhub driver. This happens even if the
power is reconnected to the peripheral before waking the PC.

It appears this case is similar to the error Doronh discussed in his
2006/03/20 blog. I’m guessing the peripheral loses its USB address
when its power is removed, but on wakeup the usbhub driver is still
trying to talk to my device at that lost address.

While getting a hotfix might take care of the problem on my XPSP2
machine, it will be difficult to get all of our customers to upgrade
their systems. So I need to find a workaround.

Right now, I’m failing EvtDeviceD0Exit. So, when the PC wakes up, my
driver shows a yellow exclamation mark in Device Manager with error 43
CM_PROB_FAILED_POST_START. I have to run “devcon restart” or
disable/enable from the Device Manager before it works properly again.

I would like to find something I can call in EvtDeviceD0Entry that
will make the driver automatically come back alive without having to
run devcon or Device Manager.

Thanks for any help you can give.

Best regards, Wendy Tucker


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Hi Michal and Doran,

Thanks for your replies. I appreciate them.

I reviewed my code and the driver does not change the Sx -> Dx power
state mapping, but just uses the KMDF defaults which I think means
S1-S3 map to D3. But maybe I’ll have a try at setting them
explicitly, just to make sure.

No doubt as Doran says, any workarounds I could come up with will only
result in more fragile code. We will encourage the trailing users to
upgrade. Probably the best resolution anyway.

Thanks again, Wendy

> -----Original Message-----

From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@symres.com
Sent: Wednesday, November 25, 2009 11:50 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] How can USB driver disable/enable itself
on PC sleep/wakeup?

I reviewed my code and the driver does not change the Sx -> Dx power
state mapping, but just uses the KMDF defaults which I think means
S1-S3 map to D3. But maybe I’ll have a try at setting them
explicitly, just to make sure.

Power state mapping is assigned by OS, not KMDF, and can differ. You can
check it in the Device Manager in Details tab for your device.

Best regards,

Michal Vodicka
UPEK, Inc.
[xxxxx@upek.com, http://www.upek.com]

[/quote]

While getting a hotfix might take care of the problem on my XPSP2
machine, it will be difficult to get all of our customers to upgrade
their systems. So I need to find a workaround.

[/quote]

Do you get hotfix from Microsoft. If so, why it’s defficult to apply in on
your customers system. I think upgrade your driver also need a downtime.

Wayne

Michal, thanks for the tip. According to the Device Manager Details
my device has the following Power State Mappings:

S0 -> D0
S1 -> D3
S2 -> D3
S3 -> D3
S4 -> D3
S5 -> D3

Wayne, sometimes the hotfixes have been political. We’ve had cases
where the customer’s IT department outright refuses to make changes to
the OS. Not rational, but there it is and the customer is stuck.

I’ve experimented with putting my PC to sleep and then cycling the
power on other self powered USB devices such as an HP printer and a
DVD writer. I then have no problem waking the PC afterwards.

If I connect my device to the PC through a bus-powered hub, I can
cycle my device power and still wake the PC with no problem. It is
just when I connect my device directly to the PC that the BSOD trouble
occurs.

Something seems wrong. If these other peripherals can survive power
cycles while the PC is asleep, then it seems like I should be able to
also.

I’ll ask more after I return from a trade show. Many thanks to
everyone.

– Wendy