How should I handle my hardware when processing IRP_MN_SURPRSISE_REMOVAL?

The quick answer answer that you must assume your hardware is present and at least probe the hardware to see if it responds.  You might be thinking, "I thought surprise removal was only sent when my hardware was yanked from the machine."  Not so, please read this for an explanation as to why surprise removal can be multiple things in terms of state change.

The long answer stems from the plain and simple problem that you don't know why a surprise removal arrived in the stack.  If it is because a call to IoInvalidateDeviceState and then reporting PNP_DEVICE_FAILED, your hardware is still present and running.  This means that you must stop your DMA engine, disable interrupt generation in the hardware, and call IoDisconnectInterrupt if you are on a hardware bus.  If you are on a protocol bus like USB or firewire, you should probably cancel all sent I/O if hasn't already completed.  KMDF will automatically go through your power down sequence and perform hardware teardown when it gets a surprise removal, if your driver is WDM you must handle this yourself.