[net-next] net: phy: improve struct phy_device member interrupts handling

Message ID 44805a11-3063-4f1f-2fd2-b268155d4935@gmail.com
State Changes Requested
Delegated to: David Miller
Headers show
Series
  • [net-next] net: phy: improve struct phy_device member interrupts handling
Related show

Commit Message

Heiner Kallweit Nov. 8, 2018, 9:36 p.m.
As a heritage from the very early days of phylib member interrupts is
defined as u32 even though it's just a flag whether interrupts are
enabled. So we can change it to a bitfield member. In addition change
the code dealing with this member in a way that it's clear we're
dealing with a bool value.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
Actually this member isn't needed at all and could be replaced with
a parameter in phy_driver->config_intr. But this would mean an API
change, maybe I come up with a proposal later.
---
 drivers/net/phy/phy.c |  2 +-
 include/linux/phy.h   | 10 +++++-----
 2 files changed, 6 insertions(+), 6 deletions(-)

Comments

Andrew Lunn Nov. 8, 2018, 10:24 p.m. | #1
On Thu, Nov 08, 2018 at 10:36:33PM +0100, Heiner Kallweit wrote:
> As a heritage from the very early days of phylib member interrupts is
> defined as u32 even though it's just a flag whether interrupts are
> enabled. So we can change it to a bitfield member. In addition change
> the code dealing with this member in a way that it's clear we're
> dealing with a bool value.
> 
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> ---
> Actually this member isn't needed at all and could be replaced with
> a parameter in phy_driver->config_intr. But this would mean an API
> change, maybe I come up with a proposal later.
> ---
>  drivers/net/phy/phy.c |  2 +-
>  include/linux/phy.h   | 10 +++++-----
>  2 files changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
> index dd5bff955..a5e6acfe6 100644
> --- a/drivers/net/phy/phy.c
> +++ b/drivers/net/phy/phy.c
> @@ -115,7 +115,7 @@ static int phy_clear_interrupt(struct phy_device *phydev)
>   *
>   * Returns 0 on success or < 0 on error.
>   */
> -static int phy_config_interrupt(struct phy_device *phydev, u32 interrupts)
> +static int phy_config_interrupt(struct phy_device *phydev, bool interrupts)
>  {
>  	phydev->interrupts = interrupts;
>  	if (phydev->drv->config_intr)
> diff --git a/include/linux/phy.h b/include/linux/phy.h
> index 5dd85c441..fc90af152 100644
> --- a/include/linux/phy.h
> +++ b/include/linux/phy.h
> @@ -263,8 +263,8 @@ static inline struct mii_bus *devm_mdiobus_alloc(struct device *dev)
>  void devm_mdiobus_free(struct device *dev, struct mii_bus *bus);
>  struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr);
>  
> -#define PHY_INTERRUPT_DISABLED	0x0
> -#define PHY_INTERRUPT_ENABLED	0x80000000
> +#define PHY_INTERRUPT_DISABLED	0
> +#define PHY_INTERRUPT_ENABLED	1

Hi Heiner

Since this is passed around as a bool, false/true would be better than
0/1.

	Andrew
Heiner Kallweit Nov. 8, 2018, 10:39 p.m. | #2
On 08.11.2018 23:24, Andrew Lunn wrote:
> On Thu, Nov 08, 2018 at 10:36:33PM +0100, Heiner Kallweit wrote:
>> As a heritage from the very early days of phylib member interrupts is
>> defined as u32 even though it's just a flag whether interrupts are
>> enabled. So we can change it to a bitfield member. In addition change
>> the code dealing with this member in a way that it's clear we're
>> dealing with a bool value.
>>
>> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
>> ---
>> Actually this member isn't needed at all and could be replaced with
>> a parameter in phy_driver->config_intr. But this would mean an API
>> change, maybe I come up with a proposal later.
>> ---
>>  drivers/net/phy/phy.c |  2 +-
>>  include/linux/phy.h   | 10 +++++-----
>>  2 files changed, 6 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
>> index dd5bff955..a5e6acfe6 100644
>> --- a/drivers/net/phy/phy.c
>> +++ b/drivers/net/phy/phy.c
>> @@ -115,7 +115,7 @@ static int phy_clear_interrupt(struct phy_device *phydev)
>>   *
>>   * Returns 0 on success or < 0 on error.
>>   */
>> -static int phy_config_interrupt(struct phy_device *phydev, u32 interrupts)
>> +static int phy_config_interrupt(struct phy_device *phydev, bool interrupts)
>>  {
>>  	phydev->interrupts = interrupts;
>>  	if (phydev->drv->config_intr)
>> diff --git a/include/linux/phy.h b/include/linux/phy.h
>> index 5dd85c441..fc90af152 100644
>> --- a/include/linux/phy.h
>> +++ b/include/linux/phy.h
>> @@ -263,8 +263,8 @@ static inline struct mii_bus *devm_mdiobus_alloc(struct device *dev)
>>  void devm_mdiobus_free(struct device *dev, struct mii_bus *bus);
>>  struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr);
>>  
>> -#define PHY_INTERRUPT_DISABLED	0x0
>> -#define PHY_INTERRUPT_ENABLED	0x80000000
>> +#define PHY_INTERRUPT_DISABLED	0
>> +#define PHY_INTERRUPT_ENABLED	1
> 
> Hi Heiner
> 
> Since this is passed around as a bool, false/true would be better than
> 0/1.
> 
I thought about that before submitting the patch. I preferred to go with
0/1 because we assign this value to a 1 bit bitfield member which supports
values 0/1 only. So neither option is perfect IMO.

> 	Andrew
> 
Heiner

Patch

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index dd5bff955..a5e6acfe6 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -115,7 +115,7 @@  static int phy_clear_interrupt(struct phy_device *phydev)
  *
  * Returns 0 on success or < 0 on error.
  */
-static int phy_config_interrupt(struct phy_device *phydev, u32 interrupts)
+static int phy_config_interrupt(struct phy_device *phydev, bool interrupts)
 {
 	phydev->interrupts = interrupts;
 	if (phydev->drv->config_intr)
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 5dd85c441..fc90af152 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -263,8 +263,8 @@  static inline struct mii_bus *devm_mdiobus_alloc(struct device *dev)
 void devm_mdiobus_free(struct device *dev, struct mii_bus *bus);
 struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr);
 
-#define PHY_INTERRUPT_DISABLED	0x0
-#define PHY_INTERRUPT_ENABLED	0x80000000
+#define PHY_INTERRUPT_DISABLED	0
+#define PHY_INTERRUPT_ENABLED	1
 
 /* PHY state machine states:
  *
@@ -410,6 +410,9 @@  struct phy_device {
 	/* The most recently read link state */
 	unsigned link:1;
 
+	/* Interrupts are enabled */
+	unsigned interrupts:1;
+
 	enum phy_state state;
 
 	u32 dev_flags;
@@ -425,9 +428,6 @@  struct phy_device {
 	int pause;
 	int asym_pause;
 
-	/* Enabled Interrupts */
-	u32 interrupts;
-
 	/* Union of PHY and Attached devices' supported modes */
 	/* See mii.h for more info */
 	u32 supported;