tc-gate offload for SJA1105 DSA switch
Subsystems (5)
Vladimir Oltean
maintainerv2 cover tc-gate offload for SJA1105 DSA switch
From: Vladimir Oltean <[email protected]>
Expose the TTEthernet hardware features of the switch using standard tc-flower actions: trap, drop, redirect and gate.
v1 was submitted at:
https://patchwork.ozlabs.org/project/netdev/cover/[email protected]/
Changes in v2:
Using a newly introduced dsa_port_from_netdev public helper.
Vladimir Oltean (6):
net: dsa: introduce a dsa_port_from_netdev public helper
net: dsa: sja1105: add static tables for virtual links
net: dsa: sja1105: make room for virtual link parsing in flower
offload
net: dsa: sja1105: support flow-based redirection via virtual links
net: dsa: sja1105: implement tc-gate using time-triggered virtual
links
docs: net: dsa: sja1105: document intended usage of virtual links
Documentation/networking/dsa/sja1105.rst | 116 +++ drivers/net/dsa/sja1105/Kconfig | 9 + drivers/net/dsa/sja1105/Makefile | 4 + drivers/net/dsa/sja1105/sja1105.h | 59 +- .../net/dsa/sja1105/sja1105_dynamic_config.c | 51 ++ drivers/net/dsa/sja1105/sja1105_flower.c | 215 ++++- drivers/net/dsa/sja1105/sja1105_main.c | 13 +- drivers/net/dsa/sja1105/sja1105_ptp.h | 13 + drivers/net/dsa/sja1105/sja1105_spi.c | 2 + .../net/dsa/sja1105/sja1105_static_config.c | 202 +++++ .../net/dsa/sja1105/sja1105_static_config.h | 65 ++ drivers/net/dsa/sja1105/sja1105_tas.c | 127 ++- drivers/net/dsa/sja1105/sja1105_tas.h | 31 + drivers/net/dsa/sja1105/sja1105_vl.c | 796 ++++++++++++++++++ drivers/net/dsa/sja1105/sja1105_vl.h | 72 ++ include/net/dsa.h | 1 + net/dsa/dsa.c | 9 + 17 files changed, 1741 insertions(+), 44 deletions(-) create mode 100644 drivers/net/dsa/sja1105/sja1105_vl.c create mode 100644 drivers/net/dsa/sja1105/sja1105_vl.h
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v2 1/6 net: dsa: introduce a dsa_port_from_netdev public helper
From: Vladimir Oltean <[email protected]>
As its implementation shows, this is synonimous with calling dsa_slave_dev_check followed by dsa_slave_to_port, so it is quite simple already and provides functionality which is already there.
However there is now a need for these functions outside dsa_priv.h, for example in drivers that perform mirroring and redirection through tc-flower offloads (they are given raw access to the flow_cls_offload structure), where they need to call this function on act->dev.
But simply exporting dsa_slave_to_port would make it non-inline and would result in an extra function call in the hotpath, as can be seen for example in sja1105:
Before:
000006dc <sja1105_xmit>:
{
6dc: e92d4ff0 push {r4, r5, r6, r7, r8, r9, sl, fp, lr}
6e0: e1a04000 mov r4, r0
6e4: e591958c ldr r9, [r1, #1420] ; 0x58c <- Inline dsa_slave_to_port
6e8: e1a05001 mov r5, r1
6ec: e24dd004 sub sp, sp, #4
u16 tx_vid = dsa_8021q_tx_vid(dp->ds, dp->index); 6f0: e1c901d8 ldrd r0, [r9, #24] 6f4: ebfffffe bl 0 <dsa_8021q_tx_vid> 6f4: R_ARM_CALL dsa_8021q_tx_vid u8 pcp = netdev_txq_to_tc(netdev, queue_mapping); 6f8: e1d416b0 ldrh r1, [r4, #96] ; 0x60 u16 tx_vid = dsa_8021q_tx_vid(dp->ds, dp->index);
6fc: e1a08000 mov r8, r0
After:
000006e4 <sja1105_xmit>:
{
6e4: e92d4ff0 push {r4, r5, r6, r7, r8, r9, sl, fp, lr}
6e8: e1a04000 mov r4, r0
6ec: e24dd004 sub sp, sp, #4
struct dsa_port *dp = dsa_slave_to_port(netdev);
6f0: e1a00001 mov r0, r1
{
6f4: e1a05001 mov r5, r1
struct dsa_port *dp = dsa_slave_to_port(netdev);
6f8: ebfffffe bl 0 <dsa_slave_to_port>
6f8: R_ARM_CALL dsa_slave_to_port
6fc: e1a09000 mov r9, r0
u16 tx_vid = dsa_8021q_tx_vid(dp->ds, dp->index);
700: e1c001d8 ldrd r0, [r0, #24]
704: ebfffffe bl 0 <dsa_8021q_tx_vid>
704: R_ARM_CALL dsa_8021q_tx_vidBecause we want to avoid possible performance regressions, introduce this new function which is designed to be public.
---
Changes in v2:
Previous patch "net: dsa: export dsa_slave_dev_check and dsa_slave_to_port" was replaced with this one.
include/net/dsa.h | 1 + net/dsa/dsa.c | 9 +++++++++ 2 files changed, 10 insertions(+)
include/net/dsa.h +1 -0
@@ -637,6 +637,7 @@ void dsa_devlink_resource_occ_get_register(struct dsa_switch *ds, void *occ_get_priv);void dsa_devlink_resource_occ_get_unregister (struct dsa_switch *ds,u64 resource_id); +struct dsa_port *dsa_port_from_netdev (struct net_device *netdev);struct dsa_devlink_priv {struct dsa_switch *ds;
net/dsa/dsa.c +9 -0
@@ -412,6 +412,15 @@ void dsa_devlink_resource_occ_get_unregister(struct dsa_switch *ds, }EXPORT_SYMBOL_GPL (dsa_devlink_resource_occ_get_unregister); +struct dsa_port *dsa_port_from_netdev (struct net_device *netdev) +{ +if (!netdev || !dsa_slave_dev_check (netdev)) +return ERR_PTR (-ENODEV ); + +return dsa_slave_to_port (netdev); +} +EXPORT_SYMBOL_GPL (dsa_port_from_netdev); +static int __init dsa_init_module (void ) {int rc;
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v2 3/6 net: dsa: sja1105: make room for virtual link parsing in flower offload
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
Virtual links are a sja1105 hardware concept of executing various flow actions based on a key extracted from the frame's DMAC, VID and PCP.
Currently the tc-flower offload code supports only parsing the DMAC if that is the broadcast MAC address, and the VLAN PCP. Extract the key parsing logic from the L2 policers functionality and move it into its own function, after adding extra logic for matching on any DMAC and VID.
---
Changes from v1:
None.
Changes from RFC:
None.
drivers/net/dsa/sja1105/sja1105.h | 28 +++++- drivers/net/dsa/sja1105/sja1105_flower.c | 111 +++++++++++++++++------ 2 files changed, 112 insertions(+), 27 deletions(-)
drivers/net/dsa/sja1105/sja1105.h +27 -1
@@ -97,6 +97,32 @@ struct sja1105_info {const char *name; }; +enum sja1105_key_type { +SJA1105_KEY_BCAST , +SJA1105_KEY_TC , +SJA1105_KEY_VLAN_UNAWARE_VL , +SJA1105_KEY_VLAN_AWARE_VL , +}; + +struct sja1105_key { +enum sja1105_key_type type; + +union { +/* SJA1105_KEY_TC */ +struct { +int pcp; + } tc; + +/* SJA1105_KEY_VLAN_UNAWARE_VL */ +/* SJA1105_KEY_VLAN_AWARE_VL */ +struct { +u64 dmac; +u16 vid; +u16 pcp; + } vl; + }; +}; +enum sja1105_rule_type {SJA1105_RULE_BCAST_POLICER ,SJA1105_RULE_TC_POLICER ,
@@ -106,6 +132,7 @@ struct sja1105_rule {struct list_head list;unsigned long cookie;unsigned long port_mask; +struct sja1105_key key;enum sja1105_rule_type type;union {
@@ -117,7 +144,6 @@ struct sja1105_rule {/* SJA1105_RULE_TC_POLICER */ struct {int sharindx; -int tc; } tc_pol; }; };
drivers/net/dsa/sja1105/sja1105_flower.c +85 -26
179 lines not on this page · raw message
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v2 4/6 net: dsa: sja1105: support flow-based redirection via virtual links
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
Implement tc-flower offloads for redirect, trap and drop using non-critical virtual links.
Commands which were tested to work are:
# Send frames received on swp2 with a DA of 42:be:24:9b:76:20 to the
# CPU and to swp3. This type of key (DA only) when the port's VLAN
# awareness state is off.
tc qdisc add dev swp2 clsact
tc filter add dev swp2 ingress flower skip_sw dst_mac 42:be:24:9b:76:20 \
action mirred egress redirect dev swp3 \
action trap
# Drop frames received on swp2 with a DA of 42:be:24:9b:76:20, a VID
# of 100 and a PCP of 0.
tc filter add dev swp2 ingress protocol 802.1Q flower skip_sw \
dst_mac 42:be:24:9b:76:20 vlan_id 100 vlan_prio 0 action dropUnder the hood, all rules match on DMAC, VID and PCP, but when VLAN filtering is disabled, those are set internally by the driver to the port-based defaults. Because we would be put in an awkward situation if the user were to change the VLAN filtering state while there are active rules (packets would no longer match on the specified keys), we simply deny changing vlan_filtering unless the list of flows offloaded via virtual links is empty. Then the user can re-add new rules.
---
Changes from v1:
Using the new dsa_port_from_netdev helper.
Changes from RFC:
None.
drivers/net/dsa/sja1105/Kconfig | 9 + drivers/net/dsa/sja1105/Makefile | 4 + drivers/net/dsa/sja1105/sja1105.h | 18 ++ drivers/net/dsa/sja1105/sja1105_flower.c | 57 ++++- drivers/net/dsa/sja1105/sja1105_main.c | 12 +- drivers/net/dsa/sja1105/sja1105_vl.c | 302 +++++++++++++++++++++++ drivers/net/dsa/sja1105/sja1105_vl.h | 41 +++ 7 files changed, 437 insertions(+), 6 deletions(-) create mode 100644 drivers/net/dsa/sja1105/sja1105_vl.c create mode 100644 drivers/net/dsa/sja1105/sja1105_vl.h
drivers/net/dsa/sja1105/Kconfig +9 -0
@@ -33,3 +33,12 @@ config NET_DSA_SJA1105_TAS 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. + +config NET_DSA_SJA1105_VL + bool "Support for Virtual Links on NXP SJA1105" + depends on NET_DSA_SJA1105_TAS + help + This enables support for flow classification using capable devices + (SJA1105T, SJA1105Q, SJA1105S). The following actions are supported: + - redirect, trap, drop + - time-based ingress policing, via the tc-gate action
drivers/net/dsa/sja1105/Makefile +4 -0
@@ -17,3 +17,7 @@ endif ifdef CONFIG_NET_DSA_SJA1105_TAS sja1105-objs += sja1105_tas.o endif + +ifdef CONFIG_NET_DSA_SJA1105_VL +sja1105-objs += sja1105_vl.o +endif
drivers/net/dsa/sja1105/sja1105.h +18 -0
@@ -126,6 +126,13 @@ struct sja1105_key {enum sja1105_rule_type {SJA1105_RULE_BCAST_POLICER ,SJA1105_RULE_TC_POLICER , +SJA1105_RULE_VL , +}; + +enum sja1105_vl_type { +SJA1105_VL_NONCRITICAL , +SJA1105_VL_RATE_CONSTRAINED , +SJA1105_VL_TIME_TRIGGERED , };struct sja1105_rule {
@@ -135,6 +142,7 @@ struct sja1105_rule {struct sja1105_key key;enum sja1105_rule_type type; +/* Action */ union { /* SJA1105_RULE_BCAST_POLICER */ struct {
@@ -145,12 +153,19 @@ struct sja1105_rule {struct {int sharindx; } tc_pol; + +/* SJA1105_RULE_VL */ +struct { +unsigned long destports; +enum sja1105_vl_type type; + } vl; }; };struct sja1105_flow_block {struct list_head rules;bool l2_policer_used[SJA1105_NUM_L2_POLICERS ]; +int num_virtual_links; };struct sja1105_private {
@@ -187,6 +202,7 @@ enum sja1105_reset_reason {SJA1105_AGEING_TIME ,SJA1105_SCHEDULING ,SJA1105_BEST_EFFORT_POLICING , + SJA1105_VIRTUAL_LINKS, }; int sja1105_static_config_reload(struct sja1105_private *priv,
@@ -290,5 +306,7 @@ int sja1105_cls_flower_add(struct dsa_switch *ds, int port, struct flow_cls_offload *cls, bool ingress);void sja1105_flower_setup (struct dsa_switch *ds);void sja1105_flower_teardown (struct dsa_switch *ds); +struct sja1105_rule *sja1105_rule_find (struct sja1105_private *priv, +unsigned long cookie);#endif
drivers/net/dsa/sja1105/sja1105_flower.c +52 -5
99 lines not on this page · raw message
drivers/net/dsa/sja1105/sja1105_main.c +11 -1
@@ -445,7 +445,7 @@ static int sja1105_init_general_params(struct sja1105_private *priv)*/ .casc_port = SJA1105_NUM_PORTS,/* No TTEthernet */ - .vllupformat = 0, + .vllupformat = SJA1105_VL_FORMAT_PSFP, .vlmarker = 0, .vlmask = 0,/* Only update correctionField for 1-step PTP (L2 transport) */
@@ -1589,6 +1589,7 @@ static const char * const sja1105_reset_reasons[] = { [SJA1105_AGEING_TIME] = "Ageing time", [SJA1105_SCHEDULING] = "Time-aware scheduling", [SJA1105_BEST_EFFORT_POLICING] = "Best-effort policing", + [SJA1105_VIRTUAL_LINKS] = "Virtual links", };/* For situations where we need to change a setting at runtime that is only
@@ -1831,9 +1832,18 @@ static int sja1105_vlan_filtering(struct dsa_switch *ds, int port, bool enabled)struct sja1105_general_params_entry *general_params;struct sja1105_private *priv = ds->priv;struct sja1105_table *table; +struct sja1105_rule *rule;u16 tpid, tpid2;int rc; +list_for_each_entry (rule, &priv->flow_block.rules, list) { +if (rule->type ==SJA1105_RULE_VL ) { +dev_err (ds->dev, +"Cannot change VLAN filtering state while VL rules are active\n" ); +return -EBUSY ; + } + } +if (enabled) {/* Enable VLAN filtering. */ tpid =ETH_P_8021Q ;
drivers/net/dsa/sja1105/sja1105_vl.c new file +302 -0
302 lines not on this page · raw message
drivers/net/dsa/sja1105/sja1105_vl.h new file +41 -0
41 lines not on this page · raw message
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v2 2/6 net: dsa: sja1105: add static tables for virtual links
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
This patch adds the register definitions for the:
- VL Lookup Table
- VL Policing Table
- VL Forwarding Table
- VL Forwarding Parameters Table
These are needed in order to perform TTEthernet operations: QoS classification, flow-based policing and/or frame redirecting with the switch.
---
Changes from v1:
None.
Changes from RFC:
None.
drivers/net/dsa/sja1105/sja1105.h | 2 + .../net/dsa/sja1105/sja1105_dynamic_config.c | 51 +++++ .../net/dsa/sja1105/sja1105_static_config.c | 202 ++++++++++++++++++ .../net/dsa/sja1105/sja1105_static_config.h | 63 ++++++ 4 files changed, 318 insertions(+)
drivers/net/dsa/sja1105/sja1105.h +2 -0
@@ -254,6 +254,8 @@ size_t sja1105pqrs_mac_config_entry_packing(void *buf, void *entry_ptr, enum packing_op op);size_t sja1105pqrs_avb_params_entry_packing (void *buf,void *entry_ptr,enum packing_op op); +size_t sja1105_vl_lookup_entry_packing (void *buf,void *entry_ptr, +enum packing_op op);/* From sja1105_flower.c */ int sja1105_cls_flower_del(struct dsa_switch *ds, int port,
drivers/net/dsa/sja1105/sja1105_dynamic_config.c +51 -0
87 lines not on this page · raw message
drivers/net/dsa/sja1105/sja1105_static_config.c +202 -0
316 lines not on this page · raw message
drivers/net/dsa/sja1105/sja1105_static_config.h +63 -0
123 lines not on this page · raw message
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v2 5/6 net: dsa: sja1105: implement tc-gate using time-triggered virtual links
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
Restrict the TTEthernet hardware support on this switch to operate as closely as possible to IEEE 802.1Qci as possible. This means that it can perform PTP-time-based ingress admission control on streams identified by {DMAC, VID, PCP}, which is useful when trying to ensure the determinism of traffic scheduled via IEEE 802.1Qbv.
The oddity comes from the fact that in hardware (and in TTEthernet at large), virtual links always need a full-blown action, including not only the type of policing, but also the list of destination ports. So in practice, a single tc-gate action will result in all packets getting dropped. Additional actions (either "trap" or "redirect") need to be specified in the same filter rule such that the conforming packets are actually forwarded somewhere.
Apart from the VL Lookup, Policing and Forwarding tables which need to be programmed for each flow (virtual link), the Schedule engine also needs to be told to open/close the admission gates for each individual virtual link. A fairly accurate (and detailed) description of how that works is already present in sja1105_tas.c, since it is already used to trigger the egress gates for the tc-taprio offload (IEEE 802.1Qbv). Key point here, we remember that the schedule engine supports 8 "subschedules" (execution threads that iterate through the global schedule in parallel, and that no 2 hardware threads must execute a schedule entry at the same time). For tc-taprio, each egress port used one of these 8 subschedules, leaving a total of 4 subschedules unused. In principle we could have allocated 1 subschedule for the tc-gate offload of each ingress port, but actually the schedules of all virtual links installed on each ingress port would have needed to be merged together, before they could have been programmed to hardware. So simplify our life and just merge the entire tc-gate configuration, for all virtual links on all ingress ports, into a single subschedule. Be sure to check that against the usual hardware scheduling conflicts, and program it to hardware alongside any tc-taprio subschedule that may be present.
The following scenarios were tested:
1. Quantitative testing:
tc qdisc add dev swp2 clsact
tc filter add dev swp2 ingress flower skip_sw \
dst_mac 42:be:24:9b:76:20 \
action gate index 1 base-time 0 \
sched-entry OPEN 1200 -1 -1 \
sched-entry CLOSE 1200 -1 -1 \
action trap ping 192.168.1.2 -f
PING 192.168.1.2 (192.168.1.2) 56(84) bytes of data.
.............................
--- 192.168.1.2 ping statistics ---
948 packets transmitted, 467 received, 50.7384% packet loss, time 9671ms
2. Qualitative testing (with a phase-aligned schedule - the clocks are synchronized by ptp4l, not shown here):
Receiver (sja1105):
tc qdisc add dev swp2 clsact
now=$(phc_ctl /dev/ptp1 get | awk '/clock time is/ {print $5}') && \
sec=$(echo $now | awk -F. '{print $1}') && \
base_time="$(((sec + 2) * 1000000000))" && \
echo "base time ${base_time}"
tc filter add dev swp2 ingress flower skip_sw \
dst_mac 42:be:24:9b:76:20 \
action gate base-time ${base_time} \
sched-entry OPEN 60000 -1 -1 \
sched-entry CLOSE 40000 -1 -1 \
action trap
Sender (enetc):
now=$(phc_ctl /dev/ptp0 get | awk '/clock time is/ {print $5}') && \
sec=$(echo $now | awk -F. '{print $1}') && \
base_time="$(((sec + 2) * 1000000000))" && \
echo "base time ${base_time}"
tc qdisc add dev eno0 parent root taprio \
num_tc 8 \
map 0 1 2 3 4 5 6 7 \
queues 1@0 1@1 1@2 1@3 1@4 1@5 1@6 1@7 \
base-time ${base_time} \
sched-entry S 01 50000 \
sched-entry S 00 50000 \
flags 2 ping -A 192.168.1.1
PING 192.168.1.1 (192.168.1.1): 56 data bytes
...
^C
--- 192.168.1.1 ping statistics ---
1425 packets transmitted, 1424 packets received, 0% packet loss round-trip min/avg/max = 0.322/0.361/0.990 ms
And just for comparison, with the tc-taprio schedule deleted:
ping -A 192.168.1.1
PING 192.168.1.1 (192.168.1.1): 56 data bytes
...
^C
--- 192.168.1.1 ping statistics ---
33 packets transmitted, 19 packets received, 42% packet loss round-trip min/avg/max = 0.336/0.464/0.597 ms
---
Changes from v1:
None.
Changes from RFC:
* Deny gating actions in absence of any routing action. Without this check, the default behavior would be to drop everything, which is probably not what the user expects.
* Deny offloading IntervalOctetMax, which I initially mistook for meaning per-flow MTU. It actually means a sort of flow metering within each time slot. Not supported.
drivers/net/dsa/sja1105/sja1105.h | 13 +- drivers/net/dsa/sja1105/sja1105_flower.c | 57 +- drivers/net/dsa/sja1105/sja1105_main.c | 1 + drivers/net/dsa/sja1105/sja1105_ptp.h | 13 + drivers/net/dsa/sja1105/sja1105_spi.c | 2 + .../net/dsa/sja1105/sja1105_static_config.h | 2 + drivers/net/dsa/sja1105/sja1105_tas.c | 127 ++++- drivers/net/dsa/sja1105/sja1105_tas.h | 31 ++ drivers/net/dsa/sja1105/sja1105_vl.c | 494 ++++++++++++++++++ drivers/net/dsa/sja1105/sja1105_vl.h | 31 ++ 10 files changed, 754 insertions(+), 17 deletions(-)
drivers/net/dsa/sja1105/sja1105.h +12 -1
@@ -36,6 +36,7 @@ struct sja1105_regs {u64 status;u64 port_control;u64 rgu; +u64 vl_status;u64 config;u64 sgmii;u64 rmii_pll1;
@@ -156,8 +157,16 @@ struct sja1105_rule {/* SJA1105_RULE_VL */ struct { -unsigned long destports;enum sja1105_vl_type type; +unsigned long destports; +int sharindx; +int maxlen; +int ipv; +u64 base_time; +u64 cycle_time; +int num_entries; +struct action_gate_entry *entries; +struct flow_stats stats; } vl; }; };
@@ -304,6 +313,8 @@ int sja1105_cls_flower_del(struct dsa_switch *ds, int port, struct flow_cls_offload *cls, bool ingress);int sja1105_cls_flower_add (struct dsa_switch *ds,int port,struct flow_cls_offload *cls,bool ingress); +int sja1105_cls_flower_stats (struct dsa_switch *ds,int port, +struct flow_cls_offload *cls,bool ingress);void sja1105_flower_setup (struct dsa_switch *ds);void sja1105_flower_teardown (struct dsa_switch *ds); struct sja1105_rule *sja1105_rule_find(struct sja1105_private *priv,
drivers/net/dsa/sja1105/sja1105_flower.c +56 -1
95 lines not on this page · raw message
drivers/net/dsa/sja1105/sja1105_main.c +1 -0
@@ -2369,6 +2369,7 @@ static const struct dsa_switch_ops sja1105_switch_ops = { .port_policer_del = sja1105_port_policer_del, .cls_flower_add = sja1105_cls_flower_add, .cls_flower_del = sja1105_cls_flower_del, + .cls_flower_stats = sja1105_cls_flower_stats, };static int sja1105_check_device_id (struct sja1105_private *priv)
drivers/net/dsa/sja1105/sja1105_ptp.h +13 -0
@@ -48,6 +48,19 @@ static inline s64 future_base_time(s64 base_time, s64 cycle_time, s64 now)return base_time + n * cycle_time; } +/* This is not a preprocessor macro because the "ns" argument may or may not be +* s64 at caller side. This ensures it is properly type-cast before div_s64. +*/ +static inline s64 ns_to_sja1105_delta (s64 ns) +{ +return div_s64 (ns,200 ); +} + +static inline s64 sja1105_delta_to_ns (s64 delta) +{ +return delta *200 ; +} +struct sja1105_ptp_cmd {u64 startptpcp;/* start toggling PTP_CLK pin */ u64 stopptpcp;/* stop toggling PTP_CLK pin */
drivers/net/dsa/sja1105/sja1105_spi.c +2 -0
@@ -439,6 +439,7 @@ static struct sja1105_regs sja1105et_regs = { .prod_id = 0x100BC3, .status = 0x1, .port_control = 0x11, + .vl_status = 0x10000, .config = 0x020000, .rgu = 0x100440,/* UM10944.pdf, Table 86, ACU Register overview */
@@ -472,6 +473,7 @@ static struct sja1105_regs sja1105pqrs_regs = { .prod_id = 0x100BC3, .status = 0x1, .port_control = 0x12, + .vl_status = 0x10000, .config = 0x020000, .rgu = 0x100440,/* UM10944.pdf, Table 86, ACU Register overview */
drivers/net/dsa/sja1105/sja1105_static_config.h +2 -0
@@ -302,6 +302,8 @@ struct sja1105_vl_lookup_entry {u64 vlid; }; }; +/* Not part of hardware structure */ +unsigned long flow_cookie; };struct sja1105_vl_policing_entry {
drivers/net/dsa/sja1105/sja1105_tas.c +112 -15
190 lines not on this page · raw message
drivers/net/dsa/sja1105/sja1105_tas.h +31 -0
@@ -6,6 +6,8 @@#include <net/pkt_sched.h> +#define SJA1105_TAS_MAX_DELTA BIT(18) +#if IS_ENABLED (CONFIG_NET_DSA_SJA1105_TAS ) enum sja1105_tas_state {
@@ -20,8 +22,23 @@ enum sja1105_ptp_op { SJA1105_PTP_ADJUSTFREQ, }; +struct sja1105_gate_entry { +struct list_head list; +struct sja1105_rule *rule; +s64 interval; +u8 gate_state; +}; + +struct sja1105_gating_config { +u64 cycle_time; +s64 base_time; +int num_entries; +struct list_head entries; +}; +struct sja1105_tas_data {struct tc_taprio_qopt_offload *offload[SJA1105_NUM_PORTS ]; +struct sja1105_gating_config gating_cfg;enum sja1105_tas_state state;enum sja1105_ptp_op last_op;struct work_struct tas_work;
@@ -31,6 +48,8 @@ struct sja1105_tas_data {bool enabled; }; +struct sja1105_private ; +int sja1105_setup_tc_taprio (struct dsa_switch *ds,int port,struct tc_taprio_qopt_offload *admin);
@@ -42,6 +61,11 @@ void sja1105_tas_clockstep(struct dsa_switch *ds);void sja1105_tas_adjfreq (struct dsa_switch *ds); +bool sja1105_gating_check_conflicts (struct sja1105_private *priv,int port, +struct netlink_ext_ack *extack); + +int sja1105_init_scheduling (struct sja1105_private *priv); +#else /* C doesn't allow empty structures, bah! */
@@ -63,6 +87,13 @@ static inline void sja1105_tas_clockstep(struct dsa_switch *ds) { }static inline void sja1105_tas_adjfreq (struct dsa_switch *ds) { } +static inline bool +sja1105_gating_check_conflicts (struct dsa_switch *ds,int port, +struct netlink_ext_ack *extack) +{ +return true; +} +#endif /* IS_ENABLED(CONFIG_NET_DSA_SJA1105_TAS) */ #endif /* _SJA1105_TAS_H */
drivers/net/dsa/sja1105/sja1105_vl.c +494 -0
548 lines not on this page · raw message
drivers/net/dsa/sja1105/sja1105_vl.h +31 -0
@@ -15,6 +15,16 @@ int sja1105_vl_delete(struct sja1105_private *priv, int port,struct sja1105_rule *rule, struct netlink_ext_ack *extack); +int sja1105_vl_gate (struct sja1105_private *priv,int port, +struct netlink_ext_ack *extack,unsigned long cookie, +struct sja1105_key *key,u32 index,s32 prio, +u64 base_time,u64 cycle_time,u64 cycle_time_ext, +u32 num_entries,struct action_gate_entry *entries); + +int sja1105_vl_stats (struct sja1105_private *priv,int port, +struct sja1105_rule *rule,struct flow_stats *stats, +struct netlink_ext_ack *extack); +#else static inline int sja1105_vl_redirect(struct sja1105_private *priv, int port,
@@ -36,6 +46,27 @@ static inline int sja1105_vl_delete(struct sja1105_private *priv,return -EOPNOTSUPP ; } +static inline int sja1105_vl_gate (struct sja1105_private *priv,int port, +struct netlink_ext_ack *extack, +unsigned long cookie, +struct sja1105_key *key,u32 index,s32 prio, +u64 base_time,u64 cycle_time, +u64 cycle_time_ext,u32 num_entries, +struct action_gate_entry *entries) +{ +NL_SET_ERR_MSG_MOD (extack,"Virtual Links not compiled in" ); +return -EOPNOTSUPP ; +} + +static inline int sja1105_vl_stats (struct sja1105_private *priv,int port, +struct sja1105_rule *rule, +struct flow_stats *stats, +struct netlink_ext_ack *extack) +{ +NL_SET_ERR_MSG_MOD (extack,"Virtual Links not compiled in" ); +return -EOPNOTSUPP ; +} +#endif /* IS_ENABLED(CONFIG_NET_DSA_SJA1105_VL) */ #endif /* _SJA1105_VL_H */
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v2 6/6 docs: net: dsa: sja1105: document intended usage of virtual links
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
Add some verbiage describing how the hardware features of the switch are exposed to users through tc-flower.
---
Changes from v1:
None.
Changes from RFC:
Patch is new.
Documentation/networking/dsa/sja1105.rst | 116 +++++++++++++++++++++++ 1 file changed, 116 insertions(+)
Documentation/networking/dsa/sja1105.rst +116 -0
@@ -230,6 +230,122 @@ simultaneously on two ports. The driver checks the consistency of the schedules against this restriction and errors out when appropriate. Schedule analysis is needed to avoid this, which is outside the scope of the document. +Routing actions (redirect, trap, drop) +-------------------------------------- + +The switch is able to offload flow-based redirection of packets to a set of +destination ports specified by the user. Internally, this is implemented by +making use of Virtual Links, a TTEthernet concept. + +The driver supports 2 types of keys for Virtual Links: + +- VLAN-aware virtual links: these match on destination MAC address, VLAN ID and + VLAN PCP. +- VLAN-unaware virtual links: these match on destination MAC address only. + +The VLAN awareness state of the bridge (vlan_filtering) cannot be changed while +there are virtual link rules installed. + +Composing multiple actions inside the same rule is supported. When only routing +actions are requested, the driver creates a "non-critical" virtual link. When +the action list also contains tc-gate (more details below), the virtual link +becomes "time-critical" (draws frame buffers from a reserved memory partition, +etc). + +The 3 routing actions that are supported are "trap", "drop" and "redirect". + +Example 1: send frames received on swp2 with a DA of 42:be:24:9b:76:20 to the +CPU and to swp3. This type of key (DA only) when the port's VLAN awareness +state is off:: + + tc qdisc add dev swp2 clsact + tc filter add dev swp2 ingress flower skip_sw dst_mac 42:be:24:9b:76:20 \ + action mirred egress redirect dev swp3 \ + action trap + +Example 2: drop frames received on swp2 with a DA of 42:be:24:9b:76:20, a VID +of 100 and a PCP of 0:: + + tc filter add dev swp2 ingress protocol 802.1Q flower skip_sw \ + dst_mac 42:be:24:9b:76:20 vlan_id 100 vlan_prio 0 action drop + +Time-based ingress policing +--------------------------- + +The TTEthernet hardware abilities of the switch can be constrained to act +similarly to the Per-Stream Filtering and Policing (PSFP) clause specified in +IEEE 802.1Q-2018 (formerly 802.1Qci). This means it can be used to perform +tight timing-based admission control for up to 1024 flows (identified by a +tuple composed of destination MAC address, VLAN ID and VLAN PCP). Packets which +are received outside their expected reception window are dropped. + +This capability can be managed through the offload of the tc-gate action. As +routing actions are intrinsic to virtual links in TTEthernet (which performs +explicit routing of time-critical traffic and does not leave that in the hands +of the FDB, flooding etc), the tc-gate action may never appear alone when +asking sja1105 to offload it. One (or more) redirect or trap actions must also +follow along. + +Example: create a tc-taprio schedule that is phase-aligned with a tc-gate +schedule (the clocks must be synchronized by a 1588 application stack, which is +outside the scope of this document). No packet delivered by the sender will be +dropped. Note that the reception window is larger than the transmission window +(and much more so, in this example) to compensate for the packet propagation +delay of the link (which can be determined by the 1588 application stack). + +Receiver (sja1105):: + + tc qdisc add dev swp2 clsact + now=$(phc_ctl /dev/ptp1 get | awk '/clock time is/ {print $5}') && \ + sec=$(echo $now | awk -F. '{print $1}') && \ + base_time="$(((sec + 2) * 1000000000))" && \ + echo "base time ${base_time}" + tc filter add dev swp2 ingress flower skip_sw \ + dst_mac 42:be:24:9b:76:20 \ + action gate base-time ${base_time} \ + sched-entry OPEN 60000 -1 -1 \ + sched-entry CLOSE 40000 -1 -1 \ + action trap + +Sender:: + + now=$(phc_ctl /dev/ptp0 get | awk '/clock time is/ {print $5}') && \ + sec=$(echo $now | awk -F. '{print $1}') && \ + base_time="$(((sec + 2) * 1000000000))" && \ + echo "base time ${base_time}" + tc qdisc add dev eno0 parent root taprio \ + num_tc 8 \ + map 0 1 2 3 4 5 6 7 \ + queues 1@0 1@1 1@2 1@3 1@4 1@5 1@6 1@7 \ + base-time ${base_time} \ + sched-entry S 01 50000 \ + sched-entry S 00 50000 \ + flags 2 + +The engine used to schedule the ingress gate operations is the same that the +one used for the tc-taprio offload. Therefore, the restrictions regarding the +fact that no two gate actions (either tc-gate or tc-taprio gates) may fire at +the same time (during the same 200 ns slot) still apply. + +To come in handy, it is possible to share time-triggered virtual links across +more than 1 ingress port, via flow blocks. In this case, the restriction of +firing at the same time does not apply because there is a single schedule in +the system, that of the shared virtual link:: + + tc qdisc add dev swp2 ingress_block 1 clsact + tc qdisc add dev swp3 ingress_block 1 clsact + tc filter add block 1 flower skip_sw dst_mac 42:be:24:9b:76:20 \ + action gate index 2 \ + base-time 0 \ + sched-entry OPEN 50000000 -1 -1 \ + sched-entry CLOSE 50000000 -1 -1 \ + action trap + +Hardware statistics for each flow are also available ("pkts" counts the number +of dropped frames, which is a sum of frames dropped due to timing violations, +lack of destination ports and MTU enforcement checks). Byte-level counters are +not available. + Device Tree bindings and board design =====================================
Signature · 1 line
2.17.1