Skip to contentSkip to conversation

net: dsa: sja1105: offload the Credit-Based Shaper qdisc

PATCH Superseded Vladimir Oltean 2 participants 3 messages May 27, 2020

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Vladimir Oltean

author maintainer
#0 lore raw

PATCH 1/1 net: dsa: sja1105: offload the Credit-Based Shaper qdisc

From: Vladimir Oltean <[email protected]>

SJA1105, being AVB/TSN switches, provide hardware assist for the Credit-Based Shaper as described in the IEEE 8021Q-2018 document.

First generation has 10 shapers, freely assignable to any of the 4 external ports and 8 traffic classes, and second generation has 16 shapers.

We also need to provide a dummy implementation of mqprio qdisc offload, since this seems to be necessary for shaping any traffic class other than zero.

The Credit-Based Shaper tables are accessed through the dynamic reconfiguration interface, so we have to restore them manually after a switch reset. The tables are backed up by the static config only on P/Q/R/S, and we don't want to add custom code only for that family, since the procedure that is in place now works for both.

Tested with the following commands:

data_rate_kbps=34000 port_transmit_rate_kbps=1000000 idleslope=$data_rate_kbps sendslope=$(($idleslope - $port_transmit_rate_kbps)) locredit=$((-0x7fffffff)) hicredit=$((0x7fffffff))
tc qdisc add dev sw1p3 root handle 1: mqprio num_tc 8 tc qdisc add dev sw1p3 parent 1:1 cbs \

        idleslope $idleslope \
        sendslope $sendslope \
        hicredit $hicredit \
        locredit $locredit \
        offload 1
---
 drivers/net/dsa/sja1105/sja1105.h             |   2 +
 .../net/dsa/sja1105/sja1105_dynamic_config.c  |  76 ++++++++++++
 drivers/net/dsa/sja1105/sja1105_main.c        | 108 ++++++++++++++++++
 drivers/net/dsa/sja1105/sja1105_spi.c         |   6 +
 .../net/dsa/sja1105/sja1105_static_config.h   |  15 +++
 5 files changed, 207 insertions(+)
drivers/net/dsa/sja1105/sja1105.h +2 -0
index 303b21470d77..ee79749aacf1 100644
@@ -84,6 +84,7 @@ struct sja1105_info {
 	 * the egress timestamps.
 	 */
 	int ptpegr_ts_bytes;
+	int num_cbs_shapers;
 	const struct sja1105_dynamic_table_ops *dyn_ops;
 	const struct sja1105_table_ops *static_ops;
 	const struct sja1105_regs *regs;
@@ -218,6 +219,7 @@ struct sja1105_private {
 	struct mutex mgmt_lock;
 	bool expect_dsa_8021q;
 	enum sja1105_vlan_state vlan_state;
+	struct sja1105_cbs_entry *cbs;
 	struct sja1105_tagger_data tagger_data;
 	struct sja1105_ptp_data ptp_data;
 	struct sja1105_tas_data tas_data;
drivers/net/dsa/sja1105/sja1105_dynamic_config.c +76 -0

100 lines not on this page · raw message

drivers/net/dsa/sja1105/sja1105_main.c +108 -0

132 lines not on this page · raw message

drivers/net/dsa/sja1105/sja1105_spi.c +6 -0
index a0dacae803cc..bb52b9c841b2 100644
@@ -515,6 +515,7 @@ struct sja1105_info sja1105e_info = {
 	.qinq_tpid		= ETH_P_8021Q,
 	.ptp_ts_bits		= 24,
 	.ptpegr_ts_bytes	= 4,
+	.num_cbs_shapers	= SJA1105ET_MAX_CBS_COUNT,
 	.reset_cmd		= sja1105et_reset_cmd,
 	.fdb_add_cmd		= sja1105et_fdb_add,
 	.fdb_del_cmd		= sja1105et_fdb_del,
@@ -530,6 +531,7 @@ struct sja1105_info sja1105t_info = {
 	.qinq_tpid		= ETH_P_8021Q,
 	.ptp_ts_bits		= 24,
 	.ptpegr_ts_bytes	= 4,
+	.num_cbs_shapers	= SJA1105ET_MAX_CBS_COUNT,
 	.reset_cmd		= sja1105et_reset_cmd,
 	.fdb_add_cmd		= sja1105et_fdb_add,
 	.fdb_del_cmd		= sja1105et_fdb_del,
@@ -545,6 +547,7 @@ struct sja1105_info sja1105p_info = {
 	.qinq_tpid		= ETH_P_8021AD,
 	.ptp_ts_bits		= 32,
 	.ptpegr_ts_bytes	= 8,
+	.num_cbs_shapers	= SJA1105PQRS_MAX_CBS_COUNT,
 	.setup_rgmii_delay	= sja1105pqrs_setup_rgmii_delay,
 	.reset_cmd		= sja1105pqrs_reset_cmd,
 	.fdb_add_cmd		= sja1105pqrs_fdb_add,
@@ -561,6 +564,7 @@ struct sja1105_info sja1105q_info = {
 	.qinq_tpid		= ETH_P_8021AD,
 	.ptp_ts_bits		= 32,
 	.ptpegr_ts_bytes	= 8,
+	.num_cbs_shapers	= SJA1105PQRS_MAX_CBS_COUNT,
 	.setup_rgmii_delay	= sja1105pqrs_setup_rgmii_delay,
 	.reset_cmd		= sja1105pqrs_reset_cmd,
 	.fdb_add_cmd		= sja1105pqrs_fdb_add,
@@ -577,6 +581,7 @@ struct sja1105_info sja1105r_info = {
 	.qinq_tpid		= ETH_P_8021AD,
 	.ptp_ts_bits		= 32,
 	.ptpegr_ts_bytes	= 8,
+	.num_cbs_shapers	= SJA1105PQRS_MAX_CBS_COUNT,
 	.setup_rgmii_delay	= sja1105pqrs_setup_rgmii_delay,
 	.reset_cmd		= sja1105pqrs_reset_cmd,
 	.fdb_add_cmd		= sja1105pqrs_fdb_add,
@@ -594,6 +599,7 @@ struct sja1105_info sja1105s_info = {
 	.qinq_tpid		= ETH_P_8021AD,
 	.ptp_ts_bits		= 32,
 	.ptpegr_ts_bytes	= 8,
+	.num_cbs_shapers	= SJA1105PQRS_MAX_CBS_COUNT,
 	.setup_rgmii_delay	= sja1105pqrs_setup_rgmii_delay,
 	.reset_cmd		= sja1105pqrs_reset_cmd,
 	.fdb_add_cmd		= sja1105pqrs_fdb_add,
drivers/net/dsa/sja1105/sja1105_static_config.h +15 -0
index 5946847bb5b9..9b62b9b5549d 100644
@@ -30,11 +30,13 @@
 #define SJA1105ET_SIZE_L2_LOOKUP_PARAMS_ENTRY		4
 #define SJA1105ET_SIZE_GENERAL_PARAMS_ENTRY		40
 #define SJA1105ET_SIZE_AVB_PARAMS_ENTRY			12
+#define SJA1105ET_SIZE_CBS_ENTRY			16
 #define SJA1105PQRS_SIZE_L2_LOOKUP_ENTRY		20
 #define SJA1105PQRS_SIZE_MAC_CONFIG_ENTRY		32
 #define SJA1105PQRS_SIZE_L2_LOOKUP_PARAMS_ENTRY		16
 #define SJA1105PQRS_SIZE_GENERAL_PARAMS_ENTRY		44
 #define SJA1105PQRS_SIZE_AVB_PARAMS_ENTRY		16
+#define SJA1105PQRS_SIZE_CBS_ENTRY			20
 
 /* UM10944.pdf Page 11, Table 2. Configuration Blocks */
 enum {
@@ -56,6 +58,7 @@ enum {
 	BLKID_AVB_PARAMS				= 0x10,
 	BLKID_GENERAL_PARAMS				= 0x11,
 	BLKID_RETAGGING					= 0x12,
+	BLKID_CBS					= 0x13,
 	BLKID_XMII_PARAMS				= 0x4E,
 };
 
@@ -78,6 +81,7 @@ enum sja1105_blk_idx {
 	BLK_IDX_AVB_PARAMS,
 	BLK_IDX_GENERAL_PARAMS,
 	BLK_IDX_RETAGGING,
+	BLK_IDX_CBS,
 	BLK_IDX_XMII_PARAMS,
 	BLK_IDX_MAX,
 	/* Fake block indices that are only valid for dynamic access */
@@ -105,6 +109,8 @@ enum sja1105_blk_idx {
 #define SJA1105_MAX_RETAGGING_COUNT			32
 #define SJA1105_MAX_XMII_PARAMS_COUNT			1
 #define SJA1105_MAX_AVB_PARAMS_COUNT			1
+#define SJA1105ET_MAX_CBS_COUNT				10
+#define SJA1105PQRS_MAX_CBS_COUNT			16
 
 #define SJA1105_MAX_FRAME_MEMORY			929
 #define SJA1105_MAX_FRAME_MEMORY_RETAGGING		910
@@ -289,6 +295,15 @@ struct sja1105_retagging_entry {
 	u64 destports;
 };
 
+struct sja1105_cbs_entry {
+	u64 port;
+	u64 prio;
+	u64 credit_hi;
+	u64 credit_lo;
+	u64 send_slope;
+	u64 idle_slope;
+};
+
 struct sja1105_xmii_params_entry {
 	u64 phy_mac[5];
 	u64 xmii_mode[5];
Signature · 1 line
2.25.1
#1 lore raw

Hi,

Quoted 21 lines · Vladimir Oltean

From: Vladimir Oltean <[email protected]>

SJA1105, being AVB/TSN switches, provide hardware assist for the Credit-Based Shaper as described in the IEEE 8021Q-2018 document.

First generation has 10 shapers, freely assignable to any of the 4 external ports and 8 traffic classes, and second generation has 16 shapers.

We also need to provide a dummy implementation of mqprio qdisc offload, since this seems to be necessary for shaping any traffic class other than zero.

The Credit-Based Shaper tables are accessed through the dynamic reconfiguration interface, so we have to restore them manually after a switch reset. The tables are backed up by the static config only on P/Q/R/S, and we don't want to add custom code only for that family, since the procedure that is in place now works for both.

Tested with the following commands:

Quoted 7 lines

data_rate_kbps=34000 port_transmit_rate_kbps=1000000 idleslope=$data_rate_kbps sendslope=$(($idleslope - $port_transmit_rate_kbps)) locredit=$((-0x7fffffff)) hicredit=$((0x7fffffff))
tc qdisc add dev sw1p3 root handle 1: mqprio num_tc 8

This (and implementing the dummy mqprio offload callback) seem a bit
hackish: I am reading this is more a way to bypass mqprio parameter validation (the priority to queue mapping) than anything else.

And I don't think that accepting any parameters without doing any validation is really what you want.

Question:

$ tc qdisc replace dev $IFACE parent root handle 100 mqprio \
      num_tc 3 \
      map 2 2 1 0 2 2 2 2 2 2 2 2 2 2 2 2 \
      queues 1@0 1@1 1@2 \
      hw 0
$ tc qdisc replace dev $IFACE handle 200 parent 100:1 cbs \
      idleslope 100000 sendslope -900000 hicredit 150 locredit -1362 \
      offload 1

Why doesn't something like this work for your hardware?

Cheers,

Signature · 1 line
Vinicius
author maintainer
#2 lore raw

Hi Vinicius,

Quoted 53 lines · Vinicius Costa Gomes

Hi,

Quoted 21 lines · Vladimir Oltean

From: Vladimir Oltean <[email protected]>

SJA1105, being AVB/TSN switches, provide hardware assist for the Credit-Based Shaper as described in the IEEE 8021Q-2018 document.

First generation has 10 shapers, freely assignable to any of the 4 external ports and 8 traffic classes, and second generation has 16 shapers.

We also need to provide a dummy implementation of mqprio qdisc offload, since this seems to be necessary for shaping any traffic class other than zero.

The Credit-Based Shaper tables are accessed through the dynamic reconfiguration interface, so we have to restore them manually after a switch reset. The tables are backed up by the static config only on P/Q/R/S, and we don't want to add custom code only for that family, since the procedure that is in place now works for both.

Tested with the following commands:

Quoted 7 lines

data_rate_kbps=34000 port_transmit_rate_kbps=1000000 idleslope=$data_rate_kbps sendslope=$(($idleslope - $port_transmit_rate_kbps)) locredit=$((-0x7fffffff)) hicredit=$((0x7fffffff))
tc qdisc add dev sw1p3 root handle 1: mqprio num_tc 8

This (and implementing the dummy mqprio offload callback) seem a bit
hackish: I am reading this is more a way to bypass mqprio parameter validation (the priority to queue mapping) than anything else.

And I don't think that accepting any parameters without doing any validation is really what you want.

Question:

$ tc qdisc replace dev $IFACE parent root handle 100 mqprio \
      num_tc 3 \
      map 2 2 1 0 2 2 2 2 2 2 2 2 2 2 2 2 \
      queues 1@0 1@1 1@2 \
      hw 0
$ tc qdisc replace dev $IFACE handle 200 parent 100:1 cbs \
      idleslope 100000 sendslope -900000 hicredit 150 locredit -1362 \
      offload 1
Quoted 6 lines

Why doesn't something like this work for your hardware?

Cheers,
--
Vinicius

No, it absolutely does, thanks.
I had tried a few combinations of tc mqprio commands with hw 0, and they all returned this cryptic:

tc qdisc add dev swp2 root handle 100 mqprio num_tc 8 map 0 1 2 3 4 5 6 7 hw 0 RTNETLINK answers: Invalid argument
tc qdisc add dev swp2 root handle 100 mqprio num_tc 8 hw 0 RTNETLINK answers: Invalid argument

which I had absolutely no desire to debug, especially since the same commands, with hw 1, were accepted.
I just chose to be deliberately wrong, knowing that it's the quickest way to find out the real solution :)

Cheers,
-Vladimir