From nobody Tue Jan 04 12:29:33 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 41F0B192F956; Tue, 4 Jan 2022 12:29:35 +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 4JSsPT5nkyz4jxM; Tue, 4 Jan 2022 12:29:33 +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 7015F18E40; Tue, 4 Jan 2022 12:29:33 +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 204CTXbT070886; Tue, 4 Jan 2022 12:29:33 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 204CTXZH070885; Tue, 4 Jan 2022 12:29:33 GMT (envelope-from git) Date: Tue, 4 Jan 2022 12:29:33 GMT Message-Id: <202201041229.204CTXZH070885@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: 4885d6f3ec5b - main - if_mvneta: Use clock frequency 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: wma X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 4885d6f3ec5bdb9c7bf57f7a07575089572ef3ab Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1641299374; 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=psoFXAcXoj9VMO31NB/5sIesUEVPgkeDBvO+VksGUNg=; b=CfekzvnmGtjNWc6PCq16odWylcX0NvYSgaST6Fi9HbWIQpuvmljaMVbOtYVSNo81RfZ4i2 SMyNEaKGvynKuyb1vhsC5n9u4T2vTcYanaPWdVFsnPmBTV4uy/ZB/ZFeNnzdjayvNmIOC7 bd9BH7DiDGvHgv3UFnH7xm26HEKfeAeC42TudAbB1B0q7YzMfiurOHsGbqcvR5UDdnWU5B Xyi36c3095+SmyzUdyIg+hyTPReBXxmdTnp4gq3JlWzJodbUU84q4GU2rEVi4pwJcoiBDj NdxduGyzF7ePY3N9A01zOx9qFOtLxJgY76EKi8LFjuuOvqkYywhVw/AMzVxXxw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1641299374; a=rsa-sha256; cv=none; b=EPMdY7nj94cBW4dlLKqNdRhBgyWMI4iiUePnkHHlH1FRAqIwkE3XxVDqOFplmAGjgnAV0g vPyWPEficXxLwHnoYsqvnSmYZIjAnZ+CoEzjwaKEd6slz8H2KyVi8r4WRW/FPIlkp+1pk5 ETyLQ+6JRgGHr3XH9yJBOmAhVW4XdgXnD0qytHZimoTgPUD/DyONkaJM5EAAJWUnUjekzc MocMvl5P6Qi+Bcp8lhdlU1CPUj6wPnLthwjSv+sPZx3fTS4fQd8ueF+/8ZqTTfWQkdFGcH IR2sVttMrlw5rbjN93Sklqb9rHPYMzx2LFunwMLsZadDyl7mRlaad+K1BMg7bA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by wma: URL: https://cgit.FreeBSD.org/src/commit/?id=4885d6f3ec5bdb9c7bf57f7a07575089572ef3ab commit 4885d6f3ec5bdb9c7bf57f7a07575089572ef3ab Author: Hubert Mazur AuthorDate: 2021-08-24 10:04:30 +0000 Commit: Wojciech Macek CommitDate: 2022-01-04 12:26:35 +0000 if_mvneta: Use clock frequency Make neta use frequency obtained from clock, instead of hardcoded one. Use default frequency in case of clock device failure. Remove unnecessary function calls to obtain frequency and use cached one instead. Reviewed by: manu Obtained from: Semihalf Differential revision: https://reviews.freebsd.org/D32336 --- sys/dev/neta/if_mvneta.c | 47 ++++++++++++++++++++++++++++----------------- sys/dev/neta/if_mvnetavar.h | 2 ++ 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/sys/dev/neta/if_mvneta.c b/sys/dev/neta/if_mvneta.c index c94e91b16013..4d54e95e807d 100644 --- a/sys/dev/neta/if_mvneta.c +++ b/sys/dev/neta/if_mvneta.c @@ -65,6 +65,8 @@ __FBSDID("$FreeBSD$"); #include #include +#include + #include #include @@ -200,9 +202,6 @@ STATIC int mvneta_detach(device_t); STATIC int mvneta_miibus_readreg(device_t, int, int); STATIC int mvneta_miibus_writereg(device_t, int, int, int); -/* Clock */ -STATIC uint32_t mvneta_get_clk(void); - static device_method_t mvneta_methods[] = { /* Device interface */ DEVMETHOD(device_detach, mvneta_detach), @@ -344,16 +343,6 @@ static struct { { mvneta_rxtxth_intr, "MVNETA aggregated interrupt" }, }; -STATIC uint32_t -mvneta_get_clk() -{ -#if defined(__aarch64__) - return (A3700_TCLK_250MHZ); -#else - return (get_tclk()); -#endif -} - static int mvneta_set_mac_address(struct mvneta_softc *sc, uint8_t *addr) { @@ -541,7 +530,9 @@ mvneta_attach(device_t self) #if !defined(__aarch64__) uint32_t reg; #endif - +#if defined(__aarch64__) + clk_t clk; +#endif sc = device_get_softc(self); sc->dev = self; @@ -563,6 +554,27 @@ mvneta_attach(device_t self) MVNETA_WRITE(sc, MVNETA_PRXINIT, 0x00000001); MVNETA_WRITE(sc, MVNETA_PTXINIT, 0x00000001); +#if defined(__aarch64__) + error = clk_get_by_ofw_index(sc->dev, ofw_bus_get_node(sc->dev), 0, + &clk); + if (error != 0) { + device_printf(sc->dev, + "Cannot get clock, using default frequency: %d\n", + A3700_TCLK_250MHZ); + sc->clk_freq = A3700_TCLK_250MHZ; + } else { + error = clk_get_freq(clk, &sc->clk_freq); + if (error != 0) { + device_printf(sc->dev, + "Cannot obtain frequency from parent clock\n"); + bus_release_resources(sc->dev, res_spec, sc->res); + return (error); + } + } +#else + sc->clk_freq = get_tclk(); +#endif + #if !defined(__aarch64__) /* * Disable port snoop for buffers and descriptors @@ -1380,7 +1392,7 @@ mvneta_ring_init_rx_queue(struct mvneta_softc *sc, int q) rx = MVNETA_RX_RING(sc, q); rx->dma = rx->cpu = 0; rx->queue_th_received = MVNETA_RXTH_COUNT; - rx->queue_th_time = (mvneta_get_clk() / 1000) / 10; /* 0.1 [ms] */ + rx->queue_th_time = (sc->clk_freq / 1000) / 10; /* 0.1 [ms] */ /* Initialize LRO */ rx->lro_enabled = FALSE; @@ -3389,7 +3401,7 @@ sysctl_set_queue_rxthtime(SYSCTL_HANDLER_ARGS) mvneta_rx_lockq(sc, arg->queue); rx = MVNETA_RX_RING(sc, arg->queue); time_mvtclk = rx->queue_th_time; - time_us = ((uint64_t)time_mvtclk * 1000ULL * 1000ULL) / mvneta_get_clk(); + time_us = ((uint64_t)time_mvtclk * 1000ULL * 1000ULL) / sc->clk_freq; mvneta_rx_unlockq(sc, arg->queue); mvneta_sc_unlock(sc); @@ -3406,8 +3418,7 @@ sysctl_set_queue_rxthtime(SYSCTL_HANDLER_ARGS) mvneta_sc_unlock(sc); return (EINVAL); } - time_mvtclk = - (uint64_t)mvneta_get_clk() * (uint64_t)time_us / (1000ULL * 1000ULL); + time_mvtclk = sc->clk_freq * (uint64_t)time_us / (1000ULL * 1000ULL); rx->queue_th_time = time_mvtclk; reg = MVNETA_PRXITTH_RITT(rx->queue_th_time); MVNETA_WRITE(sc, MVNETA_PRXITTH(arg->queue), reg); diff --git a/sys/dev/neta/if_mvnetavar.h b/sys/dev/neta/if_mvnetavar.h index 0e6cf7829197..b73ced5d2fe1 100644 --- a/sys/dev/neta/if_mvnetavar.h +++ b/sys/dev/neta/if_mvnetavar.h @@ -258,6 +258,8 @@ struct mvneta_softc { struct mtx mtx; struct resource *res[2]; void *ih_cookie[1]; + + uint64_t clk_freq; struct ifnet *ifp; uint32_t mvneta_if_flags;