Skip to contentSkip to conversation

tc-taprio offload for SJA1105 DSA

RFC PATCH Superseded Vladimir Oltean 5 participants 15 messages Jul 7, 2019 – Jul 13, 2019

Subsystems (7)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Vladimir Oltean

author maintainer
#0 lore raw

cover tc-taprio offload for SJA1105 DSA

Using Vinicius Costa Gomes' configuration interface for 802.1Qbv (later resent by Voon Weifeng for the stmmac driver), I am submitting for review a draft implementation of this offload for a DSA switch.

I don't want to insist too much on the hardware specifics of SJA1105 which isn't otherwise very compliant to the IEEE spec.

In order to be able to test with Vedang Patel's iproute2 patch for taprio offload (https://www.spinics.net/lists/netdev/msg573072.html)
I had to actually revert the txtime-assist branch as it had changed the iproute2 interface.

In terms of impact for DSA drivers, I would like to point out that:

- Maybe somebody should pre-populate qopt->cycle_time in case the user does not provide one. Otherwise each driver needs to iterate over the GCL once, just to set the cycle time (right now stmmac does as well).

- Configuring the switch over SPI cannot apparently be done from this ndo_setup_tc callback because it runs in atomic context. I also have some downstream patches to offload tc clsact matchall with mirred action, but in that case it looks like the atomic context restriction does not apply.

- I had to copy the struct tc_taprio_qopt_offload to driver private memory because a static config needs to be constructed every time a change takes place, and there are up to 4 switch ports that may take a TAS configuration. I have created a private tc_taprio_qopt_offload_copy() helper for this - I don't know whether it's of any help in the general case.

There is more to be done however. The TAS needs to be integrated with the PTP driver. This is because with a PTP clock source, the base time is written dynamically to the PTPSCHTM (PTP schedule time) register and must be a time in the future. Then the "real" base time of each port's TAS config can be offset by at most ~50 ms (the DELTA field from the Schedule Entry Points Table) relative to PTPSCHTM.
Because base times in the past are completely ignored by this hardware, we need to decide if it's ok behaviorally for a driver to "roll" a past base time into the immediate future by incrementally adding the cycle time (so the phase doesn't change). If it is, then decide by how long in the future it is ok to do so. Or alternatively, is it preferable if the driver errors out if the user-supplied base time is in the past and the hardware doesn't like it? But even then, there might be fringe cases when the base time becomes a past PTP time right as the driver tries to apply the config.
Also applying a tc-taprio offload to a second SJA1105 switch port will inevitably need to roll the first port's (now past) base time into an equivalent future time.
All of this is going to be complicated even further by the fact that resetting the switch (to apply the tc-taprio offload) makes it reset its PTP time.

Vinicius Costa Gomes (1):
taprio: Add support for hardware offloading

Vladimir Oltean (5):
Revert "Merge branch 'net-sched-Add-txtime-assist-support-for-taprio'"
net: dsa: Pass tc-taprio offload to drivers
net: dsa: sja1105: Add static config tables for scheduling
net: dsa: sja1105: Advertise the 8 TX queues
net: dsa: sja1105: Configure the Time-Aware Shaper via tc-taprio
offload

 drivers/net/dsa/sja1105/Kconfig               |   8 +
 drivers/net/dsa/sja1105/Makefile              |   4 +
 drivers/net/dsa/sja1105/sja1105.h             |   6 +
 .../net/dsa/sja1105/sja1105_dynamic_config.c  |   8 +
 drivers/net/dsa/sja1105/sja1105_main.c        |  19 +-
 .../net/dsa/sja1105/sja1105_static_config.c   | 167 +++++
 .../net/dsa/sja1105/sja1105_static_config.h   |  48 +-
 drivers/net/dsa/sja1105/sja1105_tas.c         | 452 ++++++++++++
 drivers/net/dsa/sja1105/sja1105_tas.h         |  22 +
 drivers/net/ethernet/intel/igb/igb_main.c     |   1 -
 include/linux/netdevice.h                     |   1 +
 include/net/dsa.h                             |   3 +
 include/net/pkt_sched.h                       |  18 +
 include/uapi/linux/pkt_sched.h                |  11 +-
 net/dsa/slave.c                               |  14 +
 net/dsa/tag_sja1105.c                         |   3 +-
 net/sched/sch_etf.c                           |  10 -
 net/sched/sch_taprio.c                        | 666 ++++++++----------
 18 files changed, 1060 insertions(+), 401 deletions(-)
 create mode 100644 drivers/net/dsa/sja1105/sja1105_tas.c
 create mode 100644 drivers/net/dsa/sja1105/sja1105_tas.h
Signature · 1 line
2.17.1
author maintainer
#1 lore raw

RFC PATCH 1/6 Revert "Merge branch 'net-sched-Add-txtime-assist-support-for-taprio'"

This reverts commit 0a7960c7922228ca975ca4c5595e5539fc8f8b79, reversing changes made to 8747d82d3c32df488ea0fe9b86bdb53a8a04a7b8.

This returns the tc-taprio state to where it was when Voon Weifeng <[email protected]> had resent Vinicius Costa Gomes <[email protected]>'s patch "taprio: Add support for hardware offloading" (also resent by me in this series).

There are conflicts within the two that would otherwise propagate all the way up to iproute2. I don't want to redefine yet a third userspace interface, hence simply reverting the txtime-assist patches for review purposes of taprio offload.

---
 drivers/net/ethernet/intel/igb/igb_main.c |   1 -
 include/uapi/linux/pkt_sched.h            |   9 +-
 net/sched/sch_etf.c                       |  10 -
 net/sched/sch_taprio.c                    | 421 ++--------------------
 4 files changed, 36 insertions(+), 405 deletions(-)
drivers/net/ethernet/intel/igb/igb_main.c +0 -1
index f66dae72fe37..fc925adbd9fa 100644
@@ -5688,7 +5688,6 @@ static void igb_tx_ctxtdesc(struct igb_ring *tx_ring,
 	 */
 	if (tx_ring->launchtime_enable) {
 		ts = ns_to_timespec64(first->skb->tstamp);
-		first->skb->tstamp = 0;
 		context_desc->seqnum_seed = cpu_to_le32(ts.tv_nsec / 32);
 	} else {
 		context_desc->seqnum_seed = 0;
include/uapi/linux/pkt_sched.h +2 -7
index 390efb54b2e0..8b2f993cbb77 100644
@@ -988,9 +988,8 @@ struct tc_etf_qopt {
 	__s32 delta;
 	__s32 clockid;
 	__u32 flags;
-#define TC_ETF_DEADLINE_MODE_ON	_BITUL(0)
-#define TC_ETF_OFFLOAD_ON	_BITUL(1)
-#define TC_ETF_SKIP_SOCK_CHECK	_BITUL(2)
+#define TC_ETF_DEADLINE_MODE_ON	BIT(0)
+#define TC_ETF_OFFLOAD_ON	BIT(1)
 };
 
 enum {
@@ -1159,8 +1158,6 @@ enum {
  *       [TCA_TAPRIO_ATTR_SCHED_ENTRY_INTERVAL]
  */
 
-#define TCA_TAPRIO_ATTR_FLAG_TXTIME_ASSIST 0x1
-
 enum {
 	TCA_TAPRIO_ATTR_UNSPEC,
 	TCA_TAPRIO_ATTR_PRIOMAP, /* struct tc_mqprio_qopt */
@@ -1172,8 +1169,6 @@ enum {
 	TCA_TAPRIO_ATTR_ADMIN_SCHED, /* The admin sched, only used in dump */
 	TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME, /* s64 */
 	TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME_EXTENSION, /* s64 */
-	TCA_TAPRIO_ATTR_FLAGS, /* u32 */
-	TCA_TAPRIO_ATTR_TXTIME_DELAY, /* s32 */
 	__TCA_TAPRIO_ATTR_MAX,
 };
 
net/sched/sch_etf.c +0 -10
index cebfb65d8556..db0c2ba1d156 100644
@@ -22,12 +22,10 @@
 
 #define DEADLINE_MODE_IS_ON(x) ((x)->flags & TC_ETF_DEADLINE_MODE_ON)
 #define OFFLOAD_IS_ON(x) ((x)->flags & TC_ETF_OFFLOAD_ON)
-#define SKIP_SOCK_CHECK_IS_SET(x) ((x)->flags & TC_ETF_SKIP_SOCK_CHECK)
 
 struct etf_sched_data {
 	bool offload;
 	bool deadline_mode;
-	bool skip_sock_check;
 	int clockid;
 	int queue;
 	s32 delta; /* in ns */
@@ -79,9 +77,6 @@ static bool is_packet_valid(struct Qdisc *sch, struct sk_buff *nskb)
 	struct sock *sk = nskb->sk;
 	ktime_t now;
 
-	if (q->skip_sock_check)
-		goto skip;
-
 	if (!sk)
 		return false;
 
@@ -97,7 +92,6 @@ static bool is_packet_valid(struct Qdisc *sch, struct sk_buff *nskb)
 	if (sk->sk_txtime_deadline_mode != q->deadline_mode)
 		return false;
 
-skip:
 	now = q->get_time();
 	if (ktime_before(txtime, now) || ktime_before(txtime, q->last))
 		return false;
@@ -391,7 +385,6 @@ static int etf_init(struct Qdisc *sch, struct nlattr *opt,
 	q->clockid = qopt->clockid;
 	q->offload = OFFLOAD_IS_ON(qopt);
 	q->deadline_mode = DEADLINE_MODE_IS_ON(qopt);
-	q->skip_sock_check = SKIP_SOCK_CHECK_IS_SET(qopt);
 
 	switch (q->clockid) {
 	case CLOCK_REALTIME:
@@ -480,9 +473,6 @@ static int etf_dump(struct Qdisc *sch, struct sk_buff *skb)
 	if (q->deadline_mode)
 		opt.flags |= TC_ETF_DEADLINE_MODE_ON;
 
-	if (q->skip_sock_check)
-		opt.flags |= TC_ETF_SKIP_SOCK_CHECK;
-
 	if (nla_put(skb, TCA_ETF_PARMS, sizeof(opt), &opt))
 		goto nla_put_failure;
 
net/sched/sch_taprio.c +34 -387

595 lines not on this page · raw message

Signature · 1 line
2.17.1
author maintainer
#2 lore raw

RFC PATCH 2/6 taprio: Add support for hardware offloading

In reply to Vladimir Oltean

From: Vinicius Costa Gomes <[email protected]>

This allows taprio to offload the schedule enforcement to capable network cards, resulting in more precise windows and less CPU usage.

The important detail here is the difference between the gate_mask in taprio and gate_mask for the network driver. For the driver, each bit in gate_mask references a transmission queue: bit 0 for queue 0, bit 1 for queue 1, and so on. This is done so the driver doesn't need to know about traffic classes.

---
 include/linux/netdevice.h      |   1 +
 include/net/pkt_sched.h        |  18 +++
 include/uapi/linux/pkt_sched.h |   4 +
 net/sched/sch_taprio.c         | 263 ++++++++++++++++++++++++++++++++-
 4 files changed, 284 insertions(+), 2 deletions(-)
include/linux/netdevice.h +1 -0
index 88292953aa6f..514eb7e9feee 100644
@@ -845,6 +845,7 @@ enum tc_setup_type {
 	TC_SETUP_QDISC_ETF,
 	TC_SETUP_ROOT_QDISC,
 	TC_SETUP_QDISC_GRED,
+	TC_SETUP_QDISC_TAPRIO,
 };
 
 /* These structures hold the attributes of bpf state that are being passed
include/net/pkt_sched.h +18 -0
index a16fbe9a2a67..3333c107f920 100644
@@ -161,4 +161,22 @@ struct tc_etf_qopt_offload {
 	s32 queue;
 };
 
+struct tc_taprio_sched_entry {
+	u8 command; /* TC_TAPRIO_CMD_* */
+
+	/* The gate_mask in the offloading side refers to HW queues */
+	u32 gate_mask;
+	u32 interval;
+};
+
+struct tc_taprio_qopt_offload {
+	u8 enable;
+	ktime_t base_time;
+	u64 cycle_time;
+	u64 cycle_time_extension;
+
+	size_t num_entries;
+	struct tc_taprio_sched_entry entries[0];
+};
+
 #endif
include/uapi/linux/pkt_sched.h +4 -0
index 8b2f993cbb77..08a260fd7843 100644
@@ -1158,6 +1158,9 @@ enum {
  *       [TCA_TAPRIO_ATTR_SCHED_ENTRY_INTERVAL]
  */
 
+#define TCA_TAPRIO_ATTR_OFFLOAD_FLAG_FULL_OFFLOAD 0x1
+#define TCA_TAPRIO_ATTR_OFFLOAD_FLAG_TXTIME_OFFLOAD 0x2
+
 enum {
 	TCA_TAPRIO_ATTR_UNSPEC,
 	TCA_TAPRIO_ATTR_PRIOMAP, /* struct tc_mqprio_qopt */
@@ -1169,6 +1172,7 @@ enum {
 	TCA_TAPRIO_ATTR_ADMIN_SCHED, /* The admin sched, only used in dump */
 	TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME, /* s64 */
 	TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME_EXTENSION, /* s64 */
+	TCA_TAPRIO_ATTR_OFFLOAD_FLAGS, /* u32 */
 	__TCA_TAPRIO_ATTR_MAX,
 };
 
net/sched/sch_taprio.c +261 -2

359 lines not on this page · raw message

Signature · 1 line
2.17.1
maintainer
#3 lore raw

Re: [RFC PATCH net-next 2/6] taprio: Add support for hardware offloading

Quoted 5 lines · Vladimir Oltean

From: Vinicius Costa Gomes <[email protected]>

This allows taprio to offload the schedule enforcement to capable network cards, resulting in more precise windows and less CPU usage.

Quoted 8 lines

The important detail here is the difference between the gate_mask in taprio and gate_mask for the network driver. For the driver, each bit in gate_mask references a transmission queue: bit 0 for queue 0, bit 1 for queue 1, and so on. This is done so the driver doesn't need to know about traffic classes.

Hi Vladimir

Your SOB is also needed here.

Andrew

author maintainer
#4 lore raw

Re: [RFC PATCH net-next 2/6] taprio: Add support for hardware offloading

Quoted 13 lines · Andrew Lunn
Quoted 11 lines · Vladimir Oltean

From: Vinicius Costa Gomes <[email protected]>

This allows taprio to offload the schedule enforcement to capable network cards, resulting in more precise windows and less CPU usage.

The important detail here is the difference between the gate_mask in taprio and gate_mask for the network driver. For the driver, each bit in gate_mask references a transmission queue: bit 0 for queue 0, bit 1 for queue 1, and so on. This is done so the driver doesn't need to know about traffic classes.

Quoted 8 lines
Quoted 2 lines

Hi Vladimir

Your SOB is also needed here.

Andrew

Hi Andrew,

I thought I'd added it, but it looks like I edited the patch and then overwrote it, instead of operating on the git history. Next time!

-Vladimir

author maintainer
#5 lore raw

RFC PATCH 3/6 net: dsa: Pass tc-taprio offload to drivers

In reply to Vladimir Oltean

tc-taprio is a qdisc based on the enhancements for scheduled traffic specified in IEEE 802.1Qbv (later merged in 802.1Q). This qdisc has a software implementation and an optional offload through which compatible Ethernet ports may configure their egress 802.1Qbv schedulers.

---
 include/net/dsa.h |  3 +++
 net/dsa/slave.c   | 14 ++++++++++++++
 2 files changed, 17 insertions(+)
include/net/dsa.h +3 -0
index 1e8650fa8acc..e7ee6ac8ce6b 100644
@@ -152,6 +152,7 @@ struct dsa_mall_tc_entry {
 	};
 };
 
+struct tc_taprio_qopt_offload;
 
 struct dsa_port {
 	/* A CPU port is physically connected to a master device.
@@ -516,6 +517,8 @@ struct dsa_switch_ops {
 				   bool ingress);
 	void	(*port_mirror_del)(struct dsa_switch *ds, int port,
 				   struct dsa_mall_mirror_tc_entry *mirror);
+	int	(*port_setup_taprio)(struct dsa_switch *ds, int port,
+				     struct tc_taprio_qopt_offload *qopt);
 
 	/*
 	 * Cross-chip operations
net/dsa/slave.c +14 -0
index 99673f6b07f6..2bae33788708 100644
@@ -965,12 +965,26 @@ static int dsa_slave_setup_tc_block(struct net_device *dev,
 	}
 }
 
+static int dsa_slave_setup_tc_taprio(struct net_device *dev,
+				     struct tc_taprio_qopt_offload *f)
+{
+	struct dsa_port *dp = dsa_slave_to_port(dev);
+	struct dsa_switch *ds = dp->ds;
+
+	if (!ds->ops->port_setup_taprio)
+		return -EOPNOTSUPP;
+
+	return ds->ops->port_setup_taprio(ds, dp->index, f);
+}
+
 static int dsa_slave_setup_tc(struct net_device *dev, enum tc_setup_type type,
 			      void *type_data)
 {
 	switch (type) {
 	case TC_SETUP_BLOCK:
 		return dsa_slave_setup_tc_block(dev, type_data);
+	case TC_SETUP_QDISC_TAPRIO:
+		return dsa_slave_setup_tc_taprio(dev, type_data);
 	default:
 		return -EOPNOTSUPP;
 	}
Signature · 1 line
2.17.1
#6 lore raw

Re: [RFC PATCH net-next 3/6] net: dsa: Pass tc-taprio offload to drivers

Hi Vladimir,

Quoted 25 lines

tc-taprio is a qdisc based on the enhancements for scheduled traffic specified in IEEE 802.1Qbv (later merged in 802.1Q). This qdisc has a software implementation and an optional offload through which compatible Ethernet ports may configure their egress 802.1Qbv schedulers.

---
 include/net/dsa.h |  3 +++
 net/dsa/slave.c   | 14 ++++++++++++++
 2 files changed, 17 insertions(+)
include/net/dsa.h +1 -0
index 1e8650fa8acc..e7ee6ac8ce6b 100644
@@ -152,6 +152,7 @@ struct dsa_mall_tc_entry {
 	};
 };
 
+struct tc_taprio_qopt_offload;
 
 struct dsa_port {
 	/* A CPU port is physically connected to a master device.

include/net/dsa.h struct dsa_switch_ops { · line 521

Quoted 5 lines
include/net/dsa.h +2 -0
@@ -516,6 +517,8 @@ struct dsa_switch_ops {
 				   bool ingress);
 	void	(*port_mirror_del)(struct dsa_switch *ds, int port,
 				   struct dsa_mall_mirror_tc_entry *mirror);
+	int	(*port_setup_taprio)(struct dsa_switch *ds, int port,
+				     struct tc_taprio_qopt_offload *qopt);

Is there any way to make this more generic? 802.1Qbv are not the only hardware schedulers. CBS and ETF are examples that first come to mind. Maybe having something more generic than tc_taprio_qopt_offload as an option could host future schedulers?

Quoted 37 lines
include/net/dsa.h +0 -0
 	/*
 	 * Cross-chip operations
net/dsa/slave.c +14 -0
index 99673f6b07f6..2bae33788708 100644
@@ -965,12 +965,26 @@ static int dsa_slave_setup_tc_block(struct net_device *dev,
 	}
 }
 
+static int dsa_slave_setup_tc_taprio(struct net_device *dev,
+				     struct tc_taprio_qopt_offload *f)
+{
+	struct dsa_port *dp = dsa_slave_to_port(dev);
+	struct dsa_switch *ds = dp->ds;
+
+	if (!ds->ops->port_setup_taprio)
+		return -EOPNOTSUPP;
+
+	return ds->ops->port_setup_taprio(ds, dp->index, f);
+}
+
 static int dsa_slave_setup_tc(struct net_device *dev, enum tc_setup_type type,
 			      void *type_data)
 {
 	switch (type) {
 	case TC_SETUP_BLOCK:
 		return dsa_slave_setup_tc_block(dev, type_data);
+	case TC_SETUP_QDISC_TAPRIO:
+		return dsa_slave_setup_tc_taprio(dev, type_data);
 	default:
 		return -EOPNOTSUPP;
 	}
Signature · 1 line
2.17.1

Thanks
/Ilias

author maintainer
#7 lore raw

Re: [RFC PATCH net-next 3/6] net: dsa: Pass tc-taprio offload to drivers

Hi Ilias,

Quoted 25 lines · Ilias Apalodimas

Hi Vladimir,

Quoted 22 lines

tc-taprio is a qdisc based on the enhancements for scheduled traffic specified in IEEE 802.1Qbv (later merged in 802.1Q). This qdisc has a software implementation and an optional offload through which compatible Ethernet ports may configure their egress 802.1Qbv schedulers.

---
 include/net/dsa.h |  3 +++
 net/dsa/slave.c   | 14 ++++++++++++++
 2 files changed, 17 insertions(+)
include/net/dsa.h +1 -0
index 1e8650fa8acc..e7ee6ac8ce6b 100644
@@ -152,6 +152,7 @@ struct dsa_mall_tc_entry {
      };
 };
 
+struct tc_taprio_qopt_offload;
 
Quoted 14 lines

include/net/dsa.h struct dsa_switch_ops { · line 521

Quoted 8 lines
include/net/dsa.h +2 -0
 struct dsa_port {
      /* A CPU port is physically connected to a master device.
@@ -516,6 +517,8 @@ struct dsa_switch_ops {
                                 bool ingress);
      void    (*port_mirror_del)(struct dsa_switch *ds, int port,
                                 struct dsa_mall_mirror_tc_entry *mirror);
+     int     (*port_setup_taprio)(struct dsa_switch *ds, int port,
+                                  struct tc_taprio_qopt_offload *qopt);

Is there any way to make this more generic? 802.1Qbv are not the only hardware schedulers. CBS and ETF are examples that first come to mind. Maybe having something more generic than tc_taprio_qopt_offload as an option could host future schedulers?

Good point. I'll see what I can do to make DSA more qdisc-agnostic when I gather enough feedback to mandate a v2.

Quoted 31 lines
Quoted 31 lines
include/net/dsa.h +0 -0
      /*
       * Cross-chip operations
net/dsa/slave.c +14 -0
index 99673f6b07f6..2bae33788708 100644
@@ -965,12 +965,26 @@ static int dsa_slave_setup_tc_block(struct net_device *dev,
      }
 }
 
+static int dsa_slave_setup_tc_taprio(struct net_device *dev,
+                                  struct tc_taprio_qopt_offload *f)
+{
+     struct dsa_port *dp = dsa_slave_to_port(dev);
+     struct dsa_switch *ds = dp->ds;
+
+     if (!ds->ops->port_setup_taprio)
+             return -EOPNOTSUPP;
+
+     return ds->ops->port_setup_taprio(ds, dp->index, f);
+}
+
 static int dsa_slave_setup_tc(struct net_device *dev, enum tc_setup_type type,
                            void *type_data)
 {
      switch (type) {
      case TC_SETUP_BLOCK:
              return dsa_slave_setup_tc_block(dev, type_data);
+     case TC_SETUP_QDISC_TAPRIO:
+             return dsa_slave_setup_tc_taprio(dev, type_data);
Quoted 8 lines
Quoted 6 lines
net/dsa/slave.c +0 -1
      default:
              return -EOPNOTSUPP;
      }
--

2.17.1

Thanks
/Ilias

Thanks,
-Vladimir

author maintainer
#8 lore raw

RFC PATCH 4/6 net: dsa: sja1105: Add static config tables for scheduling

In reply to Vladimir Oltean

In order to support tc-taprio offload, the TTEthernet egress scheduling core registers must be made visible through the static interface.

---
 .../net/dsa/sja1105/sja1105_dynamic_config.c  |   8 +
 .../net/dsa/sja1105/sja1105_static_config.c   | 167 ++++++++++++++++++
 .../net/dsa/sja1105/sja1105_static_config.h   |  48 ++++-
 3 files changed, 222 insertions(+), 1 deletion(-)
drivers/net/dsa/sja1105/sja1105_dynamic_config.c +8 -0
index 9988c9d18567..91da430045ff 100644
@@ -488,6 +488,8 @@ sja1105et_general_params_entry_packing(void *buf, void *entry_ptr,
 
 /* SJA1105E/T: First generation */
 struct sja1105_dynamic_table_ops sja1105et_dyn_ops[BLK_IDX_MAX_DYN] = {
+	[BLK_IDX_SCHEDULE] = {0},
+	[BLK_IDX_SCHEDULE_ENTRY_POINTS] = {0},
 	[BLK_IDX_L2_LOOKUP] = {
 		.entry_packing = sja1105et_dyn_l2_lookup_entry_packing,
 		.cmd_packing = sja1105et_l2_lookup_cmd_packing,
@@ -529,6 +531,8 @@ struct sja1105_dynamic_table_ops sja1105et_dyn_ops[BLK_IDX_MAX_DYN] = {
 		.packed_size = SJA1105ET_SIZE_MAC_CONFIG_DYN_CMD,
 		.addr = 0x36,
 	},
+	[BLK_IDX_SCHEDULE_PARAMS] = {0},
+	[BLK_IDX_SCHEDULE_ENTRY_POINTS_PARAMS] = {0},
 	[BLK_IDX_L2_LOOKUP_PARAMS] = {
 		.entry_packing = sja1105et_l2_lookup_params_entry_packing,
 		.cmd_packing = sja1105et_l2_lookup_params_cmd_packing,
@@ -552,6 +556,8 @@ struct sja1105_dynamic_table_ops sja1105et_dyn_ops[BLK_IDX_MAX_DYN] = {
 
 /* SJA1105P/Q/R/S: Second generation */
 struct sja1105_dynamic_table_ops sja1105pqrs_dyn_ops[BLK_IDX_MAX_DYN] = {
+	[BLK_IDX_SCHEDULE] = {0},
+	[BLK_IDX_SCHEDULE_ENTRY_POINTS] = {0},
 	[BLK_IDX_L2_LOOKUP] = {
 		.entry_packing = sja1105pqrs_dyn_l2_lookup_entry_packing,
 		.cmd_packing = sja1105pqrs_l2_lookup_cmd_packing,
@@ -593,6 +599,8 @@ struct sja1105_dynamic_table_ops sja1105pqrs_dyn_ops[BLK_IDX_MAX_DYN] = {
 		.packed_size = SJA1105PQRS_SIZE_MAC_CONFIG_DYN_CMD,
 		.addr = 0x4B,
 	},
+	[BLK_IDX_SCHEDULE_PARAMS] = {0},
+	[BLK_IDX_SCHEDULE_ENTRY_POINTS_PARAMS] = {0},
 	[BLK_IDX_L2_LOOKUP_PARAMS] = {
 		.entry_packing = sja1105et_l2_lookup_params_entry_packing,
 		.cmd_packing = sja1105et_l2_lookup_params_cmd_packing,
drivers/net/dsa/sja1105/sja1105_static_config.c +167 -0

268 lines not on this page · raw message

drivers/net/dsa/sja1105/sja1105_static_config.h +47 -1

109 lines not on this page · raw message

Signature · 1 line
2.17.1
author maintainer
#9 lore raw

RFC PATCH 5/6 net: dsa: sja1105: Advertise the 8 TX queues

In reply to Vladimir Oltean

This is a preparation patch for the tc-taprio offload (and potentially for other future offloads such as tc-mqprio).

Instead of looking directly at skb->priority during xmit, let's get the netdev queue and the queue-to-traffic-class mapping, and put the resulting traffic class into the dsa_8021q PCP field. The switch is configured with a 1-to-1 PCP-to-ingress-queue-to-egress-queue mapping (see vlan_pmap in sja1105_main.c), so the effect is that we can inject into a front-panel's egress traffic class through VLAN tagging from Linux, completely transparently.

Unfortunately the switch doesn't look at the VLAN PCP in the case of management traffic to/from the CPU (link-local frames at 01-80-C2-xx-xx-xx or 01-1B-19-xx-xx-xx) so we can't alter the transmission queue of this type of traffic on a frame-by-frame basis. It is only selected through the "hostprio" setting which ATM is harcoded in the driver to 7.

---
 drivers/net/dsa/sja1105/sja1105_main.c | 7 ++++++-
 net/dsa/tag_sja1105.c                  | 3 ++-
 2 files changed, 8 insertions(+), 2 deletions(-)
drivers/net/dsa/sja1105/sja1105_main.c +6 -1
index bc7e4e030b07..30761e6545a3 100644
@@ -384,7 +384,9 @@ static int sja1105_init_general_params(struct sja1105_private *priv)
 		/* Disallow dynamic changing of the mirror port */
 		.mirr_ptacu = 0,
 		.switchid = priv->ds->index,
-		/* Priority queue for link-local frames trapped to CPU */
+		/* Priority queue for link-local management frames
+		 * (both ingress to and egress from CPU - PTP, STP etc)
+		 */
 		.hostprio = 7,
 		.mac_fltres1 = SJA1105_LINKLOCAL_FILTER_A,
 		.mac_flt1    = SJA1105_LINKLOCAL_FILTER_A_MASK,
@@ -1704,6 +1706,9 @@ static int sja1105_setup(struct dsa_switch *ds)
 	 */
 	ds->vlan_filtering_is_global = true;
 
+	/* Advertise the 8 egress queues */
+	ds->num_tx_queues = SJA1105_NUM_TC;
+
 	/* The DSA/switchdev model brings up switch ports in standalone mode by
 	 * default, and that means vlan_filtering is 0 since they're not under
 	 * a bridge, so it's safe to set up switch tagging at this time.
net/dsa/tag_sja1105.c +2 -1
index 1d96c9d4a8e9..9ae84990f730 100644
@@ -89,7 +89,8 @@ static struct sk_buff *sja1105_xmit(struct sk_buff *skb,
 	struct dsa_port *dp = dsa_slave_to_port(netdev);
 	struct dsa_switch *ds = dp->ds;
 	u16 tx_vid = dsa_8021q_tx_vid(ds, dp->index);
-	u8 pcp = skb->priority;
+	u16 queue_mapping = skb_get_queue_mapping(skb);
+	u8 pcp = netdev_txq_to_tc(netdev, queue_mapping);
 
 	/* Transmitting management traffic does not rely upon switch tagging,
 	 * but instead SPI-installed management routes. Part 2 of this
Signature · 1 line
2.17.1
author maintainer
#10 lore raw

RFC PATCH 6/6 net: dsa: sja1105: Configure the Time-Aware Shaper via tc-taprio offload

In reply to Vladimir Oltean

This qdisc offload is the closest thing to what the SJA1105 supports in hardware for time-based egress shaping. The switch core really is built around SAE AS6802/TTEthernet (a TTTech standard) but can be made to operate similarly to IEEE 802.1Qbv with some constraints:

- The gate control list is a global list for all ports. There are 8 execution threads that iterate through this global list in parallel. I don't know why 8, there are only 4 front-panel ports.

- Care must be taken by the user to make sure that two execution threads never get to execute a GCL entry simultaneously. I created a O(n^5) checker for this hardware limitation, prior to accepting a taprio offload configuration as valid.

- The spec says that if a GCL entry's interval is shorter than the frame length, you shouldn't send it (and end up in head-of-line blocking). Well, this switch does anyway.

- The switch has no concept of ADMIN and OPER configurations. Because it's so simple, the TAS settings are loaded through the static config tables interface, so there isn't even place for any discussion about 'graceful switchover between ADMIN and OPER'. You just reset the switch and upload a new OPER config.

- The switch accepts multiple time sources for the gate events. Right now I am using the standalone clock source as opposed to PTP. So the base time parameter doesn't really do much. This is because the PTP part of the driver uses a timecounter/cyclecounter and its PTP clock is free-running (so it's not a valid time source for 802.1Qbv anyway).

---
 drivers/net/dsa/sja1105/Kconfig        |   8 +
 drivers/net/dsa/sja1105/Makefile       |   4 +
 drivers/net/dsa/sja1105/sja1105.h      |   6 +
 drivers/net/dsa/sja1105/sja1105_main.c |  12 +-
 drivers/net/dsa/sja1105/sja1105_tas.c  | 452 +++++++++++++++++++++++++
 drivers/net/dsa/sja1105/sja1105_tas.h  |  22 ++
 6 files changed, 503 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/dsa/sja1105/sja1105_tas.c
 create mode 100644 drivers/net/dsa/sja1105/sja1105_tas.h
drivers/net/dsa/sja1105/Kconfig +8 -0
index 770134a66e48..55424f39cb0d 100644
@@ -23,3 +23,11 @@ config NET_DSA_SJA1105_PTP
 	help
 	  This enables support for timestamping and PTP clock manipulations in
 	  the SJA1105 DSA driver.
+
+config NET_DSA_SJA1105_TAS
+	bool "Support for the Time-Aware Scheduler on NXP SJA1105"
+	depends on NET_DSA_SJA1105
+	help
+	  This enables support for the TTEthernet-based egress scheduling
+	  engine in the SJA1105 DSA driver, which is controlled using a
+	  hardware offload of the tc-tqprio qdisc.
drivers/net/dsa/sja1105/Makefile +4 -0
index 4483113e6259..66161e874344 100644
@@ -12,3 +12,7 @@ sja1105-objs := \
 ifdef CONFIG_NET_DSA_SJA1105_PTP
 sja1105-objs += sja1105_ptp.o
 endif
+
+ifdef CONFIG_NET_DSA_SJA1105_TAS
+sja1105-objs += sja1105_tas.o
+endif
drivers/net/dsa/sja1105/sja1105.h +6 -0
index 12cfcae0dc11..b326345f3f5c 100644
@@ -8,6 +8,7 @@
 #include <linux/ptp_clock_kernel.h>
 #include <linux/timecounter.h>
 #include <linux/dsa/sja1105.h>
+#include <net/pkt_sched.h>
 #include <net/dsa.h>
 #include <linux/mutex.h>
 #include "sja1105_static_config.h"
@@ -111,6 +112,8 @@ struct sja1105_private {
 	 */
 	struct mutex mgmt_lock;
 	struct sja1105_tagger_data tagger_data;
+	struct tc_taprio_qopt_offload *tas_config[SJA1105_NUM_PORTS];
+	struct work_struct tas_config_work;
 };
 
 #include "sja1105_dynamic_config.h"
@@ -127,6 +130,9 @@ typedef enum {
 	SPI_WRITE = 1,
 } sja1105_spi_rw_mode_t;
 
+/* From sja1105_main.c */
+int sja1105_static_config_reload(struct sja1105_private *priv);
+
 /* From sja1105_spi.c */
 int sja1105_spi_send_packed_buf(const struct sja1105_private *priv,
 				sja1105_spi_rw_mode_t rw, u64 reg_addr,
drivers/net/dsa/sja1105/sja1105_main.c +11 -1
index 30761e6545a3..0efc4bfa42d9 100644
@@ -22,6 +22,7 @@
 #include <linux/if_ether.h>
 #include <linux/dsa/8021q.h>
 #include "sja1105.h"
+#include "sja1105_tas.h"
 
 static void sja1105_hw_reset(struct gpio_desc *gpio, unsigned int pulse_len,
 			     unsigned int startup_delay)
@@ -1375,7 +1376,7 @@ static void sja1105_bridge_leave(struct dsa_switch *ds, int port,
  * modify at runtime (currently only MAC) and restore them after uploading,
  * such that this operation is relatively seamless.
  */
-static int sja1105_static_config_reload(struct sja1105_private *priv)
+int sja1105_static_config_reload(struct sja1105_private *priv)
 {
 	struct sja1105_mac_config_entry *mac;
 	int speed_mbps[SJA1105_NUM_PORTS];
@@ -1719,9 +1720,16 @@ static int sja1105_setup(struct dsa_switch *ds)
 static void sja1105_teardown(struct dsa_switch *ds)
 {
 	struct sja1105_private *priv = ds->priv;
+	int port;
 
 	cancel_work_sync(&priv->tagger_data.rxtstamp_work);
 	skb_queue_purge(&priv->tagger_data.skb_rxtstamp_queue);
+
+	cancel_work_sync(&priv->tas_config_work);
+
+	for (port = 0; port < SJA1105_NUM_PORTS; port++)
+		if (priv->tas_config[port])
+			kfree(priv->tas_config[port]);
 }
 
 static int sja1105_mgmt_xmit(struct dsa_switch *ds, int port, int slot,
@@ -2075,6 +2083,7 @@ static const struct dsa_switch_ops sja1105_switch_ops = {
 	.port_hwtstamp_set	= sja1105_hwtstamp_set,
 	.port_rxtstamp		= sja1105_port_rxtstamp,
 	.port_txtstamp		= sja1105_port_txtstamp,
+	.port_setup_taprio	= sja1105_setup_taprio,
 };
 
 static int sja1105_check_device_id(struct sja1105_private *priv)
@@ -2173,6 +2182,7 @@ static int sja1105_probe(struct spi_device *spi)
 	tagger_data = &priv->tagger_data;
 	skb_queue_head_init(&tagger_data->skb_rxtstamp_queue);
 	INIT_WORK(&tagger_data->rxtstamp_work, sja1105_rxtstamp_work);
+	INIT_WORK(&priv->tas_config_work, sja1105_tas_config_work);
 
 	/* Connections between dsa_port and sja1105_port */
 	for (i = 0; i < SJA1105_NUM_PORTS; i++) {
drivers/net/dsa/sja1105/sja1105_tas.c new file +452 -0

452 lines not on this page · raw message

drivers/net/dsa/sja1105/sja1105_tas.h new file +22 -0
new file mode 100644
index 000000000000..af535b4f5f29
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0
+ * Copyright (c) 2019, Vladimir Oltean <[email protected]>
+ */
+#ifndef _SJA1105_TAS_H
+#define _SJA1105_TAS_H
+
+#if IS_ENABLED(CONFIG_NET_DSA_SJA1105_TAS)
+
+void sja1105_tas_config_work(struct work_struct *work);
+
+int sja1105_setup_taprio(struct dsa_switch *ds, int port,
+			 struct tc_taprio_qopt_offload *qopt);
+
+#else
+
+#define sja1105_tas_config_work NULL
+
+#define sja1105_setup_taprio NULL
+
+#endif /* IS_ENABLED(CONFIG_NET_DSA_SJA1105_TAS) */
+
+#endif /* _SJA1105_TAS_H */
Signature · 1 line
2.17.1
maintainer
#11 lore raw
In reply to Vladimir Oltean
Quoted 5 lines

- Configuring the switch over SPI cannot apparently be done from this ndo_setup_tc callback because it runs in atomic context. I also have some downstream patches to offload tc clsact matchall with mirred action, but in that case it looks like the atomic context restriction does not apply.

There have been similar problems in the past. We can probably have the DSA layer turn it into a notifier. Look at the dsa_port_mdb_* functions for example.

Andrew

author maintainer
#12 lore raw
Quoted 7 lines · Andrew Lunn
Quoted 6 lines

- Configuring the switch over SPI cannot apparently be done from this ndo_setup_tc callback because it runs in atomic context. I also have some downstream patches to offload tc clsact matchall with mirred action, but in that case it looks like the atomic context restriction does not apply.

Quoted 5 lines

There have been similar problems in the past. We can probably have the DSA layer turn it into a notifier. Look at the dsa_port_mdb_* functions for example.

Andrew

Ok, thanks. I thought the dsa_port_notify functions are just to be called from switchdev. I'm still not sure I fully understand, but I'll try to switch to that in v2 and see what happens.

-Vladimir

#13 lore raw
Quoted 3 lines · Vladimir Oltean

I thought the dsa_port_notify functions are just to be called from switchdev. I'm still not sure I fully understand, but I'll try to switch to that in v2 and see what happens.

dsa_port_notify is used to forward an event occuring on a given port, to all switch chips of a fabric. For example when programming a VLAN on a port, all ports interconnecting switches together must to programmed too. Even though mainly switchdev objects or attributes are notified at the moment, a DSA notification is not specific to switchdev.

Thanks,

Vivien

#14 lore raw
In reply to Vladimir Oltean

Hi Vladimir,

Quoted 11 lines · Vladimir Oltean

Using Vinicius Costa Gomes' configuration interface for 802.1Qbv (later resent by Voon Weifeng for the stmmac driver), I am submitting for review a draft implementation of this offload for a DSA switch.

I don't want to insist too much on the hardware specifics of SJA1105 which isn't otherwise very compliant to the IEEE spec.

In order to be able to test with Vedang Patel's iproute2 patch for taprio offload (https://www.spinics.net/lists/netdev/msg573072.html)
I had to actually revert the txtime-assist branch as it had changed the iproute2 interface.

Now, that Vedang's work was merged, I will send a rebased version of the taprio offload series (also taking your feedback into account, see below).

Quoted 7 lines

In terms of impact for DSA drivers, I would like to point out that:

- Maybe somebody should pre-populate qopt->cycle_time in case the user does not provide one. Otherwise each driver needs to iterate over the GCL once, just to set the cycle time (right now stmmac does as
well).

Very fair, this should be very easy to do from taprio side.

Quoted 7 lines

- Configuring the switch over SPI cannot apparently be done from this ndo_setup_tc callback because it runs in atomic context. I also have some downstream patches to offload tc clsact matchall with mirred action, but in that case it looks like the atomic context restriction does not apply.

Quoted 6 lines

- I had to copy the struct tc_taprio_qopt_offload to driver private memory because a static config needs to be constructed every time a change takes place, and there are up to 4 switch ports that may take a TAS configuration. I have created a private tc_taprio_qopt_offload_copy() helper for this - I don't know whether it's of any help in the general case.

If everyone needs to do this, perhaps we can think of something else, one first idea is that taprio builds this configuration and gives ownership of it to the driver, but we would need to add _ref()/_unref() (or similar) helpers to the qdisc/driver API.

Quoted 11 lines

There is more to be done however. The TAS needs to be integrated with the PTP driver. This is because with a PTP clock source, the base time is written dynamically to the PTPSCHTM (PTP schedule time) register and must be a time in the future. Then the "real" base time of each port's TAS config can be offset by at most ~50 ms (the DELTA field from the Schedule Entry Points Table) relative to PTPSCHTM.
Because base times in the past are completely ignored by this hardware, we need to decide if it's ok behaviorally for a driver to "roll" a past base time into the immediate future by incrementally adding the cycle time (so the phase doesn't change).

That's another good piece of information. My understanding from reading section 8.6.9.1.1 from the IEEE 802.1Q-2018 spec, is that it's ok:

"""
CycleStartTime = (OperBaseTime + N*OperCycleTime) where N is the smallest integer for which the relation:
CycleStartTime >= CurrentTime
would be TRUE.
"""

Quoted 6 lines

If it is, then decide by how long in
the future it is ok to do so. Or alternatively, is it preferable if the driver errors out if the user-supplied base time is in the past and the hardware doesn't like it? But even then, there might be fringe cases when the base time becomes a past PTP time right as the driver tries to apply the config.

This fringe case is interesting. I don't know how to handle it well. The first idea that comes to mind is for the driver to add a integer number of cycles so there's enough time to apply the config. But this I think will be different for every driver, no?

Quoted 6 lines

Also applying a tc-taprio offload to a second SJA1105 switch port will inevitably need to roll the first port's (now past) base time into an equivalent future time.
All of this is going to be complicated even further by the fact that resetting the switch (to apply the tc-taprio offload) makes it reset its PTP time.

This is going to be complicated indeed.

Thanks a lot,
--
Vinicius