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>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Sat, 11 May 2024 00:14:25 +0100
From: Daniel Golle <daniel@...rotopia.org>
To: Christian Marangi <ansuelsmth@...il.com>
Cc: Pavel Machek <pavel@....cz>, Lee Jones <lee@...nel.org>,
	Rob Herring <robh+dt@...nel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@...aro.org>,
	Conor Dooley <conor+dt@...nel.org>,
	William Zhang <william.zhang@...adcom.com>,
	Anand Gore <anand.gore@...adcom.com>,
	Kursad Oney <kursad.oney@...adcom.com>,
	Florian Fainelli <florian.fainelli@...adcom.com>,
	Rafał Miłecki <rafal@...ecki.pl>,
	Broadcom internal kernel review list <bcm-kernel-feedback-list@...adcom.com>,
	"David S. Miller" <davem@...emloft.net>,
	Eric Dumazet <edumazet@...gle.com>,
	Jakub Kicinski <kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>,
	Andrew Lunn <andrew@...n.ch>,
	Heiner Kallweit <hkallweit1@...il.com>,
	Russell King <linux@...linux.org.uk>,
	Jacek Anaszewski <jacek.anaszewski@...il.com>,
	Fernández Rojas <noltari@...il.com>,
	Sven Schwermer <sven.schwermer@...ruptive-technologies.com>,
	linux-leds@...r.kernel.org, devicetree@...r.kernel.org,
	linux-kernel@...r.kernel.org, linux-arm-kernel@...ts.infradead.org,
	netdev@...r.kernel.org
Subject: Re: [net-next PATCH v10 3/5] net: phy: add support for PHY LEDs
 polarity modes

Hi Christian,
Hi Andrew,

On Thu, Jan 25, 2024 at 09:36:59PM +0100, Christian Marangi wrote:
> Add support for PHY LEDs polarity modes. Some PHY require LED to be set
> to active low to be turned ON. Adds support for this by declaring
> active-low property in DT.
> 
> PHY driver needs to declare .led_polarity_set() to configure LED
> polarity modes. Function will pass the index with the LED index and a
> bitmap with all the required modes to set.
> 
> Current supported modes are:
> - active-low with the flag PHY_LED_ACTIVE_LOW. LED is set to active-low
>   to turn it ON.
> - inactive-high-impedance with the flag PHY_LED_INACTIVE_HIGH_IMPEDANCE.
>   LED is set to high impedance to turn it OFF.

Wanting to make use of this I noticed that polarity settings are only
applied once in of_phy_led(), which is not sufficient for my use-case:

I'm writing a LED driver for Aquantia PHYs and those PHYs reset the
polarity mode every time a PHY reset is triggered.

I ended up writing the patch below, but I'm not sure if phy_init_hw
should take care of this or if the polarity modes should be stored in
memory allocated by the PHY driver and re-applied by the driver after
reset (eg. in .config_init). Kinda depends on taste and on how common
this behavior is in practise, so I thought the best is to reach out to
discuss.

Let me know what you think.

diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 616bd7ba46cb..1624884fd627 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -1251,6 +1251,7 @@ static int phy_poll_reset(struct phy_device *phydev)
 int phy_init_hw(struct phy_device *phydev)
 {
 	int ret = 0;
+	struct phy_led *phyled;
 
 	/* Deassert the reset signal */
 	phy_device_reset(phydev, 0);
@@ -1285,6 +1286,17 @@ int phy_init_hw(struct phy_device *phydev)
 			return ret;
 	}
 
+	if (phydev->drv->led_polarity_set) {
+		list_for_each_entry(phyled, &phydev->leds, list) {
+			if (!phyled->polarity_modes)
+				continue;
+
+			ret = phydev->drv->led_polarity_set(phydev, phyled->index, phyled->polarity_modes);
+			if (ret)
+				return ret;
+		}
+	}
+
 	return 0;
 }
 EXPORT_SYMBOL(phy_init_hw);
@@ -3316,7 +3328,6 @@ static int of_phy_led(struct phy_device *phydev,
 	struct device *dev = &phydev->mdio.dev;
 	struct led_init_data init_data = {};
 	struct led_classdev *cdev;
-	unsigned long modes = 0;
 	struct phy_led *phyled;
 	u32 index;
 	int err;
@@ -3335,18 +3346,14 @@ static int of_phy_led(struct phy_device *phydev,
 		return -EINVAL;
 
 	if (of_property_read_bool(led, "active-low"))
-		set_bit(PHY_LED_ACTIVE_LOW, &modes);
+		set_bit(PHY_LED_ACTIVE_LOW, &phyled->polarity_modes);
 	if (of_property_read_bool(led, "inactive-high-impedance"))
-		set_bit(PHY_LED_INACTIVE_HIGH_IMPEDANCE, &modes);
+		set_bit(PHY_LED_INACTIVE_HIGH_IMPEDANCE, &phyled->polarity_modes);
 
-	if (modes) {
+	if (phyled->polarity_modes) {
 		/* Return error if asked to set polarity modes but not supported */
 		if (!phydev->drv->led_polarity_set)
 			return -EINVAL;
-
-		err = phydev->drv->led_polarity_set(phydev, index, modes);
-		if (err)
-			return err;
 	}
 
 	phyled->index = index;
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 3ddfe7fe781a..7c8bd72e6fee 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -888,6 +888,7 @@ struct phy_led {
 	struct list_head list;
 	struct phy_device *phydev;
 	struct led_classdev led_cdev;
+	unsigned long polarity_modes;
 	u8 index;
 };
 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ