From nobody Tue Feb 10 03:38:54 2026 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4B575320391 for ; Fri, 7 Nov 2025 20:13:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762546384; cv=none; b=FdAiFQ7vY+NLCdNnT2zi61kEmtLGIUbRiuh8tobtvmIG+t8W3oUDT5mFQcyGTRLEi9SodupcEHLbEfNsAA0xV4m9bLMctN+BT+8dDguVYMQbEt3U5wDgjaJGGAaVS1T9aOj0nF5WqXeqTJhYqGJTa1R/1R3Q3aM36GsW32miBIE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762546384; c=relaxed/simple; bh=OJO2xSgxar2IxgfmRA7vKrNBBYE2vrWHFsE1Ua95Rbw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jo6DFolzSj3iej/8mcBkaXHKheArtc5Nbhzy4aosmGSlR7Su8f7XuoZvNTJq1UC+hUHc0rwoMFafhBelpA++Z/WHPuQp94T8ezgpZ+KWlZO9WY+GqOfKQ0QiLFHK2OYqT0pgquURdgQRLzk8PknG6cDglBslY+Is02wFURE+VVE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=l5yxZYMW; arc=none smtp.client-ip=209.85.210.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="l5yxZYMW" Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-7afd7789ccdso1165693b3a.2 for ; Fri, 07 Nov 2025 12:13:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762546381; x=1763151181; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7WSv8Aw/7fkJYwtWG+mu3XdUcZ3be7F0tZpqyDku934=; b=l5yxZYMWjOJ7021+gKorLrYXTsSmD9ZQQtHwPLMddB5DkCXsXy6m8ekWZ/Axyq7iN/ XBikO4aXvLtCinLi46T2fPE6g6pK1cmdqkpLgvnLMJ93TAIKm4w/RjtqUoJZwPizbGvO hLLpdWZ0989s9ZMsb32DpyVK82FF0i2Enn3piD4ZSjyR+W935uOjMv3eTJxy+UqpFZlh 1C5gfNOm35qzYgkxXIgtkPx73MHBhcH9H2rFUxYsb/zafv3r3+9CQRBEkXmGEYvvqbvh fYW4Jn5IEax2NqNisa+2bq9XK0VX9GWE3yclot106Q5pGDY2gJOIopwNm2IQf93X6Ujb 038A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762546381; x=1763151181; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=7WSv8Aw/7fkJYwtWG+mu3XdUcZ3be7F0tZpqyDku934=; b=EAb78FzHrEjsGIG4W2smvyeB9enDanZgLcDZa2IOf7rA3mQghoZZ23hXyafeBzS0Fh p1bNv4ZjxjalFHALBxmhl5Fy7Iw4mbqjsH0J50hakjD3Q0bT/rbadMK2I5foc79YatIe nsqjI3gkmEbtijvDn5fwgLsmxw8v8ndwgqUP8UCRJJ8SlSwSVP1z5b33aYLTBIzzFJ9I i1WhZoiUg3AhPz7fNMx6ACpUX6lUJcuRay+RG5oaDT0qv2HMpwX9ghpBmonPv385bcdz F8kByH5uUPKwiD5tGXWUr45w/MLUBYZ8m+6U3GHDdR2tbtrAXvSVrHBW0a3kqoKNOclU OgCQ== X-Forwarded-Encrypted: i=1; AJvYcCU9MTYaNlWNQr5MF7dUkzSSShFaoZt3DO8RJnRN3m5H3eJQyRL0B+q8j7p7XiWZ1lDt6uLBRxq2dJQP+C4=@vger.kernel.org X-Gm-Message-State: AOJu0Yz/eR1QheK4FT4Vm2EsCg6NNIyqHyoKRY+WiH4X3JnKJGFoXk1c a/guOZRK0UDA818mZJ620+OkVY/wqpPxJNQTJBY6rDQxWNgonNw5/VaL X-Gm-Gg: ASbGncsy1SsKKdmE6WVbuncVGz0giurjkx3zPJKPHLxY0L5rRP02MnL6Bb1JJPF7SBG v8yiM5ADTSw9neS7WZKG9wKuZH52RZ6Bo+OT6PgZDth3INFWk3sRvIg8qPInx0L+W6N7kodisOc LjmtL9+nJJ0GGdyB43oLgTqGfk4ohIBjoI2RXR6BNHifw0fCUuSG7Fh+bHWUoBGn5YchkkzP7b5 tE/Y3iy5HNSREbkcLLr+77Tjwocm+dtxXnbojKiYRrV40hEXOCqJHak6Kd8NziDMyxqfnxeJXV4 xsqcBH+Ct9LiYUWZnqw9wUjYLE+I7LyA3oCG9GlNxuDFngJlu12iowDG6cMXAaz8G9EfeqTuz+N /1cmOqXwqGq4acgTSxLCLqf6xHQItIQ3XJ1uzSXn27MdRUAxCibrnVVIFsxY4R1B+u/83oBLfzr Cmq11SGp/hqNUwa2ehC20cxg== X-Google-Smtp-Source: AGHT+IE+5yFYqM5mDxRsnnBXUa+vUiRM7ZVmLo9HA3291G0opu0viMVqZfKTydYEwq5VYS1zEOjqKA== X-Received: by 2002:a05:6a21:3298:b0:342:15d3:eed8 with SMTP id adf61e73a8af0-353a426f0a6mr417893637.58.1762546381442; Fri, 07 Nov 2025 12:13:01 -0800 (PST) Received: from iku.. ([2401:4900:1c07:5fe8:9724:b1da:3d06:ab48]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7b0cc17784bsm3828553b3a.47.2025.11.07.12.12.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Nov 2025 12:13:00 -0800 (PST) From: Prabhakar X-Google-Original-From: Prabhakar To: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Horatiu Vultur , Geert Uytterhoeven , Vladimir Oltean , Vadim Fedorenko , Maxime Chevallier Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Prabhakar , Biju Das , Fabrizio Castro , Lad Prabhakar Subject: [PATCH net-next v2 2/3] net: phy: mscc: Consolidate probe functions into a common helper Date: Fri, 7 Nov 2025 20:12:31 +0000 Message-ID: <20251107201232.282152-3-prabhakar.mahadev-lad.rj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251107201232.282152-1-prabhakar.mahadev-lad.rj@bp.renesas.com> References: <20251107201232.282152-1-prabhakar.mahadev-lad.rj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Lad Prabhakar Unify the probe implementations of the VSC85xx PHY family into a single vsc85xx_probe_common() helper. The existing probe functions for the vsc85xx, vsc8514, vsc8574, and vsc8584 variants contained almost identical initialization logic, differing only in configuration parameters such as the number of LEDs, supported LED modes, hardware statistics, and PTP support. Introduce a vsc85xx_probe_config structure to describe the per-variant parameters, and move all common setup code into the shared helper. Each variant's probe function now defines a constant configuration instance and calls vsc85xx_probe_common(). Also mark the default LED mode array parameter as const to match its usage. Signed-off-by: Lad Prabhakar --- v1->v2: - New patch --- drivers/net/phy/mscc/mscc_main.c | 205 ++++++++++++++++--------------- 1 file changed, 109 insertions(+), 96 deletions(-) diff --git a/drivers/net/phy/mscc/mscc_main.c b/drivers/net/phy/mscc/mscc_m= ain.c index 032050ec0bc9..788344b7eb38 100644 --- a/drivers/net/phy/mscc/mscc_main.c +++ b/drivers/net/phy/mscc/mscc_main.c @@ -22,6 +22,24 @@ #include "mscc_serdes.h" #include "mscc.h" =20 +struct vsc85xx_probe_config { + const struct vsc85xx_hw_stat *hw_stats; + u8 nleds; + u16 supp_led_modes; + size_t nstats; + bool use_package; + size_t shared_size; + bool has_ptp; + bool check_rate_magic; +}; + +static const u32 vsc85xx_default_led_modes_4[] =3D { + VSC8531_LINK_1000_ACTIVITY, + VSC8531_LINK_100_ACTIVITY, + VSC8531_LINK_ACTIVITY, + VSC8531_DUPLEX_COLLISION +}; + static const struct vsc85xx_hw_stat vsc85xx_hw_stats[] =3D { { .string =3D "phy_receive_errors", @@ -436,7 +454,7 @@ static int vsc85xx_dt_led_mode_get(struct phy_device *p= hydev, #endif /* CONFIG_OF_MDIO */ =20 static int vsc85xx_dt_led_modes_get(struct phy_device *phydev, - u32 *default_mode) + const u32 *default_mode) { struct vsc8531_private *priv =3D phydev->priv; char led_dt_prop[28]; @@ -2211,41 +2229,19 @@ static int vsc85xx_config_inband(struct phy_device = *phydev, unsigned int modes) reg_val); } =20 -static int vsc8514_probe(struct phy_device *phydev) +static int vsc85xx_probe_common(struct phy_device *phydev, + const struct vsc85xx_probe_config *cfg, + const u32 *default_led_mode) { struct vsc8531_private *vsc8531; - u32 default_mode[4] =3D {VSC8531_LINK_1000_ACTIVITY, - VSC8531_LINK_100_ACTIVITY, VSC8531_LINK_ACTIVITY, - VSC8531_DUPLEX_COLLISION}; - - vsc8531 =3D devm_kzalloc(&phydev->mdio.dev, sizeof(*vsc8531), GFP_KERNEL); - if (!vsc8531) - return -ENOMEM; - - phydev->priv =3D vsc8531; - - vsc8584_get_base_addr(phydev); - devm_phy_package_join(&phydev->mdio.dev, phydev, - vsc8531->base_addr, 0); - - vsc8531->nleds =3D 4; - vsc8531->supp_led_modes =3D VSC85XX_SUPP_LED_MODES; - vsc8531->hw_stats =3D vsc85xx_hw_stats; - vsc8531->nstats =3D ARRAY_SIZE(vsc85xx_hw_stats); - vsc8531->stats =3D devm_kcalloc(&phydev->mdio.dev, vsc8531->nstats, - sizeof(u64), GFP_KERNEL); - if (!vsc8531->stats) - return -ENOMEM; - - return vsc85xx_dt_led_modes_get(phydev, default_mode); -} + int ret; =20 -static int vsc8574_probe(struct phy_device *phydev) -{ - struct vsc8531_private *vsc8531; - u32 default_mode[4] =3D {VSC8531_LINK_1000_ACTIVITY, - VSC8531_LINK_100_ACTIVITY, VSC8531_LINK_ACTIVITY, - VSC8531_DUPLEX_COLLISION}; + /* Check rate magic if needed (only for non-package PHYs) */ + if (cfg->check_rate_magic) { + ret =3D vsc85xx_edge_rate_magic_get(phydev); + if (ret < 0) + return ret; + } =20 vsc8531 =3D devm_kzalloc(&phydev->mdio.dev, sizeof(*vsc8531), GFP_KERNEL); if (!vsc8531) @@ -2253,90 +2249,107 @@ static int vsc8574_probe(struct phy_device *phydev) =20 phydev->priv =3D vsc8531; =20 - vsc8584_get_base_addr(phydev); - devm_phy_package_join(&phydev->mdio.dev, phydev, - vsc8531->base_addr, 0); - - vsc8531->nleds =3D 4; - vsc8531->supp_led_modes =3D VSC8584_SUPP_LED_MODES; - vsc8531->hw_stats =3D vsc8584_hw_stats; - vsc8531->nstats =3D ARRAY_SIZE(vsc8584_hw_stats); - vsc8531->stats =3D devm_kcalloc(&phydev->mdio.dev, vsc8531->nstats, - sizeof(u64), GFP_KERNEL); - if (!vsc8531->stats) - return -ENOMEM; - - return vsc85xx_dt_led_modes_get(phydev, default_mode); -} - -static int vsc8584_probe(struct phy_device *phydev) -{ - struct vsc8531_private *vsc8531; - u32 default_mode[4] =3D {VSC8531_LINK_1000_ACTIVITY, - VSC8531_LINK_100_ACTIVITY, VSC8531_LINK_ACTIVITY, - VSC8531_DUPLEX_COLLISION}; - int ret; - - vsc8531 =3D devm_kzalloc(&phydev->mdio.dev, sizeof(*vsc8531), GFP_KERNEL); - if (!vsc8531) - return -ENOMEM; + /* Store rate magic if it was checked */ + if (cfg->check_rate_magic) + vsc8531->rate_magic =3D ret; =20 - phydev->priv =3D vsc8531; + /* Set up package if needed */ + if (cfg->use_package) { + vsc8584_get_base_addr(phydev); + devm_phy_package_join(&phydev->mdio.dev, phydev, + vsc8531->base_addr, cfg->shared_size); + } =20 - vsc8584_get_base_addr(phydev); - devm_phy_package_join(&phydev->mdio.dev, phydev, vsc8531->base_addr, - sizeof(struct vsc85xx_shared_private)); + /* Configure LED settings */ + vsc8531->nleds =3D cfg->nleds; + vsc8531->supp_led_modes =3D cfg->supp_led_modes; =20 - vsc8531->nleds =3D 4; - vsc8531->supp_led_modes =3D VSC8584_SUPP_LED_MODES; - vsc8531->hw_stats =3D vsc8584_hw_stats; - vsc8531->nstats =3D ARRAY_SIZE(vsc8584_hw_stats); + /* Configure hardware stats */ + vsc8531->hw_stats =3D cfg->hw_stats; + vsc8531->nstats =3D cfg->nstats; vsc8531->stats =3D devm_kcalloc(&phydev->mdio.dev, vsc8531->nstats, sizeof(u64), GFP_KERNEL); if (!vsc8531->stats) return -ENOMEM; =20 - if (phy_package_probe_once(phydev)) { - ret =3D vsc8584_ptp_probe_once(phydev); + /* PTP setup for VSC8584 */ + if (cfg->has_ptp) { + if (phy_package_probe_once(phydev)) { + ret =3D vsc8584_ptp_probe_once(phydev); + if (ret) + return ret; + } + + ret =3D vsc8584_ptp_probe(phydev); if (ret) return ret; } =20 - ret =3D vsc8584_ptp_probe(phydev); - if (ret) - return ret; + /* Parse LED modes from device tree */ + return vsc85xx_dt_led_modes_get(phydev, default_led_mode); +} =20 - return vsc85xx_dt_led_modes_get(phydev, default_mode); +static int vsc8514_probe(struct phy_device *phydev) +{ + static const struct vsc85xx_probe_config vsc8514_cfg =3D { + .nleds =3D 4, + .supp_led_modes =3D VSC85XX_SUPP_LED_MODES, + .hw_stats =3D vsc85xx_hw_stats, + .nstats =3D ARRAY_SIZE(vsc85xx_hw_stats), + .use_package =3D true, + .shared_size =3D 0, + .has_ptp =3D false, + .check_rate_magic =3D false, + }; + + return vsc85xx_probe_common(phydev, &vsc8514_cfg, vsc85xx_default_led_mod= es_4); } =20 -static int vsc85xx_probe(struct phy_device *phydev) +static int vsc8574_probe(struct phy_device *phydev) { - struct vsc8531_private *vsc8531; - int rate_magic; - u32 default_mode[2] =3D {VSC8531_LINK_1000_ACTIVITY, - VSC8531_LINK_100_ACTIVITY}; + static const struct vsc85xx_probe_config vsc8574_cfg =3D { + .nleds =3D 4, + .supp_led_modes =3D VSC8584_SUPP_LED_MODES, + .hw_stats =3D vsc8584_hw_stats, + .nstats =3D ARRAY_SIZE(vsc8584_hw_stats), + .use_package =3D true, + .shared_size =3D 0, + .has_ptp =3D false, + .check_rate_magic =3D false, + }; =20 - rate_magic =3D vsc85xx_edge_rate_magic_get(phydev); - if (rate_magic < 0) - return rate_magic; + return vsc85xx_probe_common(phydev, &vsc8574_cfg, vsc85xx_default_led_mod= es_4); +} =20 - vsc8531 =3D devm_kzalloc(&phydev->mdio.dev, sizeof(*vsc8531), GFP_KERNEL); - if (!vsc8531) - return -ENOMEM; +static int vsc8584_probe(struct phy_device *phydev) +{ + static const struct vsc85xx_probe_config vsc8584_cfg =3D { + .nleds =3D 4, + .supp_led_modes =3D VSC8584_SUPP_LED_MODES, + .hw_stats =3D vsc8584_hw_stats, + .nstats =3D ARRAY_SIZE(vsc8584_hw_stats), + .use_package =3D true, + .shared_size =3D sizeof(struct vsc85xx_shared_private), + .has_ptp =3D true, + .check_rate_magic =3D false, + }; =20 - phydev->priv =3D vsc8531; + return vsc85xx_probe_common(phydev, &vsc8584_cfg, vsc85xx_default_led_mod= es_4); +} =20 - vsc8531->rate_magic =3D rate_magic; - vsc8531->nleds =3D 2; - vsc8531->supp_led_modes =3D VSC85XX_SUPP_LED_MODES; - vsc8531->hw_stats =3D vsc85xx_hw_stats; - vsc8531->nstats =3D ARRAY_SIZE(vsc85xx_hw_stats); - vsc8531->stats =3D devm_kcalloc(&phydev->mdio.dev, vsc8531->nstats, - sizeof(u64), GFP_KERNEL); - if (!vsc8531->stats) - return -ENOMEM; +static int vsc85xx_probe(struct phy_device *phydev) +{ + static const struct vsc85xx_probe_config vsc85xx_cfg =3D { + .nleds =3D 2, + .supp_led_modes =3D VSC85XX_SUPP_LED_MODES, + .hw_stats =3D vsc85xx_hw_stats, + .nstats =3D ARRAY_SIZE(vsc85xx_hw_stats), + .use_package =3D false, + .has_ptp =3D false, + .check_rate_magic =3D true, + }; =20 - return vsc85xx_dt_led_modes_get(phydev, default_mode); + return vsc85xx_probe_common(phydev, &vsc85xx_cfg, vsc85xx_default_led_mod= es_4); } =20 static void vsc85xx_remove(struct phy_device *phydev) --=20 2.43.0