summaryrefslogtreecommitdiff
path: root/drivers/net/ethernet/microchip/lan966x/lan966x_tc_matchall.c
blob: a539abaad9b674eeca9e2ced5be69372473abb8b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// SPDX-License-Identifier: GPL-2.0+

#include "lan966x_main.h"

static int lan966x_tc_matchall_add(struct lan966x_port *port,
				   struct tc_cls_matchall_offload *f,
				   bool ingress)
{
	struct flow_action_entry *act;

	if (!flow_offload_has_one_action(&f->rule->action)) {
		NL_SET_ERR_MSG_MOD(f->common.extack,
				   "Only once action per filter is supported");
		return -EOPNOTSUPP;
	}

	act = &f->rule->action.entries[0];
	switch (act->id) {
	case FLOW_ACTION_POLICE:
		return lan966x_police_port_add(port, &f->rule->action, act,
					       f->cookie, ingress,
					       f->common.extack);
	case FLOW_ACTION_MIRRED:
		return lan966x_mirror_port_add(port, act, f->cookie,
					       ingress, f->common.extack);
	case FLOW_ACTION_GOTO:
		return lan966x_goto_port_add(port, act, f->cookie,
					     f->common.extack);
	default:
		NL_SET_ERR_MSG_MOD(f->common.extack,
				   "Unsupported action");
		return -EOPNOTSUPP;
	}

	return 0;
}

static int lan966x_tc_matchall_del(struct lan966x_port *port,
				   struct tc_cls_matchall_offload *f,
				   bool ingress)
{
	if (f->cookie == port->tc.police_id) {
		return lan966x_police_port_del(port, f->cookie,
					       f->common.extack);
	} else if (f->cookie == port->tc.ingress_mirror_id ||
		   f->cookie == port->tc.egress_mirror_id) {
		return lan966x_mirror_port_del(port, ingress,
					       f->common.extack);
	} else if (f->cookie == port->tc.goto_id) {
		return lan966x_goto_port_del(port, f->cookie,
					     f->common.extack);
	} else {
		NL_SET_ERR_MSG_MOD(f->common.extack,
				   "Unsupported action");
		return -EOPNOTSUPP;
	}

	return 0;
}

static int lan966x_tc_matchall_stats(struct lan966x_port *port,
				     struct tc_cls_matchall_offload *f,
				     bool ingress)
{
	if (f->cookie == port->tc.police_id) {
		lan966x_police_port_stats(port, &f->stats);
	} else if (f->cookie == port->tc.ingress_mirror_id ||
		   f->cookie == port->tc.egress_mirror_id) {
		lan966x_mirror_port_stats(port, &f->stats, ingress);
	} else {
		NL_SET_ERR_MSG_MOD(f->common.extack,
				   "Unsupported action");
		return -EOPNOTSUPP;
	}

	return 0;
}

int lan966x_tc_matchall(struct lan966x_port *port,
			struct tc_cls_matchall_offload *f,
			bool ingress)
{
	if (!tc_cls_can_offload_and_chain0(port->dev, &f->common)) {
		NL_SET_ERR_MSG_MOD(f->common.extack,
				   "Only chain zero is supported");
		return -EOPNOTSUPP;
	}

	switch (f->command) {
	case TC_CLSMATCHALL_REPLACE:
		return lan966x_tc_matchall_add(port, f, ingress);
	case TC_CLSMATCHALL_DESTROY:
		return lan966x_tc_matchall_del(port, f, ingress);
	case TC_CLSMATCHALL_STATS:
		return lan966x_tc_matchall_stats(port, f, ingress);
	default:
		return -EOPNOTSUPP;
	}

	return 0;
}