Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Patrick McHardy | b863ceb | 2007-07-14 18:55:06 -0700 | [diff] [blame] | 2 | #ifndef _LINUX_IF_MACVLAN_H |
| 3 | #define _LINUX_IF_MACVLAN_H |
| 4 | |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 5 | #include <linux/if_link.h> |
Li RongQing | cdf3e27 | 2014-01-04 14:22:34 +0800 | [diff] [blame] | 6 | #include <linux/if_vlan.h> |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 7 | #include <linux/list.h> |
| 8 | #include <linux/netdevice.h> |
| 9 | #include <linux/netlink.h> |
| 10 | #include <net/netlink.h> |
Eric Dumazet | bc66154 | 2010-06-24 00:54:21 +0000 | [diff] [blame] | 11 | #include <linux/u64_stats_sync.h> |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 12 | |
| 13 | struct macvlan_port; |
Krishna Kumar | 1565c7c | 2010-08-04 06:15:59 +0000 | [diff] [blame] | 14 | |
Eric Dumazet | cd431e7 | 2013-02-05 20:22:50 +0000 | [diff] [blame] | 15 | #define MACVLAN_MC_FILTER_BITS 8 |
| 16 | #define MACVLAN_MC_FILTER_SZ (1 << MACVLAN_MC_FILTER_BITS) |
| 17 | |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 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; |
Alexander Duyck | 7d775f6 | 2018-04-03 17:16:03 -0400 | [diff] [blame] | 24 | void *accel_priv; |
Li RongQing | cdf3e27 | 2014-01-04 14:22:34 +0800 | [diff] [blame] | 25 | struct vlan_pcpu_stats __percpu *pcpu_stats; |
Eric Dumazet | cd431e7 | 2013-02-05 20:22:50 +0000 | [diff] [blame] | 26 | |
| 27 | DECLARE_BITMAP(mc_filter, MACVLAN_MC_FILTER_SZ); |
| 28 | |
Vlad Yasevich | 2be5c76 | 2013-06-25 16:04:21 -0400 | [diff] [blame] | 29 | netdev_features_t set_features; |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 30 | enum macvlan_mode mode; |
John Fastabend | df8ef8f | 2012-04-15 06:44:37 +0000 | [diff] [blame] | 31 | u16 flags; |
Vlad Yasevich | c674ac3 | 2014-05-16 17:04:56 -0400 | [diff] [blame] | 32 | int nest_level; |
Girish Moodalbail | 5e54b3c | 2017-12-08 06:03:26 -0800 | [diff] [blame] | 33 | unsigned int macaddr_count; |
dingtianhong | 688cea8 | 2014-05-30 16:00:56 +0800 | [diff] [blame] | 34 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 35 | struct netpoll *netpoll; |
| 36 | #endif |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | static inline void macvlan_count_rx(const struct macvlan_dev *vlan, |
| 40 | unsigned int len, bool success, |
| 41 | bool multicast) |
| 42 | { |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 43 | if (likely(success)) { |
Li RongQing | cdf3e27 | 2014-01-04 14:22:34 +0800 | [diff] [blame] | 44 | struct vlan_pcpu_stats *pcpu_stats; |
Eric Dumazet | 8ffab51 | 2010-11-10 21:14:04 +0000 | [diff] [blame] | 45 | |
| 46 | pcpu_stats = this_cpu_ptr(vlan->pcpu_stats); |
| 47 | u64_stats_update_begin(&pcpu_stats->syncp); |
| 48 | pcpu_stats->rx_packets++; |
| 49 | pcpu_stats->rx_bytes += len; |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 50 | if (multicast) |
Eric Dumazet | 8ffab51 | 2010-11-10 21:14:04 +0000 | [diff] [blame] | 51 | pcpu_stats->rx_multicast++; |
| 52 | u64_stats_update_end(&pcpu_stats->syncp); |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 53 | } else { |
Eric Dumazet | 8ffab51 | 2010-11-10 21:14:04 +0000 | [diff] [blame] | 54 | this_cpu_inc(vlan->pcpu_stats->rx_errors); |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 55 | } |
| 56 | } |
| 57 | |
Herbert Xu | 8a35747 | 2010-07-21 21:44:31 +0000 | [diff] [blame] | 58 | extern void macvlan_common_setup(struct net_device *dev); |
| 59 | |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 60 | extern int macvlan_common_newlink(struct net *src_net, struct net_device *dev, |
David Ahern | 42ab19e | 2017-10-04 17:48:47 -0700 | [diff] [blame] | 61 | struct nlattr *tb[], struct nlattr *data[], |
| 62 | struct netlink_ext_ack *extack); |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 63 | |
Arnd Bergmann | fc0663d | 2010-01-30 12:23:40 +0000 | [diff] [blame] | 64 | extern void macvlan_dellink(struct net_device *dev, struct list_head *head); |
| 65 | |
| 66 | extern int macvlan_link_register(struct rtnl_link_ops *ops); |
| 67 | |
Michal Kubeček | be9eac4 | 2013-11-15 06:18:40 +0100 | [diff] [blame] | 68 | #if IS_ENABLED(CONFIG_MACVLAN) |
| 69 | static inline struct net_device * |
| 70 | macvlan_dev_real_dev(const struct net_device *dev) |
| 71 | { |
| 72 | struct macvlan_dev *macvlan = netdev_priv(dev); |
| 73 | |
| 74 | return macvlan->lowerdev; |
| 75 | } |
| 76 | #else |
| 77 | static inline struct net_device * |
| 78 | macvlan_dev_real_dev(const struct net_device *dev) |
| 79 | { |
| 80 | BUG(); |
| 81 | return NULL; |
| 82 | } |
| 83 | #endif |
| 84 | |
Alexander Duyck | 7d775f6 | 2018-04-03 17:16:03 -0400 | [diff] [blame] | 85 | static inline void *macvlan_accel_priv(struct net_device *dev) |
| 86 | { |
| 87 | struct macvlan_dev *macvlan = netdev_priv(dev); |
| 88 | |
| 89 | return macvlan->accel_priv; |
| 90 | } |
Alexander Duyck | 6cb1937 | 2018-04-03 17:16:25 -0400 | [diff] [blame] | 91 | |
| 92 | static inline bool macvlan_supports_dest_filter(struct net_device *dev) |
| 93 | { |
| 94 | struct macvlan_dev *macvlan = netdev_priv(dev); |
| 95 | |
| 96 | return macvlan->mode == MACVLAN_MODE_PRIVATE || |
| 97 | macvlan->mode == MACVLAN_MODE_VEPA || |
| 98 | macvlan->mode == MACVLAN_MODE_BRIDGE; |
| 99 | } |
Alexander Duyck | 53cd4d8 | 2018-04-03 17:16:30 -0400 | [diff] [blame] | 100 | |
| 101 | static inline int macvlan_release_l2fw_offload(struct net_device *dev) |
| 102 | { |
| 103 | struct macvlan_dev *macvlan = netdev_priv(dev); |
| 104 | |
| 105 | macvlan->accel_priv = NULL; |
| 106 | return dev_uc_add(macvlan->lowerdev, dev->dev_addr); |
| 107 | } |
Patrick McHardy | b863ceb | 2007-07-14 18:55:06 -0700 | [diff] [blame] | 108 | #endif /* _LINUX_IF_MACVLAN_H */ |