kernel: backport phylink changes from mainline Linux
[openwrt/staging/blocktrron.git] / target / linux / generic / backport-6.1 / 715-18-v6.5-net-phylink-require-supported_interfaces-to-be-fille.patch
1 From 441e1e44301fc5762a06737f8ec04bf1ce3fb039 Mon Sep 17 00:00:00 2001
2 From: "Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>
3 Date: Sat, 20 May 2023 11:41:42 +0100
4 Subject: [PATCH 16/21] net: phylink: require supported_interfaces to be filled
5
6 We have been requiring the supported_interfaces bitmap to be filled in
7 by MAC drivers that have a mac_select_pcs() method. Now that all MAC
8 drivers fill in the supported_interfaces bitmap, it is time to enforce
9 this. We have already required supported_interfaces to be set in order
10 for optical SFPs to be configured in commit f81fa96d8a6c ("net: phylink:
11 use phy_interface_t bitmaps for optical modules").
12
13 Refuse phylink creation if supported_interfaces is empty, and remove
14 code to deal with cases where this mask is empty.
15
16 Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
17 Reviewed-by: Andrew Lunn <andrew@lunn.ch>
18 Link: https://lore.kernel.org/r/E1q0K1u-006EIP-ET@rmk-PC.armlinux.org.uk
19 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
20 ---
21 drivers/net/phy/phylink.c | 26 +++++++++++---------------
22 1 file changed, 11 insertions(+), 15 deletions(-)
23
24 --- a/drivers/net/phy/phylink.c
25 +++ b/drivers/net/phy/phylink.c
26 @@ -710,14 +710,11 @@ static int phylink_validate(struct phyli
27 {
28 const unsigned long *interfaces = pl->config->supported_interfaces;
29
30 - if (!phy_interface_empty(interfaces)) {
31 - if (state->interface == PHY_INTERFACE_MODE_NA)
32 - return phylink_validate_mask(pl, supported, state,
33 - interfaces);
34 + if (state->interface == PHY_INTERFACE_MODE_NA)
35 + return phylink_validate_mask(pl, supported, state, interfaces);
36
37 - if (!test_bit(state->interface, interfaces))
38 - return -EINVAL;
39 - }
40 + if (!test_bit(state->interface, interfaces))
41 + return -EINVAL;
42
43 return phylink_validate_mac_and_pcs(pl, supported, state);
44 }
45 @@ -1512,19 +1509,18 @@ struct phylink *phylink_create(struct ph
46 struct phylink *pl;
47 int ret;
48
49 - if (mac_ops->mac_select_pcs &&
50 - mac_ops->mac_select_pcs(config, PHY_INTERFACE_MODE_NA) !=
51 - ERR_PTR(-EOPNOTSUPP))
52 - using_mac_select_pcs = true;
53 -
54 /* Validate the supplied configuration */
55 - if (using_mac_select_pcs &&
56 - phy_interface_empty(config->supported_interfaces)) {
57 + if (phy_interface_empty(config->supported_interfaces)) {
58 dev_err(config->dev,
59 - "phylink: error: empty supported_interfaces but mac_select_pcs() method present\n");
60 + "phylink: error: empty supported_interfaces\n");
61 return ERR_PTR(-EINVAL);
62 }
63
64 + if (mac_ops->mac_select_pcs &&
65 + mac_ops->mac_select_pcs(config, PHY_INTERFACE_MODE_NA) !=
66 + ERR_PTR(-EOPNOTSUPP))
67 + using_mac_select_pcs = true;
68 +
69 pl = kzalloc(sizeof(*pl), GFP_KERNEL);
70 if (!pl)
71 return ERR_PTR(-ENOMEM);