From nobody Mon Jul 04 16:40:03 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id CB0511893FCA; Mon, 4 Jul 2022 16:40:05 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4LcBP02DL6z4SCb; Mon, 4 Jul 2022 16:40:04 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1656952804; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=96YU9Sa6vgwoP8/UOFhy+NQdUcZII3Ie+2x1ufvEfWI=; b=aiOORnV8QwyZKH128TwCqfqMF+gv1+SW1di/3etOnCFssvQQ75WOa1hshXSKKCS/F36FDq 5QIsh55AAJ9DGIoXFsEzDm9eFEtZhRDKSZBYAZ7JMhsMnkgYm+ytPoPhjlG6JGK2x+W75n hmlemkPdxA7hB4GW53wD4Hdd6BoljquGhJWqXNfb+q2gGCw6HM5ASUdAMASyd28Dek8S47 y7CjHN2d0Ajw4ECNklJvUp9qC/CnnnJysqPWMKO6MTKHM+/BsIEOabxFM9X1yX1YcKbZ+H c+PZBeizeb5AFM/f0FW/jJlOMiCoKV5fTHm+qYs9N0ZoOqpOq4HXo3C+pu2MUg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id DB30D14BAF; Mon, 4 Jul 2022 16:40:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 264Ge3tV043091; Mon, 4 Jul 2022 16:40:03 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 264Ge327043088; Mon, 4 Jul 2022 16:40:03 GMT (envelope-from git) Date: Mon, 4 Jul 2022 16:40:03 GMT Message-Id: <202207041640.264Ge327043088@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mitchell Horne Subject: git: 5dec16de37f5 - stable/13 - if_dwc: add detach method List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mhorne X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 5dec16de37f5f1d9650525b3ee5d476b453ef184 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1656952804; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=96YU9Sa6vgwoP8/UOFhy+NQdUcZII3Ie+2x1ufvEfWI=; b=SyfFbMbP1RyZpbboWg8B8UcLwVxf0tPKxjLzg/fmx6s+LGu4WdDNTvzNmCfsS2gzPAwHD/ tfu790edJ03F/IKn6olSK3oPgDMgFtKC086LjzKgX7bvvJ4uvIZLsOjQw1kqE6fmU41jn0 ZOk+xLk59FXl31GkcopbzkPtJIHEt1JzGeggpZgSso47TPBBzr1p8z03zOgh5SgNrTFmdn nLEV2y8x8NqSU8UKHpnYYlNLXr9TeGYQreXOqnwZeDF3pUYDAM0exH9ekWJzsIVjnSRIPp JE3FHq4pSiPYaFQcyw+CxkooERP0tdkDjoJPS6kf6EAzlrVxZ1envF0i81pvPg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1656952804; a=rsa-sha256; cv=none; b=ymbLLD3sLH8aRleFiJKFOnbld0HtkvtAhgKO6YDxNLwM9PerRIpZtU6+I30Iaet7QNRYWm R9itHeARrFoPFiE+vb/V2YAKznFhkksW/RWX4Y2GFwEDGaKQYB6JqeVY89EI0yY4Gc/S2Y APCiKk3u0vzU49iXHpMNGqyvxalPllPc3fTk47BLIwvlLiw70wU+E9cieM6IqiZ8ZYC2AU +rcLwlzhpT4tndEgZEL2Tkz4b2l7OMDrzGQjNTFD1ivMNf9jRHyIA90SlPBr7PxGmnoksV Iid7yAXJ95RLF8kFqkTHyUaGRsGJlJMR8S4FzC4/2FnhJ6uwKv1TMx6lRX65aA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=5dec16de37f5f1d9650525b3ee5d476b453ef184 commit 5dec16de37f5f1d9650525b3ee5d476b453ef184 Author: Mitchell Horne AuthorDate: 2022-06-21 13:26:44 +0000 Commit: Mitchell Horne CommitDate: 2022-07-04 16:34:57 +0000 if_dwc: add detach method It can be useful for testing. Reviewed by: manu MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D35496 (cherry picked from commit 27b39e58b39edb76a4bffdfe730edfe6bc22f329) --- sys/dev/dwc/if_dwc.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/sys/dev/dwc/if_dwc.c b/sys/dev/dwc/if_dwc.c index 44b9b0b3179c..e32ac20f5749 100644 --- a/sys/dev/dwc/if_dwc.c +++ b/sys/dev/dwc/if_dwc.c @@ -1057,6 +1057,48 @@ out: return (0); } +static void +free_dma(struct dwc_softc *sc) +{ + bus_dmamap_t map; + int idx; + + /* Clean up RX DMA resources and free mbufs. */ + for (idx = 0; idx < RX_DESC_COUNT; ++idx) { + if ((map = sc->rxbuf_map[idx].map) != NULL) { + bus_dmamap_unload(sc->rxbuf_tag, map); + bus_dmamap_destroy(sc->rxbuf_tag, map); + m_freem(sc->rxbuf_map[idx].mbuf); + } + } + if (sc->rxbuf_tag != NULL) + bus_dma_tag_destroy(sc->rxbuf_tag); + if (sc->rxdesc_map != NULL) { + bus_dmamap_unload(sc->rxdesc_tag, sc->rxdesc_map); + bus_dmamem_free(sc->rxdesc_tag, sc->rxdesc_ring, + sc->rxdesc_map); + } + if (sc->rxdesc_tag != NULL) + bus_dma_tag_destroy(sc->rxdesc_tag); + + /* Clean up TX DMA resources. */ + for (idx = 0; idx < TX_DESC_COUNT; ++idx) { + if ((map = sc->txbuf_map[idx].map) != NULL) { + /* TX maps are already unloaded. */ + bus_dmamap_destroy(sc->txbuf_tag, map); + } + } + if (sc->txbuf_tag != NULL) + bus_dma_tag_destroy(sc->txbuf_tag); + if (sc->txdesc_map != NULL) { + bus_dmamap_unload(sc->txdesc_tag, sc->txdesc_map); + bus_dmamem_free(sc->txdesc_tag, sc->txdesc_ring, + sc->txdesc_map); + } + if (sc->txdesc_tag != NULL) + bus_dma_tag_destroy(sc->txdesc_tag); +} + /* * if_ functions */ @@ -1730,9 +1772,55 @@ dwc_attach(device_t dev) return (0); } +static int +dwc_detach(device_t dev) +{ + struct dwc_softc *sc; + + sc = device_get_softc(dev); + + /* + * Disable and tear down interrupts before anything else, so we don't + * race with the handler. + */ + WRITE4(sc, INTERRUPT_ENABLE, 0); + if (sc->intr_cookie != NULL) { + bus_teardown_intr(dev, sc->res[1], sc->intr_cookie); + } + + if (sc->is_attached) { + DWC_LOCK(sc); + sc->is_detaching = true; + dwc_stop_locked(sc); + DWC_UNLOCK(sc); + callout_drain(&sc->dwc_callout); + ether_ifdetach(sc->ifp); + } + + if (sc->miibus != NULL) { + device_delete_child(dev, sc->miibus); + sc->miibus = NULL; + } + bus_generic_detach(dev); + + /* Free DMA descriptors */ + free_dma(sc); + + if (sc->ifp != NULL) { + if_free(sc->ifp); + sc->ifp = NULL; + } + + bus_release_resources(dev, dwc_spec, sc->res); + + mtx_destroy(&sc->mtx); + return (0); +} + static device_method_t dwc_methods[] = { DEVMETHOD(device_probe, dwc_probe), DEVMETHOD(device_attach, dwc_attach), + DEVMETHOD(device_detach, dwc_detach), /* MII Interface */ DEVMETHOD(miibus_readreg, dwc_miibus_read_reg),