All of lore.kernel.org
 help / color / mirror / Atom feed
From: Russell King <rmk+kernel@armlinux.org.uk>
To: "David S. Miller" <davem@davemloft.net>
Cc: Andrew Lunn <andrew@lunn.ch>,
	Florian Fainelli <f.fainelli@gmail.com>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	netdev@vger.kernel.org
Subject: [PATCH net-next 2/5] net: phylink: support for link gpio interrupt
Date: Tue, 28 May 2019 10:57:23 +0100	[thread overview]
Message-ID: <E1hVYrD-0005Z1-L0@rmk-PC.armlinux.org.uk> (raw)
In-Reply-To: <20190528095639.kqalmvffsmc5ebs7@shell.armlinux.org.uk>

Add support for using GPIO interrupts with a fixed-link GPIO rather than
polling the GPIO every second and invoking the phylink resolution.  This
avoids unnecessary calls to mac_config().

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
---
 drivers/net/phy/phylink.c | 36 ++++++++++++++++++++++++++++++++----
 1 file changed, 32 insertions(+), 4 deletions(-)

diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index 219a061572d2..00cd0ed7ff3d 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -56,6 +56,7 @@ struct phylink {
 	phy_interface_t cur_interface;
 
 	struct gpio_desc *link_gpio;
+	unsigned int link_irq;
 	struct timer_list link_poll;
 	void (*get_fixed_state)(struct net_device *dev,
 				struct phylink_link_state *s);
@@ -612,7 +613,7 @@ void phylink_destroy(struct phylink *pl)
 {
 	if (pl->sfp_bus)
 		sfp_unregister_upstream(pl->sfp_bus);
-	if (!IS_ERR_OR_NULL(pl->link_gpio))
+	if (pl->link_gpio)
 		gpiod_put(pl->link_gpio);
 
 	cancel_work_sync(&pl->resolve);
@@ -875,6 +876,15 @@ void phylink_mac_change(struct phylink *pl, bool up)
 }
 EXPORT_SYMBOL_GPL(phylink_mac_change);
 
+static irqreturn_t phylink_link_handler(int irq, void *data)
+{
+	struct phylink *pl = data;
+
+	phylink_run_resolve(pl);
+
+	return IRQ_HANDLED;
+}
+
 /**
  * phylink_start() - start a phylink instance
  * @pl: a pointer to a &struct phylink returned from phylink_create()
@@ -910,7 +920,22 @@ void phylink_start(struct phylink *pl)
 	clear_bit(PHYLINK_DISABLE_STOPPED, &pl->phylink_disable_state);
 	phylink_run_resolve(pl);
 
-	if (pl->link_an_mode == MLO_AN_FIXED && !IS_ERR(pl->link_gpio))
+	if (pl->link_an_mode == MLO_AN_FIXED && pl->link_gpio) {
+		int irq = gpiod_to_irq(pl->link_gpio);
+
+		if (irq > 0) {
+			if (!request_irq(irq, phylink_link_handler,
+					 IRQF_TRIGGER_RISING |
+					 IRQF_TRIGGER_FALLING,
+					 "netdev link", pl))
+				pl->link_irq = irq;
+			else
+				irq = 0;
+		}
+		if (irq <= 0)
+			mod_timer(&pl->link_poll, jiffies + HZ);
+	}
+	if (pl->link_an_mode == MLO_AN_FIXED && pl->get_fixed_state)
 		mod_timer(&pl->link_poll, jiffies + HZ);
 	if (pl->sfp_bus)
 		sfp_upstream_start(pl->sfp_bus);
@@ -936,8 +961,11 @@ void phylink_stop(struct phylink *pl)
 		phy_stop(pl->phydev);
 	if (pl->sfp_bus)
 		sfp_upstream_stop(pl->sfp_bus);
-	if (pl->link_an_mode == MLO_AN_FIXED && !IS_ERR(pl->link_gpio))
-		del_timer_sync(&pl->link_poll);
+	del_timer_sync(&pl->link_poll);
+	if (pl->link_irq) {
+		free_irq(pl->link_irq, pl);
+		pl->link_irq = 0;
+	}
 
 	phylink_run_resolve_and_disable(pl, PHYLINK_DISABLE_STOPPED);
 }
-- 
2.7.4


  parent reply	other threads:[~2019-05-28  9:57 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-20 15:21 [PATCH net-next 0/4] phylink/sfp updates Russell King - ARM Linux admin
2019-05-20 15:22 ` [PATCH net-next 1/4] net: phylink: support for link gpio interrupt Russell King
2019-05-20 18:22   ` Florian Fainelli
2019-05-20 18:31     ` Russell King - ARM Linux admin
2019-05-20 15:22 ` [PATCH net-next 2/4] net: phy: allow Clause 45 access via mii ioctl Russell King
2019-05-20 18:23   ` Florian Fainelli
2019-05-20 15:22 ` [PATCH net-next 3/4] net: sfp: add mandatory attach/detach methods for sfp buses Russell King
2019-05-20 18:24   ` Florian Fainelli
2019-05-20 15:22 ` [PATCH net-next 4/4] net: sfp: remove sfp-bus use of netdevs Russell King
2019-05-20 18:25   ` Florian Fainelli
2019-05-20 15:40 ` [PATCH net-next 0/4] phylink/sfp updates Vladimir Oltean
2019-05-22 17:34 ` David Miller
2019-05-28  9:56 ` [PATCH net-next 0/5] " Russell King - ARM Linux admin
2019-05-28  9:57   ` [PATCH net-next 1/5] net: phylink: remove netdev from phylink mii ioctl emulation Russell King
2019-05-28 15:19     ` Andrew Lunn
2019-05-28  9:57   ` Russell King [this message]
2019-05-28 10:02     ` [PATCH net-next 2/5] net: phylink: support for link gpio interrupt Russell King - ARM Linux admin
2019-05-29 21:21       ` David Miller
2019-05-28  9:57   ` [PATCH net-next 3/5] net: phy: allow Clause 45 access via mii ioctl Russell King
2019-05-28 12:54     ` Vladimir Oltean
2019-05-28 13:27       ` Russell King - ARM Linux admin
2019-05-28 15:31         ` Andrew Lunn
2019-05-28  9:57   ` [PATCH net-next 4/5] net: sfp: add mandatory attach/detach methods for sfp buses Russell King
2019-05-28 15:21     ` Andrew Lunn
2019-05-28  9:57   ` [PATCH net-next 5/5] net: sfp: remove sfp-bus use of netdevs Russell King
2019-05-28 15:21     ` Andrew Lunn
2019-05-31 19:39   ` [PATCH net-next 0/5] phylink/sfp updates David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E1hVYrD-0005Z1-L0@rmk-PC.armlinux.org.uk \
    --to=rmk+kernel@armlinux.org.uk \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=f.fainelli@gmail.com \
    --cc=hkallweit1@gmail.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.