netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vladimir Oltean <olteanv@gmail.com>
To: andrew@lunn.ch, f.fainelli@gmail.com, vivien.didelot@gmail.com,
	davem@davemloft.net, jakub.kicinski@netronome.com
Cc: murali.policharla@broadcom.com, stephen@networkplumber.org,
	jiri@resnulli.us, idosch@idosch.org, kuba@kernel.org,
	nikolay@cumulusnetworks.com, netdev@vger.kernel.org
Subject: [PATCH v2 net-next 07/10] net: dsa: sja1105: Implement the port MTU callbacks
Date: Wed, 25 Mar 2020 17:22:06 +0200	[thread overview]
Message-ID: <20200325152209.3428-8-olteanv@gmail.com> (raw)
In-Reply-To: <20200325152209.3428-1-olteanv@gmail.com>

From: Vladimir Oltean <vladimir.oltean@nxp.com>

On this switch, the frame length enforcements are performed by the
ingress policers. There are 2 types of those: regular L2 (also called
best-effort) and Virtual Link policers (an ARINC664/AFDX concept for
defining L2 streams with certain QoS abilities). To avoid future
confusion, I prefer to call the reset reason "Best-effort policers",
even though the VL policers are not yet supported.

We also need to change the setup of the initial static config, such that
DSA calls to .change_mtu (which are expensive) become no-ops and don't
reset the switch 5 times.

A driver-level decision is to unconditionally allow single VLAN-tagged
traffic on all ports. The CPU port must accept an additional VLAN header
for the DSA tag, which is again a driver-level decision.

The policers actually count bytes not only from the SDU, but also from
the Ethernet header and FCS, so those need to be accounted for as well.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
 drivers/net/dsa/sja1105/sja1105.h      |  1 +
 drivers/net/dsa/sja1105/sja1105_main.c | 48 +++++++++++++++++++++++---
 2 files changed, 45 insertions(+), 4 deletions(-)

diff --git a/drivers/net/dsa/sja1105/sja1105.h b/drivers/net/dsa/sja1105/sja1105.h
index a358fc89a6db..0e5b739b2fe8 100644
--- a/drivers/net/dsa/sja1105/sja1105.h
+++ b/drivers/net/dsa/sja1105/sja1105.h
@@ -126,6 +126,7 @@ enum sja1105_reset_reason {
 	SJA1105_RX_HWTSTAMPING,
 	SJA1105_AGEING_TIME,
 	SJA1105_SCHEDULING,
+	SJA1105_BEST_EFFORT_POLICING,
 };
 
 int sja1105_static_config_reload(struct sja1105_private *priv,
diff --git a/drivers/net/dsa/sja1105/sja1105_main.c b/drivers/net/dsa/sja1105/sja1105_main.c
index e0c99bb63cdf..5f3392e5678b 100644
--- a/drivers/net/dsa/sja1105/sja1105_main.c
+++ b/drivers/net/dsa/sja1105/sja1105_main.c
@@ -519,12 +519,12 @@ static int sja1105_init_avb_params(struct sja1105_private *priv)
 #define SJA1105_RATE_MBPS(speed) (((speed) * 64000) / 1000)
 
 static void sja1105_setup_policer(struct sja1105_l2_policing_entry *policing,
-				  int index)
+				  int index, int mtu)
 {
 	policing[index].sharindx = index;
 	policing[index].smax = 65535; /* Burst size in bytes */
 	policing[index].rate = SJA1105_RATE_MBPS(1000);
-	policing[index].maxlen = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
+	policing[index].maxlen = mtu;
 	policing[index].partition = 0;
 }
 
@@ -556,12 +556,16 @@ static int sja1105_init_l2_policing(struct sja1105_private *priv)
 	 */
 	for (i = 0, k = 0; i < SJA1105_NUM_PORTS; i++) {
 		int bcast = (SJA1105_NUM_PORTS * SJA1105_NUM_TC) + i;
+		int mtu = VLAN_ETH_FRAME_LEN + ETH_FCS_LEN;
+
+		if (dsa_is_cpu_port(priv->ds, i))
+			mtu += VLAN_HLEN;
 
 		for (j = 0; j < SJA1105_NUM_TC; j++, k++)
-			sja1105_setup_policer(policing, k);
+			sja1105_setup_policer(policing, k, mtu);
 
 		/* Set up this port's policer for broadcast traffic */
-		sja1105_setup_policer(policing, bcast);
+		sja1105_setup_policer(policing, bcast, mtu);
 	}
 	return 0;
 }
@@ -1544,6 +1548,7 @@ static const char * const sja1105_reset_reasons[] = {
 	[SJA1105_RX_HWTSTAMPING] = "RX timestamping",
 	[SJA1105_AGEING_TIME] = "Ageing time",
 	[SJA1105_SCHEDULING] = "Time-aware scheduling",
+	[SJA1105_BEST_EFFORT_POLICING] = "Best-effort policing",
 };
 
 /* For situations where we need to change a setting at runtime that is only
@@ -2120,6 +2125,39 @@ static int sja1105_set_ageing_time(struct dsa_switch *ds,
 	return sja1105_static_config_reload(priv, SJA1105_AGEING_TIME);
 }
 
+static int sja1105_change_mtu(struct dsa_switch *ds, int port, int new_mtu)
+{
+	int bcast = (SJA1105_NUM_PORTS * SJA1105_NUM_TC) + port;
+	struct sja1105_l2_policing_entry *policing;
+	struct sja1105_private *priv = ds->priv;
+	int tc;
+
+	new_mtu += VLAN_ETH_HLEN + ETH_FCS_LEN;
+
+	if (dsa_is_cpu_port(ds, port))
+		new_mtu += VLAN_HLEN;
+
+	policing = priv->static_config.tables[BLK_IDX_L2_POLICING].entries;
+
+	/* We set all 9 port policers to the same value, so just checking the
+	 * broadcast one is fine.
+	 */
+	if (policing[bcast].maxlen == new_mtu)
+		return 0;
+
+	for (tc = 0; tc < SJA1105_NUM_TC; tc++)
+		policing[port * SJA1105_NUM_TC + tc].maxlen = new_mtu;
+
+	policing[bcast].maxlen = new_mtu;
+
+	return sja1105_static_config_reload(priv, SJA1105_BEST_EFFORT_POLICING);
+}
+
+static int sja1105_get_max_mtu(struct dsa_switch *ds, int port)
+{
+	return 2043 - VLAN_ETH_HLEN - ETH_FCS_LEN;
+}
+
 static int sja1105_port_setup_tc(struct dsa_switch *ds, int port,
 				 enum tc_setup_type type,
 				 void *type_data)
@@ -2215,6 +2253,8 @@ static const struct dsa_switch_ops sja1105_switch_ops = {
 	.setup			= sja1105_setup,
 	.teardown		= sja1105_teardown,
 	.set_ageing_time	= sja1105_set_ageing_time,
+	.port_change_mtu	= sja1105_change_mtu,
+	.port_max_mtu		= sja1105_get_max_mtu,
 	.phylink_validate	= sja1105_phylink_validate,
 	.phylink_mac_link_state	= sja1105_mac_pcs_get_state,
 	.phylink_mac_config	= sja1105_mac_config,
-- 
2.17.1


  parent reply	other threads:[~2020-03-25 15:22 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-25 15:21 [PATCH v2 net-next 00/10] Configure the MTU on DSA switches Vladimir Oltean
2020-03-25 15:22 ` [PATCH v2 net-next 01/10] net: dsa: configure the MTU for switch ports Vladimir Oltean
2020-03-25 15:22 ` [PATCH v2 net-next 02/10] net: phy: bcm7xx: Add jumbo frame configuration to PHY Vladimir Oltean
2020-03-25 15:44   ` Heiner Kallweit
2020-03-25 22:45     ` Vladimir Oltean
2020-03-25 23:02       ` Florian Fainelli
2020-03-25 23:21       ` Heiner Kallweit
2020-03-25 15:22 ` [PATCH v2 net-next 03/10] bgmac: Add support for Jumbo frames Vladimir Oltean
2020-03-25 15:22 ` [PATCH v2 net-next 04/10] bgmac: Add MTU configuration support to the driver Vladimir Oltean
2020-03-25 15:22 ` [PATCH v2 net-next 05/10] bgmac: Add DMA support to handle frames beyond 8192 bytes Vladimir Oltean
2020-03-25 23:07   ` Florian Fainelli
2020-03-25 15:22 ` [PATCH v2 net-next 06/10] net: dsa: b53: Add MTU configuration support Vladimir Oltean
2020-03-25 23:21   ` Florian Fainelli
2020-03-26  0:48     ` Vladimir Oltean
2020-03-25 15:22 ` Vladimir Oltean [this message]
2020-03-25 23:08   ` [PATCH v2 net-next 07/10] net: dsa: sja1105: Implement the port MTU callbacks Florian Fainelli
2020-03-25 15:22 ` [PATCH v2 net-next 08/10] net: dsa: vsc73xx: Make the MTU configurable Vladimir Oltean
2020-03-25 23:09   ` Florian Fainelli
2020-03-25 15:22 ` [PATCH v2 net-next 09/10] net: dsa: felix: support changing the MTU Vladimir Oltean
2020-03-25 23:10   ` Florian Fainelli
2020-03-25 15:22 ` [PATCH v2 net-next 10/10] net: bridge: implement auto-normalization of MTU for hardware datapath Vladimir Oltean
2020-03-25 23:17   ` Florian Fainelli
2020-03-26  0:30     ` Vladimir Oltean
2020-03-26 10:17   ` Ido Schimmel
2020-03-26 10:25     ` Vladimir Oltean
2020-03-26 11:35       ` Ido Schimmel
2020-03-26 11:44         ` Vladimir Oltean
2020-03-26 11:54           ` Ido Schimmel
2020-03-26 12:34             ` Vladimir Oltean
2020-03-26 12:59               ` Ido Schimmel
2020-03-26 12:06         ` Nikolay Aleksandrov
2020-03-26 12:18           ` Vladimir Oltean
2020-03-26 12:19             ` Nikolay Aleksandrov
2020-03-26 12:25               ` Vladimir Oltean
2020-03-26 12:38                 ` Nikolay Aleksandrov
2020-03-26 18:49                   ` Jakub Kicinski
2020-03-26 19:41                     ` Nikolay Aleksandrov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200325152209.3428-8-olteanv@gmail.com \
    --to=olteanv@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=f.fainelli@gmail.com \
    --cc=idosch@idosch.org \
    --cc=jakub.kicinski@netronome.com \
    --cc=jiri@resnulli.us \
    --cc=kuba@kernel.org \
    --cc=murali.policharla@broadcom.com \
    --cc=netdev@vger.kernel.org \
    --cc=nikolay@cumulusnetworks.com \
    --cc=stephen@networkplumber.org \
    --cc=vivien.didelot@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).