kernel: backport list_count_nodes()
[openwrt/openwrt.git] / target / linux / generic / backport-5.15 / 703-14-v5.17-net-phylink-use-legacy_pre_march2020.patch
1 From 001f4261fe4d5ae710cf1f445b6cae6d9d3ae26e Mon Sep 17 00:00:00 2001
2 From: "Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>
3 Date: Thu, 9 Dec 2021 13:11:48 +0000
4 Subject: [PATCH] net: phylink: use legacy_pre_march2020
5
6 Use the legacy flag to indicate whether we should operate in legacy
7 mode. This allows us to stop using the presence of a PCS as an
8 indicator to the age of the phylink user, and make PCS presence
9 optional.
10
11 Legacy mode involves:
12 1) calling mac_config() whenever the link comes up
13 2) calling mac_config() whenever the inband advertisement changes,
14 possibly followed by a call to mac_an_restart()
15 3) making use of mac_an_restart()
16 4) making use of mac_pcs_get_state()
17
18 All the above functionality was moved to a seperate "PCS" block of
19 operations in March 2020.
20
21 Update the documents to indicate that the differences that this flag
22 makes.
23
24 Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
25 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
26 ---
27 drivers/net/phy/phylink.c | 12 ++++++------
28 include/linux/phylink.h | 17 +++++++++++++++++
29 2 files changed, 23 insertions(+), 6 deletions(-)
30
31 --- a/drivers/net/phy/phylink.c
32 +++ b/drivers/net/phy/phylink.c
33 @@ -777,7 +777,7 @@ static void phylink_mac_pcs_an_restart(s
34 phylink_autoneg_inband(pl->cur_link_an_mode)) {
35 if (pl->pcs_ops)
36 pl->pcs_ops->pcs_an_restart(pl->pcs);
37 - else
38 + else if (pl->config->legacy_pre_march2020)
39 pl->mac_ops->mac_an_restart(pl->config);
40 }
41 }
42 @@ -855,7 +855,7 @@ static int phylink_change_inband_advert(
43 if (test_bit(PHYLINK_DISABLE_STOPPED, &pl->phylink_disable_state))
44 return 0;
45
46 - if (!pl->pcs_ops) {
47 + if (!pl->pcs_ops && pl->config->legacy_pre_march2020) {
48 /* Legacy method */
49 phylink_mac_config(pl, &pl->link_config);
50 phylink_mac_pcs_an_restart(pl);
51 @@ -900,7 +900,8 @@ static void phylink_mac_pcs_get_state(st
52
53 if (pl->pcs_ops)
54 pl->pcs_ops->pcs_get_state(pl->pcs, state);
55 - else if (pl->mac_ops->mac_pcs_get_state)
56 + else if (pl->mac_ops->mac_pcs_get_state &&
57 + pl->config->legacy_pre_march2020)
58 pl->mac_ops->mac_pcs_get_state(pl->config, state);
59 else
60 state->link = 0;
61 @@ -1094,12 +1095,11 @@ static void phylink_resolve(struct work_
62 }
63 phylink_major_config(pl, false, &link_state);
64 pl->link_config.interface = link_state.interface;
65 - } else if (!pl->pcs_ops) {
66 + } else if (!pl->pcs_ops && pl->config->legacy_pre_march2020) {
67 /* The interface remains unchanged, only the speed,
68 * duplex or pause settings have changed. Call the
69 * old mac_config() method to configure the MAC/PCS
70 - * only if we do not have a PCS installed (an
71 - * unconverted user.)
72 + * only if we do not have a legacy MAC driver.
73 */
74 phylink_mac_config(pl, &link_state);
75 }
76 --- a/include/linux/phylink.h
77 +++ b/include/linux/phylink.h
78 @@ -210,6 +210,10 @@ struct phylink_pcs *mac_select_pcs(struc
79 * negotiation completion state in @state->an_complete, and link up state
80 * in @state->link. If possible, @state->lp_advertising should also be
81 * populated.
82 + *
83 + * Note: This is a legacy method. This function will not be called unless
84 + * legacy_pre_march2020 is set in &struct phylink_config and there is no
85 + * PCS attached.
86 */
87 void mac_pcs_get_state(struct phylink_config *config,
88 struct phylink_link_state *state);
89 @@ -250,6 +254,15 @@ int mac_prepare(struct phylink_config *c
90 * guaranteed to be correct, and so any mac_config() implementation must
91 * never reference these fields.
92 *
93 + * Note: For legacy March 2020 drivers (drivers with legacy_pre_march2020 set
94 + * in their &phylnk_config and which don't have a PCS), this function will be
95 + * called on each link up event, and to also change the in-band advert. For
96 + * non-legacy drivers, it will only be called to reconfigure the MAC for a
97 + * "major" change in e.g. interface mode. It will not be called for changes
98 + * in speed, duplex or pause modes or to change the in-band advertisement.
99 + * In any case, it is strongly preferred that speed, duplex and pause settings
100 + * are handled in the mac_link_up() method and not in this method.
101 + *
102 * (this requires a rewrite - please refer to mac_link_up() for situations
103 * where the PCS and MAC are not tightly integrated.)
104 *
105 @@ -334,6 +347,10 @@ int mac_finish(struct phylink_config *co
106 /**
107 * mac_an_restart() - restart 802.3z BaseX autonegotiation
108 * @config: a pointer to a &struct phylink_config.
109 + *
110 + * Note: This is a legacy method. This function will not be called unless
111 + * legacy_pre_march2020 is set in &struct phylink_config and there is no
112 + * PCS attached.
113 */
114 void mac_an_restart(struct phylink_config *config);
115