Loading...
1/* SPDX-License-Identifier: GPL-2.0 */
2/* Copyright (C) 2018-2021, Intel Corporation. */
3
4#ifndef _ICE_LAG_H_
5#define _ICE_LAG_H_
6
7#include <linux/netdevice.h>
8
9/* LAG roles for netdev */
10enum ice_lag_role {
11 ICE_LAG_NONE,
12 ICE_LAG_PRIMARY,
13 ICE_LAG_BACKUP,
14 ICE_LAG_UNSET
15};
16
17#define ICE_LAG_INVALID_PORT 0xFF
18
19#define ICE_LAG_RESET_RETRIES 5
20#define ICE_SW_DEFAULT_PROFILE 0
21#define ICE_FV_PROT_MDID 255
22#define ICE_LP_EXT_BUF_OFFSET 32
23
24struct ice_pf;
25struct ice_vf;
26
27struct ice_lag_netdev_list {
28 struct list_head node;
29 struct net_device *netdev;
30};
31
32/* LAG info struct */
33struct ice_lag {
34 struct ice_pf *pf; /* backlink to PF struct */
35 struct net_device *netdev; /* this PF's netdev */
36 struct net_device *upper_netdev; /* upper bonding netdev */
37 struct list_head *netdev_head;
38 struct notifier_block notif_block;
39 s32 bond_mode;
40 u16 bond_swid; /* swid for primary interface */
41 u8 active_port; /* lport value for the current active port */
42 u8 bonded:1; /* currently bonded */
43 u8 primary:1; /* this is primary */
44 u16 pf_recipe;
45 u16 lport_recipe;
46 u16 pf_rx_rule_id;
47 u16 pf_tx_rule_id;
48 u16 cp_rule_idx;
49 u16 lport_rule_idx;
50 u8 role;
51};
52
53/* LAG workqueue struct */
54struct ice_lag_work {
55 struct work_struct lag_task;
56 struct ice_lag_netdev_list netdev_list;
57 struct ice_lag *lag;
58 unsigned long event;
59 struct net_device *event_netdev;
60 union {
61 struct netdev_notifier_changeupper_info changeupper_info;
62 struct netdev_notifier_bonding_info bonding_info;
63 struct netdev_notifier_info notifier_info;
64 } info;
65};
66
67void ice_lag_move_new_vf_nodes(struct ice_vf *vf);
68int ice_init_lag(struct ice_pf *pf);
69void ice_deinit_lag(struct ice_pf *pf);
70void ice_lag_rebuild(struct ice_pf *pf);
71bool ice_lag_is_switchdev_running(struct ice_pf *pf);
72void ice_lag_move_vf_nodes_cfg(struct ice_lag *lag, u8 src_prt, u8 dst_prt);
73#endif /* _ICE_LAG_H_ */
1/* SPDX-License-Identifier: GPL-2.0 */
2/* Copyright (C) 2018-2021, Intel Corporation. */
3
4#ifndef _ICE_LAG_H_
5#define _ICE_LAG_H_
6
7#include <linux/netdevice.h>
8
9/* LAG roles for netdev */
10enum ice_lag_role {
11 ICE_LAG_NONE,
12 ICE_LAG_PRIMARY,
13 ICE_LAG_BACKUP,
14 ICE_LAG_UNSET
15};
16
17struct ice_pf;
18
19/* LAG info struct */
20struct ice_lag {
21 struct ice_pf *pf; /* backlink to PF struct */
22 struct net_device *netdev; /* this PF's netdev */
23 struct net_device *peer_netdev;
24 struct net_device *upper_netdev; /* upper bonding netdev */
25 struct notifier_block notif_block;
26 u8 bonded:1; /* currently bonded */
27 u8 primary:1; /* this is primary */
28 u8 handler:1; /* did we register a rx_netdev_handler */
29 /* each thing blocking bonding will increment this value by one.
30 * If this value is zero, then bonding is allowed.
31 */
32 u16 dis_lag;
33 u8 role;
34};
35
36int ice_init_lag(struct ice_pf *pf);
37void ice_deinit_lag(struct ice_pf *pf);
38rx_handler_result_t ice_lag_nop_handler(struct sk_buff **pskb);
39
40/**
41 * ice_disable_lag - increment LAG disable count
42 * @lag: LAG struct
43 */
44static inline void ice_disable_lag(struct ice_lag *lag)
45{
46 /* If LAG this PF is not already disabled, disable it */
47 rtnl_lock();
48 if (!netdev_is_rx_handler_busy(lag->netdev)) {
49 if (!netdev_rx_handler_register(lag->netdev,
50 ice_lag_nop_handler,
51 NULL))
52 lag->handler = true;
53 }
54 rtnl_unlock();
55 lag->dis_lag++;
56}
57
58/**
59 * ice_enable_lag - decrement disable count for a PF
60 * @lag: LAG struct
61 *
62 * Decrement the disable counter for a port, and if that count reaches
63 * zero, then remove the no-op Rx handler from that netdev
64 */
65static inline void ice_enable_lag(struct ice_lag *lag)
66{
67 if (lag->dis_lag)
68 lag->dis_lag--;
69 if (!lag->dis_lag && lag->handler) {
70 rtnl_lock();
71 netdev_rx_handler_unregister(lag->netdev);
72 rtnl_unlock();
73 lag->handler = false;
74 }
75}
76
77/**
78 * ice_is_lag_dis - is LAG disabled
79 * @lag: LAG struct
80 *
81 * Return true if bonding is disabled
82 */
83static inline bool ice_is_lag_dis(struct ice_lag *lag)
84{
85 return !!(lag->dis_lag);
86}
87#endif /* _ICE_LAG_H_ */