All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCHv3] Fixed PHY: Add fixed_phy_change_carrier()
@ 2018-12-13 17:47 Joakim Tjernlund
  2018-12-13 18:48 ` Florian Fainelli
  0 siblings, 1 reply; 3+ messages in thread
From: Joakim Tjernlund @ 2018-12-13 17:47 UTC (permalink / raw)
  To: netdev @ vger . kernel . org, Florian Fainelli, Andrew Lunn,
	claudiu . manoil @ nxp . com
  Cc: Joakim Tjernlund

Drivers can use this as .ndo_change_carrier() to change carrier
via /sys/class/net/ethX/carrier.

Signed-off-by: Joakim Tjernlund <joakim.tjernlund@infinera.com>
---

 v3 - Moved the logic into fixed PHY to minimize eth driver
      impact

 v2 - Only allow carrier changes for Fixed PHYs

 I will follow up with drivers using this next.
 
 drivers/net/phy/fixed_phy.c | 23 ++++++++++++++++++++++-
 include/linux/phy_fixed.h   |  5 +++++
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/drivers/net/phy/fixed_phy.c b/drivers/net/phy/fixed_phy.c
index eb5167210681..aedebc251997 100644
--- a/drivers/net/phy/fixed_phy.c
+++ b/drivers/net/phy/fixed_phy.c
@@ -25,6 +25,7 @@
 #include <linux/gpio.h>
 #include <linux/seqlock.h>
 #include <linux/idr.h>
+#include <linux/netdevice.h>
 
 #include "swphy.h"
 
@@ -38,6 +39,7 @@ struct fixed_phy {
 	struct phy_device *phydev;
 	seqcount_t seqcount;
 	struct fixed_phy_status status;
+	bool no_carrier;
 	int (*link_update)(struct net_device *, struct fixed_phy_status *);
 	struct list_head node;
 	int link_gpio;
@@ -48,9 +50,27 @@ static struct fixed_mdio_bus platform_fmb = {
 	.phys = LIST_HEAD_INIT(platform_fmb.phys),
 };
 
+int
+fixed_phy_change_carrier(struct net_device *dev, bool new_carrier)
+{
+	struct fixed_mdio_bus *fmb = &platform_fmb;
+	struct phy_device *phydev = dev->phydev;
+	struct fixed_phy *fp;
+
+	if (!phydev || !phydev->mdio.bus)
+		return -EINVAL;
+
+	list_for_each_entry(fp, &fmb->phys, node) {
+		if (fp->addr == phydev->mdio.addr) {
+			fp->no_carrier = !new_carrier;
+			return 0;
+		}
+	}
+	return -EINVAL;
+}
 static void fixed_phy_update(struct fixed_phy *fp)
 {
-	if (gpio_is_valid(fp->link_gpio))
+	if (!fp->no_carrier && gpio_is_valid(fp->link_gpio))
 		fp->status.link = !!gpio_get_value_cansleep(fp->link_gpio);
 }
 
@@ -66,6 +86,7 @@ static int fixed_mdio_read(struct mii_bus *bus, int phy_addr, int reg_num)
 
 			do {
 				s = read_seqcount_begin(&fp->seqcount);
+				fp->status.link = !fp->no_carrier;
 				/* Issue callback if user registered it. */
 				if (fp->link_update) {
 					fp->link_update(fp->phydev->attached_dev,
diff --git a/include/linux/phy_fixed.h b/include/linux/phy_fixed.h
index cf6392de6eb0..a711b41f3e20 100644
--- a/include/linux/phy_fixed.h
+++ b/include/linux/phy_fixed.h
@@ -13,6 +13,7 @@ struct fixed_phy_status {
 struct device_node;
 
 #if IS_ENABLED(CONFIG_FIXED_PHY)
+extern int fixed_phy_change_carrier(struct net_device *dev, bool new_carrier);
 extern int fixed_phy_add(unsigned int irq, int phy_id,
 			 struct fixed_phy_status *status,
 			 int link_gpio);
@@ -56,6 +57,10 @@ static inline int fixed_phy_update_state(struct phy_device *phydev,
 {
 	return -ENODEV;
 }
+static inline int fixed_phy_change_carrier(struct net_device *dev, bool new_carrier)
+{
+	return -EINVAL;
+}
 #endif /* CONFIG_FIXED_PHY */
 
 #endif /* __PHY_FIXED_H */
-- 
2.18.1

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

* Re: [PATCHv3] Fixed PHY: Add fixed_phy_change_carrier()
  2018-12-13 17:47 [PATCHv3] Fixed PHY: Add fixed_phy_change_carrier() Joakim Tjernlund
@ 2018-12-13 18:48 ` Florian Fainelli
  2018-12-14  8:05   ` Joakim Tjernlund
  0 siblings, 1 reply; 3+ messages in thread
From: Florian Fainelli @ 2018-12-13 18:48 UTC (permalink / raw)
  To: Joakim Tjernlund, netdev @ vger . kernel . org, Andrew Lunn,
	claudiu . manoil @ nxp . com

Le 12/13/18 à 9:47 AM, Joakim Tjernlund a écrit :
> Drivers can use this as .ndo_change_carrier() to change carrier
> via /sys/class/net/ethX/carrier.
> 
> Signed-off-by: Joakim Tjernlund <joakim.tjernlund@infinera.com>

Other than a few

> ---
> 
>  v3 - Moved the logic into fixed PHY to minimize eth driver
>       impact
> 
>  v2 - Only allow carrier changes for Fixed PHYs
> 
>  I will follow up with drivers using this next.

You might as well post them as a patch series that way we can review the
function and its user(s) in one go. Few nitpicks below, but looking good
otherwise.

>  
>  drivers/net/phy/fixed_phy.c | 23 ++++++++++++++++++++++-
>  include/linux/phy_fixed.h   |  5 +++++
>  2 files changed, 27 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/phy/fixed_phy.c b/drivers/net/phy/fixed_phy.c
> index eb5167210681..aedebc251997 100644
> --- a/drivers/net/phy/fixed_phy.c
> +++ b/drivers/net/phy/fixed_phy.c
> @@ -25,6 +25,7 @@
>  #include <linux/gpio.h>
>  #include <linux/seqlock.h>
>  #include <linux/idr.h>
> +#include <linux/netdevice.h>
>  
>  #include "swphy.h"
>  
> @@ -38,6 +39,7 @@ struct fixed_phy {
>  	struct phy_device *phydev;
>  	seqcount_t seqcount;
>  	struct fixed_phy_status status;
> +	bool no_carrier;

Any reason why this is used with negative logic instead of positive
logic and calling that just "carrier"?

>  	int (*link_update)(struct net_device *, struct fixed_phy_status *);
>  	struct list_head node;
>  	int link_gpio;
> @@ -48,9 +50,27 @@ static struct fixed_mdio_bus platform_fmb = {
>  	.phys = LIST_HEAD_INIT(platform_fmb.phys),
>  };
>  
> +int
> +fixed_phy_change_carrier(struct net_device *dev, bool new_carrier)

Can you put the return type and function name on the same line?

> +{
> +	struct fixed_mdio_bus *fmb = &platform_fmb;
> +	struct phy_device *phydev = dev->phydev;
> +	struct fixed_phy *fp;
> +
> +	if (!phydev || !phydev->mdio.bus)
> +		return -EINVAL;
> +
> +	list_for_each_entry(fp, &fmb->phys, node) {
> +		if (fp->addr == phydev->mdio.addr) {
> +			fp->no_carrier = !new_carrier;
> +			return 0;
> +		}
> +	}
> +	return -EINVAL;
> +}

Missing newline and EXPORT_SYMBOL_GPL() here to make that visible to
modules.

>  static void fixed_phy_update(struct fixed_phy *fp)
>  {
> -	if (gpio_is_valid(fp->link_gpio))
> +	if (!fp->no_carrier && gpio_is_valid(fp->link_gpio))
>  		fp->status.link = !!gpio_get_value_cansleep(fp->link_gpio);
>  }
>  
> @@ -66,6 +86,7 @@ static int fixed_mdio_read(struct mii_bus *bus, int phy_addr, int reg_num)
>  
>  			do {
>  				s = read_seqcount_begin(&fp->seqcount);
> +				fp->status.link = !fp->no_carrier;
>  				/* Issue callback if user registered it. */
>  				if (fp->link_update) {
>  					fp->link_update(fp->phydev->attached_dev,
> diff --git a/include/linux/phy_fixed.h b/include/linux/phy_fixed.h
> index cf6392de6eb0..a711b41f3e20 100644
> --- a/include/linux/phy_fixed.h
> +++ b/include/linux/phy_fixed.h
> @@ -13,6 +13,7 @@ struct fixed_phy_status {
>  struct device_node;
>  
>  #if IS_ENABLED(CONFIG_FIXED_PHY)
> +extern int fixed_phy_change_carrier(struct net_device *dev, bool new_carrier);
>  extern int fixed_phy_add(unsigned int irq, int phy_id,
>  			 struct fixed_phy_status *status,
>  			 int link_gpio);
> @@ -56,6 +57,10 @@ static inline int fixed_phy_update_state(struct phy_device *phydev,
>  {
>  	return -ENODEV;
>  }
> +static inline int fixed_phy_change_carrier(struct net_device *dev, bool new_carrier)
> +{
> +	return -EINVAL;
> +}
>  #endif /* CONFIG_FIXED_PHY */
>  
>  #endif /* __PHY_FIXED_H */
> 


-- 
Florian

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

* Re: [PATCHv3] Fixed PHY: Add fixed_phy_change_carrier()
  2018-12-13 18:48 ` Florian Fainelli
@ 2018-12-14  8:05   ` Joakim Tjernlund
  0 siblings, 0 replies; 3+ messages in thread
From: Joakim Tjernlund @ 2018-12-14  8:05 UTC (permalink / raw)
  To: claudiu.manoil, netdev, f.fainelli, andrew

On Thu, 2018-12-13 at 10:48 -0800, Florian Fainelli wrote:
> CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.
> 
> 
> Le 12/13/18 à 9:47 AM, Joakim Tjernlund a écrit :
> > Drivers can use this as .ndo_change_carrier() to change carrier
> > via /sys/class/net/ethX/carrier.
> > 
> > Signed-off-by: Joakim Tjernlund <joakim.tjernlund@infinera.com>
> 
> Other than a few
> 
> > ---
> > 
> >  v3 - Moved the logic into fixed PHY to minimize eth driver
> >       impact
> > 
> >  v2 - Only allow carrier changes for Fixed PHYs
> > 
> >  I will follow up with drivers using this next.
> 
> You might as well post them as a patch series that way we can review the
> function and its user(s) in one go. Few nitpicks below, but looking good
> otherwise.

OK, will do.

> 
> >  drivers/net/phy/fixed_phy.c | 23 ++++++++++++++++++++++-
> >  include/linux/phy_fixed.h   |  5 +++++
> >  2 files changed, 27 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/net/phy/fixed_phy.c b/drivers/net/phy/fixed_phy.c
> > index eb5167210681..aedebc251997 100644
> > --- a/drivers/net/phy/fixed_phy.c
> > +++ b/drivers/net/phy/fixed_phy.c
> > @@ -25,6 +25,7 @@
> >  #include <linux/gpio.h>
> >  #include <linux/seqlock.h>
> >  #include <linux/idr.h>
> > +#include <linux/netdevice.h>
> > 
> >  #include "swphy.h"
> > 
> > @@ -38,6 +39,7 @@ struct fixed_phy {
> >       struct phy_device *phydev;
> >       seqcount_t seqcount;
> >       struct fixed_phy_status status;
> > +     bool no_carrier;
> 
> Any reason why this is used with negative logic instead of positive
> logic and calling that just "carrier"?

Yes, both because I like no_carrier better and because 0 as default does not
require explicit initialization. Are you good with that ?

> 
> >       int (*link_update)(struct net_device *, struct fixed_phy_status *);
> >       struct list_head node;
> >       int link_gpio;
> > @@ -48,9 +50,27 @@ static struct fixed_mdio_bus platform_fmb = {
> >       .phys = LIST_HEAD_INIT(platform_fmb.phys),
> >  };
> > 
> > +int
> > +fixed_phy_change_carrier(struct net_device *dev, bool new_carrier)
> 
> Can you put the return type and function name on the same line?

Done.

> 
> > +{
> > +     struct fixed_mdio_bus *fmb = &platform_fmb;
> > +     struct phy_device *phydev = dev->phydev;
> > +     struct fixed_phy *fp;
> > +
> > +     if (!phydev || !phydev->mdio.bus)
> > +             return -EINVAL;
> > +
> > +     list_for_each_entry(fp, &fmb->phys, node) {
> > +             if (fp->addr == phydev->mdio.addr) {
> > +                     fp->no_carrier = !new_carrier;
> > +                     return 0;
> > +             }
> > +     }
> > +     return -EINVAL;
> > +}
> 
> Missing newline and EXPORT_SYMBOL_GPL() here to make that visible to
> modules.

Done.

> 
> >  static void fixed_phy_update(struct fixed_phy *fp)
> >  {
> > -     if (gpio_is_valid(fp->link_gpio))
> > +     if (!fp->no_carrier && gpio_is_valid(fp->link_gpio))
> >               fp->status.link = !!gpio_get_value_cansleep(fp->link_gpio);
> >  }
> > 
> > @@ -66,6 +86,7 @@ static int fixed_mdio_read(struct mii_bus *bus, int phy_addr, int reg_num)
> > 
> >                       do {
> >                               s = read_seqcount_begin(&fp->seqcount);
> > +                             fp->status.link = !fp->no_carrier;
> >                               /* Issue callback if user registered it. */
> >                               if (fp->link_update) {
> >                                       fp->link_update(fp->phydev->attached_dev,
> > diff --git a/include/linux/phy_fixed.h b/include/linux/phy_fixed.h
> > index cf6392de6eb0..a711b41f3e20 100644
> > --- a/include/linux/phy_fixed.h
> > +++ b/include/linux/phy_fixed.h
> > @@ -13,6 +13,7 @@ struct fixed_phy_status {
> >  struct device_node;
> > 
> >  #if IS_ENABLED(CONFIG_FIXED_PHY)
> > +extern int fixed_phy_change_carrier(struct net_device *dev, bool new_carrier);
> >  extern int fixed_phy_add(unsigned int irq, int phy_id,
> >                        struct fixed_phy_status *status,
> >                        int link_gpio);
> > @@ -56,6 +57,10 @@ static inline int fixed_phy_update_state(struct phy_device *phydev,
> >  {
> >       return -ENODEV;
> >  }
> > +static inline int fixed_phy_change_carrier(struct net_device *dev, bool new_carrier)
> > +{
> > +     return -EINVAL;
> > +}
> >  #endif /* CONFIG_FIXED_PHY */
> > 
> >  #endif /* __PHY_FIXED_H */
> > 
> 
> --
> Florian


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

end of thread, other threads:[~2018-12-14  8:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-13 17:47 [PATCHv3] Fixed PHY: Add fixed_phy_change_carrier() Joakim Tjernlund
2018-12-13 18:48 ` Florian Fainelli
2018-12-14  8:05   ` Joakim Tjernlund

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.