All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kai-Heng Feng <kai.heng.feng@canonical.com>
To: peppe.cavallaro@st.com, alexandre.torgue@foss.st.com,
	joabreu@synopsys.com
Cc: "Kai-Heng Feng" <kai.heng.feng@canonical.com>,
	"David S. Miller" <davem@davemloft.net>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Maxime Coquelin" <mcoquelin.stm32@gmail.com>,
	"Andrew Lunn" <andrew@lunn.ch>,
	"Heiner Kallweit" <hkallweit1@gmail.com>,
	"Russell King" <linux@armlinux.org.uk>,
	"Marek Behún" <kabel@kernel.org>,
	"Ivan Bornyakov" <i.bornyakov@metrotek.ru>,
	"Pali Rohár" <pali@kernel.org>,
	netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] stmmac: intel: Honor phy LED set by system firmware on a Dell hardware
Date: Fri, 14 Jan 2022 12:07:54 +0800	[thread overview]
Message-ID: <20220114040755.1314349-2-kai.heng.feng@canonical.com> (raw)
In-Reply-To: <20220114040755.1314349-1-kai.heng.feng@canonical.com>

BIOS on Dell Edge Gateway 3200 already makes its own phy LED setting, so
instead of setting another value, keep it untouched and restore the saved
value on system resume.

Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
---
 .../net/ethernet/stmicro/stmmac/dwmac-intel.c | 16 +++++
 drivers/net/ethernet/stmicro/stmmac/stmmac.h  |  2 +
 .../net/ethernet/stmicro/stmmac/stmmac_main.c |  4 ++
 drivers/net/phy/marvell.c                     | 58 ++++++++++++-------
 include/linux/marvell_phy.h                   |  1 +
 5 files changed, 61 insertions(+), 20 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c
index 8e8778cfbbadd..f8a2879e0264a 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c
@@ -857,6 +857,16 @@ static const struct dmi_system_id quark_pci_dmi[] = {
 	{}
 };
 
+static const struct dmi_system_id use_preset_led[] = {
+	{
+		.matches = {
+			DMI_MATCH(DMI_SYS_VENDOR, "Dell EMC"),
+			DMI_MATCH(DMI_PRODUCT_NAME, "Edge Gateway 3200"),
+		},
+	},
+	{}
+};
+
 static int quark_default_data(struct pci_dev *pdev,
 			      struct plat_stmmacenet_data *plat)
 {
@@ -989,6 +999,7 @@ static int intel_eth_pci_probe(struct pci_dev *pdev,
 	struct intel_priv_data *intel_priv;
 	struct plat_stmmacenet_data *plat;
 	struct stmmac_resources res;
+	struct stmmac_priv *priv;
 	int ret;
 
 	intel_priv = devm_kzalloc(&pdev->dev, sizeof(*intel_priv), GFP_KERNEL);
@@ -1075,6 +1086,11 @@ static int intel_eth_pci_probe(struct pci_dev *pdev,
 		goto err_dvr_probe;
 	}
 
+	if (dmi_check_system(use_preset_led)) {
+		priv = netdev_priv(dev_get_drvdata(&pdev->dev));
+		priv->use_preset_led = true;
+	}
+
 	return 0;
 
 err_dvr_probe:
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
index 40b5ed94cb54a..525701acbbdbb 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
@@ -319,6 +319,8 @@ struct stmmac_priv {
 	/* XDP BPF Program */
 	unsigned long *af_xdp_zc_qps;
 	struct bpf_prog *xdp_prog;
+
+	bool use_preset_led;
 };
 
 enum stmmac_state {
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 63ff2dad8c85f..155412656b8bf 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -49,6 +49,7 @@
 #include "dwmac1000.h"
 #include "dwxgmac2.h"
 #include "hwif.h"
+#include <linux/marvell_phy.h>
 
 /* As long as the interface is active, we keep the timestamping counter enabled
  * with fine resolution and binary rollover. This avoid non-monotonic behavior
@@ -1236,6 +1237,9 @@ static int stmmac_init_phy(struct net_device *dev)
 			return -ENODEV;
 		}
 
+		if (priv->use_preset_led)
+			phydev->dev_flags |= MARVELL_PHY_USE_PRESET_LED;
+
 		ret = phylink_connect_phy(priv->phylink, phydev);
 	}
 
diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c
index 739859c0dfb18..45be432188781 100644
--- a/drivers/net/phy/marvell.c
+++ b/drivers/net/phy/marvell.c
@@ -304,6 +304,7 @@ struct marvell_priv {
 	u32 last;
 	u32 step;
 	s8 pair;
+	u16 led_def_config;
 };
 
 static int marvell_read_page(struct phy_device *phydev)
@@ -748,32 +749,49 @@ static int m88e1510_config_aneg(struct phy_device *phydev)
 
 static void marvell_config_led(struct phy_device *phydev)
 {
-	u16 def_config;
+	struct marvell_priv *priv = phydev->priv;
 	int err;
 
-	switch (MARVELL_PHY_FAMILY_ID(phydev->phy_id)) {
-	/* Default PHY LED config: LED[0] .. Link, LED[1] .. Activity */
-	case MARVELL_PHY_FAMILY_ID(MARVELL_PHY_ID_88E1121R):
-	case MARVELL_PHY_FAMILY_ID(MARVELL_PHY_ID_88E1318S):
-		def_config = MII_88E1121_PHY_LED_DEF;
-		break;
-	/* Default PHY LED config:
-	 * LED[0] .. 1000Mbps Link
-	 * LED[1] .. 100Mbps Link
-	 * LED[2] .. Blink, Activity
-	 */
-	case MARVELL_PHY_FAMILY_ID(MARVELL_PHY_ID_88E1510):
-		if (phydev->dev_flags & MARVELL_PHY_LED0_LINK_LED1_ACTIVE)
-			def_config = MII_88E1510_PHY_LED0_LINK_LED1_ACTIVE;
-		else
-			def_config = MII_88E1510_PHY_LED_DEF;
-		break;
-	default:
+	if (priv->led_def_config == -1)
 		return;
+
+	if (priv->led_def_config)
+		goto write;
+
+	if (phydev->dev_flags & MARVELL_PHY_USE_PRESET_LED) {
+		priv->led_def_config = phy_read_paged(phydev, MII_MARVELL_LED_PAGE,
+						      MII_PHY_LED_CTRL);
+		if (priv->led_def_config < 0) {
+			priv->led_def_config = -1;
+			return;
+		}
+	} else {
+		switch (MARVELL_PHY_FAMILY_ID(phydev->phy_id)) {
+		/* Default PHY LED config: LED[0] .. Link, LED[1] .. Activity */
+		case MARVELL_PHY_FAMILY_ID(MARVELL_PHY_ID_88E1121R):
+		case MARVELL_PHY_FAMILY_ID(MARVELL_PHY_ID_88E1318S):
+			priv->led_def_config = MII_88E1121_PHY_LED_DEF;
+			break;
+		/* Default PHY LED config:
+		 * LED[0] .. 1000Mbps Link
+		 * LED[1] .. 100Mbps Link
+		 * LED[2] .. Blink, Activity
+		 */
+		case MARVELL_PHY_FAMILY_ID(MARVELL_PHY_ID_88E1510):
+			if (phydev->dev_flags & MARVELL_PHY_LED0_LINK_LED1_ACTIVE)
+				priv->led_def_config = MII_88E1510_PHY_LED0_LINK_LED1_ACTIVE;
+			else
+				priv->led_def_config = MII_88E1510_PHY_LED_DEF;
+			break;
+		default:
+			priv->led_def_config = -1;
+			return;
+		}
 	}
 
+write:
 	err = phy_write_paged(phydev, MII_MARVELL_LED_PAGE, MII_PHY_LED_CTRL,
-			      def_config);
+			      priv->led_def_config);
 	if (err < 0)
 		phydev_warn(phydev, "Fail to config marvell phy LED.\n");
 }
diff --git a/include/linux/marvell_phy.h b/include/linux/marvell_phy.h
index ea5995d9ad6c1..492f07620b6c0 100644
--- a/include/linux/marvell_phy.h
+++ b/include/linux/marvell_phy.h
@@ -43,5 +43,6 @@
 #define MARVELL_PHY_M1145_FLAGS_RESISTANCE	BIT(0)
 #define MARVELL_PHY_M1118_DNS323_LEDS		BIT(1)
 #define MARVELL_PHY_LED0_LINK_LED1_ACTIVE	BIT(2)
+#define MARVELL_PHY_USE_PRESET_LED		BIT(3)
 
 #endif /* _MARVELL_PHY_H */
-- 
2.33.1


WARNING: multiple messages have this Message-ID (diff)
From: Kai-Heng Feng <kai.heng.feng@canonical.com>
To: peppe.cavallaro@st.com, alexandre.torgue@foss.st.com,
	joabreu@synopsys.com
Cc: "Kai-Heng Feng" <kai.heng.feng@canonical.com>,
	"David S. Miller" <davem@davemloft.net>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Maxime Coquelin" <mcoquelin.stm32@gmail.com>,
	"Andrew Lunn" <andrew@lunn.ch>,
	"Heiner Kallweit" <hkallweit1@gmail.com>,
	"Russell King" <linux@armlinux.org.uk>,
	"Marek Behún" <kabel@kernel.org>,
	"Ivan Bornyakov" <i.bornyakov@metrotek.ru>,
	"Pali Rohár" <pali@kernel.org>,
	netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] stmmac: intel: Honor phy LED set by system firmware on a Dell hardware
Date: Fri, 14 Jan 2022 12:07:54 +0800	[thread overview]
Message-ID: <20220114040755.1314349-2-kai.heng.feng@canonical.com> (raw)
In-Reply-To: <20220114040755.1314349-1-kai.heng.feng@canonical.com>

BIOS on Dell Edge Gateway 3200 already makes its own phy LED setting, so
instead of setting another value, keep it untouched and restore the saved
value on system resume.

Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
---
 .../net/ethernet/stmicro/stmmac/dwmac-intel.c | 16 +++++
 drivers/net/ethernet/stmicro/stmmac/stmmac.h  |  2 +
 .../net/ethernet/stmicro/stmmac/stmmac_main.c |  4 ++
 drivers/net/phy/marvell.c                     | 58 ++++++++++++-------
 include/linux/marvell_phy.h                   |  1 +
 5 files changed, 61 insertions(+), 20 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c
index 8e8778cfbbadd..f8a2879e0264a 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c
@@ -857,6 +857,16 @@ static const struct dmi_system_id quark_pci_dmi[] = {
 	{}
 };
 
+static const struct dmi_system_id use_preset_led[] = {
+	{
+		.matches = {
+			DMI_MATCH(DMI_SYS_VENDOR, "Dell EMC"),
+			DMI_MATCH(DMI_PRODUCT_NAME, "Edge Gateway 3200"),
+		},
+	},
+	{}
+};
+
 static int quark_default_data(struct pci_dev *pdev,
 			      struct plat_stmmacenet_data *plat)
 {
@@ -989,6 +999,7 @@ static int intel_eth_pci_probe(struct pci_dev *pdev,
 	struct intel_priv_data *intel_priv;
 	struct plat_stmmacenet_data *plat;
 	struct stmmac_resources res;
+	struct stmmac_priv *priv;
 	int ret;
 
 	intel_priv = devm_kzalloc(&pdev->dev, sizeof(*intel_priv), GFP_KERNEL);
@@ -1075,6 +1086,11 @@ static int intel_eth_pci_probe(struct pci_dev *pdev,
 		goto err_dvr_probe;
 	}
 
+	if (dmi_check_system(use_preset_led)) {
+		priv = netdev_priv(dev_get_drvdata(&pdev->dev));
+		priv->use_preset_led = true;
+	}
+
 	return 0;
 
 err_dvr_probe:
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
index 40b5ed94cb54a..525701acbbdbb 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
@@ -319,6 +319,8 @@ struct stmmac_priv {
 	/* XDP BPF Program */
 	unsigned long *af_xdp_zc_qps;
 	struct bpf_prog *xdp_prog;
+
+	bool use_preset_led;
 };
 
 enum stmmac_state {
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 63ff2dad8c85f..155412656b8bf 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -49,6 +49,7 @@
 #include "dwmac1000.h"
 #include "dwxgmac2.h"
 #include "hwif.h"
+#include <linux/marvell_phy.h>
 
 /* As long as the interface is active, we keep the timestamping counter enabled
  * with fine resolution and binary rollover. This avoid non-monotonic behavior
@@ -1236,6 +1237,9 @@ static int stmmac_init_phy(struct net_device *dev)
 			return -ENODEV;
 		}
 
+		if (priv->use_preset_led)
+			phydev->dev_flags |= MARVELL_PHY_USE_PRESET_LED;
+
 		ret = phylink_connect_phy(priv->phylink, phydev);
 	}
 
diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c
index 739859c0dfb18..45be432188781 100644
--- a/drivers/net/phy/marvell.c
+++ b/drivers/net/phy/marvell.c
@@ -304,6 +304,7 @@ struct marvell_priv {
 	u32 last;
 	u32 step;
 	s8 pair;
+	u16 led_def_config;
 };
 
 static int marvell_read_page(struct phy_device *phydev)
@@ -748,32 +749,49 @@ static int m88e1510_config_aneg(struct phy_device *phydev)
 
 static void marvell_config_led(struct phy_device *phydev)
 {
-	u16 def_config;
+	struct marvell_priv *priv = phydev->priv;
 	int err;
 
-	switch (MARVELL_PHY_FAMILY_ID(phydev->phy_id)) {
-	/* Default PHY LED config: LED[0] .. Link, LED[1] .. Activity */
-	case MARVELL_PHY_FAMILY_ID(MARVELL_PHY_ID_88E1121R):
-	case MARVELL_PHY_FAMILY_ID(MARVELL_PHY_ID_88E1318S):
-		def_config = MII_88E1121_PHY_LED_DEF;
-		break;
-	/* Default PHY LED config:
-	 * LED[0] .. 1000Mbps Link
-	 * LED[1] .. 100Mbps Link
-	 * LED[2] .. Blink, Activity
-	 */
-	case MARVELL_PHY_FAMILY_ID(MARVELL_PHY_ID_88E1510):
-		if (phydev->dev_flags & MARVELL_PHY_LED0_LINK_LED1_ACTIVE)
-			def_config = MII_88E1510_PHY_LED0_LINK_LED1_ACTIVE;
-		else
-			def_config = MII_88E1510_PHY_LED_DEF;
-		break;
-	default:
+	if (priv->led_def_config == -1)
 		return;
+
+	if (priv->led_def_config)
+		goto write;
+
+	if (phydev->dev_flags & MARVELL_PHY_USE_PRESET_LED) {
+		priv->led_def_config = phy_read_paged(phydev, MII_MARVELL_LED_PAGE,
+						      MII_PHY_LED_CTRL);
+		if (priv->led_def_config < 0) {
+			priv->led_def_config = -1;
+			return;
+		}
+	} else {
+		switch (MARVELL_PHY_FAMILY_ID(phydev->phy_id)) {
+		/* Default PHY LED config: LED[0] .. Link, LED[1] .. Activity */
+		case MARVELL_PHY_FAMILY_ID(MARVELL_PHY_ID_88E1121R):
+		case MARVELL_PHY_FAMILY_ID(MARVELL_PHY_ID_88E1318S):
+			priv->led_def_config = MII_88E1121_PHY_LED_DEF;
+			break;
+		/* Default PHY LED config:
+		 * LED[0] .. 1000Mbps Link
+		 * LED[1] .. 100Mbps Link
+		 * LED[2] .. Blink, Activity
+		 */
+		case MARVELL_PHY_FAMILY_ID(MARVELL_PHY_ID_88E1510):
+			if (phydev->dev_flags & MARVELL_PHY_LED0_LINK_LED1_ACTIVE)
+				priv->led_def_config = MII_88E1510_PHY_LED0_LINK_LED1_ACTIVE;
+			else
+				priv->led_def_config = MII_88E1510_PHY_LED_DEF;
+			break;
+		default:
+			priv->led_def_config = -1;
+			return;
+		}
 	}
 
+write:
 	err = phy_write_paged(phydev, MII_MARVELL_LED_PAGE, MII_PHY_LED_CTRL,
-			      def_config);
+			      priv->led_def_config);
 	if (err < 0)
 		phydev_warn(phydev, "Fail to config marvell phy LED.\n");
 }
diff --git a/include/linux/marvell_phy.h b/include/linux/marvell_phy.h
index ea5995d9ad6c1..492f07620b6c0 100644
--- a/include/linux/marvell_phy.h
+++ b/include/linux/marvell_phy.h
@@ -43,5 +43,6 @@
 #define MARVELL_PHY_M1145_FLAGS_RESISTANCE	BIT(0)
 #define MARVELL_PHY_M1118_DNS323_LEDS		BIT(1)
 #define MARVELL_PHY_LED0_LINK_LED1_ACTIVE	BIT(2)
+#define MARVELL_PHY_USE_PRESET_LED		BIT(3)
 
 #endif /* _MARVELL_PHY_H */
-- 
2.33.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2022-01-14  4:08 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-14  4:07 [PATCH 1/2] net: phy: marvell: Use BIT() macro for flags Kai-Heng Feng
2022-01-14  4:07 ` Kai-Heng Feng [this message]
2022-01-14  4:07   ` [PATCH 2/2] stmmac: intel: Honor phy LED set by system firmware on a Dell hardware Kai-Heng Feng
2022-01-14  4:35   ` Jakub Kicinski
2022-01-14  4:35     ` Jakub Kicinski
2022-01-14  6:47     ` Kai-Heng Feng
2022-01-14  6:47       ` Kai-Heng Feng
2022-01-14 16:23       ` Jakub Kicinski
2022-01-14 16:23         ` Jakub Kicinski
2022-01-14  6:53   ` kernel test robot
2022-01-14  6:53     ` kernel test robot
2022-01-14 13:09   ` Andrew Lunn
2022-01-14 13:09     ` Andrew Lunn
2022-01-14 15:22     ` Kai-Heng Feng
2022-01-14 15:22       ` Kai-Heng Feng
2022-01-14 17:25       ` Andrew Lunn
2022-01-14 17:25         ` Andrew Lunn
2022-01-14 13:20   ` Andrew Lunn
2022-01-14 13:20     ` Andrew Lunn
2022-01-14 15:25     ` Kai-Heng Feng
2022-01-14 15:25       ` Kai-Heng Feng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220114040755.1314349-2-kai.heng.feng@canonical.com \
    --to=kai.heng.feng@canonical.com \
    --cc=alexandre.torgue@foss.st.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=hkallweit1@gmail.com \
    --cc=i.bornyakov@metrotek.ru \
    --cc=joabreu@synopsys.com \
    --cc=kabel@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=linux@armlinux.org.uk \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pali@kernel.org \
    --cc=peppe.cavallaro@st.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.