^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * Copyright (C) 2017 Netronome Systems, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * This software is licensed under the GNU General License Version 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * June 1991 as shown in the file COPYING in the top-level directory of this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * source tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/u64_stats_sync.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <net/devlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <net/udp_tunnel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <net/xdp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define DRV_NAME "netdevsim"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define NSIM_XDP_MAX_MTU 4000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define NSIM_EA(extack, msg) NL_SET_ERR_MSG_MOD((extack), msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define NSIM_IPSEC_MAX_SA_COUNT 33
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define NSIM_IPSEC_VALID BIT(31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define NSIM_UDP_TUNNEL_N_PORTS 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) struct nsim_sa {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) struct xfrm_state *xs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) __be32 ipaddr[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) u32 key[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) u32 salt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) bool used;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) bool crypt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) bool rx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct nsim_ipsec {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct nsim_sa sa[NSIM_IPSEC_MAX_SA_COUNT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct dentry *pfile;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) u32 count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) u32 tx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) u32 ok;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct nsim_ethtool {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) bool rx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) bool tx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) bool report_stats_rx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) bool report_stats_tx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) struct netdevsim {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) struct net_device *netdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) struct nsim_dev *nsim_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct nsim_dev_port *nsim_dev_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) u64 tx_packets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) u64 tx_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) struct u64_stats_sync syncp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct nsim_bus_dev *nsim_bus_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) struct bpf_prog *bpf_offloaded;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) u32 bpf_offloaded_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) struct xdp_attachment_info xdp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) struct xdp_attachment_info xdp_hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) bool bpf_tc_accept;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) bool bpf_tc_non_bound_accept;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) bool bpf_xdpdrv_accept;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) bool bpf_xdpoffload_accept;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) bool bpf_map_accept;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) struct nsim_ipsec ipsec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) u32 inject_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) u32 sleep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) u32 __ports[2][NSIM_UDP_TUNNEL_N_PORTS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) u32 (*ports)[NSIM_UDP_TUNNEL_N_PORTS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) struct debugfs_u32_array dfs_ports[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) } udp_ports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) struct nsim_ethtool ethtool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) struct netdevsim *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) nsim_create(struct nsim_dev *nsim_dev, struct nsim_dev_port *nsim_dev_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) void nsim_destroy(struct netdevsim *ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) void nsim_ethtool_init(struct netdevsim *ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) void nsim_udp_tunnels_debugfs_create(struct nsim_dev *nsim_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) int nsim_udp_tunnels_info_create(struct nsim_dev *nsim_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) struct net_device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) void nsim_udp_tunnels_info_destroy(struct net_device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) #ifdef CONFIG_BPF_SYSCALL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) int nsim_bpf_dev_init(struct nsim_dev *nsim_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) void nsim_bpf_dev_exit(struct nsim_dev *nsim_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) int nsim_bpf_init(struct netdevsim *ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) void nsim_bpf_uninit(struct netdevsim *ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) int nsim_bpf(struct net_device *dev, struct netdev_bpf *bpf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) int nsim_bpf_disable_tc(struct netdevsim *ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) int nsim_bpf_setup_tc_block_cb(enum tc_setup_type type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) void *type_data, void *cb_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) static inline int nsim_bpf_dev_init(struct nsim_dev *nsim_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static inline void nsim_bpf_dev_exit(struct nsim_dev *nsim_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) static inline int nsim_bpf_init(struct netdevsim *ns)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) static inline void nsim_bpf_uninit(struct netdevsim *ns)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) static inline int nsim_bpf(struct net_device *dev, struct netdev_bpf *bpf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) static inline int nsim_bpf_disable_tc(struct netdevsim *ns)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) nsim_bpf_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) void *cb_priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) enum nsim_resource_id {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) NSIM_RESOURCE_NONE, /* DEVLINK_RESOURCE_ID_PARENT_TOP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) NSIM_RESOURCE_IPV4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) NSIM_RESOURCE_IPV4_FIB,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) NSIM_RESOURCE_IPV4_FIB_RULES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) NSIM_RESOURCE_IPV6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) NSIM_RESOURCE_IPV6_FIB,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) NSIM_RESOURCE_IPV6_FIB_RULES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) struct nsim_dev_health {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) struct devlink_health_reporter *empty_reporter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) struct devlink_health_reporter *dummy_reporter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) struct dentry *ddir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) char *recovered_break_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) u32 binary_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) bool fail_recover;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) int nsim_dev_health_init(struct nsim_dev *nsim_dev, struct devlink *devlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) void nsim_dev_health_exit(struct nsim_dev *nsim_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) struct nsim_dev_port {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) struct devlink_port devlink_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) unsigned int port_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) struct dentry *ddir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) struct netdevsim *ns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) struct nsim_dev {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) struct nsim_bus_dev *nsim_bus_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) struct nsim_fib_data *fib_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) struct nsim_trap_data *trap_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) struct dentry *ddir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) struct dentry *ports_ddir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) struct dentry *take_snapshot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) struct bpf_offload_dev *bpf_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) bool bpf_bind_accept;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) bool bpf_bind_verifier_accept;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) u32 bpf_bind_verifier_delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) struct dentry *ddir_bpf_bound_progs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) u32 prog_id_gen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) struct list_head bpf_bound_progs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) struct list_head bpf_bound_maps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) struct netdev_phys_item_id switch_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) struct list_head port_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) struct mutex port_list_lock; /* protects port list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) bool fw_update_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) u32 fw_update_overwrite_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) u32 max_macs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) bool test1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) bool dont_allow_reload;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) bool fail_reload;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) struct devlink_region *dummy_region;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) struct nsim_dev_health health;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) struct flow_action_cookie *fa_cookie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) spinlock_t fa_cookie_lock; /* protects fa_cookie */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) bool fail_trap_group_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) bool fail_trap_policer_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) bool fail_trap_policer_counter_get;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) struct udp_tunnel_nic_shared utn_shared;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) u32 __ports[2][NSIM_UDP_TUNNEL_N_PORTS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) bool sync_all;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) bool open_only;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) bool ipv4_only;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) bool shared;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) bool static_iana_vxlan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) u32 sleep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) } udp_ports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) static inline struct net *nsim_dev_net(struct nsim_dev *nsim_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) return devlink_net(priv_to_devlink(nsim_dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) int nsim_dev_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) void nsim_dev_exit(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) int nsim_dev_probe(struct nsim_bus_dev *nsim_bus_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) void nsim_dev_remove(struct nsim_bus_dev *nsim_bus_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) int nsim_dev_port_add(struct nsim_bus_dev *nsim_bus_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) unsigned int port_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) int nsim_dev_port_del(struct nsim_bus_dev *nsim_bus_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) unsigned int port_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) struct nsim_fib_data *nsim_fib_create(struct devlink *devlink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) struct netlink_ext_ack *extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) void nsim_fib_destroy(struct devlink *devlink, struct nsim_fib_data *fib_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) u64 nsim_fib_get_val(struct nsim_fib_data *fib_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) enum nsim_resource_id res_id, bool max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) #if IS_ENABLED(CONFIG_XFRM_OFFLOAD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) void nsim_ipsec_init(struct netdevsim *ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) void nsim_ipsec_teardown(struct netdevsim *ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) bool nsim_ipsec_tx(struct netdevsim *ns, struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) static inline void nsim_ipsec_init(struct netdevsim *ns)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) static inline void nsim_ipsec_teardown(struct netdevsim *ns)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) static inline bool nsim_ipsec_tx(struct netdevsim *ns, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) struct nsim_vf_config {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) int link_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) u16 min_tx_rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) u16 max_tx_rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) u16 vlan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) __be16 vlan_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) u16 qos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) u8 vf_mac[ETH_ALEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) bool spoofchk_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) bool trusted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) bool rss_query_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) struct nsim_bus_dev {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) struct device dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) unsigned int port_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) struct net *initial_net; /* Purpose of this is to carry net pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) * during the probe time only.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) unsigned int num_vfs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) struct nsim_vf_config *vfconfigs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) /* Lock for devlink->reload_enabled in netdevsim module */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) struct mutex nsim_bus_reload_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) bool init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) int nsim_bus_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) void nsim_bus_exit(void);