tools: mkimage: provide dtc path during build
[openwrt/staging/wigyori.git] / target / linux / mvebu / patches-4.4 / 131-phylink-add-hooks-for-SFP-support.patch
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
5
6 Add support to phylink for SFP, which needs to control and configure
7 the ethernet MAC link state. Specifically, SFP needs to:
8
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
12
13 In the absence of a PHY, we also need to set the ethtool port type
14 according to the module plugged in.
15
16 Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
17 Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
18 ---
19 drivers/net/phy/phylink.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++
20 include/linux/phylink.h | 6 ++++
21 2 files changed, 88 insertions(+)
22
23 --- a/drivers/net/phy/phylink.c
24 +++ b/drivers/net/phy/phylink.c
25 @@ -11,6 +11,7 @@
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>
31 #include <linux/of.h>
32 #include <linux/of_mdio.h>
33 @@ -29,11 +30,16 @@
34 (ADVERTISED_TP | ADVERTISED_MII | ADVERTISED_FIBRE | \
35 ADVERTISED_BNC | ADVERTISED_AUI | ADVERTISED_Backplane)
36
37 +static LIST_HEAD(phylinks);
38 +static DEFINE_MUTEX(phylink_mutex);
39 +
40 enum {
41 PHYLINK_DISABLE_STOPPED,
42 + PHYLINK_DISABLE_LINK,
43 };
44
45 struct phylink {
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
51 return ERR_PTR(ret);
52 }
53
54 + mutex_lock(&phylink_mutex);
55 + list_add_tail(&pl->node, &phylinks);
56 + mutex_unlock(&phylink_mutex);
57 +
58 return pl;
59 }
60 EXPORT_SYMBOL_GPL(phylink_create);
61
62 void phylink_destroy(struct phylink *pl)
63 {
64 + mutex_lock(&phylink_mutex);
65 + list_del(&pl->node);
66 + mutex_unlock(&phylink_mutex);
67 +
68 cancel_work_sync(&pl->resolve);
69 kfree(pl);
70 }
71 @@ -813,4 +827,72 @@ int phylink_mii_ioctl(struct phylink *pl
72 }
73 EXPORT_SYMBOL_GPL(phylink_mii_ioctl);
74
75 +
76 +
77 +void phylink_disable(struct phylink *pl)
78 +{
79 + set_bit(PHYLINK_DISABLE_LINK, &pl->phylink_disable_state);
80 + flush_work(&pl->resolve);
81 +
82 + netif_carrier_off(pl->netdev);
83 +}
84 +EXPORT_SYMBOL_GPL(phylink_disable);
85 +
86 +void phylink_enable(struct phylink *pl)
87 +{
88 + clear_bit(PHYLINK_DISABLE_LINK, &pl->phylink_disable_state);
89 + phylink_run_resolve(pl);
90 +}
91 +EXPORT_SYMBOL_GPL(phylink_enable);
92 +
93 +void phylink_set_link_port(struct phylink *pl, u32 support, u8 port)
94 +{
95 + WARN_ON(support & ~SUPPORTED_INTERFACES);
96 +
97 + mutex_lock(&pl->config_mutex);
98 + pl->link_port_support = support;
99 + pl->link_port = port;
100 + mutex_unlock(&pl->config_mutex);
101 +}
102 +EXPORT_SYMBOL_GPL(phylink_set_link_port);
103 +
104 +int phylink_set_link_an_mode(struct phylink *pl, unsigned int mode)
105 +{
106 + int ret = 0;
107 +
108 + mutex_lock(&pl->config_mutex);
109 + if (pl->link_an_mode != mode) {
110 + ret = phylink_get_support(pl, mode);
111 + if (ret == 0) {
112 + if (!test_bit(PHYLINK_DISABLE_STOPPED,
113 + &pl->phylink_disable_state))
114 + phylink_mac_config(pl, &pl->link_config);
115 +
116 + netdev_info(pl->netdev, "switched to %s link mode\n",
117 + phylink_an_mode_str(mode));
118 + }
119 + }
120 + mutex_unlock(&pl->config_mutex);
121 +
122 + return ret;
123 +}
124 +EXPORT_SYMBOL_GPL(phylink_set_link_an_mode);
125 +
126 +struct phylink *phylink_lookup_by_netdev(struct net_device *ndev)
127 +{
128 + struct phylink *pl, *found = NULL;
129 +
130 + mutex_lock(&phylink_mutex);
131 + list_for_each_entry(pl, &phylinks, node)
132 + if (pl->netdev == ndev) {
133 + found = pl;
134 + break;
135 + }
136 +
137 + mutex_unlock(&phylink_mutex);
138 +
139 + return found;
140 +}
141 +EXPORT_SYMBOL_GPL(phylink_lookup_by_netdev);
142 +
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);
149
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);
155 +
156 #endif