io_uring/cmd: add cmd lazy tw wake helper
[linux-block.git] / include / linux / if_macvlan.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
b863ceb7
PM
2#ifndef _LINUX_IF_MACVLAN_H
3#define _LINUX_IF_MACVLAN_H
4
fc0663d6 5#include <linux/if_link.h>
cdf3e274 6#include <linux/if_vlan.h>
fc0663d6
AB
7#include <linux/list.h>
8#include <linux/netdevice.h>
9#include <linux/netlink.h>
10#include <net/netlink.h>
bc66154e 11#include <linux/u64_stats_sync.h>
fc0663d6
AB
12
13struct macvlan_port;
1565c7c1 14
cd431e73
ED
15#define MACVLAN_MC_FILTER_BITS 8
16#define MACVLAN_MC_FILTER_SZ (1 << MACVLAN_MC_FILTER_BITS)
17
fc0663d6
AB
18struct 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;
1f4a5983 24 netdevice_tracker dev_tracker;
7d775f63 25 void *accel_priv;
cdf3e274 26 struct vlan_pcpu_stats __percpu *pcpu_stats;
cd431e73
ED
27
28 DECLARE_BITMAP(mc_filter, MACVLAN_MC_FILTER_SZ);
29
2be5c767 30 netdev_features_t set_features;
fc0663d6 31 enum macvlan_mode mode;
df8ef8f3 32 u16 flags;
5e54b3c1 33 unsigned int macaddr_count;
d4bff72c 34 u32 bc_queue_len_req;
688cea83 35#ifdef CONFIG_NET_POLL_CONTROLLER
36 struct netpoll *netpoll;
37#endif
fc0663d6
AB
38};
39
40static inline void macvlan_count_rx(const struct macvlan_dev *vlan,
41 unsigned int len, bool success,
42 bool multicast)
43{
fc0663d6 44 if (likely(success)) {
cdf3e274 45 struct vlan_pcpu_stats *pcpu_stats;
8ffab51b 46
dd4fa1da 47 pcpu_stats = get_cpu_ptr(vlan->pcpu_stats);
8ffab51b 48 u64_stats_update_begin(&pcpu_stats->syncp);
09cca53c
ED
49 u64_stats_inc(&pcpu_stats->rx_packets);
50 u64_stats_add(&pcpu_stats->rx_bytes, len);
fc0663d6 51 if (multicast)
09cca53c 52 u64_stats_inc(&pcpu_stats->rx_multicast);
8ffab51b 53 u64_stats_update_end(&pcpu_stats->syncp);
dd4fa1da 54 put_cpu_ptr(vlan->pcpu_stats);
fc0663d6 55 } else {
8ffab51b 56 this_cpu_inc(vlan->pcpu_stats->rx_errors);
fc0663d6
AB
57 }
58}
59
8a35747a
HX
60extern void macvlan_common_setup(struct net_device *dev);
61
fc0663d6 62extern int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
42ab19ee
DA
63 struct nlattr *tb[], struct nlattr *data[],
64 struct netlink_ext_ack *extack);
fc0663d6 65
fc0663d6
AB
66extern void macvlan_dellink(struct net_device *dev, struct list_head *head);
67
68extern int macvlan_link_register(struct rtnl_link_ops *ops);
69
be9eac48
MK
70#if IS_ENABLED(CONFIG_MACVLAN)
71static inline struct net_device *
72macvlan_dev_real_dev(const struct net_device *dev)
73{
74 struct macvlan_dev *macvlan = netdev_priv(dev);
75
76 return macvlan->lowerdev;
77}
78#else
79static inline struct net_device *
80macvlan_dev_real_dev(const struct net_device *dev)
81{
82 BUG();
83 return NULL;
84}
85#endif
86
7d775f63
AD
87static inline void *macvlan_accel_priv(struct net_device *dev)
88{
89 struct macvlan_dev *macvlan = netdev_priv(dev);
90
91 return macvlan->accel_priv;
92}
6cb1937d
AD
93
94static inline bool macvlan_supports_dest_filter(struct net_device *dev)
95{
96 struct macvlan_dev *macvlan = netdev_priv(dev);
97
98 return macvlan->mode == MACVLAN_MODE_PRIVATE ||
99 macvlan->mode == MACVLAN_MODE_VEPA ||
100 macvlan->mode == MACVLAN_MODE_BRIDGE;
101}
53cd4d8e
AD
102
103static inline int macvlan_release_l2fw_offload(struct net_device *dev)
104{
105 struct macvlan_dev *macvlan = netdev_priv(dev);
106
107 macvlan->accel_priv = NULL;
108 return dev_uc_add(macvlan->lowerdev, dev->dev_addr);
109}
b863ceb7 110#endif /* _LINUX_IF_MACVLAN_H */