Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _LINUX_IF_MACVLAN_H
0003 #define _LINUX_IF_MACVLAN_H
0004 
0005 #include <linux/if_link.h>
0006 #include <linux/if_vlan.h>
0007 #include <linux/list.h>
0008 #include <linux/netdevice.h>
0009 #include <linux/netlink.h>
0010 #include <net/netlink.h>
0011 #include <linux/u64_stats_sync.h>
0012 
0013 struct macvlan_port;
0014 
0015 #define MACVLAN_MC_FILTER_BITS  8
0016 #define MACVLAN_MC_FILTER_SZ    (1 << MACVLAN_MC_FILTER_BITS)
0017 
0018 struct macvlan_dev {
0019     struct net_device   *dev;
0020     struct list_head    list;
0021     struct hlist_node   hlist;
0022     struct macvlan_port *port;
0023     struct net_device   *lowerdev;
0024     netdevice_tracker   dev_tracker;
0025     void            *accel_priv;
0026     struct vlan_pcpu_stats __percpu *pcpu_stats;
0027 
0028     DECLARE_BITMAP(mc_filter, MACVLAN_MC_FILTER_SZ);
0029 
0030     netdev_features_t   set_features;
0031     enum macvlan_mode   mode;
0032     u16         flags;
0033     unsigned int        macaddr_count;
0034     u32         bc_queue_len_req;
0035 #ifdef CONFIG_NET_POLL_CONTROLLER
0036     struct netpoll      *netpoll;
0037 #endif
0038 };
0039 
0040 static inline void macvlan_count_rx(const struct macvlan_dev *vlan,
0041                     unsigned int len, bool success,
0042                     bool multicast)
0043 {
0044     if (likely(success)) {
0045         struct vlan_pcpu_stats *pcpu_stats;
0046 
0047         pcpu_stats = get_cpu_ptr(vlan->pcpu_stats);
0048         u64_stats_update_begin(&pcpu_stats->syncp);
0049         u64_stats_inc(&pcpu_stats->rx_packets);
0050         u64_stats_add(&pcpu_stats->rx_bytes, len);
0051         if (multicast)
0052             u64_stats_inc(&pcpu_stats->rx_multicast);
0053         u64_stats_update_end(&pcpu_stats->syncp);
0054         put_cpu_ptr(vlan->pcpu_stats);
0055     } else {
0056         this_cpu_inc(vlan->pcpu_stats->rx_errors);
0057     }
0058 }
0059 
0060 extern void macvlan_common_setup(struct net_device *dev);
0061 
0062 extern int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
0063                   struct nlattr *tb[], struct nlattr *data[],
0064                   struct netlink_ext_ack *extack);
0065 
0066 extern void macvlan_dellink(struct net_device *dev, struct list_head *head);
0067 
0068 extern int macvlan_link_register(struct rtnl_link_ops *ops);
0069 
0070 #if IS_ENABLED(CONFIG_MACVLAN)
0071 static inline struct net_device *
0072 macvlan_dev_real_dev(const struct net_device *dev)
0073 {
0074     struct macvlan_dev *macvlan = netdev_priv(dev);
0075 
0076     return macvlan->lowerdev;
0077 }
0078 #else
0079 static inline struct net_device *
0080 macvlan_dev_real_dev(const struct net_device *dev)
0081 {
0082     BUG();
0083     return NULL;
0084 }
0085 #endif
0086 
0087 static inline void *macvlan_accel_priv(struct net_device *dev)
0088 {
0089     struct macvlan_dev *macvlan = netdev_priv(dev);
0090 
0091     return macvlan->accel_priv;
0092 }
0093 
0094 static inline bool macvlan_supports_dest_filter(struct net_device *dev)
0095 {
0096     struct macvlan_dev *macvlan = netdev_priv(dev);
0097 
0098     return macvlan->mode == MACVLAN_MODE_PRIVATE ||
0099            macvlan->mode == MACVLAN_MODE_VEPA ||
0100            macvlan->mode == MACVLAN_MODE_BRIDGE;
0101 }
0102 
0103 static inline int macvlan_release_l2fw_offload(struct net_device *dev)
0104 {
0105     struct macvlan_dev *macvlan = netdev_priv(dev);
0106 
0107     macvlan->accel_priv = NULL;
0108     return dev_uc_add(macvlan->lowerdev, dev->dev_addr);
0109 }
0110 #endif /* _LINUX_IF_MACVLAN_H */