macvlan: make start_xmit local
[deliverable/linux.git] / include / linux / if_macvlan.h
CommitLineData
b863ceb7
PM
1#ifndef _LINUX_IF_MACVLAN_H
2#define _LINUX_IF_MACVLAN_H
3
fc0663d6
AB
4#include <linux/if_link.h>
5#include <linux/list.h>
6#include <linux/netdevice.h>
7#include <linux/netlink.h>
8#include <net/netlink.h>
bc66154e 9#include <linux/u64_stats_sync.h>
fc0663d6 10
1d2f41ed 11#if IS_ENABLED(CONFIG_MACVTAP)
501c774c
AB
12struct socket *macvtap_get_socket(struct file *);
13#else
14#include <linux/err.h>
15#include <linux/errno.h>
16struct file;
17struct socket;
18static inline struct socket *macvtap_get_socket(struct file *f)
19{
20 return ERR_PTR(-EINVAL);
21}
22#endif /* CONFIG_MACVTAP */
23
fc0663d6
AB
24struct macvlan_port;
25struct macvtap_queue;
26
27/**
8ffab51b 28 * struct macvlan_pcpu_stats - MACVLAN percpu stats
fc0663d6
AB
29 * @rx_packets: number of received packets
30 * @rx_bytes: number of received bytes
bc66154e 31 * @rx_multicast: number of received multicast packets
8ffab51b
ED
32 * @tx_packets: number of transmitted packets
33 * @tx_bytes: number of transmitted bytes
bc66154e 34 * @syncp: synchronization point for 64bit counters
8ffab51b
ED
35 * @rx_errors: number of rx errors
36 * @tx_dropped: number of tx dropped packets
fc0663d6 37 */
8ffab51b 38struct macvlan_pcpu_stats {
bc66154e
ED
39 u64 rx_packets;
40 u64 rx_bytes;
41 u64 rx_multicast;
8ffab51b
ED
42 u64 tx_packets;
43 u64 tx_bytes;
bc66154e 44 struct u64_stats_sync syncp;
8ffab51b
ED
45 u32 rx_errors;
46 u32 tx_dropped;
fc0663d6
AB
47};
48
1565c7c1
KK
49/*
50 * Maximum times a macvtap device can be opened. This can be used to
51 * configure the number of receive queue, e.g. for multiqueue virtio.
52 */
f0afce01 53#define MAX_MACVTAP_QUEUES 16
1565c7c1 54
cd431e73
ED
55#define MACVLAN_MC_FILTER_BITS 8
56#define MACVLAN_MC_FILTER_SZ (1 << MACVLAN_MC_FILTER_BITS)
57
fc0663d6
AB
58struct macvlan_dev {
59 struct net_device *dev;
60 struct list_head list;
61 struct hlist_node hlist;
62 struct macvlan_port *port;
63 struct net_device *lowerdev;
a6cc0cfa 64 void *fwd_priv;
8ffab51b 65 struct macvlan_pcpu_stats __percpu *pcpu_stats;
cd431e73
ED
66
67 DECLARE_BITMAP(mc_filter, MACVLAN_MC_FILTER_SZ);
68
2be5c767 69 netdev_features_t set_features;
fc0663d6 70 enum macvlan_mode mode;
df8ef8f3 71 u16 flags;
815f236d 72 /* This array tracks active taps. */
d9a90a31 73 struct macvtap_queue __rcu *taps[MAX_MACVTAP_QUEUES];
815f236d
JW
74 /* This list tracks all taps (both enabled and disabled) */
75 struct list_head queue_list;
1565c7c1 76 int numvtaps;
815f236d 77 int numqueues;
2be5c767 78 netdev_features_t tap_features;
e09eff7f 79 int minor;
fc0663d6
AB
80};
81
82static inline void macvlan_count_rx(const struct macvlan_dev *vlan,
83 unsigned int len, bool success,
84 bool multicast)
85{
fc0663d6 86 if (likely(success)) {
8ffab51b
ED
87 struct macvlan_pcpu_stats *pcpu_stats;
88
89 pcpu_stats = this_cpu_ptr(vlan->pcpu_stats);
90 u64_stats_update_begin(&pcpu_stats->syncp);
91 pcpu_stats->rx_packets++;
92 pcpu_stats->rx_bytes += len;
fc0663d6 93 if (multicast)
8ffab51b
ED
94 pcpu_stats->rx_multicast++;
95 u64_stats_update_end(&pcpu_stats->syncp);
fc0663d6 96 } else {
8ffab51b 97 this_cpu_inc(vlan->pcpu_stats->rx_errors);
fc0663d6
AB
98 }
99}
100
8a35747a
HX
101extern void macvlan_common_setup(struct net_device *dev);
102
fc0663d6 103extern int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
2f6a1b66 104 struct nlattr *tb[], struct nlattr *data[]);
fc0663d6
AB
105
106extern void macvlan_count_rx(const struct macvlan_dev *vlan,
107 unsigned int len, bool success,
108 bool multicast);
109
110extern void macvlan_dellink(struct net_device *dev, struct list_head *head);
111
112extern int macvlan_link_register(struct rtnl_link_ops *ops);
113
be9eac48
MK
114#if IS_ENABLED(CONFIG_MACVLAN)
115static inline struct net_device *
116macvlan_dev_real_dev(const struct net_device *dev)
117{
118 struct macvlan_dev *macvlan = netdev_priv(dev);
119
120 return macvlan->lowerdev;
121}
122#else
123static inline struct net_device *
124macvlan_dev_real_dev(const struct net_device *dev)
125{
126 BUG();
127 return NULL;
128}
129#endif
130
b863ceb7 131#endif /* _LINUX_IF_MACVLAN_H */
This page took 0.722519 seconds and 5 git commands to generate.