How can bus driver issue rebuild his drivers stack?

Hi,

I work in developing network drivers, our architecture is build a way that we have KMDF bus driver that create PDOs for Ethernet drivers and others.

We are looking for a way to allow the bus driver to issue rebuild his stack.
So the OS will destroy his stack from UP bottom (for example halt the NDIS miniport drivers etc,…)

We tried to use WdfDeviceSetFailed.
But the result is the OS has destroyed only the bus driver without notifying his above stack, and we have crashed.

Can you help us find another way to do this?

Appreciate any kind of help,
Firas Mahameed
Windows SW Engineer
Mellanox Technologies

See Bus_UnPlugDevice in the toaster bus dynamic sample. You unplug the
device, then plug it back in after it has finished being removed.

Mark Roddy

On Thu, Dec 16, 2010 at 7:27 AM, Firas Mahameed wrote:
> Hi,
>
>
>
> I work in developing network drivers, our architecture is build a way that
> we have KMDF bus driver that create PDOs for Ethernet drivers and others.
>
>
>
> We are looking for a way to allow the bus driver to issue rebuild his stack.
>
> So the OS will destroy his stack from UP bottom (for example halt the NDIS
> miniport drivers etc,…)
>
>
>
> We tried to use WdfDeviceSetFailed.
>
> But the result is the OS has destroyed only the bus driver without notifying
> his above stack, and we have crashed.
>
>
>
> Can you help us find another way to do this?
>
>
>
> Appreciate any kind of help,
>
> Firas Mahameed
>
> Windows SW Engineer
>
> Mellanox Technologies
>
>
>
> —
> 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

Thanks, but where can I found this sample? I didn’t find it in the WDK samples

Thx Firas.

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Mark Roddy
Sent: Thursday, December 16, 2010 5:06 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] How can bus driver issue rebuild his drivers stack?

See Bus_UnPlugDevice in the toaster bus dynamic sample. You unplug the
device, then plug it back in after it has finished being removed.

Mark Roddy

On Thu, Dec 16, 2010 at 7:27 AM, Firas Mahameed wrote:
> Hi,
>
>
>
> I work in developing network drivers, our architecture is build a way that
> we have KMDF bus driver that create PDOs for Ethernet drivers and others.
>
>
>
> We are looking for a way to allow the bus driver to issue rebuild his stack.
>
> So the OS will destroy his stack from UP bottom (for example halt the NDIS
> miniport drivers etc,…)
>
>
>
> We tried to use WdfDeviceSetFailed.
>
> But the result is the OS has destroyed only the bus driver without notifying
> his above stack, and we have crashed.
>
>
>
> Can you help us find another way to do this?
>
>
>
> Appreciate any kind of help,
>
> Firas Mahameed
>
> Windows SW Engineer
>
> Mellanox Technologies
>
>
>
> —
> 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


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

/src/general/toaster/kmdf/bus/dynamic/busenum.c

Good luck,

mm

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Firas Mahameed
Sent: Saturday, December 18, 2010 4:04 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How can bus driver issue rebuild his drivers stack?

Thanks, but where can I found this sample? I didn’t find it in the WDK
samples

Thx Firas.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Mark Roddy
Sent: Thursday, December 16, 2010 5:06 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] How can bus driver issue rebuild his drivers stack?

See Bus_UnPlugDevice in the toaster bus dynamic sample. You unplug the
device, then plug it back in after it has finished being removed.

Mark Roddy

On Thu, Dec 16, 2010 at 7:27 AM, Firas Mahameed
wrote:
> Hi,
>
>
>
> I work in developing network drivers, our architecture is build a way that
> we have KMDF bus driver that create PDOs for Ethernet drivers and others.
>
>
>
> We are looking for a way to allow the bus driver to issue rebuild his
stack.
>
> So the OS will destroy his stack from UP bottom (for example halt the NDIS
> miniport drivers etc,…)
>
>
>
> We tried to use WdfDeviceSetFailed.
>
> But the result is the OS has destroyed only the bus driver without
notifying
> his above stack, and we have crashed.
>
>
>
> Can you help us find another way to do this?
>
>
>
> Appreciate any kind of help,
>
> Firas Mahameed
>
> Windows SW Engineer
>
> Mellanox Technologies
>
>
>
> —
> 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


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


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

This approach demands support dynamic enumeration, in our code we use static enumeration.
Do we have any other alternatives? Or we must support the dynamic enumeration method?

Thx Firas.

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Martin O’Brien
Sent: Saturday, December 18, 2010 11:09 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How can bus driver issue rebuild his drivers stack?

/src/general/toaster/kmdf/bus/dynamic/busenum.c

Good luck,

mm

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Firas Mahameed
Sent: Saturday, December 18, 2010 4:04 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How can bus driver issue rebuild his drivers stack?

Thanks, but where can I found this sample? I didn’t find it in the WDK
samples

Thx Firas.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Mark Roddy
Sent: Thursday, December 16, 2010 5:06 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] How can bus driver issue rebuild his drivers stack?

See Bus_UnPlugDevice in the toaster bus dynamic sample. You unplug the
device, then plug it back in after it has finished being removed.

Mark Roddy

On Thu, Dec 16, 2010 at 7:27 AM, Firas Mahameed
wrote:
> Hi,
>
>
>
> I work in developing network drivers, our architecture is build a way that
> we have KMDF bus driver that create PDOs for Ethernet drivers and others.
>
>
>
> We are looking for a way to allow the bus driver to issue rebuild his
stack.
>
> So the OS will destroy his stack from UP bottom (for example halt the NDIS
> miniport drivers etc,…)
>
>
>
> We tried to use WdfDeviceSetFailed.
>
> But the result is the OS has destroyed only the bus driver without
notifying
> his above stack, and we have crashed.
>
>
>
> Can you help us find another way to do this?
>
>
>
> Appreciate any kind of help,
>
> Firas Mahameed
>
> Windows SW Engineer
>
> Mellanox Technologies
>
>
>
> —
> 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


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


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


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

The other alternative is to, from user mode, disable/re-enable the device.

Mark Roddy

On Sun, Dec 19, 2010 at 3:42 AM, Firas Mahameed wrote:
> This approach demands support dynamic enumeration, in our code we use static enumeration.
> Do we have any other alternatives? Or we must support the dynamic enumeration ?method?
>
> Thx Firas.
>
>
> -----Original Message-----
> From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Martin O’Brien
> Sent: Saturday, December 18, 2010 11:09 AM
> To: Windows System Software Devs Interest List
> Subject: RE: [ntdev] How can bus driver issue rebuild his drivers stack?
>
> /src/general/toaster/kmdf/bus/dynamic/busenum.c
>
>
> Good luck,
>
> mm
>
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Firas Mahameed
> Sent: Saturday, December 18, 2010 4:04 AM
> To: Windows System Software Devs Interest List
> Subject: RE: [ntdev] How can bus driver issue rebuild his drivers stack?
>
> Thanks, but where can I found this sample? I didn’t find it in the WDK
> samples
>
> Thx Firas.
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Mark Roddy
> Sent: Thursday, December 16, 2010 5:06 PM
> To: Windows System Software Devs Interest List
> Subject: Re: [ntdev] How can bus driver issue rebuild his drivers stack?
>
> See Bus_UnPlugDevice in the toaster bus dynamic sample. You unplug the
> device, then plug it back in after it has finished being removed.
>
> Mark Roddy
>
>
>
> On Thu, Dec 16, 2010 at 7:27 AM, Firas Mahameed
> wrote:
>> Hi,
>>
>>
>>
>> I work in developing network drivers, our architecture is build a way that
>> we have KMDF bus driver that create PDOs for Ethernet drivers and others.
>>
>>
>>
>> We are looking for a way to allow the bus driver to issue rebuild his
> stack.
>>
>> So the OS will destroy his stack from UP bottom (for example halt the NDIS
>> miniport drivers etc,…)
>>
>>
>>
>> We tried to use WdfDeviceSetFailed.
>>
>> But the result is the OS has destroyed only the bus driver without
> notifying
>> his above stack, and we have crashed.
>>
>>
>>
>> Can you help us find another way to do this?
>>
>>
>>
>> Appreciate any kind of help,
>>
>> Firas Mahameed
>>
>> Windows SW Engineer
>>
>> Mellanox Technologies
>>
>>
>>
>> —
>> 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
>
> —
> 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
>
> —
> 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
>
>
> —
> 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
>
> —
> 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
>

What about using WdfPdoMarkMissing? For all the bus driver children.

Thx Firas.

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Mark Roddy
Sent: Sunday, December 19, 2010 7:07 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] How can bus driver issue rebuild his drivers stack?

The other alternative is to, from user mode, disable/re-enable the device.

Mark Roddy

On Sun, Dec 19, 2010 at 3:42 AM, Firas Mahameed wrote:
> This approach demands support dynamic enumeration, in our code we use static enumeration.
> Do we have any other alternatives? Or we must support the dynamic enumeration ?method?
>
> Thx Firas.
>
>
> -----Original Message-----
> From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Martin O’Brien
> Sent: Saturday, December 18, 2010 11:09 AM
> To: Windows System Software Devs Interest List
> Subject: RE: [ntdev] How can bus driver issue rebuild his drivers stack?
>
> /src/general/toaster/kmdf/bus/dynamic/busenum.c
>
>
> Good luck,
>
> mm
>
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Firas Mahameed
> Sent: Saturday, December 18, 2010 4:04 AM
> To: Windows System Software Devs Interest List
> Subject: RE: [ntdev] How can bus driver issue rebuild his drivers stack?
>
> Thanks, but where can I found this sample? I didn’t find it in the WDK
> samples
>
> Thx Firas.
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Mark Roddy
> Sent: Thursday, December 16, 2010 5:06 PM
> To: Windows System Software Devs Interest List
> Subject: Re: [ntdev] How can bus driver issue rebuild his drivers stack?
>
> See Bus_UnPlugDevice in the toaster bus dynamic sample. You unplug the
> device, then plug it back in after it has finished being removed.
>
> Mark Roddy
>
>
>
> On Thu, Dec 16, 2010 at 7:27 AM, Firas Mahameed
> wrote:
>> Hi,
>>
>>
>>
>> I work in developing network drivers, our architecture is build a way that
>> we have KMDF bus driver that create PDOs for Ethernet drivers and others.
>>
>>
>>
>> We are looking for a way to allow the bus driver to issue rebuild his
> stack.
>>
>> So the OS will destroy his stack from UP bottom (for example halt the NDIS
>> miniport drivers etc,…)
>>
>>
>>
>> We tried to use WdfDeviceSetFailed.
>>
>> But the result is the OS has destroyed only the bus driver without
> notifying
>> his above stack, and we have crashed.
>>
>>
>>
>> Can you help us find another way to do this?
>>
>>
>>
>> Appreciate any kind of help,
>>
>> Firas Mahameed
>>
>> Windows SW Engineer
>>
>> Mellanox Technologies
>>
>>
>>
>> —
>> 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
>
> —
> 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
>
> —
> 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
>
>
> —
> 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
>
> —
> 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
>


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

The static enumeration model would seem to be inappropriate for your
case. Why not use the mechanism outlined in the dynamic sample? The
documentation states that “drivers should only use static child lists
for device configurations that are predetermined and permanent”. You
have a specific requirement to have a ‘tear down and rebuild’
operation on device stacks, and as such the dynamic model is more
appropriate (and massively easy to implement too!)

Mark Roddy

2010/12/20 Firas Mahameed :
> WdfPdoMarkMissing

In our case the bus driver should create only 2 children, we have child type A and child type B.
What I’m looking for is the ability to tear down and up with different child type.
Assume bus driver started with rising 2 children type A, on some scenario I want to destroy the current stack and rise with type B.

So you suggest to move to the dynamic model? But it’s a matter of how much effort we need to do that porting.

I checked that calling WdfPdoMarkMissing will do the trick for now.

Thx Firas.

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Mark Roddy
Sent: Monday, December 20, 2010 4:38 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] How can bus driver issue rebuild his drivers stack?

The static enumeration model would seem to be inappropriate for your
case. Why not use the mechanism outlined in the dynamic sample? The
documentation states that “drivers should only use static child lists
for device configurations that are predetermined and permanent”. You
have a specific requirement to have a ‘tear down and rebuild’
operation on device stacks, and as such the dynamic model is more
appropriate (and massively easy to implement too!)

Mark Roddy

2010/12/20 Firas Mahameed :
> WdfPdoMarkMissing


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

i don’t really understand why you are so resistant to moving to dynamic enumeration. this is exactly what it was designed to do. WdfPdoMarkMissing will work, but you must handle a bunch of race conditions yourself. in the dynamic model, KMDF handles all of it for you. the difference is not that hard, you have to implement a couple of callbacks. Plus, any KMDF drivers loaded on top of these “dynamic” PDOs can ask KMDF to reenumerate the stack and you have no code to implement to get this feature.

d

OK I’ll make the changes to move to dynamic enumeration.

but one more questions:

In case I have something running in user mode (openSM.exe) that is bounded to the driver stack, and bus driver decides to destroy the stack. what will happen in this case? and what is the solution?

the app needs to register for file handle notifications (RegisterDeviceNotification in UM). when the child stack is surprise removed, the app will be notified to close its handle. the child stack will stay in the surprise removed state until that handle is closed, at which point the pnp remove irp will be sent. this happens regardless of the enumeration model, static or dynamic, that you use.

d

Thanks for the explanation,

But we support the network drivers (kernel modules and DLLs), and can’t take control of all the UM applications.

Our customer can write an application that binds to our drivers (through the DLLs) and bypass the kernel to directly talk with the HW.

The problem will happen when the bus driver decides that he need to destroy his upper stack, and create a new different one.

I think to make the changes in our UM DLLs, that get the notification about the surprise removal.
but we still can get to a situation that application will crash.

Any suggestions?

Thx Firas.

You cannot do much more in a dll than provide a layer of indirection
between application and device. The dll can hide the disappearance of
the network stack below it, but it has to do something with
application requests for service.

Mark Roddy

On Tue, Dec 28, 2010 at 7:25 AM, wrote:
> Thanks for the explanation,
>
> But we support the network drivers (kernel modules and DLLs), and can’t take control of all the UM applications.
>
> Our customer can write an application that binds to our drivers (through the DLLs) and bypass the kernel to directly talk with the HW.
>
> The problem will happen when the bus driver decides that he need to destroy his upper stack, and create a new different one.
>
> I think to make the changes in our UM DLLs, that get the notification about the surprise removal.
> but we still can get to a situation that application will crash.
>
> Any suggestions?
>
> Thx Firas.
>
> —
> 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
>

Clearly you control the API exposed by your DLL to applications. That API
needs to accommodate the semantics of the ‘device’ being removed. Can you
extend that API so that applications with ‘open sessions’ via your DLL to
your device(s) can be notified to close those sessions so that PnP can
remove the device?

If not, then as Mark said you will need to introduce an indirection layer
that will disconnect from a device when notified by PnP and then handle any
calls from the application by doing some reasonable (like returning an
error).

Good Luck,
Dave Cattley

Thank you and happy new year :slight_smile:

Firas