All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next v3 0/3] fix forced link mode for KSZ886X switches
@ 2023-10-19 11:14 Oleksij Rempel
  2023-10-19 11:14 ` [PATCH net-next v3 1/2] net: dsa: microchip: ksz8: Enable MIIM PHY Control reg access Oleksij Rempel
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Oleksij Rempel @ 2023-10-19 11:14 UTC (permalink / raw)
  To: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Florian Fainelli,
	Vladimir Oltean, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Heiner Kallweit
  Cc: Oleksij Rempel, kernel, linux-kernel, Russell King, netdev,
	Alexander Stein

changes v3:
- squash patch 1 and 2
- use genphy_config_aneg() instead of genphy_setup_forced()

changes v2:
- address kernel test robot warning
- change comment explaining clearing of KSZ886X_CTRL_FORCE_LINK bit
- s/PHY we create/PHY will create/

Oleksij Rempel (2):
  net: dsa: microchip: ksz8: Enable MIIM PHY Control reg access
  net: phy: micrel: Fix forced link mode for KSZ886X switches

 drivers/net/dsa/microchip/ksz8795.c | 86 ++++++++++++++++++++++++++++-
 drivers/net/phy/micrel.c            | 22 ++++++++
 include/linux/micrel_phy.h          |  4 ++
 3 files changed, 109 insertions(+), 3 deletions(-)

-- 
2.39.2


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH net-next v3 1/2] net: dsa: microchip: ksz8: Enable MIIM PHY Control reg access
  2023-10-19 11:14 [PATCH net-next v3 0/3] fix forced link mode for KSZ886X switches Oleksij Rempel
@ 2023-10-19 11:14 ` Oleksij Rempel
  2023-10-19 16:31   ` Vladimir Oltean
  2023-10-19 11:14 ` [PATCH net-next v3 2/2] net: phy: micrel: Fix forced link mode for KSZ886X switches Oleksij Rempel
  2023-10-20 23:55 ` [PATCH net-next v3 0/3] fix " Jakub Kicinski
  2 siblings, 1 reply; 7+ messages in thread
From: Oleksij Rempel @ 2023-10-19 11:14 UTC (permalink / raw)
  To: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Florian Fainelli,
	Vladimir Oltean, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Heiner Kallweit
  Cc: Oleksij Rempel, kernel test robot, kernel, linux-kernel,
	Russell King, netdev, Alexander Stein

Provide access to MIIM PHY Control register (Reg. 31) through
ksz8_r_phy_ctrl() and ksz8_w_phy_ctrl() functions. Necessary for
upcoming micrel.c patch to address forced link mode configuration.

Closes: https://lore.kernel.org/oe-kbuild-all/202310112224.iYgvjBUy-lkp@intel.com/
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/dsa/microchip/ksz8795.c | 86 ++++++++++++++++++++++++++++-
 include/linux/micrel_phy.h          |  4 ++
 2 files changed, 87 insertions(+), 3 deletions(-)

diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c
index 91aba470fb2f..4bf4d67557dc 100644
--- a/drivers/net/dsa/microchip/ksz8795.c
+++ b/drivers/net/dsa/microchip/ksz8795.c
@@ -632,6 +632,50 @@ static void ksz8_w_vlan_table(struct ksz_device *dev, u16 vid, u16 vlan)
 	ksz8_w_table(dev, TABLE_VLAN, addr, buf);
 }
 
+/**
+ * ksz8_r_phy_ctrl - Translates and reads from the SMI interface to a MIIM PHY
+ *		     Control register (Reg. 31).
+ * @dev: The KSZ device instance.
+ * @port: The port number to be read.
+ * @val: The value read from the SMI interface.
+ *
+ * This function reads the SMI interface and translates the hardware register
+ * bit values into their corresponding control settings for a MIIM PHY Control
+ * register.
+ *
+ * Return: 0 on success, error code on failure.
+ */
+static int ksz8_r_phy_ctrl(struct ksz_device *dev, int port, u16 *val)
+{
+	const u16 *regs = dev->info->regs;
+	u8 reg_val;
+	int ret;
+
+	*val = 0;
+
+	ret = ksz_pread8(dev, port, regs[P_LINK_STATUS], &reg_val);
+	if (ret < 0)
+		return ret;
+
+	if (reg_val & PORT_MDIX_STATUS)
+		*val |= KSZ886X_CTRL_MDIX_STAT;
+
+	ret = ksz_pread8(dev, port, REG_PORT_LINK_MD_CTRL, &reg_val);
+	if (ret < 0)
+		return ret;
+
+	if (reg_val & PORT_FORCE_LINK)
+		*val |= KSZ886X_CTRL_FORCE_LINK;
+
+	if (reg_val & PORT_POWER_SAVING)
+		*val |= KSZ886X_CTRL_PWRSAVE;
+
+	if (reg_val & PORT_PHY_REMOTE_LOOPBACK)
+		*val |= KSZ886X_CTRL_REMOTE_LOOPBACK;
+
+	return 0;
+}
+
 int ksz8_r_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 *val)
 {
 	u8 restart, speed, ctrl, link;
@@ -769,12 +813,10 @@ int ksz8_r_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 *val)
 				FIELD_GET(PORT_CABLE_FAULT_COUNTER_L, val2));
 		break;
 	case PHY_REG_PHY_CTRL:
-		ret = ksz_pread8(dev, p, regs[P_LINK_STATUS], &link);
+		ret = ksz8_r_phy_ctrl(dev, p, &data);
 		if (ret)
 			return ret;
 
-		if (link & PORT_MDIX_STATUS)
-			data |= KSZ886X_CTRL_MDIX_STAT;
 		break;
 	default:
 		processed = false;
@@ -786,6 +828,38 @@ int ksz8_r_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 *val)
 	return 0;
 }
 
+/**
+ * ksz8_w_phy_ctrl - Translates and writes to the SMI interface from a MIIM PHY
+ *		     Control register (Reg. 31).
+ * @dev: The KSZ device instance.
+ * @port: The port number to be configured.
+ * @val: The register value to be written.
+ *
+ * This function translates control settings from a MIIM PHY Control register
+ * into their corresponding hardware register bit values for the SMI
+ * interface.
+ *
+ * Return: 0 on success, error code on failure.
+ */
+static int ksz8_w_phy_ctrl(struct ksz_device *dev, int port, u16 val)
+{
+	u8 reg_val = 0;
+	int ret;
+
+	if (val & KSZ886X_CTRL_FORCE_LINK)
+		reg_val |= PORT_FORCE_LINK;
+
+	if (val & KSZ886X_CTRL_PWRSAVE)
+		reg_val |= PORT_POWER_SAVING;
+
+	if (val & KSZ886X_CTRL_REMOTE_LOOPBACK)
+		reg_val |= PORT_PHY_REMOTE_LOOPBACK;
+
+	ret = ksz_prmw8(dev, port, REG_PORT_LINK_MD_CTRL, PORT_FORCE_LINK |
+			PORT_POWER_SAVING | PORT_PHY_REMOTE_LOOPBACK, reg_val);
+	return ret;
+}
+
 int ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val)
 {
 	u8 restart, speed, ctrl, data;
@@ -926,6 +1000,12 @@ int ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val)
 		if (val & PHY_START_CABLE_DIAG)
 			ksz_port_cfg(dev, p, REG_PORT_LINK_MD_CTRL, PORT_START_CABLE_DIAG, true);
 		break;
+
+	case PHY_REG_PHY_CTRL:
+		ret = ksz8_w_phy_ctrl(dev, p, val);
+		if (ret)
+			return ret;
+		break;
 	default:
 		break;
 	}
diff --git a/include/linux/micrel_phy.h b/include/linux/micrel_phy.h
index 4e27ca7c49de..591bf5b5e8dc 100644
--- a/include/linux/micrel_phy.h
+++ b/include/linux/micrel_phy.h
@@ -64,6 +64,10 @@
 #define KSZ886X_BMCR_DISABLE_TRANSMIT		BIT(1)
 #define KSZ886X_BMCR_DISABLE_LED		BIT(0)
 
+/* PHY Special Control/Status Register (Reg 31) */
 #define KSZ886X_CTRL_MDIX_STAT			BIT(4)
+#define KSZ886X_CTRL_FORCE_LINK			BIT(3)
+#define KSZ886X_CTRL_PWRSAVE			BIT(2)
+#define KSZ886X_CTRL_REMOTE_LOOPBACK		BIT(1)
 
 #endif /* _MICREL_PHY_H */
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net-next v3 2/2] net: phy: micrel: Fix forced link mode for KSZ886X switches
  2023-10-19 11:14 [PATCH net-next v3 0/3] fix forced link mode for KSZ886X switches Oleksij Rempel
  2023-10-19 11:14 ` [PATCH net-next v3 1/2] net: dsa: microchip: ksz8: Enable MIIM PHY Control reg access Oleksij Rempel
@ 2023-10-19 11:14 ` Oleksij Rempel
  2023-10-19 16:32   ` Vladimir Oltean
  2023-10-20  8:01   ` Divya.Koppera
  2023-10-20 23:55 ` [PATCH net-next v3 0/3] fix " Jakub Kicinski
  2 siblings, 2 replies; 7+ messages in thread
From: Oleksij Rempel @ 2023-10-19 11:14 UTC (permalink / raw)
  To: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Florian Fainelli,
	Vladimir Oltean, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Heiner Kallweit
  Cc: Oleksij Rempel, kernel, linux-kernel, Russell King, netdev,
	Alexander Stein

Address a link speed detection issue in KSZ886X PHY driver when in
forced link mode. Previously, link partners like "ASIX AX88772B"
with KSZ8873 could fall back to 10Mbit instead of configured 100Mbit.

The issue arises as KSZ886X PHY continues sending Fast Link Pulses (FLPs)
even with autonegotiation off, misleading link partners in autoneg mode,
leading to incorrect link speed detection.

Now, when autonegotiation is disabled, the driver sets the link state
forcefully using KSZ886X_CTRL_FORCE_LINK bit. This action, beyond just
disabling autonegotiation, makes the PHY state more reliably detected by
link partners using parallel detection, thus fixing the link speed
misconfiguration.

With autonegotiation enabled, link state is not forced, allowing proper
autonegotiation process participation.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/phy/micrel.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c
index 927d3d54658e..08e3915001c3 100644
--- a/drivers/net/phy/micrel.c
+++ b/drivers/net/phy/micrel.c
@@ -1733,6 +1733,28 @@ static int ksz886x_config_aneg(struct phy_device *phydev)
 	if (ret)
 		return ret;
 
+	if (phydev->autoneg != AUTONEG_ENABLE) {
+		/* When autonegotation is disabled, we need to manually force
+		 * the link state. If we don't do this, the PHY will keep
+		 * sending Fast Link Pulses (FLPs) which are part of the
+		 * autonegotiation process. This is not desired when
+		 * autonegotiation is off.
+		 */
+		ret = phy_set_bits(phydev, MII_KSZPHY_CTRL,
+				   KSZ886X_CTRL_FORCE_LINK);
+		if (ret)
+			return ret;
+	} else {
+		/* If we had previously forced the link state, we need to
+		 * clear KSZ886X_CTRL_FORCE_LINK bit now. Otherwise, the PHY
+		 * will not perform autonegotiation.
+		 */
+		ret = phy_clear_bits(phydev, MII_KSZPHY_CTRL,
+				     KSZ886X_CTRL_FORCE_LINK);
+		if (ret)
+			return ret;
+	}
+
 	/* The MDI-X configuration is automatically changed by the PHY after
 	 * switching from autoneg off to on. So, take MDI-X configuration under
 	 * own control and set it after autoneg configuration was done.
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next v3 1/2] net: dsa: microchip: ksz8: Enable MIIM PHY Control reg access
  2023-10-19 11:14 ` [PATCH net-next v3 1/2] net: dsa: microchip: ksz8: Enable MIIM PHY Control reg access Oleksij Rempel
@ 2023-10-19 16:31   ` Vladimir Oltean
  0 siblings, 0 replies; 7+ messages in thread
From: Vladimir Oltean @ 2023-10-19 16:31 UTC (permalink / raw)
  To: Oleksij Rempel
  Cc: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Florian Fainelli,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Heiner Kallweit, kernel test robot, kernel, linux-kernel,
	Russell King, netdev, Alexander Stein

On Thu, Oct 19, 2023 at 01:14:58PM +0200, Oleksij Rempel wrote:
> Provide access to MIIM PHY Control register (Reg. 31) through
> ksz8_r_phy_ctrl() and ksz8_w_phy_ctrl() functions. Necessary for
> upcoming micrel.c patch to address forced link mode configuration.
> 
> Closes: https://lore.kernel.org/oe-kbuild-all/202310112224.iYgvjBUy-lkp@intel.com/
> Reported-by: kernel test robot <lkp@intel.com>

These tags do not age well if you add them in response to a kbuild robot
notification on a previous, unmerged version of the same patch. They are
for when the patch gets accepted with issues.

> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> ---

Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next v3 2/2] net: phy: micrel: Fix forced link mode for KSZ886X switches
  2023-10-19 11:14 ` [PATCH net-next v3 2/2] net: phy: micrel: Fix forced link mode for KSZ886X switches Oleksij Rempel
@ 2023-10-19 16:32   ` Vladimir Oltean
  2023-10-20  8:01   ` Divya.Koppera
  1 sibling, 0 replies; 7+ messages in thread
From: Vladimir Oltean @ 2023-10-19 16:32 UTC (permalink / raw)
  To: Oleksij Rempel
  Cc: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Florian Fainelli,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Heiner Kallweit, kernel, linux-kernel, Russell King, netdev,
	Alexander Stein

On Thu, Oct 19, 2023 at 01:14:59PM +0200, Oleksij Rempel wrote:
> Address a link speed detection issue in KSZ886X PHY driver when in
> forced link mode. Previously, link partners like "ASIX AX88772B"
> with KSZ8873 could fall back to 10Mbit instead of configured 100Mbit.
> 
> The issue arises as KSZ886X PHY continues sending Fast Link Pulses (FLPs)
> even with autonegotiation off, misleading link partners in autoneg mode,
> leading to incorrect link speed detection.
> 
> Now, when autonegotiation is disabled, the driver sets the link state
> forcefully using KSZ886X_CTRL_FORCE_LINK bit. This action, beyond just
> disabling autonegotiation, makes the PHY state more reliably detected by
> link partners using parallel detection, thus fixing the link speed
> misconfiguration.
> 
> With autonegotiation enabled, link state is not forced, allowing proper
> autonegotiation process participation.
> 
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> ---

Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: [PATCH net-next v3 2/2] net: phy: micrel: Fix forced link mode for KSZ886X switches
  2023-10-19 11:14 ` [PATCH net-next v3 2/2] net: phy: micrel: Fix forced link mode for KSZ886X switches Oleksij Rempel
  2023-10-19 16:32   ` Vladimir Oltean
@ 2023-10-20  8:01   ` Divya.Koppera
  1 sibling, 0 replies; 7+ messages in thread
From: Divya.Koppera @ 2023-10-20  8:01 UTC (permalink / raw)
  To: o.rempel, Woojung.Huh, UNGLinuxDriver, andrew, f.fainelli,
	olteanv, davem, edumazet, kuba, pabeni, hkallweit1
  Cc: kernel, linux-kernel, linux, netdev, alexander.stein



> -----Original Message-----
> From: Oleksij Rempel <o.rempel@pengutronix.de>
> Sent: Thursday, October 19, 2023 4:45 PM
> To: Woojung Huh - C21699 <Woojung.Huh@microchip.com>;
> UNGLinuxDriver <UNGLinuxDriver@microchip.com>; Andrew Lunn
> <andrew@lunn.ch>; Florian Fainelli <f.fainelli@gmail.com>; Vladimir Oltean
> <olteanv@gmail.com>; David S. Miller <davem@davemloft.net>; Eric Dumazet
> <edumazet@google.com>; Jakub Kicinski <kuba@kernel.org>; Paolo Abeni
> <pabeni@redhat.com>; Heiner Kallweit <hkallweit1@gmail.com>
> Cc: Oleksij Rempel <o.rempel@pengutronix.de>; kernel@pengutronix.de;
> linux-kernel@vger.kernel.org; Russell King <linux@armlinux.org.uk>;
> netdev@vger.kernel.org; Alexander Stein <alexander.stein@ew.tq-group.com>
> Subject: [PATCH net-next v3 2/2] net: phy: micrel: Fix forced link mode for
> KSZ886X switches
> 
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the
> content is safe
> 
> Address a link speed detection issue in KSZ886X PHY driver when in forced link
> mode. Previously, link partners like "ASIX AX88772B"
> with KSZ8873 could fall back to 10Mbit instead of configured 100Mbit.
> 
> The issue arises as KSZ886X PHY continues sending Fast Link Pulses (FLPs)
> even with autonegotiation off, misleading link partners in autoneg mode,
> leading to incorrect link speed detection.
> 
> Now, when autonegotiation is disabled, the driver sets the link state forcefully
> using KSZ886X_CTRL_FORCE_LINK bit. This action, beyond just disabling
> autonegotiation, makes the PHY state more reliably detected by link partners
> using parallel detection, thus fixing the link speed misconfiguration.
> 
> With autonegotiation enabled, link state is not forced, allowing proper
> autonegotiation process participation.
> 
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> ---
>  drivers/net/phy/micrel.c | 22 ++++++++++++++++++++++
>  1 file changed, 22 insertions(+)
> 
> diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c index
> 927d3d54658e..08e3915001c3 100644
> --- a/drivers/net/phy/micrel.c
> +++ b/drivers/net/phy/micrel.c
> @@ -1733,6 +1733,28 @@ static int ksz886x_config_aneg(struct phy_device
> *phydev)
>         if (ret)
>                 return ret;
> 
> +       if (phydev->autoneg != AUTONEG_ENABLE) {
> +               /* When autonegotation is disabled, we need to manually force
> +                * the link state. If we don't do this, the PHY will keep
> +                * sending Fast Link Pulses (FLPs) which are part of the
> +                * autonegotiation process. This is not desired when
> +                * autonegotiation is off.
> +                */
> +               ret = phy_set_bits(phydev, MII_KSZPHY_CTRL,
> +                                  KSZ886X_CTRL_FORCE_LINK);
> +               if (ret)
> +                       return ret;
> +       } else {
> +               /* If we had previously forced the link state, we need to
> +                * clear KSZ886X_CTRL_FORCE_LINK bit now. Otherwise, the PHY
> +                * will not perform autonegotiation.
> +                */
> +               ret = phy_clear_bits(phydev, MII_KSZPHY_CTRL,
> +                                    KSZ886X_CTRL_FORCE_LINK);
> +               if (ret)
> +                       return ret;
> +       }
> +
>         /* The MDI-X configuration is automatically changed by the PHY after
>          * switching from autoneg off to on. So, take MDI-X configuration under
>          * own control and set it after autoneg configuration was done.
> --
> 2.39.2

Reviewed-by: Divya Koppera <divya.koppera@microchip.com>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next v3 0/3] fix forced link mode for KSZ886X switches
  2023-10-19 11:14 [PATCH net-next v3 0/3] fix forced link mode for KSZ886X switches Oleksij Rempel
  2023-10-19 11:14 ` [PATCH net-next v3 1/2] net: dsa: microchip: ksz8: Enable MIIM PHY Control reg access Oleksij Rempel
  2023-10-19 11:14 ` [PATCH net-next v3 2/2] net: phy: micrel: Fix forced link mode for KSZ886X switches Oleksij Rempel
@ 2023-10-20 23:55 ` Jakub Kicinski
  2 siblings, 0 replies; 7+ messages in thread
From: Jakub Kicinski @ 2023-10-20 23:55 UTC (permalink / raw)
  To: Oleksij Rempel
  Cc: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Florian Fainelli,
	Vladimir Oltean, David S. Miller, Eric Dumazet, Paolo Abeni,
	Heiner Kallweit, kernel, linux-kernel, Russell King, netdev,
	Alexander Stein

On Thu, 19 Oct 2023 13:14:57 +0200 Oleksij Rempel wrote:
> Oleksij Rempel (2):
>   net: dsa: microchip: ksz8: Enable MIIM PHY Control reg access
>   net: phy: micrel: Fix forced link mode for KSZ886X switches

Looks applied, thanks!

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-10-20 23:55 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-19 11:14 [PATCH net-next v3 0/3] fix forced link mode for KSZ886X switches Oleksij Rempel
2023-10-19 11:14 ` [PATCH net-next v3 1/2] net: dsa: microchip: ksz8: Enable MIIM PHY Control reg access Oleksij Rempel
2023-10-19 16:31   ` Vladimir Oltean
2023-10-19 11:14 ` [PATCH net-next v3 2/2] net: phy: micrel: Fix forced link mode for KSZ886X switches Oleksij Rempel
2023-10-19 16:32   ` Vladimir Oltean
2023-10-20  8:01   ` Divya.Koppera
2023-10-20 23:55 ` [PATCH net-next v3 0/3] fix " Jakub Kicinski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.