From e13f72484a72d3f19eb5a5ed41e7514c3e2ee20d Mon Sep 17 00:00:00 2001 From: dlg Date: Fri, 19 Jan 2024 03:46:14 +0000 Subject: [PATCH] consolidate pci and cardbus detach code, and have it detach kstats. this solves one probably with an re(4) going away. --- sys/dev/cardbus/if_re_cardbus.c | 15 ++-------- sys/dev/ic/re.c | 49 +++++++++++++++++++++++++++++++-- sys/dev/ic/revar.h | 3 +- sys/dev/pci/if_re_pci.c | 15 ++-------- 4 files changed, 53 insertions(+), 29 deletions(-) diff --git a/sys/dev/cardbus/if_re_cardbus.c b/sys/dev/cardbus/if_re_cardbus.c index 0d01d700793..b437fcc1054 100644 --- a/sys/dev/cardbus/if_re_cardbus.c +++ b/sys/dev/cardbus/if_re_cardbus.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_re_cardbus.c,v 1.30 2022/04/06 18:59:28 naddy Exp $ */ +/* $OpenBSD: if_re_cardbus.c,v 1.31 2024/01/19 03:46:15 dlg Exp $ */ /* * Copyright (c) 2005 Peter Valchev @@ -232,19 +232,8 @@ re_cardbus_detach(struct device *self, int flags) 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) diff --git a/sys/dev/ic/re.c b/sys/dev/ic/re.c index 70b4794020e..29074188922 100644 --- a/sys/dev/ic/re.c +++ b/sys/dev/ic/re.c @@ -1,4 +1,4 @@ -/* $OpenBSD: re.c,v 1.216 2023/11/10 15:51:20 bluhm Exp $ */ +/* $OpenBSD: re.c,v 1.217 2024/01/19 03:46:14 dlg Exp $ */ /* $FreeBSD: if_re.c,v 1.31 2004/09/04 07:54:05 ru Exp $ */ /* * Copyright (c) 1997, 1998-2003 @@ -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) @@ -2604,10 +2626,33 @@ unmap: bus_dmamem_unmap(sc->sc_dmat, (caddr_t)re_ks_sc->re_ks_sc_stats, sizeof(struct re_stats)); freedma: - bus_dmamem_free(sc->sc_dmat, &re_ks_sc->re_ks_sc_seg, 1); + bus_dmamem_free(sc->sc_dmat, &re_ks_sc->re_ks_sc_seg, + re_ks_sc->re_ks_sc_nsegs); 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, + re_ks_sc->re_ks_sc_nsegs); + 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 */ diff --git a/sys/dev/ic/revar.h b/sys/dev/ic/revar.h index 971a4da8c88..6a141f2a5c0 100644 --- a/sys/dev/ic/revar.h +++ b/sys/dev/ic/revar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: revar.h,v 1.7 2010/07/27 20:53:39 kettenis Exp $ */ +/* $OpenBSD: revar.h,v 1.8 2024/01/19 03:46:15 dlg Exp $ */ /* * Copyright (c) 2005 Peter Valchev @@ -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 *); diff --git a/sys/dev/pci/if_re_pci.c b/sys/dev/pci/if_re_pci.c index eb989fb8823..aaf30479bf3 100644 --- a/sys/dev/pci/if_re_pci.c +++ b/sys/dev/pci/if_re_pci.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_re_pci.c,v 1.56 2022/03/11 18:00:48 mpi Exp $ */ +/* $OpenBSD: if_re_pci.c,v 1.57 2024/01/19 03:46:15 dlg Exp $ */ /* * Copyright (c) 2005 Peter Valchev @@ -223,19 +223,8 @@ re_pci_detach(struct device *self, int flags) { 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) -- 2.20.1