1 From 4054955f0da08c81d42220cb445820d474f1ac92 Mon Sep 17 00:00:00 2001
2 From: Russell King <rmk+kernel@armlinux.org.uk>
3 Date: Sat, 14 Sep 2019 14:21:22 +0100
4 Subject: [PATCH 614/660] net: sfp: move fwnode parsing into sfp-bus layer
6 Rather than parsing the sfp firmware node in phylink, parse it in the
7 sfp-bus code, so we can re-use this code for PHYs without having to
10 Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
12 drivers/net/phy/phylink.c | 21 ++++---------
13 drivers/net/phy/sfp-bus.c | 65 +++++++++++++++++++++++++--------------
14 include/linux/sfp.h | 10 +++---
15 3 files changed, 53 insertions(+), 43 deletions(-)
17 --- a/drivers/net/phy/phylink.c
18 +++ b/drivers/net/phy/phylink.c
19 @@ -565,26 +565,17 @@ static const struct sfp_upstream_ops sfp
20 static int phylink_register_sfp(struct phylink *pl,
21 struct fwnode_handle *fwnode)
23 - struct fwnode_reference_args ref;
24 + struct sfp_bus *bus;
30 - ret = fwnode_property_get_reference_args(fwnode, "sfp", NULL,
36 - phylink_err(pl, "unable to parse \"sfp\" node: %d\n",
38 + bus = sfp_register_upstream_node(fwnode, pl, &sfp_phylink_ops);
41 + phylink_err(pl, "unable to attach SFP bus: %d\n", ret);
45 - pl->sfp_bus = sfp_register_upstream(ref.fwnode, pl, &sfp_phylink_ops);
52 --- a/drivers/net/phy/sfp-bus.c
53 +++ b/drivers/net/phy/sfp-bus.c
55 #include <linux/list.h>
56 #include <linux/mutex.h>
57 #include <linux/phylink.h>
58 +#include <linux/property.h>
59 #include <linux/rtnetlink.h>
60 #include <linux/slab.h>
62 @@ -445,45 +446,63 @@ static void sfp_upstream_clear(struct sf
66 - * sfp_register_upstream() - Register the neighbouring device
67 - * @fwnode: firmware node for the SFP bus
68 + * sfp_register_upstream_node() - parse and register the neighbouring device
69 + * @fwnode: firmware node for the parent device (MAC or PHY)
70 * @upstream: the upstream private data
71 * @ops: the upstream's &struct sfp_upstream_ops
73 - * Register the upstream device (eg, PHY) with the SFP bus. MAC drivers
74 - * should use phylink, which will call this function for them. Returns
75 - * a pointer to the allocated &struct sfp_bus.
76 + * Parse the parent device's firmware node for a SFP bus, and register the
77 + * SFP bus using sfp_register_upstream().
79 - * On error, returns %NULL.
80 + * Returns: on success, a pointer to the sfp_bus structure,
81 + * %NULL if no SFP is specified,
82 + * on failure, an error pointer value:
83 + * corresponding to the errors detailed for
84 + * fwnode_property_get_reference_args().
85 + * %-ENOMEM if we failed to allocate the bus.
86 + * an error from the upstream's connect_phy() method.
88 -struct sfp_bus *sfp_register_upstream(struct fwnode_handle *fwnode,
90 - const struct sfp_upstream_ops *ops)
92 - struct sfp_bus *bus = sfp_bus_get(fwnode);
97 - bus->upstream_ops = ops;
98 - bus->upstream = upstream;
99 +struct sfp_bus *sfp_register_upstream_node(struct fwnode_handle *fwnode,
101 + const struct sfp_upstream_ops *ops)
103 + struct fwnode_reference_args ref;
104 + struct sfp_bus *bus;
108 - ret = sfp_register_bus(bus);
110 - sfp_upstream_clear(bus);
113 + ret = fwnode_property_get_reference_args(fwnode, "sfp", NULL,
115 + if (ret == -ENOENT)
118 + return ERR_PTR(ret);
120 + bus = sfp_bus_get(ref.fwnode);
121 + fwnode_handle_put(ref.fwnode);
123 + return ERR_PTR(-ENOMEM);
126 + bus->upstream_ops = ops;
127 + bus->upstream = upstream;
130 + ret = sfp_register_bus(bus);
132 + sfp_upstream_clear(bus);
141 + bus = ERR_PTR(ret);
146 -EXPORT_SYMBOL_GPL(sfp_register_upstream);
147 +EXPORT_SYMBOL_GPL(sfp_register_upstream_node);
150 * sfp_unregister_upstream() - Unregister sfp bus
151 --- a/include/linux/sfp.h
152 +++ b/include/linux/sfp.h
153 @@ -508,9 +508,9 @@ int sfp_get_module_eeprom(struct sfp_bus
155 void sfp_upstream_start(struct sfp_bus *bus);
156 void sfp_upstream_stop(struct sfp_bus *bus);
157 -struct sfp_bus *sfp_register_upstream(struct fwnode_handle *fwnode,
159 - const struct sfp_upstream_ops *ops);
160 +struct sfp_bus *sfp_register_upstream_node(struct fwnode_handle *fwnode,
162 + const struct sfp_upstream_ops *ops);
163 void sfp_unregister_upstream(struct sfp_bus *bus);
165 static inline int sfp_parse_port(struct sfp_bus *bus,
166 @@ -553,11 +553,11 @@ static inline void sfp_upstream_stop(str
170 -static inline struct sfp_bus *sfp_register_upstream(
171 +static inline struct sfp_bus *sfp_register_upstream_node(
172 struct fwnode_handle *fwnode, void *upstream,
173 const struct sfp_upstream_ops *ops)
175 - return (struct sfp_bus *)-1;
179 static inline void sfp_unregister_upstream(struct sfp_bus *bus)