Lines Matching refs:ns

41 	struct netdevsim *ns;  member
87 static bool nsim_xdp_offload_active(struct netdevsim *ns) in nsim_xdp_offload_active() argument
89 return ns->xdp_hw.prog; in nsim_xdp_offload_active()
104 nsim_bpf_offload(struct netdevsim *ns, struct bpf_prog *prog, bool oldprog) in nsim_bpf_offload() argument
106 nsim_prog_set_loaded(ns->bpf_offloaded, false); in nsim_bpf_offload()
108 WARN(!!ns->bpf_offloaded != oldprog, in nsim_bpf_offload()
111 ns->bpf_offloaded = prog; in nsim_bpf_offload()
112 ns->bpf_offloaded_id = prog ? prog->aux->id : 0; in nsim_bpf_offload()
123 struct netdevsim *ns = cb_priv; in nsim_bpf_setup_tc_block_cb() local
132 if (!tc_cls_can_offload_and_chain0(ns->netdev, &cls_bpf->common)) in nsim_bpf_setup_tc_block_cb()
141 if (!ns->bpf_tc_accept) { in nsim_bpf_setup_tc_block_cb()
147 if (prog && !prog->aux->offload && !ns->bpf_tc_non_bound_accept) { in nsim_bpf_setup_tc_block_cb()
159 if (ns->bpf_offloaded != oldprog) { in nsim_bpf_setup_tc_block_cb()
163 if (ns->bpf_offloaded) { in nsim_bpf_setup_tc_block_cb()
170 return nsim_bpf_offload(ns, cls_bpf->prog, oldprog); in nsim_bpf_setup_tc_block_cb()
173 int nsim_bpf_disable_tc(struct netdevsim *ns) in nsim_bpf_disable_tc() argument
175 if (ns->bpf_offloaded && !nsim_xdp_offload_active(ns)) in nsim_bpf_disable_tc()
180 static int nsim_xdp_offload_prog(struct netdevsim *ns, struct netdev_bpf *bpf) in nsim_xdp_offload_prog() argument
182 if (!nsim_xdp_offload_active(ns) && !bpf->prog) in nsim_xdp_offload_prog()
184 if (!nsim_xdp_offload_active(ns) && bpf->prog && ns->bpf_offloaded) { in nsim_xdp_offload_prog()
189 return nsim_bpf_offload(ns, bpf->prog, nsim_xdp_offload_active(ns)); in nsim_xdp_offload_prog()
193 nsim_xdp_set_prog(struct netdevsim *ns, struct netdev_bpf *bpf, in nsim_xdp_set_prog() argument
198 if (bpf->command == XDP_SETUP_PROG && !ns->bpf_xdpdrv_accept) { in nsim_xdp_set_prog()
202 if (bpf->command == XDP_SETUP_PROG_HW && !ns->bpf_xdpoffload_accept) { in nsim_xdp_set_prog()
208 err = nsim_xdp_offload_prog(ns, bpf); in nsim_xdp_set_prog()
293 static int nsim_setup_prog_checks(struct netdevsim *ns, struct netdev_bpf *bpf) in nsim_setup_prog_checks() argument
299 if (ns->netdev->mtu > NSIM_XDP_MAX_MTU) { in nsim_setup_prog_checks()
307 nsim_setup_prog_hw_checks(struct netdevsim *ns, struct netdev_bpf *bpf) in nsim_setup_prog_hw_checks() argument
484 nsim_bpf_map_alloc(struct netdevsim *ns, struct bpf_offloaded_map *offmap) in nsim_bpf_map_alloc() argument
502 nmap->ns = ns; in nsim_bpf_map_alloc()
520 list_add_tail(&nmap->l, &ns->nsim_dev->bpf_bound_maps); in nsim_bpf_map_alloc()
549 struct netdevsim *ns = netdev_priv(dev); in nsim_bpf() local
556 err = nsim_setup_prog_checks(ns, bpf); in nsim_bpf()
560 return nsim_xdp_set_prog(ns, bpf, &ns->xdp); in nsim_bpf()
562 err = nsim_setup_prog_hw_checks(ns, bpf); in nsim_bpf()
566 return nsim_xdp_set_prog(ns, bpf, &ns->xdp_hw); in nsim_bpf()
568 if (!ns->bpf_map_accept) in nsim_bpf()
571 return nsim_bpf_map_alloc(ns, bpf->offmap); in nsim_bpf()
615 int nsim_bpf_init(struct netdevsim *ns) in nsim_bpf_init() argument
617 struct dentry *ddir = ns->nsim_dev_port->ddir; in nsim_bpf_init()
620 err = bpf_offload_dev_netdev_register(ns->nsim_dev->bpf_dev, in nsim_bpf_init()
621 ns->netdev); in nsim_bpf_init()
626 &ns->bpf_offloaded_id); in nsim_bpf_init()
628 ns->bpf_tc_accept = true; in nsim_bpf_init()
630 &ns->bpf_tc_accept); in nsim_bpf_init()
632 &ns->bpf_tc_non_bound_accept); in nsim_bpf_init()
633 ns->bpf_xdpdrv_accept = true; in nsim_bpf_init()
635 &ns->bpf_xdpdrv_accept); in nsim_bpf_init()
636 ns->bpf_xdpoffload_accept = true; in nsim_bpf_init()
638 &ns->bpf_xdpoffload_accept); in nsim_bpf_init()
640 ns->bpf_map_accept = true; in nsim_bpf_init()
642 &ns->bpf_map_accept); in nsim_bpf_init()
647 void nsim_bpf_uninit(struct netdevsim *ns) in nsim_bpf_uninit() argument
649 WARN_ON(ns->xdp.prog); in nsim_bpf_uninit()
650 WARN_ON(ns->xdp_hw.prog); in nsim_bpf_uninit()
651 WARN_ON(ns->bpf_offloaded); in nsim_bpf_uninit()
652 bpf_offload_dev_netdev_unregister(ns->nsim_dev->bpf_dev, ns->netdev); in nsim_bpf_uninit()