]> bbs.cooldavid.org Git - net-next-2.6.git/blame - include/linux/if_macvlan.h
macvlan: lockless tx path
[net-next-2.6.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
501c774c
AB
11#if defined(CONFIG_MACVTAP) || defined(CONFIG_MACVTAP_MODULE)
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 */
53#define MAX_MACVTAP_QUEUES (NR_CPUS < 16 ? NR_CPUS : 16)
54
fc0663d6
AB
55struct macvlan_dev {
56 struct net_device *dev;
57 struct list_head list;
58 struct hlist_node hlist;
59 struct macvlan_port *port;
60 struct net_device *lowerdev;
8ffab51b 61 struct macvlan_pcpu_stats __percpu *pcpu_stats;
fc0663d6
AB
62 enum macvlan_mode mode;
63 int (*receive)(struct sk_buff *skb);
64 int (*forward)(struct net_device *dev, struct sk_buff *skb);
1565c7c1
KK
65 struct macvtap_queue *taps[MAX_MACVTAP_QUEUES];
66 int numvtaps;
fc0663d6
AB
67};
68
69static inline void macvlan_count_rx(const struct macvlan_dev *vlan,
70 unsigned int len, bool success,
71 bool multicast)
72{
fc0663d6 73 if (likely(success)) {
8ffab51b
ED
74 struct macvlan_pcpu_stats *pcpu_stats;
75
76 pcpu_stats = this_cpu_ptr(vlan->pcpu_stats);
77 u64_stats_update_begin(&pcpu_stats->syncp);
78 pcpu_stats->rx_packets++;
79 pcpu_stats->rx_bytes += len;
fc0663d6 80 if (multicast)
8ffab51b
ED
81 pcpu_stats->rx_multicast++;
82 u64_stats_update_end(&pcpu_stats->syncp);
fc0663d6 83 } else {
8ffab51b 84 this_cpu_inc(vlan->pcpu_stats->rx_errors);
fc0663d6
AB
85 }
86}
87
8a35747a
HX
88extern void macvlan_common_setup(struct net_device *dev);
89
fc0663d6
AB
90extern int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
91 struct nlattr *tb[], struct nlattr *data[],
92 int (*receive)(struct sk_buff *skb),
93 int (*forward)(struct net_device *dev,
94 struct sk_buff *skb));
95
96extern void macvlan_count_rx(const struct macvlan_dev *vlan,
97 unsigned int len, bool success,
98 bool multicast);
99
100extern void macvlan_dellink(struct net_device *dev, struct list_head *head);
101
102extern int macvlan_link_register(struct rtnl_link_ops *ops);
103
104extern netdev_tx_t macvlan_start_xmit(struct sk_buff *skb,
105 struct net_device *dev);
106
b863ceb7 107#endif /* _LINUX_IF_MACVLAN_H */