1 From cba0aba37d2228556e0d1f776d403435868cdbfa Mon Sep 17 00:00:00 2001
2 From: Russell King <rmk+kernel@armlinux.org.uk>
3 Date: Tue, 28 May 2019 10:57:23 +0100
4 Subject: [PATCH 607/660] net: phylink: support for link gpio interrupt
6 Add support for using GPIO interrupts with a fixed-link GPIO rather than
7 polling the GPIO every second and invoking the phylink resolution. This
8 avoids unnecessary calls to mac_config().
10 Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
11 Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
12 Signed-off-by: David S. Miller <davem@davemloft.net>
13 Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
15 drivers/net/phy/phylink.c | 36 ++++++++++++++++++++++++++++++++----
16 1 file changed, 32 insertions(+), 4 deletions(-)
18 --- a/drivers/net/phy/phylink.c
19 +++ b/drivers/net/phy/phylink.c
20 @@ -59,6 +59,7 @@ struct phylink {
21 phy_interface_t cur_interface;
23 struct gpio_desc *link_gpio;
24 + unsigned int link_irq;
25 struct timer_list link_poll;
26 void (*get_fixed_state)(struct net_device *dev,
27 struct phylink_link_state *s);
28 @@ -645,7 +646,7 @@ void phylink_destroy(struct phylink *pl)
31 sfp_unregister_upstream(pl->sfp_bus);
32 - if (!IS_ERR_OR_NULL(pl->link_gpio))
34 gpiod_put(pl->link_gpio);
36 cancel_work_sync(&pl->resolve);
37 @@ -912,6 +913,15 @@ void phylink_mac_change(struct phylink *
39 EXPORT_SYMBOL_GPL(phylink_mac_change);
41 +static irqreturn_t phylink_link_handler(int irq, void *data)
43 + struct phylink *pl = data;
45 + phylink_run_resolve(pl);
51 * phylink_start() - start a phylink instance
52 * @pl: a pointer to a &struct phylink returned from phylink_create()
53 @@ -947,7 +957,22 @@ void phylink_start(struct phylink *pl)
54 clear_bit(PHYLINK_DISABLE_STOPPED, &pl->phylink_disable_state);
55 phylink_run_resolve(pl);
57 - if (pl->link_an_mode == MLO_AN_FIXED && !IS_ERR(pl->link_gpio))
58 + if (pl->link_an_mode == MLO_AN_FIXED && pl->link_gpio) {
59 + int irq = gpiod_to_irq(pl->link_gpio);
62 + if (!request_irq(irq, phylink_link_handler,
63 + IRQF_TRIGGER_RISING |
64 + IRQF_TRIGGER_FALLING,
71 + mod_timer(&pl->link_poll, jiffies + HZ);
73 + if (pl->link_an_mode == MLO_AN_FIXED && pl->get_fixed_state)
74 mod_timer(&pl->link_poll, jiffies + HZ);
76 sfp_upstream_start(pl->sfp_bus);
77 @@ -973,8 +998,11 @@ void phylink_stop(struct phylink *pl)
80 sfp_upstream_stop(pl->sfp_bus);
81 - if (pl->link_an_mode == MLO_AN_FIXED && !IS_ERR(pl->link_gpio))
82 - del_timer_sync(&pl->link_poll);
83 + del_timer_sync(&pl->link_poll);
85 + free_irq(pl->link_irq, pl);
89 phylink_run_resolve_and_disable(pl, PHYLINK_DISABLE_STOPPED);