aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/of
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2014-06-12 17:27:40 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-06-12 17:27:40 -0400
commitf9da455b93f6ba076935b4ef4589f61e529ae046 (patch)
tree3c4e69ce1ba1d6bf65915b97a76ca2172105b278 /drivers/of
parent0e04c641b199435f3779454055f6a7de258ecdfc (diff)
parente5eca6d41f53db48edd8cf88a3f59d2c30227f8e (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next
Pull networking updates from David Miller: 1) Seccomp BPF filters can now be JIT'd, from Alexei Starovoitov. 2) Multiqueue support in xen-netback and xen-netfront, from Andrew J Benniston. 3) Allow tweaking of aggregation settings in cdc_ncm driver, from Bjørn Mork. 4) BPF now has a "random" opcode, from Chema Gonzalez. 5) Add more BPF documentation and improve test framework, from Daniel Borkmann. 6) Support TCP fastopen over ipv6, from Daniel Lee. 7) Add software TSO helper functions and use them to support software TSO in mvneta and mv643xx_eth drivers. From Ezequiel Garcia. 8) Support software TSO in fec driver too, from Nimrod Andy. 9) Add Broadcom SYSTEMPORT driver, from Florian Fainelli. 10) Handle broadcasts more gracefully over macvlan when there are large numbers of interfaces configured, from Herbert Xu. 11) Allow more control over fwmark used for non-socket based responses, from Lorenzo Colitti. 12) Do TCP congestion window limiting based upon measurements, from Neal Cardwell. 13) Support busy polling in SCTP, from Neal Horman. 14) Allow RSS key to be configured via ethtool, from Venkata Duvvuru. 15) Bridge promisc mode handling improvements from Vlad Yasevich. 16) Don't use inetpeer entries to implement ID generation any more, it performs poorly, from Eric Dumazet. * git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next: (1522 commits) rtnetlink: fix userspace API breakage for iproute2 < v3.9.0 tcp: fixing TLP's FIN recovery net: fec: Add software TSO support net: fec: Add Scatter/gather support net: fec: Increase buffer descriptor entry number net: fec: Factorize feature setting net: fec: Enable IP header hardware checksum net: fec: Factorize the .xmit transmit function bridge: fix compile error when compiling without IPv6 support bridge: fix smatch warning / potential null pointer dereference via-rhine: fix full-duplex with autoneg disable bnx2x: Enlarge the dorq threshold for VFs bnx2x: Check for UNDI in uncommon branch bnx2x: Fix 1G-baseT link bnx2x: Fix link for KR with swapped polarity lane sctp: Fix sk_ack_backlog wrap-around problem net/core: Add VF link state control policy net/fsl: xgmac_mdio is dependent on OF_MDIO net/fsl: Make xgmac_mdio read error message useful net_sched: drr: warn when qdisc is not work conserving ...
Diffstat (limited to 'drivers/of')
-rw-r--r--drivers/of/of_mdio.c206
1 files changed, 126 insertions, 80 deletions
diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c
index 9a95831bd065..fb4a59830648 100644
--- a/drivers/of/of_mdio.c
+++ b/drivers/of/of_mdio.c
@@ -14,6 +14,7 @@
14#include <linux/netdevice.h> 14#include <linux/netdevice.h>
15#include <linux/err.h> 15#include <linux/err.h>
16#include <linux/phy.h> 16#include <linux/phy.h>
17#include <linux/phy_fixed.h>
17#include <linux/of.h> 18#include <linux/of.h>
18#include <linux/of_irq.h> 19#include <linux/of_irq.h>
19#include <linux/of_mdio.h> 20#include <linux/of_mdio.h>
@@ -22,27 +23,6 @@
22MODULE_AUTHOR("Grant Likely <grant.likely@secretlab.ca>"); 23MODULE_AUTHOR("Grant Likely <grant.likely@secretlab.ca>");
23MODULE_LICENSE("GPL"); 24MODULE_LICENSE("GPL");
24 25
25static void of_set_phy_supported(struct phy_device *phydev, u32 max_speed)
26{
27 /* The default values for phydev->supported are provided by the PHY
28 * driver "features" member, we want to reset to sane defaults fist
29 * before supporting higher speeds.
30 */
31 phydev->supported &= PHY_DEFAULT_FEATURES;
32
33 switch (max_speed) {
34 default:
35 return;
36
37 case SPEED_1000:
38 phydev->supported |= PHY_1000BT_FEATURES;
39 case SPEED_100:
40 phydev->supported |= PHY_100BT_FEATURES;
41 case SPEED_10:
42 phydev->supported |= PHY_10BT_FEATURES;
43 }
44}
45
46/* Extract the clause 22 phy ID from the compatible string of the form 26/* Extract the clause 22 phy ID from the compatible string of the form
47 * ethernet-phy-idAAAA.BBBB */ 27 * ethernet-phy-idAAAA.BBBB */
48static int of_get_phy_id(struct device_node *device, u32 *phy_id) 28static int of_get_phy_id(struct device_node *device, u32 *phy_id)
@@ -66,7 +46,6 @@ static int of_mdiobus_register_phy(struct mii_bus *mdio, struct device_node *chi
66 struct phy_device *phy; 46 struct phy_device *phy;
67 bool is_c45; 47 bool is_c45;
68 int rc; 48 int rc;
69 u32 max_speed = 0;
70 u32 phy_id; 49 u32 phy_id;
71 50
72 is_c45 = of_device_is_compatible(child, 51 is_c45 = of_device_is_compatible(child,
@@ -103,17 +82,33 @@ static int of_mdiobus_register_phy(struct mii_bus *mdio, struct device_node *chi
103 return 1; 82 return 1;
104 } 83 }
105 84
106 /* Set phydev->supported based on the "max-speed" property
107 * if present */
108 if (!of_property_read_u32(child, "max-speed", &max_speed))
109 of_set_phy_supported(phy, max_speed);
110
111 dev_dbg(&mdio->dev, "registered phy %s at address %i\n", 85 dev_dbg(&mdio->dev, "registered phy %s at address %i\n",
112 child->name, addr); 86 child->name, addr);
113 87
114 return 0; 88 return 0;
115} 89}
116 90
91static int of_mdio_parse_addr(struct device *dev, const struct device_node *np)
92{
93 u32 addr;
94 int ret;
95
96 ret = of_property_read_u32(np, "reg", &addr);
97 if (ret < 0) {
98 dev_err(dev, "%s has invalid PHY address\n", np->full_name);
99 return ret;
100 }
101
102 /* A PHY must have a reg property in the range [0-31] */
103 if (addr >= PHY_MAX_ADDR) {
104 dev_err(dev, "%s PHY address %i is too large\n",
105 np->full_name, addr);
106 return -EINVAL;
107 }
108
109 return addr;
110}
111
117/** 112/**
118 * of_mdiobus_register - Register mii_bus and create PHYs from the device tree 113 * of_mdiobus_register - Register mii_bus and create PHYs from the device tree
119 * @mdio: pointer to mii_bus structure 114 * @mdio: pointer to mii_bus structure
@@ -126,9 +121,8 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
126{ 121{
127 struct device_node *child; 122 struct device_node *child;
128 const __be32 *paddr; 123 const __be32 *paddr;
129 u32 addr;
130 bool scanphys = false; 124 bool scanphys = false;
131 int rc, i, len; 125 int addr, rc, i;
132 126
133 /* Mask out all PHYs from auto probing. Instead the PHYs listed in 127 /* Mask out all PHYs from auto probing. Instead the PHYs listed in
134 * the device tree are populated after the bus has been registered */ 128 * the device tree are populated after the bus has been registered */
@@ -148,19 +142,9 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
148 142
149 /* Loop over the child nodes and register a phy_device for each one */ 143 /* Loop over the child nodes and register a phy_device for each one */
150 for_each_available_child_of_node(np, child) { 144 for_each_available_child_of_node(np, child) {
151 /* A PHY must have a reg property in the range [0-31] */ 145 addr = of_mdio_parse_addr(&mdio->dev, child);
152 paddr = of_get_property(child, "reg", &len); 146 if (addr < 0) {
153 if (!paddr || len < sizeof(*paddr)) {
154 scanphys = true; 147 scanphys = true;
155 dev_err(&mdio->dev, "%s has invalid PHY address\n",
156 child->full_name);
157 continue;
158 }
159
160 addr = be32_to_cpup(paddr);
161 if (addr >= PHY_MAX_ADDR) {
162 dev_err(&mdio->dev, "%s PHY address %i is too large\n",
163 child->full_name, addr);
164 continue; 148 continue;
165 } 149 }
166 150
@@ -175,7 +159,7 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
175 /* auto scan for PHYs with empty reg property */ 159 /* auto scan for PHYs with empty reg property */
176 for_each_available_child_of_node(np, child) { 160 for_each_available_child_of_node(np, child) {
177 /* Skip PHYs with reg property set */ 161 /* Skip PHYs with reg property set */
178 paddr = of_get_property(child, "reg", &len); 162 paddr = of_get_property(child, "reg", NULL);
179 if (paddr) 163 if (paddr)
180 continue; 164 continue;
181 165
@@ -198,6 +182,40 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
198} 182}
199EXPORT_SYMBOL(of_mdiobus_register); 183EXPORT_SYMBOL(of_mdiobus_register);
200 184
185/**
186 * of_mdiobus_link_phydev - Find a device node for a phy
187 * @mdio: pointer to mii_bus structure
188 * @phydev: phydev for which the of_node pointer should be set
189 *
190 * Walk the list of subnodes of a mdio bus and look for a node that matches the
191 * phy's address with its 'reg' property. If found, set the of_node pointer for
192 * the phy. This allows auto-probed pyh devices to be supplied with information
193 * passed in via DT.
194 */
195void of_mdiobus_link_phydev(struct mii_bus *mdio,
196 struct phy_device *phydev)
197{
198 struct device *dev = &phydev->dev;
199 struct device_node *child;
200
201 if (dev->of_node || !mdio->dev.of_node)
202 return;
203
204 for_each_available_child_of_node(mdio->dev.of_node, child) {
205 int addr;
206
207 addr = of_mdio_parse_addr(&mdio->dev, child);
208 if (addr < 0)
209 continue;
210
211 if (addr == phydev->addr) {
212 dev->of_node = child;
213 return;
214 }
215 }
216}
217EXPORT_SYMBOL(of_mdiobus_link_phydev);
218
201/* Helper function for of_phy_find_device */ 219/* Helper function for of_phy_find_device */
202static int of_phy_match(struct device *dev, void *phy_np) 220static int of_phy_match(struct device *dev, void *phy_np)
203{ 221{
@@ -245,44 +263,6 @@ struct phy_device *of_phy_connect(struct net_device *dev,
245EXPORT_SYMBOL(of_phy_connect); 263EXPORT_SYMBOL(of_phy_connect);
246 264
247/** 265/**
248 * of_phy_connect_fixed_link - Parse fixed-link property and return a dummy phy
249 * @dev: pointer to net_device claiming the phy
250 * @hndlr: Link state callback for the network device
251 * @iface: PHY data interface type
252 *
253 * This function is a temporary stop-gap and will be removed soon. It is
254 * only to support the fs_enet, ucc_geth and gianfar Ethernet drivers. Do
255 * not call this function from new drivers.
256 */
257struct phy_device *of_phy_connect_fixed_link(struct net_device *dev,
258 void (*hndlr)(struct net_device *),
259 phy_interface_t iface)
260{
261 struct device_node *net_np;
262 char bus_id[MII_BUS_ID_SIZE + 3];
263 struct phy_device *phy;
264 const __be32 *phy_id;
265 int sz;
266
267 if (!dev->dev.parent)
268 return NULL;
269
270 net_np = dev->dev.parent->of_node;
271 if (!net_np)
272 return NULL;
273
274 phy_id = of_get_property(net_np, "fixed-link", &sz);
275 if (!phy_id || sz < sizeof(*phy_id))
276 return NULL;
277
278 sprintf(bus_id, PHY_ID_FMT, "fixed-0", be32_to_cpu(phy_id[0]));
279
280 phy = phy_connect(dev, bus_id, hndlr, iface);
281 return IS_ERR(phy) ? NULL : phy;
282}
283EXPORT_SYMBOL(of_phy_connect_fixed_link);
284
285/**
286 * of_phy_attach - Attach to a PHY without starting the state machine 266 * of_phy_attach - Attach to a PHY without starting the state machine
287 * @dev: pointer to net_device claiming the phy 267 * @dev: pointer to net_device claiming the phy
288 * @phy_np: Node pointer for the PHY 268 * @phy_np: Node pointer for the PHY
@@ -301,3 +281,69 @@ struct phy_device *of_phy_attach(struct net_device *dev,
301 return phy_attach_direct(dev, phy, flags, iface) ? NULL : phy; 281 return phy_attach_direct(dev, phy, flags, iface) ? NULL : phy;
302} 282}
303EXPORT_SYMBOL(of_phy_attach); 283EXPORT_SYMBOL(of_phy_attach);
284
285#if defined(CONFIG_FIXED_PHY)
286/*
287 * of_phy_is_fixed_link() and of_phy_register_fixed_link() must
288 * support two DT bindings:
289 * - the old DT binding, where 'fixed-link' was a property with 5
290 * cells encoding various informations about the fixed PHY
291 * - the new DT binding, where 'fixed-link' is a sub-node of the
292 * Ethernet device.
293 */
294bool of_phy_is_fixed_link(struct device_node *np)
295{
296 struct device_node *dn;
297 int len;
298
299 /* New binding */
300 dn = of_get_child_by_name(np, "fixed-link");
301 if (dn) {
302 of_node_put(dn);
303 return true;
304 }
305
306 /* Old binding */
307 if (of_get_property(np, "fixed-link", &len) &&
308 len == (5 * sizeof(__be32)))
309 return true;
310
311 return false;
312}
313EXPORT_SYMBOL(of_phy_is_fixed_link);
314
315int of_phy_register_fixed_link(struct device_node *np)
316{
317 struct fixed_phy_status status = {};
318 struct device_node *fixed_link_node;
319 const __be32 *fixed_link_prop;
320 int len;
321
322 /* New binding */
323 fixed_link_node = of_get_child_by_name(np, "fixed-link");
324 if (fixed_link_node) {
325 status.link = 1;
326 status.duplex = of_property_read_bool(np, "full-duplex");
327 if (of_property_read_u32(fixed_link_node, "speed", &status.speed))
328 return -EINVAL;
329 status.pause = of_property_read_bool(np, "pause");
330 status.asym_pause = of_property_read_bool(np, "asym-pause");
331 of_node_put(fixed_link_node);
332 return fixed_phy_register(PHY_POLL, &status, np);
333 }
334
335 /* Old binding */
336 fixed_link_prop = of_get_property(np, "fixed-link", &len);
337 if (fixed_link_prop && len == (5 * sizeof(__be32))) {
338 status.link = 1;
339 status.duplex = be32_to_cpu(fixed_link_prop[1]);
340 status.speed = be32_to_cpu(fixed_link_prop[2]);
341 status.pause = be32_to_cpu(fixed_link_prop[3]);
342 status.asym_pause = be32_to_cpu(fixed_link_prop[4]);
343 return fixed_phy_register(PHY_POLL, &status, np);
344 }
345
346 return -ENODEV;
347}
348EXPORT_SYMBOL(of_phy_register_fixed_link);
349#endif