blob: ea081c10efb8b30f562dabf09c9eaec26ef2fc1e [file] [log] [blame]
Jakub Kicinski83c9e132017-12-01 15:08:58 -08001/*
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
Jakub Kicinski79579222017-12-01 15:09:01 -080016#include <linux/device.h>
Jakub Kicinski83c9e132017-12-01 15:08:58 -080017#include <linux/kernel.h>
Jakub Kicinski31d3ad82017-12-01 15:08:59 -080018#include <linux/list.h>
Jakub Kicinski83c9e132017-12-01 15:08:58 -080019#include <linux/netdevice.h>
20#include <linux/u64_stats_sync.h>
21
22#define DRV_NAME "netdevsim"
23
Jakub Kicinski31d3ad82017-12-01 15:08:59 -080024#define NSIM_XDP_MAX_MTU 4000
25
26#define NSIM_EA(extack, msg) NL_SET_ERR_MSG_MOD((extack), msg)
27
28struct bpf_prog;
29struct dentry;
Jakub Kicinski79579222017-12-01 15:09:01 -080030struct nsim_vf_config;
Jakub Kicinski31d3ad82017-12-01 15:08:59 -080031
Jakub Kicinski83c9e132017-12-01 15:08:58 -080032struct netdevsim {
Jakub Kicinski31d3ad82017-12-01 15:08:59 -080033 struct net_device *netdev;
34
Jakub Kicinski83c9e132017-12-01 15:08:58 -080035 u64 tx_packets;
36 u64 tx_bytes;
37 struct u64_stats_sync syncp;
Jakub Kicinski31d3ad82017-12-01 15:08:59 -080038
Jakub Kicinski79579222017-12-01 15:09:01 -080039 struct device dev;
40
Jakub Kicinski31d3ad82017-12-01 15:08:59 -080041 struct dentry *ddir;
42
Jakub Kicinski79579222017-12-01 15:09:01 -080043 unsigned int num_vfs;
44 struct nsim_vf_config *vfconfigs;
45
Jakub Kicinski31d3ad82017-12-01 15:08:59 -080046 struct bpf_prog *bpf_offloaded;
47 u32 bpf_offloaded_id;
48
49 u32 xdp_flags;
50 int xdp_prog_mode;
51 struct bpf_prog *xdp_prog;
52
53 u32 prog_id_gen;
54
55 bool bpf_bind_accept;
56 u32 bpf_bind_verifier_delay;
57 struct dentry *ddir_bpf_bound_progs;
58 struct list_head bpf_bound_progs;
59
60 bool bpf_tc_accept;
61 bool bpf_tc_non_bound_accept;
62 bool bpf_xdpdrv_accept;
63 bool bpf_xdpoffload_accept;
Jakub Kicinski395cacb2018-01-17 19:13:30 -080064
65 bool bpf_map_accept;
66 struct list_head bpf_bound_maps;
Jakub Kicinski83c9e132017-12-01 15:08:58 -080067};
Jakub Kicinski31d3ad82017-12-01 15:08:59 -080068
69extern struct dentry *nsim_ddir;
70
Jakub Kicinski7c5db7e2018-01-23 11:22:54 -080071#ifdef CONFIG_BPF_SYSCALL
Jakub Kicinski31d3ad82017-12-01 15:08:59 -080072int nsim_bpf_init(struct netdevsim *ns);
73void nsim_bpf_uninit(struct netdevsim *ns);
74int nsim_bpf(struct net_device *dev, struct netdev_bpf *bpf);
75int nsim_bpf_disable_tc(struct netdevsim *ns);
76int nsim_bpf_setup_tc_block_cb(enum tc_setup_type type,
77 void *type_data, void *cb_priv);
Jakub Kicinski7c5db7e2018-01-23 11:22:54 -080078#else
79static inline int nsim_bpf_init(struct netdevsim *ns)
80{
81 return 0;
82}
83
84static inline void nsim_bpf_uninit(struct netdevsim *ns)
85{
86}
87
88static inline int nsim_bpf(struct net_device *dev, struct netdev_bpf *bpf)
89{
90 return bpf->command == XDP_QUERY_PROG ? 0 : -EOPNOTSUPP;
91}
92
93static inline int nsim_bpf_disable_tc(struct netdevsim *ns)
94{
95 return 0;
96}
97
98static inline int
99nsim_bpf_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
100 void *cb_priv)
101{
102 return -EOPNOTSUPP;
103}
104#endif
Jakub Kicinski79579222017-12-01 15:09:01 -0800105
106static inline struct netdevsim *to_nsim(struct device *ptr)
107{
108 return container_of(ptr, struct netdevsim, dev);
109}