From nobody Thu Jun 23 18:15:58 2022 X-Original-To: dev-commits-src-main@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 57B7987659A; Thu, 23 Jun 2022 18:15:59 +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 4LTT2l01Lmz3P2b; Thu, 23 Jun 2022 18:15:59 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1656008159; 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=w+WwtHgnPNS/3QBAy2TzC/r23/Cb49k847u75pPxmTI=; b=VUMPFY//alwhDnrGbi9HGMoQFir/W9jz+JNL7CXiNtd8ccMjz3mJkCBq/jgkCPFKbbvfIt Fl8bVzTUArS1NteE0fNeFUmuqc94Qi7DMogeGGrM9kYs17aKyam5n9e8IK4wD5O1CPZYaZ LtyuGS4cwvgR1fETzr98tLPH3QWVz+/eE3uhY2jCo/NU+WoWaqRf4nuP4U63YCRDOrDNJa olcvAsjZ8T+HbpsFRPWpoaEdCzLA57ABeaYlCQ/30g7E7A1RkeP+0ZATMiET4OhkZWGEMe P6pTafsIUAFCT8L9h4qLgocI7ZetkXp0EySlL3XjdUqOI4r1UtN2jRqkSMfwSw== 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 D5C991FDEC; Thu, 23 Jun 2022 18:15:58 +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 25NIFwqg014728; Thu, 23 Jun 2022 18:15:58 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 25NIFweH014727; Thu, 23 Jun 2022 18:15:58 GMT (envelope-from git) Date: Thu, 23 Jun 2022 18:15:58 GMT Message-Id: <202206231815.25NIFweH014727@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mitchell Horne Subject: git: 27b39e58b39e - main - if_dwc: add detach method List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: 27b39e58b39edb76a4bffdfe730edfe6bc22f329 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1656008159; 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=w+WwtHgnPNS/3QBAy2TzC/r23/Cb49k847u75pPxmTI=; b=SeVdeReTzifWGuVFfSqc/UPd2tTpaUChfZOhJ7vGSgz9nuy47I1Aco9oIJveY8/XozS2bf sjcKHAOIKDISSql2fKXG8Sy3f1EumlNck9KP8C7phaNqA+1cCBBQ1VmPmpXOtdvwpzDAXM biGGBnAOkeTs7UXcYOJbLmovvlDYem34IEsqnuyp6wcBTWGPIN3Su6Uil6ZEb5Xx8lPFqs dVnLRkSX8SpMU/YtzA4vEvdMXJoyxEX76j8vmZFIRXwjgU41T/X37szVT4J5clYMSJmnPZ OQ55bZk+bCqSSlwDgxz/96N/iL4G+tv+xaA6hAaNI86mLrXxzieIhET91+JsFA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1656008159; a=rsa-sha256; cv=none; b=XTaDI4yVyw3A+uRBOCDnnmOc4VITT3mjnDgkraQjWSsgJBGQWSG0REMcKPGYhd5WgaeBF9 6gn8rgfUlvm+gxyWnblfmoNMNf4tq+96z2KssjuyBm76dofmYX1YOwhSHUDGcguF7uWdYI TW07JQw85JLiGNGpCn5rlg6gGbkDe8JlCuZRf6wuO8oNhTHQOgBJzteqt2hvFVkTMA1Vqj gXTYYJN3wcbA5NYeVDlAGK1R+2KN/LKjMNaEKmf5fWlUXWSRB4QDsDPoiPmdb2hMl6obmZ rKkOJw+CW26gD1jPzQEbVNkAocYJOFpONNU2ADpHeTYY4uX3/GLUcIoNRlOfTA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=27b39e58b39edb76a4bffdfe730edfe6bc22f329 commit 27b39e58b39edb76a4bffdfe730edfe6bc22f329 Author: Mitchell Horne AuthorDate: 2022-06-21 13:26:44 +0000 Commit: Mitchell Horne CommitDate: 2022-06-23 18:15:10 +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 --- 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 e83d2f7906c9..531a83d1a41b 100644 --- a/sys/dev/dwc/if_dwc.c +++ b/sys/dev/dwc/if_dwc.c @@ -1043,6 +1043,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 */ @@ -1709,9 +1751,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),