1 From 0a0c4b3dd4f34df4532f254a5940b520015d766f Mon Sep 17 00:00:00 2001
2 From: Russell King <rmk+kernel@arm.linux.org.uk>
3 Date: Thu, 24 Sep 2015 11:01:13 +0100
4 Subject: [PATCH 719/744] phylink: add hooks for SFP support
6 Add support to phylink for SFP, which needs to control and configure
7 the ethernet MAC link state. Specifically, SFP needs to:
9 1. set the negotiation mode between SGMII and 1000base-X
10 2. attach and detach the module PHY
11 3. prevent the link coming up when errors are reported
13 In the absence of a PHY, we also need to set the ethtool port type
14 according to the module plugged in.
16 Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
17 Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
19 drivers/net/phy/phylink.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++
20 include/linux/phylink.h | 6 ++++
21 2 files changed, 88 insertions(+)
23 --- a/drivers/net/phy/phylink.c
24 +++ b/drivers/net/phy/phylink.c
26 #include <linux/ethtool.h>
27 #include <linux/export.h>
28 #include <linux/gpio/consumer.h>
29 +#include <linux/list.h>
30 #include <linux/netdevice.h>
32 #include <linux/of_mdio.h>
34 (ADVERTISED_TP | ADVERTISED_MII | ADVERTISED_FIBRE | \
35 ADVERTISED_BNC | ADVERTISED_AUI | ADVERTISED_Backplane)
37 +static LIST_HEAD(phylinks);
38 +static DEFINE_MUTEX(phylink_mutex);
41 PHYLINK_DISABLE_STOPPED,
42 + PHYLINK_DISABLE_LINK,
46 + struct list_head node;
47 struct net_device *netdev;
48 const struct phylink_mac_ops *ops;
49 struct mutex config_mutex;
50 @@ -341,12 +347,20 @@ struct phylink *phylink_create(struct ne
54 + mutex_lock(&phylink_mutex);
55 + list_add_tail(&pl->node, &phylinks);
56 + mutex_unlock(&phylink_mutex);
60 EXPORT_SYMBOL_GPL(phylink_create);
62 void phylink_destroy(struct phylink *pl)
64 + mutex_lock(&phylink_mutex);
65 + list_del(&pl->node);
66 + mutex_unlock(&phylink_mutex);
68 cancel_work_sync(&pl->resolve);
71 @@ -813,4 +827,72 @@ int phylink_mii_ioctl(struct phylink *pl
73 EXPORT_SYMBOL_GPL(phylink_mii_ioctl);
77 +void phylink_disable(struct phylink *pl)
79 + set_bit(PHYLINK_DISABLE_LINK, &pl->phylink_disable_state);
80 + flush_work(&pl->resolve);
82 + netif_carrier_off(pl->netdev);
84 +EXPORT_SYMBOL_GPL(phylink_disable);
86 +void phylink_enable(struct phylink *pl)
88 + clear_bit(PHYLINK_DISABLE_LINK, &pl->phylink_disable_state);
89 + phylink_run_resolve(pl);
91 +EXPORT_SYMBOL_GPL(phylink_enable);
93 +void phylink_set_link_port(struct phylink *pl, u32 support, u8 port)
95 + WARN_ON(support & ~SUPPORTED_INTERFACES);
97 + mutex_lock(&pl->config_mutex);
98 + pl->link_port_support = support;
99 + pl->link_port = port;
100 + mutex_unlock(&pl->config_mutex);
102 +EXPORT_SYMBOL_GPL(phylink_set_link_port);
104 +int phylink_set_link_an_mode(struct phylink *pl, unsigned int mode)
108 + mutex_lock(&pl->config_mutex);
109 + if (pl->link_an_mode != mode) {
110 + ret = phylink_get_support(pl, mode);
112 + if (!test_bit(PHYLINK_DISABLE_STOPPED,
113 + &pl->phylink_disable_state))
114 + phylink_mac_config(pl, &pl->link_config);
116 + netdev_info(pl->netdev, "switched to %s link mode\n",
117 + phylink_an_mode_str(mode));
120 + mutex_unlock(&pl->config_mutex);
124 +EXPORT_SYMBOL_GPL(phylink_set_link_an_mode);
126 +struct phylink *phylink_lookup_by_netdev(struct net_device *ndev)
128 + struct phylink *pl, *found = NULL;
130 + mutex_lock(&phylink_mutex);
131 + list_for_each_entry(pl, &phylinks, node)
132 + if (pl->netdev == ndev) {
137 + mutex_unlock(&phylink_mutex);
141 +EXPORT_SYMBOL_GPL(phylink_lookup_by_netdev);
143 MODULE_LICENSE("GPL");
144 --- a/include/linux/phylink.h
145 +++ b/include/linux/phylink.h
146 @@ -67,4 +67,10 @@ int phylink_ethtool_get_settings(struct
147 int phylink_ethtool_set_settings(struct phylink *, struct ethtool_cmd *);
148 int phylink_mii_ioctl(struct phylink *, struct ifreq *, int);
150 +void phylink_set_link_port(struct phylink *pl, u32 support, u8 port);
151 +int phylink_set_link_an_mode(struct phylink *pl, unsigned int mode);
152 +void phylink_disable(struct phylink *pl);
153 +void phylink_enable(struct phylink *pl);
154 +struct phylink *phylink_lookup_by_netdev(struct net_device *ndev);