10
Implementing a Watchdog Section
Network device drivers can take advantage of the watchdog timer. The network layer implements this mechanism to ensure that the network device is transmitting data. The driver starts the watchdog timer when it sends a transmit request to the device. After it receives the transmit completion interrupt, the driver stops the timer. If the interrupt never happens, the timer expires and the driver’s watchdog interface is called.
The watchdog timer is implemented using the if_timer member of the device’s ifnet data structure. The value stored there represents the number of seconds to wait for the transmit to complete. Once per second, the network layer examines this value. If it is 0 (zero), then the timer is disabled. Otherwise, the value is decremented, and if it reaches 0 (zero), the driver’s watchdog interface is called.
The watchdog section of a network device driver is an optional interface, but we recommend that all network drivers have one.
The if_el device driver implements a watchdog( ) routine called el_watch( ), which performs the following tasks:
•Sets the IPL and obtains the simple lock (Section 10.1)
•Increments the transmit timeout counter and calls the
el_reset_locked( ) routine to reset the unit (Section 10.2)
•Releases the simple lock and resets the IPL (Section 10.3)
10.1Setting the IPL and Obtaining the Simple Lock
The following code shows how to set up the el_watch( ) routine and shows how el_watch( ) sets the IPL and obtains the simple lock.
static int el_watch(int unit)
{
register struct el_softc *sc = el_softc[unit]; register struct ifnet *ifp =
int s;
s = splimp(); 1
1
Calls the splimp( ) routine to mask all LAN hardware interrupts. On successful completion, splimp( ) stores an integer value in the s variable. This integer value represents the CPU priority level that existed prior to the call to splimp( ).
Implementing a Watchdog Section