A.2.3.8 Interrupt Handling Functions

The NDIS interface library provides several interrupt handling functions for use in a multiprocessor environment, which are listed in Table A.2.11. These functions relate to network interface card interrupts to a host processor. Windows NT makes it invalid to call NdisAcquireSpinLock or NdisReleaseSpinLock from within an ISR. For more information about spin locks, see Section A.2.3.11.

Consider what happens if an executing NIC driver thread acquires a spin lock, begins manipulating associated data structures, and is then interrupted by the network controller hardware. In handling the interrupt, the driver enters a section of code in the ISR that needs the data structures that the spin lock protects. Therefore, the driver needs to acquire the lock from within the ISR to inspect the data structures. The driver must essentially acquire the spin lock from itself. If it attempts to do this, an infinite loop occurs, since the interrupt has pre-empted the locked region of code.

To alleviate this problem, the NIC driver calls NdisSynchronizeWithInterrupt from most functions (except MacInterruptServiceRoutine and MacSynchronizeFunction) to synchronize access to data that the ISR shares with non-ISR functions. NdisSynchronizeWithInterrupt raises the IRQL of the executing thread and then calls MacSynchronizeFunction to access shared data. Because of the raised IRQL, the ISR cannot execute on any processor while MacSynchronizeFunction is running.

A typical use of interrupt synchronization by the NIC driver is to protect a global variable that counts the number of interrupts received but not processed. The ISR must increment this variable and a non-ISR NIC driver function must decrement it once the ISR processes an interrupt. The decrement operation must be non-interruptible, but this is not ensured because interrupts are enabled. Therefore, the driver must use interrupt synchronization to protect the variable. Access from the ISR requires no special precautions. However, the driver must access the variable from non-ISR functions by calling NdisSynchronizeWithInterrupt.

Table A.2.11 Interrupt Handling Functions

Function

Definition

NdisInitializeInterrupt

Associates the MacInterruptServiceRoutine and MacDeferredProcessingRoutine functions with a network interface card.

NdisRemoveInterrupt

Stops interrupt reception by MacInterruptServiceRoutine during network interface card removal.

NdisSynchronizeWithInterrupt

Synchronizes access to data shared between non-ISR functions and MacInterruptServiceRoutine.