1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (C) 2018-2021, Intel Corporation. */
4 /* Link Aggregation code */
10 #define ICE_LAG_RES_SHARED BIT(14)
11 #define ICE_LAG_RES_VALID BIT(15)
13 #define LACP_TRAIN_PKT_LEN 16
14 static const u8 lacp_train_pkt
[LACP_TRAIN_PKT_LEN
] = { 0, 0, 0, 0, 0, 0,
18 #define ICE_RECIPE_LEN 64
19 static const u8 ice_dflt_vsi_rcp
[ICE_RECIPE_LEN
] = {
20 0x05, 0, 0, 0, 0x20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
21 0x85, 0, 0x01, 0, 0, 0, 0xff, 0xff, 0x08, 0, 0, 0, 0, 0, 0, 0,
22 0, 0, 0, 0, 0, 0, 0x30 };
23 static const u8 ice_lport_rcp
[ICE_RECIPE_LEN
] = {
24 0x05, 0, 0, 0, 0x20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
25 0x85, 0, 0x16, 0, 0, 0, 0xff, 0xff, 0x07, 0, 0, 0, 0, 0, 0, 0,
26 0, 0, 0, 0, 0, 0, 0x30 };
29 * ice_lag_set_primary - set PF LAG state as Primary
30 * @lag: LAG info struct
32 static void ice_lag_set_primary(struct ice_lag
*lag
)
34 struct ice_pf
*pf
= lag
->pf
;
39 if (lag
->role
!= ICE_LAG_UNSET
&& lag
->role
!= ICE_LAG_BACKUP
) {
40 dev_warn(ice_pf_to_dev(pf
), "%s: Attempt to be Primary, but incompatible state.\n",
41 netdev_name(lag
->netdev
));
45 lag
->role
= ICE_LAG_PRIMARY
;
49 * ice_lag_set_backup - set PF LAG state to Backup
50 * @lag: LAG info struct
52 static void ice_lag_set_backup(struct ice_lag
*lag
)
54 struct ice_pf
*pf
= lag
->pf
;
59 if (lag
->role
!= ICE_LAG_UNSET
&& lag
->role
!= ICE_LAG_PRIMARY
) {
60 dev_dbg(ice_pf_to_dev(pf
), "%s: Attempt to be Backup, but incompatible state\n",
61 netdev_name(lag
->netdev
));
65 lag
->role
= ICE_LAG_BACKUP
;
69 * netif_is_same_ice - determine if netdev is on the same ice NIC as local PF
70 * @pf: local PF struct
71 * @netdev: netdev we are evaluating
73 static bool netif_is_same_ice(struct ice_pf
*pf
, struct net_device
*netdev
)
75 struct ice_netdev_priv
*np
;
76 struct ice_pf
*test_pf
;
79 if (!netif_is_ice(netdev
))
82 np
= netdev_priv(netdev
);
94 if (pf
->pdev
->bus
!= test_pf
->pdev
->bus
||
95 pf
->pdev
->slot
!= test_pf
->pdev
->slot
)
102 * ice_netdev_to_lag - return pointer to associated lag struct from netdev
103 * @netdev: pointer to net_device struct to query
105 static struct ice_lag
*ice_netdev_to_lag(struct net_device
*netdev
)
107 struct ice_netdev_priv
*np
;
110 if (!netif_is_ice(netdev
))
113 np
= netdev_priv(netdev
);
121 return vsi
->back
->lag
;
125 * ice_lag_find_hw_by_lport - return an hw struct from bond members lport
127 * @lport: lport value to search for
129 static struct ice_hw
*
130 ice_lag_find_hw_by_lport(struct ice_lag
*lag
, u8 lport
)
132 struct ice_lag_netdev_list
*entry
;
133 struct net_device
*tmp_netdev
;
134 struct ice_netdev_priv
*np
;
137 list_for_each_entry(entry
, lag
->netdev_head
, node
) {
138 tmp_netdev
= entry
->netdev
;
139 if (!tmp_netdev
|| !netif_is_ice(tmp_netdev
))
142 np
= netdev_priv(tmp_netdev
);
146 hw
= &np
->vsi
->back
->hw
;
147 if (hw
->port_info
->lport
== lport
)
155 * ice_lag_find_primary - returns pointer to primary interfaces lag struct
156 * @lag: local interfaces lag struct
158 static struct ice_lag
*ice_lag_find_primary(struct ice_lag
*lag
)
160 struct ice_lag
*primary_lag
= NULL
;
161 struct list_head
*tmp
;
163 list_for_each(tmp
, lag
->netdev_head
) {
164 struct ice_lag_netdev_list
*entry
;
165 struct ice_lag
*tmp_lag
;
167 entry
= list_entry(tmp
, struct ice_lag_netdev_list
, node
);
168 tmp_lag
= ice_netdev_to_lag(entry
->netdev
);
169 if (tmp_lag
&& tmp_lag
->primary
) {
170 primary_lag
= tmp_lag
;
179 * ice_lag_cfg_fltr - Add/Remove rule for LAG
180 * @lag: lag struct for local interface
182 * @recipe_id: recipe id for the new rule
183 * @rule_idx: pointer to rule index
184 * @add: boolean on whether we are adding filters
187 ice_lag_cfg_fltr(struct ice_lag
*lag
, u32 act
, u16 recipe_id
, u16
*rule_idx
,
190 struct ice_sw_rule_lkup_rx_tx
*s_rule
;
191 u16 s_rule_sz
, vsi_num
;
198 vsi_num
= ice_get_hw_vsi_num(hw
, 0);
200 s_rule_sz
= ICE_SW_RULE_RX_TX_ETH_HDR_SIZE(s_rule
);
201 s_rule
= kzalloc(s_rule_sz
, GFP_KERNEL
);
203 dev_err(ice_pf_to_dev(lag
->pf
), "error allocating rule for LAG\n");
208 eth_hdr
= s_rule
->hdr_data
;
209 ice_fill_eth_hdr(eth_hdr
);
211 act
|= (vsi_num
<< ICE_SINGLE_ACT_VSI_ID_S
) &
212 ICE_SINGLE_ACT_VSI_ID_M
;
214 s_rule
->hdr
.type
= cpu_to_le16(ICE_AQC_SW_RULES_T_LKUP_RX
);
215 s_rule
->recipe_id
= cpu_to_le16(recipe_id
);
216 s_rule
->src
= cpu_to_le16(hw
->port_info
->lport
);
217 s_rule
->act
= cpu_to_le32(act
);
218 s_rule
->hdr_len
= cpu_to_le16(DUMMY_ETH_HDR_LEN
);
219 opc
= ice_aqc_opc_add_sw_rules
;
221 s_rule
->index
= cpu_to_le16(*rule_idx
);
222 opc
= ice_aqc_opc_remove_sw_rules
;
225 err
= ice_aq_sw_rules(&lag
->pf
->hw
, s_rule
, s_rule_sz
, 1, opc
, NULL
);
230 *rule_idx
= le16_to_cpu(s_rule
->index
);
240 * ice_lag_cfg_dflt_fltr - Add/Remove default VSI rule for LAG
241 * @lag: lag struct for local interface
242 * @add: boolean on whether to add filter
245 ice_lag_cfg_dflt_fltr(struct ice_lag
*lag
, bool add
)
247 u32 act
= ICE_SINGLE_ACT_VSI_FORWARDING
|
248 ICE_SINGLE_ACT_VALID_BIT
| ICE_SINGLE_ACT_LAN_ENABLE
;
250 return ice_lag_cfg_fltr(lag
, act
, lag
->pf_recipe
,
251 &lag
->pf_rule_id
, add
);
255 * ice_lag_cfg_drop_fltr - Add/Remove lport drop rule
256 * @lag: lag struct for local interface
257 * @add: boolean on whether to add filter
260 ice_lag_cfg_drop_fltr(struct ice_lag
*lag
, bool add
)
262 u32 act
= ICE_SINGLE_ACT_VSI_FORWARDING
|
263 ICE_SINGLE_ACT_VALID_BIT
|
266 return ice_lag_cfg_fltr(lag
, act
, lag
->lport_recipe
,
267 &lag
->lport_rule_idx
, add
);
271 * ice_lag_cfg_pf_fltrs - set filters up for new active port
272 * @lag: local interfaces lag struct
273 * @ptr: opaque data containing notifier event
276 ice_lag_cfg_pf_fltrs(struct ice_lag
*lag
, void *ptr
)
278 struct netdev_notifier_bonding_info
*info
;
279 struct netdev_bonding_info
*bonding_info
;
280 struct net_device
*event_netdev
;
283 event_netdev
= netdev_notifier_info_to_dev(ptr
);
284 /* not for this netdev */
285 if (event_netdev
!= lag
->netdev
)
288 info
= (struct netdev_notifier_bonding_info
*)ptr
;
289 bonding_info
= &info
->bonding_info
;
290 dev
= ice_pf_to_dev(lag
->pf
);
292 /* interface not active - remove old default VSI rule */
293 if (bonding_info
->slave
.state
&& lag
->pf_rule_id
) {
294 if (ice_lag_cfg_dflt_fltr(lag
, false))
295 dev_err(dev
, "Error removing old default VSI filter\n");
296 if (ice_lag_cfg_drop_fltr(lag
, true))
297 dev_err(dev
, "Error adding new drop filter\n");
301 /* interface becoming active - add new default VSI rule */
302 if (!bonding_info
->slave
.state
&& !lag
->pf_rule_id
) {
303 if (ice_lag_cfg_dflt_fltr(lag
, true))
304 dev_err(dev
, "Error adding new default VSI filter\n");
305 if (lag
->lport_rule_idx
&& ice_lag_cfg_drop_fltr(lag
, false))
306 dev_err(dev
, "Error removing old drop filter\n");
311 * ice_display_lag_info - print LAG info
312 * @lag: LAG info struct
314 static void ice_display_lag_info(struct ice_lag
*lag
)
316 const char *name
, *upper
, *role
, *bonded
, *primary
;
317 struct device
*dev
= &lag
->pf
->pdev
->dev
;
319 name
= lag
->netdev
? netdev_name(lag
->netdev
) : "unset";
320 upper
= lag
->upper_netdev
? netdev_name(lag
->upper_netdev
) : "unset";
321 primary
= lag
->primary
? "TRUE" : "FALSE";
322 bonded
= lag
->bonded
? "BONDED" : "UNBONDED";
328 case ICE_LAG_PRIMARY
:
341 dev_dbg(dev
, "%s %s, upper:%s, role:%s, primary:%s\n", name
, bonded
,
342 upper
, role
, primary
);
346 * ice_lag_qbuf_recfg - generate a buffer of queues for a reconfigure command
347 * @hw: HW struct that contains the queue contexts
348 * @qbuf: pointer to buffer to populate
349 * @vsi_num: index of the VSI in PF space
350 * @numq: number of queues to search for
351 * @tc: traffic class that contains the queues
353 * function returns the number of valid queues in buffer
356 ice_lag_qbuf_recfg(struct ice_hw
*hw
, struct ice_aqc_cfg_txqs_buf
*qbuf
,
357 u16 vsi_num
, u16 numq
, u8 tc
)
359 struct ice_q_ctx
*q_ctx
;
365 for (i
= 0; i
< numq
; i
++) {
366 q_ctx
= ice_get_lan_q_ctx(hw
, vsi_num
, tc
, i
);
368 dev_dbg(ice_hw_to_dev(hw
), "%s queue %d NO Q CONTEXT\n",
372 if (q_ctx
->q_teid
== ICE_INVAL_TEID
) {
373 dev_dbg(ice_hw_to_dev(hw
), "%s queue %d INVAL TEID\n",
377 if (q_ctx
->q_handle
== ICE_INVAL_Q_HANDLE
) {
378 dev_dbg(ice_hw_to_dev(hw
), "%s queue %d INVAL Q HANDLE\n",
383 qid
= pf
->vsi
[vsi_num
]->txq_map
[q_ctx
->q_handle
];
384 qbuf
->queue_info
[count
].q_handle
= cpu_to_le16(qid
);
385 qbuf
->queue_info
[count
].tc
= tc
;
386 qbuf
->queue_info
[count
].q_teid
= cpu_to_le32(q_ctx
->q_teid
);
394 * ice_lag_get_sched_parent - locate or create a sched node parent
395 * @hw: HW struct for getting parent in
396 * @tc: traffic class on parent/node
398 static struct ice_sched_node
*
399 ice_lag_get_sched_parent(struct ice_hw
*hw
, u8 tc
)
401 struct ice_sched_node
*tc_node
, *aggnode
, *parent
= NULL
;
402 u16 num_nodes
[ICE_AQC_TOPO_MAX_LEVEL_NUM
] = { 0 };
403 struct ice_port_info
*pi
= hw
->port_info
;
408 dev
= ice_hw_to_dev(hw
);
410 tc_node
= ice_sched_get_tc_node(pi
, tc
);
412 dev_warn(dev
, "Failure to find TC node for LAG move\n");
416 aggnode
= ice_sched_get_agg_node(pi
, tc_node
, ICE_DFLT_AGG_ID
);
418 dev_warn(dev
, "Failure to find aggregate node for LAG move\n");
422 aggl
= ice_sched_get_agg_layer(hw
);
423 vsil
= ice_sched_get_vsi_layer(hw
);
425 for (n
= aggl
+ 1; n
< vsil
; n
++)
428 for (n
= 0; n
< aggnode
->num_children
; n
++) {
429 parent
= ice_sched_get_free_vsi_parent(hw
, aggnode
->children
[n
],
435 /* if free parent not found - add one */
437 for (n
= aggl
+ 1; n
< vsil
; n
++) {
442 err
= ice_sched_add_nodes_to_layer(pi
, tc_node
, parent
, n
,
443 num_nodes
[n
], &first_teid
,
445 if (err
|| num_nodes
[n
] != num_nodes_added
)
449 parent
= ice_sched_find_node_by_teid(tc_node
,
452 parent
= parent
->children
[0];
454 dev_warn(dev
, "Failure to add new parent for LAG move\n");
463 * ice_lag_move_vf_node_tc - move scheduling nodes for one VF on one TC
464 * @lag: lag info struct
465 * @oldport: lport of previous nodes location
466 * @newport: lport of destination nodes location
467 * @vsi_num: array index of VSI in PF space
468 * @tc: traffic class to move
471 ice_lag_move_vf_node_tc(struct ice_lag
*lag
, u8 oldport
, u8 newport
,
474 DEFINE_FLEX(struct ice_aqc_move_elem
, buf
, teid
, 1);
475 struct device
*dev
= ice_pf_to_dev(lag
->pf
);
476 u16 numq
, valq
, num_moved
, qbuf_size
;
477 u16 buf_size
= __struct_size(buf
);
478 struct ice_aqc_cfg_txqs_buf
*qbuf
;
479 struct ice_sched_node
*n_prt
;
480 struct ice_hw
*new_hw
= NULL
;
481 __le32 teid
, parent_teid
;
482 struct ice_vsi_ctx
*ctx
;
485 ctx
= ice_get_vsi_ctx(&lag
->pf
->hw
, vsi_num
);
487 dev_warn(dev
, "Unable to locate VSI context for LAG failover\n");
491 /* check to see if this VF is enabled on this TC */
492 if (!ctx
->sched
.vsi_node
[tc
])
495 /* locate HW struct for destination port */
496 new_hw
= ice_lag_find_hw_by_lport(lag
, newport
);
498 dev_warn(dev
, "Unable to locate HW struct for LAG node destination\n");
502 numq
= ctx
->num_lan_q_entries
[tc
];
503 teid
= ctx
->sched
.vsi_node
[tc
]->info
.node_teid
;
504 tmp_teid
= le32_to_cpu(teid
);
505 parent_teid
= ctx
->sched
.vsi_node
[tc
]->info
.parent_teid
;
506 /* if no teid assigned or numq == 0, then this TC is not active */
507 if (!tmp_teid
|| !numq
)
510 /* suspend VSI subtree for Traffic Class "tc" on
513 if (ice_sched_suspend_resume_elems(&lag
->pf
->hw
, 1, &tmp_teid
, true))
514 dev_dbg(dev
, "Problem suspending traffic for LAG node move\n");
516 /* reconfigure all VF's queues on this Traffic Class
519 qbuf_size
= struct_size(qbuf
, queue_info
, numq
);
520 qbuf
= kzalloc(qbuf_size
, GFP_KERNEL
);
522 dev_warn(dev
, "Failure allocating memory for VF queue recfg buffer\n");
526 /* add the per queue info for the reconfigure command buffer */
527 valq
= ice_lag_qbuf_recfg(&lag
->pf
->hw
, qbuf
, vsi_num
, numq
, tc
);
529 dev_dbg(dev
, "No valid queues found for LAG failover\n");
533 if (ice_aq_cfg_lan_txq(&lag
->pf
->hw
, qbuf
, qbuf_size
, valq
, oldport
,
535 dev_warn(dev
, "Failure to configure queues for LAG failover\n");
542 /* find new parent in destination port's tree for VF VSI node on this
545 n_prt
= ice_lag_get_sched_parent(new_hw
, tc
);
549 /* Move Vf's VSI node for this TC to newport's scheduler tree */
550 buf
->hdr
.src_parent_teid
= parent_teid
;
551 buf
->hdr
.dest_parent_teid
= n_prt
->info
.node_teid
;
552 buf
->hdr
.num_elems
= cpu_to_le16(1);
553 buf
->hdr
.mode
= ICE_AQC_MOVE_ELEM_MODE_KEEP_OWN
;
556 if (ice_aq_move_sched_elems(&lag
->pf
->hw
, buf
, buf_size
, &num_moved
))
557 dev_warn(dev
, "Failure to move VF nodes for failover\n");
559 ice_sched_update_parent(n_prt
, ctx
->sched
.vsi_node
[tc
]);
567 /* restart traffic for VSI node */
568 if (ice_sched_suspend_resume_elems(&lag
->pf
->hw
, 1, &tmp_teid
, false))
569 dev_dbg(dev
, "Problem restarting traffic for LAG node move\n");
573 * ice_lag_build_netdev_list - populate the lag struct's netdev list
574 * @lag: local lag struct
575 * @ndlist: pointer to netdev list to populate
577 static void ice_lag_build_netdev_list(struct ice_lag
*lag
,
578 struct ice_lag_netdev_list
*ndlist
)
580 struct ice_lag_netdev_list
*nl
;
581 struct net_device
*tmp_nd
;
583 INIT_LIST_HEAD(&ndlist
->node
);
585 for_each_netdev_in_bond_rcu(lag
->upper_netdev
, tmp_nd
) {
586 nl
= kzalloc(sizeof(*nl
), GFP_ATOMIC
);
591 list_add(&nl
->node
, &ndlist
->node
);
594 lag
->netdev_head
= &ndlist
->node
;
598 * ice_lag_destroy_netdev_list - free lag struct's netdev list
599 * @lag: pointer to local lag struct
600 * @ndlist: pointer to lag struct netdev list
602 static void ice_lag_destroy_netdev_list(struct ice_lag
*lag
,
603 struct ice_lag_netdev_list
*ndlist
)
605 struct ice_lag_netdev_list
*entry
, *n
;
608 list_for_each_entry_safe(entry
, n
, &ndlist
->node
, node
) {
609 list_del(&entry
->node
);
613 lag
->netdev_head
= NULL
;
617 * ice_lag_move_single_vf_nodes - Move Tx scheduling nodes for single VF
618 * @lag: primary interface LAG struct
619 * @oldport: lport of previous interface
620 * @newport: lport of destination interface
621 * @vsi_num: SW index of VF's VSI
624 ice_lag_move_single_vf_nodes(struct ice_lag
*lag
, u8 oldport
, u8 newport
,
629 ice_for_each_traffic_class(tc
)
630 ice_lag_move_vf_node_tc(lag
, oldport
, newport
, vsi_num
, tc
);
634 * ice_lag_move_new_vf_nodes - Move Tx scheduling nodes for a VF if required
635 * @vf: the VF to move Tx nodes for
637 * Called just after configuring new VF queues. Check whether the VF Tx
638 * scheduling nodes need to be updated to fail over to the active port. If so,
641 void ice_lag_move_new_vf_nodes(struct ice_vf
*vf
)
643 struct ice_lag_netdev_list ndlist
;
644 u8 pri_port
, act_port
;
649 vsi
= ice_get_vf_vsi(vf
);
654 if (WARN_ON(vsi
->type
!= ICE_VSI_VF
))
660 mutex_lock(&pf
->lag_mutex
);
664 pri_port
= pf
->hw
.port_info
->lport
;
665 act_port
= lag
->active_port
;
667 if (lag
->upper_netdev
)
668 ice_lag_build_netdev_list(lag
, &ndlist
);
670 if (ice_is_feature_supported(pf
, ICE_F_SRIOV_LAG
) &&
671 lag
->bonded
&& lag
->primary
&& pri_port
!= act_port
&&
672 !list_empty(lag
->netdev_head
))
673 ice_lag_move_single_vf_nodes(lag
, pri_port
, act_port
, vsi
->idx
);
675 ice_lag_destroy_netdev_list(lag
, &ndlist
);
678 mutex_unlock(&pf
->lag_mutex
);
682 * ice_lag_move_vf_nodes - move Tx scheduling nodes for all VFs to new port
683 * @lag: lag info struct
684 * @oldport: lport of previous interface
685 * @newport: lport of destination interface
687 static void ice_lag_move_vf_nodes(struct ice_lag
*lag
, u8 oldport
, u8 newport
)
696 ice_for_each_vsi(pf
, i
)
697 if (pf
->vsi
[i
] && (pf
->vsi
[i
]->type
== ICE_VSI_VF
||
698 pf
->vsi
[i
]->type
== ICE_VSI_SWITCHDEV_CTRL
))
699 ice_lag_move_single_vf_nodes(lag
, oldport
, newport
, i
);
703 * ice_lag_move_vf_nodes_cfg - move vf nodes outside LAG netdev event context
704 * @lag: local lag struct
705 * @src_prt: lport value for source port
706 * @dst_prt: lport value for destination port
708 * This function is used to move nodes during an out-of-netdev-event situation,
709 * primarily when the driver needs to reconfigure or recreate resources.
711 * Must be called while holding the lag_mutex to avoid lag events from
712 * processing while out-of-sync moves are happening. Also, paired moves,
713 * such as used in a reset flow, should both be called under the same mutex
714 * lock to avoid changes between start of reset and end of reset.
716 void ice_lag_move_vf_nodes_cfg(struct ice_lag
*lag
, u8 src_prt
, u8 dst_prt
)
718 struct ice_lag_netdev_list ndlist
;
720 ice_lag_build_netdev_list(lag
, &ndlist
);
721 ice_lag_move_vf_nodes(lag
, src_prt
, dst_prt
);
722 ice_lag_destroy_netdev_list(lag
, &ndlist
);
725 #define ICE_LAG_SRIOV_CP_RECIPE 10
726 #define ICE_LAG_SRIOV_TRAIN_PKT_LEN 16
729 * ice_lag_cfg_cp_fltr - configure filter for control packets
730 * @lag: local interface's lag struct
731 * @add: add or remove rule
734 ice_lag_cfg_cp_fltr(struct ice_lag
*lag
, bool add
)
736 struct ice_sw_rule_lkup_rx_tx
*s_rule
= NULL
;
740 vsi
= lag
->pf
->vsi
[0];
742 buf_len
= ICE_SW_RULE_RX_TX_HDR_SIZE(s_rule
,
743 ICE_LAG_SRIOV_TRAIN_PKT_LEN
);
744 s_rule
= kzalloc(buf_len
, GFP_KERNEL
);
746 netdev_warn(lag
->netdev
, "-ENOMEM error configuring CP filter\n");
751 s_rule
->hdr
.type
= cpu_to_le16(ICE_AQC_SW_RULES_T_LKUP_RX
);
752 s_rule
->recipe_id
= cpu_to_le16(ICE_LAG_SRIOV_CP_RECIPE
);
753 s_rule
->src
= cpu_to_le16(vsi
->port_info
->lport
);
754 s_rule
->act
= cpu_to_le32(ICE_FWD_TO_VSI
|
755 ICE_SINGLE_ACT_LAN_ENABLE
|
756 ICE_SINGLE_ACT_VALID_BIT
|
758 ICE_SINGLE_ACT_VSI_ID_S
) &
759 ICE_SINGLE_ACT_VSI_ID_M
));
760 s_rule
->hdr_len
= cpu_to_le16(ICE_LAG_SRIOV_TRAIN_PKT_LEN
);
761 memcpy(s_rule
->hdr_data
, lacp_train_pkt
, LACP_TRAIN_PKT_LEN
);
762 opc
= ice_aqc_opc_add_sw_rules
;
764 opc
= ice_aqc_opc_remove_sw_rules
;
765 s_rule
->index
= cpu_to_le16(lag
->cp_rule_idx
);
767 if (ice_aq_sw_rules(&lag
->pf
->hw
, s_rule
, buf_len
, 1, opc
, NULL
)) {
768 netdev_warn(lag
->netdev
, "Error %s CP rule for fail-over\n",
769 add
? "ADDING" : "REMOVING");
774 lag
->cp_rule_idx
= le16_to_cpu(s_rule
->index
);
776 lag
->cp_rule_idx
= 0;
783 * ice_lag_info_event - handle NETDEV_BONDING_INFO event
784 * @lag: LAG info struct
785 * @ptr: opaque data pointer
787 * ptr is to be cast to (netdev_notifier_bonding_info *)
789 static void ice_lag_info_event(struct ice_lag
*lag
, void *ptr
)
791 struct netdev_notifier_bonding_info
*info
;
792 struct netdev_bonding_info
*bonding_info
;
793 struct net_device
*event_netdev
;
794 const char *lag_netdev_name
;
796 event_netdev
= netdev_notifier_info_to_dev(ptr
);
798 lag_netdev_name
= netdev_name(lag
->netdev
);
799 bonding_info
= &info
->bonding_info
;
801 if (event_netdev
!= lag
->netdev
|| !lag
->bonded
|| !lag
->upper_netdev
)
804 if (bonding_info
->master
.bond_mode
!= BOND_MODE_ACTIVEBACKUP
) {
805 netdev_dbg(lag
->netdev
, "Bonding event recv, but mode not active/backup\n");
809 if (strcmp(bonding_info
->slave
.slave_name
, lag_netdev_name
)) {
810 netdev_dbg(lag
->netdev
, "Bonding event recv, but secondary info not for us\n");
814 if (bonding_info
->slave
.state
)
815 ice_lag_set_backup(lag
);
817 ice_lag_set_primary(lag
);
820 ice_display_lag_info(lag
);
824 * ice_lag_reclaim_vf_tc - move scheduling nodes back to primary interface
825 * @lag: primary interface lag struct
826 * @src_hw: HW struct current node location
827 * @vsi_num: VSI index in PF space
828 * @tc: traffic class to move
831 ice_lag_reclaim_vf_tc(struct ice_lag
*lag
, struct ice_hw
*src_hw
, u16 vsi_num
,
834 DEFINE_FLEX(struct ice_aqc_move_elem
, buf
, teid
, 1);
835 struct device
*dev
= ice_pf_to_dev(lag
->pf
);
836 u16 numq
, valq
, num_moved
, qbuf_size
;
837 u16 buf_size
= __struct_size(buf
);
838 struct ice_aqc_cfg_txqs_buf
*qbuf
;
839 struct ice_sched_node
*n_prt
;
840 __le32 teid
, parent_teid
;
841 struct ice_vsi_ctx
*ctx
;
846 ctx
= ice_get_vsi_ctx(hw
, vsi_num
);
848 dev_warn(dev
, "Unable to locate VSI context for LAG reclaim\n");
852 /* check to see if this VF is enabled on this TC */
853 if (!ctx
->sched
.vsi_node
[tc
])
856 numq
= ctx
->num_lan_q_entries
[tc
];
857 teid
= ctx
->sched
.vsi_node
[tc
]->info
.node_teid
;
858 tmp_teid
= le32_to_cpu(teid
);
859 parent_teid
= ctx
->sched
.vsi_node
[tc
]->info
.parent_teid
;
861 /* if !teid or !numq, then this TC is not active */
862 if (!tmp_teid
|| !numq
)
865 /* suspend traffic */
866 if (ice_sched_suspend_resume_elems(hw
, 1, &tmp_teid
, true))
867 dev_dbg(dev
, "Problem suspending traffic for LAG node move\n");
869 /* reconfig queues for new port */
870 qbuf_size
= struct_size(qbuf
, queue_info
, numq
);
871 qbuf
= kzalloc(qbuf_size
, GFP_KERNEL
);
873 dev_warn(dev
, "Failure allocating memory for VF queue recfg buffer\n");
877 /* add the per queue info for the reconfigure command buffer */
878 valq
= ice_lag_qbuf_recfg(hw
, qbuf
, vsi_num
, numq
, tc
);
880 dev_dbg(dev
, "No valid queues found for LAG reclaim\n");
884 if (ice_aq_cfg_lan_txq(hw
, qbuf
, qbuf_size
, numq
,
885 src_hw
->port_info
->lport
, hw
->port_info
->lport
,
887 dev_warn(dev
, "Failure to configure queues for LAG failover\n");
894 /* find parent in primary tree */
895 n_prt
= ice_lag_get_sched_parent(hw
, tc
);
899 /* Move node to new parent */
900 buf
->hdr
.src_parent_teid
= parent_teid
;
901 buf
->hdr
.dest_parent_teid
= n_prt
->info
.node_teid
;
902 buf
->hdr
.num_elems
= cpu_to_le16(1);
903 buf
->hdr
.mode
= ICE_AQC_MOVE_ELEM_MODE_KEEP_OWN
;
906 if (ice_aq_move_sched_elems(&lag
->pf
->hw
, buf
, buf_size
, &num_moved
))
907 dev_warn(dev
, "Failure to move VF nodes for LAG reclaim\n");
909 ice_sched_update_parent(n_prt
, ctx
->sched
.vsi_node
[tc
]);
917 /* restart traffic */
918 if (ice_sched_suspend_resume_elems(hw
, 1, &tmp_teid
, false))
919 dev_warn(dev
, "Problem restarting traffic for LAG node reclaim\n");
923 * ice_lag_reclaim_vf_nodes - When interface leaving bond primary reclaims nodes
924 * @lag: primary interface lag struct
925 * @src_hw: HW struct for current node location
928 ice_lag_reclaim_vf_nodes(struct ice_lag
*lag
, struct ice_hw
*src_hw
)
933 if (!lag
->primary
|| !src_hw
)
937 ice_for_each_vsi(pf
, i
)
938 if (pf
->vsi
[i
] && (pf
->vsi
[i
]->type
== ICE_VSI_VF
||
939 pf
->vsi
[i
]->type
== ICE_VSI_SWITCHDEV_CTRL
))
940 ice_for_each_traffic_class(tc
)
941 ice_lag_reclaim_vf_tc(lag
, src_hw
, i
, tc
);
945 * ice_lag_link - handle LAG link event
946 * @lag: LAG info struct
948 static void ice_lag_link(struct ice_lag
*lag
)
950 struct ice_pf
*pf
= lag
->pf
;
953 dev_warn(ice_pf_to_dev(pf
), "%s Already part of a bond\n",
954 netdev_name(lag
->netdev
));
957 lag
->role
= ICE_LAG_UNSET
;
958 netdev_info(lag
->netdev
, "Shared SR-IOV resources in bond are active\n");
962 * ice_lag_unlink - handle unlink event
963 * @lag: LAG info struct
965 static void ice_lag_unlink(struct ice_lag
*lag
)
967 u8 pri_port
, act_port
, loc_port
;
968 struct ice_pf
*pf
= lag
->pf
;
971 netdev_dbg(lag
->netdev
, "bonding unlink event on non-LAG netdev\n");
976 act_port
= lag
->active_port
;
977 pri_port
= lag
->pf
->hw
.port_info
->lport
;
978 if (act_port
!= pri_port
&& act_port
!= ICE_LAG_INVALID_PORT
)
979 ice_lag_move_vf_nodes(lag
, act_port
, pri_port
);
980 lag
->primary
= false;
981 lag
->active_port
= ICE_LAG_INVALID_PORT
;
983 struct ice_lag
*primary_lag
;
985 primary_lag
= ice_lag_find_primary(lag
);
987 act_port
= primary_lag
->active_port
;
988 pri_port
= primary_lag
->pf
->hw
.port_info
->lport
;
989 loc_port
= pf
->hw
.port_info
->lport
;
990 if (act_port
== loc_port
&&
991 act_port
!= ICE_LAG_INVALID_PORT
) {
992 ice_lag_reclaim_vf_nodes(primary_lag
,
994 primary_lag
->active_port
= ICE_LAG_INVALID_PORT
;
1000 lag
->role
= ICE_LAG_NONE
;
1001 lag
->upper_netdev
= NULL
;
1005 * ice_lag_link_unlink - helper function to call lag_link/unlink
1006 * @lag: lag info struct
1007 * @ptr: opaque pointer data
1009 static void ice_lag_link_unlink(struct ice_lag
*lag
, void *ptr
)
1011 struct net_device
*netdev
= netdev_notifier_info_to_dev(ptr
);
1012 struct netdev_notifier_changeupper_info
*info
= ptr
;
1014 if (netdev
!= lag
->netdev
)
1020 ice_lag_unlink(lag
);
1024 * ice_lag_set_swid - set the SWID on secondary interface
1025 * @primary_swid: primary interface's SWID
1026 * @local_lag: local interfaces LAG struct
1027 * @link: Is this a linking activity
1029 * If link is false, then primary_swid should be expected to not be valid
1030 * This function should never be called in interrupt context.
1033 ice_lag_set_swid(u16 primary_swid
, struct ice_lag
*local_lag
,
1036 struct ice_aqc_alloc_free_res_elem
*buf
;
1037 struct ice_aqc_set_port_params
*cmd
;
1038 struct ice_aq_desc desc
;
1042 buf_len
= struct_size(buf
, elem
, 1);
1043 buf
= kzalloc(buf_len
, GFP_KERNEL
);
1045 dev_err(ice_pf_to_dev(local_lag
->pf
), "-ENOMEM error setting SWID\n");
1049 buf
->num_elems
= cpu_to_le16(1);
1050 buf
->res_type
= cpu_to_le16(ICE_AQC_RES_TYPE_SWID
);
1051 /* if unlinnking need to free the shared resource */
1052 if (!link
&& local_lag
->bond_swid
) {
1053 buf
->elem
[0].e
.sw_resp
= cpu_to_le16(local_lag
->bond_swid
);
1054 status
= ice_aq_alloc_free_res(&local_lag
->pf
->hw
, buf
,
1055 buf_len
, ice_aqc_opc_free_res
);
1057 dev_err(ice_pf_to_dev(local_lag
->pf
), "Error freeing SWID during LAG unlink\n");
1058 local_lag
->bond_swid
= 0;
1062 buf
->res_type
|= cpu_to_le16(ICE_LAG_RES_SHARED
|
1064 /* store the primary's SWID in case it leaves bond first */
1065 local_lag
->bond_swid
= primary_swid
;
1066 buf
->elem
[0].e
.sw_resp
= cpu_to_le16(local_lag
->bond_swid
);
1068 buf
->elem
[0].e
.sw_resp
=
1069 cpu_to_le16(local_lag
->pf
->hw
.port_info
->sw_id
);
1072 status
= ice_aq_alloc_free_res(&local_lag
->pf
->hw
, buf
, buf_len
,
1073 ice_aqc_opc_alloc_res
);
1075 dev_err(ice_pf_to_dev(local_lag
->pf
), "Error subscribing to SWID 0x%04X\n",
1076 local_lag
->bond_swid
);
1080 /* Configure port param SWID to correct value */
1082 swid
= primary_swid
;
1084 swid
= local_lag
->pf
->hw
.port_info
->sw_id
;
1086 cmd
= &desc
.params
.set_port_params
;
1087 ice_fill_dflt_direct_cmd_desc(&desc
, ice_aqc_opc_set_port_params
);
1089 cmd
->swid
= cpu_to_le16(ICE_AQC_PORT_SWID_VALID
| swid
);
1090 /* If this is happening in reset context, it is possible that the
1091 * primary interface has not finished setting its SWID to SHARED
1092 * yet. Allow retries to account for this timing issue between
1095 for (i
= 0; i
< ICE_LAG_RESET_RETRIES
; i
++) {
1096 status
= ice_aq_send_cmd(&local_lag
->pf
->hw
, &desc
, NULL
, 0,
1101 usleep_range(1000, 2000);
1105 dev_err(ice_pf_to_dev(local_lag
->pf
), "Error setting SWID in port params %d\n",
1110 * ice_lag_primary_swid - set/clear the SHARED attrib of primary's SWID
1111 * @lag: primary interface's lag struct
1112 * @link: is this a linking activity
1114 * Implement setting primary SWID as shared using 0x020B
1116 static void ice_lag_primary_swid(struct ice_lag
*lag
, bool link
)
1122 swid
= hw
->port_info
->sw_id
;
1124 if (ice_share_res(hw
, ICE_AQC_RES_TYPE_SWID
, link
, swid
))
1125 dev_warn(ice_pf_to_dev(lag
->pf
), "Failure to set primary interface shared status\n");
1129 * ice_lag_add_prune_list - Adds event_pf's VSI to primary's prune list
1130 * @lag: lag info struct
1131 * @event_pf: PF struct for VSI we are adding to primary's prune list
1133 static void ice_lag_add_prune_list(struct ice_lag
*lag
, struct ice_pf
*event_pf
)
1135 u16 num_vsi
, rule_buf_sz
, vsi_list_id
, event_vsi_num
, prim_vsi_idx
;
1136 struct ice_sw_rule_vsi_list
*s_rule
= NULL
;
1141 dev
= ice_pf_to_dev(lag
->pf
);
1142 event_vsi_num
= event_pf
->vsi
[0]->vsi_num
;
1143 prim_vsi_idx
= lag
->pf
->vsi
[0]->idx
;
1145 if (!ice_find_vsi_list_entry(&lag
->pf
->hw
, ICE_SW_LKUP_VLAN
,
1146 prim_vsi_idx
, &vsi_list_id
)) {
1147 dev_warn(dev
, "Could not locate prune list when setting up SRIOV LAG\n");
1151 rule_buf_sz
= (u16
)ICE_SW_RULE_VSI_LIST_SIZE(s_rule
, num_vsi
);
1152 s_rule
= kzalloc(rule_buf_sz
, GFP_KERNEL
);
1154 dev_warn(dev
, "Error allocating space for prune list when configuring SRIOV LAG\n");
1158 s_rule
->hdr
.type
= cpu_to_le16(ICE_AQC_SW_RULES_T_PRUNE_LIST_SET
);
1159 s_rule
->index
= cpu_to_le16(vsi_list_id
);
1160 s_rule
->number_vsi
= cpu_to_le16(num_vsi
);
1161 s_rule
->vsi
[0] = cpu_to_le16(event_vsi_num
);
1163 if (ice_aq_sw_rules(&event_pf
->hw
, s_rule
, rule_buf_sz
, 1,
1164 ice_aqc_opc_update_sw_rules
, NULL
))
1165 dev_warn(dev
, "Error adding VSI prune list\n");
1170 * ice_lag_del_prune_list - Remove secondary's vsi from primary's prune list
1171 * @lag: primary interface's ice_lag struct
1172 * @event_pf: PF struct for unlinking interface
1174 static void ice_lag_del_prune_list(struct ice_lag
*lag
, struct ice_pf
*event_pf
)
1176 u16 num_vsi
, vsi_num
, vsi_idx
, rule_buf_sz
, vsi_list_id
;
1177 struct ice_sw_rule_vsi_list
*s_rule
= NULL
;
1182 dev
= ice_pf_to_dev(lag
->pf
);
1183 vsi_num
= event_pf
->vsi
[0]->vsi_num
;
1184 vsi_idx
= lag
->pf
->vsi
[0]->idx
;
1186 if (!ice_find_vsi_list_entry(&lag
->pf
->hw
, ICE_SW_LKUP_VLAN
,
1187 vsi_idx
, &vsi_list_id
)) {
1188 dev_warn(dev
, "Could not locate prune list when unwinding SRIOV LAG\n");
1192 rule_buf_sz
= (u16
)ICE_SW_RULE_VSI_LIST_SIZE(s_rule
, num_vsi
);
1193 s_rule
= kzalloc(rule_buf_sz
, GFP_KERNEL
);
1195 dev_warn(dev
, "Error allocating prune list when unwinding SRIOV LAG\n");
1199 s_rule
->hdr
.type
= cpu_to_le16(ICE_AQC_SW_RULES_T_PRUNE_LIST_CLEAR
);
1200 s_rule
->index
= cpu_to_le16(vsi_list_id
);
1201 s_rule
->number_vsi
= cpu_to_le16(num_vsi
);
1202 s_rule
->vsi
[0] = cpu_to_le16(vsi_num
);
1204 if (ice_aq_sw_rules(&event_pf
->hw
, (struct ice_aqc_sw_rules
*)s_rule
,
1205 rule_buf_sz
, 1, ice_aqc_opc_update_sw_rules
, NULL
))
1206 dev_warn(dev
, "Error clearing VSI prune list\n");
1212 * ice_lag_init_feature_support_flag - Check for NVM support for LAG
1215 static void ice_lag_init_feature_support_flag(struct ice_pf
*pf
)
1217 struct ice_hw_common_caps
*caps
;
1219 caps
= &pf
->hw
.dev_caps
.common_cap
;
1221 ice_set_feature_support(pf
, ICE_F_ROCE_LAG
);
1223 ice_clear_feature_support(pf
, ICE_F_ROCE_LAG
);
1225 if (caps
->sriov_lag
)
1226 ice_set_feature_support(pf
, ICE_F_SRIOV_LAG
);
1228 ice_clear_feature_support(pf
, ICE_F_SRIOV_LAG
);
1232 * ice_lag_changeupper_event - handle LAG changeupper event
1233 * @lag: LAG info struct
1234 * @ptr: opaque pointer data
1236 static void ice_lag_changeupper_event(struct ice_lag
*lag
, void *ptr
)
1238 struct netdev_notifier_changeupper_info
*info
;
1239 struct ice_lag
*primary_lag
;
1240 struct net_device
*netdev
;
1243 netdev
= netdev_notifier_info_to_dev(ptr
);
1245 /* not for this netdev */
1246 if (netdev
!= lag
->netdev
)
1249 primary_lag
= ice_lag_find_primary(lag
);
1250 if (info
->linking
) {
1251 lag
->upper_netdev
= info
->upper_dev
;
1252 /* If there is not already a primary interface in the LAG,
1253 * then mark this one as primary.
1256 lag
->primary
= true;
1257 /* Configure primary's SWID to be shared */
1258 ice_lag_primary_swid(lag
, true);
1263 swid
= primary_lag
->pf
->hw
.port_info
->sw_id
;
1264 ice_lag_set_swid(swid
, lag
, true);
1265 ice_lag_add_prune_list(primary_lag
, lag
->pf
);
1266 ice_lag_cfg_drop_fltr(lag
, true);
1268 /* add filter for primary control packets */
1269 ice_lag_cfg_cp_fltr(lag
, true);
1271 if (!primary_lag
&& lag
->primary
)
1274 if (!lag
->primary
) {
1275 ice_lag_set_swid(0, lag
, false);
1277 if (primary_lag
&& lag
->primary
) {
1278 ice_lag_primary_swid(lag
, false);
1279 ice_lag_del_prune_list(primary_lag
, lag
->pf
);
1282 /* remove filter for control packets */
1283 ice_lag_cfg_cp_fltr(lag
, false);
1288 * ice_lag_monitor_link - monitor interfaces entering/leaving the aggregate
1289 * @lag: lag info struct
1290 * @ptr: opaque data containing notifier event
1292 * This function only operates after a primary has been set.
1294 static void ice_lag_monitor_link(struct ice_lag
*lag
, void *ptr
)
1296 struct netdev_notifier_changeupper_info
*info
;
1297 struct ice_hw
*prim_hw
, *active_hw
;
1298 struct net_device
*event_netdev
;
1305 event_netdev
= netdev_notifier_info_to_dev(ptr
);
1306 if (!netif_is_same_ice(lag
->pf
, event_netdev
))
1311 prim_port
= prim_hw
->port_info
->lport
;
1313 info
= (struct netdev_notifier_changeupper_info
*)ptr
;
1314 if (info
->upper_dev
!= lag
->upper_netdev
)
1317 if (!info
->linking
) {
1318 /* Since there are only two interfaces allowed in SRIOV+LAG, if
1319 * one port is leaving, then nodes need to be on primary
1322 if (prim_port
!= lag
->active_port
&&
1323 lag
->active_port
!= ICE_LAG_INVALID_PORT
) {
1324 active_hw
= ice_lag_find_hw_by_lport(lag
,
1326 ice_lag_reclaim_vf_nodes(lag
, active_hw
);
1327 lag
->active_port
= ICE_LAG_INVALID_PORT
;
1333 * ice_lag_monitor_active - main PF keep track of which port is active
1334 * @lag: lag info struct
1335 * @ptr: opaque data containing notifier event
1337 * This function is for the primary PF to monitor changes in which port is
1338 * active and handle changes for SRIOV VF functionality
1340 static void ice_lag_monitor_active(struct ice_lag
*lag
, void *ptr
)
1342 struct net_device
*event_netdev
, *event_upper
;
1343 struct netdev_notifier_bonding_info
*info
;
1344 struct netdev_bonding_info
*bonding_info
;
1345 struct ice_netdev_priv
*event_np
;
1346 struct ice_pf
*pf
, *event_pf
;
1347 u8 prim_port
, event_port
;
1356 event_netdev
= netdev_notifier_info_to_dev(ptr
);
1358 event_upper
= netdev_master_upper_dev_get_rcu(event_netdev
);
1360 if (!netif_is_ice(event_netdev
) || event_upper
!= lag
->upper_netdev
)
1363 event_np
= netdev_priv(event_netdev
);
1364 event_pf
= event_np
->vsi
->back
;
1365 event_port
= event_pf
->hw
.port_info
->lport
;
1366 prim_port
= pf
->hw
.port_info
->lport
;
1368 info
= (struct netdev_notifier_bonding_info
*)ptr
;
1369 bonding_info
= &info
->bonding_info
;
1371 if (!bonding_info
->slave
.state
) {
1372 /* if no port is currently active, then nodes and filters exist
1373 * on primary port, check if we need to move them
1375 if (lag
->active_port
== ICE_LAG_INVALID_PORT
) {
1376 if (event_port
!= prim_port
)
1377 ice_lag_move_vf_nodes(lag
, prim_port
,
1379 lag
->active_port
= event_port
;
1383 /* active port is already set and is current event port */
1384 if (lag
->active_port
== event_port
)
1386 /* new active port */
1387 ice_lag_move_vf_nodes(lag
, lag
->active_port
, event_port
);
1388 lag
->active_port
= event_port
;
1390 /* port not set as currently active (e.g. new active port
1391 * has already claimed the nodes and filters
1393 if (lag
->active_port
!= event_port
)
1395 /* This is the case when neither port is active (both link down)
1396 * Link down on the bond - set active port to invalid and move
1397 * nodes and filters back to primary if not already there
1399 if (event_port
!= prim_port
)
1400 ice_lag_move_vf_nodes(lag
, event_port
, prim_port
);
1401 lag
->active_port
= ICE_LAG_INVALID_PORT
;
1406 * ice_lag_chk_comp - evaluate bonded interface for feature support
1407 * @lag: lag info struct
1408 * @ptr: opaque data for netdev event info
1411 ice_lag_chk_comp(struct ice_lag
*lag
, void *ptr
)
1413 struct net_device
*event_netdev
, *event_upper
;
1414 struct netdev_notifier_bonding_info
*info
;
1415 struct netdev_bonding_info
*bonding_info
;
1416 struct list_head
*tmp
;
1423 event_netdev
= netdev_notifier_info_to_dev(ptr
);
1425 event_upper
= netdev_master_upper_dev_get_rcu(event_netdev
);
1427 if (event_upper
!= lag
->upper_netdev
)
1430 dev
= ice_pf_to_dev(lag
->pf
);
1432 /* only supporting switchdev mode for SRIOV VF LAG.
1433 * primary interface has to be in switchdev mode
1435 if (!ice_is_switchdev_running(lag
->pf
)) {
1436 dev_info(dev
, "Primary interface not in switchdev mode - VF LAG disabled\n");
1440 info
= (struct netdev_notifier_bonding_info
*)ptr
;
1441 bonding_info
= &info
->bonding_info
;
1442 lag
->bond_mode
= bonding_info
->master
.bond_mode
;
1443 if (lag
->bond_mode
!= BOND_MODE_ACTIVEBACKUP
) {
1444 dev_info(dev
, "Bond Mode not ACTIVE-BACKUP - VF LAG disabled\n");
1448 list_for_each(tmp
, lag
->netdev_head
) {
1449 struct ice_dcbx_cfg
*dcb_cfg
, *peer_dcb_cfg
;
1450 struct ice_lag_netdev_list
*entry
;
1451 struct ice_netdev_priv
*peer_np
;
1452 struct net_device
*peer_netdev
;
1453 struct ice_vsi
*vsi
, *peer_vsi
;
1454 struct ice_pf
*peer_pf
;
1456 entry
= list_entry(tmp
, struct ice_lag_netdev_list
, node
);
1457 peer_netdev
= entry
->netdev
;
1458 if (!netif_is_ice(peer_netdev
)) {
1459 dev_info(dev
, "Found %s non-ice netdev in LAG - VF LAG disabled\n",
1460 netdev_name(peer_netdev
));
1466 dev_info(dev
, "Found more than two netdevs in LAG - VF LAG disabled\n");
1470 peer_np
= netdev_priv(peer_netdev
);
1471 vsi
= ice_get_main_vsi(lag
->pf
);
1472 peer_vsi
= peer_np
->vsi
;
1473 if (lag
->pf
->pdev
->bus
!= peer_vsi
->back
->pdev
->bus
||
1474 lag
->pf
->pdev
->slot
!= peer_vsi
->back
->pdev
->slot
) {
1475 dev_info(dev
, "Found %s on different device in LAG - VF LAG disabled\n",
1476 netdev_name(peer_netdev
));
1480 dcb_cfg
= &vsi
->port_info
->qos_cfg
.local_dcbx_cfg
;
1481 peer_dcb_cfg
= &peer_vsi
->port_info
->qos_cfg
.local_dcbx_cfg
;
1482 if (memcmp(dcb_cfg
, peer_dcb_cfg
,
1483 sizeof(struct ice_dcbx_cfg
))) {
1484 dev_info(dev
, "Found %s with different DCB in LAG - VF LAG disabled\n",
1485 netdev_name(peer_netdev
));
1489 peer_pf
= peer_vsi
->back
;
1490 if (test_bit(ICE_FLAG_FW_LLDP_AGENT
, peer_pf
->flags
)) {
1491 dev_warn(dev
, "Found %s with FW LLDP agent active - VF LAG disabled\n",
1492 netdev_name(peer_netdev
));
1501 * ice_lag_unregister - handle netdev unregister events
1502 * @lag: LAG info struct
1503 * @event_netdev: netdev struct for target of notifier event
1506 ice_lag_unregister(struct ice_lag
*lag
, struct net_device
*event_netdev
)
1508 struct ice_netdev_priv
*np
;
1509 struct ice_pf
*event_pf
;
1510 struct ice_lag
*p_lag
;
1512 p_lag
= ice_lag_find_primary(lag
);
1513 np
= netdev_priv(event_netdev
);
1514 event_pf
= np
->vsi
->back
;
1517 if (p_lag
->active_port
!= p_lag
->pf
->hw
.port_info
->lport
&&
1518 p_lag
->active_port
!= ICE_LAG_INVALID_PORT
) {
1519 struct ice_hw
*active_hw
;
1521 active_hw
= ice_lag_find_hw_by_lport(lag
,
1522 p_lag
->active_port
);
1524 ice_lag_reclaim_vf_nodes(p_lag
, active_hw
);
1525 lag
->active_port
= ICE_LAG_INVALID_PORT
;
1529 /* primary processing for primary */
1530 if (lag
->primary
&& lag
->netdev
== event_netdev
)
1531 ice_lag_primary_swid(lag
, false);
1533 /* primary processing for secondary */
1534 if (lag
->primary
&& lag
->netdev
!= event_netdev
)
1535 ice_lag_del_prune_list(lag
, event_pf
);
1537 /* secondary processing for secondary */
1538 if (!lag
->primary
&& lag
->netdev
== event_netdev
)
1539 ice_lag_set_swid(0, lag
, false);
1543 * ice_lag_monitor_rdma - set and clear rdma functionality
1544 * @lag: pointer to lag struct
1545 * @ptr: opaque data for netdev event info
1548 ice_lag_monitor_rdma(struct ice_lag
*lag
, void *ptr
)
1550 struct netdev_notifier_changeupper_info
*info
;
1551 struct net_device
*netdev
;
1554 netdev
= netdev_notifier_info_to_dev(ptr
);
1556 if (netdev
!= lag
->netdev
)
1560 ice_clear_rdma_cap(lag
->pf
);
1562 ice_set_rdma_cap(lag
->pf
);
1566 * ice_lag_chk_disabled_bond - monitor interfaces entering/leaving disabled bond
1567 * @lag: lag info struct
1568 * @ptr: opaque data containing event
1570 * as interfaces enter a bond - determine if the bond is currently
1571 * SRIOV LAG compliant and flag if not. As interfaces leave the
1572 * bond, reset their compliant status.
1574 static void ice_lag_chk_disabled_bond(struct ice_lag
*lag
, void *ptr
)
1576 struct net_device
*netdev
= netdev_notifier_info_to_dev(ptr
);
1577 struct netdev_notifier_changeupper_info
*info
= ptr
;
1578 struct ice_lag
*prim_lag
;
1580 if (netdev
!= lag
->netdev
)
1583 if (info
->linking
) {
1584 prim_lag
= ice_lag_find_primary(lag
);
1586 !ice_is_feature_supported(prim_lag
->pf
, ICE_F_SRIOV_LAG
)) {
1587 ice_clear_feature_support(lag
->pf
, ICE_F_SRIOV_LAG
);
1588 netdev_info(netdev
, "Interface added to non-compliant SRIOV LAG aggregate\n");
1591 ice_lag_init_feature_support_flag(lag
->pf
);
1596 * ice_lag_disable_sriov_bond - set members of bond as not supporting SRIOV LAG
1597 * @lag: primary interfaces lag struct
1599 static void ice_lag_disable_sriov_bond(struct ice_lag
*lag
)
1601 struct ice_netdev_priv
*np
;
1604 np
= netdev_priv(lag
->netdev
);
1606 ice_clear_feature_support(pf
, ICE_F_SRIOV_LAG
);
1610 * ice_lag_process_event - process a task assigned to the lag_wq
1611 * @work: pointer to work_struct
1613 static void ice_lag_process_event(struct work_struct
*work
)
1615 struct netdev_notifier_changeupper_info
*info
;
1616 struct ice_lag_work
*lag_work
;
1617 struct net_device
*netdev
;
1618 struct list_head
*tmp
, *n
;
1621 lag_work
= container_of(work
, struct ice_lag_work
, lag_task
);
1622 pf
= lag_work
->lag
->pf
;
1624 mutex_lock(&pf
->lag_mutex
);
1625 lag_work
->lag
->netdev_head
= &lag_work
->netdev_list
.node
;
1627 switch (lag_work
->event
) {
1628 case NETDEV_CHANGEUPPER
:
1629 info
= &lag_work
->info
.changeupper_info
;
1630 ice_lag_chk_disabled_bond(lag_work
->lag
, info
);
1631 if (ice_is_feature_supported(pf
, ICE_F_SRIOV_LAG
)) {
1632 ice_lag_monitor_link(lag_work
->lag
, info
);
1633 ice_lag_changeupper_event(lag_work
->lag
, info
);
1634 ice_lag_link_unlink(lag_work
->lag
, info
);
1636 ice_lag_monitor_rdma(lag_work
->lag
, info
);
1638 case NETDEV_BONDING_INFO
:
1639 if (ice_is_feature_supported(pf
, ICE_F_SRIOV_LAG
)) {
1640 if (!ice_lag_chk_comp(lag_work
->lag
,
1641 &lag_work
->info
.bonding_info
)) {
1642 netdev
= lag_work
->info
.bonding_info
.info
.dev
;
1643 ice_lag_disable_sriov_bond(lag_work
->lag
);
1644 ice_lag_unregister(lag_work
->lag
, netdev
);
1647 ice_lag_monitor_active(lag_work
->lag
,
1648 &lag_work
->info
.bonding_info
);
1649 ice_lag_cfg_pf_fltrs(lag_work
->lag
,
1650 &lag_work
->info
.bonding_info
);
1652 ice_lag_info_event(lag_work
->lag
, &lag_work
->info
.bonding_info
);
1654 case NETDEV_UNREGISTER
:
1655 if (ice_is_feature_supported(pf
, ICE_F_SRIOV_LAG
)) {
1656 netdev
= lag_work
->info
.bonding_info
.info
.dev
;
1657 if ((netdev
== lag_work
->lag
->netdev
||
1658 lag_work
->lag
->primary
) && lag_work
->lag
->bonded
)
1659 ice_lag_unregister(lag_work
->lag
, netdev
);
1667 /* cleanup resources allocated for this work item */
1668 list_for_each_safe(tmp
, n
, &lag_work
->netdev_list
.node
) {
1669 struct ice_lag_netdev_list
*entry
;
1671 entry
= list_entry(tmp
, struct ice_lag_netdev_list
, node
);
1672 list_del(&entry
->node
);
1675 lag_work
->lag
->netdev_head
= NULL
;
1677 mutex_unlock(&pf
->lag_mutex
);
1683 * ice_lag_event_handler - handle LAG events from netdev
1684 * @notif_blk: notifier block registered by this netdev
1685 * @event: event type
1686 * @ptr: opaque data containing notifier event
1689 ice_lag_event_handler(struct notifier_block
*notif_blk
, unsigned long event
,
1692 struct net_device
*netdev
= netdev_notifier_info_to_dev(ptr
);
1693 struct net_device
*upper_netdev
;
1694 struct ice_lag_work
*lag_work
;
1695 struct ice_lag
*lag
;
1697 if (!netif_is_ice(netdev
))
1700 if (event
!= NETDEV_CHANGEUPPER
&& event
!= NETDEV_BONDING_INFO
&&
1701 event
!= NETDEV_UNREGISTER
)
1704 if (!(netdev
->priv_flags
& IFF_BONDING
))
1707 lag
= container_of(notif_blk
, struct ice_lag
, notif_block
);
1711 if (!net_eq(dev_net(netdev
), &init_net
))
1714 /* This memory will be freed at the end of ice_lag_process_event */
1715 lag_work
= kzalloc(sizeof(*lag_work
), GFP_KERNEL
);
1719 lag_work
->event_netdev
= netdev
;
1720 lag_work
->lag
= lag
;
1721 lag_work
->event
= event
;
1722 if (event
== NETDEV_CHANGEUPPER
) {
1723 struct netdev_notifier_changeupper_info
*info
;
1726 upper_netdev
= info
->upper_dev
;
1728 upper_netdev
= netdev_master_upper_dev_get(netdev
);
1731 INIT_LIST_HEAD(&lag_work
->netdev_list
.node
);
1733 struct ice_lag_netdev_list
*nd_list
;
1734 struct net_device
*tmp_nd
;
1737 for_each_netdev_in_bond_rcu(upper_netdev
, tmp_nd
) {
1738 nd_list
= kzalloc(sizeof(*nd_list
), GFP_ATOMIC
);
1742 nd_list
->netdev
= tmp_nd
;
1743 list_add(&nd_list
->node
, &lag_work
->netdev_list
.node
);
1749 case NETDEV_CHANGEUPPER
:
1750 lag_work
->info
.changeupper_info
=
1751 *((struct netdev_notifier_changeupper_info
*)ptr
);
1753 case NETDEV_BONDING_INFO
:
1754 lag_work
->info
.bonding_info
=
1755 *((struct netdev_notifier_bonding_info
*)ptr
);
1758 lag_work
->info
.notifier_info
=
1759 *((struct netdev_notifier_info
*)ptr
);
1763 INIT_WORK(&lag_work
->lag_task
, ice_lag_process_event
);
1764 queue_work(ice_lag_wq
, &lag_work
->lag_task
);
1770 * ice_register_lag_handler - register LAG handler on netdev
1773 static int ice_register_lag_handler(struct ice_lag
*lag
)
1775 struct device
*dev
= ice_pf_to_dev(lag
->pf
);
1776 struct notifier_block
*notif_blk
;
1778 notif_blk
= &lag
->notif_block
;
1780 if (!notif_blk
->notifier_call
) {
1781 notif_blk
->notifier_call
= ice_lag_event_handler
;
1782 if (register_netdevice_notifier(notif_blk
)) {
1783 notif_blk
->notifier_call
= NULL
;
1784 dev_err(dev
, "FAIL register LAG event handler!\n");
1787 dev_dbg(dev
, "LAG event handler registered\n");
1793 * ice_unregister_lag_handler - unregister LAG handler on netdev
1796 static void ice_unregister_lag_handler(struct ice_lag
*lag
)
1798 struct device
*dev
= ice_pf_to_dev(lag
->pf
);
1799 struct notifier_block
*notif_blk
;
1801 notif_blk
= &lag
->notif_block
;
1802 if (notif_blk
->notifier_call
) {
1803 unregister_netdevice_notifier(notif_blk
);
1804 dev_dbg(dev
, "LAG event handler unregistered\n");
1809 * ice_create_lag_recipe
1810 * @hw: pointer to HW struct
1811 * @rid: pointer to u16 to pass back recipe index
1812 * @base_recipe: recipe to base the new recipe on
1813 * @prio: priority for new recipe
1815 * function returns 0 on error
1817 static int ice_create_lag_recipe(struct ice_hw
*hw
, u16
*rid
,
1818 const u8
*base_recipe
, u8 prio
)
1820 struct ice_aqc_recipe_data_elem
*new_rcp
;
1823 err
= ice_alloc_recipe(hw
, rid
);
1827 new_rcp
= kzalloc(ICE_RECIPE_LEN
* ICE_MAX_NUM_RECIPES
, GFP_KERNEL
);
1831 memcpy(new_rcp
, base_recipe
, ICE_RECIPE_LEN
);
1832 new_rcp
->content
.act_ctrl_fwd_priority
= prio
;
1833 new_rcp
->content
.rid
= *rid
| ICE_AQ_RECIPE_ID_IS_ROOT
;
1834 new_rcp
->recipe_indx
= *rid
;
1835 bitmap_zero((unsigned long *)new_rcp
->recipe_bitmap
,
1836 ICE_MAX_NUM_RECIPES
);
1837 set_bit(*rid
, (unsigned long *)new_rcp
->recipe_bitmap
);
1839 err
= ice_aq_add_recipe(hw
, new_rcp
, 1, NULL
);
1848 * ice_lag_move_vf_nodes_tc_sync - move a VF's nodes for a tc during reset
1849 * @lag: primary interfaces lag struct
1850 * @dest_hw: HW struct for destination's interface
1851 * @vsi_num: VSI index in PF space
1852 * @tc: traffic class to move
1855 ice_lag_move_vf_nodes_tc_sync(struct ice_lag
*lag
, struct ice_hw
*dest_hw
,
1858 DEFINE_FLEX(struct ice_aqc_move_elem
, buf
, teid
, 1);
1859 struct device
*dev
= ice_pf_to_dev(lag
->pf
);
1860 u16 numq
, valq
, num_moved
, qbuf_size
;
1861 u16 buf_size
= __struct_size(buf
);
1862 struct ice_aqc_cfg_txqs_buf
*qbuf
;
1863 struct ice_sched_node
*n_prt
;
1864 __le32 teid
, parent_teid
;
1865 struct ice_vsi_ctx
*ctx
;
1870 ctx
= ice_get_vsi_ctx(hw
, vsi_num
);
1872 dev_warn(dev
, "LAG rebuild failed after reset due to VSI Context failure\n");
1876 if (!ctx
->sched
.vsi_node
[tc
])
1879 numq
= ctx
->num_lan_q_entries
[tc
];
1880 teid
= ctx
->sched
.vsi_node
[tc
]->info
.node_teid
;
1881 tmp_teid
= le32_to_cpu(teid
);
1882 parent_teid
= ctx
->sched
.vsi_node
[tc
]->info
.parent_teid
;
1884 if (!tmp_teid
|| !numq
)
1887 if (ice_sched_suspend_resume_elems(hw
, 1, &tmp_teid
, true))
1888 dev_dbg(dev
, "Problem suspending traffic during reset rebuild\n");
1890 /* reconfig queues for new port */
1891 qbuf_size
= struct_size(qbuf
, queue_info
, numq
);
1892 qbuf
= kzalloc(qbuf_size
, GFP_KERNEL
);
1894 dev_warn(dev
, "Failure allocating VF queue recfg buffer for reset rebuild\n");
1898 /* add the per queue info for the reconfigure command buffer */
1899 valq
= ice_lag_qbuf_recfg(hw
, qbuf
, vsi_num
, numq
, tc
);
1901 dev_warn(dev
, "Failure to reconfig queues for LAG reset rebuild\n");
1905 if (ice_aq_cfg_lan_txq(hw
, qbuf
, qbuf_size
, numq
, hw
->port_info
->lport
,
1906 dest_hw
->port_info
->lport
, NULL
)) {
1907 dev_warn(dev
, "Failure to configure queues for LAG reset rebuild\n");
1914 /* find parent in destination tree */
1915 n_prt
= ice_lag_get_sched_parent(dest_hw
, tc
);
1919 /* Move node to new parent */
1920 buf
->hdr
.src_parent_teid
= parent_teid
;
1921 buf
->hdr
.dest_parent_teid
= n_prt
->info
.node_teid
;
1922 buf
->hdr
.num_elems
= cpu_to_le16(1);
1923 buf
->hdr
.mode
= ICE_AQC_MOVE_ELEM_MODE_KEEP_OWN
;
1924 buf
->teid
[0] = teid
;
1926 if (ice_aq_move_sched_elems(&lag
->pf
->hw
, buf
, buf_size
, &num_moved
))
1927 dev_warn(dev
, "Failure to move VF nodes for LAG reset rebuild\n");
1929 ice_sched_update_parent(n_prt
, ctx
->sched
.vsi_node
[tc
]);
1937 if (ice_sched_suspend_resume_elems(hw
, 1, &tmp_teid
, false))
1938 dev_warn(dev
, "Problem restarting traffic for LAG node reset rebuild\n");
1942 * ice_lag_move_vf_nodes_sync - move vf nodes to active interface
1943 * @lag: primary interfaces lag struct
1944 * @dest_hw: lport value for currently active port
1946 * This function is used in a reset context, outside of event handling,
1947 * to move the VF nodes to the secondary interface when that interface
1948 * is the active interface during a reset rebuild
1951 ice_lag_move_vf_nodes_sync(struct ice_lag
*lag
, struct ice_hw
*dest_hw
)
1956 if (!lag
->primary
|| !dest_hw
)
1960 ice_for_each_vsi(pf
, i
)
1961 if (pf
->vsi
[i
] && (pf
->vsi
[i
]->type
== ICE_VSI_VF
||
1962 pf
->vsi
[i
]->type
== ICE_VSI_SWITCHDEV_CTRL
))
1963 ice_for_each_traffic_class(tc
)
1964 ice_lag_move_vf_nodes_tc_sync(lag
, dest_hw
, i
,
1969 * ice_init_lag - initialize support for LAG
1972 * Alloc memory for LAG structs and initialize the elements.
1973 * Memory will be freed in ice_deinit_lag
1975 int ice_init_lag(struct ice_pf
*pf
)
1977 struct device
*dev
= ice_pf_to_dev(pf
);
1978 struct ice_lag
*lag
;
1979 struct ice_vsi
*vsi
;
1980 u64 recipe_bits
= 0;
1983 ice_lag_init_feature_support_flag(pf
);
1984 if (!ice_is_feature_supported(pf
, ICE_F_SRIOV_LAG
))
1987 pf
->lag
= kzalloc(sizeof(*lag
), GFP_KERNEL
);
1992 vsi
= ice_get_main_vsi(pf
);
1994 dev_err(dev
, "couldn't get main vsi, link aggregation init fail\n");
2000 lag
->netdev
= vsi
->netdev
;
2001 lag
->role
= ICE_LAG_NONE
;
2002 lag
->active_port
= ICE_LAG_INVALID_PORT
;
2003 lag
->bonded
= false;
2004 lag
->upper_netdev
= NULL
;
2005 lag
->notif_block
.notifier_call
= NULL
;
2007 err
= ice_register_lag_handler(lag
);
2009 dev_warn(dev
, "INIT LAG: Failed to register event handler\n");
2013 err
= ice_create_lag_recipe(&pf
->hw
, &lag
->pf_recipe
,
2014 ice_dflt_vsi_rcp
, 1);
2018 err
= ice_create_lag_recipe(&pf
->hw
, &lag
->lport_recipe
,
2023 /* associate recipes to profiles */
2024 for (n
= 0; n
< ICE_PROFID_IPV6_GTPU_IPV6_TCP_INNER
; n
++) {
2025 err
= ice_aq_get_recipe_to_profile(&pf
->hw
, n
,
2026 (u8
*)&recipe_bits
, NULL
);
2030 if (recipe_bits
& BIT(ICE_SW_LKUP_DFLT
)) {
2031 recipe_bits
|= BIT(lag
->pf_recipe
) |
2032 BIT(lag
->lport_recipe
);
2033 ice_aq_map_recipe_to_profile(&pf
->hw
, n
,
2034 (u8
*)&recipe_bits
, NULL
);
2038 ice_display_lag_info(lag
);
2040 dev_dbg(dev
, "INIT LAG complete\n");
2044 ice_free_hw_res(&pf
->hw
, ICE_AQC_RES_TYPE_RECIPE
, 1,
2045 &pf
->lag
->pf_recipe
);
2053 * ice_deinit_lag - Clean up LAG
2056 * Clean up kernel LAG info and free memory
2057 * This function is meant to only be called on driver remove/shutdown
2059 void ice_deinit_lag(struct ice_pf
*pf
)
2061 struct ice_lag
*lag
;
2069 ice_unregister_lag_handler(lag
);
2071 flush_workqueue(ice_lag_wq
);
2073 ice_free_hw_res(&pf
->hw
, ICE_AQC_RES_TYPE_RECIPE
, 1,
2074 &pf
->lag
->pf_recipe
);
2075 ice_free_hw_res(&pf
->hw
, ICE_AQC_RES_TYPE_RECIPE
, 1,
2076 &pf
->lag
->lport_recipe
);
2084 * ice_lag_rebuild - rebuild lag resources after reset
2085 * @pf: pointer to local pf struct
2087 * PF resets are promoted to CORER resets when interface in an aggregate. This
2088 * means that we need to rebuild the PF resources for the interface. Since
2089 * this will happen outside the normal event processing, need to acquire the lag
2092 * This function will also evaluate the VF resources if this is the primary
2095 void ice_lag_rebuild(struct ice_pf
*pf
)
2097 struct ice_lag_netdev_list ndlist
;
2098 struct ice_lag
*lag
, *prim_lag
;
2099 u8 act_port
, loc_port
;
2101 if (!pf
->lag
|| !pf
->lag
->bonded
)
2104 mutex_lock(&pf
->lag_mutex
);
2110 ice_lag_build_netdev_list(lag
, &ndlist
);
2111 prim_lag
= ice_lag_find_primary(lag
);
2115 dev_dbg(ice_pf_to_dev(pf
), "No primary interface in aggregate, can't rebuild\n");
2116 goto lag_rebuild_out
;
2119 act_port
= prim_lag
->active_port
;
2120 loc_port
= lag
->pf
->hw
.port_info
->lport
;
2122 /* configure SWID for this port */
2124 ice_lag_primary_swid(lag
, true);
2126 ice_lag_set_swid(prim_lag
->pf
->hw
.port_info
->sw_id
, lag
, true);
2127 ice_lag_add_prune_list(prim_lag
, pf
);
2128 if (act_port
== loc_port
)
2129 ice_lag_move_vf_nodes_sync(prim_lag
, &pf
->hw
);
2132 ice_lag_cfg_cp_fltr(lag
, true);
2134 if (lag
->pf_rule_id
)
2135 if (ice_lag_cfg_dflt_fltr(lag
, true))
2136 dev_err(ice_pf_to_dev(pf
), "Error adding default VSI rule in rebuild\n");
2138 ice_clear_rdma_cap(pf
);
2140 ice_lag_destroy_netdev_list(lag
, &ndlist
);
2141 mutex_unlock(&pf
->lag_mutex
);
2145 * ice_lag_is_switchdev_running
2146 * @pf: pointer to PF structure
2148 * Check if switchdev is running on any of the interfaces connected to lag.
2150 bool ice_lag_is_switchdev_running(struct ice_pf
*pf
)
2152 struct ice_lag
*lag
= pf
->lag
;
2153 struct net_device
*tmp_nd
;
2155 if (!ice_is_feature_supported(pf
, ICE_F_SRIOV_LAG
) || !lag
)
2159 for_each_netdev_in_bond_rcu(lag
->upper_netdev
, tmp_nd
) {
2160 struct ice_netdev_priv
*priv
= netdev_priv(tmp_nd
);
2162 if (!netif_is_ice(tmp_nd
) || !priv
|| !priv
->vsi
||
2166 if (ice_is_switchdev_running(priv
->vsi
->back
)) {