* [PATCH net-next] net: dsa: mt7530: Add TBF qdisc offload support
@ 2024-10-30 19:29 Lorenzo Bianconi
2024-10-31 7:10 ` Arınç ÜNAL
0 siblings, 1 reply; 5+ messages in thread
From: Lorenzo Bianconi @ 2024-10-30 19:29 UTC (permalink / raw)
To: Arınç ÜNAL, Daniel Golle, DENG Qingfang, Sean Wang,
Andrew Lunn, Florian Fainelli, Vladimir Oltean, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Matthias Brugger,
AngeloGioacchino Del Regno
Cc: netdev, linux-arm-kernel, linux-mediatek, Lorenzo Bianconi
Introduce port_setup_tc callback in mt7530 dsa driver in order to enable
dsa ports rate shaping via hw Token Bucket Filter (TBF) for hw switched
traffic. Enable hw TBF just for EN7581 SoC for the moment.
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
drivers/net/dsa/mt7530.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++
drivers/net/dsa/mt7530.h | 12 +++++++++++
2 files changed, 66 insertions(+)
diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
index d84ee1b419a614dda5f440e6571cff5f4f27bf21..0adf69ac8827cd66cdc44f9bc43d27ab8acb785c 100644
--- a/drivers/net/dsa/mt7530.c
+++ b/drivers/net/dsa/mt7530.c
@@ -21,6 +21,7 @@
#include <linux/gpio/consumer.h>
#include <linux/gpio/driver.h>
#include <net/dsa.h>
+#include <net/pkt_cls.h>
#include "mt7530.h"
@@ -3146,6 +3147,58 @@ mt753x_conduit_state_change(struct dsa_switch *ds,
mt7530_rmw(priv, MT753X_MFC, MT7530_CPU_EN | MT7530_CPU_PORT_MASK, val);
}
+static int mt753x_tc_setup_qdisc_tbf(struct mt7530_priv *priv, int port,
+ struct tc_tbf_qopt_offload *qopt)
+{
+ struct tc_tbf_qopt_offload_replace_params *p = &qopt->replace_params;
+ u32 rate = 0;
+
+ switch (qopt->command) {
+ case TC_TBF_REPLACE:
+ rate = div_u64(p->rate.rate_bytes_ps, 1000) << 3; /* kbps */
+ fallthrough;
+ case TC_TBF_DESTROY: {
+ u32 val, tick;
+
+ mt7530_rmw(priv, MT7530_GERLCR, EGR_BC_MASK,
+ EGR_BC_CRC_IPG_PREAMBLE);
+
+ /* if rate is greater than 10Mbps tick is 1/32 ms,
+ * 1ms otherwise
+ */
+ tick = rate > 10000 ? 2 : 7;
+ val = FIELD_PREP(ERLCR_CIR_MASK, (rate >> 5)) |
+ FIELD_PREP(ERLCR_EXP_MASK, tick) |
+ ERLCR_TBF_MODE_MASK |
+ FIELD_PREP(ERLCR_MANT_MASK, 0xf);
+ if (rate)
+ val |= ERLCR_EN_MASK;
+ mt7530_write(priv, MT7530_ERLCR_P(port), val);
+ break;
+ }
+ default:
+ return -EOPNOTSUPP;
+ }
+
+ return 0;
+}
+
+static int mt753x_setup_tc(struct dsa_switch *ds, int port,
+ enum tc_setup_type type, void *type_data)
+{
+ struct mt7530_priv *priv = ds->priv;
+
+ if (priv->id != ID_EN7581)
+ return -EOPNOTSUPP;
+
+ switch (type) {
+ case TC_SETUP_QDISC_TBF:
+ return mt753x_tc_setup_qdisc_tbf(priv, port, type_data);
+ default:
+ return -EOPNOTSUPP;
+ }
+}
+
static int mt7988_setup(struct dsa_switch *ds)
{
struct mt7530_priv *priv = ds->priv;
@@ -3193,6 +3246,7 @@ const struct dsa_switch_ops mt7530_switch_ops = {
.get_mac_eee = mt753x_get_mac_eee,
.set_mac_eee = mt753x_set_mac_eee,
.conduit_state_change = mt753x_conduit_state_change,
+ .port_setup_tc = mt753x_setup_tc,
};
EXPORT_SYMBOL_GPL(mt7530_switch_ops);
diff --git a/drivers/net/dsa/mt7530.h b/drivers/net/dsa/mt7530.h
index 6ad33a9f6b1dff3a423baa668a8a2ca158f72b91..9467f2a3f2bca45b3fce3bace2b3b3205158c4bd 100644
--- a/drivers/net/dsa/mt7530.h
+++ b/drivers/net/dsa/mt7530.h
@@ -248,6 +248,18 @@ enum mt7530_vlan_egress_attr {
#define AGE_UNIT_MAX 0xfff
#define AGE_UNIT(x) (AGE_UNIT_MASK & (x))
+#define MT7530_ERLCR_P(x) (0x1040 + ((x) * 0x100))
+#define ERLCR_CIR_MASK GENMASK(31, 16)
+#define ERLCR_EN_MASK BIT(15)
+#define ERLCR_EXP_MASK GENMASK(11, 8)
+#define ERLCR_TBF_MODE_MASK BIT(7)
+#define ERLCR_MANT_MASK GENMASK(6, 0)
+
+#define MT7530_GERLCR 0x10e0
+#define EGR_BC_MASK GENMASK(7, 0)
+#define EGR_BC_CRC 0x4 /* crc */
+#define EGR_BC_CRC_IPG_PREAMBLE 0x18 /* crc + ipg + preamble */
+
/* Register for port STP state control */
#define MT7530_SSP_P(x) (0x2000 + ((x) * 0x100))
#define FID_PST(fid, state) (((state) & 0x3) << ((fid) * 2))
---
base-commit: 668d663989c77fcb2a92748645e4c394b03d5988
change-id: 20241030-mt7530-tc-offload-05e204441500
Best regards,
--
Lorenzo Bianconi <lorenzo@kernel.org>
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net-next] net: dsa: mt7530: Add TBF qdisc offload support
2024-10-30 19:29 [PATCH net-next] net: dsa: mt7530: Add TBF qdisc offload support Lorenzo Bianconi
@ 2024-10-31 7:10 ` Arınç ÜNAL
2024-10-31 8:00 ` Lorenzo Bianconi
0 siblings, 1 reply; 5+ messages in thread
From: Arınç ÜNAL @ 2024-10-31 7:10 UTC (permalink / raw)
To: Lorenzo Bianconi, Daniel Golle, DENG Qingfang, Sean Wang,
Andrew Lunn, Florian Fainelli, Vladimir Oltean, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Matthias Brugger,
AngeloGioacchino Del Regno
Cc: netdev, linux-arm-kernel, linux-mediatek
On 30/10/2024 22:29, Lorenzo Bianconi wrote:
> Introduce port_setup_tc callback in mt7530 dsa driver in order to enable
> dsa ports rate shaping via hw Token Bucket Filter (TBF) for hw switched
> traffic. Enable hw TBF just for EN7581 SoC for the moment.
Is this because you didn't test it on the other models? Let me know if
that's the case and I'll test it.
Arınç
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next] net: dsa: mt7530: Add TBF qdisc offload support
2024-10-31 7:10 ` Arınç ÜNAL
@ 2024-10-31 8:00 ` Lorenzo Bianconi
2024-10-31 13:35 ` Arınç ÜNAL
0 siblings, 1 reply; 5+ messages in thread
From: Lorenzo Bianconi @ 2024-10-31 8:00 UTC (permalink / raw)
To: Arınç ÜNAL
Cc: Daniel Golle, DENG Qingfang, Sean Wang, Andrew Lunn,
Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Matthias Brugger,
AngeloGioacchino Del Regno, netdev, linux-arm-kernel,
linux-mediatek
[-- Attachment #1: Type: text/plain, Size: 607 bytes --]
> On 30/10/2024 22:29, Lorenzo Bianconi wrote:
> > Introduce port_setup_tc callback in mt7530 dsa driver in order to enable
> > dsa ports rate shaping via hw Token Bucket Filter (TBF) for hw switched
> > traffic. Enable hw TBF just for EN7581 SoC for the moment.
>
> Is this because you didn't test it on the other models? Let me know if
> that's the case and I'll test it.
yep, exactly. I have tested it just on EN7581 since I do not have any other
boards for testing at the moment. If you confirm it works on other SoCs too,
I can remove the limitation.
Regards,
Lorenzo
>
> Arınç
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next] net: dsa: mt7530: Add TBF qdisc offload support
2024-10-31 8:00 ` Lorenzo Bianconi
@ 2024-10-31 13:35 ` Arınç ÜNAL
2024-10-31 14:19 ` Lorenzo Bianconi
0 siblings, 1 reply; 5+ messages in thread
From: Arınç ÜNAL @ 2024-10-31 13:35 UTC (permalink / raw)
To: Lorenzo Bianconi
Cc: Daniel Golle, DENG Qingfang, Sean Wang, Andrew Lunn,
Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Matthias Brugger,
AngeloGioacchino Del Regno, netdev, linux-arm-kernel,
linux-mediatek
On 31/10/2024 11:00, Lorenzo Bianconi wrote:
>> On 30/10/2024 22:29, Lorenzo Bianconi wrote:
>>> Introduce port_setup_tc callback in mt7530 dsa driver in order to enable
>>> dsa ports rate shaping via hw Token Bucket Filter (TBF) for hw switched
>>> traffic. Enable hw TBF just for EN7581 SoC for the moment.
>>
>> Is this because you didn't test it on the other models? Let me know if
>> that's the case and I'll test it.
>
> yep, exactly. I have tested it just on EN7581 since I do not have any other
> boards for testing at the moment. If you confirm it works on other SoCs too,
> I can remove the limitation.
Seems to be working fine on MT7530. As we have tested this on the oldest
and newest models that use this switching IP, I'm going to assume it will
work on the other models as well. You can remove the limitation. Also,
please change MT7530_ERLCR_P and MT7530_GERLCR to MT753X_ERLCR_P and
MT753X_GERLCR.
tc qdisc add dev lan4 root tbf rate 10mbit burst 10kb latency 50ms
[ ID] Interval Transfer Bitrate Retr
[ 5] 0.00-5.00 sec 5.88 MBytes 9.85 Mbits/sec 4 sender
[ 5] 0.00-5.00 sec 5.50 MBytes 9.23 Mbits/sec receiver
tc qdisc del dev lan4 root
[ ID] Interval Transfer Bitrate Retr
[ 5] 0.00-5.00 sec 469 MBytes 786 Mbits/sec 0 sender
[ 5] 0.00-5.00 sec 468 MBytes 785 Mbits/sec receiver
tc qdisc add dev lan4 root tbf rate 11mbit burst 10kb latency 50ms
[ ID] Interval Transfer Bitrate Retr
[ 5] 0.00-5.00 sec 6.38 MBytes 10.7 Mbits/sec 6 sender
[ 5] 0.00-5.00 sec 6.00 MBytes 10.1 Mbits/sec receiver
tc qdisc del dev lan4 root
[ ID] Interval Transfer Bitrate Retr
[ 5] 0.00-5.00 sec 467 MBytes 783 Mbits/sec 0 sender
[ 5] 0.00-5.00 sec 466 MBytes 783 Mbits/sec receiver
tc qdisc add dev lan4 root tbf rate 11mbit burst 10kb latency 50ms
tc qdisc replace dev lan4 root tbf rate 10mbit burst 10kb latency 50ms
[ ID] Interval Transfer Bitrate Retr
[ 5] 0.00-5.00 sec 5.88 MBytes 9.85 Mbits/sec 4 sender
[ 5] 0.00-5.00 sec 5.50 MBytes 9.23 Mbits/sec receiver
Arınç
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next] net: dsa: mt7530: Add TBF qdisc offload support
2024-10-31 13:35 ` Arınç ÜNAL
@ 2024-10-31 14:19 ` Lorenzo Bianconi
0 siblings, 0 replies; 5+ messages in thread
From: Lorenzo Bianconi @ 2024-10-31 14:19 UTC (permalink / raw)
To: Arınç ÜNAL
Cc: Daniel Golle, DENG Qingfang, Sean Wang, Andrew Lunn,
Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Matthias Brugger,
AngeloGioacchino Del Regno, netdev, linux-arm-kernel,
linux-mediatek
[-- Attachment #1: Type: text/plain, Size: 2570 bytes --]
> On 31/10/2024 11:00, Lorenzo Bianconi wrote:
> > > On 30/10/2024 22:29, Lorenzo Bianconi wrote:
> > > > Introduce port_setup_tc callback in mt7530 dsa driver in order to enable
> > > > dsa ports rate shaping via hw Token Bucket Filter (TBF) for hw switched
> > > > traffic. Enable hw TBF just for EN7581 SoC for the moment.
> > >
> > > Is this because you didn't test it on the other models? Let me know if
> > > that's the case and I'll test it.
> >
> > yep, exactly. I have tested it just on EN7581 since I do not have any other
> > boards for testing at the moment. If you confirm it works on other SoCs too,
> > I can remove the limitation.
>
> Seems to be working fine on MT7530. As we have tested this on the oldest
> and newest models that use this switching IP, I'm going to assume it will
> work on the other models as well. You can remove the limitation. Also,
> please change MT7530_ERLCR_P and MT7530_GERLCR to MT753X_ERLCR_P and
> MT753X_GERLCR.
ack, thx for testing. I will fix it in v2.
Regards,
Lorenzo
>
> tc qdisc add dev lan4 root tbf rate 10mbit burst 10kb latency 50ms
>
> [ ID] Interval Transfer Bitrate Retr
> [ 5] 0.00-5.00 sec 5.88 MBytes 9.85 Mbits/sec 4 sender
> [ 5] 0.00-5.00 sec 5.50 MBytes 9.23 Mbits/sec receiver
>
> tc qdisc del dev lan4 root
>
> [ ID] Interval Transfer Bitrate Retr
> [ 5] 0.00-5.00 sec 469 MBytes 786 Mbits/sec 0 sender
> [ 5] 0.00-5.00 sec 468 MBytes 785 Mbits/sec receiver
>
> tc qdisc add dev lan4 root tbf rate 11mbit burst 10kb latency 50ms
>
> [ ID] Interval Transfer Bitrate Retr
> [ 5] 0.00-5.00 sec 6.38 MBytes 10.7 Mbits/sec 6 sender
> [ 5] 0.00-5.00 sec 6.00 MBytes 10.1 Mbits/sec receiver
>
> tc qdisc del dev lan4 root
>
> [ ID] Interval Transfer Bitrate Retr
> [ 5] 0.00-5.00 sec 467 MBytes 783 Mbits/sec 0 sender
> [ 5] 0.00-5.00 sec 466 MBytes 783 Mbits/sec receiver
>
> tc qdisc add dev lan4 root tbf rate 11mbit burst 10kb latency 50ms
> tc qdisc replace dev lan4 root tbf rate 10mbit burst 10kb latency 50ms
>
> [ ID] Interval Transfer Bitrate Retr
> [ 5] 0.00-5.00 sec 5.88 MBytes 9.85 Mbits/sec 4 sender
> [ 5] 0.00-5.00 sec 5.50 MBytes 9.23 Mbits/sec receiver
>
> Arınç
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-10-31 14:19 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-30 19:29 [PATCH net-next] net: dsa: mt7530: Add TBF qdisc offload support Lorenzo Bianconi
2024-10-31 7:10 ` Arınç ÜNAL
2024-10-31 8:00 ` Lorenzo Bianconi
2024-10-31 13:35 ` Arınç ÜNAL
2024-10-31 14:19 ` Lorenzo Bianconi
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).