Re: [PATCH net-next v4 08/10] net: stmmac: qcom-ethqos: add per-platform NOC clock voting

From: Lorenzo Bianconi

Date: Wed Nov 18 2026 - 04:40:48 EST


> Some SoCs gate the EMAC DMA path behind dedicated AXI clocks. Add
> per-platform clock-name lists and configure them as a single
> multi-clock OPP. The OPP core programs every clock rate and propagates
> the required power state.
>
> Select PM_OPP because DWMAC_QCOM_ETHQOS calls PM OPP APIs for
> compatibles that describe AXI OPP clocks.
>
> No functional change for existing compatibles. This will help us when
> we add support for Shikra.
>
> Signed-off-by: Mohd Ayaan Anwar <mohd.anwar@xxxxxxxxxxxxxxxx>

Hi Mohd,

just a nit inline. Fixing it:
Reviewed-by: Lorenzo Bianconi <lorenzo.bianconi@xxxxxxxxxxxxxxxx>

Regards,
Lorenzo

> ---
> drivers/net/ethernet/stmicro/stmmac/Kconfig | 1 +
> .../ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c | 103 +++++++++++++++++++++
> 2 files changed, 104 insertions(+)
>
> diff --git a/drivers/net/ethernet/stmicro/stmmac/Kconfig b/drivers/net/ethernet/stmicro/stmmac/Kconfig
> index c6559e749c0c..15639666e837 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/Kconfig
> +++ b/drivers/net/ethernet/stmicro/stmmac/Kconfig
> @@ -146,6 +146,7 @@ config DWMAC_QCOM_ETHQOS
> tristate "Qualcomm ETHQOS support"
> default ARCH_QCOM
> depends on OF && (ARCH_QCOM || COMPILE_TEST)
> + select PM_OPP
> help
> Support for the Qualcomm ETHQOS core.
>
> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c
> index bc443793539b..15385750b3e6 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c
> @@ -6,6 +6,7 @@
> #include <linux/of_net.h>
> #include <linux/platform_device.h>
> #include <linux/pm_domain.h>
> +#include <linux/pm_opp.h>
> #include <linux/phy.h>
> #include <linux/phy/phy.h>
>
> @@ -102,6 +103,8 @@ struct ethqos_emac_driver_data {
> const char *link_clk_name;
> const struct dwmac4_addrs *dwmac4_addrs;
> bool needs_sgmii_loopback;
> + const char * const *noc_clk_names;
> + unsigned int num_noc_clks;
> /* Fixed PTP reference clock rate, used on SCMI platforms where
> * firmware does not implement the clock protocol allowing linux to
> * query it.
> @@ -119,6 +122,8 @@ struct qcom_ethqos {
> phy_interface_t phy_mode;
> struct dev_pm_domain_list *pds;
> const struct ethqos_emac_driver_data *data;
> + struct clk_bulk_data *noc_clks;
> + unsigned int num_noc_clks;
> };
>
> static u32 rgmii_readl(struct qcom_ethqos *ethqos, unsigned int offset)
> @@ -725,18 +730,61 @@ static int ethqos_mac_finish_serdes(struct net_device *ndev, void *priv,
> return ret;
> }
>
> +static int qcom_ethqos_set_opp(struct qcom_ethqos *ethqos)

is it clearer to have an utility routine to set a specific freq and then call it
with freq = ULONG_MAX? Something like:

static in t qcom_ethqos_set_opp(struct qcom_ethqos *ethqos, unsigned long *freq)
{
....
}

> +{
> + struct device *dev = &ethqos->pdev->dev;
> + unsigned long freq = ULONG_MAX;
> + struct dev_pm_opp *opp;
> + int ret;
> +
> + opp = dev_pm_opp_find_freq_floor_indexed(dev, &freq, 0);
> + if (IS_ERR(opp)) {
> + ret = PTR_ERR(opp);
> + dev_err(dev, "Failed to find AXI NOC OPP: %d\n", ret);
> + return ret;
> + }
> +
> + ret = dev_pm_opp_set_opp(dev, opp);
> + dev_pm_opp_put(opp);
> +
> + return ret;
> +}
> +
> static int ethqos_clks_config(void *priv, bool enabled)
> {
> struct qcom_ethqos *ethqos = priv;
> int ret = 0;
>
> if (enabled) {
> + if (ethqos->num_noc_clks) {
> + ret = qcom_ethqos_set_opp(ethqos);
> + if (ret) {
> + dev_err(&ethqos->pdev->dev,
> + "NOC OPP set failed: %d\n", ret);
> + return ret;
> + }
> + }
> +
> ret = clk_prepare_enable(ethqos->link_clk);
> if (ret) {
> dev_err(&ethqos->pdev->dev, "link_clk enable failed\n");
> + if (ethqos->num_noc_clks)
> + dev_pm_opp_set_rate(&ethqos->pdev->dev, 0);
> return ret;
> }
>
> + if (ethqos->num_noc_clks) {
> + ret = clk_bulk_prepare_enable(ethqos->num_noc_clks,
> + ethqos->noc_clks);
> + if (ret) {
> + dev_err(&ethqos->pdev->dev,
> + "NOC clocks enable failed: %d\n", ret);
> + clk_disable_unprepare(ethqos->link_clk);
> + dev_pm_opp_set_rate(&ethqos->pdev->dev, 0);
> + return ret;
> + }
> + }
> +
> /* Enable functional clock to prevent DMA reset to timeout due
> * to lacking PHY clock after the hardware block has been power
> * cycled. The actual configuration will be adjusted once
> @@ -745,7 +793,12 @@ static int ethqos_clks_config(void *priv, bool enabled)
> qcom_ethqos_set_sgmii_loopback(ethqos, true);
> ethqos_set_func_clk_en(ethqos);
> } else {
> + if (ethqos->num_noc_clks)
> + clk_bulk_disable_unprepare(ethqos->num_noc_clks,
> + ethqos->noc_clks);
> clk_disable_unprepare(ethqos->link_clk);
> + if (ethqos->num_noc_clks)
> + dev_pm_opp_set_rate(&ethqos->pdev->dev, 0);
> }
>
> return ret;
> @@ -773,6 +826,52 @@ static void ethqos_ptp_clk_freq_config(struct stmmac_priv *priv)
> netdev_dbg(priv->dev, "PTP rate %lu\n", plat_dat->clk_ptp_rate);
> }
>
> +static void qcom_ethqos_noc_opp_cleanup(void *dev)
> +{
> + dev_pm_opp_set_rate(dev, 0);
> +}
> +
> +/* Some SoCs gate NOC access behind dedicated clocks. Acquire them here
> + * and set up an OPP table to vote for the required rate and power.
> + */
> +static int qcom_ethqos_init_noc_clks(struct qcom_ethqos *ethqos,
> + const struct ethqos_emac_driver_data *data)
> +{
> + struct dev_pm_opp_config config = {
> + .clk_names = data->noc_clk_names,
> + .config_clks = dev_pm_opp_config_clks_simple,
> + };
> + struct device *dev = &ethqos->pdev->dev;
> + unsigned int i;
> + int ret;
> +
> + if (!data->num_noc_clks)
> + return 0;
> +
> + ethqos->noc_clks = devm_kcalloc(dev, data->num_noc_clks,
> + sizeof(*ethqos->noc_clks), GFP_KERNEL);
> + if (!ethqos->noc_clks)
> + return -ENOMEM;
> +
> + for (i = 0; i < data->num_noc_clks; i++)
> + ethqos->noc_clks[i].id = data->noc_clk_names[i];
> + ethqos->num_noc_clks = data->num_noc_clks;
> +
> + ret = devm_clk_bulk_get(dev, ethqos->num_noc_clks, ethqos->noc_clks);
> + if (ret)
> + return dev_err_probe(dev, ret, "Failed to get NOC clocks\n");
> +
> + ret = devm_pm_opp_set_config(dev, &config);
> + if (ret)
> + return dev_err_probe(dev, ret, "Failed to configure OPP clocks\n");
> +
> + ret = devm_pm_opp_of_add_table(dev);
> + if (ret)
> + return dev_err_probe(dev, ret, "Failed to add OPP table\n");
> +
> + return devm_add_action_or_reset(dev, qcom_ethqos_noc_opp_cleanup, dev);
> +}
> +
> static int ethqos_hlos_setup(struct qcom_ethqos *ethqos,
> struct plat_stmmacenet_data *plat_dat)
> {
> @@ -780,6 +879,10 @@ static int ethqos_hlos_setup(struct qcom_ethqos *ethqos,
> struct device *dev = &pdev->dev;
> int ret;
>
> + ret = qcom_ethqos_init_noc_clks(ethqos, ethqos->data);
> + if (ret)
> + return ret;
> +
> ethqos->rgmii_base = devm_platform_ioremap_resource_byname(pdev, "rgmii");
> if (IS_ERR(ethqos->rgmii_base))
> return dev_err_probe(dev, PTR_ERR(ethqos->rgmii_base),
>
> --
> 2.34.1
>

Attachment: signature.asc
Description: PGP signature