netdevsim.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright (C) 2017 Netronome Systems, Inc.
  3. *
  4. * This software is licensed under the GNU General License Version 2,
  5. * June 1991 as shown in the file COPYING in the top-level directory of this
  6. * source tree.
  7. *
  8. * THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS"
  9. * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
  10. * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  11. * FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE
  12. * OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME
  13. * THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
  14. */
  15. #include <linux/device.h>
  16. #include <linux/kernel.h>
  17. #include <linux/list.h>
  18. #include <linux/netdevice.h>
  19. #include <linux/u64_stats_sync.h>
  20. #define DRV_NAME "netdevsim"
  21. #define NSIM_XDP_MAX_MTU 4000
  22. #define NSIM_EA(extack, msg) NL_SET_ERR_MSG_MOD((extack), msg)
  23. struct bpf_prog;
  24. struct dentry;
  25. struct nsim_vf_config;
  26. struct netdevsim {
  27. struct net_device *netdev;
  28. u64 tx_packets;
  29. u64 tx_bytes;
  30. struct u64_stats_sync syncp;
  31. struct device dev;
  32. struct dentry *ddir;
  33. unsigned int num_vfs;
  34. struct nsim_vf_config *vfconfigs;
  35. struct bpf_prog *bpf_offloaded;
  36. u32 bpf_offloaded_id;
  37. u32 xdp_flags;
  38. int xdp_prog_mode;
  39. struct bpf_prog *xdp_prog;
  40. u32 prog_id_gen;
  41. bool bpf_bind_accept;
  42. u32 bpf_bind_verifier_delay;
  43. struct dentry *ddir_bpf_bound_progs;
  44. struct list_head bpf_bound_progs;
  45. bool bpf_tc_accept;
  46. bool bpf_tc_non_bound_accept;
  47. bool bpf_xdpdrv_accept;
  48. bool bpf_xdpoffload_accept;
  49. };
  50. extern struct dentry *nsim_ddir;
  51. int nsim_bpf_init(struct netdevsim *ns);
  52. void nsim_bpf_uninit(struct netdevsim *ns);
  53. int nsim_bpf(struct net_device *dev, struct netdev_bpf *bpf);
  54. int nsim_bpf_disable_tc(struct netdevsim *ns);
  55. int nsim_bpf_setup_tc_block_cb(enum tc_setup_type type,
  56. void *type_data, void *cb_priv);
  57. static inline struct netdevsim *to_nsim(struct device *ptr)
  58. {
  59. return container_of(ptr, struct netdevsim, dev);
  60. }