netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: sfp: Unique GPIO interrupt names
@ 2020-07-06 19:38 Chris Healy
  2020-07-06 20:07 ` Andrew Lunn
  2020-07-06 20:42 ` Russell King - ARM Linux admin
  0 siblings, 2 replies; 5+ messages in thread
From: Chris Healy @ 2020-07-06 19:38 UTC (permalink / raw)
  To: Russell King - ARM Linux, Andrew Lunn, Florian Fainelli,
	Heiner Kallweit, David S. Miller, kuba, netdev, linux-kernel

Dynamically generate a unique GPIO interrupt name, based on the
device name and the GPIO name.  For example:

103:          0   sx1503q  12 Edge      sff2-los
104:          0   sx1503q  13 Edge      sff3-los

The sffX indicates the SFP the loss of signal GPIO is associated with.

Signed-off-by: Chris Healy <cphealy@gmail.com>
---
 drivers/net/phy/sfp.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c
index 73c2969f11a4..9b03c7229320 100644
--- a/drivers/net/phy/sfp.c
+++ b/drivers/net/phy/sfp.c
@@ -220,6 +220,7 @@ struct sfp {
     struct phy_device *mod_phy;
     const struct sff_data *type;
     u32 max_power_mW;
+    char sfp_irq_name[32];

     unsigned int (*get_state)(struct sfp *);
     void (*set_state)(struct sfp *, unsigned int);
@@ -2349,12 +2350,15 @@ static int sfp_probe(struct platform_device *pdev)
             continue;
         }

+        snprintf(sfp->sfp_irq_name, sizeof(sfp->sfp_irq_name),
+             "%s-%s", dev_name(sfp->dev), gpio_of_names[i]);
+
         err = devm_request_threaded_irq(sfp->dev, sfp->gpio_irq[i],
                         NULL, sfp_irq,
                         IRQF_ONESHOT |
                         IRQF_TRIGGER_RISING |
                         IRQF_TRIGGER_FALLING,
-                        dev_name(sfp->dev), sfp);
+                        sfp->sfp_irq_name, sfp);
         if (err) {
             sfp->gpio_irq[i] = 0;
             sfp->need_poll = true;
-- 
2.21.3

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

* Re: [PATCH] net: sfp: Unique GPIO interrupt names
  2020-07-06 19:38 [PATCH] net: sfp: Unique GPIO interrupt names Chris Healy
@ 2020-07-06 20:07 ` Andrew Lunn
  2020-07-06 23:03   ` Chris Healy
  2020-07-06 20:42 ` Russell King - ARM Linux admin
  1 sibling, 1 reply; 5+ messages in thread
From: Andrew Lunn @ 2020-07-06 20:07 UTC (permalink / raw)
  To: Chris Healy
  Cc: Russell King - ARM Linux, Florian Fainelli, Heiner Kallweit,
	David S. Miller, kuba, netdev, linux-kernel

On Mon, Jul 06, 2020 at 12:38:37PM -0700, Chris Healy wrote:
> Dynamically generate a unique GPIO interrupt name, based on the
> device name and the GPIO name.  For example:
> 
> 103:          0   sx1503q  12 Edge      sff2-los
> 104:          0   sx1503q  13 Edge      sff3-los
> 
> The sffX indicates the SFP the loss of signal GPIO is associated with.

Hi Chris

For netdev, please put inside the [PATCH] part of the subject, which
tree this is for, i.e. net-next.

> Signed-off-by: Chris Healy <cphealy@gmail.com>
> ---
>  drivers/net/phy/sfp.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c
> index 73c2969f11a4..9b03c7229320 100644
> --- a/drivers/net/phy/sfp.c
> +++ b/drivers/net/phy/sfp.c
> @@ -220,6 +220,7 @@ struct sfp {
>      struct phy_device *mod_phy;
>      const struct sff_data *type;
>      u32 max_power_mW;
> +    char sfp_irq_name[32];
> 
>      unsigned int (*get_state)(struct sfp *);
>      void (*set_state)(struct sfp *, unsigned int);
> @@ -2349,12 +2350,15 @@ static int sfp_probe(struct platform_device *pdev)
>              continue;
>          }
> 
> +        snprintf(sfp->sfp_irq_name, sizeof(sfp->sfp_irq_name),
> +             "%s-%s", dev_name(sfp->dev), gpio_of_names[i]);
> +

This is perfectly O.K, but you could consider using
devm_kasprintf(). That will allocate as much memory as needed for the
string, and hence avoid truncation issues, which we have seen before
with other interrupt names.

     Andrew

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

* Re: [PATCH] net: sfp: Unique GPIO interrupt names
  2020-07-06 19:38 [PATCH] net: sfp: Unique GPIO interrupt names Chris Healy
  2020-07-06 20:07 ` Andrew Lunn
@ 2020-07-06 20:42 ` Russell King - ARM Linux admin
  2020-07-06 23:04   ` Chris Healy
  1 sibling, 1 reply; 5+ messages in thread
From: Russell King - ARM Linux admin @ 2020-07-06 20:42 UTC (permalink / raw)
  To: Chris Healy
  Cc: Andrew Lunn, Florian Fainelli, Heiner Kallweit, David S. Miller,
	kuba, netdev, linux-kernel

On Mon, Jul 06, 2020 at 12:38:37PM -0700, Chris Healy wrote:
> Dynamically generate a unique GPIO interrupt name, based on the
> device name and the GPIO name.  For example:
> 
> 103:          0   sx1503q  12 Edge      sff2-los
> 104:          0   sx1503q  13 Edge      sff3-los
> 
> The sffX indicates the SFP the loss of signal GPIO is associated with.
> 
> Signed-off-by: Chris Healy <cphealy@gmail.com>

This doesn't work in all cases.

> ---
>  drivers/net/phy/sfp.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c
> index 73c2969f11a4..9b03c7229320 100644
> --- a/drivers/net/phy/sfp.c
> +++ b/drivers/net/phy/sfp.c
> @@ -220,6 +220,7 @@ struct sfp {
>      struct phy_device *mod_phy;
>      const struct sff_data *type;
>      u32 max_power_mW;
> +    char sfp_irq_name[32];
> 
>      unsigned int (*get_state)(struct sfp *);
>      void (*set_state)(struct sfp *, unsigned int);
> @@ -2349,12 +2350,15 @@ static int sfp_probe(struct platform_device *pdev)
>              continue;
>          }
> 
> +        snprintf(sfp->sfp_irq_name, sizeof(sfp->sfp_irq_name),
> +             "%s-%s", dev_name(sfp->dev), gpio_of_names[i]);

sfp_irq_name will be overwritten for each GPIO IRQ claimed, which means
all IRQs for a particular cage will end up with the same name.
sfp_irq_name[] therefore needs to be an array of names, one per input.

Thanks.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!

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

* Re: [PATCH] net: sfp: Unique GPIO interrupt names
  2020-07-06 20:07 ` Andrew Lunn
@ 2020-07-06 23:03   ` Chris Healy
  0 siblings, 0 replies; 5+ messages in thread
From: Chris Healy @ 2020-07-06 23:03 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: Russell King - ARM Linux, Florian Fainelli, Heiner Kallweit,
	David S. Miller, kuba, netdev, linux-kernel

On Mon, Jul 6, 2020 at 1:07 PM Andrew Lunn <andrew@lunn.ch> wrote:
>
> On Mon, Jul 06, 2020 at 12:38:37PM -0700, Chris Healy wrote:
> > Dynamically generate a unique GPIO interrupt name, based on the
> > device name and the GPIO name.  For example:
> >
> > 103:          0   sx1503q  12 Edge      sff2-los
> > 104:          0   sx1503q  13 Edge      sff3-los
> >
> > The sffX indicates the SFP the loss of signal GPIO is associated with.
>
> Hi Chris
>
> For netdev, please put inside the [PATCH] part of the subject, which
> tree this is for, i.e. net-next.

Will do.
>
> > Signed-off-by: Chris Healy <cphealy@gmail.com>
> > ---
> >  drivers/net/phy/sfp.c | 6 +++++-
> >  1 file changed, 5 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c
> > index 73c2969f11a4..9b03c7229320 100644
> > --- a/drivers/net/phy/sfp.c
> > +++ b/drivers/net/phy/sfp.c
> > @@ -220,6 +220,7 @@ struct sfp {
> >      struct phy_device *mod_phy;
> >      const struct sff_data *type;
> >      u32 max_power_mW;
> > +    char sfp_irq_name[32];
> >
> >      unsigned int (*get_state)(struct sfp *);
> >      void (*set_state)(struct sfp *, unsigned int);
> > @@ -2349,12 +2350,15 @@ static int sfp_probe(struct platform_device *pdev)
> >              continue;
> >          }
> >
> > +        snprintf(sfp->sfp_irq_name, sizeof(sfp->sfp_irq_name),
> > +             "%s-%s", dev_name(sfp->dev), gpio_of_names[i]);
> > +
>
> This is perfectly O.K, but you could consider using
> devm_kasprintf(). That will allocate as much memory as needed for the
> string, and hence avoid truncation issues, which we have seen before
> with other interrupt names.

I'll give this a try for the next version of this patch.

>
>      Andrew

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

* Re: [PATCH] net: sfp: Unique GPIO interrupt names
  2020-07-06 20:42 ` Russell King - ARM Linux admin
@ 2020-07-06 23:04   ` Chris Healy
  0 siblings, 0 replies; 5+ messages in thread
From: Chris Healy @ 2020-07-06 23:04 UTC (permalink / raw)
  To: Russell King - ARM Linux admin
  Cc: Andrew Lunn, Florian Fainelli, Heiner Kallweit, David S. Miller,
	kuba, netdev, linux-kernel

On Mon, Jul 6, 2020 at 1:42 PM Russell King - ARM Linux admin
<linux@armlinux.org.uk> wrote:
>
> On Mon, Jul 06, 2020 at 12:38:37PM -0700, Chris Healy wrote:
> > Dynamically generate a unique GPIO interrupt name, based on the
> > device name and the GPIO name.  For example:
> >
> > 103:          0   sx1503q  12 Edge      sff2-los
> > 104:          0   sx1503q  13 Edge      sff3-los
> >
> > The sffX indicates the SFP the loss of signal GPIO is associated with.
> >
> > Signed-off-by: Chris Healy <cphealy@gmail.com>
>
> This doesn't work in all cases.
>
> > ---
> >  drivers/net/phy/sfp.c | 6 +++++-
> >  1 file changed, 5 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c
> > index 73c2969f11a4..9b03c7229320 100644
> > --- a/drivers/net/phy/sfp.c
> > +++ b/drivers/net/phy/sfp.c
> > @@ -220,6 +220,7 @@ struct sfp {
> >      struct phy_device *mod_phy;
> >      const struct sff_data *type;
> >      u32 max_power_mW;
> > +    char sfp_irq_name[32];
> >
> >      unsigned int (*get_state)(struct sfp *);
> >      void (*set_state)(struct sfp *, unsigned int);
> > @@ -2349,12 +2350,15 @@ static int sfp_probe(struct platform_device *pdev)
> >              continue;
> >          }
> >
> > +        snprintf(sfp->sfp_irq_name, sizeof(sfp->sfp_irq_name),
> > +             "%s-%s", dev_name(sfp->dev), gpio_of_names[i]);
>
> sfp_irq_name will be overwritten for each GPIO IRQ claimed, which means
> all IRQs for a particular cage will end up with the same name.
> sfp_irq_name[] therefore needs to be an array of names, one per input.

Good point.  I'll add the necessary support to deal with this case and
test on my side with a hacked up devicetree file providing some
additional GPIOs and include this in the next version of the patch.

>
> Thanks.
>
> --
> RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
> FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!

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

end of thread, other threads:[~2020-07-06 23:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-06 19:38 [PATCH] net: sfp: Unique GPIO interrupt names Chris Healy
2020-07-06 20:07 ` Andrew Lunn
2020-07-06 23:03   ` Chris Healy
2020-07-06 20:42 ` Russell King - ARM Linux admin
2020-07-06 23:04   ` Chris Healy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).