struct el_softc *sc = el_softc[unit]; struct ifnet *ifp = &sc->is_if;

1

2

Declares as an argument a pointer to a bus data structure and a controller data structure for this controller. The controller data structure contains such information as the controller type, the controller name, and the current status of the controller. This completely identifies the adapter that is being unattached.

Declares a unit variable and initializes it to the controller number for this controller. This controller number identifies the specific 3Com 3C5x9 controller that is being unattached. The controller number is contained in the ctlr_num member of the controller data structure for this device.

7.2 Verifying That the Interface Has Shut Down

The following code verifies that the interface is down. Make sure that other errors returned by if_detach do not stop interface shutdown.

status = if_detach(ifp); 1 if (status == EBUSY) 2

return(status);

else if (status == ESUCCESS) 3 detachpfilter(sc->is_ed);

ifp->if_flags &= ~IFF_RUNNING;

4

1

2

3

4

Calls if_detach to remove this interface from the list of active interfaces.

If the interface is still in use, it cannot be detached, so failure is returned.

If the interface is not in use, detaches it from the list of those that the packet filter monitors.

Marks the interface as no longer running.

7.3Obtaining the Simple Lock and Shutting Down the Device

The following code shows how the el_unattach( ) routine obtains the simple lock, shuts down the device, and releases the simple lock:

s = splimp(); 1

simple_lock(&sc->el_softc_lock);

2

el_shutdown(sc); 3

simple_unlock(&sc->el_softc_lock); splx(s); 5

4

1

Calls the splimp( ) routine to mask all LAN hardware interrupts. Upon successful completion, splimp( ) stores an integer value in the

7–2Implementing the unattach Routine

Page 96
Image 96
Compaq AA-RNG2A-TE Verifying That the Interface Has Shut Down, Obtaining the Simple Lock and Shutting Down the Device