kernel: bump 6.1 to 6.1.64
[openwrt/staging/hauke.git] / target / linux / generic / backport-6.1 / 792-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 @@ -71,6 +75,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 @@ -987,6 +992,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 @@ -1023,11 +1044,16 @@ static void phylink_major_config(struct
62 /* If we have a new PCS, switch to the new PCS after preparing the MAC
63 * for the change.
64 */
65 - if (pcs_changed)
66 + if (pcs_changed) {
67 + phylink_pcs_disable(pl->pcs);
68 pl->pcs = pcs;
69 + }
70
71 phylink_mac_config(pl, state);
72
73 + if (pl->pcs_state == PCS_STATE_STARTING || pcs_changed)
74 + phylink_pcs_enable(pl->pcs);
75 +
76 if (pl->pcs) {
77 err = pl->pcs->ops->pcs_config(pl->pcs, pl->cur_link_an_mode,
78 state->interface,
79 @@ -1499,6 +1525,7 @@ struct phylink *phylink_create(struct ph
80 pl->link_config.speed = SPEED_UNKNOWN;
81 pl->link_config.duplex = DUPLEX_UNKNOWN;
82 pl->link_config.an_enabled = true;
83 + pl->pcs_state = PCS_STATE_DOWN;
84 pl->mac_ops = mac_ops;
85 __set_bit(PHYLINK_DISABLE_STOPPED, &pl->phylink_disable_state);
86 timer_setup(&pl->link_poll, phylink_fixed_poll, 0);
87 @@ -1900,6 +1927,8 @@ void phylink_start(struct phylink *pl)
88 if (pl->netdev)
89 netif_carrier_off(pl->netdev);
90
91 + pl->pcs_state = PCS_STATE_STARTING;
92 +
93 /* Apply the link configuration to the MAC when starting. This allows
94 * a fixed-link to start with the correct parameters, and also
95 * ensures that we set the appropriate advertisement for Serdes links.
96 @@ -1910,6 +1939,8 @@ void phylink_start(struct phylink *pl)
97 */
98 phylink_mac_initial_config(pl, true);
99
100 + pl->pcs_state = PCS_STATE_STARTED;
101 +
102 phylink_enable_and_run_resolve(pl, PHYLINK_DISABLE_STOPPED);
103
104 if (pl->cfg_link_an_mode == MLO_AN_FIXED && pl->link_gpio) {
105 @@ -1928,15 +1959,9 @@ void phylink_start(struct phylink *pl)
106 poll = true;
107 }
108
109 - switch (pl->cfg_link_an_mode) {
110 - case MLO_AN_FIXED:
111 + if (pl->cfg_link_an_mode == MLO_AN_FIXED)
112 poll |= pl->config->poll_fixed_state;
113 - break;
114 - case MLO_AN_INBAND:
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 @@ -1973,6 +1998,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 @@ -446,6 +446,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 @@ -455,6 +457,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 @@ -485,6 +489,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.