Skip to content

Commit 1ede4ac

Browse files
Danielmachondavem330
authored andcommitted
net: sparx5: add bookkeeping code for matchall rules
In preparation for new tc matchall rules, we add a bit of bookkeeping code to keep track of them. The rules are identified by the cookie passed from the tc stack. Signed-off-by: Daniel Machon <daniel.machon@microchip.com> Reviewed-by: Steen Hegelund <Steen.Hegelund@microchip.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 8c82bfd commit 1ede4ac

File tree

3 files changed

+67
-8
lines changed

3 files changed

+67
-8
lines changed

drivers/net/ethernet/microchip/sparx5/sparx5_main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,9 @@ static int mchp_sparx5_probe(struct platform_device *pdev)
899899
dev_err(sparx5->dev, "PTP failed\n");
900900
goto cleanup_ports;
901901
}
902+
903+
INIT_LIST_HEAD(&sparx5->mall_entries);
904+
902905
goto cleanup_config;
903906

904907
cleanup_ports:

drivers/net/ethernet/microchip/sparx5/sparx5_main.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/ptp_clock_kernel.h>
1919
#include <linux/hrtimer.h>
2020
#include <linux/debugfs.h>
21+
#include <net/flow_offload.h>
2122

2223
#include "sparx5_main_regs.h"
2324

@@ -227,6 +228,14 @@ struct sparx5_mdb_entry {
227228
u16 pgid_idx;
228229
};
229230

231+
struct sparx5_mall_entry {
232+
struct list_head list;
233+
struct sparx5_port *port;
234+
unsigned long cookie;
235+
enum flow_action_id type;
236+
bool ingress;
237+
};
238+
230239
#define SPARX5_PTP_TIMEOUT msecs_to_jiffies(10)
231240
#define SPARX5_SKB_CB(skb) \
232241
((struct sparx5_skb_cb *)((skb)->cb))
@@ -295,6 +304,7 @@ struct sparx5 {
295304
struct vcap_control *vcap_ctrl;
296305
/* PGID allocation map */
297306
u8 pgid_map[PGID_TABLE_SIZE];
307+
struct list_head mall_entries;
298308
/* Common root for debugfs */
299309
struct dentry *debugfs_root;
300310
};

drivers/net/ethernet/microchip/sparx5/sparx5_tc_matchall.c

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,37 @@
1111
#include "sparx5_main.h"
1212
#include "sparx5_vcap_impl.h"
1313

14+
static struct sparx5_mall_entry *
15+
sparx5_tc_matchall_entry_find(struct list_head *entries, unsigned long cookie)
16+
{
17+
struct sparx5_mall_entry *entry;
18+
19+
list_for_each_entry(entry, entries, list) {
20+
if (entry->cookie == cookie)
21+
return entry;
22+
}
23+
24+
return NULL;
25+
}
26+
27+
static void sparx5_tc_matchall_parse_action(struct sparx5_port *port,
28+
struct sparx5_mall_entry *entry,
29+
struct flow_action_entry *action,
30+
bool ingress,
31+
unsigned long cookie)
32+
{
33+
entry->port = port;
34+
entry->type = action->id;
35+
entry->ingress = ingress;
36+
entry->cookie = cookie;
37+
}
38+
1439
static int sparx5_tc_matchall_replace(struct net_device *ndev,
1540
struct tc_cls_matchall_offload *tmo,
1641
bool ingress)
1742
{
1843
struct sparx5_port *port = netdev_priv(ndev);
44+
struct sparx5_mall_entry *mall_entry;
1945
struct flow_action_entry *action;
2046
struct sparx5 *sparx5;
2147
int err;
@@ -27,6 +53,16 @@ static int sparx5_tc_matchall_replace(struct net_device *ndev,
2753
}
2854
action = &tmo->rule->action.entries[0];
2955

56+
mall_entry = kzalloc(sizeof(*mall_entry), GFP_KERNEL);
57+
if (!mall_entry)
58+
return -ENOMEM;
59+
60+
sparx5_tc_matchall_parse_action(port,
61+
mall_entry,
62+
action,
63+
ingress,
64+
tmo->cookie);
65+
3066
sparx5 = port->sparx5;
3167
switch (action->id) {
3268
case FLOW_ACTION_GOTO:
@@ -59,6 +95,9 @@ static int sparx5_tc_matchall_replace(struct net_device *ndev,
5995
NL_SET_ERR_MSG_MOD(tmo->common.extack, "Unsupported action");
6096
return -EOPNOTSUPP;
6197
}
98+
99+
list_add_tail(&mall_entry->list, &sparx5->mall_entries);
100+
62101
return 0;
63102
}
64103

@@ -67,19 +106,26 @@ static int sparx5_tc_matchall_destroy(struct net_device *ndev,
67106
bool ingress)
68107
{
69108
struct sparx5_port *port = netdev_priv(ndev);
70-
struct sparx5 *sparx5;
109+
struct sparx5 *sparx5 = port->sparx5;
110+
struct sparx5_mall_entry *entry;
71111
int err;
72112

73-
sparx5 = port->sparx5;
74-
if (!tmo->rule && tmo->cookie) {
113+
entry = sparx5_tc_matchall_entry_find(&sparx5->mall_entries,
114+
tmo->cookie);
115+
if (!entry)
116+
return -ENOENT;
117+
118+
if (entry->type == FLOW_ACTION_GOTO) {
75119
err = vcap_enable_lookups(sparx5->vcap_ctrl, ndev,
76120
0, 0, tmo->cookie, false);
77-
if (err)
78-
return err;
79-
return 0;
121+
} else {
122+
NL_SET_ERR_MSG_MOD(tmo->common.extack, "Unsupported action");
123+
err = -EOPNOTSUPP;
80124
}
81-
NL_SET_ERR_MSG_MOD(tmo->common.extack, "Unsupported action");
82-
return -EOPNOTSUPP;
125+
126+
list_del(&entry->list);
127+
128+
return err;
83129
}
84130

85131
int sparx5_tc_matchall(struct net_device *ndev,

0 commit comments

Comments
 (0)