kernel: add support for kernel 5.4
[openwrt/staging/rmilecki.git] / target / linux / generic / pending-5.4 / 749-net-phylink-split-phylink_sfp_module_insert.patch
1 From 36569971241ae6b81376da4937d2c8760122d10b Mon Sep 17 00:00:00 2001
2 From: Russell King <rmk+kernel@armlinux.org.uk>
3 Date: Thu, 21 Nov 2019 17:58:58 +0000
4 Subject: [PATCH 652/660] net: phylink: split phylink_sfp_module_insert()
5
6 Split out the configuration step from phylink_sfp_module_insert() so
7 we can re-use this later.
8
9 Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
10 ---
11 drivers/net/phy/phylink.c | 47 +++++++++++++++++++++++----------------
12 1 file changed, 28 insertions(+), 19 deletions(-)
13
14 --- a/drivers/net/phy/phylink.c
15 +++ b/drivers/net/phy/phylink.c
16 @@ -1688,25 +1688,21 @@ static void phylink_sfp_detach(void *ups
17 pl->netdev->sfp_bus = NULL;
18 }
19
20 -static int phylink_sfp_module_insert(void *upstream,
21 - const struct sfp_eeprom_id *id)
22 +static int phylink_sfp_config(struct phylink *pl, u8 mode, u8 port,
23 + const unsigned long *supported,
24 + const unsigned long *advertising)
25 {
26 - struct phylink *pl = upstream;
27 - __ETHTOOL_DECLARE_LINK_MODE_MASK(support) = { 0, };
28 __ETHTOOL_DECLARE_LINK_MODE_MASK(support1);
29 + __ETHTOOL_DECLARE_LINK_MODE_MASK(support);
30 struct phylink_link_state config;
31 phy_interface_t iface;
32 - int ret = 0;
33 bool changed;
34 - u8 port;
35 + int ret;
36
37 - ASSERT_RTNL();
38 -
39 - sfp_parse_support(pl->sfp_bus, id, support);
40 - port = sfp_parse_port(pl->sfp_bus, id, support);
41 + linkmode_copy(support, supported);
42
43 memset(&config, 0, sizeof(config));
44 - linkmode_copy(config.advertising, support);
45 + linkmode_copy(config.advertising, advertising);
46 config.interface = PHY_INTERFACE_MODE_NA;
47 config.speed = SPEED_UNKNOWN;
48 config.duplex = DUPLEX_UNKNOWN;
49 @@ -1721,8 +1717,6 @@ static int phylink_sfp_module_insert(voi
50 return ret;
51 }
52
53 - linkmode_copy(support1, support);
54 -
55 iface = sfp_select_interface(pl->sfp_bus, config.advertising);
56 if (iface == PHY_INTERFACE_MODE_NA) {
57 phylink_err(pl,
58 @@ -1732,18 +1726,18 @@ static int phylink_sfp_module_insert(voi
59 }
60
61 config.interface = iface;
62 + linkmode_copy(support1, support);
63 ret = phylink_validate(pl, support1, &config);
64 if (ret) {
65 phylink_err(pl, "validation of %s/%s with support %*pb failed: %d\n",
66 - phylink_an_mode_str(MLO_AN_INBAND),
67 + phylink_an_mode_str(mode),
68 phy_modes(config.interface),
69 __ETHTOOL_LINK_MODE_MASK_NBITS, support, ret);
70 return ret;
71 }
72
73 phylink_dbg(pl, "requesting link mode %s/%s with support %*pb\n",
74 - phylink_an_mode_str(MLO_AN_INBAND),
75 - phy_modes(config.interface),
76 + phylink_an_mode_str(mode), phy_modes(config.interface),
77 __ETHTOOL_LINK_MODE_MASK_NBITS, support);
78
79 if (phy_interface_mode_is_8023z(iface) && pl->phydev)
80 @@ -1756,15 +1750,15 @@ static int phylink_sfp_module_insert(voi
81 linkmode_copy(pl->link_config.advertising, config.advertising);
82 }
83
84 - if (pl->cur_link_an_mode != MLO_AN_INBAND ||
85 + if (pl->cur_link_an_mode != mode ||
86 pl->link_config.interface != config.interface) {
87 pl->link_config.interface = config.interface;
88 - pl->cur_link_an_mode = MLO_AN_INBAND;
89 + pl->cur_link_an_mode = mode;
90
91 changed = true;
92
93 phylink_info(pl, "switched to %s/%s link mode\n",
94 - phylink_an_mode_str(MLO_AN_INBAND),
95 + phylink_an_mode_str(mode),
96 phy_modes(config.interface));
97 }
98
99 @@ -1777,6 +1771,21 @@ static int phylink_sfp_module_insert(voi
100 return ret;
101 }
102
103 +static int phylink_sfp_module_insert(void *upstream,
104 + const struct sfp_eeprom_id *id)
105 +{
106 + struct phylink *pl = upstream;
107 + __ETHTOOL_DECLARE_LINK_MODE_MASK(support) = { 0, };
108 + u8 port;
109 +
110 + ASSERT_RTNL();
111 +
112 + sfp_parse_support(pl->sfp_bus, id, support);
113 + port = sfp_parse_port(pl->sfp_bus, id, support);
114 +
115 + return phylink_sfp_config(pl, MLO_AN_INBAND, port, support, support);
116 +}
117 +
118 static int phylink_sfp_module_start(void *upstream)
119 {
120 struct phylink *pl = upstream;