lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20220420124053.853891-4-kai.heng.feng@canonical.com>
Date:   Wed, 20 Apr 2022 20:40:50 +0800
From:   Kai-Heng Feng <kai.heng.feng@...onical.com>
To:     andrew@...n.ch, hkallweit1@...il.com, linux@...linux.org.uk,
        peppe.cavallaro@...com, alexandre.torgue@...s.st.com,
        joabreu@...opsys.com, davem@...emloft.net, kuba@...nel.org,
        pabeni@...hat.com
Cc:     Kai-Heng Feng <kai.heng.feng@...onical.com>,
        netdev@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH 3/5] net: phy: Add helpers to save and restore firmware LED

PHY drivers may set hardcoded LED config in phy_init_hw(), so to
preserve the firmware LED after init or system sleep, it needs to be
saved before init and be restored after.

To do so, create helpers and driver callbacks to access and save LED
config for the need.

Signed-off-by: Kai-Heng Feng <kai.heng.feng@...onical.com>
---
 drivers/net/phy/phy_device.c | 22 ++++++++++++++++++++++
 include/linux/phy.h          |  4 ++++
 2 files changed, 26 insertions(+)

diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 8406ac739def8..33b402279febe 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -1154,6 +1154,24 @@ static int phy_poll_reset(struct phy_device *phydev)
 	return 0;
 }
 
+static void phy_save_led(struct phy_device *phydev)
+{
+	if (!phydev->use_firmware_led)
+		return;
+
+	if (phydev->drv->get_led_config)
+		phydev->led_config = phydev->drv->get_led_config(phydev);
+}
+
+static void phy_restore_led(struct phy_device *phydev)
+{
+	if (!phydev->use_firmware_led)
+		return;
+
+	if (phydev->drv->set_led_config && phydev->led_config)
+		phydev->drv->set_led_config(phydev, phydev->led_config);
+}
+
 int phy_init_hw(struct phy_device *phydev)
 {
 	int ret = 0;
@@ -1463,6 +1481,8 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
 	if (dev)
 		netif_carrier_off(phydev->attached_dev);
 
+	phy_save_led(phydev);
+
 	/* Do initial configuration here, now that
 	 * we have certain key parameters
 	 * (dev_flags and interface)
@@ -1803,6 +1823,8 @@ int __phy_resume(struct phy_device *phydev)
 	if (!ret)
 		phydev->suspended = false;
 
+	phy_restore_led(phydev);
+
 	return ret;
 }
 EXPORT_SYMBOL(__phy_resume);
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 53e693b3430ec..cd9c05ff75ee1 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -657,6 +657,7 @@ struct phy_device {
 	u32 eee_broken_modes;
 
 	bool use_firmware_led;
+	int led_config;
 #ifdef CONFIG_LED_TRIGGER_PHY
 	struct phy_led_trigger *phy_led_triggers;
 	unsigned int phy_num_led_triggers;
@@ -933,6 +934,9 @@ struct phy_driver {
 	int (*get_sqi)(struct phy_device *dev);
 	/** @get_sqi_max: Get the maximum signal quality indication */
 	int (*get_sqi_max)(struct phy_device *dev);
+
+	int (*get_led_config)(struct phy_device *dev);
+	void (*set_led_config)(struct phy_device *dev, int led_config);
 };
 #define to_phy_driver(d) container_of(to_mdio_common_driver(d),		\
 				      struct phy_driver, mdiodrv)
-- 
2.34.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ