A.3.9 Closing Network Interface Cards

As Figure A.3.9 illustrates, a transport driver unbinds itself from a network interface card by calling MacCloseAdapter through NdisCloseAdapter, with the binding block indicated by the NDIS binding handle. The NIC driver uses MacCloseAdapter to close the NIC binding, cancel the ISR, and prevent further requests to the network interface card. Because multiple transport drivers can have open bindings to one network interface card, the NIC driver keeps a reference count of open handles. If any requests remain on a binding when a transport driver calls MacCloseAdapter, the function returns NDIS_STATUS_PENDING, regardless of the state of the network interface card.

If MacCloseAdapter completes synchronously with either a success status code or an error code, the function unlinks the binding block from the NIC and transport driver block binding lists and dereferences these blocks. It then deallocates the binding block and calls the operating system to dereference the file object representing the open network interface card. The operating system ultimately deletes the file object and returns control to the transport driver.

MacCloseAdapter can also be asynchronous, returning NDIS_STATUS_PENDING. In this case, the NIC driver eventually calls NdisCompleteCloseAdapter, which forwards the call to ProtocolCloseAdapterComplete for postprocessing.

After the NIC driver has closed the NIC binding, the transport driver cannot submit further requests on this binding. It cannot call NdisReset even if it concludes the NIC close operation has suspended and hung.

Figure A.3.9 Closing network interface cards

It is possible for a NIC driver to close a binding for a known network interface card malfunction. The driver does this by calling ProtocolStatus through NdisIndicateStatus, passing an NDIS_STATUS_CLOSING general status code. Although this indication does not change the behavior of the transport driver or the NIC driver, the transport driver must call NdisCloseAdapter as soon as possible after receiving it. The NIC driver returns NDIS_STATUS_ADAPTER_NOT_OPEN for any requests made by the transport driver between the NDIS_STATUS_CLOSING indication and the call to NdisCloseAdapter.