| 5195 | } |
| 5196 | |
| 5197 | int |
| 5198 | iflib_device_deregister(if_ctx_t ctx) |
| 5199 | { |
| 5200 | if_t ifp = ctx->ifc_ifp; |
| 5201 | device_t dev = ctx->ifc_dev; |
| 5202 | |
| 5203 | /* Make sure VLANS are not using driver */ |
| 5204 | if (if_vlantrunkinuse(ifp)) { |
| 5205 | device_printf(dev, "Vlan in use, detach first\n"); |
| 5206 | return (EBUSY); |
| 5207 | } |
| 5208 | #ifdef PCI_IOV |
| 5209 | if (!CTX_IS_VF(ctx) && pci_iov_detach(dev) != 0) { |
| 5210 | device_printf(dev, "SR-IOV in use; detach first.\n"); |
| 5211 | return (EBUSY); |
| 5212 | } |
| 5213 | #endif |
| 5214 | |
| 5215 | STATE_LOCK(ctx); |
| 5216 | ctx->ifc_flags |= IFC_IN_DETACH; |
| 5217 | STATE_UNLOCK(ctx); |
| 5218 | |
| 5219 | /* Unregister VLAN handlers before calling iflib_stop() */ |
| 5220 | iflib_unregister_vlan_handlers(ctx); |
| 5221 | |
| 5222 | iflib_netmap_detach(ifp); |
| 5223 | ether_ifdetach(ifp); |
| 5224 | |
| 5225 | CTX_LOCK(ctx); |
| 5226 | iflib_stop(ctx); |
| 5227 | CTX_UNLOCK(ctx); |
| 5228 | |
| 5229 | iflib_rem_pfil(ctx); |
| 5230 | if (ctx->ifc_led_dev != NULL) |
| 5231 | led_destroy(ctx->ifc_led_dev); |
| 5232 | |
| 5233 | iflib_tqg_detach(ctx); |
| 5234 | CTX_LOCK(ctx); |
| 5235 | IFDI_DETACH(ctx); |
| 5236 | CTX_UNLOCK(ctx); |
| 5237 | |
| 5238 | /* ether_ifdetach calls if_qflush - lock must be destroy afterwards*/ |
| 5239 | iflib_free_intr_mem(ctx); |
| 5240 | |
| 5241 | bus_generic_detach(dev); |
| 5242 | |
| 5243 | iflib_tx_structures_free(ctx); |
| 5244 | iflib_rx_structures_free(ctx); |
| 5245 | |
| 5246 | iflib_deregister(ctx); |
| 5247 | |
| 5248 | device_set_softc(ctx->ifc_dev, NULL); |
| 5249 | if (ctx->ifc_flags & IFC_SC_ALLOCATED) |
| 5250 | free(ctx->ifc_softc, M_IFLIB); |
| 5251 | unref_ctx_core_offset(ctx); |
| 5252 | free(ctx, M_IFLIB); |
| 5253 | return (0); |
| 5254 | } |
no test coverage detected