blob: 82c9fa53c28a147f41fd14f6885fc30c08cc7c39 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001From 4054955f0da08c81d42220cb445820d474f1ac92 Mon Sep 17 00:00:00 2001
2From: Russell King <rmk+kernel@armlinux.org.uk>
3Date: Sat, 14 Sep 2019 14:21:22 +0100
4Subject: [PATCH 614/660] net: sfp: move fwnode parsing into sfp-bus layer
5
6Rather than parsing the sfp firmware node in phylink, parse it in the
7sfp-bus code, so we can re-use this code for PHYs without having to
8duplicate the parsing.
9
10Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
11---
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(-)
16
17--- a/drivers/net/phy/phylink.c
18+++ b/drivers/net/phy/phylink.c
19@@ -565,31 +565,17 @@ static const struct sfp_upstream_ops sfp
20 static int phylink_register_sfp(struct phylink *pl,
21 struct fwnode_handle *fwnode)
22 {
23- struct fwnode_reference_args ref;
24+ struct sfp_bus *bus;
25 int ret;
26
27- if (!fwnode)
28- return 0;
29-
30- ret = fwnode_property_get_reference_args(fwnode, "sfp", NULL,
31- 0, 0, &ref);
32- if (ret < 0) {
33- if (ret == -ENOENT)
34- return 0;
35-
36- phylink_err(pl, "unable to parse \"sfp\" node: %d\n",
37- ret);
38+ bus = sfp_register_upstream_node(fwnode, pl, &sfp_phylink_ops);
39+ if (IS_ERR(bus)) {
40+ ret = PTR_ERR(bus);
41+ phylink_err(pl, "unable to attach SFP bus: %d\n", ret);
42 return ret;
43 }
44
45- if (!fwnode_device_is_available(ref.fwnode)) {
46- fwnode_handle_put(ref.fwnode);
47- return 0;
48- }
49-
50- pl->sfp_bus = sfp_register_upstream(ref.fwnode, pl, &sfp_phylink_ops);
51- if (!pl->sfp_bus)
52- return -ENOMEM;
53+ pl->sfp_bus = bus;
54
55 return 0;
56 }
57--- a/drivers/net/phy/sfp-bus.c
58+++ b/drivers/net/phy/sfp-bus.c
59@@ -4,6 +4,7 @@
60 #include <linux/list.h>
61 #include <linux/mutex.h>
62 #include <linux/phylink.h>
63+#include <linux/property.h>
64 #include <linux/rtnetlink.h>
65 #include <linux/slab.h>
66
67@@ -520,45 +521,68 @@ static void sfp_upstream_clear(struct sf
68 }
69
70 /**
71- * sfp_register_upstream() - Register the neighbouring device
72- * @fwnode: firmware node for the SFP bus
73+ * sfp_register_upstream_node() - parse and register the neighbouring device
74+ * @fwnode: firmware node for the parent device (MAC or PHY)
75 * @upstream: the upstream private data
76 * @ops: the upstream's &struct sfp_upstream_ops
77 *
78- * Register the upstream device (eg, PHY) with the SFP bus. MAC drivers
79- * should use phylink, which will call this function for them. Returns
80- * a pointer to the allocated &struct sfp_bus.
81+ * Parse the parent device's firmware node for a SFP bus, and register the
82+ * SFP bus using sfp_register_upstream().
83 *
84- * On error, returns %NULL.
85+ * Returns: on success, a pointer to the sfp_bus structure,
86+ * %NULL if no SFP is specified,
87+ * on failure, an error pointer value:
88+ * corresponding to the errors detailed for
89+ * fwnode_property_get_reference_args().
90+ * %-ENOMEM if we failed to allocate the bus.
91+ * an error from the upstream's connect_phy() method.
92 */
93-struct sfp_bus *sfp_register_upstream(struct fwnode_handle *fwnode,
94- void *upstream,
95- const struct sfp_upstream_ops *ops)
96-{
97- struct sfp_bus *bus = sfp_bus_get(fwnode);
98- int ret = 0;
99-
100- if (bus) {
101- rtnl_lock();
102- bus->upstream_ops = ops;
103- bus->upstream = upstream;
104+struct sfp_bus *sfp_register_upstream_node(struct fwnode_handle *fwnode,
105+ void *upstream,
106+ const struct sfp_upstream_ops *ops)
107+{
108+ struct fwnode_reference_args ref;
109+ struct sfp_bus *bus;
110+ int ret;
111
112- if (bus->sfp) {
113- ret = sfp_register_bus(bus);
114- if (ret)
115- sfp_upstream_clear(bus);
116- }
117- rtnl_unlock();
118+ ret = fwnode_property_get_reference_args(fwnode, "sfp", NULL,
119+ 0, 0, &ref);
120+ if (ret == -ENOENT)
121+ return NULL;
122+ else if (ret < 0)
123+ return ERR_PTR(ret);
124+
125+ if (!fwnode_device_is_available(ref.fwnode)) {
126+ fwnode_handle_put(ref.fwnode);
127+ return NULL;
128+ }
129+
130+ bus = sfp_bus_get(ref.fwnode);
131+ fwnode_handle_put(ref.fwnode);
132+ if (!bus)
133+ return ERR_PTR(-ENOMEM);
134+
135+ rtnl_lock();
136+ bus->upstream_ops = ops;
137+ bus->upstream = upstream;
138+
139+ if (bus->sfp) {
140+ ret = sfp_register_bus(bus);
141+ if (ret)
142+ sfp_upstream_clear(bus);
143+ } else {
144+ ret = 0;
145 }
146+ rtnl_unlock();
147
148 if (ret) {
149 sfp_bus_put(bus);
150- bus = NULL;
151+ bus = ERR_PTR(ret);
152 }
153
154 return bus;
155 }
156-EXPORT_SYMBOL_GPL(sfp_register_upstream);
157+EXPORT_SYMBOL_GPL(sfp_register_upstream_node);
158
159 /**
160 * sfp_unregister_upstream() - Unregister sfp bus
161--- a/include/linux/sfp.h
162+++ b/include/linux/sfp.h
163@@ -508,9 +508,9 @@ int sfp_get_module_eeprom(struct sfp_bus
164 u8 *data);
165 void sfp_upstream_start(struct sfp_bus *bus);
166 void sfp_upstream_stop(struct sfp_bus *bus);
167-struct sfp_bus *sfp_register_upstream(struct fwnode_handle *fwnode,
168- void *upstream,
169- const struct sfp_upstream_ops *ops);
170+struct sfp_bus *sfp_register_upstream_node(struct fwnode_handle *fwnode,
171+ void *upstream,
172+ const struct sfp_upstream_ops *ops);
173 void sfp_unregister_upstream(struct sfp_bus *bus);
174 #else
175 static inline int sfp_parse_port(struct sfp_bus *bus,
176@@ -553,11 +553,11 @@ static inline void sfp_upstream_stop(str
177 {
178 }
179
180-static inline struct sfp_bus *sfp_register_upstream(
181+static inline struct sfp_bus *sfp_register_upstream_node(
182 struct fwnode_handle *fwnode, void *upstream,
183 const struct sfp_upstream_ops *ops)
184 {
185- return (struct sfp_bus *)-1;
186+ return NULL;
187 }
188
189 static inline void sfp_unregister_upstream(struct sfp_bus *bus)