74dc39fa7f0ee0967e443e17bf00daf91ceb965e
[openwrt/staging/mans0n.git] /
1 From aeabfaa63285470e81fa341e14f92d68880aa160 Mon Sep 17 00:00:00 2001
2 From: Russell King <rmk+kernel@armlinux.org.uk>
3 Date: Tue, 28 May 2019 10:57:34 +0100
4 Subject: [PATCH 609/660] net: sfp: add mandatory attach/detach methods for sfp
5 buses
6
7 Add attach and detach methods for SFP buses, which will allow us to get
8 rid of the netdev storage in sfp-bus.
9
10 Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
11 Reviewed-by: Andrew Lunn <andrew@lunn.ch>
12 Signed-off-by: David S. Miller <davem@davemloft.net>
13 Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
14 ---
15 drivers/net/phy/phylink.c | 16 ++++++++++++++++
16 drivers/net/phy/sfp-bus.c | 4 ++--
17 include/linux/sfp.h | 6 ++++++
18 3 files changed, 24 insertions(+), 2 deletions(-)
19
20 --- a/drivers/net/phy/phylink.c
21 +++ b/drivers/net/phy/phylink.c
22 @@ -1615,6 +1615,20 @@ int phylink_mii_ioctl(struct phylink *pl
23 }
24 EXPORT_SYMBOL_GPL(phylink_mii_ioctl);
25
26 +static void phylink_sfp_attach(void *upstream, struct sfp_bus *bus)
27 +{
28 + struct phylink *pl = upstream;
29 +
30 + pl->netdev->sfp_bus = bus;
31 +}
32 +
33 +static void phylink_sfp_detach(void *upstream, struct sfp_bus *bus)
34 +{
35 + struct phylink *pl = upstream;
36 +
37 + pl->netdev->sfp_bus = NULL;
38 +}
39 +
40 static int phylink_sfp_module_insert(void *upstream,
41 const struct sfp_eeprom_id *id)
42 {
43 @@ -1733,6 +1747,8 @@ static void phylink_sfp_disconnect_phy(v
44 }
45
46 static const struct sfp_upstream_ops sfp_phylink_ops = {
47 + .attach = phylink_sfp_attach,
48 + .detach = phylink_sfp_detach,
49 .module_insert = phylink_sfp_module_insert,
50 .link_up = phylink_sfp_link_up,
51 .link_down = phylink_sfp_link_down,
52 --- a/drivers/net/phy/sfp-bus.c
53 +++ b/drivers/net/phy/sfp-bus.c
54 @@ -350,7 +350,7 @@ static int sfp_register_bus(struct sfp_b
55 bus->socket_ops->attach(bus->sfp);
56 if (bus->started)
57 bus->socket_ops->start(bus->sfp);
58 - bus->netdev->sfp_bus = bus;
59 + bus->upstream_ops->attach(bus->upstream, bus);
60 bus->registered = true;
61 return 0;
62 }
63 @@ -359,8 +359,8 @@ static void sfp_unregister_bus(struct sf
64 {
65 const struct sfp_upstream_ops *ops = bus->upstream_ops;
66
67 - bus->netdev->sfp_bus = NULL;
68 if (bus->registered) {
69 + bus->upstream_ops->detach(bus->upstream, bus);
70 if (bus->started)
71 bus->socket_ops->stop(bus->sfp);
72 bus->socket_ops->detach(bus->sfp);
73 --- a/include/linux/sfp.h
74 +++ b/include/linux/sfp.h
75 @@ -469,6 +469,10 @@ struct sfp_bus;
76
77 /**
78 * struct sfp_upstream_ops - upstream operations structure
79 + * @attach: called when the sfp socket driver is bound to the upstream
80 + * (mandatory).
81 + * @detach: called when the sfp socket driver is unbound from the upstream
82 + * (mandatory).
83 * @module_insert: called after a module has been detected to determine
84 * whether the module is supported for the upstream device.
85 * @module_remove: called after the module has been removed.
86 @@ -481,6 +485,8 @@ struct sfp_bus;
87 * been removed.
88 */
89 struct sfp_upstream_ops {
90 + void (*attach)(void *priv, struct sfp_bus *bus);
91 + void (*detach)(void *priv, struct sfp_bus *bus);
92 int (*module_insert)(void *priv, const struct sfp_eeprom_id *id);
93 void (*module_remove)(void *priv);
94 void (*link_down)(void *priv);