generic: 6.1, 6.6: mt7530: import accepted patches
[openwrt/staging/pepe2k.git] / target / linux / generic / backport-6.1 / 766-v6.10-net-dsa-allow-DSA-switch-drivers-to-provide-their-ow.patch
1 From c22d8240fcd73a1c3ec8dcb055bd583fb970c375 Mon Sep 17 00:00:00 2001
2 From: "Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>
3 Date: Wed, 10 Apr 2024 20:42:43 +0100
4 Subject: [PATCH 2/2] net: dsa: allow DSA switch drivers to provide their own
5 phylink mac ops
6
7 Rather than having a shim for each and every phylink MAC operation,
8 allow DSA switch drivers to provide their own ops structure. When a
9 DSA driver provides the phylink MAC operations, the shimmed ops must
10 not be provided, so fail an attempt to register a switch with both
11 the phylink_mac_ops in struct dsa_switch and the phylink_mac_*
12 operations populated in dsa_switch_ops populated.
13
14 Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
15 Reviewed-by: Vladimir Oltean <olteanv@gmail.com>
16 Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
17 Link: https://lore.kernel.org/r/E1rudqF-006K9H-Cc@rmk-PC.armlinux.org.uk
18 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
19 ---
20 include/net/dsa.h | 5 +++++
21 net/dsa/dsa.c | 11 +++++++++++
22 net/dsa/port.c | 26 ++++++++++++++++++++------
23 3 files changed, 36 insertions(+), 6 deletions(-)
24
25 --- a/include/net/dsa.h
26 +++ b/include/net/dsa.h
27 @@ -468,6 +468,11 @@ struct dsa_switch {
28 const struct dsa_switch_ops *ops;
29
30 /*
31 + * Allow a DSA switch driver to override the phylink MAC ops
32 + */
33 + const struct phylink_mac_ops *phylink_mac_ops;
34 +
35 + /*
36 * Slave mii_bus and devices for the individual ports.
37 */
38 u32 phys_mii_mask;
39 --- a/net/dsa/port.c
40 +++ b/net/dsa/port.c
41 @@ -1675,6 +1675,7 @@ static const struct phylink_mac_ops dsa_
42
43 int dsa_port_phylink_create(struct dsa_port *dp)
44 {
45 + const struct phylink_mac_ops *mac_ops;
46 struct dsa_switch *ds = dp->ds;
47 phy_interface_t mode;
48 struct phylink *pl;
49 @@ -1694,8 +1695,12 @@ int dsa_port_phylink_create(struct dsa_p
50 if (ds->ops->phylink_get_caps)
51 ds->ops->phylink_get_caps(ds, dp->index, &dp->pl_config);
52
53 - pl = phylink_create(&dp->pl_config, of_fwnode_handle(dp->dn),
54 - mode, &dsa_port_phylink_mac_ops);
55 + mac_ops = &dsa_port_phylink_mac_ops;
56 + if (ds->phylink_mac_ops)
57 + mac_ops = ds->phylink_mac_ops;
58 +
59 + pl = phylink_create(&dp->pl_config, of_fwnode_handle(dp->dn), mode,
60 + mac_ops);
61 if (IS_ERR(pl)) {
62 pr_err("error creating PHYLINK: %ld\n", PTR_ERR(pl));
63 return PTR_ERR(pl);
64 @@ -1961,12 +1966,23 @@ static void dsa_shared_port_validate_of(
65 dn, dsa_port_is_cpu(dp) ? "CPU" : "DSA", dp->index);
66 }
67
68 +static void dsa_shared_port_link_down(struct dsa_port *dp)
69 +{
70 + struct dsa_switch *ds = dp->ds;
71 +
72 + if (ds->phylink_mac_ops && ds->phylink_mac_ops->mac_link_down)
73 + ds->phylink_mac_ops->mac_link_down(&dp->pl_config, MLO_AN_FIXED,
74 + PHY_INTERFACE_MODE_NA);
75 + else if (ds->ops->phylink_mac_link_down)
76 + ds->ops->phylink_mac_link_down(ds, dp->index, MLO_AN_FIXED,
77 + PHY_INTERFACE_MODE_NA);
78 +}
79 +
80 int dsa_shared_port_link_register_of(struct dsa_port *dp)
81 {
82 struct dsa_switch *ds = dp->ds;
83 bool missing_link_description;
84 bool missing_phy_mode;
85 - int port = dp->index;
86
87 dsa_shared_port_validate_of(dp, &missing_phy_mode,
88 &missing_link_description);
89 @@ -1982,9 +1998,7 @@ int dsa_shared_port_link_register_of(str
90 "Skipping phylink registration for %s port %d\n",
91 dsa_port_is_cpu(dp) ? "CPU" : "DSA", dp->index);
92 } else {
93 - if (ds->ops->phylink_mac_link_down)
94 - ds->ops->phylink_mac_link_down(ds, port,
95 - MLO_AN_FIXED, PHY_INTERFACE_MODE_NA);
96 + dsa_shared_port_link_down(dp);
97
98 return dsa_shared_port_phylink_register(dp);
99 }
100 --- a/net/dsa/dsa2.c
101 +++ b/net/dsa/dsa2.c
102 @@ -1736,6 +1736,15 @@ static int dsa_switch_probe(struct dsa_s
103 if (!ds->num_ports)
104 return -EINVAL;
105
106 + if (ds->phylink_mac_ops) {
107 + if (ds->ops->phylink_mac_select_pcs ||
108 + ds->ops->phylink_mac_config ||
109 + ds->ops->phylink_mac_link_down ||
110 + ds->ops->phylink_mac_link_up ||
111 + ds->ops->adjust_link)
112 + return -EINVAL;
113 + }
114 +
115 if (np) {
116 err = dsa_switch_parse_of(ds, np);
117 if (err)