Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /* Copyright (C) 2018-2021, Intel Corporation. */
0003 
0004 #ifndef _ICE_LAG_H_
0005 #define _ICE_LAG_H_
0006 
0007 #include <linux/netdevice.h>
0008 
0009 /* LAG roles for netdev */
0010 enum ice_lag_role {
0011     ICE_LAG_NONE,
0012     ICE_LAG_PRIMARY,
0013     ICE_LAG_BACKUP,
0014     ICE_LAG_UNSET
0015 };
0016 
0017 struct ice_pf;
0018 
0019 /* LAG info struct */
0020 struct ice_lag {
0021     struct ice_pf *pf; /* backlink to PF struct */
0022     struct net_device *netdev; /* this PF's netdev */
0023     struct net_device *peer_netdev;
0024     struct net_device *upper_netdev; /* upper bonding netdev */
0025     struct notifier_block notif_block;
0026     u8 bonded:1; /* currently bonded */
0027     u8 master:1; /* this is a master */
0028     u8 handler:1; /* did we register a rx_netdev_handler */
0029     /* each thing blocking bonding will increment this value by one.
0030      * If this value is zero, then bonding is allowed.
0031      */
0032     u16 dis_lag;
0033     u8 role;
0034 };
0035 
0036 int ice_init_lag(struct ice_pf *pf);
0037 void ice_deinit_lag(struct ice_pf *pf);
0038 rx_handler_result_t ice_lag_nop_handler(struct sk_buff **pskb);
0039 
0040 /**
0041  * ice_disable_lag - increment LAG disable count
0042  * @lag: LAG struct
0043  */
0044 static inline void ice_disable_lag(struct ice_lag *lag)
0045 {
0046     /* If LAG this PF is not already disabled, disable it */
0047     rtnl_lock();
0048     if (!netdev_is_rx_handler_busy(lag->netdev)) {
0049         if (!netdev_rx_handler_register(lag->netdev,
0050                         ice_lag_nop_handler,
0051                         NULL))
0052             lag->handler = true;
0053     }
0054     rtnl_unlock();
0055     lag->dis_lag++;
0056 }
0057 
0058 /**
0059  * ice_enable_lag - decrement disable count for a PF
0060  * @lag: LAG struct
0061  *
0062  * Decrement the disable counter for a port, and if that count reaches
0063  * zero, then remove the no-op Rx handler from that netdev
0064  */
0065 static inline void ice_enable_lag(struct ice_lag *lag)
0066 {
0067     if (lag->dis_lag)
0068         lag->dis_lag--;
0069     if (!lag->dis_lag && lag->handler) {
0070         rtnl_lock();
0071         netdev_rx_handler_unregister(lag->netdev);
0072         rtnl_unlock();
0073         lag->handler = false;
0074     }
0075 }
0076 
0077 /**
0078  * ice_is_lag_dis - is LAG disabled
0079  * @lag: LAG struct
0080  *
0081  * Return true if bonding is disabled
0082  */
0083 static inline bool ice_is_lag_dis(struct ice_lag *lag)
0084 {
0085     return !!(lag->dis_lag);
0086 }
0087 #endif /* _ICE_LAG_H_ */