]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - include/linux/if_macvlan.h
Merge tag 'staging-5.13-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh...
[mirror_ubuntu-jammy-kernel.git] / include / linux / if_macvlan.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_IF_MACVLAN_H
3 #define _LINUX_IF_MACVLAN_H
4
5 #include <linux/if_link.h>
6 #include <linux/if_vlan.h>
7 #include <linux/list.h>
8 #include <linux/netdevice.h>
9 #include <linux/netlink.h>
10 #include <net/netlink.h>
11 #include <linux/u64_stats_sync.h>
12
13 struct macvlan_port;
14
15 #define MACVLAN_MC_FILTER_BITS 8
16 #define MACVLAN_MC_FILTER_SZ (1 << MACVLAN_MC_FILTER_BITS)
17
18 struct macvlan_dev {
19 struct net_device *dev;
20 struct list_head list;
21 struct hlist_node hlist;
22 struct macvlan_port *port;
23 struct net_device *lowerdev;
24 void *accel_priv;
25 struct vlan_pcpu_stats __percpu *pcpu_stats;
26
27 DECLARE_BITMAP(mc_filter, MACVLAN_MC_FILTER_SZ);
28
29 netdev_features_t set_features;
30 enum macvlan_mode mode;
31 u16 flags;
32 unsigned int macaddr_count;
33 u32 bc_queue_len_req;
34 #ifdef CONFIG_NET_POLL_CONTROLLER
35 struct netpoll *netpoll;
36 #endif
37 };
38
39 static inline void macvlan_count_rx(const struct macvlan_dev *vlan,
40 unsigned int len, bool success,
41 bool multicast)
42 {
43 if (likely(success)) {
44 struct vlan_pcpu_stats *pcpu_stats;
45
46 pcpu_stats = get_cpu_ptr(vlan->pcpu_stats);
47 u64_stats_update_begin(&pcpu_stats->syncp);
48 pcpu_stats->rx_packets++;
49 pcpu_stats->rx_bytes += len;
50 if (multicast)
51 pcpu_stats->rx_multicast++;
52 u64_stats_update_end(&pcpu_stats->syncp);
53 put_cpu_ptr(vlan->pcpu_stats);
54 } else {
55 this_cpu_inc(vlan->pcpu_stats->rx_errors);
56 }
57 }
58
59 extern void macvlan_common_setup(struct net_device *dev);
60
61 extern int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
62 struct nlattr *tb[], struct nlattr *data[],
63 struct netlink_ext_ack *extack);
64
65 extern void macvlan_dellink(struct net_device *dev, struct list_head *head);
66
67 extern int macvlan_link_register(struct rtnl_link_ops *ops);
68
69 #if IS_ENABLED(CONFIG_MACVLAN)
70 static inline struct net_device *
71 macvlan_dev_real_dev(const struct net_device *dev)
72 {
73 struct macvlan_dev *macvlan = netdev_priv(dev);
74
75 return macvlan->lowerdev;
76 }
77 #else
78 static inline struct net_device *
79 macvlan_dev_real_dev(const struct net_device *dev)
80 {
81 BUG();
82 return NULL;
83 }
84 #endif
85
86 static inline void *macvlan_accel_priv(struct net_device *dev)
87 {
88 struct macvlan_dev *macvlan = netdev_priv(dev);
89
90 return macvlan->accel_priv;
91 }
92
93 static inline bool macvlan_supports_dest_filter(struct net_device *dev)
94 {
95 struct macvlan_dev *macvlan = netdev_priv(dev);
96
97 return macvlan->mode == MACVLAN_MODE_PRIVATE ||
98 macvlan->mode == MACVLAN_MODE_VEPA ||
99 macvlan->mode == MACVLAN_MODE_BRIDGE;
100 }
101
102 static inline int macvlan_release_l2fw_offload(struct net_device *dev)
103 {
104 struct macvlan_dev *macvlan = netdev_priv(dev);
105
106 macvlan->accel_priv = NULL;
107 return dev_uc_add(macvlan->lowerdev, dev->dev_addr);
108 }
109 #endif /* _LINUX_IF_MACVLAN_H */