Skip to content

Commit dfacc5a

Browse files
vladimirolteandavem330
authored andcommitted
net: dsa: sja1105: support flow-based redirection via virtual links
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 drop Under 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. Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent b70bb8d commit dfacc5a

7 files changed

Lines changed: 437 additions & 6 deletions

File tree

‎drivers/net/dsa/sja1105/Kconfig‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,12 @@ config NET_DSA_SJA1105_TAS
3434
This enables support for the TTEthernet-based egress scheduling
3535
engine in the SJA1105 DSA driver, which is controlled using a
3636
hardware offload of the tc-tqprio qdisc.
37+
38+
config NET_DSA_SJA1105_VL
39+
bool "Support for Virtual Links on NXP SJA1105"
40+
depends on NET_DSA_SJA1105_TAS
41+
help
42+
This enables support for flow classification using capable devices
43+
(SJA1105T, SJA1105Q, SJA1105S). The following actions are supported:
44+
- redirect, trap, drop
45+
- time-based ingress policing, via the tc-gate action

‎drivers/net/dsa/sja1105/Makefile‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ endif
1717
ifdef CONFIG_NET_DSA_SJA1105_TAS
1818
sja1105-objs += sja1105_tas.o
1919
endif
20+
21+
ifdef CONFIG_NET_DSA_SJA1105_VL
22+
sja1105-objs += sja1105_vl.o
23+
endif

‎drivers/net/dsa/sja1105/sja1105.h‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,13 @@ struct sja1105_key {
126126
enum sja1105_rule_type {
127127
SJA1105_RULE_BCAST_POLICER,
128128
SJA1105_RULE_TC_POLICER,
129+
SJA1105_RULE_VL,
130+
};
131+
132+
enum sja1105_vl_type {
133+
SJA1105_VL_NONCRITICAL,
134+
SJA1105_VL_RATE_CONSTRAINED,
135+
SJA1105_VL_TIME_TRIGGERED,
129136
};
130137

131138
struct sja1105_rule {
@@ -135,6 +142,7 @@ struct sja1105_rule {
135142
struct sja1105_key key;
136143
enum sja1105_rule_type type;
137144

145+
/* Action */
138146
union {
139147
/* SJA1105_RULE_BCAST_POLICER */
140148
struct {
@@ -145,12 +153,19 @@ struct sja1105_rule {
145153
struct {
146154
int sharindx;
147155
} tc_pol;
156+
157+
/* SJA1105_RULE_VL */
158+
struct {
159+
unsigned long destports;
160+
enum sja1105_vl_type type;
161+
} vl;
148162
};
149163
};
150164

151165
struct sja1105_flow_block {
152166
struct list_head rules;
153167
bool l2_policer_used[SJA1105_NUM_L2_POLICERS];
168+
int num_virtual_links;
154169
};
155170

156171
struct sja1105_private {
@@ -187,6 +202,7 @@ enum sja1105_reset_reason {
187202
SJA1105_AGEING_TIME,
188203
SJA1105_SCHEDULING,
189204
SJA1105_BEST_EFFORT_POLICING,
205+
SJA1105_VIRTUAL_LINKS,
190206
};
191207

192208
int sja1105_static_config_reload(struct sja1105_private *priv,
@@ -290,5 +306,7 @@ int sja1105_cls_flower_add(struct dsa_switch *ds, int port,
290306
struct flow_cls_offload *cls, bool ingress);
291307
void sja1105_flower_setup(struct dsa_switch *ds);
292308
void sja1105_flower_teardown(struct dsa_switch *ds);
309+
struct sja1105_rule *sja1105_rule_find(struct sja1105_private *priv,
310+
unsigned long cookie);
293311

294312
#endif

‎drivers/net/dsa/sja1105/sja1105_flower.c‎

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
/* Copyright 2020, NXP Semiconductors
33
*/
44
#include "sja1105.h"
5+
#include "sja1105_vl.h"
56

6-
static struct sja1105_rule *sja1105_rule_find(struct sja1105_private *priv,
7-
unsigned long cookie)
7+
struct sja1105_rule *sja1105_rule_find(struct sja1105_private *priv,
8+
unsigned long cookie)
89
{
910
struct sja1105_rule *rule;
1011

@@ -173,7 +174,8 @@ static int sja1105_setup_tc_policer(struct sja1105_private *priv,
173174

174175
static int sja1105_flower_policer(struct sja1105_private *priv, int port,
175176
struct netlink_ext_ack *extack,
176-
unsigned long cookie, struct sja1105_key *key,
177+
unsigned long cookie,
178+
struct sja1105_key *key,
177179
u64 rate_bytes_per_sec,
178180
s64 burst)
179181
{
@@ -308,6 +310,7 @@ int sja1105_cls_flower_add(struct dsa_switch *ds, int port,
308310
const struct flow_action_entry *act;
309311
unsigned long cookie = cls->cookie;
310312
struct sja1105_key key;
313+
bool vl_rule = false;
311314
int rc, i;
312315

313316
rc = sja1105_flower_parse_key(priv, extack, cls, &key);
@@ -319,20 +322,61 @@ int sja1105_cls_flower_add(struct dsa_switch *ds, int port,
319322
flow_action_for_each(i, act, &rule->action) {
320323
switch (act->id) {
321324
case FLOW_ACTION_POLICE:
322-
rc = sja1105_flower_policer(priv, port,
323-
extack, cookie, &key,
325+
rc = sja1105_flower_policer(priv, port, extack, cookie,
326+
&key,
324327
act->police.rate_bytes_ps,
325328
act->police.burst);
326329
if (rc)
327330
goto out;
328331
break;
332+
case FLOW_ACTION_TRAP: {
333+
int cpu = dsa_upstream_port(ds, port);
334+
335+
vl_rule = true;
336+
337+
rc = sja1105_vl_redirect(priv, port, extack, cookie,
338+
&key, BIT(cpu), true);
339+
if (rc)
340+
goto out;
341+
break;
342+
}
343+
case FLOW_ACTION_REDIRECT: {
344+
struct dsa_port *to_dp;
345+
346+
to_dp = dsa_port_from_netdev(act->dev);
347+
if (IS_ERR(to_dp)) {
348+
NL_SET_ERR_MSG_MOD(extack,
349+
"Destination not a switch port");
350+
return -EOPNOTSUPP;
351+
}
352+
353+
vl_rule = true;
354+
355+
rc = sja1105_vl_redirect(priv, port, extack, cookie,
356+
&key, BIT(to_dp->index), true);
357+
if (rc)
358+
goto out;
359+
break;
360+
}
361+
case FLOW_ACTION_DROP:
362+
vl_rule = true;
363+
364+
rc = sja1105_vl_redirect(priv, port, extack, cookie,
365+
&key, 0, false);
366+
if (rc)
367+
goto out;
368+
break;
329369
default:
330370
NL_SET_ERR_MSG_MOD(extack,
331371
"Action not supported");
332372
rc = -EOPNOTSUPP;
333373
goto out;
334374
}
335375
}
376+
377+
if (vl_rule && !rc)
378+
rc = sja1105_static_config_reload(priv, SJA1105_VIRTUAL_LINKS);
379+
336380
out:
337381
return rc;
338382
}
@@ -348,6 +392,9 @@ int sja1105_cls_flower_del(struct dsa_switch *ds, int port,
348392
if (!rule)
349393
return 0;
350394

395+
if (rule->type == SJA1105_RULE_VL)
396+
return sja1105_vl_delete(priv, port, rule, cls->common.extack);
397+
351398
policing = priv->static_config.tables[BLK_IDX_L2_POLICING].entries;
352399

353400
if (rule->type == SJA1105_RULE_BCAST_POLICER) {

‎drivers/net/dsa/sja1105/sja1105_main.c‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ static int sja1105_init_general_params(struct sja1105_private *priv)
445445
*/
446446
.casc_port = SJA1105_NUM_PORTS,
447447
/* No TTEthernet */
448-
.vllupformat = 0,
448+
.vllupformat = SJA1105_VL_FORMAT_PSFP,
449449
.vlmarker = 0,
450450
.vlmask = 0,
451451
/* Only update correctionField for 1-step PTP (L2 transport) */
@@ -1589,6 +1589,7 @@ static const char * const sja1105_reset_reasons[] = {
15891589
[SJA1105_AGEING_TIME] = "Ageing time",
15901590
[SJA1105_SCHEDULING] = "Time-aware scheduling",
15911591
[SJA1105_BEST_EFFORT_POLICING] = "Best-effort policing",
1592+
[SJA1105_VIRTUAL_LINKS] = "Virtual links",
15921593
};
15931594

15941595
/* 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)
18311832
struct sja1105_general_params_entry *general_params;
18321833
struct sja1105_private *priv = ds->priv;
18331834
struct sja1105_table *table;
1835+
struct sja1105_rule *rule;
18341836
u16 tpid, tpid2;
18351837
int rc;
18361838

1839+
list_for_each_entry(rule, &priv->flow_block.rules, list) {
1840+
if (rule->type == SJA1105_RULE_VL) {
1841+
dev_err(ds->dev,
1842+
"Cannot change VLAN filtering state while VL rules are active\n");
1843+
return -EBUSY;
1844+
}
1845+
}
1846+
18371847
if (enabled) {
18381848
/* Enable VLAN filtering. */
18391849
tpid = ETH_P_8021Q;

0 commit comments

Comments
 (0)