src/add-ons/kernel/drivers/network/ipro1000/dev/e1000/if_igb.c
/*********************************************************************
 *  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
igb_detach(device_t dev)
{
	struct adapter	*adapter = device_get_softc(dev);
	struct ifnet	*ifp = adapter->ifp;
	INIT_DEBUGOUT("igb_detach: begin");
	if (adapter->ifp->if_vlantrunk != NULL) {
		device_printf(dev,"Vlan in use, detach first\n");
		return (EBUSY);
	}
	ether_ifdetach(adapter->ifp);
	if (adapter->led_dev != NULL)
		led_destroy(adapter->led_dev);
#ifdef DEVICE_POLLING
	if (ifp->if_capenable & IFCAP_POLLING)
		ether_poll_deregister(ifp);
#endif
	IGB_CORE_LOCK(adapter);
	adapter->in_detach = 1;
	igb_stop(adapter);
	IGB_CORE_UNLOCK(adapter);
	e1000_phy_hw_reset(&adapter->hw);
	igb_release_manageability(adapter);
	igb_release_hw_control(adapter);
	if (adapter->wol) {
		E1000_WRITE_REG(&adapter->hw, E1000_WUC, E1000_WUC_PME_EN);
		E1000_WRITE_REG(&adapter->hw, E1000_WUFC, adapter->wol);
		igb_enable_wakeup(dev);
	}
	if (adapter->vlan_attach != NULL)
		EVENTHANDLER_DEREGISTER(vlan_config, adapter->vlan_attach);
	if (adapter->vlan_detach != NULL)
		EVENTHANDLER_DEREGISTER(vlan_unconfig, adapter->vlan_detach);
	callout_drain(&adapter->timer);
#ifdef DEV_NETMAP
	netmap_detach(adapter->ifp);
#endif 
	igb_free_pci_resources(adapter);
	bus_generic_detach(dev);
	if_free(ifp);
	igb_free_transmit_structures(adapter);
	igb_free_receive_structures(adapter);
	if (adapter->mta != NULL)
		free(adapter->mta, M_DEVBUF);
	IGB_CORE_LOCK_DESTROY(adapter);
	return (0);
}
static int igb_detach ( device_t dev ) { struct adapter * adapter = device_get_softc ( dev ) ; struct ifnet * ifp = adapter -> ifp ; INIT_DEBUGOUT ( " " ) ; if ( adapter -> ifp -> if_vlantrunk != NULL ) { device_printf ( dev , " \n " ) ; return ( EBUSY ) ; } ether_ifdetach ( adapter -> ifp ) ; if ( adapter -> led_dev != NULL ) led_destroy ( adapter -> led_dev ) ; #ifdef DEVICE_POLLING if ( ifp -> if_capenable & IFCAP_POLLING ) ether_poll_deregister ( ifp ) ; #endif IGB_CORE_LOCK ( adapter ) ; adapter -> in_detach = 1 ; igb_stop ( adapter ) ; IGB_CORE_UNLOCK ( adapter ) ; e1000_phy_hw_reset ( & adapter -> hw ) ; igb_release_manageability ( adapter ) ; igb_release_hw_control ( adapter ) ; if ( adapter -> wol ) { E1000_WRITE_REG ( & adapter -> hw , E1000_WUC , E1000_WUC_PME_EN ) ; E1000_WRITE_REG ( & adapter -> hw , E1000_WUFC , adapter -> wol ) ; igb_enable_wakeup ( dev ) ; } if ( adapter -> vlan_attach != NULL ) EVENTHANDLER_DEREGISTER ( vlan_config , adapter -> vlan_attach ) ; if ( adapter -> vlan_detach != NULL ) EVENTHANDLER_DEREGISTER ( vlan_unconfig , adapter -> vlan_detach ) ; callout_drain ( & adapter -> timer ) ; #ifdef DEV_NETMAP netmap_detach ( adapter -> ifp ) ; #endif igb_free_pci_resources ( adapter ) ; bus_generic_detach ( dev ) ; if_free ( ifp ) ; igb_free_transmit_structures ( adapter ) ; igb_free_receive_structures ( adapter ) ; if ( adapter -> mta != NULL ) free ( adapter -> mta , M_DEVBUF ) ; IGB_CORE_LOCK_DESTROY ( adapter ) ; 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 */ /* Give control back to firmware */ /* Unregister VLAN events */ /* DEV_NETMAP */