1 // SPDX-License-Identifier: GPL-2.0 2 3 #include <linux/netdevice.h> 4 #include <net/pkt_sched.h> 5 #include <net/pkt_cls.h> 6 7 #include "netdevsim.h" 8 9 static int 10 nsim_setup_tc_block_cb(enum tc_setup_type type, void *type_data, void *cb_priv) 11 { 12 return nsim_bpf_setup_tc_block_cb(type, type_data, cb_priv); 13 } 14 15 static void nsim_taprio_stats(struct tc_taprio_qopt_stats *stats) 16 { 17 stats->window_drops = 0; 18 stats->tx_overruns = 0; 19 } 20 21 static int nsim_setup_tc_taprio(struct net_device *dev, 22 struct tc_taprio_qopt_offload *offload) 23 { 24 int err = 0; 25 26 switch (offload->cmd) { 27 case TAPRIO_CMD_REPLACE: 28 case TAPRIO_CMD_DESTROY: 29 break; 30 case TAPRIO_CMD_STATS: 31 nsim_taprio_stats(&offload->stats); 32 break; 33 default: 34 err = -EOPNOTSUPP; 35 } 36 37 return err; 38 } 39 40 static int nsim_setup_tc_ets(struct net_device *dev, 41 struct tc_ets_qopt_offload *offload) 42 { 43 int err = 0; 44 45 switch (offload->command) { 46 case TC_ETS_REPLACE: 47 case TC_ETS_DESTROY: 48 break; 49 case TC_ETS_STATS: 50 _bstats_update(offload->stats.bstats, 0, 0); 51 break; 52 default: 53 err = -EOPNOTSUPP; 54 } 55 56 return err; 57 } 58 59 static LIST_HEAD(nsim_block_cb_list); 60 61 int 62 nsim_setup_tc(struct net_device *dev, enum tc_setup_type type, void *type_data) 63 { 64 struct netdevsim *ns = netdev_priv(dev); 65 66 switch (type) { 67 case TC_SETUP_QDISC_TAPRIO: 68 return nsim_setup_tc_taprio(dev, type_data); 69 case TC_SETUP_QDISC_ETS: 70 return nsim_setup_tc_ets(dev, type_data); 71 case TC_SETUP_BLOCK: 72 return flow_block_cb_setup_simple(type_data, 73 &nsim_block_cb_list, 74 nsim_setup_tc_block_cb, 75 ns, ns, true); 76 default: 77 return -EOPNOTSUPP; 78 } 79 } 80