eea99a5d782e837e50bfa83375adc7e9da081510
[openwrt/staging/981213.git] /
1 From 796d709363135a6bd6a8ccc07b509c939e5b855f Mon Sep 17 00:00:00 2001
2 From: "Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>
3 Date: Tue, 23 May 2023 16:31:50 +0100
4 Subject: [PATCH 19/21] net: phylink: provide phylink_pcs_config() and
5 phylink_pcs_link_up()
6
7 Add two helper functions for calling PCS methods. phylink_pcs_config()
8 allows us to handle PCS configuration specifics in one location, rather
9 than the two call sites. phylink_pcs_link_up() gives us consistency.
10
11 Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
12 Link: https://lore.kernel.org/r/E1q1TzK-007Exd-Rs@rmk-PC.armlinux.org.uk
13 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
14 ---
15 drivers/net/phy/phylink.c | 53 ++++++++++++++++++++++++---------------
16 1 file changed, 33 insertions(+), 20 deletions(-)
17
18 --- a/drivers/net/phy/phylink.c
19 +++ b/drivers/net/phy/phylink.c
20 @@ -991,6 +991,25 @@ static void phylink_resolve_an_pause(str
21 }
22 }
23
24 +static int phylink_pcs_config(struct phylink_pcs *pcs, unsigned int mode,
25 + const struct phylink_link_state *state,
26 + bool permit_pause_to_mac)
27 +{
28 + if (!pcs)
29 + return 0;
30 +
31 + return pcs->ops->pcs_config(pcs, mode, state->interface,
32 + state->advertising, permit_pause_to_mac);
33 +}
34 +
35 +static void phylink_pcs_link_up(struct phylink_pcs *pcs, unsigned int mode,
36 + phy_interface_t interface, int speed,
37 + int duplex)
38 +{
39 + if (pcs && pcs->ops->pcs_link_up)
40 + pcs->ops->pcs_link_up(pcs, mode, interface, speed, duplex);
41 +}
42 +
43 static void phylink_pcs_poll_stop(struct phylink *pl)
44 {
45 if (pl->cfg_link_an_mode == MLO_AN_INBAND)
46 @@ -1074,18 +1093,15 @@ static void phylink_major_config(struct
47
48 phylink_mac_config(pl, state);
49
50 - if (pl->pcs) {
51 - err = pl->pcs->ops->pcs_config(pl->pcs, pl->cur_link_an_mode,
52 - state->interface,
53 - state->advertising,
54 - !!(pl->link_config.pause &
55 - MLO_PAUSE_AN));
56 - if (err < 0)
57 - phylink_err(pl, "pcs_config failed: %pe\n",
58 - ERR_PTR(err));
59 - if (err > 0)
60 - restart = true;
61 - }
62 + err = phylink_pcs_config(pl->pcs, pl->cur_link_an_mode, state,
63 + !!(pl->link_config.pause &
64 + MLO_PAUSE_AN));
65 + if (err < 0)
66 + phylink_err(pl, "pcs_config failed: %pe\n",
67 + ERR_PTR(err));
68 + else if (err > 0)
69 + restart = true;
70 +
71 if (restart)
72 phylink_mac_pcs_an_restart(pl);
73
74 @@ -1136,11 +1152,9 @@ static int phylink_change_inband_advert(
75 * restart negotiation if the pcs_config() helper indicates that
76 * the programmed advertisement has changed.
77 */
78 - ret = pl->pcs->ops->pcs_config(pl->pcs, pl->cur_link_an_mode,
79 - pl->link_config.interface,
80 - pl->link_config.advertising,
81 - !!(pl->link_config.pause &
82 - MLO_PAUSE_AN));
83 + ret = phylink_pcs_config(pl->pcs, pl->cur_link_an_mode,
84 + &pl->link_config,
85 + !!(pl->link_config.pause & MLO_PAUSE_AN));
86 if (ret < 0)
87 return ret;
88
89 @@ -1272,9 +1286,8 @@ static void phylink_link_up(struct phyli
90
91 pl->cur_interface = link_state.interface;
92
93 - if (pl->pcs && pl->pcs->ops->pcs_link_up)
94 - pl->pcs->ops->pcs_link_up(pl->pcs, pl->cur_link_an_mode,
95 - pl->cur_interface, speed, duplex);
96 + phylink_pcs_link_up(pl->pcs, pl->cur_link_an_mode, pl->cur_interface,
97 + speed, duplex);
98
99 pl->mac_ops->mac_link_up(pl->config, pl->phydev, pl->cur_link_an_mode,
100 pl->cur_interface, speed, duplex,