2 * Copyright (C) 2017 Netronome Systems, Inc.
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
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.
16 #include <linux/device.h>
17 #include <linux/kernel.h>
18 #include <linux/list.h>
19 #include <linux/netdevice.h>
20 #include <linux/u64_stats_sync.h>
22 #define DRV_NAME "netdevsim"
24 #define NSIM_XDP_MAX_MTU 4000
26 #define NSIM_EA(extack, msg) NL_SET_ERR_MSG_MOD((extack), msg)
30 struct nsim_vf_config
;
33 struct net_device
*netdev
;
37 struct u64_stats_sync syncp
;
44 struct nsim_vf_config
*vfconfigs
;
46 struct bpf_prog
*bpf_offloaded
;
51 struct bpf_prog
*xdp_prog
;
56 u32 bpf_bind_verifier_delay
;
57 struct dentry
*ddir_bpf_bound_progs
;
58 struct list_head bpf_bound_progs
;
61 bool bpf_tc_non_bound_accept
;
62 bool bpf_xdpdrv_accept
;
63 bool bpf_xdpoffload_accept
;
66 struct list_head bpf_bound_maps
;
69 extern struct dentry
*nsim_ddir
;
71 #ifdef CONFIG_BPF_SYSCALL
72 int nsim_bpf_init(struct netdevsim
*ns
);
73 void nsim_bpf_uninit(struct netdevsim
*ns
);
74 int nsim_bpf(struct net_device
*dev
, struct netdev_bpf
*bpf
);
75 int nsim_bpf_disable_tc(struct netdevsim
*ns
);
76 int nsim_bpf_setup_tc_block_cb(enum tc_setup_type type
,
77 void *type_data
, void *cb_priv
);
79 static inline int nsim_bpf_init(struct netdevsim
*ns
)
84 static inline void nsim_bpf_uninit(struct netdevsim
*ns
)
88 static inline int nsim_bpf(struct net_device
*dev
, struct netdev_bpf
*bpf
)
90 return bpf
->command
== XDP_QUERY_PROG
? 0 : -EOPNOTSUPP
;
93 static inline int nsim_bpf_disable_tc(struct netdevsim
*ns
)
99 nsim_bpf_setup_tc_block_cb(enum tc_setup_type type
, void *type_data
,
106 static inline struct netdevsim
*to_nsim(struct device
*ptr
)
108 return container_of(ptr
, struct netdevsim
, dev
);