How to prevent normal NIC from SHUTDOWN or HALT like to KDNET?

We developed a virtual storport driver that needs NIC essentially.
The problem is that NIC is shutdown while restarting or power off system so that storport cannot read or write some disk blocks at last.
I realized that KDNET is alive always.
So I thought that let’s make normal NICs to live until the end like to KDNET.

At first I tried to complete IRP (IRP_MJ_POWER, IRP_MN_SET_POWER) with STATUS_UNSUCCESSFUL in PCI bus driver(PDO) but it doesn’t work.
I think NDIS sends a shutdown to miniport driver first even though IRP_MJ_POWER is filtered in bus driver later.

Now I’m trying to add or remove some capabilities in NDIS filter driver but I’m not much familiar with NDIS.
Normal NIC and KDNET states are below.

[Realtek PCIe GbE Family Controller #2]
STATE
Miniport Running
Device PnP Started !miniport ffff8b00057531a0 -log
Datapath Normal
Interface Up
Media Connected
Power D0
References 0n11 !miniport ffff8b00057531a0 -ref
Total resets 0
Pending OID None
Flags BUS_MASTER, 64BIT_DMA, SG_DMA, CHECK_FOR_LOOPBACK,
DEFAULT_PORT_ACTIVATED, SUPPORTS_MEDIA_SENSE,
DOES_NOT_DO_LOOPBACK, MEDIA_CONNECTED

PnP flags RECEIVED_START, HARDWARE_DEVICE

[Microsoft Kernel Debug Network Adapter]
STATE
Miniport Running
Device PnP Started !miniport ffff8b00063f61a0 -log
Datapath Normal
Interface Up
Media Connected
Power D0
References 2 !miniport ffff8b00063f61a0 -ref
Total resets 0
Pending OID None
Flags NOT_BUS_MASTER, ALLOW_BUGCHECK_CALLBACK,
BUGCHECK_CALLBACK_REGISTERED, DEFAULT_PORT_ACTIVATED,
SUPPORTS_MEDIA_SENSE, DOES_NOT_DO_LOOPBACK,
MEDIA_CONNECTED

PnP flags VIRTUAL_DEVICE, HIDDEN, NO_HALT_ON_SUSPEND,
RECEIVED_START

The difference is NO_HALT_ON_SUSPEND? How can I add that flag? Is that flag all I need to add?

If NDIS filter driver cannot prevent NIC from shutdown how to do it?

Thank you for any suggestions.

I found a old post. https://community.osr.com/discussion/90157/how-to-keep-nic-functioning-during-system-shutdown

Doron Holan said that “You can send the NIC a usage notification which will put you both into the non power pagable group”.

I don’t understand how to send the NIC a usage notification from storport driver to some NIC.

Sooncheol_Won wrote:

The problem is that NIC is shutdown while restarting or power off system so that storport cannot read or write some disk blocks at last.

I realized that KDNET is alive always.

That’s not exactly true, although I guess it’s true enough. However,
KDNET (like all the KD transports) lives outside of the Windows kernel
driver world.  Those transports have their own drivers, dedicated only
to the kernel debugger, and they don’t serve any other requests.  They
can’t be reached by PnP, and they don’t respond to power messages.  You
can’t make your driver like that.

You can’t make your driver like that.

Well… you could. But it would be an epically bad idea. :stuck_out_tongue:

Peter

NO_HALT_ON_SUSPEND is a distraction; it has a poor name, and doesn’t have anything to do with this.

As others have mentioned, there’s a DeviceUsageTypePaging that is intended for this purpose. Unfortunately, you have an NDIS miniport driver, which means that you don’t get direct access to the device. So when you read WDM or WDF documentation, it doesn’t always apply to your NDIS miniport.

You can work around that by putting an NT Upper Filter driver on top of the device (not an NDIS lightweight filter driver), and issuing the IRP from there.

Do not use the TdiRegisterPnPHandlers mentioned in the other thread – that’s broken and old; it won’t work on modern versions of Windows.

Thanks for all your comments.
I studied hard about IRP_MN_DEVICE_USAGE_NOTIFICATION, DeviceUsageTypePaging, DO_POWER_PAGABLE, paging path and etc.
My storport driver can send last packets successfully now by using DeviceUsageTypePaging IRP.
Thanks Jeffrey Tippet especially.