1 // SPDX-License-Identifier: GPL-2.0+
3 #include <net/pkt_cls.h>
4 #include <net/pkt_sched.h>
6 #include "lan966x_main.h"
8 static LIST_HEAD(lan966x_tc_block_cb_list);
10 static int lan966x_tc_setup_qdisc_mqprio(struct lan966x_port *port,
11 struct tc_mqprio_qopt_offload *mqprio)
13 u8 num_tc = mqprio->qopt.num_tc;
15 mqprio->qopt.hw = TC_MQPRIO_HW_OFFLOAD_TCS;
17 return num_tc ? lan966x_mqprio_add(port, num_tc) :
18 lan966x_mqprio_del(port);
21 static int lan966x_tc_setup_qdisc_taprio(struct lan966x_port *port,
22 struct tc_taprio_qopt_offload *taprio)
24 switch (taprio->cmd) {
25 case TAPRIO_CMD_REPLACE:
26 return lan966x_taprio_add(port, taprio);
27 case TAPRIO_CMD_DESTROY:
28 return lan966x_taprio_del(port);
34 static int lan966x_tc_setup_qdisc_tbf(struct lan966x_port *port,
35 struct tc_tbf_qopt_offload *qopt)
37 switch (qopt->command) {
39 return lan966x_tbf_add(port, qopt);
41 return lan966x_tbf_del(port, qopt);
49 static int lan966x_tc_setup_qdisc_cbs(struct lan966x_port *port,
50 struct tc_cbs_qopt_offload *qopt)
52 return qopt->enable ? lan966x_cbs_add(port, qopt) :
53 lan966x_cbs_del(port, qopt);
56 static int lan966x_tc_setup_qdisc_ets(struct lan966x_port *port,
57 struct tc_ets_qopt_offload *qopt)
59 switch (qopt->command) {
61 return lan966x_ets_add(port, qopt);
63 return lan966x_ets_del(port, qopt);
71 static int lan966x_tc_block_cb(enum tc_setup_type type, void *type_data,
72 void *cb_priv, bool ingress)
74 struct lan966x_port *port = cb_priv;
77 case TC_SETUP_CLSMATCHALL:
78 return lan966x_tc_matchall(port, type_data, ingress);
79 case TC_SETUP_CLSFLOWER:
80 return lan966x_tc_flower(port, type_data, ingress);
86 static int lan966x_tc_block_cb_ingress(enum tc_setup_type type,
87 void *type_data, void *cb_priv)
89 return lan966x_tc_block_cb(type, type_data, cb_priv, true);
92 static int lan966x_tc_block_cb_egress(enum tc_setup_type type,
93 void *type_data, void *cb_priv)
95 return lan966x_tc_block_cb(type, type_data, cb_priv, false);
98 static int lan966x_tc_setup_block(struct lan966x_port *port,
99 struct flow_block_offload *f)
104 if (f->binder_type == FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS) {
105 cb = lan966x_tc_block_cb_ingress;
106 port->tc.ingress_shared_block = f->block_shared;
108 } else if (f->binder_type == FLOW_BLOCK_BINDER_TYPE_CLSACT_EGRESS) {
109 cb = lan966x_tc_block_cb_egress;
115 return flow_block_cb_setup_simple(f, &lan966x_tc_block_cb_list,
116 cb, port, port, ingress);
119 int lan966x_tc_setup(struct net_device *dev, enum tc_setup_type type,
122 struct lan966x_port *port = netdev_priv(dev);
125 case TC_SETUP_QDISC_MQPRIO:
126 return lan966x_tc_setup_qdisc_mqprio(port, type_data);
127 case TC_SETUP_QDISC_TAPRIO:
128 return lan966x_tc_setup_qdisc_taprio(port, type_data);
129 case TC_SETUP_QDISC_TBF:
130 return lan966x_tc_setup_qdisc_tbf(port, type_data);
131 case TC_SETUP_QDISC_CBS:
132 return lan966x_tc_setup_qdisc_cbs(port, type_data);
133 case TC_SETUP_QDISC_ETS:
134 return lan966x_tc_setup_qdisc_ets(port, type_data);
136 return lan966x_tc_setup_block(port, type_data);