From owner-dev-commits-src-all@freebsd.org Mon Sep 13 09:45:18 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 0AD886789AC; Mon, 13 Sep 2021 09:45:18 +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 4H7M656sl7z3H4f; Mon, 13 Sep 2021 09:45:17 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 C7CCF24E20; Mon, 13 Sep 2021 09:45:17 +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 18D9jHDe045809; Mon, 13 Sep 2021 09:45:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 18D9jHm3045808; Mon, 13 Sep 2021 09:45:17 GMT (envelope-from git) Date: Mon, 13 Sep 2021 09:45:17 GMT Message-Id: <202109130945.18D9jHm3045808@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Wojciech Macek Subject: git: 41b0190cc404 - main - if_mvneta: Build the driver as a kernel module MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: wma X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 41b0190cc404e21cb8b430602eabfedc20107471 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Sep 2021 09:45:18 -0000 The branch main has been updated by wma: URL: https://cgit.FreeBSD.org/src/commit/?id=41b0190cc404e21cb8b430602eabfedc20107471 commit 41b0190cc404e21cb8b430602eabfedc20107471 Author: Hubert Mazur AuthorDate: 2021-09-13 09:44:31 +0000 Commit: Wojciech Macek CommitDate: 2021-09-13 09:44:31 +0000 if_mvneta: Build the driver as a kernel module Fix device detach and attach routine. Add required Makefile to build as a module. Remove entry from GENERIC, since now it can be loaded automatically. Tested on EspressoBin. Obtained from: Semihalf Reviewed by: manu Differential revision: https://reviews.freebsd.org/D31581 --- sys/dev/neta/if_mvneta.c | 73 ++++++++++++++++++++++++++++-------------------- sys/modules/Makefile | 2 ++ 2 files changed, 45 insertions(+), 30 deletions(-) diff --git a/sys/dev/neta/if_mvneta.c b/sys/dev/neta/if_mvneta.c index debb4a922cbc..242e139b8cac 100644 --- a/sys/dev/neta/if_mvneta.c +++ b/sys/dev/neta/if_mvneta.c @@ -222,6 +222,11 @@ static device_method_t mvneta_methods[] = { DEVMETHOD_END }; +static struct ofw_compat_data compat_data[] = { + { "marvell,armada-3700-neta", true }, + { NULL, false } +}; + DEFINE_CLASS_0(mvneta, mvneta_driver, mvneta_methods, sizeof(struct mvneta_softc)); DRIVER_MODULE(miibus, mvneta, miibus_driver, miibus_devclass, 0, 0); @@ -229,7 +234,7 @@ DRIVER_MODULE(mdio, mvneta, mdio_driver, mdio_devclass, 0, 0); MODULE_DEPEND(mvneta, mdio, 1, 1, 1); MODULE_DEPEND(mvneta, ether, 1, 1, 1); MODULE_DEPEND(mvneta, miibus, 1, 1, 1); -MODULE_DEPEND(mvneta, mvxpbm, 1, 1, 1); +SIMPLEBUS_PNP_INFO(compat_data); /* * List of MIB register and names @@ -609,6 +614,16 @@ mvneta_attach(device_t self) } #endif + error = bus_setup_intr(self, sc->res[1], + INTR_TYPE_NET | INTR_MPSAFE, NULL, mvneta_intrs[0].handler, sc, + &sc->ih_cookie[0]); + if (error) { + device_printf(self, "could not setup %s\n", + mvneta_intrs[0].description); + mvneta_detach(self); + return (error); + } + /* * MAC address */ @@ -704,8 +719,6 @@ mvneta_attach(device_t self) } } - ether_ifattach(ifp, sc->enaddr); - /* * Enable DMA engines and Initialize Device Registers. */ @@ -835,20 +848,11 @@ mvneta_attach(device_t self) mvneta_update_media(sc, ifm_target); } - sysctl_mvneta_init(sc); + ether_ifattach(ifp, sc->enaddr); callout_reset(&sc->tick_ch, 0, mvneta_tick, sc); - error = bus_setup_intr(self, sc->res[1], - INTR_TYPE_NET | INTR_MPSAFE, NULL, mvneta_intrs[0].handler, sc, - &sc->ih_cookie[0]); - if (error) { - device_printf(self, "could not setup %s\n", - mvneta_intrs[0].description); - ether_ifdetach(sc->ifp); - mvneta_detach(self); - return (error); - } + sysctl_mvneta_init(sc); return (0); } @@ -857,20 +861,28 @@ STATIC int mvneta_detach(device_t dev) { struct mvneta_softc *sc; + struct ifnet *ifp; int q; sc = device_get_softc(dev); + ifp = sc->ifp; - mvneta_stop(sc); - /* Detach network interface */ - if (sc->ifp) - if_free(sc->ifp); + if (device_is_attached(dev)) { + mvneta_stop(sc); + callout_drain(&sc->tick_ch); + ether_ifdetach(sc->ifp); + } for (q = 0; q < MVNETA_RX_QNUM_MAX; q++) mvneta_ring_dealloc_rx_queue(sc, q); for (q = 0; q < MVNETA_TX_QNUM_MAX; q++) mvneta_ring_dealloc_tx_queue(sc, q); + device_delete_children(dev); + + if (sc->ih_cookie[0] != NULL) + bus_teardown_intr(dev, sc->res[1], sc->ih_cookie[0]); + if (sc->tx_dtag != NULL) bus_dma_tag_destroy(sc->tx_dtag); if (sc->rx_dtag != NULL) @@ -881,6 +893,13 @@ mvneta_detach(device_t dev) bus_dma_tag_destroy(sc->rxbuf_dtag); bus_release_resources(dev, res_spec, sc->res); + + if (sc->ifp) + if_free(sc->ifp); + + if (mtx_initialized(&sc->mtx)) + mtx_destroy(&sc->mtx); + return (0); } @@ -1254,6 +1273,9 @@ mvneta_ring_alloc_rx_queue(struct mvneta_softc *sc, int q) return (0); fail: + mvneta_rx_lockq(sc, q); + mvneta_ring_flush_rx_queue(sc, q); + mvneta_rx_unlockq(sc, q); mvneta_ring_dealloc_rx_queue(sc, q); device_printf(sc->dev, "DMA Ring buffer allocation failure.\n"); return (error); @@ -1295,6 +1317,9 @@ mvneta_ring_alloc_tx_queue(struct mvneta_softc *sc, int q) return (0); fail: + mvneta_tx_lockq(sc, q); + mvneta_ring_flush_tx_queue(sc, q); + mvneta_tx_unlockq(sc, q); mvneta_ring_dealloc_tx_queue(sc, q); device_printf(sc->dev, "DMA Ring buffer allocation failure.\n"); return (error); @@ -1324,16 +1349,6 @@ mvneta_ring_dealloc_tx_queue(struct mvneta_softc *sc, int q) #endif if (sc->txmbuf_dtag != NULL) { - if (mtx_name(&tx->ring_mtx) != NULL) { - /* - * It is assumed that maps are being loaded after mutex - * is initialized. Therefore we can skip unloading maps - * when mutex is empty. - */ - mvneta_tx_lockq(sc, q); - mvneta_ring_flush_tx_queue(sc, q); - mvneta_tx_unlockq(sc, q); - } for (i = 0; i < MVNETA_TX_RING_CNT; i++) { txbuf = &tx->txbuf[i]; if (txbuf->dmap != NULL) { @@ -1372,8 +1387,6 @@ mvneta_ring_dealloc_rx_queue(struct mvneta_softc *sc, int q) rx = MVNETA_RX_RING(sc, q); - mvneta_ring_flush_rx_queue(sc, q); - if (rx->desc_pa != 0) bus_dmamap_unload(sc->rx_dtag, rx->desc_map); diff --git a/sys/modules/Makefile b/sys/modules/Makefile index 7ed2169445e4..b1063ad003d8 100644 --- a/sys/modules/Makefile +++ b/sys/modules/Makefile @@ -264,6 +264,7 @@ SUBDIR= \ mxge \ my \ ${_nctgpio} \ + ${_neta} \ ${_netgraph} \ ${_nfe} \ nfscl \ @@ -626,6 +627,7 @@ _rockchip= rockchip .if ${MACHINE_CPUARCH} == "aarch64" || ${MACHINE_CPUARCH} == "arm" _sdhci_fdt= sdhci_fdt _e6000sw= e6000sw +_neta= neta .endif .if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64"