kernel: bump 5.15 to 5.15.140
[openwrt/staging/hauke.git] / target / linux / generic / backport-5.15 / 792-03-v6.6-net-phylink-add-pcs_enable-pcs_disable-methods.patch
1 From 90ef0a7b0622c62758b2638604927867775479ea Mon Sep 17 00:00:00 2001
2 From: "Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>
3 Date: Thu, 13 Jul 2023 09:42:07 +0100
4 Subject: [PATCH] net: phylink: add pcs_enable()/pcs_disable() methods
5
6 Add phylink PCS enable/disable callbacks that will allow us to place
7 IEEE 802.3 register compliant PCS in power-down mode while not being
8 used.
9
10 Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
11 Signed-off-by: David S. Miller <davem@davemloft.net>
12 ---
13 drivers/net/phy/phylink.c | 48 +++++++++++++++++++++++++++++++--------
14 include/linux/phylink.h | 16 +++++++++++++
15 2 files changed, 55 insertions(+), 9 deletions(-)
16
17 --- a/drivers/net/phy/phylink.c
18 +++ b/drivers/net/phy/phylink.c
19 @@ -34,6 +34,10 @@ enum {
20 PHYLINK_DISABLE_STOPPED,
21 PHYLINK_DISABLE_LINK,
22 PHYLINK_DISABLE_MAC_WOL,
23 +
24 + PCS_STATE_DOWN = 0,
25 + PCS_STATE_STARTING,
26 + PCS_STATE_STARTED,
27 };
28
29 /**
30 @@ -72,6 +76,7 @@ struct phylink {
31 struct mutex state_mutex;
32 struct phylink_link_state phy_state;
33 struct work_struct resolve;
34 + unsigned int pcs_state;
35
36 bool mac_link_dropped;
37 bool using_mac_select_pcs;
38 @@ -795,6 +800,22 @@ static void phylink_mac_pcs_an_restart(s
39 }
40 }
41
42 +static void phylink_pcs_disable(struct phylink_pcs *pcs)
43 +{
44 + if (pcs && pcs->ops->pcs_disable)
45 + pcs->ops->pcs_disable(pcs);
46 +}
47 +
48 +static int phylink_pcs_enable(struct phylink_pcs *pcs)
49 +{
50 + int err = 0;
51 +
52 + if (pcs && pcs->ops->pcs_enable)
53 + err = pcs->ops->pcs_enable(pcs);
54 +
55 + return err;
56 +}
57 +
58 static void phylink_major_config(struct phylink *pl, bool restart,
59 const struct phylink_link_state *state)
60 {
61 @@ -832,12 +853,16 @@ static void phylink_major_config(struct
62 * for the change.
63 */
64 if (pcs_changed) {
65 + phylink_pcs_disable(pl->pcs);
66 pl->pcs = pcs;
67 pl->pcs_ops = pcs->ops;
68 }
69
70 phylink_mac_config(pl, state);
71
72 + if (pl->pcs_state == PCS_STATE_STARTING || pcs_changed)
73 + phylink_pcs_enable(pl->pcs);
74 +
75 if (pl->pcs_ops) {
76 err = pl->pcs_ops->pcs_config(pl->pcs, pl->cur_link_an_mode,
77 state->interface,
78 @@ -1261,6 +1286,7 @@ struct phylink *phylink_create(struct ph
79 pl->link_config.speed = SPEED_UNKNOWN;
80 pl->link_config.duplex = DUPLEX_UNKNOWN;
81 pl->link_config.an_enabled = true;
82 + pl->pcs_state = PCS_STATE_DOWN;
83 pl->mac_ops = mac_ops;
84 __set_bit(PHYLINK_DISABLE_STOPPED, &pl->phylink_disable_state);
85 timer_setup(&pl->link_poll, phylink_fixed_poll, 0);
86 @@ -1652,6 +1678,8 @@ void phylink_start(struct phylink *pl)
87 if (pl->netdev)
88 netif_carrier_off(pl->netdev);
89
90 + pl->pcs_state = PCS_STATE_STARTING;
91 +
92 /* Apply the link configuration to the MAC when starting. This allows
93 * a fixed-link to start with the correct parameters, and also
94 * ensures that we set the appropriate advertisement for Serdes links.
95 @@ -1662,6 +1690,8 @@ void phylink_start(struct phylink *pl)
96 */
97 phylink_mac_initial_config(pl, true);
98
99 + pl->pcs_state = PCS_STATE_STARTED;
100 +
101 clear_bit(PHYLINK_DISABLE_STOPPED, &pl->phylink_disable_state);
102 phylink_run_resolve(pl);
103
104 @@ -1681,16 +1711,9 @@ void phylink_start(struct phylink *pl)
105 poll = true;
106 }
107
108 - switch (pl->cfg_link_an_mode) {
109 - case MLO_AN_FIXED:
110 + if (pl->cfg_link_an_mode == MLO_AN_FIXED)
111 poll |= pl->config->poll_fixed_state;
112 - break;
113 - case MLO_AN_INBAND:
114 - poll |= pl->config->pcs_poll;
115 - if (pl->pcs)
116 - poll |= pl->pcs->poll;
117 - break;
118 - }
119 +
120 if (poll)
121 mod_timer(&pl->link_poll, jiffies + HZ);
122 if (pl->phydev)
123 @@ -1727,6 +1750,10 @@ void phylink_stop(struct phylink *pl)
124 }
125
126 phylink_run_resolve_and_disable(pl, PHYLINK_DISABLE_STOPPED);
127 +
128 + pl->pcs_state = PCS_STATE_DOWN;
129 +
130 + phylink_pcs_disable(pl->pcs);
131 }
132 EXPORT_SYMBOL_GPL(phylink_stop);
133
134 --- a/include/linux/phylink.h
135 +++ b/include/linux/phylink.h
136 @@ -419,6 +419,8 @@ struct phylink_pcs {
137 /**
138 * struct phylink_pcs_ops - MAC PCS operations structure.
139 * @pcs_validate: validate the link configuration.
140 + * @pcs_enable: enable the PCS.
141 + * @pcs_disable: disable the PCS.
142 * @pcs_get_state: read the current MAC PCS link state from the hardware.
143 * @pcs_config: configure the MAC PCS for the selected mode and state.
144 * @pcs_an_restart: restart 802.3z BaseX autonegotiation.
145 @@ -428,6 +430,8 @@ struct phylink_pcs {
146 struct phylink_pcs_ops {
147 int (*pcs_validate)(struct phylink_pcs *pcs, unsigned long *supported,
148 const struct phylink_link_state *state);
149 + int (*pcs_enable)(struct phylink_pcs *pcs);
150 + void (*pcs_disable)(struct phylink_pcs *pcs);
151 void (*pcs_get_state)(struct phylink_pcs *pcs,
152 struct phylink_link_state *state);
153 int (*pcs_config)(struct phylink_pcs *pcs, unsigned int mode,
154 @@ -458,6 +462,18 @@ int pcs_validate(struct phylink_pcs *pcs
155 const struct phylink_link_state *state);
156
157 /**
158 + * pcs_enable() - enable the PCS.
159 + * @pcs: a pointer to a &struct phylink_pcs.
160 + */
161 +int pcs_enable(struct phylink_pcs *pcs);
162 +
163 +/**
164 + * pcs_disable() - disable the PCS.
165 + * @pcs: a pointer to a &struct phylink_pcs.
166 + */
167 +void pcs_disable(struct phylink_pcs *pcs);
168 +
169 +/**
170 * pcs_get_state() - Read the current inband link state from the hardware
171 * @pcs: a pointer to a &struct phylink_pcs.
172 * @state: a pointer to a &struct phylink_link_state.