Skip to contentSkip to conversation

net: dsa: mt7530: support setting MTU

PATCH Superseded DENG Qingfang 5 participants 8 messages Oct 28, 2020 – Oct 30, 2020

Subsystems (5)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: dsa: mt7530: support setting MTU

MT7530/7531 has a global RX packet length register, which can be used to set MTU.

---
 drivers/net/dsa/mt7530.c | 36 ++++++++++++++++++++++++++++++++++++
 drivers/net/dsa/mt7530.h | 12 ++++++++++++
 2 files changed, 48 insertions(+)
drivers/net/dsa/mt7530.c +36 -0
index de7692b763d8..7764c66a47c9 100644
@@ -1021,6 +1021,40 @@ mt7530_port_disable(struct dsa_switch *ds, int port)
 	mutex_unlock(&priv->reg_mutex);
 }
 
+static int
+mt7530_port_change_mtu(struct dsa_switch *ds, int port, int new_mtu)
+{
+	struct mt7530_priv *priv = ds->priv;
+	int length;
+
+	/* When a new MTU is set, DSA always set the CPU port's MTU to the largest MTU
+	 * of the slave ports. Because the switch only has a global RX length register,
+	 * only allowing CPU port here is enough.
+	 */
+	if (!dsa_is_cpu_port(ds, port))
+		return 0;
+
+	/* RX length also includes Ethernet header, MTK tag, and FCS length */
+	length = new_mtu + ETH_HLEN + MTK_HDR_LEN + ETH_FCS_LEN;
+	if (length <= 1522)
+		mt7530_rmw(priv, MT7530_GMACCR, MAX_RX_PKT_LEN_MASK, MAX_RX_PKT_LEN_1522);
+	else if (length <= 1536)
+		mt7530_rmw(priv, MT7530_GMACCR, MAX_RX_PKT_LEN_MASK, MAX_RX_PKT_LEN_1536);
+	else if (length <= 1552)
+		mt7530_rmw(priv, MT7530_GMACCR, MAX_RX_PKT_LEN_MASK, MAX_RX_PKT_LEN_1552);
+	else
+		mt7530_rmw(priv, MT7530_GMACCR, MAX_RX_JUMBO_MASK | MAX_RX_PKT_LEN_MASK,
+			MAX_RX_JUMBO(DIV_ROUND_UP(length, 1024)) | MAX_RX_PKT_LEN_JUMBO);
+
+	return 0;
+}
+
+static int
+mt7530_port_max_mtu(struct dsa_switch *ds, int port)
+{
+	return MT7530_MAX_MTU;
+}
+
 static void
 mt7530_stp_state_set(struct dsa_switch *ds, int port, u8 state)
 {
@@ -2519,6 +2553,8 @@ static const struct dsa_switch_ops mt7530_switch_ops = {
 	.get_sset_count		= mt7530_get_sset_count,
 	.port_enable		= mt7530_port_enable,
 	.port_disable		= mt7530_port_disable,
+	.port_change_mtu	= mt7530_port_change_mtu,
+	.port_max_mtu		= mt7530_port_max_mtu,
 	.port_stp_state_set	= mt7530_stp_state_set,
 	.port_bridge_join	= mt7530_port_bridge_join,
 	.port_bridge_leave	= mt7530_port_bridge_leave,
drivers/net/dsa/mt7530.h +12 -0
index 9278a8e3d04e..77a6222d2635 100644
@@ -11,6 +11,9 @@
 #define MT7530_NUM_FDB_RECORDS		2048
 #define MT7530_ALL_MEMBERS		0xff
 
+#define MTK_HDR_LEN			4
+#define MT7530_MAX_MTU			(15 * 1024 - ETH_HLEN - ETH_FCS_LEN - MTK_HDR_LEN)
+
 enum mt753x_id {
 	ID_MT7530 = 0,
 	ID_MT7621 = 1,
@@ -289,6 +292,15 @@ enum mt7530_vlan_port_attr {
 #define MT7531_DBG_CNT(x)		(0x3018 + (x) * 0x100)
 #define  MT7531_DIS_CLR			BIT(31)
 
+#define MT7530_GMACCR			0x30e0
+#define  MAX_RX_JUMBO(x)		((x) << 2)
+#define  MAX_RX_JUMBO_MASK		GENMASK(5, 2)
+#define  MAX_RX_PKT_LEN_MASK		GENMASK(1, 0)
+#define  MAX_RX_PKT_LEN_1522		0x0
+#define  MAX_RX_PKT_LEN_1536		0x1
+#define  MAX_RX_PKT_LEN_1552		0x2
+#define  MAX_RX_PKT_LEN_JUMBO		0x3
+
 /* Register for MIB */
 #define MT7530_PORT_MIB_COUNTER(x)	(0x4000 + (x) * 0x100)
 #define MT7530_MIB_CCR			0x4fe0
Signature · 1 line
2.25.1
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to DENG Qingfang
Quoted 5 lines · DENG Qingfang

MT7530/7531 has a global RX packet length register, which can be used to set MTU.

---

Also, please format your patches with --subject-prefix="PATCH net-next" in the future. Jakub installed some patchwork scripts that "guess" the tree based on the commit message, but maybe sometimes they might fail:

https://patchwork.ozlabs.org/project/netdev/patch/e5fdcddeda21884a21162e441d1e8a04994f2825.1603837679.git.pavana.sharma@digi.com/

Quoted 12 lines
 drivers/net/dsa/mt7530.c | 36 ++++++++++++++++++++++++++++++++++++
 drivers/net/dsa/mt7530.h | 12 ++++++++++++
 2 files changed, 48 insertions(+)
drivers/net/dsa/mt7530.c +0 -0
index de7692b763d8..7764c66a47c9 100644
@@ -1021,6 +1021,40 @@ mt7530_port_disable(struct dsa_switch *ds, int port)
 	mutex_unlock(&priv->reg_mutex);
 }
 

drivers/net/dsa/mt7530.c mt7530_port_disable(struct dsa_switch *ds, int port) · line 1033

Quoted 10 lines
drivers/net/dsa/mt7530.c +10 -0
+static int
+mt7530_port_change_mtu(struct dsa_switch *ds, int port, int new_mtu)
+{
+	struct mt7530_priv *priv = ds->priv;
+	int length;
+
+	/* When a new MTU is set, DSA always set the CPU port's MTU to the largest MTU
+	 * of the slave ports. Because the switch only has a global RX length register,
+	 * only allowing CPU port here is enough.
+	 */

Good point, please tell that to Linus (cc) - I'm talking about e0b2e0d8e669 ("net: dsa: rtl8366rb: Roof MTU for switch"),

Quoted 36 lines
drivers/net/dsa/mt7530.c +26 -0
+	if (!dsa_is_cpu_port(ds, port))
+		return 0;
+
+	/* RX length also includes Ethernet header, MTK tag, and FCS length */
+	length = new_mtu + ETH_HLEN + MTK_HDR_LEN + ETH_FCS_LEN;
+	if (length <= 1522)
+		mt7530_rmw(priv, MT7530_GMACCR, MAX_RX_PKT_LEN_MASK, MAX_RX_PKT_LEN_1522);
+	else if (length <= 1536)
+		mt7530_rmw(priv, MT7530_GMACCR, MAX_RX_PKT_LEN_MASK, MAX_RX_PKT_LEN_1536);
+	else if (length <= 1552)
+		mt7530_rmw(priv, MT7530_GMACCR, MAX_RX_PKT_LEN_MASK, MAX_RX_PKT_LEN_1552);
+	else
+		mt7530_rmw(priv, MT7530_GMACCR, MAX_RX_JUMBO_MASK | MAX_RX_PKT_LEN_MASK,
+			MAX_RX_JUMBO(DIV_ROUND_UP(length, 1024)) | MAX_RX_PKT_LEN_JUMBO);
+
+	return 0;
+}
+
+static int
+mt7530_port_max_mtu(struct dsa_switch *ds, int port)
+{
+	return MT7530_MAX_MTU;
+}
+
 static void
 mt7530_stp_state_set(struct dsa_switch *ds, int port, u8 state)
 {
@@ -2519,6 +2553,8 @@ static const struct dsa_switch_ops mt7530_switch_ops = {
 	.get_sset_count		= mt7530_get_sset_count,
 	.port_enable		= mt7530_port_enable,
 	.port_disable		= mt7530_port_disable,
+	.port_change_mtu	= mt7530_port_change_mtu,
+	.port_max_mtu		= mt7530_port_max_mtu,
 	.port_stp_state_set	= mt7530_stp_state_set,
 	.port_bridge_join	= mt7530_port_bridge_join,
 	.port_bridge_leave	= mt7530_port_bridge_leave,
#3 lore raw
Quoted 28 lines · Vladimir Oltean
Quoted 5 lines · DENG Qingfang

MT7530/7531 has a global RX packet length register, which can be used to set MTU.

---

Also, please format your patches with --subject-prefix="PATCH net-next" in the future. Jakub installed some patchwork scripts that "guess" the tree based on the commit message, but maybe sometimes they might fail:

https://patchwork.ozlabs.org/project/netdev/patch/e5fdcddeda21884a21162e441d1e8a04994f2825.1603837679.git.pavana.sharma@digi.com/

Quoted 12 lines
 drivers/net/dsa/mt7530.c | 36 ++++++++++++++++++++++++++++++++++++
 drivers/net/dsa/mt7530.h | 12 ++++++++++++
 2 files changed, 48 insertions(+)
drivers/net/dsa/mt7530.c +0 -0
index de7692b763d8..7764c66a47c9 100644
@@ -1021,6 +1021,40 @@ mt7530_port_disable(struct dsa_switch *ds, int port)
      mutex_unlock(&priv->reg_mutex);
 }
 
Quoted 13 lines

drivers/net/dsa/mt7530.c mt7530_port_disable(struct dsa_switch *ds, int port) · line 1033

Quoted 10 lines
drivers/net/dsa/mt7530.c +10 -0
+static int
+mt7530_port_change_mtu(struct dsa_switch *ds, int port, int new_mtu)
+{
+     struct mt7530_priv *priv = ds->priv;
+     int length;
+
+     /* When a new MTU is set, DSA always set the CPU port's MTU to the largest MTU
+      * of the slave ports. Because the switch only has a global RX length register,
+      * only allowing CPU port here is enough.
+      */

Good point, please tell that to Linus (cc) - I'm talking about e0b2e0d8e669 ("net: dsa: rtl8366rb: Roof MTU for switch"),

And 6ae5834b983a ("net: dsa: b53: add MTU configuration support"), 1baf0fac10fb ("net: dsa: mv88e6xxx: Use chip-wide max frame size for MTU"), f58d2598cf70 ("net: dsa: qca8k: implement the port MTU callbacks")

CC'd them as well.

Also, the commit e0b2e0d8e669 states that the new_mtu parameter is L2 frame length instead of L2 payload. But according to my tests, it is L2 payload (i.e. the same as the MTU shown in ip link or ifconfig. Is that right?

Quoted 37 lines
Quoted 37 lines
drivers/net/dsa/mt7530.c +26 -0
+     if (!dsa_is_cpu_port(ds, port))
+             return 0;
+
+     /* RX length also includes Ethernet header, MTK tag, and FCS length */
+     length = new_mtu + ETH_HLEN + MTK_HDR_LEN + ETH_FCS_LEN;
+     if (length <= 1522)
+             mt7530_rmw(priv, MT7530_GMACCR, MAX_RX_PKT_LEN_MASK, MAX_RX_PKT_LEN_1522);
+     else if (length <= 1536)
+             mt7530_rmw(priv, MT7530_GMACCR, MAX_RX_PKT_LEN_MASK, MAX_RX_PKT_LEN_1536);
+     else if (length <= 1552)
+             mt7530_rmw(priv, MT7530_GMACCR, MAX_RX_PKT_LEN_MASK, MAX_RX_PKT_LEN_1552);
+     else
+             mt7530_rmw(priv, MT7530_GMACCR, MAX_RX_JUMBO_MASK | MAX_RX_PKT_LEN_MASK,
+                     MAX_RX_JUMBO(DIV_ROUND_UP(length, 1024)) | MAX_RX_PKT_LEN_JUMBO);
+
+     return 0;
+}
+
+static int
+mt7530_port_max_mtu(struct dsa_switch *ds, int port)
+{
+     return MT7530_MAX_MTU;
+}
+
 static void
 mt7530_stp_state_set(struct dsa_switch *ds, int port, u8 state)
 {
@@ -2519,6 +2553,8 @@ static const struct dsa_switch_ops mt7530_switch_ops = {
      .get_sset_count         = mt7530_get_sset_count,
      .port_enable            = mt7530_port_enable,
      .port_disable           = mt7530_port_disable,
+     .port_change_mtu        = mt7530_port_change_mtu,
+     .port_max_mtu           = mt7530_port_max_mtu,
      .port_stp_state_set     = mt7530_stp_state_set,
      .port_bridge_join       = mt7530_port_bridge_join,
      .port_bridge_leave      = mt7530_port_bridge_leave,
#5 lore raw
In reply to Jonathan McDowell
Quoted 24 lines · Jonathan McDowell
Quoted 3 lines · DENG Qingfang
Quoted 2 lines · Vladimir Oltean

On Thu, Oct 29, 2020 at 02:12:21AM +0800, DENG Qingfang wrote:

...

Quoted 18 lines
Quoted 5 lines
Quoted 5 lines
drivers/net/dsa/mt7530.c +5 -0
+static int
+mt7530_port_change_mtu(struct dsa_switch *ds, int port, int new_mtu)
+{
+     struct mt7530_priv *priv = ds->priv;
+     int length;
Quoted 8 lines

drivers/net/dsa/mt7530.c mt7530_port_disable(struct dsa_switch *ds, int port) · line 1033

Quoted 5 lines
drivers/net/dsa/mt7530.c +5 -0
+
+     /* When a new MTU is set, DSA always set the CPU port's MTU to the largest MTU
+      * of the slave ports. Because the switch only has a global RX length register,
+      * only allowing CPU port here is enough.
+      */

Good point, please tell that to Linus (cc) - I'm talking about e0b2e0d8e669 ("net: dsa: rtl8366rb: Roof MTU for switch"),

And 6ae5834b983a ("net: dsa: b53: add MTU configuration support"), 1baf0fac10fb ("net: dsa: mv88e6xxx: Use chip-wide max frame size for MTU"), f58d2598cf70 ("net: dsa: qca8k: implement the port MTU callbacks")

Quoted 5 lines
Quoted 1 line

CC'd them as well.

qca8k tracks and use the maximum provided mtu; perhaps that could be optimised by only allow the CPU port to be set but it feels a bit more future proof (e.g. if/when we support multiple CPU ports).

btw, there is a bug in your commit f58d2598cf70, in qca8k_port_change_mtu the loop variable is not used inside the for loop.

Quoted 15 lines
Quoted 5 lines

Also, the commit e0b2e0d8e669 states that the new_mtu parameter is L2 frame length instead of L2 payload. But according to my tests, it is L2 payload (i.e. the same as the MTU shown in ip link or ifconfig. Is that right?

Certainly that's what I saw; qca8k sets the MTU to the provided MTU + ETH_HLEN + ETH_FCS_LEN.

J.

--
Pretty please, with sugar on top, clean the f**king car. This .sig brought to you by the letter J and the number 13 Product of the Republic of HuggieTag

#4 lore raw
In reply to DENG Qingfang
Quoted 3 lines · DENG Qingfang
Quoted 2 lines · Vladimir Oltean

On Thu, Oct 29, 2020 at 02:12:21AM +0800, DENG Qingfang wrote:

...

Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
drivers/net/dsa/mt7530.c +5 -0
+static int
+mt7530_port_change_mtu(struct dsa_switch *ds, int port, int new_mtu)
+{
+     struct mt7530_priv *priv = ds->priv;
+     int length;
Quoted 8 lines

drivers/net/dsa/mt7530.c mt7530_port_disable(struct dsa_switch *ds, int port) · line 1033

Quoted 5 lines
drivers/net/dsa/mt7530.c +5 -0
+
+     /* When a new MTU is set, DSA always set the CPU port's MTU to the largest MTU
+      * of the slave ports. Because the switch only has a global RX length register,
+      * only allowing CPU port here is enough.
+      */

Good point, please tell that to Linus (cc) - I'm talking about e0b2e0d8e669 ("net: dsa: rtl8366rb: Roof MTU for switch"),

Quoted 5 lines

And 6ae5834b983a ("net: dsa: b53: add MTU configuration support"), 1baf0fac10fb ("net: dsa: mv88e6xxx: Use chip-wide max frame size for MTU"), f58d2598cf70 ("net: dsa: qca8k: implement the port MTU callbacks")

CC'd them as well.

qca8k tracks and use the maximum provided mtu; perhaps that could be optimised by only allow the CPU port to be set but it feels a bit more future proof (e.g. if/when we support multiple CPU ports).

Quoted 4 lines

Also, the commit e0b2e0d8e669 states that the new_mtu parameter is L2 frame length instead of L2 payload. But according to my tests, it is L2 payload (i.e. the same as the MTU shown in ip link or ifconfig. Is that right?

Certainly that's what I saw; qca8k sets the MTU to the provided MTU + ETH_HLEN + ETH_FCS_LEN.

J.

Signature · 3 lines
Pretty please, with sugar on top, clean the f**king car.
This .sig brought to you by the letter J and the number 13
Product of the Republic of HuggieTag
maintainer
#6 lore raw
In reply to DENG Qingfang
Quoted 4 lines · On Thu, 29 Oct 2020 02:12:21 +0800 DENG Qingfang wrote:

MT7530/7531 has a global RX packet length register, which can be used to set MTU.

Please wrap your code at 80 chars.

Quoted 22 lines
drivers/net/dsa/mt7530.c +14 -0
index de7692b763d8..7764c66a47c9 100644
@@ -1021,6 +1021,40 @@ mt7530_port_disable(struct dsa_switch *ds, int port)
 	mutex_unlock(&priv->reg_mutex);
 }
 
+static int
+mt7530_port_change_mtu(struct dsa_switch *ds, int port, int new_mtu)
+{
+	struct mt7530_priv *priv = ds->priv;
+	int length;
+
+	/* When a new MTU is set, DSA always set the CPU port's MTU to the largest MTU
+	 * of the slave ports. Because the switch only has a global RX length register,
+	 * only allowing CPU port here is enough.
+	 */
+	if (!dsa_is_cpu_port(ds, port))
+		return 0;
+
+	/* RX length also includes Ethernet header, MTK tag, and FCS length */

drivers/net/dsa/mt7530.c mt7530_port_disable(struct dsa_switch *ds, int port) · line 1047

Quoted 10 lines
drivers/net/dsa/mt7530.c +10 -0
+	length = new_mtu + ETH_HLEN + MTK_HDR_LEN + ETH_FCS_LEN;
+	if (length <= 1522)
+		mt7530_rmw(priv, MT7530_GMACCR, MAX_RX_PKT_LEN_MASK, MAX_RX_PKT_LEN_1522);
+	else if (length <= 1536)
+		mt7530_rmw(priv, MT7530_GMACCR, MAX_RX_PKT_LEN_MASK, MAX_RX_PKT_LEN_1536);
+	else if (length <= 1552)
+		mt7530_rmw(priv, MT7530_GMACCR, MAX_RX_PKT_LEN_MASK, MAX_RX_PKT_LEN_1552);
+	else
+		mt7530_rmw(priv, MT7530_GMACCR, MAX_RX_JUMBO_MASK | MAX_RX_PKT_LEN_MASK,
+			MAX_RX_JUMBO(DIV_ROUND_UP(length, 1024)) | MAX_RX_PKT_LEN_JUMBO);

this line should start under priv, so it aligns to the opening parenthesis.

Besides, don't you need to reset the JUMBO bit when going from jumbo to non-jumbo? The mask should always include jumbo.

I assume you're duplicating the mt7530_rmw() for the benefit of the constant validation, but it seems to be counterproductive here.

Quoted 2 lines
drivers/net/dsa/mt7530.c +2 -0
+	return 0;
+}
#7 lore raw
Quoted 45 lines · Jakub Kicinski
Quoted 4 lines · On Thu, 29 Oct 2020 02:12:21 +0800 DENG Qingfang wrote:

MT7530/7531 has a global RX packet length register, which can be used to set MTU.

Please wrap your code at 80 chars.

Quoted 22 lines
drivers/net/dsa/mt7530.c +14 -0
index de7692b763d8..7764c66a47c9 100644
@@ -1021,6 +1021,40 @@ mt7530_port_disable(struct dsa_switch *ds, int port)
      mutex_unlock(&priv->reg_mutex);
 }
 
+static int
+mt7530_port_change_mtu(struct dsa_switch *ds, int port, int new_mtu)
+{
+     struct mt7530_priv *priv = ds->priv;
+     int length;
+
+     /* When a new MTU is set, DSA always set the CPU port's MTU to the largest MTU
+      * of the slave ports. Because the switch only has a global RX length register,
+      * only allowing CPU port here is enough.
+      */
+     if (!dsa_is_cpu_port(ds, port))
+             return 0;
+
+     /* RX length also includes Ethernet header, MTK tag, and FCS length */

drivers/net/dsa/mt7530.c mt7530_port_disable(struct dsa_switch *ds, int port) · line 1047

Quoted 10 lines
drivers/net/dsa/mt7530.c +10 -0
+     length = new_mtu + ETH_HLEN + MTK_HDR_LEN + ETH_FCS_LEN;
+     if (length <= 1522)
+             mt7530_rmw(priv, MT7530_GMACCR, MAX_RX_PKT_LEN_MASK, MAX_RX_PKT_LEN_1522);
+     else if (length <= 1536)
+             mt7530_rmw(priv, MT7530_GMACCR, MAX_RX_PKT_LEN_MASK, MAX_RX_PKT_LEN_1536);
+     else if (length <= 1552)
+             mt7530_rmw(priv, MT7530_GMACCR, MAX_RX_PKT_LEN_MASK, MAX_RX_PKT_LEN_1552);
+     else
+             mt7530_rmw(priv, MT7530_GMACCR, MAX_RX_JUMBO_MASK | MAX_RX_PKT_LEN_MASK,
+                     MAX_RX_JUMBO(DIV_ROUND_UP(length, 1024)) | MAX_RX_PKT_LEN_JUMBO);

this line should start under priv, so it aligns to the opening parenthesis.

Quoted 2 lines

Besides, don't you need to reset the JUMBO bit when going from jumbo to non-jumbo? The mask should always include jumbo.

MAX_RX_JUMBO works only when MAX_RX_PKT_LEN is set to 0x3, so just changing MAX_RX_PKT_LEN to non-jumbo is enough.
FYI, the default value of MAX_RX_JUMBO is 0x9.

Quoted 3 lines

I assume you're duplicating the mt7530_rmw() for the benefit of the constant validation, but it seems to be counterproductive here.

As I mentioned above, MAX_RX_JUMBO does not need to be changed when going from jumbo to non-jumbo.
Perhaps I should use mt7530_mii_read() and mt7530_mii_write() instead?

Quoted 4 lines
Quoted 3 lines
drivers/net/dsa/mt7530.c +2 -0
+     return 0;
+}