Index: head/sys/dev/vnic/nic_main.c =================================================================== --- head/sys/dev/vnic/nic_main.c +++ head/sys/dev/vnic/nic_main.c @@ -247,7 +247,9 @@ nicpf_detach(device_t dev) { struct nicpf *nic; + int err; + err = 0; nic = device_get_softc(dev); callout_drain(&nic->check_link); @@ -257,7 +259,12 @@ nicpf_free_res(nic); pci_disable_busmaster(dev); - return (0); +#ifdef PCI_IOV + err = pci_iov_detach(dev); + if (err != 0) + device_printf(dev, "SR-IOV in use. Detach first.\n"); +#endif + return (err); } /* @@ -1055,6 +1062,9 @@ nic->msix_enabled = 0; nic->num_vec = 0; } + + bus_release_resource(nic->dev, SYS_RES_MEMORY, + rman_get_rid(nic->msix_table_res), nic->msix_table_res); } static void @@ -1071,7 +1081,7 @@ nic->msix_entries[irq].handle); } - bus_release_resource(nic->dev, SYS_RES_IRQ, irq, + bus_release_resource(nic->dev, SYS_RES_IRQ, irq + 1, nic->msix_entries[irq].irq_res); } } Index: head/sys/dev/vnic/thunder_bgx.c =================================================================== --- head/sys/dev/vnic/thunder_bgx.c +++ head/sys/dev/vnic/thunder_bgx.c @@ -136,12 +136,16 @@ thunder_bgx_attach(device_t dev) { struct bgx *bgx; - uint8_t lmac; + uint8_t lmacid; int err; int rid; + struct lmac *lmac; bgx = malloc(sizeof(*bgx), M_BGX, (M_WAITOK | M_ZERO)); bgx->dev = dev; + + lmac = device_get_softc(dev); + lmac->bgx = bgx; /* Enable bus mastering */ pci_enable_busmaster(dev); /* Allocate resources - configuration registers */ @@ -168,11 +172,11 @@ bgx_init_hw(bgx); /* Enable all LMACs */ - for (lmac = 0; lmac < bgx->lmac_count; lmac++) { - err = bgx_lmac_enable(bgx, lmac); + for (lmacid = 0; lmacid < bgx->lmac_count; lmacid++) { + err = bgx_lmac_enable(bgx, lmacid); if (err) { device_printf(dev, "BGX%d failed to enable lmac%d\n", - bgx->bgx_id, lmac); + bgx->bgx_id, lmacid); goto err_free_res; } } @@ -203,6 +207,12 @@ for (lmacid = 0; lmacid < bgx->lmac_count; lmacid++) bgx_lmac_disable(bgx, lmacid); + bgx_vnic[bgx->bgx_id] = NULL; + bus_release_resource(dev, SYS_RES_MEMORY, + rman_get_rid(bgx->reg_base), bgx->reg_base); + free(bgx, M_BGX); + pci_disable_busmaster(dev); + return (0); }