summaryrefslogtreecommitdiff
path: root/drivers/net/ethernet/microchip/lan966x/lan966x_tc.c
blob: 336eb7ee0d608417b05301a659cdce549ff244aa (plain)
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
// SPDX-License-Identifier: GPL-2.0+

#include <net/pkt_cls.h>

#include "lan966x_main.h"

static int lan966x_tc_setup_qdisc_mqprio(struct lan966x_port *port,
					 struct tc_mqprio_qopt_offload *mqprio)
{
	u8 num_tc = mqprio->qopt.num_tc;

	mqprio->qopt.hw = TC_MQPRIO_HW_OFFLOAD_TCS;

	return num_tc ? lan966x_mqprio_add(port, num_tc) :
			lan966x_mqprio_del(port);
}

static int lan966x_tc_setup_qdisc_taprio(struct lan966x_port *port,
					 struct tc_taprio_qopt_offload *taprio)
{
	return taprio->enable ? lan966x_taprio_add(port, taprio) :
				lan966x_taprio_del(port);
}

static int lan966x_tc_setup_qdisc_tbf(struct lan966x_port *port,
				      struct tc_tbf_qopt_offload *qopt)
{
	switch (qopt->command) {
	case TC_TBF_REPLACE:
		return lan966x_tbf_add(port, qopt);
	case TC_TBF_DESTROY:
		return lan966x_tbf_del(port, qopt);
	default:
		return -EOPNOTSUPP;
	}

	return -EOPNOTSUPP;
}

static int lan966x_tc_setup_qdisc_cbs(struct lan966x_port *port,
				      struct tc_cbs_qopt_offload *qopt)
{
	return qopt->enable ? lan966x_cbs_add(port, qopt) :
			      lan966x_cbs_del(port, qopt);
}

static int lan966x_tc_setup_qdisc_ets(struct lan966x_port *port,
				      struct tc_ets_qopt_offload *qopt)
{
	switch (qopt->command) {
	case TC_ETS_REPLACE:
		return lan966x_ets_add(port, qopt);
	case TC_ETS_DESTROY:
		return lan966x_ets_del(port, qopt);
	default:
		return -EOPNOTSUPP;
	};

	return -EOPNOTSUPP;
}

int lan966x_tc_setup(struct net_device *dev, enum tc_setup_type type,
		     void *type_data)
{
	struct lan966x_port *port = netdev_priv(dev);

	switch (type) {
	case TC_SETUP_QDISC_MQPRIO:
		return lan966x_tc_setup_qdisc_mqprio(port, type_data);
	case TC_SETUP_QDISC_TAPRIO:
		return lan966x_tc_setup_qdisc_taprio(port, type_data);
	case TC_SETUP_QDISC_TBF:
		return lan966x_tc_setup_qdisc_tbf(port, type_data);
	case TC_SETUP_QDISC_CBS:
		return lan966x_tc_setup_qdisc_cbs(port, type_data);
	case TC_SETUP_QDISC_ETS:
		return lan966x_tc_setup_qdisc_ets(port, type_data);
	default:
		return -EOPNOTSUPP;
	}

	return 0;
}