Article View: linux.kernel.netdev
Article #10851Re: [PATCH RFC net-next] net: airoha: npu: attach passive devfreq scaling
From: Lorenzo Bianconi
Date: Wed, 04 Nov 2026 08:22
Date: Wed, 04 Nov 2026 08:22
166 lines
12815 bytes
12815 bytes
--GXeSiHAEIfQDVlvR
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
On Nov 04, Christian Marangi wrote:
> The NPU can scale to different operating state from idle to normal to
> turbo. Attach a passive devfreq that will scale the NPU frequency with the
> CPU with the use of OPP table and opp-required properties.
>=20
> Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
> ---
>=20
> Posted as RFC to understand if it's the correct way to handle this...
>=20
> DT patch will come later.
>=20
> drivers/net/ethernet/airoha/airoha_npu.c | 61 ++++++++++++++++++++++-
> include/linux/soc/airoha/airoha_offload.h | 3 ++
> 2 files changed, 63 insertions(+), 1 deletion(-)
>=20
> diff --git a/drivers/net/ethernet/airoha/airoha_npu.c b/drivers/net/ether=
net/airoha/airoha_npu.c
> index 4d3195eb00f7..f8055ca65ec4 100644
> --- a/drivers/net/ethernet/airoha/airoha_npu.c
> +++ b/drivers/net/ethernet/airoha/airoha_npu.c
> @@ -12,6 +12,8 @@
> #include <linux/of_platform.h>
> #include <linux/of_reserved_mem.h>
> #include <linux/regmap.h>
> +#include <linux/pm_opp.h>
> +#include <linux/clk.h>
> =20
> #include "airoha_eth.h"
> =20
> @@ -656,6 +658,62 @@ void airoha_npu_put(struct airoha_npu *npu)
> }
> EXPORT_SYMBOL_GPL(airoha_npu_put);
> =20
> +static int airoha_npu_devfreq_get_cur_freq(struct device *dev, unsigned =
long *freq)
> +{
> + struct airoha_npu *npu =3D dev_get_drvdata(dev);
> +
> + *freq =3D clk_get_rate(npu->clk);
> +
> + return 0;
> +}
> +
> +static int airoha_npu_devfreq_target(struct device *dev, unsigned long *=
freq,
> + u32 flags)
> +{
> + struct airoha_npu *npu =3D dev_get_drvdata(dev);
> +
> + return clk_set_rate(npu->clk, *freq);
> +}
> +
> +static int airoha_npu_devfreq_get_dev_status(struct device *dev,
> + struct devfreq_dev_status *stat)
> +{
> + struct airoha_npu *npu =3D dev_get_drvdata(dev);
> +
> + stat->busy_time =3D 0;
> + stat->total_time =3D 0;
> + stat->current_frequency =3D clk_get_rate(npu->clk);
> +
> + return 0;
> +}
> +
> +static struct devfreq_dev_profile airoha_npu_devfreq_profile =3D {
> + .target =3D airoha_npu_devfreq_target,
> + .get_dev_status =3D airoha_npu_devfreq_get_dev_status,
> + .get_cur_freq =3D airoha_npu_devfreq_get_cur_freq
> +};
> +
> +static int airoha_npu_devfreq_probe(struct device *dev)
> +{
> + struct airoha_npu *npu =3D dev_get_drvdata(dev);
> + struct devfreq *devfreq;
> + int ret;
> +
> + npu->clk =3D devm_clk_get_enabled(dev, NULL);
I guess this should be devm_clk_get_optional_enabled() otherwise this patch
will break backward compatibility. Moreover, we should bail out early if
npu->clk is NULL.
> + if (IS_ERR(npu->clk))
> + return dev_err_probe(dev, PTR_ERR(npu->clk), "failed to get clk\n");
> +
> + ret =3D devm_pm_opp_of_add_table(dev);
> + if (ret)
> + return dev_err_probe(dev, ret, "failed to parse NPU freq thresholds\n"=
);
> +
> + npu->gov_data.parent_type =3D CPUFREQ_PARENT_DEV;
> + devfreq =3D devm_devfreq_add_device(dev, &airoha_npu_devfreq_profile,
> + DEVFREQ_GOV_PASSIVE, &npu->gov_data);
> +
> + return PTR_ERR_OR_ZERO(devfreq);
> +}
> +
> static const struct airoha_npu_soc_data en7581_npu_soc_data =3D {
> .fw_rv32 =3D {
> .name =3D NPU_EN7581_FIRMWARE_RV32,
> @@ -803,8 +861,9 @@ static int airoha_npu_probe(struct platform_device *p=
dev)
> (val >> 16) & 0xffff, val & 0xffff);
> =20
> platform_set_drvdata(pdev, npu);
> + dev_set_drvdata(dev, npu);
why do we need that one? I guess this is exactly what platform_set_drvdata(=
) is
doing, right?
Regards,
Lorenzo
> =20
> - return 0;
> + return airoha_npu_devfreq_probe(dev);
> }
> =20
> static struct platform_driver airoha_npu_driver =3D {
> diff --git a/include/linux/soc/airoha/airoha_offload.h b/include/linux/so=
c/airoha/airoha_offload.h
> index 7589fccfeef6..ac776dc31487 100644
> --- a/include/linux/soc/airoha/airoha_offload.h
> +++ b/include/linux/soc/airoha/airoha_offload.h
> @@ -6,6 +6,7 @@
> #ifndef AIROHA_OFFLOAD_H
> #define AIROHA_OFFLOAD_H
> =20
> +#include <linux/devfreq.h>
> #include <linux/skbuff.h>
> #include <linux/spinlock.h>
> #include <linux/workqueue.h>
> @@ -167,6 +168,8 @@ struct airoha_npu {
> #if (IS_BUILTIN(CONFIG_NET_AIROHA_NPU) || IS_MODULE(CONFIG_NET_AIROHA_NP=
U))
> struct device *dev;
> struct regmap *regmap;
> + struct clk *clk;
> + struct devfreq_passive_data gov_data;
> =20
> struct airoha_npu_core {
> struct airoha_npu *npu;
> --=20
> 2.55.0
>=20
--GXeSiHAEIfQDVlvR
Content-Type: application/pgp-signature; name=signature.asc
-----BEGIN PGP SIGNATURE-----
iHUEABYKAB0WIQTquNwa3Txd3rGGn7Y6cBh0uS2trAUCaurrNwAKCRA6cBh0uS2t
rELpAPwI9Nyf59rcUT+dErD/iejg4G1NiCfVcWRFwPmERqWr2QD/dKM7AqI7pn1A
Ju7qDHM8TiXXoQDNkpgJgPGDMOaVXgw=
=UYLH
-----END PGP SIGNATURE-----
--GXeSiHAEIfQDVlvR--
Technical Details
Message-ID:
<aurrN349nP-b6FK2@lore-desk>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-356282-linux-kernel-netdev=dewy.ruReferences:
<20261104072940.52933-1-ansuelsmth@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-356282-linux-kernel-netdev=dewy.ru From: lorenzo@kernel.org (Lorenzo Bianconi) Newsgroups: linux.kernel.netdev Subject: Re: [PATCH RFC net-next] net: airoha: npu: attach passive devfreq scaling Date: Wed, 4 Nov 2026 09:22:15 +0100 Organization: Usenet Network Message-ID: <aurrN349nP-b6FK2@lore-desk> References: <20261104072940.52933-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="GXeSiHAEIfQDVlvR" Injection-Info: usenet.network; logging-data="3353283"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:oCakG5NdsFdb3Ex+VC3jICtUiRE= sha256:HHLOAAqugRtXGyv9ml3bZ2hR6cndyotgsR7LbdBS7fc= sha1:69cwQKqdZ3S5JnkZR/ANcMzdu9U= sha256:y0aJPPYMvTkMIgV5Iy3BUhU4kii0e3w6Y0xkXACIqhQ= Content-Disposition: inline List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 4BC81112B34; Wed, 4 Nov 2026 11:27:28 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.401 X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id mhm9Tgzou9Pn; Wed, 4 Nov 2026 11:27:21 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-356282-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id A5DFD112B2D; Wed, 4 Nov 2026 11:27:10 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 6684E2A6E0; Wed, 4 Nov 2026 08:22:19 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1793780539; b=enix2hpfv22ESba0QzKIm83LV6utVDpHjY30vkfuivReZGDF1FK+2dVcK5kJhVNWRNtu MUbBsI/v6IDdinN/xbNjDmymvv3LX218ysOC3vAso7FoknWnoagMT+/OfWsXqxb2GqUBv +H1JhDgPflByBKvteQ2Lw/iyvV28+XHHXLgNh9vaieJAYBo0KpM1d55wFasHN7K9nVNuX b4ugZIsU4wzyxdjGti+/6PIPrUvLFKA0Vv3bs/ukDNTKr4M6+srq7Lls8Ts5BAnE0/pvZ EwqpbmH39fM8S3QMIhtKK5x8yjLOPuYikj2l9qi2dyrHd1Q+v5Zn35zTmdMXfdgXa+g== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793780539; h=X-Original-To:Received:Received:DKIM-Signature:Date:From:To:Cc: Subject:Message-ID:References:X-Mailing-List:List-Id:List-Post: List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence: MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=pADrcnEYh45IHa88Qe/iiabroBcjL7BN29WsN4XYUyU=; b=olqGdLkyEjM/1dlwg9o9c0OiPsmPHbzVHbgU5aG1drtbtbZrkNVTbpvOhVb15tIE1Wp0 O2kECjTFSWEkwlRZX7YLs46gJdeD2UE/j+RRhH4UgXG+aryfB8LFS7fKMZ8DTxa/ypAxr 5N/umIeGk7xg21yRKWEJ46LrIWUX//FCo0MMuxPNfSQd8KlaqGD8jRtB8MsvLZu8UKU4c 875wE4vRhGFVZC0kcn3N0EMg0cXgBD0DqwtWPIbJZcci2h8CvBKegA5iepdpuUv1Qqbit jrr7s+Q2U2hM6dQ6Iuev3aKMAajpSBZW0n8MTyTIpNzGrf8lbzV5F5tXAx1uwDLh1jA== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=EkMv8SpD; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3E1F6606A331; Wed, 4 Nov 2026 08:22:19 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=EkMv8SpD X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793780538; b=MJ0U7s4dgAp7n0S2zUd3sBK9Mks4qOlJy7ofdDurcuAXuZdHblR/V0dTFfuct/NNbIH3 rWaAHnWtNyu2PETJIOQ5v+YmFSrECm5i54PvM6w1OPZKB0dMMEBZZbt2o71pIxbYo+ueJ e/Y2Tu/tmGwuPZNwPlkc6x8LxAgoCz4qc64zhfn3Htyar5CPZ5f+DYfiM2QXNRw0yeb8H Gm/Uq3u8e/J0UK0qqmozDGPuF1JZ449+yNbh7Ca7o7YKwZ5OW0dD4pQRyDBM6qKRXLqj5 kY6iIRmxp+RRdCqpajUlXKHaq+iaww7zyRZ/gy0jN1scqtRjhlJ9SEnPoRuVYHQUjXQ== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793780538; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=pADrcnEYh45IHa88Qe/iiabroBcjL7BN29WsN4XYUyU=; b=QKzz11uuurqNKPpdJQg0EFLE0kbuy7DJWDG8dPWytnEXlSUaQdyQ1ucCf4jYegk6Szw5 RXtKm8puw70bQkS0pYXoa006f8NQMRH9JxLk4mA+MuiQZC3/n1QCnlIxK9nvi1TOz+BJW t2uQS3NZDE7n0BPmMnLWBV11wy+ta2jiVFWh+iYcv43NRXajGXRgABDZMZTD7dBSUMxZW wk0zMfpyuGAume0Q/gaqhNgGb4sMBqc1i44o56mpHEgcmfICtQOJhOXljrwzcfWET+wYV 5cfjyhygWCFP/xLsBQeTmdn5lhGqToEGJXLawmxBqo3ht8G5cx9MfL/Yj+pv5h+4FJA== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=EkMv8SpD; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1CD4A606A31B; Wed, 4 Nov 2026 08:22:17 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3C32D1F000C1; Wed, 4 Nov 2026 08:22:17 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793780537; bh=pADrcnEYh45IHa88Qe/iiabroBcjL7BN29WsN4XYUyU=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=EkMv8SpDXRieR47meuB4Pmvi+QdeQNBFZee5HjFZ3ArWQntn9N0erRQunqJdSqJvi sWEvzP0bt2zYGdgLulDtJnGTDFmO+bq2cs44K+vBbPcQPtB+L3P5716FURpwk3uWog iY1qkIKamcct2cAmHBueyqILVdAwSkbh4sZiVKQ3FdWyUa6EA4457jh+gnyephq5zL FV2F+JbxaRPq05y2ie/ZaUpQ4ppa7iO6cwu6roHi4+e/uNh80NdytCmjEBZS7NObpE AhphzsAuRTjykkvYNNIvkd08xfwKMJaebMNrPd2VfuSxJEDgIhGpVvhOy1UHTFHGsu BLBtITrf8+y6g== X-Cc: Andrew Lunn <andrew+netdev@lunn.ch>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@kernel.org>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, Felix Fietkau <nbd@nbd.name>, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list X-In-Reply-To: <20261104072940.52933-1-ansuelsmth@gmail.com>