forked from openwrt/openwrt
-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
generic: 6.6: sync mt7530 DSA driver with upstream
Backport lots upstream changes, many of them fixes, for the mt7530 DSA driver, similar to how it was done for Linux 6.1 in the previous commit. The remaining differences compared to the upstream driver are only the 'slave' -> 'user', 'master' -> 'conduit' language change in DSA and the rename of 'struct ethtool_eee' to 'struct ethtool_keee' as well as tree-wide replacement of ethtool_sprintf with ethtool_puts, all of them do not have any functional impact. Apart from some minor bug fixes and style improvements the switch should now behave more conformant when it comes to link-local frames, and we will again be able to cleanly pick patches from upstream. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
- Loading branch information
Showing
32 changed files
with
2,823 additions
and
71 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
...neric/backport-6.6/790-01-v6.7-net-dsa-mt7530-Convert-to-platform-remove-callback-r.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
From b91ef50f70e7c092c50c1b92e63ef3fb0041cdd4 Mon Sep 17 00:00:00 2001 | ||
From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= <u.kleine-koenig@pengutronix.de> | ||
Date: Mon, 18 Sep 2023 21:19:12 +0200 | ||
Subject: [PATCH 01/30] net: dsa: mt7530: Convert to platform remove callback | ||
returning void | ||
MIME-Version: 1.0 | ||
Content-Type: text/plain; charset=UTF-8 | ||
Content-Transfer-Encoding: 8bit | ||
|
||
The .remove() callback for a platform driver returns an int which makes | ||
many driver authors wrongly assume it's possible to do error handling by | ||
returning an error code. However the value returned is ignored (apart | ||
from emitting a warning) and this typically results in resource leaks. | ||
To improve here there is a quest to make the remove callback return | ||
void. In the first step of this quest all drivers are converted to | ||
.remove_new() which already returns void. Eventually after all drivers | ||
are converted, .remove_new() is renamed to .remove(). | ||
|
||
Trivially convert this driver from always returning zero in the remove | ||
callback to the void returning variant. | ||
|
||
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> | ||
Reviewed-by: Andrew Lunn <andrew@lunn.ch> | ||
Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com> | ||
Acked-by: Daniel Golle <daniel@makrotopia.org> | ||
Signed-off-by: David S. Miller <davem@davemloft.net> | ||
--- | ||
drivers/net/dsa/mt7530-mmio.c | 7 ++----- | ||
1 file changed, 2 insertions(+), 5 deletions(-) | ||
|
||
--- a/drivers/net/dsa/mt7530-mmio.c | ||
+++ b/drivers/net/dsa/mt7530-mmio.c | ||
@@ -63,15 +63,12 @@ mt7988_probe(struct platform_device *pde | ||
return dsa_register_switch(priv->ds); | ||
} | ||
|
||
-static int | ||
-mt7988_remove(struct platform_device *pdev) | ||
+static void mt7988_remove(struct platform_device *pdev) | ||
{ | ||
struct mt7530_priv *priv = platform_get_drvdata(pdev); | ||
|
||
if (priv) | ||
mt7530_remove_common(priv); | ||
- | ||
- return 0; | ||
} | ||
|
||
static void mt7988_shutdown(struct platform_device *pdev) | ||
@@ -88,7 +85,7 @@ static void mt7988_shutdown(struct platf | ||
|
||
static struct platform_driver mt7988_platform_driver = { | ||
.probe = mt7988_probe, | ||
- .remove = mt7988_remove, | ||
+ .remove_new = mt7988_remove, | ||
.shutdown = mt7988_shutdown, | ||
.driver = { | ||
.name = "mt7530-mmio", |
51 changes: 51 additions & 0 deletions
51
...x/generic/backport-6.6/790-02-v6.7-net-dsa-mt753x-remove-mt753x_phylink_pcs_link_up.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
From d22c85764665af931c5c61bbe282b4116a88e792 Mon Sep 17 00:00:00 2001 | ||
From: "Russell King (Oracle)" <rmk+kernel@armlinux.org.uk> | ||
Date: Wed, 27 Sep 2023 13:13:56 +0100 | ||
Subject: [PATCH 02/30] net: dsa: mt753x: remove mt753x_phylink_pcs_link_up() | ||
|
||
Remove the mt753x_phylink_pcs_link_up() function for two reasons: | ||
|
||
1) priv->pcs[i].pcs.neg_mode is set true, meaning it doesn't take a | ||
MLO_AN_FIXED anymore, but one of PHYLINK_PCS_NEG_*. However, this | ||
is inconsequential due to... | ||
2) priv->pcs[port].pcs.ops is always initialised to point at | ||
mt7530_pcs_ops, which does not have a pcs_link_up() member. | ||
|
||
So, let's remove mt753x_phylink_pcs_link_up() entirely. | ||
|
||
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk> | ||
Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com> | ||
Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com> | ||
Link: https://lore.kernel.org/r/E1qlTQS-008BWe-Va@rmk-PC.armlinux.org.uk | ||
Signed-off-by: Jakub Kicinski <kuba@kernel.org> | ||
--- | ||
drivers/net/dsa/mt7530.c | 11 ----------- | ||
1 file changed, 11 deletions(-) | ||
|
||
--- a/drivers/net/dsa/mt7530.c | ||
+++ b/drivers/net/dsa/mt7530.c | ||
@@ -2860,15 +2860,6 @@ static void mt753x_phylink_mac_link_down | ||
mt7530_clear(priv, MT7530_PMCR_P(port), PMCR_LINK_SETTINGS_MASK); | ||
} | ||
|
||
-static void mt753x_phylink_pcs_link_up(struct phylink_pcs *pcs, | ||
- unsigned int mode, | ||
- phy_interface_t interface, | ||
- int speed, int duplex) | ||
-{ | ||
- if (pcs->ops->pcs_link_up) | ||
- pcs->ops->pcs_link_up(pcs, mode, interface, speed, duplex); | ||
-} | ||
- | ||
static void mt753x_phylink_mac_link_up(struct dsa_switch *ds, int port, | ||
unsigned int mode, | ||
phy_interface_t interface, | ||
@@ -2956,8 +2947,6 @@ mt7531_cpu_port_config(struct dsa_switch | ||
return ret; | ||
mt7530_write(priv, MT7530_PMCR_P(port), | ||
PMCR_CPU_PORT_SETTING(priv->id)); | ||
- mt753x_phylink_pcs_link_up(&priv->pcs[port].pcs, MLO_AN_FIXED, | ||
- interface, speed, DUPLEX_FULL); | ||
mt753x_phylink_mac_link_up(ds, port, MLO_AN_FIXED, interface, NULL, | ||
speed, DUPLEX_FULL, true, true); | ||
|
40 changes: 40 additions & 0 deletions
40
...neric/backport-6.6/790-03-v6.7-net-dsa-mt7530-replace-deprecated-strncpy-with-ethto.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
From 9b4f1f5a0801652056670a38503b4049eb413caf Mon Sep 17 00:00:00 2001 | ||
From: Justin Stitt <justinstitt@google.com> | ||
Date: Mon, 9 Oct 2023 18:29:19 +0000 | ||
Subject: [PATCH 03/30] net: dsa: mt7530: replace deprecated strncpy with | ||
ethtool_sprintf | ||
|
||
`strncpy` is deprecated for use on NUL-terminated destination strings | ||
[1] and as such we should prefer more robust and less ambiguous string | ||
interfaces. | ||
|
||
ethtool_sprintf() is designed specifically for get_strings() usage. | ||
Let's replace strncpy in favor of this more robust and easier to | ||
understand interface. | ||
|
||
Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1] | ||
Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html [2] | ||
Link: https://github.com/KSPP/linux/issues/90 | ||
Signed-off-by: Justin Stitt <justinstitt@google.com> | ||
Reviewed-by: Kees Cook <keescook@chromium.org> | ||
Acked-by: Daniel Golle <daniel@makrotopia.org> | ||
Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com> | ||
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> | ||
Link: https://lore.kernel.org/r/20231009-strncpy-drivers-net-dsa-mt7530-c-v1-1-ec6677a6436a@google.com | ||
Signed-off-by: Jakub Kicinski <kuba@kernel.org> | ||
--- | ||
drivers/net/dsa/mt7530.c | 3 +-- | ||
1 file changed, 1 insertion(+), 2 deletions(-) | ||
|
||
--- a/drivers/net/dsa/mt7530.c | ||
+++ b/drivers/net/dsa/mt7530.c | ||
@@ -836,8 +836,7 @@ mt7530_get_strings(struct dsa_switch *ds | ||
return; | ||
|
||
for (i = 0; i < ARRAY_SIZE(mt7530_mib); i++) | ||
- strncpy(data + i * ETH_GSTRING_LEN, mt7530_mib[i].name, | ||
- ETH_GSTRING_LEN); | ||
+ ethtool_sprintf(&data, "%s", mt7530_mib[i].name); | ||
} | ||
|
||
static void |
116 changes: 116 additions & 0 deletions
116
...neric/backport-6.6/790-04-v6.9-net-dsa-mt7530-support-OF-based-registration-of-swit.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
From af26b0d1bf934bbaa7cafb871a51e95087a088a0 Mon Sep 17 00:00:00 2001 | ||
From: =?UTF-8?q?Ar=C4=B1n=C3=A7=20=C3=9CNAL?= <arinc.unal@arinc9.com> | ||
Date: Mon, 22 Jan 2024 08:34:31 +0300 | ||
Subject: [PATCH 04/30] net: dsa: mt7530: support OF-based registration of | ||
switch MDIO bus | ||
MIME-Version: 1.0 | ||
Content-Type: text/plain; charset=UTF-8 | ||
Content-Transfer-Encoding: 8bit | ||
|
||
Currently the MDIO bus of the switches the MT7530 DSA subdriver controls | ||
can only be registered as non-OF-based. Bring support for registering the | ||
bus OF-based. | ||
|
||
The subdrivers that control switches [with MDIO bus] probed on OF must | ||
follow this logic to support all cases properly: | ||
|
||
No switch MDIO bus defined: Populate ds->user_mii_bus, register the MDIO | ||
bus, set the interrupts for PHYs if "interrupt-controller" is defined at | ||
the switch node. This case should only be covered for the switches which | ||
their dt-bindings documentation didn't document the MDIO bus from the | ||
start. This is to keep supporting the device trees that do not describe the | ||
MDIO bus on the device tree but the MDIO bus is being used nonetheless. | ||
|
||
Switch MDIO bus defined: Don't populate ds->user_mii_bus, register the MDIO | ||
bus, set the interrupts for PHYs if ["interrupt-controller" is defined at | ||
the switch node and "interrupts" is defined at the PHY nodes under the | ||
switch MDIO bus node]. | ||
|
||
Switch MDIO bus defined but explicitly disabled: If the device tree says | ||
status = "disabled" for the MDIO bus, we shouldn't need an MDIO bus at all. | ||
Instead, just exit as early as possible and do not call any MDIO API. | ||
|
||
The use of ds->user_mii_bus is inappropriate when the MDIO bus of the | ||
switch is described on the device tree [1], which is why we don't populate | ||
ds->user_mii_bus in that case. | ||
|
||
Link: https://lore.kernel.org/netdev/20231213120656.x46fyad6ls7sqyzv@skbuf/ [1] | ||
Suggested-by: David Bauer <mail@david-bauer.net> | ||
Signed-off-by: Arınç ÜNAL <arinc.unal@arinc9.com> | ||
Reviewed-by: Vladimir Oltean <olteanv@gmail.com> | ||
Link: https://lore.kernel.org/r/20240122053431.7751-1-arinc.unal@arinc9.com | ||
Signed-off-by: Paolo Abeni <pabeni@redhat.com> | ||
--- | ||
drivers/net/dsa/mt7530.c | 34 ++++++++++++++++++++++++++-------- | ||
1 file changed, 26 insertions(+), 8 deletions(-) | ||
|
||
--- a/drivers/net/dsa/mt7530.c | ||
+++ b/drivers/net/dsa/mt7530.c | ||
@@ -2182,24 +2182,40 @@ mt7530_free_irq_common(struct mt7530_pri | ||
static void | ||
mt7530_free_irq(struct mt7530_priv *priv) | ||
{ | ||
- mt7530_free_mdio_irq(priv); | ||
+ struct device_node *mnp, *np = priv->dev->of_node; | ||
+ | ||
+ mnp = of_get_child_by_name(np, "mdio"); | ||
+ if (!mnp) | ||
+ mt7530_free_mdio_irq(priv); | ||
+ of_node_put(mnp); | ||
+ | ||
mt7530_free_irq_common(priv); | ||
} | ||
|
||
static int | ||
mt7530_setup_mdio(struct mt7530_priv *priv) | ||
{ | ||
+ struct device_node *mnp, *np = priv->dev->of_node; | ||
struct dsa_switch *ds = priv->ds; | ||
struct device *dev = priv->dev; | ||
struct mii_bus *bus; | ||
static int idx; | ||
- int ret; | ||
+ int ret = 0; | ||
+ | ||
+ mnp = of_get_child_by_name(np, "mdio"); | ||
+ | ||
+ if (mnp && !of_device_is_available(mnp)) | ||
+ goto out; | ||
|
||
bus = devm_mdiobus_alloc(dev); | ||
- if (!bus) | ||
- return -ENOMEM; | ||
+ if (!bus) { | ||
+ ret = -ENOMEM; | ||
+ goto out; | ||
+ } | ||
+ | ||
+ if (!mnp) | ||
+ ds->slave_mii_bus = bus; | ||
|
||
- ds->slave_mii_bus = bus; | ||
bus->priv = priv; | ||
bus->name = KBUILD_MODNAME "-mii"; | ||
snprintf(bus->id, MII_BUS_ID_SIZE, KBUILD_MODNAME "-%d", idx++); | ||
@@ -2210,16 +2226,18 @@ mt7530_setup_mdio(struct mt7530_priv *pr | ||
bus->parent = dev; | ||
bus->phy_mask = ~ds->phys_mii_mask; | ||
|
||
- if (priv->irq) | ||
+ if (priv->irq && !mnp) | ||
mt7530_setup_mdio_irq(priv); | ||
|
||
- ret = devm_mdiobus_register(dev, bus); | ||
+ ret = devm_of_mdiobus_register(dev, bus, mnp); | ||
if (ret) { | ||
dev_err(dev, "failed to register MDIO bus: %d\n", ret); | ||
- if (priv->irq) | ||
+ if (priv->irq && !mnp) | ||
mt7530_free_mdio_irq(priv); | ||
} | ||
|
||
+out: | ||
+ of_node_put(mnp); | ||
return ret; | ||
} | ||
|
125 changes: 125 additions & 0 deletions
125
...neric/backport-6.6/790-05-v6.9-net-dsa-mt7530-always-trap-frames-to-active-CPU-port.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
From 617b07e08bcb1f69a72a085a7d847d1ca2999830 Mon Sep 17 00:00:00 2001 | ||
From: =?UTF-8?q?Ar=C4=B1n=C3=A7=20=C3=9CNAL?= <arinc.unal@arinc9.com> | ||
Date: Mon, 22 Jan 2024 08:35:52 +0300 | ||
Subject: [PATCH 05/30] net: dsa: mt7530: always trap frames to active CPU port | ||
on MT7530 | ||
MIME-Version: 1.0 | ||
Content-Type: text/plain; charset=UTF-8 | ||
Content-Transfer-Encoding: 8bit | ||
|
||
On the MT7530 switch, the CPU_PORT field indicates which CPU port to trap | ||
frames to, regardless of the affinity of the inbound user port. | ||
|
||
When multiple CPU ports are in use, if the DSA conduit interface is down, | ||
trapped frames won't be passed to the conduit interface. | ||
|
||
To make trapping frames work including this case, implement | ||
ds->ops->conduit_state_change() on this subdriver and set the CPU_PORT | ||
field to the numerically smallest CPU port whose conduit interface is up. | ||
Introduce the active_cpu_ports field to store the information of the active | ||
CPU ports. Correct the macros, CPU_PORT is bits 4 through 6 of the | ||
register. | ||
|
||
Add a comment to explain frame trapping for this switch. | ||
|
||
Currently, the driver doesn't support the use of multiple CPU ports so this | ||
is not necessarily a bug fix. | ||
|
||
Suggested-by: Vladimir Oltean <olteanv@gmail.com> | ||
Suggested-by: Russell King (Oracle) <linux@armlinux.org.uk> | ||
Signed-off-by: Arınç ÜNAL <arinc.unal@arinc9.com> | ||
Reviewed-by: Vladimir Oltean <olteanv@gmail.com> | ||
Link: https://lore.kernel.org/r/20240122-for-netnext-mt7530-improvements-1-v3-1-042401f2b279@arinc9.com | ||
Signed-off-by: Jakub Kicinski <kuba@kernel.org> | ||
--- | ||
drivers/net/dsa/mt7530.c | 35 +++++++++++++++++++++++++++++++---- | ||
drivers/net/dsa/mt7530.h | 6 ++++-- | ||
2 files changed, 35 insertions(+), 6 deletions(-) | ||
|
||
--- a/drivers/net/dsa/mt7530.c | ||
+++ b/drivers/net/dsa/mt7530.c | ||
@@ -1071,10 +1071,6 @@ mt753x_cpu_port_enable(struct dsa_switch | ||
mt7530_set(priv, MT7530_MFC, BC_FFP(BIT(port)) | UNM_FFP(BIT(port)) | | ||
UNU_FFP(BIT(port))); | ||
|
||
- /* Set CPU port number */ | ||
- if (priv->id == ID_MT7530 || priv->id == ID_MT7621) | ||
- mt7530_rmw(priv, MT7530_MFC, CPU_MASK, CPU_EN | CPU_PORT(port)); | ||
- | ||
/* Add the CPU port to the CPU port bitmap for MT7531 and the switch on | ||
* the MT7988 SoC. Trapped frames will be forwarded to the CPU port that | ||
* is affine to the inbound user port. | ||
@@ -3128,6 +3124,36 @@ static int mt753x_set_mac_eee(struct dsa | ||
return 0; | ||
} | ||
|
||
+static void | ||
+mt753x_conduit_state_change(struct dsa_switch *ds, | ||
+ const struct net_device *conduit, | ||
+ bool operational) | ||
+{ | ||
+ struct dsa_port *cpu_dp = conduit->dsa_ptr; | ||
+ struct mt7530_priv *priv = ds->priv; | ||
+ int val = 0; | ||
+ u8 mask; | ||
+ | ||
+ /* Set the CPU port to trap frames to for MT7530. Trapped frames will be | ||
+ * forwarded to the numerically smallest CPU port whose conduit | ||
+ * interface is up. | ||
+ */ | ||
+ if (priv->id != ID_MT7530 && priv->id != ID_MT7621) | ||
+ return; | ||
+ | ||
+ mask = BIT(cpu_dp->index); | ||
+ | ||
+ if (operational) | ||
+ priv->active_cpu_ports |= mask; | ||
+ else | ||
+ priv->active_cpu_ports &= ~mask; | ||
+ | ||
+ if (priv->active_cpu_ports) | ||
+ val = CPU_EN | CPU_PORT(__ffs(priv->active_cpu_ports)); | ||
+ | ||
+ mt7530_rmw(priv, MT7530_MFC, CPU_EN | CPU_PORT_MASK, val); | ||
+} | ||
+ | ||
static int mt7988_pad_setup(struct dsa_switch *ds, phy_interface_t interface) | ||
{ | ||
return 0; | ||
@@ -3183,6 +3209,7 @@ const struct dsa_switch_ops mt7530_switc | ||
.phylink_mac_link_up = mt753x_phylink_mac_link_up, | ||
.get_mac_eee = mt753x_get_mac_eee, | ||
.set_mac_eee = mt753x_set_mac_eee, | ||
+ .master_state_change = mt753x_conduit_state_change, | ||
}; | ||
EXPORT_SYMBOL_GPL(mt7530_switch_ops); | ||
|
||
--- a/drivers/net/dsa/mt7530.h | ||
+++ b/drivers/net/dsa/mt7530.h | ||
@@ -41,8 +41,8 @@ enum mt753x_id { | ||
#define UNU_FFP(x) (((x) & 0xff) << 8) | ||
#define UNU_FFP_MASK UNU_FFP(~0) | ||
#define CPU_EN BIT(7) | ||
-#define CPU_PORT(x) ((x) << 4) | ||
-#define CPU_MASK (0xf << 4) | ||
+#define CPU_PORT_MASK GENMASK(6, 4) | ||
+#define CPU_PORT(x) FIELD_PREP(CPU_PORT_MASK, x) | ||
#define MIRROR_EN BIT(3) | ||
#define MIRROR_PORT(x) ((x) & 0x7) | ||
#define MIRROR_MASK 0x7 | ||
@@ -780,6 +780,7 @@ struct mt753x_info { | ||
* @irq_domain: IRQ domain of the switch irq_chip | ||
* @irq_enable: IRQ enable bits, synced to SYS_INT_EN | ||
* @create_sgmii: Pointer to function creating SGMII PCS instance(s) | ||
+ * @active_cpu_ports: Holding the active CPU ports | ||
*/ | ||
struct mt7530_priv { | ||
struct device *dev; | ||
@@ -806,6 +807,7 @@ struct mt7530_priv { | ||
struct irq_domain *irq_domain; | ||
u32 irq_enable; | ||
int (*create_sgmii)(struct mt7530_priv *priv, bool dual_sgmii); | ||
+ u8 active_cpu_ports; | ||
}; | ||
|
||
struct mt7530_hw_vlan_entry { |
Oops, something went wrong.