1 From 1054457006d4a14de4ae4132030e33d7eedaeba1 Mon Sep 17 00:00:00 2001
2 From: "Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>
3 Date: Mon, 21 Feb 2022 17:10:52 +0000
4 Subject: [PATCH] net: phy: phylink: fix DSA mac_select_pcs() introduction
6 Vladimir Oltean reports that probing on DSA drivers that aren't yet
7 populating supported_interfaces now fails. Fix this by allowing
8 phylink to detect whether DSA actually provides an underlying
9 mac_select_pcs() implementation.
11 Reported-by: Vladimir Oltean <olteanv@gmail.com>
12 Fixes: bde018222c6b ("net: dsa: add support for phylink mac_select_pcs()")
13 Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
14 Tested-by: Vladimir Oltean <olteanv@gmail.com>
15 Link: https://lore.kernel.org/r/E1nMCD6-00A0wC-FG@rmk-PC.armlinux.org.uk
16 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
18 drivers/net/phy/phylink.c | 14 +++++++++++---
20 2 files changed, 12 insertions(+), 4 deletions(-)
22 --- a/drivers/net/phy/phylink.c
23 +++ b/drivers/net/phy/phylink.c
24 @@ -74,6 +74,7 @@ struct phylink {
25 struct work_struct resolve;
27 bool mac_link_dropped;
28 + bool using_mac_select_pcs;
30 struct sfp_bus *sfp_bus;
31 bool sfp_may_have_phy;
32 @@ -163,7 +164,7 @@ static int phylink_validate_mac_and_pcs(
35 /* Get the PCS for this interface mode */
36 - if (pl->mac_ops->mac_select_pcs) {
37 + if (pl->using_mac_select_pcs) {
38 pcs = pl->mac_ops->mac_select_pcs(pl->config, state->interface);
41 @@ -790,7 +791,7 @@ static void phylink_major_config(struct
43 phylink_dbg(pl, "major config %s\n", phy_modes(state->interface));
45 - if (pl->mac_ops->mac_select_pcs) {
46 + if (pl->using_mac_select_pcs) {
47 pcs = pl->mac_ops->mac_select_pcs(pl->config, state->interface);
50 @@ -1192,11 +1193,17 @@ struct phylink *phylink_create(struct ph
51 phy_interface_t iface,
52 const struct phylink_mac_ops *mac_ops)
54 + bool using_mac_select_pcs = false;
58 - /* Validate the supplied configuration */
59 if (mac_ops->mac_select_pcs &&
60 + mac_ops->mac_select_pcs(config, PHY_INTERFACE_MODE_NA) !=
61 + ERR_PTR(-EOPNOTSUPP))
62 + using_mac_select_pcs = true;
64 + /* Validate the supplied configuration */
65 + if (using_mac_select_pcs &&
66 phy_interface_empty(config->supported_interfaces)) {
68 "phylink: error: empty supported_interfaces but mac_select_pcs() method present\n");
69 @@ -1220,6 +1227,7 @@ struct phylink *phylink_create(struct ph
70 return ERR_PTR(-EINVAL);
73 + pl->using_mac_select_pcs = using_mac_select_pcs;
74 pl->phy_state.interface = iface;
75 pl->link_interface = iface;
76 if (iface == PHY_INTERFACE_MODE_MOCA)
79 @@ -1033,8 +1033,8 @@ dsa_port_phylink_mac_select_pcs(struct p
80 phy_interface_t interface)
82 struct dsa_port *dp = container_of(config, struct dsa_port, pl_config);
83 + struct phylink_pcs *pcs = ERR_PTR(-EOPNOTSUPP);
84 struct dsa_switch *ds = dp->ds;
85 - struct phylink_pcs *pcs = NULL;
87 if (ds->ops->phylink_mac_select_pcs)
88 pcs = ds->ops->phylink_mac_select_pcs(ds, dp->index, interface);