Index: ic/re.c =================================================================== RCS file: /cvs/src/sys/dev/ic/re.c,v retrieving revision 1.216 diff -u -p -r1.216 re.c --- ic/re.c 10 Nov 2023 15:51:20 -0000 1.216 +++ ic/re.c 4 Dec 2023 01:03:30 -0000 @@ -199,6 +199,7 @@ int re_wol(struct ifnet*, int); #endif #if NKSTAT > 0 void re_kstat_attach(struct rl_softc *); +void re_kstat_detach(struct rl_softc *); #endif void in_delayed_cksum(struct mbuf *); @@ -1128,6 +1129,27 @@ fail_0: return (1); } +void +re_detach(struct rl_softc *sc) +{ + struct ifnet *ifp = &sc->sc_arpcom.ac_if; + +#if NKSTAT > 0 + re_kstat_detach(sc); +#endif + + /* Remove timeout handler */ + timeout_del(&sc->timer_handle); + + /* Detach PHY */ + if (LIST_FIRST(&sc->sc_mii.mii_phys) != NULL) + mii_detach(&sc->sc_mii, MII_PHY_ANY, MII_OFFSET_ANY); + + /* Delete media stuff */ + ifmedia_delete_instance(&sc->sc_mii.mii_media, IFM_INST_ANY); + ether_ifdetach(ifp); + if_detach(ifp); +} int re_newbuf(struct rl_softc *sc) @@ -2608,6 +2630,27 @@ freedma: destroy: bus_dmamap_destroy(sc->sc_dmat, re_ks_sc->re_ks_sc_map); free: + free(re_ks_sc, M_DEVBUF, sizeof(*re_ks_sc)); +} + +void +re_kstat_detach(struct rl_softc *sc) +{ + struct kstat *ks = sc->rl_kstat; + struct re_kstat_softc *re_ks_sc; + + if (ks == NULL) + return; + + kstat_remove(ks); + re_ks_sc = ks->ks_ptr; + kstat_destroy(ks); + + bus_dmamap_unload(sc->sc_dmat, re_ks_sc->re_ks_sc_map); + bus_dmamem_unmap(sc->sc_dmat, + (caddr_t)re_ks_sc->re_ks_sc_stats, sizeof(struct re_stats)); + bus_dmamem_free(sc->sc_dmat, &re_ks_sc->re_ks_sc_seg, 1); + bus_dmamap_destroy(sc->sc_dmat, re_ks_sc->re_ks_sc_map); free(re_ks_sc, M_DEVBUF, sizeof(*re_ks_sc)); } #endif /* NKSTAT > 0 */ Index: ic/revar.h =================================================================== RCS file: /cvs/src/sys/dev/ic/revar.h,v retrieving revision 1.7 diff -u -p -r1.7 revar.h --- ic/revar.h 27 Jul 2010 20:53:39 -0000 1.7 +++ ic/revar.h 4 Dec 2023 01:03:30 -0000 @@ -18,6 +18,7 @@ int re_intr(void *); int re_attach(struct rl_softc *, const char *); +void re_detach(struct rl_softc *); void re_reset(struct rl_softc *); int re_init(struct ifnet *); void re_stop(struct ifnet *); Index: pci/if_re_pci.c =================================================================== RCS file: /cvs/src/sys/dev/pci/if_re_pci.c,v retrieving revision 1.56 diff -u -p -r1.56 if_re_pci.c --- pci/if_re_pci.c 11 Mar 2022 18:00:48 -0000 1.56 +++ pci/if_re_pci.c 4 Dec 2023 01:03:30 -0000 @@ -223,19 +223,8 @@ re_pci_detach(struct device *self, int f { struct re_pci_softc *psc = (struct re_pci_softc *)self; struct rl_softc *sc = &psc->sc_rl; - struct ifnet *ifp = &sc->sc_arpcom.ac_if; - /* Remove timeout handler */ - timeout_del(&sc->timer_handle); - - /* Detach PHY */ - if (LIST_FIRST(&sc->sc_mii.mii_phys) != NULL) - mii_detach(&sc->sc_mii, MII_PHY_ANY, MII_OFFSET_ANY); - - /* Delete media stuff */ - ifmedia_delete_instance(&sc->sc_mii.mii_media, IFM_INST_ANY); - ether_ifdetach(ifp); - if_detach(ifp); + re_detach(sc); /* Disable interrupts */ if (sc->sc_ih != NULL) Index: cardbus/if_re_cardbus.c =================================================================== RCS file: /cvs/src/sys/dev/cardbus/if_re_cardbus.c,v retrieving revision 1.30 diff -u -p -r1.30 if_re_cardbus.c --- cardbus/if_re_cardbus.c 6 Apr 2022 18:59:28 -0000 1.30 +++ cardbus/if_re_cardbus.c 4 Dec 2023 01:03:30 -0000 @@ -232,19 +232,8 @@ re_cardbus_detach(struct device *self, i struct re_cardbus_softc *csc = (void *)self; struct rl_softc *sc = &csc->sc_rl; struct cardbus_devfunc *ct = csc->ct; - struct ifnet *ifp = &sc->sc_arpcom.ac_if; - /* Remove timeout handler */ - timeout_del(&sc->timer_handle); - - /* Detach PHY */ - if (LIST_FIRST(&sc->sc_mii.mii_phys) != NULL) - mii_detach(&sc->sc_mii, MII_PHY_ANY, MII_OFFSET_ANY); - - /* Delete media stuff */ - ifmedia_delete_instance(&sc->sc_mii.mii_media, IFM_INST_ANY); - ether_ifdetach(ifp); - if_detach(ifp); + re_detach(sc); /* Disable interrupts */ if (sc->sc_ih != NULL)