FreeBSD/sys/dev/e1000/if_em.c
static int
em_detach(device_t dev)
{
	struct adapter	*adapter = device_get_softc(dev);
	if_t ifp = adapter->ifp;

	INIT_DEBUGOUT("em_detach: begin");

	/* Make sure VLANS are not using driver */
	if (if_vlantrunkinuse(ifp)) {
		device_printf(dev,"Vlan in use, detach first\n");
		return (EBUSY);
	}

#ifdef DEVICE_POLLING
	if (if_getcapenable(ifp) & IFCAP_POLLING)
		ether_poll_deregister(ifp);
#endif

	if (adapter->led_dev != NULL)
		led_destroy(adapter->led_dev);

	EM_CORE_LOCK(adapter);
	adapter->in_detach = 1;
	em_stop(adapter);
	EM_CORE_UNLOCK(adapter);
	EM_CORE_LOCK_DESTROY(adapter);

	e1000_phy_hw_reset(&adapter->hw);

	em_release_manageability(adapter);
	em_release_hw_control(adapter);

	/* Unregister VLAN events */
	if (adapter->vlan_attach != NULL)
		EVENTHANDLER_DEREGISTER(vlan_config, adapter->vlan_attach);
	if (adapter->vlan_detach != NULL)
		EVENTHANDLER_DEREGISTER(vlan_unconfig, adapter->vlan_detach); 

	ether_ifdetach(adapter->ifp);
	callout_drain(&adapter->timer);

#ifdef DEV_NETMAP
	netmap_detach(ifp);
#endif /* DEV_NETMAP */

	em_free_pci_resources(adapter);
	bus_generic_detach(dev);
	if_free(ifp);

	em_free_transmit_structures(adapter);
	em_free_receive_structures(adapter);

	em_release_hw_control(adapter);
	free(adapter->mta, M_DEVBUF);

	return (0);
}
/*********************************************************************
 *  Device removal routine
 *
 *  The detach entry point is called when the driver is being removed.
 *  This routine stops the adapter and deallocates all the resources
 *  that were allocated for driver operation.
 *
 *  return 0 on success, positive on failure
 *********************************************************************/
Device removal routine
The detach entry point is called when the driver is being removed.
This routine stops the adapter and deallocates all the resources
that were allocated for driver operation.

return 0 on success, positive on failure
Device removal routine The detach entry point is called when the driver is being removed . This routine stops the adapter and deallocates all the resources that were allocated for driver operation . return 0 on success positive on failure
static int
em_detach(device_t dev)
{
	struct adapter	*adapter = device_get_softc(dev);
	if_t ifp = adapter->ifp;
	INIT_DEBUGOUT("em_detach: begin");
	if (if_vlantrunkinuse(ifp)) {
		device_printf(dev,"Vlan in use, detach first\n");
		return (EBUSY);
	}
#ifdef DEVICE_POLLING
	if (if_getcapenable(ifp) & IFCAP_POLLING)
		ether_poll_deregister(ifp);
#endif
	if (adapter->led_dev != NULL)
		led_destroy(adapter->led_dev);
	EM_CORE_LOCK(adapter);
	adapter->in_detach = 1;
	em_stop(adapter);
	EM_CORE_UNLOCK(adapter);
	EM_CORE_LOCK_DESTROY(adapter);
	e1000_phy_hw_reset(&adapter->hw);
	em_release_manageability(adapter);
	em_release_hw_control(adapter);
	if (adapter->vlan_attach != NULL)
		EVENTHANDLER_DEREGISTER(vlan_config, adapter->vlan_attach);
	if (adapter->vlan_detach != NULL)
		EVENTHANDLER_DEREGISTER(vlan_unconfig, adapter->vlan_detach); 
	ether_ifdetach(adapter->ifp);
	callout_drain(&adapter->timer);
#ifdef DEV_NETMAP
	netmap_detach(ifp);
#endif 
	em_free_pci_resources(adapter);
	bus_generic_detach(dev);
	if_free(ifp);
	em_free_transmit_structures(adapter);
	em_free_receive_structures(adapter);
	em_release_hw_control(adapter);
	free(adapter->mta, M_DEVBUF);
	return (0);
}
static int em_detach ( device_t dev ) { struct adapter * adapter = device_get_softc ( dev ) ; if_t ifp = adapter -> ifp ; INIT_DEBUGOUT ( " " ) ; if ( if_vlantrunkinuse ( ifp ) ) { device_printf ( dev , " \n " ) ; return ( EBUSY ) ; } #ifdef DEVICE_POLLING if ( if_getcapenable ( ifp ) & IFCAP_POLLING ) ether_poll_deregister ( ifp ) ; #endif if ( adapter -> led_dev != NULL ) led_destroy ( adapter -> led_dev ) ; EM_CORE_LOCK ( adapter ) ; adapter -> in_detach = 1 ; em_stop ( adapter ) ; EM_CORE_UNLOCK ( adapter ) ; EM_CORE_LOCK_DESTROY ( adapter ) ; e1000_phy_hw_reset ( & adapter -> hw ) ; em_release_manageability ( adapter ) ; em_release_hw_control ( adapter ) ; if ( adapter -> vlan_attach != NULL ) EVENTHANDLER_DEREGISTER ( vlan_config , adapter -> vlan_attach ) ; if ( adapter -> vlan_detach != NULL ) EVENTHANDLER_DEREGISTER ( vlan_unconfig , adapter -> vlan_detach ) ; ether_ifdetach ( adapter -> ifp ) ; callout_drain ( & adapter -> timer ) ; #ifdef DEV_NETMAP netmap_detach ( ifp ) ; #endif em_free_pci_resources ( adapter ) ; bus_generic_detach ( dev ) ; if_free ( ifp ) ; em_free_transmit_structures ( adapter ) ; em_free_receive_structures ( adapter ) ; em_release_hw_control ( adapter ) ; free ( adapter -> mta , M_DEVBUF ) ; return ( 0 ) ; }
Device removal routine
  The detach entry point is called when the driver is being removed.
Device removal routine The detach entry point is called when the driver is being removed .
/* Make sure VLANS are not using driver */ /* Unregister VLAN events */ /* DEV_NETMAP */