usb device doesnot work after PC wakeup from standby

Some background:

I am developing an USB device firmware and windows WDM driver.
windows WDM driver has two thread, one for send URB and one for recv URB.
Both firmware and WDM driver works well in most cases except the following case

Problem:
device fails to work after pc wakeup from standby

The RECV URB returns 0xC000009d (STATUS_DEVICE_NOT_CONNECTED). - so device is not enumerated after PC wakeup.
from the log of firmware, suspend event is send before PC goes to standby, host wakeup event is sent after or during
PC wakeup, but the last event is suspend event, communication between host and device is not resume.

Questions:
I have some questions, as I can’t find any relevant information about this problem by search INTERNET.

  1. how host and device cooperate to resume communication? will usb device be re-enumerated after wakeup and previous device
    object be discarded in Windows kernel? If this is not the case, why RECV URB returns that STATUS_DEVICE_NOT_CONNECTED.

  2. what should WDM driver do? I can only see that Power IRP is send to driver during standby and wakeup.
    For Power IRP, I just forward it to lower level driver.

  3. Should I power off the device? 2.5mA is good enough for my device, and I can single step in the device by JTAG debugger when PC is standby. So I skip
    power off the device.

  4. It will be great to have a example code.

Why are you writing a wdm driver? At the very least, go with kmdf. Or even better go with umdf and get out of the kernel.

1 the same stack is used
2 you can’t just send power irps down, you are the power policy owner. When receiving an Sx irp, you need to request a Dx power down irp. When receiving an S0 power irp, you need to request a D0 irp. Wdf takes care of all of this for you. Furthermore you need to synchronize your send and receive threads with your device’s power state and not send io while in low power
3 you need to comply with the USB spec
4 wdm has been long abandoned for USB client drivers, all samples are wdf or winusb

You can get a USB etw trace and view it in netmon on win7 or higher, http://blogs.msdn.com/b/usbcoreblog/archive/2009/12/04/etw-in-the-windows-7-usb-core-stack.aspx

d

Bent from my phone


From: xxxxx@gmail.commailto:xxxxx
Sent: ?8/?11/?2013 4:01 AM
To: Windows System Software Devs Interest Listmailto:xxxxx
Subject: [ntdev] usb device doesnot work after PC wakeup from standby

Some background:

I am developing an USB device firmware and windows WDM driver.
windows WDM driver has two thread, one for send URB and one for recv URB.
Both firmware and WDM driver works well in most cases except the following case

Problem:
device fails to work after pc wakeup from standby

The RECV URB returns 0xC000009d (STATUS_DEVICE_NOT_CONNECTED). - so device is not enumerated after PC wakeup.
from the log of firmware, suspend event is send before PC goes to standby, host wakeup event is sent after or during
PC wakeup, but the last event is suspend event, communication between host and device is not resume.

Questions:
I have some questions, as I can’t find any relevant information about this problem by search INTERNET.

1. how host and device cooperate to resume communication? will usb device be re-enumerated after wakeup and previous device
object be discarded in Windows kernel? If this is not the case, why RECV URB returns that STATUS_DEVICE_NOT_CONNECTED.
2. what should WDM driver do? I can only see that Power IRP is send to driver during standby and wakeup.
For Power IRP, I just forward it to lower level driver.
3. Should I power off the device? 2.5mA is good enough for my device, and I can single step in the device by JTAG debugger when PC is standby. So I skip
power off the device.

4. It will be great to have a example code.


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

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</mailto:xxxxx></mailto:xxxxx>

Reconnecting to an USB device after suspend requires very precise handling of power transitions. A single missing or wrong step would cause it to not work.

You’re better with using KMDF rather than with handling the power IRPs by yourself.

xxxxx@gmail.com wrote:

Questions:
I have some questions, as I can’t find any relevant information about this problem by search INTERNET.

Have you read the USB specification? That is the information you need.

  1. how host and device cooperate to resume communication? will usb device be re-enumerated after wakeup and previous device object be discarded in Windows kernel? If this is not the case, why RECV URB returns that STATUS_DEVICE_NOT_CONNECTED.

There is a negotiation between the host controller and the device to
bring things back up. That’s all described in the USB specification.
My guess is that your device is not handling the wakeup sequence
correctly, so the host controller is reporting that your device has
disappeared. If the wakeup is handled correctly, your device object
will not go away.

  1. what should WDM driver do? I can only see that Power IRP is send to driver during standby and wakeup. For Power IRP, I just forward it to lower level driver.

In general, you probably want to cancel your outstanding URBs during
power down and resubmit them during power up.

  1. Should I power off the device? 2.5mA is good enough for my device, and I can single step in the device by JTAG debugger when PC is standby. So I skip power off the device.

Are you bus-powered or externally powered? Bus power is likely to go
away in this case.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

When you get System power down IRP, you hold to it, while cancelling all pending transfers in the device, deselect the current configuration (select null config), send the device power down IRP to your stack, and when the device power down completes, you forward the system power IRP further down the stack.

When you get system power up IRP, you forward it down the stack; when it completes, you issue the device power up IRP. When it completes, you send SELECT_CONFIGURATION URB. After that you can resume sending transfers to the device.

There is absolutely no need to deselect the current config on power down nor to select a config on power up. The current configuration is maintained across power transitions from a client driver POV.

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@broadcom.com
Sent: Monday, August 12, 2013 10:46 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] usb device doesnot work after PC wakeup from standby

When you get System power down IRP, you hold to it, while cancelling all pending transfers in the device, deselect the current configuration (select null config), send the device power down IRP to your stack, and when the device power down completes, you forward the system power IRP further down the stack.

When you get system power up IRP, you forward it down the stack; when it completes, you issue the device power up IRP. When it completes, you send SELECT_CONFIGURATION URB. After that you can resume sending transfers to the device.


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

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

>There is absolutely no need to deselect the current config on power down nor to select a config on power up.

Otherwise it didn’t work for me in XP. I haven’t tested it since 2007, so no chance to see what it takes in Vista+.

As I say, the sequence had to be very exact and that included having to deconfigure and reconfigure. This was with EHCI. Are you sure it does SELECT_CONFIGURATION for the device on the client driver’s behalf during D0 transition?

Absolutely positive. i have written many USB client drivers, I never had to do this for power management. There must have been something wrong with your specific device.

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@broadcom.com
Sent: Monday, August 12, 2013 2:11 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] usb device doesnot work after PC wakeup from standby

There is absolutely no need to deselect the current config on power down nor to select a config on power up.

Otherwise it didn’t work for me in XP. I haven’t tested it since 2007, so no chance to see what it takes in Vista+.

As I say, the sequence had to be very exact and that included having to deconfigure and reconfigure. This was with EHCI. Are you sure it does SELECT_CONFIGURATION for the device on the client driver’s behalf during D0 transition?


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

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

Many thanks for all the replies!

Why are you writing a wdm driver? At the very least, go with kmdf. Or even better go with umdf and get out of the kernel.

=?I need to combine a WDM virtual serial port driver with this USB driver and I am somehow familiar with WDM driver, so I choose WDM. And I am fixing the last bug of the project, :), big change is not an option.

2 you can’t just send power irps down, you are the power policy owner. When receiving an Sx irp, you need to request a Dx power down irp. When receiving an S0 power irp, you need to request a D0 irp. Wdf takes care of all of this for you. Furthermore you need to synchronize your send and receive threads with your device’s power state and not send io while in low power

=> yes, I rewrite the power management IRP handing , and the usb device can work if the device is powered during PC standby. And I can confirm that select config is sent to device by others, maybe the bus driver.

3 you need to comply with the USB spec.
=> I may have a problem here. the device is bus powered, but USB library from chipset vendor force the setting of self powered.

Now I still meet the problem with usb device is powered off during PC standby. Will windows handle this case differently , comparing to usb device is kept on during PC standby? Or this is related to my wrong configuration report about power supply?

xxxxx@gmail.com wrote:

=> yes, I rewrite the power management IRP handing , and the usb device can work if the device is powered during PC standby. And I can confirm that select config is sent to device by others, maybe the bus driver.

Nope, that doesn’t happen. You must have a call to
USBD_CreateConfigurationRequestEx in your driver somewhere.

3 you need to comply with the USB spec.
=> I may have a problem here. the device is bus powered, but USB library from chipset vendor force the setting of self powered.

That’s a serious problem. However, every USB chipset allows you to
provide your own descriptors, so you should be able to solve that problem.

Now I still meet the problem with usb device is powered off during PC standby. Will windows handle this case differently , comparing to usb device is kept on during PC standby? Or this is related to my wrong configuration report about power supply?

What are you expecting to happen here? Unless your device is registered
as a “wakeup” source, when the PC goes into standby, the power to your
port will be removed. That’s a fact. You need to be able to put it
back in a working state when power is restored.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

> => yes, I rewrite the power management IRP handing , and the usb device
can work if the device is powered during PC standby. And I can confirm
that select config is sent to device by others, maybe the bus driver.

Nope, that doesn’t happen. You must have a call to
USBD_CreateConfigurationRequestEx in your driver somewhere.

=??yes, select configure is send when device is started by my driver. Here
I mean when PC wakeup, the select configure is sent by system.

Now I still meet the problem with usb device is powered off during PC
standby. Will windows handle this case differently , comparing to usb
device is kept on during PC standby? Or this is related to my wrong
configuration report about power supply?

What are you expecting to happen here? Unless your device is registered
as a “wakeup” source, when the PC goes into standby, the power to your
port will be removed. That’s a fact. You need to be able to put it
back in a working state when power is restored.

=> USB device is not powered off in my desktop at least, according to USB
spec, VBUS is not off in suspend state. I guess there is an user setting to
control this. and Yes, I add restoring virtual serial hardware context in
virtual serial driver, now the problem is solved.

Cheers, the problem is solved!

2013/8/14 Tim Roberts

> xxxxx@gmail.com wrote:
> > => yes, I rewrite the power management IRP handing , and the usb device
> can work if the device is powered during PC standby. And I can confirm
> that select config is sent to device by others, maybe the bus driver.
>
> Nope, that doesn’t happen. You must have a call to
> USBD_CreateConfigurationRequestEx in your driver somewhere.
>
>
> > 3 you need to comply with the USB spec.
> > => I may have a problem here. the device is bus powered, but USB library
> from chipset vendor force the setting of self powered.
>
> That’s a serious problem. However, every USB chipset allows you to
> provide your own descriptors, so you should be able to solve that problem.
>
>
> > Now I still meet the problem with usb device is powered off during
> PC standby. Will windows handle this case differently , comparing to usb
> device is kept on during PC standby? Or this is related to my wrong
> configuration report about power supply?
>
> What are you expecting to happen here? Unless your device is registered
> as a “wakeup” source, when the PC goes into standby, the power to your
> port will be removed. That’s a fact. You need to be able to put it
> back in a working state when power is restored.
>
> –
> Tim Roberts, xxxxx@probo.com
> Providenza & Boekelheide, Inc.
>
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> 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
>